reevesagents 2.1.0 → 2.2.1
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/CHANGELOG.md +21 -0
- package/README.md +232 -318
- package/dist/chunk-CJKEBBUI.js +7663 -0
- package/dist/{chunk-UEYJAKAZ.js → chunk-DGLUP7Q7.js} +2 -2
- package/dist/{chunk-PWYG5IM5.js → chunk-HTCENB3Q.js} +2 -2
- package/dist/chunk-PKMTELW4.js +115 -0
- package/dist/chunk-PVYM35RS.js +1697 -0
- package/dist/{chunk-OQJNBACW.js → chunk-QWUBYDUV.js} +2 -2
- package/dist/chunk-XEOWHTRQ.js +1246 -0
- package/dist/{chunk-KROKGL2R.js → chunk-XHP63Y64.js} +879 -2
- package/dist/cli.js +1099 -13
- package/dist/index.d.ts +5 -0
- package/dist/index.js +2 -2
- package/dist/{router-AYNTF24M.js → router-S7KR2CIE.js} +146 -79
- package/dist/{server-TIFQ5JSM.js → server-4OILK2LL.js} +344 -6
- package/dist/{server-BNBSZZIP.js → server-5U4NNV43.js} +305 -14
- package/dist/{tui-launch-7DBX4JYA.js → tui-launch-7WKLVYEH.js} +2 -2
- package/dist/web/app.css +444 -11
- package/dist/web/app.js +672 -21
- package/dist/web/favicon.png +0 -0
- package/dist/web/index.html +75 -0
- package/dist/web/insights-core.js +92 -0
- package/dist/web/plan-controller.js +91 -0
- package/dist/web/plan-error.js +81 -0
- package/dist/web/tick-line.js +78 -0
- package/package.json +10 -8
- package/dist/chunk-DLWYZPW6.js +0 -3222
- package/dist/chunk-YWS3MILO.js +0 -266
package/dist/chunk-YWS3MILO.js
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
RUN_SESSION_PATTERN,
|
|
4
|
-
VIEWER_SESSION_PATTERN,
|
|
5
|
-
allWindowIds,
|
|
6
|
-
findAgent,
|
|
7
|
-
killAgent,
|
|
8
|
-
killSession,
|
|
9
|
-
listAgents,
|
|
10
|
-
listRuns,
|
|
11
|
-
listSessions,
|
|
12
|
-
loadConfig,
|
|
13
|
-
nowIso,
|
|
14
|
-
nowMs,
|
|
15
|
-
redactSecrets,
|
|
16
|
-
runDir,
|
|
17
|
-
sessionAttached,
|
|
18
|
-
sessionInGroup,
|
|
19
|
-
targetExists,
|
|
20
|
-
tmuxAvailable,
|
|
21
|
-
withRunsLock
|
|
22
|
-
} from "./chunk-DLWYZPW6.js";
|
|
23
|
-
|
|
24
|
-
// src/version.ts
|
|
25
|
-
import { readFileSync } from "fs";
|
|
26
|
-
import { URL } from "url";
|
|
27
|
-
function readVersion() {
|
|
28
|
-
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
29
|
-
if (typeof pkg.version !== "string") throw new Error("package.json version must be a string");
|
|
30
|
-
return pkg.version;
|
|
31
|
-
}
|
|
32
|
-
var REEVESAGENTS_VERSION = readVersion();
|
|
33
|
-
|
|
34
|
-
// src/core/reaper.ts
|
|
35
|
-
function sweepAgents(options = {}) {
|
|
36
|
-
const haveTmux = options.targetExists ? true : (options.tmuxAvailable ?? tmuxAvailable)();
|
|
37
|
-
if (!haveTmux) return { reaped: [] };
|
|
38
|
-
const targetExists2 = options.targetExists ?? targetExists;
|
|
39
|
-
const now = options.now ?? nowMs;
|
|
40
|
-
const maxLifetimeMs = options.maxLifetimeMs ?? loadConfig().global.max_lifetime_ms;
|
|
41
|
-
const candidates = listAgents().filter((agent) => !agent.ended_at && !agent.headless);
|
|
42
|
-
const batchWindows = !options.targetExists && candidates.some((agent) => agent.tmux_window_id) ? allWindowIds() : null;
|
|
43
|
-
const probe = batchWindows ? (id, session) => batchWindows.has(`${session}\0${id}`) || targetExists2(id, session) : targetExists2;
|
|
44
|
-
const reaped = [];
|
|
45
|
-
for (const agent of candidates) {
|
|
46
|
-
const ageMs = now() - new Date(agent.started_at).getTime();
|
|
47
|
-
let reason = null;
|
|
48
|
-
if (agent.tmux_window_id && !probe(agent.tmux_window_id, agent.tmux_session)) {
|
|
49
|
-
reason = "window-gone";
|
|
50
|
-
} else if (maxLifetimeMs > 0 && ageMs > maxLifetimeMs) {
|
|
51
|
-
reason = "lifetime-exceeded";
|
|
52
|
-
}
|
|
53
|
-
if (!reason) continue;
|
|
54
|
-
try {
|
|
55
|
-
killAgent(agent.id, options.driver ? { driver: options.driver } : {});
|
|
56
|
-
reaped.push({
|
|
57
|
-
agent_id: agent.id,
|
|
58
|
-
run_id: agent.run_id,
|
|
59
|
-
nickname: agent.nickname,
|
|
60
|
-
reason,
|
|
61
|
-
age_ms: Math.max(0, Math.round(ageMs))
|
|
62
|
-
});
|
|
63
|
-
} catch {
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return { reaped };
|
|
67
|
-
}
|
|
68
|
-
var ORPHAN_MIN_AGE_SEC = 60;
|
|
69
|
-
function sweepOrphanSessions(options = {}) {
|
|
70
|
-
const haveTmux = options.listSessions ? true : (options.tmuxAvailable ?? tmuxAvailable)();
|
|
71
|
-
if (!haveTmux) return { killed: [] };
|
|
72
|
-
const sessions = (options.listSessions ?? listSessions)();
|
|
73
|
-
const killSession2 = options.killSession ?? killSession;
|
|
74
|
-
const sessionAttached2 = options.sessionAttached ?? sessionAttached;
|
|
75
|
-
const nowSec = (options.now ?? nowMs)() / 1e3;
|
|
76
|
-
const liveRunSessions = new Set(listRuns().map((run) => run.tmux_session));
|
|
77
|
-
const killed = [];
|
|
78
|
-
for (const info of sessions) {
|
|
79
|
-
if (info.attached) continue;
|
|
80
|
-
if (!options.ignoreGrace && info.createdSec > 0 && nowSec - info.createdSec < ORPHAN_MIN_AGE_SEC) continue;
|
|
81
|
-
let orphan = false;
|
|
82
|
-
if (RUN_SESSION_PATTERN.test(info.name)) {
|
|
83
|
-
orphan = !liveRunSessions.has(info.name);
|
|
84
|
-
} else if (VIEWER_SESSION_PATTERN.test(info.name)) {
|
|
85
|
-
orphan = ![...liveRunSessions].some((s) => sessionInGroup(info, s));
|
|
86
|
-
}
|
|
87
|
-
if (!orphan) continue;
|
|
88
|
-
if (sessionAttached2(info.name)) continue;
|
|
89
|
-
try {
|
|
90
|
-
killSession2(info.name);
|
|
91
|
-
killed.push(info.name);
|
|
92
|
-
} catch {
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return { killed };
|
|
96
|
-
}
|
|
97
|
-
var lastOrphanSweepAt = 0;
|
|
98
|
-
function sweepOrphanSessionsThrottled(minIntervalMs = 15e3, options = {}) {
|
|
99
|
-
const now = nowMs();
|
|
100
|
-
if (lastOrphanSweepAt !== 0 && now - lastOrphanSweepAt < minIntervalMs) return { killed: [], swept: false };
|
|
101
|
-
lastOrphanSweepAt = now;
|
|
102
|
-
return { ...sweepOrphanSessions(options), swept: true };
|
|
103
|
-
}
|
|
104
|
-
var lastSweepAt = 0;
|
|
105
|
-
function sweepAgentsThrottled(minIntervalMs = 15e3, options = {}) {
|
|
106
|
-
const now = (options.now ?? nowMs)();
|
|
107
|
-
if (lastSweepAt !== 0 && now - lastSweepAt < minIntervalMs) return { reaped: [], swept: false };
|
|
108
|
-
lastSweepAt = now;
|
|
109
|
-
return { ...sweepAgents(options), swept: true };
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// src/core/approvals.ts
|
|
113
|
-
import {
|
|
114
|
-
chmodSync,
|
|
115
|
-
mkdirSync,
|
|
116
|
-
readdirSync,
|
|
117
|
-
readFileSync as readFileSync2,
|
|
118
|
-
renameSync,
|
|
119
|
-
writeFileSync
|
|
120
|
-
} from "fs";
|
|
121
|
-
import { randomUUID } from "crypto";
|
|
122
|
-
import { dirname, join } from "path";
|
|
123
|
-
function runApprovalsDir(runId) {
|
|
124
|
-
return join(runDir(runId), "approvals");
|
|
125
|
-
}
|
|
126
|
-
function runApprovalPath(runId, approvalId) {
|
|
127
|
-
return join(runApprovalsDir(runId), `${approvalId}.json`);
|
|
128
|
-
}
|
|
129
|
-
function atomicWriteJson(path, data) {
|
|
130
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
131
|
-
const tmpPath = `${path}.tmp`;
|
|
132
|
-
writeFileSync(tmpPath, JSON.stringify(data, null, 2), "utf-8");
|
|
133
|
-
chmodSync(tmpPath, 384);
|
|
134
|
-
renameSync(tmpPath, path);
|
|
135
|
-
}
|
|
136
|
-
function asString(value, fallback = "") {
|
|
137
|
-
return typeof value === "string" ? value : fallback;
|
|
138
|
-
}
|
|
139
|
-
function asNullableString(value) {
|
|
140
|
-
return typeof value === "string" ? value : null;
|
|
141
|
-
}
|
|
142
|
-
function normalizeApprovalStatus(value) {
|
|
143
|
-
if (value === "pending" || value === "approved" || value === "denied" || value === "expired") return value;
|
|
144
|
-
return "pending";
|
|
145
|
-
}
|
|
146
|
-
function normalizeRisk(value) {
|
|
147
|
-
if (value === "low" || value === "medium" || value === "high") return value;
|
|
148
|
-
return "medium";
|
|
149
|
-
}
|
|
150
|
-
function redactValue(value) {
|
|
151
|
-
if (typeof value === "string") return redactSecrets(value);
|
|
152
|
-
if (Array.isArray(value)) return value.map(redactValue);
|
|
153
|
-
if (typeof value === "object" && value !== null) {
|
|
154
|
-
return Object.fromEntries(
|
|
155
|
-
Object.entries(value).map(([key, item]) => [key, redactValue(item)])
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
return value;
|
|
159
|
-
}
|
|
160
|
-
function normalizeApproval(raw) {
|
|
161
|
-
return {
|
|
162
|
-
id: asString(raw.id),
|
|
163
|
-
run_id: asString(raw.run_id),
|
|
164
|
-
agent_id: asString(raw.agent_id),
|
|
165
|
-
action: asString(raw.action),
|
|
166
|
-
summary: asString(raw.summary),
|
|
167
|
-
details: typeof raw.details === "object" && raw.details !== null ? raw.details : {},
|
|
168
|
-
risk: normalizeRisk(raw.risk),
|
|
169
|
-
status: normalizeApprovalStatus(raw.status),
|
|
170
|
-
decision_note: asString(raw.decision_note),
|
|
171
|
-
requested_at: asString(raw.requested_at, nowIso()),
|
|
172
|
-
resolved_at: asNullableString(raw.resolved_at)
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
function redactApproval(approval) {
|
|
176
|
-
return {
|
|
177
|
-
...approval,
|
|
178
|
-
action: redactSecrets(approval.action),
|
|
179
|
-
summary: redactSecrets(approval.summary),
|
|
180
|
-
details: redactValue(approval.details),
|
|
181
|
-
decision_note: redactSecrets(approval.decision_note)
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
function writeApprovalUnlocked(approval) {
|
|
185
|
-
const path = runApprovalPath(approval.run_id, approval.id);
|
|
186
|
-
atomicWriteJson(path, redactApproval(approval));
|
|
187
|
-
return path;
|
|
188
|
-
}
|
|
189
|
-
function readApprovalUnlocked(runId, approvalId) {
|
|
190
|
-
try {
|
|
191
|
-
return normalizeApproval(JSON.parse(readFileSync2(runApprovalPath(runId, approvalId), "utf-8")));
|
|
192
|
-
} catch {
|
|
193
|
-
throw new Error(`Approval not found: ${approvalId}`);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
function createRunApproval(input) {
|
|
197
|
-
return withRunsLock(() => {
|
|
198
|
-
const agent = findAgent(input.agent_id);
|
|
199
|
-
const approval = {
|
|
200
|
-
id: randomUUID(),
|
|
201
|
-
run_id: agent.run_id,
|
|
202
|
-
agent_id: agent.id,
|
|
203
|
-
action: input.action,
|
|
204
|
-
summary: input.summary,
|
|
205
|
-
details: input.details ?? {},
|
|
206
|
-
risk: input.risk ?? "medium",
|
|
207
|
-
status: "pending",
|
|
208
|
-
decision_note: "",
|
|
209
|
-
requested_at: nowIso(),
|
|
210
|
-
resolved_at: null
|
|
211
|
-
};
|
|
212
|
-
writeApprovalUnlocked(approval);
|
|
213
|
-
return redactApproval(approval);
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
function readRunApproval(runId, approvalId) {
|
|
217
|
-
return readApprovalUnlocked(runId, approvalId);
|
|
218
|
-
}
|
|
219
|
-
function listRunApprovals(runId, status) {
|
|
220
|
-
const runIds = runId ? [runId] : listRuns().map((run) => run.id);
|
|
221
|
-
const approvals = [];
|
|
222
|
-
for (const id of runIds) {
|
|
223
|
-
let files;
|
|
224
|
-
try {
|
|
225
|
-
files = readdirSync(runApprovalsDir(id));
|
|
226
|
-
} catch {
|
|
227
|
-
continue;
|
|
228
|
-
}
|
|
229
|
-
for (const file of files) {
|
|
230
|
-
if (!file.endsWith(".json")) continue;
|
|
231
|
-
try {
|
|
232
|
-
approvals.push(readApprovalUnlocked(id, file.slice(0, -5)));
|
|
233
|
-
} catch {
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
return approvals.filter((approval) => !status || approval.status === status).sort((a, b) => new Date(b.requested_at).getTime() - new Date(a.requested_at).getTime());
|
|
238
|
-
}
|
|
239
|
-
function resolveRunApproval(approvalId, decision, note = "") {
|
|
240
|
-
return withRunsLock(() => {
|
|
241
|
-
const approval = listRunApprovals().find((item) => item.id === approvalId);
|
|
242
|
-
if (!approval) throw new Error(`Approval not found: ${approvalId}`);
|
|
243
|
-
if (approval.status !== "pending") return approval;
|
|
244
|
-
const updated = {
|
|
245
|
-
...approval,
|
|
246
|
-
status: decision,
|
|
247
|
-
decision_note: note,
|
|
248
|
-
resolved_at: nowIso()
|
|
249
|
-
};
|
|
250
|
-
writeApprovalUnlocked(updated);
|
|
251
|
-
return redactApproval(updated);
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
export {
|
|
256
|
-
REEVESAGENTS_VERSION,
|
|
257
|
-
sweepAgents,
|
|
258
|
-
sweepOrphanSessions,
|
|
259
|
-
sweepOrphanSessionsThrottled,
|
|
260
|
-
sweepAgentsThrottled,
|
|
261
|
-
createRunApproval,
|
|
262
|
-
readRunApproval,
|
|
263
|
-
listRunApprovals,
|
|
264
|
-
resolveRunApproval
|
|
265
|
-
};
|
|
266
|
-
//# sourceMappingURL=chunk-YWS3MILO.js.map
|