repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by admin

fixes for some extensions

0a41f7c6de46063c07ec2b2cc65eee8226c2f42b

Oliver Krylow <o.krylow@isp-insoft.de> ·

SSH signature · not checked

Browse filesCompare with HEAD

Changed files (23)

CHANGELOG.md

Modified
3 3 # Changelog
5 5 ## Unreleased
7 7 - Redesign Angel with persistent investigative child sessions, inherited tools, bounded on-demand access to pinned parent context, automatic failure analysis, cancellable live progress, and stale-session delivery protection
8 +- Shorten model labels consistently in model status displays, including family-specific speed and release qualifiers
8 9 - Remove the cmprss, Leaks, and Verboten extensions and the dedicated Leaks fuzz task
9 10 - Remove the always-on Terse extension; configure personal response style through Pi's `APPEND_SYSTEM.md` instead
10 11 - Improve Decay progress with neutral pending history, a combined history and retained-tail row, readable labels, and continuous merge animation with atom and streamed-token counts
21 22 - Fix Strata cancellation and session shutdown so pending requests and subprocesses settle before cleanup finishes
22 23 - Keep Ultra's intermediate results out of orchestrator context, return final output once, and replace output above 50KB or 2000 lines with a full-output file reference while preserving complete results in UI details
23 24 - Let Ultra configure named model tiers with default thinking levels and orchestrator selection guidance, merge global and project overrides, use the session model by default across providers, and start fresh checkpoints when effective model or thinking routes change
25 +- Make Ultra choose the least-compute model tier likely to meet each step's acceptance criteria and escalate only for a concrete reasoning bottleneck
24 26 - Remove Strata Ask's fixed tool-call, round, batch, and cumulative-output caps while retaining per-tool resource limits and cancellation
25 27 - Add optional Strata GitHub PR reviews with confirmed checkout switching, attributed read-only discussions, and PR-aware feedback; keep saved plans and drafts separate across PRs and forge hosts
26 28 - Add Strata Vim-style line, hunk, layer, and pane navigation, literal diff search, keyboard review actions, whole-layer review toggles, and contextual shortcut guides

extensions/angel/README.md

Modified
98 98 ## UI
100 +When available, Angel publishes semantic `model-route:angel` state for `model-info` to render as `󰧑 <advisor>:<thinking>`.
101 +Without `model-info`, it publishes the full advisor id and thinking level as an `angel` status fallback.
100 103 Final advice is shown prominently as Markdown.
101 104 Model, effective thinking level, origin, runtime, token use, cost when known, and child-session identity are subdued metadata.
102 105 The complete investigation remains in the child session and is inspected through Pi's normal session browser.

extensions/angel/__tests__/harness.test.ts

