@arhen/pi-senja 1.0.5 → 1.1.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 -0
- package/package.json +71 -76
- package/src/index.ts +576 -510
- package/themes/senja.json +102 -102
package/src/index.ts
CHANGED
|
@@ -7,10 +7,14 @@
|
|
|
7
7
|
* • Line 3 (optional): raw extension statuses
|
|
8
8
|
*
|
|
9
9
|
* Usage:
|
|
10
|
-
* /senja
|
|
10
|
+
* /senja Toggle on/off
|
|
11
|
+
* /fast on|off OpenAI Fast mode (service_tier: priority)
|
|
12
|
+
* /ultrafast on|off OpenAI Ultrafast mode (service_tier: ultrafast)
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
|
-
import {
|
|
15
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
16
|
+
import { homedir } from "node:os";
|
|
17
|
+
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
14
18
|
import type { AssistantMessage, ThinkingLevel } from "@earendil-works/pi-ai";
|
|
15
19
|
import type { ExtensionAPI, ExtensionContext, Theme, ThemeColor } from "@earendil-works/pi-coding-agent";
|
|
16
20
|
import { VERSION } from "@earendil-works/pi-coding-agent";
|
|
@@ -19,267 +23,260 @@ import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
|
19
23
|
// ── Visual primitives ────────────────────────────────────────────────────────
|
|
20
24
|
|
|
21
25
|
const GLYPH = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
dot: "·",
|
|
27
|
+
square: "▪",
|
|
28
|
+
barFull: "█",
|
|
29
|
+
barEmpty: "░",
|
|
30
|
+
bracketL: "[",
|
|
31
|
+
bracketR: "]",
|
|
32
|
+
pipe: "|",
|
|
29
33
|
} as const;
|
|
30
34
|
|
|
31
35
|
interface RenderHandle {
|
|
32
|
-
|
|
36
|
+
requestRender(): void;
|
|
33
37
|
}
|
|
34
38
|
|
|
39
|
+
type SpeedTier = "fast" | "ultrafast";
|
|
40
|
+
|
|
35
41
|
// ── Helpers ──────────────────────────────────────────────────────────────────
|
|
36
42
|
|
|
37
43
|
/** Replace $HOME with ~, mirroring Pi's built-in footer logic. */
|
|
38
44
|
function formatCwd(cwd: string): string {
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
const home = process.env.HOME || process.env.USERPROFILE;
|
|
46
|
+
if (!home) return cwd;
|
|
41
47
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
rel === "" || (rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel));
|
|
48
|
+
const resolvedCwd = resolve(cwd);
|
|
49
|
+
const resolvedHome = resolve(home);
|
|
50
|
+
const rel = relative(resolvedHome, resolvedCwd);
|
|
51
|
+
const insideHome = rel === "" || (rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel));
|
|
47
52
|
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
if (!insideHome) return cwd;
|
|
54
|
+
return rel === "" ? "~" : `~${sep}${rel}`;
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
/** Compact token formatter. */
|
|
53
58
|
function fmtTokens(n: number): string {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
if (n < 1000) return n.toString();
|
|
60
|
+
if (n < 10_000) return `${(n / 1000).toFixed(1)}k`;
|
|
61
|
+
if (n < 1_000_000) return `${Math.round(n / 1000)}k`;
|
|
62
|
+
if (n < 10_000_000) return `${(n / 1_000_000).toFixed(1)}M`;
|
|
63
|
+
return `${Math.round(n / 1_000_000)}M`;
|
|
59
64
|
}
|
|
60
65
|
|
|
61
66
|
/** Format milliseconds as a human-readable duration. */
|
|
62
67
|
function formatDuration(ms: number): string {
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
const totalSeconds = Math.max(0, Math.floor(ms / 1000));
|
|
69
|
+
if (totalSeconds < 60) return `${totalSeconds}s`;
|
|
65
70
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
const s = totalSeconds % 60;
|
|
72
|
+
const totalMinutes = Math.floor(totalSeconds / 60);
|
|
73
|
+
if (totalMinutes < 60) return `${totalMinutes}m ${s}s`;
|
|
69
74
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
75
|
+
const m = totalMinutes % 60;
|
|
76
|
+
const h = Math.floor(totalMinutes / 60);
|
|
77
|
+
return `${h}h ${m}m ${s}s`;
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
/** Right-align two text blocks, truncating left if they don't both fit. */
|
|
76
81
|
function alignRight(left: string, right: string, width: number, theme: Theme): string {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
82
|
+
const rightW = visibleWidth(right);
|
|
83
|
+
if (rightW > width) {
|
|
84
|
+
right = truncateToWidth(right, width, theme.fg("dim", "…"));
|
|
85
|
+
}
|
|
86
|
+
const leftW = visibleWidth(left);
|
|
87
|
+
const rightW2 = visibleWidth(right);
|
|
88
|
+
const pad = width - leftW - rightW2;
|
|
89
|
+
if (pad >= 1) {
|
|
90
|
+
return left + " ".repeat(pad) + right;
|
|
91
|
+
}
|
|
92
|
+
const availableForLeft = Math.max(0, width - rightW2 - 1);
|
|
93
|
+
const truncatedLeft = availableForLeft > 0 ? truncateToWidth(left, availableForLeft, theme.fg("dim", "…")) : "";
|
|
94
|
+
return truncatedLeft ? `${truncatedLeft} ${right}` : right;
|
|
90
95
|
}
|
|
91
96
|
|
|
92
97
|
/** Theme color for a provider name. */
|
|
93
98
|
function providerColor(provider: string): ThemeColor {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
99
|
+
switch (provider.toLowerCase()) {
|
|
100
|
+
case "anthropic":
|
|
101
|
+
return "accent";
|
|
102
|
+
case "openai":
|
|
103
|
+
case "openai-codex":
|
|
104
|
+
return "success";
|
|
105
|
+
case "google":
|
|
106
|
+
case "google-vertex":
|
|
107
|
+
return "warning";
|
|
108
|
+
case "amazon-bedrock":
|
|
109
|
+
return "thinkingHigh";
|
|
110
|
+
case "github-copilot":
|
|
111
|
+
return "mdLink";
|
|
112
|
+
case "deepseek":
|
|
113
|
+
return "thinkingLow";
|
|
114
|
+
case "xai":
|
|
115
|
+
case "groq":
|
|
116
|
+
return "error";
|
|
117
|
+
case "opencode-go":
|
|
118
|
+
return "accent";
|
|
119
|
+
default:
|
|
120
|
+
return "muted";
|
|
121
|
+
}
|
|
117
122
|
}
|
|
118
123
|
|
|
119
124
|
/** Theme color for an effort/thinking level. */
|
|
120
125
|
function effortColor(level: ThinkingLevel | string | undefined): ThemeColor {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
126
|
+
switch (level) {
|
|
127
|
+
case "minimal":
|
|
128
|
+
return "thinkingMinimal";
|
|
129
|
+
case "low":
|
|
130
|
+
return "thinkingLow";
|
|
131
|
+
case "medium":
|
|
132
|
+
return "thinkingMedium";
|
|
133
|
+
case "high":
|
|
134
|
+
return "thinkingHigh";
|
|
135
|
+
case "xhigh":
|
|
136
|
+
return "thinkingXhigh";
|
|
137
|
+
case "max":
|
|
138
|
+
return "thinkingMax";
|
|
139
|
+
default:
|
|
140
|
+
return "thinkingMedium";
|
|
141
|
+
}
|
|
137
142
|
}
|
|
138
143
|
|
|
139
144
|
/** Color scale for percentage values (context usage / cache hit). */
|
|
140
145
|
function stressColor(value: number, warn = 70, danger = 90): ThemeColor {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
146
|
+
if (value >= danger) return "error";
|
|
147
|
+
if (value >= warn) return "warning";
|
|
148
|
+
return "accent";
|
|
144
149
|
}
|
|
145
150
|
|
|
146
151
|
/** Color scale for cache-hit percentage: low is red, high is green. */
|
|
147
152
|
function cacheHitColor(value: number): ThemeColor {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
153
|
+
if (value < 30) return "error";
|
|
154
|
+
if (value < 70) return "warning";
|
|
155
|
+
return "success";
|
|
151
156
|
}
|
|
152
157
|
|
|
153
158
|
/** Render a horizontal progress bar. */
|
|
154
159
|
function renderBar(theme: Theme, pct: number, barWidth: number): string {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
160
|
+
const filled = Math.max(0, Math.min(barWidth, Math.round((pct / 100) * barWidth)));
|
|
161
|
+
const empty = barWidth - filled;
|
|
162
|
+
const color = stressColor(pct, 70, 90);
|
|
163
|
+
|
|
164
|
+
return (
|
|
165
|
+
theme.fg("dim", GLYPH.bracketL) +
|
|
166
|
+
theme.fg(color, GLYPH.barFull.repeat(filled)) +
|
|
167
|
+
theme.fg("dim", GLYPH.barEmpty.repeat(empty)) +
|
|
168
|
+
theme.fg("dim", GLYPH.bracketR)
|
|
169
|
+
);
|
|
165
170
|
}
|
|
166
171
|
|
|
167
172
|
function sanitizeStatus(text: string): string {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
return text
|
|
174
|
+
.replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\|$)/g, "")
|
|
175
|
+
.replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, (sequence) => (/^\x1b\[[0-9;:]*m$/.test(sequence) ? sequence : ""))
|
|
176
|
+
.replace(/[\r\n\t]/g, " ")
|
|
177
|
+
.replace(/[\x00-\x08\x0b-\x1a\x1c-\x1f\x7f-\x9f]|\x1b(?!\[[0-9;:]*m)/g, "")
|
|
178
|
+
.replace(/ +/g, " ")
|
|
179
|
+
.trim();
|
|
175
180
|
}
|
|
176
181
|
|
|
177
182
|
function renderHeader(theme: Theme, width: number): string[] {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
// --- Hint ---
|
|
263
|
-
lines.push("");
|
|
264
|
-
lines.push(
|
|
265
|
-
" ".repeat(INDENT) +
|
|
266
|
-
theme.fg("muted", "Pi can explain its own features and look up its docs."),
|
|
267
|
-
);
|
|
268
|
-
|
|
269
|
-
return lines.map((line) => truncateToWidth(line, width, ellipsis));
|
|
183
|
+
if (width <= 0) return [];
|
|
184
|
+
const lines: string[] = [];
|
|
185
|
+
|
|
186
|
+
// Column grid: 2-space indent · 8-wide eyebrow · 2-space gap · content.
|
|
187
|
+
const INDENT = 2;
|
|
188
|
+
const EYEBROW_W = 8;
|
|
189
|
+
const GAP = 2;
|
|
190
|
+
const contentStart = INDENT + EYEBROW_W + GAP;
|
|
191
|
+
const contentWidth = Math.max(0, width - contentStart);
|
|
192
|
+
|
|
193
|
+
// A keybinding pair: the key glows in accent, the verb sits quiet in dim.
|
|
194
|
+
const pair = (key: string, desc: string) => `${theme.fg("accent", key)} ${theme.fg("dim", desc)}`;
|
|
195
|
+
const sep = theme.fg("dim", " · ");
|
|
196
|
+
const ellipsis = theme.fg("dim", "…");
|
|
197
|
+
|
|
198
|
+
// Greedy flow: pack pairs into the content column, wrapping under the
|
|
199
|
+
// eyebrow when a line would overflow. Continuation lines align with the
|
|
200
|
+
// first content column so the key map reads as a tidy block.
|
|
201
|
+
const flowGroup = (label: string, pairs: string[]): string[] => {
|
|
202
|
+
const out: string[] = [];
|
|
203
|
+
const prefix =
|
|
204
|
+
" ".repeat(INDENT) +
|
|
205
|
+
theme.fg("warning", label) +
|
|
206
|
+
" ".repeat(Math.max(1, EYEBROW_W - visibleWidth(label))) +
|
|
207
|
+
" ".repeat(GAP);
|
|
208
|
+
let line = prefix;
|
|
209
|
+
let lineW = contentStart;
|
|
210
|
+
|
|
211
|
+
for (const seg of pairs) {
|
|
212
|
+
const segW = visibleWidth(seg);
|
|
213
|
+
if (lineW === contentStart) {
|
|
214
|
+
const fit = segW <= contentWidth ? seg : truncateToWidth(seg, contentWidth, ellipsis);
|
|
215
|
+
line += fit;
|
|
216
|
+
lineW += visibleWidth(fit);
|
|
217
|
+
} else if (lineW + visibleWidth(sep) + segW <= width) {
|
|
218
|
+
line += sep + seg;
|
|
219
|
+
lineW += visibleWidth(sep) + segW;
|
|
220
|
+
} else {
|
|
221
|
+
out.push(line);
|
|
222
|
+
const fit = segW <= contentWidth ? seg : truncateToWidth(seg, contentWidth, ellipsis);
|
|
223
|
+
line = " ".repeat(contentStart) + fit;
|
|
224
|
+
lineW = contentStart + visibleWidth(fit);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
out.push(line);
|
|
228
|
+
return out;
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
// --- Identity line: bold accent "pi", muted version, no leading spacing ---
|
|
232
|
+
lines.push(`${theme.bold(theme.fg("accent", "pi"))} ${theme.fg("muted", `v${VERSION}`)}`);
|
|
233
|
+
lines.push("");
|
|
234
|
+
|
|
235
|
+
// --- Key map, grouped by intent ---
|
|
236
|
+
lines.push(
|
|
237
|
+
...flowGroup("control", [
|
|
238
|
+
pair("esc", "interrupt"),
|
|
239
|
+
pair("ctrl+c", "clear"),
|
|
240
|
+
pair("ctrl+d", "exit"),
|
|
241
|
+
pair("ctrl+z", "suspend"),
|
|
242
|
+
pair("ctrl+k", "delete to end"),
|
|
243
|
+
]),
|
|
244
|
+
...flowGroup("models", [
|
|
245
|
+
pair("ctrl+p", "next"),
|
|
246
|
+
pair("shift+ctrl+p", "prev"),
|
|
247
|
+
pair("ctrl+l", "select"),
|
|
248
|
+
pair("shift+tab", "thinking"),
|
|
249
|
+
]),
|
|
250
|
+
...flowGroup("view", [pair("ctrl+o", "tools"), pair("ctrl+t", "thinking"), pair("ctrl+g", "editor")]),
|
|
251
|
+
...flowGroup("input", [
|
|
252
|
+
pair("/", "commands"),
|
|
253
|
+
pair("!", "bash"),
|
|
254
|
+
pair("!!", "bash·nc"),
|
|
255
|
+
pair("alt+enter", "follow-up"),
|
|
256
|
+
pair("alt+up", "queue"),
|
|
257
|
+
pair("ctrl+v", "image"),
|
|
258
|
+
pair("drop", "attach files"),
|
|
259
|
+
]),
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
// --- Hint ---
|
|
263
|
+
lines.push("");
|
|
264
|
+
lines.push(" ".repeat(INDENT) + theme.fg("muted", "Pi can explain its own features and look up its docs."));
|
|
265
|
+
|
|
266
|
+
return lines.map((line) => truncateToWidth(line, width, ellipsis));
|
|
270
267
|
}
|
|
271
268
|
|
|
272
269
|
function applyHeader(ctx: ExtensionContext): void {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
270
|
+
ctx.ui.setHeader((_tui, theme) => ({
|
|
271
|
+
render(width: number): string[] {
|
|
272
|
+
return renderHeader(theme, width);
|
|
273
|
+
},
|
|
274
|
+
invalidate() {},
|
|
275
|
+
}));
|
|
279
276
|
}
|
|
280
277
|
|
|
281
278
|
function restoreHeader(ctx: ExtensionContext): void {
|
|
282
|
-
|
|
279
|
+
ctx.ui.setHeader(undefined);
|
|
283
280
|
}
|
|
284
281
|
|
|
285
282
|
/** Clear the visible screen and home the cursor on initial launch.
|
|
@@ -289,313 +286,382 @@ function restoreHeader(ctx: ExtensionContext): void {
|
|
|
289
286
|
* Scrollback is preserved.
|
|
290
287
|
*/
|
|
291
288
|
function clearVisibleScreenOnStartup(): void {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
289
|
+
if (process.stdout.isTTY) {
|
|
290
|
+
process.stdout.write("\x1b[2J\x1b[H");
|
|
291
|
+
}
|
|
295
292
|
}
|
|
296
293
|
|
|
297
294
|
// ── Extension ────────────────────────────────────────────────────────────────
|
|
298
295
|
|
|
299
296
|
export default function (pi: ExtensionAPI) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
297
|
+
let renderHandle: RenderHandle | undefined;
|
|
298
|
+
let disposeFooter: (() => void) | undefined;
|
|
299
|
+
let enabled = true;
|
|
300
|
+
let workingSince: number | undefined;
|
|
301
|
+
let workingTimer: ReturnType<typeof setInterval> | undefined;
|
|
302
|
+
let lastDoneIn: number | undefined;
|
|
303
|
+
let modeWorkingMessage: string | undefined;
|
|
304
|
+
let speedTier: SpeedTier | null = null;
|
|
305
|
+
let speedTierLoaded = false;
|
|
306
|
+
|
|
307
|
+
const unsubscribeMode = pi.events.on("pi-mode:working-message", (message) => {
|
|
308
|
+
if (message === undefined || typeof message === "string") modeWorkingMessage = message || undefined;
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
function requestFooterRender(): void {
|
|
312
|
+
renderHandle?.requestRender();
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function speedStateFile(): string {
|
|
316
|
+
return join(process.env.PI_CODING_AGENT_DIR ?? join(homedir(), ".pi", "agent"), "fast-mode.json");
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function loadSpeedTier(): void {
|
|
320
|
+
if (speedTierLoaded) return;
|
|
321
|
+
speedTierLoaded = true;
|
|
322
|
+
try {
|
|
323
|
+
const raw = JSON.parse(readFileSync(speedStateFile(), "utf8")) as { tier?: unknown };
|
|
324
|
+
speedTier = raw.tier === "fast" || raw.tier === "ultrafast" ? raw.tier : null;
|
|
325
|
+
} catch {
|
|
326
|
+
speedTier = null;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function saveSpeedTier(): void {
|
|
331
|
+
try {
|
|
332
|
+
writeFileSync(speedStateFile(), `${JSON.stringify({ tier: speedTier })}\n`);
|
|
333
|
+
} catch {
|
|
334
|
+
// Best-effort persistence; the toggle still applies to this session.
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function clearWorkingTimers(): void {
|
|
339
|
+
if (workingTimer !== undefined) {
|
|
340
|
+
clearInterval(workingTimer);
|
|
341
|
+
workingTimer = undefined;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Re-render when state that the footer displays changes.
|
|
346
|
+
pi.on("thinking_level_select", requestFooterRender);
|
|
347
|
+
pi.on("model_select", requestFooterRender);
|
|
348
|
+
|
|
349
|
+
// Inject the active speed tier into OpenAI requests. /fast maps to service_tier
|
|
350
|
+
// "priority": the ChatGPT backend rejects the literal "fast" value.
|
|
351
|
+
pi.on("before_provider_request", (event, ctx) => {
|
|
352
|
+
loadSpeedTier();
|
|
353
|
+
if (!speedTier) return;
|
|
354
|
+
const model = ctx.model;
|
|
355
|
+
if (!model || (model.provider !== "openai" && model.provider !== "openai-codex")) return;
|
|
356
|
+
const payload = event.payload as { model?: string; service_tier?: unknown } | undefined;
|
|
357
|
+
if (!payload || payload.model !== model.id || payload.service_tier !== undefined) return;
|
|
358
|
+
return { ...payload, service_tier: speedTier === "fast" ? "priority" : "ultrafast" };
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
// Track how long the current prompt has been running.
|
|
362
|
+
pi.on("agent_start", (_event, ctx) => {
|
|
363
|
+
clearWorkingTimers();
|
|
364
|
+
workingSince = Date.now();
|
|
365
|
+
lastDoneIn = undefined;
|
|
366
|
+
|
|
367
|
+
if (ctx.mode !== "tui") return;
|
|
368
|
+
|
|
369
|
+
const tick = () => {
|
|
370
|
+
if (workingSince === undefined) return;
|
|
371
|
+
const elapsed = formatDuration(Date.now() - workingSince);
|
|
372
|
+
try {
|
|
373
|
+
ctx.ui.setWorkingMessage(`${modeWorkingMessage ?? "Working…"} ${elapsed}`);
|
|
374
|
+
} catch {
|
|
375
|
+
// Ignore if the UI is already torn down.
|
|
376
|
+
}
|
|
377
|
+
requestFooterRender();
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
tick();
|
|
381
|
+
workingTimer = setInterval(tick, 250);
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
// Report final duration and clean up timers.
|
|
385
|
+
pi.on("agent_end", (_event, ctx) => {
|
|
386
|
+
clearWorkingTimers();
|
|
387
|
+
|
|
388
|
+
if (workingSince !== undefined) {
|
|
389
|
+
lastDoneIn = Date.now() - workingSince;
|
|
390
|
+
workingSince = undefined;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
requestFooterRender();
|
|
394
|
+
|
|
395
|
+
// Show a notification and working message with the total elapsed time.
|
|
396
|
+
// The working message area may be hidden after streaming ends, so we
|
|
397
|
+
// make it visible first. The footer also displays this until the next task.
|
|
398
|
+
if (lastDoneIn !== undefined && ctx.mode === "tui") {
|
|
399
|
+
try {
|
|
400
|
+
ctx.ui.setWorkingVisible(true);
|
|
401
|
+
ctx.ui.setWorkingMessage(`Worked for ${formatDuration(lastDoneIn)}`);
|
|
402
|
+
ctx.ui.notify(`Worked for ${formatDuration(lastDoneIn)}`, "info");
|
|
403
|
+
} catch {
|
|
404
|
+
// Ignore if the UI is already torn down.
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
function applyFooter(ctx: ExtensionContext): void {
|
|
410
|
+
disposeFooter?.();
|
|
411
|
+
ctx.ui.setFooter((tui, theme, footerData) => {
|
|
412
|
+
disposeFooter?.();
|
|
413
|
+
renderHandle = tui;
|
|
414
|
+
const unsubscribeBranch = footerData.onBranchChange(() => tui.requestRender());
|
|
415
|
+
let disposed = false;
|
|
416
|
+
const dispose = () => {
|
|
417
|
+
if (disposed) return;
|
|
418
|
+
disposed = true;
|
|
419
|
+
unsubscribeBranch();
|
|
420
|
+
if (disposeFooter === dispose) {
|
|
421
|
+
disposeFooter = undefined;
|
|
422
|
+
renderHandle = undefined;
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
disposeFooter = dispose;
|
|
426
|
+
|
|
427
|
+
return {
|
|
428
|
+
dispose,
|
|
429
|
+
invalidate() {
|
|
430
|
+
// Stateless render; nothing to cache.
|
|
431
|
+
},
|
|
432
|
+
render(width: number): string[] {
|
|
433
|
+
if (width <= 0) return [];
|
|
434
|
+
// ── Aggregate usage across every assistant message ───────────────
|
|
435
|
+
let totalInput = 0;
|
|
436
|
+
let totalOutput = 0;
|
|
437
|
+
let totalCost = 0;
|
|
438
|
+
let latestCacheHitRate: number | undefined;
|
|
439
|
+
|
|
440
|
+
for (const entry of ctx.sessionManager.getEntries()) {
|
|
441
|
+
if (entry.type === "message" && entry.message.role === "assistant") {
|
|
442
|
+
const m = entry.message as AssistantMessage;
|
|
443
|
+
totalInput += m.usage.input;
|
|
444
|
+
totalOutput += m.usage.output;
|
|
445
|
+
totalCost += m.usage.cost.total;
|
|
446
|
+
|
|
447
|
+
const promptTokens = m.usage.input + m.usage.cacheRead + m.usage.cacheWrite;
|
|
448
|
+
latestCacheHitRate = promptTokens > 0 ? (m.usage.cacheRead / promptTokens) * 100 : undefined;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// ── Context usage for the active model ───────────────────────────
|
|
453
|
+
const contextUsage = ctx.getContextUsage();
|
|
454
|
+
const contextWindow = contextUsage?.contextWindow ?? ctx.model?.contextWindow ?? 0;
|
|
455
|
+
const contextTokens = contextUsage?.tokens ?? null;
|
|
456
|
+
const contextPercent = contextUsage?.percent ?? null;
|
|
457
|
+
const contextPctValue = contextPercent ?? 0;
|
|
458
|
+
|
|
459
|
+
// ── Location / session metadata ──────────────────────────────────
|
|
460
|
+
const cwd = sanitizeStatus(formatCwd(ctx.sessionManager.getCwd()));
|
|
461
|
+
const branch = sanitizeStatus(footerData.getGitBranch() ?? "");
|
|
462
|
+
const sessionName = sanitizeStatus(ctx.sessionManager.getSessionName() ?? "");
|
|
463
|
+
|
|
464
|
+
// ── Provider / model / effort metadata ───────────────────────────
|
|
465
|
+
const provider = sanitizeStatus(ctx.model?.provider ?? "none");
|
|
466
|
+
const modelId = sanitizeStatus(ctx.model?.id ?? "no-model");
|
|
467
|
+
const reasoning = ctx.model?.reasoning ?? false;
|
|
468
|
+
const usingSubscription = ctx.model ? ctx.modelRegistry.isUsingOAuth(ctx.model) : false;
|
|
469
|
+
|
|
470
|
+
// ── Line 1: location left, provider ▪ model ▪ effort right ───────
|
|
471
|
+
let locationBlock = theme.fg("accent", cwd);
|
|
472
|
+
if (branch) {
|
|
473
|
+
locationBlock += ` ${theme.fg("dim", "branch")} ${theme.fg("success", branch)}`;
|
|
474
|
+
}
|
|
475
|
+
if (sessionName) {
|
|
476
|
+
locationBlock += ` ${theme.fg("dim", "session")} ${theme.fg("text", sessionName)}`;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
let modelBlock = `${theme.fg(providerColor(provider), String(provider))} ${theme.fg("dim", GLYPH.square)} ${theme.fg("text", modelId)}`;
|
|
480
|
+
if (reasoning) {
|
|
481
|
+
const level = pi.getThinkingLevel();
|
|
482
|
+
modelBlock += ` ${theme.fg("dim", GLYPH.square)} ${theme.fg(effortColor(level), level)}`;
|
|
483
|
+
}
|
|
484
|
+
if (speedTier) {
|
|
485
|
+
modelBlock += ` ${theme.fg("dim", GLYPH.square)} ${theme.fg("warning", speedTier)}`;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const line1 = alignRight(locationBlock, modelBlock, width, theme);
|
|
489
|
+
|
|
490
|
+
// ── Line 2: working/done timer + stats left, context right ───────
|
|
491
|
+
const stats: string[] = [];
|
|
492
|
+
|
|
493
|
+
if (totalInput > 0) {
|
|
494
|
+
stats.push(`${theme.fg("dim", "in")} ${theme.fg("accent", `↑${fmtTokens(totalInput)}`)}`);
|
|
495
|
+
}
|
|
496
|
+
if (totalOutput > 0) {
|
|
497
|
+
stats.push(`${theme.fg("dim", "out")} ${theme.fg("success", `↓${fmtTokens(totalOutput)}`)}`);
|
|
498
|
+
}
|
|
499
|
+
if (latestCacheHitRate !== undefined) {
|
|
500
|
+
stats.push(
|
|
501
|
+
`${theme.fg("dim", "cache hit")} ${theme.fg(
|
|
502
|
+
cacheHitColor(latestCacheHitRate),
|
|
503
|
+
`${latestCacheHitRate.toFixed(1)}%`,
|
|
504
|
+
)}`,
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
if (totalCost > 0) {
|
|
509
|
+
const costText = `$${totalCost.toFixed(3)}${usingSubscription ? " (sub)" : ""}`;
|
|
510
|
+
stats.push(`${theme.fg("dim", "cost")} ${theme.fg("warning", costText)}`);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
const statsBlock = stats.join(` ${theme.fg("dim", GLYPH.pipe)} `);
|
|
514
|
+
|
|
515
|
+
let contextBlock = "";
|
|
516
|
+
if (contextTokens !== null && contextTokens > 0) {
|
|
517
|
+
const pctText = theme.fg(stressColor(contextPctValue, 70, 90), `${contextPctValue.toFixed(1)}%`);
|
|
518
|
+
const contextText = `${theme.fg("text", fmtTokens(contextTokens))}${theme.fg("dim", "/")}${theme.fg("text", fmtTokens(contextWindow))}`;
|
|
519
|
+
// Fit the context block within the available width so the right-hand
|
|
520
|
+
// numbers aren't truncated (e.g. 50k/500k becoming 50k/5...).
|
|
521
|
+
const reserved = visibleWidth(pctText) + visibleWidth(contextText) + 4 + 2; // separators + brackets
|
|
522
|
+
const barWidth = Math.max(6, Math.min(16, width - reserved));
|
|
523
|
+
contextBlock = `${renderBar(theme, contextPctValue, barWidth)} ${pctText} ${theme.fg("dim", GLYPH.square)} ${contextText}`;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
let timerBlock = "";
|
|
527
|
+
if (workingSince !== undefined) {
|
|
528
|
+
timerBlock = `${theme.fg("dim", "working")} ${theme.fg("accent", formatDuration(Date.now() - workingSince))}`;
|
|
529
|
+
} else if (lastDoneIn !== undefined) {
|
|
530
|
+
timerBlock = `${theme.fg("success", "worked")} ${theme.fg("text", `for ${formatDuration(lastDoneIn)}`)}`;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
let rightBlock = statsBlock;
|
|
534
|
+
if (contextBlock) {
|
|
535
|
+
rightBlock = rightBlock ? alignRight(rightBlock, contextBlock, width, theme) : contextBlock;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
let line2: string | undefined;
|
|
539
|
+
if (timerBlock && rightBlock) {
|
|
540
|
+
line2 = alignRight(timerBlock, rightBlock, width, theme);
|
|
541
|
+
} else if (timerBlock) {
|
|
542
|
+
line2 = timerBlock;
|
|
543
|
+
} else if (rightBlock) {
|
|
544
|
+
line2 = rightBlock;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// ── Optional line 3: raw extension statuses ──────────────────────
|
|
548
|
+
const lines: string[] = [line1];
|
|
549
|
+
if (line2) {
|
|
550
|
+
lines.push(line2);
|
|
551
|
+
}
|
|
552
|
+
const extensionStatuses = footerData.getExtensionStatuses();
|
|
553
|
+
|
|
554
|
+
if (extensionStatuses.size > 0) {
|
|
555
|
+
const divider = ` ${GLYPH.pipe} `;
|
|
556
|
+
const rawStatuses = Array.from(extensionStatuses.entries())
|
|
557
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
558
|
+
.map(([, text]) => sanitizeStatus(text))
|
|
559
|
+
.filter((text) => text.length > 0)
|
|
560
|
+
.join(divider);
|
|
561
|
+
if (rawStatuses) {
|
|
562
|
+
lines.push(theme.fg("dim", rawStatuses));
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
// Truncate every line to exact terminal width; no trailing spacing.
|
|
567
|
+
return lines.map((line) => truncateToWidth(line, width, theme.fg("dim", "…")));
|
|
568
|
+
},
|
|
569
|
+
};
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function restoreFooter(ctx: ExtensionContext): void {
|
|
574
|
+
disposeFooter?.();
|
|
575
|
+
ctx.ui.setFooter(undefined);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// Toggle command.
|
|
579
|
+
pi.registerCommand("senja", {
|
|
580
|
+
description: "Toggle the Senja header and footer",
|
|
581
|
+
handler: async (_args, ctx) => {
|
|
582
|
+
if (ctx.mode !== "tui") {
|
|
583
|
+
if (ctx.hasUI) ctx.ui.notify("Senja requires terminal UI mode", "info");
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
enabled = !enabled;
|
|
587
|
+
if (enabled) {
|
|
588
|
+
applyFooter(ctx);
|
|
589
|
+
applyHeader(ctx);
|
|
590
|
+
ctx.ui.notify("Senja enabled", "info");
|
|
591
|
+
} else {
|
|
592
|
+
restoreFooter(ctx);
|
|
593
|
+
restoreHeader(ctx);
|
|
594
|
+
ctx.ui.notify("Default UI restored", "info");
|
|
595
|
+
}
|
|
596
|
+
},
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
const speedTierCommand = (tier: SpeedTier): Parameters<ExtensionAPI["registerCommand"]>[1] => ({
|
|
600
|
+
description: `OpenAI ${tier} processing: on | off (service_tier: ${tier === "fast" ? "priority" : "ultrafast"})`,
|
|
601
|
+
getArgumentCompletions: (prefix: string) =>
|
|
602
|
+
["on", "off"].filter((value) => value.startsWith(prefix)).map((value) => ({ value, label: value })),
|
|
603
|
+
handler: async (args, ctx) => {
|
|
604
|
+
loadSpeedTier();
|
|
605
|
+
const arg = args.trim().toLowerCase();
|
|
606
|
+
if (arg === "on") {
|
|
607
|
+
speedTier = tier;
|
|
608
|
+
} else if (arg === "off") {
|
|
609
|
+
if (speedTier === tier) speedTier = null;
|
|
610
|
+
} else {
|
|
611
|
+
if (ctx.hasUI) {
|
|
612
|
+
ctx.ui.notify(speedTier ? `${speedTier} mode is on` : "Fast and Ultrafast are off", "info");
|
|
613
|
+
}
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
saveSpeedTier();
|
|
617
|
+
requestFooterRender();
|
|
618
|
+
if (ctx.hasUI) {
|
|
619
|
+
ctx.ui.notify(
|
|
620
|
+
speedTier
|
|
621
|
+
? `${speedTier} mode on — service_tier: ${speedTier === "fast" ? "priority" : "ultrafast"}`
|
|
622
|
+
: `${tier} mode off`,
|
|
623
|
+
"info",
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
},
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
pi.registerCommand("fast", speedTierCommand("fast"));
|
|
630
|
+
pi.registerCommand("ultrafast", speedTierCommand("ultrafast"));
|
|
631
|
+
|
|
632
|
+
pi.on("session_start", (event, ctx) => {
|
|
633
|
+
loadSpeedTier();
|
|
634
|
+
clearWorkingTimers();
|
|
635
|
+
workingSince = undefined;
|
|
636
|
+
lastDoneIn = undefined;
|
|
637
|
+
disposeFooter?.();
|
|
638
|
+
if (ctx.mode !== "tui") return;
|
|
639
|
+
|
|
640
|
+
if (event.reason === "startup") {
|
|
641
|
+
clearVisibleScreenOnStartup();
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
const result = ctx.ui.setTheme("senja");
|
|
645
|
+
if (!result.success) {
|
|
646
|
+
ctx.ui.notify(`Senja theme: ${result.error ?? "unknown error"}`, "warning");
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
if (enabled) {
|
|
650
|
+
applyFooter(ctx);
|
|
651
|
+
applyHeader(ctx);
|
|
652
|
+
} else {
|
|
653
|
+
restoreFooter(ctx);
|
|
654
|
+
restoreHeader(ctx);
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
pi.on("session_shutdown", () => {
|
|
659
|
+
unsubscribeMode();
|
|
660
|
+
modeWorkingMessage = undefined;
|
|
661
|
+
clearWorkingTimers();
|
|
662
|
+
workingSince = undefined;
|
|
663
|
+
lastDoneIn = undefined;
|
|
664
|
+
disposeFooter?.();
|
|
665
|
+
renderHandle = undefined;
|
|
666
|
+
});
|
|
601
667
|
}
|