thenomad 0.4.2 → 0.5.1

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 (133) hide show
  1. package/dist/nomad.js +427 -52
  2. package/package.json +1 -1
  3. package/web/404.html +1 -1
  4. package/web/__next.__PAGE__.txt +33 -31
  5. package/web/__next._full.txt +37 -35
  6. package/web/__next._tree.txt +2 -2
  7. package/web/_next/static/chunks/{35uvx15wn7-j-.js → 1x9sijct2al7p.js} +1 -1
  8. package/web/_next/static/chunks/{1ygp921kjfxbp.css → 2o1e9ex_u8yqf.css} +1 -1
  9. package/web/_next/static/chunks/2qcrytgk9-6pf.js +1 -0
  10. package/web/_next/static/chunks/3u5lly_m8hc-w.js +1 -0
  11. package/web/_not-found/__next._full.txt +3 -3
  12. package/web/_not-found/__next._not-found.__PAGE__.txt +2 -2
  13. package/web/_not-found/__next._tree.txt +2 -2
  14. package/web/_not-found.html +1 -1
  15. package/web/_not-found.txt +3 -3
  16. package/web/app/__next._full.txt +3 -3
  17. package/web/app/__next._tree.txt +2 -2
  18. package/web/app/__next.app.__PAGE__.txt +1 -1
  19. package/web/app/__next.app.txt +2 -2
  20. package/web/app/agents/__next._full.txt +3 -3
  21. package/web/app/agents/__next._tree.txt +2 -2
  22. package/web/app/agents/__next.app.agents.__PAGE__.txt +1 -1
  23. package/web/app/agents/__next.app.txt +2 -2
  24. package/web/app/agents/view/__next._full.txt +3 -3
  25. package/web/app/agents/view/__next._tree.txt +2 -2
  26. package/web/app/agents/view/__next.app.agents.view.__PAGE__.txt +1 -1
  27. package/web/app/agents/view/__next.app.txt +2 -2
  28. package/web/app/agents/view.html +1 -1
  29. package/web/app/agents/view.txt +3 -3
  30. package/web/app/agents.html +1 -1
  31. package/web/app/agents.txt +3 -3
  32. package/web/app/backups/__next._full.txt +3 -3
  33. package/web/app/backups/__next._tree.txt +2 -2
  34. package/web/app/backups/__next.app.backups.__PAGE__.txt +1 -1
  35. package/web/app/backups/__next.app.txt +2 -2
  36. package/web/app/backups.html +1 -1
  37. package/web/app/backups.txt +3 -3
  38. package/web/app/compatibility/__next._full.txt +5 -5
  39. package/web/app/compatibility/__next._tree.txt +2 -2
  40. package/web/app/compatibility/__next.app.compatibility.__PAGE__.txt +3 -3
  41. package/web/app/compatibility/__next.app.txt +2 -2
  42. package/web/app/compatibility.html +1 -1
  43. package/web/app/compatibility.txt +5 -5
  44. package/web/app/export/__next._full.txt +5 -5
  45. package/web/app/export/__next._tree.txt +2 -2
  46. package/web/app/export/__next.app.export.__PAGE__.txt +3 -3
  47. package/web/app/export/__next.app.txt +2 -2
  48. package/web/app/export.html +1 -1
  49. package/web/app/export.txt +5 -5
  50. package/web/app/history/__next._full.txt +5 -5
  51. package/web/app/history/__next._tree.txt +2 -2
  52. package/web/app/history/__next.app.history.__PAGE__.txt +3 -3
  53. package/web/app/history/__next.app.txt +2 -2
  54. package/web/app/history.html +1 -1
  55. package/web/app/history.txt +5 -5
  56. package/web/app/import/__next._full.txt +3 -3
  57. package/web/app/import/__next._tree.txt +2 -2
  58. package/web/app/import/__next.app.import.__PAGE__.txt +1 -1
  59. package/web/app/import/__next.app.txt +2 -2
  60. package/web/app/import.html +1 -1
  61. package/web/app/import.txt +3 -3
  62. package/web/app/migrate/__next._full.txt +5 -5
  63. package/web/app/migrate/__next._tree.txt +2 -2
  64. package/web/app/migrate/__next.app.migrate.__PAGE__.txt +3 -3
  65. package/web/app/migrate/__next.app.txt +2 -2
  66. package/web/app/migrate.html +1 -1
  67. package/web/app/migrate.txt +5 -5
  68. package/web/app/settings/__next._full.txt +5 -5
  69. package/web/app/settings/__next._tree.txt +2 -2
  70. package/web/app/settings/__next.app.settings.__PAGE__.txt +3 -3
  71. package/web/app/settings/__next.app.txt +2 -2
  72. package/web/app/settings.html +1 -1
  73. package/web/app/settings.txt +5 -5
  74. package/web/app/versions/__next._full.txt +3 -3
  75. package/web/app/versions/__next._tree.txt +2 -2
  76. package/web/app/versions/__next.app.txt +2 -2
  77. package/web/app/versions/__next.app.versions.__PAGE__.txt +1 -1
  78. package/web/app/versions.html +1 -1
  79. package/web/app/versions.txt +3 -3
  80. package/web/app.html +1 -1
  81. package/web/app.txt +3 -3
  82. package/web/docs/__next._full.txt +3 -3
  83. package/web/docs/__next._tree.txt +2 -2
  84. package/web/docs/__next.docs.__PAGE__.txt +2 -2
  85. package/web/docs/adapters/__next._full.txt +20 -18
  86. package/web/docs/adapters/__next._tree.txt +2 -2
  87. package/web/docs/adapters/__next.docs.adapters.__PAGE__.txt +16 -14
  88. package/web/docs/adapters.html +1 -1
  89. package/web/docs/adapters.txt +20 -18
  90. package/web/docs/format/__next._full.txt +3 -3
  91. package/web/docs/format/__next._tree.txt +2 -2
  92. package/web/docs/format/__next.docs.format.__PAGE__.txt +2 -2
  93. package/web/docs/format.html +2 -2
  94. package/web/docs/format.txt +3 -3
  95. package/web/docs/security/__next._full.txt +3 -3
  96. package/web/docs/security/__next._tree.txt +2 -2
  97. package/web/docs/security/__next.docs.security.__PAGE__.txt +2 -2
  98. package/web/docs/security.html +1 -1
  99. package/web/docs/security.txt +3 -3
  100. package/web/docs/token/__next._full.txt +3 -3
  101. package/web/docs/token/__next._tree.txt +2 -2
  102. package/web/docs/token/__next.docs.token.__PAGE__.txt +2 -2
  103. package/web/docs/token.html +1 -1
  104. package/web/docs/token.txt +3 -3
  105. package/web/docs.html +2 -2
  106. package/web/docs.txt +3 -3
  107. package/web/index.html +2 -2
  108. package/web/index.txt +37 -35
  109. package/web/inspect/__next._full.txt +5 -5
  110. package/web/inspect/__next._tree.txt +2 -2
  111. package/web/inspect/__next.inspect.__PAGE__.txt +4 -4
  112. package/web/inspect.html +1 -1
  113. package/web/inspect.txt +5 -5
  114. package/web/privacy/__next._full.txt +3 -3
  115. package/web/privacy/__next._tree.txt +2 -2
  116. package/web/privacy/__next.privacy.__PAGE__.txt +2 -2
  117. package/web/privacy.html +1 -1
  118. package/web/privacy.txt +3 -3
  119. package/web/terms/__next._full.txt +3 -3
  120. package/web/terms/__next._tree.txt +2 -2
  121. package/web/terms/__next.terms.__PAGE__.txt +2 -2
  122. package/web/terms.html +1 -1
  123. package/web/terms.txt +3 -3
  124. package/web/vote/__next._full.txt +3 -3
  125. package/web/vote/__next._tree.txt +2 -2
  126. package/web/vote/__next.vote.__PAGE__.txt +2 -2
  127. package/web/vote.html +1 -1
  128. package/web/vote.txt +3 -3
  129. package/web/_next/static/chunks/10-jap4z156cb.js +0 -1
  130. package/web/_next/static/chunks/2bgjjtv5djk5k.js +0 -1
  131. /package/web/_next/static/{GFCmlWJPNNpG79BCw_NAH → QinUk6PjXyM9AWH7_9ASp}/_buildManifest.js +0 -0
  132. /package/web/_next/static/{GFCmlWJPNNpG79BCw_NAH → QinUk6PjXyM9AWH7_9ASp}/_clientMiddlewareManifest.js +0 -0
  133. /package/web/_next/static/{GFCmlWJPNNpG79BCw_NAH → QinUk6PjXyM9AWH7_9ASp}/_ssgManifest.js +0 -0
