Skip to content

feat(opencode): report submitted prompts to the prompt log via v2's admission hook (#304) - #305

Merged
amirlehmam merged 1 commit into
amirlehmam:masterfrom
Mattheinrichs:feat/opencode-v2-prompt-log
Oct 19, 2026
Merged

amirlehmam merged 1 commit into
amirlehmam:masterfrom
Mattheinrichs:feat/opencode-v2-prompt-log

Conversation

@Mattheinrichs

Copy link
Copy Markdown
Contributor

The prompt log has exactly two producers, and neither could see a prompt typed inside an OpenCode TUI: the shell integration's OSC 133 marks end when the TUI takes the screen, and the only sender of a UserPromptSubmit hook event was wmux-hook.js (Claude Code / Grok). The OpenCode plugin never sent one — no chat.message in the v1 hooks object, and setupV2 registered tool.* and shell.create.before only — so the outline, the Prompts pane and wmux prompts were empty for every OpenCode pane.

OpenCode v2 has a hook for exactly this: prompt admission (ctx.session.hook("prompt")), which runs for prompts a human submitted and excludes synthetic messages, shell messages and compaction controls. The plugin registers it, reads event.prompt.text, and reports via wmux hook --event UserPromptSubmit --prompt … — the same event App.tsx already turns into a recordAgentPrompt call, so the renderer side needed no new plumbing.

What this PR changes

  • Plugin (resources/opencode-plugin/wmux.js): registers session.prompt in setupV2 through the existing guarded register() (a v2 build without the hook loses the prompt log, never its own startup). Text is capped at 4000 chars — the same MAX_PROMPT wmux-hook.js uses — and deduped by messageID, because v2 documents admission as retry-safe but not exactly-once and two entries would put two jump marks on one line. Marker bumped 7 → 8 so installed copies update. v1 is untouched; the new handler key is inert there.
  • CLI (src/cli/wmux.ts): cmdHook gains --prompt, parsed by the existing pair loop rather than parseFlagArgs — that parser refuses a value that reads as one of its own flags, and a prompt whose entire text is --tool is a prompt, not malformed argv. COMMAND_SPECS.hook declares the flag (a check before anything reaches the pipe). hookParams is exported pure, with tests.
  • Renderer (src/renderer/utils/prompt-log.ts, App.tsx): hookEventSurface resolves the pane for the prompt log from either spelling. Claude's helper talks JSON-RPC itself and sends surfaceId; wmux hook goes through the CLI transport, which stamps the calling pane as caller. The two are deliberately not collapsed earlier: main's declared-state bridge gates on surfaceId, and a v2 OpenCode UserPromptSubmit has no Stop behind it, so it would set runDepth: 1 and leave the pane reading "working" for the whole trust window after every prompt.

Verified

  • npm test on Linux: the only failures are the pre-existing Windows/path.join ones (also failing on untouched master in this container), plus one pre-existing flaky mtime assertion in grok-context.test.ts unrelated to this change.
  • npm run typecheck, npm run lint on the touched files, npm run build:main and npm run verify:resources (the checked-in resources/cli/wmux.js is rebuilt).
  • Live test on Windows + real OpenCode v2 not possible from this machine — the plugin test suite covers the handler logic against the documented v2 payload, and WMUX_PLUGIN_DEBUG=1 should now show prompt + the hook … UserPromptSubmit CLI call on the first submission; worth a run before merging, together with a check that the v2 CLI in use actually exposes session.hook("prompt") (the guarded registration logs v2: session.prompt failed if not).

