repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

feat(goal): autocomplete prompt templates

68f4fb2c6896380c90a25dc1d3e7a205651cdce8

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (5)

CHANGELOG.md

Modified
13 13 errors to verdict history
14 14 - Keep visible goal judge/event reasons untruncated while preserving internal
15 15 bounded context snippets
16 -- Expand prompt templates when starting goals with `/goal /template args`
16 +- Expand and autocomplete prompt templates when starting goals with
17 + `/goal /template args`
17 18 - Rename `autoresearch` extension package/slug to `tune` and slash command to
18 19 `/tune`
19 20 - Move tune session state to `.pi/tune/`

extensions/goal/CHANGELOG.md

Modified
2 2 # Changelog
4 4 ## 0.0.3
6 -- Expand prompt templates when starting goals with `/goal /template args`.
6 +- Expand and autocomplete prompt templates when starting goals with
7 + `/goal /template args`.
7 8 - Add planner dossier for autonomous goal runs.
8 9 - Harden continuation and judge loops; retry empty verdicts and errors.
9 10 - Goal widget: live updates, judge history, deduped output, full criteria list.

extensions/goal/README.md

Modified
18 18 ## Commands
20 20 Subcommands autocomplete.
21 +`/goal /...` autocompletes prompt templates.
21 22 `/goal remove` autocompletes criterion numbers.
23 24 ```text
115 116 It sends a kickoff prompt immediately.
116 117 - `/goal /prompt-template [args]` expands a prompt template and uses the expanded
117 118 content as the objective.
119 + Prompt templates autocomplete after `/goal /`.
118 120 - A raw prompt containing `standing goal` plus an `<objective>...</objective>`
119 121 block is adopted as an active goal when no goal exists.
120 122 - New goals require an idle agent.

extensions/goal/__tests__/unit.test.ts

Modified
445 445 ).toBeNull();
448 + it("autocompletes prompt templates after /goal slash input", () => {
449 + expect(
450 + __goalTest.goalArgumentCompletions("/sh", undefined, [
452 + name: "ship",
453 + description: "Ship feature",
454 + content: "Ship $ARGUMENTS",
455 + },
457 + name: "review",
458 + description: "Review change",
459 + content: "Review $ARGUMENTS",
460 + },
461 + ]),
462 + ).toEqual([
463 + { value: "/ship", label: "/ship", description: "Ship feature" },
464 + ]);
465 + expect(
466 + __goalTest.goalArgumentCompletions("/ship ", undefined, [
467 + { name: "ship", description: "Ship feature", content: "" },
468 + ]),
469 + ).toBeNull();
470 + });
448 472 it("marks goals owned by another session in status output", () => {
449 473 expect(
450 474 __goalTest.statusLine(goal({ sessionId: "other" }) as never, "current"),

extensions/goal/index.ts

Modified
1314 1314 .join("\n");
1317 +function goalPromptTemplateCompletions(
1318 + input: string,
1319 + templates: GoalPromptTemplate[],
1320 +): AutocompleteItem[] | null {
1321 + const firstSpace = input.search(/\s/);
1322 + if (firstSpace !== -1) return null;
1323 + const prefix = input.slice(1);
1324 + const matches = templates
1325 + .filter((template) => template.name.startsWith(prefix))
1326 + .map((template) => ({
1327 + value: `/${template.name}`,
1328 + label: `/${template.name}`,
1329 + description: template.description,
1330 + }));
1331 + return matches.length === 0 ? null : matches;
1317 1334 function goalArgumentCompletions(
1318 1335 argumentPrefix: string,
1319 1336 state: GoalState | undefined,
1337 + templates: GoalPromptTemplate[] = [],
1320 1338 ): AutocompleteItem[] | null {
1321 1339 const input = argumentPrefix.trimStart();
1340 + if (input.startsWith("/"))
1341 + return goalPromptTemplateCompletions(input, templates);
1322 1342 const firstSpace = input.search(/\s/);
1323 1343 const cmd = firstSpace === -1 ? input : input.slice(0, firstSpace);
1324 1344 const rest = firstSpace === -1 ? "" : input.slice(firstSpace + 1).trim();
1959 1979 throw lastError;
1962 -type GoalPromptTemplate = { name: string; content: string };
1982 +type GoalPromptTemplate = {
1983 + name: string;
1984 + description?: string;
1985 + content: string;
1964 1988 function judgeResourceLoaderOptions(ctx: ExtensionContext) {
1965 1989 return {
2029 -async function resolveGoalObjectiveInput(
2030 - input: string,
2053 +async function loadGoalPromptTemplates(
2031 2054 ctx: ExtensionContext,
2032 -): Promise<string | undefined> {
2033 - if (!input.startsWith("/")) return input;
2055 +): Promise<GoalPromptTemplate[]> {
2034 2056 const loader = new DefaultResourceLoader({
2035 2057 cwd: ctx.cwd,
2036 2058 agentDir: getAgentDir(),
2040 2062 noContextFiles: true,
2042 2064 await loader.reload();
2043 - return expandGoalPromptTemplate(input, loader.getPrompts().prompts);
2065 + return loader.getPrompts().prompts;
2068 +async function resolveGoalObjectiveInput(
2069 + input: string,
2070 + ctx: ExtensionContext,
2071 +): Promise<string | undefined> {
2072 + if (!input.startsWith("/")) return input;
2073 + return expandGoalPromptTemplate(input, await loadGoalPromptTemplates(ctx));
2046 2076 async function judgeGoalWithAgent(
2345 2375 let state: GoalState | undefined;
2346 2376 const continuation: ContinuationState = { queued: false, scheduled: false };
2347 2377 let removeTerminalInput: (() => void) | undefined;
2378 + let promptTemplates: GoalPromptTemplate[] = [];
2348 2379 let probe: ProbeState | undefined;
2349 2380 let lastTurnEvidence: TurnEvidence | undefined;
2350 2381 let liveUiInterval: ReturnType<typeof setInterval> | undefined;
2398 - pi.on("session_start", (_event, ctx) => {
2429 + pi.on("session_start", async (_event, ctx) => {
2430 + promptTemplates = await loadGoalPromptTemplates(ctx);
2399 2431 state = latestGoalState(ctx);
2400 2432 if (state && state.status === "active") ensureDossier(pi, ctx, state);
2401 2433 continuation.queued = false;
2783 2815 pi.registerCommand("goal", {
2784 2816 description: "Persistent goal loop. Usage: /goal <objective>",
2785 2817 getArgumentCompletions: (argumentPrefix) =>
2786 - goalArgumentCompletions(argumentPrefix, state),
2818 + goalArgumentCompletions(argumentPrefix, state, promptTemplates),
2787 2819 handler: async (args, ctx) => {
2788 2820 const input = args.trim();
2789 2821 const firstSpace = input.search(/\s/);