@tablation/crew 0.172.0 → 0.173.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 +110 -27
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -10032,6 +10032,8 @@ var encodeSort = (s) => JSON.stringify(s);
10032
10032
  var LIST_PAGE_SIZE = 500;
10033
10033
  var LIST_MAX_PAGES = 200;
10034
10034
  var LIST_SORT = encodeSort([{ columnName: "id", direction: "asc" }]);
10035
+ var OPEN_SET_OVERLAP_MS = 6e4;
10036
+ var openSetCache = /* @__PURE__ */ new Map();
10035
10037
  function actionableStatuses(c) {
10036
10038
  const s = c.statuses;
10037
10039
  const named = [s.approved, s.parked, s.building, s.handoff, s.verifying, s.verified, s.needsHuman, ...s.reviewing ? [s.reviewing] : []];
@@ -10130,11 +10132,56 @@ var Tracker = class _Tracker {
10130
10132
  if (areaId) base.push({ columnName: c.columns.slice, operator: "EQ", value: areaId });
10131
10133
  const queries = scope && scope.modes.size > 0 ? scopedTicketQueries(c, scope) : [[{ columnName: c.columns.status, operator: "IN", value: c.statuses.open }]];
10132
10134
  const seen = /* @__PURE__ */ new Map();
10135
+ const delta = scope ? await this.deltaOpenSet(base, queries) : void 0;
10136
+ if (delta) return delta;
10133
10137
  for (const q2 of queries) {
10134
10138
  for (const t of await this.listAll(this.models.issues, "open tickets", encodeFilters([...base, ...q2]))) seen.set(t.id, t);
10135
10139
  }
10140
+ if (scope && !this.truncated.has("open tickets")) {
10141
+ openSetCache.set(this.openSetKey(base, queries), { rows: new Map(seen), watermark: new Date(Date.now() - OPEN_SET_OVERLAP_MS).toISOString(), fullAt: Date.now() });
10142
+ }
10136
10143
  return [...seen.values()];
10137
10144
  }
10145
+ openSetKey(base, queries) {
10146
+ return `${this.route.baseUrl}|${this.models.issues}|${encodeFilters(base)}|${JSON.stringify(queries)}`;
10147
+ }
10148
+ /**
10149
+ * CREW-4016: the open set from the cache plus what changed since the last
10150
+ * read, or `undefined` when a full read is due (nothing cached, or the cache
10151
+ * is older than `Tracker.openSetReconcileMs`, which also repairs anything a
10152
+ * delta could miss: a clock skew past the overlap, a deleted row) or the
10153
+ * delta read failed.
10154
+ *
10155
+ * Two reads of rows with `updated_at` at or after the watermark: every row of
10156
+ * the area (to drop the ones that stopped matching), and the ones that match
10157
+ * each query. A row in the first and not the second left the open set.
10158
+ */
10159
+ async deltaOpenSet(base, queries) {
10160
+ const key = this.openSetKey(base, queries);
10161
+ const entry = openSetCache.get(key);
10162
+ if (!entry || Date.now() - entry.fullAt >= _Tracker.openSetReconcileMs) return void 0;
10163
+ const since2 = { columnName: "updated_at", operator: "GTE", value: entry.watermark };
10164
+ try {
10165
+ const changed2 = await this.listAll(this.models.issues, "changed tickets", encodeFilters([...base, since2]));
10166
+ if (this.truncated.has("changed tickets")) {
10167
+ this.truncated.delete("changed tickets");
10168
+ return void 0;
10169
+ }
10170
+ const matching = /* @__PURE__ */ new Map();
10171
+ for (const q2 of queries) {
10172
+ for (const t of await this.listAll(this.models.issues, "open tickets", encodeFilters([...base, ...q2, since2]))) matching.set(t.id, t);
10173
+ }
10174
+ for (const t of changed2) entry.rows.delete(t.id);
10175
+ for (const [id, t] of matching) entry.rows.set(id, t);
10176
+ let newest = Date.parse(entry.watermark);
10177
+ for (const t of changed2) newest = Math.max(newest, Date.parse(t.updated_at) || 0);
10178
+ entry.watermark = new Date(newest).toISOString();
10179
+ return [...entry.rows.values()].map((t) => ({ ...t }));
10180
+ } catch {
10181
+ openSetCache.delete(key);
10182
+ return void 0;
10183
+ }
10184
+ }
10138
10185
  /**
10139
10186
  * Every ticket of this route's area at `status`, which need not be an open
10140
10187
  * one (CREW-2290: the pipeline mode reads tickets released to QA, a status no
@@ -10188,6 +10235,8 @@ var Tracker = class _Tracker {
10188
10235
  truncated = /* @__PURE__ */ new Map();
10189
10236
  /** The page backstop `listAll` stops at; a variable only so a test can reach it without a hundred thousand rows. */
10190
10237
  static maxPages = LIST_MAX_PAGES;
10238
+ /** How long a poll trusts its cached open set before reading all of it again (CREW-4016). */
10239
+ static openSetReconcileMs = 6e4;
10191
10240
  /** Records that the list `what` hit `limit` rows and may be missing more. */
10192
10241
  noteTruncated(what, limit) {
10193
10242
  this.truncated.set(what, limit);
@@ -13661,6 +13710,13 @@ var TICKET_KEY_RE = /\b[A-Z][A-Z0-9]{1,9}-\d+\b/g;
13661
13710
  function ticketMentions(text2) {
13662
13711
  return [...text2.matchAll(TICKET_KEY_RE)].map((m) => m[0]);
13663
13712
  }
13713
+ function canonicalTicketKey(key, hint) {
13714
+ if (!hint || hint === key) return key;
13715
+ const issue = /^ISSUE-(\d+)$/.exec(key);
13716
+ if (!issue) return key;
13717
+ const tagged = /^[A-Z][A-Z0-9]{1,9}-(\d+)$/.exec(hint);
13718
+ return tagged && tagged[1] === issue[1] && !hint.startsWith("ISSUE-") ? hint : key;
13719
+ }
13664
13720
  var TicketAttributionTracker = class {
13665
13721
  #tokensByTicket = /* @__PURE__ */ new Map();
13666
13722
  #turns = 0;
@@ -16010,7 +16066,8 @@ var RunObserver = class {
16010
16066
  if (ev.kind === "tool") this.attribution.noteWrite(ev.tool, ev.input);
16011
16067
  if (ev.kind === "tool") this.beforeFirstEdit.note(ev.tool, ev.target, this.muted ? void 0 : Date.now() - this.startMs);
16012
16068
  if (ev.kind === "tool" && isClaimWrite(ev.tool, ev.input)) {
16013
- const claimed = this.attribution.current;
16069
+ const named = this.attribution.current;
16070
+ const claimed = named ? canonicalTicketKey(named, plan.ticket) : void 0;
16014
16071
  if (claimed && claimed !== this.liveTicket) {
16015
16072
  if (!this.muted) {
16016
16073
  this.eventsSink?.write(`${JSON.stringify({
@@ -16103,7 +16160,9 @@ async function finishRun(id, obs, emit, startedAt, end, agentLogKey, hintMoved)
16103
16160
  } catch {
16104
16161
  }
16105
16162
  }
16106
- const { ticket: attributedTicket, by: attributedBy } = obs.attribution.decide(obs.liveTicket, { hintMoved: moved });
16163
+ const decided = obs.attribution.decide(obs.liveTicket, { hintMoved: moved });
16164
+ const attributedBy = decided.by;
16165
+ const attributedTicket = decided.ticket ? canonicalTicketKey(decided.ticket, id.ticket) : void 0;
16107
16166
  const identity = { toolchain: id.toolchain, harness: id.harness, provider: id.provider };
16108
16167
  const { result } = obs;
16109
16168
  const pending = end.interrupted ? null : obs.handoff.pending();
@@ -25399,7 +25458,7 @@ async function reconcileRouteShipName(o) {
25399
25458
  stateDir: o.ship.stateDir,
25400
25459
  ship: o.ship,
25401
25460
  machineId,
25402
- rows: () => tracker.shipRows(),
25461
+ rows: o.rows ?? (() => tracker.shipRows()),
25403
25462
  rename: (id, name) => tracker.renameShipRow(id, name),
25404
25463
  emit: o.emit,
25405
25464
  readOnly: o.readOnly
@@ -30724,7 +30783,7 @@ import { dirname as dirOf2, resolve as resolvePath } from "path";
30724
30783
  import { existsSync as existsSync58, readdirSync as readdirSync18, statSync as statSync18 } from "fs";
30725
30784
  import { join as join62 } from "path";
30726
30785
  function builtVersion() {
30727
- return true ? "0.172.0" : null;
30786
+ return true ? "0.173.0" : null;
30728
30787
  }
30729
30788
  var REBUILD_HINT = "rebuild with npm run build";
30730
30789
  function newestMtime(path) {
@@ -32762,6 +32821,20 @@ function findPeriscope(sidecars, segment) {
32762
32821
  }
32763
32822
 
32764
32823
  // src/cli.ts
32824
+ var TRACKER_BLOCKS = [
32825
+ "todo",
32826
+ "ships",
32827
+ "route.projects",
32828
+ "route.crewMinVersion",
32829
+ "ship.rowName",
32830
+ "ship.nameDrift",
32831
+ "crew.repos[].worktreePrefix(area prefix)",
32832
+ "crew.seats[].name",
32833
+ "crew.seats[].personaName",
32834
+ "crew.seats[].missing",
32835
+ "runs[].title",
32836
+ "runs[].ticket(display tag)"
32837
+ ];
32765
32838
  var CREW_HOME = isCompiledBinary(import.meta.url) ? dirname39(process.execPath) : resolve8(dirname39(fileURLToPath2(import.meta.url)), "..");
32766
32839
  {
32767
32840
  const v = crewVersion(CREW_HOME);
@@ -32924,6 +32997,7 @@ function usage(problem, requested = false) {
32924
32997
  crew watch [route] live view of what the crew is doing
32925
32998
  crew --version [--json] print the crew version on one line (also: crew version); --json adds home and compiled
32926
32999
  crew status [route] [--json] [--verbose] what is running and what needs a person; --verbose adds configuration and full lists; --json for a machine reader
33000
+ crew status [route] --json --no-tracker the same document from this ship alone, with no tracker request; leaves out todo, ships, projects, crewMinVersion, seat names, rowName/nameDrift and the area worktree prefix
32927
33001
  crew projects [--route R] [--json] the Projects rows each route can read (id, name, prefix, work mode)
32928
33002
  crew routes available [--json] the tracker apps you can reach that this machine has no route for (read-only; starts no sign-in)
32929
33003
  crew projects add [route] NAME --prefix P [--work-mode automatic|hybrid|manual] [--json] [--dry-run] create a Projects row
@@ -34054,11 +34128,11 @@ if (command === "passenger-sync-daemon") {
34054
34128
  ${changed2.map((c) => ` - ${c}
34055
34129
  `).join("")}` : "fix: nothing changed\n");
34056
34130
  }
34057
- async function resolvedRepos(c) {
34058
- return (await resolveRoute(c)).settled;
34131
+ async function resolvedRepos(c, opts = {}) {
34132
+ return (await resolveRoute(c, opts)).settled;
34059
34133
  }
34060
- async function resolveRoute(c) {
34061
- const { settled, errors } = await settleRepos(reposOf(c), (t) => t.name, (t) => resolveOneRepo(c, t));
34134
+ async function resolveRoute(c, opts = {}) {
34135
+ const { settled, errors } = await settleRepos(reposOf(c), (t) => t.name, (t) => resolveOneRepo(c, t, opts));
34062
34136
  for (const e of errors) {
34063
34137
  try {
34064
34138
  await raiseShipAttention({ state, emit }, repoContractRefusedItem(e.repo, e.detail));
@@ -34133,7 +34207,7 @@ ${changed2.map((c) => ` - ${c}
34133
34207
  const t = repo ? reposOf(c).find((r) => r.name === repo) : void 0;
34134
34208
  return t && cfg.ship.runner === "sandbox" ? repoContractFor(cfg.ship, c, t) : void 0;
34135
34209
  }
34136
- async function resolveOneRepo(c, t) {
34210
+ async function resolveOneRepo(c, t, opts = {}) {
34137
34211
  {
34138
34212
  const id = repoIdForName(c, t.name);
34139
34213
  const o = c.repoOverrides[t.name];
@@ -34155,7 +34229,8 @@ ${changed2.map((c) => ` - ${c}
34155
34229
  // that declares its own `worktrees.prefix` shadows either, and
34156
34230
  // `doctor` reports that the way it reports every other shadowed
34157
34231
  // setting.
34158
- worktrees: { prefix: shipWorktreePrefixFor(c) ?? await areaWorktreePrefix(c, id), nameOverride: o?.worktreeName }
34232
+ // CREW-4019: `status --json --no-tracker` makes no tracker request, so the area's prefix is not read.
34233
+ worktrees: { prefix: shipWorktreePrefixFor(c) ?? (opts.noTracker ? void 0 : await areaWorktreePrefix(c, id)), nameOverride: o?.worktreeName }
34159
34234
  }, t.dir)
34160
34235
  };
34161
34236
  }
@@ -38927,21 +39002,27 @@ ${where.join("\n")}`);
38927
39002
  }
38928
39003
  process.exit(1);
38929
39004
  }
38930
- const shipRows = await statusTracker.shipRows();
39005
+ const noTracker = flag("no-tracker");
39006
+ if (noTracker && !flag("json")) die("crew status", "--no-tracker applies to --json", "`crew status --json --no-tracker`");
39007
+ let openRead;
39008
+ const openTicketsOnce = () => openRead ??= statusTracker.openTickets();
39009
+ const trackerReadAt = (/* @__PURE__ */ new Date()).toISOString();
39010
+ const shipRows = noTracker ? [] : await statusTracker.shipRows();
38931
39011
  const engagedTicketIds = shipRows.map((s) => s.engaged_ticket_id).filter((id) => !!id);
38932
39012
  const engagedTickets = engagedTicketIds.length ? await statusTracker.ticketsByIds(engagedTicketIds) : [];
38933
39013
  const issueLabelById = new Map(engagedTickets.map((t) => [t.id, displayKey(t)]));
38934
- const todo = await statusTracker.openTickets().then((open2) => operatorTodo(open2, statusTracker.contract, route2.resolved?.operator ?? "")).catch(() => []);
38935
- const projects = projectModeLabels(await statusTracker.projectRowsWithModes().catch(() => []));
38936
- const crewMinVersion = await readCrewFloor(route2, cfg.ship) ?? null;
39014
+ const todo = noTracker ? [] : await openTicketsOnce().then((open2) => operatorTodo(open2, statusTracker.contract, route2.resolved?.operator ?? "")).catch(() => []);
39015
+ const projects = noTracker ? [] : projectModeLabels(await statusTracker.projectRowsWithModes().catch(() => []));
39016
+ const crewMinVersion = noTracker ? null : await readCrewFloor(route2, cfg.ship) ?? null;
38937
39017
  const runs = liveRuns(cfg.ship.stateDir);
38938
39018
  const runTitles = new Map(
38939
- (await statusTracker.ticketsByIds([...new Set(runs.map((x) => x.ticketRecordId).filter((id) => !!id))]).catch(() => [])).map((t) => [t.id, t.title ?? null])
39019
+ (noTracker ? [] : await statusTracker.ticketsByIds([...new Set(runs.map((x) => x.ticketRecordId).filter((id) => !!id))]).catch(() => [])).map((t) => [t.id, t.title ?? null])
38940
39020
  );
38941
39021
  const lastRuns = lastRunsBySeat(cfg.ship.stateDir);
38942
39022
  const thisSlug = routeSlug(route2.route);
38943
39023
  const otherSources = /* @__PURE__ */ new Map();
38944
39024
  const sourceFor = (slug2) => {
39025
+ if (noTracker) return void 0;
38945
39026
  if (slug2 === thisSlug) return statusTracker;
38946
39027
  if (!otherSources.has(slug2)) {
38947
39028
  const rt = cfg.routes.find((x) => routeSlug(x.route) === slug2);
@@ -38960,11 +39041,11 @@ ${where.join("\n")}`);
38960
39041
  const periscopes = await periscopesForStatus(cfg.ship.stateDir);
38961
39042
  const runPreviews = new Map(periscopes.filter((p) => p.serving).map((p) => [p.ticketRecordId, p.url]));
38962
39043
  if (flag("json")) {
38963
- const nameSync = await reconcileRouteShipName({ route: route2, ship: cfg.ship, configFile: cfg.configFile, readOnly: true });
38964
- const repos = await resolvedRepos(route2);
39044
+ const nameSync = noTracker ? void 0 : await reconcileRouteShipName({ route: route2, ship: cfg.ship, configFile: cfg.configFile, readOnly: true, rows: async () => shipRows });
39045
+ const repos = await resolvedRepos(route2, { noTracker });
38965
39046
  const seatIds = route2.resolved?.seats ?? {};
38966
- const crewRows = Object.keys(seatIds).length ? await statusTracker.crewRows() : [];
38967
- const seatProbes = await probeSeats(route2, (id) => statusTracker.crewRow(id));
39047
+ const crewRows = !noTracker && Object.keys(seatIds).length ? await statusTracker.crewRows() : [];
39048
+ const seatProbes = noTracker ? [] : await probeSeats(route2, (id) => statusTracker.crewRow(id));
38968
39049
  const seatProbeOf = (role) => seatProbes.find((p) => p.role === role);
38969
39050
  const crewRowById = new Map(crewRows.map((c) => [c.id, c]));
38970
39051
  const agentPersonas = route2.resolved?.agentPersonas ?? {};
@@ -39016,15 +39097,17 @@ ${where.join("\n")}`);
39016
39097
  // derived `release_stale`. `version` stays 1.
39017
39098
  attention: mergeSeatAttention(openShipAttention(state), route2, seatProbes),
39018
39099
  // Additive (CREW-2495): this ship's Ships-row name and whether it has drifted from `name`.
39019
- rowName: nameSync.rowName ?? null,
39020
- nameDrift: nameSync.drift,
39100
+ ...nameSync ? { rowName: nameSync.rowName ?? null, nameDrift: nameSync.drift } : {},
39021
39101
  // Additive (CREW-2803): the relay URL this route's tunnel is reachable at, or null.
39022
39102
  relayUrl: routeRelayUrl(route2),
39023
39103
  // Additive (CREW-2887): when a `crew reload` request was written and not yet honored, else null.
39024
39104
  reloadRequestedAt: ((at) => at === null ? null : new Date(at).toISOString())(readReloadRequestedAt(cfg.ship.stateDir))
39025
39105
  },
39106
+ // Additive (CREW-4019): when the tracker-derived blocks were read, or that they were left out
39107
+ // (`--no-tracker`) and which. A block named in `omitted` is absent, never empty.
39108
+ tracker: noTracker ? { read: false, readAt: null, omitted: [...TRACKER_BLOCKS] } : { read: true, readAt: trackerReadAt, omitted: [] },
39026
39109
  // Additive (CREW-1402): what the operator owes. `version` stays 1.
39027
- todo: todo.map((i) => ({ ticket: displayKey(i.ticket), title: i.ticket.title ?? null, reasons: i.reasons })),
39110
+ ...noTracker ? {} : { todo: todo.map((i) => ({ ticket: displayKey(i.ticket), title: i.ticket.title ?? null, reasons: i.reasons })) },
39028
39111
  crew: {
39029
39112
  paused: state.isPaused(),
39030
39113
  // The release timer honors the whole-crew pause too, so this is
@@ -39042,9 +39125,9 @@ ${where.join("\n")}`);
39042
39125
  name: route2.route,
39043
39126
  // Additive (CREW-2248): the running version and the workspace's floor. `version` stays 1.
39044
39127
  crewVersion: sentVersion(cfg.ship),
39045
- crewMinVersion,
39128
+ ...noTracker ? {} : { crewMinVersion },
39046
39129
  // Additive (CREW-1496): each project and its work mode. `version` stays 1.
39047
- projects: projects.map((p) => ({ id: p.id, name: p.name, workMode: p.mode })),
39130
+ ...noTracker ? {} : { projects: projects.map((p) => ({ id: p.id, name: p.name, workMode: p.mode })) },
39048
39131
  dir: route2.dir,
39049
39132
  // Additive (CREW-2548): open tickets with no repository, as of the last cycle.
39050
39133
  unroutable: state.unroutable(route2.route).previous().length,
@@ -39084,7 +39167,7 @@ ${where.join("\n")}`);
39084
39167
  })),
39085
39168
  waiting: waiting ? { ticket: waiting.ticket, since: waiting.since, streak: fairness.streak() } : null
39086
39169
  },
39087
- ships: shipRows.map((s) => ({
39170
+ ...noTracker ? {} : { ships: shipRows.map((s) => ({
39088
39171
  ...shipIdentityJson(s),
39089
39172
  name: s.name ?? null,
39090
39173
  lastSeen: s.last_seen ?? null,
@@ -39093,7 +39176,7 @@ ${where.join("\n")}`);
39093
39176
  engagedRoute: s.engaged_connection ?? null,
39094
39177
  engagedTicket: s.engaged_ticket_id ? issueLabelById.get(s.engaged_ticket_id) ?? null : null,
39095
39178
  attention: s.attention ?? []
39096
- }))
39179
+ })) }
39097
39180
  }, null, 2)}
39098
39181
  `);
39099
39182
  break;
@@ -39103,7 +39186,7 @@ ${where.join("\n")}`);
39103
39186
  let waitViews = [];
39104
39187
  let deferredReleases = [];
39105
39188
  try {
39106
- const open2 = await statusTracker.openTickets();
39189
+ const open2 = await openTicketsOnce();
39107
39190
  const blockerInfo = blockerInfoMap(open2, await statusTracker.ticketsByIds(missingBlockerIds(open2)));
39108
39191
  heldReleases = describeHeld(heldByBlockers(open2, statusTracker.contract.statuses.verified, blockerInfo, new Set(statusTracker.contract.statuses.resolved)));
39109
39192
  waitViews = [...planFootprintsFor(route2, open2, await readFootprintEvents(statusTracker), computeBlockedIds(open2, blockerInfo, { resolved: new Set(statusTracker.contract.statuses.resolved) })).waits.values()].map((w) => ({ ticket: displayKey(w.ticket), waitingFor: w.waitingFor, files: w.files }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tablation/crew",
3
- "version": "0.172.0",
3
+ "version": "0.173.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",