@narumitw/pi-goal 0.53.1 → 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/README.md +21 -10
- package/dist/chunks/{chunk-UA7LMS63.ts → chunk-2ARA24RR.js} +2 -2
- package/dist/chunks/{chunk-4GOI2LMD.ts → chunk-ZT3VZXYO.js} +277 -151
- package/dist/chunks/chunk-ZT3VZXYO.js.map +7 -0
- package/dist/chunks/{menu-MMY32N6V.ts → menu-H3C3LAQW.js} +4 -4
- package/dist/chunks/{settings-ui-NXPYYRGD.ts → settings-ui-LBFJ7TOX.js} +3 -3
- package/dist/index.ts +34 -57
- package/dist/index.ts.map +4 -4
- package/package.json +7 -7
- package/src/goal-contract.ts +76 -23
- package/src/lifecycle.ts +43 -6
- package/src/runtime.ts +74 -1
- package/dist/chunks/chunk-4GOI2LMD.ts.map +0 -7
- /package/dist/chunks/{chunk-UA7LMS63.ts.map → chunk-2ARA24RR.js.map} +0 -0
- /package/dist/chunks/{menu-MMY32N6V.ts.map → menu-H3C3LAQW.js.map} +0 -0
- /package/dist/chunks/{settings-ui-NXPYYRGD.ts.map → settings-ui-LBFJ7TOX.js.map} +0 -0
package/dist/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// @generated by scripts/build-runtime.mjs; do not edit.
|
|
2
|
-
// @ts-nocheck -- generated
|
|
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,
|
|
@@ -12,7 +13,6 @@ import {
|
|
|
12
13
|
STATUS_KEY,
|
|
13
14
|
abortCurrentTurn,
|
|
14
15
|
blocksStaleGoalToolCalls,
|
|
15
|
-
buildGoalContextPrompt,
|
|
16
16
|
buildGoalPrompt,
|
|
17
17
|
buildObjectiveUpdatedPrompt,
|
|
18
18
|
buildResumePrompt,
|
|
@@ -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-
|
|
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-
|
|
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-
|
|
66
|
+
options.loadGoalManager ?? (() => import("./chunks/menu-H3C3LAQW.js"))
|
|
64
67
|
);
|
|
65
68
|
const loadGoalSettings = cachedModuleLoader(
|
|
66
|
-
options.loadGoalSettings ?? (() => import("./chunks/settings-ui-
|
|
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>",
|
|
@@ -605,52 +608,6 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
|
|
|
605
608
|
}
|
|
606
609
|
};
|
|
607
610
|
|
|
608
|
-
// src/goal-contract.ts
|
|
609
|
-
var GOAL_CONTRACT_MESSAGE_TYPE = "goal-contract";
|
|
610
|
-
var GOAL_CONTRACT_VERSION = 1;
|
|
611
|
-
function createGoalContextContract(goal2) {
|
|
612
|
-
return {
|
|
613
|
-
role: "custom",
|
|
614
|
-
customType: GOAL_CONTRACT_MESSAGE_TYPE,
|
|
615
|
-
content: buildGoalContextPrompt(goal2),
|
|
616
|
-
display: false,
|
|
617
|
-
details: { version: GOAL_CONTRACT_VERSION, goalId: goal2.id },
|
|
618
|
-
timestamp: 0
|
|
619
|
-
};
|
|
620
|
-
}
|
|
621
|
-
function reconcileGoalContextContract(messages, goal2) {
|
|
622
|
-
const summaryBoundary = leadingSummaryBoundary(messages);
|
|
623
|
-
const expected = createGoalContextContract(goal2);
|
|
624
|
-
const contractIndexes = messages.flatMap(
|
|
625
|
-
(message, index) => unwrapMessage(message).customType === GOAL_CONTRACT_MESSAGE_TYPE ? [index] : []
|
|
626
|
-
);
|
|
627
|
-
if (contractIndexes.length === 1 && contractIndexes[0] === summaryBoundary && unwrapMessage(messages[summaryBoundary]).content === expected.content) {
|
|
628
|
-
return messages;
|
|
629
|
-
}
|
|
630
|
-
const withoutContracts = messages.filter(
|
|
631
|
-
(message) => unwrapMessage(message).customType !== GOAL_CONTRACT_MESSAGE_TYPE
|
|
632
|
-
);
|
|
633
|
-
const insertionIndex = leadingSummaryBoundary(withoutContracts);
|
|
634
|
-
return [
|
|
635
|
-
...withoutContracts.slice(0, insertionIndex),
|
|
636
|
-
expected,
|
|
637
|
-
...withoutContracts.slice(insertionIndex)
|
|
638
|
-
];
|
|
639
|
-
}
|
|
640
|
-
function leadingSummaryBoundary(messages) {
|
|
641
|
-
let index = 0;
|
|
642
|
-
while (index < messages.length) {
|
|
643
|
-
const role = unwrapMessage(messages[index]).role;
|
|
644
|
-
if (role !== "compactionSummary" && role !== "branchSummary") break;
|
|
645
|
-
index += 1;
|
|
646
|
-
}
|
|
647
|
-
return index;
|
|
648
|
-
}
|
|
649
|
-
function unwrapMessage(message) {
|
|
650
|
-
const entry = message;
|
|
651
|
-
return entry?.message ?? message ?? {};
|
|
652
|
-
}
|
|
653
|
-
|
|
654
611
|
// src/lifecycle.ts
|
|
655
612
|
var REMOVED_QUEUE_SETTING_WARNING = "Ordered goal queue has been removed. Use /goal edit to reprioritize an active objective, or start /goal <objectives> if no active goal exists.";
|
|
656
613
|
var REMOVED_PERSISTED_QUEUE_WARNING = "Ordered goal queue has been removed. Start /goal <objectives> to continue with one merged objective, or use /goal clear to discard the old queue state.";
|
|
@@ -693,6 +650,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
693
650
|
if (!runtime.acquireWorkflow()) {
|
|
694
651
|
runtime.activeGoal = transitionGoal(loaded.goal, "paused");
|
|
695
652
|
runtime.persistGoal(runtime.activeGoal);
|
|
653
|
+
runtime.ensureInactiveGoalContextContract(ctx);
|
|
696
654
|
runtime.updateStatus(ctx, runtime.activeGoal);
|
|
697
655
|
notifyTerminal(
|
|
698
656
|
ctx.ui,
|
|
@@ -729,6 +687,11 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
729
687
|
}
|
|
730
688
|
runtime.persistGoal(runtime.activeGoal);
|
|
731
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
|
+
}
|
|
732
695
|
runtime.updateStatus(ctx, runtime.activeGoal);
|
|
733
696
|
runtime.restoreGoalWaitTimer(ctx);
|
|
734
697
|
return;
|
|
@@ -769,8 +732,10 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
769
732
|
}
|
|
770
733
|
if (runtime.activeGoal) {
|
|
771
734
|
runtime.persistGoal(runtime.activeGoal);
|
|
735
|
+
runtime.ensureInactiveGoalContextContract(ctx);
|
|
772
736
|
runtime.updateStatus(ctx, runtime.activeGoal);
|
|
773
737
|
} else {
|
|
738
|
+
runtime.ensureInactiveGoalContextContract(ctx);
|
|
774
739
|
ctx.ui.setStatus(STATUS_KEY, void 0);
|
|
775
740
|
}
|
|
776
741
|
});
|
|
@@ -829,8 +794,13 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
829
794
|
runtime.persistGoal(runtime.activeGoal);
|
|
830
795
|
runtime.updateStatus(ctx, runtime.activeGoal);
|
|
831
796
|
}
|
|
832
|
-
if (!usageRecorded) return;
|
|
833
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;
|
|
834
804
|
const wasPiRetry = runtime.isPiOwnedCompactionRetry(event, runtime.activeGoal.id);
|
|
835
805
|
if (wasPiRetry) return;
|
|
836
806
|
runtime.clearGoalRecoveryForGoal(runtime.activeGoal.id);
|
|
@@ -872,6 +842,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
872
842
|
return;
|
|
873
843
|
}
|
|
874
844
|
if (message.role === "custom") {
|
|
845
|
+
if (Reflect.get(message, "customType") === GOAL_CONTRACT_MESSAGE_TYPE) return;
|
|
875
846
|
if (runtime.isActiveBudgetWrapUpMessage(message)) return;
|
|
876
847
|
if (runtime.activeGoal?.waiting) runtime.clearGoalWait(ctx, runtime.activeGoal.id);
|
|
877
848
|
if (runtime.guardAbortGoalId === runtime.activeGoal?.id) {
|
|
@@ -913,7 +884,8 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
913
884
|
const keptMessages = event.messages.filter(
|
|
914
885
|
(message) => runtime.keepBudgetWrapUpMessage(message)
|
|
915
886
|
);
|
|
916
|
-
const
|
|
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;
|
|
917
889
|
if (runtime.activeGoal?.status === "paused" && runtime.guardAbortGoalId === runtime.activeGoal.id) {
|
|
918
890
|
abortCurrentTurn(ctx);
|
|
919
891
|
}
|
|
@@ -985,7 +957,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
985
957
|
const runOrigin = continuationGoalId ? "automatic" : activeGoalRecovery && runtime.goalRecovery?.automaticOwner ? "automatic" : "manual";
|
|
986
958
|
if (activeBudgetWrapUp && runtime.activeGoal) {
|
|
987
959
|
runtime.beginAgentRun(runtime.activeGoal.id, "manual");
|
|
988
|
-
return;
|
|
960
|
+
return goalContractBoundaryResult(ctx);
|
|
989
961
|
}
|
|
990
962
|
if (ownedPromptGoalId && ownedPromptGoalId !== runtime.activeGoal?.id) {
|
|
991
963
|
runtime.beginAgentRun(ownedPromptGoalId, runOrigin);
|
|
@@ -996,18 +968,19 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
996
968
|
return;
|
|
997
969
|
}
|
|
998
970
|
if (runtime.activeGoal?.status !== "active" || !runtime.ownsWorkflow(runtime.activeGoal)) {
|
|
999
|
-
return;
|
|
971
|
+
return goalContractBoundaryResult(ctx);
|
|
1000
972
|
}
|
|
1001
973
|
runtime.beginAgentRun(runtime.activeGoal.id, runOrigin);
|
|
1002
974
|
if (!runtime.toolPolicy.toolsAvailable()) {
|
|
1003
975
|
runtime.pauseGoalForUnavailableTools(ctx, ownedPromptGoalId !== void 0);
|
|
1004
|
-
return;
|
|
976
|
+
return goalContractBoundaryResult(ctx);
|
|
1005
977
|
}
|
|
1006
978
|
if (goalPrompt?.resetSafetyEpoch && goalPromptGoalId === runtime.activeGoal.id) {
|
|
1007
979
|
runtime.activeGoal = resetGoalSafetyEpoch(runtime.activeGoal);
|
|
1008
980
|
runtime.persistGoal(runtime.activeGoal);
|
|
1009
981
|
runtime.updateStatus(ctx, runtime.activeGoal);
|
|
1010
982
|
}
|
|
983
|
+
return goalContractBoundaryResult(ctx, runtime.activeGoal);
|
|
1011
984
|
});
|
|
1012
985
|
pi.on("agent_start", (_event, _ctx) => {
|
|
1013
986
|
const activeGoal = runtime.activeGoal;
|
|
@@ -1110,6 +1083,10 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
1110
1083
|
if (!resumedWait) runtime.dispatchContinuationIfSettled(ctx);
|
|
1111
1084
|
runtime.clearSettledSafetyTracking();
|
|
1112
1085
|
});
|
|
1086
|
+
function goalContractBoundaryResult(ctx, goal2) {
|
|
1087
|
+
const message = runtime.goalContextContractForPrompt(ctx, goal2);
|
|
1088
|
+
return message ? { message } : void 0;
|
|
1089
|
+
}
|
|
1113
1090
|
function beginNonGoalFollowUp(ctx, resetSafetyEpoch) {
|
|
1114
1091
|
runtime.clearGoalRecovery();
|
|
1115
1092
|
runtime.clearStaleGoalToolCallBlock();
|