pi-one-ui 0.3.0 → 0.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/CHANGELOG.md +31 -1
- package/README.en.md +39 -35
- package/README.md +20 -16
- package/extensions/app/commands/settings-previews.ts +4 -16
- package/extensions/app/config/renderer.ts +7 -6
- package/extensions/app/config/shell.ts +15 -137
- package/extensions/app/overlay/selector-border.ts +5 -5
- package/extensions/app/ownership.ts +1 -1
- package/extensions/app/panel.ts +19 -25
- package/extensions/app/runtime/tui-runtime.ts +31 -56
- package/extensions/features/context-inspector/index.ts +3 -3
- package/extensions/features/session-reference/index.ts +5 -5
- package/extensions/features/subagent-autocomplete.ts +1 -1
- package/extensions/layouts/context/index.ts +9 -12
- package/extensions/layouts/context/renderer/compact-mode.ts +24 -24
- package/extensions/layouts/context/renderer/default-mode.ts +21 -16
- package/extensions/layouts/context/renderer/index.ts +24 -24
- package/extensions/layouts/context/renderer/mouse/hover.ts +6 -6
- package/extensions/layouts/context/renderer/mouse/interaction.ts +35 -35
- package/extensions/layouts/context/renderer/mouse/packets.ts +3 -2
- package/extensions/layouts/context/renderer/mouse/scroll.ts +2 -2
- package/extensions/layouts/context/renderer/tool/diff/diff-component.ts +2 -1
- package/extensions/layouts/context/renderer/tool/diff/diff-edit-render.ts +21 -21
- package/extensions/layouts/context/renderer/tool/diff/diff-header.ts +4 -4
- package/extensions/layouts/context/renderer/tool/diff/diff-highlight.ts +6 -6
- package/extensions/layouts/context/renderer/tool/diff/diff-inline.ts +1 -1
- package/extensions/layouts/context/renderer/tool/diff/diff-layout.ts +18 -18
- package/extensions/layouts/context/renderer/tool/diff/diff-limits.ts +5 -5
- package/extensions/layouts/context/renderer/tool/diff/diff-palette.ts +3 -3
- package/extensions/layouts/context/renderer/tool/diff/diff-presentation.ts +1 -1
- package/extensions/layouts/context/renderer/tool/diff/diff-renderer.ts +2 -1
- package/extensions/layouts/context/renderer/tool/diff/diff-write-render.ts +31 -31
- package/extensions/layouts/context/renderer/tool/diff/index.ts +4 -4
- package/extensions/layouts/context/renderer/tool/diff/line-width-safety.ts +1 -1
- package/extensions/layouts/context/renderer/tool/diff/write-execution.ts +1 -1
- package/extensions/layouts/context/renderer/tool/grouping.ts +12 -12
- package/extensions/layouts/context/renderer/tool/message-display.ts +2 -2
- package/extensions/layouts/context/renderer/tool/result.ts +199 -19
- package/extensions/layouts/context/summary/core.ts +1 -0
- package/extensions/layouts/context/summary/index.ts +3 -3
- package/extensions/layouts/context/thinking/compact-thinking.ts +12 -13
- package/extensions/layouts/editor/controller.ts +3 -57
- package/extensions/layouts/editor/editor-metadata-format.ts +4 -4
- package/extensions/layouts/editor/factory.ts +5 -23
- package/extensions/layouts/editor/index.ts +2 -8
- package/extensions/layouts/editor/minimalist-editor.ts +1 -52
- package/extensions/layouts/editor/ui.ts +23 -255
- package/extensions/layouts/footer/controller.ts +3 -3
- package/extensions/layouts/footer/footer.ts +21 -21
- package/extensions/layouts/footer/index.ts +8 -8
- package/extensions/layouts/header/index.ts +1 -1
- package/extensions/layouts/header/startup-header.ts +3 -2
- package/extensions/layouts/working-line/controller.ts +6 -6
- package/extensions/layouts/working-line/interaction-summary.ts +47 -7
- package/extensions/layouts/working-line/working-line.ts +24 -3
- package/extensions/services/project-refresh.ts +2 -2
- package/extensions/services/session-state.ts +1 -1
- package/extensions/shared/format.ts +2 -2
- package/extensions/shared/icons.ts +0 -4
- package/package.json +9 -12
- package/extensions/features/legacy/working-message.ts +0 -226
- package/extensions/layouts/editor/accent-rail-editor.ts +0 -112
- package/extensions/layouts/editor/accent-rail-layout-patch.ts +0 -530
|
@@ -550,7 +550,12 @@ export type WorkingLineRuntimeSegments = {
|
|
|
550
550
|
tool?: string;
|
|
551
551
|
elapsedMs?: number;
|
|
552
552
|
thought?: { durationMs: number; active: boolean };
|
|
553
|
-
tokens?: {
|
|
553
|
+
tokens?: {
|
|
554
|
+
input: number;
|
|
555
|
+
output: number;
|
|
556
|
+
outputApproximate?: boolean;
|
|
557
|
+
outputTokensPerSecond?: number;
|
|
558
|
+
};
|
|
554
559
|
};
|
|
555
560
|
|
|
556
561
|
export type WorkingLineFrameState = {
|
|
@@ -617,11 +622,18 @@ export function formatWorkingLineTokens(
|
|
|
617
622
|
tokens.input < 0 ||
|
|
618
623
|
tokens.output < 0 ||
|
|
619
624
|
(tokens.outputApproximate !== undefined &&
|
|
620
|
-
typeof tokens.outputApproximate !== "boolean")
|
|
625
|
+
typeof tokens.outputApproximate !== "boolean") ||
|
|
626
|
+
(tokens.outputTokensPerSecond !== undefined &&
|
|
627
|
+
(!Number.isFinite(tokens.outputTokensPerSecond) ||
|
|
628
|
+
tokens.outputTokensPerSecond < 0))
|
|
621
629
|
) {
|
|
622
630
|
return undefined;
|
|
623
631
|
}
|
|
624
|
-
|
|
632
|
+
const outputRate =
|
|
633
|
+
tokens.outputTokensPerSecond && tokens.outputTokensPerSecond > 0
|
|
634
|
+
? ` ⚡${formatCount(Math.round(tokens.outputTokensPerSecond * 10) / 10)} tok/s`
|
|
635
|
+
: "";
|
|
636
|
+
return `↑${formatCount(tokens.input)} ↓${formatCount(tokens.output)}${outputRate}`;
|
|
625
637
|
}
|
|
626
638
|
|
|
627
639
|
function truncateWithEllipsis(value: string, capacity: number): string {
|
|
@@ -1174,6 +1186,15 @@ export class WorkingLineController {
|
|
|
1174
1186
|
startTurn(ctx: WorkingLineContext): WorkingLineReconcileResult {
|
|
1175
1187
|
const config = this.getConfig().components.workingLine;
|
|
1176
1188
|
this.activeTools.clear();
|
|
1189
|
+
if (this.tokens?.outputTokensPerSecond !== undefined) {
|
|
1190
|
+
this.tokens = {
|
|
1191
|
+
input: this.tokens.input,
|
|
1192
|
+
output: this.tokens.output,
|
|
1193
|
+
...(this.tokens.outputApproximate === undefined
|
|
1194
|
+
? {}
|
|
1195
|
+
: { outputApproximate: this.tokens.outputApproximate }),
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1177
1198
|
const selectedMessage = selectWorkingLineMessage(config, this.random);
|
|
1178
1199
|
if (!config.enabled) {
|
|
1179
1200
|
this.selectedMessage = selectedMessage;
|
|
@@ -3,10 +3,10 @@ import { dirname, join, resolve } from "node:path";
|
|
|
3
3
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
import type { SessionLifecycle } from "../app/runtime/session-lifecycle.ts";
|
|
5
5
|
import { readGitStatus } from "./git-data.ts";
|
|
6
|
-
import type { FooterState } from "./session-state.ts";
|
|
7
|
-
import { applyProjectRefreshToState } from "./project-state.ts";
|
|
8
6
|
import { readPackageVersionResult } from "./package-data.ts";
|
|
7
|
+
import { applyProjectRefreshToState } from "./project-state.ts";
|
|
9
8
|
import { readRuntimeInfo } from "./runtime-data.ts";
|
|
9
|
+
import type { FooterState } from "./session-state.ts";
|
|
10
10
|
|
|
11
11
|
export type StopProjectRefreshInterval = () => void;
|
|
12
12
|
|
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
getUsageTotals,
|
|
11
11
|
invalidateUsageTotalsCache,
|
|
12
12
|
} from "../shared/format.ts";
|
|
13
|
-
import { emptyGitStatus } from "./git-data.ts";
|
|
14
13
|
import type { GitStatusSummary } from "./git-data.ts";
|
|
14
|
+
import { emptyGitStatus } from "./git-data.ts";
|
|
15
15
|
import type { PackageVersionResult } from "./package-data.ts";
|
|
16
16
|
import type { RuntimeInfo } from "./runtime-data.ts";
|
|
17
17
|
import type { FooterTelemetry } from "./telemetry.ts";
|
|
@@ -10,14 +10,14 @@ import type {
|
|
|
10
10
|
PathDisplayMode,
|
|
11
11
|
} from "../app/config/shell.ts";
|
|
12
12
|
import type { GitCommitInfo, GitMetricsInfo } from "../services/git-data.ts";
|
|
13
|
+
import type { PackageVersionResult } from "../services/package-data.ts";
|
|
14
|
+
import type { RuntimeInfo } from "../services/runtime-data.ts";
|
|
13
15
|
import type { IconMode } from "./icons.ts";
|
|
14
16
|
import {
|
|
15
17
|
resolveOsIcon,
|
|
16
18
|
resolvePackageIcon,
|
|
17
19
|
resolveRuntimeSymbol,
|
|
18
20
|
} from "./icons.ts";
|
|
19
|
-
import type { PackageVersionResult } from "../services/package-data.ts";
|
|
20
|
-
import type { RuntimeInfo } from "../services/runtime-data.ts";
|
|
21
21
|
import { renderStyleForSource } from "./style.ts";
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -23,7 +23,6 @@ export type IconGlyphs = {
|
|
|
23
23
|
deleted: string;
|
|
24
24
|
typechanged: string;
|
|
25
25
|
cacheHit: string;
|
|
26
|
-
editorPrompt: string;
|
|
27
26
|
rail: string;
|
|
28
27
|
username: string;
|
|
29
28
|
time: string;
|
|
@@ -48,7 +47,6 @@ export const ICON_GLYPH_KEYS = [
|
|
|
48
47
|
"deleted",
|
|
49
48
|
"typechanged",
|
|
50
49
|
"cacheHit",
|
|
51
|
-
"editorPrompt",
|
|
52
50
|
"rail",
|
|
53
51
|
"username",
|
|
54
52
|
"time",
|
|
@@ -79,7 +77,6 @@ export const NERD_DEFAULT_ICONS: IconGlyphs = {
|
|
|
79
77
|
deleted: "✘",
|
|
80
78
|
typechanged: "T",
|
|
81
79
|
cacheHit: "",
|
|
82
|
-
editorPrompt: "",
|
|
83
80
|
rail: "│",
|
|
84
81
|
username: "",
|
|
85
82
|
time: "",
|
|
@@ -103,7 +100,6 @@ export const ASCII_DEFAULT_ICONS: IconGlyphs = {
|
|
|
103
100
|
deleted: "x",
|
|
104
101
|
typechanged: "T",
|
|
105
102
|
cacheHit: "c",
|
|
106
|
-
editorPrompt: "",
|
|
107
103
|
rail: "|",
|
|
108
104
|
username: "@",
|
|
109
105
|
time: "t",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-one-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A single, customizable Pi UI package with layout-oriented Context and Shell rendering for Pi.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,17 +28,15 @@
|
|
|
28
28
|
"LICENSE"
|
|
29
29
|
],
|
|
30
30
|
"scripts": {
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"format": "biome format --write extensions tests package.json tsconfig.json biome.json",
|
|
35
|
-
"format:check": "biome format extensions tests package.json tsconfig.json biome.json",
|
|
36
|
-
"lint": "biome check extensions/index.ts extensions/app/panel.ts extensions/app/presets.ts package.json tsconfig.json biome.json",
|
|
37
|
-
"test:vitest": "vitest run tests/shell-*.test.ts tests/working-line-*.test.ts tests/editor-*.test.ts tests/footer-*.test.ts tests/services-*.test.ts",
|
|
38
|
-
"verify": "npm run format:check && npm run lint && npm run typecheck && npm test",
|
|
31
|
+
"format": "biome format --write extensions tests package.json tsconfig.json vitest.config.ts biome.json",
|
|
32
|
+
"check": "biome check extensions tests package.json tsconfig.json vitest.config.ts biome.json",
|
|
33
|
+
"fix": "biome check --write extensions tests package.json tsconfig.json vitest.config.ts biome.json",
|
|
39
34
|
"pack:check": "npm pack --dry-run",
|
|
40
35
|
"pi:dev": "${PI_BIN:-pi} --no-extensions -e ./extensions/index.ts",
|
|
41
|
-
"pi:install-local": "${PI_BIN:-pi} install ./ -l"
|
|
36
|
+
"pi:install-local": "${PI_BIN:-pi} install ./ -l",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"typecheck": "tsc --noEmit",
|
|
39
|
+
"verify": "npm run check && npm run typecheck && npm test"
|
|
42
40
|
},
|
|
43
41
|
"dependencies": {
|
|
44
42
|
"@shikijs/cli": "^4.0.2",
|
|
@@ -60,8 +58,7 @@
|
|
|
60
58
|
"themes": [
|
|
61
59
|
"./themes/cc-dark.json",
|
|
62
60
|
"./themes/cc-light.json"
|
|
63
|
-
]
|
|
64
|
-
"image": "https://raw.githubusercontent.com/minuque/pi-cc-extensions/main/assets/readme/preview.png"
|
|
61
|
+
]
|
|
65
62
|
},
|
|
66
63
|
"devDependencies": {
|
|
67
64
|
"@biomejs/biome": "^2.5.5",
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { formatDuration } from "../../tools/format.ts";
|
|
3
|
-
|
|
4
|
-
const REFRESH_INTERVAL_MS = 1_000;
|
|
5
|
-
/** Elapsed time is only shown once the turn has run this long. */
|
|
6
|
-
const SHOW_TIMER_AFTER_MS = 3_000;
|
|
7
|
-
|
|
8
|
-
function formatCount(value: number): string {
|
|
9
|
-
return new Intl.NumberFormat("en-US").format(value);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
type ContentBlock = {
|
|
13
|
-
type?: unknown;
|
|
14
|
-
text?: unknown;
|
|
15
|
-
thinkingSignature?: { body?: unknown };
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
type StreamMessage = {
|
|
19
|
-
content?: unknown;
|
|
20
|
-
usage?: { output?: unknown };
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/** 每个 content index 的可见文本/思考长度;无对应块的 index 保持稀疏洞。 */
|
|
24
|
-
function textBlockLengths(message: StreamMessage): number[] {
|
|
25
|
-
const content = message.content;
|
|
26
|
-
if (!Array.isArray(content)) return [];
|
|
27
|
-
const lengths: number[] = [];
|
|
28
|
-
for (let index = 0; index < content.length; index++) {
|
|
29
|
-
const block = content[index] as ContentBlock;
|
|
30
|
-
if (block?.type === "text" && typeof block.text === "string") {
|
|
31
|
-
lengths[index] = block.text.length;
|
|
32
|
-
} else if (block?.type === "thinking" && block.thinkingSignature?.body) {
|
|
33
|
-
lengths[index] = (block.thinkingSignature.body as string).length;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return lengths;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function outputUsage(message: StreamMessage): number {
|
|
40
|
-
const value = Number(message?.usage?.output);
|
|
41
|
-
return Number.isFinite(value) && value > 0 ? Math.round(value) : 0;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
type WorkingUi = {
|
|
45
|
-
setWorkingMessage(message?: string): void;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Extend Pi's footer working row while preserving its spinner and "Working...":
|
|
50
|
-
* `⠋ Working... (↓ 1,234 tokens · 12s)`
|
|
51
|
-
*
|
|
52
|
-
* Live tokens use the same chars/4 estimate as pi-claude-code-ui, then switch to
|
|
53
|
-
* provider `usage.output` whenever the stream exposes an actual count.
|
|
54
|
-
*/
|
|
55
|
-
export default function (pi: ExtensionAPI): void {
|
|
56
|
-
let turnActive = false;
|
|
57
|
-
let agentStartTime = 0;
|
|
58
|
-
let turnStartTime = 0;
|
|
59
|
-
let responseLength = 0;
|
|
60
|
-
let responseTextBlockLengths: number[] = [];
|
|
61
|
-
let providerOutputTokens = 0;
|
|
62
|
-
let refreshTimer: ReturnType<typeof setTimeout> | null = null;
|
|
63
|
-
let lastMessage: string | null = null;
|
|
64
|
-
let activeCtx: { ui: WorkingUi | undefined; hasUI: boolean } | null = null;
|
|
65
|
-
|
|
66
|
-
function tokenCount(): number {
|
|
67
|
-
return providerOutputTokens || Math.max(0, Math.round(responseLength / 4));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function setTextBlockLength(index: number, length: number): void {
|
|
71
|
-
const previous = responseTextBlockLengths[index] ?? 0;
|
|
72
|
-
responseTextBlockLengths[index] = Math.max(0, length);
|
|
73
|
-
responseLength = Math.max(
|
|
74
|
-
0,
|
|
75
|
-
responseLength + responseTextBlockLengths[index] - previous,
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function resetResponseTracking(message?: StreamMessage): void {
|
|
80
|
-
responseTextBlockLengths = message ? textBlockLengths(message) : [];
|
|
81
|
-
responseLength = responseTextBlockLengths.reduce(
|
|
82
|
-
(sum, length) => sum + length,
|
|
83
|
-
0,
|
|
84
|
-
);
|
|
85
|
-
providerOutputTokens = message ? outputUsage(message) : 0;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function updateProviderUsage(message: StreamMessage): void {
|
|
89
|
-
const output = outputUsage(message);
|
|
90
|
-
if (output > 0) providerOutputTokens = output;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function buildWorkingMessage(): string {
|
|
94
|
-
const elapsed = Date.now() - (agentStartTime || turnStartTime);
|
|
95
|
-
const tokens = tokenCount();
|
|
96
|
-
const parts: string[] = [];
|
|
97
|
-
if (tokens > 0) parts.push(`↓ ${formatCount(tokens)} tokens`);
|
|
98
|
-
if (elapsed >= SHOW_TIMER_AFTER_MS || tokens > 0) {
|
|
99
|
-
// formatDuration 低于 1 秒返回 "",此处回退 "0s" 保持计时器连续跳动。
|
|
100
|
-
parts.push(formatDuration(elapsed) || "0s");
|
|
101
|
-
}
|
|
102
|
-
return parts.length ? `Working... (${parts.join(" · ")})` : "";
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function restoreDefaultWorkingMessage(): void {
|
|
106
|
-
lastMessage = null;
|
|
107
|
-
if (!activeCtx?.hasUI) return;
|
|
108
|
-
try {
|
|
109
|
-
activeCtx.ui?.setWorkingMessage();
|
|
110
|
-
} catch {
|
|
111
|
-
// Noop when the TUI is unavailable.
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function syncWorkingMessage(force = false): void {
|
|
116
|
-
if (!activeCtx?.hasUI) return;
|
|
117
|
-
const next = buildWorkingMessage();
|
|
118
|
-
if (!next) {
|
|
119
|
-
if (force) restoreDefaultWorkingMessage();
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
if (!force && next === lastMessage) return;
|
|
123
|
-
lastMessage = next;
|
|
124
|
-
try {
|
|
125
|
-
activeCtx.ui?.setWorkingMessage(next);
|
|
126
|
-
} catch {
|
|
127
|
-
// Noop when the TUI is unavailable.
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function scheduleRefreshTick(): void {
|
|
132
|
-
if (!turnActive || refreshTimer) return;
|
|
133
|
-
refreshTimer = setTimeout(() => {
|
|
134
|
-
refreshTimer = null;
|
|
135
|
-
try {
|
|
136
|
-
syncWorkingMessage();
|
|
137
|
-
} finally {
|
|
138
|
-
scheduleRefreshTick();
|
|
139
|
-
}
|
|
140
|
-
}, REFRESH_INTERVAL_MS);
|
|
141
|
-
refreshTimer.unref?.();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function stopRefreshLoop(): void {
|
|
145
|
-
if (!refreshTimer) return;
|
|
146
|
-
clearTimeout(refreshTimer);
|
|
147
|
-
refreshTimer = null;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function clearDisplay(): void {
|
|
151
|
-
stopRefreshLoop();
|
|
152
|
-
agentStartTime = 0;
|
|
153
|
-
turnStartTime = 0;
|
|
154
|
-
resetResponseTracking();
|
|
155
|
-
restoreDefaultWorkingMessage();
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
pi.on("before_agent_start", async () => {
|
|
159
|
-
if (!agentStartTime) agentStartTime = Date.now();
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
pi.on("turn_start", async (_event, ctx) => {
|
|
163
|
-
turnActive = true;
|
|
164
|
-
activeCtx = ctx;
|
|
165
|
-
turnStartTime = Date.now();
|
|
166
|
-
if (!agentStartTime) agentStartTime = turnStartTime;
|
|
167
|
-
resetResponseTracking();
|
|
168
|
-
syncWorkingMessage(true);
|
|
169
|
-
scheduleRefreshTick();
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
pi.on("message_update", async (event, ctx) => {
|
|
173
|
-
activeCtx = ctx;
|
|
174
|
-
const evt = event?.assistantMessageEvent;
|
|
175
|
-
if (!evt) return;
|
|
176
|
-
|
|
177
|
-
if (evt.type === "start") {
|
|
178
|
-
resetResponseTracking(evt.partial);
|
|
179
|
-
} else if (evt.type === "thinking_start" || evt.type === "text_start") {
|
|
180
|
-
setTextBlockLength(evt.contentIndex, 0);
|
|
181
|
-
updateProviderUsage(evt.partial);
|
|
182
|
-
} else if (evt.type === "thinking_delta" || evt.type === "text_delta") {
|
|
183
|
-
const add = typeof evt.delta === "string" ? evt.delta.length : 0;
|
|
184
|
-
setTextBlockLength(
|
|
185
|
-
evt.contentIndex,
|
|
186
|
-
(responseTextBlockLengths[evt.contentIndex] ?? 0) + add,
|
|
187
|
-
);
|
|
188
|
-
updateProviderUsage(evt.partial);
|
|
189
|
-
} else if (evt.type === "text_end") {
|
|
190
|
-
setTextBlockLength(
|
|
191
|
-
evt.contentIndex,
|
|
192
|
-
typeof evt.content === "string" ? evt.content.length : 0,
|
|
193
|
-
);
|
|
194
|
-
updateProviderUsage(evt.partial);
|
|
195
|
-
} else if (evt.type === "done") {
|
|
196
|
-
resetResponseTracking(evt.message);
|
|
197
|
-
} else if (evt.type === "error") {
|
|
198
|
-
resetResponseTracking(evt.error);
|
|
199
|
-
} else {
|
|
200
|
-
updateProviderUsage(evt.partial);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
syncWorkingMessage();
|
|
204
|
-
scheduleRefreshTick();
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
pi.on("turn_end", async (_event, ctx) => {
|
|
208
|
-
turnActive = false;
|
|
209
|
-
activeCtx = ctx;
|
|
210
|
-
stopRefreshLoop();
|
|
211
|
-
resetResponseTracking();
|
|
212
|
-
// No completion message: return immediately to Pi's default idle state.
|
|
213
|
-
restoreDefaultWorkingMessage();
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
pi.on("agent_end", async () => {
|
|
217
|
-
turnActive = false;
|
|
218
|
-
clearDisplay();
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
pi.on("session_shutdown", async () => {
|
|
222
|
-
turnActive = false;
|
|
223
|
-
clearDisplay();
|
|
224
|
-
activeCtx = null;
|
|
225
|
-
});
|
|
226
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
3
|
-
import {
|
|
4
|
-
applyOwnedLayoutBackground,
|
|
5
|
-
fillTerminalLine,
|
|
6
|
-
renderCompletionRows,
|
|
7
|
-
} from "./completion-menu.ts";
|
|
8
|
-
import type { ZentuiConfig } from "../../app/config/shell.ts";
|
|
9
|
-
import { sanitizeEditorMetadataText } from "./editor-metadata-format.ts";
|
|
10
|
-
import {
|
|
11
|
-
renderStyleForSourceOrFallback,
|
|
12
|
-
type SourceStyleFallback,
|
|
13
|
-
} from "../../shared/style.ts";
|
|
14
|
-
|
|
15
|
-
export const ACCENT_RAIL_CHROME_WIDTH = 2;
|
|
16
|
-
|
|
17
|
-
const ACCENT_RAIL_FALLBACK: SourceStyleFallback = {
|
|
18
|
-
theme: "syntaxNumber",
|
|
19
|
-
terminal: "fg:215",
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export type AccentRailViewport = {
|
|
23
|
-
above?: string;
|
|
24
|
-
below?: string;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export type AccentRailEditorFrameOptions = {
|
|
28
|
-
width: number;
|
|
29
|
-
editorLines: string[];
|
|
30
|
-
autocompleteLines?: string[];
|
|
31
|
-
viewport?: AccentRailViewport;
|
|
32
|
-
uiTheme: Theme;
|
|
33
|
-
config: ZentuiConfig;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
function clampLines(lines: string[], width: number): string[] {
|
|
37
|
-
const maxWidth = Math.max(0, width);
|
|
38
|
-
return lines.map((line) => truncateToWidth(line, maxWidth, ""));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function selectedRail(config: ZentuiConfig): string {
|
|
42
|
-
const style = config.components.editor.styles["accent-rail"];
|
|
43
|
-
const fallback = config.icons.mode === "ascii" ? "|" : "▎";
|
|
44
|
-
const configured =
|
|
45
|
-
config.icons.mode === "ascii" ? style.asciiRail : style.rail;
|
|
46
|
-
const sanitized = sanitizeEditorMetadataText(configured);
|
|
47
|
-
const glyph = truncateToWidth(sanitized, 1, "");
|
|
48
|
-
return visibleWidth(glyph) === 1 ? glyph : fallback;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function viewportLabel(
|
|
52
|
-
direction: "above" | "below",
|
|
53
|
-
count: string | undefined,
|
|
54
|
-
): string | undefined {
|
|
55
|
-
if (!count || !/^[1-9]\d*$/.test(count)) return undefined;
|
|
56
|
-
return `${direction === "above" ? "↑" : "↓"} ${count} more`;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** Pure compact accent-rail composition shared by live rendering and settings previews. */
|
|
60
|
-
export function renderAccentRailEditorFrame({
|
|
61
|
-
width,
|
|
62
|
-
editorLines,
|
|
63
|
-
autocompleteLines = [],
|
|
64
|
-
viewport = {},
|
|
65
|
-
uiTheme,
|
|
66
|
-
config,
|
|
67
|
-
}: AccentRailEditorFrameOptions): string[] {
|
|
68
|
-
if (width < ACCENT_RAIL_CHROME_WIDTH + 1) {
|
|
69
|
-
return clampLines([...editorLines, ...autocompleteLines], width);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const contentWidth = width - ACCENT_RAIL_CHROME_WIDTH;
|
|
73
|
-
const rail = renderStyleForSourceOrFallback(
|
|
74
|
-
uiTheme,
|
|
75
|
-
config.components.editor.colorSource,
|
|
76
|
-
config.colors.editorRail,
|
|
77
|
-
ACCENT_RAIL_FALLBACK,
|
|
78
|
-
selectedRail(config),
|
|
79
|
-
);
|
|
80
|
-
const above = config.components.editor.viewportIndicators
|
|
81
|
-
? viewportLabel("above", viewport.above)
|
|
82
|
-
: undefined;
|
|
83
|
-
const below = config.components.editor.viewportIndicators
|
|
84
|
-
? viewportLabel("below", viewport.below)
|
|
85
|
-
: undefined;
|
|
86
|
-
const rows = [
|
|
87
|
-
...(above ? [above] : []),
|
|
88
|
-
...editorLines,
|
|
89
|
-
...(below ? [below] : []),
|
|
90
|
-
];
|
|
91
|
-
const transparent =
|
|
92
|
-
config.components.editor.styles["accent-rail"].transparent;
|
|
93
|
-
const layout = rows.map((line) => {
|
|
94
|
-
const railCell = transparent
|
|
95
|
-
? rail
|
|
96
|
-
: applyOwnedLayoutBackground(uiTheme, rail);
|
|
97
|
-
const bodyText = ` ${fillTerminalLine(line, contentWidth)}`;
|
|
98
|
-
const body = transparent
|
|
99
|
-
? bodyText
|
|
100
|
-
: applyOwnedLayoutBackground(uiTheme, bodyText);
|
|
101
|
-
return `${railCell}${body}`;
|
|
102
|
-
});
|
|
103
|
-
const autocompleteLayout = renderCompletionRows({
|
|
104
|
-
lines: autocompleteLines,
|
|
105
|
-
width,
|
|
106
|
-
theme: uiTheme,
|
|
107
|
-
selectedPrefix: `${rail} `,
|
|
108
|
-
ownedBackground: !transparent,
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
return clampLines([...layout, ...autocompleteLayout], width);
|
|
112
|
-
}
|