Skip to content

#907 Session Chat: shells in the background work pill - #927

Merged
ivanfenenko merged 16 commits into
mainfrom
feature/907-background-shells-pill
Nov 1, 2026
Merged

ivanfenenko merged 16 commits into
mainfrom
feature/907-background-shells-pill

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #907

Session Chat's background work pill now counts the shells the agent runs, next to subagents ("1 subagent · 2 shells"). The panel gets a Shells section, and tapping a shell opens a half-height sheet with its live output, Copy, and Stop shell where the server supports it.

What changed

  • Both protocols, one UI. Feature code and Screen Models only see the new AgentShell product type; the protocol difference stays in the domain layer.
    • v1: running bash tool parts of the open session. Output comes from state.metadata.output on message.part.updated. No per-shell Stop (v1 can only abort the whole session), so the button is hidden.
    • v2: GET /api/shell (on open and every reconnect) plus shell.created / shell.exited / shell.deleted, filtered by metadata.sessionID. Output is polled from /api/shell/:id/output only while the sheet is visible and the app is in the foreground. It reads the tail first, so a long log doesn't download from the start. Stop calls DELETE /api/shell/:id. Gated on the server's /openapi.json declaring GET /api/shell.
  • v1 end states: an aborted or timed-out bash call ends as completed with a <shell_metadata> notice; it now reads as Stopped / Timed out.
  • Design system: new OpenCodeShellRow on both platforms, with Component Gallery entries. The subagents sheet became the "Background work" panel.
  • API contract: api/opencode-shells.openapi.yaml documents the v2 routes and events as observed on opencode 2.2.
  • Scenario harness: shell-foreground-stream (v1 and v2), shell-background and shell-two-running (v2), with server-side checks.

Checks

  • Android: :app:testDebugUnitTest 3140 passed (1 skipped), :app:assembleDebug OK.
  • iOS: full OpenCode MobileTests passed (3070) before the review fixes; after them, the shell, background-work, pill-slot and Session Chat view model suites passed (325).
  • Harness check.mjs --variants for the three shell scenarios passes on opencode v1 1.19.5 and v2 dev.
  • Real apps against the scenario harness on both protocols: pill, panel, live output, Stop (v2), and the ended state (v1). Screenshots are in the comment below.
  • gitleaks: no leaks.

Risks / Follow-ups

  • Not checked in the real apps: the cold-start and reconnect fixes (a v2 server whose contract has not been read yet, and shells that end while disconnected). Both have unit tests only.
  • On Android v1, one session started by the harness as another client opened with an empty timeline, although the server returned its messages. A session started from the app worked. I did not check whether main does the same.
  • Small visual differences remain: iOS clips the command in the v1 sheet to one line, and Android shows two.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

ivanfenenko and others added 16 commits November 1, 2026 17:00
shell-foreground-stream (v1 and v2), shell-background and shell-two-running (v2) exercise the background work pill's shells. The harness can list, read and stop a session's v2 shells as another client, and check.mjs asserts named server-side facts per protocol (serverChecks) with a per-scenario timeout.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
v1 reads running shells and their output from bash tool parts. v2 lists
/api/shell, follows shell.created/exited/deleted, polls output tail
first and stops a shell with DELETE, gated on the server declaring
GET /api/shell.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Session Chat binds the open session's shells, lists running ones in
panel order, counts them on the background work pill, and owns the
shell output sheet: output is read only while the sheet is observed,
Stop shows Stopping… until the shell ends, and a failed stop shows an
inline error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A running agent shell for the background work panel: terminal glyph,
one-line monospace command, optional description and a live timer.
Listed in the Component Gallery with running and long-command states.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The subagents sheet becomes the background work panel with Subagents
and Shells sections. A shell row opens a half-height output sheet with
a live status line, Copy, and Stop shell where the server supports it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AgentShell and AgentShellOutput product types behind a protocol-selected
remote: v1 reads running bash tool calls and their metadata output from the
transcript; v2 lists GET /api/shell, follows shell.created/exited/deleted,
polls output tail-first while observed, and stops with DELETE. The v2 remote
is used only when /openapi.json declares GET /api/shell.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A running shell row next to OpenCodeChildSessionRow: terminal glyph in the
leading slot, the command in monospace on one line, the description below,
and a live timer. The gallery shows running and long-command states.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The pill counts running shells with subagents ("1 subagent · 2 shells"), the
panel becomes Background work with Subagents and Shells sections, and a shell
row opens a half-height output sheet with a live status line, Copy, and Stop
shell where the server can stop it. Output is read only while the sheet is up
and the app is active.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ure/907-ios' into feature/907-background-shells-pill
…names

