@deathbeam/pi-plan 0.0.1 → 0.0.2
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/index.ts +40 -20
- package/package.json +1 -1
- package/src/inspector.ts +216 -48
- package/src/store.ts +30 -7
package/index.ts
CHANGED
|
@@ -12,6 +12,8 @@ import { openPlans } from "./src/inspector.ts";
|
|
|
12
12
|
import {
|
|
13
13
|
doneCount,
|
|
14
14
|
excludePlans,
|
|
15
|
+
fact,
|
|
16
|
+
hanging,
|
|
15
17
|
listPlans,
|
|
16
18
|
listText,
|
|
17
19
|
moreLines,
|
|
@@ -125,15 +127,19 @@ function capLines<T>(lines: readonly T[], max: number): { shown: T[]; hidden: nu
|
|
|
125
127
|
}
|
|
126
128
|
|
|
127
129
|
/** A result view capped to ten rows until the user expands it, then in full. */
|
|
128
|
-
function resultView(
|
|
129
|
-
|
|
130
|
+
function resultView(
|
|
131
|
+
rows: (width: number) => string[],
|
|
132
|
+
theme: Theme,
|
|
133
|
+
expanded: boolean,
|
|
134
|
+
keyHint: KeybindingHints["keyHint"],
|
|
135
|
+
): Component {
|
|
130
136
|
return {
|
|
131
137
|
render: (width) => {
|
|
132
138
|
// Wrapping turns one long line into many rows, so the cap counts rendered rows.
|
|
133
|
-
const { shown, hidden } = capLines(
|
|
139
|
+
const { shown, hidden } = capLines(rows(width), expanded ? Infinity : COLLAPSED_LINES + 1);
|
|
134
140
|
return hidden ? [...shown, truncateToWidth(moreLines(theme, hidden, keyHint), width)] : shown;
|
|
135
141
|
},
|
|
136
|
-
invalidate
|
|
142
|
+
invalidate() {},
|
|
137
143
|
};
|
|
138
144
|
}
|
|
139
145
|
|
|
@@ -149,34 +155,44 @@ function resultText(result: { content: { type: string; text?: string }[] }): str
|
|
|
149
155
|
}
|
|
150
156
|
|
|
151
157
|
/** 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[] {
|
|
158
|
+
function planLines(plan: Plan, theme: Theme, expanded: boolean, width: number): string[] {
|
|
153
159
|
const tasks = plan.tasks.flatMap((task) =>
|
|
154
|
-
expanded
|
|
160
|
+
expanded
|
|
161
|
+
? [...hanging(taskRow(theme, plan, task), width, task.id.length + 3), ...taskFacts(theme, task, width)]
|
|
162
|
+
: [taskRow(theme, plan, task)],
|
|
155
163
|
);
|
|
156
164
|
return [
|
|
157
165
|
"",
|
|
158
166
|
`${theme.fg("accent", "plan")} ${planSummary(theme, plan)}`,
|
|
159
167
|
...(expanded
|
|
160
|
-
? [
|
|
168
|
+
? [...fact(theme, "Goal: ", plan.goal, width), ...fact(theme, "Context: ", plan.context, width, 2, "dim")]
|
|
161
169
|
: []),
|
|
162
170
|
...tasks,
|
|
163
171
|
];
|
|
164
172
|
}
|
|
165
173
|
|
|
166
174
|
/** 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[] {
|
|
175
|
+
function focusLines(plan: Plan, id: string, theme: Theme, width: number): string[] {
|
|
168
176
|
const task = plan.tasks.find((item) => item.id === id);
|
|
169
|
-
return task
|
|
177
|
+
return task
|
|
178
|
+
? ["", ...hanging(taskRow(theme, plan, task), width, task.id.length + 3), ...taskFacts(theme, task, width)]
|
|
179
|
+
: [];
|
|
170
180
|
}
|
|
171
181
|
|
|
172
182
|
/** What changed: the task row, the note this call appended, and where the plan now stands. */
|
|
173
|
-
function updateLines(
|
|
183
|
+
function updateLines(
|
|
184
|
+
plan: Plan,
|
|
185
|
+
id: string | undefined,
|
|
186
|
+
note: string | undefined,
|
|
187
|
+
theme: Theme,
|
|
188
|
+
width: number,
|
|
189
|
+
): string[] {
|
|
174
190
|
const task = plan.tasks.find((item) => item.id === id);
|
|
175
191
|
if (!task) return [];
|
|
176
192
|
return [
|
|
177
193
|
"",
|
|
178
|
-
taskRow(theme, plan, task),
|
|
179
|
-
...(note ?
|
|
194
|
+
...hanging(taskRow(theme, plan, task), width, task.id.length + 3),
|
|
195
|
+
...(note ? fact(theme, "", note, width) : []),
|
|
180
196
|
theme.fg("muted", planSummary(theme, plan)),
|
|
181
197
|
];
|
|
182
198
|
}
|
|
@@ -357,14 +373,18 @@ export default function (pi: ExtensionAPI) {
|
|
|
357
373
|
|
|
358
374
|
renderResult(result, { expanded }, theme, context) {
|
|
359
375
|
const details = context.isError ? undefined : (result.details as PlanDetails | undefined);
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
376
|
+
const plan = details?.plan;
|
|
377
|
+
const list = details?.list;
|
|
378
|
+
const active = details?.active;
|
|
379
|
+
const id = details?.id;
|
|
380
|
+
const note = details?.note;
|
|
381
|
+
let rows: ((width: number) => string[]) | undefined;
|
|
382
|
+
if (list) rows = () => listLines(list, active, theme);
|
|
383
|
+
else if (plan && details?.action === "update") rows = (width) => updateLines(plan, id, note, theme, width);
|
|
384
|
+
else if (plan && id) rows = (width) => focusLines(plan, id, theme, width);
|
|
385
|
+
else if (plan) rows = (width) => planLines(plan, theme, expanded, width);
|
|
386
|
+
return rows
|
|
387
|
+
? resultView(rows, theme, expanded, context.keyHint)
|
|
368
388
|
: errorView(resultText(result), theme, context.isError);
|
|
369
389
|
},
|
|
370
390
|
});
|
package/package.json
CHANGED
package/src/inspector.ts
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
|
-
import { rawKeyHint, type ExtensionContext, type Theme } from "@earendil-works/pi-coding-agent";
|
|
1
|
+
import { rawKeyHint, getMarkdownTheme, type ExtensionContext, type Theme } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import {
|
|
3
|
+
Markdown,
|
|
3
4
|
type Component,
|
|
4
5
|
type Keybinding,
|
|
5
6
|
type KeybindingsManager,
|
|
7
|
+
matchesKey,
|
|
6
8
|
type TuiMouseEvent,
|
|
7
9
|
truncateToWidth,
|
|
10
|
+
visibleWidth,
|
|
8
11
|
wrapTextWithAnsi,
|
|
9
12
|
} from "@earendil-works/pi-tui";
|
|
10
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
doneCount,
|
|
15
|
+
hanging,
|
|
16
|
+
nextTask,
|
|
17
|
+
planCount,
|
|
18
|
+
planStatus,
|
|
19
|
+
statusText,
|
|
20
|
+
type Plan,
|
|
21
|
+
type PlanList,
|
|
22
|
+
type PlanTask,
|
|
23
|
+
} from "./store.ts";
|
|
11
24
|
|
|
12
25
|
type PlansScreenOptions = {
|
|
13
26
|
plans: Plan[];
|
|
@@ -24,34 +37,150 @@ type PlansScreenOptions = {
|
|
|
24
37
|
|
|
25
38
|
/** Fixed rows: title, top rule, bottom rule, footer. */
|
|
26
39
|
const CHROME_ROWS = 4;
|
|
40
|
+
/** Prose past this width is hard to follow on a wide terminal; the pane leaves the rest empty. */
|
|
41
|
+
const MAX_TEXT_WIDTH = 120;
|
|
42
|
+
/** Rendered markdown by theme, then width and text; cleared by invalidate() and on a width change. */
|
|
43
|
+
const MARKDOWN_CACHE = new WeakMap<Theme, Map<string, string[]>>();
|
|
44
|
+
|
|
45
|
+
type Focus = "list" | "detail";
|
|
27
46
|
|
|
28
47
|
function hint(keys: KeybindingsManager, ids: Keybinding[], description: string): string {
|
|
29
48
|
return rawKeyHint(ids.flatMap((id) => keys.getKeys(id)).join("/"), description);
|
|
30
49
|
}
|
|
31
50
|
|
|
51
|
+
/** Markdown reads a lone newline as a space; a planner's one-newline paragraph break is meant as a break. */
|
|
52
|
+
function hardBreaks(text: string): string {
|
|
53
|
+
const lines = text.split("\n");
|
|
54
|
+
let fenced = false;
|
|
55
|
+
return lines
|
|
56
|
+
.map((line, index) => {
|
|
57
|
+
const fence = /^\s*(```|~~~)/.test(line);
|
|
58
|
+
const block = fenced || fence || /^\s*([-*+]|\d+\.)\s/.test(line) || /^\s*#/.test(line);
|
|
59
|
+
if (fence) fenced = !fenced;
|
|
60
|
+
return block || !lines[index + 1] ? line : `${line} `;
|
|
61
|
+
})
|
|
62
|
+
.join("\n");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Markdown rendered at one width, cached per theme: render() runs every frame and contexts can be long. */
|
|
66
|
+
function markdown(theme: Theme, text: string, width: number, indent = 0): string[] {
|
|
67
|
+
let cache = MARKDOWN_CACHE.get(theme);
|
|
68
|
+
if (!cache) MARKDOWN_CACHE.set(theme, (cache = new Map()));
|
|
69
|
+
const key = `${width} ${text}`;
|
|
70
|
+
let lines = cache.get(key);
|
|
71
|
+
if (!lines) {
|
|
72
|
+
const component = new Markdown(hardBreaks(text), 0, 0, getMarkdownTheme(), {
|
|
73
|
+
color: (t) => theme.fg("text", t),
|
|
74
|
+
});
|
|
75
|
+
// Markdown pads every row to its width; the pane pads again, so trim before composing.
|
|
76
|
+
lines = component.render(Math.max(1, width)).map((line) => line.trimEnd());
|
|
77
|
+
while (lines.length && !lines[0]) lines.shift();
|
|
78
|
+
while (lines.length && !lines.at(-1)) lines.pop();
|
|
79
|
+
cache.set(key, lines);
|
|
80
|
+
}
|
|
81
|
+
return lines.map((line) => " ".repeat(indent) + line);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** A section heading: the word in accent, a rule to the pane edge, and the tasks heading's own count. */
|
|
85
|
+
function section(theme: Theme, word: string, width: number, trailing = ""): string {
|
|
86
|
+
const head = `${theme.bold(theme.fg("accent", word))} `;
|
|
87
|
+
const rule = "─".repeat(Math.max(0, width - visibleWidth(head) - visibleWidth(trailing)));
|
|
88
|
+
return head + theme.fg("borderMuted", rule) + trailing;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The title row: the glyph, the title, and the id at the right edge, with the blockers still open after it. */
|
|
92
|
+
function taskLines(plan: Plan, task: PlanTask, theme: Theme, width: number, current: boolean): string[] {
|
|
93
|
+
const open = task.blockedBy.filter((id) => !plan.tasks.some((item) => item.id === id && item.status === "done"));
|
|
94
|
+
const id = theme.fg("muted", open.length ? `${task.id} · after ${open.join(", ")}` : task.id);
|
|
95
|
+
// Accent means headings and labels, so the task the reader is on is bold text instead.
|
|
96
|
+
const title = theme.fg("text", task.title);
|
|
97
|
+
const [first = "", ...rest] = hanging(current ? theme.bold(title) : title, width, 2);
|
|
98
|
+
// The id sits beside the first row only, so that row loses the room the id and its gap take.
|
|
99
|
+
const room = Math.max(1, width - 3 - visibleWidth(id));
|
|
100
|
+
return [`${statusText(theme, task.status)} ${truncateToWidth(first, room, "…", true)} ${id}`, ...rest];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** An accent label padded into one column, then its value in the column beside it. */
|
|
104
|
+
function field(theme: Theme, label: string, value: string, width: number, prose = false): string[] {
|
|
105
|
+
const lead = ` ${theme.fg("accent", label.padEnd(9))} `;
|
|
106
|
+
const column = visibleWidth(lead);
|
|
107
|
+
const lines = prose
|
|
108
|
+
? markdown(theme, value, Math.max(1, width - column))
|
|
109
|
+
: wrapTextWithAnsi(theme.fg("text", value), Math.max(1, width - column));
|
|
110
|
+
const [first = "", ...rest] = lines;
|
|
111
|
+
return [lead + first, ...rest.map((line) => " ".repeat(column) + line)];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** One task: its title row, then the check, where and notes of every task still open. */
|
|
115
|
+
function taskBlock(
|
|
116
|
+
plan: Plan,
|
|
117
|
+
task: PlanTask,
|
|
118
|
+
theme: Theme,
|
|
119
|
+
width: number,
|
|
120
|
+
current: boolean,
|
|
121
|
+
expanded: boolean,
|
|
122
|
+
): string[] {
|
|
123
|
+
const head = taskLines(plan, task, theme, width, current);
|
|
124
|
+
if (!expanded && task.status === "done") return head;
|
|
125
|
+
return [
|
|
126
|
+
...head,
|
|
127
|
+
// Both labels pad to nine columns, so the two values start in one column.
|
|
128
|
+
...field(theme, "Done when", task.doneWhen, width, true),
|
|
129
|
+
...(task.where ? field(theme, "Where", task.where, width) : []),
|
|
130
|
+
...task.notes.flatMap((note) => ["", ...markdown(theme, note, Math.max(1, width - 2), 2)]),
|
|
131
|
+
"",
|
|
132
|
+
];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Goal, tasks and context as three sections; the headings show where the reader is in a long plan. */
|
|
136
|
+
function taskRows(plan: Plan, theme: Theme, width: number, expanded: boolean): string[] {
|
|
137
|
+
const current = plan.tasks.find((task) => task.status === "doing") ?? nextTask(plan);
|
|
138
|
+
const blocks = plan.tasks.flatMap((task) => taskBlock(plan, task, theme, width, task === current, expanded));
|
|
139
|
+
// The next heading brings its own leading blank line, so a task's trailing one would double it.
|
|
140
|
+
if (blocks.at(-1) === "") blocks.pop();
|
|
141
|
+
return [
|
|
142
|
+
...markdown(theme, plan.goal, width),
|
|
143
|
+
"",
|
|
144
|
+
section(theme, "Tasks", width, theme.fg("muted", ` ${planCount(plan)}`)),
|
|
145
|
+
...blocks,
|
|
146
|
+
"",
|
|
147
|
+
section(theme, "Context", width),
|
|
148
|
+
...markdown(theme, plan.context, width),
|
|
149
|
+
].map((line) => truncateToWidth(line, width, "…", true));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Two rows per plan, like pi-delegate's job rows: cursor, status glyph, name and count, then the goal. */
|
|
32
153
|
function sidebarRows(
|
|
33
154
|
plans: Plan[],
|
|
34
155
|
unreadable: string[],
|
|
35
156
|
selected: number,
|
|
36
157
|
active: string | undefined,
|
|
158
|
+
focus: Focus,
|
|
37
159
|
theme: Theme,
|
|
38
160
|
width: number,
|
|
39
161
|
height: number,
|
|
40
162
|
): { lines: string[]; indexes: (number | undefined)[] } {
|
|
41
|
-
const all: {
|
|
163
|
+
const all: { lines: string[]; index?: number }[] = [
|
|
42
164
|
...plans.map((plan, planIndex) => {
|
|
43
165
|
const chosen = planIndex === selected;
|
|
44
|
-
//
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
166
|
+
// The cursor dims while the detail pane takes the keys, so the user sees which pane is live.
|
|
167
|
+
const cursor = chosen ? theme.fg(focus === "list" ? "accent" : "muted", "›") : " ";
|
|
168
|
+
return {
|
|
169
|
+
lines: [
|
|
170
|
+
`${cursor} ${statusText(theme, planStatus(plan))} ${theme.fg(chosen ? "accent" : "text", plan.name)} ${theme.fg("muted", planCount(plan))}`,
|
|
171
|
+
theme.fg("dim", ` ${plan.name === active ? "active · " : ""}${plan.goal}`),
|
|
172
|
+
],
|
|
173
|
+
index: planIndex,
|
|
174
|
+
};
|
|
50
175
|
}),
|
|
51
|
-
...unreadable.map((name) => ({
|
|
176
|
+
...unreadable.map((name) => ({ lines: [theme.fg("error", ` ? ${name} unreadable`)] })),
|
|
52
177
|
];
|
|
53
|
-
const
|
|
54
|
-
const
|
|
178
|
+
const rows = all.flatMap((entry) => entry.lines.map((line, at) => ({ line, index: entry.index, head: at === 0 })));
|
|
179
|
+
const selectedRow = rows.findIndex((row) => row.index === selected);
|
|
180
|
+
let start = Math.max(0, Math.min(selectedRow - Math.floor(height / 2), rows.length - height));
|
|
181
|
+
// A window never opens on a plan's second row, which would show a goal with no name above it.
|
|
182
|
+
while (start > 0 && !rows[start]!.head) start--;
|
|
183
|
+
const shown = rows.slice(start, start + height);
|
|
55
184
|
return {
|
|
56
185
|
lines: [
|
|
57
186
|
...shown.map(
|
|
@@ -65,31 +194,18 @@ function sidebarRows(
|
|
|
65
194
|
};
|
|
66
195
|
}
|
|
67
196
|
|
|
68
|
-
|
|
69
|
-
const lines = [
|
|
70
|
-
...wrapTextWithAnsi(planSummary(theme, plan), width),
|
|
71
|
-
"",
|
|
72
|
-
...wrapTextWithAnsi(theme.fg("muted", `goal: ${plan.goal}`), width),
|
|
73
|
-
...(plan.context ? ["", ...wrapTextWithAnsi(theme.fg("muted", `context: ${plan.context}`), width)] : []),
|
|
74
|
-
"",
|
|
75
|
-
];
|
|
76
|
-
for (const task of plan.tasks) {
|
|
77
|
-
lines.push(...wrapTextWithAnsi(taskRow(theme, plan, task), width));
|
|
78
|
-
for (const fact of taskFacts(theme, task)) lines.push(...wrapTextWithAnsi(fact, width));
|
|
79
|
-
lines.push("");
|
|
80
|
-
}
|
|
81
|
-
return lines.map((line) => truncateToWidth(line, width, "…", true));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/** The /plan screen: every plan in the sidebar, the selected one's tasks on the right. */
|
|
197
|
+
/** The /plan screen, laid out like pi-delegate's: the plans on the left, the selected one's tasks on the right. */
|
|
85
198
|
export class PlansScreen implements Component {
|
|
86
199
|
private readonly options: PlansScreenOptions;
|
|
87
200
|
private index: number;
|
|
88
201
|
private active: string | undefined;
|
|
202
|
+
private focus: Focus = "list";
|
|
89
203
|
private top = 0;
|
|
204
|
+
private expanded = false;
|
|
90
205
|
private lastBody = { height: 0, total: 0 };
|
|
91
206
|
private lastIndexes: (number | undefined)[] = [];
|
|
92
207
|
private lastSidebar = 0;
|
|
208
|
+
private lastTextWidth = 0;
|
|
93
209
|
|
|
94
210
|
constructor(options: PlansScreenOptions) {
|
|
95
211
|
this.options = options;
|
|
@@ -98,7 +214,9 @@ export class PlansScreen implements Component {
|
|
|
98
214
|
this.index = Math.max(0, found);
|
|
99
215
|
}
|
|
100
216
|
|
|
101
|
-
invalidate() {
|
|
217
|
+
invalidate() {
|
|
218
|
+
MARKDOWN_CACHE.delete(this.options.theme);
|
|
219
|
+
}
|
|
102
220
|
|
|
103
221
|
render(width: number): string[] {
|
|
104
222
|
const { plans, unreadable, theme, height, keys } = this.options;
|
|
@@ -108,63 +226,113 @@ export class PlansScreen implements Component {
|
|
|
108
226
|
const detailWidth = Math.max(1, width - sidebarWidth - 1);
|
|
109
227
|
this.lastSidebar = sidebarWidth;
|
|
110
228
|
const row = (text: string, columns = width) => truncateToWidth(text, columns, "…", true);
|
|
229
|
+
const list = this.focus === "list";
|
|
111
230
|
const title = row(
|
|
112
|
-
`${theme.fg("accent"
|
|
231
|
+
`${theme.fg(list ? "accent" : "muted", list ? "[Plans]" : "Plans")} ` +
|
|
232
|
+
`${theme.fg(list ? "muted" : "accent", list ? "Tasks" : "[Tasks]")}` +
|
|
233
|
+
theme.fg("dim", ` · ${plans.length + unreadable.length} in .pi/plans`),
|
|
113
234
|
);
|
|
114
235
|
const rule = theme.fg("borderMuted", "─".repeat(Math.max(0, width)));
|
|
236
|
+
// Always-on keys first, so the pane's own hints can spill off a narrow line.
|
|
237
|
+
const paneHints = list
|
|
238
|
+
? hint(keys, ["tui.select.up", "tui.select.down"], "select plan")
|
|
239
|
+
: `${hint(keys, ["tui.select.up", "tui.select.down"], "scroll")} · ${hint(keys, ["tui.altScreen.pageUp", "tui.altScreen.pageDown"], "page")}`;
|
|
115
240
|
const footer = row(
|
|
116
241
|
theme.fg(
|
|
117
242
|
"dim",
|
|
118
243
|
[
|
|
119
|
-
|
|
244
|
+
rawKeyHint("←/→", "pane"),
|
|
120
245
|
hint(keys, ["tui.select.confirm"], "make active"),
|
|
121
|
-
hint(keys, ["tui.altScreen.pageUp", "tui.altScreen.pageDown"], "scroll"),
|
|
122
246
|
hint(keys, ["tui.select.cancel"], "close"),
|
|
247
|
+
hint(keys, ["app.tools.expand"], this.expanded ? "collapse" : "expand"),
|
|
248
|
+
paneHints,
|
|
123
249
|
].join(" · "),
|
|
124
250
|
),
|
|
125
251
|
);
|
|
126
252
|
const plan = plans[this.index];
|
|
127
|
-
const sidebar = sidebarRows(plans, unreadable, this.index, this.active, theme, sidebarWidth, body);
|
|
253
|
+
const sidebar = sidebarRows(plans, unreadable, this.index, this.active, this.focus, theme, sidebarWidth, body);
|
|
128
254
|
this.lastIndexes = sidebar.indexes;
|
|
129
255
|
const detail = plan
|
|
130
|
-
?
|
|
256
|
+
? this.detail(plan, Math.min(detailWidth, MAX_TEXT_WIDTH), detailWidth, body)
|
|
131
257
|
: [row(theme.fg("muted", "No readable plans."), detailWidth)];
|
|
132
|
-
|
|
133
|
-
this.top = start;
|
|
134
|
-
this.lastBody = { height: body, total: detail.length };
|
|
135
|
-
const shown = detail.slice(start, start + body);
|
|
136
|
-
const right = [...shown, ...Array(Math.max(0, body - shown.length)).fill("")];
|
|
137
|
-
return [title, rule, ...sidebar.lines.map((line, index) => `${line} ${right[index] ?? ""}`), rule, footer];
|
|
258
|
+
return [title, rule, ...sidebar.lines.map((line, index) => `${line} ${detail[index] ?? ""}`), rule, footer];
|
|
138
259
|
}
|
|
139
260
|
|
|
140
261
|
handleInput(data: string): void {
|
|
141
262
|
const { keys, onClose, setActive } = this.options;
|
|
263
|
+
const detail = this.focus === "detail";
|
|
142
264
|
if (keys.matches(data, "tui.select.cancel")) onClose();
|
|
143
|
-
else if (
|
|
144
|
-
else if (
|
|
265
|
+
else if (matchesKey(data, "left")) this.focus = "list";
|
|
266
|
+
else if (matchesKey(data, "right")) this.focus = "detail";
|
|
145
267
|
else if (keys.matches(data, "tui.select.confirm")) {
|
|
146
268
|
const plan = this.options.plans[this.index];
|
|
147
269
|
if (!plan) return;
|
|
148
270
|
this.active = plan.name;
|
|
149
271
|
setActive(plan.name);
|
|
150
|
-
} else if (keys.matches(data, "
|
|
151
|
-
|
|
272
|
+
} else if (keys.matches(data, "app.tools.expand")) {
|
|
273
|
+
this.expanded = !this.expanded;
|
|
274
|
+
this.top = 0;
|
|
275
|
+
} else if (detail && keys.matches(data, "tui.altScreen.pageUp")) this.scroll(-this.pageSize());
|
|
276
|
+
else if (detail && keys.matches(data, "tui.altScreen.pageDown")) this.scroll(this.pageSize());
|
|
277
|
+
else if (detail && keys.matches(data, "tui.altScreen.top")) this.top = 0;
|
|
278
|
+
else if (detail && keys.matches(data, "tui.altScreen.bottom")) this.top = Infinity;
|
|
279
|
+
else if (keys.matches(data, "tui.select.up")) this.move(-1);
|
|
280
|
+
else if (keys.matches(data, "tui.select.down")) this.move(1);
|
|
152
281
|
this.options.requestRender();
|
|
153
282
|
}
|
|
154
283
|
|
|
155
284
|
// Fullscreen turns on mouse tracking, so the wheel arrives here instead of as arrow keys.
|
|
156
285
|
handleMouse(event: TuiMouseEvent) {
|
|
157
|
-
if (event.type === "wheel" && event.wheelDelta)
|
|
158
|
-
|
|
286
|
+
if (event.type === "wheel" && event.wheelDelta) {
|
|
287
|
+
if (event.x < this.lastSidebar) this.select(event.wheelDelta < 0 ? -1 : 1);
|
|
288
|
+
else this.scroll(event.wheelDelta);
|
|
289
|
+
} else if (event.type === "click" && event.button === "left" && event.x < this.lastSidebar) {
|
|
159
290
|
const target = this.lastIndexes[event.y - 2];
|
|
160
291
|
if (event.y < 2 || event.y - 2 >= this.lastBody.height || target === undefined) return;
|
|
161
292
|
this.index = target;
|
|
162
293
|
this.top = 0;
|
|
163
|
-
} else
|
|
294
|
+
} else if (event.type === "click" && event.button === "left") this.focus = "detail";
|
|
295
|
+
else return;
|
|
164
296
|
this.options.requestRender();
|
|
165
297
|
return { handled: true };
|
|
166
298
|
}
|
|
167
299
|
|
|
300
|
+
/** The right pane: the plan's name stays put over the goal, tasks and context, with a counter below. */
|
|
301
|
+
private detail(plan: Plan, textWidth: number, width: number, body: number): string[] {
|
|
302
|
+
const { theme } = this.options;
|
|
303
|
+
if (this.lastTextWidth !== textWidth) {
|
|
304
|
+
this.lastTextWidth = textWidth;
|
|
305
|
+
MARKDOWN_CACHE.delete(theme);
|
|
306
|
+
}
|
|
307
|
+
const blocked = plan.tasks.some((task) => task.status === "blocked") ? " · blocked" : "";
|
|
308
|
+
const progress = theme.fg("muted", `${doneCount(plan)} of ${plan.tasks.length} done${blocked}`);
|
|
309
|
+
const name = theme.fg("accent", plan.name);
|
|
310
|
+
const header = [
|
|
311
|
+
name + " ".repeat(Math.max(0, textWidth - visibleWidth(name) - visibleWidth(progress))) + progress,
|
|
312
|
+
];
|
|
313
|
+
const height = Math.max(0, body - header.length - 1);
|
|
314
|
+
const all = taskRows(plan, theme, textWidth, this.expanded);
|
|
315
|
+
const start = Math.min(this.top, Math.max(0, all.length - height));
|
|
316
|
+
this.top = start;
|
|
317
|
+
this.lastBody = { height, total: all.length };
|
|
318
|
+
const shown = all.slice(start, start + height);
|
|
319
|
+
const counter = theme.fg(
|
|
320
|
+
"muted",
|
|
321
|
+
shown.length ? `${start + 1}–${start + shown.length}/${all.length}` : `0/${all.length}`,
|
|
322
|
+
);
|
|
323
|
+
// Right-aligned like pi-delegate's counter; every row is padded so the pane's right edge holds still.
|
|
324
|
+
const tail = " ".repeat(Math.max(0, width - visibleWidth(counter))) + counter;
|
|
325
|
+
return [...header, ...shown, ...Array(Math.max(0, height - shown.length)).fill(""), tail].map((line) =>
|
|
326
|
+
truncateToWidth(line, width, "…", true),
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// Detail focus scrolls by a line; list focus moves the cursor.
|
|
331
|
+
private move(step: number) {
|
|
332
|
+
if (this.focus === "detail") this.scroll(step);
|
|
333
|
+
else this.select(step);
|
|
334
|
+
}
|
|
335
|
+
|
|
168
336
|
private select(step: number) {
|
|
169
337
|
this.index = Math.max(0, Math.min(this.options.plans.length - 1, this.index + step));
|
|
170
338
|
this.top = 0;
|
package/src/store.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process";
|
|
2
2
|
import { appendFileSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, join, resolve } from "node:path";
|
|
4
|
-
import type { KeybindingHints, Theme } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import type { KeybindingHints, Theme, ThemeColor } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import { wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
5
6
|
|
|
6
7
|
export const STATUSES = ["todo", "doing", "done", "blocked"] as const;
|
|
7
8
|
|
|
@@ -218,13 +219,35 @@ export function taskRow(theme: Theme, plan: Plan, task: PlanTask): string {
|
|
|
218
219
|
return `${statusText(theme, task.status)} ${theme.fg("accent", task.id)} ${task.title}${blocked}`;
|
|
219
220
|
}
|
|
220
221
|
|
|
221
|
-
/**
|
|
222
|
-
export function
|
|
222
|
+
/** Wrapped rows whose continuations sit `indent` columns in, so a wrapped line never reads as a new one. */
|
|
223
|
+
export function hanging(text: string, width: number, indent: number): string[] {
|
|
224
|
+
return wrapTextWithAnsi(text, Math.max(1, width - indent)).map(
|
|
225
|
+
(line, index) => (index ? " ".repeat(indent) : "") + line,
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** 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. */
|
|
230
|
+
export function fact(
|
|
231
|
+
theme: Theme,
|
|
232
|
+
label: string,
|
|
233
|
+
text: string,
|
|
234
|
+
width: number,
|
|
235
|
+
indent = 2,
|
|
236
|
+
color: ThemeColor = label ? "text" : "dim",
|
|
237
|
+
): string[] {
|
|
238
|
+
return hanging((label ? theme.fg("muted", label) : "") + theme.fg(color, text), width - indent, label.length).map(
|
|
239
|
+
(line) => " ".repeat(indent) + line,
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** The lines under a task row: where it lives, its check, and its dim notes as written. */
|
|
244
|
+
export function taskFacts(theme: Theme, task: PlanTask, width: number): string[] {
|
|
223
245
|
return [
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
...
|
|
227
|
-
|
|
246
|
+
// Paths are reference, not the point of the task; the check is.
|
|
247
|
+
...(task.where ? fact(theme, "Where: ", task.where, width, 2, "dim") : []),
|
|
248
|
+
...fact(theme, "Done when: ", task.doneWhen, width),
|
|
249
|
+
...task.notes.flatMap((note) => fact(theme, "", note, width)),
|
|
250
|
+
];
|
|
228
251
|
}
|
|
229
252
|
|
|
230
253
|
/** pi's built-in expand hint; callers place it on its own row, so it carries no leading newline. */
|