@arhen/pi-senja 1.3.0 → 1.4.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 +2 -1
- package/package.json +1 -1
- package/src/index.ts +7 -3
- package/src/tool-groups.ts +44 -14
package/README.md
CHANGED
|
@@ -10,7 +10,8 @@ Forked from [pi-haiku](https://github.com/nnocte/pi-haiku) **0.2.0** by **nocte*
|
|
|
10
10
|
- **A header** with shortcuts grouped by control, models, view, and input.
|
|
11
11
|
- **A footer** with location, Git branch, session name, provider, model, thinking effort (including `max`), context bar, token usage, latest cache-hit rate, cost, OAuth subscription marker, and extension statuses.
|
|
12
12
|
- **Flat tool output** — image captions, command results, and errors sit on the terminal background. Only source and diff lines get a quiet editor surface (Senja warm grey `#32302f`). Status dots and failure labels carry the state; user messages retain their own background.
|
|
13
|
-
- **Grouped tool calls** — a single call stays on one line, e.g. `•
|
|
13
|
+
- **Grouped tool calls** — a single call stays on one line, e.g. `• Write example.ts ▸`. Codemode summaries can use the full pane width; all other tool summaries use at most 60% of the pane. Long titles truncate on one line, leaving room for the status and arrow. For runs longer than ten, the heading counts every call and failure, but only the latest ten calls are listed. Click **Show all** to reveal earlier calls above those ten, or **Show less** to fold history again. The control briefly brightens without scrolling through intermediate layouts (`REDUCE_MOTION=1` disables the feedback). Image reads keep Pi’s native inline image or text fallback, without a code gutter. Two or more consecutive calls to the same tool share a fixed heading, e.g. `• Ran codemode ×4 · 1 failed`. Each call occupies one tree line: `├─ script ▸` or `└─ script · failed ▸`. Click the line to open its indented native panel. The muted trailing icon changes to `▾`. Calls start collapsed by default. While running, the label has a subtle moving highlight without changing the row height (`REDUCE_MOTION=1` or `NO_COLOR=1` disables it). Click a call to open or close it at any time; partial output, success, and failure update its status without changing your choice. Expanded panels omit repeated titles and number script or file source lines (read offsets and native diff numbering are preserved). A text read opens to five wrapped lines; click its “more lines” hint to see the full read result. Image reads are not clipped. Opening a codemode row shows Pi’s native preview: at most five wrapped output lines. Click the result to see it in full; click it again to return to the preview. The row arrow closes the panel. Numbered source has a shaded row of padding above and below. Nested calls, output, and timing align with the script text, without an inner border. Pi’s tool expansion shortcut (default `Ctrl+O`) toggles all calls. Collapsed thinking is marked with a single-cell outline bulb (Nerd Font) beside `Thinking…` while streaming and `Thought` afterward. Inside a tool group, the bulb sits after the tree guide. Click the label to replace it with Pi’s thinking text without an icon, or the text to fold it back. A thinking-only turn between matching tools stays above the next call’s tree branch; elsewhere it stays in transcript order. Final replies have no marker. Parallel calls share the row once. Thinking follows its call through **Show all / Show less** and does not count toward the ten calls. A different tool or assistant prose starts a new group.
|
|
14
|
+
- **Shared transcript renderer** — compatible subagent views use the same renderer as the leader when Senja is enabled. Other Pi extensions can synchronously discover it via `pi.events.emit("pi:transcript-renderer", provider => { … })`. Mount with `provider.mount(chatContainer, tui, theme, starts?, cancelled?)`, render and send clicks to its `root`, and call `dispose()` when the view closes. The optional maps use tool call IDs and monotonic milliseconds (starts or frozen durations). With no provider, render the native container. This is opt-in for custom views; non-transcript panels are unchanged.
|
|
14
15
|
- **Tool activity** — An unnamed call shows `preparing…`. As soon as Pi names it, the row shows `running`, even while the model writes the script. The timer starts at the first named call update and keeps counting through execution (`running 1m 30s`). Confirmed interruptions freeze that total (`cancelled · 8s`) without counting as failures.
|
|
15
16
|
- **Codemode intent titles** — Senja asks the agent to put a short plan in a leading `// @title: Find the goal notice renderer` comment (after an optional `// @options:` line). The row displays that plan; expand it for the actual script and results. Untitled calls keep their script preview.
|
|
16
17
|
- **Goal notices** — a `goal-ui` status starts as one clickable row. Open it for the original notice, including its objective, usage and commands.
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -21,7 +21,7 @@ import type { ExtensionAPI, ExtensionContext, Theme, ThemeColor } from "@earendi
|
|
|
21
21
|
import { VERSION } from "@earendil-works/pi-coding-agent";
|
|
22
22
|
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
23
23
|
|
|
24
|
-
import { formatDuration, installToolGroups } from "./tool-groups.ts";
|
|
24
|
+
import { createTranscriptView, formatDuration, installToolGroups } from "./tool-groups.ts";
|
|
25
25
|
|
|
26
26
|
// ── Visual primitives ────────────────────────────────────────────────────────
|
|
27
27
|
|
|
@@ -420,10 +420,13 @@ export default function (pi: ExtensionAPI) {
|
|
|
420
420
|
const speedTiers = new Map<string, SpeedTier | null>();
|
|
421
421
|
const unverifiedTiers = new Set<string>();
|
|
422
422
|
|
|
423
|
+
const guide =
|
|
424
|
+
"Start each codemode script with a // @title: comment describing its planned action in a short verb phrase (e.g. // @title: Find the goal notice renderer). If using // @options:, put the title on the next line.";
|
|
425
|
+
const unsubscribeTranscript = pi.events.on("pi:transcript-renderer", (accept) => {
|
|
426
|
+
if (enabled && typeof accept === "function") accept({ mount: createTranscriptView, codemodeGuide: guide });
|
|
427
|
+
});
|
|
423
428
|
pi.on("before_agent_start", (event, ctx) => {
|
|
424
429
|
if (!enabled || ctx.mode !== "tui" || !event.systemPromptOptions?.selectedTools.includes("codemode")) return;
|
|
425
|
-
const guide =
|
|
426
|
-
"Start each codemode script with a // @title: comment describing its planned action in a short verb phrase (e.g. // @title: Find the goal notice renderer). If using // @options:, put the title on the next line.";
|
|
427
430
|
const { promptGuidelines } = event.systemPromptOptions;
|
|
428
431
|
if (!promptGuidelines.includes(guide)) promptGuidelines.push(guide);
|
|
429
432
|
});
|
|
@@ -851,6 +854,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
851
854
|
pi.on("session_shutdown", () => {
|
|
852
855
|
starts.clear();
|
|
853
856
|
cancelled.clear();
|
|
857
|
+
unsubscribeTranscript();
|
|
854
858
|
unsubscribeMode();
|
|
855
859
|
modeWorkingMessage = undefined;
|
|
856
860
|
clearWorkingTimers();
|
package/src/tool-groups.ts
CHANGED
|
@@ -30,7 +30,12 @@ type ToolRow = Component & {
|
|
|
30
30
|
isPartial: boolean;
|
|
31
31
|
expanded: boolean;
|
|
32
32
|
outputPad?: number;
|
|
33
|
-
result?: {
|
|
33
|
+
result?: {
|
|
34
|
+
isError: boolean;
|
|
35
|
+
durationMs?: number;
|
|
36
|
+
details?: { diff?: string };
|
|
37
|
+
content?: { type: string; text?: string }[];
|
|
38
|
+
};
|
|
34
39
|
setExpanded(value: boolean): void;
|
|
35
40
|
};
|
|
36
41
|
|
|
@@ -235,19 +240,23 @@ function indentedDetails(
|
|
|
235
240
|
tool.toolName === "codemode" && codeEnd > top ? gutter : Math.max(0, innerPad - (tool.outputPad ?? 1));
|
|
236
241
|
const resultIndent = " ".repeat(outputGutter);
|
|
237
242
|
const fills = (["toolPendingBg", "toolSuccessBg", "toolErrorBg"] as const).map((role) => theme.getBgAnsi(role));
|
|
243
|
+
const diff =
|
|
244
|
+
tool.toolName === "edit" &&
|
|
245
|
+
!tool.result?.isError &&
|
|
246
|
+
!!(tool.result?.details?.diff || Reflect.get(tool, "rendererState")?.callComponent?.preview?.diff);
|
|
247
|
+
const surface = (text: string) => theme.bg("toolSuccessBg", text.replace(/\x1b\[(?:0?|49)m/g, "$&" + fills[1]));
|
|
238
248
|
const body = lines.slice(top, displayEnd).map((line, i) => {
|
|
239
249
|
// Graphics sequences and their reserved rows belong to Pi's image renderer.
|
|
240
250
|
if (image && (!line.trim() || line.includes("\x1b_G") || line.includes("\x1b]1337;File="))) return guide + line;
|
|
241
251
|
let content = i === 0 && labelEnd ? sliceByColumn(line, labelEnd, contentWidth) : line;
|
|
242
252
|
for (const fill of fills) if (fill) content = content.replaceAll(fill, "");
|
|
243
253
|
const code = top + i < codeEnd;
|
|
244
|
-
const diff = tool.toolName === "edit" && !tool.result?.isError && /^\s*[+-]?\s*\d+\s/.test(plain(content));
|
|
245
254
|
if (!code && !diff) return guide + resultIndent + content;
|
|
246
255
|
const number = numbers.get(top + i);
|
|
247
256
|
const cell = number && gutter ? ` ${theme.fg("dim", number.padStart(digits))} ` : " ".repeat(gutter);
|
|
248
|
-
return guide +
|
|
257
|
+
return guide + surface(cell + content);
|
|
249
258
|
});
|
|
250
|
-
editorRows = codeEnd - top;
|
|
259
|
+
editorRows = diff ? body.length : codeEnd - top;
|
|
251
260
|
padTop = !image && (editorRows || body.length > 1) ? 1 : 0;
|
|
252
261
|
padBottom = !image && body.length > 1 && editorRows !== body.length ? 1 : 0;
|
|
253
262
|
if (padBottom) body.push(guide);
|
|
@@ -352,6 +361,30 @@ export function installToolGroups(
|
|
|
352
361
|
const [header, resources, chat] = document.children;
|
|
353
362
|
if (!(header instanceof Container && resources instanceof Container && chat instanceof Container)) return;
|
|
354
363
|
|
|
364
|
+
const mounted = createTranscriptView(chat, tui, theme, starts, cancelled, () => {
|
|
365
|
+
const viewport =
|
|
366
|
+
"getPrimaryScrollView" in tui && typeof tui.getPrimaryScrollView === "function"
|
|
367
|
+
? tui.getPrimaryScrollView()
|
|
368
|
+
: undefined;
|
|
369
|
+
viewport?.scrollTo(viewport.scrollTop, { disableFollow: true });
|
|
370
|
+
});
|
|
371
|
+
document.children[2] = mounted.root;
|
|
372
|
+
return {
|
|
373
|
+
dispose() {
|
|
374
|
+
mounted.dispose();
|
|
375
|
+
if (document.children[2] === mounted.root) document.children[2] = chat;
|
|
376
|
+
},
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export function createTranscriptView(
|
|
381
|
+
chat: Container,
|
|
382
|
+
tui: TUI,
|
|
383
|
+
theme: Theme,
|
|
384
|
+
starts?: ReadonlyMap<string, number>,
|
|
385
|
+
cancelled?: ReadonlyMap<string, number | undefined>,
|
|
386
|
+
holdScroll?: () => void,
|
|
387
|
+
) {
|
|
355
388
|
const blockGap = new Spacer(1);
|
|
356
389
|
const branchGap: Component = {
|
|
357
390
|
render: (width) => [width >= 8 ? theme.fg("dim", " │") : ""],
|
|
@@ -447,10 +480,7 @@ export function installToolGroups(
|
|
|
447
480
|
if (showAll.has(first)) showAll.delete(first);
|
|
448
481
|
else {
|
|
449
482
|
showAll.add(first);
|
|
450
|
-
|
|
451
|
-
const viewport = tui.getPrimaryScrollView();
|
|
452
|
-
viewport?.scrollTo(viewport.scrollTop, { disableFollow: true });
|
|
453
|
-
}
|
|
483
|
+
holdScroll?.();
|
|
454
484
|
}
|
|
455
485
|
if (motion) {
|
|
456
486
|
clearTimeout(settle);
|
|
@@ -514,7 +544,7 @@ export function installToolGroups(
|
|
|
514
544
|
const settled = interrupted ? "muted" : "success";
|
|
515
545
|
const role = failed ? "error" : run.some((tool) => tool.isPartial) ? "warning" : settled;
|
|
516
546
|
const dot = theme.fg(role, "•");
|
|
517
|
-
const action = theme.bold(theme.fg("customMessageLabel", verb ||
|
|
547
|
+
const action = theme.bold(theme.fg("customMessageLabel", verb || (name === "edit" ? "Edit" : "Write")));
|
|
518
548
|
return ` ${dot} ${action}${verb ? ` ${theme.fg("toolTitle", summary(name))}` : ""}`;
|
|
519
549
|
};
|
|
520
550
|
rows.push(blockGap);
|
|
@@ -567,7 +597,8 @@ export function installToolGroups(
|
|
|
567
597
|
state === "cancelled" ? (cancelled?.get(tool.toolCallId) ?? tool.result?.durationMs) : undefined;
|
|
568
598
|
const elapsed = start === undefined ? "" : formatDuration(performance.now() - start);
|
|
569
599
|
const regions = before.get(tool);
|
|
570
|
-
const
|
|
600
|
+
const rowWidth = name === "codemode" ? width : Math.max(1, Math.floor(width * 0.6));
|
|
601
|
+
const branch = grouped && rowWidth >= 9 ? (last ? " └─ " : " ├─ ") : "";
|
|
571
602
|
const guide = width < 8 ? "" : !grouped ? " " : last ? " " : " │ ";
|
|
572
603
|
if (regions) {
|
|
573
604
|
for (const row of regions) {
|
|
@@ -581,7 +612,7 @@ export function installToolGroups(
|
|
|
581
612
|
const labelKey = `${revision}:${width}:${grouped}:${last}:${open}:${state}:${elapsed}:${duration ?? ""}:${active ? frame : 0}:${subject}`;
|
|
582
613
|
if (labelKey !== call.labelKey) {
|
|
583
614
|
call.labelKey = labelKey;
|
|
584
|
-
const available =
|
|
615
|
+
const available = rowWidth - branch.length - 2;
|
|
585
616
|
let suffix = state ? ` · ${state}` : "";
|
|
586
617
|
if (duration !== undefined) {
|
|
587
618
|
const timed = `${suffix} · ${formatDuration(duration)}`;
|
|
@@ -596,7 +627,7 @@ export function installToolGroups(
|
|
|
596
627
|
const caption = grouped ? label : !name ? " •" : subject ? `${heading()} ${label}` : heading();
|
|
597
628
|
const script = truncateToWidth(caption, Math.max(0, available - visibleWidth(status)), "…");
|
|
598
629
|
const line = `${script}${status} ${icon}`;
|
|
599
|
-
call.label.setText(
|
|
630
|
+
call.label.setText(rowWidth <= 1 ? icon : theme.fg("dim", branch) + (active ? shimmer(line, frame) : line));
|
|
600
631
|
}
|
|
601
632
|
rows.push(call.row);
|
|
602
633
|
if (open) {
|
|
@@ -659,8 +690,8 @@ export function installToolGroups(
|
|
|
659
690
|
view.children = rows;
|
|
660
691
|
return render(width);
|
|
661
692
|
};
|
|
662
|
-
document.children[2] = view;
|
|
663
693
|
return {
|
|
694
|
+
root: view,
|
|
664
695
|
dispose() {
|
|
665
696
|
clearInterval(animation);
|
|
666
697
|
clearTimeout(settle);
|
|
@@ -674,7 +705,6 @@ export function installToolGroups(
|
|
|
674
705
|
}
|
|
675
706
|
}
|
|
676
707
|
}
|
|
677
|
-
if (document.children[2] === view) document.children[2] = chat;
|
|
678
708
|
},
|
|
679
709
|
};
|
|
680
710
|
}
|