@causyne/agent 1.20.8 → 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/agentLoop.js +167 -34
- package/src/agentLoop.ts +188 -37
- 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/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 +4 -2
- package/src/providers/acp.ts +4 -2
- package/src/providers/antigravity.js +122 -22
- package/src/providers/antigravity.ts +121 -21
- 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
|
@@ -6,18 +6,6 @@
|
|
|
6
6
|
* Enforces authentic human cadence, strict hyphenation rules, and zero ungrounded placeholders.
|
|
7
7
|
*/
|
|
8
8
|
const BANNED_LONG_DASHES = /[—–]/g;
|
|
9
|
-
const AI_SLOP_CLICHES_ID = [
|
|
10
|
-
/\bsangatlah\b/i,
|
|
11
|
-
/\btak terbantahkan\b/i,
|
|
12
|
-
/\brevolusioner\b/i,
|
|
13
|
-
/\bgame[- ]?changer\b/i,
|
|
14
|
-
/\bdi era yang serba\b/i,
|
|
15
|
-
/\bmari kita\b/i,
|
|
16
|
-
/\btidak dapat dipungkiri\b/i,
|
|
17
|
-
/\bperlu diingat bahwa\b/i,
|
|
18
|
-
/\bdalam lanskap modern\b/i,
|
|
19
|
-
/\bmerupakan sebuah bukti nyata\b/i
|
|
20
|
-
];
|
|
21
9
|
const AI_SLOP_CLICHES_EN = [
|
|
22
10
|
/\bdelve(?:s|d|ing)?\b/i,
|
|
23
11
|
/\bcrucial(?:ly)?\b/i,
|
|
@@ -36,8 +24,8 @@ const AI_SLOP_CLICHES_EN = [
|
|
|
36
24
|
/\bholistic approach\b/i
|
|
37
25
|
];
|
|
38
26
|
const PLACEHOLDER_BRACKETS = [
|
|
39
|
-
/\[(?:insert|
|
|
40
|
-
/<(?:insert|
|
|
27
|
+
/\[(?:insert|placeholder|tbd|todo|name|date|location)[^\]]*\]/i,
|
|
28
|
+
/<(?:insert|placeholder|tbd|todo)[^>]*>/i
|
|
41
29
|
];
|
|
42
30
|
/**
|
|
43
31
|
* Scan raw text or HTML content for AI slop, long em-dashes, and placeholder tokens.
|
|
@@ -45,7 +33,6 @@ const PLACEHOLDER_BRACKETS = [
|
|
|
45
33
|
export function auditTextContent(content, options = {}) {
|
|
46
34
|
const findings = [];
|
|
47
35
|
const lines = (content || '').split(/\r?\n/);
|
|
48
|
-
const lang = options.language || 'both';
|
|
49
36
|
const strictDashes = options.strictDashes !== false;
|
|
50
37
|
lines.forEach((line, idx) => {
|
|
51
38
|
const lineNum = idx + 1;
|
|
@@ -75,34 +62,17 @@ export function auditTextContent(content, options = {}) {
|
|
|
75
62
|
});
|
|
76
63
|
}
|
|
77
64
|
}
|
|
78
|
-
// 3. AI Slop Cliches (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
// 4. AI Slop Cliches (EN)
|
|
94
|
-
if (lang === 'en' || lang === 'both') {
|
|
95
|
-
for (const pat of AI_SLOP_CLICHES_EN) {
|
|
96
|
-
const m = line.match(pat);
|
|
97
|
-
if (m) {
|
|
98
|
-
findings.push({
|
|
99
|
-
rule: 'anti_ai_slop_phrase_en',
|
|
100
|
-
severity: 'warning',
|
|
101
|
-
match: m[0],
|
|
102
|
-
line: lineNum,
|
|
103
|
-
message: `Found generic AI trope "${m[0]}". Replace with concrete, factual language.`
|
|
104
|
-
});
|
|
105
|
-
}
|
|
65
|
+
// 3. AI Slop Cliches (EN)
|
|
66
|
+
for (const pat of AI_SLOP_CLICHES_EN) {
|
|
67
|
+
const m = line.match(pat);
|
|
68
|
+
if (m) {
|
|
69
|
+
findings.push({
|
|
70
|
+
rule: 'anti_ai_slop_phrase_en',
|
|
71
|
+
severity: 'warning',
|
|
72
|
+
match: m[0],
|
|
73
|
+
line: lineNum,
|
|
74
|
+
message: `Found generic AI trope "${m[0]}". Replace with concrete, factual language.`
|
|
75
|
+
});
|
|
106
76
|
}
|
|
107
77
|
}
|
|
108
78
|
});
|
|
@@ -31,25 +31,12 @@ export interface ArithmeticCategory {
|
|
|
31
31
|
|
|
32
32
|
export interface ArithmeticBudgetSpec {
|
|
33
33
|
categories: ArithmeticCategory[];
|
|
34
|
-
grossUpTaxRate?: number; // e.g. 0.025 for 2.5%
|
|
34
|
+
grossUpTaxRate?: number; // e.g. 0.025 for 2.5% withholding tax
|
|
35
35
|
targetGross?: number;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
const BANNED_LONG_DASHES = /[—–]/g;
|
|
39
39
|
|
|
40
|
-
const AI_SLOP_CLICHES_ID = [
|
|
41
|
-
/\bsangatlah\b/i,
|
|
42
|
-
/\btak terbantahkan\b/i,
|
|
43
|
-
/\brevolusioner\b/i,
|
|
44
|
-
/\bgame[- ]?changer\b/i,
|
|
45
|
-
/\bdi era yang serba\b/i,
|
|
46
|
-
/\bmari kita\b/i,
|
|
47
|
-
/\btidak dapat dipungkiri\b/i,
|
|
48
|
-
/\bperlu diingat bahwa\b/i,
|
|
49
|
-
/\bdalam lanskap modern\b/i,
|
|
50
|
-
/\bmerupakan sebuah bukti nyata\b/i
|
|
51
|
-
];
|
|
52
|
-
|
|
53
40
|
const AI_SLOP_CLICHES_EN = [
|
|
54
41
|
/\bdelve(?:s|d|ing)?\b/i,
|
|
55
42
|
/\bcrucial(?:ly)?\b/i,
|
|
@@ -69,20 +56,19 @@ const AI_SLOP_CLICHES_EN = [
|
|
|
69
56
|
];
|
|
70
57
|
|
|
71
58
|
const PLACEHOLDER_BRACKETS = [
|
|
72
|
-
/\[(?:insert|
|
|
73
|
-
/<(?:insert|
|
|
59
|
+
/\[(?:insert|placeholder|tbd|todo|name|date|location)[^\]]*\]/i,
|
|
60
|
+
/<(?:insert|placeholder|tbd|todo)[^>]*>/i
|
|
74
61
|
];
|
|
75
62
|
|
|
76
63
|
/**
|
|
77
64
|
* Scan raw text or HTML content for AI slop, long em-dashes, and placeholder tokens.
|
|
78
65
|
*/
|
|
79
|
-
export function auditTextContent(content: string, options: {
|
|
66
|
+
export function auditTextContent(content: string, options: { strictDashes?: boolean } = {}): {
|
|
80
67
|
clean: boolean;
|
|
81
68
|
findings: SlopAuditFinding[];
|
|
82
69
|
} {
|
|
83
70
|
const findings: SlopAuditFinding[] = [];
|
|
84
71
|
const lines = (content || '').split(/\r?\n/);
|
|
85
|
-
const lang = options.language || 'both';
|
|
86
72
|
const strictDashes = options.strictDashes !== false;
|
|
87
73
|
|
|
88
74
|
lines.forEach((line, idx) => {
|
|
@@ -116,35 +102,17 @@ export function auditTextContent(content: string, options: { language?: 'id' | '
|
|
|
116
102
|
}
|
|
117
103
|
}
|
|
118
104
|
|
|
119
|
-
// 3. AI Slop Cliches (
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// 4. AI Slop Cliches (EN)
|
|
136
|
-
if (lang === 'en' || lang === 'both') {
|
|
137
|
-
for (const pat of AI_SLOP_CLICHES_EN) {
|
|
138
|
-
const m = line.match(pat);
|
|
139
|
-
if (m) {
|
|
140
|
-
findings.push({
|
|
141
|
-
rule: 'anti_ai_slop_phrase_en',
|
|
142
|
-
severity: 'warning',
|
|
143
|
-
match: m[0],
|
|
144
|
-
line: lineNum,
|
|
145
|
-
message: `Found generic AI trope "${m[0]}". Replace with concrete, factual language.`
|
|
146
|
-
});
|
|
147
|
-
}
|
|
105
|
+
// 3. AI Slop Cliches (EN)
|
|
106
|
+
for (const pat of AI_SLOP_CLICHES_EN) {
|
|
107
|
+
const m = line.match(pat);
|
|
108
|
+
if (m) {
|
|
109
|
+
findings.push({
|
|
110
|
+
rule: 'anti_ai_slop_phrase_en',
|
|
111
|
+
severity: 'warning',
|
|
112
|
+
match: m[0],
|
|
113
|
+
line: lineNum,
|
|
114
|
+
message: `Found generic AI trope "${m[0]}". Replace with concrete, factual language.`
|
|
115
|
+
});
|
|
148
116
|
}
|
|
149
117
|
}
|
|
150
118
|
});
|
|
@@ -53,7 +53,7 @@ export function compileDocumentHtml(spec) {
|
|
|
53
53
|
size: A4 portrait;
|
|
54
54
|
margin: 20mm 18mm 18mm 18mm;
|
|
55
55
|
@bottom-right {
|
|
56
|
-
content: "
|
|
56
|
+
content: "Page " counter(page);
|
|
57
57
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
58
58
|
font-size: 8.5pt;
|
|
59
59
|
color: #64748b;
|
|
@@ -213,7 +213,7 @@ tr:nth-child(even) td {
|
|
|
213
213
|
<div class="cover-content">
|
|
214
214
|
<div class="cover-title">${escapeHtml(spec.title)}</div>
|
|
215
215
|
${spec.subtitle ? `<div class="cover-subtitle">${escapeHtml(spec.subtitle)}</div>` : ''}
|
|
216
|
-
${spec.authorOrProposer ? `<div class="cover-meta">
|
|
216
|
+
${spec.authorOrProposer ? `<div class="cover-meta">Prepared by: <strong>${escapeHtml(spec.authorOrProposer)}</strong></div>` : ''}
|
|
217
217
|
</div>
|
|
218
218
|
<div class="cover-band-bottom"></div>
|
|
219
219
|
</div>`;
|
|
@@ -251,7 +251,7 @@ tr:nth-child(even) td {
|
|
|
251
251
|
}
|
|
252
252
|
bodyHtml += '\n</div>';
|
|
253
253
|
const html = `<!DOCTYPE html>
|
|
254
|
-
<html lang="
|
|
254
|
+
<html lang="en">
|
|
255
255
|
<head>
|
|
256
256
|
<meta charset="UTF-8">
|
|
257
257
|
<title>${escapeHtml(spec.title)}</title>
|
|
@@ -104,7 +104,7 @@ export function compileDocumentHtml(spec: FormalDocumentSpec): { html: string; c
|
|
|
104
104
|
size: A4 portrait;
|
|
105
105
|
margin: 20mm 18mm 18mm 18mm;
|
|
106
106
|
@bottom-right {
|
|
107
|
-
content: "
|
|
107
|
+
content: "Page " counter(page);
|
|
108
108
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
109
109
|
font-size: 8.5pt;
|
|
110
110
|
color: #64748b;
|
|
@@ -266,7 +266,7 @@ tr:nth-child(even) td {
|
|
|
266
266
|
<div class="cover-content">
|
|
267
267
|
<div class="cover-title">${escapeHtml(spec.title)}</div>
|
|
268
268
|
${spec.subtitle ? `<div class="cover-subtitle">${escapeHtml(spec.subtitle)}</div>` : ''}
|
|
269
|
-
${spec.authorOrProposer ? `<div class="cover-meta">
|
|
269
|
+
${spec.authorOrProposer ? `<div class="cover-meta">Prepared by: <strong>${escapeHtml(spec.authorOrProposer)}</strong></div>` : ''}
|
|
270
270
|
</div>
|
|
271
271
|
<div class="cover-band-bottom"></div>
|
|
272
272
|
</div>`;
|
|
@@ -306,7 +306,7 @@ tr:nth-child(even) td {
|
|
|
306
306
|
bodyHtml += '\n</div>';
|
|
307
307
|
|
|
308
308
|
const html = `<!DOCTYPE html>
|
|
309
|
-
<html lang="
|
|
309
|
+
<html lang="en">
|
|
310
310
|
<head>
|
|
311
311
|
<meta charset="UTF-8">
|
|
312
312
|
<title>${escapeHtml(spec.title)}</title>
|
package/src/launchIntent.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const LAUNCH_VERBS = /\b(open|launch|start|run|play|serve|preview
|
|
2
|
-
const CHANGE_VERBS = /\b(create|build|make|write|edit|fix|modify|change|update|implement|generate|refactor|delete|remove|install|deploy
|
|
1
|
+
const LAUNCH_VERBS = /\b(open|launch|start|run|play|serve|preview)\b/i;
|
|
2
|
+
const CHANGE_VERBS = /\b(create|build|make|write|edit|fix|modify|change|update|implement|generate|refactor|delete|remove|install|deploy)\b/i;
|
|
3
3
|
const SERVER_COMMAND = /^\s*(?:python(?:3(?:\.\d+)?)?\s+(?:-u\s+)?(?:\S*\/)?server\.py\b|python(?:3(?:\.\d+)?)?\s+-m\s+http\.server\b|(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:dev|start|serve)\b|(?:npx|bunx)\s+(?:vite|next\s+dev|http-server)\b|uvicorn\b|gunicorn\b|flask\s+run\b)/i;
|
|
4
4
|
const READ_ONLY_COMMAND = /^\s*(?:pwd|ls|rg|grep|cat|head|tail|find|which|where|ps|pgrep|lsof|netstat|ss|git\s+(?:status|diff|log|show)|node\s+(?:-v|--version)|python(?:3(?:\.\d+)?)?\s+(?:-V|--version))\b/i;
|
|
5
5
|
const OPEN_COMMAND = /^\s*(?:open|xdg-open|start)\s+\S+/i;
|
|
@@ -11,7 +11,7 @@ const MUTATION_TOOLS = new Set([
|
|
|
11
11
|
'create_skill', 'manage_local_dependencies'
|
|
12
12
|
]);
|
|
13
13
|
export function isLaunchOnlyPrompt(prompt) {
|
|
14
|
-
if (/\
|
|
14
|
+
if (/\brun\s+(?:the\s+)?(?:tests?|checks?|lint|benchmarks?|scripts?|commands?)\b/i.test(prompt))
|
|
15
15
|
return false;
|
|
16
16
|
return LAUNCH_VERBS.test(prompt) && !CHANGE_VERBS.test(prompt);
|
|
17
17
|
}
|
package/src/launchIntent.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const LAUNCH_VERBS = /\b(open|launch|start|run|play|serve|preview
|
|
2
|
-
const CHANGE_VERBS = /\b(create|build|make|write|edit|fix|modify|change|update|implement|generate|refactor|delete|remove|install|deploy
|
|
1
|
+
const LAUNCH_VERBS = /\b(open|launch|start|run|play|serve|preview)\b/i;
|
|
2
|
+
const CHANGE_VERBS = /\b(create|build|make|write|edit|fix|modify|change|update|implement|generate|refactor|delete|remove|install|deploy)\b/i;
|
|
3
3
|
const SERVER_COMMAND = /^\s*(?:python(?:3(?:\.\d+)?)?\s+(?:-u\s+)?(?:\S*\/)?server\.py\b|python(?:3(?:\.\d+)?)?\s+-m\s+http\.server\b|(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:dev|start|serve)\b|(?:npx|bunx)\s+(?:vite|next\s+dev|http-server)\b|uvicorn\b|gunicorn\b|flask\s+run\b)/i;
|
|
4
4
|
const READ_ONLY_COMMAND = /^\s*(?:pwd|ls|rg|grep|cat|head|tail|find|which|where|ps|pgrep|lsof|netstat|ss|git\s+(?:status|diff|log|show)|node\s+(?:-v|--version)|python(?:3(?:\.\d+)?)?\s+(?:-V|--version))\b/i;
|
|
5
5
|
const OPEN_COMMAND = /^\s*(?:open|xdg-open|start)\s+\S+/i;
|
|
@@ -13,7 +13,7 @@ const MUTATION_TOOLS = new Set([
|
|
|
13
13
|
]);
|
|
14
14
|
|
|
15
15
|
export function isLaunchOnlyPrompt(prompt: string): boolean {
|
|
16
|
-
if (/\
|
|
16
|
+
if (/\brun\s+(?:the\s+)?(?:tests?|checks?|lint|benchmarks?|scripts?|commands?)\b/i.test(prompt)) return false;
|
|
17
17
|
return LAUNCH_VERBS.test(prompt) && !CHANGE_VERBS.test(prompt);
|
|
18
18
|
}
|
|
19
19
|
|
package/src/planCache.js
CHANGED
|
@@ -77,22 +77,12 @@ const STOPWORDS = new Set([
|
|
|
77
77
|
'with', 'from', 'into', 'then', 'this', 'that', 'it', 'its', 'as', 'by',
|
|
78
78
|
'please', 'just', 'now', 'my', 'me', 'you', 'your', 'i',
|
|
79
79
|
// Generic creation verbs. Every task has one, so they inflate the union
|
|
80
|
-
// without discriminating between tasks
|
|
81
|
-
// "buat pena 3D di Blender" and "bikin pulpen 3D di blender" score 0.40
|
|
82
|
-
// when they describe the same job. `build`, `fix`, `debug` and `render` are
|
|
80
|
+
// without discriminating between tasks. `build`, `fix`, `debug` and `render` are
|
|
83
81
|
// deliberately NOT here: those DO separate tasks inside one archetype.
|
|
84
|
-
'make', 'create', 'creating', 'made', 'generate'
|
|
85
|
-
// Indonesian — the owner writes in both, and a mixed-language prompt must
|
|
86
|
-
// key the same way whichever language framed it.
|
|
87
|
-
'dan', 'atau', 'yang', 'untuk', 'dari', 'ke', 'di', 'itu', 'ini', 'dengan',
|
|
88
|
-
'tolong', 'saya', 'aku', 'kamu', 'adalah', 'pada', 'juga', 'agar', 'jadi',
|
|
89
|
-
'buat', 'bikin', 'membuat', 'lalu', 'kemudian', 'terus', 'dulu', 'saja',
|
|
90
|
-
'sekarang', 'harus', 'bisa', 'sudah', 'belum', 'akan', 'mau', 'coba'
|
|
82
|
+
'make', 'create', 'creating', 'made', 'generate'
|
|
91
83
|
]);
|
|
92
|
-
// HONEST LIMIT. Matching is LEXICAL.
|
|
93
|
-
//
|
|
94
|
-
// "pen" and "pena" are the same object. That is a deliberate trade: this path
|
|
95
|
-
// is deterministic, instant, and works on a machine with no embedding model
|
|
84
|
+
// HONEST LIMIT. Matching is LEXICAL.
|
|
85
|
+
// This path is deterministic, instant, and works on a machine with no embedding model
|
|
96
86
|
// provisioned. Cortex is the semantic route and already carries embeddings;
|
|
97
87
|
// these two compose rather than compete.
|
|
98
88
|
/**
|
package/src/planCache.ts
CHANGED
|
@@ -203,23 +203,13 @@ const STOPWORDS: ReadonlySet<string> = new Set([
|
|
|
203
203
|
'with', 'from', 'into', 'then', 'this', 'that', 'it', 'its', 'as', 'by',
|
|
204
204
|
'please', 'just', 'now', 'my', 'me', 'you', 'your', 'i',
|
|
205
205
|
// Generic creation verbs. Every task has one, so they inflate the union
|
|
206
|
-
// without discriminating between tasks
|
|
207
|
-
// "buat pena 3D di Blender" and "bikin pulpen 3D di blender" score 0.40
|
|
208
|
-
// when they describe the same job. `build`, `fix`, `debug` and `render` are
|
|
206
|
+
// without discriminating between tasks. `build`, `fix`, `debug` and `render` are
|
|
209
207
|
// deliberately NOT here: those DO separate tasks inside one archetype.
|
|
210
|
-
'make', 'create', 'creating', 'made', 'generate'
|
|
211
|
-
// Indonesian — the owner writes in both, and a mixed-language prompt must
|
|
212
|
-
// key the same way whichever language framed it.
|
|
213
|
-
'dan', 'atau', 'yang', 'untuk', 'dari', 'ke', 'di', 'itu', 'ini', 'dengan',
|
|
214
|
-
'tolong', 'saya', 'aku', 'kamu', 'adalah', 'pada', 'juga', 'agar', 'jadi',
|
|
215
|
-
'buat', 'bikin', 'membuat', 'lalu', 'kemudian', 'terus', 'dulu', 'saja',
|
|
216
|
-
'sekarang', 'harus', 'bisa', 'sudah', 'belum', 'akan', 'mau', 'coba'
|
|
208
|
+
'make', 'create', 'creating', 'made', 'generate'
|
|
217
209
|
]);
|
|
218
210
|
|
|
219
|
-
// HONEST LIMIT. Matching is LEXICAL.
|
|
220
|
-
//
|
|
221
|
-
// "pen" and "pena" are the same object. That is a deliberate trade: this path
|
|
222
|
-
// is deterministic, instant, and works on a machine with no embedding model
|
|
211
|
+
// HONEST LIMIT. Matching is LEXICAL.
|
|
212
|
+
// This path is deterministic, instant, and works on a machine with no embedding model
|
|
223
213
|
// provisioned. Cortex is the semantic route and already carries embeddings;
|
|
224
214
|
// these two compose rather than compete.
|
|
225
215
|
|
package/src/providers/acp.js
CHANGED
|
@@ -71,7 +71,7 @@ export class AcpProvider extends LLMProvider {
|
|
|
71
71
|
}
|
|
72
72
|
formatConversation(messages, tools = []) {
|
|
73
73
|
const lines = [];
|
|
74
|
-
lines.push('[System Instructions]\nYou are acting as an AI reasoning engine for Causyne Agent over ACP. Do NOT invoke your own internal host CLI tools or execute commands directly. When an action or tool is required, output an explicit tool call in this exact format:\n<tool_call>{"name": "tool_name", "arguments": { ... }}</tool_call>\nCausyne Agent will execute the tool in its secure environment and return the results back to you.\n\n[Language & Communication Directive]\nDynamically reflect and match the exact language used by the user in their prompt.
|
|
74
|
+
lines.push('[System Instructions]\nYou are acting as an AI reasoning engine for Causyne Agent over ACP. Do NOT invoke your own internal host CLI tools or execute commands directly. When an action or tool is required, output an explicit tool call in this exact format:\n<tool_call>{"name": "tool_name", "arguments": { ... }}</tool_call>\nCausyne Agent will execute the tool in its secure environment and return the results back to you.\n\n[Language & Communication Directive]\nDynamically reflect and match the exact language used by the user in their prompt. Respond naturally in that same language.');
|
|
75
75
|
if (tools && tools.length > 0) {
|
|
76
76
|
const toolSummaries = tools.map(t => {
|
|
77
77
|
const name = t.name || t.function?.name || 'unknown';
|
|
@@ -505,7 +505,9 @@ export class AcpProvider extends LLMProvider {
|
|
|
505
505
|
usage: {
|
|
506
506
|
promptTokens: Math.ceil(promptText.length / 4),
|
|
507
507
|
completionTokens: Math.ceil(rawContent.length / 4),
|
|
508
|
-
cachedPromptTokens: 0
|
|
508
|
+
cachedPromptTokens: 0,
|
|
509
|
+
measurement: 'text_estimate',
|
|
510
|
+
cacheMeasurement: 'unavailable'
|
|
509
511
|
}
|
|
510
512
|
};
|
|
511
513
|
if (toolCalls.length > 0) {
|
package/src/providers/acp.ts
CHANGED
|
@@ -73,7 +73,7 @@ export class AcpProvider extends LLMProvider {
|
|
|
73
73
|
|
|
74
74
|
formatConversation(messages: any[], tools: any[] = []): string {
|
|
75
75
|
const lines: string[] = [];
|
|
76
|
-
lines.push('[System Instructions]\nYou are acting as an AI reasoning engine for Causyne Agent over ACP. Do NOT invoke your own internal host CLI tools or execute commands directly. When an action or tool is required, output an explicit tool call in this exact format:\n<tool_call>{"name": "tool_name", "arguments": { ... }}</tool_call>\nCausyne Agent will execute the tool in its secure environment and return the results back to you.\n\n[Language & Communication Directive]\nDynamically reflect and match the exact language used by the user in their prompt.
|
|
76
|
+
lines.push('[System Instructions]\nYou are acting as an AI reasoning engine for Causyne Agent over ACP. Do NOT invoke your own internal host CLI tools or execute commands directly. When an action or tool is required, output an explicit tool call in this exact format:\n<tool_call>{"name": "tool_name", "arguments": { ... }}</tool_call>\nCausyne Agent will execute the tool in its secure environment and return the results back to you.\n\n[Language & Communication Directive]\nDynamically reflect and match the exact language used by the user in their prompt. Respond naturally in that same language.');
|
|
77
77
|
|
|
78
78
|
if (tools && tools.length > 0) {
|
|
79
79
|
const toolSummaries = tools.map(t => {
|
|
@@ -516,7 +516,9 @@ export class AcpProvider extends LLMProvider {
|
|
|
516
516
|
usage: {
|
|
517
517
|
promptTokens: Math.ceil(promptText.length / 4),
|
|
518
518
|
completionTokens: Math.ceil(rawContent.length / 4),
|
|
519
|
-
cachedPromptTokens: 0
|
|
519
|
+
cachedPromptTokens: 0,
|
|
520
|
+
measurement: 'text_estimate',
|
|
521
|
+
cacheMeasurement: 'unavailable'
|
|
520
522
|
}
|
|
521
523
|
};
|
|
522
524
|
if (toolCalls.length > 0) {
|
|
@@ -490,6 +490,7 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
490
490
|
printTimeout;
|
|
491
491
|
currentConversationId = null;
|
|
492
492
|
lastTaskId = null;
|
|
493
|
+
lastCumulativeUsage = null;
|
|
493
494
|
constructor(config = {}) {
|
|
494
495
|
super(config);
|
|
495
496
|
this.model = config.model || 'Gemini 3.8 Flash (Low)';
|
|
@@ -564,7 +565,7 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
564
565
|
'[Environment State & Idempotency Directive]\n' +
|
|
565
566
|
'Reuse relevant verified tool results from this session, and check uncertain prerequisites before relying on them.\n\n' +
|
|
566
567
|
'[Language & Communication Directive]\n' +
|
|
567
|
-
'Dynamically reflect and match the exact language used by the user in their prompt.
|
|
568
|
+
'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.');
|
|
568
569
|
if (tools && tools.length > 0) {
|
|
569
570
|
const toolSummaries = tools.map(t => {
|
|
570
571
|
const name = t.name || t.function?.name || 'unknown';
|
|
@@ -734,15 +735,19 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
734
735
|
const currentSessionKey = options.conversationId || options.taskId || null;
|
|
735
736
|
if (currentSessionKey && currentSessionKey !== this.lastTaskId) {
|
|
736
737
|
this.currentConversationId = null;
|
|
738
|
+
this.lastCumulativeUsage = null;
|
|
737
739
|
this.lastTaskId = currentSessionKey;
|
|
738
740
|
}
|
|
739
741
|
if (messages.length <= 1) {
|
|
740
742
|
this.currentConversationId = null;
|
|
743
|
+
this.lastCumulativeUsage = null;
|
|
741
744
|
}
|
|
742
745
|
const useConversation = Boolean(this.currentConversationId);
|
|
746
|
+
const resumedConversationId = this.currentConversationId;
|
|
743
747
|
const latestUserMessage = [...messages].reverse().find(message => message.role === 'user');
|
|
744
748
|
const latestPrompt = typeof latestUserMessage?.content === 'string' ? latestUserMessage.content : '';
|
|
745
749
|
const launchOnly = options.taskIntent === 'launch' || isLaunchOnlyPrompt(latestPrompt);
|
|
750
|
+
const desktopTask = options.taskArchetype === 'desktop_personalization';
|
|
746
751
|
let promptText;
|
|
747
752
|
if (useConversation) {
|
|
748
753
|
let lastAssistantIndex = -1;
|
|
@@ -766,6 +771,13 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
766
771
|
'Do not create, edit, delete, install, or regenerate files. Do not claim the app opened unless a tool confirmed it. ' +
|
|
767
772
|
'Use Causyne tool calls for commands and desktop opening.\n\n' + promptText;
|
|
768
773
|
}
|
|
774
|
+
if (desktopTask) {
|
|
775
|
+
promptText = '[Current desktop task: finish and verify the requested change]\n' +
|
|
776
|
+
'Use only the tools needed. Search and download alone are not completion. ' +
|
|
777
|
+
'After setting the desktop picture, read back the actual system wallpaper and compare it with the intended image. ' +
|
|
778
|
+
'If a command is denied or the readback does not confirm the change, report the blocker honestly. ' +
|
|
779
|
+
'Keep native tool actions within 12; use Causyne tool calls when a native action is blocked.\n\n' + promptText;
|
|
780
|
+
}
|
|
769
781
|
const modelSlug = resolveAgyModelId(this.model);
|
|
770
782
|
const effort = resolveAgyEffort(this.model);
|
|
771
783
|
// Standard high-performance non-blocking CLI invocation:
|
|
@@ -817,7 +829,41 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
817
829
|
const nativeActions = [];
|
|
818
830
|
const attemptedNativeTools = [];
|
|
819
831
|
let childClosed = false;
|
|
832
|
+
const terminateChild = () => {
|
|
833
|
+
try {
|
|
834
|
+
child.kill('SIGTERM');
|
|
835
|
+
setTimeout(() => {
|
|
836
|
+
if (!childClosed)
|
|
837
|
+
child.kill('SIGKILL');
|
|
838
|
+
}, 1000).unref();
|
|
839
|
+
}
|
|
840
|
+
catch {
|
|
841
|
+
// A process that already exited needs no further action.
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
const maxNativeActions = desktopTask ? 12 : Infinity;
|
|
845
|
+
let nativeActionStarts = 0;
|
|
846
|
+
const seenNativeActionSteps = new Set();
|
|
847
|
+
// Antigravity's result usage is cumulative across the conversation, but
|
|
848
|
+
// DONE step updates carry usage for that step. Keep a turn-local subtotal
|
|
849
|
+
// so a single headless run cannot consume an entire task budget unseen.
|
|
850
|
+
const completedUsageSteps = new Set();
|
|
851
|
+
const partialUsage = {
|
|
852
|
+
promptTokens: 0, completionTokens: 0, cachedPromptTokens: 0,
|
|
853
|
+
thinkingTokens: 0, measurement: 'provider_reported', cacheMeasurement: 'provider_reported'
|
|
854
|
+
};
|
|
855
|
+
const tokenLimit = Number(options.maxTokensThisCall);
|
|
856
|
+
const enforceTokenLimit = Number.isFinite(tokenLimit) && tokenLimit > 0;
|
|
857
|
+
const wallTimer = desktopTask ? setTimeout(() => {
|
|
858
|
+
const error = new Error('Antigravity exceeded the 180-second desktop task limit. Outcome is unverified.');
|
|
859
|
+
error.code = 'AGY_DESKTOP_TASK_LIMIT';
|
|
860
|
+
safeReject(error);
|
|
861
|
+
terminateChild();
|
|
862
|
+
}, 180_000) : null;
|
|
863
|
+
wallTimer?.unref();
|
|
820
864
|
const cleanup = () => {
|
|
865
|
+
if (wallTimer)
|
|
866
|
+
clearTimeout(wallTimer);
|
|
821
867
|
if (options.signal) {
|
|
822
868
|
options.signal.removeEventListener('abort', onAbort);
|
|
823
869
|
}
|
|
@@ -837,16 +883,7 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
837
883
|
resolve(res);
|
|
838
884
|
};
|
|
839
885
|
const onAbort = () => {
|
|
840
|
-
|
|
841
|
-
child.kill('SIGTERM');
|
|
842
|
-
setTimeout(() => {
|
|
843
|
-
if (!childClosed)
|
|
844
|
-
child.kill('SIGKILL');
|
|
845
|
-
}, 1000).unref();
|
|
846
|
-
}
|
|
847
|
-
catch {
|
|
848
|
-
// ignore kill errors
|
|
849
|
-
}
|
|
886
|
+
terminateChild();
|
|
850
887
|
const abortErr = new Error('Turn aborted by user or timeout.');
|
|
851
888
|
abortErr.name = 'AbortError';
|
|
852
889
|
safeReject(abortErr);
|
|
@@ -887,15 +924,50 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
887
924
|
}
|
|
888
925
|
else if (event.event === 'step_update') {
|
|
889
926
|
const stepUpdate = event.step_update;
|
|
927
|
+
const usage = stepUpdate?.usage;
|
|
928
|
+
const usageStepIndex = Number(stepUpdate?.step_index ?? event?.step_index);
|
|
929
|
+
if (stepUpdate?.state === 'DONE' && usage && Number.isFinite(usageStepIndex)
|
|
930
|
+
&& !completedUsageSteps.has(usageStepIndex)) {
|
|
931
|
+
const input = Number(usage.input_tokens);
|
|
932
|
+
const output = Number(usage.output_tokens);
|
|
933
|
+
if (Number.isFinite(input) && input >= 0 && Number.isFinite(output) && output >= 0) {
|
|
934
|
+
completedUsageSteps.add(usageStepIndex);
|
|
935
|
+
partialUsage.promptTokens += input;
|
|
936
|
+
partialUsage.completionTokens += output;
|
|
937
|
+
partialUsage.cachedPromptTokens = (partialUsage.cachedPromptTokens || 0)
|
|
938
|
+
+ (Number(usage.cache_read_tokens) || 0);
|
|
939
|
+
partialUsage.thinkingTokens = (partialUsage.thinkingTokens || 0)
|
|
940
|
+
+ (Number(usage.thinking_tokens) || 0);
|
|
941
|
+
if (enforceTokenLimit && partialUsage.promptTokens + partialUsage.completionTokens >= tokenLimit) {
|
|
942
|
+
this.currentConversationId = null;
|
|
943
|
+
const error = Object.assign(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.`), { code: 'AGY_TOKEN_BUDGET', partialUsage: { ...partialUsage } });
|
|
944
|
+
safeReject(error);
|
|
945
|
+
terminateChild();
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
}
|
|
890
950
|
const delta = stepUpdate?.text_delta;
|
|
891
951
|
const stepType = stepUpdate?.step_type;
|
|
892
952
|
if (stepType === 'tool') {
|
|
893
953
|
const state = stepUpdate?.state;
|
|
954
|
+
const stepIndex = Number(stepUpdate?.step_index ?? event?.step_index);
|
|
955
|
+
const newNativeAction = (state === 'ACTIVE' || (state === 'DONE' && Number.isFinite(stepIndex)))
|
|
956
|
+
&& (!Number.isFinite(stepIndex) || !seenNativeActionSteps.has(stepIndex));
|
|
957
|
+
if (newNativeAction && Number.isFinite(stepIndex))
|
|
958
|
+
seenNativeActionSteps.add(stepIndex);
|
|
959
|
+
if (desktopTask && newNativeAction && ++nativeActionStarts > maxNativeActions) {
|
|
960
|
+
const error = new Error(`Antigravity exceeded ${maxNativeActions} native actions for this desktop task. Outcome is unverified.`);
|
|
961
|
+
error.code = 'AGY_NATIVE_ACTION_BUDGET';
|
|
962
|
+
safeReject(error);
|
|
963
|
+
terminateChild();
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
894
966
|
const toolInfo = stepUpdate?.tool_info || {};
|
|
895
967
|
const name = stepUpdate?.tool_name || toolInfo?.name;
|
|
896
|
-
const status = state === 'DONE'
|
|
897
|
-
? 'completed'
|
|
898
|
-
:
|
|
968
|
+
const status = state === 'DONE' || state === 'ERROR'
|
|
969
|
+
? (state === 'ERROR' || toolInfo?.error ? 'failed' : 'completed')
|
|
970
|
+
: 'running';
|
|
899
971
|
const rawParams = (toolInfo && typeof toolInfo === 'object' && toolInfo.parameters) ||
|
|
900
972
|
(stepUpdate && typeof stepUpdate === 'object' && stepUpdate.parameters) ||
|
|
901
973
|
(toolInfo && typeof toolInfo === 'object' && toolInfo.input) ||
|
|
@@ -997,6 +1069,10 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
997
1069
|
});
|
|
998
1070
|
child.on('close', (code) => {
|
|
999
1071
|
childClosed = true;
|
|
1072
|
+
// A budget or user abort has already settled this call. Do not accept
|
|
1073
|
+
// a late result from the terminated process as a resumable session.
|
|
1074
|
+
if (isSettled)
|
|
1075
|
+
return;
|
|
1000
1076
|
// Process any remaining bytes in stdoutBuffer
|
|
1001
1077
|
if (stdoutBuffer.trim()) {
|
|
1002
1078
|
try {
|
|
@@ -1018,10 +1094,11 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
1018
1094
|
// ignore
|
|
1019
1095
|
}
|
|
1020
1096
|
}
|
|
1021
|
-
if (code !== 0 || finalResultObj?.status
|
|
1097
|
+
if (code !== 0 || (finalResultObj?.status && finalResultObj.status !== 'SUCCESS')) {
|
|
1022
1098
|
if (useConversation)
|
|
1023
1099
|
this.currentConversationId = null;
|
|
1024
|
-
const errDetail = finalResultObj?.error || stderrBuffer.trim() ||
|
|
1100
|
+
const errDetail = finalResultObj?.error || stderrBuffer.trim() ||
|
|
1101
|
+
`terminal status ${finalResultObj?.status || 'unknown'}, exit code ${code}`;
|
|
1025
1102
|
safeReject(new Error(`Antigravity Agent (agy) failed: ${errDetail}`));
|
|
1026
1103
|
return;
|
|
1027
1104
|
}
|
|
@@ -1096,15 +1173,33 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
1096
1173
|
const finalResponseText = typeof finalResultObj?.response === 'string' ? finalResultObj.response.trim() : '';
|
|
1097
1174
|
const endedAfterToolWithoutFinalResponse = sawToolAfterLastText && !finalResponseText && deniedActions.length === 0 && toolCalls.length === 0;
|
|
1098
1175
|
const missingResultEvent = finalResultObj === null && deniedActions.length === 0 && toolCalls.length === 0;
|
|
1099
|
-
const
|
|
1100
|
-
|
|
1101
|
-
|
|
1176
|
+
const usageIsReported = finalResultObj?.usage?.input_tokens != null
|
|
1177
|
+
&& finalResultObj?.usage?.output_tokens != null
|
|
1178
|
+
&& Number.isFinite(Number(finalResultObj.usage.input_tokens))
|
|
1179
|
+
&& Number.isFinite(Number(finalResultObj.usage.output_tokens));
|
|
1180
|
+
const cumulative = {
|
|
1181
|
+
input: usageIsReported ? Number(finalResultObj.usage.input_tokens) : Math.ceil(promptText.length / 4),
|
|
1182
|
+
output: usageIsReported ? Number(finalResultObj.usage.output_tokens) : Math.ceil(rawContent.length / 4),
|
|
1183
|
+
thinking: Number(finalResultObj?.usage?.thinking_tokens) || 0,
|
|
1184
|
+
cacheRead: Number(finalResultObj?.usage?.cache_read_tokens) || 0
|
|
1185
|
+
};
|
|
1186
|
+
const prior = useConversation && resumedConversationId === this.lastCumulativeUsage?.conversationId
|
|
1187
|
+
? this.lastCumulativeUsage : null;
|
|
1188
|
+
const delta = (current, previous) => current >= previous ? current - previous : current;
|
|
1189
|
+
const promptTokens = prior && usageIsReported ? delta(cumulative.input, prior.input) : cumulative.input;
|
|
1190
|
+
const completionTokens = prior && usageIsReported ? delta(cumulative.output, prior.output) : cumulative.output;
|
|
1191
|
+
const thinkingTokens = prior && usageIsReported ? delta(cumulative.thinking, prior.thinking) : cumulative.thinking;
|
|
1192
|
+
const cachedPromptTokens = prior && usageIsReported ? delta(cumulative.cacheRead, prior.cacheRead) : cumulative.cacheRead;
|
|
1102
1193
|
const response = {
|
|
1103
1194
|
content,
|
|
1104
1195
|
usage: {
|
|
1105
1196
|
promptTokens,
|
|
1106
|
-
completionTokens
|
|
1107
|
-
|
|
1197
|
+
completionTokens,
|
|
1198
|
+
thinkingTokens,
|
|
1199
|
+
cachedPromptTokens,
|
|
1200
|
+
measurement: usageIsReported ? 'provider_reported' : 'text_estimate',
|
|
1201
|
+
cacheMeasurement: finalResultObj?.usage?.cache_read_tokens != null
|
|
1202
|
+
? 'provider_reported' : 'unavailable'
|
|
1108
1203
|
}
|
|
1109
1204
|
};
|
|
1110
1205
|
if (extractedReasoning) {
|
|
@@ -1119,6 +1214,9 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
1119
1214
|
if (timedOutMidTurn || endedAfterToolWithoutFinalResponse || missingResultEvent) {
|
|
1120
1215
|
response.incompleteTurn = true;
|
|
1121
1216
|
}
|
|
1217
|
+
if (usageIsReported && this.currentConversationId) {
|
|
1218
|
+
this.lastCumulativeUsage = { conversationId: this.currentConversationId, ...cumulative };
|
|
1219
|
+
}
|
|
1122
1220
|
safeResolve(response);
|
|
1123
1221
|
});
|
|
1124
1222
|
});
|
|
@@ -1135,7 +1233,9 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
1135
1233
|
if (options.signal?.aborted || err?.name === 'AbortError') {
|
|
1136
1234
|
throw err;
|
|
1137
1235
|
}
|
|
1138
|
-
const canRetryResetConversation = hadConversation && !this.currentConversationId
|
|
1236
|
+
const canRetryResetConversation = hadConversation && !this.currentConversationId
|
|
1237
|
+
&& err?.code !== 'AGY_NATIVE_ACTION_DENIED'
|
|
1238
|
+
&& err?.code !== 'AGY_TOKEN_BUDGET';
|
|
1139
1239
|
if (attempt < maxRetries && (this._isTransientError(err.message) || canRetryResetConversation)) {
|
|
1140
1240
|
attempt++;
|
|
1141
1241
|
const delay = attempt * 1200;
|