@xynogen/pix-pretty 1.37.2 → 2.0.0
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/package.json +4 -2
- package/src/batch.ts +4 -5
- package/src/command-preview.ts +2 -3
- package/src/confirm.ts +106 -98
- package/src/gate-overlay.ts +185 -162
- package/src/grammar-consent.ts +3 -1
- package/src/icon-catalog.ts +1 -0
- package/src/index.ts +2 -0
- package/src/overlay-images.ts +25 -0
- package/src/overlay-lifecycle.ts +34 -0
- package/src/progress.ts +54 -41
- package/src/shell-tool.ts +4 -4
- package/src/user-prompt.ts +27 -0
- package/src/utils.ts +38 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xynogen/pix-pretty",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Enhanced tool output rendering with syntax highlighting, file icons, tree views, diff rendering, and FFF search",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
"./batch": "./src/batch.ts",
|
|
11
11
|
"./confirm": "./src/confirm.ts",
|
|
12
12
|
"./progress": "./src/progress.ts",
|
|
13
|
+
"./overlay-lifecycle": "./src/overlay-lifecycle.ts",
|
|
14
|
+
"./user-prompt": "./src/user-prompt.ts",
|
|
13
15
|
"./config": "./src/config.ts",
|
|
14
16
|
"./diff": "./src/diff.ts",
|
|
15
17
|
"./diff-render": "./src/diff-render.ts",
|
|
@@ -70,7 +72,7 @@
|
|
|
70
72
|
"access": "public"
|
|
71
73
|
},
|
|
72
74
|
"dependencies": {
|
|
73
|
-
"@xynogen/pix-runtime": "^0.
|
|
75
|
+
"@xynogen/pix-runtime": "^0.19.0",
|
|
74
76
|
"chalk": "^4.1.2",
|
|
75
77
|
"cli-highlight": "^2.1.11",
|
|
76
78
|
"@ff-labs/fff-node": "^0.10.6",
|
package/src/batch.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/** Shared batching for read/grep/find/ls — N known targets, one tool result. */
|
|
2
2
|
|
|
3
|
+
import { truncateStringToBytes } from "@xynogen/pix-runtime/utf8";
|
|
4
|
+
|
|
3
5
|
export const BATCH_MAX_TARGETS = 20;
|
|
4
6
|
export const BATCH_MAX_BYTES = 50 * 1024;
|
|
5
7
|
|
|
6
8
|
const encoder = new TextEncoder();
|
|
7
|
-
const decoder = new TextDecoder();
|
|
8
9
|
|
|
9
10
|
/** Merge a singular target with an optional array, trimming and de-duping. */
|
|
10
11
|
export function resolveBatchStrings(single: string | undefined, many: unknown): string[] {
|
|
@@ -97,10 +98,8 @@ function byteLength(text: string): number {
|
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
function cutToBytes(text: string, maxBytes: number): string {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
let cut = decoder.decode(bytes.slice(0, maxBytes));
|
|
103
|
-
if (cut.endsWith("\uFFFD")) cut = cut.slice(0, -1);
|
|
101
|
+
if (byteLength(text) <= maxBytes) return text;
|
|
102
|
+
const cut = truncateStringToBytes(text, maxBytes);
|
|
104
103
|
const lastNl = cut.lastIndexOf("\n");
|
|
105
104
|
return lastNl > 0 ? cut.slice(0, lastNl) : cut;
|
|
106
105
|
}
|
package/src/command-preview.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Text, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil
|
|
|
2
2
|
import { hlBlock } from "./highlight.ts";
|
|
3
3
|
import { fadePaint, fadeRowsOf, fadeText } from "./text.ts";
|
|
4
4
|
import type { ThemeLike } from "./types.ts";
|
|
5
|
-
import { type ExpandHintCtx, expandHint, type
|
|
5
|
+
import { type ExpandHintCtx, expandHint, type renderRow } from "./utils.ts";
|
|
6
6
|
|
|
7
7
|
export function commandPreview(
|
|
8
8
|
header: string,
|
|
@@ -94,8 +94,7 @@ export function commandPreview(
|
|
|
94
94
|
export function collapsedCommandRow(
|
|
95
95
|
header: string,
|
|
96
96
|
command: string,
|
|
97
|
-
theme: Pick<ThemeLike, "fg"> &
|
|
98
|
-
Pick<Parameters<typeof formatCollapsedToolRow>[0], "colors" | "style">,
|
|
97
|
+
theme: Pick<ThemeLike, "fg"> & Pick<Parameters<typeof renderRow>[0], "colors" | "style">,
|
|
99
98
|
) {
|
|
100
99
|
const plain = command.replace(/\s+/g, " ").trim();
|
|
101
100
|
const prefix = `${header}${theme.fg("muted", " · ")}`;
|
package/src/confirm.ts
CHANGED
|
@@ -10,11 +10,12 @@ import {
|
|
|
10
10
|
frameModal,
|
|
11
11
|
MIN_PERMISSION_MODAL_HEIGHT,
|
|
12
12
|
ModalPager,
|
|
13
|
-
modalOverlayOptions,
|
|
14
13
|
modalWidth,
|
|
15
14
|
selectListTheme,
|
|
16
15
|
terminalModalHeight,
|
|
17
16
|
} from "./modal-frame.ts";
|
|
17
|
+
import { createOverlayLifecycle } from "./overlay-lifecycle.ts";
|
|
18
|
+
import { type UserPromptOptions, type UserPromptState, withUserPrompt } from "./user-prompt.ts";
|
|
18
19
|
|
|
19
20
|
// Minimal structural type for the `ctx.ui.custom` host call.
|
|
20
21
|
interface CustomTheme {
|
|
@@ -38,11 +39,12 @@ export interface ConfirmUI {
|
|
|
38
39
|
kb: KeybindingsManager,
|
|
39
40
|
done: (v: T) => void,
|
|
40
41
|
) => CustomComponent,
|
|
41
|
-
opts?:
|
|
42
|
+
opts?: UserPromptOptions,
|
|
42
43
|
): Promise<T | undefined>;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
export interface ConfirmOptions {
|
|
47
|
+
state?: UserPromptState;
|
|
46
48
|
/** Optional leading glyph for the title row, e.g. `icon("update")`. Rendered
|
|
47
49
|
* as "<icon> <title>" so callers pass a resolved icon + plain text. */
|
|
48
50
|
icon?: string;
|
|
@@ -66,106 +68,112 @@ const COUNTDOWN_WARN_S = 5;
|
|
|
66
68
|
/**
|
|
67
69
|
* Show a Yes/No overlay. Resolves true on confirm, false otherwise.
|
|
68
70
|
*/
|
|
69
|
-
export function confirmOverlay(ui: ConfirmUI, opts: ConfirmOptions): Promise<boolean> {
|
|
71
|
+
export async function confirmOverlay(ui: ConfirmUI, opts: ConfirmOptions): Promise<boolean> {
|
|
70
72
|
const accent = opts.accent ?? "accent";
|
|
71
73
|
const timeoutMs = opts.timeoutMs ?? 0;
|
|
72
74
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
updateCountdown();
|
|
107
|
-
ticker = setInterval(() => {
|
|
108
|
-
updateCountdown();
|
|
109
|
-
tui.requestRender();
|
|
110
|
-
}, SECOND_MS);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const finish = (value: boolean) => {
|
|
114
|
-
if (timer !== undefined) clearTimeout(timer);
|
|
115
|
-
if (ticker !== undefined) clearInterval(ticker);
|
|
116
|
-
done(value);
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
selectList.onSelect = (item) => finish(item.value === "yes");
|
|
120
|
-
selectList.onCancel = () => finish(false);
|
|
121
|
-
controller.signal.addEventListener("abort", () => finish(false));
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
render: (w: number) => {
|
|
125
|
-
const mw = modalWidth(w);
|
|
126
|
-
const inner = mw - 4;
|
|
127
|
-
const footer = [theme.fg("muted", "─".repeat(inner))];
|
|
128
|
-
if (countdownLine !== undefined) footer.push(countdownLine);
|
|
129
|
-
footer.push(...selectList.render(inner));
|
|
130
|
-
footer.push("");
|
|
131
|
-
footer.push(
|
|
132
|
-
theme.fg("muted", "↑↓ choose • ←→/PgUp/PgDn inspect • enter select • esc cancel"),
|
|
75
|
+
const lifecycle = createOverlayLifecycle<boolean>();
|
|
76
|
+
const finish = lifecycle.finish;
|
|
77
|
+
try {
|
|
78
|
+
const timer = timeoutMs > 0 ? setTimeout(() => finish(false), timeoutMs) : undefined;
|
|
79
|
+
lifecycle.onCleanup(() => clearTimeout(timer));
|
|
80
|
+
return (
|
|
81
|
+
(await withUserPrompt(
|
|
82
|
+
{ kind: "permission", message: opts.title },
|
|
83
|
+
(options) =>
|
|
84
|
+
ui.custom<boolean>((tui, theme, kb, done) => {
|
|
85
|
+
let ticker: ReturnType<typeof setInterval> | undefined;
|
|
86
|
+
let countdownLine: string | undefined;
|
|
87
|
+
const pager = new ModalPager();
|
|
88
|
+
lifecycle.onCleanup(() => clearInterval(ticker));
|
|
89
|
+
lifecycle.bind(done);
|
|
90
|
+
|
|
91
|
+
const choices: SelectItem[] = [
|
|
92
|
+
{
|
|
93
|
+
value: "yes",
|
|
94
|
+
label: opts.confirmLabel ?? "Yes",
|
|
95
|
+
description: "Proceed",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
value: "no",
|
|
99
|
+
label: opts.denyLabel ?? "No",
|
|
100
|
+
description: "Cancel",
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
const selectList = new SelectList(
|
|
105
|
+
choices,
|
|
106
|
+
choices.length,
|
|
107
|
+
selectListTheme(theme, accent),
|
|
133
108
|
);
|
|
134
109
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
});
|
|
151
|
-
pager.sync(result);
|
|
152
|
-
return result.lines;
|
|
153
|
-
},
|
|
154
|
-
invalidate: () => {},
|
|
155
|
-
handleInput: (data: string) => {
|
|
156
|
-
if (pager.handleInput(data, kb, true)) {
|
|
157
|
-
tui.requestRender();
|
|
158
|
-
return;
|
|
110
|
+
selectList.onSelect = (item) => finish(item.value === "yes");
|
|
111
|
+
selectList.onCancel = () => finish(false);
|
|
112
|
+
if (!lifecycle.closed && timeoutMs > 0) {
|
|
113
|
+
const deadlineMs = Date.now() + timeoutMs;
|
|
114
|
+
const updateCountdown = () => {
|
|
115
|
+
const remaining = Math.max(0, Math.ceil((deadlineMs - Date.now()) / SECOND_MS));
|
|
116
|
+
countdownLine =
|
|
117
|
+
theme.fg("muted", "Auto-cancel in ") +
|
|
118
|
+
theme.fg(remaining <= COUNTDOWN_WARN_S ? accent : "muted", `${remaining}s`);
|
|
119
|
+
};
|
|
120
|
+
updateCountdown();
|
|
121
|
+
ticker = setInterval(() => {
|
|
122
|
+
updateCountdown();
|
|
123
|
+
tui.requestRender();
|
|
124
|
+
}, SECOND_MS);
|
|
159
125
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
render: (w: number) => {
|
|
129
|
+
const mw = modalWidth(w);
|
|
130
|
+
const inner = mw - 4;
|
|
131
|
+
const footer = [theme.fg("muted", "─".repeat(inner))];
|
|
132
|
+
if (countdownLine !== undefined) footer.push(countdownLine);
|
|
133
|
+
footer.push(...selectList.render(inner));
|
|
134
|
+
footer.push("");
|
|
135
|
+
footer.push(
|
|
136
|
+
theme.fg("muted", "↑↓ choose • ←→/PgUp/PgDn inspect • enter select • esc cancel"),
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
const result = frameModal({
|
|
140
|
+
width: mw,
|
|
141
|
+
maxHeight: terminalModalHeight(tui.terminal?.rows),
|
|
142
|
+
minHeight: MIN_PERMISSION_MODAL_HEIGHT,
|
|
143
|
+
header: [
|
|
144
|
+
theme.fg(
|
|
145
|
+
accent,
|
|
146
|
+
theme.bold(opts.icon ? `${opts.icon} ${opts.title}` : opts.title),
|
|
147
|
+
),
|
|
148
|
+
],
|
|
149
|
+
body: (opts.body ?? []).map((line) => theme.fg("text", line)),
|
|
150
|
+
footer,
|
|
151
|
+
bodyOffset: pager.bodyOffset,
|
|
152
|
+
color: (s) => theme.fg(accent, s),
|
|
153
|
+
bg: (s) => theme.bg("customMessageBg", s),
|
|
154
|
+
fg: (s) => theme.fg("text", s),
|
|
155
|
+
overflowLine: ({ page, totalPages }) =>
|
|
156
|
+
theme.fg("muted", `←→/PgUp/PgDn inspect • ${page}/${totalPages}`),
|
|
157
|
+
});
|
|
158
|
+
pager.sync(result);
|
|
159
|
+
return result.lines;
|
|
160
|
+
},
|
|
161
|
+
invalidate: () => {},
|
|
162
|
+
handleInput: (data: string) => {
|
|
163
|
+
if (lifecycle.closed) return;
|
|
164
|
+
if (pager.handleInput(data, kb, true)) {
|
|
165
|
+
tui.requestRender();
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
selectList.handleInput(data);
|
|
169
|
+
tui.requestRender();
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
}, options),
|
|
173
|
+
opts.state,
|
|
174
|
+
)) ?? false
|
|
175
|
+
);
|
|
176
|
+
} finally {
|
|
177
|
+
lifecycle.dispose();
|
|
178
|
+
}
|
|
171
179
|
}
|
package/src/gate-overlay.ts
CHANGED
|
@@ -16,17 +16,19 @@
|
|
|
16
16
|
* - Single source of truth for the overlay look across pix-gate, pix-sudo, and pix-ssh.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import { Input, type SelectItem, SelectList } from "@earendil-works/pi-tui";
|
|
19
|
+
import { Input, matchesKey, type SelectItem, SelectList } from "@earendil-works/pi-tui";
|
|
20
|
+
import { onAbort } from "@xynogen/pix-runtime/abort";
|
|
20
21
|
import {
|
|
21
22
|
frameModal,
|
|
22
23
|
MIN_PERMISSION_MODAL_HEIGHT,
|
|
23
24
|
type ModalPageKeybindings,
|
|
24
25
|
ModalPager,
|
|
25
|
-
modalOverlayOptions,
|
|
26
26
|
modalWidth,
|
|
27
27
|
selectListTheme,
|
|
28
28
|
terminalModalHeight,
|
|
29
29
|
} from "./modal-frame.ts";
|
|
30
|
+
import { createOverlayLifecycle } from "./overlay-lifecycle.ts";
|
|
31
|
+
import { type UserPromptOptions, type UserPromptState, withUserPrompt } from "./user-prompt.ts";
|
|
30
32
|
|
|
31
33
|
// ── Types ─────────────────────────────────────────────────────────────────────
|
|
32
34
|
|
|
@@ -49,6 +51,8 @@ export interface OverlayChoice {
|
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
interface BaseConfig {
|
|
54
|
+
state?: UserPromptState;
|
|
55
|
+
signal?: AbortSignal;
|
|
52
56
|
/** Accent colour token (e.g. "error", "warning", "accent"). Default "accent". */
|
|
53
57
|
accent?: string;
|
|
54
58
|
/**
|
|
@@ -87,7 +91,7 @@ export interface SudoConfig extends BaseConfig {
|
|
|
87
91
|
/** Label for the password input hint. Default "Sudo password:" */
|
|
88
92
|
passwordLabel?: string;
|
|
89
93
|
/** Validate an entered password without closing the overlay. */
|
|
90
|
-
validatePassword?: (password: string) => Promise<boolean>;
|
|
94
|
+
validatePassword?: (password: string, signal?: AbortSignal) => Promise<boolean>;
|
|
91
95
|
/** Number of validation attempts before closing as exhausted. Default 3. */
|
|
92
96
|
maxPasswordAttempts?: number;
|
|
93
97
|
}
|
|
@@ -121,7 +125,7 @@ export interface OverlayUI {
|
|
|
121
125
|
kb: unknown,
|
|
122
126
|
done: (v: T) => void,
|
|
123
127
|
) => OverlayComponent,
|
|
124
|
-
opts?:
|
|
128
|
+
opts?: UserPromptOptions,
|
|
125
129
|
): Promise<T | undefined>;
|
|
126
130
|
}
|
|
127
131
|
|
|
@@ -265,168 +269,187 @@ function buildSections(opts: {
|
|
|
265
269
|
* if (result.action === "approved") runWithSudo(cmd, result.password!);
|
|
266
270
|
* ```
|
|
267
271
|
*/
|
|
268
|
-
export function showOverlay(ui: OverlayUI, config: OverlayConfig): Promise<OverlayResult> {
|
|
272
|
+
export async function showOverlay(ui: OverlayUI, config: OverlayConfig): Promise<OverlayResult> {
|
|
273
|
+
if (config.signal?.aborted) return Promise.resolve({ action: "denied" });
|
|
269
274
|
const accent = config.accent ?? "accent";
|
|
270
275
|
const choices = config.choices ?? DEFAULT_CHOICES;
|
|
271
276
|
const approveVals = [config.approveValue ?? "yes"].flat();
|
|
272
277
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
278
|
+
const lifecycle = createOverlayLifecycle<OverlayResult>();
|
|
279
|
+
const finish = lifecycle.finish;
|
|
280
|
+
try {
|
|
281
|
+
return (
|
|
282
|
+
(await withUserPrompt(
|
|
283
|
+
{ kind: config.mode === "sudo" ? "auth" : "permission", message: config.title },
|
|
284
|
+
(options) =>
|
|
285
|
+
ui.custom<OverlayResult>((tui, theme, kb, done) => {
|
|
286
|
+
const pageKeybindings = asPageKeybindings(kb);
|
|
287
|
+
type Stage = "select" | "password";
|
|
288
|
+
let stage: Stage = "select";
|
|
289
|
+
const validation = new AbortController();
|
|
290
|
+
let countdownLine: string | undefined;
|
|
291
|
+
let passwordStatus: string | undefined;
|
|
292
|
+
let passwordAttempts = 0;
|
|
293
|
+
let validatingPassword = false;
|
|
294
|
+
const pager = new ModalPager();
|
|
295
|
+
|
|
296
|
+
// Dead-man's-switch timer: counts down only while untouched. The
|
|
297
|
+
// first keypress cancels it (user is present → let them decide). If
|
|
298
|
+
// it expires with no input, auto-deny so the agent isn't stuck.
|
|
299
|
+
const timeoutMs = config.timeoutMs ?? 0;
|
|
300
|
+
let remaining = Math.ceil(timeoutMs / 1000);
|
|
301
|
+
let timer: ReturnType<typeof setInterval> | undefined;
|
|
302
|
+
const cancelTimer = () => {
|
|
303
|
+
if (timer) clearInterval(timer);
|
|
304
|
+
timer = undefined;
|
|
305
|
+
countdownLine = undefined;
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
// ── components ──────────────────────────────────────────────────
|
|
309
|
+
const selectItems: SelectItem[] = choices.map((c) => ({
|
|
310
|
+
value: c.value,
|
|
311
|
+
label: c.label,
|
|
312
|
+
description: c.description,
|
|
313
|
+
}));
|
|
314
|
+
|
|
315
|
+
const selectList = new SelectList(
|
|
316
|
+
selectItems,
|
|
317
|
+
selectItems.length,
|
|
318
|
+
selectListTheme(theme, accent),
|
|
319
|
+
);
|
|
320
|
+
const maskedInput = new MaskedInput();
|
|
321
|
+
|
|
322
|
+
lifecycle.onCleanup(cancelTimer);
|
|
323
|
+
lifecycle.onCleanup(() => validation.abort());
|
|
324
|
+
lifecycle.bind(done);
|
|
325
|
+
lifecycle.onCleanup(onAbort(config.signal, () => finish({ action: "denied" })));
|
|
326
|
+
|
|
327
|
+
// Arm the dead-man's switch (only when a timeout was requested).
|
|
328
|
+
if (!lifecycle.closed && timeoutMs > 0) {
|
|
329
|
+
const urgencyColor = (s: number): string =>
|
|
330
|
+
s <= 5 ? "error" : s <= 15 ? "warning" : "muted";
|
|
331
|
+
const countdownText = (s: number): string => {
|
|
332
|
+
const color = urgencyColor(s);
|
|
333
|
+
const text = `auto-deny in ${s}s`;
|
|
334
|
+
return s <= 5 ? theme.bold(theme.fg(color, text)) : theme.fg(color, text);
|
|
335
|
+
};
|
|
336
|
+
countdownLine = countdownText(remaining);
|
|
337
|
+
timer = setInterval(() => {
|
|
338
|
+
remaining -= 1;
|
|
339
|
+
if (remaining <= 0) {
|
|
340
|
+
finish({ action: "timeout" });
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
countdownLine = countdownText(remaining);
|
|
344
|
+
tui.requestRender();
|
|
345
|
+
}, 1000);
|
|
332
346
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
if (!pw.trim() || validatingPassword) return;
|
|
357
|
-
|
|
358
|
-
validatingPassword = true;
|
|
359
|
-
passwordStatus = "Checking password…";
|
|
360
|
-
tui.requestRender();
|
|
361
|
-
const valid = await config.validatePassword(pw);
|
|
362
|
-
validatingPassword = false;
|
|
363
|
-
if (valid) {
|
|
364
|
-
finish({ action: "approved", password: pw });
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
passwordAttempts += 1;
|
|
369
|
-
const maxAttempts = config.maxPasswordAttempts ?? 3;
|
|
370
|
-
if (passwordAttempts >= maxAttempts) {
|
|
371
|
-
// Fail closed: a caller that ignores the flag must not run anything.
|
|
372
|
-
finish({ action: "denied", passwordAttemptsExhausted: true });
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
maskedInput.setValue("");
|
|
376
|
-
passwordStatus = `Incorrect password — attempt ${passwordAttempts} of ${maxAttempts}`;
|
|
377
|
-
tui.requestRender();
|
|
378
|
-
};
|
|
379
|
-
maskedInput.onEscape = () => {
|
|
380
|
-
if (!validatingPassword) finish({ action: "denied" });
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
// ── component interface ──────────────────────────────────────────
|
|
384
|
-
return {
|
|
385
|
-
render: (w) => {
|
|
386
|
-
const mw = modalWidth(w);
|
|
387
|
-
const sections = buildSections({
|
|
388
|
-
theme,
|
|
389
|
-
accent,
|
|
390
|
-
config,
|
|
391
|
-
stage,
|
|
392
|
-
selectList,
|
|
393
|
-
maskedInput,
|
|
394
|
-
countdownLine,
|
|
395
|
-
passwordStatus,
|
|
396
|
-
width: mw,
|
|
397
|
-
});
|
|
398
|
-
const result = frameModal({
|
|
399
|
-
width: mw,
|
|
400
|
-
maxHeight: terminalModalHeight(tui.terminal?.rows),
|
|
401
|
-
minHeight: MIN_PERMISSION_MODAL_HEIGHT,
|
|
402
|
-
...sections,
|
|
403
|
-
bodyOffset: pager.bodyOffset,
|
|
404
|
-
color: (s) => theme.fg(accent, s),
|
|
405
|
-
bg: (s) => theme.bg("customMessageBg", s),
|
|
406
|
-
fg: (s) => theme.fg("text", s),
|
|
407
|
-
overflowLine: ({ page, totalPages }) =>
|
|
408
|
-
theme.fg("muted", `←→/PgUp/PgDn inspect • ${page}/${totalPages}`),
|
|
409
|
-
});
|
|
410
|
-
pager.sync(result);
|
|
411
|
-
return result.lines;
|
|
412
|
-
},
|
|
413
|
-
invalidate: () => {},
|
|
414
|
-
handleInput: (data) => {
|
|
415
|
-
cancelTimer(); // user is present — stop the auto-deny countdown
|
|
416
|
-
if (validatingPassword) return;
|
|
417
|
-
if (pager.handleInput(data, pageKeybindings, true)) {
|
|
347
|
+
|
|
348
|
+
// ── event wiring ─────────────────────────────────────────────────
|
|
349
|
+
selectList.onSelect = (item) => {
|
|
350
|
+
if (!approveVals.includes(item.value)) {
|
|
351
|
+
finish({ action: "denied", choice: item.value });
|
|
352
|
+
} else if (config.mode === "sudo") {
|
|
353
|
+
stage = "password";
|
|
354
|
+
tui.requestRender();
|
|
355
|
+
} else {
|
|
356
|
+
finish({ action: "approved", choice: item.value });
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
selectList.onCancel = () => finish({ action: "denied" });
|
|
360
|
+
|
|
361
|
+
maskedInput.onSubmit = async (pw) => {
|
|
362
|
+
if (config.mode !== "sudo" || !config.validatePassword) {
|
|
363
|
+
finish({ action: "approved", password: pw });
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
if (!pw.trim() || validatingPassword) return;
|
|
367
|
+
|
|
368
|
+
validatingPassword = true;
|
|
369
|
+
passwordStatus = "Checking password…";
|
|
418
370
|
tui.requestRender();
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
371
|
+
let valid: boolean;
|
|
372
|
+
try {
|
|
373
|
+
valid = await config.validatePassword(pw, validation.signal);
|
|
374
|
+
} catch {
|
|
375
|
+
finish({ action: "denied" });
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
if (lifecycle.closed) return;
|
|
379
|
+
validatingPassword = false;
|
|
380
|
+
if (valid) {
|
|
381
|
+
finish({ action: "approved", password: pw });
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
passwordAttempts += 1;
|
|
386
|
+
const maxAttempts = config.maxPasswordAttempts ?? 3;
|
|
387
|
+
if (passwordAttempts >= maxAttempts) {
|
|
388
|
+
// Fail closed: a caller that ignores the flag must not run anything.
|
|
389
|
+
finish({ action: "denied", passwordAttemptsExhausted: true });
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
maskedInput.setValue("");
|
|
393
|
+
passwordStatus = `Incorrect password — attempt ${passwordAttempts} of ${maxAttempts}`;
|
|
394
|
+
tui.requestRender();
|
|
395
|
+
};
|
|
396
|
+
maskedInput.onEscape = () => {
|
|
397
|
+
finish({ action: "denied" });
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
// ── component interface ──────────────────────────────────────────
|
|
401
|
+
return {
|
|
402
|
+
render: (w) => {
|
|
403
|
+
const mw = modalWidth(w);
|
|
404
|
+
const sections = buildSections({
|
|
405
|
+
theme,
|
|
406
|
+
accent,
|
|
407
|
+
config,
|
|
408
|
+
stage,
|
|
409
|
+
selectList,
|
|
410
|
+
maskedInput,
|
|
411
|
+
countdownLine,
|
|
412
|
+
passwordStatus,
|
|
413
|
+
width: mw,
|
|
414
|
+
});
|
|
415
|
+
const result = frameModal({
|
|
416
|
+
width: mw,
|
|
417
|
+
maxHeight: terminalModalHeight(tui.terminal?.rows),
|
|
418
|
+
minHeight: MIN_PERMISSION_MODAL_HEIGHT,
|
|
419
|
+
...sections,
|
|
420
|
+
bodyOffset: pager.bodyOffset,
|
|
421
|
+
color: (s) => theme.fg(accent, s),
|
|
422
|
+
bg: (s) => theme.bg("customMessageBg", s),
|
|
423
|
+
fg: (s) => theme.fg("text", s),
|
|
424
|
+
overflowLine: ({ page, totalPages }) =>
|
|
425
|
+
theme.fg("muted", `←→/PgUp/PgDn inspect • ${page}/${totalPages}`),
|
|
426
|
+
});
|
|
427
|
+
pager.sync(result);
|
|
428
|
+
return result.lines;
|
|
429
|
+
},
|
|
430
|
+
invalidate: () => {},
|
|
431
|
+
handleInput: (data) => {
|
|
432
|
+
if (lifecycle.closed) return;
|
|
433
|
+
if (matchesKey(data, "escape")) {
|
|
434
|
+
finish({ action: "denied" });
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
cancelTimer(); // user is present — stop the auto-deny countdown
|
|
438
|
+
if (validatingPassword) return;
|
|
439
|
+
if (pager.handleInput(data, pageKeybindings, true)) {
|
|
440
|
+
tui.requestRender();
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
if (stage === "select") selectList.handleInput(data);
|
|
444
|
+
else maskedInput.handleInput(data);
|
|
445
|
+
tui.requestRender();
|
|
446
|
+
},
|
|
447
|
+
};
|
|
448
|
+
}, options),
|
|
449
|
+
config.state,
|
|
450
|
+
)) ?? { action: "denied" }
|
|
451
|
+
);
|
|
452
|
+
} finally {
|
|
453
|
+
lifecycle.dispose();
|
|
454
|
+
}
|
|
432
455
|
}
|
package/src/grammar-consent.ts
CHANGED
|
@@ -19,10 +19,11 @@ export interface ExecuteCtx {
|
|
|
19
19
|
const INSTALL_TIMEOUT_MS = 60_000;
|
|
20
20
|
|
|
21
21
|
/** Build a consent function that asks once per grammar package. */
|
|
22
|
-
export function grammarConsent(ctx?: ExecuteCtx): ConsentFn | undefined {
|
|
22
|
+
export function grammarConsent(ctx?: ExecuteCtx, signal?: AbortSignal): ConsentFn | undefined {
|
|
23
23
|
if (!ctx?.hasUI) return undefined;
|
|
24
24
|
return async (pkg: string): Promise<boolean> => {
|
|
25
25
|
const result = await showOverlay(ctx.ui, {
|
|
26
|
+
signal,
|
|
26
27
|
mode: "confirm",
|
|
27
28
|
title: "Install ast-grep grammar",
|
|
28
29
|
body: [
|
|
@@ -39,6 +40,7 @@ export function grammarConsent(ctx?: ExecuteCtx): ConsentFn | undefined {
|
|
|
39
40
|
{ value: "no", label: "Skip", description: "Do not install; skip this language" },
|
|
40
41
|
],
|
|
41
42
|
});
|
|
43
|
+
signal?.throwIfAborted();
|
|
42
44
|
return result.action === "approved";
|
|
43
45
|
};
|
|
44
46
|
}
|
package/src/icon-catalog.ts
CHANGED
|
@@ -32,6 +32,7 @@ const PRETTY_CATALOG = {
|
|
|
32
32
|
// ── agent mode (pix-core plan mode, footer) ───────────────────────────
|
|
33
33
|
"mode.plan": { nerd: "\u{F034D}", unicode: `\u2630${VS}`, ascii: "P" },
|
|
34
34
|
"mode.normal": { nerd: "\u{F0174}", unicode: `\u276F${VS}`, ascii: ">" },
|
|
35
|
+
"mode.nuclear": { nerd: "\u{F135}", unicode: "\u{1F680}", ascii: "^" },
|
|
35
36
|
// ── model kind (pix-models picker) ─────────────────────────────────────
|
|
36
37
|
"model.classifier": { nerd: "\u{F05D1}", unicode: `\u2696${VS}`, ascii: "C" },
|
|
37
38
|
// ── steering hint (pix-nudge cards): advice, not a warning — keep it off `⚠` ──
|
package/src/index.ts
CHANGED
|
@@ -15,9 +15,11 @@ import { fffState } from "./fff.ts";
|
|
|
15
15
|
import { clearHighlightCache } from "./highlight.ts";
|
|
16
16
|
import { initIconMode } from "./icon-persist.ts";
|
|
17
17
|
import { installOrderedWidgets } from "./ordered-widgets.ts";
|
|
18
|
+
import { installOverlayImages } from "./overlay-images.ts";
|
|
18
19
|
import type { PiPrettyApi } from "./types.ts";
|
|
19
20
|
|
|
20
21
|
export default function piPrettyExtension(pi: ExtensionAPI): void {
|
|
22
|
+
installOverlayImages();
|
|
21
23
|
once(pi, "pix-pretty-widgets", () => {
|
|
22
24
|
let restore: (() => void) | undefined;
|
|
23
25
|
pi.on("session_start", (_event, ctx) => {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TuiMainScreen } from "@earendil-works/pi-tui";
|
|
2
|
+
|
|
3
|
+
const PATCHED = Symbol.for("@xynogen/pix-pretty:overlay-images");
|
|
4
|
+
type Compositor = {
|
|
5
|
+
hasOverlay(): boolean;
|
|
6
|
+
compositeOverlays(lines: string[], width: number, height: number): string[];
|
|
7
|
+
[PATCHED]?: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/** Let the native renderer remove image placements before it draws an overlay. */
|
|
11
|
+
export function installOverlayImages(): void {
|
|
12
|
+
const prototype = Object.getPrototypeOf(TuiMainScreen.prototype) as Compositor;
|
|
13
|
+
if (prototype[PATCHED]) return;
|
|
14
|
+
const compose = prototype.compositeOverlays;
|
|
15
|
+
// ponytail: Pi skips overlay composition on image lines; suppress transcript images until upstream supports image occlusion.
|
|
16
|
+
prototype.compositeOverlays = function (lines, width, height) {
|
|
17
|
+
const background = this.hasOverlay()
|
|
18
|
+
? lines.map((line) =>
|
|
19
|
+
line.includes("\x1b_G") || line.includes("\x1b]1337;File=") ? "" : line,
|
|
20
|
+
)
|
|
21
|
+
: lines;
|
|
22
|
+
return compose.call(this, background, width, height);
|
|
23
|
+
};
|
|
24
|
+
prototype[PATCHED] = true;
|
|
25
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { onAbort } from "@xynogen/pix-runtime/abort";
|
|
2
|
+
|
|
3
|
+
/** Overlay lifetime with exactly-once completion; UI policy and timers stay with each component. */
|
|
4
|
+
export function createOverlayLifecycle<T>() {
|
|
5
|
+
const controller = new AbortController();
|
|
6
|
+
let done: ((value: T) => void) | undefined;
|
|
7
|
+
let result: { value: T } | undefined;
|
|
8
|
+
let notified = false;
|
|
9
|
+
const notify = () => {
|
|
10
|
+
if (!done || !result || notified) return;
|
|
11
|
+
notified = true;
|
|
12
|
+
done(result.value);
|
|
13
|
+
};
|
|
14
|
+
const dispose = () => controller.abort();
|
|
15
|
+
return {
|
|
16
|
+
get closed() {
|
|
17
|
+
return controller.signal.aborted;
|
|
18
|
+
},
|
|
19
|
+
onCleanup(cleanup: () => void) {
|
|
20
|
+
onAbort(controller.signal, cleanup);
|
|
21
|
+
},
|
|
22
|
+
bind(callback: (value: T) => void) {
|
|
23
|
+
done = callback;
|
|
24
|
+
notify();
|
|
25
|
+
},
|
|
26
|
+
finish(value: T) {
|
|
27
|
+
if (controller.signal.aborted) return;
|
|
28
|
+
result = { value };
|
|
29
|
+
dispose();
|
|
30
|
+
notify();
|
|
31
|
+
},
|
|
32
|
+
dispose,
|
|
33
|
+
};
|
|
34
|
+
}
|
package/src/progress.ts
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
modalWidth,
|
|
21
21
|
terminalModalHeight,
|
|
22
22
|
} from "./modal-frame.ts";
|
|
23
|
+
import { createOverlayLifecycle } from "./overlay-lifecycle.ts";
|
|
23
24
|
import { SPINNER } from "./widget-format.ts";
|
|
24
25
|
|
|
25
26
|
interface ProgressTheme {
|
|
@@ -49,8 +50,8 @@ export interface ProgressUI {
|
|
|
49
50
|
export interface ProgressHandle {
|
|
50
51
|
/** Update the status line shown under the title. */
|
|
51
52
|
setLabel(label: string): void;
|
|
52
|
-
/** Close the overlay
|
|
53
|
-
close(): void
|
|
53
|
+
/** Close the overlay, release input ownership, and propagate any host UI failure. */
|
|
54
|
+
close(): Promise<void>;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
// 120ms: smooth enough to read as motion, slow enough to barely touch the
|
|
@@ -63,51 +64,63 @@ const SPINNER_INTERVAL_MS = 120;
|
|
|
63
64
|
*/
|
|
64
65
|
export function openProgress(ui: ProgressUI, title: string, accent = "accent"): ProgressHandle {
|
|
65
66
|
let setLabelImpl: (label: string) => void = () => {};
|
|
66
|
-
|
|
67
|
+
const lifecycle = createOverlayLifecycle<void>();
|
|
68
|
+
let pending: Promise<void>;
|
|
69
|
+
try {
|
|
70
|
+
pending = ui
|
|
71
|
+
.custom<void>(
|
|
72
|
+
(tui, theme, _kb, done) => {
|
|
73
|
+
let frame = 0;
|
|
74
|
+
let labelValue = "Working…";
|
|
75
|
+
lifecycle.bind(done);
|
|
67
76
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
const ticker = setInterval(() => {
|
|
78
|
+
frame = (frame + 1) % SPINNER.length;
|
|
79
|
+
if (lifecycle.closed) return;
|
|
80
|
+
tui.requestRender();
|
|
81
|
+
}, SPINNER_INTERVAL_MS);
|
|
82
|
+
lifecycle.onCleanup(() => clearInterval(ticker));
|
|
72
83
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
84
|
+
setLabelImpl = (label: string) => {
|
|
85
|
+
if (lifecycle.closed) return;
|
|
86
|
+
labelValue = label;
|
|
87
|
+
tui.requestRender();
|
|
88
|
+
};
|
|
77
89
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
color: (s) => theme.fg(accent, s),
|
|
97
|
-
bg: (s) => theme.bg("customMessageBg", s),
|
|
98
|
-
}).lines;
|
|
90
|
+
return {
|
|
91
|
+
render: (w: number) => {
|
|
92
|
+
const mw = modalWidth(w);
|
|
93
|
+
return frameModal({
|
|
94
|
+
width: mw,
|
|
95
|
+
maxHeight: terminalModalHeight(tui.terminal?.rows),
|
|
96
|
+
minHeight: MIN_MODAL_HEIGHT,
|
|
97
|
+
header: [theme.fg(accent, theme.bold(title))],
|
|
98
|
+
body: [`${theme.fg(accent, SPINNER[frame] ?? "")} ${theme.fg("dim", labelValue)}`],
|
|
99
|
+
color: (s) => theme.fg(accent, s),
|
|
100
|
+
bg: (s) => theme.bg("customMessageBg", s),
|
|
101
|
+
}).lines;
|
|
102
|
+
},
|
|
103
|
+
invalidate: () => {},
|
|
104
|
+
// Swallow every keystroke: a focused overlay owns input, so nothing
|
|
105
|
+
// reaches the editor while the update runs.
|
|
106
|
+
handleInput: () => {},
|
|
107
|
+
};
|
|
99
108
|
},
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
)
|
|
109
|
+
{ overlay: true, overlayOptions: modalOverlayOptions() },
|
|
110
|
+
)
|
|
111
|
+
.finally(lifecycle.dispose);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
lifecycle.dispose();
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
// Observe early UI failures until the owner awaits close() in its finally block.
|
|
117
|
+
void pending.catch(() => {});
|
|
108
118
|
|
|
109
119
|
return {
|
|
110
120
|
setLabel: (label) => setLabelImpl(label),
|
|
111
|
-
close: () =>
|
|
121
|
+
close: async () => {
|
|
122
|
+
lifecycle.finish();
|
|
123
|
+
await pending;
|
|
124
|
+
},
|
|
112
125
|
};
|
|
113
126
|
}
|
package/src/shell-tool.ts
CHANGED
|
@@ -30,14 +30,14 @@ import {
|
|
|
30
30
|
dotJoin,
|
|
31
31
|
fadeRulePaint,
|
|
32
32
|
fillToolBackground,
|
|
33
|
-
formatCollapsedToolRow,
|
|
34
|
-
formatToolCallTitle,
|
|
35
33
|
frameToolResult,
|
|
36
34
|
getErrorMessage,
|
|
37
35
|
getTextContent,
|
|
38
36
|
hideCollapsedToolCall,
|
|
39
37
|
isTextContent,
|
|
40
38
|
moreLines,
|
|
39
|
+
renderRow,
|
|
40
|
+
renderTitle,
|
|
41
41
|
renderToolError,
|
|
42
42
|
ruleFrame,
|
|
43
43
|
setResultDetails,
|
|
@@ -150,7 +150,7 @@ export function registerShellTool(
|
|
|
150
150
|
resolveBaseBackground(theme);
|
|
151
151
|
const displayCmdRaw = (args.command ?? "").trim();
|
|
152
152
|
const text = renderCtx.lastComponent ?? new TextComponent("", 0, 0);
|
|
153
|
-
const label =
|
|
153
|
+
const label = renderTitle(theme, name, renderCtx);
|
|
154
154
|
const collapseState = renderCtx.state as CollapseState;
|
|
155
155
|
if (hideCollapsedToolCall(collapseState, renderCtx.expanded, (value) => text.setText(value)))
|
|
156
156
|
return text;
|
|
@@ -202,7 +202,7 @@ export function registerShellTool(
|
|
|
202
202
|
durationMs > 0 && formatDuration(durationMs, "bash"),
|
|
203
203
|
]);
|
|
204
204
|
return collapsedCommandRow(
|
|
205
|
-
|
|
205
|
+
renderRow(theme, name, "", meta, status).trimEnd(),
|
|
206
206
|
String(d.command ?? ""),
|
|
207
207
|
theme,
|
|
208
208
|
);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { EventBus } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { withAgentBlock } from "@xynogen/pix-runtime";
|
|
3
|
+
import { modalOverlayOptions } from "./modal-frame.ts";
|
|
4
|
+
|
|
5
|
+
export interface UserPromptState {
|
|
6
|
+
events: EventBus;
|
|
7
|
+
source: string;
|
|
8
|
+
message?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface UserPromptOptions {
|
|
12
|
+
overlay?: boolean;
|
|
13
|
+
overlayOptions?: ReturnType<typeof modalOverlayOptions>;
|
|
14
|
+
blocked?: { kind: "permission" | "auth" | "question"; message: string };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Keep native terminal status and Pix notifications scoped to the same prompt. */
|
|
18
|
+
export function withUserPrompt<T>(
|
|
19
|
+
blocked: NonNullable<UserPromptOptions["blocked"]>,
|
|
20
|
+
open: (options: UserPromptOptions) => Promise<T>,
|
|
21
|
+
state?: UserPromptState,
|
|
22
|
+
): Promise<T> {
|
|
23
|
+
const prompt = () => open({ overlay: true, overlayOptions: modalOverlayOptions(), blocked });
|
|
24
|
+
return state
|
|
25
|
+
? withAgentBlock(state.events, state.source, state.message ?? blocked.message, prompt)
|
|
26
|
+
: prompt();
|
|
27
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
hyperlink,
|
|
8
8
|
MouseRegion,
|
|
9
9
|
mixColors,
|
|
10
|
+
Text,
|
|
10
11
|
truncateToWidth,
|
|
11
12
|
visibleWidth,
|
|
12
13
|
} from "@earendil-works/pi-tui";
|
|
@@ -356,13 +357,14 @@ export function widgetActivityRow(
|
|
|
356
357
|
}
|
|
357
358
|
|
|
358
359
|
/** Use the host lifecycle fields so every call has the same status marker. */
|
|
359
|
-
export function
|
|
360
|
+
export function renderTitle(
|
|
360
361
|
theme: {
|
|
361
362
|
fg: (role: "muted" | "warning" | "error" | "success" | "toolTitle", text: string) => string;
|
|
362
363
|
bold?: (text: string) => string;
|
|
363
364
|
},
|
|
364
365
|
tool: string,
|
|
365
366
|
context: { executionStarted?: boolean; isPartial?: boolean; isError?: boolean } = {},
|
|
367
|
+
action?: string,
|
|
366
368
|
): string {
|
|
367
369
|
const complete = context.isPartial === false;
|
|
368
370
|
const role = complete
|
|
@@ -379,11 +381,42 @@ export function formatToolCallTitle(
|
|
|
379
381
|
: context.executionStarted
|
|
380
382
|
? "status.running"
|
|
381
383
|
: "status.pending";
|
|
382
|
-
|
|
384
|
+
const label = action ? `${tool} ${action}` : tool;
|
|
385
|
+
return `${theme.fg(role, padIcon(icon(marker)))} ${theme.fg("toolTitle", theme.bold?.(label) ?? label)}`;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/** Build a plain call renderer; command and rich previews keep their own body. */
|
|
389
|
+
export function renderCall<TArgs = Record<string, unknown>>(
|
|
390
|
+
tool: string,
|
|
391
|
+
target: (args: TArgs) => string,
|
|
392
|
+
action?: (args: TArgs) => string | undefined,
|
|
393
|
+
) {
|
|
394
|
+
return (
|
|
395
|
+
args: TArgs,
|
|
396
|
+
theme: Parameters<typeof renderTitle>[0] & { fg: (role: "dim", text: string) => string },
|
|
397
|
+
context: Parameters<typeof renderTitle>[2] & {
|
|
398
|
+
lastComponent?: Component;
|
|
399
|
+
state: Record<string, unknown>;
|
|
400
|
+
expanded: boolean;
|
|
401
|
+
},
|
|
402
|
+
): Component => {
|
|
403
|
+
const previous = context.lastComponent && unframeToolResult(context.lastComponent);
|
|
404
|
+
const text =
|
|
405
|
+
previous && "setText" in previous && typeof previous.setText === "function"
|
|
406
|
+
? (previous as Component & { setText(value: string): void })
|
|
407
|
+
: new Text("", 0, 0);
|
|
408
|
+
if (hideCollapsedToolCall(context.state, context.expanded, (value) => text.setText(value)))
|
|
409
|
+
return text;
|
|
410
|
+
const value = target(args);
|
|
411
|
+
text.setText(
|
|
412
|
+
`${renderTitle(theme, tool, context, action?.(args))}${value ? ` ${theme.fg("dim", value)}` : ""}`,
|
|
413
|
+
);
|
|
414
|
+
return text;
|
|
415
|
+
};
|
|
383
416
|
}
|
|
384
417
|
|
|
385
418
|
/** Format the shared one-row content without assuming a render shell. */
|
|
386
|
-
export function
|
|
419
|
+
export function renderRow(
|
|
387
420
|
theme: CollapsedToolTheme,
|
|
388
421
|
tool: string,
|
|
389
422
|
target: string,
|
|
@@ -404,7 +437,7 @@ export function formatCollapsedToolRow(
|
|
|
404
437
|
}
|
|
405
438
|
|
|
406
439
|
/** Render shared one-row content for tools using the self-rendered shell. */
|
|
407
|
-
export function
|
|
440
|
+
export function renderCollapsed(
|
|
408
441
|
theme: CollapsedToolTheme,
|
|
409
442
|
tool: string,
|
|
410
443
|
target: string,
|
|
@@ -413,7 +446,7 @@ export function renderCollapsedToolRow(
|
|
|
413
446
|
width?: number,
|
|
414
447
|
): string {
|
|
415
448
|
return fillToolBackground(
|
|
416
|
-
|
|
449
|
+
renderRow(theme, tool, target, meta, status, width ?? termW()),
|
|
417
450
|
BG_BASE,
|
|
418
451
|
width,
|
|
419
452
|
);
|