@xynogen/pix-pretty 1.38.0 → 2.0.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/package.json +3 -2
- package/src/command-preview.ts +2 -3
- package/src/confirm.ts +89 -86
- package/src/gate-overlay.ts +160 -157
- package/src/index.ts +2 -0
- package/src/overlay-images.ts +25 -0
- 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.1",
|
|
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",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"./confirm": "./src/confirm.ts",
|
|
12
12
|
"./progress": "./src/progress.ts",
|
|
13
13
|
"./overlay-lifecycle": "./src/overlay-lifecycle.ts",
|
|
14
|
+
"./user-prompt": "./src/user-prompt.ts",
|
|
14
15
|
"./config": "./src/config.ts",
|
|
15
16
|
"./diff": "./src/diff.ts",
|
|
16
17
|
"./diff-render": "./src/diff-render.ts",
|
|
@@ -71,7 +72,7 @@
|
|
|
71
72
|
"access": "public"
|
|
72
73
|
},
|
|
73
74
|
"dependencies": {
|
|
74
|
-
"@xynogen/pix-runtime": "^0.
|
|
75
|
+
"@xynogen/pix-runtime": "^0.19.0",
|
|
75
76
|
"chalk": "^4.1.2",
|
|
76
77
|
"cli-highlight": "^2.1.11",
|
|
77
78
|
"@ff-labs/fff-node": "^0.10.6",
|
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,12 +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";
|
|
18
17
|
import { createOverlayLifecycle } from "./overlay-lifecycle.ts";
|
|
18
|
+
import { type UserPromptOptions, type UserPromptState, withUserPrompt } from "./user-prompt.ts";
|
|
19
19
|
|
|
20
20
|
// Minimal structural type for the `ctx.ui.custom` host call.
|
|
21
21
|
interface CustomTheme {
|
|
@@ -39,11 +39,12 @@ export interface ConfirmUI {
|
|
|
39
39
|
kb: KeybindingsManager,
|
|
40
40
|
done: (v: T) => void,
|
|
41
41
|
) => CustomComponent,
|
|
42
|
-
opts?:
|
|
42
|
+
opts?: UserPromptOptions,
|
|
43
43
|
): Promise<T | undefined>;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
export interface ConfirmOptions {
|
|
47
|
+
state?: UserPromptState;
|
|
47
48
|
/** Optional leading glyph for the title row, e.g. `icon("update")`. Rendered
|
|
48
49
|
* as "<icon> <title>" so callers pass a resolved icon + plain text. */
|
|
49
50
|
icon?: string;
|
|
@@ -77,97 +78,99 @@ export async function confirmOverlay(ui: ConfirmUI, opts: ConfirmOptions): Promi
|
|
|
77
78
|
const timer = timeoutMs > 0 ? setTimeout(() => finish(false), timeoutMs) : undefined;
|
|
78
79
|
lifecycle.onCleanup(() => clearTimeout(timer));
|
|
79
80
|
return (
|
|
80
|
-
(await
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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);
|
|
87
90
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
+
];
|
|
100
103
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
const selectList = new SelectList(
|
|
105
|
+
choices,
|
|
106
|
+
choices.length,
|
|
107
|
+
selectListTheme(theme, accent),
|
|
108
|
+
);
|
|
106
109
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
updateCountdown();
|
|
118
|
-
ticker = setInterval(() => {
|
|
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
|
+
};
|
|
119
120
|
updateCountdown();
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
ticker = setInterval(() => {
|
|
122
|
+
updateCountdown();
|
|
123
|
+
tui.requestRender();
|
|
124
|
+
}, SECOND_MS);
|
|
125
|
+
}
|
|
123
126
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
+
);
|
|
135
138
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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);
|
|
162
169
|
tui.requestRender();
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
},
|
|
168
|
-
};
|
|
169
|
-
},
|
|
170
|
-
{ overlay: true, overlayOptions: modalOverlayOptions() },
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
}, options),
|
|
173
|
+
opts.state,
|
|
171
174
|
)) ?? false
|
|
172
175
|
);
|
|
173
176
|
} finally {
|
package/src/gate-overlay.ts
CHANGED
|
@@ -23,12 +23,12 @@ import {
|
|
|
23
23
|
MIN_PERMISSION_MODAL_HEIGHT,
|
|
24
24
|
type ModalPageKeybindings,
|
|
25
25
|
ModalPager,
|
|
26
|
-
modalOverlayOptions,
|
|
27
26
|
modalWidth,
|
|
28
27
|
selectListTheme,
|
|
29
28
|
terminalModalHeight,
|
|
30
29
|
} from "./modal-frame.ts";
|
|
31
30
|
import { createOverlayLifecycle } from "./overlay-lifecycle.ts";
|
|
31
|
+
import { type UserPromptOptions, type UserPromptState, withUserPrompt } from "./user-prompt.ts";
|
|
32
32
|
|
|
33
33
|
// ── Types ─────────────────────────────────────────────────────────────────────
|
|
34
34
|
|
|
@@ -51,6 +51,7 @@ export interface OverlayChoice {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
interface BaseConfig {
|
|
54
|
+
state?: UserPromptState;
|
|
54
55
|
signal?: AbortSignal;
|
|
55
56
|
/** Accent colour token (e.g. "error", "warning", "accent"). Default "accent". */
|
|
56
57
|
accent?: string;
|
|
@@ -124,7 +125,7 @@ export interface OverlayUI {
|
|
|
124
125
|
kb: unknown,
|
|
125
126
|
done: (v: T) => void,
|
|
126
127
|
) => OverlayComponent,
|
|
127
|
-
opts?:
|
|
128
|
+
opts?: UserPromptOptions,
|
|
128
129
|
): Promise<T | undefined>;
|
|
129
130
|
}
|
|
130
131
|
|
|
@@ -278,172 +279,174 @@ export async function showOverlay(ui: OverlayUI, config: OverlayConfig): Promise
|
|
|
278
279
|
const finish = lifecycle.finish;
|
|
279
280
|
try {
|
|
280
281
|
return (
|
|
281
|
-
(await
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
// ── components ──────────────────────────────────────────────────
|
|
306
|
-
const selectItems: SelectItem[] = choices.map((c) => ({
|
|
307
|
-
value: c.value,
|
|
308
|
-
label: c.label,
|
|
309
|
-
description: c.description,
|
|
310
|
-
}));
|
|
311
|
-
|
|
312
|
-
const selectList = new SelectList(
|
|
313
|
-
selectItems,
|
|
314
|
-
selectItems.length,
|
|
315
|
-
selectListTheme(theme, accent),
|
|
316
|
-
);
|
|
317
|
-
const maskedInput = new MaskedInput();
|
|
318
|
-
|
|
319
|
-
lifecycle.onCleanup(cancelTimer);
|
|
320
|
-
lifecycle.onCleanup(() => validation.abort());
|
|
321
|
-
lifecycle.bind(done);
|
|
322
|
-
lifecycle.onCleanup(onAbort(config.signal, () => finish({ action: "denied" })));
|
|
323
|
-
|
|
324
|
-
// Arm the dead-man's switch (only when a timeout was requested).
|
|
325
|
-
if (!lifecycle.closed && timeoutMs > 0) {
|
|
326
|
-
const urgencyColor = (s: number): string =>
|
|
327
|
-
s <= 5 ? "error" : s <= 15 ? "warning" : "muted";
|
|
328
|
-
const countdownText = (s: number): string => {
|
|
329
|
-
const color = urgencyColor(s);
|
|
330
|
-
const text = `auto-deny in ${s}s`;
|
|
331
|
-
return s <= 5 ? theme.bold(theme.fg(color, text)) : theme.fg(color, text);
|
|
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;
|
|
332
306
|
};
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
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
|
+
};
|
|
340
336
|
countdownLine = countdownText(remaining);
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
stage = "password";
|
|
351
|
-
tui.requestRender();
|
|
352
|
-
} else {
|
|
353
|
-
finish({ action: "approved", choice: item.value });
|
|
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);
|
|
354
346
|
}
|
|
355
|
-
};
|
|
356
|
-
selectList.onCancel = () => finish({ action: "denied" });
|
|
357
347
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
valid = await config.validatePassword(pw, validation.signal);
|
|
371
|
-
} catch {
|
|
372
|
-
finish({ action: "denied" });
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
if (lifecycle.closed) return;
|
|
376
|
-
validatingPassword = false;
|
|
377
|
-
if (valid) {
|
|
378
|
-
finish({ action: "approved", password: pw });
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
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" });
|
|
381
360
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
return;
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
// ── component interface ──────────────────────────────────────────
|
|
398
|
-
return {
|
|
399
|
-
render: (w) => {
|
|
400
|
-
const mw = modalWidth(w);
|
|
401
|
-
const sections = buildSections({
|
|
402
|
-
theme,
|
|
403
|
-
accent,
|
|
404
|
-
config,
|
|
405
|
-
stage,
|
|
406
|
-
selectList,
|
|
407
|
-
maskedInput,
|
|
408
|
-
countdownLine,
|
|
409
|
-
passwordStatus,
|
|
410
|
-
width: mw,
|
|
411
|
-
});
|
|
412
|
-
const result = frameModal({
|
|
413
|
-
width: mw,
|
|
414
|
-
maxHeight: terminalModalHeight(tui.terminal?.rows),
|
|
415
|
-
minHeight: MIN_PERMISSION_MODAL_HEIGHT,
|
|
416
|
-
...sections,
|
|
417
|
-
bodyOffset: pager.bodyOffset,
|
|
418
|
-
color: (s) => theme.fg(accent, s),
|
|
419
|
-
bg: (s) => theme.bg("customMessageBg", s),
|
|
420
|
-
fg: (s) => theme.fg("text", s),
|
|
421
|
-
overflowLine: ({ page, totalPages }) =>
|
|
422
|
-
theme.fg("muted", `←→/PgUp/PgDn inspect • ${page}/${totalPages}`),
|
|
423
|
-
});
|
|
424
|
-
pager.sync(result);
|
|
425
|
-
return result.lines;
|
|
426
|
-
},
|
|
427
|
-
invalidate: () => {},
|
|
428
|
-
handleInput: (data) => {
|
|
429
|
-
if (lifecycle.closed) return;
|
|
430
|
-
if (matchesKey(data, "escape")) {
|
|
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…";
|
|
370
|
+
tui.requestRender();
|
|
371
|
+
let valid: boolean;
|
|
372
|
+
try {
|
|
373
|
+
valid = await config.validatePassword(pw, validation.signal);
|
|
374
|
+
} catch {
|
|
431
375
|
finish({ action: "denied" });
|
|
432
376
|
return;
|
|
433
377
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
if (
|
|
437
|
-
|
|
378
|
+
if (lifecycle.closed) return;
|
|
379
|
+
validatingPassword = false;
|
|
380
|
+
if (valid) {
|
|
381
|
+
finish({ action: "approved", password: pw });
|
|
438
382
|
return;
|
|
439
383
|
}
|
|
440
|
-
|
|
441
|
-
|
|
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}`;
|
|
442
394
|
tui.requestRender();
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
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,
|
|
447
450
|
)) ?? { action: "denied" }
|
|
448
451
|
);
|
|
449
452
|
} finally {
|
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
|
+
}
|
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
|
);
|