deus-machine 0.3.11 → 0.3.13

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.
package/dist/cli.js CHANGED
@@ -19,7 +19,7 @@ var init_package = __esm({
19
19
  "package.json"() {
20
20
  package_default = {
21
21
  name: "deus-machine",
22
- version: "0.3.11",
22
+ version: "0.3.13",
23
23
  description: "Run Deus IDE from the command line \u2014 headless server or desktop installer",
24
24
  license: "MIT",
25
25
  author: {
@@ -58,11 +58,9 @@ var init_package = __esm({
58
58
  build: "bunx tsx build.ts"
59
59
  },
60
60
  dependencies: {
61
- "@anthropic-ai/claude-agent-sdk": "0.2.131",
61
+ "@anthropic-ai/claude-agent-sdk": "0.3.288",
62
62
  "@hono/node-server": "^1.19.9",
63
63
  "@napi-rs/canvas": "^0.1.97",
64
- "@openai/codex": "0.153.4",
65
- "@openai/codex-sdk": "0.153.4",
66
64
  "@sentry/node": "^10.40.0",
67
65
  "agent-browser": "^0.21.4",
68
66
  "better-sqlite3": "^12.4.1",
@@ -77,31 +75,18 @@ var init_package = __esm({
77
75
  import { parseArgs } from "node:util";
78
76
 
79
77
  // src/start.ts
80
- import { execSync as execSync2, spawn as spawn2 } from "node:child_process";
81
- import { existsSync as existsSync6 } from "node:fs";
78
+ import { spawn } from "node:child_process";
79
+ import { existsSync as existsSync3 } from "node:fs";
80
+ import { createRequire } from "node:module";
82
81
  import { join as join3, resolve, dirname } from "node:path";
83
- import { fileURLToPath as fileURLToPath4 } from "node:url";
82
+ import { fileURLToPath } from "node:url";
84
83
  import { homedir as homedir3 } from "node:os";
85
- import { mkdirSync as mkdirSync4 } from "node:fs";
84
+ import { mkdirSync as mkdirSync2 } from "node:fs";
86
85
 
87
86
  // ../../shared/runtime.ts
88
87
  import path from "node:path";
89
88
  var DEUS_APP_ID = "com.deus.app";
90
89
  var DEUS_DB_FILENAME = "deus.db";
91
- var DEUS_PREFERENCES_FILENAME = "preferences.json";
92
- var RUNTIME_MANIFEST_VERSION = 1;
93
- var CLI_RUNTIME_DEPENDENCIES = [
94
- "@anthropic-ai/claude-agent-sdk",
95
- "@hono/node-server",
96
- "@napi-rs/canvas",
97
- "@openai/codex",
98
- "@openai/codex-sdk",
99
- "@sentry/node",
100
- "agent-browser",
101
- "better-sqlite3",
102
- "node-pty",
103
- "ws"
104
- ];
105
90
  function getPathModule(platform4) {
106
91
  return platform4 === "win32" ? path.win32 : path.posix;
107
92
  }
@@ -130,8 +115,7 @@ function resolveRuntimeStagePaths(projectRoot) {
130
115
  manifest: path.join(runtimeRoot, "manifest.json"),
131
116
  common: {
132
117
  root: commonRoot,
133
- backendBundle: path.join(commonRoot, "server.bundled.cjs"),
134
- agentServerBundle: path.join(commonRoot, "agent-server.bundled.cjs")
118
+ backendBundle: path.join(commonRoot, "server.bundled.cjs")
135
119
  },
136
120
  electron: {
137
121
  root: electronRoot
@@ -139,974 +123,6 @@ function resolveRuntimeStagePaths(projectRoot) {
139
123
  };
140
124
  }
141
125
 
142
- // ../../scripts/runtime/validate.ts
143
- import { execFileSync as execFileSync3 } from "node:child_process";
144
- import { createHash as createHash3 } from "node:crypto";
145
- import { existsSync as existsSync3, readFileSync as readFileSync3, statSync as statSync3 } from "node:fs";
146
- import path4 from "node:path";
147
- import { fileURLToPath as fileURLToPath3 } from "node:url";
148
-
149
- // ../../scripts/runtime/agent-clis.ts
150
- import { execFileSync, spawn, spawnSync } from "node:child_process";
151
- import { createHash } from "node:crypto";
152
- import {
153
- chmodSync,
154
- constants,
155
- cpSync,
156
- existsSync,
157
- linkSync,
158
- mkdirSync,
159
- mkdtempSync,
160
- readFileSync,
161
- rmSync,
162
- statSync,
163
- symlinkSync,
164
- writeFileSync
165
- } from "node:fs";
166
- import path2 from "node:path";
167
- import { fileURLToPath } from "node:url";
168
- var runtimeDir = path2.dirname(fileURLToPath(import.meta.url));
169
- var defaultProjectRoot = path2.resolve(runtimeDir, "../..");
170
- var VERIFY_TIMEOUT_MS = 2e4;
171
- var MIN_CODEX_APP_SERVER_VERSION = "0.128.0";
172
- var VERSION_CHECK_ENV_DENYLIST = [
173
- "AGENT_SERVER_CWD",
174
- "AGENT_SERVER_ENTRY",
175
- "AUTH_TOKEN",
176
- "BUN_OPTIONS",
177
- "DATABASE_PATH",
178
- "DEUS_AUTH_TOKEN",
179
- "DEUS_BACKEND_PORT",
180
- "DEUS_BUNDLED_BIN_DIR",
181
- "DEUS_DATA_DIR",
182
- "DEUS_PACKAGED",
183
- "DEUS_RESOURCES_PATH",
184
- "DEUS_RUNTIME",
185
- "DEUS_RUNTIME_COMMAND",
186
- "DEUS_RUNTIME_EXECUTABLE",
187
- "ELECTRON_RUN_AS_NODE",
188
- "NODE_PATH",
189
- "PORT"
190
- ];
191
- var CODEX_HELPERS = [
192
- "codex-runtime/bin/codex-code-mode-host",
193
- "codex-runtime/codex-resources/zsh/bin/zsh"
194
- ];
195
- var CODEX_LINUX_HELPER = "codex-runtime/codex-resources/bwrap";
196
- function bundledTools(runtimeKey) {
197
- return [
198
- "codex",
199
- "claude",
200
- "rg",
201
- "agent-browser",
202
- ...CODEX_HELPERS,
203
- ...runtimeKey.startsWith("linux-") ? [CODEX_LINUX_HELPER] : []
204
- ];
205
- }
206
- var AGENT_CLI_TARGETS = [
207
- {
208
- runtimeKey: "darwin-arm64",
209
- fileFormat: "Mach-O 64-bit executable",
210
- fileArch: "arm64",
211
- agentBrowserEntry: "bin/agent-browser-darwin-arm64",
212
- codexAliasPackage: "@openai/codex-darwin-arm64",
213
- codexTriple: "aarch64-apple-darwin",
214
- claudePackageName: "@anthropic-ai/claude-agent-sdk-darwin-arm64"
215
- },
216
- {
217
- runtimeKey: "darwin-x64",
218
- fileFormat: "Mach-O 64-bit executable",
219
- fileArch: "x86_64",
220
- agentBrowserEntry: "bin/agent-browser-darwin-x64",
221
- codexAliasPackage: "@openai/codex-darwin-x64",
222
- codexTriple: "x86_64-apple-darwin",
223
- claudePackageName: "@anthropic-ai/claude-agent-sdk-darwin-x64"
224
- },
225
- {
226
- runtimeKey: "linux-x64",
227
- fileFormat: "ELF 64-bit",
228
- fileArch: "x86-64",
229
- agentBrowserEntry: "bin/agent-browser-linux-x64",
230
- codexAliasPackage: "@openai/codex-linux-x64",
231
- codexTriple: "x86_64-unknown-linux-musl",
232
- claudePackageName: "@anthropic-ai/claude-agent-sdk-linux-x64"
233
- }
234
- ];
235
- function relativeFromProjectRoot(projectRoot, targetPath) {
236
- return path2.relative(projectRoot, targetPath).split(path2.sep).join("/");
237
- }
238
- function resolveAgentCliManifestPath(projectRoot) {
239
- return path2.join(resolveRuntimeStagePaths(projectRoot).electron.root, "bin", "agent-clis.json");
240
- }
241
- function resolveStagedAgentCliPath(projectRoot, runtimeKey, tool) {
242
- return path2.join(resolveRuntimeStagePaths(projectRoot).electron.root, "bin", runtimeKey, tool);
243
- }
244
- function readSemver(version) {
245
- return version.match(/\d+\.\d+\.\d+/)?.[0] ?? null;
246
- }
247
- function isVersionAtLeast(version, minimum) {
248
- if (!version) return false;
249
- const currentParts = version.split(".").map(Number);
250
- const minimumParts = minimum.split(".").map(Number);
251
- for (let i = 0; i < minimumParts.length; i++) {
252
- const current = currentParts[i] ?? 0;
253
- const required = minimumParts[i] ?? 0;
254
- if (current > required) return true;
255
- if (current < required) return false;
256
- }
257
- return true;
258
- }
259
- function assertCodexAppServerCompatible(version, label) {
260
- const semver = readSemver(version);
261
- if (isVersionAtLeast(semver, MIN_CODEX_APP_SERVER_VERSION)) return;
262
- throw new Error(
263
- `${label} requires @openai/codex >= ${MIN_CODEX_APP_SERVER_VERSION} for the codex app-server harness; found ${version}`
264
- );
265
- }
266
- function hashFile(filePath) {
267
- return createHash("sha256").update(readFileSync(filePath)).digest("hex");
268
- }
269
- function shouldVerifyRuntimeKey(runtimeKey) {
270
- if (process.platform === "darwin") return runtimeKey === `darwin-${process.arch}`;
271
- if (process.platform === "linux" && process.arch === "x64") return runtimeKey === "linux-x64";
272
- return false;
273
- }
274
- function spawnErrorCode(error2) {
275
- return error2?.code ?? error2?.message ?? "none";
276
- }
277
- function verifyVersion(executablePath, args, env = process.env) {
278
- const result = spawnSync(executablePath, args, {
279
- encoding: "utf8",
280
- timeout: VERIFY_TIMEOUT_MS,
281
- env,
282
- stdio: ["ignore", "pipe", "pipe"]
283
- });
284
- const output = (result.stdout || "").trim();
285
- if (result.status !== 0) {
286
- const stderr = (result.stderr || "").trim();
287
- const diagnostics = stagedExecutableDiagnostics(executablePath);
288
- const hint2 = macExecutionPolicyHint(diagnostics);
289
- throw new Error(
290
- `${path2.basename(executablePath)} ${args.join(" ")} failed: status=${result.status} signal=${result.signal} error=${spawnErrorCode(result.error)} stdout=${output} stderr=${stderr}${diagnostics ? `
291
- ${diagnostics}` : ""}${hint2}`
292
- );
293
- }
294
- return output;
295
- }
296
- function diagnosticOutput(command, args, cwd) {
297
- const result = spawnSync(command, args, {
298
- cwd,
299
- encoding: "utf8",
300
- timeout: VERIFY_TIMEOUT_MS,
301
- stdio: ["ignore", "pipe", "pipe"]
302
- });
303
- const output = `${result.stdout || ""}${result.stderr || ""}`.trim();
304
- if (result.error) {
305
- return [spawnErrorCode(result.error), output].filter(Boolean).join("\n");
306
- }
307
- if (result.status !== 0) return output || `${command} exited with status ${result.status}`;
308
- return output;
309
- }
310
- function stagedExecutableDiagnostics(executablePath) {
311
- if (process.platform !== "darwin") return "";
312
- const cwd = path2.dirname(executablePath);
313
- return [
314
- `file: ${diagnosticOutput("file", [executablePath], cwd)}`,
315
- `codesign: ${diagnosticOutput("codesign", ["-dv", "--verbose=4", executablePath], cwd)}`,
316
- `spctl: ${diagnosticOutput("spctl", ["--assess", "--type", "execute", "--verbose=4", executablePath], cwd)}`,
317
- `xattr: ${diagnosticOutput("xattr", ["-l", executablePath], cwd) || "none"}`
318
- ].join("\n");
319
- }
320
- function macExecutionPolicyHint(diagnostics) {
321
- if (process.platform !== "darwin") return "";
322
- if (!/spctl:[\s\S]*rejected/.test(diagnostics)) return "";
323
- if (!/com\.apple\.(provenance|quarantine)/.test(diagnostics)) return "";
324
- return [
325
- "",
326
- "macOS rejected this executable before --version produced output.",
327
- "Verify runnable staged agent CLIs on a notarized artifact or a macOS host that allows generated/copied Mach-O binaries to launch."
328
- ].join("\n");
329
- }
330
- function assertVersionOutput(tool, output, executablePath) {
331
- if (!output) {
332
- throw new Error(`${tool} --version produced no output for ${executablePath}`);
333
- }
334
- if (tool === "codex" && !/\b\d+\.\d+\.\d+\b/.test(output)) {
335
- throw new Error(`Unexpected codex --version output for ${executablePath}: ${output}`);
336
- }
337
- if (tool === "claude" && !/Claude Code|\b\d+\.\d+\.\d+\b/.test(output)) {
338
- throw new Error(`Unexpected claude --version output for ${executablePath}: ${output}`);
339
- }
340
- }
341
- function verifyStagedAgentCliVersion(tool, executablePath) {
342
- const binDir = path2.dirname(executablePath);
343
- const env = versionCheckEnv(binDir);
344
- const output = verifyVersion(
345
- executablePath,
346
- [tool === "claude" ? "--version" : "--version"],
347
- env
348
- );
349
- assertVersionOutput(tool, output, executablePath);
350
- return output;
351
- }
352
- function versionCheckEnv(binDir) {
353
- const env = { ...process.env };
354
- for (const key of VERSION_CHECK_ENV_DENYLIST) {
355
- delete env[key];
356
- }
357
- env.PATH = [binDir, process.env.PATH].filter(Boolean).join(path2.delimiter);
358
- return env;
359
- }
360
- function inspectStaticExecutable(projectRoot, filePath, label, fileFormat, fileArch) {
361
- assertExecutable(filePath, label);
362
- return {
363
- sha256: hashFile(filePath),
364
- size: statSync(filePath).size,
365
- fileOutput: getExecutableFileOutput(projectRoot, filePath, label, fileFormat, fileArch)
366
- };
367
- }
368
- function assertManifestEntry(projectRoot, manifestEntries, runtimeKey, tool, executablePath, inspection) {
369
- const entry = manifestEntries.find((candidate) => candidate.tool === tool);
370
- if (!entry) {
371
- throw new Error(`Agent CLI manifest is missing ${runtimeKey}/${tool}`);
372
- }
373
- const expectedPath = relativeFromProjectRoot(projectRoot, executablePath);
374
- if (entry.path !== expectedPath) {
375
- throw new Error(
376
- `Agent CLI manifest path mismatch for ${runtimeKey}/${tool}: expected ${expectedPath}, found ${entry.path}`
377
- );
378
- }
379
- if (entry.sha256 !== inspection.sha256) {
380
- throw new Error(`Agent CLI manifest hash mismatch for ${runtimeKey}/${tool}`);
381
- }
382
- if (entry.size !== inspection.size) {
383
- throw new Error(`Agent CLI manifest size mismatch for ${runtimeKey}/${tool}`);
384
- }
385
- if (entry.fileOutput !== inspection.fileOutput) {
386
- throw new Error(`Agent CLI manifest file output mismatch for ${runtimeKey}/${tool}`);
387
- }
388
- }
389
- function assertExecutable(filePath, label) {
390
- if (!existsSync(filePath)) {
391
- throw new Error(`Missing ${label}: ${filePath}`);
392
- }
393
- const stat = statSync(filePath);
394
- if (!stat.isFile()) {
395
- throw new Error(`Expected ${label} to be a regular file: ${filePath}`);
396
- }
397
- if ((stat.mode & 73) === 0) {
398
- throw new Error(`Expected ${label} to be executable: ${filePath}`);
399
- }
400
- }
401
- function getExecutableFileOutput(projectRoot, filePath, label, fileFormat, fileArch) {
402
- const fileOutput = execFileSync("file", ["-L", relativeFromProjectRoot(projectRoot, filePath)], {
403
- cwd: projectRoot,
404
- encoding: "utf8",
405
- timeout: VERIFY_TIMEOUT_MS,
406
- stdio: ["ignore", "pipe", "pipe"]
407
- }).trim();
408
- const hasExpectedFormat = fileFormat === "Mach-O 64-bit executable" ? fileOutput.includes("Mach-O 64-bit") && fileOutput.includes("executable") : fileOutput.includes(fileFormat);
409
- if (!hasExpectedFormat || !fileOutput.includes(fileArch)) {
410
- throw new Error(`Unexpected ${label} architecture: ${fileOutput}`);
411
- }
412
- return fileOutput;
413
- }
414
- function validateStagedAgentClis(options = {}) {
415
- const log = options.log ?? console.log;
416
- const projectRoot = options.projectRoot ?? defaultProjectRoot;
417
- const manifestPath = resolveAgentCliManifestPath(projectRoot);
418
- if (!existsSync(manifestPath)) {
419
- throw new Error(`Missing staged agent CLI manifest: ${manifestPath}`);
420
- }
421
- const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
422
- const runtimeKeys = options.runtimeKey ? [options.runtimeKey] : AGENT_CLI_TARGETS.map((target) => target.runtimeKey);
423
- for (const runtimeKey of runtimeKeys) {
424
- const target = AGENT_CLI_TARGETS.find((item) => item.runtimeKey === runtimeKey);
425
- if (!target) throw new Error(`Unsupported agent CLI runtime key: ${runtimeKey}`);
426
- const manifestEntries = manifest.targets.filter((entry) => entry.runtimeKey === runtimeKey);
427
- const codexEntry = manifestEntries.find((entry) => entry.tool === "codex");
428
- if (!codexEntry) {
429
- throw new Error(`Agent CLI manifest is missing ${runtimeKey}/codex`);
430
- }
431
- assertCodexAppServerCompatible(codexEntry.source.version, `${runtimeKey}/codex`);
432
- const tools = bundledTools(runtimeKey);
433
- for (const tool of tools) {
434
- const executablePath = resolveStagedAgentCliPath(projectRoot, runtimeKey, tool);
435
- const inspection = inspectStaticExecutable(
436
- projectRoot,
437
- executablePath,
438
- `${runtimeKey}/${tool}`,
439
- target.fileFormat,
440
- target.fileArch
441
- );
442
- assertManifestEntry(
443
- projectRoot,
444
- manifestEntries,
445
- runtimeKey,
446
- tool,
447
- executablePath,
448
- inspection
449
- );
450
- }
451
- if (manifestEntries.length !== tools.length) {
452
- throw new Error(
453
- `Agent CLI manifest expected ${tools.length} entries for ${runtimeKey}, found ${manifestEntries.length}`
454
- );
455
- }
456
- if (!existsSync(
457
- path2.join(
458
- path2.dirname(resolveStagedAgentCliPath(projectRoot, runtimeKey, "codex")),
459
- "codex-runtime",
460
- "codex-package.json"
461
- )
462
- )) {
463
- throw new Error(`Missing Codex package metadata for ${runtimeKey}`);
464
- }
465
- if (options.verifyRunnable === true && shouldVerifyRuntimeKey(runtimeKey)) {
466
- for (const tool of ["codex", "claude"]) {
467
- const executablePath = resolveStagedAgentCliPath(projectRoot, runtimeKey, tool);
468
- const version = verifyStagedAgentCliVersion(tool, executablePath);
469
- log(`\u2713 ${runtimeKey}/${tool} ${version}`);
470
- }
471
- }
472
- }
473
- log(`\u2713 Staged agent CLIs ready (${runtimeKeys.join(", ")})`);
474
- return manifest;
475
- }
476
-
477
- // ../../scripts/runtime/native-runtime.ts
478
- import { execFileSync as execFileSync2, spawnSync as spawnSync2 } from "node:child_process";
479
- import { createHash as createHash2 } from "node:crypto";
480
- import {
481
- chmodSync as chmodSync2,
482
- existsSync as existsSync2,
483
- mkdirSync as mkdirSync2,
484
- readdirSync,
485
- readFileSync as readFileSync2,
486
- rmSync as rmSync2,
487
- statSync as statSync2,
488
- writeFileSync as writeFileSync2
489
- } from "node:fs";
490
- import path3 from "node:path";
491
- import { fileURLToPath as fileURLToPath2 } from "node:url";
492
- var runtimeDir2 = path3.dirname(fileURLToPath2(import.meta.url));
493
- var defaultProjectRoot2 = path3.resolve(runtimeDir2, "../..");
494
- var VERIFY_TIMEOUT_MS2 = 2e4;
495
- var VERIFY_STOP_TIMEOUT_MS = 5e3;
496
- var MAC_CODESIGN_PAGE_SIZE = "4096";
497
- var SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([".cjs", ".js", ".json", ".mjs", ".ts", ".tsx"]);
498
- var IGNORED_SOURCE_DIRS = /* @__PURE__ */ new Set([
499
- ".git",
500
- ".turbo",
501
- "coverage",
502
- "dist",
503
- "node_modules",
504
- "out",
505
- "test",
506
- "tests",
507
- "__tests__"
508
- ]);
509
- var REQUIRED_RUNTIME_ENTITLEMENTS = [
510
- "com.apple.security.cs.allow-jit",
511
- "com.apple.security.cs.allow-unsigned-executable-memory",
512
- "com.apple.security.cs.disable-library-validation"
513
- ];
514
- var VERSION_CHECK_ENV_DENYLIST2 = [
515
- "AGENT_SERVER_CWD",
516
- "AGENT_SERVER_ENTRY",
517
- "AUTH_TOKEN",
518
- "BUN_OPTIONS",
519
- "DATABASE_PATH",
520
- "DEUS_AUTH_TOKEN",
521
- "DEUS_BACKEND_PORT",
522
- "DEUS_BUNDLED_BIN_DIR",
523
- "DEUS_DATA_DIR",
524
- "DEUS_PACKAGED",
525
- "DEUS_RESOURCES_PATH",
526
- "DEUS_RUNTIME",
527
- "DEUS_RUNTIME_COMMAND",
528
- "DEUS_RUNTIME_EXECUTABLE",
529
- "ELECTRON_RUN_AS_NODE",
530
- "NODE_PATH",
531
- "PORT"
532
- ];
533
- var DEUS_RUNTIME_TARGETS = [
534
- {
535
- runtimeKey: "darwin-arm64",
536
- platform: "darwin",
537
- bunTarget: "bun-darwin-arm64",
538
- fileArch: "arm64"
539
- },
540
- {
541
- runtimeKey: "darwin-x64",
542
- platform: "darwin",
543
- bunTarget: "bun-darwin-x64",
544
- fileArch: "x86_64"
545
- },
546
- {
547
- runtimeKey: "linux-x64",
548
- platform: "linux",
549
- bunTarget: "bun-linux-x64",
550
- fileArch: "x86-64"
551
- }
552
- ];
553
- function relativeFromProjectRoot2(projectRoot, targetPath) {
554
- return path3.relative(projectRoot, targetPath).split(path3.sep).join("/");
555
- }
556
- function resolveDeusRuntimeManifestPath(projectRoot) {
557
- return path3.join(resolveRuntimeStagePaths(projectRoot).electron.root, "bin", "deus-runtime.json");
558
- }
559
- function resolveStagedDeusRuntimePath(projectRoot, runtimeKey) {
560
- return path3.join(
561
- resolveRuntimeStagePaths(projectRoot).electron.root,
562
- "bin",
563
- runtimeKey,
564
- "deus-runtime"
565
- );
566
- }
567
- function hashFile2(filePath) {
568
- return createHash2("sha256").update(readFileSync2(filePath)).digest("hex");
569
- }
570
- function getHostRuntimeKey() {
571
- if (process.platform === "darwin" && (process.arch === "arm64" || process.arch === "x64")) {
572
- return `darwin-${process.arch}`;
573
- }
574
- if (process.platform === "linux" && process.arch === "x64") {
575
- return "linux-x64";
576
- }
577
- return null;
578
- }
579
- function shouldVerifyRuntimeKey2(runtimeKey) {
580
- return getHostRuntimeKey() === runtimeKey;
581
- }
582
- function canInspectMacBinary(target) {
583
- return target.platform === "darwin" && process.platform === "darwin";
584
- }
585
- function execOutput(command, args, cwd) {
586
- return execFileSync2(command, args, {
587
- cwd,
588
- encoding: "utf8",
589
- timeout: VERIFY_TIMEOUT_MS2,
590
- stdio: ["ignore", "pipe", "pipe"]
591
- }).trim();
592
- }
593
- function spawnErrorCode2(error2) {
594
- return error2?.code ?? error2?.message ?? "none";
595
- }
596
- function diagnosticOutput2(command, args, cwd) {
597
- const result = spawnSync2(command, args, {
598
- cwd,
599
- encoding: "utf8",
600
- timeout: VERIFY_TIMEOUT_MS2,
601
- stdio: ["ignore", "pipe", "pipe"]
602
- });
603
- const output = `${result.stdout || ""}${result.stderr || ""}`.trim();
604
- if (result.error) {
605
- return [spawnErrorCode2(result.error), output].filter(Boolean).join("\n");
606
- }
607
- if (result.status !== 0) return output || `${command} exited with status ${result.status}`;
608
- return output;
609
- }
610
- function runtimeExecutableDiagnostics(executablePath) {
611
- if (process.platform !== "darwin") return "";
612
- const cwd = path3.dirname(executablePath);
613
- return [
614
- `file: ${diagnosticOutput2("file", [executablePath], cwd)}`,
615
- `codesign: ${diagnosticOutput2("codesign", ["-dv", "--verbose=4", executablePath], cwd)}`,
616
- `spctl: ${diagnosticOutput2("spctl", ["--assess", "--type", "execute", "--verbose=4", executablePath], cwd)}`,
617
- `xattr: ${diagnosticOutput2("xattr", ["-l", executablePath], cwd) || "none"}`
618
- ].join("\n");
619
- }
620
- function macExecutionPolicyHint2(diagnostics) {
621
- if (process.platform !== "darwin") return "";
622
- if (!/spctl:[\s\S]*rejected/.test(diagnostics)) return "";
623
- if (!/com\.apple\.(provenance|quarantine)/.test(diagnostics)) return "";
624
- return [
625
- "",
626
- "macOS rejected this executable before --version produced output.",
627
- "Verify runnable staged runtime binaries on a notarized artifact or a macOS host that allows generated Mach-O binaries to launch."
628
- ].join("\n");
629
- }
630
- function readPackageVersion(projectRoot) {
631
- const packageJsonPath = path3.join(projectRoot, "package.json");
632
- const packageJson = JSON.parse(readFileSync2(packageJsonPath, "utf8"));
633
- if (typeof packageJson.version !== "string" || packageJson.version.length === 0) {
634
- throw new Error(`package.json is missing a string version: ${packageJsonPath}`);
635
- }
636
- return packageJson.version;
637
- }
638
- function latestSourceMtime(projectRoot, sourceRelatives) {
639
- let latest = { mtimeMs: 0, path: null };
640
- function visit(sourcePath) {
641
- if (!existsSync2(sourcePath)) return;
642
- const stat = statSync2(sourcePath);
643
- if (stat.isDirectory()) {
644
- for (const entry of readdirSync(sourcePath, { withFileTypes: true })) {
645
- if (IGNORED_SOURCE_DIRS.has(entry.name)) continue;
646
- visit(path3.join(sourcePath, entry.name));
647
- }
648
- return;
649
- }
650
- if (!SOURCE_EXTENSIONS.has(path3.extname(sourcePath))) return;
651
- if (stat.mtimeMs > latest.mtimeMs) {
652
- latest = { mtimeMs: stat.mtimeMs, path: sourcePath };
653
- }
654
- }
655
- for (const sourceRelative of sourceRelatives) {
656
- visit(path3.join(projectRoot, sourceRelative));
657
- }
658
- return latest;
659
- }
660
- function assertRuntimeFresh(projectRoot, executablePath, runtimeKey) {
661
- const latestSource = latestSourceMtime(projectRoot, [
662
- "apps/runtime",
663
- "apps/backend/src",
664
- "apps/agent-server",
665
- "shared",
666
- "resources/entitlements.runtime.plist"
667
- ]);
668
- if (!latestSource.path) return;
669
- if (statSync2(executablePath).mtimeMs >= latestSource.mtimeMs) return;
670
- throw new Error(
671
- `${runtimeKey}/deus-runtime is stale: ${relativeFromProjectRoot2(
672
- projectRoot,
673
- executablePath
674
- )} is older than ${relativeFromProjectRoot2(projectRoot, latestSource.path)}. Run \`bun run build:runtime\` before packaging.`
675
- );
676
- }
677
- function assertExecutable2(filePath, label) {
678
- if (!existsSync2(filePath)) {
679
- throw new Error(`Missing ${label}: ${filePath}`);
680
- }
681
- const stat = statSync2(filePath);
682
- if (!stat.isFile()) {
683
- throw new Error(`Expected ${label} to be a regular file: ${filePath}`);
684
- }
685
- if ((stat.mode & 73) === 0) {
686
- throw new Error(`Expected ${label} to be executable: ${filePath}`);
687
- }
688
- }
689
- function assertFileArch(fileOutput, target, filePath) {
690
- const hasExpectedFormat = target.platform === "darwin" ? fileOutput.includes("Mach-O 64-bit") && fileOutput.includes("executable") : fileOutput.includes("ELF 64-bit");
691
- if (!hasExpectedFormat || !fileOutput.includes(target.fileArch)) {
692
- throw new Error(`Unexpected file(1) output for ${filePath}: ${fileOutput}`);
693
- }
694
- }
695
- function verifyMacCodeSignature(filePath) {
696
- if (process.platform !== "darwin") return;
697
- const result = spawnSync2("codesign", ["--verify", "--verbose=2", filePath], {
698
- encoding: "utf8",
699
- stdio: ["ignore", "pipe", "pipe"]
700
- });
701
- if (result.status !== 0) {
702
- throw new Error(`Invalid code signature for ${filePath}: ${result.stderr || result.stdout}`);
703
- }
704
- }
705
- function verifyMacCodeSignaturePageSize(filePath) {
706
- if (process.platform !== "darwin") return;
707
- const result = spawnSync2("codesign", ["-dv", "--verbose=4", filePath], {
708
- encoding: "utf8",
709
- stdio: ["ignore", "pipe", "pipe"]
710
- });
711
- if (result.status !== 0) {
712
- throw new Error(
713
- `Unable to inspect code signature for ${filePath}: ${result.stderr || result.stdout}`
714
- );
715
- }
716
- const output = `${result.stdout}
717
- ${result.stderr}`;
718
- if (!output.includes(`Page size=${MAC_CODESIGN_PAGE_SIZE}`)) {
719
- throw new Error(
720
- `Unexpected code signature page size for ${filePath}; expected ${MAC_CODESIGN_PAGE_SIZE}`
721
- );
722
- }
723
- }
724
- function readMacEntitlements(filePath) {
725
- const result = spawnSync2("codesign", ["-d", "--entitlements", ":-", filePath], {
726
- encoding: "utf8",
727
- stdio: ["ignore", "pipe", "pipe"]
728
- });
729
- if (result.status !== 0) {
730
- throw new Error(
731
- `Unable to read entitlements for ${filePath}: ${result.stderr || result.stdout}`
732
- );
733
- }
734
- return `${result.stdout}
735
- ${result.stderr}`;
736
- }
737
- function verifyMacSystemDylibs(otoolOutput, filePath) {
738
- if (process.platform !== "darwin") return;
739
- const unexpected = otoolOutput.split(/\r?\n/).slice(1).map((line) => line.trim().split(/\s+/)[0]).filter(Boolean).filter(
740
- (dependency) => !dependency.startsWith("/usr/lib/") && !dependency.startsWith("/System/Library/")
741
- );
742
- if (unexpected.length > 0) {
743
- throw new Error(
744
- `Unexpected non-system dylib dependency for ${filePath}: ${unexpected.join(", ")}`
745
- );
746
- }
747
- }
748
- function verifyMacRuntimeEntitlements(filePath) {
749
- if (process.platform !== "darwin") return;
750
- const entitlements = readMacEntitlements(filePath);
751
- for (const entitlement of REQUIRED_RUNTIME_ENTITLEMENTS) {
752
- if (!entitlements.includes(entitlement)) {
753
- throw new Error(`Missing ${entitlement} entitlement for ${filePath}`);
754
- }
755
- }
756
- }
757
- function verifyStagedDeusRuntimeVersion(executablePath) {
758
- const helperPath = path3.join(runtimeDir2, "smoke", "run-version-check.cjs");
759
- const env = { ...process.env };
760
- for (const key of VERSION_CHECK_ENV_DENYLIST2) {
761
- delete env[key];
762
- }
763
- env.DEUS_VERSION_CHECK_TIMEOUT_MS = String(VERIFY_TIMEOUT_MS2);
764
- env.DEUS_VERSION_CHECK_STOP_TIMEOUT_MS = String(VERIFY_STOP_TIMEOUT_MS);
765
- const result = spawnSync2(process.execPath, [helperPath, executablePath, "--version"], {
766
- encoding: "utf8",
767
- timeout: VERIFY_TIMEOUT_MS2 + VERIFY_STOP_TIMEOUT_MS + 5e3,
768
- env,
769
- stdio: ["ignore", "pipe", "pipe"]
770
- });
771
- const rawOutput = (result.stdout || "").trim();
772
- let checkResult;
773
- try {
774
- checkResult = JSON.parse(rawOutput);
775
- } catch {
776
- checkResult = {
777
- ok: false,
778
- status: result.status,
779
- signal: result.signal,
780
- error: spawnErrorCode2(result.error),
781
- stdout: rawOutput,
782
- stderr: (result.stderr || "").trim()
783
- };
784
- }
785
- const output = (checkResult.stdout || "").trim();
786
- if (result.status !== 0) {
787
- const stderr = [checkResult.stderr, result.stderr].filter(Boolean).join("\n").trim();
788
- const diagnostics = runtimeExecutableDiagnostics(executablePath);
789
- const hint2 = macExecutionPolicyHint2(diagnostics);
790
- throw new Error(
791
- `deus-runtime --version failed for ${executablePath}: status=${result.status} signal=${result.signal} error=${checkResult.error ?? spawnErrorCode2(result.error)} timedOut=${checkResult.timedOut === true} stdout=${output} stderr=${stderr}${diagnostics ? `
792
- ${diagnostics}` : ""}${hint2}`
793
- );
794
- }
795
- if (!/^deus-runtime \d+\.\d+\.\d+ /.test(output)) {
796
- throw new Error(`Unexpected deus-runtime --version output for ${executablePath}: ${output}`);
797
- }
798
- return output;
799
- }
800
- function validateDeusRuntime(options = {}) {
801
- const log = options.log ?? console.log;
802
- const projectRoot = options.projectRoot ?? defaultProjectRoot2;
803
- const manifestPath = resolveDeusRuntimeManifestPath(projectRoot);
804
- if (!existsSync2(manifestPath)) {
805
- throw new Error(`Missing native runtime manifest: ${manifestPath}`);
806
- }
807
- const manifest = JSON.parse(readFileSync2(manifestPath, "utf8"));
808
- const packageVersion = readPackageVersion(projectRoot);
809
- if (manifest.packageVersion !== packageVersion) {
810
- throw new Error(
811
- `Native runtime manifest package version mismatch: expected ${packageVersion}, found ${manifest.packageVersion ?? "missing"}. Run \`bun run build:runtime\` before packaging.`
812
- );
813
- }
814
- const runtimeKeys = options.runtimeKey ? [options.runtimeKey] : DEUS_RUNTIME_TARGETS.map((target) => target.runtimeKey);
815
- for (const runtimeKey of runtimeKeys) {
816
- const target = DEUS_RUNTIME_TARGETS.find((item) => item.runtimeKey === runtimeKey);
817
- if (!target) throw new Error(`Unsupported native runtime key: ${runtimeKey}`);
818
- const executablePath = resolveStagedDeusRuntimePath(projectRoot, runtimeKey);
819
- assertExecutable2(executablePath, `${runtimeKey}/deus-runtime`);
820
- assertRuntimeFresh(projectRoot, executablePath, runtimeKey);
821
- const manifestEntry = manifest.entries.find((entry) => entry.runtimeKey === runtimeKey);
822
- if (!manifestEntry) throw new Error(`Native runtime manifest is missing ${runtimeKey}`);
823
- const expectedPath = relativeFromProjectRoot2(projectRoot, executablePath);
824
- if (manifestEntry.path !== expectedPath) {
825
- throw new Error(
826
- `Native runtime manifest path mismatch for ${runtimeKey}: expected ${expectedPath}, found ${manifestEntry.path}`
827
- );
828
- }
829
- if (manifestEntry.sha256 !== hashFile2(executablePath)) {
830
- throw new Error(`Native runtime manifest hash mismatch for ${runtimeKey}`);
831
- }
832
- const manifestCommandPath = relativeFromProjectRoot2(projectRoot, executablePath);
833
- const fileOutput = execOutput("file", [manifestCommandPath], projectRoot);
834
- assertFileArch(fileOutput, target, executablePath);
835
- const otoolOutput = canInspectMacBinary(target) ? execOutput("otool", ["-L", manifestCommandPath], projectRoot) : void 0;
836
- if (otoolOutput) verifyMacSystemDylibs(otoolOutput, executablePath);
837
- if (manifestEntry.size !== statSync2(executablePath).size) {
838
- throw new Error(`Native runtime manifest size mismatch for ${runtimeKey}`);
839
- }
840
- if (manifestEntry.fileOutput !== fileOutput) {
841
- throw new Error(`Native runtime manifest file output mismatch for ${runtimeKey}`);
842
- }
843
- if (manifestEntry.otoolOutput !== otoolOutput) {
844
- throw new Error(`Native runtime manifest otool output mismatch for ${runtimeKey}`);
845
- }
846
- if (canInspectMacBinary(target)) {
847
- verifyMacCodeSignature(executablePath);
848
- verifyMacCodeSignaturePageSize(executablePath);
849
- verifyMacRuntimeEntitlements(executablePath);
850
- }
851
- if (options.verifyRunnable === true && shouldVerifyRuntimeKey2(runtimeKey)) {
852
- const version = verifyStagedDeusRuntimeVersion(executablePath);
853
- log(`\u2713 ${runtimeKey}/deus-runtime ${version}`);
854
- }
855
- }
856
- log(`\u2713 Native runtime ready (${runtimeKeys.join(", ")})`);
857
- return manifest;
858
- }
859
-
860
- // ../../scripts/runtime/validate.ts
861
- var runtimeDir3 = path4.dirname(fileURLToPath3(import.meta.url));
862
- var defaultProjectRoot3 = path4.resolve(runtimeDir3, "../..");
863
- var BUILD_RUNTIME_COMMAND = "bun run build:runtime";
864
- function relativeFromProjectRoot3(projectRoot, targetPath) {
865
- return path4.relative(projectRoot, targetPath).split(path4.sep).join("/");
866
- }
867
- function createBuildRuntimeError(message) {
868
- return new Error(`${message}
869
- Run \`${BUILD_RUNTIME_COMMAND}\` before packaging.`);
870
- }
871
- function readManifest(manifestPath) {
872
- try {
873
- return JSON.parse(readFileSync3(manifestPath, "utf8"));
874
- } catch (error2) {
875
- throw createBuildRuntimeError(
876
- `Unable to read staged runtime manifest at ${manifestPath}: ${error2 instanceof Error ? error2.message : String(error2)}`
877
- );
878
- }
879
- }
880
- function hashFile3(filePath) {
881
- return createHash3("sha256").update(readFileSync3(filePath)).digest("hex");
882
- }
883
- function ghArchiveName(version, archivePlatform, extension = "zip") {
884
- return `gh_${version}_${archivePlatform}.${extension}`;
885
- }
886
- function readGhCliContract(projectRoot) {
887
- const contractPath = path4.join(projectRoot, "scripts", "runtime", "gh-cli-contract.json");
888
- try {
889
- const contract = JSON.parse(readFileSync3(contractPath, "utf8"));
890
- if (typeof contract.ghVersion !== "string" || !Array.isArray(contract.targets)) {
891
- throw new Error("unexpected contract shape");
892
- }
893
- return contract;
894
- } catch (error2) {
895
- throw createBuildRuntimeError(
896
- `Unable to read GitHub CLI contract at ${contractPath}: ${error2 instanceof Error ? error2.message : String(error2)}`
897
- );
898
- }
899
- }
900
- function assertExists(filePath, label) {
901
- if (!existsSync3(filePath)) {
902
- throw createBuildRuntimeError(`Missing ${label}: ${filePath}`);
903
- }
904
- }
905
- function assertExecutable3(filePath, label) {
906
- assertExists(filePath, label);
907
- const stat = statSync3(filePath);
908
- if (!stat.isFile()) {
909
- throw createBuildRuntimeError(`Expected ${label} to be a regular file: ${filePath}`);
910
- }
911
- if ((stat.mode & 73) === 0) {
912
- throw createBuildRuntimeError(`Expected ${label} to be executable: ${filePath}`);
913
- }
914
- }
915
- function getExecutableFileOutput2(projectRoot, filePath, label, fileFormat, fileArch) {
916
- const fileOutput = execFileSync3("file", [relativeFromProjectRoot3(projectRoot, filePath)], {
917
- cwd: projectRoot,
918
- encoding: "utf8",
919
- timeout: 2e4,
920
- stdio: ["ignore", "pipe", "pipe"]
921
- }).trim();
922
- const hasExpectedFormat = fileFormat === "Mach-O 64-bit executable" ? fileOutput.includes("Mach-O 64-bit") && fileOutput.includes("executable") : fileOutput.includes(fileFormat);
923
- if (!hasExpectedFormat || !fileOutput.includes(fileArch)) {
924
- throw createBuildRuntimeError(`Unexpected ${label} architecture: ${fileOutput}`);
925
- }
926
- return fileOutput;
927
- }
928
- function verifyMacCodeSignature2(filePath, label) {
929
- if (process.platform !== "darwin" || !label.startsWith("darwin-")) return;
930
- try {
931
- execFileSync3("codesign", ["--verify", "--verbose=2", filePath], {
932
- encoding: "utf8",
933
- timeout: 2e4,
934
- stdio: ["ignore", "ignore", "pipe"]
935
- });
936
- } catch (error2) {
937
- throw createBuildRuntimeError(
938
- `Invalid ${label} code signature: ${error2 instanceof Error ? error2.message : String(error2)}`
939
- );
940
- }
941
- }
942
- function assertStagedGhCli(projectRoot) {
943
- const binRoot = path4.join(resolveRuntimeStagePaths(projectRoot).electron.root, "bin");
944
- const manifestPath = path4.join(binRoot, "gh-cli.json");
945
- assertExists(manifestPath, "staged GitHub CLI manifest");
946
- const manifest = JSON.parse(readFileSync3(manifestPath, "utf8"));
947
- if (manifest.version !== 1 || !Array.isArray(manifest.targets)) {
948
- throw createBuildRuntimeError(`Unexpected staged GitHub CLI manifest shape: ${manifestPath}`);
949
- }
950
- const contract = readGhCliContract(projectRoot);
951
- if (manifest.ghVersion !== contract.ghVersion) {
952
- throw createBuildRuntimeError(
953
- `GitHub CLI manifest version mismatch: expected ${contract.ghVersion}, found ${manifest.ghVersion}`
954
- );
955
- }
956
- for (const target of contract.targets) {
957
- const ghPath = path4.join(binRoot, target.runtimeKey, "gh");
958
- const label = `${target.runtimeKey}/gh`;
959
- assertExecutable3(ghPath, label);
960
- const fileOutput = getExecutableFileOutput2(
961
- projectRoot,
962
- ghPath,
963
- label,
964
- target.fileFormat ?? "Mach-O 64-bit executable",
965
- target.fileArch
966
- );
967
- verifyMacCodeSignature2(ghPath, label);
968
- const manifestEntry = manifest.targets.find(
969
- (entry) => entry.runtimeKey === target.runtimeKey && entry.tool === "gh"
970
- );
971
- if (!manifestEntry) {
972
- throw createBuildRuntimeError(`GitHub CLI manifest is missing ${target.runtimeKey}/gh`);
973
- }
974
- const expectedPath = relativeFromProjectRoot3(projectRoot, ghPath);
975
- if (manifestEntry.path !== expectedPath) {
976
- throw createBuildRuntimeError(
977
- `GitHub CLI manifest path mismatch for ${target.runtimeKey}/gh: expected ${expectedPath}, found ${manifestEntry.path}`
978
- );
979
- }
980
- if (manifestEntry.sha256 !== hashFile3(ghPath)) {
981
- throw createBuildRuntimeError(`GitHub CLI manifest hash mismatch for ${target.runtimeKey}/gh`);
982
- }
983
- if (manifestEntry.size !== statSync3(ghPath).size) {
984
- throw createBuildRuntimeError(`GitHub CLI manifest size mismatch for ${target.runtimeKey}/gh`);
985
- }
986
- if (manifestEntry.fileOutput !== fileOutput) {
987
- throw createBuildRuntimeError(
988
- `GitHub CLI manifest file output mismatch for ${target.runtimeKey}/gh`
989
- );
990
- }
991
- const archiveName = ghArchiveName(
992
- contract.ghVersion,
993
- target.archivePlatform,
994
- target.archiveExtension
995
- );
996
- const expectedUrl = `https://github.com/cli/cli/releases/download/v${contract.ghVersion}/${archiveName}`;
997
- const source = manifestEntry.source;
998
- if (!source || source.version !== contract.ghVersion || source.archiveName !== archiveName || source.archiveSha256 !== target.archiveSha256 || source.url !== expectedUrl) {
999
- throw createBuildRuntimeError(
1000
- `GitHub CLI manifest source mismatch for ${target.runtimeKey}/gh`
1001
- );
1002
- }
1003
- }
1004
- }
1005
- function assertPackagedProviderBinaries(projectRoot) {
1006
- try {
1007
- validateDeusRuntime({
1008
- projectRoot,
1009
- log: () => void 0,
1010
- verifyRunnable: process.env.DEUS_VERIFY_RUNTIME_RUNNABLE === "1"
1011
- });
1012
- } catch (error2) {
1013
- throw createBuildRuntimeError(
1014
- `Native runtime validation failed: ${error2 instanceof Error ? error2.message : String(error2)}`
1015
- );
1016
- }
1017
- try {
1018
- validateStagedAgentClis({ projectRoot, log: () => void 0, verifyRunnable: false });
1019
- } catch (error2) {
1020
- throw createBuildRuntimeError(
1021
- `Staged agent CLI validation failed: ${error2 instanceof Error ? error2.message : String(error2)}`
1022
- );
1023
- }
1024
- assertStagedGhCli(projectRoot);
1025
- }
1026
- function assertNotStale(projectRoot, filePath, label, sourcePath, sourceLabel) {
1027
- if (statSync3(filePath).mtimeMs < statSync3(sourcePath).mtimeMs) {
1028
- throw createBuildRuntimeError(
1029
- `${label} is stale: ${relativeFromProjectRoot3(projectRoot, filePath)} is older than ${relativeFromProjectRoot3(projectRoot, sourcePath)} (${sourceLabel})`
1030
- );
1031
- }
1032
- }
1033
- function buildExpectedManifest(projectRoot) {
1034
- const stagePaths = resolveRuntimeStagePaths(projectRoot);
1035
- return {
1036
- version: RUNTIME_MANIFEST_VERSION,
1037
- appId: DEUS_APP_ID,
1038
- data: {
1039
- databaseFile: DEUS_DB_FILENAME,
1040
- preferencesFile: DEUS_PREFERENCES_FILENAME
1041
- },
1042
- bundles: {
1043
- common: {
1044
- backend: relativeFromProjectRoot3(projectRoot, stagePaths.common.backendBundle),
1045
- agentServer: relativeFromProjectRoot3(projectRoot, stagePaths.common.agentServerBundle)
1046
- }
1047
- },
1048
- nodeRuntimeDependencies: CLI_RUNTIME_DEPENDENCIES
1049
- };
1050
- }
1051
- function validateRuntimeStage(options = {}) {
1052
- const log = options.log ?? console.log;
1053
- const projectRoot = options.projectRoot ?? defaultProjectRoot3;
1054
- const stagePaths = resolveRuntimeStagePaths(projectRoot);
1055
- const sources = {
1056
- backendBundle: path4.join(projectRoot, "apps", "backend", "dist", "server.bundled.cjs"),
1057
- agentServerBundle: path4.join(projectRoot, "apps", "agent-server", "dist", "index.bundled.cjs")
1058
- };
1059
- assertExists(sources.backendBundle, "runtime source bundle (backend)");
1060
- assertExists(sources.agentServerBundle, "runtime source bundle (agent-server)");
1061
- assertExists(stagePaths.manifest, "staged runtime manifest");
1062
- assertExists(stagePaths.common.backendBundle, "staged common backend bundle");
1063
- assertExists(stagePaths.common.agentServerBundle, "staged common agent-server bundle");
1064
- const manifest = readManifest(stagePaths.manifest);
1065
- const expectedManifest = buildExpectedManifest(projectRoot);
1066
- if (JSON.stringify(manifest) !== JSON.stringify(expectedManifest)) {
1067
- throw createBuildRuntimeError(
1068
- `Staged runtime manifest at ${stagePaths.manifest} does not match the current runtime contract`
1069
- );
1070
- }
1071
- assertNotStale(
1072
- projectRoot,
1073
- stagePaths.common.backendBundle,
1074
- "staged common backend bundle",
1075
- sources.backendBundle,
1076
- "backend source bundle"
1077
- );
1078
- assertNotStale(
1079
- projectRoot,
1080
- stagePaths.common.agentServerBundle,
1081
- "staged common agent-server bundle",
1082
- sources.agentServerBundle,
1083
- "agent-server source bundle"
1084
- );
1085
- const latestSourceMtime2 = Math.max(
1086
- statSync3(sources.backendBundle).mtimeMs,
1087
- statSync3(sources.agentServerBundle).mtimeMs
1088
- );
1089
- if (statSync3(stagePaths.manifest).mtimeMs < latestSourceMtime2) {
1090
- throw createBuildRuntimeError(
1091
- `Staged runtime manifest is stale: ${relativeFromProjectRoot3(projectRoot, stagePaths.manifest)} is older than the source bundles`
1092
- );
1093
- }
1094
- assertPackagedProviderBinaries(projectRoot);
1095
- log(
1096
- `\u2713 Staged runtime ready for packaging (${relativeFromProjectRoot3(projectRoot, stagePaths.root)})`
1097
- );
1098
- return manifest;
1099
- }
1100
- var entryPath = process.argv[1] ? path4.resolve(process.argv[1]) : null;
1101
- if (entryPath === fileURLToPath3(import.meta.url)) {
1102
- try {
1103
- validateRuntimeStage();
1104
- } catch (error2) {
1105
- console.error("Runtime validation failed:", error2);
1106
- process.exit(1);
1107
- }
1108
- }
1109
-
1110
126
  // src/ui.ts
1111
127
  var ESC = "\x1B[";
1112
128
  var RESET = `${ESC}0m`;
@@ -1461,13 +477,13 @@ function sleep(ms) {
1461
477
 
1462
478
  // src/config.ts
1463
479
  import {
1464
- readFileSync as readFileSync4,
1465
- writeFileSync as writeFileSync3,
1466
- existsSync as existsSync4,
480
+ readFileSync,
481
+ writeFileSync,
482
+ existsSync,
1467
483
  unlinkSync,
1468
484
  renameSync,
1469
- mkdirSync as mkdirSync3,
1470
- chmodSync as chmodSync3
485
+ mkdirSync,
486
+ chmodSync
1471
487
  } from "node:fs";
1472
488
  import { join } from "node:path";
1473
489
  import { homedir, platform } from "node:os";
@@ -1494,10 +510,10 @@ function getServerInfoPath() {
1494
510
  return join(getConfigDir(), "server.json");
1495
511
  }
1496
512
  function loadConfig() {
1497
- const path5 = getConfigPath();
1498
- if (!existsSync4(path5)) return { ...DEFAULT_CONFIG };
513
+ const path2 = getConfigPath();
514
+ if (!existsSync(path2)) return { ...DEFAULT_CONFIG };
1499
515
  try {
1500
- const raw = readFileSync4(path5, "utf-8");
516
+ const raw = readFileSync(path2, "utf-8");
1501
517
  const parsed = JSON.parse(raw);
1502
518
  return { ...DEFAULT_CONFIG, ...parsed };
1503
519
  } catch {
@@ -1506,19 +522,19 @@ function loadConfig() {
1506
522
  }
1507
523
  function saveConfig(config) {
1508
524
  const dir = getConfigDir();
1509
- mkdirSync3(dir, { recursive: true });
1510
- const path5 = getConfigPath();
1511
- const tmp = path5 + ".tmp." + randomBytes(4).toString("hex");
525
+ mkdirSync(dir, { recursive: true });
526
+ const path2 = getConfigPath();
527
+ const tmp = path2 + ".tmp." + randomBytes(4).toString("hex");
1512
528
  try {
1513
- writeFileSync3(tmp, JSON.stringify(config, null, 2) + "\n", "utf-8");
1514
- chmodSync3(tmp, 384);
1515
- renameSync(tmp, path5);
529
+ writeFileSync(tmp, JSON.stringify(config, null, 2) + "\n", "utf-8");
530
+ chmodSync(tmp, 384);
531
+ renameSync(tmp, path2);
1516
532
  } catch {
1517
533
  try {
1518
534
  unlinkSync(tmp);
1519
535
  } catch {
1520
536
  }
1521
- throw new Error(`Failed to save config to ${path5}`);
537
+ throw new Error(`Failed to save config to ${path2}`);
1522
538
  }
1523
539
  }
1524
540
  function hasCompletedOnboarding() {
@@ -1526,16 +542,16 @@ function hasCompletedOnboarding() {
1526
542
  }
1527
543
  function writeServerInfo(info2) {
1528
544
  const dir = getConfigDir();
1529
- mkdirSync3(dir, { recursive: true });
1530
- const path5 = getServerInfoPath();
1531
- writeFileSync3(path5, JSON.stringify(info2, null, 2) + "\n", "utf-8");
1532
- chmodSync3(path5, 384);
545
+ mkdirSync(dir, { recursive: true });
546
+ const path2 = getServerInfoPath();
547
+ writeFileSync(path2, JSON.stringify(info2, null, 2) + "\n", "utf-8");
548
+ chmodSync(path2, 384);
1533
549
  }
1534
550
  function readServerInfo() {
1535
- const path5 = getServerInfoPath();
1536
- if (!existsSync4(path5)) return null;
551
+ const path2 = getServerInfoPath();
552
+ if (!existsSync(path2)) return null;
1537
553
  try {
1538
- const raw = readFileSync4(path5, "utf-8");
554
+ const raw = readFileSync(path2, "utf-8");
1539
555
  const info2 = JSON.parse(raw);
1540
556
  try {
1541
557
  process.kill(info2.pid, 0);
@@ -1549,16 +565,16 @@ function readServerInfo() {
1549
565
  }
1550
566
  }
1551
567
  function clearServerInfo() {
1552
- const path5 = getServerInfoPath();
568
+ const path2 = getServerInfoPath();
1553
569
  try {
1554
- unlinkSync(path5);
570
+ unlinkSync(path2);
1555
571
  } catch {
1556
572
  }
1557
573
  }
1558
574
 
1559
575
  // src/login.ts
1560
- import { execSync, spawnSync as spawnSync3 } from "node:child_process";
1561
- import { existsSync as existsSync5 } from "node:fs";
576
+ import { execSync, spawnSync } from "node:child_process";
577
+ import { existsSync as existsSync2 } from "node:fs";
1562
578
  import { join as join2 } from "node:path";
1563
579
  import { homedir as homedir2, platform as platform2 } from "node:os";
1564
580
 
@@ -1773,7 +789,7 @@ function getClaudeCliCandidates() {
1773
789
  }
1774
790
  function detectClaudeCli() {
1775
791
  for (const candidate of getClaudeCliCandidates()) {
1776
- if (existsSync5(candidate)) {
792
+ if (existsSync2(candidate)) {
1777
793
  try {
1778
794
  const version = execSync(`node "${candidate}" --version`, {
1779
795
  encoding: "utf-8",
@@ -1817,7 +833,7 @@ function isClaudeAuthenticated() {
1817
833
  join2(homedir2(), ".claude", "credentials.json")
1818
834
  ];
1819
835
  for (const p of credPaths) {
1820
- if (existsSync5(p)) return true;
836
+ if (existsSync2(p)) return true;
1821
837
  }
1822
838
  return false;
1823
839
  }
@@ -1901,7 +917,7 @@ async function runClaudeLogin(cliPath) {
1901
917
  blank();
1902
918
  hint("Opening browser for authentication...");
1903
919
  blank();
1904
- const result = spawnSync3(cliPath, ["login"], {
920
+ const result = spawnSync(cliPath, ["login"], {
1905
921
  stdio: "inherit",
1906
922
  timeout: 12e4
1907
923
  });
@@ -1921,7 +937,7 @@ async function runClaudeLogin(cliPath) {
1921
937
  async function installAndLogin() {
1922
938
  blank();
1923
939
  const s = spinner("Installing Claude Code CLI...");
1924
- const result = spawnSync3("npm", ["install", "-g", "@anthropic-ai/claude-code"], {
940
+ const result = spawnSync("npm", ["install", "-g", "@anthropic-ai/claude-code"], {
1925
941
  stdio: ["pipe", "pipe", "pipe"],
1926
942
  timeout: 12e4
1927
943
  });
@@ -2391,10 +1407,10 @@ function printQR(data, indent = 4) {
2391
1407
 
2392
1408
  // src/lib/http.ts
2393
1409
  import { request } from "node:http";
2394
- function httpGet(port, path5, timeoutMs = 3e3) {
1410
+ function httpGet(port, path2, timeoutMs = 3e3) {
2395
1411
  return new Promise((resolve2) => {
2396
1412
  const req = request(
2397
- { hostname: "localhost", port, path: path5, method: "GET", timeout: timeoutMs },
1413
+ { hostname: "localhost", port, path: path2, method: "GET", timeout: timeoutMs },
2398
1414
  (res) => {
2399
1415
  let body = "";
2400
1416
  res.on("data", (chunk) => body += chunk.toString());
@@ -2415,14 +1431,14 @@ function httpGet(port, path5, timeoutMs = 3e3) {
2415
1431
  req.end();
2416
1432
  });
2417
1433
  }
2418
- function httpPost(port, path5, body) {
1434
+ function httpPost(port, path2, body) {
2419
1435
  return new Promise((resolve2, reject) => {
2420
1436
  const payload = body ? JSON.stringify(body) : "";
2421
1437
  const req = request(
2422
1438
  {
2423
1439
  hostname: "localhost",
2424
1440
  port,
2425
- path: path5,
1441
+ path: path2,
2426
1442
  method: "POST",
2427
1443
  headers: {
2428
1444
  "Content-Type": "application/json",
@@ -2435,13 +1451,13 @@ function httpPost(port, path5, body) {
2435
1451
  res.on("data", (chunk) => data += chunk.toString());
2436
1452
  res.on("end", () => {
2437
1453
  if (res.statusCode !== 200) {
2438
- reject(new Error(`${path5} returned ${res.statusCode}: ${data}`));
1454
+ reject(new Error(`${path2} returned ${res.statusCode}: ${data}`));
2439
1455
  return;
2440
1456
  }
2441
1457
  try {
2442
1458
  resolve2(JSON.parse(data));
2443
1459
  } catch {
2444
- reject(new Error(`Invalid JSON from ${path5}`));
1460
+ reject(new Error(`Invalid JSON from ${path2}`));
2445
1461
  }
2446
1462
  });
2447
1463
  }
@@ -2449,7 +1465,7 @@ function httpPost(port, path5, body) {
2449
1465
  req.on("error", reject);
2450
1466
  req.on("timeout", () => {
2451
1467
  req.destroy();
2452
- reject(new Error(`Timeout: ${path5}`));
1468
+ reject(new Error(`Timeout: ${path2}`));
2453
1469
  });
2454
1470
  req.end(payload);
2455
1471
  });
@@ -2546,7 +1562,7 @@ async function pair() {
2546
1562
  }
2547
1563
 
2548
1564
  // src/start.ts
2549
- var __filename = fileURLToPath4(import.meta.url);
1565
+ var __filename = fileURLToPath(import.meta.url);
2550
1566
  var __dirname = dirname(__filename);
2551
1567
  async function start(options) {
2552
1568
  const { dataDir } = options;
@@ -2563,7 +1579,16 @@ async function start(options) {
2563
1579
  blank();
2564
1580
  process.exit(1);
2565
1581
  }
2566
- const nodeCmd = resolveNodeBinary();
1582
+ const sqliteFailure = sqliteLoadFailure();
1583
+ if (sqliteFailure) {
1584
+ error(`SQLite (better-sqlite3) does not load under Node ${process.version}: ${sqliteFailure}`);
1585
+ blank();
1586
+ hint(
1587
+ paths.monorepo ? `Run ${c.cyan("bun run native:node")} from the monorepo root, then start again.` : `Reinstall Deus with ${c.cyan("npm install -g deus-machine")}, then start again.`
1588
+ );
1589
+ blank();
1590
+ process.exit(1);
1591
+ }
2567
1592
  const dbPath = resolveDataDir(dataDir);
2568
1593
  kv("Database", c.dim(dbPath));
2569
1594
  blank();
@@ -2597,14 +1622,10 @@ async function start(options) {
2597
1622
  }
2598
1623
  const s1 = spinner("Starting backend...");
2599
1624
  const started = await startBackendProcess({
2600
- command: nodeCmd,
2601
1625
  backendEntry: paths.backend,
2602
1626
  backendCwd: dirname(paths.backend),
2603
- forceElectronRunAsNode: nodeCmd !== process.execPath,
2604
1627
  env: {
2605
1628
  DATABASE_PATH: dbPath,
2606
- AGENT_SERVER_ENTRY: paths.agentServer,
2607
- AGENT_SERVER_CWD: dirname(paths.agentServer),
2608
1629
  PORT: "0",
2609
1630
  ...extraEnv
2610
1631
  },
@@ -2626,7 +1647,6 @@ async function start(options) {
2626
1647
  writeServerInfo({
2627
1648
  pid: process.pid,
2628
1649
  backendPort: port,
2629
- agentServerUrl: "managed-by-backend",
2630
1650
  startedAt: (/* @__PURE__ */ new Date()).toISOString()
2631
1651
  });
2632
1652
  blank();
@@ -2666,27 +1686,24 @@ async function start(options) {
2666
1686
  function resolveBundlePaths() {
2667
1687
  const cliRoot = resolve(__dirname, "..");
2668
1688
  const bundledDir = join3(cliRoot, "bundles");
2669
- if (existsSync6(join3(bundledDir, "agent-server.bundled.cjs"))) {
2670
- return {
2671
- agentServer: join3(bundledDir, "agent-server.bundled.cjs"),
2672
- backend: join3(bundledDir, "server.bundled.cjs")
2673
- };
1689
+ if (existsSync3(join3(bundledDir, "server.bundled.cjs"))) {
1690
+ return { backend: join3(bundledDir, "server.bundled.cjs"), monorepo: false };
2674
1691
  }
2675
1692
  const monorepoRoot = resolve(cliRoot, "../..");
2676
- const runtimePaths = resolveRuntimeStagePaths(monorepoRoot);
1693
+ const backend = resolveRuntimeStagePaths(monorepoRoot).common.backendBundle;
1694
+ if (existsSync3(backend)) return { backend, monorepo: true };
1695
+ warn(`The staged runtime is missing in the monorepo: ${backend} does not exist.`);
1696
+ return null;
1697
+ }
1698
+ function sqliteLoadFailure() {
2677
1699
  try {
2678
- validateRuntimeStage({ projectRoot: monorepoRoot, log: () => {
2679
- } });
2680
- return {
2681
- agentServer: runtimePaths.common.agentServerBundle,
2682
- backend: runtimePaths.common.backendBundle
2683
- };
2684
- } catch (error2) {
2685
- warn(
2686
- `Staged runtime is missing or stale in monorepo mode: ${error2 instanceof Error ? error2.message : String(error2)}`
2687
- );
1700
+ const Database = createRequire(import.meta.url)("better-sqlite3");
1701
+ new Database(":memory:").close();
1702
+ return null;
1703
+ } catch (cause) {
1704
+ const message = cause instanceof Error ? cause.message : String(cause);
1705
+ return message.split("\n")[0];
2688
1706
  }
2689
- return null;
2690
1707
  }
2691
1708
  function resolveDataDir(customDir) {
2692
1709
  const dir = customDir ?? resolveDefaultDataDir({
@@ -2695,42 +1712,16 @@ function resolveDataDir(customDir) {
2695
1712
  appData: process.env.APPDATA,
2696
1713
  xdgDataHome: process.env.XDG_DATA_HOME
2697
1714
  });
2698
- mkdirSync4(dir, { recursive: true });
1715
+ mkdirSync2(dir, { recursive: true });
2699
1716
  return join3(dir, DEUS_DB_FILENAME);
2700
1717
  }
2701
- function resolveNodeBinary() {
2702
- if (process.env.ELECTRON_RUN_AS_NODE === "1") return process.execPath;
2703
- try {
2704
- const electronPath = execSync2(
2705
- `node -e "try { console.log(require('electron')) } catch { process.exit(1) }"`,
2706
- { encoding: "utf-8", timeout: 5e3, stdio: ["pipe", "pipe", "pipe"] }
2707
- ).trim();
2708
- if (electronPath && existsSync6(electronPath)) {
2709
- try {
2710
- execSync2(
2711
- `node -e "const D = require('better-sqlite3'); const d = new D(':memory:'); d.close()"`,
2712
- { timeout: 5e3, stdio: ["pipe", "pipe", "pipe"] }
2713
- );
2714
- return process.execPath;
2715
- } catch {
2716
- return electronPath;
2717
- }
2718
- }
2719
- } catch {
2720
- }
2721
- return process.execPath;
2722
- }
2723
1718
  async function startBackendProcess(opts) {
2724
- const { command, backendEntry, backendCwd, env, forceElectronRunAsNode, onUnexpectedExit } = opts;
1719
+ const { backendEntry, backendCwd, env, onUnexpectedExit } = opts;
2725
1720
  return new Promise((resolve2) => {
2726
- const child = spawn2(command, [backendEntry], {
1721
+ const child = spawn(process.execPath, [backendEntry], {
2727
1722
  cwd: backendCwd,
2728
1723
  stdio: ["ignore", "pipe", "pipe"],
2729
- env: {
2730
- ...process.env,
2731
- ...forceElectronRunAsNode ? { ELECTRON_RUN_AS_NODE: "1" } : {},
2732
- ...env
2733
- }
1724
+ env: { ...process.env, ...env }
2734
1725
  });
2735
1726
  let buffer = "";
2736
1727
  let resolved = false;
@@ -2782,13 +1773,13 @@ function stopBackendProcess(child) {
2782
1773
  }
2783
1774
 
2784
1775
  // src/desktop.ts
2785
- import { execFileSync as execFileSync4, execSync as execSync3, spawn as spawn3 } from "node:child_process";
1776
+ import { execFileSync, execSync as execSync2, spawn as spawn2 } from "node:child_process";
2786
1777
  import {
2787
- chmodSync as chmodSync4,
1778
+ chmodSync as chmodSync2,
2788
1779
  copyFileSync,
2789
1780
  createWriteStream,
2790
- existsSync as existsSync7,
2791
- mkdirSync as mkdirSync5,
1781
+ existsSync as existsSync4,
1782
+ mkdirSync as mkdirSync3,
2792
1783
  unlinkSync as unlinkSync2
2793
1784
  } from "node:fs";
2794
1785
  import { join as join4 } from "node:path";
@@ -2801,7 +1792,7 @@ var INSTALL_PATHS = {
2801
1792
  };
2802
1793
  function hasDisplay() {
2803
1794
  const os = platform3();
2804
- if (process.env.CI || process.env.DOCKER || existsSync7("/.dockerenv")) return false;
1795
+ if (process.env.CI || process.env.DOCKER || existsSync4("/.dockerenv")) return false;
2805
1796
  if (process.env.SSH_CONNECTION || process.env.SSH_TTY) return false;
2806
1797
  if (os === "darwin") return true;
2807
1798
  if (os === "linux") return !!(process.env.DISPLAY || process.env.WAYLAND_DISPLAY);
@@ -2811,7 +1802,7 @@ function findInstalledApp() {
2811
1802
  const os = platform3();
2812
1803
  const paths = INSTALL_PATHS[os] || [];
2813
1804
  for (const p of paths) {
2814
- if (p && existsSync7(p)) return p;
1805
+ if (p && existsSync4(p)) return p;
2815
1806
  }
2816
1807
  return null;
2817
1808
  }
@@ -2819,10 +1810,10 @@ function launchDesktop(appPath) {
2819
1810
  const os = platform3();
2820
1811
  switch (os) {
2821
1812
  case "darwin":
2822
- spawn3("open", [appPath], { detached: true, stdio: "ignore" }).unref();
1813
+ spawn2("open", [appPath], { detached: true, stdio: "ignore" }).unref();
2823
1814
  break;
2824
1815
  case "linux":
2825
- spawn3(appPath, [], {
1816
+ spawn2(appPath, [], {
2826
1817
  detached: true,
2827
1818
  stdio: "ignore",
2828
1819
  env: {
@@ -2842,9 +1833,9 @@ function hasFuse2() {
2842
1833
  "/usr/lib64/libfuse.so.2",
2843
1834
  "/usr/lib/libfuse.so.2"
2844
1835
  ];
2845
- if (commonLibPaths.some((libPath) => existsSync7(libPath))) return true;
1836
+ if (commonLibPaths.some((libPath) => existsSync4(libPath))) return true;
2846
1837
  try {
2847
- return execSync3("ldconfig -p", { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).split("\n").some((line) => line.includes("libfuse.so.2"));
1838
+ return execSync2("ldconfig -p", { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).split("\n").some((line) => line.includes("libfuse.so.2"));
2848
1839
  } catch {
2849
1840
  return false;
2850
1841
  }
@@ -2855,21 +1846,21 @@ function isOnPath(dir) {
2855
1846
  function replaceInstalledMacApp(appPath, destPath) {
2856
1847
  const stagedPath = `${destPath}.staged`;
2857
1848
  const backupPath = `${destPath}.backup`;
2858
- const hadExistingInstall = existsSync7(destPath);
2859
- execSync3(`rm -rf "${stagedPath}" "${backupPath}"`, { stdio: "pipe" });
2860
- execSync3(`ditto "${appPath}" "${stagedPath}"`, { stdio: "pipe" });
1849
+ const hadExistingInstall = existsSync4(destPath);
1850
+ execSync2(`rm -rf "${stagedPath}" "${backupPath}"`, { stdio: "pipe" });
1851
+ execSync2(`ditto "${appPath}" "${stagedPath}"`, { stdio: "pipe" });
2861
1852
  if (hadExistingInstall) {
2862
- execSync3(`mv "${destPath}" "${backupPath}"`, { stdio: "pipe" });
1853
+ execSync2(`mv "${destPath}" "${backupPath}"`, { stdio: "pipe" });
2863
1854
  }
2864
1855
  try {
2865
- execSync3(`mv "${stagedPath}" "${destPath}"`, { stdio: "pipe" });
1856
+ execSync2(`mv "${stagedPath}" "${destPath}"`, { stdio: "pipe" });
2866
1857
  if (hadExistingInstall) {
2867
- execSync3(`rm -rf "${backupPath}"`, { stdio: "pipe" });
1858
+ execSync2(`rm -rf "${backupPath}"`, { stdio: "pipe" });
2868
1859
  }
2869
1860
  } catch (error2) {
2870
- execSync3(`rm -rf "${stagedPath}"`, { stdio: "pipe" });
2871
- if (hadExistingInstall && existsSync7(backupPath) && !existsSync7(destPath)) {
2872
- execSync3(`mv "${backupPath}" "${destPath}"`, { stdio: "pipe" });
1861
+ execSync2(`rm -rf "${stagedPath}"`, { stdio: "pipe" });
1862
+ if (hadExistingInstall && existsSync4(backupPath) && !existsSync4(destPath)) {
1863
+ execSync2(`mv "${backupPath}" "${destPath}"`, { stdio: "pipe" });
2873
1864
  }
2874
1865
  throw error2;
2875
1866
  }
@@ -2914,7 +1905,7 @@ async function installDesktop(options) {
2914
1905
  process.exit(1);
2915
1906
  }
2916
1907
  const downloadDir = join4(tmpdir(), "deus-installer");
2917
- mkdirSync5(downloadDir, { recursive: true });
1908
+ mkdirSync3(downloadDir, { recursive: true });
2918
1909
  const downloadPath = join4(downloadDir, asset.name);
2919
1910
  await downloadFile(asset.browser_download_url, downloadPath);
2920
1911
  const s3 = spinner("Installing...");
@@ -3059,7 +2050,7 @@ async function installForPlatform(os, filePath, s) {
3059
2050
  case "darwin": {
3060
2051
  let mountPoint;
3061
2052
  try {
3062
- const mountOutput = execSync3(`hdiutil attach "${filePath}" -nobrowse`, {
2053
+ const mountOutput = execSync2(`hdiutil attach "${filePath}" -nobrowse`, {
3063
2054
  encoding: "utf-8"
3064
2055
  });
3065
2056
  mountPoint = mountOutput.split("\n").filter((line) => line.includes("/Volumes/")).map((line) => line.trim().split(" ").pop()?.trim()).find(Boolean);
@@ -3070,7 +2061,7 @@ async function installForPlatform(os, filePath, s) {
3070
2061
  const appName = "Deus.app";
3071
2062
  const appPath = `${mountPoint}/${appName}`;
3072
2063
  const destPath = `/Applications/${appName}`;
3073
- if (existsSync7(appPath)) {
2064
+ if (existsSync4(appPath)) {
3074
2065
  replaceInstalledMacApp(appPath, destPath);
3075
2066
  s.succeed(`Installed to ${c.dim("/Applications/Deus.app")}`);
3076
2067
  launchDesktop(destPath);
@@ -3081,13 +2072,13 @@ async function installForPlatform(os, filePath, s) {
3081
2072
  return null;
3082
2073
  } catch {
3083
2074
  s.fail("Auto-install failed \u2014 opening DMG manually");
3084
- execFileSync4("open", [filePath], { stdio: "ignore" });
2075
+ execFileSync("open", [filePath], { stdio: "ignore" });
3085
2076
  hint("Drag Deus.app to Applications, then launch it from Applications.");
3086
2077
  return null;
3087
2078
  } finally {
3088
2079
  if (mountPoint) {
3089
2080
  try {
3090
- execSync3(`hdiutil detach "${mountPoint}" -quiet`, { stdio: "pipe" });
2081
+ execSync2(`hdiutil detach "${mountPoint}" -quiet`, { stdio: "pipe" });
3091
2082
  } catch {
3092
2083
  }
3093
2084
  }
@@ -3096,10 +2087,10 @@ async function installForPlatform(os, filePath, s) {
3096
2087
  case "linux": {
3097
2088
  try {
3098
2089
  const installDir = join4(homedir4(), ".local", "bin");
3099
- mkdirSync5(installDir, { recursive: true });
2090
+ mkdirSync3(installDir, { recursive: true });
3100
2091
  const destPath = join4(installDir, "Deus.AppImage");
3101
2092
  copyFileSync(filePath, destPath);
3102
- chmodSync4(destPath, 493);
2093
+ chmodSync2(destPath, 493);
3103
2094
  s.succeed(`Installed to ${c.dim(destPath)}`);
3104
2095
  if (!hasFuse2()) {
3105
2096
  info("libfuse2 not found; launching AppImage with APPIMAGE_EXTRACT_AND_RUN=1.");
@@ -3118,6 +2109,10 @@ async function installForPlatform(os, filePath, s) {
3118
2109
  }
3119
2110
 
3120
2111
  // src/status.ts
2112
+ var AGENT_NAMES = {
2113
+ "claude-code": "Claude Code",
2114
+ "codex-app-server": "Codex"
2115
+ };
3121
2116
  async function showStatus() {
3122
2117
  const serverInfo = readServerInfo();
3123
2118
  if (!serverInfo) {
@@ -3130,7 +2125,7 @@ async function showStatus() {
3130
2125
  const port = serverInfo.backendPort;
3131
2126
  const [health, relayStatus, devicesRes, agentAuth] = await Promise.all([
3132
2127
  httpGet(port, "/api/health"),
3133
- httpGet(port, "/api/settings/relay-status"),
2128
+ httpGet(port, "/api/relay/status"),
3134
2129
  httpGet(port, "/api/remote-auth/devices"),
3135
2130
  httpGet(port, "/api/settings/agent-auth")
3136
2131
  ]);
@@ -3164,21 +2159,26 @@ async function showStatus() {
3164
2159
  console.log(` ${c.green(sym.dot)} ${device.name.padEnd(24)} ${c.dim(age)}`);
3165
2160
  }
3166
2161
  }
3167
- if (agentAuth?.agents) {
2162
+ if (agentAuth?.auth?.length) {
3168
2163
  blank();
3169
2164
  divider("AI Agents");
3170
2165
  blank();
3171
- for (const agent of agentAuth.agents) {
2166
+ for (const agent of agentAuth.auth) {
2167
+ const cli = agentAuth.clis?.find((candidate) => candidate.harness === agent.harness);
3172
2168
  let status;
3173
- if (!agent.initialized) {
2169
+ if (cli?.state === "installing") {
2170
+ status = c.dim("installing");
2171
+ } else if (cli && cli.state !== "ready" && cli.state !== "unmanaged") {
3174
2172
  status = c.dim("not installed");
3175
- } else if (agent.authenticated) {
3176
- const email = agent.account?.email ? c.dim(` (${agent.account.email})`) : "";
3177
- status = c.green("authenticated") + email;
2173
+ } else if (agent.state === "signed_in") {
2174
+ const who = [agent.label, agent.email].filter(Boolean).join(" \xB7 ");
2175
+ status = c.green("signed in") + (who ? c.dim(` (${who})`) : "");
2176
+ } else if (agent.state === "unknown") {
2177
+ status = c.dim("status unavailable");
3178
2178
  } else {
3179
- status = c.yellow("not authenticated");
2179
+ status = c.yellow("not signed in");
3180
2180
  }
3181
- kv(agent.name, status, 14);
2181
+ kv(AGENT_NAMES[agent.harness] ?? agent.harness, status, 14);
3182
2182
  }
3183
2183
  }
3184
2184
  blank();
@@ -3282,7 +2282,7 @@ function printHelp(version) {
3282
2282
  console.log(` ${c.bold("Commands:")}`);
3283
2283
  console.log(` ${c.cyan("(none)")} Auto-detect: launch desktop app or start server`);
3284
2284
  console.log(
3285
- ` ${c.cyan("start")} Start headless server ${c.dim("(backend + agent-server)")}`
2285
+ ` ${c.cyan("start")} Start headless server ${c.dim("(backend + agent engine)")}`
3286
2286
  );
3287
2287
  console.log(` ${c.cyan("install")} Download and install the desktop app`);
3288
2288
  console.log(` ${c.cyan("pair")} Generate a pairing code for remote access`);