Skip to content

feat(cli): relay pre-tool and prompt hooks on opencode and kilo - #1361

Closed
blafourcade wants to merge 2 commits into
nextfrom
feat/bridge-relays-pre-tool-and-prompt
Closed

blafourcade wants to merge 2 commits into
nextfrom
feat/bridge-relays-pre-tool-and-prompt

Conversation

@blafourcade

Copy link
Copy Markdown
Contributor

🎯 What & why

Relays the PreToolUse and UserPromptSubmit hooks through the OpenCode and Kilo bridge, which relayed neither event before. A PreToolUse script can refuse a tool call; a UserPromptSubmit script can add a part to the prompt. Refs #1193.

🛠️ How it works

Host facts, probed end to end through the built bridge (translate --to <host> --as flat, two probe plugins). Payloads captured in scripts/__tests__/fixtures/hook-payloads/ (opencode-*.json, kilo-*.json).

  • OpenCode 1.19.3: tool.execute.before(input, output), arguments in output.args. A throw refuses the call and the message reaches the model. chat.message(input, output): a part pushed to output.parts reaches the model only if it is complete (id, messageID, sessionID, synthetic: true).
  • Kilo 7.7.5: same shapes, same refusal and part behaviour.

Wired in cli/src/contexts/tools/domain/bridges/bridge-relay-source.ts:

  • PreToolUse: a script exiting 2 refuses the call with its stderr as the reason. The first refusing script stops the rest.
  • UserPromptSubmit: each answer becomes a synthetic part, id <first part id>-<plugin>-<hook index>, so two scripts of one plugin do not collide. A follow-up the bridge sent itself (metadata mark) is never read as the user's prompt.
  • Build warning (translate) for each event a plugin names that the bridge does not relay.

Goldens moved, all intended: cli/tests/fixtures/hooks-routes/{kilo,opencode}/*.txt (generated bridge source) and the opencode/kilo aidd-context-hooks.js hashes in cli/tests/golden/snapshots/{framework-build,translate-install}/golden.json.

🧪 How to verify

  • Unit and integration: cd cli && pnpm exec vitest run tests/contexts/tools tests/contexts/translate.
  • Mutation proof: each guard (follow-up early return, synthetic filter, empty-answer skip, first-refuser short-circuit, warning filter and text) was broken in turn and the test naming it went red, then restored.
  • Gates on the head commit, all exit 0: make validate; pnpm exec lefthook run pre-commit --all-files; cd cli && pnpm exec lefthook run pre-push (9948 passed, 1 expected fail, 15 skipped); cd cli && pnpm build (bundle 884.4 KB, budget 897 KB, +5.2 KB over 879.2 KB).

⚠️ Heads-up

Limits, stated and not coded:

  • OpenCode V2 (setup(ctx), v2.2.7): not installed, not probed. opencode-events.js relays neither event. Open question for the maintainer: does the bridge target 1.x only, or V2 too. Not decided here.
  • Kilo probed on 7.7.5 only; the issue cites 7.8.27, not re-probed.
  • UserPromptSubmit cannot refuse a prompt on either host: a throw from chat.message is unprobed. Exit 2 only puts stderr in context.
  • The neutral adapter (hooks-runtime/host-bridge.cjs) still maps SessionStart, PostToolUse and Stop only.
  • The warning is build-only. plugin install on the flat route reports no skipped event, and SessionEnd and SubagentStop are dropped silently there.
  • Host tables (docs/COMPATIBILITY.md, 08-hook-generate references, tool-paths) are not edited here, another PR owns them. They must now read: PreToolUse = tool.execute.before (denies by throwing); UserPromptSubmit = chat.message (adds a part, no refusal). Their PR link is not added yet.
  • The issue stays open.

🔗 Linked issue

Refs #1193

✅ I certify

  • I DO CERTIFY I READ EACH LINE OF THE PULL REQUEST BECAUSE I AM A SOFTWARE ENGINEER, NOT A AI PUPPY.

🤖 Generated with Claude Code

…oss hosts

Kilo's awaited scripts and its Stop reason now go through the shared
runCapture like OpenCode's. The skipped-event warning has one owner in
shared materialization, and the bridge reports its own unrelayed events
from the manifest parser instead of a duplicated event list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@blafourcade

Copy link
Copy Markdown
Contributor Author

Superseded by #1378, which consolidates the five OpenCode and Kilo bridge branches into one shared runtime (V1 and V2) and is merged on next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant