trantor 0.18.135 → 0.18.138
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/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +1 -0
- package/bin/app.mjs +5 -10
- package/bin/crew-runner.mjs +12 -10
- package/kimi.plugin.json +1 -1
- package/lib/app-release.mjs +30 -0
- package/lib/browser-client.mjs +117 -0
- package/lib/turn-policy.mjs +20 -0
- package/mcp.mjs +84 -3
- package/package.json +1 -1
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
},
|
|
7
7
|
"metadata": {
|
|
8
8
|
"description": "Trantor — the hub-world for AI agent crews: live message bus, presence, project Kanban/flow board + context-handoff for independent AI coding agents (Claude, Codex, Gemini, …)",
|
|
9
|
-
"version": "0.18.
|
|
9
|
+
"version": "0.18.138"
|
|
10
10
|
},
|
|
11
11
|
"plugins": [
|
|
12
12
|
{
|
|
13
13
|
"name": "trantor",
|
|
14
14
|
"source": "./",
|
|
15
15
|
"description": "The hub-world for AI agent crews. Say \"fire up the crew\" and Claude becomes the architect: a plan-aware Advisor routes the work (solo / cheap inline calls / live crew of Codex, GLM, Kimi & DeepSeek in their own terminal windows), a Kanban/flow command center with a testing gate tracks it, and an economics brain (Scrooge) keeps the receipts. Includes the relay MCP, a SessionStart auto-discovery hook, and a PreCompact context-handoff so a fresh session can take over a full window instead of compacting.",
|
|
16
|
-
"version": "0.18.
|
|
16
|
+
"version": "0.18.138",
|
|
17
17
|
"author": {
|
|
18
18
|
"name": "Sasha Bogojevic"
|
|
19
19
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trantor",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.138",
|
|
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
|
@@ -415,6 +415,7 @@ rate, not work rate.
|
|
|
415
415
|
| `relay_scrooge(prompt, task?, difficulty?)` | Fractal cheap-model delegation, with the ledger receipt |
|
|
416
416
|
| `relay_lesson(text, scope?)` | Record a failure lesson — auto-injected into all future crews |
|
|
417
417
|
| `relay_handoff(summary)` | Full-window session succession |
|
|
418
|
+
| `browser_open` / `browser_read` / `browser_click` / `browser_type` / `browser_scroll` / `browser_screenshot` / `browser_resize` / `browser_pages` / `browser_back` / `browser_forward` | Drive the project's browser tab in the Trantor desktop app on the same Mac: open a page, read its text and element refs, act on refs, screenshot, emulate a device. Waits while the operator holds the browser or approves a new site; says so when the desktop app is not open |
|
|
418
419
|
|
|
419
420
|
## The CLI
|
|
420
421
|
|
package/bin/app.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import { pipeline } from "node:stream/promises";
|
|
|
13
13
|
import { join } from "node:path";
|
|
14
14
|
import { tmpdir } from "node:os";
|
|
15
15
|
import { cleanLaunchEnv } from "../lib/launch-env.mjs";
|
|
16
|
+
import { newestDmgRelease } from "../lib/app-release.mjs";
|
|
16
17
|
|
|
17
18
|
const REPO = "sashabogi/trantor";
|
|
18
19
|
const APP = "/Applications/Trantor.app";
|
|
@@ -69,16 +70,10 @@ async function latestAppRelease() {
|
|
|
69
70
|
if (process.env.GITHUB_TOKEN) headers.authorization = `Bearer ${process.env.GITHUB_TOKEN}`;
|
|
70
71
|
const r = await fetch(`https://api.github.com/repos/${REPO}/releases?per_page=30`, { headers, signal: AbortSignal.timeout(15000) });
|
|
71
72
|
if (!r.ok) throw new Error(`GitHub API ${r.status} — ${(await r.text()).slice(0, 200)}`);
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const asset = assets.find(a => a.name.includes(`_${ARCH_TAG}`)) || assets[0];
|
|
77
|
-
if (!asset.name.includes(`_${ARCH_TAG}`)) console.error(`⚠ no ${ARCH_TAG} build in ${rel.tag_name} — using ${asset.name} (may not run on this Mac)`);
|
|
78
|
-
const version = (asset.name.match(/[_-]([0-9]+(?:\.[0-9]+)*)[_-]/) || [])[1] || rel.tag_name.replace(/^app-v?|^v/, "");
|
|
79
|
-
return { tag: rel.tag_name, version, asset };
|
|
80
|
-
}
|
|
81
|
-
throw new Error("no release with a Trantor DMG asset found");
|
|
73
|
+
const best = newestDmgRelease(await r.json(), ARCH_TAG);
|
|
74
|
+
if (!best) throw new Error("no release with a Trantor DMG asset found");
|
|
75
|
+
if (!best.asset.name.includes(`_${ARCH_TAG}`)) console.error(`⚠ no ${ARCH_TAG} build in ${best.tag} — using ${best.asset.name} (may not run on this Mac)`);
|
|
76
|
+
return best;
|
|
82
77
|
}
|
|
83
78
|
|
|
84
79
|
const rel = await latestAppRelease().catch(e => { console.error(`trantor app: ${e.message}`); process.exit(1); });
|
package/bin/crew-runner.mjs
CHANGED
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
cardRefs, servedContractCard, carriesWork, parseTurnTokens, parseResetAt, reasonWithBalances, quotaResetAt, queuedWording, turnDelivered, budgetPause, PARKING_REASONS,
|
|
32
32
|
senderProjectOf, isLinkedProject, stateSkipReason, isMessageCardTitle, OPEN_CARD_STATUSES,
|
|
33
33
|
ownCardForInstance, contractedCardIds,
|
|
34
|
-
shouldAlignForContract,
|
|
34
|
+
shouldAlignForContract, hasContractText, completedCardIds, owesReadContract,
|
|
35
35
|
CUT_CHAIN_PARK_MIN, cutChainEvidence, isBoundedPark, askDuringTurn, askedVerdict,
|
|
36
36
|
} from "../lib/turn-policy.mjs";
|
|
37
37
|
import { snapshotBeforeCut } from "./cut-snapshot.mjs";
|
|
@@ -417,10 +417,8 @@ async function janitorStop(why, card) {
|
|
|
417
417
|
log(text);
|
|
418
418
|
await api("/send", { from: SESSION, to: "all", text, project: PROJ, kind: "status" }).catch(() => {});
|
|
419
419
|
}
|
|
420
|
-
//
|
|
421
|
-
//
|
|
422
|
-
// and persisted in the pending file, so a message the session read mid-turn is never re-woken by
|
|
423
|
-
// the poll, across turn AND process boundaries.
|
|
420
|
+
// Inbox reads dedupe context across turn boundaries; #14520 contracts still need a matching outcome.
|
|
421
|
+
// Persist that turn's completed cards with its read ids so later outcomes cannot consume old work.
|
|
424
422
|
let seenLedger = [];
|
|
425
423
|
// A cap, so a long outage cannot grow the queue without bound. Overflow drops the OLDEST and says
|
|
426
424
|
// so on the bus — a silent drop is the exact failure this whole mechanism exists to end.
|
|
@@ -474,7 +472,7 @@ function loadPending() {
|
|
|
474
472
|
wake: Array.isArray(j.wake) ? j.wake : [],
|
|
475
473
|
bcast: Array.isArray(j.bcast) ? j.bcast : [],
|
|
476
474
|
seen: Array.isArray(j.seen)
|
|
477
|
-
? j.seen.filter(e => e && Number.isFinite(Number(e.id))).map(e => ({ id: Number(e.id), ts: Number(e.ts) || 0 }))
|
|
475
|
+
? j.seen.filter(e => e && Number.isFinite(Number(e.id))).map(e => ({ id: Number(e.id), ts: Number(e.ts) || 0, completedCards: e.completedCards || [] }))
|
|
478
476
|
: [],
|
|
479
477
|
ask: Number(j.ask) || 0, askTo: String(j.askTo || ""),
|
|
480
478
|
};
|
|
@@ -1498,7 +1496,7 @@ function isReceipt(message) {
|
|
|
1498
1496
|
// contract riding `re` must wake. A reply is a receipt only when it threads an outcome THIS seat
|
|
1499
1497
|
// sent and its own text carries no work (an ack/closure, #7079).
|
|
1500
1498
|
if (!(Number(message?.re) > 0)) return false;
|
|
1501
|
-
return sentOutcomes.has(Number(message.re)) && !carriesWork(text) && !isContract(message);
|
|
1499
|
+
return sentOutcomes.has(Number(message.re)) && !carriesWork(text) && !isContract(message) && !hasContractText(text);
|
|
1502
1500
|
}
|
|
1503
1501
|
|
|
1504
1502
|
function isStatusBroadcast(message) {
|
|
@@ -1780,7 +1778,10 @@ async function resolveWakeCard(messages, { session }) {
|
|
|
1780
1778
|
// not the shared ledger, so the second reader stands down here and the cursor adopts the consumed
|
|
1781
1779
|
// ids. Filtering BEFORE the wake/bcast split keeps a dupe out of #7766's demoted-sender notice.
|
|
1782
1780
|
if (seenLedger.length) {
|
|
1783
|
-
const seenIds = new Set(
|
|
1781
|
+
const seenIds = new Set(msgs.filter(m => {
|
|
1782
|
+
const entry = seenLedger.find(e => e.id === m.id);
|
|
1783
|
+
return entry && !owesReadContract(m, SESSION, entry.completedCards);
|
|
1784
|
+
}).map(m => m.id));
|
|
1784
1785
|
const dupes = msgs.filter(m => seenIds.has(m.id));
|
|
1785
1786
|
if (dupes.length) {
|
|
1786
1787
|
log(`duplicate delivery suppressed — ${dupes.map(m => `#${m.id}`).join(", ")} already consumed by the session's own inbox read`);
|
|
@@ -1886,12 +1887,13 @@ async function resolveWakeCard(messages, { session }) {
|
|
|
1886
1887
|
// A delta wider than one turn could plausibly carry is a corrupt or rewound ledger: mark
|
|
1887
1888
|
// nothing. Non-marking only risks the duplicate this fixes, never a lost message.
|
|
1888
1889
|
if (!(readUpTo > upToCursor) || readUpTo - upToCursor > 10000) return 0;
|
|
1889
|
-
|
|
1890
|
+
const turnCompletedCards = completedCardIds(lastErrText);
|
|
1891
|
+
for (let id = upToCursor + 1; id <= readUpTo; id++) seenLedger.push({ id, ts: Date.now(), completedCards: turnCompletedCards });
|
|
1890
1892
|
seenLedger = seenLedger.filter(e => e.id > upToCursor).slice(-500);
|
|
1891
1893
|
// persist HERE, at every caller: a runner killed seconds after the boundary is exactly the
|
|
1892
1894
|
// restart the restored seen-set exists for.
|
|
1893
1895
|
savePending(pendingWake, pendingBcast);
|
|
1894
|
-
log(`dedupe: message id(s) ${upToCursor + 1}..${readUpTo} were
|
|
1896
|
+
log(`dedupe: message id(s) ${upToCursor + 1}..${readUpTo} were read by the session — context dedupes; contracts require a matching done/testing outcome`);
|
|
1895
1897
|
return readUpTo - upToCursor;
|
|
1896
1898
|
} catch { return 0; }
|
|
1897
1899
|
}
|
package/kimi.plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trantor",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.138",
|
|
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). This manifest makes Kimi Code CLI a first-class ORCHESTRATOR, mirroring .claude-plugin/plugin.json. Hooks are the CANONICAL hooks/** executed through the kimi dialect bridge (kimi/bridge.mjs) — docs/KIMI-BRIDGE-CONTRACT.md.",
|
|
5
5
|
"interface": {
|
|
6
6
|
"displayName": "Trantor",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// trantor — which GitHub release is the newest Trantor app. Mirrors newest_dmg_release in
|
|
2
|
+
// desktop/src-tauri/src/update.rs: change both or neither.
|
|
3
|
+
|
|
4
|
+
// "2.1.10" > "2.1.9": numeric per part, never a string compare.
|
|
5
|
+
export function versionNewer(latest, current) {
|
|
6
|
+
const parse = (s) => String(s).trim().replace(/^v/, "").split(".").map(p => parseInt(p, 10) || 0);
|
|
7
|
+
const [l, c] = [parse(latest), parse(current)];
|
|
8
|
+
for (let i = 0; i < Math.max(l.length, c.length); i++) {
|
|
9
|
+
const a = l[i] ?? 0, b = c[i] ?? 0;
|
|
10
|
+
if (a !== b) return a > b;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// The highest-versioned release carrying a Trantor DMG, preferring this arch's build. GitHub's list
|
|
16
|
+
// is NOT in version order: it sorts tag names as text, so app-v2.1.10 came back after app-v2.1.2 and
|
|
17
|
+
// taking the first entry told a 2.1.9 install it was current (2026-11-26).
|
|
18
|
+
export function newestDmgRelease(releases, archTag) {
|
|
19
|
+
const isDmg = a => /^Trantor[_-].*\.dmg$/.test(a?.name || "");
|
|
20
|
+
let best = null;
|
|
21
|
+
for (const rel of Array.isArray(releases) ? releases : []) {
|
|
22
|
+
if (rel?.draft) continue;
|
|
23
|
+
const assets = (rel.assets || []).filter(isDmg);
|
|
24
|
+
if (!assets.length) continue;
|
|
25
|
+
const asset = assets.find(a => a.name.includes(`_${archTag}`)) || assets[0];
|
|
26
|
+
const version = (asset.name.match(/[_-]([0-9]+(?:\.[0-9]+)*)[_-]/) || [])[1] || String(rel.tag_name || "").replace(/^app-v?|^v/, "");
|
|
27
|
+
if (!best || versionNewer(version, best.version)) best = { tag: rel.tag_name, version, asset };
|
|
28
|
+
}
|
|
29
|
+
return best;
|
|
30
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { connect } from "node:net";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
6
|
+
|
|
7
|
+
export class BrowserError extends Error {
|
|
8
|
+
constructor(code, message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.code = code;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
class SocketTimeout extends BrowserError {
|
|
15
|
+
constructor(op) {
|
|
16
|
+
super("timeout", `Browser ${op} timed out`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class WaitTimeout extends BrowserError {}
|
|
21
|
+
|
|
22
|
+
const waiting = new Set(["held_by_user", "waiting_for_approval"]);
|
|
23
|
+
const waitReason = code => code === "held_by_user"
|
|
24
|
+
? "the operator to give back the browser"
|
|
25
|
+
: "the operator to approve browser access";
|
|
26
|
+
|
|
27
|
+
function request(socketPath, payload, timeoutMs) {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
const socket = connect(socketPath);
|
|
30
|
+
let buffer = "", settled = false;
|
|
31
|
+
const finish = (error, result) => {
|
|
32
|
+
if (settled) return;
|
|
33
|
+
settled = true;
|
|
34
|
+
clearTimeout(timer);
|
|
35
|
+
socket.destroy();
|
|
36
|
+
if (error) reject(error);
|
|
37
|
+
else resolve(result);
|
|
38
|
+
};
|
|
39
|
+
const timer = setTimeout(() => finish(new SocketTimeout(payload.op)), timeoutMs);
|
|
40
|
+
socket.setEncoding("utf8");
|
|
41
|
+
socket.on("connect", () => socket.write(JSON.stringify(payload) + "\n"));
|
|
42
|
+
socket.on("error", error => finish(["ENOENT", "ECONNREFUSED"].includes(error.code)
|
|
43
|
+
? new BrowserError("no_app", "Trantor's desktop app is not open on this machine")
|
|
44
|
+
: error));
|
|
45
|
+
socket.on("end", () => finish(new BrowserError("connection_closed", "The browser socket closed before replying")));
|
|
46
|
+
socket.on("data", chunk => {
|
|
47
|
+
buffer += chunk;
|
|
48
|
+
const newline = buffer.indexOf("\n");
|
|
49
|
+
if (newline < 0) return;
|
|
50
|
+
let response;
|
|
51
|
+
try { response = JSON.parse(buffer.slice(0, newline)); }
|
|
52
|
+
catch { finish(new BrowserError("bad_response", "The browser socket returned invalid JSON")); return; }
|
|
53
|
+
if (!response || response.id !== payload.id || ![true, false].includes(response.ok)) {
|
|
54
|
+
finish(new BrowserError("bad_response", "The browser socket returned an invalid response"));
|
|
55
|
+
} else if (!response.ok) {
|
|
56
|
+
finish(new BrowserError(response.error, response.message));
|
|
57
|
+
} else {
|
|
58
|
+
const { id, ok, ...result } = response;
|
|
59
|
+
finish(null, result);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function createBrowserClient({ session, label, project,
|
|
66
|
+
busDir = process.env.AGENT_BUS_DIR || join(homedir(), ".agent-bus"),
|
|
67
|
+
timeoutMs = 30_000, waitMs = 120_000, pollMs = 1_000,
|
|
68
|
+
}) {
|
|
69
|
+
const socketPath = join(busDir, "browser.sock");
|
|
70
|
+
const send = (op, args, limit = timeoutMs) => request(socketPath,
|
|
71
|
+
{ ...args, id: randomUUID(), session, label, project, op }, limit);
|
|
72
|
+
|
|
73
|
+
return async (op, args = {}, onWaiting = async () => {}) => {
|
|
74
|
+
let blocked;
|
|
75
|
+
try { return await send(op, args); }
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (!waiting.has(error.code)) throw error;
|
|
78
|
+
blocked = error;
|
|
79
|
+
}
|
|
80
|
+
const deadline = Date.now() + waitMs;
|
|
81
|
+
const expired = () => new WaitTimeout(blocked.code,
|
|
82
|
+
`Waited ${waitMs / 1000}s for ${waitReason(blocked.code)}. ${blocked.message}`);
|
|
83
|
+
const sendWhileWaiting = async (nextOp, nextArgs) => {
|
|
84
|
+
const remaining = deadline - Date.now();
|
|
85
|
+
if (remaining <= 0) throw expired();
|
|
86
|
+
try { return await send(nextOp, nextArgs, Math.min(timeoutMs, remaining)); }
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (error instanceof SocketTimeout && remaining <= timeoutMs) throw expired();
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
await onWaiting(`Waiting for ${waitReason(blocked.code)}. ${blocked.message}`);
|
|
93
|
+
while (Date.now() < deadline) {
|
|
94
|
+
await sleep(Math.min(pollMs, deadline - Date.now()));
|
|
95
|
+
if (Date.now() >= deadline) break;
|
|
96
|
+
try {
|
|
97
|
+
const stateArgs = args.page === undefined ? {} : { page: args.page };
|
|
98
|
+
const state = await sendWhileWaiting("state", stateArgs);
|
|
99
|
+
if (state.held_by_user) {
|
|
100
|
+
if (blocked.code !== "held_by_user") {
|
|
101
|
+
blocked = new BrowserError("held_by_user", "The operator has taken over the browser");
|
|
102
|
+
await onWaiting(`Waiting for ${waitReason(blocked.code)}. ${blocked.message}`);
|
|
103
|
+
}
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (Date.now() >= deadline) break;
|
|
107
|
+
// Approval is not in BrowserState; retrying the op observes the operator's answer.
|
|
108
|
+
return await sendWhileWaiting(op, args);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if (error instanceof WaitTimeout || !waiting.has(error.code)) throw error;
|
|
111
|
+
if (blocked.code !== error.code) await onWaiting(`Waiting for ${waitReason(error.code)}. ${error.message}`);
|
|
112
|
+
blocked = error;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
throw expired();
|
|
116
|
+
};
|
|
117
|
+
}
|
package/lib/turn-policy.mjs
CHANGED
|
@@ -383,3 +383,23 @@ export function askedVerdict(ask) {
|
|
|
383
383
|
const firstLine = String(ask.text || "").trim().split(/\r?\n/)[0];
|
|
384
384
|
return `asked: ${firstLine.replace(/^❓\s*(?:ask(?:s)?(?: on #[0-9]+)?\s*:\s*)?/, "")}`;
|
|
385
385
|
}
|
|
386
|
+
|
|
387
|
+
// Threaded assignments can follow an answer in the same message (#14520).
|
|
388
|
+
export function hasContractText(text) {
|
|
389
|
+
return /\bcontract(?:\s*:|\s+(?:for\s+)?#\d+\b)/i.test(String(text || ""));
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// #14520: reading a contract during another turn is not delivery of that contract.
|
|
393
|
+
export function owesReadContract(message, session, completedCards = []) {
|
|
394
|
+
if (message.to !== session || message.wake === false) return false;
|
|
395
|
+
if (message.kind !== "contract" && !hasContractText(message.text)) return false;
|
|
396
|
+
const cards = cardRefs(message.text);
|
|
397
|
+
if (Number(message.card) > 0) cards.push(Number(message.card));
|
|
398
|
+
return !cards.length || cards.some(id => !completedCards.includes(id));
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// Accept explicit card outcomes, not a bare mention or a promise to finish later.
|
|
402
|
+
export function completedCardIds(text) {
|
|
403
|
+
return [...String(text || "").matchAll(/^[ \t]*(?:[-*][ \t]+)?(?:card[ \t]+)?#(\d{1,7})\b[ \t]*(?::|—|-)?[ \t]*(?:(?:is|was|moved to|moved|in|→)[ \t]+)?(done|testing)\b/gim)]
|
|
404
|
+
.map(match => Number(match[1]));
|
|
405
|
+
}
|
package/mcp.mjs
CHANGED
|
@@ -15,8 +15,10 @@ import { signedPost, signedGet } from "./hooks/lib/api.mjs";
|
|
|
15
15
|
import { anchorCursor } from "./hooks/lib/inbox-ledger.mjs";
|
|
16
16
|
import { formatInboxPage, fmtMessage } from "./hooks/lib/inbox-page.mjs";
|
|
17
17
|
import { assertNoSecrets } from "./lib/scrub.mjs";
|
|
18
|
-
import { isMessageCardTitle, OPEN_CARD_STATUSES, ownCardForInstance, contractedCardIds } from "./lib/turn-policy.mjs";
|
|
18
|
+
import { isMessageCardTitle, OPEN_CARD_STATUSES, ownCardForInstance, contractedCardIds, hasContractText } from "./lib/turn-policy.mjs";
|
|
19
19
|
import { markDoing, hollowVerdict, blastRadius, blastLine } from "./hooks/lib/hollow-move.mjs";
|
|
20
|
+
import { createBrowserClient, BrowserError } from "./lib/browser-client.mjs";
|
|
21
|
+
import { readFile } from "node:fs/promises";
|
|
20
22
|
|
|
21
23
|
import { dep } from "./lib/dep.mjs";
|
|
22
24
|
|
|
@@ -93,6 +95,81 @@ const fmt = fmtMessage;
|
|
|
93
95
|
|
|
94
96
|
const server = new McpServer({ name: "trantor", version: "0.1.0" });
|
|
95
97
|
|
|
98
|
+
const browser = createBrowserClient({ session: SESSION, project: PROJECT,
|
|
99
|
+
label: process.env.TRANTOR_ORCH === PROJECT ? "orchestrator" : SESSION.split(":")[0] });
|
|
100
|
+
const browserPage = { page: z.string().optional().describe("Page id; omit for the active page") };
|
|
101
|
+
async function browserCall(op, args, extra) {
|
|
102
|
+
try {
|
|
103
|
+
let progress = 0;
|
|
104
|
+
const result = await browser(op, args, async message => {
|
|
105
|
+
const progressToken = extra?._meta?.progressToken;
|
|
106
|
+
if (progressToken !== undefined) await extra.sendNotification({ method: "notifications/progress",
|
|
107
|
+
params: { progressToken, progress: ++progress, message } });
|
|
108
|
+
});
|
|
109
|
+
const content = [{ type: "text", text: JSON.stringify(result) }];
|
|
110
|
+
if (op === "screenshot") {
|
|
111
|
+
const png = await readFile(result.path);
|
|
112
|
+
content.push({ type: "image", mimeType: "image/png", data: png.toString("base64") });
|
|
113
|
+
}
|
|
114
|
+
return { content };
|
|
115
|
+
} catch (error) {
|
|
116
|
+
return { isError: true, content: [{ type: "text", text: error.message }],
|
|
117
|
+
structuredContent: { error: error.code || "browser_error", message: error.message } };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function browserTarget(args, coordinates = false) {
|
|
121
|
+
const count = Number(args.ref !== undefined) + Number(args.selector !== undefined)
|
|
122
|
+
+ Number(coordinates && (args.x !== undefined || args.y !== undefined));
|
|
123
|
+
if (count !== 1 || (coordinates && ((args.x === undefined) !== (args.y === undefined)))) {
|
|
124
|
+
throw new BrowserError("bad_request", coordinates
|
|
125
|
+
? "Choose exactly one target: ref, selector, or both x and y"
|
|
126
|
+
: "Choose exactly one target: ref or selector");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function invalidBrowserArgs(error) {
|
|
130
|
+
return { isError: true, content: [{ type: "text", text: error.message }],
|
|
131
|
+
structuredContent: { error: error.code, message: error.message } };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
server.tool("browser_open", "Open a URL in the project's browser. Waits for operator approval or control when needed.",
|
|
135
|
+
{ ...browserPage, url: z.string().min(1), new_page: z.boolean().optional() },
|
|
136
|
+
({ new_page, ...args }, extra) => browserCall(new_page ? "new_page" : "open", args, extra));
|
|
137
|
+
server.tool("browser_read", "Read the page text and interactive element refs. Refs last until navigation.",
|
|
138
|
+
{ ...browserPage, max_chars: z.number().int().positive().optional() },
|
|
139
|
+
(args, extra) => browserCall("read", args, extra));
|
|
140
|
+
server.tool("browser_click", "Click one element ref, CSS selector, or point (x, y).",
|
|
141
|
+
{ ...browserPage, ref: z.string().min(1).optional(), selector: z.string().min(1).optional(), x: z.number().optional(), y: z.number().optional() },
|
|
142
|
+
(args, extra) => {
|
|
143
|
+
try { browserTarget(args, true); } catch (error) { return invalidBrowserArgs(error); }
|
|
144
|
+
return browserCall("click", args, extra);
|
|
145
|
+
});
|
|
146
|
+
server.tool("browser_type", "Type text into an element ref or CSS selector, optionally submitting it.",
|
|
147
|
+
{ ...browserPage, ref: z.string().min(1).optional(), selector: z.string().min(1).optional(), text: z.string(), submit: z.boolean().optional() },
|
|
148
|
+
(args, extra) => {
|
|
149
|
+
try { browserTarget(args); } catch (error) { return invalidBrowserArgs(error); }
|
|
150
|
+
return browserCall("type", args, extra);
|
|
151
|
+
});
|
|
152
|
+
server.tool("browser_scroll", "Scroll the page vertically by dy pixels.",
|
|
153
|
+
{ ...browserPage, dy: z.number() }, (args, extra) => browserCall("scroll", args, extra));
|
|
154
|
+
server.tool("browser_screenshot", "Capture a PNG of the page or element ref; returns the image and its saved path.",
|
|
155
|
+
{ ...browserPage, ref: z.string().min(1).optional() },
|
|
156
|
+
({ ref, ...args }, extra) => browserCall("screenshot", { ...args, element: ref }, extra));
|
|
157
|
+
server.tool("browser_resize", "Emulate a device or set width and height in pixels. Omit both to reset.",
|
|
158
|
+
{ ...browserPage, device: z.enum(["iPhone 15", "iPhone SE", "Pixel 8", "iPad", "Laptop", "Desktop"]).optional(),
|
|
159
|
+
w: z.number().positive().optional(), h: z.number().positive().optional() },
|
|
160
|
+
(args, extra) => {
|
|
161
|
+
if ((args.w === undefined) !== (args.h === undefined) || (args.device !== undefined && args.w !== undefined)) {
|
|
162
|
+
return invalidBrowserArgs(new BrowserError("bad_request", "Choose device, both w and h, or no size to reset"));
|
|
163
|
+
}
|
|
164
|
+
return browserCall("resize", args, extra);
|
|
165
|
+
});
|
|
166
|
+
server.tool("browser_pages", "List the project's browser pages.", browserPage,
|
|
167
|
+
(args, extra) => browserCall("pages", args, extra));
|
|
168
|
+
server.tool("browser_back", "Go back in the browser page's history.", browserPage,
|
|
169
|
+
(args, extra) => browserCall("back", args, extra));
|
|
170
|
+
server.tool("browser_forward", "Go forward in the browser page's history.", browserPage,
|
|
171
|
+
(args, extra) => browserCall("forward", args, extra));
|
|
172
|
+
|
|
96
173
|
server.tool("relay_whoami", "Show this session's relay identity, project, hub URL, HOW that hub was chosen, and whether this session is actually a registered seat.", {}, async () => {
|
|
97
174
|
// A diagnostic must observe, never mutate: this tool used to POST /register before answering, so
|
|
98
175
|
// asking "where am I?" from a non-project directory CREATED the phantom seat it then reported,
|
|
@@ -443,7 +520,7 @@ server.tool("relay_peers", "Find who you can talk to: the live agent sessions on
|
|
|
443
520
|
|
|
444
521
|
server.tool("relay_send", "Send a live message to another agent session (or 'all'). Message the agent yourself; never ask the human to relay. Ids: relay_peers. Cross-project sends are a breach unless the operator linked the projects (`trantor policy link <a> <b> --reason \"<why>\"`); the hub answers 403 for an unlinked project.",
|
|
445
522
|
{ to: z.string(), text: z.string(),
|
|
446
|
-
wake: z.boolean().optional().describe("false = context, not a contract: batches into the target's next turn. Unset or true, a direct message
|
|
523
|
+
wake: z.boolean().optional().describe("false = context, not a contract: batches into the target's next turn. Unset or true, a direct message earns a turn; a reply that only acknowledges the seat's own report does not, unless its text carries Contract #<id> or contract:. Set false on every ack, FYI and queue note."),
|
|
447
524
|
re: z.number().optional().describe("message id you are answering; set it on every reply. Without it the hub matches your reply to the peer's OLDEST outstanding contract, closing the wrong one.") },
|
|
448
525
|
async ({ to, text, wake, re }) => {
|
|
449
526
|
// The event log is append-only — a secret in it is unrecoverable, so refuse BEFORE
|
|
@@ -465,7 +542,11 @@ server.tool("relay_send", "Send a live message to another agent session (or 'all
|
|
|
465
542
|
throw error;
|
|
466
543
|
}
|
|
467
544
|
const { id } = sent;
|
|
468
|
-
|
|
545
|
+
const delivery = wake === false ? " (batched — no turn)"
|
|
546
|
+
: Number(re) > 0 && to !== "all"
|
|
547
|
+
? hasContractText(text) ? " (contract reply — will wake the seat)" : " (reply — wakes the seat unless it only acknowledges the seat's own report)"
|
|
548
|
+
: "";
|
|
549
|
+
return { content: [{ type: "text", text: `sent #${id} to ${to}${delivery}` }] };
|
|
469
550
|
});
|
|
470
551
|
|
|
471
552
|
server.tool("relay_ask", "Ask a blocking question on your card without forfeiting the contract. Use it when the contract omits a fact you cannot proceed without; never invent the value. Sends a kind:ask to the card's assigner, blocks the card with your question as its note, and the answer resumes this session with the original contract re-attached. End your turn right after calling it.",
|