@adeildo/pi-look 5.15.0 → 6.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/README.md +54 -44
- package/assets/preview.png +0 -0
- package/package.json +3 -2
- package/src/data/git.ts +1 -1
- package/src/data/github.ts +6 -17
- package/src/data/runner.ts +3 -4
- package/src/data/snapshot.ts +24 -13
- package/src/data/start-notes.ts +2 -6
- package/src/data/telemetry.ts +13 -16
- package/src/data/totals.ts +14 -73
- package/src/data/visits.ts +2 -3
- package/src/index.ts +66 -18
- package/src/render/diff.ts +104 -0
- package/src/render/fit.ts +1 -1
- package/src/render/format.ts +1 -2
- package/src/render/glyphs.ts +23 -10
- package/src/render/paint.ts +4 -4
- package/src/render/segments.ts +112 -33
- package/src/render/streaming.ts +17 -40
- package/src/render/tools.ts +4 -6
- package/src/settings.ts +5 -7
- package/src/ui/editor.ts +11 -8
- package/src/ui/footer.ts +4 -11
- package/src/ui/header.ts +25 -18
- package/src/ui/outputs.ts +5 -11
- package/src/ui/pi-entries.ts +29 -27
- package/src/ui/previews.ts +2 -6
- package/src/ui/queue.ts +8 -8
- package/src/ui/screen.ts +1 -8
- package/src/ui/tool-frame.ts +84 -91
- package/src/view/state.ts +97 -0
- package/src/view/transcript.ts +175 -0
- package/src/view/view.ts +161 -0
package/src/render/segments.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type AccountWindow,
|
|
3
|
+
type BoardCard,
|
|
4
|
+
formatClock,
|
|
5
|
+
type PeerMark,
|
|
6
|
+
type RoomMark,
|
|
7
|
+
} from "@adeildo/pi-kit";
|
|
2
8
|
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
3
9
|
|
|
4
10
|
import type { Snapshot } from "../data/snapshot.ts";
|
|
@@ -26,8 +32,9 @@ export const SEGMENT_IDS = [
|
|
|
26
32
|
"path",
|
|
27
33
|
"branch",
|
|
28
34
|
"host",
|
|
35
|
+
"me",
|
|
29
36
|
"session",
|
|
30
|
-
"
|
|
37
|
+
"board",
|
|
31
38
|
"peers",
|
|
32
39
|
"version",
|
|
33
40
|
"clock",
|
|
@@ -51,7 +58,7 @@ export const SEGMENT_IDS = [
|
|
|
51
58
|
] as const;
|
|
52
59
|
|
|
53
60
|
export type BuiltinSegment = (typeof SEGMENT_IDS)[number];
|
|
54
|
-
|
|
61
|
+
type StatusSegment = `status:${string}`;
|
|
55
62
|
export type SegmentId = BuiltinSegment | StatusSegment;
|
|
56
63
|
|
|
57
64
|
const STATUS_PREFIX = "status:";
|
|
@@ -64,10 +71,9 @@ export function isSegmentId(value: string): value is SegmentId {
|
|
|
64
71
|
);
|
|
65
72
|
}
|
|
66
73
|
|
|
67
|
-
/**
|
|
74
|
+
/** The statuses segment skips them. */
|
|
68
75
|
const CLAIMED_BY_SEGMENT: Partial<Record<BuiltinSegment, string>> = {
|
|
69
76
|
model: "pi-providers:account",
|
|
70
|
-
tasks: "pi-tasks",
|
|
71
77
|
peers: "pi-peers",
|
|
72
78
|
};
|
|
73
79
|
|
|
@@ -160,22 +166,34 @@ export const SEGMENTS: Record<BuiltinSegment, Segment> = {
|
|
|
160
166
|
peers: {
|
|
161
167
|
priority: 25,
|
|
162
168
|
describe:
|
|
163
|
-
"
|
|
164
|
-
// The whole folder, then one name, then the bare mark, as
|
|
169
|
+
"each room this session is in, with ● taking part, ◐ listening or ○ stepped out, then its agents by name and colour, each ◆ working, ⚑ waiting on you or ◇ idle, rooms apart by a rule, then @ how many messages wait for an answer",
|
|
170
|
+
// The whole folder, then one name, then the bare mark, as room runs out.
|
|
165
171
|
render: ({ snapshot, glyphs, paint }) => {
|
|
166
172
|
const peers = snapshot.peers;
|
|
167
|
-
|
|
173
|
+
// A draft is a line here, not a frame over the editor.
|
|
174
|
+
const drafts = (snapshot.peersWriting ?? []).map(
|
|
175
|
+
(mark) => `${paint.raw(mark.color, mark.handle)}${paint.dim(` \u2192 ${mark.to}`)}`,
|
|
176
|
+
);
|
|
177
|
+
const writing = drafts.length === 0 ? "" : paint.dim(drafts.join(", "));
|
|
178
|
+
const unread =
|
|
168
179
|
snapshot.peersUnread > 0 ? paint.role("waiting", `@${snapshot.peersUnread}`) : "";
|
|
180
|
+
const mentions = [writing, unread].filter((part) => part !== "").join(" ");
|
|
181
|
+
const rooms = snapshot.peersRooms.filter(
|
|
182
|
+
(room) => room.peers.length > 0 || room.mode !== "in",
|
|
183
|
+
);
|
|
184
|
+
if (rooms.length > 0) return roomsPiece(rooms, mentions, glyphs, paint);
|
|
169
185
|
const first = peers[0];
|
|
170
186
|
if (first === undefined) return mentions === "" ? undefined : { text: mentions };
|
|
171
187
|
const named = (peer: PeerMark) => paint.raw(peer.color, `${glyphs.peers} ${peer.handle}`);
|
|
172
188
|
const rest = peers.length > 1 ? paint.dim(` +${peers.length - 1}`) : "";
|
|
173
|
-
const
|
|
189
|
+
const groups = new Map<string, string[]>();
|
|
174
190
|
for (const peer of peers)
|
|
175
|
-
|
|
191
|
+
groups.set(peer.room ?? "", [...(groups.get(peer.room ?? "") ?? []), named(peer)]);
|
|
176
192
|
const apart = ` ${paint.dim(glyphs.apart)} `;
|
|
177
|
-
const
|
|
178
|
-
|
|
193
|
+
const full = joined(
|
|
194
|
+
[...groups.values()].map((group) => group.join(" ")).join(apart),
|
|
195
|
+
mentions,
|
|
196
|
+
);
|
|
179
197
|
const short = joined(named(first) + rest, mentions);
|
|
180
198
|
const least = joined(paint.raw(first.color, glyphs.peers), mentions);
|
|
181
199
|
return {
|
|
@@ -185,25 +203,27 @@ export const SEGMENTS: Record<BuiltinSegment, Segment> = {
|
|
|
185
203
|
};
|
|
186
204
|
},
|
|
187
205
|
},
|
|
188
|
-
|
|
206
|
+
board: {
|
|
189
207
|
priority: 30,
|
|
190
208
|
describe:
|
|
191
|
-
"
|
|
192
|
-
//
|
|
209
|
+
"the card being done, then ⚑ how many open cards are blocked, ⧗ how many are to do and free to start, and ✓ how many are done, from the session's board",
|
|
210
|
+
// A short line cuts the words, not the counts.
|
|
193
211
|
render: ({ snapshot, glyphs, paint }) => {
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
const
|
|
197
|
-
const
|
|
198
|
-
const
|
|
212
|
+
const cards = snapshot.board?.cards ?? [];
|
|
213
|
+
const doing = cards.filter((card) => card.column === "doing");
|
|
214
|
+
const blocked = cards.filter(blocks).length;
|
|
215
|
+
const todo = cards.filter((card) => card.column === "todo" && !blocks(card)).length;
|
|
216
|
+
const done = cards.filter((card) => card.column === "done").length;
|
|
199
217
|
const counts = [
|
|
200
|
-
tally(
|
|
201
|
-
tally(
|
|
202
|
-
tally(
|
|
218
|
+
tally(blocked, glyphs.waiting, "waiting", paint),
|
|
219
|
+
tally(todo, glyphs.queued, "queued", paint),
|
|
220
|
+
tally(done, glyphs.done, "done", paint),
|
|
203
221
|
].filter((part) => part !== "");
|
|
222
|
+
const step = doing[0]?.title;
|
|
204
223
|
if (step === undefined && counts.length === 0) return undefined;
|
|
205
|
-
|
|
206
|
-
|
|
224
|
+
const more = doing.length > 1 ? paint.dim(` +${doing.length - 1}`) : "";
|
|
225
|
+
// Between cards the line stays, so what was done and what waits do not vanish.
|
|
226
|
+
const icon = mark(glyphs.board, paint, "board");
|
|
207
227
|
const words = (room: number) =>
|
|
208
228
|
step === undefined ? paint.dim("idle") : paint.text(fitWidth(step, room, glyphs.ellipsis));
|
|
209
229
|
const tail = `${more}${counts.length === 0 ? "" : ` ${counts.join(" ")}`}`;
|
|
@@ -214,6 +234,16 @@ export const SEGMENTS: Record<BuiltinSegment, Segment> = {
|
|
|
214
234
|
};
|
|
215
235
|
},
|
|
216
236
|
},
|
|
237
|
+
me: {
|
|
238
|
+
priority: 85,
|
|
239
|
+
describe: "the name the rooms call this session by, in its color",
|
|
240
|
+
render: ({ snapshot: { me }, paint }) => {
|
|
241
|
+
if (me === undefined) return undefined;
|
|
242
|
+
const name =
|
|
243
|
+
me.color === undefined ? paint.role("brand", me.handle) : paint.raw(me.color, me.handle);
|
|
244
|
+
return { text: paint.bold(name) };
|
|
245
|
+
},
|
|
246
|
+
},
|
|
217
247
|
session: {
|
|
218
248
|
priority: 45,
|
|
219
249
|
describe: "the session name, once it has one",
|
|
@@ -441,10 +471,9 @@ export const SEGMENTS: Record<BuiltinSegment, Segment> = {
|
|
|
441
471
|
"what the session cost; `sub` means a subscription, so it is what the tokens would have cost",
|
|
442
472
|
render: ({ snapshot, glyphs, paint }) => {
|
|
443
473
|
const amount = snapshot.totals.cost;
|
|
444
|
-
// A session that spent nothing has nothing to say yet.
|
|
445
474
|
if (amount === 0) return undefined;
|
|
446
475
|
const value = paint.money(amount, money(amount));
|
|
447
|
-
// On a plan
|
|
476
|
+
// On a plan the amount is what the tokens would cost at API prices.
|
|
448
477
|
const what = paint.dim(snapshot.subscription ? " at API prices" : " this session");
|
|
449
478
|
const icon = glyphs.cost === "$" ? "" : mark(glyphs.cost, paint, "cost");
|
|
450
479
|
return { text: `${icon}${value}${what}`, compact: `${icon}${value}` };
|
|
@@ -457,7 +486,7 @@ export const SEGMENTS: Record<BuiltinSegment, Segment> = {
|
|
|
457
486
|
render: ({ snapshot, glyphs, paint, options }) => {
|
|
458
487
|
const totals = snapshot.totals;
|
|
459
488
|
if (tokensOf(totals) === 0) return undefined;
|
|
460
|
-
// Everything sent, not
|
|
489
|
+
// Everything sent, not only the uncached part.
|
|
461
490
|
const sent = paint.role("sent", count(promptOf(totals)));
|
|
462
491
|
const got = paint.role("received", count(totals.output));
|
|
463
492
|
const arrows = `${paint.role("sent", glyphs.sent)}${sent} ${paint.role("received", glyphs.received)}${got}`;
|
|
@@ -476,13 +505,13 @@ export const SEGMENTS: Record<BuiltinSegment, Segment> = {
|
|
|
476
505
|
const hit = snapshot.cacheHit;
|
|
477
506
|
if (hit === undefined) return undefined;
|
|
478
507
|
const icon = mark(glyphs.cacheRead, paint, "cache");
|
|
479
|
-
//
|
|
508
|
+
// Written to the cache and not read from it is the cache warming, not a miss.
|
|
480
509
|
if (snapshot.cacheWarming)
|
|
481
510
|
return { text: `${icon}${paint.muted(options.labels ? "cache new" : "new")}` };
|
|
482
511
|
const value =
|
|
483
512
|
hit >= 90 ? paint.role("done", percent(hit)) : paint.stress(100 - hit, percent(hit));
|
|
484
513
|
return {
|
|
485
|
-
// The numbers around it are the session's
|
|
514
|
+
// The numbers around it are the session's; this one is the last prompt's.
|
|
486
515
|
text: options.labels
|
|
487
516
|
? `${paint.dim("last prompt ")}${value}${paint.dim(" cached")}`
|
|
488
517
|
: `${icon}${value}`,
|
|
@@ -526,6 +555,52 @@ export const SEGMENTS: Record<BuiltinSegment, Segment> = {
|
|
|
526
555
|
},
|
|
527
556
|
};
|
|
528
557
|
|
|
558
|
+
/**
|
|
559
|
+
* Each room once, with how this session stands in it, then its agents with the marks the rooms panel
|
|
560
|
+
* and the board use: working, waiting on you, or idle.
|
|
561
|
+
*/
|
|
562
|
+
function roomsPiece(
|
|
563
|
+
rooms: readonly RoomMark[],
|
|
564
|
+
mentions: string,
|
|
565
|
+
glyphs: Glyphs,
|
|
566
|
+
paint: Paint,
|
|
567
|
+
): Rendered {
|
|
568
|
+
const roomMark = (room: RoomMark): string => {
|
|
569
|
+
if (room.mode === "listening") return paint.raw("muted", glyphs.roomListening);
|
|
570
|
+
if (room.mode === "out") return paint.dim(glyphs.roomOut);
|
|
571
|
+
return paint.raw("accent", glyphs.roomIn);
|
|
572
|
+
};
|
|
573
|
+
const agent = (peer: PeerMark): string => {
|
|
574
|
+
const name = paint.raw(peer.color, peer.handle);
|
|
575
|
+
if (peer.state === "waiting") return `${paint.role("waiting", glyphs.waiting || "!")} ${name}`;
|
|
576
|
+
if (peer.state === "running") return `${paint.raw(peer.color, glyphs.agentWorking)} ${name}`;
|
|
577
|
+
return `${paint.dim(glyphs.agentIdle)} ${name}`;
|
|
578
|
+
};
|
|
579
|
+
const label = (room: RoomMark): string => `${roomMark(room)} ${paint.dim(room.name)}`;
|
|
580
|
+
const apart = ` ${paint.dim(glyphs.apart)} `;
|
|
581
|
+
const full = joined(
|
|
582
|
+
rooms.map((room) => [label(room), ...room.peers.map(agent)].join(" ")).join(apart),
|
|
583
|
+
mentions,
|
|
584
|
+
);
|
|
585
|
+
const [head] = rooms;
|
|
586
|
+
if (head === undefined) return undefined;
|
|
587
|
+
const total = rooms.reduce((sum, room) => sum + room.peers.length, 0);
|
|
588
|
+
const first = rooms.find((room) => room.peers.length > 0)?.peers[0];
|
|
589
|
+
const short = joined(
|
|
590
|
+
[label(head), ...(first === undefined ? [] : [agent(first)])].join(" ") +
|
|
591
|
+
(total > 1 ? paint.dim(` +${total - 1}`) : ""),
|
|
592
|
+
mentions,
|
|
593
|
+
);
|
|
594
|
+
const least = joined(roomMark(head), mentions);
|
|
595
|
+
return {
|
|
596
|
+
text: full,
|
|
597
|
+
shrink: (width) => {
|
|
598
|
+
if (visibleWidth(full) <= width) return full;
|
|
599
|
+
return visibleWidth(short) <= width ? short : least;
|
|
600
|
+
},
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
|
|
529
604
|
export function renderSegments(ids: readonly SegmentId[], input: SegmentInput): Piece[] {
|
|
530
605
|
return ids.flatMap((id): Piece[] => {
|
|
531
606
|
if (id.startsWith(STATUS_PREFIX)) {
|
|
@@ -538,7 +613,7 @@ export function renderSegments(ids: readonly SegmentId[], input: SegmentInput):
|
|
|
538
613
|
});
|
|
539
614
|
}
|
|
540
615
|
|
|
541
|
-
/**
|
|
616
|
+
/** `5h 62% resets in 2h`; the percent carries the color. */
|
|
542
617
|
function quotaWindow(paint: Paint, window: AccountWindow): string {
|
|
543
618
|
const used = paint.stress(window.used, `${window.used}%`);
|
|
544
619
|
const reset =
|
|
@@ -546,7 +621,6 @@ function quotaWindow(paint: Paint, window: AccountWindow): string {
|
|
|
546
621
|
return `${paint.dim(window.name)} ${used}${reset}`;
|
|
547
622
|
}
|
|
548
623
|
|
|
549
|
-
/** The parts that have something to say, with the gap the footer uses between things. */
|
|
550
624
|
function joined(...parts: string[]): string {
|
|
551
625
|
return parts.filter((part) => part !== "").join(" ");
|
|
552
626
|
}
|
|
@@ -555,7 +629,12 @@ function mark(glyph: string, paint: Paint, role: Role): string {
|
|
|
555
629
|
return glyph === "" ? "" : `${paint.role(role, glyph)} `;
|
|
556
630
|
}
|
|
557
631
|
|
|
558
|
-
/**
|
|
632
|
+
/** Counted as blocked, not as to do; a closed card no longer waits. */
|
|
633
|
+
function blocks(card: BoardCard): boolean {
|
|
634
|
+
return card.blocked !== undefined && card.column !== "done" && card.column !== "dropped";
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/** ASCII has no icon, so the word goes after the number. */
|
|
559
638
|
function tally(
|
|
560
639
|
size: number,
|
|
561
640
|
glyph: string,
|
package/src/render/streaming.ts
CHANGED
|
@@ -1,35 +1,30 @@
|
|
|
1
1
|
import { readFileSync, statSync } from "node:fs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
|
|
4
|
-
// While the model writes an edit or a write,
|
|
5
|
-
// which stopped changing long ago. These show the end instead: the lines arriving, with a cursor
|
|
6
|
-
// where the model is writing, and what it has written so far on the bottom rule.
|
|
4
|
+
// While the model writes an edit or a write, these show the lines arriving, with a cursor.
|
|
7
5
|
import { GLYPH, isObject, tildify } from "@adeildo/pi-kit";
|
|
8
6
|
import { getLanguageFromPath, highlightCode, type Theme } from "@earendil-works/pi-coding-agent";
|
|
9
7
|
import { stripTerminalSequences } from "@earendil-works/pi-tui";
|
|
10
8
|
|
|
11
9
|
import { tabs } from "./format.ts";
|
|
12
10
|
|
|
13
|
-
/** What the frame shows inside, and the counts it adds to the bottom rule. */
|
|
14
11
|
export interface Stream {
|
|
15
12
|
lines: string[];
|
|
16
13
|
progress: string[];
|
|
17
14
|
}
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
interface StreamContext {
|
|
20
17
|
cwd: string;
|
|
21
18
|
expanded: boolean;
|
|
22
|
-
/** The
|
|
19
|
+
/** The cursor shows and the last key may be cut short. */
|
|
23
20
|
writing: boolean;
|
|
24
|
-
/**
|
|
21
|
+
/** Keeps what was read from disk across renders of one call. */
|
|
25
22
|
state: { streamTarget?: Target };
|
|
26
23
|
}
|
|
27
24
|
|
|
28
25
|
type Streamer = (args: unknown, theme: Theme, context: StreamContext) => Stream | undefined;
|
|
29
26
|
|
|
30
|
-
/** How many of the last lines a write shows while it streams. */
|
|
31
27
|
const WRITE_TAIL = 8;
|
|
32
|
-
/** How many lines of the diff an edit shows while it streams. */
|
|
33
28
|
const EDIT_TAIL = 10;
|
|
34
29
|
const CURSOR = GLYPH.cursor;
|
|
35
30
|
/** Larger files are not read to count their lines. */
|
|
@@ -40,24 +35,19 @@ export const STREAMERS: Readonly<Record<string, Streamer>> = {
|
|
|
40
35
|
edit: editStream,
|
|
41
36
|
};
|
|
42
37
|
|
|
43
|
-
/** What a write is about to replace. */
|
|
44
38
|
interface Target {
|
|
45
39
|
path: string;
|
|
46
40
|
lines?: number;
|
|
47
41
|
exists: boolean;
|
|
48
42
|
}
|
|
49
43
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
theme: Theme,
|
|
53
|
-
context: StreamContext,
|
|
54
|
-
): Stream | undefined {
|
|
55
|
-
// The model may write the content before the path, so the stream does not wait for the path.
|
|
44
|
+
function writeStream(args: unknown, theme: Theme, context: StreamContext): Stream | undefined {
|
|
45
|
+
// The model may write the content before the path.
|
|
56
46
|
const content = field(args, "content");
|
|
57
47
|
if (content === undefined) return undefined;
|
|
58
48
|
const path = pathOf(args);
|
|
59
49
|
|
|
60
|
-
// A path still arriving
|
|
50
|
+
// A path still arriving may name another file on the way.
|
|
61
51
|
const target =
|
|
62
52
|
path !== undefined && pathSettled(args, context) ? targetOf(path, context) : undefined;
|
|
63
53
|
const note = target === undefined ? "" : ` ${theme.fg("muted", replaces(target))}`;
|
|
@@ -83,11 +73,7 @@ export function writeStream(
|
|
|
83
73
|
};
|
|
84
74
|
}
|
|
85
75
|
|
|
86
|
-
|
|
87
|
-
args: unknown,
|
|
88
|
-
theme: Theme,
|
|
89
|
-
context: StreamContext,
|
|
90
|
-
): Stream | undefined {
|
|
76
|
+
function editStream(args: unknown, theme: Theme, context: StreamContext): Stream | undefined {
|
|
91
77
|
const path = pathOf(args);
|
|
92
78
|
const edits = editsOf(args);
|
|
93
79
|
if (edits.length === 0) return undefined;
|
|
@@ -97,7 +83,7 @@ export function editStream(
|
|
|
97
83
|
const diff: string[] = [];
|
|
98
84
|
for (const [index, edit] of edits.entries()) {
|
|
99
85
|
if (index > 0) diff.push(theme.fg("dim", GLYPH.ellipsisAcross));
|
|
100
|
-
// Only the last edit can still be arriving
|
|
86
|
+
// Only the last edit can still be arriving.
|
|
101
87
|
const lines = editLines(edit, !context.writing || index < edits.length - 1);
|
|
102
88
|
for (const line of lines.before) diff.push(theme.fg("toolDiffContext", ` ${printable(line)}`));
|
|
103
89
|
for (const line of lines.out) diff.push(theme.fg("toolDiffRemoved", `-${printable(line)}`));
|
|
@@ -118,11 +104,7 @@ export function editStream(
|
|
|
118
104
|
};
|
|
119
105
|
}
|
|
120
106
|
|
|
121
|
-
/**
|
|
122
|
-
* The lines an edit takes out and puts in. The model repeats the lines around the change in both
|
|
123
|
-
* texts, so the lines both start with, and the lines both end with once the edit is complete, are
|
|
124
|
-
* context. A line the new text has not repeated yet counts as taken out until it does.
|
|
125
|
-
*/
|
|
107
|
+
/** Lines both texts start and end with are context; a line not repeated yet counts as taken out. */
|
|
126
108
|
export function editLines(
|
|
127
109
|
edit: PartialEdit,
|
|
128
110
|
complete: boolean,
|
|
@@ -148,24 +130,20 @@ export function editLines(
|
|
|
148
130
|
};
|
|
149
131
|
}
|
|
150
132
|
|
|
151
|
-
/**
|
|
152
|
-
function pathLine(tool: string, path: string | undefined, theme: Theme): string {
|
|
133
|
+
/** Pi's own renderer draws the same first line, so nothing moves when it takes over. */
|
|
134
|
+
export function pathLine(tool: string, path: string | undefined, theme: Theme): string {
|
|
153
135
|
const title = theme.fg("toolTitle", theme.bold(tool));
|
|
154
|
-
// Pi's own stand-in for a path not written yet.
|
|
155
136
|
if (path === undefined) return `${title} ${theme.fg("toolOutput", "...")}`;
|
|
156
137
|
return `${title} ${theme.fg("accent", printable(tildify(path)))}`;
|
|
157
138
|
}
|
|
158
139
|
|
|
159
|
-
/**
|
|
160
|
-
|
|
161
|
-
* back over the border, and a colour code or a bell in the file would reach the terminal.
|
|
162
|
-
*/
|
|
163
|
-
function printable(line: string): string {
|
|
140
|
+
/** A carriage return would cross the border, and escape codes would reach the terminal. */
|
|
141
|
+
export function printable(line: string): string {
|
|
164
142
|
// oxlint-disable-next-line no-control-regex -- control characters are what this removes
|
|
165
143
|
return tabs(stripTerminalSequences(line).replace(/[\u0000-\u0008\u000a-\u001f\u007f]/g, ""));
|
|
166
144
|
}
|
|
167
145
|
|
|
168
|
-
/** A key the model
|
|
146
|
+
/** A key the model moved past is complete, and so is every key once the call is written. */
|
|
169
147
|
function pathSettled(args: unknown, context: StreamContext): boolean {
|
|
170
148
|
if (!context.writing || !isObject(args)) return true;
|
|
171
149
|
const last = Object.keys(args).at(-1);
|
|
@@ -191,7 +169,7 @@ function replaces(target: Target): string {
|
|
|
191
169
|
return `replaces ${target.lines} line${target.lines === 1 ? "" : "s"}`;
|
|
192
170
|
}
|
|
193
171
|
|
|
194
|
-
/**
|
|
172
|
+
/** Once per call, when the path is complete. */
|
|
195
173
|
function targetOf(path: string, context: StreamContext): Target {
|
|
196
174
|
const known = context.state.streamTarget;
|
|
197
175
|
if (known?.path === path) return known;
|
|
@@ -205,7 +183,7 @@ function targetOf(path: string, context: StreamContext): Target {
|
|
|
205
183
|
target.lines = text === "" ? 0 : text.replace(/\n$/, "").split("\n").length;
|
|
206
184
|
}
|
|
207
185
|
} catch (error) {
|
|
208
|
-
//
|
|
186
|
+
// Missing is a new file; unreadable is still a file.
|
|
209
187
|
target = { path, exists: (error as NodeJS.ErrnoException).code !== "ENOENT" };
|
|
210
188
|
}
|
|
211
189
|
context.state.streamTarget = target;
|
|
@@ -234,7 +212,6 @@ export interface PartialEdit {
|
|
|
234
212
|
newText?: string;
|
|
235
213
|
}
|
|
236
214
|
|
|
237
|
-
/** The edits written so far. The last one may have its old text and nothing else yet. */
|
|
238
215
|
function editsOf(args: unknown): PartialEdit[] {
|
|
239
216
|
if (!isObject(args)) return [];
|
|
240
217
|
const { edits } = args;
|
package/src/render/tools.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
// The mark
|
|
2
|
-
// settings, like every other glyph on the screen.
|
|
1
|
+
// The mark follows the icon set in the look's settings.
|
|
3
2
|
import { GLYPH, SPIN } from "@adeildo/pi-kit";
|
|
4
3
|
|
|
5
4
|
import type { IconSet } from "./glyphs.ts";
|
|
@@ -79,7 +78,6 @@ const MARKS: Record<IconSet, Record<CallPhase, string>> = {
|
|
|
79
78
|
ascii: { writing: "~", waiting: ":", running: "...", done: "ok", failed: "!" },
|
|
80
79
|
};
|
|
81
80
|
|
|
82
|
-
/** A mark that moves while its phase lasts: frames, and how long each stays. */
|
|
83
81
|
interface Motion {
|
|
84
82
|
frames: readonly string[];
|
|
85
83
|
stepMs: number;
|
|
@@ -92,7 +90,7 @@ const CLOCK = [0xf1456, ...Array.from({ length: 11 }, (_, hour) => 0xf144b + hou
|
|
|
92
90
|
|
|
93
91
|
const MOTIONS: Record<IconSet, Partial<Record<CallPhase, Motion>>> = {
|
|
94
92
|
nerd: {
|
|
95
|
-
//
|
|
93
|
+
// The same spinner as an agent writing, in every font a Nerd Font is built on.
|
|
96
94
|
writing: { frames: SPIN.braille, stepMs: 100 },
|
|
97
95
|
waiting: { frames: ["\u{f251}", "\u{f252}", "\u{f253}"], stepMs: 400 }, // nf-fa-hourglass_start..end
|
|
98
96
|
running: { frames: CLOCK, stepMs: 110 }, // nf-md-clock_time_*_outline
|
|
@@ -107,7 +105,7 @@ const MOTIONS: Record<IconSet, Partial<Record<CallPhase, Motion>>> = {
|
|
|
107
105
|
},
|
|
108
106
|
};
|
|
109
107
|
|
|
110
|
-
/**
|
|
108
|
+
/** A phase that lasts moves, so a call still going looks alive. */
|
|
111
109
|
export function stateMark(phase: CallPhase, set: IconSet, now: number = Date.now()): string {
|
|
112
110
|
const motion = MOTIONS[set][phase];
|
|
113
111
|
if (motion === undefined) return MARKS[set][phase];
|
|
@@ -118,7 +116,7 @@ export function toolIcon(toolName: string, set: IconSet): string {
|
|
|
118
116
|
return ICONS[set][toolKind(toolName)];
|
|
119
117
|
}
|
|
120
118
|
|
|
121
|
-
/**
|
|
119
|
+
/** An MCP tool says its server rather than `mcp__server__tool`. */
|
|
122
120
|
export function toolLabel(toolName: string): string {
|
|
123
121
|
const mcp = toolName.match(/^mcp__([^_]+)__(.+)$/u);
|
|
124
122
|
return mcp === null ? toolName : `${mcp[1]}:${mcp[2]}`;
|
package/src/settings.ts
CHANGED
|
@@ -6,23 +6,21 @@ import type { SegmentId } from "./render/segments.ts";
|
|
|
6
6
|
import { framePreview, iconsPreview, userFramePreview } from "./ui/previews.ts";
|
|
7
7
|
import type { SlotName } from "./ui/screen.ts";
|
|
8
8
|
|
|
9
|
-
//
|
|
10
|
-
// start screen are fixed. Only what depends on your terminal or your taste in lines is a setting:
|
|
11
|
-
// the icon set, the frame's line style, and whether your messages are framed. See DESIGN.md.
|
|
9
|
+
// Only what depends on the terminal or taste is a setting: icons, line style, framed messages.
|
|
12
10
|
|
|
13
11
|
export const SECTIONS = ["Appearance"];
|
|
14
12
|
|
|
15
13
|
export type HeaderStyle = "card" | "compact";
|
|
16
14
|
export type CursorStyle = "block" | "bar" | "underline";
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
const PERMISSION_MODE: SegmentId = "status:pi-ask-permission:mode";
|
|
19
17
|
|
|
20
18
|
/** The line above the editor: how long the agent has worked, and the last call that finished. */
|
|
21
19
|
export const strip: readonly SegmentId[] = ["elapsed"];
|
|
22
20
|
/** The other side of that line, or a line of its own under it when it does not fit. */
|
|
23
|
-
export const stripRight: readonly SegmentId[] = ["
|
|
21
|
+
export const stripRight: readonly SegmentId[] = ["board", "peers"];
|
|
24
22
|
/** After the working spinner on the editor's top edge. */
|
|
25
|
-
export const topLeft: readonly SegmentId[] = ["branch", "session"];
|
|
23
|
+
export const topLeft: readonly SegmentId[] = ["me", "branch", "session"];
|
|
26
24
|
/** Where you are. */
|
|
27
25
|
export const topRight: readonly SegmentId[] = ["path", "host"];
|
|
28
26
|
/** How what you type is handled, and who does the work. */
|
|
@@ -34,7 +32,7 @@ export const below: readonly SegmentId[] = ["cost", "tokens", "cache", "average"
|
|
|
34
32
|
/** The plan's quota: what each window spent, and when it resets. */
|
|
35
33
|
export const belowRight: readonly SegmentId[] = ["quota"];
|
|
36
34
|
|
|
37
|
-
/**
|
|
35
|
+
/** The docs fixture draws with the same map. */
|
|
38
36
|
export const SLOTS: Record<SlotName, readonly SegmentId[]> = {
|
|
39
37
|
strip,
|
|
40
38
|
stripRight,
|
package/src/ui/editor.ts
CHANGED
|
@@ -16,7 +16,7 @@ import { type Screen, type SlotName, slotPieces } from "./screen.ts";
|
|
|
16
16
|
|
|
17
17
|
type WorkingIndicator = Parameters<CustomEditor["setWorkingStatusIndicator"]>[0];
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
// Pi calls the border hooks inside its render; these mark where this class draws its own lines.
|
|
20
20
|
const TOP = "\u0000look:top\u0000";
|
|
21
21
|
const BOTTOM = "\u0000look:bottom\u0000";
|
|
22
22
|
// oxlint-disable-next-line no-control-regex -- pi's software cursor is an escape sequence
|
|
@@ -49,7 +49,7 @@ export class LookEditor extends CustomEditor {
|
|
|
49
49
|
this.#screen = screen;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
/** The frame owns the horizontal inset, so pi's padding
|
|
52
|
+
/** The frame owns the horizontal inset, so pi's padding would double it. */
|
|
53
53
|
override setPaddingX(_padding: number): void {
|
|
54
54
|
super.setPaddingX(0);
|
|
55
55
|
}
|
|
@@ -60,10 +60,14 @@ export class LookEditor extends CustomEditor {
|
|
|
60
60
|
this.tui.requestRender();
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* Pi opens and reopens its palette only at the start of a message. Further in, any edit that
|
|
65
|
+
* leaves the cursor in a `/name` (a typed slash, a deleted or retyped letter) lists the skills.
|
|
66
|
+
*/
|
|
64
67
|
override handleInput(data: string): void {
|
|
68
|
+
const before = this.getText();
|
|
65
69
|
super.handleInput(data);
|
|
66
|
-
if (
|
|
70
|
+
if (this.isShowingAutocomplete() || !this.#screen.skills() || this.getText() === before) return;
|
|
67
71
|
const { line, col } = this.getCursor();
|
|
68
72
|
if (skillQueryAt(this.getLines(), line, col) !== undefined) openAutocomplete(this);
|
|
69
73
|
}
|
|
@@ -102,7 +106,7 @@ export class LookEditor extends CustomEditor {
|
|
|
102
106
|
const inner = Math.max(1, width - 2 * this.#inset);
|
|
103
107
|
|
|
104
108
|
const cursor = this.#screen.cursor();
|
|
105
|
-
// Pi
|
|
109
|
+
// Pi restores its own cursor setting after a reload, which would hide a bar cursor.
|
|
106
110
|
if (cursor !== "block" && !this.tui.getShowHardwareCursor()) applyCursor(this.tui, cursor);
|
|
107
111
|
|
|
108
112
|
this.#framing = true;
|
|
@@ -162,7 +166,7 @@ export class LookEditor extends CustomEditor {
|
|
|
162
166
|
}
|
|
163
167
|
}
|
|
164
168
|
|
|
165
|
-
// Every line
|
|
169
|
+
// Every line is drawn to the width already, and measuring is cheaper than cutting.
|
|
166
170
|
return result.map((line) =>
|
|
167
171
|
visibleWidth(line) > width ? truncateToWidth(line, width, "") : line,
|
|
168
172
|
);
|
|
@@ -177,7 +181,7 @@ export class LookEditor extends CustomEditor {
|
|
|
177
181
|
}
|
|
178
182
|
}
|
|
179
183
|
|
|
180
|
-
|
|
184
|
+
/** The method is private; nothing opens if a pi release renames it. */
|
|
181
185
|
function openAutocomplete(editor: CustomEditor): void {
|
|
182
186
|
const open: unknown = Reflect.get(editor, "tryTriggerAutocomplete");
|
|
183
187
|
if (typeof open === "function") open.call(editor);
|
|
@@ -190,7 +194,6 @@ function withoutSoftwareCursor(line: string): string {
|
|
|
190
194
|
|
|
191
195
|
function fill(line: string, width: number): string {
|
|
192
196
|
const cells = visibleWidth(line);
|
|
193
|
-
// Measuring is cheap, and cutting a line that already fits is not.
|
|
194
197
|
if (cells <= width) return line + " ".repeat(width - cells);
|
|
195
198
|
const clipped = truncateToWidth(line, width, "");
|
|
196
199
|
return clipped + " ".repeat(Math.max(0, width - visibleWidth(clipped)));
|
package/src/ui/footer.ts
CHANGED
|
@@ -6,19 +6,12 @@ import type { Paint } from "../render/paint.ts";
|
|
|
6
6
|
import { type Screen, type SlotName, slotPieces } from "./screen.ts";
|
|
7
7
|
|
|
8
8
|
const GAP = 3;
|
|
9
|
-
/**
|
|
9
|
+
/** So the strip's changing width never moves the right side. */
|
|
10
10
|
const STRIP_ROOM = 56;
|
|
11
|
-
/**
|
|
12
|
-
* How long the footer and the strip are drawn again without a reason. What they show moves with the
|
|
13
|
-
* clock, the live tokens and the context, and none of that reads differently 100 ms later, while a
|
|
14
|
-
* keystroke always redraws both. Anything that asks for a redraw drops the drawing anyway.
|
|
15
|
-
*/
|
|
11
|
+
/** A keystroke always redraws; nothing shown here reads differently 100 ms later. */
|
|
16
12
|
const REDRAW_MS = 100;
|
|
17
13
|
|
|
18
|
-
/**
|
|
19
|
-
* A drawing kept per width and per revision of the screen for a moment. The transcript draws every
|
|
20
|
-
* entry on every keystroke, and the footer and the strip were built again each time.
|
|
21
|
-
*/
|
|
14
|
+
/** Kept per width and screen revision, since the transcript redraws on every keystroke. */
|
|
22
15
|
class KeptDrawing {
|
|
23
16
|
#drawn: { width: number; revision: number; at: number; lines: string[] } | undefined;
|
|
24
17
|
|
|
@@ -48,7 +41,7 @@ class KeptDrawing {
|
|
|
48
41
|
}
|
|
49
42
|
}
|
|
50
43
|
|
|
51
|
-
|
|
44
|
+
function indentOf(screen: Screen): number {
|
|
52
45
|
const style = screen.frameStyle();
|
|
53
46
|
return style === "off" || style === "line" ? 1 : 2;
|
|
54
47
|
}
|