@koed-labs/server 0.11.1 → 1.0.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 (45) 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-VGIYSDNU.js → chunk-273NMYXE.js} +115 -32
  5. package/vendor/{chunk-4OO6VAU3.js → chunk-4DHYSJJT.js} +1 -1
  6. package/vendor/{chunk-WDFERJG3.js → chunk-54UL4U2E.js} +42 -23
  7. package/vendor/{chunk-W2OJZZ6X.js → chunk-64AST7WZ.js} +2 -2
  8. package/vendor/{chunk-ZIOKV2X6.js → chunk-7HLNJ2BI.js} +113 -33
  9. package/vendor/{chunk-2XKSVKQA.js → chunk-AOZ3LMTF.js} +2 -2
  10. package/vendor/{chunk-C5SNDPAP.js → chunk-BYN6KXNP.js} +4 -4
  11. package/vendor/{chunk-Z5WCAUA6.js → chunk-DWWMBGHX.js} +16 -16
  12. package/vendor/{chunk-ZOHNXUDY.js → chunk-E6YVGIEW.js} +25 -8
  13. package/vendor/{chunk-NVTMIAAF.js → chunk-EEBIYWTE.js} +16 -16
  14. package/vendor/{chunk-GFASBPV2.js → chunk-F77ZTTNS.js} +3 -3
  15. package/vendor/{chunk-TG26CZGQ.js → chunk-F7AMEDDU.js} +4 -4
  16. package/vendor/{chunk-EA4QDDQA.js → chunk-GY5GATZL.js} +1 -1
  17. package/vendor/{chunk-HC76426R.js → chunk-ILQVLZ2I.js} +7 -5
  18. package/vendor/{chunk-6KS67EQE.js → chunk-KG3RANR4.js} +1 -1
  19. package/vendor/{chunk-OCILJ737.js → chunk-KRBZZ6GS.js} +8 -8
  20. package/vendor/{chunk-SHLRINKO.js → chunk-L4RD3TAZ.js} +1 -1
  21. package/vendor/{chunk-SRKIBFOE.js → chunk-LHUMBHG7.js} +1 -1
  22. package/vendor/{chunk-CHMH4LH5.js → chunk-NGV45YWB.js} +3 -3
  23. package/vendor/{chunk-V67IQB7H.js → chunk-OG7G6DIR.js} +1 -1
  24. package/vendor/{chunk-NOU7RHYZ.js → chunk-OZU6JFB4.js} +4 -4
  25. package/vendor/chunk-QV3WPU7A.js +8 -0
  26. package/vendor/{chunk-BUIM2M4R.js → chunk-S6HD3MDU.js} +2 -2
  27. package/vendor/{chunk-SNKWETM5.js → chunk-SQZ2OSP6.js} +2 -2
  28. package/vendor/{chunk-WPIEF4LY.js → chunk-T7OGE5E5.js} +3 -3
  29. package/vendor/{chunk-FYYRFX4U.js → chunk-TIBYKMRW.js} +74 -38
  30. package/vendor/{chunk-FN3HUUO2.js → chunk-UCOHFZ77.js} +73 -13
  31. package/vendor/{chunk-LRP66XEY.js → chunk-UIMUUIH7.js} +13 -13
  32. package/vendor/{chunk-EDPNYIX5.js → chunk-USHFSJT7.js} +141 -86
  33. package/vendor/{chunk-QRKHHWJJ.js → chunk-VGL5AZN5.js} +51 -3
  34. package/vendor/{chunk-PL3LWC5C.js → chunk-VLP72QWX.js} +1 -1
  35. package/vendor/{chunk-O7DW2VAV.js → chunk-W6632NOX.js} +3 -3
  36. package/vendor/{chunk-RCR4XPE3.js → chunk-WBMO7YCO.js} +1 -1
  37. package/vendor/chunk-XCO3RV3Z.js +11 -0
  38. package/vendor/{chunk-TVYEB2GN.js → chunk-XKXSC6YS.js} +34 -4
  39. package/vendor/{chunk-C4V72GXC.js → chunk-Y6GE52OP.js} +17 -17
  40. package/vendor/{chunk-BGENSONI.js → chunk-ZKKWLLPU.js} +1 -1
  41. package/vendor/cli.js +1 -1
  42. package/vendor/component-manifest-catalog.js +1 -1
  43. package/vendor/control-plane.js +4 -4
  44. package/vendor/chunk-7EGSY3E4.js +0 -8
  45. package/vendor/chunk-ZUDSZGVO.js +0 -11
