@causyne/agent 1.19.0 → 1.20.5
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/README.md +0 -18
- package/package.json +1 -1
- package/src/acp/client.js +2 -1
- package/src/acp/client.ts +2 -1
- package/src/acp/server.js +5 -6
- package/src/acp/server.ts +4 -6
- package/src/agentLoop.d.ts +1 -0
- package/src/agentLoop.js +505 -241
- package/src/agentLoop.ts +527 -258
- package/src/agentPolicy.js +9 -0
- package/src/agentPolicy.ts +9 -0
- package/src/approvalPolicy.js +55 -0
- package/src/approvalPolicy.ts +66 -0
- package/src/browser/browserRuntime.js +217 -14
- package/src/browser/browserRuntime.ts +255 -14
- package/src/browser/causyneBrowser.js +1215 -68
- package/src/browser/causyneBrowser.ts +1340 -72
- package/src/cliMode.js +66 -37
- package/src/commands.js +343 -72
- package/src/config.js +22 -12
- package/src/continuum/ingest.js +1 -1
- package/src/continuum/ingest.ts +1 -1
- package/src/continuum/ui/continuumPicker.js +18 -1
- package/src/continuum/ui/continuumPicker.ts +19 -1
- package/src/dynamicCatalogue.js +87 -20
- package/src/dynamicCatalogue.ts +85 -15
- package/src/launchIntent.js +40 -0
- package/src/launchIntent.ts +49 -0
- package/src/memoryManager.js +36 -8
- package/src/modelCatalogue.js +2 -0
- package/src/planCache.js +320 -11
- package/src/planCache.ts +402 -13
- package/src/providers/acp.js +67 -1
- package/src/providers/acp.ts +65 -2
- package/src/providers/antigravity.d.ts +5 -1
- package/src/providers/antigravity.js +643 -32
- package/src/providers/antigravity.ts +671 -33
- package/src/providers/base.d.ts +9 -0
- package/src/providers/factory.js +2 -0
- package/src/providers/pi.js +157 -0
- package/src/providers/pi.ts +144 -0
- package/src/provisioning/capabilityProvisioner.js +17 -0
- package/src/provisioning/capabilityTools.js +1 -1
- package/src/sandbox.js +30 -39
- package/src/sessionJournal.js +66 -10
- package/src/sessionJournal.ts +84 -10
- package/src/taskShape.js +9 -9
- package/src/taskShape.ts +9 -9
- package/src/timeMachine.js +124 -0
- package/src/timeMachine.ts +141 -0
- package/src/toolPacks.js +4 -10
- package/src/tools/archive.js +196 -59
- package/src/tools/archive.ts +220 -0
- package/src/tools/browserAutomator.js +78 -9
- package/src/tools/browserAutomator.ts +90 -9
- package/src/tools/desktopOpen.js +114 -31
- package/src/tools/desktopOpen.ts +144 -0
- package/src/tools/gitExec.js +5 -3
- package/src/tools/nativeEngine.js +4 -3
- package/src/tools/nativeEngine.ts +5 -3
- package/src/tools/openSourceToolProvisioner.js +5 -4
- package/src/tools/openSourceToolProvisioner.ts +5 -4
- package/src/tools/registry.js +3 -0
- package/src/tools/screenshot.js +55 -71
- package/src/tools/screenshot.ts +70 -0
- package/src/tools/sysRun.js +284 -117
- package/src/tools/sysRun.ts +347 -0
- package/src/tools/toolSelfRepair.js +109 -2
- package/src/tools/toolSelfRepair.ts +100 -2
- package/src/tools/updatePlan.js +49 -1
- package/src/tools/updatePlan.ts +43 -1
- package/src/tools/viewImage.js +93 -78
- package/src/tools/viewImage.ts +116 -0
- package/src/tools/webFetch.js +20 -6
- package/src/tools/webFetch.ts +26 -6
- package/src/tui/block.d.ts +1 -0
- package/src/tui/chatRenderer.d.ts +21 -0
- package/src/tui/chatRenderer.js +118 -45
- package/src/tui/clipboardSync.js +28 -1
- package/src/tui/clipboardSync.ts +26 -1
- package/src/tui/codeProgress.js +299 -0
- package/src/tui/codeProgress.ts +304 -0
- package/src/tui/codeStreamRenderer.js +116 -0
- package/src/tui/codeStreamRenderer.ts +124 -0
- package/src/tui/commandPresentation.js +11 -0
- package/src/tui/commandPresentation.ts +18 -0
- package/src/tui/completion.js +45 -13
- package/src/tui/composerControls.js +66 -0
- package/src/tui/composerControls.ts +78 -0
- package/src/tui/diff.d.ts +2 -0
- package/src/tui/home.js +4 -2
- package/src/tui/homeTransition.js +21 -0
- package/src/tui/homeTransition.ts +27 -0
- package/src/tui/homeView.js +62 -0
- package/src/tui/homeView.ts +91 -0
- package/src/tui/layout.js +46 -0
- package/src/tui/layout.ts +52 -0
- package/src/tui/messageActionPlacement.js +16 -0
- package/src/tui/messageActionPlacement.ts +25 -0
- package/src/tui/messageInteraction.js +221 -0
- package/src/tui/messageInteraction.ts +275 -0
- package/src/tui/modelPicker.js +13 -0
- package/src/tui/modelPicker.ts +12 -0
- package/src/tui/mouseHover.js +6 -0
- package/src/tui/mouseHover.ts +5 -0
- package/src/tui/prompt.js +199 -52
- package/src/tui/resizeRecovery.js +15 -0
- package/src/tui/resizeRecovery.ts +27 -0
- package/src/tui/scrollInteraction.js +97 -0
- package/src/tui/scrollInteraction.ts +189 -0
- package/src/tui/sessionLayout.js +12 -0
- package/src/tui/sessionLayout.ts +12 -0
- package/src/tui/sessionPicker.js +280 -0
- package/src/tui/sessionPicker.ts +364 -0
- package/src/tui/sessionSidebar.js +78 -0
- package/src/tui/sessionSidebar.ts +95 -0
- package/src/tui/setup.js +1 -1
- package/src/tui/setup.ts +1 -1
- package/src/tui/stageSurface.js +128 -57
- package/src/tui/statusLine.js +5 -5
- package/src/tui/text.d.ts +5 -0
- package/src/tui/textLayout.js +23 -0
- package/src/tui/textLayout.ts +28 -0
- package/src/tui/viewport.js +204 -279
- package/src/tui/viewport.ts +326 -0
- package/src/types/contracts.ts +54 -0
- package/src/utils/paths.js +5 -4
- package/src/utils/paths.ts +5 -5
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import {
|
|
4
|
+
import { isLaunchOnlyPrompt } from '../launchIntent.js';
|
|
5
|
+
import { LLMProvider, type ProviderConfig, type ChatOptions, type ChatResponse, type ChatResponseAction, type ChatResponseToolCall } from './base.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* resolve here rather than failing at the provider.
|
|
8
|
+
* Baseline fallback models for instant offline availability.
|
|
9
|
+
* Live models are autodetected dynamically from `agy models`
|
|
10
|
+
* and cached in ~/.causyne/models_cache.json.
|
|
11
11
|
*/
|
|
12
|
-
export const
|
|
12
|
+
export const BASELINE_ANTIGRAVITY_MODELS: Record<string, string> = {
|
|
13
13
|
'Gemini 3.8 Flash (Low)': 'gemini-3.8-flash-low',
|
|
14
14
|
'Gemini 3.8 Flash (Medium)': 'gemini-3.8-flash-medium',
|
|
15
15
|
'Gemini 3.8 Flash (High)': 'gemini-3.8-flash-high',
|
|
@@ -25,16 +25,107 @@ export const ANTIGRAVITY_MODEL_IDS: Record<string, string> = {
|
|
|
25
25
|
'GPT-OSS 120B (Medium)': 'gpt-oss-120b-medium'
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
+
export const ANTIGRAVITY_MODEL_IDS: Record<string, string> = {
|
|
29
|
+
...BASELINE_ANTIGRAVITY_MODELS
|
|
30
|
+
};
|
|
31
|
+
|
|
28
32
|
export const ANTIGRAVITY_LABEL_BY_ID: Record<string, string> = Object.fromEntries(
|
|
29
33
|
Object.entries(ANTIGRAVITY_MODEL_IDS).map(([label, id]) => [id, label])
|
|
30
34
|
);
|
|
31
35
|
|
|
32
36
|
export const ANTIGRAVITY_MODELS: string[] = Object.keys(ANTIGRAVITY_MODEL_IDS);
|
|
33
37
|
|
|
38
|
+
export function registerAntigravityModel(slug: string, label?: string): void {
|
|
39
|
+
if (!slug || typeof slug !== 'string') return;
|
|
40
|
+
const cleanSlug = slug.trim();
|
|
41
|
+
const cleanLabel = (label && typeof label === 'string' && label.trim()) || cleanSlug;
|
|
42
|
+
|
|
43
|
+
ANTIGRAVITY_MODEL_IDS[cleanLabel] = cleanSlug;
|
|
44
|
+
ANTIGRAVITY_MODEL_IDS[cleanSlug] = cleanSlug;
|
|
45
|
+
ANTIGRAVITY_LABEL_BY_ID[cleanSlug] = cleanLabel;
|
|
46
|
+
if (!ANTIGRAVITY_MODELS.includes(cleanLabel)) {
|
|
47
|
+
ANTIGRAVITY_MODELS.push(cleanLabel);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function parseAgyModelsOutput(stdout: string): Array<{ id: string; label: string }> {
|
|
52
|
+
const result: Array<{ id: string; label: string }> = [];
|
|
53
|
+
if (!stdout || typeof stdout !== 'string') return result;
|
|
54
|
+
|
|
55
|
+
const lines = stdout.replace(/\r/g, '\n').split(/\n+/);
|
|
56
|
+
for (const rawLine of lines) {
|
|
57
|
+
const line = rawLine.replace(/\u001b\[[0-9;]*[A-Za-z]/g, '').trim();
|
|
58
|
+
if (!line) continue;
|
|
59
|
+
if (/^(fetching|loading|no models|error)/i.test(line)) continue;
|
|
60
|
+
if (line.endsWith('…') || line.endsWith('...')) continue;
|
|
61
|
+
|
|
62
|
+
const cleanLine = line.replace(/^[^a-zA-Z0-9_-]+/, '');
|
|
63
|
+
const match = cleanLine.match(/^([a-z0-9_.-]+)(?:\s+(.+))?$/i);
|
|
64
|
+
if (!match) continue;
|
|
65
|
+
|
|
66
|
+
const id = match[1]!.trim();
|
|
67
|
+
const label = (match[2] && match[2].trim()) || id;
|
|
68
|
+
result.push({ id, label });
|
|
69
|
+
registerAntigravityModel(id, label);
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function hydrateModelsFromDiskCache(): void {
|
|
75
|
+
try {
|
|
76
|
+
const home = process.env.HOME || process.env.USERPROFILE || '';
|
|
77
|
+
const cacheFile = path.join(home, '.causyne', 'models_cache.json');
|
|
78
|
+
if (!fs.existsSync(cacheFile)) return;
|
|
79
|
+
const content = fs.readFileSync(cacheFile, 'utf8');
|
|
80
|
+
const parsed = JSON.parse(content);
|
|
81
|
+
const agyModels = parsed?.providers?.antigravity?.models;
|
|
82
|
+
if (Array.isArray(agyModels)) {
|
|
83
|
+
for (const item of agyModels) {
|
|
84
|
+
if (typeof item === 'string' && item.trim()) {
|
|
85
|
+
const trimmed = item.trim();
|
|
86
|
+
if (!ANTIGRAVITY_MODEL_IDS[trimmed]) {
|
|
87
|
+
registerAntigravityModel(trimmed, trimmed);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
} catch {
|
|
93
|
+
// Ignore cache read errors
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
hydrateModelsFromDiskCache();
|
|
98
|
+
|
|
34
99
|
export function resolveAgyModelId(model?: string | null): string {
|
|
35
100
|
if (typeof model !== 'string') return '';
|
|
36
101
|
const trimmed = model.trim();
|
|
37
|
-
|
|
102
|
+
if (!trimmed) return '';
|
|
103
|
+
|
|
104
|
+
if (ANTIGRAVITY_MODEL_IDS[trimmed]) {
|
|
105
|
+
return ANTIGRAVITY_MODEL_IDS[trimmed];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const lower = trimmed.toLowerCase();
|
|
109
|
+
for (const [key, slug] of Object.entries(ANTIGRAVITY_MODEL_IDS)) {
|
|
110
|
+
if (key.toLowerCase() === lower || slug.toLowerCase() === lower) {
|
|
111
|
+
return slug;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const effort = resolveAgyEffort(trimmed);
|
|
116
|
+
const candidateWithEffort = `${lower}-${effort}`;
|
|
117
|
+
for (const [key, slug] of Object.entries(ANTIGRAVITY_MODEL_IDS)) {
|
|
118
|
+
if (slug.toLowerCase() === candidateWithEffort || key.toLowerCase() === candidateWithEffort) {
|
|
119
|
+
return slug;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
for (const [key, slug] of Object.entries(ANTIGRAVITY_MODEL_IDS)) {
|
|
123
|
+
if (slug.toLowerCase().startsWith(lower) || key.toLowerCase().startsWith(lower)) {
|
|
124
|
+
return slug;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return trimmed;
|
|
38
129
|
}
|
|
39
130
|
|
|
40
131
|
export function resolveAgyEffort(model?: string | null): string {
|
|
@@ -82,27 +173,329 @@ export function resolveAgyBinary(): string {
|
|
|
82
173
|
return 'agy';
|
|
83
174
|
}
|
|
84
175
|
|
|
176
|
+
function describeNativeAction(toolInfo: any): string | undefined {
|
|
177
|
+
const parameters = toolInfo && typeof toolInfo === 'object' ? toolInfo.parameters : null;
|
|
178
|
+
if (parameters && typeof parameters === 'object') {
|
|
179
|
+
for (const key of ['Path', 'path', 'file_path', 'TargetFile', 'target_file', 'CommandLine', 'command', 'url']) {
|
|
180
|
+
const value = parameters[key];
|
|
181
|
+
if (typeof value === 'string' && value.trim()) return value.trim();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
for (const key of ['toolAction', 'tool_action', 'toolSummary', 'tool_summary']) {
|
|
185
|
+
const value = toolInfo && toolInfo[key];
|
|
186
|
+
if (typeof value === 'string' && value.trim()) return value.trim();
|
|
187
|
+
}
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function mapNativeToolToCausyne(
|
|
192
|
+
name: string,
|
|
193
|
+
rawParams: Record<string, any>,
|
|
194
|
+
index: number
|
|
195
|
+
): ChatResponseToolCall | null {
|
|
196
|
+
if (!name || typeof name !== 'string') return null;
|
|
197
|
+
const lowerName = name.toLowerCase().replace(/[_-]/g, '');
|
|
198
|
+
const params = rawParams && typeof rawParams === 'object' ? rawParams : {};
|
|
199
|
+
|
|
200
|
+
if (lowerName === 'runcommand' || lowerName === 'command' || lowerName === 'sysrun' || lowerName === 'terminal' || lowerName === 'bash' || lowerName === 'shell') {
|
|
201
|
+
const rawCmd = params.CommandLine ?? params.command ?? params.cmd ?? params.input ?? params.detail ?? '';
|
|
202
|
+
let cmd = typeof rawCmd === 'string' ? rawCmd.trim() : '';
|
|
203
|
+
if (!cmd && typeof params.parameters === 'object' && params.parameters) {
|
|
204
|
+
cmd = String(params.parameters.CommandLine || params.parameters.command || params.parameters.cmd || '').trim();
|
|
205
|
+
}
|
|
206
|
+
if (cmd) {
|
|
207
|
+
const isDaemon = Boolean(params.IsDaemon ?? params.isDaemon ?? params.daemon);
|
|
208
|
+
const cwd = params.Cwd ?? params.cwd;
|
|
209
|
+
if (isDaemon) {
|
|
210
|
+
const bgArgs: Record<string, any> = { command: cmd, label: 'daemon' };
|
|
211
|
+
if (typeof cwd === 'string' && cwd.trim()) bgArgs.cwd = cwd.trim();
|
|
212
|
+
return {
|
|
213
|
+
id: `agy_native_${Date.now()}_${index}`,
|
|
214
|
+
type: 'function',
|
|
215
|
+
function: {
|
|
216
|
+
name: 'sysRunBg',
|
|
217
|
+
arguments: JSON.stringify(bgArgs)
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
const args: Record<string, any> = { command: cmd };
|
|
222
|
+
if (typeof cwd === 'string' && cwd.trim()) args.cwd = cwd.trim();
|
|
223
|
+
return {
|
|
224
|
+
id: `agy_native_${Date.now()}_${index}`,
|
|
225
|
+
type: 'function',
|
|
226
|
+
function: {
|
|
227
|
+
name: 'sysRun',
|
|
228
|
+
arguments: JSON.stringify(args)
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (lowerName === 'viewfile' || lowerName === 'readfile' || lowerName === 'read' || lowerName === 'view' || lowerName === 'fsread') {
|
|
235
|
+
const filePath = params.AbsolutePath ?? params.path ?? params.file_path ?? params.TargetFile ?? '';
|
|
236
|
+
if (typeof filePath === 'string' && filePath.trim()) {
|
|
237
|
+
return {
|
|
238
|
+
id: `agy_native_${Date.now()}_${index}`,
|
|
239
|
+
type: 'function',
|
|
240
|
+
function: {
|
|
241
|
+
name: 'fs_read',
|
|
242
|
+
arguments: JSON.stringify({ path: filePath.trim() })
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (lowerName === 'listdir' || lowerName === 'fslist' || lowerName === 'list') {
|
|
249
|
+
const dirPath = params.DirectoryPath ?? params.path ?? '.';
|
|
250
|
+
return {
|
|
251
|
+
id: `agy_native_${Date.now()}_${index}`,
|
|
252
|
+
type: 'function',
|
|
253
|
+
function: {
|
|
254
|
+
name: 'fs_list',
|
|
255
|
+
arguments: JSON.stringify({ path: String(dirPath).trim() || '.' })
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (lowerName === 'grepsearch' || lowerName === 'searchworkspace') {
|
|
261
|
+
const query = params.Query ?? params.query ?? '';
|
|
262
|
+
if (typeof query === 'string' && query.trim()) {
|
|
263
|
+
return {
|
|
264
|
+
id: `agy_native_${Date.now()}_${index}`,
|
|
265
|
+
type: 'function',
|
|
266
|
+
function: {
|
|
267
|
+
name: 'workspace_search',
|
|
268
|
+
arguments: JSON.stringify({
|
|
269
|
+
query: query.trim(),
|
|
270
|
+
path: params.SearchPath ?? params.path ?? '.'
|
|
271
|
+
})
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (lowerName === 'writetofile' || lowerName === 'fswrite') {
|
|
278
|
+
const filePath = params.TargetFile ?? params.path ?? params.file_path ?? '';
|
|
279
|
+
const content = params.CodeContent ?? params.content ?? '';
|
|
280
|
+
if (typeof filePath === 'string' && filePath.trim()) {
|
|
281
|
+
return {
|
|
282
|
+
id: `agy_native_${Date.now()}_${index}`,
|
|
283
|
+
type: 'function',
|
|
284
|
+
function: {
|
|
285
|
+
name: 'fs_write',
|
|
286
|
+
arguments: JSON.stringify({ path: filePath.trim(), content: String(content) })
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (lowerName === 'replacefilecontent' || lowerName === 'fsedit') {
|
|
293
|
+
const filePath = params.TargetFile ?? params.path ?? params.file_path ?? '';
|
|
294
|
+
const oldText = params.TargetContent ?? params.oldText ?? '';
|
|
295
|
+
const newText = params.ReplacementContent ?? params.newText ?? '';
|
|
296
|
+
if (typeof filePath === 'string' && filePath.trim()) {
|
|
297
|
+
return {
|
|
298
|
+
id: `agy_native_${Date.now()}_${index}`,
|
|
299
|
+
type: 'function',
|
|
300
|
+
function: {
|
|
301
|
+
name: 'fs_edit',
|
|
302
|
+
arguments: JSON.stringify({ path: filePath.trim(), oldText: String(oldText), newText: String(newText) })
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (lowerName === 'openbrowserurl') {
|
|
309
|
+
const url = params.Url ?? params.url ?? '';
|
|
310
|
+
if (typeof url === 'string' && url.trim()) {
|
|
311
|
+
return {
|
|
312
|
+
id: `agy_native_${Date.now()}_${index}`,
|
|
313
|
+
type: 'function',
|
|
314
|
+
function: {
|
|
315
|
+
name: 'desktop.open',
|
|
316
|
+
arguments: JSON.stringify({ target: url.trim() })
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (lowerName === 'readurlcontent') {
|
|
323
|
+
const url = params.Url ?? params.url ?? '';
|
|
324
|
+
if (typeof url === 'string' && url.trim()) {
|
|
325
|
+
return {
|
|
326
|
+
id: `agy_native_${Date.now()}_${index}`,
|
|
327
|
+
type: 'function',
|
|
328
|
+
function: {
|
|
329
|
+
name: 'web_fetch',
|
|
330
|
+
arguments: JSON.stringify({ url: url.trim() })
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (lowerName === 'searchweb') {
|
|
337
|
+
const query = params.query ?? params.Query ?? '';
|
|
338
|
+
if (typeof query === 'string' && query.trim()) {
|
|
339
|
+
return {
|
|
340
|
+
id: `agy_native_${Date.now()}_${index}`,
|
|
341
|
+
type: 'function',
|
|
342
|
+
function: {
|
|
343
|
+
name: 'web_search',
|
|
344
|
+
arguments: JSON.stringify({ query: query.trim() })
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (lowerName === 'multireplacefilecontent' || lowerName === 'multireplace') {
|
|
351
|
+
const filePath = params.TargetFile ?? params.path ?? params.file_path ?? '';
|
|
352
|
+
const rawChunks = Array.isArray(params.ReplacementChunks) ? params.ReplacementChunks : [];
|
|
353
|
+
const edits = rawChunks.map((chunk: any) => ({
|
|
354
|
+
old_string: String(chunk.TargetContent ?? chunk.old_string ?? ''),
|
|
355
|
+
new_string: String(chunk.ReplacementContent ?? chunk.new_string ?? '')
|
|
356
|
+
})).filter((e: any) => e.old_string);
|
|
357
|
+
if (typeof filePath === 'string' && filePath.trim() && edits.length > 0) {
|
|
358
|
+
return {
|
|
359
|
+
id: `agy_native_${Date.now()}_${index}`,
|
|
360
|
+
type: 'function',
|
|
361
|
+
function: {
|
|
362
|
+
name: 'MultiEdit',
|
|
363
|
+
arguments: JSON.stringify({ file_path: filePath.trim(), edits })
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (lowerName === 'browsersubagent' || lowerName === 'browseragent') {
|
|
370
|
+
const textToSearch = [
|
|
371
|
+
params.Url, params.url, params.Task, params.task, params.TaskName, params.taskName, params.TaskSummary
|
|
372
|
+
].filter(Boolean).join(' ');
|
|
373
|
+
const urlMatch = textToSearch.match(/https?:\/\/[^\s'")]+/i) || textToSearch.match(/localhost:\d+[^\s'")]*/i);
|
|
374
|
+
if (urlMatch) {
|
|
375
|
+
let targetUrl = urlMatch[0];
|
|
376
|
+
if (!targetUrl.startsWith('http')) targetUrl = `http://${targetUrl}`;
|
|
377
|
+
return {
|
|
378
|
+
id: `agy_native_${Date.now()}_${index}`,
|
|
379
|
+
type: 'function',
|
|
380
|
+
function: {
|
|
381
|
+
name: 'desktop.open',
|
|
382
|
+
arguments: JSON.stringify({ target: targetUrl })
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if (lowerName === 'managetask') {
|
|
389
|
+
const action = String(params.Action ?? params.action ?? '').toLowerCase();
|
|
390
|
+
if (action === 'list') {
|
|
391
|
+
return {
|
|
392
|
+
id: `agy_native_${Date.now()}_${index}`,
|
|
393
|
+
type: 'function',
|
|
394
|
+
function: {
|
|
395
|
+
name: 'process_list',
|
|
396
|
+
arguments: JSON.stringify({})
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
if (action === 'kill') {
|
|
401
|
+
const pid = Number(params.TaskId ?? params.taskId ?? params.pid);
|
|
402
|
+
if (!Number.isNaN(pid) && pid > 0) {
|
|
403
|
+
return {
|
|
404
|
+
id: `agy_native_${Date.now()}_${index}`,
|
|
405
|
+
type: 'function',
|
|
406
|
+
function: {
|
|
407
|
+
name: 'proc_term',
|
|
408
|
+
arguments: JSON.stringify({ pid })
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
return null;
|
|
416
|
+
}
|
|
417
|
+
|
|
85
418
|
export class AntigravityProvider extends LLMProvider {
|
|
86
419
|
command: string;
|
|
420
|
+
currentConversationId: string | null = null;
|
|
421
|
+
lastTaskId: string | null = null;
|
|
87
422
|
|
|
88
423
|
constructor(config: ProviderConfig = {}) {
|
|
89
424
|
super(config);
|
|
90
425
|
this.model = config.model || 'Gemini 3.8 Flash (Low)';
|
|
91
426
|
this.command = config.command || resolveAgyBinary();
|
|
92
|
-
this.visionModels = [];
|
|
427
|
+
this.visionModels = ['*'];
|
|
93
428
|
this.audioModels = [];
|
|
94
429
|
}
|
|
95
430
|
|
|
431
|
+
formatDelta(messages: any[]): string {
|
|
432
|
+
const lines: string[] = [];
|
|
433
|
+
for (const msg of messages) {
|
|
434
|
+
const role = msg.role === 'user'
|
|
435
|
+
? 'User'
|
|
436
|
+
: (msg.role === 'assistant'
|
|
437
|
+
? 'Assistant'
|
|
438
|
+
: (msg.role === 'system'
|
|
439
|
+
? 'System Instructions'
|
|
440
|
+
: (msg.role === 'tool'
|
|
441
|
+
? `Tool Result (${msg.name || 'tool'})`
|
|
442
|
+
: 'Context')));
|
|
443
|
+
|
|
444
|
+
let text = '';
|
|
445
|
+
if (typeof msg.content === 'string') {
|
|
446
|
+
text = msg.content;
|
|
447
|
+
} else if (Array.isArray(msg.content)) {
|
|
448
|
+
text = msg.content.map((c: any) => {
|
|
449
|
+
if (typeof c === 'string') return c;
|
|
450
|
+
if (c?.text) return c.text;
|
|
451
|
+
if (c?.type === 'image_url' || c?.type === 'image') {
|
|
452
|
+
const url = c?.image_url?.url || '';
|
|
453
|
+
const mime = c?.source?.media_type || (url.startsWith('data:') ? url.slice(5, url.indexOf(';')) : 'image');
|
|
454
|
+
return `[Visual Content: ${mime}]`;
|
|
455
|
+
}
|
|
456
|
+
return '';
|
|
457
|
+
}).filter(Boolean).join('\n');
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
if (msg.tool_calls && Array.isArray(msg.tool_calls)) {
|
|
461
|
+
for (const tc of msg.tool_calls) {
|
|
462
|
+
const fn = tc.function || {};
|
|
463
|
+
const fnArgs = typeof fn.arguments === 'string' ? fn.arguments : JSON.stringify(fn.arguments || {});
|
|
464
|
+
text += `\n<tool_call>{"name": "${fn.name}", "arguments": ${fnArgs}}</tool_call>`;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
if (text.trim()) {
|
|
469
|
+
lines.push(`[${role}]\n${text.trim()}`);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
return lines.join('\n\n');
|
|
473
|
+
}
|
|
474
|
+
|
|
96
475
|
formatConversation(messages: any[], tools: any[] = []): string {
|
|
97
476
|
const lines: string[] = [];
|
|
98
477
|
|
|
99
|
-
//
|
|
478
|
+
// Host capabilities must be learned from real tool results in this session.
|
|
100
479
|
lines.push(
|
|
101
480
|
'[System Instructions]\n' +
|
|
102
|
-
'You are
|
|
103
|
-
'
|
|
481
|
+
'You are the execution engine for Causyne Agent, operating inside the user\'s workspace. ' +
|
|
482
|
+
'Do not claim a tool action succeeded without evidence. Use Causyne tools for file changes, terminal commands, and browser actions. ' +
|
|
483
|
+
'When a command, browser action, or other external action is required, output an explicit tool call in this exact format:\n' +
|
|
104
484
|
'<tool_call>{"name": "tool_name", "arguments": { ... }}</tool_call>\n' +
|
|
105
|
-
'Causyne Agent will execute the tool in its secure environment and return the results back to you
|
|
485
|
+
'Causyne Agent will execute the tool in its secure environment and return the results back to you.\n\n' +
|
|
486
|
+
'[Action Directive]\n' +
|
|
487
|
+
'1. When the user requests to create, build, code, fix, write, optimize, or implement anything, invoke the relevant file or command tools immediately.\n' +
|
|
488
|
+
'2. When the user requests to OPEN, LAUNCH, RUN, SERVE, or PLAY an application, project, or game:\n' +
|
|
489
|
+
' - If a background server is required (e.g. server.py, python -m http.server, npm run dev), start it using sysRunBg or a background command.\n' +
|
|
490
|
+
' - If the default port (e.g. 8080 or 3000) is already occupied or in use by another process, immediately use the next available port (e.g. 8081, 8082, 3001) rather than getting stuck in process-checking loops.\n' +
|
|
491
|
+
' - Immediately open the URL or project in the user\'s browser using desktop.open with {"target": "http://localhost:<port>"} or run the native open command.\n' +
|
|
492
|
+
' - Confirm the application is accessible only after a readiness check succeeds.\n' +
|
|
493
|
+
'3. NEVER reply with conversational pleasantries, canned greetings (e.g. "How can I help you today?"), or ask what the user wants when an instruction has already been provided.\n' +
|
|
494
|
+
'4. Create or edit files only when the current user request authorizes it.\n\n' +
|
|
495
|
+
'[Environment State & Idempotency Directive]\n' +
|
|
496
|
+
'Reuse relevant verified tool results from this session, and check uncertain prerequisites before relying on them.\n\n' +
|
|
497
|
+
'[Language & Communication Directive]\n' +
|
|
498
|
+
'Dynamically reflect and match the exact language used by the user in their prompt. If the user writes in English, you must respond strictly in English. Default to English for all responses and reasoning. Never default to Indonesian or send canned greetings in Indonesian.'
|
|
106
499
|
);
|
|
107
500
|
|
|
108
501
|
if (tools && tools.length > 0) {
|
|
@@ -118,7 +511,11 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
118
511
|
);
|
|
119
512
|
}
|
|
120
513
|
|
|
121
|
-
|
|
514
|
+
const seenToolOutputs = new Set<string>();
|
|
515
|
+
const seenAssistantCalls = new Set<string>();
|
|
516
|
+
for (let i = 0; i < messages.length; i++) {
|
|
517
|
+
const msg = messages[i];
|
|
518
|
+
const isRecent = messages.length - i <= 4;
|
|
122
519
|
const role = msg.role === 'user'
|
|
123
520
|
? 'User'
|
|
124
521
|
: (msg.role === 'assistant'
|
|
@@ -133,13 +530,36 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
133
530
|
if (typeof msg.content === 'string') {
|
|
134
531
|
text = msg.content;
|
|
135
532
|
} else if (Array.isArray(msg.content)) {
|
|
136
|
-
text = msg.content.map((c: any) =>
|
|
533
|
+
text = msg.content.map((c: any) => {
|
|
534
|
+
if (typeof c === 'string') return c;
|
|
535
|
+
if (c?.text) return c.text;
|
|
536
|
+
if (c?.type === 'image_url' || c?.type === 'image') {
|
|
537
|
+
const url = c?.image_url?.url || '';
|
|
538
|
+
const mime = c?.source?.media_type || (url.startsWith('data:') ? url.slice(5, url.indexOf(';')) : 'image');
|
|
539
|
+
return `[Visual Content: ${mime}]`;
|
|
540
|
+
}
|
|
541
|
+
return '';
|
|
542
|
+
}).filter(Boolean).join('\n');
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// Compact duplicate identical tool outputs to prevent token ballooning
|
|
546
|
+
if (msg.role === 'tool' && text.trim()) {
|
|
547
|
+
const normalized = text.trim();
|
|
548
|
+
if (seenToolOutputs.has(normalized)) {
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
551
|
+
seenToolOutputs.add(normalized);
|
|
137
552
|
}
|
|
138
553
|
|
|
139
554
|
if (msg.tool_calls && Array.isArray(msg.tool_calls)) {
|
|
140
555
|
for (const tc of msg.tool_calls) {
|
|
141
556
|
const fn = tc.function || {};
|
|
142
557
|
const fnArgs = typeof fn.arguments === 'string' ? fn.arguments : JSON.stringify(fn.arguments || {});
|
|
558
|
+
const callSig = `${fn.name}:${fnArgs}`;
|
|
559
|
+
if (seenAssistantCalls.has(callSig)) {
|
|
560
|
+
continue;
|
|
561
|
+
}
|
|
562
|
+
seenAssistantCalls.add(callSig);
|
|
143
563
|
text += `\n<tool_call>{"name": "${fn.name}", "arguments": ${fnArgs}}</tool_call>`;
|
|
144
564
|
}
|
|
145
565
|
}
|
|
@@ -202,6 +622,34 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
202
622
|
}
|
|
203
623
|
}
|
|
204
624
|
|
|
625
|
+
// Unclosed tool_call recovery (when model generated large file content and closed turn)
|
|
626
|
+
if (calls.length === 0) {
|
|
627
|
+
const openIndex = text.lastIndexOf('<tool_call>');
|
|
628
|
+
if (openIndex !== -1 && text.indexOf('</tool_call>', openIndex) === -1) {
|
|
629
|
+
const partial = text.slice(openIndex + '<tool_call>'.length).trim();
|
|
630
|
+
for (const suffix of ['', '}', '}}', '}}}', '"}', '"}}', '"}}}', '"}]}}', '"]}}', '"]}}}']) {
|
|
631
|
+
try {
|
|
632
|
+
const parsed = JSON.parse(partial + suffix);
|
|
633
|
+
const name = parsed.name || parsed.tool || parsed.function?.name;
|
|
634
|
+
if (name) {
|
|
635
|
+
const rawArgs = parsed.arguments !== undefined ? parsed.arguments : (parsed.parameters !== undefined ? parsed.parameters : (parsed.input !== undefined ? parsed.input : (parsed.function?.arguments || {})));
|
|
636
|
+
calls.push({
|
|
637
|
+
id: `agy_call_${Date.now()}_0`,
|
|
638
|
+
type: 'function',
|
|
639
|
+
function: {
|
|
640
|
+
name,
|
|
641
|
+
arguments: typeof rawArgs === 'string' ? rawArgs : JSON.stringify(rawArgs || {})
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
break;
|
|
645
|
+
}
|
|
646
|
+
} catch {
|
|
647
|
+
// try next candidate
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
205
653
|
return calls;
|
|
206
654
|
}
|
|
207
655
|
|
|
@@ -221,34 +669,86 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
221
669
|
}
|
|
222
670
|
|
|
223
671
|
async _executeOnce(messages: any[], options: ChatOptions = {}): Promise<ChatResponse> {
|
|
224
|
-
const
|
|
672
|
+
const currentTaskId = (options as any).taskId || (options as any).conversationId || null;
|
|
673
|
+
if (currentTaskId && currentTaskId !== this.lastTaskId) {
|
|
674
|
+
this.currentConversationId = null;
|
|
675
|
+
this.lastTaskId = currentTaskId;
|
|
676
|
+
}
|
|
677
|
+
if (messages.length <= 1) {
|
|
678
|
+
this.currentConversationId = null;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
const useConversation = Boolean(this.currentConversationId);
|
|
682
|
+
const latestUserMessage = [...messages].reverse().find(message => message.role === 'user');
|
|
683
|
+
const latestPrompt = typeof latestUserMessage?.content === 'string' ? latestUserMessage.content : '';
|
|
684
|
+
const launchOnly = (options as any).taskIntent === 'launch' || isLaunchOnlyPrompt(latestPrompt);
|
|
685
|
+
let promptText: string;
|
|
686
|
+
|
|
687
|
+
if (useConversation) {
|
|
688
|
+
let lastAssistantIndex = -1;
|
|
689
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
690
|
+
if (messages[i].role === 'assistant') {
|
|
691
|
+
lastAssistantIndex = i;
|
|
692
|
+
break;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
const deltaMessages = lastAssistantIndex >= 0 ? messages.slice(lastAssistantIndex + 1) : messages;
|
|
696
|
+
promptText = this.formatDelta(deltaMessages.length > 0 ? deltaMessages : [messages[messages.length - 1]]);
|
|
697
|
+
} else {
|
|
698
|
+
promptText = this.formatConversation(messages, options.tools);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
// A resumed agy conversation retains its old instructions. Reassert the
|
|
702
|
+
// current turn's narrower scope on every call, including formatDelta turns.
|
|
703
|
+
if (launchOnly) {
|
|
704
|
+
promptText = '[Current request: open existing project only]\n' +
|
|
705
|
+
'Inspect the selected project, start an existing server in the background if needed, verify readiness, and open it. ' +
|
|
706
|
+
'Do not create, edit, delete, install, or regenerate files. Do not claim the app opened unless a tool confirmed it. ' +
|
|
707
|
+
'Use Causyne tool calls for commands and desktop opening.\n\n' + promptText;
|
|
708
|
+
}
|
|
709
|
+
|
|
225
710
|
const modelSlug = resolveAgyModelId(this.model);
|
|
226
711
|
const effort = resolveAgyEffort(this.model);
|
|
227
712
|
|
|
228
713
|
// Standard high-performance non-blocking CLI invocation:
|
|
229
714
|
// 1. stream-json output for real-time responsiveness and non-buffering progress.
|
|
230
715
|
// 2. --disable-slash-commands prevents sluggish filesystem and customization scans.
|
|
231
|
-
// 3.
|
|
232
|
-
//
|
|
716
|
+
// 3. agy only treats stdin as a prompt in stream-json input mode. Plain text
|
|
717
|
+
// stdin without --print starts an interactive session and loses the task.
|
|
718
|
+
// Keep the prompt off the process command line by sending one user event.
|
|
719
|
+
// 4. --mode accept-edits lets agy create and edit workspace files in
|
|
720
|
+
// headless mode, where the default request-review policy cannot prompt
|
|
721
|
+
// and would auto-deny every write. --dangerously-skip-permissions must
|
|
722
|
+
// stay off: it would also grant shell commands and other host tools,
|
|
723
|
+
// bypassing Causyne. Native terminal/browser tools remain denied; those
|
|
724
|
+
// must go through Causyne XML tool calls.
|
|
725
|
+
// 5. Launch-only turns use a shorter limit because they should not spend
|
|
726
|
+
// several minutes generating code or holding a foreground server open.
|
|
727
|
+
// 6. --conversation links multi-turn steps to agy's local session memory to prevent re-reading files.
|
|
233
728
|
const args = [
|
|
729
|
+
'--mode',
|
|
730
|
+
launchOnly ? 'plan' : 'accept-edits',
|
|
731
|
+
'--input-format',
|
|
732
|
+
'stream-json',
|
|
234
733
|
'--output-format',
|
|
235
734
|
'stream-json',
|
|
236
735
|
'--disable-slash-commands',
|
|
237
736
|
'--print-timeout',
|
|
238
|
-
'
|
|
239
|
-
'--dangerously-skip-permissions',
|
|
737
|
+
launchOnly ? '90s' : '300s',
|
|
240
738
|
'--model',
|
|
241
739
|
modelSlug,
|
|
242
740
|
'--effort',
|
|
243
|
-
effort
|
|
244
|
-
'-p',
|
|
245
|
-
'-'
|
|
741
|
+
effort
|
|
246
742
|
];
|
|
247
743
|
|
|
744
|
+
if (useConversation && this.currentConversationId) {
|
|
745
|
+
args.push('--conversation', this.currentConversationId);
|
|
746
|
+
}
|
|
747
|
+
|
|
248
748
|
return new Promise<ChatResponse>((resolve, reject) => {
|
|
249
749
|
let isSettled = false;
|
|
250
750
|
const child = spawn(this.command, args, {
|
|
251
|
-
cwd: process.cwd(),
|
|
751
|
+
cwd: typeof (options as any).workspaceRoot === 'string' ? (options as any).workspaceRoot : process.cwd(),
|
|
252
752
|
env: process.env,
|
|
253
753
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
254
754
|
windowsHide: true
|
|
@@ -258,6 +758,15 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
258
758
|
let stderrBuffer = '';
|
|
259
759
|
let streamedResponse = '';
|
|
260
760
|
let finalResultObj: any = null;
|
|
761
|
+
const nativeActions: ChatResponseAction[] = [];
|
|
762
|
+
const attemptedNativeTools: {
|
|
763
|
+
name: string;
|
|
764
|
+
parameters: Record<string, any>;
|
|
765
|
+
status: 'running' | 'completed' | 'failed';
|
|
766
|
+
error?: string | undefined;
|
|
767
|
+
detail?: string | undefined;
|
|
768
|
+
}[] = [];
|
|
769
|
+
let childClosed = false;
|
|
261
770
|
|
|
262
771
|
const cleanup = () => {
|
|
263
772
|
if (options.signal) {
|
|
@@ -283,7 +792,7 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
283
792
|
try {
|
|
284
793
|
child.kill('SIGTERM');
|
|
285
794
|
setTimeout(() => {
|
|
286
|
-
if (!
|
|
795
|
+
if (!childClosed) child.kill('SIGKILL');
|
|
287
796
|
}, 1000).unref();
|
|
288
797
|
} catch {
|
|
289
798
|
// ignore kill errors
|
|
@@ -301,7 +810,8 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
301
810
|
|
|
302
811
|
// Feed prompt directly into child process stdin, then close stdin
|
|
303
812
|
try {
|
|
304
|
-
child.stdin.
|
|
813
|
+
child.stdin.on('error', () => {});
|
|
814
|
+
child.stdin.write(JSON.stringify({ event: 'user', message: { content: promptText } }) + '\n', 'utf8');
|
|
305
815
|
child.stdin.end();
|
|
306
816
|
} catch (err: any) {
|
|
307
817
|
safeReject(new Error(`Failed to pipe prompt to Antigravity CLI: ${err.message}`));
|
|
@@ -321,10 +831,67 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
321
831
|
if (!trimmed) continue;
|
|
322
832
|
try {
|
|
323
833
|
const event = JSON.parse(trimmed);
|
|
324
|
-
if (event.event === '
|
|
834
|
+
if (event.event === 'init') {
|
|
835
|
+
if (event.conversation_id) {
|
|
836
|
+
this.currentConversationId = event.conversation_id;
|
|
837
|
+
}
|
|
838
|
+
} else if (event.event === 'step_update') {
|
|
325
839
|
const stepUpdate = event.step_update;
|
|
326
840
|
const delta = stepUpdate?.text_delta;
|
|
327
841
|
const stepType = stepUpdate?.step_type;
|
|
842
|
+
if (stepType === 'tool') {
|
|
843
|
+
const state = stepUpdate?.state;
|
|
844
|
+
const toolInfo = stepUpdate?.tool_info || {};
|
|
845
|
+
const name = stepUpdate?.tool_name || toolInfo?.name;
|
|
846
|
+
const status = state === 'DONE'
|
|
847
|
+
? 'completed'
|
|
848
|
+
: (state === 'ERROR' ? 'failed' : 'running');
|
|
849
|
+
const rawParams = (toolInfo && typeof toolInfo === 'object' && toolInfo.parameters) ||
|
|
850
|
+
(stepUpdate && typeof stepUpdate === 'object' && stepUpdate.parameters) ||
|
|
851
|
+
(toolInfo && typeof toolInfo === 'object' && toolInfo.input) ||
|
|
852
|
+
{};
|
|
853
|
+
|
|
854
|
+
if (name) {
|
|
855
|
+
const existingAttempt = attemptedNativeTools.find(a => a.name === name && a.status === 'running');
|
|
856
|
+
if (existingAttempt) {
|
|
857
|
+
existingAttempt.status = status;
|
|
858
|
+
if (rawParams && Object.keys(rawParams).length > 0) {
|
|
859
|
+
existingAttempt.parameters = { ...existingAttempt.parameters, ...rawParams };
|
|
860
|
+
}
|
|
861
|
+
if (toolInfo?.error?.message) existingAttempt.error = toolInfo.error.message;
|
|
862
|
+
} else {
|
|
863
|
+
attemptedNativeTools.push({
|
|
864
|
+
name,
|
|
865
|
+
parameters: { ...rawParams },
|
|
866
|
+
status,
|
|
867
|
+
error: toolInfo?.error?.message,
|
|
868
|
+
detail: describeNativeAction(toolInfo) || describeNativeAction({ parameters: rawParams })
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
if (name && (state === 'ACTIVE' || state === 'DONE' || state === 'ERROR')) {
|
|
874
|
+
const detail = describeNativeAction(toolInfo) || describeNativeAction({ parameters: rawParams });
|
|
875
|
+
const action: ChatResponseAction = {
|
|
876
|
+
name,
|
|
877
|
+
status,
|
|
878
|
+
...(detail ? { detail } : {})
|
|
879
|
+
};
|
|
880
|
+
if (status !== 'running') {
|
|
881
|
+
const existing = nativeActions.find(a => a.name === action.name && a.detail === action.detail);
|
|
882
|
+
if (existing) existing.status = status;
|
|
883
|
+
else nativeActions.push(action);
|
|
884
|
+
}
|
|
885
|
+
// Stream the start; completion is reported only after the
|
|
886
|
+
// final result has checked for denied actions.
|
|
887
|
+
if (status === 'running' && typeof options.onNativeAction === 'function') {
|
|
888
|
+
const parameters = rawParams && typeof rawParams === 'object'
|
|
889
|
+
? rawParams as Record<string, unknown>
|
|
890
|
+
: {};
|
|
891
|
+
options.onNativeAction({ ...action, parameters });
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
}
|
|
328
895
|
if (delta && typeof delta === 'string') {
|
|
329
896
|
if (stepType === 'thought' || stepType === 'agent_thought') {
|
|
330
897
|
if (typeof options.onReasoningChunk === 'function') {
|
|
@@ -339,7 +906,11 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
339
906
|
}
|
|
340
907
|
} else if (event.event === 'result') {
|
|
341
908
|
finalResultObj = event.result;
|
|
909
|
+
if (event.result?.conversation_id) {
|
|
910
|
+
this.currentConversationId = event.result.conversation_id;
|
|
911
|
+
}
|
|
342
912
|
} else if (event.status === 'ERROR') {
|
|
913
|
+
if (useConversation) this.currentConversationId = null;
|
|
343
914
|
safeReject(new Error(`Antigravity Agent returned error: ${event.error || 'Unknown error'}`));
|
|
344
915
|
return;
|
|
345
916
|
}
|
|
@@ -355,17 +926,23 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
355
926
|
});
|
|
356
927
|
|
|
357
928
|
child.on('error', (err: Error) => {
|
|
929
|
+
if (useConversation) this.currentConversationId = null;
|
|
358
930
|
safeReject(new Error(`Antigravity Agent (agy) spawn error: ${err.message}. Make sure Antigravity CLI is installed.`));
|
|
359
931
|
});
|
|
360
932
|
|
|
361
933
|
child.on('close', (code: number | null) => {
|
|
934
|
+
childClosed = true;
|
|
362
935
|
// Process any remaining bytes in stdoutBuffer
|
|
363
936
|
if (stdoutBuffer.trim()) {
|
|
364
937
|
try {
|
|
365
938
|
const event = JSON.parse(stdoutBuffer.trim());
|
|
366
939
|
if (event.event === 'result') {
|
|
367
940
|
finalResultObj = event.result;
|
|
941
|
+
if (event.result?.conversation_id) {
|
|
942
|
+
this.currentConversationId = event.result.conversation_id;
|
|
943
|
+
}
|
|
368
944
|
} else if (event.status === 'ERROR') {
|
|
945
|
+
if (useConversation) this.currentConversationId = null;
|
|
369
946
|
safeReject(new Error(`Antigravity Agent returned error: ${event.error || 'Unknown error'}`));
|
|
370
947
|
return;
|
|
371
948
|
}
|
|
@@ -374,8 +951,9 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
374
951
|
}
|
|
375
952
|
}
|
|
376
953
|
|
|
377
|
-
if (code !== 0
|
|
378
|
-
|
|
954
|
+
if (code !== 0 || finalResultObj?.status === 'ERROR') {
|
|
955
|
+
if (useConversation) this.currentConversationId = null;
|
|
956
|
+
const errDetail = finalResultObj?.error || stderrBuffer.trim() || `exit code ${code}`;
|
|
379
957
|
safeReject(new Error(`Antigravity Agent (agy) failed: ${errDetail}`));
|
|
380
958
|
return;
|
|
381
959
|
}
|
|
@@ -395,12 +973,68 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
395
973
|
// Strip tool call tags from prose so raw XML does not leak into chat display
|
|
396
974
|
let content = rawContent.replace(/<tool_call>[\s\S]*?<\/tool_call>/g, '').trim();
|
|
397
975
|
|
|
398
|
-
|
|
399
|
-
|
|
976
|
+
const deniedActions: any[] = Array.isArray(finalResultObj?.denied_actions)
|
|
977
|
+
? finalResultObj.denied_actions : [];
|
|
978
|
+
const normalizeAction = (value: unknown): string =>
|
|
979
|
+
String(value || '').toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
980
|
+
const deniedNames = new Set(deniedActions.flatMap(action =>
|
|
981
|
+
[normalizeAction(action?.action), normalizeAction(action?.display_name)]).filter(Boolean));
|
|
982
|
+
for (const action of nativeActions) {
|
|
983
|
+
if (deniedNames.has(normalizeAction(action.name))) action.status = 'failed';
|
|
984
|
+
if (typeof options.onNativeAction === 'function') {
|
|
985
|
+
const attempt = [...attemptedNativeTools].reverse().find(candidate =>
|
|
986
|
+
normalizeAction(candidate.name) === normalizeAction(action.name));
|
|
987
|
+
options.onNativeAction({ ...action, parameters: attempt?.parameters || {} });
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
if (deniedActions.length > 0) {
|
|
992
|
+
const unmapped: string[] = [];
|
|
993
|
+
for (const denied of deniedActions) {
|
|
994
|
+
const name = String(denied?.action || denied?.display_name || 'unknown');
|
|
995
|
+
const attempt = [...attemptedNativeTools].reverse().find(candidate =>
|
|
996
|
+
normalizeAction(candidate.name) === normalizeAction(name)
|
|
997
|
+
|| normalizeAction(candidate.name) === normalizeAction(denied?.display_name));
|
|
998
|
+
const parameters = {
|
|
999
|
+
...(attempt?.parameters || {}),
|
|
1000
|
+
...(denied?.parameters || {}),
|
|
1001
|
+
...(attempt?.detail ? { detail: attempt.detail } : {})
|
|
1002
|
+
};
|
|
1003
|
+
const mapped = mapNativeToolToCausyne(attempt?.name || String(denied?.display_name || name), parameters, toolCalls.length);
|
|
1004
|
+
if (!mapped) {
|
|
1005
|
+
unmapped.push(String(denied?.display_name || name));
|
|
1006
|
+
continue;
|
|
1007
|
+
}
|
|
1008
|
+
if (!toolCalls.some(call => call.function.name === mapped.function.name
|
|
1009
|
+
&& call.function.arguments === mapped.function.arguments)) {
|
|
1010
|
+
toolCalls.push(mapped);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
if (unmapped.length > 0) {
|
|
1014
|
+
const error = new Error(`Antigravity could not perform: ${unmapped.join(', ')}. The denied action had no safe Causyne tool mapping.`) as Error & { code: string };
|
|
1015
|
+
error.code = 'AGY_NATIVE_ACTION_DENIED';
|
|
1016
|
+
safeReject(error);
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
1019
|
+
// Any prose produced alongside a denied action may claim work that
|
|
1020
|
+
// did not occur. Wait for the mapped Causyne tool result instead.
|
|
1021
|
+
content = '';
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
const completedNativeActions = nativeActions.filter((a: ChatResponseAction) => a.status === 'completed');
|
|
1025
|
+
|
|
1026
|
+
if (!content && completedNativeActions.length > 0) {
|
|
1027
|
+
content = `Antigravity completed: ${completedNativeActions
|
|
1028
|
+
.map((a: ChatResponseAction) => `${a.name}${a.detail ? ` (${a.detail})` : ''}`)
|
|
1029
|
+
.join(', ')}`;
|
|
400
1030
|
}
|
|
401
1031
|
|
|
402
1032
|
if (!content && toolCalls.length === 0) {
|
|
403
|
-
|
|
1033
|
+
const detail = stderrBuffer.trim();
|
|
1034
|
+
safeReject(new Error(detail
|
|
1035
|
+
? `Antigravity returned no response: ${detail}`
|
|
1036
|
+
: 'Antigravity returned no response.'));
|
|
1037
|
+
return;
|
|
404
1038
|
}
|
|
405
1039
|
|
|
406
1040
|
const promptTokens = Number(finalResultObj?.usage?.input_tokens) || Math.ceil(promptText.length / 4);
|
|
@@ -408,7 +1042,7 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
408
1042
|
const thinkingTokens = Number(finalResultObj?.usage?.thinking_tokens) || 0;
|
|
409
1043
|
|
|
410
1044
|
const response: ChatResponse = {
|
|
411
|
-
content
|
|
1045
|
+
content,
|
|
412
1046
|
usage: {
|
|
413
1047
|
promptTokens,
|
|
414
1048
|
completionTokens: completionTokens + thinkingTokens,
|
|
@@ -424,13 +1058,17 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
424
1058
|
response.toolCalls = toolCalls;
|
|
425
1059
|
}
|
|
426
1060
|
|
|
1061
|
+
if (nativeActions.length > 0) {
|
|
1062
|
+
response.externalActions = nativeActions.filter((a: ChatResponseAction) => a.status !== 'running');
|
|
1063
|
+
}
|
|
1064
|
+
|
|
427
1065
|
safeResolve(response);
|
|
428
1066
|
});
|
|
429
1067
|
});
|
|
430
1068
|
}
|
|
431
1069
|
|
|
432
1070
|
override async chat(messages: any[], options: ChatOptions = {}): Promise<ChatResponse> {
|
|
433
|
-
const maxRetries = options.maxRetries ?? 2;
|
|
1071
|
+
const maxRetries = options.maxRetries ?? ((options as any).taskIntent === 'launch' ? 1 : 2);
|
|
434
1072
|
let attempt = 0;
|
|
435
1073
|
while (attempt <= maxRetries) {
|
|
436
1074
|
try {
|