trantor 0.18.133 → 0.18.135
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 +10 -3
- package/bin/adopt.mjs +2 -2
- package/bin/cli.mjs +42 -0
- package/bin/connect.mjs +14 -1
- package/bin/crew/models.mjs +4 -1
- package/bin/crew/open.mjs +18 -8
- package/bin/crew/worktrees.mjs +3 -3
- package/bin/crew-runner.mjs +22 -7
- package/bin/crew.mjs +7 -2
- package/bin/doctor.mjs +14 -3
- package/bin/helper.mjs +119 -0
- package/bin/herdr-agent.mjs +67 -13
- package/bin/new.mjs +2 -2
- package/bin/seats.mjs +3 -2
- package/bin/slop-gate.mjs +1 -1
- package/bin/takeover.mjs +2 -2
- package/bin/turn-watchdog.mjs +2 -1
- package/deploy/node-path.sh +18 -0
- package/deploy/setup.sh +11 -3
- package/engine/bin/scrooge +9 -0
- package/hooks/lib/handoff.mjs +10 -3
- package/hooks/lib/start-gates.mjs +18 -0
- package/hooks/precompact.mjs +6 -2
- package/hooks/sessionstart.mjs +11 -6
- package/hub/routes/insights.mjs +77 -30
- package/hub/routes/messages.mjs +2 -1
- package/hub/store.mjs +140 -2
- package/kimi/bin/baton-close.mjs +108 -0
- package/kimi/bin/lib/handoff.mjs +119 -0
- package/kimi/bin/write-handoff.mjs +31 -0
- package/kimi/bridge.mjs +219 -0
- package/kimi/skills/crew/SKILL.md +119 -0
- package/kimi/skills/handoff/SKILL.md +44 -0
- package/kimi/skills/research/SKILL.md +49 -0
- package/kimi.plugin.json +66 -0
- package/lib/agent-preferences.mjs +15 -0
- package/lib/balances.mjs +6 -1
- package/lib/enroll.mjs +20 -2
- package/lib/jsonc.mjs +37 -0
- package/lib/project.mjs +21 -2
- package/lib/seat-compaction.mjs +26 -4
- package/lib/store-pg.mjs +64 -0
- package/lib/telemetry-ship.mjs +193 -0
- package/package.json +3 -1
package/bin/herdr-agent.mjs
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Keep herdr
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// window never costs you a session. A REBOOT does: the server dies with everything else, and
|
|
6
|
-
// nothing brings it back, so the next `trantor open` finds no workspace and starts over. That was
|
|
7
|
-
// the missing half of "it survives restarts" (card #5401).
|
|
8
|
-
//
|
|
9
|
-
// This is only the SERVER's lifetime. The conversation inside a pane is a separate problem, solved
|
|
10
|
-
// in crew.mjs: the project keeps one claude session id and `open` resumes it.
|
|
11
|
-
import { existsSync, writeFileSync, unlinkSync, mkdirSync } from "node:fs";
|
|
2
|
+
// Keep herdr alive across reboot; Trantor restores opted-in orchestrators after its server returns.
|
|
3
|
+
// Server lifetime and conversation restore are separate: `trantor open` resumes the project session.
|
|
4
|
+
import { existsSync, writeFileSync, unlinkSync, mkdirSync, chmodSync, readFileSync } from "node:fs";
|
|
12
5
|
import { execFileSync } from "node:child_process";
|
|
13
6
|
import { homedir } from "node:os";
|
|
14
7
|
import { join, dirname } from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
15
9
|
|
|
16
10
|
const LABEL = "com.trantor.herdr";
|
|
17
11
|
const PLIST = join(homedir(), "Library", "LaunchAgents", `${LABEL}.plist`);
|
|
18
12
|
const LOG = "/tmp/trantor-herdr-server.log";
|
|
13
|
+
const RESTORE_LOG = "/tmp/trantor-herdr-restore.log";
|
|
14
|
+
const RESTORE_SCRIPT = join(homedir(), "Library", "LaunchAgents", "trantor-herdr-restore.sh");
|
|
19
15
|
const D = "\x1b[2m", R = "\x1b[0m";
|
|
20
16
|
|
|
17
|
+
const shellQuote = value => `'${String(value).replaceAll("'", `'\\''`)}'`;
|
|
18
|
+
const xmlEscape = value => String(value).replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
19
|
+
|
|
21
20
|
function herdrBin() {
|
|
22
21
|
// launchd runs with a minimal PATH, so the absolute path has to be baked in at install time.
|
|
23
22
|
for (const p of [join(homedir(), ".local/bin/herdr"), "/opt/homebrew/bin/herdr", "/usr/local/bin/herdr"]) {
|
|
@@ -30,7 +29,46 @@ function herdrBin() {
|
|
|
30
29
|
return "";
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
|
|
32
|
+
export function restoreScriptBody({ herdr = "herdr", node = process.execPath, cli = join(dirname(fileURLToPath(import.meta.url)), "cli.mjs"), log = RESTORE_LOG } = {}) {
|
|
33
|
+
return `#!/bin/bash
|
|
34
|
+
HERDR_BIN=\${TRANTOR_HERDR_BIN:-${shellQuote(herdr)}}
|
|
35
|
+
NODE_BIN=\${TRANTOR_NODE_BIN:-${shellQuote(node)}}
|
|
36
|
+
TRANTOR_CLI=\${TRANTOR_CLI_PATH:-${shellQuote(cli)}}
|
|
37
|
+
RESTORE_LOG=\${TRANTOR_RESTORE_LOG:-${shellQuote(log)}}
|
|
38
|
+
MARKER_DIR=\${TRANTOR_RESTORE_MARKER_DIR:-/tmp}
|
|
39
|
+
BOOT_KEY=\${TRANTOR_RESTORE_BOOT_KEY:-$(/usr/sbin/sysctl -n kern.boottime 2>/dev/null | sed -E 's/.*sec = ([0-9]+).*/\\1/')}
|
|
40
|
+
WAIT_SECONDS=\${TRANTOR_RESTORE_WAIT_SECONDS:-60}
|
|
41
|
+
SLEEP_SECONDS=\${TRANTOR_RESTORE_SLEEP_SECONDS:-1}
|
|
42
|
+
|
|
43
|
+
if [[ ! "$BOOT_KEY" =~ ^[0-9]+$ ]]; then
|
|
44
|
+
echo "$(date -u '+%FT%TZ') herdr restore skipped: could not determine boot time" >> "$RESTORE_LOG"
|
|
45
|
+
exit 0
|
|
46
|
+
fi
|
|
47
|
+
MARKER="$MARKER_DIR/trantor-herdr-restore-$BOOT_KEY.done"
|
|
48
|
+
if [ -d "$MARKER" ]; then exit 0; fi
|
|
49
|
+
|
|
50
|
+
elapsed=0
|
|
51
|
+
while [ "$elapsed" -lt "$WAIT_SECONDS" ]; do
|
|
52
|
+
if "$HERDR_BIN" status 2>/dev/null | grep -q 'status: running'; then
|
|
53
|
+
if mkdir "$MARKER" 2>/dev/null; then
|
|
54
|
+
echo "$(date -u '+%FT%TZ') herdr is running; restoring opted-in Trantor orchestrators" >> "$RESTORE_LOG"
|
|
55
|
+
"$NODE_BIN" "$TRANTOR_CLI" restore >> "$RESTORE_LOG" 2>&1
|
|
56
|
+
result=$?
|
|
57
|
+
echo "$(date -u '+%FT%TZ') trantor restore exited $result" >> "$RESTORE_LOG"
|
|
58
|
+
fi
|
|
59
|
+
exit 0
|
|
60
|
+
fi
|
|
61
|
+
sleep "$SLEEP_SECONDS"
|
|
62
|
+
elapsed=$((elapsed + 1))
|
|
63
|
+
done
|
|
64
|
+
echo "$(date -u '+%FT%TZ') herdr did not answer status within $WAIT_SECONDS seconds; restore skipped" >> "$RESTORE_LOG"
|
|
65
|
+
exit 0
|
|
66
|
+
`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function plistBody(bin, restoreScript = RESTORE_SCRIPT) {
|
|
70
|
+
const launch = xmlEscape(`/bin/bash ${shellQuote(restoreScript)} >/dev/null 2>&1 & ${shellQuote(bin)} status 2>/dev/null | grep -q 'status: running' && exit 0; exec ${shellQuote(bin)} server`);
|
|
71
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
34
72
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
35
73
|
<plist version="1.0">
|
|
36
74
|
<dict>
|
|
@@ -42,7 +80,7 @@ const plistBody = (bin) => `<?xml version="1.0" encoding="UTF-8"?>
|
|
|
42
80
|
<!-- Idempotent on purpose. A second herdr server against a live one prints "already running"
|
|
43
81
|
and exits 1, so a plain KeepAlive would respawn it every 10s forever. Bail out cleanly
|
|
44
82
|
instead, and only exec when nothing is holding the socket. -->
|
|
45
|
-
<string>${
|
|
83
|
+
<string>${launch}</string>
|
|
46
84
|
</array>
|
|
47
85
|
<key>RunAtLoad</key><true/>
|
|
48
86
|
<!-- Restart a server that DIED, never one that stopped cleanly (herdr server stop) or one that
|
|
@@ -53,7 +91,15 @@ const plistBody = (bin) => `<?xml version="1.0" encoding="UTF-8"?>
|
|
|
53
91
|
</dict>
|
|
54
92
|
</plist>
|
|
55
93
|
`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function restoreWired(plist, script) {
|
|
97
|
+
return String(plist || "").includes("trantor-herdr-restore.sh")
|
|
98
|
+
&& String(script || "").includes("restore >> \"$RESTORE_LOG\"")
|
|
99
|
+
&& String(script || "").includes("trantor-herdr-restore-$BOOT_KEY.done");
|
|
100
|
+
}
|
|
56
101
|
|
|
102
|
+
function main() {
|
|
57
103
|
const cmd = process.argv[2] || "status";
|
|
58
104
|
const uid = process.getuid();
|
|
59
105
|
|
|
@@ -64,6 +110,8 @@ if (cmd === "install") {
|
|
|
64
110
|
process.exit(1);
|
|
65
111
|
}
|
|
66
112
|
mkdirSync(dirname(PLIST), { recursive: true });
|
|
113
|
+
writeFileSync(RESTORE_SCRIPT, restoreScriptBody({ herdr: bin }));
|
|
114
|
+
chmodSync(RESTORE_SCRIPT, 0o755);
|
|
67
115
|
writeFileSync(PLIST, plistBody(bin));
|
|
68
116
|
// bootout first so a re-install replaces rather than stacks
|
|
69
117
|
try { execFileSync("/bin/launchctl", ["bootout", `gui/${uid}/${LABEL}`], { stdio: "ignore" }); } catch { /* not loaded */ }
|
|
@@ -74,7 +122,7 @@ if (cmd === "install") {
|
|
|
74
122
|
process.exit(1);
|
|
75
123
|
}
|
|
76
124
|
console.log(`herdr's server now starts at login (${bin} server)`);
|
|
77
|
-
console.log(`${D}plist: ${PLIST} log: ${LOG}${R}`);
|
|
125
|
+
console.log(`${D}plist: ${PLIST} log: ${LOG} restore log: ${RESTORE_LOG}${R}`);
|
|
78
126
|
} else if (cmd === "remove") {
|
|
79
127
|
try { execFileSync("/bin/launchctl", ["bootout", `gui/${uid}/${LABEL}`], { stdio: "ignore" }); } catch { /* not loaded */ }
|
|
80
128
|
if (existsSync(PLIST)) { unlinkSync(PLIST); console.log("removed the herdr login agent"); }
|
|
@@ -87,10 +135,16 @@ if (cmd === "install") {
|
|
|
87
135
|
} catch { /* launchctl unavailable */ }
|
|
88
136
|
let running = false;
|
|
89
137
|
try { running = /status:\s*running/.test(execFileSync(herdrBin() || "herdr", ["status"], { encoding: "utf8" })); } catch { /* server down */ }
|
|
138
|
+
let wired = false;
|
|
139
|
+
try { wired = restoreWired(readFileSync(PLIST, "utf8"), readFileSync(RESTORE_SCRIPT, "utf8")); } catch { /* missing helper */ }
|
|
90
140
|
console.log(`login agent: ${installed ? "installed" : "not installed"}${installed ? ` (${loaded ? "loaded" : "NOT loaded"})` : ""}`);
|
|
91
141
|
console.log(`herdr server: ${running ? "running" : "not running"}`);
|
|
142
|
+
console.log(`Trantor restore: ${wired ? "wired after herdr starts" : "not wired"}`);
|
|
92
143
|
if (!installed) console.log(`${D}install it so panes survive a reboot: trantor herdr install${R}`);
|
|
93
144
|
} else {
|
|
94
145
|
console.log("usage: trantor herdr install | remove | status");
|
|
95
146
|
process.exit(1);
|
|
96
147
|
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) main();
|
package/bin/new.mjs
CHANGED
|
@@ -22,7 +22,7 @@ import { fileURLToPath } from "node:url";
|
|
|
22
22
|
import { ensureEnrolled as enrollTofu, loadIdentity, signedPost } from "../hooks/lib/api.mjs";
|
|
23
23
|
import { ensureEnrolled as enrollViaOwnerInvite } from "../lib/enroll.mjs";
|
|
24
24
|
import { setAutonomy } from "../lib/autonomy.mjs";
|
|
25
|
-
import { resolveHub, setProjectHub, writeProjectId, isProjectId } from "../lib/project.mjs";
|
|
25
|
+
import { resolveHub, setProjectHub, writeProjectId, isProjectId, devRootFor } from "../lib/project.mjs";
|
|
26
26
|
|
|
27
27
|
const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
28
28
|
|
|
@@ -71,7 +71,7 @@ if (briefFile) {
|
|
|
71
71
|
const dirArg = flag("dir");
|
|
72
72
|
const devRoot = dirArg
|
|
73
73
|
? resolve(dirArg)
|
|
74
|
-
:
|
|
74
|
+
: resolve(devRootFor());
|
|
75
75
|
if (dirArg && !isAbsolute(dirArg)) { /* relative --dir is allowed; resolved above */ }
|
|
76
76
|
const dir = isAbsolute(name) ? name : join(devRoot, name);
|
|
77
77
|
|
package/bin/seats.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import { existsSync, writeFileSync, unlinkSync } from "node:fs";
|
|
|
6
6
|
import { join, resolve } from "node:path";
|
|
7
7
|
import { homedir } from "node:os";
|
|
8
8
|
import { execFileSync } from "node:child_process";
|
|
9
|
+
import { devRootFor } from "../lib/project.mjs";
|
|
9
10
|
import {
|
|
10
11
|
readSeats, declareSeat, undeclareSeat, seatStatus,
|
|
11
12
|
launchSeat, suggestSeats, projectForDir, waitForHerdr,
|
|
@@ -25,7 +26,7 @@ function printStatus() {
|
|
|
25
26
|
if (!rows.length) {
|
|
26
27
|
console.log("No seats declared yet.");
|
|
27
28
|
console.log(`Declare the one you are standing in: ${O}trantor seats add ${projectForDir(process.cwd())}${R}`);
|
|
28
|
-
console.log(`…or adopt every pinned project under a workspace: ${O}trantor seats adopt
|
|
29
|
+
console.log(`…or adopt every pinned project under a workspace: ${O}trantor seats adopt ${devRootFor()}${R}`);
|
|
29
30
|
return 0;
|
|
30
31
|
}
|
|
31
32
|
const w = Math.max(...rows.map(r => r.project.length), 7);
|
|
@@ -114,7 +115,7 @@ switch (sub) {
|
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
case "adopt": {
|
|
117
|
-
const workspace = resolve(rest[0] ||
|
|
118
|
+
const workspace = resolve(rest[0] || devRootFor());
|
|
118
119
|
const found = suggestSeats(workspace);
|
|
119
120
|
if (!found.length) { console.log(`nothing to adopt under ${workspace} (every pinned project is already declared, or has no directory there)`); break; }
|
|
120
121
|
console.log(`Found ${found.length} pinned project(s) with a directory under ${workspace}:`);
|
package/bin/slop-gate.mjs
CHANGED
|
@@ -60,7 +60,7 @@ if (SURFACE) {
|
|
|
60
60
|
} else if (ALL) {
|
|
61
61
|
files = walk(".", []);
|
|
62
62
|
} else {
|
|
63
|
-
const changed = sh("git diff --name-only HEAD");
|
|
63
|
+
const changed = sh("git diff --name-only --diff-filter=d HEAD"); // a deleted file has nothing left to read
|
|
64
64
|
const untracked = sh("git ls-files --others --exclude-standard");
|
|
65
65
|
files = [...new Set([...changed.split("\n"), ...untracked.split("\n")])].filter(f => f && COMMENTABLE.test(f));
|
|
66
66
|
if (!files.length) { console.log("slop-gate: no lintable changes — pass."); process.exit(0); }
|
package/bin/takeover.mjs
CHANGED
|
@@ -16,7 +16,7 @@ import { join, dirname } from "node:path";
|
|
|
16
16
|
import { homedir } from "node:os";
|
|
17
17
|
import { fileURLToPath } from "node:url";
|
|
18
18
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
19
|
-
import { resolveProject, checkoutFor, devRootFor } from "../lib/project.mjs";
|
|
19
|
+
import { resolveProject, checkoutFor, localCheckoutFor, devRootFor } from "../lib/project.mjs";
|
|
20
20
|
|
|
21
21
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
22
22
|
const args = process.argv.slice(2);
|
|
@@ -103,7 +103,7 @@ if (process.argv[1] && _bn(process.argv[1]) === "takeover.mjs") {
|
|
|
103
103
|
const project = args.find(a => !a.startsWith("--") && args[args.indexOf(a) - 1] !== "--session")
|
|
104
104
|
|| resolveProject(process.cwd());
|
|
105
105
|
// By the project's id, so a renamed directory still answers (#6724).
|
|
106
|
-
const dir =
|
|
106
|
+
const dir = localCheckoutFor(project);
|
|
107
107
|
if (!dir) { say(`no local checkout for ${project} (looked in ${devRootFor()})`); out(false, { reason: "no-checkout" }); }
|
|
108
108
|
const d = decide({ terminalPids: terminalClaudePids(dir, project), candidates: recentCandidates(dir), sessionFlag: opt("--session"), force: flag("--force") });
|
|
109
109
|
if (flag("--dry-run")) { say(`dry-run: ${d.action}${d.reason ? ` — ${d.reason}` : ""}${d.sid ? ` (sid ${d.sid}, pid ${d.pid})` : ""}`); out(true, { decision: d }); }
|
package/bin/turn-watchdog.mjs
CHANGED
|
@@ -141,7 +141,8 @@ if (stallFile) {
|
|
|
141
141
|
reportLiveness(now, Math.max(tr, cli));
|
|
142
142
|
if (heavyWait.waiting) { lastErrAt = now; continue; }
|
|
143
143
|
if (tr > freshCut || cli > freshCut || wk > freshCut || now - lastErrAt < windowMs) { // producing work: alive
|
|
144
|
-
|
|
144
|
+
// #14235: re-read the stamp just before extending, so a turn that ended during this pass is not extended and announced after the runner counted.
|
|
145
|
+
if (box && extensions < Number(box.extensionsMax) && now + poll + SLACK >= deadline && (() => { const t = readStamp(); return t && t.turn === armed.turn; })()) {
|
|
145
146
|
extensions++;
|
|
146
147
|
deadline += Number(box.extendMs);
|
|
147
148
|
try { writeFileSync(box.deadlineFile, String(Math.floor(deadline / 1000))); } catch {}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Sourced by setup.sh. Prints the node binary to bake into the launchd plist.
|
|
3
|
+
# A Node manager path (nvm, fnm, volta) changes when the user switches versions and would leave the hub
|
|
4
|
+
# service pointing at a missing binary, so a system install wins when one exists.
|
|
5
|
+
# TRANTOR_NODE_CANDIDATES (space separated) overrides the system locations, for tests.
|
|
6
|
+
pick_node() {
|
|
7
|
+
local cur c
|
|
8
|
+
cur="$(command -v node)"
|
|
9
|
+
for c in ${TRANTOR_NODE_CANDIDATES:-/opt/homebrew/bin/node /usr/local/bin/node}; do
|
|
10
|
+
if [ -x "$c" ]; then echo "$c"; return 0; fi
|
|
11
|
+
done
|
|
12
|
+
[ -n "$cur" ] && echo "$cur"
|
|
13
|
+
case "$cur" in
|
|
14
|
+
*"/.nvm/"*|*"/.fnm/"*|*"/fnm_multishells/"*|*"/.volta/"*|*"/.asdf/"*|*"/.local/share/mise/"*)
|
|
15
|
+
echo "warning: node is at $cur, a Node manager path that changes when you switch versions; install Node system-wide (brew install node) and re-run trantor setup if the hub stops starting" >&2;;
|
|
16
|
+
esac
|
|
17
|
+
return 0
|
|
18
|
+
}
|
package/deploy/setup.sh
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
# trantor one-shot setup: hub service + config + CLI wiring + doctor.
|
|
3
3
|
set -e
|
|
4
4
|
REPO="$(cd "$(dirname "$0")/.." && pwd)"
|
|
5
|
-
|
|
5
|
+
. "$REPO/deploy/node-path.sh"
|
|
6
|
+
NODE="$(pick_node)"
|
|
6
7
|
[ -z "$NODE" ] && { echo "node >= 18 required"; exit 1; }
|
|
7
8
|
mkdir -p "$HOME/.agent-bus"
|
|
8
9
|
[ -f "$HOME/.agent-bus/config.json" ] || echo '{"url":"http://127.0.0.1:4477"}' > "$HOME/.agent-bus/config.json"
|
|
@@ -11,8 +12,15 @@ if [ "$(uname)" = "Darwin" ]; then
|
|
|
11
12
|
PL="$HOME/Library/LaunchAgents/com.trantor.hub.plist"
|
|
12
13
|
sed -e "s|__NODE__|$NODE|" -e "s|__REPO__|$REPO|" "$REPO/deploy/com.trantor.hub.plist" > "$PL"
|
|
13
14
|
launchctl bootout "gui/$(id -u)/com.trantor.hub" 2>/dev/null || true
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
# bootstrap can fail when the label is still loading or already loaded; retry once, then carry on
|
|
16
|
+
# (the rest of setup must not abort under set -e).
|
|
17
|
+
if ! launchctl bootstrap "gui/$(id -u)" "$PL" 2>/dev/null; then
|
|
18
|
+
sleep 1
|
|
19
|
+
launchctl bootout "gui/$(id -u)/com.trantor.hub" 2>/dev/null || true
|
|
20
|
+
launchctl bootstrap "gui/$(id -u)" "$PL" 2>/dev/null \
|
|
21
|
+
|| echo " (launchd did not load the hub service; start it with: trantor hub — setup continues)"
|
|
22
|
+
fi
|
|
23
|
+
echo "✓ hub service installed (starts at login, restarts on crash)"
|
|
16
24
|
else
|
|
17
25
|
echo "Linux: run the hub under systemd/tmux: RELAY_PORT=4477 node $REPO/hub.mjs"
|
|
18
26
|
fi
|
package/engine/bin/scrooge
CHANGED
|
@@ -86,6 +86,15 @@ def load_env_fallback():
|
|
|
86
86
|
_load_env_file(ENV_FALLBACK)
|
|
87
87
|
|
|
88
88
|
def load_registry():
|
|
89
|
+
# A fresh machine has no ~/.token-scrooge/registry.json until `trantor setup`/install.sh runs: seed it
|
|
90
|
+
# from the template shipped next to this script instead of dying with a traceback (#14322).
|
|
91
|
+
if not os.path.exists(REGISTRY):
|
|
92
|
+
tpl = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "registry.template.json")
|
|
93
|
+
if os.path.exists(tpl):
|
|
94
|
+
os.makedirs(SCROOGE_DIR, exist_ok=True)
|
|
95
|
+
shutil.copyfile(tpl, REGISTRY)
|
|
96
|
+
shutil.copyfile(tpl, os.path.join(SCROOGE_DIR, "registry.template.json"))
|
|
97
|
+
sys.stderr.write("[scrooge] seeded %s from the bundled template\n" % REGISTRY)
|
|
89
98
|
with open(REGISTRY) as fh:
|
|
90
99
|
return json.load(fh)
|
|
91
100
|
|
package/hooks/lib/handoff.mjs
CHANGED
|
@@ -821,8 +821,15 @@ export async function pingBus(projectName, id, conf = readConfig()) {
|
|
|
821
821
|
}
|
|
822
822
|
|
|
823
823
|
// Spawn a fresh same-agent session (macOS) that takes over via the handoff.
|
|
824
|
-
//
|
|
825
|
-
//
|
|
824
|
+
// OPT-IN (#14322): only when ~/.agent-bus/config.json has "autoHandoffPrompt": true (a Terminal prompt
|
|
825
|
+
// with a timeout, default button "Open fresh session"). env TRANTOR_NO_HANDOFF_SPAWN=1 is a hard off.
|
|
826
|
+
export function autoHandoffEnabled(conf = readConfig(), env = process.env) {
|
|
827
|
+
return conf?.autoHandoffPrompt === true && env.TRANTOR_NO_HANDOFF_SPAWN !== "1";
|
|
828
|
+
}
|
|
829
|
+
// What the hook says instead of spawning: the handoff is on disk, here is how to continue.
|
|
830
|
+
export function manualContinueLine(file = "") {
|
|
831
|
+
return `Auto handoff is off, so no new window was opened${file ? ` (handoff saved: ${file})` : ""}. To continue in a fresh session, run \`trantor handoff\` here, or start a new session in this project: it picks the handoff up and recaps it before you say anything. Turn on the auto prompt with "autoHandoffPrompt": true in ~/.agent-bus/config.json.`;
|
|
832
|
+
}
|
|
826
833
|
export function maybeSpawn(projectDir, conf = readConfig(), handoffFile = "", deps = {}) {
|
|
827
834
|
// Injection points, for the same reason spawnBaton has them: "A DRILL MUST BE ABLE TO SAY NO —
|
|
828
835
|
// a path that spawns windows needs an off switch or it cannot be tested honestly." maybeSpawn had
|
|
@@ -844,7 +851,7 @@ export function maybeSpawn(projectDir, conf = readConfig(), handoffFile = "", de
|
|
|
844
851
|
_log(`[trantor] session lives in herdr pane ${_pane(_env)} — no Terminal window and no baton driver from here; the app (or the skill path) owns the replacement\n`);
|
|
845
852
|
return false;
|
|
846
853
|
}
|
|
847
|
-
if (conf
|
|
854
|
+
if (!autoHandoffEnabled(conf, _env)) return false;
|
|
848
855
|
if (_hasPane(basename(projectDir))) {
|
|
849
856
|
_log(`[trantor] orch pane hosts ${basename(projectDir)} — no Terminal window; the app or the skill path claims the handoff
|
|
850
857
|
`);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// SessionStart gates that decide what a fresh machine is told (#14322): pure helpers so tests can inject config.
|
|
2
|
+
import { loopbackHub } from "../../lib/identity.mjs";
|
|
3
|
+
|
|
4
|
+
export const HUB_DOWN_LINE = "The local Trantor hub is not running. Start it with `trantor hub`, or open the Trantor app, which starts it.";
|
|
5
|
+
|
|
6
|
+
export function loopbackUrl(u) {
|
|
7
|
+
try { const s = String(u); return loopbackHub(s.endsWith("/") ? s : s + "/"); } catch { return false; }
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// An unpinned project only matters when pins exist (another hub may hold the crew) or the fallback hub
|
|
11
|
+
// is not this machine. One local loopback hub with no pins is the normal setup: say nothing.
|
|
12
|
+
export function shouldWarnUnpinned(via, url, pinned) {
|
|
13
|
+
if (via !== "global" && via !== "default") return false;
|
|
14
|
+
return pinned.length > 0 || !loopbackUrl(url);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// The build doctrine is opt-in: config "buildDoctrine": true.
|
|
18
|
+
export function wantsBuildDoctrine(cfg) { return cfg?.buildDoctrine === true; }
|
package/hooks/precompact.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// trantor PreCompact hook — cannot stop compaction, so it writes a whole-session handoff and (macOS,
|
|
3
3
|
// by default) prompts to open a FRESH session that takes over; the at-the-wall backstop behind
|
|
4
4
|
// the heartbeat's early warning (hooks/lib/handoff.mjs).
|
|
5
|
-
import { readConfig, writeHandoff, pingBus, maybeSpawn, armBatonClose,
|
|
5
|
+
import { readConfig, writeHandoff, pingBus, maybeSpawn, armBatonClose, autoHandoffEnabled, manualContinueLine,
|
|
6
6
|
contextUsage, alreadyHandedOff, markHandedOff, controllingTty, terminalWindowForTty } from "./lib/handoff.mjs";
|
|
7
7
|
import { basename } from "node:path";
|
|
8
8
|
|
|
@@ -12,6 +12,7 @@ function readStdin() {
|
|
|
12
12
|
setTimeout(() => res(d), 100); });
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
let noteLine = "";
|
|
15
16
|
try {
|
|
16
17
|
const input = JSON.parse((await readStdin()) || "{}");
|
|
17
18
|
// input.cwd FIRST — every hook must derive the project the SAME way, or two hooks in one
|
|
@@ -39,6 +40,9 @@ try {
|
|
|
39
40
|
process.stderr.write(`[trantor] compaction trigger "${trigger}" is not auto/manual (idle compaction?) — handoff refreshed only, no fresh session\n`);
|
|
40
41
|
} else if (alreadyHandedOff(sessionId, cur)) {
|
|
41
42
|
process.stderr.write(`[trantor] fresh session already spawned for this window — handoff refreshed only\n`);
|
|
43
|
+
} else if (!autoHandoffEnabled(conf)) {
|
|
44
|
+
process.stderr.write(`[trantor] ${manualContinueLine(file)}\n`);
|
|
45
|
+
noteLine = manualContinueLine(file);
|
|
42
46
|
} else if (maybeSpawn(projectDir, conf)) {
|
|
43
47
|
markHandedOff(sessionId, cur);
|
|
44
48
|
// baton pass at the wall. Close THIS window ONLY when config.autoCloseOriginal is true: an auto
|
|
@@ -51,5 +55,5 @@ try {
|
|
|
51
55
|
} catch (err) {
|
|
52
56
|
process.stderr.write(`[trantor] precompact error: ${err?.message || err}\n`);
|
|
53
57
|
}
|
|
54
|
-
process.stdout.write("{}");
|
|
58
|
+
process.stdout.write(noteLine ? JSON.stringify({ systemMessage: noteLine }) : "{}");
|
|
55
59
|
process.exit(0);
|
package/hooks/sessionstart.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { join, basename, dirname } from "node:path";
|
|
|
7
7
|
import { homedir, hostname } from "node:os";
|
|
8
8
|
import { execSync, spawn } from "node:child_process";
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
|
-
import { resolveProject, hostId, resolveHubInfo, knownProjects, nonSeatReason, nestedProjects, handoffDir, readOrchSession, writeOrchSession } from "../lib/project.mjs";
|
|
10
|
+
import { resolveProject, hostId, resolveHubInfo, knownProjects, nonSeatReason, nestedProjects, readConfig as readBusConfig, handoffDir, readOrchSession, writeOrchSession } from "../lib/project.mjs";
|
|
11
11
|
import { formatSubagentManifest } from "../lib/subagent-manifest.mjs";
|
|
12
12
|
import { updateAvailable, maybeNotifyDesktop, readConfig } from "./lib/update-check.mjs";
|
|
13
13
|
import { renderStateBlock, capSummary } from "./lib/handoff.mjs";
|
|
@@ -17,6 +17,7 @@ import { maybeCheckBalances } from "./lib/balance-check.mjs";
|
|
|
17
17
|
import { getJSON, signedGet, signedPost, loadIdentity } from "./lib/api.mjs";
|
|
18
18
|
import { ledgerPaths, ensureStart, anchorCursor, writeCursor } from "./lib/inbox-ledger.mjs";
|
|
19
19
|
import { ensureEnrolled } from "../lib/enroll.mjs";
|
|
20
|
+
import { HUB_DOWN_LINE, loopbackUrl, shouldWarnUnpinned, wantsBuildDoctrine } from "./lib/start-gates.mjs";
|
|
20
21
|
import { memoryStartLine } from "./lib/memory-start.mjs";
|
|
21
22
|
import { staleResumeLine } from "./lib/cc-signals.mjs";
|
|
22
23
|
import { machineLabel } from "../lib/machine-label.mjs";
|
|
@@ -27,7 +28,7 @@ import { machineLabel } from "../lib/machine-label.mjs";
|
|
|
27
28
|
function buildDoctrineShortForm() {
|
|
28
29
|
const doc = join(dirname(dirname(fileURLToPath(import.meta.url))), "docs", "BUILD-DOCTRINE.md");
|
|
29
30
|
return `<trantor-build-doctrine>\n` +
|
|
30
|
-
`📐 **Build doctrine** (
|
|
31
|
+
`📐 **Build doctrine** (rules with a gate each, not advice). Full text: ${doc}\n` +
|
|
31
32
|
`1. The real path is the gate — every card names its DRILL (what a person does on the built artifact and must see); nothing merges until you ran it and wrote the result on the card; unit tests are never sufficient; the seat that wrote the code never closes its own card to done (testing is the seat's last move, done is yours after the drill).\n` +
|
|
32
33
|
`2. Red blocks merge — a red suite blocks merge; red for a day is an incident with a card; a flaky test is fixed or deleted within a week; no test inherits the runner's identity.\n` +
|
|
33
34
|
`3. One owner per subsystem — one named owner per wave who reviews every change; cross-seat edits go through the owner over the bus; you own the gates and merges, no seat merges to main.\n` +
|
|
@@ -202,7 +203,11 @@ try {
|
|
|
202
203
|
|
|
203
204
|
// fetch roster of OTHER online sessions
|
|
204
205
|
let peers = [], hubAnswered = false;
|
|
205
|
-
try {
|
|
206
|
+
try { const pr = await signedGet(`${url}/peers`, { timeoutMs: 2500, session }); hubAnswered = pr.status !== 0 && !pr.timedOut; peers = pr.json?.peers || []; } catch {}
|
|
207
|
+
if (!hubAnswered && loopbackUrl(url)) {
|
|
208
|
+
userBanner = userBanner ? `${userBanner}\n${HUB_DOWN_LINE}` : HUB_DOWN_LINE;
|
|
209
|
+
additionalContext += `<trantor-hub-down hub="${sanitize(url)}">${HUB_DOWN_LINE}</trantor-hub-down>\n`;
|
|
210
|
+
}
|
|
206
211
|
const others = peers.filter(p => p.online && p.session !== session);
|
|
207
212
|
|
|
208
213
|
process.stderr.write(`[trantor] registered as ${session} -> ${url} (via ${hubVia}, ${others.length} other live session(s))\n`);
|
|
@@ -211,7 +216,7 @@ try {
|
|
|
211
216
|
// the bus its crew is on: pins route the known projects to the remote hub, and anything unpinned
|
|
212
217
|
// drops to the global default. Two seats that believe they are the same project then read and
|
|
213
218
|
// write different stores, each looking perfectly healthy. Never let that be silent.
|
|
214
|
-
if (hubVia
|
|
219
|
+
if (shouldWarnUnpinned(hubVia, url, knownProjects())) {
|
|
215
220
|
const known = knownProjects();
|
|
216
221
|
const O = "\x1b[1;38;5;208m", R = "\x1b[0m";
|
|
217
222
|
const line = `🟠 ${O}"${project}" is not pinned to a hub${R} — falling back to ${url}. `
|
|
@@ -359,14 +364,14 @@ try {
|
|
|
359
364
|
try {
|
|
360
365
|
if (project && (process.env.TRANTOR_ORCH || "") === project) {
|
|
361
366
|
additionalContext += `<trantor-orchestrator-role project="${sanitize(project)}">\n` +
|
|
362
|
-
`🎛️ **You are this project's ORCHESTRATOR — a project manager, not a coder
|
|
367
|
+
`🎛️ **You are this project's ORCHESTRATOR — a project manager, not a coder**.\n` +
|
|
363
368
|
`- Building goes to the CREW: invoke the trantor:crew skill (Advisor → \`trantor up\` seats → contracts over the bus), or relay_scrooge for grunt one-shots.\n` +
|
|
364
369
|
`- Spend your own tokens on design, contracts, supervision, integration and VERIFICATION — run the seats' tests yourself; bounce hollow dones.\n` +
|
|
365
370
|
`- Write code yourself ONLY for small one-head seam work that needs this session's full context — and say so when you do.\n` +
|
|
366
371
|
`- Check relay_inbox and the board before asking the operator anything a peer may already have answered.\n` +
|
|
367
372
|
`- Dispatch rule: the target project is confirmed from the session's badge and cwd before any relay_send, relay_task_add or \`trantor up\` — an ambiguous instruction is not a project name; and a session asking the operator a question never triggers a wake (its messages batch until the answer).\n` +
|
|
368
373
|
`</trantor-orchestrator-role>\n`;
|
|
369
|
-
additionalContext += buildDoctrineShortForm();
|
|
374
|
+
if (wantsBuildDoctrine(readBusConfig())) additionalContext += buildDoctrineShortForm();
|
|
370
375
|
process.stderr.write(`[trantor] injected orchestrator-role doctrine for ${project}\n`);
|
|
371
376
|
}
|
|
372
377
|
} catch {}
|
package/hub/routes/insights.mjs
CHANGED
|
@@ -1,32 +1,74 @@
|
|
|
1
1
|
/* oxlint-disable anti-slop/no-runtime-typeof -- SAFETY: Ledger and card records are historical external formats; their compatibility probes remain unchanged in this structural split. */
|
|
2
|
-
import { readFileSync,
|
|
2
|
+
import { readFileSync, statSync } from "node:fs";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
|
|
6
6
|
let ledgerCache = { mtimeMs: -1, rows: [] };
|
|
7
|
-
|
|
8
|
-
const
|
|
7
|
+
const TURN_OUTCOMES = new Set(["completed", "asked", "blocked", "no-delivery", "empty", "stalled", "cut", "rejected", "api-error"]);
|
|
8
|
+
const stringWithin = (value, max) => typeof value === "string" && value.length > 0 && value.length <= max;
|
|
9
|
+
const safeInteger = (value, min = 0) => Number.isSafeInteger(value) && value >= min;
|
|
10
|
+
const optionalBoolean = (row, key) => row[key] === undefined || typeof row[key] === "boolean";
|
|
9
11
|
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return
|
|
12
|
+
function validTurnRow(row, nowMs) {
|
|
13
|
+
if (!row || typeof row !== "object" || Array.isArray(row)) return null;
|
|
14
|
+
if ("prompt" in row || "output" in row || "text" in row) return null;
|
|
15
|
+
if (typeof row.id !== "string" || !/^[0-9a-f]{32}$/i.test(row.id) || row.v !== 1) return null;
|
|
16
|
+
if (!safeInteger(row.ts, 1) || row.ts > nowMs + 60000 || !safeInteger(row.turn, 1)) return null;
|
|
17
|
+
if (!stringWithin(row.persona, 120) || !stringWithin(row.agent, 80) || !stringWithin(row.project, 80)) return null;
|
|
18
|
+
// A machine with no label configured reports "" (lib/machine-label.mjs): that is a valid row, not a dropped one.
|
|
19
|
+
if (typeof row.machine !== "string" || row.machine.length > 120) return null;
|
|
20
|
+
if (!stringWithin(row.trigger, 120) || !stringWithin(row.model, 200)) return null;
|
|
21
|
+
if (!safeInteger(row.card) || !safeInteger(row.duration_ms)) return null;
|
|
22
|
+
if (!(row.tokens === null || safeInteger(row.tokens))) return null;
|
|
23
|
+
if (!(row.exit === null || Number.isInteger(row.exit)) || !(row.effExit === null || Number.isInteger(row.effExit))) return null;
|
|
24
|
+
if (!TURN_OUTCOMES.has(row.outcome) || typeof row.verdict !== "string") return null;
|
|
25
|
+
if (row.usage !== undefined && (!row.usage || typeof row.usage !== "object" || Array.isArray(row.usage))) return null;
|
|
26
|
+
if (row.containers !== undefined && (!Array.isArray(row.containers) || row.containers.length > 100 || row.containers.some(name => !stringWithin(name, 200)))) return null;
|
|
27
|
+
if (!["cut", "stalled", "authFailed", "emptyOutput", "emptyTurn"].every(key => optionalBoolean(row, key))) return null;
|
|
28
|
+
if (row.cutSignal !== undefined && (typeof row.cutSignal !== "string" || row.cutSignal.length > 80)) return null;
|
|
29
|
+
if (row.extensions !== undefined && !safeInteger(row.extensions)) return null;
|
|
30
|
+
if (row.boxMs !== undefined && !safeInteger(row.boxMs)) return null;
|
|
31
|
+
return { ...row, id: row.id.toLowerCase(), verdict: row.verdict.slice(0, 600) };
|
|
26
32
|
}
|
|
27
33
|
|
|
28
|
-
export async function routeInsights({ res, q, P, req, ctx }) {
|
|
29
|
-
const { state, json, canon, now } = ctx;
|
|
34
|
+
export async function routeInsights({ res, q, P, req, auth, ctx }) {
|
|
35
|
+
const { state, json, canon, now, body, scopeAllows, filterReadable, turnTelemetry, AUTH_MODE } = ctx;
|
|
36
|
+
if (req.method === "POST" && P === "/telemetry/turns") {
|
|
37
|
+
const b = await body(req);
|
|
38
|
+
if (!Array.isArray(b?.rows)) return json(res, 400, { error: "rows array required" });
|
|
39
|
+
if (b.rows.length > 100) return json(res, 400, { error: "at most 100 rows per request" });
|
|
40
|
+
const rows = [];
|
|
41
|
+
let dropped = 0;
|
|
42
|
+
for (const candidate of b.rows) {
|
|
43
|
+
const row = validTurnRow(candidate, now());
|
|
44
|
+
if (row) rows.push(row); else dropped++;
|
|
45
|
+
}
|
|
46
|
+
const owner = scopeAllows(auth?.identity, "", "owner");
|
|
47
|
+
if (AUTH_MODE !== "off" && !owner && rows.some(row => auth?.identity?.name !== `${row.persona}:${row.project}`)) {
|
|
48
|
+
return json(res, 403, { error: "turn rows must name the signing seat" });
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const result = await turnTelemetry.append(rows);
|
|
52
|
+
return json(res, 200, { ok: true, stored: result.stored, duplicates: result.duplicates, dropped });
|
|
53
|
+
} catch (error) {
|
|
54
|
+
const reason = String(error?.message || error);
|
|
55
|
+
process.stderr.write(`[trantor] turn telemetry store failed: ${reason}\n`);
|
|
56
|
+
return json(res, 500, { error: `turn telemetry store failed: ${reason}` });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (req.method === "GET" && P === "/telemetry/turns") {
|
|
60
|
+
const numberQuery = (value, fallback) => {
|
|
61
|
+
if (value === undefined || value === "") return fallback;
|
|
62
|
+
const parsed = Number(value);
|
|
63
|
+
return Number.isFinite(parsed) ? parsed : fallback;
|
|
64
|
+
};
|
|
65
|
+
const limit = Math.min(1000, Math.max(1, Math.floor(numberQuery(q.limit, 1000))));
|
|
66
|
+
const rows = turnTelemetry.readRows({
|
|
67
|
+
project: q.project || "", agent: q.agent || "",
|
|
68
|
+
since: numberQuery(q.since, 0), until: numberQuery(q.until, Number.MAX_SAFE_INTEGER),
|
|
69
|
+
});
|
|
70
|
+
return json(res, 200, { rows: filterReadable(auth, rows, row => row.project || "").slice(0, limit) });
|
|
71
|
+
}
|
|
30
72
|
if (req.method === "GET" && P === "/economics") { // the brain's books, surfaced: scrooge ledger + quota profile
|
|
31
73
|
const out = { scrooge: null, lifetime: null, profile: null };
|
|
32
74
|
try { out.profile = JSON.parse(readFileSync(join(homedir(), ".agent-bus", "profile.json"), "utf8")).providers || {}; } catch {}
|
|
@@ -113,7 +155,7 @@ export async function routeInsights({ res, q, P, req, ctx }) {
|
|
|
113
155
|
// charts), and the Scrooge guardrails baked into each model's prompt (+ per-model economics).
|
|
114
156
|
if (req.method === "GET" && P === "/learning") {
|
|
115
157
|
const projOf = by => (by && by.includes(":")) ? by.split(":").pop() : "";
|
|
116
|
-
// ts is ms (lessons
|
|
158
|
+
// ts is ms (lessons) or s (ledger). Null-safe: a malformed record with a missing/bad
|
|
117
159
|
// ts must not throw (new Date(NaN).toISOString() does) and 500 the whole endpoint — return null
|
|
118
160
|
// and let callers skip that day-bucket.
|
|
119
161
|
const dayOf = ts => { const n = Number(ts); if (!n) return null; const d = new Date(n > 2e10 ? n : n * 1000); return Number.isNaN(d.getTime()) ? null : d.toISOString().slice(0, 10); };
|
|
@@ -130,20 +172,25 @@ export async function routeInsights({ res, q, P, req, ctx }) {
|
|
|
130
172
|
|
|
131
173
|
// per-LLM reliability from turn telemetry, bucketed BY PROJECT (+ a global ALL bucket) so the
|
|
132
174
|
// sidebar's project filter scopes the charts. Each turn carries its own project.
|
|
133
|
-
const
|
|
175
|
+
const totals = turnTelemetry.readTotals();
|
|
134
176
|
const relAgg = {}; // scope -> agent -> {turns,failures,models:Set,lastFailure,days}
|
|
135
177
|
const scopeModels = {}; // scope -> Set(model used)
|
|
136
178
|
let totalTurns = 0, totalFails = 0;
|
|
137
179
|
const bumpRel = (scope, t) => {
|
|
138
180
|
const a = ((relAgg[scope] ||= {})[t.agent] ||= { agent: t.agent, turns: 0, failures: 0, models: new Set(), lastFailure: null, days: {} });
|
|
139
|
-
a.turns
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
|
|
181
|
+
a.turns += t.turns;
|
|
182
|
+
a.failures += t.failed;
|
|
183
|
+
for (const model of t.models) { a.models.add(model); if (model !== "default") (scopeModels[scope] ||= new Set()).add(model); }
|
|
184
|
+
const d = (a.days[t.day] ||= { turns: 0, failures: 0 });
|
|
185
|
+
d.turns += t.turns;
|
|
186
|
+
d.failures += t.failed;
|
|
187
|
+
if (t.lastFailure && (!a.lastFailure || t.lastFailure.ts > a.lastFailure.ts)) {
|
|
188
|
+
a.lastFailure = { ts: t.lastFailure.ts, exit: t.lastFailure.exit, project: t.project || "" };
|
|
189
|
+
}
|
|
143
190
|
};
|
|
144
|
-
for (const t of
|
|
145
|
-
|
|
146
|
-
|
|
191
|
+
for (const t of totals) {
|
|
192
|
+
totalTurns += t.turns;
|
|
193
|
+
totalFails += t.failed;
|
|
147
194
|
bumpRel(ALL, t);
|
|
148
195
|
if (t.project) { bumpRel(t.project, t); projSet.add(t.project); }
|
|
149
196
|
}
|
package/hub/routes/messages.mjs
CHANGED
|
@@ -9,7 +9,7 @@ export async function routeMessages({ req, res, q, P, auth, ctx }) {
|
|
|
9
9
|
appendEvent, appendCardEvent, appendTaskLog, markDelivered, contractsFor, canUseInboxSession, inboxWindow,
|
|
10
10
|
deliverable, inboxReadable, inboxResponse, filterReadable, canRead, streams, UI,
|
|
11
11
|
AUTH_MODE, persistHealth, duty, now, markDirty, assertNoSecrets, PEER_TTL_MS,
|
|
12
|
-
CONTRACT_WINDOW_MS, PUBLIC_URL,
|
|
12
|
+
CONTRACT_WINDOW_MS, PUBLIC_URL, turnTelemetry,
|
|
13
13
|
} = ctx;
|
|
14
14
|
if (req.method === "POST" && P === "/send") {
|
|
15
15
|
const b = await body(req);
|
|
@@ -175,6 +175,7 @@ export async function routeMessages({ req, res, q, P, auth, ctx }) {
|
|
|
175
175
|
// #8723: the count is a listing in aggregate — memory rows (past PEER_TTL_MS) never count.
|
|
176
176
|
if (P === "/health") return json(res, 200, { ok: true, authMode: AUTH_MODE, peers: Object.values(state.peers).filter(v => (v.lastSeen || 0) >= now() - PEER_TTL_MS).length, messages: state.messages.length, streams: streams.length,
|
|
177
177
|
persist: persistHealth.view(),
|
|
178
|
+
telemetry: turnTelemetry.health(),
|
|
178
179
|
// v1.4: the public front door, empty when RELAY_PUBLIC_URL is unset — pairing hands it out.
|
|
179
180
|
publicUrl: PUBLIC_URL,
|
|
180
181
|
// #5686: duty liveness rides /health so the app's Home strip and doctor read one truth.
|