@tablation/crew 0.169.5 → 0.170.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +154 -9
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -5164,6 +5164,24 @@ function credentialSource(r) {
5164
5164
  }
5165
5165
  return process.env.CREW_API_KEY?.trim() ? "CREW_API_KEY" : "none";
5166
5166
  }
5167
+ function siblingRouteKey(routes, host, sameWorkspace, hostOf) {
5168
+ for (const r of routes) {
5169
+ const [workspace] = splitRoute(r.route);
5170
+ if (hostOf(r.baseUrl) !== host || !sameWorkspace(workspace)) continue;
5171
+ const source = credentialSource(r);
5172
+ if (source === "none") continue;
5173
+ try {
5174
+ return {
5175
+ apiKey: resolveApiKey(r),
5176
+ source,
5177
+ workspace,
5178
+ ...source === "apiKeyFile" ? { apiKeyFile: r.apiKeyFile, apiKeyVar: r.apiKeyVar } : {}
5179
+ };
5180
+ } catch {
5181
+ }
5182
+ }
5183
+ return void 0;
5184
+ }
5167
5185
  var KEYCHAIN_ELIGIBLE_ROUTES = /* @__PURE__ */ new WeakSet();
5168
5186
  async function hydrateApiKeys(routes, getStore = getSessionStore) {
5169
5187
  let store;
@@ -26843,6 +26861,98 @@ function fallbackStateDir(configFile) {
26843
26861
  return join55(dirname30(configFile), "state");
26844
26862
  }
26845
26863
 
26864
+ // src/routes-available.ts
26865
+ var lower = (s) => s.trim().toLowerCase();
26866
+ async function buildRoutesAvailable(routes, deps) {
26867
+ const doFetch = deps.fetch ?? fetch;
26868
+ const hosts = /* @__PURE__ */ new Map();
26869
+ for (const r of routes) {
26870
+ const h = deps.hostOf(r.baseUrl);
26871
+ hosts.set(h, [...hosts.get(h) ?? [], r]);
26872
+ }
26873
+ const existing = new Set(routes.map((r) => {
26874
+ const [ws, proj] = splitRoute(r.route);
26875
+ return `${deps.hostOf(r.baseUrl)}|${lower(ws)}|${lower(proj)}`;
26876
+ }));
26877
+ const get2 = (r, key, path) => doFetch(`${r.baseUrl.replace(/\/+$/, "")}/api${path}`, {
26878
+ headers: { Authorization: `Bearer ${key}`, "User-Agent": deps.userAgent ?? "Mozilla/5.0 TablationCrewAgent/1.0" }
26879
+ });
26880
+ return Promise.all([...hosts].map(async ([host, hostRoutes]) => {
26881
+ let keyed = 0;
26882
+ for (const r of hostRoutes) {
26883
+ let key;
26884
+ try {
26885
+ key = resolveApiKey(r);
26886
+ } catch {
26887
+ continue;
26888
+ }
26889
+ keyed++;
26890
+ let res;
26891
+ try {
26892
+ res = await get2(r, key, "/auth/my-tracker-apps");
26893
+ } catch (e) {
26894
+ return { host, error: e.message, reason: "failed" };
26895
+ }
26896
+ if (res.status === 401 || res.status === 403) continue;
26897
+ if (res.status === 404) return { host, error: "this Tablation host does not offer the tracker app list yet", reason: "unsupported" };
26898
+ if (!res.ok) return { host, error: `/auth/my-tracker-apps answered HTTP ${res.status}`, reason: "failed" };
26899
+ const apps = await res.json();
26900
+ const list = Array.isArray(apps) ? apps : apps.apps ?? [];
26901
+ let email = null;
26902
+ try {
26903
+ const me = await get2(r, key, "/auth/me");
26904
+ if (me.ok) email = (await me.json()).email ?? null;
26905
+ } catch {
26906
+ }
26907
+ const signIn = /* @__PURE__ */ new Map();
26908
+ const out = [];
26909
+ for (const a of list) {
26910
+ const address = a.workspace.path || a.workspace.slug;
26911
+ if (existing.has(`${host}|${lower(address)}|${lower(a.project.slug)}`)) continue;
26912
+ if (!signIn.has(address)) {
26913
+ const sibling = siblingRouteKey(hostRoutes, host, (w) => lower(w) === lower(address), deps.hostOf);
26914
+ signIn.set(address, !sibling && !await deps.holdsCredential(host, address).catch(() => false));
26915
+ }
26916
+ out.push({
26917
+ route: `${address}/${a.project.slug}`,
26918
+ workspace: { address, name: a.workspace.name, role: a.workspace.role },
26919
+ project: { slug: a.project.slug, name: a.project.name },
26920
+ accepted: a.interfaceVersion === null || versionAccepted(a.interfaceVersion),
26921
+ needsSignIn: signIn.get(address)
26922
+ });
26923
+ }
26924
+ return { host, identity: { email }, routes: out };
26925
+ }
26926
+ return keyed === 0 ? { host, error: "no route on this host has a usable key", reason: "no_key" } : { host, error: "every key on this host was rejected", reason: "rejected" };
26927
+ }));
26928
+ }
26929
+ function formatRoutesAvailable(report, hadRoutes) {
26930
+ if (!hadRoutes) return "No routes are configured, so there is nothing to list from. `crew connect` is the first-run path.\n";
26931
+ const lines2 = [];
26932
+ let any = false;
26933
+ for (const h of report) {
26934
+ if ("error" in h) {
26935
+ lines2.push(`${h.host}: ${h.error}`);
26936
+ continue;
26937
+ }
26938
+ if (report.length > 1) lines2.push(`${h.host}${h.identity.email ? ` (${h.identity.email})` : ""}`);
26939
+ const byWs = /* @__PURE__ */ new Map();
26940
+ for (const r of h.routes) byWs.set(r.workspace.address, [...byWs.get(r.workspace.address) ?? [], r]);
26941
+ for (const [, rs] of [...byWs].sort((a, b) => a[1][0].workspace.name.localeCompare(b[1][0].workspace.name))) {
26942
+ any = true;
26943
+ lines2.push(rs[0].workspace.name);
26944
+ for (const r of rs.sort((a, b) => a.project.name.localeCompare(b.project.name))) {
26945
+ const marks = [!r.accepted ? `needs a newer crew (accepts ${acceptedLabel()})` : "", r.needsSignIn ? "sign-in needed" : ""].filter(Boolean);
26946
+ lines2.push(` ${r.project.name} ${r.route}${marks.length ? ` [${marks.join("; ")}]` : ""}`);
26947
+ }
26948
+ }
26949
+ }
26950
+ if (!any && report.some((h) => !("error" in h))) lines2.push("Every tracker app you can reach is already routed on this machine.");
26951
+ if (any) lines2.push("", "Add one with `crew connect <route>`.");
26952
+ return `${lines2.join("\n")}
26953
+ `;
26954
+ }
26955
+
26846
26956
  // src/projects-cmd.ts
26847
26957
  async function buildProjectsReport(routes, open2) {
26848
26958
  return Promise.all(routes.map(async (r) => {
@@ -28315,7 +28425,8 @@ function renderConnection(d, route2, dir, opts = {}) {
28315
28425
  apiKeyVar: ${opts.apiKeyVar}` : "";
28316
28426
  const baseUrlLine = opts.baseUrl && opts.baseUrl.replace(/\/+$/, "") !== DEFAULT_BASE_URL ? ` baseUrl: "${opts.baseUrl}"
28317
28427
  ` : "";
28318
- const keyLines = [apiKeyFileLine, apiKeyVarLine.replace(/^\n/, "")].filter(Boolean).join("\n");
28428
+ const inlineKeyLine = !opts.keychainBacked && opts.inlineApiKey ? ` apiKey: "${opts.inlineApiKey}"` : "";
28429
+ const keyLines = [apiKeyFileLine, apiKeyVarLine.replace(/^\n/, ""), inlineKeyLine].filter(Boolean).join("\n");
28319
28430
  return ` - route: ${route2}
28320
28431
  enabled: false # set to true once \`crew doctor\` is green
28321
28432
  ${opts.area ? ` area: "${opts.area}"
@@ -29948,7 +30059,7 @@ import { dirname as dirOf2, resolve as resolvePath } from "path";
29948
30059
  import { existsSync as existsSync56, readdirSync as readdirSync18, statSync as statSync17 } from "fs";
29949
30060
  import { join as join61 } from "path";
29950
30061
  function builtVersion() {
29951
- return true ? "0.169.5" : null;
30062
+ return true ? "0.170.0" : null;
29952
30063
  }
29953
30064
  var REBUILD_HINT = "rebuild with npm run build";
29954
30065
  function newestMtime(path) {
@@ -32149,6 +32260,7 @@ function usage(problem, requested = false) {
32149
32260
  crew --version [--json] print the crew version on one line (also: crew version); --json adds home and compiled
32150
32261
  crew status [route] [--json] [--verbose] what is running and what needs a person; --verbose adds configuration and full lists; --json for a machine reader
32151
32262
  crew projects [--route R] [--json] the Projects rows each route can read (id, name, prefix, work mode)
32263
+ crew routes available [--json] the tracker apps you can reach that this machine has no route for (read-only; starts no sign-in)
32152
32264
  crew projects add [route] NAME --prefix P [--work-mode automatic|hybrid|manual] [--json] [--dry-run] create a Projects row
32153
32265
  crew provision --key K --route WS[/PROJECT] [--forge-host H] [--ship-name N] [--json] one non-interactive run: connect, forge tokens,
32154
32266
  enable routes, install units with lingering, start the daemon; safe to re-run (CREW_CONNECT_KEY,
@@ -32303,6 +32415,7 @@ var KNOWN_COMMANDS = /* @__PURE__ */ new Set([
32303
32415
  "projects",
32304
32416
  "reap",
32305
32417
  "release",
32418
+ "routes",
32306
32419
  "reload",
32307
32420
  "repos",
32308
32421
  "resume",
@@ -32741,8 +32854,8 @@ if (command === "passenger-sync-daemon") {
32741
32854
  firstRun = { answers, configPath };
32742
32855
  cfg = loadConfig(CREW_HOME, configPath, { text: renderShipBlock(answers), allowNoRoutes: true });
32743
32856
  } else {
32744
- const toleratesNoRoutes = command === "credential" || command === "forge" || command === "repos" || command === "ship" || command === "disconnect" && flag("reset") || command === "deprovision" || command === "connect" && flag("sign-out");
32745
- const configless = command === "connect" && flag("sign-out") || command === "disconnect" && flag("reset") || command === "deprovision";
32857
+ const toleratesNoRoutes = command === "routes" || command === "credential" || command === "forge" || command === "repos" || command === "ship" || command === "disconnect" && flag("reset") || command === "deprovision" || command === "connect" && flag("sign-out");
32858
+ const configless = command === "routes" || command === "connect" && flag("sign-out") || command === "disconnect" && flag("reset") || command === "deprovision";
32746
32859
  if (configless && !existsSync60(findConfigFile(CREW_HOME))) {
32747
32860
  cfg = loadConfig(CREW_HOME, firstRunConfigPath(), { text: "ship: {}\n", allowNoRoutes: true });
32748
32861
  } else {
@@ -32800,7 +32913,7 @@ if (command === "passenger-sync-daemon") {
32800
32913
  const DAEMON_SUBCOMMANDS = /* @__PURE__ */ new Set(["start", "stop", "status", "restart"]);
32801
32914
  const worktreeArgs = command === "worktree" ? splitWorktreeArgs(positional, cfg.routes.map((r) => r.route)) : void 0;
32802
32915
  const named = worktreeArgs ? worktreeArgs.route : command === "daemon" && DAEMON_SUBCOMMANDS.has(positional[1] ?? "") ? positional[2] : positional[1];
32803
- const fleetWide = command === "inbox" || command === "connect" || command === "disconnect" || command === "deprovision" || command === "agents" || command === "skills" || command === "logbook" || command === "repos" || command === "ship" || command === "projects" || command === "periscope" || command === "whoami" || command === "sandbox" || releaseFleetWide || // CREW-3875: the scheduler units are per ship and name no route, so a route given is ignored.
32916
+ const fleetWide = command === "inbox" || command === "connect" || command === "disconnect" || command === "deprovision" || command === "agents" || command === "skills" || command === "logbook" || command === "repos" || command === "ship" || command === "projects" || command === "routes" || command === "periscope" || command === "whoami" || command === "sandbox" || releaseFleetWide || // CREW-3875: the scheduler units are per ship and name no route, so a route given is ignored.
32804
32917
  command === "install" || command === "uninstall" || command === "pause" || command === "resume" || command === "reload" || FLEET_CAPABLE.has(command) && !named && cfg.routes.length > 1 || worktreeArgs !== void 0 && !named && cfg.routes.length > 1;
32805
32918
  let route2;
32806
32919
  try {
@@ -35803,8 +35916,9 @@ ${reconstruction.prompt}
35803
35916
  let workspace = argWorkspace ?? value("workspace-id") ?? value("workspace") ?? connectChoices.workspace;
35804
35917
  const project = argProject ?? value("project") ?? connectChoices.project;
35805
35918
  const baseUrl = value("base-url") ?? cfg.routes[0]?.baseUrl ?? DEFAULT_BASE_URL;
35806
- let apiKey = value("key") ?? process.env.CREW_CONNECT_KEY ?? cfg.routes.find((c) => c.apiKey)?.apiKey;
35919
+ let apiKey = value("key") ?? process.env.CREW_CONNECT_KEY ?? (workspace ? void 0 : cfg.routes.find((c) => c.apiKey)?.apiKey);
35807
35920
  const givenKeySource = value("key") ?? process.env.CREW_CONNECT_KEY ? "flag" : "config";
35921
+ let siblingKey;
35808
35922
  let store;
35809
35923
  try {
35810
35924
  store = getSessionStore();
@@ -35833,6 +35947,19 @@ ${reconstruction.prompt}
35833
35947
  } catch {
35834
35948
  }
35835
35949
  }
35950
+ if (!apiKey && workspace) {
35951
+ const host = hostFromUrl4(baseUrl);
35952
+ const full = rememberedAddressFor(cfg.ship.stateDir, host, workspace);
35953
+ siblingKey = siblingRouteKey(cfg.routes, host, (w) => w === workspace || w === full, hostFromUrl4);
35954
+ if (siblingKey) {
35955
+ apiKey = siblingKey.apiKey;
35956
+ if (siblingKey.source === "keychain") {
35957
+ keychainBacked = true;
35958
+ sessionAddress = siblingKey.workspace;
35959
+ }
35960
+ routineLine(`Reusing the key of the existing route in ${host}/${workspace}.`);
35961
+ }
35962
+ }
35836
35963
  let signInSource = apiKey ? "key" : "device";
35837
35964
  if (!apiKey && !workspace && store) {
35838
35965
  const resumable = await resumableSessions({
@@ -36274,7 +36401,9 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`, "fix the problems above, t
36274
36401
  }
36275
36402
  }
36276
36403
  }
36277
- if ((mintedFromDevice || firstRunFromFlags || keyFromFlag) && !keychainBacked) {
36404
+ if (siblingKey?.source === "apiKeyFile") {
36405
+ apiKeyFile = siblingKey.apiKeyFile;
36406
+ } else if (!siblingKey && (mintedFromDevice || firstRunFromFlags || keyFromFlag) && !keychainBacked) {
36278
36407
  apiKeyFile = apiKeyPathFor(cfg.ship.stateDir, route3);
36279
36408
  if (dryRun) {
36280
36409
  process.stderr.write(`(dry run) would write the API key to ${apiKeyFile}
@@ -36286,7 +36415,7 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`, "fix the problems above, t
36286
36415
  routineLine(`API key written to ${apiKeyFile}`);
36287
36416
  }
36288
36417
  }
36289
- const keyPersisted = keychainBacked || apiKeyFile !== void 0;
36418
+ const keyPersisted = keychainBacked || apiKeyFile !== void 0 || siblingKey !== void 0;
36290
36419
  const wizard = firstRun;
36291
36420
  const writeFirstRun = wizard !== void 0 && !dryRun && keyPersisted;
36292
36421
  const routeDir = value("dir");
@@ -36297,9 +36426,10 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`, "fix the problems above, t
36297
36426
  {
36298
36427
  area: value("area"),
36299
36428
  apiKeyFile,
36300
- apiKeyVar: apiKeyFile ? apiKeyVar : void 0,
36429
+ apiKeyVar: apiKeyFile ? siblingKey?.apiKeyVar ?? apiKeyVar : void 0,
36301
36430
  keychainBacked,
36302
36431
  baseUrl,
36432
+ ...siblingKey?.source === "inline" ? { inlineApiKey: siblingKey.apiKey } : {},
36303
36433
  ...writeFirstRun ? { hostPassengers: wizard.answers.hostPassengers } : {}
36304
36434
  }
36305
36435
  );
@@ -37994,6 +38124,21 @@ ${where.join("\n")}`);
37994
38124
  if (report.some((r) => !r.ok)) process.exitCode = 1;
37995
38125
  break;
37996
38126
  }
38127
+ case "routes": {
38128
+ if (positional[1] !== "available") die("crew routes", "unknown subcommand", "`crew routes available [--json]`", 2);
38129
+ const report = await buildRoutesAvailable(cfg.routes, {
38130
+ userAgent: cfg.ship.userAgent,
38131
+ hostOf: hostFromUrl4,
38132
+ holdsCredential: async (host, address) => {
38133
+ const s = getSessionStore();
38134
+ return !!(await s.get(host, address))?.apiKey;
38135
+ }
38136
+ });
38137
+ process.stdout.write(flag("json") ? `${JSON.stringify({ hosts: report }, null, 2)}
38138
+ ` : formatRoutesAvailable(report, cfg.routes.length > 0));
38139
+ if (report.length > 0 && report.every((h) => "error" in h)) process.exitCode = 1;
38140
+ break;
38141
+ }
37997
38142
  case "projects": {
37998
38143
  if (positional[1] === "add") {
37999
38144
  const rest = positional.slice(2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tablation/crew",
3
- "version": "0.169.5",
3
+ "version": "0.170.0",
4
4
  "description": "A standing team of headless agents that picks work off a Tablation board, does it on a machine you control, and reports back.",
5
5
  "type": "module",
6
6
  "license": "MIT",