@gracefultools/astrid-sdk 0.6.1 → 0.7.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/bin/cli.js +170 -47
- package/dist/bin/cli.js.map +1 -1
- package/dist/executors/terminal-base.d.ts +105 -0
- package/dist/executors/terminal-base.d.ts.map +1 -0
- package/dist/executors/terminal-base.js +113 -0
- package/dist/executors/terminal-base.js.map +1 -0
- package/dist/executors/terminal-claude.d.ts +16 -28
- package/dist/executors/terminal-claude.d.ts.map +1 -1
- package/dist/executors/terminal-claude.js +122 -75
- package/dist/executors/terminal-claude.js.map +1 -1
- package/dist/executors/terminal-executors.test.d.ts +8 -0
- package/dist/executors/terminal-executors.test.d.ts.map +1 -0
- package/dist/executors/terminal-executors.test.js +279 -0
- package/dist/executors/terminal-executors.test.js.map +1 -0
- package/dist/executors/terminal-gemini.d.ts +48 -0
- package/dist/executors/terminal-gemini.d.ts.map +1 -0
- package/dist/executors/terminal-gemini.js +509 -0
- package/dist/executors/terminal-gemini.js.map +1 -0
- package/dist/executors/terminal-openai.d.ts +48 -0
- package/dist/executors/terminal-openai.d.ts.map +1 -0
- package/dist/executors/terminal-openai.js +531 -0
- package/dist/executors/terminal-openai.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/package.json +7 -5
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Terminal Gemini Executor
|
|
4
|
+
*
|
|
5
|
+
* Executes tasks using Gemini API with local tool execution.
|
|
6
|
+
* This enables running tasks assigned to gemini@astrid.cc in terminal mode.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.terminalGeminiExecutor = exports.TerminalGeminiExecutor = void 0;
|
|
43
|
+
const fs = __importStar(require("fs/promises"));
|
|
44
|
+
const path = __importStar(require("path"));
|
|
45
|
+
const child_process_1 = require("child_process");
|
|
46
|
+
const glob_1 = require("glob");
|
|
47
|
+
const terminal_base_js_1 = require("./terminal-base.js");
|
|
48
|
+
const agent_config_js_1 = require("../utils/agent-config.js");
|
|
49
|
+
// ============================================================================
|
|
50
|
+
// TOOL DEFINITIONS (same as gemini.ts)
|
|
51
|
+
// ============================================================================
|
|
52
|
+
const TOOL_DECLARATIONS = [
|
|
53
|
+
{
|
|
54
|
+
name: 'read_file',
|
|
55
|
+
description: 'Read the contents of a file',
|
|
56
|
+
parameters: {
|
|
57
|
+
type: 'object',
|
|
58
|
+
properties: {
|
|
59
|
+
file_path: { type: 'string', description: 'Path to the file' }
|
|
60
|
+
},
|
|
61
|
+
required: ['file_path']
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'write_file',
|
|
66
|
+
description: 'Write content to a file (creates or overwrites)',
|
|
67
|
+
parameters: {
|
|
68
|
+
type: 'object',
|
|
69
|
+
properties: {
|
|
70
|
+
file_path: { type: 'string', description: 'Path to the file' },
|
|
71
|
+
content: { type: 'string', description: 'Content to write' }
|
|
72
|
+
},
|
|
73
|
+
required: ['file_path', 'content']
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: 'edit_file',
|
|
78
|
+
description: 'Edit a file by replacing old_string with new_string',
|
|
79
|
+
parameters: {
|
|
80
|
+
type: 'object',
|
|
81
|
+
properties: {
|
|
82
|
+
file_path: { type: 'string', description: 'Path to the file' },
|
|
83
|
+
old_string: { type: 'string', description: 'String to find' },
|
|
84
|
+
new_string: { type: 'string', description: 'Replacement string' }
|
|
85
|
+
},
|
|
86
|
+
required: ['file_path', 'old_string', 'new_string']
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: 'run_bash',
|
|
91
|
+
description: 'Run a bash command',
|
|
92
|
+
parameters: {
|
|
93
|
+
type: 'object',
|
|
94
|
+
properties: {
|
|
95
|
+
command: { type: 'string', description: 'The bash command' }
|
|
96
|
+
},
|
|
97
|
+
required: ['command']
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: 'glob_files',
|
|
102
|
+
description: 'Find files matching a glob pattern',
|
|
103
|
+
parameters: {
|
|
104
|
+
type: 'object',
|
|
105
|
+
properties: {
|
|
106
|
+
pattern: { type: 'string', description: 'Glob pattern' }
|
|
107
|
+
},
|
|
108
|
+
required: ['pattern']
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: 'grep_search',
|
|
113
|
+
description: 'Search for a pattern in files',
|
|
114
|
+
parameters: {
|
|
115
|
+
type: 'object',
|
|
116
|
+
properties: {
|
|
117
|
+
pattern: { type: 'string', description: 'Search pattern' },
|
|
118
|
+
file_pattern: { type: 'string', description: 'Optional glob pattern' }
|
|
119
|
+
},
|
|
120
|
+
required: ['pattern']
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: 'task_complete',
|
|
125
|
+
description: 'Signal task completion',
|
|
126
|
+
parameters: {
|
|
127
|
+
type: 'object',
|
|
128
|
+
properties: {
|
|
129
|
+
summary: { type: 'string', description: 'Summary of what was done' },
|
|
130
|
+
commit_message: { type: 'string', description: 'Git commit message' },
|
|
131
|
+
pr_title: { type: 'string', description: 'PR title' },
|
|
132
|
+
pr_description: { type: 'string', description: 'PR description' }
|
|
133
|
+
},
|
|
134
|
+
required: ['summary']
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
];
|
|
138
|
+
// Dangerous commands that should be blocked
|
|
139
|
+
const DANGEROUS_COMMANDS = ['rm -rf /', 'sudo', '> /dev/', 'mkfs', 'dd if='];
|
|
140
|
+
async function executeTool(name, args, repoPath) {
|
|
141
|
+
try {
|
|
142
|
+
switch (name) {
|
|
143
|
+
case 'read_file': {
|
|
144
|
+
const filePath = path.join(repoPath, args.file_path);
|
|
145
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
146
|
+
return { success: true, result: content };
|
|
147
|
+
}
|
|
148
|
+
case 'write_file': {
|
|
149
|
+
const filePath = path.join(repoPath, args.file_path);
|
|
150
|
+
const content = args.content;
|
|
151
|
+
let action = 'create';
|
|
152
|
+
try {
|
|
153
|
+
await fs.access(filePath);
|
|
154
|
+
action = 'modify';
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
158
|
+
}
|
|
159
|
+
await fs.writeFile(filePath, content, 'utf-8');
|
|
160
|
+
return {
|
|
161
|
+
success: true,
|
|
162
|
+
result: `File ${action === 'create' ? 'created' : 'updated'}: ${args.file_path}`,
|
|
163
|
+
fileChange: { path: args.file_path, content, action }
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
case 'edit_file': {
|
|
167
|
+
const filePath = path.join(repoPath, args.file_path);
|
|
168
|
+
const oldContent = await fs.readFile(filePath, 'utf-8');
|
|
169
|
+
const oldString = args.old_string;
|
|
170
|
+
const newString = args.new_string;
|
|
171
|
+
if (!oldContent.includes(oldString)) {
|
|
172
|
+
return { success: false, result: `Error: Could not find string in file` };
|
|
173
|
+
}
|
|
174
|
+
const newContent = oldContent.replace(oldString, newString);
|
|
175
|
+
await fs.writeFile(filePath, newContent, 'utf-8');
|
|
176
|
+
return {
|
|
177
|
+
success: true,
|
|
178
|
+
result: `File edited: ${args.file_path}`,
|
|
179
|
+
fileChange: { path: args.file_path, content: newContent, action: 'modify' }
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
case 'run_bash': {
|
|
183
|
+
const command = args.command;
|
|
184
|
+
if (DANGEROUS_COMMANDS.some(d => command.includes(d))) {
|
|
185
|
+
return { success: false, result: 'Error: Command blocked by safety policy' };
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
const output = (0, child_process_1.execSync)(command, {
|
|
189
|
+
cwd: repoPath,
|
|
190
|
+
encoding: 'utf-8',
|
|
191
|
+
timeout: 120000, // 2 minute timeout
|
|
192
|
+
maxBuffer: 1024 * 1024
|
|
193
|
+
});
|
|
194
|
+
return { success: true, result: output || '(no output)' };
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
const err = error;
|
|
198
|
+
return { success: false, result: `Error: ${err.stderr || err.message}` };
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
case 'glob_files': {
|
|
202
|
+
const pattern = args.pattern;
|
|
203
|
+
const files = await (0, glob_1.glob)(pattern, { cwd: repoPath, nodir: true });
|
|
204
|
+
return { success: true, result: files.slice(0, 100).join('\n') || '(no matches)' };
|
|
205
|
+
}
|
|
206
|
+
case 'grep_search': {
|
|
207
|
+
const pattern = args.pattern;
|
|
208
|
+
const filePattern = args.file_pattern || '.';
|
|
209
|
+
try {
|
|
210
|
+
const output = (0, child_process_1.execSync)(`grep -rn "${pattern.replace(/"/g, '\\"')}" ${filePattern} | head -50`, { cwd: repoPath, encoding: 'utf-8', timeout: 30000 });
|
|
211
|
+
return { success: true, result: output || '(no matches)' };
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
return { success: true, result: '(no matches)' };
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
case 'task_complete':
|
|
218
|
+
return { success: true, result: 'Task marked complete' };
|
|
219
|
+
default:
|
|
220
|
+
return { success: false, result: `Unknown tool: ${name}` };
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
return { success: false, result: `Error: ${error instanceof Error ? error.message : String(error)}` };
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async function callGemini(contents, systemInstruction, apiKey, model) {
|
|
228
|
+
const url = `https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent?key=${apiKey}`;
|
|
229
|
+
const response = await fetch(url, {
|
|
230
|
+
method: 'POST',
|
|
231
|
+
headers: { 'Content-Type': 'application/json' },
|
|
232
|
+
body: JSON.stringify({
|
|
233
|
+
systemInstruction: { parts: [{ text: systemInstruction }] },
|
|
234
|
+
contents,
|
|
235
|
+
tools: [{ functionDeclarations: TOOL_DECLARATIONS }],
|
|
236
|
+
toolConfig: {
|
|
237
|
+
functionCallingConfig: {
|
|
238
|
+
mode: 'AUTO'
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
generationConfig: { maxOutputTokens: 8192, temperature: 0.2 }
|
|
242
|
+
})
|
|
243
|
+
});
|
|
244
|
+
if (!response.ok) {
|
|
245
|
+
const error = await response.text();
|
|
246
|
+
throw new Error(`Gemini API error: ${error}`);
|
|
247
|
+
}
|
|
248
|
+
return response.json();
|
|
249
|
+
}
|
|
250
|
+
// ============================================================================
|
|
251
|
+
// TERMINAL GEMINI EXECUTOR
|
|
252
|
+
// ============================================================================
|
|
253
|
+
class TerminalGeminiExecutor {
|
|
254
|
+
apiKey;
|
|
255
|
+
model;
|
|
256
|
+
maxTurns;
|
|
257
|
+
timeout;
|
|
258
|
+
constructor(options = {}) {
|
|
259
|
+
this.apiKey = options.apiKey || process.env.GEMINI_API_KEY || '';
|
|
260
|
+
this.model = options.model || process.env.GEMINI_MODEL || agent_config_js_1.DEFAULT_MODELS.gemini;
|
|
261
|
+
this.maxTurns = options.maxTurns || parseInt(process.env.GEMINI_MAX_TURNS || '50', 10);
|
|
262
|
+
this.timeout = options.timeout || parseInt(process.env.GEMINI_TIMEOUT || '900000', 10); // 15 min default
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Check if Gemini API key is configured
|
|
266
|
+
*/
|
|
267
|
+
async checkAvailable() {
|
|
268
|
+
return !!this.apiKey;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Read project context files
|
|
272
|
+
*/
|
|
273
|
+
async readProjectContext(projectPath) {
|
|
274
|
+
const MAX_CONTEXT_CHARS = 8000;
|
|
275
|
+
const contextFiles = ['ASTRID.md', 'GEMINI.md', 'README.md'];
|
|
276
|
+
let context = '';
|
|
277
|
+
for (const file of contextFiles) {
|
|
278
|
+
try {
|
|
279
|
+
const filePath = path.join(projectPath, file);
|
|
280
|
+
let content = await fs.readFile(filePath, 'utf-8');
|
|
281
|
+
if (content.length > MAX_CONTEXT_CHARS) {
|
|
282
|
+
content = content.slice(0, MAX_CONTEXT_CHARS) + '\n\n[... truncated ...]';
|
|
283
|
+
}
|
|
284
|
+
context += `\n\n## Project Instructions (from ${file})\n\n${content}`;
|
|
285
|
+
break; // Only use the first found file
|
|
286
|
+
}
|
|
287
|
+
catch {
|
|
288
|
+
// File doesn't exist, try next
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return context;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Build system prompt for the task
|
|
295
|
+
*/
|
|
296
|
+
async buildSystemPrompt(session) {
|
|
297
|
+
const projectContext = await this.readProjectContext(session.projectPath || process.cwd());
|
|
298
|
+
return `You are an expert software engineer working on a coding task.
|
|
299
|
+
You have access to tools for reading, writing, and editing files, running bash commands, and searching the codebase.
|
|
300
|
+
|
|
301
|
+
${projectContext}
|
|
302
|
+
|
|
303
|
+
## Your Task
|
|
304
|
+
${session.title}
|
|
305
|
+
${session.description ? `\nDetails: ${session.description}` : ''}
|
|
306
|
+
|
|
307
|
+
## Workflow
|
|
308
|
+
|
|
309
|
+
1. **Understand** the task by reading relevant files
|
|
310
|
+
2. **Plan** your approach - identify which files need changes
|
|
311
|
+
3. **Implement** the changes using the available tools
|
|
312
|
+
4. **Test** your changes by running build/tests: \`npm run predeploy\` or similar
|
|
313
|
+
5. **Create PR** using \`gh pr create\` command
|
|
314
|
+
6. **Complete** the task by calling task_complete with a summary
|
|
315
|
+
|
|
316
|
+
## Rules
|
|
317
|
+
|
|
318
|
+
- Make ONLY the requested changes - don't over-engineer
|
|
319
|
+
- Follow existing code patterns and style
|
|
320
|
+
- Test your changes before completing
|
|
321
|
+
- Write clear commit messages
|
|
322
|
+
- Always create a PR unless explicitly told not to
|
|
323
|
+
|
|
324
|
+
CRITICAL: You must use ACTUAL FUNCTION CALLS, not text descriptions.
|
|
325
|
+
Do NOT write text saying "I will call X" - actually invoke the function.
|
|
326
|
+
|
|
327
|
+
Begin by reading the relevant files to understand the current state.`;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Start a new session to process a task
|
|
331
|
+
*/
|
|
332
|
+
async startSession(session, prompt, context, onProgress) {
|
|
333
|
+
const projectPath = session.projectPath || process.cwd();
|
|
334
|
+
const systemPrompt = await this.buildSystemPrompt(session);
|
|
335
|
+
const userPrompt = prompt || (0, terminal_base_js_1.buildDefaultPrompt)(session, context);
|
|
336
|
+
const commentHistory = (0, terminal_base_js_1.formatCommentHistory)(context?.comments);
|
|
337
|
+
console.log(`🚀 Starting Gemini terminal session for task: ${session.title}`);
|
|
338
|
+
console.log(`📁 Working directory: ${projectPath}`);
|
|
339
|
+
console.log(`🤖 Model: ${this.model}`);
|
|
340
|
+
const contents = [
|
|
341
|
+
{
|
|
342
|
+
role: 'user',
|
|
343
|
+
parts: [{ text: commentHistory ? `${commentHistory}\n\n---\n\n${userPrompt}` : userPrompt }]
|
|
344
|
+
}
|
|
345
|
+
];
|
|
346
|
+
const modifiedFiles = [];
|
|
347
|
+
let stdout = '';
|
|
348
|
+
let prUrl;
|
|
349
|
+
let completeSummary;
|
|
350
|
+
const startTime = Date.now();
|
|
351
|
+
try {
|
|
352
|
+
for (let turn = 0; turn < this.maxTurns; turn++) {
|
|
353
|
+
// Check timeout
|
|
354
|
+
if (Date.now() - startTime > this.timeout) {
|
|
355
|
+
stdout += '\n\n[Execution timed out]';
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
onProgress?.(`Turn ${turn + 1}/${this.maxTurns}...`);
|
|
359
|
+
const response = await callGemini(contents, systemPrompt, this.apiKey, this.model);
|
|
360
|
+
const candidate = response.candidates[0];
|
|
361
|
+
if (!candidate) {
|
|
362
|
+
stdout += '\n\n[No response from Gemini]';
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
// Add model response to history
|
|
366
|
+
contents.push({ role: 'model', parts: candidate.content.parts });
|
|
367
|
+
// Handle text responses
|
|
368
|
+
const textPart = candidate.content.parts.find(p => p.text);
|
|
369
|
+
if (textPart?.text) {
|
|
370
|
+
stdout += `\n\n${textPart.text}`;
|
|
371
|
+
console.log(`📝 Assistant: ${textPart.text.slice(0, 200)}...`);
|
|
372
|
+
}
|
|
373
|
+
// Handle function calls
|
|
374
|
+
const functionCalls = candidate.content.parts.filter(p => p.functionCall);
|
|
375
|
+
if (functionCalls.length > 0) {
|
|
376
|
+
const functionResponses = [];
|
|
377
|
+
for (const part of functionCalls) {
|
|
378
|
+
if (!part.functionCall)
|
|
379
|
+
continue;
|
|
380
|
+
const { name, args } = part.functionCall;
|
|
381
|
+
onProgress?.(`Using tool: ${name}`);
|
|
382
|
+
console.log(`🔧 Tool: ${name}`);
|
|
383
|
+
// Check for task_complete
|
|
384
|
+
if (name === 'task_complete') {
|
|
385
|
+
completeSummary = args.summary;
|
|
386
|
+
stdout += `\n\n[Task Complete]\nSummary: ${completeSummary}`;
|
|
387
|
+
// Capture git changes
|
|
388
|
+
const changes = await (0, terminal_base_js_1.captureGitChanges)(projectPath);
|
|
389
|
+
prUrl = (0, terminal_base_js_1.extractPrUrl)(stdout);
|
|
390
|
+
return {
|
|
391
|
+
exitCode: 0,
|
|
392
|
+
stdout,
|
|
393
|
+
stderr: '',
|
|
394
|
+
modifiedFiles: changes.files.length > 0 ? changes.files : modifiedFiles,
|
|
395
|
+
gitDiff: changes.diff,
|
|
396
|
+
prUrl,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
// Execute tool
|
|
400
|
+
const result = await executeTool(name, args, projectPath);
|
|
401
|
+
stdout += `\n\n[${name}]: ${result.result.slice(0, 500)}${result.result.length > 500 ? '...' : ''}`;
|
|
402
|
+
// Track modified files
|
|
403
|
+
if (result.fileChange) {
|
|
404
|
+
if (!modifiedFiles.includes(result.fileChange.path)) {
|
|
405
|
+
modifiedFiles.push(result.fileChange.path);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
// Add function response
|
|
409
|
+
functionResponses.push({
|
|
410
|
+
functionResponse: { name, response: { result: result.result.slice(0, 10000) } }
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
// Add all function responses in a single user message
|
|
414
|
+
contents.push({ role: 'user', parts: functionResponses });
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
// Check for stop condition
|
|
418
|
+
if (candidate.finishReason === 'STOP') {
|
|
419
|
+
// Check if we should prompt for completion
|
|
420
|
+
if (!completeSummary) {
|
|
421
|
+
contents.push({
|
|
422
|
+
role: 'user',
|
|
423
|
+
parts: [{ text: 'Please call task_complete to finalize your work, or continue if there is more to do.' }]
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
break;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
// Capture final git changes
|
|
432
|
+
const changes = await (0, terminal_base_js_1.captureGitChanges)(projectPath);
|
|
433
|
+
prUrl = (0, terminal_base_js_1.extractPrUrl)(stdout);
|
|
434
|
+
return {
|
|
435
|
+
exitCode: 0,
|
|
436
|
+
stdout,
|
|
437
|
+
stderr: '',
|
|
438
|
+
modifiedFiles: changes.files.length > 0 ? changes.files : modifiedFiles,
|
|
439
|
+
gitDiff: changes.diff,
|
|
440
|
+
prUrl,
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
catch (error) {
|
|
444
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
445
|
+
console.error(`❌ Gemini terminal execution error:`, errorMsg);
|
|
446
|
+
return {
|
|
447
|
+
exitCode: 1,
|
|
448
|
+
stdout,
|
|
449
|
+
stderr: errorMsg,
|
|
450
|
+
modifiedFiles,
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Resume a session with new input
|
|
456
|
+
* Note: Gemini doesn't have native session management, so we rebuild context
|
|
457
|
+
*/
|
|
458
|
+
async resumeSession(session, input, context, onProgress) {
|
|
459
|
+
console.log(`🔄 Resuming Gemini session (rebuilding context)`);
|
|
460
|
+
// For Gemini, resuming means starting a new conversation with the follow-up
|
|
461
|
+
const fullPrompt = (0, terminal_base_js_1.formatCommentHistory)(context?.comments) +
|
|
462
|
+
`\n\n---\n\n## Follow-up Request\n\n${input}`;
|
|
463
|
+
return this.startSession(session, fullPrompt, context, onProgress);
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Parse output to extract key information
|
|
467
|
+
*/
|
|
468
|
+
parseOutput(output) {
|
|
469
|
+
const result = {};
|
|
470
|
+
const lines = output.split('\n');
|
|
471
|
+
const files = [];
|
|
472
|
+
for (const line of lines) {
|
|
473
|
+
// Extract modified/created files
|
|
474
|
+
const fileMatch = line.match(/(?:modified|created|edited|wrote):\s*[`'"]*([^`'"]+)[`'"]*/i);
|
|
475
|
+
if (fileMatch) {
|
|
476
|
+
files.push(fileMatch[1].trim());
|
|
477
|
+
}
|
|
478
|
+
// Extract PR URL
|
|
479
|
+
const prMatch = line.match(/(https:\/\/github\.com\/[\w-]+\/[\w-]+\/pull\/\d+)/i);
|
|
480
|
+
if (prMatch) {
|
|
481
|
+
result.prUrl = prMatch[1];
|
|
482
|
+
}
|
|
483
|
+
// Extract error messages
|
|
484
|
+
if (line.toLowerCase().includes('error:') || line.toLowerCase().includes('failed:')) {
|
|
485
|
+
result.error = line.trim();
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
if (files.length > 0) {
|
|
489
|
+
result.files = [...new Set(files)];
|
|
490
|
+
}
|
|
491
|
+
// Try to extract summary (look for task_complete summary)
|
|
492
|
+
const summaryMatch = output.match(/\[Task Complete\]\s*Summary:\s*([^\n]+)/i);
|
|
493
|
+
if (summaryMatch) {
|
|
494
|
+
result.summary = summaryMatch[1].trim();
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
// Fallback: last substantial paragraph
|
|
498
|
+
const paragraphs = output.split(/\n\n+/).filter(p => p.trim().length > 50);
|
|
499
|
+
if (paragraphs.length > 0) {
|
|
500
|
+
result.summary = paragraphs[paragraphs.length - 1].trim().slice(0, 500);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
return result;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
exports.TerminalGeminiExecutor = TerminalGeminiExecutor;
|
|
507
|
+
// Export singleton for convenience
|
|
508
|
+
exports.terminalGeminiExecutor = new TerminalGeminiExecutor();
|
|
509
|
+
//# sourceMappingURL=terminal-gemini.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal-gemini.js","sourceRoot":"","sources":["../../src/executors/terminal-gemini.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,gDAAiC;AACjC,2CAA4B;AAC5B,iDAAwC;AACxC,+BAA2B;AAS3B,yDAK2B;AAC3B,8DAAyD;AAazD,+EAA+E;AAC/E,uCAAuC;AACvC,+EAA+E;AAE/E,MAAM,iBAAiB,GAAG;IACxB;QACE,IAAI,EAAE,WAAW;QACjB,WAAW,EAAE,6BAA6B;QAC1C,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE;aAC/D;YACD,QAAQ,EAAE,CAAC,WAAW,CAAC;SACxB;KACF;IACD;QACE,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE,iDAAiD;QAC9D,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE;gBAC9D,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE;aAC7D;YACD,QAAQ,EAAE,CAAC,WAAW,EAAE,SAAS,CAAC;SACnC;KACF;IACD;QACE,IAAI,EAAE,WAAW;QACjB,WAAW,EAAE,qDAAqD;QAClE,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ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,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC1B,MAAM,CAAC,OAAO,GAAG,UAAU,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;YACzE,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AA7SD,wDA6SC;AAED,mCAAmC;AACtB,QAAA,sBAAsB,GAAG,IAAI,sBAAsB,EAAE,CAAA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Terminal OpenAI Executor
|
|
3
|
+
*
|
|
4
|
+
* Executes tasks using OpenAI API with local tool execution.
|
|
5
|
+
* This enables running tasks assigned to openai@astrid.cc in terminal mode.
|
|
6
|
+
*/
|
|
7
|
+
import type { Session } from '../server/session-manager.js';
|
|
8
|
+
import type { TerminalExecutor, TerminalExecutionResult, TerminalTaskContext, TerminalProgressCallback, ParsedOutput } from './terminal-base.js';
|
|
9
|
+
export interface TerminalOpenAIOptions {
|
|
10
|
+
apiKey?: string;
|
|
11
|
+
model?: string;
|
|
12
|
+
maxTurns?: number;
|
|
13
|
+
timeout?: number;
|
|
14
|
+
}
|
|
15
|
+
export declare class TerminalOpenAIExecutor implements TerminalExecutor {
|
|
16
|
+
private apiKey;
|
|
17
|
+
private model;
|
|
18
|
+
private maxTurns;
|
|
19
|
+
private timeout;
|
|
20
|
+
constructor(options?: TerminalOpenAIOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Check if OpenAI API key is configured
|
|
23
|
+
*/
|
|
24
|
+
checkAvailable(): Promise<boolean>;
|
|
25
|
+
/**
|
|
26
|
+
* Read project context files
|
|
27
|
+
*/
|
|
28
|
+
private readProjectContext;
|
|
29
|
+
/**
|
|
30
|
+
* Build system prompt for the task
|
|
31
|
+
*/
|
|
32
|
+
private buildSystemPrompt;
|
|
33
|
+
/**
|
|
34
|
+
* Start a new session to process a task
|
|
35
|
+
*/
|
|
36
|
+
startSession(session: Session, prompt?: string, context?: TerminalTaskContext, onProgress?: TerminalProgressCallback): Promise<TerminalExecutionResult>;
|
|
37
|
+
/**
|
|
38
|
+
* Resume a session with new input
|
|
39
|
+
* Note: OpenAI doesn't have native session management, so we rebuild context
|
|
40
|
+
*/
|
|
41
|
+
resumeSession(session: Session, input: string, context?: TerminalTaskContext, onProgress?: TerminalProgressCallback): Promise<TerminalExecutionResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Parse output to extract key information
|
|
44
|
+
*/
|
|
45
|
+
parseOutput(output: string): ParsedOutput;
|
|
46
|
+
}
|
|
47
|
+
export declare const terminalOpenAIExecutor: TerminalOpenAIExecutor;
|
|
48
|
+
//# sourceMappingURL=terminal-openai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal-openai.d.ts","sourceRoot":"","sources":["../../src/executors/terminal-openai.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAC3D,OAAO,KAAK,EACV,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,wBAAwB,EACxB,YAAY,EACb,MAAM,oBAAoB,CAAA;AAa3B,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AA4SD,qBAAa,sBAAuB,YAAW,gBAAgB;IAC7D,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,OAAO,CAAQ;gBAEX,OAAO,GAAE,qBAA0B;IAO/C;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;IAIxC;;OA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