Skip to content

feat(cli): relay every hook event through one opencode and kilo bridge, v1 and v2 - #1378

Merged
blafourcade merged 59 commits into
nextfrom
feat/opencode-kilo-bridge
Nov 26, 2026
Merged

blafourcade merged 59 commits into
nextfrom
feat/opencode-kilo-bridge

Conversation

@blafourcade

Copy link
Copy Markdown
Contributor

Summary

One OpenCode and Kilo hook bridge, V1 and V2, replacing five parallel branches.

  • One shared runtime (bridgeHooks): SessionStart, UserPromptSubmit, PreToolUse, PostToolUse and Stop, plus the system-prompt hand-over. Each host template keeps only what differs: the start folder, the follow-up call (prompt or promptAsync), what ends a turn, the person channel and the dispose wait.
  • Relayed now: PreToolUse (a refusal blocks the write and the reason reaches the model) and UserPromptSubmit on both hosts. A required finding is queued as the next prompt. A person message shows as an OpenCode toast. A session-start answer reaches the model.
  • Fixed:
    • several plugins answering at Stop each reach the model;
    • two plugins whose follow-ups both land no longer loop forever on Kilo;
    • SessionStart runs once per session, not at plugin load;
    • a child session runs neither SessionStart nor Stop.
  • OpenCode V2 (@opencode/cli 2.4.1), proven end to end with two plugins:
    • SessionStart at the first prompt;
    • UserPromptSubmit through the context hook;
    • the PreToolUse refusal;
    • path read as file_path;
    • Stop through experimental.idle with session.synthetic.
  • Warnings come from one plan-stage parse, on both build and install.
  • Limits:
    • On V2, the patch tool's name was not observed, there is no toast, and a required finding is appended, not queued.
    • Kilo 7.7.5 and 7.8.x were probed. The interface was not.

Gates: G1 to G4 = 0, 10060 tests passed, bundle 893.2 KB of 897.

Refs #1320, #1193, #1348, #1349, #1350, #1342. Supersedes #1356, #1361 and #1354.

🤖 Generated with Claude Code

blafourcade and others added 30 commits November 25, 2026 14:55
…kilo

The OpenCode and Kilo bridges ran SessionStart with its output ignored.
Probed on OpenCode 1.19.3 and Kilo 7.7.5: text pushed onto the V1
experimental.chat.system.transform output reaches the model. The bridges
now read the hook's additionalContext and add it to the system prompt,
per server on OpenCode and per created session on Kilo.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eral plugins answer one Stop

SessionStart ran once at plugin load with no session id, and again each time the host recreated the plugin. It now runs on the first event naming a session, once, with the id and folder the event carries. The OpenCode profile declares session.created for it, as Kilo's does, and the orphaned server-init payloads are removed.

A captured first event of a continued session drives its test. A test holds that two plugins answering the same Stop each reach the model. The Kilo bridge comment states the open run-mode loss as a limit with its versions. The V2 adapter's created event names no session, stated as a limit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…oast

The OpenCode bridge sends a script's systemMessage to the server plugin client's
tui.showToast, from SessionStart (held to the first turn), PostToolUse and Stop.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Dispose waits for the session-start answer, so the hold is asserted without a sleep.
The architecture rule states where a person message beside a text is dropped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s from the Kilo template

The session-start call mapping lived once per host template. It is now one
generated part both read, so only what differs per host stays in the host.
The Kilo template states its run-mode limit with the probed versions and
keys, and its provenance moves to the generator's doc comment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d kilo

A level 2 answer after a write is appended to the tool's result and, when the
script marks it required, queued with promptAsync from tool.execute.after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…bridges

