pi-ext
bugabingas pi extensions
owned by bugabinga
goal: add command autocomplete
42605ca1521a07d5f2db1d29c44ca720a345a52d
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
Browse filesCompare with HEAD
Changed files (7)
extensions/AGENTS.md
Modified56 56 - Publish is git-only. No npm registry flow.
61 +- Commands with subcommands must provide argument autocomplete.
61 65 - READMEs must be terse.
extensions/goal/README.md
Modified 11 +Subcommands autocomplete.
extensions/goal/__tests__/harness.test.ts
Modified181 181 {
event:
"start",
objective:
"finish feature",
turn:
1,
maxTurns:
20 },
182 182 {
event:
"verdict",
objective:
"finish feature",
turn:
1,
maxTurns:
20,
verdict: {
done:
true,
blocked:
false,
reason:
"all criteria verified" } },
184 - expect(t.events.ui.
filter((call)
=> call.
method === "setStatus" && call.args[
0]
=== "goal").
map((call)
=> call.args[
1])).
toContain(
"goal judging 1/20");
184 + const statusCalls
= t.events.ui.
filter((call)
=> call.
method === "setStatus" && call.args[
0]
=== "goal").
map((call)
=> call.args[
1]);
185 + expect(statusCalls).
toContain(
"goal judging 1/20");
186 + const widgetCalls
= t.events.ui.
filter((call)
=> call.
method === "setWidget" && call.args[
0]
=== "goal").
map((call)
=> call.args[
1]);
187 + expect(widgetCalls.
some(
Boolean)).
toBe(
true);
188 + expect(widgetCalls).
toContain(
undefined);
extensions/goal/__tests__/unit.test.ts
Modified 79 79 expect(__goalTest.
latestAssistantTail({ sessionManager: {
getEntries: ()
=> entries } }
as never,
3)).
toBe(
"def");
82 + it(
"autocompletes goal subcommands and criterion removal", ()
=> {
83 + expect(__goalTest.
goalArgumentCompletions(
"pa",
undefined)).
toEqual([{ value:
"pause", label:
"pause", description:
"Pause active goal" }]);
84 + expect(__goalTest.
goalArgumentCompletions(
"clear",
undefined)?.
map((item)
=> item.
value)).
toEqual([
"clear",
"clear-criteria"]);
85 + expect(__goalTest.
goalArgumentCompletions(
"remove ",
goal()
as never)).
toEqual([
86 + { value:
"remove 1", label:
"1", description:
"tests pass" },
87 + { value:
"remove 2", label:
"2", description:
"docs updated" },
89 + expect(__goalTest.
goalArgumentCompletions(
"remove 2",
goal()
as never)).
toEqual([{ value:
"remove 2", label:
"2", description:
"docs updated" }]);
90 + expect(__goalTest.
goalArgumentCompletions(
"add ",
goal()
as never)).
toBeNull();
82 93 it(
"marks goals owned by another session in status output", ()
=> {
83 94 expect(__goalTest.
statusLine(
goal({ sessionId:
"other" })
as never,
"current")).
toContain(
"owned by another session");
84 95 expect(__goalTest.
statusLine(
goal({ sessionId:
"current" })
as never,
"current")).not.
toContain(
"owned by another session");
extensions/goal/bun.lock
Modified 10 10 "peerDependencies": {
11 11 "@earendil-works/pi-ai": "*",
12 12 "@earendil-works/pi-coding-agent": "*",
13 + "@earendil-works/pi-tui": "*",
extensions/goal/index.ts
Modified 1 1 import { complete, StringEnum }
from "@earendil-works/pi-ai";
2 2 import type { ExtensionAPI, ExtensionContext, ThemeColor }
from "@earendil-works/pi-coding-agent";
3 -import { truncateToWidth }
from "@earendil-works/pi-tui";
3 +import { truncateToWidth, type AutocompleteItem }
from "@earendil-works/pi-tui";
4 4 import { Type }
from "typebox";
6 6 type GoalStatus = "active" | "paused" | "complete" | "blocked";
38 38 dispatched: boolean;
41 +type GoalSubcommand = {
43 + description
: string;
41 46 const GOAL_STATE_ENTRY
= "goal-state";
42 47 const GOAL_JUDGE_ENTRY
= "goal-judge";
43 48 const PROBE_ENTRY
= "goal-probe";
55 60 Mark done only
if the latest assistant response explicitly proves the objective and every criterion are complete.
56 61 Mark blocked only
if the response shows a real impasse needing user input or external state.
57 62 Otherwise
return done
=false, blocked
=false.
`; 63 +const GOAL_SUBCOMMANDS: GoalSubcommand[] = [ 64 + { value: "status", description: "Show current goal" }, 65 + { value: "pause", description: "Pause active goal" }, 66 + { value: "resume", description: "Resume/rebind goal" }, 67 + { value: "complete", description: "Mark goal complete" }, 68 + { value: "clear", description: "Clear goal" }, 69 + { value: "add", description: "Add criterion" }, 70 + { value: "remove", description: "Remove criterion by number" }, 71 + { value: "criteria", description: "List criteria" }, 72 + { value: "clear-criteria", description: "Clear all criteria" }, 59 75 type GoalUiMode = "normal" | "judging"; 308 324 return state.criteria.
map((criterion, index)
=> `${index + 1}. ${criterion}`).
join(
"\n");
327 +function goalArgumentCompletions(argumentPrefix
: string, state
: GoalState | undefined)
: AutocompleteItem[]
| null {
328 + const input
= argumentPrefix.
trimStart();
329 + const firstSpace
= input.
search(
/\s/);
330 + const cmd
= firstSpace
=== -1 ? input
: input.
slice(
0, firstSpace);
331 + const rest
= firstSpace
=== -1 ? "" : input.
slice(firstSpace
+ 1).
trim();
332 + if (firstSpace
=== -1) {
333 + const matches
= GOAL_SUBCOMMANDS
334 + .
filter((subcommand)
=> subcommand.
value.
startsWith(cmd))
335 + .
map((subcommand)
=> ({ value: subcommand.
value, label: subcommand.
value, description: subcommand.
description }));
336 + return matches.
length === 0 ? null : matches;
338 + if (cmd
!== "remove" || !state
|| state.criteria.
length === 0)
return null;
339 + const matches
= state.criteria
340 + .
map((criterion, index)
=> ({ n:
String(index
+ 1), criterion }))
341 + .
filter((item)
=> item.n.
startsWith(rest))
342 + .
map((item)
=> ({ value:
`remove ${item.n}`, label: item.n, description: item.criterion }));
343 + return matches.
length === 0 ? null : matches;
311 346 function activeGoalPrompt(state
: GoalState)
: string {
312 347 const criteria
= state.criteria.
length === 0 588 623 pi.
registerCommand(
"goal", {
589 624 description:
"Persistent goal loop. Usage: /goal <objective>",
625 + getArgumentCompletions: (argumentPrefix)
=> goalArgumentCompletions(argumentPrefix, state),
590 626 handler: (args, ctx)
=> {
591 627 const input
= args.
trim();
592 628 const firstSpace
= input.
search(
/\s/);
708 744 activeGoalPrompt,
709 745 continuationPrompt,
747 + goalArgumentCompletions,
712 749 latestAssistantTail,
extensions/goal/package.json
Modified 6 6 "peerDependencies": {
7 7 "@earendil-works/pi-ai":
"*",
8 8 "@earendil-works/pi-coding-agent":
"*",
9 + "@earendil-works/pi-tui":
"*",
11 12 "devDependencies": {