@tablation/crew 0.172.0 → 0.172.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 (2) hide show
  1. package/dist/cli.js +50 -1
  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);
@@ -30724,7 +30773,7 @@ import { dirname as dirOf2, resolve as resolvePath } from "path";
30724
30773
  import { existsSync as existsSync58, readdirSync as readdirSync18, statSync as statSync18 } from "fs";
30725
30774
  import { join as join62 } from "path";
30726
30775
  function builtVersion() {
30727
- return true ? "0.172.0" : null;
30776
+ return true ? "0.172.1" : null;
30728
30777
  }
30729
30778
  var REBUILD_HINT = "rebuild with npm run build";
30730
30779
  function newestMtime(path) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tablation/crew",
3
- "version": "0.172.0",
3
+ "version": "0.172.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",