feat: add hooks authoring instruction 🤖🤖🤖#1507
feat: add hooks authoring instruction 🤖🤖🤖#1507yeelam-gordon wants to merge 5 commits intogithub:stagedfrom
Conversation
Add hooks.instructions.md with portable guidance for writing GitHub Copilot hooks: - Folder structure, config schema, and all field documentation - Script contract: stdin JSON, exit codes, stdout/stderr channels - Payload schemas for all common events (sessionStart, sessionEnd, userPromptSubmitted, preToolUse, postToolUse, errorOccurred, agentStop) - Per-event deny mechanisms (structured JSON for preToolUse, non-zero exit for others) - Matcher support for host-level tool filtering - Three impactful examples: commit gate, auto-format, dangerous command blocker - Bash and PowerShell templates - Cross-platform guidance (Python through both entries) - Anti-patterns, design rules, and portability notes (GitHub Copilot vs Claude Code) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a new instruction document intended to guide authors in writing GitHub Copilot hooks, and registers it in the instructions index so it’s discoverable alongside other instruction files.
Changes:
- Added
instructions/hooks.instructions.mdwith hook configuration guidance, script I/O contract, event payload examples, and sample hook patterns. - Updated
docs/README.instructions.mdto include the new “Hook Authoring Guidelines” entry and install links.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| instructions/hooks.instructions.md | New, comprehensive hook authoring guide (config schema, event behaviors, payloads, examples). |
| docs/README.instructions.md | Adds the new instruction to the published instructions catalog. |
- Document both toolArgs (JSON string) and tool_input/toolInput (object) variants with defensive parsing - Update sessionStart stdout to reflect additionalContext injection support - Document preToolUse stdout output fields: modifiedArgs/updatedInput, additionalContext - Add matcher field note about local verification - Remove undocumented notification event from event table Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Addressed all 4 review comments:
Also documented preToolUse stdout output fields (modifiedArgs/updatedInput, additionalContext) from the Learning Hub docs. Requesting re-review. |
kukuguzka
left a comment
There was a problem hiding this comment.
2a6b71346eb1b00d229447a719959d8f2cc43499
- Defensive toolArgs parsing in all 3 example scripts (handle toolArgs string, tool_input, toolInput) - PowerShell type check: test -is [string] before ConvertFrom-Json, init to null - commit-gate.sh: add package.json existence guard before jq - block-dangerous.sh: truncate command in deny reason and stderr to avoid leaking secrets - Consistent defensive parsing helper across all Bash examples Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@kukuguzka, what is this stand for? |
- All 3 Bash example jq blocks now check toolArgs type before fromjson - short_cmd defined before the deny/log branch to avoid set -u error - Consistent defensive pattern across commit-gate, format-on-save, block-dangerous Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@aaronpowell, it is super strange we don't have hook's instruction. |
Summary
Add \instructions/hooks.instructions.md\ — a portable, deeply researched guide for writing GitHub Copilot hooks correctly.
What it covers
How it was built
Checklist
pm start\ to update generated README