Skip to content

fix(agents): detect a live OpenCode pane from its native OC | session title - #13957

Merged
AmethystLiang merged 3 commits into
mainfrom
active-opencode-not-detected
Aug 12, 2026
Merged

AmethystLiang merged 3 commits into
mainfrom
active-opencode-not-detected

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

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 that OC | marker.

What Changed

Two lines of behavior in the shared title layer:

  • src/shared/agent-title-status.ts — detectAgentStatusFromTitle() returns idle for OpenCode's native OC | <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 | build lookalike rejection), notes send targets, and sidebar rows.

Why

detectAgentStatusFromTitle gates everything after the glyph checks behind a whole-token agent-name match. OC | Ad hoc build has no such token, so it returned null — "not an agent pane" — even though getAgentLabel() already resolved the very same title to OpenCode. Identity was known; activity was not. Every status-derived surface then dropped a live pane:

  • "Send notes to" — deriveNotesSendAgentTargets only lists panes whose title passes detectAgentSendTitleStatus; null meant never listed.
  • Sidebar / dashboard rows — buildTitleDerivedAgentRows bails on !status.
  • Runtime agent-presence — classifyAgentTitle scored 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-blinker from 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:

before-send-notes-menu.png

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 plain zsh pane appears in neither (negative control — visible as the untouched zsh tab):

orca-proof-3-send-notes-menu-final.png

Sidebar — "2 agents" for the worktree, with a real OpenCode 1.18.16 TUI live in the pane behind it:

orca-proof-2-sidebar-both-opencode-rows.png

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:

  1. Open a terminal pane in a worktree and run opencode; send it a prompt so the session earns a title (it then publishes OC | <session>).
  2. Confirm the pane renders as an Idle OpenCode row in the worktree sidebar.
  3. Open the diff view → AI notes → Send; confirm OpenCode is listed under "Send notes to" and is enabled.
  4. Negative control: a plain shell pane titled zsh gets neither a row nor a menu entry.

Automated: src/shared, src/renderer/src/lib, and src/renderer/src/components/sidebar — 10426 passing on the rebased branch.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Review

  • Security — no new input surface; classification of a string Orca already parsed.
  • Cross-platform — no platform branches touched; src/shared logic identical on macOS/Linux/Windows.
  • Remote SSH — the marker's optional multiplexer prefix (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.
  • Backwards compatibility — additive. Titles that previously classified continue to classify identically; only the previously-null native marker changes.
  • Performance — one extra regex test, reached only after the existing glyph/spinner checks fall through.

Known remaining case

A fresh OpenCode session that hasn't been prompted yet publishes the bare title OpenCode, not OC | …. 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 named opencode produces 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

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Lint (oxlint + oxfmt) and typecheck:node run clean locally. Two pre-existing failures in src/main/ssh/ssh-relay-upload-stage-commands.test.ts reproduce on a clean main checkout 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.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1546c1e5-a85f-498d-8573-13df6a90d838

📥 Commits

Reviewing files that changed from the base of the PR and between 8b083b8 and a968180.

📒 Files selected for processing (12)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/terminal-opencode-send-guard.integration.test.ts
  • src/renderer/src/lib/agent-send-title-status.test.ts
  • src/renderer/src/lib/agent-send-title-status.ts
  • src/renderer/src/lib/notes-send-agent-targets.test.ts
  • src/renderer/src/lib/notes-send-agent-targets.ts
  • src/renderer/src/lib/use-tab-agent-opencode-native-title.test.ts
  • src/shared/agent-detection.test.ts
  • src/shared/agent-title-status.ts
  • src/shared/opencode-terminal-title.test.ts
  • src/shared/opencode-terminal-title.ts

📝 Walkthrough

Walkthrough

OpenCode native OC | <session> titles are recognized after validation of spacing, prefixes, status glyphs, and title content. Shared and renderer status detection classifies these titles as idle or working. Runtime checks use native titles with process and PTY evidence, while permission prompts remain authoritative. Renderer target detection and sidebar rows now cover live and stale OpenCode panes.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: detecting live OpenCode panes from native session titles.
Description check ✅ Passed The description is detailed and covers the change, rationale, testing, visual proof, review considerations, and checklist; the required linked issue is the only notable omission.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5ea7df1 and 50caaea.

📒 Files selected for processing (5)
  • src/renderer/src/components/sidebar/worktree-title-derived-agent-rows.test.ts
  • src/renderer/src/lib/agent-send-title-status.ts
  • src/renderer/src/lib/notes-send-agent-targets.test.ts
  • src/shared/agent-detection.test.ts
  • src/shared/agent-title-status.ts

Comment thread src/shared/agent-detection.test.ts Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/shared/opencode-terminal-title.ts (1)

5-10: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Shorten 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

📥 Commits

Reviewing files that changed from the base of the PR and between 50caaea and 8b083b8.

📒 Files selected for processing (5)
  • src/shared/agent-detection.test.ts
  • src/shared/agent-title-status.ts
  • src/shared/opencode-terminal-title.test.ts
  • src/shared/opencode-terminal-title.ts
  • src/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.
@AmethystLiang

Copy link
Copy Markdown
Contributor Author

@coderabbitai Fixing. Will be in the next commit

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@AmethystLiang Thanks. I will review the update after the next commit.

You are interacting with an AI system.

@AmethystLiang
AmethystLiang force-pushed the active-opencode-not-detected branch from 8b083b8 to a968180 Compare August 12, 2026 07:07
@AmethystLiang
AmethystLiang merged commit a812246 into main Aug 12, 2026
43 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
… 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.
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