Skip to content

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

Merged
amirlehmam merged 2 commits into
amirlehmam:masterfrom
Mattheinrichs:feat/opencode-tui-prompts
Oct 20, 2026
Merged

amirlehmam merged 2 commits into
amirlehmam:masterfrom
Mattheinrichs:feat/opencode-tui-prompts

Conversation

@Mattheinrichs

Copy link
Copy Markdown
Contributor

Stacked on #311 — phase 2 of #310. Review after #311 merges; this diff will shrink to the phase-2 commits alone once master carries them.

Why

The server-side prompt hook (#304) needs the pane's environment, which a remote or shared server process does not have. The TUI half from #311 runs where the prompt is actually typed; this PR teaches it to report the prompt itself.

Signal, from the v2 schema (packages/schema/src/session-event.ts + session-inbox.ts):

session.inbox.enqueued   { sessionID, inboxID, item }
item = { type: "user", payload: { text, … }, delivery }
     | { type: "synthetic" | "compaction" | "move", … }

It is a public durable event, so data.on sees it against a remote server. Only item.type === "user" is reported — the same exclusions the server-side session.prompt hook gets for free. inboxID dedupes admission (v2 documents admission as retry-safe, not exactly-once); the text is trimmed and capped at 4000 chars, the number wmux-hook.js and the server half use.

Attribution

data.listen/data.on is the whole connected server's stream: with several panes on one remote server, pane B's session events arrive in pane A's TUI too. The reporter therefore only attributes prompts for sessions this TUI hosts — the one being viewed, or one open in a tab (ui.tabs.list(), read defensively for the host's field name). A tab-less TUI falls back to the current route.

Path

wmux hook --event UserPromptSubmit --prompt … — exactly what #305 wired end to end. caller is stamped by the CLI transport, hookEventSurface resolves it, and the prompt log renders it. No main, renderer, or CLI changes in this PR.

Tests

11 new cases in opencode-tui-core (user vs synthetic/compaction/move, empty payloads, validator, tab extraction, hosted vs foreign sessions, inboxID replay dedupe, 4000-char cap) and the entry-shape test now asserts the subscription and marker 2. Full suite: only the pre-existing Windows/path.join failures that also fail on untouched master in this container.

Live check (after #311 + this): in the WSL pane, node "$WMUX_CLI" opencode-tui (rewrites v1 → v2), restart OpenCode with WMUX_PLUGIN_DEBUG=1, submit a prompt — the debug log should show prompt {"chars":…} and cli ["hook","--event","UserPromptSubmit","--prompt",…], and the entry should land in the Prompts pane / wmux prompts. Two panes on the same remote server is the attribution check: prompt in B must not appear in A.

Part of #310

@Mattheinrichs

Copy link
Copy Markdown
Contributor Author

Live verification on Windows wmux 2.30.0 + a WSL pane whose TUI is a client of a remote OpenCode server (@opencode/cli TUI 2.0.26). Both phases of #310 were exercised on this branch:

Load + session handle

  • wmux opencode-tui → Installed … (v2); re-run → already current (v2); marker 2 on tui.js.
  • On load: init {surface, runtime: /home/…/node, cli: /mnt/c/…/wmux.js}, session ses_…, cli ["report-session", …] ok — the handle lands even though the server process never sees WMUX_*.
  • wmux report-session / release-agent probed directly against the same main: record appears with sessionId + sessionProvider: opencode, release removes it. So the store path is good; wmux agent-state visibility is per wmux instance/pipe, expected.

Prompt log (this PR)

  • session.inbox.enqueued was delivered through data.on (not just the data.listen type logger), and both fresh prompts produced:
    prompt {"chars":20} → cli ["hook","--event","UserPromptSubmit","--prompt","WMUX-PHASE2-TEST-…"] ok.
  • Per-surface wmux prompts --json showed only the prompt submitted in that pane, and attribution held in both directions (A's text not under B, B's not under A) with the two TUIs on different sessions.
  • Both prompts appeared in the sidebar Prompts pane. No route: threw, inbox: subscribe failed/threw, or cli … failed lines.

Loader finding — fixed in docs
OpenCode loads every directory directly under <config>/plugins/ as a plugin. The natural backup (plugins/wmux-cli.bak/ kept beside the plugin) registered the same wmux.cli id, shadowed the live copy, and produced silence: no init, no reports, while the old copy kept loading. Moving the backup outside plugins/ fixed it and OpenCode hot-reloaded v2 without a restart. Added a warning to the TUI-half docs in this branch: keep backups outside plugins/.

Still marked draft until #311 lands; then this is ready.

…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
…mirlehmam#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 amirlehmam#310
@amirlehmam
amirlehmam marked this pull request as ready for review October 20, 2026 00:12
@amirlehmam
amirlehmam force-pushed the feat/opencode-tui-prompts branch from b9526cd to 8db42d2 Compare October 20, 2026 00:12
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-20T00:15:21.866812Z 8db42d2 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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.

2 participants