@narumitw/pi-goal 0.46.0 → 0.49.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 +41 -20
- package/package.json +7 -6
- package/src/command-registration.ts +92 -0
- package/src/commands.ts +79 -52
- package/src/goal.ts +11 -1101
- package/src/lifecycle.ts +662 -0
- package/src/menu.ts +437 -71
- package/src/runtime.ts +210 -182
- package/src/settings-ui.ts +58 -43
- package/src/settings.ts +1 -1
- package/src/tool-policy.ts +178 -0
- package/src/tools.ts +316 -0
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ Goal mode uses Codex-like persistence instructions and sends guarded continuatio
|
|
|
15
15
|
- Keeps direct goal management available through `/goal` subcommands: `status`, `pause`, `resume`, `clear`, and `edit`.
|
|
16
16
|
- Exposes only one top-level command: `/goal`, including when ordered goals are enabled.
|
|
17
17
|
- Optionally adds ordered-goal operations through `/goal add`, `prioritize`, `drop-last`, and `skip`, while accepting `push`, `unshift`, `pop`, and `shift` as hidden compatibility aliases.
|
|
18
|
-
-
|
|
18
|
+
- Pauses automatic work after 25 Goal-owned model responses by default, preserves progress, and provides a guided review-and-continue flow; custom finite limits and confirmed Unlimited mode remain available.
|
|
19
19
|
- Pauses after three consecutive empty or normalized-identical tool-free automatic runs, while distinct short output and tool activity reset the repeat detector.
|
|
20
20
|
- Supports optional token budgets such as `/goal --tokens 100k <goal>`, using provider-reported total-token accounting with a cache-inclusive compatibility fallback.
|
|
21
21
|
- Tracks distinct `active`, `paused`, `blocked`, `usage_limited`, `budget_limited`, and `complete` states.
|
|
@@ -70,7 +70,7 @@ built-in defaults without creating the file:
|
|
|
70
70
|
"enabled": false
|
|
71
71
|
},
|
|
72
72
|
"continuationLimits": {
|
|
73
|
-
"automaticTurns":
|
|
73
|
+
"automaticTurns": 25,
|
|
74
74
|
"noProgressTurns": 3
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -80,7 +80,7 @@ Use `/goal` → **Settings…** in the TUI to create or update the file interact
|
|
|
80
80
|
and edit it directly. The standard Settings screen keeps all five controls on one level in task
|
|
81
81
|
order; the two safety limits open standard choice screens:
|
|
82
82
|
|
|
83
|
-
- **Automatic
|
|
83
|
+
- **Automatic-work limit** shows the exact response limit or **Unlimited**. Choose **Set response limit…** to edit the current finite value (or the built-in default of 25 when switching from Unlimited), or choose **Unlimited…**. Unlimited requires confirmation that tool loops may continue consuming tokens and provider cost without a response-count cap.
|
|
84
84
|
- **No-progress guard** shows **_N_ runs** or **Off**. Choose the default threshold, **Off**, or **Set threshold…** and enter a safe whole number greater than zero.
|
|
85
85
|
- **Goal tools** controls whether terminal Goal tools are always visible or appear after the first goal.
|
|
86
86
|
- **Ordered goal queue** controls the experimental ordered-goal workflows.
|
|
@@ -99,7 +99,7 @@ Custom number inputs reject zero, negative numbers, decimals, text, and unsafe i
|
|
|
99
99
|
|
|
100
100
|
`continuationLimits` controls the runaway guards:
|
|
101
101
|
|
|
102
|
-
- `automaticTurns` accepts a positive safe integer or `null` and defaults to `
|
|
102
|
+
- `automaticTurns` accepts a positive safe integer or `null` and defaults to `25`. It counts every completed normal `turn_end` owned by automatically started Goal work, including model responses inside tool loops and matching Pi-owned retries. The user-triggered kickoff, resume, edit, and ordinary user runs are not charged. At the limit, the goal becomes `paused` with cause `continuation_limit`, pending continuation/recovery is cancelled, and the current operation is aborted before a 26th normal response starts. Pi may invoke a provider adapter once more with an already-aborted signal to produce its synthetic terminal event; that event is not counted and cannot resume Goal work. Set this field explicitly to `null` to opt into Unlimited mode; existing explicit `null` values remain compatible.
|
|
103
103
|
- `noProgressTurns` is a positive safe integer and defaults to `3`. At the end of an automatic run, pi-goal compares visible assistant text after Unicode normalization, lowercasing, control-character removal, and whitespace collapse. Thinking and tool blocks are excluded; empty and punctuation-only output are equivalent. Consecutive empty or identical tool-free outputs increment the repeat count. Different non-empty output starts a new run at one, and any attempted tool call resets it. Set this field to `null` to disable only this heuristic.
|
|
104
104
|
|
|
105
105
|
Settings are reread at Pi startup, session replacement, and `/reload`; direct external file edits are not watched live, while changes made through the Goal menu apply immediately. A missing file remains absent and uses the built-in defaults. The first successful settings change creates the file atomically; later saves preserve unknown fields.
|
|
@@ -130,18 +130,25 @@ Tool visibility is a baseline, not ownership of Pi's global active-tool list. Pl
|
|
|
130
130
|
```
|
|
131
131
|
|
|
132
132
|
- In the TUI, `/goal` opens a standard state-aware manager. Its first action follows the current
|
|
133
|
-
state: start when empty, pause when active,
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
133
|
+
state: start when empty, pause when active, review a reached automatic-work limit, resume for other
|
|
134
|
+
stopped states, or increase an exhausted token budget. Active and paused views show **Automatic
|
|
135
|
+
work: _used_ of _limit_ responses** with the remaining count, or explicitly show **Unlimited**.
|
|
136
|
+
A hard-cap pause opens **Review and continue…**, which states that objective, cumulative usage,
|
|
137
|
+
active time, and queue are preserved and previews that Continue resets the counter to zero and
|
|
138
|
+
allows up to one more configured epoch. **Change automatic-work limit…** opens that setting while
|
|
139
|
+
leaving the goal paused; Back and Escape make no change. **Start with token budget…** first offers
|
|
140
|
+
`25k`, a suggested `100k`, `300k`, and **Set a custom budget…**, then collects the objective with
|
|
141
|
+
the selected budget still visible. Custom input accepts examples such as `300000`, `300k`, `2.5k`,
|
|
142
|
+
and `1.5m`; invalid input retains its draft for correction. Status, Settings, Help, queue
|
|
143
|
+
management, invalid-settings guidance, Clear, and Close remain shallow, labeled routes. Arrow keys
|
|
144
|
+
navigate, Enter selects or submits, Escape goes Back, and Ctrl+C closes the full flow.
|
|
138
145
|
- In RPC mode, bare `/goal` and `/goal status` report the current summary through an observable notification without opening terminal UI. Pi exposes no extension-command output channel in print or JSON mode, so those routes reject with an explicit unsupported-mode error instead of misreporting stderr as status output.
|
|
139
146
|
- Menu-driven Replace, Clear, Prioritize, Skip, and Drop last actions preview the exact affected goals and require confirmation. Existing direct routes remain immediate for compatibility and automation.
|
|
140
147
|
- `/goal <goal_to_complete>` starts goal mode. If another unfinished goal exists, Pi asks for confirmation before replacing it with a new active goal and resetting its usage counters. Failed kickoff delivery clears a new goal or restores the prior goal; a previously active goal is restored as paused.
|
|
141
148
|
- `/goal --tokens 100k <goal_to_complete>` starts or replaces goal mode with a token budget. `k` and `m` suffixes are accepted, for example `100k` or `1.5m`.
|
|
142
149
|
- `/goal edit <goal_to_complete>` updates the existing goal objective without resetting usage counters. A successful active edit rotates the stale-turn guard and starts a fresh safety epoch. Paused, blocked, and usage-limited goals stay stopped and retain their safety state until resume. A budget-limited goal reactivates only when `edit --tokens` raises its budget above current usage. Failed prompt delivery restores the exact previous safety counters/cause; it restores a budget-limited goal or restores and pauses a previously active goal.
|
|
143
150
|
- `/goal pause` stops prompt injection and auto-continuation, aborts the current turn, and keeps the goal for later resume. Only active goals can be paused.
|
|
144
|
-
- `/goal resume` resumes a paused, blocked, usage-limited, or budget-limited goal when its token budget allows it, rotates the stale-turn guard id, resets the automatic-response/repeat safety epoch, clears a safety-pause cause, and
|
|
151
|
+
- `/goal resume` resumes a paused, blocked, usage-limited, or budget-limited goal when its token budget allows it, rotates the stale-turn guard id, resets the automatic-response/repeat safety epoch when the queued resume prompt starts, clears a safety-pause cause, and reports the new finite epoch or explicit Unlimited state. Objective, cumulative usage, elapsed time, and queue are preserved. If prompt delivery fails, the original stopped state, guard id, counters, fingerprint, and cause are restored.
|
|
145
152
|
- `/goal clear` clears the current goal or the entire ordered queue, status, pending continuation/transition, and legacy persisted state for the current working directory without aborting unrelated in-flight work.
|
|
146
153
|
|
|
147
154
|
With `experimental.goals: true`:
|
|
@@ -159,7 +166,7 @@ Goal objectives are limited to 4,000 characters. Put longer instructions in a fi
|
|
|
159
166
|
|
|
160
167
|
## 🔁 Session and reload behavior
|
|
161
168
|
|
|
162
|
-
Goal state is stored as Pi session state, similar to Codex's thread-owned goals. `/reload` and reopening the same Pi session can restore that session's unfinished goal. With `"after-first-goal"`,
|
|
169
|
+
Goal state is stored as Pi session state, similar to Codex's thread-owned goals. `/reload` and reopening the same Pi session can restore that session's unfinished goal. An active restored goal already at or above its finite automatic-work limit pauses before another provider request and reports that progress is saved; use `/goal` to review and continue. With `"after-first-goal"`, an unfinished restore marks the tools unlocked in the new extension runtime, but it does not widen an active-tool set already restricted by an earlier lifecycle handler; an active goal instead restores as paused when either terminal tool is missing. If no unfinished goal remains, a fresh runtime starts locked again. Active elapsed time is checkpointed before shutdown and restarted after reload, so offline and stopped wall-clock time is excluded. Automatic-response counts, repeat fingerprints, and safety-pause causes persist across reload and compaction. A direct non-`/goal` user/RPC input resets the safety epoch only while the goal is active and reclassifies the in-flight run as manual; extension input and messages sent while stopped do not reset it. Starting a new Pi session in the same working directory does not inherit the old goal.
|
|
163
170
|
|
|
164
171
|
Ordered queues use the same canonical `goal-state` session entry as single goals. Every item owns independent usage and safety state. Shelving, priority displacement, automatic advancement, and later reactivation preserve that item's epoch rather than granting more automatic work. The legacy `{ goal }` shape remains valid, and missing safety fields normalize to zero/defaults. Queue fields are written only when needed. Sessions created by the former standalone `pi-goals` experiment can migrate their last `goals-state` array and pending `unshift` intent when the branch has never written a canonical `goal-state`; any canonical entry, including an explicit clear, takes precedence so old plural state cannot be resurrected.
|
|
165
172
|
|
|
@@ -171,22 +178,32 @@ Older versions wrote unfinished goals to `~/.pi/agent/pi-goal-state.json` keyed
|
|
|
171
178
|
|
|
172
179
|
`pi-goal` writes compact plain status strings for statusline extensions. `@narumitw/pi-statusline` adds the default `🎯` icon unless configured otherwise:
|
|
173
180
|
|
|
174
|
-
- `active 3m` — an active goal without a token budget; elapsed time counts only periods when its status is active.
|
|
175
|
-
- `active 18k/100k` — an active goal with token usage and budget.
|
|
176
|
-
- `
|
|
177
|
-
- `
|
|
178
|
-
- `
|
|
179
|
-
- `
|
|
181
|
+
- `active 3m · automatic 12/25` — an active goal without a token budget; elapsed time counts only periods when its status is active.
|
|
182
|
+
- `active 18k/100k · automatic 12/25` — an active goal with token usage and budget.
|
|
183
|
+
- `active 3m · automatic Unlimited` — explicit Unlimited automatic work.
|
|
184
|
+
- `paused · automatic limit 25/25` — the automatic-work limit paused the goal; `/goal` opens the recovery preview.
|
|
185
|
+
- `paused · automatic 12/25` — another pause reason stopped work while preserving the finite epoch.
|
|
186
|
+
- `blocked · automatic 12/25` — progress requires user or external action, or a terminal non-usage error stopped work.
|
|
187
|
+
- `usage · automatic 12/25` — the provider or account usage limit stopped work.
|
|
188
|
+
- `budget 100k/100k · automatic 12/25` — the user-configured token budget was reached; auto-continuation stops.
|
|
180
189
|
- `complete` — shown briefly after `goal_complete` succeeds.
|
|
181
190
|
- `queue off` — retained ordered goals are frozen because `experimental.goals` is disabled.
|
|
182
191
|
|
|
183
192
|
## 💰 Token budgets and elapsed time
|
|
184
193
|
|
|
194
|
+
The TUI budget chooser describes token budgets as cumulative Goal usage, warns that the final model
|
|
195
|
+
call may exceed the chosen value, and keeps the independent automatic-work response limit visible.
|
|
196
|
+
It is not a dollar-cost cap. Choosing a preset or entering a custom value remains provisional until
|
|
197
|
+
the objective is submitted; cancelling the chooser, custom input, or objective editor creates no
|
|
198
|
+
Goal. **Increase budget and resume…** shows the exact current budget and usage, requires a new total
|
|
199
|
+
above current usage, previews the new total plus automatic-work epoch, and resumes only after
|
|
200
|
+
confirmation. If the goal or its usage changes while that dialog is open, no change is applied.
|
|
201
|
+
|
|
185
202
|
For each persisted assistant message, `pi-goal` uses finite, non-negative `usage.totalTokens` when available. For compatibility with older or partial records, it otherwise sums finite, non-negative `input + output + cacheRead + cacheWrite`. It does not add `reasoning` because reasoning is already part of output, or `cacheWrite1h` because that is a subset of cache writes. Goal usage is the current branch's cumulative assistant total minus the baseline captured when the goal started, clamped at zero after branch rewinds.
|
|
186
203
|
|
|
187
204
|
Provider usage becomes authoritative only when an assistant message finishes, so a budget can overshoot by one model call. When completed tool activity first exposes exhaustion, the goal transitions once to `budget_limited`, cancels continuation, and queues one bounded custom wrap-up instruction before the next model call. The instruction permits only a concise progress/results/blockers summary; a substantive tool attempt is blocked and aborts the remaining wrap-up. A rejected `goal_complete` also terminates the wrap-up, while accepted completion still requires existing evidence that proves every requirement—budget exhaustion itself never means completion. If exhaustion is first visible at `agent_end` and no turn remains, the extension stops without creating another model turn.
|
|
188
205
|
|
|
189
|
-
|
|
206
|
+
The default 25-response automatic-work limit is a response-count boundary, not a fixed cost ceiling: context size, cache pricing, output length, and provider rates vary, and the final capped response is still retained. Pi derives displayed cost estimates from provider-reported token usage and local model pricing; pi-goal does not query a billing balance or enforce a dollar cap. For tighter token control, choose a smaller `automaticTurns` value and/or use `/goal --tokens`; choosing Unlimited removes only the response-count boundary.
|
|
190
207
|
|
|
191
208
|
Elapsed time is accumulated only while status is `active`. Pause, blocked, usage-limited, budget-limited, shutdown, and offline periods do not increase it. Legacy session entries are migrated by preserving their accumulated seconds and starting a fresh active clock when loaded.
|
|
192
209
|
|
|
@@ -296,9 +313,13 @@ This breaking contract replaces and removes `pi-goal:rpc:start`, `pi-goal:rpc:pa
|
|
|
296
313
|
extensions/pi-goal/
|
|
297
314
|
├── src/
|
|
298
315
|
│ ├── index.ts # Pi package entrypoint
|
|
299
|
-
│ ├── goal.ts #
|
|
316
|
+
│ ├── goal.ts # Order-explicit extension composition root
|
|
317
|
+
│ ├── command-registration.ts # Pi slash-command adapter
|
|
300
318
|
│ ├── commands.ts # Per-factory user-command and queue mutation controller
|
|
301
|
-
│ ├──
|
|
319
|
+
│ ├── tools.ts # Goal completion and blocker tool adapters
|
|
320
|
+
│ ├── lifecycle.ts # Pi session, agent, tool, and compaction event adapter
|
|
321
|
+
│ ├── runtime.ts # Per-factory Goal state, transitions, prompts, and budgets
|
|
322
|
+
│ ├── tool-policy.ts # Goal tool visibility ownership and rollback
|
|
302
323
|
│ ├── safety.ts # Output normalization and no-progress fingerprint state
|
|
303
324
|
│ ├── errors.ts # Pi-aligned provider error and retry classification
|
|
304
325
|
│ ├── markers.ts # Bounded Goal prompt marker parsing and formatting
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@narumitw/pi-goal",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.49.0",
|
|
4
4
|
"description": "Pi extension for autonomous /goal completion with opt-in experimental ordered queues.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,21 +29,22 @@
|
|
|
29
29
|
"test:runtime": "node ./test/goal-runtime-smoke.mjs",
|
|
30
30
|
"typecheck": "tsc --noEmit"
|
|
31
31
|
},
|
|
32
|
-
"dependencies": {
|
|
33
|
-
"@narumitw/pi-tui-kit": "^0.40.0",
|
|
34
|
-
"typebox": "^1.3.9"
|
|
35
|
-
},
|
|
36
32
|
"peerDependencies": {
|
|
37
33
|
"@earendil-works/pi-ai": "*",
|
|
38
34
|
"@earendil-works/pi-coding-agent": "*",
|
|
39
|
-
"@earendil-works/pi-tui": "*"
|
|
35
|
+
"@earendil-works/pi-tui": "*",
|
|
36
|
+
"typebox": "*"
|
|
40
37
|
},
|
|
41
38
|
"devDependencies": {
|
|
42
39
|
"@biomejs/biome": "2.5.6",
|
|
43
40
|
"@earendil-works/pi-ai": "0.83.0",
|
|
44
41
|
"@earendil-works/pi-coding-agent": "0.83.0",
|
|
42
|
+
"typebox": "1.3.9",
|
|
45
43
|
"typescript": "7.0.2"
|
|
46
44
|
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@narumitw/pi-tui-kit": "^0.46.0"
|
|
47
|
+
},
|
|
47
48
|
"repository": {
|
|
48
49
|
"type": "git",
|
|
49
50
|
"url": "https://github.com/narumiruna/pi-extensions",
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { completeGoalArguments, parseCommand } from "./command.js";
|
|
3
|
+
import type { GoalCommandController } from "./commands.js";
|
|
4
|
+
import { showGoalManager } from "./menu.js";
|
|
5
|
+
import type { GoalRuntime } from "./runtime.js";
|
|
6
|
+
import { showGoalSettings } from "./settings-ui.js";
|
|
7
|
+
|
|
8
|
+
interface GoalCommandRegistrationOptions {
|
|
9
|
+
settingsPath?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function registerGoalCommand(
|
|
13
|
+
pi: ExtensionAPI,
|
|
14
|
+
runtime: GoalRuntime,
|
|
15
|
+
commands: GoalCommandController,
|
|
16
|
+
options: GoalCommandRegistrationOptions = {},
|
|
17
|
+
) {
|
|
18
|
+
pi.registerCommand("goal", {
|
|
19
|
+
description: "Run a goal to completion: /goal [--tokens 100k] <goal_to_complete>",
|
|
20
|
+
getArgumentCompletions: (prefix) =>
|
|
21
|
+
completeGoalArguments(prefix, {
|
|
22
|
+
experimentalGoals: runtime.settings.experimental.goals,
|
|
23
|
+
}),
|
|
24
|
+
handler: async (args, ctx) => {
|
|
25
|
+
const result = parseCommand(args, {
|
|
26
|
+
experimentalGoals: runtime.settings.experimental.goals,
|
|
27
|
+
});
|
|
28
|
+
if (typeof result === "string") {
|
|
29
|
+
ctx.ui.notify(result, "warning");
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (result.kind === "show" && args.trim() === "") {
|
|
33
|
+
await showGoalManager(runtime, commands, ctx, (menuCtx, target) =>
|
|
34
|
+
showGoalSettings(runtime, menuCtx, {
|
|
35
|
+
settingsPath: options.settingsPath,
|
|
36
|
+
initialScreen: target,
|
|
37
|
+
onQueueUnfrozen: async (settingsCtx) => {
|
|
38
|
+
await commands.resumeQueueAfterUnfreeze(settingsCtx);
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (runtime.queueFrozen) {
|
|
45
|
+
if (result.kind === "show") commands.showGoal(ctx);
|
|
46
|
+
else if (result.kind === "clear") commands.clearGoal(ctx);
|
|
47
|
+
else commands.notifyFrozenQueue(ctx);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (runtime.pendingQueueAction && result.kind !== "show" && result.kind !== "clear") {
|
|
51
|
+
ctx.ui.notify(
|
|
52
|
+
"A queued goal change is waiting for Pi to settle. Retry after it finishes.",
|
|
53
|
+
"warning",
|
|
54
|
+
);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
switch (result.kind) {
|
|
59
|
+
case "show":
|
|
60
|
+
commands.showGoal(ctx);
|
|
61
|
+
return;
|
|
62
|
+
case "pause":
|
|
63
|
+
commands.pauseGoal(ctx);
|
|
64
|
+
return;
|
|
65
|
+
case "resume":
|
|
66
|
+
await commands.resumeGoal(ctx);
|
|
67
|
+
return;
|
|
68
|
+
case "clear":
|
|
69
|
+
commands.clearGoal(ctx);
|
|
70
|
+
return;
|
|
71
|
+
case "edit":
|
|
72
|
+
await commands.editGoal(result.objective ?? "", result.tokenBudget, ctx);
|
|
73
|
+
return;
|
|
74
|
+
case "add":
|
|
75
|
+
await commands.addGoal(result.objective ?? "", result.tokenBudget, ctx);
|
|
76
|
+
return;
|
|
77
|
+
case "prioritize":
|
|
78
|
+
await commands.prioritizeGoal(result.objective ?? "", result.tokenBudget, ctx);
|
|
79
|
+
return;
|
|
80
|
+
case "drop-last":
|
|
81
|
+
commands.dropLastGoal(ctx);
|
|
82
|
+
return;
|
|
83
|
+
case "skip":
|
|
84
|
+
await commands.skipGoal(ctx);
|
|
85
|
+
return;
|
|
86
|
+
case "start":
|
|
87
|
+
await commands.startGoal(result.objective ?? "", result.tokenBudget, ctx);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}
|
package/src/commands.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { checkpointGoalActiveTime, currentTokenTotal } from "./accounting.js";
|
|
1
|
+
import { checkpointGoalActiveTime, currentTokenTotal, formatTokenCount } from "./accounting.js";
|
|
2
2
|
import { validateObjective } from "./command.js";
|
|
3
3
|
import { safeGoalMenuText } from "./menu.js";
|
|
4
4
|
import type { ActiveGoal } from "./persistence.js";
|
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
skipGoal as skipQueuedGoal,
|
|
14
14
|
} from "./queue.js";
|
|
15
15
|
import {
|
|
16
|
-
abortCurrentTurn,
|
|
17
16
|
blocksStaleGoalToolCalls,
|
|
18
17
|
createGoal,
|
|
19
18
|
editedGoalStatus,
|
|
@@ -46,7 +45,9 @@ export class GoalCommandController {
|
|
|
46
45
|
ctx: StatusContext,
|
|
47
46
|
onActivated?: (goal: ActiveGoal) => void,
|
|
48
47
|
isActivationCurrent?: (goal: ActiveGoal) => boolean,
|
|
48
|
+
isRequestCurrent?: () => boolean,
|
|
49
49
|
) {
|
|
50
|
+
if (isRequestCurrent && !isRequestCurrent()) return;
|
|
50
51
|
const validationError = validateObjective(objective);
|
|
51
52
|
if (validationError) {
|
|
52
53
|
ctx.ui.notify(validationError, "warning");
|
|
@@ -76,6 +77,7 @@ export class GoalCommandController {
|
|
|
76
77
|
ctx.ui.notify(`Goal kept: ${existingGoal.text}`, "info");
|
|
77
78
|
return;
|
|
78
79
|
}
|
|
80
|
+
if (isRequestCurrent && !isRequestCurrent()) return;
|
|
79
81
|
if (
|
|
80
82
|
goalQueueIdentity(
|
|
81
83
|
this.runtime.activeGoal,
|
|
@@ -90,9 +92,10 @@ export class GoalCommandController {
|
|
|
90
92
|
|
|
91
93
|
// Unlock lazy visibility only for a real activation. In always mode, a
|
|
92
94
|
// missing tool means another policy or allowlist intentionally removed it.
|
|
93
|
-
|
|
95
|
+
if (isRequestCurrent && !isRequestCurrent()) return;
|
|
96
|
+
const goalToolVisibilityBeforeActivation = this.runtime.toolPolicy.snapshot();
|
|
94
97
|
try {
|
|
95
|
-
this.runtime.
|
|
98
|
+
this.runtime.toolPolicy.prepareActivation(this.runtime.settings.toolVisibility, ctx);
|
|
96
99
|
} catch (error) {
|
|
97
100
|
ctx.ui.notify(`Cannot start /goal: ${formatError(error)}`, "error");
|
|
98
101
|
if (existingGoal?.status === "active") this.runtime.pauseGoalForUnavailableTools(ctx);
|
|
@@ -121,7 +124,7 @@ export class GoalCommandController {
|
|
|
121
124
|
startedGoal.id,
|
|
122
125
|
buildGoalPrompt(startedGoal),
|
|
123
126
|
true,
|
|
124
|
-
() => isActivationCurrent?.(startedGoal) ?? true,
|
|
127
|
+
() => (isRequestCurrent?.() ?? true) && (isActivationCurrent?.(startedGoal) ?? true),
|
|
125
128
|
);
|
|
126
129
|
if (isActivationCurrent && !isActivationCurrent(startedGoal)) return;
|
|
127
130
|
if (!sent) {
|
|
@@ -132,9 +135,12 @@ export class GoalCommandController {
|
|
|
132
135
|
this.runtime.queuedGoals = existingQueuedGoals;
|
|
133
136
|
this.runtime.recordGoalUsage(existingGoal, ctx);
|
|
134
137
|
if (existingGoal.status === "active") {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
+
this.runtime.stopActiveGoal(ctx, {
|
|
139
|
+
kind: "activation_rollback",
|
|
140
|
+
expectedGoalId: startedGoal.id,
|
|
141
|
+
restoreGoal: existingGoal,
|
|
142
|
+
abortTurn: true,
|
|
143
|
+
});
|
|
138
144
|
} else {
|
|
139
145
|
this.runtime.activeGoal = existingGoal;
|
|
140
146
|
if (blocksStaleGoalToolCalls(this.runtime.activeGoal.status)) {
|
|
@@ -142,15 +148,15 @@ export class GoalCommandController {
|
|
|
142
148
|
} else {
|
|
143
149
|
this.runtime.clearStaleGoalToolCallBlock();
|
|
144
150
|
}
|
|
151
|
+
this.runtime.persistGoal(this.runtime.activeGoal);
|
|
152
|
+
this.runtime.updateStatus(ctx, this.runtime.activeGoal);
|
|
145
153
|
}
|
|
146
|
-
this.runtime.persistGoal(this.runtime.activeGoal);
|
|
147
|
-
this.runtime.updateStatus(ctx, this.runtime.activeGoal);
|
|
148
154
|
} else {
|
|
149
155
|
this.runtime.clearActiveGoal(ctx);
|
|
150
156
|
}
|
|
151
157
|
}
|
|
152
158
|
if (rolledBackStartedGoal) {
|
|
153
|
-
this.runtime.
|
|
159
|
+
this.runtime.toolPolicy.restore(goalToolVisibilityBeforeActivation);
|
|
154
160
|
}
|
|
155
161
|
return;
|
|
156
162
|
}
|
|
@@ -160,9 +166,18 @@ export class GoalCommandController {
|
|
|
160
166
|
) {
|
|
161
167
|
return;
|
|
162
168
|
}
|
|
169
|
+
const automaticLimit = this.runtime.settings.continuationLimits.automaticTurns;
|
|
163
170
|
ctx.ui.notify(
|
|
164
|
-
existingGoal ?
|
|
165
|
-
|
|
171
|
+
`${existingGoal ? "Goal replaced" : "Goal started"}: ${objective}. ${
|
|
172
|
+
startedGoal.tokenBudget === undefined
|
|
173
|
+
? ""
|
|
174
|
+
: `Token budget: ${formatTokenCount(startedGoal.tokenBudget)} cumulative; the final model call may exceed it. `
|
|
175
|
+
}${
|
|
176
|
+
automaticLimit === null
|
|
177
|
+
? "Automatic work is Unlimited; tool loops may consume substantial tokens and provider cost. Open /goal to monitor."
|
|
178
|
+
: `Automatic work pauses after ${automaticLimit} responses; open /goal to monitor progress.`
|
|
179
|
+
}`,
|
|
180
|
+
automaticLimit === null ? "warning" : "info",
|
|
166
181
|
);
|
|
167
182
|
}
|
|
168
183
|
|
|
@@ -342,12 +357,14 @@ export class GoalCommandController {
|
|
|
342
357
|
}
|
|
343
358
|
|
|
344
359
|
try {
|
|
345
|
-
this.runtime.
|
|
360
|
+
this.runtime.toolPolicy.prepareActivation(this.runtime.settings.toolVisibility, ctx);
|
|
346
361
|
} catch (error) {
|
|
347
|
-
this.runtime.
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
362
|
+
this.runtime.stopActiveGoal(ctx, {
|
|
363
|
+
kind: "activation_rollback",
|
|
364
|
+
expectedGoalId: this.runtime.activeGoal.id,
|
|
365
|
+
restoreGoal: this.runtime.activeGoal,
|
|
366
|
+
abortTurn: false,
|
|
367
|
+
});
|
|
351
368
|
ctx.ui.notify(`Cannot start the next /goal: ${formatError(error)}`, "error");
|
|
352
369
|
return false;
|
|
353
370
|
}
|
|
@@ -359,10 +376,12 @@ export class GoalCommandController {
|
|
|
359
376
|
false, // Queue reactivation preserves its persisted safety epoch.
|
|
360
377
|
);
|
|
361
378
|
if (!sent && this.runtime.activeGoal?.id === activatedGoal.id) {
|
|
362
|
-
this.runtime.
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
379
|
+
this.runtime.stopActiveGoal(ctx, {
|
|
380
|
+
kind: "activation_rollback",
|
|
381
|
+
expectedGoalId: activatedGoal.id,
|
|
382
|
+
restoreGoal: activatedGoal,
|
|
383
|
+
abortTurn: false,
|
|
384
|
+
});
|
|
366
385
|
ctx.ui.notify(
|
|
367
386
|
`Next goal paused after prompt delivery failed: ${activatedGoal.text}`,
|
|
368
387
|
"warning",
|
|
@@ -395,15 +414,11 @@ export class GoalCommandController {
|
|
|
395
414
|
);
|
|
396
415
|
return;
|
|
397
416
|
}
|
|
398
|
-
this.runtime.
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
this.runtime.activeGoal = transitionGoal(this.runtime.activeGoal, "paused");
|
|
404
|
-
this.runtime.persistGoal(this.runtime.activeGoal);
|
|
405
|
-
this.runtime.updateStatus(ctx, this.runtime.activeGoal);
|
|
406
|
-
ctx.ui.notify(`Goal paused: ${this.runtime.activeGoal.text}`, "info");
|
|
417
|
+
const stoppedGoal = this.runtime.stopActiveGoal(ctx, {
|
|
418
|
+
kind: "explicit_pause",
|
|
419
|
+
expectedGoalId: this.runtime.activeGoal.id,
|
|
420
|
+
});
|
|
421
|
+
if (stoppedGoal) ctx.ui.notify(`Goal paused: ${stoppedGoal.text}`, "info");
|
|
407
422
|
}
|
|
408
423
|
|
|
409
424
|
async resumeGoal(ctx: StatusContext) {
|
|
@@ -428,9 +443,9 @@ export class GoalCommandController {
|
|
|
428
443
|
);
|
|
429
444
|
return;
|
|
430
445
|
}
|
|
431
|
-
const goalToolVisibilityBeforeActivation = this.runtime.
|
|
446
|
+
const goalToolVisibilityBeforeActivation = this.runtime.toolPolicy.snapshot();
|
|
432
447
|
try {
|
|
433
|
-
this.runtime.
|
|
448
|
+
this.runtime.toolPolicy.prepareActivation(this.runtime.settings.toolVisibility, ctx);
|
|
434
449
|
} catch (error) {
|
|
435
450
|
ctx.ui.notify(`Cannot resume /goal: ${formatError(error)}`, "error");
|
|
436
451
|
return;
|
|
@@ -470,13 +485,18 @@ export class GoalCommandController {
|
|
|
470
485
|
if (blocksStaleGoalToolCalls(this.runtime.activeGoal.status)) {
|
|
471
486
|
this.runtime.blockStaleGoalToolCalls();
|
|
472
487
|
}
|
|
473
|
-
this.runtime.
|
|
488
|
+
this.runtime.toolPolicy.restore(goalToolVisibilityBeforeActivation);
|
|
474
489
|
}
|
|
475
490
|
return;
|
|
476
491
|
}
|
|
492
|
+
const automaticLimit = this.runtime.settings.continuationLimits.automaticTurns;
|
|
477
493
|
ctx.ui.notify(
|
|
478
|
-
`Goal resumed from ${stoppedStatusLabel(stoppedStatus)}: ${resumedGoal.text}
|
|
479
|
-
|
|
494
|
+
`Goal resumed from ${stoppedStatusLabel(stoppedStatus)}: ${resumedGoal.text}. ${
|
|
495
|
+
automaticLimit === null
|
|
496
|
+
? "Automatic work remains Unlimited; goal progress and cumulative usage are preserved."
|
|
497
|
+
: `The automatic-work counter will reset to 0 of ${automaticLimit} when the resumed prompt starts; goal progress and cumulative usage are preserved.`
|
|
498
|
+
}`,
|
|
499
|
+
automaticLimit === null ? "warning" : "info",
|
|
480
500
|
);
|
|
481
501
|
}
|
|
482
502
|
|
|
@@ -528,10 +548,10 @@ export class GoalCommandController {
|
|
|
528
548
|
? queueGoalSafetyReset(transitionedGoal)
|
|
529
549
|
: transitionedGoal;
|
|
530
550
|
const goalToolVisibilityBeforeActivation =
|
|
531
|
-
nextGoal.status === "active" ? this.runtime.
|
|
551
|
+
nextGoal.status === "active" ? this.runtime.toolPolicy.snapshot() : undefined;
|
|
532
552
|
if (nextGoal.status === "active") {
|
|
533
553
|
try {
|
|
534
|
-
this.runtime.
|
|
554
|
+
this.runtime.toolPolicy.prepareActivation(this.runtime.settings.toolVisibility, ctx);
|
|
535
555
|
} catch (error) {
|
|
536
556
|
ctx.ui.notify(`Cannot reactivate /goal: ${formatError(error)}`, "error");
|
|
537
557
|
if (this.runtime.activeGoal?.status === "active") {
|
|
@@ -555,9 +575,12 @@ export class GoalCommandController {
|
|
|
555
575
|
if (!sent) {
|
|
556
576
|
if (this.runtime.activeGoal?.id === editedGoal.id) {
|
|
557
577
|
if (previousStatus === "active") {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
578
|
+
this.runtime.stopActiveGoal(ctx, {
|
|
579
|
+
kind: "activation_rollback",
|
|
580
|
+
expectedGoalId: editedGoal.id,
|
|
581
|
+
restoreGoal: previousGoal,
|
|
582
|
+
abortTurn: true,
|
|
583
|
+
});
|
|
561
584
|
} else {
|
|
562
585
|
this.runtime.activeGoal = previousGoal;
|
|
563
586
|
if (blocksStaleGoalToolCalls(this.runtime.activeGoal.status)) {
|
|
@@ -565,11 +588,11 @@ export class GoalCommandController {
|
|
|
565
588
|
} else {
|
|
566
589
|
this.runtime.clearStaleGoalToolCallBlock();
|
|
567
590
|
}
|
|
591
|
+
this.runtime.persistGoal(this.runtime.activeGoal);
|
|
592
|
+
this.runtime.updateStatus(ctx, this.runtime.activeGoal);
|
|
568
593
|
}
|
|
569
|
-
this.runtime.persistGoal(this.runtime.activeGoal);
|
|
570
|
-
this.runtime.updateStatus(ctx, this.runtime.activeGoal);
|
|
571
594
|
if (goalToolVisibilityBeforeActivation) {
|
|
572
|
-
this.runtime.
|
|
595
|
+
this.runtime.toolPolicy.restore(goalToolVisibilityBeforeActivation);
|
|
573
596
|
}
|
|
574
597
|
}
|
|
575
598
|
return;
|
|
@@ -602,6 +625,7 @@ export class GoalCommandController {
|
|
|
602
625
|
this.runtime.settings.experimental.goals,
|
|
603
626
|
this.runtime.queueFrozen,
|
|
604
627
|
this.runtime.pendingQueueAction,
|
|
628
|
+
this.runtime.settings.continuationLimits.automaticTurns,
|
|
605
629
|
),
|
|
606
630
|
);
|
|
607
631
|
}
|
|
@@ -631,9 +655,9 @@ export class GoalCommandController {
|
|
|
631
655
|
}
|
|
632
656
|
const previousGoal = { ...currentGoal };
|
|
633
657
|
const previousQueue = [...this.runtime.queuedGoals];
|
|
634
|
-
const visibilityBeforeActivation = this.runtime.
|
|
658
|
+
const visibilityBeforeActivation = this.runtime.toolPolicy.snapshot();
|
|
635
659
|
try {
|
|
636
|
-
this.runtime.
|
|
660
|
+
this.runtime.toolPolicy.prepareActivation(this.runtime.settings.toolVisibility, ctx);
|
|
637
661
|
} catch (error) {
|
|
638
662
|
ctx.ui.notify(`Cannot prioritize /goal: ${formatError(error)}`, "error");
|
|
639
663
|
if (currentGoal.status === "complete") {
|
|
@@ -682,9 +706,12 @@ export class GoalCommandController {
|
|
|
682
706
|
if (!sent && this.runtime.activeGoal.id === prioritized.id) {
|
|
683
707
|
this.runtime.queuedGoals = previousQueue;
|
|
684
708
|
if (previousGoal.status === "active") {
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
709
|
+
this.runtime.stopActiveGoal(ctx, {
|
|
710
|
+
kind: "activation_rollback",
|
|
711
|
+
expectedGoalId: prioritized.id,
|
|
712
|
+
restoreGoal: previousGoal,
|
|
713
|
+
abortTurn: true,
|
|
714
|
+
});
|
|
688
715
|
} else {
|
|
689
716
|
this.runtime.activeGoal = previousGoal;
|
|
690
717
|
if (previousGoal.status === "complete") {
|
|
@@ -692,10 +719,10 @@ export class GoalCommandController {
|
|
|
692
719
|
} else if (blocksStaleGoalToolCalls(previousGoal.status)) {
|
|
693
720
|
this.runtime.blockStaleGoalToolCalls();
|
|
694
721
|
}
|
|
722
|
+
this.runtime.persistGoal(this.runtime.activeGoal);
|
|
723
|
+
this.runtime.updateStatus(ctx, this.runtime.activeGoal);
|
|
695
724
|
}
|
|
696
|
-
this.runtime.
|
|
697
|
-
this.runtime.updateStatus(ctx, this.runtime.activeGoal);
|
|
698
|
-
this.runtime.restoreGoalToolVisibility(visibilityBeforeActivation);
|
|
725
|
+
this.runtime.toolPolicy.restore(visibilityBeforeActivation);
|
|
699
726
|
return false;
|
|
700
727
|
}
|
|
701
728
|
ctx.ui.notify(`Goal prioritized: ${objective}`, "info");
|