@tablation/crew 0.157.0 → 0.157.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 (3) hide show
  1. package/README.md +2 -2
  2. package/dist/cli.js +67 -32
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -10,8 +10,8 @@ and reports back on the board.
10
10
 
11
11
  Each **seat** is a row in the board's Crew table that happens to be a robot,
12
12
  with a brief (`prompts/<promptSet>/`, see "Prompt sets" below) and a slice
13
- of the queue. A seat is named in that table and answers to that name, in the
14
- queue digest and in the comments it writes on tickets. Everything the crew
13
+ of the queue. A seat is linked to its Agents row and is found by that link, not its name; it
14
+ answers to the name in that table, in the queue digest and in the comments it writes on tickets. Everything the crew
15
15
  knows about a run — what to build, what is blocked, what has shipped — is
16
16
  table data, and every step it takes is visible as a status change or a
17
17
  comment on the ticket. There is no hidden state and no queue but the board.
package/dist/cli.js CHANGED
@@ -4454,6 +4454,18 @@ function readResolvedFile(stateDir, route2) {
4454
4454
  throw new ConfigError(`${path}: not valid JSON \u2014 ${e.message}`);
4455
4455
  }
4456
4456
  }
4457
+ function readStoredSeats(stateDir, route2) {
4458
+ let raw;
4459
+ try {
4460
+ raw = readResolvedFile(stateDir, route2);
4461
+ } catch {
4462
+ return void 0;
4463
+ }
4464
+ if (!raw || typeof raw !== "object") return void 0;
4465
+ const seats2 = {};
4466
+ for (const role of ROLE_NAMES) if (typeof raw.seats?.[role] === "string" && raw.seats[role]) seats2[role] = raw.seats[role];
4467
+ return { seats: seats2, ...typeof raw.releaseSeat === "string" && raw.releaseSeat ? { releaseSeat: raw.releaseSeat } : {} };
4468
+ }
4457
4469
  function parseResolved(raw, m, where) {
4458
4470
  if (!raw) return void 0;
4459
4471
  const seats2 = {};
@@ -26187,12 +26199,13 @@ async function listWorkspaces(o) {
26187
26199
  return res.workspaces.map((w) => ({ slug: w.path ?? w.slug, name: w.name, role: w.role }));
26188
26200
  }
26189
26201
  var eq = (a, b) => (a ?? "").trim().toLowerCase() === b.trim().toLowerCase();
26190
- function seatFor(rows, role, agentId) {
26191
- const linked = agentId ? rows.find((x) => x.agent_id === agentId) : void 0;
26192
- if (linked) return linked.id;
26193
- const byName = (x) => (x.name ?? "").toLowerCase().includes(role.toLowerCase());
26194
- const r = rows.find((x) => !x.agent_id && byName(x)) ?? rows.find(byName);
26195
- return r?.id;
26202
+ function pickSeat(rows, agentId, storedId) {
26203
+ const linked = agentId ? rows.filter((x) => x.agent_id === agentId) : [];
26204
+ if (storedId && linked.some((x) => x.id === storedId)) return { id: storedId, via: "agent" };
26205
+ if (linked.length === 1) return { id: linked[0].id, via: "agent" };
26206
+ if (linked.length > 1) return { ambiguous: linked };
26207
+ const kept = storedId ? rows.find((x) => x.id === storedId && (!agentId || !x.agent_id)) : void 0;
26208
+ return kept ? { id: kept.id, via: "stored" } : {};
26196
26209
  }
26197
26210
  var REQUIRED_TABLES = ["Issues"];
26198
26211
  async function missingTables(o, projectId) {
@@ -26212,7 +26225,8 @@ async function discover(o) {
26212
26225
  holds: [],
26213
26226
  candidates: [],
26214
26227
  problems,
26215
- provisioning
26228
+ provisioning,
26229
+ notes: []
26216
26230
  };
26217
26231
  try {
26218
26232
  const me = await get(o, `/auth/me?workspaceId=${ws.id}`);
@@ -26469,7 +26483,8 @@ async function discover(o) {
26469
26483
  }
26470
26484
  }
26471
26485
  let agentIdFor = () => void 0;
26472
- if (shipRowId || o.ship) {
26486
+ let agentsGap = () => "the Agents table could not be read with this key";
26487
+ if (out.models.crew) {
26473
26488
  try {
26474
26489
  const agentsModel = await get(o, `/data-models/agents?workspaceId=${ws.id}`);
26475
26490
  const agentRows = await get(
@@ -26477,6 +26492,7 @@ async function discover(o) {
26477
26492
  `/data-models/${agentsModel.id}/records?limit=200`
26478
26493
  );
26479
26494
  agentIdFor = (role) => agentRows.find((r) => r.name === PERSONA_NAME[role])?.id;
26495
+ agentsGap = (role) => `the Agents table has no "${PERSONA_NAME[role]}" row`;
26480
26496
  } catch {
26481
26497
  }
26482
26498
  }
@@ -26500,46 +26516,64 @@ async function discover(o) {
26500
26516
  }
26501
26517
  const scoped = seatShipId ? rows.filter((r) => r.ship_id === seatShipId) : rows.filter((r) => !r.ship_id);
26502
26518
  const unclaimed = seatShipId ? rows.filter((r) => !r.ship_id) : [];
26519
+ const stored = o.storedSeats?.(`${out.workspaceSlug}/${out.projectSlug ?? out.projectId}`);
26520
+ const listRows = (rs) => rs.map((r) => `"${r.name ?? ""}" (${r.id})`).join(", ");
26503
26521
  for (const role of ["dev", "design", "qa", "triage"]) {
26504
- const searchTerm = role === "dev" ? "develop" : role;
26505
- let id = seatFor(scoped, searchTerm, agentIdFor(role));
26522
+ const agentId = agentIdFor(role);
26523
+ let pick = pickSeat(scoped, agentId, stored?.seats?.[role]);
26524
+ let id = pick.id;
26506
26525
  let seatAction = "matched";
26507
- if (!id && seatShipId && !shipRowId) {
26508
- const legacyId = seatFor(unclaimed, searchTerm, agentIdFor(role));
26509
- if (legacyId) {
26510
- id = legacyId;
26526
+ if (!id && !pick.ambiguous && agentId && seatShipId) {
26527
+ const legacy = pickSeat(unclaimed, agentId);
26528
+ if (legacy.ambiguous) pick = legacy;
26529
+ else if (legacy.id) {
26530
+ id = legacy.id;
26511
26531
  seatAction = "claimed";
26532
+ if (shipRowId) {
26533
+ await patch(o, `/data-models/${out.models.crew}/records/${id}`, { ship_id: shipRowId });
26534
+ provisioning.push(`claimed existing Crew row for the ${role} seat`);
26535
+ }
26512
26536
  }
26513
- } else if (!id && shipRowId) {
26514
- const legacyId = seatFor(unclaimed, searchTerm, agentIdFor(role));
26515
- if (legacyId) {
26516
- await patch(o, `/data-models/${out.models.crew}/records/${legacyId}`, { ship_id: shipRowId });
26517
- id = legacyId;
26518
- seatAction = "claimed";
26519
- provisioning.push(`claimed existing Crew row for the ${role} seat`);
26520
- } else {
26537
+ }
26538
+ if (pick.ambiguous) {
26539
+ problems.push(`${pick.ambiguous.length} Crew rows on this ship are linked to the ${PERSONA_NAME[role]} agent, so the ${role} seat is ambiguous: ${listRows(pick.ambiguous)} \u2014 unlink all but one`);
26540
+ continue;
26541
+ }
26542
+ if (!id && agentId) {
26543
+ if (shipRowId) {
26521
26544
  const created = await post2(o, `/data-models/${out.models.crew}/records`, {
26522
26545
  name: `${PERSONA_NAME[role]} agent`,
26523
26546
  ship_id: shipRowId,
26524
- ...agentIdFor(role) ? { agent_id: agentIdFor(role) } : {}
26547
+ agent_id: agentId
26525
26548
  });
26526
26549
  id = created.id;
26527
26550
  seatAction = "created";
26528
26551
  provisioning.push(`created Crew row for the ${role} seat`);
26552
+ } else if (o.dryRun && out.shipsModelId) {
26553
+ (out.seatRows ??= []).push({ role, id: "", action: "would-create" });
26554
+ continue;
26529
26555
  }
26530
26556
  }
26531
26557
  if (id) {
26532
26558
  out.seats[role] = id;
26533
26559
  const rowShip = rows.find((r) => r.id === id)?.ship_id ?? shipRowId ?? void 0;
26534
26560
  (out.seatRows ??= []).push({ role, id, action: seatAction, ...rowShip ? { shipId: rowShip } : {} });
26535
- } else if (o.dryRun && o.ship && out.shipsModelId) {
26536
- (out.seatRows ??= []).push({ role, id: "", action: "would-create" });
26537
- } else problems.push(`no Crew row looking like the ${role} seat \u2014 create one, or omit that role`);
26561
+ if (pick.via === "stored") (out.notes ??= []).push(`${role} seat kept by its stored id; it is not linked to its Agent \u2014 run \`crew agents sync\` to link it`);
26562
+ } else if (!agentId) {
26563
+ problems.push(`${role} seat: ${agentsGap(role)}, so no Crew row can be matched or created for it (seats are never matched by name) \u2014 run \`crew agents sync\`, then connect again`);
26564
+ } else problems.push(`no Crew row on this ship is linked to the ${PERSONA_NAME[role]} agent for the ${role} seat \u2014 link one, or omit that role`);
26565
+ }
26566
+ const pairAgent = agentIdFor("pair");
26567
+ let pairPick = pickSeat(scoped, pairAgent, stored?.seats?.pair);
26568
+ if (!pairPick.id && !pairPick.ambiguous && pairAgent && seatShipId) pairPick = pickSeat(unclaimed, pairAgent);
26569
+ if (pairPick.ambiguous) {
26570
+ problems.push(`${pairPick.ambiguous.length} Crew rows are linked to the Pair agent, so the pair seat is ambiguous: ${listRows(pairPick.ambiguous)} \u2014 unlink all but one`);
26571
+ } else if (pairPick.id) {
26572
+ out.seats.pair = pairPick.id;
26573
+ if (pairPick.via === "stored") (out.notes ??= []).push("pair seat kept by its stored id; it is not linked to its Agent \u2014 run `crew agents sync` to link it");
26538
26574
  }
26539
- const pairId = seatFor(scoped, "pair") || (seatShipId ? seatFor(unclaimed, "pair") : void 0);
26540
- if (pairId) out.seats.pair = pairId;
26541
26575
  if (shipRowId) {
26542
- const releaseId = seatFor(scoped, "release");
26576
+ const releaseId = stored?.releaseSeat && scoped.some((r) => r.id === stored.releaseSeat) ? stored.releaseSeat : void 0;
26543
26577
  if (releaseId) out.releaseSeat = releaseId;
26544
26578
  else {
26545
26579
  const created = await post2(o, `/data-models/${out.models.crew}/records`, {
@@ -28249,7 +28283,7 @@ import { dirname as dirOf2, resolve as resolvePath } from "path";
28249
28283
  import { existsSync as existsSync56, readdirSync as readdirSync18, statSync as statSync17 } from "fs";
28250
28284
  import { join as join60 } from "path";
28251
28285
  function builtVersion() {
28252
- return true ? "0.157.0" : null;
28286
+ return true ? "0.157.1" : null;
28253
28287
  }
28254
28288
  var REBUILD_HINT = "rebuild with npm run build";
28255
28289
  function newestMtime(path) {
@@ -34083,7 +34117,7 @@ Waiting for approval`
34083
34117
  lastSyncedName: (r) => readSyncedName(resolvedPathFor(cfg.ship.stateDir, r))
34084
34118
  };
34085
34119
  const runConnect = async (ws, proj) => {
34086
- let found = await discover({ ...authOpts, workspace: ws, project: proj, area: value("area"), ship, dryRun, interactive: canAsk || connectEvents.json });
34120
+ let found = await discover({ ...authOpts, workspace: ws, project: proj, area: value("area"), ship, dryRun, interactive: canAsk || connectEvents.json, storedSeats: (r) => readStoredSeats(cfg.ship.stateDir, r) });
34087
34121
  if (store && keychainBacked && sessionAddress && sessionAddress !== found.workspaceSlug) {
34088
34122
  if (await adoptSessionAddress({
34089
34123
  store,
@@ -34132,7 +34166,7 @@ Waiting for approval`
34132
34166
  const installedSlug = await offerTemplateInstall(authOpts, found.workspaceId, canAsk ? void 0 : true);
34133
34167
  if (installedSlug) {
34134
34168
  connectEvents.emit("template_installed", `installed project ${installedSlug}`, { projectSlug: installedSlug });
34135
- found = await discover({ ...authOpts, workspace: ws, project: installedSlug, area: value("area"), ship, dryRun, interactive: canAsk || connectEvents.json });
34169
+ found = await discover({ ...authOpts, workspace: ws, project: installedSlug, area: value("area"), ship, dryRun, interactive: canAsk || connectEvents.json, storedSeats: (r) => readStoredSeats(cfg.ship.stateDir, r) });
34136
34170
  }
34137
34171
  }
34138
34172
  }
@@ -34427,6 +34461,7 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`, "fix the problems above, t
34427
34461
  emit.note(`Provisioned for this machine (${ship.name}):`);
34428
34462
  for (const p of found.provisioning) emit.note(` - ${p}`);
34429
34463
  }
34464
+ for (const n of found.notes ?? []) emit.note(`Note: ${n}`);
34430
34465
  if (found.problems.length) {
34431
34466
  emit.warn(`Unresolved \u2014 fix these before arming it:
34432
34467
  ${found.problems.map((p) => ` - ${p}`).join("\n")}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tablation/crew",
3
- "version": "0.157.0",
3
+ "version": "0.157.1",
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",