Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
refactor(daemon): remove dead RuntimeTurnState (convergence B0)
Gus518101439aca
diff --git a/src/daemon/README.md b/src/daemon/README.mdindex 4b1d33780..e6e73b4cc 100644--- a/src/daemon/README.md+++ b/src/daemon/README.md@@ -60,11 +60,8 @@ still-open input channel** — no restart. This is "steering."- **`direct`** (codex, kimi, pi): write immediately; the runtimetolerates injection any time.- **`gated`** (claude): a raw write mid-stream could collide with an active- signed thinking block, so writes are **held until a safe boundary**. Two state- machines implement this:- - `RuntimeTurnState` (`src/runtime/turnState.ts`) — the instantaneous gate:- `canSteerBusy = currentTurnId && !steeringGateActive`. Tool boundary closes- the gate; progress / turn-start reopens it.+ signed thinking block, so writes are **held until a safe boundary**,+ implemented by:- `apmStateMachine` (`src/runtime/apmStateMachine.ts`) — the policy reducersthat decide *when* to flush queued inbox notices and emit the concrete`notify_stdin` / `deliver_stdin` effects (clause `SMR-002`). Flushing is@@ -130,7 +127,6 @@ src/runtime/runtimeSession.ts # ChildProcessRuntimeSession + descriptorsdkRuntimeSession.ts # SdkRuntimeSession (in-process)- turnState.ts # instantaneous steering gateapmStateMachine.ts # gated-delivery policy reducers (SMR-002)progressState.ts # liveness / stall detectionnotificationState.ts # inbox-notice de-dup + batchingdiff --git a/src/daemon/src/drivers/claude.ts b/src/daemon/src/drivers/claude.tsindex 96a9563a0..34a1dac23 100644--- a/src/daemon/src/drivers/claude.ts+++ b/src/daemon/src/drivers/claude.ts@@ -5,8 +5,7 @@* channel; the initial prompt and every subsequent message are written as* `{type:"user", message:{role:"user", content:[{type:"text",text}]}}` lines.* Because mid-stream injection can collide with signed thinking blocks, busy- * delivery is `gated` — held until a safe boundary (see runtime/apmStateMachine- * and runtime/turnState).+ * delivery is `gated` — held until a safe boundary (see runtime/apmStateMachine).*/import type { Driver, EncodeOpts, LaunchConfig, LaunchContext, ParsedEvent, SpawnResult } from "../types.js";import { prepareCliTransport, buildCliTransportSystemPrompt, DEFAULT_CLI_CONFIG } from "./cliTransport.js";diff --git a/src/daemon/src/index.ts b/src/daemon/src/index.tsindex 544d4152e..0a9e332e2 100644--- a/src/daemon/src/index.ts+++ b/src/daemon/src/index.ts@@ -18,7 +18,6 @@ export {type RuntimeSessionDescriptor,} from "./runtime/runtimeSession.js";export { SdkRuntimeSession, type SdkSessionHandle } from "./runtime/sdkRuntimeSession.js";-export { RuntimeTurnState } from "./runtime/turnState.js";export { RuntimeProgressState } from "./runtime/progressState.js";export { RuntimeNotificationState } from "./runtime/notificationState.js";export * from "./runtime/apmStateMachine.js";diff --git a/src/daemon/src/runtime/apmStateMachine.ts b/src/daemon/src/runtime/apmStateMachine.tsindex 8e92d21dd..af1f281e0 100644--- a/src/daemon/src/runtime/apmStateMachine.ts+++ b/src/daemon/src/runtime/apmStateMachine.ts@@ -1,10 +1,9 @@/*** APM (Agent Process Manager) gated-steering state machine.*- * Where `RuntimeTurnState` answers "is it safe *right now*?", this reducer set- * is the coarse-grained policy layer that decides WHEN to flush queued inbox- * notices into a `gated` runtime, and emits the concrete delivery effects- * (`notify_stdin` / `deliver_stdin`).+ * This reducer set is the coarse-grained policy layer that decides WHEN to+ * flush queued inbox notices into a `gated` runtime, and emits the concrete+ * delivery effects (`notify_stdin` / `deliver_stdin`).** It is a pure reducer: `(state, input) -> { nextState?, effects?, ... }`. The* orchestrator owns the mutable copy and applies the effects.diff --git a/src/daemon/src/runtime/turnState.test.ts b/src/daemon/src/runtime/turnState.test.tsdeleted file mode 100644index 16a5582b4..000000000--- a/src/daemon/src/runtime/turnState.test.ts+++ /dev/null@@ -1,50 +0,0 @@-import { describe, it, expect } from "vitest";-import { RuntimeTurnState } from "./turnState";--describe("RuntimeTurnState — gated steering gate", () => {- it("cannot steer before a turn starts", () => {- const t = new RuntimeTurnState();- expect(t.canSteerBusy).toBe(false);- });-- it("turn start opens the gate", () => {- const t = new RuntimeTurnState();- t.markTurnStarted("turn-1");- expect(t.canSteerBusy).toBe(true);- expect(t.activeTurnId).toBe("turn-1");- });-- it("tool boundary closes the gate; progress reopens it", () => {- const t = new RuntimeTurnState();- t.markTurnStarted("turn-1");- t.markToolBoundary();- expect(t.canSteerBusy).toBe(false);- t.markProgress();- expect(t.canSteerBusy).toBe(true);- });-- it("turn completion goes idle (gate shut because no active turn)", () => {- const t = new RuntimeTurnState();- t.markTurnStarted("turn-1");- t.markTurnCompleted();- expect(t.canSteerBusy).toBe(false);- expect(t.activeTurnId).toBeNull();- });-- it("adoptTurnId learns the id without changing the gate", () => {- const t = new RuntimeTurnState();- t.markTurnStarted("turn-1");- t.markToolBoundary(); // gate shut- t.adoptTurnId("turn-2");- expect(t.activeTurnId).toBe("turn-2");- expect(t.canSteerBusy).toBe(false); // unchanged- });-- it("reset clears everything", () => {- const t = new RuntimeTurnState();- t.markTurnStarted("turn-1");- t.reset();- expect(t.activeTurnId).toBeNull();- expect(t.canSteerBusy).toBe(false);- });-});diff --git a/src/daemon/src/runtime/turnState.ts b/src/daemon/src/runtime/turnState.tsdeleted file mode 100644index 2303ed29a..000000000--- a/src/daemon/src/runtime/turnState.ts+++ /dev/null@@ -1,62 +0,0 @@-/**- * RuntimeTurnState — the fine-grained steering gate.- *- * For `busyDeliveryMode: "gated"` runtimes (Claude), the daemon may NOT inject a- * busy message at an arbitrary instant: a raw stdin write mid-stream can collide- * with an active signed thinking block. This tiny state machine tracks whether- * we're currently at a safe point.- *- * turn starts → gate OPEN (canSteerBusy = true)- * tool boundary hit → gate SHUT (hold writes)- * progress observed → gate OPEN- * turn completes → idle, gate OPEN- *- * `canSteerBusy` is the single question the delivery path asks before writing.- */-export class RuntimeTurnState {- private currentTurnId: string | null = null;- private steeringGateActive = false;-- /** Safe to write a busy (steering) message right now? */- get canSteerBusy(): boolean {- return Boolean(this.currentTurnId && !this.steeringGateActive);- }-- get activeTurnId(): string | null {- return this.currentTurnId;- }-- /** A new turn began: adopt its id and open the gate. */- markTurnStarted(turnId?: string | null): void {- if (turnId !== undefined && turnId !== null) {- this.currentTurnId = turnId;- }- this.steeringGateActive = false;- }-- /** Learn the turn id without touching the gate. */- adoptTurnId(turnId: string | null): void {- this.currentTurnId = turnId;- }-- /** Entered a tool boundary — close the gate (may be emitting a thinking block). */- markToolBoundary(): void {- this.steeringGateActive = true;- }-- /** Fresh progress (a delta) — reopen the gate. */- markProgress(): void {- this.steeringGateActive = false;- }-- /** Turn finished — go idle, gate open. */- markTurnCompleted(): void {- this.currentTurnId = null;- this.steeringGateActive = false;- }-- reset(): void {- this.currentTurnId = null;- this.steeringGateActive = false;- }-}