@narumitw/pi-goal 0.15.1 → 0.16.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 CHANGED
@@ -2,28 +2,30 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@narumitw/pi-goal)](https://www.npmjs.com/package/@narumitw/pi-goal) [![Pi extension](https://img.shields.io/badge/Pi-extension-blue)](https://pi.dev) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](./LICENSE)
4
4
 
5
- `@narumitw/pi-goal` is a native [Pi coding agent](https://pi.dev) extension that adds session-scoped `/goal` commands, a `goal_complete({ goal_id, summary })` completion tool, and a strict `goal_blocked({ goal_id, reason, evidence, repeated_turns })` impasse tool for autonomous, verifiable task completion.
5
+ `@narumitw/pi-goal` is a native [Pi coding agent](https://pi.dev) extension that adds session-scoped `/goal` commands, a `goal_complete({ goal_id, summary })` completion tool, and a strict `goal_blocked({ goal_id, reason, evidence, repeated_turns })` impasse tool for autonomous, verifiable task completion. An opt-in experimental mode adds an ordered queue without introducing a second command or tool namespace.
6
6
 
7
- Goal mode uses Codex-like persistence instructions and sends guarded continuation messages from Pi's fully settled idle boundary until the agent completes the goal, the user pauses or clears it, a true blocker or provider usage limit stops it, or an optional token budget is reached.
7
+ Goal mode uses Codex-like persistence instructions and sends guarded continuation messages from Pi's fully settled idle boundary until the agent completes the goal, the user pauses or clears it, a true blocker or provider usage limit stops it, or an optional token budget is reached. With ordered goals enabled, the same lifecycle advances through queued objectives one at a time.
8
8
 
9
9
  ## ✨ Features
10
10
 
11
11
  - Adds `/goal <goal_to_complete>` to start goal mode, with confirmation before replacing an existing goal.
12
12
  - Bare `/goal` shows the current goal summary.
13
13
  - Keeps advanced goal management inside `/goal` subcommands: `pause`, `resume`, `clear`, and `edit`.
14
- - Exposes only one top-level command: `/goal`.
14
+ - Exposes only one top-level command: `/goal`, including when ordered goals are enabled.
15
+ - Optionally adds ordered-goal operations through `/goal add`, `prioritize`, `drop-last`, and `skip`, while accepting `push`, `unshift`, `pop`, and `shift` as hidden compatibility aliases.
15
16
  - Supports optional token budgets such as `/goal --tokens 100k <goal>`, using provider-reported total-token accounting with a cache-inclusive compatibility fallback.
16
17
  - Tracks distinct `active`, `paused`, `blocked`, `usage_limited`, `budget_limited`, and `complete` states.
17
- - Stores goal state in the current Pi session, following Codex's thread-owned goal model instead of using a global per-directory goal.
18
+ - Stores goal state in the current Pi session, following Codex's thread-owned goal model instead of using a global per-directory goal. Experimental queues keep independent budget, usage, elapsed-time, iteration, status, and stale-id accounting for every item.
18
19
  - Registers a `goal_complete({ goal_id, summary })` tool for explicit completion, requiring the current goal id and rejecting missing/stale ids plus plainly contradictory summaries such as “not complete” or “tests still fail”.
19
20
  - Registers `goal_blocked({ goal_id, reason, evidence, repeated_turns })` for true impasses only; it requires the current goal id, concrete evidence, and the same blocker recurring for at least three consecutive goal turns.
20
- - Records continuation intent when an active turn ends early, then directly triggers exactly one next turn only after Pi reports the agent fully settled, idle, and free of pending messages.
21
+ - Keeps both goal tools active by default for a stable tool schema; optional `"after-first-goal"` visibility hides them until the first accepted `/goal` activation or an unfinished goal is restored, then keeps them desired for the rest of that extension runtime without overriding a restrictive restore policy.
22
+ - Records continuation and queue-transition intent, then triggers exactly one next turn only after Pi reports the agent fully settled, idle, and free of pending messages; if terminal tools disappear during a tool loop or before the next queued goal starts, pauses before another model turn.
21
23
  - Lets retry, compaction, steering, follow-up, and other queued work settle before automatic goal continuation.
22
24
  - Separates user interruption (`paused`), true impasse or terminal non-usage error (`blocked`), provider/account quota exhaustion (`usage_limited`), and user token budget exhaustion (`budget_limited`).
23
25
  - Detects budget exhaustion after completed tool activity when assistant usage is persisted, then injects at most one non-user-authored wrap-up instruction and blocks further substantive tools.
24
26
  - Keeps retryable provider interruptions and Pi compaction retries active without enqueueing duplicate goal continuations while Pi retries.
25
27
  - Preserves active goals across manual, threshold, and overflow compaction.
26
- - Guards auto-follow-ups so duplicate, replaced, stopped, cleared, completed, or budget-limited goals are not continued.
28
+ - Guards auto-follow-ups and Goal-owned kickoff deliveries so duplicate, replaced, stopped, cleared, completed, budget-limited, or stale queued prompts cannot continue or overwrite a newer goal.
27
29
  - Rotates the completion guard id when a goal is resumed or edited so delayed old turns cannot complete the newer goal instance.
28
30
  - Blocks stale tool calls after in-flight work pauses, blocks, or reaches a usage limit, until fresh non-goal user work, successful reactivation/replacement, or clear.
29
31
  - Applies one evidence-based completion audit across kickoff, resume, edit, system, continuation, and budget-wrap-up prompts.
@@ -48,6 +50,30 @@ Try this package locally from the repository root:
48
50
  pi -e ./extensions/pi-goal
49
51
  ```
50
52
 
53
+ ## ⚙️ Configuration
54
+
55
+ Configuration is optional. Create `~/.pi/agent/pi-goal.json` only when overriding the defaults:
56
+
57
+ ```json
58
+ {
59
+ "toolVisibility": "always",
60
+ "experimental": {
61
+ "goals": false
62
+ }
63
+ }
64
+ ```
65
+
66
+ `toolVisibility` accepts:
67
+
68
+ - `"always"` (default) — pi-goal does not proactively hide `goal_complete` or `goal_blocked`, keeping the tool schema stable from session startup.
69
+ - `"after-first-goal"` — hides both tools at fresh runtime startup, reveals them for the first accepted Goal activation, and treats an unfinished-goal restore as unlocked for the remainder of that extension runtime. On restore, pi-goal uses the active tools already established by earlier lifecycle handlers; it does not re-add missing terminal tools over a restrictive policy. Failed kickoff, replacement, resume, or reactivating-edit delivery restores the exact pre-activation tool set, including terminal tools exposed by another extension. If revealing the tools would widen an already-running turn, wait for Pi to become idle and retry `/goal`.
70
+
71
+ `experimental.goals` accepts a boolean and defaults to `false`. Set it to `true` to enable the ordered-goal subcommands and automatic queue advancement described below. Enabled sessions show one warning because command behavior and persisted queue state remain experimental. Settings are reread at Pi startup, session replacement, and `/reload`; the file is not watched live.
72
+
73
+ Missing settings and omitted fields use the defaults above. Invalid settings produce a warning and fall back to all defaults; pi-goal never creates the file automatically. Reload Pi after changing the file. If a live runtime reloads settings, switching `toolVisibility` to `"always"` restores only the exact tools that pi-goal previously hid, while switching to `"after-first-goal"` locks a runtime that has no unfinished goal.
74
+
75
+ Tool visibility is a baseline, not ownership of Pi's global active-tool list. Plan mode or another restrictive policy may temporarily hide the tools. pi-goal does not fight that policy on restore or on every turn: activation is rejected if both tools cannot be made available, and an already-active goal is paused without automatic continuation if they disappear. The pause aborts a Goal-owned kickoff, resume, active-edit, or automatic-continuation prompt, but it does not cancel or stale-block an unrelated user or extension turn, including startup follow-ups after a restrictive restore.
76
+
51
77
  ## 🚀 Commands
52
78
 
53
79
  ```text
@@ -58,6 +84,12 @@ pi -e ./extensions/pi-goal
58
84
  /goal pause
59
85
  /goal resume
60
86
  /goal clear
87
+
88
+ # With experimental.goals enabled:
89
+ /goal add --tokens 20k run the integration tests
90
+ /goal prioritize fix the urgent production regression
91
+ /goal drop-last
92
+ /goal skip
61
93
  ```
62
94
 
63
95
  - `/goal` shows the current goal, status, iteration count, active elapsed time, token usage, and available `/goal` subcommands.
@@ -66,13 +98,28 @@ pi -e ./extensions/pi-goal
66
98
  - `/goal edit <goal_to_complete>` updates the existing goal objective without resetting usage counters. Active goals stay active; paused, blocked, and usage-limited goals stay stopped. A budget-limited goal reactivates only when `edit --tokens` raises its budget above current usage. Failed prompt delivery restores a budget-limited goal or restores and pauses a previously active goal.
67
99
  - `/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.
68
100
  - `/goal resume` resumes a paused, blocked, usage-limited, or budget-limited goal when its token budget allows it, rotates the stale-turn guard id, and queues a resume prompt so work continues. If prompt delivery fails, the original stopped state and guard id are restored.
69
- - `/goal clear` clears the current goal state, status, pending continuation, and legacy persisted state for the current working directory without aborting any in-flight agent turn.
101
+ - `/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.
102
+
103
+ With `experimental.goals: true`:
104
+
105
+ - `/goal add [--tokens <budget>] <goal>` appends an objective without interrupting the active head. If no goal exists, it starts immediately.
106
+ - `/goal prioritize [--tokens <budget>] <goal>` inserts an urgent objective at the front. When Pi is busy, the intent is persisted and activation waits until the old run, retries, and pending messages settle, so old usage cannot be charged to the urgent goal.
107
+ - `/goal drop-last` removes the tail. If only the active head remains, it clears that goal.
108
+ - `/goal skip` removes the active head and starts the next eligible item only from an idle settled boundary. A stopped next item remains stopped.
109
+ - `push`, `unshift`, `pop`, and `shift` are accepted as aliases for `add`, `prioritize`, `drop-last`, and `skip`, respectively. Autocomplete shows only the intent-oriented names.
110
+ - `/goal <goal>` still starts or replaces the whole queue; `edit`, `pause`, and `resume` operate on the active head.
111
+
112
+ When the experiment is disabled, queue words retain the original parser behavior and are ordinary objective text. For example, `/goal add docs` starts the single objective `add docs`.
70
113
 
71
114
  Goal objectives are limited to 4,000 characters. Put longer instructions in a file and reference the file path from `/goal`.
72
115
 
73
116
  ## 🔁 Session and reload behavior
74
117
 
75
- 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. Active elapsed time is checkpointed before shutdown and restarted after reload, so offline and stopped wall-clock time is excluded. Starting a new Pi session in the same working directory does not inherit the old goal.
118
+ 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"`, that 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. Starting a new Pi session in the same working directory does not inherit the old goal.
119
+
120
+ Ordered queues use the same canonical `goal-state` session entry as single goals. The legacy `{ goal }` shape remains valid, and 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.
121
+
122
+ If a session still contains multiple goals or a pending queue transition when `experimental.goals` is disabled, pi-goal freezes that queue. It does not inject Goal prompts or continue work, reports `queue off`, preserves every item, and accepts only `/goal` for inspection or `/goal clear` for removal. Re-enable the setting and run `/reload` to resume. A migrated legacy array containing only one goal becomes an ordinary single goal without requiring the experiment.
76
123
 
77
124
  Older versions wrote unfinished goals to `~/.pi/agent/pi-goal-state.json` keyed by working directory. This version no longer reads that global file, and `/goal clear` removes any legacy entry for the current working directory.
78
125
 
@@ -87,6 +134,7 @@ Older versions wrote unfinished goals to `~/.pi/agent/pi-goal-state.json` keyed
87
134
  - `usage` — the provider or account usage limit stopped work.
88
135
  - `budget 100k/100k` — the user-configured token budget was reached; auto-continuation stops.
89
136
  - `complete` — shown briefly after `goal_complete` succeeds.
137
+ - `queue off` — retained ordered goals are frozen because `experimental.goals` is disabled.
90
138
 
91
139
  ## 💰 Token budgets and elapsed time
92
140
 
@@ -104,7 +152,7 @@ Before completion, the shared audit tells the agent to treat completion as unpro
104
152
 
105
153
  To finish, the agent must call `goal_complete` with the exact current `goal_id` and a `summary` of completion evidence. Missing or stale `goal_id` values are rejected before summary validation. Paused, blocked, and usage-limited goals cannot be completed until resumed; a budget-limited goal permits completion only during its bounded in-flight wrap-up. The summary is completion evidence, not the stale-turn safety token.
106
154
 
107
- If a turn ends before completion, `pi-goal` records usage and creates one continuation intent. It dispatches that continuation only from Pi's `agent_settled` lifecycle after retries, automatic compaction, steering, and follow-up work have drained, `ctx.isIdle()` is true, and no messages are pending. Repeated settled events cannot dispatch the same intent twice.
155
+ If a turn ends before completion, `pi-goal` records usage and creates one continuation intent. It dispatches that continuation only from Pi's `agent_settled` lifecycle after retries, automatic compaction, steering, and follow-up work have drained, `ctx.isIdle()` is true, and no messages are pending. Repeated settled events cannot dispatch the same intent twice. Goal-owned kickoff, resume, active-edit, and automatic-continuation deliveries are bound to the goal instance that created them; a delayed prompt from a replaced goal is aborted without rolling back, injecting, or stopping the newer goal.
108
156
 
109
157
  Manual compaction does not emit `agent_settled`, so its completion hook uses the same single-flight dispatcher as a narrow idle-only fallback. Pi extensions cannot reserve an idle turn atomically like Codex core; another extension can still win the race after the idle check, and its newer turn supersedes the old continuation intent.
110
158
 
@@ -131,8 +179,11 @@ A user pause or aborted turn produces `paused`; a terminal provider/account quot
131
179
  ```txt
132
180
  extensions/pi-goal/
133
181
  ├── src/
134
- │ ├── goal.ts # Pi entrypoint and shared lifecycle state machine
135
- │ └── *.ts # Package-local command, prompt, accounting, and persistence modules
182
+ │ ├── goal.ts # Pi entrypoint, tool contracts, and lifecycle orchestration
183
+ │ ├── commands.ts # Per-factory user-command and queue mutation controller
184
+ │ ├── runtime.ts # Per-factory state, prompt ownership, budgets, and tool policy
185
+ │ ├── queue.ts # Pure ordered-goal transitions
186
+ │ └── *.ts # Package-local parsing, settings, prompts, accounting, and persistence
136
187
  ├── README.md
137
188
  ├── LICENSE
138
189
  ├── tsconfig.json
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@narumitw/pi-goal",
3
- "version": "0.15.1",
4
- "description": "Pi extension that keeps working on a /goal until the agent marks it complete.",
3
+ "version": "0.16.0",
4
+ "description": "Pi extension for autonomous /goal completion with opt-in experimental ordered queues.",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "private": false,
@@ -10,6 +10,7 @@
10
10
  "pi-extension",
11
11
  "pi",
12
12
  "goal",
13
+ "queue",
13
14
  "automation"
14
15
  ],
15
16
  "files": [
package/src/command.ts CHANGED
@@ -1,7 +1,21 @@
1
1
  const MAX_OBJECTIVE_LENGTH = 4_000;
2
2
 
3
+ export interface GoalCommandFeatures {
4
+ experimentalGoals?: boolean;
5
+ }
6
+
3
7
  export interface CommandResult {
4
- kind: "start" | "pause" | "resume" | "clear" | "show" | "edit";
8
+ kind:
9
+ | "start"
10
+ | "pause"
11
+ | "resume"
12
+ | "clear"
13
+ | "show"
14
+ | "edit"
15
+ | "add"
16
+ | "prioritize"
17
+ | "drop-last"
18
+ | "skip";
5
19
  objective?: string;
6
20
  tokenBudget?: number;
7
21
  }
@@ -12,61 +26,123 @@ export interface GoalArgumentCompletion {
12
26
  description?: string;
13
27
  }
14
28
 
29
+ const TOKEN_BUDGET_COMPLETION: GoalArgumentCompletion = {
30
+ value: "--tokens ",
31
+ label: "--tokens",
32
+ description: "Set a token budget before the goal",
33
+ };
15
34
  const GOAL_ARGUMENT_COMPLETIONS: readonly GoalArgumentCompletion[] = [
16
35
  { value: "pause", label: "pause", description: "Pause the active goal" },
17
36
  { value: "resume", label: "resume", description: "Resume a stopped or budget-limited goal" },
18
37
  { value: "clear", label: "clear", description: "Clear the current goal" },
19
38
  { value: "edit", label: "edit", description: "Edit the current goal objective" },
20
39
  { value: "status", label: "status", description: "Show the current goal" },
21
- { value: "--tokens ", label: "--tokens", description: "Set a token budget before the goal" },
40
+ TOKEN_BUDGET_COMPLETION,
41
+ ];
42
+ const QUEUE_ARGUMENT_COMPLETIONS: readonly GoalArgumentCompletion[] = [
43
+ { value: "add", label: "add", description: "Add a goal to the end of the queue" },
44
+ {
45
+ value: "prioritize",
46
+ label: "prioritize",
47
+ description: "Prioritize a new goal at the front of the queue",
48
+ },
49
+ { value: "drop-last", label: "drop-last", description: "Remove the last goal" },
50
+ { value: "skip", label: "skip", description: "Skip the current goal" },
22
51
  ];
23
- const EDIT_TOKEN_COMPLETION: GoalArgumentCompletion = {
24
- value: "edit --tokens ",
25
- label: "--tokens",
26
- description: "Set a token budget before the updated goal",
27
- };
28
52
 
29
- export function completeGoalArguments(argumentPrefix: string): GoalArgumentCompletion[] | null {
53
+ export function completeGoalArguments(
54
+ argumentPrefix: string,
55
+ features: GoalCommandFeatures = {},
56
+ ): GoalArgumentCompletion[] | null {
30
57
  const prefix = argumentPrefix.trimStart();
31
- if (prefix === "") return [...GOAL_ARGUMENT_COMPLETIONS];
32
- const editOptionPrefix = /^edit\s+(\S*)$/.exec(prefix)?.[1];
33
- if (editOptionPrefix !== undefined) {
34
- return editOptionPrefix === "" || "--tokens".startsWith(editOptionPrefix)
35
- ? [EDIT_TOKEN_COMPLETION]
58
+ const completions = features.experimentalGoals
59
+ ? [
60
+ ...GOAL_ARGUMENT_COMPLETIONS.slice(0, -1),
61
+ ...QUEUE_ARGUMENT_COMPLETIONS,
62
+ TOKEN_BUDGET_COMPLETION,
63
+ ]
64
+ : [...GOAL_ARGUMENT_COMPLETIONS];
65
+ if (prefix === "") return completions;
66
+
67
+ const objectiveOption = features.experimentalGoals
68
+ ? /^(edit|add|prioritize)\s+(\S*)$/.exec(prefix)
69
+ : /^edit\s+(\S*)$/.exec(prefix);
70
+ if (objectiveOption) {
71
+ const command = features.experimentalGoals ? (objectiveOption[1] ?? "edit") : "edit";
72
+ const optionPrefix = features.experimentalGoals
73
+ ? (objectiveOption[2] ?? "")
74
+ : (objectiveOption[1] ?? "");
75
+ return optionPrefix === "" || "--tokens".startsWith(optionPrefix)
76
+ ? [
77
+ {
78
+ value: `${command} --tokens `,
79
+ label: "--tokens",
80
+ description:
81
+ command === "edit"
82
+ ? "Set a token budget before the updated goal"
83
+ : "Set a token budget before the queued goal",
84
+ },
85
+ ]
36
86
  : null;
37
87
  }
38
88
  if (/\s/.test(prefix)) return null;
39
- const matches = GOAL_ARGUMENT_COMPLETIONS.filter(
89
+ const matches = completions.filter(
40
90
  (item) => item.value.startsWith(prefix) || item.label.startsWith(prefix),
41
91
  );
42
- return matches.length > 0 ? [...matches] : null;
92
+ return matches.length > 0 ? matches : null;
43
93
  }
44
94
 
45
- export function parseCommand(args: string): CommandResult | string {
95
+ export function parseCommand(
96
+ args: string,
97
+ features: GoalCommandFeatures = {},
98
+ ): CommandResult | string {
46
99
  const tokens = tokenize(args.trim());
47
100
  if (tokens.length === 0) return { kind: "show" };
48
101
  const [first, ...rest] = tokens;
49
102
  if (first === "pause") return rest.length === 0 ? { kind: "pause" } : "Usage: /goal pause";
50
103
  if (first === "resume") return rest.length === 0 ? { kind: "resume" } : "Usage: /goal resume";
51
- if (first === "clear" || first === "stop") return rest.length === 0 ? { kind: "clear" } : "Usage: /goal clear";
104
+ if (first === "clear" || first === "stop")
105
+ return rest.length === 0 ? { kind: "clear" } : "Usage: /goal clear";
52
106
  if (first === "status") return rest.length === 0 ? { kind: "show" } : "Usage: /goal status";
53
107
  if (first === "edit") return parseObjective("edit", rest);
108
+
109
+ if (features.experimentalGoals) {
110
+ if (first === "drop-last" || first === "pop") {
111
+ return rest.length === 0 ? { kind: "drop-last" } : "Usage: /goal drop-last";
112
+ }
113
+ if (first === "skip" || first === "shift") {
114
+ return rest.length === 0 ? { kind: "skip" } : "Usage: /goal skip";
115
+ }
116
+ if (first === "add" || first === "push") return parseObjective("add", rest);
117
+ if (first === "prioritize" || first === "unshift") {
118
+ return parseObjective("prioritize", rest);
119
+ }
120
+ }
121
+
54
122
  return parseObjective("start", tokens);
55
123
  }
56
124
 
57
- function parseObjective(kind: "start" | "edit", tokens: string[]): CommandResult | string {
125
+ function parseObjective(
126
+ kind: "start" | "edit" | "add" | "prioritize",
127
+ tokens: string[],
128
+ ): CommandResult | string {
58
129
  let tokenBudget: number | undefined;
59
130
  const objectiveTokens = [...tokens];
60
131
  if (objectiveTokens[0] === "--tokens") {
61
132
  const rawBudget = objectiveTokens[1];
62
- if (!rawBudget) return "Usage: /goal --tokens 100k <goal_to_complete>";
133
+ if (!rawBudget) {
134
+ return kind === "start"
135
+ ? "Usage: /goal --tokens 100k <goal_to_complete>"
136
+ : `Usage: /goal ${kind} --tokens 100k <goal_to_complete>`;
137
+ }
63
138
  const parsedBudget = parseTokenBudget(rawBudget);
64
139
  if (parsedBudget === undefined) return `Invalid token budget: ${rawBudget}`;
65
140
  tokenBudget = parsedBudget;
66
141
  objectiveTokens.splice(0, 2);
67
142
  }
68
143
  if (objectiveTokens.length === 0) {
69
- return kind === "edit" ? "Usage: /goal edit <goal_to_complete>" : "Usage: /goal <goal_to_complete>";
144
+ if (kind === "start") return "Usage: /goal <goal_to_complete>";
145
+ return `Usage: /goal ${kind} <goal_to_complete>`;
70
146
  }
71
147
  return { kind, objective: objectiveTokens.join(" "), tokenBudget };
72
148
  }
@@ -101,7 +177,8 @@ export function parseTokenBudget(value: string): number | undefined {
101
177
  if (!match) return undefined;
102
178
  const amount = Number(match[1]);
103
179
  if (!Number.isFinite(amount) || amount <= 0) return undefined;
104
- const multiplier = match[2]?.toLowerCase() === "m" ? 1_000_000 : match[2]?.toLowerCase() === "k" ? 1_000 : 1;
180
+ const multiplier =
181
+ match[2]?.toLowerCase() === "m" ? 1_000_000 : match[2]?.toLowerCase() === "k" ? 1_000 : 1;
105
182
  return normalizeTokenBudget(Math.floor(amount * multiplier));
106
183
  }
107
184
 
@@ -115,7 +192,5 @@ export function validateObjective(objective: string): string | undefined {
115
192
  }
116
193
 
117
194
  function normalizeTokenBudget(value: unknown) {
118
- return typeof value === "number" && Number.isSafeInteger(value) && value > 0
119
- ? value
120
- : undefined;
195
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : undefined;
121
196
  }