@wrenautomation/aerie 0.8.5 → 0.8.7

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 (43) hide show
  1. package/dist/backlog/files.d.ts +2 -0
  2. package/dist/backlog/files.js +8 -0
  3. package/dist/backlog/files.js.map +1 -1
  4. package/dist/backlog/index.d.ts +1 -1
  5. package/dist/backlog/index.js +1 -1
  6. package/dist/backlog/index.js.map +1 -1
  7. package/dist/bin.js +232 -37
  8. package/dist/bin.js.map +4 -4
  9. package/dist/cli-run.d.ts +2 -0
  10. package/dist/cli-run.js +39 -9
  11. package/dist/cli-run.js.map +1 -1
  12. package/dist/cli.js +31 -22
  13. package/dist/cli.js.map +1 -1
  14. package/dist/coord/audit.d.ts +45 -0
  15. package/dist/coord/audit.js +64 -0
  16. package/dist/coord/audit.js.map +1 -0
  17. package/dist/coord/port.d.ts +19 -0
  18. package/dist/coord/postgres.d.ts +5 -1
  19. package/dist/coord/postgres.js +30 -8
  20. package/dist/coord/postgres.js.map +1 -1
  21. package/dist/core/task.d.ts +4 -1
  22. package/dist/core/task.js +9 -0
  23. package/dist/core/task.js.map +1 -1
  24. package/dist/http.d.ts +4 -24
  25. package/dist/http.js +5 -4
  26. package/dist/http.js.map +1 -1
  27. package/dist/mirror.d.ts +2 -0
  28. package/dist/mirror.js +15 -1
  29. package/dist/mirror.js.map +1 -1
  30. package/dist/peers-coord.js +95 -11
  31. package/dist/peers-coord.js.map +2 -2
  32. package/dist/remote.js +7 -0
  33. package/dist/remote.js.map +1 -1
  34. package/dist/schema.d.ts +181 -0
  35. package/dist/schema.js +21 -0
  36. package/dist/schema.js.map +1 -1
  37. package/dist/store.d.ts +1 -0
  38. package/dist/store.js +29 -1
  39. package/dist/store.js.map +1 -1
  40. package/drizzle/0013_coord_lease_event.sql +16 -0
  41. package/drizzle/meta/0013_snapshot.json +2049 -0
  42. package/drizzle/meta/_journal.json +7 -0
  43. package/package.json +1 -1
@@ -8378,7 +8378,7 @@ function oneOf(name, col, values) {
8378
8378
  const list = values.map((v) => `'${v.replaceAll("'", "''")}'`).join(", ");
8379
8379
  return check(name, sql.raw(`"${col.name}" IN (${list})`));
8380
8380
  }
