agent-council 0.1.0 → 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.
@@ -1,16 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # AgentCouncil::Harnesses::PiHarness — all knowledge specific to the pi
4
- # coding-agent harness: how to invoke the pi CLI for one model run, the
5
- # tool allowlist, and read-only scaffolding delivered with it, and how to
6
- # read pi's JSONL event stream afterward.
4
+ # coding-agent harness: how to invoke the pi CLI for one agent, with
5
+ # its tool allowlist and the shared read-only scaffolding, and how to read
6
+ # pi's JSONL event stream afterward.
7
7
  #
8
- # AgentCouncil is harness-agnostic and refers to this module only via
9
- # AgentCouncil::HARNESS. A second harness (claude, codex, ...) would be
10
- # another module under AgentCouncil::Harnesses shaped like this one —
11
- # this is deliberately a plain namespace, not an adapter framework.
8
+ # AgentCouncil is harness-agnostic and finds this module through
9
+ # AgentCouncil::Harnesses (lib/agent_council/harnesses.rb), by its NAME.
12
10
 
13
11
  require 'json'
12
+ require_relative 'scaffold'
14
13
 
15
14
  module AgentCouncil
16
15
  module Harnesses
@@ -20,62 +19,45 @@ module AgentCouncil
20
19
  # Analysis toolset (pi's built-in tool names): edit/write (and the
21
20
  # Windows-only powershell) are withheld. bash, a full shell, stays for
22
21
  # investigation (git log/status, dependency inspection, ...); only the
23
- # scaffolding text asks the model to use it read-only.
24
- TOOLS = 'read,grep,find,ls,bash'
25
-
26
- # Invocation for one model run. The substantive prompt is not part of argv;
22
+ # scaffolding text asks the model to use it read-only. The rest give
23
+ # agents the MCP tools pi gives an interactive session, however a
24
+ # server exposes them: codemode for the default exposure (a server's
25
+ # tools are called from a codemode script, which reaches only the
26
+ # tools listed here), mcp__* for servers with direct exposure,
27
+ # tool_search for servers with deferred exposure (it loads only MCP
28
+ # tools, not withheld built-in ones), and pi's MCP resource tools,
29
+ # which --tools would drop once it names an mcp__ entry.
30
+ TOOLS = %w[read grep find ls bash
31
+ codemode mcp__* tool_search
32
+ list_mcp_resources list_mcp_resource_templates read_mcp_resource].join(',')
33
+
34
+ # Invocation for one agent. The substantive prompt is not part of argv;
27
35
  # it is piped to stdin (byte-identical for every analyst; the
28
36
  # consolidator gets its own).
29
- module_function def argv(provider, model, scratch_dir)
37
+ module_function def argv(provider, model)
30
38
  [
31
39
  NAME,
32
40
  '-p', # non-interactive: process prompt and exit
33
41
  '--mode', 'json', # JSONL event stream on stdout
34
- '--no-session', # ephemeral: no session state between runs
42
+ '--no-session', # ephemeral: no session state between agents
35
43
  '--tools', TOOLS,
36
44
  '--provider', provider,
37
45
  '--model', model,
38
- '--append-system-prompt', scaffold_text(scratch_dir)
46
+ '--append-system-prompt', Harnesses.scaffold_text
39
47
  ]
40
48
  end
41
49
 
42
- # Scaffolding appended to pi's system prompt. Identical for every agent
43
- # except the scratch dir path.
44
- module_function def scaffold_text(scratch_dir)
45
- <<~TEXT
46
- You are one of the independent agents agent-council runs on this
47
- repository. This is a strictly read-only analysis task.
48
-
49
- Rules:
50
- - Do not modify, create, rename, or delete any project source or
51
- configuration file. Do not change git state, install or remove
52
- software, modify user or system configuration, or start persistent
53
- services.
54
- - Do not run test suites, builds, coverage tools, application servers,
55
- or database tasks unless the user's prompt explicitly permits it:
56
- other agents may be running concurrently and such commands can collide
57
- through shared state (databases, ports, Docker, fixed temp paths).
58
- Where the prompt permits them, direct their temporary output to the
59
- scratch directory below, and still skip any that need shared
60
- services (databases, servers, fixed ports, Docker). Otherwise, if
61
- running such a command would materially improve your analysis,
62
- describe what you would run and why instead of running it.
63
- - You may run clearly read-only commands: reading, searching, and
64
- listing files; inspecting git history and status; inspecting
65
- dependency and configuration information.
66
- - If you need scratch space for temporary artifacts, use this
67
- disposable directory that is unique to your run: #{scratch_dir}
68
- - Deliver your complete analysis as your final message text. Do not
69
- write the report to a file; the orchestrator captures your final
70
- message directly.
71
- TEXT
72
- end
73
-
74
50
  # --- event stream reading ---
