@xiuper/cli 0.0.2 → 1.0.1
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/jsMain/typescript/agents/acp/AcpAgentServer.d.ts +18 -0
- package/dist/jsMain/typescript/agents/acp/AcpAgentServer.d.ts.map +1 -0
- package/dist/jsMain/typescript/agents/acp/AcpAgentServer.js +255 -0
- package/dist/jsMain/typescript/agents/acp/AcpAgentServer.js.map +1 -0
- package/dist/jsMain/typescript/agents/acp/AcpClientConnection.d.ts +96 -0
- package/dist/jsMain/typescript/agents/acp/AcpClientConnection.d.ts.map +1 -0
- package/dist/jsMain/typescript/agents/acp/AcpClientConnection.js +356 -0
- package/dist/jsMain/typescript/agents/acp/AcpClientConnection.js.map +1 -0
- package/dist/jsMain/typescript/agents/acp/index.d.ts +10 -0
- package/dist/jsMain/typescript/agents/acp/index.d.ts.map +1 -0
- package/dist/jsMain/typescript/agents/acp/index.js +10 -0
- package/dist/jsMain/typescript/agents/acp/index.js.map +1 -0
- package/dist/jsMain/typescript/agents/render/BaseRenderer.d.ts +39 -5
- package/dist/jsMain/typescript/agents/render/BaseRenderer.d.ts.map +1 -1
- package/dist/jsMain/typescript/agents/render/BaseRenderer.js +85 -0
- package/dist/jsMain/typescript/agents/render/BaseRenderer.js.map +1 -1
- package/dist/jsMain/typescript/agents/render/CliRenderer.d.ts +9 -4
- package/dist/jsMain/typescript/agents/render/CliRenderer.d.ts.map +1 -1
- package/dist/jsMain/typescript/agents/render/CliRenderer.js +65 -4
- package/dist/jsMain/typescript/agents/render/CliRenderer.js.map +1 -1
- package/dist/jsMain/typescript/agents/render/ServerRenderer.d.ts.map +1 -1
- package/dist/jsMain/typescript/agents/render/ServerRenderer.js +4 -1
- package/dist/jsMain/typescript/agents/render/ServerRenderer.js.map +1 -1
- package/dist/jsMain/typescript/config/ConfigManager.d.ts.map +1 -1
- package/dist/jsMain/typescript/config/ConfigManager.js +4 -2
- package/dist/jsMain/typescript/config/ConfigManager.js.map +1 -1
- package/dist/jsMain/typescript/index.js +60 -2
- package/dist/jsMain/typescript/index.js.map +1 -1
- package/dist/jsMain/typescript/modes/AgentMode.d.ts.map +1 -1
- package/dist/jsMain/typescript/modes/AgentMode.js +2 -0
- package/dist/jsMain/typescript/modes/AgentMode.js.map +1 -1
- package/dist/jsMain/typescript/modes/ChatMode.d.ts.map +1 -1
- package/dist/jsMain/typescript/modes/ChatMode.js +2 -0
- package/dist/jsMain/typescript/modes/ChatMode.js.map +1 -1
- package/dist/jsMain/typescript/modes/CodexMode.d.ts +39 -0
- package/dist/jsMain/typescript/modes/CodexMode.d.ts.map +1 -0
- package/dist/jsMain/typescript/modes/CodexMode.js +285 -0
- package/dist/jsMain/typescript/modes/CodexMode.js.map +1 -0
- package/dist/jsMain/typescript/modes/index.d.ts +1 -0
- package/dist/jsMain/typescript/modes/index.d.ts.map +1 -1
- package/dist/jsMain/typescript/modes/index.js +1 -0
- package/dist/jsMain/typescript/modes/index.js.map +1 -1
- package/dist/jsMain/typescript/processors/ModeCommandProcessor.d.ts.map +1 -1
- package/dist/jsMain/typescript/processors/ModeCommandProcessor.js +18 -1
- package/dist/jsMain/typescript/processors/ModeCommandProcessor.js.map +1 -1
- package/dist/jsMain/typescript/processors/SkillCommandProcessor.d.ts +31 -0
- package/dist/jsMain/typescript/processors/SkillCommandProcessor.d.ts.map +1 -0
- package/dist/jsMain/typescript/processors/SkillCommandProcessor.js +153 -0
- package/dist/jsMain/typescript/processors/SkillCommandProcessor.js.map +1 -0
- package/dist/jsMain/typescript/processors/SlashCommandProcessor.d.ts +12 -0
- package/dist/jsMain/typescript/processors/SlashCommandProcessor.d.ts.map +1 -1
- package/dist/jsMain/typescript/processors/SlashCommandProcessor.js +40 -0
- package/dist/jsMain/typescript/processors/SlashCommandProcessor.js.map +1 -1
- package/dist/jsMain/typescript/ui/App.d.ts.map +1 -1
- package/dist/jsMain/typescript/ui/App.js +3 -1
- package/dist/jsMain/typescript/ui/App.js.map +1 -1
- package/package.json +4 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP Agent Server for the JS/Node.js CLI.
|
|
3
|
+
*
|
|
4
|
+
* This exposes our CodingAgent as an ACP-compliant agent that can be connected to
|
|
5
|
+
* by any ACP client (e.g., JetBrains IDEA, VSCode, Zed, or other editors).
|
|
6
|
+
*
|
|
7
|
+
* Communication happens over STDIO using JSON-RPC (newline-delimited JSON).
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* xiuper acp
|
|
11
|
+
* # Now other editors can connect to this agent via its stdin/stdout
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Start the ACP agent server on stdin/stdout.
|
|
15
|
+
* This is the entry point for `xiuper acp` command.
|
|
16
|
+
*/
|
|
17
|
+
export declare function startAcpAgentServer(): Promise<void>;
|
|
18
|
+
//# sourceMappingURL=AcpAgentServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AcpAgentServer.d.ts","sourceRoot":"","sources":["../../../../../src/jsMain/typescript/agents/acp/AcpAgentServer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA4TH;;;GAGG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAoBzD"}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP Agent Server for the JS/Node.js CLI.
|
|
3
|
+
*
|
|
4
|
+
* This exposes our CodingAgent as an ACP-compliant agent that can be connected to
|
|
5
|
+
* by any ACP client (e.g., JetBrains IDEA, VSCode, Zed, or other editors).
|
|
6
|
+
*
|
|
7
|
+
* Communication happens over STDIO using JSON-RPC (newline-delimited JSON).
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* xiuper acp
|
|
11
|
+
* # Now other editors can connect to this agent via its stdin/stdout
|
|
12
|
+
*/
|
|
13
|
+
import * as acp from '@agentclientprotocol/sdk';
|
|
14
|
+
import { Readable, Writable } from 'node:stream';
|
|
15
|
+
import { ConfigManager } from '../../config/ConfigManager.js';
|
|
16
|
+
import mppCore from '@xiuper/mpp-core';
|
|
17
|
+
const { cc: KotlinCC } = mppCore;
|
|
18
|
+
/**
|
|
19
|
+
* ACP Agent implementation that wraps our CodingAgent.
|
|
20
|
+
*/
|
|
21
|
+
class AutoDevAcpAgent {
|
|
22
|
+
connection;
|
|
23
|
+
sessions = new Map();
|
|
24
|
+
constructor(connection) {
|
|
25
|
+
this.connection = connection;
|
|
26
|
+
}
|
|
27
|
+
async initialize(params) {
|
|
28
|
+
console.error('[ACP Agent] Client connected:', params.clientInfo?.name);
|
|
29
|
+
return {
|
|
30
|
+
protocolVersion: acp.PROTOCOL_VERSION,
|
|
31
|
+
agentCapabilities: {
|
|
32
|
+
loadSession: false,
|
|
33
|
+
promptCapabilities: {},
|
|
34
|
+
},
|
|
35
|
+
agentInfo: {
|
|
36
|
+
name: 'autodev-xiuper',
|
|
37
|
+
version: '3.0.0',
|
|
38
|
+
title: 'AutoDev Xiuper (ACP Agent)',
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async newSession(params) {
|
|
43
|
+
const sessionId = `autodev-${Date.now()}`;
|
|
44
|
+
const cwd = params.cwd || process.cwd();
|
|
45
|
+
console.error(`[ACP Agent] New session: ${sessionId} (cwd=${cwd})`);
|
|
46
|
+
// Load config
|
|
47
|
+
const config = await ConfigManager.load();
|
|
48
|
+
const activeConfig = config.getActiveConfig();
|
|
49
|
+
if (!activeConfig) {
|
|
50
|
+
throw new Error('No active LLM configuration found. Please configure your LLM provider first.');
|
|
51
|
+
}
|
|
52
|
+
// Create LLM service
|
|
53
|
+
const llmService = new KotlinCC.unitmesh.llm.JsKoogLLMService(new KotlinCC.unitmesh.llm.JsModelConfig(activeConfig.provider, activeConfig.model, activeConfig.apiKey || '', activeConfig.temperature || 0.7, activeConfig.maxTokens || 8192, activeConfig.baseUrl || ''));
|
|
54
|
+
// Load MCP servers if configured
|
|
55
|
+
const mcpServers = config.getMcpServers();
|
|
56
|
+
const enabledMcpServers = {};
|
|
57
|
+
for (const [name, serverConfig] of Object.entries(mcpServers)) {
|
|
58
|
+
if (serverConfig.enabled) {
|
|
59
|
+
enabledMcpServers[name] = {
|
|
60
|
+
command: serverConfig.command,
|
|
61
|
+
args: serverConfig.args || [],
|
|
62
|
+
env: serverConfig.env || {},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Create a renderer that sends updates via ACP
|
|
67
|
+
const renderer = new AcpSessionRenderer(this.connection, sessionId);
|
|
68
|
+
// Create CodingAgent
|
|
69
|
+
const agent = new KotlinCC.unitmesh.agent.JsCodingAgent(cwd, llmService, 10, // maxIterations
|
|
70
|
+
renderer, Object.keys(enabledMcpServers).length > 0 ? enabledMcpServers : null, null // toolConfig
|
|
71
|
+
);
|
|
72
|
+
this.sessions.set(sessionId, {
|
|
73
|
+
sessionId,
|
|
74
|
+
cwd,
|
|
75
|
+
agent,
|
|
76
|
+
abortController: new AbortController(),
|
|
77
|
+
});
|
|
78
|
+
return { sessionId };
|
|
79
|
+
}
|
|
80
|
+
async prompt(params) {
|
|
81
|
+
const session = this.sessions.get(params.sessionId);
|
|
82
|
+
if (!session) {
|
|
83
|
+
throw acp.RequestError.invalidParams(`Unknown session: ${params.sessionId}`);
|
|
84
|
+
}
|
|
85
|
+
// Extract text from content blocks
|
|
86
|
+
const textParts = [];
|
|
87
|
+
for (const block of params.prompt) {
|
|
88
|
+
if (block.type === 'text') {
|
|
89
|
+
textParts.push(block.text);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const promptText = textParts.join('\n');
|
|
93
|
+
console.error(`[ACP Agent] Prompt in session ${params.sessionId}: ${promptText.substring(0, 100)}...`);
|
|
94
|
+
try {
|
|
95
|
+
// Create task and execute
|
|
96
|
+
const task = new KotlinCC.unitmesh.agent.JsAgentTask(promptText, session.cwd);
|
|
97
|
+
const result = await session.agent.executeTask(task);
|
|
98
|
+
return {
|
|
99
|
+
stopReason: result.success ? 'end_turn' : 'end_turn',
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
console.error('[ACP Agent] Prompt error:', error);
|
|
104
|
+
// Send error as agent message
|
|
105
|
+
await this.connection.sessionUpdate({
|
|
106
|
+
sessionId: params.sessionId,
|
|
107
|
+
update: {
|
|
108
|
+
sessionUpdate: 'agent_message_chunk',
|
|
109
|
+
content: {
|
|
110
|
+
type: 'text',
|
|
111
|
+
text: `Error: ${error instanceof Error ? error.message : String(error)}`,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
return { stopReason: 'end_turn' };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async cancel(params) {
|
|
119
|
+
const session = this.sessions.get(params.sessionId);
|
|
120
|
+
if (session) {
|
|
121
|
+
session.abortController.abort();
|
|
122
|
+
console.error(`[ACP Agent] Session cancelled: ${params.sessionId}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// Optional methods - not needed for basic operation
|
|
126
|
+
async authenticate(params) {
|
|
127
|
+
throw acp.RequestError.methodNotFound('authenticate');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Renderer that sends all output as ACP session updates.
|
|
132
|
+
* This bridges our internal renderer to the ACP protocol.
|
|
133
|
+
*/
|
|
134
|
+
class AcpSessionRenderer {
|
|
135
|
+
__doNotUseOrImplementIt = {};
|
|
136
|
+
connection;
|
|
137
|
+
sessionId;
|
|
138
|
+
toolCallCounter = 0;
|
|
139
|
+
constructor(connection, sessionId) {
|
|
140
|
+
this.connection = connection;
|
|
141
|
+
this.sessionId = sessionId;
|
|
142
|
+
}
|
|
143
|
+
renderIterationHeader(current, max) {
|
|
144
|
+
// Send as thought
|
|
145
|
+
this.sendThought(`Iteration ${current}/${max}`);
|
|
146
|
+
}
|
|
147
|
+
renderLLMResponseStart() {
|
|
148
|
+
// No-op, chunks will follow
|
|
149
|
+
}
|
|
150
|
+
renderLLMResponseChunk(chunk) {
|
|
151
|
+
if (chunk) {
|
|
152
|
+
this.sendTextChunk(chunk);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
renderLLMResponseEnd() {
|
|
156
|
+
// No-op
|
|
157
|
+
}
|
|
158
|
+
renderThinkingChunk(chunk, isStart, isEnd) {
|
|
159
|
+
if (chunk) {
|
|
160
|
+
this.sendThought(chunk);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
renderToolCall(toolName, paramsStr) {
|
|
164
|
+
this.toolCallCounter++;
|
|
165
|
+
this.sendToolCall(toolName, 'in_progress', paramsStr);
|
|
166
|
+
}
|
|
167
|
+
renderToolCallWithParams(toolName, params) {
|
|
168
|
+
this.toolCallCounter++;
|
|
169
|
+
const paramsStr = Object.entries(params)
|
|
170
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
171
|
+
.join(', ');
|
|
172
|
+
this.sendToolCall(toolName, 'in_progress', paramsStr);
|
|
173
|
+
}
|
|
174
|
+
renderToolResult(toolName, success, output, fullOutput, metadata) {
|
|
175
|
+
this.sendToolCall(toolName, success ? 'completed' : 'errored', undefined, output || fullOutput || undefined);
|
|
176
|
+
}
|
|
177
|
+
renderTaskComplete(executionTimeMs, toolsUsedCount) {
|
|
178
|
+
this.sendTextChunk(`\nTask completed in ${executionTimeMs || 0}ms using ${toolsUsedCount || 0} tools.`);
|
|
179
|
+
}
|
|
180
|
+
renderFinalResult(success, message, iterations) {
|
|
181
|
+
// Final result is implicit in the prompt response
|
|
182
|
+
}
|
|
183
|
+
renderError(message) {
|
|
184
|
+
this.sendTextChunk(`\nError: ${message}`);
|
|
185
|
+
}
|
|
186
|
+
renderRepeatWarning(toolName, count) {
|
|
187
|
+
this.sendThought(`Warning: Tool '${toolName}' called ${count} times consecutively`);
|
|
188
|
+
}
|
|
189
|
+
renderRecoveryAdvice(recoveryAdvice) {
|
|
190
|
+
this.sendTextChunk(`\nRecovery advice: ${recoveryAdvice}`);
|
|
191
|
+
}
|
|
192
|
+
renderUserConfirmationRequest(toolName, params) {
|
|
193
|
+
// Auto-approve in ACP mode
|
|
194
|
+
}
|
|
195
|
+
renderPlanSummary(summary) {
|
|
196
|
+
// Could emit plan update here if needed
|
|
197
|
+
}
|
|
198
|
+
renderAgentSketchBlock(agentName, language, code, metadata) {
|
|
199
|
+
this.sendTextChunk(`\n\`\`\`${language}\n${code}\n\`\`\`\n`);
|
|
200
|
+
}
|
|
201
|
+
addLiveTerminal(sessionId, command, workingDirectory, ptyHandle) {
|
|
202
|
+
// No-op in ACP mode
|
|
203
|
+
}
|
|
204
|
+
// -- Private helpers --
|
|
205
|
+
sendTextChunk(text) {
|
|
206
|
+
this.connection.sessionUpdate({
|
|
207
|
+
sessionId: this.sessionId,
|
|
208
|
+
update: {
|
|
209
|
+
sessionUpdate: 'agent_message_chunk',
|
|
210
|
+
content: { type: 'text', text },
|
|
211
|
+
},
|
|
212
|
+
}).catch(err => console.error('[ACP Renderer] Failed to send text chunk:', err));
|
|
213
|
+
}
|
|
214
|
+
sendThought(text) {
|
|
215
|
+
this.connection.sessionUpdate({
|
|
216
|
+
sessionId: this.sessionId,
|
|
217
|
+
update: {
|
|
218
|
+
sessionUpdate: 'agent_thought_chunk',
|
|
219
|
+
content: { type: 'text', text },
|
|
220
|
+
},
|
|
221
|
+
}).catch(err => console.error('[ACP Renderer] Failed to send thought:', err));
|
|
222
|
+
}
|
|
223
|
+
sendToolCall(title, status, input, output) {
|
|
224
|
+
this.connection.sessionUpdate({
|
|
225
|
+
sessionId: this.sessionId,
|
|
226
|
+
update: {
|
|
227
|
+
sessionUpdate: 'tool_call',
|
|
228
|
+
toolCallId: `tc-${this.toolCallCounter}`,
|
|
229
|
+
title,
|
|
230
|
+
status,
|
|
231
|
+
kind: 'other',
|
|
232
|
+
...(input ? { rawInput: input } : {}),
|
|
233
|
+
...(output ? { rawOutput: output } : {}),
|
|
234
|
+
},
|
|
235
|
+
}).catch(err => console.error('[ACP Renderer] Failed to send tool call:', err));
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Start the ACP agent server on stdin/stdout.
|
|
240
|
+
* This is the entry point for `xiuper acp` command.
|
|
241
|
+
*/
|
|
242
|
+
export async function startAcpAgentServer() {
|
|
243
|
+
console.error('[ACP Agent] Starting AutoDev Xiuper ACP Agent Server...');
|
|
244
|
+
// For ACP ndJsonStream: first param is output (where we write), second is input (where we read)
|
|
245
|
+
// We write JSON responses to stdout, read JSON requests from stdin
|
|
246
|
+
const output = Writable.toWeb(process.stdout);
|
|
247
|
+
const input = Readable.toWeb(process.stdin);
|
|
248
|
+
const stream = acp.ndJsonStream(output, input);
|
|
249
|
+
const connection = new acp.AgentSideConnection((conn) => new AutoDevAcpAgent(conn), stream);
|
|
250
|
+
console.error('[ACP Agent] Server started. Waiting for client connections on stdio...');
|
|
251
|
+
// Wait for the connection to close
|
|
252
|
+
await connection.closed;
|
|
253
|
+
console.error('[ACP Agent] Connection closed.');
|
|
254
|
+
}
|
|
255
|
+
//# sourceMappingURL=AcpAgentServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AcpAgentServer.js","sourceRoot":"","sources":["../../../../../src/jsMain/typescript/agents/acp/AcpAgentServer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,GAAG,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,OAAO,MAAM,kBAAkB,CAAC;AAIvC,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;AAYjC;;GAEG;AACH,MAAM,eAAe;IACX,UAAU,CAA0B;IACpC,QAAQ,GAAG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AC5C,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,eAAe,CAAC,IAAI,CAAC,EACnC,MAAM,CACP,CAAC;IAEF,OAAO,CAAC,KAAK,CAAC,wEAAwE,CAAC,CAAC;IAExF,mCAAmC;IACnC,MAAM,UAAU,CAAC,MAAM,CAAC;IACxB,OAAO,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP Client Connection for the JS/Node.js CLI.
|
|
3
|
+
*
|
|
4
|
+
* This allows our CLI to connect to external ACP agents (e.g., Claude CLI, Gemini CLI, Codex)
|
|
5
|
+
* and interact with them through the standardized ACP protocol.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Process lifecycle management with graceful shutdown
|
|
9
|
+
* - fs capabilities (readTextFile/writeTextFile) for agent file access
|
|
10
|
+
* - Terminal capability for agent shell execution
|
|
11
|
+
* - Session reuse for multi-turn prompts
|
|
12
|
+
* - Tool call deduplication (ACP streams many IN_PROGRESS updates)
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* const client = new AcpClientConnection('codex', ['--acp']);
|
|
16
|
+
* await client.connect('/path/to/project');
|
|
17
|
+
* const result = await client.prompt('Fix the bug in main.ts');
|
|
18
|
+
* // Multi-turn: send another prompt in the same session
|
|
19
|
+
* const result2 = await client.prompt('Now add tests');
|
|
20
|
+
* await client.disconnect();
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Callback interface for receiving ACP session updates.
|
|
24
|
+
*/
|
|
25
|
+
export interface AcpClientCallbacks {
|
|
26
|
+
onTextChunk?: (text: string) => void;
|
|
27
|
+
onThoughtChunk?: (text: string) => void;
|
|
28
|
+
onToolCall?: (title: string, status: string, input?: string, output?: string) => void;
|
|
29
|
+
onPlanUpdate?: (entries: Array<{
|
|
30
|
+
content: string;
|
|
31
|
+
status: string;
|
|
32
|
+
}>) => void;
|
|
33
|
+
onModeUpdate?: (modeId: string) => void;
|
|
34
|
+
onError?: (message: string) => void;
|
|
35
|
+
/** Called when permission is requested. Return true to approve, false to deny. */
|
|
36
|
+
onPermissionRequest?: (toolTitle: string, options: string[]) => Promise<boolean>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Configuration for ACP client capabilities.
|
|
40
|
+
*/
|
|
41
|
+
export interface AcpClientCapabilities {
|
|
42
|
+
/** Enable fs.readTextFile and fs.writeTextFile for the agent */
|
|
43
|
+
fs?: boolean;
|
|
44
|
+
/** Enable terminal operations for the agent */
|
|
45
|
+
terminal?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* ACP Client that connects to an external ACP agent process.
|
|
49
|
+
*
|
|
50
|
+
* Supports process reuse, multi-turn prompts, and tool call dedup.
|
|
51
|
+
*/
|
|
52
|
+
export declare class AcpClientConnection {
|
|
53
|
+
private command;
|
|
54
|
+
private args;
|
|
55
|
+
private env;
|
|
56
|
+
private clientCapabilities;
|
|
57
|
+
private connection;
|
|
58
|
+
private agentProcess;
|
|
59
|
+
private callbacks;
|
|
60
|
+
private currentSessionId;
|
|
61
|
+
private currentCwd;
|
|
62
|
+
private promptCount;
|
|
63
|
+
constructor(command: string, args?: string[], env?: Record<string, string>, capabilities?: AcpClientCapabilities);
|
|
64
|
+
/**
|
|
65
|
+
* Set callbacks for receiving updates from the agent.
|
|
66
|
+
*/
|
|
67
|
+
setCallbacks(callbacks: AcpClientCallbacks): void;
|
|
68
|
+
/**
|
|
69
|
+
* Connect to the ACP agent: spawn the process, initialize protocol, create session.
|
|
70
|
+
*/
|
|
71
|
+
connect(cwd: string): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Send a prompt to the agent and wait for completion.
|
|
74
|
+
* Supports multi-turn: call this multiple times within the same session.
|
|
75
|
+
*/
|
|
76
|
+
prompt(text: string): Promise<{
|
|
77
|
+
stopReason: string;
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* Cancel the current prompt.
|
|
81
|
+
*/
|
|
82
|
+
cancel(): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Disconnect from the agent and clean up the process.
|
|
85
|
+
*/
|
|
86
|
+
disconnect(): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Check if the client is connected and the process is alive.
|
|
89
|
+
*/
|
|
90
|
+
get isConnected(): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Get the number of prompts sent in the current session.
|
|
93
|
+
*/
|
|
94
|
+
get currentPromptCount(): number;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=AcpClientConnection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AcpClientConnection.d.ts","sourceRoot":"","sources":["../../../../../src/jsMain/typescript/agents/acp/AcpClientConnection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAQH;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACtF,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,KAAK,IAAI,CAAC;IAC7E,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,kFAAkF;IAClF,mBAAmB,CAAC,EAAE,CAAC,SAAS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