Skip to content

The desk, DC2: the bridge — a machine's sessions watched and driven locally (7.155.0) - #195

Merged
SSFSKIM merged 44 commits into
mainfrom
worktree-smns-erb
Oct 15, 2026
Merged

SSFSKIM merged 44 commits into
mainfrom
worktree-smns-erb

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Oct 15, 2026

Copy link
Copy Markdown
Owner

The desk, child DC2: the bridge. Every Claude Code session on a machine can now be watched and driven from that machine, with no hub:

  • live chunks, subagents included;
  • steer, interrupt, model, compact;
  • answers and decisions for permission prompts and questions;
  • delivery of a log event as the human's words;
  • live export of <message> spans and async questions to the project log.

The parts:

  • The mod, hooks/mods/bridge.tsx. It is registered first in hooks/mods/register.tsx, so its hooks are the outermost.
  • Its session-lifetime child, sminos bridge (skills/sminos/scripts/sminos_bridge.py). It serves the session's endpoint at $SMINOS_HOME/bridge/<session>.sock.
  • The verbs, sminos watch|steer|interrupt|model|compact|decide|answer (sminos_control.py).

The protocol, DX5, is in the plan's Interfaces section. The composite spec (MAWS, docs/doperpowers/specs/2026-10-15-desk-design.md) has taken every extension of it.

  • Plan, decisions and retrospective: docs/doperpowers/plans/2026-10-15-arkho-desk-c2-bridge.md.
  • Controller report: docs/doperpowers/plans/2026-10-15-arkho-desk-c2-report.md.
  • Version: 7.155.0, above main's 7.154.0. DC4's branch re-bumps after this one merges.
  • No Closes line: DC2 is a child of a composite spec, not a GitHub issue.

Validation Evidence

  • G1. The local protocol is written and reviewed. DX5 is in the plan's Interfaces section: M1's text, then the M2–M4 extensions and the final-review rows. Each milestone's task review checked DX5 against the code, and so did the whole-branch high review: "correct — … no material findings" on its third pass.
  • G2. Local control on a terminal session and a --bg job. Live walk tests/mods/live-walk-check.py passed 45/45 (M4 report, "The live walk"). It covered:
    • steer during a 15 s Python sleep: the sleep ran to its end and the steer was read next;
    • interrupt: the turn stopped in 0.27–0.57 s and the backgrounded Bash was stopped;
    • decide deny, and answer "B";
    • compact asked mid-turn, which ran at the turn's end;
    • model sonnet, with settings.json bytes and mtime unchanged;
    • send --wait through a bridged seat;
    • a foreground subagent's Bash stopped by interrupt;
    • the [ answer ] press in the terminal.
      The earlier live checks were re-run on M4's code: live-bridge-check.py 15/15, live-control-check.py 22/22, live-requests-check.py 18/18.
  • G3. Settlement, live and in the requests test. The CLI first, the terminal first (through claude attach on the --bg job), both at once, and a late CLI answer refused as already settled. A subscriber arriving after the settlement sees the request settled. Settlement comes from the engine's tool_decision record, keyed by call id; a witness mod pins that record.
  • G4. Live export. A <message> reached the log 0.01 s after its row's notice, 10.5 s before the Bash result. The Stop hook then found one event under the same (kind, src).
  • Suites on the merged tree (fdbe2db0, plus docs):
    • tests/mods/run-mods-tests.sh: 295 pass, 0 fail, and ask search: all checks passed.
    • tests/sminos/run-sminos-tests.sh, every bridge file passing: all 99 bridge assertions passed, all 79 bridge control assertions passed, all 68 bridge request assertions passed, all 15 bridge export assertions passed, all 31 bridge order assertions passed. No stand-in left: pgrep -f 'ctl.py supervisor' gave 0.
    • The non-bridge failures are timing checks under load average 220–250. In the worktree they were send --wait (3 assertions) and the daemon's "say lands within two seconds" (2.4 s).
      • Exporting this branch's HEAD to /tmp and running it at load ~100 gave 3 of 1539 assertions FAILED: "reading chat is the first sminos instruction", the daemon two-second check, and "at most once more: two frames in all" (the known flake DC4 logs). send --wait passed there.
      • Main exported to /tmp, at the same load, gave 1 of 1534 assertions FAILED ("reading chat is the first sminos instruction").
    • scripts/lint-shell.sh is clean.

Unresolved Review Findings

  • The kept-notification count can race the watcher. tests/sminos/test-bridge-control.sh (the kept failure and recovery assertions). The M2 task review rated this Minor and non-blocking: the baseline count is sampled without first syncing on the previous recovery. Left because it has not flaked in any run. The fix is to sync on the recovery event before sampling.
  • claude plugin validate has two baseline warnings. One is the root CLAUDE.md not being loaded as project context; the other is the frontmatter of agents/codex/README.md. Both predate this branch (identical at 4dddfb4b) and are outside DC2's scope.

