@causyne/agent 1.20.112 → 1.20.117
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/docs/ARCHITECTURE.md +29 -0
- package/package.json +1 -1
- package/src/agentLoop.js +153 -68
- package/src/agentLoop.ts +152 -71
- package/src/browser/browserRuntime.js +13 -8
- package/src/browser/browserRuntime.ts +16 -8
- package/src/browser/causyneBrowser.js +37 -9
- package/src/browser/causyneBrowser.ts +37 -9
- package/src/browser/searchProviders.js +18 -7
- package/src/browser/searchProviders.ts +17 -5
- package/src/browser/snapshotWindow.js +1 -1
- package/src/browser/snapshotWindow.ts +1 -1
- package/src/browser/urlPolicy.js +21 -10
- package/src/browser/urlPolicy.ts +19 -10
- package/src/browser/workspacePreview.js +13 -1
- package/src/browser/workspacePreview.ts +11 -1
- package/src/cliMode.js +5 -1
- package/src/computerUse/visionGrounding.js +31 -27
- package/src/computerUse/visionGrounding.ts +27 -27
- package/src/continuum/ui/continuumPicker.js +14 -6
- package/src/continuum/ui/continuumPicker.ts +13 -6
- package/src/continuum/ui/continuumPickerView.js +24 -15
- package/src/continuum/ui/continuumPickerView.ts +24 -16
- package/src/memory/scopedFacts.js +171 -0
- package/src/memory/scopedFacts.ts +214 -0
- package/src/memory.d.ts +13 -1
- package/src/memory.js +9 -12
- package/src/observer/advisory.js +32 -22
- package/src/observer/advisory.ts +30 -18
- package/src/observer/coldObserver.js +21 -33
- package/src/observer/coldObserver.ts +20 -33
- package/src/observer/evidence.js +20 -13
- package/src/observer/evidence.ts +21 -13
- package/src/observer.js +47 -12
- package/src/observer.ts +50 -18
- package/src/perception.js +124 -3
- package/src/perception.ts +128 -4
- package/src/planCache.js +17 -3
- package/src/planCache.ts +17 -3
- package/src/pluginsFactory/discovery.js +28 -16
- package/src/pluginsFactory/discovery.ts +29 -16
- package/src/pluginsFactory/pluginsFactory.js +213 -38
- package/src/pluginsFactory/pluginsFactory.ts +218 -39
- package/src/pluginsFactory/strategy.js +26 -16
- package/src/pluginsFactory/strategy.ts +34 -19
- package/src/pluginsFactory/templates.js +183 -62
- package/src/pluginsFactory/templates.ts +174 -54
- package/src/smartToolsUse.js +4 -5
- package/src/smartToolsUse.ts +4 -6
- package/src/taskShape.js +49 -7
- package/src/taskShape.ts +55 -7
- package/src/timeMachine.js +43 -22
- package/src/timeMachine.ts +44 -22
- package/src/tool-scripts/desktop_act.applescript +1 -0
- package/src/toolPacks.js +27 -5
- package/src/toolPacks.ts +32 -5
- package/src/tools/computerUse.js +23 -10
- package/src/tools/computerUse.ts +19 -8
- package/src/tools/desktopAct.js +12 -1
- package/src/tools/memoryWrite.js +8 -10
- package/src/tools/memoryWrite.ts +13 -11
- package/src/tools/pluginsFactory.js +108 -5
- package/src/tools/pluginsFactory.ts +115 -5
- package/src/tui/CausyneRotor.js +24 -10
- package/src/tui/CausyneRotor.ts +25 -10
- package/src/tui/activityLayout.js +9 -5
- package/src/tui/activityLayout.ts +9 -5
- package/src/tui/ask.js +34 -14
- package/src/tui/banner.js +55 -18
- package/src/tui/banner.ts +52 -17
- package/src/tui/block.js +47 -20
- package/src/tui/block.ts +54 -27
- package/src/tui/chatRenderer.js +139 -84
- package/src/tui/chatboxClipboard.js +12 -5
- package/src/tui/chatboxClipboard.ts +10 -4
- package/src/tui/clipboardImage.js +52 -42
- package/src/tui/clipboardImage.ts +50 -39
- package/src/tui/clipboardSync.js +12 -1
- package/src/tui/clipboardSync.ts +9 -1
- package/src/tui/codeProgress.js +60 -28
- package/src/tui/codeProgress.ts +60 -27
- package/src/tui/codeStreamRenderer.js +94 -23
- package/src/tui/codeStreamRenderer.ts +92 -23
- package/src/tui/commandPresentation.js +9 -2
- package/src/tui/commandPresentation.ts +9 -2
- package/src/tui/completion.js +45 -23
- package/src/tui/composerControls.js +21 -10
- package/src/tui/composerControls.ts +18 -10
- package/src/tui/composerGeometry.js +6 -4
- package/src/tui/composerGeometry.ts +6 -4
- package/src/tui/consoleGuard.js +29 -7
- package/src/tui/consoleGuard.ts +28 -7
- package/src/tui/dialogs.js +134 -71
- package/src/tui/diff.js +8 -4
- package/src/tui/history.js +6 -5
- package/src/tui/home.js +25 -13
- package/src/tui/homeView.js +37 -18
- package/src/tui/homeView.ts +38 -18
- package/src/tui/inlineSlash.js +6 -5
- package/src/tui/inlineSlash.ts +6 -5
- package/src/tui/keys.js +36 -18
- package/src/tui/layout.js +27 -9
- package/src/tui/layout.ts +26 -9
- package/src/tui/lineEditor.js +49 -23
- package/src/tui/markdownMath.js +64 -14
- package/src/tui/markdownMath.ts +69 -13
- package/src/tui/messageActionPlacement.js +28 -13
- package/src/tui/messageActionPlacement.ts +28 -13
- package/src/tui/messageInteraction.js +111 -46
- package/src/tui/messageInteraction.ts +115 -47
- package/src/tui/modelPicker.js +44 -15
- package/src/tui/modelPicker.ts +48 -15
- package/src/tui/observerPicker.js +56 -13
- package/src/tui/observerPicker.ts +73 -30
- package/src/tui/overlay.js +79 -35
- package/src/tui/overlay.ts +81 -34
- package/src/tui/prompt.js +186 -94
- package/src/tui/runningLight.js +1 -1
- package/src/tui/runningLight.ts +1 -1
- package/src/tui/scrollInteraction.js +64 -36
- package/src/tui/scrollInteraction.ts +70 -37
- package/src/tui/selectList.js +60 -32
- package/src/tui/sessionLayout.js +11 -3
- package/src/tui/sessionLayout.ts +10 -3
- package/src/tui/sessionPicker.js +74 -46
- package/src/tui/sessionPicker.ts +73 -48
- package/src/tui/sessionPickerView.js +32 -19
- package/src/tui/sessionPickerView.ts +31 -18
- package/src/tui/sessionSidebar.js +87 -57
- package/src/tui/sessionSidebar.ts +90 -54
- package/src/tui/setup.js +28 -3
- package/src/tui/setup.ts +27 -3
- package/src/tui/skillAuthoring.js +11 -5
- package/src/tui/skillAuthoring.ts +11 -5
- package/src/tui/smartLinkClick.js +75 -23
- package/src/tui/smartLinkClick.ts +86 -26
- package/src/tui/stage.js +47 -16
- package/src/tui/stage.ts +53 -18
- package/src/tui/stageSurface.js +232 -51
- package/src/tui/statusLine.js +85 -53
- package/src/tui/statusLine.ts +82 -46
- package/src/tui/terminalInputFramer.js +5 -2
- package/src/tui/text.js +117 -46
- package/src/tui/text.ts +113 -43
- package/src/tui/textLayout.js +6 -4
- package/src/tui/textLayout.ts +11 -5
- package/src/tui/theme.js +17 -8
- package/src/tui/thinkingBox.js +95 -95
- package/src/tui/thinkingBox.ts +105 -80
- package/src/tui/toolActivityPolicy.js +8 -1
- package/src/tui/toolActivityPolicy.ts +7 -1
- package/src/tui/toolDisplay.js +15 -6
- package/src/tui/toolDisplay.ts +16 -6
- package/src/tui/toolOutputNormalizer.js +16 -3
- package/src/tui/toolOutputNormalizer.ts +13 -3
- package/src/tui/transcript.js +15 -9
- package/src/tui/turnRail.js +176 -80
- package/src/tui/turnRail.ts +173 -71
- package/src/tui/usageCard.js +136 -80
- package/src/tui/usageCard.ts +145 -103
- package/src/tui/viewport.js +48 -23
- package/src/tui/viewport.ts +48 -27
- package/src/tui/viewportAnchor.js +2 -2
- package/src/tui/viewportAnchor.ts +2 -2
- package/src/tui/workspaceFileIndex.js +8 -6
- package/src/tui/workspaceFileIndex.ts +8 -6
- package/src/tui/workspaceSwitch.js +13 -10
- package/src/tui/workspaceSwitch.ts +11 -7
- package/src/types/contracts.ts +3 -0
package/src/taskShape.ts
CHANGED
|
@@ -109,6 +109,19 @@ const ARCHETYPES: Record<string, ArchetypeDefinition> = {
|
|
|
109
109
|
{ name: 'Report', tools: [], note: 'Answer concisely and cite exact file paths or URLs. Do not modify anything unless asked.' }
|
|
110
110
|
]
|
|
111
111
|
},
|
|
112
|
+
modify_repo: {
|
|
113
|
+
label: 'Inspect and update an existing project or build release artifact',
|
|
114
|
+
match: {
|
|
115
|
+
strong: ['bump', 'version code', 'version name', 'aab', 'apk', 'release', 'export', 'synchronize', 'sync', 'upgrade', 'migrate', 'rebuild'],
|
|
116
|
+
weak: ['version', 'bundle', 'existing', 'repo', 'repository', 'docs']
|
|
117
|
+
},
|
|
118
|
+
phases: [
|
|
119
|
+
{ name: 'Orient in docs and structure', tools: ['fs_read', 'fs_list'], note: 'Read the workspace README, docs/ guides (e.g. ANDROID_RELEASE.md, ENGINEERING.md), and build scripts/manifests FIRST to follow the repository conventions.' },
|
|
120
|
+
{ name: 'Apply targeted updates', tools: ['fs_read', 'fs_edit', 'MultiEdit'], note: 'Modify only the exact configuration, version fields, or source files required by the user request.' },
|
|
121
|
+
{ name: 'Run documented build', tools: ['sysRun'], note: 'Execute the project’s documented build/export command for the requested deliverable only. Do not build unrelated web or side targets.' },
|
|
122
|
+
{ name: 'Verify artifact', tools: ['sysRun', 'fs_read'], note: 'Verify the exact produced output (version, signature, alignment, tests) before reporting.' }
|
|
123
|
+
]
|
|
124
|
+
},
|
|
112
125
|
maintain: {
|
|
113
126
|
label: 'Operate on files, processes or the machine itself',
|
|
114
127
|
match: {
|
|
@@ -153,6 +166,12 @@ function scoreSignals(text: string, signals: SignalSet): { score: number; hits:
|
|
|
153
166
|
return { score, hits };
|
|
154
167
|
}
|
|
155
168
|
|
|
169
|
+
function isPureGreeting(prompt: string): boolean {
|
|
170
|
+
const cleaned = String(prompt || '').trim().toLowerCase().replace(/[!?.]+$/g, '');
|
|
171
|
+
if (!cleaned) return false;
|
|
172
|
+
return /^(?:hi+|hello+|hey+|yo+|sup|greetings|good\s+(?:morning|afternoon|evening)|thanks|thank\s+you|ok(?:ay)?)$/.test(cleaned);
|
|
173
|
+
}
|
|
174
|
+
|
|
156
175
|
/**
|
|
157
176
|
* Analyse a request into the shape of the work it implies.
|
|
158
177
|
*
|
|
@@ -160,11 +179,13 @@ function scoreSignals(text: string, signals: SignalSet): { score: number; hits:
|
|
|
160
179
|
export function analyzeTask(prompt: string, workspaceContext: WorkspaceContext | null = null): TaskShape {
|
|
161
180
|
const rawPrompt = String(prompt || '');
|
|
162
181
|
const pureSkillLookup = isPureSkillOrCapabilityLookup(rawPrompt);
|
|
182
|
+
const pureGreeting = !pureSkillLookup && isPureGreeting(rawPrompt);
|
|
183
|
+
const lightweightLookup = pureSkillLookup || pureGreeting;
|
|
163
184
|
const text = (pureSkillLookup ? redactSkillAndQueryLiterals(rawPrompt) : rawPrompt).toLowerCase();
|
|
164
185
|
|
|
165
186
|
// Which capability packs are worth their token cost for this request.
|
|
166
187
|
const packScores: TaskPackScore[] = [];
|
|
167
|
-
if (!
|
|
188
|
+
if (!lightweightLookup) {
|
|
168
189
|
for (const packName of Object.keys(PACK_SIGNALS)) {
|
|
169
190
|
const signals = PACK_SIGNALS[packName];
|
|
170
191
|
if (!signals) continue;
|
|
@@ -178,12 +199,14 @@ export function analyzeTask(prompt: string, workspaceContext: WorkspaceContext |
|
|
|
178
199
|
// Workspace evidence outranks keywords: a Godot project on disk is far more
|
|
179
200
|
// reliable than any phrasing in the prompt. Pure skill/capability lookups
|
|
180
201
|
// stay lightweight and never preload workspace app packs.
|
|
181
|
-
if (workspaceContext && !
|
|
202
|
+
if (workspaceContext && !lightweightLookup) {
|
|
182
203
|
const signals = [
|
|
183
204
|
workspaceContext.framework,
|
|
184
205
|
workspaceContext.projectType,
|
|
185
206
|
workspaceContext.designSystem,
|
|
186
|
-
Array.isArray(workspaceContext.keyFiles) ? workspaceContext.keyFiles.join(' ') : ''
|
|
207
|
+
Array.isArray(workspaceContext.keyFiles) ? workspaceContext.keyFiles.join(' ') : '',
|
|
208
|
+
Array.isArray(workspaceContext.subprojectStacks) ? workspaceContext.subprojectStacks.join(' ') : '',
|
|
209
|
+
Array.isArray(workspaceContext.buildFiles) ? workspaceContext.buildFiles.join(' ') : ''
|
|
187
210
|
].filter(Boolean).join(' ').toLowerCase();
|
|
188
211
|
|
|
189
212
|
const bump = (name: string, amount: number): void => {
|
|
@@ -192,8 +215,14 @@ export function analyzeTask(prompt: string, workspaceContext: WorkspaceContext |
|
|
|
192
215
|
else packScores.push({ name, score: amount });
|
|
193
216
|
};
|
|
194
217
|
|
|
195
|
-
|
|
196
|
-
|
|
218
|
+
const hasGameProject = /godot|project\.godot|unity|\.tscn/.test(signals);
|
|
219
|
+
const hasExplicitWebFramework = /\b(react|vue|svelte|next|nuxt|astro|angular|tailwind|vite)\b/.test(signals);
|
|
220
|
+
const explicitNonWebTarget = /\b(aab|apk|gradle|android|godot|export_presets|tscn|gdscript|xcode|ipa|ios|rust|cargo)\b/.test(text);
|
|
221
|
+
const hasPromptWebSignal = /\b(web|website|html|css|browser|frontend|page|ui|dom|react|vue|svelte|vite|next|playwright|lighthouse|localhost)\b/.test(text);
|
|
222
|
+
if (hasGameProject) bump('game', 5);
|
|
223
|
+
if (!explicitNonWebTarget && (hasExplicitWebFramework || (!hasGameProject && /index\.html/.test(signals)) || (hasGameProject && /index\.html/.test(signals) && hasPromptWebSignal))) {
|
|
224
|
+
bump('web', 4);
|
|
225
|
+
}
|
|
197
226
|
}
|
|
198
227
|
|
|
199
228
|
packScores.sort((a, b) => b.score - a.score);
|
|
@@ -222,12 +251,31 @@ export function analyzeTask(prompt: string, workspaceContext: WorkspaceContext |
|
|
|
222
251
|
bestScore = integrationScore;
|
|
223
252
|
}
|
|
224
253
|
|
|
225
|
-
|
|
254
|
+
const hasExistingRepo = Boolean(
|
|
255
|
+
workspaceContext && (
|
|
256
|
+
(Array.isArray(workspaceContext.keyFiles) && workspaceContext.keyFiles.length > 0)
|
|
257
|
+
|| (Array.isArray(workspaceContext.buildFiles) && workspaceContext.buildFiles.length > 0)
|
|
258
|
+
|| (Array.isArray(workspaceContext.docFiles) && workspaceContext.docFiles.length > 0)
|
|
259
|
+
|| (Array.isArray(workspaceContext.subprojectStacks) && workspaceContext.subprojectStacks.length > 0)
|
|
260
|
+
|| (workspaceContext.framework && !/^(?:none|unknown)$/i.test(String(workspaceContext.framework)))
|
|
261
|
+
|| (workspaceContext.projectType && !/^(?:none|unknown)$/i.test(String(workspaceContext.projectType)))
|
|
262
|
+
)
|
|
263
|
+
);
|
|
264
|
+
const explicitGreenfield = /\b(?:from\s+scratch|new\s+app(?:lication)?|new\s+project|greenfield|scaffold)\b/.test(text);
|
|
265
|
+
const explicitRepoReleaseOrModify = /\b(?:aab|apk|gradle|android|release|bump|versioncode|version|export|rebuild|update|upgrade|modify|extend|add\s+feature|existing|script)\b/.test(text);
|
|
266
|
+
if (!lightweightLookup && hasExistingRepo && (bestArchetype === 'build_app' || !bestArchetype) && !explicitGreenfield) {
|
|
267
|
+
if (bestArchetype !== 'build_app' || explicitRepoReleaseOrModify) {
|
|
268
|
+
bestArchetype = 'modify_repo';
|
|
269
|
+
bestScore = Math.max(bestScore, STRONG_WEIGHT);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (lightweightLookup) {
|
|
226
274
|
bestArchetype = 'research';
|
|
227
275
|
bestScore = Math.max(bestScore, STRONG_WEIGHT);
|
|
228
276
|
}
|
|
229
277
|
|
|
230
|
-
const archetype = bestArchetype || 'build_app';
|
|
278
|
+
const archetype = bestArchetype || (hasExistingRepo ? 'modify_repo' : 'build_app');
|
|
231
279
|
const confidence = bestScore >= 6 ? 'high' : (bestScore >= 3 ? 'medium' : 'low');
|
|
232
280
|
|
|
233
281
|
const definition = ARCHETYPES[archetype];
|
package/src/timeMachine.js
CHANGED
|
@@ -13,7 +13,8 @@ export function recoveryUserMessage(decision, tool) {
|
|
|
13
13
|
if (decision.kind === 'human') {
|
|
14
14
|
return `${tool} needs approval or authentication. Review the last tool error, then provide the needed access or choose another route. No success is claimed.`;
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
// A stop before the hard maximum only happens when further attempts were not approved.
|
|
17
|
+
if (decision.attempt < TIME_MACHINE_MAX_ATTEMPTS && decision.kind === 'stop') {
|
|
17
18
|
return `${tool} failed ${decision.attempt} times (${decision.failureClass}) and more attempts were not approved. The task stopped without verified success.`;
|
|
18
19
|
}
|
|
19
20
|
return `${tool} still failed after ${decision.attempt} attempts (${decision.failureClass}). The task stopped without verified success.`;
|
|
@@ -22,14 +23,16 @@ function record(value) {
|
|
|
22
23
|
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
23
24
|
? value : {};
|
|
24
25
|
}
|
|
26
|
+
function firstText(values) {
|
|
27
|
+
return values.find((value) => typeof value === 'string' && value.trim().length > 0) ?? '';
|
|
28
|
+
}
|
|
29
|
+
function commandText(args) {
|
|
30
|
+
return firstText([args.command, args.cmd, args.CommandLine, args.commandLine, args.script]);
|
|
31
|
+
}
|
|
25
32
|
function operationFamily(args) {
|
|
26
|
-
const command =
|
|
27
|
-
: typeof args.cmd === 'string' ? args.cmd
|
|
28
|
-
: typeof args.CommandLine === 'string' ? args.CommandLine
|
|
29
|
-
: typeof args.commandLine === 'string' ? args.commandLine
|
|
30
|
-
: typeof args.script === 'string' ? args.script : '';
|
|
33
|
+
const command = commandText(args);
|
|
31
34
|
if (!command) {
|
|
32
|
-
const endpoint =
|
|
35
|
+
const endpoint = firstText([args.url, args.endpoint]);
|
|
33
36
|
if (endpoint) {
|
|
34
37
|
try {
|
|
35
38
|
return new URL(endpoint).hostname.toLowerCase();
|
|
@@ -40,18 +43,31 @@ function operationFamily(args) {
|
|
|
40
43
|
}
|
|
41
44
|
return '';
|
|
42
45
|
}
|
|
43
|
-
const
|
|
46
|
+
const tokens = command.trim().split(/\s+/);
|
|
47
|
+
// Leading VAR=value assignments do not change which operation is retried, so
|
|
48
|
+
// `CI=1 npm test` must share the retry budget of `npm test`.
|
|
49
|
+
while (tokens.length > 1 && /^[A-Za-z_][A-Za-z0-9_]*=/.test(tokens[0] || ''))
|
|
50
|
+
tokens.shift();
|
|
51
|
+
const words = tokens.slice(0, 3);
|
|
52
|
+
// Windows shims (`npm.cmd`, `bun.exe`) are the same tools as their bare names.
|
|
53
|
+
const executable = (words[0] || '').replace(/^.*[\\/]/, '').replace(/\.(cmd|exe|bat|ps1)$/i, '').toLowerCase();
|
|
44
54
|
// Keep common verification commands distinct without retaining paths,
|
|
45
55
|
// source text, environment variables, or credentials in the journal.
|
|
46
|
-
if (/^(npm|pnpm|yarn|bun)$/.test(
|
|
47
|
-
|
|
56
|
+
if (/^(npm|pnpm|yarn|bun)$/.test(executable)) {
|
|
57
|
+
// Script names are case-sensitive; a passing `build` cannot resolve `Build`.
|
|
58
|
+
return [executable, ...words.slice(1, words[1] === 'run' ? 3 : 2)].join(' ');
|
|
59
|
+
}
|
|
60
|
+
if (/^(git|gh|docker|podman|kubectl)$/.test(executable)) {
|
|
61
|
+
// Distinct subcommands must have distinct recovery histories: a passing
|
|
62
|
+
// git status is not evidence that an earlier git push succeeded.
|
|
63
|
+
return [executable, (words[1] || '').toLowerCase().slice(0, 32)].filter(Boolean).join(' ');
|
|
48
64
|
}
|
|
49
|
-
return
|
|
65
|
+
return executable.slice(0, 32);
|
|
50
66
|
}
|
|
51
67
|
function issueKey(tool, args) {
|
|
52
68
|
const family = operationFamily(args);
|
|
53
|
-
const target =
|
|
54
|
-
const workspace = String(args.cwd ?? '');
|
|
69
|
+
const target = firstText([args.path, args.file_path, args.filePath, args.target, args.endpoint, args.url]);
|
|
70
|
+
const workspace = String(args.cwd ?? args.workingDirectory ?? args.workingDir ?? args.workspaceRoot ?? '');
|
|
55
71
|
// Changing error text/class does not buy another three attempts at the same
|
|
56
72
|
// operation. Targets are hashed and never included in recovery messages.
|
|
57
73
|
return createHash('sha256').update(`${tool}\0${family}\0${target}\0${workspace}`).digest('hex');
|
|
@@ -95,12 +111,16 @@ export class TimeMachine {
|
|
|
95
111
|
return this.extended.has(issueKeyValue);
|
|
96
112
|
}
|
|
97
113
|
observe(tool, args, result, outcomes = []) {
|
|
114
|
+
const safeArgs = record(args);
|
|
98
115
|
const value = record(result);
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
||
|
|
102
|
-
|
|
103
|
-
|
|
116
|
+
const exitStatus = value.exitCode ?? value.exit_code;
|
|
117
|
+
const failed = result instanceof Error || value.success === false || value.ok === false || value.isError === true || value.requiresConsent === true || value.requiresApproval === true || value.authenticationRequired === true || (typeof value.error === 'string' && value.error.trim().length > 0)
|
|
118
|
+
|| (typeof exitStatus === 'number' && (!Number.isFinite(exitStatus) || exitStatus !== 0))
|
|
119
|
+
|| value.failureKind === 'site_refusal' || value.status === 'error' || value.status === 'failed'
|
|
120
|
+
|| (typeof value.status === 'number' && (!Number.isFinite(value.status) || value.status >= 400))
|
|
121
|
+
|| (value.error !== null && typeof value.error === 'object');
|
|
122
|
+
const classification = failed ? (value.status === 429 ? 'rate_limited' : value.status === 401 ? 'permission' : failureClass(value) || 'failed') : '';
|
|
123
|
+
const key = issueKey(tool, safeArgs);
|
|
104
124
|
const good = lastGoodTool(outcomes);
|
|
105
125
|
if (!failed) {
|
|
106
126
|
// A successful check only clears its own failure family. A successful
|
|
@@ -116,14 +136,15 @@ export class TimeMachine {
|
|
|
116
136
|
issueKey: '',
|
|
117
137
|
lastGoodTool: good,
|
|
118
138
|
guidance: hadFailure
|
|
119
|
-
? isVerificationCommand(
|
|
139
|
+
? isVerificationCommand(commandText(safeArgs))
|
|
120
140
|
? 'The same verification command now passed. Report that check as evidence; assess the rest of the task separately.'
|
|
121
141
|
: 'This tool call succeeded. Verify the intended task outcome before reporting success.'
|
|
122
142
|
: ''
|
|
123
143
|
};
|
|
124
144
|
}
|
|
125
145
|
const error = typeof value.error === 'string' ? value.error : '';
|
|
126
|
-
const needsHuman =
|
|
146
|
+
const needsHuman = value.failureKind !== 'site_refusal'
|
|
147
|
+
&& (classification === 'permission' || value.requiresConsent === true || value.requiresApproval === true || value.authenticationRequired === true || /user denied|approval required|authentication required/i.test(error));
|
|
127
148
|
const attempt = Math.min(TIME_MACHINE_MAX_ATTEMPTS, (this.failures.get(key) || 0) + 1);
|
|
128
149
|
this.failures.set(key, attempt);
|
|
129
150
|
const checkpoint = good ? ` Last successful tool: ${good}.` : '';
|
|
@@ -135,7 +156,7 @@ export class TimeMachine {
|
|
|
135
156
|
if (attempt >= TIME_MACHINE_MAX_ATTEMPTS) {
|
|
136
157
|
return { kind: 'stop', attempt, maxAttempts: TIME_MACHINE_MAX_ATTEMPTS, issueKey: key,
|
|
137
158
|
failureClass: classification, lastGoodTool: good,
|
|
138
|
-
guidance: `The same
|
|
159
|
+
guidance: `The same operation failed through ${TIME_MACHINE_MAX_ATTEMPTS} attempts. Stop this task. Give a brief evidence-based report, state what remains unresolved, and ask for input only if needed. Put a detailed report in a Markdown file only if the user requests one.${checkpoint}` };
|
|
139
160
|
}
|
|
140
161
|
// The agent may spend three attempts alone. The fourth through sixth belong
|
|
141
162
|
// to the user: without an explicit grant the budget ends here.
|
|
@@ -149,7 +170,7 @@ export class TimeMachine {
|
|
|
149
170
|
failureClass: classification, lastGoodTool: good,
|
|
150
171
|
guidance: `Further attempts were not approved. Stop this task. Give a brief evidence-based report and state what remains unresolved.${checkpoint}` };
|
|
151
172
|
}
|
|
152
|
-
if (classification === 'rate_limited' && attempt <
|
|
173
|
+
if (classification === 'rate_limited' && attempt < TIME_MACHINE_MAX_ATTEMPTS) {
|
|
153
174
|
return { kind: 'replan', attempt, maxAttempts: TIME_MACHINE_MAX_ATTEMPTS, issueKey: key,
|
|
154
175
|
failureClass: classification, lastGoodTool: good,
|
|
155
176
|
guidance: `Rate limit reached. Respect the provider's retry/reset window; do not immediately resend the same request.${checkpoint}` };
|
package/src/timeMachine.ts
CHANGED
|
@@ -30,7 +30,8 @@ export function recoveryUserMessage(decision: RecoveryDecision, tool: string): s
|
|
|
30
30
|
if (decision.kind === 'human') {
|
|
31
31
|
return `${tool} needs approval or authentication. Review the last tool error, then provide the needed access or choose another route. No success is claimed.`;
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
// A stop before the hard maximum only happens when further attempts were not approved.
|
|
34
|
+
if (decision.attempt < TIME_MACHINE_MAX_ATTEMPTS && decision.kind === 'stop') {
|
|
34
35
|
return `${tool} failed ${decision.attempt} times (${decision.failureClass}) and more attempts were not approved. The task stopped without verified success.`;
|
|
35
36
|
}
|
|
36
37
|
return `${tool} still failed after ${decision.attempt} attempts (${decision.failureClass}). The task stopped without verified success.`;
|
|
@@ -41,32 +42,48 @@ function record(value: unknown): Record<string, unknown> {
|
|
|
41
42
|
? value as Record<string, unknown> : {};
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
function firstText(values: readonly unknown[]): string {
|
|
46
|
+
return values.find((value): value is string => typeof value === 'string' && value.trim().length > 0) ?? '';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function commandText(args: Record<string, unknown>): string {
|
|
50
|
+
return firstText([args.command, args.cmd, args.CommandLine, args.commandLine, args.script]);
|
|
51
|
+
}
|
|
52
|
+
|
|
44
53
|
function operationFamily(args: Record<string, unknown>): string {
|
|
45
|
-
const command =
|
|
46
|
-
: typeof args.cmd === 'string' ? args.cmd
|
|
47
|
-
: typeof args.CommandLine === 'string' ? args.CommandLine
|
|
48
|
-
: typeof args.commandLine === 'string' ? args.commandLine
|
|
49
|
-
: typeof args.script === 'string' ? args.script : '';
|
|
54
|
+
const command = commandText(args);
|
|
50
55
|
if (!command) {
|
|
51
|
-
const endpoint =
|
|
56
|
+
const endpoint = firstText([args.url, args.endpoint]);
|
|
52
57
|
if (endpoint) {
|
|
53
58
|
try { return new URL(endpoint).hostname.toLowerCase(); } catch { return ''; }
|
|
54
59
|
}
|
|
55
60
|
return '';
|
|
56
61
|
}
|
|
57
|
-
const
|
|
62
|
+
const tokens = command.trim().split(/\s+/);
|
|
63
|
+
// Leading VAR=value assignments do not change which operation is retried, so
|
|
64
|
+
// `CI=1 npm test` must share the retry budget of `npm test`.
|
|
65
|
+
while (tokens.length > 1 && /^[A-Za-z_][A-Za-z0-9_]*=/.test(tokens[0] || '')) tokens.shift();
|
|
66
|
+
const words = tokens.slice(0, 3);
|
|
67
|
+
// Windows shims (`npm.cmd`, `bun.exe`) are the same tools as their bare names.
|
|
68
|
+
const executable = (words[0] || '').replace(/^.*[\\/]/, '').replace(/\.(cmd|exe|bat|ps1)$/i, '').toLowerCase();
|
|
58
69
|
// Keep common verification commands distinct without retaining paths,
|
|
59
70
|
// source text, environment variables, or credentials in the journal.
|
|
60
|
-
if (/^(npm|pnpm|yarn|bun)$/.test(
|
|
61
|
-
|
|
71
|
+
if (/^(npm|pnpm|yarn|bun)$/.test(executable)) {
|
|
72
|
+
// Script names are case-sensitive; a passing `build` cannot resolve `Build`.
|
|
73
|
+
return [executable, ...words.slice(1, words[1] === 'run' ? 3 : 2)].join(' ');
|
|
74
|
+
}
|
|
75
|
+
if (/^(git|gh|docker|podman|kubectl)$/.test(executable)) {
|
|
76
|
+
// Distinct subcommands must have distinct recovery histories: a passing
|
|
77
|
+
// git status is not evidence that an earlier git push succeeded.
|
|
78
|
+
return [executable, (words[1] || '').toLowerCase().slice(0, 32)].filter(Boolean).join(' ');
|
|
62
79
|
}
|
|
63
|
-
return
|
|
80
|
+
return executable.slice(0, 32);
|
|
64
81
|
}
|
|
65
82
|
|
|
66
83
|
function issueKey(tool: string, args: Record<string, unknown>): string {
|
|
67
84
|
const family = operationFamily(args);
|
|
68
|
-
const target =
|
|
69
|
-
const workspace = String(args.cwd ?? '');
|
|
85
|
+
const target = firstText([args.path, args.file_path, args.filePath, args.target, args.endpoint, args.url]);
|
|
86
|
+
const workspace = String(args.cwd ?? args.workingDirectory ?? args.workingDir ?? args.workspaceRoot ?? '');
|
|
70
87
|
// Changing error text/class does not buy another three attempts at the same
|
|
71
88
|
// operation. Targets are hashed and never included in recovery messages.
|
|
72
89
|
return createHash('sha256').update(`${tool}\0${family}\0${target}\0${workspace}`).digest('hex');
|
|
@@ -116,12 +133,16 @@ export class TimeMachine {
|
|
|
116
133
|
|
|
117
134
|
observe(tool: string, args: Record<string, unknown>, result: unknown,
|
|
118
135
|
outcomes: readonly ToolOutcome[] = []): RecoveryDecision {
|
|
136
|
+
const safeArgs = record(args);
|
|
119
137
|
const value = record(result);
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
||
|
|
123
|
-
|
|
124
|
-
|
|
138
|
+
const exitStatus = value.exitCode ?? value.exit_code;
|
|
139
|
+
const failed = result instanceof Error || value.success === false || value.ok === false || value.isError === true || value.requiresConsent === true || value.requiresApproval === true || value.authenticationRequired === true || (typeof value.error === 'string' && value.error.trim().length > 0)
|
|
140
|
+
|| (typeof exitStatus === 'number' && (!Number.isFinite(exitStatus) || exitStatus !== 0))
|
|
141
|
+
|| value.failureKind === 'site_refusal' || value.status === 'error' || value.status === 'failed'
|
|
142
|
+
|| (typeof value.status === 'number' && (!Number.isFinite(value.status) || value.status >= 400))
|
|
143
|
+
|| (value.error !== null && typeof value.error === 'object');
|
|
144
|
+
const classification = failed ? (value.status === 429 ? 'rate_limited' : value.status === 401 ? 'permission' : failureClass(value) || 'failed') : '';
|
|
145
|
+
const key = issueKey(tool, safeArgs);
|
|
125
146
|
const good = lastGoodTool(outcomes);
|
|
126
147
|
|
|
127
148
|
if (!failed) {
|
|
@@ -138,7 +159,7 @@ export class TimeMachine {
|
|
|
138
159
|
issueKey: '',
|
|
139
160
|
lastGoodTool: good,
|
|
140
161
|
guidance: hadFailure
|
|
141
|
-
? isVerificationCommand(
|
|
162
|
+
? isVerificationCommand(commandText(safeArgs))
|
|
142
163
|
? 'The same verification command now passed. Report that check as evidence; assess the rest of the task separately.'
|
|
143
164
|
: 'This tool call succeeded. Verify the intended task outcome before reporting success.'
|
|
144
165
|
: ''
|
|
@@ -146,7 +167,8 @@ export class TimeMachine {
|
|
|
146
167
|
}
|
|
147
168
|
|
|
148
169
|
const error = typeof value.error === 'string' ? value.error : '';
|
|
149
|
-
const needsHuman =
|
|
170
|
+
const needsHuman = value.failureKind !== 'site_refusal'
|
|
171
|
+
&& (classification === 'permission' || value.requiresConsent === true || value.requiresApproval === true || value.authenticationRequired === true || /user denied|approval required|authentication required/i.test(error));
|
|
150
172
|
const attempt = Math.min(TIME_MACHINE_MAX_ATTEMPTS, (this.failures.get(key) || 0) + 1);
|
|
151
173
|
this.failures.set(key, attempt);
|
|
152
174
|
const checkpoint = good ? ` Last successful tool: ${good}.` : '';
|
|
@@ -160,7 +182,7 @@ export class TimeMachine {
|
|
|
160
182
|
if (attempt >= TIME_MACHINE_MAX_ATTEMPTS) {
|
|
161
183
|
return { kind: 'stop', attempt, maxAttempts: TIME_MACHINE_MAX_ATTEMPTS, issueKey: key,
|
|
162
184
|
failureClass: classification, lastGoodTool: good,
|
|
163
|
-
guidance: `The same
|
|
185
|
+
guidance: `The same operation failed through ${TIME_MACHINE_MAX_ATTEMPTS} attempts. Stop this task. Give a brief evidence-based report, state what remains unresolved, and ask for input only if needed. Put a detailed report in a Markdown file only if the user requests one.${checkpoint}` };
|
|
164
186
|
}
|
|
165
187
|
// The agent may spend three attempts alone. The fourth through sixth belong
|
|
166
188
|
// to the user: without an explicit grant the budget ends here.
|
|
@@ -174,7 +196,7 @@ export class TimeMachine {
|
|
|
174
196
|
failureClass: classification, lastGoodTool: good,
|
|
175
197
|
guidance: `Further attempts were not approved. Stop this task. Give a brief evidence-based report and state what remains unresolved.${checkpoint}` };
|
|
176
198
|
}
|
|
177
|
-
if (classification === 'rate_limited' && attempt <
|
|
199
|
+
if (classification === 'rate_limited' && attempt < TIME_MACHINE_MAX_ATTEMPTS) {
|
|
178
200
|
return { kind: 'replan', attempt, maxAttempts: TIME_MACHINE_MAX_ATTEMPTS, issueKey: key,
|
|
179
201
|
failureClass: classification, lastGoodTool: good,
|
|
180
202
|
guidance: `Rate limit reached. Respect the provider's retry/reset window; do not immediately resend the same request.${checkpoint}` };
|
|
@@ -34,6 +34,7 @@ on run argv
|
|
|
34
34
|
set report to report & "ok|press|" & elemName & linefeed
|
|
35
35
|
else
|
|
36
36
|
set report to report & "miss|press|" & elemName & linefeed
|
|
37
|
+
exit repeat -- Never type/click elsewhere after a required target is missing.
|
|
37
38
|
end if
|
|
38
39
|
else if verb is "clickxy" then
|
|
39
40
|
set px to (item 2 of parts) as integer
|
package/src/toolPacks.js
CHANGED
|
@@ -335,7 +335,9 @@ const WEB_INTENT = /\b(web|webpage|website|frontend|front-end|landing page|homep
|
|
|
335
335
|
const MEDIA_INTENT = /\b(image|images|picture|photo|photoshop|premiere|after\s*effects|illustrator|indesign|media\s*encoder|uxp|render|3d model|blender|animation|animate|video|movie|film|audio|sound|sfx|music|song|voice|tts|text.to.speech|narration|podcast|thumbnail|poster|illustration|logo)\b|\.(psd|prproj|aep|ai|indd|ccx)\b/i;
|
|
336
336
|
const SYSTEM_INTENT = /\b(process|processes|pid|kill|port|zip|unzip|tar|archive|compress|extract|clipboard|copy to clipboard|print|printer|open in browser|launch app|computer use|vision grounding|desktop vision|gui agent|coordinate click|desktop control)\b/i;
|
|
337
337
|
const ADVANCED_INTENT = /\b(pdf|document|proposal|screenplay|shotlist|shot list|voiceover|dubbing|forge a tool|custom tool|new tool|plugin|plugins|custom plugin|plugins? factory|python bridge|mcp|mcp server|subagent|sub-agent|parallel agent|swarm|ast|symbols|refactor across)\b/i;
|
|
338
|
-
const REVERSE_ENGINEERING_INTENT = /\b(rea|rea-agents|decompile|decompiling|decompilation|disassemble|disassembly|disassembling|binary|binaries|
|
|
338
|
+
const REVERSE_ENGINEERING_INTENT = /\b(rea|rea-agents|decompile|decompiling|decompilation|disassemble|disassembly|disassembling|disasm|binary|binaries|elf binary|mach-o|portable executable|coff|reverse[\s_-]?engineer(ing)?|sourcemap|deobfuscate|ghidra|rizin|radare|jadx|apktool|hopper|frida|hook script|mitigations|clean[- ]?room)\b|\.(dylib|so|dll|exe|wasm|asar)\b/i;
|
|
339
|
+
const RE_BUNDLE_TARGET = /(?:\b(?:apk|aab|dex|asar)\b|\.(?:apk|aab|dex)\b)/i;
|
|
340
|
+
const RE_INSPECTION_VERB = /\b(?:inspect|analyze|analyse|examine|unpack|extract|dump|audit|reconstruct|decode|parse|strings)\b|what(?:'s| is) inside/i;
|
|
339
341
|
const INTENT_MATCHERS = {
|
|
340
342
|
game: GAME_INTENT,
|
|
341
343
|
web: WEB_INTENT,
|
|
@@ -344,6 +346,13 @@ const INTENT_MATCHERS = {
|
|
|
344
346
|
advanced: ADVANCED_INTENT,
|
|
345
347
|
reverse_engineering: REVERSE_ENGINEERING_INTENT
|
|
346
348
|
};
|
|
349
|
+
/** True when the prompt genuinely asks for reverse engineering or binary inspection rather than building/exporting our own APK/AAB. */
|
|
350
|
+
export function isReverseEngineeringIntent(prompt) {
|
|
351
|
+
const value = prompt || '';
|
|
352
|
+
if (REVERSE_ENGINEERING_INTENT.test(value))
|
|
353
|
+
return true;
|
|
354
|
+
return RE_BUNDLE_TARGET.test(value) && RE_INSPECTION_VERB.test(value);
|
|
355
|
+
}
|
|
347
356
|
/** True when the prompt genuinely describes game development work. */
|
|
348
357
|
export function isGameIntent(prompt) {
|
|
349
358
|
return GAME_INTENT.test(prompt || '');
|
|
@@ -366,27 +375,40 @@ export function routePacks(prompt, workspaceContext = null) {
|
|
|
366
375
|
const unlocked = new Set();
|
|
367
376
|
const text = prompt || '';
|
|
368
377
|
for (const packName of PACK_NAMES) {
|
|
369
|
-
|
|
378
|
+
const matched = packName === 'reverse_engineering'
|
|
379
|
+
? isReverseEngineeringIntent(text)
|
|
380
|
+
: INTENT_MATCHERS[packName].test(text);
|
|
381
|
+
if (matched) {
|
|
370
382
|
unlocked.add(packName);
|
|
371
383
|
}
|
|
372
384
|
}
|
|
385
|
+
// Greetings and pure non-actionable prompts must not preload heavy workspace packs.
|
|
386
|
+
const trimmed = text.trim();
|
|
387
|
+
const isGreeting = /^(?:hi|hello|hey|yo|halo|hai|p|good\s+(?:morning|afternoon|evening))[.!?, ]*$/i.test(trimmed);
|
|
388
|
+
const explicitNonWebTarget = /\b(?:aab|apk|gradle|bundleRelease|android|godot|\.gd\b|rust|cargo|xcode|ipa)\b/i.test(trimmed)
|
|
389
|
+
&& !isWebIntent(trimmed);
|
|
373
390
|
// Workspace signals. A Godot project on disk is far more reliable evidence of
|
|
374
391
|
// game work than any keyword, and a detected web framework means the agent
|
|
375
392
|
// will eventually need to look at what it built.
|
|
376
|
-
if (workspaceContext) {
|
|
393
|
+
if (workspaceContext && !isGreeting) {
|
|
377
394
|
const signals = [
|
|
378
395
|
workspaceContext.framework,
|
|
379
396
|
workspaceContext.projectType,
|
|
380
397
|
workspaceContext.designSystem,
|
|
398
|
+
Array.isArray(workspaceContext.subprojectStacks) ? workspaceContext.subprojectStacks.join(' ') : '',
|
|
381
399
|
Array.isArray(workspaceContext.keyFiles) ? workspaceContext.keyFiles.join(' ') : ''
|
|
382
400
|
]
|
|
383
401
|
.filter(Boolean)
|
|
384
402
|
.join(' ')
|
|
385
403
|
.toLowerCase();
|
|
386
|
-
|
|
404
|
+
const hasGameProject = /godot|project\.godot|unity|\.tscn/.test(signals);
|
|
405
|
+
const hasFrontendFramework = /react|vue|svelte|next|nuxt|astro|angular|tailwind|vite/.test(signals);
|
|
406
|
+
const hasHtmlEntry = /\bhtml\b/.test(signals);
|
|
407
|
+
if (hasGameProject)
|
|
387
408
|
unlocked.add('game');
|
|
388
|
-
if (
|
|
409
|
+
if (hasFrontendFramework || (hasHtmlEntry && !hasGameProject && !explicitNonWebTarget)) {
|
|
389
410
|
unlocked.add('web');
|
|
411
|
+
}
|
|
390
412
|
}
|
|
391
413
|
return [...unlocked];
|
|
392
414
|
}
|
package/src/toolPacks.ts
CHANGED
|
@@ -24,6 +24,7 @@ export interface WorkspaceRoutingContext {
|
|
|
24
24
|
projectType?: string | null | undefined;
|
|
25
25
|
designSystem?: string | null | undefined;
|
|
26
26
|
keyFiles?: string[] | null | undefined;
|
|
27
|
+
subprojectStacks?: string[] | null | undefined;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
export interface ToolDefinitionLike {
|
|
@@ -380,7 +381,10 @@ const SYSTEM_INTENT = /\b(process|processes|pid|kill|port|zip|unzip|tar|archive|
|
|
|
380
381
|
|
|
381
382
|
const ADVANCED_INTENT = /\b(pdf|document|proposal|screenplay|shotlist|shot list|voiceover|dubbing|forge a tool|custom tool|new tool|plugin|plugins|custom plugin|plugins? factory|python bridge|mcp|mcp server|subagent|sub-agent|parallel agent|swarm|ast|symbols|refactor across)\b/i;
|
|
382
383
|
|
|
383
|
-
const REVERSE_ENGINEERING_INTENT = /\b(rea|rea-agents|decompile|decompiling|decompilation|disassemble|disassembly|disassembling|binary|binaries|
|
|
384
|
+
const REVERSE_ENGINEERING_INTENT = /\b(rea|rea-agents|decompile|decompiling|decompilation|disassemble|disassembly|disassembling|disasm|binary|binaries|elf binary|mach-o|portable executable|coff|reverse[\s_-]?engineer(ing)?|sourcemap|deobfuscate|ghidra|rizin|radare|jadx|apktool|hopper|frida|hook script|mitigations|clean[- ]?room)\b|\.(dylib|so|dll|exe|wasm|asar)\b/i;
|
|
385
|
+
|
|
386
|
+
const RE_BUNDLE_TARGET = /(?:\b(?:apk|aab|dex|asar)\b|\.(?:apk|aab|dex)\b)/i;
|
|
387
|
+
const RE_INSPECTION_VERB = /\b(?:inspect|analyze|analyse|examine|unpack|extract|dump|audit|reconstruct|decode|parse|strings)\b|what(?:'s| is) inside/i;
|
|
384
388
|
|
|
385
389
|
const INTENT_MATCHERS: Record<PackName, RegExp> = {
|
|
386
390
|
game: GAME_INTENT,
|
|
@@ -391,6 +395,13 @@ const INTENT_MATCHERS: Record<PackName, RegExp> = {
|
|
|
391
395
|
reverse_engineering: REVERSE_ENGINEERING_INTENT
|
|
392
396
|
};
|
|
393
397
|
|
|
398
|
+
/** True when the prompt genuinely asks for reverse engineering or binary inspection rather than building/exporting our own APK/AAB. */
|
|
399
|
+
export function isReverseEngineeringIntent(prompt?: string | null): boolean {
|
|
400
|
+
const value = prompt || '';
|
|
401
|
+
if (REVERSE_ENGINEERING_INTENT.test(value)) return true;
|
|
402
|
+
return RE_BUNDLE_TARGET.test(value) && RE_INSPECTION_VERB.test(value);
|
|
403
|
+
}
|
|
404
|
+
|
|
394
405
|
/** True when the prompt genuinely describes game development work. */
|
|
395
406
|
export function isGameIntent(prompt?: string | null): boolean {
|
|
396
407
|
return GAME_INTENT.test(prompt || '');
|
|
@@ -418,27 +429,43 @@ export function routePacks(
|
|
|
418
429
|
const text = prompt || '';
|
|
419
430
|
|
|
420
431
|
for (const packName of PACK_NAMES) {
|
|
421
|
-
|
|
432
|
+
const matched = packName === 'reverse_engineering'
|
|
433
|
+
? isReverseEngineeringIntent(text)
|
|
434
|
+
: INTENT_MATCHERS[packName].test(text);
|
|
435
|
+
if (matched) {
|
|
422
436
|
unlocked.add(packName);
|
|
423
437
|
}
|
|
424
438
|
}
|
|
425
439
|
|
|
440
|
+
// Greetings and pure non-actionable prompts must not preload heavy workspace packs.
|
|
441
|
+
const trimmed = text.trim();
|
|
442
|
+
const isGreeting = /^(?:hi|hello|hey|yo|halo|hai|p|good\s+(?:morning|afternoon|evening))[.!?, ]*$/i.test(trimmed);
|
|
443
|
+
const explicitNonWebTarget = /\b(?:aab|apk|gradle|bundleRelease|android|godot|\.gd\b|rust|cargo|xcode|ipa)\b/i.test(trimmed)
|
|
444
|
+
&& !isWebIntent(trimmed);
|
|
445
|
+
|
|
426
446
|
// Workspace signals. A Godot project on disk is far more reliable evidence of
|
|
427
447
|
// game work than any keyword, and a detected web framework means the agent
|
|
428
448
|
// will eventually need to look at what it built.
|
|
429
|
-
if (workspaceContext) {
|
|
449
|
+
if (workspaceContext && !isGreeting) {
|
|
430
450
|
const signals = [
|
|
431
451
|
workspaceContext.framework,
|
|
432
452
|
workspaceContext.projectType,
|
|
433
453
|
workspaceContext.designSystem,
|
|
454
|
+
Array.isArray(workspaceContext.subprojectStacks) ? workspaceContext.subprojectStacks.join(' ') : '',
|
|
434
455
|
Array.isArray(workspaceContext.keyFiles) ? workspaceContext.keyFiles.join(' ') : ''
|
|
435
456
|
]
|
|
436
457
|
.filter(Boolean)
|
|
437
458
|
.join(' ')
|
|
438
459
|
.toLowerCase();
|
|
439
460
|
|
|
440
|
-
|
|
441
|
-
|
|
461
|
+
const hasGameProject = /godot|project\.godot|unity|\.tscn/.test(signals);
|
|
462
|
+
const hasFrontendFramework = /react|vue|svelte|next|nuxt|astro|angular|tailwind|vite/.test(signals);
|
|
463
|
+
const hasHtmlEntry = /\bhtml\b/.test(signals);
|
|
464
|
+
|
|
465
|
+
if (hasGameProject) unlocked.add('game');
|
|
466
|
+
if (hasFrontendFramework || (hasHtmlEntry && !hasGameProject && !explicitNonWebTarget)) {
|
|
467
|
+
unlocked.add('web');
|
|
468
|
+
}
|
|
442
469
|
}
|
|
443
470
|
|
|
444
471
|
return [...unlocked];
|
package/src/tools/computerUse.js
CHANGED
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
import { parseVisionGroundingPrediction, visionGroundingToDesktopAct, groundBoxCenter } from '../computerUse/visionGrounding.js';
|
|
8
8
|
import { desktopAct } from './desktopAct.js';
|
|
9
9
|
import { auditLog } from '../auditLog.js';
|
|
10
|
+
function hasValidCoordinates(value) {
|
|
11
|
+
return Array.isArray(value) && (value.length === 2 || value.length === 4)
|
|
12
|
+
&& value.every(coord => typeof coord === 'number' && Number.isFinite(coord));
|
|
13
|
+
}
|
|
10
14
|
export const computerUse = {
|
|
11
15
|
schema: {
|
|
12
16
|
name: 'computer_use',
|
|
@@ -76,38 +80,47 @@ export const computerUse = {
|
|
|
76
80
|
// Mode 2: Direct action request
|
|
77
81
|
const actionType = args.action || 'click';
|
|
78
82
|
if (actionType === 'click') {
|
|
79
|
-
const coords = args.coordinates
|
|
83
|
+
const coords = args.coordinates;
|
|
84
|
+
if (!hasValidCoordinates(coords))
|
|
85
|
+
return { success: false, error: 'Click requires finite coordinates [x, y] or [x1, y1, x2, y2].' };
|
|
80
86
|
const point = groundBoxCenter(coords, screen);
|
|
81
|
-
if (!point)
|
|
82
|
-
return { success: false, error: 'Click
|
|
87
|
+
if (!point || !Number.isFinite(point.x) || !Number.isFinite(point.y))
|
|
88
|
+
return { success: false, error: 'Click coordinates are outside the supported screen context.' };
|
|
83
89
|
desktopActions.push({ verb: 'clickxy', x: point.x, y: point.y });
|
|
84
90
|
}
|
|
85
91
|
else if (actionType === 'type') {
|
|
86
|
-
if (args.coordinates
|
|
92
|
+
if (args.coordinates !== undefined) {
|
|
93
|
+
if (!hasValidCoordinates(args.coordinates))
|
|
94
|
+
return { success: false, error: 'Type target requires finite coordinates [x, y] or [x1, y1, x2, y2].' };
|
|
87
95
|
const point = groundBoxCenter(args.coordinates, screen);
|
|
88
|
-
if (point)
|
|
89
|
-
|
|
96
|
+
if (!point || !Number.isFinite(point.x) || !Number.isFinite(point.y))
|
|
97
|
+
return { success: false, error: 'Type target coordinates are outside the supported screen context.' };
|
|
98
|
+
desktopActions.push({ verb: 'clickxy', x: point.x, y: point.y });
|
|
90
99
|
}
|
|
91
100
|
if (!args.text)
|
|
92
101
|
return { success: false, error: 'Type action requires "text" parameter.' };
|
|
93
102
|
desktopActions.push({ verb: 'type', text: args.text });
|
|
94
103
|
}
|
|
95
104
|
else if (actionType === 'key') {
|
|
96
|
-
|
|
105
|
+
const keyName = typeof args.key === 'string' ? args.key.trim() : '';
|
|
106
|
+
if (!keyName)
|
|
97
107
|
return { success: false, error: 'Key action requires "key" parameter.' };
|
|
98
108
|
const keyMap = {
|
|
99
109
|
return: 36, enter: 36, tab: 48, space: 49, backspace: 51, escape: 53, esc: 53
|
|
100
110
|
};
|
|
101
|
-
const keyCode = keyMap[
|
|
111
|
+
const keyCode = keyMap[keyName.toLowerCase()];
|
|
102
112
|
if (keyCode !== undefined) {
|
|
103
113
|
desktopActions.push({ verb: 'key', keyCode });
|
|
104
114
|
}
|
|
115
|
+
else if (/^[a-z0-9]$/i.test(keyName)) {
|
|
116
|
+
desktopActions.push({ verb: 'type', text: keyName });
|
|
117
|
+
}
|
|
105
118
|
else {
|
|
106
|
-
|
|
119
|
+
return { success: false, error: 'Unsupported key name or chord. Use action "type" for text; compound hotkeys require supported key actuation.' };
|
|
107
120
|
}
|
|
108
121
|
}
|
|
109
122
|
else if (actionType === 'wait') {
|
|
110
|
-
desktopActions.push({ verb: 'wait', seconds: Math.min(10, Math.max(0.1, args.seconds
|
|
123
|
+
desktopActions.push({ verb: 'wait', seconds: Math.min(10, Math.max(0.1, Number.isFinite(args.seconds) ? args.seconds : 1)) });
|
|
111
124
|
}
|
|
112
125
|
else {
|
|
113
126
|
return { success: false, error: `Unsupported computer_use action: ${actionType}` };
|