pi-goal-x 0.8.2 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # pi-goal-x
2
2
 
3
- > **Fork of [@capyup/pi-goal](https://github.com/capyup/pi-goal)** — this repository extends the upstream with quality-of-life features for the completion auditor, lifecycle reliability improvements, and drafting UX refinements. Upstream changes can be merged from the original repository.
3
+ > **Fork of [@capyup/pi-goal](https://github.com/capyup/pi-goal)** — this repository extends the upstream with quality-of-life features for the completion auditor, lifecycle reliability improvements, mid-flight objective updates, deferred archival, and drafting UX refinements. Upstream changes can be merged from the original repository.
4
4
 
5
5
  `pi-goal-x` is a long-running goal extension for [pi](https://github.com/earendil-works/pi-coding-agent). It gives the agent a durable objective, a visible lifecycle, and schema-gated tools for drafting, executing, pausing, resuming, and completing work.
6
6
 
@@ -10,6 +10,21 @@ The extension is designed around one rule: **the user owns intent; the agent exe
10
10
 
11
11
  All core features of [@capyup/pi-goal](https://github.com/capyup/pi-goal) are preserved. The following changes are specific to pi-goal-x:
12
12
 
13
+ ### Mid-flight objective updates
14
+
15
+ - **`update_goal({updatedObjective})`** — the agent can now sync the goal objective mid-flight when user requirements change, *without* completing the goal. This ensures the completion auditor evaluates against the latest requirements. The combined path (`updatedObjective` + `status: "complete"`) applies the update first, then runs the normal completion+audit flow.
16
+ - **`apply_goal_tweak`** remains available for `/goal-tweak` drafting revisions; the new parameter is the lightest possible touch on the existing `update_goal` tool.
17
+
18
+ ### Deferred archival
19
+
20
+ - **No more premature archiving**: previously, `update_goal` archived the goal file inline within the tool handler before the agent could see the audit result (or skip notification). Archival is now deferred until `turn_end` — after the agent has received the audit/skip result in the conversation. The goal remains visible in the active pool through the entire completion flow.
21
+ - **Cleaner lifecycle**: completed goals are archived by the `turn_end` lifecycle hook, not by the tool handler. The `accountProgress` guard skips disk reconciliation for completed goals.
22
+
23
+ ### E2e test infrastructure
24
+
25
+ - **Deterministic fork tests using `--mode json`**: the e2e suite spawns a real `pi --fork --mode json` session, parses structured `tool_execution_start`/`tool_execution_end` JSON events for field-level assertions — no free-text AI output parsing. Uses `--append-system-prompt` + `--tools` to force deterministic tool calls.
26
+ - **Full coverage**: 131 tests total — function-level integration tests (12), mock-pi handler tests (4), file-validity checks (6), and real `pi --fork --mode json` tests (3 scenarios: quick-sync, combined sync+complete, deferred archival).
27
+
13
28
  ### Completion auditor
14
29
 
15
30
  - **Live progress widget** — when the auditor runs, the TUI shows a spinner, the current tool being executed, and recent output lines. No more wondering if anything is happening.
@@ -43,6 +43,14 @@ export function validateGoalCompletion(args: {
43
43
  return { ok: true };
44
44
  }
45
45
 
46
+ export function validateGoalUpdate(args: {
47
+ goal: GoalPolicyRecordLike | null;
48
+ }): PolicyValidation {
49
+ if (!args.goal) return { ok: false, message: "No goal is set; cannot update objective." };
50
+ if (args.goal.status === "complete") return { ok: false, message: "Goal is already complete; cannot update objective." };
51
+ return { ok: true };
52
+ }
53
+
46
54
  export function validateGoalAbort(args: {
47
55
  goal: GoalPolicyRecordLike | null;
48
56
  runningGoalId?: string | null;
@@ -106,6 +106,7 @@ import {
106
106
  shouldInjectPostCompactReminder,
107
107
  validateGoalAbort,
108
108
  validateGoalCompletion,
109
+ validateGoalUpdate,
109
110
  validatePauseGoal,
110
111
  validateResumeGoal,
111
112
  } from "./goal-policy.ts";
@@ -1704,16 +1705,70 @@ export default function goalExtension(pi: ExtensionAPI): void {
1704
1705
  "Do not call update_goal merely because work is stopping, substantial progress was made, or tests passed without covering every requirement.",
1705
1706
  "Do not use update_goal=complete as an escape hatch when you are blocked. If you are blocked, call pause_goal({reason, suggestedAction?}) instead so the user can intervene.",
1706
1707
  "For sisyphus goals, do not mark complete until every numbered step has been executed and individually verified against its done criterion.",
1708
+ "If the user gives requirements, feedback, or corrections that differ from the goal objective, the goal is stale. Use update_goal with updatedObjective to sync the objective before continuing work or before marking the goal complete. This ensures the auditor evaluates against the latest requirements.",
1707
1709
  ],
1708
1710
  parameters: Type.Object({
1709
- status: StringEnum([COMPLETE_STATUS] as const, { description: "Set to complete only when the objective is achieved." }),
1711
+ status: Type.Optional(StringEnum([COMPLETE_STATUS] as const, { description: "Set to complete only when the objective is achieved." })),
1710
1712
  completionSummary: Type.Optional(Type.String({ description: "Concise completion claim and evidence summary passed to the independent auditor agent." })),
1711
1713
  confirmBypassAuditor: Type.Optional(Type.Boolean({ description: "Set to true to confirm bypassing the independent auditor when it is disabled in settings." })),
1714
+ updatedObjective: Type.Optional(Type.String({ description: "Revised goal objective. Use when the user's requirements have changed mid-flight. The goal remains active so the agent can continue working toward the new objective. Can be combined with status=complete to update the objective before the completion audit." })),
1712
1715
  }),
1713
1716
  executionMode: "sequential",
1714
1717
  async execute(_toolCallId, params, signal, _onUpdate, ctx) {
1715
1718
  reconcileFocusedGoalFromDisk(ctx);
1716
- if (params.status !== COMPLETE_STATUS) throw new Error("update_goal only supports status=complete.");
1719
+
1720
+ // -- Phase 1: Objective update (quick sync) --
1721
+ // Apply updatedObjective before any completion logic so the completion
1722
+ // flow (if status=complete is also set) reads the latest objective.
1723
+ if (params.updatedObjective !== undefined) {
1724
+ const newObjective = params.updatedObjective.trim();
1725
+ if (!newObjective) throw new Error("update_goal requires a non-empty updatedObjective.");
1726
+ const updateGate = validateGoalUpdate({ goal: state.goal });
1727
+ if (!updateGate.ok) {
1728
+ return {
1729
+ content: [{ type: "text", text: updateGate.message }],
1730
+ details: goalDetails(state.goal),
1731
+ };
1732
+ }
1733
+ if (!state.goal) throw new Error("Goal disappeared during objective update.");
1734
+ const next: GoalRecord = {
1735
+ ...state.goal,
1736
+ objective: newObjective,
1737
+ updatedAt: nowIso(),
1738
+ };
1739
+ state.goal = writeActiveGoalFile(ctx, next);
1740
+ pi.appendEntry(STATE_ENTRY, goalDetails(state.goal));
1741
+ try {
1742
+ appendGoalEvent(ctx, {
1743
+ type: "goal_tweaked",
1744
+ goalId: state.goal.id,
1745
+ changeSummary: "Objective updated via update_goal",
1746
+ at: state.goal.updatedAt,
1747
+ });
1748
+ } catch {
1749
+ // Ledger append failure should not block update
1750
+ }
1751
+ updateUI(ctx);
1752
+
1753
+ // Quick sync only (no status=complete) — return without terminating
1754
+ if (params.status !== COMPLETE_STATUS) {
1755
+ return {
1756
+ content: [{ type: "text", text: `Goal objective updated.` }],
1757
+ details: goalDetails(state.goal),
1758
+ };
1759
+ }
1760
+ // Fall through: status=complete also set, proceed with completion below
1761
+ }
1762
+
1763
+ // -- Phase 2: Status validation --
1764
+ if (params.status !== COMPLETE_STATUS) {
1765
+ if (params.updatedObjective === undefined) {
1766
+ throw new Error("update_goal requires either status=complete or updatedObjective.");
1767
+ }
1768
+ throw new Error("update_goal requires status=complete when marking a goal complete.");
1769
+ }
1770
+
1771
+ // -- Phase 3: Completion --
1717
1772
  const completionGate = validateGoalCompletion({ goal: state.goal, runningGoalId });
1718
1773
  if (!completionGate.ok) {
1719
1774
  return {
@@ -2009,7 +2064,8 @@ export default function goalExtension(pi: ExtensionAPI): void {
2009
2064
  };
2010
2065
  },
2011
2066
  renderCall(args, theme) {
2012
- return new Text(theme.fg("toolTitle", "update_goal ") + theme.fg("success", args.status), 0, 0);
2067
+ const label = args?.status ?? args?.updatedObjective ? "sync" : "";
2068
+ return new Text(theme.fg("toolTitle", "update_goal ") + theme.fg("success", label), 0, 0);
2013
2069
  },
2014
2070
  renderResult(result, _options, theme) {
2015
2071
  return renderGoalResult(result, theme);
@@ -44,7 +44,9 @@ If you hit a real blocker that you cannot resolve with one more reasonable next
44
44
 
45
45
  If the user explicitly asks to abandon/cancel this goal, or the objective is obsolete, impossible, or unsafe to continue and should not be marked complete, call abort_goal({reason}) with a non-empty reason and stop.
46
46
 
47
- Do NOT silently invent workarounds, fake completion, or quietly redefine the objective. Do NOT call update_goal=complete to escape a blocker.${sisyphusDisciplineBlock(goal) ? `\n${sisyphusDisciplineBlock(goal)}` : ""}`;
47
+ Do NOT silently invent workarounds, fake completion, or quietly redefine the objective. Do NOT call update_goal=complete to escape a blocker.
48
+
49
+ Goal evolution: if the user gives requirements, feedback, or corrections that differ from the goal objective, the goal is stale. Propose the updated objective concisely and wait for the user to confirm before continuing. Use update_goal with updatedObjective for narrow focus-area changes, or suggest /goal-tweak for broader revisions (boundaries, constraints, multiple sections). Do NOT mark the goal complete with a stale objective.${sisyphusDisciplineBlock(goal) ? `\n${sisyphusDisciplineBlock(goal)}` : ""}`;
48
50
  }
49
51
 
50
52
  export function continuationPrompt(goal: GoalRecord): string {
@@ -77,6 +79,8 @@ export function continuationPrompt(goal: GoalRecord): string {
77
79
  "Do not call update_goal unless the goal is complete enough to survive independent semantic auditing. Do not mark a goal complete merely because work is stopping.",
78
80
  "Do not ask the user for confirmation unless there is a real blocker.",
79
81
  "",
82
+ "Goal evolution: if the user gives requirements, feedback, or corrections that differ from the goal objective, the goal is stale. Propose the updated objective concisely and wait for the user to confirm before continuing. Use update_goal with updatedObjective for narrow focus-area changes, or suggest /goal-tweak for broader revisions (boundaries, constraints, multiple sections). Do NOT mark the goal complete with a stale objective.",
83
+ "",
80
84
  "If you hit a real blocker (missing credentials, contradictory spec, file/permission you cannot access, dangerous operation pending user approval, or an unclear Sisyphus-style ordered plan), call pause_goal({reason, suggestedAction?}) and stop. If the user explicitly asks to abandon/cancel, or the objective is obsolete, impossible, or unsafe to continue, call abort_goal({reason}) and stop. Do not silently invent workarounds. Do not fake completion. pause_goal and abort_goal are structured lifecycle exits; update_goal=complete is not an escape hatch for blockers.",
81
85
  ...(goal.sisyphus ? ["", sisyphusDisciplineBlock(goal)] : []),
82
86
  ].join("\n");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-goal-x",
3
- "version": "0.8.2",
3
+ "version": "0.9.0",
4
4
  "description": "Goal mode extension for pi: persistent long-running objectives, /goal-set drafting, Sisyphus prompt style, autoContinue, and an above-editor status overlay. Fork of @capyup/pi-goal.",
5
5
  "license": "MIT",
6
6
  "author": "pi-goal-x contributors",