@narumitw/pi-goal 0.54.4 → 0.54.6

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.
Files changed (39) hide show
  1. package/README.md +41 -166
  2. package/dist/chunks/{chunk-UQRRW4CY.js → chunk-6T3MHA45.js} +7 -6
  3. package/dist/chunks/chunk-6T3MHA45.js.map +7 -0
  4. package/dist/chunks/{chunk-QWIUWKRW.js → chunk-WLIH47XO.js} +57 -77
  5. package/dist/chunks/chunk-WLIH47XO.js.map +7 -0
  6. package/dist/chunks/{menu-WEFDREGC.js → menu-RGCRCQJK.js} +7 -22
  7. package/dist/chunks/menu-RGCRCQJK.js.map +7 -0
  8. package/dist/chunks/{settings-ui-MVYTTBHW.js → settings-ui-BAWNTINU.js} +6 -18
  9. package/dist/chunks/settings-ui-BAWNTINU.js.map +7 -0
  10. package/dist/index.ts +92 -126
  11. package/dist/index.ts.map +2 -2
  12. package/docs/managing-goals.md +47 -0
  13. package/docs/settings.md +91 -0
  14. package/package.json +55 -55
  15. package/src/accounting.ts +62 -66
  16. package/src/command-registration.ts +104 -102
  17. package/src/command.ts +101 -112
  18. package/src/commands.ts +465 -501
  19. package/src/errors.ts +127 -122
  20. package/src/goal-contract.ts +64 -64
  21. package/src/goal.ts +25 -25
  22. package/src/lifecycle.ts +615 -628
  23. package/src/markers.ts +6 -6
  24. package/src/menu.ts +565 -591
  25. package/src/persistence.ts +177 -192
  26. package/src/prompts.ts +53 -67
  27. package/src/run-protocol.ts +299 -325
  28. package/src/runtime.ts +1422 -1495
  29. package/src/safety.ts +51 -51
  30. package/src/settings-ui.ts +366 -393
  31. package/src/settings.ts +134 -147
  32. package/src/tool-policy.ts +6 -6
  33. package/src/tools.ts +360 -371
  34. package/src/wait.ts +47 -51
  35. package/src/workflow-mutex.ts +68 -68
  36. package/dist/chunks/chunk-QWIUWKRW.js.map +0 -7
  37. package/dist/chunks/chunk-UQRRW4CY.js.map +0 -7
  38. package/dist/chunks/menu-WEFDREGC.js.map +0 -7
  39. package/dist/chunks/settings-ui-MVYTTBHW.js.map +0 -7