Modified
101 101 expect(runner.hasHandlers("tool_call")).toBe(false);
104 + it("publishes and clears its fallback availability status", async () => {
105 + testSession = await createTestSession({
106 + extensionFactories: [createAngelExtension(dependencies())],
107 + });
108 + expect(testSession.events.uiCallsFor("setStatus").at(-1)?.args[1]).toMatch(
109 + /^󰧑 angel: gpt-4o:/u,
110 + );
112 + const runner = testSession.session.extensionRunner;
113 + await runner
114 + .getCommand("angel")
115 + ?.handler("off", runner.createCommandContext());
116 + expect(
117 + testSession.events.uiCallsFor("setStatus").at(-1)?.args[1],
118 + ).toBeUndefined();
119 + });
104 121 it("returns tool advice once and appends one UI-only advice entry", async () => {
105 122 const deps = dependencies();
106 123 testSession = await createTestSession({

extensions/angel/index.ts

Modified
1 1 import { createHash } from "node:crypto";
2 2 import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
3 -import type { Api, Model, ToolResultMessage } from "@earendil-works/pi-ai";
3 +import {
4 + type Api,
5 + clampThinkingLevel,
6 + type Model,
7 + type ToolResultMessage,
8 +} from "@earendil-works/pi-ai";
4 9 import {
5 10 DEFAULT_MAX_BYTES,
6 11 DEFAULT_MAX_LINES,
73 78 const ADVICE_TYPE = "angel-advice";
74 79 const STATUS_TYPE = "angel-status";
75 80 const CHILD_MARKER = "angel-child";
81 +const STATUS_ID = "angel";
82 +const ANGEL_ICON = "󰧑";
76 83 const PREVIEW_MAX_CHARS = 1_200;
77 84 const DEFAULT_THINKING_LEVEL: ThinkingLevel = "max";
78 85 const LOW_SIGNAL_BUILTINS = new Set([
448 + function clearAvailabilityStatus(ctx?: ExtensionContext): void {
449 + pi.events.emit("model-route:angel", { advisor: undefined });
450 + if (ctx?.hasUI) ctx.ui.setStatus(STATUS_ID, undefined);
441 453 function syncAvailability(
442 454 ctx: ExtensionContext,
443 455 executor = ctx.model,
444 456 ): void {
445 - const available = isAvailable(ctx, executor);
457 + const binding = resolveBinding(ctx, settings, executor);
458 + const available =
459 + enabled() &&
460 + !!binding &&
461 + ctx.modelRegistry.hasConfiguredAuth(binding.advisor);
446 462 const tools = pi.getActiveTools();
447 463 const present = tools.includes("angel");
448 464 if (available && !present) pi.setActiveTools([...tools, "angel"]);
449 465 if (!available && present)
450 466 pi.setActiveTools(tools.filter((tool) => tool !== "angel"));
468 + if (!available || !binding) {
469 + clearAvailabilityStatus(ctx);
470 + return;
472 + const thinkingLevel = clampThinkingLevel(
473 + binding.advisor,
474 + settings.thinkingLevel ?? DEFAULT_THINKING_LEVEL,
475 + );
476 + if (ctx.hasUI)
477 + ctx.ui.setStatus(
478 + STATUS_ID,
479 + `${ANGEL_ICON} angel: ${binding.advisor.id}:${thinkingLevel}`,
480 + );
481 + pi.events.emit("model-route:angel", {
482 + advisor: { modelId: binding.advisor.id, thinkingLevel },
483 + });
453 486 async function run(
568 601 syncAvailability(ctx);
571 - pi.on("session_shutdown", () => {
604 + pi.on("session_shutdown", (_event, ctx) => {
605 + clearAvailabilityStatus(ctx);
572 606 sessionGeneration += 1;
573 607 taskGeneration += 1;
574 608 active = false;

extensions/fast/README.md

Modified
64 64 No model allowlist.
66 -When active on `openai-codex`, publishes `fast` as its UI indicator.
67 -With `@bugabinga/pi-ext-footer`, emits footer segment `fast` in the `llm` zone.
68 -Without shared footer, uses `fast` status fallback.
66 +When active on `openai-codex`, publishes semantic `model-route:fast` state for `model-info` to render as the Nerd Font lightning-bolt icon `󱐋`.
67 +Without `model-info`, it uses the icon as its status fallback.

extensions/fast/index.ts

Modified
12 12 import type {
13 13 ExtensionAPI,
14 14 ExtensionContext,
15 - ThemeColor,
16 15 } from "@earendil-works/pi-coding-agent";
17 16 import { SettingsManager } from "@earendil-works/pi-coding-agent";
19 -const FOOTER_KEY = Symbol.for("@bugabinga/pi-ext-footer");
20 18 const PROVIDER = "openai-codex";
21 19 const API = "openai-codex-responses";
22 20 const SETTINGS_KEY = "fast";
23 21 const STATUS_ID = "fast";
24 -const SEGMENT_ID = "fast";
22 +const FAST_ICON = "󱐋";
26 24 type FastSettings = { enable?: boolean };
27 -type FooterGlobal = typeof globalThis & {
28 - [FOOTER_KEY]?: { loaded?: boolean; version?: number };
29 -};
31 26 function isRecord(value: unknown): value is Record<string, unknown> {
32 27 return typeof value === "object" && value !== null && !Array.isArray(value);
58 -function hasFooter(): boolean {
59 - const footer = (globalThis as FooterGlobal)[FOOTER_KEY];
60 - return footer?.loaded === true && (footer.version ?? 0) >= 1;
63 53 function fastActive(
64 54 ctx: Pick<ExtensionContext, "model">,
65 55 enabled: boolean,
80 70 function clear(ctx?: ExtensionContext): void {
81 - pi.events.emit("footer:segment", { id: SEGMENT_ID, text: undefined });
71 + pi.events.emit("model-route:fast", { active: false });
82 72 if (ctx?.hasUI) ctx.ui.setStatus(STATUS_ID, undefined);
89 79 return;
92 - if (hasFooter()) {
93 - ctx.ui.setStatus(STATUS_ID, undefined);
94 - pi.events.emit("footer:segment", {
95 - id: SEGMENT_ID,
96 - text: "fast",
97 - color: "warning" as ThemeColor,
98 - zone: "llm",
99 - order: 0.5,
100 - });
101 - return;
102 - }
104 - pi.events.emit("footer:segment", { id: SEGMENT_ID, text: undefined });
105 - ctx.ui.setStatus(STATUS_ID, "fast");
82 + ctx.ui.setStatus(STATUS_ID, FAST_ICON);
83 + pi.events.emit("model-route:fast", { active: true });
108 86 pi.registerProvider(PROVIDER, {

extensions/footer/README.md

Modified
18 18 - `session_start`
19 19 - `session_shutdown`
20 20 - Events:
21 - - listens for `footer:segment`.
21 + - listens for `footer:segment` and `footer:probe`.
22 + - emits runtime-scoped `footer:ready` capability announcements.
22 23 - Settings: none.
24 25 ## Behavior
26 27 Owns the Pi footer through `ctx.ui.setFooter()`.
28 -Visible footer has stable height:
29 +Visible footer has a stable two-line height:
30 -- line 0: `workspace` segments plus current session name.
31 -- lines 1-2: `llm` segments, flow layout, overflow on line 2.
32 -- line 3: extension statuses via `ctx.ui.setStatus()`.
31 +- line 0: `workspace` segments plus current session name on the left, with extension statuses via `ctx.ui.setStatus()` right-aligned in the remaining space.
32 +- line 1: the first `llm` flow row; overflow is not shown.
34 34 `footer:segment` payloads use `id`, `text`, and `zone` (`workspace` or `llm`).
35 -Optional fields: `variants`, `icon`, `color`, `bar`, `suffix`, `order`.
35 +Optional fields: `variants`, `icon`, `color`, `bar`, `suffix`, `group`, `separator`, and `order`.
37 +Adjacent segments with the same `group` stay together during line flow.
38 +Grouped segments use a space internally unless a segment supplies the separator that precedes it.
37 40 Send `{ id, text: undefined }` to remove a segment.

extensions/footer/__tests__/harness.test.ts

Modified
1 1 import path from "node:path";
2 +import { visibleWidth } from "@earendil-works/pi-tui";
2 3 import { afterEach, describe, expect, it } from "vitest";
3 4 import { createTestSession, type TestSession } from "../../../test/harness";
5 +import { __test } from "../index.ts";
5 7 describe("footer pi-test-harness", () => {
6 8 let t: TestSession | undefined;
17 19 expect(t.session.extensionRunner.extensions).toHaveLength(1);
18 20 expect(t.session.extensionRunner.extensions[0].path).toBe(extensionPath);
23 + it("right-aligns statuses beside the workspace row", () => {
24 + expect(__test.alignLeftAndRight("workspace", "busy", 16)).toBe(
25 + "workspace busy",
26 + );
27 + });
29 + it("preserves the workspace row when statuses exceed the remaining space", () => {
30 + const line = __test.alignLeftAndRight("workspace", "very long status", 12);
32 + expect(visibleWidth(line)).toBe(12);
33 + expect(line.startsWith("workspace ")).toBe(true);
34 + });
36 + it("uses the first row when its first group is oversized", () => {
37 + const [first, second] = __test.flowLines(
38 + ["oversized-model-route", "tokens"],
39 + " | ",
40 + 8,
41 + );
43 + expect(first).not.toBe("");
44 + expect(second).toBe("tokens");
45 + });
47 + it("keeps adjacent members of a named segment group atomic", () => {
48 + const model = { id: "model", text: "sol:medium", zone: "llm" } as const;
49 + const fast = {
50 + id: "fast",
51 + text: "",
52 + zone: "llm",
53 + group: "model-route",
54 + } as const;
55 + const angel = {
56 + id: "angel",
57 + text: "astra:max",
58 + zone: "llm",
59 + group: "model-route",
60 + } as const;
61 + const tokens = { id: "tokens", text: "1k", zone: "llm" } as const;
63 + expect(
64 + __test.groupSegments([
65 + { ...model, group: "model-route" },
66 + fast,
67 + angel,
68 + tokens,
69 + ]),
70 + ).toEqual([[{ ...model, group: "model-route" }, fast, angel], [tokens]]);
71 + });

extensions/footer/index.ts

Modified
3 3 * Footer renderer extension.
5 5 * Listens for "footer:segment" events from producer extensions and renders
6 - * a 4-line footer with stable height:
7 - * line 0 = workspace zone (cwd, branch, PR, runtime, session name)
8 - * line 1-2 = llm zone (model, thinking, context, tokens, cost, timing) — flow layout
9 - * line 3 = extension statuses via ctx.ui.setStatus()
6 + * a 2-line footer with stable height:
7 + * line 0 = workspace zone left-aligned, extension statuses right-aligned
8 + * line 1 = llm zone (model, thinking, context, tokens, cost, timing)
11 10 * Producers use semantic zones ("workspace" | "llm"). Footer decides row mapping.
12 11 * Publishes a process-global capability flag so producers can choose footer
55 54 bar?: number;
56 55 suffix?: string;
57 56 zone: FooterZone;
57 + group?: string;
58 + separator?: string;
58 59 order?: number;
81 82 .trim();
85 +function groupSegments(segments: Segment[]): Segment[][] {
86 + const groups: Segment[][] = [];
87 + for (const segment of segments) {
88 + const previous = groups.at(-1);
89 + if (segment.group && previous?.[0]?.group === segment.group)
90 + previous.push(segment);
91 + else groups.push([segment]);
92 + }
93 + return groups;
96 +function alignLeftAndRight(left: string, right: string, width: number): string {
97 + const safeLeft = truncateToWidth(left, width);
98 + const leftWidth = visibleWidth(safeLeft);
99 + if (!right || leftWidth >= width) return safeLeft;
101 + const gapWidth = leftWidth > 0 ? 1 : 0;
102 + const available = width - leftWidth - gapWidth;
103 + if (available <= 0) return safeLeft;
105 + const safeRight = truncateToWidth(right, available);
106 + const padding = width - leftWidth - visibleWidth(safeRight);
107 + return safeLeft + " ".repeat(padding) + safeRight;
110 +function flowLines(
111 + rendered: string[],
112 + separator: string,
113 + width: number,
114 +): [string, string] {
115 + let line1 = "";
116 + let line1Width = 0;
117 + let overflowIndex = -1;
119 + for (const [index, segment] of rendered.entries()) {
120 + const segmentWidth = visibleWidth(segment);
121 + const prefixWidth = line1Width > 0 ? visibleWidth(separator) : 0;
122 + if (line1Width + prefixWidth + segmentWidth <= width) {
123 + line1 += (line1Width > 0 ? separator : "") + segment;
124 + line1Width += prefixWidth + segmentWidth;
125 + continue;
127 + if (line1Width === 0) {
128 + line1 = truncateToWidth(segment, width);
129 + overflowIndex = index + 1;
130 + } else overflowIndex = index;
131 + break;
134 + if (overflowIndex < 0 || overflowIndex >= rendered.length) return [line1, ""];
135 + return [
136 + line1,
137 + truncateToWidth(rendered.slice(overflowIndex).join(separator), width),
138 + ];
84 141 /** Zero-height footer stub for hidden mode. */
85 142 const HIDDEN_FOOTER = {
86 143 dispose: () => {},
119 176 pi.events.on("footer:segment", handleSegment);
177 + pi.events.on("footer:probe", () =>
178 + pi.events.emit("footer:ready", { version: 1 }),
179 + );
180 + pi.events.emit("footer:ready", { version: 1 });
121 182 // ── Coalesced render scheduling ───────────────────────────────
186 247 return segs.map((s) => renderSegment(s, theme, width)).join(sep);
250 + function renderSegmentGroup(
251 + segments: Segment[],
252 + theme: Theme,
253 + width: number,
254 + ): string {
255 + return segments
256 + .map((segment, index) => {
257 + const rendered = renderSegment(segment, theme, width);
258 + if (index === 0) return rendered;
259 + const separator = sanitizeDisplayText(segment.separator ?? "");
260 + const joiner = separator
261 + ? ` ${theme.fg(SEPARATOR_COLOR, separator)} `
262 + : " ";
263 + return joiner + rendered;
264 + })
265 + .join("");
189 268 // ── Zone rendering ────────────────────────────────────────────
191 270 function safeSessionName(
227 306 if (segs.length === 0) return ["", ""];
229 308 const sep = theme.fg(SEPARATOR_COLOR, " | ");
230 - const rendered = segs.map((s) => renderSegment(s, theme, width));
232 - let line1 = "";
233 - let line1Width = 0;
234 - let overflowIndex = -1;
236 - for (const [i, segment] of rendered.entries()) {
237 - const segWidth = visibleWidth(segment);
238 - const prefixWidth = line1Width > 0 ? visibleWidth(sep) : 0;
240 - if (line1Width + prefixWidth + segWidth <= width) {
241 - line1 += (line1Width > 0 ? sep : "") + segment;
242 - line1Width += prefixWidth + segWidth;
243 - } else {
244 - overflowIndex = i;
245 - break;
246 - }
247 - }
249 - if (overflowIndex === -1) return [line1, ""];
251 - const line2 = truncateToWidth(
252 - rendered.slice(overflowIndex).join(sep),
253 - width,
309 + const rendered = groupSegments(segs).map((group) =>
310 + renderSegmentGroup(group, theme, width),
255 - return [line1, line2];
313 + return flowLines(rendered, sep, width);
258 316 function renderStatusLine(
275 333 ): string[] {
276 334 const contentWidth = Math.max(0, width - 2);
277 335 const workspaceLine = renderWorkspaceLine(theme, contentWidth, ctx);
278 - const [llmLine1, llmLine2] = renderLlmLines(theme, contentWidth);
336 + const [llmLine] = renderLlmLines(theme, contentWidth);
279 337 const statusLine = renderStatusLine(theme, statuses);
338 + const topLine = alignLeftAndRight(workspaceLine, statusLine, contentWidth);
281 - return [
282 - padLine(workspaceLine, width),
283 - padLine(llmLine1, width),
284 - padLine(llmLine2, width),
285 - padLine(statusLine, width),
286 - ];
340 + return [padLine(topLine, width), padLine(llmLine, width)];
289 343 // ── Mounting ──────────────────────────────────────────────────
363 417 currentCtx = undefined;
421 +export const __test = { alignLeftAndRight, flowLines, groupSegments };

extensions/model-info/README.md

Modified
1 1 # model-info
3 -Model and thinking telemetry for Pi.
3 +Compact executor, transport, and advisor telemetry for Pi.
5 5 ## Install / load
27 27 - `session_shutdown`:
28 28 clears the footer segment and status fallback.
30 +Events consumed:
32 +- `model-route:fast`:
33 + updates the executor transport indicator.
34 +- `model-route:angel`:
35 + updates the advisor model and thinking level.
30 37 Events emitted:
32 39 - `footer:segment`:
33 - publishes or clears segment `model` in the `llm` zone.
40 + publishes or clears the grouped `model`, `fast`, and `angel` segments in the `llm` zone.
35 42 UI status:
39 46 ## Behavior
41 -Shows current model id plus thinking level:
48 +Shows a compact current model label plus thinking level:
43 50 ```text
44 -gpt-5.5:off
45 -gpt-5.5:high
51 +sol:medium
52 +opus:high
48 -Model label uses the last `/`-separated model id segment.
55 +Known model families are shortened according to their naming grammar rather than a maintained model alias list.
56 +Unknown families retain the last `/`-separated model id segment.
49 57 Missing model becomes `no-model`.
51 59 Thinking level comes from `thinking_level_select`; otherwise from the latest
52 60 `thinking_level_change` session entry; fallback is `off`.
54 -When the shared footer is loaded, the extension publishes footer segment
55 -`model` with color `syntaxKeyword`, zone `llm`, and order `0`.
62 +When the shared footer is loaded, the extension publishes one atomic `model-route` group containing the executor, optional fast icon, and optional Angel advisor.
64 +```text
65 +sol:medium 󱐋 → 󰧑 astra:max
66 +```
57 68 Without the shared footer, it clears the footer segment and writes the
58 69 `model-info` UI status fallback.

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

Modified
1 +import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
1 2 import { afterEach, describe, expect, it } from "vitest";
2 3 import { createTestSession, type TestSession } from "../../../test/harness";
3 4 import modelInfoExtension, { __test } from "../index.ts";
5 +import { shortModelLabel } from "../model-label.ts";
5 7 describe("model-info pi-test-harness", () => {
6 8 let t: TestSession | undefined;
16 18 expect(t.session.extensionRunner.extensions).toHaveLength(1);
21 + it("replaces producer fallbacks with the combined route", async () => {
22 + const producer = (pi: ExtensionAPI) => {
23 + pi.on("session_start", (_event, ctx) => {
24 + ctx.ui.setStatus("fast", "fast fallback");
25 + pi.events.emit("model-route:fast", { active: true });
26 + ctx.ui.setStatus("angel", "angel fallback");
27 + pi.events.emit("model-route:angel", {
28 + advisor: { modelId: "gpt-6-astra", thinkingLevel: "max" },
29 + });
30 + });
31 + };
32 + t = await createTestSession({
33 + extensionFactories: [producer, modelInfoExtension],
34 + });
36 + const statuses = t.events.uiCallsFor("setStatus");
37 + const latest = (id: string) =>
38 + statuses.filter((call) => call.args[0] === id).at(-1)?.args[1];
39 + expect(latest("fast")).toBeUndefined();
40 + expect(latest("angel")).toBeUndefined();
41 + expect(latest("model-info")).toMatch(/→ 󰧑 astra:max$/u);
42 + });
19 44 it("formats model and thinking", () => {
20 45 const ctx = {
21 46 cwd: "/tmp",
22 - model: { provider: "test", id: "openai-codex/gpt-5.5" },
47 + model: { provider: "test", id: "openai-codex/gpt-5.6-sol" },
23 48 sessionManager: {
24 49 getBranch: () => [
25 50 { type: "thinking_level_change", thinkingLevel: "high" },
28 53 } as any;
30 - expect(__test.modelInfoLabel(ctx)).toBe("gpt-5.5:high");
55 + expect(__test.modelInfoLabel(ctx)).toBe("sol:high");
56 + });
58 + it("uses footer segments only in TUI mode", () => {
59 + expect(__test.usesFooter(true, "tui")).toBe(true);
60 + expect(__test.usesFooter(true, "rpc")).toBe(false);
61 + expect(__test.usesFooter(false, "tui")).toBe(false);
62 + });
64 + it("combines executor, transport, and advisor into one route", () => {
65 + expect(
66 + __test.statusLabel("sol:medium", true, {
67 + modelId: "gpt-6-astra",
68 + thinkingLevel: "max",
69 + }),
70 + ).toBe("sol:medium 󱐋 → 󰧑 astra:max");
71 + });
73 + it.each([
74 + ["gpt-6-astra", "astra"],
75 + ["gpt-5.5", "gpt-5.5"],
76 + ["claude-fable-5-1", "fable"],
77 + ["claude-opus-5", "opus"],
78 + ["gemini-3.1-pro-preview", "3.1-pro"],
79 + ["grok-4.6", "grok-4.6"],
80 + ["deepseek-v4-flash-vision-exp", "v4-flash"],
81 + ["MiniMax-M3", "M3"],
82 + ["kimi-k2.7-code-highspeed", "k2.7-code"],
83 + ["glm-5.3-highspeed", "glm-5.3"],
84 + ["mistral-medium-2604", "mistral-medium"],
85 + ["new-family-7-alpha", "new-family-7-alpha"],
86 + ])("shortens %s by model-family grammar", (modelId, expected) => {
87 + expect(shortModelLabel(modelId)).toBe(expected);

extensions/model-info/index.ts

Modified
2 - * Model and thinking footer segment.
2 + * Model route footer segments.
4 - * Owns footer segment `model` in the `llm` zone.
4 + * Owns executor model, fast transport, and Angel advisor presentation.
7 7 import type {
9 9 ExtensionContext,
10 10 ThemeColor,
11 11 } from "@earendil-works/pi-coding-agent";
12 +import { shortModelLabel } from "./model-label.ts";
13 -const FOOTER_KEY = Symbol.for("@bugabinga/pi-ext-footer");
14 14 const STATUS_ID = "model-info";
15 -const SEGMENT_ID = "model";
15 +const GROUP_ID = "model-route";
16 +const MODEL_SEGMENT_ID = "model";
17 +const FAST_SEGMENT_ID = "fast";
18 +const ANGEL_SEGMENT_ID = "angel";
19 +const FAST_ICON = "󱐋";
20 +const ANGEL_ICON = "󰧑";
17 -type FooterGlobal = typeof globalThis & {
18 - [FOOTER_KEY]?: { loaded?: boolean; version?: number };
19 -};
22 +type AngelState = { modelId: string; thinkingLevel: string };
21 -function hasFooter(): boolean {
22 - const footer = (globalThis as FooterGlobal)[FOOTER_KEY];
23 - return footer?.loaded === true && (footer.version ?? 0) >= 1;
24 +function usesFooter(
25 + footerReady: boolean,
26 + mode: ExtensionContext["mode"],
27 +): boolean {
28 + return footerReady && mode === "tui";
26 31 function modelLabel(ctx: Pick<ExtensionContext, "model">): string {
27 - const modelId = ctx.model?.id ?? "no-model";
28 - return modelId.split("/").pop() ?? modelId;
32 + return shortModelLabel(ctx.model?.id ?? "no-model");
31 35 function thinkingLevelFromBranch(
52 56 return `${modelLabel(ctx)}:${thinking ?? thinkingLevelFromBranch(ctx)}`;
55 -function publish(
56 - pi: ExtensionAPI,
57 - ctx: ExtensionContext,
58 - thinking?: string,
59 -): void {
60 - const text = modelInfoLabel(ctx, thinking);
62 - if (hasFooter()) {
63 - ctx.ui.setStatus(STATUS_ID, undefined);
64 - pi.events.emit("footer:segment", {
65 - id: SEGMENT_ID,
66 - text,
67 - color: "syntaxKeyword" as ThemeColor,
68 - zone: "llm",
69 - order: 0,
70 - });
71 - return;
72 - }
74 - pi.events.emit("footer:segment", { id: SEGMENT_ID, text: undefined });
75 - ctx.ui.setStatus(STATUS_ID, text);
59 +function clearSegments(pi: ExtensionAPI): void {
60 + for (const id of [MODEL_SEGMENT_ID, FAST_SEGMENT_ID, ANGEL_SEGMENT_ID])
61 + pi.events.emit("footer:segment", { id, text: undefined });
78 -function clear(pi: ExtensionAPI, ctx?: ExtensionContext): void {
79 - pi.events.emit("footer:segment", { id: SEGMENT_ID, text: undefined });
80 - if (ctx?.hasUI) ctx.ui.setStatus(STATUS_ID, undefined);
64 +function statusLabel(
65 + model: string,
66 + fast: boolean,
67 + angel: AngelState | undefined,
68 +): string {
69 + const parts = [model];
70 + if (fast) parts.push(FAST_ICON);
71 + if (angel)
72 + parts.push(
73 + `→ ${ANGEL_ICON} ${shortModelLabel(angel.modelId)}:${angel.thinkingLevel}`,
74 + );
75 + return parts.join(" ");
83 78 export default function modelInfoExtension(pi: ExtensionAPI): void {
84 - function refresh(ctx: ExtensionContext, thinking?: string): void {
85 - if (!ctx.hasUI) return;
86 - publish(pi, ctx, thinking ?? ctx.thinkingLevel);
79 + let currentCtx: ExtensionContext | undefined;
80 + let footerReady = false;
81 + let fast = false;
82 + let angel: AngelState | undefined;
84 + function publish(ctx: ExtensionContext, thinking?: string): void {
85 + const model = modelInfoLabel(ctx, thinking);
86 + ctx.ui.setStatus(FAST_SEGMENT_ID, undefined);
87 + ctx.ui.setStatus(ANGEL_SEGMENT_ID, undefined);
88 + if (!usesFooter(footerReady, ctx.mode)) {
89 + clearSegments(pi);
90 + ctx.ui.setStatus(STATUS_ID, statusLabel(model, fast, angel));
91 + return;
92 + }
94 + ctx.ui.setStatus(STATUS_ID, undefined);
95 + pi.events.emit("footer:segment", {
96 + id: MODEL_SEGMENT_ID,
97 + text: model,
98 + color: "syntaxKeyword" as ThemeColor,
99 + zone: "llm",
100 + group: GROUP_ID,
101 + order: 0,
102 + });
103 + pi.events.emit(
104 + "footer:segment",
105 + fast
106 + ? {
107 + id: FAST_SEGMENT_ID,
108 + text: "",
109 + icon: FAST_ICON,
110 + color: "warning" as ThemeColor,
111 + zone: "llm",
112 + group: GROUP_ID,
113 + order: 0.5,
115 + : { id: FAST_SEGMENT_ID, text: undefined },
116 + );
117 + pi.events.emit(
118 + "footer:segment",
119 + angel
120 + ? {
121 + id: ANGEL_SEGMENT_ID,
122 + text: `${shortModelLabel(angel.modelId)}:${angel.thinkingLevel}`,
123 + icon: ANGEL_ICON,
124 + color: "accent" as ThemeColor,
125 + zone: "llm",
126 + group: GROUP_ID,
127 + separator: "→",
128 + order: 0.75,
130 + : { id: ANGEL_SEGMENT_ID, text: undefined },
131 + );
134 + function refresh(ctx: ExtensionContext, thinking?: string): void {
135 + currentCtx = ctx;
136 + if (!ctx.hasUI) return;
137 + publish(ctx, thinking ?? ctx.thinkingLevel);
140 + pi.events.on("footer:ready", (data: unknown) => {
141 + if ((data as { version?: unknown })?.version !== 1) return;
142 + footerReady = true;
143 + if (currentCtx) refresh(currentCtx);
144 + });
145 + pi.events.on("model-route:fast", (data: unknown) => {
146 + if (typeof (data as { active?: unknown })?.active !== "boolean") return;
147 + fast = (data as { active: boolean }).active;
148 + if (currentCtx) refresh(currentCtx);
149 + });
150 + pi.events.on("model-route:angel", (data: unknown) => {
151 + const candidate = (data as { advisor?: unknown })?.advisor;
152 + if (candidate === undefined) angel = undefined;
153 + else if (
154 + typeof (candidate as AngelState)?.modelId === "string" &&
155 + typeof (candidate as AngelState)?.thinkingLevel === "string"
157 + angel = candidate as AngelState;
158 + else return;
159 + if (currentCtx) refresh(currentCtx);
160 + });
162 + pi.events.emit("footer:probe", undefined);
89 164 pi.on("session_start", (_event, ctx) => refresh(ctx));
90 165 pi.on("model_select", (_event, ctx) => refresh(ctx));
91 166 pi.on("thinking_level_select", (event, ctx) => refresh(ctx, event.level));
92 167 pi.on("session_compact", (_event, ctx) => refresh(ctx));
93 - pi.on("session_shutdown", (_event, ctx) => clear(pi, ctx));
168 + pi.on("session_shutdown", (_event, ctx) => {
169 + clearSegments(pi);
170 + if (ctx.hasUI) ctx.ui.setStatus(STATUS_ID, undefined);
171 + currentCtx = undefined;
172 + footerReady = false;
173 + fast = false;
174 + angel = undefined;
175 + });
96 178 export const __test = {
97 179 modelInfoLabel,
98 180 modelLabel,
181 + statusLabel,
99 182 thinkingLevelFromBranch,
183 + usesFooter,

extensions/model-info/model-label.ts

Added
new file mode 100644
1 +function basename(modelId: string): string {
2 + return modelId.split("/").at(-1) ?? modelId;
3 +}
5 +function withoutTrailingQualifiers(
6 + value: string,
7 + qualifiers: ReadonlySet<string>,
8 +): string {
9 + const parts = value.split("-");
10 + while (parts.length > 0 && qualifiers.has(parts.at(-1)?.toLowerCase() ?? ""))
11 + parts.pop();
12 + return parts.join("-");
15 +const GEMINI_QUALIFIERS = new Set([
16 + "customtools",
17 + "image",
18 + "latest",
19 + "live",
20 + "preview",
21 +]);
22 +const HIGHSPEED_QUALIFIER = new Set(["highspeed"]);
23 +const KIMI_QUALIFIERS = new Set(["highspeed", "preview", "turbo"]);
24 +const RELEASE_QUALIFIERS = new Set(["latest"]);
26 +/** Compact a model ID according to its family's stable naming grammar. */
27 +export function shortModelLabel(modelId: string): string {
28 + const id = basename(modelId);
29 + let match: RegExpExecArray | null;
31 + match = /^gpt-(\d+(?:\.\d+)*)(?:-(.+))?$/iu.exec(id);
32 + if (match) return match[2] ?? id;
34 + match = /^claude-([^-]+)-\d/iu.exec(id);
35 + if (match) return match[1] ?? id;
37 + match = /^gemini-(\d+(?:\.\d+)?)-(.+)$/iu.exec(id);
38 + if (match) {
39 + const variant = withoutTrailingQualifiers(
40 + match[2] ?? "",
41 + GEMINI_QUALIFIERS,
42 + );
43 + return variant ? `${match[1]}-${variant}` : id;
44 + }
45 + match = /^gemini-(.+)$/iu.exec(id);
46 + if (match)
47 + return withoutTrailingQualifiers(match[1] ?? id, GEMINI_QUALIFIERS);
49 + if (/^grok-\d/iu.test(id)) return id;
51 + match = /^deepseek-(v?\d+(?:\.\d+)?)-(flash|pro)(?:-|$)/iu.exec(id);
52 + if (match) return `${match[1]}-${match[2]}`;
54 + match = /^minimax-(m\d+(?:\.\d+)?)(?:-(.+))?$/iu.exec(id);
55 + if (match) return match[1] ?? id;
57 + match = /^kimi-(k\d+(?:\.\d+)?)(?:-(.+))?$/iu.exec(id);
58 + if (match) {
59 + const variant = withoutTrailingQualifiers(match[2] ?? "", KIMI_QUALIFIERS);
60 + return variant ? `${match[1]}-${variant}` : (match[1] ?? id);
61 + }
62 + if (/^kimi-for-coding(?:-highspeed)?$/iu.test(id)) return "kimi-coding";
64 + match = /^glm-(\d+(?:\.\d+)?)(?:-(.+))?$/iu.exec(id);
65 + if (match) {
66 + const variant = withoutTrailingQualifiers(
67 + match[2] ?? "",
68 + HIGHSPEED_QUALIFIER,
69 + );
70 + return `glm-${match[1]}${variant ? `-${variant}` : ""}`;
71 + }
73 + if (
74 + /^(?:codestral|devstral|magistral|ministral|mistral|pixtral|voxtral)-/iu.test(
75 + id,
76 + )
77 + ) {
78 + const withoutRelease = id.replace(/-(?:\d{4}|\d{8})$/u, "");
79 + return withoutTrailingQualifiers(withoutRelease, RELEASE_QUALIFIERS);
80 + }
82 + return id;

extensions/os-notifier/CHANGELOG.md

Modified
7 7 - Notify only for direct interactive TUI runs completed while unfocused.
8 8 - Preserve rich metadata with natural urgency and bounded sanitized text.
9 9 - Remove the unused extension notification event bridge.
10 +- Publish pane-scoped Pi identity through OSC 1337 during TUI sessions.
11 12 ## 0.0.3

extensions/os-notifier/README.md

Modified
19 19 Hooks:
21 -- `session_start` attaches terminal focus tracking in TUI mode.
21 +- `session_start` attaches terminal focus tracking and publishes pane identity in TUI mode.
22 22 - `input` records candidate direct interactive input origin.
23 23 - `before_agent_start` confirms the accepted input that starts a lifecycle.
24 24 - `agent_start` starts duration measurement for the active lifecycle.
25 25 - `agent_end` records the latest low-level outcome.
26 26 - `agent_settled` sends the final eligible notification while unfocused.
27 -- `session_shutdown` clears in-memory state and focus tracking.
27 +- `session_shutdown` clears in-memory state, pane identity, and focus tracking.
29 29 ## Eligibility
62 62 Dynamic text is sanitized and passed without shell interpolation.
64 64 Focus tracking uses DECSET `?1004`, shared through `globalThis` and reference-counted.
65 +TUI sessions publish `agent=pi` as an OSC 1337 pane user variable and clear it on shutdown.

extensions/os-notifier/__tests__/harness.test.ts

Modified
6 6 agentDoneNotification,
7 7 deliverNative,
8 8 nativeCommand,
9 + oscAgentIdentity,
9 10 oscBackend,
10 11 TurnEligibility,
11 12 } from "../index";
63 64 expect(oscBackend({})).toBe("osc777");
67 + it("encodes pane-scoped agent identity as an OSC user variable", () => {
68 + expect(oscAgentIdentity("pi")).toBe(
69 + "\u001b]1337;SetUserVar=agent=cGk=\u0007",
70 + );
71 + expect(oscAgentIdentity("")).toBe("\u001b]1337;SetUserVar=agent=\u0007");
72 + });
66 74 it("falls back exactly once only when native delivery fails", async () => {
67 75 const writes: string[] = [];
68 76 await deliverNative(

extensions/os-notifier/index.ts

Modified
264 264 return env.KITTY_WINDOW_ID ? "osc99" : "osc777";
267 +export function oscAgentIdentity(value: string): string {
268 + return `\x1b]1337;SetUserVar=agent=${Buffer.from(value).toString("base64")}\x07`;
271 +function writeAgentIdentity(value: string): void {
272 + try {
273 + process.stdout.write(oscAgentIdentity(value));
274 + } catch {
275 + // Terminal metadata is best-effort.
267 279 function severityPrefix(severity: NotificationSeverity): string {
268 280 return severity === "warning" ? "⚠️ " : severity === "error" ? "❌ " : "";
382 394 pi.on("session_start", async (_event, ctx) => {
383 395 if (ctx.mode === "tui") {
384 396 focus.attach();
397 + writeAgentIdentity("pi");
385 398 focusAttached = true;
453 466 acceptedPrompt = undefined;
454 467 lastAgentEnd = undefined;
455 468 if (focusAttached) {
469 + writeAgentIdentity("");
456 470 focus.detach();
457 471 focusAttached = false;

extensions/ultra/README.md

Modified
174 174 When `run_workflow` is active, Ultra injects one effective rubric generated from the merged tiers into the orchestrator system prompt.
175 175 That applies to ordinary tool use and `/ultra exec`.
176 176 The rubric, not a hardcoded role list in an authored workflow, decides tier selection.
177 +The orchestrator chooses the least-compute tier likely to satisfy each step's acceptance criteria and escalates only for a concrete remaining reasoning bottleneck.
178 +Broad scope, long prompts, routine review or debugging, and general importance do not justify more compute; missing context is supplied or reported blocked instead.
177 179 Tier instructions guide the orchestrator only and are never passed to child agents as model-specific instructions.
179 181 A step's `model` may name any configured tier or give a concrete `provider/model` reference.

extensions/ultra/__tests__/prompt.test.ts

Modified
298 298 expect(prompt).toContain(
299 299 "effective tier rubric injected into this orchestrator",
301 + for (const content of [prompt, reference, readme]) {
302 + expect(content).toContain("least-compute tier");
303 + expect(content).toContain("concrete remaining reasoning bottleneck");
304 + expect(content).toContain(
305 + "Broad scope, long prompts, routine review or debugging",
306 + );
307 + expect(content).toMatch(/missing context|Supply missing context/u);
308 + expect(content).toMatch(/report(?:ed)? blocked/u);
301 310 expect(prompt).toContain("Normally omit `thinkingLevel`");
302 311 expect(prompt).toContain(
303 312 "Saved workflows retain their explicit model selections",

extensions/ultra/__tests__/settings.test.ts

Modified
225 225 expect(prompt).toContain(
226 226 "Tier: model; default thinkingLevel; orchestrator-only selection guidance.",
228 + expect(prompt).toContain(
229 + "Choose the least-compute tier likely to satisfy each step's acceptance criteria.",
230 + );
231 + expect(prompt).toContain(
232 + "Escalate only for a concrete remaining reasoning bottleneck",
233 + );
234 + expect(prompt).toContain(
235 + "Supply missing context or report blocked instead of compensating with a larger tier.",
236 + );
228 237 for (const [name, tier] of Object.entries(tiers)) {
229 238 expect(prompt).toContain(
230 239 `- ${name}: ${tier.model ?? "session model"}; ${tier.thinkingLevel}; ${tier.instructions}`,
233 242 expect(prompt.match(/default thinkingLevel/g)).toHaveLength(1);
234 - expect(modelTierPrompt(DEFAULT_MODEL_TIERS).length).toBeLessThan(650);
243 + expect(modelTierPrompt(DEFAULT_MODEL_TIERS).length).toBeLessThan(1_250);
244 + });
246 + it("inherits fallback instructions when settings override only routing", () => {
247 + const overrides = Object.fromEntries(
248 + Object.entries(DEFAULT_MODEL_TIERS).map(([name, tier]) => [
249 + name,
251 + model: `custom/${name}`,
252 + thinkingLevel: tier.thinkingLevel,
253 + },
254 + ]),
255 + );
256 + const result = loadUltraSettings({
257 + global: { ultra: { modelTiers: overrides } },
258 + });
260 + for (const [name, fallback] of Object.entries(DEFAULT_MODEL_TIERS)) {
261 + expect(result.modelTiers[name]).toEqual({
262 + model: `custom/${name}`,
263 + thinkingLevel: fallback.thinkingLevel,
264 + instructions: fallback.instructions,
265 + });
237 269 it("allows null to restore session-model routing", () => {

extensions/ultra/prompts/references/spec-format.md

Modified
114 114 When `run_workflow` is active, Ultra injects one effective tier rubric generated from merged `ultra.modelTiers` settings into the orchestrator system prompt.
115 115 Use that rubric to choose each step's explicit tier selection; do not encode a hardcoded tier-to-role list here or in child prompts.
116 +Choose the least-compute tier likely to satisfy each step's acceptance criteria.
117 +Escalate only for a concrete remaining reasoning bottleneck that a lower tier cannot adequately handle.
118 +Broad scope, long prompts, routine review or debugging, and general importance do not justify more compute.
119 +Supply missing context or report blocked instead of compensating with a larger tier.
116 120 Saved workflows retain their selected tier names.
118 122 Normally omit `thinkingLevel` so settings decide the tier default.

extensions/ultra/prompts/ultra-authoring/SKILL.md

Modified
120 120 6. **Assign compute deliberately.** For every step:
121 121 - Use the one effective tier rubric injected into this orchestrator's system prompt.
122 122 It reflects the merged `ultra.modelTiers` settings, so do not copy a hardcoded tier-to-role list into a workflow.
123 + - Choose the least-compute tier likely to satisfy each step's acceptance criteria.
124 + Escalate only for a concrete remaining reasoning bottleneck that a lower tier cannot adequately handle.
125 + Broad scope, long prompts, routine review or debugging, and general importance do not justify more compute.
126 + Supply missing context or report blocked instead of compensating with a larger tier.
123 127 - Save an explicit `model` tier selection when the step needs a tier; a concrete `provider/model` reference is also valid.
124 128 An unknown bare tier name fails.
125 129 Omit `model` when the session model is appropriate.

extensions/ultra/settings.ts

Modified
31 31 tiny: {
32 32 model: null,
33 33 thinkingLevel: "low",
34 - instructions: "Labels, extraction, and formatting from supplied context.",
34 + instructions:
35 + "Labels, extraction, and formatting from supplied context. No open-ended investigation.",
36 37 small: {
37 38 model: null,
38 39 thinkingLevel: "low",
39 - instructions: "Bounded scouting and straightforward edits.",
40 + instructions:
41 + "Bounded scouting and straightforward edits with clear success criteria.",
41 43 medium: {
42 44 model: null,
43 45 thinkingLevel: "medium",
44 - instructions: "Routine implementation and testing.",
46 + instructions:
47 + "Routine implementation and testing with prepared context and an agreed specification.",
46 49 large: {
47 50 model: null,
48 51 thinkingLevel: "high",
49 - instructions: "Architecture, ambiguous debugging, critique, and synthesis.",
52 + instructions:
53 + "Architecture, ambiguous debugging, critique, and synthesis requiring substantial judgment. Delegate independent work when it materially helps; keep verification scoped to changed behavior and required gates.",
51 55 huge: {
52 56 model: null,
53 57 thinkingLevel: "max",
54 58 instructions:
55 - "Use only when exceptionally difficult work or costly mistakes justify maximum reasoning.",
59 + "Reserved for exceptional reasoning bottlenecks that large cannot adequately handle; broad scope, routine review or debugging, and general importance are insufficient.",
149 153 return [
150 154 "# Ultra model tier policy",
151 155 "Tier: model; default thinkingLevel; orchestrator-only selection guidance.",
156 + "Choose the least-compute tier likely to satisfy each step's acceptance criteria.",
157 + "Escalate only for a concrete remaining reasoning bottleneck; broad scope, long prompts, routine review or debugging, and general importance do not justify more compute.",
158 + "Supply missing context or report blocked instead of compensating with a larger tier.",
152 159 ...Object.entries(tiers).map(
153 160 ([name, tier]) =>
154 161 `- ${name}: ${tier.model ?? "session model"}; ${tier.thinkingLevel}; ${tier.instructions}`,