@deathbeam/pi-plan 0.0.6 → 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 -399
- package/package.json +2 -2
- package/skills/import-plan/SKILL.md +8 -8
- package/skills/prepare-plan/SKILL.md +11 -13
- package/src/format.ts +269 -0
- package/src/inspector.ts +19 -86
- package/src/store.ts +34 -74
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deathbeam/pi-plan",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Structured plans with
|
|
3
|
+
"version": "0.0.7",
|
|
4
|
+
"description": "Structured plans with five plan tools and a full-screen plan picker",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: import-plan
|
|
3
|
-
description: Migrate existing plan documents
|
|
3
|
+
description: Migrate existing plan documents (.plans, Cursor, Kiro, Taskmaster) into the plan tools, when asked or when work starts from them.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Import plan
|
|
7
7
|
|
|
8
|
-
Move existing plan documents into the
|
|
8
|
+
Move existing plan documents into the plan tools: a `plan` call for the shell, then one `plan_task` call per task.
|
|
9
9
|
|
|
10
10
|
Migrate every plan you find in the project. When the request names specific files or plans, convert only those.
|
|
11
11
|
|
|
@@ -23,24 +23,24 @@ Migrate every plan you find in the project. When the request names specific file
|
|
|
23
23
|
|
|
24
24
|
3. **Skip a taken id.** If `.pi/plans/<id>.json` already exists, report the skip and convert the next source.
|
|
25
25
|
|
|
26
|
-
4. **Create one plan per source.** Use the mapping rules, then call `plan
|
|
26
|
+
4. **Create one plan per source.** Use the mapping rules, then call `plan` for the shell and `plan_task` once per task, carrying its `status` and `notes`.
|
|
27
27
|
|
|
28
|
-
5. **Report.** End with one table: source file, new plan id, tasks by status, and what you skipped or guessed.
|
|
28
|
+
5. **Report.** End with one table: source file, new plan id, tasks by status, and what you skipped or guessed. Leave the source files for the user to remove once the plan reads correctly.
|
|
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
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
|
|
35
|
+
- **title.** The plan's title or goal.
|
|
36
36
|
- **goal.** The plan's goal, summary or objective, as one observable outcome plus the check that proves it.
|
|
37
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 `
|
|
38
|
+
- **notes.** A top-level Notes, log or rulings section becomes plan notes. Create the plan first, then append each note with `plan_update`, the plan id, a `note` and no `task`.
|
|
39
39
|
- **Tasks.** Each top-level actionable item becomes one task.
|
|
40
40
|
- `title`: the item's text.
|
|
41
41
|
- `goal`: its verification, acceptance or test step, with the command when the source names it.
|
|
42
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.
|
|
43
|
+
- `dependsOn`: only the dependencies the source states, mapped to the new ids.
|
|
44
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.
|
|
45
45
|
- **Task notes.** Execution notes and log lines go to the notes of the task they belong to.
|
|
46
46
|
|
|
@@ -48,4 +48,4 @@ Fold a nested sub-step into its parent task's `detail` or notes. When a sub-step
|
|
|
48
48
|
|
|
49
49
|
When an item has no verification step, set its `goal` to `unverified: <what to check>`.
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
Translate stated dependencies after you order the tasks. Titles, goals, details and `dependsOn` are fixed once added, so check them before the `plan_task` calls.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: prepare-plan
|
|
3
|
-
description: Turn a request into a plan of independently verifiable tasks
|
|
3
|
+
description: Turn a request into a plan of independently verifiable tasks; use before implementing multi-step work.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Prepare plan
|
|
7
7
|
|
|
8
|
-
Write the plan with
|
|
8
|
+
Write the plan with `plan` for the shell, then one `plan_task` per task. The plan is the source of truth: each task is worked from `plan_get`, never from this conversation.
|
|
9
9
|
|
|
10
10
|
## Process
|
|
11
11
|
|
|
@@ -15,28 +15,26 @@ Write the plan with the `plan` tool, action `create`. The plan is the source of
|
|
|
15
15
|
|
|
16
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
|
-
4. **Write the plan detail.**
|
|
18
|
+
4. **Write the plan goal and detail.** The plan `goal` is the whole plan's final check, written as under Writing a goal; its `detail` uses the `plan` tool's section list, every `path:line` from code you read.
|
|
19
19
|
|
|
20
20
|
- Current behaviour, with `path:line` for each site.
|
|
21
|
-
-
|
|
22
|
-
-
|
|
21
|
+
- Problem: why that code is wrong today.
|
|
22
|
+
- Chosen design and rejected alternatives, with the reason.
|
|
23
23
|
- Accepted behaviour changes.
|
|
24
24
|
- Out of scope.
|
|
25
25
|
- Open questions.
|
|
26
26
|
|
|
27
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.
|
|
28
28
|
|
|
29
|
-
Each task is executed from `
|
|
29
|
+
Each task is executed from `plan_get` with `plan` and `task` alone: the plan's goal and detail, and that one task. Write it for a reader who never saw this conversation.
|
|
30
30
|
|
|
31
|
-
|
|
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.
|
|
31
|
+
Fill `title`, `goal` and `detail` as the `plan_task` schema describes; the `Where:` line cites `path:line` for each file that changes.
|
|
34
32
|
|
|
35
33
|
Add `dependsOn` only for a real dependency; tasks without one may run at the same time, in parallel agents, so keep their files disjoint.
|
|
36
34
|
|
|
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 `
|
|
35
|
+
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 `plan_get` will show it and confirm it can be done and checked without this conversation. Confirm the plan `goal`'s check fails before the tasks and passes after them.
|
|
38
36
|
|
|
39
|
-
7. **Create the plan.**
|
|
37
|
+
7. **Create the plan.** Call `plan` once for the shell: `title`, the plan `goal`, and the `detail` from step 4. Then call `plan_task` once per task in execution order; they may all go in one turn, since the calls run in order.
|
|
40
38
|
|
|
41
39
|
## Writing a goal
|
|
42
40
|
|
|
@@ -46,10 +44,10 @@ The plan `goal` and a task `goal` mean the same thing: the observable outcome pl
|
|
|
46
44
|
- `curl localhost:8080/health returns 200 with {"ok":true}`
|
|
47
45
|
- `open the settings page and press Save: the toast reads Saved`
|
|
48
46
|
|
|
49
|
-
The plan goal is the final verification of the whole plan.
|
|
47
|
+
The plan goal is the final verification of the whole plan. A task closes on its goal's check, so a goal without a check cannot close.
|
|
50
48
|
|
|
51
49
|
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`.
|
|
52
50
|
|
|
53
51
|
## Hand off
|
|
54
52
|
|
|
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.
|
|
53
|
+
Report the plan id, the task count and any decision still open. The task ids a later `plan_task` `dependsOn` or `plan_update` names come from `plan_list` with the `plan` id. Planning ends here: start the tasks when the user asks for it.
|
package/src/format.ts
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { getMarkdownTheme, type KeybindingHints, type Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import {
|
|
3
|
+
Container,
|
|
4
|
+
Markdown,
|
|
5
|
+
Spacer,
|
|
6
|
+
Text,
|
|
7
|
+
TruncatedText,
|
|
8
|
+
truncateToWidth,
|
|
9
|
+
type Component,
|
|
10
|
+
wrapTextWithAnsi,
|
|
11
|
+
} from "@earendil-works/pi-tui";
|
|
12
|
+
import { planCount, planStatus, type Plan, type PlanList, type PlanStatus, type PlanTask } from "./store.ts";
|
|
13
|
+
|
|
14
|
+
/** What a plan tool result carries for its renderer. */
|
|
15
|
+
export type PlanDetails = {
|
|
16
|
+
/** plan, plan_task, plan_update and plan_list: the plan the call wrote, or the one it drilled into. */
|
|
17
|
+
plan?: Plan;
|
|
18
|
+
/** plan_task and plan_update: the task the call changed. */
|
|
19
|
+
id?: string;
|
|
20
|
+
/** plan_update: the note this call appended. */
|
|
21
|
+
note?: string;
|
|
22
|
+
/** plan_get: the markdown this call returned. */
|
|
23
|
+
text?: string;
|
|
24
|
+
/** plan_list: every plan the call found, newest write first. */
|
|
25
|
+
list?: PlanList;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** What pi hands a renderer: the model's text, and the details this extension attached. */
|
|
29
|
+
type ToolResult = { content: { type: string; text?: string }[]; details?: unknown };
|
|
30
|
+
|
|
31
|
+
/** What pi hands a renderer beside the result: whether the call failed, and the expand keybinding. */
|
|
32
|
+
type ViewContext = { isError: boolean; keyHint: KeybindingHints["keyHint"] };
|
|
33
|
+
|
|
34
|
+
/** What pi hands a call renderer: whether the row is expanded, and the expand keybinding. */
|
|
35
|
+
type CallContext = { expanded: boolean; keyHint: KeybindingHints["keyHint"] };
|
|
36
|
+
|
|
37
|
+
/** One glyph and color per status, so the results and the inspector never disagree. */
|
|
38
|
+
const STATUS = {
|
|
39
|
+
todo: { glyph: "○", color: "muted" },
|
|
40
|
+
doing: { glyph: "◐", color: "warning" },
|
|
41
|
+
done: { glyph: "✓", color: "success" },
|
|
42
|
+
blocked: { glyph: "✗", color: "error" },
|
|
43
|
+
} as const satisfies Record<PlanStatus, { glyph: string; color: string }>;
|
|
44
|
+
|
|
45
|
+
/** pi caps a collapsed tool result at ten rows; the expansion shows all of them. */
|
|
46
|
+
const COLLAPSED_LINES = 10;
|
|
47
|
+
|
|
48
|
+
export function statusText(theme: Theme, status: PlanStatus): string {
|
|
49
|
+
return theme.fg(STATUS[status].color, STATUS[status].glyph);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** A model's arg as text: trimmed, and "" for the literal "null" a strict model sends for an omitted optional. */
|
|
53
|
+
export function argText(value: unknown): string {
|
|
54
|
+
const text = typeof value === "string" ? value.trim() : "";
|
|
55
|
+
return text === "null" ? "" : text;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** A status word in its status color; anything that is not a status shows nothing. */
|
|
59
|
+
export function statusArg(theme: Theme, status: unknown): string {
|
|
60
|
+
return typeof status === "string" && status in STATUS ? theme.fg(STATUS[status as PlanStatus].color, status) : "";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The plan a call names, as pi-delegate's jobTarget names its job. */
|
|
64
|
+
export function planTarget(args: any, theme: Theme): string {
|
|
65
|
+
return theme.fg("accent", argText(args?.plan) || "…");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Ids take the accent in a header, the same color planSummary and taskRow give them in the result. */
|
|
69
|
+
export function taskTarget(args: any, theme: Theme): string {
|
|
70
|
+
const task = argText(args?.task);
|
|
71
|
+
return task ? theme.fg("accent", task) : "";
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** `◐ foo Add widget 2/5`: the plan line every surface shows: tool result footer and inspector row. */
|
|
75
|
+
export function planSummary(theme: Theme, plan: Plan): string {
|
|
76
|
+
return `${statusText(theme, planStatus(plan))} ${theme.fg("accent", plan.id)} ${plan.title} ${theme.fg("muted", planCount(plan))}`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** A task row: glyph, id, title, and the blockers still open; a done blocker is no noise worth showing. */
|
|
80
|
+
export function taskRow(theme: Theme, plan: Plan, task: PlanTask, current = false): string {
|
|
81
|
+
const open = task.dependsOn.filter((id) => !plan.tasks.some((item) => item.id === id && item.status === "done"));
|
|
82
|
+
const blocked = open.length ? ` ${theme.fg("muted", `· dependsOn ${open.join(" ")}`)}` : "";
|
|
83
|
+
const title = current ? theme.bold(task.title) : task.title;
|
|
84
|
+
return `${statusText(theme, task.status)} ${theme.fg("accent", task.id)} ${title}${blocked}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** A task row wrapped to the width; the indent is taskRow's glyph, id and space, so continuations line up under the title. */
|
|
88
|
+
export function taskLines(theme: Theme, plan: Plan, task: PlanTask, width: number, current = false): string[] {
|
|
89
|
+
return hanging(taskRow(theme, plan, task, current), width, task.id.length + 3);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Wrapped rows whose continuations sit `indent` columns in, so a wrapped line never reads as a new one. */
|
|
93
|
+
export function hanging(text: string, width: number, indent: number): string[] {
|
|
94
|
+
return wrapTextWithAnsi(text, Math.max(1, width - indent)).map(
|
|
95
|
+
(line, index) => (index ? " ".repeat(indent) : "") + line,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** pi's built-in expand hint; callers place it on its own row, so it carries no leading newline. */
|
|
100
|
+
function moreLines(theme: Theme, hidden: number, keyHint: KeybindingHints["keyHint"]): string {
|
|
101
|
+
return `${theme.fg("muted", `... (${hidden} more lines,`)} ${keyHint("app.tools.expand", "to expand")}${theme.fg("muted", ")")}`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Markdown reads a lone newline as a space; a planner's one-newline paragraph break is meant as a break. */
|
|
105
|
+
export function hardBreaks(text: string): string {
|
|
106
|
+
const lines = text.split("\n");
|
|
107
|
+
let fenced = false;
|
|
108
|
+
return lines
|
|
109
|
+
.map((line, index) => {
|
|
110
|
+
const fence = /^\s*(```|~~~)/.test(line);
|
|
111
|
+
const block = fenced || fence || /^\s*([-*+]|\d+\.)\s/.test(line) || /^\s*#/.test(line);
|
|
112
|
+
if (fence) fenced = !fenced;
|
|
113
|
+
return block || !lines[index + 1] ? line : `${line} `;
|
|
114
|
+
})
|
|
115
|
+
.join("\n");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function capLines<T>(lines: readonly T[], max: number): { shown: T[]; hidden: number } {
|
|
119
|
+
return { shown: lines.slice(0, max), hidden: Math.max(0, lines.length - max) };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** A result view capped to ten rows until the user expands it, then in full. */
|
|
123
|
+
function resultView(
|
|
124
|
+
rows: (width: number) => string[],
|
|
125
|
+
theme: Theme,
|
|
126
|
+
expanded: boolean,
|
|
127
|
+
keyHint: KeybindingHints["keyHint"],
|
|
128
|
+
): Component {
|
|
129
|
+
return {
|
|
130
|
+
render: (width) => {
|
|
131
|
+
// Wrapping turns one long line into many rows, so the cap counts rendered rows.
|
|
132
|
+
const { shown, hidden } = capLines(rows(width), expanded ? Infinity : COLLAPSED_LINES + 1);
|
|
133
|
+
return hidden ? [...shown, truncateToWidth(moreLines(theme, hidden, keyHint), width)] : shown;
|
|
134
|
+
},
|
|
135
|
+
invalidate() {},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Markdown as trimmed rows: the theme, the hard breaks and the padding trim in one place. */
|
|
140
|
+
function markdownRows(text: string, width: number): string[] {
|
|
141
|
+
return new Markdown(hardBreaks(text), 0, 0, getMarkdownTheme())
|
|
142
|
+
.render(Math.max(1, width))
|
|
143
|
+
.map((line) => line.trimEnd());
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** The present parts, a blank row between them: a call body never shows a gap for what the model omitted. */
|
|
147
|
+
export function blocks(parts: string[]): string[] {
|
|
148
|
+
return parts.filter((part) => part.trim()).flatMap((part, index) => (index ? ["", part] : [part]));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** A tool call: the name and identity on one truncated row, a blank row, then the body capped like a result. */
|
|
152
|
+
function callLayout(toolName: string, identity: string, body: string, theme: Theme, context: CallContext): Component {
|
|
153
|
+
const container = new Container();
|
|
154
|
+
container.addChild(
|
|
155
|
+
new TruncatedText(`${theme.fg("toolTitle", theme.bold(toolName))}${identity ? ` ${identity}` : ""}`),
|
|
156
|
+
);
|
|
157
|
+
if (!body.trim()) return container;
|
|
158
|
+
container.addChild(new Spacer(1));
|
|
159
|
+
container.addChild({
|
|
160
|
+
render: (width) => {
|
|
161
|
+
// Wrapping turns one long line into many rows, so the cap counts rendered rows.
|
|
162
|
+
const { shown, hidden } = capLines(
|
|
163
|
+
markdownRows(body, width),
|
|
164
|
+
context.expanded ? Infinity : COLLAPSED_LINES,
|
|
165
|
+
);
|
|
166
|
+
return hidden ? [...shown, truncateToWidth(moreLines(theme, hidden, context.keyHint), width)] : shown;
|
|
167
|
+
},
|
|
168
|
+
invalidate() {},
|
|
169
|
+
});
|
|
170
|
+
return container;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** The renderCall every plan tool shares: identity beside the name, the model's own markdown under it. */
|
|
174
|
+
export function callRenderer(
|
|
175
|
+
toolName: string,
|
|
176
|
+
identity: (args: any, theme: Theme) => string,
|
|
177
|
+
body: (args: any, theme: Theme) => string = () => "",
|
|
178
|
+
) {
|
|
179
|
+
return (args: any, theme: Theme, context: CallContext) =>
|
|
180
|
+
callLayout(toolName, identity(args, theme), body(args, theme), theme, context);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** pi styles errors itself, but a custom renderer replaces that default, so keep its look. */
|
|
184
|
+
function errorView(body: string, theme: Theme, isError: boolean): Component {
|
|
185
|
+
const mark = statusText(theme, isError ? "blocked" : "done");
|
|
186
|
+
const text = theme.fg(isError ? "error" : "toolOutput", body || "(no output)");
|
|
187
|
+
return new Text(`\n${mark} ${text}`, 0, 0);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function resultText(result: ToolResult): string {
|
|
191
|
+
return result.content.flatMap((part) => (part.type === "text" && part.text ? [part.text] : [])).join("\n");
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** A failed call carries no details to render; the views fall back to the model's text. */
|
|
195
|
+
function detailsOf(result: ToolResult, context: ViewContext): PlanDetails | undefined {
|
|
196
|
+
return context.isError ? undefined : (result.details as PlanDetails | undefined);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** What changed: the task row, the note this call appended, and where the plan now stands. */
|
|
200
|
+
function updateLines(
|
|
201
|
+
plan: Plan,
|
|
202
|
+
id: string | undefined,
|
|
203
|
+
note: string | undefined,
|
|
204
|
+
theme: Theme,
|
|
205
|
+
width: number,
|
|
206
|
+
): string[] {
|
|
207
|
+
const task = plan.tasks.find((item) => item.id === id);
|
|
208
|
+
return [
|
|
209
|
+
"",
|
|
210
|
+
...(task ? taskLines(theme, plan, task, width) : []),
|
|
211
|
+
...(note ? hanging(theme.fg("dim", note), width - 2, 0).map((line) => ` ${line}`) : []),
|
|
212
|
+
planSummary(theme, plan),
|
|
213
|
+
];
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** plan_task and plan_update change one task or the plan's notes, so both show the same rows. */
|
|
217
|
+
export function changeView(
|
|
218
|
+
result: ToolResult,
|
|
219
|
+
options: { expanded: boolean },
|
|
220
|
+
theme: Theme,
|
|
221
|
+
context: ViewContext,
|
|
222
|
+
): Component {
|
|
223
|
+
const d = detailsOf(result, context);
|
|
224
|
+
const plan = d?.plan;
|
|
225
|
+
if (!plan) return errorView(resultText(result), theme, context.isError);
|
|
226
|
+
return resultView(
|
|
227
|
+
(width) => updateLines(plan, d?.id, d?.note, theme, width),
|
|
228
|
+
theme,
|
|
229
|
+
options.expanded,
|
|
230
|
+
context.keyHint,
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** plan and plan_get return markdown: the plan header, or that header and the task's brief. */
|
|
235
|
+
export function markdownView(
|
|
236
|
+
result: ToolResult,
|
|
237
|
+
options: { expanded: boolean },
|
|
238
|
+
theme: Theme,
|
|
239
|
+
context: ViewContext,
|
|
240
|
+
): Component {
|
|
241
|
+
const d = detailsOf(result, context);
|
|
242
|
+
const text = d?.text;
|
|
243
|
+
if (!text) return errorView(resultText(result), theme, context.isError);
|
|
244
|
+
return resultView((width) => ["", ...markdownRows(text, width)], theme, options.expanded, context.keyHint);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** plan_list: a blank row, then the named plan's task rows, or one plan line each, then any unreadable file. */
|
|
248
|
+
function listLines(d: PlanDetails, theme: Theme, width: number): string[] {
|
|
249
|
+
const { plan, list } = d;
|
|
250
|
+
if (plan) return ["", ...plan.tasks.flatMap((task) => taskLines(theme, plan, task, width))];
|
|
251
|
+
return [
|
|
252
|
+
"",
|
|
253
|
+
...(list?.plans ?? []).map((item) => planSummary(theme, item)),
|
|
254
|
+
...(list?.unreadable ?? []).map((name) => theme.fg("error", `? ${name} unreadable`)),
|
|
255
|
+
];
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** plan_list's result: the plan it names, or every plan in the mtime order the store returned. */
|
|
259
|
+
export function listView(
|
|
260
|
+
result: ToolResult,
|
|
261
|
+
options: { expanded: boolean },
|
|
262
|
+
theme: Theme,
|
|
263
|
+
context: ViewContext,
|
|
264
|
+
): Component {
|
|
265
|
+
const d = detailsOf(result, context);
|
|
266
|
+
if (d?.plan || d?.list?.plans.length || d?.list?.unreadable.length)
|
|
267
|
+
return resultView((width) => listLines(d, theme, width), theme, options.expanded, context.keyHint);
|
|
268
|
+
return errorView(resultText(result), theme, context.isError);
|
|
269
|
+
}
|
package/src/inspector.ts
CHANGED
|
@@ -11,29 +11,17 @@ import {
|
|
|
11
11
|
truncateToWidth,
|
|
12
12
|
visibleWidth,
|
|
13
13
|
} from "@earendil-works/pi-tui";
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
hanging,
|
|
17
|
-
nextTask,
|
|
18
|
-
noteItem,
|
|
19
|
-
planCount,
|
|
20
|
-
planStatus,
|
|
21
|
-
statusText,
|
|
22
|
-
type Plan,
|
|
23
|
-
type PlanStatus,
|
|
24
|
-
type PlanList,
|
|
25
|
-
type PlanTask,
|
|
26
|
-
} from "./store.ts";
|
|
14
|
+
import { hardBreaks, planSummary, taskLines } from "./format.ts";
|
|
15
|
+
import { nextTask, noteItem, type Plan, type PlanList, type PlanStatus, type PlanTask } from "./store.ts";
|
|
27
16
|
|
|
28
17
|
type PlansScreenOptions = {
|
|
29
18
|
plans: Plan[];
|
|
30
19
|
unreadable: string[];
|
|
31
|
-
|
|
20
|
+
selected?: string;
|
|
32
21
|
theme: Theme;
|
|
33
22
|
keys: KeybindingsManager;
|
|
34
23
|
/** Terminal rows, read per frame. */
|
|
35
24
|
height: () => number;
|
|
36
|
-
setActive: (id: string) => void;
|
|
37
25
|
onClose: () => void;
|
|
38
26
|
requestRender: () => void;
|
|
39
27
|
};
|
|
@@ -49,20 +37,6 @@ function hint(keys: KeybindingsManager, ids: Keybinding[], description: string):
|
|
|
49
37
|
return rawKeyHint(ids.flatMap((id) => keys.getKeys(id)).join("/"), description);
|
|
50
38
|
}
|
|
51
39
|
|
|
52
|
-
/** Markdown reads a lone newline as a space; a planner's one-newline paragraph break is meant as a break. */
|
|
53
|
-
export function hardBreaks(text: string): string {
|
|
54
|
-
const lines = text.split("\n");
|
|
55
|
-
let fenced = false;
|
|
56
|
-
return lines
|
|
57
|
-
.map((line, index) => {
|
|
58
|
-
const fence = /^\s*(```|~~~)/.test(line);
|
|
59
|
-
const block = fenced || fence || /^\s*([-*+]|\d+\.)\s/.test(line) || /^\s*#/.test(line);
|
|
60
|
-
if (fence) fenced = !fenced;
|
|
61
|
-
return block || !lines[index + 1] ? line : `${line} `;
|
|
62
|
-
})
|
|
63
|
-
.join("\n");
|
|
64
|
-
}
|
|
65
|
-
|
|
66
40
|
/** Markdown rendered at one width, cached per theme: render() runs every frame and contexts can be long. */
|
|
67
41
|
function markdown(theme: Theme, text: string, width: number): string[] {
|
|
68
42
|
let cache = MARKDOWN_CACHE.get(theme);
|
|
@@ -89,20 +63,6 @@ function section(theme: Theme, word: string, width: number): string {
|
|
|
89
63
|
return head + theme.fg("borderMuted", rule);
|
|
90
64
|
}
|
|
91
65
|
|
|
92
|
-
/** The block header: glyph, muted id, title, then the blockers still open after a dim separator. */
|
|
93
|
-
function taskLines(plan: Plan, task: PlanTask, theme: Theme, width: number, current: boolean): string[] {
|
|
94
|
-
const open = task.dependsOn.filter((id) => !plan.tasks.some((item) => item.id === id && item.status === "done"));
|
|
95
|
-
const after = open.length ? ` ${theme.fg("muted", `· after ${open.join(", ")}`)}` : "";
|
|
96
|
-
// Accent means headings and labels, so the task the reader is on is bold text instead.
|
|
97
|
-
const title = theme.fg("text", task.title);
|
|
98
|
-
const [first = "", ...rest] = hanging(
|
|
99
|
-
`${theme.fg("muted", task.id)} ${current ? theme.bold(title) : title}${after}`,
|
|
100
|
-
width,
|
|
101
|
-
2,
|
|
102
|
-
);
|
|
103
|
-
return [`${statusText(theme, task.status)} ${first}`, ...rest];
|
|
104
|
-
}
|
|
105
|
-
|
|
106
66
|
/** A blank row, the field's accent label on a line of its own, then its value at column 0. */
|
|
107
67
|
function field(theme: Theme, label: string, value: string, width: number): string[] {
|
|
108
68
|
return ["", theme.fg("accent", label), ...markdown(theme, value, width)];
|
|
@@ -130,7 +90,7 @@ function taskBlock(
|
|
|
130
90
|
): string[] {
|
|
131
91
|
const inner = Math.max(1, width - 2);
|
|
132
92
|
const groups = [
|
|
133
|
-
taskLines(plan, task,
|
|
93
|
+
taskLines(theme, plan, task, inner, current),
|
|
134
94
|
...(!expanded && task.status === "done"
|
|
135
95
|
? []
|
|
136
96
|
: [
|
|
@@ -166,38 +126,26 @@ function taskRows(plan: Plan, theme: Theme, width: number, expanded: boolean): s
|
|
|
166
126
|
].map((line) => truncateToWidth(line, width, "…", true));
|
|
167
127
|
}
|
|
168
128
|
|
|
169
|
-
/**
|
|
129
|
+
/** One row per plan: the cursor, then the plan line every surface shows. */
|
|
170
130
|
function sidebarRows(
|
|
171
131
|
plans: Plan[],
|
|
172
132
|
unreadable: string[],
|
|
173
|
-
|
|
174
|
-
active: string | undefined,
|
|
133
|
+
cursor: number,
|
|
175
134
|
focus: Focus,
|
|
176
135
|
theme: Theme,
|
|
177
136
|
width: number,
|
|
178
137
|
height: number,
|
|
179
138
|
): { lines: string[]; indexes: (number | undefined)[] } {
|
|
180
|
-
const all: {
|
|
139
|
+
const all: { line: string; index?: number }[] = [
|
|
181
140
|
...plans.map((plan, planIndex) => {
|
|
182
|
-
const chosen = planIndex === selected;
|
|
183
141
|
// The cursor dims while the detail pane takes the keys, so the user sees which pane is live.
|
|
184
|
-
const
|
|
185
|
-
return {
|
|
186
|
-
lines: [
|
|
187
|
-
`${cursor} ${statusText(theme, planStatus(plan))} ${theme.fg(chosen ? "accent" : "text", plan.id)} ${theme.fg("muted", planCount(plan))}`,
|
|
188
|
-
theme.fg("dim", ` ${plan.id === active ? "active · " : ""}${plan.title}`),
|
|
189
|
-
],
|
|
190
|
-
index: planIndex,
|
|
191
|
-
};
|
|
142
|
+
const mark = planIndex === cursor ? theme.fg(focus === "list" ? "accent" : "muted", "›") : " ";
|
|
143
|
+
return { line: `${mark} ${planSummary(theme, plan)}`, index: planIndex };
|
|
192
144
|
}),
|
|
193
|
-
...unreadable.map((file) => ({
|
|
145
|
+
...unreadable.map((file) => ({ line: theme.fg("error", ` ? ${file} unreadable`) })),
|
|
194
146
|
];
|
|
195
|
-
const
|
|
196
|
-
const
|
|
197
|
-
let start = Math.max(0, Math.min(selectedRow - Math.floor(height / 2), rows.length - height));
|
|
198
|
-
// A window never opens on a plan's second row, which would show a title with no id above it.
|
|
199
|
-
while (start > 0 && !rows[start]!.head) start--;
|
|
200
|
-
const shown = rows.slice(start, start + height);
|
|
147
|
+
const start = Math.max(0, Math.min(cursor - Math.floor(height / 2), all.length - height));
|
|
148
|
+
const shown = all.slice(start, start + height);
|
|
201
149
|
return {
|
|
202
150
|
lines: [
|
|
203
151
|
...shown.map(
|
|
@@ -215,7 +163,6 @@ function sidebarRows(
|
|
|
215
163
|
export class PlansScreen implements Component {
|
|
216
164
|
private readonly options: PlansScreenOptions;
|
|
217
165
|
private index: number;
|
|
218
|
-
private active: string | undefined;
|
|
219
166
|
private focus: Focus = "list";
|
|
220
167
|
private top = 0;
|
|
221
168
|
private expanded = false;
|
|
@@ -226,8 +173,7 @@ export class PlansScreen implements Component {
|
|
|
226
173
|
|
|
227
174
|
constructor(options: PlansScreenOptions) {
|
|
228
175
|
this.options = options;
|
|
229
|
-
|
|
230
|
-
const found = options.active ? options.plans.findIndex((plan) => plan.id === options.active) : -1;
|
|
176
|
+
const found = options.selected ? options.plans.findIndex((plan) => plan.id === options.selected) : -1;
|
|
231
177
|
this.index = Math.max(0, found);
|
|
232
178
|
}
|
|
233
179
|
|
|
@@ -259,7 +205,6 @@ export class PlansScreen implements Component {
|
|
|
259
205
|
"dim",
|
|
260
206
|
[
|
|
261
207
|
rawKeyHint("←/→", "pane"),
|
|
262
|
-
hint(keys, ["tui.select.confirm"], "make active"),
|
|
263
208
|
hint(keys, ["tui.select.cancel"], "close"),
|
|
264
209
|
hint(keys, ["app.tools.expand"], this.expanded ? "collapse" : "expand"),
|
|
265
210
|
paneHints,
|
|
@@ -267,7 +212,7 @@ export class PlansScreen implements Component {
|
|
|
267
212
|
),
|
|
268
213
|
);
|
|
269
214
|
const plan = plans[this.index];
|
|
270
|
-
const sidebar = sidebarRows(plans, unreadable, this.index, this.
|
|
215
|
+
const sidebar = sidebarRows(plans, unreadable, this.index, this.focus, theme, sidebarWidth, body);
|
|
271
216
|
this.lastIndexes = sidebar.indexes;
|
|
272
217
|
const detail = plan
|
|
273
218
|
? this.detail(plan, detailWidth, body)
|
|
@@ -276,17 +221,12 @@ export class PlansScreen implements Component {
|
|
|
276
221
|
}
|
|
277
222
|
|
|
278
223
|
handleInput(data: string): void {
|
|
279
|
-
const { keys, onClose
|
|
224
|
+
const { keys, onClose } = this.options;
|
|
280
225
|
const detail = this.focus === "detail";
|
|
281
226
|
if (keys.matches(data, "tui.select.cancel")) onClose();
|
|
282
227
|
else if (matchesKey(data, "left")) this.focus = "list";
|
|
283
228
|
else if (matchesKey(data, "right")) this.focus = "detail";
|
|
284
|
-
else if (keys.matches(data, "
|
|
285
|
-
const plan = this.options.plans[this.index];
|
|
286
|
-
if (!plan) return;
|
|
287
|
-
this.active = plan.id;
|
|
288
|
-
setActive(plan.id);
|
|
289
|
-
} else if (keys.matches(data, "app.tools.expand")) {
|
|
229
|
+
else if (keys.matches(data, "app.tools.expand")) {
|
|
290
230
|
this.expanded = !this.expanded;
|
|
291
231
|
this.top = 0;
|
|
292
232
|
} else if (detail && keys.matches(data, "tui.altScreen.pageUp")) this.scroll(-this.pageSize());
|
|
@@ -322,8 +262,7 @@ export class PlansScreen implements Component {
|
|
|
322
262
|
MARKDOWN_CACHE.delete(theme);
|
|
323
263
|
}
|
|
324
264
|
const blocked = plan.tasks.some((task) => task.status === "blocked") ? " · blocked" : "";
|
|
325
|
-
const
|
|
326
|
-
const header = `${statusText(theme, planStatus(plan))} ${theme.fg("accent", plan.id)} ${theme.fg("text", plan.title)} ${progress}`;
|
|
265
|
+
const header = planSummary(theme, plan) + (blocked ? theme.fg("muted", blocked) : "");
|
|
327
266
|
const height = Math.max(0, body - 2);
|
|
328
267
|
const all = taskRows(plan, theme, width, this.expanded);
|
|
329
268
|
const start = Math.min(this.top, Math.max(0, all.length - height));
|
|
@@ -363,23 +302,17 @@ export class PlansScreen implements Component {
|
|
|
363
302
|
}
|
|
364
303
|
}
|
|
365
304
|
|
|
366
|
-
export function openPlans(
|
|
367
|
-
ctx: ExtensionContext,
|
|
368
|
-
list: PlanList,
|
|
369
|
-
active: string | undefined,
|
|
370
|
-
setActive: (id: string) => void,
|
|
371
|
-
): Promise<void> {
|
|
305
|
+
export function openPlans(ctx: ExtensionContext, list: PlanList, selected: string | undefined): Promise<void> {
|
|
372
306
|
const screen = { overlay: true, overlayOptions: { width: "100%", maxHeight: "100%", row: 0, col: 0 } } as const;
|
|
373
307
|
return ctx.ui.custom<void>(
|
|
374
308
|
(tui, theme, keys, done) =>
|
|
375
309
|
new PlansScreen({
|
|
376
310
|
plans: list.plans,
|
|
377
311
|
unreadable: list.unreadable,
|
|
378
|
-
|
|
312
|
+
selected,
|
|
379
313
|
theme,
|
|
380
314
|
keys,
|
|
381
315
|
height: () => tui.terminal.rows,
|
|
382
|
-
setActive,
|
|
383
316
|
onClose: () => done(undefined),
|
|
384
317
|
requestRender: () => tui.requestRender(),
|
|
385
318
|
}),
|