75
51
 
76
52
  # The assistant message from a single pi JSONL line, or nil if the line
77
53
  # is not an assistant message_end event.
78
54
  module_function def assistant_message_from_line(line)
55
+ message_from_line(line, %w[assistant])
56
+ end
57
+
58
+ # The message with one of the given roles from a single pi JSONL line,
59
+ # or nil if the line is not a message_end event for one.
60
+ module_function def message_from_line(line, roles)
79
61
  event =
80
62
  begin
81
63
  JSON.parse(line)
@@ -87,7 +69,7 @@ module AgentCouncil
87
69
  return nil unless event['type'] == 'message_end'
88
70
 
89
71
  message = event['message']
90
- return nil unless message && message['role'] == 'assistant'
72
+ return nil unless message.is_a?(Hash) && roles.include?(message['role'])
91
73
 
92
74
  message
93
75
  end
@@ -124,12 +106,14 @@ module AgentCouncil
124
106
  'cache_read' => 'cacheRead', 'cache_write' => 'cacheWrite' }.freeze
125
107
 
126
108
  # Token usage summed over all assistant messages (each is a separate
127
- # model request), as AgentCouncil expects it: integer 'input', 'output',
128
- # 'cache_read', and 'cache_write', plus 'cost' in US dollars when pi
129
- # priced the run. nil when the stream reports no usage, as some
130
- # providers don't.
109
+ # model request) and tool results, as AgentCouncil expects it: integer
110
+ # 'input', 'output', 'cache_read', and 'cache_write', plus 'cost' in US
111
+ # dollars when pi priced the usage. A tool result has usage when the
112
+ # tool called a model itself, e.g. a codemode script's models.classify
113
+ # call. nil when the stream reports no usage, as some providers don't.
131
114
  module_function def usage(jsonl)
132
- usages = assistant_messages(jsonl).map { |m| m['usage'] }.grep(Hash)
115
+ messages = jsonl.each_line.filter_map { |line| message_from_line(line, %w[assistant toolResult]) }
116
+ usages = messages.map { |m| m['usage'] }.grep(Hash)
133
117
  totals = USAGE_KEYS.transform_values { |key| usages.sum { |u| count(u[key]) } }
134
118
  return nil if totals.values.all?(&:zero?)
135
119
 
@@ -146,7 +130,7 @@ module AgentCouncil
146
130
  # instead; this catches one that is missing or blank.
147
131
  UNUSABLE_STOP_REASONS = %w[length aborted error].freeze
148
132
 
149
- # Why the run produced no usable report, or nil. Pi exits 0 even when the
133
+ # Why the agent produced no usable report, or nil. Pi exits 0 even when the
150
134
  # provider rejects the request or the output hits its token limit, so this
151
135
  # is how such failures are surfaced. Two messages are checked: the final
152
136
  # one (an error in an earlier turn that a later turn recovered from is not
@@ -164,6 +148,18 @@ module AgentCouncil
164
148
  message = candidates.detect { |m| UNUSABLE_STOP_REASONS.include?(m['stopReason']) }
165
149
  message && "stopped early (stopReason: #{message['stopReason']})"
166
150
  end
151
+
152
+ # Why an agent that exited nonzero failed: pi explains it on stderr.
153
+ module_function def exit_detail(_stdout, stderr)
154
+ stderr.lines.map(&:strip).reject(&:empty?).first || 'no error output'
155
+ end
156
+
157
+ # Warnings about an agent that succeeded: none. A failed tool call,
158
+ # MCP calls included, is an ordinary tool error the agent sees, not a
159
+ # refusal (DESIGN.md §11).
160
+ module_function def warnings(_jsonl)
161
+ []
162
+ end
167
163
  end
168
164
  end
