@caupulican/pi-adaptative 0.80.82 → 0.80.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +5 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +1 -0
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.d.ts +3 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +6 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +143 -24
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +41 -6
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/docs/settings.md +4 -2
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings-selector.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/settings-selector.ts"],"names":[],"mappings":"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","sourcesContent":["import type { ThinkingLevel } from \"@caupulican/pi-agent-core\";\nimport type { Transport } from \"@caupulican/pi-ai\";\nimport {\n\tContainer,\n\tgetCapabilities,\n\tgetKeybindings,\n\tInput,\n\ttype SelectItem,\n\tSelectList,\n\ttype SelectListLayoutOptions,\n\ttype SettingItem,\n\tSettingsList,\n\tSpacer,\n\tText,\n} from \"@caupulican/pi-tui\";\nimport { formatHttpIdleTimeoutMs, HTTP_IDLE_TIMEOUT_CHOICES } from \"../../../core/http-dispatcher.ts\";\nimport type {\n\tAutoLearnSettings,\n\tAutonomyMode,\n\tAutonomySettings,\n\tModelRouterSettings,\n\tSelfModificationSettings,\n\tSettingsScope,\n\tWarningSettings,\n} from \"../../../core/settings-manager.ts\";\nimport { getSelectListTheme, getSettingsListTheme, theme } from \"../theme/theme.ts\";\nimport { DynamicBorder } from \"./dynamic-border.ts\";\nimport { keyDisplayText } from \"./keybinding-hints.ts\";\n\nconst SETTINGS_SUBMENU_SELECT_LIST_LAYOUT: SelectListLayoutOptions = {\n\tminPrimaryColumnWidth: 12,\n\tmaxPrimaryColumnWidth: 32,\n};\n\nconst AUTO_LEARN_CUSTOM_MODEL_VALUE = \"__custom_auto_learn_model__\";\n\nconst THINKING_DESCRIPTIONS: Record<ThinkingLevel, string> = {\n\toff: \"No reasoning\",\n\tminimal: \"Very brief reasoning (~1k tokens)\",\n\tlow: \"Light reasoning (~2k tokens)\",\n\tmedium: \"Moderate reasoning (~8k tokens)\",\n\thigh: \"Deep reasoning (~16k tokens)\",\n\txhigh: \"Maximum reasoning (~32k tokens)\",\n};\n\nconst AUTONOMY_MODES: AutonomyMode[] = [\"off\", \"safe\", \"balanced\", \"full\"];\n\nconst AUTO_LEARN_DEFAULTS = {\n\tmodel: \"active\",\n\tlongSessionMessages: 32,\n\tlongSessionContextPercent: 70,\n\tcooldownMinutes: 120,\n\tleaseMinutes: 90,\n\tmaxConcurrentLearners: 2,\n\tapplyHighConfidence: false,\n\treflectionReview: true,\n\treflectionMinToolCalls: 5,\n\treflectionCooldownMinutes: 60,\n} as const;\n\nfunction booleanSettingValue(value: boolean | undefined, defaultValue = false): string {\n\treturn (value ?? defaultValue) ? \"true\" : \"false\";\n}\n\nfunction optionalStringValue(value: string | undefined, fallback = \"(not set)\"): string {\n\tconst trimmed = value?.trim();\n\treturn trimmed && trimmed.length > 0 ? trimmed : fallback;\n}\n\nfunction normalizeOptionalString(value: string): string | undefined {\n\tconst trimmed = value.trim();\n\treturn trimmed.length > 0 ? trimmed : undefined;\n}\n\nfunction numberSettingValue(value: number | undefined, defaultValue: number): string {\n\treturn String(value ?? defaultValue);\n}\n\nfunction autoLearnModelValue(settings: AutoLearnSettings): string {\n\treturn optionalStringValue(settings.model, AUTO_LEARN_DEFAULTS.model);\n}\n\nfunction selfModificationSummary(settings: SelfModificationSettings): string {\n\tif (!(settings.enabled ?? false)) return \"disabled\";\n\tconst hasPath =\n\t\tBoolean(settings.sourcePath?.trim()) ||\n\t\t(Array.isArray(settings.sourcePaths) && settings.sourcePaths.some((candidate) => Boolean(candidate?.trim())));\n\treturn hasPath ? \"enabled\" : \"enabled (missing path)\";\n}\n\nfunction autonomyModeValue(settings: AutonomySettings): AutonomyMode {\n\treturn settings.mode && AUTONOMY_MODES.includes(settings.mode) ? settings.mode : \"off\";\n}\n\nfunction autonomySummary(settings: AutonomySettings): string {\n\tconst mode = autonomyModeValue(settings);\n\treturn mode === \"full\" ? \"standing autonomy\" : mode;\n}\n\nfunction autoLearnSummary(settings: AutoLearnSettings): string {\n\treturn settings.enabled ? `enabled (${autoLearnModelValue(settings)})` : \"disabled\";\n}\n\nfunction modelRouterSummary(settings: ModelRouterSettings): string {\n\tconst state = settings.enabled ? \"enabled\" : \"disabled\";\n\treturn `${state} · cheap: ${optionalStringValue(settings.cheapModel)} · expensive: ${optionalStringValue(settings.expensiveModel)} · learn: ${optionalStringValue(settings.learningModel, \"active\")}`;\n}\n\nfunction buildAutoLearnModelOptions(\n\tsettings: AutoLearnSettings,\n\tconfiguredModelOptions: SelectItem[] | undefined,\n\tcurrentModelPattern: string | undefined,\n): SelectItem[] {\n\tconst currentValue = autoLearnModelValue(settings);\n\tconst options: SelectItem[] = [\n\t\t{\n\t\t\tvalue: AUTO_LEARN_DEFAULTS.model,\n\t\t\tlabel: \"active\",\n\t\t\tdescription: currentModelPattern\n\t\t\t\t? `Use the current session model (${currentModelPattern})`\n\t\t\t\t: \"Use the current session model\",\n\t\t},\n\t];\n\tconst seen = new Set(options.map((option) => option.value));\n\n\tfor (const option of configuredModelOptions ?? []) {\n\t\tif (seen.has(option.value)) continue;\n\t\toptions.push(option);\n\t\tseen.add(option.value);\n\t}\n\n\tif (currentValue !== AUTO_LEARN_DEFAULTS.model && !seen.has(currentValue)) {\n\t\toptions.push({\n\t\t\tvalue: currentValue,\n\t\t\tlabel: currentValue,\n\t\t\tdescription: \"Current custom setting\",\n\t\t});\n\t\tseen.add(currentValue);\n\t}\n\n\toptions.push({\n\t\tvalue: AUTO_LEARN_CUSTOM_MODEL_VALUE,\n\t\tlabel: \"Manual / custom…\",\n\t\tdescription: \"Type a model pattern not listed above\",\n\t});\n\n\treturn options;\n}\n\nexport interface SettingsConfig {\n\tautoCompact: boolean;\n\tshowImages: boolean;\n\timageWidthCells: number;\n\tautoResizeImages: boolean;\n\tblockImages: boolean;\n\tenableSkillCommands: boolean;\n\tsteeringMode: \"all\" | \"one-at-a-time\";\n\tfollowUpMode: \"all\" | \"one-at-a-time\";\n\ttransport: Transport;\n\thttpIdleTimeoutMs: number;\n\tthinkingLevel: ThinkingLevel;\n\tavailableThinkingLevels: ThinkingLevel[];\n\tcurrentTheme: string;\n\tavailableThemes: string[];\n\thideThinkingBlock: boolean;\n\tcollapseChangelog: boolean;\n\tenableInstallTelemetry: boolean;\n\tdoubleEscapeAction: \"fork\" | \"tree\" | \"none\";\n\ttreeFilterMode: \"default\" | \"no-tools\" | \"user-only\" | \"labeled-only\" | \"all\";\n\tshowHardwareCursor: boolean;\n\teditorPaddingX: number;\n\tautocompleteMaxVisible: number;\n\tquietStartup: boolean;\n\tclearOnShrink: boolean;\n\tshowTerminalProgress: boolean;\n\twarnings: WarningSettings;\n\tselfModification: {\n\t\tenabled: boolean;\n\t\tsourcePath?: string;\n\t\tsourcePaths?: string[];\n\t};\n\tselfModificationScope?: SettingsScope;\n\tautonomy: AutonomySettings;\n\tautonomyScope?: SettingsScope;\n\tmodelRouter: ModelRouterSettings;\n\tmodelRouterScope?: SettingsScope;\n\tautoLearn: AutoLearnSettings;\n\tautoLearnScope?: SettingsScope;\n\tcurrentModelPattern?: string;\n\tautoLearnModelOptions?: SelectItem[];\n\tactiveProfileName?: string;\n\tprofileOptions?: SelectItem[];\n\texternalResourceRoots?: string[];\n\ttrustedResourceRoots?: string[];\n}\n\nexport interface SettingsCallbacks {\n\tonAutoCompactChange: (enabled: boolean) => void;\n\tonShowImagesChange: (enabled: boolean) => void;\n\tonImageWidthCellsChange: (width: number) => void;\n\tonAutoResizeImagesChange: (enabled: boolean) => void;\n\tonBlockImagesChange: (blocked: boolean) => void;\n\tonEnableSkillCommandsChange: (enabled: boolean) => void;\n\tonSteeringModeChange: (mode: \"all\" | \"one-at-a-time\") => void;\n\tonFollowUpModeChange: (mode: \"all\" | \"one-at-a-time\") => void;\n\tonTransportChange: (transport: Transport) => void;\n\tonHttpIdleTimeoutMsChange: (timeoutMs: number) => void;\n\tonThinkingLevelChange: (level: ThinkingLevel) => void;\n\tonThemeChange: (theme: string) => void;\n\tonThemePreview?: (theme: string) => void;\n\tonHideThinkingBlockChange: (hidden: boolean) => void;\n\tonCollapseChangelogChange: (collapsed: boolean) => void;\n\tonEnableInstallTelemetryChange: (enabled: boolean) => void;\n\tonDoubleEscapeActionChange: (action: \"fork\" | \"tree\" | \"none\") => void;\n\tonTreeFilterModeChange: (mode: \"default\" | \"no-tools\" | \"user-only\" | \"labeled-only\" | \"all\") => void;\n\tonShowHardwareCursorChange: (enabled: boolean) => void;\n\tonEditorPaddingXChange: (padding: number) => void;\n\tonAutocompleteMaxVisibleChange: (maxVisible: number) => void;\n\tonQuietStartupChange: (enabled: boolean) => void;\n\tonClearOnShrinkChange: (enabled: boolean) => void;\n\tonShowTerminalProgressChange: (enabled: boolean) => void;\n\tonWarningsChange: (warnings: WarningSettings) => void;\n\tonSelfModificationChange: (settings: SelfModificationSettings, scope: SettingsScope) => void;\n\tonAutonomyChange: (settings: AutonomySettings, scope: SettingsScope) => void;\n\tonModelRouterChange: (settings: ModelRouterSettings, scope: SettingsScope) => void;\n\tonAutoLearnChange: (settings: AutoLearnSettings, scope: SettingsScope) => void;\n\tonResourcesHubAction?: (action: string) => void;\n\tonCancel: () => void;\n}\n\nclass TextInputSubmenu extends Container {\n\tprivate input: Input;\n\n\tconstructor(\n\t\ttitle: string,\n\t\tdescription: string,\n\t\tcurrentValue: string,\n\t\tonSubmit: (value: string) => void,\n\t\tonCancel: () => void,\n\t\temptyHint = \"empty clears the setting\",\n\t) {\n\t\tsuper();\n\n\t\tthis.addChild(new Text(theme.bold(theme.fg(\"accent\", title)), 0, 0));\n\t\tif (description) {\n\t\t\tthis.addChild(new Spacer(1));\n\t\t\tthis.addChild(new Text(theme.fg(\"muted\", description), 0, 0));\n\t\t}\n\t\tthis.addChild(new Spacer(1));\n\n\t\tthis.input = new Input();\n\t\tthis.input.setValue(currentValue);\n\t\tthis.input.focused = true;\n\t\tthis.input.onSubmit = onSubmit;\n\t\tthis.input.onEscape = onCancel;\n\t\tthis.addChild(this.input);\n\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new Text(theme.fg(\"dim\", ` Enter to save · Esc to go back · ${emptyHint}`), 0, 0));\n\t}\n\n\thandleInput(data: string): void {\n\t\tthis.input.handleInput(data);\n\t}\n}\n\nclass AutoLearnModelSelectionSubmenu extends Container {\n\tprivate searchInput: Input;\n\tprivate selectList: SelectList;\n\tprivate customInput: TextInputSubmenu | null = null;\n\n\tconstructor(options: SelectItem[], currentValue: string, onSelect: (value: string) => void, onCancel: () => void) {\n\t\tsuper();\n\n\t\tthis.addChild(new Text(theme.bold(theme.fg(\"accent\", \"Auto Learn Scavenger Model\")), 0, 0));\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(\n\t\t\tnew Text(\n\t\t\t\ttheme.fg(\n\t\t\t\t\t\"muted\",\n\t\t\t\t\t\"Choose active or a model from currently configured subscription/API accounts. Type to filter; choose manual for a custom pattern.\",\n\t\t\t\t),\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t\tthis.addChild(new Spacer(1));\n\n\t\tthis.searchInput = new Input();\n\t\tthis.searchInput.focused = true;\n\t\tthis.addChild(this.searchInput);\n\t\tthis.addChild(new Spacer(1));\n\n\t\tthis.selectList = new SelectList(\n\t\t\toptions,\n\t\t\tMath.min(options.length, 10),\n\t\t\tgetSelectListTheme(),\n\t\t\tSETTINGS_SUBMENU_SELECT_LIST_LAYOUT,\n\t\t);\n\n\t\tconst currentIndex = options.findIndex((option) => option.value === currentValue);\n\t\tif (currentIndex !== -1) {\n\t\t\tthis.selectList.setSelectedIndex(currentIndex);\n\t\t}\n\n\t\tthis.selectList.onSelect = (item) => {\n\t\t\tif (item.value === AUTO_LEARN_CUSTOM_MODEL_VALUE) {\n\t\t\t\tthis.customInput = new TextInputSubmenu(\n\t\t\t\t\t\"Custom Auto Learn Model\",\n\t\t\t\t\t'Enter \"active\" or a provider/model pattern like \"openai/gpt-5.4\".',\n\t\t\t\t\tcurrentValue === AUTO_LEARN_DEFAULTS.model ? \"\" : currentValue,\n\t\t\t\t\t(value) => {\n\t\t\t\t\t\tonSelect(normalizeOptionalString(value) ?? AUTO_LEARN_DEFAULTS.model);\n\t\t\t\t\t},\n\t\t\t\t\t() => {\n\t\t\t\t\t\tthis.customInput = null;\n\t\t\t\t\t},\n\t\t\t\t\t'empty uses \"active\"',\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tonSelect(item.value);\n\t\t};\n\t\tthis.selectList.onCancel = onCancel;\n\t\tthis.addChild(this.selectList);\n\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new Text(theme.fg(\"dim\", \" Type to filter · Enter to select · Esc to go back\"), 0, 0));\n\t}\n\n\thandleInput(data: string): void {\n\t\tif (this.customInput) {\n\t\t\tthis.customInput.handleInput(data);\n\t\t\treturn;\n\t\t}\n\n\t\tconst kb = getKeybindings();\n\t\tif (kb.matches(data, \"tui.select.up\") || kb.matches(data, \"tui.select.down\")) {\n\t\t\tthis.selectList.handleInput(data);\n\t\t\treturn;\n\t\t}\n\t\tif (kb.matches(data, \"tui.select.confirm\") || kb.matches(data, \"tui.select.cancel\")) {\n\t\t\tthis.selectList.handleInput(data);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.searchInput.handleInput(data);\n\t\tthis.selectList.setFilter(this.searchInput.getValue());\n\t}\n\n\trender(width: number): string[] {\n\t\treturn this.customInput ? this.customInput.render(width) : super.render(width);\n\t}\n\n\tinvalidate(): void {\n\t\tsuper.invalidate();\n\t\tthis.customInput?.invalidate?.();\n\t}\n}\n\nclass SelfModificationSettingsSubmenu extends Container {\n\tprivate settingsList: SettingsList;\n\tprivate state: SelfModificationSettings;\n\tprivate scope: SettingsScope;\n\n\tconstructor(\n\t\tsettings: SelfModificationSettings,\n\t\tonChange: (settings: SelfModificationSettings, scope: SettingsScope) => void,\n\t\tonCancel: () => void,\n\t\tscope: SettingsScope = \"global\",\n\t) {\n\t\tsuper();\n\n\t\tthis.state = { ...settings, enabled: settings.enabled ?? false };\n\t\tthis.scope = scope;\n\n\t\tconst items: SettingItem[] = [\n\t\t\t{\n\t\t\t\tid: \"self-modification-scope\",\n\t\t\t\tlabel: \"Save scope\",\n\t\t\t\tdescription:\n\t\t\t\t\t\"Save this self-modification configuration globally or in the current project's .pi/settings.json\",\n\t\t\t\tcurrentValue: this.scope,\n\t\t\t\tvalues: [\"global\", \"project\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"self-modification-enabled\",\n\t\t\t\tlabel: \"Enabled\",\n\t\t\t\tdescription: \"Allow agents to modify Pi's own source/harness only when explicitly tasked\",\n\t\t\t\tcurrentValue: booleanSettingValue(this.state.enabled),\n\t\t\t\tvalues: [\"true\", \"false\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"self-modification-source-path\",\n\t\t\t\tlabel: \"Source path\",\n\t\t\t\tdescription: \"Path to the pi-adaptative source checkout agents may edit for self-evolution\",\n\t\t\t\tcurrentValue: optionalStringValue(this.state.sourcePath),\n\t\t\t\tsubmenu: (_currentValue, done) =>\n\t\t\t\t\tnew TextInputSubmenu(\n\t\t\t\t\t\t\"Pi-adaptative Source Path\",\n\t\t\t\t\t\t\"Set the source checkout path used by self-evolution guardrails. Empty clears it.\",\n\t\t\t\t\t\tthis.state.sourcePath ?? \"\",\n\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\tconst sourcePath = normalizeOptionalString(value);\n\t\t\t\t\t\t\tthis.state = { ...this.state, sourcePath };\n\t\t\t\t\t\t\tonChange({ ...this.state }, this.scope);\n\t\t\t\t\t\t\tdone(optionalStringValue(sourcePath));\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(),\n\t\t\t\t\t),\n\t\t\t},\n\t\t];\n\n\t\tthis.settingsList = new SettingsList(\n\t\t\titems,\n\t\t\tMath.min(items.length, 10),\n\t\t\tgetSettingsListTheme(),\n\t\t\t(id, newValue) => {\n\t\t\t\tswitch (id) {\n\t\t\t\t\tcase \"self-modification-scope\":\n\t\t\t\t\t\tthis.scope = newValue as SettingsScope;\n\t\t\t\t\t\tonChange({ ...this.state }, this.scope);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"self-modification-enabled\":\n\t\t\t\t\t\tthis.state = { ...this.state, enabled: newValue === \"true\" };\n\t\t\t\t\t\tonChange({ ...this.state }, this.scope);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t},\n\t\t\tonCancel,\n\t\t);\n\n\t\tthis.addChild(this.settingsList);\n\t}\n\n\thandleInput(data: string): void {\n\t\tthis.settingsList.handleInput(data);\n\t}\n}\n\nclass AutonomySettingsSubmenu extends Container {\n\tprivate settingsList: SettingsList;\n\tprivate state: AutonomySettings;\n\tprivate scope: SettingsScope;\n\n\tconstructor(\n\t\tsettings: AutonomySettings,\n\t\tonChange: (settings: AutonomySettings, scope: SettingsScope) => void,\n\t\tonCancel: () => void,\n\t\tscope: SettingsScope = \"global\",\n\t) {\n\t\tsuper();\n\t\tthis.state = { mode: autonomyModeValue(settings) };\n\t\tthis.scope = scope;\n\n\t\tconst items: SettingItem[] = [\n\t\t\t{\n\t\t\t\tid: \"autonomy-scope\",\n\t\t\t\tlabel: \"Save scope\",\n\t\t\t\tdescription: \"Save this autonomy preset globally or in the current project's .pi/settings.json\",\n\t\t\t\tcurrentValue: this.scope,\n\t\t\t\tvalues: [\"global\", \"project\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"autonomy-mode\",\n\t\t\t\tlabel: \"Mode\",\n\t\t\t\tdescription: \"One preset for background learning: off, safe, balanced, or standing autonomy\",\n\t\t\t\tcurrentValue: autonomyModeValue(this.state),\n\t\t\t\tvalues: AUTONOMY_MODES,\n\t\t\t},\n\t\t];\n\n\t\tthis.settingsList = new SettingsList(\n\t\t\titems,\n\t\t\tMath.min(items.length, 10),\n\t\t\tgetSettingsListTheme(),\n\t\t\t(id, newValue) => {\n\t\t\t\tswitch (id) {\n\t\t\t\t\tcase \"autonomy-scope\":\n\t\t\t\t\t\tthis.scope = newValue as SettingsScope;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"autonomy-mode\":\n\t\t\t\t\t\tthis.state = { ...this.state, mode: newValue as AutonomyMode };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tonChange({ ...this.state }, this.scope);\n\t\t\t},\n\t\t\tonCancel,\n\t\t);\n\n\t\tthis.addChild(this.settingsList);\n\t}\n\n\thandleInput(data: string): void {\n\t\tthis.settingsList.handleInput(data);\n\t}\n}\n\nclass AutoLearnSettingsSubmenu extends Container {\n\tprivate settingsList: SettingsList;\n\tprivate state: AutoLearnSettings;\n\tprivate scope: SettingsScope;\n\n\tconstructor(\n\t\tsettings: AutoLearnSettings,\n\t\tcurrentModelPattern: string | undefined,\n\t\tmodelOptions: SelectItem[] | undefined,\n\t\tonChange: (settings: AutoLearnSettings, scope: SettingsScope) => void,\n\t\tonCancel: () => void,\n\t\tscope: SettingsScope = \"global\",\n\t) {\n\t\tsuper();\n\n\t\tthis.state = { ...settings };\n\t\tthis.scope = scope;\n\t\tconst modelDescription = currentModelPattern\n\t\t\t? `Model for background learning. \"active\" uses ${currentModelPattern}; configured subscription/API models are listed first.`\n\t\t\t: 'Model for background learning. Use \"active\" for the current session model, or choose a configured subscription/API model.';\n\t\tconst selectableModelOptions = buildAutoLearnModelOptions(this.state, modelOptions, currentModelPattern);\n\n\t\tconst items: SettingItem[] = [\n\t\t\t{\n\t\t\t\tid: \"auto-learn-scope\",\n\t\t\t\tlabel: \"Save scope\",\n\t\t\t\tdescription: \"Save this Auto Learn configuration globally or in the current project's .pi/settings.json\",\n\t\t\t\tcurrentValue: this.scope,\n\t\t\t\tvalues: [\"global\", \"project\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-enabled\",\n\t\t\t\tlabel: \"Enabled\",\n\t\t\t\tdescription: \"Autonomously trigger background history scavenging for long sessions\",\n\t\t\t\tcurrentValue: booleanSettingValue(this.state.enabled),\n\t\t\t\tvalues: [\"true\", \"false\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-model\",\n\t\t\t\tlabel: \"Scavenger model\",\n\t\t\t\tdescription: modelDescription,\n\t\t\t\tcurrentValue: autoLearnModelValue(this.state),\n\t\t\t\tsubmenu: (_currentValue, done) =>\n\t\t\t\t\tnew AutoLearnModelSelectionSubmenu(\n\t\t\t\t\t\tselectableModelOptions,\n\t\t\t\t\t\tautoLearnModelValue(this.state),\n\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\tthis.state = { ...this.state, model: value };\n\t\t\t\t\t\t\tonChange({ ...this.state }, this.scope);\n\t\t\t\t\t\t\tdone(autoLearnModelValue(this.state));\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(),\n\t\t\t\t\t),\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-long-session-messages\",\n\t\t\t\tlabel: \"Message trigger\",\n\t\t\t\tdescription: \"Trigger after this many message entries in the active branch\",\n\t\t\t\tcurrentValue: numberSettingValue(this.state.longSessionMessages, AUTO_LEARN_DEFAULTS.longSessionMessages),\n\t\t\t\tvalues: [\"16\", \"32\", \"64\", \"128\", \"256\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-context-percent\",\n\t\t\t\tlabel: \"Context trigger %\",\n\t\t\t\tdescription: \"Trigger when current context usage reaches this percentage\",\n\t\t\t\tcurrentValue: numberSettingValue(\n\t\t\t\t\tthis.state.longSessionContextPercent,\n\t\t\t\t\tAUTO_LEARN_DEFAULTS.longSessionContextPercent,\n\t\t\t\t),\n\t\t\t\tvalues: [\"50\", \"60\", \"70\", \"80\", \"90\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-cooldown-minutes\",\n\t\t\t\tlabel: \"Cooldown minutes\",\n\t\t\t\tdescription: \"Per-session-tenant cooldown between learner launches\",\n\t\t\t\tcurrentValue: numberSettingValue(this.state.cooldownMinutes, AUTO_LEARN_DEFAULTS.cooldownMinutes),\n\t\t\t\tvalues: [\"15\", \"30\", \"60\", \"120\", \"240\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-lease-minutes\",\n\t\t\t\tlabel: \"Lease minutes\",\n\t\t\t\tdescription: \"Shared-state lease duration for a running background learner\",\n\t\t\t\tcurrentValue: numberSettingValue(this.state.leaseMinutes, AUTO_LEARN_DEFAULTS.leaseMinutes),\n\t\t\t\tvalues: [\"30\", \"60\", \"90\", \"180\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-max-concurrent\",\n\t\t\t\tlabel: \"Max learners\",\n\t\t\t\tdescription: \"Maximum running Auto Learn background learners per session tenant\",\n\t\t\t\tcurrentValue: numberSettingValue(\n\t\t\t\t\tthis.state.maxConcurrentLearners,\n\t\t\t\t\tAUTO_LEARN_DEFAULTS.maxConcurrentLearners,\n\t\t\t\t),\n\t\t\t\tvalues: [\"1\", \"2\", \"3\", \"4\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-apply-high-confidence\",\n\t\t\t\tlabel: \"Apply high confidence\",\n\t\t\t\tdescription:\n\t\t\t\t\t\"Allow high-confidence memory candidates to be applied automatically; broader write authority follows autonomy.mode\",\n\t\t\t\tcurrentValue: booleanSettingValue(this.state.applyHighConfidence, AUTO_LEARN_DEFAULTS.applyHighConfidence),\n\t\t\t\tvalues: [\"false\", \"true\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-reflection-review\",\n\t\t\t\tlabel: \"Reflection review\",\n\t\t\t\tdescription: \"After corrective or complex turns, launch a bounded background learning review\",\n\t\t\t\tcurrentValue: booleanSettingValue(this.state.reflectionReview, AUTO_LEARN_DEFAULTS.reflectionReview),\n\t\t\t\tvalues: [\"true\", \"false\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-reflection-tool-calls\",\n\t\t\t\tlabel: \"Reflection tool trigger\",\n\t\t\t\tdescription: \"Trigger reflection review after this many tool calls in one completed turn\",\n\t\t\t\tcurrentValue: numberSettingValue(\n\t\t\t\t\tthis.state.reflectionMinToolCalls,\n\t\t\t\t\tAUTO_LEARN_DEFAULTS.reflectionMinToolCalls,\n\t\t\t\t),\n\t\t\t\tvalues: [\"3\", \"5\", \"8\", \"12\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-reflection-cooldown\",\n\t\t\t\tlabel: \"Reflection cooldown\",\n\t\t\t\tdescription: \"Per-session-tenant cooldown between reflection-review launches\",\n\t\t\t\tcurrentValue: numberSettingValue(\n\t\t\t\t\tthis.state.reflectionCooldownMinutes,\n\t\t\t\t\tAUTO_LEARN_DEFAULTS.reflectionCooldownMinutes,\n\t\t\t\t),\n\t\t\t\tvalues: [\"15\", \"30\", \"60\", \"120\"],\n\t\t\t},\n\t\t];\n\n\t\tthis.settingsList = new SettingsList(\n\t\t\titems,\n\t\t\tMath.min(items.length, 10),\n\t\t\tgetSettingsListTheme(),\n\t\t\t(id, newValue) => {\n\t\t\t\tswitch (id) {\n\t\t\t\t\tcase \"auto-learn-scope\":\n\t\t\t\t\t\tthis.scope = newValue as SettingsScope;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-learn-enabled\":\n\t\t\t\t\t\tthis.state = { ...this.state, enabled: newValue === \"true\" };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-learn-long-session-messages\":\n\t\t\t\t\t\tthis.state = { ...this.state, longSessionMessages: parseInt(newValue, 10) };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-learn-context-percent\":\n\t\t\t\t\t\tthis.state = { ...this.state, longSessionContextPercent: parseInt(newValue, 10) };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-learn-cooldown-minutes\":\n\t\t\t\t\t\tthis.state = { ...this.state, cooldownMinutes: parseInt(newValue, 10) };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-learn-lease-minutes\":\n\t\t\t\t\t\tthis.state = { ...this.state, leaseMinutes: parseInt(newValue, 10) };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-learn-max-concurrent\":\n\t\t\t\t\t\tthis.state = { ...this.state, maxConcurrentLearners: parseInt(newValue, 10) };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-learn-apply-high-confidence\":\n\t\t\t\t\t\tthis.state = { ...this.state, applyHighConfidence: newValue === \"true\" };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-learn-reflection-review\":\n\t\t\t\t\t\tthis.state = { ...this.state, reflectionReview: newValue === \"true\" };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-learn-reflection-tool-calls\":\n\t\t\t\t\t\tthis.state = { ...this.state, reflectionMinToolCalls: parseInt(newValue, 10) };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-learn-reflection-cooldown\":\n\t\t\t\t\t\tthis.state = { ...this.state, reflectionCooldownMinutes: parseInt(newValue, 10) };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tonChange({ ...this.state }, this.scope);\n\t\t\t},\n\t\t\tonCancel,\n\t\t);\n\n\t\tthis.addChild(this.settingsList);\n\t}\n\n\thandleInput(data: string): void {\n\t\tthis.settingsList.handleInput(data);\n\t}\n}\n\nclass ModelRouterSettingsSubmenu extends Container {\n\tprivate settingsList: SettingsList;\n\tprivate state: ModelRouterSettings;\n\tprivate scope: SettingsScope;\n\n\tconstructor(\n\t\tsettings: ModelRouterSettings,\n\t\tonChange: (settings: ModelRouterSettings, scope: SettingsScope) => void,\n\t\tonCancel: () => void,\n\t\tscope: SettingsScope = \"global\",\n\t) {\n\t\tsuper();\n\t\tthis.state = {\n\t\t\t...settings,\n\t\t\tenabled: settings.enabled ?? false,\n\t\t\tlearningModel: settings.learningModel ?? \"active\",\n\t\t};\n\t\tthis.scope = scope;\n\t\tthis.addChild(new Text(theme.bold(theme.fg(\"accent\", \"Model Router\")), 0, 0));\n\t\tthis.addChild(new Spacer(1));\n\n\t\tconst items: SettingItem[] = [\n\t\t\t{\n\t\t\t\tid: \"model-router-scope\",\n\t\t\t\tlabel: \"Save scope\",\n\t\t\t\tdescription: \"Save this routing configuration globally or in the current project's .pi/settings.json\",\n\t\t\t\tcurrentValue: this.scope,\n\t\t\t\tvalues: [\"global\", \"project\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"model-router-enabled\",\n\t\t\t\tlabel: \"Enabled\",\n\t\t\t\tdescription: \"Route read-only/research turns to cheap model and modify/tool-heavy turns to expensive model\",\n\t\t\t\tcurrentValue: booleanSettingValue(this.state.enabled),\n\t\t\t\tvalues: [\"false\", \"true\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"model-router-cheap\",\n\t\t\t\tlabel: \"Cheap model\",\n\t\t\t\tdescription: \"Model pattern for read-only, research, explanation, and question turns\",\n\t\t\t\tcurrentValue: optionalStringValue(this.state.cheapModel),\n\t\t\t\tsubmenu: (_currentValue, done) =>\n\t\t\t\t\tnew TextInputSubmenu(\n\t\t\t\t\t\t\"Cheap / Research Model\",\n\t\t\t\t\t\t\"Enter a provider/model pattern from pi --list-models. Empty clears it.\",\n\t\t\t\t\t\tthis.state.cheapModel ?? \"\",\n\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\tthis.state = { ...this.state, cheapModel: normalizeOptionalString(value) };\n\t\t\t\t\t\t\tonChange({ ...this.state }, this.scope);\n\t\t\t\t\t\t\tdone(optionalStringValue(this.state.cheapModel));\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(),\n\t\t\t\t\t),\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"model-router-expensive\",\n\t\t\t\tlabel: \"Expensive model\",\n\t\t\t\tdescription: \"Model pattern for modify, implementation, and escalated tool-heavy turns\",\n\t\t\t\tcurrentValue: optionalStringValue(this.state.expensiveModel),\n\t\t\t\tsubmenu: (_currentValue, done) =>\n\t\t\t\t\tnew TextInputSubmenu(\n\t\t\t\t\t\t\"Expensive / Modify Model\",\n\t\t\t\t\t\t\"Enter a provider/model pattern from pi --list-models. Empty clears it.\",\n\t\t\t\t\t\tthis.state.expensiveModel ?? \"\",\n\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\tthis.state = { ...this.state, expensiveModel: normalizeOptionalString(value) };\n\t\t\t\t\t\t\tonChange({ ...this.state }, this.scope);\n\t\t\t\t\t\t\tdone(optionalStringValue(this.state.expensiveModel));\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(),\n\t\t\t\t\t),\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"model-router-learning\",\n\t\t\t\tlabel: \"Learning/reflection model\",\n\t\t\t\tdescription:\n\t\t\t\t\t\"Model pattern for background reflection, learn, and skill-creator work; active uses the session model\",\n\t\t\t\tcurrentValue: optionalStringValue(this.state.learningModel, \"active\"),\n\t\t\t\tsubmenu: (_currentValue, done) =>\n\t\t\t\t\tnew TextInputSubmenu(\n\t\t\t\t\t\t\"Learning / Reflection Model\",\n\t\t\t\t\t\t'Enter \"active\" or a provider/model pattern from pi --list-models. Empty uses active.',\n\t\t\t\t\t\tthis.state.learningModel === \"active\" ? \"\" : (this.state.learningModel ?? \"\"),\n\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\tthis.state = { ...this.state, learningModel: normalizeOptionalString(value) ?? \"active\" };\n\t\t\t\t\t\t\tonChange({ ...this.state }, this.scope);\n\t\t\t\t\t\t\tdone(optionalStringValue(this.state.learningModel, \"active\"));\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(),\n\t\t\t\t\t\t'empty uses \"active\"',\n\t\t\t\t\t),\n\t\t\t},\n\t\t];\n\n\t\tthis.settingsList = new SettingsList(\n\t\t\titems,\n\t\t\tMath.min(items.length, 10),\n\t\t\tgetSettingsListTheme(),\n\t\t\t(id, newValue) => {\n\t\t\t\tswitch (id) {\n\t\t\t\t\tcase \"model-router-scope\":\n\t\t\t\t\t\tthis.scope = newValue as SettingsScope;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"model-router-enabled\":\n\t\t\t\t\t\tthis.state = { ...this.state, enabled: newValue === \"true\" };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tonChange({ ...this.state }, this.scope);\n\t\t\t},\n\t\t\tonCancel,\n\t\t);\n\n\t\tthis.addChild(this.settingsList);\n\t}\n\n\thandleInput(data: string): void {\n\t\tthis.settingsList.handleInput(data);\n\t}\n}\n\n/**\n * A submenu component for selecting from a list of options.\n */\nclass WarningSettingsSubmenu extends Container {\n\tprivate settingsList: SettingsList;\n\tprivate state: WarningSettings;\n\n\tconstructor(warnings: WarningSettings, onChange: (warnings: WarningSettings) => void, onCancel: () => void) {\n\t\tsuper();\n\n\t\tthis.state = { ...warnings };\n\n\t\tconst items: SettingItem[] = [\n\t\t\t{\n\t\t\t\tid: \"anthropic-extra-usage\",\n\t\t\t\tlabel: \"Anthropic extra usage\",\n\t\t\t\tdescription: \"Warn when Anthropic subscription auth may use paid extra usage\",\n\t\t\t\tcurrentValue: (this.state.anthropicExtraUsage ?? true) ? \"true\" : \"false\",\n\t\t\t\tvalues: [\"true\", \"false\"],\n\t\t\t},\n\t\t];\n\n\t\tthis.settingsList = new SettingsList(\n\t\t\titems,\n\t\t\tMath.min(items.length, 10),\n\t\t\tgetSettingsListTheme(),\n\t\t\t(id, newValue) => {\n\t\t\t\tswitch (id) {\n\t\t\t\t\tcase \"anthropic-extra-usage\":\n\t\t\t\t\t\tthis.state = { ...this.state, anthropicExtraUsage: newValue === \"true\" };\n\t\t\t\t\t\tonChange({ ...this.state });\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t},\n\t\t\tonCancel,\n\t\t);\n\n\t\tthis.addChild(this.settingsList);\n\t}\n\n\thandleInput(data: string): void {\n\t\tthis.settingsList.handleInput(data);\n\t}\n}\n\nexport class SelectSubmenu extends Container {\n\tprivate selectList: SelectList;\n\n\tgetSelectList(): SelectList {\n\t\treturn this.selectList;\n\t}\n\n\tconstructor(\n\t\ttitle: string,\n\t\tdescription: string,\n\t\toptions: SelectItem[],\n\t\tcurrentValue: string,\n\t\tonSelect: (value: string) => void,\n\t\tonCancel: () => void,\n\t\tonSelectionChange?: (value: string) => void,\n\t) {\n\t\tsuper();\n\n\t\t// Title\n\t\tthis.addChild(new Text(theme.bold(theme.fg(\"accent\", title)), 0, 0));\n\n\t\t// Description\n\t\tif (description) {\n\t\t\tthis.addChild(new Spacer(1));\n\t\t\tthis.addChild(new Text(theme.fg(\"muted\", description), 0, 0));\n\t\t}\n\n\t\t// Spacer\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Select list\n\t\tthis.selectList = new SelectList(\n\t\t\toptions,\n\t\t\tMath.min(options.length, 10),\n\t\t\tgetSelectListTheme(),\n\t\t\tSETTINGS_SUBMENU_SELECT_LIST_LAYOUT,\n\t\t);\n\n\t\t// Pre-select current value\n\t\tconst currentIndex = options.findIndex((o) => o.value === currentValue);\n\t\tif (currentIndex !== -1) {\n\t\t\tthis.selectList.setSelectedIndex(currentIndex);\n\t\t}\n\n\t\tthis.selectList.onSelect = (item) => {\n\t\t\tonSelect(item.value);\n\t\t};\n\n\t\tthis.selectList.onCancel = onCancel;\n\n\t\tif (onSelectionChange) {\n\t\t\tthis.selectList.onSelectionChange = (item) => {\n\t\t\t\tonSelectionChange(item.value);\n\t\t\t};\n\t\t}\n\n\t\tthis.addChild(this.selectList);\n\n\t\t// Hint\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new Text(theme.fg(\"dim\", \" Enter to select · Esc to go back\"), 0, 0));\n\t}\n\n\thandleInput(data: string): void {\n\t\tconst kb = getKeybindings();\n\t\tif (kb.matches(data, \"app.interrupt\") || kb.matches(data, \"app.clear\")) {\n\t\t\tthis.selectList.onCancel?.();\n\t\t\treturn;\n\t\t}\n\t\tthis.selectList.handleInput(data);\n\t}\n}\n\n/**\n * Main settings selector component.\n */\nexport class SettingsSelectorComponent extends Container {\n\tprivate settingsList: SettingsList;\n\n\tconstructor(config: SettingsConfig, callbacks: SettingsCallbacks) {\n\t\tsuper();\n\n\t\tconst supportsImages = getCapabilities().images;\n\t\tconst followUpKey = keyDisplayText(\"app.message.followUp\");\n\t\tlet currentWarnings = { ...config.warnings };\n\t\tlet currentSelfModification: SelfModificationSettings = { ...config.selfModification };\n\t\tlet currentAutonomy: AutonomySettings = { ...config.autonomy };\n\t\tlet currentModelRouter: ModelRouterSettings = { ...config.modelRouter };\n\t\tlet currentAutoLearn: AutoLearnSettings = { ...config.autoLearn };\n\t\tconst items: SettingItem[] = [\n\t\t\t{\n\t\t\t\tid: \"autocompact\",\n\t\t\t\tlabel: \"Auto-compact\",\n\t\t\t\tdescription: \"Automatically compact context when it gets too large\",\n\t\t\t\tcurrentValue: config.autoCompact ? \"true\" : \"false\",\n\t\t\t\tvalues: [\"true\", \"false\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"steering-mode\",\n\t\t\t\tlabel: \"Steering mode\",\n\t\t\t\tdescription:\n\t\t\t\t\t\"Enter while streaming queues steering messages. 'one-at-a-time': deliver one, wait for response. 'all': deliver all at once.\",\n\t\t\t\tcurrentValue: config.steeringMode,\n\t\t\t\tvalues: [\"one-at-a-time\", \"all\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"follow-up-mode\",\n\t\t\t\tlabel: \"Follow-up mode\",\n\t\t\t\tdescription: `${followUpKey} queues follow-up messages until agent stops. 'one-at-a-time': deliver one, wait for response. 'all': deliver all at once.`,\n\t\t\t\tcurrentValue: config.followUpMode,\n\t\t\t\tvalues: [\"one-at-a-time\", \"all\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"transport\",\n\t\t\t\tlabel: \"Transport\",\n\t\t\t\tdescription: \"Preferred transport for providers that support multiple transports\",\n\t\t\t\tcurrentValue: config.transport,\n\t\t\t\tvalues: [\"sse\", \"websocket\", \"websocket-cached\", \"auto\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"http-idle-timeout\",\n\t\t\t\tlabel: \"HTTP idle timeout\",\n\t\t\t\tdescription:\n\t\t\t\t\t\"Maximum idle gap while waiting for HTTP headers or body chunks. Disable for local models that pause longer than five minutes.\",\n\t\t\t\tcurrentValue: formatHttpIdleTimeoutMs(config.httpIdleTimeoutMs),\n\t\t\t\tvalues: HTTP_IDLE_TIMEOUT_CHOICES.map((choice) => choice.label),\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"hide-thinking\",\n\t\t\t\tlabel: \"Hide thinking\",\n\t\t\t\tdescription: \"Hide thinking blocks in assistant responses\",\n\t\t\t\tcurrentValue: config.hideThinkingBlock ? \"true\" : \"false\",\n\t\t\t\tvalues: [\"true\", \"false\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"collapse-changelog\",\n\t\t\t\tlabel: \"Collapse changelog\",\n\t\t\t\tdescription: \"Show condensed changelog after updates\",\n\t\t\t\tcurrentValue: config.collapseChangelog ? \"true\" : \"false\",\n\t\t\t\tvalues: [\"true\", \"false\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"quiet-startup\",\n\t\t\t\tlabel: \"Quiet startup\",\n\t\t\t\tdescription: \"Disable verbose printing at startup\",\n\t\t\t\tcurrentValue: config.quietStartup ? \"true\" : \"false\",\n\t\t\t\tvalues: [\"true\", \"false\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"install-telemetry\",\n\t\t\t\tlabel: \"Install telemetry\",\n\t\t\t\tdescription: \"Send an anonymous version/update ping after changelog-detected updates\",\n\t\t\t\tcurrentValue: config.enableInstallTelemetry ? \"true\" : \"false\",\n\t\t\t\tvalues: [\"true\", \"false\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"double-escape-action\",\n\t\t\t\tlabel: \"Double-escape action\",\n\t\t\t\tdescription: \"Action when pressing Escape twice with empty editor\",\n\t\t\t\tcurrentValue: config.doubleEscapeAction,\n\t\t\t\tvalues: [\"tree\", \"fork\", \"none\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"tree-filter-mode\",\n\t\t\t\tlabel: \"Tree filter mode\",\n\t\t\t\tdescription: \"Default filter when opening /tree\",\n\t\t\t\tcurrentValue: config.treeFilterMode,\n\t\t\t\tvalues: [\"default\", \"no-tools\", \"user-only\", \"labeled-only\", \"all\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"self-modification\",\n\t\t\t\tlabel: \"Self modification\",\n\t\t\t\tdescription: \"Enable Pi self-evolution guardrails and configure the editable pi-adaptative source checkout\",\n\t\t\t\tcurrentValue: selfModificationSummary(currentSelfModification),\n\t\t\t\tsubmenu: (_currentValue, done) =>\n\t\t\t\t\tnew SelfModificationSettingsSubmenu(\n\t\t\t\t\t\tcurrentSelfModification,\n\t\t\t\t\t\t(settings, scope) => {\n\t\t\t\t\t\t\tcurrentSelfModification = { ...settings };\n\t\t\t\t\t\t\tcallbacks.onSelfModificationChange(settings, scope);\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(selfModificationSummary(currentSelfModification)),\n\t\t\t\t\t\tconfig.selfModificationScope ?? \"global\",\n\t\t\t\t\t),\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"autonomy\",\n\t\t\t\tlabel: \"Autonomy\",\n\t\t\t\tdescription: \"Choose one autonomy preset instead of tuning many background-learning knobs\",\n\t\t\t\tcurrentValue: autonomySummary(currentAutonomy),\n\t\t\t\tsubmenu: (_currentValue, done) =>\n\t\t\t\t\tnew AutonomySettingsSubmenu(\n\t\t\t\t\t\tcurrentAutonomy,\n\t\t\t\t\t\t(settings, scope) => {\n\t\t\t\t\t\t\tcurrentAutonomy = { ...settings };\n\t\t\t\t\t\t\tcallbacks.onAutonomyChange(settings, scope);\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(autonomySummary(currentAutonomy)),\n\t\t\t\t\t\tconfig.autonomyScope ?? \"global\",\n\t\t\t\t\t),\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"model-router\",\n\t\t\t\tlabel: \"Model Router\",\n\t\t\t\tdescription:\n\t\t\t\t\t\"Configure models for cheap research, expensive modify/escalation, and background learning/reflection\",\n\t\t\t\tcurrentValue: modelRouterSummary(currentModelRouter),\n\t\t\t\tsubmenu: (_currentValue, done) =>\n\t\t\t\t\tnew ModelRouterSettingsSubmenu(\n\t\t\t\t\t\tcurrentModelRouter,\n\t\t\t\t\t\t(settings, scope) => {\n\t\t\t\t\t\t\tcurrentModelRouter = { ...settings };\n\t\t\t\t\t\t\tcallbacks.onModelRouterChange(settings, scope);\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(modelRouterSummary(currentModelRouter)),\n\t\t\t\t\t\tconfig.modelRouterScope ?? \"global\",\n\t\t\t\t\t),\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn\",\n\t\t\t\tlabel: \"Auto Learn Advanced\",\n\t\t\t\tdescription: \"Advanced overrides for autonomous background learning/scavenging\",\n\t\t\t\tcurrentValue: autoLearnSummary(currentAutoLearn),\n\t\t\t\tsubmenu: (_currentValue, done) =>\n\t\t\t\t\tnew AutoLearnSettingsSubmenu(\n\t\t\t\t\t\tcurrentAutoLearn,\n\t\t\t\t\t\tconfig.currentModelPattern,\n\t\t\t\t\t\tconfig.autoLearnModelOptions,\n\t\t\t\t\t\t(settings, scope) => {\n\t\t\t\t\t\t\tcurrentAutoLearn = { ...settings };\n\t\t\t\t\t\t\tcallbacks.onAutoLearnChange(settings, scope);\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(autoLearnSummary(currentAutoLearn)),\n\t\t\t\t\t\tconfig.autoLearnScope ?? \"global\",\n\t\t\t\t\t),\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"warnings\",\n\t\t\t\tlabel: \"Warnings\",\n\t\t\t\tdescription: \"Enable or disable individual warnings\",\n\t\t\t\tcurrentValue: \"configure\",\n\t\t\t\tsubmenu: (_currentValue, done) =>\n\t\t\t\t\tnew WarningSettingsSubmenu(\n\t\t\t\t\t\tcurrentWarnings,\n\t\t\t\t\t\t(warnings) => {\n\t\t\t\t\t\t\tcurrentWarnings = warnings;\n\t\t\t\t\t\t\tcallbacks.onWarningsChange(warnings);\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(),\n\t\t\t\t\t),\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"thinking\",\n\t\t\t\tlabel: \"Thinking level\",\n\t\t\t\tdescription: \"Reasoning depth for thinking-capable models\",\n\t\t\t\tcurrentValue: config.thinkingLevel,\n\t\t\t\tsubmenu: (currentValue, done) =>\n\t\t\t\t\tnew SelectSubmenu(\n\t\t\t\t\t\t\"Thinking Level\",\n\t\t\t\t\t\t\"Select reasoning depth for thinking-capable models\",\n\t\t\t\t\t\tconfig.availableThinkingLevels.map((level) => ({\n\t\t\t\t\t\t\tvalue: level,\n\t\t\t\t\t\t\tlabel: level,\n\t\t\t\t\t\t\tdescription: THINKING_DESCRIPTIONS[level],\n\t\t\t\t\t\t})),\n\t\t\t\t\t\tcurrentValue,\n\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\tcallbacks.onThinkingLevelChange(value as ThinkingLevel);\n\t\t\t\t\t\t\tdone(value);\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(),\n\t\t\t\t\t),\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"theme\",\n\t\t\t\tlabel: \"Theme\",\n\t\t\t\tdescription: \"Color theme for the interface\",\n\t\t\t\tcurrentValue: config.currentTheme,\n\t\t\t\tsubmenu: (currentValue, done) =>\n\t\t\t\t\tnew SelectSubmenu(\n\t\t\t\t\t\t\"Theme\",\n\t\t\t\t\t\t\"Select color theme\",\n\t\t\t\t\t\tconfig.availableThemes.map((t) => ({\n\t\t\t\t\t\t\tvalue: t,\n\t\t\t\t\t\t\tlabel: t,\n\t\t\t\t\t\t})),\n\t\t\t\t\t\tcurrentValue,\n\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\tcallbacks.onThemeChange(value);\n\t\t\t\t\t\t\tdone(value);\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => {\n\t\t\t\t\t\t\t// Restore original theme on cancel\n\t\t\t\t\t\t\tcallbacks.onThemePreview?.(currentValue);\n\t\t\t\t\t\t\tdone();\n\t\t\t\t\t\t},\n\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\t// Preview theme on selection change\n\t\t\t\t\t\t\tcallbacks.onThemePreview?.(value);\n\t\t\t\t\t\t},\n\t\t\t\t\t),\n\t\t\t},\n\t\t];\n\n\t\tconst externalRoots = config.externalResourceRoots ?? [];\n\t\tconst hasSources = externalRoots.length > 0;\n\t\tconst hasProfiles = (config.profileOptions ?? []).filter((o) => o.value !== \"(none)\").length > 0;\n\n\t\titems.push({\n\t\t\tid: \"resources\",\n\t\t\tlabel: \"Resources\",\n\t\t\tdescription: \"Manage profiles/situations, library, and external resource sources.\",\n\t\t\tcurrentValue: config.activeProfileName ?? \"(none)\",\n\t\t\tsubmenu: (_currentValue, done) => {\n\t\t\t\tconst options: SelectItem[] = [];\n\n\t\t\t\tif (!hasSources && !hasProfiles) {\n\t\t\t\t\toptions.push({\n\t\t\t\t\t\tvalue: \"nudge-add-source\",\n\t\t\t\t\t\tlabel: \"Add your catalog directory →\",\n\t\t\t\t\t\tdescription: \"First-run nudge: Add a directory of shared skills, extensions, profiles, and agents.\",\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\toptions.push({\n\t\t\t\t\tvalue: \"active-profile\",\n\t\t\t\t\tlabel: \"Profile / Situation\",\n\t\t\t\t\tdescription: `Select the active profile/situation. Current: ${config.activeProfileName ?? \"(none)\"}`,\n\t\t\t\t});\n\n\t\t\t\toptions.push({\n\t\t\t\t\tvalue: \"manage-library\",\n\t\t\t\t\tlabel: \"Manage Library\",\n\t\t\t\t\tdescription: \"Toggle allowed tools/skills/extensions in the active profile/scope.\",\n\t\t\t\t});\n\n\t\t\t\toptions.push({\n\t\t\t\t\tvalue: \"manage-profiles\",\n\t\t\t\t\tlabel: \"Manage Profiles / Situations\",\n\t\t\t\t\tdescription: \"Create, delete, or persist profile/situation definitions.\",\n\t\t\t\t});\n\n\t\t\t\toptions.push({\n\t\t\t\t\tvalue: \"sources\",\n\t\t\t\t\tlabel: \"Sources\",\n\t\t\t\t\tdescription: `Manage external resource roots (${externalRoots.length} registered).`,\n\t\t\t\t});\n\n\t\t\t\treturn new SelectSubmenu(\n\t\t\t\t\t\"Resources Hub\",\n\t\t\t\t\t\"Configure profiles/situations and external resource catalogs.\",\n\t\t\t\t\toptions,\n\t\t\t\t\t\"\",\n\t\t\t\t\t(value) => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tcallbacks.onResourcesHubAction?.(value);\n\t\t\t\t\t},\n\t\t\t\t\t() => done(),\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\n\t\t// Only show image toggle if terminal supports it\n\t\tif (supportsImages) {\n\t\t\t// Insert after autocompact\n\t\t\titems.splice(1, 0, {\n\t\t\t\tid: \"show-images\",\n\t\t\t\tlabel: \"Show images\",\n\t\t\t\tdescription: \"Render images inline in terminal\",\n\t\t\t\tcurrentValue: config.showImages ? \"true\" : \"false\",\n\t\t\t\tvalues: [\"true\", \"false\"],\n\t\t\t});\n\t\t\titems.splice(2, 0, {\n\t\t\t\tid: \"image-width-cells\",\n\t\t\t\tlabel: \"Image width\",\n\t\t\t\tdescription: \"Preferred inline image width in terminal cells\",\n\t\t\t\tcurrentValue: String(config.imageWidthCells),\n\t\t\t\tvalues: [\"60\", \"80\", \"120\"],\n\t\t\t});\n\t\t}\n\n\t\t// Image auto-resize toggle (always available, affects both attached and read images)\n\t\titems.splice(supportsImages ? 3 : 1, 0, {\n\t\t\tid: \"auto-resize-images\",\n\t\t\tlabel: \"Auto-resize images\",\n\t\t\tdescription: \"Resize large images to 2000x2000 max for better model compatibility\",\n\t\t\tcurrentValue: config.autoResizeImages ? \"true\" : \"false\",\n\t\t\tvalues: [\"true\", \"false\"],\n\t\t});\n\n\t\t// Block images toggle (always available, insert after auto-resize-images)\n\t\tconst autoResizeIndex = items.findIndex((item) => item.id === \"auto-resize-images\");\n\t\titems.splice(autoResizeIndex + 1, 0, {\n\t\t\tid: \"block-images\",\n\t\t\tlabel: \"Block images\",\n\t\t\tdescription: \"Prevent images from being sent to LLM providers\",\n\t\t\tcurrentValue: config.blockImages ? \"true\" : \"false\",\n\t\t\tvalues: [\"true\", \"false\"],\n\t\t});\n\n\t\t// Skill commands toggle (insert after block-images)\n\t\tconst blockImagesIndex = items.findIndex((item) => item.id === \"block-images\");\n\t\titems.splice(blockImagesIndex + 1, 0, {\n\t\t\tid: \"skill-commands\",\n\t\t\tlabel: \"Skill commands\",\n\t\t\tdescription: \"Register skills as /skill:name commands\",\n\t\t\tcurrentValue: config.enableSkillCommands ? \"true\" : \"false\",\n\t\t\tvalues: [\"true\", \"false\"],\n\t\t});\n\n\t\t// Hardware cursor toggle (insert after skill-commands)\n\t\tconst skillCommandsIndex = items.findIndex((item) => item.id === \"skill-commands\");\n\t\titems.splice(skillCommandsIndex + 1, 0, {\n\t\t\tid: \"show-hardware-cursor\",\n\t\t\tlabel: \"Show hardware cursor\",\n\t\t\tdescription: \"Show the terminal cursor while still positioning it for IME support\",\n\t\t\tcurrentValue: config.showHardwareCursor ? \"true\" : \"false\",\n\t\t\tvalues: [\"true\", \"false\"],\n\t\t});\n\n\t\t// Editor padding toggle (insert after show-hardware-cursor)\n\t\tconst hardwareCursorIndex = items.findIndex((item) => item.id === \"show-hardware-cursor\");\n\t\titems.splice(hardwareCursorIndex + 1, 0, {\n\t\t\tid: \"editor-padding\",\n\t\t\tlabel: \"Editor padding\",\n\t\t\tdescription: \"Horizontal padding for input editor (0-3)\",\n\t\t\tcurrentValue: String(config.editorPaddingX),\n\t\t\tvalues: [\"0\", \"1\", \"2\", \"3\"],\n\t\t});\n\n\t\t// Autocomplete max visible toggle (insert after editor-padding)\n\t\tconst editorPaddingIndex = items.findIndex((item) => item.id === \"editor-padding\");\n\t\titems.splice(editorPaddingIndex + 1, 0, {\n\t\t\tid: \"autocomplete-max-visible\",\n\t\t\tlabel: \"Autocomplete max items\",\n\t\t\tdescription: \"Max visible items in autocomplete dropdown (3-20)\",\n\t\t\tcurrentValue: String(config.autocompleteMaxVisible),\n\t\t\tvalues: [\"3\", \"5\", \"7\", \"10\", \"15\", \"20\"],\n\t\t});\n\n\t\t// Clear on shrink toggle (insert after autocomplete-max-visible)\n\t\tconst autocompleteIndex = items.findIndex((item) => item.id === \"autocomplete-max-visible\");\n\t\titems.splice(autocompleteIndex + 1, 0, {\n\t\t\tid: \"clear-on-shrink\",\n\t\t\tlabel: \"Clear on shrink\",\n\t\t\tdescription: \"Clear empty rows when content shrinks (may cause flicker)\",\n\t\t\tcurrentValue: config.clearOnShrink ? \"true\" : \"false\",\n\t\t\tvalues: [\"true\", \"false\"],\n\t\t});\n\n\t\t// Terminal progress toggle (insert after clear-on-shrink)\n\t\tconst clearOnShrinkIndex = items.findIndex((item) => item.id === \"clear-on-shrink\");\n\t\titems.splice(clearOnShrinkIndex + 1, 0, {\n\t\t\tid: \"terminal-progress\",\n\t\t\tlabel: \"Terminal progress\",\n\t\t\tdescription: \"Show OSC 9;4 progress indicators in the terminal tab bar\",\n\t\t\tcurrentValue: config.showTerminalProgress ? \"true\" : \"false\",\n\t\t\tvalues: [\"true\", \"false\"],\n\t\t});\n\n\t\t// Add borders\n\t\tthis.addChild(new DynamicBorder());\n\n\t\tthis.settingsList = new SettingsList(\n\t\t\titems,\n\t\t\t10,\n\t\t\tgetSettingsListTheme(),\n\t\t\t(id, newValue) => {\n\t\t\t\tswitch (id) {\n\t\t\t\t\tcase \"autocompact\":\n\t\t\t\t\t\tcallbacks.onAutoCompactChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"show-images\":\n\t\t\t\t\t\tcallbacks.onShowImagesChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"image-width-cells\":\n\t\t\t\t\t\tcallbacks.onImageWidthCellsChange(parseInt(newValue, 10));\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-resize-images\":\n\t\t\t\t\t\tcallbacks.onAutoResizeImagesChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"block-images\":\n\t\t\t\t\t\tcallbacks.onBlockImagesChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"skill-commands\":\n\t\t\t\t\t\tcallbacks.onEnableSkillCommandsChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"steering-mode\":\n\t\t\t\t\t\tcallbacks.onSteeringModeChange(newValue as \"all\" | \"one-at-a-time\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"follow-up-mode\":\n\t\t\t\t\t\tcallbacks.onFollowUpModeChange(newValue as \"all\" | \"one-at-a-time\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"transport\":\n\t\t\t\t\t\tcallbacks.onTransportChange(newValue as Transport);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"http-idle-timeout\": {\n\t\t\t\t\t\tconst choice = HTTP_IDLE_TIMEOUT_CHOICES.find((item) => item.label === newValue);\n\t\t\t\t\t\tif (choice) {\n\t\t\t\t\t\t\tcallbacks.onHttpIdleTimeoutMsChange(choice.timeoutMs);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"hide-thinking\":\n\t\t\t\t\t\tcallbacks.onHideThinkingBlockChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"collapse-changelog\":\n\t\t\t\t\t\tcallbacks.onCollapseChangelogChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"quiet-startup\":\n\t\t\t\t\t\tcallbacks.onQuietStartupChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"install-telemetry\":\n\t\t\t\t\t\tcallbacks.onEnableInstallTelemetryChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"double-escape-action\":\n\t\t\t\t\t\tcallbacks.onDoubleEscapeActionChange(newValue as \"fork\" | \"tree\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"tree-filter-mode\":\n\t\t\t\t\t\tcallbacks.onTreeFilterModeChange(\n\t\t\t\t\t\t\tnewValue as \"default\" | \"no-tools\" | \"user-only\" | \"labeled-only\" | \"all\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"show-hardware-cursor\":\n\t\t\t\t\t\tcallbacks.onShowHardwareCursorChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"editor-padding\":\n\t\t\t\t\t\tcallbacks.onEditorPaddingXChange(parseInt(newValue, 10));\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"autocomplete-max-visible\":\n\t\t\t\t\t\tcallbacks.onAutocompleteMaxVisibleChange(parseInt(newValue, 10));\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"clear-on-shrink\":\n\t\t\t\t\t\tcallbacks.onClearOnShrinkChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"terminal-progress\":\n\t\t\t\t\t\tcallbacks.onShowTerminalProgressChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t},\n\t\t\tcallbacks.onCancel,\n\t\t\t{ enableSearch: true },\n\t\t);\n\n\t\tthis.addChild(this.settingsList);\n\t\tthis.addChild(new DynamicBorder());\n\t}\n\n\tgetSettingsList(): SettingsList {\n\t\treturn this.settingsList;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"settings-selector.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/settings-selector.ts"],"names":[],"mappings":"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","sourcesContent":["import type { ThinkingLevel } from \"@caupulican/pi-agent-core\";\nimport type { Transport } from \"@caupulican/pi-ai\";\nimport {\n\tContainer,\n\tgetCapabilities,\n\tgetKeybindings,\n\tInput,\n\ttype SelectItem,\n\tSelectList,\n\ttype SelectListLayoutOptions,\n\ttype SettingItem,\n\tSettingsList,\n\tSpacer,\n\tText,\n} from \"@caupulican/pi-tui\";\nimport { formatHttpIdleTimeoutMs, HTTP_IDLE_TIMEOUT_CHOICES } from \"../../../core/http-dispatcher.ts\";\nimport type {\n\tAutoLearnSettings,\n\tAutonomyMode,\n\tAutonomySettings,\n\tModelRouterSettings,\n\tSelfModificationSettings,\n\tSettingsScope,\n\tWarningSettings,\n} from \"../../../core/settings-manager.ts\";\nimport { DEFAULT_AUTONOMY_MAX_STALL_TURNS } from \"../../../core/settings-manager.ts\";\nimport { getSelectListTheme, getSettingsListTheme, theme } from \"../theme/theme.ts\";\nimport { DynamicBorder } from \"./dynamic-border.ts\";\nimport { keyDisplayText } from \"./keybinding-hints.ts\";\n\nconst SETTINGS_SUBMENU_SELECT_LIST_LAYOUT: SelectListLayoutOptions = {\n\tminPrimaryColumnWidth: 12,\n\tmaxPrimaryColumnWidth: 32,\n};\n\nconst AUTO_LEARN_CUSTOM_MODEL_VALUE = \"__custom_auto_learn_model__\";\nconst MODEL_ROUTER_UNSET_MODEL_VALUE = \"__unset_model_router_model__\";\n\nconst THINKING_DESCRIPTIONS: Record<ThinkingLevel, string> = {\n\toff: \"No reasoning\",\n\tminimal: \"Very brief reasoning (~1k tokens)\",\n\tlow: \"Light reasoning (~2k tokens)\",\n\tmedium: \"Moderate reasoning (~8k tokens)\",\n\thigh: \"Deep reasoning (~16k tokens)\",\n\txhigh: \"Maximum reasoning (~32k tokens)\",\n};\n\nconst AUTONOMY_MODES: AutonomyMode[] = [\"off\", \"safe\", \"balanced\", \"full\"];\nconst AUTONOMY_MAX_STALL_TURN_VALUES = [\"0\", \"5\", \"10\", \"20\", \"30\", \"50\"];\n\nconst AUTO_LEARN_DEFAULTS = {\n\tmodel: \"active\",\n\tlongSessionMessages: 32,\n\tlongSessionContextPercent: 70,\n\tcooldownMinutes: 120,\n\tleaseMinutes: 90,\n\tmaxConcurrentLearners: 2,\n\tapplyHighConfidence: false,\n\treflectionReview: true,\n\treflectionMinToolCalls: 5,\n\treflectionCooldownMinutes: 60,\n} as const;\n\nfunction booleanSettingValue(value: boolean | undefined, defaultValue = false): string {\n\treturn (value ?? defaultValue) ? \"true\" : \"false\";\n}\n\nfunction optionalStringValue(value: string | undefined, fallback = \"(not set)\"): string {\n\tconst trimmed = value?.trim();\n\treturn trimmed && trimmed.length > 0 ? trimmed : fallback;\n}\n\nfunction normalizeOptionalString(value: string): string | undefined {\n\tconst trimmed = value.trim();\n\treturn trimmed.length > 0 ? trimmed : undefined;\n}\n\nfunction numberSettingValue(value: number | undefined, defaultValue: number): string {\n\treturn String(value ?? defaultValue);\n}\n\nfunction autoLearnModelValue(settings: AutoLearnSettings): string {\n\treturn optionalStringValue(settings.model, AUTO_LEARN_DEFAULTS.model);\n}\n\nfunction selfModificationSummary(settings: SelfModificationSettings): string {\n\tif (!(settings.enabled ?? false)) return \"disabled\";\n\tconst hasPath =\n\t\tBoolean(settings.sourcePath?.trim()) ||\n\t\t(Array.isArray(settings.sourcePaths) && settings.sourcePaths.some((candidate) => Boolean(candidate?.trim())));\n\treturn hasPath ? \"enabled\" : \"enabled (missing path)\";\n}\n\nfunction autonomyModeValue(settings: AutonomySettings): AutonomyMode {\n\treturn settings.mode && AUTONOMY_MODES.includes(settings.mode) ? settings.mode : \"off\";\n}\n\nfunction autonomySummary(settings: AutonomySettings): string {\n\tconst mode = autonomyModeValue(settings);\n\tconst rounds = settings.maxStallTurns ?? DEFAULT_AUTONOMY_MAX_STALL_TURNS;\n\tconst modeLabel = mode === \"full\" ? \"standing autonomy\" : mode;\n\treturn `${modeLabel}, ${rounds} rounds`;\n}\n\nfunction autonomyMaxStallTurnsValue(settings: AutonomySettings): string {\n\tconst rounds = settings.maxStallTurns ?? DEFAULT_AUTONOMY_MAX_STALL_TURNS;\n\treturn String(rounds);\n}\n\nfunction autoLearnSummary(settings: AutoLearnSettings): string {\n\treturn settings.enabled ? `enabled (${autoLearnModelValue(settings)})` : \"disabled\";\n}\n\nfunction modelRouterSummary(settings: ModelRouterSettings): string {\n\tconst state = settings.enabled ? \"enabled\" : \"disabled\";\n\treturn `${state} · cheap: ${optionalStringValue(settings.cheapModel)} · expensive: ${optionalStringValue(settings.expensiveModel)} · learn: ${optionalStringValue(settings.learningModel, \"active\")}`;\n}\n\nfunction buildAutoLearnModelOptions(\n\tsettings: AutoLearnSettings,\n\tconfiguredModelOptions: SelectItem[] | undefined,\n\tcurrentModelPattern: string | undefined,\n): SelectItem[] {\n\tconst currentValue = autoLearnModelValue(settings);\n\tconst options: SelectItem[] = [\n\t\t{\n\t\t\tvalue: AUTO_LEARN_DEFAULTS.model,\n\t\t\tlabel: \"active\",\n\t\t\tdescription: currentModelPattern\n\t\t\t\t? `Use the current session model (${currentModelPattern})`\n\t\t\t\t: \"Use the current session model\",\n\t\t},\n\t];\n\tconst seen = new Set(options.map((option) => option.value));\n\n\tfor (const option of configuredModelOptions ?? []) {\n\t\tif (seen.has(option.value)) continue;\n\t\toptions.push(option);\n\t\tseen.add(option.value);\n\t}\n\n\tif (currentValue !== AUTO_LEARN_DEFAULTS.model && !seen.has(currentValue)) {\n\t\toptions.push({\n\t\t\tvalue: currentValue,\n\t\t\tlabel: currentValue,\n\t\t\tdescription: \"Current custom setting\",\n\t\t});\n\t\tseen.add(currentValue);\n\t}\n\n\toptions.push({\n\t\tvalue: AUTO_LEARN_CUSTOM_MODEL_VALUE,\n\t\tlabel: \"Manual / custom…\",\n\t\tdescription: \"Type a model pattern not listed above\",\n\t});\n\n\treturn options;\n}\n\nfunction buildModelRouterRoleModelOptions(options: {\n\tcurrentValue: string | undefined;\n\tconfiguredModelOptions: SelectItem[] | undefined;\n\tcurrentModelPattern: string | undefined;\n\tincludeActive: boolean;\n\tunsetDescription?: string;\n}): SelectItem[] {\n\tconst modelOptions: SelectItem[] = [];\n\tconst seen = new Set<string>();\n\n\tif (options.includeActive) {\n\t\tmodelOptions.push({\n\t\t\tvalue: AUTO_LEARN_DEFAULTS.model,\n\t\t\tlabel: \"active\",\n\t\t\tdescription: options.currentModelPattern\n\t\t\t\t? `Use the current session model (${options.currentModelPattern})`\n\t\t\t\t: \"Use the current session model\",\n\t\t});\n\t\tseen.add(AUTO_LEARN_DEFAULTS.model);\n\t} else {\n\t\tmodelOptions.push({\n\t\t\tvalue: MODEL_ROUTER_UNSET_MODEL_VALUE,\n\t\t\tlabel: \"(unset)\",\n\t\t\tdescription: options.unsetDescription ?? \"Clear this model setting\",\n\t\t});\n\t\tseen.add(MODEL_ROUTER_UNSET_MODEL_VALUE);\n\t}\n\n\tfor (const option of options.configuredModelOptions ?? []) {\n\t\tif (seen.has(option.value)) continue;\n\t\tmodelOptions.push(option);\n\t\tseen.add(option.value);\n\t}\n\n\tconst currentValue = options.currentValue?.trim();\n\tif (currentValue && !seen.has(currentValue)) {\n\t\tmodelOptions.push({\n\t\t\tvalue: currentValue,\n\t\t\tlabel: currentValue,\n\t\t\tdescription: \"Current custom setting\",\n\t\t});\n\t\tseen.add(currentValue);\n\t}\n\n\tmodelOptions.push({\n\t\tvalue: AUTO_LEARN_CUSTOM_MODEL_VALUE,\n\t\tlabel: \"Manual / custom…\",\n\t\tdescription: \"Type a model pattern not listed above\",\n\t});\n\n\treturn modelOptions;\n}\n\nexport interface SettingsConfig {\n\tautoCompact: boolean;\n\tshowImages: boolean;\n\timageWidthCells: number;\n\tautoResizeImages: boolean;\n\tblockImages: boolean;\n\tenableSkillCommands: boolean;\n\tsteeringMode: \"all\" | \"one-at-a-time\";\n\tfollowUpMode: \"all\" | \"one-at-a-time\";\n\ttransport: Transport;\n\thttpIdleTimeoutMs: number;\n\tthinkingLevel: ThinkingLevel;\n\tavailableThinkingLevels: ThinkingLevel[];\n\tcurrentTheme: string;\n\tavailableThemes: string[];\n\thideThinkingBlock: boolean;\n\tcollapseChangelog: boolean;\n\tenableInstallTelemetry: boolean;\n\tdoubleEscapeAction: \"fork\" | \"tree\" | \"none\";\n\ttreeFilterMode: \"default\" | \"no-tools\" | \"user-only\" | \"labeled-only\" | \"all\";\n\tshowHardwareCursor: boolean;\n\teditorPaddingX: number;\n\tautocompleteMaxVisible: number;\n\tquietStartup: boolean;\n\tclearOnShrink: boolean;\n\tshowTerminalProgress: boolean;\n\twarnings: WarningSettings;\n\tselfModification: {\n\t\tenabled: boolean;\n\t\tsourcePath?: string;\n\t\tsourcePaths?: string[];\n\t};\n\tselfModificationScope?: SettingsScope;\n\tautonomy: AutonomySettings;\n\tautonomyScope?: SettingsScope;\n\tmodelRouter: ModelRouterSettings;\n\tmodelRouterScope?: SettingsScope;\n\tautoLearn: AutoLearnSettings;\n\tautoLearnScope?: SettingsScope;\n\tcurrentModelPattern?: string;\n\tautoLearnModelOptions?: SelectItem[];\n\tactiveProfileName?: string;\n\tprofileOptions?: SelectItem[];\n\texternalResourceRoots?: string[];\n\ttrustedResourceRoots?: string[];\n}\n\nexport interface SettingsCallbacks {\n\tonAutoCompactChange: (enabled: boolean) => void;\n\tonShowImagesChange: (enabled: boolean) => void;\n\tonImageWidthCellsChange: (width: number) => void;\n\tonAutoResizeImagesChange: (enabled: boolean) => void;\n\tonBlockImagesChange: (blocked: boolean) => void;\n\tonEnableSkillCommandsChange: (enabled: boolean) => void;\n\tonSteeringModeChange: (mode: \"all\" | \"one-at-a-time\") => void;\n\tonFollowUpModeChange: (mode: \"all\" | \"one-at-a-time\") => void;\n\tonTransportChange: (transport: Transport) => void;\n\tonHttpIdleTimeoutMsChange: (timeoutMs: number) => void;\n\tonThinkingLevelChange: (level: ThinkingLevel) => void;\n\tonThemeChange: (theme: string) => void;\n\tonThemePreview?: (theme: string) => void;\n\tonHideThinkingBlockChange: (hidden: boolean) => void;\n\tonCollapseChangelogChange: (collapsed: boolean) => void;\n\tonEnableInstallTelemetryChange: (enabled: boolean) => void;\n\tonDoubleEscapeActionChange: (action: \"fork\" | \"tree\" | \"none\") => void;\n\tonTreeFilterModeChange: (mode: \"default\" | \"no-tools\" | \"user-only\" | \"labeled-only\" | \"all\") => void;\n\tonShowHardwareCursorChange: (enabled: boolean) => void;\n\tonEditorPaddingXChange: (padding: number) => void;\n\tonAutocompleteMaxVisibleChange: (maxVisible: number) => void;\n\tonQuietStartupChange: (enabled: boolean) => void;\n\tonClearOnShrinkChange: (enabled: boolean) => void;\n\tonShowTerminalProgressChange: (enabled: boolean) => void;\n\tonWarningsChange: (warnings: WarningSettings) => void;\n\tonSelfModificationChange: (settings: SelfModificationSettings, scope: SettingsScope) => void;\n\tonAutonomyChange: (settings: AutonomySettings, scope: SettingsScope) => void;\n\tonModelRouterChange: (settings: ModelRouterSettings, scope: SettingsScope) => void;\n\tonAutoLearnChange: (settings: AutoLearnSettings, scope: SettingsScope) => void;\n\tonResourcesHubAction?: (action: string) => void;\n\tonCancel: () => void;\n}\n\nclass TextInputSubmenu extends Container {\n\tprivate input: Input;\n\n\tconstructor(\n\t\ttitle: string,\n\t\tdescription: string,\n\t\tcurrentValue: string,\n\t\tonSubmit: (value: string) => void,\n\t\tonCancel: () => void,\n\t\temptyHint = \"empty clears the setting\",\n\t) {\n\t\tsuper();\n\n\t\tthis.addChild(new Text(theme.bold(theme.fg(\"accent\", title)), 0, 0));\n\t\tif (description) {\n\t\t\tthis.addChild(new Spacer(1));\n\t\t\tthis.addChild(new Text(theme.fg(\"muted\", description), 0, 0));\n\t\t}\n\t\tthis.addChild(new Spacer(1));\n\n\t\tthis.input = new Input();\n\t\tthis.input.setValue(currentValue);\n\t\tthis.input.focused = true;\n\t\tthis.input.onSubmit = onSubmit;\n\t\tthis.input.onEscape = onCancel;\n\t\tthis.addChild(this.input);\n\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new Text(theme.fg(\"dim\", ` Enter to save · Esc to go back · ${emptyHint}`), 0, 0));\n\t}\n\n\thandleInput(data: string): void {\n\t\tthis.input.handleInput(data);\n\t}\n}\n\nclass ModelSelectionSubmenu extends Container {\n\tprivate searchInput: Input;\n\tprivate selectList: SelectList;\n\tprivate customInput: TextInputSubmenu | null = null;\n\n\tconstructor(\n\t\toptions: SelectItem[],\n\t\tcurrentValue: string,\n\t\tonSelect: (value: string) => void,\n\t\tonCancel: () => void,\n\t\tlabels: {\n\t\t\ttitle: string;\n\t\t\tdescription: string;\n\t\t\tcustomTitle: string;\n\t\t\tcustomDescription: string;\n\t\t\tcustomEmptyHint: string;\n\t\t\tcustomEmptyValue: string | undefined;\n\t\t} = {\n\t\t\ttitle: \"Auto Learn Scavenger Model\",\n\t\t\tdescription:\n\t\t\t\t\"Choose active or a model from currently configured subscription/API accounts. Type to filter; choose manual for a custom pattern.\",\n\t\t\tcustomTitle: \"Custom Auto Learn Model\",\n\t\t\tcustomDescription: 'Enter \"active\" or a provider/model pattern like \"openai/gpt-5.4\".',\n\t\t\tcustomEmptyHint: 'empty uses \"active\"',\n\t\t\tcustomEmptyValue: AUTO_LEARN_DEFAULTS.model,\n\t\t},\n\t) {\n\t\tsuper();\n\n\t\tthis.addChild(new Text(theme.bold(theme.fg(\"accent\", labels.title)), 0, 0));\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new Text(theme.fg(\"muted\", labels.description), 0, 0));\n\t\tthis.addChild(new Spacer(1));\n\n\t\tthis.searchInput = new Input();\n\t\tthis.searchInput.focused = true;\n\t\tthis.addChild(this.searchInput);\n\t\tthis.addChild(new Spacer(1));\n\n\t\tthis.selectList = new SelectList(\n\t\t\toptions,\n\t\t\tMath.min(options.length, 10),\n\t\t\tgetSelectListTheme(),\n\t\t\tSETTINGS_SUBMENU_SELECT_LIST_LAYOUT,\n\t\t);\n\n\t\tconst currentIndex = options.findIndex((option) => option.value === currentValue);\n\t\tif (currentIndex !== -1) {\n\t\t\tthis.selectList.setSelectedIndex(currentIndex);\n\t\t}\n\n\t\tthis.selectList.onSelect = (item) => {\n\t\t\tif (item.value === AUTO_LEARN_CUSTOM_MODEL_VALUE) {\n\t\t\t\tthis.customInput = new TextInputSubmenu(\n\t\t\t\t\tlabels.customTitle,\n\t\t\t\t\tlabels.customDescription,\n\t\t\t\t\tcurrentValue === labels.customEmptyValue ? \"\" : currentValue,\n\t\t\t\t\t(value) => {\n\t\t\t\t\t\tonSelect(normalizeOptionalString(value) ?? labels.customEmptyValue ?? \"\");\n\t\t\t\t\t},\n\t\t\t\t\t() => {\n\t\t\t\t\t\tthis.customInput = null;\n\t\t\t\t\t},\n\t\t\t\t\tlabels.customEmptyHint,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tonSelect(item.value);\n\t\t};\n\t\tthis.selectList.onCancel = onCancel;\n\t\tthis.addChild(this.selectList);\n\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new Text(theme.fg(\"dim\", \" Type to filter · Enter to select · Esc to go back\"), 0, 0));\n\t}\n\n\thandleInput(data: string): void {\n\t\tif (this.customInput) {\n\t\t\tthis.customInput.handleInput(data);\n\t\t\treturn;\n\t\t}\n\n\t\tconst kb = getKeybindings();\n\t\tif (kb.matches(data, \"tui.select.up\") || kb.matches(data, \"tui.select.down\")) {\n\t\t\tthis.selectList.handleInput(data);\n\t\t\treturn;\n\t\t}\n\t\tif (kb.matches(data, \"tui.select.confirm\") || kb.matches(data, \"tui.select.cancel\")) {\n\t\t\tthis.selectList.handleInput(data);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.searchInput.handleInput(data);\n\t\tthis.selectList.setFilter(this.searchInput.getValue());\n\t}\n\n\trender(width: number): string[] {\n\t\treturn this.customInput ? this.customInput.render(width) : super.render(width);\n\t}\n\n\tinvalidate(): void {\n\t\tsuper.invalidate();\n\t\tthis.customInput?.invalidate?.();\n\t}\n}\n\nclass SelfModificationSettingsSubmenu extends Container {\n\tprivate settingsList: SettingsList;\n\tprivate state: SelfModificationSettings;\n\tprivate scope: SettingsScope;\n\n\tconstructor(\n\t\tsettings: SelfModificationSettings,\n\t\tonChange: (settings: SelfModificationSettings, scope: SettingsScope) => void,\n\t\tonCancel: () => void,\n\t\tscope: SettingsScope = \"global\",\n\t) {\n\t\tsuper();\n\n\t\tthis.state = { ...settings, enabled: settings.enabled ?? false };\n\t\tthis.scope = scope;\n\n\t\tconst items: SettingItem[] = [\n\t\t\t{\n\t\t\t\tid: \"self-modification-scope\",\n\t\t\t\tlabel: \"Save scope\",\n\t\t\t\tdescription:\n\t\t\t\t\t\"Save this self-modification configuration globally or in the current project's .pi/settings.json\",\n\t\t\t\tcurrentValue: this.scope,\n\t\t\t\tvalues: [\"global\", \"project\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"self-modification-enabled\",\n\t\t\t\tlabel: \"Enabled\",\n\t\t\t\tdescription: \"Allow agents to modify Pi's own source/harness only when explicitly tasked\",\n\t\t\t\tcurrentValue: booleanSettingValue(this.state.enabled),\n\t\t\t\tvalues: [\"true\", \"false\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"self-modification-source-path\",\n\t\t\t\tlabel: \"Source path\",\n\t\t\t\tdescription: \"Path to the pi-adaptative source checkout agents may edit for self-evolution\",\n\t\t\t\tcurrentValue: optionalStringValue(this.state.sourcePath),\n\t\t\t\tsubmenu: (_currentValue, done) =>\n\t\t\t\t\tnew TextInputSubmenu(\n\t\t\t\t\t\t\"Pi-adaptative Source Path\",\n\t\t\t\t\t\t\"Set the source checkout path used by self-evolution guardrails. Empty clears it.\",\n\t\t\t\t\t\tthis.state.sourcePath ?? \"\",\n\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\tconst sourcePath = normalizeOptionalString(value);\n\t\t\t\t\t\t\tthis.state = { ...this.state, sourcePath };\n\t\t\t\t\t\t\tonChange({ ...this.state }, this.scope);\n\t\t\t\t\t\t\tdone(optionalStringValue(sourcePath));\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(),\n\t\t\t\t\t),\n\t\t\t},\n\t\t];\n\n\t\tthis.settingsList = new SettingsList(\n\t\t\titems,\n\t\t\tMath.min(items.length, 10),\n\t\t\tgetSettingsListTheme(),\n\t\t\t(id, newValue) => {\n\t\t\t\tswitch (id) {\n\t\t\t\t\tcase \"self-modification-scope\":\n\t\t\t\t\t\tthis.scope = newValue as SettingsScope;\n\t\t\t\t\t\tonChange({ ...this.state }, this.scope);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"self-modification-enabled\":\n\t\t\t\t\t\tthis.state = { ...this.state, enabled: newValue === \"true\" };\n\t\t\t\t\t\tonChange({ ...this.state }, this.scope);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t},\n\t\t\tonCancel,\n\t\t);\n\n\t\tthis.addChild(this.settingsList);\n\t}\n\n\thandleInput(data: string): void {\n\t\tthis.settingsList.handleInput(data);\n\t}\n}\n\nclass AutonomySettingsSubmenu extends Container {\n\tprivate settingsList: SettingsList;\n\tprivate state: AutonomySettings;\n\tprivate scope: SettingsScope;\n\n\tconstructor(\n\t\tsettings: AutonomySettings,\n\t\tonChange: (settings: AutonomySettings, scope: SettingsScope) => void,\n\t\tonCancel: () => void,\n\t\tscope: SettingsScope = \"global\",\n\t) {\n\t\tsuper();\n\t\tthis.state = {\n\t\t\tmode: autonomyModeValue(settings),\n\t\t\tmaxStallTurns: settings.maxStallTurns ?? DEFAULT_AUTONOMY_MAX_STALL_TURNS,\n\t\t};\n\t\tthis.scope = scope;\n\n\t\tconst items: SettingItem[] = [\n\t\t\t{\n\t\t\t\tid: \"autonomy-scope\",\n\t\t\t\tlabel: \"Save scope\",\n\t\t\t\tdescription: \"Save this autonomy preset globally or in the current project's .pi/settings.json\",\n\t\t\t\tcurrentValue: this.scope,\n\t\t\t\tvalues: [\"global\", \"project\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"autonomy-mode\",\n\t\t\t\tlabel: \"Mode\",\n\t\t\t\tdescription: \"One preset for background learning: off, safe, balanced, or standing autonomy\",\n\t\t\t\tcurrentValue: autonomyModeValue(this.state),\n\t\t\t\tvalues: AUTONOMY_MODES,\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"autonomy-goal-loop-rounds\",\n\t\t\t\tlabel: \"Goal loop rounds\",\n\t\t\t\tdescription: \"Maximum provider rounds in one foreground goal loop before Pi stops continuing\",\n\t\t\t\tcurrentValue: autonomyMaxStallTurnsValue(this.state),\n\t\t\t\tvalues: AUTONOMY_MAX_STALL_TURN_VALUES,\n\t\t\t},\n\t\t];\n\n\t\tthis.settingsList = new SettingsList(\n\t\t\titems,\n\t\t\tMath.min(items.length, 10),\n\t\t\tgetSettingsListTheme(),\n\t\t\t(id, newValue) => {\n\t\t\t\tswitch (id) {\n\t\t\t\t\tcase \"autonomy-scope\":\n\t\t\t\t\t\tthis.scope = newValue as SettingsScope;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"autonomy-mode\":\n\t\t\t\t\t\tthis.state = { ...this.state, mode: newValue as AutonomyMode };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"autonomy-goal-loop-rounds\":\n\t\t\t\t\t\tthis.state = { ...this.state, maxStallTurns: Number(newValue) };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tonChange({ ...this.state }, this.scope);\n\t\t\t},\n\t\t\tonCancel,\n\t\t);\n\n\t\tthis.addChild(this.settingsList);\n\t}\n\n\thandleInput(data: string): void {\n\t\tthis.settingsList.handleInput(data);\n\t}\n}\n\nclass AutoLearnSettingsSubmenu extends Container {\n\tprivate settingsList: SettingsList;\n\tprivate state: AutoLearnSettings;\n\tprivate scope: SettingsScope;\n\n\tconstructor(\n\t\tsettings: AutoLearnSettings,\n\t\tcurrentModelPattern: string | undefined,\n\t\tmodelOptions: SelectItem[] | undefined,\n\t\tonChange: (settings: AutoLearnSettings, scope: SettingsScope) => void,\n\t\tonCancel: () => void,\n\t\tscope: SettingsScope = \"global\",\n\t) {\n\t\tsuper();\n\n\t\tthis.state = { ...settings };\n\t\tthis.scope = scope;\n\t\tconst modelDescription = currentModelPattern\n\t\t\t? `Model for background learning. \"active\" uses ${currentModelPattern}; configured subscription/API models are listed first.`\n\t\t\t: 'Model for background learning. Use \"active\" for the current session model, or choose a configured subscription/API model.';\n\t\tconst selectableModelOptions = buildAutoLearnModelOptions(this.state, modelOptions, currentModelPattern);\n\n\t\tconst items: SettingItem[] = [\n\t\t\t{\n\t\t\t\tid: \"auto-learn-scope\",\n\t\t\t\tlabel: \"Save scope\",\n\t\t\t\tdescription: \"Save this Auto Learn configuration globally or in the current project's .pi/settings.json\",\n\t\t\t\tcurrentValue: this.scope,\n\t\t\t\tvalues: [\"global\", \"project\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-enabled\",\n\t\t\t\tlabel: \"Enabled\",\n\t\t\t\tdescription: \"Autonomously trigger background history scavenging for long sessions\",\n\t\t\t\tcurrentValue: booleanSettingValue(this.state.enabled),\n\t\t\t\tvalues: [\"true\", \"false\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-model\",\n\t\t\t\tlabel: \"Scavenger model\",\n\t\t\t\tdescription: modelDescription,\n\t\t\t\tcurrentValue: autoLearnModelValue(this.state),\n\t\t\t\tsubmenu: (_currentValue, done) =>\n\t\t\t\t\tnew ModelSelectionSubmenu(\n\t\t\t\t\t\tselectableModelOptions,\n\t\t\t\t\t\tautoLearnModelValue(this.state),\n\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\tthis.state = { ...this.state, model: value };\n\t\t\t\t\t\t\tonChange({ ...this.state }, this.scope);\n\t\t\t\t\t\t\tdone(autoLearnModelValue(this.state));\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(),\n\t\t\t\t\t),\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-long-session-messages\",\n\t\t\t\tlabel: \"Message trigger\",\n\t\t\t\tdescription: \"Trigger after this many message entries in the active branch\",\n\t\t\t\tcurrentValue: numberSettingValue(this.state.longSessionMessages, AUTO_LEARN_DEFAULTS.longSessionMessages),\n\t\t\t\tvalues: [\"16\", \"32\", \"64\", \"128\", \"256\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-context-percent\",\n\t\t\t\tlabel: \"Context trigger %\",\n\t\t\t\tdescription: \"Trigger when current context usage reaches this percentage\",\n\t\t\t\tcurrentValue: numberSettingValue(\n\t\t\t\t\tthis.state.longSessionContextPercent,\n\t\t\t\t\tAUTO_LEARN_DEFAULTS.longSessionContextPercent,\n\t\t\t\t),\n\t\t\t\tvalues: [\"50\", \"60\", \"70\", \"80\", \"90\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-cooldown-minutes\",\n\t\t\t\tlabel: \"Cooldown minutes\",\n\t\t\t\tdescription: \"Per-session-tenant cooldown between learner launches\",\n\t\t\t\tcurrentValue: numberSettingValue(this.state.cooldownMinutes, AUTO_LEARN_DEFAULTS.cooldownMinutes),\n\t\t\t\tvalues: [\"15\", \"30\", \"60\", \"120\", \"240\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-lease-minutes\",\n\t\t\t\tlabel: \"Lease minutes\",\n\t\t\t\tdescription: \"Shared-state lease duration for a running background learner\",\n\t\t\t\tcurrentValue: numberSettingValue(this.state.leaseMinutes, AUTO_LEARN_DEFAULTS.leaseMinutes),\n\t\t\t\tvalues: [\"30\", \"60\", \"90\", \"180\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-max-concurrent\",\n\t\t\t\tlabel: \"Max learners\",\n\t\t\t\tdescription: \"Maximum running Auto Learn background learners per session tenant\",\n\t\t\t\tcurrentValue: numberSettingValue(\n\t\t\t\t\tthis.state.maxConcurrentLearners,\n\t\t\t\t\tAUTO_LEARN_DEFAULTS.maxConcurrentLearners,\n\t\t\t\t),\n\t\t\t\tvalues: [\"1\", \"2\", \"3\", \"4\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-apply-high-confidence\",\n\t\t\t\tlabel: \"Apply high confidence\",\n\t\t\t\tdescription:\n\t\t\t\t\t\"Allow high-confidence memory candidates to be applied automatically; broader write authority follows autonomy.mode\",\n\t\t\t\tcurrentValue: booleanSettingValue(this.state.applyHighConfidence, AUTO_LEARN_DEFAULTS.applyHighConfidence),\n\t\t\t\tvalues: [\"false\", \"true\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-reflection-review\",\n\t\t\t\tlabel: \"Reflection review\",\n\t\t\t\tdescription: \"After corrective or complex turns, launch a bounded background learning review\",\n\t\t\t\tcurrentValue: booleanSettingValue(this.state.reflectionReview, AUTO_LEARN_DEFAULTS.reflectionReview),\n\t\t\t\tvalues: [\"true\", \"false\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-reflection-tool-calls\",\n\t\t\t\tlabel: \"Reflection tool trigger\",\n\t\t\t\tdescription: \"Trigger reflection review after this many tool calls in one completed turn\",\n\t\t\t\tcurrentValue: numberSettingValue(\n\t\t\t\t\tthis.state.reflectionMinToolCalls,\n\t\t\t\t\tAUTO_LEARN_DEFAULTS.reflectionMinToolCalls,\n\t\t\t\t),\n\t\t\t\tvalues: [\"3\", \"5\", \"8\", \"12\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn-reflection-cooldown\",\n\t\t\t\tlabel: \"Reflection cooldown\",\n\t\t\t\tdescription: \"Per-session-tenant cooldown between reflection-review launches\",\n\t\t\t\tcurrentValue: numberSettingValue(\n\t\t\t\t\tthis.state.reflectionCooldownMinutes,\n\t\t\t\t\tAUTO_LEARN_DEFAULTS.reflectionCooldownMinutes,\n\t\t\t\t),\n\t\t\t\tvalues: [\"15\", \"30\", \"60\", \"120\"],\n\t\t\t},\n\t\t];\n\n\t\tthis.settingsList = new SettingsList(\n\t\t\titems,\n\t\t\tMath.min(items.length, 10),\n\t\t\tgetSettingsListTheme(),\n\t\t\t(id, newValue) => {\n\t\t\t\tswitch (id) {\n\t\t\t\t\tcase \"auto-learn-scope\":\n\t\t\t\t\t\tthis.scope = newValue as SettingsScope;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-learn-enabled\":\n\t\t\t\t\t\tthis.state = { ...this.state, enabled: newValue === \"true\" };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-learn-long-session-messages\":\n\t\t\t\t\t\tthis.state = { ...this.state, longSessionMessages: parseInt(newValue, 10) };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-learn-context-percent\":\n\t\t\t\t\t\tthis.state = { ...this.state, longSessionContextPercent: parseInt(newValue, 10) };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-learn-cooldown-minutes\":\n\t\t\t\t\t\tthis.state = { ...this.state, cooldownMinutes: parseInt(newValue, 10) };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-learn-lease-minutes\":\n\t\t\t\t\t\tthis.state = { ...this.state, leaseMinutes: parseInt(newValue, 10) };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-learn-max-concurrent\":\n\t\t\t\t\t\tthis.state = { ...this.state, maxConcurrentLearners: parseInt(newValue, 10) };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-learn-apply-high-confidence\":\n\t\t\t\t\t\tthis.state = { ...this.state, applyHighConfidence: newValue === \"true\" };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-learn-reflection-review\":\n\t\t\t\t\t\tthis.state = { ...this.state, reflectionReview: newValue === \"true\" };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-learn-reflection-tool-calls\":\n\t\t\t\t\t\tthis.state = { ...this.state, reflectionMinToolCalls: parseInt(newValue, 10) };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-learn-reflection-cooldown\":\n\t\t\t\t\t\tthis.state = { ...this.state, reflectionCooldownMinutes: parseInt(newValue, 10) };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tonChange({ ...this.state }, this.scope);\n\t\t\t},\n\t\t\tonCancel,\n\t\t);\n\n\t\tthis.addChild(this.settingsList);\n\t}\n\n\thandleInput(data: string): void {\n\t\tthis.settingsList.handleInput(data);\n\t}\n}\n\nclass ModelRouterSettingsSubmenu extends Container {\n\tprivate settingsList: SettingsList;\n\tprivate state: ModelRouterSettings;\n\tprivate scope: SettingsScope;\n\n\tconstructor(\n\t\tsettings: ModelRouterSettings,\n\t\tcurrentModelPattern: string | undefined,\n\t\tmodelOptions: SelectItem[] | undefined,\n\t\tonChange: (settings: ModelRouterSettings, scope: SettingsScope) => void,\n\t\tonCancel: () => void,\n\t\tscope: SettingsScope = \"global\",\n\t) {\n\t\tsuper();\n\t\tthis.state = {\n\t\t\t...settings,\n\t\t\tenabled: settings.enabled ?? false,\n\t\t\tlearningModel: settings.learningModel ?? \"active\",\n\t\t};\n\t\tthis.scope = scope;\n\t\tconst cheapModelOptions = buildModelRouterRoleModelOptions({\n\t\t\tcurrentValue: this.state.cheapModel,\n\t\t\tconfiguredModelOptions: modelOptions,\n\t\t\tcurrentModelPattern,\n\t\t\tincludeActive: false,\n\t\t\tunsetDescription: \"Clear cheap routing model; research turns fall back to the active session model\",\n\t\t});\n\t\tconst expensiveModelOptions = buildModelRouterRoleModelOptions({\n\t\t\tcurrentValue: this.state.expensiveModel,\n\t\t\tconfiguredModelOptions: modelOptions,\n\t\t\tcurrentModelPattern,\n\t\t\tincludeActive: false,\n\t\t\tunsetDescription: \"Clear expensive routing model; modify turns fall back to the active session model\",\n\t\t});\n\t\tconst learningModelOptions = buildModelRouterRoleModelOptions({\n\t\t\tcurrentValue: this.state.learningModel,\n\t\t\tconfiguredModelOptions: modelOptions,\n\t\t\tcurrentModelPattern,\n\t\t\tincludeActive: true,\n\t\t});\n\t\tthis.addChild(new Text(theme.bold(theme.fg(\"accent\", \"Model Router\")), 0, 0));\n\t\tthis.addChild(new Spacer(1));\n\n\t\tconst items: SettingItem[] = [\n\t\t\t{\n\t\t\t\tid: \"model-router-scope\",\n\t\t\t\tlabel: \"Save scope\",\n\t\t\t\tdescription: \"Save this routing configuration globally or in the current project's .pi/settings.json\",\n\t\t\t\tcurrentValue: this.scope,\n\t\t\t\tvalues: [\"global\", \"project\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"model-router-enabled\",\n\t\t\t\tlabel: \"Enabled\",\n\t\t\t\tdescription: \"Route read-only/research turns to cheap model and modify/tool-heavy turns to expensive model\",\n\t\t\t\tcurrentValue: booleanSettingValue(this.state.enabled),\n\t\t\t\tvalues: [\"false\", \"true\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"model-router-cheap\",\n\t\t\t\tlabel: \"Cheap model\",\n\t\t\t\tdescription: \"Pick the model for read-only, research, explanation, and question turns\",\n\t\t\t\tcurrentValue: optionalStringValue(this.state.cheapModel),\n\t\t\t\tsubmenu: (_currentValue, done) =>\n\t\t\t\t\tnew ModelSelectionSubmenu(\n\t\t\t\t\t\tcheapModelOptions,\n\t\t\t\t\t\tthis.state.cheapModel ?? MODEL_ROUTER_UNSET_MODEL_VALUE,\n\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\tthis.state = {\n\t\t\t\t\t\t\t\t...this.state,\n\t\t\t\t\t\t\t\tcheapModel: value === MODEL_ROUTER_UNSET_MODEL_VALUE ? undefined : value,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tonChange({ ...this.state }, this.scope);\n\t\t\t\t\t\t\tdone(optionalStringValue(this.state.cheapModel));\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttitle: \"Cheap / Research Model\",\n\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\"Choose from models available through configured subscription/API accounts. Type to filter; manual is fallback.\",\n\t\t\t\t\t\t\tcustomTitle: \"Custom Cheap / Research Model\",\n\t\t\t\t\t\t\tcustomDescription: \"Enter a provider/model pattern from pi --list-models.\",\n\t\t\t\t\t\t\tcustomEmptyHint: \"empty clears the setting\",\n\t\t\t\t\t\t\tcustomEmptyValue: MODEL_ROUTER_UNSET_MODEL_VALUE,\n\t\t\t\t\t\t},\n\t\t\t\t\t),\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"model-router-expensive\",\n\t\t\t\tlabel: \"Expensive model\",\n\t\t\t\tdescription: \"Pick the model for modify, implementation, and escalated tool-heavy turns\",\n\t\t\t\tcurrentValue: optionalStringValue(this.state.expensiveModel),\n\t\t\t\tsubmenu: (_currentValue, done) =>\n\t\t\t\t\tnew ModelSelectionSubmenu(\n\t\t\t\t\t\texpensiveModelOptions,\n\t\t\t\t\t\tthis.state.expensiveModel ?? MODEL_ROUTER_UNSET_MODEL_VALUE,\n\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\tthis.state = {\n\t\t\t\t\t\t\t\t...this.state,\n\t\t\t\t\t\t\t\texpensiveModel: value === MODEL_ROUTER_UNSET_MODEL_VALUE ? undefined : value,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tonChange({ ...this.state }, this.scope);\n\t\t\t\t\t\t\tdone(optionalStringValue(this.state.expensiveModel));\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttitle: \"Expensive / Modify Model\",\n\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\"Choose from models available through configured subscription/API accounts. Type to filter; manual is fallback.\",\n\t\t\t\t\t\t\tcustomTitle: \"Custom Expensive / Modify Model\",\n\t\t\t\t\t\t\tcustomDescription: \"Enter a provider/model pattern from pi --list-models.\",\n\t\t\t\t\t\t\tcustomEmptyHint: \"empty clears the setting\",\n\t\t\t\t\t\t\tcustomEmptyValue: MODEL_ROUTER_UNSET_MODEL_VALUE,\n\t\t\t\t\t\t},\n\t\t\t\t\t),\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"model-router-learning\",\n\t\t\t\tlabel: \"Learning/reflection model\",\n\t\t\t\tdescription:\n\t\t\t\t\t\"Pick the model for background reflection, learn, and skill-creator work; active uses the session model\",\n\t\t\t\tcurrentValue: optionalStringValue(this.state.learningModel, \"active\"),\n\t\t\t\tsubmenu: (_currentValue, done) =>\n\t\t\t\t\tnew ModelSelectionSubmenu(\n\t\t\t\t\t\tlearningModelOptions,\n\t\t\t\t\t\tthis.state.learningModel ?? AUTO_LEARN_DEFAULTS.model,\n\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\tthis.state = { ...this.state, learningModel: value };\n\t\t\t\t\t\t\tonChange({ ...this.state }, this.scope);\n\t\t\t\t\t\t\tdone(optionalStringValue(this.state.learningModel, \"active\"));\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttitle: \"Learning / Reflection Model\",\n\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\"Choose active or a model from configured subscription/API accounts. Type to filter; manual is fallback.\",\n\t\t\t\t\t\t\tcustomTitle: \"Custom Learning / Reflection Model\",\n\t\t\t\t\t\t\tcustomDescription: 'Enter \"active\" or a provider/model pattern from pi --list-models.',\n\t\t\t\t\t\t\tcustomEmptyHint: 'empty uses \"active\"',\n\t\t\t\t\t\t\tcustomEmptyValue: AUTO_LEARN_DEFAULTS.model,\n\t\t\t\t\t\t},\n\t\t\t\t\t),\n\t\t\t},\n\t\t];\n\n\t\tthis.settingsList = new SettingsList(\n\t\t\titems,\n\t\t\tMath.min(items.length, 10),\n\t\t\tgetSettingsListTheme(),\n\t\t\t(id, newValue) => {\n\t\t\t\tswitch (id) {\n\t\t\t\t\tcase \"model-router-scope\":\n\t\t\t\t\t\tthis.scope = newValue as SettingsScope;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"model-router-enabled\":\n\t\t\t\t\t\tthis.state = { ...this.state, enabled: newValue === \"true\" };\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tonChange({ ...this.state }, this.scope);\n\t\t\t},\n\t\t\tonCancel,\n\t\t);\n\n\t\tthis.addChild(this.settingsList);\n\t}\n\n\thandleInput(data: string): void {\n\t\tthis.settingsList.handleInput(data);\n\t}\n}\n\n/**\n * A submenu component for selecting from a list of options.\n */\nclass WarningSettingsSubmenu extends Container {\n\tprivate settingsList: SettingsList;\n\tprivate state: WarningSettings;\n\n\tconstructor(warnings: WarningSettings, onChange: (warnings: WarningSettings) => void, onCancel: () => void) {\n\t\tsuper();\n\n\t\tthis.state = { ...warnings };\n\n\t\tconst items: SettingItem[] = [\n\t\t\t{\n\t\t\t\tid: \"anthropic-extra-usage\",\n\t\t\t\tlabel: \"Anthropic extra usage\",\n\t\t\t\tdescription: \"Warn when Anthropic subscription auth may use paid extra usage\",\n\t\t\t\tcurrentValue: (this.state.anthropicExtraUsage ?? true) ? \"true\" : \"false\",\n\t\t\t\tvalues: [\"true\", \"false\"],\n\t\t\t},\n\t\t];\n\n\t\tthis.settingsList = new SettingsList(\n\t\t\titems,\n\t\t\tMath.min(items.length, 10),\n\t\t\tgetSettingsListTheme(),\n\t\t\t(id, newValue) => {\n\t\t\t\tswitch (id) {\n\t\t\t\t\tcase \"anthropic-extra-usage\":\n\t\t\t\t\t\tthis.state = { ...this.state, anthropicExtraUsage: newValue === \"true\" };\n\t\t\t\t\t\tonChange({ ...this.state });\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t},\n\t\t\tonCancel,\n\t\t);\n\n\t\tthis.addChild(this.settingsList);\n\t}\n\n\thandleInput(data: string): void {\n\t\tthis.settingsList.handleInput(data);\n\t}\n}\n\nexport class SelectSubmenu extends Container {\n\tprivate selectList: SelectList;\n\n\tgetSelectList(): SelectList {\n\t\treturn this.selectList;\n\t}\n\n\tconstructor(\n\t\ttitle: string,\n\t\tdescription: string,\n\t\toptions: SelectItem[],\n\t\tcurrentValue: string,\n\t\tonSelect: (value: string) => void,\n\t\tonCancel: () => void,\n\t\tonSelectionChange?: (value: string) => void,\n\t) {\n\t\tsuper();\n\n\t\t// Title\n\t\tthis.addChild(new Text(theme.bold(theme.fg(\"accent\", title)), 0, 0));\n\n\t\t// Description\n\t\tif (description) {\n\t\t\tthis.addChild(new Spacer(1));\n\t\t\tthis.addChild(new Text(theme.fg(\"muted\", description), 0, 0));\n\t\t}\n\n\t\t// Spacer\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Select list\n\t\tthis.selectList = new SelectList(\n\t\t\toptions,\n\t\t\tMath.min(options.length, 10),\n\t\t\tgetSelectListTheme(),\n\t\t\tSETTINGS_SUBMENU_SELECT_LIST_LAYOUT,\n\t\t);\n\n\t\t// Pre-select current value\n\t\tconst currentIndex = options.findIndex((o) => o.value === currentValue);\n\t\tif (currentIndex !== -1) {\n\t\t\tthis.selectList.setSelectedIndex(currentIndex);\n\t\t}\n\n\t\tthis.selectList.onSelect = (item) => {\n\t\t\tonSelect(item.value);\n\t\t};\n\n\t\tthis.selectList.onCancel = onCancel;\n\n\t\tif (onSelectionChange) {\n\t\t\tthis.selectList.onSelectionChange = (item) => {\n\t\t\t\tonSelectionChange(item.value);\n\t\t\t};\n\t\t}\n\n\t\tthis.addChild(this.selectList);\n\n\t\t// Hint\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new Text(theme.fg(\"dim\", \" Enter to select · Esc to go back\"), 0, 0));\n\t}\n\n\thandleInput(data: string): void {\n\t\tconst kb = getKeybindings();\n\t\tif (kb.matches(data, \"app.interrupt\") || kb.matches(data, \"app.clear\")) {\n\t\t\tthis.selectList.onCancel?.();\n\t\t\treturn;\n\t\t}\n\t\tthis.selectList.handleInput(data);\n\t}\n}\n\n/**\n * Main settings selector component.\n */\nexport class SettingsSelectorComponent extends Container {\n\tprivate settingsList: SettingsList;\n\n\tconstructor(config: SettingsConfig, callbacks: SettingsCallbacks) {\n\t\tsuper();\n\n\t\tconst supportsImages = getCapabilities().images;\n\t\tconst followUpKey = keyDisplayText(\"app.message.followUp\");\n\t\tlet currentWarnings = { ...config.warnings };\n\t\tlet currentSelfModification: SelfModificationSettings = { ...config.selfModification };\n\t\tlet currentAutonomy: AutonomySettings = { ...config.autonomy };\n\t\tlet currentModelRouter: ModelRouterSettings = { ...config.modelRouter };\n\t\tlet currentAutoLearn: AutoLearnSettings = { ...config.autoLearn };\n\t\tconst items: SettingItem[] = [\n\t\t\t{\n\t\t\t\tid: \"autocompact\",\n\t\t\t\tlabel: \"Auto-compact\",\n\t\t\t\tdescription: \"Automatically compact context when it gets too large\",\n\t\t\t\tcurrentValue: config.autoCompact ? \"true\" : \"false\",\n\t\t\t\tvalues: [\"true\", \"false\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"steering-mode\",\n\t\t\t\tlabel: \"Steering mode\",\n\t\t\t\tdescription:\n\t\t\t\t\t\"Enter while streaming queues steering messages. 'one-at-a-time': deliver one, wait for response. 'all': deliver all at once.\",\n\t\t\t\tcurrentValue: config.steeringMode,\n\t\t\t\tvalues: [\"one-at-a-time\", \"all\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"follow-up-mode\",\n\t\t\t\tlabel: \"Follow-up mode\",\n\t\t\t\tdescription: `${followUpKey} queues follow-up messages until agent stops. 'one-at-a-time': deliver one, wait for response. 'all': deliver all at once.`,\n\t\t\t\tcurrentValue: config.followUpMode,\n\t\t\t\tvalues: [\"one-at-a-time\", \"all\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"transport\",\n\t\t\t\tlabel: \"Transport\",\n\t\t\t\tdescription: \"Preferred transport for providers that support multiple transports\",\n\t\t\t\tcurrentValue: config.transport,\n\t\t\t\tvalues: [\"sse\", \"websocket\", \"websocket-cached\", \"auto\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"http-idle-timeout\",\n\t\t\t\tlabel: \"HTTP idle timeout\",\n\t\t\t\tdescription:\n\t\t\t\t\t\"Maximum idle gap while waiting for HTTP headers or body chunks. Disable for local models that pause longer than five minutes.\",\n\t\t\t\tcurrentValue: formatHttpIdleTimeoutMs(config.httpIdleTimeoutMs),\n\t\t\t\tvalues: HTTP_IDLE_TIMEOUT_CHOICES.map((choice) => choice.label),\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"hide-thinking\",\n\t\t\t\tlabel: \"Hide thinking\",\n\t\t\t\tdescription: \"Hide thinking blocks in assistant responses\",\n\t\t\t\tcurrentValue: config.hideThinkingBlock ? \"true\" : \"false\",\n\t\t\t\tvalues: [\"true\", \"false\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"collapse-changelog\",\n\t\t\t\tlabel: \"Collapse changelog\",\n\t\t\t\tdescription: \"Show condensed changelog after updates\",\n\t\t\t\tcurrentValue: config.collapseChangelog ? \"true\" : \"false\",\n\t\t\t\tvalues: [\"true\", \"false\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"quiet-startup\",\n\t\t\t\tlabel: \"Quiet startup\",\n\t\t\t\tdescription: \"Disable verbose printing at startup\",\n\t\t\t\tcurrentValue: config.quietStartup ? \"true\" : \"false\",\n\t\t\t\tvalues: [\"true\", \"false\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"install-telemetry\",\n\t\t\t\tlabel: \"Install telemetry\",\n\t\t\t\tdescription: \"Send an anonymous version/update ping after changelog-detected updates\",\n\t\t\t\tcurrentValue: config.enableInstallTelemetry ? \"true\" : \"false\",\n\t\t\t\tvalues: [\"true\", \"false\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"double-escape-action\",\n\t\t\t\tlabel: \"Double-escape action\",\n\t\t\t\tdescription: \"Action when pressing Escape twice with empty editor\",\n\t\t\t\tcurrentValue: config.doubleEscapeAction,\n\t\t\t\tvalues: [\"tree\", \"fork\", \"none\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"tree-filter-mode\",\n\t\t\t\tlabel: \"Tree filter mode\",\n\t\t\t\tdescription: \"Default filter when opening /tree\",\n\t\t\t\tcurrentValue: config.treeFilterMode,\n\t\t\t\tvalues: [\"default\", \"no-tools\", \"user-only\", \"labeled-only\", \"all\"],\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"self-modification\",\n\t\t\t\tlabel: \"Self modification\",\n\t\t\t\tdescription: \"Enable Pi self-evolution guardrails and configure the editable pi-adaptative source checkout\",\n\t\t\t\tcurrentValue: selfModificationSummary(currentSelfModification),\n\t\t\t\tsubmenu: (_currentValue, done) =>\n\t\t\t\t\tnew SelfModificationSettingsSubmenu(\n\t\t\t\t\t\tcurrentSelfModification,\n\t\t\t\t\t\t(settings, scope) => {\n\t\t\t\t\t\t\tcurrentSelfModification = { ...settings };\n\t\t\t\t\t\t\tcallbacks.onSelfModificationChange(settings, scope);\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(selfModificationSummary(currentSelfModification)),\n\t\t\t\t\t\tconfig.selfModificationScope ?? \"global\",\n\t\t\t\t\t),\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"autonomy\",\n\t\t\t\tlabel: \"Autonomy\",\n\t\t\t\tdescription: \"Choose one autonomy preset instead of tuning many background-learning knobs\",\n\t\t\t\tcurrentValue: autonomySummary(currentAutonomy),\n\t\t\t\tsubmenu: (_currentValue, done) =>\n\t\t\t\t\tnew AutonomySettingsSubmenu(\n\t\t\t\t\t\tcurrentAutonomy,\n\t\t\t\t\t\t(settings, scope) => {\n\t\t\t\t\t\t\tcurrentAutonomy = { ...settings };\n\t\t\t\t\t\t\tcallbacks.onAutonomyChange(settings, scope);\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(autonomySummary(currentAutonomy)),\n\t\t\t\t\t\tconfig.autonomyScope ?? \"global\",\n\t\t\t\t\t),\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"model-router\",\n\t\t\t\tlabel: \"Model Router\",\n\t\t\t\tdescription:\n\t\t\t\t\t\"Configure models for cheap research, expensive modify/escalation, and background learning/reflection\",\n\t\t\t\tcurrentValue: modelRouterSummary(currentModelRouter),\n\t\t\t\tsubmenu: (_currentValue, done) =>\n\t\t\t\t\tnew ModelRouterSettingsSubmenu(\n\t\t\t\t\t\tcurrentModelRouter,\n\t\t\t\t\t\tconfig.currentModelPattern,\n\t\t\t\t\t\tconfig.autoLearnModelOptions,\n\t\t\t\t\t\t(settings, scope) => {\n\t\t\t\t\t\t\tcurrentModelRouter = { ...settings };\n\t\t\t\t\t\t\tcallbacks.onModelRouterChange(settings, scope);\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(modelRouterSummary(currentModelRouter)),\n\t\t\t\t\t\tconfig.modelRouterScope ?? \"global\",\n\t\t\t\t\t),\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"auto-learn\",\n\t\t\t\tlabel: \"Auto Learn Advanced\",\n\t\t\t\tdescription: \"Advanced overrides for autonomous background learning/scavenging\",\n\t\t\t\tcurrentValue: autoLearnSummary(currentAutoLearn),\n\t\t\t\tsubmenu: (_currentValue, done) =>\n\t\t\t\t\tnew AutoLearnSettingsSubmenu(\n\t\t\t\t\t\tcurrentAutoLearn,\n\t\t\t\t\t\tconfig.currentModelPattern,\n\t\t\t\t\t\tconfig.autoLearnModelOptions,\n\t\t\t\t\t\t(settings, scope) => {\n\t\t\t\t\t\t\tcurrentAutoLearn = { ...settings };\n\t\t\t\t\t\t\tcallbacks.onAutoLearnChange(settings, scope);\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(autoLearnSummary(currentAutoLearn)),\n\t\t\t\t\t\tconfig.autoLearnScope ?? \"global\",\n\t\t\t\t\t),\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"warnings\",\n\t\t\t\tlabel: \"Warnings\",\n\t\t\t\tdescription: \"Enable or disable individual warnings\",\n\t\t\t\tcurrentValue: \"configure\",\n\t\t\t\tsubmenu: (_currentValue, done) =>\n\t\t\t\t\tnew WarningSettingsSubmenu(\n\t\t\t\t\t\tcurrentWarnings,\n\t\t\t\t\t\t(warnings) => {\n\t\t\t\t\t\t\tcurrentWarnings = warnings;\n\t\t\t\t\t\t\tcallbacks.onWarningsChange(warnings);\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(),\n\t\t\t\t\t),\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"thinking\",\n\t\t\t\tlabel: \"Thinking level\",\n\t\t\t\tdescription: \"Reasoning depth for thinking-capable models\",\n\t\t\t\tcurrentValue: config.thinkingLevel,\n\t\t\t\tsubmenu: (currentValue, done) =>\n\t\t\t\t\tnew SelectSubmenu(\n\t\t\t\t\t\t\"Thinking Level\",\n\t\t\t\t\t\t\"Select reasoning depth for thinking-capable models\",\n\t\t\t\t\t\tconfig.availableThinkingLevels.map((level) => ({\n\t\t\t\t\t\t\tvalue: level,\n\t\t\t\t\t\t\tlabel: level,\n\t\t\t\t\t\t\tdescription: THINKING_DESCRIPTIONS[level],\n\t\t\t\t\t\t})),\n\t\t\t\t\t\tcurrentValue,\n\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\tcallbacks.onThinkingLevelChange(value as ThinkingLevel);\n\t\t\t\t\t\t\tdone(value);\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => done(),\n\t\t\t\t\t),\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: \"theme\",\n\t\t\t\tlabel: \"Theme\",\n\t\t\t\tdescription: \"Color theme for the interface\",\n\t\t\t\tcurrentValue: config.currentTheme,\n\t\t\t\tsubmenu: (currentValue, done) =>\n\t\t\t\t\tnew SelectSubmenu(\n\t\t\t\t\t\t\"Theme\",\n\t\t\t\t\t\t\"Select color theme\",\n\t\t\t\t\t\tconfig.availableThemes.map((t) => ({\n\t\t\t\t\t\t\tvalue: t,\n\t\t\t\t\t\t\tlabel: t,\n\t\t\t\t\t\t})),\n\t\t\t\t\t\tcurrentValue,\n\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\tcallbacks.onThemeChange(value);\n\t\t\t\t\t\t\tdone(value);\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => {\n\t\t\t\t\t\t\t// Restore original theme on cancel\n\t\t\t\t\t\t\tcallbacks.onThemePreview?.(currentValue);\n\t\t\t\t\t\t\tdone();\n\t\t\t\t\t\t},\n\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\t// Preview theme on selection change\n\t\t\t\t\t\t\tcallbacks.onThemePreview?.(value);\n\t\t\t\t\t\t},\n\t\t\t\t\t),\n\t\t\t},\n\t\t];\n\n\t\tconst externalRoots = config.externalResourceRoots ?? [];\n\t\tconst hasSources = externalRoots.length > 0;\n\t\tconst hasProfiles = (config.profileOptions ?? []).filter((o) => o.value !== \"(none)\").length > 0;\n\n\t\titems.push({\n\t\t\tid: \"resources\",\n\t\t\tlabel: \"Resources\",\n\t\t\tdescription: \"Manage profiles/situations, library, and external resource sources.\",\n\t\t\tcurrentValue: config.activeProfileName ?? \"(none)\",\n\t\t\tsubmenu: (_currentValue, done) => {\n\t\t\t\tconst options: SelectItem[] = [];\n\n\t\t\t\tif (!hasSources && !hasProfiles) {\n\t\t\t\t\toptions.push({\n\t\t\t\t\t\tvalue: \"nudge-add-source\",\n\t\t\t\t\t\tlabel: \"Add your catalog directory →\",\n\t\t\t\t\t\tdescription: \"First-run nudge: Add a directory of shared skills, extensions, profiles, and agents.\",\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\toptions.push({\n\t\t\t\t\tvalue: \"active-profile\",\n\t\t\t\t\tlabel: \"Profile / Situation\",\n\t\t\t\t\tdescription: `Select the active profile/situation. Current: ${config.activeProfileName ?? \"(none)\"}`,\n\t\t\t\t});\n\n\t\t\t\toptions.push({\n\t\t\t\t\tvalue: \"manage-library\",\n\t\t\t\t\tlabel: \"Manage Library\",\n\t\t\t\t\tdescription: \"Toggle allowed tools/skills/extensions in the active profile/scope.\",\n\t\t\t\t});\n\n\t\t\t\toptions.push({\n\t\t\t\t\tvalue: \"manage-profiles\",\n\t\t\t\t\tlabel: \"Manage Profiles / Situations\",\n\t\t\t\t\tdescription: \"Create, delete, or persist profile/situation definitions.\",\n\t\t\t\t});\n\n\t\t\t\toptions.push({\n\t\t\t\t\tvalue: \"sources\",\n\t\t\t\t\tlabel: \"Sources\",\n\t\t\t\t\tdescription: `Manage external resource roots (${externalRoots.length} registered).`,\n\t\t\t\t});\n\n\t\t\t\treturn new SelectSubmenu(\n\t\t\t\t\t\"Resources Hub\",\n\t\t\t\t\t\"Configure profiles/situations and external resource catalogs.\",\n\t\t\t\t\toptions,\n\t\t\t\t\t\"\",\n\t\t\t\t\t(value) => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tcallbacks.onResourcesHubAction?.(value);\n\t\t\t\t\t},\n\t\t\t\t\t() => done(),\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\n\t\t// Only show image toggle if terminal supports it\n\t\tif (supportsImages) {\n\t\t\t// Insert after autocompact\n\t\t\titems.splice(1, 0, {\n\t\t\t\tid: \"show-images\",\n\t\t\t\tlabel: \"Show images\",\n\t\t\t\tdescription: \"Render images inline in terminal\",\n\t\t\t\tcurrentValue: config.showImages ? \"true\" : \"false\",\n\t\t\t\tvalues: [\"true\", \"false\"],\n\t\t\t});\n\t\t\titems.splice(2, 0, {\n\t\t\t\tid: \"image-width-cells\",\n\t\t\t\tlabel: \"Image width\",\n\t\t\t\tdescription: \"Preferred inline image width in terminal cells\",\n\t\t\t\tcurrentValue: String(config.imageWidthCells),\n\t\t\t\tvalues: [\"60\", \"80\", \"120\"],\n\t\t\t});\n\t\t}\n\n\t\t// Image auto-resize toggle (always available, affects both attached and read images)\n\t\titems.splice(supportsImages ? 3 : 1, 0, {\n\t\t\tid: \"auto-resize-images\",\n\t\t\tlabel: \"Auto-resize images\",\n\t\t\tdescription: \"Resize large images to 2000x2000 max for better model compatibility\",\n\t\t\tcurrentValue: config.autoResizeImages ? \"true\" : \"false\",\n\t\t\tvalues: [\"true\", \"false\"],\n\t\t});\n\n\t\t// Block images toggle (always available, insert after auto-resize-images)\n\t\tconst autoResizeIndex = items.findIndex((item) => item.id === \"auto-resize-images\");\n\t\titems.splice(autoResizeIndex + 1, 0, {\n\t\t\tid: \"block-images\",\n\t\t\tlabel: \"Block images\",\n\t\t\tdescription: \"Prevent images from being sent to LLM providers\",\n\t\t\tcurrentValue: config.blockImages ? \"true\" : \"false\",\n\t\t\tvalues: [\"true\", \"false\"],\n\t\t});\n\n\t\t// Skill commands toggle (insert after block-images)\n\t\tconst blockImagesIndex = items.findIndex((item) => item.id === \"block-images\");\n\t\titems.splice(blockImagesIndex + 1, 0, {\n\t\t\tid: \"skill-commands\",\n\t\t\tlabel: \"Skill commands\",\n\t\t\tdescription: \"Register skills as /skill:name commands\",\n\t\t\tcurrentValue: config.enableSkillCommands ? \"true\" : \"false\",\n\t\t\tvalues: [\"true\", \"false\"],\n\t\t});\n\n\t\t// Hardware cursor toggle (insert after skill-commands)\n\t\tconst skillCommandsIndex = items.findIndex((item) => item.id === \"skill-commands\");\n\t\titems.splice(skillCommandsIndex + 1, 0, {\n\t\t\tid: \"show-hardware-cursor\",\n\t\t\tlabel: \"Show hardware cursor\",\n\t\t\tdescription: \"Show the terminal cursor while still positioning it for IME support\",\n\t\t\tcurrentValue: config.showHardwareCursor ? \"true\" : \"false\",\n\t\t\tvalues: [\"true\", \"false\"],\n\t\t});\n\n\t\t// Editor padding toggle (insert after show-hardware-cursor)\n\t\tconst hardwareCursorIndex = items.findIndex((item) => item.id === \"show-hardware-cursor\");\n\t\titems.splice(hardwareCursorIndex + 1, 0, {\n\t\t\tid: \"editor-padding\",\n\t\t\tlabel: \"Editor padding\",\n\t\t\tdescription: \"Horizontal padding for input editor (0-3)\",\n\t\t\tcurrentValue: String(config.editorPaddingX),\n\t\t\tvalues: [\"0\", \"1\", \"2\", \"3\"],\n\t\t});\n\n\t\t// Autocomplete max visible toggle (insert after editor-padding)\n\t\tconst editorPaddingIndex = items.findIndex((item) => item.id === \"editor-padding\");\n\t\titems.splice(editorPaddingIndex + 1, 0, {\n\t\t\tid: \"autocomplete-max-visible\",\n\t\t\tlabel: \"Autocomplete max items\",\n\t\t\tdescription: \"Max visible items in autocomplete dropdown (3-20)\",\n\t\t\tcurrentValue: String(config.autocompleteMaxVisible),\n\t\t\tvalues: [\"3\", \"5\", \"7\", \"10\", \"15\", \"20\"],\n\t\t});\n\n\t\t// Clear on shrink toggle (insert after autocomplete-max-visible)\n\t\tconst autocompleteIndex = items.findIndex((item) => item.id === \"autocomplete-max-visible\");\n\t\titems.splice(autocompleteIndex + 1, 0, {\n\t\t\tid: \"clear-on-shrink\",\n\t\t\tlabel: \"Clear on shrink\",\n\t\t\tdescription: \"Clear empty rows when content shrinks (may cause flicker)\",\n\t\t\tcurrentValue: config.clearOnShrink ? \"true\" : \"false\",\n\t\t\tvalues: [\"true\", \"false\"],\n\t\t});\n\n\t\t// Terminal progress toggle (insert after clear-on-shrink)\n\t\tconst clearOnShrinkIndex = items.findIndex((item) => item.id === \"clear-on-shrink\");\n\t\titems.splice(clearOnShrinkIndex + 1, 0, {\n\t\t\tid: \"terminal-progress\",\n\t\t\tlabel: \"Terminal progress\",\n\t\t\tdescription: \"Show OSC 9;4 progress indicators in the terminal tab bar\",\n\t\t\tcurrentValue: config.showTerminalProgress ? \"true\" : \"false\",\n\t\t\tvalues: [\"true\", \"false\"],\n\t\t});\n\n\t\t// Add borders\n\t\tthis.addChild(new DynamicBorder());\n\n\t\tthis.settingsList = new SettingsList(\n\t\t\titems,\n\t\t\t10,\n\t\t\tgetSettingsListTheme(),\n\t\t\t(id, newValue) => {\n\t\t\t\tswitch (id) {\n\t\t\t\t\tcase \"autocompact\":\n\t\t\t\t\t\tcallbacks.onAutoCompactChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"show-images\":\n\t\t\t\t\t\tcallbacks.onShowImagesChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"image-width-cells\":\n\t\t\t\t\t\tcallbacks.onImageWidthCellsChange(parseInt(newValue, 10));\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"auto-resize-images\":\n\t\t\t\t\t\tcallbacks.onAutoResizeImagesChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"block-images\":\n\t\t\t\t\t\tcallbacks.onBlockImagesChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"skill-commands\":\n\t\t\t\t\t\tcallbacks.onEnableSkillCommandsChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"steering-mode\":\n\t\t\t\t\t\tcallbacks.onSteeringModeChange(newValue as \"all\" | \"one-at-a-time\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"follow-up-mode\":\n\t\t\t\t\t\tcallbacks.onFollowUpModeChange(newValue as \"all\" | \"one-at-a-time\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"transport\":\n\t\t\t\t\t\tcallbacks.onTransportChange(newValue as Transport);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"http-idle-timeout\": {\n\t\t\t\t\t\tconst choice = HTTP_IDLE_TIMEOUT_CHOICES.find((item) => item.label === newValue);\n\t\t\t\t\t\tif (choice) {\n\t\t\t\t\t\t\tcallbacks.onHttpIdleTimeoutMsChange(choice.timeoutMs);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"hide-thinking\":\n\t\t\t\t\t\tcallbacks.onHideThinkingBlockChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"collapse-changelog\":\n\t\t\t\t\t\tcallbacks.onCollapseChangelogChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"quiet-startup\":\n\t\t\t\t\t\tcallbacks.onQuietStartupChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"install-telemetry\":\n\t\t\t\t\t\tcallbacks.onEnableInstallTelemetryChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"double-escape-action\":\n\t\t\t\t\t\tcallbacks.onDoubleEscapeActionChange(newValue as \"fork\" | \"tree\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"tree-filter-mode\":\n\t\t\t\t\t\tcallbacks.onTreeFilterModeChange(\n\t\t\t\t\t\t\tnewValue as \"default\" | \"no-tools\" | \"user-only\" | \"labeled-only\" | \"all\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"show-hardware-cursor\":\n\t\t\t\t\t\tcallbacks.onShowHardwareCursorChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"editor-padding\":\n\t\t\t\t\t\tcallbacks.onEditorPaddingXChange(parseInt(newValue, 10));\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"autocomplete-max-visible\":\n\t\t\t\t\t\tcallbacks.onAutocompleteMaxVisibleChange(parseInt(newValue, 10));\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"clear-on-shrink\":\n\t\t\t\t\t\tcallbacks.onClearOnShrinkChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"terminal-progress\":\n\t\t\t\t\t\tcallbacks.onShowTerminalProgressChange(newValue === \"true\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t},\n\t\t\tcallbacks.onCancel,\n\t\t\t{ enableSearch: true },\n\t\t);\n\n\t\tthis.addChild(this.settingsList);\n\t\tthis.addChild(new DynamicBorder());\n\t}\n\n\tgetSettingsList(): SettingsList {\n\t\treturn this.settingsList;\n\t}\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Container, getCapabilities, getKeybindings, Input, SelectList, SettingsList, Spacer, Text, } from "@caupulican/pi-tui";
|
|
2
2
|
import { formatHttpIdleTimeoutMs, HTTP_IDLE_TIMEOUT_CHOICES } from "../../../core/http-dispatcher.js";
|
|
3
|
+
import { DEFAULT_AUTONOMY_MAX_STALL_TURNS } from "../../../core/settings-manager.js";
|
|
3
4
|
import { getSelectListTheme, getSettingsListTheme, theme } from "../theme/theme.js";
|
|
4
5
|
import { DynamicBorder } from "./dynamic-border.js";
|
|
5
6
|
import { keyDisplayText } from "./keybinding-hints.js";
|
|
@@ -8,6 +9,7 @@ const SETTINGS_SUBMENU_SELECT_LIST_LAYOUT = {
|
|
|
8
9
|
maxPrimaryColumnWidth: 32,
|
|
9
10
|
};
|
|
10
11
|
const AUTO_LEARN_CUSTOM_MODEL_VALUE = "__custom_auto_learn_model__";
|
|
12
|
+
const MODEL_ROUTER_UNSET_MODEL_VALUE = "__unset_model_router_model__";
|
|
11
13
|
const THINKING_DESCRIPTIONS = {
|
|
12
14
|
off: "No reasoning",
|
|
13
15
|
minimal: "Very brief reasoning (~1k tokens)",
|
|
@@ -17,6 +19,7 @@ const THINKING_DESCRIPTIONS = {
|
|
|
17
19
|
xhigh: "Maximum reasoning (~32k tokens)",
|
|
18
20
|
};
|
|
19
21
|
const AUTONOMY_MODES = ["off", "safe", "balanced", "full"];
|
|
22
|
+
const AUTONOMY_MAX_STALL_TURN_VALUES = ["0", "5", "10", "20", "30", "50"];
|
|
20
23
|
const AUTO_LEARN_DEFAULTS = {
|
|
21
24
|
model: "active",
|
|
22
25
|
longSessionMessages: 32,
|
|
@@ -58,7 +61,13 @@ function autonomyModeValue(settings) {
|
|
|
58
61
|
}
|
|
59
62
|
function autonomySummary(settings) {
|
|
60
63
|
const mode = autonomyModeValue(settings);
|
|
61
|
-
|
|
64
|
+
const rounds = settings.maxStallTurns ?? DEFAULT_AUTONOMY_MAX_STALL_TURNS;
|
|
65
|
+
const modeLabel = mode === "full" ? "standing autonomy" : mode;
|
|
66
|
+
return `${modeLabel}, ${rounds} rounds`;
|
|
67
|
+
}
|
|
68
|
+
function autonomyMaxStallTurnsValue(settings) {
|
|
69
|
+
const rounds = settings.maxStallTurns ?? DEFAULT_AUTONOMY_MAX_STALL_TURNS;
|
|
70
|
+
return String(rounds);
|
|
62
71
|
}
|
|
63
72
|
function autoLearnSummary(settings) {
|
|
64
73
|
return settings.enabled ? `enabled (${autoLearnModelValue(settings)})` : "disabled";
|
|
@@ -100,6 +109,49 @@ function buildAutoLearnModelOptions(settings, configuredModelOptions, currentMod
|
|
|
100
109
|
});
|
|
101
110
|
return options;
|
|
102
111
|
}
|
|
112
|
+
function buildModelRouterRoleModelOptions(options) {
|
|
113
|
+
const modelOptions = [];
|
|
114
|
+
const seen = new Set();
|
|
115
|
+
if (options.includeActive) {
|
|
116
|
+
modelOptions.push({
|
|
117
|
+
value: AUTO_LEARN_DEFAULTS.model,
|
|
118
|
+
label: "active",
|
|
119
|
+
description: options.currentModelPattern
|
|
120
|
+
? `Use the current session model (${options.currentModelPattern})`
|
|
121
|
+
: "Use the current session model",
|
|
122
|
+
});
|
|
123
|
+
seen.add(AUTO_LEARN_DEFAULTS.model);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
modelOptions.push({
|
|
127
|
+
value: MODEL_ROUTER_UNSET_MODEL_VALUE,
|
|
128
|
+
label: "(unset)",
|
|
129
|
+
description: options.unsetDescription ?? "Clear this model setting",
|
|
130
|
+
});
|
|
131
|
+
seen.add(MODEL_ROUTER_UNSET_MODEL_VALUE);
|
|
132
|
+
}
|
|
133
|
+
for (const option of options.configuredModelOptions ?? []) {
|
|
134
|
+
if (seen.has(option.value))
|
|
135
|
+
continue;
|
|
136
|
+
modelOptions.push(option);
|
|
137
|
+
seen.add(option.value);
|
|
138
|
+
}
|
|
139
|
+
const currentValue = options.currentValue?.trim();
|
|
140
|
+
if (currentValue && !seen.has(currentValue)) {
|
|
141
|
+
modelOptions.push({
|
|
142
|
+
value: currentValue,
|
|
143
|
+
label: currentValue,
|
|
144
|
+
description: "Current custom setting",
|
|
145
|
+
});
|
|
146
|
+
seen.add(currentValue);
|
|
147
|
+
}
|
|
148
|
+
modelOptions.push({
|
|
149
|
+
value: AUTO_LEARN_CUSTOM_MODEL_VALUE,
|
|
150
|
+
label: "Manual / custom…",
|
|
151
|
+
description: "Type a model pattern not listed above",
|
|
152
|
+
});
|
|
153
|
+
return modelOptions;
|
|
154
|
+
}
|
|
103
155
|
class TextInputSubmenu extends Container {
|
|
104
156
|
input;
|
|
105
157
|
constructor(title, description, currentValue, onSubmit, onCancel, emptyHint = "empty clears the setting") {
|
|
@@ -123,15 +175,22 @@ class TextInputSubmenu extends Container {
|
|
|
123
175
|
this.input.handleInput(data);
|
|
124
176
|
}
|
|
125
177
|
}
|
|
126
|
-
class
|
|
178
|
+
class ModelSelectionSubmenu extends Container {
|
|
127
179
|
searchInput;
|
|
128
180
|
selectList;
|
|
129
181
|
customInput = null;
|
|
130
|
-
constructor(options, currentValue, onSelect, onCancel
|
|
182
|
+
constructor(options, currentValue, onSelect, onCancel, labels = {
|
|
183
|
+
title: "Auto Learn Scavenger Model",
|
|
184
|
+
description: "Choose active or a model from currently configured subscription/API accounts. Type to filter; choose manual for a custom pattern.",
|
|
185
|
+
customTitle: "Custom Auto Learn Model",
|
|
186
|
+
customDescription: 'Enter "active" or a provider/model pattern like "openai/gpt-5.4".',
|
|
187
|
+
customEmptyHint: 'empty uses "active"',
|
|
188
|
+
customEmptyValue: AUTO_LEARN_DEFAULTS.model,
|
|
189
|
+
}) {
|
|
131
190
|
super();
|
|
132
|
-
this.addChild(new Text(theme.bold(theme.fg("accent",
|
|
191
|
+
this.addChild(new Text(theme.bold(theme.fg("accent", labels.title)), 0, 0));
|
|
133
192
|
this.addChild(new Spacer(1));
|
|
134
|
-
this.addChild(new Text(theme.fg("muted",
|
|
193
|
+
this.addChild(new Text(theme.fg("muted", labels.description), 0, 0));
|
|
135
194
|
this.addChild(new Spacer(1));
|
|
136
195
|
this.searchInput = new Input();
|
|
137
196
|
this.searchInput.focused = true;
|
|
@@ -144,11 +203,11 @@ class AutoLearnModelSelectionSubmenu extends Container {
|
|
|
144
203
|
}
|
|
145
204
|
this.selectList.onSelect = (item) => {
|
|
146
205
|
if (item.value === AUTO_LEARN_CUSTOM_MODEL_VALUE) {
|
|
147
|
-
this.customInput = new TextInputSubmenu(
|
|
148
|
-
onSelect(normalizeOptionalString(value) ??
|
|
206
|
+
this.customInput = new TextInputSubmenu(labels.customTitle, labels.customDescription, currentValue === labels.customEmptyValue ? "" : currentValue, (value) => {
|
|
207
|
+
onSelect(normalizeOptionalString(value) ?? labels.customEmptyValue ?? "");
|
|
149
208
|
}, () => {
|
|
150
209
|
this.customInput = null;
|
|
151
|
-
},
|
|
210
|
+
}, labels.customEmptyHint);
|
|
152
211
|
return;
|
|
153
212
|
}
|
|
154
213
|
onSelect(item.value);
|
|
@@ -243,7 +302,10 @@ class AutonomySettingsSubmenu extends Container {
|
|
|
243
302
|
scope;
|
|
244
303
|
constructor(settings, onChange, onCancel, scope = "global") {
|
|
245
304
|
super();
|
|
246
|
-
this.state = {
|
|
305
|
+
this.state = {
|
|
306
|
+
mode: autonomyModeValue(settings),
|
|
307
|
+
maxStallTurns: settings.maxStallTurns ?? DEFAULT_AUTONOMY_MAX_STALL_TURNS,
|
|
308
|
+
};
|
|
247
309
|
this.scope = scope;
|
|
248
310
|
const items = [
|
|
249
311
|
{
|
|
@@ -260,6 +322,13 @@ class AutonomySettingsSubmenu extends Container {
|
|
|
260
322
|
currentValue: autonomyModeValue(this.state),
|
|
261
323
|
values: AUTONOMY_MODES,
|
|
262
324
|
},
|
|
325
|
+
{
|
|
326
|
+
id: "autonomy-goal-loop-rounds",
|
|
327
|
+
label: "Goal loop rounds",
|
|
328
|
+
description: "Maximum provider rounds in one foreground goal loop before Pi stops continuing",
|
|
329
|
+
currentValue: autonomyMaxStallTurnsValue(this.state),
|
|
330
|
+
values: AUTONOMY_MAX_STALL_TURN_VALUES,
|
|
331
|
+
},
|
|
263
332
|
];
|
|
264
333
|
this.settingsList = new SettingsList(items, Math.min(items.length, 10), getSettingsListTheme(), (id, newValue) => {
|
|
265
334
|
switch (id) {
|
|
@@ -269,6 +338,9 @@ class AutonomySettingsSubmenu extends Container {
|
|
|
269
338
|
case "autonomy-mode":
|
|
270
339
|
this.state = { ...this.state, mode: newValue };
|
|
271
340
|
break;
|
|
341
|
+
case "autonomy-goal-loop-rounds":
|
|
342
|
+
this.state = { ...this.state, maxStallTurns: Number(newValue) };
|
|
343
|
+
break;
|
|
272
344
|
default:
|
|
273
345
|
return;
|
|
274
346
|
}
|
|
@@ -312,7 +384,7 @@ class AutoLearnSettingsSubmenu extends Container {
|
|
|
312
384
|
label: "Scavenger model",
|
|
313
385
|
description: modelDescription,
|
|
314
386
|
currentValue: autoLearnModelValue(this.state),
|
|
315
|
-
submenu: (_currentValue, done) => new
|
|
387
|
+
submenu: (_currentValue, done) => new ModelSelectionSubmenu(selectableModelOptions, autoLearnModelValue(this.state), (value) => {
|
|
316
388
|
this.state = { ...this.state, model: value };
|
|
317
389
|
onChange({ ...this.state }, this.scope);
|
|
318
390
|
done(autoLearnModelValue(this.state));
|
|
@@ -432,7 +504,7 @@ class ModelRouterSettingsSubmenu extends Container {
|
|
|
432
504
|
settingsList;
|
|
433
505
|
state;
|
|
434
506
|
scope;
|
|
435
|
-
constructor(settings, onChange, onCancel, scope = "global") {
|
|
507
|
+
constructor(settings, currentModelPattern, modelOptions, onChange, onCancel, scope = "global") {
|
|
436
508
|
super();
|
|
437
509
|
this.state = {
|
|
438
510
|
...settings,
|
|
@@ -440,6 +512,26 @@ class ModelRouterSettingsSubmenu extends Container {
|
|
|
440
512
|
learningModel: settings.learningModel ?? "active",
|
|
441
513
|
};
|
|
442
514
|
this.scope = scope;
|
|
515
|
+
const cheapModelOptions = buildModelRouterRoleModelOptions({
|
|
516
|
+
currentValue: this.state.cheapModel,
|
|
517
|
+
configuredModelOptions: modelOptions,
|
|
518
|
+
currentModelPattern,
|
|
519
|
+
includeActive: false,
|
|
520
|
+
unsetDescription: "Clear cheap routing model; research turns fall back to the active session model",
|
|
521
|
+
});
|
|
522
|
+
const expensiveModelOptions = buildModelRouterRoleModelOptions({
|
|
523
|
+
currentValue: this.state.expensiveModel,
|
|
524
|
+
configuredModelOptions: modelOptions,
|
|
525
|
+
currentModelPattern,
|
|
526
|
+
includeActive: false,
|
|
527
|
+
unsetDescription: "Clear expensive routing model; modify turns fall back to the active session model",
|
|
528
|
+
});
|
|
529
|
+
const learningModelOptions = buildModelRouterRoleModelOptions({
|
|
530
|
+
currentValue: this.state.learningModel,
|
|
531
|
+
configuredModelOptions: modelOptions,
|
|
532
|
+
currentModelPattern,
|
|
533
|
+
includeActive: true,
|
|
534
|
+
});
|
|
443
535
|
this.addChild(new Text(theme.bold(theme.fg("accent", "Model Router")), 0, 0));
|
|
444
536
|
this.addChild(new Spacer(1));
|
|
445
537
|
const items = [
|
|
@@ -460,35 +552,62 @@ class ModelRouterSettingsSubmenu extends Container {
|
|
|
460
552
|
{
|
|
461
553
|
id: "model-router-cheap",
|
|
462
554
|
label: "Cheap model",
|
|
463
|
-
description: "
|
|
555
|
+
description: "Pick the model for read-only, research, explanation, and question turns",
|
|
464
556
|
currentValue: optionalStringValue(this.state.cheapModel),
|
|
465
|
-
submenu: (_currentValue, done) => new
|
|
466
|
-
this.state = {
|
|
557
|
+
submenu: (_currentValue, done) => new ModelSelectionSubmenu(cheapModelOptions, this.state.cheapModel ?? MODEL_ROUTER_UNSET_MODEL_VALUE, (value) => {
|
|
558
|
+
this.state = {
|
|
559
|
+
...this.state,
|
|
560
|
+
cheapModel: value === MODEL_ROUTER_UNSET_MODEL_VALUE ? undefined : value,
|
|
561
|
+
};
|
|
467
562
|
onChange({ ...this.state }, this.scope);
|
|
468
563
|
done(optionalStringValue(this.state.cheapModel));
|
|
469
|
-
}, () => done()
|
|
564
|
+
}, () => done(), {
|
|
565
|
+
title: "Cheap / Research Model",
|
|
566
|
+
description: "Choose from models available through configured subscription/API accounts. Type to filter; manual is fallback.",
|
|
567
|
+
customTitle: "Custom Cheap / Research Model",
|
|
568
|
+
customDescription: "Enter a provider/model pattern from pi --list-models.",
|
|
569
|
+
customEmptyHint: "empty clears the setting",
|
|
570
|
+
customEmptyValue: MODEL_ROUTER_UNSET_MODEL_VALUE,
|
|
571
|
+
}),
|
|
470
572
|
},
|
|
471
573
|
{
|
|
472
574
|
id: "model-router-expensive",
|
|
473
575
|
label: "Expensive model",
|
|
474
|
-
description: "
|
|
576
|
+
description: "Pick the model for modify, implementation, and escalated tool-heavy turns",
|
|
475
577
|
currentValue: optionalStringValue(this.state.expensiveModel),
|
|
476
|
-
submenu: (_currentValue, done) => new
|
|
477
|
-
this.state = {
|
|
578
|
+
submenu: (_currentValue, done) => new ModelSelectionSubmenu(expensiveModelOptions, this.state.expensiveModel ?? MODEL_ROUTER_UNSET_MODEL_VALUE, (value) => {
|
|
579
|
+
this.state = {
|
|
580
|
+
...this.state,
|
|
581
|
+
expensiveModel: value === MODEL_ROUTER_UNSET_MODEL_VALUE ? undefined : value,
|
|
582
|
+
};
|
|
478
583
|
onChange({ ...this.state }, this.scope);
|
|
479
584
|
done(optionalStringValue(this.state.expensiveModel));
|
|
480
|
-
}, () => done()
|
|
585
|
+
}, () => done(), {
|
|
586
|
+
title: "Expensive / Modify Model",
|
|
587
|
+
description: "Choose from models available through configured subscription/API accounts. Type to filter; manual is fallback.",
|
|
588
|
+
customTitle: "Custom Expensive / Modify Model",
|
|
589
|
+
customDescription: "Enter a provider/model pattern from pi --list-models.",
|
|
590
|
+
customEmptyHint: "empty clears the setting",
|
|
591
|
+
customEmptyValue: MODEL_ROUTER_UNSET_MODEL_VALUE,
|
|
592
|
+
}),
|
|
481
593
|
},
|
|
482
594
|
{
|
|
483
595
|
id: "model-router-learning",
|
|
484
596
|
label: "Learning/reflection model",
|
|
485
|
-
description: "
|
|
597
|
+
description: "Pick the model for background reflection, learn, and skill-creator work; active uses the session model",
|
|
486
598
|
currentValue: optionalStringValue(this.state.learningModel, "active"),
|
|
487
|
-
submenu: (_currentValue, done) => new
|
|
488
|
-
this.state = { ...this.state, learningModel:
|
|
599
|
+
submenu: (_currentValue, done) => new ModelSelectionSubmenu(learningModelOptions, this.state.learningModel ?? AUTO_LEARN_DEFAULTS.model, (value) => {
|
|
600
|
+
this.state = { ...this.state, learningModel: value };
|
|
489
601
|
onChange({ ...this.state }, this.scope);
|
|
490
602
|
done(optionalStringValue(this.state.learningModel, "active"));
|
|
491
|
-
}, () => done(),
|
|
603
|
+
}, () => done(), {
|
|
604
|
+
title: "Learning / Reflection Model",
|
|
605
|
+
description: "Choose active or a model from configured subscription/API accounts. Type to filter; manual is fallback.",
|
|
606
|
+
customTitle: "Custom Learning / Reflection Model",
|
|
607
|
+
customDescription: 'Enter "active" or a provider/model pattern from pi --list-models.',
|
|
608
|
+
customEmptyHint: 'empty uses "active"',
|
|
609
|
+
customEmptyValue: AUTO_LEARN_DEFAULTS.model,
|
|
610
|
+
}),
|
|
492
611
|
},
|
|
493
612
|
];
|
|
494
613
|
this.settingsList = new SettingsList(items, Math.min(items.length, 10), getSettingsListTheme(), (id, newValue) => {
|
|
@@ -705,7 +824,7 @@ export class SettingsSelectorComponent extends Container {
|
|
|
705
824
|
label: "Model Router",
|
|
706
825
|
description: "Configure models for cheap research, expensive modify/escalation, and background learning/reflection",
|
|
707
826
|
currentValue: modelRouterSummary(currentModelRouter),
|
|
708
|
-
submenu: (_currentValue, done) => new ModelRouterSettingsSubmenu(currentModelRouter, (settings, scope) => {
|
|
827
|
+
submenu: (_currentValue, done) => new ModelRouterSettingsSubmenu(currentModelRouter, config.currentModelPattern, config.autoLearnModelOptions, (settings, scope) => {
|
|
709
828
|
currentModelRouter = { ...settings };
|
|
710
829
|
callbacks.onModelRouterChange(settings, scope);
|
|
711
830
|
}, () => done(modelRouterSummary(currentModelRouter)), config.modelRouterScope ?? "global"),
|