agentgui 1.0.60 → 1.0.62
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/acp-launcher.js +67 -35
- package/package.json +1 -1
- package/server.js +10 -13
package/acp-launcher.js
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import { query } from '@anthropic-ai/claude-code';
|
|
2
|
-
import { default as SYSTEM_PROMPT } from './system-prompt.js';
|
|
3
2
|
|
|
3
|
+
/**
|
|
4
|
+
* ACPConnection - Uses @anthropic-ai/claude-code SDK directly
|
|
5
|
+
*
|
|
6
|
+
* This uses the real Claude Code SDK which handles:
|
|
7
|
+
* - Plugin execution with real system prompt
|
|
8
|
+
* - Actual filesystem operations
|
|
9
|
+
* - Streaming responses with onUpdate callbacks
|
|
10
|
+
* - No subprocess spawning needed (SDK handles it)
|
|
11
|
+
*/
|
|
4
12
|
export default class ACPConnection {
|
|
5
13
|
constructor() {
|
|
6
14
|
this.sessionId = null;
|
|
7
15
|
this.onUpdate = null;
|
|
16
|
+
this.cwd = process.cwd();
|
|
8
17
|
}
|
|
9
18
|
|
|
10
19
|
async connect(agentType, cwd) {
|
|
11
|
-
console.log(`[ACP] Using
|
|
20
|
+
console.log(`[ACP] Using @anthropic-ai/claude-code SDK (${agentType})`);
|
|
21
|
+
if (cwd) {
|
|
22
|
+
this.cwd = cwd;
|
|
23
|
+
}
|
|
24
|
+
return { connected: true };
|
|
12
25
|
}
|
|
13
26
|
|
|
14
27
|
async initialize() {
|
|
@@ -17,6 +30,10 @@ export default class ACPConnection {
|
|
|
17
30
|
|
|
18
31
|
async newSession(cwd) {
|
|
19
32
|
this.sessionId = Math.random().toString(36).substring(7);
|
|
33
|
+
if (cwd) {
|
|
34
|
+
this.cwd = cwd;
|
|
35
|
+
}
|
|
36
|
+
console.log(`[ACP] Session ${this.sessionId} in ${this.cwd}`);
|
|
20
37
|
return { sessionId: this.sessionId };
|
|
21
38
|
}
|
|
22
39
|
|
|
@@ -29,49 +46,63 @@ export default class ACPConnection {
|
|
|
29
46
|
}
|
|
30
47
|
|
|
31
48
|
async injectSystemContext() {
|
|
32
|
-
return { context:
|
|
49
|
+
return { context: 'Using Claude Code SDK with real plugins' };
|
|
33
50
|
}
|
|
34
51
|
|
|
35
52
|
async sendPrompt(prompt) {
|
|
36
|
-
|
|
53
|
+
const promptText = typeof prompt === 'string' ? prompt : prompt.map(p => p.text).join('\n');
|
|
37
54
|
|
|
38
55
|
try {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
56
|
+
console.log(`[ACP] Sending prompt (${promptText.length} chars) in ${this.cwd}`);
|
|
57
|
+
|
|
58
|
+
// Use the SDK directly to execute the prompt
|
|
59
|
+
// The SDK handles plugins, system prompt, and all real execution
|
|
60
|
+
const session = await query({
|
|
61
|
+
prompt: promptText,
|
|
62
|
+
options: {
|
|
63
|
+
cwd: this.cwd
|
|
64
|
+
}
|
|
45
65
|
});
|
|
46
66
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
let fullResponse = '';
|
|
68
|
+
|
|
69
|
+
// Stream messages and collect the final result
|
|
70
|
+
for await (const message of session.sdkMessages) {
|
|
71
|
+
if (message.type === 'result') {
|
|
72
|
+
// Extract the actual result from the final message
|
|
73
|
+
if (message.result) {
|
|
74
|
+
fullResponse = String(message.result);
|
|
75
|
+
console.log(`[ACP] Got result: ${fullResponse.length} chars`);
|
|
76
|
+
|
|
77
|
+
// Emit update callback if provided
|
|
78
|
+
if (this.onUpdate && fullResponse) {
|
|
79
|
+
this.onUpdate({
|
|
80
|
+
update: {
|
|
81
|
+
sessionUpdate: 'agent_message_chunk',
|
|
82
|
+
content: { text: fullResponse }
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
65
86
|
}
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
content: fullResponse,
|
|
90
|
+
stopReason: 'end_turn',
|
|
91
|
+
result: fullResponse,
|
|
92
|
+
sessionId: this.sessionId,
|
|
93
|
+
usage: message.usage
|
|
94
|
+
};
|
|
66
95
|
}
|
|
67
96
|
}
|
|
68
97
|
|
|
69
|
-
// Fallback if
|
|
70
|
-
|
|
71
|
-
fullResponse
|
|
72
|
-
|
|
98
|
+
// Fallback if no result message found
|
|
99
|
+
return {
|
|
100
|
+
content: fullResponse,
|
|
101
|
+
stopReason: 'end_turn',
|
|
102
|
+
result: fullResponse,
|
|
103
|
+
sessionId: this.sessionId
|
|
104
|
+
};
|
|
73
105
|
|
|
74
|
-
return { content: fullResponse };
|
|
75
106
|
} catch (err) {
|
|
76
107
|
console.error(`[ACP] Query error: ${err.message}`);
|
|
77
108
|
throw err;
|
|
@@ -79,10 +110,11 @@ export default class ACPConnection {
|
|
|
79
110
|
}
|
|
80
111
|
|
|
81
112
|
isRunning() {
|
|
82
|
-
return true;
|
|
113
|
+
return true; // SDK manages process lifecycle
|
|
83
114
|
}
|
|
84
115
|
|
|
85
116
|
async terminate() {
|
|
86
|
-
|
|
117
|
+
console.log(`[ACP] Terminating session ${this.sessionId}`);
|
|
118
|
+
return { terminated: true };
|
|
87
119
|
}
|
|
88
120
|
}
|
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -455,19 +455,16 @@ async function processMessage(conversationId, messageId, sessionId, content, age
|
|
|
455
455
|
data: { promptSentTime: Date.now(), responseReceivedTime: Date.now() }
|
|
456
456
|
});
|
|
457
457
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
html: true,
|
|
469
|
-
streamUpdatesCount: streamHandler.getUpdateCount()
|
|
470
|
-
};
|
|
458
|
+
console.log(`[processMessage] ACP returned: stopReason=${result?.stopReason}, streamUpdates=${streamHandler.getUpdateCount()}`);
|
|
459
|
+
|
|
460
|
+
// Save agent's complete response as-is, without any processing
|
|
461
|
+
// The agent workflow must flow naturally - no HTML extraction or interference
|
|
462
|
+
const responseText = fullText || result?.result || 'No response.';
|
|
463
|
+
|
|
464
|
+
const messageContent = {
|
|
465
|
+
text: responseText,
|
|
466
|
+
streamUpdatesCount: streamHandler.getUpdateCount()
|
|
467
|
+
};
|
|
471
468
|
|
|
472
469
|
// Save consolidated response to database
|
|
473
470
|
const assistantMessage = queries.createMessage(conversationId, 'assistant', messageContent);
|