8381
- var aerie, ACTOR_KINDS, AREA_ROLES, TASK_ROLES, LAYOUTS, PLACES, at, area, actor, areaRole, task, taskArea, taskActor, taskHolder, view, tsvector, taskEvent, milestone, mirrorFile, setting, coordGen, coordLease, coordClosing, coordTask, coordQueue, decision, routeRule, intake, remoteCall;
8381
+ var aerie, ACTOR_KINDS, AREA_ROLES, TASK_ROLES, LAYOUTS, PLACES, at, area, actor, areaRole, task, taskArea, taskActor, taskHolder, view, tsvector, taskEvent, milestone, mirrorFile, setting, coordGen, coordLease, coordClosing, coordTask, coordLeaseEvent, coordQueue, decision, routeRule, intake, remoteCall;
8382
8382
  var init_schema2 = __esm({
8383
8383
  "src/schema.ts"() {
8384
8384
  "use strict";
@@ -8677,6 +8677,27 @@ var init_schema2 = __esm({
8677
8677
  },
8678
8678
  (t) => [primaryKey({ columns: [t.ns, t.taskId], name: "pk_coord_task" })]
8679
8679
  );
8680
+ coordLeaseEvent = aerie.table(
8681
+ "coord_lease_event",
8682
+ {
8683
+ id: bigserial({ mode: "number" }).notNull(),
8684
+ ns: text().notNull(),
8685
+ taskId: text("task_id").notNull(),
8686
+ holder: text().notNull(),
8687
+ gen: bigint({ mode: "number" }).notNull(),
8688
+ /** claim | take (from the queue) | reclaim | release | done | expire (freed by `by`) | lost (lapsed, seen at renew) | reap (lapsed run lane) */
8689
+ kind: text().notNull(),
8690
+ queued: boolean().notNull(),
8691
+ expires: at("expires").notNull(),
8692
+ by: text().notNull(),
8693
+ at: at("at").notNull()
8694
+ },
8695
+ (t) => [
8696
+ primaryKey({ columns: [t.id], name: "pk_coord_lease_event" }),
8697
+ index("coord_lease_event_task_idx").on(t.ns, t.taskId),
8698
+ index("coord_lease_event_at_idx").on(t.ns, t.at)
8699
+ ]
8700
+ );
8680
8701
  coordQueue = aerie.table(
8681
8702
  "coord_queue",
8682
8703
  {
@@ -8961,6 +8982,11 @@ var init_filter = __esm({
8961
8982
  });
8962
8983
 
8963
8984
  // src/core/task.ts
8985
+ function statusIn(all, s) {
8986
+ const hit = all.find((x) => x.toLowerCase() === s.trim().toLowerCase());
8987
+ if (!hit) throw new Error(`unknown status "${s}" (one of: ${all.join(", ")})`);
8988
+ return hit;
8989
+ }
8964
8990
  function sameTask(a, b) {
8965
8991
  return canonical(a) === canonical(b);
8966
8992
  }
@@ -8978,6 +9004,7 @@ var init_task = __esm({
8978
9004
  STATUSES = [
8979
9005
  "To Do",
8980
9006
  "In Progress",
9007
+ "In Testing",
8981
9008
  "Needs Human Input",
8982
9009
  "Backlog",
8983
9010
  "Parked",
@@ -9666,6 +9693,8 @@ function aerieStore(o) {
9666
9693
  async function create(input2, by, opts = {}) {
9667
9694
  const id = await write2(by, async (tx) => {
9668
9695
  const parent = input2.parentId ? await must(input2.parentId, tx) : null;
9696
+ if (input2.status !== void 0)
9697
+ input2 = { ...input2, status: await statusName(tx, input2.status) };
9669
9698
  if (input2.milestone)
9670
9699
  input2 = { ...input2, milestone: await milestoneOf(tx, input2.milestone) };
9671
9700
  const id2 = await nextId(tx, parent?.id);
@@ -9704,6 +9733,7 @@ function aerieStore(o) {
9704
9733
  if (opts.expect !== void 0 && opts.expect !== row.version)
9705
9734
  throw new AerieError(`stale: ${row.id} is at version ${row.version}`, 409);
9706
9735
  const was = await must(row.id, tx);
9736
+ if (e.status !== void 0) e = { ...e, status: await statusName(tx, e.status) };
9707
9737
  if (e.parentId) e = { ...e, parentId: (await must(e.parentId, tx)).id };
9708
9738
  if (e.milestone) e = { ...e, milestone: await milestoneOf(tx, e.milestone) };
9709
9739
  const t = applyEdit(was, e, now());
@@ -9838,6 +9868,22 @@ function aerieStore(o) {
9838
9868
  dependencies: task.dependencies
9839
9869
  }).from(task);
9840
9870
  }
9871
+ async function statuses(q = db) {
9872
+ const r = await q.select({ v: setting.value }).from(setting).where(eq(setting.key, "statuses"));
9873
+ try {
9874
+ const v = JSON.parse(r[0]?.v ?? "null");
9875
+ if (Array.isArray(v) && v.length && v.every((x) => typeof x === "string")) return v;
9876
+ } catch {
9877
+ }
9878
+ return [...STATUSES];
9879
+ }
9880
+ async function statusName(q, v) {
9881
+ try {
9882
+ return statusIn(await statuses(q), v);
9883
+ } catch (e) {
9884
+ throw new AerieError(e.message);
9885
+ }
9886
+ }
9841
9887
  async function getSetting(key) {
9842
9888
  const r = await db.select({ v: setting.value }).from(setting).where(eq(setting.key, key));
9843
9889
  return r[0]?.v ?? null;
@@ -10008,6 +10054,7 @@ function aerieStore(o) {
10008
10054
  ask,
10009
10055
  decide,
10010
10056
  prefixOf,
10057
+ statuses,
10011
10058
  getSetting,
10012
10059
  setSetting
10013
10060
  };
@@ -10059,6 +10106,7 @@ function pgCoord(o) {
10059
10106
  const C = coordClosing;
10060
10107
  const T = coordTask;
10061
10108
  const Q = coordQueue;
10109
+ const E = coordLeaseEvent;
10062
10110
  const lockQueue = (tx) => tx.execute(
10063
10111
  sql`select pg_advisory_xact_lock(hashtextextended(${`aerie.coord:${ns}:queue`}, 0))`
10064
10112
  );
@@ -10078,7 +10126,7 @@ function pgCoord(o) {
10078
10126
  if (!hit[0] || hit[0].status === name) return;
10079
10127
  await aerieStore({ db: tx }).edit(id, { status: name }, by);
10080
10128
  };
10081
- const lease = async (tx, id, holder, leaseMs, queued, key) => {
10129
+ const lease = async (tx, id, holder, leaseMs, queued, key, how = "claim") => {
10082
10130
  const t = clock();
10083
10131
  const others = await rows(
10084
10132
  tx,
@@ -10091,13 +10139,17 @@ function pgCoord(o) {
10091
10139
  );
10092
10140
  const gen = num(g?.gen);
10093
10141
  await tx.execute(sql`
10094
- insert into ${L} (ns, task_id, holder, gen, expires, queued, lane, pin, take_key)
10142
+ with up as (insert into ${L} (ns, task_id, holder, gen, expires, queued, lane, pin, take_key)
10095
10143
  values (${ns}, ${id}, ${holder}, ${gen}, ${plus(t, leaseMs)}, ${!!queued}, ${queued?.lane ?? null}, ${queued?.pin ?? null}, ${key ?? null})
10096
10144
  on conflict (ns, task_id, holder) do update set gen = excluded.gen, expires = excluded.expires,
10097
10145
  take_key = coalesce(excluded.take_key, ${L}.take_key),
10098
10146
  queued = excluded.queued or ${L}.queued,
10099
10147
  lane = case when excluded.queued then excluded.lane else ${L}.lane end,
10100
- pin = case when excluded.queued then excluded.pin else ${L}.pin end`);
10148
+ pin = case when excluded.queued then excluded.pin else ${L}.pin end
10149
+ returning task_id, holder, gen, queued, expires, (xmax = 0) as fresh)
10150
+ insert into ${E} (ns, task_id, holder, gen, kind, queued, expires, by, at)
10151
+ select ${ns}, task_id, holder, gen, case when fresh then ${how} else 'reclaim' end, queued, expires, holder, ${t}
10152
+ from up`);
10101
10153
  await touch(tx, id, t);
10102
10154
  await setStatus(tx, id, "doing", holder);
10103
10155
  return { gen, others: others.map((r) => r.holder) };
@@ -10110,8 +10162,13 @@ function pgCoord(o) {
10110
10162
  if (!has.length) return { last: true, closeNow: false, status: "ready" };
10111
10163
  const gone = await rows(
10112
10164
  tx,
10113
- sql`delete from ${L} where ns = ${ns} and task_id = ${id} and holder = any(${textArr(holders)})
10114
- returning holder, queued, lane, pin`
10165
+ sql`with gone as (delete from ${L} where ns = ${ns} and task_id = ${id} and holder = any(${textArr(holders)})
10166
+ returning holder, gen, queued, lane, pin, expires),
10167
+ logged as (insert into ${E} (ns, task_id, holder, gen, kind, queued, expires, by, at)
10168
+ select ${ns}, ${id}, holder, gen,
10169
+ case when holder <> ${x.by} then 'expire' else ${x.done ? "done" : x.why ?? "release"} end,
10170
+ queued, expires, ${x.by}, ${t} from gone)
10171
+ select holder, queued, lane, pin from gone`
10115
10172
  );
10116
10173
  if (x.done && gone.some((l) => l.holder === x.by))
10117
10174
  await tx.execute(sql`insert into ${C} (ns, task_id, holder, reason, at)
@@ -10191,7 +10248,7 @@ function pgCoord(o) {
10191
10248
  );
10192
10249
  if (!still.length) continue;
10193
10250
  lost.push({ id: l.id, holder: l.holder });
10194
- await drop(tx, l.id, [l.holder], { queue: l.queued, by: l.holder });
10251
+ await drop(tx, l.id, [l.holder], { queue: l.queued, by: l.holder, why: "lost" });
10195
10252
  }
10196
10253
  }
10197
10254
  await tx.execute(sql`update ${L} set expires = ${plus(t, leaseMs)}
@@ -10319,7 +10376,8 @@ function pgCoord(o) {
10319
10376
  sql`select 1 from ${L} where ns = ${ns} and task_id = ${l.id} and holder = ${l.holder}
10320
10377
  and expires < ${t}`
10321
10378
  );
10322
- if (still.length) await drop(tx, l.id, [l.holder], { queue: l.queued, by: l.holder });
10379
+ if (still.length)
10380
+ await drop(tx, l.id, [l.holder], { queue: l.queued, by: l.holder, why: "reap" });
10323
10381
  }
10324
10382
  }
10325
10383
  if (x.cap !== void 0) {
@@ -10349,10 +10407,28 @@ function pgCoord(o) {
10349
10407
  holder,
10350
10408
  leaseMs,
10351
10409
  { lane: item.lane, pin: item.pin },
10352
- x.key
10410
+ x.key,
10411
+ "take"
10353
10412
  );
10354
10413
  return { id: item.id, gen: r.gen };
10355
10414
  }),
10415
+ leaseEvents: async ({ since, limit = 1e4 }) => (await rows(
10416
+ db,
10417
+ sql`select id::float8 as id, task_id, holder, gen::float8 as gen, kind, queued, ${ms(sql`expires`)} as expires,
10418
+ by, ${ms(sql`at`)} as at from ${E} where ns = ${ns} and at >= ${at2(since)} order by id limit ${limit}`
10419
+ )).map(
10420
+ (r) => ({
10421
+ id: num(r.id),
10422
+ task: String(r.task_id),
10423
+ holder: String(r.holder),
10424
+ gen: num(r.gen),
10425
+ kind: r.kind,
10426
+ queued: !!r.queued,
10427
+ expires: num(r.expires),
10428
+ by: String(r.by),
10429
+ at: num(r.at)
10430
+ })
10431
+ ),
10356
10432
  fence: async (id, holder, gen) => (await rows(
10357
10433
  db,
10358
10434
  sql`select 1 from ${L} where ns = ${ns} and task_id = ${id} and holder = ${holder}
@@ -31780,7 +31856,8 @@ var init_http = __esm({
31780
31856
  EDIT = {
31781
31857
  title: external_exports.string().trim().min(1).max(500).optional(),
31782
31858
  description: TEXT.optional(),
31783
- status: external_exports.enum(STATUSES).optional(),
31859
+ status: external_exports.string().trim().min(1).max(100).optional(),
31860
+ // the store checks it against the board
31784
31861
  priority: external_exports.enum(["high", "medium", "low"]).nullish(),
31785
31862
  type: external_exports.string().max(100).nullish(),
31786
31863
  milestone: external_exports.string().max(200).nullish(),
@@ -32090,6 +32167,7 @@ var init_remote = __esm({
32090
32167
  ]),
32091
32168
  views: read([BY], 0),
32092
32169
  prefixOf: read(),
32170
+ statuses: read(),
32093
32171
  mirrorAreas: read(),
32094
32172
  getSetting: read([external_exports.string().min(1).max(100)]),
32095
32173
  create: write(
@@ -32232,7 +32310,13 @@ var init_remote = __esm({
32232
32310
  HOLDER,
32233
32311
  MS
32234
32312
  ]),
32235
- fence: read([ID2, HOLDER, external_exports.int().nonnegative()])
32313
+ fence: read([ID2, HOLDER, external_exports.int().nonnegative()]),
32314
+ leaseEvents: read([
32315
+ external_exports.strictObject({
32316
+ since: external_exports.number().nonnegative(),
32317
+ limit: external_exports.int().positive().max(1e4).optional()
32318
+ })
32319
+ ])
32236
32320
  };
32237
32321
  OPS = { store: STORE_OPS, coord: COORD_OPS };
32238
32322
  CALL = external_exports.object({