ceulen 0.8.0 → 0.9.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.
Files changed (95) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/extensions/lib/registry.ts +8 -1
  3. package/extensions/modules/a2a/configPanel.ts +435 -0
  4. package/extensions/modules/a2a/index.ts +1117 -0
  5. package/extensions/modules/a2a/lib/activity.ts +173 -0
  6. package/extensions/modules/a2a/lib/client.ts +1061 -0
  7. package/extensions/modules/a2a/lib/config.ts +920 -0
  8. package/extensions/modules/a2a/lib/discovery.ts +158 -0
  9. package/extensions/modules/a2a/lib/gateway.ts +889 -0
  10. package/extensions/modules/a2a/lib/mdns.ts +233 -0
  11. package/extensions/modules/a2a/lib/outcome.ts +48 -0
  12. package/extensions/modules/a2a/lib/persistence.ts +123 -0
  13. package/extensions/modules/a2a/lib/protocol.ts +506 -0
  14. package/extensions/modules/a2a/lib/registry.ts +146 -0
  15. package/extensions/modules/a2a/lib/retry.ts +86 -0
  16. package/extensions/modules/a2a/lib/security.ts +394 -0
  17. package/extensions/modules/a2a/lib/server.ts +1436 -0
  18. package/extensions/modules/a2a/test/activity.test.ts +138 -0
  19. package/extensions/modules/a2a/test/bridge.test.ts +101 -0
  20. package/extensions/modules/a2a/test/broadcast-parse.test.ts +31 -0
  21. package/extensions/modules/a2a/test/chai.ts +101 -0
  22. package/extensions/modules/a2a/test/client.test.ts +856 -0
  23. package/extensions/modules/a2a/test/completion-guard.test.ts +73 -0
  24. package/extensions/modules/a2a/test/config.test.ts +1396 -0
  25. package/extensions/modules/a2a/test/configPanel.test.ts +393 -0
  26. package/extensions/modules/a2a/test/discovery.test.ts +144 -0
  27. package/extensions/modules/a2a/test/extension.test.ts +135 -0
  28. package/extensions/modules/a2a/test/gateway.test.ts +1449 -0
  29. package/extensions/modules/a2a/test/helpers.ts +39 -0
  30. package/extensions/modules/a2a/test/mdns.test.ts +131 -0
  31. package/extensions/modules/a2a/test/outcome.test.ts +61 -0
  32. package/extensions/modules/a2a/test/persistence.test.ts +92 -0
  33. package/extensions/modules/a2a/test/protocol.test.ts +217 -0
  34. package/extensions/modules/a2a/test/registry.test.ts +114 -0
  35. package/extensions/modules/a2a/test/retry.test.ts +136 -0
  36. package/extensions/modules/a2a/test/security.test.ts +281 -0
  37. package/extensions/modules/a2a/test/server.test.ts +1966 -0
  38. package/extensions/modules/a2a/test/tmp.ts +59 -0
  39. package/extensions/modules/a2a/test/vendor.test.ts +57 -0
  40. package/extensions/modules/a2a/types/bonjour-service.d.ts +22 -0
  41. package/extensions/modules/a2a/vendor/VENDORED.md +18 -0
  42. package/extensions/modules/a2a/vendor/package.json +1 -0
  43. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/LICENSE +23 -0
  44. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/index.d.ts +14 -0
  45. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/index.js +57 -0
  46. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/KeyValue.d.ts +4 -0
  47. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/KeyValue.js +3 -0
  48. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/bonjour.d.ts +13 -0
  49. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/bonjour.js +50 -0
  50. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/browser.d.ts +41 -0
  51. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/browser.js +209 -0
  52. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/dns-txt.d.ts +9 -0
  53. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/dns-txt.js +42 -0
  54. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/mdns-server.d.ts +14 -0
  55. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/mdns-server.js +119 -0
  56. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/registry.d.ts +14 -0
  57. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/registry.js +142 -0
  58. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service-types.d.ts +7 -0
  59. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service-types.js +53 -0
  60. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service.d.ts +58 -0
  61. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service.js +130 -0
  62. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/dns-equal.d.ts +1 -0
  63. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/dns-equal.js +13 -0
  64. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/equal-txt.d.ts +1 -0
  65. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/equal-txt.js +17 -0
  66. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-service.d.ts +4 -0
  67. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-service.js +22 -0
  68. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-txt.d.ts +3 -0
  69. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-txt.js +6 -0
  70. package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/LICENSE +21 -0
  71. package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/classes.js +23 -0
  72. package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/index.js +1761 -0
  73. package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/opcodes.js +50 -0
  74. package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/optioncodes.js +59 -0
  75. package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/rcodes.js +50 -0
  76. package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/types.js +103 -0
  77. package/extensions/modules/a2a/vendor/vendored_deps/fast-deep-equal/LICENSE +21 -0
  78. package/extensions/modules/a2a/vendor/vendored_deps/fast-deep-equal/es6.js +73 -0
  79. package/extensions/modules/a2a/vendor/vendored_deps/fast-deep-equal/index.js +46 -0
  80. package/extensions/modules/a2a/vendor/vendored_deps/ip-codec/LICENSE +21 -0
  81. package/extensions/modules/a2a/vendor/vendored_deps/ip-codec/index.cjs +250 -0
  82. package/extensions/modules/a2a/vendor/vendored_deps/multicast-dns/LICENSE +21 -0
  83. package/extensions/modules/a2a/vendor/vendored_deps/multicast-dns/index.js +205 -0
  84. package/extensions/modules/a2a/vendor/vendored_deps/thunky/LICENSE +21 -0
  85. package/extensions/modules/a2a/vendor/vendored_deps/thunky/index.js +55 -0
  86. package/extensions/modules/composer/test/module.test.ts +2 -2
  87. package/extensions/modules/config/index.ts +2 -0
  88. package/extensions/modules/config/test/renderTools.test.ts +1 -1
  89. package/extensions/modules/todo/configPanel.ts +55 -0
  90. package/extensions/modules/todo/index.ts +46 -13
  91. package/extensions/modules/todo/lib/render.ts +271 -0
  92. package/extensions/modules/todo/lib/settings.ts +73 -0
  93. package/extensions/modules/todo/test/todo.test.ts +276 -0
  94. package/package.json +2 -2
  95. package/skills/a2a/SKILL.md +63 -0
