trantor 0.18.128 → 0.18.130
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/README.md +15 -1
- package/bin/cargo-gate.mjs +19 -0
- package/bin/cli.mjs +2 -0
- package/bin/crew/herdr.mjs +30 -8
- package/bin/crew-runner.mjs +78 -35
- package/bin/desktop-build-gate.mjs +35 -0
- package/bin/doctor.mjs +15 -0
- package/bin/heavy-gate-shim/cargo +2 -0
- package/bin/heavy-gate-shim/npx +2 -0
- package/bin/heavy-gate-shim/pnpm +2 -0
- package/bin/heavy-gate.mjs +4 -0
- package/bin/install-axe.sh +24 -0
- package/bin/package-runner-gate.mjs +19 -0
- package/bin/sim.mjs +235 -0
- package/bin/turn-watchdog.mjs +15 -6
- package/lib/heavy-gate-wait.mjs +28 -0
- package/lib/heavy-gate.mjs +139 -0
- package/lib/seat-worktree.mjs +23 -7
- package/lib/sim/axe-status.mjs +10 -0
- package/lib/tauri-version-parity.mjs +59 -0
- package/package.json +1 -1
- package/skills/sim/SKILL.md +54 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trantor",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.130",
|
|
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/README.md
CHANGED
|
@@ -417,7 +417,7 @@ rate, not work rate.
|
|
|
417
417
|
```
|
|
418
418
|
trantor setup | doctor | connect | profile | provider | models
|
|
419
419
|
| new <name> | up <agents…> | swap <old> <new> | down | seat-why <agent> | ui | advise | hub | watch
|
|
420
|
-
| adopt <project> | reconcile | duty | orchestrate | patrol | app | backfill | init-hooks | pair
|
|
420
|
+
| adopt <project> | reconcile | duty | orchestrate | patrol | app | backfill | init-hooks | pair | sim
|
|
421
421
|
```
|
|
422
422
|
|
|
423
423
|
- **`trantor pair`** pairs the iPhone and iPad companion app (`ios/`, an operator console for
|
|
@@ -427,6 +427,15 @@ trantor setup | doctor | connect | profile | provider | models
|
|
|
427
427
|
scripts, and `--role owner` widens the scope. The desktop app's Settings shows the same invite
|
|
428
428
|
as a QR code. It signs as the operator's owner identity (`TRANTOR_IDENTITY`, default `owner@laptop`).
|
|
429
429
|
|
|
430
|
+
- **`trantor sim`** drives the iOS Simulator on a Mac for agents, through
|
|
431
|
+
[AXe](https://github.com/cameroncooke/AXe) (pinned v2.1.1, installed with
|
|
432
|
+
`bash bin/install-axe.sh`, which checks its SHA-256): `boot <device>`, `install <app>`,
|
|
433
|
+
`launch <bundle>`, `screen` (screenshot plus the accessibility tree in point coordinates),
|
|
434
|
+
`tap --label | --id | --xy`, `swipe`, `type`, `shutdown`. Every verb prints JSON. It refuses to
|
|
435
|
+
boot over another session's simulator and shuts down only its own. The `sim` skill gives agents
|
|
436
|
+
the drill loop; the XCTest drills in `ios/` stay the regression gate. `trantor doctor` reports
|
|
437
|
+
the AXe pin.
|
|
438
|
+
|
|
430
439
|
- **`trantor new <name>`** — project genesis in one command: makes the dir under your dev root
|
|
431
440
|
(`TRANTOR_DEV_ROOT` or `~/development`), git on main (or `--from <git-url>`, or `--adopt` an
|
|
432
441
|
existing folder), installs the auto-card hook, posts the brief to the hub, and opens the first
|
|
@@ -521,6 +530,11 @@ npm test # unit + 120+ protocol-level scenario drills + capability-routing, a
|
|
|
521
530
|
# difficulty-aware model selection, deps validation, virgin-machine doctor, failure drills
|
|
522
531
|
```
|
|
523
532
|
|
|
533
|
+
Heavy gates share one machine-wide semaphore: full suites, desktop Vitest, and Cargo test/build.
|
|
534
|
+
The default is `max(1, floor(cores / 4))` slots; set `"heavyGateSlots": 4` in
|
|
535
|
+
`~/.agent-bus/config.json` to override it. Crew runners wire Cargo and package-runner shims into
|
|
536
|
+
each seat. For a heavy command outside a runner, use `node bin/heavy-gate.mjs -- <command> …`.
|
|
537
|
+
|
|
524
538
|
## License
|
|
525
539
|
|
|
526
540
|
[MIT](./LICENSE) © 2026 Sasha Bogojevic · Built with [Claude Code](https://claude.com/claude-code) ·
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { constants } from "node:os";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
|
+
|
|
6
|
+
const args = process.argv.slice(2);
|
|
7
|
+
const shimDir = resolve(import.meta.dirname, "heavy-gate-shim");
|
|
8
|
+
const path = (process.env.PATH || "").split(":").filter(entry => resolve(entry) !== shimDir).join(":");
|
|
9
|
+
const env = { ...process.env, PATH: path };
|
|
10
|
+
const heavy = args.includes("test") || args.includes("build");
|
|
11
|
+
const result = heavy
|
|
12
|
+
? spawnSync(process.execPath, [join(import.meta.dirname, "heavy-gate.mjs"), "--", "cargo", ...args], { env, stdio: "inherit" })
|
|
13
|
+
: spawnSync("cargo", args, { env, stdio: "inherit" });
|
|
14
|
+
if (result.error) {
|
|
15
|
+
console.error(`cargo-gate: ${result.error.message}`);
|
|
16
|
+
process.exit(127);
|
|
17
|
+
}
|
|
18
|
+
if (result.signal) process.exit(128 + (constants.signals[result.signal] || 0));
|
|
19
|
+
process.exit(result.status ?? 1);
|
package/bin/cli.mjs
CHANGED
|
@@ -20,6 +20,7 @@ const runCrew = () => {
|
|
|
20
20
|
switch (cmd) {
|
|
21
21
|
case "setup": run("deploy/setup.sh", "/bin/bash"); break;
|
|
22
22
|
case "doctor": run("bin/doctor.mjs"); break;
|
|
23
|
+
case "sim": run("bin/sim.mjs"); break;
|
|
23
24
|
case "connect": run("bin/connect.mjs"); break;
|
|
24
25
|
case "profile": run("bin/profile.mjs"); break;
|
|
25
26
|
case "provider": case "providers": run("bin/provider.mjs"); break;
|
|
@@ -239,6 +240,7 @@ switch (cmd) {
|
|
|
239
240
|
|
|
240
241
|
trantor setup one-shot install: hub as an always-on service + config + CLI wiring + doctor
|
|
241
242
|
trantor doctor where do I stand? hub/plugin/CLIs/auth/keys/profile, with copy-paste fixes
|
|
243
|
+
trantor sim drive the owned iOS Simulator through AXe: boot|install|launch|screen|tap|swipe|type|shutdown
|
|
242
244
|
trantor connect (re)wire every installed AI CLI to the bus
|
|
243
245
|
trantor profile declare your plans: trantor profile set claude=max codex=plus deepseek=api
|
|
244
246
|
trantor provider bring ANY model (BYOM): list · status [--json] · verify <name> --key … · add <name> --key … · remove <name>
|
package/bin/crew/herdr.mjs
CHANGED
|
@@ -59,14 +59,36 @@ export function workspacePane(ctx, workspace, preferredCwd) {
|
|
|
59
59
|
return "";
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
// #13922: the herdr home(s) of the process RUNNING the crew CLI, when it itself sits in a pane —
|
|
63
|
+
// HERDR_WORKSPACE_ID names it, and a pane id embeds it (w2:p4Y lives in w2, #7247 forensics).
|
|
64
|
+
// Closing such a workspace kills this very shell and every sibling pane in it (the 11-20 netcup
|
|
65
|
+
// incident: one workspace.close from inside a seat's test run took the whole crew down).
|
|
66
|
+
function callerHerdrHomes(ctx) {
|
|
67
|
+
const env = ctx.env || {};
|
|
68
|
+
const pane = String(env.HERDR_PANE_ID || "").trim();
|
|
69
|
+
return new Set([String(env.HERDR_WORKSPACE_ID || "").trim(), pane ? pane.split(":")[0] : ""].filter(Boolean));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function refusal(what) {
|
|
73
|
+
console.error(` ✗ refusing to close herdr ${what}: it hosts this very process (own HERDR pane/workspace env). Close it from outside the crew, or set TRANTOR_CLOSE_OWN_WORKSPACE=1 to override.`);
|
|
74
|
+
}
|
|
75
|
+
|
|
62
76
|
export function closeWorkspace(ctx, id) {
|
|
63
|
-
if (ctx.
|
|
64
|
-
|
|
77
|
+
if (callerHerdrHomes(ctx).has(id) && String(ctx.env?.TRANTOR_CLOSE_OWN_WORKSPACE || "") !== "1") {
|
|
78
|
+
refusal(`workspace ${id}`);
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
if (ctx.dry) { console.log(`[dry] herdr workspace close ${id}`); return true; }
|
|
82
|
+
return herdrCall(ctx, ["workspace", "close", id]).ok;
|
|
65
83
|
}
|
|
66
84
|
|
|
67
85
|
export function closePane(ctx, id) {
|
|
68
|
-
if (ctx.
|
|
69
|
-
|
|
86
|
+
if (id && String(ctx.env?.HERDR_PANE_ID || "").trim() === id && String(ctx.env?.TRANTOR_CLOSE_OWN_WORKSPACE || "") !== "1") {
|
|
87
|
+
refusal(`pane ${id}`);
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
if (ctx.dry) { console.log(`[dry] herdr pane close ${id}`); return true; }
|
|
91
|
+
return herdrCall(ctx, ["pane", "close", id]).ok;
|
|
70
92
|
}
|
|
71
93
|
|
|
72
94
|
export function reportAgent(ctx, pane, agent) {
|
|
@@ -128,8 +150,8 @@ function prepareWorkspace(ctx, prune) {
|
|
|
128
150
|
// killed its own orchestrator that way. The row stays: the workspace is still live.
|
|
129
151
|
if (id === tracked.reuse || orchSpaces.has(id)) continue;
|
|
130
152
|
console.log(` → closing stale stacked crew workspace for ${ctx.project} (${id})`);
|
|
131
|
-
|
|
132
|
-
dropState(ctx, ctx.project, "herdrws", "", id);
|
|
153
|
+
// #13922: a refused close (the caller's own home) leaves the workspace live, so its row stays.
|
|
154
|
+
if (closeWorkspace(ctx, id)) dropState(ctx, ctx.project, "herdrws", "", id);
|
|
133
155
|
}
|
|
134
156
|
if (tracked.stale.length) prune();
|
|
135
157
|
if (ctx.dry) return tracked.reuse;
|
|
@@ -169,8 +191,8 @@ function replacementPane(ctx, workspace, spec, hostPane, resolve) {
|
|
|
169
191
|
runSeat(ctx, pane, (seat.persona || seat.agent), runnerCommand(ctx, seat.agent, seat.model, seat.effort, seat.persona));
|
|
170
192
|
}
|
|
171
193
|
if (old) {
|
|
172
|
-
|
|
173
|
-
dropState(ctx, ctx.project, "herdr", (seat.persona || seat.agent));
|
|
194
|
+
// #13922: a refused/failed close leaves the old pane live, so its row stays with it.
|
|
195
|
+
if (closePane(ctx, old)) dropState(ctx, ctx.project, "herdr", (seat.persona || seat.agent));
|
|
174
196
|
}
|
|
175
197
|
return { ...seat, pane };
|
|
176
198
|
}
|
package/bin/crew-runner.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// trantor crew runner — keeps a crew agent alive without burning tokens: it long-polls the bus
|
|
3
3
|
// (zero tokens) and resumes the CLI with each message. Usage: node crew-runner.mjs <agent> [dir]
|
|
4
4
|
import { execSync, spawnSync, spawn } from "node:child_process";
|
|
5
|
-
import { readFileSync, writeFileSync, unlinkSync, existsSync, appendFileSync, mkdirSync, realpathSync, statSync } from "node:fs";
|
|
5
|
+
import { readFileSync, writeFileSync, unlinkSync, existsSync, appendFileSync, mkdirSync, realpathSync, statSync, rmSync } from "node:fs";
|
|
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";
|
|
@@ -509,6 +509,21 @@ let parkAnnounced = false;
|
|
|
509
509
|
// #7914: the park this seat is currently sitting in, or null. Read by the poll loop, which ends a
|
|
510
510
|
// bounded one the moment somebody sends a direct message, and cleared by any turn that lands.
|
|
511
511
|
let parkState = null;
|
|
512
|
+
// #13949: unpark already told the room the episode ended, so the next reportHealthy must not echo
|
|
513
|
+
// a second "recovered" for the same landing. Consumed on every reportHealthy call, used or not.
|
|
514
|
+
let parkRecovered = false;
|
|
515
|
+
// #13949: is this park call the START of an episode or a retry inside a live one? A window-lift
|
|
516
|
+
// retry that parks AGAIN for the same reason never left the episode, and the room already holds
|
|
517
|
+
// its one notice — re-sending it every window is how one park became 10 identical DMs (#13949).
|
|
518
|
+
// Read BEFORE parkSeat, which overwrites parkState.
|
|
519
|
+
const sameParkEpisode = (reason) => !!(parkState && parkState.reason === reason);
|
|
520
|
+
// #13949: a park notice owes its reader the END of the wait, not only its cause — a bounded park
|
|
521
|
+
// names the resume clock (and the shortcut), a wall says it holds. Read after parkSeat sets it.
|
|
522
|
+
function parkLifts() {
|
|
523
|
+
return parkState?.bounded
|
|
524
|
+
? ` · resumes ${new Date(parkState.until).toLocaleTimeString()} (a direct message ends it now)`
|
|
525
|
+
: " — not retrying";
|
|
526
|
+
}
|
|
512
527
|
// #13474: uncommitted work in the seat worktree is saved on the seat branch when a turn is cut or
|
|
513
528
|
// the seat parks, so the next seat starts from it. One log line, only when something was saved.
|
|
514
529
|
function saveWipLogged(why) {
|
|
@@ -518,6 +533,7 @@ function saveWipLogged(why) {
|
|
|
518
533
|
}
|
|
519
534
|
|
|
520
535
|
async function parkSeat(reason, undelivered, resetHint = 0, { evidence = "", announce = true } = {}) {
|
|
536
|
+
const renewed = sameParkEpisode(reason); // #13949: a retry re-parking inside a live episode
|
|
521
537
|
saveWipLogged(`parked: ${reason}`);
|
|
522
538
|
// A seat that went QUIET printed no wall message to parse (#6131), so its own balance row is the
|
|
523
539
|
// only place the reset time exists. Output first when there is any: it is this turn's evidence.
|
|
@@ -547,8 +563,9 @@ async function parkSeat(reason, undelivered, resetHint = 0, { evidence = "", ann
|
|
|
547
563
|
}
|
|
548
564
|
log(`\x1b[31mparked (${reason})${when ? ` — retrying after ${when}` : " — no reset time in the output; waiting for a restart"}${evidence ? `\n evidence: ${evidence}` : ""}\x1b[0m`);
|
|
549
565
|
// The alarm for "the bus is stuck" cannot itself be a bus message, so a park also rings a bell
|
|
550
|
-
// the operator can hear out of band
|
|
551
|
-
|
|
566
|
+
// the operator can hear out of band — once per EPISODE (#13949): a window-lift retry that
|
|
567
|
+
// re-parks is the same silence continuing, not a new one starting.
|
|
568
|
+
if (!renewed) notifyOperator(`Trantor: ${SESSION} PARKED (${reason})`,
|
|
552
569
|
`${undelivered} message(s) held${when ? ` — retrying after ${when}` : ` — needs \`trantor up ${AGENT}\``}`);
|
|
553
570
|
// #7749: parked is a first-class phase — the file and the peer row both say so, so an
|
|
554
571
|
// orchestrator stops confusing a quota-held seat with a working or a dead one.
|
|
@@ -562,12 +579,21 @@ async function parkSeat(reason, undelivered, resetHint = 0, { evidence = "", ann
|
|
|
562
579
|
// #7914: the park is over — because a direct message asked for a turn now, or because one landed.
|
|
563
580
|
// The record goes with it, and the announce latch reopens so the NEXT park is heard too (a latch
|
|
564
581
|
// that never reopens turns a repeating park into one message and then silence).
|
|
565
|
-
|
|
582
|
+
// #13949: the END is an event too, once — one "recovered" each to the room and the orchestrator.
|
|
583
|
+
async function unpark(why) {
|
|
566
584
|
if (!parkState) return;
|
|
567
|
-
|
|
585
|
+
const { reason, ts } = parkState;
|
|
586
|
+
log(`\x1b[33mpark ended (${reason}) — ${why}\x1b[0m`);
|
|
568
587
|
parkState = null;
|
|
569
588
|
parkAnnounced = false;
|
|
570
589
|
try { unlinkSync(PARKF); } catch {}
|
|
590
|
+
const durMs = Date.now() - (Number(ts) || Date.now());
|
|
591
|
+
const dur = durMs >= 120_000 ? `${Math.round(durMs / 60_000)}m` : `${Math.max(1, Math.round(durMs / 1000))}s`;
|
|
592
|
+
const text = `✅ ${SESSION} recovered — ${reason} park over after ${dur} (${why})`;
|
|
593
|
+
await api("/send", { from: SESSION, to: "all", text, project: PROJ, kind: "status" }).catch(() => {});
|
|
594
|
+
const orch = `${hostId()}:${PROJ}`;
|
|
595
|
+
if (orch !== SESSION) await api("/send", { from: SESSION, to: orch, text, project: PROJ, kind: "alert" }).catch(() => {});
|
|
596
|
+
parkRecovered = true;
|
|
571
597
|
}
|
|
572
598
|
|
|
573
599
|
/**
|
|
@@ -672,13 +698,17 @@ async function busActivitySince(seq) {
|
|
|
672
698
|
}
|
|
673
699
|
|
|
674
700
|
async function reportHealthy() {
|
|
701
|
+
const saidParkRecovered = parkRecovered;
|
|
702
|
+
parkRecovered = false; // #13949: consumed whether used or not — never a stale skip
|
|
675
703
|
if (consecFails === 0) return; // already healthy — don't spam
|
|
676
704
|
consecFails = 0;
|
|
677
705
|
// Recovery is a change too, so the next failure is news again — a park included.
|
|
678
706
|
announced = "";
|
|
679
707
|
parkAnnounced = false;
|
|
680
708
|
await api("/register", { session: SESSION, project: PROJ, status: `active in ${PROJ}`, persona: PERSONA, agent: AGENT, llm: AGENT, model: MODEL, kind: "agent" }).catch(() => {});
|
|
681
|
-
|
|
709
|
+
// #13949: a landing that ended a park already said "recovered" once, with the reason and the
|
|
710
|
+
// duration — the ladder's echo would be the second recovery message for one event.
|
|
711
|
+
if (!saidParkRecovered) await api("/send", { from: SESSION, to: "all", text: `✅ ${SESSION} recovered`, project: PROJ, kind: "status" }).catch(() => {});
|
|
682
712
|
cmuxStatus("ok", "#14b8a6", "check"); herdrAgent("idle");
|
|
683
713
|
}
|
|
684
714
|
|
|
@@ -931,6 +961,8 @@ async function runTurn(prompt, isFirst, trigger = "kickoff", opts = {}) {
|
|
|
931
961
|
// ONE stall report, never a kill. #6206: floor 10 min, never derived from TRANTOR_TURN_MAX_MS.
|
|
932
962
|
const WD_MS = Number(process.env.TRANTOR_TURN_WATCHDOG_MS) || 10 * 60 * 1000;
|
|
933
963
|
const STAMPF = join(homedir(), ".agent-bus", `turnstamp-${PERSONA}-${PROJ}.json`);
|
|
964
|
+
const HEAVY_WAIT_DIR = join(homedir(), ".agent-bus", `heavy-gate-wait-${PERSONA}-${PROJ}`);
|
|
965
|
+
rmSync(HEAVY_WAIT_DIR, { recursive: true, force: true });
|
|
934
966
|
// #6206: the CLI's transcript dir (a missing dir is a quiet channel), exported so a drill's fake
|
|
935
967
|
// CLI can write lines the watchdog sees. CUTF is written by the shell's time box: cut, not crashed.
|
|
936
968
|
const CUTF = join(homedir(), ".agent-bus", `turncut-${PERSONA}-${PROJ}`);
|
|
@@ -946,7 +978,7 @@ async function runTurn(prompt, isFirst, trigger = "kickoff", opts = {}) {
|
|
|
946
978
|
const EXTF = join(homedir(), ".agent-bus", `turnext-${PERSONA}-${PROJ}`);
|
|
947
979
|
try { unlinkSync(DEADLINEF); } catch {}
|
|
948
980
|
try { unlinkSync(EXTF); } catch {}
|
|
949
|
-
const boxPlan =
|
|
981
|
+
const boxPlan = TURN_MAX_MS ? {
|
|
950
982
|
maxMs: TURN_MAX_MS, extendMs: TURN_EXTEND_MS, ceilingMs: TURN_CEILING_MS, extensionsMax: TURN_EXTENSIONS_MAX,
|
|
951
983
|
deadlineFile: DEADLINEF, extFile: EXTF, card: sessionCard || 0,
|
|
952
984
|
assigners: (opts.assigners || []).map(a => ({ from: a.from, id: a.id })),
|
|
@@ -970,7 +1002,7 @@ async function runTurn(prompt, isFirst, trigger = "kickoff", opts = {}) {
|
|
|
970
1002
|
// end the turn, so the watchdog stays report-only (reporting is the whole job, boxless).
|
|
971
1003
|
TURN_MAX_MS ? STALLF : "",
|
|
972
1004
|
// #7749: the turn-state file the watchdog refreshes mid-turn (lastBytesAt/lastTranscriptAt).
|
|
973
|
-
join(homedir(), ".agent-bus", `turnstate-${PERSONA}-${PROJ}.json`)],
|
|
1005
|
+
join(homedir(), ".agent-bus", `turnstate-${PERSONA}-${PROJ}.json`), HEAVY_WAIT_DIR],
|
|
974
1006
|
{ detached: true, stdio: "ignore" });
|
|
975
1007
|
WD_CHILD = wd;
|
|
976
1008
|
wd.unref();
|
|
@@ -1032,6 +1064,8 @@ exit $turn_exit`;
|
|
|
1032
1064
|
// A runner-managed seat must never hand itself a baton: the runner is its lifecycle manager,
|
|
1033
1065
|
// so a handoff spawn would only leak an unmanaged interactive window.
|
|
1034
1066
|
TRANTOR_NO_HANDOFF_SPAWN: "1", TRANTOR_NO_BATON_SPAWN: "1",
|
|
1067
|
+
TRANTOR_HEAVY_GATE_WAIT_DIR: HEAVY_WAIT_DIR,
|
|
1068
|
+
PATH: `${join(import.meta.dirname, "heavy-gate-shim")}:${process.env.PATH || ""}`,
|
|
1035
1069
|
// #6206: the seat's transcript dir — a real CLI ignores it, a drill's fake CLI writes
|
|
1036
1070
|
// its transcript lines there so the watchdog sees the liveness a real claude shows.
|
|
1037
1071
|
TRANTOR_TRANSCRIPT_DIR: TRANSCRIPT_DIR };
|
|
@@ -1041,16 +1075,12 @@ exit $turn_exit`;
|
|
|
1041
1075
|
if (cli.pinned && OC_SEAT_CONFIG) spawnEnv.OPENCODE_CONFIG_CONTENT = OC_SEAT_CONFIG;
|
|
1042
1076
|
spawnOpts.env = spawnEnv;
|
|
1043
1077
|
spawnOpts.maxBuffer = 16 * 1024 * 1024;
|
|
1044
|
-
// The timeout signals the shell to snapshot before sweeping, just like the normal box.
|
|
1045
|
-
// Its 30s margin keeps it out of the normal cut path.
|
|
1046
|
-
if (TURN_MAX_MS) { spawnOpts.timeout = (TURN_EXTENSIONS_MAX ? TURN_CEILING_MS : TURN_MAX_MS) + 30000; spawnOpts.killSignal = "SIGTERM"; }
|
|
1047
1078
|
const r = spawnSync("/bin/bash", ["-c", shell], spawnOpts);
|
|
1048
|
-
//
|
|
1049
|
-
//
|
|
1050
|
-
// the whole window is a stall however the sweep found it.
|
|
1079
|
+
// A stall marker (#7752) outranks the box marker: a turn silent for the whole window is a stall
|
|
1080
|
+
// however the sweep found it. Heavy-gate waits move DEADLINEF instead of feeding a Node timeout.
|
|
1051
1081
|
const boxed = existsSync(CUTF);
|
|
1052
1082
|
const stallCut = existsSync(STALLF);
|
|
1053
|
-
const cut = !!TURN_MAX_MS && (boxed || stallCut
|
|
1083
|
+
const cut = !!TURN_MAX_MS && (boxed || stallCut);
|
|
1054
1084
|
// #7761: how far the watchdog moved the box, one EXTF row per extension. boxMs is the box the
|
|
1055
1085
|
// turn actually had, so a ceiling cut reads as the ceiling, never as the 20-minute default.
|
|
1056
1086
|
let extensions = 0;
|
|
@@ -1075,8 +1105,8 @@ exit $turn_exit`;
|
|
|
1075
1105
|
try { unlinkSync(CUTF); } catch {}
|
|
1076
1106
|
try { unlinkSync(STALLF); } catch {}
|
|
1077
1107
|
if (stallCut) log(`\x1b[33mturn STALLED — no bytes on either stream and no transcript advance for ${Math.round(WD_MS / 60000)}m; ended at the stall window, not the ${Math.round(TURN_MAX_MS / 1000)}s box\x1b[0m`);
|
|
1078
|
-
else if (extensions) log(`\x1b[33mturn cut at the ${Math.round(boxMs / 1000)}s box after ${extensions} liveness extension(s) (ceiling ${Math.round(TURN_CEILING_MS / 1000)}s) — CLI and every descendant ended
|
|
1079
|
-
else log(`\x1b[33mturn cut at the ${Math.round(TURN_MAX_MS / 1000)}s time box — CLI and every descendant ended
|
|
1108
|
+
else if (extensions) log(`\x1b[33mturn cut at the ${Math.round(boxMs / 1000)}s box after ${extensions} liveness extension(s) (ceiling ${Math.round(TURN_CEILING_MS / 1000)}s) — CLI and every descendant ended\x1b[0m`);
|
|
1109
|
+
else log(`\x1b[33mturn cut at the ${Math.round(TURN_MAX_MS / 1000)}s time box — CLI and every descendant ended\x1b[0m`);
|
|
1080
1110
|
}
|
|
1081
1111
|
lastTurnCut = cut;
|
|
1082
1112
|
lastTurnStalled = cut && stallCut;
|
|
@@ -1739,12 +1769,12 @@ async function resolveWakeCard(messages, { session }) {
|
|
|
1739
1769
|
// #10197: no-delivery owes the old contract, but its retry delay must not batch away
|
|
1740
1770
|
// fresh contracts. Only actual CLI failures impose backoff on a new wake.
|
|
1741
1771
|
if (noDeliveryRetry) {
|
|
1742
|
-
unpark("new wake after no-delivery");
|
|
1772
|
+
await unpark("new wake after no-delivery");
|
|
1743
1773
|
retryAt = 0; deliveryFails = 0; noDeliveryRetry = false;
|
|
1744
1774
|
}
|
|
1745
1775
|
if (parkState && directWake.length) {
|
|
1746
1776
|
if (isBoundedPark(parkState.reason)) {
|
|
1747
|
-
unpark(`direct message from ${directWake[0].from || "?"}`);
|
|
1777
|
+
await unpark(`direct message from ${directWake[0].from || "?"}`);
|
|
1748
1778
|
retryAt = 0; deliveryFails = 0; cutChain = [];
|
|
1749
1779
|
} else {
|
|
1750
1780
|
log(`\x1b[33mparked (${parkState.reason}) — a direct message cannot clear this park; it holds until the reset or \`trantor up ${AGENT}\`\x1b[0m`);
|
|
@@ -1913,7 +1943,13 @@ async function resolveWakeCard(messages, { session }) {
|
|
|
1913
1943
|
savePending([], pendingBcast);
|
|
1914
1944
|
return;
|
|
1915
1945
|
}
|
|
1916
|
-
if (aligned.parked)
|
|
1946
|
+
if (aligned.parked) {
|
|
1947
|
+
const notice = `saved unharvested seat commits at ${aligned.parked} before aligning #${card} to ${base}`;
|
|
1948
|
+
log(notice);
|
|
1949
|
+
const owed = assigners.map(a => a.from).filter(f => f && f !== SESSION);
|
|
1950
|
+
for (const to of (owed.length ? owed : ["all"]))
|
|
1951
|
+
await api("/send", { from: SESSION, to, text: notice, project: PROJ, kind: "alert" }).catch(() => {});
|
|
1952
|
+
}
|
|
1917
1953
|
}
|
|
1918
1954
|
const baseText = base ? `\n${baseLine(base)}\n` : "";
|
|
1919
1955
|
// #6289: the session SHAPE (fresh vs resume) reads the served contract's raw citation — a wake
|
|
@@ -2049,8 +2085,9 @@ async function resolveWakeCard(messages, { session }) {
|
|
|
2049
2085
|
const text = `⛔ permission rejected: ${lastPermissionReject.tool} on #${sessionCard} · ${lastPermissionReject.evidence} · card moved to blocked; wake stays owed`;
|
|
2050
2086
|
savePending(pendingWake, pendingBcast);
|
|
2051
2087
|
await api("/task/update", { id: sessionCard, status: "blocked", note: text, by: SESSION }).catch(() => {});
|
|
2088
|
+
const renewed = sameParkEpisode("permission-rejected"); // #13949: once per episode
|
|
2052
2089
|
retryAt = await parkSeat("permission-rejected", pendingWake.length, 0, { announce: false });
|
|
2053
|
-
await notifyAssigners(assigners, text);
|
|
2090
|
+
if (!renewed) await notifyAssigners(assigners, text);
|
|
2054
2091
|
lastTurnAt = Date.now();
|
|
2055
2092
|
return;
|
|
2056
2093
|
}
|
|
@@ -2084,6 +2121,7 @@ async function resolveWakeCard(messages, { session }) {
|
|
|
2084
2121
|
const stallWhy = reason === "stalled" ? ` · probable cause: ${stallCause({ text: lastErrText })}` : "";
|
|
2085
2122
|
const evidence = cutChain.length >= CUT_CHAIN_PARK_MIN ? cutChainEvidence(cutChain) : "";
|
|
2086
2123
|
if (PARKING_REASONS.has(reason) || deliveryFails >= 2) {
|
|
2124
|
+
const renewed = sameParkEpisode(parkReason); // #13949: a window-lift retry re-parking
|
|
2087
2125
|
retryAt = await parkSeat(parkReason, pendingWake.length, quotaReset, { evidence });
|
|
2088
2126
|
// RUNNER_PARK_MAX_MS is set only by `trantor duty up` (launchd keepalive): past the ceiling,
|
|
2089
2127
|
// exit so the supervisor restarts clean. Unsupervised seats stay parked; exiting would kill them.
|
|
@@ -2098,15 +2136,16 @@ async function resolveWakeCard(messages, { session }) {
|
|
|
2098
2136
|
}
|
|
2099
2137
|
// #7914: what the park is, when it lifts, and the evidence it rests on — in the message
|
|
2100
2138
|
// that reaches the one who is actually blocked, not only in the card log they never read.
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2139
|
+
// #13949: once per episode — the retries inside it are state, not events.
|
|
2140
|
+
const lifts = parkLifts();
|
|
2141
|
+
if (!renewed) {
|
|
2142
|
+
// The lift time goes BEFORE the evidence: the transport caps the line, and what the reader
|
|
2143
|
+
// has to act on must never be the part that gets eaten.
|
|
2144
|
+
await notifyAssigners(assigners,
|
|
2145
|
+
reason === "stalled"
|
|
2146
|
+
? `⛔ your contract is PARKED on ${SESSION} (stalled: two turns silent for the whole watchdog window)${lifts}${stallWhy} · asked: "${asked}"`
|
|
2147
|
+
: `⛔ your contract is PARKED on ${SESSION} (${parkReason})${lifts}${evidence ? ` · ${evidence}` : ""} · asked: "${asked}"`);
|
|
2148
|
+
}
|
|
2110
2149
|
lastTurnAt = Date.now();
|
|
2111
2150
|
return;
|
|
2112
2151
|
}
|
|
@@ -2137,9 +2176,12 @@ async function resolveWakeCard(messages, { session }) {
|
|
|
2137
2176
|
savePending(pendingWake, pendingBcast);
|
|
2138
2177
|
const still = lastNoDeliveryStatus || "unresolved";
|
|
2139
2178
|
if (deliveryFails >= 2) {
|
|
2179
|
+
// #13949: every window-lift retry inside the episode re-parks HERE. The one notice went
|
|
2180
|
+
// out when the episode started; these retries are state, never another DM.
|
|
2181
|
+
const renewed = sameParkEpisode("no-delivery");
|
|
2140
2182
|
retryAt = await parkSeat("no-delivery", pendingWake.length);
|
|
2141
|
-
await notifyAssigners(assigners,
|
|
2142
|
-
`⛔ your contract is PARKED on ${SESSION} (no-delivery: two exit-0 turns with no commit and card #${sessionCard} unmoved) · asked: "${asked}"`);
|
|
2183
|
+
if (!renewed) await notifyAssigners(assigners,
|
|
2184
|
+
`⛔ your contract is PARKED on ${SESSION} (no-delivery: two exit-0 turns with no commit and card #${sessionCard} unmoved)${parkLifts()} · asked: "${asked}"`);
|
|
2143
2185
|
lastTurnAt = Date.now();
|
|
2144
2186
|
return;
|
|
2145
2187
|
}
|
|
@@ -2155,9 +2197,10 @@ async function resolveWakeCard(messages, { session }) {
|
|
|
2155
2197
|
deliveryFails++;
|
|
2156
2198
|
savePending(pendingWake, pendingBcast);
|
|
2157
2199
|
if (deliveryFails >= 2) {
|
|
2200
|
+
const renewed = sameParkEpisode("empty-turn"); // #13949: retries inside the episode stay quiet
|
|
2158
2201
|
retryAt = await parkSeat("empty-turn", pendingWake.length);
|
|
2159
|
-
await notifyAssigners(assigners,
|
|
2160
|
-
`⛔ your contract is PARKED on ${SESSION} (empty-turn: two exit-0 turns with no worktree change, substantive output or bus activity) · asked: "${asked}"`);
|
|
2202
|
+
if (!renewed) await notifyAssigners(assigners,
|
|
2203
|
+
`⛔ your contract is PARKED on ${SESSION} (empty-turn: two exit-0 turns with no worktree change, substantive output or bus activity)${parkLifts()} · asked: "${asked}"`);
|
|
2161
2204
|
lastTurnAt = Date.now();
|
|
2162
2205
|
return;
|
|
2163
2206
|
}
|
|
@@ -2168,7 +2211,7 @@ async function resolveWakeCard(messages, { session }) {
|
|
|
2168
2211
|
`🫥 EMPTY turn on ${SESSION} (exit 0, ${secs}s — no worktree change, no substantive output, no bus activity) · wake stays owed · retrying in ${Math.round(wait / 1000)}s · asked: "${asked}"`);
|
|
2169
2212
|
} else {
|
|
2170
2213
|
pendingWake = []; pendingBcast = []; deliveryFails = 0; retryAt = 0;
|
|
2171
|
-
unpark("a turn landed"); // #7914: the seat is working again — the park record must not outlive it
|
|
2214
|
+
await unpark("a turn landed"); // #7914: the seat is working again — the park record must not outlive it
|
|
2172
2215
|
// #7778: reconcile BEFORE the write below so the persisted snapshot carries the seen-set.
|
|
2173
2216
|
await reconcileSessionReads(cursor);
|
|
2174
2217
|
savePending([], []);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { checkTauriVersionParity } from "../lib/tauri-version-parity.mjs";
|
|
6
|
+
|
|
7
|
+
const ROOT = fileURLToPath(new URL("../", import.meta.url));
|
|
8
|
+
let parity;
|
|
9
|
+
try {
|
|
10
|
+
parity = checkTauriVersionParity(join(ROOT, "desktop"));
|
|
11
|
+
} catch (error) {
|
|
12
|
+
console.error(`desktop-build-gate: ${error.message}`);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
const mismatches = parity.filter(pair => !pair.matches);
|
|
16
|
+
for (const pair of mismatches) {
|
|
17
|
+
console.error(`desktop-build-gate: ${pair.crateName} ${pair.cargoVersion} != ${pair.npmPackage} ${pair.npmVersion}; major.minor must match`);
|
|
18
|
+
}
|
|
19
|
+
if (mismatches.length) process.exit(1);
|
|
20
|
+
console.log(`Tauri version parity: ${parity.length} pair${parity.length === 1 ? "" : "s"} matched`);
|
|
21
|
+
|
|
22
|
+
const result = spawnSync(process.execPath, [
|
|
23
|
+
join(ROOT, "bin", "cargo-gate.mjs"),
|
|
24
|
+
"check",
|
|
25
|
+
"--release",
|
|
26
|
+
"--locked",
|
|
27
|
+
"--manifest-path",
|
|
28
|
+
"desktop/src-tauri/Cargo.toml",
|
|
29
|
+
], { cwd: ROOT, stdio: "inherit" });
|
|
30
|
+
|
|
31
|
+
if (result.error) {
|
|
32
|
+
console.error(`desktop-build-gate: ${result.error.message}`);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
process.exit(result.status ?? 1);
|
package/bin/doctor.mjs
CHANGED
|
@@ -15,6 +15,7 @@ import { scan } from "../lib/splitbrain.mjs";
|
|
|
15
15
|
import { resolveSecrets, envFileSecrets, backendFor } from "../lib/secrets.mjs";
|
|
16
16
|
import { resolveStateFlags } from "../lib/state/flags.mjs";
|
|
17
17
|
import { probeClaudeIntegration, HERDR_CLAUDE_INSTALL } from "../lib/herdr-integration.mjs";
|
|
18
|
+
import { axeDoctorStatus } from "../lib/sim/axe-status.mjs";
|
|
18
19
|
|
|
19
20
|
const H = homedir();
|
|
20
21
|
const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
@@ -362,6 +363,20 @@ prof?.providers && Object.keys(prof.providers).length
|
|
|
362
363
|
// billing issues while the duty seat had held 48 undelivered messages for 22 hours and finished
|
|
363
364
|
// crew work went unread overnight: credentials EXIST is not the fleet is MOVING. Both signals are
|
|
364
365
|
// already on disk, written by the runner itself.
|
|
366
|
+
section("iOS simulator driver");
|
|
367
|
+
{
|
|
368
|
+
const present = has("axe");
|
|
369
|
+
let version = "";
|
|
370
|
+
if (present) {
|
|
371
|
+
try { version = execSync("axe --version", { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim(); }
|
|
372
|
+
catch { version = ""; }
|
|
373
|
+
}
|
|
374
|
+
const status = axeDoctorStatus(process.platform, present, version);
|
|
375
|
+
if (status.kind === "ok") ok(status.message);
|
|
376
|
+
else if (status.kind === "warn") warn(status.message, `bash ${join(ROOT, "bin", "install-axe.sh")}`);
|
|
377
|
+
else note(status.message);
|
|
378
|
+
}
|
|
379
|
+
|
|
365
380
|
section("the fleet (is it actually running?)");
|
|
366
381
|
{
|
|
367
382
|
const busDir = join(H, ".agent-bus");
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
if [[ "$(uname -s)" != Darwin ]]; then
|
|
5
|
+
echo "AXe v2.1.1 requires macOS; install it on the Mac that hosts the iOS Simulator." >&2
|
|
6
|
+
exit 1
|
|
7
|
+
fi
|
|
8
|
+
|
|
9
|
+
VERSION="2.1.1"
|
|
10
|
+
SHA256="8788838b1b32059d143cf06541b72fcaead85c16274457cdbff086510a5b17fa"
|
|
11
|
+
ARCHIVE="AXe-macOS-v${VERSION}-universal.tar.gz"
|
|
12
|
+
URL="https://github.com/cameroncooke/AXe/releases/download/v${VERSION}/${ARCHIVE}"
|
|
13
|
+
DEST="${HOME}/.local/share/trantor/axe/v${VERSION}"
|
|
14
|
+
BIN="${HOME}/.local/bin"
|
|
15
|
+
TMP="$(mktemp -d)"
|
|
16
|
+
trap 'rm -rf "$TMP"' EXIT
|
|
17
|
+
|
|
18
|
+
mkdir -p "$DEST" "$BIN"
|
|
19
|
+
curl --fail --location --silent --show-error "$URL" -o "$TMP/$ARCHIVE"
|
|
20
|
+
echo "$SHA256 $TMP/$ARCHIVE" | shasum -a 256 -c -
|
|
21
|
+
tar -xzf "$TMP/$ARCHIVE" -C "$DEST"
|
|
22
|
+
ln -sfn "$DEST/axe" "$BIN/axe"
|
|
23
|
+
echo "Installed AXe v${VERSION} at $DEST/axe"
|
|
24
|
+
echo "Ensure $BIN is on PATH, then verify with: axe --version"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { constants } from "node:os";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
|
+
|
|
6
|
+
const [tool, ...args] = process.argv.slice(2);
|
|
7
|
+
const shimDir = resolve(import.meta.dirname, "heavy-gate-shim");
|
|
8
|
+
const path = (process.env.PATH || "").split(":").filter(entry => resolve(entry) !== shimDir).join(":");
|
|
9
|
+
const env = { ...process.env, PATH: path };
|
|
10
|
+
const heavy = args.some((arg, index) => arg === "vitest" && args[index + 1] === "run");
|
|
11
|
+
const result = heavy
|
|
12
|
+
? spawnSync(process.execPath, [join(import.meta.dirname, "heavy-gate.mjs"), "--", tool, ...args], { env, stdio: "inherit" })
|
|
13
|
+
: spawnSync(tool, args, { env, stdio: "inherit" });
|
|
14
|
+
if (result.error) {
|
|
15
|
+
console.error(`package-runner-gate: ${result.error.message}`);
|
|
16
|
+
process.exit(127);
|
|
17
|
+
}
|
|
18
|
+
if (result.signal) process.exit(128 + (constants.signals[result.signal] || 0));
|
|
19
|
+
process.exit(result.status ?? 1);
|
package/bin/sim.mjs
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { dirname, join, resolve } from "node:path";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
const AXE_INSTALL = `bash ${join(dirname(fileURLToPath(import.meta.url)), "install-axe.sh")}`;
|
|
10
|
+
const [, , verb, ...args] = process.argv;
|
|
11
|
+
const owner = process.env.RELAY_SESSION || process.env.CLAUDE_SESSION_ID || process.cwd();
|
|
12
|
+
const ownerId = createHash("sha256").update(owner).digest("hex").slice(0, 16);
|
|
13
|
+
const registryPath = process.env.TRANTOR_SIM_REGISTRY || join(tmpdir(), "trantor-sim-registry.json");
|
|
14
|
+
const outputRoot = process.env.TRANTOR_SIM_OUTPUT || join(process.cwd(), ".agent-bus-out", "sim");
|
|
15
|
+
|
|
16
|
+
function fail(reason) {
|
|
17
|
+
console.error(String(reason).trim() || "simulator command failed");
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function command(file, argv, { optional = false } = {}) {
|
|
22
|
+
const result = spawnSync(file, argv, { encoding: "utf8", maxBuffer: 32 * 1024 * 1024 });
|
|
23
|
+
if (result.error?.code === "ENOENT" && optional) return null;
|
|
24
|
+
if (result.error) fail(`${file} failed: ${result.error.message}`);
|
|
25
|
+
if (result.status !== 0) fail((result.stderr || result.stdout || `${file} exited ${result.status}`).trim());
|
|
26
|
+
return result.stdout || "";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function axe(args) {
|
|
30
|
+
const result = spawnSync("axe", args, { encoding: "utf8", maxBuffer: 32 * 1024 * 1024 });
|
|
31
|
+
if (result.error?.code === "ENOENT") fail(`AXe is missing. Install the pinned release with: ${AXE_INSTALL}`);
|
|
32
|
+
if (result.error) fail(`axe failed: ${result.error.message}`);
|
|
33
|
+
if (result.status !== 0) fail((result.stderr || result.stdout || `axe exited ${result.status}`).trim());
|
|
34
|
+
return result.stdout || "";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function registry() {
|
|
38
|
+
try { return JSON.parse(readFileSync(registryPath, "utf8")); }
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (error.code === "ENOENT") return { owners: {} };
|
|
41
|
+
fail(`cannot read simulator registry: ${error.message}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function saveRegistry(value) {
|
|
46
|
+
mkdirSync(dirname(registryPath), { recursive: true });
|
|
47
|
+
const temp = `${registryPath}.${process.pid}.tmp`;
|
|
48
|
+
writeFileSync(temp, JSON.stringify(value));
|
|
49
|
+
renameSync(temp, registryPath);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function simulators() {
|
|
53
|
+
let list;
|
|
54
|
+
try { list = JSON.parse(command("xcrun", ["simctl", "list", "devices", "--json"])); }
|
|
55
|
+
catch (error) { fail(`could not read Simulator devices: ${error.message}`); }
|
|
56
|
+
return Object.values(list.devices || {}).flat();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function selected() {
|
|
60
|
+
const id = registry().owners[ownerId]?.udid;
|
|
61
|
+
if (!id) fail("this session has no simulator; run trantor sim boot <device> first");
|
|
62
|
+
const device = simulators().find((item) => item.udid === id);
|
|
63
|
+
if (!device || device.state !== "Booted") fail(`owned simulator ${id} is not booted; run trantor sim boot <device>`);
|
|
64
|
+
return device;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function emit(value) { process.stdout.write(`${JSON.stringify(value)}\n`); }
|
|
68
|
+
|
|
69
|
+
function resolveDevice(name, devices) {
|
|
70
|
+
const matches = devices.filter((device) => device.udid === name || device.name === name);
|
|
71
|
+
if (matches.length === 0) fail(`simulator not found: ${name}`);
|
|
72
|
+
if (matches.length > 1) fail(`simulator name is ambiguous: ${name}; pass its UDID`);
|
|
73
|
+
return matches[0];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function parseTree(raw) {
|
|
77
|
+
let tree;
|
|
78
|
+
try { tree = JSON.parse(raw); }
|
|
79
|
+
catch { fail("AXe returned invalid accessibility JSON"); }
|
|
80
|
+
if (tree?.didError) fail(tree.error?.message || "AXe accessibility read failed");
|
|
81
|
+
const root = tree?.data?.result ?? tree;
|
|
82
|
+
const elements = [];
|
|
83
|
+
let maxX = 0, maxY = 0;
|
|
84
|
+
const visit = (node) => {
|
|
85
|
+
if (Array.isArray(node)) { for (const child of node) visit(child); return; }
|
|
86
|
+
if (!node || Object.getPrototypeOf(node) !== Object.prototype) return;
|
|
87
|
+
const frame = node.frame || node.AXFrame;
|
|
88
|
+
if (frame && Object.getPrototypeOf(frame) === Object.prototype) {
|
|
89
|
+
const x = Number(frame.x ?? 0), y = Number(frame.y ?? 0);
|
|
90
|
+
const width = Number(frame.width ?? 0), height = Number(frame.height ?? 0);
|
|
91
|
+
if ([x, y, width, height].every(Number.isFinite)) {
|
|
92
|
+
maxX = Math.max(maxX, x + width); maxY = Math.max(maxY, y + height);
|
|
93
|
+
const label = node.AXLabel ?? node.label ?? node.title ?? node.AXValue ?? "";
|
|
94
|
+
const role = node.role_description ?? node.role ?? node.type ?? node.AXRole ?? "";
|
|
95
|
+
const id = node.AXUniqueId ?? node.identifier ?? node.id;
|
|
96
|
+
if (label || role || id) {
|
|
97
|
+
const element = { frame: { x, y, width, height }, enabled: node.enabled ?? node.isEnabled ?? true };
|
|
98
|
+
if (label) element.label = String(label);
|
|
99
|
+
if (id) element.id = String(id);
|
|
100
|
+
if (role) element.role = String(role);
|
|
101
|
+
elements.push({ ...element, _hasLabelOrId: Boolean(label || id), _scrollBarSlider:
|
|
102
|
+
/slider/i.test(String(node.role ?? node.type ?? node.AXRole ?? ""))
|
|
103
|
+
&& /scroll.?bar/i.test([node.role_description, node.roleDescription, node.AXLabel, node.label].filter(Boolean).join(" ")) });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
for (const [key, value] of Object.entries(node)) if (key === "children" || key === "AXChildren") visit(value);
|
|
108
|
+
};
|
|
109
|
+
visit(root);
|
|
110
|
+
if (maxX <= 0 || maxY <= 0) fail("AXe accessibility tree has no screen-sized frame");
|
|
111
|
+
const widthPoints = Math.round(maxX), heightPoints = Math.round(maxY);
|
|
112
|
+
const visible = elements.filter((element) => {
|
|
113
|
+
if (element._scrollBarSlider) return false;
|
|
114
|
+
if (element._hasLabelOrId) return true;
|
|
115
|
+
const { x, y, width, height } = element.frame;
|
|
116
|
+
if (width <= 0 || height <= 0) return false;
|
|
117
|
+
if (x <= 0 && y <= 0 && width >= widthPoints && height >= heightPoints) return false;
|
|
118
|
+
return true;
|
|
119
|
+
}).map(({ _hasLabelOrId, _scrollBarSlider, ...element }) => element);
|
|
120
|
+
return { elements: visible, widthPoints, heightPoints };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function point(value, name) {
|
|
124
|
+
const coords = String(value || "").split(",").map(Number);
|
|
125
|
+
if (coords.length !== 2 || coords.some((part) => !Number.isFinite(part) || part < 0)) fail(`${name} must be x,y in simulator points`);
|
|
126
|
+
return coords;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function pointDimensions(device) {
|
|
130
|
+
const shared = registry();
|
|
131
|
+
const owned = shared.owners[ownerId];
|
|
132
|
+
if (owned.dimensionsPoints?.width > 0 && owned.dimensionsPoints?.height > 0) return owned.dimensionsPoints;
|
|
133
|
+
const tree = parseTree(axe(["describe-ui", "--minimal-keys", "--udid", device.udid]));
|
|
134
|
+
owned.dimensionsPoints = { width: tree.widthPoints, height: tree.heightPoints };
|
|
135
|
+
saveRegistry(shared);
|
|
136
|
+
return owned.dimensionsPoints;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function checkOnScreen(coords, name, dimensions) {
|
|
140
|
+
if (coords[0] >= dimensions.width || coords[1] >= dimensions.height) {
|
|
141
|
+
fail(`${name} point ${coords.join(",")} is outside the simulator screen (${dimensions.width}x${dimensions.height} points)`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
if (verb === "boot") {
|
|
147
|
+
if (args.length !== 1 || !args[0]) fail("usage: trantor sim boot <device-name-or-udid>");
|
|
148
|
+
const devices = simulators();
|
|
149
|
+
const target = resolveDevice(args[0], devices);
|
|
150
|
+
const shared = registry();
|
|
151
|
+
const anotherOwner = Object.entries(shared.owners).find(([key, value]) => key !== ownerId && value.udid === target.udid);
|
|
152
|
+
if (anotherOwner) fail(`simulator ${target.name} is owned by another agent session`);
|
|
153
|
+
const bootedElsewhere = devices.find((device) => device.state === "Booted" && device.udid !== target.udid);
|
|
154
|
+
if (bootedElsewhere) fail(`another simulator is already booted (${bootedElsewhere.name}, ${bootedElsewhere.udid}); shut it down before booting ${target.name}`);
|
|
155
|
+
if (target.state !== "Booted") {
|
|
156
|
+
command("xcrun", ["simctl", "boot", target.udid]);
|
|
157
|
+
command("xcrun", ["simctl", "bootstatus", target.udid, "-b"]);
|
|
158
|
+
}
|
|
159
|
+
shared.owners[ownerId] = { udid: target.udid, name: target.name, startedAt: new Date().toISOString() };
|
|
160
|
+
saveRegistry(shared);
|
|
161
|
+
emit({ verb, udid: target.udid, device: target.name, reused: target.state === "Booted", state: "Booted" });
|
|
162
|
+
} else if (verb === "install") {
|
|
163
|
+
if (args.length !== 1) fail("usage: trantor sim install <app-path>");
|
|
164
|
+
const device = selected(), app = resolve(args[0]);
|
|
165
|
+
command("xcrun", ["simctl", "install", device.udid, app]);
|
|
166
|
+
emit({ verb, udid: device.udid, app });
|
|
167
|
+
} else if (verb === "launch") {
|
|
168
|
+
if (args.length !== 1) fail("usage: trantor sim launch <bundle-id>");
|
|
169
|
+
const device = selected();
|
|
170
|
+
const result = command("xcrun", ["simctl", "launch", device.udid, args[0]]).trim();
|
|
171
|
+
emit({ verb, udid: device.udid, bundle: args[0], result });
|
|
172
|
+
} else if (verb === "screen") {
|
|
173
|
+
const device = selected();
|
|
174
|
+
const outAt = args.indexOf("--out");
|
|
175
|
+
if (args.length && (outAt !== 0 || args.length !== 2 || !args[1])) fail("usage: trantor sim screen [--out <png-path>]");
|
|
176
|
+
const path = resolve(outAt === 0 ? args[1] : join(outputRoot, `screen-${Date.now()}.png`));
|
|
177
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
178
|
+
command("xcrun", ["simctl", "io", device.udid, "screenshot", path]);
|
|
179
|
+
const tree = parseTree(axe(["describe-ui", "--minimal-keys", "--udid", device.udid]));
|
|
180
|
+
const shared = registry();
|
|
181
|
+
shared.owners[ownerId].dimensionsPoints = { width: tree.widthPoints, height: tree.heightPoints };
|
|
182
|
+
saveRegistry(shared);
|
|
183
|
+
const dimensions = command("sips", ["-g", "pixelWidth", "-g", "pixelHeight", path]);
|
|
184
|
+
const pixelWidth = Number(dimensions.match(/pixelWidth:\s*(\d+)/)?.[1]);
|
|
185
|
+
const pixelHeight = Number(dimensions.match(/pixelHeight:\s*(\d+)/)?.[1]);
|
|
186
|
+
if (!pixelWidth || !pixelHeight) fail("could not read screenshot dimensions with sips");
|
|
187
|
+
const scaledPath = `${path}.scaled.png`;
|
|
188
|
+
command("sips", ["-z", String(tree.heightPoints), String(tree.widthPoints), path, "--out", scaledPath]);
|
|
189
|
+
rmSync(path, { force: true });
|
|
190
|
+
command("/bin/mv", [scaledPath, path]);
|
|
191
|
+
emit({ verb, udid: device.udid, screenshot: path, dimensionsPoints: { width: tree.widthPoints, height: tree.heightPoints }, elements: tree.elements });
|
|
192
|
+
} else if (verb === "tap") {
|
|
193
|
+
const device = selected();
|
|
194
|
+
const mode = args[0], value = args[1];
|
|
195
|
+
if (args.length !== 2 || !["--label", "--id", "--xy"].includes(mode) || !value) fail("usage: trantor sim tap --label <text> | --id <identifier> | --xy x,y");
|
|
196
|
+
let target;
|
|
197
|
+
if (mode === "--xy") {
|
|
198
|
+
const coords = point(value, "--xy");
|
|
199
|
+
checkOnScreen(coords, "--xy", pointDimensions(device));
|
|
200
|
+
target = ["-x", String(coords[0]), "-y", String(coords[1])];
|
|
201
|
+
} else target = [mode, value];
|
|
202
|
+
axe(["tap", ...target, "--udid", device.udid]);
|
|
203
|
+
emit({ verb, udid: device.udid, selector: mode, target: value });
|
|
204
|
+
} else if (verb === "swipe") {
|
|
205
|
+
const device = selected();
|
|
206
|
+
if (args.length !== 4 || args[0] !== "--from" || args[2] !== "--to") fail("usage: trantor sim swipe --from x,y --to x,y");
|
|
207
|
+
const from = point(args[1], "--from"), to = point(args[3], "--to");
|
|
208
|
+
const dimensions = pointDimensions(device);
|
|
209
|
+
checkOnScreen(from, "--from", dimensions);
|
|
210
|
+
checkOnScreen(to, "--to", dimensions);
|
|
211
|
+
axe(["swipe", "--start-x", String(from[0]), "--start-y", String(from[1]), "--end-x", String(to[0]), "--end-y", String(to[1]), "--udid", device.udid]);
|
|
212
|
+
emit({ verb, udid: device.udid, from, to });
|
|
213
|
+
} else if (verb === "type") {
|
|
214
|
+
const device = selected(), value = args.join(" ");
|
|
215
|
+
if (!value) fail("usage: trantor sim type <text>");
|
|
216
|
+
axe(["type", value, "--udid", device.udid]);
|
|
217
|
+
emit({ verb, udid: device.udid, characters: [...value].length });
|
|
218
|
+
} else if (verb === "shutdown") {
|
|
219
|
+
if (args.length) fail("usage: trantor sim shutdown");
|
|
220
|
+
const shared = registry(), owned = shared.owners[ownerId];
|
|
221
|
+
if (!owned) { emit({ verb, shutdown: false, reason: "this session owns no simulator" }); }
|
|
222
|
+
else {
|
|
223
|
+
const device = simulators().find((item) => item.udid === owned.udid);
|
|
224
|
+
if (device?.state === "Booted") command("xcrun", ["simctl", "shutdown", owned.udid]);
|
|
225
|
+
delete shared.owners[ownerId];
|
|
226
|
+
saveRegistry(shared);
|
|
227
|
+
emit({ verb, udid: owned.udid, shutdown: device?.state === "Booted", alreadyShutdown: device?.state !== "Booted" });
|
|
228
|
+
}
|
|
229
|
+
} else {
|
|
230
|
+
fail("usage: trantor sim <boot|install|launch|screen|tap|swipe|type|shutdown>");
|
|
231
|
+
}
|
|
232
|
+
} catch (error) {
|
|
233
|
+
if (error?.message) fail(error.message);
|
|
234
|
+
fail("simulator command failed");
|
|
235
|
+
}
|
package/bin/turn-watchdog.mjs
CHANGED
|
@@ -9,8 +9,9 @@ import { sessionActivityReader } from "../lib/session-liveness.mjs";
|
|
|
9
9
|
import { hostId } from "../lib/project.mjs";
|
|
10
10
|
import { signedPost } from "../hooks/lib/api.mjs";
|
|
11
11
|
import { refreshTurnLiveness } from "../lib/turnstate.mjs";
|
|
12
|
+
import { readHeavyGateWait } from "../lib/heavy-gate-wait.mjs";
|
|
12
13
|
|
|
13
|
-
const [stampFile, errFile, windowMsRaw, session, project, hub, transcriptDir = "", workDir = "", stallFile = "", turnStateFile = ""] = process.argv.slice(2);
|
|
14
|
+
const [stampFile, errFile, windowMsRaw, session, project, hub, transcriptDir = "", workDir = "", stallFile = "", turnStateFile = "", heavyWaitDir = ""] = process.argv.slice(2);
|
|
14
15
|
// SAFETY: the 10-minute floor lives in crew-runner.mjs (the default when TRANTOR_TURN_WATCHDOG_MS
|
|
15
16
|
// is unset); this fallback only covers a missing argument. Drills pass tiny windows on purpose.
|
|
16
17
|
const windowMs = Number(windowMsRaw) || 10 * 60 * 1000;
|
|
@@ -30,7 +31,7 @@ function newestMtime(dir) {
|
|
|
30
31
|
let rows = [];
|
|
31
32
|
try { rows = readdirSync(d, { withFileTypes: true }); } catch { return; }
|
|
32
33
|
for (const e of rows) {
|
|
33
|
-
if (++seen > SCAN_CAP || e.name === ".git" || e.name === "node_modules") continue;
|
|
34
|
+
if (++seen > SCAN_CAP || e.name === ".git" || e.name === "node_modules" || e.name === ".agent-bus") continue;
|
|
34
35
|
const p = join(d, e.name);
|
|
35
36
|
if (e.isDirectory()) walk(p);
|
|
36
37
|
else { try { best = Math.max(best, statSync(p).mtimeMs); } catch {} }
|
|
@@ -98,9 +99,10 @@ function reportLiveness(now, tr) {
|
|
|
98
99
|
|
|
99
100
|
// #7752 kill mode: poll liveness; a whole window silent on EVERY channel writes the stall marker
|
|
100
101
|
// (the shell box sweeps on it), reports once, exits; stderr is measured ROLLING (bytes this window).
|
|
101
|
-
// #7761: `armed.box`
|
|
102
|
-
// deadline one poll away on a turn
|
|
103
|
-
const
|
|
102
|
+
// #7761: `armed.box.extensionsMax` enables liveness extensions; heavy-gate waits move the deadline
|
|
103
|
+
// in both modes, and a deadline one poll away on a moving turn is pushed out one step.
|
|
104
|
+
const timeBox = stallFile && armed.box ? armed.box : null;
|
|
105
|
+
const box = timeBox && Number(timeBox.extensionsMax) > 0 ? timeBox : null;
|
|
104
106
|
const mins = (ms) => `${Math.max(1, Math.round(ms / 60000))}m`;
|
|
105
107
|
const secsOrMins = (ms) => (ms >= 60000 ? mins(ms) : `${Math.round(ms / 1000)}s`);
|
|
106
108
|
async function tellExtension(text) {
|
|
@@ -117,7 +119,7 @@ async function tellExtension(text) {
|
|
|
117
119
|
if (stallFile) {
|
|
118
120
|
const poll = Math.max(250, Math.min(windowMs / 4, 10000));
|
|
119
121
|
let lastErrAt = armedAt;
|
|
120
|
-
let deadline = armedAt + (
|
|
122
|
+
let deadline = armedAt + (timeBox ? Number(timeBox.maxMs) : 0);
|
|
121
123
|
let extensions = 0;
|
|
122
124
|
for (;;) {
|
|
123
125
|
await sleep(poll);
|
|
@@ -125,6 +127,11 @@ if (stallFile) {
|
|
|
125
127
|
if (!s || s.turn !== armed.turn || (armed.runner && s.runner !== armed.runner)) process.exit(0); // turn ended, or a NEWER runner owns the stamp now
|
|
126
128
|
if (!runnerAlive()) process.exit(0); // our runner is gone — never speak for it
|
|
127
129
|
const now = Date.now();
|
|
130
|
+
const heavyWait = readHeavyGateWait(heavyWaitDir, now);
|
|
131
|
+
if (timeBox) {
|
|
132
|
+
deadline = armedAt + Number(timeBox.maxMs) + heavyWait.totalMs + extensions * Number(timeBox.extendMs);
|
|
133
|
+
try { writeFileSync(timeBox.deadlineFile, String(Math.floor(deadline / 1000))); } catch {}
|
|
134
|
+
}
|
|
128
135
|
const size = errSize();
|
|
129
136
|
if (size > baseErr + 200) { baseErr = size; lastErrAt = now; } // new bytes: alive
|
|
130
137
|
const freshCut = Math.max(armedAt, now - windowMs - SLACK);
|
|
@@ -132,6 +139,7 @@ if (stallFile) {
|
|
|
132
139
|
const cli = sessionActivity();
|
|
133
140
|
const wk = workDir ? newestMtime(workDir) : 0;
|
|
134
141
|
reportLiveness(now, Math.max(tr, cli));
|
|
142
|
+
if (heavyWait.waiting) { lastErrAt = now; continue; }
|
|
135
143
|
if (tr > freshCut || cli > freshCut || wk > freshCut || now - lastErrAt < windowMs) { // producing work: alive
|
|
136
144
|
if (box && extensions < Number(box.extensionsMax) && now + poll + SLACK >= deadline) {
|
|
137
145
|
extensions++;
|
|
@@ -168,6 +176,7 @@ for (;;) {
|
|
|
168
176
|
const cli = sessionActivity();
|
|
169
177
|
const wk = workDir ? newestMtime(workDir) : 0;
|
|
170
178
|
reportLiveness(Date.now(), Math.max(tr, cli));
|
|
179
|
+
if (readHeavyGateWait(heavyWaitDir).waiting) continue;
|
|
171
180
|
if (errSize() > baseErr + 200 || tr > freshCut || cli > freshCut || wk > freshCut) continue; // producing work: alive, re-arm
|
|
172
181
|
const mins = Math.round((Date.now() - armedAt) / 60000);
|
|
173
182
|
const orch = `${hostId()}:${project}`;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
const ACTIVE_MS = 15_000;
|
|
5
|
+
|
|
6
|
+
function alive(pid) {
|
|
7
|
+
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
8
|
+
try { process.kill(pid, 0); return true; }
|
|
9
|
+
catch (error) { return error?.code === "EPERM"; }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function readHeavyGateWait(dir, now = Date.now()) {
|
|
13
|
+
let totalMs = 0, waiting = false;
|
|
14
|
+
if (!dir) return { totalMs, waiting };
|
|
15
|
+
let names = [];
|
|
16
|
+
try { names = readdirSync(dir).filter(name => name.endsWith(".json")).slice(0, 256); } catch { return { totalMs, waiting }; }
|
|
17
|
+
for (const name of names) {
|
|
18
|
+
let row;
|
|
19
|
+
try { row = JSON.parse(readFileSync(join(dir, name), "utf8")); } catch { continue; }
|
|
20
|
+
const recorded = Number(row?.totalMs);
|
|
21
|
+
const updatedAt = Number(row?.updatedAt);
|
|
22
|
+
if (!Number.isFinite(recorded) || recorded < 0 || !Number.isFinite(updatedAt)) continue;
|
|
23
|
+
const active = row.waiting === true && now - updatedAt <= ACTIVE_MS && alive(Number(row.pid));
|
|
24
|
+
totalMs += recorded + (active ? Math.max(0, now - updatedAt) : 0);
|
|
25
|
+
if (active) waiting = true;
|
|
26
|
+
}
|
|
27
|
+
return { totalMs, waiting };
|
|
28
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { closeSync, mkdirSync, openSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { constants, cpus, homedir } from "node:os";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { spawnSync } from "node:child_process";
|
|
5
|
+
|
|
6
|
+
const waitArray = new Int32Array(new SharedArrayBuffer(4));
|
|
7
|
+
|
|
8
|
+
function busDir(env) {
|
|
9
|
+
return env.AGENT_BUS_DIR || env.RELAY_DATA_DIR || join(homedir(), ".agent-bus");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function slotCount(env) {
|
|
13
|
+
try {
|
|
14
|
+
const value = JSON.parse(readFileSync(join(busDir(env), "config.json"), "utf8")).heavyGateSlots;
|
|
15
|
+
if (Number.isSafeInteger(value) && value > 0) return value;
|
|
16
|
+
} catch {}
|
|
17
|
+
return Math.max(1, Math.floor(cpus().length / 4));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function pidAlive(pid) {
|
|
21
|
+
if (!Number.isSafeInteger(pid) || pid <= 0) return false;
|
|
22
|
+
try {
|
|
23
|
+
process.kill(pid, 0);
|
|
24
|
+
return true;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
return error?.code !== "ESRCH";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function readSlot(path) {
|
|
31
|
+
try {
|
|
32
|
+
const row = JSON.parse(readFileSync(path, "utf8"));
|
|
33
|
+
if (Number.isSafeInteger(row.pid) && Number.isFinite(row.startedAt)) return row;
|
|
34
|
+
} catch {}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function writeWait(waitFile, waitStarted, waiting) {
|
|
39
|
+
if (!waitFile || waitStarted === null) return;
|
|
40
|
+
const now = Date.now();
|
|
41
|
+
const temporary = `${waitFile}.tmp`;
|
|
42
|
+
mkdirSync(dirname(waitFile), { recursive: true });
|
|
43
|
+
writeFileSync(temporary, JSON.stringify({
|
|
44
|
+
pid: process.pid,
|
|
45
|
+
waiting,
|
|
46
|
+
updatedAt: now,
|
|
47
|
+
totalMs: now - waitStarted,
|
|
48
|
+
}));
|
|
49
|
+
try { renameSync(temporary, waitFile); } catch (error) {
|
|
50
|
+
try { unlinkSync(temporary); } catch {}
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function acquire(slots, env) {
|
|
56
|
+
const lockDir = join(busDir(env), "heavy-gate");
|
|
57
|
+
mkdirSync(lockDir, { recursive: true });
|
|
58
|
+
const waitDir = env.TRANTOR_HEAVY_GATE_WAIT_DIR;
|
|
59
|
+
const waitFile = waitDir ? join(waitDir, `${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}.json`) : null;
|
|
60
|
+
let waitStarted = null;
|
|
61
|
+
let announced = false;
|
|
62
|
+
let lastBeat = 0;
|
|
63
|
+
let delay = 50;
|
|
64
|
+
|
|
65
|
+
for (;;) {
|
|
66
|
+
let inUse = 0;
|
|
67
|
+
for (let index = 0; index < slots; index += 1) {
|
|
68
|
+
const path = join(lockDir, `slot-${index}.json`);
|
|
69
|
+
let fd;
|
|
70
|
+
try {
|
|
71
|
+
fd = openSync(path, "wx", 0o600);
|
|
72
|
+
writeFileSync(fd, JSON.stringify({ pid: process.pid, startedAt: Date.now() }));
|
|
73
|
+
closeSync(fd);
|
|
74
|
+
writeWait(waitFile, waitStarted, false);
|
|
75
|
+
return { path, waitFile };
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (fd !== undefined) {
|
|
78
|
+
try { closeSync(fd); } catch {}
|
|
79
|
+
try { unlinkSync(path); } catch {}
|
|
80
|
+
}
|
|
81
|
+
if (error?.code !== "EEXIST") throw error;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const row = readSlot(path);
|
|
85
|
+
if (row && !pidAlive(row.pid)) {
|
|
86
|
+
try { unlinkSync(path); } catch {}
|
|
87
|
+
try {
|
|
88
|
+
fd = openSync(path, "wx", 0o600);
|
|
89
|
+
writeFileSync(fd, JSON.stringify({ pid: process.pid, startedAt: Date.now() }));
|
|
90
|
+
closeSync(fd);
|
|
91
|
+
writeWait(waitFile, waitStarted, false);
|
|
92
|
+
return { path, waitFile };
|
|
93
|
+
} catch (error) {
|
|
94
|
+
if (fd !== undefined) { try { closeSync(fd); } catch {} }
|
|
95
|
+
if (error?.code !== "EEXIST") throw error;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
inUse += 1;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!announced) {
|
|
102
|
+
waitStarted = Date.now();
|
|
103
|
+
console.log(`waiting for a heavy-gate slot (${inUse} in use)`);
|
|
104
|
+
announced = true;
|
|
105
|
+
}
|
|
106
|
+
const now = Date.now();
|
|
107
|
+
if (now - lastBeat >= 1000) {
|
|
108
|
+
writeWait(waitFile, waitStarted, true);
|
|
109
|
+
lastBeat = now;
|
|
110
|
+
}
|
|
111
|
+
Atomics.wait(waitArray, 0, 0, delay);
|
|
112
|
+
delay = Math.min(1000, Math.ceil(delay * 1.5));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function runHeavyGate(args, env = process.env) {
|
|
117
|
+
const command = args[0] === "--" ? args.slice(1) : args;
|
|
118
|
+
if (!command.length) {
|
|
119
|
+
console.error("usage: heavy-gate.mjs -- <command> [args ...]");
|
|
120
|
+
return 2;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
let slot = null;
|
|
124
|
+
if (env.TRANTOR_HEAVY_GATE_HELD !== "1") slot = acquire(slotCount(env), env);
|
|
125
|
+
const childEnv = { ...env, TRANTOR_HEAVY_GATE_HELD: "1" };
|
|
126
|
+
try {
|
|
127
|
+
const result = spawnSync(command[0], command.slice(1), { env: childEnv, stdio: "inherit" });
|
|
128
|
+
if (result.error) {
|
|
129
|
+
console.error(`heavy-gate: ${result.error.message}`);
|
|
130
|
+
return 127;
|
|
131
|
+
}
|
|
132
|
+
if (result.signal) return 128 + (constants.signals[result.signal] || 0);
|
|
133
|
+
return result.status ?? 1;
|
|
134
|
+
} finally {
|
|
135
|
+
if (slot) {
|
|
136
|
+
try { unlinkSync(slot.path); } catch {}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
package/lib/seat-worktree.mjs
CHANGED
|
@@ -25,9 +25,9 @@ function gitOut(args, cwd) {
|
|
|
25
25
|
return r.status === 0 ? String(r.stdout || "").trim() : "";
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
// Start a new contract from its pinned base
|
|
29
|
-
//
|
|
30
|
-
export function alignSeatWorktree({ dir, project, agent, base, receiptsRoot }) {
|
|
28
|
+
// Start a new contract from its pinned base unless that base is already in the seat's history.
|
|
29
|
+
// Unharvested commits are parked on harvest/<card-or-sha> before moving the seat branch.
|
|
30
|
+
export function alignSeatWorktree({ dir, project, agent, base, receiptsRoot, log = console.log }) {
|
|
31
31
|
const branch = gitOut(["rev-parse", "--abbrev-ref", "HEAD"], dir);
|
|
32
32
|
const expected = `seat/${agent}`;
|
|
33
33
|
if (branch !== expected) return { ok: false, reason: `refusing to align ${dir}: expected ${expected}, found ${branch || "detached HEAD"}` };
|
|
@@ -35,16 +35,32 @@ export function alignSeatWorktree({ dir, project, agent, base, receiptsRoot }) {
|
|
|
35
35
|
spawnSync("git", ["cat-file", "-e", `${base}^{commit}`], { cwd: dir, stdio: "ignore", timeout: 8000 }).status !== 0)
|
|
36
36
|
return { ok: false, reason: `base ${base || "(missing)"} is not a commit in ${dir}` };
|
|
37
37
|
if (gitOut(["status", "--porcelain"], dir)) return { ok: false, reason: `refusing to reset dirty seat worktree ${dir}` };
|
|
38
|
+
if (spawnSync("git", ["merge-base", "--is-ancestor", base, "HEAD"], { cwd: dir, stdio: "ignore", timeout: 8000 }).status === 0) {
|
|
39
|
+
log(`${branch} branch already contains base ${base}; keeping ${dir} at its current tip`);
|
|
40
|
+
return { ok: true, to: gitOut(["rev-parse", "HEAD"], dir), parked: "" };
|
|
41
|
+
}
|
|
38
42
|
|
|
39
43
|
const receipts = readReceipts(project, receiptsRoot);
|
|
40
44
|
const audit = auditSeat(dir, { branch, targetRef: base, receipts });
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
const parked = [];
|
|
46
|
+
for (const commit of audit.unharvested) {
|
|
47
|
+
const refs = gitOut(["for-each-ref", "--format=%(refname)", "refs/heads/harvest"], dir).split("\n").filter(Boolean);
|
|
48
|
+
const saved = refs.some(ref => spawnSync("git", ["merge-base", "--is-ancestor", commit.sha, ref], { cwd: dir, stdio: "ignore", timeout: 8000 }).status === 0);
|
|
49
|
+
if (saved) continue;
|
|
50
|
+
const subjectCard = commit.subject.match(/#(\d+)/)?.[1];
|
|
51
|
+
const key = subjectCard || commit.sha.slice(0, 7);
|
|
52
|
+
let name = `harvest/${key}`;
|
|
53
|
+
const existing = gitOut(["rev-parse", "--verify", "--quiet", `refs/heads/${name}`], dir);
|
|
54
|
+
if (existing && existing !== commit.sha) name = `harvest/${key}-${commit.sha.slice(0, 7)}`;
|
|
55
|
+
const save = spawnSync("git", ["update-ref", `refs/heads/${name}`, commit.sha], { cwd: dir, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: 8000 });
|
|
56
|
+
if (save.status !== 0) return { ok: false, reason: `could not park ${commit.sha.slice(0, 7)} at ${name}: ${String(save.stderr || "git update-ref failed").trim()}` };
|
|
57
|
+
parked.push(name);
|
|
44
58
|
}
|
|
45
59
|
const reset = spawnSync("git", ["reset", "--hard", base], { cwd: dir, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: 15000 });
|
|
46
60
|
if (reset.status !== 0) return { ok: false, reason: `could not align to ${base}: ${String(reset.stderr || reset.stdout || "git reset failed").trim()}` };
|
|
47
|
-
|
|
61
|
+
const uniqueParked = [...new Set(parked)];
|
|
62
|
+
if (uniqueParked.length) log(`saved unharvested commits at ${uniqueParked.join(", ")}`);
|
|
63
|
+
return { ok: true, to: gitOut(["rev-parse", "HEAD"], dir), parked: uniqueParked.join(", ") };
|
|
48
64
|
}
|
|
49
65
|
|
|
50
66
|
// Returns { dir, created }: dir is the seat worktree, or sourceDir when no worktree applies
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const AXE_VERSION = "2.1.1";
|
|
2
|
+
|
|
3
|
+
export function axeDoctorStatus(platform, present, version = "") {
|
|
4
|
+
if (platform !== "darwin") return { kind: "note", message: "AXe version check applies on macOS hosts with iOS Simulator." };
|
|
5
|
+
if (!present) return { kind: "warn", message: "AXe missing; install pinned v2.1.1 with the Trantor installer." };
|
|
6
|
+
const found = String(version).trim().replace(/^v/, "");
|
|
7
|
+
if (!found) return { kind: "warn", message: `AXe is present, but its version could not be read; Trantor pins v${AXE_VERSION}.` };
|
|
8
|
+
if (found === AXE_VERSION) return { kind: "ok", message: `AXe v${found} installed (Trantor pin).` };
|
|
9
|
+
return { kind: "warn", message: `AXe v${found} installed; Trantor pins v${AXE_VERSION}.` };
|
|
10
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { parse } from "yaml";
|
|
4
|
+
|
|
5
|
+
function majorMinor(version, source) {
|
|
6
|
+
const match = /^(\d+)\.(\d+)(?:\.|$)/.exec(version);
|
|
7
|
+
if (!match) throw new Error(`${source}: cannot read resolved version ${JSON.stringify(version)}`);
|
|
8
|
+
return `${match[1]}.${match[2]}`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function cargoLockVersions(lockfile) {
|
|
12
|
+
const versions = new Map();
|
|
13
|
+
for (const block of lockfile.split("[[package]]").slice(1)) {
|
|
14
|
+
const name = /^name = "([^"]+)"$/m.exec(block)?.[1];
|
|
15
|
+
const version = /^version = "([^"]+)"$/m.exec(block)?.[1];
|
|
16
|
+
if (!name || !version) continue;
|
|
17
|
+
if (!versions.has(name)) versions.set(name, new Set());
|
|
18
|
+
versions.get(name).add(version);
|
|
19
|
+
}
|
|
20
|
+
return versions;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function npmLockVersion(lockfile, packageName) {
|
|
24
|
+
const importer = lockfile.importers?.["."];
|
|
25
|
+
for (const section of ["dependencies", "devDependencies"]) {
|
|
26
|
+
const version = importer?.[section]?.[packageName]?.version;
|
|
27
|
+
if (version) return version.split("(")[0];
|
|
28
|
+
}
|
|
29
|
+
throw new Error(`desktop/pnpm-lock.yaml: no resolved version for ${packageName}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function checkTauriVersionParity(desktopDir) {
|
|
33
|
+
const manifest = readFileSync(join(desktopDir, "src-tauri", "Cargo.toml"), "utf8");
|
|
34
|
+
const packageJson = JSON.parse(readFileSync(join(desktopDir, "package.json"), "utf8"));
|
|
35
|
+
const cargoLock = cargoLockVersions(readFileSync(join(desktopDir, "src-tauri", "Cargo.lock"), "utf8"));
|
|
36
|
+
const pnpmLock = parse(readFileSync(join(desktopDir, "pnpm-lock.yaml"), "utf8"));
|
|
37
|
+
const npmPackages = { ...packageJson.devDependencies, ...packageJson.dependencies };
|
|
38
|
+
const crateNames = [...manifest.matchAll(/^(tauri|tauri-plugin-[a-z0-9-]+)\s*=/gm)].map(match => match[1]);
|
|
39
|
+
const pairs = [];
|
|
40
|
+
|
|
41
|
+
for (const crateName of new Set(crateNames)) {
|
|
42
|
+
const npmPackage = crateName === "tauri" ? "@tauri-apps/api" : `@tauri-apps/${crateName.slice("tauri-".length)}`;
|
|
43
|
+
if (!npmPackages[npmPackage]) continue;
|
|
44
|
+
const resolvedCargo = [...(cargoLock.get(crateName) || [])];
|
|
45
|
+
if (resolvedCargo.length !== 1) {
|
|
46
|
+
throw new Error(`desktop/src-tauri/Cargo.lock: expected one resolved ${crateName}, found ${resolvedCargo.length}`);
|
|
47
|
+
}
|
|
48
|
+
const cargoVersion = resolvedCargo[0];
|
|
49
|
+
const npmVersion = npmLockVersion(pnpmLock, npmPackage);
|
|
50
|
+
pairs.push({
|
|
51
|
+
crateName,
|
|
52
|
+
npmPackage,
|
|
53
|
+
cargoVersion,
|
|
54
|
+
npmVersion,
|
|
55
|
+
matches: majorMinor(cargoVersion, "desktop/src-tauri/Cargo.lock") === majorMinor(npmVersion, "desktop/pnpm-lock.yaml"),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return pairs;
|
|
59
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: trantor-sim
|
|
3
|
+
description: Drive the iOS Simulator on a Mac through Trantor's guarded AXe wrapper for companion app drills and screenshot evidence.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Trantor iOS Simulator
|
|
7
|
+
|
|
8
|
+
Use this skill when an iOS task needs a live simulator. The stable interface is `trantor sim`; do not call raw `xcrun simctl` or `axe` for interactive actions. The wrapper tracks the simulator owned by this session, refuses a conflicting booted simulator, and prints JSON results.
|
|
9
|
+
|
|
10
|
+
This requires a Mac with Xcode and an available iOS Simulator runtime. It cannot drive an iOS Simulator from Linux. If AXe is missing, install the pinned release from the Trantor repository root:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
bash bin/install-axe.sh
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The installer downloads AXe v2.1.1 from its official GitHub release and checks the published SHA-256 before extracting it. Ensure `$HOME/.local/bin` is on `PATH`; `trantor doctor` reports whether the pinned version is present.
|
|
17
|
+
|
|
18
|
+
## Run a drill
|
|
19
|
+
|
|
20
|
+
1. Build the iOS app using the task's requested drill and retain the built `.app` path.
|
|
21
|
+
2. Boot one simulator by its exact name or UDID. If another simulator is already booted, stop and coordinate; do not shut down a simulator you did not start.
|
|
22
|
+
3. Install and launch the app, then inspect the screen and accessibility elements.
|
|
23
|
+
4. Interact using an element label/identifier when available. Use point coordinates from the `screen` output only when no stable element selector exists. `screen` writes a PNG under `.agent-bus-out/sim/` and returns its path plus screen-scaled accessibility elements.
|
|
24
|
+
5. Open/read the returned PNG as visual evidence. Capture a new screen after each meaningful action and record screenshots and the observed result in the drill report.
|
|
25
|
+
6. Always call `trantor sim shutdown` in a `finally`/cleanup step, including after a failed build or interaction. Verify the JSON result says `shutdown: true` or the session owns no simulator.
|
|
26
|
+
|
|
27
|
+
Example:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
trantor sim boot "iPhone 17 Pro"
|
|
31
|
+
trantor sim install .agent-bus-out/ios/Trantor.app
|
|
32
|
+
trantor sim launch ai.trantor.companion
|
|
33
|
+
trantor sim screen
|
|
34
|
+
trantor sim tap --label "Continue"
|
|
35
|
+
trantor sim screen
|
|
36
|
+
trantor sim shutdown
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Commands:
|
|
40
|
+
|
|
41
|
+
```text
|
|
42
|
+
trantor sim boot <device-name-or-udid>
|
|
43
|
+
trantor sim install <app-path>
|
|
44
|
+
trantor sim launch <bundle-id>
|
|
45
|
+
trantor sim screen [--out <png-path>]
|
|
46
|
+
trantor sim tap --label <text> | --id <identifier> | --xy x,y
|
|
47
|
+
trantor sim swipe --from x,y --to x,y
|
|
48
|
+
trantor sim type <text>
|
|
49
|
+
trantor sim shutdown
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Coordinates are logical points, matching the screenshot dimensions and AXe frames. `shutdown` is safe and idempotent: it shuts down only the simulator registered to the current session. Do not replace it with `xcrun simctl shutdown all`.
|
|
53
|
+
|
|
54
|
+
The wrapper owns local simulator exploration; existing `ios/` build and XCTest drills remain the required deterministic test gate. Turn confirmed exploratory findings into a focused regression test when practical.
|