@causyne/agent 1.20.121 → 1.20.122

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 (256) hide show
  1. package/README.md +3 -3
  2. package/package.json +1 -1
  3. package/src/acp/agentCatalog.js +81 -26
  4. package/src/acp/agentCatalog.ts +73 -29
  5. package/src/acp/client.js +210 -53
  6. package/src/acp/client.ts +202 -52
  7. package/src/acp/peerProfiles.js +55 -22
  8. package/src/acp/peerProfiles.ts +51 -22
  9. package/src/acp/protocol.js +37 -8
  10. package/src/acp/protocol.ts +30 -8
  11. package/src/acp/server.js +123 -25
  12. package/src/acp/server.ts +124 -24
  13. package/src/agent/errorClassifier.js +6 -2
  14. package/src/agent/errorClassifier.ts +6 -2
  15. package/src/agentLoop.js +11 -5
  16. package/src/agentLoop.ts +11 -5
  17. package/src/approvalGrants.js +19 -7
  18. package/src/approvalGrants.ts +20 -7
  19. package/src/approvalPolicy.js +48 -15
  20. package/src/approvalPolicy.ts +46 -15
  21. package/src/autoUpdate.js +5 -2
  22. package/src/autoUpdate.ts +5 -2
  23. package/src/browser/causyneBrowser.js +3 -2
  24. package/src/browser/causyneBrowser.ts +3 -2
  25. package/src/browser/searchProviders.js +1 -1
  26. package/src/browser/searchProviders.ts +1 -1
  27. package/src/config.js +287 -250
  28. package/src/config.ts +342 -0
  29. package/src/configVault.js +84 -17
  30. package/src/configVault.ts +77 -17
  31. package/src/continuum/compactor.js +2 -1
  32. package/src/continuum/compactor.ts +2 -1
  33. package/src/continuum/sanitizer.js +10 -3
  34. package/src/continuum/sanitizer.ts +9 -3
  35. package/src/continuum/ui/continuumPickerView.js +3 -2
  36. package/src/continuum/ui/continuumPickerView.ts +3 -2
  37. package/src/cortex/vectorDb.js +26 -15
  38. package/src/cortex/vectorDb.ts +26 -16
  39. package/src/creative/liveBridge.js +7 -5
  40. package/src/creative/liveBridge.ts +7 -5
  41. package/src/creative/studioScripts.js +16 -5
  42. package/src/creative/studioScripts.ts +14 -5
  43. package/src/decisionPolicy.js +16 -4
  44. package/src/decisionPolicy.ts +14 -4
  45. package/src/documentEngine/antiSlopAuditor.js +10 -5
  46. package/src/documentEngine/antiSlopAuditor.ts +11 -5
  47. package/src/documentEngine/documentForge.js +47 -15
  48. package/src/documentEngine/documentForge.ts +43 -14
  49. package/src/engines/design.js +2 -1
  50. package/src/engines/design.ts +2 -1
  51. package/src/engines/film.js +4 -4
  52. package/src/engines/film.ts +2 -2
  53. package/src/engines/light.js +2 -1
  54. package/src/engines/light.ts +2 -1
  55. package/src/engines/registry.js +1 -1
  56. package/src/engines/registry.ts +1 -1
  57. package/src/engines/reverseHarness.js +4 -3
  58. package/src/engines/reverseHarness.ts +4 -3
  59. package/src/headlessCli.js +2 -1
  60. package/src/headlessCli.ts +2 -1
  61. package/src/historyPruner.js +3 -2
  62. package/src/historyPruner.ts +3 -2
  63. package/src/hooks.js +3 -0
  64. package/src/hooks.ts +3 -0
  65. package/src/implementationPlan.js +21 -11
  66. package/src/implementationPlan.ts +21 -11
  67. package/src/infra/atomicWriter.js +4 -1
  68. package/src/infra/atomicWriter.ts +4 -1
  69. package/src/launchIntent.js +1 -1
  70. package/src/launchIntent.ts +1 -1
  71. package/src/memory/scopedFacts.js +1 -1
  72. package/src/memory/scopedFacts.ts +1 -1
  73. package/src/memory/symbolFolder.js +1 -1
  74. package/src/memory/symbolFolder.ts +1 -1
  75. package/src/modelRouter.js +1 -1
  76. package/src/modelRouter.ts +1 -1
  77. package/src/observer/evidence.js +10 -4
  78. package/src/observer/evidence.ts +10 -4
  79. package/src/osKeychain.js +62 -8
  80. package/src/osKeychain.ts +50 -8
  81. package/src/perception.js +3 -2
  82. package/src/perception.ts +3 -2
  83. package/src/planCache.js +2 -2
  84. package/src/planCache.ts +2 -2
  85. package/src/pluginsFactory/pluginsFactory.js +19 -11
  86. package/src/pluginsFactory/pluginsFactory.ts +18 -11
  87. package/src/promptMentions.js +2 -2
  88. package/src/promptMentions.ts +2 -2
  89. package/src/providers/acp.js +1 -1
  90. package/src/providers/acp.ts +1 -1
  91. package/src/providers/anthropic.js +327 -401
  92. package/src/providers/anthropic.ts +386 -0
  93. package/src/providers/antigravity.js +10 -4
  94. package/src/providers/antigravity.ts +10 -4
  95. package/src/providers/base.js +221 -319
  96. package/src/providers/base.ts +340 -0
  97. package/src/providers/byokHttp.js +58 -15
  98. package/src/providers/byokHttp.ts +59 -16
  99. package/src/providers/byokStream.js +142 -51
  100. package/src/providers/byokStream.ts +146 -42
  101. package/src/providers/dashscope-byok.js +97 -89
  102. package/src/providers/dashscope-byok.ts +114 -0
  103. package/src/providers/deepseek.js +73 -72
  104. package/src/providers/deepseek.ts +99 -0
  105. package/src/providers/factory.js +35 -28
  106. package/src/providers/factory.ts +40 -0
  107. package/src/providers/gemini.js +227 -278
  108. package/src/providers/gemini.ts +261 -0
  109. package/src/providers/loopGuard.js +9 -5
  110. package/src/providers/loopGuard.ts +10 -5
  111. package/src/providers/moonshot.js +70 -72
  112. package/src/providers/moonshot.ts +93 -0
  113. package/src/providers/muse.js +82 -152
  114. package/src/providers/muse.ts +122 -0
  115. package/src/providers/ollama.js +114 -106
  116. package/src/providers/ollama.ts +135 -0
  117. package/src/providers/openai-compatible.js +113 -96
  118. package/src/providers/openai-compatible.ts +139 -0
  119. package/src/providers/openai.js +22 -15
  120. package/src/providers/openai.ts +30 -0
  121. package/src/providers/openrouter.js +136 -74
  122. package/src/providers/openrouter.ts +133 -72
  123. package/src/providers/pi.js +6 -0
  124. package/src/providers/pi.ts +6 -0
  125. package/src/providers/qwen-byok.js +96 -87
  126. package/src/providers/qwen-byok.ts +113 -0
  127. package/src/providers/toolContracts.js +40 -14
  128. package/src/providers/toolContracts.ts +35 -14
  129. package/src/providers/wireNormalizer.js +78 -11
  130. package/src/providers/wireNormalizer.ts +68 -12
  131. package/src/providers/xai.js +73 -72
  132. package/src/providers/xai.ts +97 -0
  133. package/src/reliability/assetEvidence.js +4 -2
  134. package/src/reliability/assetEvidence.ts +4 -2
  135. package/src/sandbox.js +489 -554
  136. package/src/sandbox.ts +552 -0
  137. package/src/sandboxPolicy.js +95 -16
  138. package/src/sandboxPolicy.ts +97 -16
  139. package/src/sessionJournal.js +8 -3
  140. package/src/sessionJournal.ts +9 -3
  141. package/src/skills/skillResourceSafety.js +19 -8
  142. package/src/skills/skillResourceSafety.ts +16 -7
  143. package/src/skillsManager.js +3 -3
  144. package/src/skillsManager.ts +3 -3
  145. package/src/smartToolsUse.js +28 -4
  146. package/src/smartToolsUse.ts +29 -7
  147. package/src/stallGuard.js +45 -22
  148. package/src/stallGuard.ts +46 -22
  149. package/src/subagentJournal.js +6 -4
  150. package/src/subagentJournal.ts +6 -4
  151. package/src/textDiff.js +6 -1
  152. package/src/textDiff.ts +6 -1
  153. package/src/timeMachine.js +7 -1
  154. package/src/timeMachine.ts +7 -1
  155. package/src/tokenTracker.js +43 -28
  156. package/src/tokenTracker.ts +44 -30
  157. package/src/toolPacks.js +3 -1
  158. package/src/toolPacks.ts +3 -1
  159. package/src/tools/archive.js +245 -35
  160. package/src/tools/archive.ts +244 -35
  161. package/src/tools/computerUse.js +7 -3
  162. package/src/tools/computerUse.ts +7 -3
  163. package/src/tools/creativeApps.js +13 -8
  164. package/src/tools/creativeApps.ts +22 -9
  165. package/src/tools/deferredMcpSearch.js +26 -14
  166. package/src/tools/deferredMcpSearch.ts +26 -14
  167. package/src/tools/desktopOpen.js +69 -10
  168. package/src/tools/desktopOpen.ts +70 -11
  169. package/src/tools/documentForge.js +167 -82
  170. package/src/tools/documentForge.ts +169 -84
  171. package/src/tools/fsEdit.js +101 -30
  172. package/src/tools/fsEdit.ts +105 -32
  173. package/src/tools/fsFind.js +8 -5
  174. package/src/tools/fsFind.ts +7 -4
  175. package/src/tools/fsRead.js +119 -13
  176. package/src/tools/fsRead.ts +124 -13
  177. package/src/tools/fsWrite.js +17 -5
  178. package/src/tools/fsWrite.ts +17 -7
  179. package/src/tools/generateMediaViaApi.js +82 -19
  180. package/src/tools/generateMediaViaApi.ts +80 -19
  181. package/src/tools/memoryRecall.js +62 -11
  182. package/src/tools/memoryRecall.ts +70 -13
  183. package/src/tools/memoryWrite.js +27 -14
  184. package/src/tools/memoryWrite.ts +30 -14
  185. package/src/tools/multiEdit.js +100 -30
  186. package/src/tools/multiEdit.ts +104 -32
  187. package/src/tools/nativeEngine.js +33 -18
  188. package/src/tools/nativeEngine.ts +31 -18
  189. package/src/tools/openSourceToolProvisioner.js +49 -14
  190. package/src/tools/openSourceToolProvisioner.ts +54 -15
  191. package/src/tools/osSandbox.js +54 -14
  192. package/src/tools/osSandbox.ts +48 -14
  193. package/src/tools/payloadSanitizer.js +40 -8
  194. package/src/tools/payloadSanitizer.ts +39 -8
  195. package/src/tools/peerAgent.js +96 -34
  196. package/src/tools/peerAgent.ts +114 -37
  197. package/src/tools/pluginsFactory.js +38 -6
  198. package/src/tools/pluginsFactory.ts +42 -6
  199. package/src/tools/readNativeSkill.js +10 -8
  200. package/src/tools/readNativeSkill.ts +10 -8
  201. package/src/tools/requestDecision.js +10 -3
  202. package/src/tools/requestDecision.ts +10 -3
  203. package/src/tools/resolveAutomator.js +91 -17
  204. package/src/tools/resolveAutomator.ts +102 -17
  205. package/src/tools/reverseEngineering.js +168 -41
  206. package/src/tools/reverseEngineering.ts +161 -41
  207. package/src/tools/sysRun.js +69 -29
  208. package/src/tools/sysRun.ts +66 -24
  209. package/src/tools/toolDispatch.js +24 -1
  210. package/src/tools/toolDispatch.ts +21 -1
  211. package/src/tools/toolOutputStore.js +62 -23
  212. package/src/tools/toolOutputStore.ts +56 -23
  213. package/src/tools/toolScanner.js +13 -10
  214. package/src/tools/toolScanner.ts +13 -10
  215. package/src/tools/toolSelfRepair.js +94 -28
  216. package/src/tools/toolSelfRepair.ts +96 -28
  217. package/src/tools/uiForge.js +71 -6
  218. package/src/tools/uiForge.ts +74 -6
  219. package/src/tools/viewImage.js +62 -17
  220. package/src/tools/viewImage.ts +57 -12
  221. package/src/tools/visionInspector.js +15 -3
  222. package/src/tools/visionInspector.ts +15 -3
  223. package/src/tools/walkerSafety.js +2 -0
  224. package/src/tools/walkerSafety.ts +1 -0
  225. package/src/tools/webFetch.js +105 -10
  226. package/src/tools/webFetch.ts +105 -11
  227. package/src/tui/banner.js +3 -2
  228. package/src/tui/banner.ts +3 -2
  229. package/src/tui/consoleGuard.js +12 -4
  230. package/src/tui/consoleGuard.ts +9 -4
  231. package/src/tui/messageInteraction.js +2 -3
  232. package/src/tui/messageInteraction.ts +2 -3
  233. package/src/tui/modelPicker.js +1 -0
  234. package/src/tui/modelPicker.ts +1 -0
  235. package/src/tui/overlay.js +3 -1
  236. package/src/tui/overlay.ts +3 -1
  237. package/src/tui/sessionPicker.js +3 -2
  238. package/src/tui/sessionPicker.ts +3 -2
  239. package/src/tui/sessionPickerView.js +7 -1
  240. package/src/tui/sessionPickerView.ts +6 -1
  241. package/src/tui/toolOutputNormalizer.js +2 -3
  242. package/src/tui/toolOutputNormalizer.ts +4 -3
  243. package/src/tui/viewport.js +4 -4
  244. package/src/tui/viewport.ts +5 -5
  245. package/src/tui/workspaceIdentity.js +2 -1
  246. package/src/tui/workspaceIdentity.ts +2 -1
  247. package/src/uncertainty.js +8 -3
  248. package/src/uncertainty.ts +8 -3
  249. package/src/utils/paths.js +8 -5
  250. package/src/utils/paths.ts +9 -7
  251. package/src/vfeTracker.js +9 -3
  252. package/src/vfeTracker.ts +9 -3
  253. package/src/config.d.ts +0 -2
  254. package/src/providers/base.d.ts +0 -94
  255. package/src/providers/factory.d.ts +0 -1
  256. package/src/sandbox.d.ts +0 -1
