feat(agents): add Copilot and Pi agent support#1085
Conversation
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds two new agent implementations that execute external CLIs (Pi and Copilot) via BaseAgent, capturing stdout/stderr and attempting to parse token-usage from JSONL output.
Changes:
- Introduces
PiAgentto run/review tasks through Pi CLI in JSON mode and parse usage. - Introduces
CopilotAgentto run/review tasks through Copilot CLI with JSON output and parse usage.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/agents/pi-agent.js | New agent that shells out to pi CLI, parses JSONL, and returns AgentResult with usage fields. |
| src/agents/copilot-agent.js | New agent that shells out to copilot CLI, parses JSONL, and returns AgentResult with usage fields. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return { | ||
| ok: res.exitCode === 0, | ||
| output: res.stdout, | ||
| error: res.stderr, | ||
| exitCode: res.exitCode, | ||
| ...usage | ||
| }; |
| return { | ||
| ok: res.exitCode === 0, | ||
| output: res.stdout, | ||
| error: res.stderr, | ||
| exitCode: res.exitCode, | ||
| ...usage | ||
| }; |
| /** | ||
| * Extract usage from Copilot CLI JSONL output. | ||
| * Copilot CLI with --output-format json emits JSONL (one JSON object per line). | ||
| * We look for the final message with usage information. | ||
| */ | ||
| function extractCopilotUsage(text) { |
| return result; | ||
| } | ||
|
|
||
| async _exec(task, model, _jsonFormat) { |
| function extractPiUsage(text) { | ||
| if (!text) return null; | ||
|
|
||
| const lines = text.trim().split("\n"); | ||
| for (const line of lines) { | ||
| const t = line.trim(); | ||
| if (!t.startsWith("{")) continue; |
593c235 to
f0fa566
Compare
- Add CopilotAgent class with JSONL usage parsing for Copilot CLI - Add PiAgent class for pi.dev agent - Register both agents in the agent registry Related to: PR-J (audit quick win)
f0fa566 to
7c5b4e6
Compare
|
Resolving Copilot review comments: ✅ Comment 1 (pi-agent.js:114) - Null spread fix: Changed ✅ Comment 2 (copilot-agent.js:88) - Null spread fix: Same fix applied to CopilotAgent. ✅ Comment 3 (copilot-agent.js:9) - Comment fix: Changed 'final message' to 'first message' to match actual behavior. ✅ Comment 4 (copilot-agent.js:61) - Unused param: Parameter renamed to 💡 Comment 5 (pi-agent.js:15) - Shared helper: Noted as a future refactoring opportunity. The extraction logic is similar but has agent-specific nuances (different CLI output formats). Will factor into shared helper in a follow-up PR when more agents are added. |
Summary
CopilotAgentclass with JSONL usage parsing for Copilot CLIPiAgentclass for pi.dev agentRelated