@arhen/pi-senja 1.0.6 → 1.2.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 +1 -0
- package/package.json +1 -1
- package/src/index.ts +117 -2
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ Forked from [pi-haiku](https://github.com/nnocte/pi-haiku) **0.2.0** by **nocte*
|
|
|
13
13
|
- **Quiet tool text** — tool titles and output both use the foreground beige (`fg0`) rather than loud accents, keeping panels calm against their tint.
|
|
14
14
|
- **Editor-style code colors** — pink keywords, olive strings, aqua function names, amber types, warm beige identifiers and punctuation, readable muted comments. Applies to code in tool calls/results and Markdown code blocks through Pi's syntax roles.
|
|
15
15
|
- **A live timer** while Pi works, plus elapsed-time completion message and notification. Preserves the active mode label and colour from `@arhen/pi-add-mode` (`review is working... 8s`).
|
|
16
|
+
- **Fast / Ultrafast mode** — `/fast on|off` and `/ultrafast on|off` toggle OpenAI's paid speed tiers for OpenAI requests (`service_tier: priority` / `ultrafast`). Both off by default; mutually exclusive; persisted in `<agent-dir>/fast-mode.json`. The active tier shows as a footer chip next to the model (`openai ▪ gpt-6.2-sol ▪ xhigh ▪ fast`). A bare `/fast` reports the current state. Setting a tier on a non-OpenAI model, or on a model outside the known support lists (from OpenAI's model catalog and Ultrafast docs), warns that the request may be rejected or ignored — the tier is still sent, since OpenAI is the source of truth. Per-model `samplingParams.service_tier` in `models.json` still wins.
|
|
16
17
|
- **A fresh start** — clear the visible screen on initial terminal startup without clearing scrollback.
|
|
17
18
|
|
|
18
19
|
Enabled by default in terminal UI mode. Print, JSON, SDK, and RPC modes do not install terminal components, switch themes, clear the screen, or start UI timers. `/senja` in RPC mode reports that terminal UI is required.
|
package/package.json
CHANGED
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";
|
|
@@ -32,6 +36,29 @@ interface RenderHandle {
|
|
|
32
36
|
requestRender(): void;
|
|
33
37
|
}
|
|
34
38
|
|
|
39
|
+
type SpeedTier = "fast" | "ultrafast";
|
|
40
|
+
|
|
41
|
+
// Advisory only — OpenAI rejects or silently downgrades unsupported tiers server-side,
|
|
42
|
+
// so unknown models still get the tier; they just warn here. Fast list from OpenAI's
|
|
43
|
+
// model catalog (codex 0.166.0, service_tiers/priority); Ultrafast list from OpenAI's
|
|
44
|
+
// Ultrafast mode docs. Extend as OpenAI ships new tiers/models.
|
|
45
|
+
const SPEED_TIER_SUPPORT: Record<SpeedTier, ReadonlySet<string>> = {
|
|
46
|
+
fast: new Set([
|
|
47
|
+
"gpt-5.5",
|
|
48
|
+
"gpt-5.6-luna",
|
|
49
|
+
"gpt-5.6-sol",
|
|
50
|
+
"gpt-5.6-terra",
|
|
51
|
+
"gpt-6-astra",
|
|
52
|
+
"gpt-6-luna",
|
|
53
|
+
"gpt-6-sol",
|
|
54
|
+
"gpt-6.1-sol",
|
|
55
|
+
"gpt-6.1-terra",
|
|
56
|
+
"gpt-6.2-astra",
|
|
57
|
+
"gpt-6.2-sol",
|
|
58
|
+
]),
|
|
59
|
+
ultrafast: new Set(["gpt-6.1-sol", "gpt-6.2-astra", "gpt-6.2-sol", "gpt-6-astra"]),
|
|
60
|
+
};
|
|
61
|
+
|
|
35
62
|
// ── Helpers ──────────────────────────────────────────────────────────────────
|
|
36
63
|
|
|
37
64
|
/** Replace $HOME with ~, mirroring Pi's built-in footer logic. */
|
|
@@ -295,6 +322,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
295
322
|
let workingTimer: ReturnType<typeof setInterval> | undefined;
|
|
296
323
|
let lastDoneIn: number | undefined;
|
|
297
324
|
let modeWorkingMessage: string | undefined;
|
|
325
|
+
let speedTier: SpeedTier | null = null;
|
|
326
|
+
let speedTierLoaded = false;
|
|
298
327
|
|
|
299
328
|
const unsubscribeMode = pi.events.on("pi-mode:working-message", (message) => {
|
|
300
329
|
if (message === undefined || typeof message === "string") modeWorkingMessage = message || undefined;
|
|
@@ -304,6 +333,29 @@ export default function (pi: ExtensionAPI) {
|
|
|
304
333
|
renderHandle?.requestRender();
|
|
305
334
|
}
|
|
306
335
|
|
|
336
|
+
function speedStateFile(): string {
|
|
337
|
+
return join(process.env.PI_CODING_AGENT_DIR ?? join(homedir(), ".pi", "agent"), "fast-mode.json");
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function loadSpeedTier(): void {
|
|
341
|
+
if (speedTierLoaded) return;
|
|
342
|
+
speedTierLoaded = true;
|
|
343
|
+
try {
|
|
344
|
+
const raw = JSON.parse(readFileSync(speedStateFile(), "utf8")) as { tier?: unknown };
|
|
345
|
+
speedTier = raw.tier === "fast" || raw.tier === "ultrafast" ? raw.tier : null;
|
|
346
|
+
} catch {
|
|
347
|
+
speedTier = null;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function saveSpeedTier(): void {
|
|
352
|
+
try {
|
|
353
|
+
writeFileSync(speedStateFile(), `${JSON.stringify({ tier: speedTier })}\n`);
|
|
354
|
+
} catch {
|
|
355
|
+
// Best-effort persistence; the toggle still applies to this session.
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
307
359
|
function clearWorkingTimers(): void {
|
|
308
360
|
if (workingTimer !== undefined) {
|
|
309
361
|
clearInterval(workingTimer);
|
|
@@ -315,6 +367,18 @@ export default function (pi: ExtensionAPI) {
|
|
|
315
367
|
pi.on("thinking_level_select", requestFooterRender);
|
|
316
368
|
pi.on("model_select", requestFooterRender);
|
|
317
369
|
|
|
370
|
+
// Inject the active speed tier into OpenAI requests. /fast maps to service_tier
|
|
371
|
+
// "priority": the ChatGPT backend rejects the literal "fast" value.
|
|
372
|
+
pi.on("before_provider_request", (event, ctx) => {
|
|
373
|
+
loadSpeedTier();
|
|
374
|
+
if (!speedTier) return;
|
|
375
|
+
const model = ctx.model;
|
|
376
|
+
if (!model || (model.provider !== "openai" && model.provider !== "openai-codex")) return;
|
|
377
|
+
const payload = event.payload as { model?: string; service_tier?: unknown } | undefined;
|
|
378
|
+
if (!payload || payload.model !== model.id || payload.service_tier !== undefined) return;
|
|
379
|
+
return { ...payload, service_tier: speedTier === "fast" ? "priority" : "ultrafast" };
|
|
380
|
+
});
|
|
381
|
+
|
|
318
382
|
// Track how long the current prompt has been running.
|
|
319
383
|
pi.on("agent_start", (_event, ctx) => {
|
|
320
384
|
clearWorkingTimers();
|
|
@@ -438,6 +502,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
438
502
|
const level = pi.getThinkingLevel();
|
|
439
503
|
modelBlock += ` ${theme.fg("dim", GLYPH.square)} ${theme.fg(effortColor(level), level)}`;
|
|
440
504
|
}
|
|
505
|
+
if (speedTier) {
|
|
506
|
+
modelBlock += ` ${theme.fg("dim", GLYPH.square)} ${theme.fg("warning", speedTier)}`;
|
|
507
|
+
}
|
|
441
508
|
|
|
442
509
|
const line1 = alignRight(locationBlock, modelBlock, width, theme);
|
|
443
510
|
|
|
@@ -550,7 +617,55 @@ export default function (pi: ExtensionAPI) {
|
|
|
550
617
|
},
|
|
551
618
|
});
|
|
552
619
|
|
|
620
|
+
const speedTierCommand = (tier: SpeedTier): Parameters<ExtensionAPI["registerCommand"]>[1] => ({
|
|
621
|
+
description: `OpenAI ${tier} processing: on | off (service_tier: ${tier === "fast" ? "priority" : "ultrafast"})`,
|
|
622
|
+
getArgumentCompletions: (prefix: string) =>
|
|
623
|
+
["on", "off"].filter((value) => value.startsWith(prefix)).map((value) => ({ value, label: value })),
|
|
624
|
+
handler: async (args, ctx) => {
|
|
625
|
+
loadSpeedTier();
|
|
626
|
+
const arg = args.trim().toLowerCase();
|
|
627
|
+
if (arg === "on") {
|
|
628
|
+
speedTier = tier;
|
|
629
|
+
} else if (arg === "off") {
|
|
630
|
+
if (speedTier === tier) speedTier = null;
|
|
631
|
+
} else {
|
|
632
|
+
if (ctx.hasUI) {
|
|
633
|
+
ctx.ui.notify(speedTier ? `${speedTier} mode is on` : "Fast and Ultrafast are off", "info");
|
|
634
|
+
}
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
saveSpeedTier();
|
|
638
|
+
requestFooterRender();
|
|
639
|
+
if (!ctx.hasUI) return;
|
|
640
|
+
if (!speedTier) {
|
|
641
|
+
ctx.ui.notify(`${tier} mode off`, "info");
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
const model = ctx.model;
|
|
645
|
+
if (!model || (model.provider !== "openai" && model.provider !== "openai-codex")) {
|
|
646
|
+
ctx.ui.notify(
|
|
647
|
+
`${speedTier} mode on — it only affects OpenAI requests; active model is ${model ? `${model.provider}/${model.id}` : "unset"}`,
|
|
648
|
+
"warning",
|
|
649
|
+
);
|
|
650
|
+
} else if (!SPEED_TIER_SUPPORT[tier].has(model.id)) {
|
|
651
|
+
ctx.ui.notify(
|
|
652
|
+
`${speedTier} mode on — ${model.id} is not on the known ${speedTier} support list; OpenAI may reject or ignore the request`,
|
|
653
|
+
"warning",
|
|
654
|
+
);
|
|
655
|
+
} else {
|
|
656
|
+
ctx.ui.notify(
|
|
657
|
+
`${speedTier} mode on — service_tier: ${speedTier === "fast" ? "priority" : "ultrafast"}`,
|
|
658
|
+
"info",
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
},
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
pi.registerCommand("fast", speedTierCommand("fast"));
|
|
665
|
+
pi.registerCommand("ultrafast", speedTierCommand("ultrafast"));
|
|
666
|
+
|
|
553
667
|
pi.on("session_start", (event, ctx) => {
|
|
668
|
+
loadSpeedTier();
|
|
554
669
|
clearWorkingTimers();
|
|
555
670
|
workingSince = undefined;
|
|
556
671
|
lastDoneIn = undefined;
|