@each1024/pi-mini-mode 0.9.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/LICENSE +21 -0
- package/README.md +214 -0
- package/README.zh-CN.md +210 -0
- package/extensions/footer-status.ts +1612 -0
- package/lib/agent-view.ts +518 -0
- package/lib/file-links.ts +80 -0
- package/lib/footer-tidy.ts +75 -0
- package/lib/input-enhancements.ts +622 -0
- package/lib/minimal-markdown.ts +181 -0
- package/lib/minimal-theme.ts +48 -0
- package/lib/settings-web.ts +119 -0
- package/lib/settings.html +209 -0
- package/lib/sticky-tool.ts +100 -0
- package/lib/title-plain.ts +57 -0
- package/lib/transcript-adapter.ts +578 -0
- package/package.json +61 -0
- package/themes/README.md +5 -0
- package/themes/cc-dark.json +91 -0
- package/themes/cc-light.json +91 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { ScrollView, VStack, truncateToWidth, type Component } from "@earendil-works/pi-tui";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import type { getLayoutNode as GetLayoutNode } from "@earendil-works/pi-tui/dist/layout-node.js";
|
|
4
|
+
|
|
5
|
+
interface StickyToolView {
|
|
6
|
+
pinnedTool(): { id: string; y: number; line: string; autoScroll?: boolean } | undefined;
|
|
7
|
+
unpinTool(): void;
|
|
8
|
+
toggleTool(id: string): void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** ponytail: Pi 0.85 layoutRoot + optional internal layout-node export;
|
|
12
|
+
* replace discovery with a public primary-scroll/layout getter when available. */
|
|
13
|
+
export function attachStickyTool(tui: unknown, document: Component, view: StickyToolView, setMinHeight: (height: number) => void = () => {}): (() => void) | undefined {
|
|
14
|
+
const host = tui as { mode?: string; terminal?: { rows: number }; layoutRoot?: Component; setLayoutRoot?: (root: Component) => void; requestRender?: () => void };
|
|
15
|
+
if (host.mode !== "fullscreen" || !host.layoutRoot || !host.setLayoutRoot || !host.requestRender) return;
|
|
16
|
+
let getNode: typeof GetLayoutNode;
|
|
17
|
+
try { getNode = createRequire(import.meta.url)("@earendil-works/pi-tui/dist/layout-node.js").getLayoutNode; }
|
|
18
|
+
catch { return; }
|
|
19
|
+
if (typeof getNode !== "function") return;
|
|
20
|
+
const originalRoot = host.layoutRoot;
|
|
21
|
+
let scroll: ScrollView | undefined;
|
|
22
|
+
let primaries = 0;
|
|
23
|
+
const seen = new Set<Component>();
|
|
24
|
+
const inspect = (component: Component): boolean => {
|
|
25
|
+
if (seen.has(component)) return false;
|
|
26
|
+
seen.add(component);
|
|
27
|
+
const node = getNode(component);
|
|
28
|
+
if (!node) return true;
|
|
29
|
+
if (node.type === "scroll") {
|
|
30
|
+
if (node.state.primary) {
|
|
31
|
+
primaries++;
|
|
32
|
+
if (component instanceof ScrollView && node.component === document) scroll = component;
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
if (node.type !== "vstack" || !(component instanceof VStack)) return false;
|
|
37
|
+
return node.entries.every(entry => inspect(entry.component));
|
|
38
|
+
};
|
|
39
|
+
try { if (!inspect(originalRoot) || primaries !== 1 || !scroll) return; }
|
|
40
|
+
catch { return; }
|
|
41
|
+
const transcript = scroll;
|
|
42
|
+
let currentId: string | undefined;
|
|
43
|
+
let shown: { id: string; line: string } | undefined;
|
|
44
|
+
const heading: Component = {
|
|
45
|
+
invalidate() {},
|
|
46
|
+
render(width) {
|
|
47
|
+
// Measure the unchanged document before moving the existing ScrollView.
|
|
48
|
+
setMinHeight(0);
|
|
49
|
+
document.render(transcript.getContentWidth(width));
|
|
50
|
+
const target = view.pinnedTool();
|
|
51
|
+
if (!target) {
|
|
52
|
+
currentId = undefined;
|
|
53
|
+
shown = undefined;
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
if (target.id !== currentId) {
|
|
57
|
+
currentId = target.id;
|
|
58
|
+
// Suspend follow-end before layout grows, without moving the reading position.
|
|
59
|
+
transcript.scrollTo(transcript.scrollTop, { disableFollow: true });
|
|
60
|
+
}
|
|
61
|
+
// At the original heading, use its document row rather than duplicating it.
|
|
62
|
+
shown = transcript.scrollTop > target.y ? target : undefined;
|
|
63
|
+
return shown ? [truncateToWidth(width < 5 ? "▼" : shown.line, width, "")] : [];
|
|
64
|
+
},
|
|
65
|
+
handleMouse(event) {
|
|
66
|
+
if (!shown) return;
|
|
67
|
+
if (event.type === "wheel") {
|
|
68
|
+
transcript.scrollBy(event.wheelDelta ?? 0);
|
|
69
|
+
return { handled: true, render: true };
|
|
70
|
+
}
|
|
71
|
+
// Dedicated layout row: never dispatch its clicks into underlying links.
|
|
72
|
+
if (event.button === "left" && !event.shift && !event.ctrl && !event.alt) {
|
|
73
|
+
if (event.type === "press") return { handled: true };
|
|
74
|
+
if (event.type === "click") {
|
|
75
|
+
view.toggleTool(shown.id);
|
|
76
|
+
return { handled: true, render: true };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
const section = new VStack([
|
|
82
|
+
{ component: heading, basis: "auto", shrink: 0 },
|
|
83
|
+
{ component: transcript, basis: 0, grow: 1, shrink: 1, minSize: 1 },
|
|
84
|
+
]);
|
|
85
|
+
const replace = (component: Component): Component => {
|
|
86
|
+
if (component === transcript) return section;
|
|
87
|
+
const node = getNode(component);
|
|
88
|
+
if (node?.type !== "vstack") return component;
|
|
89
|
+
const entries = node.entries.map(entry => ({ ...entry, component: replace(entry.component) }));
|
|
90
|
+
return entries.some((entry, index) => entry.component !== node.entries[index].component)
|
|
91
|
+
? new VStack(entries, { gap: node.gap, align: node.align }) : component;
|
|
92
|
+
};
|
|
93
|
+
const root = replace(originalRoot);
|
|
94
|
+
host.setLayoutRoot(root);
|
|
95
|
+
return () => {
|
|
96
|
+
view.unpinTool();
|
|
97
|
+
setMinHeight(0);
|
|
98
|
+
if (host.layoutRoot === root) host.setLayoutRoot!(originalRoot);
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** Strip noisy prefixes/suffixes from the terminal window title. */
|
|
2
|
+
|
|
3
|
+
import { basename } from "node:path";
|
|
4
|
+
|
|
5
|
+
type TitleCtx = {
|
|
6
|
+
cwd?: string;
|
|
7
|
+
getSessionName?: () => string | undefined;
|
|
8
|
+
ui: { setTitle(title: string): void };
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
type ExtensionAPILike = {
|
|
12
|
+
getSessionName?: () => string | undefined;
|
|
13
|
+
on(event: string, handler: (...args: any[]) => void): void;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function escapeRe(s: string): string {
|
|
17
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function plainTitle(name: string | undefined, cwd: string | undefined): string {
|
|
21
|
+
let t = String(name || "").replace(/[\r\n\t]+/g, " ").trim();
|
|
22
|
+
t = t.replace(/^(π|pi)\s*[-–—:|]\s*/i, "");
|
|
23
|
+
const base = cwd ? basename(cwd.replace(/\/+$/, "")) : "";
|
|
24
|
+
if (base) t = t.replace(new RegExp(`\\s*[-–—]\\s*${escapeRe(base)}\\s*$`, "i"), "");
|
|
25
|
+
t = t.replace(/\s*[-–—]\s*(ravenclaw|goose-agent|goose-note|goose-monitor|loopdesk|diteng[\w-]*)\s*$/i, "");
|
|
26
|
+
return t.trim();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function apply(ctx: TitleCtx, name: string | undefined, pi: ExtensionAPILike): void {
|
|
30
|
+
const raw = name ?? ctx.getSessionName?.() ?? pi.getSessionName?.();
|
|
31
|
+
const title = plainTitle(raw, ctx.cwd);
|
|
32
|
+
if (title) ctx.ui.setTitle(title);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Attach title-plain behavior. */
|
|
36
|
+
export default function attachTitlePlain(pi: ExtensionAPILike): void {
|
|
37
|
+
let timer: ReturnType<typeof setInterval> | undefined;
|
|
38
|
+
let lastCtx: TitleCtx | undefined;
|
|
39
|
+
|
|
40
|
+
const start = (event: { name?: string } | undefined, ctx: TitleCtx) => {
|
|
41
|
+
lastCtx = ctx;
|
|
42
|
+
apply(ctx, event?.name ?? pi.getSessionName?.(), pi);
|
|
43
|
+
if (timer) clearInterval(timer);
|
|
44
|
+
timer = setInterval(() => {
|
|
45
|
+
if (lastCtx) apply(lastCtx, pi.getSessionName?.(), pi);
|
|
46
|
+
}, 400);
|
|
47
|
+
timer.unref?.();
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
pi.on("session_start", start);
|
|
51
|
+
pi.on("session_info_changed", start);
|
|
52
|
+
pi.on("session_shutdown", () => {
|
|
53
|
+
if (timer) clearInterval(timer);
|
|
54
|
+
timer = undefined;
|
|
55
|
+
lastCtx = undefined;
|
|
56
|
+
});
|
|
57
|
+
}
|