@@ -174,7 +174,7 @@ function resolveLocalRef(
174
174
  } else if (ref.startsWith('#/definitions/')) {
175
175
  key = ref.slice('#/definitions/'.length);
176
176
  }
177
- if (!key) return null;
177
+ if (!key || !Object.hasOwn(defs, key)) return null;
178
178
  const target = defs[key];
179
179
  return isPlainObject(target) ? target : null;
180
180
  }
@@ -197,7 +197,7 @@ function inspectSchemaForProvider(
197
197
  provider: string,
198
198
  issues: ToolScanIssue[]
199
199
  ): void {
200
- if (!isPlainObject(schema)) return;
200
+ if (path.length > 32 || !isPlainObject(schema)) return;
201
201
  const pathStr = path.join('.');
202
202
  const isGemini = provider === 'gemini';
203
203
 
@@ -246,7 +246,7 @@ function inspectSchemaForProvider(
246
246
  if (schema['type'] === 'object' && Array.isArray(schema['required']) && isPlainObject(schema['properties'])) {
247
247
  const props = schema['properties'];
248
248
  for (const req of schema['required']) {
249
- if (typeof req === 'string' && !(req in props)) {
249
+ if (typeof req === 'string' && !Object.hasOwn(props, req)) {
250
250
  issues.push({
251
251
  tool: toolName,
252
252
  path: `${pathStr}.required.${req}`,
@@ -636,7 +636,7 @@ function compileSchemaNode(
636
636
 
637
637
  if (adapted['type'] === 'object' && Array.isArray(adapted['required']) && isPlainObject(adapted['properties'])) {
638
638
  const props = adapted['properties'];
639
- const filtered = adapted['required'].filter((k): k is string => typeof k === 'string' && k in props);
639
+ const filtered = adapted['required'].filter((k): k is string => typeof k === 'string' && Object.hasOwn(props, k));
640
640
  if (filtered.length > 0) {
641
641
  adapted['required'] = filtered;
642
642
  } else {
@@ -827,8 +827,11 @@ export function scanAndAdaptToolsForProvider(
827
827
 
828
828
  if (isGemini) {
829
829
  const declaration: Record<string, unknown> = { name, description };
830
- if (rawSchema && !isEmptyObjectSchema(rawSchema)) {
831
- declaration['parameters'] = adaptSchemaForGemini(rawSchema, [], rewritten);
830
+ if (rawSchema) {
831
+ const compiled = adaptSchemaForGemini(rawSchema, [], rewritten);
832
+ if (!isEmptyObjectSchema(compiled)) {
833
+ declaration['parameters'] = compiled;
834
+ }
832
835
  }
833
836
  adapted = declaration;
834
837
  } else if (isAnthropic) {
@@ -967,7 +970,7 @@ function applyAtPath(
967
970
  const target = node as Record<string, unknown>;
968
971
 
969
972
  const [head, ...rest] = path;
970
- if (!head) return;
973
+ if (!head || head === '__proto__' || head === 'constructor' || head === 'prototype') return;
971
974
 
972
975
  if (head === '[]') {
973
976
  if (!Array.isArray(node)) return;
@@ -975,10 +978,10 @@ function applyAtPath(
975
978
  return;
976
979
  }
977
980
 
981
+ if (!Object.hasOwn(target, head)) return;
982
+
978
983
  if (rest.length === 0) {
979
- if (head in target) {
980
- target[head] = transform(target[head]);
981
- }
984
+ target[head] = transform(target[head]);
982
985
  return;
983
986
  }
984
987
 
@@ -171,11 +171,11 @@ for (const [alias, canonical] of Object.entries(TOOL_NAME_ALIASES)) {
171
171
  */
172
172
  export function canonicalizeToolName(rawName) {
173
173
  const normalized = String(rawName || '').replace(/\./g, '_');
174
- if (TOOL_NAME_ALIASES[normalized]) {
174
+ if (Object.hasOwn(TOOL_NAME_ALIASES, normalized) && TOOL_NAME_ALIASES[normalized]) {
175
175
  return TOOL_NAME_ALIASES[normalized];
176
176
  }
177
177
  const stripped = stripDelimiters(rawName);
178
- if (DELIMITER_FREE_TOOL_INDEX[stripped]) {
178
+ if (Object.hasOwn(DELIMITER_FREE_TOOL_INDEX, stripped) && DELIMITER_FREE_TOOL_INDEX[stripped]) {
179
179
  return DELIMITER_FREE_TOOL_INDEX[stripped];
180
180
  }
181
181
  return normalized;
@@ -310,9 +310,12 @@ export function repairJsonArguments(rawInput) {
310
310
  // 5. Native parse retry after stripping markdown/filler
311
311
  try {
312
312
  const parsed = JSON.parse(healed);
313
- if (parsed && typeof parsed === 'object') {
313
+ if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
314
314
  return { args: parsed, repaired: true, repairs };
315
315
  }
316
+ if (Array.isArray(parsed)) {
317
+ return { args: { items: parsed }, repaired: true, repairs: [...repairs, 'Wrapped array payload into items'] };
318
+ }
316
319
  }
317
320
  catch {
318
321
  // Proceed to syntax healing
@@ -451,6 +454,11 @@ function sanitizeUnescapedStringLiterals(input) {
451
454
  result += '\\t';
452
455
  continue;
453
456
  }
457
+ const code = char.charCodeAt(0);
458
+ if (code < 0x20) {
459
+ result += `\\u${code.toString(16).padStart(4, '0')}`;
460
+ continue;
461
+ }
454
462
  }
455
463
  result += char;
456
464
  }
@@ -460,16 +468,73 @@ function sanitizeUnescapedStringLiterals(input) {
460
468
  return result;
461
469
  }
462
470
  /**
463
- * Convert simple single-quoted JSON objects to valid double-quoted JSON.
471
+ * Convert single-quoted JSON keys/values to valid double-quoted JSON without
472
+ * mutating single quotes that already reside inside double-quoted strings.
464
473
  */
465
474
  function convertSingleQuotesToJson(input) {
466
- return input.replace(/'([^'\\]*(?:\\.[^'\\]*)*)'/g, (_match, inner) => {
467
- const escaped = inner
468
- .replace(/\\'/g, "'")
469
- .replace(/\\/g, '\\\\')
470
- .replace(/"/g, '\\"');
471
- return `"${escaped}"`;
472
- });
475
+ let out = '';
476
+ let i = 0;
477
+ let inDouble = false;
478
+ while (i < input.length) {
479
+ const ch = input[i];
480
+ if (inDouble) {
481
+ if (ch === '\\' && i + 1 < input.length) {
482
+ out += ch + input[i + 1];
483
+ i += 2;
484
+ continue;
485
+ }
486
+ if (ch === '"')
487
+ inDouble = false;
488
+ out += ch;
489
+ i++;
490
+ continue;
491
+ }
492
+ if (ch === '"') {
493
+ inDouble = true;
494
+ out += ch;
495
+ i++;
496
+ continue;
497
+ }
498
+ if (ch === "'") {
499
+ let j = i + 1;
500
+ let inner = '';
501
+ let closed = false;
502
+ while (j < input.length) {
503
+ const c = input[j];
504
+ if (c === '\\' && j + 1 < input.length) {
505
+ const next = input[j + 1];
506
+ if (next === "'") {
507
+ inner += "'";
508
+ }
509
+ else {
510
+ inner += '\\' + next;
511
+ }
512
+ j += 2;
513
+ continue;
514
+ }
515
+ if (c === "'") {
516
+ closed = true;
517
+ j++;
518
+ break;
519
+ }
520
+ if (c === '"') {
521
+ inner += '\\"';
522
+ }
523
+ else {
524
+ inner += c;
525
+ }
526
+ j++;
527
+ }
528
+ if (closed) {
529
+ out += `"${inner}"`;
530
+ i = j;
531
+ continue;
532
+ }
533
+ }
534
+ out += ch;
535
+ i++;
536
+ }
537
+ return out;
473
538
  }
474
539
  /**
475
540
  * Balance unmatched brackets/braces if the LLM output was truncated.
@@ -538,9 +603,9 @@ export function resolveParameterAliases(toolName, args, schema) {
538
603
  // 1. Specialized structural healing: fs_edit vs MultiEdit
539
604
  if (canonicalName === 'fs_edit') {
540
605
  // If edits is missing, synthesize from top-level fields
541
- if (!modified.edits && (modified.searchContent || modified.old_string || modified.oldText || modified.find)) {
542
- const search = (modified.searchContent || modified.old_string || modified.oldText || modified.find || '');
543
- const replace = (modified.replaceContent || modified.new_string || modified.newText || modified.replacement || '');
606
+ if (!modified.edits && (modified.searchContent !== undefined || modified.old_string !== undefined || modified.oldText !== undefined || modified.find !== undefined)) {
607
+ const search = (modified.searchContent ?? modified.old_string ?? modified.oldText ?? modified.find ?? '');
608
+ const replace = (modified.replaceContent ?? modified.new_string ?? modified.newText ?? modified.replacement ?? '');
544
609
  modified.edits = [{ searchContent: search, replaceContent: replace }];
545
610
  delete modified.searchContent;
546
611
  delete modified.old_string;
@@ -557,20 +622,20 @@ export function resolveParameterAliases(toolName, args, schema) {
557
622
  if (!item || typeof item !== 'object')
558
623
  return item;
559
624
  const normalizedItem = { ...item };
560
- if (!normalizedItem.searchContent && (normalizedItem.old_string || normalizedItem.oldText || normalizedItem.find)) {
561
- normalizedItem.searchContent = normalizedItem.old_string || normalizedItem.oldText || normalizedItem.find;
625
+ if (normalizedItem.searchContent === undefined && (normalizedItem.old_string !== undefined || normalizedItem.oldText !== undefined || normalizedItem.find !== undefined)) {
626
+ normalizedItem.searchContent = normalizedItem.old_string ?? normalizedItem.oldText ?? normalizedItem.find;
562
627
  }
563
- if (!normalizedItem.replaceContent && (normalizedItem.new_string || normalizedItem.newText || normalizedItem.replace)) {
564
- normalizedItem.replaceContent = normalizedItem.new_string || normalizedItem.newText || normalizedItem.replace;
628
+ if (normalizedItem.replaceContent === undefined && (normalizedItem.new_string !== undefined || normalizedItem.newText !== undefined || normalizedItem.replace !== undefined)) {
629
+ normalizedItem.replaceContent = normalizedItem.new_string ?? normalizedItem.newText ?? normalizedItem.replace;
565
630
  }
566
631
  return normalizedItem;
567
632
  });
568
633
  }
569
634
  }
570
635
  else if (canonicalName === 'MultiEdit') {
571
- if (!modified.edits && (modified.old_string || modified.searchContent || modified.oldText || modified.find)) {
572
- const search = (modified.old_string || modified.searchContent || modified.oldText || modified.find || '');
573
- const replace = (modified.new_string || modified.replaceContent || modified.newText || modified.replacement || '');
636
+ if (!modified.edits && (modified.old_string !== undefined || modified.searchContent !== undefined || modified.oldText !== undefined || modified.find !== undefined)) {
637
+ const search = (modified.old_string ?? modified.searchContent ?? modified.oldText ?? modified.find ?? '');
638
+ const replace = (modified.new_string ?? modified.replaceContent ?? modified.newText ?? modified.replacement ?? '');
574
639
  modified.edits = [{ old_string: search, new_string: replace }];
575
640
  delete modified.searchContent;
576
641
  delete modified.old_string;
@@ -587,11 +652,11 @@ export function resolveParameterAliases(toolName, args, schema) {
587
652
  if (!item || typeof item !== 'object')
588
653
  return item;
589
654
  const normalizedItem = { ...item };
590
- if (!normalizedItem.old_string && (normalizedItem.searchContent || normalizedItem.oldText || normalizedItem.find)) {
591
- normalizedItem.old_string = normalizedItem.searchContent || normalizedItem.oldText || normalizedItem.find;
655
+ if (normalizedItem.old_string === undefined && (normalizedItem.searchContent !== undefined || normalizedItem.oldText !== undefined || normalizedItem.find !== undefined)) {
656
+ normalizedItem.old_string = normalizedItem.searchContent ?? normalizedItem.oldText ?? normalizedItem.find;
592
657
  }
593
- if (!normalizedItem.new_string && (normalizedItem.replaceContent || normalizedItem.newText || normalizedItem.replace)) {
594
- normalizedItem.new_string = normalizedItem.replaceContent || normalizedItem.newText || normalizedItem.replace;
658
+ if (normalizedItem.new_string === undefined && (normalizedItem.replaceContent !== undefined || normalizedItem.newText !== undefined || normalizedItem.replace !== undefined)) {
659
+ normalizedItem.new_string = normalizedItem.replaceContent ?? normalizedItem.newText ?? normalizedItem.replace;
595
660
  }
596
661
  return normalizedItem;
597
662
  });
@@ -925,6 +990,7 @@ function coerceValueBySchema(key, val, propSchema, pathLabel, repairs, depth) {
925
990
  if (timeMatch && timeMatch[1]) {
926
991
  const rawVal = parseFloat(timeMatch[1]);
927
992
  const unit = (timeMatch[2] || '').toLowerCase();
993
+ const isExplicitMsKey = key === 'timeoutMs' || key === 'timeout_ms';
928
994
  let ms = rawVal;
929
995
  if (unit === 'ms')
930
996
  ms = rawVal;
@@ -933,7 +999,7 @@ function coerceValueBySchema(key, val, propSchema, pathLabel, repairs, depth) {
933
999
  else if (unit === 's')
934
1000
  ms = rawVal * 1000;
935
1001
  else
936
- ms = rawVal <= 600 ? rawVal * 1000 : rawVal;
1002
+ ms = (!isExplicitMsKey && rawVal <= 600) ? rawVal * 1000 : rawVal;
937
1003
  const normalized = expectedType === 'integer' ? Math.round(ms) : ms;
938
1004
  repairs.push(`Normalized time string "${val}" -> ${normalized}ms for parameter '${pathLabel}'`);
939
1005
  return normalized;
@@ -946,7 +1012,7 @@ function coerceValueBySchema(key, val, propSchema, pathLabel, repairs, depth) {
946
1012
  }
947
1013
  }
948
1014
  }
949
- else if (typeof val === 'number' && (key === 'timeout' || key === 'timeoutMs')) {
1015
+ else if (typeof val === 'number' && key === 'timeout' && pathLabel === 'timeout') {
950
1016
  if (val > 0 && val <= 600) {
951
1017
  const ms = Math.round(val * 1000);
952
1018
  repairs.push(`Scaled timeout from seconds (${val}s) -> ${ms}ms for parameter '${pathLabel}'`);
@@ -1057,7 +1123,7 @@ function coerceObjectBySchema(obj, schema, pathPrefix, repairs, depth) {
1057
1123
  return obj;
1058
1124
  const modified = { ...obj };
1059
1125
  for (const [key, propSchema] of Object.entries(schema.properties)) {
1060
- if (!(key in modified))
1126
+ if (!Object.hasOwn(modified, key))
1061
1127
  continue;
1062
1128
  const label = pathPrefix ? `${pathPrefix}.${key}` : key;
1063
1129
  modified[key] = coerceValueBySchema(key, modified[key], propSchema, label, repairs, depth);
@@ -207,11 +207,11 @@ for (const [alias, canonical] of Object.entries(TOOL_NAME_ALIASES)) {
207
207
  */
208
208
  export function canonicalizeToolName(rawName: string): string {
209
209
  const normalized = String(rawName || '').replace(/\./g, '_');
210
- if (TOOL_NAME_ALIASES[normalized]) {
210
+ if (Object.hasOwn(TOOL_NAME_ALIASES, normalized) && TOOL_NAME_ALIASES[normalized]) {
211
211
  return TOOL_NAME_ALIASES[normalized];
212
212
  }
213
213
  const stripped = stripDelimiters(rawName);
214
- if (DELIMITER_FREE_TOOL_INDEX[stripped]) {
214
+ if (Object.hasOwn(DELIMITER_FREE_TOOL_INDEX, stripped) && DELIMITER_FREE_TOOL_INDEX[stripped]) {
215
215
  return DELIMITER_FREE_TOOL_INDEX[stripped];
216
216
  }
217
217
  return normalized;
@@ -355,9 +355,12 @@ export function repairJsonArguments(rawInput: unknown): RepairResult {
355
355
  // 5. Native parse retry after stripping markdown/filler
356
356
  try {
357
357
  const parsed = JSON.parse(healed);
358
- if (parsed && typeof parsed === 'object') {
358
+ if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
359
359
  return { args: parsed as Record<string, unknown>, repaired: true, repairs };
360
360
  }
361
+ if (Array.isArray(parsed)) {
362
+ return { args: { items: parsed }, repaired: true, repairs: [...repairs, 'Wrapped array payload into items'] };
363
+ }
361
364
  } catch {
362
365
  // Proceed to syntax healing
363
366
  }
@@ -502,6 +505,11 @@ function sanitizeUnescapedStringLiterals(input: string): string {
502
505
  result += '\\t';
503
506
  continue;
504
507
  }
508
+ const code = char.charCodeAt(0);
509
+ if (code < 0x20) {
510
+ result += `\\u${code.toString(16).padStart(4, '0')}`;
511
+ continue;
512
+ }
505
513
  }
506
514
 
507
515
  result += char;
@@ -515,16 +523,75 @@ function sanitizeUnescapedStringLiterals(input: string): string {
515
523
  }
516
524
 
517
525
  /**
518
- * Convert simple single-quoted JSON objects to valid double-quoted JSON.
526
+ * Convert single-quoted JSON keys/values to valid double-quoted JSON without
527
+ * mutating single quotes that already reside inside double-quoted strings.
519
528
  */
520
529
  function convertSingleQuotesToJson(input: string): string {
521
- return input.replace(/'([^'\\]*(?:\\.[^'\\]*)*)'/g, (_match, inner) => {
522
- const escaped = (inner as string)
523
- .replace(/\\'/g, "'")
524
- .replace(/\\/g, '\\\\')
525
- .replace(/"/g, '\\"');
526
- return `"${escaped}"`;
527
- });
530
+ let out = '';
531
+ let i = 0;
532
+ let inDouble = false;
533
+
534
+ while (i < input.length) {
535
+ const ch = input[i]!;
536
+ if (inDouble) {
537
+ if (ch === '\\' && i + 1 < input.length) {
538
+ out += ch + input[i + 1]!;
539
+ i += 2;
540
+ continue;
541
+ }
542
+ if (ch === '"') inDouble = false;
543
+ out += ch;
544
+ i++;
545
+ continue;
546
+ }
547
+
548
+ if (ch === '"') {
549
+ inDouble = true;
550
+ out += ch;
551
+ i++;
552
+ continue;
553
+ }
554
+
555
+ if (ch === "'") {
556
+ let j = i + 1;
557
+ let inner = '';
558
+ let closed = false;
559
+ while (j < input.length) {
560
+ const c = input[j]!;
561
+ if (c === '\\' && j + 1 < input.length) {
562
+ const next = input[j + 1]!;
563
+ if (next === "'") {
564
+ inner += "'";
565
+ } else {
566
+ inner += '\\' + next;
567
+ }
568
+ j += 2;
569
+ continue;
570
+ }
571
+ if (c === "'") {
572
+ closed = true;
573
+ j++;
574
+ break;
575
+ }
576
+ if (c === '"') {
577
+ inner += '\\"';
578
+ } else {
579
+ inner += c;
580
+ }
581
+ j++;
582
+ }
583
+ if (closed) {
584
+ out += `"${inner}"`;
585
+ i = j;
586
+ continue;
587
+ }
588
+ }
589
+
590
+ out += ch;
591
+ i++;
592
+ }
593
+
594
+ return out;
528
595
  }
529
596
 
530
597
  /**
@@ -600,9 +667,9 @@ export function resolveParameterAliases(
600
667
  // 1. Specialized structural healing: fs_edit vs MultiEdit
601
668
  if (canonicalName === 'fs_edit') {
602
669
  // If edits is missing, synthesize from top-level fields
603
- if (!modified.edits && (modified.searchContent || modified.old_string || modified.oldText || modified.find)) {
604
- const search = (modified.searchContent || modified.old_string || modified.oldText || modified.find || '') as string;
605
- const replace = (modified.replaceContent || modified.new_string || modified.newText || modified.replacement || '') as string;
670
+ if (!modified.edits && (modified.searchContent !== undefined || modified.old_string !== undefined || modified.oldText !== undefined || modified.find !== undefined)) {
671
+ const search = (modified.searchContent ?? modified.old_string ?? modified.oldText ?? modified.find ?? '') as string;
672
+ const replace = (modified.replaceContent ?? modified.new_string ?? modified.newText ?? modified.replacement ?? '') as string;
606
673
  modified.edits = [{ searchContent: search, replaceContent: replace }];
607
674
  delete modified.searchContent;
608
675
  delete modified.old_string;
@@ -617,19 +684,19 @@ export function resolveParameterAliases(
617
684
  modified.edits = (modified.edits as Record<string, unknown>[]).map((item) => {
618
685
  if (!item || typeof item !== 'object') return item;
619
686
  const normalizedItem = { ...item };
620
- if (!normalizedItem.searchContent && (normalizedItem.old_string || normalizedItem.oldText || normalizedItem.find)) {
621
- normalizedItem.searchContent = normalizedItem.old_string || normalizedItem.oldText || normalizedItem.find;
687
+ if (normalizedItem.searchContent === undefined && (normalizedItem.old_string !== undefined || normalizedItem.oldText !== undefined || normalizedItem.find !== undefined)) {
688
+ normalizedItem.searchContent = normalizedItem.old_string ?? normalizedItem.oldText ?? normalizedItem.find;
622
689
  }
623
- if (!normalizedItem.replaceContent && (normalizedItem.new_string || normalizedItem.newText || normalizedItem.replace)) {
624
- normalizedItem.replaceContent = normalizedItem.new_string || normalizedItem.newText || normalizedItem.replace;
690
+ if (normalizedItem.replaceContent === undefined && (normalizedItem.new_string !== undefined || normalizedItem.newText !== undefined || normalizedItem.replace !== undefined)) {
691
+ normalizedItem.replaceContent = normalizedItem.new_string ?? normalizedItem.newText ?? normalizedItem.replace;
625
692
  }
626
693
  return normalizedItem;
627
694
  });
628
695
  }
629
696
  } else if (canonicalName === 'MultiEdit') {
630
- if (!modified.edits && (modified.old_string || modified.searchContent || modified.oldText || modified.find)) {
631
- const search = (modified.old_string || modified.searchContent || modified.oldText || modified.find || '') as string;
632
- const replace = (modified.new_string || modified.replaceContent || modified.newText || modified.replacement || '') as string;
697
+ if (!modified.edits && (modified.old_string !== undefined || modified.searchContent !== undefined || modified.oldText !== undefined || modified.find !== undefined)) {
698
+ const search = (modified.old_string ?? modified.searchContent ?? modified.oldText ?? modified.find ?? '') as string;
699
+ const replace = (modified.new_string ?? modified.replaceContent ?? modified.newText ?? modified.replacement ?? '') as string;
633
700
  modified.edits = [{ old_string: search, new_string: replace }];
634
701
  delete modified.searchContent;
635
702
  delete modified.old_string;
@@ -644,11 +711,11 @@ export function resolveParameterAliases(
644
711
  modified.edits = (modified.edits as Record<string, unknown>[]).map((item) => {
645
712
  if (!item || typeof item !== 'object') return item;
646
713
  const normalizedItem = { ...item };
647
- if (!normalizedItem.old_string && (normalizedItem.searchContent || normalizedItem.oldText || normalizedItem.find)) {
648
- normalizedItem.old_string = normalizedItem.searchContent || normalizedItem.oldText || normalizedItem.find;
714
+ if (normalizedItem.old_string === undefined && (normalizedItem.searchContent !== undefined || normalizedItem.oldText !== undefined || normalizedItem.find !== undefined)) {
715
+ normalizedItem.old_string = normalizedItem.searchContent ?? normalizedItem.oldText ?? normalizedItem.find;
649
716
  }
650
- if (!normalizedItem.new_string && (normalizedItem.replaceContent || normalizedItem.newText || normalizedItem.replace)) {
651
- normalizedItem.new_string = normalizedItem.replaceContent || normalizedItem.newText || normalizedItem.replace;
717
+ if (normalizedItem.new_string === undefined && (normalizedItem.replaceContent !== undefined || normalizedItem.newText !== undefined || normalizedItem.replace !== undefined)) {
718
+ normalizedItem.new_string = normalizedItem.replaceContent ?? normalizedItem.newText ?? normalizedItem.replace;
652
719
  }
653
720
  return normalizedItem;
654
721
  });
@@ -968,11 +1035,12 @@ function coerceValueBySchema(
968
1035
  if (timeMatch && timeMatch[1]) {
969
1036
  const rawVal = parseFloat(timeMatch[1]);
970
1037
  const unit = (timeMatch[2] || '').toLowerCase();
1038
+ const isExplicitMsKey = key === 'timeoutMs' || key === 'timeout_ms';
971
1039
  let ms = rawVal;
972
1040
  if (unit === 'ms') ms = rawVal;
973
1041
  else if (unit === 'm') ms = rawVal * 60 * 1000;
974
1042
  else if (unit === 's') ms = rawVal * 1000;
975
- else ms = rawVal <= 600 ? rawVal * 1000 : rawVal;
1043
+ else ms = (!isExplicitMsKey && rawVal <= 600) ? rawVal * 1000 : rawVal;
976
1044
  const normalized = expectedType === 'integer' ? Math.round(ms) : ms;
977
1045
  repairs.push(`Normalized time string "${val}" -> ${normalized}ms for parameter '${pathLabel}'`);
978
1046
  return normalized;
@@ -983,7 +1051,7 @@ function coerceValueBySchema(
983
1051
  return num;
984
1052
  }
985
1053
  }
986
- } else if (typeof val === 'number' && (key === 'timeout' || key === 'timeoutMs')) {
1054
+ } else if (typeof val === 'number' && key === 'timeout' && pathLabel === 'timeout') {
987
1055
  if (val > 0 && val <= 600) {
988
1056
  const ms = Math.round(val * 1000);
989
1057
  repairs.push(`Scaled timeout from seconds (${val}s) -> ${ms}ms for parameter '${pathLabel}'`);
@@ -1100,7 +1168,7 @@ function coerceObjectBySchema(
1100
1168
  if (depth > 8 || !schema.properties) return obj;
1101
1169
  const modified: Record<string, unknown> = { ...obj };
1102
1170
  for (const [key, propSchema] of Object.entries(schema.properties)) {
1103
- if (!(key in modified)) continue;
1171
+ if (!Object.hasOwn(modified, key)) continue;
1104
1172
  const label = pathPrefix ? `${pathPrefix}.${key}` : key;
1105
1173
  modified[key] = coerceValueBySchema(key, modified[key], propSchema, label, repairs, depth);
1106
1174
  }
@@ -8,6 +8,60 @@ import fs from 'node:fs';
8
8
  import path from 'node:path';
9
9
  import { generateHtmlComponent, generatePreviewHtml, generateReactComponent } from '../uiEngine/uiForge.js';
10
10
  import { resolveUserPath } from '../utils/paths.js';
11
+ function canonicalUiPath(target) {
12
+ const resolved = path.resolve(target);
13
+ try {
14
+ return fs.realpathSync(resolved);
15
+ }
16
+ catch {
17
+ let current = resolved;
18
+ const missing = [];
19
+ for (let i = 0; i < 64; i++) {
20
+ const parent = path.dirname(current);
21
+ if (parent === current)
22
+ break;
23
+ missing.unshift(path.basename(current));
24
+ current = parent;
25
+ try {
26
+ return path.join(fs.realpathSync(current), ...missing);
27
+ }
28
+ catch {
29
+ continue;
30
+ }
31
+ }
32
+ return resolved;
33
+ }
34
+ }
35
+ function assertUiWriteScope(target, context) {
36
+ if (fs.existsSync(target) && fs.lstatSync(target).isSymbolicLink()) {
37
+ throw new Error(`Refusing to overwrite symbolic link: ${target}`);
38
+ }
39
+ if (!context || context.grantAllAccess === true)
40
+ return;
41
+ const configured = Array.isArray(context.workspacePaths)
42
+ ? context.workspacePaths.filter((p) => typeof p === 'string' && p.trim().length > 0).map(p => p.trim())
43
+ : [];
44
+ const roots = configured.length > 0
45
+ ? configured
46
+ : [context.parentLoop?.workspaceRoot, context.workspaceRoot]
47
+ .filter((p) => typeof p === 'string' && p.trim().length > 0)
48
+ .map(p => p.trim());
49
+ if (roots.length === 0)
50
+ return;
51
+ const physical = canonicalUiPath(target);
52
+ for (const root of roots) {
53
+ try {
54
+ const realRoot = fs.realpathSync(resolveUserPath(root));
55
+ const rel = path.relative(realRoot, physical);
56
+ if (rel === '' || (rel !== '..' && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel)))
57
+ return;
58
+ }
59
+ catch {
60
+ continue;
61
+ }
62
+ }
63
+ throw new Error(`UI output path resolves outside the selected workspace: ${target}`);
64
+ }
11
65
  export const uiForge = {
12
66
  schema: {
13
67
  name: 'ui_forge',
@@ -70,8 +124,8 @@ export const uiForge = {
70
124
  required: ['spec']
71
125
  }
72
126
  },
73
- async execute(args = {}) {
74
- if (!args.spec || !args.spec.type) {
127
+ async execute(args = {}, context) {
128
+ if (!args || typeof args !== 'object' || Array.isArray(args) || !args.spec || typeof args.spec !== 'object' || Array.isArray(args.spec) || !args.spec.type) {
75
129
  return { success: false, error: 'UI Forge specification with a valid component "type" is required.' };
76
130
  }
77
131
  const framework = args.framework || 'html-css';
@@ -92,16 +146,27 @@ export const uiForge = {
92
146
  previewHtml = generatePreviewHtml(htmlComp.html, htmlComp.css, spec.theme || 'dark');
93
147
  }
94
148
  let writtenFiles = [];
95
- if (args.outputPath) {
149
+ if (typeof args.outputPath === 'string' && args.outputPath.trim()) {
96
150
  try {
97
- const resolved = resolveUserPath(args.outputPath);
151
+ const trimmedOut = args.outputPath.trim();
152
+ const isHome = trimmedOut === '~' || trimmedOut.startsWith('~/') || trimmedOut.startsWith('~\\');
153
+ const baseRoot = context?.parentLoop?.workspaceRoot?.trim()
154
+ || context?.workspaceRoot?.trim()
155
+ || context?.workspacePaths?.find((p) => typeof p === 'string' && p.trim().length > 0)?.trim();
156
+ const resolved = isHome
157
+ ? resolveUserPath(trimmedOut)
158
+ : path.isAbsolute(trimmedOut)
159
+ ? path.resolve(trimmedOut)
160
+ : path.resolve(baseRoot ? resolveUserPath(baseRoot) : process.cwd(), trimmedOut);
98
161
  const dir = path.dirname(resolved);
162
+ const ext = path.extname(resolved);
163
+ const previewFile = path.join(dir, `${path.basename(resolved, ext)}.preview.html`);
164
+ assertUiWriteScope(resolved, context);
165
+ assertUiWriteScope(previewFile, context);
99
166
  if (!fs.existsSync(dir))
100
167
  fs.mkdirSync(dir, { recursive: true });
101
168
  fs.writeFileSync(resolved, code, 'utf8');
102
169
  writtenFiles.push(resolved);
103
- const ext = path.extname(resolved);
104
- const previewFile = path.join(dir, `${path.basename(resolved, ext)}.preview.html`);
105
170
  fs.writeFileSync(previewFile, previewHtml, 'utf8');
106
171
  writtenFiles.push(previewFile);
107
172
  }