package/README.md CHANGED
@@ -9,7 +9,7 @@ Looking for the desktop client? Visit the [Koed GitHub repository](https://githu
9
9
  For a local Personal setup, install Node.js 24 and Homebrew first. Then install the Koed command-line tool:
10
10
 
11
11
  ```sh
12
- npm install --global @koed-labs/server@0.11.1
12
+ npm install --global @koed-labs/server@1.0.0
13
13
  ```
14
14
 
15
15
  ## 2. Set up your services
@@ -19,13 +19,13 @@ Install the Base component for your platform using the matching release URLs:
19
19
  **linux-x64**
20
20
 
21
21
  ```sh
22
- koed components install --component base --archive-url https://github.com/koed-labs/koed/releases/download/v0.11.1/koed-base-0.11.1-linux-x64.tar.gz --manifest-url https://github.com/koed-labs/koed/releases/download/v0.11.1/koed-base-0.11.1-linux-x64.tar.gz.manifest.json --json
22
+ koed components install --component base --archive-url https://github.com/koed-labs/koed/releases/download/v1.0.0/koed-base-1.0.0-linux-x64.tar.gz --manifest-url https://github.com/koed-labs/koed/releases/download/v1.0.0/koed-base-1.0.0-linux-x64.tar.gz.manifest.json --json
23
23
  ```
24
24
 
25
25
  **macos-arm64**
26
26
 
27
27
  ```sh
28
- koed components install --component base --archive-url https://github.com/koed-labs/koed/releases/download/v0.11.1/koed-base-0.11.1-macos-arm64.tar.gz --manifest-url https://github.com/koed-labs/koed/releases/download/v0.11.1/koed-base-0.11.1-macos-arm64.tar.gz.manifest.json --json
28
+ koed components install --component base --archive-url https://github.com/koed-labs/koed/releases/download/v1.0.0/koed-base-1.0.0-macos-arm64.tar.gz --manifest-url https://github.com/koed-labs/koed/releases/download/v1.0.0/koed-base-1.0.0-macos-arm64.tar.gz.manifest.json --json
29
29
  ```
30
30
 
31
31
  Then install the runtime and embedding model:
package/bin/koed.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- if (Number(process.versions.node.split(".")[0]) !== 24) { console.error(`@koed-labs/server requires Node.js >=24 <25; found ${process.versions.node}.`); process.exit(1); }
2
+ if (Number(process.versions.node.split(".")[0]) < 24 || Number(process.versions.node.split(".")[0]) >= 27) { console.error(`@koed-labs/server requires Node.js >=24 <27; found ${process.versions.node}.`); process.exit(1); }
3
3
  const { runKoedServerCli, shouldExitPackagedSupervisor } = await import("../vendor/control-plane.js");
4
4
  const args = process.argv.slice(2);
5
5
  const exitCode = await runKoedServerCli(args);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koed-labs/server",
3
- "version": "0.11.1",
3
+ "version": "1.0.0",
4
4
  "description": "Koed Self-Hosted control plane",
5
5
  "repository": {
6
6
  "type": "git",
@@ -13,7 +13,7 @@
13
13
  "koed": "bin/koed.js"
14
14
  },
15
15
  "engines": {
16
- "node": ">=24 <25"
16
+ "node": ">=24 <27"
17
17
  },
18
18
  "publishConfig": {
19
19
  "access": "public"
@@ -3,23 +3,24 @@ import {
3
3
  checkCudaHost,
4
4
  nativeCommand,
5
5
  validateStagedCuda
6
- } from "./chunk-TVYEB2GN.js";
6
+ } from "./chunk-XKXSC6YS.js";
7
7
  import "./chunk-JYK6UL6D.js";
8
8
  import {
9
9
  resolveKoedServerConfig
10
10
  } from "./chunk-ALJUSOF7.js";
11
11
  import {
12
12
  resolveKoedRuntimeOwner
13
- } from "./chunk-V67IQB7H.js";
13
+ } from "./chunk-OG7G6DIR.js";
14
14
  import {
15
15
  assertDirectoryChain,
16
16
  fetchBounded,
17
17
  renameAtomically,
18
+ resolveDesktopRuntimeOwner,
18
19
  withStoppedRuntime
19
- } from "./chunk-FN3HUUO2.js";
20
+ } from "./chunk-UCOHFZ77.js";
20
21
  import "./chunk-T6UB5PNX.js";
21
22
  import "./chunk-7NXKPDF3.js";
22
- import "./chunk-ZUDSZGVO.js";
23
+ import "./chunk-XCO3RV3Z.js";
23
24
  import {
24
25
  canonicalArtifactJson,
25
26
  extractNativeArchive,
@@ -29,15 +30,16 @@ import {
29
30
  readNativeMetadata,
30
31
  syncNativeDirectory,
31
32
  verifyNativePayload
32
- } from "./chunk-ZIOKV2X6.js";
33
+ } from "./chunk-7HLNJ2BI.js";
33
34
  import {
34
35
  compareNativeVersions,
35
36
  compatibleCuda,
36
37
  getNativeRuntimeCatalog,
37
38
  nativeKind,
39
+ selectNativeRuntimeCatalog,
38
40
  validateNativeRuntimeCatalog
39
- } from "./chunk-QRKHHWJJ.js";
40
- import "./chunk-7EGSY3E4.js";
41
+ } from "./chunk-VGL5AZN5.js";
42
+ import "./chunk-QV3WPU7A.js";
41
43
  import "./chunk-IY2HRXOZ.js";
42
44
  import "./chunk-FSNLU46W.js";
43
45
  import "./chunk-BTS4ZTF3.js";
@@ -46,6 +48,7 @@ import "./chunk-BTS4ZTF3.js";
46
48
  import { randomUUID as randomUUID2 } from "node:crypto";
47
49
  import { mkdirSync as mkdirSync2, mkdtempSync, renameSync as renameSync2, rmSync as rmSync2, statfsSync, writeFileSync as writeFileSync2, lstatSync as lstatSync2, readlinkSync as readlinkSync2 } from "node:fs";
48
50
  import { dirname as dirname2, resolve as resolve3 } from "node:path";
51
+ import { release as kernelRelease } from "node:os";
49
52
 
50
53
  // packages/koed-server/dist/native-selection.js
51
54
  import { lstatSync, mkdirSync, readlinkSync, readdirSync, rmSync, renameSync, symlinkSync, writeFileSync } from "node:fs";
@@ -55,9 +58,9 @@ var releaseInstallCommand = "koed runtime install --provider release --dependenc
55
58
  var nativeStore = (paths) => resolve(paths.koedHome, "runtime/native");
56
59
  var nativePathExists = (path) => lstatSync(path, { throwIfNoEntry: false }) !== void 0;
57
60
  var payloadRoot = (paths, pin) => resolve(nativeStore(paths), nativeKind(pin), pin.recipeId);
