repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

fix(goal): adopt standing prompts

84da4523078bc514e831d2b0b5b19645bc6d878c

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (4)

+56 / −0 text lines

Diff layout

extensions/goal/README.md

Modified

+1 / −0 text lines

6767- `/goal` and `/goal status` print current goal status.
6868- `/goal <objective>` creates an active goal with empty criteria, current session ownership, and the configured turn budget. It sends a kickoff prompt immediately.
69- A raw prompt containing `standing goal` plus an `<objective>...</objective>` block is adopted as an active goal when no goal exists.
6970- New goals require an idle agent. Subcommands can run while the agent is busy.
7071- Goal state is stored as append-only custom `goal-state` entries. Replay scans backward; newest valid state or clear tombstone wins.
7172- `before_agent_start` injects the active goal and criteria into the system prompt for the owning session.

extensions/goal/__tests__/harness.test.ts

Modified

+19 / −0 text lines

148148 }
149149 });
151 it("adopts raw standing-goal prompts and runs judge", async () => {
152 const restore = installJudgeProvider(['{"done":true,"blocked":false,"reason":"raw standing goal complete"}']);
153 try {
154 t = await createTestSession({ extensions: [goalPath()] });
155 installSaysStream(t, ["shipped the raw goal"]);
157 await t.session.prompt("Start working toward this standing goal.\n\n<objective>\nship raw prompt\n</objective>\n\nDo not stop just because one turn ends.");
158 await waitFor(() => latestGoal()?.status === "complete");
160 expect(latestGoal()).toMatchObject({ objective: "ship raw prompt", status: "complete", lastReason: "raw standing goal complete" });
161 expect(customEvents("goal-judge")).toMatchObject([
162 { event: "start", objective: "ship raw prompt", turn: 1, maxTurns: 20 },
163 { event: "verdict", objective: "ship raw prompt", turn: 1, maxTurns: 20, verdict: { done: true, blocked: false, reason: "raw standing goal complete" } },
164 ]);
165 } finally {
166 restore();
167 }
168 });
151170 it("judge complete verdict completes goal", async () => {
152171 const restore = installJudgeProvider(['{"done":true,"blocked":false,"reason":"all criteria verified"}']);
153172 try {

extensions/goal/__tests__/unit.test.ts

Modified

+7 / −0 text lines

4848 expect(() => __goalTest.parseModelRef("provider/")).toThrow('Invalid model ref "provider/". Use "provider/model".');
4949 });
51 it("extracts standing goal objective blocks", () => {
52 expect(__goalTest.extractStandingGoalObjective("Start working toward this standing goal.\n\n<objective>\nShip it\n</objective>")).toBe("Ship it");
53 expect(__goalTest.extractStandingGoalObjective("Continue working toward this standing goal.\n\n<objective>\n Ship it\n now\n</objective>")).toBe("Ship it\n now");
54 expect(__goalTest.extractStandingGoalObjective("<objective>\nShip it\n</objective>")).toBeUndefined();
55 expect(__goalTest.extractStandingGoalObjective("standing goal without xml")).toBeUndefined();
56 });
5158 it("parses judge JSON strictly", () => {
5259 expect(__goalTest.parseJudge('prefix {"done":true,"blocked":false,"reason":"complete"} suffix')).toEqual({ done: true, blocked: false, reason: "complete" });
5360 expect(__goalTest.parseJudge('{"done":"true","blocked":1,"reason":" loose "}')).toEqual({ done: false, blocked: false, reason: "loose" });

extensions/goal/index.ts

Modified

+29 / −0 text lines

8888 .join("\n");
91function extractStandingGoalObjective(prompt: string): string | undefined {
92 if (!/standing goal/i.test(prompt)) return undefined;
93 const match = prompt.match(/<objective>\s*([\s\S]*?)\s*<\/objective>/i);
94 const objective = match?.[1]?.trim();
95 return objective || undefined;
96}
9198function isGoalStatus(value: unknown): value is GoalStatus {
9299 return value === "active" || value === "paused" || value === "complete" || value === "blocked";
370377 });
372379 pi.on("before_agent_start", (event, ctx) => {
380 if (!state) {
381 const objective = extractStandingGoalObjective(event.prompt);
382 if (objective) {
383 const settings = loadSettings(pi);
384 const now = Date.now();
385 state = {
386 id: crypto.randomUUID(),
387 objective,
388 criteria: [],
389 status: "active",
390 turnsUsed: 0,
391 maxTurns: settings.maxTurns,
392 sessionId: currentSessionId(ctx),
393 createdAt: now,
394 updatedAt: now,
395 };
396 appendGoal(pi, state);
397 updateStatus(ctx, state);
398 syncUpdateGoalTool();
399 }
400 }
373401 if (!state || state.status !== "active" || !ownsGoal(ctx, state)) return;
374402 return { systemPrompt: event.systemPrompt + activeGoalPrompt(state) };
375403 });
595623 judgeRunningText,
596624 parseJudge,
597625 parseModelRef,
626 extractStandingGoalObjective,
598627 statusLine,
599628 statusText,
600629 textFromContent,