pi-better-goal 0.2.1 → 0.2.3

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +19 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-better-goal",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Pi extension for goal tracking with background-aware continuation.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/index.ts CHANGED
@@ -248,6 +248,15 @@ export default function (pi: ExtensionAPI): void {
248
248
  refreshGoalWidget?.(wasVisible);
249
249
  };
250
250
 
251
+ const pauseGoalOnInterrupt = (ctx: ExtensionContext): void => {
252
+ const goal = getGoal(ctx);
253
+ if (!isPokeable(goal)) {
254
+ return;
255
+ }
256
+ setGoal(goalWithStatus(goal, "paused"), ctx, "runtime");
257
+ notifyGoal(ctx, "Goal paused (interrupted).");
258
+ };
259
+
251
260
  const queueGoalContinuation = (goal: GoalSnapshot): void => {
252
261
  if (!isPokeable(goal) || continuationQueuedFor === goal.goalId) {
253
262
  return;
@@ -713,7 +722,7 @@ export default function (pi: ExtensionAPI): void {
713
722
  }
714
723
 
715
724
  const backgroundInstruction = snapshot.backgroundRunning
716
- ? ` The goal still has delegated background work running (${summarizeActiveBackground(snapshot)}). Foreground idleness alone is not goal completion; do not mark the goal complete until delegated background work reaches a terminal state and its result or failure has been inspected.`
725
+ ? ` The goal still has delegated background work running (${summarizeActiveBackground(snapshot)}). Foreground idleness alone is not goal completion; keep any structured plan current and do not mark verification, the plan, or the goal complete until every relevant delegated task reaches a terminal state and its result or failure has been inspected and integrated.`
717
726
  : "";
718
727
  return {
719
728
  systemPrompt:
@@ -728,6 +737,14 @@ export default function (pi: ExtensionAPI): void {
728
737
  clearIdleContinuation();
729
738
  continuationQueuedFor = null;
730
739
  lastAgentEvidence = null;
740
+ const turnSignal = ctx.signal;
741
+ if (turnSignal) {
742
+ if (turnSignal.aborted) {
743
+ pauseGoalOnInterrupt(ctx);
744
+ } else {
745
+ turnSignal.addEventListener("abort", () => pauseGoalOnInterrupt(ctx), { once: true });
746
+ }
747
+ }
731
748
  await publishSnapshot(ctx);
732
749
  });
733
750
 
@@ -738,13 +755,7 @@ export default function (pi: ExtensionAPI): void {
738
755
  // aborted (escape / ctrl+c while streaming), pause the active goal so it does
739
756
  // not auto-continue after the user stopped the agent.
740
757
  if (wasTurnAborted(event.messages)) {
741
- const goal = getGoal(ctx);
742
- if (isPokeable(goal)) {
743
- setGoal(goalWithStatus(goal, "paused"), ctx, "runtime");
744
- if (ctx.hasUI) {
745
- ctx.ui.notify("Goal paused (interrupted).", "info");
746
- }
747
- }
758
+ pauseGoalOnInterrupt(ctx);
748
759
  }
749
760
  });
750
761