@@ -0,0 +1,271 @@
1
+ // todo widget — the themed above-editor HUD + shared board renderer (OMP look).
2
+ //
3
+ // Pattern: extensions/modules/subagent/lib/widget.ts (WidgetTheme shim, pure
4
+ // renderers, small controller owning the setWidget handle). Todo is simpler:
5
+ // no live subscription — the widget only changes on a tool mutation, so the
6
+ // controller re-renders on demand and carries the ALL-DONE LINGER timer
7
+ // (OMP parity: the completed board stays `lingerSecs` before auto-clearing).
8
+ //
9
+ // Visual language (matched to OMP's todo HUD, user-approved 2026-10-04;
10
+ // nested-tree + progress-spine per the 2026-10-04 side-by-side):
11
+ // TODO
12
+ // └─ Tasks · 2/5 head connector accents when ALL done
13
+ // ├─ ☑ done-title success + strikethrough (stays visible)
14
+ // ├─ ☐ current-title mdLink (blue = "current"), default fg title
15
+ // └─ ☐ pending-title dim
16
+ // The tree spine is OMP's progress path: a connector turns accent once its
17
+ // phase is done — the completed tree reads as one lit path. Blocked rows keep
18
+ // the warning treatment + `(blocked by …)` tail; ids and notes stay in dim
19
+ // tails. The LLM-facing text board (index.ts) is unchanged.
20
+ //
21
+ // Rendering uses theme tokens only (theme.fg/bold/strikethrough) — no raw ANSI.
22
+
23
+ import { truncateToWidth } from "@earendil-works/pi-tui";
24
+ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
25
+ import { effectiveStatus, TODO_WIDGET_KEY, type TodoPhase } from "../index.ts";
26
+
27
+ /** Theme shim so renderers are testable without a Theme instance. */
28
+ export interface WidgetTheme {
29
+ fg(color: string, text: string): string;
30
+ bold?(text: string): string;
31
+ strikethrough?(text: string): string;
32
+ }
33
+
34
+ function c(theme: WidgetTheme | null | undefined, token: string, text: string): string {
35
+ return theme?.fg ? theme.fg(token, text) : text;
36
+ }
37
+
38
+ // Tree-spine glyphs (OMP's renderTreeList shape, 1-column cells).
39
+ const SPINE_BRANCH = "├─ ";
40
+ const SPINE_LAST = "└─ ";
41
+ const SPINE_VERT = "│ ";
42
+ const SPINE_BLANK = " ";
43
+
44
+ /** One nested child row's spine prefix (1-space gutter + 3-cell indent under
45
+ * the group head — OMP's tree geometry). */
46
+ const childSpine = (last: boolean): string => " " + SPINE_BLANK + (last ? SPINE_LAST : SPINE_BRANCH);
47
+
48
+ /** Checked/unchecked box for a phase. */
49
+ function box(st: "pending" | "in_progress" | "done" | "blocked"): string {
50
+ return st === "done" ? "☑" : "☐";
51
+ }
52
+
53
+ /** One themed phase row. `spine` prefixes the row (tree connectors); `current`
54
+ * marks the in-progress phase (mdLink = OMP's blue "current"). */
55
+ function phaseRow(
56
+ p: TodoPhase,
57
+ phases: readonly TodoPhase[],
58
+ theme: WidgetTheme | null | undefined,
59
+ spine: string,
60
+ current: boolean,
61
+ width: number,
62
+ /** OMP: notes collapse to a `+n` marker — full text lives in the tool result. */
63
+ compact = false,
64
+ ): string {
65
+ const st = effectiveStatus(p, phases);
66
+ const waiters = p.blockedBy.filter((dep) => phases.find((x) => x.id === dep)?.status !== "done");
67
+ const title = st === "done" && theme?.strikethrough ? theme.strikethrough(p.title) : p.title;
68
+ const noteCount = (p.notes ? 1 : 0) + (st === "blocked" && waiters.length > 0 ? 1 : 0);
69
+ const tail = compact
70
+ ? ""
71
+ : (
72
+ [
73
+ st === "blocked" && waiters.length > 0 ? `blocked by ${waiters.join(", ")}` : undefined,
74
+ p.notes,
75
+ ]
76
+ .filter(Boolean)
77
+ .join(" — ")
78
+ );
79
+ const line =
80
+ // OMP's progress path: the connector lights accent once its phase is done.
81
+ c(theme, st === "done" ? "accent" : "dim", spine) +
82
+ c(theme, st === "done" ? "success" : current ? "mdLink" : "dim", box(st)) +
83
+ " " +
84
+ c(theme, st === "done" ? "success" : current ? "mdLink" : st === "blocked" ? "warning" : "dim", title) +
85
+ (tail ? c(theme, "dim", ` (${tail})`) : "") +
86
+ (compact && noteCount > 0 ? c(theme, "dim", ` +${noteCount}`) : "");
87
+ return line.length > width ? truncateToWidth(line, width) : line;
88
+ }
89
+
90
+ /**
91
+ * The full board, one themed line per phase — the transcript renderResult
92
+ * surface and the all-done widget view. Same OMP visual language as the
93
+ * widget (tree spine, checkboxes); ids/notes ride the dim tails.
94
+ */
95
+ export function renderTodoBoard(phases: readonly TodoPhase[], theme?: WidgetTheme | null, width = 100): string[] {
96
+ if (phases.length === 0) return [c(theme, "dim", "Todo list is empty.")];
97
+ const lines: string[] = [];
98
+ for (const [i, p] of phases.entries()) {
99
+ const last = i === phases.length - 1;
100
+ const spine = childSpine(last);
101
+ lines.push(phaseRow(p, phases, theme, spine, effectiveStatus(p, phases) === "in_progress", width));
102
+ }
103
+ return lines;
104
+ }
105
+
106
+ /** Phases shown around the active one in the HUD window. */
107
+ const WINDOW_OPEN = 5; // active phase + up to 4 following open phases (OMP's cap shape)
108
+
109
+ /**
110
+ * The bounded HUD window (OMP look): `TODO` header, then the phase subtree —
111
+ * `└─ Tasks · done/total` with done phases KEPT visible (green strikethrough),
112
+ * the current phase in mdLink blue, pending muted, `+ n more phases` tail when
113
+ * truncated. An all-done list renders every phase (the closure view).
114
+ */
115
+ export function renderTodoWidgetLines(phases: readonly TodoPhase[], theme?: WidgetTheme | null, width = 100): string[] {
116
+ if (phases.length === 0) return [];
117
+ const done = phases.filter((p) => p.status === "done").length;
118
+ const all = done === phases.length;
119
+ const header =
120
+ c(theme, "accent", theme?.bold ? theme.bold("TODO") : "TODO");
121
+
122
+ // Subtree head: OMP's single root elbowing into its children (`└─`), the
123
+ // connector accenting only when the whole path is complete. The group is
124
+ // the whole list — ceulen phases are flat, so the label is fixed.
125
+ const groupHead =
126
+ " " +
127
+ c(theme, all ? "accent" : "dim", SPINE_LAST) +
128
+ c(theme, "mdLink", theme?.bold ? theme.bold("Tasks") : "Tasks") +
129
+ c(theme, "dim", ` · ${done}/${phases.length}`) +
130
+ (!all && phases.some((p) => effectiveStatus(p, phases) === "blocked") ? c(theme, "warning", " · blocked") : "");
131
+
132
+ if (all) {
133
+ const rows = phases.map((p, i) =>
134
+ phaseRow(p, phases, theme, childSpine(i === phases.length - 1), false, width, true),
135
+ );
136
+ return [header, groupHead, ...rows];
137
+ }
138
+
139
+ // OMP parity: done rows STAY visible (green strikethrough). The window
140
+ // slides to show the active phase with context: one done row above it (the
141
+ // just-finished step) + the pending tail, capped at WINDOW_OPEN rows.
142
+ const activeIdx = phases.findIndex((p) => effectiveStatus(p, phases) === "in_progress");
143
+ const start = activeIdx === -1 ? 0 : Math.max(0, activeIdx - 1);
144
+ const windowed = phases.slice(start, start + WINDOW_OPEN);
145
+ const hidden = phases.length - windowed.length;
146
+ const rows = windowed.map((p, i) =>
147
+ phaseRow(p, phases, theme, childSpine(i === windowed.length - 1 && hidden === 0), effectiveStatus(p, phases) === "in_progress", width, true),
148
+ );
149
+ if (hidden > 0) rows.push(c(theme, "dim", `${childSpine(true)}+ ${hidden} more phase${hidden === 1 ? "" : "s"}`));
150
+ return [header, groupHead, ...rows];
151
+ }
152
+
153
+ // ---------------------------------------------------------------------------
154
+ // Controller — owns the setWidget handle + the all-done linger timer
155
+ // ---------------------------------------------------------------------------
156
+
157
+ export interface WidgetUi {
158
+ mode?: string;
159
+ ui: ExtensionContext["ui"];
160
+ }
161
+
162
+ export interface TodoWidgetController {
163
+ /** Install/refresh/clear per current phases. `lingerSecs`:
164
+ * >0 = seconds the all-done board stays, 0 = clear instantly, -1 = never auto-clear.
165
+ * `render` reads through `getPhases` so re-renders always draw CURRENT state —
166
+ * a captured array would freeze the board at the install-time snapshot. */
167
+ sync(target: WidgetUi | undefined, phases: readonly TodoPhase[], lingerSecs: number, getPhases?: () => readonly TodoPhase[]): void;
168
+ /** Remove the widget + cancel the timer (stale ctx tolerated). */
169
+ clear(target?: WidgetUi): void;
170
+ dispose(): void;
171
+ /** Test seam: true while a linger timer is armed. */
172
+ lingerArmed(): boolean;
173
+ }
174
+
175
+ export function createTodoWidgetController(): TodoWidgetController {
176
+ let widgetCtx: ExtensionContext["ui"] | null = null;
177
+ let requestWidgetRender: (() => void) | null = null;
178
+ let widgetTheme: WidgetTheme | null = null;
179
+ let lingerTimer: ReturnType<typeof setTimeout> | undefined;
180
+ let generation = 0;
181
+ /** Live view of the board — swapped by sync so the render closure never
182
+ * holds a stale snapshot. */
183
+ let current: readonly TodoPhase[] = [];
184
+
185
+ const stale = <T>(fn: () => T): T | undefined => {
186
+ try {
187
+ return fn();
188
+ } catch {
189
+ return undefined; // stale ctx after session replacement
190
+ }
191
+ };
192
+
193
+ function cancelLinger(): void {
194
+ generation += 1;
195
+ if (lingerTimer) {
196
+ clearTimeout(lingerTimer);
197
+ lingerTimer = undefined;
198
+ }
199
+ }
200
+
201
+ function removeWidget(): void {
202
+ if (widgetCtx) {
203
+ const ui = widgetCtx;
204
+ stale(() => ui.setWidget(TODO_WIDGET_KEY, undefined));
205
+ widgetCtx = null;
206
+ }
207
+ requestWidgetRender = null;
208
+ widgetTheme = null;
209
+ }
210
+
211
+ return {
212
+ sync(target, phases, lingerSecs, getPhases) {
213
+ cancelLinger();
214
+ current = getPhases ? getPhases() : phases;
215
+ if (!target || target.mode !== "tui") return;
216
+ const { ui } = target;
217
+ if (phases.length === 0) {
218
+ removeWidget();
219
+ return;
220
+ }
221
+ const all = phases.every((p) => p.status === "done");
222
+ if (all && lingerSecs === 0) {
223
+ removeWidget();
224
+ return;
225
+ }
226
+ if (widgetCtx) {
227
+ requestWidgetRender?.();
228
+ } else {
229
+ stale(() =>
230
+ ui.setWidget(TODO_WIDGET_KEY, (tui, theme) => {
231
+ widgetTheme = theme as unknown as WidgetTheme;
232
+ requestWidgetRender = () => tui.requestRender();
233
+ return {
234
+ render: (width: number) => renderTodoWidgetLines(current, widgetTheme, width),
235
+ invalidate: () => requestWidgetRender?.(),
236
+ dispose: () => {
237
+ widgetTheme = null;
238
+ requestWidgetRender = null;
239
+ },
240
+ };
241
+ }),
242
+ );
243
+ widgetCtx = ui;
244
+ }
245
+ if (all && lingerSecs >= 0) {
246
+ const gen = generation;
247
+ lingerTimer = setTimeout(() => {
248
+ if (gen !== generation) return; // a newer sync canceled this arm
249
+ lingerTimer = undefined;
250
+ removeWidget();
251
+ }, lingerSecs * 1000);
252
+ lingerTimer.unref?.();
253
+ }
254
+ },
255
+
256
+ clear(target) {
257
+ cancelLinger();
258
+ if (target?.ui && target.ui !== widgetCtx) {
259
+ stale(() => target.ui.setWidget(TODO_WIDGET_KEY, undefined));
260
+ }
261
+ removeWidget();
262
+ },
263
+
264
+ dispose() {
265
+ cancelLinger();
266
+ removeWidget();
267
+ },
268
+
269
+ lingerArmed: () => lingerTimer !== undefined,
270
+ };
271
+ }
@@ -0,0 +1,73 @@
1
+ // todo settings — the `todo` section of the GLOBAL agent-dir settings.json.
2
+ // ponytail: deliberately global-only (no trusted-project overlay) — a cosmetic
3
+ // preference; add the overlay only if a project genuinely needs it.
4
+ //
5
+ // "todo": {
6
+ // "lingerSecs": 60 // seconds the all-done HUD stays up; 0 = instant clear, -1 = never
7
+ // }
8
+
9
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
10
+ import os from "node:os";
11
+ import path from "node:path";
12
+
13
+ export const DEFAULT_LINGER_SECS = 60;
14
+
15
+ /** Closed set for the /config row (plan: values 0 / 60 / 300 / 900 / -1). */
16
+ export const LINGER_VALUES = ["0", "60", "300", "900", "-1"] as const;
17
+ export type LingerValue = (typeof LINGER_VALUES)[number];
18
+
19
+ export const LINGER_DESCRIPTIONS: Record<LingerValue, string> = {
20
+ "0": "Instant — the HUD clears the moment the last phase completes",
21
+ "60": "1 minute (default)",
22
+ "300": "5 minutes",
23
+ "900": "15 minutes",
24
+ "-1": "Never auto-clears — /todo clear removes it",
25
+ };
26
+
27
+ function agentDir(): string {
28
+ return process.env.PI_CODING_AGENT_DIR || path.join(os.homedir(), ".pi", "agent");
29
+ }
30
+
31
+ export function globalSettingsPath(): string {
32
+ return path.join(agentDir(), "settings.json");
33
+ }
34
+
35
+ /** Effective linger seconds: default ← global `todo.lingerSecs`. Unset/garbage
36
+ * → default. `allow` (the /config closed set) clamps the accepted values. */
37
+ export function readLingerSecs(): number {
38
+ const file = globalSettingsPath();
39
+ try {
40
+ if (!existsSync(file)) return DEFAULT_LINGER_SECS;
41
+ const raw = (JSON.parse(readFileSync(file, "utf8"))?.todo ?? {}) as { lingerSecs?: unknown };
42
+ const n = typeof raw.lingerSecs === "string" ? parseInt(raw.lingerSecs, 10) : raw.lingerSecs;
43
+ if (typeof n !== "number" || !Number.isFinite(n)) return DEFAULT_LINGER_SECS;
44
+ if (n === -1) return -1;
45
+ if (n < 0) return DEFAULT_LINGER_SECS;
46
+ // Out-of-set values are clamped into the closed set (nearest member).
47
+ const allowed = [...LINGER_VALUES.map(Number), DEFAULT_LINGER_SECS].sort((a, b) => a - b);
48
+ return allowed.reduce((best, v) => (Math.abs(v - n) < Math.abs(best - n) ? v : best));
49
+ } catch {
50
+ return DEFAULT_LINGER_SECS; // unreadable/corrupt → default
51
+ }
52
+ }
53
+
54
+ /** Read-modify-write `todo.lingerSecs` into the GLOBAL settings.json (merge,
55
+ * never clobber; atomic tmp+rename; a corrupt file refuses to clobber).
56
+ * Returns the written path. Exported for tests. */
57
+ export function writeTodoSection(lingerSecs: number): string {
58
+ const file = globalSettingsPath();
59
+ let settings: Record<string, unknown>;
60
+ try {
61
+ settings = existsSync(file) ? (JSON.parse(readFileSync(file, "utf8")) as Record<string, unknown>) : {};
62
+ } catch {
63
+ throw new Error(`${file} is not valid JSON — fix or remove it before saving.`);
64
+ }
65
+ const s = (settings.todo ?? {}) as Record<string, unknown>;
66
+ s.lingerSecs = lingerSecs;
67
+ settings.todo = s;
68
+ mkdirSync(path.dirname(file), { recursive: true });
69
+ const tmp = file + ".tmp";
70
+ writeFileSync(tmp, JSON.stringify(settings, null, 2) + "\n", { mode: 0o600 });
71
+ renameSync(tmp, file);
72
+ return file;
73
+ }
@@ -250,3 +250,279 @@ describe("/todo command", () => {
250
250
  assert.equal(h.notifications.at(-1), "Todo list is empty.");
251
251
  });
