@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 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` picker over every plan in the project.
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/<name>.json` at the repository root. Add `.pi/plans/` to `.gitignore` if the first `plan create` cannot write it to `.git/info/exclude`.
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 type {
3
- ExtensionAPI,
4
- ExtensionContext,
5
- KeybindingHints,
6
- SessionEntry,
7
- Theme,
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
- nextTask,
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
- widgetLine,
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
- name: Type.Optional(
58
- Type.String({ description: "Plan name in kebab-case; get and update default to the active 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
- goal: Type.Optional(Type.String({ description: "create: the observable outcome." })),
61
- context: Type.Optional(
62
- Type.String({ description: "create: current behaviour, seams, decisions, constraints, out of scope." }),
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({ description: "Deliverable or behaviour, one line." }),
68
- where: Type.Optional(Type.String({ description: "Files or paths the task touches." })),
69
- blockedBy: Type.Optional(
70
- Type.Array(Type.String(), { description: "Task ids this task waits on, such as t1." }),
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
- id: Type.Optional(
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 context.",
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(Type.String({ description: "update: text appended to the task's notes." })),
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(lines: string[], theme: Theme, expanded: boolean, keyHint: KeybindingHints["keyHint"]): Component {
129
- const body = new Text(lines.join("\n"), 0, 0);
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(body.render(width), expanded ? Infinity : COLLAPSED_LINES + 1);
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: () => body.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, context and notes. */
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 ? [taskRow(theme, plan, task), ...taskFacts(theme, task)] : [taskRow(theme, plan, task)],
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
- ? [` ${theme.fg("dim", `goal: ${plan.goal}`)}`, ` ${theme.fg("dim", `context: ${plan.context}`)}`]
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(plan: Plan, id: string | undefined, note: string | undefined, theme: Theme): string[] {
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 ? [` ${theme.fg("muted", 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.name === active ? theme.fg("accent", "›") : " "} ${planSummary(theme, 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.id)
201
- : [argText(args.name), action === "get" ? argText(args.id) : ""].filter(Boolean).join(" ");
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 name or a corrupt file must not break the session; the tool reports the real error.
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
- ctx.ui.setWidget(WIDGET_KEY, [widgetLine(ctx.ui.theme, plan)]);
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 task list at .pi/plans/<name>.json. Actions: create, update, get, list.",
248
- promptSnippet: "Track multi-step work as a plan in this project, one task per verifiable step",
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 doneWhen check passed, and put that check and its result in the note, for example `npm test -- packages/x: 42 passed`.",
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 scope change as a `Ruling:` note giving the change and the reason.",
255
- 'When the user refers to a plan by a loose name ("continue the npc draft"), run `list`, then `get` the matching name; that makes it active.',
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 ["name", "goal", "context", "tasks", "id", "status", "note"]) {
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 requireName = () => {
271
- const name = params.name ?? active;
272
- if (!name) throw new Error("No active plan; run list, then pass name.");
273
- return name;
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 name = requireName();
277
- const plan = readPlan(root, name);
278
- if (!plan) throw new Error(`No plan ${name} in ${plansDir(root)}; run list for the names.`);
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 { name, goal, context, tasks } = params;
285
- if (!name || !goal || !context || !tasks)
286
- throw new Error("create needs name, goal, context and tasks.");
287
- if (readPlan(root, name)) throw new Error(`Plan ${name} already exists; use get or update.`);
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
- name,
339
+ id,
340
+ title,
290
341
  goal,
291
- context,
342
+ detail,
343
+ notes: [],
292
344
  tasks: tasks.map((task, index) => ({
293
345
  id: `t${index + 1}`,
294
346
  title: task.title,
295
- ...(task.where && task.where !== "null" ? { where: task.where } : {}),
296
- blockedBy: task.blockedBy ?? [],
297
- doneWhen: task.doneWhen,
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.blockedBy) {
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} is blockedBy ${id}, a task this plan lacks.`);
359
+ throw new Error(`${task.id} dependsOn ${id}, a task this plan lacks.`);
308
360
  if (target >= index)
309
- throw new Error(`${task.id} is blockedBy ${id}; blockedBy takes only earlier ids.`);
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.name;
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.id) throw new Error("update needs id.");
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.id);
322
- if (!task) throw new Error(`Plan ${plan.name} has no task ${params.id}.`);
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.name;
385
+ active = plan.id;
327
386
  // The model already holds the plan; echo only what changed and where it now stands.
328
- const next = nextTask(plan);
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.id ? plan.tasks.find((item) => item.id === params.id) : undefined;
340
- if (params.id && !task) throw new Error(`Plan ${plan.name} has no task ${params.id}.`);
341
- active = plan.name;
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
- let lines: string[] = [];
361
- if (details?.list) lines = listLines(details.list, details.active, theme);
362
- else if (details?.plan && details.action === "update")
363
- lines = updateLines(details.plan, details.id, details.note, theme);
364
- else if (details?.plan && details.id) lines = focusLines(details.plan, details.id, theme);
365
- else if (details?.plan) lines = planLines(details.plan, theme, expanded);
366
- return lines.length
367
- ? resultView(lines, theme, expanded, context.keyHint)
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 <name> sets it directly",
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 = (name: string) => {
377
- active = name;
378
- pi.appendEntry(ACTIVE_ENTRY, name);
447
+ const setActive = (id: string) => {
448
+ active = id;
449
+ pi.appendEntry(ACTIVE_ENTRY, id);
379
450
  refreshWidget(ctx);
380
451
  };
381
- const name = args.trim();
382
- if (name) {
452
+ const id = args.trim();
453
+ if (id) {
383
454
  let plan: Plan | undefined;
384
455
  try {
385
- plan = readPlan(root, name);
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 ${name} in ${plansDir(root)}.`, "error");
462
+ ctx.ui.notify(`No plan ${id} in ${plansDir(root)}.`, "error");
392
463
  return;
393
464
  }
394
- setActive(plan.name);
395
- ctx.ui.notify(`Active plan: ${plan.name}`, "info");
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.name === active);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deathbeam/pi-plan",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Structured plans with a progress widget and a full-screen plan picker",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -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 name.** If `.pi/plans/<name>.json` already exists, report the skip and convert the next source.
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 name, 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.
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
- - **Name.** The plan title, or the file name without its extension, in kebab-case.
35
- - **goal.** The plan's goal, summary or objective, as one observable outcome.
36
- - **context.** The plan's context, decisions, constraints, design notes, open questions and general notes. Condense it, but keep every decision and every path.
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
- - `where`: the files and paths it mentions.
40
- - `doneWhen`: its verification, acceptance or test step.
41
- - `blockedBy`: only the dependencies the source states, mapped to the new ids. List order alone is no dependency.
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
- - **Notes.** Execution notes, log lines and rulings go to the notes of the task they belong to.
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 `doneWhen` or notes. When a sub-step is independently verifiable, it becomes its own task with `blockedBy` on the parent.
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 `doneWhen` to `unverified: <what to check>`.
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, `doneWhen` and `blockedBy` before the `create` call.
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 it and updated when its check passes.
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.** Gather the request, repo instructions, the code the change touches, its callers, its tests, and prior patterns. Stop when you can name the behaviour to change, the seam it goes through, and the check that proves it. If the plan exists, report it and continue with `update`; use a new name only for new work.
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. **Resolve decisions.** Find facts in the code and docs rather than asking. Ask the user only for a decision that changes the plan. Record an assumption in `context` instead of leaving a task that a later reader cannot execute. Settle a blocking choice before the plan exists.
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. **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.
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
- Each task is executed from `get <id>` alone: the goal, the context and that one task. Write it for a reader who never saw this conversation: exact paths, the interfaces it must match, and its check. Add `blockedBy` only for a real dependency; tasks without one can run at the same time, so keep their `where` files disjoint.
18
+ 4. **Write the plan detail.** Plan `detail` is markdown in sections (headings inside it use `####` or lower, below the fixed `##`):
19
19
 
20
- 4. **Self-check.** Trace every requirement in the request to a task, and every task to a concrete `doneWhen`. 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 <id>` will show it and confirm it can be done and checked without this conversation.
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. **Create the plan.** One `plan create` call. Task ids follow list order, so write `blockedBy` with those ids.
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
- ## Writing doneWhen
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
- A good check names the result, the command, and the expected output:
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 name, the task count, and any decision still open. Planning ends here: start the tasks when the user asks for it.
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.