repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

refactor(fast): own fast status

1b4e456ebbbecc78769d60adc028667d0c2c6fe1

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (6)

extensions/fast/README.md

Modified
18 18 Hooks:
20 20 - `session_start`:
21 - refreshes settings from the session cwd.
21 + refreshes settings from the session cwd and publishes status.
22 22 - `model_select`:
23 - refreshes settings from the session cwd.
23 + refreshes settings from the session cwd and publishes status.
24 +- `session_shutdown`:
25 + clears published status/footer segment.
25 27 Settings:
58 60 If the clamped reasoning level is `off`, no `reasoningEffort` is sent.
60 62 No model allowlist.
64 +When active on `openai-codex`, publishes `fast` as its own UI indicator.
65 +With `@bugabinga/pi-ext-footer`, emits footer segment `fast` in the `llm` zone.
66 +Without shared footer, uses `fast` status fallback.

extensions/fast/__tests__/harness.test.ts

Modified
1 1 import path from "node:path";
2 2 import { afterEach, describe, expect, it } from "vitest";
3 3 import { createTestSession, type TestSession } from "../../../test/harness";
4 +import { _test } from "../index.ts";
5 6 describe("fast pi-test-harness", () => {
6 7 let t: TestSession | undefined;
17 18 expect(t.session.extensionRunner.extensions).toHaveLength(1);
18 19 expect(t.session.extensionRunner.extensions[0].path).toBe(extensionPath);
22 + it("parses settings and owns fast activation", () => {
23 + expect(_test.parseFastSettings({ enable: true })).toEqual({
24 + enable: true,
25 + });
26 + expect(_test.parseFastSettings({ enable: "true" })).toEqual({});
27 + expect(
28 + _test.fastActive({ model: { provider: "openai-codex" } } as any, true),
29 + ).toBe(true);
30 + expect(
31 + _test.fastActive({ model: { provider: "openai" } } as any, true),
32 + ).toBe(false);
33 + expect(
34 + _test.fastActive({ model: { provider: "openai-codex" } } as any, false),
35 + ).toBe(false);
36 + });

extensions/fast/index.ts

Modified
7 7 streamOpenAICodexResponses,
8 8 streamSimpleOpenAICodexResponses,
9 9 } from "@earendil-works/pi-ai";
10 -import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
10 +import type {
11 + ExtensionAPI,
12 + ExtensionContext,
13 + ThemeColor,
14 +} from "@earendil-works/pi-coding-agent";
11 15 import { SettingsManager } from "@earendil-works/pi-coding-agent";
17 +const FOOTER_KEY = Symbol.for("@bugabinga/pi-ext-footer");
13 18 const PROVIDER = "openai-codex";
14 19 const API = "openai-codex-responses";
15 20 const SETTINGS_KEY = "fast";
21 +const STATUS_ID = "fast";
22 +const SEGMENT_ID = "fast";
17 24 type FastSettings = { enable?: boolean };
25 +type FooterGlobal = typeof globalThis & {
26 + [FOOTER_KEY]?: { loaded?: boolean; version?: number };
27 +};
19 29 function isRecord(value: unknown): value is Record<string, unknown> {
20 30 return typeof value === "object" && value !== null && !Array.isArray(value);
36 46 return projectFast.enable ?? globalFast.enable ?? false;
49 +function hasFooter(): boolean {
50 + const footer = (globalThis as FooterGlobal)[FOOTER_KEY];
51 + return footer?.loaded === true && (footer.version ?? 0) >= 1;
54 +function fastActive(
55 + ctx: Pick<ExtensionContext, "model">,
56 + enabled: boolean,
57 +): boolean {
58 + return enabled && ctx.model?.provider === PROVIDER;
39 61 export default function fast(pi: ExtensionAPI): void {
40 62 let enabled = readEnabled(process.cwd());
43 65 enabled = readEnabled(cwd);
68 + function clear(ctx?: ExtensionContext): void {
69 + pi.events.emit("footer:segment", { id: SEGMENT_ID, text: undefined });
70 + if (ctx?.hasUI) ctx.ui.setStatus(STATUS_ID, undefined);
71 + }
73 + function publish(ctx: ExtensionContext): void {
74 + if (!ctx.hasUI) return;
75 + if (!fastActive(ctx, enabled)) {
76 + clear(ctx);
77 + return;
78 + }
80 + if (hasFooter()) {
81 + ctx.ui.setStatus(STATUS_ID, undefined);
82 + pi.events.emit("footer:segment", {
83 + id: SEGMENT_ID,
84 + text: "fast",
85 + color: "warning" as ThemeColor,
86 + zone: "llm",
87 + order: 0.5,
88 + });
89 + return;
90 + }
92 + pi.events.emit("footer:segment", { id: SEGMENT_ID, text: undefined });
93 + ctx.ui.setStatus(STATUS_ID, "fast");
94 + }
46 96 pi.registerProvider(PROVIDER, {
47 97 api: API,
48 98 streamSimple(
74 - pi.on("session_start", (_event, ctx) => refresh(ctx.cwd));
75 - pi.on("model_select", (_event, ctx) => refresh(ctx.cwd));
124 + pi.on("session_start", (_event, ctx) => {
125 + refresh(ctx.cwd);
126 + publish(ctx);
127 + });
128 + pi.on("model_select", (_event, ctx) => {
129 + refresh(ctx.cwd);
130 + publish(ctx);
131 + });
132 + pi.on("session_shutdown", (_event, ctx) => clear(ctx));
78 -export const _test = { parseFastSettings };
135 +export const _test = { fastActive, parseFastSettings };

extensions/model-info/README.md

Modified
16 16 none.
18 18 Settings read:
20 -- `fast.enable`:
21 - when the current provider is `openai-codex`, appends `fast` if enabled.
22 - Project setting overrides global setting.
19 +none.
24 21 Hooks:
44 41 ```text
45 42 gpt-5.5:off
46 -gpt-5.5:high fast
43 +gpt-5.5:high
49 46 Model label uses the last `/`-separated model id segment.

extensions/model-info/__tests__/harness.test.ts

Modified
31 31 } as any;
33 33 expect(__test.modelInfoLabel(ctx)).toBe("gpt-5.5:high");
34 - expect(__test.enabledSetting({ enable: true })).toBe(true);

extensions/model-info/index.ts

Modified
9 9 ExtensionContext,
10 10 ThemeColor,
11 11 } from "@earendil-works/pi-coding-agent";
12 -import { SettingsManager } from "@earendil-works/pi-coding-agent";
14 13 const FOOTER_KEY = Symbol.for("@bugabinga/pi-ext-footer");
15 14 const STATUS_ID = "model-info";
16 15 const SEGMENT_ID = "model";
17 -const FAST_SETTINGS_KEY = "fast";
18 -const CODEX_PROVIDER = "openai-codex";
19 -const FAST_BADGE = "fast";
21 17 type FooterGlobal = typeof globalThis & {
22 18 [FOOTER_KEY]?: { loaded?: boolean; version?: number };
27 23 return footer?.loaded === true && (footer.version ?? 0) >= 1;
30 -function isRecord(value: unknown): value is Record<string, unknown> {
31 - return typeof value === "object" && value !== null && !Array.isArray(value);
34 -function enabledSetting(value: unknown): boolean | undefined {
35 - if (!isRecord(value)) return undefined;
36 - return typeof value.enable === "boolean" ? value.enable : undefined;
39 -function fastEnabled(cwd: string): boolean {
40 - const settings = SettingsManager.create(cwd);
41 - const globalEnabled = enabledSetting(
42 - (settings.getGlobalSettings() as Record<string, unknown>)[
43 - FAST_SETTINGS_KEY
44 - ],
45 - );
46 - const projectEnabled = enabledSetting(
47 - (settings.getProjectSettings() as Record<string, unknown>)[
48 - FAST_SETTINGS_KEY
49 - ],
50 - );
51 - return projectEnabled ?? globalEnabled ?? false;
54 26 function modelLabel(ctx: Pick<ExtensionContext, "model">): string {
55 27 const modelId = ctx.model?.id ?? "no-model";
56 28 return modelId.split("/").pop() ?? modelId;
73 45 return "off";
76 -function isPriority(ctx: Pick<ExtensionContext, "cwd" | "model">): boolean {
77 - return ctx.model?.provider === CODEX_PROVIDER && fastEnabled(ctx.cwd);
80 48 function modelInfoLabel(
81 - ctx: Pick<ExtensionContext, "cwd" | "model" | "sessionManager">,
49 + ctx: Pick<ExtensionContext, "model" | "sessionManager">,
82 50 thinking?: string,
83 51 ): string {
84 - const parts = [
85 - `${modelLabel(ctx)}:${thinking ?? thinkingLevelFromBranch(ctx)}`,
86 - ];
87 - if (isPriority(ctx)) parts.push(FAST_BADGE);
88 - return parts.join(" ");
52 + return `${modelLabel(ctx)}:${thinking ?? thinkingLevelFromBranch(ctx)}`;
91 55 function publish(
132 96 export const __test = {
133 - enabledSetting,
134 97 modelInfoLabel,
135 98 modelLabel,
136 99 thinkingLevelFromBranch,