genaicode 2.20.0 → 2.22.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/README.md +1 -0
- package/dist/acp/server.d.ts +38 -0
- package/dist/acp/server.js +475 -0
- package/dist/acp/server.js.map +1 -0
- package/dist/app-agent/app-agent.d.ts +20 -4
- package/dist/app-agent/app-agent.js +31 -7
- package/dist/app-agent/app-agent.js.map +1 -1
- package/dist/app-agent/mcp.d.ts +11 -1
- package/dist/app-agent/mcp.js +12 -1
- package/dist/app-agent/mcp.js.map +1 -1
- package/dist/app-agent.d.ts +1 -1
- package/dist/cli/args.d.ts +6 -0
- package/dist/cli/args.js +19 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/main.d.ts +3 -1
- package/dist/cli/main.js +31 -0
- package/dist/cli/main.js.map +1 -1
- package/docs/CHANGELOG.md +16 -0
- package/docs/app-agent.md +73 -2
- package/docs/cli.md +19 -3
- package/docs/embedding.md +166 -0
- package/docs/skills/genaicode-embed/SKILL.md +80 -10
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -42,6 +42,7 @@ log in to (`npx genaicode agents` lists what it finds).
|
|
|
42
42
|
| A panel in your dev server | `genaicode/vite`, `createDevOverlay` | [vite.md](docs/vite.md) |
|
|
43
43
|
| A chat component | `genaicode/react` `<AgentChat>` | [react.md](docs/react.md) |
|
|
44
44
|
| An agent inside your own app | `genaicode/app-agent` | [app-agent.md](docs/app-agent.md) |
|
|
45
|
+
| Editors, desktop, game engines | `genaicode acp`, `genaicode/ui` | [embedding.md](docs/embedding.md) |
|
|
45
46
|
| A thin LLM layer | `genaicode`, `genaicode/providers` | [llm.md](docs/llm.md) |
|
|
46
47
|
|
|
47
48
|
```ts
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { AgentEvent, CodingAgent } from '../agents/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* `genaicode acp`: the agent side of the Agent Client Protocol (https://agentclientprotocol.com),
|
|
4
|
+
* version 1, over newline-delimited JSON-RPC. A host in any language (an editor, a game engine's
|
|
5
|
+
* editor, a native app) starts the process, opens sessions and sends prompts; each prompt is one
|
|
6
|
+
* run of the chosen agent CLI, and the agent's own session continues on the next prompt.
|
|
7
|
+
*
|
|
8
|
+
* The host picks the agent, its effort and the approval mode through session config options.
|
|
9
|
+
* Permission prompts reach the host as `session/request_permission`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const ACP_PROTOCOL_VERSION = 1;
|
|
12
|
+
export interface AcpServerOptions {
|
|
13
|
+
/** Agents to offer; only the installed ones are listed. */
|
|
14
|
+
agents: readonly CodingAgent[];
|
|
15
|
+
/** Agent new sessions start with. Default: the first installed one. */
|
|
16
|
+
agent?: string;
|
|
17
|
+
model?: string;
|
|
18
|
+
effort?: string;
|
|
19
|
+
/** Start sessions in auto-approve mode. */
|
|
20
|
+
approveAll?: boolean;
|
|
21
|
+
env?: NodeJS.ProcessEnv;
|
|
22
|
+
version: string;
|
|
23
|
+
input: NodeJS.ReadableStream;
|
|
24
|
+
output: {
|
|
25
|
+
write(chunk: string): unknown;
|
|
26
|
+
};
|
|
27
|
+
/** Ends the connection as if the host closed it: running prompts stop. */
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
}
|
|
30
|
+
/** Serve ACP until `input` ends. Resolves once every running prompt has stopped. */
|
|
31
|
+
export declare function serveAcp(options: AcpServerOptions): Promise<void>;
|
|
32
|
+
/** The prompt's content blocks as the text the agent CLI gets. */
|
|
33
|
+
export declare function promptText(blocks: unknown): string;
|
|
34
|
+
/**
|
|
35
|
+
* Turns the agent's events into ACP `session/update` values. Streamed text goes out as it comes;
|
|
36
|
+
* a final `message` adds only what the stream did not already show.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createEventMapper(): (event: AgentEvent) => Array<Record<string, unknown>>;
|
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { createInterface } from 'node:readline';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { detectAgents } from '../agents/discovery.js';
|
|
5
|
+
import { RpcError, RpcPeer } from '../agents/rpc.js';
|
|
6
|
+
/**
|
|
7
|
+
* `genaicode acp`: the agent side of the Agent Client Protocol (https://agentclientprotocol.com),
|
|
8
|
+
* version 1, over newline-delimited JSON-RPC. A host in any language (an editor, a game engine's
|
|
9
|
+
* editor, a native app) starts the process, opens sessions and sends prompts; each prompt is one
|
|
10
|
+
* run of the chosen agent CLI, and the agent's own session continues on the next prompt.
|
|
11
|
+
*
|
|
12
|
+
* The host picks the agent, its effort and the approval mode through session config options.
|
|
13
|
+
* Permission prompts reach the host as `session/request_permission`.
|
|
14
|
+
*/
|
|
15
|
+
export const ACP_PROTOCOL_VERSION = 1;
|
|
16
|
+
const NO_TIMEOUT = 2 ** 31 - 1;
|
|
17
|
+
/** Serve ACP until `input` ends. Resolves once every running prompt has stopped. */
|
|
18
|
+
export async function serveAcp(options) {
|
|
19
|
+
const env = options.env ?? process.env;
|
|
20
|
+
const installed = detectAgents(options.agents, env)
|
|
21
|
+
.filter(({ path }) => path)
|
|
22
|
+
.map(({ agent }) => agent);
|
|
23
|
+
const sessions = new Map();
|
|
24
|
+
const peer = new RpcPeer((line) => options.output.write(`${line}\n`), {
|
|
25
|
+
notification(method, params) {
|
|
26
|
+
if (method === 'session/cancel')
|
|
27
|
+
sessions.get(sessionIdOf(params))?.run?.abort();
|
|
28
|
+
},
|
|
29
|
+
request(method, params) {
|
|
30
|
+
switch (method) {
|
|
31
|
+
case 'initialize':
|
|
32
|
+
return initialize();
|
|
33
|
+
case 'session/new':
|
|
34
|
+
return newSession(params);
|
|
35
|
+
case 'session/set_config_option':
|
|
36
|
+
return setConfigOption(params);
|
|
37
|
+
case 'session/prompt':
|
|
38
|
+
return prompt(params);
|
|
39
|
+
case 'session/close': {
|
|
40
|
+
const session = takeSession(params);
|
|
41
|
+
session.run?.abort();
|
|
42
|
+
sessions.delete(session.id);
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
default:
|
|
46
|
+
throw new RpcError(`Method not found: ${method}`, -32601);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
function initialize() {
|
|
51
|
+
return {
|
|
52
|
+
protocolVersion: ACP_PROTOCOL_VERSION,
|
|
53
|
+
agentCapabilities: {
|
|
54
|
+
loadSession: false,
|
|
55
|
+
promptCapabilities: { image: false, audio: false, embeddedContext: true },
|
|
56
|
+
mcpCapabilities: { http: true, sse: false },
|
|
57
|
+
sessionCapabilities: { close: {} },
|
|
58
|
+
},
|
|
59
|
+
agentInfo: { name: 'genaicode', title: 'genaicode', version: options.version },
|
|
60
|
+
authMethods: [],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/** Agents that can run this session's prompts: with MCP servers, only drivers that attach them. */
|
|
64
|
+
function usable(mcpServers) {
|
|
65
|
+
return mcpServers.length > 0 ? installed.filter((agent) => agent.capabilities.mcp) : installed;
|
|
66
|
+
}
|
|
67
|
+
function newSession(params) {
|
|
68
|
+
if (typeof params?.cwd !== 'string' || params.cwd === '')
|
|
69
|
+
throw invalid('cwd is required.');
|
|
70
|
+
const names = new Set();
|
|
71
|
+
const mcpServers = (params.mcpServers ?? []).map((server) => toMcpServer(server, names));
|
|
72
|
+
const agents = usable(mcpServers);
|
|
73
|
+
const agent = options.agent ? installed.find((candidate) => candidate.name === options.agent) : agents[0];
|
|
74
|
+
if (!agent) {
|
|
75
|
+
throw new RpcError(options.agent
|
|
76
|
+
? `Agent "${options.agent}" is not installed.`
|
|
77
|
+
: installed.length > 0
|
|
78
|
+
? `None of the installed agents (${installed.map((a) => a.name).join(', ')}) supports MCP servers.`
|
|
79
|
+
: `No supported agent CLI found on PATH. Install one of: ${options.agents.map((a) => a.command).join(', ')}.`, -32603);
|
|
80
|
+
}
|
|
81
|
+
if (!agents.includes(agent))
|
|
82
|
+
throw invalid(`${agent.name} does not support MCP servers in genaicode.`);
|
|
83
|
+
const session = {
|
|
84
|
+
id: randomUUID(),
|
|
85
|
+
cwd: params.cwd,
|
|
86
|
+
mcpServers,
|
|
87
|
+
agent,
|
|
88
|
+
effort: effortFor(agent, options.effort),
|
|
89
|
+
mode: options.approveAll ? 'auto-approve' : 'ask',
|
|
90
|
+
};
|
|
91
|
+
sessions.set(session.id, session);
|
|
92
|
+
return { sessionId: session.id, configOptions: configOptions(session) };
|
|
93
|
+
}
|
|
94
|
+
function setConfigOption(params) {
|
|
95
|
+
const session = takeSession(params);
|
|
96
|
+
const value = params.value;
|
|
97
|
+
if (typeof value !== 'string')
|
|
98
|
+
throw invalid(`${params.configId} takes one of its listed values.`);
|
|
99
|
+
switch (params.configId) {
|
|
100
|
+
case 'agent': {
|
|
101
|
+
if (session.run)
|
|
102
|
+
throw invalid('Wait for the running prompt to end before switching agents.');
|
|
103
|
+
const agent = installed.find((candidate) => candidate.name === value);
|
|
104
|
+
if (!agent)
|
|
105
|
+
throw invalid(`Agent "${value}" is not installed.`);
|
|
106
|
+
if (!usable(session.mcpServers).includes(agent)) {
|
|
107
|
+
throw invalid(`${agent.name} does not support MCP servers in genaicode.`);
|
|
108
|
+
}
|
|
109
|
+
if (agent !== session.agent) {
|
|
110
|
+
// The next agent cannot continue the previous one's session.
|
|
111
|
+
session.agent = agent;
|
|
112
|
+
session.agentSessionId = undefined;
|
|
113
|
+
session.effort = effortFor(agent, session.effort);
|
|
114
|
+
}
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
case 'effort':
|
|
118
|
+
if (value !== 'default' && !session.agent.capabilities.effort?.includes(value)) {
|
|
119
|
+
throw invalid(`${session.agent.name} has no effort "${value}".`);
|
|
120
|
+
}
|
|
121
|
+
session.effort = value === 'default' ? undefined : value;
|
|
122
|
+
break;
|
|
123
|
+
case 'mode':
|
|
124
|
+
if (value !== 'ask' && value !== 'auto-approve')
|
|
125
|
+
throw invalid(`Unknown mode "${value}".`);
|
|
126
|
+
session.mode = value;
|
|
127
|
+
break;
|
|
128
|
+
default:
|
|
129
|
+
throw invalid(`Unknown config option "${String(params.configId)}".`);
|
|
130
|
+
}
|
|
131
|
+
return { configOptions: configOptions(session) };
|
|
132
|
+
}
|
|
133
|
+
async function prompt(params) {
|
|
134
|
+
const session = takeSession(params);
|
|
135
|
+
if (session.run)
|
|
136
|
+
throw invalid('A prompt is already running in this session.');
|
|
137
|
+
const text = promptText(params.prompt);
|
|
138
|
+
if (!text)
|
|
139
|
+
throw invalid('The prompt is empty.');
|
|
140
|
+
const update = (value) => peer.notify('session/update', { sessionId: session.id, update: value });
|
|
141
|
+
const toUpdates = createEventMapper();
|
|
142
|
+
const run = session.agent.run({
|
|
143
|
+
prompt: text,
|
|
144
|
+
cwd: session.cwd,
|
|
145
|
+
model: options.model,
|
|
146
|
+
effort: session.effort,
|
|
147
|
+
// A driver that cannot resume starts each prompt fresh instead of refusing it.
|
|
148
|
+
resume: session.agent.capabilities.resume ? session.agentSessionId : undefined,
|
|
149
|
+
env,
|
|
150
|
+
...(session.mcpServers.length > 0 ? { mcpServers: session.mcpServers } : {}),
|
|
151
|
+
// Approvals are decided here, as in `genaicode chat`: not every driver takes
|
|
152
|
+
// `permissions.approval`, but every one that asks goes through onApproval.
|
|
153
|
+
onApproval: (request, signal) => session.mode === 'auto-approve' ? 'approve' : askHost(session.id, request, signal),
|
|
154
|
+
});
|
|
155
|
+
session.run = run;
|
|
156
|
+
let result;
|
|
157
|
+
try {
|
|
158
|
+
for await (const event of run) {
|
|
159
|
+
if (event.type === 'session')
|
|
160
|
+
session.agentSessionId = event.sessionId;
|
|
161
|
+
for (const value of toUpdates(event))
|
|
162
|
+
update(value);
|
|
163
|
+
}
|
|
164
|
+
result = await run.result;
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
session.run = undefined;
|
|
168
|
+
}
|
|
169
|
+
if (result.sessionId)
|
|
170
|
+
session.agentSessionId = result.sessionId;
|
|
171
|
+
if (result.status === 'aborted')
|
|
172
|
+
return { stopReason: 'cancelled' };
|
|
173
|
+
if (!result.ok)
|
|
174
|
+
throw new RpcError(result.error ?? `${session.agent.name} failed (${result.status}).`, -32603);
|
|
175
|
+
return { stopReason: 'end_turn' };
|
|
176
|
+
}
|
|
177
|
+
async function askHost(sessionId, request, signal) {
|
|
178
|
+
if (signal?.aborted)
|
|
179
|
+
return 'deny';
|
|
180
|
+
const answer = peer.request('session/request_permission', {
|
|
181
|
+
sessionId,
|
|
182
|
+
toolCall: {
|
|
183
|
+
toolCallId: request.id, // Claude: the id of the tool call it asks about
|
|
184
|
+
title: request.summary ?? approvalTitle(request.kind),
|
|
185
|
+
kind: request.kind === 'command' ? 'execute' : request.kind === 'file-change' ? 'edit' : 'other',
|
|
186
|
+
status: 'pending',
|
|
187
|
+
...(request.detail === undefined ? {} : { rawInput: request.detail }),
|
|
188
|
+
},
|
|
189
|
+
options: [
|
|
190
|
+
{
|
|
191
|
+
optionId: 'approve',
|
|
192
|
+
name: request.scope === 'turn' ? 'Allow for this turn' : 'Allow',
|
|
193
|
+
kind: 'allow_once',
|
|
194
|
+
},
|
|
195
|
+
{ optionId: 'deny', name: 'Reject', kind: 'reject_once' },
|
|
196
|
+
],
|
|
197
|
+
}, NO_TIMEOUT);
|
|
198
|
+
const withdrawn = new Promise((resolve) => signal?.addEventListener('abort', () => resolve(undefined)));
|
|
199
|
+
try {
|
|
200
|
+
const response = (await Promise.race([answer, withdrawn]));
|
|
201
|
+
return response?.outcome?.outcome === 'selected' && response.outcome.optionId === 'approve' && !signal?.aborted
|
|
202
|
+
? 'approve'
|
|
203
|
+
: 'deny';
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
return 'deny';
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function configOptions(session) {
|
|
210
|
+
const config = [
|
|
211
|
+
{
|
|
212
|
+
id: 'agent',
|
|
213
|
+
name: 'Agent',
|
|
214
|
+
description: 'The coding agent CLI that runs the prompts. Switching starts a new conversation.',
|
|
215
|
+
category: 'model',
|
|
216
|
+
type: 'select',
|
|
217
|
+
currentValue: session.agent.name,
|
|
218
|
+
options: usable(session.mcpServers).map((agent) => ({ value: agent.name, name: agent.name })),
|
|
219
|
+
},
|
|
220
|
+
];
|
|
221
|
+
const efforts = session.agent.capabilities.effort ?? [];
|
|
222
|
+
if (efforts.length > 0) {
|
|
223
|
+
config.push({
|
|
224
|
+
id: 'effort',
|
|
225
|
+
name: 'Effort',
|
|
226
|
+
category: 'thought_level',
|
|
227
|
+
type: 'select',
|
|
228
|
+
currentValue: session.effort ?? 'default',
|
|
229
|
+
options: [{ value: 'default', name: 'Default' }, ...efforts.map((value) => ({ value, name: value }))],
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
config.push({
|
|
233
|
+
id: 'mode',
|
|
234
|
+
name: 'Approvals',
|
|
235
|
+
category: 'mode',
|
|
236
|
+
type: 'select',
|
|
237
|
+
currentValue: session.mode,
|
|
238
|
+
options: [
|
|
239
|
+
{ value: 'ask', name: 'Ask', description: 'Ask before the agent runs a command or edits a file.' },
|
|
240
|
+
{ value: 'auto-approve', name: 'Auto-approve', description: 'Approve every permission request.' },
|
|
241
|
+
],
|
|
242
|
+
});
|
|
243
|
+
return config;
|
|
244
|
+
}
|
|
245
|
+
function takeSession(params) {
|
|
246
|
+
const session = sessions.get(sessionIdOf(params));
|
|
247
|
+
if (!session)
|
|
248
|
+
throw invalid('Unknown session.');
|
|
249
|
+
return session;
|
|
250
|
+
}
|
|
251
|
+
const lines = createInterface({ input: options.input, crlfDelay: Infinity });
|
|
252
|
+
// Closing the interface ends the loop below even when the input itself never ends.
|
|
253
|
+
if (options.signal?.aborted)
|
|
254
|
+
lines.close();
|
|
255
|
+
options.signal?.addEventListener('abort', () => lines.close(), { once: true });
|
|
256
|
+
for await (const line of lines) {
|
|
257
|
+
if (line.trim() === '')
|
|
258
|
+
continue;
|
|
259
|
+
let message;
|
|
260
|
+
try {
|
|
261
|
+
message = JSON.parse(line);
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
options.output.write(`${JSON.stringify({ jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error' } })}\n`);
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
peer.receive(message);
|
|
268
|
+
}
|
|
269
|
+
// The host went away: stop what still runs and let it settle.
|
|
270
|
+
const running = [...sessions.values()].flatMap((session) => (session.run ? [session.run] : []));
|
|
271
|
+
peer.fail(new Error('The client closed the connection.'));
|
|
272
|
+
for (const run of running)
|
|
273
|
+
run.abort();
|
|
274
|
+
await Promise.allSettled(running.map((run) => run.result));
|
|
275
|
+
}
|
|
276
|
+
function toMcpServer(server, taken) {
|
|
277
|
+
// genaicode server names are /^[A-Za-z0-9_-]+$/ and unique; ACP allows any.
|
|
278
|
+
const base = String(server.name ?? '').replace(/[^A-Za-z0-9_-]/g, '_') || 'mcp';
|
|
279
|
+
let name = base;
|
|
280
|
+
for (let n = 2; taken.has(name); n++)
|
|
281
|
+
name = `${base}_${n}`;
|
|
282
|
+
taken.add(name);
|
|
283
|
+
if ('url' in server && typeof server.url === 'string') {
|
|
284
|
+
if (server.type === 'sse')
|
|
285
|
+
throw invalid(`MCP server "${server.name}": SSE is not supported; use HTTP.`);
|
|
286
|
+
return { name, url: server.url, headers: pairs(server.headers) };
|
|
287
|
+
}
|
|
288
|
+
if ('command' in server && typeof server.command === 'string') {
|
|
289
|
+
return { name, command: server.command, args: server.args ?? [], env: pairs(server.env) };
|
|
290
|
+
}
|
|
291
|
+
throw invalid(`MCP server "${String(server.name)}" has neither a url nor a command.`);
|
|
292
|
+
}
|
|
293
|
+
function pairs(list) {
|
|
294
|
+
return Object.fromEntries((list ?? []).map(({ name, value }) => [name, value]));
|
|
295
|
+
}
|
|
296
|
+
function effortFor(agent, effort) {
|
|
297
|
+
return effort !== undefined && agent.capabilities.effort?.includes(effort) ? effort : undefined;
|
|
298
|
+
}
|
|
299
|
+
function sessionIdOf(params) {
|
|
300
|
+
const id = params?.sessionId;
|
|
301
|
+
return typeof id === 'string' ? id : '';
|
|
302
|
+
}
|
|
303
|
+
function invalid(message) {
|
|
304
|
+
return new RpcError(message, -32602);
|
|
305
|
+
}
|
|
306
|
+
function approvalTitle(kind) {
|
|
307
|
+
return kind === 'command' ? 'Run a command' : kind === 'file-change' ? 'Edit files' : 'Permission request';
|
|
308
|
+
}
|
|
309
|
+
/** The prompt's content blocks as the text the agent CLI gets. */
|
|
310
|
+
export function promptText(blocks) {
|
|
311
|
+
if (!Array.isArray(blocks))
|
|
312
|
+
throw invalid('prompt must be an array of content blocks.');
|
|
313
|
+
const parts = [];
|
|
314
|
+
for (const block of blocks) {
|
|
315
|
+
switch (block?.type) {
|
|
316
|
+
case 'text':
|
|
317
|
+
parts.push(String(block.text ?? ''));
|
|
318
|
+
break;
|
|
319
|
+
case 'resource_link':
|
|
320
|
+
parts.push(`@${pathOf(String(block.uri ?? ''))}`);
|
|
321
|
+
break;
|
|
322
|
+
case 'resource': {
|
|
323
|
+
const resource = (block.resource ?? {});
|
|
324
|
+
const where = pathOf(String(resource.uri ?? ''));
|
|
325
|
+
if (typeof resource.text === 'string')
|
|
326
|
+
parts.push(`${where}:\n\`\`\`\n${resource.text}\n\`\`\``);
|
|
327
|
+
else
|
|
328
|
+
parts.push(`@${where}`);
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
default:
|
|
332
|
+
throw invalid(`Unsupported content block "${String(block?.type)}".`);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return parts.join('\n').trim();
|
|
336
|
+
}
|
|
337
|
+
function pathOf(uri) {
|
|
338
|
+
if (!uri.startsWith('file://'))
|
|
339
|
+
return uri;
|
|
340
|
+
try {
|
|
341
|
+
return fileURLToPath(uri);
|
|
342
|
+
}
|
|
343
|
+
catch {
|
|
344
|
+
return uri;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Turns the agent's events into ACP `session/update` values. Streamed text goes out as it comes;
|
|
349
|
+
* a final `message` adds only what the stream did not already show.
|
|
350
|
+
*/
|
|
351
|
+
export function createEventMapper() {
|
|
352
|
+
let streamed = '';
|
|
353
|
+
let messageId = randomUUID();
|
|
354
|
+
let toolCalls = 0;
|
|
355
|
+
const open = new Map();
|
|
356
|
+
const chunk = (text) => ({
|
|
357
|
+
sessionUpdate: 'agent_message_chunk',
|
|
358
|
+
messageId,
|
|
359
|
+
content: { type: 'text', text },
|
|
360
|
+
});
|
|
361
|
+
const nextMessage = () => {
|
|
362
|
+
streamed = '';
|
|
363
|
+
messageId = randomUUID();
|
|
364
|
+
};
|
|
365
|
+
return (event) => {
|
|
366
|
+
switch (event.type) {
|
|
367
|
+
case 'text-delta':
|
|
368
|
+
streamed += event.text;
|
|
369
|
+
return event.text ? [chunk(event.text)] : [];
|
|
370
|
+
case 'message': {
|
|
371
|
+
const rest = event.text.startsWith(streamed) ? event.text.slice(streamed.length) : streamed ? '' : event.text;
|
|
372
|
+
const update = rest ? [chunk(rest)] : [];
|
|
373
|
+
nextMessage();
|
|
374
|
+
return update;
|
|
375
|
+
}
|
|
376
|
+
case 'tool-start': {
|
|
377
|
+
// Text after the tool is a new ACP message, but some drivers end with one `message` holding
|
|
378
|
+
// the whole reply, so `streamed` keeps counting until that message arrives.
|
|
379
|
+
if (streamed)
|
|
380
|
+
messageId = randomUUID();
|
|
381
|
+
const toolCallId = event.id ?? `tool-${++toolCalls}`;
|
|
382
|
+
open.set(event.name, toolCallId);
|
|
383
|
+
return [
|
|
384
|
+
{
|
|
385
|
+
sessionUpdate: 'tool_call',
|
|
386
|
+
toolCallId,
|
|
387
|
+
title: toolTitle(event.name, event.input),
|
|
388
|
+
name: event.name,
|
|
389
|
+
kind: toolKind(event.name),
|
|
390
|
+
status: 'in_progress',
|
|
391
|
+
...(event.input === undefined ? {} : { rawInput: event.input }),
|
|
392
|
+
...locationsOf(event.input),
|
|
393
|
+
},
|
|
394
|
+
];
|
|
395
|
+
}
|
|
396
|
+
case 'tool-end': {
|
|
397
|
+
const toolCallId = event.id ?? (event.name ? open.get(event.name) : undefined);
|
|
398
|
+
if (!toolCallId)
|
|
399
|
+
return [];
|
|
400
|
+
if (event.name)
|
|
401
|
+
open.delete(event.name);
|
|
402
|
+
return [
|
|
403
|
+
{
|
|
404
|
+
sessionUpdate: 'tool_call_update',
|
|
405
|
+
toolCallId,
|
|
406
|
+
status: event.isError ? 'failed' : 'completed',
|
|
407
|
+
...(event.output
|
|
408
|
+
? {
|
|
409
|
+
content: [{ type: 'content', content: { type: 'text', text: event.output } }],
|
|
410
|
+
rawOutput: event.output,
|
|
411
|
+
}
|
|
412
|
+
: {}),
|
|
413
|
+
},
|
|
414
|
+
];
|
|
415
|
+
}
|
|
416
|
+
case 'file-change':
|
|
417
|
+
return [
|
|
418
|
+
{
|
|
419
|
+
sessionUpdate: 'tool_call',
|
|
420
|
+
toolCallId: `files-${++toolCalls}`,
|
|
421
|
+
title: `Changed ${event.paths.join(', ')}`,
|
|
422
|
+
kind: 'edit',
|
|
423
|
+
status: 'completed',
|
|
424
|
+
locations: event.paths.map((path) => ({ path })),
|
|
425
|
+
},
|
|
426
|
+
];
|
|
427
|
+
default:
|
|
428
|
+
return [];
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
function toolKind(name) {
|
|
433
|
+
const lower = name.toLowerCase();
|
|
434
|
+
if (/bash|shell|exec|command|terminal|run/.test(lower))
|
|
435
|
+
return 'execute';
|
|
436
|
+
if (/edit|write|patch|apply|create|file_change/.test(lower))
|
|
437
|
+
return 'edit';
|
|
438
|
+
if (/delete|remove/.test(lower))
|
|
439
|
+
return 'delete';
|
|
440
|
+
if (/grep|glob|search|find|list|ls/.test(lower))
|
|
441
|
+
return 'search';
|
|
442
|
+
if (/read|view|cat|open/.test(lower))
|
|
443
|
+
return 'read';
|
|
444
|
+
if (/fetch|web|http|url/.test(lower))
|
|
445
|
+
return 'fetch';
|
|
446
|
+
if (/think|todo|plan/.test(lower))
|
|
447
|
+
return 'think';
|
|
448
|
+
return 'other';
|
|
449
|
+
}
|
|
450
|
+
function toolTitle(name, input) {
|
|
451
|
+
if (input && typeof input === 'object') {
|
|
452
|
+
const fields = input;
|
|
453
|
+
for (const key of ['command', 'cmd', 'file_path', 'path', 'pattern', 'query', 'url', 'description']) {
|
|
454
|
+
const value = fields[key];
|
|
455
|
+
if (typeof value === 'string' && value.trim())
|
|
456
|
+
return `${name}: ${oneLine(value)}`;
|
|
457
|
+
if (Array.isArray(value) && value.every((part) => typeof part === 'string')) {
|
|
458
|
+
return `${name}: ${oneLine(value.join(' '))}`;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
return name;
|
|
463
|
+
}
|
|
464
|
+
function locationsOf(input) {
|
|
465
|
+
if (!input || typeof input !== 'object')
|
|
466
|
+
return {};
|
|
467
|
+
const fields = input;
|
|
468
|
+
const path = [fields.file_path, fields.path, fields.notebook_path].find((value) => typeof value === 'string' && value !== '');
|
|
469
|
+
return path ? { locations: [{ path }] } : {};
|
|
470
|
+
}
|
|
471
|
+
function oneLine(text) {
|
|
472
|
+
const line = text.replace(/\s+/g, ' ').trim();
|
|
473
|
+
return line.length > 120 ? `${line.slice(0, 117)}...` : line;
|
|
474
|
+
}
|
|
475
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/acp/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAGrD;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,oBAAoB,GA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AE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC,IAAI,CACrE,CAAC,KAAK,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,CACtE,CAAC;IACF,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAC/C,CAAC;AAED,SAAS,OAAO,CAAC,IAAY;IAC3B,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAC9C,OAAO,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/D,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ApprovalDecision, CodingAgent } from '../agents/types.js';
|
|
2
|
-
import type
|
|
1
|
+
import type { ApprovalDecision, ApprovalRequest, CodingAgent } from '../agents/types.js';
|
|
2
|
+
import { type McpTool, type ToolOutput } from './mcp.js';
|
|
3
3
|
import { type AppAgentMode, type AppAgentState, type TreeChanges } from './state.js';
|
|
4
4
|
export interface AppTool {
|
|
5
5
|
name: string;
|
|
@@ -10,8 +10,11 @@ export interface AppTool {
|
|
|
10
10
|
write?: boolean;
|
|
11
11
|
/** Throw to refuse a call. Write tools check here, before an action is created. */
|
|
12
12
|
validate?(args: Record<string, unknown>): void;
|
|
13
|
-
/**
|
|
14
|
-
|
|
13
|
+
/**
|
|
14
|
+
* What the tool returns to the agent (read tools) or the outcome of an approved action (write
|
|
15
|
+
* tools). A read tool may add images, e.g. a screenshot; a write tool's outcome is its text.
|
|
16
|
+
*/
|
|
17
|
+
run(args: Record<string, unknown>): Promise<ToolOutput> | ToolOutput;
|
|
15
18
|
}
|
|
16
19
|
export interface AppAgentOptions {
|
|
17
20
|
/** How the agent should call the app, e.g. "the gamedev.pl operator console". */
|
|
@@ -33,6 +36,13 @@ export interface AppAgentOptions {
|
|
|
33
36
|
*/
|
|
34
37
|
commands?: readonly string[];
|
|
35
38
|
instructions?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Offer `propose_commit`. Default true. Turn it off when `cwd` is not a git repository the
|
|
41
|
+
* user commits to, e.g. the app syncs or delivers the files itself.
|
|
42
|
+
*/
|
|
43
|
+
commit?: boolean;
|
|
44
|
+
/** Only `dev` mode: no `use` mode, and the agent starts in `dev`. */
|
|
45
|
+
only?: boolean;
|
|
36
46
|
};
|
|
37
47
|
/** Agents offered in each mode. Default `defaultAppAgents(mode, dev.commands)`. */
|
|
38
48
|
agents?: (mode: AppAgentMode) => readonly CodingAgent[];
|
|
@@ -48,6 +58,12 @@ export interface AppAgentOptions {
|
|
|
48
58
|
now?: () => number;
|
|
49
59
|
/** How long an approved commit waits for the turn it stops to end; past it the commit fails. Default 10 s. */
|
|
50
60
|
stopTimeoutMs?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Decide the agent CLI's own permission prompts without asking, e.g. from an "auto-approve"
|
|
63
|
+
* setting the app has. Read on every prompt, so the app can change its answer at any time.
|
|
64
|
+
* Return undefined to leave the prompt to the user (`approve`).
|
|
65
|
+
*/
|
|
66
|
+
autoApprove?(request: ApprovalRequest): ApprovalDecision | undefined;
|
|
51
67
|
}
|
|
52
68
|
/** One line of the trace. Long texts are clipped. */
|
|
53
69
|
export type AppAgentTrace = {
|