Repository navigation
fix(agents): detect a live OpenCode pane from its native OC | session title - #13957
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (12)
📝 WalkthroughWalkthroughOpenCode native 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: bf0520ab-b203-4d86-abb4-79621735ea36
📒 Files selected for processing (5)
src/renderer/src/components/sidebar/worktree-title-derived-agent-rows.test.tssrc/renderer/src/lib/agent-send-title-status.tssrc/renderer/src/lib/notes-send-agent-targets.test.tssrc/shared/agent-detection.test.tssrc/shared/agent-title-status.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/shared/opencode-terminal-title.ts (1)
5-10: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winShorten the predicate comments.
The six-line block explains valid marker shape, downstream consumers, allocation behavior, and trailing-space behavior. Keep the non-obvious rationale in one or two short lines.
As per coding guidelines, comments in
**/*.{ts,tsx,js,jsx}must be concise, non-obvious, and brief; one line is preferred.Proposed comment simplification
-// identity. The separator is the literal ` | ` OpenCode emits — an unspaced `OC|x` -// is some other tool's pipe-delimited title, not a send target. Used for both -// display-title preservation and tab-agent identity. -// Leading `\s*` stands in for a trim(): one OSC frame fans this predicate out -// across status, identity, agent-type and tab-title resolution, so the trimmed -// copy was pure allocation. Trailing space never mattered — nothing anchors $. +// Match the spaced native marker with at most one prefix. +// Reject unspaced lookalikes without allocating a trimmed copy.Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 55dc077d-7cff-4e07-956d-8be73265f22d
📒 Files selected for processing (5)
src/shared/agent-detection.test.tssrc/shared/agent-title-status.tssrc/shared/opencode-terminal-title.test.tssrc/shared/opencode-terminal-title.tssrc/shared/terminal-title-agent-type.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/shared/agent-title-status.ts
- src/shared/agent-detection.test.ts
… title OpenCode publishes `OC | <session>` as its OSC title, which carries no agent-name token. detectAgentStatusFromTitle gates status on a whole-token name match, so it returned null and every status consumer read a live OpenCode pane as a plain shell: no "Send notes to" entry, no title-derived sidebar row, and a title that the runtime's agent-presence check scored as neutral. Identity already resolved (getAgentLabel returns OpenCode); only activity was missing. Treat the native marker as a live idle agent, placed after the spinner and glyph checks so the decorated frames pinned by #8940 keep their status, and accept it in the send-readiness gate the way Claude's U+2733 prefix is accepted -- only a running OpenCode TUI ever publishes it.
Unspaced pipes like `OC|Build` match other tools and would mistakenly route non-OpenCode panes as send targets. Enforce literal ` | ` as OpenCode emits it. Also clarify that only spinner decorations carry working status, not keywords in the session summary.
OpenCode's native `OC | ` title marker now requires an active OpenCode process to authorize agent sends, preventing false detection when the marker is left on shell prompts. Extends wrapper prefix matching (ssh, tmux, etc.) and spinner glyph support. Adds permission-prompt blocking signals for guarded writes.
|
@coderabbitai Fixing. Will be in the next commit |
|
Tip For best results, initiate chat on the files or code changes.
You are interacting with an AI system. |
8b083b8 to
a968180
Compare
… title (stablyai#13957) * fix(agents): detect a live OpenCode pane from its native OC | session title OpenCode publishes `OC | <session>` as its OSC title, which carries no agent-name token. detectAgentStatusFromTitle gates status on a whole-token name match, so it returned null and every status consumer read a live OpenCode pane as a plain shell: no "Send notes to" entry, no title-derived sidebar row, and a title that the runtime's agent-presence check scored as neutral. Identity already resolved (getAgentLabel returns OpenCode); only activity was missing. Treat the native marker as a live idle agent, placed after the spinner and glyph checks so the decorated frames pinned by stablyai#8940 keep their status, and accept it in the send-readiness gate the way Claude's U+2733 prefix is accepted -- only a running OpenCode TUI ever publishes it. * fix(agents): require spaced `OC | ` marker for native OpenCode detection Unspaced pipes like `OC|Build` match other tools and would mistakenly route non-OpenCode panes as send targets. Enforce literal ` | ` as OpenCode emits it. Also clarify that only spinner decorations carry working status, not keywords in the session summary. * fix(agents): require OpenCode foreground process to validate native mark OpenCode's native `OC | ` title marker now requires an active OpenCode process to authorize agent sends, preventing false detection when the marker is left on shell prompts. Extends wrapper prefix matching (ssh, tmux, etc.) and spinner glyph support. Adds permission-prompt blocking signals for guarded writes.
ELI5
Orca figures out "is an agent running in this pane?" partly by reading the terminal's title. OpenCode names its tab
OC | <session>, which never contains the word "opencode" — so the check that looks for an agent's name found nothing and decided the pane was just a shell. The agent was right there, running, and Orca couldn't see it. Now Orca recognizes thatOC |marker.What Changed
Two lines of behavior in the shared title layer:
src/shared/agent-title-status.ts—detectAgentStatusFromTitle()returnsidlefor OpenCode's nativeOC | <session>marker. Placed after the spinner/glyph checks, so the decorated frames pinned by [Bug] opencode is displayed as Claude Code #8940 (OC | ⠋ ask claude about this→ working) keep their status; only undecorated frames go idle.src/renderer/src/lib/agent-send-title-status.ts—isExplicitIdleSendTitle()accepts the same marker as readiness proof, the way Claude's✳prefix is accepted. Only a running OpenCode TUI ever publishes it.Plus tests at all three seams: shared detection (including
oc | …/OCTOPUS | buildlookalike rejection), notes send targets, and sidebar rows.Why
detectAgentStatusFromTitlegates everything after the glyph checks behind a whole-token agent-name match.OC | Ad hoc buildhas no such token, so it returnednull— "not an agent pane" — even thoughgetAgentLabel()already resolved the very same title to OpenCode. Identity was known; activity was not. Every status-derived surface then dropped a live pane:deriveNotesSendAgentTargetsonly lists panes whose title passesdetectAgentSendTitleStatus;nullmeant never listed.buildTitleDerivedAgentRowsbails on!status.classifyAgentTitlescored the pane neutral, falling through to the slower foreground-process probe.A second gate compounded it: even with a status, the send path requires an explicit readiness marker (
ready/idle/done,✳,◇). OpenCode publishes no readiness word at all, so the native marker had to be accepted as its equivalent.Scoped deliberately to the native marker rather than loosening the name-token rule, which exists to stop cwd titles like
opencode-blinkerfrom minting a false agent identity.Linked Issue
No filed issue — reported directly with the screenshot now used as the "before" below.
Visual Proof
Validated in a dev build launched from this branch, driven over CDP with playwright-cli.
Before — a live OpenCode session is absent from the menu:
After — the OpenCode pane is listed and enabled (
OpenCode · Idle · just now · OC | Ad hoc build), and the sidebar shows it as an Idle OpenCode row. A plainzshpane appears in neither (negative control — visible as the untouchedzshtab):Sidebar — "2 agents" for the worktree, with a real OpenCode 1.18.16 TUI live in the pane behind it:
Testing
Platform tested: macOS. The change is pure string classification in
src/shared, with no platform-dependent behavior, so Linux/Windows/SSH behave identically — the same title arrives over the same pipeline on every host.Manual, in a dev build from this branch:
opencode; send it a prompt so the session earns a title (it then publishesOC | <session>).zshgets neither a row nor a menu entry.Automated:
src/shared,src/renderer/src/lib, andsrc/renderer/src/components/sidebar— 10426 passing on the rebased branch.Review
src/sharedlogic identical on macOS/Linux/Windows.tmux | OC | …) is covered by the existing regex and by test. No wire change: this reads a title both sides already exchange, and it changes only local classification, so a new client against an old host and vice versa behave the same.nullnative marker changes.Known remaining case
A fresh OpenCode session that hasn't been prompted yet publishes the bare title
OpenCode, notOC | …. That already gets a sidebar row, but stays out of the send menu, because the send gate treats a bare agent name as identity rather than readiness. Left alone on purpose: a shell sitting in a directory namedopencodeproduces the identical title, and promoting it would surface a menu entry that the runtime then refuses on click. Both states are visible in the sidebar screenshot above — two OpenCode rows, one send target.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Lint (oxlint + oxfmt) and
typecheck:noderun clean locally. Two pre-existing failures insrc/main/ssh/ssh-relay-upload-stage-commands.test.tsreproduce on a cleanmaincheckout and are unrelated to this change.AI Disclosure
Written with Claude Code (Opus 5). The rendered validation above was run by an OpenCode agent driving the dev build over CDP.