@narumitw/pi-goal 0.53.3 → 0.54.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 +11 -23
- package/dist/chunks/{chunk-2ARA24RR.js → chunk-UQRRW4CY.js} +1 -7
- package/dist/chunks/{chunk-2ARA24RR.js.map → chunk-UQRRW4CY.js.map} +2 -2
- package/dist/chunks/{chunk-ZT3VZXYO.js → chunk-XHEFHXTF.js} +20 -170
- package/dist/chunks/chunk-XHEFHXTF.js.map +7 -0
- package/dist/chunks/{menu-H3C3LAQW.js → menu-4GLAABLR.js} +3 -3
- package/dist/chunks/{settings-ui-LBFJ7TOX.js → settings-ui-MVYTTBHW.js} +31 -84
- package/dist/chunks/settings-ui-MVYTTBHW.js.map +7 -0
- package/dist/index.ts +17 -89
- package/dist/index.ts.map +2 -2
- package/package.json +1 -1
- package/src/commands.ts +6 -16
- package/src/lifecycle.ts +6 -51
- package/src/runtime.ts +11 -35
- package/src/settings-ui.ts +29 -93
- package/src/settings.ts +0 -10
- package/src/tool-policy.ts +8 -171
- package/src/tools.ts +3 -28
- package/dist/chunks/chunk-ZT3VZXYO.js.map +0 -7
- package/dist/chunks/settings-ui-LBFJ7TOX.js.map +0 -7
- /package/dist/chunks/{menu-H3C3LAQW.js.map → menu-4GLAABLR.js.map} +0 -0
package/dist/index.ts
CHANGED
|
@@ -43,7 +43,7 @@ import {
|
|
|
43
43
|
stoppedStatusLabel,
|
|
44
44
|
transitionGoal,
|
|
45
45
|
validateObjective
|
|
46
|
-
} from "./chunks/chunk-
|
|
46
|
+
} from "./chunks/chunk-XHEFHXTF.js";
|
|
47
47
|
import {
|
|
48
48
|
DEFAULT_GOAL_SETTINGS,
|
|
49
49
|
currentTokenTotal,
|
|
@@ -58,15 +58,15 @@ import {
|
|
|
58
58
|
safeGoalMenuText,
|
|
59
59
|
safeTerminalText,
|
|
60
60
|
truncateNotification
|
|
61
|
-
} from "./chunks/chunk-
|
|
61
|
+
} from "./chunks/chunk-UQRRW4CY.js";
|
|
62
62
|
|
|
63
63
|
// src/command-registration.ts
|
|
64
64
|
function registerGoalCommand(pi, runtime, commands, options = {}) {
|
|
65
65
|
const loadGoalManager = cachedModuleLoader(
|
|
66
|
-
options.loadGoalManager ?? (() => import("./chunks/menu-
|
|
66
|
+
options.loadGoalManager ?? (() => import("./chunks/menu-4GLAABLR.js"))
|
|
67
67
|
);
|
|
68
68
|
const loadGoalSettings = cachedModuleLoader(
|
|
69
|
-
options.loadGoalSettings ?? (() => import("./chunks/settings-ui-
|
|
69
|
+
options.loadGoalSettings ?? (() => import("./chunks/settings-ui-MVYTTBHW.js"))
|
|
70
70
|
);
|
|
71
71
|
pi.registerCommand("goal", {
|
|
72
72
|
description: "Run a goal to completion: /goal [--tokens 100k] <goal_to_complete>",
|
|
@@ -201,9 +201,8 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
|
|
|
201
201
|
const retainedOwner = this.runtime.ownsWorkflow(existingGoal);
|
|
202
202
|
if (!this.runtime.acquireWorkflow(ctx.sessionManager)) return this.reportWorkflowBusy(ctx);
|
|
203
203
|
const acquiredForRequest = !retainedOwner;
|
|
204
|
-
const goalToolVisibilityBeforeActivation = this.runtime.toolPolicy.snapshot();
|
|
205
204
|
try {
|
|
206
|
-
this.runtime.
|
|
205
|
+
this.runtime.assertGoalToolsAvailable();
|
|
207
206
|
} catch (error) {
|
|
208
207
|
notifyTerminal(ctx.ui, `Cannot start /goal: ${formatError(error)}`, "error");
|
|
209
208
|
if (existingGoal?.status === "active") this.runtime.pauseGoalForUnavailableTools(ctx);
|
|
@@ -278,7 +277,6 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
|
|
|
278
277
|
}
|
|
279
278
|
}
|
|
280
279
|
if (rolledBackStartedGoal) {
|
|
281
|
-
this.runtime.toolPolicy.restore(goalToolVisibilityBeforeActivation);
|
|
282
280
|
if (acquiredForRequest && !this.runtime.ownsWorkflow(existingGoal)) {
|
|
283
281
|
this.runtime.releaseWorkflow();
|
|
284
282
|
}
|
|
@@ -343,9 +341,8 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
|
|
|
343
341
|
this.reportWorkflowBusy(ctx);
|
|
344
342
|
return;
|
|
345
343
|
}
|
|
346
|
-
const goalToolVisibilityBeforeActivation = this.runtime.toolPolicy.snapshot();
|
|
347
344
|
try {
|
|
348
|
-
this.runtime.
|
|
345
|
+
this.runtime.assertGoalToolsAvailable();
|
|
349
346
|
} catch (error) {
|
|
350
347
|
notifyTerminal(ctx.ui, `Cannot resume /goal: ${formatError(error)}`, "error");
|
|
351
348
|
this.runtime.releaseWorkflow();
|
|
@@ -387,7 +384,6 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
|
|
|
387
384
|
if (blocksStaleGoalToolCalls(this.runtime.activeGoal.status)) {
|
|
388
385
|
this.runtime.blockStaleGoalToolCalls();
|
|
389
386
|
}
|
|
390
|
-
this.runtime.toolPolicy.restore(goalToolVisibilityBeforeActivation);
|
|
391
387
|
this.runtime.releaseWorkflow();
|
|
392
388
|
}
|
|
393
389
|
return;
|
|
@@ -409,7 +405,7 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
|
|
|
409
405
|
return;
|
|
410
406
|
}
|
|
411
407
|
try {
|
|
412
|
-
this.runtime.
|
|
408
|
+
this.runtime.assertGoalToolsAvailable();
|
|
413
409
|
} catch (error) {
|
|
414
410
|
notifyTerminal(ctx.ui, `Cannot resume /goal: ${formatError(error)}`, "error");
|
|
415
411
|
return;
|
|
@@ -482,10 +478,9 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
|
|
|
482
478
|
return;
|
|
483
479
|
}
|
|
484
480
|
const acquiredForEdit = intendsActive && !retainedOwner;
|
|
485
|
-
const goalToolVisibilityBeforeActivation = intendsActive ? this.runtime.toolPolicy.snapshot() : void 0;
|
|
486
481
|
if (intendsActive) {
|
|
487
482
|
try {
|
|
488
|
-
this.runtime.
|
|
483
|
+
this.runtime.assertGoalToolsAvailable();
|
|
489
484
|
} catch (error) {
|
|
490
485
|
notifyTerminal(ctx.ui, `Cannot reactivate /goal: ${formatError(error)}`, "error");
|
|
491
486
|
if (currentGoal.status === "active") this.runtime.pauseGoalForUnavailableTools(ctx);
|
|
@@ -548,9 +543,6 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
|
|
|
548
543
|
this.runtime.persistGoal(this.runtime.activeGoal);
|
|
549
544
|
this.runtime.updateStatus(ctx, this.runtime.activeGoal);
|
|
550
545
|
}
|
|
551
|
-
if (goalToolVisibilityBeforeActivation) {
|
|
552
|
-
this.runtime.toolPolicy.restore(goalToolVisibilityBeforeActivation);
|
|
553
|
-
}
|
|
554
546
|
if (acquiredForEdit && previousStatus !== "active") {
|
|
555
547
|
this.runtime.releaseWorkflow();
|
|
556
548
|
}
|
|
@@ -627,7 +619,6 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
627
619
|
runtime.legacyQueueState = void 0;
|
|
628
620
|
runtime.legacyExperimentalGoalsSetting = false;
|
|
629
621
|
runtime.clearTerminalDetails();
|
|
630
|
-
const previousToolVisibility = runtime.settings.toolVisibility;
|
|
631
622
|
const settingsResult = readGoalSettings(options.settingsPath);
|
|
632
623
|
const loaded = loadGoalStateFromSession(ctx);
|
|
633
624
|
runtime.settings = settingsResult.kind === "loaded" ? settingsResult.settings : DEFAULT_GOAL_SETTINGS;
|
|
@@ -660,18 +651,6 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
660
651
|
return;
|
|
661
652
|
}
|
|
662
653
|
runtime.activeGoal = loaded.goal;
|
|
663
|
-
try {
|
|
664
|
-
runtime.toolPolicy.prepareSessionStart(
|
|
665
|
-
runtime.settings.toolVisibility,
|
|
666
|
-
previousToolVisibility
|
|
667
|
-
);
|
|
668
|
-
} catch (error) {
|
|
669
|
-
notifyTerminal(
|
|
670
|
-
ctx.ui,
|
|
671
|
-
`Could not restore always-visible goal tools: ${formatError(error)}`,
|
|
672
|
-
"error"
|
|
673
|
-
);
|
|
674
|
-
}
|
|
675
654
|
if (runtime.activeGoal.safetyResetPending) {
|
|
676
655
|
runtime.activeGoal = resetGoalSafetyEpoch(runtime.activeGoal);
|
|
677
656
|
}
|
|
@@ -680,8 +659,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
680
659
|
if (runtime.enforceAutomaticTurnLimit(ctx, false) || runtime.enforceNoProgressLimit(ctx)) {
|
|
681
660
|
return;
|
|
682
661
|
}
|
|
683
|
-
runtime.
|
|
684
|
-
if (!runtime.toolPolicy.toolsAvailable()) {
|
|
662
|
+
if (!runtime.goalToolsAvailable()) {
|
|
685
663
|
runtime.pauseGoalForUnavailableTools(ctx, false);
|
|
686
664
|
return;
|
|
687
665
|
}
|
|
@@ -697,34 +675,6 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
697
675
|
return;
|
|
698
676
|
}
|
|
699
677
|
runtime.activeGoal = loaded.goal;
|
|
700
|
-
let appliedInactivePolicy = false;
|
|
701
|
-
let inactivePolicyFailed = false;
|
|
702
|
-
try {
|
|
703
|
-
appliedInactivePolicy = runtime.withTemporaryWorkflowAccess(() => {
|
|
704
|
-
runtime.toolPolicy.prepareSessionStart(
|
|
705
|
-
runtime.settings.toolVisibility,
|
|
706
|
-
previousToolVisibility
|
|
707
|
-
);
|
|
708
|
-
runtime.toolPolicy.reconcileRestoredState(
|
|
709
|
-
runtime.settings.toolVisibility,
|
|
710
|
-
runtime.activeGoal !== void 0 && runtime.legacyQueueState === void 0
|
|
711
|
-
);
|
|
712
|
-
});
|
|
713
|
-
} catch (error) {
|
|
714
|
-
inactivePolicyFailed = true;
|
|
715
|
-
notifyTerminal(
|
|
716
|
-
ctx.ui,
|
|
717
|
-
`Could not restore always-visible goal tools: ${formatError(error)}`,
|
|
718
|
-
"error"
|
|
719
|
-
);
|
|
720
|
-
}
|
|
721
|
-
if (!appliedInactivePolicy && !inactivePolicyFailed) {
|
|
722
|
-
notifyTerminal(
|
|
723
|
-
ctx.ui,
|
|
724
|
-
"Goal tool visibility was deferred because another workflow is active in this session.",
|
|
725
|
-
"warning"
|
|
726
|
-
);
|
|
727
|
-
}
|
|
728
678
|
if (runtime.legacyQueueState) {
|
|
729
679
|
ctx.ui.setStatus(STATUS_KEY, void 0);
|
|
730
680
|
notifyTerminal(ctx.ui, REMOVED_PERSISTED_QUEUE_WARNING, "warning");
|
|
@@ -925,7 +875,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
925
875
|
runtime.persistGoal(runtime.activeGoal);
|
|
926
876
|
runtime.updateStatus(ctx, runtime.activeGoal);
|
|
927
877
|
if (runtime.limitActiveGoalForBudget(ctx, true)) return;
|
|
928
|
-
if (!runtime.
|
|
878
|
+
if (!runtime.goalToolsAvailable()) runtime.pauseGoalForUnavailableTools(ctx);
|
|
929
879
|
});
|
|
930
880
|
pi.on("before_agent_start", (event, ctx) => {
|
|
931
881
|
runtime.clearAgentRun();
|
|
@@ -961,7 +911,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
961
911
|
}
|
|
962
912
|
if (ownedPromptGoalId && ownedPromptGoalId !== runtime.activeGoal?.id) {
|
|
963
913
|
runtime.beginAgentRun(ownedPromptGoalId, runOrigin);
|
|
964
|
-
if (runtime.activeGoal?.status === "active" && !runtime.
|
|
914
|
+
if (runtime.activeGoal?.status === "active" && !runtime.goalToolsAvailable()) {
|
|
965
915
|
runtime.pauseGoalForUnavailableTools(ctx, false);
|
|
966
916
|
}
|
|
967
917
|
abortCurrentTurn(ctx);
|
|
@@ -971,7 +921,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
971
921
|
return goalContractBoundaryResult(ctx);
|
|
972
922
|
}
|
|
973
923
|
runtime.beginAgentRun(runtime.activeGoal.id, runOrigin);
|
|
974
|
-
if (!runtime.
|
|
924
|
+
if (!runtime.goalToolsAvailable()) {
|
|
975
925
|
runtime.pauseGoalForUnavailableTools(ctx, ownedPromptGoalId !== void 0);
|
|
976
926
|
return goalContractBoundaryResult(ctx);
|
|
977
927
|
}
|
|
@@ -1027,7 +977,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
1027
977
|
if (isRetryableGoalInterruption(finalAssistant)) {
|
|
1028
978
|
if (run.origin === "automatic" && runtime.enforceAutomaticTurnLimit(ctx, true)) return;
|
|
1029
979
|
if (runtime.limitActiveGoalForBudget(ctx, false)) return;
|
|
1030
|
-
if (!runtime.
|
|
980
|
+
if (!runtime.goalToolsAvailable()) {
|
|
1031
981
|
runtime.pauseGoalForUnavailableTools(ctx);
|
|
1032
982
|
return;
|
|
1033
983
|
}
|
|
@@ -1053,7 +1003,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
1053
1003
|
}
|
|
1054
1004
|
runtime.clearGoalRecoveryForGoal(goalId);
|
|
1055
1005
|
if (runtime.limitActiveGoalForBudget(ctx, false)) return;
|
|
1056
|
-
if (!runtime.
|
|
1006
|
+
if (!runtime.goalToolsAvailable()) {
|
|
1057
1007
|
runtime.pauseGoalForUnavailableTools(ctx);
|
|
1058
1008
|
return;
|
|
1059
1009
|
}
|
|
@@ -1421,14 +1371,7 @@ function registerGoalTools(pi, runtime) {
|
|
|
1421
1371
|
const goalCompleteTool = defineTool({
|
|
1422
1372
|
name: GOAL_COMPLETE_TOOL,
|
|
1423
1373
|
label: "Goal Complete",
|
|
1424
|
-
description: "Mark
|
|
1425
|
-
promptSnippet: "Mark the active /goal as complete after fully finishing and verifying it, with the current goal_id",
|
|
1426
|
-
promptGuidelines: [
|
|
1427
|
-
"When a /goal is active, keep working until the goal is complete; do not stop with only a plan or partial progress.",
|
|
1428
|
-
"Before calling goal_complete, audit the active goal requirement by requirement against the current files, command output, tests, or external state.",
|
|
1429
|
-
"Pass the exact goal_id shown in the current /goal prompt; never reuse a goal_id from an older, stopped, replaced, or cleared turn.",
|
|
1430
|
-
"Call goal_complete only after the requested goal is fully implemented, verified, and no known required work remains; otherwise keep working."
|
|
1431
|
-
],
|
|
1374
|
+
description: "Mark an active /goal complete only when the latest effective Goal contract explicitly says Goal mode is active, supplies the matching current goal_id, and every requirement is verified. Tool visibility alone does not activate Goal mode. Never call for ordinary work, partial progress, blockers, failures, or unverified work.",
|
|
1432
1375
|
parameters: Type.Object({
|
|
1433
1376
|
goal_id: Type.String({
|
|
1434
1377
|
minLength: 1,
|
|
@@ -1528,14 +1471,7 @@ function registerGoalTools(pi, runtime) {
|
|
|
1528
1471
|
const goalBlockedTool = defineTool({
|
|
1529
1472
|
name: GOAL_BLOCKED_TOOL,
|
|
1530
1473
|
label: "Goal Blocked",
|
|
1531
|
-
description: "Stop
|
|
1532
|
-
promptSnippet: "Mark the active /goal blocked only after the same blocker recurs for three consecutive goal turns",
|
|
1533
|
-
promptGuidelines: [
|
|
1534
|
-
"Use goal_blocked only for a true impasse after the same blocker recurs for at least three consecutive goal turns and concrete evidence shows user or external action is required.",
|
|
1535
|
-
"After a blocked goal is resumed, start a fresh three-turn blocker audit before using goal_blocked again.",
|
|
1536
|
-
"Do not use goal_blocked for ordinary clarification, incomplete work, uncertainty, difficult tasks, or recoverable tool/provider failures.",
|
|
1537
|
-
"Pass goal_blocked the exact current goal_id; never reuse a goal_id from an older, stopped, replaced, or cleared goal turn."
|
|
1538
|
-
],
|
|
1474
|
+
description: "Stop an active /goal only when the latest effective Goal contract explicitly says Goal mode is active, supplies the matching current goal_id, and the same evidenced external blocker recurred for at least three consecutive Goal turns. Tool visibility alone does not activate Goal mode. Never call for ordinary clarification, uncertainty, incomplete work, or recoverable failures.",
|
|
1539
1475
|
parameters: Type.Object({
|
|
1540
1476
|
goal_id: Type.String({
|
|
1541
1477
|
minLength: 1,
|
|
@@ -1607,15 +1543,7 @@ function registerGoalTools(pi, runtime) {
|
|
|
1607
1543
|
const goalWaitTool = defineTool({
|
|
1608
1544
|
name: GOAL_WAIT_TOOL,
|
|
1609
1545
|
label: "Goal Wait",
|
|
1610
|
-
description: `Keep
|
|
1611
|
-
promptSnippet: "Wait quietly for an external event without stopping the active /goal or starting automatic continuations",
|
|
1612
|
-
promptGuidelines: [
|
|
1613
|
-
"Use goal_wait only when progress depends on a later non-goal message, or when resume_after_ms provides a bounded safety wake-up rather than a polling interval.",
|
|
1614
|
-
`Prefer longer waits measured in minutes to avoid busy polling; goal_wait requests below ${MIN_GOAL_WAIT_DELAY_MS}ms are clamped to ${MIN_GOAL_WAIT_DELAY_MS}ms.`,
|
|
1615
|
-
"Arrange the external monitor or wake source before calling goal_wait, and call goal_wait alone because parallel sibling tools can prevent immediate turn termination.",
|
|
1616
|
-
"Pass the exact current goal_id so a stale turn cannot put a replacement goal into waiting.",
|
|
1617
|
-
"Do not use goal_blocked for a recoverable external wait that can be resumed by a message or deadline."
|
|
1618
|
-
],
|
|
1546
|
+
description: `Keep an active /goal quiet only when the latest effective Goal contract explicitly says Goal mode is active, supplies the matching current goal_id, and progress depends on an arranged external wake event or one safety deadline. Tool visibility alone does not activate Goal mode. Call goal_wait alone. Requests below ${MIN_GOAL_WAIT_DELAY_MS}ms are clamped to ${MIN_GOAL_WAIT_DELAY_MS}ms. Never call for ordinary unfinished work.`,
|
|
1619
1547
|
parameters: Type.Object({
|
|
1620
1548
|
goal_id: Type.String({
|
|
1621
1549
|
minLength: 1,
|