ceulen 0.7.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.
- package/CHANGELOG.md +83 -0
- package/extensions/lib/registry.test.ts +67 -0
- package/extensions/lib/registry.ts +24 -7
- package/extensions/modules/a2a/configPanel.ts +435 -0
- package/extensions/modules/a2a/index.ts +1117 -0
- package/extensions/modules/a2a/lib/activity.ts +173 -0
- package/extensions/modules/a2a/lib/client.ts +1061 -0
- package/extensions/modules/a2a/lib/config.ts +920 -0
- package/extensions/modules/a2a/lib/discovery.ts +158 -0
- package/extensions/modules/a2a/lib/gateway.ts +889 -0
- package/extensions/modules/a2a/lib/mdns.ts +233 -0
- package/extensions/modules/a2a/lib/outcome.ts +48 -0
- package/extensions/modules/a2a/lib/persistence.ts +123 -0
- package/extensions/modules/a2a/lib/protocol.ts +506 -0
- package/extensions/modules/a2a/lib/registry.ts +146 -0
- package/extensions/modules/a2a/lib/retry.ts +86 -0
- package/extensions/modules/a2a/lib/security.ts +394 -0
- package/extensions/modules/a2a/lib/server.ts +1436 -0
- package/extensions/modules/a2a/test/activity.test.ts +138 -0
- package/extensions/modules/a2a/test/bridge.test.ts +101 -0
- package/extensions/modules/a2a/test/broadcast-parse.test.ts +31 -0
- package/extensions/modules/a2a/test/chai.ts +101 -0
- package/extensions/modules/a2a/test/client.test.ts +856 -0
- package/extensions/modules/a2a/test/completion-guard.test.ts +73 -0
- package/extensions/modules/a2a/test/config.test.ts +1396 -0
- package/extensions/modules/a2a/test/configPanel.test.ts +393 -0
- package/extensions/modules/a2a/test/discovery.test.ts +144 -0
- package/extensions/modules/a2a/test/extension.test.ts +135 -0
- package/extensions/modules/a2a/test/gateway.test.ts +1449 -0
- package/extensions/modules/a2a/test/helpers.ts +39 -0
- package/extensions/modules/a2a/test/mdns.test.ts +131 -0
- package/extensions/modules/a2a/test/outcome.test.ts +61 -0
- package/extensions/modules/a2a/test/persistence.test.ts +92 -0
- package/extensions/modules/a2a/test/protocol.test.ts +217 -0
- package/extensions/modules/a2a/test/registry.test.ts +114 -0
- package/extensions/modules/a2a/test/retry.test.ts +136 -0
- package/extensions/modules/a2a/test/security.test.ts +281 -0
- package/extensions/modules/a2a/test/server.test.ts +1966 -0
- package/extensions/modules/a2a/test/tmp.ts +59 -0
- package/extensions/modules/a2a/test/vendor.test.ts +57 -0
- package/extensions/modules/a2a/types/bonjour-service.d.ts +22 -0
- package/extensions/modules/a2a/vendor/VENDORED.md +18 -0
- package/extensions/modules/a2a/vendor/package.json +1 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/LICENSE +23 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/index.d.ts +14 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/index.js +57 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/KeyValue.d.ts +4 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/KeyValue.js +3 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/bonjour.d.ts +13 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/bonjour.js +50 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/browser.d.ts +41 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/browser.js +209 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/dns-txt.d.ts +9 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/dns-txt.js +42 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/mdns-server.d.ts +14 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/mdns-server.js +119 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/registry.d.ts +14 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/registry.js +142 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service-types.d.ts +7 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service-types.js +53 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service.d.ts +58 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service.js +130 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/dns-equal.d.ts +1 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/dns-equal.js +13 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/equal-txt.d.ts +1 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/equal-txt.js +17 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-service.d.ts +4 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-service.js +22 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-txt.d.ts +3 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-txt.js +6 -0
- package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/LICENSE +21 -0
- package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/classes.js +23 -0
- package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/index.js +1761 -0
- package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/opcodes.js +50 -0
- package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/optioncodes.js +59 -0
- package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/rcodes.js +50 -0
- package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/types.js +103 -0
- package/extensions/modules/a2a/vendor/vendored_deps/fast-deep-equal/LICENSE +21 -0
- package/extensions/modules/a2a/vendor/vendored_deps/fast-deep-equal/es6.js +73 -0
- package/extensions/modules/a2a/vendor/vendored_deps/fast-deep-equal/index.js +46 -0
- package/extensions/modules/a2a/vendor/vendored_deps/ip-codec/LICENSE +21 -0
- package/extensions/modules/a2a/vendor/vendored_deps/ip-codec/index.cjs +250 -0
- package/extensions/modules/a2a/vendor/vendored_deps/multicast-dns/LICENSE +21 -0
- package/extensions/modules/a2a/vendor/vendored_deps/multicast-dns/index.js +205 -0
- package/extensions/modules/a2a/vendor/vendored_deps/thunky/LICENSE +21 -0
- package/extensions/modules/a2a/vendor/vendored_deps/thunky/index.js +55 -0
- package/extensions/modules/advisor/index.ts +20 -2
- package/extensions/modules/advisor/lib/watcher.ts +3 -1
- package/extensions/modules/advisor/test/module.test.ts +64 -1
- package/extensions/modules/composer/test/module.test.ts +2 -2
- package/extensions/modules/config/index.ts +2 -0
- package/extensions/modules/config/test/renderTools.test.ts +1 -1
- package/extensions/modules/munin/configPanel.ts +5 -2
- package/extensions/modules/munin/test/configPanel.test.ts +27 -2
- package/extensions/modules/router/configPanel.ts +24 -10
- package/extensions/modules/router/lib/client.ts +6 -4
- package/extensions/modules/router/test/unit.test.ts +83 -2
- package/extensions/modules/rules/index.ts +120 -0
- package/extensions/modules/rules/lib/rules.ts +348 -0
- package/extensions/modules/rules/test/lib.test.ts +263 -0
- package/extensions/modules/rules/test/module.test.ts +222 -0
- package/extensions/modules/subagent/index.ts +19 -6
- package/extensions/modules/subagent/lib/routing.ts +11 -6
- package/extensions/modules/subagent/lib/security.ts +12 -1
- package/extensions/modules/subagent/test/routing.test.ts +174 -0
- package/extensions/modules/todo/configPanel.ts +55 -0
- package/extensions/modules/todo/index.ts +511 -0
- package/extensions/modules/todo/lib/render.ts +271 -0
- package/extensions/modules/todo/lib/settings.ts +73 -0
- package/extensions/modules/todo/test/todo.test.ts +528 -0
- package/extensions/modules/usage/index.ts +11 -0
- package/extensions/modules/usage/test/session-accumulators.test.ts +85 -0
- package/extensions/modules/web/configPanel.ts +38 -13
- package/extensions/modules/web/lib/settings.ts +11 -2
- package/extensions/modules/web/test/configPanel.test.ts +67 -1
- package/extensions/modules/zai/configPanel.ts +5 -2
- package/extensions/modules/zai/lib/signing.ts +4 -1
- package/extensions/modules/zai/test/configPanel.test.ts +23 -0
- package/extensions/modules/zai/test/signing.test.ts +19 -0
- package/package.json +2 -2
- package/skills/a2a/SKILL.md +63 -0
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* todo — phased task tracking for ceulen.
|
|
3
|
+
*
|
|
4
|
+
* Ported from OMP's `todo` tool (packages/coding-agent/src/tools/todo.ts +
|
|
5
|
+
* prompts/tools/todo.md): the CONTRACT and state machine, not the code. An
|
|
6
|
+
* ORDERED list of phases (each {id, title, status, blockedBy, notes}) with
|
|
7
|
+
* actions init/start/done/rm/block/unblock/append/view, one in_progress at a
|
|
8
|
+
* time, blockers that never auto-start, and a compact rendered board (never
|
|
9
|
+
* JSON) as the result text.
|
|
10
|
+
*
|
|
11
|
+
* State is branch-scoped via `pi.appendEntry(ceulen-todo, {phases})` on EVERY
|
|
12
|
+
* mutation and rehydrated on session_start from the LAST such entry — the plan
|
|
13
|
+
* module's pattern (appendEntry + resolve-the-last-entry on the branch).
|
|
14
|
+
*
|
|
15
|
+
* Zero prompt rewriting: no before_agent_start handler. The usage contract
|
|
16
|
+
* rides on the tool's own promptGuidelines, so this module never enters the
|
|
17
|
+
* steering load-order contract.
|
|
18
|
+
*
|
|
19
|
+
* DELIBERATE DEVIATIONS from OMP (enumerated, not accidental):
|
|
20
|
+
* - Phase-level only: a phase IS the unit of work (OMP nests {content} tasks
|
|
21
|
+
* under phases). Nothing in the contract needs the second level.
|
|
22
|
+
* - `blockedBy: phaseId[]` replaces OMP's `blocked` status + `blocker` note —
|
|
23
|
+
* blocked is DERIVED from unmet edges, so finishing a blocker unblocks its
|
|
24
|
+
* dependents with no extra call.
|
|
25
|
+
* - start errors when another phase is in_progress (force:true demotes it),
|
|
26
|
+
* OMP's rule hoisted to phase granularity; the auto-advance pointer is kept.
|
|
27
|
+
* - Result text is the rendered board (glyph + [id] + title + counts), not
|
|
28
|
+
* OMP's "Remaining items:" prose. Ids replace OMP's verbatim-content
|
|
29
|
+
* addressing (a 20-char title is not a stable handle).
|
|
30
|
+
* - NOT ported: the `drop`/abandoned status, the Markdown round-trip
|
|
31
|
+
* (TODO.md read/write), op inference + lenientArgValidation repair, the HUD
|
|
32
|
+
* visibility state, the flat `items` init shape, and /todo edit.
|
|
33
|
+
* - Persistence is ONE `ceulen-todo` entry per mutation on the branch;
|
|
34
|
+
* OMP's canonical snapshot also rides toolResult details + a HUD entry.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
import type {
|
|
38
|
+
ExtensionAPI,
|
|
39
|
+
ExtensionContext,
|
|
40
|
+
ToolDefinition,
|
|
41
|
+
} from "@earendil-works/pi-coding-agent";
|
|
42
|
+
import { Text } from "@earendil-works/pi-tui";
|
|
43
|
+
import { Type, type Static } from "typebox";
|
|
44
|
+
import {
|
|
45
|
+
createTodoWidgetController,
|
|
46
|
+
renderTodoBoard,
|
|
47
|
+
type WidgetTheme,
|
|
48
|
+
} from "./lib/render.ts";
|
|
49
|
+
import { readLingerSecs } from "./lib/settings.ts";
|
|
50
|
+
import { readDisabledTools } from "../../lib/tools.js";
|
|
51
|
+
|
|
52
|
+
export const TODO_TOOL = "todo";
|
|
53
|
+
export const TODO_ENTRY_TYPE = "ceulen-todo";
|
|
54
|
+
export const TODO_STATUS_KEY = "ceulen-todo";
|
|
55
|
+
export const TODO_WIDGET_KEY = "ceulen-todo";
|
|
56
|
+
|
|
57
|
+
export type TodoStatus = "pending" | "in_progress" | "done" | "blocked";
|
|
58
|
+
|
|
59
|
+
export interface TodoPhase {
|
|
60
|
+
/** Stable handle for the list's lifetime (auto-assigned when omitted). */
|
|
61
|
+
id: string;
|
|
62
|
+
title: string;
|
|
63
|
+
status: TodoStatus;
|
|
64
|
+
/** Phase ids this phase waits on — non-empty means BLOCKED (never auto-starts). */
|
|
65
|
+
blockedBy: string[];
|
|
66
|
+
/** Free-form detail. */
|
|
67
|
+
notes?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** ponytail: free-text task items are NOT ported — a phase IS the unit of
|
|
71
|
+
* work (OMP nests tasks under phases; nothing in the port's contract needs
|
|
72
|
+
* the second level). Add a nested list only if a real plan needs it. */
|
|
73
|
+
|
|
74
|
+
const STATUSES: readonly TodoStatus[] = ["pending", "in_progress", "done", "blocked"];
|
|
75
|
+
|
|
76
|
+
const todoSchema = Type.Object({
|
|
77
|
+
action: Type.Union(
|
|
78
|
+
[
|
|
79
|
+
Type.Literal("init"),
|
|
80
|
+
Type.Literal("start"),
|
|
81
|
+
Type.Literal("done"),
|
|
82
|
+
Type.Literal("rm"),
|
|
83
|
+
Type.Literal("block"),
|
|
84
|
+
Type.Literal("unblock"),
|
|
85
|
+
Type.Literal("append"),
|
|
86
|
+
Type.Literal("view"),
|
|
87
|
+
],
|
|
88
|
+
{
|
|
89
|
+
description:
|
|
90
|
+
"init replaces the whole list · start/done mark a phase · block/unblock edit blockedBy · append adds a phase · rm removes one (or all) · view renders without mutating.",
|
|
91
|
+
},
|
|
92
|
+
),
|
|
93
|
+
phases: Type.Optional(
|
|
94
|
+
Type.Array(
|
|
95
|
+
Type.Object({
|
|
96
|
+
id: Type.Optional(Type.String({ description: "Stable handle; auto-assigned as p1, p2, … when omitted." })),
|
|
97
|
+
title: Type.String({ description: "Short imperative phase title." }),
|
|
98
|
+
status: Type.Optional(
|
|
99
|
+
Type.Union(STATUSES.map((s) => Type.Literal(s)), { description: "Defaults to pending." }),
|
|
100
|
+
),
|
|
101
|
+
blockedBy: Type.Optional(
|
|
102
|
+
Type.Array(Type.String(), { description: "Phase ids this phase waits on." }),
|
|
103
|
+
),
|
|
104
|
+
notes: Type.Optional(Type.String()),
|
|
105
|
+
}),
|
|
106
|
+
{ description: "init: the ordered phase list (replaces everything). append: exactly one phase." },
|
|
107
|
+
),
|
|
108
|
+
),
|
|
109
|
+
id: Type.Optional(Type.String({ description: "Target phase id (start/done/rm/block/unblock)." })),
|
|
110
|
+
blockedBy: Type.Optional(
|
|
111
|
+
Type.Array(Type.String(), {
|
|
112
|
+
description: "block: the phase ids standing in the way (required). unblock: edge(s) to drop; omit to clear them all.",
|
|
113
|
+
}),
|
|
114
|
+
),
|
|
115
|
+
force: Type.Optional(
|
|
116
|
+
Type.Boolean({ description: "start: demote the other in_progress phase instead of erroring. Default false." }),
|
|
117
|
+
),
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
type TodoParams = Static<typeof todoSchema>;
|
|
121
|
+
|
|
122
|
+
const GLYPH: Record<TodoStatus, string> = { pending: "○", in_progress: "▸", done: "✓", blocked: "!" };
|
|
123
|
+
|
|
124
|
+
function clonePhases(phases: readonly TodoPhase[]): TodoPhase[] {
|
|
125
|
+
return phases.map((p) => ({ ...p, blockedBy: [...p.blockedBy] }));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** A phase is BLOCKED when it has unmet blockers — derived, never stored. */
|
|
129
|
+
export function isBlocked(phase: TodoPhase, phases: readonly TodoPhase[]): boolean {
|
|
130
|
+
const byId = new Map(phases.map((p) => [p.id, p]));
|
|
131
|
+
return phase.blockedBy.some((dep) => {
|
|
132
|
+
const depPhase = byId.get(dep);
|
|
133
|
+
return depPhase !== undefined && depPhase.status !== "done";
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function effectiveStatus(phase: TodoPhase, phases: readonly TodoPhase[]): TodoStatus {
|
|
138
|
+
return isBlocked(phase, phases) ? "blocked" : phase.status;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Next actionable phase: first running one, else the first pending unblocked phase. */
|
|
142
|
+
function nextActionable(phases: readonly TodoPhase[]): TodoPhase | undefined {
|
|
143
|
+
const byId = new Map(phases.map((p) => [p.id, p]));
|
|
144
|
+
return (
|
|
145
|
+
phases.find((p) => p.status === "in_progress" && !isBlocked(p, phases)) ??
|
|
146
|
+
phases.find((p) => p.status === "pending" && !isBlocked(p, phases))
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function counts(phases: readonly TodoPhase[]): { done: number; total: number } {
|
|
151
|
+
return { done: phases.filter((p) => p.status === "done").length, total: phases.length };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** The footer indicator text; undefined when the list is empty or all done. */
|
|
155
|
+
export function statusLine(phases: readonly TodoPhase[]): string | undefined {
|
|
156
|
+
const { done, total } = counts(phases);
|
|
157
|
+
if (total === 0 || done === total) return undefined;
|
|
158
|
+
const active = phases.find((p) => p.status === "in_progress" && !isBlocked(p, phases));
|
|
159
|
+
const blocked = phases.filter((p) => p.status !== "done" && isBlocked(p, phases)).length;
|
|
160
|
+
return [
|
|
161
|
+
`▸ ${done}/${total} done`,
|
|
162
|
+
active ? `in_progress: ${active.title}` : "next: " + (nextActionable(phases)?.title ?? "—"),
|
|
163
|
+
blocked > 0 ? `${blocked} blocked` : undefined,
|
|
164
|
+
]
|
|
165
|
+
.filter(Boolean)
|
|
166
|
+
.join(" · ");
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** The compact rendered board (never JSON). */
|
|
170
|
+
function renderBoard(phases: readonly TodoPhase[], note?: string): string {
|
|
171
|
+
const head = note ? `${note}\n` : "";
|
|
172
|
+
if (phases.length === 0) return `${head}Todo list is empty.`;
|
|
173
|
+
const byId = new Map(phases.map((p) => [p.id, p]));
|
|
174
|
+
const { done, total } = counts(phases);
|
|
175
|
+
const lines = phases.map((p, i) => {
|
|
176
|
+
const st = effectiveStatus(p, phases);
|
|
177
|
+
const waiters = p.blockedBy.filter((dep) => byId.get(dep)?.status !== "done");
|
|
178
|
+
const tail = [
|
|
179
|
+
st === "blocked" && waiters.length > 0 ? `blocked by ${waiters.join(", ")}` : undefined,
|
|
180
|
+
p.notes,
|
|
181
|
+
]
|
|
182
|
+
.filter(Boolean)
|
|
183
|
+
.join(" — ");
|
|
184
|
+
return `${i + 1}. ${GLYPH[st]} [${p.id}] ${p.title}${tail ? ` (${tail})` : ""}`;
|
|
185
|
+
});
|
|
186
|
+
return `${head}${lines.join("\n")}\n▸ ${done}/${total} done`;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** The batch contract, restated on every MUTATING result (OMP: never call todo alone). */
|
|
190
|
+
const BATCH_REMINDER = "(batch todo calls with real work; never call todo alone)";
|
|
191
|
+
|
|
192
|
+
function autoId(index: number, taken: Set<string>): string {
|
|
193
|
+
let n = index + 1;
|
|
194
|
+
while (taken.has(`p${n}`)) n += 1;
|
|
195
|
+
return `p${n}`;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
interface ApplyResult {
|
|
199
|
+
phases: TodoPhase[];
|
|
200
|
+
errors: string[];
|
|
201
|
+
changed: boolean;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Apply one action to a copy of the list. ALL errors leave the input
|
|
206
|
+
* untouched (the caller discards the partial copy) — the state and the
|
|
207
|
+
* rendered board stay at the previous value and the model retries.
|
|
208
|
+
*/
|
|
209
|
+
export function applyTodo(current: readonly TodoPhase[], params: TodoParams): ApplyResult {
|
|
210
|
+
const phases = clonePhases(current);
|
|
211
|
+
const errors: string[] = [];
|
|
212
|
+
const fail = (message: string): ApplyResult => ({ phases, errors: [...errors, message], changed: false });
|
|
213
|
+
const byId = new Map(phases.map((p) => [p.id, p]));
|
|
214
|
+
const target = (): TodoPhase | undefined => {
|
|
215
|
+
if (!params.id) {
|
|
216
|
+
errors.push(`Missing phase id — pass the [id] shown in the board`);
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
const hit = byId.get(params.id);
|
|
220
|
+
if (!hit) errors.push(`Phase "${params.id}" not found`);
|
|
221
|
+
return hit;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
switch (params.action) {
|
|
225
|
+
case "view":
|
|
226
|
+
return { phases, errors, changed: false };
|
|
227
|
+
|
|
228
|
+
case "init": {
|
|
229
|
+
const list = params.phases;
|
|
230
|
+
if (!list || list.length === 0) return fail("init needs a non-empty phases list");
|
|
231
|
+
const taken = new Set<string>();
|
|
232
|
+
const seenTitle = new Set<string>();
|
|
233
|
+
const next: TodoPhase[] = [];
|
|
234
|
+
for (const [i, p] of list.entries()) {
|
|
235
|
+
const title = p.title.trim();
|
|
236
|
+
if (!title) return fail("Every phase needs a title");
|
|
237
|
+
if (seenTitle.has(title)) return fail(`Duplicate phase title "${title}"`);
|
|
238
|
+
seenTitle.add(title);
|
|
239
|
+
const id = p.id?.trim() || autoId(i, taken);
|
|
240
|
+
if (taken.has(id)) return fail(`Duplicate phase id "${id}"`);
|
|
241
|
+
taken.add(id);
|
|
242
|
+
next.push({
|
|
243
|
+
id,
|
|
244
|
+
title,
|
|
245
|
+
status: p.status ?? "pending",
|
|
246
|
+
blockedBy: [...new Set(p.blockedBy ?? [])],
|
|
247
|
+
...(p.notes ? { notes: p.notes } : {}),
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
return finish(next, errors);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
case "append": {
|
|
254
|
+
const list = params.phases;
|
|
255
|
+
if (!list || list.length !== 1) return fail("append needs exactly one phase in `phases`");
|
|
256
|
+
const p = list[0];
|
|
257
|
+
const title = p.title.trim();
|
|
258
|
+
if (!title) return fail("Every phase needs a title");
|
|
259
|
+
if (phases.some((x) => x.title === title)) return fail(`Phase "${title}" already exists`);
|
|
260
|
+
const id = p.id?.trim() || autoId(phases.length, new Set(phases.map((x) => x.id)));
|
|
261
|
+
if (byId.has(id)) return fail(`Phase id "${id}" already exists`);
|
|
262
|
+
phases.push({
|
|
263
|
+
id,
|
|
264
|
+
title,
|
|
265
|
+
status: p.status ?? "pending",
|
|
266
|
+
blockedBy: [...new Set(p.blockedBy ?? [])],
|
|
267
|
+
...(p.notes ? { notes: p.notes } : {}),
|
|
268
|
+
});
|
|
269
|
+
return finish(phases, errors);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
case "start": {
|
|
273
|
+
const hit = target();
|
|
274
|
+
if (!hit) return { phases, errors, changed: false };
|
|
275
|
+
const other = phases.find((p) => p.status === "in_progress" && p !== hit);
|
|
276
|
+
if (other && !params.force) {
|
|
277
|
+
return fail(
|
|
278
|
+
`"${other.title}" [${other.id}] is already in_progress — finish it with done (or pass force:true to demote it)`,
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
if (other) other.status = "pending";
|
|
282
|
+
hit.status = "in_progress";
|
|
283
|
+
return finish(phases, errors);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
case "done": {
|
|
287
|
+
const hit = target();
|
|
288
|
+
if (!hit) return { phases, errors, changed: false };
|
|
289
|
+
hit.status = "done";
|
|
290
|
+
return finish(phases, errors);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
case "rm": {
|
|
294
|
+
if (!params.id) {
|
|
295
|
+
if (phases.length === 0) return fail("The todo list is already empty");
|
|
296
|
+
return finish([], errors);
|
|
297
|
+
}
|
|
298
|
+
const hit = target();
|
|
299
|
+
if (!hit) return { phases, errors, changed: false };
|
|
300
|
+
const next = phases.filter((p) => p !== hit);
|
|
301
|
+
// A removed phase must not linger as a dangling blocker elsewhere.
|
|
302
|
+
for (const p of next) p.blockedBy = p.blockedBy.filter((dep) => dep !== hit.id);
|
|
303
|
+
return finish(next, errors);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
case "block": {
|
|
307
|
+
const hit = target();
|
|
308
|
+
if (!hit) return { phases, errors, changed: false };
|
|
309
|
+
const deps = [...new Set(params.blockedBy ?? [])];
|
|
310
|
+
if (deps.length === 0) return fail("block needs blockedBy — the phase id(s) standing in the way");
|
|
311
|
+
for (const dep of deps) {
|
|
312
|
+
if (dep === hit.id) return fail(`"${hit.title}" cannot block itself`);
|
|
313
|
+
if (!byId.has(dep)) return fail(`blockedBy "${dep}" is not a phase in this list`);
|
|
314
|
+
}
|
|
315
|
+
hit.blockedBy = [...new Set([...hit.blockedBy, ...deps])];
|
|
316
|
+
return finish(phases, errors);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
case "unblock": {
|
|
320
|
+
const hit = target();
|
|
321
|
+
if (!hit) return { phases, errors, changed: false };
|
|
322
|
+
const deps = params.blockedBy ?? [];
|
|
323
|
+
hit.blockedBy = deps.length === 0 ? [] : hit.blockedBy.filter((dep) => !deps.includes(dep));
|
|
324
|
+
return finish(phases, errors);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return { phases, errors: ["Unknown action"], changed: false };
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Validate blocker edges once the whole list is known, then normalize the
|
|
332
|
+
* pointer: no in_progress phase means the earliest PENDING, UNBLOCKED one
|
|
333
|
+
* becomes active (phase order, OMP's rule). Blocked phases never auto-start,
|
|
334
|
+
* and an out-of-order pointer never reopens a finished phase.
|
|
335
|
+
*/
|
|
336
|
+
function finish(phases: TodoPhase[], priorErrors: string[]): ApplyResult {
|
|
337
|
+
const errors = [...priorErrors];
|
|
338
|
+
const ids = new Set(phases.map((p) => p.id));
|
|
339
|
+
for (const p of phases) {
|
|
340
|
+
for (const dep of p.blockedBy) {
|
|
341
|
+
if (dep === p.id) errors.push(`"${p.title}" cannot block itself`);
|
|
342
|
+
else if (!ids.has(dep)) errors.push(`"${p.title}" is blocked by unknown phase "${dep}"`);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (errors.length > 0) return { phases, errors, changed: false };
|
|
346
|
+
if (!phases.some((p) => p.status === "in_progress")) {
|
|
347
|
+
const next = nextActionable(phases);
|
|
348
|
+
if (next) next.status = "in_progress";
|
|
349
|
+
}
|
|
350
|
+
return { phases, errors, changed: true };
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export default function todoModule(pi: ExtensionAPI): void {
|
|
354
|
+
let phases: TodoPhase[] = [];
|
|
355
|
+
/** Last live ctx — the status item is set through it on every mutation. */
|
|
356
|
+
let liveUi: ExtensionContext["ui"] | undefined;
|
|
357
|
+
/** Above-editor HUD (colored board + all-done linger). */
|
|
358
|
+
const widget = createTodoWidgetController();
|
|
359
|
+
|
|
360
|
+
const syncWidget = (ctx?: { mode?: string; ui: ExtensionContext["ui"] }): void => {
|
|
361
|
+
// getPhases: the render closure reads LIVE state — a captured array would
|
|
362
|
+
// freeze the HUD at the install-time snapshot (caught live in a herdr pane).
|
|
363
|
+
widget.sync(ctx, phases, readLingerSecs(), () => phases);
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
const syncStatus = (ui: ExtensionContext["ui"] | undefined = liveUi): void => {
|
|
367
|
+
if (!ui) return;
|
|
368
|
+
try {
|
|
369
|
+
ui.setStatus(TODO_STATUS_KEY, statusLine(phases));
|
|
370
|
+
} catch {
|
|
371
|
+
/* stale ctx after session replacement — the next session_start re-syncs */
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
const commit = (next: TodoPhase[], ctx?: { mode?: string; ui: ExtensionContext["ui"] }): void => {
|
|
376
|
+
phases = next;
|
|
377
|
+
pi.appendEntry(TODO_ENTRY_TYPE, { phases });
|
|
378
|
+
syncStatus(ctx?.ui);
|
|
379
|
+
syncWidget(ctx);
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
const tool: ToolDefinition<typeof todoSchema, { phases: TodoPhase[] }> = {
|
|
383
|
+
name: TODO_TOOL,
|
|
384
|
+
label: "Todo",
|
|
385
|
+
description:
|
|
386
|
+
"Track a phased task list for this session: init (replace the whole list) · start/done/rm · block/unblock (blockedBy edges) · append · view. The result is the rendered board; phases are referenced by their [id].",
|
|
387
|
+
promptSnippet: "Track a phased task list for this session (init/start/done/block/unblock/append/view)",
|
|
388
|
+
// OMP's usage contract (prompts/tools/todo.md), verbatim in intent.
|
|
389
|
+
promptGuidelines: [
|
|
390
|
+
"Batch todo calls with real work: init alongside the FIRST work call, done in the SAME call that starts the next action, and NEVER call todo alone.",
|
|
391
|
+
"Before work, init for 3+ steps, a requested task set, or new instructions. List EVERY user item separately (phased/numbered/bulleted) — never omit or leave leftovers to memory.",
|
|
392
|
+
"After a successful mutation the earliest pending, unblocked phase auto-starts (marked in_progress); starting one while another is in_progress errors unless force:true.",
|
|
393
|
+
"Blocked phases NEVER start automatically (unblock returns them to pending); mark done immediately and in phase order — out-of-order done never reopens a finished phase.",
|
|
394
|
+
"External waits (user, another agent, a service): block with the blocker ids, which suppresses the stop reminder; unblock when actionable, and append a clearing phase when the blocker is agent-actionable.",
|
|
395
|
+
"Phase ids are stable for the list's lifetime; when the board loses text, view it — never guess.",
|
|
396
|
+
],
|
|
397
|
+
defaultActive: !readDisabledTools().has(TODO_TOOL),
|
|
398
|
+
parameters: todoSchema,
|
|
399
|
+
// TUI-only: the colored board (status colors, strikethrough on done).
|
|
400
|
+
// The LLM-facing text content stays the plain board — this only swaps
|
|
401
|
+
// what the transcript draws. No phases in details → the plain text blob.
|
|
402
|
+
renderResult(result, _options, theme) {
|
|
403
|
+
const detail = result.details as { phases?: TodoPhase[] } | undefined;
|
|
404
|
+
const boardPhases = Array.isArray(detail?.phases) && detail!.phases!.every(isTodoPhase) ? detail!.phases! : [];
|
|
405
|
+
if (boardPhases.length === 0) {
|
|
406
|
+
const text = result.content[0];
|
|
407
|
+
return new Text(text?.type === "text" ? text.text : "", 0, 0);
|
|
408
|
+
}
|
|
409
|
+
return new Text(renderTodoBoard(boardPhases, theme as unknown as WidgetTheme).join("\n"), 0, 0);
|
|
410
|
+
},
|
|
411
|
+
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
412
|
+
const ui = ctx.ui;
|
|
413
|
+
liveUi = ui;
|
|
414
|
+
const result = applyTodo(phases, params);
|
|
415
|
+
const failed = result.errors.length > 0;
|
|
416
|
+
if (!failed && result.changed) commit(result.phases, ctx);
|
|
417
|
+
const effective = failed ? phases : result.phases;
|
|
418
|
+
// Mutations restate the batch contract; a pure view stays quiet.
|
|
419
|
+
const tail = failed
|
|
420
|
+
? `\n✗ ${result.errors.join("; ")}`
|
|
421
|
+
: params.action === "view"
|
|
422
|
+
? ""
|
|
423
|
+
: `\n${BATCH_REMINDER}`;
|
|
424
|
+
return {
|
|
425
|
+
content: [{ type: "text", text: renderBoard(effective, tail) }],
|
|
426
|
+
details: { phases: effective },
|
|
427
|
+
isError: failed ? true : undefined,
|
|
428
|
+
};
|
|
429
|
+
},
|
|
430
|
+
};
|
|
431
|
+
pi.registerTool(tool);
|
|
432
|
+
|
|
433
|
+
pi.registerCommand("todo", {
|
|
434
|
+
description: "Show the phased todo board, or /todo clear to reset it",
|
|
435
|
+
getArgumentCompletions: (prefix) => {
|
|
436
|
+
const q = String(prefix || "").trim().toLowerCase();
|
|
437
|
+
const items = ["clear"].filter((k) => k.startsWith(q)).map((k) => ({ value: k, label: k }));
|
|
438
|
+
return items.length > 0 ? items : null;
|
|
439
|
+
},
|
|
440
|
+
handler: async (args, ctx) => {
|
|
441
|
+
const sub = args.trim().toLowerCase();
|
|
442
|
+
if (sub === "clear") {
|
|
443
|
+
if (phases.length === 0) {
|
|
444
|
+
ctx.ui.notify("Todo list is already empty.", "info");
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
commit([], ctx);
|
|
448
|
+
ctx.ui.notify("Todo list cleared.", "info");
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
if (sub) {
|
|
452
|
+
ctx.ui.notify(`Unknown subcommand: ${sub}. Use /todo (board) or /todo clear.`, "warning");
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
ctx.ui.notify(renderBoard(phases), "info");
|
|
456
|
+
},
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
/** Rehydrate the LAST persisted entry, then label it. */
|
|
460
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
461
|
+
liveUi = ctx.ui;
|
|
462
|
+
const entries: unknown[] =
|
|
463
|
+
(typeof ctx.sessionManager?.getBranch === "function" ? ctx.sessionManager.getBranch() : undefined) ??
|
|
464
|
+
(typeof ctx.sessionManager?.getEntries === "function" ? ctx.sessionManager.getEntries() : undefined) ??
|
|
465
|
+
[];
|
|
466
|
+
phases = resolveTodoPhases(entries);
|
|
467
|
+
syncStatus(ctx.ui);
|
|
468
|
+
// A resumed session with open work shows the HUD again; an all-done
|
|
469
|
+
// snapshot from a previous session stays hidden (no re-linger).
|
|
470
|
+
syncWidget(ctx);
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
// The indicator must not leak past this runtime (subagent-precedent: the
|
|
474
|
+
// widget controller owns set + clear on session change).
|
|
475
|
+
pi.on("session_shutdown", () => {
|
|
476
|
+
widget.dispose();
|
|
477
|
+
try {
|
|
478
|
+
liveUi?.setStatus(TODO_STATUS_KEY, undefined);
|
|
479
|
+
} catch {
|
|
480
|
+
/* dead runtime */
|
|
481
|
+
}
|
|
482
|
+
liveUi = undefined;
|
|
483
|
+
phases = [];
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/** Read the last `ceulen-todo` entry on a branch. Exported for tests. */
|
|
488
|
+
export function resolveTodoPhases(entries: unknown): TodoPhase[] {
|
|
489
|
+
if (!Array.isArray(entries)) return [];
|
|
490
|
+
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
491
|
+
const entry = entries[i] as { type?: string; customType?: string; data?: { phases?: unknown } } | undefined;
|
|
492
|
+
if (entry?.type !== "custom" || entry?.customType !== TODO_ENTRY_TYPE) continue;
|
|
493
|
+
const raw = entry.data?.phases;
|
|
494
|
+
if (!Array.isArray(raw)) continue; // malformed entry — fall back to the previous one
|
|
495
|
+
return raw.filter(isTodoPhase).map((p) => ({ ...p }));
|
|
496
|
+
}
|
|
497
|
+
return [];
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
export function isTodoPhase(value: unknown): value is TodoPhase {
|
|
501
|
+
if (typeof value !== "object" || value === null) return false;
|
|
502
|
+
const p = value as Partial<TodoPhase>;
|
|
503
|
+
return (
|
|
504
|
+
typeof p.id === "string" &&
|
|
505
|
+
typeof p.title === "string" &&
|
|
506
|
+
typeof p.status === "string" &&
|
|
507
|
+
(STATUSES as readonly string[]).includes(p.status) &&
|
|
508
|
+
Array.isArray(p.blockedBy) &&
|
|
509
|
+
p.blockedBy.every((d) => typeof d === "string")
|
|
510
|
+
);
|
|
511
|
+
}
|