@generacy-ai/generacy-plugin-claude-code 0.0.0-preview-20260304013206
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/LICENSE +191 -0
- package/dist/container/container-manager.d.ts +82 -0
- package/dist/container/container-manager.d.ts.map +1 -0
- package/dist/container/container-manager.js +420 -0
- package/dist/container/container-manager.js.map +1 -0
- package/dist/container/types.d.ts +160 -0
- package/dist/container/types.d.ts.map +1 -0
- package/dist/container/types.js +24 -0
- package/dist/container/types.js.map +1 -0
- package/dist/errors.d.ts +106 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +180 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/invocation/invoker.d.ts +59 -0
- package/dist/invocation/invoker.d.ts.map +1 -0
- package/dist/invocation/invoker.js +271 -0
- package/dist/invocation/invoker.js.map +1 -0
- package/dist/invocation/types.d.ts +129 -0
- package/dist/invocation/types.d.ts.map +1 -0
- package/dist/invocation/types.js +57 -0
- package/dist/invocation/types.js.map +1 -0
- package/dist/plugin/claude-code-plugin.d.ts +144 -0
- package/dist/plugin/claude-code-plugin.d.ts.map +1 -0
- package/dist/plugin/claude-code-plugin.js +416 -0
- package/dist/plugin/claude-code-plugin.js.map +1 -0
- package/dist/schemas.d.ts +198 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +75 -0
- package/dist/schemas.js.map +1 -0
- package/dist/session/session-manager.d.ts +117 -0
- package/dist/session/session-manager.d.ts.map +1 -0
- package/dist/session/session-manager.js +243 -0
- package/dist/session/session-manager.js.map +1 -0
- package/dist/session/session.d.ts +99 -0
- package/dist/session/session.d.ts.map +1 -0
- package/dist/session/session.js +271 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/types.d.ts +107 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +33 -0
- package/dist/session/types.js.map +1 -0
- package/dist/streaming/output-parser.d.ts +91 -0
- package/dist/streaming/output-parser.d.ts.map +1 -0
- package/dist/streaming/output-parser.js +321 -0
- package/dist/streaming/output-parser.js.map +1 -0
- package/dist/streaming/output-stream.d.ts +45 -0
- package/dist/streaming/output-stream.d.ts.map +1 -0
- package/dist/streaming/output-stream.js +222 -0
- package/dist/streaming/output-stream.js.map +1 -0
- package/dist/streaming/types.d.ts +89 -0
- package/dist/streaming/types.d.ts.map +1 -0
- package/dist/streaming/types.js +47 -0
- package/dist/streaming/types.js.map +1 -0
- package/dist/types.d.ts +267 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +33 -0
- package/dist/types.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @generacy-ai/generacy-plugin-claude-code
|
|
3
|
+
*
|
|
4
|
+
* Invoker class for executing Claude Code commands.
|
|
5
|
+
*/
|
|
6
|
+
import { randomUUID } from 'crypto';
|
|
7
|
+
import { InvocationTimeoutError, wrapError, } from '../errors.js';
|
|
8
|
+
import { OutputParser } from '../streaming/output-parser.js';
|
|
9
|
+
import { buildClaudeCommand, buildModeCommand, DEFAULT_INVOCATION_TIMEOUT_MS, DEFAULT_MAX_TURNS, } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Invoker class for executing Claude Code commands in containers.
|
|
12
|
+
*/
|
|
13
|
+
export class Invoker {
|
|
14
|
+
containerManager;
|
|
15
|
+
logger;
|
|
16
|
+
invocations = new Map();
|
|
17
|
+
constructor(containerManager, logger) {
|
|
18
|
+
this.containerManager = containerManager;
|
|
19
|
+
this.logger = logger.child({ component: 'Invoker' });
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Execute an invocation in a session's container.
|
|
23
|
+
*/
|
|
24
|
+
async invoke(session, prompt, options = {}) {
|
|
25
|
+
const invocationId = randomUUID();
|
|
26
|
+
const startTime = Date.now();
|
|
27
|
+
this.logger.info({ sessionId: session.id, invocationId, prompt: prompt.slice(0, 100) }, 'Starting invocation');
|
|
28
|
+
// Create invocation tracking
|
|
29
|
+
const invocation = {
|
|
30
|
+
id: invocationId,
|
|
31
|
+
sessionId: session.id,
|
|
32
|
+
prompt,
|
|
33
|
+
options,
|
|
34
|
+
state: { status: 'pending' },
|
|
35
|
+
outputChunks: [],
|
|
36
|
+
createdAt: new Date(),
|
|
37
|
+
filesModified: [],
|
|
38
|
+
};
|
|
39
|
+
this.invocations.set(invocationId, invocation);
|
|
40
|
+
try {
|
|
41
|
+
// Set mode if specified
|
|
42
|
+
if (options.mode) {
|
|
43
|
+
await this.setMode(session.id, options.mode);
|
|
44
|
+
}
|
|
45
|
+
// Update state to executing
|
|
46
|
+
invocation.state = { status: 'executing', startedAt: new Date() };
|
|
47
|
+
session.onInvocationStarted(invocationId);
|
|
48
|
+
// Build and execute command
|
|
49
|
+
const commandOptions = {
|
|
50
|
+
prompt,
|
|
51
|
+
headless: true,
|
|
52
|
+
outputFormat: 'json',
|
|
53
|
+
tools: options.tools,
|
|
54
|
+
context: options.context,
|
|
55
|
+
workdir: session.containerConfig.workdir,
|
|
56
|
+
maxTurns: DEFAULT_MAX_TURNS,
|
|
57
|
+
print: 'all',
|
|
58
|
+
};
|
|
59
|
+
const result = await this.executeCommand(session.id, buildClaudeCommand(commandOptions), {
|
|
60
|
+
timeout: options.timeout ?? DEFAULT_INVOCATION_TIMEOUT_MS,
|
|
61
|
+
onOutput: (chunk) => {
|
|
62
|
+
invocation.outputChunks.push(chunk);
|
|
63
|
+
this.handleOutputChunk(session, chunk);
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
// Build invocation result
|
|
67
|
+
const invocationResult = this.buildResult(invocationId, session.id, result, startTime);
|
|
68
|
+
// Update state
|
|
69
|
+
invocation.state = { status: 'completed', result: invocationResult };
|
|
70
|
+
invocation.completedAt = new Date();
|
|
71
|
+
// Update session state
|
|
72
|
+
session.onInvocationCompleted();
|
|
73
|
+
this.logger.info({
|
|
74
|
+
sessionId: session.id,
|
|
75
|
+
invocationId,
|
|
76
|
+
exitCode: result.exitCode,
|
|
77
|
+
duration: invocationResult.duration,
|
|
78
|
+
}, 'Invocation completed');
|
|
79
|
+
return invocationResult;
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
const wrappedError = wrapError(error);
|
|
83
|
+
// Update invocation state
|
|
84
|
+
invocation.state = { status: 'failed', error: wrappedError };
|
|
85
|
+
invocation.completedAt = new Date();
|
|
86
|
+
// Update session state
|
|
87
|
+
session.onInvocationCompleted();
|
|
88
|
+
this.logger.error({ sessionId: session.id, invocationId, error: wrappedError }, 'Invocation failed');
|
|
89
|
+
// Return failed result
|
|
90
|
+
return {
|
|
91
|
+
success: false,
|
|
92
|
+
sessionId: session.id,
|
|
93
|
+
invocationId,
|
|
94
|
+
exitCode: -1,
|
|
95
|
+
duration: Date.now() - startTime,
|
|
96
|
+
error: wrappedError.toInvocationError(),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Set the Agency mode in a container.
|
|
102
|
+
*/
|
|
103
|
+
async setMode(sessionId, mode, options = { mode }) {
|
|
104
|
+
this.logger.info({ sessionId, mode }, 'Setting Agency mode');
|
|
105
|
+
const result = await this.containerManager.exec(sessionId, buildModeCommand(mode), { timeout: options.timeout ?? 30000 });
|
|
106
|
+
if (result.exitCode !== 0) {
|
|
107
|
+
this.logger.warn({ sessionId, mode, exitCode: result.exitCode, stderr: result.stderr }, 'Failed to set mode');
|
|
108
|
+
throw new Error(`Failed to set mode ${mode}: ${result.stderr || 'Unknown error'}`);
|
|
109
|
+
}
|
|
110
|
+
this.logger.debug({ sessionId, mode }, 'Mode set successfully');
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Execute a command in a container.
|
|
114
|
+
*/
|
|
115
|
+
async executeCommand(sessionId, cmd, options = {}) {
|
|
116
|
+
const startTime = Date.now();
|
|
117
|
+
const timeout = options.timeout ?? DEFAULT_INVOCATION_TIMEOUT_MS;
|
|
118
|
+
this.logger.debug({ sessionId, cmd: cmd.join(' ') }, 'Executing command');
|
|
119
|
+
try {
|
|
120
|
+
const result = await this.containerManager.exec(sessionId, cmd, { timeout });
|
|
121
|
+
// Parse output
|
|
122
|
+
const parser = new OutputParser();
|
|
123
|
+
const chunks = [];
|
|
124
|
+
// Parse stdout
|
|
125
|
+
if (result.stdout) {
|
|
126
|
+
const stdoutChunks = parser.parseChunk(result.stdout);
|
|
127
|
+
for (const chunk of stdoutChunks) {
|
|
128
|
+
chunks.push(chunk);
|
|
129
|
+
options.onOutput?.(chunk);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Flush remaining
|
|
133
|
+
const remaining = parser.flush();
|
|
134
|
+
for (const chunk of remaining) {
|
|
135
|
+
chunks.push(chunk);
|
|
136
|
+
options.onOutput?.(chunk);
|
|
137
|
+
}
|
|
138
|
+
// Add stderr as error chunk if present
|
|
139
|
+
if (result.stderr && result.exitCode !== 0) {
|
|
140
|
+
const errorChunk = parser.createErrorChunk(result.stderr);
|
|
141
|
+
chunks.push(errorChunk);
|
|
142
|
+
options.onOutput?.(errorChunk);
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
exitCode: result.exitCode,
|
|
146
|
+
stdout: result.stdout,
|
|
147
|
+
stderr: result.stderr,
|
|
148
|
+
chunks,
|
|
149
|
+
duration: Date.now() - startTime,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
const wrappedError = wrapError(error);
|
|
154
|
+
if (wrappedError.message.includes('timed out')) {
|
|
155
|
+
throw new InvocationTimeoutError(sessionId, 'exec', timeout);
|
|
156
|
+
}
|
|
157
|
+
throw wrappedError;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Get invocation data by ID.
|
|
162
|
+
*/
|
|
163
|
+
getInvocation(invocationId) {
|
|
164
|
+
return this.invocations.get(invocationId);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Get all invocations for a session.
|
|
168
|
+
*/
|
|
169
|
+
getSessionInvocations(sessionId) {
|
|
170
|
+
return Array.from(this.invocations.values()).filter((inv) => inv.sessionId === sessionId);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Clean up invocations for a session.
|
|
174
|
+
*/
|
|
175
|
+
cleanupSession(sessionId) {
|
|
176
|
+
for (const [id, invocation] of this.invocations) {
|
|
177
|
+
if (invocation.sessionId === sessionId) {
|
|
178
|
+
this.invocations.delete(id);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Handle an output chunk during execution.
|
|
184
|
+
*/
|
|
185
|
+
handleOutputChunk(session, chunk) {
|
|
186
|
+
// Check for question
|
|
187
|
+
if (chunk.type === 'question') {
|
|
188
|
+
const question = chunk.data;
|
|
189
|
+
this.logger.info({ sessionId: session.id, question: question.question }, 'Question received during invocation');
|
|
190
|
+
// Transition session to awaiting_input
|
|
191
|
+
session.onQuestionReceived({
|
|
192
|
+
question: question.question,
|
|
193
|
+
urgency: question.urgency,
|
|
194
|
+
choices: question.choices,
|
|
195
|
+
askedAt: question.askedAt,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
// Track file modifications
|
|
199
|
+
if (chunk.type === 'tool_result' && chunk.metadata?.filePath) {
|
|
200
|
+
const invocation = this.getCurrentInvocation(session.id);
|
|
201
|
+
if (invocation && !invocation.filesModified.includes(chunk.metadata.filePath)) {
|
|
202
|
+
invocation.filesModified.push(chunk.metadata.filePath);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Get the current executing invocation for a session.
|
|
208
|
+
*/
|
|
209
|
+
getCurrentInvocation(sessionId) {
|
|
210
|
+
for (const invocation of this.invocations.values()) {
|
|
211
|
+
if (invocation.sessionId === sessionId &&
|
|
212
|
+
invocation.state.status === 'executing') {
|
|
213
|
+
return invocation;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Build an InvocationResult from command result.
|
|
220
|
+
*/
|
|
221
|
+
buildResult(invocationId, sessionId, result, startTime) {
|
|
222
|
+
const success = result.exitCode === 0;
|
|
223
|
+
// Extract summary from completion chunk
|
|
224
|
+
let summary;
|
|
225
|
+
const completeChunk = result.chunks.find((c) => c.type === 'complete');
|
|
226
|
+
if (completeChunk) {
|
|
227
|
+
const data = completeChunk.data;
|
|
228
|
+
summary = data.summary;
|
|
229
|
+
}
|
|
230
|
+
// Collect modified files from tool results
|
|
231
|
+
const filesModified = [];
|
|
232
|
+
for (const chunk of result.chunks) {
|
|
233
|
+
if (chunk.type === 'tool_result' && chunk.metadata?.filePath) {
|
|
234
|
+
if (!filesModified.includes(chunk.metadata.filePath)) {
|
|
235
|
+
filesModified.push(chunk.metadata.filePath);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
// Build error if failed
|
|
240
|
+
let error = undefined;
|
|
241
|
+
if (!success) {
|
|
242
|
+
const errorChunk = result.chunks.find((c) => c.type === 'error');
|
|
243
|
+
if (errorChunk) {
|
|
244
|
+
const data = errorChunk.data;
|
|
245
|
+
error = {
|
|
246
|
+
code: (data.code ?? 'UNKNOWN'),
|
|
247
|
+
isTransient: data.isTransient ?? false,
|
|
248
|
+
message: data.message ?? result.stderr ?? 'Unknown error',
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
else if (result.stderr) {
|
|
252
|
+
error = {
|
|
253
|
+
code: 'UNKNOWN',
|
|
254
|
+
isTransient: false,
|
|
255
|
+
message: result.stderr,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return {
|
|
260
|
+
success,
|
|
261
|
+
sessionId,
|
|
262
|
+
invocationId,
|
|
263
|
+
exitCode: result.exitCode,
|
|
264
|
+
summary,
|
|
265
|
+
filesModified: filesModified.length > 0 ? filesModified : undefined,
|
|
266
|
+
duration: Date.now() - startTime,
|
|
267
|
+
error,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
//# sourceMappingURL=invoker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoker.js","sourceRoot":"","sources":["../../src/invocation/invoker.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAIpC,OAAO,EACL,sBAAsB,EACtB,SAAS,GACV,MAAM,cAAc,CAAC;AAMtB,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAO7D,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,6BAA6B,EAC7B,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,OAAO,OAAO;IACD,gBAAgB,CAAmB;IACnC,MAAM,CAAS;IACf,WAAW,GAAgC,IAAI,GAAG,EAAE,CAAC;IAEtE,YAAY,gBAAkC,EAAE,MAAc;QAC5D,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;IACvD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CACV,OAAgB,EAChB,MAAc,EACd,UAAyB,EAAE;QAE3B,MAAM,YAAY,GAAG,UAAU,EAAE,CAAC;QAClC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE7B,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EACrE,q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O,IAAI,MAAM,CAAC,MAAM,IAAI,eAAe;iBAC1D,CAAC;YACJ,CAAC;iBAAM,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;gBACzB,KAAK,GAAG;oBACN,IAAI,EAAE,SAAkB;oBACxB,WAAW,EAAE,KAAK;oBAClB,OAAO,EAAE,MAAM,CAAC,MAAM;iBACvB,CAAC;YACJ,CAAC;QACH,CAAC;QAED,OAAO;YACL,OAAO;YACP,SAAS;YACT,YAAY;YACZ,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,OAAO;YACP,aAAa,EAAE,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS;YACnE,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;YAChC,KAAK;SACN,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @generacy-ai/generacy-plugin-claude-code
|
|
3
|
+
*
|
|
4
|
+
* Internal types for invocation management.
|
|
5
|
+
*/
|
|
6
|
+
import type { InvokeParams, InvokeOptions, InvocationResult, OutputChunk } from '../types.js';
|
|
7
|
+
export type { InvokeParams, InvokeOptions, InvocationResult, OutputChunk, };
|
|
8
|
+
/**
|
|
9
|
+
* Internal state of an invocation.
|
|
10
|
+
*/
|
|
11
|
+
export type InvocationState = {
|
|
12
|
+
status: 'pending';
|
|
13
|
+
} | {
|
|
14
|
+
status: 'executing';
|
|
15
|
+
startedAt: Date;
|
|
16
|
+
} | {
|
|
17
|
+
status: 'awaiting_input';
|
|
18
|
+
question: string;
|
|
19
|
+
} | {
|
|
20
|
+
status: 'completed';
|
|
21
|
+
result: InvocationResult;
|
|
22
|
+
} | {
|
|
23
|
+
status: 'failed';
|
|
24
|
+
error: Error;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Invocation status type.
|
|
28
|
+
*/
|
|
29
|
+
export type InvocationStatus = InvocationState['status'];
|
|
30
|
+
/**
|
|
31
|
+
* Internal invocation tracking data.
|
|
32
|
+
*/
|
|
33
|
+
export interface InvocationData {
|
|
34
|
+
/** Unique invocation identifier */
|
|
35
|
+
id: string;
|
|
36
|
+
/** Session ID this invocation belongs to */
|
|
37
|
+
sessionId: string;
|
|
38
|
+
/** The prompt being executed */
|
|
39
|
+
prompt: string;
|
|
40
|
+
/** Options for this invocation */
|
|
41
|
+
options: InvokeOptions;
|
|
42
|
+
/** Current state */
|
|
43
|
+
state: InvocationState;
|
|
44
|
+
/** Output chunks collected during execution */
|
|
45
|
+
outputChunks: OutputChunk[];
|
|
46
|
+
/** When the invocation was created */
|
|
47
|
+
createdAt: Date;
|
|
48
|
+
/** When the invocation completed (if completed) */
|
|
49
|
+
completedAt?: Date;
|
|
50
|
+
/** Files modified during invocation */
|
|
51
|
+
filesModified: string[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Options for executing a command in the container.
|
|
55
|
+
*/
|
|
56
|
+
export interface ExecuteOptions {
|
|
57
|
+
/** Working directory for the command */
|
|
58
|
+
workdir?: string;
|
|
59
|
+
/** Environment variables to set */
|
|
60
|
+
env?: Record<string, string>;
|
|
61
|
+
/** Timeout in milliseconds */
|
|
62
|
+
timeout?: number;
|
|
63
|
+
/** Callback for output chunks */
|
|
64
|
+
onOutput?: (chunk: OutputChunk) => void;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Command builder options for Claude Code CLI.
|
|
68
|
+
*/
|
|
69
|
+
export interface CommandBuilderOptions {
|
|
70
|
+
/** The prompt to execute */
|
|
71
|
+
prompt: string;
|
|
72
|
+
/** Use headless mode (no interactive terminal) */
|
|
73
|
+
headless?: boolean;
|
|
74
|
+
/** Output format (json for structured output) */
|
|
75
|
+
outputFormat?: 'json' | 'text';
|
|
76
|
+
/** Tool whitelist */
|
|
77
|
+
tools?: string[];
|
|
78
|
+
/** Additional context to pass */
|
|
79
|
+
context?: string;
|
|
80
|
+
/** Working directory */
|
|
81
|
+
workdir?: string;
|
|
82
|
+
/** Resume session ID (for continuing previous session) */
|
|
83
|
+
resumeSession?: string;
|
|
84
|
+
/** Maximum turns/iterations */
|
|
85
|
+
maxTurns?: number;
|
|
86
|
+
/** Print output mode */
|
|
87
|
+
print?: 'all' | 'assistant' | 'none';
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Result of command execution.
|
|
91
|
+
*/
|
|
92
|
+
export interface CommandResult {
|
|
93
|
+
/** Exit code from the command */
|
|
94
|
+
exitCode: number;
|
|
95
|
+
/** Standard output */
|
|
96
|
+
stdout: string;
|
|
97
|
+
/** Standard error */
|
|
98
|
+
stderr: string;
|
|
99
|
+
/** Parsed output chunks */
|
|
100
|
+
chunks: OutputChunk[];
|
|
101
|
+
/** Duration in milliseconds */
|
|
102
|
+
duration: number;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Mode setting options.
|
|
106
|
+
*/
|
|
107
|
+
export interface SetModeOptions {
|
|
108
|
+
/** The mode to set */
|
|
109
|
+
mode: string;
|
|
110
|
+
/** Timeout for mode setting command */
|
|
111
|
+
timeout?: number;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Default invocation timeout (5 minutes).
|
|
115
|
+
*/
|
|
116
|
+
export declare const DEFAULT_INVOCATION_TIMEOUT_MS = 300000;
|
|
117
|
+
/**
|
|
118
|
+
* Default max turns for Claude Code.
|
|
119
|
+
*/
|
|
120
|
+
export declare const DEFAULT_MAX_TURNS = 100;
|
|
121
|
+
/**
|
|
122
|
+
* Build the Claude Code command array.
|
|
123
|
+
*/
|
|
124
|
+
export declare function buildClaudeCommand(options: CommandBuilderOptions): string[];
|
|
125
|
+
/**
|
|
126
|
+
* Build the Agency mode set command.
|
|
127
|
+
*/
|
|
128
|
+
export declare function buildModeCommand(mode: string): string[];
|
|
129
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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AAM,6BAA6B,SAAS,CAAC;AAEpD;;GAEG;AACH,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,qBAAqB,GAAG,MAAM,EAAE,CA0C3E;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAEvD"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @generacy-ai/generacy-plugin-claude-code
|
|
3
|
+
*
|
|
4
|
+
* Internal types for invocation management.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Default invocation timeout (5 minutes).
|
|
8
|
+
*/
|
|
9
|
+
export const DEFAULT_INVOCATION_TIMEOUT_MS = 300000;
|
|
10
|
+
/**
|
|
11
|
+
* Default max turns for Claude Code.
|
|
12
|
+
*/
|
|
13
|
+
export const DEFAULT_MAX_TURNS = 100;
|
|
14
|
+
/**
|
|
15
|
+
* Build the Claude Code command array.
|
|
16
|
+
*/
|
|
17
|
+
export function buildClaudeCommand(options) {
|
|
18
|
+
const cmd = ['claude'];
|
|
19
|
+
// Headless mode for non-interactive execution
|
|
20
|
+
if (options.headless !== false) {
|
|
21
|
+
cmd.push('--headless');
|
|
22
|
+
}
|
|
23
|
+
// Output format
|
|
24
|
+
if (options.outputFormat === 'json') {
|
|
25
|
+
cmd.push('--output', 'json');
|
|
26
|
+
}
|
|
27
|
+
// Print mode
|
|
28
|
+
if (options.print) {
|
|
29
|
+
cmd.push('--print', options.print);
|
|
30
|
+
}
|
|
31
|
+
// Max turns
|
|
32
|
+
if (options.maxTurns) {
|
|
33
|
+
cmd.push('--max-turns', String(options.maxTurns));
|
|
34
|
+
}
|
|
35
|
+
// Tool whitelist
|
|
36
|
+
if (options.tools && options.tools.length > 0) {
|
|
37
|
+
cmd.push('--allowedTools', options.tools.join(','));
|
|
38
|
+
}
|
|
39
|
+
// Resume session
|
|
40
|
+
if (options.resumeSession) {
|
|
41
|
+
cmd.push('--resume', options.resumeSession);
|
|
42
|
+
}
|
|
43
|
+
// Working directory
|
|
44
|
+
if (options.workdir) {
|
|
45
|
+
cmd.push('--cwd', options.workdir);
|
|
46
|
+
}
|
|
47
|
+
// Prompt (must be last)
|
|
48
|
+
cmd.push('--prompt', options.prompt);
|
|
49
|
+
return cmd;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Build the Agency mode set command.
|
|
53
|
+
*/
|
|
54
|
+
export function buildModeCommand(mode) {
|
|
55
|
+
return ['agency', 'mode', 'set', mode];
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/invocation/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAgJH;;GAEG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,MAAM,CAAC;AAEpD;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAErC;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAA8B;IAC/D,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEvB,8CAA8C;IAC9C,IAAI,OAAO,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC;QAC/B,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACzB,CAAC;IAED,gBAAgB;IAChB,IAAI,OAAO,CAAC,YAAY,KAAK,MAAM,EAAE,CAAC;QACpC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC/B,CAAC;IAED,aAAa;IACb,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QAClB,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;IAED,YAAY;IACZ,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACrB,GAAG,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IACpD,CAAC;IAED,iBAAiB;IACjB,IAAI,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9C,GAAG,CAAC,IAAI,CAAC,gBAAgB,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACtD,CAAC;IAED,iBAAiB;IACjB,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;QAC1B,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IAC9C,CAAC;IAED,oBAAoB;IACpB,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAED,wBAAwB;IACxB,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAErC,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @generacy-ai/generacy-plugin-claude-code
|
|
3
|
+
*
|
|
4
|
+
* Main plugin class extending AbstractDevAgentPlugin for Claude Code agent invocation.
|
|
5
|
+
*/
|
|
6
|
+
import Docker from 'dockerode';
|
|
7
|
+
import pino from 'pino';
|
|
8
|
+
import type { Logger } from 'pino';
|
|
9
|
+
import type { AgentResult, AgentCapabilities, StreamChunk } from '@generacy-ai/latency';
|
|
10
|
+
import { AbstractDevAgentPlugin, type InternalInvokeOptions } from '@generacy-ai/latency-plugin-dev-agent';
|
|
11
|
+
import type { Session as SessionInterface, ContainerConfig, InvokeParams, InvokeOptions as ClaudeInvokeOptions, InvocationResult, OutputChunk } from '../types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Configuration options for ClaudeCodePlugin.
|
|
14
|
+
*/
|
|
15
|
+
export interface ClaudeCodePluginOptions {
|
|
16
|
+
/** Docker client options or instance */
|
|
17
|
+
docker?: Docker | Docker.DockerOptions;
|
|
18
|
+
/** Logger instance or pino options */
|
|
19
|
+
logger?: Logger | pino.LoggerOptions;
|
|
20
|
+
/** Session timeout in milliseconds */
|
|
21
|
+
sessionTimeoutMs?: number;
|
|
22
|
+
/** Maximum concurrent sessions */
|
|
23
|
+
maxSessions?: number;
|
|
24
|
+
/** Default container configuration */
|
|
25
|
+
defaultContainerConfig?: Partial<ContainerConfig>;
|
|
26
|
+
/** Default invocation options */
|
|
27
|
+
defaultInvokeOptions?: ClaudeInvokeOptions;
|
|
28
|
+
/** Default timeout for DevAgent invoke operations */
|
|
29
|
+
defaultTimeoutMs?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* ClaudeCodePlugin - Main plugin class for Claude Code agent invocation.
|
|
33
|
+
*
|
|
34
|
+
* Extends AbstractDevAgentPlugin to provide the standard DevAgent interface
|
|
35
|
+
* while also exposing Docker container session management functionality.
|
|
36
|
+
*
|
|
37
|
+
* Provides a thin interface for invoking Claude Code agents in isolated
|
|
38
|
+
* Docker containers, with session management, output streaming, and
|
|
39
|
+
* integration with the Humancy decision framework.
|
|
40
|
+
*/
|
|
41
|
+
export declare class ClaudeCodePlugin extends AbstractDevAgentPlugin {
|
|
42
|
+
private readonly docker;
|
|
43
|
+
private readonly logger;
|
|
44
|
+
private readonly containerManager;
|
|
45
|
+
private readonly sessionManager;
|
|
46
|
+
private readonly invoker;
|
|
47
|
+
private readonly defaultContainerConfig;
|
|
48
|
+
private readonly defaultClaudeInvokeOptions;
|
|
49
|
+
private disposed;
|
|
50
|
+
constructor(options?: ClaudeCodePluginOptions);
|
|
51
|
+
/**
|
|
52
|
+
* Invoke Claude Code with a prompt (implements abstract method).
|
|
53
|
+
*
|
|
54
|
+
* Creates an ephemeral Docker container session, runs the prompt,
|
|
55
|
+
* and returns the complete result.
|
|
56
|
+
*/
|
|
57
|
+
protected doInvoke(prompt: string, options: InternalInvokeOptions): Promise<AgentResult>;
|
|
58
|
+
/**
|
|
59
|
+
* Stream Claude Code output (implements abstract method).
|
|
60
|
+
*
|
|
61
|
+
* Creates an ephemeral Docker container session and yields output chunks.
|
|
62
|
+
*/
|
|
63
|
+
protected doInvokeStream(prompt: string, options: InternalInvokeOptions): AsyncIterableIterator<StreamChunk>;
|
|
64
|
+
/**
|
|
65
|
+
* Return Claude Code capabilities (implements abstract method).
|
|
66
|
+
*/
|
|
67
|
+
protected doGetCapabilities(): Promise<AgentCapabilities>;
|
|
68
|
+
/**
|
|
69
|
+
* Invoke Claude Code with parameters.
|
|
70
|
+
* Creates an ephemeral session if no sessionId provided.
|
|
71
|
+
*/
|
|
72
|
+
invokeWithParams(params: InvokeParams): Promise<InvocationResult>;
|
|
73
|
+
/**
|
|
74
|
+
* Convenience method for simple prompt invocation.
|
|
75
|
+
*/
|
|
76
|
+
invokeWithPrompt(prompt: string, options?: ClaudeInvokeOptions): Promise<InvocationResult>;
|
|
77
|
+
/**
|
|
78
|
+
* Start a new session with the given container configuration.
|
|
79
|
+
*/
|
|
80
|
+
startSession(container: ContainerConfig): Promise<SessionInterface>;
|
|
81
|
+
/**
|
|
82
|
+
* Continue an existing session with a new prompt.
|
|
83
|
+
* Used to provide answers to questions.
|
|
84
|
+
*/
|
|
85
|
+
continueSession(sessionId: string, prompt: string): Promise<InvocationResult>;
|
|
86
|
+
/**
|
|
87
|
+
* End a session and clean up resources.
|
|
88
|
+
*/
|
|
89
|
+
endSession(sessionId: string): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Stream output from an active session.
|
|
92
|
+
* Yields OutputChunks as they are received from the agent.
|
|
93
|
+
*/
|
|
94
|
+
streamOutput(sessionId: string): AsyncIterable<OutputChunk>;
|
|
95
|
+
/**
|
|
96
|
+
* Set the Agency mode for a session.
|
|
97
|
+
* Must be called before invoke for mode to take effect.
|
|
98
|
+
*/
|
|
99
|
+
setMode(sessionId: string, mode: string): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Get a session by ID.
|
|
102
|
+
*/
|
|
103
|
+
getSession(sessionId: string): SessionInterface;
|
|
104
|
+
/**
|
|
105
|
+
* Check if a session exists.
|
|
106
|
+
*/
|
|
107
|
+
hasSession(sessionId: string): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* List all active sessions.
|
|
110
|
+
*/
|
|
111
|
+
listSessions(): SessionInterface[];
|
|
112
|
+
/**
|
|
113
|
+
* Get session count.
|
|
114
|
+
*/
|
|
115
|
+
getSessionCount(): {
|
|
116
|
+
active: number;
|
|
117
|
+
total: number;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Dispose of the plugin and cleanup all resources.
|
|
121
|
+
*/
|
|
122
|
+
dispose(): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Check if the plugin is disposed.
|
|
125
|
+
*/
|
|
126
|
+
isPluginDisposed(): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Internal method to start a session.
|
|
129
|
+
*/
|
|
130
|
+
private startSessionInternal;
|
|
131
|
+
/**
|
|
132
|
+
* Create an ephemeral container configuration.
|
|
133
|
+
*/
|
|
134
|
+
private createEphemeralContainerConfig;
|
|
135
|
+
/**
|
|
136
|
+
* Get output stream for a session.
|
|
137
|
+
*/
|
|
138
|
+
private getSessionOutputStream;
|
|
139
|
+
/**
|
|
140
|
+
* Ensure the plugin is not disposed.
|
|
141
|
+
*/
|
|
142
|
+
private ensureNotDisposed;
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=claude-code-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-code-plugin.d.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