@multiclawcli/core 0.3.1 → 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.
- package/dist/index.d.ts +720 -0
- package/dist/index.js +1909 -811
- package/package.json +18 -4
- package/src/agents/arch-design-reviewer.ts +0 -45
- package/src/agents/architect.ts +0 -72
- package/src/agents/backend-developer.ts +0 -54
- package/src/agents/code-reviewer.ts +0 -54
- package/src/agents/devops.ts +0 -59
- package/src/agents/frontend-developer.ts +0 -56
- package/src/agents/index.ts +0 -27
- package/src/agents/leader.ts +0 -37
- package/src/agents/product-manager.ts +0 -43
- package/src/agents/reviewer.ts +0 -47
- package/src/agents/tester.ts +0 -53
- package/src/agents/ui-design-reviewer.ts +0 -48
- package/src/agents/ui-designer.ts +0 -61
- package/src/config/defineConfig.ts +0 -4
- package/src/event/EventBus.ts +0 -19
- package/src/index.ts +0 -8
- package/src/orchestrator/AgentRunner.ts +0 -104
- package/src/orchestrator/ContextManager.ts +0 -11
- package/src/orchestrator/Orchestrator.ts +0 -180
- package/src/orchestrator/StageBuilder.ts +0 -30
- package/src/runtime/ClaudeRuntime.ts +0 -41
- package/src/runtime/RuntimeBase.ts +0 -7
- package/src/runtime/index.ts +0 -20
- package/src/types/agent.ts +0 -48
- package/src/types/config.ts +0 -26
- package/src/types/event.ts +0 -21
- package/src/types/index.ts +0 -4
- package/src/types/runtime.ts +0 -23
- package/src/utils/prompt.ts +0 -24
- package/src/utils/retry.ts +0 -24
- package/src/utils/timeout.ts +0 -16
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -5
- package/tsup.config.ts +0 -10
package/dist/index.js
CHANGED
|
@@ -1,658 +1,293 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
var
|
|
3
|
-
constructor() {
|
|
4
|
-
this.listeners = /* @__PURE__ */ new Set();
|
|
5
|
-
}
|
|
6
|
-
subscribe(listener) {
|
|
7
|
-
this.listeners.add(listener);
|
|
8
|
-
return () => this.listeners.delete(listener);
|
|
9
|
-
}
|
|
10
|
-
emit(event) {
|
|
11
|
-
for (const listener of this.listeners) {
|
|
12
|
-
try {
|
|
13
|
-
listener(event);
|
|
14
|
-
} catch (err) {
|
|
15
|
-
console.error("EventBus listener error:", err);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
clear() {
|
|
20
|
-
this.listeners.clear();
|
|
21
|
-
}
|
|
22
|
-
};
|
|
1
|
+
// src/agents/arch-design-reviewer.ts
|
|
2
|
+
var SYSTEM = `You are an architecture design reviewer. Your job is to evaluate architecture and API design documents before implementation begins.
|
|
23
3
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
4
|
+
Responsibilities:
|
|
5
|
+
- Review architecture design for completeness, consistency, and technical soundness
|
|
6
|
+
- Review API specifications for clarity, correctness, and REST/contract conventions
|
|
7
|
+
- Identify ambiguities, missing edge cases, or risky design decisions
|
|
8
|
+
- Do not write code, do not implement \u2014 provide only design-level feedback
|
|
27
9
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
constructor(initial) {
|
|
31
|
-
this.store = /* @__PURE__ */ new Map();
|
|
32
|
-
if (initial) for (const [k, v] of Object.entries(initial)) this.store.set(k, v);
|
|
33
|
-
}
|
|
34
|
-
set(key, value) {
|
|
35
|
-
this.store.set(key, value);
|
|
36
|
-
}
|
|
37
|
-
get(key) {
|
|
38
|
-
return this.store.get(key);
|
|
39
|
-
}
|
|
40
|
-
snapshot() {
|
|
41
|
-
return Object.fromEntries(this.store.entries());
|
|
42
|
-
}
|
|
43
|
-
};
|
|
10
|
+
Deliverables (save to the working directory):
|
|
11
|
+
- arch-review.md \u2014 verdict (Approved / Changes Required), issue list (blocking / advisory) with specific locations and suggested fixes, overall assessment
|
|
44
12
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
13
|
+
Principles: Be precise \u2014 point to specific sections. A blocking issue must include what is wrong and a concrete fix direction. If the design is sound, say so directly. Do not approve with vague praise.`;
|
|
14
|
+
var TASK = `## Architecture Design
|
|
15
|
+
{{file:architecture.md}}
|
|
48
16
|
|
|
49
|
-
|
|
50
|
-
|
|
17
|
+
## API Specification
|
|
18
|
+
{{file:api-spec.md}}
|
|
51
19
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
20
|
+
## Task
|
|
21
|
+
Review the architecture design and API specification above. Output arch-review.md:
|
|
22
|
+
1. Overall verdict: Approved / Changes Required
|
|
23
|
+
2. Blocking issues (must be fixed before implementation): each with location, problem, and fix direction
|
|
24
|
+
3. Advisory issues (should fix but not blocking): each with location and suggestion
|
|
25
|
+
4. Design strengths worth noting
|
|
26
|
+
5. Final summary (1\u20132 sentences)
|
|
55
27
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
"-p",
|
|
73
|
-
task.prompt,
|
|
74
|
-
"--allowedTools",
|
|
75
|
-
task.tools.join(",")
|
|
76
|
-
];
|
|
77
|
-
if (task.systemPrompt) args.push("--system-prompt", task.systemPrompt);
|
|
78
|
-
if (task.model) args.push("--model", task.model);
|
|
79
|
-
return new Promise((resolve4, reject) => {
|
|
80
|
-
const child = spawn("claude", args, { cwd: task.workDir, env: process.env });
|
|
81
|
-
task.signal?.addEventListener("abort", () => child.kill());
|
|
82
|
-
let output = "";
|
|
83
|
-
let errorOutput = "";
|
|
84
|
-
child.stdout.on("data", (d) => {
|
|
85
|
-
const chunk = d.toString();
|
|
86
|
-
output += chunk;
|
|
87
|
-
task.onOutput?.(chunk);
|
|
88
|
-
});
|
|
89
|
-
child.stderr.on("data", (d) => {
|
|
90
|
-
errorOutput += d.toString();
|
|
91
|
-
});
|
|
92
|
-
child.on("close", (code) => {
|
|
93
|
-
if (task.signal?.aborted) return;
|
|
94
|
-
code === 0 ? resolve4({ output, exitCode: code }) : reject(new Error(`claude exited with code ${code}: ${errorOutput}`));
|
|
95
|
-
});
|
|
96
|
-
child.on("error", (err) => reject(new Error(`Failed to start claude: ${err.message}`)));
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
};
|
|
28
|
+
Be specific. Reference section names or endpoint paths when citing issues.`;
|
|
29
|
+
function archDesignReviewer(overrides) {
|
|
30
|
+
return {
|
|
31
|
+
id: "arch-design-reviewer",
|
|
32
|
+
name: "Arch Design Reviewer",
|
|
33
|
+
icon: "\u25B3",
|
|
34
|
+
description: "reviews the design",
|
|
35
|
+
runtime: "acp",
|
|
36
|
+
models: { acp: "haiku" },
|
|
37
|
+
modelTier: "fast",
|
|
38
|
+
systemPrompt: SYSTEM,
|
|
39
|
+
taskPrompt: TASK,
|
|
40
|
+
tools: ["Read", "Write"],
|
|
41
|
+
...overrides
|
|
42
|
+
};
|
|
43
|
+
}
|
|
100
44
|
|
|
101
|
-
// src/
|
|
102
|
-
var
|
|
103
|
-
constructor() {
|
|
104
|
-
this.runtimes = /* @__PURE__ */ new Map();
|
|
105
|
-
this.register(new ClaudeRuntime());
|
|
106
|
-
}
|
|
107
|
-
register(r) {
|
|
108
|
-
this.runtimes.set(r.name, r);
|
|
109
|
-
}
|
|
110
|
-
get(name) {
|
|
111
|
-
const r = this.runtimes.get(name);
|
|
112
|
-
if (!r) throw new Error(`Runtime not found: "${name}". Available: ${[...this.runtimes.keys()].join(", ")}`);
|
|
113
|
-
return r;
|
|
114
|
-
}
|
|
115
|
-
has(name) {
|
|
116
|
-
return this.runtimes.has(name);
|
|
117
|
-
}
|
|
118
|
-
list() {
|
|
119
|
-
return [...this.runtimes.keys()];
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
var runtimeRegistry = new RuntimeRegistry();
|
|
45
|
+
// src/agents/architect.ts
|
|
46
|
+
var SYSTEM2 = `You are the technical architect for this project. Your responsibility is technical analysis and design \u2014 you do not write feature code.
|
|
123
47
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
48
|
+
Responsibilities:
|
|
49
|
+
- Understand requirements, identify key technical risks and affected components
|
|
50
|
+
- Review existing code (if any) and propose minimal-change solutions
|
|
51
|
+
- Define module boundaries, interface contracts, and directory structure
|
|
52
|
+
- Provide a clear design foundation for developers and testers
|
|
53
|
+
- Decompose the work into per-agent subtasks based on who is actually in the pipeline
|
|
54
|
+
- For each subtask, write a step-by-step plan concrete enough that the agent can follow it without re-analyzing the full requirement
|
|
55
|
+
|
|
56
|
+
Deliverables (save to the working directory):
|
|
57
|
+
- architecture.md \u2014 architecture plan (module breakdown, directory structure, technology choices, key component descriptions)
|
|
58
|
+
- api-spec.md \u2014 complete API specification (paths, methods, request/response formats, status codes, error handling)
|
|
59
|
+
- task-plan.json \u2014 structured task breakdown for all implementation agents in the pipeline (see format below)
|
|
60
|
+
|
|
61
|
+
task-plan.json format:
|
|
62
|
+
{
|
|
63
|
+
"projectName": "<project name>",
|
|
64
|
+
"requirement": "<one-line summary>",
|
|
65
|
+
"tasks": [
|
|
66
|
+
{
|
|
67
|
+
"id": "<agent id exactly as listed in pipelineAgents>",
|
|
68
|
+
"title": "<short task title>",
|
|
69
|
+
"scope": "<concrete description of what this agent should build or produce>",
|
|
70
|
+
"plan": [
|
|
71
|
+
"Step 1: ...",
|
|
72
|
+
"Step 2: ...",
|
|
73
|
+
"Step 3: ..."
|
|
74
|
+
],
|
|
75
|
+
"dependsOn": ["<other agent id>"]
|
|
139
76
|
}
|
|
140
|
-
|
|
141
|
-
throw lastError;
|
|
77
|
+
]
|
|
142
78
|
}
|
|
143
79
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
80
|
+
Rules for task-plan.json:
|
|
81
|
+
- Only create tasks for implementation agents (those that produce code, designs, or infrastructure). Skip review agents (code-reviewer, arch-design-reviewer, ui-design-reviewer, reviewer) and planning agents (product-manager, architect, leader).
|
|
82
|
+
- Use the exact agent id from pipelineAgents as the task id.
|
|
83
|
+
- If an agent is not in pipelineAgents, do not create a task for it.
|
|
84
|
+
- dependsOn references other task ids, not agent names.
|
|
85
|
+
|
|
86
|
+
Principles: Execute tasks directly without asking for confirmation. If information is missing, mark the file with BLOCKED and describe what is needed. Do not change the requirement scope. Do not write business feature code. Do not refactor beyond the task scope.`;
|
|
87
|
+
var TASK2 = `## Project
|
|
88
|
+
{{projectName}}
|
|
89
|
+
|
|
90
|
+
## Requirement
|
|
91
|
+
{{requirement}}
|
|
92
|
+
|
|
93
|
+
## Pipeline Agents
|
|
94
|
+
The following agents will run in this pipeline (id: name):
|
|
95
|
+
{{pipelineAgents}}
|
|
96
|
+
|
|
97
|
+
## Task
|
|
98
|
+
Analyze the requirement and create three files in the current directory:
|
|
99
|
+
1. architecture.md \u2014 architecture plan (module breakdown, directory structure, technology choices, key component descriptions, affected scope)
|
|
100
|
+
2. api-spec.md \u2014 complete API specification (paths, methods, request parameters, response formats, status codes, error handling)
|
|
101
|
+
3. task-plan.json \u2014 task breakdown for each implementation agent listed in the pipeline above
|
|
102
|
+
|
|
103
|
+
For task-plan.json: create one task per implementation agent (skip reviewers and planners). Each task must have:
|
|
104
|
+
- scope: concrete description of what this agent should build
|
|
105
|
+
- plan: ordered list of concrete steps, specific enough that the agent can follow them without re-analyzing the full requirement (e.g. "Create src/models/user.ts with User and UserProfile interfaces", "Implement POST /users endpoint in src/routes/users.ts")
|
|
106
|
+
Set dependsOn to reflect actual execution order constraints (e.g. devops depends on backend and frontend).
|
|
107
|
+
|
|
108
|
+
Create the files directly. No extra output.`;
|
|
109
|
+
function architect(overrides) {
|
|
110
|
+
return {
|
|
111
|
+
id: "architect",
|
|
112
|
+
name: "Architect",
|
|
113
|
+
icon: "\u25C6",
|
|
114
|
+
description: "designs the architecture",
|
|
115
|
+
runtime: "acp",
|
|
116
|
+
models: { acp: "opus" },
|
|
117
|
+
modelTier: "strong",
|
|
118
|
+
systemPrompt: SYSTEM2,
|
|
119
|
+
taskPrompt: TASK2,
|
|
120
|
+
tools: ["Read", "Write"],
|
|
121
|
+
...overrides
|
|
122
|
+
};
|
|
155
123
|
}
|
|
156
124
|
|
|
157
|
-
// src/
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
125
|
+
// src/agents/backend-developer.ts
|
|
126
|
+
var SYSTEM3 = `You are the backend engineer. You own the API contract and all server-side logic.
|
|
127
|
+
|
|
128
|
+
Responsibilities:
|
|
129
|
+
- Read the architecture design and API specification, implement server-side logic and data models
|
|
130
|
+
- Write backend tests (unit tests / integration tests)
|
|
131
|
+
- Run validation commands (compile, lint, test) and record the results
|
|
132
|
+
|
|
133
|
+
Deliverables (write code to the working directory, and record in implementation-notes.md):
|
|
134
|
+
- List of files created or modified
|
|
135
|
+
- Commands actually executed and their output
|
|
136
|
+
- Known issues and risks
|
|
137
|
+
|
|
138
|
+
Principles: Write code directly without asking for confirmation. Follow the API spec strictly \u2014 do not change the contract unilaterally; escalate contract issues upstream. Do not refactor unrelated code. Run commands and report evidence.`;
|
|
139
|
+
var TASK3 = `## Task Scope
|
|
140
|
+
{{agentScope}}
|
|
141
|
+
|
|
142
|
+
## Plan
|
|
143
|
+
{{agentPlan}}
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Architecture Design
|
|
148
|
+
{{file:architecture.md}}
|
|
149
|
+
|
|
150
|
+
## API Specification
|
|
151
|
+
{{file:api-spec.md}}
|
|
152
|
+
|
|
153
|
+
## Task
|
|
154
|
+
Implement complete backend code following the architecture design and API specification:
|
|
155
|
+
1. Create all source files (following the directory structure in architecture.md)
|
|
156
|
+
2. Implement all API endpoints (strictly following api-spec.md)
|
|
157
|
+
3. Write basic tests
|
|
158
|
+
4. Run compile/test commands to verify (e.g. npx tsc --noEmit, npm test)
|
|
159
|
+
5. Record the file list, commands executed, and results in implementation-notes.md
|
|
160
|
+
|
|
161
|
+
Start immediately. Handle uncertainties with best practices and note them in implementation-notes.md.`;
|
|
162
|
+
function backendDeveloper(overrides) {
|
|
163
|
+
return {
|
|
164
|
+
id: "backend-developer",
|
|
165
|
+
name: "Backend Developer",
|
|
166
|
+
icon: "\u2295",
|
|
167
|
+
description: "builds the API",
|
|
168
|
+
runtime: "acp",
|
|
169
|
+
models: { acp: "sonnet" },
|
|
170
|
+
modelTier: "balanced",
|
|
171
|
+
systemPrompt: SYSTEM3,
|
|
172
|
+
taskPrompt: TASK3,
|
|
173
|
+
tools: ["Read", "Write", "Bash"],
|
|
174
|
+
...overrides
|
|
175
|
+
};
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
// src/
|
|
179
|
-
var
|
|
180
|
-
constructor(eventBus, contextManager, globalWorkDir) {
|
|
181
|
-
this.eventBus = eventBus;
|
|
182
|
-
this.contextManager = contextManager;
|
|
183
|
-
this.globalWorkDir = globalWorkDir;
|
|
184
|
-
}
|
|
185
|
-
async run(agent) {
|
|
186
|
-
const startTime = /* @__PURE__ */ new Date();
|
|
187
|
-
const workDir = agent.workDir ? path2.resolve(this.globalWorkDir, agent.workDir) : this.globalWorkDir;
|
|
188
|
-
fs2.mkdirSync(workDir, { recursive: true });
|
|
189
|
-
const runtime = runtimeRegistry.get(agent.runtime ?? "claude");
|
|
190
|
-
const retries = agent.retries ?? 0;
|
|
191
|
-
const timeout = agent.timeout ?? 6e5;
|
|
192
|
-
const tools = agent.tools ?? ["Read", "Write", "Bash"];
|
|
193
|
-
const model = agent.model ?? agent.models?.[agent.runtime ?? "claude"];
|
|
194
|
-
this.eventBus.emit({
|
|
195
|
-
type: "agent:start",
|
|
196
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
197
|
-
payload: { agentId: agent.id, agentName: agent.name, icon: agent.icon, model, taskTitle: agent.taskTitle }
|
|
198
|
-
});
|
|
199
|
-
let attempts = 0;
|
|
200
|
-
let output = "";
|
|
201
|
-
try {
|
|
202
|
-
output = await withTimeout(
|
|
203
|
-
(signal) => withRetry(async (attempt) => {
|
|
204
|
-
attempts = attempt;
|
|
205
|
-
const prompt = await renderPrompt(
|
|
206
|
-
agent.taskPrompt,
|
|
207
|
-
this.contextManager.snapshot(),
|
|
208
|
-
this.globalWorkDir
|
|
209
|
-
);
|
|
210
|
-
return (await runtime.execute({
|
|
211
|
-
agentId: agent.id,
|
|
212
|
-
systemPrompt: agent.systemPrompt,
|
|
213
|
-
prompt,
|
|
214
|
-
tools,
|
|
215
|
-
workDir,
|
|
216
|
-
timeout,
|
|
217
|
-
signal,
|
|
218
|
-
model,
|
|
219
|
-
onOutput: (chunk) => {
|
|
220
|
-
this.eventBus.emit({
|
|
221
|
-
type: "agent:output",
|
|
222
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
223
|
-
payload: { agentId: agent.id, chunk }
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
})).output;
|
|
227
|
-
}, retries, (attempt, err) => {
|
|
228
|
-
this.eventBus.emit({
|
|
229
|
-
type: "agent:retrying",
|
|
230
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
231
|
-
payload: {
|
|
232
|
-
agentId: agent.id,
|
|
233
|
-
agentName: agent.name,
|
|
234
|
-
attempt,
|
|
235
|
-
maxAttempts: retries + 1,
|
|
236
|
-
error: err.message
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
}),
|
|
240
|
-
timeout,
|
|
241
|
-
agent.name
|
|
242
|
-
);
|
|
243
|
-
const endTime = /* @__PURE__ */ new Date();
|
|
244
|
-
const result = {
|
|
245
|
-
agentId: agent.id,
|
|
246
|
-
agentName: agent.name,
|
|
247
|
-
status: "success",
|
|
248
|
-
output,
|
|
249
|
-
duration: endTime.getTime() - startTime.getTime(),
|
|
250
|
-
attempts,
|
|
251
|
-
startTime: startTime.toISOString(),
|
|
252
|
-
endTime: endTime.toISOString()
|
|
253
|
-
};
|
|
254
|
-
this.eventBus.emit({
|
|
255
|
-
type: "agent:complete",
|
|
256
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
257
|
-
payload: result
|
|
258
|
-
});
|
|
259
|
-
return result;
|
|
260
|
-
} catch (err) {
|
|
261
|
-
const endTime = /* @__PURE__ */ new Date();
|
|
262
|
-
const result = {
|
|
263
|
-
agentId: agent.id,
|
|
264
|
-
agentName: agent.name,
|
|
265
|
-
status: "failed",
|
|
266
|
-
output,
|
|
267
|
-
duration: endTime.getTime() - startTime.getTime(),
|
|
268
|
-
attempts,
|
|
269
|
-
error: err.message,
|
|
270
|
-
startTime: startTime.toISOString(),
|
|
271
|
-
endTime: endTime.toISOString()
|
|
272
|
-
};
|
|
273
|
-
this.eventBus.emit({
|
|
274
|
-
type: "agent:failed",
|
|
275
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
276
|
-
payload: result
|
|
277
|
-
});
|
|
278
|
-
return result;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
// src/orchestrator/StageBuilder.ts
|
|
284
|
-
function buildStages(agents2) {
|
|
285
|
-
const stages = [];
|
|
286
|
-
const completed = /* @__PURE__ */ new Set();
|
|
287
|
-
let remaining = [...agents2];
|
|
288
|
-
const allIds = new Set(agents2.map((a) => a.id));
|
|
289
|
-
for (const a of agents2) {
|
|
290
|
-
for (const dep of a.dependsOn ?? []) {
|
|
291
|
-
if (!allIds.has(dep)) {
|
|
292
|
-
throw new Error(`Agent "${a.id}" depends on "${dep}" which does not exist`);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
while (remaining.length > 0) {
|
|
297
|
-
const stage = remaining.filter(
|
|
298
|
-
(a) => (a.dependsOn ?? []).every((dep) => completed.has(dep))
|
|
299
|
-
);
|
|
300
|
-
if (stage.length === 0) {
|
|
301
|
-
const ids = remaining.map((a) => a.id).join(", ");
|
|
302
|
-
throw new Error(`Circular or unsatisfiable dependency detected: ${ids}`);
|
|
303
|
-
}
|
|
304
|
-
stages.push(stage);
|
|
305
|
-
stage.forEach((a) => completed.add(a.id));
|
|
306
|
-
remaining = remaining.filter((a) => !stage.includes(a));
|
|
307
|
-
}
|
|
308
|
-
return stages;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// src/orchestrator/Orchestrator.ts
|
|
312
|
-
var Orchestrator = class {
|
|
313
|
-
constructor(config) {
|
|
314
|
-
this.config = config;
|
|
315
|
-
this.eventBus = new EventBus();
|
|
316
|
-
this.workDir = path3.resolve(config.workDir);
|
|
317
|
-
fs3.mkdirSync(this.workDir, { recursive: true });
|
|
318
|
-
this.contextManager = new ContextManager(config.context);
|
|
319
|
-
this.runner = new AgentRunner(this.eventBus, this.contextManager, this.workDir);
|
|
320
|
-
}
|
|
321
|
-
async run() {
|
|
322
|
-
const startTime = /* @__PURE__ */ new Date();
|
|
323
|
-
const agents2 = await this.resolveAgents();
|
|
324
|
-
this.contextManager.set(
|
|
325
|
-
"pipelineAgents",
|
|
326
|
-
agents2.map((a) => `${a.id}: ${a.name}`).join("\n")
|
|
327
|
-
);
|
|
328
|
-
let stages = buildStages(agents2);
|
|
329
|
-
const getModel = (agent) => {
|
|
330
|
-
return agent.model ?? agent.models?.[agent.runtime ?? "claude"];
|
|
331
|
-
};
|
|
332
|
-
const stageInfos = stages.map((stage, i) => ({
|
|
333
|
-
stageIndex: i,
|
|
334
|
-
agents: stage.map((a) => ({ id: a.id, name: a.name, icon: a.icon, model: getModel(a), taskTitle: a.taskTitle }))
|
|
335
|
-
}));
|
|
336
|
-
this.eventBus.emit({
|
|
337
|
-
type: "orchestration:start",
|
|
338
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
339
|
-
payload: { name: this.config.name, requirement: this.config.context?.requirement, totalAgents: agents2.length, stages: stageInfos }
|
|
340
|
-
});
|
|
341
|
-
const results = [];
|
|
342
|
-
let allSuccess = true;
|
|
343
|
-
for (let i = 0; i < stages.length; i++) {
|
|
344
|
-
const stage = stages[i];
|
|
345
|
-
this.eventBus.emit({
|
|
346
|
-
type: "stage:start",
|
|
347
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
348
|
-
payload: { stageIndex: i, agentIds: stage.map((a) => a.id) }
|
|
349
|
-
});
|
|
350
|
-
const stageResults = await this.runStage(stage);
|
|
351
|
-
results.push(...stageResults);
|
|
352
|
-
if (i === 0 && stage.some((a) => a.id === "architect") && stageResults.some((r) => r.status === "success")) {
|
|
353
|
-
await this.applyTaskPlan(agents2);
|
|
354
|
-
stages = buildStages(agents2);
|
|
355
|
-
}
|
|
356
|
-
for (const r of stageResults) {
|
|
357
|
-
if (r.status !== "success") {
|
|
358
|
-
allSuccess = false;
|
|
359
|
-
if (!this.config.continueOnError) break;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
this.eventBus.emit({
|
|
363
|
-
type: "stage:complete",
|
|
364
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
365
|
-
payload: { stageIndex: i }
|
|
366
|
-
});
|
|
367
|
-
if (!allSuccess && !this.config.continueOnError) {
|
|
368
|
-
for (const remainingStage of stages.slice(i + 1)) {
|
|
369
|
-
for (const agent of remainingStage) {
|
|
370
|
-
this.eventBus.emit({
|
|
371
|
-
type: "agent:skipped",
|
|
372
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
373
|
-
payload: { agentId: agent.id, agentName: agent.name, icon: agent.icon }
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
break;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
const endTime = /* @__PURE__ */ new Date();
|
|
381
|
-
const result = {
|
|
382
|
-
name: this.config.name,
|
|
383
|
-
success: allSuccess,
|
|
384
|
-
totalDuration: endTime.getTime() - startTime.getTime(),
|
|
385
|
-
agentResults: results,
|
|
386
|
-
startTime: startTime.toISOString(),
|
|
387
|
-
endTime: endTime.toISOString()
|
|
388
|
-
};
|
|
389
|
-
this.eventBus.emit({
|
|
390
|
-
type: "orchestration:complete",
|
|
391
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
392
|
-
payload: result
|
|
393
|
-
});
|
|
394
|
-
return result;
|
|
395
|
-
}
|
|
396
|
-
async resolveAgents() {
|
|
397
|
-
if (!this.config.leader || this.config.useLeader === false) return this.config.agents;
|
|
398
|
-
this.contextManager.set(
|
|
399
|
-
"availableAgents",
|
|
400
|
-
this.config.agents.map((a) => `${a.id}: ${a.name}`).join("\n")
|
|
401
|
-
);
|
|
402
|
-
const result = await this.runner.run(this.config.leader);
|
|
403
|
-
if (result.status !== "success") return this.config.agents;
|
|
404
|
-
const match = result.output.match(/\{[\s\S]*?"run"\s*:\s*\[[\s\S]*?\]\s*\}/);
|
|
405
|
-
if (!match) return this.config.agents;
|
|
406
|
-
let plan;
|
|
407
|
-
try {
|
|
408
|
-
plan = JSON.parse(match[0]);
|
|
409
|
-
} catch {
|
|
410
|
-
return this.config.agents;
|
|
411
|
-
}
|
|
412
|
-
const runSet = new Set(plan.run);
|
|
413
|
-
const skippedIds = new Set(
|
|
414
|
-
this.config.agents.filter((a) => !runSet.has(a.id)).map((a) => a.id)
|
|
415
|
-
);
|
|
416
|
-
for (const agent of this.config.agents.filter((a) => skippedIds.has(a.id))) {
|
|
417
|
-
this.eventBus.emit({
|
|
418
|
-
type: "agent:skipped",
|
|
419
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
420
|
-
payload: { agentId: agent.id, agentName: agent.name, icon: agent.icon }
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
return this.config.agents.filter((a) => runSet.has(a.id)).map((a) => ({
|
|
424
|
-
...a,
|
|
425
|
-
dependsOn: a.dependsOn?.filter((dep) => !skippedIds.has(dep))
|
|
426
|
-
}));
|
|
427
|
-
}
|
|
428
|
-
async runStage(agents2) {
|
|
429
|
-
const { maxConcurrency } = this.config;
|
|
430
|
-
if (!maxConcurrency || agents2.length <= maxConcurrency) {
|
|
431
|
-
return Promise.all(agents2.map((a) => this.runner.run(a)));
|
|
432
|
-
}
|
|
433
|
-
const results = [];
|
|
434
|
-
for (let i = 0; i < agents2.length; i += maxConcurrency) {
|
|
435
|
-
const batch = agents2.slice(i, i + maxConcurrency);
|
|
436
|
-
results.push(...await Promise.all(batch.map((a) => this.runner.run(a))));
|
|
437
|
-
}
|
|
438
|
-
return results;
|
|
439
|
-
}
|
|
440
|
-
async applyTaskPlan(agents2) {
|
|
441
|
-
try {
|
|
442
|
-
const taskPlanPath = path3.join(this.workDir, "task-plan.json");
|
|
443
|
-
if (!fs3.existsSync(taskPlanPath)) return;
|
|
444
|
-
const content = fs3.readFileSync(taskPlanPath, "utf-8");
|
|
445
|
-
const taskPlan = JSON.parse(content);
|
|
446
|
-
const taskMap = new Map(taskPlan.tasks.map((t) => [t.id, t]));
|
|
447
|
-
for (const agent of agents2) {
|
|
448
|
-
const task = taskMap.get(agent.id);
|
|
449
|
-
if (task) {
|
|
450
|
-
agent.taskTitle = task.title;
|
|
451
|
-
agent.dependsOn = task.dependsOn;
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
} catch {
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
};
|
|
458
|
-
|
|
459
|
-
// src/config/defineConfig.ts
|
|
460
|
-
function defineConfig(config) {
|
|
461
|
-
return config;
|
|
462
|
-
}
|
|
178
|
+
// src/agents/code-reviewer.ts
|
|
179
|
+
var SYSTEM4 = `You are a code review expert focused on implementation quality, correctness, and security.
|
|
463
180
|
|
|
464
|
-
|
|
465
|
-
|
|
181
|
+
Responsibilities:
|
|
182
|
+
- Read the requirement, architecture design, and all implementation code
|
|
183
|
+
- Verify the implementation matches the API specification and satisfies the requirement
|
|
184
|
+
- Identify bugs, security vulnerabilities, error handling gaps, and test coverage issues
|
|
185
|
+
- Assess code quality: readability, naming, separation of concerns, duplication
|
|
186
|
+
- Do not run code, do not modify code \u2014 provide written judgment only
|
|
466
187
|
|
|
467
|
-
|
|
188
|
+
Deliverables (save to the working directory):
|
|
189
|
+
- code-review.md \u2014 score (1\u201310), blocking issues, advisory issues, conclusion (Approved / Changes Required)
|
|
468
190
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
var TASK = `## Project
|
|
191
|
+
Principles: Judge the code, not the developer. A blocking issue must include the file path, the specific problem, and a fix direction. Advisory items should be actionable, not vague. If the code is solid, say so.`;
|
|
192
|
+
var TASK4 = `## Project
|
|
472
193
|
{{projectName}}
|
|
473
194
|
|
|
474
195
|
## Requirement
|
|
475
196
|
{{requirement}}
|
|
476
197
|
|
|
477
|
-
##
|
|
478
|
-
{{
|
|
198
|
+
## Architecture Design
|
|
199
|
+
{{file:architecture.md}}
|
|
200
|
+
|
|
201
|
+
## API Specification
|
|
202
|
+
{{file:api-spec.md}}
|
|
479
203
|
|
|
480
204
|
## Task
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
205
|
+
Perform a thorough code review of all implementation in the current directory and output code-review.md:
|
|
206
|
+
1. Overall score (1\u201310) and verdict: Approved / Changes Required
|
|
207
|
+
2. Blocking issues (bugs, security holes, missing requirement coverage, broken tests):
|
|
208
|
+
- file path + line range, problem description, fix direction
|
|
209
|
+
3. Advisory issues (code quality, naming, duplication, missing error handling):
|
|
210
|
+
- file path, observation, suggestion
|
|
211
|
+
4. Test coverage assessment
|
|
212
|
+
5. Final summary (2\u20133 sentences)
|
|
213
|
+
|
|
214
|
+
Start by reading implementation-notes.md (if present), then read source and test files.`;
|
|
215
|
+
function codeReviewer(overrides) {
|
|
485
216
|
return {
|
|
486
|
-
id: "
|
|
487
|
-
name: "
|
|
488
|
-
icon: "\
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
217
|
+
id: "code-reviewer",
|
|
218
|
+
name: "Code Reviewer",
|
|
219
|
+
icon: "\u2297",
|
|
220
|
+
description: "reviews the code",
|
|
221
|
+
runtime: "acp",
|
|
222
|
+
models: { acp: "haiku" },
|
|
223
|
+
modelTier: "fast",
|
|
224
|
+
systemPrompt: SYSTEM4,
|
|
225
|
+
taskPrompt: TASK4,
|
|
226
|
+
tools: ["Read", "Write"],
|
|
493
227
|
...overrides
|
|
494
228
|
};
|
|
495
229
|
}
|
|
496
230
|
|
|
497
|
-
// src/agents/
|
|
498
|
-
var
|
|
231
|
+
// src/agents/devops.ts
|
|
232
|
+
var SYSTEM5 = `You are the DevOps engineer. Your job is to containerize the application, set up CI/CD pipelines, and produce deployment-ready infrastructure configuration.
|
|
499
233
|
|
|
500
234
|
Responsibilities:
|
|
501
|
-
-
|
|
502
|
-
-
|
|
503
|
-
-
|
|
504
|
-
-
|
|
505
|
-
-
|
|
235
|
+
- Read the architecture design and implementation to understand the application structure
|
|
236
|
+
- Write a Dockerfile (and docker-compose.yml if multiple services are involved)
|
|
237
|
+
- Create a CI/CD pipeline configuration (GitHub Actions, GitLab CI, or similar based on the architecture)
|
|
238
|
+
- Write any environment configuration templates (.env.example)
|
|
239
|
+
- Document the deployment procedure and environment requirements
|
|
240
|
+
- Do not modify application source code
|
|
506
241
|
|
|
507
242
|
Deliverables (save to the working directory):
|
|
508
|
-
-
|
|
509
|
-
-
|
|
510
|
-
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
{
|
|
514
|
-
"projectName": "<project name>",
|
|
515
|
-
"requirement": "<one-line summary>",
|
|
516
|
-
"tasks": [
|
|
517
|
-
{
|
|
518
|
-
"id": "<agent id exactly as listed in pipelineAgents>",
|
|
519
|
-
"title": "<short task title>",
|
|
520
|
-
"scope": "<concrete description of what this agent should build or produce>",
|
|
521
|
-
"dependsOn": ["<other agent id>"]
|
|
522
|
-
}
|
|
523
|
-
]
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
Rules for task-plan.json:
|
|
527
|
-
- Only create tasks for implementation agents (those that produce code, designs, or infrastructure). Skip review agents (code-reviewer, arch-design-reviewer, ui-design-reviewer, reviewer) and planning agents (product-manager, architect, leader).
|
|
528
|
-
- Use the exact agent id from pipelineAgents as the task id.
|
|
529
|
-
- If an agent is not in pipelineAgents, do not create a task for it.
|
|
530
|
-
- dependsOn references other task ids, not agent names.
|
|
531
|
-
|
|
532
|
-
Principles: Execute tasks directly without asking for confirmation. If information is missing, mark the file with BLOCKED and describe what is needed. Do not change the requirement scope. Do not write business feature code. Do not refactor beyond the task scope.`;
|
|
533
|
-
var TASK2 = `## Project
|
|
534
|
-
{{projectName}}
|
|
535
|
-
|
|
536
|
-
## Requirement
|
|
537
|
-
{{requirement}}
|
|
538
|
-
|
|
539
|
-
## Pipeline Agents
|
|
540
|
-
The following agents will run in this pipeline (id: name):
|
|
541
|
-
{{pipelineAgents}}
|
|
542
|
-
|
|
543
|
-
## Task
|
|
544
|
-
Analyze the requirement and create three files in the current directory:
|
|
545
|
-
1. architecture.md \u2014 architecture plan (module breakdown, directory structure, technology choices, key component descriptions, affected scope)
|
|
546
|
-
2. api-spec.md \u2014 complete API specification (paths, methods, request parameters, response formats, status codes, error handling)
|
|
547
|
-
3. task-plan.json \u2014 task breakdown for each implementation agent listed in the pipeline above
|
|
548
|
-
|
|
549
|
-
For task-plan.json: create one task per implementation agent (skip reviewers and planners). Each task's scope should be concrete enough that the agent knows exactly what to build without ambiguity. Set dependsOn to reflect actual execution order constraints (e.g. devops depends on backend and frontend).
|
|
550
|
-
|
|
551
|
-
Create the files directly. No extra output.`;
|
|
552
|
-
function architect(overrides) {
|
|
553
|
-
return {
|
|
554
|
-
id: "architect",
|
|
555
|
-
name: "Architect",
|
|
556
|
-
icon: "\u25C6",
|
|
557
|
-
models: { claude: "opus" },
|
|
558
|
-
systemPrompt: SYSTEM2,
|
|
559
|
-
taskPrompt: TASK2,
|
|
560
|
-
tools: ["Read", "Write"],
|
|
561
|
-
...overrides
|
|
562
|
-
};
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
// src/agents/product-manager.ts
|
|
566
|
-
var SYSTEM3 = `You are the product manager. Your responsibility is to transform vague business ideas into clear, development-ready, testable product requirement documents.
|
|
567
|
-
|
|
568
|
-
Responsibilities:
|
|
569
|
-
- Analyze business goals and user scenarios
|
|
570
|
-
- Define feature scope, business rules, and acceptance criteria
|
|
571
|
-
- Structure "what is needed" into a PRD that the development team can execute directly
|
|
572
|
-
|
|
573
|
-
Deliverables (save to the working directory):
|
|
574
|
-
- requirements.md \u2014 product requirements document containing: one-line definition, goals and success metrics, user roles, functional requirements (FR-), business rules (BR-), acceptance criteria (AC-), open questions (OP-)
|
|
575
|
-
|
|
576
|
-
Principles: Output the document directly without preamble. Mark uncertain items as OP- (open questions) rather than guessing. Do not do technical architecture design. Do not write feature code.`;
|
|
577
|
-
var TASK3 = `## Business Context
|
|
578
|
-
{{requirement}}
|
|
579
|
-
|
|
580
|
-
## Task
|
|
581
|
-
Based on the context above, create requirements.md in the current directory containing:
|
|
582
|
-
- One-line definition (what this product/feature is)
|
|
583
|
-
- Goals and success metrics
|
|
584
|
-
- User roles and typical scenarios
|
|
585
|
-
- Functional requirements (FR-01, FR-02, ...)
|
|
586
|
-
- Business rules (BR-01, ...)
|
|
587
|
-
- Acceptance criteria (AC-01, ..., each must be executable and verifiable)
|
|
588
|
-
- Open questions (OP-01, ..., list uncertain items here)
|
|
589
|
-
|
|
590
|
-
Create the file directly. Mark uncertain items as OP- rather than guessing.`;
|
|
591
|
-
function productManager(overrides) {
|
|
592
|
-
return {
|
|
593
|
-
id: "product-manager",
|
|
594
|
-
name: "Product Manager",
|
|
595
|
-
icon: "\u2261",
|
|
596
|
-
models: { claude: "sonnet" },
|
|
597
|
-
systemPrompt: SYSTEM3,
|
|
598
|
-
taskPrompt: TASK3,
|
|
599
|
-
tools: ["Write"],
|
|
600
|
-
...overrides
|
|
601
|
-
};
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
// src/agents/backend-developer.ts
|
|
605
|
-
var SYSTEM4 = `You are the backend engineer. You own the API contract and all server-side logic.
|
|
606
|
-
|
|
607
|
-
Responsibilities:
|
|
608
|
-
- Read the architecture design and API specification, implement server-side logic and data models
|
|
609
|
-
- Write backend tests (unit tests / integration tests)
|
|
610
|
-
- Run validation commands (compile, lint, test) and record the results
|
|
611
|
-
|
|
612
|
-
Deliverables (write code to the working directory, and record in implementation-notes.md):
|
|
613
|
-
- List of files created or modified
|
|
614
|
-
- Commands actually executed and their output
|
|
615
|
-
- Known issues and risks
|
|
243
|
+
- Dockerfile \u2014 production-ready container image definition
|
|
244
|
+
- docker-compose.yml \u2014 local development / staging orchestration (if multiple services)
|
|
245
|
+
- .github/workflows/ci.yml (or equivalent) \u2014 CI pipeline: build, test, lint
|
|
246
|
+
- .env.example \u2014 required environment variables with descriptions
|
|
247
|
+
- devops-notes.md \u2014 deployment procedure, environment requirements, known limitations
|
|
616
248
|
|
|
617
|
-
Principles:
|
|
618
|
-
var
|
|
619
|
-
{{
|
|
249
|
+
Principles: Follow security best practices (non-root user, minimal base image, no secrets in image). Make CI fail fast. Document every non-obvious decision in devops-notes.md.`;
|
|
250
|
+
var TASK5 = `## Task Scope
|
|
251
|
+
{{agentScope}}
|
|
620
252
|
|
|
621
|
-
|
|
622
|
-
|
|
253
|
+
## Plan
|
|
254
|
+
{{agentPlan}}
|
|
623
255
|
|
|
624
256
|
---
|
|
625
257
|
|
|
258
|
+
## Project
|
|
259
|
+
{{projectName}}
|
|
260
|
+
|
|
626
261
|
## Architecture Design
|
|
627
262
|
{{file:architecture.md}}
|
|
628
263
|
|
|
629
|
-
## API Specification
|
|
630
|
-
{{file:api-spec.md}}
|
|
631
|
-
|
|
632
264
|
## Task
|
|
633
|
-
|
|
634
|
-
1.
|
|
635
|
-
2.
|
|
636
|
-
3. Write
|
|
637
|
-
4.
|
|
638
|
-
5.
|
|
265
|
+
Set up the deployment infrastructure for this project:
|
|
266
|
+
1. Write Dockerfile \u2014 multi-stage build if appropriate, non-root user, minimal image
|
|
267
|
+
2. Write docker-compose.yml \u2014 include all services from architecture.md (app, database, cache, etc.)
|
|
268
|
+
3. Write CI pipeline \u2014 build \u2192 lint \u2192 test \u2192 (optional) build image; fail fast
|
|
269
|
+
4. Write .env.example \u2014 all required environment variables with placeholder values and descriptions
|
|
270
|
+
5. Write devops-notes.md \u2014 how to build, run locally, deploy to production; environment requirements; known limitations
|
|
639
271
|
|
|
640
|
-
Start
|
|
641
|
-
function
|
|
272
|
+
Start by reading implementation-notes.md (if present) to understand what commands are used for build and test.`;
|
|
273
|
+
function devops(overrides) {
|
|
642
274
|
return {
|
|
643
|
-
id: "
|
|
644
|
-
name: "
|
|
645
|
-
icon: "\
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
275
|
+
id: "devops",
|
|
276
|
+
name: "DevOps",
|
|
277
|
+
icon: "\u25B6",
|
|
278
|
+
description: "sets up deployment",
|
|
279
|
+
runtime: "acp",
|
|
280
|
+
models: { acp: "sonnet" },
|
|
281
|
+
modelTier: "balanced",
|
|
282
|
+
systemPrompt: SYSTEM5,
|
|
283
|
+
taskPrompt: TASK5,
|
|
284
|
+
tools: ["Read", "Write"],
|
|
650
285
|
...overrides
|
|
651
286
|
};
|
|
652
287
|
}
|
|
653
288
|
|
|
654
289
|
// src/agents/frontend-developer.ts
|
|
655
|
-
var
|
|
290
|
+
var SYSTEM6 = `You are the frontend engineer. Your responsibility is to turn design specs and API contracts into a working user interface.
|
|
656
291
|
|
|
657
292
|
Responsibilities:
|
|
658
293
|
- Read the architecture design and API specification, implement pages, components, and interactions
|
|
@@ -662,11 +297,11 @@ Responsibilities:
|
|
|
662
297
|
Deliverables (write code to the working directory, and record results in implementation-notes.md).
|
|
663
298
|
|
|
664
299
|
Principles: Write code directly without asking for confirmation. Do not change the API contract \u2014 escalate contract issues upstream. Do not refactor unrelated code. Run commands and report evidence.`;
|
|
665
|
-
var
|
|
666
|
-
{{
|
|
300
|
+
var TASK6 = `## Task Scope
|
|
301
|
+
{{agentScope}}
|
|
667
302
|
|
|
668
|
-
|
|
669
|
-
|
|
303
|
+
## Plan
|
|
304
|
+
{{agentPlan}}
|
|
670
305
|
|
|
671
306
|
---
|
|
672
307
|
|
|
@@ -695,65 +330,109 @@ function frontendDeveloper(overrides) {
|
|
|
695
330
|
id: "frontend-developer",
|
|
696
331
|
name: "Frontend Developer",
|
|
697
332
|
icon: "\u25C7",
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
333
|
+
description: "builds the interface",
|
|
334
|
+
runtime: "acp",
|
|
335
|
+
models: { acp: "sonnet" },
|
|
336
|
+
modelTier: "balanced",
|
|
337
|
+
systemPrompt: SYSTEM6,
|
|
338
|
+
taskPrompt: TASK6,
|
|
701
339
|
tools: ["Read", "Write", "Bash"],
|
|
702
340
|
...overrides
|
|
703
341
|
};
|
|
704
342
|
}
|
|
705
343
|
|
|
706
|
-
// src/agents/
|
|
707
|
-
var
|
|
708
|
-
|
|
709
|
-
Responsibilities:
|
|
710
|
-
- Read requirements (acceptance criteria AC-) and the implementation code
|
|
711
|
-
- Write and execute test cases covering: happy path, edge cases, error paths
|
|
712
|
-
- Produce a reproducible test report
|
|
713
|
-
|
|
714
|
-
Deliverables (save to the working directory):
|
|
715
|
-
- test-report.md \u2014 overall verdict (PASS / FAIL / BLOCKED), test results per feature, reproduction steps and evidence for failures
|
|
344
|
+
// src/agents/leader.ts
|
|
345
|
+
var SYSTEM7 = `You are the project leader. Decide what the requirement actually needs before anyone else starts.
|
|
716
346
|
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
347
|
+
There are three outcomes, and the first one matters most:
|
|
348
|
+
- "reply" \u2014 the message is a greeting, a question, or anything you can answer on the spot. Answer it and stop; do not spend the team on it.
|
|
349
|
+
- "ask" \u2014 it is a real task, but too vague to plan. Ask the one question that would unblock it.
|
|
350
|
+
- "run" \u2014 it is a task you can scope. Name the minimum set of agents needed.
|
|
720
351
|
|
|
721
|
-
|
|
722
|
-
If task-plan.json is not found, verify all features described in the requirement below.
|
|
352
|
+
Do not apply fixed rules \u2014 use your judgment based on the actual requirement and the code. A minor bug fix may need only a developer and code-reviewer; a complex new feature may need the full pipeline. Read the code to understand the impact before deciding.
|
|
723
353
|
|
|
724
|
-
|
|
354
|
+
The console hands you the turns that came before this one. A requirement is often only interpretable next to them: "Postgres" is an answer, not a task, and the turn list is what tells you which question it answers. Read it as your own conversation \u2014 "you asked" is you. If you asked and got an answer, decide now; do not ask the same question again.
|
|
725
355
|
|
|
726
|
-
|
|
356
|
+
Output ONLY a single JSON object on its own line \u2014 no prose, no markdown fences:
|
|
357
|
+
{"mode": "reply", "message": "your answer"}
|
|
358
|
+
{"mode": "ask", "message": "your question"}
|
|
359
|
+
{"mode": "run", "run": ["agent-id-1", "agent-id-2"]}`;
|
|
360
|
+
var TASK7 = `## Project
|
|
727
361
|
{{projectName}}
|
|
728
362
|
|
|
729
363
|
## Requirement
|
|
730
364
|
{{requirement}}
|
|
365
|
+
{{conversation}}
|
|
366
|
+
## Available Agents
|
|
367
|
+
{{availableAgents}}
|
|
731
368
|
|
|
732
369
|
## Task
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
370
|
+
Read the codebase to understand the current state, then decide how to handle the requirement.
|
|
371
|
+
Output a single JSON object \u2014 exactly one of:
|
|
372
|
+
{"mode": "reply", "message": "your answer"}
|
|
373
|
+
{"mode": "ask", "message": "your question"}
|
|
374
|
+
{"mode": "run", "run": ["agent-id", ...]}
|
|
375
|
+
Agent IDs must come from the Available Agents list above.`;
|
|
376
|
+
function leader(overrides) {
|
|
377
|
+
return {
|
|
378
|
+
id: "leader",
|
|
379
|
+
name: "Leader",
|
|
380
|
+
icon: "\u2605",
|
|
381
|
+
description: "routes the request",
|
|
382
|
+
runtime: "acp",
|
|
383
|
+
models: { acp: "sonnet" },
|
|
384
|
+
modelTier: "balanced",
|
|
385
|
+
systemPrompt: SYSTEM7,
|
|
386
|
+
taskPrompt: TASK7,
|
|
387
|
+
tools: ["Read", "Bash"],
|
|
388
|
+
...overrides
|
|
389
|
+
};
|
|
390
|
+
}
|
|
740
391
|
|
|
741
|
-
|
|
742
|
-
|
|
392
|
+
// src/agents/product-manager.ts
|
|
393
|
+
var SYSTEM8 = `You are the product manager. Your responsibility is to transform vague business ideas into clear, development-ready, testable product requirement documents.
|
|
394
|
+
|
|
395
|
+
Responsibilities:
|
|
396
|
+
- Analyze business goals and user scenarios
|
|
397
|
+
- Define feature scope, business rules, and acceptance criteria
|
|
398
|
+
- Structure "what is needed" into a PRD that the development team can execute directly
|
|
399
|
+
|
|
400
|
+
Deliverables (save to the working directory):
|
|
401
|
+
- requirements.md \u2014 product requirements document containing: one-line definition, goals and success metrics, user roles, functional requirements (FR-), business rules (BR-), acceptance criteria (AC-), open questions (OP-)
|
|
402
|
+
|
|
403
|
+
Principles: Output the document directly without preamble. Mark uncertain items as OP- (open questions) rather than guessing. Do not do technical architecture design. Do not write feature code.`;
|
|
404
|
+
var TASK8 = `## Business Context
|
|
405
|
+
{{requirement}}
|
|
406
|
+
|
|
407
|
+
## Task
|
|
408
|
+
Based on the context above, create requirements.md in the current directory containing:
|
|
409
|
+
- One-line definition (what this product/feature is)
|
|
410
|
+
- Goals and success metrics
|
|
411
|
+
- User roles and typical scenarios
|
|
412
|
+
- Functional requirements (FR-01, FR-02, ...)
|
|
413
|
+
- Business rules (BR-01, ...)
|
|
414
|
+
- Acceptance criteria (AC-01, ..., each must be executable and verifiable)
|
|
415
|
+
- Open questions (OP-01, ..., list uncertain items here)
|
|
416
|
+
|
|
417
|
+
Create the file directly. Mark uncertain items as OP- rather than guessing.`;
|
|
418
|
+
function productManager(overrides) {
|
|
743
419
|
return {
|
|
744
|
-
id: "
|
|
745
|
-
name: "
|
|
746
|
-
icon: "\
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
420
|
+
id: "product-manager",
|
|
421
|
+
name: "Product Manager",
|
|
422
|
+
icon: "\u2261",
|
|
423
|
+
description: "writes the requirements",
|
|
424
|
+
runtime: "acp",
|
|
425
|
+
models: { acp: "sonnet" },
|
|
426
|
+
modelTier: "balanced",
|
|
427
|
+
systemPrompt: SYSTEM8,
|
|
428
|
+
taskPrompt: TASK8,
|
|
429
|
+
tools: ["Write"],
|
|
751
430
|
...overrides
|
|
752
431
|
};
|
|
753
432
|
}
|
|
754
433
|
|
|
755
434
|
// src/agents/reviewer.ts
|
|
756
|
-
var
|
|
435
|
+
var SYSTEM9 = `You are an independent code review expert. You evaluate both business correctness and technical quality.
|
|
757
436
|
|
|
758
437
|
Responsibilities:
|
|
759
438
|
- Read requirements, design documents, and implementation code
|
|
@@ -764,7 +443,7 @@ Deliverables (save to the working directory):
|
|
|
764
443
|
- review.md \u2014 score (1\u201310), issue list (blocking / advisory), improvement directions, conclusion (Approved / Changes Required)
|
|
765
444
|
|
|
766
445
|
Principles: Review independently \u2014 do not approve just because the developer says it is fine. Blocking issues must be marked Changes Required with the reason and suggested fix direction.`;
|
|
767
|
-
var
|
|
446
|
+
var TASK9 = `## Project
|
|
768
447
|
{{projectName}}
|
|
769
448
|
|
|
770
449
|
## Requirement
|
|
@@ -787,77 +466,36 @@ function reviewer(overrides) {
|
|
|
787
466
|
id: "reviewer",
|
|
788
467
|
name: "Reviewer",
|
|
789
468
|
icon: "\u25C9",
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
469
|
+
description: "reviews the delivery",
|
|
470
|
+
runtime: "acp",
|
|
471
|
+
models: { acp: "haiku" },
|
|
472
|
+
modelTier: "fast",
|
|
473
|
+
systemPrompt: SYSTEM9,
|
|
474
|
+
taskPrompt: TASK9,
|
|
793
475
|
tools: ["Read", "Write"],
|
|
794
476
|
...overrides
|
|
795
477
|
};
|
|
796
478
|
}
|
|
797
479
|
|
|
798
|
-
// src/agents/
|
|
799
|
-
var
|
|
480
|
+
// src/agents/tester.ts
|
|
481
|
+
var SYSTEM10 = `You are the test engineer. Your responsibility is to verify that requirements have actually been implemented.
|
|
800
482
|
|
|
801
483
|
Responsibilities:
|
|
802
|
-
-
|
|
803
|
-
-
|
|
804
|
-
-
|
|
805
|
-
- Do not write code, do not implement \u2014 provide only design-level feedback
|
|
484
|
+
- Read requirements (acceptance criteria AC-) and the implementation code
|
|
485
|
+
- Write and execute test cases covering: happy path, edge cases, error paths
|
|
486
|
+
- Produce a reproducible test report
|
|
806
487
|
|
|
807
488
|
Deliverables (save to the working directory):
|
|
808
|
-
-
|
|
489
|
+
- test-report.md \u2014 overall verdict (PASS / FAIL / BLOCKED), test results per feature, reproduction steps and evidence for failures
|
|
809
490
|
|
|
810
|
-
Principles:
|
|
811
|
-
var
|
|
812
|
-
{{
|
|
491
|
+
Principles: Do not PASS just because the code compiles or because a developer says it is fine. Every core feature must be verified with actual execution. When BLOCKED, state exactly what is missing.`;
|
|
492
|
+
var TASK10 = `## Task Scope
|
|
493
|
+
{{agentScope}}
|
|
813
494
|
|
|
814
|
-
##
|
|
815
|
-
{{
|
|
495
|
+
## Plan
|
|
496
|
+
{{agentPlan}}
|
|
816
497
|
|
|
817
|
-
|
|
818
|
-
Review the architecture design and API specification above. Output arch-review.md:
|
|
819
|
-
1. Overall verdict: Approved / Changes Required
|
|
820
|
-
2. Blocking issues (must be fixed before implementation): each with location, problem, and fix direction
|
|
821
|
-
3. Advisory issues (should fix but not blocking): each with location and suggestion
|
|
822
|
-
4. Design strengths worth noting
|
|
823
|
-
5. Final summary (1\u20132 sentences)
|
|
824
|
-
|
|
825
|
-
Be specific. Reference section names or endpoint paths when citing issues.`;
|
|
826
|
-
function archDesignReviewer(overrides) {
|
|
827
|
-
return {
|
|
828
|
-
id: "arch-design-reviewer",
|
|
829
|
-
name: "Arch Design Reviewer",
|
|
830
|
-
icon: "\u25B3",
|
|
831
|
-
models: { claude: "haiku" },
|
|
832
|
-
systemPrompt: SYSTEM8,
|
|
833
|
-
taskPrompt: TASK8,
|
|
834
|
-
tools: ["Read", "Write"],
|
|
835
|
-
...overrides
|
|
836
|
-
};
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
// src/agents/ui-designer.ts
|
|
840
|
-
var SYSTEM9 = `You are a UI/UX designer. Your job is to translate architecture and requirements into a detailed, developer-ready UI design specification.
|
|
841
|
-
|
|
842
|
-
Responsibilities:
|
|
843
|
-
- Define the component inventory: every page, section, and reusable component
|
|
844
|
-
- Specify layouts, spacing principles, and responsive breakpoints
|
|
845
|
-
- Define interaction patterns: loading states, empty states, error states, transitions
|
|
846
|
-
- Specify design tokens: color palette, typography scale, spacing scale, shadow levels
|
|
847
|
-
- Describe accessibility requirements: ARIA roles, keyboard navigation, focus management
|
|
848
|
-
- Do not write implementation code \u2014 produce specification documents only
|
|
849
|
-
|
|
850
|
-
Deliverables (save to the working directory):
|
|
851
|
-
- ui-design.md \u2014 full UI design specification: component inventory, page layouts, interaction flows, design tokens, accessibility requirements
|
|
852
|
-
|
|
853
|
-
Principles: Be specific enough that a developer can implement without guessing. Every component gets a name, purpose, props/variants, and states. Flag anything that depends on backend data.`;
|
|
854
|
-
var TASK9 = `## Task Scope
|
|
855
|
-
{{file:task-plan.json}}
|
|
856
|
-
|
|
857
|
-
Find the entry where id == "ui-designer" and treat its scope as the primary guide for your work.
|
|
858
|
-
If task-plan.json is not found, determine your scope from the architecture design and API specification below.
|
|
859
|
-
|
|
860
|
-
---
|
|
498
|
+
---
|
|
861
499
|
|
|
862
500
|
## Project
|
|
863
501
|
{{projectName}}
|
|
@@ -865,36 +503,34 @@ If task-plan.json is not found, determine your scope from the architecture desig
|
|
|
865
503
|
## Requirement
|
|
866
504
|
{{requirement}}
|
|
867
505
|
|
|
868
|
-
## Architecture Design
|
|
869
|
-
{{file:architecture.md}}
|
|
870
|
-
|
|
871
|
-
## API Specification
|
|
872
|
-
{{file:api-spec.md}}
|
|
873
|
-
|
|
874
506
|
## Task
|
|
875
|
-
|
|
876
|
-
1.
|
|
877
|
-
2.
|
|
878
|
-
3.
|
|
879
|
-
|
|
880
|
-
|
|
507
|
+
Verify the implementation code in the current directory:
|
|
508
|
+
1. Read all source code to understand the implementation
|
|
509
|
+
2. Write and execute tests for each core feature
|
|
510
|
+
3. Output results to test-report.md containing:
|
|
511
|
+
- Overall verdict (PASS / FAIL / BLOCKED)
|
|
512
|
+
- Test result for each feature
|
|
513
|
+
- Reproduction steps and evidence for failures
|
|
881
514
|
|
|
882
|
-
|
|
883
|
-
function
|
|
515
|
+
Start immediately. Verify actual behavior \u2014 do not just review code.`;
|
|
516
|
+
function tester(overrides) {
|
|
884
517
|
return {
|
|
885
|
-
id: "
|
|
886
|
-
name: "
|
|
887
|
-
icon: "\
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
518
|
+
id: "tester",
|
|
519
|
+
name: "Tester",
|
|
520
|
+
icon: "\u2299",
|
|
521
|
+
description: "verifies the behaviour",
|
|
522
|
+
runtime: "acp",
|
|
523
|
+
models: { acp: "sonnet" },
|
|
524
|
+
modelTier: "balanced",
|
|
525
|
+
systemPrompt: SYSTEM10,
|
|
526
|
+
taskPrompt: TASK10,
|
|
527
|
+
tools: ["Read", "Write", "Bash"],
|
|
892
528
|
...overrides
|
|
893
529
|
};
|
|
894
530
|
}
|
|
895
531
|
|
|
896
532
|
// src/agents/ui-design-reviewer.ts
|
|
897
|
-
var
|
|
533
|
+
var SYSTEM11 = `You are a UI/UX design reviewer. Your job is to evaluate a UI design specification before implementation begins.
|
|
898
534
|
|
|
899
535
|
Responsibilities:
|
|
900
536
|
- Review the design specification for completeness, consistency, and feasibility
|
|
@@ -907,7 +543,7 @@ Deliverables (save to the working directory):
|
|
|
907
543
|
- ui-review.md \u2014 verdict (Approved / Changes Required), issue list (blocking / advisory) with component names and fix directions
|
|
908
544
|
|
|
909
545
|
Principles: Be specific \u2014 reference component names or section titles in ui-design.md. A blocking issue must include what is missing or wrong and a fix direction. If the design is thorough and implementable, say so directly.`;
|
|
910
|
-
var
|
|
546
|
+
var TASK11 = `## Requirement
|
|
911
547
|
{{requirement}}
|
|
912
548
|
|
|
913
549
|
## UI Design Specification
|
|
@@ -929,57 +565,10 @@ function uiDesignReviewer(overrides) {
|
|
|
929
565
|
id: "ui-design-reviewer",
|
|
930
566
|
name: "UI Design Reviewer",
|
|
931
567
|
icon: "\u25CE",
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
...overrides
|
|
937
|
-
};
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
// src/agents/code-reviewer.ts
|
|
941
|
-
var SYSTEM11 = `You are a code review expert focused on implementation quality, correctness, and security.
|
|
942
|
-
|
|
943
|
-
Responsibilities:
|
|
944
|
-
- Read the requirement, architecture design, and all implementation code
|
|
945
|
-
- Verify the implementation matches the API specification and satisfies the requirement
|
|
946
|
-
- Identify bugs, security vulnerabilities, error handling gaps, and test coverage issues
|
|
947
|
-
- Assess code quality: readability, naming, separation of concerns, duplication
|
|
948
|
-
- Do not run code, do not modify code \u2014 provide written judgment only
|
|
949
|
-
|
|
950
|
-
Deliverables (save to the working directory):
|
|
951
|
-
- code-review.md \u2014 score (1\u201310), blocking issues, advisory issues, conclusion (Approved / Changes Required)
|
|
952
|
-
|
|
953
|
-
Principles: Judge the code, not the developer. A blocking issue must include the file path, the specific problem, and a fix direction. Advisory items should be actionable, not vague. If the code is solid, say so.`;
|
|
954
|
-
var TASK11 = `## Project
|
|
955
|
-
{{projectName}}
|
|
956
|
-
|
|
957
|
-
## Requirement
|
|
958
|
-
{{requirement}}
|
|
959
|
-
|
|
960
|
-
## Architecture Design
|
|
961
|
-
{{file:architecture.md}}
|
|
962
|
-
|
|
963
|
-
## API Specification
|
|
964
|
-
{{file:api-spec.md}}
|
|
965
|
-
|
|
966
|
-
## Task
|
|
967
|
-
Perform a thorough code review of all implementation in the current directory and output code-review.md:
|
|
968
|
-
1. Overall score (1\u201310) and verdict: Approved / Changes Required
|
|
969
|
-
2. Blocking issues (bugs, security holes, missing requirement coverage, broken tests):
|
|
970
|
-
- file path + line range, problem description, fix direction
|
|
971
|
-
3. Advisory issues (code quality, naming, duplication, missing error handling):
|
|
972
|
-
- file path, observation, suggestion
|
|
973
|
-
4. Test coverage assessment
|
|
974
|
-
5. Final summary (2\u20133 sentences)
|
|
975
|
-
|
|
976
|
-
Start by reading implementation-notes.md (if present), then read source and test files.`;
|
|
977
|
-
function codeReviewer(overrides) {
|
|
978
|
-
return {
|
|
979
|
-
id: "code-reviewer",
|
|
980
|
-
name: "Code Reviewer",
|
|
981
|
-
icon: "\u2297",
|
|
982
|
-
models: { claude: "haiku" },
|
|
568
|
+
description: "reviews the UI design",
|
|
569
|
+
runtime: "acp",
|
|
570
|
+
models: { acp: "haiku" },
|
|
571
|
+
modelTier: "fast",
|
|
983
572
|
systemPrompt: SYSTEM11,
|
|
984
573
|
taskPrompt: TASK11,
|
|
985
574
|
tools: ["Read", "Write"],
|
|
@@ -987,54 +576,59 @@ function codeReviewer(overrides) {
|
|
|
987
576
|
};
|
|
988
577
|
}
|
|
989
578
|
|
|
990
|
-
// src/agents/
|
|
991
|
-
var SYSTEM12 = `You are
|
|
579
|
+
// src/agents/ui-designer.ts
|
|
580
|
+
var SYSTEM12 = `You are a UI/UX designer. Your job is to translate architecture and requirements into a detailed, developer-ready UI design specification.
|
|
992
581
|
|
|
993
582
|
Responsibilities:
|
|
994
|
-
-
|
|
995
|
-
-
|
|
996
|
-
-
|
|
997
|
-
-
|
|
998
|
-
-
|
|
999
|
-
- Do not
|
|
583
|
+
- Define the component inventory: every page, section, and reusable component
|
|
584
|
+
- Specify layouts, spacing principles, and responsive breakpoints
|
|
585
|
+
- Define interaction patterns: loading states, empty states, error states, transitions
|
|
586
|
+
- Specify design tokens: color palette, typography scale, spacing scale, shadow levels
|
|
587
|
+
- Describe accessibility requirements: ARIA roles, keyboard navigation, focus management
|
|
588
|
+
- Do not write implementation code \u2014 produce specification documents only
|
|
1000
589
|
|
|
1001
590
|
Deliverables (save to the working directory):
|
|
1002
|
-
-
|
|
1003
|
-
- docker-compose.yml \u2014 local development / staging orchestration (if multiple services)
|
|
1004
|
-
- .github/workflows/ci.yml (or equivalent) \u2014 CI pipeline: build, test, lint
|
|
1005
|
-
- .env.example \u2014 required environment variables with descriptions
|
|
1006
|
-
- devops-notes.md \u2014 deployment procedure, environment requirements, known limitations
|
|
591
|
+
- ui-design.md \u2014 full UI design specification: component inventory, page layouts, interaction flows, design tokens, accessibility requirements
|
|
1007
592
|
|
|
1008
|
-
Principles:
|
|
593
|
+
Principles: Be specific enough that a developer can implement without guessing. Every component gets a name, purpose, props/variants, and states. Flag anything that depends on backend data.`;
|
|
1009
594
|
var TASK12 = `## Task Scope
|
|
1010
|
-
{{
|
|
595
|
+
{{agentScope}}
|
|
1011
596
|
|
|
1012
|
-
|
|
1013
|
-
|
|
597
|
+
## Plan
|
|
598
|
+
{{agentPlan}}
|
|
1014
599
|
|
|
1015
600
|
---
|
|
1016
601
|
|
|
1017
602
|
## Project
|
|
1018
603
|
{{projectName}}
|
|
1019
604
|
|
|
605
|
+
## Requirement
|
|
606
|
+
{{requirement}}
|
|
607
|
+
|
|
1020
608
|
## Architecture Design
|
|
1021
609
|
{{file:architecture.md}}
|
|
1022
610
|
|
|
611
|
+
## API Specification
|
|
612
|
+
{{file:api-spec.md}}
|
|
613
|
+
|
|
1023
614
|
## Task
|
|
1024
|
-
|
|
1025
|
-
1.
|
|
1026
|
-
2.
|
|
1027
|
-
3.
|
|
1028
|
-
4.
|
|
1029
|
-
5.
|
|
615
|
+
Create ui-design.md covering:
|
|
616
|
+
1. **Component Inventory** \u2014 list every page and reusable component; for each: name, purpose, variants/states, props
|
|
617
|
+
2. **Page Layouts** \u2014 describe the visual structure of each page (header, main, sidebar, footer zones); include responsive behaviour
|
|
618
|
+
3. **Interaction Flows** \u2014 key user flows with step-by-step state transitions (loading \u2192 success \u2192 error)
|
|
619
|
+
4. **Design Tokens** \u2014 color palette (primary, neutral, semantic), typography scale, spacing scale
|
|
620
|
+
5. **Accessibility** \u2014 ARIA roles/labels for interactive components, keyboard nav, focus order
|
|
1030
621
|
|
|
1031
|
-
|
|
1032
|
-
function
|
|
622
|
+
Be concrete. Reference API endpoints where components bind to data. Flag any UX decision that needs product clarification.`;
|
|
623
|
+
function uiDesigner(overrides) {
|
|
1033
624
|
return {
|
|
1034
|
-
id: "
|
|
1035
|
-
name: "
|
|
1036
|
-
icon: "\
|
|
1037
|
-
|
|
625
|
+
id: "ui-designer",
|
|
626
|
+
name: "UI Designer",
|
|
627
|
+
icon: "\u25A3",
|
|
628
|
+
description: "specs the interface",
|
|
629
|
+
runtime: "acp",
|
|
630
|
+
models: { acp: "sonnet" },
|
|
631
|
+
modelTier: "balanced",
|
|
1038
632
|
systemPrompt: SYSTEM12,
|
|
1039
633
|
taskPrompt: TASK12,
|
|
1040
634
|
tools: ["Read", "Write"],
|
|
@@ -1057,13 +651,1517 @@ var agents = {
|
|
|
1057
651
|
codeReviewer,
|
|
1058
652
|
devops
|
|
1059
653
|
};
|
|
654
|
+
|
|
655
|
+
// src/config/defineConfig.ts
|
|
656
|
+
function defineConfig(config) {
|
|
657
|
+
return config;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// src/event/EventBus.ts
|
|
661
|
+
var EventBus = class {
|
|
662
|
+
constructor() {
|
|
663
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
664
|
+
}
|
|
665
|
+
subscribe(listener) {
|
|
666
|
+
this.listeners.add(listener);
|
|
667
|
+
return () => this.listeners.delete(listener);
|
|
668
|
+
}
|
|
669
|
+
emit(event) {
|
|
670
|
+
for (const listener of this.listeners) {
|
|
671
|
+
try {
|
|
672
|
+
listener(event);
|
|
673
|
+
} catch (err) {
|
|
674
|
+
console.error("EventBus listener error:", err);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
clear() {
|
|
679
|
+
this.listeners.clear();
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
// src/orchestrator/Orchestrator.ts
|
|
684
|
+
import * as fs4 from "fs";
|
|
685
|
+
import * as path5 from "path";
|
|
686
|
+
|
|
687
|
+
// src/utils/conversation.ts
|
|
688
|
+
var MAX_CONVERSATION_TURNS = 6;
|
|
689
|
+
var MAX_CONVERSATION_CHARS = 4e3;
|
|
690
|
+
var MAX_ENTRY_CHARS = 600;
|
|
691
|
+
var ELLIPSIS = "\u2026";
|
|
692
|
+
function clip(text, max) {
|
|
693
|
+
const trimmed = text.trim();
|
|
694
|
+
if (trimmed.length <= max) return trimmed;
|
|
695
|
+
return `${trimmed.slice(0, Math.max(0, max - 1)).trimEnd()}${ELLIPSIS}`;
|
|
696
|
+
}
|
|
697
|
+
function entry(turn, index) {
|
|
698
|
+
const lines = [`${index}. user: ${clip(turn.requirement, MAX_ENTRY_CHARS)}`];
|
|
699
|
+
if (turn.reply) {
|
|
700
|
+
const verb = turn.reply.mode === "ask" ? "asked" : "answered";
|
|
701
|
+
lines.push(` you ${verb}: ${clip(turn.reply.message, MAX_ENTRY_CHARS)}`);
|
|
702
|
+
}
|
|
703
|
+
return lines.join("\n");
|
|
704
|
+
}
|
|
705
|
+
function renderConversation(history) {
|
|
706
|
+
if (!history || history.length === 0) return "";
|
|
707
|
+
const recent = history.slice(-MAX_CONVERSATION_TURNS);
|
|
708
|
+
const first = history.length - recent.length;
|
|
709
|
+
const entries = recent.map((turn, i) => entry(turn, first + i + 1));
|
|
710
|
+
while (entries.length > 1 && entries.join("\n").length > MAX_CONVERSATION_CHARS) {
|
|
711
|
+
entries.shift();
|
|
712
|
+
}
|
|
713
|
+
const body = clip(entries.join("\n"), MAX_CONVERSATION_CHARS);
|
|
714
|
+
return `
|
|
715
|
+
## Conversation so far
|
|
716
|
+
|
|
717
|
+
Earlier turns of this session, oldest first:
|
|
718
|
+
|
|
719
|
+
${body}
|
|
720
|
+
`;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
// src/utils/json.ts
|
|
724
|
+
function extractJsonObjects(text) {
|
|
725
|
+
const objects = [];
|
|
726
|
+
let searchFrom = 0;
|
|
727
|
+
while (searchFrom < text.length) {
|
|
728
|
+
const start = text.indexOf("{", searchFrom);
|
|
729
|
+
if (start === -1) break;
|
|
730
|
+
const end = findMatchingBrace(text, start);
|
|
731
|
+
if (end !== -1) {
|
|
732
|
+
try {
|
|
733
|
+
objects.push(JSON.parse(text.slice(start, end + 1)));
|
|
734
|
+
searchFrom = end + 1;
|
|
735
|
+
continue;
|
|
736
|
+
} catch {
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
searchFrom = start + 1;
|
|
740
|
+
}
|
|
741
|
+
return objects;
|
|
742
|
+
}
|
|
743
|
+
function findMatchingBrace(text, start) {
|
|
744
|
+
let depth = 0;
|
|
745
|
+
let inString = false;
|
|
746
|
+
let escaped = false;
|
|
747
|
+
for (let i = start; i < text.length; i++) {
|
|
748
|
+
const ch = text[i];
|
|
749
|
+
if (inString) {
|
|
750
|
+
if (escaped) escaped = false;
|
|
751
|
+
else if (ch === "\\") escaped = true;
|
|
752
|
+
else if (ch === '"') inString = false;
|
|
753
|
+
continue;
|
|
754
|
+
}
|
|
755
|
+
if (ch === '"') inString = true;
|
|
756
|
+
else if (ch === "{") depth++;
|
|
757
|
+
else if (ch === "}") {
|
|
758
|
+
depth--;
|
|
759
|
+
if (depth === 0) return i;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
return -1;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
// src/utils/leaderDecision.ts
|
|
766
|
+
function parseLeaderDecision(text) {
|
|
767
|
+
for (const value of extractJsonObjects(text)) {
|
|
768
|
+
const decision = asDecision(value);
|
|
769
|
+
if (decision) return decision;
|
|
770
|
+
}
|
|
771
|
+
return void 0;
|
|
772
|
+
}
|
|
773
|
+
function asDecision(value) {
|
|
774
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
775
|
+
const record = value;
|
|
776
|
+
const mode = record.mode;
|
|
777
|
+
if (mode === "reply" || mode === "ask") {
|
|
778
|
+
const message = typeof record.message === "string" ? record.message.trim() : "";
|
|
779
|
+
return message ? { mode, message } : void 0;
|
|
780
|
+
}
|
|
781
|
+
if (mode === "run" || mode === void 0) {
|
|
782
|
+
const run = record.run;
|
|
783
|
+
if (!Array.isArray(run) || !run.every((id) => typeof id === "string")) return void 0;
|
|
784
|
+
return { mode: "run", run };
|
|
785
|
+
}
|
|
786
|
+
return void 0;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
// src/orchestrator/AgentRunner.ts
|
|
790
|
+
import * as fs3 from "fs";
|
|
791
|
+
import * as path4 from "path";
|
|
792
|
+
|
|
793
|
+
// src/providers/catalog.ts
|
|
794
|
+
import * as path from "path";
|
|
795
|
+
function normalizeCommandKey(command) {
|
|
796
|
+
return path.basename(command).toLowerCase().replace(/\.(cmd|exe|bat)$/i, "");
|
|
797
|
+
}
|
|
798
|
+
var PROVIDERS = [
|
|
799
|
+
{
|
|
800
|
+
id: "opencode",
|
|
801
|
+
label: "OpenCode",
|
|
802
|
+
command: "opencode",
|
|
803
|
+
args: ["acp"],
|
|
804
|
+
tools: false,
|
|
805
|
+
modelSelection: "config-option",
|
|
806
|
+
models: [
|
|
807
|
+
{ id: "opencode/big-pickle", label: "Big Pickle", tier: "balanced", defaultForTier: true },
|
|
808
|
+
{ id: "opencode/exo-free", label: "Exo", tier: "strong", defaultForTier: true },
|
|
809
|
+
{ id: "opencode/ling-3.0-flash-fin-free", label: "Ling 3.0 Flash", tier: "fast" },
|
|
810
|
+
{
|
|
811
|
+
id: "opencode/ling-3.1-flash-free",
|
|
812
|
+
label: "Ling 3.1 Flash",
|
|
813
|
+
tier: "fast",
|
|
814
|
+
defaultForTier: true
|
|
815
|
+
},
|
|
816
|
+
{ id: "opencode/longcat-2.5-preview-free", label: "Longcat 2.5 Preview", tier: "balanced" },
|
|
817
|
+
{ id: "opencode/mimo-v2.6-flash-free", label: "Mimo 2.6 Flash", tier: "fast" },
|
|
818
|
+
{ id: "opencode/muse-spark-1.3-contributor-free", label: "Muse Spark 1.3", tier: "fast" },
|
|
819
|
+
{ id: "opencode/nemotron-3-ultra-free", label: "Nemotron 3 Ultra", tier: "strong" },
|
|
820
|
+
{ id: "opencode/nemotron-3.5-lightning-free", label: "Nemotron 3.5 Lightning", tier: "fast" },
|
|
821
|
+
{ id: "opencode/space-bunny-free", label: "Space Bunny", tier: "fast" },
|
|
822
|
+
{ id: "opencode/step-5-preview-free", label: "Step 5 Preview", tier: "strong" }
|
|
823
|
+
],
|
|
824
|
+
defaultModel: "opencode/big-pickle",
|
|
825
|
+
install: { hint: "npm install -g opencode" },
|
|
826
|
+
auth: { kind: "none", hint: "" }
|
|
827
|
+
},
|
|
828
|
+
{
|
|
829
|
+
id: "claude",
|
|
830
|
+
label: "Claude",
|
|
831
|
+
command: "claude-agent-acp",
|
|
832
|
+
args: [],
|
|
833
|
+
tools: true,
|
|
834
|
+
modelSelection: "config-option",
|
|
835
|
+
meta: (task) => {
|
|
836
|
+
const meta = {};
|
|
837
|
+
if (task.systemPrompt) meta.systemPrompt = task.systemPrompt;
|
|
838
|
+
meta.claudeCode = { options: { tools: task.tools } };
|
|
839
|
+
return meta;
|
|
840
|
+
},
|
|
841
|
+
models: [
|
|
842
|
+
{ id: "default", label: "Default", tier: "balanced" },
|
|
843
|
+
{ id: "opus", label: "Opus", tier: "strong", defaultForTier: true },
|
|
844
|
+
{ id: "fable", label: "Fable", tier: "balanced" },
|
|
845
|
+
{ id: "sonnet", label: "Sonnet", tier: "balanced", defaultForTier: true },
|
|
846
|
+
{ id: "haiku", label: "Haiku", tier: "fast", defaultForTier: true }
|
|
847
|
+
],
|
|
848
|
+
defaultModel: "sonnet",
|
|
849
|
+
install: {
|
|
850
|
+
hint: "multiclaw bundles the ACP bridge \u2014 install the Claude Code CLI (`claude`) and run `claude` to log in"
|
|
851
|
+
},
|
|
852
|
+
auth: { kind: "ambient", hint: "run `claude` to log in" }
|
|
853
|
+
},
|
|
854
|
+
{
|
|
855
|
+
id: "codex",
|
|
856
|
+
label: "Codex",
|
|
857
|
+
command: "codex-acp",
|
|
858
|
+
args: [],
|
|
859
|
+
tools: false,
|
|
860
|
+
modelSelection: "config-option",
|
|
861
|
+
meta: (task) => task.systemPrompt ? { jetbrains: { air: { customInstructions: task.systemPrompt } } } : void 0,
|
|
862
|
+
// Placeholders — real ids require auth to enumerate.
|
|
863
|
+
models: [
|
|
864
|
+
{ id: "gpt-5-codex", label: "GPT-5 Codex", tier: "strong", defaultForTier: true },
|
|
865
|
+
{ id: "gpt-5", label: "GPT-5", tier: "balanced", defaultForTier: true },
|
|
866
|
+
{ id: "gpt-5-mini", label: "GPT-5 Mini", tier: "fast", defaultForTier: true }
|
|
867
|
+
],
|
|
868
|
+
defaultModel: "gpt-5",
|
|
869
|
+
install: {
|
|
870
|
+
hint: "multiclaw bundles the ACP bridge \u2014 install the Codex CLI (`codex`) and run `codex login`"
|
|
871
|
+
},
|
|
872
|
+
auth: { kind: "api-key", hint: "set OPENAI_API_KEY or run `codex login`" }
|
|
873
|
+
},
|
|
874
|
+
{
|
|
875
|
+
id: "cursor",
|
|
876
|
+
label: "Cursor",
|
|
877
|
+
command: "cursor-agent",
|
|
878
|
+
aliases: ["agent"],
|
|
879
|
+
args: ["acp"],
|
|
880
|
+
tools: false,
|
|
881
|
+
modelSelection: "config-option",
|
|
882
|
+
// _meta support unverified — falls back to prompt prefix until confirmed.
|
|
883
|
+
meta: void 0,
|
|
884
|
+
// Placeholders — real ids require Cursor CLI + auth to enumerate.
|
|
885
|
+
models: [
|
|
886
|
+
{ id: "cursor-pro", label: "Cursor Pro", tier: "strong", defaultForTier: true },
|
|
887
|
+
{ id: "cursor-fast", label: "Cursor Fast", tier: "fast", defaultForTier: true }
|
|
888
|
+
],
|
|
889
|
+
defaultModel: "cursor-pro",
|
|
890
|
+
install: {
|
|
891
|
+
hint: "curl https://cursor.com/install | bash",
|
|
892
|
+
url: "https://cursor.com/docs/cli/acp"
|
|
893
|
+
},
|
|
894
|
+
auth: { kind: "login", hint: "run `agent login` first (or set CURSOR_API_KEY)" },
|
|
895
|
+
confirm: (v) => /cursor/i.test(v)
|
|
896
|
+
}
|
|
897
|
+
];
|
|
898
|
+
var byProviderId = /* @__PURE__ */ new Map();
|
|
899
|
+
var byCommand = /* @__PURE__ */ new Map();
|
|
900
|
+
for (const spec of PROVIDERS) {
|
|
901
|
+
byProviderId.set(spec.id, spec);
|
|
902
|
+
byCommand.set(normalizeCommandKey(spec.command), spec);
|
|
903
|
+
if (spec.aliases) {
|
|
904
|
+
for (const alias of spec.aliases) {
|
|
905
|
+
byCommand.set(normalizeCommandKey(alias), spec);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
function specForProvider(id) {
|
|
910
|
+
return byProviderId.get(id);
|
|
911
|
+
}
|
|
912
|
+
function specForCommand(command) {
|
|
913
|
+
return byCommand.get(normalizeCommandKey(command));
|
|
914
|
+
}
|
|
915
|
+
function providerIds() {
|
|
916
|
+
return [...byProviderId.keys()];
|
|
917
|
+
}
|
|
918
|
+
function providerCommands() {
|
|
919
|
+
return [...byCommand.keys()];
|
|
920
|
+
}
|
|
921
|
+
function tierModel(spec, tier) {
|
|
922
|
+
const m = spec.models.find((m2) => m2.tier === tier && m2.defaultForTier);
|
|
923
|
+
return m?.id ?? spec.models.find((m2) => m2.tier === tier)?.id;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
// src/providers/resolve.ts
|
|
927
|
+
var DEFAULT_COMMAND = "opencode";
|
|
928
|
+
var DEFAULT_PROVIDER = "opencode";
|
|
929
|
+
function resolveProvider(agent, config) {
|
|
930
|
+
return agent.provider ?? specForCommand(agent.command ?? "")?.id ?? config.defaults?.provider ?? specForCommand(DEFAULT_COMMAND)?.id ?? DEFAULT_PROVIDER;
|
|
931
|
+
}
|
|
932
|
+
function resolveCommand(agent, config) {
|
|
933
|
+
return agent.command ?? config.defaults?.command ?? specForProvider(resolveProvider(agent, config))?.command ?? DEFAULT_COMMAND;
|
|
934
|
+
}
|
|
935
|
+
function resolveArgs(agent, config) {
|
|
936
|
+
return agent.args ?? specForProvider(resolveProvider(agent, config))?.args;
|
|
937
|
+
}
|
|
938
|
+
function resolveModel(agent, config) {
|
|
939
|
+
if (agent.model) return agent.model;
|
|
940
|
+
const provider = resolveProvider(agent, config);
|
|
941
|
+
const spec = specForProvider(provider);
|
|
942
|
+
const fromModels = agent.models?.[provider] ?? agent.models?.acp;
|
|
943
|
+
if (fromModels) return fromModels;
|
|
944
|
+
if (agent.modelTier && spec) {
|
|
945
|
+
const fromTier = tierModel(spec, agent.modelTier);
|
|
946
|
+
if (fromTier) return fromTier;
|
|
947
|
+
}
|
|
948
|
+
if (config.defaults?.model) return config.defaults.model;
|
|
949
|
+
if (spec) return spec.defaultModel;
|
|
950
|
+
return void 0;
|
|
951
|
+
}
|
|
952
|
+
function resolveAgentRuntime(agent, config) {
|
|
953
|
+
const provider = resolveProvider(agent, config);
|
|
954
|
+
const spec = specForProvider(provider);
|
|
955
|
+
return {
|
|
956
|
+
provider,
|
|
957
|
+
command: resolveCommand(agent, config),
|
|
958
|
+
model: resolveModel(agent, config),
|
|
959
|
+
spec
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
// src/runtime/AcpRuntime.ts
|
|
964
|
+
import { spawn } from "child_process";
|
|
965
|
+
import { randomUUID } from "crypto";
|
|
966
|
+
import { Readable, Writable } from "stream";
|
|
967
|
+
import { StringDecoder } from "string_decoder";
|
|
968
|
+
|
|
969
|
+
// src/providers/bridge.ts
|
|
970
|
+
import * as fs from "fs";
|
|
971
|
+
import { createRequire } from "module";
|
|
972
|
+
import * as path2 from "path";
|
|
973
|
+
var BRIDGE_PACKAGES = {
|
|
974
|
+
"claude-agent-acp": "@agentclientprotocol/claude-agent-acp",
|
|
975
|
+
"codex-acp": "@agentclientprotocol/codex-acp"
|
|
976
|
+
};
|
|
977
|
+
function resolvesOnPath(command) {
|
|
978
|
+
const dirs = (process.env.PATH ?? "").split(path2.delimiter).filter(Boolean);
|
|
979
|
+
const exts = (process.env.PATHEXT ?? "").split(";").filter(Boolean);
|
|
980
|
+
const suffixes = exts.length > 0 ? exts : [""];
|
|
981
|
+
for (const dir of dirs) {
|
|
982
|
+
for (const ext of suffixes) {
|
|
983
|
+
try {
|
|
984
|
+
fs.accessSync(path2.join(dir, command + ext), fs.constants.X_OK);
|
|
985
|
+
return true;
|
|
986
|
+
} catch {
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
return false;
|
|
991
|
+
}
|
|
992
|
+
function resolveBridgeBinary(command) {
|
|
993
|
+
const pkg = BRIDGE_PACKAGES[command];
|
|
994
|
+
if (!pkg) return null;
|
|
995
|
+
try {
|
|
996
|
+
const req = createRequire(import.meta.url);
|
|
997
|
+
const pkgJsonPath = req.resolve(`${pkg}/package.json`);
|
|
998
|
+
const bin = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8")).bin;
|
|
999
|
+
const binRel = typeof bin === "string" ? bin : bin?.[command] ?? Object.values(bin)[0];
|
|
1000
|
+
if (!binRel) return null;
|
|
1001
|
+
return path2.join(path2.dirname(pkgJsonPath), binRel);
|
|
1002
|
+
} catch {
|
|
1003
|
+
return null;
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
function resolveExecutable(command) {
|
|
1007
|
+
if (resolvesOnPath(command)) return command;
|
|
1008
|
+
return resolveBridgeBinary(command);
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
// src/utils/abort.ts
|
|
1012
|
+
var ABORT_ERROR_NAME = "AbortError";
|
|
1013
|
+
function abortError(message = "Operation aborted") {
|
|
1014
|
+
const err = new Error(message);
|
|
1015
|
+
err.name = ABORT_ERROR_NAME;
|
|
1016
|
+
return err;
|
|
1017
|
+
}
|
|
1018
|
+
function isAbortError(err) {
|
|
1019
|
+
return err instanceof Error && err.name === ABORT_ERROR_NAME;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
// src/runtime/RuntimeBase.ts
|
|
1023
|
+
var RuntimeBase = class {
|
|
1024
|
+
};
|
|
1025
|
+
|
|
1026
|
+
// src/runtime/AcpRuntime.ts
|
|
1027
|
+
var discoveredModels = /* @__PURE__ */ new Map();
|
|
1028
|
+
var KILL_ESCALATION_MS = 3e3;
|
|
1029
|
+
var CANCEL_GRACE_MS = 2e3;
|
|
1030
|
+
var DEFAULT_COMMAND2 = "opencode";
|
|
1031
|
+
var DEFAULT_ARGS = ["acp"];
|
|
1032
|
+
var BASE_CAPABILITIES = {
|
|
1033
|
+
streaming: true,
|
|
1034
|
+
sessions: true,
|
|
1035
|
+
resume: true,
|
|
1036
|
+
permissions: true,
|
|
1037
|
+
tools: true,
|
|
1038
|
+
models: false,
|
|
1039
|
+
images: false,
|
|
1040
|
+
usage: true,
|
|
1041
|
+
cost: true,
|
|
1042
|
+
sandbox: false
|
|
1043
|
+
};
|
|
1044
|
+
function isRecord(value) {
|
|
1045
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1046
|
+
}
|
|
1047
|
+
function textOf(content) {
|
|
1048
|
+
if (isRecord(content) && content.type === "text" && typeof content.text === "string") {
|
|
1049
|
+
return content.text;
|
|
1050
|
+
}
|
|
1051
|
+
return void 0;
|
|
1052
|
+
}
|
|
1053
|
+
function stringifyOutput(value) {
|
|
1054
|
+
if (typeof value === "string") return value;
|
|
1055
|
+
if (value === void 0 || value === null) return "";
|
|
1056
|
+
return JSON.stringify(value);
|
|
1057
|
+
}
|
|
1058
|
+
function mapStopReason(reason) {
|
|
1059
|
+
switch (reason) {
|
|
1060
|
+
case "end_turn":
|
|
1061
|
+
return "success";
|
|
1062
|
+
case "cancelled":
|
|
1063
|
+
return "cancelled";
|
|
1064
|
+
case "max_tokens":
|
|
1065
|
+
case "max_turn_requests":
|
|
1066
|
+
return "max_turns";
|
|
1067
|
+
default:
|
|
1068
|
+
return "error";
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
var KIND_TO_TOOLS = {
|
|
1072
|
+
read: ["Read"],
|
|
1073
|
+
edit: ["Edit", "Write"],
|
|
1074
|
+
execute: ["Bash"],
|
|
1075
|
+
search: ["Grep", "Glob"],
|
|
1076
|
+
fetch: ["WebFetch"]
|
|
1077
|
+
};
|
|
1078
|
+
function decidePermission(params, tools, sessionId) {
|
|
1079
|
+
if (sessionId !== void 0 && params.sessionId !== sessionId) {
|
|
1080
|
+
return { response: { outcome: { outcome: "cancelled" } } };
|
|
1081
|
+
}
|
|
1082
|
+
const allowed = new Set(tools.map((tool) => tool.toLowerCase()));
|
|
1083
|
+
const name = params.toolCall.name ?? void 0;
|
|
1084
|
+
const kind = params.toolCall.kind ?? void 0;
|
|
1085
|
+
const approved = name !== void 0 ? allowed.has(name.toLowerCase()) : (KIND_TO_TOOLS[kind ?? ""] ?? []).some((candidate) => allowed.has(candidate.toLowerCase()));
|
|
1086
|
+
const option = approved ? params.options.find((o) => o.kind === "allow_always") ?? params.options.find((o) => o.kind === "allow_once") : params.options.find((o) => o.kind === "reject_always") ?? params.options.find((o) => o.kind === "reject_once");
|
|
1087
|
+
const response = option ? { outcome: { outcome: "selected", optionId: option.optionId } } : { outcome: { outcome: "cancelled" } };
|
|
1088
|
+
if (approved) return { response };
|
|
1089
|
+
return {
|
|
1090
|
+
response,
|
|
1091
|
+
rejected: {
|
|
1092
|
+
toolCallId: params.toolCall.toolCallId,
|
|
1093
|
+
name,
|
|
1094
|
+
kind,
|
|
1095
|
+
title: params.toolCall.title ?? void 0
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
function withAuthHint(acp, err) {
|
|
1100
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
1101
|
+
if (error instanceof acp.RequestError && error.code === acp.RequestError.authRequired().code) {
|
|
1102
|
+
return new Error(`${error.message} \u2014 run \`claude\` to log in`);
|
|
1103
|
+
}
|
|
1104
|
+
return error;
|
|
1105
|
+
}
|
|
1106
|
+
var AcpRuntime = class extends RuntimeBase {
|
|
1107
|
+
constructor() {
|
|
1108
|
+
super(...arguments);
|
|
1109
|
+
this.name = "acp";
|
|
1110
|
+
}
|
|
1111
|
+
async describe(options) {
|
|
1112
|
+
const command = options?.command ?? DEFAULT_COMMAND2;
|
|
1113
|
+
return {
|
|
1114
|
+
name: this.name,
|
|
1115
|
+
available: resolveExecutable(command) !== null,
|
|
1116
|
+
// `tools` is the one capability that depends on the bridge: only some of
|
|
1117
|
+
// them read an allowlist out of `_meta`, and none negotiates it. Claiming
|
|
1118
|
+
// it for a bridge that ignores `task.tools` would let a caller believe a
|
|
1119
|
+
// restriction landed when the agent is running unrestricted.
|
|
1120
|
+
capabilities: {
|
|
1121
|
+
...BASE_CAPABILITIES,
|
|
1122
|
+
tools: specForCommand(command)?.tools ?? false,
|
|
1123
|
+
models: (specForCommand(command)?.modelSelection ?? "none") !== "none"
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
}
|
|
1127
|
+
async execute(task) {
|
|
1128
|
+
const acp = await import("@agentclientprotocol/sdk");
|
|
1129
|
+
const command = task.command ?? DEFAULT_COMMAND2;
|
|
1130
|
+
const args = task.args ?? DEFAULT_ARGS;
|
|
1131
|
+
const exe = resolveExecutable(command) ?? command;
|
|
1132
|
+
const spec = specForCommand(command);
|
|
1133
|
+
const meta = spec?.meta?.(task);
|
|
1134
|
+
const promptText = meta === void 0 && task.systemPrompt ? `${task.systemPrompt}
|
|
1135
|
+
|
|
1136
|
+
---
|
|
1137
|
+
|
|
1138
|
+
${task.prompt}` : task.prompt;
|
|
1139
|
+
return new Promise((resolve4, reject) => {
|
|
1140
|
+
const child = spawn(exe, args, {
|
|
1141
|
+
cwd: task.workDir,
|
|
1142
|
+
env: process.env,
|
|
1143
|
+
// Own process group, so a kill reaches whatever the agent spawned too.
|
|
1144
|
+
detached: true
|
|
1145
|
+
});
|
|
1146
|
+
const signalChild = (signal) => {
|
|
1147
|
+
try {
|
|
1148
|
+
child.kill(signal);
|
|
1149
|
+
} catch {
|
|
1150
|
+
}
|
|
1151
|
+
};
|
|
1152
|
+
const killTree = (signal) => {
|
|
1153
|
+
if (child.pid === void 0) {
|
|
1154
|
+
signalChild(signal);
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
1157
|
+
try {
|
|
1158
|
+
process.kill(-child.pid, signal);
|
|
1159
|
+
} catch {
|
|
1160
|
+
signalChild(signal);
|
|
1161
|
+
}
|
|
1162
|
+
};
|
|
1163
|
+
let stopped = false;
|
|
1164
|
+
let escalation;
|
|
1165
|
+
const stop = (signal) => {
|
|
1166
|
+
if (stopped) return;
|
|
1167
|
+
stopped = true;
|
|
1168
|
+
killTree(signal);
|
|
1169
|
+
escalation = setTimeout(() => killTree("SIGKILL"), KILL_ESCALATION_MS);
|
|
1170
|
+
escalation.unref();
|
|
1171
|
+
};
|
|
1172
|
+
let timedOut = false;
|
|
1173
|
+
const timer = task.timeout === void 0 ? void 0 : setTimeout(() => {
|
|
1174
|
+
timedOut = true;
|
|
1175
|
+
stop("SIGTERM");
|
|
1176
|
+
}, task.timeout);
|
|
1177
|
+
let cancelGrace;
|
|
1178
|
+
const clearTimers = () => {
|
|
1179
|
+
if (timer) clearTimeout(timer);
|
|
1180
|
+
if (escalation) clearTimeout(escalation);
|
|
1181
|
+
if (cancelGrace) clearTimeout(cancelGrace);
|
|
1182
|
+
};
|
|
1183
|
+
const runId = randomUUID();
|
|
1184
|
+
let seq = 0;
|
|
1185
|
+
const emit = (event) => {
|
|
1186
|
+
task.onEvent?.({ ...event, runId, agentId: task.agentId, seq: seq++ });
|
|
1187
|
+
};
|
|
1188
|
+
let sessionId;
|
|
1189
|
+
let agentText = "";
|
|
1190
|
+
let errorOutput = "";
|
|
1191
|
+
let connectionError;
|
|
1192
|
+
let settled = false;
|
|
1193
|
+
let lastUsage;
|
|
1194
|
+
let lastCost;
|
|
1195
|
+
const settleResolve = (output) => {
|
|
1196
|
+
if (settled) return;
|
|
1197
|
+
settled = true;
|
|
1198
|
+
clearTimers();
|
|
1199
|
+
resolve4(output);
|
|
1200
|
+
};
|
|
1201
|
+
const settleReject = (error) => {
|
|
1202
|
+
if (settled) return;
|
|
1203
|
+
settled = true;
|
|
1204
|
+
clearTimers();
|
|
1205
|
+
reject(error);
|
|
1206
|
+
};
|
|
1207
|
+
const handleUpdate = (notification) => {
|
|
1208
|
+
if (sessionId && notification.sessionId !== sessionId) return;
|
|
1209
|
+
const update = notification.update;
|
|
1210
|
+
switch (update.sessionUpdate) {
|
|
1211
|
+
case "agent_message_chunk": {
|
|
1212
|
+
const text = textOf(update.content);
|
|
1213
|
+
if (text === void 0) {
|
|
1214
|
+
emit({ type: "raw", vendor: "acp", payload: update });
|
|
1215
|
+
break;
|
|
1216
|
+
}
|
|
1217
|
+
agentText += text;
|
|
1218
|
+
emit({ type: "message_delta", role: "agent", text });
|
|
1219
|
+
break;
|
|
1220
|
+
}
|
|
1221
|
+
case "user_message_chunk": {
|
|
1222
|
+
const text = textOf(update.content);
|
|
1223
|
+
if (text === void 0) {
|
|
1224
|
+
emit({ type: "raw", vendor: "acp", payload: update });
|
|
1225
|
+
break;
|
|
1226
|
+
}
|
|
1227
|
+
emit({ type: "message_delta", role: "user", text });
|
|
1228
|
+
break;
|
|
1229
|
+
}
|
|
1230
|
+
case "agent_thought_chunk": {
|
|
1231
|
+
const text = textOf(update.content);
|
|
1232
|
+
if (text === void 0) {
|
|
1233
|
+
emit({ type: "raw", vendor: "acp", payload: update });
|
|
1234
|
+
break;
|
|
1235
|
+
}
|
|
1236
|
+
emit({ type: "message_delta", role: "thought", text });
|
|
1237
|
+
break;
|
|
1238
|
+
}
|
|
1239
|
+
case "tool_call": {
|
|
1240
|
+
emit({
|
|
1241
|
+
type: "tool_call",
|
|
1242
|
+
id: update.toolCallId,
|
|
1243
|
+
name: update.name ?? update.title,
|
|
1244
|
+
input: update.rawInput
|
|
1245
|
+
});
|
|
1246
|
+
break;
|
|
1247
|
+
}
|
|
1248
|
+
case "tool_call_update": {
|
|
1249
|
+
emit({
|
|
1250
|
+
type: "tool_result",
|
|
1251
|
+
id: update.toolCallId,
|
|
1252
|
+
output: stringifyOutput(update.rawOutput ?? update.content),
|
|
1253
|
+
isError: update.status === "failed"
|
|
1254
|
+
});
|
|
1255
|
+
break;
|
|
1256
|
+
}
|
|
1257
|
+
case "plan": {
|
|
1258
|
+
emit({ type: "plan", entries: update.entries.map((entry2) => entry2.content) });
|
|
1259
|
+
break;
|
|
1260
|
+
}
|
|
1261
|
+
case "usage_update": {
|
|
1262
|
+
const contextTokens = typeof update.used === "number" ? update.used : void 0;
|
|
1263
|
+
const contextSize = typeof update.size === "number" ? update.size : void 0;
|
|
1264
|
+
if (contextTokens !== void 0 && contextSize !== void 0) {
|
|
1265
|
+
lastUsage = { contextTokens, contextSize };
|
|
1266
|
+
emit({ type: "usage", contextTokens, contextSize });
|
|
1267
|
+
}
|
|
1268
|
+
const cost = isRecord(update.cost) ? update.cost : void 0;
|
|
1269
|
+
const amount = typeof cost?.amount === "number" ? cost.amount : void 0;
|
|
1270
|
+
const currency = typeof cost?.currency === "string" ? cost.currency : void 0;
|
|
1271
|
+
if (amount !== void 0 && currency !== void 0) {
|
|
1272
|
+
lastCost = { amount, currency };
|
|
1273
|
+
const costUsd = currency.toLowerCase() === "usd" ? amount : void 0;
|
|
1274
|
+
emit({
|
|
1275
|
+
type: "cost",
|
|
1276
|
+
amount,
|
|
1277
|
+
currency,
|
|
1278
|
+
...costUsd !== void 0 ? { costUsd } : {}
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
break;
|
|
1282
|
+
}
|
|
1283
|
+
default:
|
|
1284
|
+
emit({ type: "raw", vendor: "acp", payload: update });
|
|
1285
|
+
}
|
|
1286
|
+
};
|
|
1287
|
+
const app = acp.client({ name: "multiclaw" });
|
|
1288
|
+
app.onNotification(acp.methods.client.session.update, (nctx) => {
|
|
1289
|
+
handleUpdate(nctx.params);
|
|
1290
|
+
});
|
|
1291
|
+
app.onRequest(acp.methods.client.session.requestPermission, (rctx) => {
|
|
1292
|
+
const { response, rejected } = decidePermission(rctx.params, task.tools, sessionId);
|
|
1293
|
+
if (rejected) {
|
|
1294
|
+
emit({
|
|
1295
|
+
type: "raw",
|
|
1296
|
+
vendor: "acp",
|
|
1297
|
+
payload: { type: "permission_rejected", ...rejected }
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
return response;
|
|
1301
|
+
});
|
|
1302
|
+
const stderrDecoder = new StringDecoder("utf8");
|
|
1303
|
+
child.stderr.on("data", (d) => {
|
|
1304
|
+
errorOutput += stderrDecoder.write(d);
|
|
1305
|
+
});
|
|
1306
|
+
const stream = acp.ndJsonStream(
|
|
1307
|
+
Writable.toWeb(child.stdin),
|
|
1308
|
+
Readable.toWeb(child.stdout)
|
|
1309
|
+
);
|
|
1310
|
+
const connection = app.connect(stream);
|
|
1311
|
+
const ctx = connection.agent;
|
|
1312
|
+
const teardown = () => {
|
|
1313
|
+
try {
|
|
1314
|
+
connection.close();
|
|
1315
|
+
} catch {
|
|
1316
|
+
}
|
|
1317
|
+
stop("SIGTERM");
|
|
1318
|
+
};
|
|
1319
|
+
task.signal?.addEventListener(
|
|
1320
|
+
"abort",
|
|
1321
|
+
() => {
|
|
1322
|
+
if (sessionId) {
|
|
1323
|
+
void ctx.notify(acp.methods.agent.session.cancel, { sessionId }).catch(() => {
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1326
|
+
cancelGrace = setTimeout(() => stop("SIGTERM"), CANCEL_GRACE_MS);
|
|
1327
|
+
cancelGrace.unref();
|
|
1328
|
+
},
|
|
1329
|
+
{ once: true }
|
|
1330
|
+
);
|
|
1331
|
+
child.on("close", (code) => {
|
|
1332
|
+
errorOutput += stderrDecoder.end();
|
|
1333
|
+
if (settled) return;
|
|
1334
|
+
if (task.signal?.aborted) {
|
|
1335
|
+
settleReject(abortError());
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
1338
|
+
if (timedOut) {
|
|
1339
|
+
settleReject(new Error(`acp timed out (${task.timeout}ms)`));
|
|
1340
|
+
return;
|
|
1341
|
+
}
|
|
1342
|
+
if (connectionError) {
|
|
1343
|
+
settleReject(connectionError);
|
|
1344
|
+
return;
|
|
1345
|
+
}
|
|
1346
|
+
settleReject(new Error(`${command} exited with code ${code}: ${errorOutput}`));
|
|
1347
|
+
});
|
|
1348
|
+
child.on("error", (err) => {
|
|
1349
|
+
settleReject(new Error(`Failed to start ${command}: ${err.message}`));
|
|
1350
|
+
});
|
|
1351
|
+
const run = async () => {
|
|
1352
|
+
const init = await ctx.request(acp.methods.agent.initialize, {
|
|
1353
|
+
protocolVersion: acp.PROTOCOL_VERSION
|
|
1354
|
+
});
|
|
1355
|
+
emit({ type: "run_started", model: task.model });
|
|
1356
|
+
if (task.sessionId) {
|
|
1357
|
+
if (init.agentCapabilities?.loadSession !== true) {
|
|
1358
|
+
throw new Error(
|
|
1359
|
+
`Agent does not support session/load (loadSession=false); cannot resume session ${task.sessionId}`
|
|
1360
|
+
);
|
|
1361
|
+
}
|
|
1362
|
+
await ctx.request(acp.methods.agent.session.load, {
|
|
1363
|
+
sessionId: task.sessionId,
|
|
1364
|
+
cwd: task.workDir,
|
|
1365
|
+
mcpServers: [],
|
|
1366
|
+
// Both session-defining requests carry `_meta`: the bridge's own
|
|
1367
|
+
// session fingerprint includes it, so a changed prompt rebuilds the
|
|
1368
|
+
// session on resume.
|
|
1369
|
+
...meta ? { _meta: meta } : {}
|
|
1370
|
+
});
|
|
1371
|
+
sessionId = task.sessionId;
|
|
1372
|
+
} else {
|
|
1373
|
+
const created = await ctx.request(acp.methods.agent.session.new, {
|
|
1374
|
+
cwd: task.workDir,
|
|
1375
|
+
mcpServers: [],
|
|
1376
|
+
...meta ? { _meta: meta } : {}
|
|
1377
|
+
});
|
|
1378
|
+
sessionId = created.sessionId;
|
|
1379
|
+
const modelOpt = created.configOptions?.find(
|
|
1380
|
+
(o) => o.category === "model" || o.id === "model"
|
|
1381
|
+
);
|
|
1382
|
+
if (modelOpt && "options" in modelOpt && Array.isArray(modelOpt.options)) {
|
|
1383
|
+
const ids = (modelOpt.options ?? []).map(
|
|
1384
|
+
(o) => o.value ?? String(o)
|
|
1385
|
+
);
|
|
1386
|
+
discoveredModels.set(command, ids);
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
if (task.model && spec?.modelSelection === "config-option" && sessionId) {
|
|
1390
|
+
const known = discoveredModels.get(command);
|
|
1391
|
+
if (known && !known.includes(task.model)) {
|
|
1392
|
+
process.stderr.write(
|
|
1393
|
+
`[multiclaw] Warning: model "${task.model}" is not offered by ${command}; running with provider default.
|
|
1394
|
+
`
|
|
1395
|
+
);
|
|
1396
|
+
} else {
|
|
1397
|
+
try {
|
|
1398
|
+
await ctx.request(acp.methods.agent.session.setConfigOption, {
|
|
1399
|
+
sessionId,
|
|
1400
|
+
configId: "model",
|
|
1401
|
+
value: task.model
|
|
1402
|
+
});
|
|
1403
|
+
} catch {
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
const response = await ctx.request(acp.methods.agent.session.prompt, {
|
|
1408
|
+
sessionId,
|
|
1409
|
+
prompt: [{ type: "text", text: promptText }]
|
|
1410
|
+
});
|
|
1411
|
+
if (task.signal?.aborted) {
|
|
1412
|
+
settleReject(abortError());
|
|
1413
|
+
teardown();
|
|
1414
|
+
return;
|
|
1415
|
+
}
|
|
1416
|
+
const stopReason = mapStopReason(response.stopReason);
|
|
1417
|
+
emit({ type: "run_finished", stopReason });
|
|
1418
|
+
settleResolve({
|
|
1419
|
+
output: agentText,
|
|
1420
|
+
exitCode: 0,
|
|
1421
|
+
sessionId,
|
|
1422
|
+
stopReason,
|
|
1423
|
+
...lastUsage ? { usage: lastUsage } : {},
|
|
1424
|
+
...lastCost?.currency.toLowerCase() === "usd" ? { costUsd: lastCost.amount } : {}
|
|
1425
|
+
});
|
|
1426
|
+
teardown();
|
|
1427
|
+
};
|
|
1428
|
+
void run().catch((err) => {
|
|
1429
|
+
connectionError = withAuthHint(acp, err);
|
|
1430
|
+
settleReject(connectionError);
|
|
1431
|
+
teardown();
|
|
1432
|
+
});
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
};
|
|
1436
|
+
|
|
1437
|
+
// src/runtime/index.ts
|
|
1438
|
+
var RuntimeRegistry = class {
|
|
1439
|
+
constructor() {
|
|
1440
|
+
this.runtimes = /* @__PURE__ */ new Map();
|
|
1441
|
+
this.register(new AcpRuntime());
|
|
1442
|
+
}
|
|
1443
|
+
register(r) {
|
|
1444
|
+
this.runtimes.set(r.name, r);
|
|
1445
|
+
}
|
|
1446
|
+
get(name) {
|
|
1447
|
+
const r = this.runtimes.get(name);
|
|
1448
|
+
if (!r)
|
|
1449
|
+
throw new Error(
|
|
1450
|
+
`Runtime not found: "${name}". Available: ${[...this.runtimes.keys()].join(", ")}`
|
|
1451
|
+
);
|
|
1452
|
+
return r;
|
|
1453
|
+
}
|
|
1454
|
+
has(name) {
|
|
1455
|
+
return this.runtimes.has(name);
|
|
1456
|
+
}
|
|
1457
|
+
list() {
|
|
1458
|
+
return [...this.runtimes.keys()];
|
|
1459
|
+
}
|
|
1460
|
+
};
|
|
1461
|
+
var runtimeRegistry = new RuntimeRegistry();
|
|
1462
|
+
|
|
1463
|
+
// src/utils/prompt.ts
|
|
1464
|
+
import * as fs2 from "fs/promises";
|
|
1465
|
+
import * as path3 from "path";
|
|
1466
|
+
function resolveInWorkspace(workDir, reference) {
|
|
1467
|
+
const root = path3.resolve(workDir);
|
|
1468
|
+
const resolved = path3.resolve(root, reference);
|
|
1469
|
+
if (resolved !== root && !resolved.startsWith(root + path3.sep)) return void 0;
|
|
1470
|
+
return resolved;
|
|
1471
|
+
}
|
|
1472
|
+
async function renderPrompt(template, context, workDir) {
|
|
1473
|
+
let result = template;
|
|
1474
|
+
const fileMatches = [...template.matchAll(/\{\{file:([^}]+)\}\}/g)];
|
|
1475
|
+
for (const match of fileMatches) {
|
|
1476
|
+
const filePath = resolveInWorkspace(workDir, match[1].trim());
|
|
1477
|
+
if (!filePath) {
|
|
1478
|
+
result = result.replace(match[0], () => `[file outside workspace: ${match[1].trim()}]`);
|
|
1479
|
+
continue;
|
|
1480
|
+
}
|
|
1481
|
+
try {
|
|
1482
|
+
const content = await fs2.readFile(filePath, "utf-8");
|
|
1483
|
+
result = result.replace(match[0], () => content);
|
|
1484
|
+
} catch {
|
|
1485
|
+
result = result.replace(match[0], () => `[file not found: ${match[1]}]`);
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
for (const [key, value] of Object.entries(context)) {
|
|
1489
|
+
result = result.replaceAll(`{{${key}}}`, () => value);
|
|
1490
|
+
}
|
|
1491
|
+
return result;
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
// src/utils/retry.ts
|
|
1495
|
+
function sleep(ms, signal) {
|
|
1496
|
+
if (signal?.aborted) return Promise.reject(abortError());
|
|
1497
|
+
return new Promise((resolve4, reject) => {
|
|
1498
|
+
const onAbort = () => {
|
|
1499
|
+
clearTimeout(timer);
|
|
1500
|
+
reject(abortError());
|
|
1501
|
+
};
|
|
1502
|
+
const timer = setTimeout(() => {
|
|
1503
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1504
|
+
resolve4();
|
|
1505
|
+
}, ms);
|
|
1506
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1507
|
+
});
|
|
1508
|
+
}
|
|
1509
|
+
async function withRetry(fn, retries, onRetry, delayMs = 2e3, signal) {
|
|
1510
|
+
let lastError = new Error("Unknown error");
|
|
1511
|
+
for (let attempt = 1; attempt <= retries + 1; attempt++) {
|
|
1512
|
+
if (signal?.aborted) throw abortError();
|
|
1513
|
+
try {
|
|
1514
|
+
return await fn(attempt);
|
|
1515
|
+
} catch (err) {
|
|
1516
|
+
lastError = err;
|
|
1517
|
+
if (signal?.aborted) throw lastError;
|
|
1518
|
+
if (attempt <= retries) {
|
|
1519
|
+
onRetry?.(attempt, err);
|
|
1520
|
+
await sleep(delayMs * attempt, signal);
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
throw lastError;
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
// src/utils/timeout.ts
|
|
1528
|
+
function withTimeout(factory, ms, label, signal) {
|
|
1529
|
+
if (signal?.aborted) return Promise.reject(abortError());
|
|
1530
|
+
const controller = new AbortController();
|
|
1531
|
+
const forward = () => controller.abort();
|
|
1532
|
+
signal?.addEventListener("abort", forward, { once: true });
|
|
1533
|
+
let timer;
|
|
1534
|
+
const timeout = new Promise((_, reject) => {
|
|
1535
|
+
timer = setTimeout(() => {
|
|
1536
|
+
controller.abort();
|
|
1537
|
+
reject(new Error(`[${label}] timed out (${ms / 1e3}s)`));
|
|
1538
|
+
}, ms);
|
|
1539
|
+
});
|
|
1540
|
+
let onCancel;
|
|
1541
|
+
const cancelled = new Promise((_, reject) => {
|
|
1542
|
+
if (!signal) return;
|
|
1543
|
+
onCancel = () => reject(abortError());
|
|
1544
|
+
signal.addEventListener("abort", onCancel, { once: true });
|
|
1545
|
+
});
|
|
1546
|
+
return Promise.race([factory(controller.signal), timeout, cancelled]).finally(() => {
|
|
1547
|
+
clearTimeout(timer);
|
|
1548
|
+
signal?.removeEventListener("abort", forward);
|
|
1549
|
+
if (onCancel) signal?.removeEventListener("abort", onCancel);
|
|
1550
|
+
});
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
// src/orchestrator/AgentRunner.ts
|
|
1554
|
+
var AgentRunner = class {
|
|
1555
|
+
constructor(eventBus, contextManager, globalWorkDir, config) {
|
|
1556
|
+
this.eventBus = eventBus;
|
|
1557
|
+
this.contextManager = contextManager;
|
|
1558
|
+
this.globalWorkDir = globalWorkDir;
|
|
1559
|
+
this.config = config;
|
|
1560
|
+
}
|
|
1561
|
+
async run(agent, signal) {
|
|
1562
|
+
const startTime = /* @__PURE__ */ new Date();
|
|
1563
|
+
const model = resolveModel(agent, this.config);
|
|
1564
|
+
this.eventBus.emit({
|
|
1565
|
+
type: "agent:start",
|
|
1566
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1567
|
+
payload: {
|
|
1568
|
+
agentId: agent.id,
|
|
1569
|
+
agentName: agent.name,
|
|
1570
|
+
icon: agent.icon,
|
|
1571
|
+
model,
|
|
1572
|
+
taskTitle: agent.taskTitle
|
|
1573
|
+
}
|
|
1574
|
+
});
|
|
1575
|
+
let attempts = 0;
|
|
1576
|
+
let output = "";
|
|
1577
|
+
try {
|
|
1578
|
+
const workDir = agent.workDir ? path4.resolve(this.globalWorkDir, agent.workDir) : this.globalWorkDir;
|
|
1579
|
+
fs3.mkdirSync(workDir, { recursive: true });
|
|
1580
|
+
const runtime = runtimeRegistry.get(agent.runtime ?? "acp");
|
|
1581
|
+
const retries = agent.retries ?? 0;
|
|
1582
|
+
const timeout = agent.timeout ?? 6e5;
|
|
1583
|
+
const tools = agent.tools ?? ["Read", "Write", "Bash"];
|
|
1584
|
+
output = await withTimeout(
|
|
1585
|
+
(innerSignal) => withRetry(
|
|
1586
|
+
async (attempt) => {
|
|
1587
|
+
attempts = attempt;
|
|
1588
|
+
const agentContext = {
|
|
1589
|
+
...this.contextManager.snapshot(),
|
|
1590
|
+
// Every built-in task template references both. The leader only
|
|
1591
|
+
// fills them in when the architect wrote a plan entry for this
|
|
1592
|
+
// agent, and the no-leader path has no plan at all — so without a
|
|
1593
|
+
// default the model is handed the literal text `{{agentScope}}`
|
|
1594
|
+
// and has to guess what it was supposed to say.
|
|
1595
|
+
agentScope: agent.agentScope ?? "Not narrowed down \u2014 cover the whole task.",
|
|
1596
|
+
agentPlan: agent.agentPlan ?? "No step-by-step plan was provided \u2014 use your judgement."
|
|
1597
|
+
};
|
|
1598
|
+
const prompt = await renderPrompt(agent.taskPrompt, agentContext, this.globalWorkDir);
|
|
1599
|
+
return (await runtime.execute({
|
|
1600
|
+
agentId: agent.id,
|
|
1601
|
+
systemPrompt: agent.systemPrompt,
|
|
1602
|
+
prompt,
|
|
1603
|
+
tools,
|
|
1604
|
+
workDir,
|
|
1605
|
+
timeout,
|
|
1606
|
+
signal: innerSignal,
|
|
1607
|
+
model,
|
|
1608
|
+
// Resolve through provider/defaults exactly as the CLI's
|
|
1609
|
+
// availability gate does — an agent that pins `provider` (or
|
|
1610
|
+
// leans on `defaults`) must launch that provider's bridge, not
|
|
1611
|
+
// the runtime's built-in default. Passing the raw `agent.command`
|
|
1612
|
+
// here sent a `provider: "claude"` config straight to `opencode`.
|
|
1613
|
+
command: resolveCommand(agent, this.config),
|
|
1614
|
+
args: resolveArgs(agent, this.config),
|
|
1615
|
+
onEvent: (e) => {
|
|
1616
|
+
if ((e.type === "message_delta" || e.type === "message") && e.role === "agent" && e.text) {
|
|
1617
|
+
this.eventBus.emit({
|
|
1618
|
+
type: "agent:output",
|
|
1619
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1620
|
+
payload: { agentId: agent.id, chunk: e.text }
|
|
1621
|
+
});
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
})).output;
|
|
1625
|
+
},
|
|
1626
|
+
retries,
|
|
1627
|
+
(attempt, err) => {
|
|
1628
|
+
this.eventBus.emit({
|
|
1629
|
+
type: "agent:retrying",
|
|
1630
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1631
|
+
payload: {
|
|
1632
|
+
agentId: agent.id,
|
|
1633
|
+
agentName: agent.name,
|
|
1634
|
+
attempt,
|
|
1635
|
+
maxAttempts: retries + 1,
|
|
1636
|
+
error: err.message
|
|
1637
|
+
}
|
|
1638
|
+
});
|
|
1639
|
+
},
|
|
1640
|
+
2e3,
|
|
1641
|
+
innerSignal
|
|
1642
|
+
),
|
|
1643
|
+
timeout,
|
|
1644
|
+
agent.name,
|
|
1645
|
+
signal
|
|
1646
|
+
);
|
|
1647
|
+
const endTime = /* @__PURE__ */ new Date();
|
|
1648
|
+
const result = {
|
|
1649
|
+
agentId: agent.id,
|
|
1650
|
+
agentName: agent.name,
|
|
1651
|
+
status: "success",
|
|
1652
|
+
output,
|
|
1653
|
+
duration: endTime.getTime() - startTime.getTime(),
|
|
1654
|
+
attempts,
|
|
1655
|
+
startTime: startTime.toISOString(),
|
|
1656
|
+
endTime: endTime.toISOString()
|
|
1657
|
+
};
|
|
1658
|
+
this.eventBus.emit({
|
|
1659
|
+
type: "agent:complete",
|
|
1660
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1661
|
+
payload: result
|
|
1662
|
+
});
|
|
1663
|
+
return result;
|
|
1664
|
+
} catch (err) {
|
|
1665
|
+
const endTime = /* @__PURE__ */ new Date();
|
|
1666
|
+
const result = {
|
|
1667
|
+
agentId: agent.id,
|
|
1668
|
+
agentName: agent.name,
|
|
1669
|
+
status: "failed",
|
|
1670
|
+
output,
|
|
1671
|
+
duration: endTime.getTime() - startTime.getTime(),
|
|
1672
|
+
attempts,
|
|
1673
|
+
error: err.message,
|
|
1674
|
+
startTime: startTime.toISOString(),
|
|
1675
|
+
endTime: endTime.toISOString()
|
|
1676
|
+
};
|
|
1677
|
+
this.eventBus.emit({
|
|
1678
|
+
type: "agent:failed",
|
|
1679
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1680
|
+
payload: result
|
|
1681
|
+
});
|
|
1682
|
+
return result;
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
};
|
|
1686
|
+
|
|
1687
|
+
// src/orchestrator/ContextManager.ts
|
|
1688
|
+
var ContextManager = class {
|
|
1689
|
+
constructor(initial) {
|
|
1690
|
+
this.store = /* @__PURE__ */ new Map();
|
|
1691
|
+
if (initial) for (const [k, v] of Object.entries(initial)) this.store.set(k, v);
|
|
1692
|
+
}
|
|
1693
|
+
set(key, value) {
|
|
1694
|
+
this.store.set(key, value);
|
|
1695
|
+
}
|
|
1696
|
+
get(key) {
|
|
1697
|
+
return this.store.get(key);
|
|
1698
|
+
}
|
|
1699
|
+
snapshot() {
|
|
1700
|
+
return Object.fromEntries(this.store.entries());
|
|
1701
|
+
}
|
|
1702
|
+
};
|
|
1703
|
+
|
|
1704
|
+
// src/orchestrator/StageBuilder.ts
|
|
1705
|
+
function buildStages(agents2) {
|
|
1706
|
+
const stages = [];
|
|
1707
|
+
const completed = /* @__PURE__ */ new Set();
|
|
1708
|
+
let remaining = [...agents2];
|
|
1709
|
+
const allIds = new Set(agents2.map((a) => a.id));
|
|
1710
|
+
for (const a of agents2) {
|
|
1711
|
+
for (const dep of a.dependsOn ?? []) {
|
|
1712
|
+
if (!allIds.has(dep)) {
|
|
1713
|
+
throw new Error(`Agent "${a.id}" depends on "${dep}" which does not exist`);
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
while (remaining.length > 0) {
|
|
1718
|
+
const stage = remaining.filter((a) => (a.dependsOn ?? []).every((dep) => completed.has(dep)));
|
|
1719
|
+
if (stage.length === 0) {
|
|
1720
|
+
const ids = remaining.map((a) => a.id).join(", ");
|
|
1721
|
+
throw new Error(`Circular or unsatisfiable dependency detected: ${ids}`);
|
|
1722
|
+
}
|
|
1723
|
+
stages.push(stage);
|
|
1724
|
+
for (const a of stage) completed.add(a.id);
|
|
1725
|
+
remaining = remaining.filter((a) => !stage.includes(a));
|
|
1726
|
+
}
|
|
1727
|
+
return stages;
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
// src/orchestrator/Orchestrator.ts
|
|
1731
|
+
var Orchestrator = class {
|
|
1732
|
+
constructor(config) {
|
|
1733
|
+
this.config = config;
|
|
1734
|
+
this.eventBus = new EventBus();
|
|
1735
|
+
this.workDir = path5.resolve(config.workDir);
|
|
1736
|
+
fs4.mkdirSync(this.workDir, { recursive: true });
|
|
1737
|
+
this.contextManager = new ContextManager(config.context);
|
|
1738
|
+
this.contextManager.set("conversation", renderConversation(config.history));
|
|
1739
|
+
this.runner = new AgentRunner(this.eventBus, this.contextManager, this.workDir, config);
|
|
1740
|
+
}
|
|
1741
|
+
async run(options = {}) {
|
|
1742
|
+
const startTime = /* @__PURE__ */ new Date();
|
|
1743
|
+
this.clearStaleTaskPlan();
|
|
1744
|
+
const resolution = await this.resolveTurn(options.signal);
|
|
1745
|
+
if (resolution.kind === "message") {
|
|
1746
|
+
return this.finishWithMessage(resolution.mode, resolution.message, startTime);
|
|
1747
|
+
}
|
|
1748
|
+
const agents2 = resolution.agents;
|
|
1749
|
+
if (agents2.length === 0) return this.finishEmpty(startTime);
|
|
1750
|
+
this.contextManager.set("pipelineAgents", agents2.map((a) => `${a.id}: ${a.name}`).join("\n"));
|
|
1751
|
+
let stages = this.buildStagesOrFallback(agents2, "Could not order the configured agents");
|
|
1752
|
+
const getModel = (agent) => {
|
|
1753
|
+
return agent.model ?? agent.models?.[agent.runtime ?? "acp"];
|
|
1754
|
+
};
|
|
1755
|
+
const toStageInfos = (list) => list.map((stage, i) => ({
|
|
1756
|
+
stageIndex: i,
|
|
1757
|
+
agents: stage.map((a) => ({
|
|
1758
|
+
id: a.id,
|
|
1759
|
+
name: a.name,
|
|
1760
|
+
icon: a.icon,
|
|
1761
|
+
model: getModel(a),
|
|
1762
|
+
description: a.description,
|
|
1763
|
+
taskTitle: a.taskTitle
|
|
1764
|
+
}))
|
|
1765
|
+
}));
|
|
1766
|
+
this.eventBus.emit({
|
|
1767
|
+
type: "orchestration:start",
|
|
1768
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1769
|
+
payload: {
|
|
1770
|
+
name: this.config.name,
|
|
1771
|
+
requirement: this.config.context?.requirement,
|
|
1772
|
+
totalAgents: agents2.length,
|
|
1773
|
+
stages: toStageInfos(stages)
|
|
1774
|
+
}
|
|
1775
|
+
});
|
|
1776
|
+
const results = [];
|
|
1777
|
+
let allSuccess = true;
|
|
1778
|
+
let cancelled = false;
|
|
1779
|
+
for (let i = 0; i < stages.length; i++) {
|
|
1780
|
+
const stage = stages[i];
|
|
1781
|
+
this.eventBus.emit({
|
|
1782
|
+
type: "stage:start",
|
|
1783
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1784
|
+
payload: { stageIndex: i, agentIds: stage.map((a) => a.id) }
|
|
1785
|
+
});
|
|
1786
|
+
const stageResults = await this.runStage(stage, options.signal);
|
|
1787
|
+
results.push(...stageResults);
|
|
1788
|
+
if (options.signal?.aborted) {
|
|
1789
|
+
cancelled = true;
|
|
1790
|
+
allSuccess = false;
|
|
1791
|
+
break;
|
|
1792
|
+
}
|
|
1793
|
+
if (i === 0 && stage.some((a) => a.id === "architect") && stageResults.some((r) => r.status === "success")) {
|
|
1794
|
+
await this.applyTaskPlan(agents2);
|
|
1795
|
+
stages = this.buildStagesOrFallback(
|
|
1796
|
+
agents2,
|
|
1797
|
+
"The task plan's dependencies could not be satisfied"
|
|
1798
|
+
);
|
|
1799
|
+
this.eventBus.emit({
|
|
1800
|
+
type: "orchestration:stages",
|
|
1801
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1802
|
+
payload: { totalAgents: agents2.length, stages: toStageInfos(stages) }
|
|
1803
|
+
});
|
|
1804
|
+
}
|
|
1805
|
+
for (const r of stageResults) {
|
|
1806
|
+
if (r.status !== "success") {
|
|
1807
|
+
allSuccess = false;
|
|
1808
|
+
if (!this.config.continueOnError) break;
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
this.eventBus.emit({
|
|
1812
|
+
type: "stage:complete",
|
|
1813
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1814
|
+
payload: { stageIndex: i }
|
|
1815
|
+
});
|
|
1816
|
+
if (!allSuccess && !this.config.continueOnError) {
|
|
1817
|
+
for (const remainingStage of stages.slice(i + 1)) {
|
|
1818
|
+
for (const agent of remainingStage) {
|
|
1819
|
+
this.eventBus.emit({
|
|
1820
|
+
type: "agent:skipped",
|
|
1821
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1822
|
+
payload: { agentId: agent.id, agentName: agent.name, icon: agent.icon }
|
|
1823
|
+
});
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
break;
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
const endTime = /* @__PURE__ */ new Date();
|
|
1830
|
+
const result = {
|
|
1831
|
+
name: this.config.name,
|
|
1832
|
+
success: allSuccess,
|
|
1833
|
+
totalDuration: endTime.getTime() - startTime.getTime(),
|
|
1834
|
+
agentResults: results,
|
|
1835
|
+
startTime: startTime.toISOString(),
|
|
1836
|
+
endTime: endTime.toISOString(),
|
|
1837
|
+
...cancelled ? { cancelled: true } : {}
|
|
1838
|
+
};
|
|
1839
|
+
this.eventBus.emit({
|
|
1840
|
+
type: "orchestration:complete",
|
|
1841
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1842
|
+
payload: result
|
|
1843
|
+
});
|
|
1844
|
+
return result;
|
|
1845
|
+
}
|
|
1846
|
+
/**
|
|
1847
|
+
* Order the agents into stages, degrading to declaration order if the graph is
|
|
1848
|
+
* broken.
|
|
1849
|
+
*
|
|
1850
|
+
* `buildStages` throws on a missing dependency and on a cycle. Letting that
|
|
1851
|
+
* escape would reject `run()` before `orchestration:complete` is emitted, so
|
|
1852
|
+
* the caller sees an unhandled rejection instead of a structured failure. A
|
|
1853
|
+
* bad ordering is not a reason to run nothing.
|
|
1854
|
+
*/
|
|
1855
|
+
buildStagesOrFallback(agents2, context) {
|
|
1856
|
+
try {
|
|
1857
|
+
return buildStages(agents2);
|
|
1858
|
+
} catch (err) {
|
|
1859
|
+
this.warn(`${context} (${errorMessage(err)}) \u2014 running the agents in declaration order.`);
|
|
1860
|
+
return [agents2];
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
/**
|
|
1864
|
+
* Drop last run's task plan before the architect gets a chance to write one.
|
|
1865
|
+
*
|
|
1866
|
+
* The console runs every turn against the same workspace, so the plan file
|
|
1867
|
+
* survives between turns. If a turn's architect fails to write a new one,
|
|
1868
|
+
* `applyTaskPlan` would silently re-apply the previous turn's titles, scopes
|
|
1869
|
+
* and dependencies to a completely different requirement.
|
|
1870
|
+
*/
|
|
1871
|
+
clearStaleTaskPlan() {
|
|
1872
|
+
fs4.rmSync(path5.join(this.workDir, "task-plan.json"), { force: true });
|
|
1873
|
+
}
|
|
1874
|
+
/**
|
|
1875
|
+
* Decide what this turn is: a pipeline, an answer, or a question.
|
|
1876
|
+
*
|
|
1877
|
+
* Only the leader can answer that, so without one the configured team is the
|
|
1878
|
+
* whole story. With one, its prose output is *not* a failure mode to be papered
|
|
1879
|
+
* over by running everybody — a leader that answers a greeting has done its
|
|
1880
|
+
* job, and that is what `message` records.
|
|
1881
|
+
*/
|
|
1882
|
+
async resolveTurn(signal) {
|
|
1883
|
+
if (!this.config.leader || this.config.useLeader === false) {
|
|
1884
|
+
return { kind: "run", agents: this.configuredAgents() };
|
|
1885
|
+
}
|
|
1886
|
+
this.contextManager.set(
|
|
1887
|
+
"availableAgents",
|
|
1888
|
+
this.config.agents.map((a) => `${a.id}: ${a.name}`).join("\n")
|
|
1889
|
+
);
|
|
1890
|
+
const result = await this.runner.run(this.config.leader, signal);
|
|
1891
|
+
if (result.status !== "success") {
|
|
1892
|
+
this.warn("The leader could not be reached \u2014 running the full configured team.");
|
|
1893
|
+
return { kind: "run", agents: this.configuredAgents() };
|
|
1894
|
+
}
|
|
1895
|
+
const decision = parseLeaderDecision(result.output);
|
|
1896
|
+
if (decision) {
|
|
1897
|
+
if (decision.mode !== "run") {
|
|
1898
|
+
return { kind: "message", mode: decision.mode, message: decision.message };
|
|
1899
|
+
}
|
|
1900
|
+
return { kind: "run", agents: this.selectAgents(decision.run) };
|
|
1901
|
+
}
|
|
1902
|
+
const message = result.output.trim();
|
|
1903
|
+
if (!message) {
|
|
1904
|
+
this.warn("The leader returned no output \u2014 running the full configured team.");
|
|
1905
|
+
return { kind: "run", agents: this.configuredAgents() };
|
|
1906
|
+
}
|
|
1907
|
+
return { kind: "message", mode: "reply", message };
|
|
1908
|
+
}
|
|
1909
|
+
/**
|
|
1910
|
+
* The configured team, as copies.
|
|
1911
|
+
*
|
|
1912
|
+
* `applyTaskPlan` writes `taskTitle` / `dependsOn` / `agentScope` onto whatever
|
|
1913
|
+
* objects it is handed. The console reuses a single config across turns, so
|
|
1914
|
+
* returning the config's own objects would leak turn 1's dependency graph into
|
|
1915
|
+
* turn 2 — the exact cross-turn contamination `clearStaleTaskPlan` exists to
|
|
1916
|
+
* prevent, but for the in-memory fields rather than the file.
|
|
1917
|
+
*/
|
|
1918
|
+
configuredAgents() {
|
|
1919
|
+
return this.config.agents.map((a) => ({ ...a }));
|
|
1920
|
+
}
|
|
1921
|
+
/**
|
|
1922
|
+
* Narrow the configured team to the ids the leader named.
|
|
1923
|
+
*
|
|
1924
|
+
* Always a subset: an id that is not in the config is reported and dropped
|
|
1925
|
+
* rather than added, so a typo in a prompt cannot conjure an agent that has no
|
|
1926
|
+
* definition behind it.
|
|
1927
|
+
*/
|
|
1928
|
+
selectAgents(run) {
|
|
1929
|
+
const runSet = new Set(run);
|
|
1930
|
+
const known = new Set(this.config.agents.map((a) => a.id));
|
|
1931
|
+
for (const id of run) {
|
|
1932
|
+
if (!known.has(id)) {
|
|
1933
|
+
this.warn(`The leader named "${id}", which is not in the config \u2014 ignoring it.`);
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
const skippedIds = new Set(this.config.agents.filter((a) => !runSet.has(a.id)).map((a) => a.id));
|
|
1937
|
+
for (const agent of this.config.agents.filter((a) => skippedIds.has(a.id))) {
|
|
1938
|
+
this.eventBus.emit({
|
|
1939
|
+
type: "agent:skipped",
|
|
1940
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1941
|
+
payload: { agentId: agent.id, agentName: agent.name, icon: agent.icon }
|
|
1942
|
+
});
|
|
1943
|
+
}
|
|
1944
|
+
return this.config.agents.filter((a) => runSet.has(a.id)).map((a) => ({
|
|
1945
|
+
...a,
|
|
1946
|
+
dependsOn: a.dependsOn?.filter((dep) => !skippedIds.has(dep))
|
|
1947
|
+
}));
|
|
1948
|
+
}
|
|
1949
|
+
async runStage(agents2, signal) {
|
|
1950
|
+
const { maxConcurrency } = this.config;
|
|
1951
|
+
if (!maxConcurrency || agents2.length <= maxConcurrency) {
|
|
1952
|
+
return Promise.all(agents2.map((a) => this.runner.run(a, signal)));
|
|
1953
|
+
}
|
|
1954
|
+
const results = [];
|
|
1955
|
+
for (let i = 0; i < agents2.length; i += maxConcurrency) {
|
|
1956
|
+
const batch = agents2.slice(i, i + maxConcurrency);
|
|
1957
|
+
results.push(...await Promise.all(batch.map((a) => this.runner.run(a, signal))));
|
|
1958
|
+
}
|
|
1959
|
+
return results;
|
|
1960
|
+
}
|
|
1961
|
+
async applyTaskPlan(agents2) {
|
|
1962
|
+
const taskPlanPath = path5.join(this.workDir, "task-plan.json");
|
|
1963
|
+
if (!fs4.existsSync(taskPlanPath)) return;
|
|
1964
|
+
let taskPlan;
|
|
1965
|
+
try {
|
|
1966
|
+
taskPlan = JSON.parse(fs4.readFileSync(taskPlanPath, "utf-8"));
|
|
1967
|
+
} catch (err) {
|
|
1968
|
+
this.warn(
|
|
1969
|
+
`Could not parse task-plan.json \u2014 continuing with the original agent set: ${errorMessage(err)}`
|
|
1970
|
+
);
|
|
1971
|
+
return;
|
|
1972
|
+
}
|
|
1973
|
+
if (!Array.isArray(taskPlan.tasks)) {
|
|
1974
|
+
this.warn("task-plan.json has no `tasks` array \u2014 ignoring it.");
|
|
1975
|
+
return;
|
|
1976
|
+
}
|
|
1977
|
+
const taskMap = new Map(taskPlan.tasks.map((t) => [t.id, t]));
|
|
1978
|
+
const selected = new Set(agents2.map((a) => a.id));
|
|
1979
|
+
for (const agent of agents2) {
|
|
1980
|
+
const task = taskMap.get(agent.id);
|
|
1981
|
+
if (task) {
|
|
1982
|
+
agent.taskTitle = task.title;
|
|
1983
|
+
const dependsOn = task.dependsOn?.filter((dep) => selected.has(dep));
|
|
1984
|
+
for (const dep of task.dependsOn ?? []) {
|
|
1985
|
+
if (!selected.has(dep)) {
|
|
1986
|
+
this.warn(
|
|
1987
|
+
`The task plan makes "${agent.id}" depend on "${dep}", which is not in this run \u2014 ignoring that dependency.`
|
|
1988
|
+
);
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
agent.dependsOn = dependsOn;
|
|
1992
|
+
agent.agentScope = task.scope;
|
|
1993
|
+
if (task.plan?.length) {
|
|
1994
|
+
agent.agentPlan = task.plan.map((s, i) => `${i + 1}. ${s}`).join("\n");
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
/**
|
|
2000
|
+
* Close out a turn the leader answered rather than planned.
|
|
2001
|
+
*
|
|
2002
|
+
* `success: true` on purpose: the user asked something and got an answer. What
|
|
2003
|
+
* keeps that from reading as a completed pipeline is `reply`, which the console
|
|
2004
|
+
* uses to say "answered" instead of "done".
|
|
2005
|
+
*/
|
|
2006
|
+
finishWithMessage(mode, message, startTime) {
|
|
2007
|
+
const endTime = /* @__PURE__ */ new Date();
|
|
2008
|
+
const result = {
|
|
2009
|
+
name: this.config.name,
|
|
2010
|
+
success: true,
|
|
2011
|
+
totalDuration: endTime.getTime() - startTime.getTime(),
|
|
2012
|
+
agentResults: [],
|
|
2013
|
+
startTime: startTime.toISOString(),
|
|
2014
|
+
endTime: endTime.toISOString(),
|
|
2015
|
+
reply: { mode, message }
|
|
2016
|
+
};
|
|
2017
|
+
this.eventBus.emit({
|
|
2018
|
+
type: "orchestration:complete",
|
|
2019
|
+
timestamp: endTime.toISOString(),
|
|
2020
|
+
payload: result
|
|
2021
|
+
});
|
|
2022
|
+
return result;
|
|
2023
|
+
}
|
|
2024
|
+
warn(message) {
|
|
2025
|
+
this.eventBus.emit({
|
|
2026
|
+
type: "orchestration:warning",
|
|
2027
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2028
|
+
payload: { message }
|
|
2029
|
+
});
|
|
2030
|
+
}
|
|
2031
|
+
/**
|
|
2032
|
+
* Close out a turn that scheduled no agents.
|
|
2033
|
+
*
|
|
2034
|
+
* Reported as a failure rather than a no-op: the user asked for work, and the
|
|
2035
|
+
* only honest outcome is to say that none was done. Running the whole team
|
|
2036
|
+
* instead would contradict the leader's explicit choice.
|
|
2037
|
+
*/
|
|
2038
|
+
finishEmpty(startTime) {
|
|
2039
|
+
const usedLeader = this.config.leader !== void 0 && this.config.useLeader !== false;
|
|
2040
|
+
this.warn(
|
|
2041
|
+
usedLeader ? "The leader selected none of the configured agents \u2014 nothing to run." : "The config lists no agents \u2014 nothing to run."
|
|
2042
|
+
);
|
|
2043
|
+
const endTime = /* @__PURE__ */ new Date();
|
|
2044
|
+
const result = {
|
|
2045
|
+
name: this.config.name,
|
|
2046
|
+
success: false,
|
|
2047
|
+
totalDuration: endTime.getTime() - startTime.getTime(),
|
|
2048
|
+
agentResults: [],
|
|
2049
|
+
startTime: startTime.toISOString(),
|
|
2050
|
+
endTime: endTime.toISOString()
|
|
2051
|
+
};
|
|
2052
|
+
this.eventBus.emit({
|
|
2053
|
+
type: "orchestration:complete",
|
|
2054
|
+
timestamp: endTime.toISOString(),
|
|
2055
|
+
payload: result
|
|
2056
|
+
});
|
|
2057
|
+
return result;
|
|
2058
|
+
}
|
|
2059
|
+
};
|
|
2060
|
+
function errorMessage(err) {
|
|
2061
|
+
return err instanceof Error ? err.message : String(err);
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
// src/providers/detect.ts
|
|
2065
|
+
import { spawn as spawn2 } from "child_process";
|
|
2066
|
+
async function versionFor(command) {
|
|
2067
|
+
return new Promise((resolve4) => {
|
|
2068
|
+
let out = "";
|
|
2069
|
+
const child = spawn2(command, ["--version"], { env: process.env });
|
|
2070
|
+
child.stdout.on("data", (d) => {
|
|
2071
|
+
out += d.toString();
|
|
2072
|
+
});
|
|
2073
|
+
child.on("close", () => {
|
|
2074
|
+
resolve4(out.trim() || void 0);
|
|
2075
|
+
});
|
|
2076
|
+
child.on("error", () => {
|
|
2077
|
+
resolve4(void 0);
|
|
2078
|
+
});
|
|
2079
|
+
setTimeout(() => {
|
|
2080
|
+
try {
|
|
2081
|
+
child.kill("SIGKILL");
|
|
2082
|
+
} catch {
|
|
2083
|
+
}
|
|
2084
|
+
resolve4(void 0);
|
|
2085
|
+
}, 3e3);
|
|
2086
|
+
});
|
|
2087
|
+
}
|
|
2088
|
+
async function detectProviders(opts) {
|
|
2089
|
+
const results = [];
|
|
2090
|
+
for (const spec of PROVIDERS) {
|
|
2091
|
+
const candidates = [spec.command, ...spec.aliases ?? []];
|
|
2092
|
+
let matched;
|
|
2093
|
+
let version;
|
|
2094
|
+
for (const cmd of candidates) {
|
|
2095
|
+
const exe = resolveExecutable(cmd);
|
|
2096
|
+
if (!exe) continue;
|
|
2097
|
+
if (spec.confirm) {
|
|
2098
|
+
if (opts?.withVersion) {
|
|
2099
|
+
const v = await versionFor(exe);
|
|
2100
|
+
if (v && spec.confirm(v)) {
|
|
2101
|
+
matched = cmd;
|
|
2102
|
+
version = v;
|
|
2103
|
+
break;
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
continue;
|
|
2107
|
+
}
|
|
2108
|
+
matched = cmd;
|
|
2109
|
+
if (opts?.withVersion) {
|
|
2110
|
+
version = await versionFor(exe);
|
|
2111
|
+
}
|
|
2112
|
+
break;
|
|
2113
|
+
}
|
|
2114
|
+
if (matched) {
|
|
2115
|
+
results.push({
|
|
2116
|
+
id: spec.id,
|
|
2117
|
+
label: spec.label,
|
|
2118
|
+
command: matched,
|
|
2119
|
+
status: "present",
|
|
2120
|
+
version,
|
|
2121
|
+
note: spec.auth.hint || void 0
|
|
2122
|
+
});
|
|
2123
|
+
} else {
|
|
2124
|
+
results.push({
|
|
2125
|
+
id: spec.id,
|
|
2126
|
+
label: spec.label,
|
|
2127
|
+
command: spec.command,
|
|
2128
|
+
status: "missing",
|
|
2129
|
+
note: spec.install.hint
|
|
2130
|
+
});
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
return results;
|
|
2134
|
+
}
|
|
2135
|
+
function presentProviders(detected) {
|
|
2136
|
+
return detected.filter((d) => d.status === "present").map((d) => d.id);
|
|
2137
|
+
}
|
|
1060
2138
|
export {
|
|
1061
|
-
|
|
2139
|
+
ABORT_ERROR_NAME,
|
|
2140
|
+
AcpRuntime,
|
|
2141
|
+
BRIDGE_PACKAGES,
|
|
1062
2142
|
EventBus,
|
|
1063
2143
|
Orchestrator,
|
|
2144
|
+
PROVIDERS,
|
|
1064
2145
|
RuntimeBase,
|
|
2146
|
+
abortError,
|
|
1065
2147
|
agents,
|
|
1066
2148
|
buildStages,
|
|
1067
2149
|
defineConfig,
|
|
1068
|
-
|
|
2150
|
+
detectProviders,
|
|
2151
|
+
isAbortError,
|
|
2152
|
+
presentProviders,
|
|
2153
|
+
providerCommands,
|
|
2154
|
+
providerIds,
|
|
2155
|
+
resolveAgentRuntime,
|
|
2156
|
+
resolveArgs,
|
|
2157
|
+
resolveBridgeBinary,
|
|
2158
|
+
resolveCommand,
|
|
2159
|
+
resolveExecutable,
|
|
2160
|
+
resolveModel,
|
|
2161
|
+
resolveProvider,
|
|
2162
|
+
resolvesOnPath,
|
|
2163
|
+
runtimeRegistry,
|
|
2164
|
+
specForCommand,
|
|
2165
|
+
specForProvider,
|
|
2166
|
+
tierModel
|
|
1069
2167
|
};
|