@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
|
@@ -9,6 +9,38 @@
|
|
|
9
9
|
import { listCompiledSkills, readCompiledSkill } from '../skillsManager.js';
|
|
10
10
|
import { parseSkillId, userSkillsRoot } from '../userSkills.js';
|
|
11
11
|
import { listSkillResourcePaths, readSkillTextResource } from '../skills/skillResourceSafety.js';
|
|
12
|
+
import { queryTerms, wordsOf, termMatches, requiredCoverage } from './searchRelevance.js';
|
|
13
|
+
function suggestSimilarSkills(allSkills, seed, limit = 3) {
|
|
14
|
+
const terms = queryTerms(seed);
|
|
15
|
+
if (terms.length === 0)
|
|
16
|
+
return [];
|
|
17
|
+
const minCoverage = requiredCoverage(terms.length);
|
|
18
|
+
const ranked = allSkills
|
|
19
|
+
.map((skill) => {
|
|
20
|
+
const titleWords = wordsOf(`${skill.domain} ${skill.id} ${skill.name || ''}`);
|
|
21
|
+
const descWords = wordsOf(skill.description || '');
|
|
22
|
+
let score = 0;
|
|
23
|
+
let coverage = 0;
|
|
24
|
+
for (const term of terms) {
|
|
25
|
+
if (termMatches(term, titleWords)) {
|
|
26
|
+
score += 10;
|
|
27
|
+
coverage += 1;
|
|
28
|
+
}
|
|
29
|
+
else if (termMatches(term, descWords)) {
|
|
30
|
+
score += 3;
|
|
31
|
+
coverage += 1;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return { skill, score, coverage };
|
|
35
|
+
})
|
|
36
|
+
.filter((entry) => entry.score > 0);
|
|
37
|
+
const strong = ranked.filter((entry) => entry.coverage >= minCoverage);
|
|
38
|
+
const pool = strong.length > 0 ? strong : ranked;
|
|
39
|
+
return pool
|
|
40
|
+
.sort((a, b) => (b.coverage - a.coverage) || (b.score - a.score))
|
|
41
|
+
.slice(0, limit)
|
|
42
|
+
.map((entry) => `${entry.skill.domain}/${entry.skill.id}`);
|
|
43
|
+
}
|
|
12
44
|
export default {
|
|
13
45
|
schema: {
|
|
14
46
|
name: 'fs_read_skill',
|
|
@@ -47,27 +79,7 @@ export default {
|
|
|
47
79
|
id = directMatch.id;
|
|
48
80
|
}
|
|
49
81
|
else if ('error' in parsed) {
|
|
50
|
-
const
|
|
51
|
-
const suggestions = allSkills
|
|
52
|
-
.map(s => {
|
|
53
|
-
let score = 0;
|
|
54
|
-
const d = s.domain.toLowerCase();
|
|
55
|
-
const n = s.id.toLowerCase();
|
|
56
|
-
const desc = (s.description || '').toLowerCase();
|
|
57
|
-
for (const t of queryTokens) {
|
|
58
|
-
if (n.includes(t))
|
|
59
|
-
score += 10;
|
|
60
|
-
if (d.includes(t))
|
|
61
|
-
score += 8;
|
|
62
|
-
if (desc.includes(t))
|
|
63
|
-
score += 2;
|
|
64
|
-
}
|
|
65
|
-
return { skill: s, score };
|
|
66
|
-
})
|
|
67
|
-
.filter(item => item.score > 0)
|
|
68
|
-
.sort((a, b) => b.score - a.score)
|
|
69
|
-
.slice(0, 3)
|
|
70
|
-
.map(item => `${item.skill.domain}/${item.skill.id}`);
|
|
82
|
+
const suggestions = suggestSimilarSkills(allSkills, rawSkillId);
|
|
71
83
|
const hint = suggestions.length > 0 ? ` Did you mean: ${suggestions.join(', ')}?` : '';
|
|
72
84
|
return { success: false, error: `Invalid skill id "${rawSkillId}".${hint} Expected "domain/name", for example android/gradle-build-configuration.` };
|
|
73
85
|
}
|
|
@@ -82,27 +94,7 @@ export default {
|
|
|
82
94
|
}
|
|
83
95
|
}
|
|
84
96
|
if (!info) {
|
|
85
|
-
const
|
|
86
|
-
const suggestions = allSkills
|
|
87
|
-
.map(s => {
|
|
88
|
-
let score = 0;
|
|
89
|
-
const d = s.domain.toLowerCase();
|
|
90
|
-
const n = s.id.toLowerCase();
|
|
91
|
-
const desc = (s.description || '').toLowerCase();
|
|
92
|
-
for (const t of queryTokens) {
|
|
93
|
-
if (n.includes(t))
|
|
94
|
-
score += 10;
|
|
95
|
-
if (d.includes(t))
|
|
96
|
-
score += 8;
|
|
97
|
-
if (desc.includes(t))
|
|
98
|
-
score += 2;
|
|
99
|
-
}
|
|
100
|
-
return { skill: s, score };
|
|
101
|
-
})
|
|
102
|
-
.filter(item => item.score > 0)
|
|
103
|
-
.sort((a, b) => b.score - a.score)
|
|
104
|
-
.slice(0, 3)
|
|
105
|
-
.map(item => `${item.skill.domain}/${item.skill.id}`);
|
|
97
|
+
const suggestions = suggestSimilarSkills(allSkills, `${domain || ''} ${id || ''} ${rawSkillId}`);
|
|
106
98
|
const hint = suggestions.length > 0 ? ` Did you mean: ${suggestions.join(', ')}?` : '';
|
|
107
99
|
return { success: false, error: `Unknown skill ${domain ? `${domain}/${id}` : rawSkillId}.${hint} Search the current catalog with tool_search first.` };
|
|
108
100
|
}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { listCompiledSkills, readCompiledSkill } from '../skillsManager.js';
|
|
10
10
|
import { parseSkillId, userSkillsRoot } from '../userSkills.js';
|
|
11
11
|
import { listSkillResourcePaths, readSkillTextResource } from '../skills/skillResourceSafety.js';
|
|
12
|
+
import { queryTerms, wordsOf, termMatches, requiredCoverage } from './searchRelevance.js';
|
|
12
13
|
|
|
13
14
|
interface SkillReadArgs {
|
|
14
15
|
skill_id?: string;
|
|
@@ -19,6 +20,41 @@ interface SkillReadArgs {
|
|
|
19
20
|
}
|
|
20
21
|
interface SkillReadResult { success: boolean; result?: string; error?: string; }
|
|
21
22
|
|
|
23
|
+
function suggestSimilarSkills(
|
|
24
|
+
allSkills: ReturnType<typeof listCompiledSkills>,
|
|
25
|
+
seed: string,
|
|
26
|
+
limit = 3
|
|
27
|
+
): string[] {
|
|
28
|
+
const terms = queryTerms(seed);
|
|
29
|
+
if (terms.length === 0) return [];
|
|
30
|
+
const minCoverage = requiredCoverage(terms.length);
|
|
31
|
+
const ranked = allSkills
|
|
32
|
+
.map((skill) => {
|
|
33
|
+
const titleWords = wordsOf(`${skill.domain} ${skill.id} ${skill.name || ''}`);
|
|
34
|
+
const descWords = wordsOf(skill.description || '');
|
|
35
|
+
let score = 0;
|
|
36
|
+
let coverage = 0;
|
|
37
|
+
for (const term of terms) {
|
|
38
|
+
if (termMatches(term, titleWords)) {
|
|
39
|
+
score += 10;
|
|
40
|
+
coverage += 1;
|
|
41
|
+
} else if (termMatches(term, descWords)) {
|
|
42
|
+
score += 3;
|
|
43
|
+
coverage += 1;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return { skill, score, coverage };
|
|
47
|
+
})
|
|
48
|
+
.filter((entry) => entry.score > 0);
|
|
49
|
+
|
|
50
|
+
const strong = ranked.filter((entry) => entry.coverage >= minCoverage);
|
|
51
|
+
const pool = strong.length > 0 ? strong : ranked;
|
|
52
|
+
return pool
|
|
53
|
+
.sort((a, b) => (b.coverage - a.coverage) || (b.score - a.score))
|
|
54
|
+
.slice(0, limit)
|
|
55
|
+
.map((entry) => `${entry.skill.domain}/${entry.skill.id}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
22
58
|
export default {
|
|
23
59
|
schema: {
|
|
24
60
|
name: 'fs_read_skill',
|
|
@@ -57,24 +93,7 @@ export default {
|
|
|
57
93
|
domain = directMatch.domain;
|
|
58
94
|
id = directMatch.id;
|
|
59
95
|
} else if ('error' in parsed) {
|
|
60
|
-
const
|
|
61
|
-
const suggestions = allSkills
|
|
62
|
-
.map(s => {
|
|
63
|
-
let score = 0;
|
|
64
|
-
const d = s.domain.toLowerCase();
|
|
65
|
-
const n = s.id.toLowerCase();
|
|
66
|
-
const desc = (s.description || '').toLowerCase();
|
|
67
|
-
for (const t of queryTokens) {
|
|
68
|
-
if (n.includes(t)) score += 10;
|
|
69
|
-
if (d.includes(t)) score += 8;
|
|
70
|
-
if (desc.includes(t)) score += 2;
|
|
71
|
-
}
|
|
72
|
-
return { skill: s, score };
|
|
73
|
-
})
|
|
74
|
-
.filter(item => item.score > 0)
|
|
75
|
-
.sort((a, b) => b.score - a.score)
|
|
76
|
-
.slice(0, 3)
|
|
77
|
-
.map(item => `${item.skill.domain}/${item.skill.id}`);
|
|
96
|
+
const suggestions = suggestSimilarSkills(allSkills, rawSkillId);
|
|
78
97
|
const hint = suggestions.length > 0 ? ` Did you mean: ${suggestions.join(', ')}?` : '';
|
|
79
98
|
return { success: false, error: `Invalid skill id "${rawSkillId}".${hint} Expected "domain/name", for example android/gradle-build-configuration.` };
|
|
80
99
|
}
|
|
@@ -91,24 +110,7 @@ export default {
|
|
|
91
110
|
}
|
|
92
111
|
|
|
93
112
|
if (!info) {
|
|
94
|
-
const
|
|
95
|
-
const suggestions = allSkills
|
|
96
|
-
.map(s => {
|
|
97
|
-
let score = 0;
|
|
98
|
-
const d = s.domain.toLowerCase();
|
|
99
|
-
const n = s.id.toLowerCase();
|
|
100
|
-
const desc = (s.description || '').toLowerCase();
|
|
101
|
-
for (const t of queryTokens) {
|
|
102
|
-
if (n.includes(t)) score += 10;
|
|
103
|
-
if (d.includes(t)) score += 8;
|
|
104
|
-
if (desc.includes(t)) score += 2;
|
|
105
|
-
}
|
|
106
|
-
return { skill: s, score };
|
|
107
|
-
})
|
|
108
|
-
.filter(item => item.score > 0)
|
|
109
|
-
.sort((a, b) => b.score - a.score)
|
|
110
|
-
.slice(0, 3)
|
|
111
|
-
.map(item => `${item.skill.domain}/${item.skill.id}`);
|
|
113
|
+
const suggestions = suggestSimilarSkills(allSkills, `${domain || ''} ${id || ''} ${rawSkillId}`);
|
|
112
114
|
const hint = suggestions.length > 0 ? ` Did you mean: ${suggestions.join(', ')}?` : '';
|
|
113
115
|
return { success: false, error: `Unknown skill ${domain ? `${domain}/${id}` : rawSkillId}.${hint} Search the current catalog with tool_search first.` };
|
|
114
116
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Causyne Agent — word-level relevance for tool and skill discovery.
|
|
3
|
+
*
|
|
4
|
+
* Substring matching made short query words hit unrelated entries ("and"
|
|
5
|
+
* inside "command", "kill" inside "skill", "git" inside "digit"), so one
|
|
6
|
+
* capability search could unlock a dozen irrelevant tool schemas. Matching is
|
|
7
|
+
* done on whole words with a bounded prefix rule instead. Deterministic,
|
|
8
|
+
* synchronous, linear-time, and never compiles user-supplied patterns.
|
|
9
|
+
*/
|
|
10
|
+
/** English function words and search meta-words that carry no capability signal. */
|
|
11
|
+
const STOPWORDS = new Set([
|
|
12
|
+
'and', 'the', 'for', 'with', 'from', 'into', 'onto', 'that', 'this', 'these', 'those',
|
|
13
|
+
'using', 'use', 'via', 'any', 'all', 'are', 'was', 'were', 'can', 'how', 'what', 'which',
|
|
14
|
+
'when', 'where', 'who', 'why', 'you', 'your', 'our', 'its', 'not', 'but', 'has', 'have',
|
|
15
|
+
'should', 'would', 'could', 'please', 'about', 'also', 'then', 'than', 'them', 'they',
|
|
16
|
+
'there', 'some', 'more', 'most', 'each', 'other', 'only', 'own', 'same', 'such', 'very',
|
|
17
|
+
'just', 'like', 'need', 'want', 'help', 'let', 'get', 'take', 'out', 'over', 'under', 'per',
|
|
18
|
+
'capability', 'capabilities', 'matching'
|
|
19
|
+
]);
|
|
20
|
+
/** Upper bound on distinct query terms, so scoring cost stays constant. */
|
|
21
|
+
export const MAX_RELEVANCE_TERMS = 16;
|
|
22
|
+
/**
|
|
23
|
+
* Lower-case text and fold British -ise/-isation spellings onto -ize/-ization
|
|
24
|
+
* so "optimisation" and "optimization" compare equal. Applied identically to
|
|
25
|
+
* queries and catalog text.
|
|
26
|
+
*/
|
|
27
|
+
export function normalizeSpelling(text) {
|
|
28
|
+
return text.toLowerCase().replace(/is(ations?|ing|ed|es|e)\b/g, 'iz$1');
|
|
29
|
+
}
|
|
30
|
+
/** Distinct meaningful query terms: alphanumeric words longer than two characters. */
|
|
31
|
+
export function queryTerms(query) {
|
|
32
|
+
const terms = [];
|
|
33
|
+
for (const word of normalizeSpelling(String(query || '')).split(/[^a-z0-9]+/)) {
|
|
34
|
+
if (word.length <= 2 || STOPWORDS.has(word) || terms.includes(word))
|
|
35
|
+
continue;
|
|
36
|
+
terms.push(word);
|
|
37
|
+
if (terms.length >= MAX_RELEVANCE_TERMS)
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
return terms;
|
|
41
|
+
}
|
|
42
|
+
/** Whole words of catalog text, splitting snake_case, kebab-case and camelCase names. */
|
|
43
|
+
export function wordsOf(text) {
|
|
44
|
+
const spaced = String(text || '').replace(/([a-z0-9])([A-Z])/g, '$1 $2');
|
|
45
|
+
return new Set(normalizeSpelling(spaced).split(/[^a-z0-9]+/).filter(word => word.length > 0));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A term matches a word exactly, or as a bounded stem: "build" matches
|
|
49
|
+
* "builds"/"builder", and "screenshots" matches "screenshot". Short words
|
|
50
|
+
* never match as a fragment of a longer one.
|
|
51
|
+
*/
|
|
52
|
+
export function termMatches(term, words) {
|
|
53
|
+
if (words.has(term))
|
|
54
|
+
return true;
|
|
55
|
+
for (const word of words) {
|
|
56
|
+
if (term.length >= 4 && word.startsWith(term))
|
|
57
|
+
return true;
|
|
58
|
+
if (word.length >= 4 && term.startsWith(word) && term.length - word.length <= 3)
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Minimum number of distinct query terms an entry must match. A multi-word
|
|
65
|
+
* capability description is not satisfied by an entry that shares only one
|
|
66
|
+
* generic word with it (for example "build" in "android build optimization").
|
|
67
|
+
*/
|
|
68
|
+
export function requiredCoverage(termCount) {
|
|
69
|
+
return termCount >= 3 ? 2 : 1;
|
|
70
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Causyne Agent — word-level relevance for tool and skill discovery.
|
|
3
|
+
*
|
|
4
|
+
* Substring matching made short query words hit unrelated entries ("and"
|
|
5
|
+
* inside "command", "kill" inside "skill", "git" inside "digit"), so one
|
|
6
|
+
* capability search could unlock a dozen irrelevant tool schemas. Matching is
|
|
7
|
+
* done on whole words with a bounded prefix rule instead. Deterministic,
|
|
8
|
+
* synchronous, linear-time, and never compiles user-supplied patterns.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** English function words and search meta-words that carry no capability signal. */
|
|
12
|
+
const STOPWORDS = new Set([
|
|
13
|
+
'and', 'the', 'for', 'with', 'from', 'into', 'onto', 'that', 'this', 'these', 'those',
|
|
14
|
+
'using', 'use', 'via', 'any', 'all', 'are', 'was', 'were', 'can', 'how', 'what', 'which',
|
|
15
|
+
'when', 'where', 'who', 'why', 'you', 'your', 'our', 'its', 'not', 'but', 'has', 'have',
|
|
16
|
+
'should', 'would', 'could', 'please', 'about', 'also', 'then', 'than', 'them', 'they',
|
|
17
|
+
'there', 'some', 'more', 'most', 'each', 'other', 'only', 'own', 'same', 'such', 'very',
|
|
18
|
+
'just', 'like', 'need', 'want', 'help', 'let', 'get', 'take', 'out', 'over', 'under', 'per',
|
|
19
|
+
'capability', 'capabilities', 'matching'
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
/** Upper bound on distinct query terms, so scoring cost stays constant. */
|
|
23
|
+
export const MAX_RELEVANCE_TERMS = 16;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Lower-case text and fold British -ise/-isation spellings onto -ize/-ization
|
|
27
|
+
* so "optimisation" and "optimization" compare equal. Applied identically to
|
|
28
|
+
* queries and catalog text.
|
|
29
|
+
*/
|
|
30
|
+
export function normalizeSpelling(text: string): string {
|
|
31
|
+
return text.toLowerCase().replace(/is(ations?|ing|ed|es|e)\b/g, 'iz$1');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Distinct meaningful query terms: alphanumeric words longer than two characters. */
|
|
35
|
+
export function queryTerms(query: string): string[] {
|
|
36
|
+
const terms: string[] = [];
|
|
37
|
+
for (const word of normalizeSpelling(String(query || '')).split(/[^a-z0-9]+/)) {
|
|
38
|
+
if (word.length <= 2 || STOPWORDS.has(word) || terms.includes(word)) continue;
|
|
39
|
+
terms.push(word);
|
|
40
|
+
if (terms.length >= MAX_RELEVANCE_TERMS) break;
|
|
41
|
+
}
|
|
42
|
+
return terms;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Whole words of catalog text, splitting snake_case, kebab-case and camelCase names. */
|
|
46
|
+
export function wordsOf(text: string): Set<string> {
|
|
47
|
+
const spaced = String(text || '').replace(/([a-z0-9])([A-Z])/g, '$1 $2');
|
|
48
|
+
return new Set(normalizeSpelling(spaced).split(/[^a-z0-9]+/).filter(word => word.length > 0));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A term matches a word exactly, or as a bounded stem: "build" matches
|
|
53
|
+
* "builds"/"builder", and "screenshots" matches "screenshot". Short words
|
|
54
|
+
* never match as a fragment of a longer one.
|
|
55
|
+
*/
|
|
56
|
+
export function termMatches(term: string, words: Set<string>): boolean {
|
|
57
|
+
if (words.has(term)) return true;
|
|
58
|
+
for (const word of words) {
|
|
59
|
+
if (term.length >= 4 && word.startsWith(term)) return true;
|
|
60
|
+
if (word.length >= 4 && term.startsWith(word) && term.length - word.length <= 3) return true;
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Minimum number of distinct query terms an entry must match. A multi-word
|
|
67
|
+
* capability description is not satisfied by an entry that shares only one
|
|
68
|
+
* generic word with it (for example "build" in "android build optimization").
|
|
69
|
+
*/
|
|
70
|
+
export function requiredCoverage(termCount: number): number {
|
|
71
|
+
return termCount >= 3 ? 2 : 1;
|
|
72
|
+
}
|
|
@@ -187,7 +187,13 @@ const PARAMETER_ALIASES = {
|
|
|
187
187
|
path: [
|
|
188
188
|
'filepath', 'file_path', 'filePath', 'targetFile', 'target_file',
|
|
189
189
|
'fileName', 'file_name', 'file', 'target', 'dir', 'folder',
|
|
190
|
-
'src_path', 'source_file', 'target_path'
|
|
190
|
+
'src_path', 'source_file', 'target_path', 'directory', 'searchPath', 'root'
|
|
191
|
+
],
|
|
192
|
+
searchPath: [
|
|
193
|
+
'path', 'dir', 'directory', 'root', 'folder'
|
|
194
|
+
],
|
|
195
|
+
skill_id: [
|
|
196
|
+
'id', 'name', 'skill', 'skillId', 'skillName'
|
|
191
197
|
],
|
|
192
198
|
file_path: [
|
|
193
199
|
'path', 'filepath', 'filePath', 'targetFile', 'target_file',
|
|
@@ -198,7 +204,7 @@ const PARAMETER_ALIASES = {
|
|
|
198
204
|
'terminalCommand', 'run', 'instruction'
|
|
199
205
|
],
|
|
200
206
|
query: [
|
|
201
|
-
'q', 'search', 'term', 'pattern', 'search_term',
|
|
207
|
+
'q', 'search', 'term', 'pattern', 'regex', 'search_term',
|
|
202
208
|
'searchQuery', 'find', 'prompt'
|
|
203
209
|
],
|
|
204
210
|
pattern: [
|
|
@@ -802,7 +808,13 @@ export function resolveParameterAliases(toolName, args, schema) {
|
|
|
802
808
|
}
|
|
803
809
|
// 3. Resolve top-level parameter aliases
|
|
804
810
|
for (const [canonicalParam, aliases] of Object.entries(PARAMETER_ALIASES)) {
|
|
805
|
-
const isExpected = expectedKeys.size === 0
|
|
811
|
+
const isExpected = expectedKeys.size === 0
|
|
812
|
+
? (canonicalParam === 'searchPath'
|
|
813
|
+
? canonicalName === 'code_search_ripgrep'
|
|
814
|
+
: canonicalParam === 'skill_id'
|
|
815
|
+
? canonicalName === 'fs_read_skill'
|
|
816
|
+
: true)
|
|
817
|
+
: expectedKeys.has(canonicalParam);
|
|
806
818
|
if (!isExpected)
|
|
807
819
|
continue;
|
|
808
820
|
if (modified[canonicalParam] === undefined || modified[canonicalParam] === null || modified[canonicalParam] === '') {
|
|
@@ -966,28 +978,50 @@ export function coerceArgumentTypes(toolName, args, schema) {
|
|
|
966
978
|
/**
|
|
967
979
|
* Automatically normalize relative file paths to absolute paths using cwd.
|
|
968
980
|
*/
|
|
969
|
-
export function normalizePaths(args, cwd = process.cwd()) {
|
|
981
|
+
export function normalizePaths(args, cwd = process.cwd(), schema, options = {}) {
|
|
970
982
|
const repairs = [];
|
|
971
983
|
const modified = { ...args };
|
|
972
|
-
const
|
|
984
|
+
const skipKeys = new Set(options.skipKeys || []);
|
|
985
|
+
const targetSchema = schema?.properties?.target;
|
|
986
|
+
const hasEnumTarget = Boolean(targetSchema && 'enum' in targetSchema);
|
|
987
|
+
const pathKeys = [
|
|
988
|
+
'path', 'searchPath', 'cwd', 'directory', 'source', 'destination',
|
|
989
|
+
'file_path', 'filePath', 'filepath', 'targetFile',
|
|
990
|
+
...(hasEnumTarget ? [] : ['target']),
|
|
991
|
+
'outputPath', 'output_path', 'outputFile', 'outputFileName'
|
|
992
|
+
];
|
|
993
|
+
const normalizeOne = (rawValue, label) => {
|
|
994
|
+
const trimmed = rawValue.trim();
|
|
995
|
+
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(trimmed)) {
|
|
996
|
+
return rawValue;
|
|
997
|
+
}
|
|
998
|
+
if (trimmed === '~' || trimmed.startsWith('~/') || trimmed.startsWith('~\\')) {
|
|
999
|
+
const expanded = trimmed.replace(/^~(?=$|[\\/])/, os.homedir());
|
|
1000
|
+
repairs.push(`Expanded home directory path '${trimmed}' -> '${expanded}' for parameter '${label}'`);
|
|
1001
|
+
return expanded;
|
|
1002
|
+
}
|
|
1003
|
+
if (!path.isAbsolute(trimmed)) {
|
|
1004
|
+
const resolved = path.resolve(cwd, trimmed);
|
|
1005
|
+
repairs.push(`Normalized relative path '${trimmed}' -> '${resolved}' for parameter '${label}'`);
|
|
1006
|
+
return resolved;
|
|
1007
|
+
}
|
|
1008
|
+
return rawValue;
|
|
1009
|
+
};
|
|
973
1010
|
for (const key of pathKeys) {
|
|
1011
|
+
if (skipKeys.has(key))
|
|
1012
|
+
continue;
|
|
974
1013
|
const val = modified[key];
|
|
975
1014
|
if (typeof val === 'string' && val.trim() !== '') {
|
|
976
|
-
|
|
977
|
-
// Skip URLs
|
|
978
|
-
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(trimmed)) {
|
|
979
|
-
continue;
|
|
980
|
-
}
|
|
981
|
-
if (trimmed === '~' || trimmed.startsWith('~/') || trimmed.startsWith('~\\')) {
|
|
982
|
-
modified[key] = trimmed.replace(/^~(?=$|[\\/])/, os.homedir());
|
|
983
|
-
repairs.push(`Expanded home directory path '${trimmed}' -> '${modified[key]}' for parameter '${key}'`);
|
|
984
|
-
}
|
|
985
|
-
else if (!path.isAbsolute(trimmed)) {
|
|
986
|
-
modified[key] = path.resolve(cwd, trimmed);
|
|
987
|
-
repairs.push(`Normalized relative path '${trimmed}' -> '${modified[key]}' for parameter '${key}'`);
|
|
988
|
-
}
|
|
1015
|
+
modified[key] = normalizeOne(val, key);
|
|
989
1016
|
}
|
|
990
1017
|
}
|
|
1018
|
+
if (!skipKeys.has('target_directories') && Array.isArray(modified.target_directories)) {
|
|
1019
|
+
modified.target_directories = modified.target_directories.map((entry, idx) => {
|
|
1020
|
+
if (typeof entry !== 'string' || entry.trim() === '')
|
|
1021
|
+
return entry;
|
|
1022
|
+
return normalizeOne(entry, `target_directories[${idx}]`);
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
991
1025
|
return {
|
|
992
1026
|
args: modified,
|
|
993
1027
|
repaired: repairs.length > 0,
|
|
@@ -1068,8 +1102,10 @@ export function selfRepairToolCall(toolCall, toolSchema, options = {}) {
|
|
|
1068
1102
|
// 3. Coerce argument types
|
|
1069
1103
|
const typeResult = coerceArgumentTypes(canonicalName, aliasResult.args, toolSchema);
|
|
1070
1104
|
allRepairs.push(...typeResult.repairs);
|
|
1071
|
-
// 4. Normalize filesystem paths
|
|
1072
|
-
const pathResult =
|
|
1105
|
+
// 4. Normalize filesystem paths (fs_read_skill uses relative skill-bundle paths, never cwd paths)
|
|
1106
|
+
const pathResult = canonicalName === 'fs_read_skill'
|
|
1107
|
+
? { args: typeResult.args, repaired: false, repairs: [] }
|
|
1108
|
+
: normalizePaths(typeResult.args, options.cwd || process.cwd(), toolSchema);
|
|
1073
1109
|
allRepairs.push(...pathResult.repairs);
|
|
1074
1110
|
const browserResult = canonicalName === 'browser_act'
|
|
1075
1111
|
? repairBrowserActions(pathResult.args, options.cwd || process.cwd())
|
|
@@ -220,7 +220,13 @@ const PARAMETER_ALIASES: Record<string, string[]> = {
|
|
|
220
220
|
path: [
|
|
221
221
|
'filepath', 'file_path', 'filePath', 'targetFile', 'target_file',
|
|
222
222
|
'fileName', 'file_name', 'file', 'target', 'dir', 'folder',
|
|
223
|
-
'src_path', 'source_file', 'target_path'
|
|
223
|
+
'src_path', 'source_file', 'target_path', 'directory', 'searchPath', 'root'
|
|
224
|
+
],
|
|
225
|
+
searchPath: [
|
|
226
|
+
'path', 'dir', 'directory', 'root', 'folder'
|
|
227
|
+
],
|
|
228
|
+
skill_id: [
|
|
229
|
+
'id', 'name', 'skill', 'skillId', 'skillName'
|
|
224
230
|
],
|
|
225
231
|
file_path: [
|
|
226
232
|
'path', 'filepath', 'filePath', 'targetFile', 'target_file',
|
|
@@ -231,7 +237,7 @@ const PARAMETER_ALIASES: Record<string, string[]> = {
|
|
|
231
237
|
'terminalCommand', 'run', 'instruction'
|
|
232
238
|
],
|
|
233
239
|
query: [
|
|
234
|
-
'q', 'search', 'term', 'pattern', 'search_term',
|
|
240
|
+
'q', 'search', 'term', 'pattern', 'regex', 'search_term',
|
|
235
241
|
'searchQuery', 'find', 'prompt'
|
|
236
242
|
],
|
|
237
243
|
pattern: [
|
|
@@ -833,7 +839,13 @@ export function resolveParameterAliases(
|
|
|
833
839
|
|
|
834
840
|
// 3. Resolve top-level parameter aliases
|
|
835
841
|
for (const [canonicalParam, aliases] of Object.entries(PARAMETER_ALIASES)) {
|
|
836
|
-
const isExpected = expectedKeys.size === 0
|
|
842
|
+
const isExpected = expectedKeys.size === 0
|
|
843
|
+
? (canonicalParam === 'searchPath'
|
|
844
|
+
? canonicalName === 'code_search_ripgrep'
|
|
845
|
+
: canonicalParam === 'skill_id'
|
|
846
|
+
? canonicalName === 'fs_read_skill'
|
|
847
|
+
: true)
|
|
848
|
+
: expectedKeys.has(canonicalParam);
|
|
837
849
|
if (!isExpected) continue;
|
|
838
850
|
|
|
839
851
|
if (modified[canonicalParam] === undefined || modified[canonicalParam] === null || modified[canonicalParam] === '') {
|
|
@@ -998,30 +1010,55 @@ export function coerceArgumentTypes(
|
|
|
998
1010
|
*/
|
|
999
1011
|
export function normalizePaths(
|
|
1000
1012
|
args: Record<string, unknown>,
|
|
1001
|
-
cwd: string = process.cwd()
|
|
1013
|
+
cwd: string = process.cwd(),
|
|
1014
|
+
schema?: ParameterSchema,
|
|
1015
|
+
options: { skipKeys?: ReadonlySet<string> | Iterable<string> } = {}
|
|
1002
1016
|
): RepairResult {
|
|
1003
1017
|
const repairs: string[] = [];
|
|
1004
1018
|
const modified = { ...args };
|
|
1005
|
-
const
|
|
1019
|
+
const skipKeys = new Set(options.skipKeys || []);
|
|
1020
|
+
const targetSchema = schema?.properties?.target;
|
|
1021
|
+
const hasEnumTarget = Boolean(targetSchema && 'enum' in targetSchema);
|
|
1022
|
+
const pathKeys = [
|
|
1023
|
+
'path', 'searchPath', 'cwd', 'directory', 'source', 'destination',
|
|
1024
|
+
'file_path', 'filePath', 'filepath', 'targetFile',
|
|
1025
|
+
...(hasEnumTarget ? [] : ['target']),
|
|
1026
|
+
'outputPath', 'output_path', 'outputFile', 'outputFileName'
|
|
1027
|
+
];
|
|
1028
|
+
|
|
1029
|
+
const normalizeOne = (rawValue: string, label: string): string => {
|
|
1030
|
+
const trimmed = rawValue.trim();
|
|
1031
|
+
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(trimmed)) {
|
|
1032
|
+
return rawValue;
|
|
1033
|
+
}
|
|
1034
|
+
if (trimmed === '~' || trimmed.startsWith('~/') || trimmed.startsWith('~\\')) {
|
|
1035
|
+
const expanded = trimmed.replace(/^~(?=$|[\\/])/, os.homedir());
|
|
1036
|
+
repairs.push(`Expanded home directory path '${trimmed}' -> '${expanded}' for parameter '${label}'`);
|
|
1037
|
+
return expanded;
|
|
1038
|
+
}
|
|
1039
|
+
if (!path.isAbsolute(trimmed)) {
|
|
1040
|
+
const resolved = path.resolve(cwd, trimmed);
|
|
1041
|
+
repairs.push(`Normalized relative path '${trimmed}' -> '${resolved}' for parameter '${label}'`);
|
|
1042
|
+
return resolved;
|
|
1043
|
+
}
|
|
1044
|
+
return rawValue;
|
|
1045
|
+
};
|
|
1006
1046
|
|
|
1007
1047
|
for (const key of pathKeys) {
|
|
1048
|
+
if (skipKeys.has(key)) continue;
|
|
1008
1049
|
const val = modified[key];
|
|
1009
1050
|
if (typeof val === 'string' && val.trim() !== '') {
|
|
1010
|
-
|
|
1011
|
-
// Skip URLs
|
|
1012
|
-
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(trimmed)) {
|
|
1013
|
-
continue;
|
|
1014
|
-
}
|
|
1015
|
-
if (trimmed === '~' || trimmed.startsWith('~/') || trimmed.startsWith('~\\')) {
|
|
1016
|
-
modified[key] = trimmed.replace(/^~(?=$|[\\/])/, os.homedir());
|
|
1017
|
-
repairs.push(`Expanded home directory path '${trimmed}' -> '${modified[key]}' for parameter '${key}'`);
|
|
1018
|
-
} else if (!path.isAbsolute(trimmed)) {
|
|
1019
|
-
modified[key] = path.resolve(cwd, trimmed);
|
|
1020
|
-
repairs.push(`Normalized relative path '${trimmed}' -> '${modified[key]}' for parameter '${key}'`);
|
|
1021
|
-
}
|
|
1051
|
+
modified[key] = normalizeOne(val, key);
|
|
1022
1052
|
}
|
|
1023
1053
|
}
|
|
1024
1054
|
|
|
1055
|
+
if (!skipKeys.has('target_directories') && Array.isArray(modified.target_directories)) {
|
|
1056
|
+
modified.target_directories = modified.target_directories.map((entry, idx) => {
|
|
1057
|
+
if (typeof entry !== 'string' || entry.trim() === '') return entry;
|
|
1058
|
+
return normalizeOne(entry, `target_directories[${idx}]`);
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1025
1062
|
return {
|
|
1026
1063
|
args: modified,
|
|
1027
1064
|
repaired: repairs.length > 0,
|
|
@@ -1114,8 +1151,10 @@ export function selfRepairToolCall(
|
|
|
1114
1151
|
const typeResult = coerceArgumentTypes(canonicalName, aliasResult.args, toolSchema);
|
|
1115
1152
|
allRepairs.push(...typeResult.repairs);
|
|
1116
1153
|
|
|
1117
|
-
// 4. Normalize filesystem paths
|
|
1118
|
-
const pathResult =
|
|
1154
|
+
// 4. Normalize filesystem paths (fs_read_skill uses relative skill-bundle paths, never cwd paths)
|
|
1155
|
+
const pathResult = canonicalName === 'fs_read_skill'
|
|
1156
|
+
? { args: typeResult.args, repaired: false, repairs: [] }
|
|
1157
|
+
: normalizePaths(typeResult.args, options.cwd || process.cwd(), toolSchema);
|
|
1119
1158
|
allRepairs.push(...pathResult.repairs);
|
|
1120
1159
|
|
|
1121
1160
|
const browserResult = canonicalName === 'browser_act'
|