trantor 0.18.148 → 0.18.152

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 (44) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/bin/advise.mjs +11 -8
  4. package/bin/cli.mjs +1 -1
  5. package/bin/connect.mjs +10 -1
  6. package/bin/crew/state.mjs +1 -1
  7. package/bin/crew-runner.mjs +9 -6
  8. package/bin/docker-seat.mjs +33 -0
  9. package/bin/heavy-gate-shim/docker +2 -0
  10. package/bin/integrate.mjs +38 -9
  11. package/bin/migrate-dispatcher.mjs +50 -0
  12. package/bin/turn-watchdog.mjs +15 -1
  13. package/deploy/restart-hub.sh +2 -0
  14. package/docs/FEATURES.md +4 -1
  15. package/hooks/sessionstart.mjs +6 -1
  16. package/hub/auth.mjs +8 -3
  17. package/hub/routes/cards.mjs +13 -1
  18. package/hub/routes/dispatcher-operations.mjs +134 -0
  19. package/hub/routes/dispatcher.mjs +18 -9
  20. package/hub/routes/git-policy.mjs +35 -0
  21. package/hub/startup-config.mjs +14 -0
  22. package/hub/store.mjs +49 -0
  23. package/hub.mjs +19 -2
  24. package/kimi.plugin.json +1 -1
  25. package/lib/canary/canary.mjs +2 -0
  26. package/lib/canary/probes.mjs +62 -0
  27. package/lib/dispatcher/admission.mjs +16 -3
  28. package/lib/dispatcher/board-bridge.mjs +82 -0
  29. package/lib/dispatcher/evidence-bridge.mjs +283 -0
  30. package/lib/dispatcher/operations.mjs +527 -0
  31. package/lib/dispatcher/planner.mjs +4 -2
  32. package/lib/dispatcher/preflight.mjs +44 -7
  33. package/lib/dispatcher/rollout.mjs +357 -0
  34. package/lib/dispatcher/schemas.mjs +1 -0
  35. package/lib/dispatcher/snapshot.mjs +76 -1
  36. package/lib/dispatcher/store.mjs +15 -0
  37. package/lib/dispatcher/verifier.mjs +246 -0
  38. package/lib/docker-janitor.mjs +24 -14
  39. package/lib/git-guard.mjs +181 -0
  40. package/lib/integrate.mjs +10 -2
  41. package/lib/store-contract.mjs +63 -0
  42. package/lib/store-pg.mjs +38 -3
  43. package/mcp.mjs +4 -5
  44. package/package.json +3 -3
package/lib/store-pg.mjs CHANGED
@@ -1,6 +1,8 @@
1
1
  // trantor Phase 1 Postgres store: implements the frozen STORE_API from ./store-contract.mjs as the durable
2
2
  // backing when RELAY_STORE=pg. SAFETY: the typeof checks here decode untrusted jsonb rows at the boundary.
3
3
  /* oxlint-disable anti-slop/no-runtime-typeof */
4
+ import { createDispatcherStore } from "./dispatcher/store.mjs";
5
+ import { setTimeout as delay } from "node:timers/promises";
4
6
  import { SCHEMA_SQL, SCHEMA_VERSION, KV_KEYS, DEFAULT_ORG, CHANGE_CHANNEL } from "./store-contract.mjs";
5
7
 