169
165
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ # AgentCouncil::Harnesses.scaffold_text — the read-only scaffolding every
4
+ # harness appends to its agents' system prompt. In its own file so each
5
+ # harness module can require it without the harness registry
6
+ # (lib/agent_council/harnesses.rb), which requires the harness modules.
7
+
8
+ module AgentCouncil
9
+ module Harnesses
10
+ # Scaffolding appended to every harness's system prompt, identical for
11
+ # every agent. It names the scratch dir as $TMPDIR, not by path: Claude
12
+ # Code's sandbox makes the dir itself read-only and points TMPDIR at a
13
+ # writable dir inside it.
14
+ module_function def scaffold_text
15
+ <<~TEXT
16
+ You are one of the independent agents agent-council runs on this
17
+ repository. This is a strictly read-only analysis task.
18
+
19
+ Rules:
20
+ - Do not modify, create, rename, or delete any project source or
21
+ configuration file. Do not change git state, install or remove
22
+ software, modify user or system configuration, or start persistent
23
+ services.
24
+ - Do not act outside this machine, with any tool (MCP tools
25
+ included): do not post, comment, send messages, or create or
26
+ change issues, tickets, records, or other remote data. Reading
27
+ remote information is fine.
28
+ - Do not run test suites, builds, coverage tools, application servers,
29
+ or database tasks unless the user's prompt explicitly permits it:
30
+ other agents may be running concurrently and such commands can collide
31
+ through shared state (databases, ports, Docker, fixed temp paths).
32
+ Where the prompt permits them, direct their temporary output to
33
+ $TMPDIR (see below), and still skip any that need shared
34
+ services (databases, servers, fixed ports, Docker). Otherwise, if
35
+ running such a command would materially improve your analysis,
36
+ describe what you would run and why instead of running it.
37
+ - You may run clearly read-only commands: reading, searching, and
38
+ listing files; inspecting git history and status; inspecting
39
+ dependency and configuration information.
40
+ - If you need scratch space for temporary artifacts, use $TMPDIR: it
41
+ is a disposable directory unique to you.
42
+ - Deliver your complete analysis as your final message text. Do not
43
+ write the report to a file; the orchestrator captures your final
44
+ message directly.
45
+ TEXT
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ # AgentCouncil::Harnesses — the harnesses agents can run under, by the name
4
+ # a config entry gives in its 'harness' key. What they share, the read-only
5
+ # scaffolding, is in harnesses/scaffold.rb.
6
+ #
7
+ # Each harness is a plain module shaped like PiHarness (NAME, argv, usage,
8
+ # error_message, exit_detail, warnings, final_response,
9
+ # assistant_messages), not an adapter framework; AgentCouncil looks one up
10
+ # per agent with module_for. NAME is both the config value and the
11
+ # executable argv runs, which the startup check looks for on PATH. The
12
+ # scaffolding sends agents to $TMPDIR, which run_agent sets to the
13
+ # scratch dir, so a harness must pass TMPDIR through to its tools. It also
14
+ # goes into report filenames unsanitized, so it must be one
15
+ # AgentCouncil.sanitize leaves unchanged (the specs check this).
16
+ #
17
+ # exit_detail (stdout, stderr) says why an agent that exited nonzero failed;
18
+ # the caller puts it, and error_message's reason, on one line cut to 300
19
+ # characters (AgentCouncil.failure_reason), so a harness returns the
20
+ # reason whole. warnings returns an Array of messages (empty for none)
21
+ # about an agent, failed or not; the caller prints and records them all, so a
22
+ # harness keeps them few and short.
23
+ #
24
+ # usage returns the agent's token usage as AgentCouncil records it, summed
25
+ # over all its requests: integer 'input' (excluding cached input), 'output',
26
+ # 'cache_read', and 'cache_write', plus 'cost' in US dollars when the
27
+ # harness priced the usage; or nil when the harness reports no usage.
28
+
29
+ require_relative 'harnesses/pi_harness'
30
+ require_relative 'harnesses/claude_code_harness'
31
+ require_relative 'harnesses/codex_harness'
32
+
33
+ module AgentCouncil
34
+ module Harnesses
35
+ BY_NAME = [PiHarness, ClaudeCodeHarness, CodexHarness].to_h { |harness| [harness::NAME, harness] }.freeze
36
+
37
+ # The harness of a report or run.json entry without a 'harness' key:
38
+ # agent-council writes one in each, so these are hand-edited or older
39
+ # than 0.1.0, when every agent ran under pi.
40
+ # A config entry must name its harness (see AgentCouncil.entry_error).
41
+ DEFAULT_NAME = PiHarness::NAME
42
+
43
+ # The harness name a config entry, report front matter, or run.json
44
+ # entry gives, or DEFAULT_NAME when it gives no string one. Config
45
+ # entries are validated first (see AgentCouncil.entry_error), so only
46
+ # unvalidated ones, such as a hand-edited report's front matter or an
47
+ # older run's, are read as pi.
48
+ module_function def name_of(entry)
49
+ harness = entry['harness'] if entry.is_a?(Hash)
50
+ harness.is_a?(String) ? harness : DEFAULT_NAME
51
+ end
52
+
53
+ # The harness module for an entry; KeyError for an unknown name, which
54
+ # config validation rules out before any agent runs.
55
+ module_function def module_for(entry)
56
+ BY_NAME.fetch(name_of(entry))
57
+ end
58
+ end
59
+ end
@@ -38,7 +38,7 @@ module AgentCouncil
38
38
  RPC_REQUEST_ID = 'list-models'
39
39
 
40
40
  module_function def fetch_models
41
- Open3.popen3('pi', '--mode', 'rpc', '--no-session') do |stdin, stdout, stderr, wait_thr|
41
+ Open3.popen3('pi', '--mode', 'rpc', '--no-session', '--no-mcp') do |stdin, stdout, stderr, wait_thr|
42
42
  # pi's output is UTF-8, whatever the locale.
