agentgui 1.0.61 → 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.
Files changed (2) hide show
  1. package/acp-launcher.js +67 -35
  2. package/package.json +1 -1
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 Claude Code SDK (${agentType})`);
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: SYSTEM_PROMPT };
49
+ return { context: 'Using Claude Code SDK with real plugins' };
33
50
  }
34
51
 
35
52
  async sendPrompt(prompt) {
36
- let fullResponse = '';
53
+ const promptText = typeof prompt === 'string' ? prompt : prompt.map(p => p.text).join('\n');
37
54
 
38
55
  try {
39
- const promptText = typeof prompt === 'string' ? prompt : prompt.map(p => p.text).join('\n');
40
- const systemMessage = `${SYSTEM_PROMPT}\n\nUser Request: ${promptText}`;
41
-
42
- const response = query({
43
- prompt: systemMessage,
44
- options: {}
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
- // query() returns an async iterable
48
- // Iterate through all messages and collect the response
49
- for await (const message of response) {
50
- // Try multiple content paths: direct .content or .message.content
51
- let content = message.content || message.message?.content;
52
-
53
- if (content && Array.isArray(content)) {
54
- const textChunks = content.map(c => c.text || '').join('');
55
- fullResponse += textChunks;
56
-
57
- // Emit update for real-time display
58
- if (this.onUpdate && textChunks) {
59
- this.onUpdate({
60
- update: {
61
- sessionUpdate: 'agent_message_chunk',
62
- content: { text: textChunks }
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 nothing was collected
70
- if (!fullResponse) {
71
- fullResponse = 'No response from agent';
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
- return;
117
+ console.log(`[ACP] Terminating session ${this.sessionId}`);
118
+ return { terminated: true };
87
119
  }
88
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentgui",
3
- "version": "1.0.61",
3
+ "version": "1.0.62",
4
4
  "description": "Multi-agent ACP client with real-time communication",
5
5
  "type": "module",
6
6
  "main": "server.js",