@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.
package/dist/report.js ADDED
@@ -0,0 +1,114 @@
1
+ import { SECURE_OFF_ADVISORY } from "./secure-gate.js";
2
+ export function emptyTotals() {
3
+ return {
4
+ subtasks: 0,
5
+ done: 0,
6
+ failed: 0,
7
+ skipped: 0,
8
+ totalAttempts: 0,
9
+ inputTokens: 0,
10
+ outputTokens: 0,
11
+ durationMs: 0,
12
+ };
13
+ }
14
+ /**
15
+ * The one status rule.
16
+ *
17
+ * planning failed -> failed
18
+ * all subtasks done -> completed
19
+ * >=1 done and >=1 failed|skipped -> partial
20
+ * no subtask done -> failed
21
+ * --secure and the bylaw review failed -> completed downgrades to partial
22
+ * --secure off (bylaw === null) -> cannot influence status
23
+ */
24
+ export function deriveStatus(report) {
25
+ if (report.plan === null)
26
+ return "failed";
27
+ const done = report.subtasks.filter((s) => s.status === "done").length;
28
+ const total = report.subtasks.length;
29
+ let status;
30
+ if (total > 0 && done === total)
31
+ status = "completed";
32
+ else if (done > 0)
33
+ status = "partial";
34
+ else
35
+ status = "failed";
36
+ // AC10: an unapproved review means the run cannot claim success.
37
+ if (report.bylaw && report.bylaw.approved === false && status === "completed") {
38
+ status = "partial";
39
+ }
40
+ return status;
41
+ }
42
+ /** Exit code convention shared with the existing CLI: 0 only on a full success. */
43
+ export function exitCodeFor(status) {
44
+ return status === "completed" ? 0 : 1;
45
+ }
46
+ /**
47
+ * Folds per-subtask verdicts into one run-level summary.
48
+ * Returns null when nothing was judged — which is exactly the `--secure off`
49
+ * case, so status cannot be influenced by an opt-out (AC11).
50
+ */
51
+ export function summariseBylawVerdicts(subtasks) {
52
+ const verdicts = subtasks
53
+ .map((s) => s.bylawVerdict)
54
+ .filter((v) => v !== null);
55
+ if (verdicts.length === 0)
56
+ return null;
57
+ return {
58
+ approved: verdicts.every((v) => v.approved),
59
+ blocking: verdicts.flatMap((v) => v.blocking),
60
+ unreviewed: verdicts.flatMap((v) => v.unreviewed),
61
+ invalid: verdicts.flatMap((v) => v.invalid),
62
+ };
63
+ }
64
+ /** Deterministic plan-order description, used by both human and JSON output. */
65
+ export function describeSubtask(sub) {
66
+ const verdict = sub.bylawVerdict;
67
+ if (!verdict)
68
+ return sub.status;
69
+ return verdict.approved ? `${sub.status} (bylaws ok)` : `${sub.status} (bylaws blocked)`;
70
+ }
71
+ /** The human-readable report. Never includes prompts or secrets. */
72
+ export function formatHumanReport(report) {
73
+ const lines = [];
74
+ lines.push(`Litebro — ${report.taskId}`);
75
+ lines.push(`goal: ${report.goal}`);
76
+ lines.push(`status: ${report.status} secure: ${report.secure.mode}`);
77
+ if (report.plan) {
78
+ lines.push(`plan: ${report.plan.subtasks.length} subtask(s) — ${report.plan.rationale}`);
79
+ }
80
+ else {
81
+ lines.push(`plan: none (${report.planning.failure ?? "unknown failure"})` +
82
+ (report.planning.errors.length ? ` — ${report.planning.errors[0]}` : ""));
83
+ }
84
+ if (report.planning.trace.length > 0) {
85
+ lines.push("planning trace:");
86
+ for (const entry of report.planning.trace) {
87
+ lines.push(` [${entry.step}] ${entry.ok ? "accepted" : "rejected"}: ${entry.thought.slice(0, 120)}`);
88
+ }
89
+ }
90
+ if (report.subtasks.length > 0) {
91
+ lines.push("subtasks:");
92
+ for (const sub of report.subtasks) {
93
+ lines.push(` ${sub.id} [${sub.role}] ${describeSubtask(sub)}` +
94
+ (sub.error ? ` — ${sub.error}` : "") +
95
+ (sub.filesTouched.length ? ` (files: ${sub.filesTouched.join(", ")})` : ""));
96
+ }
97
+ const t = report.totals;
98
+ lines.push(`totals: ${t.done} done, ${t.failed} failed, ${t.skipped} skipped, ` +
99
+ `${t.totalAttempts} attempt(s), ${t.durationMs}ms`);
100
+ }
101
+ if (report.bylaw) {
102
+ const problems = [
103
+ ...report.bylaw.blocking,
104
+ ...report.bylaw.unreviewed,
105
+ ...report.bylaw.invalid,
106
+ ];
107
+ lines.push(report.bylaw.approved
108
+ ? "bylaws: approved"
109
+ : `bylaws: BLOCKED (${problems.join(", ")})`);
110
+ }
111
+ if (report.secure.mode === "off")
112
+ lines.push(SECURE_OFF_ADVISORY);
113
+ return lines.join("\n") + "\n";
114
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The only place in Litebro that reads `--secure`.
3
+ *
4
+ * It is a *delegate*, not a policy engine. Whether a design is approved is
5
+ * decided by `evaluateReview()` in the frozen bylaws module; this file only
6
+ * decides (a) whether to ask, and (b) which layers of the question apply.
7
+ * That is deliberate: if this file invented an approval rule, `--secure`
8
+ * could drift from the bylaws every time one was edited.
9
+ *
10
+ * Opt-in by default (design tradeoff T3, an accepted + owned risk against
11
+ * CORE-04): bylaw approval is strict — every in-scope bylaw with no finding
12
+ * is `unreviewed`, and unreviewed blocks — so enforcing by default would
13
+ * reject the brief's own `litebro "Hello World"` first run. The risk is
14
+ * mitigated by always printing `secure.mode`, by an advisory line when off,
15
+ * and by this being the single line to flip.
16
+ */
17
+ import { type Role } from "xcoder-dna";
18
+ import { type BylawFinding, type BylawLayer, type ReviewResult } from "xcoder-dna";
19
+ export type SecureMode = "enforce" | "off";
20
+ /**
21
+ * Roles whose subtasks design or judge, so the laws apply.
22
+ *
23
+ * Mirrors `BYLAW_GATED_STAGES` (design | quality_gate) from the prompt
24
+ * adapter: this path has no `SdlcStage` to gate on (`WorkerSubtask` has no
25
+ * stage), so the equivalent set is expressed in the dimension it does have.
26
+ * Gating on `inferLayers(goal)` alone was rejected — a goal that happens to
27
+ * mention "api" would drag bylaws into a `technical-writer` subtask.
28
+ */
29
+ export declare const BYLAW_GATED_ROLES: readonly Role[];
30
+ export interface BylawVerdict extends ReviewResult {
31
+ readonly layers: readonly BylawLayer[];
32
+ readonly findings: readonly BylawFinding[];
33
+ }
34
+ export interface SecureGate {
35
+ readonly mode: SecureMode;
36
+ /**
37
+ * Markdown to inject into this subtask's prompt, or null.
38
+ * Null when `mode === 'off'` (AC11) or the role is not bylaw-gated.
39
+ */
40
+ promptBlock(role: Role, goal: string): string | null;
41
+ /** Verdict for a finished deliverable, or null when there is nothing to judge. */
42
+ judge(role: Role, goal: string, deliverable: unknown): BylawVerdict | null;
43
+ }
44
+ /**
45
+ * Builds the gate for a run.
46
+ *
47
+ * `off` is a hard opt-out: no bylaw text reaches any prompt and no verdict is
48
+ * ever produced, so security state cannot influence the run's status.
49
+ */
50
+ export declare function createSecureGate(mode: SecureMode): SecureGate;
51
+ /** One-line advisory shown whenever scrutiny was opted out of (T3 mitigation b). */
52
+ export declare const SECURE_OFF_ADVISORY = "security note: --secure was not set, so no secure-architect bylaw review was performed.";
@@ -0,0 +1,73 @@
1
+ import { inferLayers, renderBylaws } from "xcoder-dna";
2
+ import { BYLAW_SECTION_HEADER } from "xcoder-dna";
3
+ import { reviewDeliverable } from "xcoder-dna";
4
+ /**
5
+ * Roles whose subtasks design or judge, so the laws apply.
6
+ *
7
+ * Mirrors `BYLAW_GATED_STAGES` (design | quality_gate) from the prompt
8
+ * adapter: this path has no `SdlcStage` to gate on (`WorkerSubtask` has no
9
+ * stage), so the equivalent set is expressed in the dimension it does have.
10
+ * Gating on `inferLayers(goal)` alone was rejected — a goal that happens to
11
+ * mention "api" would drag bylaws into a `technical-writer` subtask.
12
+ */
13
+ export const BYLAW_GATED_ROLES = [
14
+ "architect",
15
+ "system-architect",
16
+ "security-lead",
17
+ ];
18
+ function isGated(role) {
19
+ return BYLAW_GATED_ROLES.includes(role);
20
+ }
21
+ /**
22
+ * Builds the gate for a run.
23
+ *
24
+ * `off` is a hard opt-out: no bylaw text reaches any prompt and no verdict is
25
+ * ever produced, so security state cannot influence the run's status.
26
+ */
27
+ export function createSecureGate(mode) {
28
+ if (mode === "off") {
29
+ return {
30
+ mode,
31
+ promptBlock: () => null,
32
+ judge: () => null,
33
+ };
34
+ }
35
+ return {
36
+ mode,
37
+ promptBlock(role, goal) {
38
+ if (!isGated(role))
39
+ return null;
40
+ try {
41
+ const layers = inferLayers(goal ?? "");
42
+ return BYLAW_SECTION_HEADER + "\n\n" + renderBylaws(layers);
43
+ }
44
+ catch {
45
+ // A prompt path must never crash a run; degrade to "no bylaws".
46
+ return null;
47
+ }
48
+ },
49
+ judge(role, goal, deliverable) {
50
+ if (!isGated(role))
51
+ return null;
52
+ try {
53
+ const layers = inferLayers(goal ?? "");
54
+ const result = reviewDeliverable(deliverable, layers);
55
+ return { ...result, layers };
56
+ }
57
+ catch {
58
+ // A gate that cannot establish compliance must not approve. Surfacing
59
+ // an empty verdict makes every in-scope bylaw `unreviewed`, which blocks.
60
+ return {
61
+ approved: false,
62
+ blocking: [],
63
+ unreviewed: [],
64
+ invalid: ["bylaw review could not be performed"],
65
+ layers: [],
66
+ findings: [],
67
+ };
68
+ }
69
+ },
70
+ };
71
+ }
72
+ /** One-line advisory shown whenever scrutiny was opted out of (T3 mitigation b). */
73
+ export const SECURE_OFF_ADVISORY = "security note: --secure was not set, so no secure-architect bylaw review was performed.";
@@ -0,0 +1,121 @@
1
+ import { FooterRenderer } from "./footer-renderer.js";
2
+ import { type ScrollRegionGuard } from "./scroll-region-guard.js";
3
+ import { type SdlcStage } from "xcoder-dna";
4
+ /**
5
+ * Specification passed to FooterManager.init() from the orchestrator.
6
+ */
7
+ export interface FooterSpec {
8
+ /** Effective ANSI gate: TTY attached and NO_COLOR unset (see isInteractiveStdout). */
9
+ tty: boolean;
10
+ /** Optional task description shown in the footer. */
11
+ taskDesc?: string;
12
+ /**
13
+ * Optional opt-out for orchestrator-adjacent runners. When true the
14
+ * singleton still exists (consumers may optional-chain safely) but no
15
+ * footer output, scroll region, spinner, or ANSI escapes are ever
16
+ * emitted. Defaults to false.
17
+ */
18
+ quiet?: boolean;
19
+ }
20
+ /**
21
+ * Public API facade for the terminal status footer.
22
+ *
23
+ * Manages FooterState + FooterRenderer lifecycle.
24
+ * Serializes concurrent updates via a microtask queue (the JS event loop
25
+ * naturally batches all synchronous calls into one render).
26
+ *
27
+ * Design reference: `src/util/footer-state.ts`, `src/util/footer-renderer.ts`
28
+ */
29
+ export declare class FooterManager {
30
+ private static _instance;
31
+ private _state;
32
+ private _renderer;
33
+ private _scrollRegionGuard;
34
+ private _muted;
35
+ private _disposed;
36
+ private _thinking;
37
+ private _usage;
38
+ private _resize;
39
+ private _pending;
40
+ private _flushScheduled;
41
+ private constructor();
42
+ /**
43
+ * Initialize the singleton footer. Sole caller: SdlcOrchestrator._runLoop.
44
+ * Consumers are restricted to `FooterManager.instance()?.` optional-chained
45
+ * update/hide/show/shutdown/writeSafe and must never call init.
46
+ *
47
+ * Availability matrix — the footer is visible iff ALL of these hold:
48
+ *
49
+ * 1) Path gate: the task runs through SdlcOrchestrator.run()/resume() into
50
+ * _runLoop. Status/bench/backlog list|status|pick|done/sprint/observe/
51
+ * release/index/test/swarm never construct the orchestrator and never
52
+ * show a footer. Backlog start/continue DO route through the
53
+ * orchestrator and DO show one.
54
+ * 2) TTY gate: process.stdout.isTTY === true at init time (ANSI/cursor/
55
+ * scroll-region output is only safe on a real terminal; piped output
56
+ * stays raw).
57
+ * 3) NO_COLOR gate: process.env.NO_COLOR is unset. Setting NO_COLOR makes
58
+ * spec.tty false, so zero escape sequences are emitted and redirected
59
+ * output stays clean.
60
+ * 4) Lifecycle gate: the footer is outside the interrupt-hide window and
61
+ * has not yet been shut down by the execution loop.
62
+ *
63
+ * The quiet flag is a deliberate opt-out for orchestrator-adjacent runners:
64
+ * the singleton exists (so optional-chained consumers are safe) but no
65
+ * footer is ever painted and no timer is started.
66
+ */
67
+ static init(spec: FooterSpec): FooterManager;
68
+ /** Get the current singleton instance (may be null if not initialized). */
69
+ static instance(): FooterManager | null;
70
+ /** Whether the footer is active (TTY attached). */
71
+ static isActive(): boolean;
72
+ /**
73
+ * Write text safely above the footer. If the footer is active (TTY),
74
+ * routes through the ScrollRegionGuard to preserve the reserved footer rows.
75
+ * If inactive, writes directly to process.stdout.
76
+ */
77
+ static writeSafe(text: string): void;
78
+ /** Get the ScrollRegionGuard instance (for OutputInterceptor). */
79
+ getScrollRegionGuard(): ScrollRegionGuard | null;
80
+ /** Get the FooterRenderer instance (for direct access to writeAbove / forceRender). */
81
+ getFooterRenderer(): FooterRenderer;
82
+ /** Agent started thinking — show spinner and agent ID. */
83
+ updateThinkingStart(agentId: string): void;
84
+ /** Agent stopped thinking. */
85
+ updateThinkingStop(agentId?: string): void;
86
+ /** Agent performed an action. */
87
+ updateAction(tool: string): void;
88
+ /** Agent received an observation. */
89
+ updateObservation(ok: boolean, text: string): void;
90
+ /** Update token count display. */
91
+ updateTokens(inputTokens: number, outputTokens: number, agentId?: string): void;
92
+ addTokens(input: number, output: number): void;
93
+ /** Update current SDLC stage. */
94
+ updateStage(stage: SdlcStage): void;
95
+ /** Update document info. */
96
+ updateDocument(docs: string): void;
97
+ /**
98
+ * Temporarily hide the footer (e.g. for interrupt prompts).
99
+ * Call show() to restore.
100
+ */
101
+ hide(): void;
102
+ /**
103
+ * Restore the footer after being hidden.
104
+ */
105
+ show(): void;
106
+ /**
107
+ * Shutdown the footer — teardown scroll region, clear line, null singleton.
108
+ * Called when the task run finishes or is interrupted.
109
+ */
110
+ shutdown(): void;
111
+ /**
112
+ * Handle terminal resize by reconfiguring the renderer.
113
+ */
114
+ onResize(): void;
115
+ /**
116
+ * Accumulate partial state changes and flush on the next microtask.
117
+ * This coalesces multiple synchronous calls into a single render.
118
+ */
119
+ private _apply;
120
+ private _flush;
121
+ }
@@ -0,0 +1,215 @@
1
+ // xcoder:version 5 | xcoder:task task-e53af9 | xcoder:updated 2026-08-13T14:02:15.014Z | xcoder:subtask code-st-a2df76
2
+ import { FooterRenderer } from "./footer-renderer.js";
3
+ import { createFooterState } from "./footer-state.js";
4
+ import { createScrollRegionGuard } from "./scroll-region-guard.js";
5
+ /**
6
+ * Public API facade for the terminal status footer.
7
+ *
8
+ * Manages FooterState + FooterRenderer lifecycle.
9
+ * Serializes concurrent updates via a microtask queue (the JS event loop
10
+ * naturally batches all synchronous calls into one render).
11
+ *
12
+ * Design reference: `src/util/footer-state.ts`, `src/util/footer-renderer.ts`
13
+ */
14
+ export class FooterManager {
15
+ static _instance = null;
16
+ _state;
17
+ _renderer;
18
+ _scrollRegionGuard = null;
19
+ _muted = false;
20
+ _disposed = false;
21
+ _thinking = new Set();
22
+ _usage = new Map();
23
+ _resize = () => this.onResize();
24
+ _pending = {};
25
+ _flushScheduled = false;
26
+ constructor(state) {
27
+ this._state = state;
28
+ this._renderer = new FooterRenderer();
29
+ }
30
+ /**
31
+ * Initialize the singleton footer. Sole caller: SdlcOrchestrator._runLoop.
32
+ * Consumers are restricted to `FooterManager.instance()?.` optional-chained
33
+ * update/hide/show/shutdown/writeSafe and must never call init.
34
+ *
35
+ * Availability matrix — the footer is visible iff ALL of these hold:
36
+ *
37
+ * 1) Path gate: the task runs through SdlcOrchestrator.run()/resume() into
38
+ * _runLoop. Status/bench/backlog list|status|pick|done/sprint/observe/
39
+ * release/index/test/swarm never construct the orchestrator and never
40
+ * show a footer. Backlog start/continue DO route through the
41
+ * orchestrator and DO show one.
42
+ * 2) TTY gate: process.stdout.isTTY === true at init time (ANSI/cursor/
43
+ * scroll-region output is only safe on a real terminal; piped output
44
+ * stays raw).
45
+ * 3) NO_COLOR gate: process.env.NO_COLOR is unset. Setting NO_COLOR makes
46
+ * spec.tty false, so zero escape sequences are emitted and redirected
47
+ * output stays clean.
48
+ * 4) Lifecycle gate: the footer is outside the interrupt-hide window and
49
+ * has not yet been shut down by the execution loop.
50
+ *
51
+ * The quiet flag is a deliberate opt-out for orchestrator-adjacent runners:
52
+ * the singleton exists (so optional-chained consumers are safe) but no
53
+ * footer is ever painted and no timer is started.
54
+ */
55
+ static init(spec) {
56
+ if (FooterManager._instance) {
57
+ FooterManager._instance.shutdown();
58
+ }
59
+ const state = createFooterState({
60
+ tty: spec.tty,
61
+ taskDesc: spec.taskDesc ?? null,
62
+ });
63
+ const mgr = new FooterManager(state);
64
+ mgr._muted = spec.quiet === true;
65
+ FooterManager._instance = mgr;
66
+ if (state.tty && !mgr._muted) {
67
+ mgr._renderer.setup(state);
68
+ process.stdout.on("resize", mgr._resize);
69
+ // Create the ScrollRegionGuard after setup so it knows the active state.
70
+ mgr._scrollRegionGuard = createScrollRegionGuard(mgr._renderer, () => mgr._state);
71
+ }
72
+ return mgr;
73
+ }
74
+ /** Get the current singleton instance (may be null if not initialized). */
75
+ static instance() {
76
+ return FooterManager._instance;
77
+ }
78
+ /** Whether the footer is active (TTY attached). */
79
+ static isActive() {
80
+ return FooterManager._instance != null && FooterManager._instance._state.tty && !FooterManager._instance._muted;
81
+ }
82
+ /**
83
+ * Write text safely above the footer. If the footer is active (TTY),
84
+ * routes through the ScrollRegionGuard to preserve the reserved footer rows.
85
+ * If inactive, writes directly to process.stdout.
86
+ */
87
+ static writeSafe(text) {
88
+ const mgr = FooterManager._instance;
89
+ if (mgr && mgr._scrollRegionGuard && mgr._state.tty) {
90
+ mgr._scrollRegionGuard.write(text);
91
+ }
92
+ else {
93
+ process.stdout.write(text);
94
+ }
95
+ }
96
+ /** Get the ScrollRegionGuard instance (for OutputInterceptor). */
97
+ getScrollRegionGuard() {
98
+ return this._scrollRegionGuard;
99
+ }
100
+ /** Get the FooterRenderer instance (for direct access to writeAbove / forceRender). */
101
+ getFooterRenderer() {
102
+ return this._renderer;
103
+ }
104
+ // ── update helpers ──
105
+ /** Agent started thinking — show spinner and agent ID. */
106
+ updateThinkingStart(agentId) {
107
+ this._thinking.add(agentId);
108
+ this._apply({ agentId: [...this._thinking].join(", "), spinner: true });
109
+ if (!this._muted) {
110
+ this._renderer.startSpinner();
111
+ }
112
+ }
113
+ /** Agent stopped thinking. */
114
+ updateThinkingStop(agentId) {
115
+ if (agentId)
116
+ this._thinking.delete(agentId);
117
+ else
118
+ this._thinking.clear();
119
+ if (!this._thinking.size)
120
+ this._renderer.stopSpinner();
121
+ this._apply({ spinner: this._thinking.size > 0, agentId: [...this._thinking].join(", ") || null });
122
+ }
123
+ /** Agent performed an action. */
124
+ updateAction(tool) {
125
+ this._apply({ action: tool });
126
+ }
127
+ /** Agent received an observation. */
128
+ updateObservation(ok, text) {
129
+ // Show observing state briefly.
130
+ const preview = text.length > 40 ? text.slice(0, 37) + "..." : text;
131
+ this._apply({ observing: true, action: ok ? preview : `✗ ${preview}` });
132
+ // Clear observing after a tick.
133
+ setTimeout(() => {
134
+ if (this._state.observing) {
135
+ this._apply({ observing: false });
136
+ }
137
+ }, 0);
138
+ }
139
+ /** Update token count display. */
140
+ updateTokens(inputTokens, outputTokens, agentId = "default") {
141
+ this._usage.set(agentId, { input: inputTokens, output: outputTokens });
142
+ const values = [...this._usage.values()];
143
+ this._apply({ tokens: `${values.reduce((n, v) => n + v.input, 0)} in / ${values.reduce((n, v) => n + v.output, 0)} out` });
144
+ }
145
+ addTokens(input, output) {
146
+ const previous = this._usage.get("run") ?? { input: 0, output: 0 };
147
+ this.updateTokens(previous.input + input, previous.output + output, "run");
148
+ }
149
+ /** Update current SDLC stage. */
150
+ updateStage(stage) {
151
+ this._apply({ stage });
152
+ }
153
+ /** Update document info. */
154
+ updateDocument(docs) {
155
+ this._apply({ docs });
156
+ }
157
+ /**
158
+ * Temporarily hide the footer (e.g. for interrupt prompts).
159
+ * Call show() to restore.
160
+ */
161
+ hide() {
162
+ this._renderer.hide();
163
+ }
164
+ /**
165
+ * Restore the footer after being hidden.
166
+ */
167
+ show() {
168
+ this._renderer.show(this._state);
169
+ }
170
+ /**
171
+ * Shutdown the footer — teardown scroll region, clear line, null singleton.
172
+ * Called when the task run finishes or is interrupted.
173
+ */
174
+ shutdown() {
175
+ this._disposed = true;
176
+ process.stdout.off("resize", this._resize);
177
+ this._renderer.stopSpinner();
178
+ this._renderer.teardown();
179
+ if (FooterManager._instance === this) {
180
+ FooterManager._instance = null;
181
+ }
182
+ }
183
+ /**
184
+ * Handle terminal resize by reconfiguring the renderer.
185
+ */
186
+ onResize() {
187
+ this._renderer.reconfigure(this._state);
188
+ }
189
+ // ── private ──
190
+ /**
191
+ * Accumulate partial state changes and flush on the next microtask.
192
+ * This coalesces multiple synchronous calls into a single render.
193
+ */
194
+ _apply(patch) {
195
+ if (this._disposed)
196
+ return;
197
+ Object.assign(this._pending, patch);
198
+ if (!this._flushScheduled) {
199
+ this._flushScheduled = true;
200
+ Promise.resolve().then(() => {
201
+ this._flush();
202
+ });
203
+ }
204
+ }
205
+ _flush() {
206
+ this._flushScheduled = false;
207
+ if (this._disposed || this._muted)
208
+ return;
209
+ Object.assign(this._state, this._pending);
210
+ this._pending = {};
211
+ if (this._state.tty) {
212
+ this._renderer.render(this._state);
213
+ }
214
+ }
215
+ }
@@ -0,0 +1,69 @@
1
+ import type { FooterState } from "./footer-state.js";
2
+ /**
3
+ * Converts a FooterState into a single ANSI escape sequence string
4
+ * that paints a persistent XCODER SDLC header and live status footer.
5
+ *
6
+ * Design:
7
+ * - 2-row footer using scroll region to reserve the header and status lines.
8
+ * - Truncation priority: stage+spinner > action > tokens > agentId > taskDesc > docs.
9
+ * - Respects NO_COLOR and TTY detection.
10
+ * - Handles window resize by re-reading process.stdout.columns.
11
+ */
12
+ export declare class FooterRenderer {
13
+ private _write;
14
+ private _active;
15
+ private _hidden;
16
+ private _spinnerIdx;
17
+ private _spinnerInterval;
18
+ private _currentState;
19
+ private _noColor;
20
+ /**
21
+ * Perform one-time setup: enable scroll region, hide cursor.
22
+ * Must be called before render(). Safe to call when already active (no-op).
23
+ */
24
+ setup(state: FooterState): void;
25
+ /**
26
+ * Render the current state to the reserved bottom row.
27
+ * Handles layout, truncation, and spinner animation.
28
+ */
29
+ render(state: FooterState): void;
30
+ /** Re-read terminal size and re-apply scroll region after a resize. */
31
+ reconfigure(state: FooterState, partial?: Partial<FooterState>): void;
32
+ /** Temporarily hide the footer (e.g. during interrupt prompts). */
33
+ hide(): void;
34
+ /** Restore the footer after being hidden. */
35
+ show(state: FooterState): void;
36
+ /**
37
+ * Return the current scroll-region bottom row (height - 2).
38
+ * Used by ScrollRegionGuard to keep both footer rows from scrolling away.
39
+ */
40
+ getScrollBottom(): number;
41
+ /**
42
+ * Force-render the footer without checking _hidden/_active guards.
43
+ * Used by ScrollRegionGuard during re-establish after a guarded write.
44
+ */
45
+ forceRender(state: FooterState): void;
46
+ /**
47
+ * Write text in the scrollable area above the footer. Re-establishes the
48
+ * current scroll region and anchors output at its bottom before writing;
49
+ * and restores cursor. This is the core defensive write — it ensures
50
+ * no output can break the scroll region.
51
+ */
52
+ writeAbove(text: string, state: FooterState): void;
53
+ /**
54
+ * Tear down: reset scroll region, show cursor, clear footer.
55
+ */
56
+ teardown(): void;
57
+ private _render;
58
+ private _clearFooterRow;
59
+ /**
60
+ * Start spinner tick — called by FooterManager when initiating thinking.
61
+ * Managed here so the renderer owns the interval lifecycle.
62
+ */
63
+ startSpinner(): void;
64
+ /**
65
+ * Stop spinner tick — called by FooterManager when thinking stops.
66
+ */
67
+ stopSpinner(): void;
68
+ }
69
+ export declare function fitFooter(text: string, columns: number): string;