@narumitw/pi-goal 0.53.0 → 0.53.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.
package/dist/index.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  // @generated by scripts/build-runtime.mjs; do not edit.
2
- // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
2
+ // @ts-nocheck -- the generated entry uses a .ts extension for Pi's Jiti loader.
3
3
  import {
4
4
  GOAL_BLOCKED_TOOL,
5
5
  GOAL_COMPLETE_TOOL,
6
+ GOAL_CONTRACT_MESSAGE_TYPE,
6
7
  GOAL_WAIT_TOOL,
7
8
  GoalRuntime,
8
9
  MAX_GOAL_ID_LENGTH,
@@ -13,7 +14,6 @@ import {
13
14
  abortCurrentTurn,
14
15
  blocksStaleGoalToolCalls,
15
16
  buildGoalPrompt,
16
- buildGoalSystemPrompt,
17
17
  buildObjectiveUpdatedPrompt,
18
18
  buildResumePrompt,
19
19
  buildWaitingResumePrompt,
@@ -28,6 +28,7 @@ import {
28
28
  hasAssistantToolCall,
29
29
  incrementGoal,
30
30
  isContradictoryCompletionSummary,
31
+ isGoalContextContract,
31
32
  isRemovedQueueCommand,
32
33
  isResumableGoalStatus,
33
34
  isTerminalGoalStatus,
@@ -35,12 +36,14 @@ import {
35
36
  nextGoalInstance,
36
37
  parseCommand,
37
38
  queueGoalSafetyReset,
39
+ reconcileGoalContextContract,
40
+ reconcileInactiveGoalContextContract,
38
41
  resetGoalSafetyEpoch,
39
42
  resolveGoalWaitDelay,
40
43
  stoppedStatusLabel,
41
44
  transitionGoal,
42
45
  validateObjective
43
- } from "./chunks/chunk-W7AFYZ6J.js";
46
+ } from "./chunks/chunk-ZT3VZXYO.js";
44
47
  import {
45
48
  DEFAULT_GOAL_SETTINGS,
46
49
  currentTokenTotal,
@@ -55,15 +58,15 @@ import {
55
58
  safeGoalMenuText,
56
59
  safeTerminalText,
57
60
  truncateNotification
58
- } from "./chunks/chunk-UA7LMS63.js";
61
+ } from "./chunks/chunk-2ARA24RR.js";
59
62
 
60
63
  // src/command-registration.ts
61
64
  function registerGoalCommand(pi, runtime, commands, options = {}) {
62
65
  const loadGoalManager = cachedModuleLoader(
63
- options.loadGoalManager ?? (() => import("./chunks/menu-73TCS5P6.js"))
66
+ options.loadGoalManager ?? (() => import("./chunks/menu-H3C3LAQW.js"))
64
67
  );
65
68
  const loadGoalSettings = cachedModuleLoader(
66
- options.loadGoalSettings ?? (() => import("./chunks/settings-ui-Y5LMEFEH.js"))
69
+ options.loadGoalSettings ?? (() => import("./chunks/settings-ui-LBFJ7TOX.js"))
67
70
  );
68
71
  pi.registerCommand("goal", {
69
72
  description: "Run a goal to completion: /goal [--tokens 100k] <goal_to_complete>",
@@ -647,6 +650,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
647
650
  if (!runtime.acquireWorkflow()) {
648
651
  runtime.activeGoal = transitionGoal(loaded.goal, "paused");
649
652
  runtime.persistGoal(runtime.activeGoal);
653
+ runtime.ensureInactiveGoalContextContract(ctx);
650
654
  runtime.updateStatus(ctx, runtime.activeGoal);
651
655
  notifyTerminal(
652
656
  ctx.ui,
@@ -683,6 +687,11 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
683
687
  }
684
688
  runtime.persistGoal(runtime.activeGoal);
685
689
  if (!runtime.ownsWorkflow(runtime.activeGoal)) return;
690
+ const restoredGoalId = runtime.activeGoal.id;
691
+ runtime.ensureGoalContextContract(ctx, runtime.activeGoal);
692
+ if (runtime.activeGoal?.id !== restoredGoalId || runtime.activeGoal.status !== "active" || !runtime.ownsWorkflow(runtime.activeGoal)) {
693
+ return;
694
+ }
686
695
  runtime.updateStatus(ctx, runtime.activeGoal);
687
696
  runtime.restoreGoalWaitTimer(ctx);
688
697
  return;
@@ -723,8 +732,10 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
723
732
  }
724
733
  if (runtime.activeGoal) {
725
734
  runtime.persistGoal(runtime.activeGoal);
735
+ runtime.ensureInactiveGoalContextContract(ctx);
726
736
  runtime.updateStatus(ctx, runtime.activeGoal);
727
737
  } else {
738
+ runtime.ensureInactiveGoalContextContract(ctx);
728
739
  ctx.ui.setStatus(STATUS_KEY, void 0);
729
740
  }
730
741
  });
@@ -783,8 +794,13 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
783
794
  runtime.persistGoal(runtime.activeGoal);
784
795
  runtime.updateStatus(ctx, runtime.activeGoal);
785
796
  }
786
- if (!usageRecorded) return;
787
797
  if (runtime.limitActiveGoalForBudget(ctx, false)) return;
798
+ const compactedGoalId = runtime.activeGoal.id;
799
+ runtime.ensureGoalContextContract(ctx, runtime.activeGoal);
800
+ if (runtime.activeGoal?.id !== compactedGoalId || runtime.activeGoal.status !== "active" || !runtime.ownsWorkflow(runtime.activeGoal)) {
801
+ return;
802
+ }
803
+ if (!usageRecorded) return;
788
804
  const wasPiRetry = runtime.isPiOwnedCompactionRetry(event, runtime.activeGoal.id);
789
805
  if (wasPiRetry) return;
790
806
  runtime.clearGoalRecoveryForGoal(runtime.activeGoal.id);
@@ -826,6 +842,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
826
842
  return;
827
843
  }
828
844
  if (message.role === "custom") {
845
+ if (Reflect.get(message, "customType") === GOAL_CONTRACT_MESSAGE_TYPE) return;
829
846
  if (runtime.isActiveBudgetWrapUpMessage(message)) return;
830
847
  if (runtime.activeGoal?.waiting) runtime.clearGoalWait(ctx, runtime.activeGoal.id);
831
848
  if (runtime.guardAbortGoalId === runtime.activeGoal?.id) {
@@ -864,11 +881,17 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
864
881
  runtime.updateStatus(ctx, runtime.activeGoal);
865
882
  });
866
883
  pi.on("context", (event, ctx) => {
867
- const messages = event.messages.filter((message) => runtime.keepBudgetWrapUpMessage(message));
884
+ const keptMessages = event.messages.filter(
885
+ (message) => runtime.keepBudgetWrapUpMessage(message)
886
+ );
887
+ const hasGoalContractHistory = keptMessages.some(isGoalContextContract) || runtime.hasGoalContextContractHistory(ctx);
888
+ const messages = runtime.activeGoal?.status === "active" && runtime.ownsWorkflow(runtime.activeGoal) ? reconcileGoalContextContract(keptMessages, runtime.activeGoal) : hasGoalContractHistory ? reconcileInactiveGoalContextContract(keptMessages) : keptMessages;
868
889
  if (runtime.activeGoal?.status === "paused" && runtime.guardAbortGoalId === runtime.activeGoal.id) {
869
890
  abortCurrentTurn(ctx);
870
891
  }
871
- if (messages.length !== event.messages.length) return { messages };
892
+ if (messages !== keptMessages || keptMessages.length !== event.messages.length) {
893
+ return { messages };
894
+ }
872
895
  });
873
896
  pi.on("tool_call", (event, ctx) => {
874
897
  runtime.markAgentToolAttempted();
@@ -934,7 +957,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
934
957
  const runOrigin = continuationGoalId ? "automatic" : activeGoalRecovery && runtime.goalRecovery?.automaticOwner ? "automatic" : "manual";
935
958
  if (activeBudgetWrapUp && runtime.activeGoal) {
936
959
  runtime.beginAgentRun(runtime.activeGoal.id, "manual");
937
- return;
960
+ return goalContractBoundaryResult(ctx);
938
961
  }
939
962
  if (ownedPromptGoalId && ownedPromptGoalId !== runtime.activeGoal?.id) {
940
963
  runtime.beginAgentRun(ownedPromptGoalId, runOrigin);
@@ -945,23 +968,19 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
945
968
  return;
946
969
  }
947
970
  if (runtime.activeGoal?.status !== "active" || !runtime.ownsWorkflow(runtime.activeGoal)) {
948
- return;
971
+ return goalContractBoundaryResult(ctx);
949
972
  }
950
973
  runtime.beginAgentRun(runtime.activeGoal.id, runOrigin);
951
974
  if (!runtime.toolPolicy.toolsAvailable()) {
952
975
  runtime.pauseGoalForUnavailableTools(ctx, ownedPromptGoalId !== void 0);
953
- return;
976
+ return goalContractBoundaryResult(ctx);
954
977
  }
955
978
  if (goalPrompt?.resetSafetyEpoch && goalPromptGoalId === runtime.activeGoal.id) {
956
979
  runtime.activeGoal = resetGoalSafetyEpoch(runtime.activeGoal);
957
980
  runtime.persistGoal(runtime.activeGoal);
958
981
  runtime.updateStatus(ctx, runtime.activeGoal);
959
982
  }
960
- return {
961
- systemPrompt: `${event.systemPrompt}
962
-
963
- ${buildGoalSystemPrompt(runtime.activeGoal)}`
964
- };
983
+ return goalContractBoundaryResult(ctx, runtime.activeGoal);
965
984
  });
966
985
  pi.on("agent_start", (_event, _ctx) => {
967
986
  const activeGoal = runtime.activeGoal;
@@ -1064,6 +1083,10 @@ ${buildGoalSystemPrompt(runtime.activeGoal)}`
1064
1083
  if (!resumedWait) runtime.dispatchContinuationIfSettled(ctx);
1065
1084
  runtime.clearSettledSafetyTracking();
1066
1085
  });
1086
+ function goalContractBoundaryResult(ctx, goal2) {
1087
+ const message = runtime.goalContextContractForPrompt(ctx, goal2);
1088
+ return message ? { message } : void 0;
1089
+ }
1067
1090
  function beginNonGoalFollowUp(ctx, resetSafetyEpoch) {
1068
1091
  runtime.clearGoalRecovery();
1069
1092
  runtime.clearStaleGoalToolCallBlock();