@virling/subagents 0.1.1 → 0.2.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 +8 -1
- package/README.md +7 -0
- package/package.json +1 -1
- package/src/analyze.js +64 -0
- package/src/format.js +11 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,12 @@ All notable changes to this project are documented here. The format follows [Kee
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.2.0] - 2026-11-28
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- 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`.
|
|
12
|
+
|
|
7
13
|
## [0.1.1] - 2026-11-28
|
|
8
14
|
|
|
9
15
|
### Fixed
|
|
@@ -18,6 +24,7 @@ All notable changes to this project are documented here. The format follows [Kee
|
|
|
18
24
|
- Flags overlapping reads, repeated commands, error-heavy subagents, edit collisions and empty results.
|
|
19
25
|
- Pick a session with `--session`, a file path or `--project`; `--list` shows recent sessions; `--json` output.
|
|
20
26
|
|
|
21
|
-
[Unreleased]: https://github.com/virling/subagents/compare/v0.
|
|
27
|
+
[Unreleased]: https://github.com/virling/subagents/compare/v0.2.0...HEAD
|
|
28
|
+
[0.2.0]: https://github.com/virling/subagents/compare/v0.1.1...v0.2.0
|
|
22
29
|
[0.1.1]: https://github.com/virling/subagents/compare/v0.1.0...v0.1.1
|
|
23
30
|
[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;
|
|
@@ -38,7 +42,10 @@ export function summarizeAgent(id, entries, input) {
|
|
|
38
42
|
let first = "";
|
|
39
43
|
const times = [];
|
|
40
44
|
let active = 0;
|
|
45
|
+
let waited = 0;
|
|
41
46
|
let prev = null;
|
|
47
|
+
const uses = new Map();
|
|
48
|
+
const approvals = [];
|
|
42
49
|
for (const e of turns(entries)) {
|
|
43
50
|
const { role, content } = e.message;
|
|
44
51
|
if (e.timestamp) {
|
|
@@ -48,6 +55,12 @@ export function summarizeAgent(id, entries, input) {
|
|
|
48
55
|
const prompt = role === "user" && text(content).trim() && !blocks(content).some((c) => c.type === "tool_result");
|
|
49
56
|
const approved = role === "user" && e.permissionDecision?.source?.startsWith("user");
|
|
50
57
|
if (prev !== null && !prompt && !approved) active += t - prev;
|
|
58
|
+
if (prev !== null && approved) {
|
|
59
|
+
waited += t - prev;
|
|
60
|
+
const use = uses.get(blocks(content).find((c) => c.type === "tool_result")?.tool_use_id);
|
|
61
|
+
const reasons = (e.permissionDecision.reasonCode || "prompt").split("+").map((r) => r.replace(/^(subcommands:)?(bashMiss:)?/, ""));
|
|
62
|
+
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 });
|
|
63
|
+
}
|
|
51
64
|
prev = t;
|
|
52
65
|
}
|
|
53
66
|
if (role === "user" && !first) first = text(content).trim();
|
|
@@ -57,6 +70,7 @@ export function summarizeAgent(id, entries, input) {
|
|
|
57
70
|
if (role !== "assistant") continue;
|
|
58
71
|
if (c.type === "text") report += `${c.text}\n`;
|
|
59
72
|
if (c.type !== "tool_use") continue;
|
|
73
|
+
uses.set(c.id, c);
|
|
60
74
|
report = "";
|
|
61
75
|
calls++;
|
|
62
76
|
tools[c.name] = (tools[c.name] || 0) + 1;
|
|
@@ -84,6 +98,8 @@ export function summarizeAgent(id, entries, input) {
|
|
|
84
98
|
start,
|
|
85
99
|
end,
|
|
86
100
|
durationMs: active,
|
|
101
|
+
waitMs: waited,
|
|
102
|
+
approvals,
|
|
87
103
|
toolCalls: calls,
|
|
88
104
|
tools,
|
|
89
105
|
failed,
|
|
@@ -127,6 +143,52 @@ export function findFlags(agents, mainReads = []) {
|
|
|
127
143
|
return flags;
|
|
128
144
|
}
|
|
129
145
|
|
|
146
|
+
const home = (p) => p.replace(/^~(?=\/|$)/, os.homedir());
|
|
147
|
+
|
|
148
|
+
function repoRoot(dir) {
|
|
149
|
+
for (let d = dir; d !== path.dirname(d); d = path.dirname(d)) if (fs.existsSync(path.join(d, ".git"))) return d;
|
|
150
|
+
return dir;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function outsideFolders(a) {
|
|
154
|
+
const dirs = [];
|
|
155
|
+
const cds = new Set([...a.target.matchAll(/(?:^|[;&|]\s*)cd\s+(\S+)/g)].map((m) => m[1]));
|
|
156
|
+
if (a.tool !== "Bash") return a.target.startsWith("/") ? [repoRoot(path.dirname(a.target))] : [];
|
|
157
|
+
for (const m of a.target.matchAll(/(?:^|[\s=])(~?\/[^\s;&|'"`)]+)/g)) {
|
|
158
|
+
const p = home(m[1]);
|
|
159
|
+
const cd = cds.has(m[1]);
|
|
160
|
+
dirs.push(repoRoot(cd || !path.extname(p) ? p : path.dirname(p)));
|
|
161
|
+
}
|
|
162
|
+
if (!dirs.length && a.cwd) dirs.push(repoRoot(a.cwd));
|
|
163
|
+
return [...new Set(dirs)];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function allowRule(a) {
|
|
167
|
+
if (a.tool !== "Bash") return `${a.tool}`;
|
|
168
|
+
const words = a.target.split(/&&|\|\||;|\|/).map((x) => x.trim().split(/\s+/).find((w) => !/^\w+=/.test(w))).filter((w) => w && w !== "cd");
|
|
169
|
+
return words.length ? `Bash(${words[0]}:*)` : null;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
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 }));
|
|
173
|
+
|
|
174
|
+
export function approvalSummary(agents, project) {
|
|
175
|
+
const all = agents.flatMap((a) => a.approvals);
|
|
176
|
+
const reasons = new Map();
|
|
177
|
+
for (const a of all) for (const r of a.reasons) {
|
|
178
|
+
const cur = reasons.get(r) || { reason: r, count: 0, waitMs: 0, example: a.target };
|
|
179
|
+
cur.count++;
|
|
180
|
+
cur.waitMs += a.waitMs;
|
|
181
|
+
reasons.set(r, cur);
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
count: all.length,
|
|
185
|
+
waitMs: all.reduce((s, a) => s + a.waitMs, 0),
|
|
186
|
+
reasons: [...reasons.values()].sort((x, y) => y.count - x.count),
|
|
187
|
+
folders: tally(all.filter((a) => a.reasons.includes("outsideReadsBlocked")).flatMap(outsideFolders).filter((d) => d !== project)).map(({ key, count }) => ({ dir: key, count })),
|
|
188
|
+
rules: tally(all.filter((a) => a.reasons.includes("no-rule-match")).map(allowRule).filter(Boolean)).map(({ key, count }) => ({ rule: key, count })),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
130
192
|
export function analyze({ main, agents }) {
|
|
131
193
|
const { byAgent, reads } = launches(main);
|
|
132
194
|
const summaries = agents
|
|
@@ -137,9 +199,11 @@ export function analyze({ main, agents }) {
|
|
|
137
199
|
return {
|
|
138
200
|
agents: summaries,
|
|
139
201
|
flags: findFlags(summaries, reads),
|
|
202
|
+
approvals: approvalSummary(summaries, main.find((e) => e.cwd) && repoRoot(main.find((e) => e.cwd).cwd)),
|
|
140
203
|
totals: {
|
|
141
204
|
subagents: summaries.length,
|
|
142
205
|
durationMs: summaries.reduce((s, a) => s + a.durationMs, 0),
|
|
206
|
+
waitMs: summaries.reduce((s, a) => s + a.waitMs, 0),
|
|
143
207
|
toolCalls: summaries.reduce((s, a) => s + a.toolCalls, 0),
|
|
144
208
|
tokens: known.length ? known.reduce((s, a) => s + a.tokens.total, 0) : null,
|
|
145
209
|
},
|
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.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,6 +35,14 @@ 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(
|