@causyne/agent 1.20.5 → 1.20.8
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 +25 -3
- package/SECURITY.md +1 -4
- package/package.json +1 -1
- package/src/acp/agentCatalog.js +9 -3
- package/src/acp/agentCatalog.ts +20 -4
- package/src/acp/client.js +174 -25
- package/src/acp/client.ts +165 -24
- package/src/acp/protocol.js +116 -0
- package/src/acp/protocol.ts +163 -0
- package/src/agentLoop.js +180 -8
- package/src/agentLoop.ts +185 -8
- package/src/commands.js +25 -10
- package/src/dynamicCatalogue.js +568 -77
- package/src/dynamicCatalogue.ts +608 -79
- package/src/providers/acp.js +141 -19
- package/src/providers/acp.ts +142 -19
- package/src/providers/antigravity.d.ts +7 -1
- package/src/providers/antigravity.js +135 -18
- package/src/providers/antigravity.ts +139 -18
- package/src/providers/base.d.ts +1 -0
- package/src/providers/pi.js +5 -1
- package/src/providers/pi.ts +5 -1
- package/src/tui/activityLayout.js +9 -0
- package/src/tui/activityLayout.ts +10 -0
- package/src/tui/chatRenderer.d.ts +2 -0
- package/src/tui/chatRenderer.js +15 -2
- package/src/tui/codeStreamRenderer.js +16 -0
- package/src/tui/codeStreamRenderer.ts +17 -0
- package/src/tui/composerControls.js +65 -0
- package/src/tui/composerControls.ts +106 -0
- package/src/tui/modelPicker.js +288 -69
- package/src/tui/modelPicker.ts +333 -72
- package/src/tui/prompt.js +23 -25
- package/src/tui/text.d.ts +2 -1
|
@@ -28,11 +28,32 @@ export const ANTIGRAVITY_MODEL_IDS = {
|
|
|
28
28
|
};
|
|
29
29
|
export const ANTIGRAVITY_LABEL_BY_ID = Object.fromEntries(Object.entries(ANTIGRAVITY_MODEL_IDS).map(([label, id]) => [id, label]));
|
|
30
30
|
export const ANTIGRAVITY_MODELS = Object.keys(ANTIGRAVITY_MODEL_IDS);
|
|
31
|
+
export function synthesizeAgySlug(input) {
|
|
32
|
+
const trimmed = input.trim();
|
|
33
|
+
if (!trimmed)
|
|
34
|
+
return '';
|
|
35
|
+
if (!/[\s()]/.test(trimmed)) {
|
|
36
|
+
return trimmed;
|
|
37
|
+
}
|
|
38
|
+
let slug = trimmed
|
|
39
|
+
.toLowerCase()
|
|
40
|
+
.replace(/\(([^()]+)\)/g, ' $1 ')
|
|
41
|
+
.replace(/[^a-z0-9.]+/g, '-')
|
|
42
|
+
.replace(/^-+|-+$/g, '')
|
|
43
|
+
.replace(/-{2,}/g, '-');
|
|
44
|
+
if (slug.startsWith('claude-')) {
|
|
45
|
+
slug = slug.replace(/\./g, '-');
|
|
46
|
+
}
|
|
47
|
+
return slug;
|
|
48
|
+
}
|
|
31
49
|
export function registerAntigravityModel(slug, label) {
|
|
32
50
|
if (!slug || typeof slug !== 'string')
|
|
33
51
|
return;
|
|
34
|
-
const
|
|
35
|
-
const cleanLabel = (label && typeof label === 'string' && label.trim()) ||
|
|
52
|
+
const rawSlug = slug.trim();
|
|
53
|
+
const cleanLabel = (label && typeof label === 'string' && label.trim()) || rawSlug;
|
|
54
|
+
const cleanSlug = /[\s()]/.test(rawSlug)
|
|
55
|
+
? (ANTIGRAVITY_MODEL_IDS[rawSlug] || synthesizeAgySlug(rawSlug))
|
|
56
|
+
: rawSlug;
|
|
36
57
|
ANTIGRAVITY_MODEL_IDS[cleanLabel] = cleanSlug;
|
|
37
58
|
ANTIGRAVITY_MODEL_IDS[cleanSlug] = cleanSlug;
|
|
38
59
|
ANTIGRAVITY_LABEL_BY_ID[cleanSlug] = cleanLabel;
|
|
@@ -40,7 +61,40 @@ export function registerAntigravityModel(slug, label) {
|
|
|
40
61
|
ANTIGRAVITY_MODELS.push(cleanLabel);
|
|
41
62
|
}
|
|
42
63
|
}
|
|
43
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Authoritatively replace the active Antigravity model list with the live
|
|
66
|
+
* models returned by the user's current Antigravity account/tier, while
|
|
67
|
+
* preserving slug lookup mappings in ANTIGRAVITY_MODEL_IDS.
|
|
68
|
+
*/
|
|
69
|
+
export function replaceAntigravityModels(items) {
|
|
70
|
+
const nextLabels = [];
|
|
71
|
+
for (const item of items) {
|
|
72
|
+
if (typeof item === 'string') {
|
|
73
|
+
const trimmed = item.trim();
|
|
74
|
+
if (!trimmed)
|
|
75
|
+
continue;
|
|
76
|
+
const existingSlug = ANTIGRAVITY_MODEL_IDS[trimmed] || synthesizeAgySlug(trimmed);
|
|
77
|
+
const label = ANTIGRAVITY_LABEL_BY_ID[trimmed] || trimmed;
|
|
78
|
+
registerAntigravityModel(existingSlug, label);
|
|
79
|
+
if (!nextLabels.includes(label))
|
|
80
|
+
nextLabels.push(label);
|
|
81
|
+
}
|
|
82
|
+
else if (item && typeof item === 'object' && typeof item.id === 'string') {
|
|
83
|
+
const id = item.id.trim();
|
|
84
|
+
if (!id)
|
|
85
|
+
continue;
|
|
86
|
+
const label = (item.label && item.label.trim()) || ANTIGRAVITY_LABEL_BY_ID[id] || id;
|
|
87
|
+
registerAntigravityModel(id, label);
|
|
88
|
+
if (!nextLabels.includes(label))
|
|
89
|
+
nextLabels.push(label);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (nextLabels.length > 0) {
|
|
93
|
+
ANTIGRAVITY_MODELS.splice(0, ANTIGRAVITY_MODELS.length, ...nextLabels);
|
|
94
|
+
}
|
|
95
|
+
return [...ANTIGRAVITY_MODELS];
|
|
96
|
+
}
|
|
97
|
+
export function parseAgyModelsOutput(stdout, options = {}) {
|
|
44
98
|
const result = [];
|
|
45
99
|
if (!stdout || typeof stdout !== 'string')
|
|
46
100
|
return result;
|
|
@@ -49,7 +103,7 @@ export function parseAgyModelsOutput(stdout) {
|
|
|
49
103
|
const line = rawLine.replace(/\u001b\[[0-9;]*[A-Za-z]/g, '').trim();
|
|
50
104
|
if (!line)
|
|
51
105
|
continue;
|
|
52
|
-
if (/^(fetching|loading|no models|error)/i.test(line))
|
|
106
|
+
if (/^(fetching|loading|no models|error|warning|usage|available)/i.test(line))
|
|
53
107
|
continue;
|
|
54
108
|
if (line.endsWith('…') || line.endsWith('...'))
|
|
55
109
|
continue;
|
|
@@ -58,28 +112,59 @@ export function parseAgyModelsOutput(stdout) {
|
|
|
58
112
|
if (!match)
|
|
59
113
|
continue;
|
|
60
114
|
const id = match[1].trim();
|
|
61
|
-
const label = (match[2] && match[2].trim()) || id;
|
|
115
|
+
const label = ((match[2] && match[2].trim()) || id).replace(/\s+\(default\)$/i, '').trim();
|
|
62
116
|
result.push({ id, label });
|
|
63
117
|
registerAntigravityModel(id, label);
|
|
64
118
|
}
|
|
119
|
+
if (options.replaceActiveList && result.length > 0) {
|
|
120
|
+
replaceAntigravityModels(result);
|
|
121
|
+
}
|
|
65
122
|
return result;
|
|
66
123
|
}
|
|
67
|
-
function
|
|
124
|
+
export function isAntigravityOnboarded() {
|
|
68
125
|
try {
|
|
69
126
|
const home = process.env.HOME || process.env.USERPROFILE || '';
|
|
70
|
-
|
|
127
|
+
if (!home)
|
|
128
|
+
return false;
|
|
129
|
+
const onboardingFile = path.join(home, '.gemini', 'antigravity-cli', 'cache', 'onboarding.json');
|
|
130
|
+
if (fs.existsSync(onboardingFile)) {
|
|
131
|
+
const parsed = JSON.parse(fs.readFileSync(onboardingFile, 'utf8'));
|
|
132
|
+
if (parsed && parsed.onboardingComplete === true)
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
const oauthFile = path.join(home, '.gemini', 'oauth_creds.json');
|
|
136
|
+
if (fs.existsSync(oauthFile))
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
// ignore read errors
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
function hydrateModelsFromDiskCache() {
|
|
145
|
+
try {
|
|
146
|
+
const causyneDir = process.env.CAUSYNE_HOME
|
|
147
|
+
|| path.join(process.env.HOME || process.env.USERPROFILE || '', '.causyne');
|
|
148
|
+
const cacheFile = path.join(causyneDir, 'models_cache.json');
|
|
71
149
|
if (!fs.existsSync(cacheFile))
|
|
72
150
|
return;
|
|
73
151
|
const content = fs.readFileSync(cacheFile, 'utf8');
|
|
74
152
|
const parsed = JSON.parse(content);
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
153
|
+
const agyEntry = parsed?.providers?.antigravity;
|
|
154
|
+
if (agyEntry?.modelIdMap && typeof agyEntry.modelIdMap === 'object') {
|
|
155
|
+
for (const [label, slug] of Object.entries(agyEntry.modelIdMap)) {
|
|
156
|
+
if (typeof slug === 'string' && slug.trim()) {
|
|
157
|
+
registerAntigravityModel(slug.trim(), label);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const agyModels = agyEntry?.models;
|
|
162
|
+
if (Array.isArray(agyModels) && agyModels.length > 0) {
|
|
77
163
|
for (const item of agyModels) {
|
|
78
164
|
if (typeof item === 'string' && item.trim()) {
|
|
79
165
|
const trimmed = item.trim();
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
166
|
+
const slug = ANTIGRAVITY_MODEL_IDS[trimmed] || synthesizeAgySlug(trimmed);
|
|
167
|
+
registerAntigravityModel(slug, trimmed);
|
|
83
168
|
}
|
|
84
169
|
}
|
|
85
170
|
}
|
|
@@ -116,6 +201,9 @@ export function resolveAgyModelId(model) {
|
|
|
116
201
|
return slug;
|
|
117
202
|
}
|
|
118
203
|
}
|
|
204
|
+
if (/[\s()]/.test(trimmed)) {
|
|
205
|
+
return synthesizeAgySlug(trimmed);
|
|
206
|
+
}
|
|
119
207
|
return trimmed;
|
|
120
208
|
}
|
|
121
209
|
export function resolveAgyEffort(model) {
|
|
@@ -399,12 +487,16 @@ export function mapNativeToolToCausyne(name, rawParams, index) {
|
|
|
399
487
|
}
|
|
400
488
|
export class AntigravityProvider extends LLMProvider {
|
|
401
489
|
command;
|
|
490
|
+
printTimeout;
|
|
402
491
|
currentConversationId = null;
|
|
403
492
|
lastTaskId = null;
|
|
404
493
|
constructor(config = {}) {
|
|
405
494
|
super(config);
|
|
406
495
|
this.model = config.model || 'Gemini 3.8 Flash (Low)';
|
|
407
496
|
this.command = config.command || resolveAgyBinary();
|
|
497
|
+
this.printTimeout = typeof config.printTimeout === 'string' && config.printTimeout.trim()
|
|
498
|
+
? config.printTimeout.trim()
|
|
499
|
+
: '1800s';
|
|
408
500
|
this.visionModels = ['*'];
|
|
409
501
|
this.audioModels = [];
|
|
410
502
|
}
|
|
@@ -639,10 +731,10 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
639
731
|
msg.includes('status 429');
|
|
640
732
|
}
|
|
641
733
|
async _executeOnce(messages, options = {}) {
|
|
642
|
-
const
|
|
643
|
-
if (
|
|
734
|
+
const currentSessionKey = options.conversationId || options.taskId || null;
|
|
735
|
+
if (currentSessionKey && currentSessionKey !== this.lastTaskId) {
|
|
644
736
|
this.currentConversationId = null;
|
|
645
|
-
this.lastTaskId =
|
|
737
|
+
this.lastTaskId = currentSessionKey;
|
|
646
738
|
}
|
|
647
739
|
if (messages.length <= 1) {
|
|
648
740
|
this.currentConversationId = null;
|
|
@@ -700,7 +792,7 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
700
792
|
'stream-json',
|
|
701
793
|
'--disable-slash-commands',
|
|
702
794
|
'--print-timeout',
|
|
703
|
-
launchOnly ? '90s' :
|
|
795
|
+
launchOnly ? '90s' : this.printTimeout,
|
|
704
796
|
'--model',
|
|
705
797
|
modelSlug,
|
|
706
798
|
'--effort',
|
|
@@ -721,6 +813,7 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
721
813
|
let stderrBuffer = '';
|
|
722
814
|
let streamedResponse = '';
|
|
723
815
|
let finalResultObj = null;
|
|
816
|
+
let sawToolAfterLastText = false;
|
|
724
817
|
const nativeActions = [];
|
|
725
818
|
const attemptedNativeTools = [];
|
|
726
819
|
let childClosed = false;
|
|
@@ -754,7 +847,9 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
754
847
|
catch {
|
|
755
848
|
// ignore kill errors
|
|
756
849
|
}
|
|
757
|
-
|
|
850
|
+
const abortErr = new Error('Turn aborted by user or timeout.');
|
|
851
|
+
abortErr.name = 'AbortError';
|
|
852
|
+
safeReject(abortErr);
|
|
758
853
|
};
|
|
759
854
|
if (options.signal) {
|
|
760
855
|
if (options.signal.aborted) {
|
|
@@ -826,6 +921,7 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
826
921
|
}
|
|
827
922
|
}
|
|
828
923
|
if (name && (state === 'ACTIVE' || state === 'DONE' || state === 'ERROR')) {
|
|
924
|
+
sawToolAfterLastText = true;
|
|
829
925
|
const detail = describeNativeAction(toolInfo) || describeNativeAction({ parameters: rawParams });
|
|
830
926
|
const action = {
|
|
831
927
|
name,
|
|
@@ -856,6 +952,15 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
856
952
|
}
|
|
857
953
|
}
|
|
858
954
|
else {
|
|
955
|
+
if (sawToolAfterLastText && streamedResponse.length > 0 && !/\s$/.test(streamedResponse) && !/^\s/.test(delta)) {
|
|
956
|
+
streamedResponse += '\n';
|
|
957
|
+
if (typeof options.onChunk === 'function') {
|
|
958
|
+
options.onChunk('\n');
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
if (delta.trim().length > 0) {
|
|
962
|
+
sawToolAfterLastText = false;
|
|
963
|
+
}
|
|
859
964
|
streamedResponse += delta;
|
|
860
965
|
if (typeof options.onChunk === 'function') {
|
|
861
966
|
options.onChunk(delta);
|
|
@@ -987,6 +1092,10 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
987
1092
|
: 'Antigravity returned no response.'));
|
|
988
1093
|
return;
|
|
989
1094
|
}
|
|
1095
|
+
const timedOutMidTurn = /print timeout after .* with turn in progress|returning partial output/i.test(stderrBuffer);
|
|
1096
|
+
const finalResponseText = typeof finalResultObj?.response === 'string' ? finalResultObj.response.trim() : '';
|
|
1097
|
+
const endedAfterToolWithoutFinalResponse = sawToolAfterLastText && !finalResponseText && deniedActions.length === 0 && toolCalls.length === 0;
|
|
1098
|
+
const missingResultEvent = finalResultObj === null && deniedActions.length === 0 && toolCalls.length === 0;
|
|
990
1099
|
const promptTokens = Number(finalResultObj?.usage?.input_tokens) || Math.ceil(promptText.length / 4);
|
|
991
1100
|
const completionTokens = Number(finalResultObj?.usage?.output_tokens) || Math.ceil(rawContent.length / 4);
|
|
992
1101
|
const thinkingTokens = Number(finalResultObj?.usage?.thinking_tokens) || 0;
|
|
@@ -1007,6 +1116,9 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
1007
1116
|
if (nativeActions.length > 0) {
|
|
1008
1117
|
response.externalActions = nativeActions.filter((a) => a.status !== 'running');
|
|
1009
1118
|
}
|
|
1119
|
+
if (timedOutMidTurn || endedAfterToolWithoutFinalResponse || missingResultEvent) {
|
|
1120
|
+
response.incompleteTurn = true;
|
|
1121
|
+
}
|
|
1010
1122
|
safeResolve(response);
|
|
1011
1123
|
});
|
|
1012
1124
|
});
|
|
@@ -1015,11 +1127,16 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
1015
1127
|
const maxRetries = options.maxRetries ?? (options.taskIntent === 'launch' ? 1 : 2);
|
|
1016
1128
|
let attempt = 0;
|
|
1017
1129
|
while (attempt <= maxRetries) {
|
|
1130
|
+
const hadConversation = Boolean(this.currentConversationId);
|
|
1018
1131
|
try {
|
|
1019
1132
|
return await this._executeOnce(messages, options);
|
|
1020
1133
|
}
|
|
1021
1134
|
catch (err) {
|
|
1022
|
-
if (
|
|
1135
|
+
if (options.signal?.aborted || err?.name === 'AbortError') {
|
|
1136
|
+
throw err;
|
|
1137
|
+
}
|
|
1138
|
+
const canRetryResetConversation = hadConversation && !this.currentConversationId && err?.code !== 'AGY_NATIVE_ACTION_DENIED';
|
|
1139
|
+
if (attempt < maxRetries && (this._isTransientError(err.message) || canRetryResetConversation)) {
|
|
1023
1140
|
attempt++;
|
|
1024
1141
|
const delay = attempt * 1200;
|
|
1025
1142
|
await new Promise(r => setTimeout(r, delay));
|
|
@@ -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
|
|
|
@@ -417,6 +504,7 @@ export function mapNativeToolToCausyne(
|
|
|
417
504
|
|
|
418
505
|
export class AntigravityProvider extends LLMProvider {
|
|
419
506
|
command: string;
|
|
507
|
+
printTimeout: string;
|
|
420
508
|
currentConversationId: string | null = null;
|
|
421
509
|
lastTaskId: string | null = null;
|
|
422
510
|
|
|
@@ -424,6 +512,9 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
424
512
|
super(config);
|
|
425
513
|
this.model = config.model || 'Gemini 3.8 Flash (Low)';
|
|
426
514
|
this.command = config.command || resolveAgyBinary();
|
|
515
|
+
this.printTimeout = typeof config.printTimeout === 'string' && config.printTimeout.trim()
|
|
516
|
+
? config.printTimeout.trim()
|
|
517
|
+
: '1800s';
|
|
427
518
|
this.visionModels = ['*'];
|
|
428
519
|
this.audioModels = [];
|
|
429
520
|
}
|
|
@@ -669,10 +760,10 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
669
760
|
}
|
|
670
761
|
|
|
671
762
|
async _executeOnce(messages: any[], options: ChatOptions = {}): Promise<ChatResponse> {
|
|
672
|
-
const
|
|
673
|
-
if (
|
|
763
|
+
const currentSessionKey = (options as any).conversationId || (options as any).taskId || null;
|
|
764
|
+
if (currentSessionKey && currentSessionKey !== this.lastTaskId) {
|
|
674
765
|
this.currentConversationId = null;
|
|
675
|
-
this.lastTaskId =
|
|
766
|
+
this.lastTaskId = currentSessionKey;
|
|
676
767
|
}
|
|
677
768
|
if (messages.length <= 1) {
|
|
678
769
|
this.currentConversationId = null;
|
|
@@ -734,7 +825,7 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
734
825
|
'stream-json',
|
|
735
826
|
'--disable-slash-commands',
|
|
736
827
|
'--print-timeout',
|
|
737
|
-
launchOnly ? '90s' :
|
|
828
|
+
launchOnly ? '90s' : this.printTimeout,
|
|
738
829
|
'--model',
|
|
739
830
|
modelSlug,
|
|
740
831
|
'--effort',
|
|
@@ -758,6 +849,7 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
758
849
|
let stderrBuffer = '';
|
|
759
850
|
let streamedResponse = '';
|
|
760
851
|
let finalResultObj: any = null;
|
|
852
|
+
let sawToolAfterLastText = false;
|
|
761
853
|
const nativeActions: ChatResponseAction[] = [];
|
|
762
854
|
const attemptedNativeTools: {
|
|
763
855
|
name: string;
|
|
@@ -797,7 +889,9 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
797
889
|
} catch {
|
|
798
890
|
// ignore kill errors
|
|
799
891
|
}
|
|
800
|
-
|
|
892
|
+
const abortErr = new Error('Turn aborted by user or timeout.');
|
|
893
|
+
abortErr.name = 'AbortError';
|
|
894
|
+
safeReject(abortErr);
|
|
801
895
|
};
|
|
802
896
|
|
|
803
897
|
if (options.signal) {
|
|
@@ -871,6 +965,7 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
871
965
|
}
|
|
872
966
|
|
|
873
967
|
if (name && (state === 'ACTIVE' || state === 'DONE' || state === 'ERROR')) {
|
|
968
|
+
sawToolAfterLastText = true;
|
|
874
969
|
const detail = describeNativeAction(toolInfo) || describeNativeAction({ parameters: rawParams });
|
|
875
970
|
const action: ChatResponseAction = {
|
|
876
971
|
name,
|
|
@@ -898,6 +993,15 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
898
993
|
options.onReasoningChunk(delta);
|
|
899
994
|
}
|
|
900
995
|
} else {
|
|
996
|
+
if (sawToolAfterLastText && streamedResponse.length > 0 && !/\s$/.test(streamedResponse) && !/^\s/.test(delta)) {
|
|
997
|
+
streamedResponse += '\n';
|
|
998
|
+
if (typeof options.onChunk === 'function') {
|
|
999
|
+
options.onChunk('\n');
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
if (delta.trim().length > 0) {
|
|
1003
|
+
sawToolAfterLastText = false;
|
|
1004
|
+
}
|
|
901
1005
|
streamedResponse += delta;
|
|
902
1006
|
if (typeof options.onChunk === 'function') {
|
|
903
1007
|
options.onChunk(delta);
|
|
@@ -1037,6 +1141,13 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
1037
1141
|
return;
|
|
1038
1142
|
}
|
|
1039
1143
|
|
|
1144
|
+
const timedOutMidTurn = /print timeout after .* with turn in progress|returning partial output/i.test(stderrBuffer);
|
|
1145
|
+
const finalResponseText = typeof finalResultObj?.response === 'string' ? finalResultObj.response.trim() : '';
|
|
1146
|
+
const endedAfterToolWithoutFinalResponse =
|
|
1147
|
+
sawToolAfterLastText && !finalResponseText && deniedActions.length === 0 && toolCalls.length === 0;
|
|
1148
|
+
const missingResultEvent =
|
|
1149
|
+
finalResultObj === null && deniedActions.length === 0 && toolCalls.length === 0;
|
|
1150
|
+
|
|
1040
1151
|
const promptTokens = Number(finalResultObj?.usage?.input_tokens) || Math.ceil(promptText.length / 4);
|
|
1041
1152
|
const completionTokens = Number(finalResultObj?.usage?.output_tokens) || Math.ceil(rawContent.length / 4);
|
|
1042
1153
|
const thinkingTokens = Number(finalResultObj?.usage?.thinking_tokens) || 0;
|
|
@@ -1062,6 +1173,10 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
1062
1173
|
response.externalActions = nativeActions.filter((a: ChatResponseAction) => a.status !== 'running');
|
|
1063
1174
|
}
|
|
1064
1175
|
|
|
1176
|
+
if (timedOutMidTurn || endedAfterToolWithoutFinalResponse || missingResultEvent) {
|
|
1177
|
+
response.incompleteTurn = true;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1065
1180
|
safeResolve(response);
|
|
1066
1181
|
});
|
|
1067
1182
|
});
|
|
@@ -1071,10 +1186,16 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
1071
1186
|
const maxRetries = options.maxRetries ?? ((options as any).taskIntent === 'launch' ? 1 : 2);
|
|
1072
1187
|
let attempt = 0;
|
|
1073
1188
|
while (attempt <= maxRetries) {
|
|
1189
|
+
const hadConversation = Boolean(this.currentConversationId);
|
|
1074
1190
|
try {
|
|
1075
1191
|
return await this._executeOnce(messages, options);
|
|
1076
1192
|
} catch (err: any) {
|
|
1077
|
-
if (
|
|
1193
|
+
if (options.signal?.aborted || err?.name === 'AbortError') {
|
|
1194
|
+
throw err;
|
|
1195
|
+
}
|
|
1196
|
+
const canRetryResetConversation =
|
|
1197
|
+
hadConversation && !this.currentConversationId && (err as any)?.code !== 'AGY_NATIVE_ACTION_DENIED';
|
|
1198
|
+
if (attempt < maxRetries && (this._isTransientError(err.message) || canRetryResetConversation)) {
|
|
1078
1199
|
attempt++;
|
|
1079
1200
|
const delay = attempt * 1200;
|
|
1080
1201
|
await new Promise(r => setTimeout(r, delay));
|
package/src/providers/base.d.ts
CHANGED
package/src/providers/pi.js
CHANGED
|
@@ -70,7 +70,11 @@ export class PiProvider extends LLMProvider {
|
|
|
70
70
|
toolCalls: this.formatter.extractToolCalls(raw)
|
|
71
71
|
});
|
|
72
72
|
};
|
|
73
|
-
const abort = () =>
|
|
73
|
+
const abort = () => {
|
|
74
|
+
const err = new Error('Pi request aborted');
|
|
75
|
+
err.name = 'AbortError';
|
|
76
|
+
fail(err);
|
|
77
|
+
};
|
|
74
78
|
if (options.signal?.aborted) {
|
|
75
79
|
abort();
|
|
76
80
|
return;
|
package/src/providers/pi.ts
CHANGED
|
@@ -73,7 +73,11 @@ export class PiProvider extends LLMProvider {
|
|
|
73
73
|
toolCalls: this.formatter.extractToolCalls(raw)
|
|
74
74
|
});
|
|
75
75
|
};
|
|
76
|
-
const abort = (): void =>
|
|
76
|
+
const abort = (): void => {
|
|
77
|
+
const err = new Error('Pi request aborted');
|
|
78
|
+
err.name = 'AbortError';
|
|
79
|
+
fail(err);
|
|
80
|
+
};
|
|
77
81
|
if (options.signal?.aborted) { abort(); return; }
|
|
78
82
|
options.signal?.addEventListener('abort', abort, { once: true });
|
|
79
83
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { safeDisplay, visibleWidth, wrapBlock } from './text.js';
|
|
2
|
+
/** Render provider activity inside the conversation column, including multiline commands. */
|
|
3
|
+
export function activityRows(message, columns, prefix = '▸ ') {
|
|
4
|
+
const width = Number.isFinite(columns) ? Math.max(20, Math.floor(columns)) : 80;
|
|
5
|
+
const inset = visibleWidth(prefix);
|
|
6
|
+
const bodyWidth = Math.max(1, width - inset - 1);
|
|
7
|
+
const lines = wrapBlock(safeDisplay(message).trim(), bodyWidth, { hang: 2 });
|
|
8
|
+
return lines.map((line, index) => `${index === 0 ? prefix : ' '.repeat(inset)}${line}`);
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { safeDisplay, visibleWidth, wrapBlock } from './text.js';
|
|
2
|
+
|
|
3
|
+
/** Render provider activity inside the conversation column, including multiline commands. */
|
|
4
|
+
export function activityRows(message: string, columns: number, prefix = '▸ '): string[] {
|
|
5
|
+
const width = Number.isFinite(columns) ? Math.max(20, Math.floor(columns)) : 80;
|
|
6
|
+
const inset = visibleWidth(prefix);
|
|
7
|
+
const bodyWidth = Math.max(1, width - inset - 1);
|
|
8
|
+
const lines = wrapBlock(safeDisplay(message).trim(), bodyWidth, { hang: 2 });
|
|
9
|
+
return lines.map((line, index) => `${index === 0 ? prefix : ' '.repeat(inset)}${line}`);
|
|
10
|
+
}
|
|
@@ -10,8 +10,10 @@ export interface ChatTranscript {
|
|
|
10
10
|
export class ChatRenderer {
|
|
11
11
|
constructor(options?: Record<string, unknown>);
|
|
12
12
|
transcript: ChatTranscript | null;
|
|
13
|
+
stepCount: number;
|
|
13
14
|
_activeReasoning?: boolean;
|
|
14
15
|
handle(message: { type: string; [key: string]: unknown }): boolean;
|
|
16
|
+
resetTurn(): void;
|
|
15
17
|
onAgentReasoning(message: { content?: string; streaming?: boolean; elapsedMs?: number }): void;
|
|
16
18
|
stopSpinner(): void;
|
|
17
19
|
frame(kind: string, produce: () => void, meta?: Record<string, unknown> | null): void;
|