@tablation/crew 0.146.2 → 0.148.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.
package/crew.example.yaml CHANGED
@@ -132,6 +132,11 @@ routes:
132
132
  # dev/design/QA policy this repo ships with) when omitted. See
133
133
  # prompts/default/ for the shape a custom set needs to have.
134
134
  # promptSet: "dev-qa"
135
+ # Roles whose run start marks the ticket's optional `crew_assisted` Yes/No
136
+ # column true (CREW-3258): a record that the crew's building or verifying
137
+ # lane worked it. Defaults to [dev, qa]; [] turns the marking off for this
138
+ # route. Ignored on a workspace whose Issues table lacks the column.
139
+ # assistedRoles: [dev, qa]
135
140
  # What a host must be to build a repo lives in THAT repo's own .crew.yaml
136
141
  # (any | unix | macos | linux | windows) — never here. A route can span
137
142
  # repos with different needs; the ship refuses a route only when it can
package/dist/cli.js CHANGED
@@ -1633,9 +1633,9 @@ function inferenceHeaders(inf) {
1633
1633
  return lines2.length > 0 ? lines2.join("\n") : void 0;
1634
1634
  }
1635
1635
  function workspaceSettings(baseUrl, headers) {
1636
- const blank = BILLING_VARS_TO_UNSET.filter((v) => v !== "ANTHROPIC_AUTH_TOKEN");
1636
+ const blank2 = BILLING_VARS_TO_UNSET.filter((v) => v !== "ANTHROPIC_AUTH_TOKEN");
1637
1637
  return JSON.stringify({ env: {
1638
- ...Object.fromEntries(blank.map((v) => [v, ""])),
1638
+ ...Object.fromEntries(blank2.map((v) => [v, ""])),
1639
1639
  ANTHROPIC_BASE_URL: baseUrl,
1640
1640
  ...headers ? { ANTHROPIC_CUSTOM_HEADERS: headers } : {}
1641
1641
  } });
@@ -2576,18 +2576,23 @@ var ForgeError = class extends Error {
2576
2576
  };
2577
2577
  var DEFAULT_FORGE_USERNAME = "x-access-token";
2578
2578
  var DEFAULT_FORGE_HOST = "github.com";
2579
+ var encodeSegments = (name) => name.split("/").map(encodeURIComponent).join("/");
2579
2580
  var FORGE_DESCRIPTORS = {
2580
2581
  github: {
2581
2582
  kind: "github",
2582
2583
  httpsUrl: (host, remote) => `https://${host}/${remote}.git`,
2583
2584
  sshUrl: (host, remote) => `git@${host}:${remote}.git`,
2584
- credentialUsername: DEFAULT_FORGE_USERNAME
2585
+ credentialUsername: DEFAULT_FORGE_USERNAME,
2586
+ branchUrl: (host, remote, branch) => `https://${host}/${remote}/tree/${encodeSegments(branch)}`,
2587
+ pullUrl: (host, remote, number) => `https://${host}/${remote}/pull/${number}`
2585
2588
  },
2586
2589
  gitlab: {
2587
2590
  kind: "gitlab",
2588
2591
  httpsUrl: (host, remote) => `https://${host}/${remote}.git`,
2589
2592
  sshUrl: (host, remote) => `git@${host}:${remote}.git`,
2590
- credentialUsername: "oauth2"
2593
+ credentialUsername: "oauth2",
2594
+ branchUrl: (host, remote, branch) => `https://${host}/${remote}/-/tree/${encodeSegments(branch)}`,
2595
+ pullUrl: (host, remote, number) => `https://${host}/${remote}/-/merge_requests/${number}`
2591
2596
  }
2592
2597
  };
2593
2598
  function normalizeForgeHost(host) {
@@ -2597,6 +2602,18 @@ function normalizeForgeHost(host) {
2597
2602
  function forgeDescriptorFor(host) {
2598
2603
  return normalizeForgeHost(host).includes("gitlab") ? FORGE_DESCRIPTORS.gitlab : FORGE_DESCRIPTORS.github;
2599
2604
  }
2605
+ function branchWebUrl(forgeHost, remote, branch) {
2606
+ const r = remote?.trim().replace(/^\/+|\/+$/g, "");
2607
+ if (!r || !branch) return null;
2608
+ const host = normalizeForgeHost(forgeHost);
2609
+ return forgeDescriptorFor(host).branchUrl(host, r, branch);
2610
+ }
2611
+ function pullWebUrl(forgeHost, remote, number) {
2612
+ const r = remote?.trim().replace(/^\/+|\/+$/g, "");
2613
+ if (!r) return null;
2614
+ const host = normalizeForgeHost(forgeHost);
2615
+ return forgeDescriptorFor(host).pullUrl(host, r, number);
2616
+ }
2600
2617
  var DEFAULT_KEYCHAIN_SERVICE = "crew-forge";
2601
2618
  function defaultTokenFilePath(stateDir, host) {
2602
2619
  return join15(stateDir, "forges", `${host.replace(/[^a-z0-9.-]/gi, "_")}.token`);
@@ -4003,6 +4020,7 @@ var ROLE_LABEL = {
4003
4020
  triage: "Triage",
4004
4021
  pair: "Pair"
4005
4022
  };
4023
+ var DEFAULT_ASSISTED_ROLES = ["dev", "qa"];
4006
4024
  var ConfigError = class extends Error {
4007
4025
  };
4008
4026
  var DEFAULT_MAX_PERISCOPES = 3;
@@ -4133,7 +4151,8 @@ var ROUTE_KEYS = /* @__PURE__ */ new Set([
4133
4151
  "hostPassengers",
4134
4152
  "hostPeriscopes",
4135
4153
  "toolchain",
4136
- "maxRunMinutes"
4154
+ "maxRunMinutes",
4155
+ "assistedRoles"
4137
4156
  ]);
4138
4157
  function parseWorktreeName(v, where, file) {
4139
4158
  const problem = typeof v === "string" ? worktreeNameProblem(v) : "must be a string";
@@ -4585,6 +4604,22 @@ function parseMaxRunMinutes(raw, where, missing) {
4585
4604
  }
4586
4605
  return n;
4587
4606
  }
4607
+ function parseAssistedRoles(raw, where, missing) {
4608
+ if (raw === void 0) return void 0;
4609
+ if (!Array.isArray(raw)) {
4610
+ missing.add(`${where} must be a list of roles (expected any of ${ROLE_NAMES.join(", ")}), [] to turn the marking off`);
4611
+ return void 0;
4612
+ }
4613
+ const out = [];
4614
+ for (const r of raw) {
4615
+ if (!ROLE_NAMES.includes(String(r))) {
4616
+ missing.add(`${where} has "${String(r)}", which is not a role (expected any of ${ROLE_NAMES.join(", ")})`);
4617
+ continue;
4618
+ }
4619
+ if (!out.includes(r)) out.push(r);
4620
+ }
4621
+ return out;
4622
+ }
4588
4623
  function parsePair(raw, missing) {
4589
4624
  if (raw === void 0) return void 0;
4590
4625
  if (!Array.isArray(raw)) {
@@ -4673,6 +4708,7 @@ function parseOneRoute(c, where, file, base, stateDir, raw, missing, crewHome, t
4673
4708
  rejectUnknownKeys(c, ROUTE_KEYS, `${where}`, file);
4674
4709
  const toolchain = c?.toolchain === void 0 ? void 0 : String(c.toolchain);
4675
4710
  const maxRunMinutes = parseMaxRunMinutes(c?.maxRunMinutes, `${where}.maxRunMinutes`, missing);
4711
+ const assistedRoles = parseAssistedRoles(c?.assistedRoles, `${where}.assistedRoles`, missing);
4676
4712
  if (toolchain !== void 0 && !toolchainNames.has(toolchain)) {
4677
4713
  missing.add(`${where}.toolchain "${toolchain}" is not defined in ship.toolchains (have: ${[...toolchainNames].join(", ")})`);
4678
4714
  }
@@ -4737,6 +4773,7 @@ function parseOneRoute(c, where, file, base, stateDir, raw, missing, crewHome, t
4737
4773
  worktreePrefix: c?.worktreePrefix ? String(c.worktreePrefix) : void 0,
4738
4774
  ...toolchain !== void 0 ? { toolchain } : {},
4739
4775
  ...maxRunMinutes !== void 0 ? { maxRunMinutes } : {},
4776
+ ...assistedRoles !== void 0 ? { assistedRoles } : {},
4740
4777
  promptsDir: resolvePromptsDir(c?.promptSet ? String(c.promptSet) : void 0, crewHome, base),
4741
4778
  weight,
4742
4779
  baseUrl: String(c?.baseUrl ?? raw.ship?.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, ""),
@@ -8750,6 +8787,8 @@ var DEFAULT_CONTRACT = {
8750
8787
  resolutionNote: "resolution_note",
8751
8788
  verifiedSha: "verified_sha",
8752
8789
  prRef: "pr_ref",
8790
+ branchUrl: "branch_url",
8791
+ prUrl: "pr_url",
8753
8792
  externalId: "external_id",
8754
8793
  position: "position",
8755
8794
  agentRuns: "agent_runs",
@@ -8757,7 +8796,8 @@ var DEFAULT_CONTRACT = {
8757
8796
  tokensOut: "tokens_out",
8758
8797
  cacheReadTokens: "cache_read_tokens",
8759
8798
  cacheWriteTokens: "cache_write_tokens",
8760
- costUsd: "cost_usd"
8799
+ costUsd: "cost_usd",
8800
+ crewAssisted: "crew_assisted"
8761
8801
  },
8762
8802
  comments: {
8763
8803
  parent: "ticket_id",
@@ -9152,6 +9192,7 @@ var Tracker = class {
9152
9192
  * so concurrent first writes share one round of field-metadata reads.
9153
9193
  */
9154
9194
  authorship;
9195
+ crewAssistedColumn;
9155
9196
  attachments;
9156
9197
  stateDir;
9157
9198
  /**
@@ -9798,6 +9839,11 @@ var Tracker = class {
9798
9839
  shipId: auth.shipId
9799
9840
  };
9800
9841
  }
9842
+ /** Whether Issues carries the optional `crew_assisted` column (CREW-3258). */
9843
+ async hasCrewAssistedColumn() {
9844
+ this.crewAssistedColumn ??= this.columnNames(this.models.issues).then((f) => f.has(this.contract.columns.crewAssisted));
9845
+ return this.crewAssistedColumn;
9846
+ }
9801
9847
  /**
9802
9848
  * Which of the optional review columns (`verified_sha`, `pr_ref`) the Issues
9803
9849
  * table carries. A table without them has not adopted the review hand-off:
@@ -9807,6 +9853,20 @@ var Tracker = class {
9807
9853
  const fields = await this.columnNames(this.models.issues);
9808
9854
  return {
9809
9855
  verifiedSha: fields.has(this.contract.columns.verifiedSha),
9856
+ prRef: fields.has(this.contract.columns.prRef),
9857
+ prUrl: fields.has(this.contract.columns.prUrl)
9858
+ };
9859
+ }
9860
+ /**
9861
+ * Which of the optional link columns (`branch_url`, `pr_url`; CREW-3255) the
9862
+ * Issues table carries. A table without them has not adopted the links and
9863
+ * crew writes around them, with no extra forge calls.
9864
+ */
9865
+ async linkColumns() {
9866
+ const fields = await this.columnNames(this.models.issues);
9867
+ return {
9868
+ branchUrl: fields.has(this.contract.columns.branchUrl),
9869
+ prUrl: fields.has(this.contract.columns.prUrl),
9810
9870
  prRef: fields.has(this.contract.columns.prRef)
9811
9871
  };
9812
9872
  }
@@ -10570,6 +10630,16 @@ ${shipName2 ? `Ship: ${shipName2}
10570
10630
 
10571
10631
  ${v.reason[0].toUpperCase()}${v.reason.slice(1)}. ${pushError ? ` The runner tried a plain push and git refused it: \`${pushError}\`.` : ""} Set back to \`in_progress\`, still held by this ship; push with a plain \`git push --set-upstream ${v.remote} <branch>\` (never \`--force\`) and set \`fixed\` again. Your brief authorizes this push: it is the hand-off, not a release, so do it now rather than asking for permission.`;
10572
10632
  }
10633
+ async function postPushed(i, ticketId, sha, remote, branch, log) {
10634
+ await i.writer.postEvent(ticketId, pushedEventBody(sha, remote, branch), i.seatId, "pushed");
10635
+ const url = i.branchLink?.url(branch);
10636
+ if (!i.branchLink || !url) return;
10637
+ try {
10638
+ await i.writer.updateTicket(ticketId, { [i.branchLink.column]: url });
10639
+ } catch {
10640
+ i.log.warn(`pushed, but the branch link could not be recorded`, log);
10641
+ }
10642
+ }
10573
10643
  async function takenOverSince(i, ticketRow) {
10574
10644
  if (!i.since || !i.writer.events) return false;
10575
10645
  const from = Date.parse(i.since);
@@ -10655,7 +10725,7 @@ async function enforceHandoff(i) {
10655
10725
  }
10656
10726
  }
10657
10727
  if (v.kind === "pushed") {
10658
- await i.writer.postEvent(t.id, pushedEventBody(v.sha, v.remote, v.branch), i.seatId, "pushed");
10728
+ await postPushed(i, t.id, v.sha, v.remote, v.branch, log);
10659
10729
  i.log.emit(`${t.issue_id} pushed at ${v.sha.slice(0, 7)} \u2014 handed on to QA`, log);
10660
10730
  return { kind: "pushed", sha: v.sha };
10661
10731
  }
@@ -10683,7 +10753,7 @@ async function enforceHandoff(i) {
10683
10753
  pushBranchUpstream(wt?.path ?? i.dir, v.remote, v.branch);
10684
10754
  const again = inspectHandoff(i.dir, i.cfg, t, i.role);
10685
10755
  if (again.kind === "pushed") {
10686
- await i.writer.postEvent(t.id, pushedEventBody(again.sha, again.remote, again.branch), i.seatId, "pushed");
10756
+ await postPushed(i, t.id, again.sha, again.remote, again.branch, log);
10687
10757
  await i.writer.postEvent(
10688
10758
  t.id,
10689
10759
  `The runner pushed \`${again.branch}\` to \`${again.remote}\` on ${i.shipName ? `${i.shipName}'s` : "this ship's"} behalf: the ${i.role} seat set \`${i.contract.statuses.handoff}\` without pushing. Plain fast-forward push.${i.cfg.hooks.ci_status ? " The repo's `ci_status` hook was NOT run by the hand-off guard, so CI was not checked by the builder." : ""}`,
@@ -10763,6 +10833,10 @@ async function guardRunHandoff(route2, ship, tracker, role, workingId, log, sinc
10763
10833
  hold: affinity ? { column: affinity.column, shipId: affinity.shipId } : void 0,
10764
10834
  since: since2,
10765
10835
  log,
10836
+ ...await branchLinkFor(tracker, {
10837
+ remote: target.remote ?? (t.repo_id ? route2.resolved?.repoRemotes?.[t.repo_id] : void 0),
10838
+ forgeHost: target.forgeHost ?? (t.repo_id ? route2.resolved?.repoForgeHosts?.[t.repo_id] : void 0)
10839
+ }),
10766
10840
  ...origin ? { origin } : {}
10767
10841
  });
10768
10842
  if (origin) {
@@ -10780,6 +10854,14 @@ async function guardRunHandoff(route2, ship, tracker, role, workingId, log, sinc
10780
10854
  return null;
10781
10855
  }
10782
10856
  }
10857
+ async function branchLinkFor(tracker, target) {
10858
+ try {
10859
+ if (!target.remote || !(await tracker.linkColumns()).branchUrl) return {};
10860
+ } catch {
10861
+ return {};
10862
+ }
10863
+ return { branchLink: { column: tracker.contract.columns.branchUrl, url: (b) => branchWebUrl(target.forgeHost, target.remote, b) } };
10864
+ }
10783
10865
  async function retireRunWorktree(tracker, dir, cfg, t, role, seatId, shipName2, log) {
10784
10866
  try {
10785
10867
  const branch = existingBranchForTicket(dir, cfg, t, role);
@@ -19099,6 +19181,27 @@ async function claimStillHeld(tracker, t, buildingStatus, affinity) {
19099
19181
  return null;
19100
19182
  }
19101
19183
 
19184
+ // src/crew-assisted.ts
19185
+ function countsAsAssisted(route2, role) {
19186
+ return (route2.assistedRoles ?? DEFAULT_ASSISTED_ROLES).includes(role);
19187
+ }
19188
+ async function markCrewAssisted(tracker, route2, role, ticket) {
19189
+ if (!countsAsAssisted(route2, role)) return false;
19190
+ const column = tracker.contract.columns.crewAssisted;
19191
+ if (ticket[column] === true) return false;
19192
+ if (!await tracker.hasCrewAssistedColumn()) return false;
19193
+ await tracker.updateTicket(ticket.id, { [column]: true });
19194
+ return true;
19195
+ }
19196
+ async function markCrewAssistedAtLaunch(tracker, route2, role, ticketId, ticket, warn) {
19197
+ if (!ticketId || !countsAsAssisted(route2, role)) return;
19198
+ try {
19199
+ await markCrewAssisted(tracker, route2, role, ticket ?? await tracker.ticket(ticketId));
19200
+ } catch (e) {
19201
+ warn(`could not mark the ticket crew-assisted: ${e.message}`);
19202
+ }
19203
+ }
19204
+
19102
19205
  // src/repo-refresh.ts
19103
19206
  import { existsSync as existsSync40, mkdirSync as mkdirSync28, readFileSync as readFileSync40, writeFileSync as writeFileSync32 } from "fs";
19104
19207
  import { dirname as dirname22 } from "path";
@@ -20292,6 +20395,127 @@ async function applyExternalClosures(tracker, closures, contract, emit, dryRun,
20292
20395
  return stamped;
20293
20396
  }
20294
20397
 
20398
+ // src/pr-links.ts
20399
+ function selectPull(pulls, firstPushedAt) {
20400
+ const byNewest = [...pulls].sort((a, b) => Date.parse(b.createdAt) - Date.parse(a.createdAt));
20401
+ const open = byNewest.find((p) => p.open);
20402
+ if (open) return open;
20403
+ const cutoff = firstPushedAt ? Date.parse(firstPushedAt) : NaN;
20404
+ if (Number.isNaN(cutoff)) return null;
20405
+ return byNewest.find((p) => Date.parse(p.createdAt) > cutoff) ?? null;
20406
+ }
20407
+ function pushedBranchOf(message) {
20408
+ const m = /^pushed \S+ to [^/\s]+\/(\S+)/.exec((message ?? "").trim());
20409
+ return m ? m[1] : null;
20410
+ }
20411
+ function prUrlFromRef(ref, forgeHost, remote) {
20412
+ const r = ref?.trim();
20413
+ if (!r) return null;
20414
+ if (/^https?:\/\/\S+$/.test(r)) return r;
20415
+ const n = /^#?(\d+)$/.exec(r);
20416
+ return n ? pullWebUrl(forgeHost, remote, n[1]) : null;
20417
+ }
20418
+ async function listPulls(host, remote, branch, token, fetcher = fetch) {
20419
+ const h = normalizeForgeHost(host);
20420
+ const kind = forgeDescriptorFor(h).kind;
20421
+ const signal = AbortSignal.timeout(15e3);
20422
+ if (kind === "gitlab") {
20423
+ const url2 = `https://${h}/api/v4/projects/${encodeURIComponent(remote)}/merge_requests?source_branch=${encodeURIComponent(branch)}&state=all&order_by=created_at&sort=desc&per_page=30`;
20424
+ const res2 = await fetcher(url2, { headers: { "PRIVATE-TOKEN": token, Accept: "application/json" }, signal });
20425
+ if (!res2.ok) throw new Error(`${h} answered ${res2.status}`);
20426
+ const rows2 = await res2.json();
20427
+ return rows2.filter((r) => r.web_url && r.created_at).map((r) => ({
20428
+ url: r.web_url,
20429
+ number: r.iid ?? 0,
20430
+ open: r.state === "opened",
20431
+ createdAt: r.created_at
20432
+ }));
20433
+ }
20434
+ const owner = remote.split("/")[0] ?? "";
20435
+ const api = h === "github.com" ? "https://api.github.com" : `https://${h}/api/v3`;
20436
+ const url = `${api}/repos/${remote}/pulls?head=${encodeURIComponent(`${owner}:${branch}`)}&state=all&sort=created&direction=desc&per_page=30`;
20437
+ const res = await fetcher(url, {
20438
+ headers: { Authorization: `Bearer ${token}`, Accept: "application/vnd.github+json", "User-Agent": "crew" },
20439
+ signal
20440
+ });
20441
+ if (!res.ok) throw new Error(`${h} answered ${res.status}`);
20442
+ const rows = await res.json();
20443
+ return rows.filter((r) => r.html_url && r.created_at).map((r) => ({
20444
+ url: r.html_url,
20445
+ number: r.number ?? 0,
20446
+ open: r.state === "open",
20447
+ createdAt: r.created_at
20448
+ }));
20449
+ }
20450
+ var processWarned = /* @__PURE__ */ new Set();
20451
+ var blank = (v) => typeof v !== "string" || v.trim() === "";
20452
+ async function discoverPullRequests(i) {
20453
+ const warned = i.warnedHosts ?? processWarned;
20454
+ const cols = i.tracker.contract.columns;
20455
+ try {
20456
+ const have = await i.tracker.linkColumns();
20457
+ if (!have.prUrl) return 0;
20458
+ const candidates2 = i.tickets.filter((t) => blank(t[cols.prUrl]) && t.repo_id);
20459
+ if (candidates2.length === 0) return 0;
20460
+ const pushed = await i.tracker.events("pushed");
20461
+ let found = 0;
20462
+ for (const t of candidates2) {
20463
+ const mine = pushed.filter((e) => e.record_id === t.id);
20464
+ if (mine.length === 0) continue;
20465
+ const stamp = (e) => e.occurred_at ?? e.created_at ?? "";
20466
+ const ordered = [...mine].sort((a, b) => Date.parse(stamp(a)) - Date.parse(stamp(b)));
20467
+ const branch = pushedBranchOf(ordered[ordered.length - 1].message);
20468
+ if (!branch) continue;
20469
+ const target = repoTargetFor(i.route, t.repo_id);
20470
+ const remote = target?.remote ?? i.route.resolved?.repoRemotes?.[t.repo_id];
20471
+ const host = normalizeForgeHost(target?.forgeHost ?? i.route.resolved?.repoForgeHosts?.[t.repo_id]);
20472
+ if (!remote) continue;
20473
+ let token = null;
20474
+ try {
20475
+ token = readForgeToken(i.forges, host, i.stateDir, i.env);
20476
+ } catch {
20477
+ }
20478
+ if (!token) continue;
20479
+ try {
20480
+ const pull = selectPull(await listPulls(host, remote, branch, token, i.fetcher), stamp(ordered[0]) || null);
20481
+ if (!pull) continue;
20482
+ const patch2 = { [cols.prUrl]: pull.url };
20483
+ if (have.prRef && blank(t[cols.prRef])) patch2[cols.prRef] = pull.url;
20484
+ await i.tracker.updateTicket(t.id, patch2);
20485
+ i.log.emit(`found pull request ${pull.url}`, { ticket: t.issue_id, step: "review" });
20486
+ found++;
20487
+ } catch (e) {
20488
+ if (!warned.has(host)) {
20489
+ warned.add(host);
20490
+ i.log.warn(`pull request discovery on ${host} skipped: ${e.message}`, { step: "review" });
20491
+ }
20492
+ }
20493
+ }
20494
+ return found;
20495
+ } catch (e) {
20496
+ i.log.warn(`pull request discovery skipped: ${e.message}`, { step: "review" });
20497
+ return 0;
20498
+ }
20499
+ }
20500
+ async function discoverForRoute(route2, ship, tickets, log, tracker = new Tracker(route2, ship)) {
20501
+ return discoverPullRequests({ tracker, route: route2, forges: ship.forges, stateDir: ship.stateDir, tickets, log });
20502
+ }
20503
+ function linkDoctorLines(have, repos, forges, stateDir, env = process.env) {
20504
+ const out = [
20505
+ have.branchUrl ? "branch links: branch_url present" : "branch links: branch_url absent \u2014 the pushed branch is not linked; add it to the Issues template",
20506
+ have.prUrl ? "pull requests: pr_url present \u2014 discovery runs each cycle" : "pull requests: pr_url absent \u2014 pull requests a person opens are not linked; add it to the Issues template"
20507
+ ];
20508
+ if (have.prUrl) {
20509
+ for (const r of repos) {
20510
+ const host = normalizeForgeHost(r.host);
20511
+ if (!hasForgeToken(forges, host, stateDir, env)) {
20512
+ out.push(`pull requests: discovery unavailable for ${r.name}: no forge token stored for ${host} (see \`crew forge\`)`);
20513
+ }
20514
+ }
20515
+ }
20516
+ return out;
20517
+ }
20518
+
20295
20519
  // src/review.ts
20296
20520
  function reviewApplies(repo, contract) {
20297
20521
  return repo.release.mode === "external" && !!contract.statuses.reviewing;
@@ -20377,6 +20601,10 @@ async function runReview(r, verified, reviewing) {
20377
20601
  if (res && res.code !== 0) handoff.prFailure = { code: res.code, tail: lastLines(res.output, 5).trim() };
20378
20602
  else if (res) handoff.prRef = parsePrRef(res.output);
20379
20603
  }
20604
+ if (handoff.prRef && r.columns.prUrl) {
20605
+ const url = prUrlFromRef(handoff.prRef, r.forge?.host, r.forge?.remote);
20606
+ if (url) handoff.prUrl = url;
20607
+ }
20380
20608
  out.handoffs.push(handoff);
20381
20609
  }
20382
20610
  return out;
@@ -20400,7 +20628,8 @@ ${h.prFailure.tail}
20400
20628
  try {
20401
20629
  await tracker.updateTicket(t.id, {
20402
20630
  [contract.columns.status]: reviewing,
20403
- ...h.prRef && columns.prRef ? { [contract.columns.prRef]: h.prRef } : {}
20631
+ ...h.prRef && columns.prRef ? { [contract.columns.prRef]: h.prRef } : {},
20632
+ ...h.prUrl && columns.prUrl ? { [contract.columns.prUrl]: h.prUrl } : {}
20404
20633
  }, t.updated_at);
20405
20634
  await tracker.postEvent(t.id, lines2.join("\n\n"), seat, "review");
20406
20635
  emit.emit(`moved to ${reviewing}`, { ticket: t.issue_id });
@@ -20572,6 +20801,7 @@ async function reviewHandoff(o, closures, verifiedCandidates, reviewing) {
20572
20801
  emit: o.emit,
20573
20802
  dryRun: o.dryRun,
20574
20803
  columns: o.reviewColumns ?? { verifiedSha: false, prRef: false },
20804
+ ...o.forge ? { forge: o.forge } : {},
20575
20805
  runPrHook: async (env) => {
20576
20806
  const r = await hook(o, "pr", env);
20577
20807
  return r ? { code: r.code, output: r.output } : null;
@@ -23061,6 +23291,7 @@ async function applyRouteDecision(o, ctx, decision) {
23061
23291
  const tracker = new Tracker(o.route, o.ship);
23062
23292
  await applyHoldReleases(tracker, decision.holdReleases, tracker.contract, emit);
23063
23293
  }
23294
+ await discoverForRoute(o.route, o.ship, decision.tickets, emit);
23064
23295
  {
23065
23296
  const tracker = new Tracker(o.route, o.ship);
23066
23297
  const memberId = o.route.resolved?.seats.qa ?? o.route.resolved?.seats.dev;
@@ -23666,6 +23897,7 @@ async function runRoleAgentLocked(role, decision, ctx, hooks, held) {
23666
23897
  if (workingId) {
23667
23898
  try {
23668
23899
  const before = await tracker.ticket(workingId);
23900
+ await markCrewAssistedAtLaunch(tracker, route2, role, workingId, before, (m) => emit.warn(m, { step: "agent" }));
23669
23901
  const col = tracker.contract.columns;
23670
23902
  const tipBefore = branchProgress(route2, before);
23671
23903
  if (role === "dev" || role === "design") {
@@ -26208,7 +26440,7 @@ function warnOrphanedWorktreeDirs(paths, log, held) {
26208
26440
  }
26209
26441
  }
26210
26442
  }
26211
- async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin", base, held) {
26443
+ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin", base, held, onRemoteBranchDeleted) {
26212
26444
  const refused = [];
26213
26445
  const refuse2 = (a, reason, detail) => {
26214
26446
  refused.push(a.path);
@@ -26293,6 +26525,11 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
26293
26525
  gitOk(cwd, ["branch", "-D", a.branch]);
26294
26526
  if (remoteConfigured(cwd, remote) && !deleteRemoteBranch(cwd, remote, a.branch)) {
26295
26527
  log.warn(`could not delete ${remote}/${a.branch} \u2014 leaving it for the next sweep`, { ticket: a.ticket.issue_id, step: "worktree" });
26528
+ } else if (remoteConfigured(cwd, remote)) {
26529
+ try {
26530
+ await onRemoteBranchDeleted?.(a.ticket);
26531
+ } catch {
26532
+ }
26296
26533
  }
26297
26534
  }
26298
26535
  log.emit(
@@ -26539,7 +26776,7 @@ import { dirname as dirOf2, resolve as resolvePath } from "path";
26539
26776
  import { existsSync as existsSync56, readdirSync as readdirSync18, statSync as statSync17 } from "fs";
26540
26777
  import { join as join58 } from "path";
26541
26778
  function builtVersion() {
26542
- return true ? "0.146.2" : null;
26779
+ return true ? "0.148.0" : null;
26543
26780
  }
26544
26781
  var REBUILD_HINT = "rebuild with npm run build";
26545
26782
  function newestMtime(path) {
@@ -28509,6 +28746,14 @@ var CREW_HOME = isCompiledBinary(import.meta.url) ? dirname37(process.execPath)
28509
28746
  var RELEASE_LOCK_TTL_MS = 20 * 60 * 1e3;
28510
28747
  var CYCLE_SECONDS2 = 120;
28511
28748
  var STALE_CYCLES = 3;
28749
+ function clearBranchLink(tracker) {
28750
+ return async (t) => {
28751
+ const col = tracker.contract.columns.branchUrl;
28752
+ const v = t[col];
28753
+ if (typeof v !== "string" || !v.trim()) return;
28754
+ await tracker.updateTicket(t.id, { [col]: null });
28755
+ };
28756
+ }
28512
28757
  async function duplicateLivePeriscopeProblems(route2, ship) {
28513
28758
  try {
28514
28759
  const tr = new Tracker(route2, ship);
@@ -29835,7 +30080,7 @@ ${changed2.map((c) => ` - ${c}
29835
30080
  warnOrphanedWorktreeDirs(orphanDirs, remit, dryRun2 ? void 0 : { state, repo: target.name });
29836
30081
  if (actions.length) {
29837
30082
  remit.enter("worktree");
29838
- const r = await applyWorktreeSweep(target.dir, actions, dryRun2, remit, branch.remote, branch.base, { state, repo: target.name });
30083
+ const r = await applyWorktreeSweep(target.dir, actions, dryRun2, remit, branch.remote, branch.base, { state, repo: target.name }, clearBranchLink(tracker));
29839
30084
  remit.emit(`swept ${r.removed} worktree(s), kept ${r.keptBranches} branch(es)`, { step: "worktree" });
29840
30085
  if (!dryRun2) reconcileHeldWorktrees(state, target.name, remit, /* @__PURE__ */ new Set([...r.refused, ...orphanDirs]));
29841
30086
  } else if (!dryRun2) reconcileHeldWorktrees(state, target.name, remit, new Set(orphanDirs));
@@ -30156,6 +30401,7 @@ ${changed2.map((c) => ` - ${c}
30156
30401
  ...contractRefusal ? { contractRefusal: contractRefusal.message } : {},
30157
30402
  state: state.release(scope),
30158
30403
  reviewColumns: repo.release.mode === "external" ? await tracker.reviewColumns() : void 0,
30404
+ forge: { host: target.forgeHost, remote: target.remote },
30159
30405
  dryRun,
30160
30406
  skipTests: flag("skip-tests"),
30161
30407
  shell: cfg.ship.shell,
@@ -30507,6 +30753,10 @@ ${f.tail.trimEnd()}
30507
30753
  const tracker = new Tracker(e.route, cfg.ship);
30508
30754
  await applyHoldReleases(tracker, e.decision.holdReleases, tracker.contract, emit.forRoute(e.route.route));
30509
30755
  }
30756
+ for (const e of fleet.entries) {
30757
+ if (dryRun || e.error || !e.decision) continue;
30758
+ await discoverForRoute(e.route, cfg.ship, e.decision.tickets, emit.forRoute(e.route.route));
30759
+ }
30510
30760
  for (const e of fleet.entries) {
30511
30761
  if (e.error || !e.decision || !e.decision.sweep.length) continue;
30512
30762
  const remit = emit.forRoute(e.route.route);
@@ -30704,6 +30954,7 @@ ${f.tail.trimEnd()}
30704
30954
  }
30705
30955
  try {
30706
30956
  const runStart = (/* @__PURE__ */ new Date()).toISOString();
30957
+ await markCrewAssistedAtLaunch(fleetTracker, w.route, w.role, fleetWorkingId ?? null, void 0, (m) => wemit.warn(m, { step: "agent" }));
30707
30958
  await spawnAgent(fleetPlan, wemit);
30708
30959
  await guardRunHandoff(w.route, cfg.ship, fleetTracker, w.role, fleetWorkingId, wemit, runStart);
30709
30960
  } finally {
@@ -30766,6 +31017,7 @@ ${f.tail.trimEnd()}
30766
31017
  const tracker = new Tracker(route2, cfg.ship);
30767
31018
  await applyHoldReleases(tracker, decision.holdReleases, tracker.contract, emit);
30768
31019
  }
31020
+ if (!dryRun) await discoverForRoute(route2, cfg.ship, decision.tickets, emit);
30769
31021
  const role = value("role") ?? decision.selection.selected;
30770
31022
  if (command === "poll") break;
30771
31023
  if (!dryRun) {
@@ -30945,6 +31197,7 @@ ${f.tail.trimEnd()}
30945
31197
  }
30946
31198
  try {
30947
31199
  const runStart = (/* @__PURE__ */ new Date()).toISOString();
31200
+ await markCrewAssistedAtLaunch(tracker2, route2, current, workingId ?? null, void 0, (m) => emit.warn(m, { step: "agent" }));
30948
31201
  await spawnAgent(plan, emit);
30949
31202
  await guardRunHandoff(route2, cfg.ship, tracker2, current, workingId, emit, runStart);
30950
31203
  } finally {
@@ -32992,7 +33245,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
32992
33245
  continue;
32993
33246
  }
32994
33247
  anything = true;
32995
- const res = await applyWorktreeSweep(r.dir, actions, dryRun, emit, r.config.branch.remote, r.config.branch.base, { state, repo: r.name });
33248
+ const res = await applyWorktreeSweep(r.dir, actions, dryRun, emit, r.config.branch.remote, r.config.branch.base, { state, repo: r.name }, clearBranchLink(tracker));
32996
33249
  if (!dryRun) reconcileHeldWorktrees(state, r.name, emit, /* @__PURE__ */ new Set([...res.refused, ...orphanDirs]));
32997
33250
  emit.emit(
32998
33251
  `swept ${res.removed} worktree(s) for ${r.name}, kept ${res.keptBranches} branch(es)`,
@@ -34787,9 +35040,20 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
34787
35040
  missingRuntime.length === 0 ? "runtime columns: forge_host, kind, instance_class, relay_url present\n" : `runtime columns: missing ${missingRuntime.join(", ")} \u2014 read as their defaults; update the Issues template
34788
35041
  `
34789
35042
  );
35043
+ {
35044
+ const have = await tracker.linkColumns();
35045
+ const lines2 = linkDoctorLines(have, reposOf(route2).map((t) => ({ name: t.name, host: t.forgeHost })), cfg.ship.forges, cfg.ship.stateDir);
35046
+ process.stdout.write(`${lines2.join("\n")}
35047
+ `);
35048
+ }
34790
35049
  process.stdout.write(
34791
35050
  await tracker.hasPublicReplyColumn() ? `public replies: Comments.${tracker.contract.comments.publicReply} present \u2014 public reporters are labelled in the digest
34792
35051
  ` : `public replies: Comments.${tracker.contract.comments.publicReply} absent \u2014 no public intake form, nothing to guard
35052
+ `
35053
+ );
35054
+ process.stdout.write(
35055
+ await tracker.hasCrewAssistedColumn() ? `crew assisted: Issues.${tracker.contract.columns.crewAssisted} present \u2014 Dev/QA runs mark the ticket
35056
+ ` : `crew assisted: Issues.${tracker.contract.columns.crewAssisted} absent \u2014 tickets are not marked; update the Issues template to adopt it
34793
35057
  `
34794
35058
  );
34795
35059
  const periscopes = await tracker.periscopesStatus();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tablation/crew",
3
- "version": "0.146.2",
3
+ "version": "0.148.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",