@virling/subagents 0.1.0 → 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 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.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
+
13
+ ## [0.1.1] - 2026-11-28
14
+
15
+ ### Fixed
16
+
17
+ - Time no longer includes waiting for a person to approve a tool call, which could inflate a subagent from minutes to hours.
18
+
7
19
  ## [0.1.0] - 2026-11-27
8
20
 
9
21
  ### Added
@@ -12,5 +24,7 @@ All notable changes to this project are documented here. The format follows [Kee
12
24
  - Flags overlapping reads, repeated commands, error-heavy subagents, edit collisions and empty results.
13
25
  - Pick a session with `--session`, a file path or `--project`; `--list` shows recent sessions; `--json` output.
14
26
 
15
- [Unreleased]: https://github.com/virling/subagents/compare/v0.1.0...HEAD
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
29
+ [0.1.1]: https://github.com/virling/subagents/compare/v0.1.0...v0.1.1
16
30
  [0.1.0]: https://github.com/virling/subagents/releases/tag/v0.1.0
package/README.md CHANGED
@@ -61,7 +61,7 @@ Total: 3 subagents, 14m 57s, 56 tool calls, 1.4M tokens
61
61
 
62
62
  Each subagent transcript lives at `~/.claude/projects/<project>/<session>/subagents/agent-<id>.jsonl`. The description comes from the `Agent` (or older `Task`) tool call in the main session, or else the subagent's first message.
63
63
 
64
- - **Time**: active time in the subagent transcript. When a subagent is continued later with a follow-up message, the idle gap before that message is not counted. Time spent waiting on a tool, such as a long Bash command, still counts.
64
+ - **Time**: active time in the subagent transcript. When a subagent is continued later with a follow-up message, the idle gap before that message is not counted. Time spent waiting for a person to approve a tool call is not counted either. A long-running tool, such as a slow Bash command, still counts.
65
65
  - **Tool calls**: every `tool_use`, grouped by tool name. **Failed** counts `tool_result` entries with `is_error`.
66
66
  - **Read / edited**: file paths from `Read`, and from `Edit`, `Write`, `MultiEdit` and `NotebookEdit`.
67
67
  - **Report**: characters of the subagent's last text after its last tool call.
@@ -75,8 +75,22 @@ 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
 
87
+ ## More tools from Virling
88
+
89
+ - [agentmem](https://github.com/virling/agentmem): project memory for AI coding agents, shared across Claude Code, Cursor, Codex and other MCP clients.
90
+ - [ccdoctor](https://github.com/virling/ccdoctor): checks your Claude Code setup: hooks, MCP servers and plugins that are registered but not working.
91
+ - [ciwhy](https://github.com/virling/ciwhy): finds the real error in a failed GitHub Actions run and tells you if it is flaky.
92
+ - [npmship](https://github.com/virling/npmship): releases an npm package and verifies it landed on npm, in CI and on GitHub.
93
+
80
94
  ## License
81
95
 
82
96
  [PolyForm Noncommercial 1.0.0](LICENSE)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@virling/subagents",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Review what Claude Code subagents did in a session and flag repeated or wasted work",
5
5
  "type": "module",
6
6
  "bin": {
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,15 +42,25 @@ 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) {
45
52
  times.push(e.timestamp);
46
53
  const t = Date.parse(e.timestamp);
47
- // A new prompt after a pause is a later continuation, so the gap before it is idle time.
54
+ // A new prompt after a pause is a later continuation, and a tool call a person approved waited on them, so both gaps are idle time.
48
55
  const prompt = role === "user" && text(content).trim() && !blocks(content).some((c) => c.type === "tool_result");
49
- if (prev !== null && !prompt) active += t - prev;
56
+ const approved = role === "user" && e.permissionDecision?.source?.startsWith("user");
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
+ }
50
64
  prev = t;
51
65
  }
52
66
  if (role === "user" && !first) first = text(content).trim();
@@ -56,6 +70,7 @@ export function summarizeAgent(id, entries, input) {
56
70
  if (role !== "assistant") continue;
57
71
  if (c.type === "text") report += `${c.text}\n`;
58
72
  if (c.type !== "tool_use") continue;
73
+ uses.set(c.id, c);
59
74
  report = "";
60
75
  calls++;
61
76
  tools[c.name] = (tools[c.name] || 0) + 1;
@@ -83,6 +98,8 @@ export function summarizeAgent(id, entries, input) {
83
98
  start,
84
99
  end,
85
100
  durationMs: active,
101
+ waitMs: waited,
102
+ approvals,
86
103
  toolCalls: calls,
87
104
  tools,
88
105
  failed,
@@ -126,6 +143,52 @@ export function findFlags(agents, mainReads = []) {
126
143
  return flags;
127
144
  }
128
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
+
129
192
  export function analyze({ main, agents }) {
130
193
  const { byAgent, reads } = launches(main);
131
194
  const summaries = agents
@@ -136,9 +199,11 @@ export function analyze({ main, agents }) {
136
199
  return {
137
200
  agents: summaries,
138
201
  flags: findFlags(summaries, reads),
202
+ approvals: approvalSummary(summaries, main.find((e) => e.cwd) && repoRoot(main.find((e) => e.cwd).cwd)),
139
203
  totals: {
140
204
  subagents: summaries.length,
141
205
  durationMs: summaries.reduce((s, a) => s + a.durationMs, 0),
206
+ waitMs: summaries.reduce((s, a) => s + a.waitMs, 0),
142
207
  toolCalls: summaries.reduce((s, a) => s + a.toolCalls, 0),
143
208
  tokens: known.length ? known.reduce((s, a) => s + a.tokens.total, 0) : null,
144
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(