@virling/subagents 0.1.1 → 0.3.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/CHANGELOG.md +15 -1
- package/README.md +7 -0
- package/package.json +1 -1
- package/src/analyze.js +85 -1
- package/src/format.js +12 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,18 @@ All notable changes to this project are documented here. The format follows [Kee
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.3.0] - 2026-11-28
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Estimated cost at API prices for each subagent and in the total (`costUsd` in `--json`), from per-model prices for Opus 5.5, Opus 5, Sonnet 5.5 and Haiku 5.5, with 1-hour cache writes at 2x input and 5-minute writes at 1.25x. Subagents on other models show no cost.
|
|
12
|
+
|
|
13
|
+
## [0.2.0] - 2026-11-28
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- Approvals section: tool calls that waited for you to approve them, grouped by reason, with folders to add to `permissions.additionalDirectories` and `Bash(...)` allow rule candidates. Each subagent shows how long it waited. `--json` includes `approvals` and `waitMs`.
|
|
18
|
+
|
|
7
19
|
## [0.1.1] - 2026-11-28
|
|
8
20
|
|
|
9
21
|
### Fixed
|
|
@@ -18,6 +30,8 @@ All notable changes to this project are documented here. The format follows [Kee
|
|
|
18
30
|
- Flags overlapping reads, repeated commands, error-heavy subagents, edit collisions and empty results.
|
|
19
31
|
- Pick a session with `--session`, a file path or `--project`; `--list` shows recent sessions; `--json` output.
|
|
20
32
|
|
|
21
|
-
[Unreleased]: https://github.com/virling/subagents/compare/v0.
|
|
33
|
+
[Unreleased]: https://github.com/virling/subagents/compare/v0.3.0...HEAD
|
|
34
|
+
[0.3.0]: https://github.com/virling/subagents/compare/v0.2.0...v0.3.0
|
|
35
|
+
[0.2.0]: https://github.com/virling/subagents/compare/v0.1.1...v0.2.0
|
|
22
36
|
[0.1.1]: https://github.com/virling/subagents/compare/v0.1.0...v0.1.1
|
|
23
37
|
[0.1.0]: https://github.com/virling/subagents/releases/tag/v0.1.0
|
package/README.md
CHANGED
|
@@ -75,6 +75,13 @@ Each subagent transcript lives at `~/.claude/projects/<project>/<session>/subage
|
|
|
75
75
|
- **edit-collision**: the same file edited by 2+ subagents.
|
|
76
76
|
- **empty-result**: the final report is under 200 characters.
|
|
77
77
|
|
|
78
|
+
## Approvals
|
|
79
|
+
|
|
80
|
+
Tool calls that waited for you to approve a permission prompt, and how long they waited in total, grouped by the reason Claude Code recorded: `outsideReadsBlocked` (the call read outside the project's folders), `safetyCheck`, `no-rule-match` and others.
|
|
81
|
+
|
|
82
|
+
- **Folders outside the project**: the folders behind `outsideReadsBlocked` prompts. Add them to `permissions.additionalDirectories` in settings, or with `/add-dir`, to stop those prompts.
|
|
83
|
+
- **Allow rule candidates**: `Bash(<command>:*)` rules for `no-rule-match` prompts. Check that each one is safe before adding it to `permissions.allow`.
|
|
84
|
+
|
|
78
85
|
Flags are hints, not verdicts: two subagents reading the same file is often fine.
|
|
79
86
|
|
|
80
87
|
## More tools from Virling
|
package/package.json
CHANGED
package/src/analyze.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
1
5
|
const AGENT_TOOLS = ["Agent", "Task"];
|
|
2
6
|
const EDIT_TOOLS = ["Edit", "Write", "MultiEdit", "NotebookEdit"];
|
|
3
7
|
export const EMPTY_REPORT_CHARS = 200;
|
|
@@ -26,6 +30,22 @@ export function launches(main) {
|
|
|
26
30
|
return { byAgent, reads };
|
|
27
31
|
}
|
|
28
32
|
|
|
33
|
+
// USD per million tokens (input, output, cache read); cache writes are 1.25x input for 5m and 2x for 1h.
|
|
34
|
+
const PRICES = {
|
|
35
|
+
"claude-opus-5-5": [4, 20, 0.2],
|
|
36
|
+
"claude-opus-5": [5, 25, 0.5],
|
|
37
|
+
"claude-sonnet-5-5": [2, 10, 0.1],
|
|
38
|
+
"claude-haiku-5-5": [0.1, 0.5, 0.01],
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export function cost(u, model) {
|
|
42
|
+
const p = PRICES[model];
|
|
43
|
+
if (!p) return null;
|
|
44
|
+
const write1h = u.cache_creation?.ephemeral_1h_input_tokens || 0;
|
|
45
|
+
const write5m = (u.cache_creation_input_tokens || 0) - write1h;
|
|
46
|
+
return ((u.input_tokens || 0) * p[0] + (u.output_tokens || 0) * p[1] + (u.cache_read_input_tokens || 0) * p[2] + write5m * p[0] * 1.25 + write1h * p[0] * 2) / 1e6;
|
|
47
|
+
}
|
|
48
|
+
|
|
29
49
|
export function summarizeAgent(id, entries, input) {
|
|
30
50
|
const tools = {};
|
|
31
51
|
const read = new Set();
|
|
@@ -38,7 +58,10 @@ export function summarizeAgent(id, entries, input) {
|
|
|
38
58
|
let first = "";
|
|
39
59
|
const times = [];
|
|
40
60
|
let active = 0;
|
|
61
|
+
let waited = 0;
|
|
41
62
|
let prev = null;
|
|
63
|
+
const uses = new Map();
|
|
64
|
+
const approvals = [];
|
|
42
65
|
for (const e of turns(entries)) {
|
|
43
66
|
const { role, content } = e.message;
|
|
44
67
|
if (e.timestamp) {
|
|
@@ -48,15 +71,22 @@ export function summarizeAgent(id, entries, input) {
|
|
|
48
71
|
const prompt = role === "user" && text(content).trim() && !blocks(content).some((c) => c.type === "tool_result");
|
|
49
72
|
const approved = role === "user" && e.permissionDecision?.source?.startsWith("user");
|
|
50
73
|
if (prev !== null && !prompt && !approved) active += t - prev;
|
|
74
|
+
if (prev !== null && approved) {
|
|
75
|
+
waited += t - prev;
|
|
76
|
+
const use = uses.get(blocks(content).find((c) => c.type === "tool_result")?.tool_use_id);
|
|
77
|
+
const reasons = (e.permissionDecision.reasonCode || "prompt").split("+").map((r) => r.replace(/^(subcommands:)?(bashMiss:)?/, ""));
|
|
78
|
+
approvals.push({ tool: use?.name || "?", target: use?.input?.command || fileOf(use?.input) || use?.input?.path || "", reasons: [...new Set(reasons)], waitMs: t - prev, cwd: e.cwd });
|
|
79
|
+
}
|
|
51
80
|
prev = t;
|
|
52
81
|
}
|
|
53
82
|
if (role === "user" && !first) first = text(content).trim();
|
|
54
|
-
if (role === "assistant" && e.message.usage) usage.set(e.message.id || e.uuid, e.message.usage);
|
|
83
|
+
if (role === "assistant" && e.message.usage) usage.set(e.message.id || e.uuid, { ...e.message.usage, model: e.message.model });
|
|
55
84
|
for (const c of blocks(content)) {
|
|
56
85
|
if (c.type === "tool_result" && c.is_error) failed++;
|
|
57
86
|
if (role !== "assistant") continue;
|
|
58
87
|
if (c.type === "text") report += `${c.text}\n`;
|
|
59
88
|
if (c.type !== "tool_use") continue;
|
|
89
|
+
uses.set(c.id, c);
|
|
60
90
|
report = "";
|
|
61
91
|
calls++;
|
|
62
92
|
tools[c.name] = (tools[c.name] || 0) + 1;
|
|
@@ -78,12 +108,16 @@ export function summarizeAgent(id, entries, input) {
|
|
|
78
108
|
tokens.cacheCreation += u.cache_creation_input_tokens || 0;
|
|
79
109
|
}
|
|
80
110
|
if (tokens) tokens.total = tokens.input + tokens.output + tokens.cacheRead + tokens.cacheCreation;
|
|
111
|
+
const costs = [...usage.values()].map((u) => cost(u, u.model));
|
|
112
|
+
const costUsd = costs.length && costs.every((c) => c !== null) ? costs.reduce((a, b) => a + b, 0) : null;
|
|
81
113
|
return {
|
|
82
114
|
id,
|
|
83
115
|
description: truncate((input?.description || first || "").replace(/\s+/g, " ").trim()),
|
|
84
116
|
start,
|
|
85
117
|
end,
|
|
86
118
|
durationMs: active,
|
|
119
|
+
waitMs: waited,
|
|
120
|
+
approvals,
|
|
87
121
|
toolCalls: calls,
|
|
88
122
|
tools,
|
|
89
123
|
failed,
|
|
@@ -92,6 +126,7 @@ export function summarizeAgent(id, entries, input) {
|
|
|
92
126
|
commands: [...commands],
|
|
93
127
|
reportChars: report.trim().length,
|
|
94
128
|
tokens,
|
|
129
|
+
costUsd,
|
|
95
130
|
};
|
|
96
131
|
}
|
|
97
132
|
|
|
@@ -127,6 +162,52 @@ export function findFlags(agents, mainReads = []) {
|
|
|
127
162
|
return flags;
|
|
128
163
|
}
|
|
129
164
|
|
|
165
|
+
const home = (p) => p.replace(/^~(?=\/|$)/, os.homedir());
|
|
166
|
+
|
|
167
|
+
function repoRoot(dir) {
|
|
168
|
+
for (let d = dir; d !== path.dirname(d); d = path.dirname(d)) if (fs.existsSync(path.join(d, ".git"))) return d;
|
|
169
|
+
return dir;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function outsideFolders(a) {
|
|
173
|
+
const dirs = [];
|
|
174
|
+
const cds = new Set([...a.target.matchAll(/(?:^|[;&|]\s*)cd\s+(\S+)/g)].map((m) => m[1]));
|
|
175
|
+
if (a.tool !== "Bash") return a.target.startsWith("/") ? [repoRoot(path.dirname(a.target))] : [];
|
|
176
|
+
for (const m of a.target.matchAll(/(?:^|[\s=])(~?\/[^\s;&|'"`)]+)/g)) {
|
|
177
|
+
const p = home(m[1]);
|
|
178
|
+
const cd = cds.has(m[1]);
|
|
179
|
+
dirs.push(repoRoot(cd || !path.extname(p) ? p : path.dirname(p)));
|
|
180
|
+
}
|
|
181
|
+
if (!dirs.length && a.cwd) dirs.push(repoRoot(a.cwd));
|
|
182
|
+
return [...new Set(dirs)];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function allowRule(a) {
|
|
186
|
+
if (a.tool !== "Bash") return `${a.tool}`;
|
|
187
|
+
const words = a.target.split(/&&|\|\||;|\|/).map((x) => x.trim().split(/\s+/).find((w) => !/^\w+=/.test(w))).filter((w) => w && w !== "cd");
|
|
188
|
+
return words.length ? `Bash(${words[0]}:*)` : null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const tally = (items) => [...items.reduce((m, k) => m.set(k, (m.get(k) || 0) + 1), new Map())].sort((x, y) => y[1] - x[1]).map(([key, n]) => ({ key, count: n }));
|
|
192
|
+
|
|
193
|
+
export function approvalSummary(agents, project) {
|
|
194
|
+
const all = agents.flatMap((a) => a.approvals);
|
|
195
|
+
const reasons = new Map();
|
|
196
|
+
for (const a of all) for (const r of a.reasons) {
|
|
197
|
+
const cur = reasons.get(r) || { reason: r, count: 0, waitMs: 0, example: a.target };
|
|
198
|
+
cur.count++;
|
|
199
|
+
cur.waitMs += a.waitMs;
|
|
200
|
+
reasons.set(r, cur);
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
count: all.length,
|
|
204
|
+
waitMs: all.reduce((s, a) => s + a.waitMs, 0),
|
|
205
|
+
reasons: [...reasons.values()].sort((x, y) => y.count - x.count),
|
|
206
|
+
folders: tally(all.filter((a) => a.reasons.includes("outsideReadsBlocked")).flatMap(outsideFolders).filter((d) => d !== project)).map(({ key, count }) => ({ dir: key, count })),
|
|
207
|
+
rules: tally(all.filter((a) => a.reasons.includes("no-rule-match")).map(allowRule).filter(Boolean)).map(({ key, count }) => ({ rule: key, count })),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
130
211
|
export function analyze({ main, agents }) {
|
|
131
212
|
const { byAgent, reads } = launches(main);
|
|
132
213
|
const summaries = agents
|
|
@@ -137,11 +218,14 @@ export function analyze({ main, agents }) {
|
|
|
137
218
|
return {
|
|
138
219
|
agents: summaries,
|
|
139
220
|
flags: findFlags(summaries, reads),
|
|
221
|
+
approvals: approvalSummary(summaries, main.find((e) => e.cwd) && repoRoot(main.find((e) => e.cwd).cwd)),
|
|
140
222
|
totals: {
|
|
141
223
|
subagents: summaries.length,
|
|
142
224
|
durationMs: summaries.reduce((s, a) => s + a.durationMs, 0),
|
|
225
|
+
waitMs: summaries.reduce((s, a) => s + a.waitMs, 0),
|
|
143
226
|
toolCalls: summaries.reduce((s, a) => s + a.toolCalls, 0),
|
|
144
227
|
tokens: known.length ? known.reduce((s, a) => s + a.tokens.total, 0) : null,
|
|
228
|
+
costUsd: summaries.some((a) => a.costUsd !== null) ? summaries.reduce((s, a) => s + (a.costUsd || 0), 0) : null,
|
|
145
229
|
},
|
|
146
230
|
};
|
|
147
231
|
}
|
package/src/format.js
CHANGED
|
@@ -13,6 +13,8 @@ export function count(n) {
|
|
|
13
13
|
return `${(n / 1e6).toFixed(1)}M`;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
const truncate = (s, n = 70) => (s.length > n ? `${s.slice(0, n - 3)}...` : s);
|
|
17
|
+
|
|
16
18
|
const time = (iso) => (iso ? new Date(iso).toLocaleString("sv").slice(5, 16) : "?");
|
|
17
19
|
|
|
18
20
|
export function formatReport(report, cwd = "") {
|
|
@@ -24,7 +26,7 @@ export function formatReport(report, cwd = "") {
|
|
|
24
26
|
.map(([name, n]) => `${name} ${n}`)
|
|
25
27
|
.join(", ");
|
|
26
28
|
lines.push(`#${a.n} ${a.id} ${a.description || "(no description)"}`);
|
|
27
|
-
lines.push(` ${time(a.start)} -> ${time(a.end)} ${duration(a.durationMs)} report ${count(a.reportChars)} chars${a.tokens ? ` tokens ${count(a.tokens.total)}` : ""}`);
|
|
29
|
+
lines.push(` ${time(a.start)} -> ${time(a.end)} ${duration(a.durationMs)} report ${count(a.reportChars)} chars${a.tokens ? ` tokens ${count(a.tokens.total)}` : ""}${a.costUsd === null ? "" : ` ~$${a.costUsd.toFixed(2)}`}${a.waitMs ? ` waited ${duration(a.waitMs)} for approval` : ""}`);
|
|
28
30
|
lines.push(` tools ${a.toolCalls}${tools ? ` (${tools})` : ""}${a.failed ? ` failed ${a.failed}` : ""}`);
|
|
29
31
|
if (a.read.length) lines.push(` read ${a.read.map(rel).join(", ")}`);
|
|
30
32
|
if (a.edited.length) lines.push(` edited ${a.edited.map(rel).join(", ")}`);
|
|
@@ -33,10 +35,18 @@ export function formatReport(report, cwd = "") {
|
|
|
33
35
|
lines.push("Flags");
|
|
34
36
|
if (!report.flags.length) lines.push(" none");
|
|
35
37
|
for (const f of report.flags) lines.push(` ${f.type}: ${f.file ? f.text.replace(f.file, rel(f.file)) : f.text}`);
|
|
38
|
+
const ap = report.approvals;
|
|
39
|
+
if (ap?.count) {
|
|
40
|
+
lines.push("", "Approvals");
|
|
41
|
+
lines.push(` ${ap.count} tool calls waited ${duration(ap.waitMs)} for you to approve them`);
|
|
42
|
+
for (const r of ap.reasons) lines.push(` ${r.reason} ${r.count} ${duration(r.waitMs)} e.g. ${truncate(r.example.replace(/\s+/g, " "))}`);
|
|
43
|
+
if (ap.folders.length) lines.push(` folders outside the project (add to permissions.additionalDirectories or run /add-dir): ${ap.folders.slice(0, 5).map((f) => `${f.dir} (${f.count})`).join(", ")}`);
|
|
44
|
+
if (ap.rules.length) lines.push(` no allow rule matched, candidates for permissions.allow: ${ap.rules.slice(0, 5).map((r) => `${r.rule} (${r.count})`).join(", ")}`);
|
|
45
|
+
}
|
|
36
46
|
const t = report.totals;
|
|
37
47
|
lines.push("");
|
|
38
48
|
lines.push(
|
|
39
|
-
`Total: ${t.subagents} subagents, ${duration(t.durationMs)}, ${t.toolCalls} tool calls${t.tokens === null ? "" : `, ${count(t.tokens)} tokens`}`
|
|
49
|
+
`Total: ${t.subagents} subagents, ${duration(t.durationMs)}, ${t.toolCalls} tool calls${t.tokens === null ? "" : `, ${count(t.tokens)} tokens`}${t.costUsd == null ? "" : `, ~$${t.costUsd.toFixed(2)} at API prices`}`
|
|
40
50
|
);
|
|
41
51
|
return lines.join("\n");
|
|
42
52
|
}
|