@@ -1,7 +0,0 @@
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\";\n\nexport type ContinuationLimit = number | null;\n\nexport interface GoalSettings {\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\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\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\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\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,KAAO,QAAQ,CAAC,CAAC;AAAA,EAC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,SAAS,UAAU;AAC5C;AAEA,SAASA,aAAY,OAAgB;AACpC,SAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC7D;",
6
- "names": ["formatError"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/menu.ts"],
4
- "sourcesContent": ["import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport type { ActionMenuItem } from \"@narumitw/pi-tui-kit\";\nimport { formatTokenCount as formatCompactTokenCount, formatDuration } from \"./accounting.js\";\nimport { parseTokenBudget } from \"./command.js\";\nimport type { GoalCommandController } from \"./commands.js\";\nimport { notifyTerminal, safeGoalMenuText } from \"./errors.js\";\n\nexport { safeGoalMenuText } from \"./errors.js\";\n\nimport type { ActiveGoal } from \"./persistence.js\";\nimport { type GoalRuntime, goalSummary } from \"./runtime.js\";\n\nexport const GOAL_MENU_ACTIONS = {\n\tstart: \"Start a goal\u2026\",\n\tstartBudget: \"Start with token budget\u2026\",\n\tpause: \"Pause goal\",\n\tresume: \"Resume goal\",\n\treviewSafety: \"Review and continue\u2026\",\n\tincreaseBudget: \"Increase budget and resume\u2026\",\n\tedit: \"Edit goal\u2026\",\n\treplace: \"Replace goal\u2026\",\n\tstatus: \"View full status\",\n\tsettings: \"Settings\u2026\",\n\thelp: \"Help\",\n\tclear: \"Clear goal\u2026\",\n\tclose: \"Close\",\n} as const;\n\ninterface GoalMenuRuntimeView {\n\tactiveGoal?: ActiveGoal;\n\tsettings: GoalRuntime[\"settings\"];\n\trecordGoalUsage?: GoalRuntime[\"recordGoalUsage\"];\n\tpersistGoal?: GoalRuntime[\"persistGoal\"];\n\tupdateStatus?: GoalRuntime[\"updateStatus\"];\n}\n\nexport interface GoalMenuState {\n\ttitle: string;\n\tactions: string[];\n}\n\ntype ShowSettings = (ctx: ExtensionCommandContext, target?: \"automatic\") => Promise<void>;\ntype GoalMenuScreen =\n\t| \"main\"\n\t| \"start-budget\"\n\t| \"start-custom-budget\"\n\t| \"increase-budget\"\n\t| \"safety\"\n\t| \"status\"\n\t| \"help\";\ntype GoalMenuAction =\n\t| \"start\"\n\t| \"start-with-budget\"\n\t| \"start-with-custom-budget\"\n\t| \"submit-increase-budget\"\n\t| \"pause\"\n\t| \"resume\"\n\t| \"safety-resume\"\n\t| \"safety-settings\"\n\t| \"edit\"\n\t| \"replace\"\n\t| \"settings\"\n\t| \"clear\"\n\t| \"back\";\n\nexport function buildGoalMenuState(runtime: GoalMenuRuntimeView): GoalMenuState {\n\tconst goal = runtime.activeGoal;\n\tconst pausedByAutomaticLimit =\n\t\tgoal?.status === \"paused\" && goal.safetyPauseCause === \"continuation_limit\";\n\tconst waitingReason = goal?.waiting ? safeGoalMenuText(goal.waiting.reason) : undefined;\n\tconst state = pausedByAutomaticLimit\n\t\t? \"Paused \u2014 automatic-work limit reached\"\n\t\t: waitingReason\n\t\t\t? `Waiting \u2014 ${waitingReason}`\n\t\t\t: displayStatus(goal?.status);\n\tconst automaticTurnLimit = runtime.settings.continuationLimits.automaticTurns;\n\tconst used = goal?.automaticModelTurns ?? 0;\n\tconst automaticResponses =\n\t\tautomaticTurnLimit === null\n\t\t\t? `Automatic work: ${used} responses \u00B7 Unlimited`\n\t\t\t: `Automatic work: ${used} of ${automaticTurnLimit} responses${\n\t\t\t\t\tused < automaticTurnLimit ? ` \u00B7 ${automaticTurnLimit - used} remaining` : \"\"\n\t\t\t\t}`;\n\tconst title = goal\n\t\t? [\n\t\t\t\t`Goal \u00B7 ${state}`,\n\t\t\t\tsafeGoalMenuText(goal.text),\n\t\t\t\t`Usage: ${\n\t\t\t\t\tgoal.tokenBudget === undefined\n\t\t\t\t\t\t? formatDuration(goal.timeUsedSeconds)\n\t\t\t\t\t\t: `${formatTokenCount(goal.tokensUsed)}/${formatTokenCount(goal.tokenBudget)}`\n\t\t\t\t}`,\n\t\t\t\tautomaticResponses,\n\t\t\t\t...(pausedByAutomaticLimit\n\t\t\t\t\t? [\"Progress is saved. Review the safety limit before continuing.\"]\n\t\t\t\t\t: []),\n\t\t\t].join(\"\\n\")\n\t\t: [\n\t\t\t\t`Goal \u00B7 ${state}`,\n\t\t\t\t\"No goal is currently set\",\n\t\t\t\tautomaticTurnLimit === null\n\t\t\t\t\t? \"Automatic work is configured as Unlimited.\"\n\t\t\t\t\t: `Automatic work is configured to pause after ${automaticTurnLimit} responses.`,\n\t\t\t].join(\"\\n\");\n\n\tconst actions: string[] = [];\n\tif (!goal || goal.status === \"complete\") {\n\t\tactions.push(GOAL_MENU_ACTIONS.start, GOAL_MENU_ACTIONS.startBudget);\n\t} else if (goal.waiting) {\n\t\tactions.push(GOAL_MENU_ACTIONS.resume);\n\t} else if (goal.status === \"active\") {\n\t\tactions.push(GOAL_MENU_ACTIONS.pause);\n\t} else if (goal.status === \"budget_limited\") {\n\t\tactions.push(GOAL_MENU_ACTIONS.increaseBudget);\n\t} else if (pausedByAutomaticLimit) {\n\t\tactions.push(GOAL_MENU_ACTIONS.reviewSafety);\n\t} else {\n\t\tactions.push(GOAL_MENU_ACTIONS.resume);\n\t}\n\tif (goal && goal.status !== \"complete\") {\n\t\tactions.push(GOAL_MENU_ACTIONS.edit, GOAL_MENU_ACTIONS.replace);\n\t}\n\tif (goal) actions.push(GOAL_MENU_ACTIONS.status);\n\tactions.push(GOAL_MENU_ACTIONS.settings, GOAL_MENU_ACTIONS.help);\n\tif (goal) actions.push(GOAL_MENU_ACTIONS.clear);\n\tactions.push(GOAL_MENU_ACTIONS.close);\n\treturn { title, actions };\n}\n\nexport async function showGoalManager(\n\truntime: GoalMenuRuntimeView,\n\tcommands: GoalCommandController,\n\tctx: ExtensionCommandContext,\n\tshowSettings: ShowSettings,\n): Promise<void> {\n\tif (ctx.mode !== \"tui\") {\n\t\tcommands.showGoal(ctx);\n\t\treturn;\n\t}\n\tconst owner = runtime as GoalRuntime;\n\tconst generation = owner.menuGeneration;\n\tconst ownerSignal = owner.menuController?.signal;\n\tconst isMenuCurrent = () =>\n\t\towner.menuController === undefined ||\n\t\t(generation === owner.menuGeneration && !owner.menuController.signal.aborted);\n\tconst { defineMenu, runMenu } = await import(\"@narumitw/pi-tui-kit\");\n\tif (!isMenuCurrent()) return;\n\tlet displayedGoal: ActiveGoal | undefined;\n\tlet displayedBudgetGoal: ActiveGoal | undefined;\n\tlet displayedBudgetValue: number | undefined;\n\tlet displayedBudgetUsage: number | undefined;\n\tlet displayedBudgetStatus: ActiveGoal[\"status\"] | undefined;\n\tconst menu = defineMenu<undefined, GoalMenuScreen, GoalMenuAction, ExtensionCommandContext>({\n\t\tstart: \"main\",\n\t\tscreens: {\n\t\t\tmain: () => {\n\t\t\t\trefreshGoalMenuState(runtime, ctx);\n\t\t\t\tconst state = buildGoalMenuState(runtime);\n\t\t\t\tdisplayedGoal = runtime.activeGoal;\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"actions\",\n\t\t\t\t\ttitle: \"Goal\",\n\t\t\t\t\tlines: state.title.split(\"\\n\").slice(1),\n\t\t\t\t\titems: state.actions.map(goalMainMenuItem),\n\t\t\t\t\thint: \"close\",\n\t\t\t\t};\n\t\t\t},\n\t\t\t\"start-budget\": () => {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"actions\",\n\t\t\t\t\ttitle: \"Choose token budget\",\n\t\t\t\t\tlines: tokenBudgetGuidance(runtime.settings.continuationLimits.automaticTurns),\n\t\t\t\t\titems: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"25k\",\n\t\t\t\t\t\t\tlabel: \"25k \u2014 Lower token ceiling\",\n\t\t\t\t\t\t\tdescription: \"Set the cumulative token limit to 25k.\",\n\t\t\t\t\t\t\taction: \"start-with-budget\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"100k\",\n\t\t\t\t\t\t\tlabel: \"100k \u2014 Suggested\",\n\t\t\t\t\t\t\tdescription: \"Set the cumulative token limit to 100k.\",\n\t\t\t\t\t\t\taction: \"start-with-budget\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"300k\",\n\t\t\t\t\t\t\tlabel: \"300k \u2014 Higher token ceiling\",\n\t\t\t\t\t\t\tdescription: \"Set the cumulative token limit to 300k.\",\n\t\t\t\t\t\t\taction: \"start-with-budget\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"custom\",\n\t\t\t\t\t\t\tlabel: \"Set a custom budget\u2026\",\n\t\t\t\t\t\t\tdescription: \"Enter an exact cumulative token limit.\",\n\t\t\t\t\t\t\tto: \"start-custom-budget\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ id: \"back\", label: \"Back\", action: \"back\" },\n\t\t\t\t\t],\n\t\t\t\t\thint: \"back\",\n\t\t\t\t};\n\t\t\t},\n\t\t\t\"start-custom-budget\": () => ({\n\t\t\t\tkind: \"input\",\n\t\t\t\ttitle: \"Custom token budget\",\n\t\t\t\tlines: customTokenBudgetGuidance(runtime.settings.continuationLimits.automaticTurns),\n\t\t\t\tplaceholder: \"100k\",\n\t\t\t\taction: \"start-with-custom-budget\",\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\t\"increase-budget\": () => {\n\t\t\t\tconst goal = runtime.activeGoal;\n\t\t\t\tdisplayedBudgetGoal = goal;\n\t\t\t\tdisplayedBudgetValue = goal?.tokenBudget;\n\t\t\t\tdisplayedBudgetUsage = goal?.tokensUsed;\n\t\t\t\tdisplayedBudgetStatus = goal?.status;\n\t\t\t\tif (goal && goal.tokensUsed >= Number.MAX_SAFE_INTEGER) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tkind: \"detail\",\n\t\t\t\t\t\ttitle: \"Increase token budget unavailable\",\n\t\t\t\t\t\tlines: [\n\t\t\t\t\t\t\t`Current usage: ${formatBudgetDecisionValue(goal.tokensUsed)}`,\n\t\t\t\t\t\t\t\"No larger safe whole-number token budget is available. Progress remains saved; choose Back and clear or replace the goal when ready.\",\n\t\t\t\t\t\t],\n\t\t\t\t\t\thint: \"back\",\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"input\",\n\t\t\t\t\ttitle: \"Increase token budget\",\n\t\t\t\t\tlines: goal\n\t\t\t\t\t\t? increaseTokenBudgetGuidance(goal, runtime.settings.continuationLimits.automaticTurns)\n\t\t\t\t\t\t: [\"The budget-limited goal is no longer available. Return to the Goal menu.\"],\n\t\t\t\t\tplaceholder: goal ? suggestedIncreasedBudget(goal) : \"300k\",\n\t\t\t\t\taction: \"submit-increase-budget\",\n\t\t\t\t\thint: \"back\",\n\t\t\t\t};\n\t\t\t},\n\t\t\tsafety: () => {\n\t\t\t\tconst goal = runtime.activeGoal;\n\t\t\t\tdisplayedGoal = goal;\n\t\t\t\tconst limit = runtime.settings.continuationLimits.automaticTurns;\n\t\t\t\tconst used = goal?.automaticModelTurns ?? 0;\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"actions\",\n\t\t\t\t\ttitle: \"Automatic work paused\",\n\t\t\t\t\tlines: goal\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\tautomaticPauseSummary(used, limit),\n\t\t\t\t\t\t\t\t`${safeGoalMenuText(goal.text)} is preserved.`,\n\t\t\t\t\t\t\t\t`${formatInteger(goal.tokensUsed)} cumulative tokens and ${formatDuration(goal.timeUsedSeconds)} active time are preserved.`,\n\t\t\t\t\t\t\t\t\"The objective and usage are preserved.\",\n\t\t\t\t\t\t\t\tlimit === null\n\t\t\t\t\t\t\t\t\t? \"Continuing resets the counter to 0 and resumes with Unlimited automatic work.\"\n\t\t\t\t\t\t\t\t\t: `Continuing resets the counter to 0 and allows up to ${limit} more automatic model responses.`,\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t: [\"The paused goal is no longer available. Return to the Goal menu.\"],\n\t\t\t\t\titems: goal\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tid: \"continue\",\n\t\t\t\t\t\t\t\t\tlabel:\n\t\t\t\t\t\t\t\t\t\tlimit === null\n\t\t\t\t\t\t\t\t\t\t\t? \"Continue \u2014 Unlimited\"\n\t\t\t\t\t\t\t\t\t\t\t: `Continue \u2014 up to ${limit} more responses`,\n\t\t\t\t\t\t\t\t\taction: \"safety-resume\" as const,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tid: \"settings\",\n\t\t\t\t\t\t\t\t\tlabel: \"Change automatic-work limit\u2026\",\n\t\t\t\t\t\t\t\t\taction: \"safety-settings\" as const,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{ id: \"back\", label: \"Back\", action: \"back\" as const },\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t: [{ id: \"back\", label: \"Back\", action: \"back\" as const }],\n\t\t\t\t\thint: \"back\",\n\t\t\t\t};\n\t\t\t},\n\t\t\tstatus: () => ({\n\t\t\t\tkind: \"detail\",\n\t\t\t\ttitle: \"Goal status\",\n\t\t\t\tlines: runtime.activeGoal\n\t\t\t\t\t? goalSummary(\n\t\t\t\t\t\t\truntime.activeGoal,\n\t\t\t\t\t\t\truntime.settings.continuationLimits.automaticTurns,\n\t\t\t\t\t\t).split(\"\\n\")\n\t\t\t\t\t: [\"No goal is currently set.\"],\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\thelp: () => ({\n\t\t\t\tkind: \"detail\",\n\t\t\t\ttitle: \"Goal help\",\n\t\t\t\tlines: goalHelp().split(\"\\n\").slice(1),\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t},\n\t\tactions: {\n\t\t\tstart: async () => {\n\t\t\t\tawait startFromMenu(commands, ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\t\"start-with-budget\": async ({ itemId, signal }) => {\n\t\t\t\tconst budget = parseTokenBudget(itemId);\n\t\t\t\tif (budget === undefined) return { kind: \"rejected\" };\n\t\t\t\treturn startBudgetedGoal(\n\t\t\t\t\tcommands,\n\t\t\t\t\tctx,\n\t\t\t\t\tbudget,\n\t\t\t\t\truntime.settings.continuationLimits.automaticTurns,\n\t\t\t\t\tsignal,\n\t\t\t\t\tisMenuCurrent,\n\t\t\t\t\t\"stay\",\n\t\t\t\t);\n\t\t\t},\n\t\t\t\"start-with-custom-budget\": async ({ value, signal }) => {\n\t\t\t\tconst budget = parseTokenBudget(value ?? \"\");\n\t\t\t\tif (budget === undefined) {\n\t\t\t\t\tnotifyTerminal(\n\t\t\t\t\t\tctx.ui,\n\t\t\t\t\t\t\"Enter a positive token amount, for example 25k, 300k, or 1.5m.\",\n\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t);\n\t\t\t\t\treturn { kind: \"rejected\" };\n\t\t\t\t}\n\t\t\t\treturn startBudgetedGoal(\n\t\t\t\t\tcommands,\n\t\t\t\t\tctx,\n\t\t\t\t\tbudget,\n\t\t\t\t\truntime.settings.continuationLimits.automaticTurns,\n\t\t\t\t\tsignal,\n\t\t\t\t\tisMenuCurrent,\n\t\t\t\t\t\"back\",\n\t\t\t\t);\n\t\t\t},\n\t\t\t\"submit-increase-budget\": async ({ value, signal }) => {\n\t\t\t\tconst goal = displayedBudgetGoal;\n\t\t\t\tconst budget = parseTokenBudget(value ?? \"\");\n\t\t\t\tif (budget === undefined) {\n\t\t\t\t\tnotifyTerminal(\n\t\t\t\t\t\tctx.ui,\n\t\t\t\t\t\t\"Enter a positive token amount, for example 300k, 1.5m, or 300000.\",\n\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t);\n\t\t\t\t\treturn { kind: \"rejected\" };\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\t!goal ||\n\t\t\t\t\t!requireCurrentBudgetPreview(\n\t\t\t\t\t\truntime,\n\t\t\t\t\t\tgoal,\n\t\t\t\t\t\tdisplayedBudgetValue,\n\t\t\t\t\t\tdisplayedBudgetUsage,\n\t\t\t\t\t\tdisplayedBudgetStatus,\n\t\t\t\t\t\tctx,\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn { kind: \"close\" };\n\t\t\t\t}\n\t\t\t\tif (budget <= goal.tokensUsed) {\n\t\t\t\t\tnotifyTerminal(\n\t\t\t\t\t\tctx.ui,\n\t\t\t\t\t\t`Enter a new cumulative total greater than current usage (${formatCompactTokenCount(goal.tokensUsed)}).`,\n\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t);\n\t\t\t\t\treturn { kind: \"rejected\" };\n\t\t\t\t}\n\t\t\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t\t\t\"Increase goal budget?\",\n\t\t\t\t\tincreaseBudgetPreview(goal, budget, runtime.settings.continuationLimits.automaticTurns),\n\t\t\t\t);\n\t\t\t\tif (signal.aborted || !isMenuCurrent()) return { kind: \"close\" };\n\t\t\t\tif (!confirmed) return { kind: \"rejected\" };\n\t\t\t\tif (\n\t\t\t\t\t!requireCurrentBudgetPreview(\n\t\t\t\t\t\truntime,\n\t\t\t\t\t\tgoal,\n\t\t\t\t\t\tdisplayedBudgetValue,\n\t\t\t\t\t\tdisplayedBudgetUsage,\n\t\t\t\t\t\tdisplayedBudgetStatus,\n\t\t\t\t\t\tctx,\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn { kind: \"close\" };\n\t\t\t\t}\n\t\t\t\tawait commands.editGoal(goal.text, budget, ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tpause: async () => {\n\t\t\t\tif (!displayedGoal || !requireCurrentMenuGoal(runtime, displayedGoal, ctx)) {\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t}\n\t\t\t\tcommands.pauseGoal(ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tresume: async () => {\n\t\t\t\tif (!displayedGoal || !requireCurrentMenuGoal(runtime, displayedGoal, ctx)) {\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t}\n\t\t\t\tawait commands.resumeGoal(ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\t\"safety-resume\": async () => {\n\t\t\t\tif (!displayedGoal || !requireCurrentMenuGoal(runtime, displayedGoal, ctx)) {\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t}\n\t\t\t\tawait commands.resumeGoal(ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\t\"safety-settings\": async () => {\n\t\t\t\tif (!displayedGoal || !requireCurrentMenuGoal(runtime, displayedGoal, ctx)) {\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t}\n\t\t\t\tconst expectedGoal = displayedGoal;\n\t\t\t\tawait showSettings(ctx, \"automatic\");\n\t\t\t\tif (!isMenuCurrent()) return { kind: \"close\" };\n\t\t\t\tif (!requireCurrentMenuGoal(runtime, expectedGoal, ctx)) return { kind: \"stay\" };\n\t\t\t\treturn { kind: \"stay\" };\n\t\t\t},\n\t\t\tedit: async () => {\n\t\t\t\tif (!displayedGoal || !requireCurrentMenuGoal(runtime, displayedGoal, ctx)) {\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t}\n\t\t\t\tawait editFromMenu(runtime, commands, ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\treplace: async () => {\n\t\t\t\tawait startFromMenu(commands, ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tsettings: async () => {\n\t\t\t\tawait showSettings(ctx);\n\t\t\t\treturn { kind: \"stay\" };\n\t\t\t},\n\t\t\tclear: async () => {\n\t\t\t\tconst previewedGoal = runtime.activeGoal;\n\t\t\t\tif (!(await confirmClear(runtime, ctx))) return { kind: \"stay\" };\n\t\t\t\tif (previewedGoal && !requireCurrentMenuGoal(runtime, previewedGoal, ctx)) {\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t}\n\t\t\t\tcommands.clearGoal(ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tback: async () => ({ kind: \"back\" }),\n\t\t},\n\t});\n\tawait runMenu(ctx, menu, {\n\t\tgetState: () => undefined,\n\t\tsignal: ownerSignal,\n\t\tisCurrent: isMenuCurrent,\n\t});\n}\n\nfunction goalMainMenuItem(label: string): ActionMenuItem<GoalMenuScreen, GoalMenuAction> {\n\tif (label === GOAL_MENU_ACTIONS.status) return { id: \"status\", label, to: \"status\" as const };\n\tif (label === GOAL_MENU_ACTIONS.startBudget) {\n\t\treturn { id: \"start-budget\", label, to: \"start-budget\" as const };\n\t}\n\tif (label === GOAL_MENU_ACTIONS.increaseBudget) {\n\t\treturn { id: \"increase-budget\", label, to: \"increase-budget\" as const };\n\t}\n\tif (label === GOAL_MENU_ACTIONS.reviewSafety) {\n\t\treturn { id: \"review-safety\", label, to: \"safety\" as const };\n\t}\n\tif (label === GOAL_MENU_ACTIONS.help) return { id: \"help\", label, to: \"help\" as const };\n\tif (label === GOAL_MENU_ACTIONS.close) return { id: \"close\", label, close: true as const };\n\tconst actions = new Map<string, GoalMenuAction>([\n\t\t[GOAL_MENU_ACTIONS.start, \"start\"],\n\t\t[GOAL_MENU_ACTIONS.pause, \"pause\"],\n\t\t[GOAL_MENU_ACTIONS.resume, \"resume\"],\n\t\t[GOAL_MENU_ACTIONS.edit, \"edit\"],\n\t\t[GOAL_MENU_ACTIONS.replace, \"replace\"],\n\t\t[GOAL_MENU_ACTIONS.settings, \"settings\"],\n\t\t[GOAL_MENU_ACTIONS.clear, \"clear\"],\n\t]);\n\treturn { id: actions.get(label) ?? label, label, action: actions.get(label) ?? \"settings\" };\n}\n\nfunction refreshGoalMenuState(runtime: GoalMenuRuntimeView, ctx: ExtensionCommandContext) {\n\tconst goal = runtime.activeGoal;\n\tif (!goal) return;\n\truntime.recordGoalUsage?.(goal, ctx);\n\truntime.persistGoal?.(goal);\n\truntime.updateStatus?.(ctx, goal);\n}\n\nasync function startFromMenu(commands: GoalCommandController, ctx: ExtensionCommandContext) {\n\tconst objective = (await ctx.ui.editor(\"Goal objective\", \"\"))?.trim();\n\tif (!objective) return;\n\tawait commands.startGoal(objective, undefined, ctx);\n}\n\nasync function startBudgetedGoal(\n\tcommands: GoalCommandController,\n\tctx: ExtensionCommandContext,\n\tbudget: number,\n\tautomaticLimit: number | null,\n\tsignal: AbortSignal,\n\tisMenuCurrent: () => boolean,\n\tcancelTransition: \"stay\" | \"back\",\n) {\n\tconst objective = (\n\t\tawait ctx.ui.editor(\n\t\t\t`Goal objective \u00B7 Token budget ${formatCompactTokenCount(budget)} \u00B7 ${automaticLimit === null ? \"Automatic Unlimited\" : `Automatic limit ${automaticLimit}`}`,\n\t\t\t\"\",\n\t\t)\n\t)?.trim();\n\tif (signal.aborted || !isMenuCurrent()) return { kind: \"close\" as const };\n\tif (!objective) return { kind: cancelTransition } as const;\n\tawait commands.startGoal(\n\t\tobjective,\n\t\tbudget,\n\t\tctx,\n\t\tundefined,\n\t\t() => !signal.aborted && isMenuCurrent(),\n\t\t() => !signal.aborted && isMenuCurrent(),\n\t);\n\treturn { kind: \"close\" as const };\n}\n\nfunction tokenBudgetGuidance(automaticLimit: number | null) {\n\treturn [\n\t\t\"Set the maximum cumulative token usage for this goal.\",\n\t\t\"The final model call may exceed the limit; this is not a dollar-cost cap.\",\n\t\tautomaticBudgetGuidance(automaticLimit),\n\t];\n}\n\nfunction customTokenBudgetGuidance(automaticLimit: number | null) {\n\treturn [\n\t\t\"Enter the maximum cumulative token usage for this goal.\",\n\t\t\"Examples: 25k, 300k, 1.5m, or 300000.\",\n\t\t\"The final model call may exceed this value; this is not a dollar-cost cap.\",\n\t\tautomaticBudgetGuidance(automaticLimit),\n\t];\n}\n\nfunction automaticBudgetGuidance(automaticLimit: number | null) {\n\treturn automaticLimit === null\n\t\t? \"Automatic work has no response-count cap.\"\n\t\t: `Automatic work will also pause after ${automaticLimit} responses.`;\n}\n\nfunction increaseTokenBudgetGuidance(goal: ActiveGoal, automaticLimit: number | null) {\n\treturn [\n\t\t`Current budget: ${formatBudgetDecisionValue(goal.tokenBudget ?? 0)}`,\n\t\t`Current usage: ${formatBudgetDecisionValue(goal.tokensUsed)}`,\n\t\t`Enter a new cumulative total greater than ${formatBudgetDecisionValue(goal.tokensUsed)}.`,\n\t\t\"Examples: 300k, 1.5m, or 300000.\",\n\t\t\"The final model call may exceed the limit; this is not a dollar-cost cap.\",\n\t\tautomaticBudgetGuidance(automaticLimit),\n\t];\n}\n\nfunction suggestedIncreasedBudget(goal: ActiveGoal) {\n\tconst floor = Math.max(goal.tokensUsed, goal.tokenBudget ?? 0);\n\tfor (const suggestion of [25_000, 100_000, 300_000, 500_000, 1_000_000]) {\n\t\tif (suggestion > floor) return formatCompactTokenCount(suggestion);\n\t}\n\treturn formatCompactTokenCount(\n\t\tMath.min(Number.MAX_SAFE_INTEGER, Math.max(Math.floor(floor) + 1, Math.ceil(floor * 2))),\n\t);\n}\n\nfunction formatBudgetDecisionValue(value: number) {\n\tconst compact = formatCompactTokenCount(value);\n\tif (value < 1_000 || value % 1_000 === 0) return compact;\n\treturn `${compact} (${formatInteger(value)} tokens)`;\n}\n\nfunction increaseBudgetPreview(goal: ActiveGoal, budget: number, automaticLimit: number | null) {\n\treturn [\n\t\t`Goal: ${safeGoalMenuText(goal.text, 4_000)}`,\n\t\t`Budget: ${formatCompactTokenCount(goal.tokenBudget ?? 0)} \u2192 ${formatCompactTokenCount(budget)}`,\n\t\t`Current usage: ${formatCompactTokenCount(goal.tokensUsed)}`,\n\t\tautomaticLimit === null\n\t\t\t? \"Automatic work: Unlimited after resume\"\n\t\t\t: `Automatic work: up to ${automaticLimit} more responses after resume`,\n\t\t\"The goal will resume immediately.\",\n\t].join(\"\\n\");\n}\n\nasync function editFromMenu(\n\truntime: GoalMenuRuntimeView,\n\tcommands: GoalCommandController,\n\tctx: ExtensionCommandContext,\n) {\n\tconst goal = runtime.activeGoal;\n\tif (!goal) return;\n\tconst objective = (await ctx.ui.editor(\"Edit goal objective\", goal.text))?.trim();\n\tif (!objective || objective === goal.text) return;\n\tif (!requireCurrentMenuGoal(runtime, goal, ctx)) return;\n\tif (goal.status === \"active\") {\n\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t\"Apply goal edit?\",\n\t\t\t`Current goal:\\n${safeGoalMenuText(goal.text, 4_000)}\\n\\nUpdated goal:\\n${safeGoalMenuText(objective, 4_000)}\\n\\nApplying this edit starts a new guarded goal instance.`,\n\t\t);\n\t\tif (!confirmed || !requireCurrentMenuGoal(runtime, goal, ctx)) return;\n\t}\n\tawait commands.editGoal(objective, undefined, ctx);\n}\n\nasync function confirmClear(runtime: GoalMenuRuntimeView, ctx: ExtensionCommandContext) {\n\tconst goal = runtime.activeGoal;\n\tif (!goal) return false;\n\treturn ctx.ui.confirm(\n\t\t\"Clear goal?\",\n\t\t`Remove this goal:\\n\\n${safeGoalMenuText(goal.text, 4_000)}\\n\\nThis cannot be undone.`,\n\t);\n}\n\nfunction requireCurrentBudgetPreview(\n\truntime: GoalMenuRuntimeView,\n\texpectedGoal: ActiveGoal,\n\texpectedBudget: number | undefined,\n\texpectedUsage: number | undefined,\n\texpectedStatus: ActiveGoal[\"status\"] | undefined,\n\tctx: ExtensionCommandContext,\n) {\n\tconst current = runtime.activeGoal;\n\tif (\n\t\tcurrent?.id === expectedGoal.id &&\n\t\tcurrent.tokenBudget === expectedBudget &&\n\t\tcurrent.tokensUsed === expectedUsage &&\n\t\tcurrent.status === expectedStatus\n\t) {\n\t\treturn true;\n\t}\n\tnotifyTerminal(\n\t\tctx.ui,\n\t\t\"The goal changed or its usage changed while the budget dialog was open. Reopen /goal and try again.\",\n\t\t\"warning\",\n\t);\n\treturn false;\n}\n\nfunction requireCurrentMenuGoal(\n\truntime: GoalMenuRuntimeView,\n\texpected: ActiveGoal,\n\tctx: ExtensionCommandContext,\n) {\n\tif (runtime.activeGoal?.id === expected.id) return true;\n\tnotifyTerminal(\n\t\tctx.ui,\n\t\t\"The active goal changed while the dialog was open. Reopen /goal and try again.\",\n\t\t\"warning\",\n\t);\n\treturn false;\n}\n\nfunction displayStatus(status?: ActiveGoal[\"status\"]) {\n\tif (!status) return \"No goal\";\n\tif (status === \"usage_limited\") return \"Usage limited\";\n\tif (status === \"budget_limited\") return \"Budget limited\";\n\treturn status[0]?.toUpperCase() + status.slice(1);\n}\n\nfunction formatTokenCount(tokens: number) {\n\treturn String(tokens);\n}\n\nfunction formatInteger(value: number) {\n\treturn value.toLocaleString(\"en-US\", { maximumFractionDigits: 0 });\n}\n\nfunction automaticPauseSummary(used: number, limit: number | null) {\n\tif (limit === null) {\n\t\treturn `Goal paused after ${used} responses at its previous safety limit. Current limit: Unlimited.`;\n\t}\n\tif (used < limit) {\n\t\treturn `Goal paused after ${used} responses at its previous safety limit. Current automatic-work limit: ${limit}.`;\n\t}\n\treturn `Goal reached its ${used}-of-${limit} safety limit.`;\n}\n\nfunction goalHelp() {\n\treturn [\n\t\t\"Goal menu\",\n\t\t\"Use the menu for guided status, edits, settings, and confirmations.\",\n\t\t\"Direct routes remain available for deterministic workflows:\",\n\t\t\"/goal <objective>\",\n\t\t\"/goal status | pause | resume | edit | clear\",\n\t\t\"/goal --tokens 100k <objective>\",\n\t\t\"Escape cancels the current menu or input without changing goal state.\",\n\t].join(\"\\n\");\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;AAYO,IAAM,oBAAoB;AAAA,EAChC,OAAO;AAAA,EACP,aAAa;AAAA,EACb,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AACR;AAuCO,SAAS,mBAAmB,SAA6C;AAC/E,QAAM,OAAO,QAAQ;AACrB,QAAM,yBACL,MAAM,WAAW,YAAY,KAAK,qBAAqB;AACxD,QAAM,gBAAgB,MAAM,UAAU,iBAAiB,KAAK,QAAQ,MAAM,IAAI;AAC9E,QAAM,QAAQ,yBACX,+CACA,gBACC,k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
- "names": ["formatTokenCount"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/settings-ui.ts"],
4
- "sourcesContent": ["import { join } from \"node:path\";\nimport { type ExtensionCommandContext, getAgentDir } from \"@earendil-works/pi-coding-agent\";\nimport { notifyTerminal, safeTerminalText } from \"./errors.js\";\nimport type { GoalRuntime } from \"./runtime.js\";\nimport {\n\tDEFAULT_GOAL_SETTINGS,\n\tGOAL_SETTINGS_FILE,\n\ttype GoalSettings,\n\tsaveGoalSettings,\n} from \"./settings.js\";\n\ninterface GoalSettingsUiOptions {\n\tsettingsPath?: string;\n\tinitialScreen?: \"settings\" | \"automatic\";\n\tsave?: (settings: GoalSettings, settingsPath: string) => void;\n}\n\ninterface GoalSettingsApplyOptions {\n\tsave?: (settings: GoalSettings) => void;\n}\n\ntype LimitField = \"automaticTurns\" | \"noProgressTurns\";\ntype LimitSelection = \"unlimited\" | \"default\" | \"custom\" | \"off\";\nexport async function showGoalSettings(\n\truntime: GoalRuntime,\n\tctx: ExtensionCommandContext,\n\toptions: GoalSettingsUiOptions = {},\n) {\n\tconst settingsPath = options.settingsPath ?? join(getAgentDir(), GOAL_SETTINGS_FILE);\n\tif (ctx.mode !== \"tui\") {\n\t\tnotifyTerminal(\n\t\t\tctx.ui,\n\t\t\t`Edit pi-goal settings manually: ${safeTerminalText(settingsPath)}`,\n\t\t\t\"info\",\n\t\t);\n\t\treturn;\n\t}\n\tconst generation = runtime.menuGeneration;\n\tconst isMenuCurrent = () =>\n\t\tgeneration === runtime.menuGeneration && !runtime.menuController.signal.aborted;\n\tconst { defineMenu, runMenu } = await import(\"@narumitw/pi-tui-kit\");\n\tif (!isMenuCurrent()) return;\n\tconst invalid = runtime.settingsLoadIssue?.kind === \"invalid\";\n\tconst previewGoalIds = new Map<LimitField, string | null>();\n\ttype Screen = \"settings\" | \"automatic\" | \"no-progress\" | \"invalid\";\n\ttype Action =\n\t\t| \"open-automatic\"\n\t\t| \"open-no-progress\"\n\t\t| \"choose-automatic\"\n\t\t| \"choose-no-progress\"\n\t\t| \"set-rpc\";\n\tconst menu = defineMenu<undefined, Screen, Action, ExtensionCommandContext>({\n\t\tstart: invalid ? \"invalid\" : (options.initialScreen ?? \"settings\"),\n\t\tscreens: {\n\t\t\tsettings: () => ({\n\t\t\t\tkind: \"settings\",\n\t\t\t\ttitle: \"Pi Goal Settings\",\n\t\t\t\tlines: [`User settings \u00B7 ${safeTerminalText(settingsPath)}`],\n\t\t\t\titems: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"automaticTurns\",\n\t\t\t\t\t\tlabel: \"Automatic-work limit\",\n\t\t\t\t\t\tdescription: \"Pause automatic Goal work after a visible number of model responses.\",\n\t\t\t\t\t\tcurrentValue: formatAutomaticSettingValue(\n\t\t\t\t\t\t\truntime.settings.continuationLimits.automaticTurns,\n\t\t\t\t\t\t),\n\t\t\t\t\t\taction: \"open-automatic\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"noProgressTurns\",\n\t\t\t\t\t\tlabel: \"No-progress guard\",\n\t\t\t\t\t\tdescription: \"Pause after repeated or empty tool-free automatic runs.\",\n\t\t\t\t\t\tcurrentValue: formatNoProgressSettingValue(\n\t\t\t\t\t\t\truntime.settings.continuationLimits.noProgressTurns,\n\t\t\t\t\t\t),\n\t\t\t\t\t\taction: \"open-no-progress\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"rpcEnabled\",\n\t\t\t\t\t\tlabel: \"Managed run RPC\",\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\"Allow trusted installed extensions to start and cancel Goal runs; this is not an extension sandbox.\",\n\t\t\t\t\t\tcurrentValue: runtime.settings.rpc.enabled ? \"On\" : \"Off\",\n\t\t\t\t\t\tvalues: [\"Off\", \"On\"],\n\t\t\t\t\t\taction: \"set-rpc\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t}),\n\t\t\tautomatic: () => limitChoiceScreen(runtime, \"automaticTurns\", \"choose-automatic\"),\n\t\t\t\"no-progress\": () => limitChoiceScreen(runtime, \"noProgressTurns\", \"choose-no-progress\"),\n\t\t\tinvalid: () => ({\n\t\t\t\tkind: \"detail\",\n\t\t\t\ttitle: \"Pi Goal Settings \u00B7 Read only\",\n\t\t\t\tlines: [\n\t\t\t\t\t`Invalid settings file. Pi-goal is using built-in defaults. Fix ${safeTerminalText(settingsPath)} and run /reload. The file will not be overwritten.`,\n\t\t\t\t\t`Automatic-work limit: ${formatAutomaticWork(runtime.settings.continuationLimits.automaticTurns)}`,\n\t\t\t\t\t`No-progress guard: ${formatNoProgressProtection(runtime.settings.continuationLimits.noProgressTurns)}`,\n\t\t\t\t\t`Managed run RPC: ${runtime.settings.rpc.enabled ? \"On\" : \"Off\"}`,\n\t\t\t\t],\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t},\n\t\tactions: {\n\t\t\t\"open-automatic\": async () => {\n\t\t\t\tpreviewGoalIds.set(\"automaticTurns\", runtime.activeGoal?.id ?? null);\n\t\t\t\treturn { kind: \"to\", screen: \"automatic\" };\n\t\t\t},\n\t\t\t\"open-no-progress\": async () => {\n\t\t\t\tpreviewGoalIds.set(\"noProgressTurns\", runtime.activeGoal?.id ?? null);\n\t\t\t\treturn { kind: \"to\", screen: \"no-progress\" };\n\t\t\t},\n\t\t\t\"choose-automatic\": async ({ itemId }) =>\n\t\t\t\tapplyLimitChoice(\n\t\t\t\t\truntime,\n\t\t\t\t\tctx,\n\t\t\t\t\toptions,\n\t\t\t\t\tsettingsPath,\n\t\t\t\t\t\"automaticTurns\",\n\t\t\t\t\titemId,\n\t\t\t\t\tpreviewGoalIds.get(\"automaticTurns\") ?? null,\n\t\t\t\t\tisMenuCurrent,\n\t\t\t\t),\n\t\t\t\"choose-no-progress\": async ({ itemId }) =>\n\t\t\t\tapplyLimitChoice(\n\t\t\t\t\truntime,\n\t\t\t\t\tctx,\n\t\t\t\t\toptions,\n\t\t\t\t\tsettingsPath,\n\t\t\t\t\t\"noProgressTurns\",\n\t\t\t\t\titemId,\n\t\t\t\t\tpreviewGoalIds.get(\"noProgressTurns\") ?? null,\n\t\t\t\t\tisMenuCurrent,\n\t\t\t\t),\n\t\t\t\"set-rpc\": async ({ value }) => {\n\t\t\t\tconst enabled = value === \"On\";\n\t\t\t\tif (enabled === runtime.settings.rpc.enabled) return { kind: \"stay\" };\n\t\t\t\ttry {\n\t\t\t\t\tconst next = {\n\t\t\t\t\t\t...structuredClone(runtime.settings),\n\t\t\t\t\t\trpc: { enabled },\n\t\t\t\t\t} satisfies GoalSettings;\n\t\t\t\t\tapplyGoalSettings(runtime, next, ctx, {\n\t\t\t\t\t\tsave: (settings) => (options.save ?? saveGoalSettings)(settings, settingsPath),\n\t\t\t\t\t});\n\t\t\t\t\tnotifyTerminal(ctx.ui, `Managed run RPC: ${enabled ? \"On\" : \"Off\"}.`, \"info\");\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t} catch (error) {\n\t\t\t\t\tnotifySettingsFailure(ctx, settingsPath, error);\n\t\t\t\t\treturn { kind: \"rejected\" };\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t});\n\tawait runMenu(ctx, menu, {\n\t\tgetState: () => undefined,\n\t\tsignal: runtime.menuController.signal,\n\t\tisCurrent: isMenuCurrent,\n\t});\n}\n\nfunction limitChoiceScreen(\n\truntime: GoalRuntime,\n\tfield: LimitField,\n\taction: \"choose-automatic\" | \"choose-no-progress\",\n) {\n\tconst value = runtime.settings.continuationLimits[field];\n\tconst goal = runtime.activeGoal;\n\treturn {\n\t\tkind: \"actions\" as const,\n\t\ttitle: field === \"automaticTurns\" ? \"Automatic-work limit\" : \"No-progress guard\",\n\t\tlines: [\n\t\t\tfield === \"automaticTurns\"\n\t\t\t\t? `Current: ${formatAutomaticWork(value)}`\n\t\t\t\t: `Current: ${formatNoProgressProtection(value)}`,\n\t\t\t...(field === \"automaticTurns\"\n\t\t\t\t? [\n\t\t\t\t\t\t`Set a whole-number response limit for each automatic-work epoch. Default: ${DEFAULT_GOAL_SETTINGS.continuationLimits.automaticTurns}.`,\n\t\t\t\t\t]\n\t\t\t\t: []),\n\t\t\t...(goal\n\t\t\t\t? [\n\t\t\t\t\t\tfield === \"automaticTurns\"\n\t\t\t\t\t\t\t? `Active goal: ${goal.automaticModelTurns} automatic responses used`\n\t\t\t\t\t\t\t: `Active goal: ${goal.toolFreeRepeatCount} repeated or empty runs detected`,\n\t\t\t\t\t]\n\t\t\t\t: []),\n\t\t],\n\t\titems: limitChoices(field, value, goal?.automaticModelTurns).map((item) => ({\n\t\t\tid: item.value,\n\t\t\tlabel: item.label,\n\t\t\tdescription: item.description,\n\t\t\taction,\n\t\t})),\n\t\thint: \"back\" as const,\n\t};\n}\n\nfunction limitChoices(\n\tfield: LimitField,\n\tvalue: number | null,\n\tautomaticTurnsUsed: number | undefined,\n): Array<{ value: LimitSelection; label: string; description: string }> {\n\tif (field === \"automaticTurns\") {\n\t\tconst unlimitedDescription =\n\t\t\tvalue === null\n\t\t\t\t? \"No response-count cap. Completion, manual pause, blockers, provider limits, and other configured guards still apply.\"\n\t\t\t\t: automaticTurnsUsed === undefined\n\t\t\t\t\t? `Remove the current ${value}-response cap. Goal work will have no response-count cap; other configured stop conditions remain.`\n\t\t\t\t\t: `Remove the current ${value}-response cap. The active goal has used ${automaticTurnsUsed} responses; other configured stop conditions remain.`;\n\t\treturn [\n\t\t\t{\n\t\t\t\tvalue: \"custom\",\n\t\t\t\tlabel: \"Set response limit\u2026\",\n\t\t\t\tdescription: `Choose a whole-number response limit for each automatic-work epoch. Default: ${DEFAULT_GOAL_SETTINGS.continuationLimits.automaticTurns}.`,\n\t\t\t},\n\t\t\t{ value: \"unlimited\", label: \"Unlimited\u2026\", description: unlimitedDescription },\n\t\t];\n\t}\n\tconst defaultLimit = DEFAULT_GOAL_SETTINGS.continuationLimits.noProgressTurns;\n\treturn [\n\t\t{\n\t\t\tvalue: \"default\",\n\t\t\tlabel: `After ${defaultLimit} repeated runs (default)`,\n\t\t\tdescription: \"Pause after the default number of repeated or empty tool-free runs.\",\n\t\t},\n\t\t{\n\t\t\tvalue: \"custom\",\n\t\t\tlabel: \"Set threshold\u2026\",\n\t\t\tdescription: \"Choose a whole number of repeated or empty runs before pausing.\",\n\t\t},\n\t\t{\n\t\t\tvalue: \"off\",\n\t\t\tlabel: \"Off\",\n\t\t\tdescription: \"Do not pause based on repeated or empty tool-free runs.\",\n\t\t},\n\t];\n}\n\nasync function applyLimitChoice(\n\truntime: GoalRuntime,\n\tctx: ExtensionCommandContext,\n\toptions: GoalSettingsUiOptions,\n\tsettingsPath: string,\n\tfield: LimitField,\n\titemId: string,\n\tactiveGoalId: string | null,\n\tisCurrent: () => boolean,\n) {\n\tif (!isCurrent() || !isLimitSelection(itemId)) return { kind: \"rejected\" as const };\n\tif ((runtime.activeGoal?.id ?? null) !== activeGoalId) {\n\t\tnotifyTerminal(\n\t\t\tctx.ui,\n\t\t\t\"The active goal changed while the safety setting was open. No settings were changed.\",\n\t\t\t\"warning\",\n\t\t);\n\t\treturn { kind: \"rejected\" as const };\n\t}\n\tconst previous = runtime.settings.continuationLimits[field];\n\tconst limit = await resolveLimitSelection(field, itemId, previous, ctx, isCurrent);\n\tif (!isCurrent()) return { kind: \"rejected\" as const };\n\tif (limit === undefined || limit === previous) return { kind: \"back\" as const };\n\tif ((runtime.activeGoal?.id ?? null) !== activeGoalId) {\n\t\tnotifyTerminal(\n\t\t\tctx.ui,\n\t\t\t\"The active goal changed while editing the safety setting. No settings were changed.\",\n\t\t\t\"warning\",\n\t\t);\n\t\treturn { kind: \"rejected\" as const };\n\t}\n\tconst confirmation = await confirmLowerActiveLimit(runtime, ctx, field, limit);\n\tif (!isCurrent() || !confirmation.apply) return { kind: \"rejected\" as const };\n\tif (confirmation.goalId !== undefined && runtime.activeGoal?.id !== confirmation.goalId) {\n\t\tnotifyTerminal(\n\t\t\tctx.ui,\n\t\t\t\"The active goal changed while confirming the limit. No settings were changed.\",\n\t\t\t\"warning\",\n\t\t);\n\t\treturn { kind: \"rejected\" as const };\n\t}\n\ttry {\n\t\tapplyGoalSettings(runtime, withLimit(runtime.settings, field, limit), ctx, {\n\t\t\tsave: (settings) => (options.save ?? saveGoalSettings)(settings, settingsPath),\n\t\t});\n\t\tnotifyTerminal(ctx.ui, formatLimitSuccess(field, limit), \"info\");\n\t\treturn { kind: \"back\" as const };\n\t} catch (error) {\n\t\tnotifySettingsFailure(ctx, settingsPath, error);\n\t\treturn { kind: \"rejected\" as const };\n\t}\n}\n\nexport function applyGoalSettings(\n\truntime: GoalRuntime,\n\tnext: GoalSettings,\n\tctx: ExtensionCommandContext,\n\toptions: GoalSettingsApplyOptions = {},\n) {\n\tconst snapshot = runtime.snapshotSettingsApplicationState();\n\tlet fileSaved = false;\n\ttry {\n\t\truntime.settings = structuredClone(next);\n\t\toptions.save?.(next);\n\t\tfileSaved = options.save !== undefined;\n\t\tconst activeGoalId = runtime.activeGoal?.id;\n\t\tconst abortOwnedRun = activeGoalId !== undefined && runtime.agentRunGoalId === activeGoalId;\n\t\tconst pausedByAutomaticLimit = runtime.enforceAutomaticTurnLimit(ctx, abortOwnedRun);\n\t\tif (!pausedByAutomaticLimit) runtime.enforceNoProgressLimit(ctx, abortOwnedRun);\n\t\tif (runtime.activeGoal) {\n\t\t\truntime.updateStatus(ctx, runtime.activeGoal);\n\t\t}\n\t} catch (error) {\n\t\tconst rollbackErrors: unknown[] = [];\n\t\ttry {\n\t\t\truntime.restoreSettingsApplicationState(snapshot);\n\t\t} catch (rollbackError) {\n\t\t\trollbackErrors.push(rollbackError);\n\t\t}\n\t\tif (fileSaved) {\n\t\t\ttry {\n\t\t\t\toptions.save?.(snapshot.settings);\n\t\t\t} catch (rollbackError) {\n\t\t\t\trollbackErrors.push(rollbackError);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\trestorePersistedRuntime(runtime, ctx);\n\t\t\t} catch (rollbackError) {\n\t\t\t\trollbackErrors.push(rollbackError);\n\t\t\t}\n\t\t}\n\t\tif (rollbackErrors.length > 0) {\n\t\t\tthrow new AggregateError(\n\t\t\t\t[error, ...rollbackErrors],\n\t\t\t\t`pi-goal settings application failed and rollback was incomplete: ${formatError(error)}`,\n\t\t\t);\n\t\t}\n\t\tthrow error;\n\t}\n}\n\nexport function parseGoalLimit(value: string): number | undefined {\n\tconst normalized = value.trim();\n\tif (!/^\\d+$/u.test(normalized)) return undefined;\n\tconst parsed = Number(normalized);\n\treturn Number.isSafeInteger(parsed) && parsed > 0 ? parsed : undefined;\n}\n\nasync function resolveLimitSelection(\n\tfield: LimitField,\n\tselection: LimitSelection,\n\tprevious: number | null,\n\tctx: ExtensionCommandContext,\n\tisCurrent: () => boolean,\n): Promise<number | null | undefined> {\n\tif (selection === \"off\") return null;\n\tif (selection === \"unlimited\") {\n\t\tif (previous === null) return null;\n\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t\"Allow Unlimited automatic work?\",\n\t\t\t\"Tool loops can continue without a response-count limit and may consume substantial tokens and provider cost. Completion, manual pause, blockers, provider limits, and the no-progress guard still apply.\",\n\t\t);\n\t\treturn isCurrent() && confirmed ? null : undefined;\n\t}\n\tif (selection === \"default\") {\n\t\treturn DEFAULT_GOAL_SETTINGS.continuationLimits[field];\n\t}\n\twhile (true) {\n\t\tconst raw =\n\t\t\tfield === \"automaticTurns\"\n\t\t\t\t? await ctx.ui.editor(\n\t\t\t\t\t\t`Automatic-work response limit (whole number greater than 0) \u00B7 Default: ${DEFAULT_GOAL_SETTINGS.continuationLimits.automaticTurns}`,\n\t\t\t\t\t\tString(previous ?? DEFAULT_GOAL_SETTINGS.continuationLimits.automaticTurns),\n\t\t\t\t\t)\n\t\t\t\t: await ctx.ui.input(\n\t\t\t\t\t\t\"Repeated-run threshold (whole number greater than 0)\",\n\t\t\t\t\t\tprevious === null ? \"Positive whole number\" : String(previous),\n\t\t\t\t\t);\n\t\tif (!isCurrent() || raw === undefined) return undefined;\n\t\tconst parsed = parseGoalLimit(raw);\n\t\tif (parsed !== undefined) return parsed;\n\t\tnotifyTerminal(\n\t\t\tctx.ui,\n\t\t\t`Enter a whole number greater than 0. Choose ${field === \"automaticTurns\" ? \"Unlimited\" : \"Off\"} from the previous screen if you do not want a limit.`,\n\t\t\t\"warning\",\n\t\t);\n\t}\n}\n\nfunction restorePersistedRuntime(runtime: GoalRuntime, ctx: ExtensionCommandContext) {\n\tif (runtime.activeGoal) {\n\t\truntime.persistGoal(runtime.activeGoal);\n\t\truntime.updateStatus(ctx, runtime.activeGoal);\n\t\truntime.restoreGoalWaitTimer(ctx);\n\t}\n}\n\nasync function confirmLowerActiveLimit(\n\truntime: GoalRuntime,\n\tctx: ExtensionCommandContext,\n\tfield: LimitField,\n\tlimit: number | null,\n) {\n\tconst goal = runtime.activeGoal;\n\tif (goal?.status !== \"active\" || limit === null) return { apply: true };\n\tconst used = field === \"automaticTurns\" ? goal.automaticModelTurns : goal.toolFreeRepeatCount;\n\tif (used < limit) return { apply: true };\n\treturn {\n\t\tapply: await ctx.ui.confirm(\n\t\t\t\"Apply limit and pause now?\",\n\t\t\t`The active goal has already used ${used}. Setting this limit to ${limit} will pause it immediately without deleting progress.`,\n\t\t),\n\t\tgoalId: goal.id,\n\t};\n}\n\nfunction withLimit(settings: GoalSettings, field: LimitField, value: number | null): GoalSettings {\n\treturn {\n\t\t...structuredClone(settings),\n\t\tcontinuationLimits: { ...settings.continuationLimits, [field]: value },\n\t};\n}\n\nfunction formatAutomaticSettingValue(value: number | null) {\n\treturn value === null ? \"Unlimited\" : `${value} responses`;\n}\n\nfunction formatNoProgressSettingValue(value: number | null) {\n\tif (value === null) return \"Off\";\n\treturn `${value} ${value === 1 ? \"run\" : \"runs\"}`;\n}\n\nfunction formatAutomaticWork(value: number | null) {\n\treturn value === null ? \"Unlimited\" : `Up to ${value} responses`;\n}\n\nfunction formatNoProgressProtection(value: number | null) {\n\tif (value === null) return \"Off\";\n\treturn `After ${value} repeated ${value === 1 ? \"run\" : \"runs\"}`;\n}\n\nfunction formatLimitSuccess(field: LimitField, value: number | null) {\n\treturn field === \"automaticTurns\"\n\t\t? `Automatic-work limit: ${formatAutomaticWork(value)}.`\n\t\t: `No-progress guard: ${formatNoProgressProtection(value)}.`;\n}\n\nfunction isLimitSelection(value: string): value is LimitSelection {\n\treturn value === \"unlimited\" || value === \"default\" || value === \"custom\" || value === \"off\";\n}\n\nfunction notifySettingsFailure(ctx: ExtensionCommandContext, settingsPath: string, error: unknown) {\n\tconst path = safeTerminalText(settingsPath);\n\tconst detail = safeTerminalText(formatError(error));\n\tnotifyTerminal(\n\t\tctx.ui,\n\t\terror instanceof AggregateError\n\t\t\t? `Could not apply Goal settings, and rollback was incomplete. Check ${path}, run /reload, and verify the effective settings before retrying: ${detail}`\n\t\t\t: `Could not save Goal settings; the previous value remains. Check ${path} and retry: ${detail}`,\n\t\t\"error\",\n\t);\n}\n\nfunction formatError(error: unknown) {\n\treturn error instanceof Error ? error.message : String(error);\n}\n"],
5
- "mappings": ";;;;;;;;;;;AAAA,SAAS,YAAY;AACrB,SAAuC,mBAAmB;AAsB1D,eAAsB,iBACrB,SACA,KACA,UAAiC,CAAC,GACjC;AACD,QAAM,eAAe,QAAQ,gBAAgB,KAAK,YAAY,GAAG,kBAAkB;AACnF,MAAI,IAAI,SAAS,OAAO;AACvB;AAAA,MACC,IAAI;AAAA,MACJ,mCAAmC,iBAAiB,YAAY,CAAC;AAAA,MACjE;AAAA,IACD;AACA;AAAA,EACD;AACA,QAAM,aAAa,QAAQ;AAC3B,QAAM,gBAAgB,MACrB,eAAe,QAAQ,kBAAkB,CAAC,QAAQ,eAAe,OAAO;AACzE,QAAM,EAAE,YAAY,QAAQ,IAAI,MAAM,OAAO,sBAAsB;AACnE,MAAI,CAAC,cAAc,EAAG;AACtB,QAAM,UAAU,QAAQ,mBAAmB,SAAS;AACpD,QAAM,iBAAiB,oBAAI,IAA+B;AAQ1D,QAAM,OAAO,WAA+D;AAAA,IAC3E,OAAO,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