@fractaal/pi-goal-x 0.19.1

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,146 @@
1
+ import { matchesKey, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
2
+ import type { Component, TUI } from "@earendil-works/pi-tui";
3
+ import type { ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
4
+
5
+ /**
6
+ * Result of the Escape dialog during audit.
7
+ */
8
+ export type EscapeDialogResult = "complete_without_audit" | "continue_working";
9
+
10
+ /**
11
+ * Show a TUI confirmation dialog when the user presses Escape during a completion audit.
12
+ *
13
+ * Presents two choices:
14
+ * - Mark complete without audit (skips auditor, marks goal complete immediately)
15
+ * - Continue working (returns to agent, goal stays active)
16
+ *
17
+ * Returns the user's choice. Escape or Enter on a focused option submits the selection.
18
+ */
19
+ export async function showEscapeDialog(
20
+ ctx: ExtensionContext,
21
+ goalObjective: string,
22
+ ): Promise<EscapeDialogResult> {
23
+ if (!ctx.hasUI) {
24
+ // Fallback for headless/RPC mode — return "continue" as the safe default
25
+ return "continue_working";
26
+ }
27
+
28
+ return await ctx.ui.custom<EscapeDialogResult>(
29
+ (tui: TUI, theme: Theme, _keybindings: unknown, done: (result: EscapeDialogResult) => void): Component => {
30
+ const wasHardwareCursorShown = tui.getShowHardwareCursor();
31
+ tui.setShowHardwareCursor(false);
32
+
33
+ let selectedIndex = 1; // Default: "Continue working" (index 1)
34
+ let cancelled = false;
35
+
36
+ const OPTIONS: Array<{ label: string; value: EscapeDialogResult; description: string }> = [
37
+ {
38
+ label: "Mark complete without audit",
39
+ value: "complete_without_audit",
40
+ description: "Bypass the auditor and mark the goal complete now.",
41
+ },
42
+ {
43
+ label: "Continue working",
44
+ value: "continue_working",
45
+ description: "Resume work on the goal. The audit will not run this turn.",
46
+ },
47
+ ];
48
+
49
+ const accent = (s: string) => theme.fg("accent", s);
50
+ const dim = (s: string) => theme.fg("dim", s);
51
+ const warning = (s: string) => theme.fg("warning", s);
52
+
53
+ // ── Component ────────────────────────────────────────────────────
54
+ const component: Component & { dispose?(): void } = {
55
+ dispose() {
56
+ tui.setShowHardwareCursor(wasHardwareCursorShown);
57
+ },
58
+
59
+ invalidate(): void {
60
+ // No cached state to invalidate
61
+ },
62
+
63
+ render(width: number): string[] {
64
+ const termWidth = Math.min(width, 80);
65
+ const innerWidth = Math.min(termWidth, 64) - 2; // inner content width between ││
66
+
67
+ /** Build a bordered line: fits exactly `innerWidth` visible chars between ││ */
68
+ function line(leftContent: string): string {
69
+ const vis = visibleWidth(leftContent);
70
+ const fill = innerWidth - vis;
71
+ return accent("│") + leftContent + (fill > 0 ? " ".repeat(fill) : "") + accent("│");
72
+ }
73
+
74
+ const horizLine = "─".repeat(innerWidth);
75
+ const lines: string[] = [];
76
+ const p = " "; // left padding inside the border
77
+
78
+ // ── Header ────────────────────────────────────────────────
79
+ lines.push(accent(`┌${horizLine}┐`));
80
+ const headerContent = p + theme.bold("Audit interrupted by Escape") + dim(" (continue = default)");
81
+ lines.push(line(truncateToWidth(headerContent, innerWidth, "…")));
82
+ const truncatedObjective = truncateToWidth(goalObjective, innerWidth - 14, "…");
83
+ lines.push(line(p + dim("Goal: ") + dim(truncatedObjective)));
84
+ lines.push(accent(`├${horizLine}┤`));
85
+
86
+ // ── Options ─────────────────────────────────────────────
87
+ OPTIONS.forEach((opt, i) => {
88
+ const isSelected = i === selectedIndex && !cancelled;
89
+ const marker = isSelected ? "▸ " : " ";
90
+ const label = isSelected ? warning(opt.label) : opt.label;
91
+ const truncLabel = truncateToWidth(label, innerWidth - 6, "…");
92
+ lines.push(line(p + marker + truncLabel));
93
+ if (isSelected && opt.description) {
94
+ const desc = dim(opt.description);
95
+ const truncDesc = truncateToWidth(desc, innerWidth - 10, "…");
96
+ lines.push(line(p + " ".repeat(4) + truncDesc));
97
+ }
98
+ });
99
+
100
+ // ── Footer ───────────────────────────────────────────────
101
+ lines.push(accent(`├${horizLine}┤`));
102
+ const footerText = dim("Enter to select · ↑↓ to navigate · Esc = continue working");
103
+ const truncFooter = truncateToWidth(footerText, innerWidth - 2, "…");
104
+ lines.push(line(p + truncFooter));
105
+ lines.push(accent(`└${horizLine}┘`));
106
+
107
+ return lines;
108
+ },
109
+
110
+ handleInput(data: string): void {
111
+ if (matchesKey(data, "up")) {
112
+ selectedIndex = (selectedIndex - 1 + OPTIONS.length) % OPTIONS.length;
113
+ tui.requestRender();
114
+ return;
115
+ }
116
+ if (matchesKey(data, "down")) {
117
+ selectedIndex = (selectedIndex + 1) % OPTIONS.length;
118
+ tui.requestRender();
119
+ return;
120
+ }
121
+ if (matchesKey(data, "enter")) {
122
+ cancelled = false;
123
+ done(OPTIONS[selectedIndex].value);
124
+ return;
125
+ }
126
+ if (matchesKey(data, "escape")) {
127
+ cancelled = true;
128
+ done("continue_working");
129
+ return;
130
+ }
131
+ },
132
+ };
133
+
134
+ return component;
135
+ },
136
+ {
137
+ overlay: true,
138
+ overlayOptions: {
139
+ anchor: "center",
140
+ width: "70%",
141
+ minWidth: 50,
142
+ maxHeight: "50%",
143
+ },
144
+ },
145
+ );
146
+ }
@@ -0,0 +1,9 @@
1
+ import { displayObjectiveTitle, truncateText } from "../goal-core.ts";
2
+
3
+ export function buildGoalRunningNotification(args: { objective: string; sisyphus: boolean; autoContinue: boolean }): string {
4
+ const icon = args.sisyphus ? "◆" : "●";
5
+ const mode = args.sisyphus ? "Sisyphus" : "Goal";
6
+ const title = truncateText(displayObjectiveTitle(args.objective), 92);
7
+ const drive = args.autoContinue ? "auto-continue on" : "manual mode";
8
+ return [`${icon} ${mode} running`, `├─ ⟡ ${title}`, `└─ ${drive}`].join("\n");
9
+ }
@@ -0,0 +1,378 @@
1
+ import type { Theme, ThemeColor } from "@earendil-works/pi-coding-agent";
2
+ import type { Component, TUI } from "@earendil-works/pi-tui";
3
+ import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
4
+ import {
5
+ displayObjectiveTitle,
6
+ formatDuration,
7
+ formatTokenValue,
8
+ truncateText,
9
+ type GoalDisplayRecordLike,
10
+ } from "../goal-core.ts";
11
+ import type { GoalTask, GoalTaskList, TaskStatus } from "../goal-record.ts";
12
+ import type { GoalSettings } from "../goal-settings.ts";
13
+
14
+ type GoalWidgetColor = Extract<ThemeColor, "accent" | "warning" | "success" | "error" | "dim" | "muted" | "text">;
15
+
16
+ export interface GoalWidgetRecord extends GoalDisplayRecordLike {
17
+ id: string;
18
+ createdAt: string;
19
+ updatedAt: string;
20
+ activePath?: string | null;
21
+ archivedPath?: string | null;
22
+ pauseReason?: string;
23
+ pauseSuggestedAction?: string;
24
+ taskList?: GoalTaskList | null;
25
+ verificationContract?: string;
26
+ }
27
+
28
+ export interface AuditorWidgetProgress {
29
+ currentTool?: string;
30
+ currentToolArgs?: string;
31
+ currentToolStartedAt?: number;
32
+ recentOutput: string[];
33
+ phase: "running" | "tool_executing" | "producing_report" | "thinking" | "done";
34
+ elapsedMs: number;
35
+ /** Current step label shown to the user */
36
+ label?: string;
37
+ /** Completion percentage from 0 to 100 */
38
+ percentage?: number;
39
+ }
40
+
41
+ export interface GoalWidgetOptions {
42
+ theme: Theme;
43
+ tui: TUI;
44
+ getGoal: () => GoalWidgetRecord | null;
45
+ getOpenGoalCount?: () => number;
46
+ getAuditorProgress?: () => AuditorWidgetProgress | null;
47
+ getSettings?: () => GoalSettings;
48
+ getDebugMode?: () => boolean;
49
+ }
50
+
51
+ function fit(value: string, width: number): string {
52
+ return visibleWidth(value) > width ? truncateToWidth(value, width, "…") : value;
53
+ }
54
+
55
+ function heading(theme: Theme, width: number, left: string, right = ""): string {
56
+ if (!right) return fit(left, width);
57
+ const rightPart = ` ${right}`;
58
+ const fill = Math.max(1, width - visibleWidth(left) - visibleWidth(rightPart));
59
+ return fit(`${left}${theme.fg("dim", " ".repeat(fill))}${rightPart}`, width);
60
+ }
61
+
62
+ function branchLine(theme: Theme, width: number, isLast: boolean, content: string): string {
63
+ const prefix = isLast ? "└─" : "├─";
64
+ return fit(`${theme.fg("dim", prefix)} ${content}`, width);
65
+ }
66
+
67
+ function progressBar(pct: number, barWidth: number, theme: Theme): string {
68
+ const safeBar = Math.max(3, barWidth);
69
+ const filled = Math.min(safeBar, Math.max(0, Math.round((pct / 100) * safeBar)));
70
+ const empty = safeBar - filled;
71
+ return `[${theme.fg("accent", "█".repeat(filled))}${theme.fg("dim", "░".repeat(empty))}]`;
72
+ }
73
+
74
+ function displayIcon(goal: GoalWidgetRecord): { icon: string; color: GoalWidgetColor; label: string } {
75
+ if (goal.status === "complete") return { icon: "✓", color: "success", label: "complete" };
76
+ if (goal.status === "paused") {
77
+ return goal.stopReason === "agent"
78
+ ? { icon: "⊘", color: "warning", label: "blocked" }
79
+ : { icon: "◐", color: "muted", label: "paused" };
80
+ }
81
+ if (goal.sisyphus) return { icon: "◆", color: "accent", label: goal.autoContinue ? "sisyphus running" : "sisyphus idle" };
82
+ return goal.autoContinue ? { icon: "●", color: "accent", label: "goal running" } : { icon: "○", color: "muted", label: "goal idle" };
83
+ }
84
+
85
+ function countFlatTasks(tasks: GoalTask[]): { total: number; done: number } {
86
+ let total = 0;
87
+ let done = 0;
88
+ for (const t of tasks) {
89
+ total++;
90
+ if (t.status === "complete" || t.status === "skipped") done++;
91
+ if (t.subtasks && t.subtasks.length > 0) {
92
+ const child = countFlatTasks(t.subtasks);
93
+ total += child.total;
94
+ done += child.done;
95
+ }
96
+ }
97
+ return { total, done };
98
+ }
99
+
100
+ function findFirstPending(tasks: GoalTask[]): GoalTask | undefined {
101
+ const queue = [...tasks];
102
+ while (queue.length > 0) {
103
+ const t = queue.shift()!;
104
+ if (t.status === "pending") return t;
105
+ if (t.subtasks) queue.push(...t.subtasks);
106
+ }
107
+ return undefined;
108
+ }
109
+
110
+ function headingMeta(goal: GoalWidgetRecord, otherOpenGoalCount = 0, disableTasks = false): string {
111
+ const bits: string[] = [];
112
+ if (goal.status === "active" && goal.autoContinue) bits.push("auto");
113
+ if (goal.usage.activeSeconds > 0) bits.push(formatDuration(goal.usage.activeSeconds));
114
+ if (goal.usage.tokensUsed > 0) bits.push(formatTokenValue(goal.usage.tokensUsed));
115
+ if (!disableTasks && goal.taskList && goal.taskList.tasks.length > 0) {
116
+ const { total, done } = countFlatTasks(goal.taskList.tasks);
117
+ bits.push(`${done}/${total} tasks`);
118
+ }
119
+ if (otherOpenGoalCount > 0) bits.push(`+${otherOpenGoalCount} open`);
120
+ return bits.join(" · ");
121
+ }
122
+
123
+ const SPINNER = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
124
+
125
+ function spinnerFrame(): string {
126
+ return SPINNER[Math.floor(Date.now() / 80) % SPINNER.length]!;
127
+ }
128
+
129
+ export function renderAuditorWidgetLines(progress: AuditorWidgetProgress, theme: Theme, width: number): string[] {
130
+ const safeWidth = Math.max(1, width);
131
+ const isActive = progress.phase !== "done";
132
+ const isThinking = progress.phase === "thinking";
133
+ const icon = isActive
134
+ ? isThinking
135
+ ? theme.fg("muted", "⟡")
136
+ : theme.fg("accent", spinnerFrame())
137
+ : theme.fg("success", "✓");
138
+ const label = isActive
139
+ ? isThinking
140
+ ? "thinking..."
141
+ : "auditing"
142
+ : "audit complete";
143
+ // formatDuration expects seconds, progress.elapsedMs is in milliseconds
144
+ const duration = formatDuration(Math.floor(progress.elapsedMs / 1000));
145
+ const lines: string[] = [
146
+ heading(
147
+ theme,
148
+ safeWidth,
149
+ `${icon} ${theme.fg("accent", theme.bold("Audit"))} ${theme.fg("muted", label)}`,
150
+ theme.fg("muted", duration),
151
+ ),
152
+ ];
153
+
154
+ // Show step label when available
155
+ if (progress.label) {
156
+ lines.push(branchLine(
157
+ theme,
158
+ safeWidth,
159
+ false,
160
+ `${theme.fg("text", truncateText(progress.label, Math.max(8, safeWidth - 6)))}`,
161
+ ));
162
+ }
163
+
164
+ // Show progress bar when percentage is available
165
+ if (typeof progress.percentage === "number") {
166
+ const barWidth = Math.max(6, Math.min(safeWidth - 10, 30));
167
+ const bar = progressBar(progress.percentage, barWidth, theme);
168
+ const pct = `${theme.fg("muted", `${Math.round(progress.percentage)}%`)}`;
169
+ lines.push(branchLine(
170
+ theme,
171
+ safeWidth,
172
+ isActive && !progress.currentTool && progress.recentOutput.length === 0 && !isThinking,
173
+ `${bar} ${pct}`,
174
+ ));
175
+ }
176
+
177
+ if (isActive && !isThinking && progress.currentTool) {
178
+ const argText = progress.currentToolArgs
179
+ ? truncateText(progress.currentToolArgs, Math.max(10, safeWidth - 24))
180
+ : "";
181
+ const toolDuration = progress.currentToolStartedAt
182
+ ? ` ${theme.fg("dim", formatDuration(Math.floor((Date.now() - progress.currentToolStartedAt) / 1000)))}`
183
+ : "";
184
+ lines.push(branchLine(
185
+ theme,
186
+ safeWidth,
187
+ false,
188
+ `${theme.fg("accent", "tool")} ${theme.fg("text", progress.currentTool)}${argText ? ` ${theme.fg("dim", argText)}` : ""}${toolDuration}`,
189
+ ));
190
+ }
191
+
192
+ if (progress.recentOutput.length > 0) {
193
+ // Show separator
194
+ lines.push(branchLine(
195
+ theme,
196
+ safeWidth,
197
+ !isActive,
198
+ theme.fg("dim", "─".repeat(Math.max(4, safeWidth - 6))),
199
+ ));
200
+ for (const [index, line] of progress.recentOutput.entries()) {
201
+ const isLast = index === progress.recentOutput.length - 1 && !isActive;
202
+ lines.push(branchLine(
203
+ theme,
204
+ safeWidth,
205
+ isLast,
206
+ theme.fg("dim", truncateText(line, Math.max(8, safeWidth - 6))),
207
+ ));
208
+ }
209
+ }
210
+
211
+ // Show skip hint when audit is actively running
212
+ if (isActive && !isThinking) {
213
+ lines.push(branchLine(
214
+ theme,
215
+ safeWidth,
216
+ true,
217
+ theme.fg("warning", "Esc to skip") + theme.fg("dim", " — abort the audit and let the user decide"),
218
+ ));
219
+ }
220
+
221
+ return lines;
222
+ }
223
+
224
+ export function renderGoalWidgetLines(goal: GoalWidgetRecord | null, theme: Theme, width: number, options: { openGoalCount?: number; auditorProgress?: AuditorWidgetProgress | null; disableTasks?: boolean } = {}): string[] {
225
+ // When auditor progress is active, show auditor display instead of normal goal widget
226
+ if (options.auditorProgress) {
227
+ return renderAuditorWidgetLines(options.auditorProgress, theme, width);
228
+ }
229
+ if (!goal) {
230
+ const openGoalCount = options.openGoalCount ?? 0;
231
+ if (openGoalCount <= 0) return [];
232
+ const safeWidth = Math.max(1, width);
233
+ return [
234
+ heading(theme, safeWidth, `${theme.fg("warning", "◇")} ${theme.fg("warning", theme.bold("Goal"))} ${theme.fg("muted", "unfocused")}`, theme.fg("muted", `${openGoalCount} open`)),
235
+ branchLine(theme, safeWidth, true, `${theme.fg("muted", "Run /goal-focus to choose this session's goal")}`),
236
+ ];
237
+ }
238
+ const safeWidth = Math.max(1, width);
239
+ const { icon, color, label } = displayIcon(goal);
240
+ const mode = goal.sisyphus ? "Sisyphus" : "Goal";
241
+ const headingLeft = `${theme.fg(color, icon)} ${theme.fg(color, theme.bold(mode))} ${theme.fg("muted", label.replace(/^sisyphus |^goal /, ""))}`;
242
+ const otherOpenGoalCount = Math.max(0, (options.openGoalCount ?? (goal ? 1 : 0)) - 1);
243
+ const headingRight = theme.fg("muted", headingMeta(goal, otherOpenGoalCount, options.disableTasks));
244
+ const lines: string[] = [heading(theme, safeWidth, headingLeft, headingRight)];
245
+ const body: string[] = [];
246
+
247
+ const titleWidth = Math.max(12, safeWidth - 8);
248
+ const objective = truncateText(displayObjectiveTitle(goal.objective), titleWidth);
249
+ body.push(`${theme.fg("accent", "⟡")} ${theme.fg("text", objective)}`);
250
+
251
+ if (!options.disableTasks && goal.taskList && goal.taskList.tasks.length > 0) {
252
+ const { total, done } = countFlatTasks(goal.taskList.tasks);
253
+ if (done === total) {
254
+ body.push(`${theme.fg("success", "✓")} ${theme.fg("muted", "All tasks complete")}`);
255
+ } else {
256
+ const firstPending = findFirstPending(goal.taskList.tasks);
257
+ if (firstPending) {
258
+ body.push(`${theme.fg("warning", "◻")} ${theme.fg("muted", `${firstPending.id}: ${truncateText(firstPending.title, Math.max(8, safeWidth - 20))} (next)`)}`);
259
+ }
260
+ }
261
+ }
262
+
263
+ if (goal.status === "paused" && goal.stopReason === "agent" && goal.pauseReason) {
264
+ body.push(`${theme.fg("warning", "blocker")} ${theme.fg("warning", truncateText(goal.pauseReason, Math.max(12, safeWidth - 14)))}`);
265
+ if (goal.pauseSuggestedAction) {
266
+ body.push(`${theme.fg("dim", "next")} ${theme.fg("muted", truncateText(goal.pauseSuggestedAction, Math.max(12, safeWidth - 10)))}`);
267
+ }
268
+ }
269
+
270
+ const path = goal.status === "complete" ? goal.archivedPath : goal.activePath;
271
+ if (path) {
272
+ body.push(theme.fg("dim", path));
273
+ }
274
+
275
+ for (const [index, content] of body.entries()) {
276
+ lines.push(branchLine(theme, safeWidth, index === body.length - 1, content));
277
+ }
278
+
279
+ return lines;
280
+ }
281
+
282
+ export class GoalWidgetComponent implements Component {
283
+ private theme: Theme;
284
+ private tui: TUI;
285
+ private getGoal: () => GoalWidgetRecord | null;
286
+ private getOpenGoalCount: () => number;
287
+ private getAuditorProgress: () => AuditorWidgetProgress | null;
288
+ private getSettings: () => GoalSettings;
289
+ private getDebugMode: () => boolean;
290
+
291
+ constructor(options: GoalWidgetOptions) {
292
+ this.theme = options.theme;
293
+ this.tui = options.tui;
294
+ this.getGoal = options.getGoal;
295
+ this.getOpenGoalCount = options.getOpenGoalCount ?? (() => (this.getGoal() ? 1 : 0));
296
+ this.getAuditorProgress = options.getAuditorProgress ?? (() => null);
297
+ this.getSettings = options.getSettings ?? (() => ({}));
298
+ this.getDebugMode = options.getDebugMode ?? (() => false);
299
+ }
300
+
301
+ update(): void {
302
+ this.tui.requestRender();
303
+ }
304
+
305
+ /** Render debug info panel when debug mode is active */
306
+ private renderDebugPanel(width: number): string[] {
307
+ const t = this.theme;
308
+ const lines: string[] = [];
309
+ const safeWidth = Math.max(20, width);
310
+
311
+ // Divider
312
+ lines.push(t.fg("dim", "─".repeat(safeWidth)));
313
+ lines.push(t.fg("warning", "⊙ [DEBUG MODE]"));
314
+ lines.push("");
315
+
316
+ const goal = this.getGoal();
317
+ if (goal) {
318
+ lines.push(t.fg("dim", ` id: ${goal.id}`));
319
+ lines.push(t.fg("dim", ` status: ${goal.status}`));
320
+ lines.push(t.fg("dim", ` objective: ${truncateText(goal.objective, 80)}`));
321
+ lines.push(t.fg("dim", ` sisyphus: ${goal.sisyphus}`));
322
+ lines.push(t.fg("dim", ` autoContinue: ${goal.autoContinue}`));
323
+ lines.push(t.fg("dim", ` tokens: ${goal.usage.tokensUsed}`));
324
+ lines.push(t.fg("dim", ` activeSeconds: ${goal.usage.activeSeconds}`));
325
+ lines.push(t.fg("dim", ` createdAt: ${goal.createdAt}`));
326
+ lines.push(t.fg("dim", ` updatedAt: ${goal.updatedAt}`));
327
+ if (goal.pauseReason) lines.push(t.fg("dim", ` pauseReason: ${goal.pauseReason}`));
328
+ if (goal.pauseSuggestedAction) lines.push(t.fg("dim", ` pauseSuggestedAction: ${goal.pauseSuggestedAction}`));
329
+ if (goal.stopReason) lines.push(t.fg("dim", ` stopReason: ${goal.stopReason}`));
330
+ if (goal.activePath) lines.push(t.fg("dim", ` activePath: ${goal.activePath}`));
331
+ if (goal.archivedPath) lines.push(t.fg("dim", ` archivedPath: ${goal.archivedPath}`));
332
+ if (goal.verificationContract) lines.push(t.fg("dim", ` vContract: ${truncateText(goal.verificationContract, 60)}`));
333
+
334
+ // Task tree summary
335
+ if (goal.taskList && goal.taskList.tasks.length > 0) {
336
+ const { total, done } = countFlatTasks(goal.taskList.tasks);
337
+ lines.push(t.fg("dim", ` tasks: ${done}/${total}`));
338
+ const firstPending = findFirstPending(goal.taskList.tasks);
339
+ if (firstPending) lines.push(t.fg("dim", ` next: ${firstPending.id} (${truncateText(firstPending.title, 40)})`));
340
+ }
341
+ } else {
342
+ lines.push(t.fg("dim", " (no goal)"));
343
+ }
344
+
345
+ lines.push("");
346
+ lines.push(t.fg("dim", "── Debug keybindings ──"));
347
+ lines.push(t.fg("dim", " Ctrl+Shift+X Toggle debug mode"));
348
+ lines.push(t.fg("dim", " Ctrl+Shift+N Create test goal"));
349
+ lines.push(t.fg("dim", " Ctrl+Shift+T Inject sample tasks"));
350
+ lines.push(t.fg("dim", " Ctrl+Shift+R Mock audit animation"));
351
+ lines.push(t.fg("dim", " Ctrl+Shift+O Open proposal dialog"));
352
+
353
+ return lines;
354
+ }
355
+
356
+ render(width: number): string[] {
357
+ const settings = this.getSettings();
358
+ let lines = renderGoalWidgetLines(this.getGoal(), this.theme, width, {
359
+ openGoalCount: this.getOpenGoalCount(),
360
+ auditorProgress: this.getAuditorProgress(),
361
+ disableTasks: settings.disableTasks,
362
+ });
363
+ if (this.getDebugMode()) {
364
+ lines.push(...this.renderDebugPanel(width));
365
+ }
366
+ // Safety net: ensure no returned line exceeds the terminal width
367
+ for (let i = 0; i < lines.length; i++) {
368
+ if (visibleWidth(lines[i]) > width) {
369
+ lines[i] = truncateToWidth(lines[i], width);
370
+ }
371
+ }
372
+ return lines;
373
+ }
374
+
375
+ invalidate(): void {
376
+ this.tui.requestRender();
377
+ }
378
+ }