@doidor/agentrig 0.5.3

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.
Files changed (94) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +224 -0
  3. package/dist/agent/claude.js +125 -0
  4. package/dist/agent/claude.js.map +1 -0
  5. package/dist/agent/copilot.js +147 -0
  6. package/dist/agent/copilot.js.map +1 -0
  7. package/dist/agent/index.js +17 -0
  8. package/dist/agent/index.js.map +1 -0
  9. package/dist/agent/provider.js +10 -0
  10. package/dist/agent/provider.js.map +1 -0
  11. package/dist/cli.js +169 -0
  12. package/dist/cli.js.map +1 -0
  13. package/dist/commands/compile.js +42 -0
  14. package/dist/commands/compile.js.map +1 -0
  15. package/dist/commands/dashboard.js +35 -0
  16. package/dist/commands/dashboard.js.map +1 -0
  17. package/dist/commands/doctor.js +40 -0
  18. package/dist/commands/doctor.js.map +1 -0
  19. package/dist/commands/eval.js +178 -0
  20. package/dist/commands/eval.js.map +1 -0
  21. package/dist/commands/init.js +100 -0
  22. package/dist/commands/init.js.map +1 -0
  23. package/dist/commands/update.js +176 -0
  24. package/dist/commands/update.js.map +1 -0
  25. package/dist/core/activity.js +80 -0
  26. package/dist/core/activity.js.map +1 -0
  27. package/dist/core/audit.js +112 -0
  28. package/dist/core/audit.js.map +1 -0
  29. package/dist/core/compile.js +250 -0
  30. package/dist/core/compile.js.map +1 -0
  31. package/dist/core/fsutil.js +45 -0
  32. package/dist/core/fsutil.js.map +1 -0
  33. package/dist/core/install.js +97 -0
  34. package/dist/core/install.js.map +1 -0
  35. package/dist/core/knowledge.js +34 -0
  36. package/dist/core/knowledge.js.map +1 -0
  37. package/dist/core/logger.js +31 -0
  38. package/dist/core/logger.js.map +1 -0
  39. package/dist/core/paths.js +22 -0
  40. package/dist/core/paths.js.map +1 -0
  41. package/dist/core/setupsteps.js +72 -0
  42. package/dist/core/setupsteps.js.map +1 -0
  43. package/dist/core/state.js +19 -0
  44. package/dist/core/state.js.map +1 -0
  45. package/dist/core/surfaces.js +62 -0
  46. package/dist/core/surfaces.js.map +1 -0
  47. package/dist/prompts/index.js +117 -0
  48. package/dist/prompts/index.js.map +1 -0
  49. package/dist/version.js +26 -0
  50. package/dist/version.js.map +1 -0
  51. package/knowledge/PRINCIPLES.md +106 -0
  52. package/knowledge/manifest.json +247 -0
  53. package/knowledge/templates/AGENTS.md +66 -0
  54. package/knowledge/templates/AGENTS.package.example.md +19 -0
  55. package/knowledge/templates/agents/README.md +33 -0
  56. package/knowledge/templates/agents/developer.md +7 -0
  57. package/knowledge/templates/agents/developer.yml +7 -0
  58. package/knowledge/templates/agents/judge.md +6 -0
  59. package/knowledge/templates/agents/judge.yml +6 -0
  60. package/knowledge/templates/agents/reviewer.md +6 -0
  61. package/knowledge/templates/agents/reviewer.yml +7 -0
  62. package/knowledge/templates/agents/triager.md +8 -0
  63. package/knowledge/templates/agents/triager.yml +8 -0
  64. package/knowledge/templates/dashboard/dashboard.mjs +261 -0
  65. package/knowledge/templates/eval/RUBRIC.md +94 -0
  66. package/knowledge/templates/eval/axes.json +56 -0
  67. package/knowledge/templates/eval/checks.json +304 -0
  68. package/knowledge/templates/eval/sandbox/eval-rules.md +23 -0
  69. package/knowledge/templates/eval/scenarios/README.md +24 -0
  70. package/knowledge/templates/eval/scenarios/add-small-feature.md +28 -0
  71. package/knowledge/templates/eval/scenarios/fix-failing-test.md +27 -0
  72. package/knowledge/templates/eval/scenarios/review-catches-bug.md +30 -0
  73. package/knowledge/templates/eval/score.mjs +257 -0
  74. package/knowledge/templates/eval/static-audit.mjs +112 -0
  75. package/knowledge/templates/harness/ORCHESTRATION.md +53 -0
  76. package/knowledge/templates/harness/state-machine.yml +105 -0
  77. package/knowledge/templates/mcp/mcp.json +12 -0
  78. package/knowledge/templates/rules/README.md +32 -0
  79. package/knowledge/templates/rules/code-review.md +26 -0
  80. package/knowledge/templates/rules/coding-standards.md +15 -0
  81. package/knowledge/templates/rules/no-debug-logging.md +16 -0
  82. package/knowledge/templates/rules/security.md +23 -0
  83. package/knowledge/templates/scripts/repair-worktrees.sh +124 -0
  84. package/knowledge/templates/skills/fix-ci/SKILL.md +17 -0
  85. package/knowledge/templates/skills/harness-eval/SKILL.md +83 -0
  86. package/knowledge/templates/skills/self-verify/SKILL.md +25 -0
  87. package/knowledge/templates/skills/skill-authoring/SKILL.md +35 -0
  88. package/knowledge/templates/skills/skill-improver/SKILL.md +23 -0
  89. package/knowledge/templates/skills/verify-loop/SKILL.md +35 -0
  90. package/knowledge/templates/wiki/README.md +23 -0
  91. package/knowledge/templates/wiki/_TEMPLATE.md +16 -0
  92. package/knowledge/templates/wiki/index.md +29 -0
  93. package/knowledge/templates/wiki/troubleshooting.md +14 -0
  94. package/package.json +70 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Microsoft Corporation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,224 @@