6
8
  const TURNS_SCHEMA_SQL = `
@@ -104,7 +106,7 @@ export function taskExtra(t = {}) {
104
106
  return extra;
105
107
  }
106
108
 
107
- function taskFromRow(row) {
109
+ export function taskFromRow(row) {
108
110
  const extra = row.extra && typeof row.extra === "object" ? row.extra : {};
109
111
  return {
110
112
  ...extra,
@@ -244,6 +246,34 @@ function diffById(prevArr, nextArr, idOf) {
244
246
  }
245
247
 
246
248
  export class PgStore {
249
+ // Retried callbacks must contain only database work; external effects belong after commit.
250
+ async transaction(fn, { isolation = "serializable" } = {}) {
251
+ if (!["serializable", "repeatable read", "read committed"].includes(isolation)) {
252
+ throw new RangeError("unsupported transaction isolation");
253
+ }
254
+ for (let attempt = 1; attempt <= 3; attempt++) {
255
+ const client = await this.pool.connect();
256
+ let discard;
257
+ try {
258
+ await client.query(`BEGIN ISOLATION LEVEL ${isolation.toUpperCase()}`);
259
+ const result = await fn(client);
260
+ await client.query("COMMIT");
261
+ return result;
262
+ } catch (error) {
263
+ try { await client.query("ROLLBACK"); }
264
+ catch (rollbackError) { discard = rollbackError; }
265
+ if (!["40001", "40P01"].includes(error.code) || attempt === 3) throw error;
266
+ } finally {
267
+ client.release(discard);
268
+ }
269
+ await delay((10 + Math.floor(Math.random() * 41)) * attempt);
270
+ }
271
+ }
272
+
273
+ createDispatcherStore() {
274
+ return createDispatcherStore({ pool: this.pool, transaction: this.transaction.bind(this) });
275
+ }
276
+
247
277
  constructor(options = {}) {
248
278
  this.url = options.url || process.env.RELAY_DATABASE_URL || process.env.DATABASE_URL || "";
249
279
  this.pool = options.pool || null;
@@ -371,7 +401,9 @@ export class PgStore {
371
401
  }
372
402
 
373
403
  async upsertTask(orgId, task) {
374
- await this.pool.query(
404
+ await this.transaction(async client => {
405
+ await client.query("SELECT pg_advisory_xact_lock(hashtextextended($1,0))", [`dispatcher:${orgId}`]);
406
+ await client.query(
375
407
  `INSERT INTO tasks(id, org_id, project, title, status, assignee, source, difficulty, model, phase, cost_usd, deps, history, created, updated, extra)
376
408
  VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12::jsonb,$13::jsonb,$14,$15,$16::jsonb)
377
409
  ON CONFLICT(org_id, id) DO UPDATE SET
@@ -386,7 +418,8 @@ export class PgStore {
386
418
  JSON.stringify(Array.isArray(task.history) ? task.history : []),
387
419
  ms(task.ts || task.created, 0), ms(task.updated || task.ts, 0), JSON.stringify(taskExtra(task)),
388
420
  ],
389
- );
421
+ );
422
+ });
390
423
  }
391
424
 