58
- var coreLinks = [
61
+ var coreLinks = (pin) => [
59
62
  "postgres",
60
- "llama.cpp/cpu",
63
+ `llama.cpp/${pin.target.platform === "macos" ? "metal" : "cpu"}`,
61
64
  "llama.cpp/llama-server"
62
65
  ];
63
66
  var entryNames = ["postgres", "llama.cpp"];
@@ -119,19 +122,28 @@ function loadSelection(paths, id, catalog) {
119
122
  if (nativeDigest(raw) !== id)
120
123
  throw new Error("Native selection metadata changed.");
121
124
  const record = nativeJsonObject(raw);
122
- const { core: pin, cuda } = validateNativeRuntimeCatalog({
125
+ const core = record.core;
126
+ if (typeof core === "object" && core !== null && "target" in core && typeof core.target === "object" && core.target !== null && "platform" in core.target && (core.target.platform === "linux" || core.target.platform === "macos") && core.target.platform !== catalog.core.target.platform)
127
+ throw new NativeSelectionTargetError();
128
+ const receipt = {
123
129
  schemaVersion: 1,
124
130
  minimumCoreVersion: "0.0.0",
125
131
  core: record.core,
126
132
  cuda: record.cuda
127
- });
133
+ };
134
+ let pin, cuda;
135
+ try {
136
+ ({ core: pin, cuda } = catalog.core.target.platform === "linux" ? validateNativeRuntimeCatalog(receipt) : selectNativeRuntimeCatalog({ schemaVersion: 2, linux: null, macos: receipt }, "darwin", "arm64"));
137
+ } catch (cause) {
138
+ throw new Error("Native selection target or receipt is incompatible with the reviewed host catalog.", { cause });
139
+ }
128
140
  if (canonicalArtifactJson(document(pin, cuda)) !== raw.toString("utf8") || cuda && conflictsWithPin(cuda, catalog.cuda) || conflictsWithPin(pin, catalog.core))
129
141
  throw new Error("Native selection conflicts with the reviewed identity.");
130
- if (canonicalArtifactJson(readdirSync(root).sort()) !== canonicalArtifactJson(["llama.cpp", "postgres", "selection.json"]) || canonicalArtifactJson(readdirSync(resolve(root, "llama.cpp")).sort()) !== canonicalArtifactJson(cuda ? ["cpu", "cuda", "llama-server"] : ["cpu", "llama-server"]))
142
+ if (canonicalArtifactJson(readdirSync(root).sort()) !== canonicalArtifactJson(["llama.cpp", "postgres", "selection.json"]) || canonicalArtifactJson(readdirSync(resolve(root, "llama.cpp")).sort()) !== canonicalArtifactJson(pin.target.platform === "macos" ? ["llama-server", "metal"] : cuda ? ["cpu", "cuda", "llama-server"] : ["cpu", "llama-server"]))
131
143
  throw new Error("Unexpected native selection contents.");
132
144
  const payload = payloadRoot(paths, pin);
133
145
  assertDirectoryChain(paths.koedHome, payload);
134
- for (const name of coreLinks) {
146
+ for (const name of coreLinks(pin)) {
135
147
  const path = resolve(root, name);
136
148
  checkLink(path, relative(dirname(path), resolve(payload, name)));
137
149
  }
@@ -144,6 +156,11 @@ function loadSelection(paths, id, catalog) {
144
156
  }
145
157
  return { id, root, pin, cuda };
146
158
  }
159
+ var NativeSelectionTargetError = class extends Error {
160
+ constructor() {
161
+ super("Native selection target differs from this host. Stop Koed, preserve the existing native store, and use a fresh KOED_HOME before installing the runtime. The new KOED_HOME does not include the existing database or other data.");
162
+ }
163
+ };
147
164
  function readNativeSelection(paths, catalog) {
148
165
  const id = currentNativeId(paths);
149
166
  checkEntryPaths(paths, id !== null);
@@ -152,6 +169,8 @@ function readNativeSelection(paths, catalog) {
152
169
  try {
153
170
  return loadSelection(paths, id, catalog);
154
171
  } catch (cause) {
172
+ if (cause instanceof NativeSelectionTargetError)
173
+ throw cause;
155
174
  const detail = (cause instanceof Error ? cause.message : String(cause)).replace(/\.$/, "");
156
175
  throw new Error(`Cannot admit the installed native selection: ${detail}. Stop Koed, preserve the damaged native store for recovery, then run ${releaseInstallCommand}.`, { cause });
157
176
  }
@@ -180,7 +199,7 @@ function composeNativeSelection(paths, pin, staging, catalog, cuda = null) {
180
199
  mode: 384,
181
200
  flush: true
182
201
  });
183
- for (const name of coreLinks) {
202
+ for (const name of coreLinks(pin)) {
184
203
  const target = relative(dirname(resolve(root, name)), resolve(payloadRoot(paths, pin), name));
185
204
  symlinkSync(target, resolve(fresh, name));
186
205
  }
@@ -255,7 +274,7 @@ async function stageNativeAsset(pin, staging, signal, progress) {
255
274
  } catch (cause) {
256
275
  throw new Error(`Could not acquire the pinned native ${kind}: ${cause instanceof Error ? cause.message : String(cause)}. Check connectivity and free space, then retry ${releaseInstallCommand}${kind === "cuda" ? " --with-cuda" : ""}.`, { cause });
257
276
  }
258
- await extractNativeArchive(kind, archive, unpack, pin.expandedBytes, signal);
277
+ await extractNativeArchive(kind, archive, unpack, pin.expandedBytes, signal, pin.target.platform);
259
278
  const root = resolve2(unpack, "koed-runtime");
260
279
  verifyNativePayload(root, pin, true);
261
280
  return root;
@@ -263,11 +282,29 @@ async function stageNativeAsset(pin, staging, signal, progress) {
263
282
 
264
283
  // packages/koed-server/dist/runtime-release.js
265
284
  var reserve = 128 * 1024 * 1024;
266
- function assertReleaseHost() {
267
- const report = process.report.getReport();
268
- const libc = report.header?.glibcVersionRuntime ?? "";
285
+ var MacCudaPolicyError = class extends Error {
286
+ constructor() {
287
+ super("CUDA is not supported by the macOS release runtime. Set KOED_EMBEDDING_ACCELERATION to auto or metal before installing or starting.");
288
+ }
289
+ };
290
+ function assertMacPolicy(platform, policy) {
291
+ if (platform === "macos" && policy === "cuda")
292
+ throw new MacCudaPolicyError();
293
+ }
294
+ function assertReleaseHost(host = {
295
+ platform: process.platform,
296
+ arch: process.arch,
297
+ kernel: kernelRelease(),
298
+ libc: process.report.getReport().header?.glibcVersionRuntime ?? ""
299
+ }) {
300
+ if (host.platform === "darwin" && host.arch === "arm64") {
301
+ if (!/^\d+\.\d+\.\d+$/.test(host.kernel) || Number(host.kernel.split(".")[0]) < 23)
302
+ throw new Error("The release provider requires macOS 14 or later on arm64. Upgrade macOS before installing the release runtime.");
303
+ return;
304
+ }
305
+ const libc = host.libc;
269
306
  const [major, minor] = libc.split(".").map(Number);
270
- if (process.platform !== "linux" || process.arch !== "x64" || !/^\d+\.\d+(\.\d+)?$/.test(libc) || !(major > 2 || major === 2 && minor >= 35))
307
+ if (host.platform !== "linux" || host.arch !== "x64" || !/^\d+\.\d+(\.\d+)?$/.test(libc) || !(major > 2 || major === 2 && minor >= 35))
271
308
  throw new Error("The release provider requires Linux x64 and glibc 2.35 or later. On a host supported by Homebrew, install Homebrew and its host prerequisites, then run koed runtime install --provider homebrew --dependency-mode bundled-local.");
272
309
  }
273
310
  function collectReleaseRuntimeStatus(paths, environment = process.env) {
@@ -284,7 +321,7 @@ function collectReleaseRuntimeStatus(paths, environment = process.env) {
284
321
  installedCudaId: null,
285
322
  pinnedCudaId: catalog.cuda?.recipeId ?? null,
286
323
  executionPolicy: policy,
287
- message: `Install the CPU runtime with ${releaseInstallCommand}.`
324
+ message: `Install the ${catalog.core.target.platform === "macos" ? "Metal" : "CPU"} runtime with ${releaseInstallCommand}.`
288
325
  };
289
326
  const blocker = coreStartBlocker(selected.pin, catalog);
290
327
  if (blocker)
@@ -315,10 +352,10 @@ function collectReleaseRuntimeStatus(paths, environment = process.env) {
315
352
  pinnedCudaId: catalog.cuda?.recipeId ?? null,
316
353
  executionPolicy: policy,
317
354
  runtimeVersion: selected.pin.runtimeVersion,
318
- message: cudaOutdated ? `A CUDA add-on update is available. Stop Koed and run ${releaseInstallCommand} --with-cuda.` : coreOutdated ? `A native core update is available. Stop Koed and run ${releaseInstallCommand}.` : selected.cuda ? "The selected CPU core and CUDA add-on are installed." : "The selected CPU runtime is installed."
355
+ message: cudaOutdated ? `A CUDA add-on update is available. Stop Koed and run ${releaseInstallCommand} --with-cuda.` : coreOutdated ? `A native core update is available. Stop Koed and run ${releaseInstallCommand}.` : selected.cuda ? "The selected CPU core and CUDA add-on are installed." : `The selected ${catalog.core.target.platform === "macos" ? "Metal" : "CPU"} runtime is installed.`
319
356
  };
320
357
  }
321
- async function probeCore(root, signal) {
358
+ async function probeCore(root, signal, platform) {
322
359
  for (const binary of [
323
360
  "postgres/bin/postgres",
324
361
  "postgres/bin/psql",
@@ -332,13 +369,32 @@ async function probeCore(root, signal) {
332
369
  PATH: "/usr/bin:/bin",
333
370
  LANG: "C",
334
371
  LC_ALL: "C",
335
- KOED_LLAMA_SERVER_BACKEND: "cpu"
372
+ KOED_LLAMA_SERVER_BACKEND: platform === "macos" ? "metal" : "cpu"
336
373
  }
337
374
  });
338
375
  } catch (error) {
339
376
  throw new Error(`Staged native probe failed: ${binary}. ${error instanceof Error ? error.message : String(error)}`, { cause: error });
340
377
  }
341
378
  }
379
+ if (platform === "macos") {
380
+ try {
381
+ const devices = await nativeCommand(resolve3(root, "llama.cpp/llama-server"), ["--list-devices"], {
382
+ cwd: root,
383
+ signal,
384
+ env: {
385
+ PATH: "/usr/bin:/bin",
386
+ LANG: "C",
387
+ LC_ALL: "C",
388
+ KOED_LLAMA_SERVER_BACKEND: "metal",
389
+ LLAMA_ARG_UI: "false"
390
+ }
391
+ });
392
+ if (!/^[ \t]*(?:MTL[0-9]+|Metal[0-9]*):[ \t]+\S/im.test(devices))
393
+ throw new Error("No Metal device was reported.");
394
+ } catch (cause) {
395
+ throw new Error(`Staged Metal device discovery failed: ${cause instanceof Error ? cause.message : String(cause)}. Check Metal support and the native runtime, then retry.`, { cause });
396
+ }
397
+ }
342
398
  }
343
399
  function recordStatus(paths, id) {
344
400
  const cache = resolve3(paths.cacheDir, "runtime-release.json");
@@ -368,13 +424,16 @@ function recordStatus(paths, id) {
368
424
  }
369
425
  async function installReleaseRuntime(paths, options = {}) {
370
426
  assertReleaseHost();
371
- const catalog = getNativeRuntimeCatalog(), pin = catalog.core, store = nativeStore(paths), owner = resolveKoedRuntimeOwner();
427
+ if (process.platform === "darwin" && options.cuda && options.cuda !== "preserve")
428
+ throw new Error("--with-cuda and --without-cuda are not supported on macOS.");
429
+ const catalog = getNativeRuntimeCatalog(), pin = catalog.core, store = nativeStore(paths), owner = options.desktopRuntimeCapability ? resolveDesktopRuntimeOwner(options.desktopRuntimeCapability, paths.koedHome) : resolveKoedRuntimeOwner();
372
430
  const choice = options.cuda ?? "preserve", environment = options.environment ?? process.env;
373
431
  const signal = options.signal ?? new AbortController().signal;
374
432
  const plan = () => {
375
433
  signal.throwIfAborted();
376
- const selected = readNativeSelection(paths, catalog);
377
434
  const policy = embeddingPolicy(paths, environment);
435
+ assertMacPolicy(pin.target.platform, policy);
436
+ const selected = readNativeSelection(paths, catalog);
378
437
  const cuda = chooseCuda(catalog, selected?.cuda ?? null, choice, policy);
379
438
  if (selected && selected.pin.recipeId !== pin.recipeId && compareNativeVersions(pin.runtimeVersion, selected.pin.runtimeVersion) <= 0)
380
439
  throw new Error("Refusing a native core downgrade or replacement at the same runtime version.");
@@ -382,6 +441,8 @@ async function installReleaseRuntime(paths, options = {}) {
382
441
  return { selected, cuda, policy };
383
442
  };
384
443
  const before = await withStoppedRuntime(paths, owner, async () => {
444
+ await options.assertConfiguration?.();
445
+ options.phase?.("checking");
385
446
  const { selected, cuda, policy } = plan();
386
447
  for (const name of ["core", "selections", ...cuda ? ["cuda"] : []]) {
387
448
  const dir = resolve3(store, name);
@@ -389,8 +450,11 @@ async function installReleaseRuntime(paths, options = {}) {
389
450
  mkdirSync2(dir, { recursive: true, mode: 448 });
390
451
  }
391
452
  if (selected?.pin.recipeId === pin.recipeId && selected.cuda?.recipeId === cuda?.recipeId) {
453
+ if (choice === "with")
454
+ options.phase?.("inference");
392
455
  const validation = choice === "with" ? await validateStagedCuda(paths, selected.root, environment, {
393
- signal
456
+ signal,
457
+ requireModel: options.requireModel
394
458
  }) : void 0;
395
459
  const warning = recordStatus(paths, selected.id);
396
460
  return {
@@ -437,9 +501,17 @@ async function installReleaseRuntime(paths, options = {}) {
437
501
  const staging = mkdtempSync(resolve3(store, ".stage-"));
438
502
  try {
439
503
  const staged = /* @__PURE__ */ new Map();
440
- for (const asset of missing)
441
- staged.set(asset, await stageNativeAsset(asset, staging, signal, options.progress));
504
+ let downloaded = 0;
505
+ for (const asset of missing) {
506
+ staged.set(asset, await stageNativeAsset(asset, staging, signal, (event) => options.progress?.({
507
+ ...event,
508
+ transferredBytes: downloaded + event.transferredBytes,
509
+ totalBytes: downloadBytes
510
+ })));
511
+ downloaded += asset.archiveBytes;
512
+ }
442
513
  return await withStoppedRuntime(paths, owner, async () => {
514
+ await options.assertConfiguration?.();
443
515
  const { selected, cuda, policy } = plan();
444
516
  if ((selected?.id ?? null) !== before.previousId || before.cuda?.recipeId !== cuda?.recipeId)
445
517
  throw new Error("Another installer changed the selection. Inspect runtime status and retry.");
@@ -452,19 +524,25 @@ async function installReleaseRuntime(paths, options = {}) {
452
524
  }
453
525
  }
454
526
  const next = composeNativeSelection(paths, pin, staging, catalog, cuda);
455
- await probeCore(next.root, signal);
527
+ options.phase?.("verifying");
528
+ await probeCore(next.root, signal, pin.target.platform);
529
+ if (cuda)
530
+ options.phase?.("inference");
456
531
  const validation = cuda ? await validateStagedCuda(paths, next.root, environment, {
457
- signal
532
+ signal,
533
+ requireModel: options.requireModel
458
534
  }).catch((error) => {
459
535
  if (signal.aborted)
460
536
  throw error;
461
537
  throw preservedCudaFailure(error, choice, policy);
462
538
  }) : void 0;
463
539
  signal.throwIfAborted();
540
+ options.phase?.("activating");
541
+ signal.throwIfAborted();
464
542
  activateNativeSelection(paths, next.id);
465
543
  const warning = recordStatus(paths, next.id);
466
544
  const dropped = choice === "preserve" && selected?.cuda && !cuda;
467
- const message = dropped ? `CPU runtime selected. The prior CUDA add-on is incompatible; run ${releaseInstallCommand} --with-cuda for a compatible pair. Run koed start when ready.` : `${cuda ? "CPU core and CUDA add-on" : "CPU runtime"} installed. Run koed start when ready.`;
545
+ const message = dropped ? `CPU runtime selected. The prior CUDA add-on is incompatible; run ${releaseInstallCommand} --with-cuda for a compatible pair. Run koed start when ready.` : `${cuda ? "CPU core and CUDA add-on" : pin.target.platform === "macos" ? "Metal runtime" : "CPU runtime"} installed. Run koed start when ready.`;
468
546
  return {
469
547
  ok: true,
470
548
  provider: "release",
@@ -506,10 +584,15 @@ function resolveSelectedCoreForStart(paths, environment = process.env, useSelect
506
584
  assertReleaseHost();
507
585
  const catalog = getNativeRuntimeCatalog(), selected = readNativeSelection(paths, catalog);
508
586
  assertStartableCore(selected.pin, catalog);
509
- if (useSelectedLlama && embeddingPolicy(paths, environment) === "cuda" && !selected.cuda)
587
+ const policy = useSelectedLlama ? embeddingPolicy(paths, environment) : null;
588
+ if (policy)
589
+ assertMacPolicy(catalog.core.target.platform, policy);
590
+ if (useSelectedLlama && policy === "cuda" && !selected.cuda)
510
591
  throw new Error("The forced CUDA policy requires a selected CUDA add-on.");
511
592
  return selected.root;
512
593
  } catch (cause) {
594
+ if (cause instanceof MacCudaPolicyError || cause instanceof NativeSelectionTargetError)
595
+ throw cause;
513
596
  const command = environment.KOED_EMBEDDING_ACCELERATION?.trim().toLowerCase() === "cuda" ? releaseInstallCommand + " --with-cuda" : releaseInstallCommand;
514
597
  throw new Error(`Cannot start the release-managed native runtime: ${cause instanceof Error ? cause.message : String(cause)}. Stop Koed, inspect runtime status, and run ${command}.`, { cause });
515
598
  }
@@ -3,7 +3,7 @@ import {
3
3
  PINNED_PRIVACY_MODEL_FILES,
4
4
  PINNED_PRIVACY_MODEL_ID,
5
5
  PINNED_PRIVACY_MODEL_REVISION
6
- } from "./chunk-ZOHNXUDY.js";
6
+ } from "./chunk-E6YVGIEW.js";
7
7
 
8
8
  // packages/koed-server/dist/privacy-model-runtime.js
9
9
  import { createHash, randomUUID } from "node:crypto";
@@ -2,19 +2,19 @@ import { createRequire as createKoedRequire } from "node:module"; const require
2
2
  import {
3
3
  calculateRuntimeRequirements,
4
4
  resolveEffectiveRuntimeConfig
5
- } from "./chunk-SHLRINKO.js";
5
+ } from "./chunk-L4RD3TAZ.js";
6
6
  import {
7
7
  redeemPairingLink
8
- } from "./chunk-CHMH4LH5.js";
8
+ } from "./chunk-NGV45YWB.js";
9
9
  import {
10
10
  bundledPdsSecretProviderEnvironment
11
- } from "./chunk-EA4QDDQA.js";
11
+ } from "./chunk-GY5GATZL.js";
12
12
  import {
13
13
  resolveLocalModelManifest
14
14
  } from "./chunk-JYK6UL6D.js";
15
15
  import {
16
16
  invalidateUpstreamEnrollmentReferences
17
- } from "./chunk-WPIEF4LY.js";
17
+ } from "./chunk-T7OGE5E5.js";
18
18
  import {
19
19
  collectKoedServerDoctor,
20
20
  collectKoedServerStartupStatus,
@@ -22,6 +22,7 @@ import {
22
22
  ensurePackagedLocalServiceSecrets,
23
23
  hasCompletePostgresOverride,
24
24
  koedServerStartupBlockingComponentIds,
25
+ localServiceSecretsPath,
25
26
  migrateKoedOwnedCodexRegistrationBestEffort,
26
27
  nativeLlamaServerOverride,
27
28
  pinAndResolvePackagedRuntime,
@@ -39,7 +40,7 @@ import {
39
40
  startLocalPostgresRuntime,
40
41
  startLocalPrivacyRuntime,
41
42
  stopLocalPostgresRuntime
42
- } from "./chunk-EDPNYIX5.js";
43
+ } from "./chunk-USHFSJT7.js";
43
44
  import {
44
45
  resolveActiveIntegrationApiToken,
45
46
  resolveLocalApiToken,
@@ -55,7 +56,7 @@ import {
55
56
  ensureDeviceIdentity,
56
57
  inspectDeviceIdentityStatus,
57
58
  rotateDeviceIdentity
58
- } from "./chunk-SRKIBFOE.js";
59
+ } from "./chunk-LHUMBHG7.js";
59
60
  import {
60
61
  maintainSupervisorLog,
61
62
  startKoedServerDaemon
@@ -77,20 +78,21 @@ import {
77
78
  resolveKoedAppRuntime,
78
79
  resolveKoedAppRuntimeExecution,
79
80
  resolveKoedRuntimeOwner
80
- } from "./chunk-V67IQB7H.js";
81
+ } from "./chunk-OG7G6DIR.js";
81
82
  import {
82
83
  acquireKoedServerSupervisorLock,
83
84
  observeStoppedRuntime,
84
85
  readCurrentRuntimeOwner,
85
86
  readSupervisorLock,
86
87
  releaseKoedServerSupervisorLock,
88
+ removeStaleGenerationPin,
87
89
  removeStaleRuntimeRecords,
88
90
  resolveDesktopRuntimeOwner,
89
91
  resolveProcessIdentity,
90
92
  validateDesktopRuntimeCapability,
91
93
  withLifecycleLock,
92
94
  withSourceNativeStartLock
93
- } from "./chunk-FN3HUUO2.js";
95
+ } from "./chunk-UCOHFZ77.js";
94
96
  import {
95
97
  isProcessRunning,
96
98
  isRuntimeGenerationState,
@@ -100,11 +102,11 @@ import {
100
102
  import {
101
103
  listUpstreamBackends,
102
104
  refreshUpstreamBackendCapabilities
103
- } from "./chunk-RCR4XPE3.js";
105
+ } from "./chunk-WBMO7YCO.js";
104
106
  import {
105
107
  createPdsApplicationSecretStore,
106
108
  isPrivateNetworkIpv4Address
107
- } from "./chunk-ZOHNXUDY.js";
109
+ } from "./chunk-E6YVGIEW.js";
108
110
 
109
111
  // packages/koed-server/dist/personal-device-request.js
110
112
  import { createHash as createHash2, randomBytes as randomBytes2, randomUUID as randomUUID2 } from "node:crypto";
@@ -788,7 +790,7 @@ var stopKoedServer = ({ environment = process.env, existsSync: pathExists = node
788
790
  const lock = readLock(supervisorLockPath);
789
791
  const supervisorRunning = runtime.pid > 0 && checkPid(runtime.pid);
790
792
  const processIdentity = supervisorRunning ? resolveProcessIdentity2(runtime.pid) : null;
791
- if (ownerPinRequired && !pin || pinExists && !pin || pin !== null && (pin.pid !== runtime.pid || !ownersMatch(pin.owner, owner) || lock?.pid !== runtime.pid || !lock.processIdentity || pin.processIdentity !== lock.processIdentity || supervisorRunning && processIdentity !== pin.processIdentity)) {
793
+ if (lock?.sourceOwner && !ownersMatch(lock.sourceOwner, owner) || ownerPinRequired && !pin || pinExists && !pin || pin !== null && (pin.pid !== runtime.pid || !ownersMatch(pin.owner, owner) || lock?.pid !== runtime.pid || !lock.processIdentity || pin.processIdentity !== lock.processIdentity || supervisorRunning && processIdentity !== pin.processIdentity)) {
792
794
  supervisorLockMatches = false;
793
795
  errors.push({
794
796
  target: `supervisor (${runtime.pid})`,
@@ -828,7 +830,7 @@ var stopKoedServer = ({ environment = process.env, existsSync: pathExists = node
828
830
  checkPid,
829
831
  // Let the supervisor finish its bounded per-child shutdown before falling
830
832
  // back to direct PID signals, which cannot reach llama-server descendants.
831
- waitForExitMs: requestedWait ?? (releaseManaged ? 6e4 : 5e3),
833
+ waitForExitMs: requestedWait ?? 6e4,
832
834
  pollIntervalMs,
833
835
  sleepSync
834
836
  });
@@ -1109,7 +1111,7 @@ import { existsSync as existsSync3, mkdirSync as mkdirSync3 } from "node:fs";
1109
1111
  import { dirname, resolve as resolve4 } from "node:path";
1110
1112
 
1111
1113
  // packages/koed-server/dist/runtime-lifecycle.js
1112
- import { existsSync as existsSync2, readFileSync as readFileSync3 } from "node:fs";
1114
+ import { existsSync as existsSync2, lstatSync as lstatSync2, readFileSync as readFileSync3 } from "node:fs";
1113
1115
  import { resolve as resolve3 } from "node:path";
1114
1116
  var readJson = (path) => {
1115
1117
  try {
@@ -1149,17 +1151,19 @@ function observeRuntimeLifecycle(paths, { resolveProcessIdentity: resolveProcess
1149
1151
  message: "Koed is not running."
1150
1152
  };
1151
1153
  const epoch = `${lock.pid}:${identity}`;
1152
- const pin = readJson(paths.generationStatePath ?? resolve3(paths.runDir, "runtime-generation.json"));
1154
+ const pinPath = paths.generationStatePath ?? resolve3(paths.runDir, "runtime-generation.json");
1155
+ const pin = readJson(pinPath);
1153
1156
  const pinned = isRuntimeGenerationState(pin) && pin.pid === lock.pid && pin.processIdentity === identity ? pin : null;
1154
1157
  const runtime = readJson(paths.runtimeStatePath);
1155
- const running = pinned !== null && runtime?.pid === lock.pid;
1158
+ const owner = pinned?.owner ?? (!lstatSync2(pinPath, { throwIfNoEntry: false }) ? lock.sourceOwner : null);
1159
+ const running = !!owner && runtime?.pid === lock.pid;
1156
1160
  return {
1157
1161
  state: running ? "running" : "starting",
1158
1162
  epoch,
1159
1163
  message: running ? "Koed is running." : "Koed is starting.",
1160
1164
  pid: lock.pid,
1161
1165
  processIdentity: identity,
1162
- owner: pinned ? { ...pinned.owner } : null,
1166
+ owner: owner ? { ...owner } : null,
1163
1167
  ...pinned ? { generationId: pinned.generationId } : {}
1164
1168
  };
1165
1169
  }
@@ -1521,12 +1525,16 @@ var startKoedServer = async ({ environment = process.env, pollIntervalMs = 500,
1521
1525
  const startupId = randomBytes3(12).toString("hex");
1522
1526
  const startupStartedAt = process.hrtime.bigint();
1523
1527
  const emitStartupMilestone = (milestone) => {
1524
- console.log(JSON.stringify({
1528
+ const line = JSON.stringify({
1525
1529
  event: "koed.supervisor.startup",
1526
1530
  startupId,
1527
1531
  milestone,
1528
1532
  elapsedMs: Number(process.hrtime.bigint() - startupStartedAt) / 1e6
1529
- }));
1533
+ });
1534
+ console.log(line);
1535
+ if (process.env.KOED_SUPERVISOR_STARTUP_TRACE === "1")
1536
+ process.stderr.write(`${line}
1537
+ `);
1530
1538
  };
1531
1539
  emitStartupMilestone("supervisor_entry");
1532
1540
  const execution = resolveKoedAppRuntimeExecution();
@@ -1549,6 +1557,7 @@ var startKoedServer = async ({ environment = process.env, pollIntervalMs = 500,
1549
1557
  assertObservedOwner(observeRuntimeLifecycle(paths));
1550
1558
  ensureKoedHome(paths);
1551
1559
  const supervisorLock = acquireKoedServerSupervisorLock(paths, {
1560
+ ...execution === "source" ? { sourceOwner: resolveKoedRuntimeOwner() } : {},
1552
1561
  exclusive: (action) => withLifecycleLock(paths, action)
1553
1562
  });
1554
1563
  if (!supervisorLock.acquired) {
@@ -1580,6 +1589,12 @@ var startKoedServer = async ({ environment = process.env, pollIntervalMs = 500,
1580
1589
  throw error;
1581
1590
  }
1582
1591
  };
1592
+ if (execution === "source") {
1593
+ startupPhase = "stale generation pin cleanup";
1594
+ await initializeUnderSupervisorLock(() => {
1595
+ removeStaleGenerationPin(paths);
1596
+ });
1597
+ }
1583
1598
  startupPhase = "device identity initialization";
1584
1599
  await initializeUnderSupervisorLock(() => ensureDeviceIdentity(paths, { environment }));
1585
1600
  const supervisorStartedAt = (/* @__PURE__ */ new Date()).toISOString();
@@ -1594,10 +1609,11 @@ var startKoedServer = async ({ environment = process.env, pollIntervalMs = 500,
1594
1609
  };
1595
1610
  const desktopManagedLocal = environment.KOED_AUTO_PORTS === "1";
1596
1611
  const startupConfig = effectiveRuntimeConfig.config;
1612
+ const bundledPersonal = startupConfig.runtimeMode === "local-personal" && startupConfig.dependencyMode === "bundled-local";
1597
1613
  startupPhase = "packaged local service secrets";
1598
- environment = await initializeUnderSupervisorLock(() => ensurePackagedLocalServiceSecrets(paths, execution === "packaged" || startupConfig.runtimeMode === "local-personal" && startupConfig.dependencyMode === "bundled-local", environment));
1614
+ environment = await initializeUnderSupervisorLock(() => ensurePackagedLocalServiceSecrets(paths, execution === "packaged" || bundledPersonal, environment));
1599
1615
  mkdirSync3(paths.logsDir, { recursive: true, mode: 448 });
1600
- if (startupConfig.runtimeMode === "local-personal" && startupConfig.dependencyMode === "bundled-local" && environment.KOED_AUTO_PORTS === void 0) {
1616
+ if (bundledPersonal && environment.KOED_AUTO_PORTS === void 0) {
1601
1617
  environment = { ...environment, KOED_AUTO_PORTS: "1" };
1602
1618
  }
1603
1619
  const portAllocationEnvironment = { ...environment };
@@ -1661,7 +1677,10 @@ var startKoedServer = async ({ environment = process.env, pollIntervalMs = 500,
1661
1677
  const childEnv = initialServiceEnv;
1662
1678
  if (execution === "source") {
1663
1679
  startupPhase = "source environment preparation";
1664
- runCommand(paths, "Prepare Koed environment", process.execPath, [resolve4(paths.repoRoot, "scripts/setup-env.mjs")], childEnv, spawnSync);
1680
+ runCommand(paths, "Prepare Koed environment", process.execPath, [
1681
+ resolve4(paths.repoRoot, "scripts/setup-env.mjs"),
1682
+ ...bundledPersonal ? ["--local-service-secrets", localServiceSecretsPath(paths)] : []
1683
+ ], childEnv, spawnSync);
1665
1684
  }
1666
1685
  startupPhase = "refreshed repository environment and credentials";
1667
1686
  const refreshedRepoEnv = await initializeUnderSupervisorLock(() => execution === "source" || environment.KOED_ENV_PATH?.trim() ? loadRepoEnv(paths.repoRoot, environment) : {});
@@ -1810,7 +1829,7 @@ var startKoedServer = async ({ environment = process.env, pollIntervalMs = 500,
1810
1829
  assertKoedAppRuntimeAvailable(appRuntime, paths);
1811
1830
  }
1812
1831
  if (useBundledLocalDependencies && hasReleaseRuntime(paths) && !(hasCompletePostgresOverride(refreshedEnv) && nativeLlamaServerOverride(refreshedEnv))) {
1813
- const { resolveSelectedCoreForStart } = await import("./chunk-VGIYSDNU.js");
1832
+ const { resolveSelectedCoreForStart } = await import("./chunk-273NMYXE.js");
1814
1833
  const admitSelection = () => resolveSelectedCoreForStart(paths, refreshedEnv, !nativeLlamaServerOverride(refreshedEnv));
1815
1834
  const selected = generationPin ? admitSelection() : withSourceNativeStartLock(paths, admitSelection);
1816
1835
  if (selected)
@@ -2009,7 +2028,7 @@ var startKoedServer = async ({ environment = process.env, pollIntervalMs = 500,
2009
2028
  }
2010
2029
  emitStartupMilestone("core_services_ready");
2011
2030
  startupReady = true;
2012
- onReady?.();
2031
+ onReady?.(refreshedEnv);
2013
2032
  console.log(JSON.stringify(status, null, 2));
2014
2033
  emitStartupMilestone("final_supervisor_status_emitted");
2015
2034
  console.log("Koed server supervisor is running. Press Ctrl-C to stop local app processes.");
@@ -4,13 +4,13 @@ import {
4
4
  isKoedServerCliEntrypoint,
5
5
  runKoedServerCli,
6
6
  shouldExitPackagedSupervisor
7
- } from "./chunk-FYYRFX4U.js";
7
+ } from "./chunk-TIBYKMRW.js";
8
8
  import {
9
9
  startKoedServerDaemon
10
10
  } from "./chunk-7FSHVVTZ.js";
11
11
  import "./chunk-TSAYTRX3.js";
12
12
  import "./chunk-YZLQZU5E.js";
13
- import "./chunk-V67IQB7H.js";
13
+ import "./chunk-OG7G6DIR.js";
14
14
  import "./chunk-BTS4ZTF3.js";
15
15
  export {
16
16
  isKoedServerCliEntrypoint,