@narumitw/pi-goal 0.54.15 → 0.54.17
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/CHANGELOG.md +15 -0
- package/README.md +25 -7
- package/dist/chunks/{chunk-SL6SIIVB.ts → chunk-MHW7VEET.ts} +41 -21
- package/dist/chunks/chunk-MHW7VEET.ts.map +7 -0
- package/dist/chunks/{chunk-RNWM7MOG.ts → chunk-ZLKWPYIF.ts} +2 -13
- package/dist/chunks/chunk-ZLKWPYIF.ts.map +7 -0
- package/dist/chunks/{menu-H43NPYIW.ts → menu-3AYWQ637.ts} +3 -3
- package/dist/chunks/{settings-ui-T77VFPTK.ts → settings-ui-RVQTWGJ5.ts} +2 -2
- package/dist/index.ts +76 -43
- package/dist/index.ts.map +2 -2
- package/docs/continuation-lifecycle.md +62 -15
- package/package.json +2 -2
- package/src/errors.ts +2 -16
- package/src/lifecycle.ts +91 -41
- package/src/persistence.ts +2 -1
- package/src/runtime.ts +70 -21
- package/dist/chunks/chunk-RNWM7MOG.ts.map +0 -7
- package/dist/chunks/chunk-SL6SIIVB.ts.map +0 -7
- /package/dist/chunks/{menu-H43NPYIW.ts.map → menu-3AYWQ637.ts.map} +0 -0
- /package/dist/chunks/{settings-ui-T77VFPTK.ts.map → settings-ui-RVQTWGJ5.ts.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @narumitw/pi-goal
|
|
2
2
|
|
|
3
|
+
## 0.54.17
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5f92841: Use Pi's native provider retry and context-overflow classifiers without Goal-owned retry patterns or usage/authentication vetoes. Keep unclassified assistant errors in deadline-free active waiting without adding a retry, including premature stream closures, invalid requests, authentication failures, and empty error messages. Preserve Goal identity and managed-run ownership until wake, completion, or explicit cancellation; permanent failures can wait indefinitely. Select final recognized usage limits after native recovery, and pause when Pi reports a cancelled run or automatic compaction. Preserve active waiting after native retry-only cancellation; use `/goal pause` for an explicit pause. Keep safety limits and automatic accounting through native truncated-response compaction. Preserve pending errors across threshold compaction and block failed native compaction recovery.
|
|
8
|
+
|
|
9
|
+
## 0.54.16
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 5c09977: Treat prematurely closed connections and prematurely ended streams as retryable Goal interruptions, including proxy-wrapped HTTP 400 errors. Keep the Goal active through the existing provider-recovery wait instead of marking it blocked.
|
|
14
|
+
- 6c843a2: Store independent Goal state snapshots in session history so later accounting and waiting-state updates do not change earlier entries. Keep in-memory history aligned with JSONL records and preserve append-time state during deferred writes and branch restoration.
|
|
15
|
+
- Updated dependencies [4f79c28]
|
|
16
|
+
- @narumitw/pi-tui-kit@0.69.1
|
|
17
|
+
|
|
3
18
|
## 0.54.15
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Explicit completion, blocker, and wait tools give each managed run a clear stopp
|
|
|
10
10
|
|
|
11
11
|
- Starts and manages one session goal through `/goal` and its status, pause, resume, edit, and clear routes.
|
|
12
12
|
- Continues exactly once from Pi's settled idle boundary after queued work, retries, and compaction have finished.
|
|
13
|
-
- Waits quietly
|
|
13
|
+
- Waits quietly after exhausted retries or unclassified provider errors without adding a retry attempt.
|
|
14
14
|
- Uses explicit `goal_complete`, `goal_blocked`, and `goal_wait` tools with stale-goal guards and evidence requirements.
|
|
15
15
|
- Renders an accepted `goal_complete` summary as Markdown in the TUI.
|
|
16
16
|
- Tracks active, paused, blocked, usage-limited, budget-limited, waiting, and complete outcomes separately.
|
|
@@ -277,8 +277,10 @@ An accepted call keeps the canonical Goal status active, checkpoints active elap
|
|
|
277
277
|
It persists the reason and optional absolute deadline and terminates the normal single-tool run.
|
|
278
278
|
Call `goal_wait` alone because Pi only guarantees early termination when every finalized result in a parallel tool batch terminates.
|
|
279
279
|
|
|
280
|
-
|
|
281
|
-
|
|
280
|
+
After Pi finishes handling a provider error, pi-goal enters the same active waiting state without a deadline unless cancellation, an explicit usage limit, a failed compaction recovery, or a Goal safety limit requires a stopped state.
|
|
281
|
+
This applies to exhausted, disabled, or zero-budget retries and to errors Pi does not classify for retry; Goal never adds a retry attempt.
|
|
282
|
+
The warning reports bounded provider status and explains how a follow-up or `/goal resume` wakes the Goal.
|
|
283
|
+
An already accepted `goal_wait` keeps its reason and deadline if a later assistant error occurs; the provider error does not replace that wait.
|
|
282
284
|
Context-overflow compaction exhaustion remains blocked because another model turn can repeat the same oversized request without corrective compaction.
|
|
283
285
|
|
|
284
286
|
Interactive input, RPC input, another extension's `sendUserMessage()` input, and supported non-Goal custom follow-ups clear the wait before their turn runs.
|
|
@@ -297,7 +299,7 @@ If that delivery throws, pi-goal restores the wait, retries once after one secon
|
|
|
297
299
|
A deadline never sends a prompt directly from a stale timer.
|
|
298
300
|
|
|
299
301
|
Waiting time is excluded from **Active elapsed**, while tokens, iteration, automatic-response count, no-progress state, and managed-run ownership remain preserved.
|
|
300
|
-
The managed-run protocol continues reporting `active` without a duplicate state event because waiting is non-terminal, including after
|
|
302
|
+
The managed-run protocol continues reporting `active` without a duplicate state event because waiting is non-terminal, including after exhausted retries or an unclassified provider error.
|
|
301
303
|
Editing or replacing a waiting Goal clears the previous wait so the updated objective performs a fresh external-state check.
|
|
302
304
|
|
|
303
305
|
## 🚧 Blocked goals
|
|
@@ -318,16 +320,32 @@ The user can resolve the external condition and run `/goal resume` to rotate the
|
|
|
318
320
|
|
|
319
321
|
## 🛑 Interruption and queued-input behavior
|
|
320
322
|
|
|
321
|
-
A user pause or aborted turn produces `paused`; a
|
|
323
|
+
A user pause or aborted turn produces `paused`; a final recognized provider/account quota error produces `usage_limited`; failed native compaction recovery produces `blocked`.
|
|
322
324
|
Each stopped transition cancels pending continuation intent or delivery and aborts stale work when applicable.
|
|
323
325
|
Stale tool calls remain blocked until the next non-goal user prompt, successful reactivation or replacement, or `/goal clear`.
|
|
324
326
|
On `/goal clear`, the extension clears goal state, continuation markers, and any stale tool-call block without aborting an unrelated in-flight turn.
|
|
325
|
-
|
|
327
|
+
Pi decides provider retry and context-overflow eligibility through its native classifiers.
|
|
328
|
+
Its retry settings control provider retry attempts; native compact-and-retry recovery uses Pi's compaction settings and separate recovery limit.
|
|
329
|
+
Goal adds no retry patterns or retry loop. Its usage-limit policy selects the final status without preventing recovery that Pi permits.
|
|
330
|
+
An unclassified assistant error, including `Connection prematurely closed BEFORE response`, stays active until settlement and then enters deadline-free waiting even when Pi does not retry it.
|
|
331
|
+
This intentionally also applies to invalid-request, authentication, permission, empty-message, and unrecognized account-limit errors that do not match the existing usage-limit policy.
|
|
332
|
+
These errors can wait indefinitely and retain managed-run and Workflow Mutex ownership; use `/goal pause` or managed-run cancellation to stop them.
|
|
333
|
+
Waiting does not repair an invalid request or guarantee recovery. A later external message can wake the same failing request and incur another provider charge.
|
|
334
|
+
Pi's native classifiers and Goal's existing usage-limit classifier still use regular expressions; removing Goal retry patterns does not make the full stack regex-free.
|
|
335
|
+
|
|
336
|
+
Native provider retries and overflow or truncated-response compaction retries stay `active` while Pi recovers.
|
|
326
337
|
No extra continuation is queued, and automatic ownership remains charged through retry `agent_start` events.
|
|
327
|
-
|
|
338
|
+
At `agent_settled`, reported cancellation takes precedence, including a full session abort during retry backoff without another assistant response.
|
|
339
|
+
An aborted automatic compaction also pauses its matching Goal through Pi's compaction failure event.
|
|
340
|
+
A final recognized usage limit selects `usage_limited`; otherwise remaining provider retry or unclassified-error recovery enters a deadline-free active wait before any continuation dispatches.
|
|
328
341
|
A later non-Goal input wakes the same Goal without rotating its stale-turn guard, so the model can continue, complete, or enter another wait with the current `goal_id`.
|
|
329
342
|
If matching compaction recovery still exists at `agent_settled`, the Goal becomes `blocked` because recovery did not produce usable context.
|
|
330
343
|
Stale recovery cannot wait or block a replacement goal.
|
|
344
|
+
|
|
345
|
+
Native retry-only cancellation (Escape during backoff or RPC `abort_retry`) stops further retries but does not itself pause the Goal.
|
|
346
|
+
For a transient non-usage failure, it preserves the same deadline-free active wait as exhausted retries: no extra request is sent, and a later follow-up or `/goal resume` can wake the same Goal.
|
|
347
|
+
Use `/goal pause` or a full session abort to pause the Goal instead.
|
|
348
|
+
|
|
331
349
|
User and extension work that starts before settlement supersedes the older continuation intent, and pending messages always take priority.
|
|
332
350
|
|
|
333
351
|
## 🤝 Managed run RPC
|
|
@@ -8,13 +8,14 @@ import {
|
|
|
8
8
|
formatTokenCount,
|
|
9
9
|
isNonNegativeFiniteNumber,
|
|
10
10
|
isStaleContextError,
|
|
11
|
+
isUsageLimitedGoalInterruption,
|
|
11
12
|
nonNegativeFiniteNumber,
|
|
12
13
|
normalizeTokenBudget,
|
|
13
14
|
notifyTerminal,
|
|
14
15
|
safeGoalMenuText,
|
|
15
16
|
truncateNotification,
|
|
16
17
|
updateGoalUsage
|
|
17
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-ZLKWPYIF.ts";
|
|
18
19
|
|
|
19
20
|
// src/command.ts
|
|
20
21
|
var MAX_OBJECTIVE_LENGTH = 4e3;
|
|
@@ -437,7 +438,7 @@ var GOAL_STATE_ENTRY_TYPE = "goal-state";
|
|
|
437
438
|
var LEGACY_GOALS_STATE_ENTRY_TYPE = "goals-state";
|
|
438
439
|
var STATE_FILE = join(getAgentDir(), "pi-goal-state.json");
|
|
439
440
|
function serializeGoalState(goal) {
|
|
440
|
-
return { goal: goal
|
|
441
|
+
return { goal: goal ? structuredClone(goal) : null };
|
|
441
442
|
}
|
|
442
443
|
function loadGoalStateFromSession(ctx) {
|
|
443
444
|
const entries = ctx.sessionManager?.getBranch?.() ?? ctx.sessionManager?.getEntries?.() ?? [];
|
|
@@ -760,6 +761,9 @@ var GoalRuntime = class {
|
|
|
760
761
|
continuationIntent;
|
|
761
762
|
continuationDelivery;
|
|
762
763
|
goalRecovery;
|
|
764
|
+
// Unconfirmed length recovery is invalidated by the same runtime transitions
|
|
765
|
+
// as provider errors, including a later accepted goal_wait.
|
|
766
|
+
pendingLengthRecovery;
|
|
763
767
|
budgetWrapUp;
|
|
764
768
|
/** `null` marks a run that must not be charged to the active goal. */
|
|
765
769
|
agentRunGoalId;
|
|
@@ -1091,12 +1095,12 @@ var GoalRuntime = class {
|
|
|
1091
1095
|
status = "paused";
|
|
1092
1096
|
terminalReason = request.reason;
|
|
1093
1097
|
break;
|
|
1094
|
-
case "
|
|
1098
|
+
case "recovery_ended":
|
|
1095
1099
|
this.clearGoalRecoveryForGoal(goal.id);
|
|
1096
1100
|
this.cancelContinuationWork();
|
|
1097
1101
|
this.clearBudgetWrapUp();
|
|
1098
1102
|
this.blockStaleGoalToolCalls();
|
|
1099
|
-
status =
|
|
1103
|
+
status = request.status;
|
|
1100
1104
|
terminalReason = request.reason;
|
|
1101
1105
|
break;
|
|
1102
1106
|
case "tools_unavailable":
|
|
@@ -1155,6 +1159,7 @@ var GoalRuntime = class {
|
|
|
1155
1159
|
}
|
|
1156
1160
|
clearGoalRecovery() {
|
|
1157
1161
|
this.goalRecovery = void 0;
|
|
1162
|
+
this.pendingLengthRecovery = void 0;
|
|
1158
1163
|
}
|
|
1159
1164
|
clearBudgetWrapUp() {
|
|
1160
1165
|
this.budgetWrapUp = void 0;
|
|
@@ -1239,9 +1244,11 @@ var GoalRuntime = class {
|
|
|
1239
1244
|
goal.toolFreeRepeatCount = next.toolFreeRepeatCount;
|
|
1240
1245
|
goal.lastToolFreeOutputFingerprint = next.lastToolFreeOutputFingerprint;
|
|
1241
1246
|
this.persistGoal(goal);
|
|
1242
|
-
this.
|
|
1247
|
+
const currentGoal = this.activeGoal;
|
|
1248
|
+
if (currentGoal?.id !== goalId || !this.ownsWorkflow(currentGoal)) return true;
|
|
1249
|
+
this.updateStatus(ctx, currentGoal);
|
|
1243
1250
|
const limit = this.settings.continuationLimits.noProgressTurns;
|
|
1244
|
-
if (limit === null ||
|
|
1251
|
+
if (limit === null || currentGoal.toolFreeRepeatCount < limit) return false;
|
|
1245
1252
|
return this.pauseGoalForSafety(ctx, "no_progress", false);
|
|
1246
1253
|
}
|
|
1247
1254
|
enforceAutomaticTurnLimit(ctx, abortTurn) {
|
|
@@ -1289,38 +1296,48 @@ var GoalRuntime = class {
|
|
|
1289
1296
|
this.updateStatus(ctx, this.activeGoal);
|
|
1290
1297
|
return true;
|
|
1291
1298
|
}
|
|
1292
|
-
finalizeSettledRecovery(ctx) {
|
|
1299
|
+
finalizeSettledRecovery(ctx, aborted, settledGoalId) {
|
|
1293
1300
|
const recovery = this.goalRecovery;
|
|
1294
|
-
if (!recovery) return false;
|
|
1301
|
+
if (!recovery && !aborted) return false;
|
|
1295
1302
|
this.goalRecovery = void 0;
|
|
1296
1303
|
const goal = this.activeGoal;
|
|
1297
|
-
if (goal
|
|
1304
|
+
if (!goal || goal.id !== (recovery?.goalId ?? settledGoalId) || !this.ownsWorkflow(goal)) {
|
|
1298
1305
|
return false;
|
|
1299
1306
|
}
|
|
1300
|
-
const details = recovery
|
|
1301
|
-
|
|
1307
|
+
const details = recovery?.errorMessage ? `: ${truncateNotification(recovery.errorMessage)}` : "";
|
|
1308
|
+
const usageLimited = isUsageLimitedGoalInterruption({
|
|
1309
|
+
role: "assistant",
|
|
1310
|
+
stopReason: "error",
|
|
1311
|
+
errorMessage: recovery?.errorMessage
|
|
1312
|
+
});
|
|
1313
|
+
if (!aborted && !usageLimited && recovery && recovery.kind !== "compaction_retry") {
|
|
1314
|
+
if (this.enforceAutomaticTurnLimit(ctx, false) || this.enforceNoProgressLimit(ctx) || this.limitActiveGoalForBudget(ctx, false)) {
|
|
1315
|
+
return true;
|
|
1316
|
+
}
|
|
1317
|
+
if (!this.goalToolsAvailable()) return this.pauseGoalForUnavailableTools(ctx, false);
|
|
1318
|
+
if (goal.waiting) return true;
|
|
1319
|
+
const nativeRetry = recovery.kind === "provider_retry";
|
|
1302
1320
|
const waitingGoal = this.enterGoalWait(ctx, goal.id, {
|
|
1303
|
-
reason:
|
|
1321
|
+
reason: `${nativeRetry ? "Provider retries exhausted" : "Provider error"}${details}`
|
|
1304
1322
|
});
|
|
1305
1323
|
if (!waitingGoal) return false;
|
|
1306
1324
|
notifyTerminal(
|
|
1307
1325
|
ctx.ui,
|
|
1308
|
-
`Goal waiting after provider retries were exhausted${details}. Send a follow-up or run /goal resume to retry.`,
|
|
1326
|
+
nativeRetry ? `Goal waiting after provider retries were exhausted${details}. Send a follow-up or run /goal resume to retry.` : `Goal waiting after a provider error${details}. No automatic retry was added. Send a follow-up or run /goal resume to continue.`,
|
|
1309
1327
|
"warning"
|
|
1310
1328
|
);
|
|
1311
1329
|
return true;
|
|
1312
1330
|
}
|
|
1331
|
+
const status = aborted ? "paused" : usageLimited ? "usage_limited" : "blocked";
|
|
1313
1332
|
const stoppedGoal = this.stopActiveGoal(ctx, {
|
|
1314
|
-
kind: "
|
|
1333
|
+
kind: "recovery_ended",
|
|
1315
1334
|
expectedGoalId: goal.id,
|
|
1316
|
-
|
|
1335
|
+
status,
|
|
1336
|
+
reason: aborted ? "goal paused after agent interruption" : `agent error after retries${details}`
|
|
1317
1337
|
});
|
|
1318
1338
|
if (!stoppedGoal) return false;
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
`Goal blocked after agent error retries were exhausted${details}. Resolve the blocker or run /goal resume to retry.`,
|
|
1322
|
-
"warning"
|
|
1323
|
-
);
|
|
1339
|
+
const message = aborted ? "Goal paused after interruption. Run /goal resume to continue." : usageLimited ? `Goal stopped after provider usage limit${details}. Run /goal resume when usage is available.` : `Goal blocked after agent error retries were exhausted${details}. Resolve the blocker or run /goal resume to retry.`;
|
|
1340
|
+
notifyTerminal(ctx.ui, message, "warning");
|
|
1324
1341
|
return true;
|
|
1325
1342
|
}
|
|
1326
1343
|
clearSettledSafetyTracking() {
|
|
@@ -1332,6 +1349,7 @@ var GoalRuntime = class {
|
|
|
1332
1349
|
}
|
|
1333
1350
|
clearGoalRecoveryForGoal(goalId) {
|
|
1334
1351
|
if (this.goalRecovery?.goalId === goalId) this.goalRecovery = void 0;
|
|
1352
|
+
if (this.pendingLengthRecovery?.goalId === goalId) this.pendingLengthRecovery = void 0;
|
|
1335
1353
|
}
|
|
1336
1354
|
isPiOwnedCompactionRetry(event, goalId) {
|
|
1337
1355
|
const compaction = event;
|
|
@@ -1601,6 +1619,7 @@ var GoalRuntime = class {
|
|
|
1601
1619
|
continuationIntent: this.continuationIntent ? structuredClone(this.continuationIntent) : void 0,
|
|
1602
1620
|
continuationDelivery: this.continuationDelivery ? structuredClone(this.continuationDelivery) : void 0,
|
|
1603
1621
|
goalRecovery: this.goalRecovery ? structuredClone(this.goalRecovery) : void 0,
|
|
1622
|
+
pendingLengthRecovery: this.pendingLengthRecovery ? structuredClone(this.pendingLengthRecovery) : void 0,
|
|
1604
1623
|
budgetWrapUp: this.budgetWrapUp ? structuredClone(this.budgetWrapUp) : void 0,
|
|
1605
1624
|
guardAbortGoalId: this.guardAbortGoalId,
|
|
1606
1625
|
staleGoalToolCallsBlocked: this.staleGoalToolCallsBlocked,
|
|
@@ -1619,6 +1638,7 @@ var GoalRuntime = class {
|
|
|
1619
1638
|
this.continuationIntent = snapshot.continuationIntent ? structuredClone(snapshot.continuationIntent) : void 0;
|
|
1620
1639
|
this.continuationDelivery = snapshot.continuationDelivery ? structuredClone(snapshot.continuationDelivery) : void 0;
|
|
1621
1640
|
this.goalRecovery = snapshot.goalRecovery ? structuredClone(snapshot.goalRecovery) : void 0;
|
|
1641
|
+
this.pendingLengthRecovery = snapshot.pendingLengthRecovery ? structuredClone(snapshot.pendingLengthRecovery) : void 0;
|
|
1622
1642
|
this.budgetWrapUp = snapshot.budgetWrapUp ? structuredClone(snapshot.budgetWrapUp) : void 0;
|
|
1623
1643
|
this.guardAbortGoalId = snapshot.guardAbortGoalId;
|
|
1624
1644
|
this.staleGoalToolCallsBlocked = snapshot.staleGoalToolCallsBlocked;
|
|
@@ -1922,4 +1942,4 @@ export {
|
|
|
1922
1942
|
isContradictoryCompletionSummary,
|
|
1923
1943
|
goalIdRejectionReason
|
|
1924
1944
|
};
|
|
1925
|
-
//# sourceMappingURL=chunk-
|
|
1945
|
+
//# sourceMappingURL=chunk-MHW7VEET.ts.map
|