pi-ext
bugabingas pi extensions
owned by bugabinga
refactor(lint): tighten biome rules and fix violations
f2fe77d27c3c93ffdeafd5e019465433e95df1f0
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
Browse filesCompare with HEAD
- Enable noUnusedImports, noUnusedVariables (error)
- Enable noUnusedFunctionParameters (warn)
- Enable noVoidTypeReturn, useParseIntRadix, noUselessTernary (error)
- Enable noAssignInExpressions, noGlobalIsNan (error)
- Enable useNodejsImportProtocol (error), auto-fix 15 imports
- Enable noNonNullAssertion (warn) — 49 warnings surfaced for review
- Auto-fix import sorting and formatting across 102 files
- Manual fixes: split void returns, remove unused type alias,
refactor ??= assignments, fix useless ternary
Changed files (119)
33 33 "noBannedTypes":
"off",
34 34 "noImportantStyles":
"off",
35 35 "noUselessStringRaw":
"off",
36 - "noUselessTernary":
"off",
36 + "noUselessTernary":
"error",
37 37 "useLiteralKeys":
"off" 40 - "noUnusedFunctionParameters":
"off",
41 - "noUnusedImports":
"off",
42 - "noUnusedVariables":
"off",
43 - "noVoidTypeReturn":
"off",
44 - "useParseIntRadix":
"off" 40 + "noUnusedFunctionParameters":
"warn",
41 + "noUnusedImports":
"error",
42 + "noUnusedVariables":
"error",
43 + "noVoidTypeReturn":
"error",
44 + "useParseIntRadix":
"error" 47 47 "noAccumulatingSpread":
"off" 50 50 "noDescendingSpecificity":
"off",
51 - "noNonNullAssertion":
"off",
52 - "useNodejsImportProtocol":
"off",
51 + "noNonNullAssertion":
"warn",
52 + "useNodejsImportProtocol":
"error",
53 53 "useTemplate":
"off" 56 - "noAssignInExpressions":
"off",
56 + "noAssignInExpressions":
"error",
57 57 "noControlCharactersInRegex":
"off",
58 58 "noExplicitAny":
"off",
59 - "noGlobalIsNan":
"off",
59 + "noGlobalIsNan":
"error",
60 60 "noImplicitAnyLet":
"off",
61 61 "noTemplateCurlyInString":
"off",
62 62 "useIterableCallbackReturn":
"off" extensions/AGENTS.md
Modified 4 4 #
Pi Extensions Workspace 8 8 1. `extensions/{name}/package.json` — template below
9 9 2. `extensions/{name}/index.ts`
24 24 Add only deps actually imported by the extension.
25 25 Prefer `peerDependencies` for Pi packages (`@earendil-works/*`).
26 -Run `bun install` after any structural change.
26 +Run `npm install` after any structural change.
28 28 ##
Mandatory test harness 31 31 - Every extension must include a pi-test-harness test that loads `index.ts`
32 32 through the real Pi extension runtime.
33 33 - Add `test:harness`:
34 - `bun test ./__tests__/harness.test.ts`.
34 + `npx vitest run ./__tests__/harness.test.ts`.
35 35 - If no `test` script exists, add `test`:
36 - `bun test ./__tests__/*.test.ts`.
36 + `npx vitest run ./__tests__/*.test.ts`.
extensions/angel/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"angel pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/angel/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-angel",
5 - "peerDependencies": {
6 - "@earendil-works/pi-ai":
"*",
7 - "@earendil-works/pi-coding-agent":
"*",
8 - "@earendil-works/pi-tui":
"*",
12 - "description":
"Structured advisor and command guardrail for Pi.",
17 - "devDependencies": {
18 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-angel",
5 + "peerDependencies": {
6 + "@earendil-works/pi-ai":
"*",
7 + "@earendil-works/pi-coding-agent":
"*",
8 + "@earendil-works/pi-tui":
"*",
12 + "description":
"Structured advisor and command guardrail for Pi.",
17 + "devDependencies": {
18 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/builtin-tools/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"builtin-tools pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/builtin-tools/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-builtin-tools",
5 - "peerDependencies": {
6 - "@earendil-works/pi-coding-agent":
"*" 9 - "description":
"Toggle Pi builtin file-search tools.",
14 - "devDependencies": {
15 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-builtin-tools",
5 + "peerDependencies": {
6 + "@earendil-works/pi-coding-agent":
"*" 9 + "description":
"Toggle Pi builtin file-search tools.",
14 + "devDependencies": {
15 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/context-size/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"context-size pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/context-size/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-context-size",
5 - "peerDependencies": {
6 - "@earendil-works/pi-coding-agent":
"*" 9 - "description":
"Context-window usage telemetry for Pi.",
14 - "devDependencies": {
15 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-context-size",
5 + "peerDependencies": {
6 + "@earendil-works/pi-coding-agent":
"*" 9 + "description":
"Context-window usage telemetry for Pi.",
14 + "devDependencies": {
15 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/cost/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
7 7 import { __test }
from "../index.ts";
9 9 describe(
"cost pi-test-harness", ()
=> {
extensions/cost/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-cost",
5 - "peerDependencies": {
6 - "@earendil-works/pi-coding-agent":
"*" 9 - "description":
"Token and spend telemetry for Pi.",
14 - "devDependencies": {
15 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-cost",
5 + "peerDependencies": {
6 + "@earendil-works/pi-coding-agent":
"*" 9 + "description":
"Token and spend telemetry for Pi.",
14 + "devDependencies": {
15 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/ctx/__tests__/harness.test.ts
Modified 1 -import { afterEach, beforeEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, beforeEach, describe, expect, it }
from "vitest";
8 8 let t
: TestSession | undefined;
22 22 input
?: Record
<string, unknown
>;
25 - return await t
!.session.extensionRunner.
emitToolResult({
25 + return await t?.session.extensionRunner.
emitToolResult({
26 26 type:
"tool_result",
28 28 input: params.
input ?? { path:
"big.txt" },
extensions/ctx/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-ctx",
7 - "@marcfargas/pi-test-harness":
"^0.6.1" 10 - "description":
"Compacts oversized Pi read results before they hit context.",
2 + "name":
"@bugabinga/pi-ext-ctx",
7 + "@marcfargas/pi-test-harness":
"^0.6.1" 10 + "description":
"Compacts oversized Pi read results before they hit context.",
extensions/cwd/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"cwd pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/cwd/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-cwd",
5 - "peerDependencies": {
6 - "@earendil-works/pi-coding-agent":
"*" 9 - "description":
"Switch Pi cwd without leaving the session.",
14 - "devDependencies": {
15 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-cwd",
5 + "peerDependencies": {
6 + "@earendil-works/pi-coding-agent":
"*" 9 + "description":
"Switch Pi cwd without leaving the session.",
14 + "devDependencies": {
15 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/devil/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
5 4 }
from "@marcfargas/pi-test-harness";
5 +import { afterEach, describe, expect, it }
from "vitest";
7 7 let t
: TestSession | undefined;
extensions/devil/__tests__/helpers.test.ts
Modified 11 11 } from
"../helpers.ts";
12 -import type { DebateOutput }
from "../types.ts";
126 125 controller.
abort();
127 126 const result
= checkAborted(controller.signal, [
"r1"],
2);
128 127 expect(result).not.
toBeNull();
129 - expect(result
!.aborted).
toBe(
true);
130 - expect(result
!.blockingRaised).
toBe(
2);
128 + expect(result?.aborted).
toBe(
true);
129 + expect(result?.blockingRaised).
toBe(
2);
extensions/devil/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-devil",
6 - "peerDependencies": {
7 - "@earendil-works/pi-ai":
"*",
8 - "@earendil-works/pi-agent-core":
"*",
9 - "@earendil-works/pi-coding-agent":
"*",
10 - "@earendil-works/pi-tui":
"*" 12 - "devDependencies": {
13 - "@marcfargas/pi-test-harness":
"^0.6.1" 16 - "description":
"Devil's advocate debate command for Pi.",
2 + "name":
"@bugabinga/pi-ext-devil",
6 + "peerDependencies": {
7 + "@earendil-works/pi-ai":
"*",
8 + "@earendil-works/pi-agent-core":
"*",
9 + "@earendil-works/pi-coding-agent":
"*",
10 + "@earendil-works/pi-tui":
"*" 12 + "devDependencies": {
13 + "@marcfargas/pi-test-harness":
"^0.6.1" 16 + "description":
"Devil's advocate debate command for Pi.",
extensions/fast/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"fast pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/fast/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-fast",
5 - "peerDependencies": {
6 - "@earendil-works/pi-ai":
"*",
7 - "@earendil-works/pi-coding-agent":
"*" 10 - "description":
"Priority service tier for OpenAI Codex in Pi.",
15 - "devDependencies": {
16 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-fast",
5 + "peerDependencies": {
6 + "@earendil-works/pi-ai":
"*",
7 + "@earendil-works/pi-coding-agent":
"*" 10 + "description":
"Priority service tier for OpenAI Codex in Pi.",
15 + "devDependencies": {
16 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/footer/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"footer pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/footer/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-footer",
5 - "peerDependencies": {
6 - "@earendil-works/pi-coding-agent":
"*",
7 - "@earendil-works/pi-tui":
"*" 10 - "description":
"Shared stable footer renderer for Pi.",
15 - "devDependencies": {
16 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-footer",
5 + "peerDependencies": {
6 + "@earendil-works/pi-coding-agent":
"*",
7 + "@earendil-works/pi-tui":
"*" 10 + "description":
"Shared stable footer renderer for Pi.",
15 + "devDependencies": {
16 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/git-safe/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"git-safe pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/git-safe/clone.ts
Modified 8 8 import { existsSync, realpathSync }
from "node:fs";
16 -}
from "node:fs/promises";
9 +import { mkdir, readFile, rm, writeFile }
from "node:fs/promises";
17 10 import { homedir, tmpdir }
from "node:os";
18 -import { basename, dirname, join, resolve }
from "node:path";
11 +import { dirname, join, resolve }
from "node:path";
247 240 const sizeMatch
= line.
match(
/\s+(\d+)\t/);
249 - totalSize
+= parseInt(sizeMatch[
1]);
242 + totalSize
+= parseInt(sizeMatch[
1],
10);
256 249 "Could not compute pre-checkout size (empty repo or ls-tree unavailable).",
extensions/git-safe/index.ts
Modified 20 20 import { realpath }
from "node:fs/promises";
21 21 import { resolve }
from "node:path";
22 22 import type { ExtensionAPI }
from "@earendil-works/pi-coding-agent";
23 -import { isToolCallEventType }
from "@earendil-works/pi-coding-agent";
24 23 import { Text }
from "@earendil-works/pi-tui";
25 24 import { Type }
from "typebox";
220 219 return new Text(text,
0,
0);
223 - async
execute(_toolCallId, params, signal, onUpdate, ctx) {
222 + async
execute(_toolCallId, params, _signal, onUpdate, ctx) {
224 223 ctx?.ui?.
setWorkingMessage(
`Cloning ${params.url} safely...`);
extensions/git-safe/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-git-safe",
5 - "peerDependencies": {
6 - "@earendil-works/pi-coding-agent":
"*",
7 - "@earendil-works/pi-tui":
"*",
11 - "description":
"Hardened git clone tool for Pi.",
16 - "devDependencies": {
17 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-git-safe",
5 + "peerDependencies": {
6 + "@earendil-works/pi-coding-agent":
"*",
7 + "@earendil-works/pi-tui":
"*",
11 + "description":
"Hardened git clone tool for Pi.",
16 + "devDependencies": {
17 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/git-safe/spawn.ts
Modified 42 42 proc.stderr.
on(
"data", (d
: Buffer)
=> (stderr
+= d));
43 43 proc.
on(
"close", (code)
=> {
44 44 clearTimeout(timer);
45 - resolve({ stdout, stderr, code, killed: timer.ref
? false : false });
45 + resolve({ stdout, stderr, code, killed:
false });
47 47 proc.
on(
"error", (err)
=> {
48 48 clearTimeout(timer);
extensions/goal/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
3 2 createAssistantMessageEventStream,
10 9 } from
"@marcfargas/pi-test-harness";
10 +import { afterEach, describe, expect, it }
from "vitest";
11 11 import { __goalTest, GOAL_PROBE_MESSAGE }
from "../index.ts";
13 13 let t
: TestSession | undefined;
105 105 function customEvents(kind
: string)
: Array<
Record<
string,
unknown>> {
107 - t
!.session.sessionManager.
getEntries()
as Array<{
107 + t?.session.sessionManager.
getEntries()
as Array<{
109 109 customType
?: string;
110 110 data
?: Record<
string,
unknown>;
117 117 function customMessages(kind
: string)
: Array<
Record<
string,
unknown>> {
119 - t
!.session.sessionManager.
getEntries()
as Array<{
119 + t?.session.sessionManager.
getEntries()
as Array<{
121 121 customType
?: string;
122 122 content
?: string;
137 137 function uiArgs(method
: string)
: unknown[][] {
138 - return t
!.events.ui
138 + return t?.events.ui
139 139 .
filter((call)
=> call.
method === method)
140 140 .
map((call)
=> call.args);
147 147 function latestGoal() {
148 148 return __goalTest.
latestGoalState({
149 - sessionManager: t
!.session.sessionManager,
149 + sessionManager: t?.session.sessionManager,
214 214 await t.session.
prompt(
"initial work");
217 - t
!.events.
all.
filter((event)
=> event.
type === "agent_end").
length >= 217 + t?.events.
all.
filter((event)
=> event.
type === "agent_end").
length >= 218 218 expectedAgentEnds,
220 220 await new Promise((resolve)
=> setTimeout(resolve,
25));
697 697 for (
const mode
of [
"direct",
"microtask"]
as const) {
698 698 it(
`${mode} dispatch is still busy inside agent_end`,
async ()
=> {
699 699 await runProbe(mode,
1);
700 - const agentStarts
= t
!.events.
all.
filter(
700 + const agentStarts
= t?.events.
all.
filter(
701 701 (event)
=> event.
type === "agent_start",
703 - const agentEnds
= t
!.events.
all.
filter(
703 + const agentEnds
= t?.events.
all.
filter(
704 704 (event)
=> event.
type === "agent_end",
706 706 const probeEvents
= customEvents(
"goal-probe").
map(
717 717 it(
"setTimeout(0) schedules exactly one continuation after idle",
async ()
=> {
718 718 await runProbe(
"timeout",
2);
720 - const agentStarts
= t
!.events.
all.
filter(
720 + const agentStarts
= t?.events.
all.
filter(
721 721 (event)
=> event.
type === "agent_start",
723 - const agentEnds
= t
!.events.
all.
filter(
723 + const agentEnds
= t?.events.
all.
filter(
724 724 (event)
=> event.
type === "agent_end",
726 - const assistantMessages
= t
!.events.messages
726 + const assistantMessages
= t?.events.messages
727 727 .
filter((message)
=> message.role
=== "assistant")
728 728 .
map((message)
=> 729 729 Array.
isArray(message.
content)
746 746 expect(probeEvents.
at(
-1)).
toBe(
"done");
748 - const userMessages
= t
!.session.sessionManager
748 + const userMessages
= t?.session.sessionManager
extensions/goal/__tests__/unit.test.ts
Modified 165 165 ).
toBe(
"━━━━──────");
167 167 __goalTest.
goalWidgetLines(
168 - goal({ lastReason:
"needs tests", createdAt:
Date.
now(), timeUsedSeconds:
0 })
as never,
169 + lastReason:
"needs tests",
170 + createdAt:
Date.
now(),
171 + timeUsedSeconds:
0,
446 450 expect(__goalTest.
shortText(
" a b ",
10)).
toBe(
"a b");
448 452 it(
"defaults max to 72", ()
=> {
449 - expect(__goalTest.
shortText(
"x".
repeat(
80)).
length).
toBeLessThanOrEqual(
72);
453 + expect(__goalTest.
shortText(
"x".
repeat(
80)).
length).
toBeLessThanOrEqual(
459 465 expect(__goalTest.
sanitizeGoalText(
" a b ")).
toBe(
"a b");
461 467 it(
"truncates to max", ()
=> {
462 - expect(__goalTest.
sanitizeGoalText(
"x".
repeat(
200),
160)).
toHaveLength(
160);
463 - expect(__goalTest.
sanitizeGoalText(
"x".
repeat(
200),
160).
endsWith(
"…")).
toBe(
true);
468 + expect(__goalTest.
sanitizeGoalText(
"x".
repeat(
200),
160)).
toHaveLength(
472 + __goalTest.
sanitizeGoalText(
"x".
repeat(
200),
160).
endsWith(
"…"),
465 475 it(
"defaults max to 160", ()
=> {
466 476 expect(__goalTest.
sanitizeGoalText(
"x".
repeat(
200))).
toHaveLength(
160);
507 517 describe(
"elapsedSeconds", ()
=> {
508 518 it(
"returns timeUsedSeconds from state", ()
=> {
509 - expect(__goalTest.
elapsedSeconds(
goal({ timeUsedSeconds:
42 })
as never)).
toBe(
42);
520 + __goalTest.
elapsedSeconds(
goal({ timeUsedSeconds:
42 })
as never),
511 523 it(
"defaults to 0 when undefined", ()
=> {
512 524 expect(__goalTest.
elapsedSeconds(
goal()
as never)).
toBe(
0);
526 538 describe(
"budgetText", ()
=> {
527 539 it(
"shows elapsed time with no budgets", ()
=> {
528 - const state
= goal({ createdAt:
Date.
now(), timeUsedSeconds:
0 })
as never;
540 + const state
= goal({
541 + createdAt:
Date.
now(),
542 + timeUsedSeconds:
0,
529 544 expect(__goalTest.
budgetText(state)).
toMatch(
/\d+s$/);
531 546 it(
"shows token budget when set", ()
=> {
571 586 describe(
"goalPhaseText", ()
=> {
572 587 it(
"judging shows turn+1", ()
=> {
573 - expect(__goalTest.
goalPhaseText(
goal({ turnsUsed:
3 })
as never,
"judging")).
toBe(
589 + __goalTest.
goalPhaseText(
goal({ turnsUsed:
3 })
as never,
"judging"),
590 + ).
toBe(
"judging 4/5");
577 592 it(
"queued shows continuation label", ()
=> {
578 - expect(__goalTest.
goalPhaseText(
goal({ turnsUsed:
1 })
as never,
"queued")).
toBe(
579 - "queued continuation 2/5",
594 + __goalTest.
goalPhaseText(
goal({ turnsUsed:
1 })
as never,
"queued"),
595 + ).
toBe(
"queued continuation 2/5");
582 597 it(
"normal returns status only (no turn count)", ()
=> {
583 - expect(__goalTest.
goalPhaseText(
goal()
as never,
"normal")).
toBe(
"active");
598 + expect(__goalTest.
goalPhaseText(
goal()
as never,
"normal")).
toBe(
587 604 describe(
"footerPhaseText", ()
=> {
588 605 it(
"judging includes goal prefix", ()
=> {
589 - expect(__goalTest.
footerPhaseText(
goal({ turnsUsed:
2 })
as never,
"judging")).
toBe(
590 - "goal judging 3/5",
607 + __goalTest.
footerPhaseText(
goal({ turnsUsed:
2 })
as never,
"judging"),
608 + ).
toBe(
"goal judging 3/5");
593 610 it(
"queued includes goal prefix", ()
=> {
594 611 expect(__goalTest.
footerPhaseText(
goal()
as never,
"queued")).
toBe(
603 620 it(
"blocked (no turn budget) omits turns", ()
=> {
605 - __goalTest.
footerPhaseText(
goal({ status:
"blocked" })
as never,
"normal"),
622 + __goalTest.
footerPhaseText(
623 + goal({ status:
"blocked" })
as never,
606 626 ).
toBe(
"goal blocked");
610 630 describe(
"judgeStatusText", ()
=> {
611 631 it(
"shows judging with turn+1", ()
=> {
612 - expect(__goalTest.
judgeStatusText(
goal()
as never)).
toBe(
"goal judging 3/5 · 2c");
632 + expect(__goalTest.
judgeStatusText(
goal()
as never)).
toBe(
633 + "goal judging 3/5 · 2c",
614 636 it(
"omits criteria count when empty", ()
=> {
616 - __goalTest.
judgeStatusText(
goal({ criteria: [] })
as never),
617 - ).
toBe(
"goal judging 3/5");
637 + expect(__goalTest.
judgeStatusText(
goal({ criteria: [] })
as never)).
toBe(
638 + "goal judging 3/5",
621 643 describe(
"isJudgeParseFailure", ()
=> {
622 644 it(
"detects judge returned messages", ()
=> {
624 - __goalTest.
isJudgeParseFailure({ done:
false, blocked:
false, reason:
"judge returned empty" }),
646 + __goalTest.
isJudgeParseFailure({
649 + reason:
"judge returned empty",
627 653 it(
"detects JSON parse errors", ()
=> {
629 - __goalTest.
isJudgeParseFailure({ done:
false, blocked:
false, reason:
"JSON parse failed: Unexpected token" }),
655 + __goalTest.
isJudgeParseFailure({
658 + reason:
"JSON parse failed: Unexpected token",
632 662 it(
"returns false for normal reasons", ()
=> {
634 - __goalTest.
isJudgeParseFailure({ done:
false, blocked:
false, reason:
"still working" }),
664 + __goalTest.
isJudgeParseFailure({
667 + reason:
"still working",
639 673 describe(
"judgeVerdictLabel", ()
=> {
640 674 it(
"returns done/blocked/continue", ()
=> {
641 - expect(__goalTest.
judgeVerdictLabel({ done:
true, blocked:
false, reason:
"" })).
toBe(
"done");
642 - expect(__goalTest.
judgeVerdictLabel({ done:
false, blocked:
true, reason:
"" })).
toBe(
"blocked");
643 - expect(__goalTest.
judgeVerdictLabel({ done:
false, blocked:
false, reason:
"" })).
toBe(
"continue");
676 + __goalTest.
judgeVerdictLabel({
683 + __goalTest.
judgeVerdictLabel({
690 + __goalTest.
judgeVerdictLabel({
695 + ).
toBe(
"continue");
647 699 describe(
"goalVerdictLabel", ()
=> {
648 700 it(
"returns error for judge failures", ()
=> {
650 - __goalTest.
goalVerdictLabel({ done:
false, blocked:
false, reason:
"judge failed: timeout" }),
702 + __goalTest.
goalVerdictLabel({
705 + reason:
"judge failed: timeout",
653 - __goalTest.
goalVerdictLabel({ done:
false, blocked:
false, reason:
"normal reason" }),
709 + __goalTest.
goalVerdictLabel({
712 + reason:
"normal reason",
654 714 ).
toBe(
"continue");
675 735 describe(
"nextBlockedStreak", ()
=> {
676 736 it(
"increments when same hash", ()
=> {
677 737 const h
= __goalTest.
reasonHash(
"x");
678 - const state
= goal({ blockedStreak: { reasonHash: h, count:
3 } })
as never;
738 + const state
= goal({
739 + blockedStreak: { reasonHash: h, count:
3 },
679 741 expect(__goalTest.
nextBlockedStreak(state,
"X")).
toEqual({
684 746 it(
"resets to 1 when different hash", ()
=> {
685 - const state
= goal({ blockedStreak: { reasonHash:
"x", count:
3 } })
as never;
747 + const state
= goal({
748 + blockedStreak: { reasonHash:
"x", count:
3 },
686 750 expect(__goalTest.
nextBlockedStreak(state,
"different")).
toEqual({
687 751 reasonHash: expect.
any(
String),
700 764 describe(
"showsTurnBudget", ()
=> {
701 765 it(
"shows for active and paused", ()
=> {
702 - expect(__goalTest.
showsTurnBudget(
goal({ status:
"active" })
as never)).
toBe(
true);
703 - expect(__goalTest.
showsTurnBudget(
goal({ status:
"paused" })
as never)).
toBe(
true);
767 + __goalTest.
showsTurnBudget(
goal({ status:
"active" })
as never),
770 + __goalTest.
showsTurnBudget(
goal({ status:
"paused" })
as never),
705 773 it(
"hides for complete and blocked", ()
=> {
706 - expect(__goalTest.
showsTurnBudget(
goal({ status:
"complete" })
as never)).
toBe(
false);
707 - expect(__goalTest.
showsTurnBudget(
goal({ status:
"blocked" })
as never)).
toBe(
false);
775 + __goalTest.
showsTurnBudget(
goal({ status:
"complete" })
as never),
778 + __goalTest.
showsTurnBudget(
goal({ status:
"blocked" })
as never),
711 783 describe(
"showsPersistentStatus", ()
=> {
712 784 it(
"shows for all except complete", ()
=> {
713 - expect(__goalTest.
showsPersistentStatus(
goal({ status:
"active" })
as never)).
toBe(
true);
714 - expect(__goalTest.
showsPersistentStatus(
goal({ status:
"paused" })
as never)).
toBe(
true);
715 - expect(__goalTest.
showsPersistentStatus(
goal({ status:
"blocked" })
as never)).
toBe(
true);
716 - expect(__goalTest.
showsPersistentStatus(
goal({ status:
"complete" })
as never)).
toBe(
false);
786 + __goalTest.
showsPersistentStatus(
goal({ status:
"active" })
as never),
789 + __goalTest.
showsPersistentStatus(
goal({ status:
"paused" })
as never),
792 + __goalTest.
showsPersistentStatus(
goal({ status:
"blocked" })
as never),
795 + __goalTest.
showsPersistentStatus(
goal({ status:
"complete" })
as never),
722 802 expect(__goalTest.
goalTone(
goal()
as never,
"judging")).
toBe(
"warning");
724 804 it(
"complete is success", ()
=> {
725 - expect(__goalTest.
goalTone(
goal({ status:
"complete" })
as never,
"normal")).
toBe(
"success");
806 + __goalTest.
goalTone(
goal({ status:
"complete" })
as never,
"normal"),
727 809 it(
"blocked is warning", ()
=> {
728 - expect(__goalTest.
goalTone(
goal({ status:
"blocked" })
as never,
"normal")).
toBe(
"warning");
811 + __goalTest.
goalTone(
goal({ status:
"blocked" })
as never,
"normal"),
730 814 it(
"paused is muted", ()
=> {
731 - expect(__goalTest.
goalTone(
goal({ status:
"paused" })
as never,
"normal")).
toBe(
"muted");
816 + __goalTest.
goalTone(
goal({ status:
"paused" })
as never,
"normal"),
733 819 it(
"active is accent", ()
=> {
734 - expect(__goalTest.
goalTone(
goal({ status:
"active" })
as never,
"normal")).
toBe(
"accent");
821 + __goalTest.
goalTone(
goal({ status:
"active" })
as never,
"normal"),
738 826 describe(
"goalProgress", ()
=> {
739 827 it(
"calculates percentage", ()
=> {
740 - expect(__goalTest.
goalProgress(
goal({ turnsUsed:
2, maxTurns:
5 })
as never)).
toBe(
40);
741 - expect(__goalTest.
goalProgress(
goal({ turnsUsed:
0, maxTurns:
5 })
as never)).
toBe(
0);
742 - expect(__goalTest.
goalProgress(
goal({ turnsUsed:
5, maxTurns:
5 })
as never)).
toBe(
100);
829 + __goalTest.
goalProgress(
goal({ turnsUsed:
2, maxTurns:
5 })
as never),
832 + __goalTest.
goalProgress(
goal({ turnsUsed:
0, maxTurns:
5 })
as never),
835 + __goalTest.
goalProgress(
goal({ turnsUsed:
5, maxTurns:
5 })
as never),
744 838 it(
"returns 0 for maxTurns <= 0", ()
=> {
745 839 expect(__goalTest.
goalProgress(
goal({ maxTurns:
0 })
as never)).
toBe(
0);
746 840 expect(__goalTest.
goalProgress(
goal({ maxTurns:
-1 })
as never)).
toBe(
0);
748 842 it(
"clamps to 100", ()
=> {
749 - expect(__goalTest.
goalProgress(
goal({ turnsUsed:
10, maxTurns:
5 })
as never)).
toBe(
100);
844 + __goalTest.
goalProgress(
goal({ turnsUsed:
10, maxTurns:
5 })
as never),
794 890 expect(rows[
1]).not.
toContain(
"label");
796 892 it(
"handles zero inner width", ()
=> {
797 - expect(__goalTest.
goalWidgetRow(
"x",
"y",
0)).
toEqual([
"│ x │"]);
893 + expect(__goalTest.
goalWidgetRow(
"x",
"y",
0)).
toEqual([
815 913 expect(lines.
some((l)
=> l.
includes(
"verdict"))).
toBe(
true);
817 915 it(
"renders complete status with no widget", ()
=> {
818 - expect(()
=> __goalTest.
goalWidgetLines(
819 - goal({ status:
"complete" })
as never,
917 + __goalTest.
goalWidgetLines(
918 + goal({ status:
"complete" })
as never,
824 924 it(
"handles zero criteria", ()
=> {
825 925 const lines
= __goalTest.
goalWidgetLines(
847 947 expect(__goalTest.
statusLine(
goal()
as never)).
toContain(
"2/5 turns");
849 949 it(
"omits turn count for blocked status", ()
=> {
850 - expect(__goalTest.
statusLine(
goal({ status:
"blocked" })
as never)).not.
toContain(
"turns");
951 + __goalTest.
statusLine(
goal({ status:
"blocked" })
as never),
952 + ).not.
toContain(
"turns");
852 954 it(
"includes criteria count", ()
=> {
853 955 expect(__goalTest.
statusLine(
goal()
as never)).
toContain(
"2 criteria");
855 957 it(
"omits criteria when empty", ()
=> {
856 - expect(__goalTest.
statusLine(
goal({ criteria: [] })
as never)).not.
toContain(
"criteria");
959 + __goalTest.
statusLine(
goal({ criteria: [] })
as never),
960 + ).not.
toContain(
"criteria");
858 962 it(
"includes last reason when present", ()
=> {
859 - expect(__goalTest.
statusLine(
goal({ lastReason:
"stuck" })
as never)).
toContain(
"stuck");
964 + __goalTest.
statusLine(
goal({ lastReason:
"stuck" })
as never),
965 + ).
toContain(
"stuck");
861 967 it(
"omits reason when absent", ()
=> {
862 - const text
= __goalTest.
statusLine(
goal({ lastReason:
undefined })
as never);
968 + const text
= __goalTest.
statusLine(
969 + goal({ lastReason:
undefined })
as never,
863 971 const parts
= text.
split(
"\n");
864 972 expect(parts[
0]).not.
toMatch(
/· \w+$/);
868 976 describe(
"compactStatusLine", ()
=> {
869 977 it(
"shows full criteria list", ()
=> {
870 - expect(__goalTest.
compactStatusLine(
goal()
as never)).
toContain(
"criteria:\n 1. tests pass\n 2. docs updated");
978 + expect(__goalTest.
compactStatusLine(
goal()
as never)).
toContain(
979 + "criteria:\n 1. tests pass\n 2. docs updated",
872 982 it(
"omits criteria section when empty", ()
=> {
873 - const text
= __goalTest.
compactStatusLine(
goal({ criteria: [] })
as never);
983 + const text
= __goalTest.
compactStatusLine(
984 + goal({ criteria: [] })
as never,
874 986 expect(text).not.
toContain(
"criteria:");
876 988 it(
"shows verdict glyph with reason", ()
=> {
877 - expect(__goalTest.
compactStatusLine(
goal({ lastVerdict:
"done", lastReason:
"passed" })
as never)).
toContain(
"✓ passed");
878 - expect(__goalTest.
compactStatusLine(
goal({ lastVerdict:
"blocked", lastReason:
"stuck" })
as never)).
toContain(
"⊘ stuck");
990 + __goalTest.
compactStatusLine(
991 + goal({ lastVerdict:
"done", lastReason:
"passed" })
as never,
993 + ).
toContain(
"✓ passed");
995 + __goalTest.
compactStatusLine(
996 + goal({ lastVerdict:
"blocked", lastReason:
"stuck" })
as never,
998 + ).
toContain(
"⊘ stuck");
880 1000 it(
"omits reason line when absent", ()
=> {
881 - const text
= __goalTest.
compactStatusLine(
goal({ lastReason:
undefined })
as never);
1001 + const text
= __goalTest.
compactStatusLine(
1002 + goal({ lastReason:
undefined })
as never,
882 1004 expect(text).not.
toContain(
"✓");
883 1005 expect(text).not.
toContain(
"⊘");
884 1006 expect(text).not.
toContain(
"…");
886 1008 it(
"shows budget text", ()
=> {
887 - expect(__goalTest.
compactStatusLine(
goal({ timeUsedSeconds:
30, createdAt:
Date.
now() })
as never)).
toContain(
"30s");
1010 + __goalTest.
compactStatusLine(
1011 + goal({ timeUsedSeconds:
30, createdAt:
Date.
now() })
as never,
1013 + ).
toContain(
"30s");
891 1017 describe(
"goalProgress / goalBar", ()
=> {
892 1018 it(
"goalBar fills proportionally", ()
=> {
893 - expect(__goalTest.
goalBar(
goal({ turnsUsed:
0, maxTurns:
5 })
as never)).
toBe(
"──────────");
894 - expect(__goalTest.
goalBar(
goal({ turnsUsed:
5, maxTurns:
5 })
as never)).
toBe(
"━━━━━━━━━━");
895 - expect(__goalTest.
goalBar(
goal({ turnsUsed:
3, maxTurns:
10 })
as never)).
toBe(
"━━━───────");
1020 + __goalTest.
goalBar(
goal({ turnsUsed:
0, maxTurns:
5 })
as never),
1021 + ).
toBe(
"──────────");
1023 + __goalTest.
goalBar(
goal({ turnsUsed:
5, maxTurns:
5 })
as never),
1024 + ).
toBe(
"━━━━━━━━━━");
1026 + __goalTest.
goalBar(
goal({ turnsUsed:
3, maxTurns:
10 })
as never),
1027 + ).
toBe(
"━━━───────");
897 1029 it(
"goalBar custom width", ()
=> {
898 - expect(__goalTest.
goalBar(
goal({ turnsUsed:
1, maxTurns:
4 })
as never,
4)).
toBe(
"━───");
1031 + __goalTest.
goalBar(
goal({ turnsUsed:
1, maxTurns:
4 })
as never,
4),
902 1036 describe(
"parseJudge edge cases", ()
=> {
903 1037 it(
"provides defaults for missing fields", ()
=> {
904 1038 expect(__goalTest.
parseJudge(
'{"blocked":false,"reason":"x"}')).
toEqual({
905 - done:
false, blocked:
false, reason:
"x",
907 1043 expect(__goalTest.
parseJudge(
'{"done":false,"reason":"x"}')).
toEqual({
908 - done:
false, blocked:
false, reason:
"x",
911 1049 it(
"defaults non-string reason", ()
=> {
912 - expect(__goalTest.
parseJudge(
'{"done":true,"blocked":false,"reason":123}').reason).
toBe(
"no reason");
1051 + __goalTest.
parseJudge(
'{"done":true,"blocked":false,"reason":123}')
1053 + ).
toBe(
"no reason");
914 1055 it(
"strips markdown fences", ()
=> {
916 - __goalTest.
parseJudge(
'```json\n{"done":true,"blocked":false,"reason":"ok"}\n```'),
1057 + __goalTest.
parseJudge(
1058 + '```json\n{"done":true,"blocked":false,"reason":"ok"}\n```',
917 1060 ).
toEqual({ done:
true, blocked:
false, reason:
"ok" });
921 1064 describe(
"extractStandingGoalObjective edge cases", ()
=> {
922 1065 it(
"rejects without standing goal prefix", ()
=> {
923 - expect(__goalTest.
extractStandingGoalObjective(
"<objective>\nx\n</objective>")).
toBeUndefined();
1067 + __goalTest.
extractStandingGoalObjective(
"<objective>\nx\n</objective>"),
1068 + ).
toBeUndefined();
925 1070 it(
"handles nested objectives", ()
=> {
934 1079 describe(
"goalWidgetLines wrapping", ()
=> {
935 1080 it(
"wraps long objective across multiple lines", ()
=> {
936 1081 const lines
= __goalTest.
goalWidgetLines(
937 - goal({ objective:
"a b c d e f g h i j k l m n o p q r s t u v w x y z" })
as never,
1083 + objective:
"a b c d e f g h i j k l m n o p q r s t u v w x y z",
945 1092 it(
"wraps long criteria", ()
=> {
946 1093 const lines
= __goalTest.
goalWidgetLines(
947 - goal({ criteria: [
"this is a very long criterion that should wrap nicely indeed"] })
as never,
1096 + "this is a very long criterion that should wrap nicely indeed",
1008 1159 describe(
"criteriaText", ()
=> {
1009 1160 it(
"lists criteria numbered", ()
=> {
1010 - expect(__goalTest.
criteriaText(
goal()
as never)).
toBe(
"1. tests pass\n2. docs updated");
1161 + expect(__goalTest.
criteriaText(
goal()
as never)).
toBe(
1162 + "1. tests pass\n2. docs updated",
1012 1165 it(
"returns placeholder when empty", ()
=> {
1013 - expect(__goalTest.
criteriaText(
goal({ criteria: [] })
as never)).
toBe(
"No goal criteria.");
1166 + expect(__goalTest.
criteriaText(
goal({ criteria: [] })
as never)).
toBe(
1167 + "No goal criteria.",
1017 1172 describe(
"loadSettings edge cases", ()
=> {
1018 1173 it(
"returns defaults when settings missing", ()
=> {
1020 - __goalTest.
loadSettings({ settingsManager: {
getSettings: ()
=> ({}) } }
as never),
1175 + __goalTest.
loadSettings({
1176 + settingsManager: {
getSettings: ()
=> ({}) },
1021 1178 ).
toEqual({ maxTurns:
20, judgeModel:
undefined, tailBytes:
4096 });
1023 1180 it(
"returns defaults when goal settings missing", ()
=> {
1025 - __goalTest.
loadSettings({ settingsManager: {
getSettings: ()
=> ({ other:
true }) } }
as never),
1182 + __goalTest.
loadSettings({
1183 + settingsManager: {
getSettings: ()
=> ({ other:
true }) },
1026 1185 ).
toEqual({ maxTurns:
20, judgeModel:
undefined, tailBytes:
4096 });
1028 1187 it(
"ignores non-string judgeModel", ()
=> {
1030 1189 __goalTest.
loadSettings({
1031 - settingsManager: {
getSettings: ()
=> ({ goal: { judgeModel:
123 } }) },
1190 + settingsManager: {
1191 + getSettings: ()
=> ({ goal: { judgeModel:
123 } }),
1032 1193 }
as never).judgeModel,
1033 1194 ).
toBeUndefined();
1041 1202 it(
"returns subcommands for matching prefix", ()
=> {
1042 1203 const items
= __goalTest.
goalArgumentCompletions(
"st",
undefined);
1043 1204 expect(items).not.
toBeNull();
1044 - expect(items
!.
length).
toBeGreaterThanOrEqual(
1);
1205 + expect(items?.
length).
toBeGreaterThanOrEqual(
1);
1046 1207 it(
"returns null for remove without goal", ()
=> {
1047 - expect(__goalTest.
goalArgumentCompletions(
"remove ",
undefined)).
toBeNull();
1209 + __goalTest.
goalArgumentCompletions(
"remove ",
undefined),
1059 1222 it(
"mergeTurnEvidence handles empty prior", ()
=> {
1060 1223 const ev
= __goalTest.
buildTurnEvidence({
1061 - message: { content: [{ type:
"text", text:
"hi" }], usage: { input:
1, output:
1 } },
1225 + content: [{ type:
"text", text:
"hi" }],
1226 + usage: { input:
1, output:
1 },
1063 - expect(__goalTest.
mergeTurnEvidence(
undefined as never, ev).assistantText).
toBe(
"hi");
1230 + __goalTest.
mergeTurnEvidence(
undefined as never, ev).assistantText,
1067 1235 describe(
"footerPhaseText / goalPhaseText / judgeStatusText", ()
=> {
1068 1236 it(
"footerPhaseText blocked omits turns", ()
=> {
1069 - expect(__goalTest.
footerPhaseText(
goal({ status:
"blocked" })
as never,
"normal")).
toBe(
"goal blocked");
1238 + __goalTest.
footerPhaseText(
1239 + goal({ status:
"blocked" })
as never,
1242 + ).
toBe(
"goal blocked");
1071 1244 it(
"goalPhaseText blocked returns status only", ()
=> {
1072 - expect(__goalTest.
goalPhaseText(
goal({ status:
"blocked" })
as never,
"normal")).
toBe(
"blocked");
1246 + __goalTest.
goalPhaseText(
1247 + goal({ status:
"blocked" })
as never,
1250 + ).
toBe(
"blocked");
1074 1252 it(
"judgeStatusText no criteria omits suffix", ()
=> {
1075 - expect(__goalTest.
judgeStatusText(
goal({ criteria: [] })
as never)).
toBe(
"goal judging 3/5");
1253 + expect(__goalTest.
judgeStatusText(
goal({ criteria: [] })
as never)).
toBe(
1254 + "goal judging 3/5",
1091 1271 expect((entries[
0]
as any).
status).
toBe(
"paused");
1093 1273 it(
"returns undefined when no state", ()
=> {
1094 - expect(__goalTest.
cancelGoalRun({}
as never, {}
as never,
undefined)).
toBeUndefined();
1275 + __goalTest.
cancelGoalRun({}
as never, {}
as never,
undefined),
1276 + ).
toBeUndefined();
1130 1312 describe(
"parseJudge reason truncation", ()
=> {
1131 1313 it(
"truncates long reasons to 160 chars", ()
=> {
1132 1314 const longReason
= "a".
repeat(
200);
1133 - const verdict
= __goalTest.
parseJudge(
`{"done":true,"blocked":false,"reason":"${longReason}"}`);
1315 + const verdict
= __goalTest.
parseJudge(
1316 + `{"done":true,"blocked":false,"reason":"${longReason}"}`,
1134 1318 expect(verdict.reason).
toHaveLength(
160);
1135 1319 expect(verdict.reason.
endsWith(
"…")).
toBe(
true);
1137 1321 it(
"keeps short reasons intact", ()
=> {
1138 - const verdict
= __goalTest.
parseJudge(
'{"done":true,"blocked":false,"reason":"all tests pass"}');
1322 + const verdict
= __goalTest.
parseJudge(
1323 + '{"done":true,"blocked":false,"reason":"all tests pass"}',
1139 1325 expect(verdict.reason).
toBe(
"all tests pass");
1143 1329 describe(
"usageTokenDelta", ()
=> {
1144 1330 it(
"returns delta from usage record", ()
=> {
1145 - expect(__goalTest.
usageTokenDelta({ input:
10, output:
5, cacheRead:
2 })).
toBe(
13);
1332 + __goalTest.
usageTokenDelta({ input:
10, output:
5, cacheRead:
2 }),
1146 1334 expect(__goalTest.
usageTokenDelta({ input:
100, output:
50 })).
toBe(
150);
1148 1336 it(
"returns undefined for non-record", ()
=> {
1150 1338 expect(__goalTest.
usageTokenDelta(
null)).
toBeUndefined();
1152 1340 it(
"returns undefined for non-finite values", ()
=> {
1153 - expect(__goalTest.
usageTokenDelta({ input:
NaN, output:
1 })).
toBeUndefined();
1342 + __goalTest.
usageTokenDelta({ input:
NaN, output:
1 }),
1343 + ).
toBeUndefined();
1155 1345 it(
"handles zero cacheRead", ()
=> {
1156 - expect(__goalTest.
usageTokenDelta({ input:
10, output:
5, cacheRead:
0 })).
toBe(
15);
1347 + __goalTest.
usageTokenDelta({ input:
10, output:
5, cacheRead:
0 }),
1165 1357 expect(__goalTest.
canUseUpdateGoal(
undefined)).
toBe(
false);
1167 1359 it(
"returns false for non-active status", ()
=> {
1168 - expect(__goalTest.
canUseUpdateGoal(
goal({ status:
"paused" })
as never)).
toBe(
false);
1361 + __goalTest.
canUseUpdateGoal(
goal({ status:
"paused" })
as never),
1170 1364 it(
"returns false for zero turns used", ()
=> {
1171 - expect(__goalTest.
canUseUpdateGoal(
goal({ turnsUsed:
0 })
as never)).
toBe(
false);
1365 + expect(__goalTest.
canUseUpdateGoal(
goal({ turnsUsed:
0 })
as never)).
toBe(
1177 1373 expect(__goalTest.
parseLooseBoolean(
1)).
toBe(
true);
1178 1374 expect(__goalTest.
parseLooseBoolean(
0)).
toBe(
false);
1180 - it(
"accepts string \"1\"", ()
=> {
1376 + it(
'accepts string "1"', ()
=> {
1181 1377 expect(__goalTest.
parseLooseBoolean(
"1")).
toBe(
true);
1183 1379 it(
"rejects other numbers", ()
=> {
extensions/goal/index.ts
Modified 562 562 state.sessionId
&& currentSessionId
&& state.sessionId
!== currentSessionId
563 563 ? " · other session" 565 - const criteriaText
= state.criteria.
length === 0 567 - : `\ncriteria:\n${state.criteria.map((c, i) => ` ${i + 1}. ${c}`).join("\n")}`;
565 + const criteriaText
= 566 + state.criteria.
length === 0 568 + : `\ncriteria:\n${state.criteria.map((c, i) => ` ${i + 1}. ${c}`).join("\n")}`;
568 569 const reason
= state.lastReason
569 570 ? `\n${verdictGlyph(state.lastVerdict)} ${state.lastReason}` 708 709 for (
let i
= 0; i
< state.criteria.
length; i
++)
709 - lines.
push(
...goalWidgetRow(
"criteria",
sanitizeGoalText(
`${i + 1}. ${state.criteria[i]}`, maxVal), innerWidth));
713 + sanitizeGoalText(
`${i + 1}. ${state.criteria[i]}`, maxVal),
710 717 if (mode
=== "judging") {
712 719 ...goalWidgetRow(
771 778 const s
= liveGoalState
!;
772 779 const m
= liveGoalMode;
773 780 const tone
= goalTone(s, m);
774 - const lines
= goalWidgetLines(
781 + const lines
= goalWidgetLines(s, m, width);
779 782 return lines.
map((rawLine)
=> theme.
fg(tone, rawLine));
802 805 ctx.ui.
setStatus(STATUS_KEY,
undefined);
803 806 const shown
= widgetState(state);
804 - if (
!shown)
return clearFooter(pi);
805 811 const phase
= footerPhaseText(shown, mode);
807 813 shown.criteria.
length === 0 ? "" : ` · ${shown.criteria.length}c`;
1465 1471 timeBudgetSeconds: settings.timeBudgetSeconds,
1466 1472 timeUsedSeconds:
0,
1467 1473 errorRetries:
0,
1468 - sessionId:
currentSessionId(ctx),
1474 + sessionId:
currentSessionId(ctx),
1470 1476 updatedAt: now,
1472 1478 appendGoal(pi, state);
1554 1560 evidence?.stopReason
=== "aborted" || 1555 1561 evidence?.stopReason
=== "error" 1557 - const errorMessage
= evidence.errorMessage
|| `assistant ${evidence.stopReason}`;
1563 + const errorMessage
= 1564 + evidence.errorMessage
|| `assistant ${evidence.stopReason}`;
1558 1565 const retries
= (state.errorRetries
?? 0)
+ 1;
1559 1566 if (
isRetryableError(errorMessage)
&& retries
<= MAX_ERROR_RETRIES) {
1560 1567 state
= updateGoal(pi, state, {
1562 1569 lastVerdict:
"error",
1563 1570 lastReason:
`retry ${retries}/${MAX_ERROR_RETRIES}: ${errorMessage}`,
1565 - appendGoalEvent(pi,
"error-retry", state, { reason: errorMessage, retries });
1572 + appendGoalEvent(pi,
"error-retry", state, {
1573 + reason: errorMessage,
1566 1576 updateUI(pi, ctx, state);
1567 1577 syncUpdateGoalTool();
1569 - ctx.ui.
notify(
`Goal retry ${retries}/${MAX_ERROR_RETRIES} — ${errorMessage}`,
"warning");
1570 - setTimeout(()
=> scheduleContinuation(pi, ctx, state, continuation),
Math.
min(
30000,
2000 * retries));
1580 + `Goal retry ${retries}/${MAX_ERROR_RETRIES} — ${errorMessage}`,
1584 + ()
=> scheduleContinuation(pi, ctx, state, continuation),
1585 + Math.
min(
30000,
2000 * retries),
1573 1589 state
= updateGoal(pi, state, {
extensions/goal/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-goal",
6 - "peerDependencies": {
7 - "@earendil-works/pi-ai":
"*",
8 - "@earendil-works/pi-coding-agent":
"*",
9 - "@earendil-works/pi-tui":
"*",
12 - "devDependencies": {
13 - "@marcfargas/pi-test-harness":
"^0.6.1" 16 - "bench":
"node bench/goal-state.bench.ts" 19 - "description":
"Persistent /goal loop for Pi.",
2 + "name":
"@bugabinga/pi-ext-goal",
6 + "peerDependencies": {
7 + "@earendil-works/pi-ai":
"*",
8 + "@earendil-works/pi-coding-agent":
"*",
9 + "@earendil-works/pi-tui":
"*",
12 + "devDependencies": {
13 + "@marcfargas/pi-test-harness":
"^0.6.1" 16 + "bench":
"node bench/goal-state.bench.ts" 19 + "description":
"Persistent /goal loop for Pi.",
extensions/leaks/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import { mkdirSync, writeFileSync }
from "node:fs";
3 2 import os
from "node:os";
4 3 import path
from "node:path";
10 9 } from
"@marcfargas/pi-test-harness";
10 +import { afterEach, describe, expect, it }
from "vitest";
12 12 function extPath() {
13 13 return path.
resolve(
import.
meta.
dir,
"../index.ts");
extensions/leaks/__tests__/real/minimax.test.ts
Modified 1 -import { describe, expect, it }
from "vitest";
2 1 import fs
from "node:fs";
3 2 import os
from "node:os";
4 3 import path
from "node:path";
13 12 } from
"@earendil-works/pi-coding-agent";
13 +import { describe, expect, it }
from "vitest";
15 15 const real
= process.
env.LEAKS_REAL
=== "1";
16 16 const d
= real
? describe
: describe.skip;
extensions/leaks/__tests__/unit.test.ts
Modified 1 -import { describe, expect, it }
from "vitest";
2 1 import fs, { mkdtempSync, writeFileSync }
from "node:fs";
3 2 import { tmpdir }
from "node:os";
4 3 import path
from "node:path";
4 +import { describe, expect, it }
from "vitest";
5 5 import { __test }
from "../index.ts";
7 7 describe(
"leaks engine", ()
=> {
extensions/leaks/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-leaks",
3 - "description":
"Provider-bound secret redaction for Pi.",
7 - "test:real":
"LEAKS_REAL=1 vitest run ./__tests__/real/*.test.ts --timeout 120000" 17 - "peerDependencies": {
18 - "@earendil-works/pi-ai":
"*",
19 - "@earendil-works/pi-coding-agent":
"*" 21 - "devDependencies": {
22 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-leaks",
3 + "description":
"Provider-bound secret redaction for Pi.",
7 + "test:real":
"LEAKS_REAL=1 vitest run ./__tests__/real/*.test.ts --timeout 120000" 17 + "peerDependencies": {
18 + "@earendil-works/pi-ai":
"*",
19 + "@earendil-works/pi-coding-agent":
"*" 21 + "devDependencies": {
22 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/llmiterate/__tests__/__snapshots__/core.test.ts.snap
Modified 1 -// Bun Snapshot v1, https://bun.sh/docs/test/snapshots
1 +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
3 +exports[`llmiterate output snapshots > agent prompt snapshot 1`] = `
4 +"llmiterate request from @a.rs:1
6 +Prompt marker contents:
12 +- Work in/around @a.rs.
13 +- Marker span to replace: a.rs:1-1.
14 +- Treat the marker comment line(s) as an inline prompt/TODO, not program code.
15 +- Replace the whole marker span with the requested implementation or code change.
16 +- Do not leave the marker line(s) behind unless impossible; explain if impossible."
3 19 exports[`llmiterate output snapshots agent prompt snapshot 1`] = `
4 20 "llmiterate request from @a.rs:1
extensions/llmiterate/__tests__/__snapshots__/ui.test.ts.snap
Modified 1 -// Bun Snapshot v1, https://bun.sh/docs/test/snapshots
1 +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
3 3 exports[`llmiterate UI widget empty snapshot 1`] = `
4 4 "╭ llmiterate ──────────────────────────────────────────────╮
5 -│no prompts queued yet; /llmiterate log opens latest trans\x1B[0m…\x1B[0m│
5 +│no prompts queued yet; /llmiterate log opens latest trans[0m…[0m│
6 6 ╰──────────────────────────────────────────────────────────╯"
extensions/llmiterate/__tests__/core.test.ts
Modified 1 -import { afterEach, describe, expect, test }
from "vitest";
2 1 import { mkdtempSync, readFileSync, rmSync, writeFileSync }
from "node:fs";
3 2 import { tmpdir }
from "node:os";
4 3 import { join }
from "node:path";
4 +import { afterEach, describe, expect, test }
from "vitest";
7 7 COMMENT_PREFIXES_BY_EXTENSION,
155 155 test(
"normalizes CRLF and CR line endings", ()
=> {
157 - parseMarkerPrompts(
"a.ts",
"// llmiterate: one\r\n// llmiterate: two")[
0]
! 157 + parseMarkerPrompts(
"a.ts",
"// llmiterate: one\r\n// llmiterate: two")[
0]
159 159 ).
toBe(
"one\ntwo");
161 - parseMarkerPrompts(
"a.ts",
"// llmiterate: one\r// llmiterate: two")[
0]
! 161 + parseMarkerPrompts(
"a.ts",
"// llmiterate: one\r// llmiterate: two")[
0]
163 163 ).
toBe(
"one\ntwo");
290 290 saveState(storeDir, state);
291 - expect(
loadState(storeDir).markers.a
!.
status).
toBe(
"failed");
291 + expect(
loadState(storeDir).markers.a?.
status).
toBe(
"failed");
294 294 test(
"glob supports globstar, brace alternatives, and excludes", ()
=> {
extensions/llmiterate/__tests__/extension.test.ts
Modified 1 -import { afterEach, describe, expect, test }
from "vitest";
2 1 import { mkdirSync, writeFileSync }
from "node:fs";
3 2 import { join }
from "node:path";
3 +import { afterEach, describe, expect, test }
from "vitest";
4 4 import { loadState, projectStoreDir }
from "../core";
5 5 import { createLlmiterateExtension }
from "../index";
99 99 await pi.
command(
"llmiterate",
"on");
100 100 await eventually(()
=> worker.finished
=== 1);
102 - Object.
values(
loadState(
projectStoreDir(
root)).markers)[
0]
!.
status,
102 + Object.
values(
loadState(
projectStoreDir(
root)).markers)[
0]?.
status,
103 103 ).
toBe(
"failed");
105 105 await pi.
command(
"llmiterate",
"scan");
extensions/llmiterate/__tests__/gitignore.bench.ts
Modified 60 60 function generatePaths(count
: number)
: string[] {
62 - "src",
"src/components",
"src/utils",
"src/lib",
"src/hooks",
63 - "tests",
"tests/unit",
"tests/integration",
64 - "docs",
"scripts",
"config",
"public",
"assets",
65 - "packages/core/src",
"packages/ui/src",
"packages/utils/src",
66 - "node_modules/lodash",
"node_modules/react",
"node_modules/typescript",
67 - "dist/esm",
"dist/cjs",
"dist/types",
68 - ".git",
".github",
".vscode",
".idea",
69 + "tests/integration",
75 + "packages/core/src",
77 + "packages/utils/src",
78 + "node_modules/lodash",
79 + "node_modules/react",
80 + "node_modules/typescript",
70 - const exts
= [
".ts",
".js",
".tsx",
".jsx",
".json",
".md",
".css",
".html",
".log",
".tmp",
".swp",
".bak",
".map",
".min.js"];
71 - const names
= [
"index",
"main",
"utils",
"config",
"types",
"helpers",
"constants",
"hooks",
"context",
"provider",
"App",
"router",
"store",
"api",
"client",
"server"];
72 123 const out
: string[]
= [];
73 124 for (
let i
= 0; i
< count; i
++) {
74 125 const dir
= dirs[i
% dirs.
length];
extensions/llmiterate/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"llmiterate pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/llmiterate/__tests__/harness.ts
Modified 1 -import { expect }
from "vitest";
9 8 import { tmpdir }
from "node:os";
10 9 import { join }
from "node:path";
10 +import { expect }
from "vitest";
11 11 import type { CompiledPathFilter, LlmiterateConfig }
from "../core";
12 12 import { createLlmiterateExtension }
from "../index";
13 13 import type { PiRpcWorker }
from "../rpc";
extensions/llmiterate/__tests__/lock.test.ts
Modified 1 -import { afterEach, describe, expect, test }
from "vitest";
9 8 import { hostname, tmpdir }
from "node:os";
10 9 import { join }
from "node:path";
10 +import { afterEach, describe, expect, test }
from "vitest";
11 11 import { acquireLock, type LockHandle, realPath, releaseLock }
from "../lock";
13 13 const tempDirs
: string[]
= [];
extensions/llmiterate/__tests__/log.test.ts
Modified 1 -import { afterEach, describe, expect, test }
from "vitest";
10 9 import { tmpdir }
from "node:os";
11 10 import { join }
from "node:path";
11 +import { afterEach, describe, expect, test }
from "vitest";
14 14 parseEditorCommand,
83 83 expect(
latestSessionFile(
root)).
toBe(newer);
84 84 const target
= renderLatestSessionLog(
root,
join(
root,
"logs"));
85 85 expect(target?.sessionFile).
toBe(newer);
86 - expect(
readFileSync(target
!.markdownFile,
"utf-8")).
toContain(
"new");
86 + expect(
readFileSync(target?.markdownFile,
"utf-8")).
toContain(
"new");
extensions/llmiterate/__tests__/rpc.test.ts
Modified 1 -import { afterEach, describe, expect, test }
from "vitest";
2 1 import { mkdtempSync, readFileSync, rmSync }
from "node:fs";
3 2 import { tmpdir }
from "node:os";
4 3 import { join }
from "node:path";
4 +import { afterEach, describe, expect, test }
from "vitest";
5 5 import { LLMITERATE_WORKER_ENV, PiRpcWorker, workerArgs }
from "../rpc";
6 6 import type { RpcEvent }
from "../types";
12 12 type FakeRpcMode = "ok" | "fail-new-session" | "malformed" | "env" | "hang";
15 - while (workers.
length) workers.
pop()
!.
dispose();
15 + while (workers.
length) workers.
pop()?.
dispose();
16 16 while (tempDirs.
length)
17 17 rmSync(tempDirs.
pop()
!, { recursive:
true, force:
true });
extensions/llmiterate/__tests__/ui.test.ts
Modified 1 -import { describe, expect, test }
from "vitest";
2 1 import type { ExtensionContext }
from "@earendil-works/pi-coding-agent";
2 +import { describe, expect, test }
from "vitest";
3 3 import { defaultConfig, normalizeConfig, parseMarkerPrompts }
from "../core";
4 4 import type { LlmiterateRun }
from "../types";
5 5 import { renderLlmiterateStatus }
from "../ui";
extensions/llmiterate/__tests__/watcher.test.ts
Modified 1 -import { afterEach, describe, expect, test }
from "vitest";
9 8 import { tmpdir }
from "node:os";
10 9 import { join }
from "node:path";
10 +import { afterEach, describe, expect, test }
from "vitest";
11 11 import { compilePathFilter, normalizeConfig }
from "../core";
12 12 import { ProjectWatcher }
from "../watcher";
15 15 const watchers
: ProjectWatcher[]
= [];
18 - while (watchers.
length) watchers.
pop()
!.
stop();
18 + while (watchers.
length) watchers.
pop()?.
stop();
19 19 while (tempDirs.
length)
20 20 rmSync(tempDirs.
pop()
!, { recursive:
true, force:
true });
extensions/llmiterate/gitignore.ts
Modified177 177 * Several fast paths avoid
RegExp construction for common
patterns:
178 178 * exact names,
suffix (
`*.ext`),
prefix (
`foo*`), and anchored literals.
180 -function compileTest(rawPattern
: string, directoryOnly
: boolean)
: TestFn | null {
180 +function compileTest(
181 + rawPattern
: string,
182 + directoryOnly
: boolean,
181 184 const { pattern, info }
= analyzePattern(rawPattern);
182 185 const { anchored, isRelative }
= info;
190 - if (
!anchored
&& !info.hasSlash
&& pattern.
startsWith(
"*.")
&& !hasSpecialChars(pattern.
slice(
2))) {
196 + pattern.
startsWith(
"*.")
&& 197 + !hasSpecialChars(pattern.
slice(
2))
191 199 const suffix
= pattern.
slice(
1);
192 200 return (p)
=> basenameOf(p).
endsWith(suffix);
196 - if (
!anchored
&& !info.hasSlash
&& pattern.
endsWith(
"*")
&& pattern.
indexOf(
"*")
=== pattern.
length - 1 && !hasSpecialChars(pattern.
slice(
0,
-1))) {
207 + pattern.
endsWith(
"*")
&& 208 + pattern.
indexOf(
"*")
=== pattern.
length - 1 && 209 + !hasSpecialChars(pattern.
slice(
0,
-1))
197 211 const prefix
= pattern.
slice(
0,
-1);
198 212 return (p)
=> basenameOf(p).
startsWith(prefix);
235 -function buildRegex(pattern
: string, anchored
: boolean, isRelative
: boolean)
: RegExp | null {
249 +function buildRegex(
252 + isRelative
: boolean,
238 256 while (i
< pattern.
length) {
297 315 let body
: string;
298 316 if (anchored
|| isRelative) {
299 - body
= `^${src}(?=$|\/)`;
317 + body
= `^${src}(?=$|/)`;
300 318 }
else if (pattern.
includes(
"/")) {
301 - body
= `^(?:.*\/)?${src}(?=$|\/)`;
319 + body
= `^(?:.*/)?${src}(?=$|/)`;
303 - body
= `^(?:[^/]*\/)??${src}(?=$|\/)`;
321 + body
= `^(?:[^/]*/)??${src}(?=$|/)`;
306 324 return new RegExp(body);
extensions/llmiterate/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-llmiterate",
7 - "peerDependencies": {
8 - "@earendil-works/pi-coding-agent":
"*",
9 - "@earendil-works/pi-tui":
"*" 12 - "description":
"LLM iteration watcher for Pi.",
17 - "devDependencies": {
18 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-llmiterate",
7 + "peerDependencies": {
8 + "@earendil-works/pi-coding-agent":
"*",
9 + "@earendil-works/pi-tui":
"*" 12 + "description":
"LLM iteration watcher for Pi.",
17 + "devDependencies": {
18 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/llmiterate/rpc.ts
Modified162 162 return new Promise((resolve, reject)
=> {
163 163 this.pending.
set(id, { command: payload.
type, resolve, reject });
164 - this.proc
!.stdin.
write(line, (error)
=> {
164 + this.proc?.stdin.
write(line, (error)
=> {
165 165 if (
!error)
return;
166 166 this.pending.
delete(id);
extensions/model-info/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
7 7 import { __test }
from "../index.ts";
9 9 describe(
"model-info pi-test-harness", ()
=> {
extensions/model-info/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-model-info",
5 - "peerDependencies": {
6 - "@earendil-works/pi-coding-agent":
"*" 9 - "description":
"Model and thinking telemetry for Pi.",
14 - "devDependencies": {
15 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-model-info",
5 + "peerDependencies": {
6 + "@earendil-works/pi-coding-agent":
"*" 9 + "description":
"Model and thinking telemetry for Pi.",
14 + "devDependencies": {
15 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/neko/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"neko pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/neko/__tests__/lifecycle.test.ts
Modified 1 +import { mkdtempSync, rmSync, writeFileSync }
from "node:fs";
2 +import { tmpdir }
from "node:os";
3 +import { join }
from "node:path";
10 -import { mkdtempSync, rmSync, writeFileSync }
from "node:fs";
11 -import { tmpdir }
from "node:os";
12 -import { join }
from "node:path";
14 14 type Handler = (event
: any, ctx
: any)
=> unknown | Promise<
unknown>;
19 19 kind:
"timeout" | "interval";
22 -type Harness = ReturnType<
typeof createHarness>;
25 23 let projectDir
= "";
26 24 let nekoExtension: (pi
: any)
=> void;
215 213 expect(
stripAnsi(editor.
render(
40)[
0])).
toContain(
"[");
217 215 await h.
emit(
"session_compact");
218 - expect(compactionTimer
!.cleared).
toBe(
true);
216 + expect(compactionTimer?.cleared).
toBe(
true);
219 217 expect(
stripAnsi(editor.
render(
40)[
0])).
toContain(
"(=^");
250 248 expect(compactionTimers).
toHaveLength(
2);
251 249 expect(first.cleared).
toBe(
true);
252 - expect(compactionTimers[
1]
!.cleared).
toBe(
false);
250 + expect(compactionTimers[
1]?.cleared).
toBe(
false);
255 253 it(
"shutdown restores upstream UI and clears editor, error, compaction timers",
async ()
=> {
extensions/neko/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-neko",
6 - "peerDependencies": {
7 - "@earendil-works/pi-coding-agent":
"*",
8 - "@earendil-works/pi-tui":
"*" 11 - "description":
"Tiny animated editor cat for Pi.",
16 - "devDependencies": {
17 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-neko",
6 + "peerDependencies": {
7 + "@earendil-works/pi-coding-agent":
"*",
8 + "@earendil-works/pi-tui":
"*" 11 + "description":
"Tiny animated editor cat for Pi.",
16 + "devDependencies": {
17 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/nu-bang/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"nu-bang pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/nu-bang/__tests__/nu-bang.test.ts
Modified 1 -import { describe, expect, test }
from "vitest";
2 1 import { join }
from "node:path";
2 +import { describe, expect, test }
from "vitest";
extensions/nu-bang/__tests__/real-world.test.ts
Modified 1 -import { afterEach, beforeEach, describe, expect, test }
from "vitest";
2 1 import { readdirSync }
from "node:fs";
11 10 } from
"node:fs/promises";
12 11 import { tmpdir }
from "node:os";
13 12 import { join }
from "node:path";
13 +import { afterEach, beforeEach, describe, expect, test }
from "vitest";
15 15 createNuBashOperations,
extensions/nu-bang/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-nu-bang",
6 - "peerDependencies": {
7 - "@earendil-works/pi-coding-agent":
"*",
8 - "@earendil-works/pi-tui":
"*" 11 - "description":
"Nushell bang-command bridge for Pi.",
16 - "devDependencies": {
17 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-nu-bang",
6 + "peerDependencies": {
7 + "@earendil-works/pi-coding-agent":
"*",
8 + "@earendil-works/pi-tui":
"*" 11 + "description":
"Nushell bang-command bridge for Pi.",
16 + "devDependencies": {
17 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/prompt-autopsy/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"prompt-autopsy pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/prompt-autopsy/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-prompt-autopsy",
5 - "peerDependencies": {
6 - "@earendil-works/pi-coding-agent":
"*",
7 - "@earendil-works/pi-tui":
"*" 10 - "description":
"System-prompt autopsy command for Pi.",
15 - "devDependencies": {
16 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-prompt-autopsy",
5 + "peerDependencies": {
6 + "@earendil-works/pi-coding-agent":
"*",
7 + "@earendil-works/pi-tui":
"*" 10 + "description":
"System-prompt autopsy command for Pi.",
15 + "devDependencies": {
16 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/pulse/__tests__/core.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import * as fs
from "node:fs";
3 2 import * as os
from "node:os";
4 3 import * as path
from "node:path";
4 +import { afterEach, describe, expect, it }
from "vitest";
extensions/pulse/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import { existsSync, mkdirSync, readFileSync, writeFileSync }
from "node:fs";
3 2 import path
from "node:path";
7 6 }
from "@marcfargas/pi-test-harness";
7 +import { afterEach, describe, expect, it }
from "vitest";
9 9 let t
: TestSession | undefined;
25 25 function ctx()
: any {
26 - return t
!.session.extensionRunner.
createCommandContext();
26 + return t?.session.extensionRunner.
createCommandContext();
29 29 function configPath()
: string {
30 - return path.
join(t
!.cwd,
".pi/pulse.json");
30 + return path.
join(t?.cwd,
".pi/pulse.json");
33 33 function writeConfig(config
: unknown)
: void {
38 38 function notifyText()
: string[] {
39 - return t
!.events.
uiCallsFor(
"notify").
map((c)
=> String(c.args[
0]));
39 + return t?.events.
uiCallsFor(
"notify").
map((c)
=> String(c.args[
0]));
42 42 function statusText()
: string[] {
44 44 .
uiCallsFor(
"setStatus")
45 45 .
filter((c)
=> c.args[
0]
=== "pulse")
46 46 .
map((c)
=> String(c.args[
1]));
214 214 expect(tick).
toBeDefined();
216 216 now
= 6 * 60 * 1000;
219 219 ()
=> notifyText().
some((m)
=> m.
startsWith(
"Pulse: ")),
extensions/pulse/__tests__/index.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import * as fs
from "node:fs";
3 2 import * as os
from "node:os";
4 3 import * as path
from "node:path";
4 +import { afterEach, describe, expect, it }
from "vitest";
6 6 let completionText
= '{"updates":[]}';
7 7 let completionTexts
: string[]
= [];
extensions/pulse/index.ts
Modified 260 260 typeof u.
summary === "string" 261 261 ? stripUnsafeText(u.
summary).
slice(
0, MAX_SUMMARY_CHARS)
263 - if (u.
content !== allowed.
get(u.path)
!.
content)
263 + if (u.
content !== allowed.
get(u.path)?.
content)
264 264 out.
push({ path: u.path, content: u.
content, summary });
265 265 seen.
add(u.path);
412 412 throw new Error(
`changed while updating: ${update.path}`);
414 414 for (
const update
of updates) {
415 - fs.
writeFileSync(byPath.
get(update.path)
!.absPath, update.
content,
"utf-8");
415 + fs.
writeFileSync(byPath.
get(update.path)?.absPath, update.
content,
"utf-8");
778 778 for (
const doc
of docs) {
779 779 const modelKey
= doc.model
|| defaultKey;
780 780 if (
!groups.
has(modelKey)) groups.
set(modelKey, []);
781 - groups.
get(modelKey)
!.
push(doc);
781 + groups.
get(modelKey)?.
push(doc);
784 784 return Array.
from(groups.
entries())
957 957 function removeDoc(target
: string)
: { removed
: boolean; path
?: string } {
959 959 const index
= parseInt(target,
10);
960 - if (
!isNaN(index)
&& index
>= 0 && index
< state.config.documents.
length) {
961 + !Number.
isNaN(index)
&& 963 + index
< state.config.documents.
length 961 965 const doc
= state.config.documents.
splice(index,
1)[
0];
962 966 saveConfig(state.cwd, state.config);
963 967 return { removed:
true, path: doc.path };
1491 1495 setStatus(ctx);
1494 - pi.
on(
"session_shutdown",
async (_event, ctx)
=> {
1498 + pi.
on(
"session_shutdown",
async (_event, _ctx)
=> {
1496 1500 stopConfigWatcher();
extensions/pulse/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-pulse",
5 - "peerDependencies": {
6 - "@earendil-works/pi-ai":
"*",
7 - "@earendil-works/pi-coding-agent":
"*" 10 - "description":
"Living documentation sync for Pi.",
16 - "devDependencies": {
17 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-pulse",
5 + "peerDependencies": {
6 + "@earendil-works/pi-ai":
"*",
7 + "@earendil-works/pi-coding-agent":
"*" 10 + "description":
"Living documentation sync for Pi.",
16 + "devDependencies": {
17 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/q/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"q pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/q/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-q",
5 - "peerDependencies": {
6 - "@earendil-works/pi-coding-agent":
"*",
7 - "@earendil-works/pi-ai":
"*",
8 - "@earendil-works/pi-tui":
"*" 11 - "description":
"Follow-up question fork helper for Pi.",
16 - "devDependencies": {
17 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-q",
5 + "peerDependencies": {
6 + "@earendil-works/pi-coding-agent":
"*",
7 + "@earendil-works/pi-ai":
"*",
8 + "@earendil-works/pi-tui":
"*" 11 + "description":
"Follow-up question fork helper for Pi.",
16 + "devDependencies": {
17 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/q/wizard-ui.ts
Modified100 100 private
handleSelectionInput(data: string):
void {
101 - if (
matchesKey(data, Key.escape))
return this.
done({ type:
"cancel" });
102 - if (
matchesKey(data, Key.up))
return this.
move(
-1);
103 - if (
matchesKey(data, Key.down))
return this.
move(
1);
104 - if (
matchesKey(data, Key.enter))
return this.
choose();
101 + if (
matchesKey(data, Key.escape)) {
102 + this.
done({ type:
"cancel" });
105 + if (
matchesKey(data, Key.up)) {
109 + if (
matchesKey(data, Key.down)) {
113 + if (
matchesKey(data, Key.enter)) {
107 119 private
move(delta: number):
void {
112 124 private
choose():
void {
113 125 const choice
= this.
choices()[this.
selected];
114 126 if (
!choice)
return;
115 - if (choice.
type === "answer")
return this.
accept(choice.
value);
116 - if (choice.
type === "fork")
117 - return this.
done({ type:
"fork", state: this.state });
127 + if (choice.
type === "answer") {
128 + this.
accept(choice.
value);
131 + if (choice.
type === "fork") {
132 + this.
done({ type:
"fork", state: this.state });
118 135 this.
setMode(
"custom");
extensions/quota/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
7 7 import { __test }
from "../index.ts";
9 9 describe(
"quota pi-test-harness", ()
=> {
extensions/quota/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-quota",
5 - "peerDependencies": {
6 - "@earendil-works/pi-coding-agent":
"*" 9 - "description":
"Subscription quota dashboard for Pi.",
14 - "devDependencies": {
15 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-quota",
5 + "peerDependencies": {
6 + "@earendil-works/pi-coding-agent":
"*" 9 + "description":
"Subscription quota dashboard for Pi.",
14 + "devDependencies": {
15 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/runtime/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"runtime pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/runtime/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-runtime",
5 - "peerDependencies": {
6 - "@earendil-works/pi-coding-agent":
"*" 9 - "description":
"Runtime detection telemetry for Pi.",
14 - "devDependencies": {
15 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-runtime",
5 + "peerDependencies": {
6 + "@earendil-works/pi-coding-agent":
"*" 9 + "description":
"Runtime detection telemetry for Pi.",
14 + "devDependencies": {
15 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/session-rename/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"session-rename pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/session-rename/index.ts
Modified145 145 for (
const e
of messageEntries.
slice(
-10)) {
146 - const role
= e.message
!.role;
146 + const role
= e.message?.role;
147 147 if (role
=== "user") {
148 - const text
= extractText(e.message
!.
content).
trim();
148 + const text
= extractText(e.message?.
content).
trim();
149 149 if (text) messageLines.
push(
`Recent user: ${text.slice(0, 900)}`);
150 150 }
else if (role
=== "assistant") {
151 - const text
= extractText(e.message
!.
content).
trim();
151 + const text
= extractText(e.message?.
content).
trim();
152 152 if (text) messageLines.
push(
`Recent assistant: ${text.slice(0, 900)}`);
153 - messageLines.
push(
...extractToolCalls(e.message
!.
content).
slice(
0,
8));
153 + messageLines.
push(
...extractToolCalls(e.message?.
content).
slice(
0,
8));
154 154 }
else if (role
=== "toolResult") {
155 - const text
= extractText(e.message
!.
content).
trim();
155 + const text
= extractText(e.message?.
content).
trim();
157 157 messageLines.
push(
158 - `Result(${e.message!.toolName ?? "tool"}): ${text.slice(0, 300)}`,
158 + `Result(${e.message?.toolName ?? "tool"}): ${text.slice(0, 300)}`,
450 450 export default function (pi
: ExtensionAPI) {
451 451 let idleTimer
: ReturnType<
typeof setTimeout>
| undefined;
452 452 let activeController
: AbortController | undefined;
453 - let currentCtx
: ExtensionContext | undefined;
453 + let _currentCtx
: ExtensionContext | undefined;
455 455 const clearTimer = ()
=> {
546 546 pi.
on(
"session_start",
async (_event, ctx)
=> {
548 548 scheduleRename(ctx,
"load", LOAD_DELAY_MS);
551 551 pi.
on(
"turn_end",
async (_event, ctx)
=> {
553 553 scheduleRename(ctx,
"turn");
571 571 pi.
on(
"session_shutdown",
async (_event, ctx)
=> {
573 573 cancelActive(ctx);
574 - currentCtx
= undefined;
574 + _currentCtx
= undefined;
577 577 pi.
registerCommand(
"session-rename", {
extensions/session-rename/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-session-rename",
5 - "peerDependencies": {
6 - "@earendil-works/pi-ai":
"*",
7 - "@earendil-works/pi-coding-agent":
"*" 10 - "description":
"Automatic short session names for Pi.",
15 - "devDependencies": {
16 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-session-rename",
5 + "peerDependencies": {
6 + "@earendil-works/pi-ai":
"*",
7 + "@earendil-works/pi-coding-agent":
"*" 10 + "description":
"Automatic short session names for Pi.",
15 + "devDependencies": {
16 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/ssh-tools/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"ssh-tools pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/ssh-tools/index.test.ts
Modified 6 -import { describe, expect, test }
from "vitest";
6 +import { expect, test }
from "vitest";
8 8 test(
"shellQuote escapes single quotes", ()
=> {
9 9 function shellQuote(s
: string) {
extensions/ssh-tools/index.ts
Modified139 139 if (opts.signal.aborted)
onAbort();
140 140 else opts.signal.
addEventListener(
"abort", onAbort, { once:
true });
142 - if (opts.stdin
!== undefined) child.stdin
!.
write(opts.stdin);
143 - child.stdin
!.
end();
142 + if (opts.stdin
!== undefined) child.stdin?.
write(opts.stdin);
143 + child.stdin?.
end();
250 250 let target
: Target | null = null;
252 -const readBase
= createReadToolDefinition(
"/");
253 -const writeBase
= createWriteToolDefinition(
"/");
252 +const _readBase
= createReadToolDefinition(
"/");
253 +const _writeBase
= createWriteToolDefinition(
"/");
254 254 const editBase
= createEditToolDefinition(
"/");
255 255 const bashBase
= createBashToolDefinition(
"/");
302 302 execute(id, params, signal, onUpdate) {
304 - return mkDef(target
!.cwd, { operations:
ops(target
!) }).
execute(
304 + return mkDef(target?.cwd, { operations:
ops(target
!) }).
execute(
322 322 parameters: bashBase.parameters,
323 323 execute(id, params, signal, onUpdate) {
325 - return createBashToolDefinition(target
!.cwd, {
325 + return createBashToolDefinition(target?.cwd, {
326 326 operations:
remoteBash(target
!),
327 327 }).
execute(id, params, signal, onUpdate);
extensions/ssh-tools/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-ssh-tools",
5 - "peerDependencies": {
6 - "@earendil-works/pi-coding-agent":
"*",
7 - "@earendil-works/pi-tui":
"*" 10 - "description":
"SSH mode and remote tools for Pi.",
15 - "devDependencies": {
16 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-ssh-tools",
5 + "peerDependencies": {
6 + "@earendil-works/pi-coding-agent":
"*",
7 + "@earendil-works/pi-tui":
"*" 10 + "description":
"SSH mode and remote tools for Pi.",
15 + "devDependencies": {
16 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/superpowers/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import { existsSync, mkdirSync, readFileSync, writeFileSync }
from "node:fs";
3 2 import path
from "node:path";
7 6 }
from "@marcfargas/pi-test-harness";
7 +import { afterEach, describe, expect, it }
from "vitest";
8 8 import { __test }
from "../index.ts";
10 10 let t
: TestSession | undefined;
18 18 t
!.session.extensionRunner.extensions[
0].commands.
get(
"superpowers")
!;
19 19 const ctx = ()
=> t
!.session.extensionRunner.
createCommandContext();
20 20 const notices = ()
=> 21 - t
!.events.
uiCallsFor(
"notify").
map((c)
=> String(c.args[
0]));
22 -const tasksPath = ()
=> __test.
tasksFile(t
!.cwd);
21 + t?.events.
uiCallsFor(
"notify").
map((c)
=> String(c.args[
0]));
22 +const tasksPath = ()
=> __test.
tasksFile(t?.cwd);
23 23 const tasks = ()
=> JSON.
parse(
readFileSync(
tasksPath(),
"utf8"));
24 24 const sleep = (ms
: number)
=> new Promise((r)
=> setTimeout(r, ms));
40 40 getSessionFile: ()
=> sessionFile,
41 41 appendCustomEntry: (customType
: string, data
: unknown)
=> {
42 - const entry
= { id:
`e${++entrySeq}`, type:
"custom", customType, data };
43 + id:
`e${++entrySeq}`,
43 48 entries.
push(entry);
81 86 await command().
handler(
"open sp-404",
ctx());
82 87 expect(
notices()).
toContain(
"superpowers on");
83 88 expect(
notices()).
toContain(
"superpowers off");
84 - expect(
notices().
some((m)
=> m.
includes(
"superpowers off\nno tasks"))).
toBe(
true);
89 + expect(
notices().
some((m)
=> m.
includes(
"superpowers off\nno tasks"))).
toBe(
85 92 expect(
notices().
some((m)
=> m.
includes(
"/superpowers agent"))).
toBe(
true);
86 93 expect(
notices()).
toContain(
"usage: /superpowers agent <prompt>");
87 94 expect(
notices().
some((m)
=> m.
includes(
"no tasks"))).
toBe(
true);
133 140 [
"done",
"error"].
includes(
tasks()[
"sp-1"]?.
status),
135 142 expect(
tasks()[
"sp-1"].agent).
toBe(
"systematic-debugging");
136 - expect(
tasks()[
"sp-1"].
prompt).
toContain(
"No fix before root-cause evidence");
143 + expect(
tasks()[
"sp-1"].
prompt).
toContain(
144 + "No fix before root-cause evidence",
137 146 expect(
tasks()[
"sp-1"].
prompt).
toContain(
"flaky test");
280 289 process.
env.PI_SUPERPOWERS_NO_OPEN
= "1";
282 291 await command().
handler(
"visual start",
ctx());
283 - await waitFor(()
=> t
!.events.messages.
some((m
: any)
=> m.customType
=== "superpowers"));
292 + await waitFor(()
=> 293 + t?.events.messages.
some((m
: any)
=> m.customType
=== "superpowers"),
284 295 const firstNotice
= notices().
at(
-1)
!;
285 296 expect(firstNotice).
toContain(
"visual live: http://127.0.0.1:");
286 297 expect(firstNotice).
toContain(
"content:");
287 298 expect(firstNotice).
toContain(
"events file:");
288 299 expect(firstNotice).
toContain(
"open manually: browser opener disabled");
289 - const firstMessage
= t.events.messages.
find((m
: any)
=> m.customType
=== "superpowers")
as any;
290 - expect(firstMessage.
content).
toContain(
"Superpowers visual brainstorming");
300 + const firstMessage
= t.events.messages.
find(
301 + (m
: any)
=> m.customType
=== "superpowers",
303 + expect(firstMessage.
content).
toContain(
304 + "Superpowers visual brainstorming",
291 306 expect(firstMessage.
content).
toContain(
"visual live: http://127.0.0.1:");
292 307 expect(firstMessage.
content).
toContain(
"content:");
293 308 expect(firstMessage.
content).
toContain(
"events file:");
294 309 expect(firstMessage.
content).
toContain(
"Agent rules:");
295 - expect(firstMessage.
content).
toContain(
"Use visual only for active user decisions");
296 - expect(firstMessage.
content).
toContain(
"Do not use visual as progress reporting");
310 + expect(firstMessage.
content).
toContain(
311 + "Use visual only for active user decisions",
313 + expect(firstMessage.
content).
toContain(
314 + "Do not use visual as progress reporting",
297 316 expect(firstMessage.
content).
toContain(
"data-choice");
298 - expect(firstMessage.
content).
toContain(
"wait for terminal answer or browser event");
317 + expect(firstMessage.
content).
toContain(
318 + "wait for terminal answer or browser event",
299 320 expect(firstMessage.
content).
toContain(
"Read the events file directly");
300 321 expect(firstMessage.
content).
toContain(
"Continuing in terminal");
301 322 expect(firstMessage.
content).not.
toContain(
"visual events");
305 326 const eventsFile
= firstMessage.details.eventsFile;
307 328 await command().
handler(
"visual start",
ctx());
308 - await waitFor(()
=> t
!.events.messages.
filter((m
: any)
=> m.customType
=== "superpowers").
length >= 2);
331 + t?.events.messages.
filter((m
: any)
=> m.customType
=== "superpowers")
309 334 expect(
notices().
at(
-1)).
toContain(
`visual already live: ${url}`);
310 - const secondMessage
= t.events.messages.
filter((m
: any)
=> m.customType
=== "superpowers").
at(
-1)
as any;
335 + const secondMessage
= t.events.messages
336 + .
filter((m
: any)
=> m.customType
=== "superpowers")
311 338 expect(secondMessage.details.url).
toBe(url);
312 339 expect(secondMessage.details.contentDir).
toBe(contentDir);
313 340 expect(secondMessage.details.eventsFile).
toBe(eventsFile);
331 358 process.
env.PI_SUPERPOWERS_NO_OPEN
= "1";
333 360 await command().
handler(
"visual start",
ctx());
334 - await waitFor(()
=> t
!.events.messages.
some((m
: any)
=> m.customType
=== "superpowers"));
335 - const message
= t.events.messages.
find((m
: any)
=> m.customType
=== "superpowers")
as any;
361 + await waitFor(()
=> 362 + t?.events.messages.
some((m
: any)
=> m.customType
=== "superpowers"),
364 + const message
= t.events.messages.
find(
365 + (m
: any)
=> m.customType
=== "superpowers",
336 367 const url
= message.details.url;
337 368 expect(
await fetch(url).
then((r)
=> r.
status)).
toBe(
200);
338 - await t.session.extensionRunner.
emit({ type:
"session_shutdown", reason:
"quit" });
369 + await t.session.extensionRunner.
emit({
370 + type:
"session_shutdown",
339 373 for (
let i
= 0; i
< 40; i
++) {
341 375 await fetch(url);
347 - expect.
unreachable(
"visual server still accepted requests after shutdown");
381 + expect.
unreachable(
382 + "visual server still accepted requests after shutdown",
349 385 if (prevNoOpen
=== undefined)
delete process.
env.PI_SUPERPOWERS_NO_OPEN;
350 386 else process.
env.PI_SUPERPOWERS_NO_OPEN
= prevNoOpen;
394 430 task: {
id:
"sp-7", childSession },
396 - expect(child.messages.
at(
-1)?.
content).
toContain(
"Superpowers takeover: sp-7");
397 - expect(child.messages.
at(
-1)?.
content).
toContain(
"/superpowers return <summary>");
432 + expect(child.messages.
at(
-1)?.
content).
toContain(
433 + "Superpowers takeover: sp-7",
435 + expect(child.messages.
at(
-1)?.
content).
toContain(
436 + "/superpowers return <summary>",
399 439 await command().
handler(
"return done", child.ctx);
400 440 expect(parent.entries.
at(
-1)?.
data).
toMatchObject({
406 - expect(parent.messages.
at(
-1)?.
content).
toContain(
"Superpowers return sp-7");
446 + expect(parent.messages.
at(
-1)?.
content).
toContain(
447 + "Superpowers return sp-7",
407 449 expect(parent.messages.
at(
-1)?.
content).
toContain(
"done");
408 450 expect(parent.messages.
at(
-1)?.
content).
toContain(childSession);
extensions/superpowers/__tests__/helpers.test.ts
Modified 1 -import { describe, expect, it }
from "vitest";
2 -import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync }
from "node:fs";
3 9 import os
from "node:os";
4 10 import path
from "node:path";
11 +import { describe, expect, it }
from "vitest";
5 12 import { __test }
from "../index.ts";
6 13 import { startVisualServer }
from "../visual";
10 17 expect(__test.
platformStateDir(
"linux", {},
"/home/me")).
toBe(
11 18 "/home/me/.local/state/pi",
13 - expect(__test.
platformStateDir(
"linux", { XDG_STATE_HOME:
"/state" },
"/home/me")).
toBe(
"/state/pi");
21 + __test.
platformStateDir(
23 + { XDG_STATE_HOME:
"/state" },
26 + ).
toBe(
"/state/pi");
14 27 expect(__test.
platformStateDir(
"darwin", {},
"/Users/me")).
toBe(
15 28 "/Users/me/Library/Application Support/pi",
23 36 ).
toBe(
"C:\\Users\\me\\AppData\\Local\\pi");
24 - expect(__test.
dir(
"/tmp/project")).
toContain(path.
join(
"pi",
"superpowers"));
37 + expect(__test.
dir(
"/tmp/project")).
toContain(
38 + path.
join(
"pi",
"superpowers"),
27 42 it(
"ships workflow prompts and skills", ()
=> {
61 76 expect(skill).
toContain(
"Hard gate");
62 - expect(skill).
toContain(
"Write spec to `docs/superpowers/specs/YYYY-MM-DD-<topic>-design.md`");
77 + expect(skill).
toContain(
78 + "Write spec to `docs/superpowers/specs/YYYY-MM-DD-<topic>-design.md`",
63 80 expect(skill).
toContain(
"After approval, hand off only to `writing-plans`");
99 116 it(
"strict prompt protects brainstorming before planning", ()
=> {
100 - const source
= readFileSync(path.
resolve(
import.
meta.
dir,
"../index.ts"),
"utf8");
101 - expect(source).
toContain(
"Use brainstorming first for vague goals, UX/UI work");
102 - expect(source).
toContain(
"Do not use writing-plans unless an approved design/spec already exists");
117 + const source
= readFileSync(
118 + path.
resolve(
import.
meta.
dir,
"../index.ts"),
121 + expect(source).
toContain(
122 + "Use brainstorming first for vague goals, UX/UI work",
124 + expect(source).
toContain(
125 + "Do not use writing-plans unless an approved design/spec already exists",
105 129 it(
"skills retain vital upstream workflow gates", ()
=> {
106 130 const skill = (name
: string)
=> 107 - readFileSync(path.
resolve(
import.
meta.
dir,
`../skills/${name}/SKILL.md`),
"utf8");
108 - expect(
skill(
"test-driven-development")).
toContain(
"No production code without a failing test first");
132 + path.
resolve(
import.
meta.
dir,
`../skills/${name}/SKILL.md`),
135 + expect(
skill(
"test-driven-development")).
toContain(
136 + "No production code without a failing test first",
109 138 expect(
skill(
"systematic-debugging")).
toContain(
"root-cause evidence");
110 - expect(
skill(
"verification-before-completion")).
toContain(
"Evidence before claims");
139 + expect(
skill(
"verification-before-completion")).
toContain(
140 + "Evidence before claims",
111 142 expect(
skill(
"writing-plans")).
toContain(
"No `TODO`/`TBD`");
112 - expect(
skill(
"receiving-code-review")).
toContain(
"Verify each finding against the codebase");
113 - expect(
skill(
"using-git-worktrees")).
toContain(
"If already in a linked worktree");
143 + expect(
skill(
"receiving-code-review")).
toContain(
144 + "Verify each finding against the codebase",
146 + expect(
skill(
"using-git-worktrees")).
toContain(
147 + "If already in a linked worktree",
116 151 it(
"review workflow includes deslop and compression passes", ()
=> {
extensions/superpowers/index.ts
Modified 1 +import { execSync }
from "node:child_process";
1 2 import { createHash }
from "node:crypto";
11 -import { execSync }
from "node:child_process";
12 12 import os
from "node:os";
13 13 import path
from "node:path";
14 14 import { fileURLToPath }
from "node:url";
20 20 type ExtensionCommandContext,
21 21 type ExtensionContext,
26 26 } from
"@earendil-works/pi-coding-agent";
27 27 import { openBrowser, startVisualServer, type VisualSession }
from "./visual";
145 145 const paths
= platform
=== "win32" ? path.win32
: path.posix;
146 146 if (platform
=== "win32")
147 - return paths.
join(env.LOCALAPPDATA
?? paths.
join(home,
"AppData",
"Local"),
"pi");
148 + env.LOCALAPPDATA
?? paths.
join(home,
"AppData",
"Local"),
148 151 if (env.XDG_STATE_HOME)
return paths.
join(env.XDG_STATE_HOME,
"pi");
149 - if (platform
=== "darwin")
return paths.
join(home,
"Library",
"Application Support",
"pi");
152 + if (platform
=== "darwin")
153 + return paths.
join(home,
"Library",
"Application Support",
"pi");
150 154 return paths.
join(home,
".local",
"state",
"pi");
152 156 function hashProjectRoot(cwd
: string) {
153 157 return createHash(
"sha256").
update(path.
resolve(cwd)).
digest(
"hex");
155 -const dir = (cwd
: string)
=> path.
join(
platformStateDir(),
"superpowers",
hashProjectRoot(cwd));
159 +const dir = (cwd
: string)
=> 160 + path.
join(
platformStateDir(),
"superpowers",
hashProjectRoot(cwd));
156 161 const tasksFile = (cwd
: string)
=> path.
join(
dir(cwd),
"tasks.json");
157 162 const sessionsDir = (cwd
: string)
=> path.
join(
dir(cwd),
"sessions");
158 -const ensure = (cwd
: string)
=> mkdirSync(
sessionsDir(cwd), { recursive:
true });
163 +const ensure = (cwd
: string)
=> 164 + mkdirSync(
sessionsDir(cwd), { recursive:
true });
159 165 const text = (x
: unknown)
: string => 160 166 typeof x
=== "string" 243 249 const message
= uiStatusText(ctx.cwd);
244 250 if (
hasFooter()
&& api) {
245 251 (ctx.ui
as any).
setStatus?.(STATUS_ID,
undefined);
246 - const runningTask
= Object.
values(
readTasks(ctx.cwd)).
find((t)
=> t.
status === "running");
252 + const runningTask
= Object.
values(
readTasks(ctx.cwd)).
find(
253 + (t)
=> t.
status === "running",
247 255 const footerColor
= runningTask
248 256 ? taskAccent(runningTask.agent, runningTask.accent)
249 - : (active
? "accent" : "muted")
as ThemeColor;
257 + : ((active
? "accent" : "muted")
as ThemeColor);
251 259 "footer:segment",
273 281 const AGENT_SHORT
: Record<
string,
string>
= {
274 282 "requesting-code-review":
"review",
275 283 "receiving-code-review":
"fix",
276 - "brainstorming":
"design",
284 + brainstorming:
"design",
277 285 "writing-plans":
"plan",
278 286 "executing-plans":
"exec",
279 287 "dispatching-parallel-agents":
"parallel",
306 314 return ALIAS_ACCENT[AGENT_SHORT[agent]
?? agent]
?? "accent";
308 316 const THEMED_COLORS
: Set<
string>
= new Set([
309 - "accent",
"border",
"borderAccent",
"borderMuted",
"success",
"error",
310 - "warning",
"muted",
"dim",
"text",
"thinkingText",
"userMessageText",
311 - "customMessageText",
"customMessageLabel",
"toolTitle",
"toolOutput",
312 - "mdHeading",
"mdLink",
"mdLinkUrl",
"mdCode",
"mdCodeBlock",
313 - "mdCodeBlockBorder",
"mdQuote",
"mdQuoteBorder",
"mdHr",
"mdListBullet",
314 - "toolDiffAdded",
"toolDiffRemoved",
"toolDiffContext",
"syntaxComment",
315 - "syntaxKeyword",
"syntaxFunction",
"syntaxVariable",
"syntaxString",
316 - "syntaxNumber",
"syntaxType",
"syntaxOperator",
"syntaxPunctuation",
317 - "thinkingOff",
"thinkingMinimal",
"thinkingLow",
"thinkingMedium",
318 - "thinkingHigh",
"thinkingXhigh",
"bashMode",
329 + "customMessageText",
330 + "customMessageLabel",
338 + "mdCodeBlockBorder",
354 + "syntaxPunctuation",
320 363 function elapsedLive(start
: string) {
321 364 const a
= Date.
parse(start);
326 369 function compactTaskLine(t
: Task) {
327 370 const icon
= STATUS_ICONS[t.
status]
?? "·";
328 371 const name
= AGENT_SHORT[t.agent]
?? t.agent;
329 - const time
= t.
status === "running" ? elapsedLive(t.startedAt)
: elapsed(t.startedAt, t.updatedAt);
373 + t.
status === "running" 374 + ? elapsedLive(t.startedAt)
375 + : elapsed(t.startedAt, t.updatedAt);
330 376 const tools
= toolCount(t);
331 377 return `${icon} ${t.id} ${name} ${time}${tools ? ` · ${tools} tools` : ""}`;
346 392 function summaryLine(t
: Task) {
347 393 const icon
= STATUS_ICONS[t.
status]
?? "·";
348 394 const name
= AGENT_SHORT[t.agent]
?? t.agent;
349 - const time
= t.
status === "running" ? elapsedLive(t.startedAt)
: elapsed(t.startedAt, t.updatedAt);
396 + t.
status === "running" 397 + ? elapsedLive(t.startedAt)
398 + : elapsed(t.startedAt, t.updatedAt);
350 399 const tools
= toolCount(t);
351 400 const tail
= firstLine(t.result
?? t.log.
at(
-1));
352 401 const parts
= [
`${icon} ${t.id}`, name, time];
357 406 function taskDetails(t
: Task) {
358 407 const icon
= STATUS_ICONS[t.
status]
?? "·";
359 - const time
= t.
status === "running" ? elapsedLive(t.startedAt)
: elapsed(t.startedAt, t.updatedAt);
409 + t.
status === "running" 410 + ? elapsedLive(t.startedAt)
411 + : elapsed(t.startedAt, t.updatedAt);
360 412 const tools
= toolCount(t);
361 413 const name
= AGENT_SHORT[t.agent]
?? t.agent;
362 414 const tail
= firstLine(t.result
?? t.log.
at(
-1));
391 443 const th
= ctx.ui.theme;
393 - th.
fg(
"dim",
`${running.length} worker${running.length > 1 ? "s" : ""} running`),
394 - ...running.
map((t)
=> th.
fg(
taskAccent(t.agent, t.accent),
compactTaskLine(t))),
447 + `${running.length} worker${running.length > 1 ? "s" : ""} running`,
449 + ...running.
map((t)
=> 450 + th.
fg(
taskAccent(t.agent, t.accent),
compactTaskLine(t)),
396 453 (ctx.ui
as any).
setWidget?.(WIDGET, lines);
503 560 const [provider,
...id]
= s?.
split(
"/")
?? [];
504 561 if (provider
&& id.
length) {
505 562 const m
= getModel(provider, id.
join(
"/"));
506 - if (m
&& m.provider
&& m.
id)
return m;
563 + if (m?.provider
&& m.
id)
return m;
508 565 return fallback
?? getModel(
"openai",
"gpt-4o");
555 -type GitLayout = { type
: "git"; layout
: "standard" | "bare"; gitDir
: string; root
: string };
614 + layout
: "standard" | "bare";
557 619 type RepoType = "jj" | GitLayout;
561 623 if (
existsSync(path.
join(cwd,
".jj")))
return "jj";
563 - const commonDir
= execSync(
"git rev-parse --path-format=absolute --git-common-dir", {
566 - stdio: [
"pipe",
"pipe",
"ignore"],
625 + const commonDir
= execSync(
626 + "git rev-parse --path-format=absolute --git-common-dir",
630 + stdio: [
"pipe",
"pipe",
"ignore"],
569 634 execSync(
"git config --bool core.bare", {
575 640 .
toLowerCase()
=== "true";
577 - return { type:
"git", layout:
"bare", gitDir: commonDir, root: path.
dirname(commonDir) };
646 + root: path.
dirname(commonDir),
579 - return { type:
"git", layout:
"standard", gitDir: commonDir, root: path.
dirname(commonDir) };
651 + layout:
"standard",
653 + root: path.
dirname(commonDir),
600 675 const branch
= `superpowers-${id}`;
601 676 if (repo.layout
=== "bare") {
602 677 const wtPath
= path.
join(repo.root, id);
603 - await pi.
exec(
"git", [
"-C", repo.gitDir,
"worktree",
"add",
"-b", branch, wtPath,
"HEAD"]);
604 - return { type:
"git-bare", path: wtPath, branch, gitDir: repo.gitDir, root: repo.root };
678 + await pi.
exec(
"git", [
692 + gitDir: repo.gitDir,
607 697 const wtPath
= path.
join(cwd,
".git",
`wt-${id}`);
617 707 await pi.
exec(
"jj", [
"workspace",
"forget", isolate.workspaceName
!]);
618 708 rmdirSync(isolate.path, { recursive:
true });
619 709 }
else if (isolate.
type === "git-bare") {
620 - await pi.
exec(
"git", [
"-C", isolate.gitDir
!,
"worktree",
"remove",
"--force", isolate.path]);
621 - await pi.
exec(
"git", [
"-C", isolate.gitDir
!,
"branch",
"-D", isolate.branch
!]);
710 + await pi.
exec(
"git", [
718 + await pi.
exec(
"git", [
623 726 await pi.
exec(
"git", [
"worktree",
"remove",
"--force", isolate.path]);
624 727 await pi.
exec(
"git", [
"branch",
"-D", isolate.branch
!]);
711 814 const agentModel
= modelFrom(requested, model);
713 816 const [provider,
...id]
= requested.
split(
"/");
714 - const direct
= provider
&& id.
length ? getModel(provider, id.
join(
"/"))
: null;
715 - if (
!direct
|| !direct.provider) {
716 - notify(ctx,
`warn: model "${requested}" not found, using fallback`,
"warning");
818 + provider
&& id.
length ? getModel(provider, id.
join(
"/"))
: null;
819 + if (
!direct?.provider) {
822 + `warn: model "${requested}" not found, using fallback`,
719 827 const created
= await createAgentSession({
901 1009 const key
= id.
trim();
903 1011 const t
= tasks[key];
904 - notify(ctx, t
? taskDetails(t)
: `no such task: ${key}`, t
? "info" : "error");
1014 + t
? taskDetails(t)
: `no such task: ${key}`,
1015 + t
? "info" : "error",
943 1055 "- When done with visual decisions, write a waiting screen: Continuing in terminal…",
944 1056 "- Ask whether to leave the browser open for inspection or stop it.",
946 - await Promise.
resolve(pi.
sendMessage(
953 - contentDir: session.contentDir,
954 - eventsFile: session.eventsFile,
1058 + await Promise.
resolve(
1063 + content: agentMsg,
1066 + contentDir: session.contentDir,
1067 + eventsFile: session.eventsFile,
957 - { triggerTurn:
false },
1070 + { triggerTurn:
false },
961 -async function visualCommand(args
: string, ctx
: ExtensionCommandContext, pi
: ExtensionAPI) {
1075 +async function visualCommand(
1077 + ctx
: ExtensionCommandContext,
962 1080 const [sub
= "status"]
= args.
trim().
split(
/\s+/);
963 1081 if (sub
=== "start") {
965 - notify(ctx,
`visual already live: ${visual.url}\ncontent: ${visual.contentDir}\nevents file: ${visual.eventsFile}`);
1085 + `visual already live: ${visual.url}\ncontent: ${visual.contentDir}\nevents file: ${visual.eventsFile}`,
966 1087 await announceVisualSession(pi, visual);
973 1094 `visual live: ${visual.url}`,
974 1095 `content: ${visual.contentDir}`,
975 1096 `events file: ${visual.eventsFile}`,
976 - opened.ok
? `opened: ${opened.command}` : `open manually: ${opened.error}`,
1098 + ? `opened: ${opened.command}` 1099 + : `open manually: ${opened.error}`,
978 1101 notify(ctx, msg, opened.ok
? "info" : "warning");
979 1102 await announceVisualSession(pi, visual);
990 1113 if (sub
=== "events") {
991 1114 if (
!visual)
return notify(ctx,
"no visual session",
"warning");
992 - const events
= existsSync(visual.eventsFile)
? readFileSync(visual.eventsFile,
"utf8")
: "";
993 - if (ctx.hasUI)
await ctx.ui.
editor(
"superpowers visual events", events
|| "no events");
1115 + const events
= existsSync(visual.eventsFile)
1116 + ? readFileSync(visual.eventsFile,
"utf8")
1119 + await ctx.ui.
editor(
"superpowers visual events", events
|| "no events");
994 1120 else notify(ctx, events
|| "no events");
997 - if (
!visual)
return notify(ctx,
"no visual session. use /superpowers visual start",
"warning");
998 - notify(ctx,
`visual live: ${visual.url}\ncontent: ${visual.contentDir}\nevents file: ${visual.eventsFile}`);
1126 + "no visual session. use /superpowers visual start",
1131 + `visual live: ${visual.url}\ncontent: ${visual.contentDir}\nevents file: ${visual.eventsFile}`,
1001 1135 function help(ctx
: ExtensionCommandContext) {
extensions/superpowers/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-superpowers",
17 - "peerDependencies": {
18 - "@earendil-works/pi-ai":
"*",
19 - "@earendil-works/pi-coding-agent":
"*" 21 - "devDependencies": {
22 - "@marcfargas/pi-test-harness":
"^0.6.1" 25 - "description":
"Background subagents and takeover sessions for Pi.",
2 + "name":
"@bugabinga/pi-ext-superpowers",
17 + "peerDependencies": {
18 + "@earendil-works/pi-ai":
"*",
19 + "@earendil-works/pi-coding-agent":
"*" 21 + "devDependencies": {
22 + "@marcfargas/pi-test-harness":
"^0.6.1" 25 + "description":
"Background subagents and takeover sessions for Pi.",
extensions/superpowers/visual.ts
Modified 1 1 import { spawn }
from "node:child_process";
2 2 import { randomBytes, randomUUID }
from "node:crypto";
3 -import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync, appendFileSync }
from "node:fs";
4 -import { createServer, type IncomingMessage, type Server, type ServerResponse }
from "node:http";
14 + type IncomingMessage,
16 + type ServerResponse,
5 18 import path
from "node:path";
7 20 export type VisualSession = {
22 35 const COOKIE
= "pi_superpowers_visual";
23 36 const BODY_LIMIT
= 64 * 1024;
25 -export async function startVisualServer({ root, preferredPort
= 47718 }
: StartVisualOptions)
: Promise<
VisualSession> {
38 +export async function startVisualServer({
40 + preferredPort
= 47718,
41 +}
: StartVisualOptions)
: Promise<
VisualSession> {
26 42 const id
= randomUUID();
27 43 const token
= randomBytes(
32).
toString(
"base64url");
28 44 const sessionRoot
= path.
join(
root,
"visual", id);
45 61 void (
async ()
=> {
47 63 const url
= new URL(req.url
?? "/",
"http://127.0.0.1");
48 - if (
!authorized(req, url))
return json(res,
401, { error:
"unauthorized" });
64 + if (
!authorized(req, url))
65 + return json(res,
401, { error:
"unauthorized" });
49 66 if (url.
pathname === "/" && req.
method === "GET") {
50 - res.
setHeader(
"Set-Cookie",
`${COOKIE}=${token}; SameSite=Strict; Path=/`);
51 - return html(res,
frame(
latestFragment(contentDir),
latestStamp(contentDir)));
69 + `${COOKIE}=${token}; SameSite=Strict; Path=/`,
73 + frame(
latestFragment(contentDir),
latestStamp(contentDir)),
53 76 if (url.
pathname === "/api/latest" && req.
method === "GET")
54 77 return json(res,
200,
latestStamp(contentDir));
55 78 if (url.
pathname === "/api/events" && req.
method === "GET")
56 - return text(res,
existsSync(eventsFile)
? readFileSync(eventsFile,
"utf8")
: "");
81 + existsSync(eventsFile)
? readFileSync(eventsFile,
"utf8")
: "",
57 83 if (url.
pathname === "/api/event" && req.
method === "POST") {
58 84 const body
= await readBody(req);
59 85 const event
= JSON.
parse(body
|| "{}");
60 - appendFileSync(eventsFile,
`${JSON.stringify({ ...event, timestamp: Date.now() })}\n`);
88 + `${JSON.stringify({ ...event, timestamp: Date.now() })}\n`,
61 90 return json(res,
200, { ok:
true });
63 92 return json(res,
404, { error:
"not found" });
65 - return json(res,
500, { error: err
instanceof Error ? err.message
: String(err) });
94 + return json(res,
500, {
95 + error: err
instanceof Error ? err.message
: String(err),
69 100 await listen(server, preferredPort);
70 101 const address
= server.
address();
71 - if (
!address
|| typeof address
=== "string")
throw new Error(
"visual server failed to bind");
102 + if (
!address
|| typeof address
=== "string")
103 + throw new Error(
"visual server failed to bind");
72 104 const url
= `http://127.0.0.1:${address.port}/?token=${encodeURIComponent(token)}`;
73 105 const info
= { id, url, contentDir, stateDir, eventsFile };
74 106 writeFileSync(serverInfoFile,
`${JSON.stringify(info, null, "\t")}\n`);
75 107 return {
...info, serverInfoFile,
close: ()
=> server.
close() };
78 -export async function openBrowser(url
: string)
: Promise<{ ok
: boolean; command
?: string; error
?: string }> {
110 +export async function openBrowser(
112 +)
: Promise<{ ok
: boolean; command
?: string; error
?: string }> {
79 113 if (
process.
env.NODE_ENV
=== "test" || process.
env.PI_SUPERPOWERS_NO_OPEN)
80 114 return { ok:
false, error:
"browser opener disabled" };
81 115 for (
const candidate
of openerCandidates(url)) {
85 119 return { ok:
false, error:
"no browser opener found" };
88 -function openerCandidates(url
: string)
: Array<{ command
: string; args
: string[] }> {
89 - if (
process.
env.TERMUX_VERSION)
return [{ command:
"termux-open-url", args: [url] }];
122 +function openerCandidates(
124 +)
: Array<{ command
: string; args
: string[] }> {
125 + if (
process.
env.TERMUX_VERSION)
126 + return [{ command:
"termux-open-url", args: [url] }];
90 127 if (
process.
platform === "darwin")
return [{ command:
"open", args: [url] }];
91 - if (
process.
platform === "win32")
return [{ command:
"cmd.exe", args: [
"/c",
"start",
"", url] }];
128 + if (
process.
platform === "win32")
129 + return [{ command:
"cmd.exe", args: [
"/c",
"start",
"", url] }];
93 131 { command:
"xdg-open", args: [url] },
94 132 { command:
"wslview", args: [url] },
99 -function trySpawn(command
: string, args
: string[])
: Promise<{ ok
: boolean; error
?: string }> {
140 +)
: Promise<{ ok
: boolean; error
?: string }> {
100 141 return new Promise((resolve)
=> {
101 142 const child
= spawn(command, args, { detached:
true, stdio:
"ignore" });
102 143 let settled
= false;
132 173 function latestFiles(contentDir
: string) {
133 174 return readdirSync(contentDir)
134 175 .
filter((f)
=> f.
endsWith(
".html"))
135 - .
map((name)
=> ({ name, path: path.
join(contentDir, name), mtime:
statSync(path.
join(contentDir, name)).mtimeMs }))
178 + path: path.
join(contentDir, name),
179 + mtime:
statSync(path.
join(contentDir, name)).mtimeMs,
136 181 .
sort((a, b)
=> b.mtime
- a.mtime
|| b.
name.
localeCompare(a.
name));
153 198 function frame(fragment
: string, stamp
: { name
: string; mtime
: number }) {
154 - const body
= /<html[\s>]/i.
test(fragment)
|| /<!doctype/i.
test(fragment)
? fragment
: `<main id="main">${fragment}</main>`;
200 + /<html[\s>]/i.
test(fragment)
|| /<!doctype/i.
test(fragment)
202 + : `<main id="main">${fragment}</main>`;
155 203 return `<!doctype html> 156 204 <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"> 157 205 <title>Pi Superpowers Visual Brainstorming</title><link rel="icon" href="data:,"><style>${css()}</style></head><body data-stamp="${escapeAttr(JSON.stringify(stamp))}"> 172 220 for await (
const chunk
of req) {
173 221 body
+= String(chunk);
174 - if (
Buffer.
byteLength(body,
"utf8")
> BODY_LIMIT)
throw new Error(
"request body too large");
222 + if (
Buffer.
byteLength(body,
"utf8")
> BODY_LIMIT)
223 + throw new Error(
"request body too large");
195 244 function escapeHtml(s
: string) {
196 - return s.
replaceAll(
"&",
"&").
replaceAll(
"<",
"<").
replaceAll(
">",
">");
246 + .
replaceAll(
"&",
"&")
247 + .
replaceAll(
"<",
"<")
248 + .
replaceAll(
">",
">");
198 250 function escapeAttr(s
: string) {
199 251 return escapeHtml(s).
replaceAll(
'"',
""");
extensions/terminal-notifier/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"terminal-notifier pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/terminal-notifier/focus.ts
Modified 17 17 const G
= globalThis
as unknown as { __bugabinga_pi_focus
?: FocusState };
18 -const state
= (G.__bugabinga_pi_focus
??= {
18 +G.__bugabinga_pi_focus
??= {
21 21 listeners:
new Set(),
24 +const state
= G.__bugabinga_pi_focus;
25 26 function notify(next
: boolean)
: void {
26 27 if (next
=== state.focused)
return;
extensions/terminal-notifier/index.ts
Modified146 146 function notifyWindows(title
: string, body
: string)
: void {
147 - const { execFile }
= require(
"child_process");
147 + const { execFile }
= require(
"node:child_process");
148 148 execFile(
"powershell.exe", [
195 - const onFocusChange = (isFocused
: boolean)
=> {
195 + const onFocusChange = (_isFocused
: boolean)
=> {
extensions/terminal-notifier/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-terminal-notifier",
5 - "peerDependencies": {
6 - "@earendil-works/pi-coding-agent":
"*" 9 - "description":
"Terminal notification bridge for Pi.",
14 - "devDependencies": {
15 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-terminal-notifier",
5 + "peerDependencies": {
6 + "@earendil-works/pi-coding-agent":
"*" 9 + "description":
"Terminal notification bridge for Pi.",
14 + "devDependencies": {
15 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/terminal-signals/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"terminal-signals pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/terminal-signals/focus.ts
Modified 17 17 const G
= globalThis
as unknown as { __bugabinga_pi_focus
?: FocusState };
18 -const state
= (G.__bugabinga_pi_focus
??= {
18 +G.__bugabinga_pi_focus
??= {
21 21 listeners:
new Set(),
24 +const state
= G.__bugabinga_pi_focus;
25 26 function notify(next
: boolean)
: void {
26 27 if (next
=== state.focused)
return;
extensions/terminal-signals/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-terminal-signals",
5 - "peerDependencies": {
6 - "@earendil-works/pi-coding-agent":
"*" 9 - "description":
"Terminal lifecycle signals for Pi.",
14 - "devDependencies": {
15 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-terminal-signals",
5 + "peerDependencies": {
6 + "@earendil-works/pi-coding-agent":
"*" 9 + "description":
"Terminal lifecycle signals for Pi.",
14 + "devDependencies": {
15 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/terse/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"terse pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/terse/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-terse",
5 - "peerDependencies": {
6 - "@earendil-works/pi-coding-agent":
"*" 9 - "description":
"Terse response protocol injector for Pi.",
14 - "devDependencies": {
15 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-terse",
5 + "peerDependencies": {
6 + "@earendil-works/pi-coding-agent":
"*" 9 + "description":
"Terse response protocol injector for Pi.",
14 + "devDependencies": {
15 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/tldr/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"tldr pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/tldr/__tests__/tldr.test.ts
Modified210 210 cacheRetention:
"none",
212 - const factory
= ctx.widgets[
"tldr"]
as (tui
: unknown, theme
: unknown)
=> {
render(width
: number)
: string[] };
212 + const factory
= ctx.widgets[
"tldr"]
as (
215 + )
=> {
render(width
: number)
: string[] };
213 216 expect(
typeof factory).
toBe(
"function");
214 217 const component
= factory({}, {});
215 218 expect(component.
render(
80)[
1]).
toContain(
"Reading package metadata.");
237 240 scheduler.
flush();
239 242 expect(calls).
toBe(
1);
240 - const factory
= ctx.widgets[
"tldr"]
as (tui
: unknown, theme
: unknown)
=> {
render(width
: number)
: string[] };
243 + const factory
= ctx.widgets[
"tldr"]
as (
246 + )
=> {
render(width
: number)
: string[] };
241 247 const component
= factory({}, {});
242 248 expect(component.
render(
80)[
1]).
toContain(
"Update 1.");
extensions/tldr/index.ts
Modified203 203 function showTldr(ctx
: ExtensionContext, text
: string)
: void {
204 204 if (
!ctx.hasUI)
return;
205 205 const safe
= sanitizeTldrText(text);
206 - if (
!safe)
return clearTldr(ctx);
207 210 ctx.ui.
setWidget(WIDGET_KEY, (_tui, _theme)
=> ({
208 211 render(width
: number) {
209 212 return boxLines(safe, width);
509 512 if (this.inFlight)
return;
510 513 const job
= this.queue.
shift();
511 514 if (
!job)
return;
512 - if (job.runId
!== this.runId
|| job.
index <= this.latestAcceptedIndex)
513 - return this.
pump(ctx);
515 + if (job.runId
!== this.runId
|| job.
index <= this.latestAcceptedIndex) {
514 519 this.inFlight
= { index: job.
index, runId: job.runId };
515 520 void this.
generateCheckpoint(ctx, job);
extensions/tldr/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-tldr",
5 - "peerDependencies": {
6 - "@earendil-works/pi-ai":
"*",
7 - "@earendil-works/pi-coding-agent":
"*",
8 - "@earendil-works/pi-tui":
"*" 11 - "description":
"Live TLDR widget for Pi.",
16 - "devDependencies": {
17 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-tldr",
5 + "peerDependencies": {
6 + "@earendil-works/pi-ai":
"*",
7 + "@earendil-works/pi-coding-agent":
"*",
8 + "@earendil-works/pi-tui":
"*" 11 + "description":
"Live TLDR widget for Pi.",
16 + "devDependencies": {
17 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/tps/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"tps pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/tps/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-tps",
5 - "peerDependencies": {
6 - "@earendil-works/pi-coding-agent":
"*" 9 - "description":
"Tokens-per-second footer segment for Pi.",
14 - "devDependencies": {
15 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-tps",
5 + "peerDependencies": {
6 + "@earendil-works/pi-coding-agent":
"*" 9 + "description":
"Tokens-per-second footer segment for Pi.",
14 + "devDependencies": {
15 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/usage/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"usage pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/usage/index.ts
Modified524 524 const cur
= sorted[i]
!;
526 526 right
< sorted.
length && 527 - sorted[right]
!.timestamp
<= cur.timestamp
+ PARALLEL_WINDOW_MS
527 + sorted[right]?.timestamp
<= cur.timestamp
+ PARALLEL_WINDOW_MS
529 - const sid
= sorted[right]
!.sessionId;
529 + const sid
= sorted[right]?.sessionId;
530 530 const n
= (sidCount.
get(sid)
?? 0)
+ 1;
531 531 sidCount.
set(sid, n);
532 532 if (n
=== 1) unique
++;
537 - sorted[left]
!.timestamp
< cur.timestamp
- PARALLEL_WINDOW_MS
537 + sorted[left]?.timestamp
< cur.timestamp
- PARALLEL_WINDOW_MS
539 - const sid
= sorted[left]
!.sessionId;
539 + const sid
= sorted[left]?.sessionId;
540 540 const n
= (sidCount.
get(sid)
?? 0)
- 1;
542 542 sidCount.
delete(sid);
extensions/usage/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-usage",
5 - "peerDependencies": {
6 - "@earendil-works/pi-coding-agent":
"*",
7 - "@earendil-works/pi-tui":
"*" 10 - "description":
"Local usage statistics dashboard for Pi.",
15 - "devDependencies": {
16 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-usage",
5 + "peerDependencies": {
6 + "@earendil-works/pi-coding-agent":
"*",
7 + "@earendil-works/pi-tui":
"*" 10 + "description":
"Local usage statistics dashboard for Pi.",
15 + "devDependencies": {
16 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/vcs-status/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"vcs-status pi-test-harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/vcs-status/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-vcs-status",
5 - "peerDependencies": {
6 - "@earendil-works/pi-coding-agent":
"*" 9 - "description":
"VCS workspace telemetry for Pi.",
14 - "devDependencies": {
15 - "@marcfargas/pi-test-harness":
"^0.6.1" 2 + "name":
"@bugabinga/pi-ext-vcs-status",
5 + "peerDependencies": {
6 + "@earendil-works/pi-coding-agent":
"*" 9 + "description":
"VCS workspace telemetry for Pi.",
14 + "devDependencies": {
15 + "@marcfargas/pi-test-harness":
"^0.6.1" extensions/web/__tests__/harness.test.ts
Modified 1 -import { afterEach, describe, expect, it }
from "vitest";
2 1 import path
from "node:path";
6 5 }
from "@marcfargas/pi-test-harness";
6 +import { afterEach, describe, expect, it }
from "vitest";
8 8 describe(
"web extension harness", ()
=> {
9 9 let t
: TestSession | undefined;
extensions/web/ddg.ts
Modified106 106 RESULT_BLOCK_RE.
lastIndex = 0;
108 + let blockMatch
: RegExpExecArray | null;
109 110 while ((blockMatch
= RESULT_BLOCK_RE.
exec(html))
!== null) {
110 111 diagnostics.rawBlockCount
++;
111 112 const block
= blockMatch[
1];
extensions/web/extract.ts
Modified 59 59 /<(\w+)([^>]*style=["'])([^"']*)(["'][^>]*)>([\s\S]*?)<\/\1>/gi,
60 - (_match, tag, _before, styleVal, _after, _content)
=> {
60 + (_match, _tag, _before, styleVal, _after, _content)
=> {
61 61 return VISUAL_HIDE_PATTERNS.
some((p)
=> p.
test(styleVal))
? "" : _match;
extensions/web/index.ts
Modified 288 288 const raw
= await spawnToText(
"identify", [
"-verbose", filePath]);
290 290 format: raw.
match(
/Format:\s*(\S+)/i)?.[
1]
?? "",
291 - width:
parseInt(raw.
match(
/Geometry:\s*(\d+)x(\d+)/i)?.[
1]
?? "0"),
292 - height:
parseInt(raw.
match(
/Geometry:\s*(\d+)x(\d+)/i)?.[
2]
?? "0"),
291 + width:
parseInt(raw.
match(
/Geometry:\s*(\d+)x(\d+)/i)?.[
1]
?? "0",
10),
292 + height:
parseInt(raw.
match(
/Geometry:\s*(\d+)x(\d+)/i)?.[
2]
?? "0",
10),
293 293 colorspace: raw.
match(
/Colorspace:\s*(\S+)/i)?.[
1]
?? "",
294 294 depth: raw.
match(
/Depth:\s*(\S+)/i)?.[
1]
?? "",
295 295 fileSize: raw.
match(
/Filesize:\s*(\S+)/i)?.[
1]
?? "",
350 350 height: stream.
height,
351 351 formatName: fmt.format_name,
352 352 bitRate: fmt.bit_rate
353 - ? `${Math.round(parseInt(fmt.bit_rate) / 1000)}kbps` 353 + ? `${Math.round(parseInt(fmt.bit_rate, 10) / 1000)}kbps` extensions/web/package.json
Modified 2 - "name":
"@bugabinga/pi-ext-web",
6 - "peerDependencies": {
7 - "@earendil-works/pi-coding-agent":
"*",
8 - "@earendil-works/pi-tui":
"*",
11 - "devDependencies": {
12 - "@marcfargas/pi-test-harness":
"^0.6.1" 15 - "description":
"Web fetch, search, and image tools for Pi.",
2 + "name":
"@bugabinga/pi-ext-web",
6 + "peerDependencies": {
7 + "@earendil-works/pi-coding-agent":
"*",
8 + "@earendil-works/pi-tui":
"*",
11 + "devDependencies": {
12 + "@marcfargas/pi-test-harness":
"^0.6.1" 15 + "description":
"Web fetch, search, and image tools for Pi.",
package-lock.json
Modified 13 13 "devDependencies": {
14 + "@playwright/test":
"^1.60.0",
14 15 "typescript":
"^5.7.3",
3194 3195 "react-dom":
"^18.3.1 || ^19.0.0" 3198 + "node_modules/@playwright/test": {
3199 + "version":
"1.60.0",
3200 + "resolved":
"https://registry.npmjs.org/@playwright/test/-/test-1.60.0.tgz",
3201 + "integrity":
"sha512-O71yZIbAh/PxDMNGns37GHBIfrVkEVyn+AXyIa5dOTfb4/xNvRWV+Vv/NMbNCtODB/pO7vLlF2OTmMVLhmr7Ag==",
3203 + "license":
"Apache-2.0",
3205 + "playwright":
"1.60.0" 3208 + "playwright":
"cli.js" 3197 3214 "node_modules/@protobufjs/aspromise": {
3198 3215 "version":
"1.1.2",
3199 3216 "resolved":
"https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz",
5106 5123 "url":
"https://github.com/sponsors/jonschlinkert" 5126 + "node_modules/playwright": {
5127 + "version":
"1.60.0",
5128 + "resolved":
"https://registry.npmjs.org/playwright/-/playwright-1.60.0.tgz",
5129 + "integrity":
"sha512-hheHdokM8cdqCb0lcE3s+zT4t4W+vvjpGxsZlDnikarzx8tSzMebh3UiFtgqwFwnTnjYQcsyMF8ei2mCO/tpeA==",
5131 + "license":
"Apache-2.0",
5133 + "playwright-core":
"1.60.0" 5136 + "playwright":
"cli.js" 5141 + "optionalDependencies": {
5142 + "fsevents":
"2.3.2" 5145 + "node_modules/playwright-core": {
5146 + "version":
"1.60.0",
5147 + "resolved":
"https://registry.npmjs.org/playwright-core/-/playwright-core-1.60.0.tgz",
5148 + "integrity":
"sha512-9bW6zvX/m0lEbgTKJ6YppOKx8H3VOPBMOCFh2irXFOT4BbHgrx5hPjwJYLT40Lu+4qtD36qKc/Hn56StUW57IA==",
5150 + "license":
"Apache-2.0",
5152 + "playwright-core":
"cli.js" 5158 + "node_modules/playwright/node_modules/fsevents": {
5159 + "version":
"2.3.2",
5160 + "resolved":
"https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
5161 + "integrity":
"sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
5163 + "hasInstallScript":
true,
5170 + "node":
"^8.16.0 || ^10.6.0 || >=11.0.0" 5109 5173 "node_modules/postcss": {
5110 5174 "version":
"8.5.15",
5111 5175 "resolved":
"https://registry.npmjs.org/postcss/-/postcss-8.5.15.tgz",
12 12 "test:watch":
"vitest" 14 14 "devDependencies": {
15 + "@playwright/test":
"^1.60.0",
15 16 "typescript":
"^5.7.3",
skills/ascii-boxes/index.test.ts
Modified261 261 const single
= drawBox(
"T", { style:
"single" });
262 262 const double
= drawBox(
"T", { style:
"double" });
263 263 const bold
= drawBox(
"T", { style:
"bold" });
264 - expect(single.
includes(
"┌")
&& single.
includes(
"─")
&& single.
includes(
"│")).
toBe(
true);
265 - expect(double.
includes(
"╔")
&& double.
includes(
"═")
&& double.
includes(
"║")).
toBe(
true);
266 - expect(bold.
includes(
"┏")
&& bold.
includes(
"━")
&& bold.
includes(
"┃")).
toBe(
true);
265 + single.
includes(
"┌")
&& single.
includes(
"─")
&& single.
includes(
"│"),
268 + double.
includes(
"╔")
&& double.
includes(
"═")
&& double.
includes(
"║"),
270 + expect(bold.
includes(
"┏")
&& bold.
includes(
"━")
&& bold.
includes(
"┃")).
toBe(
267 273 expect(single).not.
toInclude(
"╔");
268 274 expect(double).not.
toInclude(
"┌");
skills/chrome-cdp/scripts/cdp.mjs
Modified 11 -import { spawn }
from "child_process";
11 +import { spawn }
from "node:child_process";
21 -import net
from "net";
22 -import { homedir, tmpdir, userInfo }
from "os";
23 -import { join, resolve }
from "path";
21 +import net
from "node:net";
22 +import { homedir, tmpdir, userInfo }
from "node:os";
23 +import { join, resolve }
from "node:path";
25 25 function envInt(name, fallback, { min
= 1 }
= {}) {
26 26 const raw
= process.
env[name];
580 580 async function clickXyStr(cdp, sid, x, y) {
581 581 const cx
= parseFloat(x);
582 582 const cy
= parseFloat(y);
583 - if (
isNaN(cx)
|| isNaN(cy))
583 + if (
Number.
isNaN(cx)
|| Number.
isNaN(cy))
584 584 throw new Error(
"x and y must be numbers (CSS pixels)");
585 585 const base
= { x: cx, y: cy, button:
"left", clickCount:
1, modifiers:
0 };
804 - args[
1]
? parseInt(args[
1])
: undefined, 804 + args[
1]
? parseInt(args[
1],
10)
: undefined, skills/firefox-bidi/scripts/bidi.integration.test.mjs
Modified 1 1 import assert from "node:assert/strict";
2 2 import { spawn } from "node:child_process";
3 -import { createHash, randomBytes } from "node:crypto";
3 +import { createHash } from "node:crypto";
4 4 import { existsSync } from "node:fs";
skills/firefox-bidi/scripts/bidi.mjs
Modified 8 -import { writeFileSync }
from "fs";
9 -import { join }
from "path";
8 +import { writeFileSync }
from "node:fs";
9 +import { join }
from "node:path";
skills/firefox-bidi/scripts/firefox-common.mjs
Modified 1 -import { spawn } from "child_process";
1 +import { spawn } from "node:child_process";
9 -import { createServer } from "net";
10 -import { tmpdir, userInfo } from "os";
11 -import { join, resolve } from "path";
9 +import { createServer } from "node:net";
10 +import { tmpdir, userInfo } from "node:os";
11 +import { join, resolve } from "node:path";
13 13 export const DEFAULT_FIREFOX_APP_ID = "pi-firefox-debug";
skills/firefox-bidi/scripts/rdp.mjs
Modified 8 -import { createConnection }
from "net";
9 -import { join }
from "path";
8 +import { createConnection }
from "node:net";
9 +import { join }
from "node:path";
19 + "exclude": [
"node_modules",
"**/*.test.ts"]
vitest.workspace.ts
Modified2 2 import { defineWorkspace }
from "vitest/config";
4 4 export default defineWorkspace(
6 + [
"extensions/*",
"skills/*"],