trantor 0.18.124 → 0.18.126
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/.claude-plugin/plugin.json +1 -1
- package/bin/crew-runner.mjs +43 -7
- package/bin/relay-watch.mjs +3 -7
- package/bin/sync.mjs +7 -5
- package/hooks/heartbeat.mjs +3 -0
- package/hooks/sessionstart.mjs +3 -0
- package/hub/events.mjs +3 -1
- package/hub/routes/admin.mjs +2 -2
- package/lib/harvest.mjs +3 -1
- package/lib/machine-label.mjs +6 -0
- package/lib/seat-worktree.mjs +23 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trantor",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.126",
|
|
4
4
|
"description": "Trantor — the hub-world for AI agent crews: live message bus, presence, project Kanban/flow board + crew orchestration for independent AI coding agents (Claude, Codex, Gemini, Kimi, DeepSeek)",
|
|
5
5
|
"mcpServers": {
|
|
6
6
|
"relay": {
|
package/bin/crew-runner.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import { readFileSync, writeFileSync, unlinkSync, existsSync, appendFileSync, mk
|
|
|
6
6
|
import { join, basename } from "node:path";
|
|
7
7
|
import { homedir } from "node:os";
|
|
8
8
|
import { resolveProject, resolveHub, withEnvFiles, hostId } from "../lib/project.mjs";
|
|
9
|
+
import { machineLabel } from "../lib/machine-label.mjs";
|
|
9
10
|
import { resolveSecrets, shadowEnv, withSecretExports } from "../lib/secrets.mjs";
|
|
10
11
|
import { runnerPersona } from "../lib/persona.mjs";
|
|
11
12
|
import { loadOrCreate } from "../lib/identity.mjs";
|
|
@@ -13,7 +14,7 @@ import { signedHeaders } from "../lib/signed-fetch.mjs";
|
|
|
13
14
|
import { ensureEnrolled } from "../lib/enroll.mjs";
|
|
14
15
|
import { redactKeys } from "../lib/redact.mjs";
|
|
15
16
|
import { writeTurnState } from "../lib/turnstate.mjs";
|
|
16
|
-
import { applyWorktreeDeclaration, ensureSeatWorktree, provisioningLines, readWorktreeDeclaration } from "../lib/seat-worktree.mjs";
|
|
17
|
+
import { alignSeatWorktree, applyWorktreeDeclaration, ensureSeatWorktree, provisioningLines, readWorktreeDeclaration } from "../lib/seat-worktree.mjs";
|
|
17
18
|
import {
|
|
18
19
|
AUTH_MARKER_RE, classifyFailure, looksLikeAuthDeath,
|
|
19
20
|
verdictFor, substantiveOutput, stallVerdict, cutSignalFor,
|
|
@@ -91,6 +92,9 @@ const DIR = process.argv[3] || process.cwd();
|
|
|
91
92
|
// back to the git-repo-root basename — never a loose dir basename that could
|
|
92
93
|
// fork the host's "builtbetter.ai" into a separate "builtbetter" lane.
|
|
93
94
|
const PROJ = process.env.RELAY_PROJECT || resolveProject(DIR);
|
|
95
|
+
let machineConfig = {};
|
|
96
|
+
try { machineConfig = JSON.parse(readFileSync(join(process.env.AGENT_BUS_DIR || process.env.RELAY_DATA_DIR || join(homedir(), ".agent-bus"), "config.json"), "utf8")); } catch {}
|
|
97
|
+
const MACHINE_LABEL = machineLabel(machineConfig);
|
|
94
98
|
|
|
95
99
|
function gitOut(args, cwd = DIR) {
|
|
96
100
|
const r = spawnSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: 8000 });
|
|
@@ -114,9 +118,12 @@ function seatWorktree(sourceDir) {
|
|
|
114
118
|
|
|
115
119
|
const TURN_DIR = seatWorktree(DIR);
|
|
116
120
|
|
|
117
|
-
// #
|
|
118
|
-
//
|
|
119
|
-
const
|
|
121
|
+
// #13921: an explicit contract base wins; without one, fetch the current origin/main instead of
|
|
122
|
+
// trusting a cached local ref from when this seat worktree was created.
|
|
123
|
+
const originMainHead = () => {
|
|
124
|
+
spawnSync("git", ["fetch", "-q", "origin", "+refs/heads/main:refs/remotes/origin/main"], { cwd: TURN_DIR, stdio: "ignore", timeout: 20000 });
|
|
125
|
+
return gitOut(["rev-parse", "--verify", "--quiet", "refs/remotes/origin/main^{commit}"], TURN_DIR);
|
|
126
|
+
};
|
|
120
127
|
const resolvesHere = (sha) =>
|
|
121
128
|
spawnSync("git", ["cat-file", "-e", `${sha}^{commit}`], { cwd: TURN_DIR, stdio: "ignore", timeout: 8000 }).status === 0;
|
|
122
129
|
|
|
@@ -183,8 +190,13 @@ const banner = (trigger) => {
|
|
|
183
190
|
};
|
|
184
191
|
|
|
185
192
|
async function api(path, body) {
|
|
193
|
+
let payload;
|
|
194
|
+
if (body) {
|
|
195
|
+
payload = { ...body };
|
|
196
|
+
if (path === "/register" && MACHINE_LABEL) payload.machine = MACHINE_LABEL;
|
|
197
|
+
}
|
|
186
198
|
const opts = body
|
|
187
|
-
? { method: "POST", headers: { "content-type": "application/json", connection: "close" }, body: JSON.stringify(
|
|
199
|
+
? { method: "POST", headers: { "content-type": "application/json", connection: "close" }, body: JSON.stringify(payload) }
|
|
188
200
|
: { headers: { connection: "close" } }; // fresh socket per call — long-polls on stale keep-alive sockets reset
|
|
189
201
|
// Sign as THIS seat. Unsigned calls are 401 on an enforce hub, and because the runner fails open
|
|
190
202
|
// that shows up as a seat that quietly records nothing rather than one that errors.
|
|
@@ -602,7 +614,9 @@ async function balanceRows() {
|
|
|
602
614
|
// #7749: the live phase + its start ride the same call, so /peers answers what the seat does NOW.
|
|
603
615
|
async function registerStatus(status, extra = {}) {
|
|
604
616
|
const url = HUB + "/register";
|
|
605
|
-
const
|
|
617
|
+
const payload = { session: SESSION, project: PROJ, status, persona: PERSONA, agent: AGENT, llm: AGENT, model: MODEL, ...extra };
|
|
618
|
+
if (MACHINE_LABEL) payload.machine = MACHINE_LABEL;
|
|
619
|
+
const body = JSON.stringify(payload);
|
|
606
620
|
try {
|
|
607
621
|
const opts = { method: "POST", headers: { "content-type": "application/json", connection: "close" }, body };
|
|
608
622
|
await fetch(url, { ...opts, headers: { ...opts.headers, ...signedHeaders(identity, url, opts) }, signal: AbortSignal.timeout(5000) });
|
|
@@ -1505,6 +1519,11 @@ async function resolveWakeCard(messages, { session }) {
|
|
|
1505
1519
|
signal: AbortSignal.timeout(2500),
|
|
1506
1520
|
});
|
|
1507
1521
|
} catch {}
|
|
1522
|
+
if (releaseState) {
|
|
1523
|
+
const since = Date.now();
|
|
1524
|
+
writeTurnState(PERSONA, PROJ, { phase: "idle", since });
|
|
1525
|
+
await registerStatus("idle", { phase: "idle", phaseSince: since });
|
|
1526
|
+
}
|
|
1508
1527
|
|
|
1509
1528
|
// Wake messages this seat has PULLED off the bus but not yet worked successfully, plus the
|
|
1510
1529
|
// broadcasts batched behind them. Restored from disk first: a runner that was killed mid-turn
|
|
@@ -1862,7 +1881,8 @@ async function resolveWakeCard(messages, { session }) {
|
|
|
1862
1881
|
// served contract cites: #7763's rebinding covers confirmed message-card ids only, never a
|
|
1863
1882
|
// card cited in the text, so the unresolvable-base branch blocks the cited card.
|
|
1864
1883
|
const baseCard = card || servedContractCard(wakeForTurn, { session: SESSION });
|
|
1865
|
-
const
|
|
1884
|
+
const statedBase = contractBase(wakeForTurn);
|
|
1885
|
+
const base = statedBase || originMainHead();
|
|
1866
1886
|
if (base && baseCard && !resolvesHere(base)) {
|
|
1867
1887
|
const text = `cannot resolve base ${base} in ${TURN_DIR} (git cat-file -e failed) — #${baseCard} moved to blocked; push or fetch that sha, or name one this worktree can reach`;
|
|
1868
1888
|
log(text);
|
|
@@ -1874,6 +1894,21 @@ async function resolveWakeCard(messages, { session }) {
|
|
|
1874
1894
|
savePending([], pendingBcast);
|
|
1875
1895
|
return;
|
|
1876
1896
|
}
|
|
1897
|
+
if (base && TURN_DIR !== DIR && card && gitOut(["rev-parse", "--abbrev-ref", "HEAD"], TURN_DIR) === `seat/${PERSONA}`) {
|
|
1898
|
+
const aligned = alignSeatWorktree({ dir: TURN_DIR, project: PROJ, agent: PERSONA, base });
|
|
1899
|
+
if (!aligned.ok) {
|
|
1900
|
+
const text = `cannot align seat worktree for #${card}: ${aligned.reason}`;
|
|
1901
|
+
log(text);
|
|
1902
|
+
await api("/task/update", { id: card, status: "blocked", note: text, by: SESSION }).catch(() => {});
|
|
1903
|
+
const owed = assigners.map(a => a.from).filter(f => f && f !== SESSION);
|
|
1904
|
+
for (const to of (owed.length ? owed : ["all"]))
|
|
1905
|
+
await api("/send", { from: SESSION, to, text, project: PROJ, kind: "alert" }).catch(() => {});
|
|
1906
|
+
pendingWake = [];
|
|
1907
|
+
savePending([], pendingBcast);
|
|
1908
|
+
return;
|
|
1909
|
+
}
|
|
1910
|
+
if (aligned.parked) log(`preserved unharvested work at ${aligned.parked} before aligning to ${base}`);
|
|
1911
|
+
}
|
|
1877
1912
|
const baseText = base ? `\n${baseLine(base)}\n` : "";
|
|
1878
1913
|
// #6289: the session SHAPE (fresh vs resume) reads the served contract's raw citation — a wake
|
|
1879
1914
|
// whose card the board lacks still opens fresh, never a bare resume of the kickoff's CLI.
|
|
@@ -1888,6 +1923,7 @@ async function resolveWakeCard(messages, { session }) {
|
|
|
1888
1923
|
// (and resets the counter with the fresh session below); the paused card itself never buys
|
|
1889
1924
|
// another CLI session. The wake stays owed and retries on a long clock, so the orchestrator
|
|
1890
1925
|
// sees the pause, not a silent seat.
|
|
1926
|
+
|
|
1891
1927
|
// #13474: never run a metered provider under a subscription label (or any model off its label).
|
|
1892
1928
|
// A `trantor swap` (CREW_SWAP_DRIVER) is the operator choosing another provider on purpose.
|
|
1893
1929
|
const mismatch = process.env.CREW_SWAP_DRIVER ? null : providerMismatch(AGENT, MODEL);
|
package/bin/relay-watch.mjs
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// relay-watch
|
|
3
|
-
//
|
|
4
|
-
// node bin/relay-watch.mjs [session] (default: "all" — see every message)
|
|
5
|
-
// Signed + per-project hub (2026-07-31, agent-UX audit): the hand-rolled relayUrl() here read
|
|
6
|
-
// only the global config `url` (wrong hub for a migrated project) and fetched unsigned (dead
|
|
7
|
-
// 401 under RELAY_AUTH=enforce). Now: canonical resolver + this session's keypair on every call.
|
|
2
|
+
// relay-watch streams the bus and lists live peer status.
|
|
3
|
+
// Run `node bin/relay-watch.mjs [session]`; the default watches every session.
|
|
8
4
|
import { resolveProject, hostId, resolveHub } from "../lib/project.mjs";
|
|
9
5
|
import { loadOrCreate } from "../lib/identity.mjs";
|
|
10
6
|
import { sfetch, sfetchJson } from "../lib/signed-fetch.mjs";
|
|
@@ -22,7 +18,7 @@ async function showPeers() {
|
|
|
22
18
|
const { peers } = await (await sfetchJson(`${URL_BASE}/peers`, { method: "GET", identity })).json();
|
|
23
19
|
const live = peers.filter(p => p.online);
|
|
24
20
|
console.log(`\n live sessions (${live.length}):`);
|
|
25
|
-
for (const p of live) console.log(` 🟢 ${p.session}${p.status ? ` — ${p.status}` : ""}`);
|
|
21
|
+
for (const p of live) console.log(` 🟢 ${p.session}${p.machine ? ` [${p.machine}]` : ""}${p.status ? ` — ${p.status}` : ""}`);
|
|
26
22
|
console.log("");
|
|
27
23
|
} catch {}
|
|
28
24
|
}
|
package/bin/sync.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// `trantor sync [<seat>]` (#7748): realign a seat branch with main from the harvest receipts.
|
|
3
|
-
//
|
|
3
|
+
// Commits absent from main must have a receipt or an equivalent patch on main; otherwise sync refuses.
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { resolveProject, busDir } from "../lib/project.mjs";
|
|
@@ -27,15 +27,17 @@ const short = (s) => String(s || "").slice(0, 7);
|
|
|
27
27
|
if (r.refused) {
|
|
28
28
|
console.log(`${RED}sync refused${R} · ${r.branch} carries ${r.unharvested.length} commit(s) ${r.target.ref} does not, with no harvest receipt:`);
|
|
29
29
|
for (const c of r.unharvested) console.log(` ${short(c.sha)} ${c.subject}`);
|
|
30
|
-
if (r.harvested.length) console.log(`${D}${r.harvested.length} other commit(s) are
|
|
30
|
+
if (r.harvested.length) console.log(`${D}${r.harvested.length} other commit(s) are already harvested and would be dropped once these are.${R}`);
|
|
31
31
|
console.log(`${D}Harvest them (trantor harvest <seat-sha> <main-sha> --card N) or park them on another branch first. Receipts: ${receiptsPath(project)}${R}`);
|
|
32
32
|
process.exit(1);
|
|
33
33
|
}
|
|
34
34
|
if (!r.ok) { console.error(`${RED}sync failed${R}: ${r.reason}`); process.exit(1); }
|
|
35
35
|
if (r.noop) { console.log(`${D}${r.branch} already at ${r.target.ref} (${short(r.head)})${R}`); process.exit(0); }
|
|
36
|
-
const dropped = r.harvested.map(c =>
|
|
36
|
+
const dropped = r.harvested.map(c => c.receipt
|
|
37
|
+
? `${short(c.sha)}→${short(c.receipt.main)}`
|
|
38
|
+
: `${short(c.sha)} (patch already in target)`).join(", ");
|
|
37
39
|
if (r.dry) {
|
|
38
|
-
console.log(`${Y}[dry]${R} would move ${r.branch} ${short(r.head)} → ${r.target.ref} ${short(r.target.sha)}${dropped ? ` ${D}(
|
|
40
|
+
console.log(`${Y}[dry]${R} would move ${r.branch} ${short(r.head)} → ${r.target.ref} ${short(r.target.sha)}${dropped ? ` ${D}(harvested: ${dropped})${R}` : ""}`);
|
|
39
41
|
process.exit(0);
|
|
40
42
|
}
|
|
41
|
-
console.log(`${G}synced${R} ${r.branch} ${short(r.from)} → ${r.target.ref} ${short(r.to)}${dropped ? ` ${D}(
|
|
43
|
+
console.log(`${G}synced${R} ${r.branch} ${short(r.from)} → ${r.target.ref} ${short(r.to)}${dropped ? ` ${D}(harvested: ${dropped})${R}` : ""}`);
|
package/hooks/heartbeat.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import { armBaton, readArm, clearArm, readConfig, contextUsage, warnFrac, alread
|
|
|
12
12
|
import { resolveProject, hostId } from "../lib/project.mjs";
|
|
13
13
|
import { installedVersion } from "./lib/update-check.mjs"; // report our hook version so the hub can flag stale sessions
|
|
14
14
|
import { signedPost } from "./lib/api.mjs";
|
|
15
|
+
import { machineLabel } from "../lib/machine-label.mjs";
|
|
15
16
|
import { gitCheckoutRoot } from "./lib/git-checkout.mjs";
|
|
16
17
|
|
|
17
18
|
const HEARTBEAT_MS = Number(process.env.RELAY_HEARTBEAT_MS || 60 * 1000);
|
|
@@ -166,6 +167,8 @@ async function main(stdinRaw) {
|
|
|
166
167
|
llm: process.env.RELAY_LLM || (process.env.RELAY_AGENT ? process.env.RELAY_AGENT.replace(/-orch$/, "") : "claude"),
|
|
167
168
|
model: modelFromTranscript(stdinRaw),
|
|
168
169
|
hookVersion: (() => { try { return installedVersion(); } catch { return ""; } })() };
|
|
170
|
+
const machine = machineLabel(readConfig());
|
|
171
|
+
if (machine) beatBody.machine = machine;
|
|
169
172
|
if (beatKind) beatBody.kind = beatKind;
|
|
170
173
|
await signedPost("/register", beatBody, { session, timeoutMs: Number(process.env.RELAY_HEARTBEAT_TIMEOUT_MS || 1500) });
|
|
171
174
|
|
package/hooks/sessionstart.mjs
CHANGED
|
@@ -19,6 +19,7 @@ import { ledgerPaths, ensureStart, anchorCursor, writeCursor } from "./lib/inbox
|
|
|
19
19
|
import { ensureEnrolled } from "../lib/enroll.mjs";
|
|
20
20
|
import { memoryStartLine } from "./lib/memory-start.mjs";
|
|
21
21
|
import { staleResumeLine } from "./lib/cc-signals.mjs";
|
|
22
|
+
import { machineLabel } from "../lib/machine-label.mjs";
|
|
22
23
|
|
|
23
24
|
// The build doctrine (docs/BUILD-DOCTRINE.md) in short form, one line per rule, injected for every
|
|
24
25
|
// project's ORCHESTRATOR at boot (#6452): orchestrators that never opened the doc missed the ruling.
|
|
@@ -194,6 +195,8 @@ try {
|
|
|
194
195
|
// (#6075): strict match badge === project, since a badge of "1" carries no name. Absent kind is preserved by /register.
|
|
195
196
|
const orchBadge = process.env.TRANTOR_ORCH || "";
|
|
196
197
|
const registerBody = { session, project, status: `active in ${project}` };
|
|
198
|
+
const machine = machineLabel(readConfig());
|
|
199
|
+
if (machine) registerBody.machine = machine;
|
|
197
200
|
if (orchBadge === project) registerBody.kind = "orch";
|
|
198
201
|
await jpost(`${url}/register`, registerBody, session).catch(() => {});
|
|
199
202
|
|
package/hub/events.mjs
CHANGED
|
@@ -23,13 +23,15 @@ function applyPeerAuth(p, auth) {
|
|
|
23
23
|
p.authWarning = auth.warning;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
function touch(session, status, project, hookVersion, auth) {
|
|
26
|
+
function touch(session, status, project, hookVersion, auth, machine) {
|
|
27
27
|
if (!session || session === "all") return; // "all" is a wildcard, not a real peer
|
|
28
28
|
const p = state.peers[session] || { lastSeen: 0, status: "", project: "" };
|
|
29
29
|
// Peers carry no terminal address: /send is unauthenticated and `from` is self-asserted, so one
|
|
30
30
|
// would turn any local process into arbitrary keystrokes. Messages reach agents only through
|
|
31
31
|
// channels their own harness controls (hooks/inbox-deliver.mjs and hooks/stop-inbox.mjs).
|
|
32
32
|
delete p.tty; delete p.windowId; delete p.host;
|
|
33
|
+
// Keep only an operator-chosen short label. Never retain the full host field.
|
|
34
|
+
if (typeof machine === "string" && /^[a-z0-9-]{1,24}$/.test(machine)) p.machine = machine;
|
|
33
35
|
const wasOnline = p._on === true; // explicit flag, so the log gets ONE event per transition
|
|
34
36
|
p.lastSeen = now();
|
|
35
37
|
if (status !== undefined) p.status = String(status).slice(0, 280);
|
package/hub/routes/admin.mjs
CHANGED
|
@@ -54,7 +54,7 @@ export async function routeAdmin({ req, res, q, P, auth, ctx }) {
|
|
|
54
54
|
const b = await body(req);
|
|
55
55
|
const cpg = crossProjectGuard(auth, P, b);
|
|
56
56
|
if (!cpg.ok) return json(res, cpg.code, { error: cpg.error });
|
|
57
|
-
touch(b.session, b.status, b.project, b.hookVersion, auth);
|
|
57
|
+
touch(b.session, b.status, b.project, b.hookVersion, auth, b.machine);
|
|
58
58
|
// WHO is this, really: the LLM brand + the exact model currently loaded. In-memory like the
|
|
59
59
|
// rest of presence — the next heartbeat re-supplies it after a restart.
|
|
60
60
|
const pr = state.peers[b.session];
|
|
@@ -391,7 +391,7 @@ export async function routeAdmin({ req, res, q, P, auth, ctx }) {
|
|
|
391
391
|
return json(res, 200, { hubVersion: HUB_VERSION, authMode: AUTH_MODE, peers: peerRows.map(([s, v]) => ({ session: s, lastSeen: v.lastSeen, online: v.lastSeen > cutoff, status: v.status || "", health: healthOf(v.status), project: v.project || "", phase: v.phase || "", phaseSince: v.phaseSince || 0,
|
|
392
392
|
pubkey: v.pubkey || "", identity: v.identity || null, authWarning: v.authWarning || "",
|
|
393
393
|
kind: peerKindOf(v), // #8723 bounce-3: same resolver declaredCrewFor reads — never a roster-only answer
|
|
394
|
-
llm: v.llm || "", model: v.model || "", hookVersion: v.hookVersion || "", staleHooks: !!(v.lastSeen > cutoff && v.hookVersion && HUB_VERSION && cmpSemver(v.hookVersion, HUB_VERSION) < 0) })) });
|
|
394
|
+
llm: v.llm || "", model: v.model || "", machine: v.machine || undefined, hookVersion: v.hookVersion || "", staleHooks: !!(v.lastSeen > cutoff && v.hookVersion && HUB_VERSION && cmpSemver(v.hookVersion, HUB_VERSION) < 0) })) });
|
|
395
395
|
}
|
|
396
396
|
// --- Provider balances (prepaid credit) ---
|
|
397
397
|
// The hub runs under launchd with no provider keys, so it can't fetch balances itself. Env-having
|
package/lib/harvest.mjs
CHANGED
|
@@ -64,12 +64,14 @@ export function syncTarget(dir, base) {
|
|
|
64
64
|
// Every commit the seat branch carries that the target does not, split by whether a receipt covers it.
|
|
65
65
|
export function auditSeat(dir, { branch, targetRef, receipts }) {
|
|
66
66
|
const log = out(dir, ["log", "--reverse", "--format=%H%x09%s", `${targetRef}..${branch}`]);
|
|
67
|
+
const cherry = out(dir, ["cherry", targetRef, branch]);
|
|
68
|
+
const equivalent = new Set(cherry.split("\n").filter(line => line.startsWith("- ")).map(line => line.slice(2).trim()));
|
|
67
69
|
const harvested = [], unharvested = [];
|
|
68
70
|
for (const line of log.split("\n").filter(Boolean)) {
|
|
69
71
|
const [sha, ...rest] = line.split("\t");
|
|
70
72
|
const subject = rest.join("\t");
|
|
71
73
|
const receipt = receipts.find(r => shaMatches(r.seat, sha));
|
|
72
|
-
(receipt ? harvested : unharvested).push({ sha, subject, receipt });
|
|
74
|
+
(receipt || equivalent.has(sha) ? harvested : unharvested).push({ sha, subject, receipt });
|
|
73
75
|
}
|
|
74
76
|
return { harvested, unharvested };
|
|
75
77
|
}
|
package/lib/seat-worktree.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from "node:fs";
|
|
7
7
|
import { homedir } from "node:os";
|
|
8
8
|
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
9
|
+
import { auditSeat, readReceipts } from "./harvest.mjs";
|
|
9
10
|
|
|
10
11
|
export const DECLARATION_PATH = join(".trantor", "worktree.json");
|
|
11
12
|
export const PREFLIGHT_CAP_MS = 5 * 60 * 1000;
|
|
@@ -24,6 +25,28 @@ function gitOut(args, cwd) {
|
|
|
24
25
|
return r.status === 0 ? String(r.stdout || "").trim() : "";
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
// Start a new contract from its pinned base only when the previous branch has no unharvested work.
|
|
29
|
+
// Refusing keeps the branch tip reachable and gives the orchestrator a clear reason to harvest it.
|
|
30
|
+
export function alignSeatWorktree({ dir, project, agent, base, receiptsRoot }) {
|
|
31
|
+
const branch = gitOut(["rev-parse", "--abbrev-ref", "HEAD"], dir);
|
|
32
|
+
const expected = `seat/${agent}`;
|
|
33
|
+
if (branch !== expected) return { ok: false, reason: `refusing to align ${dir}: expected ${expected}, found ${branch || "detached HEAD"}` };
|
|
34
|
+
if (!/^[0-9a-f]{7,40}$/i.test(String(base || "")) ||
|
|
35
|
+
spawnSync("git", ["cat-file", "-e", `${base}^{commit}`], { cwd: dir, stdio: "ignore", timeout: 8000 }).status !== 0)
|
|
36
|
+
return { ok: false, reason: `base ${base || "(missing)"} is not a commit in ${dir}` };
|
|
37
|
+
if (gitOut(["status", "--porcelain"], dir)) return { ok: false, reason: `refusing to reset dirty seat worktree ${dir}` };
|
|
38
|
+
|
|
39
|
+
const receipts = readReceipts(project, receiptsRoot);
|
|
40
|
+
const audit = auditSeat(dir, { branch, targetRef: base, receipts });
|
|
41
|
+
if (audit.unharvested.length) {
|
|
42
|
+
const commits = audit.unharvested.map(c => `${c.sha.slice(0, 7)} (${c.subject})`).join(", ");
|
|
43
|
+
return { ok: false, reason: `refusing to move ${branch}: ${audit.unharvested.length} unharvested commit(s) would be lost: ${commits}` };
|
|
44
|
+
}
|
|
45
|
+
const reset = spawnSync("git", ["reset", "--hard", base], { cwd: dir, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: 15000 });
|
|
46
|
+
if (reset.status !== 0) return { ok: false, reason: `could not align to ${base}: ${String(reset.stderr || reset.stdout || "git reset failed").trim()}` };
|
|
47
|
+
return { ok: true, to: gitOut(["rev-parse", "HEAD"], dir), parked: "" };
|
|
48
|
+
}
|
|
49
|
+
|
|
27
50
|
// Returns { dir, created }: dir is the seat worktree, or sourceDir when no worktree applies
|
|
28
51
|
// (non-git source, opt-out, or a creation failure — loud, never fatal: stale beats broken).
|
|
29
52
|
export function ensureSeatWorktree({ sourceDir, project, agent, home = homedir(), env = process.env, log = console.log }) {
|