@dreb/coding-agent 2.59.2 → 2.60.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -69,7 +69,12 @@ export interface SubagentArbiterSettings {
69
69
  export interface ModelSpecificSettings {
70
70
  /** Thinking display preference for this model: "summarized" shows thinking text, "omitted" hides it (lower latency). */
71
71
  thinkingDisplay?: "summarized" | "omitted";
72
+ /** Custom system prompt for an exact provider/model key. Replaces dreb's built-in prompt. */
73
+ systemPrompt?: string;
74
+ /** Text appended to the system prompt for an exact provider/model key. */
75
+ appendSystemPrompt?: string;
72
76
  }
77
+ export type ModelPromptSettings = Pick<ModelSpecificSettings, "systemPrompt" | "appendSystemPrompt">;
73
78
  export type TransportSetting = Transport;
74
79
  /**
75
80
  * Package source for npm/git packages.
@@ -362,11 +367,18 @@ export declare class SettingsManager {
362
367
  setAgentModelsForAgent(agentName: string, models: string[]): void;
363
368
  removeAgentModelsForAgent(agentName: string): void;
364
369
  /**
365
- * Per-model settings merged global + project at the per-model-id level, with project
366
- * winning per key. Reading directly from globalSettings/projectSettings avoids the
367
- * wholesale replacement that deepMergeSettings would do for the shared `modelSettings` key.
370
+ * Per-model settings merged global + project at the entry-key level, with project
371
+ * winning per property. Entry keys are bare model IDs for legacy settings or canonical
372
+ * provider/model references for provider-aware settings. Reading directly from the two
373
+ * scopes avoids wholesale replacement of the shared `modelSettings` object.
368
374
  */
369
- getModelSettings(modelId: string): ModelSpecificSettings | undefined;
375
+ getModelSettings(modelKey: string): ModelSpecificSettings | undefined;
376
+ /**
377
+ * Resolve prompt settings for one exact provider/model pair. Prompt settings deliberately
378
+ * do not fall back to the legacy bare-model-id keys used by thinkingDisplay because that
379
+ * would leak instructions across providers exposing the same model ID.
380
+ */
381
+ getModelPromptSettings(provider: string, modelId: string): ModelPromptSettings | undefined;
370
382
  getModelThinkingDisplay(modelId: string): "summarized" | "omitted" | undefined;
371
383
  setModelThinkingDisplay(modelId: string, value: "summarized" | "omitted" | undefined): void;
372
384
  getTabTitleSettings(): TabTitleSettings | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"settings-manager.d.ts","sourceRoot":"","sources":["../../src/core/settings-manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAK1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAI7D,MAAM,WAAW,kBAAkB;IAClC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,eAAe;IAC/B;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,4FAA4F;IAC5F,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACrC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAC9C,eAAO,MAAM,gCAAgC,IAAI,CAAC;AAElD,MAAM,WAAW,wBAAwB;IACxC;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,4FAA4F;IAC5F,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4GAA4G;IAC5G,sBAAsB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,gBAAgB;IAChC,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC7B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,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,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAG9D;IAED;;;;OAIG;IACH,4BAA4B,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAEvD;IAED,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAUhE;IAED,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAMjD;IAED;;;;OAIG;IACH,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CAOnE;IAED,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,GAAG,SAAS,CAE7E;IAED,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,SAAS,GAAG,SAAS,GAAG,IAAI,CAuB1F;IAED,mBAAmB,IAAI,gBAAgB,GAAG,SAAS,CAElD;CACD","sourcesContent":["import { homedir } from \"node:os\";\nimport type { Transport } from \"@dreb/ai\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\";\nimport { dirname, join, resolve } from \"path\";\nimport lockfile from \"proper-lockfile\";\nimport { CONFIG_DIR_NAME, getAgentDir } from \"../config.js\";\nimport type { ContextTrustPolicy } from \"./context-trust.js\";\nimport { log } from \"./logger.js\";\nimport { expandPath } from \"./tools/path-utils.js\";\n\nexport interface CompactionSettings {\n\tenabled?: boolean; // default: true\n\treserveTokens?: number; // default: 16384\n\tkeepRecentTokens?: number; // default: 20000\n}\n\nexport interface ContextSettings {\n\t/**\n\t * Expert-only global opt-in to lazy-load nested context from every strictly resolvable\n\t * tool target. This is disabled by default because context files can contain prompt\n\t * injection. Project settings cannot affect this policy.\n\t */\n\tautoLoadNested?: boolean;\n\t/** Global-only folder roots allowed to lazy-load context for themselves and descendants. */\n\ttrustedFolders?: string[];\n}\n\nexport interface BranchSummarySettings {\n\treserveTokens?: number; // default: 16384 (tokens reserved for prompt + LLM response)\n\tskipPrompt?: boolean; // default: false - when true, skips \"Summarize branch?\" prompt and defaults to no summary\n}\n\nexport interface RetrySettings {\n\tenabled?: boolean; // default: true\n\tmaxRetries?: number; // default: 3\n\tbaseDelayMs?: number; // default: 2000 (exponential backoff: 2s, 4s, 8s)\n\tmaxDelayMs?: number; // default: 60000 (max server-requested delay before failing)\n}\n\nexport const DEFAULT_BG_PARENT_TURN_LIMIT = 3;\nexport const DEFAULT_MAX_CONCURRENT_SUBAGENTS = 4;\n\nexport interface BackgroundAgentsSettings {\n\t/**\n\t * Whether the parent agent is paused after `parentTurnLimit` turns while background\n\t * agents are still running. Disable (false) to let the parent keep running while\n\t * subagents work — an advanced opt-out with no upper bound on parent turns. default: true\n\t */\n\tparentTurnGuardrail?: boolean;\n\t/** Number of parent turns allowed while background agents run before pausing. default: 3 */\n\tparentTurnLimit?: number;\n\t/** Maximum child agents that one parent session may run concurrently. Zero disables the tool. default: 4 */\n\tmaxConcurrentSubagents?: number;\n}\n\nexport interface TerminalSettings {\n\tshowImages?: boolean; // default: true (only relevant if terminal supports images)\n}\n\nexport interface ImageSettings {\n\tautoResize?: boolean; // default: true (resize images to 2000x2000 max for better model compatibility)\n\tblockImages?: boolean; // default: false - when true, prevents all images from being sent to LLM providers\n}\n\nexport interface ThinkingBudgetsSettings {\n\tminimal?: number;\n\tlow?: number;\n\tmedium?: number;\n\thigh?: number;\n}\n\nexport interface MarkdownSettings {\n\tcodeBlockIndent?: string; // default: \" \"\n}\n\nexport interface AgentModelsSettings {\n\tmodels?: Record<string, string[]>;\n}\n\n/** Global-only configuration for the fail-closed pre-spawn Dispatch Arbiter. */\nexport interface SubagentArbiterSettings {\n\tenabled?: boolean;\n\t/** Exact canonical provider/model used for the tool-less arbiter call. */\n\tmodel?: string;\n\tthinking?: \"off\" | \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\";\n\tguidePath?: string;\n}\n\nexport interface ModelSpecificSettings {\n\t/** Thinking display preference for this model: \"summarized\" shows thinking text, \"omitted\" hides it (lower latency). */\n\tthinkingDisplay?: \"summarized\" | \"omitted\";\n}\n\nexport type TransportSetting = Transport;\n\n/**\n * Package source for npm/git packages.\n * - String form: load all resources from the package\n * - Object form: filter which resources to load\n */\nexport type PackageSource =\n\t| string\n\t| {\n\t\t\tsource: string;\n\t\t\textensions?: string[];\n\t\t\tskills?: string[];\n\t\t\tprompts?: string[];\n\t\t\tthemes?: string[];\n\t };\n\nexport interface Settings {\n\tdefaultProvider?: string;\n\tdefaultModel?: string;\n\tdefaultThinkingLevel?: \"off\" | \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\";\n\ttransport?: TransportSetting; // default: \"sse\"\n\tsteeringMode?: \"all\" | \"one-at-a-time\";\n\tfollowUpMode?: \"all\" | \"one-at-a-time\";\n\ttheme?: string;\n\tcompaction?: CompactionSettings;\n\tcontext?: ContextSettings;\n\tbranchSummary?: BranchSummarySettings;\n\tretry?: RetrySettings;\n\tbackgroundAgents?: BackgroundAgentsSettings;\n\thideThinkingBlock?: boolean;\n\tshellPath?: string; // Custom shell path (e.g., for Cygwin users on Windows)\n\tquietStartup?: boolean;\n\tshellCommandPrefix?: string; // Prefix prepended to every bash command (e.g., \"shopt -s expand_aliases\" for alias support)\n\tnpmCommand?: string[]; // Command used for npm package lookup/install operations, argv-style (e.g., [\"mise\", \"exec\", \"node@20\", \"--\", \"npm\"])\n\tpackages?: PackageSource[]; // Array of npm/git package sources (string or object with filtering)\n\textensions?: string[]; // Array of local extension file paths or directories\n\tskills?: string[]; // Array of local skill file paths or directories\n\tprompts?: string[]; // Array of local prompt template paths or directories\n\tthemes?: string[]; // Array of local theme file paths or directories\n\tenableSkillCommands?: boolean; // default: true - register skills as /skill:name commands\n\tterminal?: TerminalSettings;\n\timages?: ImageSettings;\n\tenabledModels?: string[]; // Model patterns for cycling (same format as --models CLI flag)\n\tdoubleEscapeAction?: \"fork\" | \"tree\" | \"none\"; // Action for double-escape with empty editor (default: \"tree\")\n\ttreeFilterMode?: \"default\" | \"no-tools\" | \"user-only\" | \"labeled-only\" | \"all\"; // Default filter when opening /tree\n\tthinkingBudgets?: ThinkingBudgetsSettings; // Custom token budgets for thinking levels\n\teditorPaddingX?: number; // Horizontal padding for input editor (default: 0)\n\tautocompleteMaxVisible?: number; // Max visible items in autocomplete dropdown (default: 5)\n\tshowHardwareCursor?: boolean; // Show terminal cursor while still positioning it for IME\n\tmarkdown?: MarkdownSettings;\n\tsessionDir?: string; // Custom session storage directory (same format as --session-dir CLI flag)\n\tforbiddenCommands?: string[]; // Regex patterns for commands blocked by the forbidden-commands guard\n\tsensitiveFilePaths?: string[]; // Additional glob patterns for sensitive file paths blocked by the read/bash guard\n\tsecretOutputPatterns?: { name: string; pattern: string }[]; // Additional regex patterns for secret scrubbing in tool output\n\tagentModels?: AgentModelsSettings;\n\t/** Global-only. Project settings must never enable or reconfigure arbitration. */\n\tsubagentArbiter?: SubagentArbiterSettings;\n\t// Per-model overrides keyed by model id (e.g. thinking display). Read identically by main sessions and subagents.\n\tmodelSettings?: Record<string, ModelSpecificSettings>;\n\tdream?: {\n\t\tarchivePath?: string; // Custom archive location for dream backups (default: ~/.dreb/memory-archive/)\n\t};\n\ttabTitle?: TabTitleSettings;\n}\n\nexport interface TabTitleSettings {\n\tenabled?: boolean; // default: true — auto-generate terminal tab title from session task\n\ttriggerAfter?: number; // default: 9 — number of tool calls before generating title\n\tmaxTitleLength?: number; // default: 60 — soft target length hint for generated titles (hard-capped at 300)\n}\n\n/** Deep merge settings: project/overrides take precedence, nested objects merge recursively */\nfunction deepMergeSettings(base: Settings, overrides: Settings): Settings {\n\tconst result: Settings = { ...base };\n\n\tfor (const key of Object.keys(overrides) as (keyof Settings)[]) {\n\t\tconst overrideValue = overrides[key];\n\t\tconst baseValue = base[key];\n\n\t\tif (overrideValue === undefined) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// For nested objects, merge recursively\n\t\tif (\n\t\t\ttypeof overrideValue === \"object\" &&\n\t\t\toverrideValue !== null &&\n\t\t\t!Array.isArray(overrideValue) &&\n\t\t\ttypeof baseValue === \"object\" &&\n\t\t\tbaseValue !== null &&\n\t\t\t!Array.isArray(baseValue)\n\t\t) {\n\t\t\t(result as Record<string, unknown>)[key] = { ...baseValue, ...overrideValue };\n\t\t} else {\n\t\t\t// For primitives and arrays, override value wins\n\t\t\t(result as Record<string, unknown>)[key] = overrideValue;\n\t\t}\n\t}\n\n\treturn result;\n}\n\nexport type SettingsScope = \"global\" | \"project\";\n\nexport interface SettingsStorage {\n\twithLock(scope: SettingsScope, fn: (current: string | undefined) => string | undefined): void;\n}\n\nexport interface SettingsError {\n\tscope: SettingsScope;\n\terror: Error;\n}\n\nexport class FileSettingsStorage implements SettingsStorage {\n\tprivate globalSettingsPath: string;\n\tprivate projectSettingsPath: string;\n\n\tconstructor(cwd: string = process.cwd(), agentDir: string = getAgentDir()) {\n\t\tthis.globalSettingsPath = join(agentDir, \"settings.json\");\n\t\tthis.projectSettingsPath = join(cwd, CONFIG_DIR_NAME, \"settings.json\");\n\t}\n\n\tprivate acquireLockSyncWithRetry(path: string): () => void {\n\t\tconst maxAttempts = 10;\n\t\tconst delayMs = 20;\n\t\tlet lastError: unknown;\n\n\t\tfor (let attempt = 1; attempt <= maxAttempts; attempt++) {\n\t\t\ttry {\n\t\t\t\treturn lockfile.lockSync(path, { realpath: false });\n\t\t\t} catch (error) {\n\t\t\t\tconst code =\n\t\t\t\t\ttypeof error === \"object\" && error !== null && \"code\" in error\n\t\t\t\t\t\t? String((error as { code?: unknown }).code)\n\t\t\t\t\t\t: undefined;\n\t\t\t\tif (code !== \"ELOCKED\" || attempt === maxAttempts) {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tlastError = error;\n\t\t\t\tconst start = Date.now();\n\t\t\t\twhile (Date.now() - start < delayMs) {\n\t\t\t\t\t// Sleep synchronously to avoid changing callers to async.\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthrow (lastError as Error) ?? new Error(\"Failed to acquire settings lock\");\n\t}\n\n\twithLock(scope: SettingsScope, fn: (current: string | undefined) => string | undefined): void {\n\t\tconst path = scope === \"global\" ? this.globalSettingsPath : this.projectSettingsPath;\n\t\tconst dir = dirname(path);\n\n\t\tlet release: (() => void) | undefined;\n\t\ttry {\n\t\t\t// Only create directory and lock if file exists or we need to write\n\t\t\tconst fileExists = existsSync(path);\n\t\t\tif (fileExists) {\n\t\t\t\trelease = this.acquireLockSyncWithRetry(path);\n\t\t\t}\n\t\t\tconst current = fileExists ? readFileSync(path, \"utf-8\") : undefined;\n\t\t\tconst next = fn(current);\n\t\t\tif (next !== undefined) {\n\t\t\t\t// Only create directory when we actually need to write\n\t\t\t\tif (!existsSync(dir)) {\n\t\t\t\t\tmkdirSync(dir, { recursive: true });\n\t\t\t\t}\n\t\t\t\tif (!release) {\n\t\t\t\t\trelease = this.acquireLockSyncWithRetry(path);\n\t\t\t\t}\n\t\t\t\twriteFileSync(path, next, \"utf-8\");\n\t\t\t}\n\t\t} finally {\n\t\t\tif (release) {\n\t\t\t\trelease();\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport class InMemorySettingsStorage implements SettingsStorage {\n\tprivate global: string | undefined;\n\tprivate project: string | undefined;\n\n\twithLock(scope: SettingsScope, fn: (current: string | undefined) => string | undefined): void {\n\t\tconst current = scope === \"global\" ? this.global : this.project;\n\t\tconst next = fn(current);\n\t\tif (next !== undefined) {\n\t\t\tif (scope === \"global\") {\n\t\t\t\tthis.global = next;\n\t\t\t} else {\n\t\t\t\tthis.project = next;\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport class SettingsManager {\n\tprivate storage: SettingsStorage;\n\tprivate globalSettings: Settings;\n\tprivate projectSettings: Settings;\n\tprivate settings: Settings;\n\tprivate modifiedFields = new Set<keyof Settings>(); // Track global fields modified during session\n\tprivate modifiedNestedFields = new Map<keyof Settings, Set<string>>(); // Track global nested field modifications\n\tprivate modifiedProjectFields = new Set<keyof Settings>(); // Track project fields modified during session\n\tprivate modifiedProjectNestedFields = new Map<keyof Settings, Set<string>>(); // Track project nested field modifications\n\tprivate globalSettingsLoadError: Error | null = null; // Track if global settings file had parse errors\n\tprivate projectSettingsLoadError: Error | null = null; // Track if project settings file had parse errors\n\tprivate writeQueue: Promise<void> = Promise.resolve();\n\tprivate errors: SettingsError[];\n\n\tprivate constructor(\n\t\tstorage: SettingsStorage,\n\t\tinitialGlobal: Settings,\n\t\tinitialProject: Settings,\n\t\tglobalLoadError: Error | null = null,\n\t\tprojectLoadError: Error | null = null,\n\t\tinitialErrors: SettingsError[] = [],\n\t) {\n\t\tthis.storage = storage;\n\t\tthis.globalSettings = initialGlobal;\n\t\tthis.projectSettings = initialProject;\n\t\tthis.globalSettingsLoadError = globalLoadError;\n\t\tthis.projectSettingsLoadError = projectLoadError;\n\t\tthis.errors = [...initialErrors];\n\t\tthis.settings = deepMergeSettings(this.globalSettings, this.projectSettings);\n\t}\n\n\t/** Create a SettingsManager that loads from files */\n\tstatic create(cwd: string = process.cwd(), agentDir: string = getAgentDir()): SettingsManager {\n\t\tconst storage = new FileSettingsStorage(cwd, agentDir);\n\t\treturn SettingsManager.fromStorage(storage);\n\t}\n\n\t/** Create a SettingsManager from an arbitrary storage backend */\n\tstatic fromStorage(storage: SettingsStorage): SettingsManager {\n\t\tconst globalLoad = SettingsManager.tryLoadFromStorage(storage, \"global\");\n\t\tconst projectLoad = SettingsManager.tryLoadFromStorage(storage, \"project\");\n\t\tconst initialErrors: SettingsError[] = [];\n\t\tif (globalLoad.error) {\n\t\t\tinitialErrors.push({ scope: \"global\", error: globalLoad.error });\n\t\t}\n\t\tif (projectLoad.error) {\n\t\t\tinitialErrors.push({ scope: \"project\", error: projectLoad.error });\n\t\t}\n\n\t\treturn new SettingsManager(\n\t\t\tstorage,\n\t\t\tglobalLoad.settings,\n\t\t\tprojectLoad.settings,\n\t\t\tglobalLoad.error,\n\t\t\tprojectLoad.error,\n\t\t\tinitialErrors,\n\t\t);\n\t}\n\n\t/** Create an in-memory SettingsManager (no file I/O) */\n\tstatic inMemory(settings: Partial<Settings> = {}): SettingsManager {\n\t\tconst storage = new InMemorySettingsStorage();\n\t\treturn new SettingsManager(storage, settings, {});\n\t}\n\n\tprivate static loadFromStorage(storage: SettingsStorage, scope: SettingsScope): Settings {\n\t\tlet content: string | undefined;\n\t\tstorage.withLock(scope, (current) => {\n\t\t\tcontent = current;\n\t\t\treturn undefined;\n\t\t});\n\n\t\tif (!content) {\n\t\t\treturn {};\n\t\t}\n\t\tconst settings = JSON.parse(content);\n\t\treturn SettingsManager.migrateSettings(settings);\n\t}\n\n\tprivate static tryLoadFromStorage(\n\t\tstorage: SettingsStorage,\n\t\tscope: SettingsScope,\n\t): { settings: Settings; error: Error | null } {\n\t\ttry {\n\t\t\treturn { settings: SettingsManager.loadFromStorage(storage, scope), error: null };\n\t\t} catch (error) {\n\t\t\treturn { settings: {}, error: error as Error };\n\t\t}\n\t}\n\n\t/**\n\t * Normalize the two known lazy-context trust fields of a `context` slice to fail-closed\n\t * defaults when malformed, preserving valid values and any unrelated keys. Used at persist\n\t * time so a single-field trust write cannot leave a malformed sibling (read fresh from disk)\n\t * that would invalidate — and therefore silently disable — the entire trust policy.\n\t */\n\tprivate static sanitizeContextTrustSlice(nested: Record<string, unknown>): Record<string, unknown> {\n\t\tconst sanitized = { ...nested };\n\t\tif (\"autoLoadNested\" in sanitized && typeof sanitized.autoLoadNested !== \"boolean\") {\n\t\t\tsanitized.autoLoadNested = false;\n\t\t}\n\t\tif (\n\t\t\t\"trustedFolders\" in sanitized &&\n\t\t\t(!Array.isArray(sanitized.trustedFolders) ||\n\t\t\t\tsanitized.trustedFolders.some((folder) => typeof folder !== \"string\"))\n\t\t) {\n\t\t\tsanitized.trustedFolders = [];\n\t\t}\n\t\treturn sanitized;\n\t}\n\n\t/** Migrate old settings format to new format */\n\tprivate static migrateSettings(settings: Record<string, unknown>): Settings {\n\t\t// Migrate queueMode -> steeringMode\n\t\tif (\"queueMode\" in settings && !(\"steeringMode\" in settings)) {\n\t\t\tsettings.steeringMode = settings.queueMode;\n\t\t\tdelete settings.queueMode;\n\t\t}\n\n\t\t// Migrate legacy websockets boolean -> transport enum\n\t\tif (!(\"transport\" in settings) && typeof settings.websockets === \"boolean\") {\n\t\t\tsettings.transport = settings.websockets ? \"websocket\" : \"sse\";\n\t\t\tdelete settings.websockets;\n\t\t}\n\n\t\t// Migrate old skills object format to new array format\n\t\tif (\n\t\t\t\"skills\" in settings &&\n\t\t\ttypeof settings.skills === \"object\" &&\n\t\t\tsettings.skills !== null &&\n\t\t\t!Array.isArray(settings.skills)\n\t\t) {\n\t\t\tconst skillsSettings = settings.skills as {\n\t\t\t\tenableSkillCommands?: boolean;\n\t\t\t\tcustomDirectories?: unknown;\n\t\t\t};\n\t\t\tif (skillsSettings.enableSkillCommands !== undefined && settings.enableSkillCommands === undefined) {\n\t\t\t\tsettings.enableSkillCommands = skillsSettings.enableSkillCommands;\n\t\t\t}\n\t\t\tif (Array.isArray(skillsSettings.customDirectories) && skillsSettings.customDirectories.length > 0) {\n\t\t\t\tsettings.skills = skillsSettings.customDirectories;\n\t\t\t} else {\n\t\t\t\tdelete settings.skills;\n\t\t\t}\n\t\t}\n\n\t\treturn settings as Settings;\n\t}\n\n\tgetGlobalSettings(): Settings {\n\t\treturn structuredClone(this.globalSettings);\n\t}\n\n\tgetProjectSettings(): Settings {\n\t\treturn structuredClone(this.projectSettings);\n\t}\n\n\treload(): void {\n\t\tconst globalLoad = SettingsManager.tryLoadFromStorage(this.storage, \"global\");\n\t\tif (!globalLoad.error) {\n\t\t\tthis.globalSettings = globalLoad.settings;\n\t\t\tthis.globalSettingsLoadError = null;\n\t\t} else {\n\t\t\tthis.globalSettingsLoadError = globalLoad.error;\n\t\t\tthis.recordError(\"global\", globalLoad.error);\n\t\t}\n\n\t\tthis.modifiedFields.clear();\n\t\tthis.modifiedNestedFields.clear();\n\t\tthis.modifiedProjectFields.clear();\n\t\tthis.modifiedProjectNestedFields.clear();\n\n\t\tconst projectLoad = SettingsManager.tryLoadFromStorage(this.storage, \"project\");\n\t\tif (!projectLoad.error) {\n\t\t\tthis.projectSettings = projectLoad.settings;\n\t\t\tthis.projectSettingsLoadError = null;\n\t\t} else {\n\t\t\tthis.projectSettingsLoadError = projectLoad.error;\n\t\t\tthis.recordError(\"project\", projectLoad.error);\n\t\t}\n\n\t\tthis.settings = deepMergeSettings(this.globalSettings, this.projectSettings);\n\t}\n\n\t/** Apply additional overrides on top of current settings */\n\tapplyOverrides(overrides: Partial<Settings>): void {\n\t\tthis.settings = deepMergeSettings(this.settings, overrides);\n\t}\n\n\t/** Mark a global field as modified during this session */\n\tprivate markModified(field: keyof Settings, nestedKey?: string): void {\n\t\tthis.modifiedFields.add(field);\n\t\tif (nestedKey) {\n\t\t\tif (!this.modifiedNestedFields.has(field)) {\n\t\t\t\tthis.modifiedNestedFields.set(field, new Set());\n\t\t\t}\n\t\t\tthis.modifiedNestedFields.get(field)!.add(nestedKey);\n\t\t}\n\t}\n\n\t/** Mark a project field as modified during this session */\n\tprivate markProjectModified(field: keyof Settings, nestedKey?: string): void {\n\t\tthis.modifiedProjectFields.add(field);\n\t\tif (nestedKey) {\n\t\t\tif (!this.modifiedProjectNestedFields.has(field)) {\n\t\t\t\tthis.modifiedProjectNestedFields.set(field, new Set());\n\t\t\t}\n\t\t\tthis.modifiedProjectNestedFields.get(field)!.add(nestedKey);\n\t\t}\n\t}\n\n\tprivate recordError(scope: SettingsScope, error: unknown): void {\n\t\tconst normalizedError = error instanceof Error ? error : new Error(String(error));\n\t\tthis.errors.push({ scope, error: normalizedError });\n\t}\n\n\tprivate refreshGlobalContextFromStorage(options: { clearContextOnError?: boolean } = {}): boolean {\n\t\t// Keep a just-selected UI value effective until its queued durable write completes;\n\t\t// otherwise always re-read the external global source for cross-process changes.\n\t\tif (this.storage instanceof InMemorySettingsStorage || this.modifiedFields.has(\"context\")) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst loaded = SettingsManager.tryLoadFromStorage(this.storage, \"global\");\n\t\tif (loaded.error) {\n\t\t\tthis.recordError(\"global\", loaded.error);\n\t\t\tif (options.clearContextOnError) {\n\t\t\t\tthis.globalSettings = { ...this.globalSettings, context: undefined };\n\t\t\t\tthis.settings = deepMergeSettings(this.globalSettings, this.projectSettings);\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\n\t\t// This re-read owns only the security-policy slice. Preserve every other\n\t\t// in-memory global field, including writes that are queued but not yet durable.\n\t\tthis.globalSettings = { ...this.globalSettings, context: loaded.settings.context };\n\t\tthis.settings = deepMergeSettings(this.globalSettings, this.projectSettings);\n\t\treturn true;\n\t}\n\n\tprivate refreshGlobalSubagentArbiterFromStorage(): void {\n\t\t// Keep a locally selected policy effective until its queued write completes;\n\t\t// otherwise re-read the global slice so long-lived sessions observe dashboard\n\t\t// and TUI changes made by another runtime.\n\t\tif (this.storage instanceof InMemorySettingsStorage || this.modifiedFields.has(\"subagentArbiter\")) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst loaded = SettingsManager.tryLoadFromStorage(this.storage, \"global\");\n\t\tif (loaded.error) {\n\t\t\tthis.recordError(\"global\", loaded.error);\n\t\t\tthis.globalSettings = { ...this.globalSettings, subagentArbiter: undefined };\n\t\t\tthis.settings = deepMergeSettings(this.globalSettings, this.projectSettings);\n\t\t\tthrow new Error(`Could not reload global Dispatch Arbiter settings: ${loaded.error.message}`);\n\t\t}\n\n\t\t// This refresh owns only the global-only arbiter slice. Preserve unrelated\n\t\t// in-memory settings, including writes that are queued but not yet durable.\n\t\tthis.globalSettings = { ...this.globalSettings, subagentArbiter: loaded.settings.subagentArbiter };\n\t\tthis.settings = deepMergeSettings(this.globalSettings, this.projectSettings);\n\t}\n\n\tprivate clearModifiedScope(scope: SettingsScope): void {\n\t\tif (scope === \"global\") {\n\t\t\tthis.modifiedFields.clear();\n\t\t\tthis.modifiedNestedFields.clear();\n\t\t\treturn;\n\t\t}\n\n\t\tthis.modifiedProjectFields.clear();\n\t\tthis.modifiedProjectNestedFields.clear();\n\t}\n\n\tprivate enqueueWrite(scope: SettingsScope, task: () => void): void {\n\t\tthis.writeQueue = this.writeQueue\n\t\t\t.then(() => {\n\t\t\t\ttask();\n\t\t\t\tthis.clearModifiedScope(scope);\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tthis.recordError(scope, error);\n\t\t\t});\n\t}\n\n\tprivate cloneModifiedNestedFields(source: Map<keyof Settings, Set<string>>): Map<keyof Settings, Set<string>> {\n\t\tconst snapshot = new Map<keyof Settings, Set<string>>();\n\t\tfor (const [key, value] of source.entries()) {\n\t\t\tsnapshot.set(key, new Set(value));\n\t\t}\n\t\treturn snapshot;\n\t}\n\n\tprivate persistScopedSettings(\n\t\tscope: SettingsScope,\n\t\tsnapshotSettings: Settings,\n\t\tmodifiedFields: Set<keyof Settings>,\n\t\tmodifiedNestedFields: Map<keyof Settings, Set<string>>,\n\t): void {\n\t\tthis.storage.withLock(scope, (current) => {\n\t\t\tconst currentFileSettings = current\n\t\t\t\t? SettingsManager.migrateSettings(JSON.parse(current) as Record<string, unknown>)\n\t\t\t\t: {};\n\t\t\tconst mergedSettings: Settings = { ...currentFileSettings };\n\t\t\tfor (const field of modifiedFields) {\n\t\t\t\tconst value = snapshotSettings[field];\n\t\t\t\tif (modifiedNestedFields.has(field) && typeof value === \"object\" && value !== null) {\n\t\t\t\t\tconst nestedModified = modifiedNestedFields.get(field)!;\n\t\t\t\t\tconst baseNested = (currentFileSettings[field] as Record<string, unknown>) ?? {};\n\t\t\t\t\tconst inMemoryNested = value as Record<string, unknown>;\n\t\t\t\t\tlet mergedNested = { ...baseNested };\n\t\t\t\t\tfor (const nestedKey of nestedModified) {\n\t\t\t\t\t\tmergedNested[nestedKey] = inMemoryNested[nestedKey];\n\t\t\t\t\t}\n\t\t\t\t\t// The global context-trust slice is security-sensitive: an untouched sibling\n\t\t\t\t\t// is preserved from the fresh on-disk read above, but a malformed on-disk\n\t\t\t\t\t// sibling must still collapse to a fail-closed default so a successful trust\n\t\t\t\t\t// mutation cannot leave the whole policy invalid (and thus silently disabled).\n\t\t\t\t\tif (scope === \"global\" && field === \"context\") {\n\t\t\t\t\t\tmergedNested = SettingsManager.sanitizeContextTrustSlice(mergedNested);\n\t\t\t\t\t}\n\t\t\t\t\t(mergedSettings as Record<string, unknown>)[field] = mergedNested;\n\t\t\t\t} else {\n\t\t\t\t\t(mergedSettings as Record<string, unknown>)[field] = value;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn JSON.stringify(mergedSettings, null, 2);\n\t\t});\n\t}\n\n\tprivate save(): void {\n\t\tthis.settings = deepMergeSettings(this.globalSettings, this.projectSettings);\n\n\t\tif (this.globalSettingsLoadError) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst snapshotGlobalSettings = structuredClone(this.globalSettings);\n\t\tconst modifiedFields = new Set(this.modifiedFields);\n\t\tconst modifiedNestedFields = this.cloneModifiedNestedFields(this.modifiedNestedFields);\n\n\t\tthis.enqueueWrite(\"global\", () => {\n\t\t\tthis.persistScopedSettings(\"global\", snapshotGlobalSettings, modifiedFields, modifiedNestedFields);\n\t\t});\n\t}\n\n\tprivate saveProjectSettings(settings: Settings): void {\n\t\tthis.projectSettings = structuredClone(settings);\n\t\tthis.settings = deepMergeSettings(this.globalSettings, this.projectSettings);\n\n\t\tif (this.projectSettingsLoadError) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst snapshotProjectSettings = structuredClone(this.projectSettings);\n\t\tconst modifiedFields = new Set(this.modifiedProjectFields);\n\t\tconst modifiedNestedFields = this.cloneModifiedNestedFields(this.modifiedProjectNestedFields);\n\t\tthis.enqueueWrite(\"project\", () => {\n\t\t\tthis.persistScopedSettings(\"project\", snapshotProjectSettings, modifiedFields, modifiedNestedFields);\n\t\t});\n\t}\n\n\tasync flush(): Promise<void> {\n\t\tawait this.writeQueue;\n\t}\n\n\t/**\n\t * True when the global settings file failed to load/parse. In that state {@link save}\n\t * silently no-ops (to avoid stomping the corrupt file), so callers that need write\n\t * durability must check this and fail loudly instead of reporting success.\n\t */\n\thasGlobalSettingsLoadError(): boolean {\n\t\treturn this.globalSettingsLoadError !== null;\n\t}\n\n\t/** True when the project settings file failed to load or parse. */\n\thasProjectSettingsLoadError(): boolean {\n\t\treturn this.projectSettingsLoadError !== null;\n\t}\n\n\tdrainErrors(): SettingsError[] {\n\t\tconst drained = [...this.errors];\n\t\tthis.errors = [];\n\t\treturn drained;\n\t}\n\n\tgetSessionDir(): string | undefined {\n\t\treturn this.settings.sessionDir;\n\t}\n\n\tgetDefaultProvider(): string | undefined {\n\t\treturn this.settings.defaultProvider;\n\t}\n\n\tgetDefaultModel(): string | undefined {\n\t\treturn this.settings.defaultModel;\n\t}\n\n\tsetDefaultProvider(provider: string): void {\n\t\tthis.globalSettings.defaultProvider = provider;\n\t\tthis.markModified(\"defaultProvider\");\n\t\tthis.save();\n\t}\n\n\tsetDefaultModel(modelId: string): void {\n\t\tthis.globalSettings.defaultModel = modelId;\n\t\tthis.markModified(\"defaultModel\");\n\t\tthis.save();\n\t}\n\n\tsetDefaultModelAndProvider(provider: string, modelId: string): void {\n\t\tthis.globalSettings.defaultProvider = provider;\n\t\tthis.globalSettings.defaultModel = modelId;\n\t\tthis.markModified(\"defaultProvider\");\n\t\tthis.markModified(\"defaultModel\");\n\t\tthis.save();\n\t}\n\n\tgetSteeringMode(): \"all\" | \"one-at-a-time\" {\n\t\treturn this.settings.steeringMode || \"one-at-a-time\";\n\t}\n\n\tsetSteeringMode(mode: \"all\" | \"one-at-a-time\"): void {\n\t\tthis.globalSettings.steeringMode = mode;\n\t\tthis.markModified(\"steeringMode\");\n\t\tthis.save();\n\t}\n\n\tgetFollowUpMode(): \"all\" | \"one-at-a-time\" {\n\t\treturn this.settings.followUpMode || \"one-at-a-time\";\n\t}\n\n\tsetFollowUpMode(mode: \"all\" | \"one-at-a-time\"): void {\n\t\tthis.globalSettings.followUpMode = mode;\n\t\tthis.markModified(\"followUpMode\");\n\t\tthis.save();\n\t}\n\n\tgetTheme(): string | undefined {\n\t\treturn this.settings.theme;\n\t}\n\n\tsetTheme(theme: string): void {\n\t\tthis.globalSettings.theme = theme;\n\t\tthis.markModified(\"theme\");\n\t\tthis.save();\n\t}\n\n\tgetDefaultThinkingLevel(): \"off\" | \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\" | undefined {\n\t\treturn this.settings.defaultThinkingLevel;\n\t}\n\n\tsetDefaultThinkingLevel(level: \"off\" | \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\"): void {\n\t\tthis.globalSettings.defaultThinkingLevel = level;\n\t\tthis.markModified(\"defaultThinkingLevel\");\n\t\tthis.save();\n\t}\n\n\tgetTransport(): TransportSetting {\n\t\treturn this.settings.transport ?? \"sse\";\n\t}\n\n\tsetTransport(transport: TransportSetting): void {\n\t\tthis.globalSettings.transport = transport;\n\t\tthis.markModified(\"transport\");\n\t\tthis.save();\n\t}\n\n\tgetCompactionEnabled(): boolean {\n\t\treturn this.settings.compaction?.enabled ?? true;\n\t}\n\n\tsetCompactionEnabled(enabled: boolean): void {\n\t\tif (!this.globalSettings.compaction) {\n\t\t\tthis.globalSettings.compaction = {};\n\t\t}\n\t\tthis.globalSettings.compaction.enabled = enabled;\n\t\tthis.markModified(\"compaction\", \"enabled\");\n\t\tthis.save();\n\t}\n\n\t/**\n\t * Read the global-only lazy-context policy. File-backed managers re-read this small\n\t * policy on each decision so independently running main/subagent processes observe\n\t * external global settings writes without ever consulting project settings. A malformed\n\t * global file fails closed rather than retaining a previously permissive value.\n\t */\n\tgetGlobalContextTrustPolicy(): ContextTrustPolicy {\n\t\tif (!this.refreshGlobalContextFromStorage()) {\n\t\t\treturn { unrestricted: false, trustedFolders: [] };\n\t\t}\n\n\t\tconst context = this.globalSettings.context;\n\t\t// A valid JSON file with a malformed security policy is also fail-closed. Do not\n\t\t// coerce strings/truthy values or partially accept an invalid trusted-folder list.\n\t\tif (\n\t\t\tcontext !== undefined &&\n\t\t\t(typeof context !== \"object\" ||\n\t\t\t\tcontext === null ||\n\t\t\t\t(context.autoLoadNested !== undefined && typeof context.autoLoadNested !== \"boolean\") ||\n\t\t\t\t(context.trustedFolders !== undefined &&\n\t\t\t\t\t(!Array.isArray(context.trustedFolders) ||\n\t\t\t\t\t\tcontext.trustedFolders.some((folder) => typeof folder !== \"string\"))))\n\t\t) {\n\t\t\tconst error = new Error(\n\t\t\t\t\"Global context trust settings are malformed; lazy nested context loading is disabled\",\n\t\t\t);\n\t\t\tthis.recordError(\"global\", error);\n\t\t\treturn { unrestricted: false, trustedFolders: [] };\n\t\t}\n\n\t\treturn {\n\t\t\tunrestricted: context?.autoLoadNested ?? false,\n\t\t\ttrustedFolders: context?.trustedFolders ? [...context.trustedFolders] : [],\n\t\t};\n\t}\n\n\t/** Effective unrestricted flag; intentionally reads global settings only. */\n\tgetAutoLoadNestedContext(): boolean {\n\t\treturn this.getGlobalContextTrustPolicy().unrestricted;\n\t}\n\n\tgetTrustedContextFolders(): string[] {\n\t\treturn this.getGlobalContextTrustPolicy().trustedFolders;\n\t}\n\n\tgetConfiguredTrustedContextFolders(): string[] {\n\t\tif (!this.refreshGlobalContextFromStorage()) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst context = this.globalSettings.context;\n\t\tif (context === undefined || typeof context !== \"object\" || context === null || Array.isArray(context)) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst trustedFolders = (context as Record<string, unknown>).trustedFolders;\n\t\tif (trustedFolders === undefined) {\n\t\t\treturn [];\n\t\t}\n\t\tif (!Array.isArray(trustedFolders) || trustedFolders.some((folder) => typeof folder !== \"string\")) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn [...trustedFolders];\n\t}\n\n\tsetAutoLoadNestedContext(enabled: boolean): void {\n\t\tthis.setContextTrust({ autoLoadNested: enabled });\n\t}\n\n\t/**\n\t * Atomically persist one or both global lazy-context trust policy fields. Every trust\n\t * write normalizes both known fields, so a malformed on-disk sibling cannot make an\n\t * otherwise successful mutation silently fail closed.\n\t */\n\tsetContextTrust(update: { autoLoadNested?: boolean; trustedFolders?: string[] }): void {\n\t\tif (update.autoLoadNested !== undefined && typeof update.autoLoadNested !== \"boolean\") {\n\t\t\tthrow new Error(\"Auto-load nested context must be a boolean\");\n\t\t}\n\t\tif (\n\t\t\tupdate.trustedFolders !== undefined &&\n\t\t\t(!Array.isArray(update.trustedFolders) || update.trustedFolders.some((folder) => typeof folder !== \"string\"))\n\t\t) {\n\t\t\tthrow new Error(\"Trusted context folders must be an array of strings\");\n\t\t}\n\n\t\t// Refresh the in-memory context slice from the external global file unless a context\n\t\t// write is already pending, so an unspecified sibling reflects concurrent cross-process\n\t\t// changes (e.g. a folder just untrusted elsewhere) instead of a stale in-memory value.\n\t\t// A pending context write already owns the authoritative in-memory value; do not stomp\n\t\t// it. Fail closed if the external file is unreadable.\n\t\tthis.refreshGlobalContextFromStorage({ clearContextOnError: true });\n\n\t\tconst currentContext = this.globalSettings.context;\n\t\tconst current =\n\t\t\ttypeof currentContext === \"object\" && currentContext !== null && !Array.isArray(currentContext)\n\t\t\t\t? (currentContext as Record<string, unknown>)\n\t\t\t\t: {};\n\t\tconst autoLoadNested =\n\t\t\tupdate.autoLoadNested ?? (typeof current.autoLoadNested === \"boolean\" ? current.autoLoadNested : false);\n\t\tconst currentTrustedFolders =\n\t\t\tArray.isArray(current.trustedFolders) && current.trustedFolders.every((folder) => typeof folder === \"string\")\n\t\t\t\t? (current.trustedFolders as string[])\n\t\t\t\t: [];\n\t\tconst trustedFolders = update.trustedFolders ?? currentTrustedFolders;\n\n\t\tthis.globalSettings.context = {\n\t\t\t...current,\n\t\t\tautoLoadNested,\n\t\t\ttrustedFolders: [...trustedFolders],\n\t\t};\n\t\t// Mark only the explicitly-supplied fields modified. persistScopedSettings then\n\t\t// preserves an untouched sibling from the fresh on-disk slice read inside the storage\n\t\t// lock, so a single-field write can no longer clobber a concurrent external change to\n\t\t// the other field. Malformed on-disk siblings are still normalized fail-closed there.\n\t\tif (update.autoLoadNested !== undefined) {\n\t\t\tthis.markModified(\"context\", \"autoLoadNested\");\n\t\t}\n\t\tif (update.trustedFolders !== undefined) {\n\t\t\tthis.markModified(\"context\", \"trustedFolders\");\n\t\t}\n\t\tthis.save();\n\t}\n\n\tsetTrustedContextFolders(folders: string[]): void {\n\t\tthis.setContextTrust({ trustedFolders: folders });\n\t}\n\n\taddTrustedContextFolder(folder: string): void {\n\t\tif (typeof folder !== \"string\" || folder === \"\") {\n\t\t\tthrow new Error(\"Trusted context folder must be a non-empty string\");\n\t\t}\n\t\tconst folders = this.getConfiguredTrustedContextFolders();\n\t\tif (!folders.includes(folder)) folders.push(folder);\n\t\tthis.setTrustedContextFolders(folders);\n\t}\n\n\tremoveTrustedContextFolder(folder: string): void {\n\t\tthis.setTrustedContextFolders(this.getConfiguredTrustedContextFolders().filter((current) => current !== folder));\n\t}\n\n\tgetCompactionReserveTokens(): number {\n\t\treturn this.settings.compaction?.reserveTokens ?? 16384;\n\t}\n\n\tgetCompactionKeepRecentTokens(): number {\n\t\treturn this.settings.compaction?.keepRecentTokens ?? 20000;\n\t}\n\n\tgetCompactionSettings(): { enabled: boolean; reserveTokens: number; keepRecentTokens: number } {\n\t\treturn {\n\t\t\tenabled: this.getCompactionEnabled(),\n\t\t\treserveTokens: this.getCompactionReserveTokens(),\n\t\t\tkeepRecentTokens: this.getCompactionKeepRecentTokens(),\n\t\t};\n\t}\n\n\tgetBranchSummarySettings(): { reserveTokens: number; skipPrompt: boolean } {\n\t\treturn {\n\t\t\treserveTokens: this.settings.branchSummary?.reserveTokens ?? 16384,\n\t\t\tskipPrompt: this.settings.branchSummary?.skipPrompt ?? false,\n\t\t};\n\t}\n\n\tgetBranchSummarySkipPrompt(): boolean {\n\t\treturn this.settings.branchSummary?.skipPrompt ?? false;\n\t}\n\n\tgetRetryEnabled(): boolean {\n\t\treturn this.settings.retry?.enabled ?? true;\n\t}\n\n\tsetRetryEnabled(enabled: boolean): void {\n\t\tif (!this.globalSettings.retry) {\n\t\t\tthis.globalSettings.retry = {};\n\t\t}\n\t\tthis.globalSettings.retry.enabled = enabled;\n\t\tthis.markModified(\"retry\", \"enabled\");\n\t\tthis.save();\n\t}\n\n\tgetRetrySettings(): { enabled: boolean; maxRetries: number; baseDelayMs: number; maxDelayMs: number } {\n\t\treturn {\n\t\t\tenabled: this.getRetryEnabled(),\n\t\t\tmaxRetries: this.settings.retry?.maxRetries ?? 3,\n\t\t\tbaseDelayMs: this.settings.retry?.baseDelayMs ?? 2000,\n\t\t\tmaxDelayMs: this.settings.retry?.maxDelayMs ?? 60000,\n\t\t};\n\t}\n\n\tgetBackgroundAgentGuardrailEnabled(): boolean {\n\t\treturn this.settings.backgroundAgents?.parentTurnGuardrail ?? true;\n\t}\n\n\tsetBackgroundAgentGuardrailEnabled(enabled: boolean): void {\n\t\tif (!this.globalSettings.backgroundAgents) {\n\t\t\tthis.globalSettings.backgroundAgents = {};\n\t\t}\n\t\tthis.globalSettings.backgroundAgents.parentTurnGuardrail = enabled;\n\t\tthis.markModified(\"backgroundAgents\", \"parentTurnGuardrail\");\n\t\tthis.save();\n\t}\n\n\tgetBackgroundAgentGuardrailSettings(): { enabled: boolean; turnLimit: number } {\n\t\tconst rawLimit = this.settings.backgroundAgents?.parentTurnLimit;\n\t\tconst turnLimit =\n\t\t\ttypeof rawLimit === \"number\" && Number.isFinite(rawLimit) && rawLimit >= 1\n\t\t\t\t? rawLimit\n\t\t\t\t: DEFAULT_BG_PARENT_TURN_LIMIT;\n\t\treturn {\n\t\t\tenabled: this.getBackgroundAgentGuardrailEnabled(),\n\t\t\tturnLimit,\n\t\t};\n\t}\n\n\tgetMaxConcurrentSubagents(): number {\n\t\tconst value = this.settings.backgroundAgents?.maxConcurrentSubagents;\n\t\tif (value === undefined) {\n\t\t\treturn DEFAULT_MAX_CONCURRENT_SUBAGENTS;\n\t\t}\n\t\tif (typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0) {\n\t\t\treturn value;\n\t\t}\n\t\tlog.warn(\n\t\t\t`[settings] Ignoring invalid backgroundAgents.maxConcurrentSubagents ${JSON.stringify(value)}; ` +\n\t\t\t\t`it must be a non-negative whole number. Falling back to ${DEFAULT_MAX_CONCURRENT_SUBAGENTS}. ` +\n\t\t\t\t\"Fix the value in your settings file to silence this warning.\",\n\t\t);\n\t\treturn DEFAULT_MAX_CONCURRENT_SUBAGENTS;\n\t}\n\n\tsetMaxConcurrentSubagents(value: number): void {\n\t\tif (!Number.isSafeInteger(value) || value < 0) {\n\t\t\tthrow new Error(\"maxConcurrentSubagents must be a non-negative whole number\");\n\t\t}\n\t\tif (!this.globalSettings.backgroundAgents) {\n\t\t\tthis.globalSettings.backgroundAgents = {};\n\t\t}\n\t\tthis.globalSettings.backgroundAgents.maxConcurrentSubagents = value;\n\t\tthis.markModified(\"backgroundAgents\", \"maxConcurrentSubagents\");\n\t\tthis.save();\n\t}\n\n\tgetHideThinkingBlock(): boolean {\n\t\treturn this.settings.hideThinkingBlock ?? false;\n\t}\n\n\tsetHideThinkingBlock(hide: boolean): void {\n\t\tthis.globalSettings.hideThinkingBlock = hide;\n\t\tthis.markModified(\"hideThinkingBlock\");\n\t\tthis.save();\n\t}\n\n\tgetShellPath(): string | undefined {\n\t\treturn this.settings.shellPath;\n\t}\n\n\tsetShellPath(path: string | undefined): void {\n\t\tthis.globalSettings.shellPath = path;\n\t\tthis.markModified(\"shellPath\");\n\t\tthis.save();\n\t}\n\n\tgetQuietStartup(): boolean {\n\t\treturn this.settings.quietStartup ?? false;\n\t}\n\n\tsetQuietStartup(quiet: boolean): void {\n\t\tthis.globalSettings.quietStartup = quiet;\n\t\tthis.markModified(\"quietStartup\");\n\t\tthis.save();\n\t}\n\n\tgetShellCommandPrefix(): string | undefined {\n\t\treturn this.settings.shellCommandPrefix;\n\t}\n\n\tsetShellCommandPrefix(prefix: string | undefined): void {\n\t\tthis.globalSettings.shellCommandPrefix = prefix;\n\t\tthis.markModified(\"shellCommandPrefix\");\n\t\tthis.save();\n\t}\n\n\tgetNpmCommand(): string[] | undefined {\n\t\treturn this.settings.npmCommand ? [...this.settings.npmCommand] : undefined;\n\t}\n\n\tsetNpmCommand(command: string[] | undefined): void {\n\t\tthis.globalSettings.npmCommand = command ? [...command] : undefined;\n\t\tthis.markModified(\"npmCommand\");\n\t\tthis.save();\n\t}\n\n\tgetPackages(): PackageSource[] {\n\t\treturn [...(this.settings.packages ?? [])];\n\t}\n\n\tsetPackages(packages: PackageSource[]): void {\n\t\tthis.globalSettings.packages = packages;\n\t\tthis.markModified(\"packages\");\n\t\tthis.save();\n\t}\n\n\tsetProjectPackages(packages: PackageSource[]): void {\n\t\tconst projectSettings = structuredClone(this.projectSettings);\n\t\tprojectSettings.packages = packages;\n\t\tthis.markProjectModified(\"packages\");\n\t\tthis.saveProjectSettings(projectSettings);\n\t}\n\n\tgetExtensionPaths(): string[] {\n\t\treturn [...(this.settings.extensions ?? [])];\n\t}\n\n\tsetExtensionPaths(paths: string[]): void {\n\t\tthis.globalSettings.extensions = paths;\n\t\tthis.markModified(\"extensions\");\n\t\tthis.save();\n\t}\n\n\tsetProjectExtensionPaths(paths: string[]): void {\n\t\tconst projectSettings = structuredClone(this.projectSettings);\n\t\tprojectSettings.extensions = paths;\n\t\tthis.markProjectModified(\"extensions\");\n\t\tthis.saveProjectSettings(projectSettings);\n\t}\n\n\tgetSkillPaths(): string[] {\n\t\treturn [...(this.settings.skills ?? [])];\n\t}\n\n\tsetSkillPaths(paths: string[]): void {\n\t\tthis.globalSettings.skills = paths;\n\t\tthis.markModified(\"skills\");\n\t\tthis.save();\n\t}\n\n\tsetProjectSkillPaths(paths: string[]): void {\n\t\tconst projectSettings = structuredClone(this.projectSettings);\n\t\tprojectSettings.skills = paths;\n\t\tthis.markProjectModified(\"skills\");\n\t\tthis.saveProjectSettings(projectSettings);\n\t}\n\n\tgetPromptTemplatePaths(): string[] {\n\t\treturn [...(this.settings.prompts ?? [])];\n\t}\n\n\tsetPromptTemplatePaths(paths: string[]): void {\n\t\tthis.globalSettings.prompts = paths;\n\t\tthis.markModified(\"prompts\");\n\t\tthis.save();\n\t}\n\n\tsetProjectPromptTemplatePaths(paths: string[]): void {\n\t\tconst projectSettings = structuredClone(this.projectSettings);\n\t\tprojectSettings.prompts = paths;\n\t\tthis.markProjectModified(\"prompts\");\n\t\tthis.saveProjectSettings(projectSettings);\n\t}\n\n\tgetThemePaths(): string[] {\n\t\treturn [...(this.settings.themes ?? [])];\n\t}\n\n\tsetThemePaths(paths: string[]): void {\n\t\tthis.globalSettings.themes = paths;\n\t\tthis.markModified(\"themes\");\n\t\tthis.save();\n\t}\n\n\tsetProjectThemePaths(paths: string[]): void {\n\t\tconst projectSettings = structuredClone(this.projectSettings);\n\t\tprojectSettings.themes = paths;\n\t\tthis.markProjectModified(\"themes\");\n\t\tthis.saveProjectSettings(projectSettings);\n\t}\n\n\tgetEnableSkillCommands(): boolean {\n\t\treturn this.settings.enableSkillCommands ?? true;\n\t}\n\n\tsetEnableSkillCommands(enabled: boolean): void {\n\t\tthis.globalSettings.enableSkillCommands = enabled;\n\t\tthis.markModified(\"enableSkillCommands\");\n\t\tthis.save();\n\t}\n\n\tgetThinkingBudgets(): ThinkingBudgetsSettings | undefined {\n\t\treturn this.settings.thinkingBudgets;\n\t}\n\n\tgetShowImages(): boolean {\n\t\treturn this.settings.terminal?.showImages ?? true;\n\t}\n\n\tsetShowImages(show: boolean): void {\n\t\tif (!this.globalSettings.terminal) {\n\t\t\tthis.globalSettings.terminal = {};\n\t\t}\n\t\tthis.globalSettings.terminal.showImages = show;\n\t\tthis.markModified(\"terminal\", \"showImages\");\n\t\tthis.save();\n\t}\n\n\tgetImageAutoResize(): boolean {\n\t\treturn this.settings.images?.autoResize ?? true;\n\t}\n\n\tsetImageAutoResize(enabled: boolean): void {\n\t\tif (!this.globalSettings.images) {\n\t\t\tthis.globalSettings.images = {};\n\t\t}\n\t\tthis.globalSettings.images.autoResize = enabled;\n\t\tthis.markModified(\"images\", \"autoResize\");\n\t\tthis.save();\n\t}\n\n\tgetBlockImages(): boolean {\n\t\treturn this.settings.images?.blockImages ?? false;\n\t}\n\n\tsetBlockImages(blocked: boolean): void {\n\t\tif (!this.globalSettings.images) {\n\t\t\tthis.globalSettings.images = {};\n\t\t}\n\t\tthis.globalSettings.images.blockImages = blocked;\n\t\tthis.markModified(\"images\", \"blockImages\");\n\t\tthis.save();\n\t}\n\n\tgetEnabledModels(): string[] | undefined {\n\t\treturn this.settings.enabledModels;\n\t}\n\n\tsetEnabledModels(patterns: string[] | undefined): void {\n\t\tthis.globalSettings.enabledModels = patterns;\n\t\tthis.markModified(\"enabledModels\");\n\t\tthis.save();\n\t}\n\n\t/** Whether project settings explicitly replace the global enabled-model scope. */\n\thasProjectEnabledModelsOverride(): boolean {\n\t\treturn this.projectSettings.enabledModels !== undefined;\n\t}\n\n\tgetDoubleEscapeAction(): \"fork\" | \"tree\" | \"none\" {\n\t\treturn this.settings.doubleEscapeAction ?? \"tree\";\n\t}\n\n\tsetDoubleEscapeAction(action: \"fork\" | \"tree\" | \"none\"): void {\n\t\tthis.globalSettings.doubleEscapeAction = action;\n\t\tthis.markModified(\"doubleEscapeAction\");\n\t\tthis.save();\n\t}\n\n\tgetTreeFilterMode(): \"default\" | \"no-tools\" | \"user-only\" | \"labeled-only\" | \"all\" {\n\t\tconst mode = this.settings.treeFilterMode;\n\t\tconst valid = [\"default\", \"no-tools\", \"user-only\", \"labeled-only\", \"all\"];\n\t\treturn mode && valid.includes(mode) ? mode : \"default\";\n\t}\n\n\tsetTreeFilterMode(mode: \"default\" | \"no-tools\" | \"user-only\" | \"labeled-only\" | \"all\"): void {\n\t\tthis.globalSettings.treeFilterMode = mode;\n\t\tthis.markModified(\"treeFilterMode\");\n\t\tthis.save();\n\t}\n\n\tgetShowHardwareCursor(): boolean {\n\t\treturn this.settings.showHardwareCursor ?? process.env.DREB_HARDWARE_CURSOR === \"1\";\n\t}\n\n\tsetShowHardwareCursor(enabled: boolean): void {\n\t\tthis.globalSettings.showHardwareCursor = enabled;\n\t\tthis.markModified(\"showHardwareCursor\");\n\t\tthis.save();\n\t}\n\n\tgetEditorPaddingX(): number {\n\t\treturn this.settings.editorPaddingX ?? 0;\n\t}\n\n\tsetEditorPaddingX(padding: number): void {\n\t\tthis.globalSettings.editorPaddingX = Math.max(0, Math.min(3, Math.floor(padding)));\n\t\tthis.markModified(\"editorPaddingX\");\n\t\tthis.save();\n\t}\n\n\tgetAutocompleteMaxVisible(): number {\n\t\treturn this.settings.autocompleteMaxVisible ?? 5;\n\t}\n\n\tsetAutocompleteMaxVisible(maxVisible: number): void {\n\t\tthis.globalSettings.autocompleteMaxVisible = Math.max(3, Math.min(20, Math.floor(maxVisible)));\n\t\tthis.markModified(\"autocompleteMaxVisible\");\n\t\tthis.save();\n\t}\n\n\tgetCodeBlockIndent(): string {\n\t\treturn this.settings.markdown?.codeBlockIndent ?? \" \";\n\t}\n\n\tgetForbiddenCommands(): string[] | undefined {\n\t\treturn this.settings.forbiddenCommands;\n\t}\n\n\tgetSensitiveFilePaths(): string[] | undefined {\n\t\treturn this.settings.sensitiveFilePaths;\n\t}\n\n\tgetSecretOutputPatterns(): { name: string; pattern: string }[] | undefined {\n\t\treturn this.settings.secretOutputPatterns;\n\t}\n\n\t/**\n\t * Read only the global arbiter policy; project settings are intentionally ignored.\n\t * File-backed managers refresh this slice for every dispatch so independently\n\t * running sessions observe dashboard and TUI writes without a restart.\n\t */\n\tgetGlobalSubagentArbiterSettings(): SubagentArbiterSettings | undefined {\n\t\tthis.refreshGlobalSubagentArbiterFromStorage();\n\t\treturn this.globalSettings.subagentArbiter ? structuredClone(this.globalSettings.subagentArbiter) : undefined;\n\t}\n\n\tsetGlobalSubagentArbiterSettings(settings: SubagentArbiterSettings | undefined): void {\n\t\tthis.globalSettings.subagentArbiter = settings ? structuredClone(settings) : undefined;\n\t\tthis.markModified(\"subagentArbiter\");\n\t\tthis.save();\n\t}\n\n\tgetDreamArchivePath(): string {\n\t\tconst configured = this.settings.dream?.archivePath;\n\t\tif (configured) {\n\t\t\treturn resolve(expandPath(configured));\n\t\t}\n\t\treturn join(homedir(), \".dreb\", \"memory-archive\");\n\t}\n\n\tsetDreamArchivePath(path: string): void {\n\t\tif (!this.globalSettings.dream) this.globalSettings.dream = {};\n\t\tthis.globalSettings.dream.archivePath = path;\n\t\tthis.markModified(\"dream\", \"archivePath\");\n\t\tthis.save();\n\t}\n\n\tgetAgentModels(): Record<string, string[]> {\n\t\t// Merge global + project at the per-agent-name level, with project winning per-key.\n\t\t// Reading directly from globalSettings/projectSettings avoids the wholesale\n\t\t// replacement that deepMergeSettings would do for the shared `models` sub-key.\n\t\tconst merged: Record<string, string[]> = {\n\t\t\t...this.globalSettings.agentModels?.models,\n\t\t\t...this.projectSettings.agentModels?.models,\n\t\t};\n\t\t// Deep-copy inner arrays so callers can't mutate stored state.\n\t\treturn Object.fromEntries(Object.entries(merged).map(([k, v]) => [k, [...v]]));\n\t}\n\n\tgetAgentModelsForAgent(agentName: string): string[] | undefined {\n\t\tconst models = this.getAgentModels()[agentName];\n\t\treturn models && models.length > 0 ? models : undefined;\n\t}\n\n\t/**\n\t * Whether a project-level (`.dreb/settings.json`) agentModels entry exists for this agent.\n\t * Project entries win over global ones in {@link getAgentModels}, so a global write/remove\n\t * via the TUI has no effect when this returns true — callers should surface this loudly.\n\t */\n\thasProjectAgentModelOverride(agentName: string): boolean {\n\t\treturn this.projectSettings.agentModels?.models?.[agentName] !== undefined;\n\t}\n\n\tsetAgentModelsForAgent(agentName: string, models: string[]): void {\n\t\tif (!this.globalSettings.agentModels) {\n\t\t\tthis.globalSettings.agentModels = {};\n\t\t}\n\t\tif (!this.globalSettings.agentModels.models) {\n\t\t\tthis.globalSettings.agentModels.models = {};\n\t\t}\n\t\tthis.globalSettings.agentModels.models[agentName] = [...models];\n\t\tthis.markModified(\"agentModels\", \"models\");\n\t\tthis.save();\n\t}\n\n\tremoveAgentModelsForAgent(agentName: string): void {\n\t\tif (this.globalSettings.agentModels?.models?.[agentName] !== undefined) {\n\t\t\tdelete this.globalSettings.agentModels.models[agentName];\n\t\t\tthis.markModified(\"agentModels\", \"models\");\n\t\t\tthis.save();\n\t\t}\n\t}\n\n\t/**\n\t * Per-model settings merged global + project at the per-model-id level, with project\n\t * winning per key. Reading directly from globalSettings/projectSettings avoids the\n\t * wholesale replacement that deepMergeSettings would do for the shared `modelSettings` key.\n\t */\n\tgetModelSettings(modelId: string): ModelSpecificSettings | undefined {\n\t\tconst global = this.globalSettings.modelSettings?.[modelId];\n\t\tconst project = this.projectSettings.modelSettings?.[modelId];\n\t\tif (!global && !project) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn { ...global, ...project };\n\t}\n\n\tgetModelThinkingDisplay(modelId: string): \"summarized\" | \"omitted\" | undefined {\n\t\treturn this.getModelSettings(modelId)?.thinkingDisplay;\n\t}\n\n\tsetModelThinkingDisplay(modelId: string, value: \"summarized\" | \"omitted\" | undefined): void {\n\t\tif (value === undefined) {\n\t\t\tconst existing = this.globalSettings.modelSettings?.[modelId];\n\t\t\tif (existing?.thinkingDisplay === undefined) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdelete existing.thinkingDisplay;\n\t\t\tif (Object.keys(existing).length === 0) {\n\t\t\t\tdelete this.globalSettings.modelSettings![modelId];\n\t\t\t}\n\t\t\tthis.markModified(\"modelSettings\", modelId);\n\t\t\tthis.save();\n\t\t\treturn;\n\t\t}\n\t\tif (!this.globalSettings.modelSettings) {\n\t\t\tthis.globalSettings.modelSettings = {};\n\t\t}\n\t\tif (!this.globalSettings.modelSettings[modelId]) {\n\t\t\tthis.globalSettings.modelSettings[modelId] = {};\n\t\t}\n\t\tthis.globalSettings.modelSettings[modelId].thinkingDisplay = value;\n\t\tthis.markModified(\"modelSettings\", modelId);\n\t\tthis.save();\n\t}\n\n\tgetTabTitleSettings(): TabTitleSettings | undefined {\n\t\treturn this.settings.tabTitle;\n\t}\n}\n"]}
1
+ {"version":3,"file":"settings-manager.d.ts","sour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CAKtC;IAED,cAAc,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAUzC;IAED,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAG9D;IAED;;;;OAIG;IACH,4BAA4B,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAEvD;IAED,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAUhE;IAED,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAMjD;IAED;;;;;OAKG;IACH,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CAOpE;IAED;;;;OAIG;IACH,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS,CAwBzF;IAED,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,GAAG,SAAS,CAE7E;IAED,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,SAAS,GAAG,SAAS,GAAG,IAAI,CAuB1F;IAED,mBAAmB,IAAI,gBAAgB,GAAG,SAAS,CAElD;CACD","sourcesContent":["import { homedir } from \"node:os\";\nimport type { Transport } from \"@dreb/ai\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\";\nimport { dirname, join, resolve } from \"path\";\nimport lockfile from \"proper-lockfile\";\nimport { CONFIG_DIR_NAME, getAgentDir } from \"../config.js\";\nimport type { ContextTrustPolicy } from \"./context-trust.js\";\nimport { log } from \"./logger.js\";\nimport { expandPath } from \"./tools/path-utils.js\";\n\nexport interface CompactionSettings {\n\tenabled?: boolean; // default: true\n\treserveTokens?: number; // default: 16384\n\tkeepRecentTokens?: number; // default: 20000\n}\n\nexport interface ContextSettings {\n\t/**\n\t * Expert-only global opt-in to lazy-load nested context from every strictly resolvable\n\t * tool target. This is disabled by default because context files can contain prompt\n\t * injection. Project settings cannot affect this policy.\n\t */\n\tautoLoadNested?: boolean;\n\t/** Global-only folder roots allowed to lazy-load context for themselves and descendants. */\n\ttrustedFolders?: string[];\n}\n\nexport interface BranchSummarySettings {\n\treserveTokens?: number; // default: 16384 (tokens reserved for prompt + LLM response)\n\tskipPrompt?: boolean; // default: false - when true, skips \"Summarize branch?\" prompt and defaults to no summary\n}\n\nexport interface RetrySettings {\n\tenabled?: boolean; // default: true\n\tmaxRetries?: number; // default: 3\n\tbaseDelayMs?: number; // default: 2000 (exponential backoff: 2s, 4s, 8s)\n\tmaxDelayMs?: number; // default: 60000 (max server-requested delay before failing)\n}\n\nexport const DEFAULT_BG_PARENT_TURN_LIMIT = 3;\nexport const DEFAULT_MAX_CONCURRENT_SUBAGENTS = 4;\n\nexport interface BackgroundAgentsSettings {\n\t/**\n\t * Whether the parent agent is paused after `parentTurnLimit` turns while background\n\t * agents are still running. Disable (false) to let the parent keep running while\n\t * subagents work — an advanced opt-out with no upper bound on parent turns. default: true\n\t */\n\tparentTurnGuardrail?: boolean;\n\t/** Number of parent turns allowed while background agents run before pausing. default: 3 */\n\tparentTurnLimit?: number;\n\t/** Maximum child agents that one parent session may run concurrently. Zero disables the tool. default: 4 */\n\tmaxConcurrentSubagents?: number;\n}\n\nexport interface TerminalSettings {\n\tshowImages?: boolean; // default: true (only relevant if terminal supports images)\n}\n\nexport interface ImageSettings {\n\tautoResize?: boolean; // default: true (resize images to 2000x2000 max for better model compatibility)\n\tblockImages?: boolean; // default: false - when true, prevents all images from being sent to LLM providers\n}\n\nexport interface ThinkingBudgetsSettings {\n\tminimal?: number;\n\tlow?: number;\n\tmedium?: number;\n\thigh?: number;\n}\n\nexport interface MarkdownSettings {\n\tcodeBlockIndent?: string; // default: \" \"\n}\n\nexport interface AgentModelsSettings {\n\tmodels?: Record<string, string[]>;\n}\n\n/** Global-only configuration for the fail-closed pre-spawn Dispatch Arbiter. */\nexport interface SubagentArbiterSettings {\n\tenabled?: boolean;\n\t/** Exact canonical provider/model used for the tool-less arbiter call. */\n\tmodel?: string;\n\tthinking?: \"off\" | \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\";\n\tguidePath?: string;\n}\n\nexport interface ModelSpecificSettings {\n\t/** Thinking display preference for this model: \"summarized\" shows thinking text, \"omitted\" hides it (lower latency). */\n\tthinkingDisplay?: \"summarized\" | \"omitted\";\n\t/** Custom system prompt for an exact provider/model key. Replaces dreb's built-in prompt. */\n\tsystemPrompt?: string;\n\t/** Text appended to the system prompt for an exact provider/model key. */\n\tappendSystemPrompt?: string;\n}\n\nexport type ModelPromptSettings = Pick<ModelSpecificSettings, \"systemPrompt\" | \"appendSystemPrompt\">;\n\nexport type TransportSetting = Transport;\n\n/**\n * Package source for npm/git packages.\n * - String form: load all resources from the package\n * - Object form: filter which resources to load\n */\nexport type PackageSource =\n\t| string\n\t| {\n\t\t\tsource: string;\n\t\t\textensions?: string[];\n\t\t\tskills?: string[];\n\t\t\tprompts?: string[];\n\t\t\tthemes?: string[];\n\t };\n\nexport interface Settings {\n\tdefaultProvider?: string;\n\tdefaultModel?: string;\n\tdefaultThinkingLevel?: \"off\" | \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\";\n\ttransport?: TransportSetting; // default: \"sse\"\n\tsteeringMode?: \"all\" | \"one-at-a-time\";\n\tfollowUpMode?: \"all\" | \"one-at-a-time\";\n\ttheme?: string;\n\tcompaction?: CompactionSettings;\n\tcontext?: ContextSettings;\n\tbranchSummary?: BranchSummarySettings;\n\tretry?: RetrySettings;\n\tbackgroundAgents?: BackgroundAgentsSettings;\n\thideThinkingBlock?: boolean;\n\tshellPath?: string; // Custom shell path (e.g., for Cygwin users on Windows)\n\tquietStartup?: boolean;\n\tshellCommandPrefix?: string; // Prefix prepended to every bash command (e.g., \"shopt -s expand_aliases\" for alias support)\n\tnpmCommand?: string[]; // Command used for npm package lookup/install operations, argv-style (e.g., [\"mise\", \"exec\", \"node@20\", \"--\", \"npm\"])\n\tpackages?: PackageSource[]; // Array of npm/git package sources (string or object with filtering)\n\textensions?: string[]; // Array of local extension file paths or directories\n\tskills?: string[]; // Array of local skill file paths or directories\n\tprompts?: string[]; // Array of local prompt template paths or directories\n\tthemes?: string[]; // Array of local theme file paths or directories\n\tenableSkillCommands?: boolean; // default: true - register skills as /skill:name commands\n\tterminal?: TerminalSettings;\n\timages?: ImageSettings;\n\tenabledModels?: string[]; // Model patterns for cycling (same format as --models CLI flag)\n\tdoubleEscapeAction?: \"fork\" | \"tree\" | \"none\"; // Action for double-escape with empty editor (default: \"tree\")\n\ttreeFilterMode?: \"default\" | \"no-tools\" | \"user-only\" | \"labeled-only\" | \"all\"; // Default filter when opening /tree\n\tthinkingBudgets?: ThinkingBudgetsSettings; // Custom token budgets for thinking levels\n\teditorPaddingX?: number; // Horizontal padding for input editor (default: 0)\n\tautocompleteMaxVisible?: number; // Max visible items in autocomplete dropdown (default: 5)\n\tshowHardwareCursor?: boolean; // Show terminal cursor while still positioning it for IME\n\tmarkdown?: MarkdownSettings;\n\tsessionDir?: string; // Custom session storage directory (same format as --session-dir CLI flag)\n\tforbiddenCommands?: string[]; // Regex patterns for commands blocked by the forbidden-commands guard\n\tsensitiveFilePaths?: string[]; // Additional glob patterns for sensitive file paths blocked by the read/bash guard\n\tsecretOutputPatterns?: { name: string; pattern: string }[]; // Additional regex patterns for secret scrubbing in tool output\n\tagentModels?: AgentModelsSettings;\n\t/** Global-only. Project settings must never enable or reconfigure arbitration. */\n\tsubagentArbiter?: SubagentArbiterSettings;\n\t// Per-model overrides. Thinking display supports legacy model-ID keys; prompt settings require exact provider/model keys.\n\tmodelSettings?: Record<string, ModelSpecificSettings>;\n\tdream?: {\n\t\tarchivePath?: string; // Custom archive location for dream backups (default: ~/.dreb/memory-archive/)\n\t};\n\ttabTitle?: TabTitleSettings;\n}\n\nexport interface TabTitleSettings {\n\tenabled?: boolean; // default: true — auto-generate terminal tab title from session task\n\ttriggerAfter?: number; // default: 9 — number of tool calls before generating title\n\tmaxTitleLength?: number; // default: 60 — soft target length hint for generated titles (hard-capped at 300)\n}\n\n/** Deep merge settings: project/overrides take precedence, nested objects merge recursively */\nfunction deepMergeSettings(base: Settings, overrides: Settings): Settings {\n\tconst result: Settings = { ...base };\n\n\tfor (const key of Object.keys(overrides) as (keyof Settings)[]) {\n\t\tconst overrideValue = overrides[key];\n\t\tconst baseValue = base[key];\n\n\t\tif (overrideValue === undefined) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// For nested objects, merge recursively\n\t\tif (\n\t\t\ttypeof overrideValue === \"object\" &&\n\t\t\toverrideValue !== null &&\n\t\t\t!Array.isArray(overrideValue) &&\n\t\t\ttypeof baseValue === \"object\" &&\n\t\t\tbaseValue !== null &&\n\t\t\t!Array.isArray(baseValue)\n\t\t) {\n\t\t\t(result as Record<string, unknown>)[key] = { ...baseValue, ...overrideValue };\n\t\t} else {\n\t\t\t// For primitives and arrays, override value wins\n\t\t\t(result as Record<string, unknown>)[key] = overrideValue;\n\t\t}\n\t}\n\n\treturn result;\n}\n\nexport type SettingsScope = \"global\" | \"project\";\n\nexport interface SettingsStorage {\n\twithLock(scope: SettingsScope, fn: (current: string | undefined) => string | undefined): void;\n}\n\nexport interface SettingsError {\n\tscope: SettingsScope;\n\terror: Error;\n}\n\nexport class FileSettingsStorage implements SettingsStorage {\n\tprivate globalSettingsPath: string;\n\tprivate projectSettingsPath: string;\n\n\tconstructor(cwd: string = process.cwd(), agentDir: string = getAgentDir()) {\n\t\tthis.globalSettingsPath = join(agentDir, \"settings.json\");\n\t\tthis.projectSettingsPath = join(cwd, CONFIG_DIR_NAME, \"settings.json\");\n\t}\n\n\tprivate acquireLockSyncWithRetry(path: string): () => void {\n\t\tconst maxAttempts = 10;\n\t\tconst delayMs = 20;\n\t\tlet lastError: unknown;\n\n\t\tfor (let attempt = 1; attempt <= maxAttempts; attempt++) {\n\t\t\ttry {\n\t\t\t\treturn lockfile.lockSync(path, { realpath: false });\n\t\t\t} catch (error) {\n\t\t\t\tconst code =\n\t\t\t\t\ttypeof error === \"object\" && error !== null && \"code\" in error\n\t\t\t\t\t\t? String((error as { code?: unknown }).code)\n\t\t\t\t\t\t: undefined;\n\t\t\t\tif (code !== \"ELOCKED\" || attempt === maxAttempts) {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tlastError = error;\n\t\t\t\tconst start = Date.now();\n\t\t\t\twhile (Date.now() - start < delayMs) {\n\t\t\t\t\t// Sleep synchronously to avoid changing callers to async.\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthrow (lastError as Error) ?? new Error(\"Failed to acquire settings lock\");\n\t}\n\n\twithLock(scope: SettingsScope, fn: (current: string | undefined) => string | undefined): void {\n\t\tconst path = scope === \"global\" ? this.globalSettingsPath : this.projectSettingsPath;\n\t\tconst dir = dirname(path);\n\n\t\tlet release: (() => void) | undefined;\n\t\ttry {\n\t\t\t// Only create directory and lock if file exists or we need to write\n\t\t\tconst fileExists = existsSync(path);\n\t\t\tif (fileExists) {\n\t\t\t\trelease = this.acquireLockSyncWithRetry(path);\n\t\t\t}\n\t\t\tconst current = fileExists ? readFileSync(path, \"utf-8\") : undefined;\n\t\t\tconst next = fn(current);\n\t\t\tif (next !== undefined) {\n\t\t\t\t// Only create directory when we actually need to write\n\t\t\t\tif (!existsSync(dir)) {\n\t\t\t\t\tmkdirSync(dir, { recursive: true });\n\t\t\t\t}\n\t\t\t\tif (!release) {\n\t\t\t\t\trelease = this.acquireLockSyncWithRetry(path);\n\t\t\t\t}\n\t\t\t\twriteFileSync(path, next, \"utf-8\");\n\t\t\t}\n\t\t} finally {\n\t\t\tif (release) {\n\t\t\t\trelease();\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport class InMemorySettingsStorage implements SettingsStorage {\n\tprivate global: string | undefined;\n\tprivate project: string | undefined;\n\n\twithLock(scope: SettingsScope, fn: (current: string | undefined) => string | undefined): void {\n\t\tconst current = scope === \"global\" ? this.global : this.project;\n\t\tconst next = fn(current);\n\t\tif (next !== undefined) {\n\t\t\tif (scope === \"global\") {\n\t\t\t\tthis.global = next;\n\t\t\t} else {\n\t\t\t\tthis.project = next;\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport class SettingsManager {\n\tprivate storage: SettingsStorage;\n\tprivate globalSettings: Settings;\n\tprivate projectSettings: Settings;\n\tprivate settings: Settings;\n\tprivate modifiedFields = new Set<keyof Settings>(); // Track global fields modified during session\n\tprivate modifiedNestedFields = new Map<keyof Settings, Set<string>>(); // Track global nested field modifications\n\tprivate modifiedProjectFields = new Set<keyof Settings>(); // Track project fields modified during session\n\tprivate modifiedProjectNestedFields = new Map<keyof Settings, Set<string>>(); // Track project nested field modifications\n\tprivate globalSettingsLoadError: Error | null = null; // Track if global settings file had parse errors\n\tprivate projectSettingsLoadError: Error | null = null; // Track if project settings file had parse errors\n\tprivate writeQueue: Promise<void> = Promise.resolve();\n\tprivate errors: SettingsError[];\n\n\tprivate constructor(\n\t\tstorage: SettingsStorage,\n\t\tinitialGlobal: Settings,\n\t\tinitialProject: Settings,\n\t\tglobalLoadError: Error | null = null,\n\t\tprojectLoadError: Error | null = null,\n\t\tinitialErrors: SettingsError[] = [],\n\t) {\n\t\tthis.storage = storage;\n\t\tthis.globalSettings = initialGlobal;\n\t\tthis.projectSettings = initialProject;\n\t\tthis.globalSettingsLoadError = globalLoadError;\n\t\tthis.projectSettingsLoadError = projectLoadError;\n\t\tthis.errors = [...initialErrors];\n\t\tthis.settings = deepMergeSettings(this.globalSettings, this.projectSettings);\n\t}\n\n\t/** Create a SettingsManager that loads from files */\n\tstatic create(cwd: string = process.cwd(), agentDir: string = getAgentDir()): SettingsManager {\n\t\tconst storage = new FileSettingsStorage(cwd, agentDir);\n\t\treturn SettingsManager.fromStorage(storage);\n\t}\n\n\t/** Create a SettingsManager from an arbitrary storage backend */\n\tstatic fromStorage(storage: SettingsStorage): SettingsManager {\n\t\tconst globalLoad = SettingsManager.tryLoadFromStorage(storage, \"global\");\n\t\tconst projectLoad = SettingsManager.tryLoadFromStorage(storage, \"project\");\n\t\tconst initialErrors: SettingsError[] = [];\n\t\tif (globalLoad.error) {\n\t\t\tinitialErrors.push({ scope: \"global\", error: globalLoad.error });\n\t\t}\n\t\tif (projectLoad.error) {\n\t\t\tinitialErrors.push({ scope: \"project\", error: projectLoad.error });\n\t\t}\n\n\t\treturn new SettingsManager(\n\t\t\tstorage,\n\t\t\tglobalLoad.settings,\n\t\t\tprojectLoad.settings,\n\t\t\tglobalLoad.error,\n\t\t\tprojectLoad.error,\n\t\t\tinitialErrors,\n\t\t);\n\t}\n\n\t/** Create an in-memory SettingsManager (no file I/O) */\n\tstatic inMemory(settings: Partial<Settings> = {}): SettingsManager {\n\t\tconst storage = new InMemorySettingsStorage();\n\t\treturn new SettingsManager(storage, settings, {});\n\t}\n\n\tprivate static loadFromStorage(storage: SettingsStorage, scope: SettingsScope): Settings {\n\t\tlet content: string | undefined;\n\t\tstorage.withLock(scope, (current) => {\n\t\t\tcontent = current;\n\t\t\treturn undefined;\n\t\t});\n\n\t\tif (!content) {\n\t\t\treturn {};\n\t\t}\n\t\tconst settings = JSON.parse(content);\n\t\treturn SettingsManager.migrateSettings(settings);\n\t}\n\n\tprivate static tryLoadFromStorage(\n\t\tstorage: SettingsStorage,\n\t\tscope: SettingsScope,\n\t): { settings: Settings; error: Error | null } {\n\t\ttry {\n\t\t\treturn { settings: SettingsManager.loadFromStorage(storage, scope), error: null };\n\t\t} catch (error) {\n\t\t\treturn { settings: {}, error: error as Error };\n\t\t}\n\t}\n\n\t/**\n\t * Normalize the two known lazy-context trust fields of a `context` slice to fail-closed\n\t * defaults when malformed, preserving valid values and any unrelated keys. Used at persist\n\t * time so a single-field trust write cannot leave a malformed sibling (read fresh from disk)\n\t * that would invalidate — and therefore silently disable — the entire trust policy.\n\t */\n\tprivate static sanitizeContextTrustSlice(nested: Record<string, unknown>): Record<string, unknown> {\n\t\tconst sanitized = { ...nested };\n\t\tif (\"autoLoadNested\" in sanitized && typeof sanitized.autoLoadNested !== \"boolean\") {\n\t\t\tsanitized.autoLoadNested = false;\n\t\t}\n\t\tif (\n\t\t\t\"trustedFolders\" in sanitized &&\n\t\t\t(!Array.isArray(sanitized.trustedFolders) ||\n\t\t\t\tsanitized.trustedFolders.some((folder) => typeof folder !== \"string\"))\n\t\t) {\n\t\t\tsanitized.trustedFolders = [];\n\t\t}\n\t\treturn sanitized;\n\t}\n\n\t/** Migrate old settings format to new format */\n\tprivate static migrateSettings(settings: Record<string, unknown>): Settings {\n\t\t// Migrate queueMode -> steeringMode\n\t\tif (\"queueMode\" in settings && !(\"steeringMode\" in settings)) {\n\t\t\tsettings.steeringMode = settings.queueMode;\n\t\t\tdelete settings.queueMode;\n\t\t}\n\n\t\t// Migrate legacy websockets boolean -> transport enum\n\t\tif (!(\"transport\" in settings) && typeof settings.websockets === \"boolean\") {\n\t\t\tsettings.transport = settings.websockets ? \"websocket\" : \"sse\";\n\t\t\tdelete settings.websockets;\n\t\t}\n\n\t\t// Migrate old skills object format to new array format\n\t\tif (\n\t\t\t\"skills\" in settings &&\n\t\t\ttypeof settings.skills === \"object\" &&\n\t\t\tsettings.skills !== null &&\n\t\t\t!Array.isArray(settings.skills)\n\t\t) {\n\t\t\tconst skillsSettings = settings.skills as {\n\t\t\t\tenableSkillCommands?: boolean;\n\t\t\t\tcustomDirectories?: unknown;\n\t\t\t};\n\t\t\tif (skillsSettings.enableSkillCommands !== undefined && settings.enableSkillCommands === undefined) {\n\t\t\t\tsettings.enableSkillCommands = skillsSettings.enableSkillCommands;\n\t\t\t}\n\t\t\tif (Array.isArray(skillsSettings.customDirectories) && skillsSettings.customDirectories.length > 0) {\n\t\t\t\tsettings.skills = skillsSettings.customDirectories;\n\t\t\t} else {\n\t\t\t\tdelete settings.skills;\n\t\t\t}\n\t\t}\n\n\t\treturn settings as Settings;\n\t}\n\n\tgetGlobalSettings(): Settings {\n\t\treturn structuredClone(this.globalSettings);\n\t}\n\n\tgetProjectSettings(): Settings {\n\t\treturn structuredClone(this.projectSettings);\n\t}\n\n\treload(): void {\n\t\tconst globalLoad = SettingsManager.tryLoadFromStorage(this.storage, \"global\");\n\t\tif (!globalLoad.error) {\n\t\t\tthis.globalSettings = globalLoad.settings;\n\t\t\tthis.globalSettingsLoadError = null;\n\t\t} else {\n\t\t\tthis.globalSettingsLoadError = globalLoad.error;\n\t\t\tthis.recordError(\"global\", globalLoad.error);\n\t\t}\n\n\t\tthis.modifiedFields.clear();\n\t\tthis.modifiedNestedFields.clear();\n\t\tthis.modifiedProjectFields.clear();\n\t\tthis.modifiedProjectNestedFields.clear();\n\n\t\tconst projectLoad = SettingsManager.tryLoadFromStorage(this.storage, \"project\");\n\t\tif (!projectLoad.error) {\n\t\t\tthis.projectSettings = projectLoad.settings;\n\t\t\tthis.projectSettingsLoadError = null;\n\t\t} else {\n\t\t\tthis.projectSettingsLoadError = projectLoad.error;\n\t\t\tthis.recordError(\"project\", projectLoad.error);\n\t\t}\n\n\t\tthis.settings = deepMergeSettings(this.globalSettings, this.projectSettings);\n\t}\n\n\t/** Apply additional overrides on top of current settings */\n\tapplyOverrides(overrides: Partial<Settings>): void {\n\t\tthis.settings = deepMergeSettings(this.settings, overrides);\n\t}\n\n\t/** Mark a global field as modified during this session */\n\tprivate markModified(field: keyof Settings, nestedKey?: string): void {\n\t\tthis.modifiedFields.add(field);\n\t\tif (nestedKey) {\n\t\t\tif (!this.modifiedNestedFields.has(field)) {\n\t\t\t\tthis.modifiedNestedFields.set(field, new Set());\n\t\t\t}\n\t\t\tthis.modifiedNestedFields.get(field)!.add(nestedKey);\n\t\t}\n\t}\n\n\t/** Mark a project field as modified during this session */\n\tprivate markProjectModified(field: keyof Settings, nestedKey?: string): void {\n\t\tthis.modifiedProjectFields.add(field);\n\t\tif (nestedKey) {\n\t\t\tif (!this.modifiedProjectNestedFields.has(field)) {\n\t\t\t\tthis.modifiedProjectNestedFields.set(field, new Set());\n\t\t\t}\n\t\t\tthis.modifiedProjectNestedFields.get(field)!.add(nestedKey);\n\t\t}\n\t}\n\n\tprivate recordError(scope: SettingsScope, error: unknown): void {\n\t\tconst normalizedError = error instanceof Error ? error : new Error(String(error));\n\t\tthis.errors.push({ scope, error: normalizedError });\n\t}\n\n\tprivate refreshGlobalContextFromStorage(options: { clearContextOnError?: boolean } = {}): boolean {\n\t\t// Keep a just-selected UI value effective until its queued durable write completes;\n\t\t// otherwise always re-read the external global source for cross-process changes.\n\t\tif (this.storage instanceof InMemorySettingsStorage || this.modifiedFields.has(\"context\")) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst loaded = SettingsManager.tryLoadFromStorage(this.storage, \"global\");\n\t\tif (loaded.error) {\n\t\t\tthis.recordError(\"global\", loaded.error);\n\t\t\tif (options.clearContextOnError) {\n\t\t\t\tthis.globalSettings = { ...this.globalSettings, context: undefined };\n\t\t\t\tthis.settings = deepMergeSettings(this.globalSettings, this.projectSettings);\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\n\t\t// This re-read owns only the security-policy slice. Preserve every other\n\t\t// in-memory global field, including writes that are queued but not yet durable.\n\t\tthis.globalSettings = { ...this.globalSettings, context: loaded.settings.context };\n\t\tthis.settings = deepMergeSettings(this.globalSettings, this.projectSettings);\n\t\treturn true;\n\t}\n\n\tprivate refreshGlobalSubagentArbiterFromStorage(): void {\n\t\t// Keep a locally selected policy effective until its queued write completes;\n\t\t// otherwise re-read the global slice so long-lived sessions observe dashboard\n\t\t// and TUI changes made by another runtime.\n\t\tif (this.storage instanceof InMemorySettingsStorage || this.modifiedFields.has(\"subagentArbiter\")) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst loaded = SettingsManager.tryLoadFromStorage(this.storage, \"global\");\n\t\tif (loaded.error) {\n\t\t\tthis.recordError(\"global\", loaded.error);\n\t\t\tthis.globalSettings = { ...this.globalSettings, subagentArbiter: undefined };\n\t\t\tthis.settings = deepMergeSettings(this.globalSettings, this.projectSettings);\n\t\t\tthrow new Error(`Could not reload global Dispatch Arbiter settings: ${loaded.error.message}`);\n\t\t}\n\n\t\t// This refresh owns only the global-only arbiter slice. Preserve unrelated\n\t\t// in-memory settings, including writes that are queued but not yet durable.\n\t\tthis.globalSettings = { ...this.globalSettings, subagentArbiter: loaded.settings.subagentArbiter };\n\t\tthis.settings = deepMergeSettings(this.globalSettings, this.projectSettings);\n\t}\n\n\tprivate clearModifiedScope(scope: SettingsScope): void {\n\t\tif (scope === \"global\") {\n\t\t\tthis.modifiedFields.clear();\n\t\t\tthis.modifiedNestedFields.clear();\n\t\t\treturn;\n\t\t}\n\n\t\tthis.modifiedProjectFields.clear();\n\t\tthis.modifiedProjectNestedFields.clear();\n\t}\n\n\tprivate enqueueWrite(scope: SettingsScope, task: () => void): void {\n\t\tthis.writeQueue = this.writeQueue\n\t\t\t.then(() => {\n\t\t\t\ttask();\n\t\t\t\tthis.clearModifiedScope(scope);\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tthis.recordError(scope, error);\n\t\t\t});\n\t}\n\n\tprivate cloneModifiedNestedFields(source: Map<keyof Settings, Set<string>>): Map<keyof Settings, Set<string>> {\n\t\tconst snapshot = new Map<keyof Settings, Set<string>>();\n\t\tfor (const [key, value] of source.entries()) {\n\t\t\tsnapshot.set(key, new Set(value));\n\t\t}\n\t\treturn snapshot;\n\t}\n\n\tprivate persistScopedSettings(\n\t\tscope: SettingsScope,\n\t\tsnapshotSettings: Settings,\n\t\tmodifiedFields: Set<keyof Settings>,\n\t\tmodifiedNestedFields: Map<keyof Settings, Set<string>>,\n\t): void {\n\t\tthis.storage.withLock(scope, (current) => {\n\t\t\tconst currentFileSettings = current\n\t\t\t\t? SettingsManager.migrateSettings(JSON.parse(current) as Record<string, unknown>)\n\t\t\t\t: {};\n\t\t\tconst mergedSettings: Settings = { ...currentFileSettings };\n\t\t\tfor (const field of modifiedFields) {\n\t\t\t\tconst value = snapshotSettings[field];\n\t\t\t\tif (modifiedNestedFields.has(field) && typeof value === \"object\" && value !== null) {\n\t\t\t\t\tconst nestedModified = modifiedNestedFields.get(field)!;\n\t\t\t\t\tconst baseNested = (currentFileSettings[field] as Record<string, unknown>) ?? {};\n\t\t\t\t\tconst inMemoryNested = value as Record<string, unknown>;\n\t\t\t\t\tlet mergedNested = { ...baseNested };\n\t\t\t\t\tfor (const nestedKey of nestedModified) {\n\t\t\t\t\t\tmergedNested[nestedKey] = inMemoryNested[nestedKey];\n\t\t\t\t\t}\n\t\t\t\t\t// The global context-trust slice is security-sensitive: an untouched sibling\n\t\t\t\t\t// is preserved from the fresh on-disk read above, but a malformed on-disk\n\t\t\t\t\t// sibling must still collapse to a fail-closed default so a successful trust\n\t\t\t\t\t// mutation cannot leave the whole policy invalid (and thus silently disabled).\n\t\t\t\t\tif (scope === \"global\" && field === \"context\") {\n\t\t\t\t\t\tmergedNested = SettingsManager.sanitizeContextTrustSlice(mergedNested);\n\t\t\t\t\t}\n\t\t\t\t\t(mergedSettings as Record<string, unknown>)[field] = mergedNested;\n\t\t\t\t} else {\n\t\t\t\t\t(mergedSettings as Record<string, unknown>)[field] = value;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn JSON.stringify(mergedSettings, null, 2);\n\t\t});\n\t}\n\n\tprivate save(): void {\n\t\tthis.settings = deepMergeSettings(this.globalSettings, this.projectSettings);\n\n\t\tif (this.globalSettingsLoadError) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst snapshotGlobalSettings = structuredClone(this.globalSettings);\n\t\tconst modifiedFields = new Set(this.modifiedFields);\n\t\tconst modifiedNestedFields = this.cloneModifiedNestedFields(this.modifiedNestedFields);\n\n\t\tthis.enqueueWrite(\"global\", () => {\n\t\t\tthis.persistScopedSettings(\"global\", snapshotGlobalSettings, modifiedFields, modifiedNestedFields);\n\t\t});\n\t}\n\n\tprivate saveProjectSettings(settings: Settings): void {\n\t\tthis.projectSettings = structuredClone(settings);\n\t\tthis.settings = deepMergeSettings(this.globalSettings, this.projectSettings);\n\n\t\tif (this.projectSettingsLoadError) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst snapshotProjectSettings = structuredClone(this.projectSettings);\n\t\tconst modifiedFields = new Set(this.modifiedProjectFields);\n\t\tconst modifiedNestedFields = this.cloneModifiedNestedFields(this.modifiedProjectNestedFields);\n\t\tthis.enqueueWrite(\"project\", () => {\n\t\t\tthis.persistScopedSettings(\"project\", snapshotProjectSettings, modifiedFields, modifiedNestedFields);\n\t\t});\n\t}\n\n\tasync flush(): Promise<void> {\n\t\tawait this.writeQueue;\n\t}\n\n\t/**\n\t * True when the global settings file failed to load/parse. In that state {@link save}\n\t * silently no-ops (to avoid stomping the corrupt file), so callers that need write\n\t * durability must check this and fail loudly instead of reporting success.\n\t */\n\thasGlobalSettingsLoadError(): boolean {\n\t\treturn this.globalSettingsLoadError !== null;\n\t}\n\n\t/** True when the project settings file failed to load or parse. */\n\thasProjectSettingsLoadError(): boolean {\n\t\treturn this.projectSettingsLoadError !== null;\n\t}\n\n\tdrainErrors(): SettingsError[] {\n\t\tconst drained = [...this.errors];\n\t\tthis.errors = [];\n\t\treturn drained;\n\t}\n\n\tgetSessionDir(): string | undefined {\n\t\treturn this.settings.sessionDir;\n\t}\n\n\tgetDefaultProvider(): string | undefined {\n\t\treturn this.settings.defaultProvider;\n\t}\n\n\tgetDefaultModel(): string | undefined {\n\t\treturn this.settings.defaultModel;\n\t}\n\n\tsetDefaultProvider(provider: string): void {\n\t\tthis.globalSettings.defaultProvider = provider;\n\t\tthis.markModified(\"defaultProvider\");\n\t\tthis.save();\n\t}\n\n\tsetDefaultModel(modelId: string): void {\n\t\tthis.globalSettings.defaultModel = modelId;\n\t\tthis.markModified(\"defaultModel\");\n\t\tthis.save();\n\t}\n\n\tsetDefaultModelAndProvider(provider: string, modelId: string): void {\n\t\tthis.globalSettings.defaultProvider = provider;\n\t\tthis.globalSettings.defaultModel = modelId;\n\t\tthis.markModified(\"defaultProvider\");\n\t\tthis.markModified(\"defaultModel\");\n\t\tthis.save();\n\t}\n\n\tgetSteeringMode(): \"all\" | \"one-at-a-time\" {\n\t\treturn this.settings.steeringMode || \"one-at-a-time\";\n\t}\n\n\tsetSteeringMode(mode: \"all\" | \"one-at-a-time\"): void {\n\t\tthis.globalSettings.steeringMode = mode;\n\t\tthis.markModified(\"steeringMode\");\n\t\tthis.save();\n\t}\n\n\tgetFollowUpMode(): \"all\" | \"one-at-a-time\" {\n\t\treturn this.settings.followUpMode || \"one-at-a-time\";\n\t}\n\n\tsetFollowUpMode(mode: \"all\" | \"one-at-a-time\"): void {\n\t\tthis.globalSettings.followUpMode = mode;\n\t\tthis.markModified(\"followUpMode\");\n\t\tthis.save();\n\t}\n\n\tgetTheme(): string | undefined {\n\t\treturn this.settings.theme;\n\t}\n\n\tsetTheme(theme: string): void {\n\t\tthis.globalSettings.theme = theme;\n\t\tthis.markModified(\"theme\");\n\t\tthis.save();\n\t}\n\n\tgetDefaultThinkingLevel(): \"off\" | \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\" | undefined {\n\t\treturn this.settings.defaultThinkingLevel;\n\t}\n\n\tsetDefaultThinkingLevel(level: \"off\" | \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\"): void {\n\t\tthis.globalSettings.defaultThinkingLevel = level;\n\t\tthis.markModified(\"defaultThinkingLevel\");\n\t\tthis.save();\n\t}\n\n\tgetTransport(): TransportSetting {\n\t\treturn this.settings.transport ?? \"sse\";\n\t}\n\n\tsetTransport(transport: TransportSetting): void {\n\t\tthis.globalSettings.transport = transport;\n\t\tthis.markModified(\"transport\");\n\t\tthis.save();\n\t}\n\n\tgetCompactionEnabled(): boolean {\n\t\treturn this.settings.compaction?.enabled ?? true;\n\t}\n\n\tsetCompactionEnabled(enabled: boolean): void {\n\t\tif (!this.globalSettings.compaction) {\n\t\t\tthis.globalSettings.compaction = {};\n\t\t}\n\t\tthis.globalSettings.compaction.enabled = enabled;\n\t\tthis.markModified(\"compaction\", \"enabled\");\n\t\tthis.save();\n\t}\n\n\t/**\n\t * Read the global-only lazy-context policy. File-backed managers re-read this small\n\t * policy on each decision so independently running main/subagent processes observe\n\t * external global settings writes without ever consulting project settings. A malformed\n\t * global file fails closed rather than retaining a previously permissive value.\n\t */\n\tgetGlobalContextTrustPolicy(): ContextTrustPolicy {\n\t\tif (!this.refreshGlobalContextFromStorage()) {\n\t\t\treturn { unrestricted: false, trustedFolders: [] };\n\t\t}\n\n\t\tconst context = this.globalSettings.context;\n\t\t// A valid JSON file with a malformed security policy is also fail-closed. Do not\n\t\t// coerce strings/truthy values or partially accept an invalid trusted-folder list.\n\t\tif (\n\t\t\tcontext !== undefined &&\n\t\t\t(typeof context !== \"object\" ||\n\t\t\t\tcontext === null ||\n\t\t\t\t(context.autoLoadNested !== undefined && typeof context.autoLoadNested !== \"boolean\") ||\n\t\t\t\t(context.trustedFolders !== undefined &&\n\t\t\t\t\t(!Array.isArray(context.trustedFolders) ||\n\t\t\t\t\t\tcontext.trustedFolders.some((folder) => typeof folder !== \"string\"))))\n\t\t) {\n\t\t\tconst error = new Error(\n\t\t\t\t\"Global context trust settings are malformed; lazy nested context loading is disabled\",\n\t\t\t);\n\t\t\tthis.recordError(\"global\", error);\n\t\t\treturn { unrestricted: false, trustedFolders: [] };\n\t\t}\n\n\t\treturn {\n\t\t\tunrestricted: context?.autoLoadNested ?? false,\n\t\t\ttrustedFolders: context?.trustedFolders ? [...context.trustedFolders] : [],\n\t\t};\n\t}\n\n\t/** Effective unrestricted flag; intentionally reads global settings only. */\n\tgetAutoLoadNestedContext(): boolean {\n\t\treturn this.getGlobalContextTrustPolicy().unrestricted;\n\t}\n\n\tgetTrustedContextFolders(): string[] {\n\t\treturn this.getGlobalContextTrustPolicy().trustedFolders;\n\t}\n\n\tgetConfiguredTrustedContextFolders(): string[] {\n\t\tif (!this.refreshGlobalContextFromStorage()) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst context = this.globalSettings.context;\n\t\tif (context === undefined || typeof context !== \"object\" || context === null || Array.isArray(context)) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst trustedFolders = (context as Record<string, unknown>).trustedFolders;\n\t\tif (trustedFolders === undefined) {\n\t\t\treturn [];\n\t\t}\n\t\tif (!Array.isArray(trustedFolders) || trustedFolders.some((folder) => typeof folder !== \"string\")) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn [...trustedFolders];\n\t}\n\n\tsetAutoLoadNestedContext(enabled: boolean): void {\n\t\tthis.setContextTrust({ autoLoadNested: enabled });\n\t}\n\n\t/**\n\t * Atomically persist one or both global lazy-context trust policy fields. Every trust\n\t * write normalizes both known fields, so a malformed on-disk sibling cannot make an\n\t * otherwise successful mutation silently fail closed.\n\t */\n\tsetContextTrust(update: { autoLoadNested?: boolean; trustedFolders?: string[] }): void {\n\t\tif (update.autoLoadNested !== undefined && typeof update.autoLoadNested !== \"boolean\") {\n\t\t\tthrow new Error(\"Auto-load nested context must be a boolean\");\n\t\t}\n\t\tif (\n\t\t\tupdate.trustedFolders !== undefined &&\n\t\t\t(!Array.isArray(update.trustedFolders) || update.trustedFolders.some((folder) => typeof folder !== \"string\"))\n\t\t) {\n\t\t\tthrow new Error(\"Trusted context folders must be an array of strings\");\n\t\t}\n\n\t\t// Refresh the in-memory context slice from the external global file unless a context\n\t\t// write is already pending, so an unspecified sibling reflects concurrent cross-process\n\t\t// changes (e.g. a folder just untrusted elsewhere) instead of a stale in-memory value.\n\t\t// A pending context write already owns the authoritative in-memory value; do not stomp\n\t\t// it. Fail closed if the external file is unreadable.\n\t\tthis.refreshGlobalContextFromStorage({ clearContextOnError: true });\n\n\t\tconst currentContext = this.globalSettings.context;\n\t\tconst current =\n\t\t\ttypeof currentContext === \"object\" && currentContext !== null && !Array.isArray(currentContext)\n\t\t\t\t? (currentContext as Record<string, unknown>)\n\t\t\t\t: {};\n\t\tconst autoLoadNested =\n\t\t\tupdate.autoLoadNested ?? (typeof current.autoLoadNested === \"boolean\" ? current.autoLoadNested : false);\n\t\tconst currentTrustedFolders =\n\t\t\tArray.isArray(current.trustedFolders) && current.trustedFolders.every((folder) => typeof folder === \"string\")\n\t\t\t\t? (current.trustedFolders as string[])\n\t\t\t\t: [];\n\t\tconst trustedFolders = update.trustedFolders ?? currentTrustedFolders;\n\n\t\tthis.globalSettings.context = {\n\t\t\t...current,\n\t\t\tautoLoadNested,\n\t\t\ttrustedFolders: [...trustedFolders],\n\t\t};\n\t\t// Mark only the explicitly-supplied fields modified. persistScopedSettings then\n\t\t// preserves an untouched sibling from the fresh on-disk slice read inside the storage\n\t\t// lock, so a single-field write can no longer clobber a concurrent external change to\n\t\t// the other field. Malformed on-disk siblings are still normalized fail-closed there.\n\t\tif (update.autoLoadNested !== undefined) {\n\t\t\tthis.markModified(\"context\", \"autoLoadNested\");\n\t\t}\n\t\tif (update.trustedFolders !== undefined) {\n\t\t\tthis.markModified(\"context\", \"trustedFolders\");\n\t\t}\n\t\tthis.save();\n\t}\n\n\tsetTrustedContextFolders(folders: string[]): void {\n\t\tthis.setContextTrust({ trustedFolders: folders });\n\t}\n\n\taddTrustedContextFolder(folder: string): void {\n\t\tif (typeof folder !== \"string\" || folder === \"\") {\n\t\t\tthrow new Error(\"Trusted context folder must be a non-empty string\");\n\t\t}\n\t\tconst folders = this.getConfiguredTrustedContextFolders();\n\t\tif (!folders.includes(folder)) folders.push(folder);\n\t\tthis.setTrustedContextFolders(folders);\n\t}\n\n\tremoveTrustedContextFolder(folder: string): void {\n\t\tthis.setTrustedContextFolders(this.getConfiguredTrustedContextFolders().filter((current) => current !== folder));\n\t}\n\n\tgetCompactionReserveTokens(): number {\n\t\treturn this.settings.compaction?.reserveTokens ?? 16384;\n\t}\n\n\tgetCompactionKeepRecentTokens(): number {\n\t\treturn this.settings.compaction?.keepRecentTokens ?? 20000;\n\t}\n\n\tgetCompactionSettings(): { enabled: boolean; reserveTokens: number; keepRecentTokens: number } {\n\t\treturn {\n\t\t\tenabled: this.getCompactionEnabled(),\n\t\t\treserveTokens: this.getCompactionReserveTokens(),\n\t\t\tkeepRecentTokens: this.getCompactionKeepRecentTokens(),\n\t\t};\n\t}\n\n\tgetBranchSummarySettings(): { reserveTokens: number; skipPrompt: boolean } {\n\t\treturn {\n\t\t\treserveTokens: this.settings.branchSummary?.reserveTokens ?? 16384,\n\t\t\tskipPrompt: this.settings.branchSummary?.skipPrompt ?? false,\n\t\t};\n\t}\n\n\tgetBranchSummarySkipPrompt(): boolean {\n\t\treturn this.settings.branchSummary?.skipPrompt ?? false;\n\t}\n\n\tgetRetryEnabled(): boolean {\n\t\treturn this.settings.retry?.enabled ?? true;\n\t}\n\n\tsetRetryEnabled(enabled: boolean): void {\n\t\tif (!this.globalSettings.retry) {\n\t\t\tthis.globalSettings.retry = {};\n\t\t}\n\t\tthis.globalSettings.retry.enabled = enabled;\n\t\tthis.markModified(\"retry\", \"enabled\");\n\t\tthis.save();\n\t}\n\n\tgetRetrySettings(): { enabled: boolean; maxRetries: number; baseDelayMs: number; maxDelayMs: number } {\n\t\treturn {\n\t\t\tenabled: this.getRetryEnabled(),\n\t\t\tmaxRetries: this.settings.retry?.maxRetries ?? 3,\n\t\t\tbaseDelayMs: this.settings.retry?.baseDelayMs ?? 2000,\n\t\t\tmaxDelayMs: this.settings.retry?.maxDelayMs ?? 60000,\n\t\t};\n\t}\n\n\tgetBackgroundAgentGuardrailEnabled(): boolean {\n\t\treturn this.settings.backgroundAgents?.parentTurnGuardrail ?? true;\n\t}\n\n\tsetBackgroundAgentGuardrailEnabled(enabled: boolean): void {\n\t\tif (!this.globalSettings.backgroundAgents) {\n\t\t\tthis.globalSettings.backgroundAgents = {};\n\t\t}\n\t\tthis.globalSettings.backgroundAgents.parentTurnGuardrail = enabled;\n\t\tthis.markModified(\"backgroundAgents\", \"parentTurnGuardrail\");\n\t\tthis.save();\n\t}\n\n\tgetBackgroundAgentGuardrailSettings(): { enabled: boolean; turnLimit: number } {\n\t\tconst rawLimit = this.settings.backgroundAgents?.parentTurnLimit;\n\t\tconst turnLimit =\n\t\t\ttypeof rawLimit === \"number\" && Number.isFinite(rawLimit) && rawLimit >= 1\n\t\t\t\t? rawLimit\n\t\t\t\t: DEFAULT_BG_PARENT_TURN_LIMIT;\n\t\treturn {\n\t\t\tenabled: this.getBackgroundAgentGuardrailEnabled(),\n\t\t\tturnLimit,\n\t\t};\n\t}\n\n\tgetMaxConcurrentSubagents(): number {\n\t\tconst value = this.settings.backgroundAgents?.maxConcurrentSubagents;\n\t\tif (value === undefined) {\n\t\t\treturn DEFAULT_MAX_CONCURRENT_SUBAGENTS;\n\t\t}\n\t\tif (typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0) {\n\t\t\treturn value;\n\t\t}\n\t\tlog.warn(\n\t\t\t`[settings] Ignoring invalid backgroundAgents.maxConcurrentSubagents ${JSON.stringify(value)}; ` +\n\t\t\t\t`it must be a non-negative whole number. Falling back to ${DEFAULT_MAX_CONCURRENT_SUBAGENTS}. ` +\n\t\t\t\t\"Fix the value in your settings file to silence this warning.\",\n\t\t);\n\t\treturn DEFAULT_MAX_CONCURRENT_SUBAGENTS;\n\t}\n\n\tsetMaxConcurrentSubagents(value: number): void {\n\t\tif (!Number.isSafeInteger(value) || value < 0) {\n\t\t\tthrow new Error(\"maxConcurrentSubagents must be a non-negative whole number\");\n\t\t}\n\t\tif (!this.globalSettings.backgroundAgents) {\n\t\t\tthis.globalSettings.backgroundAgents = {};\n\t\t}\n\t\tthis.globalSettings.backgroundAgents.maxConcurrentSubagents = value;\n\t\tthis.markModified(\"backgroundAgents\", \"maxConcurrentSubagents\");\n\t\tthis.save();\n\t}\n\n\tgetHideThinkingBlock(): boolean {\n\t\treturn this.settings.hideThinkingBlock ?? false;\n\t}\n\n\tsetHideThinkingBlock(hide: boolean): void {\n\t\tthis.globalSettings.hideThinkingBlock = hide;\n\t\tthis.markModified(\"hideThinkingBlock\");\n\t\tthis.save();\n\t}\n\n\tgetShellPath(): string | undefined {\n\t\treturn this.settings.shellPath;\n\t}\n\n\tsetShellPath(path: string | undefined): void {\n\t\tthis.globalSettings.shellPath = path;\n\t\tthis.markModified(\"shellPath\");\n\t\tthis.save();\n\t}\n\n\tgetQuietStartup(): boolean {\n\t\treturn this.settings.quietStartup ?? false;\n\t}\n\n\tsetQuietStartup(quiet: boolean): void {\n\t\tthis.globalSettings.quietStartup = quiet;\n\t\tthis.markModified(\"quietStartup\");\n\t\tthis.save();\n\t}\n\n\tgetShellCommandPrefix(): string | undefined {\n\t\treturn this.settings.shellCommandPrefix;\n\t}\n\n\tsetShellCommandPrefix(prefix: string | undefined): void {\n\t\tthis.globalSettings.shellCommandPrefix = prefix;\n\t\tthis.markModified(\"shellCommandPrefix\");\n\t\tthis.save();\n\t}\n\n\tgetNpmCommand(): string[] | undefined {\n\t\treturn this.settings.npmCommand ? [...this.settings.npmCommand] : undefined;\n\t}\n\n\tsetNpmCommand(command: string[] | undefined): void {\n\t\tthis.globalSettings.npmCommand = command ? [...command] : undefined;\n\t\tthis.markModified(\"npmCommand\");\n\t\tthis.save();\n\t}\n\n\tgetPackages(): PackageSource[] {\n\t\treturn [...(this.settings.packages ?? [])];\n\t}\n\n\tsetPackages(packages: PackageSource[]): void {\n\t\tthis.globalSettings.packages = packages;\n\t\tthis.markModified(\"packages\");\n\t\tthis.save();\n\t}\n\n\tsetProjectPackages(packages: PackageSource[]): void {\n\t\tconst projectSettings = structuredClone(this.projectSettings);\n\t\tprojectSettings.packages = packages;\n\t\tthis.markProjectModified(\"packages\");\n\t\tthis.saveProjectSettings(projectSettings);\n\t}\n\n\tgetExtensionPaths(): string[] {\n\t\treturn [...(this.settings.extensions ?? [])];\n\t}\n\n\tsetExtensionPaths(paths: string[]): void {\n\t\tthis.globalSettings.extensions = paths;\n\t\tthis.markModified(\"extensions\");\n\t\tthis.save();\n\t}\n\n\tsetProjectExtensionPaths(paths: string[]): void {\n\t\tconst projectSettings = structuredClone(this.projectSettings);\n\t\tprojectSettings.extensions = paths;\n\t\tthis.markProjectModified(\"extensions\");\n\t\tthis.saveProjectSettings(projectSettings);\n\t}\n\n\tgetSkillPaths(): string[] {\n\t\treturn [...(this.settings.skills ?? [])];\n\t}\n\n\tsetSkillPaths(paths: string[]): void {\n\t\tthis.globalSettings.skills = paths;\n\t\tthis.markModified(\"skills\");\n\t\tthis.save();\n\t}\n\n\tsetProjectSkillPaths(paths: string[]): void {\n\t\tconst projectSettings = structuredClone(this.projectSettings);\n\t\tprojectSettings.skills = paths;\n\t\tthis.markProjectModified(\"skills\");\n\t\tthis.saveProjectSettings(projectSettings);\n\t}\n\n\tgetPromptTemplatePaths(): string[] {\n\t\treturn [...(this.settings.prompts ?? [])];\n\t}\n\n\tsetPromptTemplatePaths(paths: string[]): void {\n\t\tthis.globalSettings.prompts = paths;\n\t\tthis.markModified(\"prompts\");\n\t\tthis.save();\n\t}\n\n\tsetProjectPromptTemplatePaths(paths: string[]): void {\n\t\tconst projectSettings = structuredClone(this.projectSettings);\n\t\tprojectSettings.prompts = paths;\n\t\tthis.markProjectModified(\"prompts\");\n\t\tthis.saveProjectSettings(projectSettings);\n\t}\n\n\tgetThemePaths(): string[] {\n\t\treturn [...(this.settings.themes ?? [])];\n\t}\n\n\tsetThemePaths(paths: string[]): void {\n\t\tthis.globalSettings.themes = paths;\n\t\tthis.markModified(\"themes\");\n\t\tthis.save();\n\t}\n\n\tsetProjectThemePaths(paths: string[]): void {\n\t\tconst projectSettings = structuredClone(this.projectSettings);\n\t\tprojectSettings.themes = paths;\n\t\tthis.markProjectModified(\"themes\");\n\t\tthis.saveProjectSettings(projectSettings);\n\t}\n\n\tgetEnableSkillCommands(): boolean {\n\t\treturn this.settings.enableSkillCommands ?? true;\n\t}\n\n\tsetEnableSkillCommands(enabled: boolean): void {\n\t\tthis.globalSettings.enableSkillCommands = enabled;\n\t\tthis.markModified(\"enableSkillCommands\");\n\t\tthis.save();\n\t}\n\n\tgetThinkingBudgets(): ThinkingBudgetsSettings | undefined {\n\t\treturn this.settings.thinkingBudgets;\n\t}\n\n\tgetShowImages(): boolean {\n\t\treturn this.settings.terminal?.showImages ?? true;\n\t}\n\n\tsetShowImages(show: boolean): void {\n\t\tif (!this.globalSettings.terminal) {\n\t\t\tthis.globalSettings.terminal = {};\n\t\t}\n\t\tthis.globalSettings.terminal.showImages = show;\n\t\tthis.markModified(\"terminal\", \"showImages\");\n\t\tthis.save();\n\t}\n\n\tgetImageAutoResize(): boolean {\n\t\treturn this.settings.images?.autoResize ?? true;\n\t}\n\n\tsetImageAutoResize(enabled: boolean): void {\n\t\tif (!this.globalSettings.images) {\n\t\t\tthis.globalSettings.images = {};\n\t\t}\n\t\tthis.globalSettings.images.autoResize = enabled;\n\t\tthis.markModified(\"images\", \"autoResize\");\n\t\tthis.save();\n\t}\n\n\tgetBlockImages(): boolean {\n\t\treturn this.settings.images?.blockImages ?? false;\n\t}\n\n\tsetBlockImages(blocked: boolean): void {\n\t\tif (!this.globalSettings.images) {\n\t\t\tthis.globalSettings.images = {};\n\t\t}\n\t\tthis.globalSettings.images.blockImages = blocked;\n\t\tthis.markModified(\"images\", \"blockImages\");\n\t\tthis.save();\n\t}\n\n\tgetEnabledModels(): string[] | undefined {\n\t\treturn this.settings.enabledModels;\n\t}\n\n\tsetEnabledModels(patterns: string[] | undefined): void {\n\t\tthis.globalSettings.enabledModels = patterns;\n\t\tthis.markModified(\"enabledModels\");\n\t\tthis.save();\n\t}\n\n\t/** Whether project settings explicitly replace the global enabled-model scope. */\n\thasProjectEnabledModelsOverride(): boolean {\n\t\treturn this.projectSettings.enabledModels !== undefined;\n\t}\n\n\tgetDoubleEscapeAction(): \"fork\" | \"tree\" | \"none\" {\n\t\treturn this.settings.doubleEscapeAction ?? \"tree\";\n\t}\n\n\tsetDoubleEscapeAction(action: \"fork\" | \"tree\" | \"none\"): void {\n\t\tthis.globalSettings.doubleEscapeAction = action;\n\t\tthis.markModified(\"doubleEscapeAction\");\n\t\tthis.save();\n\t}\n\n\tgetTreeFilterMode(): \"default\" | \"no-tools\" | \"user-only\" | \"labeled-only\" | \"all\" {\n\t\tconst mode = this.settings.treeFilterMode;\n\t\tconst valid = [\"default\", \"no-tools\", \"user-only\", \"labeled-only\", \"all\"];\n\t\treturn mode && valid.includes(mode) ? mode : \"default\";\n\t}\n\n\tsetTreeFilterMode(mode: \"default\" | \"no-tools\" | \"user-only\" | \"labeled-only\" | \"all\"): void {\n\t\tthis.globalSettings.treeFilterMode = mode;\n\t\tthis.markModified(\"treeFilterMode\");\n\t\tthis.save();\n\t}\n\n\tgetShowHardwareCursor(): boolean {\n\t\treturn this.settings.showHardwareCursor ?? process.env.DREB_HARDWARE_CURSOR === \"1\";\n\t}\n\n\tsetShowHardwareCursor(enabled: boolean): void {\n\t\tthis.globalSettings.showHardwareCursor = enabled;\n\t\tthis.markModified(\"showHardwareCursor\");\n\t\tthis.save();\n\t}\n\n\tgetEditorPaddingX(): number {\n\t\treturn this.settings.editorPaddingX ?? 0;\n\t}\n\n\tsetEditorPaddingX(padding: number): void {\n\t\tthis.globalSettings.editorPaddingX = Math.max(0, Math.min(3, Math.floor(padding)));\n\t\tthis.markModified(\"editorPaddingX\");\n\t\tthis.save();\n\t}\n\n\tgetAutocompleteMaxVisible(): number {\n\t\treturn this.settings.autocompleteMaxVisible ?? 5;\n\t}\n\n\tsetAutocompleteMaxVisible(maxVisible: number): void {\n\t\tthis.globalSettings.autocompleteMaxVisible = Math.max(3, Math.min(20, Math.floor(maxVisible)));\n\t\tthis.markModified(\"autocompleteMaxVisible\");\n\t\tthis.save();\n\t}\n\n\tgetCodeBlockIndent(): string {\n\t\treturn this.settings.markdown?.codeBlockIndent ?? \" \";\n\t}\n\n\tgetForbiddenCommands(): string[] | undefined {\n\t\treturn this.settings.forbiddenCommands;\n\t}\n\n\tgetSensitiveFilePaths(): string[] | undefined {\n\t\treturn this.settings.sensitiveFilePaths;\n\t}\n\n\tgetSecretOutputPatterns(): { name: string; pattern: string }[] | undefined {\n\t\treturn this.settings.secretOutputPatterns;\n\t}\n\n\t/**\n\t * Read only the global arbiter policy; project settings are intentionally ignored.\n\t * File-backed managers refresh this slice for every dispatch so independently\n\t * running sessions observe dashboard and TUI writes without a restart.\n\t */\n\tgetGlobalSubagentArbiterSettings(): SubagentArbiterSettings | undefined {\n\t\tthis.refreshGlobalSubagentArbiterFromStorage();\n\t\treturn this.globalSettings.subagentArbiter ? structuredClone(this.globalSettings.subagentArbiter) : undefined;\n\t}\n\n\tsetGlobalSubagentArbiterSettings(settings: SubagentArbiterSettings | undefined): void {\n\t\tthis.globalSettings.subagentArbiter = settings ? structuredClone(settings) : undefined;\n\t\tthis.markModified(\"subagentArbiter\");\n\t\tthis.save();\n\t}\n\n\tgetDreamArchivePath(): string {\n\t\tconst configured = this.settings.dream?.archivePath;\n\t\tif (configured) {\n\t\t\treturn resolve(expandPath(configured));\n\t\t}\n\t\treturn join(homedir(), \".dreb\", \"memory-archive\");\n\t}\n\n\tsetDreamArchivePath(path: string): void {\n\t\tif (!this.globalSettings.dream) this.globalSettings.dream = {};\n\t\tthis.globalSettings.dream.archivePath = path;\n\t\tthis.markModified(\"dream\", \"archivePath\");\n\t\tthis.save();\n\t}\n\n\tgetAgentModels(): Record<string, string[]> {\n\t\t// Merge global + project at the per-agent-name level, with project winning per-key.\n\t\t// Reading directly from globalSettings/projectSettings avoids the wholesale\n\t\t// replacement that deepMergeSettings would do for the shared `models` sub-key.\n\t\tconst merged: Record<string, string[]> = {\n\t\t\t...this.globalSettings.agentModels?.models,\n\t\t\t...this.projectSettings.agentModels?.models,\n\t\t};\n\t\t// Deep-copy inner arrays so callers can't mutate stored state.\n\t\treturn Object.fromEntries(Object.entries(merged).map(([k, v]) => [k, [...v]]));\n\t}\n\n\tgetAgentModelsForAgent(agentName: string): string[] | undefined {\n\t\tconst models = this.getAgentModels()[agentName];\n\t\treturn models && models.length > 0 ? models : undefined;\n\t}\n\n\t/**\n\t * Whether a project-level (`.dreb/settings.json`) agentModels entry exists for this agent.\n\t * Project entries win over global ones in {@link getAgentModels}, so a global write/remove\n\t * via the TUI has no effect when this returns true — callers should surface this loudly.\n\t */\n\thasProjectAgentModelOverride(agentName: string): boolean {\n\t\treturn this.projectSettings.agentModels?.models?.[agentName] !== undefined;\n\t}\n\n\tsetAgentModelsForAgent(agentName: string, models: string[]): void {\n\t\tif (!this.globalSettings.agentModels) {\n\t\t\tthis.globalSettings.agentModels = {};\n\t\t}\n\t\tif (!this.globalSettings.agentModels.models) {\n\t\t\tthis.globalSettings.agentModels.models = {};\n\t\t}\n\t\tthis.globalSettings.agentModels.models[agentName] = [...models];\n\t\tthis.markModified(\"agentModels\", \"models\");\n\t\tthis.save();\n\t}\n\n\tremoveAgentModelsForAgent(agentName: string): void {\n\t\tif (this.globalSettings.agentModels?.models?.[agentName] !== undefined) {\n\t\t\tdelete this.globalSettings.agentModels.models[agentName];\n\t\t\tthis.markModified(\"agentModels\", \"models\");\n\t\t\tthis.save();\n\t\t}\n\t}\n\n\t/**\n\t * Per-model settings merged global + project at the entry-key level, with project\n\t * winning per property. Entry keys are bare model IDs for legacy settings or canonical\n\t * provider/model references for provider-aware settings. Reading directly from the two\n\t * scopes avoids wholesale replacement of the shared `modelSettings` object.\n\t */\n\tgetModelSettings(modelKey: string): ModelSpecificSettings | undefined {\n\t\tconst global = this.globalSettings.modelSettings?.[modelKey];\n\t\tconst project = this.projectSettings.modelSettings?.[modelKey];\n\t\tif (!global && !project) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn { ...global, ...project };\n\t}\n\n\t/**\n\t * Resolve prompt settings for one exact provider/model pair. Prompt settings deliberately\n\t * do not fall back to the legacy bare-model-id keys used by thinkingDisplay because that\n\t * would leak instructions across providers exposing the same model ID.\n\t */\n\tgetModelPromptSettings(provider: string, modelId: string): ModelPromptSettings | undefined {\n\t\tconst modelRef = `${provider}/${modelId}`;\n\t\tconst settings = this.getModelSettings(modelRef);\n\t\tif (!settings) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst { systemPrompt, appendSystemPrompt } = settings;\n\t\tif (systemPrompt !== undefined && (typeof systemPrompt !== \"string\" || systemPrompt.trim().length === 0)) {\n\t\t\tthrow new Error(`modelSettings.${modelRef}.systemPrompt must be a non-empty string`);\n\t\t}\n\t\tif (\n\t\t\tappendSystemPrompt !== undefined &&\n\t\t\t(typeof appendSystemPrompt !== \"string\" || appendSystemPrompt.trim().length === 0)\n\t\t) {\n\t\t\tthrow new Error(`modelSettings.${modelRef}.appendSystemPrompt must be a non-empty string`);\n\t\t}\n\t\tif (systemPrompt !== undefined && appendSystemPrompt !== undefined) {\n\t\t\tthrow new Error(`modelSettings.${modelRef} cannot define both systemPrompt and appendSystemPrompt`);\n\t\t}\n\t\tif (systemPrompt === undefined && appendSystemPrompt === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn { systemPrompt, appendSystemPrompt };\n\t}\n\n\tgetModelThinkingDisplay(modelId: string): \"summarized\" | \"omitted\" | undefined {\n\t\treturn this.getModelSettings(modelId)?.thinkingDisplay;\n\t}\n\n\tsetModelThinkingDisplay(modelId: string, value: \"summarized\" | \"omitted\" | undefined): void {\n\t\tif (value === undefined) {\n\t\t\tconst existing = this.globalSettings.modelSettings?.[modelId];\n\t\t\tif (existing?.thinkingDisplay === undefined) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdelete existing.thinkingDisplay;\n\t\t\tif (Object.keys(existing).length === 0) {\n\t\t\t\tdelete this.globalSettings.modelSettings![modelId];\n\t\t\t}\n\t\t\tthis.markModified(\"modelSettings\", modelId);\n\t\t\tthis.save();\n\t\t\treturn;\n\t\t}\n\t\tif (!this.globalSettings.modelSettings) {\n\t\t\tthis.globalSettings.modelSettings = {};\n\t\t}\n\t\tif (!this.globalSettings.modelSettings[modelId]) {\n\t\t\tthis.globalSettings.modelSettings[modelId] = {};\n\t\t}\n\t\tthis.globalSettings.modelSettings[modelId].thinkingDisplay = value;\n\t\tthis.markModified(\"modelSettings\", modelId);\n\t\tthis.save();\n\t}\n\n\tgetTabTitleSettings(): TabTitleSettings | undefined {\n\t\treturn this.settings.tabTitle;\n\t}\n}\n"]}
@@ -993,18 +993,46 @@ export class SettingsManager {
993
993
  }
994
994
  }
