@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
@@ -9,38 +9,68 @@ export function currentToolAutonomyMode() {
9
9
  }
10
10
  /** Read the live session mode from the tool context; never infer it from a tool argument. */
11
11
  export function isAutonomousToolContext(context) {
12
- if (!context || typeof context !== 'object')
12
+ if (!context || typeof context !== 'object' || Array.isArray(context))
13
13
  return false;
14
14
  const parentLoop = context.parentLoop;
15
- if (!parentLoop || typeof parentLoop !== 'object')
15
+ if (!parentLoop || typeof parentLoop !== 'object' || Array.isArray(parentLoop))
16
16
  return false;
17
17
  const config = parentLoop.config;
18
- if (!config || typeof config !== 'object')
18
+ if (!config || typeof config !== 'object' || Array.isArray(config))
19
19
  return false;
20
20
  const mode = config.autonomyMode;
21
21
  return mode === 'C' || mode === undefined;
22
22
  }
23
23
  const SHELL_TOOLS = new Set(['sysRun', 'sysRunBg', 'terminal_persistent_shell']);
24
- const WHOLE_FILE_DELETE = /(?:^|[;&|\n(]\s*)(?:(?:sudo|command|env)\s+)*(?:rm|unlink|rmdir|del|erase|Remove-Item)\b|\bfind\b[^\n;]*\s-delete\b|\bgit\s+(?:rm\b|clean\b[^\n;&|]*(?:-[a-zA-Z0-9]*f[a-zA-Z0-9]*|--force\b))/i;
24
+ const WHOLE_FILE_DELETE = /(?:^|[;&|\n(]\s*)(?:(?:sudo|doas|pkexec|command|env)\s+)*(?:rm|unlink|rmdir|shred|srm|del|erase|Remove-Item)\b|\bgit\s+rm\b/i;
25
25
  const DELETE_API_CALL = /\b(?:os\.(?:remove|unlink)|shutil\.rmtree|fs\.(?:rm|unlink)(?:Sync)?|\.unlink|\.rmdir)\s*\(/i;
26
- const NESTED_SHELL_DELETE = /\b(?:bash|sh|zsh|dash)\s+-c\s+['"]\s*(?:rm|unlink|rmdir)\b|\b(?:powershell|pwsh)\s+(?:-Command|-c)\s+['"]?\s*Remove-Item\b/i;
26
+ const NESTED_SHELL_DELETE = /\b(?:bash|sh|zsh|dash)\s+-c\s+['"]\s*(?:rm|unlink|rmdir|shred|srm)\b|\b(?:powershell|pwsh)\s+(?:-Command|-c)\s+['"]?\s*Remove-Item\b/i;
27
+ function hasFindDelete(command) {
28
+ for (const segment of command.split(/[\n;]/)) {
29
+ const findMatch = /\bfind\b/i.exec(segment);
30
+ if (!findMatch)
31
+ continue;
32
+ if (/\s-delete\b/i.test(segment.slice(findMatch.index + findMatch[0].length)))
33
+ return true;
34
+ }
35
+ return false;
36
+ }
37
+ function hasGitForceClean(command) {
38
+ for (const segment of command.split(/[\n;&|]/)) {
39
+ const cleanMatch = /\bgit\s+clean\b/i.exec(segment);
40
+ if (!cleanMatch)
41
+ continue;
42
+ const tail = segment.slice(cleanMatch.index + cleanMatch[0].length);
43
+ if (/(?:^|\s)(?:-[a-zA-Z0-9]*f[a-zA-Z0-9]*|--force)\b/i.test(tail))
44
+ return true;
45
+ }
46
+ return false;
47
+ }
27
48
  /** A deletion is a whole filesystem entry, not removal of lines in an edit. */
49
+ function canonicalPolicyTool(tool) {
50
+ return typeof tool === 'string' ? tool.trim().replace(/\./g, '_') : '';
51
+ }
28
52
  export function isWholeFileDeletion(tool, args) {
29
- if (tool === 'fs_delete')
53
+ const canonical = canonicalPolicyTool(tool);
54
+ if (canonical === 'fs_delete')
30
55
  return true;
31
- const command = tool === 'gitOp'
32
- ? `git ${String(args.command ?? args.action ?? '')}`
33
- : SHELL_TOOLS.has(tool)
34
- ? String(args.command ?? args.input ?? args.cmd ?? '')
56
+ const safeArgs = args && typeof args === 'object' ? args : {};
57
+ const command = canonical === 'gitOp'
58
+ ? `git ${String(safeArgs.command ?? safeArgs.action ?? '')}`
59
+ : SHELL_TOOLS.has(canonical)
60
+ ? String(safeArgs.command ?? safeArgs.input ?? safeArgs.cmd ?? '')
35
61
  : '';
36
- if (/^\s*git\s+rm\s+--cached\b/i.test(command))
62
+ if (/^\s*git\s+rm\s+--cached\b[^;&|\n`$()]*$/i.test(command))
37
63
  return false;
38
64
  return command.length > 0
39
- && (WHOLE_FILE_DELETE.test(command) || DELETE_API_CALL.test(command) || NESTED_SHELL_DELETE.test(command));
65
+ && (WHOLE_FILE_DELETE.test(command)
66
+ || hasFindDelete(command)
67
+ || hasGitForceClean(command)
68
+ || DELETE_API_CALL.test(command)
69
+ || NESTED_SHELL_DELETE.test(command));
40
70
  }
41
71
  /** Routine browser verification inside the isolated agent browser (preview, snapshot, click, fill, screenshot, etc.) does not require HITL in Mode B or C unless uploading or downloading files. */
42
72
  export function isRoutineBrowserVerification(tool, args) {
43
- if (tool !== 'browser_act')
73
+ if (canonicalPolicyTool(tool) !== 'browser_act')
44
74
  return false;
45
75
  const actions = Array.isArray(args?.actions) ? args.actions : [];
46
76
  if (actions.length === 0) {
@@ -56,11 +86,14 @@ export function isRoutineBrowserVerification(tool, args) {
56
86
  }
57
87
  /** Prompt policy only. Sandbox denial, workspace checks, and observer veto run separately. */
58
88
  export function requiresToolApproval(input) {
89
+ if (!input || typeof input !== 'object')
90
+ return true;
91
+ const canonical = canonicalPolicyTool(input.tool);
59
92
  if (input.mode === 'C') {
60
- if (!isWholeFileDeletion(input.tool, input.args))
93
+ if (!isWholeFileDeletion(canonical, input.args))
61
94
  return false;
62
95
  // A general shell or git grant must not authorize future deletions.
63
- return input.tool !== 'fs_delete' || !input.standingApproval;
96
+ return canonical !== 'fs_delete' || !input.standingApproval;
64
97
  }
65
98
  if (input.standingApproval)
66
99
  return false;
@@ -24,36 +24,65 @@ export interface ToolApprovalInput {
24
24
 
25
25
  /** Read the live session mode from the tool context; never infer it from a tool argument. */
26
26
  export function isAutonomousToolContext(context: unknown): boolean {
27
- if (!context || typeof context !== 'object') return false;
27
+ if (!context || typeof context !== 'object' || Array.isArray(context)) return false;
28
28
  const parentLoop = (context as { parentLoop?: unknown }).parentLoop;
29
- if (!parentLoop || typeof parentLoop !== 'object') return false;
29
+ if (!parentLoop || typeof parentLoop !== 'object' || Array.isArray(parentLoop)) return false;
30
30
  const config = (parentLoop as { config?: unknown }).config;
31
- if (!config || typeof config !== 'object') return false;
31
+ if (!config || typeof config !== 'object' || Array.isArray(config)) return false;
32
32
  const mode = (config as { autonomyMode?: unknown }).autonomyMode;
33
33
  return mode === 'C' || mode === undefined;
34
34
  }
35
35
 
36
36
  const SHELL_TOOLS = new Set(['sysRun', 'sysRunBg', 'terminal_persistent_shell']);
37
- const WHOLE_FILE_DELETE = /(?:^|[;&|\n(]\s*)(?:(?:sudo|command|env)\s+)*(?:rm|unlink|rmdir|del|erase|Remove-Item)\b|\bfind\b[^\n;]*\s-delete\b|\bgit\s+(?:rm\b|clean\b[^\n;&|]*(?:-[a-zA-Z0-9]*f[a-zA-Z0-9]*|--force\b))/i;
37
+ const WHOLE_FILE_DELETE = /(?:^|[;&|\n(]\s*)(?:(?:sudo|doas|pkexec|command|env)\s+)*(?:rm|unlink|rmdir|shred|srm|del|erase|Remove-Item)\b|\bgit\s+rm\b/i;
38
38
  const DELETE_API_CALL = /\b(?:os\.(?:remove|unlink)|shutil\.rmtree|fs\.(?:rm|unlink)(?:Sync)?|\.unlink|\.rmdir)\s*\(/i;
39
- const NESTED_SHELL_DELETE = /\b(?:bash|sh|zsh|dash)\s+-c\s+['"]\s*(?:rm|unlink|rmdir)\b|\b(?:powershell|pwsh)\s+(?:-Command|-c)\s+['"]?\s*Remove-Item\b/i;
39
+ const NESTED_SHELL_DELETE = /\b(?:bash|sh|zsh|dash)\s+-c\s+['"]\s*(?:rm|unlink|rmdir|shred|srm)\b|\b(?:powershell|pwsh)\s+(?:-Command|-c)\s+['"]?\s*Remove-Item\b/i;
40
+
41
+ function hasFindDelete(command: string): boolean {
42
+ for (const segment of command.split(/[\n;]/)) {
43
+ const findMatch = /\bfind\b/i.exec(segment);
44
+ if (!findMatch) continue;
45
+ if (/\s-delete\b/i.test(segment.slice(findMatch.index + findMatch[0].length))) return true;
46
+ }
47
+ return false;
48
+ }
49
+
50
+ function hasGitForceClean(command: string): boolean {
51
+ for (const segment of command.split(/[\n;&|]/)) {
52
+ const cleanMatch = /\bgit\s+clean\b/i.exec(segment);
53
+ if (!cleanMatch) continue;
54
+ const tail = segment.slice(cleanMatch.index + cleanMatch[0].length);
55
+ if (/(?:^|\s)(?:-[a-zA-Z0-9]*f[a-zA-Z0-9]*|--force)\b/i.test(tail)) return true;
56
+ }
57
+ return false;
58
+ }
40
59
 
41
60
  /** A deletion is a whole filesystem entry, not removal of lines in an edit. */
61
+ function canonicalPolicyTool(tool: unknown): string {
62
+ return typeof tool === 'string' ? tool.trim().replace(/\./g, '_') : '';
63
+ }
64
+
42
65
  export function isWholeFileDeletion(tool: string, args: Record<string, unknown>): boolean {
43
- if (tool === 'fs_delete') return true;
44
- const command = tool === 'gitOp'
45
- ? `git ${String(args.command ?? args.action ?? '')}`
46
- : SHELL_TOOLS.has(tool)
47
- ? String(args.command ?? args.input ?? args.cmd ?? '')
66
+ const canonical = canonicalPolicyTool(tool);
67
+ if (canonical === 'fs_delete') return true;
68
+ const safeArgs = args && typeof args === 'object' ? args : {};
69
+ const command = canonical === 'gitOp'
70
+ ? `git ${String(safeArgs.command ?? safeArgs.action ?? '')}`
71
+ : SHELL_TOOLS.has(canonical)
72
+ ? String(safeArgs.command ?? safeArgs.input ?? safeArgs.cmd ?? '')
48
73
  : '';
49
- if (/^\s*git\s+rm\s+--cached\b/i.test(command)) return false;
74
+ if (/^\s*git\s+rm\s+--cached\b[^;&|\n`$()]*$/i.test(command)) return false;
50
75
  return command.length > 0
51
- && (WHOLE_FILE_DELETE.test(command) || DELETE_API_CALL.test(command) || NESTED_SHELL_DELETE.test(command));
76
+ && (WHOLE_FILE_DELETE.test(command)
77
+ || hasFindDelete(command)
78
+ || hasGitForceClean(command)
79
+ || DELETE_API_CALL.test(command)
80
+ || NESTED_SHELL_DELETE.test(command));
52
81
  }
53
82
 
54
83
  /** Routine browser verification inside the isolated agent browser (preview, snapshot, click, fill, screenshot, etc.) does not require HITL in Mode B or C unless uploading or downloading files. */
55
84
  export function isRoutineBrowserVerification(tool: string, args: Record<string, unknown>): boolean {
56
- if (tool !== 'browser_act') return false;
85
+ if (canonicalPolicyTool(tool) !== 'browser_act') return false;
57
86
  const actions = Array.isArray(args?.actions) ? args.actions : [];
58
87
  if (actions.length === 0) {
59
88
  const singleType = typeof args?.action === 'string' ? args.action : typeof args?.type === 'string' ? args.type : '';
@@ -68,10 +97,12 @@ export function isRoutineBrowserVerification(tool: string, args: Record<string,
68
97
 
69
98
  /** Prompt policy only. Sandbox denial, workspace checks, and observer veto run separately. */
70
99
  export function requiresToolApproval(input: ToolApprovalInput): boolean {
100
+ if (!input || typeof input !== 'object') return true;
101
+ const canonical = canonicalPolicyTool(input.tool);
71
102
  if (input.mode === 'C') {
72
- if (!isWholeFileDeletion(input.tool, input.args)) return false;
103
+ if (!isWholeFileDeletion(canonical, input.args)) return false;
73
104
  // A general shell or git grant must not authorize future deletions.
74
- return input.tool !== 'fs_delete' || !input.standingApproval;
105
+ return canonical !== 'fs_delete' || !input.standingApproval;
75
106
  }
76
107
  if (input.standingApproval) return false;
77
108
  if (input.mode !== 'A' && isRoutineBrowserVerification(input.tool, input.args)) {
package/src/autoUpdate.js CHANGED
@@ -85,8 +85,11 @@ function managedPrefix(packageRoot = PACKAGE_ROOT, env = process.env) {
85
85
  ];
86
86
  for (const marker of markers) {
87
87
  const index = packageRoot.lastIndexOf(marker);
88
- if (index >= 0 && index + marker.length === packageRoot.length) {
89
- return packageRoot.slice(0, index).replace(/[\\/]$/, '');
88
+ const atBoundary = index === 0 || packageRoot[index - 1] === '/' || packageRoot[index - 1] === '\\';
89
+ if (index >= 0 && atBoundary && index + marker.length === packageRoot.length) {
90
+ const rawPrefix = packageRoot.slice(0, index);
91
+ const root = path.parse(rawPrefix).root;
92
+ return rawPrefix === root ? rawPrefix : rawPrefix.replace(/[\\/]$/, '');
90
93
  }
91
94
  }
92
95
  return null;
package/src/autoUpdate.ts CHANGED
@@ -153,8 +153,11 @@ function managedPrefix(packageRoot: string = PACKAGE_ROOT, env: NodeJS.ProcessEn
153
153
  ];
154
154
  for (const marker of markers) {
155
155
  const index = packageRoot.lastIndexOf(marker);
156
- if (index >= 0 && index + marker.length === packageRoot.length) {
157
- return packageRoot.slice(0, index).replace(/[\\/]$/, '');
156
+ const atBoundary = index === 0 || packageRoot[index - 1] === '/' || packageRoot[index - 1] === '\\';
157
+ if (index >= 0 && atBoundary && index + marker.length === packageRoot.length) {
158
+ const rawPrefix = packageRoot.slice(0, index);
159
+ const root = path.parse(rawPrefix).root;
160
+ return rawPrefix === root ? rawPrefix : rawPrefix.replace(/[\\/]$/, '');
158
161
  }
159
162
  }
160
163
  return null;
@@ -72,7 +72,8 @@ const SEARCH_MACROS = {
72
72
  '@twitch_search': query => `https://www.twitch.tv/search?term=${encodeURIComponent(query || '')}`
73
73
  };
74
74
  export function expandSearchMacro(macro, query = '') {
75
- const fn = SEARCH_MACROS[String(macro || '').trim()];
75
+ const key = String(macro || '').trim();
76
+ const fn = Object.hasOwn(SEARCH_MACROS, key) ? SEARCH_MACROS[key] : undefined;
76
77
  return fn ? fn(String(query ?? '')) : null;
77
78
  }
78
79
  export function getSupportedSearchMacros() {
@@ -579,7 +580,7 @@ const SEARCH_EXTRACT_SCRIPT = `(() => {
579
580
  if (parsed.hostname.includes('google.') && parsed.pathname === '/url') {
580
581
  href = parsed.searchParams.get('q') || parsed.searchParams.get('url') || href;
581
582
  }
582
- if (/(^|\.)duckduckgo\.com$/i.test(parsed.hostname) && parsed.pathname.startsWith('/l/')) {
583
+ if (/(^|\\.)duckduckgo\\.com$/i.test(parsed.hostname) && parsed.pathname.startsWith('/l/')) {
583
584
  href = parsed.searchParams.get('uddg') || href;
584
585
  }
585
586
  const clean = new URL(href, document.baseURI);
@@ -86,7 +86,8 @@ const SEARCH_MACROS: Record<string, (query: string) => string> = {
86
86
  };
87
87
 
88
88
  export function expandSearchMacro(macro: string, query = ''): string | null {
89
- const fn = SEARCH_MACROS[String(macro || '').trim()];
89
+ const key = String(macro || '').trim();
90
+ const fn = Object.hasOwn(SEARCH_MACROS, key) ? SEARCH_MACROS[key] : undefined;
90
91
  return fn ? fn(String(query ?? '')) : null;
91
92
  }
92
93
 
@@ -845,7 +846,7 @@ const SEARCH_EXTRACT_SCRIPT = `(() => {
845
846
  if (parsed.hostname.includes('google.') && parsed.pathname === '/url') {
846
847
  href = parsed.searchParams.get('q') || parsed.searchParams.get('url') || href;
847
848
  }
848
- if (/(^|\.)duckduckgo\.com$/i.test(parsed.hostname) && parsed.pathname.startsWith('/l/')) {
849
+ if (/(^|\\.)duckduckgo\\.com$/i.test(parsed.hostname) && parsed.pathname.startsWith('/l/')) {
849
850
  href = parsed.searchParams.get('uddg') || href;
850
851
  }
851
852
  const clean = new URL(href, document.baseURI);
@@ -14,7 +14,7 @@ function decodeEntities(value) {
14
14
  return Number.isInteger(point) && point > 0 && point <= 0x10ffff && !(point >= 0xd800 && point <= 0xdfff)
15
15
  ? String.fromCodePoint(point) : full;
16
16
  }
17
- return named[normalized] ?? full;
17
+ return Object.hasOwn(named, normalized) ? named[normalized] : full;
18
18
  });
19
19
  }
20
20
  function cleanMarkup(value) {
@@ -27,7 +27,7 @@ function decodeEntities(value: string): string {
27
27
  return Number.isInteger(point) && point > 0 && point <= 0x10ffff && !(point >= 0xd800 && point <= 0xdfff)
28
28
  ? String.fromCodePoint(point) : full;
29
29
  }
30
- return named[normalized] ?? full;
30
+ return Object.hasOwn(named, normalized) ? named[normalized]! : full;
31
31
  });
32
32
  }
33
33