Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

feat(team): add recent steps to SlotRow for team and session rows

Jack Rudenko01b28bb92ff1
diff --git a/ai-docs/architecture/pane-session.md b/ai-docs/architecture/pane-session.md
index a1a0c594..c80597a6 100644
--- a/ai-docs/architecture/pane-session.md
+++ b/ai-docs/architecture/pane-session.md
@@ -619,6 +619,21 @@ type and new fields may only be added.
bodies carry `user_id`. One pure function, `reasonDetail()` in `pane/reason-detail.ts`, computes
it for both row builders (`toSlotRow` / `teamRunRowFromDisk` and `sessionRowOf`); the capture file
is read (16 KB tail) only for a terminal `api_error` row.
+- `recent` (added within v1, 2026-10-17) is the last 20 steps of the current turn, oldest first,
+ each `{at, kind, tool, summary}`: one per main-chain assistant block after the witness (text,
+ thinking, tool_use; an AskUserQuestion tool_use is `kind:"ask"`), `at` the record's own
+ timestamp. It exists so the mod can draw a running line (a badge, the step's words, and its
+ duration to the next step's `at`) without polling fast enough to see every step: at 1 Hz,
+ `activity` alone drops any tool shorter than the poll interval and can say `Bash` but never
+ which command. The summary is ONE line, at most 100 characters, from ONE named input field
+ (`file_path` for Read/Edit/Write, the first line of `command` for Bash, `pattern` for
+ Grep/Glob, `query`, `url`, `description` for Task/Agent, the first question for an ask, the
+ first line for text and thinking; empty for any other tool), and it goes through
+ `redactSecrets`: a Bash line or a url can hold a token. Nothing from a tool result is ever
+ read. Paths keep the home directory, unlike `report_error`'s sanitizer, because the rows never
+ leave the machine. Null before the first step and on rows built from disk (no live follower,
+ as for `activity`); kept after the turn settles until the next turn opens. `pane/slot-steps.ts`
+ (`stepOf`), fed by `applyAssistant` in `pane/transcript-follower.ts`.
- Verbs: `team(mode="list")` → `{contract_version, capabilities, runs}`; `team(mode="status")` adds
`contract_version`, `capabilities` and a `run` row to its payload; `team(mode="cancel")` and
`cancel_session` return per-slot `{state, changed}`; `team(mode="capture")` and `capture_session`
diff --git a/packages/cli/src/mcp-session/session-manager.ts b/packages/cli/src/mcp-session/session-manager.ts
index c35351b6..91ad27d6 100644
--- a/packages/cli/src/mcp-session/session-manager.ts
+++ b/packages/cli/src/mcp-session/session-manager.ts
@@ -364,6 +364,7 @@ export function sessionRowOf(
idle_seconds: terminal ? null : info.idleSeconds,
activity: terminal ? null : info.activity,
pane: info.pane,
+ recent: info.recent,
session_id: info.sessionId,
started_at: info.startedAt,
completed_at: info.completedAt,
@@ -913,6 +914,7 @@ export class SessionManager {
elapsedSeconds: 0,
idleSeconds: null,
activity: null,
+ recent: null,
reason: null,
detail: null,
pendingInputs: opts.prompt ? 1 : 0,
@@ -1154,6 +1156,7 @@ export class SessionManager {
info.lastActivityAt = snap.lastActivityAt;
info.idleSeconds = snap.idleSeconds;
info.activity = snap.activity;
+ info.recent = snap.recent;
info.reason = snap.reason;
info.detail = snap.detail;
info.pendingInputs = snap.pendingInputs;
@@ -1816,6 +1819,7 @@ function diskInfo(d: {
// Read from disk: no live process to be idle. Null, never 0.
idleSeconds: null,
activity: null,
+ recent: null,
reason,
detail: meta === null ? NO_TERMINAL_RECORD : metaString(meta.detail),
pendingInputs: 0,
diff --git a/packages/cli/src/mcp-session/types.ts b/packages/cli/src/mcp-session/types.ts
index 29c21dec..873cabc7 100644
--- a/packages/cli/src/mcp-session/types.ts
+++ b/packages/cli/src/mcp-session/types.ts
@@ -1,6 +1,6 @@
// ─── MCP Session Types ───────────────────────────────────────────────────────
-import type { FailureReason, PaneSessionOptions, SlotState } from "../pane/index.js";
+import type { FailureReason, PaneSessionOptions, SlotState, SlotStep } from "../pane/index.js";
/**
* Every value a session row's `event` field may carry, as a runtime list so a
@@ -82,6 +82,8 @@ export interface SessionInfo {
idleSeconds: number | null;
/** RUNNING: tool name, "thinking", "background" or "finishing"; a blocked tool; else null. */
activity: string | null;
+ /** SlotRow.recent: the current turn's last steps; null before the first and when read from disk. */
+ recent: SlotStep[] | null;
/** Set on FAILED / EMPTY / CANCELLED / TIMEOUT; null otherwise (incl. COMPLETED). */
reason: FailureReason | null;
detail: string | null;
diff --git a/packages/cli/src/pane/contract.ts b/packages/cli/src/pane/contract.ts
index 5cb59ab7..663154a9 100644
--- a/packages/cli/src/pane/contract.ts
+++ b/packages/cli/src/pane/contract.ts
@@ -154,6 +154,25 @@ export interface SlotRow {
activity: string | null;
/** informational only (do not parse, no verb takes it); null if no pane was ever spawned */
pane: string | null;
+ /** [additive] the last RECENT_STEP_LIMIT (20) steps of the current turn, oldest first, from the
+ * main-chain transcript; null before the first step and on rows built from disk. Kept after the
+ * turn settles until the next turn starts. Each summary is one line (≤ 100 chars), credentials
+ * masked; never a whole tool input and nothing from a tool result. `pane/slot-steps.ts` */
+ recent: SlotStep[] | null;
+}
+
+/** One step of a slot's turn: an assistant text, thinking or tool_use block. */
+export interface SlotStep {
+ /** ISO 8601: the transcript record's own timestamp */
+ at: string;
+ /** "ask" is a tool_use of AskUserQuestion */
+ kind: "text" | "thinking" | "tool" | "ask";
+ /** the tool name for "tool" and "ask"; null for "text" and "thinking" */
+ tool: string | null;
+ /** text and thinking: the first line; tool: the input naming its target (file_path, the first
+ * line of a Bash command, pattern, query, url, description) or "" for any other tool; ask: the
+ * first question */
+ summary: string;
}
/** list_sessions row = SlotRow + session fields. `slot` equals `session_id`. */
diff --git a/packages/cli/src/pane/pane-session.ts b/packages/cli/src/pane/pane-session.ts
index 8b337d3a..6a4b858c 100644
--- a/packages/cli/src/pane/pane-session.ts
+++ b/packages/cli/src/pane/pane-session.ts
@@ -1603,6 +1603,7 @@ export class PaneSessionImpl implements PaneSession, RegisteredPane {
this.activity === "finishing" &&
this.turnEndMissing,
agentCountMismatch: !terminal && this.phase === "RUNNING" && this.agentMismatch !== null,
+ recent: cur && cur.recent.length > 0 ? cur.recent : null,
};
}
diff --git a/packages/cli/src/pane/slot-row.ts b/packages/cli/src/pane/slot-row.ts
index 2b1f3e5c..7f85a655 100644
--- a/packages/cli/src/pane/slot-row.ts
+++ b/packages/cli/src/pane/slot-row.ts
@@ -49,5 +49,6 @@ export function toSlotRow(
? `${snap.activity}: agent_count_mismatch`
: snap.activity,
pane: snap.paneId || null,
+ recent: snap.recent,
};
}
diff --git a/packages/cli/src/pane/slot-steps.ts b/packages/cli/src/pane/slot-steps.ts
new file mode 100644
index 00000000..152634f0
--- /dev/null
+++ b/packages/cli/src/pane/slot-steps.ts
@@ -0,0 +1,76 @@
+/**
+ * `SlotRow.recent`: one step per main-chain assistant block of a turn (contract.ts
+ * `SlotStep`). Pure. The transcript follower calls `stepOf` for each block and keeps the
+ * last RECENT_STEP_LIMIT.
+ *
+ * A summary is ONE line taken from ONE named field. A tool step never carries the
+ * whole input and never anything from a tool result: a Bash command or a WebFetch url
+ * can hold a token, so even the named field goes through `redactSecrets`. Paths keep
+ * the home directory: the rows stay on this machine, and the path is the point.
+ */
+
+import { redactSecrets } from "../redact.js";
+import type { SlotStep } from "./contract.js";
+
+export const RECENT_STEP_LIMIT = 20;
+export const STEP_SUMMARY_MAX = 100;
+
+/** The one input field that names a tool's target. Any other tool has none. */
+const TARGET_FIELD: Readonly<Record<string, string>> = {
+ Read: "file_path",
+ Edit: "file_path",
+ Write: "file_path",
+ Bash: "command",
+ Grep: "pattern",
+ Glob: "pattern",
+ WebSearch: "query",
+ WebFetch: "url",
+ Task: "description",
+ Agent: "description",
+};
+
+/** First non-empty line, credentials masked, cut to STEP_SUMMARY_MAX characters. */
+export function oneLine(text: unknown): string {
+ if (typeof text !== "string") return "";
+ const line =
+ text
+ .split(/\r?\n/)
+ .map((l) => l.trim())
+ .find((l) => l.length > 0) ?? "";
+ const masked = redactSecrets(line);
+ return masked.length > STEP_SUMMARY_MAX ? `${masked.slice(0, STEP_SUMMARY_MAX - 1)}…` : masked;
+}
+
+function firstQuestion(input: unknown): string {
+ const qs = (input as { questions?: Array<{ question?: unknown }> } | undefined)?.questions;
+ if (!Array.isArray(qs)) return "";
+ // The first question with readable text: a whitespace-only one would summarise to "".
+ for (const q of qs) {
+ const line = oneLine(q?.question);
+ if (line) return line;
+ }
+ return "";
+}
+
+/**
+ * The step for one assistant content block, or null for a block that is not a step
+ * (empty text, redacted thinking, an image, a tool_use without a name).
+ */
+// biome-ignore lint/suspicious/noExplicitAny: a raw transcript content block, narrowed here
+export function stepOf(block: any, at: string): SlotStep | null {
+ if (!block || typeof block !== "object") return null;
+ if (block.type === "text") {
+ const summary = oneLine(block.text);
+ return summary ? { at, kind: "text", tool: null, summary } : null;
+ }
+ if (block.type === "thinking") {
+ const summary = oneLine(block.thinking);
+ return summary ? { at, kind: "thinking", tool: null, summary } : null;
+ }
+ if (block.type !== "tool_use" || typeof block.name !== "string" || !block.name) return null;
+ if (block.name === "AskUserQuestion")
+ return { at, kind: "ask", tool: block.name, summary: firstQuestion(block.input) };
+ const field = TARGET_FIELD[block.name];
+ const summary = field ? oneLine(block.input?.[field]) : "";
+ return { at, kind: "tool", tool: block.name, summary };
+}
diff --git a/packages/cli/src/pane/transcript-follower.ts b/packages/cli/src/pane/transcript-follower.ts
index f8d203e1..cfd77f2d 100644
--- a/packages/cli/src/pane/transcript-follower.ts
+++ b/packages/cli/src/pane/transcript-follower.ts
@@ -39,6 +39,8 @@ import {
statSync,
} from "node:fs";
import { join } from "node:path";
+import type { SlotStep } from "./contract.js";
+import { RECENT_STEP_LIMIT, stepOf } from "./slot-steps.js";
export type Witness =
| { kind: "text"; text: string } // typed plain line or the file-reference instruction (exact)
@@ -87,6 +89,8 @@ export interface TurnView {
lastChatOffset: number | null;
/** a local command's `<local-command-stdout>` after its witness (ANSI removed); null otherwise */
localCommandOutput: string | null;
+ /** the last RECENT_STEP_LIMIT steps of this turn, oldest first (SlotRow.recent); [] before the first */
+ recent: SlotStep[];
}
export interface SessionFacts {
@@ -145,6 +149,8 @@ interface TurnState {
read: ReadState | null;
lastChatOffset: number | null;
localOutput: { text: string; offset: number } | null;
+ /** at most RECENT_STEP_LIMIT, oldest dropped first */
+ steps: SlotStep[];
}
export interface FollowerState {
@@ -390,7 +396,15 @@ function applyAssistant(state: FollowerState, t: TurnState, r: Rec, offset: numb
t.waking = false;
t.apiError = isApiError ? apiErrorOf(r) : null;
if (isApiError) return;
- for (const b of m.content ?? []) applyAssistantBlock(state, t, b, offset);
+ const at = typeof r.timestamp === "string" ? r.timestamp : new Date().toISOString();
+ for (const b of m.content ?? []) {
+ applyAssistantBlock(state, t, b, offset);
+ const step = stepOf(b, at);
+ if (step) {
+ t.steps.push(step);
+ if (t.steps.length > RECENT_STEP_LIMIT) t.steps.shift();
+ }
+ }
}
function apiErrorOf(r: Rec): TurnView["apiError"] {
@@ -607,6 +621,7 @@ export function openTurnState(
read: t.delivery ? newReadState(t.delivery) : null,
lastChatOffset: null,
localOutput: null,
+ steps: [],
});
return state;
}
@@ -660,6 +675,7 @@ export function turnView(t: TurnState): TurnView {
preambleBytes,
lastChatOffset: t.lastChatOffset,
localCommandOutput: t.localOutput?.text ?? null,
+ recent: [...t.steps],
};
}
diff --git a/packages/cli/src/pane/types.ts b/packages/cli/src/pane/types.ts
index 17418724..e0b7211a 100644
--- a/packages/cli/src/pane/types.ts
+++ b/packages/cli/src/pane/types.ts
@@ -4,7 +4,7 @@
* snapshot every polling verb reads.
*/
-import type { FailureReason, SlotState } from "./contract.js";
+import type { FailureReason, SlotState, SlotStep } from "./contract.js";
import type { Delivery } from "./prompt-delivery.js";
import type { SettledBy } from "./settle-rule.js";
import type { Phase } from "./slot-state.js";
@@ -78,4 +78,6 @@ export interface PaneSnapshot {
* the turn settles; the `agent_count_mismatch` anomaly stays in `anomalies` as history.
*/
agentCountMismatch: boolean;
+ /** SlotRow.recent: the current turn's last steps; null before its first step */
+ recent: SlotStep[] | null;
}
diff --git a/packages/cli/src/team-orchestrator.ts b/packages/cli/src/team-orchestrator.ts
index 22e5fdf8..4458b781 100644
--- a/packages/cli/src/team-orchestrator.ts
+++ b/packages/cli/src/team-orchestrator.ts
@@ -458,6 +458,7 @@ function neverSpawnedRow(e: SlotEntry, m: ModelStatus | undefined): SlotRow {
idle_seconds: null,
activity: null,
pane: null,
+ recent: null,
};
}
@@ -547,6 +548,7 @@ export function teamRunRowFromDisk(path: string, status: TeamStatus): TeamRunRow
idle_seconds: null,
activity: null,
pane: m?.pane ?? null,
+ recent: null,
};
});
const settled = slots.length > 0 && slots.every((s) => isTerminalState(s.state));