@open330/oac 2026.2.5

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 (56) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/LICENSE +21 -0
  3. package/README.md +597 -0
  4. package/dist/budget/index.d.ts +117 -0
  5. package/dist/budget/index.js +23 -0
  6. package/dist/budget/index.js.map +1 -0
  7. package/dist/chunk-4IUL7ECC.js +3152 -0
  8. package/dist/chunk-4IUL7ECC.js.map +1 -0
  9. package/dist/chunk-5GAUWC3L.js +469 -0
  10. package/dist/chunk-5GAUWC3L.js.map +1 -0
  11. package/dist/chunk-6A37SKAJ.js +58 -0
  12. package/dist/chunk-6A37SKAJ.js.map +1 -0
  13. package/dist/chunk-7C7SC4TZ.js +358 -0
  14. package/dist/chunk-7C7SC4TZ.js.map +1 -0
  15. package/dist/chunk-CJAJ4MBO.js +475 -0
  16. package/dist/chunk-CJAJ4MBO.js.map +1 -0
  17. package/dist/chunk-LQC5DLT7.js +317 -0
  18. package/dist/chunk-LQC5DLT7.js.map +1 -0
  19. package/dist/chunk-OTPXGXO7.js +2368 -0
  20. package/dist/chunk-OTPXGXO7.js.map +1 -0
  21. package/dist/chunk-QPVNC7S4.js +1833 -0
  22. package/dist/chunk-QPVNC7S4.js.map +1 -0
  23. package/dist/cli/cli.d.ts +13 -0
  24. package/dist/cli/cli.js +16 -0
  25. package/dist/cli/cli.js.map +1 -0
  26. package/dist/cli/index.d.ts +1 -0
  27. package/dist/cli/index.js +22 -0
  28. package/dist/cli/index.js.map +1 -0
  29. package/dist/completion/index.d.ts +91 -0
  30. package/dist/completion/index.js +587 -0
  31. package/dist/completion/index.js.map +1 -0
  32. package/dist/config-DequKoFA.d.ts +1468 -0
  33. package/dist/core/index.d.ts +64 -0
  34. package/dist/core/index.js +87 -0
  35. package/dist/core/index.js.map +1 -0
  36. package/dist/dashboard/index.d.ts +14 -0
  37. package/dist/dashboard/index.js +1253 -0
  38. package/dist/dashboard/index.js.map +1 -0
  39. package/dist/discovery/index.d.ts +285 -0
  40. package/dist/discovery/index.js +50 -0
  41. package/dist/discovery/index.js.map +1 -0
  42. package/dist/event-bus-KiuR6e3P.d.ts +91 -0
  43. package/dist/execution/index.d.ts +215 -0
  44. package/dist/execution/index.js +27 -0
  45. package/dist/execution/index.js.map +1 -0
  46. package/dist/repo/index.d.ts +33 -0
  47. package/dist/repo/index.js +19 -0
  48. package/dist/repo/index.js.map +1 -0
  49. package/dist/tracking/index.d.ts +357 -0
  50. package/dist/tracking/index.js +15 -0
  51. package/dist/tracking/index.js.map +1 -0
  52. package/dist/types-CYCwgojB.d.ts +34 -0
  53. package/dist/types-Ck7IucqK.d.ts +195 -0
  54. package/docs/config-reference.md +271 -0
  55. package/docs/multi-agent-support-technical-spec.md +312 -0
  56. package/package.json +82 -0
