@narumitw/pi-goal 0.52.1 → 0.52.2

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.
@@ -0,0 +1,348 @@
1
+ // @generated by scripts/build-runtime.mjs; do not edit.
2
+ // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
3
+
4
+ // src/accounting.ts
5
+ function checkpointGoalActiveTime(goal, now, continueClock) {
6
+ const accumulated = nonNegativeFiniteNumber(goal.timeUsedSeconds);
7
+ const startedAt = goal.activeStartedAt;
8
+ if (typeof startedAt === "number" && Number.isFinite(startedAt)) {
9
+ goal.timeUsedSeconds = accumulated + Math.max(0, now - startedAt) / 1e3;
10
+ } else {
11
+ goal.timeUsedSeconds = accumulated;
12
+ }
13
+ goal.activeStartedAt = continueClock ? now : void 0;
14
+ }
15
+ function updateGoalUsage(goal, ctx, continueClock = goal.status === "active") {
16
+ const now = Date.now();
17
+ const baselineTokens = nonNegativeFiniteNumber(goal.baselineTokens);
18
+ goal.baselineTokens = baselineTokens;
19
+ goal.tokensUsed = Math.max(0, currentTokenTotal(ctx) - baselineTokens);
20
+ checkpointGoalActiveTime(goal, now, continueClock);
21
+ goal.updatedAt = now;
22
+ }
23
+ function formatDuration(seconds) {
24
+ const wholeSeconds = Math.max(0, Math.floor(nonNegativeFiniteNumber(seconds)));
25
+ if (wholeSeconds < 60) return `${wholeSeconds}s`;
26
+ const minutes = Math.floor(wholeSeconds / 60);
27
+ if (minutes < 60) return `${minutes}m`;
28
+ const hours = Math.floor(minutes / 60);
29
+ return `${hours}h${minutes % 60}m`;
30
+ }
31
+ function formatTokenCount(value) {
32
+ if (value < 1e3) return `${value}`;
33
+ if (value < 1e6) {
34
+ return `${Number.isInteger(value / 1e3) ? value / 1e3 : (value / 1e3).toFixed(1)}k`;
35
+ }
36
+ return `${Number.isInteger(value / 1e6) ? value / 1e6 : (value / 1e6).toFixed(1)}m`;
37
+ }
38
+ function isNonNegativeFiniteNumber(value) {
39
+ return typeof value === "number" && Number.isFinite(value) && value >= 0;
40
+ }
41
+ function nonNegativeFiniteNumber(value) {
42
+ return isNonNegativeFiniteNumber(value) ? value : 0;
43
+ }
44
+ function normalizeTokenBudget(value) {
45
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : void 0;
46
+ }
47
+ function assistantUsageTokens(value) {
48
+ if (!value || typeof value !== "object") return 0;
49
+ const usage = value;
50
+ if (isNonNegativeFiniteNumber(usage.totalTokens)) return usage.totalTokens;
51
+ return Math.min(
52
+ Number.MAX_SAFE_INTEGER,
53
+ nonNegativeFiniteNumber(usage.input) + nonNegativeFiniteNumber(usage.output) + nonNegativeFiniteNumber(usage.cacheRead) + nonNegativeFiniteNumber(usage.cacheWrite)
54
+ );
55
+ }
56
+ function cumulativeAssistantTokens(entries) {
57
+ let total = 0;
58
+ for (const entry of entries) {
59
+ const candidate = entry;
60
+ if (candidate?.type !== "message") continue;
61
+ const message = candidate.message;
62
+ if (message?.role !== "assistant") continue;
63
+ total = Math.min(Number.MAX_SAFE_INTEGER, total + assistantUsageTokens(message.usage));
64
+ }
65
+ return total;
66
+ }
67
+ function currentTokenTotal(ctx) {
68
+ const sessionManager = ctx.sessionManager;
69
+ return cumulativeAssistantTokens(sessionManager?.getBranch?.() ?? []);
70
+ }
71
+
72
+ // src/errors.ts
73
+ import {
74
+ isContextOverflow,
75
+ isRetryableAssistantError
76
+ } from "@earendil-works/pi-ai";
77
+ import { stripTerminalSequences } from "@earendil-works/pi-tui";
78
+ var USAGE_LIMIT_GOAL_ERROR_PATTERNS = [
79
+ /usage[_\s-]*(?:limit|cap)|chatgpt.{0,32}usage/i,
80
+ /quota.{0,32}(?:reached|exceeded|exhausted|depleted)|(?:reached|exceeded|exhausted|depleted).{0,32}quota/i,
81
+ /insufficient[_\s-]*(?:quota|credits?)|out of credits|out of budget|available balance|payment required/i,
82
+ /(?:credit|balance).{0,32}(?:low|exhausted|depleted)|billing/i
83
+ ];
84
+ var NON_RETRYABLE_GOAL_ERROR_RE = /multi-auth rotation failed|credentials tried|unauthori[sz]ed|invalid api key/i;
85
+ var RETRYABLE_GOAL_ERROR_PATTERNS = [
86
+ /overloaded|rate.?limit|too many requests|\b(?:429|500|502|503|504)\b|service.?unavailable|server.?error|internal.?error/i,
87
+ /provider.?returned.?error|you can retry your request|try your request again|please retry your request/i,
88
+ /network.?error|connection.?(?:error|refused|lost)|other side closed|fetch failed|upstream.?connect|reset before headers|socket hang up/i,
89
+ /timed? out|timeout|terminated|websocket.?(?:closed|error)|ended without|stream ended before message_stop|http2 request did not get a response|retry delay/i,
90
+ /context[_\s-]*length[_\s-]*exceeded|input exceeds the context window/i
91
+ ];
92
+ function safeTerminalText(value) {
93
+ return [...stripTerminalSequences(value)].map((character) => {
94
+ const codePoint = character.codePointAt(0) ?? 0;
95
+ if (character === "\n") return character;
96
+ return codePoint <= 31 || codePoint >= 127 && codePoint <= 159 ? " " : character;
97
+ }).join("").trim();
98
+ }
99
+ function safeGoalMenuText(value, maxCharacters = 120) {
100
+ const sanitized = safeTerminalText(value).replace(/\s+/gu, " ").trim();
101
+ const characters = [...sanitized];
102
+ return characters.length <= maxCharacters ? sanitized : `${characters.slice(0, maxCharacters).join("")}\u2026`;
103
+ }
104
+ function notifyTerminal(ui, message, level) {
105
+ ui.notify(safeTerminalText(message), level);
106
+ }
107
+ function formatError(error) {
108
+ return truncateNotification(error instanceof Error ? error.message : String(error));
109
+ }
110
+ function truncateNotification(value) {
111
+ const safe = [...safeTerminalText(value)];
112
+ return safe.length > 160 ? `${safe.slice(0, 157).join("")}...` : safe.join("");
113
+ }
114
+ function isUsageLimitedGoalInterruption(assistant) {
115
+ const errorMessage = assistant.errorMessage;
116
+ return assistant.stopReason === "error" && typeof errorMessage === "string" && USAGE_LIMIT_GOAL_ERROR_PATTERNS.some((pattern) => pattern.test(errorMessage));
117
+ }
118
+ function isRetryableGoalInterruption(assistant) {
119
+ if (assistant.stopReason !== "error" || !assistant.errorMessage) return false;
120
+ if (isUsageLimitedGoalInterruption(assistant) || NON_RETRYABLE_GOAL_ERROR_RE.test(assistant.errorMessage)) {
121
+ return false;
122
+ }
123
+ return isGoalContextOverflow(assistant) || isRetryableAssistantError(toPiAssistantMessage(assistant)) || RETRYABLE_GOAL_ERROR_PATTERNS.some((pattern) => pattern.test(assistant.errorMessage ?? ""));
124
+ }
125
+ function isGoalContextOverflow(assistant) {
126
+ return isContextOverflow(toPiAssistantMessage(assistant));
127
+ }
128
+ function findFinalAssistantMessage(messages) {
129
+ for (let index = messages.length - 1; index >= 0; index--) {
130
+ const message = messages[index];
131
+ if (!message || typeof message !== "object") continue;
132
+ const candidate = message;
133
+ if (candidate.role !== "assistant") continue;
134
+ const assistant = {
135
+ role: "assistant",
136
+ stopReason: isAgentStopReason(candidate.stopReason) ? candidate.stopReason : void 0,
137
+ errorMessage: typeof candidate.errorMessage === "string" ? candidate.errorMessage : void 0
138
+ };
139
+ if (Array.isArray(candidate.content)) {
140
+ assistant.content = candidate.content;
141
+ }
142
+ if (typeof candidate.api === "string") assistant.api = candidate.api;
143
+ if (typeof candidate.provider === "string") assistant.provider = candidate.provider;
144
+ if (typeof candidate.model === "string") assistant.model = candidate.model;
145
+ if (typeof candidate.timestamp === "number") assistant.timestamp = candidate.timestamp;
146
+ const usage = normalizeUsage(candidate.usage);
147
+ if (usage) assistant.usage = usage;
148
+ return assistant;
149
+ }
150
+ return void 0;
151
+ }
152
+ function toPiAssistantMessage(assistant) {
153
+ return {
154
+ role: "assistant",
155
+ content: assistant.content ?? [],
156
+ api: assistant.api ?? "openai-responses",
157
+ provider: assistant.provider ?? "unknown",
158
+ model: assistant.model ?? "unknown",
159
+ usage: assistant.usage ?? zeroUsage(),
160
+ stopReason: assistant.stopReason ?? "error",
161
+ errorMessage: assistant.errorMessage,
162
+ timestamp: assistant.timestamp ?? Date.now()
163
+ };
164
+ }
165
+ function zeroUsage() {
166
+ return {
167
+ input: 0,
168
+ output: 0,
169
+ cacheRead: 0,
170
+ cacheWrite: 0,
171
+ totalTokens: 0,
172
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
173
+ };
174
+ }
175
+ function isAgentStopReason(value) {
176
+ return ["stop", "length", "toolUse", "error", "aborted"].includes(String(value));
177
+ }
178
+ function normalizeUsage(value) {
179
+ if (!value || typeof value !== "object") return void 0;
180
+ const usage = value;
181
+ if (typeof usage.input !== "number" || typeof usage.output !== "number") return void 0;
182
+ return {
183
+ input: nonNegativeFiniteNumber(usage.input),
184
+ output: nonNegativeFiniteNumber(usage.output),
185
+ cacheRead: nonNegativeFiniteNumber(usage.cacheRead),
186
+ cacheWrite: nonNegativeFiniteNumber(usage.cacheWrite),
187
+ totalTokens: assistantUsageTokens(usage),
188
+ cost: {
189
+ input: usage.cost?.input ?? 0,
190
+ output: usage.cost?.output ?? 0,
191
+ cacheRead: usage.cost?.cacheRead ?? 0,
192
+ cacheWrite: usage.cost?.cacheWrite ?? 0,
193
+ total: usage.cost?.total ?? 0
194
+ }
195
+ };
196
+ }
197
+
198
+ // src/settings.ts
199
+ import { randomUUID } from "node:crypto";
200
+ import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
201
+ import { basename, dirname, join } from "node:path";
202
+ import { getAgentDir } from "@earendil-works/pi-coding-agent";
203
+ var GOAL_SETTINGS_FILE = "pi-goal.json";
204
+ var GOAL_TOOL_VISIBILITIES = ["always", "after-first-goal"];
205
+ var DEFAULT_GOAL_SETTINGS = {
206
+ toolVisibility: "after-first-goal",
207
+ rpc: { enabled: false },
208
+ continuationLimits: { automaticTurns: 25, noProgressTurns: 3 }
209
+ };
210
+ function normalizeGoalSettings(value) {
211
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
212
+ const toolVisibility = Object.hasOwn(value, "toolVisibility") ? Reflect.get(value, "toolVisibility") : DEFAULT_GOAL_SETTINGS.toolVisibility;
213
+ if (!GOAL_TOOL_VISIBILITIES.includes(toolVisibility)) return void 0;
214
+ const rpcValue = Object.hasOwn(value, "rpc") ? Reflect.get(value, "rpc") : void 0;
215
+ if (rpcValue !== void 0 && (typeof rpcValue !== "object" || rpcValue === null || Array.isArray(rpcValue))) {
216
+ return void 0;
217
+ }
218
+ const rpcEnabled = rpcValue && Object.hasOwn(rpcValue, "enabled") ? Reflect.get(rpcValue, "enabled") : DEFAULT_GOAL_SETTINGS.rpc.enabled;
219
+ if (typeof rpcEnabled !== "boolean") return void 0;
220
+ const continuationLimitsValue = Object.hasOwn(value, "continuationLimits") ? Reflect.get(value, "continuationLimits") : void 0;
221
+ if (continuationLimitsValue !== void 0 && (typeof continuationLimitsValue !== "object" || continuationLimitsValue === null || Array.isArray(continuationLimitsValue))) {
222
+ return void 0;
223
+ }
224
+ const automaticTurns = continuationLimitsValue ? normalizeContinuationLimit(
225
+ Reflect.get(continuationLimitsValue, "automaticTurns"),
226
+ DEFAULT_GOAL_SETTINGS.continuationLimits.automaticTurns
227
+ ) : DEFAULT_GOAL_SETTINGS.continuationLimits.automaticTurns;
228
+ const noProgressTurns = continuationLimitsValue ? normalizeContinuationLimit(
229
+ Reflect.get(continuationLimitsValue, "noProgressTurns"),
230
+ DEFAULT_GOAL_SETTINGS.continuationLimits.noProgressTurns
231
+ ) : DEFAULT_GOAL_SETTINGS.continuationLimits.noProgressTurns;
232
+ if (automaticTurns === void 0 || noProgressTurns === void 0) return void 0;
233
+ return {
234
+ toolVisibility,
235
+ rpc: { enabled: rpcEnabled },
236
+ continuationLimits: { automaticTurns, noProgressTurns }
237
+ };
238
+ }
239
+ function normalizeContinuationLimit(value, fallback) {
240
+ if (value === void 0) return fallback;
241
+ if (value === null) return null;
242
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : void 0;
243
+ }
244
+ function saveGoalSettings(settings, settingsPath = join(getAgentDir(), GOAL_SETTINGS_FILE), overrides = {}) {
245
+ const normalized = normalizeGoalSettings(settings);
246
+ if (!normalized) throw new Error("Refusing to save invalid pi-goal settings.");
247
+ let raw = {};
248
+ try {
249
+ const contents = readFileSync(settingsPath, "utf8");
250
+ const parsed = JSON.parse(contents);
251
+ if (!normalizeGoalSettings(parsed)) {
252
+ throw new Error(`${settingsPath}: invalid settings shape`);
253
+ }
254
+ raw = ownRecord(parsed) ?? {};
255
+ } catch (error) {
256
+ if (!isNodeError(error) || error.code !== "ENOENT") {
257
+ throw new Error(`Cannot save invalid settings file: ${formatError2(error)}`);
258
+ }
259
+ }
260
+ const rpc = ownRecord(raw.rpc) ?? {};
261
+ const continuationLimits = ownRecord(raw.continuationLimits) ?? {};
262
+ const document = `${JSON.stringify(
263
+ {
264
+ ...raw,
265
+ toolVisibility: normalized.toolVisibility,
266
+ rpc: { ...rpc, enabled: normalized.rpc.enabled },
267
+ continuationLimits: {
268
+ ...continuationLimits,
269
+ automaticTurns: normalized.continuationLimits.automaticTurns,
270
+ noProgressTurns: normalized.continuationLimits.noProgressTurns
271
+ }
272
+ },
273
+ null,
274
+ 2
275
+ )}
276
+ `;
277
+ const fs = { mkdirSync, writeFileSync, renameSync, rmSync, ...overrides };
278
+ const temporaryPath = join(
279
+ dirname(settingsPath),
280
+ `.${basename(settingsPath)}.${randomUUID()}.tmp`
281
+ );
282
+ try {
283
+ fs.mkdirSync(dirname(settingsPath), { recursive: true });
284
+ fs.writeFileSync(temporaryPath, document, { encoding: "utf8", flag: "wx" });
285
+ fs.renameSync(temporaryPath, settingsPath);
286
+ } finally {
287
+ try {
288
+ fs.rmSync(temporaryPath, { force: true });
289
+ } catch {
290
+ }
291
+ }
292
+ }
293
+ function readGoalSettings(settingsPath = join(getAgentDir(), GOAL_SETTINGS_FILE)) {
294
+ let contents;
295
+ try {
296
+ contents = readFileSync(settingsPath, "utf8");
297
+ } catch (error) {
298
+ if (isNodeError(error) && error.code === "ENOENT") {
299
+ return { kind: "missing", legacyExperimentalGoals: false };
300
+ }
301
+ return { kind: "invalid", reason: `${settingsPath}: ${formatError2(error)}` };
302
+ }
303
+ try {
304
+ const parsed = JSON.parse(contents);
305
+ const settings = normalizeGoalSettings(parsed);
306
+ return settings ? { kind: "loaded", settings, legacyExperimentalGoals: hasLegacyExperimentalGoals(parsed) } : { kind: "invalid", reason: `${settingsPath}: invalid settings shape` };
307
+ } catch (error) {
308
+ return { kind: "invalid", reason: `${settingsPath}: ${formatError2(error)}` };
309
+ }
310
+ }
311
+ function hasLegacyExperimentalGoals(value) {
312
+ const experimental = ownRecord(ownRecord(value)?.experimental);
313
+ return experimental?.goals === true;
314
+ }
315
+ function ownRecord(value) {
316
+ return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
317
+ }
318
+ function isNodeError(error) {
319
+ return error instanceof Error && "code" in error;
320
+ }
321
+ function formatError2(error) {
322
+ return error instanceof Error ? error.message : String(error);
323
+ }
324
+
325
+ export {
326
+ checkpointGoalActiveTime,
327
+ updateGoalUsage,
328
+ formatDuration,
329
+ formatTokenCount,
330
+ isNonNegativeFiniteNumber,
331
+ nonNegativeFiniteNumber,
332
+ normalizeTokenBudget,
333
+ currentTokenTotal,
334
+ safeTerminalText,
335
+ safeGoalMenuText,
336
+ notifyTerminal,
337
+ formatError,
338
+ truncateNotification,
339
+ isUsageLimitedGoalInterruption,
340
+ isRetryableGoalInterruption,
341
+ isGoalContextOverflow,
342
+ findFinalAssistantMessage,
343
+ GOAL_SETTINGS_FILE,
344
+ DEFAULT_GOAL_SETTINGS,
345
+ saveGoalSettings,
346
+ readGoalSettings
347
+ };
348
+ //# sourceMappingURL=chunk-UA7LMS63.ts.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/accounting.ts", "../../src/errors.ts", "../../src/settings.ts"],
4
+ "sourcesContent": ["import type { Usage } from \"@earendil-works/pi-ai\";\n\nexport interface GoalAccountingState {\n\tstatus: string;\n\tbaselineTokens: number;\n\ttokensUsed: number;\n\ttimeUsedSeconds: number;\n\tactiveStartedAt?: number;\n\tupdatedAt: number;\n}\n\ninterface AssistantUsageEntryLike {\n\ttype?: unknown;\n\tmessage?: unknown;\n}\n\ninterface UsageContext {\n\tsessionManager?: unknown;\n}\n\nexport function checkpointGoalActiveTime(\n\tgoal: GoalAccountingState,\n\tnow: number,\n\tcontinueClock: boolean,\n) {\n\tconst accumulated = nonNegativeFiniteNumber(goal.timeUsedSeconds);\n\tconst startedAt = goal.activeStartedAt;\n\tif (typeof startedAt === \"number\" && Number.isFinite(startedAt)) {\n\t\tgoal.timeUsedSeconds = accumulated + Math.max(0, now - startedAt) / 1000;\n\t} else {\n\t\tgoal.timeUsedSeconds = accumulated;\n\t}\n\tgoal.activeStartedAt = continueClock ? now : undefined;\n}\n\nexport function updateGoalUsage(\n\tgoal: GoalAccountingState,\n\tctx: UsageContext,\n\tcontinueClock = goal.status === \"active\",\n) {\n\tconst now = Date.now();\n\tconst baselineTokens = nonNegativeFiniteNumber(goal.baselineTokens);\n\tgoal.baselineTokens = baselineTokens;\n\tgoal.tokensUsed = Math.max(0, currentTokenTotal(ctx) - baselineTokens);\n\tcheckpointGoalActiveTime(goal, now, continueClock);\n\tgoal.updatedAt = now;\n}\n\nexport function formatDuration(seconds: number) {\n\tconst wholeSeconds = Math.max(0, Math.floor(nonNegativeFiniteNumber(seconds)));\n\tif (wholeSeconds < 60) return `${wholeSeconds}s`;\n\tconst minutes = Math.floor(wholeSeconds / 60);\n\tif (minutes < 60) return `${minutes}m`;\n\tconst hours = Math.floor(minutes / 60);\n\treturn `${hours}h${minutes % 60}m`;\n}\n\nexport function formatTokenCount(value: number) {\n\tif (value < 1_000) return `${value}`;\n\tif (value < 1_000_000) {\n\t\treturn `${Number.isInteger(value / 1_000) ? value / 1_000 : (value / 1_000).toFixed(1)}k`;\n\t}\n\treturn `${Number.isInteger(value / 1_000_000) ? value / 1_000_000 : (value / 1_000_000).toFixed(1)}m`;\n}\n\nexport function isNonNegativeFiniteNumber(value: unknown): value is number {\n\treturn typeof value === \"number\" && Number.isFinite(value) && value >= 0;\n}\n\nexport function nonNegativeFiniteNumber(value: unknown) {\n\treturn isNonNegativeFiniteNumber(value) ? value : 0;\n}\n\nexport function normalizeTokenBudget(value: unknown) {\n\treturn typeof value === \"number\" && Number.isSafeInteger(value) && value > 0 ? value : undefined;\n}\n\nexport function assistantUsageTokens(value: unknown) {\n\tif (!value || typeof value !== \"object\") return 0;\n\tconst usage = value as Partial<Usage>;\n\tif (isNonNegativeFiniteNumber(usage.totalTokens)) return usage.totalTokens;\n\treturn Math.min(\n\t\tNumber.MAX_SAFE_INTEGER,\n\t\tnonNegativeFiniteNumber(usage.input) +\n\t\t\tnonNegativeFiniteNumber(usage.output) +\n\t\t\tnonNegativeFiniteNumber(usage.cacheRead) +\n\t\t\tnonNegativeFiniteNumber(usage.cacheWrite),\n\t);\n}\n\nexport function cumulativeAssistantTokens(entries: unknown[]) {\n\tlet total = 0;\n\tfor (const entry of entries) {\n\t\tconst candidate = entry as AssistantUsageEntryLike;\n\t\tif (candidate?.type !== \"message\") continue;\n\t\tconst message = candidate.message as { role?: unknown; usage?: unknown } | undefined;\n\t\tif (message?.role !== \"assistant\") continue;\n\t\ttotal = Math.min(Number.MAX_SAFE_INTEGER, total + assistantUsageTokens(message.usage));\n\t}\n\treturn total;\n}\n\nexport function currentTokenTotal(ctx: UsageContext): number {\n\tconst sessionManager = ctx.sessionManager as { getBranch?: () => unknown[] } | undefined;\n\treturn cumulativeAssistantTokens(sessionManager?.getBranch?.() ?? []);\n}\n", "import {\n\tisContextOverflow,\n\tisRetryableAssistantError,\n\ttype AssistantMessage as PiAssistantMessage,\n\ttype Usage,\n} from \"@earendil-works/pi-ai\";\nimport { stripTerminalSequences } from \"@earendil-works/pi-tui\";\nimport { assistantUsageTokens, nonNegativeFiniteNumber } from \"./accounting.js\";\n\nexport type AgentStopReason = \"stop\" | \"length\" | \"toolUse\" | \"error\" | \"aborted\";\n\nexport interface AssistantMessageLike {\n\trole: \"assistant\";\n\tstopReason?: AgentStopReason;\n\terrorMessage?: string;\n\tcontent?: PiAssistantMessage[\"content\"];\n\tapi?: PiAssistantMessage[\"api\"];\n\tprovider?: PiAssistantMessage[\"provider\"];\n\tmodel?: string;\n\tusage?: Usage;\n\ttimestamp?: number;\n}\n\nconst USAGE_LIMIT_GOAL_ERROR_PATTERNS = [\n\t/usage[_\\s-]*(?:limit|cap)|chatgpt.{0,32}usage/i,\n\t/quota.{0,32}(?:reached|exceeded|exhausted|depleted)|(?:reached|exceeded|exhausted|depleted).{0,32}quota/i,\n\t/insufficient[_\\s-]*(?:quota|credits?)|out of credits|out of budget|available balance|payment required/i,\n\t/(?:credit|balance).{0,32}(?:low|exhausted|depleted)|billing/i,\n] as const;\nconst NON_RETRYABLE_GOAL_ERROR_RE =\n\t/multi-auth rotation failed|credentials tried|unauthori[sz]ed|invalid api key/i;\nconst RETRYABLE_GOAL_ERROR_PATTERNS = [\n\t/overloaded|rate.?limit|too many requests|\\b(?:429|500|502|503|504)\\b|service.?unavailable|server.?error|internal.?error/i,\n\t/provider.?returned.?error|you can retry your request|try your request again|please retry your request/i,\n\t/network.?error|connection.?(?:error|refused|lost)|other side closed|fetch failed|upstream.?connect|reset before headers|socket hang up/i,\n\t/timed? out|timeout|terminated|websocket.?(?:closed|error)|ended without|stream ended before message_stop|http2 request did not get a response|retry delay/i,\n\t/context[_\\s-]*length[_\\s-]*exceeded|input exceeds the context window/i,\n] as const;\n\nexport function safeTerminalText(value: string) {\n\treturn [...stripTerminalSequences(value)]\n\t\t.map((character) => {\n\t\t\tconst codePoint = character.codePointAt(0) ?? 0;\n\t\t\tif (character === \"\\n\") return character;\n\t\t\treturn codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f) ? \" \" : character;\n\t\t})\n\t\t.join(\"\")\n\t\t.trim();\n}\n\nexport function safeGoalMenuText(value: string, maxCharacters = 120) {\n\tconst sanitized = safeTerminalText(value).replace(/\\s+/gu, \" \").trim();\n\tconst characters = [...sanitized];\n\treturn characters.length <= maxCharacters\n\t\t? sanitized\n\t\t: `${characters.slice(0, maxCharacters).join(\"\")}\u2026`;\n}\n\nexport function notifyTerminal(\n\tui: { notify: (message: string, level?: \"info\" | \"warning\" | \"error\") => void },\n\tmessage: string,\n\tlevel?: \"info\" | \"warning\" | \"error\",\n) {\n\tui.notify(safeTerminalText(message), level);\n}\n\nexport function formatError(error: unknown) {\n\treturn truncateNotification(error instanceof Error ? error.message : String(error));\n}\n\nexport function truncateNotification(value: string) {\n\tconst safe = [...safeTerminalText(value)];\n\treturn safe.length > 160 ? `${safe.slice(0, 157).join(\"\")}...` : safe.join(\"\");\n}\n\nexport function isUsageLimitedGoalInterruption(assistant: AssistantMessageLike) {\n\tconst errorMessage = assistant.errorMessage;\n\treturn (\n\t\tassistant.stopReason === \"error\" &&\n\t\ttypeof errorMessage === \"string\" &&\n\t\tUSAGE_LIMIT_GOAL_ERROR_PATTERNS.some((pattern) => pattern.test(errorMessage))\n\t);\n}\n\nexport function isRetryableGoalInterruption(assistant: AssistantMessageLike) {\n\tif (assistant.stopReason !== \"error\" || !assistant.errorMessage) return false;\n\tif (\n\t\tisUsageLimitedGoalInterruption(assistant) ||\n\t\tNON_RETRYABLE_GOAL_ERROR_RE.test(assistant.errorMessage)\n\t) {\n\t\treturn false;\n\t}\n\treturn (\n\t\tisGoalContextOverflow(assistant) ||\n\t\tisRetryableAssistantError(toPiAssistantMessage(assistant)) ||\n\t\tRETRYABLE_GOAL_ERROR_PATTERNS.some((pattern) => pattern.test(assistant.errorMessage ?? \"\"))\n\t);\n}\n\nexport function isGoalContextOverflow(assistant: AssistantMessageLike) {\n\treturn isContextOverflow(toPiAssistantMessage(assistant));\n}\n\nexport function findFinalAssistantMessage(messages: unknown[]): AssistantMessageLike | undefined {\n\tfor (let index = messages.length - 1; index >= 0; index--) {\n\t\tconst message = messages[index];\n\t\tif (!message || typeof message !== \"object\") continue;\n\t\tconst candidate = message as Record<string, unknown>;\n\t\tif (candidate.role !== \"assistant\") continue;\n\t\tconst assistant: AssistantMessageLike = {\n\t\t\trole: \"assistant\",\n\t\t\tstopReason: isAgentStopReason(candidate.stopReason) ? candidate.stopReason : undefined,\n\t\t\terrorMessage: typeof candidate.errorMessage === \"string\" ? candidate.errorMessage : undefined,\n\t\t};\n\t\tif (Array.isArray(candidate.content)) {\n\t\t\tassistant.content = candidate.content as PiAssistantMessage[\"content\"];\n\t\t}\n\t\tif (typeof candidate.api === \"string\") assistant.api = candidate.api;\n\t\tif (typeof candidate.provider === \"string\") assistant.provider = candidate.provider;\n\t\tif (typeof candidate.model === \"string\") assistant.model = candidate.model;\n\t\tif (typeof candidate.timestamp === \"number\") assistant.timestamp = candidate.timestamp;\n\t\tconst usage = normalizeUsage(candidate.usage);\n\t\tif (usage) assistant.usage = usage;\n\t\treturn assistant;\n\t}\n\treturn undefined;\n}\n\nfunction toPiAssistantMessage(assistant: AssistantMessageLike): PiAssistantMessage {\n\treturn {\n\t\trole: \"assistant\",\n\t\tcontent: assistant.content ?? [],\n\t\tapi: assistant.api ?? \"openai-responses\",\n\t\tprovider: assistant.provider ?? \"unknown\",\n\t\tmodel: assistant.model ?? \"unknown\",\n\t\tusage: assistant.usage ?? zeroUsage(),\n\t\tstopReason: assistant.stopReason ?? \"error\",\n\t\terrorMessage: assistant.errorMessage,\n\t\ttimestamp: assistant.timestamp ?? Date.now(),\n\t};\n}\n\nfunction zeroUsage(): Usage {\n\treturn {\n\t\tinput: 0,\n\t\toutput: 0,\n\t\tcacheRead: 0,\n\t\tcacheWrite: 0,\n\t\ttotalTokens: 0,\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t};\n}\n\nfunction isAgentStopReason(value: unknown): value is AgentStopReason {\n\treturn [\"stop\", \"length\", \"toolUse\", \"error\", \"aborted\"].includes(String(value));\n}\n\nfunction normalizeUsage(value: unknown): Usage | undefined {\n\tif (!value || typeof value !== \"object\") return undefined;\n\tconst usage = value as Partial<Usage>;\n\tif (typeof usage.input !== \"number\" || typeof usage.output !== \"number\") return undefined;\n\treturn {\n\t\tinput: nonNegativeFiniteNumber(usage.input),\n\t\toutput: nonNegativeFiniteNumber(usage.output),\n\t\tcacheRead: nonNegativeFiniteNumber(usage.cacheRead),\n\t\tcacheWrite: nonNegativeFiniteNumber(usage.cacheWrite),\n\t\ttotalTokens: assistantUsageTokens(usage),\n\t\tcost: {\n\t\t\tinput: usage.cost?.input ?? 0,\n\t\t\toutput: usage.cost?.output ?? 0,\n\t\t\tcacheRead: usage.cost?.cacheRead ?? 0,\n\t\t\tcacheWrite: usage.cost?.cacheWrite ?? 0,\n\t\t\ttotal: usage.cost?.total ?? 0,\n\t\t},\n\t};\n}\n", "import { randomUUID } from \"node:crypto\";\nimport { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from \"node:fs\";\nimport { basename, dirname, join } from \"node:path\";\nimport { getAgentDir } from \"@earendil-works/pi-coding-agent\";\n\nexport const GOAL_SETTINGS_FILE = \"pi-goal.json\";\nexport const GOAL_TOOL_VISIBILITIES = [\"always\", \"after-first-goal\"] as const;\n\nexport type GoalToolVisibility = (typeof GOAL_TOOL_VISIBILITIES)[number];\nexport type ContinuationLimit = number | null;\n\nexport interface GoalSettings {\n\ttoolVisibility: GoalToolVisibility;\n\trpc: {\n\t\tenabled: boolean;\n\t};\n\tcontinuationLimits: {\n\t\tautomaticTurns: ContinuationLimit;\n\t\tnoProgressTurns: ContinuationLimit;\n\t};\n}\n\nexport const DEFAULT_GOAL_SETTINGS: GoalSettings = {\n\ttoolVisibility: \"after-first-goal\",\n\trpc: { enabled: false },\n\tcontinuationLimits: { automaticTurns: 25, noProgressTurns: 3 },\n};\n\nexport type GoalSettingsLoadResult =\n\t| { kind: \"missing\"; legacyExperimentalGoals: false }\n\t| { kind: \"invalid\"; reason: string }\n\t| { kind: \"loaded\"; settings: GoalSettings; legacyExperimentalGoals: boolean };\n\nexport type GoalSettingsLoadIssue = Extract<GoalSettingsLoadResult, { kind: \"invalid\" }>;\n\ninterface GoalSettingsSaveFileSystem {\n\tmkdirSync: typeof mkdirSync;\n\twriteFileSync: typeof writeFileSync;\n\trenameSync: typeof renameSync;\n\trmSync: typeof rmSync;\n}\n\nexport function normalizeGoalSettings(value: unknown): GoalSettings | undefined {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) return undefined;\n\tconst toolVisibility = Object.hasOwn(value, \"toolVisibility\")\n\t\t? Reflect.get(value, \"toolVisibility\")\n\t\t: DEFAULT_GOAL_SETTINGS.toolVisibility;\n\tif (!GOAL_TOOL_VISIBILITIES.includes(toolVisibility as GoalToolVisibility)) return undefined;\n\n\tconst rpcValue = Object.hasOwn(value, \"rpc\") ? Reflect.get(value, \"rpc\") : undefined;\n\tif (\n\t\trpcValue !== undefined &&\n\t\t(typeof rpcValue !== \"object\" || rpcValue === null || Array.isArray(rpcValue))\n\t) {\n\t\treturn undefined;\n\t}\n\tconst rpcEnabled =\n\t\trpcValue && Object.hasOwn(rpcValue, \"enabled\")\n\t\t\t? Reflect.get(rpcValue, \"enabled\")\n\t\t\t: DEFAULT_GOAL_SETTINGS.rpc.enabled;\n\tif (typeof rpcEnabled !== \"boolean\") return undefined;\n\n\tconst continuationLimitsValue = Object.hasOwn(value, \"continuationLimits\")\n\t\t? Reflect.get(value, \"continuationLimits\")\n\t\t: undefined;\n\tif (\n\t\tcontinuationLimitsValue !== undefined &&\n\t\t(typeof continuationLimitsValue !== \"object\" ||\n\t\t\tcontinuationLimitsValue === null ||\n\t\t\tArray.isArray(continuationLimitsValue))\n\t) {\n\t\treturn undefined;\n\t}\n\tconst automaticTurns = continuationLimitsValue\n\t\t? normalizeContinuationLimit(\n\t\t\t\tReflect.get(continuationLimitsValue, \"automaticTurns\"),\n\t\t\t\tDEFAULT_GOAL_SETTINGS.continuationLimits.automaticTurns,\n\t\t\t)\n\t\t: DEFAULT_GOAL_SETTINGS.continuationLimits.automaticTurns;\n\tconst noProgressTurns = continuationLimitsValue\n\t\t? normalizeContinuationLimit(\n\t\t\t\tReflect.get(continuationLimitsValue, \"noProgressTurns\"),\n\t\t\t\tDEFAULT_GOAL_SETTINGS.continuationLimits.noProgressTurns,\n\t\t\t)\n\t\t: DEFAULT_GOAL_SETTINGS.continuationLimits.noProgressTurns;\n\tif (automaticTurns === undefined || noProgressTurns === undefined) return undefined;\n\n\treturn {\n\t\ttoolVisibility: toolVisibility as GoalToolVisibility,\n\t\trpc: { enabled: rpcEnabled },\n\t\tcontinuationLimits: { automaticTurns, noProgressTurns },\n\t};\n}\n\nfunction normalizeContinuationLimit(\n\tvalue: unknown,\n\tfallback: ContinuationLimit,\n): ContinuationLimit | undefined {\n\tif (value === undefined) return fallback;\n\tif (value === null) return null;\n\treturn typeof value === \"number\" && Number.isSafeInteger(value) && value > 0 ? value : undefined;\n}\n\nexport function saveGoalSettings(\n\tsettings: GoalSettings,\n\tsettingsPath = join(getAgentDir(), GOAL_SETTINGS_FILE),\n\toverrides: Partial<GoalSettingsSaveFileSystem> = {},\n) {\n\tconst normalized = normalizeGoalSettings(settings);\n\tif (!normalized) throw new Error(\"Refusing to save invalid pi-goal settings.\");\n\n\tlet raw: Record<string, unknown> = {};\n\ttry {\n\t\tconst contents = readFileSync(settingsPath, \"utf8\");\n\t\tconst parsed = JSON.parse(contents) as unknown;\n\t\tif (!normalizeGoalSettings(parsed)) {\n\t\t\tthrow new Error(`${settingsPath}: invalid settings shape`);\n\t\t}\n\t\traw = ownRecord(parsed) ?? {};\n\t} catch (error) {\n\t\tif (!isNodeError(error) || error.code !== \"ENOENT\") {\n\t\t\tthrow new Error(`Cannot save invalid settings file: ${formatError(error)}`);\n\t\t}\n\t}\n\n\tconst rpc = ownRecord(raw.rpc) ?? {};\n\tconst continuationLimits = ownRecord(raw.continuationLimits) ?? {};\n\tconst document = `${JSON.stringify(\n\t\t{\n\t\t\t...raw,\n\t\t\ttoolVisibility: normalized.toolVisibility,\n\t\t\trpc: { ...rpc, enabled: normalized.rpc.enabled },\n\t\t\tcontinuationLimits: {\n\t\t\t\t...continuationLimits,\n\t\t\t\tautomaticTurns: normalized.continuationLimits.automaticTurns,\n\t\t\t\tnoProgressTurns: normalized.continuationLimits.noProgressTurns,\n\t\t\t},\n\t\t},\n\t\tnull,\n\t\t2,\n\t)}\\n`;\n\tconst fs = { mkdirSync, writeFileSync, renameSync, rmSync, ...overrides };\n\tconst temporaryPath = join(\n\t\tdirname(settingsPath),\n\t\t`.${basename(settingsPath)}.${randomUUID()}.tmp`,\n\t);\n\ttry {\n\t\tfs.mkdirSync(dirname(settingsPath), { recursive: true });\n\t\tfs.writeFileSync(temporaryPath, document, { encoding: \"utf8\", flag: \"wx\" });\n\t\tfs.renameSync(temporaryPath, settingsPath);\n\t} finally {\n\t\ttry {\n\t\t\tfs.rmSync(temporaryPath, { force: true });\n\t\t} catch {\n\t\t\t// Best-effort cleanup must not replace the save result.\n\t\t}\n\t}\n}\n\nexport function readGoalSettings(\n\tsettingsPath = join(getAgentDir(), GOAL_SETTINGS_FILE),\n): GoalSettingsLoadResult {\n\tlet contents: string;\n\ttry {\n\t\tcontents = readFileSync(settingsPath, \"utf8\");\n\t} catch (error: unknown) {\n\t\tif (isNodeError(error) && error.code === \"ENOENT\") {\n\t\t\treturn { kind: \"missing\", legacyExperimentalGoals: false };\n\t\t}\n\t\treturn { kind: \"invalid\", reason: `${settingsPath}: ${formatError(error)}` };\n\t}\n\n\ttry {\n\t\tconst parsed = JSON.parse(contents) as unknown;\n\t\tconst settings = normalizeGoalSettings(parsed);\n\t\treturn settings\n\t\t\t? { kind: \"loaded\", settings, legacyExperimentalGoals: hasLegacyExperimentalGoals(parsed) }\n\t\t\t: { kind: \"invalid\", reason: `${settingsPath}: invalid settings shape` };\n\t} catch (error: unknown) {\n\t\treturn { kind: \"invalid\", reason: `${settingsPath}: ${formatError(error)}` };\n\t}\n}\n\nfunction hasLegacyExperimentalGoals(value: unknown) {\n\tconst experimental = ownRecord(ownRecord(value)?.experimental);\n\treturn experimental?.goals === true;\n}\n\nfunction ownRecord(value: unknown): Record<string, unknown> | undefined {\n\treturn value && typeof value === \"object\" && !Array.isArray(value)\n\t\t? (value as Record<string, unknown>)\n\t\t: undefined;\n}\n\nfunction isNodeError(error: unknown): error is NodeJS.ErrnoException {\n\treturn error instanceof Error && \"code\" in error;\n}\n\nfunction formatError(error: unknown) {\n\treturn error instanceof Error ? error.message : String(error);\n}\n"],
5
+ "mappings": ";;;;AAoBO,SAAS,yBACf,MACA,KACA,eACC;AACD,QAAM,cAAc,wBAAwB,KAAK,eAAe;AAChE,QAAM,YAAY,KAAK;AACvB,MAAI,OAAO,cAAc,YAAY,OAAO,SAAS,SAAS,GAAG;AAChE,SAAK,kBAAkB,cAAc,KAAK,IAAI,GAAG,MAAM,SAAS,IAAI;AAAA,EACrE,OAAO;AACN,SAAK,kBAAkB;AAAA,EACxB;AACA,OAAK,kBAAkB,gBAAgB,MAAM;AAC9C;AAEO,SAAS,gBACf,MACA,KACA,gBAAgB,KAAK,WAAW,UAC/B;AACD,QAAM,MAAM,KAAK,IAAI;AACrB,QAAM,iBAAiB,wBAAwB,KAAK,cAAc;AAClE,OAAK,iBAAiB;AACtB,OAAK,aAAa,KAAK,IAAI,GAAG,kBAAkB,GAAG,IAAI,cAAc;AACrE,2BAAyB,MAAM,KAAK,aAAa;AACjD,OAAK,YAAY;AAClB;AAEO,SAAS,eAAe,SAAiB;AAC/C,QAAM,eAAe,KAAK,IAAI,GAAG,KAAK,MAAM,wBAAwB,OAAO,CAAC,CAAC;AAC7E,MAAI,eAAe,GAAI,QAAO,GAAG,YAAY;AAC7C,QAAM,UAAU,KAAK,MAAM,eAAe,EAAE;AAC5C,MAAI,UAAU,GAAI,QAAO,GAAG,OAAO;AACnC,QAAM,QAAQ,KAAK,MAAM,UAAU,EAAE;AACrC,SAAO,GAAG,KAAK,IAAI,UAAU,EAAE;AAChC;AAEO,SAAS,iBAAiB,OAAe;AAC/C,MAAI,QAAQ,IAAO,QAAO,GAAG,KAAK;AAClC,MAAI,QAAQ,KAAW;AACtB,WAAO,GAAG,OAAO,UAAU,QAAQ,GAAK,IAAI,QAAQ,OAAS,QAAQ,KA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