1
+ # AgentRig
2
+
3
+ [![CI](https://github.com/doidor/agentrig/actions/workflows/ci.yml/badge.svg)](https://github.com/doidor/agentrig/actions/workflows/ci.yml)
4
+ [![Release](https://github.com/doidor/agentrig/actions/workflows/release.yml/badge.svg)](https://github.com/doidor/agentrig/actions/workflows/release.yml)
5
+ [![npm](https://img.shields.io/npm/v/@doidor/agentrig)](https://www.npmjs.com/package/@doidor/agentrig)
6
+ [![node](https://img.shields.io/node/v/@doidor/agentrig)](https://nodejs.org)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
8
+
9
+ **An agentic meta-harness — a harness of harnesses.**
10
+
11
+ AgentRig is a lightweight CLI that installs a **best-practice agent harness** into any repository and
12
+ then **projects it into every agent's native format** — so *any* agent benefits without lock-in,
13
+ **local and remote**:
14
+
15
+ - **Local CLIs** — Copilot CLI, Claude Code, OpenCode, Codex, Cursor.
16
+ - **Remote / cloud** — the web **GitHub Copilot coding agent** (create an issue, assign it to
17
+ Copilot, walk away).
18
+
19
+ You keep **one** source of truth (`AGENTS.md` + rules + skills); AgentRig compiles it into
20
+ `copilot-instructions.md`, `.github/instructions/`, `CLAUDE.md`, `.cursor/rules/`, MCP configs, and a
21
+ `copilot-setup-steps.yml` for the cloud agent. It also keeps everything in sync as best practices
22
+ evolve, and ships a way to **evaluate the harness itself**.
23
+
24
+ ```bash
25
+ npx @doidor/agentrig init # investigate this repo, install a tailored harness, compile all surfaces
26
+ npx @doidor/agentrig compile # re-project AGENTS.md + rules into every agent surface (local + remote)
27
+ npx @doidor/agentrig eval # score the harness (deterministic, no model needed)
28
+ npx @doidor/agentrig update # pull in the latest best practices
29
+ ```
30
+
31
+ > Or install it globally — `npm i -g @doidor/agentrig` — and run `agentrig <command>`.
32
+ > Examples below use the `agentrig` command for brevity.
33
+
34
+ ---
35
+
36
+ ## Why
37
+
38
+ Modern autonomous-agent setups converge on the same dozen principles (explicit state machine,
39
+ specialized roles on varied models, GitHub as system of record, skills + rules, self-verification,
40
+ rubric-driven evaluation, hermetic worktrees, continuous self-improvement, human gates, hard limits,
41
+ **one canonical source projected to every surface**, instructions-as-source-of-truth). Standing all
42
+ of that up by hand, per repo, per agent tool, is tedious and drifts. AgentRig encodes the principles
43
+ once as **editable plain text**, installs them anywhere, **projects them to every agent surface**,
44
+ and ships the tooling to **measure** whether your harness is actually good.
45
+
46
+ The principles are documented in [`knowledge/PRINCIPLES.md`](knowledge/PRINCIPLES.md).
47
+
48
+ ## How it works
49
+
50
+ `agentrig init` runs these phases:
51
+
52
+ 1. **Investigate (agentic).** An agent explores the repo and writes an evidence-based
53
+ `.agentrig/context.md`: purpose, stack, real build/test/lint commands, layout, conventions, risks.
54
+ 2. **Install (deterministic).** The canonical harness artifacts from `knowledge/` are copied in,
55
+ guaranteeing a baseline that passes the audit regardless of the model.
56
+ 3. **Tailor (agentic).** The same conversation — keeping repo context — fills in `AGENTS.md`,
57
+ rewrites the baseline rules for your stack, and adapts the eval scenarios.
58
+ 4. **Compile (deterministic).** Projects `AGENTS.md` + rules into every agent surface, local and
59
+ remote (see [Surfaces](#surfaces)).
60
+
61
+ Run with `--skip-agent` to install + compile deterministically with no model, or `--dry-run` to
62
+ preview.
63
+
64
+ ## Surfaces
65
+
66
+ One canonical source → every agent's native format (`agentrig compile`, also run by `init`/`update`):
67
+
68
+ | Agent | Generated surface |
69
+ |-------|-------------------|
70
+ | **GitHub Copilot — coding agent (web) + IDE** | `.github/copilot-instructions.md`, `.github/instructions/*.instructions.md` (`applyTo` from rule globs), `.github/workflows/copilot-setup-steps.yml` |
71
+ | **Claude Code** | `CLAUDE.md` (imports `@AGENTS.md`) + `.claude/` skills |
72
+ | **Cursor** | `.cursor/rules/*.mdc` (globs + `alwaysApply`) |
73
+ | **OpenCode / Codex** | `AGENTS.md` (native) |
74
+ | **MCP (any)** | `.mcp.json`, `.vscode/mcp.json`, `.github/copilot/mcp.json` |
75
+
76
+ Edit the **source** (`AGENTS.md`, `.agents/rules/`) and re-run `agentrig compile` — never hand-edit
77
+ the generated files. Commit them so remote agents (and teammates' tools) pick them up.
78
+
79
+ > **`copilot-setup-steps.yml` is authored per-repo.** During `agentrig init`, the agent inspects
80
+ > your real stack (runtimes/versions, package manager, install commands, caching, services) and
81
+ > writes a genuine setup workflow so the GitHub Copilot **cloud agent** has a ready environment — not
82
+ > a generic stub. After the first scaffold it's yours; `compile`/`update` won't overwrite it.
83
+ > (With `--skip-agent`, a heuristic scaffold is generated as a fallback.) AgentRig **validates** the
84
+ > workflow (job name, `runs-on`/`steps`, `timeout-minutes ≤ 59`, tabs, and — when available — a real
85
+ > YAML parse + `actionlint`) during `compile`/`init` and in `agentrig doctor`, so a broken file is
86
+ > caught before you push. GitHub also runs it as an Actions workflow on push for final validation.
87
+
88
+ ## What gets installed
89
+
90
+ | Principle | Artifact |
91
+ |----------:|----------|
92
+ | 1 Explicit state machine | `.agentrig/harness/state-machine.yml` + `ORCHESTRATION.md` (a workflow *contract* for whatever runtime you use) |
93
+ | 2 Specialized roles, varied models | `.agentrig/agents/{triager,developer,reviewer,judge}.{yml,md}` on distinct `model_tiers` + `README.md` |
94
+ | 3 System of record | label↔state map + reconciliation/recovery cadences + MCP GitHub server + `agentrig dashboard` |
95
+ | 4 Skills & rules | `.agents/skills/*/SKILL.md` (incl. `verify-loop`, `skill-authoring`), `.agents/rules/` (security, code-review, …, priority-ordered) |
96
+ | 5 Self-verify before handoff | `.agents/skills/self-verify/` + generalized `verify-loop/` |
97
+ | 6 Rubric-driven evaluation | `.agentrig/eval/` (axes.json registry, multi-rubric lifecycle, sandbox, A/B) + `.agents/skills/harness-eval/` |
98
+ | 7 Hermetic worktrees | `scripts/repair-worktrees.sh` (add + safe archive-before-reset repair) |
99
+ | 8 Continuous self-improvement | `.agents/wiki/` (index router + troubleshooting + entry template) + `skill-improver` |
100
+ | 9 Human-in-the-loop | human-only gates in the state machine |
101
+ | 10 Hard limits | `limits:` + `runaway_token_cap` in the state machine |
102
+ | 11 One source → every surface | the compiler: `copilot-instructions.md`, `.github/instructions/`, `CLAUDE.md`, `.cursor/rules/`, MCP configs, `copilot-setup-steps.yml` |
103
+ | 12 Instructions are source of truth | `AGENTS.md` (Critical Rules + auto-generated skills inventory) + package-local AGENTS.md |
104
+
105
+ ## Evaluating the harness itself
106
+
107
+ This is a first-class feature, not an afterthought — and it's **repo-specific and runnable by you**.
108
+ The eval kit installs into your repo (`.agentrig/eval/`) and is tailored to it during `init`, so you
109
+ can measure whether AgentRig actually helps *here*. `agentrig eval` **defaults to the full agentic,
110
+ harness-on run**; add `--static` for the fast no-model audit. Two layers:
111
+
112
+ - **Static audit (deterministic, no model).** Maps each principle to a structural check in
113
+ `.agentrig/eval/checks.json`, scored `0 / 0.5 / 1.0`, producing a **Harness Score**.
114
+
115
+ ```bash
116
+ agentrig eval --static # or: node .agentrig/eval/static-audit.mjs
117
+ agentrig eval --static --min 80 # CI gate: non-zero exit below 80%
118
+ ```
119
+
120
+ - **Dynamic behavioral eval (agentic, independent judge — the default).** Runs benchmark scenarios
121
+ (`.agentrig/eval/scenarios/*.md`) through the harness and scores the results with an **independent
122
+ judge model**. Scoring is rigorous: a registry (`axes.json`) of bounded **issue codes per axis**,
123
+ strict `0/0.5/1.0` tiers, mandatory evidence, confidence-gated rollups recomputed from the axis
124
+ data, and three **lifecycle rubrics** (`spec` / `run` / `review`). `score.mjs` validates everything
125
+ and never lets a judge invent codes. Runs are sandboxed (no push, no PR, no merge).
126
+
127
+ ```bash
128
+ agentrig eval # the default: full agentic, harness-on run
129
+ agentrig eval --dynamic --scenario add-small-feature --timeout 60
130
+ agentrig eval --rubric # print exactly what's measured (axes, codes, scenarios)
131
+ node .agentrig/eval/score.mjs report
132
+ ```
133
+
134
+ **What's being evaluated?** The rubric lives in `.agentrig/eval/RUBRIC.md` and the machine-readable
135
+ registry in `.agentrig/eval/axes.json`; scenarios are in `.agentrig/eval/scenarios/`. Run
136
+ `agentrig eval --rubric` to print the rubric types, every axis and its issue codes, and the
137
+ installed scenarios.
138
+
139
+ ### Does the harness actually help? (harness lift)
140
+
141
+ Prove the harness earns its keep in *your* repo by running a scenario **with** and **without** it:
142
+
143
+ ```bash
144
+ agentrig eval --dynamic --scenario <id> --variant harness # harness ON
145
+ agentrig eval --dynamic --scenario <id> --variant baseline # bare agent, no AGENTS.md/rules/skills
146
+ node .agentrig/eval/score.mjs compare --scenario <id> --baseline baseline
147
+ ```
148
+
149
+ `compare --baseline` prints the per-axis and aggregate **delta** with a `HELPS`/`HURTS` verdict — so
150
+ you can see, and track over time, whether installing AgentRig measurably improves agent behavior here
151
+ (and whether each rule/skill/prompt change is a real improvement or a regression).
152
+
153
+ ## Dashboard
154
+
155
+ `agentrig dashboard` gives you a single-glance view of the harness — installed into every repo as a
156
+ dependency-free script (`.agentrig/dashboard/dashboard.mjs`), so it runs with or without the global
157
+ CLI:
158
+
159
+ - **Agent roster** — every role and the model it runs on.
160
+ - **Live GitHub tasks** — open issues/PRs carrying each harness label, grouped by workflow state and
161
+ showing assignees, fetched via the `gh` CLI (degrades gracefully when `gh` is absent/unauthed).
162
+ - **Harness Score** — the latest static-audit score and any weak principles.
163
+ - **Evals** — the latest dynamic-eval summary.
164
+ - **Limits** — the hard caps from the state machine.
165
+
166
+ ```bash
167
+ agentrig dashboard # terminal view
168
+ agentrig dashboard --json # machine-readable
169
+ agentrig dashboard --html dash.html # self-contained web page
170
+ agentrig dashboard --no-tasks # offline (skip gh lookups)
171
+ ```
172
+
173
+
174
+ ## Editing the best practices
175
+
176
+ All best practices are plain text under [`knowledge/`](knowledge/). Edit `PRINCIPLES.md`, the
177
+ templates, or `checks.json`, then propagate to any repo:
178
+
179
+ ```bash
180
+ agentrig update # re-sync the latest canonical artifacts, reconciling local customizations
181
+ ```
182
+
183
+ `update` refreshes AgentRig-owned files in place and asks the agent to merge changes into files you
184
+ customize (like `AGENTS.md`), preserving your repo-specific facts.
185
+
186
+ ## Commands
187
+
188
+ | Command | Description |
189
+ |---------|-------------|
190
+ | `agentrig init [path]` | Investigate + install a tailored harness, then compile surfaces |
191
+ | `agentrig compile [path]` | Project AGENTS.md + rules into every agent surface (local + remote) |
192
+ | `agentrig update [path]` | Re-sync the latest best practices (re-compiles surfaces) |
193
+ | `agentrig eval [path] [--static\|--rubric] [--scenario id] [--variant name]` | Evaluate the harness (default: agentic; `--rubric` shows what's measured) |
194
+ | `agentrig dashboard [path] [--html [file]] [--no-tasks] [--json]` | Roster, live GitHub tasks, score, evals |
195
+ | `agentrig doctor [path] [--json]` | Health check (installed? agent reachable? score?) |
196
+
197
+ Common options: `--model <id>`, `--dry-run`, `--skip-agent`, `--verbose`.
198
+ Set `AGENTRIG_PROVIDER` to choose the agent backend (default `copilot`).
199
+
200
+ ## Requirements
201
+
202
+ - Node.js ≥ 22 (Node 20 is EOL; tested on the current LTS lines, 22 and 24).
203
+ - For agentic steps, pick a provider:
204
+ - **Copilot (default):** GitHub Copilot access — sign in once with the `copilot` CLI, or set `GH_TOKEN`.
205
+ - **Claude (`AGENTRIG_PROVIDER=claude`):** install the optional `@anthropic-ai/claude-agent-sdk`
206
+ and set `ANTHROPIC_API_KEY`.
207
+ - Deterministic commands (`eval --static`, `doctor`, `dashboard`, `init --skip-agent`) need no model.
208
+
209
+ ## Provider neutrality
210
+
211
+ Model access is behind the `AgentProvider` interface (`src/agent/provider.ts`), and the SDK is only
212
+ imported under `src/agent/`. Two backends ship today, selected by `AGENTRIG_PROVIDER`:
213
+ - `copilot` (default) — `CopilotProvider` on `@github/copilot-sdk`.
214
+ - `claude` — `ClaudeProvider` on the optional `@anthropic-ai/claude-agent-sdk` (`query()` + session
215
+ resume for multi-turn context). Install the SDK and set `ANTHROPIC_API_KEY` to use it.
216
+
217
+ ## Releasing
218
+
219
+ Publishing to npm is automated via GitHub Actions on each published GitHub Release — see
220
+ [`RELEASING.md`](RELEASING.md) (requires an `NPM_TOKEN` repo secret).
221
+
222
+ ## License
223
+
224
+ MIT
@@ -0,0 +1,125 @@
1
+ import { AgentTimeoutError, } from "./provider.js";
2
+ // The Claude Agent SDK is an OPTIONAL peer dependency. A non-literal specifier keeps TypeScript
3
+ // from resolving it at build time, so AgentRig builds and runs without it installed.
4
+ const CLAUDE_SDK = "@anthropic-ai/claude-agent-sdk";
5
+ /* eslint-disable @typescript-eslint/no-explicit-any */
6
+ async function loadSdk() {
7
+ try {
8
+ return await import(CLAUDE_SDK);
9
+ }
10
+ catch {
11
+ throw new Error(`Claude provider requires the optional package ${CLAUDE_SDK}. Install it: npm i ${CLAUDE_SDK}`);
12
+ }
13
+ }
14
+ function summarizeInput(input) {
15
+ if (!input)
16
+ return undefined;
17
+ for (const key of ["command", "file_path", "path", "pattern", "query", "url", "prompt"]) {
18
+ const v = input[key];
19
+ if (typeof v === "string" && v.length > 0)
20
+ return `${key}=${v.length > 60 ? v.slice(0, 57) + "…" : v}`;
21
+ }
22
+ return undefined;
23
+ }
24
+ /**
25
+ * AgentProvider backed by the Claude Agent SDK (`query()`), kept behind the same interface as the
26
+ * Copilot provider. Selected via `AGENTRIG_PROVIDER=claude`. Auth via `ANTHROPIC_API_KEY`.
27
+ */
28
+ export class ClaudeProvider {
29
+ name = "claude";
30
+ async preflight() {
31
+ try {
32
+ await loadSdk();
33
+ }
34
+ catch (err) {
35
+ return { ok: false, detail: err.message };
36
+ }
37
+ if (!process.env.ANTHROPIC_API_KEY) {
38
+ return { ok: false, detail: "ANTHROPIC_API_KEY is not set" };
39
+ }
40
+ return { ok: true, detail: "Claude Agent SDK ready (ANTHROPIC_API_KEY set)" };
41
+ }
42
+ async startConversation(options) {
43
+ const sdk = await loadSdk();
44
+ const emit = options.onEvent;
45
+ const inactivityMs = options.inactivityMs ?? 5 * 60 * 1000;
46
+ const maxMs = options.maxMs ?? 45 * 60 * 1000;
47
+ let sessionId;
48
+ return {
49
+ async send(prompt) {
50
+ const abort = new AbortController();
51
+ let lastActivity = Date.now();
52
+ const startedAt = Date.now();
53
+ let timeoutKind = null;
54
+ const watch = setInterval(() => {
55
+ if (Date.now() - lastActivity >= inactivityMs) {
56
+ timeoutKind = "inactivity";
57
+ abort.abort();
58
+ }
59
+ else if (Date.now() - startedAt >= maxMs) {
60
+ timeoutKind = "absolute";
61
+ abort.abort();
62
+ }
63
+ }, 5000);
64
+ if (watch.unref)
65
+ watch.unref();
66
+ let finalText = "";
67
+ try {
68
+ const q = sdk.query({
69
+ prompt,
70
+ options: {
71
+ cwd: options.cwd,
72
+ permissionMode: "bypassPermissions",
73
+ abortController: abort,
74
+ ...(options.model ? { model: options.model } : {}),
75
+ ...(options.systemMessage ? { systemPrompt: options.systemMessage } : {}),
76
+ ...(sessionId ? { resume: sessionId } : {}),
77
+ },
78
+ });
79
+ for await (const msg of q) {
80
+ lastActivity = Date.now();
81
+ if (msg.session_id)
82
+ sessionId = msg.session_id;
83
+ if (msg.type === "assistant" && msg.message?.content) {
84
+ for (const block of msg.message.content) {
85
+ if (block.type === "tool_use" && emit) {
86
+ const detail = summarizeInput(block.input);
87
+ emit({ type: "tool_start", text: block.name, ...(detail ? { detail } : {}) });
88
+ }
89
+ else if (block.type === "text" && block.text && emit) {
90
+ emit({ type: "assistant", text: block.text });
91
+ }
92
+ }
93
+ }
94
+ else if (msg.type === "result") {
95
+ if (typeof msg.result === "string")
96
+ finalText = msg.result;
97
+ }
98
+ }
99
+ }
100
+ catch (err) {
101
+ if (timeoutKind) {
102
+ throw new AgentTimeoutError(timeoutKind === "inactivity"
103
+ ? `no agent activity for ${Math.round(inactivityMs / 1000)}s`
104
+ : `exceeded max turn time of ${Math.round(maxMs / 60000)}m`, timeoutKind);
105
+ }
106
+ throw err;
107
+ }
108
+ finally {
109
+ clearInterval(watch);
110
+ }
111
+ if (timeoutKind) {
112
+ throw new AgentTimeoutError(timeoutKind === "inactivity"
113
+ ? `no agent activity for ${Math.round(inactivityMs / 1000)}s`
114
+ : `exceeded max turn time of ${Math.round(maxMs / 60000)}m`, timeoutKind);
115
+ }
116
+ return finalText;
117
+ },
118
+ async end() {
119
+ // query() is stateless per call; nothing to tear down.
120
+ },
121
+ };
122
+ }
123
+ }
124
+ /* eslint-enable @typescript-eslint/no-explicit-any */
125
+ //# sourceMappingURL=claude.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claude.js","sourceRoot":"","sources":["../../src/agent/claude.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,GAKlB,MAAM,eAAe,CAAC;AAEvB,gGAAgG;AAChG,qFAAqF;AACrF,MAAM,UAAU,GAAG,gCAAgC,CAAC;AAEpD,uDAAuD;AACvD,KAAK,UAAU,OAAO;IACpB,IAAI,CAAC;QACH,OAAO,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CACb,iDAAiD,UAAU,uBAAuB,UAAU,EAAE,CAC/F,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,KAA0C;IAChE,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,KAAK,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC;QACxF,MAAM,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QACrB,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,GAAG,GAAG,IAAI,CAAC,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACzG,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,cAAc;IAChB,IAAI,GAAG,QAAQ,CAAC;IAEzB,KAAK,CAAC,SAAS;QACb,IAAI,CAAC;YACH,MAAM,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,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG;wBAC7D,CAAC,CAAC,6BAA6B,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,EAC7D,WAAW,CACZ,CAAC;gBACJ,CAAC;gBACD,OAAO,SAAS,CAAC;YACnB,CAAC;YACD,KAAK,CAAC,GAAG;gBACP,uDAAuD;YACzD,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AACD,sDAAsD"}
@@ -0,0 +1,147 @@
1
+ import { CopilotClient, approveAll } from "@github/copilot-sdk";
2
+ import { AgentTimeoutError, } from "./provider.js";
3
+ function summarizeArgs(args) {
4
+ if (!args)
5
+ return undefined;
6
+ for (const key of ["command", "path", "filePath", "pattern", "query", "url", "prompt"]) {
7
+ const v = args[key];
8
+ if (typeof v === "string" && v.length > 0) {
9
+ return `${key}=${v.length > 60 ? v.slice(0, 57) + "…" : v}`;
10
+ }
11
+ }
12
+ return undefined;
13
+ }
14
+ /**
15
+ * AgentProvider backed by the GitHub Copilot SDK. Spawns the Copilot CLI runtime over stdio and
16
+ * uses the logged-in user's credentials by default.
17
+ */
18
+ export class CopilotProvider {
19
+ name = "copilot";
20
+ async preflight() {
21
+ const client = new CopilotClient({
22
+ logLevel: "none",
23
+ env: { ...process.env, NODE_NO_WARNINGS: "1" },
24
+ });
25
+ try {
26
+ await client.start();
27
+ const status = await client.getAuthStatus();
28
+ if (!status.isAuthenticated) {
29
+ return { ok: false, detail: "not authenticated — run `copilot` once to sign in, or set GH_TOKEN" };
30
+ }
31
+ return { ok: true, detail: `authenticated as ${status.login ?? "user"} (${status.authType ?? "user"})` };
32
+ }
33
+ catch (err) {
34
+ return { ok: false, detail: `could not start Copilot runtime: ${err.message}` };
35
+ }
36
+ finally {
37
+ await client.stop().catch(() => undefined);
38
+ }
39
+ }
40
+ async startConversation(options) {
41
+ const client = new CopilotClient({
42
+ workingDirectory: options.cwd,
43
+ logLevel: "none",
44
+ env: { ...process.env, NODE_NO_WARNINGS: "1" },
45
+ });
46
+ await client.start();
47
+ const session = await client.createSession({
48
+ ...(options.model ? { model: options.model } : {}),
49
+ onPermissionRequest: approveAll,
50
+ ...(options.systemMessage ? { systemMessage: { content: options.systemMessage } } : {}),
51
+ });
52
+ const emit = options.onEvent;
53
+ if (emit) {
54
+ session.on("assistant.intent", (event) => {
55
+ const intent = event.data?.intent;
56
+ if (intent)
57
+ emit({ type: "intent", text: intent });
58
+ });
59
+ session.on("assistant.reasoning", (event) => {
60
+ const content = event.data?.content;
61
+ if (content)
62
+ emit({ type: "reasoning", text: content });
63
+ });
64
+ session.on("tool.execution_start", (event) => {
65
+ const data = event.data;
66
+ if (data?.toolName) {
67
+ const detail = summarizeArgs(data.arguments);
68
+ emit({ type: "tool_start", text: data.toolName, ...(detail ? { detail } : {}) });
69
+ }
70
+ });
71
+ session.on("tool.execution_complete", (event) => {
72
+ const data = event.data;
73
+ emit({
74
+ type: "tool_done",
75
+ text: data?.success === false ? data.error?.message ?? "failed" : "ok",
76
+ ok: data?.success !== false,
77
+ });
78
+ });
79
+ session.on("assistant.message", (event) => {
80
+ const content = event.data?.content;
81
+ if (content)
82
+ emit({ type: "assistant", text: content });
83
+ });
84
+ session.on("session.compaction_start", () => {
85
+ emit({ type: "compaction", text: "compacting context…" });
86
+ });
87
+ }
88
+ const inactivityMs = options.inactivityMs ?? 5 * 60 * 1000;
89
+ const maxMs = options.maxMs ?? 45 * 60 * 1000;
90
+ return {
91
+ // Wait for the turn to go idle, but only abort on genuine inactivity (no events for
92
+ // inactivityMs) or an absolute cap. This keeps long, productive multi-agent runs alive
93
+ // instead of killing them at a fixed total timeout.
94
+ send(prompt) {
95
+ return new Promise((resolve, reject) => {
96
+ let finalContent = "";
97
+ let lastActivity = Date.now();
98
+ const startedAt = Date.now();
99
+ let settled = false;
100
+ const offActivity = session.on(() => {
101
+ lastActivity = Date.now();
102
+ });
103
+ const offMessage = session.on("assistant.message", (event) => {
104
+ const content = event.data?.content;
105
+ if (content)
106
+ finalContent = content;
107
+ });
108
+ const offIdle = session.on("session.idle", () => finish(() => resolve(finalContent)));
109
+ const watch = setInterval(() => {
110
+ const idleFor = Date.now() - lastActivity;
111
+ const totalFor = Date.now() - startedAt;
112
+ if (idleFor >= inactivityMs) {
113
+ finish(() => {
114
+ void session.abort().catch(() => undefined);
115
+ reject(new AgentTimeoutError("no agent activity for " + Math.round(inactivityMs / 1000) + "s", "inactivity"));
116
+ });
117
+ }
118
+ else if (totalFor >= maxMs) {
119
+ finish(() => {
120
+ void session.abort().catch(() => undefined);
121
+ reject(new AgentTimeoutError("exceeded max turn time of " + Math.round(maxMs / 60000) + "m", "absolute"));
122
+ });
123
+ }
124
+ }, 5000);
125
+ if (watch.unref)
126
+ watch.unref();
127
+ function finish(action) {
128
+ if (settled)
129
+ return;
130
+ settled = true;
131
+ clearInterval(watch);
132
+ offActivity();
133
+ offMessage();
134
+ offIdle();
135
+ action();
136
+ }
137
+ session.send({ prompt }).catch((err) => finish(() => reject(err)));
138
+ });
139
+ },
140
+ async end() {
141
+ await session.disconnect().catch(() => undefined);
142
+ await client.stop().catch(() => undefined);
143
+ },
144
+ };
145
+ }
146
+ }
147
+ //# sourceMappingURL=copilot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilot.js","sourceRoot":"","sources":["../../src/agent/copilot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEhE,OAAO,EACL,iBAAiB,GAKlB,MAAM,eAAe,CAAC;AAEvB,SAAS,aAAa,CAAC,IAAyC;IAC9D,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IAC5B,KAAK,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC;QACvF,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;QACpB,IAA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C,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;gBACrE,CAAC,CAAC,CAAC;YACL,CAAC;YACD,KAAK,CAAC,GAAG;gBACP,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;gBAClD,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;YAC7C,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ import { CopilotProvider } from "./copilot.js";
2
+ import { ClaudeProvider } from "./claude.js";
3
+ /**
4
+ * Resolve the agent provider. `AGENTRIG_PROVIDER` selects the backend (default `copilot`). The
5
+ * Claude provider needs the optional `@anthropic-ai/claude-agent-sdk` package + `ANTHROPIC_API_KEY`.
6
+ */
7
+ export function getProvider(name = process.env.AGENTRIG_PROVIDER ?? "copilot") {
8
+ switch (name) {
9
+ case "copilot":
10
+ return new CopilotProvider();
11
+ case "claude":
12
+ return new ClaudeProvider();
13
+ default:
14
+ throw new Error(`Unknown AgentRig provider "${name}". Supported: copilot, claude.`);
15
+ }
16
+ }
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAI7C;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,SAAS;IAC3E,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,SAAS;YACZ,OAAO,IAAI,eAAe,EAAE,CAAC;QAC/B,KAAK,QAAQ;YACX,OAAO,IAAI,cAAc,EAAE,CAAC;QAC9B;YACE,MAAM,IAAI,KAAK,CAAC,8BAA8B,IAAI,gCAAgC,CAAC,CAAC;IACxF,CAAC;AACH,CAAC"}
@@ -0,0 +1,10 @@
1
+ /** Thrown when a turn is aborted by the inactivity watchdog or the absolute cap. */
2
+ export class AgentTimeoutError extends Error {
3
+ kind;
4
+ constructor(message, kind) {
5
+ super(message);
6
+ this.kind = kind;
7
+ this.name = "AgentTimeoutError";
8
+ }
9
+ }
10
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/agent/provider.ts"],"names":[],"mappings":"AAkBA,oFAAoF;AACpF,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAG/B;IAFX,YACE,OAAe,EACN,IAA+B;QAExC,KAAK,CAAC,OAAO,CAAC,CAAC;QAFN,SAAI,GAAJ,IAAI,CAA2B;QAGxC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF"}