@deathbeam/pi-plan 0.0.1 → 0.0.3
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/README.md +2 -3
- package/index.ts +175 -104
- package/package.json +1 -1
- package/skills/import-plan/SKILL.md +14 -12
- package/skills/prepare-plan/SKILL.md +29 -10
- package/src/inspector.ts +222 -53
- package/src/store.ts +123 -60
package/README.md
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
# [@deathbeam/pi-plan](https://www.npmjs.com/package/@deathbeam/pi-plan)
|
|
2
2
|
|
|
3
|
-
Structured plans: a `plan` tool, a progress widget, and a `/plan`
|
|
4
|
-
Each task carries its own `doneWhen` check, and `plan get <id>` returns one task with the plan's goal and context.
|
|
3
|
+
Structured plans: a `plan` tool, a progress widget, and a `/plan` inspector over every plan in the project.
|
|
5
4
|
The bundled `prepare-plan` skill writes a plan, and `import-plan` migrates existing plan documents (`.plans/*.md`, Cursor, Kiro, Taskmaster).
|
|
6
5
|
|
|
7
|
-
Plans live in `.pi/plans/<
|
|
6
|
+
Plans live in `.pi/plans/<id>.json` at the repository root. Add `.pi/plans/` to `.gitignore` if the first `plan create` cannot write it to `.git/info/exclude`.
|
|
8
7
|
|
|
9
8
|
## Installation
|
|
10
9
|
|
package/index.ts
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import { StringEnum } from "@earendil-works/pi-ai";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import {
|
|
3
|
+
getMarkdownTheme,
|
|
4
|
+
type ExtensionAPI,
|
|
5
|
+
type ExtensionContext,
|
|
6
|
+
type KeybindingHints,
|
|
7
|
+
type SessionEntry,
|
|
8
|
+
type Theme,
|
|
8
9
|
} from "@earendil-works/pi-coding-agent";
|
|
9
|
-
import { type Component, Text, truncateToWidth } from "@earendil-works/pi-tui";
|
|
10
|
+
import { Markdown, type Component, Text, truncateToWidth } from "@earendil-works/pi-tui";
|
|
10
11
|
import { Type } from "typebox";
|
|
11
|
-
import { openPlans } from "./src/inspector.ts";
|
|
12
|
+
import { hardBreaks, openPlans } from "./src/inspector.ts";
|
|
12
13
|
import {
|
|
13
14
|
doneCount,
|
|
14
15
|
excludePlans,
|
|
16
|
+
fact,
|
|
17
|
+
hanging,
|
|
15
18
|
listPlans,
|
|
16
19
|
listText,
|
|
17
20
|
moreLines,
|
|
18
|
-
|
|
21
|
+
planStatus,
|
|
19
22
|
planSummary,
|
|
20
23
|
planText,
|
|
21
24
|
plansDir,
|
|
@@ -28,15 +31,13 @@ import {
|
|
|
28
31
|
taskLine,
|
|
29
32
|
taskRow,
|
|
30
33
|
taskText,
|
|
31
|
-
|
|
34
|
+
widgetLines,
|
|
32
35
|
writePlan,
|
|
33
36
|
type Plan,
|
|
34
37
|
type PlanList,
|
|
35
38
|
type PlanStatus,
|
|
36
39
|
} from "./src/store.ts";
|
|
37
40
|
|
|
38
|
-
const ACTIONS = ["create", "update", "get", "list"] as const;
|
|
39
|
-
|
|
40
41
|
type Action = (typeof ACTIONS)[number];
|
|
41
42
|
|
|
42
43
|
type PlanDetails = {
|
|
@@ -52,26 +53,42 @@ type PlanDetails = {
|
|
|
52
53
|
list?: PlanList;
|
|
53
54
|
};
|
|
54
55
|
|
|
56
|
+
const ACTIONS = ["create", "update", "get", "list"] as const;
|
|
57
|
+
const DETAIL_HEADING = /^#{1,3}\s/m;
|
|
58
|
+
|
|
55
59
|
const PlanParams = Type.Object({
|
|
56
60
|
action: StringEnum(ACTIONS),
|
|
57
|
-
|
|
58
|
-
Type.String({ description: "Plan
|
|
61
|
+
plan: Type.Optional(
|
|
62
|
+
Type.String({ description: "Plan id in kebab-case; get and update default to the active plan." }),
|
|
59
63
|
),
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
title: Type.Optional(
|
|
65
|
+
Type.String({
|
|
66
|
+
description: "create: a three to eight word summary of the outcome, shown in the widget and list.",
|
|
67
|
+
}),
|
|
68
|
+
),
|
|
69
|
+
goal: Type.Optional(Type.String({ description: "create: the observable outcome and the check that proves it." })),
|
|
70
|
+
detail: Type.Optional(
|
|
71
|
+
Type.String({
|
|
72
|
+
description:
|
|
73
|
+
"create: markdown sections: current behaviour with path:line, problem, chosen design and rejected alternatives, accepted behaviour changes, out of scope, open questions. Headings inside use #### or lower.",
|
|
74
|
+
}),
|
|
63
75
|
),
|
|
64
76
|
tasks: Type.Optional(
|
|
65
77
|
Type.Array(
|
|
66
78
|
Type.Object({
|
|
67
|
-
title: Type.String({
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
),
|
|
72
|
-
doneWhen: Type.String({
|
|
79
|
+
title: Type.String({
|
|
80
|
+
description: "The deliverable or behaviour in one line; the widget and get show it beside the id.",
|
|
81
|
+
}),
|
|
82
|
+
goal: Type.String({
|
|
73
83
|
description: "Observable result, with the command to run and its expected output.",
|
|
74
84
|
}),
|
|
85
|
+
detail: Type.String({
|
|
86
|
+
description:
|
|
87
|
+
"Approach, interfaces to match, pitfalls, and a Where: line citing path:line. Headings inside use #### or lower.",
|
|
88
|
+
}),
|
|
89
|
+
dependsOn: Type.Optional(
|
|
90
|
+
Type.Array(Type.String(), { description: "Task ids this task waits on, such as t1." }),
|
|
91
|
+
),
|
|
75
92
|
status: Type.Optional(StringEnum(STATUSES, { description: "Defaults to todo." })),
|
|
76
93
|
notes: Type.Optional(
|
|
77
94
|
Type.Array(Type.String(), { description: "Existing notes or log lines for this task." }),
|
|
@@ -80,13 +97,18 @@ const PlanParams = Type.Object({
|
|
|
80
97
|
{ description: "create: tasks in execution order; ids t1..tn follow this order." },
|
|
81
98
|
),
|
|
82
99
|
),
|
|
83
|
-
|
|
100
|
+
task: Type.Optional(
|
|
84
101
|
Type.String({
|
|
85
|
-
description: "update: task id to change. get: this task alone, with the plan's goal and
|
|
102
|
+
description: "update: task id to change. get: this task alone, with the plan's goal and detail.",
|
|
86
103
|
}),
|
|
87
104
|
),
|
|
88
105
|
status: Type.Optional(StringEnum(STATUSES, { description: "update: the task's new state." })),
|
|
89
|
-
note: Type.Optional(
|
|
106
|
+
note: Type.Optional(
|
|
107
|
+
Type.String({
|
|
108
|
+
description:
|
|
109
|
+
"update: a note appended to the task's notes; without task, to the plan's notes (use for cross-task rulings).",
|
|
110
|
+
}),
|
|
111
|
+
),
|
|
90
112
|
});
|
|
91
113
|
|
|
92
114
|
const WIDGET_KEY = "plan";
|
|
@@ -125,15 +147,19 @@ function capLines<T>(lines: readonly T[], max: number): { shown: T[]; hidden: nu
|
|
|
125
147
|
}
|
|
126
148
|
|
|
127
149
|
/** A result view capped to ten rows until the user expands it, then in full. */
|
|
128
|
-
function resultView(
|
|
129
|
-
|
|
150
|
+
function resultView(
|
|
151
|
+
rows: (width: number) => string[],
|
|
152
|
+
theme: Theme,
|
|
153
|
+
expanded: boolean,
|
|
154
|
+
keyHint: KeybindingHints["keyHint"],
|
|
155
|
+
): Component {
|
|
130
156
|
return {
|
|
131
157
|
render: (width) => {
|
|
132
158
|
// Wrapping turns one long line into many rows, so the cap counts rendered rows.
|
|
133
|
-
const { shown, hidden } = capLines(
|
|
159
|
+
const { shown, hidden } = capLines(rows(width), expanded ? Infinity : COLLAPSED_LINES + 1);
|
|
134
160
|
return hidden ? [...shown, truncateToWidth(moreLines(theme, hidden, keyHint), width)] : shown;
|
|
135
161
|
},
|
|
136
|
-
invalidate
|
|
162
|
+
invalidate() {},
|
|
137
163
|
};
|
|
138
164
|
}
|
|
139
165
|
|
|
@@ -148,35 +174,36 @@ function resultText(result: { content: { type: string; text?: string }[] }): str
|
|
|
148
174
|
return result.content.flatMap((part) => (part.type === "text" && part.text ? [part.text] : [])).join("\n");
|
|
149
175
|
}
|
|
150
176
|
|
|
151
|
-
/** The whole plan: a summary line, then one row per task; only the expansion carries goal,
|
|
152
|
-
function planLines(plan: Plan, theme: Theme, expanded: boolean): string[] {
|
|
177
|
+
/** The whole plan: a summary line, then one row per task; only the expansion carries goal, detail and notes. */
|
|
178
|
+
function planLines(plan: Plan, theme: Theme, expanded: boolean, width: number): string[] {
|
|
153
179
|
const tasks = plan.tasks.flatMap((task) =>
|
|
154
|
-
expanded
|
|
180
|
+
expanded
|
|
181
|
+
? [...hanging(taskRow(theme, plan, task), width, task.id.length + 3), ...taskFacts(theme, task, width)]
|
|
182
|
+
: [taskRow(theme, plan, task)],
|
|
155
183
|
);
|
|
156
184
|
return [
|
|
157
185
|
"",
|
|
158
186
|
`${theme.fg("accent", "plan")} ${planSummary(theme, plan)}`,
|
|
159
187
|
...(expanded
|
|
160
|
-
? [
|
|
188
|
+
? [...fact(theme, "Goal: ", plan.goal, width), ...fact(theme, "Detail: ", plan.detail, width, 2, "dim")]
|
|
161
189
|
: []),
|
|
162
190
|
...tasks,
|
|
163
191
|
];
|
|
164
192
|
}
|
|
165
193
|
|
|
166
|
-
/** One task of a plan: its row, then the check and notes that make it a brief. */
|
|
167
|
-
function focusLines(plan: Plan, id: string, theme: Theme): string[] {
|
|
168
|
-
const task = plan.tasks.find((item) => item.id === id);
|
|
169
|
-
return task ? ["", taskRow(theme, plan, task), ...taskFacts(theme, task)] : [];
|
|
170
|
-
}
|
|
171
|
-
|
|
172
194
|
/** What changed: the task row, the note this call appended, and where the plan now stands. */
|
|
173
|
-
function updateLines(
|
|
195
|
+
function updateLines(
|
|
196
|
+
plan: Plan,
|
|
197
|
+
id: string | undefined,
|
|
198
|
+
note: string | undefined,
|
|
199
|
+
theme: Theme,
|
|
200
|
+
width: number,
|
|
201
|
+
): string[] {
|
|
174
202
|
const task = plan.tasks.find((item) => item.id === id);
|
|
175
|
-
if (!task) return [];
|
|
176
203
|
return [
|
|
177
204
|
"",
|
|
178
|
-
taskRow(theme, plan, task),
|
|
179
|
-
...(note ?
|
|
205
|
+
...(task ? hanging(taskRow(theme, plan, task), width, task.id.length + 3) : []),
|
|
206
|
+
...(note ? fact(theme, "", note, width) : []),
|
|
180
207
|
theme.fg("muted", planSummary(theme, plan)),
|
|
181
208
|
];
|
|
182
209
|
}
|
|
@@ -186,7 +213,7 @@ function listLines(list: PlanList, active: string | undefined, theme: Theme): st
|
|
|
186
213
|
return [
|
|
187
214
|
"",
|
|
188
215
|
...list.plans.map(
|
|
189
|
-
(plan) => `${plan.
|
|
216
|
+
(plan) => `${plan.id === active ? theme.fg("accent", "›") : " "} ${planSummary(theme, plan)}`,
|
|
190
217
|
),
|
|
191
218
|
...list.unreadable.map((name) => theme.fg("error", `? ${name} unreadable`)),
|
|
192
219
|
];
|
|
@@ -197,8 +224,8 @@ function callLine(args: Record<string, unknown>, theme: Theme): Component {
|
|
|
197
224
|
const action = argText(args.action);
|
|
198
225
|
const update = action === "update";
|
|
199
226
|
const target = update
|
|
200
|
-
? argText(args.
|
|
201
|
-
: [argText(args.
|
|
227
|
+
? argText(args.task)
|
|
228
|
+
: [argText(args.plan), action === "get" ? argText(args.task) : ""].filter(Boolean).join(" ");
|
|
202
229
|
const status = update ? argStatus(args.status) : undefined;
|
|
203
230
|
const note = update ? argText(args.note) : "";
|
|
204
231
|
const head = `${theme.fg("toolTitle", theme.bold("plan"))} ${theme.fg("accent", [action || "…", target].filter(Boolean).join(" "))}`;
|
|
@@ -211,6 +238,18 @@ function callLine(args: Record<string, unknown>, theme: Theme): Component {
|
|
|
211
238
|
return new Text([head, tail].filter(Boolean).join(" "), 0, 0);
|
|
212
239
|
}
|
|
213
240
|
|
|
241
|
+
/** Strict models send "null" for an omitted string or list; anything else that is empty is a bug. */
|
|
242
|
+
function blank(value: string | undefined): boolean {
|
|
243
|
+
return !value?.trim() || value === "null";
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function taskList(value: unknown, field: string): string[] {
|
|
247
|
+
if (value === undefined || value === null || value === "null") return [];
|
|
248
|
+
if (!Array.isArray(value)) throw new Error(`${field} must be an array.`);
|
|
249
|
+
// pi coerces a bare "null" for an array param into ["null"] before execute runs.
|
|
250
|
+
return value.length === 1 && value[0] === "null" ? [] : (value as string[]);
|
|
251
|
+
}
|
|
252
|
+
|
|
214
253
|
export default function (pi: ExtensionAPI) {
|
|
215
254
|
// The last plan this session created, updated or read; restored from the active branch.
|
|
216
255
|
let active: string | undefined;
|
|
@@ -221,7 +260,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
221
260
|
try {
|
|
222
261
|
plan = active ? readPlan(repoRoot(ctx.cwd), active) : undefined;
|
|
223
262
|
} catch {
|
|
224
|
-
// A restored
|
|
263
|
+
// A restored id or a corrupt file must not break the session; the tool reports the real error.
|
|
225
264
|
plan = undefined;
|
|
226
265
|
}
|
|
227
266
|
if (!plan) {
|
|
@@ -229,7 +268,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
229
268
|
ctx.ui.setWidget(WIDGET_KEY, undefined);
|
|
230
269
|
return;
|
|
231
270
|
}
|
|
232
|
-
|
|
271
|
+
// A finished plan clears the widget, like pi-delegate's finished jobs; new work brings it back.
|
|
272
|
+
ctx.ui.setWidget(WIDGET_KEY, planStatus(plan) === "done" ? undefined : widgetLines(ctx.ui.theme, plan));
|
|
233
273
|
}
|
|
234
274
|
|
|
235
275
|
function restore(ctx: ExtensionContext) {
|
|
@@ -244,22 +284,22 @@ export default function (pi: ExtensionAPI) {
|
|
|
244
284
|
name: "plan",
|
|
245
285
|
label: "Plan",
|
|
246
286
|
description:
|
|
247
|
-
"Read and write the project plan: a
|
|
248
|
-
promptSnippet: "
|
|
287
|
+
"Read and write the project plan: a plan at .pi/plans/<id>.json with a goal, the detail a cold reader needs, and tasks. Actions: create, update, get, list.",
|
|
288
|
+
promptSnippet: "Write the plan for multi-step work in this project: goal, detail, one task per verifiable step",
|
|
249
289
|
promptGuidelines: [
|
|
250
290
|
"Mark a task `doing` when work on it starts.",
|
|
251
291
|
"When another agent works a task, give it the `get` output for that task and update the plan here from its result; a second writer would overwrite plan state.",
|
|
252
|
-
"Mark a task `done` only after its
|
|
292
|
+
"Mark a task `done` only after its goal's check passed, and put the result in the note, for example `npm test -- packages/x: 42 passed`.",
|
|
253
293
|
"Leave a task open when its outcome is unproven: `blocked` with a note of what remains, or `todo`.",
|
|
254
|
-
"Record a
|
|
255
|
-
'When the user refers to a plan by a loose name ("continue the npc draft"), run `list`, then `get` the matching
|
|
294
|
+
"Record a cross-task ruling as a note on the plan: `update` with a note and no task.",
|
|
295
|
+
'When the user refers to a plan by a loose name ("continue the npc draft"), run `list`, then `get` the matching id; that makes it active.',
|
|
256
296
|
],
|
|
257
297
|
parameters: PlanParams,
|
|
258
298
|
|
|
259
299
|
async execute(_toolCallId, rawParams, _signal, _onUpdate, ctx) {
|
|
260
300
|
// Strict models inject literal "null" for optional params they omit; drop it from those only.
|
|
261
301
|
const params = { ...rawParams } as typeof rawParams & Record<string, unknown>;
|
|
262
|
-
for (const key of ["
|
|
302
|
+
for (const key of ["plan", "title", "goal", "detail", "tasks", "task", "status", "note"]) {
|
|
263
303
|
if (params[key] === null || params[key] === "null") delete params[key];
|
|
264
304
|
}
|
|
265
305
|
const root = repoRoot(ctx.cwd);
|
|
@@ -267,66 +307,84 @@ export default function (pi: ExtensionAPI) {
|
|
|
267
307
|
refreshWidget(ctx);
|
|
268
308
|
return { content: [{ type: "text" as const, text }], details: { action, active, ...extra } };
|
|
269
309
|
};
|
|
270
|
-
const
|
|
271
|
-
const
|
|
272
|
-
if (!
|
|
273
|
-
return
|
|
310
|
+
const requireId = () => {
|
|
311
|
+
const id = params.plan ?? active;
|
|
312
|
+
if (!id) throw new Error("No active plan; run list, then pass plan.");
|
|
313
|
+
return id;
|
|
274
314
|
};
|
|
275
315
|
const requirePlan = () => {
|
|
276
|
-
const
|
|
277
|
-
const plan = readPlan(root,
|
|
278
|
-
if (!plan) throw new Error(`No plan ${
|
|
316
|
+
const id = requireId();
|
|
317
|
+
const plan = readPlan(root, id);
|
|
318
|
+
if (!plan) throw new Error(`No plan ${id} in ${plansDir(root)}; run list for the ids.`);
|
|
279
319
|
return plan;
|
|
280
320
|
};
|
|
281
321
|
|
|
282
322
|
switch (params.action as Action) {
|
|
283
323
|
case "create": {
|
|
284
|
-
const {
|
|
285
|
-
if (!
|
|
286
|
-
throw new Error("create needs
|
|
287
|
-
if (
|
|
324
|
+
const { plan: id, title, goal, detail, tasks } = params;
|
|
325
|
+
if (!id || !title || !goal || !detail || !tasks || blank(goal) || blank(detail))
|
|
326
|
+
throw new Error("create needs plan, title, goal, detail and tasks.");
|
|
327
|
+
if (tasks.some((task) => blank(task.goal)))
|
|
328
|
+
throw new Error("Every task needs a goal and the check that proves it.");
|
|
329
|
+
if (tasks.some((task) => blank(task.detail)))
|
|
330
|
+
throw new Error(
|
|
331
|
+
"Every task needs a detail: the approach, the interfaces and a Where: path:line.",
|
|
332
|
+
);
|
|
333
|
+
if (DETAIL_HEADING.test(detail) || tasks.some((task) => DETAIL_HEADING.test(task.detail)))
|
|
334
|
+
throw new Error(
|
|
335
|
+
"Headings inside detail use #### or lower; # to ### belong to the plan layout.",
|
|
336
|
+
);
|
|
337
|
+
if (readPlan(root, id)) throw new Error(`Plan ${id} already exists; use get or update.`);
|
|
288
338
|
const plan: Plan = {
|
|
289
|
-
|
|
339
|
+
id,
|
|
340
|
+
title,
|
|
290
341
|
goal,
|
|
291
|
-
|
|
342
|
+
detail,
|
|
343
|
+
notes: [],
|
|
292
344
|
tasks: tasks.map((task, index) => ({
|
|
293
345
|
id: `t${index + 1}`,
|
|
294
346
|
title: task.title,
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
347
|
+
goal: task.goal,
|
|
348
|
+
detail: task.detail,
|
|
349
|
+
dependsOn: taskList(task.dependsOn, `t${index + 1} dependsOn`),
|
|
298
350
|
status: (task.status ?? "todo") as PlanStatus,
|
|
299
|
-
notes: task.notes
|
|
351
|
+
notes: taskList(task.notes, `t${index + 1} notes`),
|
|
300
352
|
})),
|
|
301
353
|
};
|
|
302
354
|
const ids = new Map(plan.tasks.map((task, index) => [task.id, index]));
|
|
303
355
|
for (const [index, task] of plan.tasks.entries())
|
|
304
|
-
for (const id of task.
|
|
356
|
+
for (const id of task.dependsOn) {
|
|
305
357
|
const target = ids.get(id);
|
|
306
358
|
if (target === undefined)
|
|
307
|
-
throw new Error(`${task.id}
|
|
359
|
+
throw new Error(`${task.id} dependsOn ${id}, a task this plan lacks.`);
|
|
308
360
|
if (target >= index)
|
|
309
|
-
throw new Error(`${task.id}
|
|
361
|
+
throw new Error(`${task.id} dependsOn ${id}; dependsOn takes only earlier ids.`);
|
|
310
362
|
}
|
|
311
363
|
excludePlans(root);
|
|
312
364
|
writePlan(root, plan);
|
|
313
|
-
active = plan.
|
|
365
|
+
active = plan.id;
|
|
314
366
|
return respond(planText(plan), "create", { plan });
|
|
315
367
|
}
|
|
316
368
|
|
|
317
369
|
case "update": {
|
|
318
370
|
const plan = requirePlan();
|
|
319
|
-
if (!params.
|
|
371
|
+
if (!params.task) {
|
|
372
|
+
if (!params.note) throw new Error("update needs task, or a note for the plan.");
|
|
373
|
+
plan.notes.push(params.note);
|
|
374
|
+
writePlan(root, plan);
|
|
375
|
+
active = plan.id;
|
|
376
|
+
const progress = `${plan.id} ${doneCount(plan)}/${plan.tasks.length}`;
|
|
377
|
+
return respond(`note: ${params.note}\n${progress}`, "update", { plan, note: params.note });
|
|
378
|
+
}
|
|
320
379
|
if (!params.status && !params.note) throw new Error("update needs status or note.");
|
|
321
|
-
const task = plan.tasks.find((item) => item.id === params.
|
|
322
|
-
if (!task) throw new Error(`Plan ${plan.
|
|
380
|
+
const task = plan.tasks.find((item) => item.id === params.task);
|
|
381
|
+
if (!task) throw new Error(`Plan ${plan.id} has no task ${params.task}.`);
|
|
323
382
|
if (params.status) task.status = params.status as PlanStatus;
|
|
324
383
|
if (params.note) task.notes.push(params.note);
|
|
325
384
|
writePlan(root, plan);
|
|
326
|
-
active = plan.
|
|
385
|
+
active = plan.id;
|
|
327
386
|
// The model already holds the plan; echo only what changed and where it now stands.
|
|
328
|
-
const
|
|
329
|
-
const progress = `${plan.name} ${doneCount(plan)}/${plan.tasks.length}${next ? ` · next ${next.id}` : ""}`;
|
|
387
|
+
const progress = `${plan.id} ${doneCount(plan)}/${plan.tasks.length}`;
|
|
330
388
|
return respond(`${taskLine(task)}\n${progress}`, "update", {
|
|
331
389
|
plan,
|
|
332
390
|
id: task.id,
|
|
@@ -336,9 +394,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
336
394
|
|
|
337
395
|
case "get": {
|
|
338
396
|
const plan = requirePlan();
|
|
339
|
-
const task = params.
|
|
340
|
-
if (params.
|
|
341
|
-
active = plan.
|
|
397
|
+
const task = params.task ? plan.tasks.find((item) => item.id === params.task) : undefined;
|
|
398
|
+
if (params.task && !task) throw new Error(`Plan ${plan.id} has no task ${params.task}.`);
|
|
399
|
+
active = plan.id;
|
|
342
400
|
return respond(task ? taskText(plan, task) : planText(plan), "get", {
|
|
343
401
|
plan,
|
|
344
402
|
...(task ? { id: task.id } : {}),
|
|
@@ -357,47 +415,60 @@ export default function (pi: ExtensionAPI) {
|
|
|
357
415
|
|
|
358
416
|
renderResult(result, { expanded }, theme, context) {
|
|
359
417
|
const details = context.isError ? undefined : (result.details as PlanDetails | undefined);
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
418
|
+
const plan = details?.plan;
|
|
419
|
+
const list = details?.list;
|
|
420
|
+
const active = details?.active;
|
|
421
|
+
const id = details?.id;
|
|
422
|
+
const note = details?.note;
|
|
423
|
+
let rows: ((width: number) => string[]) | undefined;
|
|
424
|
+
if (list) rows = () => listLines(list, active, theme);
|
|
425
|
+
else if (plan && details?.action === "get") {
|
|
426
|
+
const task = plan.tasks.find((item) => item.id === id);
|
|
427
|
+
const markdown = new Markdown(
|
|
428
|
+
hardBreaks(task ? taskText(plan, task) : planText(plan)),
|
|
429
|
+
0,
|
|
430
|
+
0,
|
|
431
|
+
getMarkdownTheme(),
|
|
432
|
+
);
|
|
433
|
+
rows = (width) => ["", ...markdown.render(Math.max(1, width)).map((line) => line.trimEnd())];
|
|
434
|
+
} else if (plan && details?.action === "update")
|
|
435
|
+
rows = (width) => updateLines(plan, id, note, theme, width);
|
|
436
|
+
else if (plan) rows = (width) => planLines(plan, theme, expanded, width);
|
|
437
|
+
return rows
|
|
438
|
+
? resultView(rows, theme, expanded, context.keyHint)
|
|
368
439
|
: errorView(resultText(result), theme, context.isError);
|
|
369
440
|
},
|
|
370
441
|
});
|
|
371
442
|
|
|
372
443
|
pi.registerCommand("plan", {
|
|
373
|
-
description: "Show every plan and pick the active one; /plan <
|
|
444
|
+
description: "Show every plan and pick the active one; /plan <id> sets it directly",
|
|
374
445
|
handler: async (args, ctx) => {
|
|
375
446
|
const root = repoRoot(ctx.cwd);
|
|
376
|
-
const setActive = (
|
|
377
|
-
active =
|
|
378
|
-
pi.appendEntry(ACTIVE_ENTRY,
|
|
447
|
+
const setActive = (id: string) => {
|
|
448
|
+
active = id;
|
|
449
|
+
pi.appendEntry(ACTIVE_ENTRY, id);
|
|
379
450
|
refreshWidget(ctx);
|
|
380
451
|
};
|
|
381
|
-
const
|
|
382
|
-
if (
|
|
452
|
+
const id = args.trim();
|
|
453
|
+
if (id) {
|
|
383
454
|
let plan: Plan | undefined;
|
|
384
455
|
try {
|
|
385
|
-
plan = readPlan(root,
|
|
456
|
+
plan = readPlan(root, id);
|
|
386
457
|
} catch (error) {
|
|
387
458
|
ctx.ui.notify((error as Error).message, "error");
|
|
388
459
|
return;
|
|
389
460
|
}
|
|
390
461
|
if (!plan) {
|
|
391
|
-
ctx.ui.notify(`No plan ${
|
|
462
|
+
ctx.ui.notify(`No plan ${id} in ${plansDir(root)}.`, "error");
|
|
392
463
|
return;
|
|
393
464
|
}
|
|
394
|
-
setActive(plan.
|
|
395
|
-
ctx.ui.notify(`Active plan: ${plan.
|
|
465
|
+
setActive(plan.id);
|
|
466
|
+
ctx.ui.notify(`Active plan: ${plan.id}`, "info");
|
|
396
467
|
return;
|
|
397
468
|
}
|
|
398
469
|
const list = listPlans(root);
|
|
399
470
|
if (ctx.mode !== "tui") {
|
|
400
|
-
const plan = list.plans.find((item) => item.
|
|
471
|
+
const plan = list.plans.find((item) => item.id === active);
|
|
401
472
|
ctx.ui.notify(plan ? planText(plan) : listText(root, list, active), "info");
|
|
402
473
|
return;
|
|
403
474
|
}
|
package/package.json
CHANGED
|
@@ -21,29 +21,31 @@ Migrate every plan you find in the project. When the request names specific file
|
|
|
21
21
|
|
|
22
22
|
2. **Read a source whole.** Read every task list, checkbox, status field, note and log line before mapping. The mapping below covers the common formats; a format you have not seen gets mapped by the same rules.
|
|
23
23
|
|
|
24
|
-
3. **Skip a taken
|
|
24
|
+
3. **Skip a taken id.** If `.pi/plans/<id>.json` already exists, report the skip and convert the next source.
|
|
25
25
|
|
|
26
26
|
4. **Create one plan per source.** Use the mapping rules, then call `plan create`.
|
|
27
27
|
|
|
28
|
-
5. **Report.** End with one table: source file, new plan
|
|
28
|
+
5. **Report.** End with one table: source file, new plan id, tasks by status, and what you skipped or guessed. Tell the user they can remove the source files once the plan reads correctly. Never edit or delete a source yourself.
|
|
29
29
|
|
|
30
30
|
## Mapping rules
|
|
31
31
|
|
|
32
32
|
Map each field by what it says; its position in the file does not decide.
|
|
33
33
|
|
|
34
|
-
- **
|
|
35
|
-
- **
|
|
36
|
-
- **
|
|
34
|
+
- **Plan id.** The file name without its extension, in kebab-case; the plan title when the file name says nothing.
|
|
35
|
+
- **title.** The plan's title or goal in three to eight words.
|
|
36
|
+
- **goal.** The plan's goal, summary or objective, as one observable outcome plus the check that proves it.
|
|
37
|
+
- **detail.** The plan's context, decisions, constraints, design notes and open questions, in sections. Condense it, but keep every decision and every path.
|
|
38
|
+
- **notes.** A top-level Notes, log or rulings section becomes plan notes. Create the plan first, then append each note with `update` and a `note` but no `task`.
|
|
37
39
|
- **Tasks.** Each top-level actionable item becomes one task.
|
|
38
40
|
- `title`: the item's text.
|
|
39
|
-
- `
|
|
40
|
-
- `
|
|
41
|
-
- `
|
|
41
|
+
- `goal`: its verification, acceptance or test step, with the command when the source names it.
|
|
42
|
+
- `detail`: the item's body, sub-bullets and interfaces, with a `Where:` line citing `path:line` for each path it mentions.
|
|
43
|
+
- `dependsOn`: only the dependencies the source states, mapped to the new ids. List order alone is no dependency.
|
|
42
44
|
- **Status.** A checked or completed item is `done`. An in-progress item, or the next open one the source marks as current, is `doing`. Everything else is `todo`. Take every status from the source.
|
|
43
|
-
- **
|
|
45
|
+
- **Task notes.** Execution notes and log lines go to the notes of the task they belong to.
|
|
44
46
|
|
|
45
|
-
Fold a nested sub-step into its parent task's `
|
|
47
|
+
Fold a nested sub-step into its parent task's `detail` or notes. When a sub-step is independently verifiable, it becomes its own task with `dependsOn` on the parent.
|
|
46
48
|
|
|
47
|
-
When an item has no verification step, set `
|
|
49
|
+
When an item has no verification step, set its `goal` to `unverified: <what to check>`.
|
|
48
50
|
|
|
49
|
-
Task ids follow list order (`t1..tn`); translate stated dependencies after you order the tasks. `update` changes only status and notes, so check titles,
|
|
51
|
+
Task ids follow list order (`t1..tn`); translate stated dependencies after you order the tasks. `update` changes only status and notes, so check titles, goals, details and `dependsOn` before the `create` call.
|
|
@@ -5,32 +5,51 @@ description: Turn a request into a plan of independently verifiable tasks with t
|
|
|
5
5
|
|
|
6
6
|
# Prepare plan
|
|
7
7
|
|
|
8
|
-
Write the plan with the `plan` tool, action `create`. The plan is the source of truth: each task is worked from
|
|
8
|
+
Write the plan with the `plan` tool, action `create`. The plan is the source of truth: each task is worked from `get <task>` and updated when its goal's check passes.
|
|
9
9
|
|
|
10
10
|
## Process
|
|
11
11
|
|
|
12
|
-
1. **Orient.**
|
|
12
|
+
1. **Orient.** Read the code the change touches, its callers, its tests and the repo instructions. Every fact, `path:line` and command in the plan comes from code you or a helper read, not from memory. Stop when you can name the behaviour to change, the seam it goes through, and the check that proves it.
|
|
13
13
|
|
|
14
|
-
2. **
|
|
14
|
+
2. **Gather facts before writing.** When others explore for you, ask each for a report with `path:line` evidence: current behaviour, seams, callers, tests and checks. Write the plan from those reports and the user's decisions. A plan written from conversation memory cites nothing and leaves every task to guesswork.
|
|
15
15
|
|
|
16
|
-
3. **
|
|
16
|
+
3. **Resolve decisions.** Find facts in the code and docs rather than asking. Ask the user only for a decision that changes the plan. Settle a blocking choice before the plan exists and record it in the plan `detail`.
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
4. **Write the plan detail.** Plan `detail` is markdown in sections (headings inside it use `####` or lower, below the fixed `##`):
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
- Current behaviour, with `path:line` for each site.
|
|
21
|
+
- The problem: why that code is wrong today.
|
|
22
|
+
- The chosen design, and the alternatives rejected, with the reason.
|
|
23
|
+
- Accepted behaviour changes.
|
|
24
|
+
- Out of scope.
|
|
25
|
+
- Open questions.
|
|
21
26
|
|
|
22
|
-
5. **
|
|
27
|
+
5. **Write the tasks.** Prefer existing code and the smallest change that meets the goal. Split the work into tasks that are independently verifiable and leave the repo working. For a feature, slice by behaviour rather than by layer: "create with status and notes", not "add schema", then "add handler". For a wide mechanical refactor, plan expand, migrate, contract.
|
|
23
28
|
|
|
24
|
-
|
|
29
|
+
Each task is executed from `get <task>` alone: the plan's goal and detail, and that one task. Write it for a reader who never saw this conversation.
|
|
25
30
|
|
|
26
|
-
|
|
31
|
+
- `title`: the deliverable or behaviour, one line.
|
|
32
|
+
- `goal`: the observable result and the command that proves it.
|
|
33
|
+
- `detail`: the approach, the interfaces it must match, the pitfalls, and a `Where:` line citing `path:line` for each file that changes. Headings inside it use `####` or lower, below the fixed `###`.
|
|
34
|
+
|
|
35
|
+
Add `dependsOn` only for a real dependency; tasks without one run at the same time, so keep their files disjoint.
|
|
36
|
+
|
|
37
|
+
6. **Self-check.** Trace every requirement in the request to a task, and every task to a goal with a check. Replace each "handle edge cases" or "write tests" with the behaviour and the check. Confirm that no task names a path or interface that a later task defines differently. Read each task as `get <task>` will show it and confirm it can be done and checked without this conversation.
|
|
38
|
+
|
|
39
|
+
7. **Create the plan.** One `plan create` call. Set `title` to three to eight words naming the outcome. Task ids follow list order (`t1..tn`), so write `dependsOn` with those ids.
|
|
40
|
+
|
|
41
|
+
## Writing a goal
|
|
42
|
+
|
|
43
|
+
The plan `goal` and a task `goal` mean the same thing: the observable outcome plus the check that proves it, for example:
|
|
27
44
|
|
|
28
45
|
- `npm test -- packages/x: 42 passed`
|
|
29
46
|
- `curl localhost:8080/health returns 200 with {"ok":true}`
|
|
30
47
|
- `open the settings page and press Save: the toast reads Saved`
|
|
31
48
|
|
|
49
|
+
The plan goal is the final verification of the whole plan. Mark a task `done` only after its goal's check passed.
|
|
50
|
+
|
|
32
51
|
For manual or visual work, describe the observation and how to reproduce it. When no check exists yet, write the one to run: `unverified: confirm X with Y`.
|
|
33
52
|
|
|
34
53
|
## Hand off
|
|
35
54
|
|
|
36
|
-
Report the plan
|
|
55
|
+
Report the plan id, the task count and any decision still open. Planning ends here: start the tasks when the user asks for it.
|