995
995
  /**
996
- * Per-model settings merged global + project at the per-model-id level, with project
997
- * winning per key. Reading directly from globalSettings/projectSettings avoids the
998
- * wholesale replacement that deepMergeSettings would do for the shared `modelSettings` key.
996
+ * Per-model settings merged global + project at the entry-key level, with project
997
+ * winning per property. Entry keys are bare model IDs for legacy settings or canonical
998
+ * provider/model references for provider-aware settings. Reading directly from the two
999
+ * scopes avoids wholesale replacement of the shared `modelSettings` object.
999
1000
  */
1000
- getModelSettings(modelId) {
1001
- const global = this.globalSettings.modelSettings?.[modelId];
1002
- const project = this.projectSettings.modelSettings?.[modelId];
1001
+ getModelSettings(modelKey) {
1002
+ const global = this.globalSettings.modelSettings?.[modelKey];
1003
+ const project = this.projectSettings.modelSettings?.[modelKey];
1003
1004
  if (!global && !project) {
1004
1005
  return undefined;
1005
1006
  }
1006
1007
  return { ...global, ...project };
1007
1008
  }
1009
+ /**
1010
+ * Resolve prompt settings for one exact provider/model pair. Prompt settings deliberately
1011
+ * do not fall back to the legacy bare-model-id keys used by thinkingDisplay because that
1012
+ * would leak instructions across providers exposing the same model ID.
1013
+ */
1014
+ getModelPromptSettings(provider, modelId) {
1015
+ const modelRef = `${provider}/${modelId}`;
1016
+ const settings = this.getModelSettings(modelRef);
1017
+ if (!settings) {
1018
+ return undefined;
1019
+ }
1020
+ const { systemPrompt, appendSystemPrompt } = settings;
1021
+ if (systemPrompt !== undefined && (typeof systemPrompt !== "string" || systemPrompt.trim().length === 0)) {
1022
+ throw new Error(`modelSettings.${modelRef}.systemPrompt must be a non-empty string`);
1023
+ }
1024
+ if (appendSystemPrompt !== undefined &&
1025
+ (typeof appendSystemPrompt !== "string" || appendSystemPrompt.trim().length === 0)) {
1026
+ throw new Error(`modelSettings.${modelRef}.appendSystemPrompt must be a non-empty string`);
1027
+ }
1028
+ if (systemPrompt !== undefined && appendSystemPrompt !== undefined) {
1029
+ throw new Error(`modelSettings.${modelRef} cannot define both systemPrompt and appendSystemPrompt`);
1030
+ }
1031
+ if (systemPrompt === undefined && appendSystemPrompt === undefined) {
1032
+ return undefined;
1033
+ }
1034
+ return { systemPrompt, appendSystemPrompt };
1035
+ }
1008
1036
  getModelThinkingDisplay(modelId) {
1009
1037
  return this.getModelSettings(modelId)?.thinkingDisplay;
1010
1038
  }