proper-base 0.3.0 → 0.5.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/README.md +1 -1
- package/index.ts +44 -4
- package/package.json +3 -3
- package/src/autocomplete-details.ts +41 -3
- package/src/clipboard-guard.ts +181 -0
- package/src/editor-navigation.ts +32 -1
- package/src/image-preview.ts +31 -7
- package/src/osc8-link-ids.ts +90 -0
- package/src/prompt-jump.ts +308 -54
- package/src/rail-setting.ts +200 -0
- package/src/selection-dismiss.ts +10 -2
- package/src/transcript-cleanup.ts +107 -8
- package/src/wheel-scroll.ts +46 -0
package/src/selection-dismiss.ts
CHANGED
|
@@ -52,7 +52,11 @@ export function isTypingInput(data: string): boolean {
|
|
|
52
52
|
*
|
|
53
53
|
* The listener registers after the renderer's own constructor-installed
|
|
54
54
|
* listener, so it only sees input the viewport declined: scroll keys and
|
|
55
|
-
* mouse gestures keep the selection, matching terminal convention.
|
|
55
|
+
* mouse gestures keep the selection, matching terminal convention. Keys the
|
|
56
|
+
* caller marks preserved also keep it: Pi 0.84.4's `app.message.copy` action
|
|
57
|
+
* (Ctrl+X) copies the active selection when `fullscreenCopyOnSelect` is
|
|
58
|
+
* disabled, and it runs at the editor after this listener, so dismissing on
|
|
59
|
+
* that keystroke would clear the selection before the copy reads it. It resets
|
|
56
60
|
* the same private fields the renderer's focus-loss branch resets and never
|
|
57
61
|
* consumes the input, so the keystroke still reaches the editor.
|
|
58
62
|
*
|
|
@@ -62,7 +66,10 @@ export function isTypingInput(data: string): boolean {
|
|
|
62
66
|
*
|
|
63
67
|
* @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Selection dismissal]]
|
|
64
68
|
*/
|
|
65
|
-
export function installSelectionDismiss(
|
|
69
|
+
export function installSelectionDismiss(
|
|
70
|
+
tui: TUI,
|
|
71
|
+
isPreservedInput?: (data: string) => boolean,
|
|
72
|
+
): (() => void) | undefined {
|
|
66
73
|
const host = tui as SelectionHost;
|
|
67
74
|
if (
|
|
68
75
|
typeof host.getSelectionBounds !== "function" ||
|
|
@@ -79,6 +86,7 @@ export function installSelectionDismiss(tui: TUI): (() => void) | undefined {
|
|
|
79
86
|
if (host.selectionPressActive) return undefined;
|
|
80
87
|
if (host.getSelectionBounds?.() === undefined) return undefined;
|
|
81
88
|
if (!isTypingInput(data)) return undefined;
|
|
89
|
+
if (isPreservedInput?.(data)) return undefined;
|
|
82
90
|
host.stopSelectionAutoScroll?.();
|
|
83
91
|
host.selectionAnchor = undefined;
|
|
84
92
|
host.selectionFocus = undefined;
|
|
@@ -41,6 +41,7 @@ type State = {
|
|
|
41
41
|
expanded: Map<object, boolean>;
|
|
42
42
|
hits: Map<number, DetailHit>;
|
|
43
43
|
pendingHits: DetailHit[];
|
|
44
|
+
outline: OutlineEntry[];
|
|
44
45
|
globalExpanded: boolean;
|
|
45
46
|
assistantCache: WeakMap<AssistantComponent, AssistantRenderCache>;
|
|
46
47
|
};
|
|
@@ -50,6 +51,17 @@ type AssistantRenderCache = {
|
|
|
50
51
|
lines: Map<string, string[]>;
|
|
51
52
|
};
|
|
52
53
|
type DetailKind = "tool" | "error";
|
|
54
|
+
/**
|
|
55
|
+
* One transcript action, in scroll-content coordinates.
|
|
56
|
+
*
|
|
57
|
+
* @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Session action rail]]
|
|
58
|
+
*/
|
|
59
|
+
export type OutlineEntry = {
|
|
60
|
+
row: number;
|
|
61
|
+
kind: "user" | "assistant" | "tool" | "error";
|
|
62
|
+
/** Short action-type name: `prompt`, `reply`, or the tool's name. */
|
|
63
|
+
label: string;
|
|
64
|
+
};
|
|
53
65
|
type Detail = {
|
|
54
66
|
owner: object;
|
|
55
67
|
kind: DetailKind;
|
|
@@ -84,6 +96,7 @@ export type TranscriptCleanupController = {
|
|
|
84
96
|
completeAssistant(message: object): void;
|
|
85
97
|
completeTool(toolCallId: string): void;
|
|
86
98
|
settle(): void;
|
|
99
|
+
outline(): OutlineEntry[];
|
|
87
100
|
update(ctx: ExtensionContext, tui: TUI): void;
|
|
88
101
|
uninstall(): void;
|
|
89
102
|
};
|
|
@@ -109,6 +122,7 @@ export function installTranscriptCleanup(
|
|
|
109
122
|
expanded: new Map(),
|
|
110
123
|
hits: new Map(),
|
|
111
124
|
pendingHits: [],
|
|
125
|
+
outline: [],
|
|
112
126
|
globalExpanded: ctx.ui.getToolsExpanded(),
|
|
113
127
|
assistantCache: new WeakMap(),
|
|
114
128
|
};
|
|
@@ -170,6 +184,9 @@ export function installTranscriptCleanup(
|
|
|
170
184
|
};
|
|
171
185
|
state.tui.requestRender();
|
|
172
186
|
},
|
|
187
|
+
outline() {
|
|
188
|
+
return state.outline;
|
|
189
|
+
},
|
|
173
190
|
update(nextCtx, nextTui) {
|
|
174
191
|
state = {
|
|
175
192
|
...state,
|
|
@@ -197,17 +214,34 @@ export function installTranscriptCleanup(
|
|
|
197
214
|
state = { ...state, globalExpanded, expanded: new Map() };
|
|
198
215
|
}
|
|
199
216
|
state.pendingHits.length = 0;
|
|
217
|
+
const sink: OutlineEntry[] = [];
|
|
200
218
|
let lines: string[];
|
|
201
219
|
if (state.activeStart === undefined && state.ctx.isIdle()) {
|
|
202
|
-
lines = renderCollapsed(chat.children, width, state);
|
|
220
|
+
lines = renderCollapsed(chat.children, width, state, sink);
|
|
203
221
|
} else {
|
|
204
222
|
const start = state.activeStart ?? chat.children.length;
|
|
223
|
+
const collapsed = renderCollapsed(
|
|
224
|
+
chat.children.slice(0, start),
|
|
225
|
+
width,
|
|
226
|
+
state,
|
|
227
|
+
sink,
|
|
228
|
+
);
|
|
205
229
|
lines = [
|
|
206
|
-
...
|
|
207
|
-
...renderActive(
|
|
230
|
+
...collapsed,
|
|
231
|
+
...renderActive(
|
|
232
|
+
chat.children.slice(start),
|
|
233
|
+
width,
|
|
234
|
+
state,
|
|
235
|
+
sink,
|
|
236
|
+
collapsed.length,
|
|
237
|
+
),
|
|
208
238
|
];
|
|
209
239
|
}
|
|
210
|
-
|
|
240
|
+
const offset = documentRowOffset(document, chat, width);
|
|
241
|
+
state.outline = sink
|
|
242
|
+
.map((entry) => ({ ...entry, row: offset + entry.row }))
|
|
243
|
+
.sort((a, b) => a.row - b.row);
|
|
244
|
+
indexDetailHits(lines, offset, state);
|
|
211
245
|
return lines;
|
|
212
246
|
};
|
|
213
247
|
chat[INSTALLED] = controller;
|
|
@@ -218,6 +252,8 @@ function renderActive(
|
|
|
218
252
|
children: Component[],
|
|
219
253
|
width: number,
|
|
220
254
|
state: State,
|
|
255
|
+
sink: OutlineEntry[],
|
|
256
|
+
base: number,
|
|
221
257
|
): string[] {
|
|
222
258
|
const output: string[][] = Array.from({ length: children.length });
|
|
223
259
|
let hasTextBelow = false;
|
|
@@ -227,23 +263,54 @@ function renderActive(
|
|
|
227
263
|
const native = child.render(width);
|
|
228
264
|
output[index] =
|
|
229
265
|
state.completed.has(child) && hasTextBelow
|
|
230
|
-
? renderGroup([child], width, state)
|
|
266
|
+
? renderGroup([child], width, state, [], 0)
|
|
231
267
|
: native;
|
|
232
268
|
if (hasSectionText(native)) hasTextBelow = true;
|
|
233
269
|
}
|
|
270
|
+
// Outline rows are recorded on a forward pass because the render loop above
|
|
271
|
+
// walks backwards; the discarded renderGroup sink avoids double records.
|
|
272
|
+
let row = base;
|
|
273
|
+
for (let index = 0; index < children.length; index++) {
|
|
274
|
+
const rendered = output[index];
|
|
275
|
+
const child = children[index];
|
|
276
|
+
if (child && rendered?.length) {
|
|
277
|
+
const entry = actionEntry(child);
|
|
278
|
+
if (entry) sink.push({ ...entry, row });
|
|
279
|
+
}
|
|
280
|
+
row += rendered?.length ?? 0;
|
|
281
|
+
}
|
|
234
282
|
return output.flat();
|
|
235
283
|
}
|
|
236
284
|
|
|
285
|
+
function actionEntry(child: Component): Omit<OutlineEntry, "row"> | undefined {
|
|
286
|
+
if (isUserBoundary(child)) {
|
|
287
|
+
return { kind: "user", label: "prompt" };
|
|
288
|
+
}
|
|
289
|
+
const name = componentName(child);
|
|
290
|
+
if (name === "AssistantMessageComponent") {
|
|
291
|
+
return { kind: "assistant", label: "reply" };
|
|
292
|
+
}
|
|
293
|
+
if (name === "ToolExecutionComponent") {
|
|
294
|
+
const tool = child as ToolComponent;
|
|
295
|
+
return {
|
|
296
|
+
kind: tool.result?.isError === true ? "error" : "tool",
|
|
297
|
+
label: tool.toolName ?? "tool",
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
return undefined;
|
|
301
|
+
}
|
|
302
|
+
|
|
237
303
|
function renderCollapsed(
|
|
238
304
|
children: Component[],
|
|
239
305
|
width: number,
|
|
240
306
|
state: State,
|
|
307
|
+
sink: OutlineEntry[],
|
|
241
308
|
): string[] {
|
|
242
309
|
const lines: string[] = [];
|
|
243
310
|
let group: Component[] = [];
|
|
244
311
|
const flush = () => {
|
|
245
312
|
if (!group.length) return;
|
|
246
|
-
lines.push(...renderGroup(group, width, state));
|
|
313
|
+
lines.push(...renderGroup(group, width, state, sink, lines.length));
|
|
247
314
|
group = [];
|
|
248
315
|
};
|
|
249
316
|
|
|
@@ -278,12 +345,19 @@ function renderGroup(
|
|
|
278
345
|
group: Component[],
|
|
279
346
|
width: number,
|
|
280
347
|
state: State,
|
|
348
|
+
sink: OutlineEntry[],
|
|
349
|
+
base: number,
|
|
281
350
|
): string[] {
|
|
282
351
|
const lines: string[] = [];
|
|
283
352
|
|
|
284
353
|
for (const child of group) {
|
|
285
354
|
const name = componentName(child);
|
|
286
355
|
if (isUserBoundary(child)) {
|
|
356
|
+
sink.push({
|
|
357
|
+
kind: "user",
|
|
358
|
+
row: base + lines.length,
|
|
359
|
+
label: "prompt",
|
|
360
|
+
});
|
|
287
361
|
lines.push(...child.render(width));
|
|
288
362
|
continue;
|
|
289
363
|
}
|
|
@@ -292,10 +366,18 @@ function renderGroup(
|
|
|
292
366
|
continue;
|
|
293
367
|
}
|
|
294
368
|
if (name === "AssistantMessageComponent") {
|
|
369
|
+
const startRow = lines.length;
|
|
295
370
|
const assistant = child as AssistantComponent;
|
|
296
371
|
const message = assistant.lastMessage;
|
|
297
372
|
if (!message || !assistant.updateContent) {
|
|
298
373
|
lines.push(...child.render(width));
|
|
374
|
+
if (lines.length > startRow) {
|
|
375
|
+
sink.push({
|
|
376
|
+
kind: "assistant",
|
|
377
|
+
row: base + startRow,
|
|
378
|
+
label: "reply",
|
|
379
|
+
});
|
|
380
|
+
}
|
|
299
381
|
continue;
|
|
300
382
|
}
|
|
301
383
|
const hasToolCall = message.content.some(
|
|
@@ -344,11 +426,25 @@ function renderGroup(
|
|
|
344
426
|
);
|
|
345
427
|
}
|
|
346
428
|
}
|
|
429
|
+
// A turn whose reply was only tool calls emits nothing of its own; its
|
|
430
|
+
// visible actions are the tool rows, so no assistant entry is recorded.
|
|
431
|
+
if (lines.length > startRow) {
|
|
432
|
+
sink.push({
|
|
433
|
+
kind: "assistant",
|
|
434
|
+
row: base + startRow,
|
|
435
|
+
label: "reply",
|
|
436
|
+
});
|
|
437
|
+
}
|
|
347
438
|
continue;
|
|
348
439
|
}
|
|
349
440
|
if (name === "ToolExecutionComponent") {
|
|
350
441
|
const tool = child as ToolComponent;
|
|
351
442
|
const error = tool.result?.isError === true;
|
|
443
|
+
sink.push({
|
|
444
|
+
kind: error ? "error" : "tool",
|
|
445
|
+
row: base + lines.length,
|
|
446
|
+
label: tool.toolName ?? "tool",
|
|
447
|
+
});
|
|
352
448
|
lines.push(
|
|
353
449
|
...renderDetail(
|
|
354
450
|
{
|
|
@@ -488,6 +584,10 @@ function detailColor(
|
|
|
488
584
|
}
|
|
489
585
|
|
|
490
586
|
function describeTool(tool: ToolComponent, error: boolean): string {
|
|
587
|
+
return `${error ? "error" : "tool"} · ${toolLabel(tool)}`;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function toolLabel(tool: ToolComponent): string {
|
|
491
591
|
const name = tool.toolName ?? "tool";
|
|
492
592
|
const args = asRecord(tool.args);
|
|
493
593
|
const value = [
|
|
@@ -502,8 +602,7 @@ function describeTool(tool: ToolComponent, error: boolean): string {
|
|
|
502
602
|
]
|
|
503
603
|
.map((key) => args?.[key])
|
|
504
604
|
.find((candidate): candidate is string => typeof candidate === "string");
|
|
505
|
-
|
|
506
|
-
return `${error ? "error" : "tool"} · ${name}${target}`;
|
|
605
|
+
return value ? `${name} · ${oneLine(value)}` : name;
|
|
507
606
|
}
|
|
508
607
|
|
|
509
608
|
function oneLine(text: string): string {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pi's fullscreen renderer scrolls its transcript exactly one line per
|
|
3
|
+
* mouse-wheel report: the renderer's `wheelScrollLines` option defaults to 1
|
|
4
|
+
* and pi passes no override and exposes no setting. Terminals natively
|
|
5
|
+
* multiply a wheel notch to about three lines, so fullscreen scrolling feels
|
|
6
|
+
* slower than every other terminal surface.
|
|
7
|
+
*
|
|
8
|
+
* No escape sequence lets an application query the terminal's own wheel
|
|
9
|
+
* configuration, so the step defaults to the 3-line application convention
|
|
10
|
+
* (vim, less) and honors a per-terminal `PROPER_WHEEL_SCROLL_LINES`
|
|
11
|
+
* environment override that each terminal's profile can export.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const DEFAULT_WHEEL_SCROLL_LINES = 3;
|
|
15
|
+
|
|
16
|
+
/** Renderer surface carrying the per-wheel-event line count. */
|
|
17
|
+
type WheelHost = { wheelScrollLines?: unknown };
|
|
18
|
+
|
|
19
|
+
/** Lines per wheel event: a positive integer override, else the 3-line convention. */
|
|
20
|
+
export function resolveWheelScrollLines(
|
|
21
|
+
env: Record<string, string | undefined> = process.env,
|
|
22
|
+
): number {
|
|
23
|
+
const parsed = Number.parseInt(env.PROPER_WHEEL_SCROLL_LINES ?? "", 10);
|
|
24
|
+
return parsed >= 1 ? parsed : DEFAULT_WHEEL_SCROLL_LINES;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Raise the fullscreen renderer's wheel step. Only a renderer that already
|
|
29
|
+
* exposes a numeric `wheelScrollLines` is touched, so regular mode — where
|
|
30
|
+
* the terminal scrolls natively — and a renamed upstream field fail open to
|
|
31
|
+
* pi's own behavior.
|
|
32
|
+
*
|
|
33
|
+
* ponytail: SGR wheel reports cannot distinguish a discrete mouse notch from
|
|
34
|
+
* one line of a high-rate trackpad stream, so a terminal emitting one report
|
|
35
|
+
* per native line scrolls proportionally faster; exporting
|
|
36
|
+
* PROPER_WHEEL_SCROLL_LINES=1 there restores pi's original pace.
|
|
37
|
+
*/
|
|
38
|
+
export function installWheelScrollLines(
|
|
39
|
+
tui: unknown,
|
|
40
|
+
lines: number = resolveWheelScrollLines(),
|
|
41
|
+
): boolean {
|
|
42
|
+
const host = tui as WheelHost;
|
|
43
|
+
if (typeof host.wheelScrollLines !== "number") return false;
|
|
44
|
+
host.wheelScrollLines = Math.floor(lines);
|
|
45
|
+
return true;
|
|
46
|
+
}
|