@causyne/agent 1.20.7 → 1.20.9
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/package.json +1 -1
- package/src/acp/agentCatalog.js +9 -3
- package/src/acp/agentCatalog.ts +20 -4
- package/src/agentLoop.js +167 -34
- package/src/agentLoop.ts +188 -37
- package/src/commands.js +25 -10
- package/src/compiledSkills.js +7330 -319
- package/src/computerUse/types.js +8 -0
- package/src/computerUse/types.ts +121 -0
- package/src/computerUse/visionGrounding.js +87 -29
- package/src/computerUse/visionGrounding.ts +108 -36
- package/src/decisionPolicy.js +7 -9
- package/src/decisionPolicy.ts +7 -9
- package/src/documentEngine/antiSlopAuditor.js +13 -43
- package/src/documentEngine/antiSlopAuditor.ts +15 -47
- package/src/documentEngine/documentForge.js +3 -3
- package/src/documentEngine/documentForge.ts +3 -3
- package/src/dynamicCatalogue.js +568 -77
- package/src/dynamicCatalogue.ts +608 -79
- package/src/launchIntent.js +3 -3
- package/src/launchIntent.ts +3 -3
- package/src/planCache.js +4 -14
- package/src/planCache.ts +4 -14
- package/src/providers/acp.js +39 -4
- package/src/providers/acp.ts +42 -4
- package/src/providers/antigravity.d.ts +7 -1
- package/src/providers/antigravity.js +222 -34
- package/src/providers/antigravity.ts +220 -33
- package/src/providers/base.d.ts +2 -0
- package/src/providers/pi.js +3 -1
- package/src/providers/pi.ts +4 -2
- package/src/sandbox.js +7 -10
- package/src/smartToolsUse.js +203 -0
- package/src/smartToolsUse.ts +263 -0
- package/src/taskShape.js +7 -7
- package/src/taskShape.ts +7 -7
- package/src/toolPacks.js +5 -5
- package/src/tools/blenderAutomator.js +198 -11
- package/src/tools/documentForge.js +1 -1
- package/src/tools/documentForge.ts +1 -1
- package/src/tui/modelPicker.js +288 -69
- package/src/tui/modelPicker.ts +333 -72
|
@@ -2,7 +2,7 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { isLaunchOnlyPrompt } from '../launchIntent.js';
|
|
5
|
-
import { LLMProvider, type ProviderConfig, type ChatOptions, type ChatResponse, type ChatResponseAction, type ChatResponseToolCall } from './base.js';
|
|
5
|
+
import { LLMProvider, type ProviderConfig, type ChatOptions, type ChatResponse, type ChatResponseAction, type ChatResponseToolCall, type ChatResponseUsage } from './base.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Baseline fallback models for instant offline availability.
|
|
@@ -35,10 +35,31 @@ export const ANTIGRAVITY_LABEL_BY_ID: Record<string, string> = Object.fromEntrie
|
|
|
35
35
|
|
|
36
36
|
export const ANTIGRAVITY_MODELS: string[] = Object.keys(ANTIGRAVITY_MODEL_IDS);
|
|
37
37
|
|
|
38
|
+
export function synthesizeAgySlug(input: string): string {
|
|
39
|
+
const trimmed = input.trim();
|
|
40
|
+
if (!trimmed) return '';
|
|
41
|
+
if (!/[\s()]/.test(trimmed)) {
|
|
42
|
+
return trimmed;
|
|
43
|
+
}
|
|
44
|
+
let slug = trimmed
|
|
45
|
+
.toLowerCase()
|
|
46
|
+
.replace(/\(([^()]+)\)/g, ' $1 ')
|
|
47
|
+
.replace(/[^a-z0-9.]+/g, '-')
|
|
48
|
+
.replace(/^-+|-+$/g, '')
|
|
49
|
+
.replace(/-{2,}/g, '-');
|
|
50
|
+
if (slug.startsWith('claude-')) {
|
|
51
|
+
slug = slug.replace(/\./g, '-');
|
|
52
|
+
}
|
|
53
|
+
return slug;
|
|
54
|
+
}
|
|
55
|
+
|
|
38
56
|
export function registerAntigravityModel(slug: string, label?: string): void {
|
|
39
57
|
if (!slug || typeof slug !== 'string') return;
|
|
40
|
-
const
|
|
41
|
-
const cleanLabel = (label && typeof label === 'string' && label.trim()) ||
|
|
58
|
+
const rawSlug = slug.trim();
|
|
59
|
+
const cleanLabel = (label && typeof label === 'string' && label.trim()) || rawSlug;
|
|
60
|
+
const cleanSlug = /[\s()]/.test(rawSlug)
|
|
61
|
+
? (ANTIGRAVITY_MODEL_IDS[rawSlug] || synthesizeAgySlug(rawSlug))
|
|
62
|
+
: rawSlug;
|
|
42
63
|
|
|
43
64
|
ANTIGRAVITY_MODEL_IDS[cleanLabel] = cleanSlug;
|
|
44
65
|
ANTIGRAVITY_MODEL_IDS[cleanSlug] = cleanSlug;
|
|
@@ -48,7 +69,41 @@ export function registerAntigravityModel(slug: string, label?: string): void {
|
|
|
48
69
|
}
|
|
49
70
|
}
|
|
50
71
|
|
|
51
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Authoritatively replace the active Antigravity model list with the live
|
|
74
|
+
* models returned by the user's current Antigravity account/tier, while
|
|
75
|
+
* preserving slug lookup mappings in ANTIGRAVITY_MODEL_IDS.
|
|
76
|
+
*/
|
|
77
|
+
export function replaceAntigravityModels(
|
|
78
|
+
items: Array<{ id: string; label?: string } | string>
|
|
79
|
+
): string[] {
|
|
80
|
+
const nextLabels: string[] = [];
|
|
81
|
+
for (const item of items) {
|
|
82
|
+
if (typeof item === 'string') {
|
|
83
|
+
const trimmed = item.trim();
|
|
84
|
+
if (!trimmed) continue;
|
|
85
|
+
const existingSlug = ANTIGRAVITY_MODEL_IDS[trimmed] || synthesizeAgySlug(trimmed);
|
|
86
|
+
const label = ANTIGRAVITY_LABEL_BY_ID[trimmed] || trimmed;
|
|
87
|
+
registerAntigravityModel(existingSlug, label);
|
|
88
|
+
if (!nextLabels.includes(label)) nextLabels.push(label);
|
|
89
|
+
} else if (item && typeof item === 'object' && typeof item.id === 'string') {
|
|
90
|
+
const id = item.id.trim();
|
|
91
|
+
if (!id) continue;
|
|
92
|
+
const label = (item.label && item.label.trim()) || ANTIGRAVITY_LABEL_BY_ID[id] || id;
|
|
93
|
+
registerAntigravityModel(id, label);
|
|
94
|
+
if (!nextLabels.includes(label)) nextLabels.push(label);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (nextLabels.length > 0) {
|
|
98
|
+
ANTIGRAVITY_MODELS.splice(0, ANTIGRAVITY_MODELS.length, ...nextLabels);
|
|
99
|
+
}
|
|
100
|
+
return [...ANTIGRAVITY_MODELS];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function parseAgyModelsOutput(
|
|
104
|
+
stdout: string,
|
|
105
|
+
options: { replaceActiveList?: boolean } = {}
|
|
106
|
+
): Array<{ id: string; label: string }> {
|
|
52
107
|
const result: Array<{ id: string; label: string }> = [];
|
|
53
108
|
if (!stdout || typeof stdout !== 'string') return result;
|
|
54
109
|
|
|
@@ -56,7 +111,7 @@ export function parseAgyModelsOutput(stdout: string): Array<{ id: string; label:
|
|
|
56
111
|
for (const rawLine of lines) {
|
|
57
112
|
const line = rawLine.replace(/\u001b\[[0-9;]*[A-Za-z]/g, '').trim();
|
|
58
113
|
if (!line) continue;
|
|
59
|
-
if (/^(fetching|loading|no models|error)/i.test(line)) continue;
|
|
114
|
+
if (/^(fetching|loading|no models|error|warning|usage|available)/i.test(line)) continue;
|
|
60
115
|
if (line.endsWith('…') || line.endsWith('...')) continue;
|
|
61
116
|
|
|
62
117
|
const cleanLine = line.replace(/^[^a-zA-Z0-9_-]+/, '');
|
|
@@ -64,28 +119,56 @@ export function parseAgyModelsOutput(stdout: string): Array<{ id: string; label:
|
|
|
64
119
|
if (!match) continue;
|
|
65
120
|
|
|
66
121
|
const id = match[1]!.trim();
|
|
67
|
-
const label = (match[2] && match[2].trim()) || id;
|
|
122
|
+
const label = ((match[2] && match[2].trim()) || id).replace(/\s+\(default\)$/i, '').trim();
|
|
68
123
|
result.push({ id, label });
|
|
69
124
|
registerAntigravityModel(id, label);
|
|
70
125
|
}
|
|
126
|
+
if (options.replaceActiveList && result.length > 0) {
|
|
127
|
+
replaceAntigravityModels(result);
|
|
128
|
+
}
|
|
71
129
|
return result;
|
|
72
130
|
}
|
|
73
131
|
|
|
74
|
-
function
|
|
132
|
+
export function isAntigravityOnboarded(): boolean {
|
|
75
133
|
try {
|
|
76
134
|
const home = process.env.HOME || process.env.USERPROFILE || '';
|
|
77
|
-
|
|
135
|
+
if (!home) return false;
|
|
136
|
+
const onboardingFile = path.join(home, '.gemini', 'antigravity-cli', 'cache', 'onboarding.json');
|
|
137
|
+
if (fs.existsSync(onboardingFile)) {
|
|
138
|
+
const parsed = JSON.parse(fs.readFileSync(onboardingFile, 'utf8'));
|
|
139
|
+
if (parsed && parsed.onboardingComplete === true) return true;
|
|
140
|
+
}
|
|
141
|
+
const oauthFile = path.join(home, '.gemini', 'oauth_creds.json');
|
|
142
|
+
if (fs.existsSync(oauthFile)) return true;
|
|
143
|
+
} catch {
|
|
144
|
+
// ignore read errors
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function hydrateModelsFromDiskCache(): void {
|
|
150
|
+
try {
|
|
151
|
+
const causyneDir = process.env.CAUSYNE_HOME
|
|
152
|
+
|| path.join(process.env.HOME || process.env.USERPROFILE || '', '.causyne');
|
|
153
|
+
const cacheFile = path.join(causyneDir, 'models_cache.json');
|
|
78
154
|
if (!fs.existsSync(cacheFile)) return;
|
|
79
155
|
const content = fs.readFileSync(cacheFile, 'utf8');
|
|
80
156
|
const parsed = JSON.parse(content);
|
|
81
|
-
const
|
|
82
|
-
if (
|
|
157
|
+
const agyEntry = parsed?.providers?.antigravity;
|
|
158
|
+
if (agyEntry?.modelIdMap && typeof agyEntry.modelIdMap === 'object') {
|
|
159
|
+
for (const [label, slug] of Object.entries(agyEntry.modelIdMap)) {
|
|
160
|
+
if (typeof slug === 'string' && slug.trim()) {
|
|
161
|
+
registerAntigravityModel(slug.trim(), label);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const agyModels = agyEntry?.models;
|
|
166
|
+
if (Array.isArray(agyModels) && agyModels.length > 0) {
|
|
83
167
|
for (const item of agyModels) {
|
|
84
168
|
if (typeof item === 'string' && item.trim()) {
|
|
85
169
|
const trimmed = item.trim();
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
170
|
+
const slug = ANTIGRAVITY_MODEL_IDS[trimmed] || synthesizeAgySlug(trimmed);
|
|
171
|
+
registerAntigravityModel(slug, trimmed);
|
|
89
172
|
}
|
|
90
173
|
}
|
|
91
174
|
}
|
|
@@ -125,6 +208,10 @@ export function resolveAgyModelId(model?: string | null): string {
|
|
|
125
208
|
}
|
|
126
209
|
}
|
|
127
210
|
|
|
211
|
+
if (/[\s()]/.test(trimmed)) {
|
|
212
|
+
return synthesizeAgySlug(trimmed);
|
|
213
|
+
}
|
|
214
|
+
|
|
128
215
|
return trimmed;
|
|
129
216
|
}
|
|
130
217
|
|
|
@@ -420,6 +507,7 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
420
507
|
printTimeout: string;
|
|
421
508
|
currentConversationId: string | null = null;
|
|
422
509
|
lastTaskId: string | null = null;
|
|
510
|
+
private lastCumulativeUsage: { conversationId: string; input: number; output: number; thinking: number; cacheRead: number } | null = null;
|
|
423
511
|
|
|
424
512
|
constructor(config: ProviderConfig = {}) {
|
|
425
513
|
super(config);
|
|
@@ -499,7 +587,7 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
499
587
|
'[Environment State & Idempotency Directive]\n' +
|
|
500
588
|
'Reuse relevant verified tool results from this session, and check uncertain prerequisites before relying on them.\n\n' +
|
|
501
589
|
'[Language & Communication Directive]\n' +
|
|
502
|
-
'Dynamically reflect and match the exact language used by the user in their prompt.
|
|
590
|
+
'Dynamically reflect and match the exact language used by the user in their prompt. Respond naturally in that same language. Never send conversational pleasantries or canned greetings.'
|
|
503
591
|
);
|
|
504
592
|
|
|
505
593
|
if (tools && tools.length > 0) {
|
|
@@ -676,16 +764,20 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
676
764
|
const currentSessionKey = (options as any).conversationId || (options as any).taskId || null;
|
|
677
765
|
if (currentSessionKey && currentSessionKey !== this.lastTaskId) {
|
|
678
766
|
this.currentConversationId = null;
|
|
767
|
+
this.lastCumulativeUsage = null;
|
|
679
768
|
this.lastTaskId = currentSessionKey;
|
|
680
769
|
}
|
|
681
770
|
if (messages.length <= 1) {
|
|
682
771
|
this.currentConversationId = null;
|
|
772
|
+
this.lastCumulativeUsage = null;
|
|
683
773
|
}
|
|
684
774
|
|
|
685
775
|
const useConversation = Boolean(this.currentConversationId);
|
|
776
|
+
const resumedConversationId = this.currentConversationId;
|
|
686
777
|
const latestUserMessage = [...messages].reverse().find(message => message.role === 'user');
|
|
687
778
|
const latestPrompt = typeof latestUserMessage?.content === 'string' ? latestUserMessage.content : '';
|
|
688
779
|
const launchOnly = (options as any).taskIntent === 'launch' || isLaunchOnlyPrompt(latestPrompt);
|
|
780
|
+
const desktopTask = (options as any).taskArchetype === 'desktop_personalization';
|
|
689
781
|
let promptText: string;
|
|
690
782
|
|
|
691
783
|
if (useConversation) {
|
|
@@ -710,6 +802,13 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
710
802
|
'Do not create, edit, delete, install, or regenerate files. Do not claim the app opened unless a tool confirmed it. ' +
|
|
711
803
|
'Use Causyne tool calls for commands and desktop opening.\n\n' + promptText;
|
|
712
804
|
}
|
|
805
|
+
if (desktopTask) {
|
|
806
|
+
promptText = '[Current desktop task: finish and verify the requested change]\n' +
|
|
807
|
+
'Use only the tools needed. Search and download alone are not completion. ' +
|
|
808
|
+
'After setting the desktop picture, read back the actual system wallpaper and compare it with the intended image. ' +
|
|
809
|
+
'If a command is denied or the readback does not confirm the change, report the blocker honestly. ' +
|
|
810
|
+
'Keep native tool actions within 12; use Causyne tool calls when a native action is blocked.\n\n' + promptText;
|
|
811
|
+
}
|
|
713
812
|
|
|
714
813
|
const modelSlug = resolveAgyModelId(this.model);
|
|
715
814
|
const effort = resolveAgyEffort(this.model);
|
|
@@ -772,8 +871,39 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
772
871
|
detail?: string | undefined;
|
|
773
872
|
}[] = [];
|
|
774
873
|
let childClosed = false;
|
|
874
|
+
const terminateChild = () => {
|
|
875
|
+
try {
|
|
876
|
+
child.kill('SIGTERM');
|
|
877
|
+
setTimeout(() => {
|
|
878
|
+
if (!childClosed) child.kill('SIGKILL');
|
|
879
|
+
}, 1000).unref();
|
|
880
|
+
} catch {
|
|
881
|
+
// A process that already exited needs no further action.
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
const maxNativeActions = desktopTask ? 12 : Infinity;
|
|
885
|
+
let nativeActionStarts = 0;
|
|
886
|
+
const seenNativeActionSteps = new Set<number>();
|
|
887
|
+
// Antigravity's result usage is cumulative across the conversation, but
|
|
888
|
+
// DONE step updates carry usage for that step. Keep a turn-local subtotal
|
|
889
|
+
// so a single headless run cannot consume an entire task budget unseen.
|
|
890
|
+
const completedUsageSteps = new Set<number>();
|
|
891
|
+
const partialUsage: ChatResponseUsage = {
|
|
892
|
+
promptTokens: 0, completionTokens: 0, cachedPromptTokens: 0,
|
|
893
|
+
thinkingTokens: 0, measurement: 'provider_reported', cacheMeasurement: 'provider_reported'
|
|
894
|
+
};
|
|
895
|
+
const tokenLimit = Number(options.maxTokensThisCall);
|
|
896
|
+
const enforceTokenLimit = Number.isFinite(tokenLimit) && tokenLimit > 0;
|
|
897
|
+
const wallTimer = desktopTask ? setTimeout(() => {
|
|
898
|
+
const error = new Error('Antigravity exceeded the 180-second desktop task limit. Outcome is unverified.') as Error & { code: string };
|
|
899
|
+
error.code = 'AGY_DESKTOP_TASK_LIMIT';
|
|
900
|
+
safeReject(error);
|
|
901
|
+
terminateChild();
|
|
902
|
+
}, 180_000) : null;
|
|
903
|
+
wallTimer?.unref();
|
|
775
904
|
|
|
776
905
|
const cleanup = () => {
|
|
906
|
+
if (wallTimer) clearTimeout(wallTimer);
|
|
777
907
|
if (options.signal) {
|
|
778
908
|
options.signal.removeEventListener('abort', onAbort);
|
|
779
909
|
}
|
|
@@ -794,14 +924,7 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
794
924
|
};
|
|
795
925
|
|
|
796
926
|
const onAbort = () => {
|
|
797
|
-
|
|
798
|
-
child.kill('SIGTERM');
|
|
799
|
-
setTimeout(() => {
|
|
800
|
-
if (!childClosed) child.kill('SIGKILL');
|
|
801
|
-
}, 1000).unref();
|
|
802
|
-
} catch {
|
|
803
|
-
// ignore kill errors
|
|
804
|
-
}
|
|
927
|
+
terminateChild();
|
|
805
928
|
const abortErr = new Error('Turn aborted by user or timeout.');
|
|
806
929
|
abortErr.name = 'AbortError';
|
|
807
930
|
safeReject(abortErr);
|
|
@@ -844,15 +967,52 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
844
967
|
}
|
|
845
968
|
} else if (event.event === 'step_update') {
|
|
846
969
|
const stepUpdate = event.step_update;
|
|
970
|
+
const usage = stepUpdate?.usage;
|
|
971
|
+
const usageStepIndex = Number(stepUpdate?.step_index ?? event?.step_index);
|
|
972
|
+
if (stepUpdate?.state === 'DONE' && usage && Number.isFinite(usageStepIndex)
|
|
973
|
+
&& !completedUsageSteps.has(usageStepIndex)) {
|
|
974
|
+
const input = Number(usage.input_tokens);
|
|
975
|
+
const output = Number(usage.output_tokens);
|
|
976
|
+
if (Number.isFinite(input) && input >= 0 && Number.isFinite(output) && output >= 0) {
|
|
977
|
+
completedUsageSteps.add(usageStepIndex);
|
|
978
|
+
partialUsage.promptTokens += input;
|
|
979
|
+
partialUsage.completionTokens += output;
|
|
980
|
+
partialUsage.cachedPromptTokens = (partialUsage.cachedPromptTokens || 0)
|
|
981
|
+
+ (Number(usage.cache_read_tokens) || 0);
|
|
982
|
+
partialUsage.thinkingTokens = (partialUsage.thinkingTokens || 0)
|
|
983
|
+
+ (Number(usage.thinking_tokens) || 0);
|
|
984
|
+
if (enforceTokenLimit && partialUsage.promptTokens + partialUsage.completionTokens >= tokenLimit) {
|
|
985
|
+
this.currentConversationId = null;
|
|
986
|
+
const error = Object.assign(
|
|
987
|
+
new Error(`Antigravity token budget reached during this turn: at least ${partialUsage.promptTokens + partialUsage.completionTokens} tokens reported for a ${tokenLimit}-token remaining budget. The task outcome is unverified.`),
|
|
988
|
+
{ code: 'AGY_TOKEN_BUDGET', partialUsage: { ...partialUsage } }
|
|
989
|
+
);
|
|
990
|
+
safeReject(error);
|
|
991
|
+
terminateChild();
|
|
992
|
+
return;
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
}
|
|
847
996
|
const delta = stepUpdate?.text_delta;
|
|
848
997
|
const stepType = stepUpdate?.step_type;
|
|
849
998
|
if (stepType === 'tool') {
|
|
850
999
|
const state = stepUpdate?.state;
|
|
1000
|
+
const stepIndex = Number(stepUpdate?.step_index ?? event?.step_index);
|
|
1001
|
+
const newNativeAction = (state === 'ACTIVE' || (state === 'DONE' && Number.isFinite(stepIndex)))
|
|
1002
|
+
&& (!Number.isFinite(stepIndex) || !seenNativeActionSteps.has(stepIndex));
|
|
1003
|
+
if (newNativeAction && Number.isFinite(stepIndex)) seenNativeActionSteps.add(stepIndex);
|
|
1004
|
+
if (desktopTask && newNativeAction && ++nativeActionStarts > maxNativeActions) {
|
|
1005
|
+
const error = new Error(`Antigravity exceeded ${maxNativeActions} native actions for this desktop task. Outcome is unverified.`) as Error & { code: string };
|
|
1006
|
+
error.code = 'AGY_NATIVE_ACTION_BUDGET';
|
|
1007
|
+
safeReject(error);
|
|
1008
|
+
terminateChild();
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
851
1011
|
const toolInfo = stepUpdate?.tool_info || {};
|
|
852
1012
|
const name = stepUpdate?.tool_name || toolInfo?.name;
|
|
853
|
-
const status = state === 'DONE'
|
|
854
|
-
? 'completed'
|
|
855
|
-
:
|
|
1013
|
+
const status = state === 'DONE' || state === 'ERROR'
|
|
1014
|
+
? (state === 'ERROR' || toolInfo?.error ? 'failed' : 'completed')
|
|
1015
|
+
: 'running';
|
|
856
1016
|
const rawParams = (toolInfo && typeof toolInfo === 'object' && toolInfo.parameters) ||
|
|
857
1017
|
(stepUpdate && typeof stepUpdate === 'object' && stepUpdate.parameters) ||
|
|
858
1018
|
(toolInfo && typeof toolInfo === 'object' && toolInfo.input) ||
|
|
@@ -949,6 +1109,9 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
949
1109
|
|
|
950
1110
|
child.on('close', (code: number | null) => {
|
|
951
1111
|
childClosed = true;
|
|
1112
|
+
// A budget or user abort has already settled this call. Do not accept
|
|
1113
|
+
// a late result from the terminated process as a resumable session.
|
|
1114
|
+
if (isSettled) return;
|
|
952
1115
|
// Process any remaining bytes in stdoutBuffer
|
|
953
1116
|
if (stdoutBuffer.trim()) {
|
|
954
1117
|
try {
|
|
@@ -968,9 +1131,10 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
968
1131
|
}
|
|
969
1132
|
}
|
|
970
1133
|
|
|
971
|
-
if (code !== 0 || finalResultObj?.status
|
|
1134
|
+
if (code !== 0 || (finalResultObj?.status && finalResultObj.status !== 'SUCCESS')) {
|
|
972
1135
|
if (useConversation) this.currentConversationId = null;
|
|
973
|
-
const errDetail = finalResultObj?.error || stderrBuffer.trim() ||
|
|
1136
|
+
const errDetail = finalResultObj?.error || stderrBuffer.trim() ||
|
|
1137
|
+
`terminal status ${finalResultObj?.status || 'unknown'}, exit code ${code}`;
|
|
974
1138
|
safeReject(new Error(`Antigravity Agent (agy) failed: ${errDetail}`));
|
|
975
1139
|
return;
|
|
976
1140
|
}
|
|
@@ -1061,16 +1225,34 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
1061
1225
|
const missingResultEvent =
|
|
1062
1226
|
finalResultObj === null && deniedActions.length === 0 && toolCalls.length === 0;
|
|
1063
1227
|
|
|
1064
|
-
const
|
|
1065
|
-
|
|
1066
|
-
|
|
1228
|
+
const usageIsReported = finalResultObj?.usage?.input_tokens != null
|
|
1229
|
+
&& finalResultObj?.usage?.output_tokens != null
|
|
1230
|
+
&& Number.isFinite(Number(finalResultObj.usage.input_tokens))
|
|
1231
|
+
&& Number.isFinite(Number(finalResultObj.usage.output_tokens));
|
|
1232
|
+
const cumulative = {
|
|
1233
|
+
input: usageIsReported ? Number(finalResultObj.usage.input_tokens) : Math.ceil(promptText.length / 4),
|
|
1234
|
+
output: usageIsReported ? Number(finalResultObj.usage.output_tokens) : Math.ceil(rawContent.length / 4),
|
|
1235
|
+
thinking: Number(finalResultObj?.usage?.thinking_tokens) || 0,
|
|
1236
|
+
cacheRead: Number(finalResultObj?.usage?.cache_read_tokens) || 0
|
|
1237
|
+
};
|
|
1238
|
+
const prior = useConversation && resumedConversationId === this.lastCumulativeUsage?.conversationId
|
|
1239
|
+
? this.lastCumulativeUsage : null;
|
|
1240
|
+
const delta = (current: number, previous: number): number => current >= previous ? current - previous : current;
|
|
1241
|
+
const promptTokens = prior && usageIsReported ? delta(cumulative.input, prior.input) : cumulative.input;
|
|
1242
|
+
const completionTokens = prior && usageIsReported ? delta(cumulative.output, prior.output) : cumulative.output;
|
|
1243
|
+
const thinkingTokens = prior && usageIsReported ? delta(cumulative.thinking, prior.thinking) : cumulative.thinking;
|
|
1244
|
+
const cachedPromptTokens = prior && usageIsReported ? delta(cumulative.cacheRead, prior.cacheRead) : cumulative.cacheRead;
|
|
1067
1245
|
|
|
1068
1246
|
const response: ChatResponse = {
|
|
1069
1247
|
content,
|
|
1070
1248
|
usage: {
|
|
1071
1249
|
promptTokens,
|
|
1072
|
-
completionTokens
|
|
1073
|
-
|
|
1250
|
+
completionTokens,
|
|
1251
|
+
thinkingTokens,
|
|
1252
|
+
cachedPromptTokens,
|
|
1253
|
+
measurement: usageIsReported ? 'provider_reported' : 'text_estimate',
|
|
1254
|
+
cacheMeasurement: finalResultObj?.usage?.cache_read_tokens != null
|
|
1255
|
+
? 'provider_reported' : 'unavailable'
|
|
1074
1256
|
}
|
|
1075
1257
|
};
|
|
1076
1258
|
|
|
@@ -1090,6 +1272,9 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
1090
1272
|
response.incompleteTurn = true;
|
|
1091
1273
|
}
|
|
1092
1274
|
|
|
1275
|
+
if (usageIsReported && this.currentConversationId) {
|
|
1276
|
+
this.lastCumulativeUsage = { conversationId: this.currentConversationId, ...cumulative };
|
|
1277
|
+
}
|
|
1093
1278
|
safeResolve(response);
|
|
1094
1279
|
});
|
|
1095
1280
|
});
|
|
@@ -1107,7 +1292,9 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
1107
1292
|
throw err;
|
|
1108
1293
|
}
|
|
1109
1294
|
const canRetryResetConversation =
|
|
1110
|
-
hadConversation && !this.currentConversationId
|
|
1295
|
+
hadConversation && !this.currentConversationId
|
|
1296
|
+
&& (err as any)?.code !== 'AGY_NATIVE_ACTION_DENIED'
|
|
1297
|
+
&& (err as any)?.code !== 'AGY_TOKEN_BUDGET';
|
|
1111
1298
|
if (attempt < maxRetries && (this._isTransientError(err.message) || canRetryResetConversation)) {
|
|
1112
1299
|
attempt++;
|
|
1113
1300
|
const delay = attempt * 1200;
|
package/src/providers/base.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export interface ChatResponseUsage {
|
|
|
14
14
|
promptTokens: number;
|
|
15
15
|
completionTokens: number;
|
|
16
16
|
cachedPromptTokens?: number | undefined;
|
|
17
|
+
measurement?: 'provider_reported' | 'text_estimate' | undefined;
|
|
18
|
+
cacheMeasurement?: 'provider_reported' | 'unavailable' | undefined;
|
|
17
19
|
totalTokens?: number | undefined;
|
|
18
20
|
thinkingTokens?: number | undefined;
|
|
19
21
|
}
|
package/src/providers/pi.js
CHANGED
|
@@ -119,7 +119,9 @@ export class PiProvider extends LLMProvider {
|
|
|
119
119
|
usage = {
|
|
120
120
|
promptTokens: Number(data.input) || 0,
|
|
121
121
|
completionTokens: Number(data.output) || 0,
|
|
122
|
-
cachedPromptTokens: Number(data.cacheRead) || 0
|
|
122
|
+
cachedPromptTokens: Number(data.cacheRead) || 0,
|
|
123
|
+
measurement: data.input != null && data.output != null ? 'provider_reported' : 'text_estimate',
|
|
124
|
+
cacheMeasurement: data.cacheRead != null ? 'provider_reported' : 'unavailable'
|
|
123
125
|
};
|
|
124
126
|
}
|
|
125
127
|
else if (record.type === 'agent_settled') {
|
package/src/providers/pi.ts
CHANGED
|
@@ -45,7 +45,7 @@ export class PiProvider extends LLMProvider {
|
|
|
45
45
|
let acknowledged = false;
|
|
46
46
|
let settled = false;
|
|
47
47
|
let finished = false;
|
|
48
|
-
let usage = { promptTokens: 0, completionTokens: 0, cachedPromptTokens: 0 };
|
|
48
|
+
let usage: ChatResponse['usage'] = { promptTokens: 0, completionTokens: 0, cachedPromptTokens: 0 };
|
|
49
49
|
|
|
50
50
|
const cleanup = (): void => {
|
|
51
51
|
options.signal?.removeEventListener('abort', abort);
|
|
@@ -115,7 +115,9 @@ export class PiProvider extends LLMProvider {
|
|
|
115
115
|
usage = {
|
|
116
116
|
promptTokens: Number(data.input) || 0,
|
|
117
117
|
completionTokens: Number(data.output) || 0,
|
|
118
|
-
cachedPromptTokens: Number(data.cacheRead) || 0
|
|
118
|
+
cachedPromptTokens: Number(data.cacheRead) || 0,
|
|
119
|
+
measurement: data.input != null && data.output != null ? 'provider_reported' : 'text_estimate',
|
|
120
|
+
cacheMeasurement: data.cacheRead != null ? 'provider_reported' : 'unavailable'
|
|
119
121
|
};
|
|
120
122
|
} else if (record.type === 'agent_settled') {
|
|
121
123
|
if (record.aborted) stopReason = 'aborted';
|
package/src/sandbox.js
CHANGED
|
@@ -127,7 +127,7 @@ const SENSITIVE_WRITE_TARGETS = [
|
|
|
127
127
|
// Shell startup files: an appended line runs on the user's next shell.
|
|
128
128
|
/(^|\/)\.(bashrc|bash_profile|bash_login|profile|zshrc|zprofile|zshenv|zlogin)$/,
|
|
129
129
|
/(^|\/)\.config\/fish\/config\.fish$/,
|
|
130
|
-
//
|
|
130
|
+
// Remote session routing profiles and authentication credentials.
|
|
131
131
|
/(^|\/)\.ssh\//,
|
|
132
132
|
// Scheduled execution.
|
|
133
133
|
/(^|\/)(crontab|cron\.d)(\/|$)/,
|
|
@@ -477,15 +477,12 @@ export class Sandbox {
|
|
|
477
477
|
const masked = maskQuotedSpans(normalized);
|
|
478
478
|
|
|
479
479
|
|
|
480
|
-
// L3 (local-path audit): classify the
|
|
481
|
-
//
|
|
482
|
-
//
|
|
483
|
-
//
|
|
484
|
-
//
|
|
485
|
-
//
|
|
486
|
-
// auto-executed in every autonomy mode — persistence and remote access with
|
|
487
|
-
// no approval prompt. Writing to these files is escalated regardless of
|
|
488
|
-
// which harmless-looking command does the writing.
|
|
480
|
+
// L3 (local-path audit): classify the redirection target, not just the verb.
|
|
481
|
+
// Tool argument validation enforces boundaries on named arguments, but
|
|
482
|
+
// shell redirection targets appended via operators (>> or >) require independent
|
|
483
|
+
// audit. Writing into sensitive paths (such as user startup profiles, remote
|
|
484
|
+
// authentication directories, or agent configuration stores) must always escalate
|
|
485
|
+
// to extreme classification regardless of which command performs the redirection.
|
|
489
486
|
if (redirectsIntoSensitiveTarget(masked)) return 'extreme';
|
|
490
487
|
const executesQuotedText = INTERPRETER_INVOCATION.test(masked);
|
|
491
488
|
const destructiveScanTarget = executesQuotedText ? normalized : masked;
|