392
425
  async readTasks(orgId, filters = {}) {
@@ -530,6 +563,7 @@ export class PgStore {
530
563
  const c = await this.pool.connect();
531
564
  try {
532
565
  await c.query("BEGIN");
566
+ await c.query("SELECT pg_advisory_xact_lock(hashtextextended($1,0))", [`dispatcher:${orgId}`]);
533
567
  await c.query("DELETE FROM tasks WHERE org_id=$1", [orgId]);
534
568
  await c.query("DELETE FROM events WHERE org_id=$1", [orgId]);
535
569
  await c.query("DELETE FROM messages WHERE org_id=$1", [orgId]);
@@ -666,6 +700,7 @@ export class PgStore {
666
700
  const c = await this.pool.connect();
667
701
  try {
668
702
  await c.query("BEGIN");
703
+ await c.query("SELECT pg_advisory_xact_lock(hashtextextended($1,0))", [`dispatcher:${orgId}`]);
669
704
  for (const raw of tasks.upserts) {
670
705
  const t = stripNulDeep(raw);
671
706
  await c.query(
package/mcp.mjs CHANGED
@@ -9,7 +9,7 @@ import { homedir, hostname } from "node:os";
9
9
  import { execSync, spawnSync } from "node:child_process";
10
10
  import { randomUUID } from "node:crypto";
11
11
  import { advise, loadWorld } from "./bin/advise.mjs";
12
- import { buildAdviceRequest, dispatchDecision, packagesToDrafts, parseCards, preflight, readCachedAdvice, readCapacity, requestAdvice } from "./lib/dispatcher/preflight.mjs";
12
+ import { adviseCards, buildAdviceRequest, dispatchDecision, packagesToDrafts, parseCards, preflight, readCachedAdvice, readCapacity, requestAdvice } from "./lib/dispatcher/preflight.mjs";
13
13
  import { loadRegistry } from "./lib/canary/registry.mjs";
14
14
  import { loadSeatRecord } from "./lib/seat-record.mjs";
15
15
  import { resolveProject, hostId, resolveHubInfo, nonSeatReason, handoffDir, orchWriterSid, busDir } from "./lib/project.mjs";
@@ -330,17 +330,16 @@ server.tool("relay_project_brief", "Set a one-paragraph project brief shown on t
330
330
  const dispatcherCards = z.array(z.record(z.string(), z.any()));
331
331
  const hubPost = (path, body) => signedPost(path, body, { session: SESSION, instance: INSTANCE_ID, project: PROJECT, timeoutMs: 10000 });
332
332
  const hubGet = (path) => signedGet(path, { session: SESSION, instance: INSTANCE_ID, project: PROJECT, timeoutMs: 5000 });
333
- server.tool("relay_advise", "Ask how to execute work before spending tokens. With cards (dispatcher work cards) it returns the hub planner's decision, the same one `trantor advise --json` gives; with the old task+packages shape it returns the legacy recommendation plus the hub's draft decision. Present the summary to the user before starting.",
333
+ server.tool("relay_advise", "Ask how to execute work before spending tokens. With cards (card numbers) it fetches each card's current WorkCard from the hub and returns the hub planner's decision, the same one `trantor advise --json` gives; with the old task+packages shape it returns the legacy recommendation plus the hub's draft decision. Present the summary to the user before starting.",
334
334
  { task: z.string().optional(),
335
335
  packages: z.array(z.object({ title: z.string(), difficulty: z.enum(["easy","medium","hard"]).optional(), kind: z.string().optional() })).optional(),
336
336
  horizon: z.enum(["short","medium","long"]).optional(),
337
- cards: dispatcherCards.optional().describe("work cards to plan (dispatchable)"),
337
+ cards: z.array(z.union([z.number().int().positive(), z.record(z.string(), z.any())])).optional().describe("card numbers to plan (dispatchable); the hub's current WorkCard is fetched for each"),
338
338
  drafts: dispatcherCards.optional().describe("unsaved cards with client-local ids (advice only)"),
339
339
  snapshotId: z.string().optional(), policyVersion: z.string().optional() },
340
340
  async ({ task, packages, horizon, cards, drafts, snapshotId, policyVersion }) => {
341
341
  if (cards || drafts) {
342
- const request = await buildAdviceRequest({ project: PROJECT, cards: cards || [], drafts: drafts || [], snapshotId, policyVersion });
343
- const result = await requestAdvice({ post: hubPost, busDir: busDir(), request });
342
+ const result = await adviseCards({ get: hubGet, post: hubPost, busDir: busDir(), project: PROJECT, cards: cards || [], drafts: drafts || [], snapshotId, policyVersion });
344
343
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], isError: result.source === "refused" };
345
344
  }
346
345
  // #7762: the advisor reads THIS project's seat record (derived, fail-open) so a seat whose
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trantor",
3
- "version": "0.18.148",
3
+ "version": "0.18.152",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "trantor": "bin/cli.mjs"
@@ -60,7 +60,7 @@
60
60
  "node": ">=18"
61
61
  },
62
62
  "devDependencies": {
63
- "@oxlint/plugins": "^1.79.0",
64
- "oxlint": "^1.79.0"
63
+ "@oxlint/plugins": "1.79.0",
64
+ "oxlint": "1.79.0"
65
65
  }
66
66
  }