дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 09:41:34 +02:00
* refactor(agents): replace per-file memory controls with native-only auto-memory controls * test(e2e): update agentComposerPopup memory catalog fixture * fix(agents): add missing memory i18n keys, valid spacing token, and rollout count
698 рядки
29 KiB
TypeScript
698 рядки
29 KiB
TypeScript
/**
|
||
* Settings shape as the UI consumes it: every field present and in range.
|
||
* Values come from user-edited TOML (via the backend) or from older versions,
|
||
* so `validateSettings` never throws — anything unknown or malformed falls
|
||
* back to the default (mirrors `ide-core::settings` defaults).
|
||
*/
|
||
import { DEFAULT_FILE_COLORS, validateFileColors, type FileColorSettings } from "@/platform/fileColors";
|
||
import { validateScopes, type NamedScope } from "@/platform/scopes";
|
||
import { validateCMake, validateToolchains, type ToolchainValid } from "@/platform/cmakeSettings";
|
||
import { SUPPORTED_LOCALES, type Locale } from "@/platform/i18n";
|
||
import { DEFAULT_IGNORED_NAMES } from "@/platform/ignoredNames";
|
||
import { validateFileTypeOverrides, validateFileTypes, type FileTypeAssociations } from "@/platform/fileTypes";
|
||
import type { AgentSettings, JsonSchemaMapping, LanguageServerSettings, Settings } from "@/platform/ipc";
|
||
import {
|
||
DEFAULT_LANGUAGES,
|
||
DEFAULT_PROJECT_STRUCTURE,
|
||
validateLanguages,
|
||
validateProjectStructure,
|
||
type LanguagesValid,
|
||
type ProjectStructureValid,
|
||
} from "@/platform/languageSettings";
|
||
import { EDITOR_EXTRA_DEFAULTS, validateEditorExtras, type EditorExtras } from "@/platform/editorSettings";
|
||
import {
|
||
DEFAULT_AGENT_RUNS,
|
||
DEFAULT_WORKFLOW,
|
||
validateAgentRuns,
|
||
validateWorkflow,
|
||
type WorkflowSettings,
|
||
} from "@/platform/workflowSettings";
|
||
import { DEFAULT_INSPECTIONS, validateInspections, type InspectionSettingsValid } from "@/platform/inspections";
|
||
import { DEFAULT_PROXY, validateProxy, type ProxySettingsValid } from "@/platform/proxySettings";
|
||
import {
|
||
DEFAULT_APPEARANCE_EXTRAS,
|
||
DEFAULT_GENERAL_EXTRAS,
|
||
DEFAULT_NOTIFICATIONS,
|
||
validateAppearanceExtras,
|
||
validateGeneralExtras,
|
||
validateNotifications,
|
||
type AppearanceExtras,
|
||
type GeneralExtras,
|
||
type NotificationsValid,
|
||
} from "./behaviorSchema";
|
||
import { isThemeChoiceId, type ThemeChoiceId } from "@/platform/themes";
|
||
import { DEFAULT_REMOTE_IDLE_MINUTES, validRemoteIdleMinutes } from "@/platform/remoteIdle";
|
||
|
||
/** Agents › IDE MCP Server › Port: its default (`ide-core::settings::DEFAULT_MCP_PORT`) and range. */
|
||
export const DEFAULT_MCP_PORT = 26371;
|
||
export const MCP_PORT_LIMITS = { min: 1, max: 65535 };
|
||
/** Agents › IDE MCP Server › Background projects: the idle minutes (0 = never unload) and the project limit. */
|
||
export const MCP_BACKGROUND_IDLE_LIMITS = { min: 0, max: 1440 };
|
||
export const MCP_BACKGROUND_PROJECT_LIMITS = { min: 1, max: 32 };
|
||
export const MCP_BACKGROUND_MODES = ["off", "trusted", "listed"] as const;
|
||
/** Agents › IDE MCP Server › Listen address: its default (`ide-core::settings::DEFAULT_MCP_ADDRESS`). */
|
||
export const DEFAULT_MCP_ADDRESS = "127.0.0.1";
|
||
|
||
/** A built-in theme, a plugin's (`plugin:<id>/<theme>`) or the legacy `"system"`. */
|
||
export type ThemeId = ThemeChoiceId | "system";
|
||
|
||
/** A user keymap (Keymap › Duplicate…): its own overrides on top of a bundled preset. */
|
||
export interface CustomKeymapSettings {
|
||
name: string;
|
||
parent: string;
|
||
overrides: Record<string, string[]>;
|
||
}
|
||
|
||
export type JsonSchemaMappingValid = Required<JsonSchemaMapping>;
|
||
|
||
export function validateJsonSchemas(raw: unknown): JsonSchemaMappingValid[] {
|
||
if (!Array.isArray(raw)) return [];
|
||
return raw.flatMap((m) => {
|
||
const o = obj(m);
|
||
return typeof o.name === "string"
|
||
? [{ name: o.name, schema: typeof o.schema === "string" ? o.schema : "", files: stringList(o.files) }]
|
||
: [];
|
||
});
|
||
}
|
||
|
||
/** A mapping pattern that takes every JSON or YAML file in the project, such as `*.json`. */
|
||
export function matchesEveryFile(pattern: string): boolean {
|
||
const p = pattern
|
||
.trim()
|
||
.replaceAll("\\", "/")
|
||
.replace(/^(?:\.\/|\/|\*\*\/)+/, "");
|
||
return ["*", "**", "*.*", "*.json", "*.jsonc", "*.yaml", "*.yml"].includes(p);
|
||
}
|
||
|
||
export interface ValidSettings extends WorkflowSettings {
|
||
plugins: Record<string, Record<string, unknown>>;
|
||
scopes: NamedScope[];
|
||
/** Languages & Frameworks › JSON Schema Mappings. */
|
||
jsonSchemas: JsonSchemaMappingValid[];
|
||
fileColors: FileColorSettings;
|
||
/** Database › Query Execution. */
|
||
database: {
|
||
inEditorResults: boolean;
|
||
outputDestination: "databaseOutput" | "services";
|
||
resolutionScopes: Array<{ path: string; dataSource: string; schema: string }>;
|
||
};
|
||
general: {
|
||
reopenLastProject: boolean;
|
||
confirmExit: boolean;
|
||
/** Last window closes instead of showing the Welcome screen. */
|
||
closeWithoutWelcome: boolean;
|
||
/** Closing a window drops its saved editor tabs. */
|
||
closeTabsWithWindow: boolean;
|
||
} & GeneralExtras;
|
||
appearance: { theme: ThemeId; accent: string; uiFontSize: number; locale: Locale } & AppearanceExtras;
|
||
editor: {
|
||
fontFamily: string;
|
||
fontSize: number;
|
||
lineHeight: number;
|
||
tabSize: number;
|
||
insertSpaces: boolean;
|
||
softWrap: boolean;
|
||
showWhitespace: boolean;
|
||
inlayHints: boolean;
|
||
stickyScroll: boolean;
|
||
formatOnSave: boolean;
|
||
/** `theme-default` follows the IDE theme. */
|
||
colorScheme: string;
|
||
} & EditorExtras;
|
||
keymap: string;
|
||
files: {
|
||
autoSave: boolean;
|
||
syncOnFocus: boolean;
|
||
exclude: string[];
|
||
ignoredNames: string[];
|
||
trimTrailingWhitespace: boolean;
|
||
ensureFinalNewline: boolean;
|
||
/** Local History keeps this many working days (days with changes). */
|
||
localHistoryDays: number;
|
||
/** Local History size bound per project, MB. */
|
||
localHistoryMaxMb: number;
|
||
/** File Types: the user's patterns per language id. */
|
||
fileTypes: FileTypeAssociations;
|
||
/** Override File Type: file → language id (project scope). */
|
||
fileTypeOverrides: Record<string, string>;
|
||
/** Files opened in associated applications: file-name patterns. */
|
||
associatedApplications: string[];
|
||
};
|
||
keymapOverrides: Record<string, string[]>;
|
||
customKeymaps: Record<string, CustomKeymapSettings>;
|
||
notifications: NotificationsValid;
|
||
/** System Settings › HTTP Proxy (global). */
|
||
proxy: ProxySettingsValid;
|
||
remoteDevelopment: { idleTimeoutMinutes: number };
|
||
/** Tools › Download sources: a mirror prefix for the installer's release downloads. */
|
||
toolDownloads: { githubMirror: string; configuredRegistriesOnly: boolean; vueLanguageServerVersion: string };
|
||
/** Settings Sync (global): the repository and the categories that sync. */
|
||
settingsSync: SettingsSyncValid;
|
||
languages: LanguagesValid;
|
||
cmake: ReturnType<typeof validateCMake>;
|
||
/** Build, Execution, Deployment › Toolchains (global); the first is the default. */
|
||
toolchains: ToolchainValid[];
|
||
projectStructure: ProjectStructureValid;
|
||
inspections: InspectionSettingsValid;
|
||
/** Editor › Natural Languages › Spelling. */
|
||
spelling: SpellingValid;
|
||
/** Executables chosen for language servers / debug adapters, by command. */
|
||
tools: Record<string, { path: string }>;
|
||
/** Settings › Language Servers, by server name (as the backend sends them). */
|
||
languageServers: Record<string, LanguageServerEntry>;
|
||
/** Tools › Agents › Chat: the meters in an agent task's header. */
|
||
agents: Required<AgentSettings>;
|
||
/** Agents › IDE MCP Server (global). */
|
||
mcpServer: {
|
||
enabled: boolean;
|
||
runWithoutConfirmation: boolean;
|
||
agentTabLimit: number;
|
||
agentArchiveLimit: number;
|
||
/** The IP address to listen on (`127.0.0.1`: this computer only); the backend checks it. */
|
||
address: string;
|
||
/** Listen on `port` in every run rather than a free port each time. */
|
||
fixedPort: boolean;
|
||
port: number;
|
||
/** Keep the bearer token across runs rather than make a new one each run. */
|
||
fixedToken: boolean;
|
||
/** Which folders without an open window the server still serves. */
|
||
backgroundProjects: (typeof MCP_BACKGROUND_MODES)[number];
|
||
/** The folders `listed` serves (and `trusted` serves even when untrusted). */
|
||
backgroundProjectPaths: string[];
|
||
/** Minutes a background project may sit idle before it unloads; 0 keeps it until the IDE quits. */
|
||
backgroundIdleMinutes: number;
|
||
/** Background projects loaded at once. */
|
||
backgroundProjectLimit: number;
|
||
};
|
||
}
|
||
|
||
/** One `languageServers.<name>` entry; every field optional, like in settings.toml. */
|
||
export type LanguageServerEntry = Partial<LanguageServerSettings>;
|
||
|
||
export interface SpellingValid {
|
||
ideWords: string[];
|
||
projectWords: string[];
|
||
customDictionaries: string[];
|
||
/** Where "Save '…' to dictionary" writes; empty means project (application without a project). */
|
||
defaultDictionary: string;
|
||
}
|
||
|
||
const stringList = (v: unknown): string[] =>
|
||
Array.isArray(v) ? v.filter((x): x is string => typeof x === "string" && !!x.trim()) : [];
|
||
|
||
function validateSpelling(raw: unknown): SpellingValid {
|
||
const r = obj(raw);
|
||
return {
|
||
ideWords: stringList(r.ideWords),
|
||
projectWords: stringList(r.projectWords),
|
||
customDictionaries: stringList(r.customDictionaries),
|
||
defaultDictionary: typeof r.defaultDictionary === "string" ? r.defaultDictionary : "",
|
||
};
|
||
}
|
||
|
||
export { ACCENT_PRESETS } from "@/workbench/theme";
|
||
|
||
type SettingsSyncValid = NonNullable<Settings["settingsSync"]>;
|
||
const DEFAULT_SETTINGS_SYNC: SettingsSyncValid = {
|
||
repository: "",
|
||
auto: true,
|
||
appearance: true,
|
||
editor: true,
|
||
keymaps: true,
|
||
other: true,
|
||
templates: true,
|
||
macros: true,
|
||
ui: true,
|
||
plugins: true,
|
||
};
|
||
|
||
export const DEFAULT_SETTINGS: ValidSettings = {
|
||
plugins: {},
|
||
scopes: [],
|
||
jsonSchemas: [],
|
||
fileColors: DEFAULT_FILE_COLORS,
|
||
database: { inEditorResults: false, outputDestination: "databaseOutput", resolutionScopes: [] },
|
||
general: {
|
||
reopenLastProject: true,
|
||
confirmExit: true,
|
||
closeWithoutWelcome: false,
|
||
closeTabsWithWindow: false,
|
||
...DEFAULT_GENERAL_EXTRAS,
|
||
},
|
||
appearance: { theme: "light", accent: "#3871e1", uiFontSize: 13, locale: "en", ...DEFAULT_APPEARANCE_EXTRAS },
|
||
editor: {
|
||
fontFamily: "JetBrains Mono",
|
||
fontSize: 13,
|
||
lineHeight: 22,
|
||
tabSize: 4,
|
||
insertSpaces: true,
|
||
softWrap: true,
|
||
showWhitespace: false,
|
||
inlayHints: true,
|
||
stickyScroll: true,
|
||
formatOnSave: false,
|
||
colorScheme: "theme-default",
|
||
...EDITOR_EXTRA_DEFAULTS,
|
||
},
|
||
keymap: "intellij-macos",
|
||
files: {
|
||
autoSave: true,
|
||
syncOnFocus: true,
|
||
exclude: ["**/.git", "**/node_modules", "**/target"],
|
||
ignoredNames: [...DEFAULT_IGNORED_NAMES],
|
||
trimTrailingWhitespace: true,
|
||
ensureFinalNewline: true,
|
||
localHistoryDays: 5,
|
||
localHistoryMaxMb: 512,
|
||
fileTypes: {},
|
||
fileTypeOverrides: {},
|
||
associatedApplications: ["*.xlsx", "*.xls", "*.docx", "*.doc", "*.pptx", "*.ppt", "*.pdf"],
|
||
},
|
||
keymapOverrides: {},
|
||
customKeymaps: {},
|
||
notifications: DEFAULT_NOTIFICATIONS,
|
||
proxy: DEFAULT_PROXY,
|
||
remoteDevelopment: { idleTimeoutMinutes: DEFAULT_REMOTE_IDLE_MINUTES },
|
||
toolDownloads: { githubMirror: "", configuredRegistriesOnly: false, vueLanguageServerVersion: "" },
|
||
settingsSync: DEFAULT_SETTINGS_SYNC,
|
||
languages: DEFAULT_LANGUAGES,
|
||
cmake: {},
|
||
toolchains: [],
|
||
projectStructure: DEFAULT_PROJECT_STRUCTURE,
|
||
inspections: DEFAULT_INSPECTIONS,
|
||
spelling: { ideWords: [], projectWords: [], customDictionaries: [], defaultDictionary: "" },
|
||
tools: {},
|
||
languageServers: {},
|
||
agents: {
|
||
showContextUsage: true,
|
||
showWorkTime: true,
|
||
showUsageLimits: true,
|
||
showCost: false,
|
||
smoothText: true,
|
||
fitWindowWidth: false,
|
||
chatUseUiFont: true,
|
||
chatFontFamily: "Inter",
|
||
chatFontFallback: "",
|
||
chatFontSize: 13,
|
||
codeUseDefaultFont: true,
|
||
codeFontFamily: "JetBrains Mono",
|
||
codeFontFallback: "",
|
||
codeFontSize: 13,
|
||
thinking: "auto",
|
||
toolCalls: "grouped",
|
||
expandToolOutput: false,
|
||
sendWith: "enter",
|
||
whileRunning: "queue",
|
||
newTaskApprovals: "bypass",
|
||
networkRetryWindow: "1h",
|
||
resumeInterrupted: "ask",
|
||
confirmTerminateOnClose: true,
|
||
defaults: {},
|
||
mcpServers: {},
|
||
mcpRegistryUrl: "",
|
||
skills: {},
|
||
memory: {
|
||
providers: {},
|
||
},
|
||
plugins: {
|
||
marketplaces: [],
|
||
entries: {},
|
||
},
|
||
automations: {
|
||
autoStartService: false,
|
||
keepAliveInBackground: true,
|
||
keepRemoteDaemonAlive: true,
|
||
preventSleep: "ac",
|
||
misfirePolicy: "runOnce",
|
||
autoCleanWorktrees: true,
|
||
maxDirtyWorktrees: 5,
|
||
},
|
||
},
|
||
mcpServer: {
|
||
enabled: false,
|
||
runWithoutConfirmation: false,
|
||
agentTabLimit: DEFAULT_AGENT_RUNS.tabLimit,
|
||
agentArchiveLimit: DEFAULT_AGENT_RUNS.archiveLimit,
|
||
address: DEFAULT_MCP_ADDRESS,
|
||
fixedPort: true,
|
||
port: DEFAULT_MCP_PORT,
|
||
fixedToken: false,
|
||
backgroundProjects: "off",
|
||
backgroundProjectPaths: [],
|
||
backgroundIdleMinutes: 30,
|
||
backgroundProjectLimit: 8,
|
||
},
|
||
...DEFAULT_WORKFLOW,
|
||
};
|
||
|
||
export const LIMITS = {
|
||
uiFontSize: { min: 10, max: 18 },
|
||
fontSize: { min: 6, max: 72 },
|
||
lineHeight: { min: 8, max: 120 },
|
||
tabSize: { min: 1, max: 16 },
|
||
localHistoryDays: { min: 1, max: 365 },
|
||
localHistoryMaxMb: { min: 16, max: 16384 },
|
||
} as const;
|
||
|
||
const theme = (v: unknown, d: ThemeId): ThemeId => (v === "system" || isThemeChoiceId(v) ? v : d);
|
||
export const HEX_COLOR = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
|
||
|
||
type Obj = Record<string, unknown>;
|
||
const obj = (v: unknown): Obj => (v && typeof v === "object" && !Array.isArray(v) ? (v as Obj) : {});
|
||
const bool = (v: unknown, d: boolean) => (typeof v === "boolean" ? v : d);
|
||
const str = (v: unknown, d: string) => (typeof v === "string" && v.trim() ? v : d);
|
||
const stringMap = (v: unknown): Record<string, string> =>
|
||
Object.fromEntries(Object.entries(obj(v)).filter((e): e is [string, string] => typeof e[1] === "string"));
|
||
|
||
/** Agent id → option id → value, keeping only string values. */
|
||
function agentDefaults(v: unknown): Record<string, Record<string, string>> {
|
||
return Object.fromEntries(Object.entries(obj(v)).map(([agent, options]) => [agent, stringMap(options)]));
|
||
}
|
||
|
||
function agentMcpServers(v: unknown): Required<AgentSettings>["mcpServers"] {
|
||
const out: Required<AgentSettings>["mcpServers"] = {};
|
||
for (const [name, raw] of Object.entries(obj(v))) {
|
||
if (!name.trim()) continue;
|
||
const s = obj(raw);
|
||
const transport = oneOf(s.transport, ["stdio", "http", "sse"] as const, "stdio");
|
||
const enabled = bool(s.enabled, true);
|
||
const command = typeof s.command === "string" && s.command.trim() ? s.command.trim() : null;
|
||
const args = stringList(s.args);
|
||
const env = stringMap(s.env);
|
||
const url = typeof s.url === "string" && s.url.trim() ? s.url.trim() : null;
|
||
const headers = stringMap(s.headers);
|
||
const agents = stringList(s.agents);
|
||
const registryName = typeof s.registryName === "string" && s.registryName.trim() ? s.registryName.trim() : null;
|
||
const registryUrl = typeof s.registryUrl === "string" && s.registryUrl.trim() ? s.registryUrl.trim() : null;
|
||
out[name] = {
|
||
transport,
|
||
enabled,
|
||
...(command ? { command } : {}),
|
||
...(args.length ? { args } : {}),
|
||
...(Object.keys(env).length ? { env } : {}),
|
||
...(url ? { url } : {}),
|
||
...(Object.keys(headers).length ? { headers } : {}),
|
||
...(agents.length ? { agents } : {}),
|
||
...(registryName ? { registryName } : {}),
|
||
...(registryUrl ? { registryUrl } : {}),
|
||
};
|
||
}
|
||
return out;
|
||
}
|
||
|
||
function agentSkillPolicies(v: unknown): Required<AgentSettings>["skills"] {
|
||
const out: Required<AgentSettings>["skills"] = {};
|
||
for (const [name, raw] of Object.entries(obj(v))) {
|
||
if (!name.trim()) continue;
|
||
out[name] = { mode: oneOf(obj(raw).mode, ["auto", "slashOnly", "off"] as const, "auto") };
|
||
}
|
||
return out;
|
||
}
|
||
|
||
function agentMemorySettings(v: unknown): Required<AgentSettings>["memory"] {
|
||
const m = obj(v);
|
||
const autoModes = ["inherit", "readWrite", "readOnly", "off"] as const;
|
||
const providers: NonNullable<Required<AgentSettings>["memory"]["providers"]> = {};
|
||
for (const [id, raw] of Object.entries(obj(m.providers))) {
|
||
if (!id.trim()) continue;
|
||
providers[id] = { autoMemory: oneOf(obj(raw).autoMemory, autoModes, "inherit") };
|
||
}
|
||
return { providers };
|
||
}
|
||
|
||
function agentPluginSettings(v: unknown): Required<AgentSettings>["plugins"] {
|
||
const p = obj(v);
|
||
const marketplaces = stringList(p.marketplaces);
|
||
const entries: NonNullable<Required<AgentSettings>["plugins"]["entries"]> = {};
|
||
for (const [id, raw] of Object.entries(obj(p.entries))) {
|
||
if (!id.trim()) continue;
|
||
const r = obj(raw);
|
||
const config = stringMap(r.config);
|
||
entries[id] = {
|
||
...(Object.keys(config).length ? { config } : {}),
|
||
};
|
||
}
|
||
return {
|
||
marketplaces,
|
||
entries,
|
||
};
|
||
}
|
||
|
||
function agentAutomationSettings(v: unknown): Required<Required<AgentSettings>["automations"]> {
|
||
const a = obj(v);
|
||
const d = DEFAULT_SETTINGS.agents.automations;
|
||
return {
|
||
autoStartService: bool(a.autoStartService, d.autoStartService ?? false),
|
||
keepAliveInBackground: bool(a.keepAliveInBackground, d.keepAliveInBackground ?? true),
|
||
keepRemoteDaemonAlive: bool(a.keepRemoteDaemonAlive, d.keepRemoteDaemonAlive ?? true),
|
||
preventSleep: oneOf(a.preventSleep, ["ac", "always", "never"] as const, d.preventSleep ?? "ac"),
|
||
misfirePolicy: oneOf(a.misfirePolicy, ["runOnce", "skip"] as const, d.misfirePolicy ?? "runOnce"),
|
||
autoCleanWorktrees: bool(a.autoCleanWorktrees, d.autoCleanWorktrees ?? true),
|
||
maxDirtyWorktrees: num(a.maxDirtyWorktrees, d.maxDirtyWorktrees ?? 5, { min: 1, max: 50 }, true),
|
||
};
|
||
}
|
||
|
||
const oneOf = <T extends string>(v: unknown, allowed: readonly T[], d: T): T =>
|
||
typeof v === "string" && (allowed as readonly string[]).includes(v) ? (v as T) : d;
|
||
const num = (v: unknown, d: number, { min, max }: { min: number; max: number }, int = false) => {
|
||
if (typeof v !== "number" || !Number.isFinite(v)) return d;
|
||
const n = Math.min(max, Math.max(min, v));
|
||
return int ? Math.round(n) : n;
|
||
};
|
||
|
||
function bindingMap(raw: unknown): Record<string, string[]> {
|
||
const out: Record<string, string[]> = {};
|
||
for (const [id, keys] of Object.entries(obj(raw))) {
|
||
if (Array.isArray(keys)) out[id] = keys.filter((k): k is string => typeof k === "string" && !!k.trim());
|
||
}
|
||
return out;
|
||
}
|
||
|
||
export function validateSettings(raw: Settings | unknown): ValidSettings {
|
||
const d = DEFAULT_SETTINGS;
|
||
const root = obj(raw);
|
||
const g = obj(root.general);
|
||
const a = obj(root.appearance);
|
||
const e = obj(root.editor);
|
||
const f = obj(root.files);
|
||
const agents = obj(root.agents);
|
||
const overrides = bindingMap(root.keymapOverrides);
|
||
const customKeymaps: Record<string, CustomKeymapSettings> = {};
|
||
for (const [id, raw] of Object.entries(obj(root.customKeymaps))) {
|
||
const k = obj(raw);
|
||
if (!id.trim()) continue;
|
||
customKeymaps[id] = { name: str(k.name, id), parent: str(k.parent, d.keymap), overrides: bindingMap(k.overrides) };
|
||
}
|
||
return {
|
||
plugins: Object.fromEntries(Object.entries(obj(root.plugins)).map(([id, values]) => [id, obj(values)])),
|
||
scopes: validateScopes(root.scopes),
|
||
jsonSchemas: validateJsonSchemas(root.jsonSchemas),
|
||
fileColors: validateFileColors(root.fileColors),
|
||
database: {
|
||
inEditorResults: bool(obj(root.database).inEditorResults, d.database.inEditorResults),
|
||
outputDestination:
|
||
obj(root.database).outputDestination === "services" ? "services" : d.database.outputDestination,
|
||
resolutionScopes: (Array.isArray(obj(root.database).resolutionScopes)
|
||
? (obj(root.database).resolutionScopes as unknown[])
|
||
: []
|
||
).map((r) => ({
|
||
path: str(obj(r).path, ""),
|
||
dataSource: str(obj(r).dataSource, ""),
|
||
schema: str(obj(r).schema, ""),
|
||
})),
|
||
},
|
||
general: {
|
||
...validateGeneralExtras(g),
|
||
reopenLastProject: bool(g.reopenLastProject, d.general.reopenLastProject),
|
||
confirmExit: bool(g.confirmExit, d.general.confirmExit),
|
||
closeWithoutWelcome: bool(g.closeWithoutWelcome, d.general.closeWithoutWelcome),
|
||
closeTabsWithWindow: bool(g.closeTabsWithWindow, d.general.closeTabsWithWindow),
|
||
},
|
||
appearance: {
|
||
...validateAppearanceExtras(a),
|
||
theme: theme(a.theme, d.appearance.theme),
|
||
accent: typeof a.accent === "string" && HEX_COLOR.test(a.accent) ? a.accent.toLowerCase() : d.appearance.accent,
|
||
uiFontSize: num(a.uiFontSize, d.appearance.uiFontSize, LIMITS.uiFontSize, true),
|
||
locale: oneOf(a.locale, SUPPORTED_LOCALES, d.appearance.locale),
|
||
},
|
||
editor: {
|
||
fontFamily: str(e.fontFamily, d.editor.fontFamily),
|
||
fontSize: num(e.fontSize, d.editor.fontSize, LIMITS.fontSize),
|
||
lineHeight: num(e.lineHeight, d.editor.lineHeight, LIMITS.lineHeight),
|
||
tabSize: num(e.tabSize, d.editor.tabSize, LIMITS.tabSize, true),
|
||
insertSpaces: bool(e.insertSpaces, d.editor.insertSpaces),
|
||
softWrap: bool(e.softWrap, d.editor.softWrap),
|
||
showWhitespace: bool(e.showWhitespace, d.editor.showWhitespace),
|
||
inlayHints: bool(e.inlayHints, d.editor.inlayHints),
|
||
stickyScroll: bool(e.stickyScroll, d.editor.stickyScroll),
|
||
formatOnSave: bool(e.formatOnSave, d.editor.formatOnSave),
|
||
colorScheme: str(e.colorScheme, d.editor.colorScheme),
|
||
...validateEditorExtras(e),
|
||
},
|
||
keymap: str(root.keymap, d.keymap),
|
||
files: {
|
||
autoSave: bool(f.autoSave, d.files.autoSave),
|
||
syncOnFocus: bool(f.syncOnFocus, d.files.syncOnFocus),
|
||
exclude: Array.isArray(f.exclude)
|
||
? f.exclude.filter((x): x is string => typeof x === "string" && !!x.trim())
|
||
: [...d.files.exclude],
|
||
ignoredNames: Array.isArray(f.ignoredNames)
|
||
? f.ignoredNames.filter((x): x is string => typeof x === "string" && !!x.trim())
|
||
: [...d.files.ignoredNames],
|
||
trimTrailingWhitespace: bool(f.trimTrailingWhitespace, d.files.trimTrailingWhitespace),
|
||
ensureFinalNewline: bool(f.ensureFinalNewline, d.files.ensureFinalNewline),
|
||
localHistoryDays: num(f.localHistoryDays, d.files.localHistoryDays, LIMITS.localHistoryDays, true),
|
||
localHistoryMaxMb: num(f.localHistoryMaxMb, d.files.localHistoryMaxMb, LIMITS.localHistoryMaxMb, true),
|
||
fileTypes: validateFileTypes(f.fileTypes),
|
||
fileTypeOverrides: validateFileTypeOverrides(f.fileTypeOverrides),
|
||
associatedApplications: Array.isArray(f.associatedApplications)
|
||
? stringList(f.associatedApplications)
|
||
: [...d.files.associatedApplications],
|
||
},
|
||
keymapOverrides: overrides,
|
||
customKeymaps,
|
||
notifications: validateNotifications(root.notifications),
|
||
proxy: validateProxy(root.proxy),
|
||
remoteDevelopment: {
|
||
idleTimeoutMinutes: validRemoteIdleMinutes(obj(root.remoteDevelopment).idleTimeoutMinutes),
|
||
},
|
||
toolDownloads: {
|
||
githubMirror:
|
||
typeof obj(root.toolDownloads).githubMirror === "string"
|
||
? String(obj(root.toolDownloads).githubMirror).trim()
|
||
: "",
|
||
configuredRegistriesOnly: obj(root.toolDownloads).configuredRegistriesOnly === true,
|
||
vueLanguageServerVersion:
|
||
typeof obj(root.toolDownloads).vueLanguageServerVersion === "string"
|
||
? String(obj(root.toolDownloads).vueLanguageServerVersion).trim()
|
||
: "",
|
||
},
|
||
settingsSync: Object.fromEntries(
|
||
Object.entries(DEFAULT_SETTINGS_SYNC).map(([key, fallback]) => {
|
||
const value = obj(root.settingsSync)[key];
|
||
return [key, typeof value === typeof fallback ? value : fallback];
|
||
}),
|
||
) as SettingsSyncValid,
|
||
languages: validateLanguages(root.languages),
|
||
cmake: validateCMake(root.cmake),
|
||
toolchains: validateToolchains(root.toolchains),
|
||
projectStructure: validateProjectStructure(root.projectStructure),
|
||
inspections: validateInspections(root.inspections),
|
||
spelling: validateSpelling(root.spelling),
|
||
tools: Object.fromEntries(
|
||
Object.entries(obj(root.tools)).flatMap(([cmd, t]) => {
|
||
const path = obj(t).path;
|
||
return typeof path === "string" ? [[cmd, { path }]] : [];
|
||
}),
|
||
),
|
||
languageServers: Object.fromEntries(
|
||
Object.entries(obj(root.languageServers)).map(([name, ls]) => [name, obj(ls) as LanguageServerEntry]),
|
||
),
|
||
agents: {
|
||
showContextUsage: bool(agents.showContextUsage, d.agents.showContextUsage),
|
||
showWorkTime: bool(agents.showWorkTime, d.agents.showWorkTime),
|
||
showUsageLimits: bool(agents.showUsageLimits, d.agents.showUsageLimits),
|
||
showCost: bool(agents.showCost, d.agents.showCost),
|
||
smoothText: bool(agents.smoothText, d.agents.smoothText),
|
||
fitWindowWidth: bool(agents.fitWindowWidth, d.agents.fitWindowWidth),
|
||
chatUseUiFont: bool(agents.chatUseUiFont, d.agents.chatUseUiFont),
|
||
chatFontFamily: str(agents.chatFontFamily, d.agents.chatFontFamily),
|
||
chatFontFallback: str(agents.chatFontFallback, d.agents.chatFontFallback),
|
||
chatFontSize: num(agents.chatFontSize, d.agents.chatFontSize, LIMITS.fontSize, true),
|
||
codeUseDefaultFont: bool(agents.codeUseDefaultFont, d.agents.codeUseDefaultFont),
|
||
codeFontFamily: str(agents.codeFontFamily, d.agents.codeFontFamily),
|
||
codeFontFallback: str(agents.codeFontFallback, d.agents.codeFontFallback),
|
||
codeFontSize: num(agents.codeFontSize, d.agents.codeFontSize, LIMITS.fontSize, true),
|
||
thinking: oneOf(agents.thinking, ["auto", "expanded", "collapsed"] as const, d.agents.thinking),
|
||
toolCalls: oneOf(agents.toolCalls, ["grouped", "each"] as const, d.agents.toolCalls),
|
||
expandToolOutput: bool(agents.expandToolOutput, d.agents.expandToolOutput),
|
||
sendWith: oneOf(agents.sendWith, ["enter", "modEnter"] as const, d.agents.sendWith),
|
||
whileRunning: oneOf(agents.whileRunning, ["queue", "steer"] as const, d.agents.whileRunning),
|
||
newTaskApprovals: oneOf(agents.newTaskApprovals, ["bypass", "ask"] as const, d.agents.newTaskApprovals),
|
||
networkRetryWindow: oneOf(
|
||
agents.networkRetryWindow,
|
||
["off", "15m", "1h", "4h", "24h"] as const,
|
||
d.agents.networkRetryWindow,
|
||
),
|
||
resumeInterrupted: oneOf(
|
||
agents.resumeInterrupted,
|
||
["ask", "restart", "window", "off"] as const,
|
||
d.agents.resumeInterrupted,
|
||
),
|
||
confirmTerminateOnClose: bool(agents.confirmTerminateOnClose, d.agents.confirmTerminateOnClose),
|
||
defaults: agentDefaults(agents.defaults),
|
||
mcpServers: agentMcpServers(agents.mcpServers),
|
||
mcpRegistryUrl: typeof agents.mcpRegistryUrl === "string" ? agents.mcpRegistryUrl.trim() : "",
|
||
skills: agentSkillPolicies(agents.skills),
|
||
memory: agentMemorySettings(agents.memory),
|
||
plugins: agentPluginSettings(agents.plugins),
|
||
automations: agentAutomationSettings(agents.automations),
|
||
},
|
||
mcpServer: {
|
||
enabled: bool(obj(root.mcpServer).enabled, d.mcpServer.enabled),
|
||
runWithoutConfirmation: bool(obj(root.mcpServer).runWithoutConfirmation, d.mcpServer.runWithoutConfirmation),
|
||
agentTabLimit: validateAgentRuns(root.mcpServer).tabLimit,
|
||
agentArchiveLimit: validateAgentRuns(root.mcpServer).archiveLimit,
|
||
address: str(obj(root.mcpServer).address, d.mcpServer.address).trim(),
|
||
fixedPort: bool(obj(root.mcpServer).fixedPort, d.mcpServer.fixedPort),
|
||
port: num(obj(root.mcpServer).port, d.mcpServer.port, MCP_PORT_LIMITS, true),
|
||
fixedToken: bool(obj(root.mcpServer).fixedToken, d.mcpServer.fixedToken),
|
||
backgroundProjects: oneOf(
|
||
obj(root.mcpServer).backgroundProjects,
|
||
MCP_BACKGROUND_MODES,
|
||
d.mcpServer.backgroundProjects,
|
||
),
|
||
backgroundProjectPaths: [...new Set(stringList(obj(root.mcpServer).backgroundProjectPaths))],
|
||
backgroundIdleMinutes: num(
|
||
obj(root.mcpServer).backgroundIdleMinutes,
|
||
d.mcpServer.backgroundIdleMinutes,
|
||
MCP_BACKGROUND_IDLE_LIMITS,
|
||
true,
|
||
),
|
||
backgroundProjectLimit: num(
|
||
obj(root.mcpServer).backgroundProjectLimit,
|
||
d.mcpServer.backgroundProjectLimit,
|
||
MCP_BACKGROUND_PROJECT_LIMITS,
|
||
true,
|
||
),
|
||
},
|
||
...validateWorkflow(root),
|
||
};
|
||
}
|
||
|
||
/** Reads a dotted key (`editor.fontSize`); `undefined` when absent. */
|
||
export function getAt(source: unknown, key: string): unknown {
|
||
let cur: unknown = source;
|
||
for (const seg of key.split(".")) {
|
||
if (!cur || typeof cur !== "object") return undefined;
|
||
cur = (cur as Obj)[seg];
|
||
}
|
||
return cur;
|
||
}
|
||
|
||
/** Returns a copy of `source` with the dotted `key` set (immutable path copy). */
|
||
export function setAt<T>(source: T, key: string, value: unknown): T {
|
||
const [head, ...rest] = key.split(".");
|
||
const base = obj(source);
|
||
return { ...base, [head!]: rest.length ? setAt(base[head!], rest.join("."), value) : value } as T;
|
||
}
|
||
|
||
/** Like `setAt`, but `null` / `undefined` removes the key (as a settings write of `null` does). */
|
||
export function putAt<T>(source: T, key: string, value: unknown): T {
|
||
const [head, ...rest] = key.split(".");
|
||
const base = { ...obj(source) };
|
||
if (rest.length) base[head!] = putAt(base[head!], rest.join("."), value);
|
||
else if (value == null) delete base[head!];
|
||
else base[head!] = value;
|
||
return base as T;
|
||
}
|
||
|
||
export function deepEqual(a: unknown, b: unknown): boolean {
|
||
if (a === b) return true;
|
||
if (typeof a !== typeof b || !a || !b || typeof a !== "object") return false;
|
||
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
||
const ka = Object.keys(a as Obj);
|
||
const kb = Object.keys(b as Obj);
|
||
return ka.length === kb.length && ka.every((k) => deepEqual((a as Obj)[k], (b as Obj)[k]));
|
||
}
|