43
43
  [stdout, stderr].each { |io| io.set_encoding(Encoding::UTF_8) }
44
44
  # Drain stderr concurrently so a chatty pi can't block on a full pipe,
@@ -1,8 +1,8 @@
1
1
  # Report format
2
2
 
3
3
  Your response will be saved as a standalone Markdown report. A metadata
4
- table (role, agent, query, harness, provider, model, timestamp, duration)
5
- is prepended to it
4
+ table (role, agent, query, harness, provider, model, timestamp, duration,
5
+ usage, and any warnings) is prepended to it
6
6
  automatically, so:
7
7
 
8
8
  - Do not add a document title or any top-level (`#`) heading.
@@ -5,8 +5,8 @@ Every analyst received the identical prompt (included below as "Original
5
5
  prompt"), followed by formatting instructions for its report. Their reports follow under "Analyst reports", each headed "Report
6
6
  from" its source label (`#<agent number> <provider> / <model>`), with a
7
7
  "Harness:" line below it. Agents that produced no report are listed last,
8
- under "Agents without a report", each with the reason shown there (its
9
- failure, when known).
8
+ under "Agents without a report", each with its harness and the reason
9
+ shown there (its failure, when known, and any warnings about that agent).
10
10
 
11
11
  Produce a consolidated report in two parts, with exactly these sections in
12
12
  this order. The first part is the findings; the second describes the
@@ -30,8 +30,10 @@ Issues raised by exactly one analyst, attributed to its source.
30
30
 
31
31
  - Assess whether each is plausible.
32
32
  - Group findings by agent; for each group:
33
- - output a heading with the agent number, harness, provider, and model
34
- name (the harness is shown under each report's heading)
33
+ - output a heading with the agent number, harness, provider, and model,
34
+ as `#<agent number> <harness> / <provider> / <model>` (e.g. `#1 claude /
35
+ anthropic / claude-opus-5-5`); the harness is on the "Harness:" line
36
+ under each report's heading
35
37
 
36
38
  ## Contradictions
37
39
 
@@ -47,18 +49,20 @@ result.
47
49
 
48
50
  ## Agent Consultants
49
51
 
50
- A list of provider/model agents consulted. For each agent listed under
52
+ A list of the agents consulted, by harness, provider, and model. For each agent listed under
51
53
  "Agents without a report", say it produced no report and give the reason
52
54
  shown there; do not infer failures any other way. If a report shows its
53
- agent could not properly do the task, say so too.
55
+ agent could not properly do the task, say so too, including when its
56
+ metadata table lists warnings, such as tool calls its harness refused.
54
57
 
55
58
  ## Agent performance
56
59
 
57
60
  A brief review of each agent that produced a report: how deep its research
58
61
  went (e.g. did it read code, run commands, verify claims) and how much it
59
62
  added to the review (unique or confirmed findings vs. noise or errors).
60
- For each agent, print a header line with agent number, duration, harness, provider,
61
- and model. Then print a single text string below it with the performance information.
63
+ For each agent, print a header line with its agent number, harness, provider,
64
+ and model, as in the Unique findings headings, followed by its duration. Then
65
+ print a single text string below it with the performance information.
62
66
 
63
67
  Rules:
64
68
  - Begin directly with the "## Findings" section; do not add a
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AgentCouncil
4
- VERSION = '0.1.0'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -11,10 +11,12 @@ module AgentCouncil
11
11
  # terminal's Ctrl-C reaches only agent-council, never the agents. Once
12
12
  # #trap_signals is installed, the first INT, TERM, HUP, or QUIT (not on
13
13
  # JRuby; see TERMINATING_SIGNALS) raises Interrupt in the main thread,
14
- # whose rescue calls #shutdown: it sends every agent SIGTERM (pi then also
15
- # stops any commands its bash tool started, which run detached and so would
16
- # survive the agent), waits up to the grace period for the workers to
17
- # finish, and SIGKILLs agents still running. A second trapped signal other
14
+ # whose rescue calls #shutdown: it sends every agent SIGTERM, waits up to
15
+ # the grace period for the workers to finish, and SIGKILLs agents still
16
+ # running. The commands an agent's shell tool started run in process
17
+ # groups of their own, which these signals don't reach; pi, Claude
18
+ # Code, and Codex stop them on SIGTERM, but an agent that is SIGKILLed can't, so
19
+ # they may keep running. A second trapped signal other
18
20
  # than HUP SIGKILLs them at once. Any HUP after the first signal is
19
21
  # ignored: a closing terminal can deliver two at once (one forwarded by the
20
22
  # shell, one from the kernel), which must not skip the graceful stop. A