trantor 0.18.119 → 0.18.121
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/bin/disk.mjs +2 -8
- package/hooks/lib/handoff-claims.mjs +9 -1
- package/hooks/lib/handoff.mjs +34 -9
- package/hooks/stop-inbox.mjs +3 -2
- package/hub/routes/session.mjs +42 -8
- package/lib/disk.mjs +104 -10
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trantor",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.121",
|
|
4
4
|
"description": "Trantor — the hub-world for AI agent crews: live message bus, presence, project Kanban/flow board + crew orchestration for independent AI coding agents (Claude, Codex, Gemini, Kimi, DeepSeek)",
|
|
5
5
|
"mcpServers": {
|
|
6
6
|
"relay": {
|
package/bin/disk.mjs
CHANGED
|
@@ -7,16 +7,10 @@ import { join, dirname } from "node:path";
|
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
9
9
|
import { homedir, platform, userInfo } from "node:os";
|
|
10
|
-
import { runDisk, formatHuman,
|
|
10
|
+
import { runDisk, formatHuman, launchdPlist, diskSummary } from "../lib/disk.mjs";
|
|
11
11
|
|
|
12
12
|
const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
13
13
|
|
|
14
|
-
function summaryLine(r, results) {
|
|
15
|
-
const okN = results.filter((x) => x.ok).length;
|
|
16
|
-
const failN = results.length - okN;
|
|
17
|
-
return `disk janitor: safe tier ${okN ? `cleaned ${okN} item(s)` : "nothing to clean"}${failN ? `, ${failN} FAILED` : ""} (~${fmtBytes(freedOnDiskBytes(r.plan))} freed), now ${fmtBytes(r.freeBytes)} free of ${fmtBytes(r.totalBytes)} — report: trantor disk`;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
14
|
async function sendWeeklyMessage(text) {
|
|
21
15
|
// One message, signed, into the operator's project lane — never a wall of warnings.
|
|
22
16
|
try {
|
|
@@ -91,4 +85,4 @@ if (json) {
|
|
|
91
85
|
for (const r of results.filter((r) => !r.ok)) console.log(` FAILED ${r.type} ${r.path || r.id || ""}: ${r.error}`);
|
|
92
86
|
}
|
|
93
87
|
}
|
|
94
|
-
if (periodic) await sendWeeklyMessage(
|
|
88
|
+
if (periodic) await sendWeeklyMessage(diskSummary(report, results));
|
|
@@ -85,7 +85,7 @@ export function loadPendingHandoff(project, { claim = true, freshSession = null,
|
|
|
85
85
|
if (!claim) return record;
|
|
86
86
|
const next = claimHandoffFile(path, freshSession, now);
|
|
87
87
|
if (!next) return null;
|
|
88
|
-
const readFirst = readFirstPaths(next.summary || "");
|
|
88
|
+
const readFirst = readFirstPaths(next.summary || "", { projectDir: next.project || process.cwd() });
|
|
89
89
|
writeFileSync(recapStampPath(dir, freshSession.session_id), JSON.stringify({
|
|
90
90
|
handoffId: next.id, file, token: next.claim.token, ts: now,
|
|
91
91
|
mode: next.mode === "unattended" ? "unattended" : "attended", readFirst,
|
|
@@ -135,3 +135,11 @@ export function completeHandoffRecap({ sessionId, transcriptPath, dir = handoffD
|
|
|
135
135
|
else traceRecapAttempt(stampPath, { ts: now, sessionId, outcome: "no-record-update" });
|
|
136
136
|
return { recapped: !!next, missed };
|
|
137
137
|
}
|
|
138
|
+
|
|
139
|
+
// Persist before emitting the reminder so subsequent turns cannot repeat it (#13061).
|
|
140
|
+
export function markHandoffReadReminder({ sessionId, dir = handoffDir() }) {
|
|
141
|
+
try {
|
|
142
|
+
return !!updateRecord(recapStampPath(dir, sessionId), stamp =>
|
|
143
|
+
stamp.readReminderShown ? null : { ...stamp, readReminderShown: true });
|
|
144
|
+
} catch { return false; }
|
|
145
|
+
}
|
package/hooks/lib/handoff.mjs
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
// spawns a fresh same-agent session. PreCompact cannot stop compaction, so continuing with a full
|
|
4
4
|
// window means a NEW session; both paths share a per-session guard so nothing is written or spawned twice.
|
|
5
5
|
import { readFileSync, writeFileSync, existsSync, mkdirSync, readdirSync, statSync, openSync, readSync, fstatSync, closeSync, rmSync } from "node:fs";
|
|
6
|
-
import { join, basename, dirname, sep } from "node:path";
|
|
6
|
+
import { join, basename, dirname, sep, resolve } 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 { asString, asRecord } from "../../lib/decode.mjs";
|
|
10
11
|
import { deriveSubagentManifest } from "../../lib/subagent-manifest.mjs";
|
|
11
12
|
import { signedPost, loadIdentity } from "./api.mjs";
|
|
12
13
|
// #7037: signedHeaders is SYNCHRONOUS, which is why this path can sign at all — see hubCallSync.
|
|
@@ -692,7 +693,7 @@ export function writeHandoff({ projectDir, sessionId, transcript, trigger, summa
|
|
|
692
693
|
// paths disarms the #8162 gate — every check downstream passes vacuously, and the summarizer
|
|
693
694
|
// produced exactly that before #8232 asked it for the section. The memory index is knowable
|
|
694
695
|
// without the model; PRD and TDD stay the summarizer's to find (only it knows they exist).
|
|
695
|
-
if (!readFirstPaths(narrative).length) {
|
|
696
|
+
if (!readFirstPaths(narrative, { projectDir }).length) {
|
|
696
697
|
const mem = memoryIndexPath(projectDir);
|
|
697
698
|
if (mem) narrative += `\n\n## READ FIRST\n${mem}`;
|
|
698
699
|
}
|
|
@@ -869,7 +870,7 @@ export function memoryIndexPath(projectDir) {
|
|
|
869
870
|
* can check it. Recognised: a `READ FIRST`/`READ-FIRST`/`Read first:` heading or line, and every
|
|
870
871
|
* path-looking token until the next blank line or heading — narrow on purpose: a path in passing
|
|
871
872
|
* is not a reading order. @returns {string[]} paths, deduped, capped */
|
|
872
|
-
export function readFirstPaths(summary, { max = 12 } = {}) {
|
|
873
|
+
export function readFirstPaths(summary, { max = 12, projectDir = process.cwd() } = {}) {
|
|
873
874
|
const text = String(summary || "");
|
|
874
875
|
const out = [];
|
|
875
876
|
const lines = text.split(/\r?\n/);
|
|
@@ -880,10 +881,13 @@ export function readFirstPaths(summary, { max = 12 } = {}) {
|
|
|
880
881
|
if (!collecting && !opens) continue;
|
|
881
882
|
if (collecting && (line === "" || /^#{1,6}\s/.test(line))) break;
|
|
882
883
|
collecting = true;
|
|
883
|
-
//
|
|
884
|
-
for (const m of line.matchAll(
|
|
885
|
-
const p = m[1].replace(
|
|
886
|
-
if (p
|
|
884
|
+
// Preserve bracketed routes and globs as whole tokens; never turn a suffix into a path.
|
|
885
|
+
for (const m of line.matchAll(/`([^`]+)`|"([^"]+)"|'([^']+)'|[^\s`"'<>]+/g)) {
|
|
886
|
+
const p = (m[1] || m[2] || m[3] || m[0]).replace(/^\(|[),;:]$/g, "");
|
|
887
|
+
if (!/\.(?:md|mjs|js|ts|tsx|json|sql|rs|py|sh|txt)$/.test(p) || /[*?]/.test(p)) continue;
|
|
888
|
+
const full = p.startsWith("~/") ? join(homedir(), p.slice(2)) : resolve(projectDir, p);
|
|
889
|
+
try { if (!statSync(full).isFile()) continue; } catch { continue; }
|
|
890
|
+
if (!out.includes(p)) out.push(p);
|
|
887
891
|
if (out.length >= max) return out;
|
|
888
892
|
}
|
|
889
893
|
}
|
|
@@ -901,8 +905,29 @@ export function pathsReadIn(transcriptPath, paths) {
|
|
|
901
905
|
// Only the tool CALLS count. A path quoted in the injected handoff summary, or in the model's own
|
|
902
906
|
// prose, must never read as "opened" — that is precisely the proxy this card exists to kill.
|
|
903
907
|
const opened = new Set();
|
|
904
|
-
for (const
|
|
905
|
-
|
|
908
|
+
for (const line of body.split("\n")) {
|
|
909
|
+
let row;
|
|
910
|
+
try { row = asRecord(JSON.parse(line)); } catch { continue; }
|
|
911
|
+
if (row?.type !== "assistant" || row.isSidechain) continue;
|
|
912
|
+
for (const call of Array.isArray(row.message?.content) ? row.message.content : []) {
|
|
913
|
+
if (call.type !== "tool_use") continue;
|
|
914
|
+
if (["Read", "Grep", "Glob", "NotebookRead"].includes(call.name)) {
|
|
915
|
+
for (const key of ["file_path", "path", "pattern"]) {
|
|
916
|
+
const path = asString(asRecord(call.input)?.[key]);
|
|
917
|
+
if (path !== null) opened.add(path);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
const command = asString(asRecord(call.input)?.command);
|
|
921
|
+
if (call.name !== "Bash" || command === null) continue;
|
|
922
|
+
const tokens = command.match(/"[^"]*"|'[^']*'|[^\s;&|]+|[;\n&|]+/g) || [];
|
|
923
|
+
let reader = false, commandStart = true;
|
|
924
|
+
for (const token of tokens) {
|
|
925
|
+
if (/^[;\n&|]+$/.test(token)) { reader = false; commandStart = true; continue; }
|
|
926
|
+
const word = token.replace(/^["']|["']$/g, "");
|
|
927
|
+
if (commandStart) { commandStart = false; reader = /^(?:\/[^ ]*\/)?(?:cat|sed|head)$/.test(word); continue; }
|
|
928
|
+
if (reader && !word.startsWith("-")) opened.add(word);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
906
931
|
}
|
|
907
932
|
const hit = (p) => {
|
|
908
933
|
const base = p.split("/").pop();
|
package/hooks/stop-inbox.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import { signedGet } from "./lib/api.mjs"; // signed: enforce hubs 401 unsigne
|
|
|
13
13
|
import { ledgerPaths, ensureStart, anchorCursor, writeCursor } from "./lib/inbox-ledger.mjs";
|
|
14
14
|
import { readArm, clearArm, markHandedOff, subagentsActive } from "./lib/handoff.mjs";
|
|
15
15
|
|
|
16
|
-
import { completeHandoffRecap } from "./lib/handoff-claims.mjs";
|
|
16
|
+
import { completeHandoffRecap, markHandoffReadReminder } from "./lib/handoff-claims.mjs";
|
|
17
17
|
|
|
18
18
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
19
19
|
|
|
@@ -129,7 +129,8 @@ async function main() {
|
|
|
129
129
|
|
|
130
130
|
if (process.env.RELAY_STOP_INBOX === "0") return allow();
|
|
131
131
|
const recap = completeHandoffRecap({ sessionId: String(input.session_id || ""), transcriptPath: input.transcript_path || "" });
|
|
132
|
-
if (recap?.missed.length && !input.stop_hook_active
|
|
132
|
+
if (recap?.missed.length && !input.stop_hook_active
|
|
133
|
+
&& markHandoffReadReminder({ sessionId: String(input.session_id || "") })) {
|
|
133
134
|
process.stdout.write(JSON.stringify({ decision: "block", reason: `Read these handoff files before recapping: ${recap.missed.join(", ")}` }));
|
|
134
135
|
return;
|
|
135
136
|
}
|
package/hub/routes/session.mjs
CHANGED
|
@@ -20,6 +20,7 @@ const CLAIMED_EXPIRED_REASON = "The Mac claimed this prompt but never delivered
|
|
|
20
20
|
const ACK_OUTCOMES = new Set(["delivered", "blocked", "not_ready", "stalled", "no_agent", "stale"]);
|
|
21
21
|
const ANSWER_PICKS_MAX = 10;
|
|
22
22
|
const ANSWER_OTHER_MAX = 2000;
|
|
23
|
+
const ANSWER_ENTRIES_MAX = 4; // CC's question limit per ask (#12912)
|
|
23
24
|
// #12161: photo attachments ride POST /session/prompt as base64 JPEGs. The phone downscales to
|
|
24
25
|
// the byte cap; the hub stores the bytes on disk next to its state (never in bus.json) and hands
|
|
25
26
|
// metadata to the claiming desktop, which downloads them through GET /session/attachment.
|
|
@@ -243,14 +244,33 @@ export function createSessionRuntime({ state, markDirty, appendEvent, pushEventT
|
|
|
243
244
|
if (!project) return json(res, 400, { error: "project required" });
|
|
244
245
|
if (!session) return json(res, 400, { error: "session required" });
|
|
245
246
|
if (!toolId) return json(res, 400, { error: "toolId required" });
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
247
|
+
// #12912: a multi-question ask carries answers[] (1..4 entries, one per question in
|
|
248
|
+
// order); the old single-question { picks, other } body normalizes to one entry.
|
|
249
|
+
const normEntry = (e) => {
|
|
250
|
+
const picks = (Array.isArray(e?.picks) ? e.picks : []).map(Number).filter(Number.isInteger).slice(0, ANSWER_PICKS_MAX);
|
|
251
|
+
const other = String(e?.other || "").slice(0, ANSWER_OTHER_MAX);
|
|
252
|
+
if (!picks.length && !other.trim()) return null;
|
|
253
|
+
const entry = { picks };
|
|
254
|
+
if (other.trim()) entry.other = other;
|
|
255
|
+
return entry;
|
|
256
|
+
};
|
|
257
|
+
let answers;
|
|
258
|
+
if (Array.isArray(b.answers)) {
|
|
259
|
+
if (!b.answers.length || b.answers.length > ANSWER_ENTRIES_MAX) {
|
|
260
|
+
return json(res, 400, { error: `answers needs 1..${ANSWER_ENTRIES_MAX} entries` });
|
|
261
|
+
}
|
|
262
|
+
answers = b.answers.map(normEntry);
|
|
263
|
+
if (answers.some(a => !a)) return json(res, 400, { error: "each answer needs picks or a non-blank other" });
|
|
264
|
+
} else {
|
|
265
|
+
const entry = normEntry(b);
|
|
266
|
+
if (!entry) return json(res, 400, { error: "picks or other required" });
|
|
267
|
+
answers = [entry];
|
|
268
|
+
}
|
|
249
269
|
expireQueued();
|
|
250
270
|
if (queueFull()) return json(res, 429, { error: "prompt queue full; try again after pending work finishes" });
|
|
251
271
|
state.sessionPromptSeq += 1;
|
|
252
|
-
const text =
|
|
253
|
-
const p = { id: state.sessionPromptSeq, project, kind: "answer", session, toolId,
|
|
272
|
+
const text = answers.map(a => a.other ? a.other : `picks ${a.picks.join(", ")}`).join("; ");
|
|
273
|
+
const p = { id: state.sessionPromptSeq, project, kind: "answer", session, toolId, answers,
|
|
254
274
|
text, by: String(auth?.identity?.name || "").slice(0, 120), ts: now(), status: "queued" };
|
|
255
275
|
state.sessionPrompts.push(p);
|
|
256
276
|
trimPrompts();
|
|
@@ -379,15 +399,29 @@ export function createSessionRuntime({ state, markDirty, appendEvent, pushEventT
|
|
|
379
399
|
}
|
|
380
400
|
|
|
381
401
|
// The public view of a queue row: plain prompts are kind "prompt"; answers carry their
|
|
382
|
-
// session, toolId
|
|
402
|
+
// session, toolId and normalized answers (plus legacy picks/other for a one-entry answer); crew commands carry action, seats, from and to —
|
|
383
403
|
// so the claiming desktop has everything it needs. Attachments ride as metadata only;
|
|
384
404
|
// the bytes go to the claimer through GET /session/attachment.
|
|
385
405
|
const promptView = (p) => {
|
|
386
406
|
const view = { id: p.id, project: p.project, text: p.text, by: p.by, ts: p.ts, status: p.status, kind: p.kind || "prompt" };
|
|
387
407
|
if (p.attachments?.length) view.attachments = p.attachments.map(({ name, size }) => ({ name, size }));
|
|
388
408
|
if (p.kind === "answer") {
|
|
389
|
-
view.session = p.session; view.toolId = p.toolId;
|
|
390
|
-
|
|
409
|
+
view.session = p.session; view.toolId = p.toolId;
|
|
410
|
+
// #12912: the view always carries the normalized answers; the legacy top-level picks and
|
|
411
|
+
// other ride along only for a one-entry answer so a desktop that predates it keeps working.
|
|
412
|
+
// A row persisted before answers[] shipped has picks/other but no answers — derive the one
|
|
413
|
+
// entry from them so new clients read old rows too.
|
|
414
|
+
let answers = Array.isArray(p.answers) && p.answers.length ? p.answers : null;
|
|
415
|
+
if (!answers) {
|
|
416
|
+
const entry = { picks: Array.isArray(p.picks) ? p.picks : [] };
|
|
417
|
+
if (String(p.other || "").trim()) entry.other = p.other;
|
|
418
|
+
answers = [entry];
|
|
419
|
+
}
|
|
420
|
+
view.answers = answers;
|
|
421
|
+
if (answers.length === 1) {
|
|
422
|
+
view.picks = answers[0].picks;
|
|
423
|
+
if (answers[0].other?.trim()) view.other = answers[0].other; // absent, never "", when nothing was typed
|
|
424
|
+
}
|
|
391
425
|
}
|
|
392
426
|
if (p.kind === "crew") {
|
|
393
427
|
view.action = p.action; view.seats = p.seats;
|
package/lib/disk.mjs
CHANGED
|
@@ -6,7 +6,6 @@ import { spawnSync } from "node:child_process";
|
|
|
6
6
|
import * as nodeFs from "node:fs";
|
|
7
7
|
import { join, resolve, sep, basename, dirname, relative } from "node:path";
|
|
8
8
|
import { homedir } from "node:os";
|
|
9
|
-
import { readRows } from "../bin/crew/state.mjs";
|
|
10
9
|
import { seatProcesses } from "../bin/crew/processes.mjs";
|
|
11
10
|
|
|
12
11
|
export const DAY = 24 * 60 * 60 * 1000;
|
|
@@ -22,6 +21,12 @@ export const WORKTREE_IDLE_MAX = 7 * DAY;
|
|
|
22
21
|
export const BUILD_OUTPUT_IDLE_MAX = 3 * DAY;
|
|
23
22
|
export const BUILD_OUTPUT_NAMES = ["DerivedData", "target"];
|
|
24
23
|
export const BUILD_OUTPUT_SUFFIX = ".xcresult";
|
|
24
|
+
// #12268: regenerable output pruned from every NON-live seat worktree, plus the drill dir.
|
|
25
|
+
export const JUNK_DIRS = ["node_modules", ".next", "target", "dist", "build", ".turbo", "DerivedData"];
|
|
26
|
+
export const DRILL_DIR = ".agent-bus-out";
|
|
27
|
+
export const LOW_SPACE_BYTES = 50 * 1024 ** 3;
|
|
28
|
+
export const ALARM_SPACE_BYTES = 15 * 1024 ** 3;
|
|
29
|
+
const ON_DISK_TYPES = ["build-dir", "scratch-entry", "seat-worktree", "build-output", "build-junk", "drill-output"];
|
|
25
30
|
|
|
26
31
|
const GB = 1024 ** 3;
|
|
27
32
|
const KB = 1024;
|
|
@@ -49,6 +54,22 @@ function isUnder(path, parent) {
|
|
|
49
54
|
return child === root || child.startsWith(root.endsWith(sep) ? root : root + sep);
|
|
50
55
|
}
|
|
51
56
|
|
|
57
|
+
// #12268: one lsof call lists every process cwd; memoized so 200 seats cost one call.
|
|
58
|
+
export function liveCwds(exec) {
|
|
59
|
+
const r = exec("lsof", ["-d", "cwd", "-Fn"]);
|
|
60
|
+
if (!r.stdout) throw new Error("lsof returned no cwd list");
|
|
61
|
+
return r.stdout.split("\n").filter((l) => l.startsWith("n")).map((l) => l.slice(1));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function memoCwds(exec) {
|
|
65
|
+
let cache = null;
|
|
66
|
+
const run = exec || ((file, args) => {
|
|
67
|
+
const r = spawnSync(file, args, { encoding: "utf8", maxBuffer: 64 * 1024 ** 2 });
|
|
68
|
+
return { stdout: r.stdout || "", status: r.status ?? 1 };
|
|
69
|
+
});
|
|
70
|
+
return () => (cache ||= liveCwds(run));
|
|
71
|
+
}
|
|
72
|
+
|
|
52
73
|
// Default dependency kit — every call site takes `d` so tests inject a temp HOME,
|
|
53
74
|
// a canned exec and a recording remove, and no real simctl/opencode/docker ever runs.
|
|
54
75
|
function defaults(d = {}) {
|
|
@@ -62,6 +83,7 @@ function defaults(d = {}) {
|
|
|
62
83
|
home: d.home || homedir(),
|
|
63
84
|
now: d.now || Date.now(),
|
|
64
85
|
worktreesRoot: d.worktreesRoot || null,
|
|
86
|
+
cwds: d.cwds || memoCwds(d.exec),
|
|
65
87
|
log: d.log || console.log,
|
|
66
88
|
entryBudget: d.entryBudget || 400_000,
|
|
67
89
|
};
|
|
@@ -124,14 +146,13 @@ export function gitTracked(exec, worktree, rel) {
|
|
|
124
146
|
return gitOut(exec, ["-C", worktree, "ls-files", "--", rel]).trim().length > 0;
|
|
125
147
|
}
|
|
126
148
|
|
|
127
|
-
// #
|
|
149
|
+
// #12268: a crew row never protects a worktree (dead seats keep theirs forever); live means a
|
|
150
|
+
// process stands in it or its runner is running.
|
|
128
151
|
function seatRetentionReason(d, project, seat, worktree) {
|
|
129
152
|
const bus = join(d.home, ".agent-bus");
|
|
130
153
|
try {
|
|
131
|
-
const ctx = {
|
|
132
|
-
if (
|
|
133
|
-
return `KEPT: ${seat}:${project} has a crew state row`;
|
|
134
|
-
}
|
|
154
|
+
const ctx = { seatDir: join(bus, "seats"), env: {} };
|
|
155
|
+
if ((d.cwds ||= memoCwds(d.exec))().some((c) => isUnder(c, worktree))) return `KEPT: ${seat}:${project} has a live process in its worktree`;
|
|
135
156
|
const trees = gitOut(d.exec, ["-C", worktree, "worktree", "list", "--porcelain"]);
|
|
136
157
|
ctx.dir = trees.match(/^worktree (.+)$/m)?.[1] || worktree;
|
|
137
158
|
if (seatProcesses(ctx, project, seat, d.exec).length) return `KEPT: ${seat}:${project} has live crew processes`;
|
|
@@ -290,6 +311,54 @@ export function scanNestedBuildOutput(d) {
|
|
|
290
311
|
return { plan, kept };
|
|
291
312
|
}
|
|
292
313
|
|
|
314
|
+
// #12268: build output and the drill dir in NON-live seat worktrees go even when the worktree
|
|
315
|
+
// itself stays (dirty); src/ and flutter/ build+dist are hand-written source and survive.
|
|
316
|
+
function findJunkDirs(d, wt) {
|
|
317
|
+
const found = [], stack = [[wt, []]];
|
|
318
|
+
let seen = 0;
|
|
319
|
+
while (stack.length) {
|
|
320
|
+
if (seen++ > d.entryBudget) break;
|
|
321
|
+
const [dir, parts] = stack.pop();
|
|
322
|
+
let entries;
|
|
323
|
+
try { entries = d.fs.readdirSync(dir, { withFileTypes: true }); } catch { continue; }
|
|
324
|
+
for (const e of entries) {
|
|
325
|
+
if (!e.isDirectory() || e.name === ".git" || e.name === DRILL_DIR) continue;
|
|
326
|
+
const source = (e.name === "build" || e.name === "dist") && parts.some((x) => x === "src" || x === "flutter");
|
|
327
|
+
if (JUNK_DIRS.includes(e.name) && !source) { found.push(join(dir, e.name)); continue; }
|
|
328
|
+
stack.push([join(dir, e.name), [...parts, e.name]]);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return found;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export function scanDeadWorktreeOutput(d) {
|
|
335
|
+
const { fs, exec } = d;
|
|
336
|
+
const root = worktreesRootFor(d);
|
|
337
|
+
const plan = [], kept = [];
|
|
338
|
+
let projects;
|
|
339
|
+
try { projects = fs.readdirSync(root, { withFileTypes: true }).filter((e) => e.isDirectory()); }
|
|
340
|
+
catch { return { plan, kept }; }
|
|
341
|
+
for (const proj of projects) {
|
|
342
|
+
let seatDirs;
|
|
343
|
+
try { seatDirs = fs.readdirSync(join(root, proj.name), { withFileTypes: true }).filter((e) => e.isDirectory()); }
|
|
344
|
+
catch { continue; }
|
|
345
|
+
for (const seat of seatDirs) {
|
|
346
|
+
const wt = join(root, proj.name, seat.name);
|
|
347
|
+
if (seatRetentionReason(d, proj.name, seat.name, wt)) continue;
|
|
348
|
+
const drill = join(wt, DRILL_DIR);
|
|
349
|
+
const targets = findJunkDirs(d, wt).map((p) => ({ p, type: "build-junk" }));
|
|
350
|
+
try { if (fs.statSync(drill).isDirectory()) targets.push({ p: drill, type: "drill-output" }); } catch {}
|
|
351
|
+
for (const { p, type } of targets) {
|
|
352
|
+
const rel = relative(wt, p);
|
|
353
|
+
if (gitTracked(exec, wt, rel)) { kept.push({ path: p, reason: `KEPT: ${rel} is git-tracked in ${proj.name}/${seat.name}` }); continue; }
|
|
354
|
+
plan.push({ type, path: p, worktree: wt, project: proj.name, seat: seat.name, bytes: dirSize(fs, p, d).bytes });
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
plan.sort((a, b) => b.bytes - a.bytes);
|
|
359
|
+
return { plan, kept };
|
|
360
|
+
}
|
|
361
|
+
|
|
293
362
|
export function scanOpencodeSessions(d) {
|
|
294
363
|
const { exec, now } = d;
|
|
295
364
|
const live = liveCommandLines(exec);
|
|
@@ -457,6 +526,7 @@ export function buildDiskReport(d) {
|
|
|
457
526
|
const seats = scanSeatWorktrees({ ...dep, entryBudget: dep.entryBudget });
|
|
458
527
|
const stale = scanStaleWorktrees({ ...dep, entryBudget: dep.entryBudget });
|
|
459
528
|
const nested = scanNestedBuildOutput({ ...dep, entryBudget: dep.entryBudget });
|
|
529
|
+
const junk = scanDeadWorktreeOutput({ ...dep, entryBudget: dep.entryBudget });
|
|
460
530
|
const sessions = scanOpencodeSessions(dep);
|
|
461
531
|
const sims = scanSimulators(dep);
|
|
462
532
|
const dbPath = join(home, ".local", "share", "opencode", "opencode.db");
|
|
@@ -472,17 +542,27 @@ export function buildDiskReport(d) {
|
|
|
472
542
|
hf: reportHfCache(dep),
|
|
473
543
|
claudeWorktrees: reportClaudeWorktrees(dep),
|
|
474
544
|
bigFiles: collectBigFiles(dep),
|
|
475
|
-
plan: [...sims.plan, ...seats.plan, ...stale.plan, ...nested.plan,
|
|
476
|
-
kept: [...seats.kept, ...stale.kept, ...nested.kept,
|
|
545
|
+
plan: mergePlans([...sims.plan, ...seats.plan, ...stale.plan, ...nested.plan], stale.plan, junk.plan).concat(sessions.plan),
|
|
546
|
+
kept: [...seats.kept, ...stale.kept, ...nested.kept].filter((k) => !junk.plan.some((j) => isUnder(k.path, j.path))).concat(junk.kept, sessions.kept),
|
|
477
547
|
};
|
|
478
548
|
return report;
|
|
479
549
|
}
|
|
480
550
|
|
|
551
|
+
// #12268: the junk scan supersedes older partial rules on the same paths, and nothing inside a
|
|
552
|
+
// worktree that is being removed whole is planned twice (bytes would double-count).
|
|
553
|
+
function mergePlans(older, wholes, junk) {
|
|
554
|
+
const whole = wholes.map((w) => w.path);
|
|
555
|
+
const junkPaths = junk.map((j) => j.path);
|
|
556
|
+
const keepOld = (p) => p.type === "seat-worktree" || !p.path || !junkPaths.some((j) => isUnder(p.path, j));
|
|
557
|
+
const keepJunk = (p) => !whole.some((w) => isUnder(p.path, w));
|
|
558
|
+
return [...older.filter(keepOld), ...junk.filter(keepJunk)];
|
|
559
|
+
}
|
|
560
|
+
|
|
481
561
|
// Bytes the safe tier's ON-DISK items (build dirs, scratch entries, whole worktrees, nested
|
|
482
562
|
// build output) would free — the summary line's number. simctl/opencode items free space
|
|
483
563
|
// inside their own stores.
|
|
484
564
|
export function freedOnDiskBytes(plan) {
|
|
485
|
-
return (plan || []).filter((p) =>
|
|
565
|
+
return (plan || []).filter((p) => ON_DISK_TYPES.includes(p.type)).reduce((n, p) => n + (p.bytes || 0), 0);
|
|
486
566
|
}
|
|
487
567
|
|
|
488
568
|
function fileSize(fs, p) {
|
|
@@ -556,7 +636,7 @@ export async function runClean(r, d) {
|
|
|
556
636
|
const g = exec("git", ["-C", p, "worktree", "remove", p]);
|
|
557
637
|
if (g.status !== 0) throw new Error(String(g.stderr || "git worktree remove failed").trim().split("\n")[0] || "git worktree remove failed");
|
|
558
638
|
results.push({ type: item.type, path: p, bytes: item.bytes || 0, ok: true });
|
|
559
|
-
} else if (
|
|
639
|
+
} else if (["build-dir", "build-output", "scratch-entry", "build-junk", "drill-output"].includes(item.type)) {
|
|
560
640
|
const p = assertUnderHome(item.path, home);
|
|
561
641
|
if (!isUnder(p, root)) throw new Error(`refused: ${p} is not under the seat worktrees root`);
|
|
562
642
|
remove(p, { recursive: true, force: true });
|
|
@@ -594,6 +674,20 @@ export function launchdPlist({ nodePath, scriptPath, logPath }) {
|
|
|
594
674
|
`;
|
|
595
675
|
}
|
|
596
676
|
|
|
677
|
+
// #12268: the daily bus message: alarm first below 15 GB, guard line below 50 GB, bytes
|
|
678
|
+
// freed from what was actually removed, not what was planned.
|
|
679
|
+
export function diskSummary(r, results) {
|
|
680
|
+
const okN = results.filter((x) => x.ok).length;
|
|
681
|
+
const failN = results.length - okN;
|
|
682
|
+
const freed = results.filter((x) => x.ok).reduce((n, x) => n + (x.bytes || 0), 0);
|
|
683
|
+
const lines = [];
|
|
684
|
+
const measured = r.totalBytes > 0;
|
|
685
|
+
if (measured && r.freeBytes < ALARM_SPACE_BYTES) lines.push(`ALARM: disk almost full, only ${fmtBytes(r.freeBytes)} free on / (alarm line is ${fmtBytes(ALARM_SPACE_BYTES)})`);
|
|
686
|
+
if (measured && r.freeBytes < LOW_SPACE_BYTES) lines.push(`low-space guard: under ${fmtBytes(LOW_SPACE_BYTES)} free, so this run pruned build and drill output from every dead seat worktree`);
|
|
687
|
+
lines.push(`disk janitor: safe tier ${okN ? `cleaned ${okN} item(s)` : "nothing to clean"}${failN ? `, ${failN} FAILED` : ""}, freed ${fmtBytes(freed)}, was ${fmtBytes(r.freeBytes)} free of ${fmtBytes(r.totalBytes)}, report: trantor disk`);
|
|
688
|
+
return lines.join("\n");
|
|
689
|
+
}
|
|
690
|
+
|
|
597
691
|
export async function runDisk(d = {}) {
|
|
598
692
|
const dep = defaults(d);
|
|
599
693
|
// --dry-run always wins: report only, never clean — whichever flag asked for cleaning.
|