package/dist/nomad.js CHANGED
@@ -928,7 +928,7 @@ var init_src2 = __esm({
928
928
  init_markdown();
929
929
  init_document();
930
930
  init_merge();
931
- NOMAD_VERSION = "0.4.2";
931
+ NOMAD_VERSION = "0.5.1";
932
932
  NomadError = class extends Error {
933
933
  constructor(message, code, hint) {
934
934
  super(message);
@@ -3439,7 +3439,7 @@ function applyKnownServerProfile(tool, platformName = "the destination") {
3439
3439
  function knownServerId(tool) {
3440
3440
  return PROFILES.find((p) => p.matches(tool))?.id ?? null;
3441
3441
  }
3442
- var NPM_SPEC, escapeRe2, isPackageArg, isPackageInScript, isPriorsPackage, isPriorsScript, isPriorsHost, PRIORS, isOakCommand, OAK, HEDGEHOOD_HOSTS, isHedgehoodHost, isHedgehoodCommand, HEDGEHOOD_KEY_VARS, HEDGEHOOD, BRAINCHAIN_PKG, isBrainChainCommand, literal, amount, BRAINCHAIN, PROFILES;
3442
+ var NPM_SPEC, escapeRe2, isPackageArg, isPackageInScript, isPriorsPackage, isPriorsScript, isPriorsHost, PRIORS, isOakCommand, OAK, HEDGEHOOD_HOSTS, isHedgehoodHost, isHedgehoodCommand, HEDGEHOOD_KEY_VARS, HEDGEHOOD, BRAINCHAIN_PKG, isBrainChainCommand, literal, amount, BRAINCHAIN, isHeyHost, isHeyCommand, isHeyPackage, HEY_API, HEY, PROFILES;
3443
3443
  var init_known_servers = __esm({
3444
3444
  "../../packages/adapters/src/known-servers.ts"() {
3445
3445
  "use strict";
@@ -3711,7 +3711,71 @@ var init_known_servers = __esm({
3711
3711
  }
3712
3712
  }
3713
3713
  };
3714
- PROFILES = [PRIORS, OAK, HEDGEHOOD, BRAINCHAIN];
3714
+ isHeyHost = (url) => {
3715
+ if (!url) return false;
3716
+ try {
3717
+ const u = new URL(url);
3718
+ return u.protocol === "https:" && u.hostname === "heyresearch.xyz" && !u.port && /^\/mcp(\/research)?\/?$/.test(u.pathname);
3719
+ } catch {
3720
+ return false;
3721
+ }
3722
+ };
3723
+ isHeyCommand = (command) => !!command && /(^|[\\/])hey-research-mcp(\.cmd|\.exe)?$/i.test(command);
3724
+ isHeyPackage = isPackageArg("@hey-research-lab/mcp");
3725
+ HEY_API = "https://heyresearch.xyz";
3726
+ HEY = {
3727
+ id: "hey-research",
3728
+ vendor: "HEY Research Lab",
3729
+ label: "HEY Research Lab (read-only research on Robinhood Chain projects)",
3730
+ matches: (t) => !!t.mcp && (isHeyHost(t.mcp.url) || isHeyCommand(t.mcp.command) || t.mcp.args.some(isHeyPackage)),
3731
+ keyVars: [],
3732
+ emptyOkEnv: [],
3733
+ limitVars: [],
3734
+ looserDefaults: {},
3735
+ apply(t, out2, platform) {
3736
+ const mcp = t.mcp;
3737
+ const lit = (k) => {
3738
+ const v = mcp.env[k];
3739
+ return v && "value" in v ? v.value.trim() : void 0;
3740
+ };
3741
+ if (mcp.transport !== "stdio") {
3742
+ const research = /\/mcp\/research\/?$/.test(new URL(mcp.url).pathname);
3743
+ out2.notes.push({
3744
+ level: "info",
3745
+ category: "tools",
3746
+ message: `"${t.name}" is HEY Research Lab's hosted, read-only server${research ? " (the research profile: builder research, without market tools)" : ""}. It needs no key and no wallet; Nomad copies its address.`
3747
+ });
3748
+ if (Object.keys(mcp.headers ?? {}).some((h) => h.toLowerCase() === "authorization")) {
3749
+ out2.notes.push({ level: "info", category: "tools", message: `"${t.name}" used a HEY API key in its Authorization header. Keys are never copied: set it again on ${platform} as "Bearer <your key>" (the key is on heyresearch.xyz/account), or leave it out to use HEY without a key.` });
3750
+ }
3751
+ return;
3752
+ }
3753
+ out2.notes.push({ level: "info", category: "tools", message: `"${t.name}" runs HEY Research Lab's read-only server on this computer. It needs no wallet; an API key is optional.` });
3754
+ if (mcp.env.HEY_API_KEY) {
3755
+ out2.notes.push({ level: "info", category: "tools", message: `"${t.name}" used a HEY API key (HEY_API_KEY). Keys are never copied: set it again on ${platform} (it is on heyresearch.xyz/account), or leave it out to use HEY without a key.` });
3756
+ }
3757
+ const api = mcp.env.HEY_API_URL;
3758
+ const apiValue = lit("HEY_API_URL");
3759
+ if (apiValue !== void 0 && apiValue.replace(/\/+$/, "") !== HEY_API) {
3760
+ out2.notes.push({
3761
+ level: "warning",
3762
+ category: "tools",
3763
+ message: `"${t.name}" reads ${apiValue} instead of ${HEY_API} (HEY_API_URL). Its API key, if it has one, is sent there too. Keep it only if you trust that address.`
3764
+ });
3765
+ } else if (api && !("value" in api)) {
3766
+ out2.notes.push({ level: "info", category: "tools", message: `"${t.name}" takes the HEY address it reads from HEY_API_URL, which was a variable on the source. Without it on ${platform}, it reads ${HEY_API}.` });
3767
+ }
3768
+ if (lit("HEY_MCP_PROFILE")?.toLowerCase() === "research") {
3769
+ out2.notes.push({ level: "info", category: "tools", message: `"${t.name}" serves HEY's research profile (HEY_MCP_PROFILE=research): builder research, without market tools.` });
3770
+ }
3771
+ if (isHeyCommand(mcp.command)) {
3772
+ out2.manualSteps.push(`Install HEY Research Lab's MCP server for "${t.name}": npm install -g @hey-research-lab/mcp. It needs Node.js 20 or later, and the hey-research-mcp command must be on the PATH ${platform} uses.`);
3773
+ } else {
3774
+ out2.manualSteps.push(`"${t.name}" runs HEY Research Lab's server through npx: ${platform} needs Node.js 20 or later on its PATH.`);
3775
+ }
3776
+ }
3777
+ };
3778
+ PROFILES = [PRIORS, OAK, HEDGEHOOD, BRAINCHAIN, HEY];
3715
3779
  }
3716
3780
  });
3717
3781
 
@@ -9131,8 +9195,8 @@ __export(src_exports4, {
9131
9195
  });
9132
9196
  import { McpServer as McpServer2 } from "@modelcontextprotocol/sdk/server/mcp.js";
9133
9197
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
9134
- import { readFileSync as readFileSync4 } from "fs";
9135
- import { join as join18, resolve as resolve5 } from "path";
9198
+ import { readFileSync as readFileSync5 } from "fs";
9199
+ import { join as join19, resolve as resolve6 } from "path";
9136
9200
  import { z as z4 } from "zod";
9137
9201
  function text2(data) {
9138
9202
  return { content: [{ type: "text", text: typeof data === "string" ? data : JSON.stringify(data, null, 2) }] };
@@ -9165,9 +9229,9 @@ function summarizePlan(p) {
9165
9229
  };
9166
9230
  }
9167
9231
  function createMcpServer(options = {}) {
9168
- const nomad = new Nomad({ home: options.home ? resolve5(options.home) : nomadHome() });
9232
+ const nomad = new Nomad({ home: options.home ? resolve6(options.home) : nomadHome() });
9169
9233
  const server = new McpServer2({ name: "nomad", version: NOMAD_VERSION });
9170
- const exportsDir = join18(nomad.store.home, "exports");
9234
+ const exportsDir = join19(nomad.store.home, "exports");
9171
9235
  server.registerTool(
9172
9236
  "list_agents",
9173
9237
  { title: "List agents", description: "Agents in the local Nomad library with their known locations.", inputSchema: {} },
@@ -9237,9 +9301,9 @@ function createMcpServer(options = {}) {
9237
9301
  { title: "Validate a package", description: "Check a .nomad, .agentpack or .jetpack package for structure, integrity and security problems.", inputSchema: { path: z4.string().describe("Path to a package file") } },
9238
9302
  async ({ path }) => {
9239
9303
  try {
9240
- const p = resolve5(expandHome(path));
9304
+ const p = resolve6(expandHome(path));
9241
9305
  if (!/\.(nomad|agentpack|jetpack)$/.test(p)) throw new NomadError("Only .nomad, .agentpack or .jetpack files can be validated.", "usage");
9242
- const r = nomad.validatePackage(new Uint8Array(readFileSync4(p)));
9306
+ const r = nomad.validatePackage(new Uint8Array(readFileSync5(p)));
9243
9307
  return text2({ ok: r.ok, name: r.doc?.name, issues: r.issues, warnings: r.warnings, secretsFound: r.scan?.findings.length ?? 0 });
9244
9308
  } catch (e) {
9245
9309
  return fail(e);
@@ -9362,10 +9426,10 @@ init_src6();
9362
9426
  import { Command, Option } from "commander";
9363
9427
  import { createInterface } from "readline/promises";
9364
9428
  import { spawn as spawn2 } from "child_process";
9365
- import { existsSync as existsSync6, mkdirSync as mkdirSync3, writeFileSync as writeFileSync3 } from "fs";
9366
- import { dirname as dirname6, join as join19, resolve as resolve6 } from "path";
9429
+ import { existsSync as existsSync7, mkdirSync as mkdirSync4, writeFileSync as writeFileSync4 } from "fs";
9430
+ import { dirname as dirname7, join as join20, resolve as resolve7 } from "path";
9367
9431
  import { fileURLToPath } from "url";
9368
- import { randomBytes as randomBytes3 } from "crypto";
9432
+ import { randomBytes as randomBytes4 } from "crypto";
9369
9433
 
9370
9434
  // src/format.ts
9371
9435
  var NPM_NAME = "thenomad";
@@ -9528,14 +9592,14 @@ function shellQuote(s) {
9528
9592
  return `'${s.replace(/'/g, `'\\''`)}'`;
9529
9593
  }
9530
9594
  function run(cmd, args, input) {
9531
- return new Promise((resolve7, reject) => {
9595
+ return new Promise((resolve8, reject) => {
9532
9596
  const p = spawn(cmd, args, { stdio: ["pipe", "pipe", "pipe"] });
9533
9597
  let stdout = "";
9534
9598
  let stderr = "";
9535
9599
  p.stdout.on("data", (d) => stdout += d);
9536
9600
  p.stderr.on("data", (d) => stderr += d);
9537
9601
  p.on("error", (e) => reject(new NomadError(`${cmd} is not available: ${e.message}`, "ssh-missing", "Install OpenSSH to use remote migration.")));
9538
- p.on("close", (code) => resolve7({ code: code ?? 1, stdout, stderr }));
9602
+ p.on("close", (code) => resolve8({ code: code ?? 1, stdout, stderr }));
9539
9603
  if (input) p.stdin.end(input);
9540
9604
  else p.stdin.end();
9541
9605
  });
@@ -9574,8 +9638,8 @@ async function remoteMigrate(o, packagePath, args) {
9574
9638
 
9575
9639
  // src/ui.ts
9576
9640
  import { createServer } from "http";
9577
- import { existsSync as existsSync5, readFileSync as readFileSync3, statSync as statSync2 } from "fs";
9578
- import { extname, join as join17, normalize, resolve as resolve4, sep as sep4 } from "path";
9641
+ import { existsSync as existsSync6, readFileSync as readFileSync4, statSync as statSync3 } from "fs";
9642
+ import { extname, join as join18, normalize, resolve as resolve5, sep as sep4 } from "path";
9579
9643
 
9580
9644
  // ../../packages/local/src/index.ts
9581
9645
  import { timingSafeEqual } from "crypto";
@@ -9793,6 +9857,215 @@ async function handleLocalApi(req, ctx, path) {
9793
9857
  }
9794
9858
  }
9795
9859
 
9860
+ // src/install.ts
9861
+ init_src2();
9862
+ import { spawnSync } from "child_process";
9863
+ import { createHash, randomBytes as randomBytes3 } from "crypto";
9864
+ import { chmodSync as chmodSync2, cpSync, existsSync as existsSync5, mkdirSync as mkdirSync3, readdirSync, readFileSync as readFileSync3, renameSync, rmSync, statSync as statSync2, writeFileSync as writeFileSync3 } from "fs";
9865
+ import { basename as basename11, dirname as dirname6, join as join17, resolve as resolve4 } from "path";
9866
+ var REPO = "kadiri-seer/nomad";
9867
+ var VERSION_RE = /^\d+\.\d+\.\d+$/;
9868
+ function currentInstall(execPath = process.execPath) {
9869
+ const appDir = dirname6(execPath);
9870
+ if (basename11(dirname6(appDir)) !== "app" || !VERSION_RE.test(basename11(appDir))) return null;
9871
+ const root = dirname6(dirname6(appDir));
9872
+ try {
9873
+ const info = JSON.parse(readFileSync3(join17(root, "install.json"), "utf8"));
9874
+ if (info.by !== "nomad-installer" || typeof info.target !== "string" || !/^(windows|macos|linux)-(x64|arm64)$/.test(info.target)) return null;
9875
+ return { root, target: info.target, version: basename11(appDir) };
9876
+ } catch {
9877
+ return null;
9878
+ }
9879
+ }
9880
+ function newer(a, b) {
9881
+ const pa = a.split(".").map(Number);
9882
+ const pb = b.split(".").map(Number);
9883
+ for (let i = 0; i < 3; i++) if (pa[i] !== pb[i]) return pa[i] > pb[i];
9884
+ return false;
9885
+ }
9886
+ function assetName(target) {
9887
+ return `nomad-${target}.${target.startsWith("windows") ? "zip" : "tar.gz"}`;
9888
+ }
9889
+ function checksumFor(sums, name) {
9890
+ for (const line of sums.split(/\r?\n/)) {
9891
+ const m = /^([0-9a-fA-F]{64})\s+\*?(\S+)\s*$/.exec(line);
9892
+ if (m && m[2] === name) return m[1].toLowerCase();
9893
+ }
9894
+ return null;
9895
+ }
9896
+ async function get(url) {
9897
+ const host = new URL(url).host;
9898
+ let r;
9899
+ try {
9900
+ r = await fetch(url, { headers: { "User-Agent": `nomad/${NOMAD_VERSION}`, Accept: host === "api.github.com" ? "application/vnd.github+json" : "*/*" }, redirect: "follow", ...host === "api.github.com" ? { signal: AbortSignal.timeout(3e4) } : {} });
9901
+ } catch {
9902
+ throw new Error(`Could not reach ${host}. Check your connection and try again.`);
9903
+ }
9904
+ if (r.status === 404 && host === "api.github.com") throw new Error("No Nomad release was found on GitHub. Try again later.");
9905
+ if (!r.ok) throw new Error(`Could not reach ${host} (HTTP ${r.status}). Try again later.`);
9906
+ return r;
9907
+ }
9908
+ async function latestVersion() {
9909
+ try {
9910
+ const page = await fetch(`https://github.com/${REPO}/releases/latest`, { method: "HEAD", redirect: "follow", headers: { "User-Agent": `nomad/${NOMAD_VERSION}` }, signal: AbortSignal.timeout(3e4) });
9911
+ const m = /^https:\/\/github\.com\/[^/]+\/[^/]+\/releases\/tag\/v(\d+\.\d+\.\d+)$/.exec(page.url);
9912
+ if (page.ok && m) return m[1];
9913
+ } catch {
9914
+ }
9915
+ const data = await (await get(`https://api.github.com/repos/${REPO}/releases/latest`)).json();
9916
+ const tag = typeof data.tag_name === "string" ? data.tag_name : "";
9917
+ if (!/^v\d+\.\d+\.\d+$/.test(tag)) throw new Error("GitHub returned an unexpected release name. Try again later.");
9918
+ return tag.slice(1);
9919
+ }
9920
+ function switchedVersion(install) {
9921
+ try {
9922
+ const v = readFileSync3(join17(install.root, "current"), "utf8").trim();
9923
+ if (VERSION_RE.test(v) && newer(v, install.version)) return v;
9924
+ } catch {
9925
+ }
9926
+ return install.version;
9927
+ }
9928
+ async function checkForUpdate(install = currentInstall()) {
9929
+ if (!install) return { installed: false, current: NOMAD_VERSION };
9930
+ const current2 = switchedVersion(install);
9931
+ const latest = await latestVersion();
9932
+ return { installed: true, current: current2, latest, available: newer(latest, current2) };
9933
+ }
9934
+ function systemTar() {
9935
+ if (process.platform === "win32") return join17(process.env.SystemRoot ?? "C:\\Windows", "System32", "tar.exe");
9936
+ for (const p of ["/usr/bin/tar", "/bin/tar"]) if (existsSync5(p)) return p;
9937
+ return "tar";
9938
+ }
9939
+ function renameWithRetry(from, to) {
9940
+ for (let i = 0; ; i++) {
9941
+ try {
9942
+ return renameSync(from, to);
9943
+ } catch (e) {
9944
+ const code = e.code;
9945
+ if (i >= 40 || code !== "EPERM" && code !== "EBUSY" && code !== "EACCES") throw e;
9946
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 500);
9947
+ }
9948
+ }
9949
+ }
9950
+ function removeQuietly(p) {
9951
+ try {
9952
+ rmSync(p, { recursive: true, force: true, maxRetries: 3, retryDelay: 200 });
9953
+ } catch {
9954
+ }
9955
+ }
9956
+ var powershell = () => join17(process.env.SystemRoot ?? "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
9957
+ function startPowerShell(script, env) {
9958
+ const ps = powershell();
9959
+ const launch = "Start-Process -FilePath $env:NOMAD_PS -ArgumentList '-NoProfile','-NonInteractive','-ExecutionPolicy','Bypass','-EncodedCommand',$env:NOMAD_PS_SCRIPT -WindowStyle Hidden";
9960
+ const r = spawnSync(ps, ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", launch], {
9961
+ env: { ...process.env, ...env, NOMAD_PS: ps, NOMAD_PS_SCRIPT: Buffer.from(script, "utf16le").toString("base64") },
9962
+ stdio: "ignore",
9963
+ windowsHide: true,
9964
+ timeout: 6e4
9965
+ });
9966
+ return r.status === 0;
9967
+ }
9968
+ function removeAfterExit(dir) {
9969
+ if (process.platform !== "win32") return;
9970
+ startPowerShell(`Wait-Process -Id ${process.pid} -ErrorAction SilentlyContinue; Start-Sleep -Seconds 2; Remove-Item -LiteralPath $env:NOMAD_OLD_DIR -Recurse -Force -ErrorAction SilentlyContinue`, { NOMAD_OLD_DIR: dir });
9971
+ }
9972
+ function takeLock(root) {
9973
+ const lock = join17(root, "update.lock");
9974
+ try {
9975
+ if (Date.now() - statSync2(lock).mtimeMs > 15 * 60 * 1e3) rmSync(lock, { recursive: true, force: true });
9976
+ } catch {
9977
+ }
9978
+ try {
9979
+ mkdirSync3(lock);
9980
+ } catch {
9981
+ throw new Error("Another Nomad update is running. Try again in a few minutes.");
9982
+ }
9983
+ return () => removeQuietly(lock);
9984
+ }
9985
+ async function applyUpdate(install, version, log = () => void 0) {
9986
+ if (!VERSION_RE.test(version)) throw new Error(`Not a version: ${version}`);
9987
+ if (switchedVersion(install) === version && existsSync5(join17(install.root, "app", version))) return version;
9988
+ const asset = assetName(install.target);
9989
+ const base = `https://github.com/${REPO}/releases/download/v${version}`;
9990
+ const unlock = takeLock(install.root);
9991
+ const work = join17(install.root, `tmp-${randomBytes3(6).toString("hex")}`);
9992
+ mkdirSync3(work, { recursive: true });
9993
+ try {
9994
+ log(`Downloading Nomad ${version}...`);
9995
+ const sums = await (await get(`${base}/SHA256SUMS`)).text();
9996
+ const expected = checksumFor(sums, asset);
9997
+ if (!expected) throw new Error(`The release has no fingerprint for ${asset}. Nothing was changed.`);
9998
+ const bytes2 = Buffer.from(await (await get(`${base}/${asset}`)).arrayBuffer());
9999
+ const actual = createHash("sha256").update(bytes2).digest("hex");
10000
+ if (actual !== expected) throw new Error("The download does not match its published fingerprint. Nothing was changed.");
10001
+ log("Fingerprint checked.");
10002
+ const archive = join17(work, asset);
10003
+ writeFileSync3(archive, bytes2);
10004
+ const staged = join17(work, "app");
10005
+ mkdirSync3(staged);
10006
+ const x = spawnSync(systemTar(), [install.target.startsWith("windows") ? "-xf" : "-xzf", archive, "-C", staged], { stdio: "pipe" });
10007
+ if (x.status !== 0) throw new Error(`Could not unpack the download: ${String(x.stderr ?? x.error ?? "").trim()}`);
10008
+ const node = join17(staged, process.platform === "win32" ? "node.exe" : "node");
10009
+ const check = spawnSync(node, [join17(staged, "node_modules", "thenomad", "dist", "nomad.js"), "--version"], { encoding: "utf8", timeout: 6e4 });
10010
+ if (check.status !== 0 || check.stdout.trim() !== version) throw new Error(`The new version did not start correctly. Nothing was changed.${check.stderr ? `
10011
+ ${check.stderr.trim()}` : ""}`);
10012
+ const target = join17(install.root, "app", version);
10013
+ if (resolve4(target) === resolve4(dirname6(process.execPath))) throw new Error(`Nomad ${version} is the version running now.`);
10014
+ removeQuietly(target);
10015
+ renameWithRetry(staged, target);
10016
+ for (const need of [process.platform === "win32" ? "node.exe" : "node", "launcher", join17("node_modules", "thenomad", "dist", "nomad.js")]) {
10017
+ if (!existsSync5(join17(target, need))) {
10018
+ removeQuietly(target);
10019
+ throw new Error(`The new version is incomplete (${need} is missing). Nothing was changed.`);
10020
+ }
10021
+ }
10022
+ const launcher = join17(target, "launcher");
10023
+ if (existsSync5(launcher)) {
10024
+ for (const f of readdirSync(launcher)) {
10025
+ cpSync(join17(launcher, f), join17(install.root, "bin", f), { force: true });
10026
+ if (process.platform !== "win32" && !f.endsWith(".png") && !f.endsWith(".icns")) chmodSync2(join17(install.root, "bin", f), 493);
10027
+ }
10028
+ }
10029
+ const next = join17(install.root, `current.${randomBytes3(4).toString("hex")}`);
10030
+ writeFileSync3(next, version);
10031
+ renameSync(next, join17(install.root, "current"));
10032
+ const infoPath = join17(install.root, "install.json");
10033
+ const info = JSON.parse(readFileSync3(infoPath, "utf8"));
10034
+ writeFileSync3(infoPath, JSON.stringify({ ...info, version, updated: (/* @__PURE__ */ new Date()).toISOString() }, null, 2) + "\n");
10035
+ if (process.platform === "win32") {
10036
+ const reg = join17(process.env.SystemRoot ?? "C:\\Windows", "System32", "reg.exe");
10037
+ spawnSync(reg, ["add", "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\thenomad.website", "/v", "DisplayVersion", "/t", "REG_SZ", "/d", version, "/f"], { stdio: "ignore" });
10038
+ }
10039
+ const running = resolve4(dirname6(process.execPath));
10040
+ for (const v of readdirSync(join17(install.root, "app"))) {
10041
+ const dir = resolve4(install.root, "app", v);
10042
+ if (v === version) continue;
10043
+ if (dir === running) removeAfterExit(dir);
10044
+ else removeQuietly(dir);
10045
+ }
10046
+ return version;
10047
+ } finally {
10048
+ removeQuietly(work);
10049
+ unlock();
10050
+ }
10051
+ }
10052
+ function runUninstaller(install, opts) {
10053
+ if (process.platform === "win32") {
10054
+ const script2 = join17(install.root, "bin", "uninstall.ps1");
10055
+ if (!existsSync5(script2)) return false;
10056
+ return startPowerShell(`& $env:NOMAD_UNINSTALL -Yes -WaitPid ${process.pid} -DataDir $env:NOMAD_DATA_DIR${opts.removeData ? " -RemoveData" : ""}`, {
10057
+ NOMAD_UNINSTALL: script2,
10058
+ NOMAD_DATA_DIR: opts.dataDir
10059
+ });
10060
+ }
10061
+ const script = join17(install.root, "bin", "uninstall.sh");
10062
+ if (!existsSync5(script)) return false;
10063
+ const args = [script, "--yes", "--data-dir", opts.dataDir];
10064
+ if (opts.removeData) args.push("--remove-data");
10065
+ const r = spawnSync("/bin/sh", args, { stdio: "inherit" });
10066
+ return r.status === 0;
10067
+ }
10068
+
9796
10069
  // src/ui.ts
9797
10070
  var TYPES = {
9798
10071
  ".html": "text/html; charset=utf-8",
@@ -9814,8 +10087,8 @@ var SECURITY_HEADERS = {
9814
10087
  "Permissions-Policy": "camera=(), microphone=(), geolocation=()"
9815
10088
  };
9816
10089
  function findSite(here) {
9817
- const candidates = [resolve4(here, "../web"), resolve4(here, "../../web/.next-export"), resolve4(process.cwd(), "apps/web/.next-export")];
9818
- return candidates.find((d) => existsSync5(join17(d, "app.html"))) ?? null;
10090
+ const candidates = [resolve5(here, "../web"), resolve5(here, "../../web/.next-export"), resolve5(process.cwd(), "apps/web/.next-export")];
10091
+ return candidates.find((d) => existsSync6(join18(d, "app.html"))) ?? null;
9819
10092
  }
9820
10093
  function fileFor(site, pathname) {
9821
10094
  let rel;
@@ -9825,11 +10098,11 @@ function fileFor(site, pathname) {
9825
10098
  return null;
9826
10099
  }
9827
10100
  if (rel.includes("\0")) return null;
9828
- const base = normalize(join17(site, rel));
10101
+ const base = normalize(join18(site, rel));
9829
10102
  if (base !== site && !base.startsWith(site + sep4)) return null;
9830
- for (const p of [base, `${base}.html`, join17(base, "index.html")]) {
10103
+ for (const p of [base, `${base}.html`, join18(base, "index.html")]) {
9831
10104
  try {
9832
- if (statSync2(p).isFile()) return p;
10105
+ if (statSync3(p).isFile()) return p;
9833
10106
  } catch {
9834
10107
  }
9835
10108
  }
@@ -9864,6 +10137,24 @@ async function send(res, r) {
9864
10137
  res.writeHead(r.status, headers);
9865
10138
  res.end(r.body ? Buffer.from(await r.arrayBuffer()) : void 0);
9866
10139
  }
10140
+ async function appUpdate(req, ctx) {
10141
+ const json2 = (body2, status = 200) => new Response(JSON.stringify(body2), { status, headers: { "Content-Type": "application/json", "Cache-Control": "no-store" } });
10142
+ const ok = checkRequest(req, ctx);
10143
+ if (!ok.ok) return json2({ error: ok.error }, ok.status);
10144
+ const install = currentInstall();
10145
+ if (!install) return json2({ installed: false });
10146
+ try {
10147
+ if (req.method === "GET") return json2(new URL(req.url).searchParams.get("check") === "1" ? await checkForUpdate(install) : { installed: true, current: install.version });
10148
+ if (req.method === "POST") {
10149
+ const c2 = await checkForUpdate(install);
10150
+ if (!c2.available || !c2.latest) return json2({ ...c2, updated: false });
10151
+ return json2({ ...c2, updated: true, current: await applyUpdate(install, c2.latest) });
10152
+ }
10153
+ return json2({ error: "Method not allowed." }, 405);
10154
+ } catch (e) {
10155
+ return json2({ error: e.message }, 502);
10156
+ }
10157
+ }
9867
10158
  function startUi(opts) {
9868
10159
  const { nomad, site, port, token } = opts;
9869
10160
  const ctx = { nomad, token, port };
@@ -9876,6 +10167,7 @@ function startUi(opts) {
9876
10167
  return;
9877
10168
  }
9878
10169
  if (url.pathname === "/app/session") return send(res, sessionResponse(await toRequest(req, url), ctx));
10170
+ if (opts.appUpdates && url.pathname === "/api/app/update") return send(res, await appUpdate(await toRequest(req, url), ctx));
9879
10171
  if (url.pathname.startsWith("/api/local/")) {
9880
10172
  const path2 = url.pathname.slice("/api/local/".length).split("/").filter(Boolean).map(decodeURIComponent);
9881
10173
  return send(res, await handleLocalApi(await toRequest(req, url), ctx, path2));
@@ -9885,11 +10177,11 @@ function startUi(opts) {
9885
10177
  return;
9886
10178
  }
9887
10179
  const file = fileFor(site, url.pathname === "/" ? "/index.html" : url.pathname);
9888
- const path = file ?? join17(site, "404.html");
10180
+ const path = file ?? join18(site, "404.html");
9889
10181
  const type = TYPES[extname(path)] ?? "application/octet-stream";
9890
10182
  const immutable = url.pathname.startsWith("/_next/static/");
9891
10183
  res.writeHead(file ? 200 : 404, { ...SECURITY_HEADERS, "Content-Type": type, "Cache-Control": immutable ? "public, max-age=31536000, immutable" : "no-cache" });
9892
- res.end(req.method === "HEAD" ? void 0 : readFileSync3(path));
10184
+ res.end(req.method === "HEAD" ? void 0 : readFileSync4(path));
9893
10185
  } catch (e) {
9894
10186
  if (!res.headersSent) res.writeHead(500, { "Content-Type": "text/plain" });
9895
10187
  res.end(e.message);
@@ -9924,8 +10216,8 @@ function out() {
9924
10216
  }
9925
10217
  function engine() {
9926
10218
  const home2 = program.opts().home;
9927
- if (home2) process.env.NOMAD_HOME = resolve6(home2);
9928
- return new Nomad({ home: home2 ? resolve6(home2) : nomadHome() });
10219
+ if (home2) process.env.NOMAD_HOME = resolve7(home2);
10220
+ return new Nomad({ home: home2 ? resolve7(home2) : nomadHome() });
9929
10221
  }
9930
10222
  function components(list) {
9931
10223
  if (!list) return void 0;
@@ -10054,8 +10346,8 @@ program.command("inspect <source>").description("show what an agent contains (re
10054
10346
  );
10055
10347
  program.command("validate <package>").description("check a package (.nomad, .agentpack or .jetpack) without importing it").action(
10056
10348
  (pkg) => run2(async (nomad) => {
10057
- const { readFileSync: readFileSync5 } = await import("fs");
10058
- const r = nomad.validatePackage(new Uint8Array(readFileSync5(resolve6(pkg))));
10349
+ const { readFileSync: readFileSync6 } = await import("fs");
10350
+ const r = nomad.validatePackage(new Uint8Array(readFileSync6(resolve7(pkg))));
10059
10351
  const { describeSigner: describeSigner2 } = await Promise.resolve().then(() => (init_src8(), src_exports3));
10060
10352
  print(out(), () => r.ok ? [green("Valid package") + ` ${r.doc.name} (${r.doc.id})`, `Format ${r.format}. ${describeSigner2(r.signer)}`, `${r.fileCount} files, ${r.totalBytes} bytes`, ...r.warnings.map((w) => yellow("! ") + w), ...r.scan?.findings.length ? [yellow(`${r.scan.findings.length} secret(s) found in the package`)] : []] : [red("Invalid package"), ...r.issues.map((i) => ` ${i.path}: ${i.message}`)], { ok: r.ok, format: r.format, signer: r.signer, issues: r.issues, warnings: r.warnings, info: r.info, findings: r.scan?.findings ?? [] });
10061
10353
  return r.ok ? EXIT.ok : EXIT.invalid;
@@ -10065,7 +10357,7 @@ program.command("export <source>").description("export an agent to a portable .n
10065
10357
  (source, o) => run2(async (nomad) => {
10066
10358
  const spec = await parseSource(nomad, source, { sourceDir: o.sourceDir, agent: o.agent });
10067
10359
  if (o.includeSecrets && !out().json) process.stderr.write(yellow("Warning: secret values will be stored in the package. Share it only with people who may see them.\n"));
10068
- const r = await nomad.exportAgent(spec, { outPath: resolve6(o.out), includeSecrets: o.includeSecrets, includeFiles: o.includeFiles, includeSensitiveFiles: o.includeSensitiveFiles, components: components(o.components), format: o.format === "jetpack" ? "interchange" : "nomad", sign: o.sign });
10360
+ const r = await nomad.exportAgent(spec, { outPath: resolve7(o.out), includeSecrets: o.includeSecrets, includeFiles: o.includeFiles, includeSensitiveFiles: o.includeSensitiveFiles, components: components(o.components), format: o.format === "jetpack" ? "interchange" : "nomad", sign: o.sign });
10069
10361
  print(out(), () => [green("Exported") + ` ${r.path}`, ...r.receipt.signedBy ? [`Signed with your key ${r.receipt.signedBy}`] : [], ...r.receipt.notIncluded.length ? [yellow(`Not representable in this format: ${r.receipt.notIncluded.join(", ")}`)] : [], `${r.files.size} files, ${r.bytes.length} bytes`, ...r.sanitize.redactedText || r.sanitize.strippedEnvValues.length ? [yellow(`${r.sanitize.redactedText} secret(s) redacted, ${r.sanitize.strippedEnvValues.length} credential(s) replaced by references`)] : [], ...r.sanitize.removedFiles.length ? [yellow(`Left out credential files: ${r.sanitize.removedFiles.join(", ")}`)] : [], ...r.sanitize.walletKeysKept ? [yellow(`Left out ${r.sanitize.walletKeysKept} wallet key(s) or recovery phrase(s): Nomad never stores them as values, even with --include-secrets.`)] : []], r.receipt);
10070
10362
  })
10071
10363
  );
@@ -10073,7 +10365,7 @@ approvalOptions(
10073
10365
  program.command("import <package>").description("import a package into the library, and optionally into a platform").option("--to <platform>", "also write the agent to this platform").option("--dest-dir <dir>", "destination directory").addOption(new Option("--mode <mode>", "conflict handling").choices(["merge", "copy", "replace"]).default("merge")).option("--name <name>", "name for copy mode").option("--components <list>", "only these components")
10074
10366
  ).action(
10075
10367
  (pkg, o) => run2(async (nomad) => {
10076
- const path = resolve6(pkg);
10368
+ const path = resolve7(pkg);
10077
10369
  const r = await nomad.importPackage({ path });
10078
10370
  if (!r.ok) {
10079
10371
  print(out(), () => [red("The package was rejected"), ...r.issues.map((i) => ` ${i.path}: ${i.message}`)], r);
@@ -10105,7 +10397,7 @@ approvalOptions(
10105
10397
  })
10106
10398
  );
10107
10399
  function parseDestination(spec) {
10108
- if (/\.(nomad|jetpack)$/i.test(spec)) return { kind: "file", path: resolve6(spec.replace(/^~(?=$|\/)/, process.env.HOME ?? "~")) };
10400
+ if (/\.(nomad|jetpack)$/i.test(spec)) return { kind: "file", path: resolve7(spec.replace(/^~(?=$|\/)/, process.env.HOME ?? "~")) };
10109
10401
  const m = /^([a-z0-9-]+)(?::(.*?))?(?:#(.+))?$/.exec(spec);
10110
10402
  const adapter = m ? findAdapter(m[1]) : void 0;
10111
10403
  if (!adapter || !m) throw new NomadError(`"${spec}" is not a platform or a package file.`, "usage", `Use a platform (${listAdapters().map((a) => a.info.id).slice(0, 5).join(", ")}, ...), a platform with a folder such as claude-code:~/project, or a file ending in .nomad.`);
@@ -10142,8 +10434,8 @@ program.command("keys").description("show your signing key, and the keys you tru
10142
10434
  );
10143
10435
  program.command("trust <package>").description("trust the key that signed a package").requiredOption("--name <who>", "a name for this key, such as a person or team").action(
10144
10436
  (pkg, o) => run2(async (nomad) => {
10145
- const { readFileSync: readFileSync5 } = await import("fs");
10146
- const k = nomad.trustPackageSigner(new Uint8Array(readFileSync5(resolve6(pkg))), o.name);
10437
+ const { readFileSync: readFileSync6 } = await import("fs");
10438
+ const k = nomad.trustPackageSigner(new Uint8Array(readFileSync6(resolve7(pkg))), o.name);
10147
10439
  print(out(), () => [green("Trusted") + ` ${k.fingerprint} ${k.name}`, dim("Check this fingerprint with them through another channel.")], k);
10148
10440
  })
10149
10441
  );
@@ -10251,7 +10543,7 @@ remote.command("push <source>").description("export locally, copy over SSH, and
10251
10543
  (source, o) => run2(async (nomad) => {
10252
10544
  const spec = await parseSource(nomad, source);
10253
10545
  const tmp = await makeTempDir("nomad-remote-");
10254
- const exp = await nomad.exportAgent(spec, { outPath: join19(tmp, "agent.nomad") });
10546
+ const exp = await nomad.exportAgent(spec, { outPath: join20(tmp, "agent.nomad") });
10255
10547
  const r = await remoteMigrate({ host: o.host, port: o.port ? Number(o.port) : void 0, identity: o.identity, remoteCommand: o.remoteCommand }, exp.path, { to: o.to, dest: o.destDir, mode: o.mode, apply: !!o.apply });
10256
10548
  print(out(), () => typeof r.result === "string" ? r.result : r.result.receipt ? receiptText(r.result.receipt) : planText(r.result.plan, out().verbose), r.result);
10257
10549
  return r.code;
@@ -10260,10 +10552,10 @@ remote.command("push <source>").description("export locally, copy over SSH, and
10260
10552
  program.command("schema").description("write the Universal Agent Format JSON Schemas").option("-o, --out <dir>", "output directory", ".").action(
10261
10553
  (o) => run2(async () => {
10262
10554
  const s = jsonSchemas();
10263
- const dir = resolve6(o.out);
10264
- mkdirSync3(dir, { recursive: true });
10265
- writeFileSync3(join19(dir, "agent-document.schema.json"), JSON.stringify(s.agentDocument, null, 2));
10266
- writeFileSync3(join19(dir, "package-manifest.schema.json"), JSON.stringify(s.packageManifest, null, 2));
10555
+ const dir = resolve7(o.out);
10556
+ mkdirSync4(dir, { recursive: true });
10557
+ writeFileSync4(join20(dir, "agent-document.schema.json"), JSON.stringify(s.agentDocument, null, 2));
10558
+ writeFileSync4(join20(dir, "package-manifest.schema.json"), JSON.stringify(s.packageManifest, null, 2));
10267
10559
  print(out(), () => `Wrote schemas to ${dir}`, { dir });
10268
10560
  })
10269
10561
  );
@@ -10285,27 +10577,99 @@ program.command("mcp").description("run the Nomad MCP server on stdio").option("
10285
10577
  const { startMcpServer: startMcpServer2 } = await Promise.resolve().then(() => (init_src9(), src_exports4));
10286
10578
  await startMcpServer2({ home: program.opts().home, allowWrites: !!o.allowWrites, allowReplace: !!o.allowReplace && !!o.allowWrites });
10287
10579
  });
10288
- program.command("ui").description("open the dashboard in your browser (only this computer can reach it)").option("-p, --port <port>", "port", "4317").option("--no-open", "do not open a browser").option("--dev", "developers: run the Next.js app from the repository with live reload").action(async (o) => {
10289
- const here = dirname6(fileURLToPath(import.meta.url));
10290
- const token = randomBytes3(24).toString("base64url");
10291
- const port = Number(o.port);
10292
- const url = `http://127.0.0.1:${port}/app/session?token=${token}`;
10580
+ program.command("update").description("update Nomad to the newest version (when installed from thenomad.website)").option("--check", "only check whether a newer version exists").option("-y, --yes", "update without asking").action(async (o) => {
10581
+ const install = currentInstall();
10582
+ if (!install) {
10583
+ const npx = process.env.npm_command === "exec";
10584
+ process.stderr.write(
10585
+ npx ? `npx runs the newest version each time, or add @latest: ${bold("npx thenomad@latest")}
10586
+ ` : `This copy of Nomad was not installed with the installer from thenomad.website.
10587
+ If you installed it with npm, update with: ${bold("npm install -g thenomad@latest")}
10588
+ `
10589
+ );
10590
+ return;
10591
+ }
10592
+ try {
10593
+ const c2 = await checkForUpdate(install);
10594
+ if (!c2.available) {
10595
+ process.stderr.write(`${green("Nomad is up to date")} (${install.version}).
10596
+ `);
10597
+ return;
10598
+ }
10599
+ process.stderr.write(`Nomad ${bold(c2.latest)} is available. You have ${install.version}.
10600
+ `);
10601
+ if (o.check) return;
10602
+ if (!o.yes && !await confirm("Update now?", true)) {
10603
+ process.exitCode = EXIT.approval;
10604
+ return;
10605
+ }
10606
+ const v = await applyUpdate(install, c2.latest, (l) => process.stderr.write(dim(l) + "\n"));
10607
+ process.stderr.write(`${green("Updated")} to Nomad ${v}. If the dashboard is open, close it and open Nomad again.
10608
+ `);
10609
+ } catch (e) {
10610
+ process.stderr.write(red("Error: ") + e.message + "\n");
10611
+ process.exitCode = EXIT.error;
10612
+ }
10613
+ });
10614
+ program.command("uninstall").description("remove Nomad from this computer (your agents are not touched)").option("-y, --yes", "do not ask; keeps your library, backups and history").option("--remove-data", "also delete the library, backups and history").action(async (o) => {
10615
+ const install = currentInstall();
10616
+ const dataDir = program.opts().home ? resolve7(program.opts().home) : nomadHome();
10617
+ if (!install) {
10618
+ process.stderr.write(
10619
+ `This copy of Nomad was not installed with the installer from thenomad.website.
10620
+ If you installed it with npm, remove it with: ${bold("npm uninstall -g thenomad")}
10621
+ Your library, backups and history stay in ${displayPath(dataDir)} until you delete that folder.
10622
+ `
10623
+ );
10624
+ return;
10625
+ }
10626
+ let removeData = !!o.removeData;
10627
+ if (!o.yes) {
10628
+ if (!process.stdin.isTTY) {
10629
+ process.stderr.write(`Run ${bold("nomad uninstall --yes")} to remove Nomad without questions.
10630
+ `);
10631
+ process.exitCode = EXIT.approval;
10632
+ return;
10633
+ }
10634
+ process.stderr.write(`This removes Nomad ${install.version} from ${displayPath(install.root)}, with its shortcut and the nomad command.
10635
+ Your agents are not touched.
10636
+ `);
10637
+ if (!await confirm("Remove Nomad?")) {
10638
+ process.exitCode = EXIT.approval;
10639
+ return;
10640
+ }
10641
+ if (!removeData && existsSync7(join20(dataDir, "nomad.db"))) removeData = await confirm(`Also delete the library, backups and history in ${displayPath(dataDir)}? Backups cannot be restored after this.`);
10642
+ }
10643
+ if (!runUninstaller(install, { removeData, dataDir })) {
10644
+ process.stderr.write(red("Error: ") + `The uninstaller is missing from ${displayPath(join20(install.root, "bin"))}. Delete ${displayPath(install.root)} to remove Nomad.
10645
+ `);
10646
+ process.exitCode = EXIT.error;
10647
+ return;
10648
+ }
10649
+ if (process.platform === "win32") process.stderr.write(`${green("Removing Nomad.")} It will be gone in a few seconds.${removeData ? "" : ` Your library, backups and history stay in ${displayPath(dataDir)}.`}
10650
+ `);
10651
+ });
10652
+ program.command("ui").description("open the dashboard in your browser (only this computer can reach it)").option("-p, --port <port>", "port", "4317").option("--no-open", "do not open a browser").option("--dev", "developers: run the Next.js app from the repository with live reload").addOption(new Option("--app").hideHelp()).action(async (o) => {
10653
+ const here = dirname7(fileURLToPath(import.meta.url));
10654
+ const token = randomBytes4(24).toString("base64url");
10655
+ let port = Number(o.port);
10656
+ let url = `http://127.0.0.1:${port}/app/session?token=${token}`;
10293
10657
  const openBrowser = () => {
10294
10658
  if (!o.open) return;
10295
10659
  const [cmd, args] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", url]] : ["xdg-open", [url]];
10296
10660
  spawn2(cmd, args, { stdio: "ignore", detached: true }).on("error", () => void 0).unref();
10297
10661
  };
10298
10662
  if (o.dev) {
10299
- const webDir = [resolve6(here, "../../web"), resolve6(process.cwd(), "apps/web")].find((d) => existsSync6(join19(d, "package.json")));
10663
+ const webDir = [resolve7(here, "../../web"), resolve7(process.cwd(), "apps/web")].find((d) => existsSync7(join20(d, "package.json")));
10300
10664
  if (!webDir) {
10301
10665
  process.stderr.write(red("--dev needs the repository checkout.\n"));
10302
10666
  process.exitCode = 1;
10303
10667
  return;
10304
10668
  }
10305
- const env = { ...process.env, NOMAD_LOCAL: "1", NOMAD_LOCAL_TOKEN: token, NOMAD_HOME: program.opts().home ? resolve6(program.opts().home) : nomadHome(), PORT: String(port) };
10669
+ const env = { ...process.env, NOMAD_LOCAL: "1", NOMAD_LOCAL_TOKEN: token, NOMAD_HOME: program.opts().home ? resolve7(program.opts().home) : nomadHome(), PORT: String(port) };
10306
10670
  process.stderr.write(`${bold("Nomad")} dev server at ${url}
10307
10671
  `);
10308
- const child = spawn2(process.execPath, [join19(webDir, "node_modules", "next", "dist", "bin", "next"), "dev", "-H", "127.0.0.1", "-p", String(port)], { cwd: webDir, env, stdio: ["ignore", "inherit", "inherit"] });
10672
+ const child = spawn2(process.execPath, [join20(webDir, "node_modules", "next", "dist", "bin", "next"), "dev", "-H", "127.0.0.1", "-p", String(port)], { cwd: webDir, env, stdio: ["ignore", "inherit", "inherit"] });
10309
10673
  setTimeout(openBrowser, 2500);
10310
10674
  child.on("exit", (code) => process.exitCode = code ?? 0);
10311
10675
  return;
@@ -10318,7 +10682,16 @@ program.command("ui").description("open the dashboard in your browser (only this
10318
10682
  }
10319
10683
  const nomad = engine();
10320
10684
  try {
10321
- await startUi({ nomad, site, port, token });
10685
+ for (let tries = 0; ; tries++) {
10686
+ try {
10687
+ await startUi({ nomad, site, port, token, appUpdates: !!currentInstall() });
10688
+ break;
10689
+ } catch (e) {
10690
+ if (!o.app || tries >= 20 || e.code !== "EADDRINUSE") throw e;
10691
+ port += 1;
10692
+ url = `http://127.0.0.1:${port}/app/session?token=${token}`;
10693
+ }
10694
+ }
10322
10695
  } catch (e) {
10323
10696
  nomad.close();
10324
10697
  const busy = e.code === "EADDRINUSE";
@@ -10327,9 +10700,11 @@ program.command("ui").description("open the dashboard in your browser (only this
10327
10700
  process.exitCode = 1;
10328
10701
  return;
10329
10702
  }
10330
- process.stderr.write(`${bold("Nomad")} is open at ${url}
10331
- ${dim("Only this computer can reach it. Press Ctrl+C to stop.")}
10332
- `);
10703
+ process.stderr.write(
10704
+ `${bold("Nomad")} is open at ${url}
10705
+ ${dim(o.app ? "Only this computer can reach it. Keep this window open while you use Nomad, and close it to stop." : "Only this computer can reach it. Press Ctrl+C to stop.")}
10706
+ `
10707
+ );
10333
10708
  openBrowser();
10334
10709
  const stop = () => {
10335
10710
  nomad.close();
@@ -10368,8 +10743,8 @@ async function guided(nomad) {
10368
10743
  if (items.length === 1) process.stderr.write(dim("No agents were found at the usual places. You can open a package file.") + "\n");
10369
10744
  const pick = await choose(rl, "Which agent?", items);
10370
10745
  if (pick === "file") {
10371
- const path = resolve6((await rl.question("Path to the file: ")).trim().replace(/^~(?=$|\/)/, process.env.HOME ?? "~"));
10372
- if (!existsSync6(path)) throw new NomadError(`There is no file at ${path}.`, "not-found");
10746
+ const path = resolve7((await rl.question("Path to the file: ")).trim().replace(/^~(?=$|\/)/, process.env.HOME ?? "~"));
10747
+ if (!existsSync7(path)) throw new NomadError(`There is no file at ${path}.`, "not-found");
10373
10748
  source = { kind: "package", path };
10374
10749
  from = null;
10375
10750
  } else {
@@ -10391,7 +10766,7 @@ async function guided(nomad) {
10391
10766
  const name = (await nomad.loadSource(source).catch(() => null))?.doc.name ?? "agent";
10392
10767
  const def = `./${name.replace(/[^A-Za-z0-9._-]+/g, "-")}.nomad`;
10393
10768
  const a = (await rl.question(`Save to ${dim(`[${def}]`)}: `)).trim();
10394
- dest = { kind: "file", path: resolve6(a || def) };
10769
+ dest = { kind: "file", path: resolve7(a || def) };
10395
10770
  } else {
10396
10771
  const info = getAdapter(where).info;
10397
10772
  const def = info.defaultLocations[0] ?? displayPath(process.cwd());