@koed-labs/server 0.11.1 → 1.2.0

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.
Files changed (47) hide show
  1. package/README.md +3 -3
  2. package/bin/koed.js +1 -1
  3. package/package.json +2 -2
  4. package/vendor/chunk-2YCDKSKW.js +45 -0
  5. package/vendor/{chunk-TG26CZGQ.js → chunk-355BP3MF.js} +4 -4
  6. package/vendor/{chunk-RCR4XPE3.js → chunk-3VNLZCMB.js} +1 -1
  7. package/vendor/{chunk-NVTMIAAF.js → chunk-7YXEB2CR.js} +18 -17
  8. package/vendor/{chunk-SRKIBFOE.js → chunk-A2TMTAAS.js} +1 -1
  9. package/vendor/{chunk-PL3LWC5C.js → chunk-AJPFOTVX.js} +1 -1
  10. package/vendor/{chunk-O7DW2VAV.js → chunk-BDJR6CKS.js} +4 -3
  11. package/vendor/{chunk-Z5WCAUA6.js → chunk-BMHMNUNK.js} +18 -17
  12. package/vendor/{chunk-C5SNDPAP.js → chunk-CSDTMMRL.js} +4 -4
  13. package/vendor/{chunk-FYYRFX4U.js → chunk-CX73L6YS.js} +67 -38
  14. package/vendor/{chunk-VGIYSDNU.js → chunk-D4XZTNLU.js} +117 -33
  15. package/vendor/{chunk-W2OJZZ6X.js → chunk-DQ5SIGZZ.js} +4 -2
  16. package/vendor/{chunk-4OO6VAU3.js → chunk-G54Q5W6M.js} +1 -1
  17. package/vendor/{chunk-EA4QDDQA.js → chunk-GEIN6UIL.js} +7 -2
  18. package/vendor/{chunk-QRKHHWJJ.js → chunk-H7ETSD25.js} +51 -3
  19. package/vendor/{chunk-NOU7RHYZ.js → chunk-HG47LAWW.js} +5 -4
  20. package/vendor/{chunk-C4V72GXC.js → chunk-HXL36SED.js} +19 -18
  21. package/vendor/{chunk-FN3HUUO2.js → chunk-I5XO5FL4.js} +73 -13
  22. package/vendor/{chunk-TVYEB2GN.js → chunk-J7LW6JFY.js} +48 -10
  23. package/vendor/{chunk-OCILJ737.js → chunk-JG7OELJM.js} +9 -9
  24. package/vendor/{chunk-6KS67EQE.js → chunk-KBECHDUE.js} +1 -1
  25. package/vendor/{chunk-2XKSVKQA.js → chunk-KH4UBONI.js} +3 -2
  26. package/vendor/{chunk-ZIOKV2X6.js → chunk-MFPPURFE.js} +113 -33
  27. package/vendor/{chunk-GFASBPV2.js → chunk-MHFYPBCL.js} +3 -3
  28. package/vendor/{chunk-V67IQB7H.js → chunk-OG7G6DIR.js} +1 -1
  29. package/vendor/{chunk-WDFERJG3.js → chunk-TAQWNZVD.js} +109 -33
  30. package/vendor/{chunk-HC76426R.js → chunk-TMCW2P6G.js} +7 -5
  31. package/vendor/chunk-ULLAURFV.js +8 -0
  32. package/vendor/{chunk-WPIEF4LY.js → chunk-ULUSFNAE.js} +3 -3
  33. package/vendor/{chunk-ZOHNXUDY.js → chunk-VWB3VEOL.js} +493 -20
  34. package/vendor/{chunk-LRP66XEY.js → chunk-XPSPPLX5.js} +14 -14
  35. package/vendor/{chunk-SHLRINKO.js → chunk-XSOQ2U5H.js} +2 -2
  36. package/vendor/{chunk-EDPNYIX5.js → chunk-XTQYFCVY.js} +146 -89
  37. package/vendor/{chunk-CHMH4LH5.js → chunk-XW7AXRDI.js} +3 -3
  38. package/vendor/{chunk-SNKWETM5.js → chunk-Y5OJXAUF.js} +2 -2
  39. package/vendor/chunk-YDZEMIAH.js +11 -0
  40. package/vendor/{chunk-BUIM2M4R.js → chunk-YOMK7KMB.js} +2 -2
  41. package/vendor/{chunk-ALJUSOF7.js → chunk-YY7NMZGD.js} +79 -1
  42. package/vendor/{chunk-BGENSONI.js → chunk-ZKKWLLPU.js} +1 -1
  43. package/vendor/cli.js +1 -1
  44. package/vendor/component-manifest-catalog.js +1 -1
  45. package/vendor/control-plane.js +6 -4
  46. package/vendor/chunk-7EGSY3E4.js +0 -8
  47. package/vendor/chunk-ZUDSZGVO.js +0 -11
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-T6UB5PNX.js";
5
5
  import {
6
6
  productionComponentManifestCatalog
7
- } from "./chunk-ZUDSZGVO.js";
7
+ } from "./chunk-YDZEMIAH.js";
8
8
  import {
9
9
  canonicalArtifactJson,
10
10
  extractVerifiedPackageArchive,
@@ -13,7 +13,7 @@ import {
13
13
  verifyComponent,
14
14
  verifyComponentManifestPin,
15
15
  verifyExtractedComponent
16
- } from "./chunk-ZIOKV2X6.js";
16
+ } from "./chunk-MFPPURFE.js";
17
17
  import {
18
18
  lookupManifestPin,
19
19
  validateManifestCatalog
@@ -28,6 +28,7 @@ import { dirname as dirname2, isAbsolute as isAbsolute3, parse as parse2, relati
28
28
  import { createHash } from "node:crypto";
29
29
  import { closeSync, constants, lstatSync, openSync, readFileSync, readlinkSync, readdirSync, realpathSync } from "node:fs";
30
30
  import { isAbsolute, relative, resolve, sep } from "node:path";
31
+ import process2 from "node:process";
31
32
  var issuedCapabilities = /* @__PURE__ */ new WeakSet();
32
33
  var hash = (bytes) => createHash("sha256").update(bytes).digest("hex");
33
34
  function validateDesktopRuntimeManifest(value) {
@@ -57,7 +58,41 @@ var regularFile = (path) => {
57
58
  closeSync(fd);
58
59
  }
59
60
  };
60
- function verifyDesktopRuntimeBundle(resourcesPath) {
61
+ var isWithin = (root, path) => {
62
+ const rel = relative(root, path);
63
+ return rel === "" || !!rel && !rel.startsWith(`..${sep}`) && rel !== ".." && !isAbsolute(rel);
64
+ };
65
+ function resolveDesktopInstallationPath(actualResources, environment = process2.env) {
66
+ const image = environment.APPIMAGE?.trim();
67
+ const mount = environment.APPDIR?.trim();
68
+ if (!image || !mount || !isAbsolute(image) || !isAbsolute(mount))
69
+ return actualResources;
70
+ let actualMount;
71
+ let actualImage;
72
+ try {
73
+ actualMount = realpathSync.native(mount);
74
+ actualImage = realpathSync.native(image);
75
+ } catch {
76
+ return actualResources;
77
+ }
78
+ if (!isWithin(actualMount, actualResources) || !lstatSync(actualImage).isFile())
79
+ return actualResources;
80
+ return actualImage;
81
+ }
82
+ function resolveDesktopInstallationResources(installationPath, environment = process2.env) {
83
+ if (!isAbsolute(installationPath))
84
+ throw new Error("Desktop installation path is invalid");
85
+ if (lstatSync(installationPath, { throwIfNoEntry: false })?.isDirectory())
86
+ return installationPath;
87
+ const mount = environment.APPDIR?.trim();
88
+ if (!mount || !isAbsolute(mount))
89
+ throw new Error("Desktop installation is not the running AppImage");
90
+ const resources = resolve(realpathSync.native(mount), "resources");
91
+ if (resolveDesktopInstallationPath(realpathSync.native(resources), environment) !== installationPath)
92
+ throw new Error("Desktop installation is not the running AppImage");
93
+ return resources;
94
+ }
95
+ function verifyDesktopRuntimeBundle(resourcesPath, environment = process2.env) {
61
96
  const actualResources = realpathSync.native(resolve(resourcesPath));
62
97
  const runtimeRoot = resolve(actualResources, "koed-runtime");
63
98
  const manifestPath = resolve(runtimeRoot, "desktop-bundle-manifest.json");
@@ -110,6 +145,7 @@ function verifyDesktopRuntimeBundle(resourcesPath) {
110
145
  });
111
146
  const capability = Object.freeze({
112
147
  resourcesPath: actualResources,
148
+ installationPath: resolveDesktopInstallationPath(actualResources, environment),
113
149
  productVersion: record.productVersion,
114
150
  bundleDigest: hash(canonicalArtifactJson(record)),
115
151
  manifest: verifiedManifest,
@@ -132,7 +168,7 @@ function resolveDesktopRuntimeOwner(capability, koedHome) {
132
168
  if (!validateDesktopRuntimeCapability(capability)) {
133
169
  throw new Error("validated private Desktop runtime capability is required");
134
170
  }
135
- return deriveDesktopRuntimeOwner(koedHome, capability.resourcesPath);
171
+ return deriveDesktopRuntimeOwner(koedHome, capability.installationPath);
136
172
  }
137
173
 
138
174
  // packages/koed-server/dist/component-store.js
@@ -292,7 +328,7 @@ var acquireDirectoryLock = (path) => {
292
328
  };
293
329
 
294
330
  // packages/koed-server/dist/component-runtime-identity.js
295
- import process2 from "node:process";
331
+ import process3 from "node:process";
296
332
  var isVersion = (value) => typeof value === "string" && /^(?:0|[1-9]\d*)(?:\.(?:0|[1-9]\d*)){1,2}$/.test(value) && value.split(".").every((part) => Number.isSafeInteger(Number(part)));
297
333
  function discoverRuntimeIdentityFromProcess(source) {
298
334
  const platform = source.platform === "darwin" ? "macos" : source.platform === "linux" ? "linux" : void 0;
@@ -323,7 +359,7 @@ function discoverRuntimeIdentityFromProcess(source) {
323
359
  };
324
360
  }
325
361
  function discoverActualRuntimeIdentity() {
326
- return discoverRuntimeIdentityFromProcess(process2);
362
+ return discoverRuntimeIdentityFromProcess(process3);
327
363
  }
328
364
 
329
365
  // packages/koed-server/dist/component-store.js
@@ -869,8 +905,8 @@ var readDesktopPrivacyGeneration = async (paths, id, record) => {
869
905
  ]) || record.schemaVersion !== 1 || record.kind !== "desktop-bundle-with-privacy" || record.id !== id || typeof record.productVersion !== "string" || typeof record.resourcesPath !== "string" || typeof record.bundleDigest !== "string" || !/^[a-f0-9]{64}$/.test(record.bundleDigest) || !isPlainRecord(record.privacy) || !exactKeys(record.privacy, ["root", "manifestDigest"]) || typeof record.privacy.root !== "string" || typeof record.privacy.manifestDigest !== "string")
870
906
  throw new Error("stored Desktop privacy generation record is invalid");
871
907
  validateOwner(record.owner);
872
- const bundle = verifyDesktopRuntimeBundle(record.resourcesPath);
873
- if (bundle.productVersion !== record.productVersion || bundle.bundleDigest !== record.bundleDigest)
908
+ const bundle = verifyDesktopRuntimeBundle(resolveDesktopInstallationResources(record.resourcesPath));
909
+ if (bundle.installationPath !== record.resourcesPath || bundle.productVersion !== record.productVersion || bundle.bundleDigest !== record.bundleDigest)
874
910
  throw new Error("Desktop runtime bundle changed after generation staging");
875
911
  const runtime = discoverActualRuntimeIdentity();
876
912
  const privacyRoot = resolve2(paths.koedHome, record.privacy.root);
@@ -888,7 +924,7 @@ var readDesktopPrivacyGeneration = async (paths, id, record) => {
888
924
  kind: "desktop-bundle-with-privacy",
889
925
  productVersion: bundle.productVersion,
890
926
  owner: record.owner,
891
- resourcesPath: bundle.resourcesPath,
927
+ resourcesPath: bundle.installationPath,
892
928
  bundleDigest: bundle.bundleDigest,
893
929
  privacy: {
894
930
  root: relative2(paths.koedHome, privacy.root),
@@ -1071,6 +1107,7 @@ import { closeSync as closeSync3, mkdirSync as mkdirSync3, openSync as openSync3
1071
1107
  import { spawnSync } from "node:child_process";
1072
1108
  import { hostname } from "node:os";
1073
1109
  import { resolve as resolve3 } from "node:path";
1110
+ var isSourceOwner = (value) => typeof value === "object" && value !== null && Object.keys(value).length === 2 && "kind" in value && value.kind === "standalone" && "installationId" in value && typeof value.installationId === "string" && /^[a-f0-9]{32}$/.test(value.installationId);
1074
1111
  var processIsRunning = (pid) => {
1075
1112
  if (!Number.isInteger(pid) || pid <= 0)
1076
1113
  return false;
@@ -1132,9 +1169,12 @@ var readSupervisorLock = (lockPath2) => {
1132
1169
  var parseSupervisorLock = (text) => {
1133
1170
  try {
1134
1171
  const value = JSON.parse(text);
1172
+ if (value.sourceOwner !== void 0 && !isSourceOwner(value.sourceOwner))
1173
+ return null;
1135
1174
  return Number.isInteger(value.pid) && Number(value.pid) > 0 ? {
1136
1175
  pid: Number(value.pid),
1137
1176
  acquiredAt: String(value.acquiredAt ?? "unknown"),
1177
+ ...value.sourceOwner ? { sourceOwner: { ...value.sourceOwner } } : {},
1138
1178
  ...typeof value.processIdentity === "string" && value.processIdentity.length > 0 ? { processIdentity: value.processIdentity } : {}
1139
1179
  } : null;
1140
1180
  } catch {
@@ -1143,6 +1183,8 @@ var parseSupervisorLock = (text) => {
1143
1183
  };
1144
1184
  var acquireKoedServerSupervisorLock = (paths, options = {}) => {
1145
1185
  const pid = options.pid ?? process.pid;
1186
+ if (options.sourceOwner !== void 0 && !isSourceOwner(options.sourceOwner))
1187
+ throw new Error("Source runtime owner must identify a standalone control plane.");
1146
1188
  const exclusive = options.exclusive ?? ((action) => action());
1147
1189
  const isRunning = options.isProcessRunning ?? processIsRunning;
1148
1190
  const identify = options.resolveProcessIdentity ?? resolveProcessIdentity;
@@ -1159,7 +1201,8 @@ var acquireKoedServerSupervisorLock = (paths, options = {}) => {
1159
1201
  writeFileSync2(descriptor, `${JSON.stringify({
1160
1202
  pid,
1161
1203
  acquiredAt: (options.now ?? (() => /* @__PURE__ */ new Date()))().toISOString(),
1162
- processIdentity
1204
+ processIdentity,
1205
+ ...options.sourceOwner ? { sourceOwner: options.sourceOwner } : {}
1163
1206
  }, null, 2)}
1164
1207
  `);
1165
1208
  } finally {
@@ -1497,6 +1540,21 @@ var readPinState = (paths) => {
1497
1540
  throw new Error("runtime generation state is invalid");
1498
1541
  return parsed;
1499
1542
  };
1543
+ var removeStaleGenerationPin = (paths) => {
1544
+ let pin;
1545
+ try {
1546
+ pin = readPinState(paths);
1547
+ } catch {
1548
+ return false;
1549
+ }
1550
+ if (!pin)
1551
+ return false;
1552
+ const identity = resolveProcessIdentity(pin.pid);
1553
+ if (identity === pin.processIdentity || !identity && processIsRunning2(pin.pid))
1554
+ return false;
1555
+ rmSync6(generationStatePath(paths), { force: true });
1556
+ return true;
1557
+ };
1500
1558
  var assertOwner = (generation, requester) => {
1501
1559
  if (!sameOwner(generation.owner, requester))
1502
1560
  throw new Error("runtime owner mismatch");
@@ -1546,7 +1604,8 @@ var persistDesktopBundleRecord = (paths, generation, capability) => {
1546
1604
  productVersion: generation.productVersion,
1547
1605
  owner: generation.owner,
1548
1606
  bundleDigest: capability.bundleDigest,
1549
- resourcesPath: capability.resourcesPath
1607
+ // Stable installation identity; see DesktopRuntimeCapability.
1608
+ resourcesPath: capability.installationPath
1550
1609
  };
1551
1610
  try {
1552
1611
  writeFileSync3(path, `${JSON.stringify(record)}
@@ -1569,7 +1628,7 @@ var readDesktopBundleGenerationById = async (paths, id, capability) => {
1569
1628
  if (generation.id !== id)
1570
1629
  throw new Error("runtime owner mismatch");
1571
1630
  const record = JSON.parse(readRegularFile(desktopBundleRecordPath(paths, id)));
1572
- if (!isRecord2(record) || record.schemaVersion !== 1 || record.kind !== "desktop-bundle" || record.id !== generation.id || record.productVersion !== generation.productVersion || record.bundleDigest !== capability.bundleDigest || record.resourcesPath !== capability.resourcesPath || !isRecord2(record.owner) || record.owner.kind !== generation.owner.kind || record.owner.installationId !== generation.owner.installationId)
1631
+ if (!isRecord2(record) || record.schemaVersion !== 1 || record.kind !== "desktop-bundle" || record.id !== generation.id || record.productVersion !== generation.productVersion || record.bundleDigest !== capability.bundleDigest || record.resourcesPath !== capability.installationPath || !isRecord2(record.owner) || record.owner.kind !== generation.owner.kind || record.owner.installationId !== generation.owner.installationId)
1573
1632
  throw new Error("private Desktop bundle generation record is invalid");
1574
1633
  return generation;
1575
1634
  };
@@ -1678,7 +1737,7 @@ function readCurrentDesktopGenerationOrderingEvidence(paths, capability) {
1678
1737
  if (!id)
1679
1738
  throw new Error("no active runtime generation");
1680
1739
  const evidence = readDesktopOrderingJournal(paths, id) ?? readGenerationOrderingEvidence(paths, id);
1681
- if (evidence.kind === "desktop-generation-ordering-evidence" && evidence.resourcesPath !== capability.resourcesPath)
1740
+ if (evidence.kind === "desktop-generation-ordering-evidence" && evidence.resourcesPath !== capability.installationPath)
1682
1741
  throw new Error("runtime owner mismatch");
1683
1742
  assertOwner(evidence, resolveDesktopRuntimeOwner(capability, paths.koedHome));
1684
1743
  return evidence;
@@ -1956,6 +2015,7 @@ export {
1956
2015
  removeStaleRuntimeRecords,
1957
2016
  assertDirectoryChain2 as assertDirectoryChain,
1958
2017
  withLifecycleLock,
2018
+ removeStaleGenerationPin,
1959
2019
  readCurrentGenerationOrderingEvidence,
1960
2020
  readCurrentGeneration,
1961
2021
  readDesktopGenerationForCapability,
@@ -1,10 +1,13 @@
1
1
  import { createRequire as createKoedRequire } from "node:module"; const require = createKoedRequire(import.meta.url);
2
+ import {
3
+ privateNodeLauncher
4
+ } from "./chunk-2YCDKSKW.js";
2
5
  import {
3
6
  collectLocalModelStatus
4
7
  } from "./chunk-JYK6UL6D.js";
5
8
  import {
6
9
  compareNativeVersions
7
- } from "./chunk-QRKHHWJJ.js";
10
+ } from "./chunk-H7ETSD25.js";
8
11
  import {
9
12
  external_exports
10
13
  } from "./chunk-FSNLU46W.js";
@@ -132,6 +135,28 @@ async function requestProbeEmbeddings(socket, inputs2, signal) {
132
135
  return JSON.parse(result.body);
133
136
  }
134
137
 
138
+ // packages/koed-server/dist/nvidia-smi.js
139
+ import { accessSync, constants, statSync } from "node:fs";
140
+ var candidates = [
141
+ "/usr/bin/nvidia-smi",
142
+ "/bin/nvidia-smi",
143
+ "/usr/local/bin/nvidia-smi",
144
+ "/usr/local/nvidia/bin/nvidia-smi",
145
+ "/usr/lib/wsl/lib/nvidia-smi"
146
+ ];
147
+ function resolveNvidiaSmi() {
148
+ for (const candidate of candidates) {
149
+ try {
150
+ if (!statSync(candidate).isFile())
151
+ continue;
152
+ accessSync(candidate, constants.X_OK);
153
+ return candidate;
154
+ } catch {
155
+ }
156
+ }
157
+ return null;
158
+ }
159
+
135
160
  // packages/koed-server/dist/runtime-release-validation.js
136
161
  var minimumDriver = "550.54.14";
137
162
  var minimumCosine = 0.999;
@@ -147,7 +172,7 @@ var NativeValidationError = class extends Error {
147
172
  this.reason = reason;
148
173
  }
149
174
  };
150
- async function checkCudaHost(signal) {
175
+ async function checkCudaHost(signal, nvidiaSmi = resolveNvidiaSmi()) {
151
176
  const context = {
152
177
  cwd: "/",
153
178
  env: { PATH: "/usr/bin:/bin", LANG: "C", LC_ALL: "C" },
@@ -155,7 +180,9 @@ async function checkCudaHost(signal) {
155
180
  };
156
181
  let driverVersion;
157
182
  try {
158
- const output = await nativeCommand("/usr/bin/nvidia-smi", ["--query-gpu=driver_version", "--format=csv,noheader"], context);
183
+ if (!nvidiaSmi)
184
+ throw new Error("NVIDIA driver tools are not available.");
185
+ const output = await nativeCommand(nvidiaSmi, ["--query-gpu=driver_version", "--format=csv,noheader"], context);
159
186
  const versions = new Set(output.split(/\r?\n/).map((row) => row.trim()));
160
187
  driverVersion = [...versions][0] ?? "";
161
188
  if (versions.size !== 1 || !/^\d{1,4}\.\d{1,4}(\.\d{1,4})?$/.test(driverVersion))
@@ -167,13 +194,24 @@ async function checkCudaHost(signal) {
167
194
  const [major, minor, patch = 0] = driverVersion.split(".").map(Number);
168
195
  if (compareNativeVersions(`${major}.${minor}.${patch}`, minimumDriver) < 0)
169
196
  throw new NativeValidationError("cuda_driver_too_old", `NVIDIA driver ${driverVersion} is older than required ${minimumDriver}.`);
170
- const loaded = await nativeCommand(process.execPath, [
171
- "-p",
172
- String.raw`process.report.getReport().sharedObjects.some(p => /\/libcuda\.so(?:\.\d+)*$/.test(p))`
173
- ], {
174
- ...context,
175
- env: { ...context.env, LD_PRELOAD: "libcuda.so.1" }
176
- });
197
+ const loaded = await nativeCommand(
198
+ // The probe environment is restricted, so use the private Node launcher.
199
+ privateNodeLauncher(),
200
+ [
201
+ "-p",
202
+ String.raw`process.report.getReport().sharedObjects.some(p => /\/libcuda\.so(?:\.\d+)*$/.test(p))`
203
+ ],
204
+ {
205
+ ...context,
206
+ // Desktop also calls this probe from Electron main. Its executable must
207
+ // run as Node, just as it does for the private server supervisor.
208
+ env: {
209
+ ...context.env,
210
+ ELECTRON_RUN_AS_NODE: "1",
211
+ LD_PRELOAD: "libcuda.so.1"
212
+ }
213
+ }
214
+ );
177
215
  if (loaded !== "true")
178
216
  throw new NativeValidationError("cuda_driver_library_unavailable", "The host loader could not load libcuda.so.1.");
179
217
  return driverVersion;
@@ -2,8 +2,8 @@ import { createRequire as createKoedRequire } from "node:module"; const require
2
2
  import {
3
3
  calculateRuntimeRequirements,
4
4
  resolveEffectiveRuntimeConfig
5
- } from "./chunk-SHLRINKO.js";
6
- import "./chunk-ALJUSOF7.js";
5
+ } from "./chunk-XSOQ2U5H.js";
6
+ import "./chunk-YY7NMZGD.js";
7
7
  import {
8
8
  resolveKoedServerPaths
9
9
  } from "./chunk-TSAYTRX3.js";
@@ -13,7 +13,7 @@ import {
13
13
  resolveKoedAppRuntimeExecution,
14
14
  resolveKoedControlPlaneVersion,
15
15
  resolveKoedRuntimeOwner
16
- } from "./chunk-V67IQB7H.js";
16
+ } from "./chunk-OG7G6DIR.js";
17
17
  import {
18
18
  activateGeneration,
19
19
  cleanupGenerations,
@@ -28,19 +28,19 @@ import {
28
28
  resolveComponentManifestPinTarget,
29
29
  stageComponent,
30
30
  stageGeneration
31
- } from "./chunk-FN3HUUO2.js";
31
+ } from "./chunk-I5XO5FL4.js";
32
32
  import "./chunk-T6UB5PNX.js";
33
33
  import "./chunk-7NXKPDF3.js";
34
34
  import {
35
35
  productionComponentManifestCatalog
36
- } from "./chunk-ZUDSZGVO.js";
37
- import "./chunk-ZIOKV2X6.js";
38
- import "./chunk-QRKHHWJJ.js";
39
- import "./chunk-7EGSY3E4.js";
36
+ } from "./chunk-YDZEMIAH.js";
37
+ import "./chunk-MFPPURFE.js";
38
+ import "./chunk-H7ETSD25.js";
39
+ import "./chunk-ULLAURFV.js";
40
40
  import {
41
41
  validateManifestCatalog
42
42
  } from "./chunk-IY2HRXOZ.js";
43
- import "./chunk-ZOHNXUDY.js";
43
+ import "./chunk-VWB3VEOL.js";
44
44
  import "./chunk-FSNLU46W.js";
45
45
  import "./chunk-BTS4ZTF3.js";
46
46
 
@@ -3,7 +3,7 @@ import {
3
3
  aiClientConnectionRevision,
4
4
  grantAiClientConnection,
5
5
  revokeAiClientConnection
6
- } from "./chunk-EDPNYIX5.js";
6
+ } from "./chunk-XTQYFCVY.js";
7
7
 
8
8
  // packages/koed-server/dist/ai-client-authorization.js
9
9
  var clientNames = {
@@ -1,10 +1,11 @@
1
1
  import { createRequire as createKoedRequire } from "node:module"; const require = createKoedRequire(import.meta.url);
2
2
  import {
3
3
  runApplicationSecretProvider
4
- } from "./chunk-EA4QDDQA.js";
4
+ } from "./chunk-GEIN6UIL.js";
5
+ import "./chunk-2YCDKSKW.js";
5
6
  import "./chunk-TSAYTRX3.js";
6
7
  import "./chunk-YZLQZU5E.js";
7
- import "./chunk-ZOHNXUDY.js";
8
+ import "./chunk-VWB3VEOL.js";
8
9
  import "./chunk-FSNLU46W.js";
9
10
  import "./chunk-BTS4ZTF3.js";
10
11
 
@@ -1,14 +1,14 @@
1
1
  import { createRequire as createKoedRequire } from "node:module"; const require = createKoedRequire(import.meta.url);
2
2
  import {
3
3
  nativeKind
4
- } from "./chunk-QRKHHWJJ.js";
4
+ } from "./chunk-H7ETSD25.js";
5
5
  import {
6
6
  lookupManifestPin
7
7
  } from "./chunk-IY2HRXOZ.js";
8
8
 
9
9
  // packages/koed-server/dist/native-payload-admission.js
10
10
  import { createHash as createHash2 } from "node:crypto";
11
- import { closeSync as closeSync2, constants as constants2, fstatSync as fstatSync2, fsyncSync, lstatSync as lstatSync2, openSync as openSync2, readFileSync, readdirSync as readdirSync2, readlinkSync, realpathSync } from "node:fs";
11
+ import { closeSync as closeSync2, constants as constants2, fstatSync as fstatSync2, fsyncSync, lstatSync as lstatSync2, openSync as openSync2, readFileSync, readSync as readSync2, readdirSync as readdirSync2, readlinkSync, realpathSync } from "node:fs";
12
12
  import { dirname, isAbsolute as isAbsolute2, relative as relative2, resolve as resolve2 } from "node:path";
13
13
 
14
14
  // packages/koed-server/dist/artifact-canonical-json.mjs
@@ -227,10 +227,10 @@ function verifyCompatibility(manifest, input) {
227
227
  throw new Error("runtime identity is invalid");
228
228
  const versionMatches = manifest.runtimes.filter((item) => item.kind === input.runtime.kind && satisfies(input.runtime.version, item.runtimeRange) && satisfies(input.runtime.nodeVersion, item.nodeRange));
229
229
  if (!versionMatches.length)
230
- throw new Error("runtime version is incompatible");
230
+ throw new Error("runtime version is incompatible; reinstall components from a release supporting this runtime");
231
231
  const abiMatches = versionMatches.filter((item) => item.modulesAbi === void 0 || item.modulesAbi === input.runtime.modulesAbi);
232
232
  if (!abiMatches.length)
233
- throw new Error("runtime ABI mismatch");
233
+ throw new Error("runtime ABI mismatch; reinstall components from a release supporting this runtime");
234
234
  const compatibility = abiMatches.find((item) => item.minimumNapi === void 0 || input.runtime.napiVersion >= item.minimumNapi);
235
235
  if (!compatibility)
236
236
  throw new Error("runtime N-API version is incompatible");
@@ -544,6 +544,52 @@ function verifyExtractedComponentSync(root, manifest, seams = {}) {
544
544
  }
545
545
  var verifyExtractedComponent = (root, manifest) => Promise.resolve().then(() => verifyExtractedComponentSync(root, manifest));
546
546
 
547
+ // packages/koed-server/dist/native-macos-policy.js
548
+ var executables = new Set(`clusterdb createdb createuser dropdb dropuser ecpg initdb oid2name pg_amcheck pg_archivecleanup pg_basebackup pg_checksums pg_combinebackup pg_config pg_controldata pg_createsubscriber pg_ctl pg_dump pg_dumpall pg_isready pg_receivewal pg_recvlogical pg_resetwal pg_restore pg_rewind pg_test_fsync pg_test_timing pg_upgrade pg_verifybackup pg_waldump pg_walsummary pgbench postgres postmaster psql reindexdb vacuumdb vacuumlo`.split(" "));
549
+ var shareFiles = new Set(`errcodes.txt information_schema.sql pg_hba.conf.sample pg_ident.conf.sample pg_service.conf.sample postgres.bki postgresql.conf.sample psqlrc.sample snowball_create.sql sql_features.txt system_constraints.sql system_functions.sql system_views.sql`.split(" "));
550
+ function permitsMacFilePath(path) {
551
+ if ([
552
+ "native-core-manifest.json",
553
+ "runtime-asset-manifest.json",
554
+ "llama.cpp/llama-server"
555
+ ].includes(path))
556
+ return true;
557
+ if (path.startsWith("postgres/bin/"))
558
+ return executables.has(path.slice("postgres/bin/".length));
559
+ if (path.startsWith("postgres/lib/"))
560
+ return /\.(?:so|dylib)$/i.test(path) || /^postgres\/lib\/(?:postgresql\/)?pkgconfig\/[\w.-]+\.pc$/.test(path) || /^postgres\/lib\/(?:postgresql\/)?pgxs\/config\/(?:install-sh|missing)$/.test(path);
561
+ if (path.startsWith("llama.cpp/metal/"))
562
+ return /^llama\.cpp\/metal\/(?:llama-server|LICENSE|ggml-metal\.metal|[\w.+-]+\.dylib)$/.test(path);
563
+ if (path.startsWith("third-party-licenses/"))
564
+ return /(?:^|\/|__)(?:LICEN[CS]E|NOTICE|COPYING|COPYRIGHT)(?:[._-][\w.-]+)?$/i.test(path);
565
+ if (!path.startsWith("postgres/share/"))
566
+ return false;
567
+ const shared = path.slice("postgres/share/".length).replace(/^postgresql\//, "");
568
+ return shareFiles.has(shared) || /^extension\/[\w.-]+\.(?:sql|control)$/.test(shared) || /^timezone\/[\w.+/-]+$/.test(shared) || /^timezonesets\/(?:Africa|America|Antarctica|Asia|Atlantic|Australia|Default|Etc|Europe|India|Indian|Pacific)(?:\.txt)?$/.test(shared) || /^tsearch_data\/[\w.-]+\.(?:stop|affix|dict|ths|syn|rules)$/.test(shared) || /^man\/man[1-9]\/[\w.+-]+\.[1-9](?:\.gz)?$/.test(shared) || /^locale\/[\w@.-]+\/LC_MESSAGES\/[\w.+-]+\.mo$/.test(shared) || /^doc\/[\w./+-]+\.(?:html|css|png|svg|txt|pdf|example)$/.test(shared);
569
+ }
570
+ function validateMacFile(path, header, mode) {
571
+ const magic = header.subarray(0, 4).toString("hex");
572
+ const arm64 = header.length >= 16 && magic === "cffaedfe" && header.readUInt32LE(4) === 16777228;
573
+ const library = /\.(?:so|dylib)$/i.test(path);
574
+ const validType = arm64 && (library ? [6, 8].includes(header.readUInt32LE(12)) : header.readUInt32LE(12) === 2);
575
+ const binaryPath = path.startsWith("postgres/bin/") && executables.has(path.slice(13)) || path.startsWith("postgres/lib/") && library || path.startsWith("llama.cpp/metal/") && (path === "llama.cpp/metal/llama-server" || /\.dylib$/i.test(path));
576
+ const macho = [
577
+ "cffaedfe",
578
+ "feedfacf",
579
+ "cafebabe",
580
+ "bebafeca",
581
+ "cafebabf",
582
+ "bfbafeca",
583
+ "cefaedfe",
584
+ "feedface"
585
+ ].includes(magic);
586
+ const foreign = magic === "7f454c46" || header.subarray(0, 2).toString() === "MZ" || /\.(?:exe|dll|so\.\d+(?:\.\d+)*)$/i.test(path) || /(?:^|\/)libcu(?:da|blas|dart)/i.test(path);
587
+ const script = (path === "llama.cpp/llama-server" || /^postgres\/lib\/(?:postgresql\/)?pgxs\/config\/(?:install-sh|missing)$/.test(path)) && header.subarray(0, 2).toString() === "#!";
588
+ const timezone = /^postgres\/share\/(?:postgresql\/)?timezone\//.test(path);
589
+ if (!permitsMacFilePath(path) || timezone && magic !== "545a6966" || foreign || macho && (!validType || !binaryPath) || library && !validType || path.startsWith("postgres/bin/") && !validType || (mode & 73) !== 0 && !arm64 && !script)
590
+ throw new Error(`Invalid macOS native file or executable: ${path}`);
591
+ }
592
+
547
593
  // packages/koed-server/dist/native-payload-admission.js
548
594
  var nativeDigest = (value) => createHash2("sha256").update(value).digest("hex");
549
595
  function nativeJsonObject(bytes) {
@@ -585,11 +631,26 @@ function nativeFileDigest(path, bytes, durable = false) {
585
631
  closeSync2(fd);
586
632
  }
587
633
  }
588
- function permitsNativeEntry(kind, path, directory) {
634
+ function checkMacFile(file, path, mode) {
635
+ const fd = openSync2(file, constants2.O_RDONLY | constants2.O_NOFOLLOW | constants2.O_NONBLOCK);
636
+ try {
637
+ const header = Buffer.alloc(16);
638
+ const length = readSync2(fd, header, 0, header.length, 0);
639
+ validateMacFile(path, header.subarray(0, length), mode);
640
+ } finally {
641
+ closeSync2(fd);
642
+ }
643
+ }
644
+ function permitsNativeEntry(kind, path, directory, platform = "linux") {
589
645
  if (path === "")
590
646
  return directory;
591
- if (kind === "core")
592
- return path !== "llama.cpp/cuda" && !path.startsWith("llama.cpp/cuda/");
647
+ if (kind === "core") {
648
+ if (platform === "linux")
649
+ return !["cuda", "metal"].some((backend) => path === `llama.cpp/${backend}` || path.startsWith(`llama.cpp/${backend}/`));
650
+ if (!directory)
651
+ return permitsMacFilePath(path);
652
+ return path === "postgres" || path.startsWith("postgres/") || path === "llama.cpp" || path === "llama.cpp/metal" || path === "third-party-licenses" || path.startsWith("third-party-licenses/");
653
+ }
593
654
  if (path === "llama.cpp" || path === "llama.cpp/cuda")
594
655
  return directory;
595
656
  return path.startsWith("llama.cpp/cuda/") && !/(?:^|\/)libcuda\.so(?:\.\d+)*$/.test(path);
@@ -616,18 +677,43 @@ function verifyNativePayload(root, pin, durable = false) {
616
677
  throw new Error(`Native ${kind} inventory changed at ${entry.path}. Inspect the damaged payload before repair.`);
617
678
  };
618
679
  let expanded = raw.length;
680
+ const required = /* @__PURE__ */ new Set([
681
+ "postgres/bin/postgres",
682
+ "postgres/bin/initdb",
683
+ "postgres/bin/pg_ctl",
684
+ "postgres/bin/psql",
685
+ "postgres/bin/pg_dump",
686
+ "postgres/bin/pg_restore",
687
+ "postgres/lib/vector.so",
688
+ "postgres/lib/pgcrypto.so",
689
+ "llama.cpp/llama-server",
690
+ "llama.cpp/metal/llama-server"
691
+ ]);
619
692
  const walk = (directory) => {
693
+ let files = 0;
620
694
  for (const entry of readdirSync2(directory).sort()) {
621
695
  const path = resolve2(directory, entry), key = relative2(root, path);
622
696
  if (key === name)
623
697
  continue;
624
698
  const stat = lstatSync2(path), mode = stat.mode & 4095;
625
- if (!permitsNativeEntry(kind, key, stat.isDirectory()))
699
+ if (pin.target.platform === "macos" && (mode & 3584) !== 0)
700
+ throw new Error(`Invalid macOS native special permission bits: ${key}`);
701
+ if (!permitsNativeEntry(kind, key, stat.isDirectory(), pin.target.platform))
626
702
  throw new Error(`Unexpected native ${kind} entry: ${key}`);
627
703
  if (stat.isDirectory()) {
704
+ if (pin.target.platform === "macos" && mode !== 493)
705
+ throw new Error(`Invalid macOS native directory mode: ${key}`);
628
706
  check({ path: key, type: "directory", mode });
629
- walk(path);
707
+ const descendants = walk(path);
708
+ if (pin.target.platform === "macos" && descendants === 0)
709
+ throw new Error(`Unexpected native ${kind} empty directory: ${key}`);
710
+ files += descendants;
630
711
  } else if (stat.isFile()) {
712
+ files++;
713
+ if (required.has(key) && (!(key.startsWith("postgres/bin/") || key.endsWith("llama-server")) || (mode & 73) !== 0))
714
+ required.delete(key);
715
+ if (pin.target.platform === "macos")
716
+ checkMacFile(path, key, mode);
631
717
  expanded += stat.size;
632
718
  if (expanded > pin.expandedBytes)
633
719
  throw new Error("Native inventory exceeds its pinned size.");
@@ -643,16 +729,22 @@ function verifyNativePayload(root, pin, durable = false) {
643
729
  const rel = relative2(boundary, dest);
644
730
  if (isAbsolute2(target) || rel.startsWith("../") || rel === ".." || !lstatSync2(dest).isFile() || realpathSync(path) !== resolve2(realpathSync(root), relative2(root, dest)))
645
731
  throw new Error(`Unsafe native library link: ${key}`);
732
+ if (pin.target.platform === "macos")
733
+ checkMacFile(dest, key, lstatSync2(dest).mode & 511);
734
+ files++;
646
735
  check({ path: key, type: "symlink", mode: 511, target });
647
736
  } else
648
737
  throw new Error(`Unsupported native file: ${key}`);
649
738
  }
650
739
  if (durable)
651
740
  syncNativeDirectory(directory);
741
+ return files;
652
742
  };
653
743
  if (durable)
654
744
  nativeFileDigest(file, raw.length, true);
655
745
  walk(root);
746
+ if (pin.target.platform === "macos" && kind === "core" && required.size)
747
+ throw new Error(`Native macOS core is missing required executable or library: ${[...required][0]}`);
656
748
  if (expanded !== pin.expandedBytes || index !== inventory.length)
657
749
  throw new Error(`Native ${kind} inventory changed. Inspect the installed payload before repair.`);
658
750
  }
@@ -685,10 +777,10 @@ var requiredPackageRuntimeFiles = [
685
777
  "mcp-server/dist/cli.js",
686
778
  "mcp-server/dist/capture-hook.js",
687
779
  "mcp-server/dist/prompts/codex-global-agent-guidance.md",
688
- "node_modules/@koed/db/dist/index.js",
689
- "node_modules/@koed/db/dist/connection.js",
690
- "node_modules/@koed/db/dist/user-api-token-repository.js",
691
- "node_modules/@koed/db/drizzle/meta/_journal.json"
780
+ "node_modules/@koed-labs/db/dist/index.js",
781
+ "node_modules/@koed-labs/db/dist/connection.js",
782
+ "node_modules/@koed-labs/db/dist/user-api-token-repository.js",
783
+ "node_modules/@koed-labs/db/drizzle/meta/_journal.json"
692
784
  ];
693
785
  var excludedPackagePatterns = [
694
786
  /^koed-runtime\/explorer-dist(?:\/|$)/,
@@ -704,14 +796,6 @@ var excludedPackagePatterns = [
704
796
  /^koed-runtime\/embedding-service\/requirements\.txt$/,
705
797
  /^koed-runtime\/embedding-service\/pyproject\.toml$/
706
798
  ];
707
- var pnpmWorkspaceSelfSymlinkPattern = /^(?<root>koed-server|koed-runtime\/api|koed-runtime\/worker|koed-runtime\/embedding-service|koed-runtime\/mcp-server)\/node_modules\/\.pnpm\/node_modules\/@koed\/(?<name>[^/]+)$/;
708
- var packageSelfNames = {
709
- "koed-server": "koed-server",
710
- "koed-runtime/api": "api",
711
- "koed-runtime/worker": "worker",
712
- "koed-runtime/embedding-service": "embedding-service",
713
- "koed-runtime/mcp-server": "mcp-server"
714
- };
715
799
  var platformKey = (platform = process.platform) => {
716
800
  if (platform === "darwin")
717
801
  return "macos";
@@ -753,18 +837,9 @@ var packageRoot = (paths) => resolve3(paths.koedHome, "runtime", "koed-server");
753
837
  var packageVersionsDir = (paths) => resolve3(packageRoot(paths), "versions");
754
838
  var packageCacheDir = (paths) => resolve3(paths.cacheDir, "koed-server-packages");
755
839
  var packageCurrentPath = (paths) => resolve3(packageRoot(paths), "current");
756
- var isPnpmWorkspaceSelfSymlink = (path) => {
757
- const match = path.match(pnpmWorkspaceSelfSymlinkPattern);
758
- if (!match?.groups)
759
- return false;
760
- const { name, root } = match.groups;
761
- return Boolean(root && name && name === packageSelfNames[root]);
762
- };
763
840
  var listFiles = (root, dir = root) => readdirSync3(dir, { withFileTypes: true }).flatMap((entry) => {
764
841
  const path = resolve3(dir, entry.name);
765
842
  const relativePath = relative3(root, path).replaceAll("\\", "/");
766
- if (isPnpmWorkspaceSelfSymlink(relativePath))
767
- return [];
768
843
  if (entry.isDirectory())
769
844
  return listFiles(root, path);
770
845
  return [relativePath];
@@ -1332,7 +1407,7 @@ var extractTarGz = async (archivePath, destination, native) => {
1332
1407
  const entryMode = tarNumber2(header, 100, 8);
1333
1408
  if (native) {
1334
1409
  const path = rawPath.replace(/\/$/, "");
1335
- if (!(path === "koed-runtime" || path.startsWith("koed-runtime/")) || !permitsNativeEntry(native.kind, path.slice("koed-runtime/".length), type === "5") || path.split("/").some((part) => !part || part === "." || part === "..") || path.includes("\\") || (entryMode & ~511) !== 0)
1410
+ if (!(path === "koed-runtime" || path.startsWith("koed-runtime/")) || !permitsNativeEntry(native.kind, path.slice("koed-runtime/".length), type === "5", native.platform) || path.split("/").some((part) => !part || part === "." || part === "..") || path.includes("\\") || (entryMode & ~511) !== 0)
1336
1411
  throw new Error("Unsafe native archive path or mode.");
1337
1412
  if (type === "0")
1338
1413
  regularBytes += size;
@@ -1404,9 +1479,14 @@ var extractTarGz = async (archivePath, destination, native) => {
1404
1479
  symlinkSync(link, path);
1405
1480
  }
1406
1481
  };
1407
- var extractNativeArchive = (kind, archive, destination, expandedBytes, signal) => {
1482
+ var extractNativeArchive = (kind, archive, destination, expandedBytes, signal, platform = "linux") => {
1408
1483
  mkdirSync(destination, { mode: 448 });
1409
- return extractTarGz(archive, destination, { kind, expandedBytes, signal });
1484
+ return extractTarGz(archive, destination, {
1485
+ kind,
1486
+ expandedBytes,
1487
+ signal,
1488
+ platform
1489
+ });
1410
1490
  };
1411
1491
  var findExtractedPackageRoot = (extractDir) => {
1412
1492
  const entries = readdirSync3(extractDir, { withFileTypes: true }).filter((entry) => entry.isDirectory());
@@ -16,9 +16,9 @@ import {
16
16
  standalonePackageKind,
17
17
  standalonePackageSchemaVersion,
18
18
  validateServerPackageRoot
19
- } from "./chunk-ZIOKV2X6.js";
20
- import "./chunk-QRKHHWJJ.js";
21
- import "./chunk-7EGSY3E4.js";
19
+ } from "./chunk-MFPPURFE.js";
20
+ import "./chunk-H7ETSD25.js";
21
+ import "./chunk-ULLAURFV.js";
22
22
  import "./chunk-IY2HRXOZ.js";
23
23
  import "./chunk-FSNLU46W.js";
24
24
  import "./chunk-BTS4ZTF3.js";