@narumitw/pi-goal 0.53.3 → 0.54.1

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.
@@ -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\nclass WorkflowBusyError extends Error {}\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-visibility\"\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: \"toolVisibility\",\n\t\t\t\t\t\tlabel: \"Goal tools\",\n\t\t\t\t\t\tdescription: \"Keep terminal Goal tools visible, or reveal them after the first goal.\",\n\t\t\t\t\t\tcurrentValue: visibilityLabel(runtime.settings.toolVisibility),\n\t\t\t\t\t\tvalues: [\"Always\", \"After first goal\"],\n\t\t\t\t\t\taction: \"set-visibility\",\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`Goal tools: ${visibilityLabel(runtime.settings.toolVisibility)}`,\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-visibility\": async ({ value }) => {\n\t\t\t\tconst nextVisibility = value === \"Always\" ? \"always\" : \"after-first-goal\";\n\t\t\t\tif (nextVisibility === runtime.settings.toolVisibility) 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\ttoolVisibility: nextVisibility,\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, `Goal tools: ${value}.`, \"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\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\tconst visibilityChanges = snapshot.settings.toolVisibility !== next.toolVisibility;\n\tconst releaseWorkflow = visibilityChanges\n\t\t? runtime.beginTemporaryWorkflowAccess(ctx.sessionManager)\n\t\t: () => undefined;\n\tif (!releaseWorkflow) {\n\t\tthrow new WorkflowBusyError(\n\t\t\t\"Another workflow is active in this session. Goal tool visibility was not changed.\",\n\t\t);\n\t}\n\n\tlet fileSaved = false;\n\ttry {\n\t\ttry {\n\t\t\tapplyToolVisibility(runtime, snapshot.settings, next, ctx);\n\t\t\truntime.settings = structuredClone(next);\n\t\t\toptions.save?.(next);\n\t\t\tfileSaved = options.save !== undefined;\n\t\t\tconst activeGoalId = runtime.activeGoal?.id;\n\t\t\tconst abortOwnedRun = activeGoalId !== undefined && runtime.agentRunGoalId === activeGoalId;\n\t\t\tconst pausedByAutomaticLimit = runtime.enforceAutomaticTurnLimit(ctx, abortOwnedRun);\n\t\t\tif (!pausedByAutomaticLimit) runtime.enforceNoProgressLimit(ctx, abortOwnedRun);\n\t\t\tif (runtime.activeGoal) {\n\t\t\t\truntime.updateStatus(ctx, runtime.activeGoal);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconst rollbackErrors: unknown[] = [];\n\t\t\ttry {\n\t\t\t\truntime.restoreSettingsApplicationState(snapshot);\n\t\t\t} catch (rollbackError) {\n\t\t\t\trollbackErrors.push(rollbackError);\n\t\t\t}\n\t\t\tif (fileSaved) {\n\t\t\t\ttry {\n\t\t\t\t\toptions.save?.(snapshot.settings);\n\t\t\t\t} catch (rollbackError) {\n\t\t\t\t\trollbackErrors.push(rollbackError);\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\trestorePersistedRuntime(runtime, ctx);\n\t\t\t\t} catch (rollbackError) {\n\t\t\t\t\trollbackErrors.push(rollbackError);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (rollbackErrors.length > 0) {\n\t\t\t\tthrow new AggregateError(\n\t\t\t\t\t[error, ...rollbackErrors],\n\t\t\t\t\t`pi-goal settings application failed and rollback was incomplete: ${formatError(error)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t} finally {\n\t\treleaseWorkflow();\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 applyToolVisibility(\n\truntime: GoalRuntime,\n\tprevious: GoalSettings,\n\tnext: GoalSettings,\n\tctx: ExtensionCommandContext,\n) {\n\tif (previous.toolVisibility === next.toolVisibility) return;\n\truntime.toolPolicy.applyVisibilityChange(\n\t\tprevious.toolVisibility,\n\t\tnext.toolVisibility,\n\t\truntime.activeGoal !== undefined,\n\t\tctx,\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 visibilityLabel(value: GoalSettings[\"toolVisibility\"]) {\n\treturn value === \"always\" ? \"Always\" : \"After first goal\";\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,SA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