Skip to content

fix(cosh): add skill_context to PreToolUse hook input for resolved skill path#409

Merged
kongche-jbw merged 1 commit intoalibaba:mainfrom
samchu-zsl:fix/cosh/381-pretooluse-skill-context
Apr 28, 2026
Merged

fix(cosh): add skill_context to PreToolUse hook input for resolved skill path#409
kongche-jbw merged 1 commit intoalibaba:mainfrom
samchu-zsl:fix/cosh/381-pretooluse-skill-context

Conversation

@samchu-zsl
Copy link
Copy Markdown
Collaborator

Summary

  • Adds skill_context (with skill_name and file_path) to PreToolUseInput, symmetric with existing mcp_context for MCP tools
  • When the Skill tool fires PreToolUse, coreToolScheduler now resolves the skill via SkillManager and attaches the resolved path to the hook input
  • Hooks can now locate skill directories on disk even when the SKILL.md name differs from the directory name

Type of Change

  • Bug fix

Related Issue

Closes #381

Testing

cd src/copilot-shell
npm run build && npm run test && npm run lint && npm run typecheck
# 125 hook tests passed, build succeeded, lint clean, typecheck clean

Changed Files

File Change
hooks/types.ts Add SkillToolContext interface and skill_context? field to PreToolUseInput
hooks/hookEventHandler.ts Forward optional skillContext parameter
hooks/hookSystem.ts Forward optional skillContext parameter in facade
core/coreToolScheduler.ts Resolve skill path before PreToolUse hook fire
tools/skill.ts Add resolveSkillConfig() method to SkillTool
hooks/hookEventHandler.test.ts 2 new tests for skill_context inclusion/omission

@samchu-zsl samchu-zsl requested a review from kongche-jbw as a code owner April 28, 2026 11:13
@gemini-code-assist
Copy link
Copy Markdown

Important

Installation incomplete: to start using Gemini Code Assist, please ask the organization owner(s) to visit the Gemini Code Assist Admin Console and sign the Terms of Services.

@github-actions github-actions Bot added the component:cosh src/copilot-shell/ label Apr 28, 2026
@samchu-zsl
Copy link
Copy Markdown
Collaborator Author

Manually tested the PreToolUse hook by:

  1. Creating ~/.copilot-shell/hooks/dump-pretooluse.sh:
#!/bin/bash
cat > /tmp/pretooluse-hook-dump.json
  1. Adding to ~/.copilot-shell/settings.json:
"hooks": {
  "PreToolUse": [{
    "matcher": "Skill",
    "hooks": [{
      "type": "command",
      "command": "bash ~/.copilot-shell/hooks/dump-pretooluse.sh",
      "name": "dump-pretooluse"
    }]
  }]
}
  1. Running /skills in cosh, then verifying output:
> cat /tmp/pretooluse-hook-dump.json | jq
{
  "session_id": "b9d9c537-aca1-4b6d-a380-c64abe36b7e6",
  "transcript_path": "xxx/b9d9c537-aca1-4b6d-a380-c64abe36b7e6.jsonl",
  "cwd": "xxx/copilot-shell",
  "hook_event_name": "PreToolUse",
  "timestamp": "2026-04-28T11:23:15.485Z",
  "tool_name": "skill",
  "tool_input": { "skill": "uv-package-manager" },
  "skill_context": {
    "skill_name": "uv-package-manager",
    "file_path": "xxx/skills/uv-package-manager/SKILL.md"
  }
}

@1570005763
Copy link
Copy Markdown
Collaborator

LGTM.

Copy link
Copy Markdown
Collaborator

@kongche-jbw kongche-jbw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm,thx

@kongche-jbw kongche-jbw merged commit d627df0 into alibaba:main Apr 28, 2026
13 checks passed
@samchu-zsl samchu-zsl deleted the fix/cosh/381-pretooluse-skill-context branch April 29, 2026 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:cosh src/copilot-shell/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[cosh] bug(cosh): PreToolUse hook input lacks resolved skill directory path

3 participants