Skip to content

feat(runtime): report PTY agent state from the OSC 7501 Program Status Protocol - #244

Closed
waterbang wants to merge 1 commit into
mainfrom
feat/osc-7501-program-status
Closed

waterbang wants to merge 1 commit into
mainfrom
feat/osc-7501-program-status

Conversation

@waterbang

Copy link
Copy Markdown
Collaborator

What

Every agent running in a native PTY currently reports effective_working_state="waiting" with effective_working_reason="pty_running_state_unknown", because CCCC deliberately never guesses idle from terminal output. Several CLIs now report their own state in-band through the OSC 7501 Program Status Protocol. Measured with the real CLIs in a PTY:

CLI Behaviour
Claude Code 2.1.331 Sends the ESC]7501;? query and reports only after the terminal answers: idle, working on a prompt, done at turn end.
Codex 0.169.1 Reports idle / working / done without a query.
Antigravity 1.5.20 Queries, then e.g. blocked:kind=auth "Sign in required" and blocked:kind=permission "Trust this folder?".

This PR makes CCCC a terminal that speaks the protocol and turns those reports into agent state, behind a runtime-agnostic model.

Runtime (crates/cccc-runtime)

  • program_status.rs: the wire grammar (BEL/ST terminators, base64 msg/title, 4096-byte cap, malformed reports discarded, child id records ignored for the root), a scanner that survives sequences split across reads, and the latest root record per PTY launch. OSC 133;A, ESC c and the end of the launch's output clear it.
  • terminal_query_responder.rs answers the query with ESC]7501;?:states=idle,working,done,blocked,error:kinds=permission,question,auth ESC\, within the existing per-read response and OSC length limits.
  • Status is updated in the same output pass as the transcript, under its own lock, and exposed as cccc_runtime::program_status(group, actor) like last_output. The session owner serves it through a new TerminalRead::ProgramStatus; an older owner rejects the read and the actor simply has no program status.

Daemon: one normalized status model (crates/cccc-daemon/src/ops/agent_status/)

  • One status type (state, reason, source, updated_at, blocked kind, message, progress, turn ended) and one resolver with the precedence: managed session > Antigravity hook > program_status > configured-managed pending > Dots > headless/PTY fallbacks.
  • Each source is a small provider (managed.rs, antigravity_hook.rs, program_status.rs, dots.rs). Only providers know which runtime speaks which protocol; nothing above the resolver branches on the runtime.
  • working_state.rs becomes a thin consumer. ready_for_mail_notice and the pre-submission rechecks use the resolver, matched to the exact launch (pid and start time): idle/done/error admit early Mail notices, blocked and working do not.
  • New projection fields effective_status_source, effective_blocked_kind, effective_status_message, effective_progress; existing keys keep their meaning.

Web: decisions come only from the normalized fields. A structured source overrides terminal heuristics; blocked shows as needing input with its kind and message and rings for attention. The store only merges the new fields when a payload carries them.

Docs: the IPC standard documents the model, precedence, the OSC 7501 contract and the Mail-notice rule; docs/guide/runtimes.md explains it for users and now says new Antigravity PTYs get their idle state from OSC 7501 instead of ordinary Mail timing.

Verification

  • Grammar/scanner unit tests (12) and query-reply tests through the real OutputReader.
  • Daemon: resolver precedence tests; a PTY actor whose command prints OSC 7501 reports drives effective_working_reason="program_status" and early-Mail gating; session_owner::program_status_tests runs a real owner child process, asserts the in-process registry has no such session, and checks Mail is withheld while blocked and delivered once idle. Existing working_state tests pass unchanged.
  • Each new behaviour was broken on purpose (responder not answering, provider returning nothing, owner not serving the read, old store) and the matching tests failed.
  • scripts/quality_gate.sh fast on this branch passes (clippy, workspace, runtime, daemon nextest, doc and Web checks); the touched Web test files pass on this base (2378 tests).
  • Live: a terminal-mode Antigravity launched by CCCC showed blocked / permission / "Trust this folder?" in a new folder, and idle → working → idle with source=program_status around a one-line prompt in a trusted folder, with no hooks installed.

…s Protocol

Every native PTY agent without a managed session or Antigravity hook read
as "waiting / pty_running_state_unknown", because CCCC deliberately never
infers idle from terminal output. Claude Code, Codex and Antigravity now
report their own state in-band with OSC 7501 (Claude Code and Antigravity
only after the terminal answers the capability query), so CCCC can show
real working, idle and blocked state without guessing.

- runtime: a focused program_status module ports the wire grammar (Orca,
  MIT): key=value bodies, BEL or ST, base64 msg/title, the 4096-byte cap,
  child records ignored for the root, and OSC 133;A / ESC c / state=clear
  ending the record. The output reader parses reports in the same pass as
  terminal queries, the query responder answers ESC]7501;? with the exact
  supported states and kinds, and the record is kept per launch (cleared
  when its output ends) under its own lock so status reads never wait on
  transcript I/O.
- session owner: a new terminal_read kind program_status carries the record
  from the owner process to the daemon; an older owner rejects it and the
  Actor simply has no program status.
- daemon: a runtime-agnostic agent_status module defines one normalized
  status (state, reason, source, updated_at, blocked kind, message,
  progress) with one provider per source (managed session, Antigravity
  hook, OSC 7501, Dots) and resolves precedence in one place: managed >
  hook > program status > fallbacks. working_state and the Mail notice
  gates are thin consumers. Projections add effective_status_source,
  effective_blocked_kind, effective_status_message and effective_progress;
  existing keys keep their meaning. An idle, done or error report admits
  early Mail notices like an idle hook; working and blocked do not, and the
  pre-submission recheck reads the exact launch.
- web: trusts any structured source over terminal heuristics, shows a
  blocked agent as needing input with its kind and message, and rings it
  for attention, all from the normalized fields only.
- docs: the IPC standard documents the normalized model, precedence and
  the OSC 7501 contract; the runtime guide explains it for users.
ChesterRa added a commit that referenced this pull request Dec 1, 2026
Observe root OSC 7501 reports from the current PTY when managed
session or hook state is unavailable. Name the terminal as the source
and show the reported wait reason when known.

Keep reports scoped to the PTY across daemon reattachment. Group
state and Mail use the established working-state rules. Free-form
terminal text stays in the transcript.

Based on the terminal status proposal in #244.

Verified workspace formatting and Clippy, 26 isolated Rust tests,
5,635 Web tests, and 138 pytest tests. Verified the sign-in wait with
Antigravity CLI 1.5.20 on Linux in an offline browser smoke test and
exercised other transitions with a PTY fixture.

Co-authored-by: waterbang <hsb@truesightai.com>
@ChesterRa ChesterRa closed this Dec 1, 2026
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