@deathbeam/pi-plan 0.0.5 → 0.0.7
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 -2
- package/index.ts +261 -398
- package/package.json +2 -2
- package/skills/import-plan/SKILL.md +8 -8
- package/skills/prepare-plan/SKILL.md +13 -15
- package/src/format.ts +269 -0
- package/src/inspector.ts +19 -86
- package/src/store.ts +34 -74
package/src/store.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
appendFileSync,
|
|
4
|
+
existsSync,
|
|
5
|
+
mkdirSync,
|
|
6
|
+
readFileSync,
|
|
7
|
+
readdirSync,
|
|
8
|
+
renameSync,
|
|
9
|
+
statSync,
|
|
10
|
+
writeFileSync,
|
|
11
|
+
} from "node:fs";
|
|
3
12
|
import { dirname, join, resolve } from "node:path";
|
|
4
|
-
import type { KeybindingHints, Theme, ThemeColor } from "@earendil-works/pi-coding-agent";
|
|
5
|
-
import { wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
6
13
|
|
|
7
14
|
export type PlanStatus = (typeof STATUSES)[number];
|
|
8
15
|
|
|
@@ -30,16 +37,9 @@ export type PlanList = {
|
|
|
30
37
|
unreadable: string[];
|
|
31
38
|
};
|
|
32
39
|
|
|
33
|
-
/** One status vocabulary for the
|
|
40
|
+
/** One status vocabulary for the tool results and the /plan overlay. */
|
|
34
41
|
export const STATUSES = ["todo", "doing", "done", "blocked"] as const;
|
|
35
42
|
|
|
36
|
-
export const STATUS = {
|
|
37
|
-
todo: { glyph: "○", color: "muted" },
|
|
38
|
-
doing: { glyph: "◐", color: "warning" },
|
|
39
|
-
done: { glyph: "✓", color: "success" },
|
|
40
|
-
blocked: { glyph: "✗", color: "error" },
|
|
41
|
-
} as const satisfies Record<PlanStatus, { glyph: string; color: string }>;
|
|
42
|
-
|
|
43
43
|
const ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
44
44
|
const PLANS_IGNORE = ".pi/plans/";
|
|
45
45
|
|
|
@@ -122,9 +122,20 @@ export function listPlans(root: string): PlanList {
|
|
|
122
122
|
if ((error as NodeJS.ErrnoException).code === "ENOENT") return { plans: [], unreadable: [] };
|
|
123
123
|
throw error;
|
|
124
124
|
}
|
|
125
|
+
// Newest write first: the plan being worked on outranks an abandoned one.
|
|
126
|
+
const newest = files
|
|
127
|
+
.filter((name) => name.endsWith(".json"))
|
|
128
|
+
.flatMap((file) => {
|
|
129
|
+
try {
|
|
130
|
+
return [{ file, mtime: statSync(join(plansDir(root), file)).mtimeMs }];
|
|
131
|
+
} catch {
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
.sort((a, b) => b.mtime - a.mtime || a.file.localeCompare(b.file));
|
|
125
136
|
const plans: Plan[] = [];
|
|
126
137
|
const unreadable: string[] = [];
|
|
127
|
-
for (const file of
|
|
138
|
+
for (const { file } of newest) {
|
|
128
139
|
try {
|
|
129
140
|
const value: unknown = JSON.parse(readFileSync(join(plansDir(root), file), "utf8"));
|
|
130
141
|
if (!isPlan(value)) throw new Error("not a plan");
|
|
@@ -211,7 +222,7 @@ function taskBlock(task: PlanTask): string {
|
|
|
211
222
|
].join("\n");
|
|
212
223
|
}
|
|
213
224
|
|
|
214
|
-
/**
|
|
225
|
+
/** The full plan as markdown: the header, then every task as its own section. */
|
|
215
226
|
export function planText(plan: Plan): string {
|
|
216
227
|
return [planBlock(plan), ...plan.tasks.map((task) => taskBlock(task))].join("\n\n");
|
|
217
228
|
}
|
|
@@ -221,81 +232,30 @@ export function taskText(plan: Plan, task: PlanTask): string {
|
|
|
221
232
|
return [planBlock(plan), taskBlock(task)].join("\n\n");
|
|
222
233
|
}
|
|
223
234
|
|
|
224
|
-
|
|
235
|
+
/** The plan header, then one row per task: the whole plan without every task's detail. */
|
|
236
|
+
export function planOverview(plan: Plan): string {
|
|
237
|
+
return [planBlock(plan), ...(plan.tasks.length ? ["", "## Tasks", ...plan.tasks.map(taskLine)] : [])].join("\n");
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function listText(root: string, list: PlanList): string {
|
|
225
241
|
if (!list.plans.length && !list.unreadable.length) return `No plans in ${plansDir(root)}.`;
|
|
226
242
|
return [
|
|
227
|
-
...list.plans.map((plan) => `${plan.id
|
|
243
|
+
...list.plans.map((plan) => `${plan.id} ${plan.title} ${planCount(plan)}`),
|
|
228
244
|
...list.unreadable.map((name) => `? ${name} unreadable`),
|
|
229
245
|
].join("\n");
|
|
230
246
|
}
|
|
231
247
|
|
|
232
|
-
|
|
233
|
-
|
|
248
|
+
/** plan_list's drill-down: one line per task, in plan order; a plan without tasks says so. */
|
|
249
|
+
export function tasksText(plan: Plan): string {
|
|
250
|
+
return plan.tasks.map(taskLine).join("\n") || `No tasks in ${plan.id} yet.`;
|
|
234
251
|
}
|
|
235
252
|
|
|
236
253
|
export function planCount(plan: Plan): string {
|
|
237
254
|
return `${doneCount(plan)}/${plan.tasks.length}`;
|
|
238
255
|
}
|
|
239
256
|
|
|
240
|
-
/** `id title 1/4`: the line the widget head, the tool result header and the list all lead with. */
|
|
241
|
-
export function planSummary(theme: Theme, plan: Plan): string {
|
|
242
|
-
return `${theme.fg("accent", plan.id)} ${plan.title} ${theme.fg("muted", planCount(plan))}`;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
257
|
/** The plan's own status: done when every task is, doing while one is, todo otherwise. */
|
|
246
258
|
export function planStatus(plan: Plan): Exclude<PlanStatus, "blocked"> {
|
|
247
259
|
if (plan.tasks.length && plan.tasks.every((task) => task.status === "done")) return "done";
|
|
248
260
|
return plan.tasks.some((task) => task.status === "doing") ? "doing" : "todo";
|
|
249
261
|
}
|
|
250
|
-
|
|
251
|
-
/** A task row: glyph, id, title, and the blockers still open; a done blocker is no noise worth showing. */
|
|
252
|
-
export function taskRow(theme: Theme, plan: Plan, task: PlanTask): string {
|
|
253
|
-
const open = task.dependsOn.filter((id) => !plan.tasks.some((item) => item.id === id && item.status === "done"));
|
|
254
|
-
const blocked = open.length ? ` ${theme.fg("muted", `· dependsOn ${open.join(" ")}`)}` : "";
|
|
255
|
-
return `${statusText(theme, task.status)} ${theme.fg("accent", task.id)} ${task.title}${blocked}`;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/** Wrapped rows whose continuations sit `indent` columns in, so a wrapped line never reads as a new one. */
|
|
259
|
-
export function hanging(text: string, width: number, indent: number): string[] {
|
|
260
|
-
return wrapTextWithAnsi(text, Math.max(1, width - indent)).map(
|
|
261
|
-
(line, index) => (index ? " ".repeat(indent) : "") + line,
|
|
262
|
-
);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/** A labelled line under a task row or in the plan header: the label muted so it reads as a key, the value in `color`, wrapping in the label's column. */
|
|
266
|
-
export function fact(
|
|
267
|
-
theme: Theme,
|
|
268
|
-
label: string,
|
|
269
|
-
text: string,
|
|
270
|
-
width: number,
|
|
271
|
-
indent = 2,
|
|
272
|
-
color: ThemeColor = label ? "text" : "dim",
|
|
273
|
-
): string[] {
|
|
274
|
-
return hanging((label ? theme.fg("muted", label) : "") + theme.fg(color, text), width - indent, label.length).map(
|
|
275
|
-
(line) => " ".repeat(indent) + line,
|
|
276
|
-
);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/** The lines under a task row: its goal, its brief as dim text, and its dim notes as written. */
|
|
280
|
-
export function taskFacts(theme: Theme, task: PlanTask, width: number): string[] {
|
|
281
|
-
return [
|
|
282
|
-
...fact(theme, "Goal: ", task.goal, width),
|
|
283
|
-
...(task.detail ? fact(theme, "Detail: ", task.detail, width, 2, "dim") : []),
|
|
284
|
-
...task.notes.flatMap((note) => fact(theme, "", note, width)),
|
|
285
|
-
];
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
/** pi's built-in expand hint; callers place it on its own row, so it carries no leading newline. */
|
|
289
|
-
export function moreLines(theme: Theme, hidden: number, keyHint: KeybindingHints["keyHint"]): string {
|
|
290
|
-
return `${theme.fg("muted", `... (${hidden} more lines,`)} ${keyHint("app.tools.expand", "to expand")}${theme.fg("muted", ")")}`;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/** The widget head, then one line per task in progress: parallel delegates can run several at once. */
|
|
294
|
-
export function widgetLines(theme: Theme, plan: Plan): string[] {
|
|
295
|
-
return [
|
|
296
|
-
`${theme.fg("accent", "plan")} ${plan.title} ${theme.fg("muted", planCount(plan))}`,
|
|
297
|
-
...plan.tasks
|
|
298
|
-
.filter((task) => task.status === "doing")
|
|
299
|
-
.map((task) => ` ${theme.fg("muted", task.id)} ${task.title}`),
|
|
300
|
-
];
|
|
301
|
-
}
|