windowsCuaDevRuntime.ts 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. /* eslint-disable max-lines -- source/product 两种解析模式共享同一稳定错误契约与路径校验,拆开会引入循环依赖 */
  2. import { createHash } from "node:crypto";
  3. import type { Stats } from "node:fs";
  4. import * as fs from "node:fs/promises";
  5. import { isAbsolute, join, relative, resolve, sep, win32 as windowsPath } from "node:path";
  6. const DEV_ROOT_ENV = "ZCODE_CUA_DEV_ROOT";
  7. const EXPECTED_PACKAGE_NAME = "@zcode/zcode-cua";
  8. const PACKAGE_JSON = "package.json";
  9. const PRODUCT_RUNTIME_MANIFEST = "runtime-manifest.json";
  10. const PRODUCT_RUNTIME_SEGMENTS = ["tools", "cua-helper"] as const;
  11. export interface WindowsCuaRuntime {
  12. root: string;
  13. entryPath: string;
  14. addonPath: string;
  15. command: string;
  16. commandEnv: Record<string, string>;
  17. }
  18. export interface WindowsCuaRuntimeFileSystem {
  19. stat(path: string): Promise<Pick<Stats, "isDirectory" | "isFile">>;
  20. lstat?(path: string): Promise<Pick<Stats, "isDirectory" | "isFile" | "isSymbolicLink">>;
  21. realpath?(path: string): Promise<string>;
  22. readFile(path: string, encoding?: "utf8"): Promise<string | Uint8Array>;
  23. }
  24. export interface WindowsCuaRuntimeResolveOptions {
  25. platform?: NodeJS.Platform;
  26. env?: NodeJS.ProcessEnv;
  27. resourcesPath?: string;
  28. arch?: NodeJS.Architecture;
  29. electronVersion?: string;
  30. fileSystem?: WindowsCuaRuntimeFileSystem;
  31. hashBytes?: (bytes: string | Uint8Array) => Promise<string>;
  32. }
  33. export type WindowsCuaDevRuntimeResolutionReason =
  34. | "unsupported-platform"
  35. | "development-root-not-absolute"
  36. | "development-root-not-found"
  37. | "invalid-package"
  38. | "missing-helper-entry"
  39. | "missing-native-addon"
  40. | "missing-resources-path"
  41. | "resources-path-not-absolute"
  42. | "invalid-runtime-manifest"
  43. | "incompatible-runtime-manifest"
  44. | "invalid-artifact-path"
  45. | "artifact-integrity-mismatch";
  46. export class WindowsCuaDevRuntimeResolutionError extends Error {
  47. constructor(
  48. readonly reason: WindowsCuaDevRuntimeResolutionReason,
  49. message: string,
  50. readonly artifact?: string,
  51. ) {
  52. super(message);
  53. this.name = "WindowsCuaDevRuntimeResolutionError";
  54. }
  55. }
  56. const defaultFileSystem: WindowsCuaRuntimeFileSystem = {
  57. stat: (path) => fs.stat(path),
  58. lstat: (path) => fs.lstat(path),
  59. realpath: (path) => fs.realpath(path),
  60. readFile: (path, encoding) =>
  61. encoding === "utf8" ? fs.readFile(path, encoding) : fs.readFile(path),
  62. };
  63. const defaultHashBytes = async (bytes: string | Uint8Array): Promise<string> =>
  64. createHash("sha256").update(bytes).digest("hex");
  65. /**
  66. * Windows 产品运行时解析边界:
  67. * - 显式开发目录具有最高优先级,配置错误时 fail closed,不能悄悄改用安装资源;
  68. * - 产品模式只读取 resources/tools/cua-helper,不搜索源码目录或 node_modules。
  69. */
  70. export async function resolveWindowsCuaRuntime(
  71. options: WindowsCuaRuntimeResolveOptions = {},
  72. ): Promise<WindowsCuaRuntime> {
  73. if ((options.platform ?? process.platform) !== "win32") {
  74. throw new WindowsCuaDevRuntimeResolutionError(
  75. "unsupported-platform",
  76. "Windows CUA runtime is only available on win32.",
  77. );
  78. }
  79. const configuredRoot = (options.env ?? process.env)[DEV_ROOT_ENV]?.trim();
  80. if (configuredRoot) {
  81. return resolveDevelopmentRuntime(configuredRoot, options.fileSystem ?? defaultFileSystem);
  82. }
  83. return resolvePackagedRuntime(options, options.fileSystem ?? defaultFileSystem);
  84. }
  85. async function resolveDevelopmentRuntime(
  86. configuredRoot: string,
  87. fileSystem: WindowsCuaRuntimeFileSystem,
  88. ): Promise<WindowsCuaRuntime> {
  89. const isHostAbsolute = isAbsolute(configuredRoot);
  90. const isWindowsAbsolute = windowsPath.isAbsolute(configuredRoot);
  91. if (!isHostAbsolute && !isWindowsAbsolute) {
  92. throw new WindowsCuaDevRuntimeResolutionError(
  93. "development-root-not-absolute",
  94. `${DEV_ROOT_ENV} must be an absolute path.`,
  95. );
  96. }
  97. // 构建和测试会在非 Windows 主机校验 Windows runtime;宿主 path.isAbsolute
  98. // 不认识 C:\ 路径,不能在进入可注入文件系统前误判为相对路径。
  99. const root = isHostAbsolute ? resolve(configuredRoot) : windowsPath.normalize(configuredRoot);
  100. const rootRealPath = await requireDevelopmentRuntimeRoot(fileSystem, root);
  101. const producerContract = await requireExpectedPackage(
  102. fileSystem,
  103. join(root, PACKAGE_JSON),
  104. rootRealPath,
  105. );
  106. const entryPath = resolveManifestArtifact(root, producerContract.entry, "entry");
  107. await requireContainedRegularArtifact(
  108. fileSystem,
  109. rootRealPath,
  110. entryPath,
  111. producerContract.entry,
  112. "missing-helper-entry",
  113. "entry",
  114. );
  115. const addonPath = resolveManifestArtifact(root, producerContract.addon, "addon");
  116. await requireContainedRegularArtifact(
  117. fileSystem,
  118. rootRealPath,
  119. addonPath,
  120. producerContract.addon,
  121. "missing-native-addon",
  122. "addon",
  123. );
  124. return {
  125. root,
  126. entryPath,
  127. addonPath,
  128. command: process.execPath,
  129. commandEnv: { ELECTRON_RUN_AS_NODE: "1" },
  130. };
  131. }
  132. interface RuntimeManifest {
  133. schemaVersion: 1;
  134. packageName: typeof EXPECTED_PACKAGE_NAME;
  135. packageVersion: string;
  136. platform: "win32";
  137. arch: NodeJS.Architecture;
  138. electronVersion: string;
  139. entry: string;
  140. addon: string;
  141. sha256: {
  142. entry: string;
  143. addon: string;
  144. };
  145. }
  146. async function resolvePackagedRuntime(
  147. options: WindowsCuaRuntimeResolveOptions,
  148. fileSystem: WindowsCuaRuntimeFileSystem,
  149. ): Promise<WindowsCuaRuntime> {
  150. const processResourcesPath = (process as NodeJS.Process & { resourcesPath?: string })
  151. .resourcesPath;
  152. const resourcesPath = (options.resourcesPath ?? processResourcesPath)?.trim();
  153. if (!resourcesPath) {
  154. throw new WindowsCuaDevRuntimeResolutionError(
  155. "missing-resources-path",
  156. "Windows CUA packaged runtime requires resourcesPath.",
  157. );
  158. }
  159. if (!isAbsolute(resourcesPath)) {
  160. throw new WindowsCuaDevRuntimeResolutionError(
  161. "resources-path-not-absolute",
  162. "Windows CUA packaged runtime resourcesPath must be absolute.",
  163. );
  164. }
  165. const root = resolve(resourcesPath, ...PRODUCT_RUNTIME_SEGMENTS);
  166. const rootRealPath = await requirePackagedRuntimeRoot(fileSystem, root);
  167. const manifestPath = join(root, PRODUCT_RUNTIME_MANIFEST);
  168. const manifest = await readRuntimeManifest(fileSystem, manifestPath, rootRealPath);
  169. validateRuntimeManifest(manifest, {
  170. arch: options.arch ?? process.arch,
  171. electronVersion: options.electronVersion ?? process.versions.electron,
  172. });
  173. const entryPath = resolveManifestArtifact(root, manifest.entry, "entry");
  174. const addonPath = resolveManifestArtifact(root, manifest.addon, "addon");
  175. await Promise.all([
  176. requireContainedRegularArtifact(
  177. fileSystem,
  178. rootRealPath,
  179. entryPath,
  180. manifest.entry,
  181. "missing-helper-entry",
  182. "entry",
  183. ),
  184. requireContainedRegularArtifact(
  185. fileSystem,
  186. rootRealPath,
  187. addonPath,
  188. manifest.addon,
  189. "missing-native-addon",
  190. "addon",
  191. ),
  192. ]);
  193. const [entryBytes, addonBytes] = await Promise.all([
  194. readRequiredArtifact(fileSystem, entryPath, manifest.entry, "missing-helper-entry", "entry"),
  195. readRequiredArtifact(fileSystem, addonPath, manifest.addon, "missing-native-addon", "addon"),
  196. ]);
  197. const hashBytes = options.hashBytes ?? defaultHashBytes;
  198. const [entryHash, addonHash] = await Promise.all([hashBytes(entryBytes), hashBytes(addonBytes)]);
  199. requireArtifactHash(entryHash, manifest.sha256.entry, "entry");
  200. requireArtifactHash(addonHash, manifest.sha256.addon, "addon");
  201. return {
  202. root,
  203. entryPath,
  204. addonPath,
  205. command: process.execPath,
  206. commandEnv: { ELECTRON_RUN_AS_NODE: "1" },
  207. };
  208. }
  209. async function readRuntimeManifest(
  210. fileSystem: WindowsCuaRuntimeFileSystem,
  211. manifestPath: string,
  212. rootRealPath: string,
  213. ): Promise<RuntimeManifest> {
  214. try {
  215. const stats = await lstatFile(fileSystem, manifestPath);
  216. if (!stats.isFile() || stats.isSymbolicLink()) {
  217. throw new Error("manifest is not a regular file");
  218. }
  219. const manifestRealPath = await realpathFile(fileSystem, manifestPath);
  220. if (!isPathContainedBy(rootRealPath, manifestRealPath)) {
  221. throw new Error("manifest escapes runtime root");
  222. }
  223. const contents = await fileSystem.readFile(manifestPath, "utf8");
  224. if (typeof contents !== "string") throw new Error("manifest is not text");
  225. const value: unknown = JSON.parse(contents);
  226. if (!value || typeof value !== "object" || Array.isArray(value)) {
  227. throw new Error("manifest is not an object");
  228. }
  229. return value as RuntimeManifest;
  230. } catch {
  231. throw new WindowsCuaDevRuntimeResolutionError(
  232. "invalid-runtime-manifest",
  233. `Windows CUA packaged runtime has an invalid ${PRODUCT_RUNTIME_MANIFEST}.`,
  234. PRODUCT_RUNTIME_MANIFEST,
  235. );
  236. }
  237. }
  238. async function requirePackagedRuntimeRoot(
  239. fileSystem: WindowsCuaRuntimeFileSystem,
  240. root: string,
  241. ): Promise<string> {
  242. try {
  243. const stats = await lstatFile(fileSystem, root);
  244. if (!stats.isDirectory() || stats.isSymbolicLink()) {
  245. throw new Error("runtime root is not a regular directory");
  246. }
  247. const rootRealPath = await realpathFile(fileSystem, root);
  248. if (!samePhysicalPath(root, rootRealPath)) {
  249. throw new Error("runtime root resolves outside its packaged location");
  250. }
  251. return rootRealPath;
  252. } catch {
  253. throw new WindowsCuaDevRuntimeResolutionError(
  254. "invalid-runtime-manifest",
  255. `Windows CUA packaged runtime has an invalid ${PRODUCT_RUNTIME_MANIFEST}.`,
  256. PRODUCT_RUNTIME_MANIFEST,
  257. );
  258. }
  259. }
  260. function validateRuntimeManifest(
  261. manifest: RuntimeManifest,
  262. expected: { arch: NodeJS.Architecture; electronVersion?: string },
  263. ): void {
  264. const hashPattern = /^[0-9a-f]{64}$/u;
  265. const hasExactManifestKeys = hasExactKeys(manifest, [
  266. "schemaVersion",
  267. "packageName",
  268. "packageVersion",
  269. "platform",
  270. "arch",
  271. "electronVersion",
  272. "entry",
  273. "addon",
  274. "sha256",
  275. ]);
  276. const hasExactHashKeys =
  277. manifest.sha256 !== null &&
  278. typeof manifest.sha256 === "object" &&
  279. hasExactKeys(manifest.sha256, ["entry", "addon"]);
  280. const compatible =
  281. hasExactManifestKeys &&
  282. manifest.schemaVersion === 1 &&
  283. manifest.packageName === EXPECTED_PACKAGE_NAME &&
  284. isNonEmptyTrimmedString(manifest.packageVersion) &&
  285. manifest.platform === "win32" &&
  286. (manifest.arch === "x64" || manifest.arch === "arm64") &&
  287. manifest.arch === expected.arch &&
  288. typeof expected.electronVersion === "string" &&
  289. expected.electronVersion.length > 0 &&
  290. manifest.electronVersion === expected.electronVersion &&
  291. typeof manifest.entry === "string" &&
  292. typeof manifest.addon === "string" &&
  293. manifest.entry !== manifest.addon &&
  294. hasExactHashKeys &&
  295. hashPattern.test(manifest.sha256.entry) &&
  296. hashPattern.test(manifest.sha256.addon);
  297. if (compatible) return;
  298. throw new WindowsCuaDevRuntimeResolutionError(
  299. "incompatible-runtime-manifest",
  300. `Windows CUA packaged runtime ${PRODUCT_RUNTIME_MANIFEST} is incompatible with this runtime.`,
  301. PRODUCT_RUNTIME_MANIFEST,
  302. );
  303. }
  304. async function requireDevelopmentRuntimeRoot(
  305. fileSystem: WindowsCuaRuntimeFileSystem,
  306. root: string,
  307. ): Promise<string> {
  308. try {
  309. const stats = await lstatFile(fileSystem, root);
  310. if (!stats.isDirectory() || stats.isSymbolicLink()) {
  311. throw new Error("development root is not a regular directory");
  312. }
  313. const rootRealPath = await realpathFile(fileSystem, root);
  314. // 根因:stat 会跟随 symlink/junction;开发目录必须绑定到用户显式配置的物理根。
  315. if (!samePhysicalPath(root, rootRealPath)) {
  316. throw new Error("development root resolves outside its configured location");
  317. }
  318. return rootRealPath;
  319. } catch {
  320. throw new WindowsCuaDevRuntimeResolutionError(
  321. "development-root-not-found",
  322. `${DEV_ROOT_ENV} must reference an existing regular directory.`,
  323. );
  324. }
  325. }
  326. function isNonEmptyTrimmedString(value: unknown): value is string {
  327. return typeof value === "string" && value.length > 0 && value.trim() === value;
  328. }
  329. function hasExactKeys(value: object, expectedKeys: readonly string[]): boolean {
  330. const actualKeys = Object.keys(value).sort();
  331. const sortedExpectedKeys = [...expectedKeys].sort();
  332. return (
  333. actualKeys.length === sortedExpectedKeys.length &&
  334. actualKeys.every((key, index) => key === sortedExpectedKeys[index])
  335. );
  336. }
  337. function resolveManifestArtifact(root: string, artifact: string, field: "entry" | "addon"): string {
  338. // 测试和构建编排可能在非 Windows 主机上检查 Windows 清单;仅用宿主 path.isAbsolute
  339. // 会把 C:\... 误判成相对路径,因此同时按 Windows 路径语义 fail closed。
  340. if (!isCanonicalRelativeArtifactPath(artifact)) {
  341. throwInvalidArtifactPath(field);
  342. }
  343. const artifactPath =
  344. windowsPath.isAbsolute(root) && !isAbsolute(root)
  345. ? join(root, ...artifact.split("/"))
  346. : resolve(root, ...artifact.split("/"));
  347. const relativePath = relative(root, artifactPath);
  348. if (
  349. !relativePath ||
  350. relativePath === ".." ||
  351. relativePath.startsWith(`..${sep}`) ||
  352. isAbsolute(relativePath)
  353. ) {
  354. throwInvalidArtifactPath(field);
  355. }
  356. return artifactPath;
  357. }
  358. function isCanonicalRelativeArtifactPath(artifact: unknown): artifact is string {
  359. if (
  360. typeof artifact !== "string" ||
  361. !artifact ||
  362. artifact.includes("\\") ||
  363. isAbsolute(artifact) ||
  364. windowsPath.isAbsolute(artifact) ||
  365. windowsPath.normalize(artifact).replaceAll("\\", "/") !== artifact
  366. ) {
  367. return false;
  368. }
  369. return !artifact
  370. .split("/")
  371. .some(
  372. (segment) =>
  373. !segment ||
  374. segment === "." ||
  375. segment === ".." ||
  376. segment.includes(":") ||
  377. segment.includes("\0"),
  378. );
  379. }
  380. async function requireContainedRegularArtifact(
  381. fileSystem: WindowsCuaRuntimeFileSystem,
  382. rootRealPath: string,
  383. artifactPath: string,
  384. artifact: string,
  385. missingReason: "missing-helper-entry" | "missing-native-addon",
  386. artifactKind: "entry" | "addon",
  387. ): Promise<void> {
  388. let stats: Pick<Stats, "isFile" | "isSymbolicLink">;
  389. try {
  390. stats = await lstatFile(fileSystem, artifactPath);
  391. } catch {
  392. throwMissingArtifact(missingReason, artifact, artifactKind);
  393. }
  394. if (stats.isSymbolicLink()) {
  395. throwInvalidArtifactPath(artifactKind);
  396. }
  397. if (!stats.isFile()) {
  398. throwMissingArtifact(missingReason, artifact, artifactKind);
  399. }
  400. try {
  401. const artifactRealPath = await realpathFile(fileSystem, artifactPath);
  402. if (!isPathContainedBy(rootRealPath, artifactRealPath)) {
  403. throwInvalidArtifactPath(artifactKind);
  404. }
  405. } catch (error) {
  406. if (error instanceof WindowsCuaDevRuntimeResolutionError) throw error;
  407. throwMissingArtifact(missingReason, artifact, artifactKind);
  408. }
  409. }
  410. function throwMissingArtifact(
  411. reason: "missing-helper-entry" | "missing-native-addon",
  412. artifact: string,
  413. artifactKind: "entry" | "addon",
  414. ): never {
  415. throw new WindowsCuaDevRuntimeResolutionError(
  416. reason,
  417. `Windows CUA runtime is missing required ${artifactKind}: ${artifact}.`,
  418. artifact,
  419. );
  420. }
  421. function lstatFile(
  422. fileSystem: WindowsCuaRuntimeFileSystem,
  423. path: string,
  424. ): Promise<Pick<Stats, "isDirectory" | "isFile" | "isSymbolicLink">> {
  425. return (fileSystem.lstat ?? defaultFileSystem.lstat!)(path);
  426. }
  427. function realpathFile(fileSystem: WindowsCuaRuntimeFileSystem, path: string): Promise<string> {
  428. return (fileSystem.realpath ?? defaultFileSystem.realpath!)(path);
  429. }
  430. function isPathContainedBy(root: string, candidate: string): boolean {
  431. const relativePath = relative(root, candidate);
  432. return (
  433. relativePath.length > 0 &&
  434. relativePath !== ".." &&
  435. !relativePath.startsWith(`..${sep}`) &&
  436. !isAbsolute(relativePath)
  437. );
  438. }
  439. function samePhysicalPath(expected: string, actual: string): boolean {
  440. const normalize = (path: string): string => {
  441. if (windowsPath.isAbsolute(path)) return windowsPath.normalize(path).toLowerCase();
  442. return resolve(path);
  443. };
  444. return normalize(expected) === normalize(actual);
  445. }
  446. async function readRequiredArtifact(
  447. fileSystem: WindowsCuaRuntimeFileSystem,
  448. artifactPath: string,
  449. artifact: string,
  450. reason: "missing-helper-entry" | "missing-native-addon",
  451. artifactKind: "entry" | "addon",
  452. ): Promise<string | Uint8Array> {
  453. try {
  454. return await fileSystem.readFile(artifactPath);
  455. } catch {
  456. // stat 与 read 之间文件仍可能被替换/删除;不能把宿主 I/O 细节泄漏成不稳定诊断。
  457. throw new WindowsCuaDevRuntimeResolutionError(
  458. reason,
  459. `Windows CUA runtime is missing required ${artifactKind}: ${artifact}.`,
  460. artifact,
  461. );
  462. }
  463. }
  464. function throwInvalidArtifactPath(field: "entry" | "addon"): never {
  465. throw new WindowsCuaDevRuntimeResolutionError(
  466. "invalid-artifact-path",
  467. `Windows CUA packaged runtime ${field} must be a contained relative artifact path.`,
  468. field,
  469. );
  470. }
  471. function requireArtifactHash(
  472. actualHash: string,
  473. expectedHash: string,
  474. artifact: "entry" | "addon",
  475. ): void {
  476. if (actualHash === expectedHash) return;
  477. throw new WindowsCuaDevRuntimeResolutionError(
  478. "artifact-integrity-mismatch",
  479. `Windows CUA packaged runtime ${artifact} failed SHA-256 verification.`,
  480. artifact,
  481. );
  482. }
  483. async function requireExpectedPackage(
  484. fileSystem: WindowsCuaRuntimeFileSystem,
  485. packagePath: string,
  486. rootRealPath: string,
  487. ): Promise<{ packageVersion: string; entry: string; addon: string }> {
  488. try {
  489. const stats = await lstatFile(fileSystem, packagePath);
  490. if (!stats.isFile() || stats.isSymbolicLink()) {
  491. throw new Error("package.json is not a regular file");
  492. }
  493. const packageRealPath = await realpathFile(fileSystem, packagePath);
  494. if (!isPathContainedBy(rootRealPath, packageRealPath)) {
  495. throw new Error("package.json escapes development root");
  496. }
  497. const contents = await fileSystem.readFile(packagePath, "utf8");
  498. if (typeof contents !== "string") throw new Error("package.json is not text");
  499. const pkg: unknown = JSON.parse(contents);
  500. if (!isPlainRecord(pkg)) throw new Error("package.json is not an object");
  501. const contract = pkg.zcodeCuaRuntime;
  502. if (
  503. pkg.name !== EXPECTED_PACKAGE_NAME ||
  504. !isNonEmptyTrimmedString(pkg.version) ||
  505. !isPlainRecord(contract) ||
  506. !hasExactKeys(contract, ["schema", "windows"]) ||
  507. contract.schema !== 1 ||
  508. !isPlainRecord(contract.windows) ||
  509. !hasExactKeys(contract.windows, ["entry", "nativeAddon"]) ||
  510. !isCanonicalRelativeArtifactPath(contract.windows.entry) ||
  511. !isCanonicalRelativeArtifactPath(contract.windows.nativeAddon) ||
  512. contract.windows.entry === contract.windows.nativeAddon
  513. ) {
  514. throw new Error("package runtime contract is incompatible");
  515. }
  516. return {
  517. packageVersion: pkg.version,
  518. entry: contract.windows.entry,
  519. addon: contract.windows.nativeAddon,
  520. };
  521. } catch {
  522. // 解析和 I/O 失败共用稳定的 package 诊断,避免依赖底层错误文本。
  523. }
  524. throw new WindowsCuaDevRuntimeResolutionError(
  525. "invalid-package",
  526. `Windows CUA development root package.json must name ${EXPECTED_PACKAGE_NAME} and expose a valid zcodeCuaRuntime contract.`,
  527. PACKAGE_JSON,
  528. );
  529. }
  530. function isPlainRecord(value: unknown): value is Record<string, unknown> {
  531. return typeof value === "object" && value !== null && !Array.isArray(value);
  532. }