Known limitation, same as the session handle: on v2's shared opencode serve --service, the plugin's WMUX_SURFACE_ID names only the pane that started the server, so other panes on that server attribute their prompts to it. That is the existing behaviour of every server-side signal, and the documented reason a CLI-side half (#290 follow-up) is the eventual answer for remote/shared setups.

Closes #304

…m#304)

The prompt log's only agent-side producer is a `UserPromptSubmit` hook
event, and nothing on the OpenCode side ever sent one — the outline, the
Prompts pane and `wmux prompts` stayed empty for every OpenCode pane, on
every version. The plugin now registers v2's prompt-admission hook
(`ctx.session.hook("prompt")`) and reports the text via
`wmux hook --event UserPromptSubmit --prompt`, capped at 4000 chars like
`wmux-hook.js` and deduped by `messageID` (admission is retry-safe, not
exactly-once).

`wmux hook` gains `--prompt`, parsed by the existing pair loop rather
than `parseFlagArgs` so a prompt whose whole text is `--tool` is not read
as a missing value. The event carries the pane in the CLI transport's
`caller` spelling; the renderer resolves both spellings for the prompt
log only. Main's declared-state bridge gates on `surfaceId`, and a v2
OpenCode `UserPromptSubmit` has no `Stop` behind it — feeding it would
set `runDepth: 1` and leave the pane reading "working" for the trust
window after every prompt.

Plugin marker 7 → 8, or no installed copy picks the hook up. v1 is
untouched (the new handler key is inert there).

Closes amirlehmam#304
@amirlehmam
amirlehmam merged commit 7eab144 into amirlehmam:master Oct 19, 2026
@amirlehmam

Copy link
Copy Markdown
Owner

Merged, thanks @Mattheinrichs — ships in v2.29.0.

Two things you flagged as untested, checked before merging:

Plugin marker 8 will reinstall on first launch.

amirlehmam pushed a commit to Mattheinrichs/wmux that referenced this pull request Oct 20, 2026
…ued (amirlehmam#310)

Phase 2 of the CLI-side (TUI) half: prompts typed in a pane now reach the
prompt log even when the TUI is a client of a remote or shared OpenCode
server, where the server-side plugin (amirlehmam#304) can never run with a pane's
environment.

The client-side source is v2's `session.inbox.enqueued` — a public durable
event carrying `{ sessionID, inboxID, item }`. Only `item.type === "user"`
counts, which is the same exclusion set the server-side `session.prompt`
hook gets for free (synthetic messages, compaction controls and moves are
never something a human typed). `inboxID` dedupes admission; the text is
trimmed and capped at 4000 chars, the number every producer uses.

The event stream is the connected server's, so with several panes on one
server a prompt is attributed only when its session is the one being viewed
or open in a tab — pane B's prompt must not land in pane A's outline. The
report rides the same `wmux hook --event UserPromptSubmit --prompt` path
amirlehmam#305 wired end to end; `caller` carries the pane, and the renderer resolves
it for the prompt log only.

Plugin marker 1 → 2 so installed copies pick it up.

Part of amirlehmam#310
amirlehmam pushed a commit that referenced this pull request Oct 20, 2026
…ued (#310) (#312)

* feat(opencode): TUI half reports user prompts via session.inbox.enqueued (#310)

Phase 2 of the CLI-side (TUI) half: prompts typed in a pane now reach the
prompt log even when the TUI is a client of a remote or shared OpenCode
server, where the server-side plugin (#304) can never run with a pane's
environment.

The client-side source is v2's `session.inbox.enqueued` — a public durable
event carrying `{ sessionID, inboxID, item }`. Only `item.type === "user"`
counts, which is the same exclusion set the server-side `session.prompt`
hook gets for free (synthetic messages, compaction controls and moves are
never something a human typed). `inboxID` dedupes admission; the text is
trimmed and capped at 4000 chars, the number every producer uses.

The event stream is the connected server's, so with several panes on one
server a prompt is attributed only when its session is the one being viewed
or open in a tab — pane B's prompt must not land in pane A's outline. The
report rides the same `wmux hook --event UserPromptSubmit --prompt` path
#305 wired end to end; `caller` carries the pane, and the renderer resolves
it for the prompt log only.

Plugin marker 1 → 2 so installed copies pick it up.

Part of #310

* docs(opencode): a backup inside plugins/ shadows the live TUI half (#310)

OpenCode loads every directory under <config>/plugins/ as a plugin, so a
`plugins/wmux-cli.bak` copy registers the same `wmux.cli` id and the live
copy silently loses its load — no init line, no reports. Found in live
testing: the obvious backup spot made the new v2 plugin invisible until
the copy was moved out. Say where a backup belongs instead.

Part of #310
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.

OpenCode v2: user prompts never reach the prompt log — the plugin registers no prompt hook

2 participants