agent-council 0.2.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.
@@ -1,22 +1,33 @@
1
- # Sample mixed-harness ensemble: a Claude Code analyst alongside pi analysts,
2
- # with a Claude Code consolidator. Claude Code entries run under your own
3
- # `claude` setup and bill however it does (see "Choosing a harness" in the
4
- # README); pi entries need credentials for their providers (see
5
- # `pi --list-models`). Replace any provider or model you don't have.
1
+ # Sample mixed-harness ensemble: Claude Code, Codex, and OpenCode analysts
2
+ # alongside pi analysts, with a Claude Code consolidator. Claude Code and Codex
3
+ # entries run under your own `claude` and `codex` setups and bill however they
4
+ # do (see "Choosing a harness" in the README); pi and OpenCode entries need
5
+ # credentials for their providers. Replace any provider or model you
6
+ # don't have; "Discovering and configuring models" in the README says
7
+ # how to find each harness's models.
6
8
  agents:
7
9
  - harness: claude
8
10
  provider: anthropic
9
11
  model: claude-opus-5-5
12
+ - harness: codex
13
+ provider: openai
14
+ model: gpt-5.6-terra
10
15
  - harness: pi
11
16
  provider: deepseek
12
17
  model: deepseek-flash
13
18
  - harness: pi
14
19
  provider: openrouter
15
20
  model: z-ai/glm-5.3-flash
16
- # The same model under the other harness, to compare harnesses:
21
+ - harness: opencode
22
+ provider: opencode-go
23
+ model: glm-5.3
24
+ # The same models under another harness, to compare harnesses:
17
25
  - harness: pi
18
26
  provider: anthropic
19
27
  model: claude-opus-5-5
28
+ - harness: pi
29
+ provider: opencode-go
30
+ model: glm-5.3
20
31
 
21
32
  consolidator:
22
33
  harness: claude