@@ -0,0 +1,312 @@
1
+ # OAC Multi-Agent Support Technical Specification
2
+
3
+ ## 1. Objective
4
+ Add production-grade multi-agent execution to OAC with these outcomes:
5
+ 1. Claude Code adapter runs real `claude` CLI subprocesses (non-interactive, stream parsing, abort support).
6
+ 2. OpenCode adapter is added and runs real `opencode` CLI subprocesses.
7
+ 3. Tasks are routed by complexity:
8
+ - `trivial`, `simple` -> `codex`
9
+ - `moderate`, `complex` -> `claude-code`
10
+ 4. `oac run --provider` accepts comma-separated providers (example: `codex,claude-code`).
11
+ 5. Agent health checks and automatic fallback retries are applied when an agent fails.
12
+
13
+ ## 2. Current State Summary
14
+ 1. `CodexAdapter` is implemented and functional in `packages/execution/src/agents/codex.adapter.ts`.
15
+ 2. `ClaudeCodeAdapter` exists but is not integrated into `oac run` execution path.
16
+ 3. `ExecutionEngine` currently round-robins agents and has no routing-by-complexity or provider health state.
17
+ 4. `oac run` currently executes only Codex (or simulated execution) and accepts a single `--provider` string.
18
+ 5. Provider IDs are inconsistent (`codex` vs `codex-cli`) across packages.
19
+
20
+ ## 3. Design Decisions
21
+ 1. Canonical runtime provider IDs for execution will be:
22
+ - `codex`
23
+ - `claude-code`
24
+ - `opencode`
25
+ 2. Legacy alias `codex-cli` will remain accepted at CLI/config boundaries and normalized to `codex`.
26
+ 3. Routing happens per task, using complexity-first preference and user-selected provider availability.
27
+ 4. Fallback is provider-level: if provider A fails, retry task on provider B before final failure.
28
+ 5. Health checking is run-level with lightweight in-memory state, not persisted.
29
+
30
+ ## 4. External CLI Contracts
31
+
32
+ ### 4.1 Claude Code subprocess contract
33
+ Use:
34
+ ```bash
35
+ claude -p "<prompt>" --output-format stream-json --verbose
36
+ ```
37
+ Process options:
38
+ - `cwd = params.workingDirectory`
39
+ - `env` includes inherited env + `params.env` + `OAC_TOKEN_BUDGET` + `OAC_ALLOW_COMMITS`
40
+ - `timeout = params.timeoutMs`
41
+
42
+ Parsing:
43
+ - Parse stream JSON lines when available.
44
+ - Emit `output`, `tokens`, `file_edit`, `tool_use`, and `error` events.
45
+ - Fall back to regex parsing for plain-text lines.
46
+
47
+ ### 4.2 OpenCode subprocess contract
48
+ Use:
49
+ ```bash
50
+ opencode run --format json "<prompt>"
51
+ ```
52
+ Process options:
53
+ - `cwd = params.workingDirectory`
54
+ - `env` includes inherited env + `params.env` + `OAC_TOKEN_BUDGET` + `OAC_ALLOW_COMMITS`
55
+ - `timeout = params.timeoutMs`
56
+
57
+ Parsing:
58
+ - Primary: JSON event lines from `--format json`.
59
+ - Fallback: plain text line heuristics for token/file/error events.
60
+
61
+ ## 5. File-by-File Changes
62
+
63
+ ### 5.1 `packages/core/src/types.ts`
64
+ 1. Update provider type for canonical + compatibility:
65
+ ```ts
66
+ export type AgentProviderId =
67
+ | "claude-code"
68
+ | "codex"
69
+ | "codex-cli"
70
+ | "opencode"
71
+ | (string & {});
72
+ ```
73
+ 2. No runtime behavior change in core.
74
+
75
+ ### 5.2 `packages/execution/src/agents/claude-code.adapter.ts`
76
+ 1. Keep `id = "claude-code"`.
77
+ 2. Ensure `execute()` uses `claude` CLI subprocess and structured output flags.
78
+ 3. Keep error normalization pattern aligned with Codex adapter:
79
+ - timeout -> `AGENT_TIMEOUT`
80
+ - OOM -> `AGENT_OOM`
81
+ - network -> `NETWORK_ERROR`
82
+ - default -> `AGENT_EXECUTION_FAILED`
83
+ 4. Keep `checkAvailability()` as `claude --version` with non-throwing availability object.
84
+ 5. Keep `abort()` SIGTERM then SIGKILL escalation with timer.
85
+
86
+ ### 5.3 `packages/execution/src/agents/opencode.adapter.ts` (new)
87
+ 1. Add new class implementing `AgentProvider`:
88
+ ```ts
89
+ export class OpenCodeAdapter implements AgentProvider {
90
+ public readonly id: AgentProviderId = "opencode";
91
+ public readonly name = "OpenCode CLI";
92
+
93
+ public async checkAvailability(): Promise<AgentAvailability>;
94
+ public execute(params: AgentExecuteParams): AgentExecution;
95
+ public async estimateTokens(params: TokenEstimateParams): Promise<TokenEstimate>;
96
+ public async abort(executionId: string): Promise<void>;
97
+ }
98
+ ```
99
+ 2. Implementation mirrors Codex/Claude adapter behavior:
100
+ - subprocess lifecycle map (`runningExecutions`)
101
+ - async event queue streaming
102
+ - structured + heuristic parsing
103
+ - normalized `AgentResult`
104
+ 3. `checkAvailability()` command: `opencode --version`.
105
+ 4. `execute()` command: `opencode run --format json <prompt>`.
106
+
107
+ ### 5.4 `packages/execution/src/index.ts`
108
+ 1. Export new adapter:
109
+ ```ts
110
+ export * from "./agents/opencode.adapter.js";
111
+ ```
112
+
113
+ ### 5.5 `packages/execution/src/engine.ts`
114
+ Add routing + health + fallback behavior.
115
+
116
+ #### 5.5.1 Type updates
117
+ 1. Extend `Job`:
118
+ ```ts
119
+ attemptedProviders: AgentProviderId[];
120
+ preferredProviders: AgentProviderId[];
121
+ ```
122
+ 2. Add internal health state:
123
+ ```ts
124
+ interface ProviderHealthState {
125
+ providerId: AgentProviderId;
126
+ available: boolean;
127
+ version?: string;
128
+ lastError?: string;
129
+ consecutiveFailures: number;
130
+ checkedAt: number;
131
+ }
132
+ ```
133
+
134
+ #### 5.5.2 New private members
135
+ ```ts
136
+ private readonly providerById: Map<AgentProviderId, AgentProvider>;
137
+ private readonly providerHealth: Map<AgentProviderId, ProviderHealthState>;
138
+ ```
139
+
140
+ #### 5.5.3 New private methods
141
+ ```ts
142
+ private async initializeProviderHealth(): Promise<void>;
143
+ private computePreferredProviders(task: Task): AgentProviderId[];
144
+ private selectAgentForJob(job: Job): AgentProvider;
145
+ private recordProviderSuccess(providerId: AgentProviderId): void;
146
+ private recordProviderFailure(providerId: AgentProviderId, error: OacError): void;
147
+ private canFallback(job: Job): boolean;
148
+ private scheduleFallback(job: Job): boolean;
149
+ ```
150
+
151
+ #### 5.5.4 Routing logic
152
+ 1. `computePreferredProviders(task)` returns ordered list:
153
+ - `trivial/simple`: `["codex", "claude-code", "opencode"]`
154
+ - `moderate/complex`: `["claude-code", "codex", "opencode"]`
155
+ 2. Order is filtered by providers passed into engine constructor and current health.
156
+ 3. On each job attempt, `selectAgentForJob(job)` picks first provider not already in `job.attemptedProviders`.
157
+
158
+ #### 5.5.5 Fallback logic
159
+ 1. If execution fails and any untried healthy provider remains, schedule immediate retry on fallback provider.
160
+ 2. If no untried provider remains, apply existing transient retry rules.
161
+ 3. Mark provider health failures on:
162
+ - `AGENT_TIMEOUT`
163
+ - `AGENT_OOM`
164
+ - `AGENT_RATE_LIMITED`
165
+ - `NETWORK_ERROR`
166
+ - `AGENT_EXECUTION_FAILED`
167
+ 4. Reset consecutive failures after a successful task on that provider.
168
+
169
+ ### 5.6 `packages/cli/src/commands/run.ts`
170
+
171
+ #### 5.6.1 Option parsing
172
+ 1. Keep flag name, change semantics:
173
+ ```ts
174
+ .option("--provider <ids>", "Comma-separated provider ids (e.g. codex,claude-code)")
175
+ ```
176
+ 2. Replace single-provider resolver:
177
+ ```ts
178
+ function resolveProviderIds(providerOption: string | undefined, config: OacConfig | null): AgentProviderId[];
179
+ function parseProviderIds(input: string): AgentProviderId[];
180
+ function normalizeProviderId(input: string): AgentProviderId;
181
+ ```
182
+ 3. Supported user inputs:
183
+ - `codex`, `codex-cli` -> `codex`
184
+ - `claude-code`
185
+ - `opencode`
186
+ 4. Deduplicate providers while preserving order.
187
+ 5. Validation errors are user-facing, fail fast.
188
+
189
+ #### 5.6.2 Adapter bootstrap
190
+ 1. Add provider factory:
191
+ ```ts
192
+ function createRequestedAdapters(providerIds: AgentProviderId[]): AgentProvider[];
193
+ ```
194
+ 2. Instantiate only requested adapters.
195
+ 3. Run `checkAvailability()` for all requested providers at start.
196
+
197
+ #### 5.6.3 Health-aware execution setup
198
+ 1. Build `healthyProviders` list from availability checks.
199
+ 2. Fail run if none are healthy.
200
+ 3. If subset healthy, continue and print warning listing disabled providers.
201
+
202
+ #### 5.6.4 Routing during execution stage
203
+ 1. Replace Codex-only path with provider-routed path:
204
+ ```ts
205
+ async function executeWithRouting(input: {
206
+ task: Task;
207
+ estimate: TokenEstimate;
208
+ providerIds: AgentProviderId[];
209
+ adapters: Map<AgentProviderId, AgentProvider>;
210
+ repoPath: string;
211
+ baseBranch: string;
212
+ timeoutSeconds: number;
213
+ }): Promise<{ execution: ExecutionOutcome; sandbox: SandboxInfo }>;
214
+ ```
215
+ 2. `executeWithRouting()` chooses preferred provider by task complexity and fallbacks if needed.
216
+ 3. Preserve existing sandbox + commit + PR flow.
217
+
218
+ #### 5.6.5 Token estimation changes
219
+ 1. Replace `estimateTaskMap(tasks, providerId)` with provider-aware selection:
220
+ ```ts
221
+ async function estimateTaskMap(
222
+ tasks: Task[],
223
+ providerSelector: (task: Task) => AgentProviderId,
224
+ ): Promise<Map<string, TokenEstimate>>;
225
+ ```
226
+ 2. For each task, estimate using preferred provider selected by complexity and provider availability.
227
+
228
+ #### 5.6.6 CLI UX changes
229
+ 1. Startup output includes:
230
+ - requested providers
231
+ - availability status per provider
232
+ - routing policy summary
233
+ 2. Per-task verbose output includes selected provider.
234
+ 3. On fallback, log one-line message:
235
+ - `Task <id>: <failed-provider> failed (<code>), retrying with <fallback-provider>`
236
+ 4. Summary output changes:
237
+ - `provider` -> comma-joined provider list for text mode
238
+ - JSON summary adds `providers: string[]`
239
+
240
+ ### 5.7 `packages/budget/src/estimator.ts`
241
+ 1. Update local provider type alias to include `codex` and legacy alias.
242
+ 2. Keep counter selection:
243
+ - `claude-code` -> Claude counter
244
+ - `codex`, `codex-cli`, `opencode` -> Codex counter (initially)
245
+
246
+ ## 6. Error Handling Patterns
247
+
248
+ ### 6.1 Adapter-level patterns
249
+ 1. `checkAvailability()` never throws; returns `{ available: false, error }`.
250
+ 2. `execute()` may reject with normalized `OacError` only.
251
+ 3. Non-zero exit code without throw returns `success: false` result with extracted error text.
252
+ 4. Timeouts map to `AGENT_TIMEOUT`.
253
+
254
+ ### 6.2 Engine/CLI fallback patterns
255
+ 1. Retry with alternate provider first when available.
256
+ 2. Use backoff only when cycling retry attempts after fallback options are exhausted.
257
+ 3. Fail final job with last normalized `OacError` and include context:
258
+ - `attempt`
259
+ - `providersTried`
260
+ - `taskId`
261
+ - `jobId`
262
+
263
+ ### 6.3 Input validation errors (`oac run`)
264
+ 1. Unknown provider ID -> throw with allowed values list.
265
+ 2. Empty provider list after parsing -> throw.
266
+ 3. Duplicate IDs are silently deduplicated.
267
+
268
+ ## 7. Test Plan
269
+
270
+ ### 7.1 New tests
271
+ 1. `packages/execution/tests/claude-code-adapter.test.ts`
272
+ - availability success/failure
273
+ - subprocess args
274
+ - stream parsing
275
+ - timeout normalization
276
+ - abort behavior
277
+ 2. `packages/execution/tests/opencode-adapter.test.ts`
278
+ - same coverage shape as Codex/Claude adapters
279
+
280
+ ### 7.2 Engine tests update
281
+ File: `packages/execution/tests/engine.test.ts`
282
+ 1. Routes trivial/simple tasks to Codex first.
283
+ 2. Routes moderate/complex tasks to Claude first.
284
+ 3. Falls back to alternate provider on provider failure.
285
+ 4. Marks unavailable providers out of routing after failed health checks.
286
+
287
+ ### 7.3 CLI tests
288
+ Add: `packages/cli/tests/run.test.ts`
289
+ 1. Parses `--provider codex,claude-code` correctly.
290
+ 2. Normalizes `codex-cli` to `codex`.
291
+ 3. Rejects unknown providers.
292
+ 4. Uses available provider when one is unhealthy.
293
+ 5. Emits fallback message when first provider fails.
294
+
295
+ ## 8. Migration and Compatibility
296
+ 1. Backward compatibility:
297
+ - `codex-cli` accepted and normalized to `codex`.
298
+ 2. No breaking change to existing single-provider usage:
299
+ - `--provider claude-code` still valid.
300
+ 3. If config has `provider.id = "codex-cli"`, runtime behaves as `codex`.
301
+
302
+ ## 9. Implementation Order
303
+ 1. Add provider normalization and ID compatibility (`core`, `budget`, `cli`).
304
+ 2. Implement `OpenCodeAdapter` and finalize Claude subprocess flags/parsing.
305
+ 3. Add routing/fallback internals to `ExecutionEngine`.
306
+ 4. Update `oac run` to multi-provider parse, health check, routing, and fallback.
307
+ 5. Add tests and adjust README command examples.
308
+
309
+ ## 10. Out of Scope
310
+ 1. Dashboard multi-agent wiring (`packages/dashboard`) in this change set.
311
+ 2. Persisted cross-run health state.
312
+ 3. Cost-based dynamic routing (future enhancement).
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@open330/oac",
3
+ "version": "2026.2.5",
4
+ "description": "Open Agent Contribution - automate open source contributions with AI agents",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/open330/open-agent-contribution.git"
9
+ },
10
+ "homepage": "https://github.com/open330/open-agent-contribution",
11
+ "bugs": {
12
+ "url": "https://github.com/open330/open-agent-contribution/issues"
13
+ },
14
+ "type": "module",
15
+ "main": "./dist/core/index.js",
16
+ "types": "./dist/core/index.d.ts",
17
+ "bin": {
18
+ "oac": "./dist/cli/index.js"
19
+ },
20
+ "exports": {
21
+ ".": {
22
+ "import": "./dist/core/index.js",
23
+ "types": "./dist/core/index.d.ts"
24
+ }
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "README.md",
29
+ "LICENSE",
30
+ "CHANGELOG.md",
31
+ "docs"
32
+ ],
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "engines": {
37
+ "node": ">=20.0.0"
38
+ },
39
+ "dependencies": {
40
+ "@fastify/cors": "^10.0.2",
41
+ "@fastify/static": "^8.1.0",
42
+ "@inquirer/prompts": "^6.0.0",
43
+ "@octokit/rest": "^21.1.1",
44
+ "@xterm/xterm": "^5.5.0",
45
+ "chalk": "^5.4.1",
46
+ "cli-table3": "^0.6.5",
47
+ "commander": "^13.1.0",
48
+ "eventemitter3": "^5.0.1",
49
+ "execa": "^9.5.2",
50
+ "fastify": "^5.2.1",
51
+ "ora": "^8.1.1",
52
+ "p-queue": "^8.1.0",
53
+ "react": "^19.0.0",
54
+ "react-dom": "^19.0.0",
55
+ "recharts": "^2.15.1",
56
+ "simple-git": "^3.27.0",
57
+ "tiktoken": "^1.0.18",
58
+ "zod": "^3.24.2"
59
+ },
60
+ "devDependencies": {
61
+ "@biomejs/biome": "^1.9.4",
62
+ "@changesets/cli": "^2.27.12",
63
+ "@types/node": "^22.0.0",
64
+ "@types/react": "^19.0.0",
65
+ "@types/react-dom": "^19.0.0",
66
+ "tsup": "^8.3.6",
67
+ "tsx": "^4.19.0",
68
+ "typescript": "^5.7.3",
69
+ "vitest": "^3.0.5"
70
+ },
71
+ "scripts": {
72
+ "build": "tsup",
73
+ "test": "vitest run",
74
+ "test:coverage": "vitest run --coverage",
75
+ "lint": "biome check .",
76
+ "lint:fix": "biome check --write .",
77
+ "format": "biome format --write .",
78
+ "typecheck": "tsc --noEmit",
79
+ "dev:dashboard": "tsx src/dashboard/dev.ts",
80
+ "clean": "rm -rf dist coverage"
81
+ }
82
+ }