@timmyjl12/pi-subagents 0.20.0 → 0.21.1
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/CHANGELOG.md +862 -827
- package/README.md +1125 -1080
- package/dist/active-agents-prompt.d.ts +31 -9
- package/dist/active-agents-prompt.js +73 -9
- package/dist/agent-color.js +9 -1
- package/dist/agent-file-toggle.d.ts +1 -1
- package/dist/agent-manager.d.ts +405 -18
- package/dist/agent-manager.js +1661 -131
- package/dist/agent-runner.d.ts +45 -6
- package/dist/agent-runner.js +109 -18
- package/dist/agent-types.d.ts +30 -7
- package/dist/agent-types.js +38 -9
- package/dist/awaited-result.d.ts +37 -0
- package/dist/awaited-result.js +150 -0
- package/dist/child-session-shutdown.d.ts +19 -1
- package/dist/child-session-shutdown.js +60 -11
- package/dist/cleanup-plans.d.ts +10 -0
- package/dist/cleanup-plans.js +112 -0
- package/dist/cross-extension-rpc.d.ts +8 -1
- package/dist/cross-extension-rpc.js +59 -5
- package/dist/custom-agents.d.ts +34 -9
- package/dist/custom-agents.js +308 -111
- package/dist/default-agents.d.ts +1 -1
- package/dist/env.d.ts +1 -1
- package/dist/error-log.d.ts +6 -0
- package/dist/error-log.js +8 -0
- package/dist/force-main-model.d.ts +21 -0
- package/dist/force-main-model.js +28 -0
- package/dist/goal-bridge.d.ts +155 -0
- package/dist/goal-bridge.js +305 -0
- package/dist/group-join.d.ts +5 -1
- package/dist/group-join.js +52 -7
- package/dist/index.d.ts +5 -5
- package/dist/index.js +2827 -333
- package/dist/invocation-config.d.ts +30 -3
- package/dist/invocation-config.js +30 -1
- package/dist/memory.d.ts +1 -1
- package/dist/mention-clone.d.ts +1 -1
- package/dist/model-scope.d.ts +1 -1
- package/dist/nested-tools.d.ts +22 -1
- package/dist/nested-tools.js +120 -26
- package/dist/output-file.d.ts +15 -4
- package/dist/output-file.js +146 -43
- package/dist/prompts.d.ts +1 -1
- package/dist/recovery.d.ts +1 -1
- package/dist/report-cleanup.d.ts +204 -0
- package/dist/report-cleanup.js +1632 -0
- package/dist/report-store.d.ts +738 -0
- package/dist/report-store.js +3616 -0
- package/dist/schedule-store.d.ts +14 -6
- package/dist/schedule-store.js +88 -58
- package/dist/schedule.d.ts +20 -8
- package/dist/schedule.js +135 -74
- package/dist/settings.d.ts +39 -11
- package/dist/settings.js +22 -5
- package/dist/status-note.d.ts +1 -1
- package/dist/structured-output.d.ts +1 -1
- package/dist/types.d.ts +32 -3
- package/dist/ui/agent-mention.d.ts +2 -2
- package/dist/ui/agent-widget.d.ts +82 -13
- package/dist/ui/agent-widget.js +155 -37
- package/dist/ui/cleanup-preview.d.ts +59 -0
- package/dist/ui/cleanup-preview.js +466 -0
- package/dist/ui/conversation-viewer.d.ts +4 -4
- package/dist/ui/conversation-viewer.js +10 -6
- package/dist/ui/fleet-list.d.ts +3 -3
- package/dist/ui/fleet-list.js +3 -3
- package/dist/ui/fleet-overlay.d.ts +37 -6
- package/dist/ui/fleet-overlay.js +214 -18
- package/dist/ui/hub-feed.d.ts +52 -0
- package/dist/ui/hub-feed.js +148 -0
- package/dist/ui/native-transcript.js +5 -1
- package/dist/ui/schedule-menu.d.ts +1 -1
- package/dist/ui/schedule-menu.js +1 -1
- package/dist/ui/workflow-card.d.ts +4 -4
- package/dist/ui/workflow-dialog.d.ts +4 -4
- package/dist/ui/workflow-dialog.js +8 -3
- package/dist/ui/workflow-menu.d.ts +2 -2
- package/dist/usage.d.ts +12 -0
- package/dist/usage.js +28 -1
- package/dist/workflow/entry.d.ts +3 -3
- package/dist/workflow/host.d.ts +7 -4
- package/dist/workflow/host.js +162 -48
- package/dist/workflow/journal.d.ts +23 -7
- package/dist/workflow/journal.js +80 -23
- package/dist/workflow/progress.d.ts +1 -1
- package/dist/workflow/runtime.d.ts +45 -6
- package/dist/workflow/runtime.js +105 -16
- package/dist/workflow/task.d.ts +13 -4
- package/dist/workflow/task.js +7 -1
- package/dist/workflow/tool-description.d.ts +7 -2
- package/dist/workflow/tool-description.js +10 -5
- package/docs/{FORK.md → DEVELOPMENT.md} +4 -4
- package/docs/artifacts.md +93 -0
- package/docs/rpc.md +252 -189
- package/docs/runtime-performance.md +53 -0
- package/docs/workflows.md +48 -18
- package/examples/agent-tool-description.md +2 -2
- package/examples/workflows/review-panel.js +6 -3
- package/package.json +5 -5
- package/src/active-agents-prompt.ts +115 -39
- package/src/agent-color.ts +10 -2
- package/src/agent-file-toggle.ts +2 -2
- package/src/agent-manager.ts +3312 -1601
- package/src/agent-runner.ts +164 -36
- package/src/agent-types.ts +56 -11
- package/src/awaited-result.ts +187 -0
- package/src/child-session-shutdown.ts +114 -46
- package/src/cleanup-plans.ts +112 -0
- package/src/cross-extension-rpc.ts +68 -9
- package/src/custom-agents.ts +384 -112
- package/src/default-agents.ts +1 -1
- package/src/enabled-models.ts +1 -1
- package/src/env.ts +1 -1
- package/src/error-log.ts +10 -1
- package/src/force-main-model.ts +29 -0
- package/src/goal-bridge.ts +468 -0
- package/src/group-join.ts +56 -9
- package/src/index.ts +2987 -349
- package/src/invocation-config.ts +50 -4
- package/src/memory.ts +1 -1
- package/src/mention-clone.ts +3 -3
- package/src/model-scope.ts +1 -1
- package/src/nested-tools.ts +164 -33
- package/src/output-file.ts +168 -46
- package/src/prompts.ts +1 -1
- package/src/recovery.ts +2 -2
- package/src/report-cleanup.ts +2044 -0
- package/src/report-store.ts +4133 -0
- package/src/schedule-store.ts +244 -201
- package/src/schedule.ts +144 -80
- package/src/settings.ts +61 -16
- package/src/skill-loader.ts +1 -1
- package/src/standalone-fallback.ts +2 -2
- package/src/status-note.ts +1 -1
- package/src/structured-output.ts +1 -1
- package/src/types.ts +33 -3
- package/src/ui/agent-mention.ts +3 -3
- package/src/ui/agent-widget.ts +179 -45
- package/src/ui/cleanup-preview.ts +518 -0
- package/src/ui/conversation-viewer.ts +19 -15
- package/src/ui/fleet-list.ts +7 -7
- package/src/ui/fleet-overlay.ts +1048 -847
- package/src/ui/hub-feed.ts +179 -0
- package/src/ui/native-transcript.ts +7 -3
- package/src/ui/schedule-menu.ts +4 -4
- package/src/ui/workflow-card.ts +4 -4
- package/src/ui/workflow-dialog.ts +10 -6
- package/src/ui/workflow-menu.ts +4 -4
- package/src/usage.ts +53 -3
- package/src/workflow/collisions.ts +1 -1
- package/src/workflow/entry.ts +3 -3
- package/src/workflow/host.ts +174 -54
- package/src/workflow/journal.ts +80 -23
- package/src/workflow/progress.ts +1 -1
- package/src/workflow/runtime.ts +146 -23
- package/src/workflow/saved.ts +3 -3
- package/src/workflow/task.ts +18 -7
- package/src/workflow/tool-description.ts +10 -5
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cleanup-preview.ts — the `/subagents cleanup` review surface.
|
|
3
|
+
*
|
|
4
|
+
* Two exports, one job: let the user INSPECT a `CleanupPlan` before anything
|
|
5
|
+
* irreversible happens. `formatCleanupPreview` is the plan as plain text —
|
|
6
|
+
* every candidate path, every count, every read flag, every skip, no cap and
|
|
7
|
+
* no subset — and is what a headless caller can print. `showCleanupPreview`
|
|
8
|
+
* puts that same text behind a native-TUI overlay and reports whether the
|
|
9
|
+
* review finished with an explicit Continue.
|
|
10
|
+
*
|
|
11
|
+
* The module is deliberately inert: it never unlinks, prepares, consumes, or
|
|
12
|
+
* even READS the filesystem, and it never asks the deletion question. `true`
|
|
13
|
+
* means only "the user reviewed the plan and chose Continue"; the parent owns
|
|
14
|
+
* the separate `ctx.ui.confirm` gate (and the legacy extra confirmation) and
|
|
15
|
+
* everything that follows it. Esc, cancel, a closed dry run, or any UI that
|
|
16
|
+
* cannot show the preview all resolve `false` — no terminal, no consent.
|
|
17
|
+
*
|
|
18
|
+
* Rendering follows the conversation viewer rather than inventing a layer:
|
|
19
|
+
* the full text lives in a `Text` child, a `ScrollView` holds the scroll
|
|
20
|
+
* state (`updateLayout` + `scrollTop`), and `render` slices the visible
|
|
21
|
+
* window itself — the local `ScrollView` has no height option, and bounded
|
|
22
|
+
* composition through `LAYOUT_NODE` is the fullscreen layout's job, not an
|
|
23
|
+
* overlay's. The whole list stays reachable: page/line/home/end keys scroll
|
|
24
|
+
* to either end, so the tail of `plan.files`/`plan.skipped` is always
|
|
25
|
+
* inspectable. Scroll/confirm/cancel keys come from the injected
|
|
26
|
+
* `KeybindingsManager` where one is available (same `tui.select.*` resolution
|
|
27
|
+
* as the viewer), with enter/escape kept as reflex fallbacks so the gate is
|
|
28
|
+
* never inoperable.
|
|
29
|
+
*
|
|
30
|
+
* Paths are user data drawn on a terminal: backslashes are doubled and
|
|
31
|
+
* C0/C1/DEL characters use `\xNN` escapes, so paths cannot inject controls and
|
|
32
|
+
* no character goes missing. Unicode width, wrapping, and resizing are left
|
|
33
|
+
* to pi-tui's width utilities and the `Text` wrapper.
|
|
34
|
+
*/
|
|
35
|
+
import { isKeyRelease, matchesKey, ScrollView, Text, truncateToWidth, visibleWidth, wrapTextWithAnsi, } from "@earendil-works/pi-tui";
|
|
36
|
+
import { cleanupReadStateLabel, isCleanupPlanEmpty, } from "../report-cleanup.js";
|
|
37
|
+
import { createViewerKeys } from "./viewer-keys.js";
|
|
38
|
+
/**
|
|
39
|
+
* Show control characters as `\xNN` instead of emitting them.
|
|
40
|
+
*
|
|
41
|
+
* A report path is drawn verbatim inside a terminal frame; a raw ESC or BEL
|
|
42
|
+
* in one would inject terminal control sequences into the preview itself.
|
|
43
|
+
* The escaping is per code point and reversible, so the display loses no
|
|
44
|
+
* data — it just cannot execute.
|
|
45
|
+
*/
|
|
46
|
+
function escapeDisplay(value) {
|
|
47
|
+
let out = "";
|
|
48
|
+
for (const ch of value) {
|
|
49
|
+
const code = ch.codePointAt(0) ?? 0;
|
|
50
|
+
if (ch === "\\") {
|
|
51
|
+
out += "\\\\";
|
|
52
|
+
}
|
|
53
|
+
else if (code < 0x20 || (code >= 0x7f && code <= 0x9f)) {
|
|
54
|
+
out += `\\x${code.toString(16).toUpperCase().padStart(2, "0")}`;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
out += ch;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
/** 1024-based, one decimal under 100 — `512 B`, `1.5 KB`, `340 MB`. */
|
|
63
|
+
function formatBytes(bytes) {
|
|
64
|
+
if (!Number.isFinite(bytes) || bytes <= 0)
|
|
65
|
+
return "0 B";
|
|
66
|
+
if (bytes < 1024)
|
|
67
|
+
return `${bytes} B`;
|
|
68
|
+
const units = ["KB", "MB", "GB", "TB"];
|
|
69
|
+
let value = bytes;
|
|
70
|
+
let unit = -1;
|
|
71
|
+
do {
|
|
72
|
+
value /= 1024;
|
|
73
|
+
unit++;
|
|
74
|
+
} while (value >= 1024 && unit < units.length - 1);
|
|
75
|
+
const rounded = value >= 100 ? String(Math.round(value)) : value.toFixed(1).replace(/\.0$/, "");
|
|
76
|
+
return `${rounded} ${units[unit]}`;
|
|
77
|
+
}
|
|
78
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
79
|
+
/** One line per file: size and kind as aligned columns, then state, flags, path. */
|
|
80
|
+
function fileLine(file, sizeWidth, kindWidth) {
|
|
81
|
+
const flags = [file.legacy ? "legacy" : "", file.shared ? "shared" : ""].filter(Boolean).join(" ");
|
|
82
|
+
const head = `${formatBytes(file.size).padEnd(sizeWidth)} ${file.kind.padEnd(kindWidth)} ${cleanupReadStateLabel(file.readState)}`;
|
|
83
|
+
return ` ${head}${flags ? ` ${flags}` : ""} ${escapeDisplay(file.path)}`;
|
|
84
|
+
}
|
|
85
|
+
/** One line per skip: the reason first — it is why the file survives — then identity, then path. */
|
|
86
|
+
function skipLine(skip) {
|
|
87
|
+
const tags = [];
|
|
88
|
+
if (skip.kind)
|
|
89
|
+
tags.push(skip.kind);
|
|
90
|
+
if (skip.agentId)
|
|
91
|
+
tags.push(`agent ${escapeDisplay(skip.agentId)}`);
|
|
92
|
+
if (skip.workflowId)
|
|
93
|
+
tags.push(`workflow ${escapeDisplay(skip.workflowId)}`);
|
|
94
|
+
if (skip.rootSessionId)
|
|
95
|
+
tags.push(`root ${escapeDisplay(skip.rootSessionId)}`);
|
|
96
|
+
if (skip.legacy)
|
|
97
|
+
tags.push("legacy");
|
|
98
|
+
const identity = tags.length > 0 ? ` (${tags.join(", ")})` : "";
|
|
99
|
+
const path = skip.path ? ` — ${escapeDisplay(skip.path)}` : "";
|
|
100
|
+
return ` ${escapeDisplay(skip.reason)}${identity}${path}`;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The whole plan as ordered lines. Nothing is capped, windowed, or sampled:
|
|
104
|
+
* `plan.files` and `plan.skipped` map one-to-one onto lines here, and the
|
|
105
|
+
* counts are the plan's own rather than a recomputation that could drift.
|
|
106
|
+
*/
|
|
107
|
+
function buildCleanupPreviewLines(plan) {
|
|
108
|
+
const lines = [];
|
|
109
|
+
const counts = plan.counts;
|
|
110
|
+
lines.push({ text: `Cleanup preview — ${plan.scope} scope`, tone: "title", fixed: true });
|
|
111
|
+
lines.push({ text: "Preview only — no changes have been made.", tone: "dim", fixed: true });
|
|
112
|
+
lines.push({ text: "Your own session history is never a cleanup candidate.", tone: "dim", fixed: true });
|
|
113
|
+
lines.push({ text: "Paths escape backslashes as \\\\ and control characters as \\xNN.", tone: "dim" });
|
|
114
|
+
const created = new Date(plan.createdAt).toISOString();
|
|
115
|
+
lines.push({
|
|
116
|
+
text: `Plan ${escapeDisplay(plan.planId)} · created ${created} · ${plural(plan.roots.length, "root")}`,
|
|
117
|
+
tone: "dim",
|
|
118
|
+
});
|
|
119
|
+
if (plan.identityUncertainty) {
|
|
120
|
+
lines.push({
|
|
121
|
+
text: `Identity uncertainty: ${escapeDisplay(plan.identityUncertainty)} — child-history candidates were refused.`,
|
|
122
|
+
tone: "warning",
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
lines.push({ text: "", tone: "plain" });
|
|
126
|
+
lines.push({ text: `Summary — ${plural(counts.files, "file")} · ${formatBytes(counts.bytes)}`, tone: "heading" });
|
|
127
|
+
lines.push({
|
|
128
|
+
text: ` ${plural(counts.reports, "report")} · task outputs ${counts.taskOutputs} · workflow files ${counts.workflowFiles} · child sessions ${counts.childSessions}`,
|
|
129
|
+
tone: "plain",
|
|
130
|
+
});
|
|
131
|
+
lines.push({
|
|
132
|
+
text: ` legacy ${counts.legacy} · diagnostics ${counts.diagnostics} · root metadata ${counts.rootMetadata}`,
|
|
133
|
+
tone: "plain",
|
|
134
|
+
});
|
|
135
|
+
const unreadNote = counts.unread > 0 ? " (not marked as read)" : "";
|
|
136
|
+
lines.push({
|
|
137
|
+
text: ` read state: ${plural(counts.unread, "unread artifact")}${unreadNote} · ${counts.unknownReadState} ${cleanupReadStateLabel("unknown")}`,
|
|
138
|
+
tone: counts.unread > 0 || counts.unknownReadState > 0 ? "warning" : "plain",
|
|
139
|
+
});
|
|
140
|
+
lines.push({ text: "", tone: "plain" });
|
|
141
|
+
if (plan.files.length === 0) {
|
|
142
|
+
lines.push({ text: "Files: none — nothing is eligible for cleanup.", tone: "dim" });
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
lines.push({ text: `Files (${plan.files.length}):`, tone: "heading" });
|
|
146
|
+
let sizeWidth = 0;
|
|
147
|
+
let kindWidth = 0;
|
|
148
|
+
for (const file of plan.files) {
|
|
149
|
+
sizeWidth = Math.max(sizeWidth, formatBytes(file.size).length);
|
|
150
|
+
kindWidth = Math.max(kindWidth, file.kind.length);
|
|
151
|
+
}
|
|
152
|
+
for (const file of plan.files) {
|
|
153
|
+
lines.push({ text: fileLine(file, sizeWidth, kindWidth), tone: "plain" });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
lines.push({ text: "", tone: "plain" });
|
|
157
|
+
if (plan.skipped.length === 0) {
|
|
158
|
+
lines.push({ text: "Skipped: none.", tone: "dim" });
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
lines.push({ text: `Skipped (${plan.skipped.length}):`, tone: "heading" });
|
|
162
|
+
for (const skip of plan.skipped) {
|
|
163
|
+
lines.push({ text: skipLine(skip), tone: "plain" });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return lines;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* The complete cleanup preview as plain text: scope, preview-only header,
|
|
170
|
+
* counts and bytes, read flags, every candidate path, and every skip.
|
|
171
|
+
*
|
|
172
|
+
* Pure — same plan in, same string out, no filesystem, no clock beyond the
|
|
173
|
+
* plan's own `createdAt`. This is also the text a non-TUI caller can print,
|
|
174
|
+
* so nothing the overlay shows exists only in the overlay.
|
|
175
|
+
*/
|
|
176
|
+
export function formatCleanupPreview(plan) {
|
|
177
|
+
return buildCleanupPreviewLines(plan).map(line => line.text).join("\n");
|
|
178
|
+
}
|
|
179
|
+
/** Apply a tone with the active theme. Neutral by default; `warning` only for warnings. */
|
|
180
|
+
function styleLine(theme, line) {
|
|
181
|
+
switch (line.tone) {
|
|
182
|
+
case "title":
|
|
183
|
+
return theme.bold(line.text);
|
|
184
|
+
case "heading":
|
|
185
|
+
return theme.bold(theme.fg("muted", line.text));
|
|
186
|
+
case "dim":
|
|
187
|
+
return theme.fg("dim", line.text);
|
|
188
|
+
case "warning":
|
|
189
|
+
return theme.fg("warning", line.text);
|
|
190
|
+
default:
|
|
191
|
+
return line.text;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/** Short display names for the keys a footer advertises. */
|
|
195
|
+
function keyLabel(id) {
|
|
196
|
+
switch (id) {
|
|
197
|
+
case "escape":
|
|
198
|
+
case "esc":
|
|
199
|
+
return "esc";
|
|
200
|
+
case "enter":
|
|
201
|
+
case "return":
|
|
202
|
+
return "enter";
|
|
203
|
+
case "up":
|
|
204
|
+
return "↑";
|
|
205
|
+
case "down":
|
|
206
|
+
return "↓";
|
|
207
|
+
case "pageUp":
|
|
208
|
+
return "PgUp";
|
|
209
|
+
case "pageDown":
|
|
210
|
+
return "PgDn";
|
|
211
|
+
case "home":
|
|
212
|
+
return "Home";
|
|
213
|
+
case "end":
|
|
214
|
+
return "End";
|
|
215
|
+
default:
|
|
216
|
+
return id;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* The overlay component. One instance per `ctx.ui.custom` call; the
|
|
221
|
+
* interaction ends only through `done`, never through an overlay handle.
|
|
222
|
+
*/
|
|
223
|
+
class CleanupPreview {
|
|
224
|
+
tui;
|
|
225
|
+
theme;
|
|
226
|
+
keybindings;
|
|
227
|
+
plan;
|
|
228
|
+
dryRun;
|
|
229
|
+
done;
|
|
230
|
+
closed = false;
|
|
231
|
+
reviewable = false;
|
|
232
|
+
text;
|
|
233
|
+
scroll;
|
|
234
|
+
keys;
|
|
235
|
+
fixedLines;
|
|
236
|
+
bodyLines;
|
|
237
|
+
styledBodyCache;
|
|
238
|
+
lastStyledBody;
|
|
239
|
+
contentTop = 0;
|
|
240
|
+
constructor(tui, theme, keybindings, plan, dryRun, done) {
|
|
241
|
+
this.tui = tui;
|
|
242
|
+
this.theme = theme;
|
|
243
|
+
this.keybindings = keybindings;
|
|
244
|
+
this.plan = plan;
|
|
245
|
+
this.dryRun = dryRun;
|
|
246
|
+
this.done = done;
|
|
247
|
+
const lines = buildCleanupPreviewLines(plan);
|
|
248
|
+
this.fixedLines = lines.filter(line => line.fixed);
|
|
249
|
+
this.bodyLines = lines.filter(line => !line.fixed);
|
|
250
|
+
this.text = new Text("", 0, 0);
|
|
251
|
+
this.scroll = new ScrollView(this.text, { follow: "none", scrollbar: "hidden", overscroll: "contain" });
|
|
252
|
+
this.keys = createViewerKeys(keybindings);
|
|
253
|
+
}
|
|
254
|
+
handleInput(data) {
|
|
255
|
+
if (this.closed || isKeyRelease(data))
|
|
256
|
+
return;
|
|
257
|
+
if (this.isCancel(data)) {
|
|
258
|
+
this.close(false);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (this.isConfirm(data)) {
|
|
262
|
+
// The ONLY path that resolves true: an explicit Continue in normal
|
|
263
|
+
// mode. A dry run closes — it never consents.
|
|
264
|
+
this.close(!this.dryRun && this.reviewable);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (this.keys.scrollUp(data))
|
|
268
|
+
this.scroll.scrollBy(-1);
|
|
269
|
+
else if (this.keys.scrollDown(data))
|
|
270
|
+
this.scroll.scrollBy(1);
|
|
271
|
+
else if (this.keys.pageUp(data))
|
|
272
|
+
this.scroll.scrollBy(-Math.max(1, this.scroll.viewportHeight));
|
|
273
|
+
else if (this.keys.pageDown(data))
|
|
274
|
+
this.scroll.scrollBy(Math.max(1, this.scroll.viewportHeight));
|
|
275
|
+
else if (this.isBoundary(data, "top"))
|
|
276
|
+
this.scroll.scrollToStart();
|
|
277
|
+
else if (this.isBoundary(data, "bottom"))
|
|
278
|
+
this.scroll.scrollToEnd();
|
|
279
|
+
else
|
|
280
|
+
return;
|
|
281
|
+
this.tui.requestRender();
|
|
282
|
+
}
|
|
283
|
+
render(width) {
|
|
284
|
+
this.reviewable = false;
|
|
285
|
+
const rows = Math.max(0, this.tui.terminal.rows);
|
|
286
|
+
if (width < 6 || rows === 0)
|
|
287
|
+
return [];
|
|
288
|
+
const th = this.theme;
|
|
289
|
+
const innerW = width - 4;
|
|
290
|
+
const lines = [];
|
|
291
|
+
const pad = (s, len) => {
|
|
292
|
+
const vis = visibleWidth(s);
|
|
293
|
+
return s + " ".repeat(Math.max(0, len - vis));
|
|
294
|
+
};
|
|
295
|
+
const row = (content) => th.fg("border", "│") + " " + truncateToWidth(pad(content, innerW), innerW, "...", true) + " " + th.fg("border", "│");
|
|
296
|
+
const hrTop = th.fg("border", `╭${"─".repeat(width - 2)}╮`);
|
|
297
|
+
const hrBot = th.fg("border", `╰${"─".repeat(width - 2)}╯`);
|
|
298
|
+
const hrMid = row(th.fg("dim", "─".repeat(Math.max(0, innerW))));
|
|
299
|
+
lines.push(hrTop);
|
|
300
|
+
// Fixed chrome: the preview-only header, then the mode line. Wrapped, not
|
|
301
|
+
// truncated — the warning's unread count must survive a narrow terminal.
|
|
302
|
+
for (const line of [...this.fixedLines, ...this.modeLines()]) {
|
|
303
|
+
for (const wrapped of wrapTextWithAnsi(styleLine(th, line), Math.max(1, innerW))) {
|
|
304
|
+
lines.push(row(wrapped));
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
lines.push(hrMid);
|
|
308
|
+
// Keep the frame inside the terminal; the scroll region gets what is left.
|
|
309
|
+
const footerRows = rows >= 4 ? 2 : 0;
|
|
310
|
+
const viewportHeight = Math.max(0, rows - lines.length - footerRows);
|
|
311
|
+
if (viewportHeight === 0) {
|
|
312
|
+
return [truncateToWidth("Resize terminal to inspect cleanup; Esc cancels.", width)];
|
|
313
|
+
}
|
|
314
|
+
const content = this.contentLines(innerW);
|
|
315
|
+
this.scroll.updateLayout(content.length, viewportHeight, () => {
|
|
316
|
+
if (!this.closed)
|
|
317
|
+
this.tui.requestRender();
|
|
318
|
+
});
|
|
319
|
+
this.contentTop = lines.length;
|
|
320
|
+
const visible = content.slice(this.scroll.scrollTop, this.scroll.scrollTop + viewportHeight);
|
|
321
|
+
for (let i = 0; i < viewportHeight; i++)
|
|
322
|
+
lines.push(row(visible[i] ?? ""));
|
|
323
|
+
if (footerRows) {
|
|
324
|
+
lines.push(row(th.fg("dim", this.footerText(content.length, viewportHeight))));
|
|
325
|
+
lines.push(hrBot);
|
|
326
|
+
}
|
|
327
|
+
this.reviewable = true;
|
|
328
|
+
return lines.slice(0, rows);
|
|
329
|
+
}
|
|
330
|
+
handleMouse(event) {
|
|
331
|
+
if (this.closed)
|
|
332
|
+
return undefined;
|
|
333
|
+
if (event.type === "wheel" && event.y >= this.contentTop && event.y < this.contentTop + this.scroll.viewportHeight) {
|
|
334
|
+
this.scroll.scrollBy(event.wheelDelta ?? 0);
|
|
335
|
+
this.tui.requestRender();
|
|
336
|
+
return { handled: true };
|
|
337
|
+
}
|
|
338
|
+
return undefined;
|
|
339
|
+
}
|
|
340
|
+
invalidate() {
|
|
341
|
+
// The styled body embeds theme colors; rebuild it rather than reusing them.
|
|
342
|
+
this.styledBodyCache = undefined;
|
|
343
|
+
this.text.invalidate();
|
|
344
|
+
}
|
|
345
|
+
dispose() {
|
|
346
|
+
this.closed = true;
|
|
347
|
+
}
|
|
348
|
+
// ---- Private ----
|
|
349
|
+
close(result) {
|
|
350
|
+
if (this.closed)
|
|
351
|
+
return;
|
|
352
|
+
this.closed = true;
|
|
353
|
+
this.done(result);
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Cancel is escape/ctrl+c even when the user rebound `tui.select.cancel`:
|
|
357
|
+
* the reflex key must never strand someone inside a deletion review.
|
|
358
|
+
*/
|
|
359
|
+
isCancel(data) {
|
|
360
|
+
return (matchesKey(data, "escape") ||
|
|
361
|
+
matchesKey(data, "ctrl+c") ||
|
|
362
|
+
(this.keybindings?.matches(data, "tui.select.cancel") ?? false));
|
|
363
|
+
}
|
|
364
|
+
/** Enter always works alongside the configured confirm binding. */
|
|
365
|
+
isConfirm(data) {
|
|
366
|
+
return matchesKey(data, "enter") || (this.keybindings?.matches(data, "tui.select.confirm") ?? false);
|
|
367
|
+
}
|
|
368
|
+
isBoundary(data, boundary) {
|
|
369
|
+
if (boundary === "top") {
|
|
370
|
+
return (matchesKey(data, "home") ||
|
|
371
|
+
matchesKey(data, "ctrl+home") ||
|
|
372
|
+
matchesKey(data, "ctrl+shift+home") ||
|
|
373
|
+
(this.keybindings?.matches(data, "tui.altScreen.top") ?? false));
|
|
374
|
+
}
|
|
375
|
+
return (matchesKey(data, "end") ||
|
|
376
|
+
matchesKey(data, "ctrl+end") ||
|
|
377
|
+
matchesKey(data, "ctrl+shift+end") ||
|
|
378
|
+
(this.keybindings?.matches(data, "tui.altScreen.bottom") ?? false));
|
|
379
|
+
}
|
|
380
|
+
/** The fixed line under the header: what THIS showing of the preview means. */
|
|
381
|
+
modeLines() {
|
|
382
|
+
if (this.dryRun) {
|
|
383
|
+
return [{ text: "Dry run — review only; nothing will be deleted.", tone: "dim" }];
|
|
384
|
+
}
|
|
385
|
+
if (isCleanupPlanEmpty(this.plan)) {
|
|
386
|
+
return [{ text: "Nothing is eligible for cleanup.", tone: "dim" }];
|
|
387
|
+
}
|
|
388
|
+
const counts = this.plan.counts;
|
|
389
|
+
const parts = [];
|
|
390
|
+
if (counts.unread > 0) {
|
|
391
|
+
parts.push(`${plural(counts.unread, "unread artifact")} (not marked as read)`);
|
|
392
|
+
}
|
|
393
|
+
if (counts.unknownReadState > 0) {
|
|
394
|
+
parts.push(`read state unknown for ${plural(counts.unknownReadState, "artifact")} (archived read state was not recorded)`);
|
|
395
|
+
}
|
|
396
|
+
const detail = parts.length > 0 ? ` — ${parts.join("; ")}` : "";
|
|
397
|
+
return [
|
|
398
|
+
{ text: `Warning — a confirmed cleanup permanently discards every file below${detail}.`, tone: "warning" },
|
|
399
|
+
];
|
|
400
|
+
}
|
|
401
|
+
footerText(contentLength, viewportHeight) {
|
|
402
|
+
const hints = [];
|
|
403
|
+
const confirmKey = this.firstKeyLabel("tui.select.confirm", "enter");
|
|
404
|
+
const cancelKey = this.firstKeyLabel("tui.select.cancel", "esc");
|
|
405
|
+
if (this.dryRun) {
|
|
406
|
+
hints.push(`${confirmKey}/${cancelKey} close`);
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
hints.push(`${confirmKey} continue`, `${cancelKey} cancel`);
|
|
410
|
+
}
|
|
411
|
+
hints.push(`${this.firstKeyLabel("tui.select.up", "↑")}${this.firstKeyLabel("tui.select.down", "↓")} scroll`);
|
|
412
|
+
hints.push(`${this.firstKeyLabel("tui.select.pageUp", "PgUp")}/${this.firstKeyLabel("tui.select.pageDown", "PgDn")} page`);
|
|
413
|
+
hints.push("Home/End top/bottom");
|
|
414
|
+
// Position last: it is the first hint a narrow footer may drop.
|
|
415
|
+
if (contentLength > viewportHeight) {
|
|
416
|
+
const top = this.scroll.scrollTop + 1;
|
|
417
|
+
const bottom = Math.min(this.scroll.scrollTop + viewportHeight, contentLength);
|
|
418
|
+
hints.push(`${top}–${bottom}/${contentLength}`);
|
|
419
|
+
}
|
|
420
|
+
return hints.join(" · ");
|
|
421
|
+
}
|
|
422
|
+
/** The user's own key for an action where bound, else the default label. */
|
|
423
|
+
firstKeyLabel(keybinding, fallback) {
|
|
424
|
+
const keys = this.keybindings?.getKeys(keybinding);
|
|
425
|
+
return keys && keys.length > 0 ? keyLabel(keys[0]) : fallback;
|
|
426
|
+
}
|
|
427
|
+
contentLines(width) {
|
|
428
|
+
const styled = this.styledBody();
|
|
429
|
+
if (styled !== this.lastStyledBody) {
|
|
430
|
+
this.text.setText(styled);
|
|
431
|
+
this.lastStyledBody = styled;
|
|
432
|
+
}
|
|
433
|
+
return this.text.render(Math.max(1, width));
|
|
434
|
+
}
|
|
435
|
+
styledBody() {
|
|
436
|
+
if (this.styledBodyCache === undefined) {
|
|
437
|
+
this.styledBodyCache = this.bodyLines.map(line => styleLine(this.theme, line)).join("\n");
|
|
438
|
+
}
|
|
439
|
+
return this.styledBodyCache;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Show the cleanup preview overlay and report whether the review was
|
|
444
|
+
* completed with an explicit Continue.
|
|
445
|
+
*
|
|
446
|
+
* Returns `true` ONLY in normal (non-dry-run) mode when the user presses the
|
|
447
|
+
* confirm key — that is "review done", not deletion approval; the parent runs
|
|
448
|
+
* its own `ctx.ui.confirm` afterwards. Esc, cancel, a closed dry run, and any
|
|
449
|
+
* environment without a real terminal all return `false`.
|
|
450
|
+
*
|
|
451
|
+
* TUI only: RPC clients report `hasUI` but their `custom()` resolves
|
|
452
|
+
* `undefined`, and print/JSON modes have no UI at all — so anything that is
|
|
453
|
+
* not an interactive terminal is a refusal, never a consent.
|
|
454
|
+
*/
|
|
455
|
+
export async function showCleanupPreview(ctx, plan, dryRun) {
|
|
456
|
+
if (ctx.mode !== "tui" || !ctx.hasUI)
|
|
457
|
+
return false;
|
|
458
|
+
let reviewed;
|
|
459
|
+
try {
|
|
460
|
+
reviewed = await ctx.ui.custom((tui, theme, keybindings, done) => new CleanupPreview(tui, theme, keybindings, plan, dryRun, done), { overlay: true, overlayOptions: { anchor: "center", width: "90%", maxHeight: "100%" } });
|
|
461
|
+
}
|
|
462
|
+
catch {
|
|
463
|
+
return false;
|
|
464
|
+
}
|
|
465
|
+
return reviewed === true;
|
|
466
|
+
}
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { type AgentSession, type KeybindingsManager } from "@earendil-works/pi-coding-agent";
|
|
8
8
|
import { type Component, type Focusable, type TUI, type TuiMouseEvent } from "@earendil-works/pi-tui";
|
|
9
|
-
import type { AgentRecord, ViewerMarkdownMode } from "../types.
|
|
10
|
-
import type { Theme } from "./agent-widget.
|
|
11
|
-
import { type AgentActivity } from "./agent-widget.
|
|
12
|
-
export { RESULT_MAX_CHARS } from "./tool-progress.
|
|
9
|
+
import type { AgentRecord, ViewerMarkdownMode } from "../types.ts";
|
|
10
|
+
import type { Theme } from "./agent-widget.ts";
|
|
11
|
+
import { type AgentActivity } from "./agent-widget.ts";
|
|
12
|
+
export { RESULT_MAX_CHARS } from "./tool-progress.ts";
|
|
13
13
|
export declare const VIEWPORT_HEIGHT_PCT = 100;
|
|
14
14
|
export declare class ConversationViewer implements Component, Focusable {
|
|
15
15
|
private tui;
|
|
@@ -9,7 +9,7 @@ import { CURSOR_MARKER, getKeybindings, isKeyRelease, Markdown, matchesKey, Scro
|
|
|
9
9
|
import { renderAgentName } from "../agent-color.js";
|
|
10
10
|
import { extractText } from "../context.js";
|
|
11
11
|
import { getLifetimeCost, getLifetimeTotal, getSessionContextPercent } from "../usage.js";
|
|
12
|
-
import { buildInvocationTags, describeActivity, fgPreservingNestedStyles, formatCost, formatDuration, formatSessionTokens, getPromptModeLabel } from "./agent-widget.js";
|
|
12
|
+
import { buildInvocationTags, describeActivity, fgPreservingNestedStyles, formatCost, formatDuration, formatSessionTokens, getPromptModeLabel, sanitizeRowText } from "./agent-widget.js";
|
|
13
13
|
import { NativeTranscript } from "./native-transcript.js";
|
|
14
14
|
import { RESULT_MAX_CHARS, truncationNote } from "./tool-progress.js";
|
|
15
15
|
export { RESULT_MAX_CHARS } from "./tool-progress.js";
|
|
@@ -308,7 +308,7 @@ export class ConversationViewer {
|
|
|
308
308
|
const cost = this.showCost ? formatCost(getLifetimeCost(this.record.lifetimeUsage)) : "";
|
|
309
309
|
if (cost)
|
|
310
310
|
headerParts.push(cost);
|
|
311
|
-
lines.push(row(`${statusIcon} ${renderAgentName(this.record.type, th, { bold: true })}${modeTag} ${th.fg("muted", this.record.description)} ${th.fg("dim", "·")} ${fgPreservingNestedStyles(th, "dim", headerParts.join(" · "))}`));
|
|
311
|
+
lines.push(row(`${statusIcon} ${renderAgentName(this.record.type, th, { bold: true })}${modeTag} ${th.fg("muted", sanitizeRowText(this.record.description))} ${th.fg("dim", "·")} ${fgPreservingNestedStyles(th, "dim", headerParts.join(" · "))}`));
|
|
312
312
|
const invocationLine = this.invocationLine();
|
|
313
313
|
if (invocationLine)
|
|
314
314
|
lines.push(row(invocationLine));
|
|
@@ -334,7 +334,9 @@ export class ConversationViewer {
|
|
|
334
334
|
const queued = (this.session.getSteeringMessages?.().length ?? 0) + (this.session.getFollowUpMessages?.().length ?? 0);
|
|
335
335
|
const action = !this.onSubmitMessage ? "Read only" : this.record.status === "running" || this.record.status === "queued" ? "Enter steer" : "Enter continue";
|
|
336
336
|
const stop = this.isStoppable() ? this.stopArmed ? " · Ctrl+X again to STOP" : " · Ctrl+X stop" : "";
|
|
337
|
-
|
|
337
|
+
// `submitError` is an error message and may be multi-line; one overlay
|
|
338
|
+
// row is one terminal row, so it is flattened like every other fragment.
|
|
339
|
+
lines.push(row(th.fg(this.submitError ? "error" : "dim", sanitizeRowText(this.submitError || `${this.submitting ? "Sending…" : action}${queued ? ` · ${queued} queued` : ""}${stop}`))));
|
|
338
340
|
}
|
|
339
341
|
this.editorTop = lines.length;
|
|
340
342
|
lines.push(...editorLines.slice(this.editorClip, this.editorClip + editorHeight).map(row));
|
|
@@ -445,7 +447,9 @@ export class ConversationViewer {
|
|
|
445
447
|
const parts = model ? [model, ...tags] : tags;
|
|
446
448
|
if (parts.length === 0)
|
|
447
449
|
return undefined;
|
|
448
|
-
|
|
450
|
+
// Model names/ids come from the registry and tags are derived from them;
|
|
451
|
+
// flattened here because the line is a single overlay row.
|
|
452
|
+
return this.theme.fg("dim", ` ↳ ${sanitizeRowText(parts.join(" · "))}`);
|
|
449
453
|
}
|
|
450
454
|
buildContentLines(width) {
|
|
451
455
|
if (width <= 0)
|
|
@@ -514,7 +518,7 @@ export class ConversationViewer {
|
|
|
514
518
|
const bash = msg;
|
|
515
519
|
if (needsSeparator)
|
|
516
520
|
lines.push(th.fg("dim", "───"));
|
|
517
|
-
lines.push(truncateToWidth(th.fg("muted", ` $ ${bash.command}`), width));
|
|
521
|
+
lines.push(truncateToWidth(th.fg("muted", ` $ ${sanitizeRowText(bash.command)}`), width));
|
|
518
522
|
if (bash.output?.trim()) {
|
|
519
523
|
// Same cap as a tool result, never Markdown: command output is the one
|
|
520
524
|
// thing here that is definitionally not authored as Markdown.
|
|
@@ -531,7 +535,7 @@ export class ConversationViewer {
|
|
|
531
535
|
}
|
|
532
536
|
// Streaming indicator for running agents
|
|
533
537
|
if (this.record.status === "running" && this.activity) {
|
|
534
|
-
const act = describeActivity(this.activity.activeTools, this.activity.responseText);
|
|
538
|
+
const act = sanitizeRowText(describeActivity(this.activity.activeTools, this.activity.responseText));
|
|
535
539
|
lines.push("");
|
|
536
540
|
lines.push(truncateToWidth(th.fg("accent", "▍ ") + th.fg("dim", act), width));
|
|
537
541
|
}
|
package/dist/ui/fleet-list.d.ts
CHANGED
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
* handling goes through `onTerminalInput` — which fires before the focused editor and
|
|
11
11
|
* can `consume` keys — gated on `getEditorText() === ""` so normal typing is untouched.
|
|
12
12
|
*/
|
|
13
|
-
import { type AgentManager } from "../agent-manager.
|
|
14
|
-
import type { AgentRecord } from "../types.
|
|
15
|
-
import { type AgentActivity, type Theme } from "./agent-widget.
|
|
13
|
+
import { type AgentManager } from "../agent-manager.ts";
|
|
14
|
+
import type { AgentRecord } from "../types.ts";
|
|
15
|
+
import { type AgentActivity, type Theme } from "./agent-widget.ts";
|
|
16
16
|
/** Minimal UI surface the FleetView needs from `ctx.ui` (structural subset). */
|
|
17
17
|
export type FleetUICtx = {
|
|
18
18
|
setWidget(key: string, content: undefined | ((tui: any, theme: Theme) => {
|
package/dist/ui/fleet-list.js
CHANGED
|
@@ -14,7 +14,7 @@ import { Editor, isKeyRelease, Key, matchesKey, truncateToWidth, visibleWidth }
|
|
|
14
14
|
import { hasAgentBadge, renderAgentName } from "../agent-color.js";
|
|
15
15
|
import { isTopLevelAgent } from "../agent-manager.js";
|
|
16
16
|
import { getLifetimeCost, getLifetimeTotal } from "../usage.js";
|
|
17
|
-
import { formatCost } from "./agent-widget.js";
|
|
17
|
+
import { formatCost, sanitizeRowText } from "./agent-widget.js";
|
|
18
18
|
/** Widget key for the below-editor fleet list. */
|
|
19
19
|
const FLEET_KEY = "fleet";
|
|
20
20
|
/** Max agent rows shown at once; extras collapse into a "↓ N more" indicator. */
|
|
@@ -462,7 +462,7 @@ export class FleetList {
|
|
|
462
462
|
renderWorkflowRow(rosterIndex, sel, workflow, width, theme) {
|
|
463
463
|
const selected = rosterIndex === sel;
|
|
464
464
|
const kind = theme.fg(selected ? "text" : "muted", "workflow");
|
|
465
|
-
const name = selected ? theme.fg("text", workflow.name) : workflow.name;
|
|
465
|
+
const name = selected ? theme.fg("text", sanitizeRowText(workflow.name)) : sanitizeRowText(workflow.name);
|
|
466
466
|
const left = ` ${this.bullet(rosterIndex, sel, theme)} ${kind} ${name}`;
|
|
467
467
|
// Frozen once the run settles, exactly as an agent's clock is.
|
|
468
468
|
const elapsed = (workflow.completedAt ?? Date.now()) - workflow.startedAt;
|
|
@@ -479,7 +479,7 @@ export class FleetList {
|
|
|
479
479
|
const name = renderAgentName(record.type, theme, selected
|
|
480
480
|
? { fallbackColor: "text", bold: hasAgentBadge(record.type) }
|
|
481
481
|
: { fallbackColor: "muted" });
|
|
482
|
-
const description = selected ? theme.fg("text", record.description) : record.description;
|
|
482
|
+
const description = selected ? theme.fg("text", sanitizeRowText(record.description)) : sanitizeRowText(record.description);
|
|
483
483
|
const left = ` ${this.bullet(rosterIndex, sel, theme)} ${name} ${description}`;
|
|
484
484
|
// The record, not the activity tracker — see the note in AgentWidget's
|
|
485
485
|
// running line: only the record carries a nested child's spend, and only it
|