One generated capture spawns the script, collects its output and settles to a failure instead of rejecting. Both hosts build answerOf, stopReasonOf, the failure warning, the follow-up warning and the PostToolUse call mapping on it, so only the host name and whether a failed script is reported stay per host.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The rule that starts a session's hooks, once per session on the first event
that names it and surviving a recreated plugin, lived in the OpenCode template
while Kilo kept its own per-instance copy keyed on session.created. It is now
one generated part both templates call, so a continued Kilo session and a
recreated Kilo plugin behave as OpenCode's do. Kilo's continued-session first
event is stated as not probed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…code and kilo bridges

Both host templates now pass only a session id and a directory; the payload,
the run and the join live in the shared bridge, as does the dispatch warning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and kilo bridges

The queue lives once in the event bridge; each host passes its client, session and
mark. OpenCode sends no mark, as nothing reads it there. Kilo's mark names the
intent, a prompt the bridge sent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The OpenCode template also drops its repo pointers and finding tag.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…session-start hand-over

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…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]>
… probe showed

The Stop follow-up and the queued required finding share one prompt sender
parameterised by host call, mark and refusal prefix, now in bridge-sources.
The adapter marks any level 2 answer required, since only the PostToolUse
bridge reads it. The kilo doc says the turn kept going after the queued
prompt, as probed, and the opencode doc states what a V2 host does without
promptAsync.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ge reports

The Stop call builder moves to the shared event bridge like SessionStart and PostToolUse,
the dispatch warning is written only for the host that uses it, the host flag is named for
what it decides, and the call builders nobody read are no longer exposed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ode-kilo-bridge

# Conflicts:
#	cli/src/composition/tool-profiles/opencode.ts
#	cli/src/contexts/tools/domain/behaviours/kilo/kilo-hooks-bridge.model.ts
#	cli/src/contexts/tools/domain/behaviours/opencode/opencode-hooks-bridge.model.ts
#	cli/src/contexts/tools/domain/bridges/event-bridge.ts
#	cli/tests/contexts/tools/domain/bridges/event-bridge.integration.test.ts
#	cli/tests/fixtures/hooks-routes/kilo/flat-translate.txt
#	cli/tests/fixtures/hooks-routes/kilo/plugin-install-twice.txt
#	cli/tests/fixtures/hooks-routes/kilo/plugin-install.txt
#	cli/tests/fixtures/hooks-routes/kilo/plugin-remove.txt
#	cli/tests/fixtures/hooks-routes/kilo/setup-plugins-reinstall.txt
#	cli/tests/fixtures/hooks-routes/opencode/flat-translate.txt
#	cli/tests/fixtures/hooks-routes/opencode/plugin-install-twice.txt
#	cli/tests/fixtures/hooks-routes/opencode/plugin-install.txt
#	cli/tests/fixtures/hooks-routes/opencode/plugin-remove.txt
#	cli/tests/fixtures/hooks-routes/opencode/setup-plugins-reinstall.txt
#	cli/tests/golden/snapshots/framework-build/golden.json
#	cli/tests/golden/snapshots/translate-install/golden.json
#	scripts/__tests__/fixtures/hook-payloads/README.md
…ncode-kilo-bridge

# Conflicts:
#	cli/src/contexts/tools/domain/behaviours/kilo/kilo-hooks-bridge.model.ts
#	cli/src/contexts/tools/domain/behaviours/opencode/opencode-hooks-bridge.model.ts
#	cli/src/contexts/tools/domain/bridges/event-bridge.ts
#	cli/tests/contexts/tools/hooks-runtime-bridges.integration.test.ts
#	cli/tests/fixtures/hooks-routes/kilo/flat-translate.txt
#	cli/tests/fixtures/hooks-routes/kilo/plugin-install-twice.txt
#	cli/tests/fixtures/hooks-routes/kilo/plugin-install.txt
#	cli/tests/fixtures/hooks-routes/kilo/plugin-remove.txt
#	cli/tests/fixtures/hooks-routes/kilo/setup-plugins-reinstall.txt
#	cli/tests/fixtures/hooks-routes/opencode/flat-translate.txt
#	cli/tests/fixtures/hooks-routes/opencode/plugin-install-twice.txt
#	cli/tests/fixtures/hooks-routes/opencode/plugin-install.txt
#	cli/tests/fixtures/hooks-routes/opencode/plugin-remove.txt
#	cli/tests/fixtures/hooks-routes/opencode/setup-plugins-reinstall.txt
#	cli/tests/golden/snapshots/framework-build/golden.json
#	cli/tests/golden/snapshots/translate-install/golden.json
#	scripts/__tests__/fixtures/hook-payloads/README.md
…kilo-bridge

