@slayzone/cli 0.36.3 → 0.36.4

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 (2) hide show
  1. package/dist/slay.js +161 -49
  2. package/package.json +1 -1
package/dist/slay.js CHANGED
@@ -16599,8 +16599,19 @@ function envTarget() {
16599
16599
  function flagTarget() {
16600
16600
  return hubOverride ? { ...hubOverride, source: "flag" } : null;
16601
16601
  }
16602
+ function relayTarget() {
16603
+ if (!isTaskTerminal()) return null;
16604
+ const address = process.env.SLAYZONE_CLI_RELAY_ADDRESS;
16605
+ const token = process.env.SLAYZONE_CLI_RELAY_TOKEN;
16606
+ if (!address && !token) return null;
16607
+ if (!address || !/^127\.0\.0\.1:\d+$/.test(address) || !isBareAuthority(address) || !token) {
16608
+ console.error("Invalid task CLI relay configuration. Open a new task terminal.");
16609
+ process.exit(1);
16610
+ }
16611
+ return { baseUrl: `http://${address}`, token, source: "relay", hubUrl: envTarget()?.baseUrl };
16612
+ }
16602
16613
  function resolveTaskCommandTarget() {
16603
- return flagTarget() ?? envTarget() ?? (isTaskTerminal() ? null : storedTarget(true));
16614
+ return flagTarget() ?? relayTarget() ?? envTarget() ?? (isTaskTerminal() ? null : storedTarget(true));
16604
16615
  }
16605
16616
  function resolveHubCommandTarget() {
16606
16617
  const flag = flagTarget();
@@ -16696,7 +16707,8 @@ async function isCoLocatedHub() {
16696
16707
  // src/api.ts
16697
16708
  async function resolveTarget() {
16698
16709
  const hub = resolveTaskCommandTarget();
16699
- if (hub) return { baseUrl: hub.baseUrl, token: hub.token, hub: true };
16710
+ if (hub)
16711
+ return { baseUrl: hub.baseUrl, token: hub.token, hub: true, relay: hub.source === "relay" };
16700
16712
  if (isTaskTerminal() && !process.env.SLAYZONE_ROOT?.trim()) {
16701
16713
  console.error(
16702
16714
  "This is a task terminal (SLAYZONE_TASK_ID is set), but it does not say which app\nspawned it: neither SLAYZONE_HUB_ADDRESS nor SLAYZONE_ROOT is set. Refusing to guess.\nOpen a new terminal from the app, or name the hub with `slay --hub <name|port>`."
@@ -16728,7 +16740,11 @@ function withAuth(init, token) {
16728
16740
  return { ...init, headers };
16729
16741
  }
16730
16742
  function connectError(target) {
16731
- if (target.hub) {
16743
+ if (target.relay) {
16744
+ console.error(
16745
+ "Task CLI relay is unavailable. Check the computer connection and open a new task terminal."
16746
+ );
16747
+ } else if (target.hub) {
16732
16748
  console.error(`Could not connect to SlayZone hub at ${target.baseUrl}.`);
16733
16749
  } else {
16734
16750
  console.error("SlayZone is not running (could not connect to app).");
@@ -21907,7 +21923,6 @@ var import_node_stream = require("node:stream");
21907
21923
  var import_promises2 = require("node:stream/promises");
21908
21924
 
21909
21925
  // ../../domains/task-contracts/src/types.ts
21910
- var COLD_RESPAWN_MS = 30 * 60 * 1e3;
21911
21926
  var px = (value) => ({ value, unit: "px" });
21912
21927
  var PANEL_LAYOUT_DEFAULTS = {
21913
21928
  terminal: { unit: "fr", value: 1, min: px(200), align: "left" },
@@ -22885,6 +22900,7 @@ function narrowProject(p) {
22885
22900
  name: p.name,
22886
22901
  color: p.color,
22887
22902
  path: p.path ?? null,
22903
+ computer_id: p.resolved_computer_id ?? null,
22888
22904
  created_at: p.created_at,
22889
22905
  updated_at: p.updated_at
22890
22906
  };
@@ -22918,6 +22934,52 @@ function ensureProjectPath(projectPath) {
22918
22934
  }
22919
22935
  return !existedBefore;
22920
22936
  }
22937
+ async function resolveHubComputer(ref) {
22938
+ const computers = await apiGet("/api/computers");
22939
+ const wanted = ref.trim().toLowerCase();
22940
+ const exact = computers.find((c) => c.id === ref.trim());
22941
+ const byName = computers.filter((c) => c.name.toLowerCase() === wanted);
22942
+ const byPrefix = computers.filter((c) => c.id.toLowerCase().startsWith(wanted));
22943
+ const matches = exact ? [exact] : byName.length > 0 ? byName : byPrefix;
22944
+ if (matches.length === 1) return matches[0];
22945
+ const available = computers.length > 0 ? ` Available: ${computers.map((c) => `${c.name} (${c.id.slice(0, 8)})`).join(", ")}` : " This hub has no computers.";
22946
+ console.error(
22947
+ matches.length === 0 ? `No computer matching "${ref}".${available}` : `Ambiguous computer "${ref}".${available}`
22948
+ );
22949
+ process.exit(1);
22950
+ }
22951
+ function isAbsoluteAnywhere(p) {
22952
+ return import_node_path4.default.posix.isAbsolute(p) || import_node_path4.default.win32.isAbsolute(p);
22953
+ }
22954
+ async function prepareFolder(input, computer) {
22955
+ const local = computer === null && await isCoLocatedHub();
22956
+ const trimmed = input?.trim() || null;
22957
+ if (!trimmed) return { path: null, local };
22958
+ if (local) return { path: normalizeProjectPath(trimmed), local };
22959
+ if (!isAbsoluteAnywhere(trimmed)) {
22960
+ const where = computer ? `computer "${computer.name}"` : "the hub\u2019s computer";
22961
+ console.error(
22962
+ `--path must be absolute: it is a folder on ${where}, not on this machine, so it cannot be resolved from here.`
22963
+ );
22964
+ process.exit(1);
22965
+ }
22966
+ return { path: trimmed, local };
22967
+ }
22968
+ function warnUnreadyFolder(project, computer, folder) {
22969
+ if (!folder) return;
22970
+ const computerId = computer?.id ?? project.resolved_computer_id;
22971
+ const placement = (project.placements ?? []).find(
22972
+ (pl) => pl.computer_id === computerId
22973
+ );
22974
+ const name = computer ? `"${computer.name}"` : "the project\u2019s computer";
22975
+ if (placement?.status === "missing") {
22976
+ console.error(
22977
+ `Folder not found on ${name}: ${folder}. Create it there; agents start once it exists.`
22978
+ );
22979
+ } else if (placement?.status === "pending") {
22980
+ console.error(`${name} is offline. The folder is recorded when it connects: ${folder}`);
22981
+ }
22982
+ }
22921
22983
  function projectsCommand() {
22922
22984
  const cmd = new Command("projects").description("Manage projects").showSuggestionAfterError(true).showHelpAfterError(true);
22923
22985
  cmd.command("list").description("List all projects").option("--json", "Output as JSON").action(async (opts) => {
@@ -22930,65 +22992,98 @@ function projectsCommand() {
22930
22992
  console.log("No projects found.");
22931
22993
  return;
22932
22994
  }
22995
+ const computerNames = /* @__PURE__ */ new Map();
22996
+ const computersRes = await apiFetch("/api/computers").catch(() => null);
22997
+ if (computersRes?.ok) {
22998
+ const computers = await computersRes.json().catch(() => []);
22999
+ for (const c of computers) computerNames.set(c.id, c.name);
23000
+ }
22933
23001
  const idW = 9;
22934
23002
  const nameW = 24;
22935
- console.log(`${"ID".padEnd(idW)} ${"NAME".padEnd(nameW)} TASKS PATH`);
22936
- console.log(`${"-".repeat(idW)} ${"-".repeat(nameW)} ----- ${"-".repeat(30)}`);
23003
+ const computerW = 16;
23004
+ console.log(
23005
+ `${"ID".padEnd(idW)} ${"NAME".padEnd(nameW)} TASKS ${"COMPUTER".padEnd(computerW)} PATH`
23006
+ );
23007
+ console.log(
23008
+ `${"-".repeat(idW)} ${"-".repeat(nameW)} ----- ${"-".repeat(computerW)} ${"-".repeat(30)}`
23009
+ );
22937
23010
  for (const p of projects) {
22938
23011
  const id = String(p.id).slice(0, 8).padEnd(idW);
22939
23012
  const name = String(p.name).slice(0, nameW).padEnd(nameW);
22940
23013
  const tasks = String(p.task_count).padStart(5);
22941
- console.log(`${id} ${name} ${tasks} ${p.path}`);
23014
+ const computer = (p.computer_id ? computerNames.get(p.computer_id) ?? p.computer_id.slice(0, 8) : "-").slice(0, computerW).padEnd(computerW);
23015
+ console.log(`${id} ${name} ${tasks} ${computer} ${p.path ?? ""}`);
22942
23016
  }
22943
23017
  });
22944
23018
  cmd.command("create <name>").description("Create a new project").option(
22945
23019
  "--path <path>",
22946
- "Repository path (relative paths are resolved from current directory and auto-created)"
22947
- ).option("--color <hex>", "Project color (#RRGGBB)", DEFAULT_PROJECT_COLOR).option("--json", "Output created project as JSON").action(async (name, opts) => {
22948
- const projectPath = normalizeProjectPath(opts.path);
22949
- let prepared;
22950
- try {
22951
- prepared = prepareProjectCreate({ name, color: opts.color, path: projectPath });
22952
- } catch (error) {
22953
- const message = error instanceof Error ? error.message : String(error);
22954
- console.error(message);
22955
- process.exit(1);
22956
- }
22957
- const createdPath = ensureProjectPath(prepared.path);
22958
- if (createdPath && prepared.path) {
22959
- console.error(`Created directory: ${prepared.path}`);
22960
- }
22961
- const { data } = await apiPost("/api/projects", {
22962
- name: prepared.name,
22963
- color: prepared.color,
22964
- path: prepared.path
22965
- });
22966
- const project = narrowProject(data);
22967
- if (opts.json) {
22968
- console.log(JSON.stringify(project, null, 2));
22969
- return;
23020
+ "Repository path (relative paths are resolved from current directory and auto-created). With --computer, or a hub on another machine: an absolute path on that computer, used as is"
23021
+ ).option(
23022
+ "--computer <name|id>",
23023
+ "Computer the project runs on (its agents, and the --path folder). Default: the hub picks"
23024
+ ).option("--color <hex>", "Project color (#RRGGBB)", DEFAULT_PROJECT_COLOR).option("--json", "Output created project as JSON").action(
23025
+ async (name, opts) => {
23026
+ const computer = opts.computer ? await resolveHubComputer(opts.computer) : null;
23027
+ const folder = await prepareFolder(opts.path, computer);
23028
+ let prepared;
23029
+ try {
23030
+ prepared = prepareProjectCreate({ name, color: opts.color, path: folder.path });
23031
+ } catch (error) {
23032
+ const message = error instanceof Error ? error.message : String(error);
23033
+ console.error(message);
23034
+ process.exit(1);
23035
+ }
23036
+ if (folder.local) {
23037
+ const createdPath = ensureProjectPath(prepared.path);
23038
+ if (createdPath && prepared.path) {
23039
+ console.error(`Created directory: ${prepared.path}`);
23040
+ }
23041
+ }
23042
+ const { data } = await apiPost("/api/projects", {
23043
+ name: prepared.name,
23044
+ color: prepared.color,
23045
+ path: prepared.path,
23046
+ ...computer ? { computerId: computer.id } : {}
23047
+ });
23048
+ if (!folder.local) warnUnreadyFolder(data, computer, prepared.path);
23049
+ const project = narrowProject(data);
23050
+ if (opts.json) {
23051
+ console.log(JSON.stringify(project, null, 2));
23052
+ return;
23053
+ }
23054
+ const location = project.path ? ` ${project.path}` : "";
23055
+ const on2 = computer ? ` (on ${computer.name})` : "";
23056
+ console.log(`Created project: ${project.id.slice(0, 8)} ${project.name}${location}${on2}`);
22970
23057
  }
22971
- const location = project.path ? ` ${project.path}` : "";
22972
- console.log(`Created project: ${project.id.slice(0, 8)} ${project.name}${location}`);
22973
- });
22974
- cmd.command("update <name|id>").description("Update a project").option("--name <name>", "New project name").option("--color <hex>", "New project color (#RRGGBB)").option("--path <path>", "New repository path").option("--json", "Output updated project as JSON").action(
23058
+ );
23059
+ cmd.command("update <name|id>").description("Update a project").option("--name <name>", "New project name").option("--color <hex>", "New project color (#RRGGBB)").option(
23060
+ "--path <path>",
23061
+ "New repository path. With --computer, or a hub on another machine: an absolute path on that computer"
23062
+ ).option(
23063
+ "--computer <name|id>",
23064
+ "Move the project to this computer (its agents run there); --path is its folder there"
23065
+ ).option("--json", "Output updated project as JSON").action(
22975
23066
  async (proj, opts) => {
22976
- if (opts.name === void 0 && opts.color === void 0 && opts.path === void 0) {
22977
- console.error("Provide at least one of --name, --color, --path");
23067
+ if (opts.name === void 0 && opts.color === void 0 && opts.path === void 0 && opts.computer === void 0) {
23068
+ console.error("Provide at least one of --name, --color, --path, --computer");
22978
23069
  process.exit(1);
22979
23070
  }
23071
+ const computer = opts.computer ? await resolveHubComputer(opts.computer) : null;
22980
23072
  const body = {};
22981
23073
  if (opts.name !== void 0) body.name = opts.name;
22982
23074
  if (opts.color !== void 0) body.color = opts.color;
23075
+ if (computer) body.computerId = computer.id;
23076
+ let folder = null;
22983
23077
  if (opts.path !== void 0) {
22984
- const resolved = normalizeProjectPath(opts.path);
22985
- if (resolved) ensureProjectPath(resolved);
22986
- body.path = resolved;
23078
+ folder = await prepareFolder(opts.path, computer);
23079
+ if (folder.local && folder.path) ensureProjectPath(folder.path);
23080
+ body.path = folder.path;
22987
23081
  }
22988
23082
  const { data } = await apiPatch(
22989
23083
  `/api/projects/${encodeURIComponent(proj)}`,
22990
23084
  body
22991
23085
  );
23086
+ if (folder && !folder.local) warnUnreadyFolder(data, computer, folder.path);
22992
23087
  const updated = narrowProject(data);
22993
23088
  if (opts.json) {
22994
23089
  console.log(JSON.stringify(updated, null, 2));
@@ -26539,7 +26634,7 @@ var import_node_child_process3 = require("node:child_process");
26539
26634
  var import_node_fs7 = require("node:fs");
26540
26635
  var import_node_module = require("node:module");
26541
26636
  var import_node_path8 = require("node:path");
26542
- var CLI_VERSION = true ? "0.36.3" : "";
26637
+ var CLI_VERSION = true ? "0.36.4" : "";
26543
26638
  function fail(message) {
26544
26639
  console.error(message);
26545
26640
  process.exit(1);
@@ -27836,6 +27931,8 @@ function describeTargetSource(target) {
27836
27931
  switch (target.source) {
27837
27932
  case "flag":
27838
27933
  return "--hub";
27934
+ case "relay":
27935
+ return "authenticated computer CLI relay";
27839
27936
  case "break-glass":
27840
27937
  return `break-glass session, ${getBreakGlassSessionPath()}`;
27841
27938
  case "env":
@@ -27846,10 +27943,13 @@ function describeTargetSource(target) {
27846
27943
  }
27847
27944
  async function probeHealth(target) {
27848
27945
  try {
27849
- const res = await fetch(`${target.baseUrl}/health`, {
27850
- headers: target.token ? { Authorization: `Bearer ${target.token}` } : {},
27851
- signal: AbortSignal.timeout(5e3)
27852
- });
27946
+ const res = await fetch(
27947
+ `${target.baseUrl}${target.source === "relay" ? "/api/computers" : "/health"}`,
27948
+ {
27949
+ headers: target.token ? { Authorization: `Bearer ${target.token}` } : {},
27950
+ signal: AbortSignal.timeout(5e3)
27951
+ }
27952
+ );
27853
27953
  return res.ok ? { ok: true, line: `Health: ok (HTTP ${res.status})` } : { ok: false, line: `Health: failed (HTTP ${res.status})` };
27854
27954
  } catch {
27855
27955
  return { ok: false, line: `Health: unreachable (could not connect to ${target.baseUrl})` };
@@ -27857,14 +27957,23 @@ async function probeHealth(target) {
27857
27957
  }
27858
27958
  function hubCommand() {
27859
27959
  const cmd = new Command("hub").description("Run, list and target SlayZone hubs").showSuggestionAfterError(true).showHelpAfterError(true);
27860
- cmd.command("ls").description("List the hubs running on this machine").option("--json", "Output as JSON").action(async (opts) => {
27960
+ cmd.command("ls").description("List local hubs and the remote task hub target").option("--json", "Output as JSON").option("--json-v2", "Output versioned JSON including the task hub target").action(async (opts) => {
27861
27961
  const hubs = await discoverAllHubs();
27962
+ const target = isTaskTerminal() ? resolveTaskCommandTarget() : null;
27963
+ const url = target?.hubUrl ?? target?.baseUrl;
27964
+ const taskHub = url ? { url, connection: target.source === "relay" ? "relay" : "configured", verified: false } : null;
27965
+ if (opts.jsonV2) {
27966
+ console.log(JSON.stringify({ version: 2, hubs, taskHub }, null, 2));
27967
+ return;
27968
+ }
27862
27969
  if (opts.json) {
27863
27970
  console.log(JSON.stringify(hubs, null, 2));
27864
27971
  return;
27865
27972
  }
27866
27973
  if (hubs.length === 0) {
27867
- console.log("No hubs running. Create one with `slay hub create <name>`.");
27974
+ if (taskHub)
27975
+ console.log(`Task hub: ${taskHub.url} (${taskHub.connection}; connection not checked)`);
27976
+ else console.log("No hubs running. Create one with `slay hub create <name>`.");
27868
27977
  return;
27869
27978
  }
27870
27979
  const nameW = Math.max(4, ...hubs.map((h) => h.name.length));
@@ -27886,6 +27995,9 @@ function hubCommand() {
27886
27995
  `${h.name.padEnd(nameW)} ${String(h.port).padEnd(5)} ${String(h.pid).padEnd(7)} ${root.padEnd(rootW)} ${String(h.computersConnected).padEnd(9)} ${formatUptime(h.uptimeMs)}${mine}`
27887
27996
  );
27888
27997
  }
27998
+ if (taskHub)
27999
+ console.log(`
28000
+ Task hub: ${taskHub.url} (${taskHub.connection}; connection not checked)`);
27889
28001
  });
27890
28002
  cmd.command("create <name>").description("Create a hub here and keep it running (crash-restart + start at login)").option("--root <dir>", "Hub root \u2014 its config, storage and logs (default: cwd)").option("--port <port>", "Bind a specific port (default: first free hub port)").option(
27891
28003
  "--public-address <host[:port]>",
@@ -28221,7 +28333,7 @@ then \`slay hub start ${name}\`.`
28221
28333
  console.log(` Hub: ${none}`);
28222
28334
  continue;
28223
28335
  }
28224
- console.log(` Hub: ${target.baseUrl}`);
28336
+ console.log(` Hub: ${target.hubUrl ?? target.baseUrl}`);
28225
28337
  console.log(` Source: ${describeTargetSource(target)}`);
28226
28338
  console.log(` Token: ${target.token ? "set" : "not set"}`);
28227
28339
  const key = `${target.baseUrl}
@@ -29104,7 +29216,7 @@ function updateCommand() {
29104
29216
  }
29105
29217
 
29106
29218
  // src/index.ts
29107
- var program2 = new Command().name("slay").description("SlayZone CLI").version("0.36.3").option("--dev", "Use development database (slayzone.dev.data.sqlite)").option("--hub <name|port>", "Target a specific hub on this machine (see `slay hub ls`)").showSuggestionAfterError(true).showHelpAfterError(true).hook("preAction", async (thisCommand) => {
29219
+ var program2 = new Command().name("slay").description("SlayZone CLI").version("0.36.4").option("--dev", "Use development database (slayzone.dev.data.sqlite)").option("--hub <name|port>", "Target a specific hub on this machine (see `slay hub ls`)").showSuggestionAfterError(true).showHelpAfterError(true).hook("preAction", async (thisCommand) => {
29108
29220
  const root = thisCommand.parent ?? thisCommand;
29109
29221
  const opts = root.opts();
29110
29222
  if (opts.dev) process.env.SLAYZONE_DEV = "1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slayzone/cli",
3
- "version": "0.36.3",
3
+ "version": "0.36.4",
4
4
  "description": "SlayZone CLI — run, list and target SlayZone hubs; drive tasks, ptys and projects",
5
5
  "license": "GPL-3.0-only",
6
6
  "private": false,