Residue

  • Sweep $SMINOS_HOME/bridge/<id>.json. The child keeps one small file per session that ever had a model choice or a bridged delivery, and nothing removes them. Discovery lists *.sock only, so nothing misreads them. Offered to DC7, whose daemon lists the directory anyway.
  • Split hooks/mods/bridge.tsx. It is about 1,850 lines, carrying the stream, control, requests, export and ordering. $ may only be passed to functions in the same file, so a split needs closures made at session.start. Worth a ticket before the next feature lands in it.
  • Notices for the plugin's own appends. Rows written by the bridge's own $.session.compact (6 rows per compaction) and the engine's reload line get no notice. Consumers therefore release them as unnamed rows after 2 s. Closing this needs the engine to raise session.append for a plugin's own calls, or a way to learn their uuids.
  • A sturdier [ answer ] press check. The live check clicks a fullscreen button (CLAUDE_CODE_NO_FLICKER=1) through SGR mouse escapes, and once failed to open the dialog under heavy load. A retry or a longer wait would make it reliable.

…-10-15-desk-design.md, 269f5212); a pointer stays here
…d sminos watch (DX5 v1)

The bridge mod spawns `sminos bridge --session <id>` for the session's life
and streams turn.step chunks (main loop and subagents, tagged turnId, agentId,
step, chunkIndex), tool calls, turn boundaries, subagent lifecycle, usage and
a heartbeat to the child's endpoint at $SMINOS_HOME/bridge/<id>.sock. Command
lines reach the mod on the child's stdout (ping at M1). `sminos watch` prints
the stream. Tests: tests/mods/bridge.test.ts, tests/sminos/test-bridge.sh, and
the live check tests/mods/live-bridge-check.py (14/14 on 2.1.300).
…tity, /clear routing, deep caps

- The mod keeps the session's live state (open turns, streaming messages
  with text and upTo, subagents) and opens every new child's first post,
  and the post after any loss, with a `resync` the child replaces its
  state with; a failed post waits 500 ms before the next. The child takes
  a message whose chunk does not follow its upTo out of the snapshot until
  the resync, so no snapshot claims an upTo its text does not cover.
- A child's identity is its socket's inode read before the rename, so an
  older child can no longer take a newer one's path for its own and unlink it.
- At a /clear's session.end the old child gets nothing more; the new id is
  looked for every 100 ms (heartbeat as fallback) and the new child's first
  post resyncs the new session's state.
- Every string in an event is capped at any depth, and every cut flagged.
… gap

The human view printed a message's chunks as they came, so after a lost
chunk it showed A … C while the child held ABC. On a gap, watch now
resubscribes at once and prints the fresh snapshot, each message whole
(DX4's rule on a discontinuity); --json passes the gap and resync through.
… through the bridge (DX5 M2)

The bridge mod answers the ops M1 reserved: steer (a user row read at the
next request, mirrored; a steer no request read is submitted at the turn's
end), interrupt (abort, then TaskStop on each Bash the abort backgrounded),
model (main-loop requests rewritten; a family alias resolved through the
session's ANTHROPIC_DEFAULT_<FAMILY>_MODEL), compact (queued for the turn's
end, or run at once; outcome on the stream), and deliver (submitted asUser,
deduplicated per writer by seq). The child keeps the model choice and the
delivered seqs in $SMINOS_HOME/bridge/<id>.json and hands them back in its
hello, so a module reload keeps them.

sminos steer|interrupt|model|compact drive it (sminos_control.py). A
delivery's last hop to a live session is the bridge, keyed by the log
event; else, for a human's message to a --bg job, the engine supervisor's
control.sock reply (nextTurn); else the inbox frame.

Tests: bridge.test.ts (+13), test-bridge-control.sh (60 assertions, run by
run-sminos-tests.sh), live-control-check.py (by hand).
…t scoped to it, failed stops and writes surfaced

- A steer is bound to its main turn before its row is appended; a turn that
  answered before reading it (or ended while the append was pending) gets
  one wake prompt that does not repeat the steer.
- Interrupt stops only the aborted turn's Bash calls (the main loop's, and
  those of foreground subagents spawned in it); a failed TaskStop comes back
  in running, and sminos interrupt says so and exits 1.
- The child's kept file: a failed write is not taken as kept, is retried at
  the next event, and is said on the stream as a kept event.
- sminos compact waits against a monotonic deadline.
…ettle; a failed kept write retried at every batch

- A turn's steers wake it at most once: settled when the turn has ended
  and every append given in it has landed, been refused, or failed.
- The child writes what it keeps at the end of each batch of the mod's
  events whenever it differs from the file, so a failed write is retried
  by any later event, a duplicate or a heartbeat included; a kept event
  says when writing starts to fail and when it works again.
…ock-row and per-block streaming (DX5 M3)

A permission prompt or a question the session raises is published as
raised, answerable with sminos decide / sminos answer, and settled once,
naming the side whose answer the engine used (the engine's
hook_permission_decision mark, the call's result, the session record
leaving waiting). A background subagent's request carries its 3 s window.
The ask mod's async questions take answers from outside through the
bridge. Response rows are paired with their blocks (block-row) and the
snapshot streams per block. Every post now begins in a poster loop
started at session.start: a post begun inside another hook's dispatch
died with it on an Esc or an interrupt.
… each decision, by call id