# Conflicts:
#	cli/src/contexts/tools/domain/behaviours/opencode/opencode-hooks-bridge.model.ts
#	cli/tests/fixtures/hooks-routes/opencode/flat-translate.txt
#	cli/tests/fixtures/hooks-routes/opencode/plugin-install-twice.txt
#	cli/tests/fixtures/hooks-routes/opencode/plugin-install.txt
#	cli/tests/fixtures/hooks-routes/opencode/plugin-remove.txt
#	cli/tests/fixtures/hooks-routes/opencode/setup-plugins-reinstall.txt
#	cli/tests/golden/snapshots/framework-build/golden.json
#	cli/tests/golden/snapshots/translate-install/golden.json
#	docs/ARCHITECTURE.md
…kilo-bridge

# Conflicts:
#	cli/assets/hooks-runtime/host-bridge.cjs
#	cli/src/contexts/tools/domain/behaviours/kilo/kilo-hooks-bridge.model.ts
#	cli/src/contexts/tools/domain/behaviours/opencode/opencode-hooks-bridge.model.ts
#	cli/src/contexts/tools/domain/bridges/event-bridge.ts
#	cli/tests/contexts/tools/hooks-runtime-bridges.integration.test.ts
#	cli/tests/fixtures/hooks-routes/kilo/flat-translate.txt
#	cli/tests/fixtures/hooks-routes/kilo/plugin-install-twice.txt
#	cli/tests/fixtures/hooks-routes/kilo/plugin-install.txt
#	cli/tests/fixtures/hooks-routes/kilo/plugin-remove.txt
#	cli/tests/fixtures/hooks-routes/kilo/setup-plugins-reinstall.txt
#	cli/tests/fixtures/hooks-routes/opencode/flat-translate.txt
#	cli/tests/fixtures/hooks-routes/opencode/plugin-install-twice.txt
#	cli/tests/fixtures/hooks-routes/opencode/plugin-install.txt
#	cli/tests/fixtures/hooks-routes/opencode/plugin-remove.txt
#	cli/tests/fixtures/hooks-routes/opencode/setup-plugins-reinstall.txt
#	cli/tests/golden/snapshots/framework-build/golden.json
#	cli/tests/golden/snapshots/translate-install/golden.json
Both generated bridges now hand their host the hooks of one shared
bridgeHooks factory: SessionStart, Stop, the tool hooks and the user's
message are handled once, and each host template keeps only its folder,
its follow-up call, what ends a turn and where a person's message goes.

A turn continued by a Stop follow-up stays continued until a message
that is no follow-up starts a fresh one. A Stop no longer clears it, so
two plugins that each send a follow-up no longer make every Stop script
block again at the second turn. Hooks of a session run in the folder its
first event names. A matcher is split into its tool names once, through
the shared matcherNames, when the module is written.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A plugin's Stop hooks are now each told whether the turn continues at
the moment they run, so a hook after one that blocked stays silent
instead of sending a second follow-up. A message that cannot be read is
reported once, under UserPromptSubmit.

