schema.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. /* eslint-disable max-lines -- zcode-cli 配置 schema 需要集中维护文件解析和 provider 继承,拆散会让配置语义更难对齐。 */
  2. import { z } from "zod";
  3. import type { RuntimeConfigPatch } from "@zcode/contracts";
  4. const stringRecordSchema = z.record(z.string(), z.string());
  5. const unknownRecordSchema = z.record(z.string(), z.unknown());
  6. const positiveNumberSchema = z.number().finite().positive();
  7. const positiveIntegerSchema = z.number().int().positive();
  8. const modelStreamSchema = z.object({
  9. idleTimeoutMs: positiveNumberSchema.optional(),
  10. });
  11. const permissionSchema = z.object({
  12. mode: z.enum(["plan", "build", "edit", "yolo", "guarded", "auto"]).optional(),
  13. allowedTools: z.array(z.string()).optional(),
  14. disallowedTools: z.array(z.string()).optional(),
  15. autoApproveHighRisk: z.boolean().optional(),
  16. allowMediumRiskInAuto: z.boolean().optional(),
  17. });
  18. const storageSchema = z.object({
  19. dir: z.string().min(1).optional(),
  20. sessionDbPath: z.string().min(1).optional(),
  21. });
  22. const networkSchema = z.object({
  23. httpProxy: z.string().min(1).optional(),
  24. noProxy: z.string().min(1).optional(),
  25. caCertFile: z.string().min(1).optional(),
  26. timeout: positiveNumberSchema.optional(),
  27. });
  28. const featuresSchema = z.object({
  29. compact: z.boolean().optional(),
  30. rewind: z.boolean().optional(),
  31. subagent: z.boolean().optional(),
  32. memory: z.boolean().optional(),
  33. skill: z.boolean().optional(),
  34. mcp: z.boolean().optional(),
  35. });
  36. const memorySchema = z.object({
  37. use: z.boolean().optional(),
  38. });
  39. const mcpServerBaseSchema = {
  40. alwaysLoad: z.boolean().optional(),
  41. // 设置页和 MCP adapter 已支持协议选择;配置入口漏掉该字段会因 strict 校验丢弃整个 server。
  42. protocolVersion: z.enum(["auto", "legacy", "2026-07-28"]).optional(),
  43. enabled: z.boolean().optional(),
  44. timeoutMs: positiveNumberSchema.optional(),
  45. };
  46. const mcpOAuthSchema = z.union([
  47. z
  48. .object({
  49. type: z.literal("client_credentials"),
  50. clientId: z.string().min(1),
  51. clientSecret: z.string().min(1),
  52. clientName: z.string().min(1).optional(),
  53. scope: z.string().optional(),
  54. })
  55. .strict(),
  56. z
  57. .object({
  58. type: z.literal("authorization_code"),
  59. clientId: z.string().min(1).optional(),
  60. clientSecret: z.string().min(1).optional(),
  61. clientName: z.string().min(1).optional(),
  62. redirectPath: z.string().min(1).optional(),
  63. scope: z.string().optional(),
  64. })
  65. .strict(),
  66. ]);
  67. const mcpStdioServerSchema = z
  68. .object({
  69. ...mcpServerBaseSchema,
  70. type: z.literal("stdio"),
  71. command: z.string().min(1),
  72. args: z.array(z.string()).optional(),
  73. cwd: z.string().min(1).optional(),
  74. env: stringRecordSchema.optional(),
  75. })
  76. .strict();
  77. const mcpHttpServerSchema = z
  78. .object({
  79. ...mcpServerBaseSchema,
  80. type: z.literal("http"),
  81. url: z.string().min(1),
  82. headers: stringRecordSchema.optional(),
  83. oauth: mcpOAuthSchema.optional(),
  84. })
  85. .strict();
  86. const mcpSseServerSchema = z
  87. .object({
  88. ...mcpServerBaseSchema,
  89. type: z.literal("sse"),
  90. url: z.string().min(1),
  91. headers: stringRecordSchema.optional(),
  92. oauth: mcpOAuthSchema.optional(),
  93. })
  94. .strict();
  95. const mcpServerSchema = z.preprocess(
  96. normalizeMcpServerConfigInput,
  97. z.discriminatedUnion("type", [mcpStdioServerSchema, mcpHttpServerSchema, mcpSseServerSchema]),
  98. );
  99. const mcpSchema = z.object({
  100. servers: z.record(z.string(), mcpServerSchema).optional(),
  101. });
  102. const pluginOptionValueSchema = z.union([z.string(), z.number(), z.boolean()]);
  103. const pluginMarketplaceSourceSchema = z.discriminatedUnion("source", [
  104. z
  105. .object({
  106. source: z.literal("url"),
  107. url: z.string().min(1),
  108. headers: stringRecordSchema.optional(),
  109. })
  110. .strict(),
  111. z
  112. .object({
  113. source: z.literal("github"),
  114. repo: z.string().min(1),
  115. ref: z.string().min(1).optional(),
  116. path: z.string().min(1).optional(),
  117. sparsePaths: z.array(z.string().min(1)).optional(),
  118. })
  119. .strict(),
  120. z
  121. .object({
  122. source: z.literal("git"),
  123. url: z.string().min(1),
  124. ref: z.string().min(1).optional(),
  125. path: z.string().min(1).optional(),
  126. sparsePaths: z.array(z.string().min(1)).optional(),
  127. })
  128. .strict(),
  129. z
  130. .object({
  131. source: z.literal("npm"),
  132. package: z.string().min(1),
  133. })
  134. .strict(),
  135. z
  136. .object({
  137. source: z.literal("file"),
  138. path: z.string().min(1),
  139. })
  140. .strict(),
  141. z
  142. .object({
  143. source: z.literal("directory"),
  144. path: z.string().min(1),
  145. })
  146. .strict(),
  147. ]);
  148. const pluginsSchema = z.object({
  149. enabled: z.boolean().optional(),
  150. dirs: z.array(z.string().min(1)).optional(),
  151. enabledPlugins: z.record(z.string(), z.boolean()).optional(),
  152. extraKnownMarketplaces: z
  153. .record(z.string().min(1), z.object({ source: pluginMarketplaceSourceSchema }).strict())
  154. .optional(),
  155. options: z.record(z.string(), z.record(z.string(), pluginOptionValueSchema)).optional(),
  156. suppressedBuiltins: z.array(z.string().min(1)).optional(),
  157. });
  158. export const LEGACY_CUA_PLUGIN_ID = "zcode-cua@zcode-plugins-official";
  159. export const CANONICAL_CUA_PLUGIN_ID = "computer-use@zcode-plugins-official";
  160. export function canonicalizePluginId(pluginId: string): string {
  161. return pluginId === LEGACY_CUA_PLUGIN_ID ? CANONICAL_CUA_PLUGIN_ID : pluginId;
  162. }
  163. export function pluginIdAliases(pluginId: string): readonly string[] {
  164. return canonicalizePluginId(pluginId) === CANONICAL_CUA_PLUGIN_ID
  165. ? [CANONICAL_CUA_PLUGIN_ID, LEGACY_CUA_PLUGIN_ID]
  166. : [pluginId];
  167. }
  168. const skillToggleSchema = z.object({
  169. enable: z.boolean().optional(),
  170. });
  171. // skill / command 可用性覆盖:key 为对应 .md 的绝对路径,enable:false 表示禁用
  172. const skillCommandOverrideSchema = z
  173. .object({
  174. enable: z.boolean().optional(),
  175. })
  176. .passthrough();
  177. const skillCommandOverridesSchema = z.record(z.string(), skillCommandOverrideSchema);
  178. const skillsSchema = z
  179. .object({
  180. enabled: z.boolean().optional(),
  181. includeInstructions: z.boolean().optional(),
  182. metadataBudget: positiveNumberSchema.optional(),
  183. roots: z.array(z.string()).optional(),
  184. })
  185. .catchall(skillToggleSchema);
  186. const loggingSchema = z.object({
  187. level: z.enum(["debug", "info", "warn", "error"]).optional(),
  188. format: z.enum(["text", "json"]).optional(),
  189. });
  190. const uiSchema = z.object({
  191. locale: z.enum(["auto", "en-US", "zh-CN"]).optional(),
  192. theme: z.enum(["auto", "dark", "light"]).optional(),
  193. });
  194. const toolConcurrencySchema = z.object({
  195. maxConcurrency: positiveNumberSchema.optional(),
  196. });
  197. const modelAnomalyGuardSchema = z.object({
  198. toolCallWarningThreshold: positiveIntegerSchema.optional(),
  199. repeatedToolCallWarningThreshold: positiveIntegerSchema.optional(),
  200. maxBudgetWarningsPerTurn: z.number().int().nonnegative().optional(),
  201. });
  202. // Hooks schema:
  203. // 理想态是 re-export shared/workspace-hook-config,但两个 pnpm workspace 解析出物理
  204. // 不同的 zod 实例(adapters 4.4.3 / shared 4.3.6):shared schema 嵌入本包组合 schema
  205. // 会让 dts 引用 foreign zod 内部类型(TS2742),typeof/ZodType 注解都会落入类型循环。
  206. // 因此本副本按原样保留(本包 zod 构造),并保持与 shared 的校验语义等价;
  207. // 运行时校验语义仍以 shared 为准(discovery/trust 装配入口都走 shared schema——
  208. // 本 schema 只负责配置文件装载诊断)。若未来统一 zod 实例,应删除本副本改 re-export。
  209. export const hookProcessSchema = z
  210. .object({
  211. type: z.literal("process"),
  212. command: z.string().min(1),
  213. enabled: z.boolean().optional(),
  214. args: z.array(z.string()).optional(),
  215. timeoutMs: positiveNumberSchema.optional(),
  216. statusMessage: z.string().min(1).optional(),
  217. })
  218. .passthrough();
  219. export const hookCommandSchema = z
  220. .object({
  221. type: z.literal("command"),
  222. command: z.string().min(1),
  223. enabled: z.boolean().optional(),
  224. async: z.boolean().optional(),
  225. shell: z.union([z.literal(true), z.string().min(1)]).optional(),
  226. timeout: positiveNumberSchema.optional(),
  227. timeoutMs: positiveNumberSchema.optional(),
  228. statusMessage: z.string().min(1).optional(),
  229. })
  230. .passthrough();
  231. export const hookMatcherSchema = z
  232. .object({
  233. matcher: z.string().min(1).optional(),
  234. hooks: z.array(z.discriminatedUnion("type", [hookProcessSchema, hookCommandSchema])).min(1),
  235. })
  236. .strict();
  237. export const hooksSchema = z
  238. .object({
  239. enabled: z.boolean().optional(),
  240. timeoutMs: positiveNumberSchema.optional(),
  241. maxOutputBytes: positiveNumberSchema.optional(),
  242. events: z
  243. .object({
  244. SessionStart: z.array(hookMatcherSchema).optional(),
  245. UserPromptSubmit: z.array(hookMatcherSchema).optional(),
  246. PreToolUse: z.array(hookMatcherSchema).optional(),
  247. PermissionRequest: z.array(hookMatcherSchema).optional(),
  248. PostToolUse: z.array(hookMatcherSchema).optional(),
  249. PostToolUseFailure: z.array(hookMatcherSchema).optional(),
  250. Stop: z.array(hookMatcherSchema).optional(),
  251. })
  252. .strict()
  253. .optional(),
  254. })
  255. .strict();
  256. export const ZCodeConfigFileSchema = z
  257. .object({
  258. $schema: z.string().optional(),
  259. modelStream: modelStreamSchema.optional(),
  260. permission: permissionSchema.optional(),
  261. storage: storageSchema.optional(),
  262. network: networkSchema.optional(),
  263. features: featuresSchema.optional(),
  264. memory: memorySchema.optional(),
  265. mcp: mcpSchema.optional(),
  266. plugins: pluginsSchema.optional(),
  267. skills: skillsSchema.optional(),
  268. skill: skillCommandOverridesSchema.optional(),
  269. command: skillCommandOverridesSchema.optional(),
  270. logging: loggingSchema.optional(),
  271. ui: uiSchema.optional(),
  272. toolConcurrency: toolConcurrencySchema.optional(),
  273. modelAnomalyGuard: modelAnomalyGuardSchema.optional(),
  274. hooks: hooksSchema.optional(),
  275. })
  276. .passthrough();
  277. export type ZCodeConfigFile = z.infer<typeof ZCodeConfigFileSchema>;
  278. type SkillCommandOverrideMap = Record<string, { enable?: boolean }>;
  279. export type ConfigDiagnosticSeverity = "warning" | "error";
  280. export type ConfigDiagnosticCode =
  281. | "config_file_invalid"
  282. | "config_mcp_server_invalid"
  283. | "config_project_hooks_pending_trust";
  284. export interface ConfigDiagnostic {
  285. code: ConfigDiagnosticCode;
  286. filePath?: string;
  287. message: string;
  288. path?: string;
  289. severity: ConfigDiagnosticSeverity;
  290. }
  291. export interface ParseConfigFileResult {
  292. config: RuntimeConfigPatch;
  293. diagnostics: ConfigDiagnostic[];
  294. }
  295. function normalizeMcpServerConfigInput(value: unknown): unknown {
  296. if (typeof value !== "object" || value === null || Array.isArray(value)) {
  297. return value;
  298. }
  299. const server = { ...(value as Record<string, unknown>) };
  300. if (!("env" in server) && "environment" in server) {
  301. // 旧配置和部分外部导入使用 environment;运行态只消费 env。
  302. // 在解析入口归一化,避免一个 legacy MCP server 拖垮整份 config。
  303. server.env = server.environment;
  304. }
  305. delete server.environment;
  306. if (typeof server.enable === "boolean" || typeof server.enabled === "boolean") {
  307. // 历史遗留兜底:桌面端早期把停用状态写成 enable,而契约字段一直是 enabled。
  308. // 桌面端与 mcp-sync 现在只写 enabled,并在加载配置时把存量 enable 就地迁移落盘;
  309. // CLI 是只读解析、不能写盘,这里只覆盖「用户先跑 CLI、还没开过桌面端」的窗口。
  310. // 冲突时以「停用」为准:桌面端写 enable:false 时不会清理外部导入残留的 enabled:true,
  311. // 按 enabled 取值会把用户关掉的 server 重新拉起(停用了还在被调用)。
  312. // 存量配置迁移完毕后,这段连同下面的 delete 可以整块删除。
  313. server.enabled = server.enable === false ? false : (server.enabled ?? true);
  314. }
  315. delete server.enable;
  316. // External MCP configs may carry provider-specific timeout fields. ZCode does not migrate
  317. // those values, but the strict runtime schema should still accept old imported entries.
  318. delete server.timeout;
  319. delete server.startup_timeout_sec;
  320. if (server.type === "remote") {
  321. // 外部 Agent 配置常把 HTTP MCP 标记为 remote;ZCode 运行态协议类型是 http。
  322. server.type = "http";
  323. } else if (typeof server.type !== "string") {
  324. // app 管理层把 command 形态视为默认 stdio;CLI 也需要同样推断,
  325. // 否则历史 app 配置缺少 type 时会阻断模型配置加载。
  326. if (typeof server.command === "string" && server.command.trim().length > 0) {
  327. server.type = "stdio";
  328. } else if (typeof server.url === "string" && server.url.trim().length > 0) {
  329. server.type = "http";
  330. }
  331. }
  332. if (
  333. (server.type === "http" || server.type === "sse") &&
  334. server.headers === undefined &&
  335. server.http_headers !== undefined
  336. ) {
  337. // 兼容历史 BigModel MCP 配置:旧字段名是 http_headers,agent runtime 只消费 headers。
  338. server.headers = server.http_headers;
  339. }
  340. delete server.http_headers;
  341. return server;
  342. }
  343. export function parseConfigFileToRuntimePatchWithDiagnostics(
  344. value: unknown,
  345. ): ParseConfigFileResult {
  346. const diagnostics: ConfigDiagnostic[] = [];
  347. const normalized = normalizeConfigFileInput(value, diagnostics);
  348. const parsed = ZCodeConfigFileSchema.parse(normalized);
  349. return {
  350. config: parsedConfigFileToRuntimePatch(parsed),
  351. diagnostics,
  352. };
  353. }
  354. function parsedConfigFileToRuntimePatch(parsed: ZCodeConfigFile): RuntimeConfigPatch {
  355. const config: RuntimeConfigPatch = {};
  356. if (parsed.modelStream) config.modelStream = parsed.modelStream;
  357. if (parsed.permission) config.permission = parsed.permission;
  358. if (parsed.storage) config.storage = parsed.storage;
  359. if (parsed.network) config.network = parsed.network;
  360. if (parsed.features) config.features = parsed.features;
  361. if (parsed.memory) config.memory = parsed.memory;
  362. if (parsed.mcp) config.mcp = parsed.mcp;
  363. if (parsed.plugins) config.plugins = normalizePluginConfig(parsed.plugins);
  364. const skillsConfig = parseSkillsRuntimeConfig(parsed.skills);
  365. if (skillsConfig) config.skills = skillsConfig;
  366. const skillOverrides = mergeSkillCommandOverrides(
  367. parsed.skill,
  368. parseSkillOverridesFromPluralSkills(parsed.skills),
  369. );
  370. if (skillOverrides) config.skillOverrides = skillOverrides;
  371. if (parsed.command) config.commandOverrides = parsed.command;
  372. if (parsed.logging) config.logging = parsed.logging;
  373. if (parsed.ui) config.ui = parsed.ui;
  374. if (parsed.toolConcurrency) config.toolConcurrency = parsed.toolConcurrency;
  375. if (parsed.modelAnomalyGuard) config.modelAnomalyGuard = parsed.modelAnomalyGuard;
  376. if (parsed.hooks) config.hooks = parsed.hooks;
  377. return config;
  378. }
  379. function normalizePluginConfig(
  380. plugins: ZCodeConfigFile["plugins"],
  381. ): NonNullable<RuntimeConfigPatch["plugins"]> {
  382. if (!plugins) return {};
  383. const enabledPlugins = plugins.enabledPlugins ? { ...plugins.enabledPlugins } : undefined;
  384. if (enabledPlugins?.[LEGACY_CUA_PLUGIN_ID] !== undefined) {
  385. if (enabledPlugins[CANONICAL_CUA_PLUGIN_ID] === undefined) {
  386. enabledPlugins[CANONICAL_CUA_PLUGIN_ID] = enabledPlugins[LEGACY_CUA_PLUGIN_ID];
  387. }
  388. delete enabledPlugins[LEGACY_CUA_PLUGIN_ID];
  389. }
  390. const suppressedBuiltins = plugins.suppressedBuiltins
  391. ? plugins.suppressedBuiltins.reduce<string[]>((ids, id) => {
  392. const canonicalId = id === LEGACY_CUA_PLUGIN_ID ? CANONICAL_CUA_PLUGIN_ID : id;
  393. if (canonicalId === CANONICAL_CUA_PLUGIN_ID && ids.includes(CANONICAL_CUA_PLUGIN_ID)) {
  394. return ids;
  395. }
  396. ids.push(canonicalId);
  397. return ids;
  398. }, [])
  399. : undefined;
  400. const options = plugins.options ? { ...plugins.options } : undefined;
  401. if (options?.[LEGACY_CUA_PLUGIN_ID] !== undefined) {
  402. if (options[CANONICAL_CUA_PLUGIN_ID] === undefined) {
  403. options[CANONICAL_CUA_PLUGIN_ID] = options[LEGACY_CUA_PLUGIN_ID];
  404. }
  405. delete options[LEGACY_CUA_PLUGIN_ID];
  406. }
  407. return {
  408. ...plugins,
  409. ...(enabledPlugins ? { enabledPlugins } : {}),
  410. ...(suppressedBuiltins ? { suppressedBuiltins } : {}),
  411. ...(options ? { options } : {}),
  412. };
  413. }
  414. function normalizeConfigFileInput(value: unknown, diagnostics: ConfigDiagnostic[]): unknown {
  415. if (!isPlainRecord(value)) return value;
  416. const root = { ...value };
  417. const mcp = root.mcp;
  418. if (!isPlainRecord(mcp)) return root;
  419. const servers = mcp.servers;
  420. if (servers === undefined) return root;
  421. if (!isPlainRecord(servers)) {
  422. diagnostics.push({
  423. code: "config_mcp_server_invalid",
  424. message: "mcp.servers must be a JSON object; ignoring all MCP servers.",
  425. path: "mcp.servers",
  426. severity: "warning",
  427. });
  428. root.mcp = {
  429. ...mcp,
  430. servers: {},
  431. };
  432. return root;
  433. }
  434. const parsedServers: Record<string, unknown> = {};
  435. for (const [name, server] of Object.entries(servers)) {
  436. const parsed = mcpServerSchema.safeParse(server);
  437. if (parsed.success) {
  438. parsedServers[name] = parsed.data;
  439. continue;
  440. }
  441. // MCP server 是可选工具配置,单个 server 错误不应导致 provider/plugin 等配置丢失。
  442. diagnostics.push({
  443. code: "config_mcp_server_invalid",
  444. message: formatMcpServerError(parsed.error),
  445. path: `mcp.servers.${name}`,
  446. severity: "warning",
  447. });
  448. }
  449. root.mcp = {
  450. ...mcp,
  451. servers: parsedServers,
  452. };
  453. return root;
  454. }
  455. function formatMcpServerError(error: z.ZodError): string {
  456. return error.issues
  457. .map((issue) => {
  458. const path = issue.path.length > 0 ? issue.path.join(".") : "<server>";
  459. return `${path}: ${issue.message}`;
  460. })
  461. .join("; ");
  462. }
  463. function isPlainRecord(value: unknown): value is Record<string, unknown> {
  464. return typeof value === "object" && value !== null && !Array.isArray(value);
  465. }
  466. function readPositiveNumber(value: unknown): number | undefined {
  467. return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined;
  468. }
  469. function parseSkillsRuntimeConfig(
  470. skills: ZCodeConfigFile["skills"],
  471. ): RuntimeConfigPatch["skills"] | undefined {
  472. if (!skills) return undefined;
  473. const next: NonNullable<RuntimeConfigPatch["skills"]> = {};
  474. if (skills.enabled !== undefined) next.enabled = skills.enabled;
  475. if (skills.includeInstructions !== undefined) {
  476. next.includeInstructions = skills.includeInstructions;
  477. }
  478. if (skills.metadataBudget !== undefined) next.metadataBudget = skills.metadataBudget;
  479. if (skills.roots !== undefined) next.roots = skills.roots;
  480. return Object.keys(next).length > 0 ? next : undefined;
  481. }
  482. function parseSkillOverridesFromPluralSkills(
  483. skills: ZCodeConfigFile["skills"],
  484. ): SkillCommandOverrideMap | undefined {
  485. if (!skills) return undefined;
  486. const overrides: SkillCommandOverrideMap = {};
  487. for (const [path, value] of Object.entries(skills)) {
  488. if (!isAbsoluteConfigPath(path) || !isSkillCommandOverrideValue(value)) {
  489. continue;
  490. }
  491. // 设置页当前把单个 skill 开关写到 skills[SKILL.md 绝对路径]。
  492. // agent 运行态只消费 skillOverrides,所以这里在配置解析阶段统一映射,避免 UI 状态和 agent 实际加载分叉。
  493. overrides[path] = { enable: value.enable };
  494. }
  495. return Object.keys(overrides).length > 0 ? overrides : undefined;
  496. }
  497. function mergeSkillCommandOverrides(
  498. ...overridesList: Array<SkillCommandOverrideMap | undefined>
  499. ): SkillCommandOverrideMap | undefined {
  500. const merged: SkillCommandOverrideMap = {};
  501. for (const overrides of overridesList) {
  502. if (!overrides) continue;
  503. Object.assign(merged, overrides);
  504. }
  505. return Object.keys(merged).length > 0 ? merged : undefined;
  506. }
  507. function isSkillCommandOverrideValue(value: unknown): value is { enable?: boolean } {
  508. return (
  509. typeof value === "object" &&
  510. value !== null &&
  511. !Array.isArray(value) &&
  512. ("enable" in value ? typeof (value as { enable?: unknown }).enable === "boolean" : true)
  513. );
  514. }
  515. function isAbsoluteConfigPath(path: string): boolean {
  516. return path.startsWith("/") || path.startsWith("\\") || /^[A-Za-z]:[\\/]/.test(path);
  517. }