@dadado/agent-kit-cli 6.17.0 → 6.19.0
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/dashboard/dashboard-data.mjs +8 -3
- package/dashboard/dashboard.html +140 -0
- package/dashboard/lib/guards.d.mts +20 -0
- package/dashboard/lib/guards.mjs +307 -0
- package/dashboard/lib/semantic-model.mjs +228 -1
- package/dist/{add-DRV3T42D.js → add-MRI5BXHH.js} +3 -3
- package/dist/{chunk-3IEE6Q37.js → chunk-2TX6NJEG.js} +1 -1
- package/dist/{chunk-IOQ6YXA3.js → chunk-3HNTNYPR.js} +1 -1
- package/dist/{chunk-MEZU47IB.js → chunk-5EBT3V7G.js} +1 -1
- package/dist/{chunk-5IJQGIOY.js → chunk-677W4QO3.js} +63 -1
- package/dist/{chunk-SKC6QZW4.js → chunk-6WUKLS4D.js} +1 -1
- package/dist/{chunk-YO4BLHDT.js → chunk-6XJZLH53.js} +149 -18
- package/dist/{chunk-J3YLSHRK.js → chunk-7MUTZHWP.js} +23 -4
- package/dist/{chunk-CJ3JAH7L.js → chunk-BGL5DRK2.js} +2 -2
- package/dist/{chunk-IJQAFPY3.js → chunk-C4LCOOL4.js} +3 -1
- package/dist/chunk-DTSL2RH7.js +433 -0
- package/dist/{chunk-4DLMU44M.js → chunk-EBDQYFA4.js} +71 -4
- package/dist/{chunk-AQTCXUYS.js → chunk-EOQMAU2J.js} +1 -1
- package/dist/{chunk-RAMT55TC.js → chunk-G2Z37XFM.js} +3 -3
- package/dist/{chunk-HKZH2IEE.js → chunk-GTP224FI.js} +1 -1
- package/dist/{chunk-QYIV6ZP6.js → chunk-HJWSOZXS.js} +52 -12
- package/dist/{chunk-AZCPUJJO.js → chunk-IQQQDEQ4.js} +2 -2
- package/dist/{chunk-ZFJIJUZ4.js → chunk-MPCNPZJZ.js} +1 -1
- package/dist/{hook-2YEC7GT5.js → chunk-NL3I2BWA.js} +104 -113
- package/dist/{chunk-WGAOM37Y.js → chunk-OKQ37A7E.js} +9 -9
- package/dist/{chunk-WRCXRV2U.js → chunk-P7732A25.js} +10 -0
- package/dist/{chunk-6RRG3WOE.js → chunk-Q35TWISF.js} +22 -1
- package/dist/{chunk-WA7IBNIL.js → chunk-QBYJNGCD.js} +2 -2
- package/dist/chunk-QWTBYXHN.js +751 -0
- package/dist/{chunk-SC2DBY2R.js → chunk-R4DUO5DA.js} +1 -0
- package/dist/{chunk-2Y27P6KC.js → chunk-SGTTC2JP.js} +4 -3
- package/dist/{chunk-TICKIKCQ.js → chunk-U23SLQGX.js} +5 -5
- package/dist/chunk-UATQQDVR.js +297 -0
- package/dist/{chunk-3YTFXTXH.js → chunk-UXQH2CNC.js} +2 -1
- package/dist/{chunk-VBQHBSIB.js → chunk-VJWWJA36.js} +3 -3
- package/dist/{chunk-OQNJRQPZ.js → chunk-W3ZJVBNY.js} +7 -4
- package/dist/{chunk-XDCCYBCJ.js → chunk-ZMYV6PRE.js} +13 -0
- package/dist/{commands-3O2HFLTW.js → commands-NL6UOEP7.js} +51 -17
- package/dist/{conflicts-UY6VTYIO.js → conflicts-XMN4PBCZ.js} +8 -8
- package/dist/{contribute-RF47NPZ2.js → contribute-QDTEJ42W.js} +4 -4
- package/dist/{countdown-JX3DZ2QU.js → countdown-7ONIVAG6.js} +40 -12
- package/dist/{dashboard-YNCFISNO.js → dashboard-P65XHYCU.js} +1 -1
- package/dist/{dashboard-broadcast-NK7PU72L.js → dashboard-broadcast-GYK34QYL.js} +1 -1
- package/dist/{diff-SVFAUOVP.js → diff-RLB7R2NE.js} +5 -5
- package/dist/{doctor-ATKYRCT4.js → doctor-OXMDSOXL.js} +11 -11
- package/dist/{engine-info-R6GXZ2VO.js → engine-info-BBI5QO5Y.js} +3 -3
- package/dist/{ground-control-D2X6CI66.js → ground-control-IDCXN5FK.js} +5 -5
- package/dist/hook-B4VUQOQF.js +108 -0
- package/dist/index.js +28 -28
- package/dist/{init-LUJRWMHC.js → init-BYONEUCW.js} +14 -14
- package/dist/{install-VQSO2JR7.js → install-HOR6VR44.js} +14 -14
- package/dist/{mission-control-JIF6GFSV.js → mission-control-QJBSZVNI.js} +2 -2
- package/dist/{queue-IEOXOBNL.js → queue-OJHKFKK3.js} +55 -11
- package/dist/{run-L63NZHAJ.js → run-PFANZJ5Y.js} +175 -27
- package/dist/{run-plan-BWJX6R7Q.js → run-plan-7EB4ERSQ.js} +46 -16
- package/dist/{scan-BWA64R7I.js → scan-K3T5RQLC.js} +1 -1
- package/dist/session-start-OSFSF4OZ.js +74 -0
- package/dist/sessions-WQU5DONU.js +102 -0
- package/dist/{setup-global-2X5TMDCB.js → setup-global-O34KFL2C.js} +6 -6
- package/dist/{status-MOOZCB5D.js → status-QB2FFYUP.js} +8 -8
- package/dist/{update-NMSO56CQ.js → update-N2EKKSE7.js} +16 -11
- package/package.json +1 -1
- package/dist/sessions-O7MYEMCT.js +0 -343
|
@@ -0,0 +1,751 @@
|
|
|
1
|
+
import {
|
|
2
|
+
inspectQueueLease
|
|
3
|
+
} from "./chunk-DTSL2RH7.js";
|
|
4
|
+
import {
|
|
5
|
+
HANDOFF_REL
|
|
6
|
+
} from "./chunk-C4Q77GGJ.js";
|
|
7
|
+
|
|
8
|
+
// ../../dashboard/lib/chat-sessions.mjs
|
|
9
|
+
import {
|
|
10
|
+
closeSync,
|
|
11
|
+
existsSync,
|
|
12
|
+
fstatSync,
|
|
13
|
+
openSync,
|
|
14
|
+
readdirSync,
|
|
15
|
+
readSync,
|
|
16
|
+
realpathSync,
|
|
17
|
+
statSync
|
|
18
|
+
} from "fs";
|
|
19
|
+
import { join } from "path";
|
|
20
|
+
var CHAT_SESSIONS_CAP = 200;
|
|
21
|
+
var CHAT_TITLE_MAX = 80;
|
|
22
|
+
var CHAT_NAMED_TITLE_MAX = 200;
|
|
23
|
+
var CHAT_FULL_SCAN_MAX_BYTES = 64 * 1024 * 1024;
|
|
24
|
+
var CHAT_HEAD_BYTES = 2 * 1024 * 1024;
|
|
25
|
+
var CHAT_TAIL_BYTES = 8 * 1024 * 1024;
|
|
26
|
+
var CHAT_SCAN_BUDGET_BYTES = 256 * 1024 * 1024;
|
|
27
|
+
var BUDGET_HEAD_BYTES = 256 * 1024;
|
|
28
|
+
var BUDGET_TAIL_BYTES = 1024 * 1024;
|
|
29
|
+
var CHAT_VENDORS = Object.freeze(["claude", "codex", "cursor"]);
|
|
30
|
+
var SESSION_FILE_RE = /^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.jsonl$/i;
|
|
31
|
+
var SLUG_MAX = 200;
|
|
32
|
+
var READ_CHUNK = 1024 * 1024;
|
|
33
|
+
var NEWLINE = 10;
|
|
34
|
+
var MARK_CUSTOM = Buffer.from('"type":"custom-title"');
|
|
35
|
+
var MARK_AI = Buffer.from('"type":"ai-title"');
|
|
36
|
+
var MARK_USER = Buffer.from('"type":"user"');
|
|
37
|
+
var NON_PROMPT_PREFIXES = [
|
|
38
|
+
"<command-name>",
|
|
39
|
+
"<command-message>",
|
|
40
|
+
"<command-args>",
|
|
41
|
+
"<local-command-",
|
|
42
|
+
"<bash-input>",
|
|
43
|
+
"<bash-stdout>",
|
|
44
|
+
"<bash-stderr>",
|
|
45
|
+
"<system-reminder>",
|
|
46
|
+
"<task-notification>",
|
|
47
|
+
"Caveat:",
|
|
48
|
+
"[Request interrupted"
|
|
49
|
+
];
|
|
50
|
+
function slugHash(value) {
|
|
51
|
+
let h = 0;
|
|
52
|
+
for (let i = 0; i < value.length; i++) h = (h << 5) - h + value.charCodeAt(i) | 0;
|
|
53
|
+
return h;
|
|
54
|
+
}
|
|
55
|
+
function claudeProjectSlug(cwd) {
|
|
56
|
+
const raw = String(cwd ?? "");
|
|
57
|
+
const slug = raw.replace(/[^a-zA-Z0-9]/g, "-");
|
|
58
|
+
if (slug.length <= SLUG_MAX) return slug;
|
|
59
|
+
return `${slug.slice(0, SLUG_MAX)}-${Math.abs(slugHash(raw)).toString(36)}`;
|
|
60
|
+
}
|
|
61
|
+
function claudeProjectDir(cwd, opts = {}) {
|
|
62
|
+
const home = opts.home === void 0 ? process.env.HOME : opts.home;
|
|
63
|
+
if (typeof home !== "string" || !home.trim() || !home.startsWith("/")) return null;
|
|
64
|
+
return join(home, ".claude", "projects", claudeProjectSlug(cwd));
|
|
65
|
+
}
|
|
66
|
+
function cleanChatTitle(value, max = CHAT_TITLE_MAX) {
|
|
67
|
+
const text = String(value ?? "").replace(/[\u0000-\u001f\u007f-\u009f\u200e\u200f\u202a-\u202e\u2066-\u2069]/g, " ").replace(/\s+/g, " ").trim();
|
|
68
|
+
const chars = [...text];
|
|
69
|
+
if (chars.length <= max) return text;
|
|
70
|
+
return `${chars.slice(0, max - 1).join("").trimEnd()}\u2026`;
|
|
71
|
+
}
|
|
72
|
+
function promptText(record) {
|
|
73
|
+
if (record?.type !== "user" || record.isMeta === true || record.isSidechain === true) {
|
|
74
|
+
return "";
|
|
75
|
+
}
|
|
76
|
+
const content = record.message?.content;
|
|
77
|
+
let text = "";
|
|
78
|
+
if (typeof content === "string") {
|
|
79
|
+
text = content;
|
|
80
|
+
} else if (Array.isArray(content)) {
|
|
81
|
+
if (content.some((part) => part && part.type === "tool_result")) return "";
|
|
82
|
+
text = content.filter((part) => part && part.type === "text" && typeof part.text === "string").map((part) => part.text).join(" ");
|
|
83
|
+
}
|
|
84
|
+
const trimmed = text.trim();
|
|
85
|
+
if (!trimmed) return "";
|
|
86
|
+
if (NON_PROMPT_PREFIXES.some((prefix) => trimmed.startsWith(prefix))) return "";
|
|
87
|
+
return trimmed;
|
|
88
|
+
}
|
|
89
|
+
function parseRecord(line) {
|
|
90
|
+
try {
|
|
91
|
+
const value = JSON.parse(line.toString("utf8"));
|
|
92
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
93
|
+
} catch {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function forEachLine(fd, start, end, onLine) {
|
|
98
|
+
const buf = Buffer.allocUnsafe(READ_CHUNK);
|
|
99
|
+
let pending = [];
|
|
100
|
+
let skipFirst = start > 0;
|
|
101
|
+
let pos = start;
|
|
102
|
+
while (pos < end) {
|
|
103
|
+
const n = readSync(fd, buf, 0, Math.min(READ_CHUNK, end - pos), pos);
|
|
104
|
+
if (n <= 0) break;
|
|
105
|
+
pos += n;
|
|
106
|
+
let from = 0;
|
|
107
|
+
for (; ; ) {
|
|
108
|
+
const nl = buf.indexOf(NEWLINE, from);
|
|
109
|
+
if (nl === -1 || nl >= n) {
|
|
110
|
+
if (from < n) pending.push(Buffer.from(buf.subarray(from, n)));
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
const piece = buf.subarray(from, nl);
|
|
114
|
+
const line = pending.length ? Buffer.concat([...pending, piece]) : piece;
|
|
115
|
+
pending = [];
|
|
116
|
+
from = nl + 1;
|
|
117
|
+
if (skipFirst) {
|
|
118
|
+
skipFirst = false;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
onLine(line);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (pending.length && !skipFirst) onLine(Buffer.concat(pending));
|
|
125
|
+
}
|
|
126
|
+
function readChatTitle(filePath, window = {}) {
|
|
127
|
+
const fullScanMax = window.fullScanMaxBytes ?? CHAT_FULL_SCAN_MAX_BYTES;
|
|
128
|
+
const headBytes = window.headBytes ?? CHAT_HEAD_BYTES;
|
|
129
|
+
const tailBytes = window.tailBytes ?? CHAT_TAIL_BYTES;
|
|
130
|
+
let custom = "";
|
|
131
|
+
let ai = "";
|
|
132
|
+
let prompt = "";
|
|
133
|
+
let fd;
|
|
134
|
+
try {
|
|
135
|
+
fd = openSync(filePath, "r");
|
|
136
|
+
} catch {
|
|
137
|
+
return { title: null, titleSource: "none" };
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
const size = fstatSync(fd).size;
|
|
141
|
+
const visit = (line) => {
|
|
142
|
+
if (line.indexOf(MARK_CUSTOM) !== -1) {
|
|
143
|
+
const rec = parseRecord(line);
|
|
144
|
+
if (rec?.type === "custom-title" && typeof rec.customTitle === "string") {
|
|
145
|
+
const t = cleanChatTitle(rec.customTitle, CHAT_NAMED_TITLE_MAX);
|
|
146
|
+
if (t) custom = t;
|
|
147
|
+
}
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (line.indexOf(MARK_AI) !== -1) {
|
|
151
|
+
const rec = parseRecord(line);
|
|
152
|
+
if (rec?.type === "ai-title" && typeof rec.aiTitle === "string") {
|
|
153
|
+
const t = cleanChatTitle(rec.aiTitle, CHAT_NAMED_TITLE_MAX);
|
|
154
|
+
if (t) ai = t;
|
|
155
|
+
}
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (!prompt && line.indexOf(MARK_USER) !== -1) {
|
|
159
|
+
prompt = cleanChatTitle(promptText(parseRecord(line)));
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
if (size <= fullScanMax || size <= headBytes + tailBytes) {
|
|
163
|
+
forEachLine(fd, 0, size, visit);
|
|
164
|
+
} else {
|
|
165
|
+
forEachLine(fd, 0, headBytes, visit);
|
|
166
|
+
forEachLine(fd, size - tailBytes, size, visit);
|
|
167
|
+
}
|
|
168
|
+
} catch {
|
|
169
|
+
} finally {
|
|
170
|
+
closeSync(fd);
|
|
171
|
+
}
|
|
172
|
+
if (custom) return { title: custom, titleSource: "custom" };
|
|
173
|
+
if (ai) return { title: ai, titleSource: "ai" };
|
|
174
|
+
if (prompt) return { title: prompt, titleSource: "first-prompt" };
|
|
175
|
+
return { title: null, titleSource: "none" };
|
|
176
|
+
}
|
|
177
|
+
var defaultTitleCache = /* @__PURE__ */ new Map();
|
|
178
|
+
function envelope(vendor, status, projectDir, sessions = [], total = 0) {
|
|
179
|
+
return { vendor, status, projectDir, sessions, total };
|
|
180
|
+
}
|
|
181
|
+
function claudeProjectDirCandidates(cwd, home) {
|
|
182
|
+
const out = [];
|
|
183
|
+
const first = claudeProjectDir(cwd, { home });
|
|
184
|
+
if (!first) return out;
|
|
185
|
+
out.push(first);
|
|
186
|
+
try {
|
|
187
|
+
const real = realpathSync(cwd);
|
|
188
|
+
const second = claudeProjectDir(real, { home });
|
|
189
|
+
if (second && second !== first) out.push(second);
|
|
190
|
+
} catch {
|
|
191
|
+
}
|
|
192
|
+
return out;
|
|
193
|
+
}
|
|
194
|
+
function listClaudeSessions(opts) {
|
|
195
|
+
const cap = Number.isInteger(opts?.cap) && opts.cap >= 0 ? opts.cap : CHAT_SESSIONS_CAP;
|
|
196
|
+
const cache = opts?.cache ?? defaultTitleCache;
|
|
197
|
+
const candidates = claudeProjectDirCandidates(String(opts?.cwd ?? ""), opts?.home);
|
|
198
|
+
if (candidates.length === 0) return envelope("claude", "none", null);
|
|
199
|
+
const projectDir = candidates.find((dir) => existsSync(dir)) ?? candidates[0];
|
|
200
|
+
let entries;
|
|
201
|
+
try {
|
|
202
|
+
entries = readdirSync(projectDir, { withFileTypes: true });
|
|
203
|
+
} catch {
|
|
204
|
+
return envelope("claude", "none", projectDir);
|
|
205
|
+
}
|
|
206
|
+
const found = [];
|
|
207
|
+
for (const entry of entries) {
|
|
208
|
+
if (!entry.isFile()) continue;
|
|
209
|
+
const m = SESSION_FILE_RE.exec(entry.name);
|
|
210
|
+
if (!m) continue;
|
|
211
|
+
const path2 = join(projectDir, entry.name);
|
|
212
|
+
try {
|
|
213
|
+
const st = statSync(path2);
|
|
214
|
+
found.push({ id: m[1], path: path2, mtimeMs: st.mtimeMs, size: st.size });
|
|
215
|
+
} catch {
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (found.length === 0) return envelope("claude", "none", projectDir);
|
|
219
|
+
found.sort((a, b) => b.mtimeMs - a.mtimeMs || (a.id < b.id ? -1 : 1));
|
|
220
|
+
let budget = opts?.scanBudgetBytes ?? CHAT_SCAN_BUDGET_BYTES;
|
|
221
|
+
const sessions = found.slice(0, cap).map((f) => {
|
|
222
|
+
const key = `${f.path}\0${f.mtimeMs}\0${f.size}`;
|
|
223
|
+
let title = cache.get(key);
|
|
224
|
+
if (!title) {
|
|
225
|
+
const cost = f.size <= CHAT_FULL_SCAN_MAX_BYTES ? f.size : CHAT_HEAD_BYTES + CHAT_TAIL_BYTES;
|
|
226
|
+
if (cost <= budget) {
|
|
227
|
+
title = readChatTitle(f.path);
|
|
228
|
+
budget -= cost;
|
|
229
|
+
cache.set(key, title);
|
|
230
|
+
} else {
|
|
231
|
+
title = readChatTitle(f.path, {
|
|
232
|
+
fullScanMaxBytes: 0,
|
|
233
|
+
headBytes: BUDGET_HEAD_BYTES,
|
|
234
|
+
tailBytes: BUDGET_TAIL_BYTES
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
id: f.id,
|
|
240
|
+
title: title.title,
|
|
241
|
+
titleSource: title.titleSource,
|
|
242
|
+
modified: Math.floor(f.mtimeMs),
|
|
243
|
+
sizeBytes: f.size
|
|
244
|
+
};
|
|
245
|
+
});
|
|
246
|
+
return envelope("claude", "ok", projectDir, sessions, found.length);
|
|
247
|
+
}
|
|
248
|
+
function listChatSessions(opts) {
|
|
249
|
+
return CHAT_VENDORS.map(
|
|
250
|
+
(vendor) => vendor === "claude" ? listClaudeSessions(opts) : envelope(vendor, "unsupported", null)
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
function collectChats(opts) {
|
|
254
|
+
if (opts?.withhold) return { withheld: true, vendors: [] };
|
|
255
|
+
return { withheld: false, vendors: listChatSessions(opts) };
|
|
256
|
+
}
|
|
257
|
+
function shellQuote(value) {
|
|
258
|
+
const s = String(value ?? "");
|
|
259
|
+
if (/^[A-Za-z0-9_./-]+$/.test(s)) return s;
|
|
260
|
+
return `'${s.replace(/'/g, `'\\''`)}'`;
|
|
261
|
+
}
|
|
262
|
+
function formatChatAge(modifiedMs, nowMs = Date.now()) {
|
|
263
|
+
const secs = Math.floor(Math.max(0, nowMs - modifiedMs) / 1e3);
|
|
264
|
+
if (secs < 5) return "just now";
|
|
265
|
+
if (secs < 60) return `${secs}s ago`;
|
|
266
|
+
const mins = Math.floor(secs / 60);
|
|
267
|
+
if (mins < 60) return `${mins}m ago`;
|
|
268
|
+
const hrs = Math.floor(mins / 60);
|
|
269
|
+
if (hrs < 24) return `${hrs}h ago`;
|
|
270
|
+
return `${Math.floor(hrs / 24)}d ago`;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// src/plan-loop/live-roster.ts
|
|
274
|
+
import { execFile } from "child_process";
|
|
275
|
+
import { existsSync as existsSync2, readdirSync as readdirSync2, readFileSync, readlinkSync, statSync as statSync2 } from "fs";
|
|
276
|
+
import path from "path";
|
|
277
|
+
var LIVE_ROSTER_COMMAND_TIMEOUT_MS = 2e3;
|
|
278
|
+
var LIVE_ROSTER_TRANSCRIPT_WINDOW_MS = 30 * 6e4;
|
|
279
|
+
var LIVE_ROSTER_TRANSCRIPT_CAP = 5;
|
|
280
|
+
var LIVE_ROSTER_WORKTREE_PID_CAP = 10;
|
|
281
|
+
function parseEtime(text) {
|
|
282
|
+
const m = /^(?:(\d+)-)?(?:(\d+):)?(\d+):(\d+)$/.exec(text.trim());
|
|
283
|
+
if (!m) return null;
|
|
284
|
+
const [, d, h, mm, ss] = m;
|
|
285
|
+
return Number(d ?? 0) * 86400 + Number(h ?? 0) * 3600 + Number(mm) * 60 + Number(ss);
|
|
286
|
+
}
|
|
287
|
+
function parsePs(text) {
|
|
288
|
+
const rows = [];
|
|
289
|
+
for (const line of text.split(/\r?\n/)) {
|
|
290
|
+
const m = /^\s*(\d+)\s+(\d+)\s+(\S+)\s+(.*)$/.exec(line);
|
|
291
|
+
if (!m) continue;
|
|
292
|
+
const [, pid, ppid, etime, args] = m;
|
|
293
|
+
const argv = (args ?? "").trim().split(/\s+/).filter(Boolean);
|
|
294
|
+
if (argv.length === 0) continue;
|
|
295
|
+
rows.push({ pid: Number(pid), ppid: Number(ppid), ageSeconds: parseEtime(etime ?? ""), argv });
|
|
296
|
+
}
|
|
297
|
+
return rows;
|
|
298
|
+
}
|
|
299
|
+
var CLAUDE_HELPER_ARGS = /* @__PURE__ */ new Set([
|
|
300
|
+
"bg-pty-host",
|
|
301
|
+
"--bg-pty-host",
|
|
302
|
+
"bg-spare",
|
|
303
|
+
"--bg-spare",
|
|
304
|
+
"daemon",
|
|
305
|
+
"--chrome-native-host",
|
|
306
|
+
"mcp"
|
|
307
|
+
]);
|
|
308
|
+
var AGENT_KIT_SUBCOMMANDS = /* @__PURE__ */ new Set(["run-plan-all", "run-plan", "countdown", "run"]);
|
|
309
|
+
var NODE_BINS = /* @__PURE__ */ new Set(["node", "node.exe", "bun", "deno"]);
|
|
310
|
+
function flagValue(argv, flag) {
|
|
311
|
+
for (let i = 0; i < argv.length; i++) {
|
|
312
|
+
const a = argv[i];
|
|
313
|
+
if (a === flag) return argv[i + 1] ?? null;
|
|
314
|
+
if (a.startsWith(`${flag}=`)) return a.slice(flag.length + 1);
|
|
315
|
+
}
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
function isAgentKitScript(p) {
|
|
319
|
+
const norm = p.replace(/\\/g, "/");
|
|
320
|
+
return /(^|\/)agent-kit(\.m?js)?$/.test(norm) || /agent-kit[^/]*\/(?:packages\/cli\/)?(?:dist|bin)\/[^/]+\.m?js$/.test(norm) || /\/colony\/engine\/[^/]+\/dist\/index\.m?js$/.test(norm);
|
|
321
|
+
}
|
|
322
|
+
function classifyProcess(argv) {
|
|
323
|
+
const exe = path.basename(argv[0] ?? "");
|
|
324
|
+
if (exe === "claude") {
|
|
325
|
+
if (argv.slice(0, 3).some((a) => CLAUDE_HELPER_ARGS.has(a))) return null;
|
|
326
|
+
const headless = argv.includes("-p") || argv.includes("--print");
|
|
327
|
+
const sessionId = flagValue(argv, "--session-id") ?? flagValue(argv, "--resume");
|
|
328
|
+
return {
|
|
329
|
+
agent: "claude",
|
|
330
|
+
kind: headless ? "headless" : "interactive",
|
|
331
|
+
role: headless ? "claude -p" : "claude chat",
|
|
332
|
+
sessionId: sessionId && /^[0-9a-f-]{8,}$/i.test(sessionId) ? sessionId : null,
|
|
333
|
+
plan: null,
|
|
334
|
+
todo: null
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
const cursorAt = [0, 1].find((i) => path.basename(argv[i] ?? "") === "cursor-agent");
|
|
338
|
+
if (cursorAt !== void 0 && (cursorAt === 0 || NODE_BINS.has(exe))) {
|
|
339
|
+
const headless = argv.includes("-p") || argv.includes("--print");
|
|
340
|
+
return {
|
|
341
|
+
agent: "cursor-agent",
|
|
342
|
+
kind: headless ? "headless" : "interactive",
|
|
343
|
+
role: headless ? "cursor-agent -p" : "cursor-agent",
|
|
344
|
+
sessionId: null,
|
|
345
|
+
plan: null,
|
|
346
|
+
todo: null
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
let rest = null;
|
|
350
|
+
if (/^agent-kit(\.m?js)?$/.test(exe)) rest = argv.slice(1);
|
|
351
|
+
else if (NODE_BINS.has(exe)) {
|
|
352
|
+
const script = argv.findIndex((a, i) => i > 0 && !a.startsWith("-"));
|
|
353
|
+
if (script > 0 && isAgentKitScript(argv[script])) rest = argv.slice(script + 1);
|
|
354
|
+
}
|
|
355
|
+
if (!rest) return null;
|
|
356
|
+
const sub = rest.find((a) => !a.startsWith("-"));
|
|
357
|
+
if (!sub || !AGENT_KIT_SUBCOMMANDS.has(sub)) return null;
|
|
358
|
+
const events = flagValue(rest, "--events");
|
|
359
|
+
let role = sub;
|
|
360
|
+
if (sub === "run") {
|
|
361
|
+
const slash = rest[rest.indexOf("run") + 1];
|
|
362
|
+
role = slash && !slash.startsWith("-") ? `run ${slash}` : "run";
|
|
363
|
+
}
|
|
364
|
+
return {
|
|
365
|
+
agent: "agent-kit",
|
|
366
|
+
kind: events === "ndjson" ? "driver" : "headless",
|
|
367
|
+
role,
|
|
368
|
+
sessionId: null,
|
|
369
|
+
plan: flagValue(rest, "--plan"),
|
|
370
|
+
todo: flagValue(rest, "--todo")
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
function parseWorktreePorcelain(text) {
|
|
374
|
+
const out = [];
|
|
375
|
+
let cur = null;
|
|
376
|
+
for (const line of text.split(/\r?\n/)) {
|
|
377
|
+
if (line.startsWith("worktree ")) {
|
|
378
|
+
cur = { path: line.slice("worktree ".length), branch: null };
|
|
379
|
+
out.push(cur);
|
|
380
|
+
} else if (cur && line.startsWith("branch ")) {
|
|
381
|
+
cur.branch = line.slice("branch ".length).replace(/^refs\/heads\//, "");
|
|
382
|
+
} else if (cur && line === "detached") {
|
|
383
|
+
cur.branch = "(detached)";
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return out;
|
|
387
|
+
}
|
|
388
|
+
function inside(dir, base) {
|
|
389
|
+
return dir === base || dir.startsWith(base.endsWith(path.sep) ? base : `${base}${path.sep}`);
|
|
390
|
+
}
|
|
391
|
+
function readHandoffSummary(text) {
|
|
392
|
+
if (!text) return { plan: null, queueStatus: null };
|
|
393
|
+
const field = (name) => {
|
|
394
|
+
const m = new RegExp(`^- \\*\\*${name}:\\*\\*\\s*(.+)$`, "m").exec(text);
|
|
395
|
+
return m?.[1]?.trim() ?? null;
|
|
396
|
+
};
|
|
397
|
+
const plan = field("Plan")?.replace(/`/g, "").split(/\s+/)[0]?.replace(/[,;]$/, "");
|
|
398
|
+
const status = field("Queue status")?.split(/[\s(]/)[0]?.replace(/[,;]$/, "");
|
|
399
|
+
return { plan: plan || null, queueStatus: status || null };
|
|
400
|
+
}
|
|
401
|
+
function composeLiveRoster(input) {
|
|
402
|
+
const root = path.resolve(input.root);
|
|
403
|
+
const notes = [...input.notes ?? []];
|
|
404
|
+
const ps = input.ps === null ? [] : parsePs(input.ps);
|
|
405
|
+
if (input.ps === null) notes.push("ps unavailable: no process rows");
|
|
406
|
+
if (input.allPids === null) {
|
|
407
|
+
notes.push("no /proc: working directories unknown, processes scoped by command line only");
|
|
408
|
+
}
|
|
409
|
+
const byPid = new Map(ps.map((r) => [r.pid, r]));
|
|
410
|
+
const selfChain = /* @__PURE__ */ new Set();
|
|
411
|
+
for (let p = input.selfPid, guard = 0; p > 1 && guard < 64; guard++) {
|
|
412
|
+
selfChain.add(p);
|
|
413
|
+
const row = byPid.get(p);
|
|
414
|
+
if (!row) break;
|
|
415
|
+
p = row.ppid;
|
|
416
|
+
}
|
|
417
|
+
const worktrees = input.worktreePorcelain === null ? null : parseWorktreePorcelain(input.worktreePorcelain);
|
|
418
|
+
if (worktrees === null) notes.push("git worktree list unavailable: worktree rows skipped");
|
|
419
|
+
const linked = (worktrees ?? []).map((w) => ({ ...w, path: path.resolve(w.path) })).filter((w) => w.path !== root).sort((a, b) => b.path.length - a.path.length);
|
|
420
|
+
const worktreeOf = (cwd) => linked.find((w) => inside(cwd, w.path))?.path ?? null;
|
|
421
|
+
const nestedCache = /* @__PURE__ */ new Map();
|
|
422
|
+
const inNestedRepo = (cwd) => {
|
|
423
|
+
if (!input.isNestedRepo || !inside(cwd, root) || cwd === root) return false;
|
|
424
|
+
const cached = nestedCache.get(cwd);
|
|
425
|
+
if (cached !== void 0) return cached;
|
|
426
|
+
let found = false;
|
|
427
|
+
for (let dir = cwd; dir !== root && inside(dir, root); dir = path.dirname(dir)) {
|
|
428
|
+
if (input.isNestedRepo(dir)) {
|
|
429
|
+
found = true;
|
|
430
|
+
break;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
nestedCache.set(cwd, found);
|
|
434
|
+
return found;
|
|
435
|
+
};
|
|
436
|
+
const mentionsRoot = (argv) => argv.some((a) => a === root || a.startsWith(`${root}/`) || a.startsWith(`--cwd=${root}`));
|
|
437
|
+
const candidates = [];
|
|
438
|
+
for (const row of ps) {
|
|
439
|
+
const c = classifyProcess(row.argv);
|
|
440
|
+
if (!c) continue;
|
|
441
|
+
const cwd = input.cwdOf(row.pid);
|
|
442
|
+
let worktree = null;
|
|
443
|
+
let scoped = false;
|
|
444
|
+
if (cwd) {
|
|
445
|
+
worktree = worktreeOf(cwd);
|
|
446
|
+
scoped = worktree !== null || inside(cwd, root) && !inNestedRepo(cwd);
|
|
447
|
+
} else {
|
|
448
|
+
scoped = mentionsRoot(row.argv);
|
|
449
|
+
}
|
|
450
|
+
if (scoped) candidates.push({ ps: row, c, cwd, worktree });
|
|
451
|
+
}
|
|
452
|
+
const agentPids = new Set(candidates.map((x) => x.ps.pid));
|
|
453
|
+
const nearestAgentAncestor = (pid) => {
|
|
454
|
+
let p = byPid.get(pid)?.ppid ?? 0;
|
|
455
|
+
for (let guard = 0; p > 1 && guard < 64; guard++) {
|
|
456
|
+
if (agentPids.has(p)) return p;
|
|
457
|
+
p = byPid.get(p)?.ppid ?? 0;
|
|
458
|
+
}
|
|
459
|
+
return null;
|
|
460
|
+
};
|
|
461
|
+
const lease = input.lease.kind === "free" ? null : input.lease.lease;
|
|
462
|
+
const leasePids = /* @__PURE__ */ new Set();
|
|
463
|
+
if (lease && input.lease.kind !== "stale") {
|
|
464
|
+
leasePids.add(lease.dispatcher.pid);
|
|
465
|
+
if (lease.agent) leasePids.add(lease.agent.pid);
|
|
466
|
+
}
|
|
467
|
+
const rows = candidates.map(({ ps: r, c, cwd, worktree }) => {
|
|
468
|
+
const parentPid = nearestAgentAncestor(r.pid);
|
|
469
|
+
return {
|
|
470
|
+
kind: parentPid !== null ? "worker" : c.kind,
|
|
471
|
+
role: c.role,
|
|
472
|
+
pid: r.pid,
|
|
473
|
+
parentPid,
|
|
474
|
+
sessionId: c.sessionId ?? (leasePids.has(r.pid) && lease ? lease.session : null),
|
|
475
|
+
plan: c.plan,
|
|
476
|
+
todo: c.todo,
|
|
477
|
+
ageSeconds: r.ageSeconds,
|
|
478
|
+
cwd,
|
|
479
|
+
worktree,
|
|
480
|
+
self: false,
|
|
481
|
+
leaseHolder: leasePids.has(r.pid)
|
|
482
|
+
};
|
|
483
|
+
});
|
|
484
|
+
const selfPids = /* @__PURE__ */ new Set();
|
|
485
|
+
for (const row of rows) {
|
|
486
|
+
if (row.pid !== null && selfChain.has(row.pid)) selfPids.add(row.pid);
|
|
487
|
+
}
|
|
488
|
+
for (const row of rows) {
|
|
489
|
+
let p = row.parentPid;
|
|
490
|
+
let self = row.pid !== null && selfPids.has(row.pid);
|
|
491
|
+
for (let guard = 0; !self && p !== null && guard < 64; guard++) {
|
|
492
|
+
if (selfPids.has(p)) self = true;
|
|
493
|
+
p = rows.find((x) => x.pid === p)?.parentPid ?? null;
|
|
494
|
+
}
|
|
495
|
+
row.self = self || input.lease.kind === "own" && row.leaseHolder;
|
|
496
|
+
}
|
|
497
|
+
if (lease && (input.lease.kind === "held" || input.lease.kind === "own")) {
|
|
498
|
+
const seen = rows.some((r) => r.pid !== null && leasePids.has(r.pid));
|
|
499
|
+
if (!seen) {
|
|
500
|
+
rows.unshift({
|
|
501
|
+
kind: "headless",
|
|
502
|
+
role: `lease holder (host ${lease.host})`,
|
|
503
|
+
pid: lease.dispatcher.pid,
|
|
504
|
+
parentPid: null,
|
|
505
|
+
sessionId: lease.session,
|
|
506
|
+
plan: null,
|
|
507
|
+
todo: null,
|
|
508
|
+
ageSeconds: Number.isFinite(Date.parse(lease.startedAt)) ? Math.max(0, Math.floor((input.now - Date.parse(lease.startedAt)) / 1e3)) : null,
|
|
509
|
+
cwd: null,
|
|
510
|
+
worktree: null,
|
|
511
|
+
self: input.lease.kind === "own",
|
|
512
|
+
leaseHolder: true
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
if (input.audit === null) notes.push("tmux/screen listing unavailable: audit rows skipped");
|
|
517
|
+
for (const a of input.audit ?? []) {
|
|
518
|
+
rows.push({
|
|
519
|
+
kind: "audit",
|
|
520
|
+
role: `audit (${a.channel})`,
|
|
521
|
+
pid: null,
|
|
522
|
+
parentPid: null,
|
|
523
|
+
sessionId: a.name,
|
|
524
|
+
plan: null,
|
|
525
|
+
todo: null,
|
|
526
|
+
ageSeconds: a.ageSeconds >= 0 ? a.ageSeconds : null,
|
|
527
|
+
cwd: null,
|
|
528
|
+
worktree: null,
|
|
529
|
+
self: false,
|
|
530
|
+
leaseHolder: false
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
const order = {
|
|
534
|
+
driver: 1,
|
|
535
|
+
headless: 2,
|
|
536
|
+
interactive: 3,
|
|
537
|
+
worker: 4,
|
|
538
|
+
audit: 5
|
|
539
|
+
};
|
|
540
|
+
rows.sort(
|
|
541
|
+
(a, b) => Number(b.leaseHolder) - Number(a.leaseHolder) || order[a.kind] - order[b.kind] || (b.ageSeconds ?? -1) - (a.ageSeconds ?? -1) || (a.pid ?? 0) - (b.pid ?? 0)
|
|
542
|
+
);
|
|
543
|
+
const worktreeRows = [];
|
|
544
|
+
if (input.allPids !== null && linked.length > 0) {
|
|
545
|
+
const hits = /* @__PURE__ */ new Map();
|
|
546
|
+
for (const pid of input.allPids) {
|
|
547
|
+
const cwd = input.cwdOf(pid);
|
|
548
|
+
if (!cwd) continue;
|
|
549
|
+
const w = worktreeOf(cwd);
|
|
550
|
+
if (!w) continue;
|
|
551
|
+
const list = hits.get(w) ?? [];
|
|
552
|
+
list.push(pid);
|
|
553
|
+
hits.set(w, list);
|
|
554
|
+
}
|
|
555
|
+
for (const w of [...linked].sort((a, b) => a.path.localeCompare(b.path))) {
|
|
556
|
+
const pids = (hits.get(w.path) ?? []).sort((a, b) => a - b);
|
|
557
|
+
if (pids.length === 0) continue;
|
|
558
|
+
worktreeRows.push({
|
|
559
|
+
path: w.path,
|
|
560
|
+
branch: w.branch,
|
|
561
|
+
pids: pids.slice(0, LIVE_ROSTER_WORKTREE_PID_CAP),
|
|
562
|
+
self: pids.some((p) => selfChain.has(p))
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
if (input.transcripts === null) notes.push("no Claude transcript folder for this workspace");
|
|
567
|
+
const transcripts = (input.transcripts ?? []).filter((t) => input.now - t.modifiedMs <= LIVE_ROSTER_TRANSCRIPT_WINDOW_MS).sort((a, b) => b.modifiedMs - a.modifiedMs).slice(0, LIVE_ROSTER_TRANSCRIPT_CAP).map((t) => ({
|
|
568
|
+
id: t.id,
|
|
569
|
+
modified: new Date(t.modifiedMs).toISOString(),
|
|
570
|
+
ageSeconds: Math.max(0, Math.floor((input.now - t.modifiedMs) / 1e3))
|
|
571
|
+
}));
|
|
572
|
+
return {
|
|
573
|
+
version: 1,
|
|
574
|
+
root,
|
|
575
|
+
generatedAt: new Date(input.now).toISOString(),
|
|
576
|
+
lease: input.lease,
|
|
577
|
+
handoff: readHandoffSummary(input.handoffText),
|
|
578
|
+
rows,
|
|
579
|
+
worktrees: worktreeRows,
|
|
580
|
+
transcripts,
|
|
581
|
+
notes
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
function runBounded(cmd, args, cwd, timeoutMs) {
|
|
585
|
+
return new Promise((resolve) => {
|
|
586
|
+
try {
|
|
587
|
+
execFile(
|
|
588
|
+
cmd,
|
|
589
|
+
args,
|
|
590
|
+
{ cwd, timeout: timeoutMs, maxBuffer: 8 * 1024 * 1024, encoding: "utf8" },
|
|
591
|
+
(err, stdout) => resolve(err ? null : stdout)
|
|
592
|
+
);
|
|
593
|
+
} catch {
|
|
594
|
+
resolve(null);
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
function procPids() {
|
|
599
|
+
if (process.platform !== "linux") return null;
|
|
600
|
+
try {
|
|
601
|
+
return readdirSync2("/proc").filter((n) => /^\d+$/.test(n)).map(Number);
|
|
602
|
+
} catch {
|
|
603
|
+
return null;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
function procCwd(pid) {
|
|
607
|
+
if (process.platform !== "linux") return null;
|
|
608
|
+
try {
|
|
609
|
+
return readlinkSync(`/proc/${pid}/cwd`);
|
|
610
|
+
} catch {
|
|
611
|
+
return null;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
function listTranscriptTimes(root, home) {
|
|
615
|
+
const dir = claudeProjectDir(root, { home });
|
|
616
|
+
if (!dir) return null;
|
|
617
|
+
let names;
|
|
618
|
+
try {
|
|
619
|
+
names = readdirSync2(dir);
|
|
620
|
+
} catch {
|
|
621
|
+
return null;
|
|
622
|
+
}
|
|
623
|
+
const out = [];
|
|
624
|
+
for (const name of names) {
|
|
625
|
+
const m = /^([0-9a-f-]{36})\.jsonl$/i.exec(name);
|
|
626
|
+
if (!m) continue;
|
|
627
|
+
try {
|
|
628
|
+
const st = statSync2(path.join(dir, name));
|
|
629
|
+
if (st.isFile()) out.push({ id: m[1], modifiedMs: st.mtimeMs });
|
|
630
|
+
} catch {
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
return out;
|
|
634
|
+
}
|
|
635
|
+
async function collectLiveRoster(rootDir, deps = {}) {
|
|
636
|
+
const root = path.resolve(rootDir);
|
|
637
|
+
const timeout = deps.timeoutMs ?? LIVE_ROSTER_COMMAND_TIMEOUT_MS;
|
|
638
|
+
const notes = [];
|
|
639
|
+
const [psText, porcelain, audit] = await Promise.all([
|
|
640
|
+
runBounded("ps", ["-axo", "pid=,ppid=,etime=,args="], root, timeout),
|
|
641
|
+
runBounded("git", ["worktree", "list", "--porcelain"], root, timeout),
|
|
642
|
+
(deps.listAudit ?? (async () => []))().catch(() => null)
|
|
643
|
+
]);
|
|
644
|
+
let lease;
|
|
645
|
+
try {
|
|
646
|
+
lease = deps.lease ?? inspectQueueLease(root);
|
|
647
|
+
} catch {
|
|
648
|
+
lease = { kind: "free" };
|
|
649
|
+
notes.push("queue lease unreadable");
|
|
650
|
+
}
|
|
651
|
+
let handoffText = null;
|
|
652
|
+
try {
|
|
653
|
+
handoffText = readFileSync(path.join(root, HANDOFF_REL), "utf8");
|
|
654
|
+
} catch {
|
|
655
|
+
}
|
|
656
|
+
let transcripts = null;
|
|
657
|
+
try {
|
|
658
|
+
transcripts = listTranscriptTimes(root, deps.home);
|
|
659
|
+
} catch {
|
|
660
|
+
transcripts = null;
|
|
661
|
+
}
|
|
662
|
+
return composeLiveRoster({
|
|
663
|
+
root,
|
|
664
|
+
now: (deps.now ?? Date.now)(),
|
|
665
|
+
ps: psText,
|
|
666
|
+
cwdOf: procCwd,
|
|
667
|
+
allPids: procPids(),
|
|
668
|
+
selfPid: deps.selfPid ?? process.pid,
|
|
669
|
+
worktreePorcelain: porcelain,
|
|
670
|
+
lease,
|
|
671
|
+
handoffText,
|
|
672
|
+
transcripts,
|
|
673
|
+
audit,
|
|
674
|
+
isNestedRepo: (dir) => existsSync2(path.join(dir, ".git")),
|
|
675
|
+
notes
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
function formatRosterAge(seconds) {
|
|
679
|
+
if (seconds === null) return "?";
|
|
680
|
+
if (seconds >= 86400) return `${Math.floor(seconds / 86400)}d`;
|
|
681
|
+
if (seconds >= 3600) return `${Math.floor(seconds / 3600)}h`;
|
|
682
|
+
if (seconds >= 60) return `${Math.floor(seconds / 60)}m`;
|
|
683
|
+
return `${seconds}s`;
|
|
684
|
+
}
|
|
685
|
+
function formatRosterLease(roster) {
|
|
686
|
+
const v = roster.lease;
|
|
687
|
+
const plan = roster.handoff.plan ? `; HANDOFF plan ${roster.handoff.plan}` : "";
|
|
688
|
+
const status = roster.handoff.queueStatus ? `, Queue status ${roster.handoff.queueStatus}` : "";
|
|
689
|
+
switch (v.kind) {
|
|
690
|
+
case "free":
|
|
691
|
+
return "Queue lease: free.";
|
|
692
|
+
case "own":
|
|
693
|
+
return `Queue lease: held by this session (${v.lease.session}${plan}${status}).`;
|
|
694
|
+
case "stale":
|
|
695
|
+
return `Queue lease: stale (${v.reason}).`;
|
|
696
|
+
case "held":
|
|
697
|
+
return `Queue lease: HELD by another live session (${v.reason}; session ${v.lease.session}${v.lease.agent ? `, agent pid ${v.lease.agent.pid}` : ""}${plan}${status}).`;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
function formatRosterRow(row, root) {
|
|
701
|
+
const bits = [row.kind.padEnd(11), row.pid === null ? "-".padEnd(8) : String(row.pid).padEnd(8)];
|
|
702
|
+
bits.push(formatRosterAge(row.ageSeconds).padEnd(4), row.role);
|
|
703
|
+
const extra = [];
|
|
704
|
+
if (row.parentPid !== null) extra.push(`under pid ${row.parentPid}`);
|
|
705
|
+
if (row.leaseHolder) extra.push("lease holder");
|
|
706
|
+
if (row.sessionId) extra.push(`session ${row.sessionId}`);
|
|
707
|
+
if (row.plan) extra.push(`plan ${row.plan}`);
|
|
708
|
+
if (row.todo) extra.push(`to-do ${row.todo}`);
|
|
709
|
+
if (row.worktree) extra.push(`worktree ${row.worktree}`);
|
|
710
|
+
else if (row.cwd && row.cwd !== root) extra.push(`cwd ${row.cwd}`);
|
|
711
|
+
if (row.self) extra.push("this session");
|
|
712
|
+
return ` ${bits.join(" ")}${extra.length ? ` (${extra.join(", ")})` : ""}`;
|
|
713
|
+
}
|
|
714
|
+
function renderLiveRoster(roster) {
|
|
715
|
+
const lines = [
|
|
716
|
+
`Live agents in ${roster.root} (${roster.generatedAt})`,
|
|
717
|
+
formatRosterLease(roster)
|
|
718
|
+
];
|
|
719
|
+
if (roster.rows.length === 0) lines.push(" No live agent process in this workspace.");
|
|
720
|
+
for (const row of roster.rows) lines.push(formatRosterRow(row, roster.root));
|
|
721
|
+
if (roster.worktrees.length > 0) {
|
|
722
|
+
lines.push("", "Worktrees with a live process (do not reuse them):");
|
|
723
|
+
for (const w of roster.worktrees) {
|
|
724
|
+
lines.push(
|
|
725
|
+
` ${w.path}${w.branch ? ` [${w.branch}]` : ""} pids ${w.pids.join(", ")}${w.self ? " (this session)" : ""}`
|
|
726
|
+
);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
if (roster.transcripts.length > 0) {
|
|
730
|
+
lines.push(
|
|
731
|
+
"",
|
|
732
|
+
"Claude transcripts written in the last 30 min (a hint, not proof of liveness):"
|
|
733
|
+
);
|
|
734
|
+
for (const t of roster.transcripts) {
|
|
735
|
+
lines.push(` ${t.id} ${formatRosterAge(t.ageSeconds)} ago`);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
if (roster.notes.length > 0) lines.push("", `Notes: ${roster.notes.join("; ")}.`);
|
|
739
|
+
return lines.join("\n");
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
export {
|
|
743
|
+
cleanChatTitle,
|
|
744
|
+
collectChats,
|
|
745
|
+
shellQuote,
|
|
746
|
+
formatChatAge,
|
|
747
|
+
collectLiveRoster,
|
|
748
|
+
formatRosterLease,
|
|
749
|
+
formatRosterRow,
|
|
750
|
+
renderLiveRoster
|
|
751
|
+
};
|