Repository navigation
feat(opencode): report submitted prompts to the prompt log via v2's admission hook (#304) - #305
Merged
amirlehmam merged 1 commit intoOct 19, 2026
Conversation
…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
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. |
This was referenced Oct 19, 2026
This was referenced Oct 19, 2026
Closed
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
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.
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
UserPromptSubmithook event waswmux-hook.js(Claude Code / Grok). The OpenCode plugin never sent one — nochat.messagein the v1 hooks object, andsetupV2registeredtool.*andshell.create.beforeonly — so the outline, the Prompts pane andwmux promptswere 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, readsevent.prompt.text, and reports viawmux hook --event UserPromptSubmit --prompt …— the same event App.tsx already turns into arecordAgentPromptcall, so the renderer side needed no new plumbing.What this PR changes
resources/opencode-plugin/wmux.js): registerssession.promptinsetupV2through the existing guardedregister()(a v2 build without the hook loses the prompt log, never its own startup). Text is capped at 4000 chars — the sameMAX_PROMPTwmux-hook.jsuses — and deduped bymessageID, 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.src/cli/wmux.ts):cmdHookgains--prompt, parsed by the existing pair loop rather thanparseFlagArgs— that parser refuses a value that reads as one of its own flags, and a prompt whose entire text is--toolis a prompt, not malformed argv.COMMAND_SPECS.hookdeclares the flag (a check before anything reaches the pipe).hookParamsis exported pure, with tests.src/renderer/utils/prompt-log.ts,App.tsx):hookEventSurfaceresolves the pane for the prompt log from either spelling. Claude's helper talks JSON-RPC itself and sendssurfaceId;wmux hookgoes through the CLI transport, which stamps the calling pane ascaller. The two are deliberately not collapsed earlier: main's declared-state bridge gates onsurfaceId, and a v2 OpenCodeUserPromptSubmithas noStopbehind it, so it would setrunDepth: 1and leave the pane reading "working" for the whole trust window after every prompt.Verified
npm teston Linux: the only failures are the pre-existing Windows/path.joinones (also failing on untouched master in this container), plus one pre-existing flaky mtime assertion ingrok-context.test.tsunrelated to this change.npm run typecheck,npm run linton the touched files,npm run build:mainandnpm run verify:resources(the checked-inresources/cli/wmux.jsis rebuilt).WMUX_PLUGIN_DEBUG=1should now showprompt+ thehook … UserPromptSubmitCLI call on the first submission; worth a run before merging, together with a check that the v2 CLI in use actually exposessession.hook("prompt")(the guarded registration logsv2: session.prompt failedif not).Known limitation, same as the session handle: on v2's shared
opencode serve --service, the plugin'sWMUX_SURFACE_IDnames 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