@causyne/agent 1.20.118 → 1.20.121

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.
Files changed (101) hide show
  1. package/package.json +1 -1
  2. package/src/agent/errorClassifier.js +113 -0
  3. package/src/agent/errorClassifier.ts +161 -0
  4. package/src/agent/promptIntent.js +200 -0
  5. package/src/agent/promptIntent.ts +203 -0
  6. package/src/agent/toolArgValidator.js +97 -0
  7. package/src/agent/toolArgValidator.ts +112 -0
  8. package/src/agentLoop.js +51 -351
  9. package/src/agentLoop.ts +69 -363
  10. package/src/autoUpdate.js +111 -8
  11. package/src/autoUpdate.ts +144 -8
  12. package/src/browser/causyneBrowser.js +231 -136
  13. package/src/browser/causyneBrowser.ts +229 -140
  14. package/src/browser/searchProviders.js +41 -30
  15. package/src/browser/searchProviders.ts +24 -14
  16. package/src/browser/workspacePathSafety.js +50 -0
  17. package/src/browser/workspacePathSafety.ts +50 -0
  18. package/src/browser/workspacePreview.js +27 -4
  19. package/src/browser/workspacePreview.ts +28 -4
  20. package/src/cliMode.js +17 -3
  21. package/src/commands.js +15 -22
  22. package/src/config.js +42 -63
  23. package/src/configVault.js +204 -0
  24. package/src/configVault.ts +213 -0
  25. package/src/core/contextCompactor.js +70 -11
  26. package/src/core/contextCompactor.ts +83 -11
  27. package/src/creative/liveBridge.js +34 -1
  28. package/src/creative/liveBridge.ts +28 -1
  29. package/src/dynamicCatalogue.js +42 -73
  30. package/src/dynamicCatalogue.ts +74 -60
  31. package/src/entrypoint.js +77 -4
  32. package/src/headlessCli.js +304 -0
  33. package/src/headlessCli.ts +380 -0
  34. package/src/mcp/mcpClient.js +38 -11
  35. package/src/mcp/mcpClient.ts +44 -11
  36. package/src/mcp/mcpRegistry.js +2 -5
  37. package/src/mcp/mcpRegistry.ts +2 -5
  38. package/src/mcp/mcpSecurity.js +189 -0
  39. package/src/mcp/mcpSecurity.ts +190 -0
  40. package/src/observer/evidence.js +23 -0
  41. package/src/observer/evidence.ts +21 -0
  42. package/src/osKeychain.js +209 -0
  43. package/src/osKeychain.ts +245 -0
  44. package/src/providers/anthropic.js +61 -28
  45. package/src/providers/base.js +14 -0
  46. package/src/providers/byokHttp.js +354 -0
  47. package/src/providers/byokHttp.ts +454 -0
  48. package/src/providers/byokStream.js +657 -0
  49. package/src/providers/byokStream.ts +759 -0
  50. package/src/providers/dashscope-byok.js +47 -32
  51. package/src/providers/deepseek.js +43 -39
  52. package/src/providers/gemini.js +73 -38
  53. package/src/providers/moonshot.js +43 -33
  54. package/src/providers/muse.js +10 -10
  55. package/src/providers/ollama.js +46 -31
  56. package/src/providers/openai-compatible.js +57 -32
  57. package/src/providers/openrouter.js +77 -113
  58. package/src/providers/openrouter.ts +99 -118
  59. package/src/providers/qwen-byok.js +46 -23
  60. package/src/providers/toolContracts.js +9 -3
  61. package/src/providers/toolContracts.ts +9 -3
  62. package/src/providers/wireNormalizer.js +238 -0
  63. package/src/providers/wireNormalizer.ts +279 -0
  64. package/src/providers/xai.js +43 -33
  65. package/src/sandbox.js +77 -56
  66. package/src/sandboxPolicy.js +1208 -0
  67. package/src/sandboxPolicy.ts +1300 -0
  68. package/src/sessionJournal.js +47 -0
  69. package/src/sessionJournal.ts +49 -0
  70. package/src/tools/browserAutomator.js +13 -1
  71. package/src/tools/browserAutomator.ts +13 -0
  72. package/src/tools/creativeApps.js +2 -1
  73. package/src/tools/creativeApps.ts +2 -1
  74. package/src/tools/gameAssetFetcher.js +130 -26
  75. package/src/tools/gameAssetHarvester.js +80 -58
  76. package/src/tools/nativeEngine.js +1 -1
  77. package/src/tools/nativeEngine.ts +1 -1
  78. package/src/tools/osSandbox.js +473 -0
  79. package/src/tools/osSandbox.ts +554 -0
  80. package/src/tools/persistentShell.js +8 -3
  81. package/src/tools/registry.js +13 -0
  82. package/src/tools/subprocessEnv.js +197 -0
  83. package/src/tools/subprocessEnv.ts +212 -0
  84. package/src/tools/sysRun.js +39 -6
  85. package/src/tools/sysRun.ts +53 -7
  86. package/src/tools/toolScanner.js +596 -140
  87. package/src/tools/toolScanner.ts +665 -147
  88. package/src/tools/toolSelfRepair.js +243 -114
  89. package/src/tools/toolSelfRepair.ts +262 -111
  90. package/src/tools/webFetch.js +161 -24
  91. package/src/tools/webFetch.ts +157 -22
  92. package/src/tools/webSearch.js +33 -4
  93. package/src/tools/webSearch.ts +27 -4
  94. package/src/tui/sessionPicker.js +132 -35
  95. package/src/tui/sessionPicker.ts +153 -32
  96. package/src/tui/sessionPickerView.js +277 -34
  97. package/src/tui/sessionPickerView.ts +328 -34
  98. package/src/tui/statusLine.js +3 -0
  99. package/src/tui/statusLine.ts +5 -0
  100. package/src/tui/workspaceIdentity.js +133 -0
  101. package/src/tui/workspaceIdentity.ts +146 -0