An event the OpenCode or Kilo bridge leaves out is reported by its
reason alone on install, which names the tool itself, and under the
tool on a build, through the bridge's one warning prefix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
blafourcade and others added 19 commits November 25, 2026 21:53
Hold the shared adapter once, on Kilo, and leave what the bridge body
does with an answer to event-bridge.integration. Remove the catches in
refuseToolUse, addPromptContext and the event hook with the tests that
faked their failures; keep the PostToolUse one, which the V2 adapter's
client reaches, under a test of that client. answerFrom reads only the
top-level additionalContext host-bridge.cjs prints, the hook table is
read from BRIDGE_EVENTS, and the two fake hosts share one client, one
record reader and one placement.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With the bridged-host cases folded onto one host, nothing went red for
an adapter that ignored stop_hook_active or continued a continued turn.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A child session is created naming its parent, as captured on OpenCode
1.19.3. The shared bridge body now remembers it and runs neither
SessionStart nor Stop for it, whatever event names it later.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…gin hooks

OpenCode 2.4.1 loads a plugin through `setup` alone, so the bridge lost
PreToolUse, UserPromptSubmit and SessionStart there, and ran Stop on an
execution event. Its V2 entrypoint now maps each of the host's hooks
onto the ones the shared bridge body hands OpenCode 1:

- a session's first prompt runs SessionStart, a child session told
  apart by the parent `session.get` names;
- the prompt hook runs UserPromptSubmit, and the context hook adds both
  answers to each request of the turn;
- execute.before relays PreToolUse, its throw the refusal;
- a V2 tool's `path` is read as the file it writes;
- experimental.idle runs Stop, its follow-up a steering synthetic
  message admitted before the hook returns.

Every case runs on payloads captured from OpenCode 2.4.1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ut of the shared bridge

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…idge

# Conflicts:
#	cli/src/contexts/tools/domain/hooks/wrapped-command-hooks-merge.ts
#	cli/src/contexts/translate/domain/layouts/build-flat.ts
#	cli/src/contexts/translate/domain/layouts/install-flat.ts
#	cli/tests/contexts/tools/testing/hooks-runtime-host.builder.ts
#	scripts/__tests__/fixtures/hook-payloads/README.md
The adapter OpenCode 1, OpenCode 2 and Kilo share now reads the moment
before a tool, each file by its path alone, and answers `refuse(reason)`
with exit code 2 and the reason on stderr, which the bridge already
throws out of the host's hook. A hook that speaks only the neutral
interface now refuses a captured write through the real bridge on all
three hosts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…pencode 2

OpenCode 2's client offers no way to queue a prompt, so a required
PostToolUse answer threw there, was reported as the call's failure and
skipped the call's later hooks. The shared bridge body now queues a
required finding only through a client that can, and appends it to the
tool's result either way. The framework build golden also takes the
OpenCode 2 events module an earlier commit changed without it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The shell case on OpenCode 1, Kilo and OpenCode 2 now asserts the
recorded command equals the captured call's. Dropping the command
spread in host-bridge.cjs turns exactly that case red on all three.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every captured OpenCode and Kilo payload, and every call the OpenCode 2
setup builds, carries the call's tool, session and arguments, the
message's parts and id, and the event's properties: the relay reads them
directly, as its stated limit says. The guards a capture motivates stay:
an idle event names no info, a part may carry no metadata. The disposed
guard names no capture, so it is stated as a limit. The OpenCode and
Kilo hook-route goldens move with the generated text.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The level-3 row says OpenCode 2 refuses a write or an edit only: its
patch tool's name was never observed. The working-on-cli reference no
longer grants the per-adapter helper copies an exception: that is the
owner's call.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ait on records by deadline

The driver fed the bridge a null event, an event with no properties and a
V2 call whose result was a string: shapes no OpenCode capture shows, which
the bridge no longer guards. It now sends the captured session creation,
idle and shell call, naming the folder the hooks run in. The record wait
counts a deadline, not attempts, so a loaded machine slowing the hook
process no longer reads as a missing call.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…idge

# Conflicts:
#	cli/src/contexts/translate/domain/layouts/install-flat.ts
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