252
252
  });
253
+
254
+ // ---------------------------------------------------------------------------
255
+ // Themed renderers + HUD widget (lib/render.ts)
256
+ // ---------------------------------------------------------------------------
257
+
258
+ import { createTodoWidgetController, renderTodoBoard, renderTodoWidgetLines, type WidgetTheme } from "../lib/render.ts";
259
+
260
+ /** Recording theme shim — asserts colors by token, keeps text readable. */
261
+ function recTheme(): WidgetTheme & { tokens: string[] } {
262
+ const tokens: string[] = [];
263
+ return {
264
+ tokens,
265
+ fg: (color: string, text: string) => {
266
+ tokens.push(color);
267
+ return `<${color}>${text}</>`;
268
+ },
269
+ bold: (text: string) => `**${text}**`,
270
+ strikethrough: (text: string) => `~~${text}~~`,
271
+ };
272
+ }
273
+
274
+ const board = () => run([], { action: "init", phases: [{ title: "Read the repo" }, { title: "Port the tool" }, { title: "Verify" }] });
275
+
276
+ describe("renderTodoBoard (OMP look)", () => {
277
+ it("colors by status: done success+strikethrough, current mdLink, pending muted, blocked warning", () => {
278
+ const t = recTheme();
279
+ const phases = board();
280
+ mark(phases, "p1", "done");
281
+ mark(phases, "p2", "in_progress");
282
+ mark(phases, "p3", "blocked", ["p2"]);
283
+ const lines = renderTodoBoard(phases, t);
284
+ // Nested-tree geometry (OMP): rows indent under an implied head with their
285
+ // own connectors; a done row's connector lights accent (the progress path).
286
+ assert.match(lines[0]!, /<accent> ├─ <\/><success>☑<\/> <success>~~Read the repo~~<\/>/);
287
+ assert.match(lines[1]!, /<dim> ├─ <\/><mdLink>☐<\/> <mdLink>Port the tool<\/>/);
288
+ assert.match(lines[2]!, /<dim> └─ <\/><dim>☐<\/> <warning>Verify<\/><dim> \(blocked by p2\)<\/>/);
289
+ assert.ok(t.tokens.includes("success") && t.tokens.includes("mdLink") && t.tokens.includes("warning"));
290
+ });
291
+
292
+ it("done rows STAY VISIBLE with success + strikethrough (OMP parity — no omission in the full board)", () => {
293
+ const t = recTheme();
294
+ const phases = board();
295
+ mark(phases, "p1", "done");
296
+ const lines = renderTodoBoard(phases, t);
297
+ assert.equal(lines.length, 3);
298
+ assert.match(lines[0]!, /~~Read the repo~~/);
299
+ });
300
+
301
+ it("blocked tail lists unmet blockers only, notes ride the dim tail", () => {
302
+ const t = recTheme();
303
+ const phases = run([], { action: "init", phases: [{ id: "a", title: "One", notes: "check npm test" }, { id: "b", title: "Two", blockedBy: ["a"] }] });
304
+ const lines = renderTodoBoard(phases, t);
305
+ assert.match(lines[1]!, /\(blocked by a\)/);
306
+ assert.match(lines[0]!, /\(check npm test\)/);
307
+ // a satisfied → the dependent shows open (unmet-only rule)
308
+ mark(phases, "a", "done");
309
+ assert.match(renderTodoBoard(phases, t)[1]!, /<dim>Two<\/>$/);
310
+ });
311
+
312
+ it("without a theme the board is plain text (no ANSI)", () => {
313
+ const lines = renderTodoBoard(board());
314
+ for (const line of lines) assert.ok(!line.includes("\u001b") && !line.includes("<"), line);
315
+ assert.match(lines[0]!, / ├─ ☐ Read the repo/);
316
+ });
317
+
318
+ it("long titles truncate to width", () => {
319
+ const long = "x".repeat(200);
320
+ const phases = run([], { action: "init", phases: [{ title: long }] });
321
+ const lines = renderTodoBoard(phases, undefined, 40);
322
+ assert.ok(lines[0]!.length <= 40 + 40, `len=${lines[0]!.length}`);
323
+ });
324
+ });
325
+
326
+ describe("renderTodoWidgetLines (OMP look)", () => {
327
+ it("header TODO + group head Tasks · done/total; done rows stay, current mdLink", () => {
328
+ const t = recTheme();
329
+ const phases = board();
330
+ mark(phases, "p1", "done");
331
+ mark(phases, "p2", "in_progress");
332
+ const lines = renderTodoWidgetLines(phases, t);
333
+ assert.match(lines[0]!, /<accent>\*\*TODO\*\*<\/>/);
334
+ assert.match(lines[1]!, /^ <dim>└─ <\/><mdLink>\*\*Tasks\*\*<\/><dim> · 1\/3<\/>/);
335
+ // Done rows stay visible (OMP parity), current phase drawn in mdLink.
336
+ assert.match(lines[2]!, /<success>☑<\/> <success>~~Read the repo~~<\/>/);
337
+ assert.match(lines[3]!, /<mdLink>☐<\/> <mdLink>Port the tool<\/>/);
338
+ assert.match(lines[4]!, /<dim>Verify<\/>/);
339
+ });
340
+
341
+ it("caps the window at 5 open phases with a + n more tail", () => {
342
+ const phases = run([], { action: "init", phases: Array.from({ length: 8 }, (_, i) => ({ title: `Phase ${i + 1}` })) });
343
+ const lines = renderTodoWidgetLines(phases, recTheme());
344
+ const body = lines.filter((l) => /☐/.test(l));
345
+ assert.equal(body.length, 5);
346
+ assert.match(lines.at(-1)!, /\+ 3 more phases/);
347
+ });
348
+
349
+ it("done phases auto-unblock dependents (real blockedBy edge, not the title)", () => {
350
+ // Regression: a drill init once put "blocked by p5" only in the TITLE —
351
+ // the dependent then auto-started while its blocker was still pending.
352
+ const r = run([], {
353
+ action: "init",
354
+ phases: [
355
+ { title: "A" },
356
+ { title: "B", blockedBy: ["p1"] },
357
+ ],
358
+ });
359
+ assert.ok(r[1]!.status === "pending", "dependent must not auto-start");
360
+ assert.equal(r[1]!.blockedBy[0], "p1");
361
+ const after = run(r, { action: "done", id: "p1" });
362
+ assert.ok(after[1]!.status === "in_progress", "finishing the blocker auto-starts the dependent");
363
+ });
364
+
365
+ it("all-done renders the closure view: every phase checked green, counts on the group head", () => {
366
+ const t = recTheme();
367
+ const phases = board();
368
+ for (const p of phases) p.status = "done";
369
+ const lines = renderTodoWidgetLines(phases, t);
370
+ assert.match(lines[1]!, /<dim> · 3\/3<\/>/);
371
+ // All-done: the whole path is lit (head + connectors accent) — OMP's
372
+ // completed-tree look from the user's screenshot.
373
+ assert.match(lines[1]!, /^ <accent>└─ <\/>/);
374
+ assert.match(lines[2]!, /<accent> ├─ <\/><success>☑<\/>/);
375
+ assert.equal(lines.filter((l) => /☑/.test(l)).length, 3);
376
+ assert.ok(lines.every((l) => !l.includes("▸ ")), "no footer fraction line (counts moved to the head)");
377
+ });
378
+
379
+ it("empty list renders nothing", () => {
380
+ assert.deepEqual(renderTodoWidgetLines([], recTheme()), []);
381
+ });
382
+ });
383
+
384
+ describe("todo HUD widget controller", () => {
385
+ interface WidgetCall { content: unknown }
386
+ function harness() {
387
+ const widgets: WidgetCall[] = [];
388
+ const ui: any = {
389
+ setWidget: (key: string, content: unknown) => widgets.push({ content }),
390
+ setStatus: () => {},
391
+ };
392
+ const ctx = { mode: "tui", ui };
393
+ const ctl = createTodoWidgetController();
394
+ return { widgets, ui, ctx, ctl };
395
+ }
396
+
397
+ it("installs on first open work, re-renders on change, headless is a no-op", () => {
398
+ const h = harness();
399
+ const live = board();
400
+ h.ctl.sync(h.ctx, live, 60, () => live);
401
+ assert.equal(h.widgets.length, 1, "widget installed once");
402
+ const factory = h.widgets[0]!.content as any;
403
+ assert.equal(typeof factory, "function", "component-factory form (theme-aware)");
404
+ // Re-render through the factory: captures theme, renders lines.
405
+ let renders = 0;
406
+ const comp = factory({ requestRender: () => renders++ }, recTheme());
407
+ const lines: string[] = comp.render(120);
408
+ assert.match(lines[0]!, /TODO/);
409
+ h.ctl.sync(h.ctx, live, 60, () => live);
410
+ assert.equal(h.widgets.length, 1, "already installed → requestRender, not re-set");
411
+ assert.ok(renders >= 1);
412
+ // Headless: nothing installs.
413
+ const headless = harness();
414
+ headless.ctl.sync({ mode: "rpc", ui: headless.ui } as any, board(), 60);
415
+ assert.equal(headless.widgets.length, 0);
416
+ });
417
+
418
+ it("re-renders draw CURRENT state, not the install-time snapshot (live-caught stale closure)", () => {
419
+ const h = harness();
420
+ const live = board(); // 3 phases, p1 auto-started
421
+ h.ctl.sync(h.ctx, live, 60, () => live);
422
+ const comp = (h.widgets[0]!.content as any)({ requestRender: () => {} }, recTheme());
423
+ assert.match(comp.render(120).join("\n"), /\*\*Tasks\*\*<\/><dim> · 0\/3<\/>/);
424
+ assert.ok(!/· 3\/3/.test(comp.render(120).join("\n")), "open board while work remains");
425
+ // Mutate the SAME array (module state) and re-sync: render must reflect it.
426
+ for (const p of live) p.status = "done";
427
+ h.ctl.sync(h.ctx, live, 60, () => live);
428
+ const after = comp.render(120).join("\n");
429
+ assert.match(after, /Tasks[^\n]*3\/3/, "group-head counts update after mutation");
430
+ assert.equal((after.match(/☑/g) ?? []).length, 3, "all rows checked in the completion view");
431
+ // Also without an explicit getPhases: sync swaps the internal view.
432
+ const h2 = harness();
433
+ const first = board();
434
+ h2.ctl.sync(h2.ctx, first, 60);
435
+ const comp2 = (h2.widgets[0]!.content as any)({ requestRender: () => {} }, recTheme());
436
+ const done = board();
437
+ for (const p of done) p.status = "done";
438
+ h2.ctl.sync(h2.ctx, done, 60);
439
+ assert.match(comp2.render(120).join("\n"), /· 3\/3/);
440
+ assert.equal((comp2.render(120).join("\n").match(/☑/g) ?? []).length, 3);
441
+ });
442
+
443
+ it("all-done with linger 0 clears the widget instantly; -1 never arms the timer", () => {
444
+ const done = () => { const p = board(); for (const x of p) x.status = "done"; return p; };
445
+ const instant = harness();
446
+ instant.ctl.sync(instant.ctx, board(), 60);
447
+ instant.ctl.sync(instant.ctx, done(), 0);
448
+ assert.equal((instant.widgets.at(-1)!.content as any), undefined, "linger 0 → removed");
449
+ assert.equal(instant.ctl.lingerArmed(), false);
450
+
451
+ const never = harness();
452
+ never.ctl.sync(never.ctx, board(), 60);
453
+ never.ctl.sync(never.ctx, done(), -1);
454
+ assert.equal(never.widgets.length, 1, "linger -1 → widget stays");
455
+ assert.equal(never.ctl.lingerArmed(), false, "no timer armed");
456
+ });
457
+
458
+ it("a new mutation after all-done cancels the pending linger (generation guard)", () => {
459
+ const done = () => { const p = board(); for (const x of p) x.status = "done"; return p; };
460
+ const h = harness();
461
+ h.ctl.sync(h.ctx, done(), 1); // arms a 1s timer
462
+ assert.ok(h.ctl.lingerArmed(), "timer armed");
463
+ h.ctl.sync(h.ctx, board(), 60); // new work before it fires
464
+ assert.equal(h.ctl.lingerArmed(), false, "timer canceled by newer sync");
465
+ assert.equal(h.widgets.length, 1, "widget re-used, not re-installed");
466
+ });
467
+
468
+ it("clear/dispose remove the widget; clear tolerates an unknown ui (stale ctx)", () => {
469
+ const h = harness();
470
+ h.ctl.sync(h.ctx, board(), 60);
471
+ h.ctl.clear({ mode: "tui", ui: { setWidget: () => {} } as any });
472
+ assert.equal((h.widgets.at(-1)!.content as any), undefined);
473
+ h.ctl.sync(h.ctx, board(), 60);
474
+ h.ctl.dispose();
475
+ assert.equal((h.widgets.at(-1)!.content as any), undefined);
476
+ });
477
+ });
478
+
479
+ // helpers used above
480
+ function mark(phases: TodoPhase[], id: string, status: TodoPhase["status"], blockedBy?: string[]): void {
481
+ const hit = phases.find((p) => p.id === id)!;
482
+ hit.status = status;
483
+ if (blockedBy) hit.blockedBy = blockedBy;
484
+ }
485
+
486
+ describe("tool renderResult + config row", () => {
487
+ it("renderResult draws the colored board from details.phases; falls back to the text blob", async () => {
488
+ const h = createPiHarness();
489
+ const tool = h.tools.get("todo");
490
+ const theme = recTheme();
491
+ // A mutation result carries phases in details → themed board.
492
+ await h.call({ action: "init", phases: [{ title: "One" }] });
493
+ const component = tool.renderResult(
494
+ { content: [{ type: "text", text: "board" }], details: { phases: run([], { action: "init", phases: [{ title: "One" }] }) } },
495
+ { expanded: true, isPartial: false },
496
+ theme,
497
+ {} as never,
498
+ );
499
+ assert.match(component.render(120).join("\n"), /<mdLink>☐<\/> <mdLink>One<\/>/);
500
+ // No phases (error path with junk details) → plain text passthrough.
501
+ const fallback = tool.renderResult(
502
+ { content: [{ type: "text", text: "✗ boom" }], details: {} },
503
+ { expanded: true, isPartial: false },
504
+ theme,
505
+ {} as never,
506
+ );
507
+ assert.match(fallback.render(120).join("\n"), /^✗ boom\s*$/);
508
+ });
509
+
510
+ it("the /config row writes todo.lingerSecs through writeTodoSection", async () => {
511
+ const { buildTodoGroups, todoConfig } = await import("../configPanel.ts");
512
+ const working = { value: "300" };
513
+ const groups = buildTodoGroups(working);
514
+ const row0 = groups[0]!.rows[0]!;
515
+ assert.equal(row0.key, "todo.lingerSecs");
516
+ assert.equal(row0.defaultValue, "60");
517
+ // Menu is a closed set incl. Never.
518
+ const menu = (row0 as any).menu();
519
+ assert.deepEqual(menu.map((m: any) => m.value), ["0", "60", "300", "900", "-1"]);
520
+ // set() mutates the working copy; save() persists via writeTodoSection.
521
+ row0.set("900");
522
+ assert.equal(working.value, "900");
523
+ // save() with no owned edited key is a no-op.
524
+ const saved: string[] = [];
525
+ await todoConfig().save(new Set(["other.key"]), { ui: { notify: (m: string) => saved.push(m) } } as never);
526
+ assert.equal(saved.length, 0);
527
+ });
528
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ceulen",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Ceulen — the Pi coding agent, fully dressed: one bundle extension carrying the full toolkit with a single /ceulen config command.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -40,7 +40,7 @@
40
40
  "homepage": "https://github.com/ceulen-dev/ceulen#readme",
41
41
  "bugs": "https://github.com/ceulen-dev/ceulen/issues",
42
42
  "scripts": {
43
- "test": "node scripts/validate-themes.mjs && node --import tsx --test extensions/lib/registry.test.ts extensions/modules/router/test/unit.test.ts extensions/modules/router/test/guard.test.ts extensions/modules/classifier/test/*.test.ts extensions/modules/advisor/test/*.test.ts extensions/modules/usage/test/*.test.ts extensions/modules/ponytail/test/*.test.ts extensions/modules/ux/test/*.test.ts extensions/modules/config/test/*.test.ts extensions/modules/composer/test/*.test.ts extensions/modules/serena/test/*.test.ts extensions/modules/fff/test/*.test.ts extensions/modules/rtk/test/*.test.js extensions/modules/munin/test/*.test.ts extensions/modules/subagent/test/*.test.ts extensions/modules/zai/test/*.test.ts extensions/modules/repair/test/*.test.ts extensions/modules/steering/test/*.test.ts extensions/modules/plan/test/*.test.ts extensions/modules/todo/test/*.test.ts extensions/modules/web/test/*.test.ts extensions/modules/rules/test/*.test.ts",
43
+ "test": "node scripts/validate-themes.mjs && node --import tsx --test extensions/lib/registry.test.ts extensions/modules/router/test/unit.test.ts extensions/modules/router/test/guard.test.ts extensions/modules/classifier/test/*.test.ts extensions/modules/advisor/test/*.test.ts extensions/modules/usage/test/*.test.ts extensions/modules/ponytail/test/*.test.ts extensions/modules/ux/test/*.test.ts extensions/modules/config/test/*.test.ts extensions/modules/composer/test/*.test.ts extensions/modules/serena/test/*.test.ts extensions/modules/fff/test/*.test.ts extensions/modules/rtk/test/*.test.js extensions/modules/munin/test/*.test.ts extensions/modules/subagent/test/*.test.ts extensions/modules/zai/test/*.test.ts extensions/modules/repair/test/*.test.ts extensions/modules/steering/test/*.test.ts extensions/modules/plan/test/*.test.ts extensions/modules/todo/test/*.test.ts extensions/modules/web/test/*.test.ts extensions/modules/rules/test/*.test.ts extensions/modules/a2a/test/*.test.ts",
44
44
  "typecheck": "tsc --noEmit"
45
45
  },
46
46
  "pi": {