@@ -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 existing
12
- `coverage.json` and refuses to start if that file looks out of date. This lets
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 `coverage.json`
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
- - Use the cov-loupe CLI (`cov-loupe`, or `bundle exec cov-loupe` if it is in
51
- the Gemfile; run `cov-loupe --help` for usage), adding `-m cli -fJ` for JSON
52
- output.
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 (`coverage/coverage.json` unless the configuration or the
75
- invocation says otherwise). The file must exist and be written by
76
- SimpleCov 1.x. Record its path, size in bytes, and modification time (in
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 with the tracked globs from Step 2
80
- (`cov-loupe -m cli -fJ -g '<globs>' totals`) and the file list with the
81
- same globs (`cov-loupe -m cli -fJ -g '<globs>' list`). `timestamp_status`
82
- must be `ok`, and `newer_files`, `deleted_files`, `length_mismatch_files`,
83
- `unreadable_files`, and `skipped_files` must all be empty. These show
84
- whether source files changed after the run.
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/coverage.json`
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
- `missing_tracked_files` (tracked files the suite never loaded) is not a
98
- staleness failure; it is a finding for Step 2.
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 tracked globs matching the
103
- code SimpleCov is meant to measure (from its `track_files` and filter
104
- settings; typically `lib/**/*.rb`, or `app/**/*.rb,lib/**/*.rb` for Rails).
105
- Passing tracked globs (`-g`) makes cov-loupe report tracked files that have
106
- **no** coverage data at all (`missing_tracked_files`, `without_coverage`);
107
- these are files never loaded by the suite and are often the biggest real
108
- gap.
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 -m cli -fJ detailed <path>`. Each row gives a line number, its
165
- hit count, and whether it is covered; lines that are not coverable
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 -m cli -fJ -g '<globs>' totals`; they must match exactly.
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 tracked
189
- file with no coverage data. State the reasoning behind your selection in the
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 (`cov-loupe -m cli -fJ uncovered <path>`); use
195
- `cov-loupe -m cli -fJ detailed <path>` or
196
- `cov-loupe -m cli -s uncovered -n 2 uncovered <path>` to see the source in
197
- context.
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 Step 1 checks.
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 tracked globs).
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 tracked files with no coverage data separately, with the areas they
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; tracked files missing from the coverage data; branch coverage being out
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,10 +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)
12
+ # lib/agent_council/harnesses/codex_harness.rb
13
+ # Codex-specific behavior (CodexHarness)
14
+ # lib/agent_council/harnesses/opencode_harness.rb
15
+ # OpenCode-specific behavior (OpenCodeHarness)
11
16
  #
12
17
  # Usage, options, and AGENT_COUNCIL_OPTS: agent-council -h, and the README.
13
18
 
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # agent-council-ps — executable entry point; the command is
5
+ # AgentCouncil::Ps.main (lib/agent_council/ps.rb).
6
+
7
+ require_relative '../lib/agent_council/ps'
8
+
9
+ AgentCouncil::Ps.main(ARGV)
data/exe/pi-models CHANGED
@@ -1,39 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative '../lib/agent_council/platform'
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
- help_output = ARGV.delete('-h') || ARGV.delete('--help')
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 module through
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
- require 'json'
14
- require_relative 'scaffold'
13
+ require_relative 'harness'
15
14
 
16
15
  module AgentCouncil
17
16
  module Harnesses
18
- module ClaudeCodeHarness
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
- module_function def argv(_provider, model)
29
+ def self.argv(_provider, model)
31
30
  [
32
31
  NAME,
33
32
  '-p', # non-interactive: process prompt and exit
@@ -37,37 +36,32 @@ module AgentCouncil
37
36
  '--tools', TOOLS, # the only built-in tools available
38
37
  '--allowedTools', TOOLS, # ...and pre-approved, since -p can't ask
39
38
  '--permission-mode', 'manual', # the same for every user, whatever their defaultMode
40
- '--strict-mcp-config', # with no --mcp-config: no MCP servers
41
39
  '--model', model,
42
40
  '--append-system-prompt', Harnesses.scaffold_text
43
41
  ]
44
42
  end
45
43
 
46
- # --- event stream reading ---
47
-
48
- # The events of a stream-json stream, in order. Unparseable lines and
49
- # non-objects are skipped.
50
- module_function def events(jsonl)
51
- jsonl.each_line.filter_map do |line|
52
- event =
53
- begin
54
- JSON.parse(line)
55
- rescue JSON::ParserError
56
- nil
57
- end
58
- event if event.is_a?(Hash)
59
- 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 }
60
51
  end
61
52
 
53
+ # --- event stream reading ---
54
+
62
55
  # The agent's result event: the last one, which ends the stream. nil if
63
56
  # there is none, e.g. for an agent that was killed.
64
- module_function def result_event(jsonl)
65
- events(jsonl).reverse_each.detect { |event| event['type'] == 'result' }
57
+ def self.result_event(jsonl)
58
+ last_event(jsonl, 'result')
66
59
  end
60
+ private_class_method :result_event
67
61
 
68
62
  # The messages of the stream's assistant events, in order (several per
69
63
  # model request, one per content block).
70
- module_function def assistant_messages(jsonl)
64
+ def self.assistant_messages(jsonl)
71
65
  events(jsonl).filter_map do |event|
72
66
  message = event['message'] if event['type'] == 'assistant'
73
67
  message if message.is_a?(Hash)
@@ -76,7 +70,7 @@ module AgentCouncil
76
70
 
77
71
  # The final response: the result event's text, for an agent that didn't
78
72
  # fail.
79
- module_function def final_response(jsonl)
73
+ def self.final_response(jsonl)
80
74
  result = result_event(jsonl)
81
75
  return nil unless result && result['is_error'] != true
82
76
 
@@ -90,26 +84,18 @@ module AgentCouncil
90
84
  'cache_read' => 'cache_read_input_tokens',
91
85
  'cache_write' => 'cache_creation_input_tokens' }.freeze
92
86
 
93
- # Token usage as AgentCouncil expects it (see Harnesses), from the
87
+ # Token usage as AgentCouncil expects it (see Harness), from the
94
88
  # result event alone: it totals all the agent's requests, while the assistant
95
89
  # events' usage is per-message snapshots that undercount output. nil
96
90
  # when the stream has no result event (as for an agent whose claude was
97
91
  # killed: no usage beats an undercount) or reports no usage (as when
98
92
  # the agent never reached a model).
99
- module_function def usage(jsonl)
93
+ def self.usage(jsonl)
100
94
  result = result_event(jsonl)
101
95
  usage = result && result['usage']
102
96
  return nil unless usage.is_a?(Hash)
103
97
 
104
- totals = USAGE_KEYS.transform_values { |key| count(usage[key]) }
105
- return nil if totals.values.all?(&:zero?)
106
-
107
- cost = count(result['total_cost_usd'])
108
- cost.positive? ? totals.merge('cost' => cost.round(6)) : totals
109
- end
110
-
111
- module_function def count(value)
112
- value.is_a?(Numeric) && value.positive? ? value : 0
98
+ usage_result(USAGE_KEYS.transform_values { |key| count(usage[key]) }, count(result['total_cost_usd']))
113
99
  end
114
100
 
115
101
  # Why the agent produced no usable report, or nil. A failed agent has a
@@ -119,23 +105,20 @@ module AgentCouncil
119
105
  # is its errors, if any (e.g. the turn limit, with no result text),
120
106
  # otherwise its result text (e.g. "Not logged in · Please run
121
107
  # /login").
122
- module_function def error_message(jsonl)
108
+ def self.error_message(jsonl)
123
109
  result = result_event(jsonl)
124
110
  return 'the stream has no result event' unless result
125
111
  return error_reason(result) || 'the agent failed and gave no reason' if result['is_error'] == true
126
112
 
127
- text = result['result']
128
- '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'])
129
114
  end
130
115
 
131
116
  # The reason a failed agent's result event gives, or nil if it gives none.
132
- module_function def error_reason(result)
133
- errors = Array(result['errors']).grep(String).map(&:strip).reject(&:empty?)
134
- return errors.join('; ') unless errors.empty?
135
-
136
- text = result['result']
137
- 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('; ')
138
120
  end
121
+ private_class_method :error_reason
139
122
 
140
123
  # Why an agent that exited nonzero failed. Claude Code explains a failure
141
124
  # in a result event with is_error true, and its stderr is then
@@ -143,16 +126,13 @@ module AgentCouncil
143
126
  # Otherwise stderr is likelier to say why (e.g. for a crash) than
144
127
  # whatever else the stream shows (e.g. a result with no text), which
145
128
  # is the last resort. Returned whole: the caller puts it on one line
146
- # and shortens it (see Harnesses).
147
- module_function def exit_detail(stdout, stderr)
129
+ # and shortens it (see Harness).
130
+ def self.exit_detail(stdout, stderr)
148
131
  result = result_event(stdout)
149
132
  reason = error_reason(result) if result && result['is_error'] == true
150
133
  return reason if reason
151
134
 
152
- stderr_line = stderr.lines.map(&:strip).reject(&:empty?).first
153
- return stderr_line if stderr_line
154
-
155
- (error_message(stdout) if result) || 'no error output'
135
+ first_line(stderr) || (error_message(stdout) if result) || NO_ERROR_OUTPUT
156
136
  end
157
137
 
158
138
  # Warnings about an agent, succeeded or not: the tool calls Claude Code
@@ -161,23 +141,25 @@ module AgentCouncil
161
141
  # call), but its report may be missing what the call would have
162
142
  # found; an agent that fails (say, out of turns) may have failed
163
143
  # because of them.
164
- module_function def warnings(jsonl)
144
+ def self.warnings(jsonl)
165
145
  result = result_event(jsonl)
166
146
  denials = result && result['permission_denials']
167
147
  return [] unless denials.is_a?(Array) && !denials.empty?
168
148
 
169
- calls = denials.map { |denial| denied_call(denial) }.uniq
170
- listed = calls.first(MAX_LISTED_CALLS).map do |tool, target|
171
- 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
172
151
  end
173
- listed << "and #{calls.size - listed.size} more" if calls.size > listed.size
174
- ["Claude Code refused #{denials.size} tool call#{'s' unless denials.size == 1}: #{listed.join('; ')}"]
152
+ [listing("Claude Code refused #{denials.size} tool call#{'s' unless denials.size == 1}", calls,
153
+ MAX_LISTED_CALLS)]
175
154
  end
176
155
 
177
156
  # Distinct refused calls named in a warning, so an agent refused many
178
157
  # times still gets a warning of a readable length.
179
158
  MAX_LISTED_CALLS = 5
180
159
 
160
+ # Characters of a refused call's target a warning shows.
161
+ MAX_TARGET_LENGTH = 80
162
+
181
163
  # The tool_input keys that say what a refused call was for, in order
182
164
  # of preference: Bash's command, Read's file_path, then Grep's and
183
165
  # Glob's pattern and path.
@@ -187,7 +169,7 @@ module AgentCouncil
187
169
  # such as a Bash command or the file a Read asked for, on one line,
188
170
  # or nil if the call gives none. Compared whole, so calls that differ
189
171
  # only past where a warning shortens them still count as different.
190
- module_function def denied_call(denial)
172
+ def self.denied_call(denial)
191
173
  return ['unknown tool', nil] unless denial.is_a?(Hash)
192
174
 
193
175
  tool = denial['tool_name'].is_a?(String) ? denial['tool_name'] : 'unknown tool'
@@ -196,10 +178,7 @@ module AgentCouncil
196
178
  target = target&.gsub(/\s+/, ' ')&.strip
197
179
  [tool, (target unless target.nil? || target.empty?)]
198
180
  end
199
-
200
- module_function def shorten(target)
201
- target.length > 80 ? "#{target[0, 80]}..." : target
202
- end
181
+ private_class_method :denied_call
203
182
  end
204
183
  end
205
184
  end