@neural-node-labs/xcoder-litebro 0.0.0-stage → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,280 @@
1
+ import { stripVTControlCharacters } from "node:util";
2
+ /**
3
+ * ANSI escape sequences for the built-in terminal color palette.
4
+ * Matches the existing palette in terminal.ts.
5
+ */
6
+ const C = {
7
+ reset: "\x1b[0m",
8
+ dim: "\x1b[2m",
9
+ bold: "\x1b[1m",
10
+ amber: "\x1b[38;5;214m",
11
+ cyan: "\x1b[38;5;80m",
12
+ green: "\x1b[38;5;78m",
13
+ coral: "\x1b[38;5;203m",
14
+ violet: "\x1b[38;5;140m",
15
+ white: "\x1b[38;5;255m",
16
+ bgFooter: "\x1b[48;5;236m",
17
+ };
18
+ // ── Scroll region helpers ──
19
+ const SAVE_CURSOR = "\x1b7";
20
+ const RESTORE_CURSOR = "\x1b8";
21
+ const RESET_SCROLL_REGION = "\x1b[r";
22
+ const CLEAR_LINE = "\x1b[2K";
23
+ const HIDE_CURSOR = "\x1b[?25l";
24
+ const SHOW_CURSOR = "\x1b[?25h";
25
+ // Scroll up by 1 to make room for the footer when enabling.
26
+ const SCROLL_UP = "\x1b[1S";
27
+ /** Resolve current terminal width, with a fallback. */
28
+ function getWidth() {
29
+ if (process.stdout && typeof process.stdout.columns === "number" && process.stdout.columns > 0) {
30
+ return process.stdout.columns;
31
+ }
32
+ return 80;
33
+ }
34
+ /** Truncate a single segment with "…" if too long. */
35
+ function truncate(text, maxLen) {
36
+ if (text.length <= maxLen)
37
+ return text;
38
+ return text.slice(0, maxLen - 1) + "…";
39
+ }
40
+ /** Spinner frames compatible with clack — simple Braille spinner. */
41
+ const SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
42
+ /**
43
+ * Converts a FooterState into a single ANSI escape sequence string
44
+ * that paints a persistent XCODER SDLC header and live status footer.
45
+ *
46
+ * Design:
47
+ * - 2-row footer using scroll region to reserve the header and status lines.
48
+ * - Truncation priority: stage+spinner > action > tokens > agentId > taskDesc > docs.
49
+ * - Respects NO_COLOR and TTY detection.
50
+ * - Handles window resize by re-reading process.stdout.columns.
51
+ */
52
+ export class FooterRenderer {
53
+ _write = process.stdout.write.bind(process.stdout);
54
+ _active = false;
55
+ _hidden = false;
56
+ _spinnerIdx = 0;
57
+ _spinnerInterval = null;
58
+ _currentState = null;
59
+ _noColor = false;
60
+ /**
61
+ * Perform one-time setup: enable scroll region, hide cursor.
62
+ * Must be called before render(). Safe to call when already active (no-op).
63
+ */
64
+ setup(state) {
65
+ this._noColor = !state.tty || process.env.NO_COLOR !== undefined;
66
+ if (!state.tty || this._active)
67
+ return;
68
+ this._active = true;
69
+ this._hidden = false;
70
+ // Reserve the bottom two rows for the fixed brand header and live status.
71
+ const height = process.stdout.rows ?? 24;
72
+ // Scroll region: rows 1 to (height - 2), keeping the final two rows free.
73
+ const scrollBottom = Math.max(1, height - 2);
74
+ this._write(HIDE_CURSOR + `\x1b[1;${scrollBottom}r\x1b[${scrollBottom};1H`);
75
+ this._render(state);
76
+ }
77
+ /**
78
+ * Render the current state to the reserved bottom row.
79
+ * Handles layout, truncation, and spinner animation.
80
+ */
81
+ render(state) {
82
+ if (!this._active || this._hidden || !state.tty) {
83
+ this._currentState = state;
84
+ return;
85
+ }
86
+ this._render(state);
87
+ }
88
+ /** Re-read terminal size and re-apply scroll region after a resize. */
89
+ reconfigure(state, partial) {
90
+ if (!state.tty || !this._active)
91
+ return;
92
+ const scrollBottom = this.getScrollBottom();
93
+ // Resizing can leave the cursor on a row that is now outside the scroll
94
+ // region. Reset the margins, establish the new region, and put the log
95
+ // cursor back on its last usable row before repainting the footer.
96
+ this._write(RESET_SCROLL_REGION + `\x1b[1;${scrollBottom}r` + `\x1b[${scrollBottom};1H`);
97
+ if (partial) {
98
+ this.render({ ...state, ...partial });
99
+ }
100
+ else {
101
+ this.render(state);
102
+ }
103
+ }
104
+ /** Temporarily hide the footer (e.g. during interrupt prompts). */
105
+ hide() {
106
+ if (!this._active || this._hidden)
107
+ return;
108
+ this._hidden = true;
109
+ this._write(SAVE_CURSOR + RESET_SCROLL_REGION + SHOW_CURSOR + RESTORE_CURSOR);
110
+ // Clear the footer row.
111
+ this._clearFooterRow();
112
+ }
113
+ /** Restore the footer after being hidden. */
114
+ show(state) {
115
+ if (!this._active || !this._hidden)
116
+ return;
117
+ this._hidden = false;
118
+ const height = process.stdout.rows ?? 24;
119
+ const scrollBottom = Math.max(1, height - 2);
120
+ this._write(HIDE_CURSOR);
121
+ this._write(`\x1b[1;${scrollBottom}r`);
122
+ if (this._currentState) {
123
+ this._render(this._currentState);
124
+ }
125
+ else {
126
+ this._render(state);
127
+ }
128
+ }
129
+ /**
130
+ * Return the current scroll-region bottom row (height - 2).
131
+ * Used by ScrollRegionGuard to keep both footer rows from scrolling away.
132
+ */
133
+ getScrollBottom() {
134
+ const height = process.stdout.rows ?? 24;
135
+ return Math.max(1, height - 2);
136
+ }
137
+ /**
138
+ * Force-render the footer without checking _hidden/_active guards.
139
+ * Used by ScrollRegionGuard during re-establish after a guarded write.
140
+ */
141
+ forceRender(state) {
142
+ this.render(state);
143
+ }
144
+ /**
145
+ * Write text in the scrollable area above the footer. Re-establishes the
146
+ * current scroll region and anchors output at its bottom before writing;
147
+ * and restores cursor. This is the core defensive write — it ensures
148
+ * no output can break the scroll region.
149
+ */
150
+ writeAbove(text, state) {
151
+ if (!this._active || this._hidden || !state.tty) {
152
+ this._write(text);
153
+ return;
154
+ }
155
+ // Keep output inside the scrolling area and start each log entry at its
156
+ // bottom row. This also recovers if another writer or a terminal resize
157
+ // changed the cursor or scroll margins. Footer rendering saves/restores
158
+ // this anchored cursor after repainting the fixed rows.
159
+ const scrollBottom = this.getScrollBottom();
160
+ this._write(RESET_SCROLL_REGION + `\x1b[1;${scrollBottom}r` + `\x1b[${scrollBottom};1H`);
161
+ this._write(text);
162
+ this.render(state);
163
+ }
164
+ /**
165
+ * Tear down: reset scroll region, show cursor, clear footer.
166
+ */
167
+ teardown() {
168
+ if (!this._active)
169
+ return;
170
+ this._active = false;
171
+ this._hidden = false;
172
+ if (this._spinnerInterval) {
173
+ clearInterval(this._spinnerInterval);
174
+ this._spinnerInterval = null;
175
+ }
176
+ this._write(RESET_SCROLL_REGION);
177
+ this._write(SHOW_CURSOR);
178
+ this._clearFooterRow();
179
+ }
180
+ // ── private helpers ──
181
+ _render(state) {
182
+ this._currentState = state;
183
+ const width = getWidth();
184
+ const height = process.stdout.rows ?? 24;
185
+ // Build the footer line — truncation priority:
186
+ // stage+spinner > action > tokens > agentId > taskDesc > docs
187
+ const segments = [];
188
+ // Stage (amber) + optional spinner
189
+ if (state.stage || state.spinner) {
190
+ let stageSeg = state.stage ?? "Working";
191
+ if (state.spinner) {
192
+ const frame = SPINNER_FRAMES[this._spinnerIdx % SPINNER_FRAMES.length];
193
+ stageSeg = `${frame} ${stageSeg}`;
194
+ }
195
+ segments.push(stageSeg);
196
+ }
197
+ // Action
198
+ if (state.action) {
199
+ segments.push(state.action);
200
+ }
201
+ // Tokens
202
+ if (state.tokens) {
203
+ segments.push(state.tokens);
204
+ }
205
+ // AgentId
206
+ if (state.agentId) {
207
+ segments.push(`[${state.agentId}]`);
208
+ }
209
+ // Task description
210
+ if (state.taskDesc) {
211
+ segments.push(state.taskDesc);
212
+ }
213
+ // Docs
214
+ if (state.docs) {
215
+ segments.push(state.docs);
216
+ }
217
+ // Join and truncate to width
218
+ const line = fitFooter(segments.join(" | "), Math.max(0, width - 1));
219
+ // Paint the full line with background
220
+ const bgLine = this._noColor ? line : `${C.bgFooter}${line}${C.reset}`;
221
+ // Keep the brand visible on the row above the live footer status. On
222
+ // terminals too short for two reserved rows, retain the status row only.
223
+ let output = SAVE_CURSOR;
224
+ if (height >= 3) {
225
+ const header = fitFooter(paint(C.cyan + C.bold, "XCODER SDLC", this._noColor), Math.max(0, width - 1));
226
+ const bgHeader = this._noColor ? header : `${C.bgFooter}${header}${C.reset}`;
227
+ output += `\x1b[${height - 1};1H` + CLEAR_LINE + bgHeader;
228
+ }
229
+ output += `\x1b[${height};1H` + CLEAR_LINE + bgLine + RESTORE_CURSOR;
230
+ this._write(output);
231
+ }
232
+ _clearFooterRow() {
233
+ const height = process.stdout.rows ?? 24;
234
+ let output = SAVE_CURSOR;
235
+ if (height >= 3)
236
+ output += `\x1b[${height - 1};1H` + CLEAR_LINE;
237
+ output += `\x1b[${height};1H` + CLEAR_LINE + RESTORE_CURSOR;
238
+ this._write(output);
239
+ }
240
+ /**
241
+ * Start spinner tick — called by FooterManager when initiating thinking.
242
+ * Managed here so the renderer owns the interval lifecycle.
243
+ */
244
+ startSpinner() {
245
+ if (!this._active || this._spinnerInterval)
246
+ return;
247
+ this._spinnerInterval = setInterval(() => {
248
+ this._spinnerIdx++;
249
+ if (this._currentState && this._currentState.tty && !this._hidden) {
250
+ this._render({ ...this._currentState, spinner: true });
251
+ }
252
+ }, 100);
253
+ }
254
+ /**
255
+ * Stop spinner tick — called by FooterManager when thinking stops.
256
+ */
257
+ stopSpinner() {
258
+ if (this._spinnerInterval) {
259
+ clearInterval(this._spinnerInterval);
260
+ this._spinnerInterval = null;
261
+ }
262
+ }
263
+ }
264
+ function paint(code, text, noColor) {
265
+ return noColor ? text : `${code}${text}${C.reset}`;
266
+ }
267
+ export function fitFooter(text, columns) {
268
+ const plain = stripVTControlCharacters(text).replace(/[\x00-\x1f\x7f]/g, " ");
269
+ let output = "", width = 0;
270
+ for (const { segment } of new Intl.Segmenter(undefined, { granularity: "grapheme" }).segment(plain)) {
271
+ const cp = segment.codePointAt(0);
272
+ const wide = /\p{Extended_Pictographic}/u.test(segment) || (cp >= 0x1100 && (cp <= 0x115f || cp >= 0x2e80 && cp <= 0xa4cf || cp >= 0xac00 && cp <= 0xd7a3 || cp >= 0xf900 && cp <= 0xfaff || cp >= 0xfe10 && cp <= 0xfe6f || cp >= 0xff01 && cp <= 0xff60 || cp >= 0x20000));
273
+ const cells = /^\p{Mark}+$/u.test(segment) ? 0 : wide ? 2 : 1;
274
+ if (width + cells > columns)
275
+ break;
276
+ output += segment;
277
+ width += cells;
278
+ }
279
+ return output + " ".repeat(Math.max(0, columns - width));
280
+ }
@@ -0,0 +1,29 @@
1
+ import { type SdlcStage } from "xcoder-dna";
2
+ /**
3
+ * The current values for every footer field.
4
+ * Single source of truth — FooterManager writes, FooterRenderer reads.
5
+ */
6
+ export interface FooterState {
7
+ /** Current SDLC stage, derived from the DAG. */
8
+ stage: SdlcStage | null;
9
+ /** Agent currently thinking (or null if idle). */
10
+ agentId: string | null;
11
+ /** Task description (shortened goal string). */
12
+ taskDesc: string | null;
13
+ /** Last action tool name. */
14
+ action: string | null;
15
+ /** Whether an observation is in flight. */
16
+ observing: boolean;
17
+ /** Whether the spinner should be active. */
18
+ spinner: boolean;
19
+ /** Cumulative token usage display string. */
20
+ tokens: string | null;
21
+ /** Document count or doc-related info. */
22
+ docs: string | null;
23
+ /** Whether the terminal supports ANSI (TTY + no NO_COLOR). */
24
+ tty: boolean;
25
+ }
26
+ /**
27
+ * Creates a default, idle footer state.
28
+ */
29
+ export declare function createFooterState(overrides?: Partial<FooterState>): FooterState;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Creates a default, idle footer state.
3
+ */
4
+ export function createFooterState(overrides) {
5
+ return {
6
+ stage: null,
7
+ agentId: null,
8
+ taskDesc: null,
9
+ action: null,
10
+ observing: false,
11
+ spinner: false,
12
+ tokens: null,
13
+ docs: null,
14
+ tty: false,
15
+ ...overrides,
16
+ };
17
+ }
@@ -0,0 +1,9 @@
1
+ import type { FooterState } from "./footer-state.js";
2
+ import type { FooterRenderer } from "./footer-renderer.js";
3
+ export interface ScrollRegionGuard {
4
+ write(text: string): void;
5
+ writeln(text: string): void;
6
+ reestablish(): void;
7
+ teardown(): void;
8
+ }
9
+ export declare function createScrollRegionGuard(renderer: FooterRenderer, getState: () => FooterState): ScrollRegionGuard;
@@ -0,0 +1,8 @@
1
+ export function createScrollRegionGuard(renderer, getState) {
2
+ return {
3
+ write: text => renderer.writeAbove(text, getState()),
4
+ writeln: text => renderer.writeAbove(text + "\n", getState()),
5
+ reestablish: () => renderer.reconfigure(getState()),
6
+ teardown: () => renderer.teardown(),
7
+ };
8
+ }
@@ -0,0 +1,15 @@
1
+ export declare const AVAILABLE_SPINNER_STYLES: readonly ["clack", ...string[]];
2
+ /**
3
+ * `--spinner <style>`: "clack" (default, Anthropic's own prompt library's
4
+ * spinner) or any named style from `cli-spinners` (the same package `ora`
5
+ * itself uses) — "dots", "line", "arc", "bounceBar", "star", etc. Falls
6
+ * back to "clack" on an unrecognized name rather than throwing, since a
7
+ * bad `--spinner` value shouldn't stop a task from running.
8
+ */
9
+ export declare function setSpinnerStyle(style: string | undefined): void;
10
+ export declare function getSpinnerStyle(): string;
11
+ export interface SpinnerHandle {
12
+ stop(message: string): void;
13
+ fail(message: string): void;
14
+ }
15
+ export declare function createSpinner(startMessage: string): SpinnerHandle;
@@ -0,0 +1,49 @@
1
+ import * as clack from "@clack/prompts";
2
+ import ora from "ora";
3
+ import cliSpinners from "cli-spinners";
4
+ export const AVAILABLE_SPINNER_STYLES = ["clack", ...Object.keys(cliSpinners)];
5
+ let activeStyle = "clack";
6
+ /**
7
+ * `--spinner <style>`: "clack" (default, Anthropic's own prompt library's
8
+ * spinner) or any named style from `cli-spinners` (the same package `ora`
9
+ * itself uses) — "dots", "line", "arc", "bounceBar", "star", etc. Falls
10
+ * back to "clack" on an unrecognized name rather than throwing, since a
11
+ * bad `--spinner` value shouldn't stop a task from running.
12
+ */
13
+ export function setSpinnerStyle(style) {
14
+ if (!style)
15
+ return;
16
+ if (style === "clack" || style in cliSpinners) {
17
+ activeStyle = style;
18
+ }
19
+ else {
20
+ console.error(`Unknown --spinner "${style}". Using "clack". Available: clack, ${Object.keys(cliSpinners).slice(0, 12).join(", ")}, ... ` +
21
+ `(${Object.keys(cliSpinners).length} total from cli-spinners)`);
22
+ }
23
+ }
24
+ export function getSpinnerStyle() {
25
+ return activeStyle;
26
+ }
27
+ export function createSpinner(startMessage) {
28
+ if (activeStyle === "clack") {
29
+ const s = clack.spinner();
30
+ s.start(startMessage);
31
+ return {
32
+ stop: (msg) => s.stop(msg),
33
+ fail: (msg) => s.stop(msg, 1),
34
+ };
35
+ }
36
+ // Cast is safe: `activeStyle` is validated against `cliSpinners`'s own keys
37
+ // in `setSpinnerStyle` before it can ever reach here (or is the literal
38
+ // "clack" string, handled in the branch above).
39
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
+ const instance = ora({ text: startMessage, spinner: activeStyle }).start();
41
+ return {
42
+ stop: (msg) => {
43
+ instance.succeed(msg);
44
+ },
45
+ fail: (msg) => {
46
+ instance.fail(msg);
47
+ },
48
+ };
49
+ }
@@ -0,0 +1,60 @@
1
+ /** Shared branded chrome for standalone companion CLIs. Sent to stderr so
2
+ * commands that emit documents or machine-readable reports on stdout stay usable in pipes. */
3
+ export declare function agentCliIntro(agentName: string, detail?: string): void;
4
+ export declare function agentCliOutro(agentName: string, status: string): void;
5
+ /**
6
+ * One spinner per Sub Agent turn — "thinking" while the LLM call is in
7
+ * flight. This is the piece that makes a long silent wait (previously
8
+ * indistinguishable from a hang, which is part of what made a crash look
9
+ * like nothing was happening) visibly alive. Backend/style is selectable
10
+ * via `--spinner` — see `util/spinner.ts`.
11
+ */
12
+ export declare function startThinking(agentId: string): {
13
+ stop: (thought: string) => void;
14
+ fail: (message: string) => void;
15
+ };
16
+ export declare function printAction(agentId: string, tool: string, input: unknown): void;
17
+ export declare function printObservation(agentId: string, ok: boolean, text: string): void;
18
+ export declare function printTokens(agentId: string, turn: {
19
+ inputTokens: number;
20
+ outputTokens: number;
21
+ }, cumulative: {
22
+ inputTokens: number;
23
+ outputTokens: number;
24
+ }): void;
25
+ export declare function printProtocolError(agentId: string, message: string): void;
26
+ export declare function printDuplicateWarning(agentId: string, message: string): void;
27
+ export declare function printCrash(agentId: string, message: string): void;
28
+ export declare function printFinalAnswer(agentId: string, summary: string): void;
29
+ export declare function taskIntro(taskId: string, goal: string): void;
30
+ export declare function taskOutro(status: string): void;
31
+ export declare function orchestratorNote(message: string): void;
32
+ /**
33
+ * Printed exactly once per interrupt, after state is flushed to disk.
34
+ * Shows task ID, done/total count, exact --resume command, and file path.
35
+ */
36
+ export declare function printInterruptSummary(summary: {
37
+ taskId: string;
38
+ doneCount: number;
39
+ totalCount: number;
40
+ resumeCommand: string;
41
+ taskFilePath: string;
42
+ }): void;
43
+ /**
44
+ * Print a color-coded summary of an Instance Swarm run.
45
+ * Uses the same palette as the rest of the terminal module:
46
+ * - green for completed workers
47
+ * - coral for crashed/failed workers
48
+ * - amber for the swarm-level status line
49
+ * - dim for metadata (tokens, output dir)
50
+ */
51
+ export declare function printSwarmSummary(result: {
52
+ instanceId: string;
53
+ status: "completed" | "failed" | "timeout";
54
+ errors: string[];
55
+ workerCount: number;
56
+ crashedCount: number;
57
+ totalInputTokens: number;
58
+ totalOutputTokens: number;
59
+ outputDir: string;
60
+ }): void;
@@ -0,0 +1,170 @@
1
+ import { requestScope } from "xcoder-dna";
2
+ // xcoder:version 4 | xcoder:task task-4f2baf | xcoder:updated 2026-08-05T05:48:55.314Z | xcoder:subtask code-st-11b531
3
+ import * as clack from "@clack/prompts";
4
+ import { createSpinner } from "./spinner.js";
5
+ import { FooterManager } from "./footer-manager.js";
6
+ import { XCODER_VERSION } from "xcoder-dna";
7
+ const terminalLog = Object.fromEntries(Object.entries(clack.log).map(([name, write]) => [name, (message) => {
8
+ if (FooterManager.isActive())
9
+ FooterManager.writeSafe(message + "\n");
10
+ else
11
+ write(message);
12
+ }]));
13
+ const C = {
14
+ reset: "\x1b[0m",
15
+ dim: "\x1b[2m",
16
+ bold: "\x1b[1m",
17
+ amber: "\x1b[38;5;214m",
18
+ cyan: "\x1b[38;5;80m",
19
+ green: "\x1b[38;5;78m",
20
+ coral: "\x1b[38;5;203m",
21
+ violet: "\x1b[38;5;140m",
22
+ };
23
+ const activeActions = new Map();
24
+ function useColor() {
25
+ return process.stdout.isTTY === true && process.env.NO_COLOR === undefined;
26
+ }
27
+ function paint(code, text) {
28
+ return useColor() ? `${code}${text}${C.reset}` : text;
29
+ }
30
+ function xcoderLogo() {
31
+ return [
32
+ "+--------------------------------------+",
33
+ "| L I T E B R O |",
34
+ "| General Worker Agent - ASK ANYTHING |",
35
+ "| N E U R A L N O D E L A B S |",
36
+ "| By Sir John Nueva |",
37
+ `| ${XCODER_VERSION} |`,
38
+ "+--------------------------------------+",
39
+ ].join("\n");
40
+ }
41
+ /** Shared branded chrome for standalone companion CLIs. Sent to stderr so
42
+ * commands that emit documents or machine-readable reports on stdout stay usable in pipes. */
43
+ export function agentCliIntro(agentName, detail) {
44
+ const label = detail ? `${agentName} · ${detail}` : agentName;
45
+ process.stderr.write(`${paint(C.cyan, xcoderLogo())}\n${paint(C.bold, label)}\n`);
46
+ }
47
+ export function agentCliOutro(agentName, status) {
48
+ const color = status === "done" || status === "completed" ? C.green : status === "escalated" ? C.coral : C.amber;
49
+ process.stderr.write(`${paint(color, `${agentName} finished: ${status}`)}\n`);
50
+ }
51
+ /**
52
+ * One spinner per Sub Agent turn — "thinking" while the LLM call is in
53
+ * flight. This is the piece that makes a long silent wait (previously
54
+ * indistinguishable from a hang, which is part of what made a crash look
55
+ * like nothing was happening) visibly alive. Backend/style is selectable
56
+ * via `--spinner` — see `util/spinner.ts`.
57
+ */
58
+ export function startThinking(agentId) {
59
+ const s = FooterManager.isActive() ? {
60
+ stop: (text) => FooterManager.writeSafe(text + "\n"),
61
+ fail: (text) => FooterManager.writeSafe(text + "\n"),
62
+ } : createSpinner(paint(C.dim, `[${agentId}] thinking…`));
63
+ FooterManager.instance()?.updateThinkingStart(agentId);
64
+ return {
65
+ stop: (thought) => {
66
+ // Keep terminal output focused on observable work; full reasoning remains in the task trace.
67
+ void thought;
68
+ s.stop(`${paint(C.violet, `[${agentId}]`)} ${paint(C.dim, "working")}`);
69
+ FooterManager.instance()?.updateThinkingStop(agentId);
70
+ },
71
+ fail: (message) => {
72
+ s.fail(paint(C.coral, `[${agentId}] ${message}`));
73
+ FooterManager.instance()?.updateThinkingStop(agentId);
74
+ },
75
+ };
76
+ }
77
+ export function printAction(agentId, tool, input) {
78
+ activeActions.set(agentId, tool);
79
+ const args = input !== null && typeof input === "object" ? input : {};
80
+ const detail = ["path", "dir", "pattern", "query", "functionName", "operation", "url", "goal", "command"]
81
+ .map((key) => typeof args[key] === "string" ? `${key}=${args[key]}` : "")
82
+ .find(Boolean);
83
+ const shortDetail = detail && detail.length > 96 ? `${detail.slice(0, 93)}...` : detail;
84
+ terminalLog.info(`${paint(C.cyan, `[${agentId}]`)} ${paint(C.dim, "›")} ${paint(C.bold, tool)}${shortDetail ? ` ${paint(C.dim, shortDetail)}` : ""}`);
85
+ FooterManager.instance()?.updateAction(tool);
86
+ }
87
+ export function printObservation(agentId, ok, text) {
88
+ const tool = activeActions.get(agentId) ?? "task";
89
+ if (ok)
90
+ terminalLog.success(`${paint(C.green, `[${agentId}]`)} ${tool} complete`);
91
+ else {
92
+ const preview = text.replace(/\s+/g, " ").slice(0, 180);
93
+ terminalLog.error(`${paint(C.coral, `[${agentId}]`)} ${tool} failed: ${preview}`);
94
+ }
95
+ activeActions.delete(agentId);
96
+ FooterManager.instance()?.updateObservation(ok, text);
97
+ }
98
+ export function printTokens(agentId, turn, cumulative) {
99
+ // Token totals are presented in the final report; per-turn token rows made parallel runs noisy.
100
+ void agentId;
101
+ void turn;
102
+ void cumulative;
103
+ if (!requestScope.getStore()?.recordUsage)
104
+ FooterManager.instance()?.addTokens(turn.inputTokens, turn.outputTokens);
105
+ }
106
+ export function printProtocolError(agentId, message) {
107
+ terminalLog.warn(paint(C.coral, `[${agentId}] protocol_error: ${message}`));
108
+ }
109
+ export function printDuplicateWarning(agentId, message) {
110
+ terminalLog.warn(paint(C.amber, `[${agentId}] ⟲ ${message}`));
111
+ }
112
+ export function printCrash(agentId, message) {
113
+ terminalLog.error(paint(C.coral, `[${agentId}] CRASHED (isolated — orchestrator continues): ${message}`));
114
+ }
115
+ export function printFinalAnswer(agentId, summary) {
116
+ terminalLog.success(paint(C.green, `[${agentId}] final_answer`) + ` ${summary}`);
117
+ }
118
+ export function taskIntro(taskId, goal) {
119
+ clack.intro(`${paint(C.cyan, xcoderLogo())}\n${paint(C.bold, `xcoder · ${taskId}`)}`);
120
+ terminalLog.step(goal);
121
+ }
122
+ export function taskOutro(status) {
123
+ const color = status === "done" ? C.green : status === "escalated" ? C.coral : C.amber;
124
+ clack.outro(paint(color, `run finished: ${status}`));
125
+ }
126
+ export function orchestratorNote(message) {
127
+ terminalLog.step(paint(C.amber, "[orchestrator] ") + message);
128
+ }
129
+ /**
130
+ * Printed exactly once per interrupt, after state is flushed to disk.
131
+ * Shows task ID, done/total count, exact --resume command, and file path.
132
+ */
133
+ export function printInterruptSummary(summary) {
134
+ terminalLog.message(paint(C.bold, `\nInterrupted — progress saved.`) +
135
+ `\n Task: ${summary.taskId}` +
136
+ `\n Done: ${summary.doneCount}/${summary.totalCount} subtasks` +
137
+ `\n Resume with: ${paint(C.cyan, summary.resumeCommand)}` +
138
+ `\n Task file: ${paint(C.dim, summary.taskFilePath)}`);
139
+ }
140
+ /**
141
+ * Print a color-coded summary of an Instance Swarm run.
142
+ * Uses the same palette as the rest of the terminal module:
143
+ * - green for completed workers
144
+ * - coral for crashed/failed workers
145
+ * - amber for the swarm-level status line
146
+ * - dim for metadata (tokens, output dir)
147
+ */
148
+ export function printSwarmSummary(result) {
149
+ const statusColor = result.status === "completed" ? C.green : result.status === "timeout" ? C.amber : C.coral;
150
+ const statusIcon = result.status === "completed" ? "✓" : result.status === "timeout" ? "⏱" : "✗";
151
+ terminalLog.message(paint(C.bold, `\nSwarm finished`) +
152
+ ` ${paint(statusColor, `${statusIcon} ${result.status}`)}`);
153
+ terminalLog.message(` ${paint(C.cyan, "instanceId:")} ${paint(C.dim, result.instanceId)}`);
154
+ const workerLine = ` ${paint(C.cyan, "workers:")} ` +
155
+ `${paint(C.green, String(result.workerCount - result.crashedCount))} completed`;
156
+ if (result.crashedCount > 0) {
157
+ terminalLog.message(workerLine + `, ${paint(C.coral, String(result.crashedCount))} crashed`);
158
+ }
159
+ else {
160
+ terminalLog.message(workerLine);
161
+ }
162
+ terminalLog.message(` ${paint(C.cyan, "tokens:")} ${paint(C.dim, `${result.totalInputTokens} in / ${result.totalOutputTokens} out`)}`);
163
+ terminalLog.message(` ${paint(C.cyan, "outputDir:")} ${paint(C.dim, result.outputDir)}`);
164
+ if (result.errors.length > 0) {
165
+ terminalLog.message(paint(C.bold, `\n Errors:`));
166
+ for (const err of result.errors) {
167
+ terminalLog.error(paint(C.coral, ` ✗ ${err}`));
168
+ }
169
+ }
170
+ }