A request is settled from the engine's tool_decision record (raised to
plugins through telemetry.log, at decision time, naming the call and who
decided), else from the transcript's hook_permission_decision mark for
the call's id, else withdrawn: no grace, no answer comparison, no
loop-wide mark credit. Every PermissionRequest takes its check, so a
later identical call never inherits an earlier one's id. An async
question answered through a dialog settles with that dialog's winner.
A resync carries each message's settled blocks, so a late chunk never
brings one back; the watch=1 poll is gone.
…or an attribution has used them

A record that arrived while the PermissionRequest hook still awaited (the
hooks beneath, or the clock) was dropped, so an answered call could be
raised and polled. Records are now kept by call id, bounded, and the
raise-or-skip decision is made after the hook's last await. An async
question whose dialog the person answered before it was raised is the
terminal's, from that record, not withdrawn.
…ecution, RPC binding, ordering via DX5, resync, compact, Resume's scope)
…napshot cut, the acceptance walk (DX5 M4)

- Export (G4): the mod hands the main loop's rows that may carry a message to
  the host (a text row with a mark, an async ask with its result) to the
  child as `export`; the child appends their events through sminos.export_live,
  the Stop hook's own writer, extraction and (kind, src) keys, so they reach
  the log as they are written and the Stop hook finds them there.
- Row order (for DC7): every row the session keeps is named once, before it is
  written: block-row for a response row, row-seen for the rest (a note once
  kept, the steer's own row from its uuid; none for a queue record or an empty
  hook_success the engine never writes). Each loop's last notice is the cut,
  carried by the resync and the snapshot.
- Readiness: /status says ready; /events waits for the mod's first resync
  (5 s, else 503); a later resync ends every subscription. watch, decide,
  answer and compact follow the same child across it.
- remove_stale needs three refusals; listen backlog 128 (a mass reconnect had
  a live socket removed).
- tests: test-bridge-export.sh, test-bridge-order.sh with a reference
  consumer (bridge_order.py), bridge.test.ts; live-walk-check.py walks the
  plan's Concrete Steps in a terminal session and a --bg job.
- docs: CLAUDE.md, hooks/mods/README.md, hooks.json, the CLI's help.
- version 7.154.0
…(hello nonce, 409, the old poster retires); bridge tests reap their stand-ins

A reloaded module's in-flight dispatch still posted to the session's path,
which the new module's child serves: a stale resync rolled the cut, the model
override and the delivery high-water mark back and ended the live
subscription. The child now mints a nonce in its hello and refuses (409) any
POST /events without it; a mod whose post is refused under the nonce it holds
stops for good (no posts, no heartbeat, its child stopped, never respawned).

The bridge tests backgrounded the ctl shell function, so $! was the subshell
and the Python stand-ins (supervisors, inboxes, fakemods, subscribers)
outlived every run; they now background Python directly.
…er follows the disk; each loop's cut seeded at load; a step's end after its block-rows

- The mod names each row once its append resolves (notice order is the
  engine's append order); the reference consumer releases disk rows strictly
  in disk order (its own notice, a later row's notice, or 2 s).
- The child's hello carries `seed`, each loop's transcript tail. A loop older
  than the module (reload, resume, a subagent running at load) is cut there,
  and its requests begun before the hello never stream (rows by row-seen); a
  loop the module saw from its first row takes no seed and streams at once.
- A step's end is held (1 s at most) until each block that streamed has its
  block-row; the engine appends a withheld refusal/max-output row after the
  request's result. The child drops a step's whole message at its end.
- The live walk fails on a block-row out of disk order and reports row-seen
  write-order quirks, the largest flush-to-notice lag, and live thinking;
  a fresh --bg job's first reply must stream. The requests check waits for
  the question's own turn.
…; unnamed rows time from when they were first on disk

- Once a step's end is posted (its block-rows all in, the 1 s hold timed out,
  or the loop's next request, the turn's end or the subagent's stop released
  it), the step's pairing is closed: a row of it that comes later is named by
  row-seen, never a block-row after its step's end.
- The reference consumer stamps every disk row past the cut as it is first
  seen, and releases in strict prefix order: unnamed rows written together
  come out together about 2 s later, not 2 s apart.
- The readiness case pins that a held subscription's first snapshot carries
  the first resync's cut (the seed).
…on's start; a reload mid-turn takes the turn back; the verbs retry a not-ready child

- resync carries sessionInfo, which the child takes: a first post lost with
  its session start no longer leaves the child without the export's cwd.
- A main-loop turn.step with no known main turn (a module reloaded while the
  turn ran) recovers it: interrupt, steer and compact act on it, and the
  stream gets its start marked recovered.
- follow_stream (decide, answer, compact) retries a 503 not-ready child until
  its 8 s first-snapshot window runs out.
…d: the main turn's state is unknown until seen

A module loaded into a session that already had its conversation cannot know
whether a main turn runs. Until a main turn starts, completes, is recovered
from its next request, or the session's engine record (named in the hello)
says idle, interrupt, steer and compact refuse with "turn state unknown since
the bridge reloaded; retry after the next model request" (the CLI exits 1),
and ping/heartbeat state carries isTurnUnknown.
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