@causyne/agent 1.20.91 → 1.20.94
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 +116 -26
- package/src/agentLoop.ts +121 -26
- package/src/contextManager.js +2 -0
- package/src/decideTools.js +9 -0
- package/src/decideTools.ts +9 -0
- package/src/decisionPolicy.js +119 -1
- package/src/decisionPolicy.ts +129 -1
- package/src/historyPruner.js +16 -1
- package/src/historyPruner.ts +13 -1
- package/src/sandbox.js +33 -7
- package/src/skills/skillResourceSafety.js +70 -0
- package/src/skills/skillResourceSafety.ts +77 -0
- package/src/smartToolsUse.js +28 -11
- package/src/smartToolsUse.ts +34 -11
- package/src/taskShape.js +28 -13
- package/src/taskShape.ts +31 -12
- package/src/tools/codeSearcher.js +349 -210
- package/src/tools/codeSearcher.ts +408 -0
- package/src/tools/codebaseSearch.js +182 -68
- package/src/tools/codebaseSearch.ts +221 -0
- package/src/tools/deferredMcpSearch.js +94 -40
- package/src/tools/deferredMcpSearch.ts +89 -30
- package/src/tools/fsFind.js +180 -115
- package/src/tools/fsFind.ts +228 -0
- package/src/tools/fsList.js +149 -69
- package/src/tools/fsList.ts +224 -0
- package/src/tools/fsSearch.js +192 -189
- package/src/tools/fsSearch.ts +241 -0
- package/src/tools/readNativeSkill.js +34 -42
- package/src/tools/readNativeSkill.ts +38 -36
- package/src/tools/searchRelevance.js +70 -0
- package/src/tools/searchRelevance.ts +72 -0
- package/src/tools/toolSelfRepair.js +56 -20
- package/src/tools/toolSelfRepair.ts +58 -19
- package/src/tools/walkerSafety.js +445 -0
- package/src/tools/walkerSafety.ts +516 -0
- package/src/tui/composerGeometry.js +45 -0
- package/src/tui/composerGeometry.ts +80 -0
- package/src/tui/homeView.js +10 -6
- package/src/tui/homeView.ts +10 -6
- package/src/tui/lineEditor.js +8 -0
- package/src/tui/prompt.js +9 -4
- package/src/userSkills.js +183 -203
- package/src/userSkills.ts +301 -0
- package/src/userSkills.d.ts +0 -26
package/package.json
CHANGED
package/src/agentLoop.js
CHANGED
|
@@ -53,7 +53,7 @@ import { resolveCharPool, measureMessages, resultCapFor, decayToolResults, build
|
|
|
53
53
|
// Provider imports
|
|
54
54
|
import { detectWorkspaceDomains, ensureSkillRepo, getSkillDomainHeader } from './skillsManager.js';
|
|
55
55
|
import { spillToolResult, buildDecayPointer, pruneOutputStore } from './outputStore.js';
|
|
56
|
-
import { defaultToolOutputStore, processToolOutputWithStore, renderSpillDocument } from './tools/toolOutputStore.js';
|
|
56
|
+
import { ToolOutputStore, defaultToolOutputStore, processToolOutputWithStore, renderSpillDocument } from './tools/toolOutputStore.js';
|
|
57
57
|
import { beginTask as beginCheckpointTask, captureBeforeMutation, pruneStore as pruneCheckpointStore, resolveProjectRoot } from './checkpoints.js';
|
|
58
58
|
import fsSync from 'fs';
|
|
59
59
|
import os from 'os';
|
|
@@ -129,6 +129,60 @@ export function isCodeAuthoringTaskPrompt(text) {
|
|
|
129
129
|
return false;
|
|
130
130
|
return /\b(create|build|make|write|code|implement|generate|game|3js|three?\.?js|three?js|app)\b/i.test(t);
|
|
131
131
|
}
|
|
132
|
+
export function extractSkillIdFromPrompt(prompt) {
|
|
133
|
+
const text = String(prompt || '').trim();
|
|
134
|
+
if (!text)
|
|
135
|
+
return '';
|
|
136
|
+
const stopWords = new Set([
|
|
137
|
+
'the', 'a', 'an', 'this', 'that', 'from', 'in', 'with',
|
|
138
|
+
'using', 'for', 'to', 'by', 'and', 'or', 'of'
|
|
139
|
+
]);
|
|
140
|
+
const leadingTrim = new Set(['`', '"', "'", '(', '[']);
|
|
141
|
+
const trailingTrim = new Set(['`', '"', "'", ')', ',', '.', ';', ':', '!', '?', ']', '\\']);
|
|
142
|
+
const cleanCandidate = (raw) => {
|
|
143
|
+
const trimmed = raw.trim();
|
|
144
|
+
let start = 0;
|
|
145
|
+
let end = trimmed.length;
|
|
146
|
+
while (start < end && leadingTrim.has(trimmed[start]))
|
|
147
|
+
start++;
|
|
148
|
+
while (end > start && trailingTrim.has(trimmed[end - 1]))
|
|
149
|
+
end--;
|
|
150
|
+
const stripped = trimmed.slice(start, end);
|
|
151
|
+
if (!stripped || stopWords.has(stripped.toLowerCase()))
|
|
152
|
+
return '';
|
|
153
|
+
if (/^(?:fs_read_skill|fs_read_skil|read_skill|read_skil|tool_search)$/i.test(stripped)) {
|
|
154
|
+
return '';
|
|
155
|
+
}
|
|
156
|
+
return stripped;
|
|
157
|
+
};
|
|
158
|
+
const isFileExt = (candidate) => /\.(?:ts|tsx|js|jsx|mjs|cjs|py|go|rs|java|kt|json|html|css|gradle|apk|aab|dex)$/i.test(candidate);
|
|
159
|
+
const cuedSlashMatch = text.match(/(?:\bskill_id|\bskill|\bfs_read_skil{1,2})(?:\s*[:=]\s*|\s+)[`"']?([a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}\/[a-zA-Z0-9][a-zA-Z0-9_.-]{0,120})[`"']?/i);
|
|
160
|
+
if (cuedSlashMatch?.[1]) {
|
|
161
|
+
const candidate = cleanCandidate(cuedSlashMatch[1]);
|
|
162
|
+
if (candidate && !isFileExt(candidate)) {
|
|
163
|
+
return candidate;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
for (const m of text.matchAll(/\b([a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}\/[a-zA-Z0-9][a-zA-Z0-9_.-]{0,120})\b/g)) {
|
|
167
|
+
const candidate = cleanCandidate(m[1] || '');
|
|
168
|
+
if (candidate && !isFileExt(candidate)) {
|
|
169
|
+
return candidate;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const explicitQuotedMatch = text.match(/(?:\bskill_id|\bskill)(?:\s*[:=]\s*|\s+)(?:the\s+)?[`"']([^`"'\n\r]{2,120})[`"']/i);
|
|
173
|
+
if (explicitQuotedMatch?.[1]) {
|
|
174
|
+
const candidate = cleanCandidate(explicitQuotedMatch[1]);
|
|
175
|
+
if (candidate)
|
|
176
|
+
return candidate;
|
|
177
|
+
}
|
|
178
|
+
const bareMatch = text.match(/(?:\bskill_id\s*[:=]\s*|\bskill\s*[:=]\s*|\bskill\s+(?:called\s+|named\s+)?)([a-zA-Z0-9][a-zA-Z0-9_.-]{1,120})/i);
|
|
179
|
+
if (bareMatch?.[1]) {
|
|
180
|
+
const candidate = cleanCandidate(bareMatch[1]);
|
|
181
|
+
if (candidate)
|
|
182
|
+
return candidate;
|
|
183
|
+
}
|
|
184
|
+
return '';
|
|
185
|
+
}
|
|
132
186
|
export function isDirectGameTask(text) {
|
|
133
187
|
return isDirectGameTaskDecision(text);
|
|
134
188
|
}
|
|
@@ -2858,18 +2912,19 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
2858
2912
|
}
|
|
2859
2913
|
if (canonical === 'fs_read_skill') {
|
|
2860
2914
|
if (!toolParams.skill_id) {
|
|
2861
|
-
toolParams.skill_id = toolParams.id || toolParams.name || toolParams.skill || '';
|
|
2915
|
+
toolParams.skill_id = toolParams.id || toolParams.name || toolParams.skill || toolParams.skillId || toolParams.skillName || '';
|
|
2862
2916
|
}
|
|
2863
2917
|
if (!toolParams.skill_id) {
|
|
2864
|
-
const
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
toolParams.skill_id = match[1].trim();
|
|
2918
|
+
const extracted = extractSkillIdFromPrompt(this.currentTaskPrompt || this.userPrompt || '');
|
|
2919
|
+
if (extracted) {
|
|
2920
|
+
toolParams.skill_id = extracted;
|
|
2868
2921
|
}
|
|
2869
2922
|
}
|
|
2870
2923
|
delete toolParams.id;
|
|
2871
2924
|
delete toolParams.name;
|
|
2872
2925
|
delete toolParams.skill;
|
|
2926
|
+
delete toolParams.skillId;
|
|
2927
|
+
delete toolParams.skillName;
|
|
2873
2928
|
}
|
|
2874
2929
|
if (Object.keys(toolParams).length > 0 && !this.validateToolArgs(canonical, toolParams)) {
|
|
2875
2930
|
response.toolCalls = [{
|
|
@@ -4481,12 +4536,15 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
4481
4536
|
let resultString = JSON.stringify(result);
|
|
4482
4537
|
// Per tool, not one number for all of them. A build log and a
|
|
4483
4538
|
// source file are not equally worth their space in the window.
|
|
4539
|
+
// Compatibility fallback preserves complete output when primary store is unavailable.
|
|
4484
4540
|
const MAX_RESULT_CHARS = resultCapFor(functionName);
|
|
4541
|
+
const inlineLimit = Math.min(MAX_RESULT_CHARS, functionName === 'fs_read_skill' ? 16000 : functionName === 'tool_search' ? 8000 : 2500);
|
|
4485
4542
|
const originalFingerprint = createHash('sha256').update(resultString).digest('hex');
|
|
4486
4543
|
let spill = null;
|
|
4487
|
-
if (resultString.length >
|
|
4544
|
+
if (resultString.length > inlineLimit) {
|
|
4488
4545
|
const document = renderSpillDocument(result, { taskId: this.taskId, step: this.stepsCompleted, tool: functionName });
|
|
4489
|
-
const
|
|
4546
|
+
const store = inlineLimit > 2500 ? new ToolOutputStore({ maxChars: inlineLimit, maxLines: 400, maxBytes: Math.max(50 * 1024, inlineLimit * 4) }) : defaultToolOutputStore;
|
|
4547
|
+
const stored = processToolOutputWithStore(this.taskId, toolCall.id, document, store);
|
|
4490
4548
|
if (stored.isTruncated && stored.diskPath) {
|
|
4491
4549
|
spill = { path: stored.diskPath };
|
|
4492
4550
|
resultString = JSON.stringify({
|
|
@@ -4495,9 +4553,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
4495
4553
|
output: stored.contentForModel
|
|
4496
4554
|
});
|
|
4497
4555
|
}
|
|
4498
|
-
else if (document.length >
|
|
4499
|
-
// Compatibility recovery store if the primary store is unavailable.
|
|
4500
|
-
// spillToolResult preserves the full document; never truncate on failure.
|
|
4556
|
+
else if (document.length > inlineLimit) {
|
|
4501
4557
|
const fallback = spillToolResult(result, { taskId: this.taskId, step: this.stepsCompleted, tool: functionName });
|
|
4502
4558
|
if (fallback) {
|
|
4503
4559
|
spill = fallback;
|
|
@@ -4880,22 +4936,47 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
4880
4936
|
}
|
|
4881
4937
|
// V5: Validate tool call arguments before execution
|
|
4882
4938
|
validateToolArgs(toolName, args) {
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4939
|
+
if (!args || typeof args !== 'object') {
|
|
4940
|
+
return 'Tool arguments must be a JSON object';
|
|
4941
|
+
}
|
|
4942
|
+
const baseDir = this.workspaceRoot || process.cwd();
|
|
4943
|
+
const resolveOne = (raw) => {
|
|
4944
|
+
const val = raw.trim();
|
|
4945
|
+
if (!val || /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(val)) {
|
|
4946
|
+
return null;
|
|
4947
|
+
}
|
|
4948
|
+
if (val === '~' || val.startsWith('~/') || val.startsWith('~\\')) {
|
|
4949
|
+
return val.replace(/^~(?=$|[\\/])/, os.homedir());
|
|
4950
|
+
}
|
|
4951
|
+
if (!path.isAbsolute(val)) {
|
|
4952
|
+
return path.resolve(baseDir, val);
|
|
4953
|
+
}
|
|
4954
|
+
return val;
|
|
4955
|
+
};
|
|
4956
|
+
// 1. File operations must have absolute paths (fs_read_skill uses skill-relative file_path)
|
|
4957
|
+
const nonPathTargetTools = new Set(['vision_inspect_ui', 'astryx_oracle', 'desktop_act']);
|
|
4958
|
+
if (toolName !== 'fs_read_skill') {
|
|
4959
|
+
const pathFields = [
|
|
4960
|
+
'path', 'searchPath', 'cwd', 'directory',
|
|
4961
|
+
'source', 'destination', 'file_path', 'filePath', 'filepath',
|
|
4962
|
+
'targetFile', 'outputFile', 'outputPath',
|
|
4963
|
+
...(nonPathTargetTools.has(toolName) ? [] : ['target'])
|
|
4964
|
+
];
|
|
4965
|
+
for (const field of pathFields) {
|
|
4966
|
+
if (args[field] && typeof args[field] === 'string') {
|
|
4967
|
+
const resolved = resolveOne(args[field]);
|
|
4968
|
+
if (resolved !== null) {
|
|
4969
|
+
args[field] = resolved;
|
|
4970
|
+
}
|
|
4897
4971
|
}
|
|
4898
4972
|
}
|
|
4973
|
+
if (Array.isArray(args.target_directories)) {
|
|
4974
|
+
args.target_directories = args.target_directories.map((entry) => {
|
|
4975
|
+
if (typeof entry !== 'string')
|
|
4976
|
+
return entry;
|
|
4977
|
+
return resolveOne(entry) ?? entry;
|
|
4978
|
+
});
|
|
4979
|
+
}
|
|
4899
4980
|
}
|
|
4900
4981
|
// 2. Terminal commands must have a command string
|
|
4901
4982
|
if ((toolName === 'sysRun' || toolName === 'sysRunBg') && !args.command) {
|
|
@@ -4922,13 +5003,22 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
4922
5003
|
}
|
|
4923
5004
|
// 5. Tool search must have a query, pack, or names array
|
|
4924
5005
|
if (toolName === 'tool_search') {
|
|
4925
|
-
const q = typeof args.query === 'string'
|
|
5006
|
+
const q = typeof args.query === 'string'
|
|
5007
|
+
? args.query.trim()
|
|
5008
|
+
: (Array.isArray(args.query) ? args.query.map(String).join(' ').trim() : '');
|
|
4926
5009
|
const p = typeof args.pack === 'string' ? args.pack.trim() : '';
|
|
4927
5010
|
const n = Array.isArray(args.names) && args.names.length > 0;
|
|
4928
5011
|
if (!q && !p && !n) {
|
|
4929
5012
|
return 'Missing required "query" or "pack" argument';
|
|
4930
5013
|
}
|
|
4931
5014
|
}
|
|
5015
|
+
// 6. Skill reader must have a non-empty skill_id
|
|
5016
|
+
if (toolName === 'fs_read_skill') {
|
|
5017
|
+
const sid = typeof args.skill_id === 'string' ? args.skill_id.trim() : '';
|
|
5018
|
+
if (!sid) {
|
|
5019
|
+
return 'Missing required "skill_id" argument';
|
|
5020
|
+
}
|
|
5021
|
+
}
|
|
4932
5022
|
return null; // No validation errors
|
|
4933
5023
|
}
|
|
4934
5024
|
}
|
package/src/agentLoop.ts
CHANGED
|
@@ -94,7 +94,7 @@ import {
|
|
|
94
94
|
// Provider imports
|
|
95
95
|
import { detectWorkspaceDomains, ensureSkillRepo, getSkillDomainHeader } from './skillsManager.js';
|
|
96
96
|
import { spillToolResult, buildDecayPointer, pruneOutputStore } from './outputStore.js';
|
|
97
|
-
import { defaultToolOutputStore, processToolOutputWithStore, renderSpillDocument } from './tools/toolOutputStore.js';
|
|
97
|
+
import { ToolOutputStore, defaultToolOutputStore, processToolOutputWithStore, renderSpillDocument } from './tools/toolOutputStore.js';
|
|
98
98
|
import { beginTask as beginCheckpointTask, captureBeforeMutation, pruneStore as pruneCheckpointStore, resolveProjectRoot } from './checkpoints.js';
|
|
99
99
|
import fsSync from 'fs';
|
|
100
100
|
import os from 'os';
|
|
@@ -204,6 +204,63 @@ export function isCodeAuthoringTaskPrompt(text: string): boolean {
|
|
|
204
204
|
return /\b(create|build|make|write|code|implement|generate|game|3js|three?\.?js|three?js|app)\b/i.test(t);
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
+
export function extractSkillIdFromPrompt(prompt: string): string {
|
|
208
|
+
const text = String(prompt || '').trim();
|
|
209
|
+
if (!text) return '';
|
|
210
|
+
const stopWords = new Set([
|
|
211
|
+
'the', 'a', 'an', 'this', 'that', 'from', 'in', 'with',
|
|
212
|
+
'using', 'for', 'to', 'by', 'and', 'or', 'of'
|
|
213
|
+
]);
|
|
214
|
+
const leadingTrim = new Set(['`', '"', "'", '(', '[']);
|
|
215
|
+
const trailingTrim = new Set(['`', '"', "'", ')', ',', '.', ';', ':', '!', '?', ']', '\\']);
|
|
216
|
+
const cleanCandidate = (raw: string): string => {
|
|
217
|
+
const trimmed = raw.trim();
|
|
218
|
+
let start = 0;
|
|
219
|
+
let end = trimmed.length;
|
|
220
|
+
while (start < end && leadingTrim.has(trimmed[start]!)) start++;
|
|
221
|
+
while (end > start && trailingTrim.has(trimmed[end - 1]!)) end--;
|
|
222
|
+
const stripped = trimmed.slice(start, end);
|
|
223
|
+
if (!stripped || stopWords.has(stripped.toLowerCase())) return '';
|
|
224
|
+
if (/^(?:fs_read_skill|fs_read_skil|read_skill|read_skil|tool_search)$/i.test(stripped)) {
|
|
225
|
+
return '';
|
|
226
|
+
}
|
|
227
|
+
return stripped;
|
|
228
|
+
};
|
|
229
|
+
const isFileExt = (candidate: string): boolean =>
|
|
230
|
+
/\.(?:ts|tsx|js|jsx|mjs|cjs|py|go|rs|java|kt|json|html|css|gradle|apk|aab|dex)$/i.test(candidate);
|
|
231
|
+
|
|
232
|
+
const cuedSlashMatch = text.match(
|
|
233
|
+
/(?:\bskill_id|\bskill|\bfs_read_skil{1,2})(?:\s*[:=]\s*|\s+)[`"']?([a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}\/[a-zA-Z0-9][a-zA-Z0-9_.-]{0,120})[`"']?/i
|
|
234
|
+
);
|
|
235
|
+
if (cuedSlashMatch?.[1]) {
|
|
236
|
+
const candidate = cleanCandidate(cuedSlashMatch[1]);
|
|
237
|
+
if (candidate && !isFileExt(candidate)) {
|
|
238
|
+
return candidate;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
for (const m of text.matchAll(/\b([a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}\/[a-zA-Z0-9][a-zA-Z0-9_.-]{0,120})\b/g)) {
|
|
242
|
+
const candidate = cleanCandidate(m[1] || '');
|
|
243
|
+
if (candidate && !isFileExt(candidate)) {
|
|
244
|
+
return candidate;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const explicitQuotedMatch = text.match(
|
|
248
|
+
/(?:\bskill_id|\bskill)(?:\s*[:=]\s*|\s+)(?:the\s+)?[`"']([^`"'\n\r]{2,120})[`"']/i
|
|
249
|
+
);
|
|
250
|
+
if (explicitQuotedMatch?.[1]) {
|
|
251
|
+
const candidate = cleanCandidate(explicitQuotedMatch[1]);
|
|
252
|
+
if (candidate) return candidate;
|
|
253
|
+
}
|
|
254
|
+
const bareMatch = text.match(
|
|
255
|
+
/(?:\bskill_id\s*[:=]\s*|\bskill\s*[:=]\s*|\bskill\s+(?:called\s+|named\s+)?)([a-zA-Z0-9][a-zA-Z0-9_.-]{1,120})/i
|
|
256
|
+
);
|
|
257
|
+
if (bareMatch?.[1]) {
|
|
258
|
+
const candidate = cleanCandidate(bareMatch[1]);
|
|
259
|
+
if (candidate) return candidate;
|
|
260
|
+
}
|
|
261
|
+
return '';
|
|
262
|
+
}
|
|
263
|
+
|
|
207
264
|
export function isDirectGameTask(text: string): boolean {
|
|
208
265
|
return isDirectGameTaskDecision(text);
|
|
209
266
|
}
|
|
@@ -2968,18 +3025,19 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
2968
3025
|
|
|
2969
3026
|
if (canonical === 'fs_read_skill') {
|
|
2970
3027
|
if (!toolParams.skill_id) {
|
|
2971
|
-
toolParams.skill_id = toolParams.id || toolParams.name || toolParams.skill || '';
|
|
3028
|
+
toolParams.skill_id = toolParams.id || toolParams.name || toolParams.skill || toolParams.skillId || toolParams.skillName || '';
|
|
2972
3029
|
}
|
|
2973
3030
|
if (!toolParams.skill_id) {
|
|
2974
|
-
const
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
toolParams.skill_id = match[1].trim();
|
|
3031
|
+
const extracted = extractSkillIdFromPrompt(this.currentTaskPrompt || this.userPrompt || '');
|
|
3032
|
+
if (extracted) {
|
|
3033
|
+
toolParams.skill_id = extracted;
|
|
2978
3034
|
}
|
|
2979
3035
|
}
|
|
2980
3036
|
delete toolParams.id;
|
|
2981
3037
|
delete toolParams.name;
|
|
2982
3038
|
delete toolParams.skill;
|
|
3039
|
+
delete toolParams.skillId;
|
|
3040
|
+
delete toolParams.skillName;
|
|
2983
3041
|
}
|
|
2984
3042
|
|
|
2985
3043
|
if (Object.keys(toolParams).length > 0 && !this.validateToolArgs(canonical, toolParams)) {
|
|
@@ -4709,12 +4767,15 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
4709
4767
|
let resultString = JSON.stringify(result);
|
|
4710
4768
|
// Per tool, not one number for all of them. A build log and a
|
|
4711
4769
|
// source file are not equally worth their space in the window.
|
|
4770
|
+
// Compatibility fallback preserves complete output when primary store is unavailable.
|
|
4712
4771
|
const MAX_RESULT_CHARS = resultCapFor(functionName);
|
|
4772
|
+
const inlineLimit = Math.min(MAX_RESULT_CHARS, functionName === 'fs_read_skill' ? 16000 : functionName === 'tool_search' ? 8000 : 2500);
|
|
4713
4773
|
const originalFingerprint = createHash('sha256').update(resultString).digest('hex');
|
|
4714
4774
|
let spill = null;
|
|
4715
|
-
if (resultString.length >
|
|
4775
|
+
if (resultString.length > inlineLimit) {
|
|
4716
4776
|
const document = renderSpillDocument(result, { taskId: this.taskId, step: this.stepsCompleted, tool: functionName });
|
|
4717
|
-
const
|
|
4777
|
+
const store = inlineLimit > 2500 ? new ToolOutputStore({ maxChars: inlineLimit, maxLines: 400, maxBytes: Math.max(50 * 1024, inlineLimit * 4) }) : defaultToolOutputStore;
|
|
4778
|
+
const stored = processToolOutputWithStore(this.taskId, toolCall.id, document, store);
|
|
4718
4779
|
if (stored.isTruncated && stored.diskPath) {
|
|
4719
4780
|
spill = { path: stored.diskPath };
|
|
4720
4781
|
resultString = JSON.stringify({
|
|
@@ -4722,9 +4783,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
4722
4783
|
...(typeof result?.error === 'string' ? { error: result.error.slice(0, 500) } : {}),
|
|
4723
4784
|
output: stored.contentForModel
|
|
4724
4785
|
});
|
|
4725
|
-
} else if (document.length >
|
|
4726
|
-
// Compatibility recovery store if the primary store is unavailable.
|
|
4727
|
-
// spillToolResult preserves the full document; never truncate on failure.
|
|
4786
|
+
} else if (document.length > inlineLimit) {
|
|
4728
4787
|
const fallback = spillToolResult(result, { taskId: this.taskId, step: this.stepsCompleted, tool: functionName });
|
|
4729
4788
|
if (fallback) {
|
|
4730
4789
|
spill = fallback;
|
|
@@ -5137,22 +5196,48 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
5137
5196
|
// V5: Validate tool call arguments before execution
|
|
5138
5197
|
|
|
5139
5198
|
validateToolArgs(toolName: string, args: any) {
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5199
|
+
if (!args || typeof args !== 'object') {
|
|
5200
|
+
return 'Tool arguments must be a JSON object';
|
|
5201
|
+
}
|
|
5202
|
+
|
|
5203
|
+
const baseDir = this.workspaceRoot || process.cwd();
|
|
5204
|
+
const resolveOne = (raw: string): string | null => {
|
|
5205
|
+
const val = raw.trim();
|
|
5206
|
+
if (!val || /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(val)) {
|
|
5207
|
+
return null;
|
|
5208
|
+
}
|
|
5209
|
+
if (val === '~' || val.startsWith('~/') || val.startsWith('~\\')) {
|
|
5210
|
+
return val.replace(/^~(?=$|[\\/])/, os.homedir());
|
|
5211
|
+
}
|
|
5212
|
+
if (!path.isAbsolute(val)) {
|
|
5213
|
+
return path.resolve(baseDir, val);
|
|
5214
|
+
}
|
|
5215
|
+
return val;
|
|
5216
|
+
};
|
|
5217
|
+
|
|
5218
|
+
// 1. File operations must have absolute paths (fs_read_skill uses skill-relative file_path)
|
|
5219
|
+
const nonPathTargetTools = new Set(['vision_inspect_ui', 'astryx_oracle', 'desktop_act']);
|
|
5220
|
+
if (toolName !== 'fs_read_skill') {
|
|
5221
|
+
const pathFields = [
|
|
5222
|
+
'path', 'searchPath', 'cwd', 'directory',
|
|
5223
|
+
'source', 'destination', 'file_path', 'filePath', 'filepath',
|
|
5224
|
+
'targetFile', 'outputFile', 'outputPath',
|
|
5225
|
+
...(nonPathTargetTools.has(toolName) ? [] : ['target'])
|
|
5226
|
+
];
|
|
5227
|
+
for (const field of pathFields) {
|
|
5228
|
+
if (args[field] && typeof args[field] === 'string') {
|
|
5229
|
+
const resolved = resolveOne(args[field]);
|
|
5230
|
+
if (resolved !== null) {
|
|
5231
|
+
args[field] = resolved;
|
|
5232
|
+
}
|
|
5154
5233
|
}
|
|
5155
5234
|
}
|
|
5235
|
+
if (Array.isArray(args.target_directories)) {
|
|
5236
|
+
args.target_directories = args.target_directories.map((entry: unknown) => {
|
|
5237
|
+
if (typeof entry !== 'string') return entry;
|
|
5238
|
+
return resolveOne(entry) ?? entry;
|
|
5239
|
+
});
|
|
5240
|
+
}
|
|
5156
5241
|
}
|
|
5157
5242
|
|
|
5158
5243
|
// 2. Terminal commands must have a command string
|
|
@@ -5183,7 +5268,9 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
5183
5268
|
|
|
5184
5269
|
// 5. Tool search must have a query, pack, or names array
|
|
5185
5270
|
if (toolName === 'tool_search') {
|
|
5186
|
-
const q = typeof args.query === 'string'
|
|
5271
|
+
const q = typeof args.query === 'string'
|
|
5272
|
+
? args.query.trim()
|
|
5273
|
+
: (Array.isArray(args.query) ? args.query.map(String).join(' ').trim() : '');
|
|
5187
5274
|
const p = typeof args.pack === 'string' ? args.pack.trim() : '';
|
|
5188
5275
|
const n = Array.isArray(args.names) && args.names.length > 0;
|
|
5189
5276
|
if (!q && !p && !n) {
|
|
@@ -5191,6 +5278,14 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
5191
5278
|
}
|
|
5192
5279
|
}
|
|
5193
5280
|
|
|
5281
|
+
// 6. Skill reader must have a non-empty skill_id
|
|
5282
|
+
if (toolName === 'fs_read_skill') {
|
|
5283
|
+
const sid = typeof args.skill_id === 'string' ? args.skill_id.trim() : '';
|
|
5284
|
+
if (!sid) {
|
|
5285
|
+
return 'Missing required "skill_id" argument';
|
|
5286
|
+
}
|
|
5287
|
+
}
|
|
5288
|
+
|
|
5194
5289
|
return null; // No validation errors
|
|
5195
5290
|
}
|
|
5196
5291
|
}
|
package/src/contextManager.js
CHANGED
|
@@ -46,6 +46,8 @@ export const RESULT_CAPS = {
|
|
|
46
46
|
fs_read: 32000,
|
|
47
47
|
code_search_ast: 32000,
|
|
48
48
|
MultiEdit: 32000,
|
|
49
|
+
fs_read_skill: 16000,
|
|
50
|
+
tool_search: 8000,
|
|
49
51
|
|
|
50
52
|
// Command output. Low information density, high volume, and the conclusion is
|
|
51
53
|
// almost always in the first and last few lines.
|
package/src/decideTools.js
CHANGED
|
@@ -30,6 +30,8 @@ export function isDirectGameTask(text) {
|
|
|
30
30
|
* is checked against the ToolsList before use, so a stale entry is inert.
|
|
31
31
|
*/
|
|
32
32
|
const TRIGGERS = [
|
|
33
|
+
{ pattern: /\b(fs_read_skill|fs_read_skil|read_skill|skill_id|skills?)\b/i,
|
|
34
|
+
tools: ['fs_read_skill'], why: 'skill inspection' },
|
|
33
35
|
{ pattern: /\b(preview|screenshot|visual(?:ly)?|rendered? (?:page|output|ui)|browser|snapshot|look at (?:the )?(?:ui|page|screen))\b/i,
|
|
34
36
|
tools: ['browser_act', 'screenshot', 'view_image'], why: 'rendered output must be looked at' },
|
|
35
37
|
{ pattern: /\b(vision|ocr|inspect (?:the )?(?:ui|screen))\b/i, tools: ['vision_inspect_ui'], why: 'screen inspection' },
|
|
@@ -148,6 +150,13 @@ export function decideTools(input) {
|
|
|
148
150
|
for (const why of intentMemory.reasons)
|
|
149
151
|
reasons.push(why);
|
|
150
152
|
}
|
|
153
|
+
if (/\b(?:fs_read_skill|fs_read_skil|read_skill|skill_id)\b|\b(?:read|load|open|show|get|inspect|fetch|view|check|use|using|apply|follow)\s+(?:the\s+|this\s+|that\s+|a\s+|existing\s+|compiled\s+)?skills?\b|\b(?:what|which|list|available)\s+(?:all\s+|the\s+)?skills?\b/i.test(prompt)) {
|
|
154
|
+
const skillTool = known.get('fs_read_skill');
|
|
155
|
+
if (skillTool) {
|
|
156
|
+
tools.push(skillTool);
|
|
157
|
+
reasons.push('skill inspection');
|
|
158
|
+
}
|
|
159
|
+
}
|
|
151
160
|
}
|
|
152
161
|
if (input.text) {
|
|
153
162
|
const found = toolsForText(input.text, input.list);
|
package/src/decideTools.ts
CHANGED
|
@@ -77,6 +77,8 @@ interface Trigger {
|
|
|
77
77
|
* is checked against the ToolsList before use, so a stale entry is inert.
|
|
78
78
|
*/
|
|
79
79
|
const TRIGGERS: readonly Trigger[] = [
|
|
80
|
+
{ pattern: /\b(fs_read_skill|fs_read_skil|read_skill|skill_id|skills?)\b/i,
|
|
81
|
+
tools: ['fs_read_skill'], why: 'skill inspection' },
|
|
80
82
|
{ pattern: /\b(preview|screenshot|visual(?:ly)?|rendered? (?:page|output|ui)|browser|snapshot|look at (?:the )?(?:ui|page|screen))\b/i,
|
|
81
83
|
tools: ['browser_act', 'screenshot', 'view_image'], why: 'rendered output must be looked at' },
|
|
82
84
|
{ pattern: /\b(vision|ocr|inspect (?:the )?(?:ui|screen))\b/i, tools: ['vision_inspect_ui'], why: 'screen inspection' },
|
|
@@ -184,6 +186,13 @@ export function decideTools(input: DecideToolsInput): ToolDecision {
|
|
|
184
186
|
for (const name of intentMemory.tools) tools.push(name);
|
|
185
187
|
for (const why of intentMemory.reasons) reasons.push(why);
|
|
186
188
|
}
|
|
189
|
+
if (/\b(?:fs_read_skill|fs_read_skil|read_skill|skill_id)\b|\b(?:read|load|open|show|get|inspect|fetch|view|check|use|using|apply|follow)\s+(?:the\s+|this\s+|that\s+|a\s+|existing\s+|compiled\s+)?skills?\b|\b(?:what|which|list|available)\s+(?:all\s+|the\s+)?skills?\b/i.test(prompt)) {
|
|
190
|
+
const skillTool = known.get('fs_read_skill');
|
|
191
|
+
if (skillTool) {
|
|
192
|
+
tools.push(skillTool);
|
|
193
|
+
reasons.push('skill inspection');
|
|
194
|
+
}
|
|
195
|
+
}
|
|
187
196
|
}
|
|
188
197
|
|
|
189
198
|
if (input.text) {
|
package/src/decisionPolicy.js
CHANGED
|
@@ -128,8 +128,126 @@ export function assessDecisionRequirement(prompt) {
|
|
|
128
128
|
reason: 'The request reaches a durable architecture boundary with more than one plausible implementation.'
|
|
129
129
|
};
|
|
130
130
|
}
|
|
131
|
+
function extractPreviousCueWord(beforeRaw) {
|
|
132
|
+
let end = beforeRaw.length;
|
|
133
|
+
while (end > 0) {
|
|
134
|
+
const c = beforeRaw[end - 1];
|
|
135
|
+
if (c === ':' || c === '=' || /\s/.test(c))
|
|
136
|
+
end--;
|
|
137
|
+
else
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
let start = end;
|
|
141
|
+
while (start > 0) {
|
|
142
|
+
const c = beforeRaw[start - 1];
|
|
143
|
+
if (/\s/.test(c) || c === '(')
|
|
144
|
+
break;
|
|
145
|
+
start--;
|
|
146
|
+
}
|
|
147
|
+
return beforeRaw.slice(start, end).toLowerCase();
|
|
148
|
+
}
|
|
149
|
+
function stripTokenEdgePunctuation(token) {
|
|
150
|
+
const leading = new Set(['`', '"', "'", '(']);
|
|
151
|
+
const trailing = new Set(['`', '"', "'", ',', '.', ';', ':', '!', '?', ')']);
|
|
152
|
+
let start = 0;
|
|
153
|
+
let end = token.length;
|
|
154
|
+
while (start < end && leading.has(token[start]))
|
|
155
|
+
start++;
|
|
156
|
+
while (end > start && trailing.has(token[end - 1]))
|
|
157
|
+
end--;
|
|
158
|
+
return token.slice(start, end);
|
|
159
|
+
}
|
|
160
|
+
function redactDelimitedLiteralAfterKeyword(text) {
|
|
161
|
+
const cues = new Set(['skill', 'skill_id', 'fs_read_skill', 'fs_read_skil', 'read_skill', 'matching', 'pattern', 'query']);
|
|
162
|
+
let out = '';
|
|
163
|
+
let i = 0;
|
|
164
|
+
while (i < text.length) {
|
|
165
|
+
const ch = text[i];
|
|
166
|
+
if (ch === '`' || ch === '"') {
|
|
167
|
+
const lastWord = extractPreviousCueWord(out);
|
|
168
|
+
const close = text.indexOf(ch, i + 1);
|
|
169
|
+
if (close !== -1 && cues.has(lastWord)) {
|
|
170
|
+
out += '<lookup_literal>';
|
|
171
|
+
i = close + 1;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (ch === "'" && (i === 0 || /[\s:=(\[]/.test(text[i - 1]))) {
|
|
176
|
+
const lastWord = extractPreviousCueWord(out);
|
|
177
|
+
const close = text.indexOf("'", i + 1);
|
|
178
|
+
if (close !== -1 && cues.has(lastWord)) {
|
|
179
|
+
out += '<lookup_literal>';
|
|
180
|
+
i = close + 1;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
out += ch;
|
|
185
|
+
i++;
|
|
186
|
+
}
|
|
187
|
+
return out;
|
|
188
|
+
}
|
|
189
|
+
const KNOWN_FILE_EXT_RE = /\.(?:ts|tsx|js|jsx|mjs|cjs|py|go|rs|java|kt|kts|swift|c|cc|cpp|h|hpp|json|yaml|yml|toml|xml|html|htm|css|scss|md|txt|sql|sh|bash|gradle|properties|apk|aab|dex|so|dylib|dll|exe|wasm|asar|png|jpe?g|webp|pdf|blend\d*|psd|aep|prproj)$/i;
|
|
190
|
+
/**
|
|
191
|
+
* Redact inline skill identifiers and tool_search query/regex literals in O(n) time
|
|
192
|
+
* so intent classifiers never mistake skill names (e.g. `mobile-development/android-build-optimization`)
|
|
193
|
+
* or search patterns (e.g. `android/.*gradle`) for software engineering/build commands.
|
|
194
|
+
*/
|
|
195
|
+
export function redactSkillAndQueryLiterals(raw) {
|
|
196
|
+
const input = String(raw ?? '');
|
|
197
|
+
if (!input.trim())
|
|
198
|
+
return input;
|
|
199
|
+
const hasSkillOrSearchContext = /\b(?:skills?|fs_read_skill|fs_read_skil|read_skill|tool_search|tool\.search|tool_deferred_mcp_search|capabilities\s+matching)\b/i.test(input);
|
|
200
|
+
if (!hasSkillOrSearchContext)
|
|
201
|
+
return input;
|
|
202
|
+
const afterQuoted = redactDelimitedLiteralAfterKeyword(input);
|
|
203
|
+
return afterQuoted.replace(/\S+/g, (token) => {
|
|
204
|
+
const core = stripTokenEdgePunctuation(token);
|
|
205
|
+
if (!core || core === '<lookup_literal>')
|
|
206
|
+
return token;
|
|
207
|
+
const isFileLikePath = /^(?:\.{0,2}\/|~\/|https?:\/\/)/i.test(core) || KNOWN_FILE_EXT_RE.test(core);
|
|
208
|
+
if (isFileLikePath)
|
|
209
|
+
return token;
|
|
210
|
+
const isSlashSkillOrPattern = core.includes('/') && /[a-z0-9]/i.test(core);
|
|
211
|
+
const hasRegexMeta = /[*+?^$[\]\\]/.test(core) && /[a-z0-9]/i.test(core);
|
|
212
|
+
if (isSlashSkillOrPattern || hasRegexMeta) {
|
|
213
|
+
return '<lookup_literal>';
|
|
214
|
+
}
|
|
215
|
+
return token;
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
const NON_LOOKUP_ACTION_RE = /\b(?:create|write|edit|modify|update|delete|remove|rename|move|build|make|implement|refactor|fix|debug|patch|install|deploy|scaffold|generate|compile|execute|decompile|disassemble|launch|apply)\b/;
|
|
219
|
+
export function isPureSkillOrCapabilityLookup(raw) {
|
|
220
|
+
const text = String(raw ?? '').trim();
|
|
221
|
+
if (!text)
|
|
222
|
+
return false;
|
|
223
|
+
const cleaned = redactSkillAndQueryLiterals(text).toLowerCase().trim();
|
|
224
|
+
if (!cleaned)
|
|
225
|
+
return false;
|
|
226
|
+
if (NON_LOOKUP_ACTION_RE.test(cleaned) ||
|
|
227
|
+
/\b(?:run|execute)\s+(?:tests?|commands?|scripts?|code)\b/.test(cleaned) ||
|
|
228
|
+
KNOWN_FILE_EXT_RE.test(cleaned)) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
const isSkillReadRequest = /\b(?:fs_read_skill|fs_read_skil|read_skill|read_skil|skill_read)\b/i.test(text) ||
|
|
232
|
+
/\b(?:read|load|open|show|get|inspect|fetch|view)\s+(?:the\s+|this\s+|a\s+|compiled\s+|native\s+|user\s+)?skills?\b/i.test(text) ||
|
|
233
|
+
/\bskill(?:_id|\s+id)\s*[:=]/i.test(text) ||
|
|
234
|
+
/^\/skills?\b/i.test(text);
|
|
235
|
+
const isSkillInventoryQuestion = /\b(?:what|which|list|show|available|browse)\s+(?:all\s+|the\s+|any\s+)?skills?\b/i.test(text) ||
|
|
236
|
+
/\bwhat\s+skills?\s+(?:do\s+you\s+have|are\s+available)\b/i.test(text) ||
|
|
237
|
+
/\bskills?\s+(?:available|catalog|inventory|list)\b/i.test(text);
|
|
238
|
+
const isToolSearchLookup = /\b(?:tool_search|tool\.search|tool_deferred_mcp_search)\b/i.test(text) ||
|
|
239
|
+
(/\b(?:search|discover|find|lookup|list|show)\b/i.test(text) &&
|
|
240
|
+
/\bcapabilit(?:y|ies)\b|\bcapability\s+packs?\b/i.test(text));
|
|
241
|
+
return isSkillReadRequest || isSkillInventoryQuestion || isToolSearchLookup;
|
|
242
|
+
}
|
|
131
243
|
export function requiresImplementationPlan(prompt, archetype = '', confidence = '') {
|
|
132
|
-
|
|
244
|
+
if (archetype === 'skill_lookup' || isPureSkillOrCapabilityLookup(prompt)) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
const text = redactSkillAndQueryLiterals(String(prompt ?? '')).toLowerCase();
|
|
248
|
+
if (archetype === 'research' && !/\b(?:implement|build|create|migrate|rewrite|refactor|integrate|write|edit|fix|modify|delete|remove|update)\b/.test(text)) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
133
251
|
// A classifier can label any "create" request build_app. A single plain
|
|
134
252
|
// text/data-file operation needs no checklist or rejected mutation round trip.
|
|
135
253
|
const namedFiles = new Set([...text.matchAll(/\b[\w./-]+\.(?:txt|md|csv|json)\b/g)].map(match => match[0]));
|