fix(opencode,kilo): shell hook events via bash-gated named hooks, global instructions registration - #2547
Merged
Conversation
…bal instructions registration Resolves the two gaps from #2501, verified against sst/opencode v1.18.10: 1. hooks (correctness): afterShellExecution was mapped to OpenCode's command.executed - a slash-command event - so the hook never fired on shell commands and fired on every slash command instead (Kilo shared the same wrong mapping). Both shell events are now emitted into the named tool.execute.before/after hooks with an implicit input.tool === "bash" gate (the .env-protection pattern from the OpenCode plugins doc), and beforeShellExecution joins OPENCODE_HOOK_EVENTS (a capability OpenCode had that rulesync did not offer). Matchers on the shell events stay warned-and-dropped upstream (matcherEvents covers only preToolUse/postToolUse); the named hooks expose no command text to match against. 2. rules: global generate no longer drops non-root rules. OpenCode reads instructions from the global ~/.config/opencode/opencode.json, so global non-root rules are now written to ~/.config/opencode/memories/*.md and registered there (entries relative to the config file's directory), via a new mcpInstructionsRegistrarGlobal opt-in on the rules factory meta and a rules ownership declaration for the global config in the gateway. Closes #2501 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…osed Review follow-ups on PR #2547: - The opencode and kilo hook factories now declare matcherEvents [preToolUse, postToolUse] (as amp does), so a matcher on any other event - the bash-gated shell events, preCompact, and the generic event dispatches - triggers the processor's 'Skipped matcher hook(s)' warning, which previously never fired for these targets. - The generator now actually skips matcher-carrying definitions on events with no matchable subject, matching the warning text; running them unconditionally would over-fire hooks the user scoped with a matcher. The preCompact test is updated to the fail-closed behavior. - Stale 'project-scope-only' comment above the opencode ownership entries corrected; processor-level test added for the shell-event matcher skip. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Owner
Author
|
@dyoshikawa Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves the two OpenCode gaps from #2501 (verified against sst/opencode v1.18.10; Kilo shares the hook surface):
afterShellExecutionwas mapped tocommand.executed, which is a slash-command event — the hook never fired after a bash command and fired on every slash command instead, for OpenCode and Kilo. Both shell events now land in the namedtool.execute.before/tool.execute.afterhooks with an implicitinput.tool === "bash"gate (the.env protectionpattern from the OpenCode plugins doc), implemented via aSHELL_EVENT_TOOL_GATEStable in the shared opencode-style generator so Kilo inherits the fix.beforeShellExecutionjoinsOPENCODE_HOOK_EVENTSat the same time. Matchers on the shell events remain warned-and-dropped upstream (matcherEventscovers onlypreToolUse/postToolUse) — the named hooks expose no command text to match against.instructionsfrom the global~/.config/opencode/opencode.jsontoo, so global generate now writes non-root rules to~/.config/opencode/memories/*.mdand registers them (entries relative to the config file's directory, so the.config/opencode/prefix is stripped). Wiring: amcpInstructionsRegistrarGlobalopt-in on the rules factory meta (off by default — Kilo auto-discovers its global rules dir and must not register), a globalnonRootsettable path,getExtraSharedWritePathsreturning the global config at global scope, and arulesownership declaration for.config/opencode/opencode.jsonin the shared-config gateway.Docs: hooks prose + hand-maintained hook matrix cells updated (the generated matrix from #2540 will own this once merged), OpenCode rules note documents the global registration.
Testing
fromInstructionsprefix stripping, updated global settable-paths expectation and the event-map completeness carve-out; derive snapshot updated.pnpm cicheckgreen.Closes #2501
🤖 Generated with Claude Code