@@ -0,0 +1,203 @@
1
+ /**
2
+ * Causyne Agent — Prompt Intent & Response Classification Helpers (Sector 3)
3
+ *
4
+ * Extracted from `AgentLoop` into a cohesive Strict TypeScript module.
5
+ * Re-exported from `src/agentLoop.ts` for full backward compatibility.
6
+ */
7
+
8
+ import { isDirectGameTask as isDirectGameTaskDecision } from '../decideTools.js';
9
+ import { isNoExecutionPrompt, isReadOnlyOrExplanatoryPrompt } from '../launchIntent.js';
10
+
11
+ export function isActionableTaskPrompt(text: string): boolean {
12
+ const t = (text || '').trim();
13
+ if (!t) return false;
14
+ // A no-execution request can be satisfied by analysis without mandatory tool calls.
15
+ if (isNoExecutionPrompt(t)) return false;
16
+ const pureGreeting = /^(hi|hello|hey|yo|halo|hai|p|assalamu['a]?[l]?aikum|good\s+(morning|afternoon|evening))[.!?, ]*$/i.test(t);
17
+ if (pureGreeting) return false;
18
+ const actionKeywords = /\b(continue|resume|proceed|lanjut\w*|create|build|make|write|code|implement|fix|optimize|refactor|generate|add|setup|install|run|open|launch|start|play|serve|preview|deploy|delete|remove|update|change|test|review|inspect|search|find|download|buat\w*|bikin\w*|perbaik\w*|tambah\w*|ubah\w*|hapus\w*|jalan\w*|pasang\w*|analis\w*|cek\w*|rancang\w*|desain\w*|kerjakan\w*|tolong\w*|bantu\w*|ganti\w*|tulis\w*|kembangkan\w*)\b/i;
19
+ if (actionKeywords.test(t)) return true;
20
+ return false; // Length alone does not turn an information question into an execution order.
21
+ }
22
+
23
+ export function isGenericHandoffResponse(text: string): boolean {
24
+ const answer = (text || '').trim();
25
+ if (!answer || answer.length > 500) return false;
26
+ const lower = answer.toLowerCase();
27
+ const handoff = /\b(let me know what you would like to do next|what would you like me to do next|how (can|may) i help|what can i help you with|feel free to (ask|tell me))\b/i.test(lower);
28
+ const verifiedOutcome = /\b(completed|changed|set the (desktop|wallpaper)|saved|created|installed|verified|downloaded|finished)\b/i.test(lower);
29
+ return handoff && !verifiedOutcome;
30
+ }
31
+
32
+ export function isDesktopWallpaperChangePrompt(text: string): boolean {
33
+ const t = (text || '').trim();
34
+ if (!t) return false;
35
+ // Explanatory questions or prompts that explicitly forbid execution are never wallpaper mutation requests
36
+ if (isNoExecutionPrompt(t) || isReadOnlyOrExplanatoryPrompt(t)) return false;
37
+ if (/^(?:why|how|what|does|can\s+you\s+explain|explain|tell\s+me|show\s+me\s+how)\b/i.test(t)) return false;
38
+ if (/\b(?:why|how)\s+does\b/i.test(t)) return false;
39
+ // Debugging wallpaper-related source or regexes is not a request to mutate macOS.
40
+ if (/\b(?:test|review|audit|analy[sz]e|debug|refactor|inspect|explain|write|implement)\b[\s\S]{0,140}\b(?:regex|code|source|logic|verification|readback|function|script|test)\b/i.test(t)) return false;
41
+ return /\b(?:change|set|switch|replace)\s+(?:(?:my|the|this|current|desktop|mac|macos)\s+){0,4}(?:desktop picture|wallpaper|desktop background)\b/i.test(t);
42
+ }
43
+
44
+ export function isExecutionOrLaunchTaskPrompt(text: string): boolean {
45
+ const t = (text || '').trim();
46
+ if (!t) return false;
47
+ return /\b(open|launch|start|run|play|serve|preview)\b/i.test(t)
48
+ && !/\b(create|build|make|write|code|implement|generate|refactor)\b/i.test(t);
49
+ }
50
+
51
+ export function isCodeAuthoringTaskPrompt(text: string): boolean {
52
+ const t = (text || '').trim();
53
+ if (!t) return false;
54
+ if (isExecutionOrLaunchTaskPrompt(t)) return false;
55
+ return /\b(create|build|make|write|code|implement|generate|game|3js|three?\.?js|three?js|app)\b/i.test(t);
56
+ }
57
+
58
+ export function extractSkillIdFromPrompt(prompt: string): string {
59
+ const text = String(prompt || '').trim();
60
+ if (!text) return '';
61
+ const stopWords = new Set([
62
+ 'the', 'a', 'an', 'this', 'that', 'from', 'in', 'with',
63
+ 'using', 'for', 'to', 'by', 'and', 'or', 'of'
64
+ ]);
65
+ const leadingTrim = new Set(['`', '"', "'", '(', '[']);
66
+ const trailingTrim = new Set(['`', '"', "'", ')', ',', '.', ';', ':', '!', '?', ']', '\\']);
67
+ const cleanCandidate = (raw: string): string => {
68
+ const trimmed = raw.trim();
69
+ let start = 0;
70
+ let end = trimmed.length;
71
+ while (start < end && leadingTrim.has(trimmed[start]!)) start++;
72
+ while (end > start && trailingTrim.has(trimmed[end - 1]!)) end--;
73
+ const stripped = trimmed.slice(start, end);
74
+ if (!stripped || stopWords.has(stripped.toLowerCase())) return '';
75
+ if (/^(?:fs_read_skill|fs_read_skil|read_skill|read_skil|tool_search)$/i.test(stripped)) {
76
+ return '';
77
+ }
78
+ return stripped;
79
+ };
80
+ const isFileExt = (candidate: string): boolean =>
81
+ /\.(?:ts|tsx|js|jsx|mjs|cjs|py|go|rs|java|kt|json|html|css|gradle|apk|aab|dex)$/i.test(candidate);
82
+
83
+ const cuedSlashMatch = text.match(
84
+ /(?:\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
85
+ );
86
+ if (cuedSlashMatch?.[1]) {
87
+ const candidate = cleanCandidate(cuedSlashMatch[1]);
88
+ if (candidate && !isFileExt(candidate)) {
89
+ return candidate;
90
+ }
91
+ }
92
+ 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)) {
93
+ const candidate = cleanCandidate(m[1] || '');
94
+ if (candidate && !isFileExt(candidate)) {
95
+ return candidate;
96
+ }
97
+ }
98
+ const explicitQuotedMatch = text.match(
99
+ /(?:\bskill_id|\bskill)(?:\s*[:=]\s*|\s+)(?:the\s+)?[`"']([^`"'\n\r]{2,120})[`"']/i
100
+ );
101
+ if (explicitQuotedMatch?.[1]) {
102
+ const candidate = cleanCandidate(explicitQuotedMatch[1]);
103
+ if (candidate) return candidate;
104
+ }
105
+ const bareMatch = text.match(
106
+ /(?:\bskill_id\s*[:=]\s*|\bskill\s*[:=]\s*|\bskill\s+(?:called\s+|named\s+)?)([a-zA-Z0-9][a-zA-Z0-9_.-]{1,120})/i
107
+ );
108
+ if (bareMatch?.[1]) {
109
+ const candidate = cleanCandidate(bareMatch[1]);
110
+ if (candidate) return candidate;
111
+ }
112
+ return '';
113
+ }
114
+
115
+ export function isDirectGameTask(text: string): boolean {
116
+ return isDirectGameTaskDecision(text);
117
+ }
118
+
119
+ export function isProviderPlanOrQuotaRefusal(text: string): boolean {
120
+ if (!text || typeof text !== 'string') return false;
121
+ const trimmed = text.trim();
122
+ if (!trimmed || trimmed.length > 320) return false;
123
+ if (/^upgrade your plan to continue\.?$/i.test(trimmed)) return true;
124
+ return /\b(upgrade your plan to continue|insufficient[_ ]quota|credit balance is too low|billing hard limit|quota exceeded for|plan limit reached|subscription required to continue)\b/i.test(trimmed);
125
+ }
126
+
127
+ /**
128
+ * Detects when an agent response is an intermediate mid-task progress note or
129
+ * transition announcement rather than a finished answer.
130
+ */
131
+ export function isMidTaskProgressText(text: string): boolean {
132
+ if (!text || typeof text !== 'string') return false;
133
+ const trimmed = text.trim();
134
+ if (!trimmed || trimmed.length > 480) return false;
135
+
136
+ const lower = trimmed.toLowerCase();
137
+ if (
138
+ lower.includes('?') ||
139
+ lower.includes('let me know') ||
140
+ lower.includes('how can i help') ||
141
+ lower.includes('how may i help') ||
142
+ lower.includes('how can i assist') ||
143
+ lower.includes('what would you like') ||
144
+ lower.includes('what can i help') ||
145
+ lower.includes('feel free to')
146
+ ) {
147
+ return false;
148
+ }
149
+
150
+ if (trimmed.includes('```')) return false;
151
+
152
+ const sentences = trimmed
153
+ .split(/(?:(?<=[.!])\s+|\n+)/)
154
+ .map(s => s.trim())
155
+ .filter(Boolean);
156
+ const lastSentence = (sentences[sentences.length - 1] || trimmed).trim();
157
+ const lastLower = lastSentence.toLowerCase();
158
+
159
+ if (trimmed.length <= 280 && (trimmed.endsWith(':') || trimmed.endsWith('...') || trimmed.endsWith('…'))) {
160
+ return true;
161
+ }
162
+
163
+ const intentPrefixes = [
164
+ 'let me ',
165
+ "i'll ",
166
+ 'i will ',
167
+ 'now i ',
168
+ 'now let me ',
169
+ "now i'll ",
170
+ 'now i will ',
171
+ 'next, i ',
172
+ 'next i ',
173
+ "next, i'll ",
174
+ "next i'll ",
175
+ 'first, i ',
176
+ 'first i ',
177
+ 'let us ',
178
+ "let's ",
179
+ 'i shall ',
180
+ 'we will ',
181
+ "we'll ",
182
+ 'i am going to ',
183
+ "i'm going to ",
184
+ 'going to '
185
+ ];
186
+ if (intentPrefixes.some(prefix => lastLower.startsWith(prefix) || (trimmed.length <= 280 && lower.startsWith(prefix)))) {
187
+ if (!/\b(?:task completed|all done|everything is ready|finished|complete\.)\b/i.test(lastSentence)) {
188
+ return true;
189
+ }
190
+ }
191
+
192
+ const gerundStart = /^(?:now\s+|next,?\s+|currently\s+|still\s+)?(?:writing|pulling|checking|inspecting|building|creating|updating|applying|implementing|generating|fetching|downloading|testing|running|fixing|setting up|configuring|refactoring|adding|modifying|replacing|launching|starting|verifying|confirming|reading|searching|analyzing|preparing|compiling|rendering|extracting|installing|opening|switching|retrying|continuing)\b/i;
193
+ if (gerundStart.test(lastSentence) && lastSentence.length <= 220) {
194
+ return true;
195
+ }
196
+
197
+ const actionNowSuffix = /\b(?:writing|pulling|checking|inspecting|building|creating|updating|applying|implementing|generating|fetching|downloading|testing|running|fixing|configuring|refactoring|adding|modifying|replacing|launching|starting|verifying|confirming|reading|searching|analyzing|preparing|compiling|rendering|extracting)\b[^.!?\n]{1,120}\b(?:now|next)\.?$/i;
198
+ if (actionNowSuffix.test(lastSentence)) {
199
+ return true;
200
+ }
201
+
202
+ return false;
203
+ }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Causyne Agent — Tool Argument Normalization & Pre-Execution Validation (Sector 3)
3
+ *
4
+ * Extracted from `AgentLoop.validateToolArgs` into a standalone Strict TypeScript
5
+ * module so workspace-relative path normalization and required-argument checks
6
+ * are independently testable.
7
+ */
8
+ import os from 'node:os';
9
+ import path from 'node:path';
10
+ const NON_PATH_TARGET_TOOLS = new Set(['vision_inspect_ui', 'astryx_oracle', 'desktop_act']);
11
+ function resolveWorkspaceArgPath(raw, baseDir) {
12
+ const val = raw.trim();
13
+ if (!val || /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(val)) {
14
+ return null;
15
+ }
16
+ if (val === '~') {
17
+ return os.homedir();
18
+ }
19
+ if (val.startsWith('~/') || val.startsWith('~\\')) {
20
+ return path.join(os.homedir(), val.slice(2));
21
+ }
22
+ if (!path.isAbsolute(val)) {
23
+ return path.resolve(baseDir, val);
24
+ }
25
+ return val;
26
+ }
27
+ /**
28
+ * Normalizes workspace-relative file path arguments in-place and validates
29
+ * required tool parameters prior to sandbox and hook evaluation.
30
+ * Returns `null` when valid, or an actionable error message when invalid.
31
+ */
32
+ export function validateAndNormalizeToolArgs(toolName, args, workspaceRoot = process.cwd()) {
33
+ if (!args || typeof args !== 'object' || Array.isArray(args)) {
34
+ return 'Tool arguments must be a JSON object';
35
+ }
36
+ const record = args;
37
+ const baseDir = workspaceRoot || process.cwd();
38
+ // 1. File operations must resolve to absolute paths (fs_read_skill uses skill-relative file_path)
39
+ if (toolName !== 'fs_read_skill') {
40
+ const pathFields = [
41
+ 'path', 'searchPath', 'cwd', 'directory',
42
+ 'source', 'destination', 'file_path', 'filePath', 'filepath',
43
+ 'targetFile', 'outputFile', 'outputPath',
44
+ ...(NON_PATH_TARGET_TOOLS.has(toolName) ? [] : ['target'])
45
+ ];
46
+ for (const field of pathFields) {
47
+ const value = record[field];
48
+ if (typeof value === 'string' && value) {
49
+ const resolved = resolveWorkspaceArgPath(value, baseDir);
50
+ if (resolved !== null) {
51
+ record[field] = resolved;
52
+ }
53
+ }
54
+ }
55
+ if (Array.isArray(record.target_directories)) {
56
+ record.target_directories = record.target_directories.map((entry) => {
57
+ if (typeof entry !== 'string')
58
+ return entry;
59
+ return resolveWorkspaceArgPath(entry, baseDir) ?? entry;
60
+ });
61
+ }
62
+ }
63
+ // 2. Terminal commands must have a command string
64
+ if ((toolName === 'sysRun' || toolName === 'sysRunBg') && !record.command) {
65
+ return 'Missing required "command" argument';
66
+ }
67
+ // 3. File write must have a path AND content
68
+ if (toolName === 'fs_write' && !record.path) {
69
+ return 'Missing required "path" argument';
70
+ }
71
+ if (toolName === 'fs_write' && record.content === undefined) {
72
+ return 'Missing required "content" argument';
73
+ }
74
+ // 4. Search must have a query
75
+ if ((toolName === 'codebase_search' || toolName === 'web_search') && !record.query) {
76
+ return 'Missing required "query" argument';
77
+ }
78
+ // 5. Tool search must have a query, pack, or names array
79
+ if (toolName === 'tool_search') {
80
+ const q = typeof record.query === 'string'
81
+ ? record.query.trim()
82
+ : (Array.isArray(record.query) ? record.query.map(String).join(' ').trim() : '');
83
+ const p = typeof record.pack === 'string' ? record.pack.trim() : '';
84
+ const n = Array.isArray(record.names) && record.names.length > 0;
85
+ if (!q && !p && !n) {
86
+ return 'Missing required "query" or "pack" argument';
87
+ }
88
+ }
89
+ // 6. Skill reader must have a non-empty skill_id
90
+ if (toolName === 'fs_read_skill') {
91
+ const sid = typeof record.skill_id === 'string' ? record.skill_id.trim() : '';
92
+ if (!sid) {
93
+ return 'Missing required "skill_id" argument';
94
+ }
95
+ }
96
+ return null;
97
+ }
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Causyne Agent — Tool Argument Normalization & Pre-Execution Validation (Sector 3)
3
+ *
4
+ * Extracted from `AgentLoop.validateToolArgs` into a standalone Strict TypeScript
5
+ * module so workspace-relative path normalization and required-argument checks
6
+ * are independently testable.
7
+ */
8
+
9
+ import os from 'node:os';
10
+ import path from 'node:path';
11
+
12
+ const NON_PATH_TARGET_TOOLS = new Set(['vision_inspect_ui', 'astryx_oracle', 'desktop_act']);
13
+
14
+ function resolveWorkspaceArgPath(raw: string, baseDir: string): string | null {
15
+ const val = raw.trim();
16
+ if (!val || /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(val)) {
17
+ return null;
18
+ }
19
+ if (val === '~') {
20
+ return os.homedir();
21
+ }
22
+ if (val.startsWith('~/') || val.startsWith('~\\')) {
23
+ return path.join(os.homedir(), val.slice(2));
24
+ }
25
+ if (!path.isAbsolute(val)) {
26
+ return path.resolve(baseDir, val);
27
+ }
28
+ return val;
29
+ }
30
+
31
+ /**
32
+ * Normalizes workspace-relative file path arguments in-place and validates
33
+ * required tool parameters prior to sandbox and hook evaluation.
34
+ * Returns `null` when valid, or an actionable error message when invalid.
35
+ */
36
+ export function validateAndNormalizeToolArgs(
37
+ toolName: string,
38
+ args: unknown,
39
+ workspaceRoot: string = process.cwd()
40
+ ): string | null {
41
+ if (!args || typeof args !== 'object' || Array.isArray(args)) {
42
+ return 'Tool arguments must be a JSON object';
43
+ }
44
+
45
+ const record = args as Record<string, unknown>;
46
+ const baseDir = workspaceRoot || process.cwd();
47
+
48
+ // 1. File operations must resolve to absolute paths (fs_read_skill uses skill-relative file_path)
49
+ if (toolName !== 'fs_read_skill') {
50
+ const pathFields = [
51
+ 'path', 'searchPath', 'cwd', 'directory',
52
+ 'source', 'destination', 'file_path', 'filePath', 'filepath',
53
+ 'targetFile', 'outputFile', 'outputPath',
54
+ ...(NON_PATH_TARGET_TOOLS.has(toolName) ? [] : ['target'])
55
+ ];
56
+ for (const field of pathFields) {
57
+ const value = record[field];
58
+ if (typeof value === 'string' && value) {
59
+ const resolved = resolveWorkspaceArgPath(value, baseDir);
60
+ if (resolved !== null) {
61
+ record[field] = resolved;
62
+ }
63
+ }
64
+ }
65
+ if (Array.isArray(record.target_directories)) {
66
+ record.target_directories = record.target_directories.map((entry: unknown) => {
67
+ if (typeof entry !== 'string') return entry;
68
+ return resolveWorkspaceArgPath(entry, baseDir) ?? entry;
69
+ });
70
+ }
71
+ }
72
+
73
+ // 2. Terminal commands must have a command string
74
+ if ((toolName === 'sysRun' || toolName === 'sysRunBg') && !record.command) {
75
+ return 'Missing required "command" argument';
76
+ }
77
+
78
+ // 3. File write must have a path AND content
79
+ if (toolName === 'fs_write' && !record.path) {
80
+ return 'Missing required "path" argument';
81
+ }
82
+ if (toolName === 'fs_write' && record.content === undefined) {
83
+ return 'Missing required "content" argument';
84
+ }
85
+
86
+ // 4. Search must have a query
87
+ if ((toolName === 'codebase_search' || toolName === 'web_search') && !record.query) {
88
+ return 'Missing required "query" argument';
89
+ }
90
+
91
+ // 5. Tool search must have a query, pack, or names array
92
+ if (toolName === 'tool_search') {
93
+ const q = typeof record.query === 'string'
94
+ ? record.query.trim()
95
+ : (Array.isArray(record.query) ? record.query.map(String).join(' ').trim() : '');
96
+ const p = typeof record.pack === 'string' ? record.pack.trim() : '';
97
+ const n = Array.isArray(record.names) && record.names.length > 0;
98
+ if (!q && !p && !n) {
99
+ return 'Missing required "query" or "pack" argument';
100
+ }
101
+ }
102
+
103
+ // 6. Skill reader must have a non-empty skill_id
104
+ if (toolName === 'fs_read_skill') {
105
+ const sid = typeof record.skill_id === 'string' ? record.skill_id.trim() : '';
106
+ if (!sid) {
107
+ return 'Missing required "skill_id" argument';
108
+ }
109
+ }
110
+
111
+ return null;
112
+ }