agent-council 0.3.0 → 0.4.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.
- checksums.yaml +4 -4
- data/DESIGN.md +92 -21
- data/INSTALL.md +8 -6
- data/README.md +232 -67
- data/RELEASE_NOTES.md +188 -110
- data/RUNAWAY_AGENTS.md +187 -9
- data/USE_CASES.md +1 -1
- data/examples/configs/mixed-harness.yml +14 -7
- data/examples/prompts/review-latest-commit-prompt.md +9 -0
- data/examples/prompts/review-pull-request-prompt.md +6 -0
- data/examples/prompts/test-coverage-analysis-prompt.md +56 -42
- data/exe/agent-council +3 -0
- data/exe/agent-council-ps +9 -0
- data/exe/pi-models +3 -33
- data/lib/agent_council/harnesses/claude_code_harness.rb +40 -60
- data/lib/agent_council/harnesses/codex_harness.rb +42 -89
- data/lib/agent_council/harnesses/harness.rb +185 -0
- data/lib/agent_council/harnesses/opencode_harness.rb +234 -0
- data/lib/agent_council/harnesses/pi_harness.rb +29 -59
- data/lib/agent_council/harnesses/scaffold.rb +3 -3
- data/lib/agent_council/harnesses.rb +11 -26
- data/lib/agent_council/pi_models.rb +40 -0
- data/lib/agent_council/plain_line.rb +24 -0
- data/lib/agent_council/platform.rb +2 -2
- data/lib/agent_council/progress_printer.rb +59 -0
- data/lib/agent_council/ps.rb +548 -0
- data/lib/agent_council/safe_stdout.rb +48 -0
- data/lib/agent_council/version.rb +1 -1
- data/lib/agent_council/worker_pool.rb +28 -15
- data/lib/agent_council.rb +157 -122
- metadata +12 -4
|
@@ -27,6 +27,9 @@ solution would be appropriate.
|
|
|
27
27
|
context, but they are local to this checkout, so judge the changes
|
|
28
28
|
against tracked files.
|
|
29
29
|
- Do not report preexisting issues unless the changes introduce or worsen them.
|
|
30
|
+
- If the repository has a `REVIEW_NOTES.md`, don't report issues it
|
|
31
|
+
records as accepted risks or non-issues, unless the changes make one
|
|
32
|
+
worse or its reasoning no longer holds.
|
|
30
33
|
- You may suggest improvements to the commit message, particularly if the
|
|
31
34
|
commit has not been pushed.
|
|
32
35
|
|
|
@@ -37,6 +40,12 @@ Investigate thoroughly before reaching conclusions.
|
|
|
37
40
|
You are permitted and encouraged to inspect files, run Git commands, execute
|
|
38
41
|
relevant tests and linters, and reproduce suspected defects.
|
|
39
42
|
|
|
43
|
+
Several agents run this review at the same time on the same machine, so
|
|
44
|
+
keep your test runs light: where you can, run the tests relevant to the
|
|
45
|
+
change rather than the whole suite, and run them under one language
|
|
46
|
+
version or interpreter, not several. If you suspect a defect specific
|
|
47
|
+
to one version or interpreter, run only the relevant tests under it.
|
|
48
|
+
|
|
40
49
|
**DO NOT EDIT ANY CODE OR TRACKED FILES.**
|
|
41
50
|
|
|
42
51
|
Tests and linters that generate temporary files or coverage data are
|
|
@@ -71,6 +71,12 @@ Investigate thoroughly before reaching conclusions.
|
|
|
71
71
|
You are permitted and encouraged to inspect files, run Git commands, execute
|
|
72
72
|
relevant tests and linters, and reproduce suspected defects.
|
|
73
73
|
|
|
74
|
+
Several agents run this review at the same time on the same machine, so
|
|
75
|
+
keep your test runs light: where you can, run the tests relevant to the
|
|
76
|
+
change rather than the whole suite, and run them under one language
|
|
77
|
+
version or interpreter, not several. If you suspect a defect specific
|
|
78
|
+
to one version or interpreter, run only the relevant tests under it.
|
|
79
|
+
|
|
74
80
|
**DO NOT EDIT ANY CODE OR TRACKED FILES.**
|
|
75
81
|
|
|
76
82
|
Tests and linters that generate temporary files or coverage data are
|
|
@@ -8,8 +8,8 @@ gaps by risk. It never asks for input, so it also works headless (e.g.
|
|
|
8
8
|
|
|
9
9
|
**Requirement:** run your full test suite (every suite that feeds SimpleCov)
|
|
10
10
|
first, make sure it passes, and don't change source or test files until the
|
|
11
|
-
analysis finishes. The prompt does not run tests; it reads the
|
|
12
|
-
|
|
11
|
+
analysis finishes. The prompt does not run tests; it reads the coverage file
|
|
12
|
+
that run left and refuses to start if that file looks out of date. This lets
|
|
13
13
|
several agents run it concurrently against the same coverage data.
|
|
14
14
|
|
|
15
15
|
---
|
|
@@ -33,7 +33,7 @@ Before you begin the analysis:
|
|
|
33
33
|
3. If `git status` shows uncommitted changes, include them in the analysis:
|
|
34
34
|
analyze the working tree as it is, and list the `git status` details
|
|
35
35
|
immediately after the commit citation.
|
|
36
|
-
4. Analyze the files git would consider part of the project: tracked files
|
|
36
|
+
4. Analyze the files git would consider part of the project: git-tracked files
|
|
37
37
|
plus new files not yet added, excluding anything git ignores
|
|
38
38
|
(`git ls-files --cached --others --exclude-standard`). Mark the untracked
|
|
39
39
|
files in the `git status` details.
|
|
@@ -44,12 +44,20 @@ Before you begin the analysis:
|
|
|
44
44
|
- Your task is to produce a report of line coverage **organized by the logical
|
|
45
45
|
parts of the system**, not just a per-file list, and to judge where the gaps
|
|
46
46
|
actually matter.
|
|
47
|
-
- Get every coverage number from cov-loupe. Do not read
|
|
47
|
+
- Get every coverage number from cov-loupe. Do not read the coverage file
|
|
48
48
|
directly, and do not estimate coverage by reading tests. Aggregating
|
|
49
49
|
cov-loupe's per-line output into area totals is expected (see Step 4).
|
|
50
|
-
-
|
|
51
|
-
the
|
|
52
|
-
|
|
50
|
+
- Prefer the cov-loupe MCP server. If it is unavailable, or its calls are
|
|
51
|
+
refused, use the CLI (`cov-loupe`, or `bundle exec cov-loupe` if it is in
|
|
52
|
+
the Gemfile). Every command needs a subcommand, such as `list`; ask for
|
|
53
|
+
JSON output (`-f J`). If the CLI rejects the subcommand because it is in
|
|
54
|
+
MCP mode (COV_LOUPE_OPTS can select it), put `-m cli` before the
|
|
55
|
+
subcommand. Say in the report which interface you used, and which
|
|
56
|
+
cov-loupe version.
|
|
57
|
+
- cov-loupe's options, tool parameters, and field names differ between
|
|
58
|
+
versions. The names below, such as `not_in_coverage_files`, are examples
|
|
59
|
+
from one version; take the real ones from the MCP tool schemas or from
|
|
60
|
+
`cov-loupe --help`, and from the output itself.
|
|
53
61
|
- Use source and test files only to define the logical areas and to judge the
|
|
54
62
|
importance of uncovered code.
|
|
55
63
|
- Do not run the test suite, and do not modify source files, test files, or
|
|
@@ -71,20 +79,22 @@ error, not a report.
|
|
|
71
79
|
|
|
72
80
|
1. Find the SimpleCov configuration (`.simplecov`, `spec/spec_helper.rb`,
|
|
73
81
|
`test/test_helper.rb`, or wherever the project starts SimpleCov) and the
|
|
74
|
-
coverage file (`
|
|
75
|
-
|
|
76
|
-
|
|
82
|
+
coverage file: the file cov-loupe reads (`cov-loupe --help` gives its
|
|
83
|
+
default location), unless the configuration or the invocation names
|
|
84
|
+
another. The file must exist. Record its path, size in bytes, and modification time (in
|
|
77
85
|
UTC) from the file system (e.g. `ls -l` or `stat`); this metadata is not
|
|
78
86
|
coverage data, so reading it is allowed.
|
|
79
|
-
2. Run the project totals
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
must
|
|
83
|
-
|
|
84
|
-
|
|
87
|
+
2. Run the project totals (`project_coverage_totals` /
|
|
88
|
+
`cov-loupe totals`) and the file list (`project_coverage` /
|
|
89
|
+
`cov-loupe list`), each limited to the file globs from Step 2. The
|
|
90
|
+
output's staleness fields must report no problem: the timestamp status
|
|
91
|
+
must be ok, and the lists of files that are newer than the coverage
|
|
92
|
+
data, deleted, of mismatched length, unreadable, or skipped (e.g.
|
|
93
|
+
`newer_files`, `deleted_files`) must all be empty. These show whether
|
|
94
|
+
source files changed after the run.
|
|
85
95
|
3. No test, fixture, or configuration file may be newer than the coverage
|
|
86
96
|
file, since cov-loupe checks only source files. For example:
|
|
87
|
-
`find spec test features Gemfile.lock .rspec .simplecov -newer coverage
|
|
97
|
+
`find spec test features Gemfile.lock .rspec .simplecov -newer <coverage file>`
|
|
88
98
|
(adjusted to the paths that exist). Include directories in the search,
|
|
89
99
|
not just files, so that deleted test files show up too.
|
|
90
100
|
4. If the project records test results, they must show no failures: for
|
|
@@ -94,18 +104,19 @@ error, not a report.
|
|
|
94
104
|
These checks cannot prove that the last run was the complete suite. Say in
|
|
95
105
|
the report that the analysis relies on the user's assurance that it was.
|
|
96
106
|
|
|
97
|
-
|
|
98
|
-
staleness failure;
|
|
107
|
+
Files that match the file globs but that the suite never loaded are not a
|
|
108
|
+
staleness failure; they are a finding for Step 2.
|
|
99
109
|
|
|
100
110
|
## Step 2: Establish the project baseline
|
|
101
111
|
|
|
102
|
-
1. Get overall totals with no globs, then with
|
|
103
|
-
code SimpleCov is meant to measure
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
112
|
+
1. Get overall totals with no globs, then with file globs matching the
|
|
113
|
+
code SimpleCov is meant to measure, taken from its `cover` setting
|
|
114
|
+
(formerly `track_files`) and its filters; typically `lib/**/*.rb`, or
|
|
115
|
+
`app/**/*.rb,lib/**/*.rb` for Rails.
|
|
116
|
+
Passing file globs makes cov-loupe report matching files that have
|
|
117
|
+
**no** coverage data at all (e.g. `not_in_coverage_files` in the list,
|
|
118
|
+
and a count of them in totals); these are files never loaded by the
|
|
119
|
+
suite and are often the biggest real gap.
|
|
109
120
|
2. Get the full file list as JSON, sorted ascending (worst first).
|
|
110
121
|
3. Note what the numbers cover: cov-loupe reports **line** coverage only.
|
|
111
122
|
If SimpleCov also collects branch coverage, say that branch coverage is out
|
|
@@ -161,16 +172,17 @@ and more tokens than a file-level rollup; that is the point.
|
|
|
161
172
|
## Step 4: Compute coverage per area
|
|
162
173
|
|
|
163
174
|
1. For each file touched by an area, get per-line data with
|
|
164
|
-
`cov-loupe
|
|
165
|
-
hit count, and whether it is covered; lines that
|
|
166
|
-
(comments, blank lines, `end`) do not appear.
|
|
175
|
+
`file_coverage_detailed` / `cov-loupe detailed <path>`. Each row
|
|
176
|
+
gives a line number, its hit count, and whether it is covered; lines that
|
|
177
|
+
are not coverable (comments, blank lines, `end`) do not appear.
|
|
167
178
|
2. For each area, sum the covered and coverable lines that fall in its line
|
|
168
179
|
ranges, and compute the percentage. Also record the number of code units
|
|
169
180
|
in the area and its weakest units (e.g. the least-covered methods).
|
|
170
181
|
3. Get a broader area's numbers by summing its children's line counts, never
|
|
171
182
|
by averaging child percentages.
|
|
172
183
|
4. For an area made of whole files, cross-check your sums against
|
|
173
|
-
`cov-loupe
|
|
184
|
+
`project_coverage_totals` / `cov-loupe totals`, limited to that area's
|
|
185
|
+
globs; they must match exactly.
|
|
174
186
|
5. Confirm that the line totals for the partition level from Step 3 add up to
|
|
175
187
|
the project's covered and total lines for the same overall globs. If they
|
|
176
188
|
don't, find the overlap or orphaned lines and fix the map; state any
|
|
@@ -185,16 +197,17 @@ and more tokens than a file-level rollup; that is the point.
|
|
|
185
197
|
Decide for yourself which files and areas deserve a close look. Do not apply a
|
|
186
198
|
fixed percentage cutoff: weigh each area's coverage against its criticality,
|
|
187
199
|
so a critical area at a high percentage can still warrant scrutiny while a
|
|
188
|
-
low-stakes area at a lower percentage may not. Always include every
|
|
189
|
-
file
|
|
190
|
-
report.
|
|
200
|
+
low-stakes area at a lower percentage may not. Always include every file
|
|
201
|
+
matching the file globs that has no coverage data. State the reasoning behind
|
|
202
|
+
your selection in the report.
|
|
191
203
|
|
|
192
204
|
For each selected file or area:
|
|
193
205
|
|
|
194
|
-
1. Get the uncovered lines (`
|
|
195
|
-
`cov-loupe
|
|
196
|
-
`cov-loupe
|
|
197
|
-
|
|
206
|
+
1. Get the uncovered lines (`file_uncovered_lines` /
|
|
207
|
+
`cov-loupe uncovered <path>`). To see them in context, run
|
|
208
|
+
`cov-loupe uncovered <path>` with its source display set to uncovered
|
|
209
|
+
lines, or read the source file around them; the MCP tools give line
|
|
210
|
+
numbers and hit counts, not source.
|
|
198
211
|
2. Characterize each cluster of uncovered lines: error/rescue path, edge-case
|
|
199
212
|
branch, defensive guard, platform-specific code, dead code, debug/logging
|
|
200
213
|
code, or core logic.
|
|
@@ -246,11 +259,12 @@ The report should have the following structure:
|
|
|
246
259
|
---
|
|
247
260
|
|
|
248
261
|
### Executive Summary
|
|
249
|
-
- Commit cited and the results of the
|
|
262
|
+
- Commit cited, cov-loupe interface used (MCP or CLI), and the results of the
|
|
263
|
+
Step 1 checks.
|
|
250
264
|
- The coverage file's path (relative to the project root), size, and
|
|
251
265
|
modification time (UTC), so readers can tell which test run the report
|
|
252
266
|
describes.
|
|
253
|
-
- Overall line coverage (with and without
|
|
267
|
+
- Overall line coverage (with and without file globs).
|
|
254
268
|
- The best- and worst-covered areas, and the top risk areas.
|
|
255
269
|
- A **one-line verdict** (e.g. *"Strong domain coverage; payment error
|
|
256
270
|
handling is the main gap"*).
|
|
@@ -269,7 +283,7 @@ percentage:
|
|
|
269
283
|
| Area | Criticality | Code units | Covered | Total | % | Weakest unit (%) |
|
|
270
284
|
|------|-------------|------------|---------|-------|---|------------------|
|
|
271
285
|
|
|
272
|
-
List
|
|
286
|
+
List matching files with no coverage data separately, with the areas they
|
|
273
287
|
belong to.
|
|
274
288
|
|
|
275
289
|
Follow with a short interpretation of each area that stands out, positively or
|
|
@@ -297,7 +311,7 @@ citations.
|
|
|
297
311
|
|
|
298
312
|
### Data Caveats
|
|
299
313
|
Reliance on the user's assurance that the last run was the complete, passing
|
|
300
|
-
suite;
|
|
314
|
+
suite; matching files not in the coverage data; branch coverage being out
|
|
301
315
|
of scope; ambiguous line assignments at area boundaries; anything else that
|
|
302
316
|
limits confidence in the numbers.
|
|
303
317
|
|
|
@@ -322,7 +336,7 @@ table, give each task a ready-to-use prompt the user can give an AI assistant
|
|
|
322
336
|
to implement it, keyed by its number.
|
|
323
337
|
|
|
324
338
|
### Appendix: Commands Run
|
|
325
|
-
Every cov-loupe command and
|
|
339
|
+
Every cov-loupe call (MCP tool name and arguments, or CLI command) and
|
|
326
340
|
freshness check used to produce the numbers, plus any aggregation script, so the
|
|
327
341
|
report can be reproduced.
|
|
328
342
|
|
data/exe/agent-council
CHANGED
|
@@ -4,12 +4,15 @@
|
|
|
4
4
|
# agent-council — executable entry point. All code lives in lib/:
|
|
5
5
|
# lib/agent_council.rb orchestration (AgentCouncil)
|
|
6
6
|
# lib/agent_council/harnesses.rb harnesses by name (AgentCouncil::Harnesses)
|
|
7
|
+
# lib/agent_council/harnesses/harness.rb the base class every harness subclasses (Harness)
|
|
7
8
|
# lib/agent_council/harnesses/scaffold.rb read-only scaffolding every harness appends
|
|
8
9
|
# lib/agent_council/harnesses/pi_harness.rb pi-specific behavior (AgentCouncil::Harnesses::PiHarness)
|
|
9
10
|
# lib/agent_council/harnesses/claude_code_harness.rb
|
|
10
11
|
# Claude Code-specific behavior (ClaudeCodeHarness)
|
|
11
12
|
# lib/agent_council/harnesses/codex_harness.rb
|
|
12
13
|
# Codex-specific behavior (CodexHarness)
|
|
14
|
+
# lib/agent_council/harnesses/opencode_harness.rb
|
|
15
|
+
# OpenCode-specific behavior (OpenCodeHarness)
|
|
13
16
|
#
|
|
14
17
|
# Usage, options, and AGENT_COUNCIL_OPTS: agent-council -h, and the README.
|
|
15
18
|
|
data/exe/pi-models
CHANGED
|
@@ -1,39 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
AgentCouncil.abort_if_native_windows('pi-models')
|
|
4
|
+
# pi-models — executable entry point; the command is AgentCouncil::PiModels.main
|
|
5
|
+
# (lib/agent_council/pi_models.rb).
|
|
7
6
|
|
|
8
7
|
require_relative '../lib/agent_council/pi_models'
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
json_output = ARGV.delete('--json') || ARGV.delete('-j')
|
|
12
|
-
ids_output = ARGV.delete('--ids') || ARGV.delete('-i')
|
|
13
|
-
ARGV.delete('--table') || ARGV.delete('-t') # table is the default format; accepted for explicitness
|
|
14
|
-
|
|
15
|
-
if help_output
|
|
16
|
-
puts AgentCouncil::PiModels.help_text
|
|
17
|
-
exit
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
unless ARGV.empty?
|
|
21
|
-
warn "pi-models: unknown option(s): #{ARGV.join(' ')}"
|
|
22
|
-
warn "Try 'pi-models --help' for usage."
|
|
23
|
-
exit 1
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
begin
|
|
27
|
-
models = AgentCouncil::PiModels.fetch_models
|
|
28
|
-
rescue AgentCouncil::PiModels::Error => e
|
|
29
|
-
warn "pi-models: #{e.message}"
|
|
30
|
-
exit 1
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
if json_output
|
|
34
|
-
puts AgentCouncil::PiModels.format_as_json(models)
|
|
35
|
-
elsif ids_output
|
|
36
|
-
print AgentCouncil::PiModels.format_as_ids(models)
|
|
37
|
-
else
|
|
38
|
-
puts AgentCouncil::PiModels.format_as_table(models)
|
|
39
|
-
end
|
|
9
|
+
AgentCouncil::PiModels.main(ARGV)
|
|
@@ -5,17 +5,16 @@
|
|
|
5
5
|
# with its tool allowlist and the shared read-only scaffolding, and how to
|
|
6
6
|
# read its stream-json output afterward.
|
|
7
7
|
#
|
|
8
|
-
# AgentCouncil is harness-agnostic and finds this
|
|
8
|
+
# AgentCouncil is harness-agnostic and finds this class through
|
|
9
9
|
# AgentCouncil::Harnesses (lib/agent_council/harnesses.rb), by its NAME.
|
|
10
10
|
# Authentication and billing are left to Claude Code: an agent bills however
|
|
11
11
|
# claude would at the user's terminal.
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
require_relative 'scaffold'
|
|
13
|
+
require_relative 'harness'
|
|
15
14
|
|
|
16
15
|
module AgentCouncil
|
|
17
16
|
module Harnesses
|
|
18
|
-
|
|
17
|
+
class ClaudeCodeHarness < Harness
|
|
19
18
|
NAME = 'claude'
|
|
20
19
|
|
|
21
20
|
# Analysis toolset (Claude Code's built-in tool names): Edit, Write, and
|
|
@@ -27,7 +26,7 @@ module AgentCouncil
|
|
|
27
26
|
# argv; it is piped to stdin. provider is not passed: Claude Code
|
|
28
27
|
# takes none, so an entry's provider only labels the agent (e.g.
|
|
29
28
|
# bedrock, for a claude set up to use it).
|
|
30
|
-
|
|
29
|
+
def self.argv(_provider, model)
|
|
31
30
|
[
|
|
32
31
|
NAME,
|
|
33
32
|
'-p', # non-interactive: process prompt and exit
|
|
@@ -42,31 +41,27 @@ module AgentCouncil
|
|
|
42
41
|
]
|
|
43
42
|
end
|
|
44
43
|
|
|
45
|
-
#
|
|
46
|
-
|
|
47
|
-
#
|
|
48
|
-
#
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
begin
|
|
53
|
-
JSON.parse(line)
|
|
54
|
-
rescue JSON::ParserError
|
|
55
|
-
nil
|
|
56
|
-
end
|
|
57
|
-
event if event.is_a?(Hash)
|
|
58
|
-
end
|
|
44
|
+
# Variables for the agent's process beyond TMPDIR: the scratch dir as
|
|
45
|
+
# CLAUDE_CODE_TMPDIR, the base under which Claude Code's sandbox makes
|
|
46
|
+
# the writable TMPDIR it gives commands. Without it, a user's own
|
|
47
|
+
# CLAUDE_CODE_TMPDIR would put that dir outside the scratch dir,
|
|
48
|
+
# shared and never cleaned up.
|
|
49
|
+
def self.env(scratch_dir)
|
|
50
|
+
{ 'CLAUDE_CODE_TMPDIR' => scratch_dir }
|
|
59
51
|
end
|
|
60
52
|
|
|
53
|
+
# --- event stream reading ---
|
|
54
|
+
|
|
61
55
|
# The agent's result event: the last one, which ends the stream. nil if
|
|
62
56
|
# there is none, e.g. for an agent that was killed.
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
def self.result_event(jsonl)
|
|
58
|
+
last_event(jsonl, 'result')
|
|
65
59
|
end
|
|
60
|
+
private_class_method :result_event
|
|
66
61
|
|
|
67
62
|
# The messages of the stream's assistant events, in order (several per
|
|
68
63
|
# model request, one per content block).
|
|
69
|
-
|
|
64
|
+
def self.assistant_messages(jsonl)
|
|
70
65
|
events(jsonl).filter_map do |event|
|
|
71
66
|
message = event['message'] if event['type'] == 'assistant'
|
|
72
67
|
message if message.is_a?(Hash)
|
|
@@ -75,7 +70,7 @@ module AgentCouncil
|
|
|
75
70
|
|
|
76
71
|
# The final response: the result event's text, for an agent that didn't
|
|
77
72
|
# fail.
|
|
78
|
-
|
|
73
|
+
def self.final_response(jsonl)
|
|
79
74
|
result = result_event(jsonl)
|
|
80
75
|
return nil unless result && result['is_error'] != true
|
|
81
76
|
|
|
@@ -89,26 +84,18 @@ module AgentCouncil
|
|
|
89
84
|
'cache_read' => 'cache_read_input_tokens',
|
|
90
85
|
'cache_write' => 'cache_creation_input_tokens' }.freeze
|
|
91
86
|
|
|
92
|
-
# Token usage as AgentCouncil expects it (see
|
|
87
|
+
# Token usage as AgentCouncil expects it (see Harness), from the
|
|
93
88
|
# result event alone: it totals all the agent's requests, while the assistant
|
|
94
89
|
# events' usage is per-message snapshots that undercount output. nil
|
|
95
90
|
# when the stream has no result event (as for an agent whose claude was
|
|
96
91
|
# killed: no usage beats an undercount) or reports no usage (as when
|
|
97
92
|
# the agent never reached a model).
|
|
98
|
-
|
|
93
|
+
def self.usage(jsonl)
|
|
99
94
|
result = result_event(jsonl)
|
|
100
95
|
usage = result && result['usage']
|
|
101
96
|
return nil unless usage.is_a?(Hash)
|
|
102
97
|
|
|
103
|
-
|
|
104
|
-
return nil if totals.values.all?(&:zero?)
|
|
105
|
-
|
|
106
|
-
cost = count(result['total_cost_usd'])
|
|
107
|
-
cost.positive? ? totals.merge('cost' => cost.round(6)) : totals
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
module_function def count(value)
|
|
111
|
-
value.is_a?(Numeric) && value.positive? ? value : 0
|
|
98
|
+
usage_result(USAGE_KEYS.transform_values { |key| count(usage[key]) }, count(result['total_cost_usd']))
|
|
112
99
|
end
|
|
113
100
|
|
|
114
101
|
# Why the agent produced no usable report, or nil. A failed agent has a
|
|
@@ -118,23 +105,20 @@ module AgentCouncil
|
|
|
118
105
|
# is its errors, if any (e.g. the turn limit, with no result text),
|
|
119
106
|
# otherwise its result text (e.g. "Not logged in · Please run
|
|
120
107
|
# /login").
|
|
121
|
-
|
|
108
|
+
def self.error_message(jsonl)
|
|
122
109
|
result = result_event(jsonl)
|
|
123
110
|
return 'the stream has no result event' unless result
|
|
124
111
|
return error_reason(result) || 'the agent failed and gave no reason' if result['is_error'] == true
|
|
125
112
|
|
|
126
|
-
text
|
|
127
|
-
'the result event has no text' unless text.is_a?(String) && !text.strip.empty?
|
|
113
|
+
'the result event has no text' unless nonblank_text(result['result'])
|
|
128
114
|
end
|
|
129
115
|
|
|
130
116
|
# The reason a failed agent's result event gives, or nil if it gives none.
|
|
131
|
-
|
|
132
|
-
errors = Array(result['errors'])
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
text = result['result']
|
|
136
|
-
text if text.is_a?(String) && !text.strip.empty?
|
|
117
|
+
def self.error_reason(result)
|
|
118
|
+
errors = nonblank_strings(Array(result['errors']))
|
|
119
|
+
errors.empty? ? nonblank_text(result['result']) : errors.join('; ')
|
|
137
120
|
end
|
|
121
|
+
private_class_method :error_reason
|
|
138
122
|
|
|
139
123
|
# Why an agent that exited nonzero failed. Claude Code explains a failure
|
|
140
124
|
# in a result event with is_error true, and its stderr is then
|
|
@@ -142,16 +126,13 @@ module AgentCouncil
|
|
|
142
126
|
# Otherwise stderr is likelier to say why (e.g. for a crash) than
|
|
143
127
|
# whatever else the stream shows (e.g. a result with no text), which
|
|
144
128
|
# is the last resort. Returned whole: the caller puts it on one line
|
|
145
|
-
# and shortens it (see
|
|
146
|
-
|
|
129
|
+
# and shortens it (see Harness).
|
|
130
|
+
def self.exit_detail(stdout, stderr)
|
|
147
131
|
result = result_event(stdout)
|
|
148
132
|
reason = error_reason(result) if result && result['is_error'] == true
|
|
149
133
|
return reason if reason
|
|
150
134
|
|
|
151
|
-
|
|
152
|
-
return stderr_line if stderr_line
|
|
153
|
-
|
|
154
|
-
(error_message(stdout) if result) || 'no error output'
|
|
135
|
+
first_line(stderr) || (error_message(stdout) if result) || NO_ERROR_OUTPUT
|
|
155
136
|
end
|
|
156
137
|
|
|
157
138
|
# Warnings about an agent, succeeded or not: the tool calls Claude Code
|
|
@@ -160,23 +141,25 @@ module AgentCouncil
|
|
|
160
141
|
# call), but its report may be missing what the call would have
|
|
161
142
|
# found; an agent that fails (say, out of turns) may have failed
|
|
162
143
|
# because of them.
|
|
163
|
-
|
|
144
|
+
def self.warnings(jsonl)
|
|
164
145
|
result = result_event(jsonl)
|
|
165
146
|
denials = result && result['permission_denials']
|
|
166
147
|
return [] unless denials.is_a?(Array) && !denials.empty?
|
|
167
148
|
|
|
168
|
-
calls = denials.map { |denial| denied_call(denial) }.uniq
|
|
169
|
-
|
|
170
|
-
target ? "#{tool} (#{shorten(target)})" : tool
|
|
149
|
+
calls = denials.map { |denial| denied_call(denial) }.uniq.map do |tool, target|
|
|
150
|
+
target ? "#{tool} (#{shorten(target, MAX_TARGET_LENGTH)})" : tool
|
|
171
151
|
end
|
|
172
|
-
|
|
173
|
-
|
|
152
|
+
[listing("Claude Code refused #{denials.size} tool call#{'s' unless denials.size == 1}", calls,
|
|
153
|
+
MAX_LISTED_CALLS)]
|
|
174
154
|
end
|
|
175
155
|
|
|
176
156
|
# Distinct refused calls named in a warning, so an agent refused many
|
|
177
157
|
# times still gets a warning of a readable length.
|
|
178
158
|
MAX_LISTED_CALLS = 5
|
|
179
159
|
|
|
160
|
+
# Characters of a refused call's target a warning shows.
|
|
161
|
+
MAX_TARGET_LENGTH = 80
|
|
162
|
+
|
|
180
163
|
# The tool_input keys that say what a refused call was for, in order
|
|
181
164
|
# of preference: Bash's command, Read's file_path, then Grep's and
|
|
182
165
|
# Glob's pattern and path.
|
|
@@ -186,7 +169,7 @@ module AgentCouncil
|
|
|
186
169
|
# such as a Bash command or the file a Read asked for, on one line,
|
|
187
170
|
# or nil if the call gives none. Compared whole, so calls that differ
|
|
188
171
|
# only past where a warning shortens them still count as different.
|
|
189
|
-
|
|
172
|
+
def self.denied_call(denial)
|
|
190
173
|
return ['unknown tool', nil] unless denial.is_a?(Hash)
|
|
191
174
|
|
|
192
175
|
tool = denial['tool_name'].is_a?(String) ? denial['tool_name'] : 'unknown tool'
|
|
@@ -195,10 +178,7 @@ module AgentCouncil
|
|
|
195
178
|
target = target&.gsub(/\s+/, ' ')&.strip
|
|
196
179
|
[tool, (target unless target.nil? || target.empty?)]
|
|
197
180
|
end
|
|
198
|
-
|
|
199
|
-
module_function def shorten(target)
|
|
200
|
-
target.length > 80 ? "#{target[0, 80]}..." : target
|
|
201
|
-
end
|
|
181
|
+
private_class_method :denied_call
|
|
202
182
|
end
|
|
203
183
|
end
|
|
204
184
|
end
|