v1 ends an aborted or timed-out bash call as completed with no exit code
and a <shell_metadata> notice; map those to Stopped and Timed out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Read v2 shell support again on every reconnect, so a cold start that
opens Session Chat before the contract probe still shows shells. Only
shells created while a list request is in flight survive its answer.
An open sheet whose shell leaves without an end event ends locally.
Output read before a failed page is kept. Durations drop zero parts,
v1 output at the 30,000-character cap counts as truncated, and failed,
timed-out and non-zero exits use the error color, matching iOS.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… lazily

On a cold start the v2 contract is read after Session Chat binds, so the first
pick could be "no shells" for good. The shell list now picks v1, v2 or none
again on every stream (re)connect. Remotes get a transcript subscription they
open only when they read it, so v2 and unsupported servers hold none.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An open output sheet whose shell leaves the list while running, or whose
output is gone (404), now ends it locally: Stopped when Stop was in flight,
else Exited, so the sheet no longer stays Running or Stopping. A shell list
that ends can start again. Loaded messages reach the shells only when they
change. An ended shell with no end time shows its state alone, and opening a
shell output logs against the background work panel.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ivanfenenko

Copy link
Copy Markdown
Collaborator Author

Evidence: real apps against the scenario harness

iPhone 17 simulator (iOS 26.5) and Pixel 9a emulator, seeded against the scenario harness. Harness data only.

v2 (shell-two-running: two background shells plus a subagent)

Step iOS Android
Pill counts subagents and shells iOS pill Android pill
Background work panel iOS panel Android panel
Live output sheet with Stop iOS output Android output
After Stop shell iOS stopped Android stopped
Pill drops to one shell iOS one shell Android one shell

v1 (shell-foreground-stream: a 60 s foreground bash call; no per-shell Stop on v1)

Step iOS Android
Pill iOS v1 pill Android v1 pill
Panel iOS v1 panel Android v1 panel
Live output, Copy only iOS v1 output Android v1 output
Command finished iOS v1 exited Android v1 exited

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Automated review: no finding that 2+ of 2 passes agreed on.

6 finding(s) from a single pass, not posted
  • ios/OpenCode Mobile/OpenCode Mobile/UI/SessionChat/Region/SessionChatShells.swift:75 high: iOS shells keep querying the old directory after session.moved (muse-spark-1.3-contributor)
  • ios/OpenCode Mobile/OpenCode Mobile/Domain/Shell/AgentShellRemote.swift:219 medium: iOS v2 shell output polls forever after the shell ends (muse-spark-1.3-contributor)
  • ios/OpenCode Mobile/OpenCode Mobile/Domain/Shell/V2AgentShellAdapter.swift:19 medium: iOS v2 shells always drop the description (muse-spark-1.3-contributor)
  • ios/OpenCode Mobile/OpenCode Mobile/UI/SessionChat/Region/SessionChatShells.swift:121 medium: Transcript feed keeps the previous session's messages after rebind (glm-5.3-flash)
  • android/app/src/main/java/dev/opencode/mobile/domain/shell/AgentShellDomainAdapter.kt:179 low: Android ignores string-encoded shell exit codes (muse-spark-1.3-contributor)
  • ios/OpenCode Mobile/OpenCode Mobile/Domain/Shell/V2AgentShellAdapter.swift:101 low: V2AgentShellList.replace drops known ended shells on every relist (glm-5.3-flash)

opencode pr-review · passes: muse-spark-1.3-contributor, glm-5.3-flash, deepseek-v4.1-flash · $0.213 · 1 pass(es) failed

@ivanfenenko
ivanfenenko merged commit ccf1538 into main Nov 1, 2026
@ivanfenenko
ivanfenenko deleted the feature/907-background-shells-pill branch November 1, 2026 20:10
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.

Session Chat: shells in the background work pill

1 participant