@causyne/agent 1.20.120 → 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 (276) 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 +117 -0
  14. package/src/agent/errorClassifier.ts +165 -0
  15. package/src/agent/promptIntent.js +200 -0
  16. package/src/agent/promptIntent.ts +203 -0
  17. package/src/agent/toolArgValidator.js +97 -0
  18. package/src/agent/toolArgValidator.ts +112 -0
  19. package/src/agentLoop.js +33 -344
  20. package/src/agentLoop.ts +51 -352
  21. package/src/approvalGrants.js +19 -7
  22. package/src/approvalGrants.ts +20 -7
  23. package/src/approvalPolicy.js +48 -15
  24. package/src/approvalPolicy.ts +46 -15
  25. package/src/autoUpdate.js +116 -10
  26. package/src/autoUpdate.ts +149 -10
  27. package/src/browser/causyneBrowser.js +3 -2
  28. package/src/browser/causyneBrowser.ts +3 -2
  29. package/src/browser/searchProviders.js +1 -1
  30. package/src/browser/searchProviders.ts +1 -1
  31. package/src/cliMode.js +16 -2
  32. package/src/commands.js +10 -9
  33. package/src/config.js +288 -272
  34. package/src/config.ts +342 -0
  35. package/src/configVault.js +271 -0
  36. package/src/configVault.ts +273 -0
  37. package/src/continuum/compactor.js +2 -1
  38. package/src/continuum/compactor.ts +2 -1
  39. package/src/continuum/sanitizer.js +10 -3
  40. package/src/continuum/sanitizer.ts +9 -3
  41. package/src/continuum/ui/continuumPickerView.js +3 -2
  42. package/src/continuum/ui/continuumPickerView.ts +3 -2
  43. package/src/core/contextCompactor.js +70 -11
  44. package/src/core/contextCompactor.ts +83 -11
  45. package/src/cortex/vectorDb.js +26 -15
  46. package/src/cortex/vectorDb.ts +26 -16
  47. package/src/creative/liveBridge.js +7 -5
  48. package/src/creative/liveBridge.ts +7 -5
  49. package/src/creative/studioScripts.js +16 -5
  50. package/src/creative/studioScripts.ts +14 -5
  51. package/src/decisionPolicy.js +16 -4
  52. package/src/decisionPolicy.ts +14 -4
  53. package/src/documentEngine/antiSlopAuditor.js +10 -5
  54. package/src/documentEngine/antiSlopAuditor.ts +11 -5
  55. package/src/documentEngine/documentForge.js +47 -15
  56. package/src/documentEngine/documentForge.ts +43 -14
  57. package/src/dynamicCatalogue.js +42 -73
  58. package/src/dynamicCatalogue.ts +74 -60
  59. package/src/engines/design.js +2 -1
  60. package/src/engines/design.ts +2 -1
  61. package/src/engines/film.js +4 -4
  62. package/src/engines/film.ts +2 -2
  63. package/src/engines/light.js +2 -1
  64. package/src/engines/light.ts +2 -1
  65. package/src/engines/registry.js +1 -1
  66. package/src/engines/registry.ts +1 -1
  67. package/src/engines/reverseHarness.js +4 -3
  68. package/src/engines/reverseHarness.ts +4 -3
  69. package/src/entrypoint.js +77 -4
  70. package/src/headlessCli.js +305 -0
  71. package/src/headlessCli.ts +381 -0
  72. package/src/historyPruner.js +3 -2
  73. package/src/historyPruner.ts +3 -2
  74. package/src/hooks.js +3 -0
  75. package/src/hooks.ts +3 -0
  76. package/src/implementationPlan.js +21 -11
  77. package/src/implementationPlan.ts +21 -11
  78. package/src/infra/atomicWriter.js +4 -1
  79. package/src/infra/atomicWriter.ts +4 -1
  80. package/src/launchIntent.js +1 -1
  81. package/src/launchIntent.ts +1 -1
  82. package/src/mcp/mcpClient.js +38 -11
  83. package/src/mcp/mcpClient.ts +44 -11
  84. package/src/mcp/mcpRegistry.js +2 -5
  85. package/src/mcp/mcpRegistry.ts +2 -5
  86. package/src/mcp/mcpSecurity.js +189 -0
  87. package/src/mcp/mcpSecurity.ts +190 -0
  88. package/src/memory/scopedFacts.js +1 -1
  89. package/src/memory/scopedFacts.ts +1 -1
  90. package/src/memory/symbolFolder.js +1 -1
  91. package/src/memory/symbolFolder.ts +1 -1
  92. package/src/modelRouter.js +1 -1
  93. package/src/modelRouter.ts +1 -1
  94. package/src/observer/evidence.js +10 -4
  95. package/src/observer/evidence.ts +10 -4
  96. package/src/osKeychain.js +263 -0
  97. package/src/osKeychain.ts +287 -0
  98. package/src/perception.js +3 -2
  99. package/src/perception.ts +3 -2
  100. package/src/planCache.js +2 -2
  101. package/src/planCache.ts +2 -2
  102. package/src/pluginsFactory/pluginsFactory.js +19 -11
  103. package/src/pluginsFactory/pluginsFactory.ts +18 -11
  104. package/src/promptMentions.js +2 -2
  105. package/src/promptMentions.ts +2 -2
  106. package/src/providers/acp.js +1 -1
  107. package/src/providers/acp.ts +1 -1
  108. package/src/providers/anthropic.js +328 -385
  109. package/src/providers/anthropic.ts +386 -0
  110. package/src/providers/antigravity.js +10 -4
  111. package/src/providers/antigravity.ts +10 -4
  112. package/src/providers/base.js +221 -319
  113. package/src/providers/base.ts +340 -0
  114. package/src/providers/byokHttp.js +397 -0
  115. package/src/providers/byokHttp.ts +497 -0
  116. package/src/providers/byokStream.js +748 -0
  117. package/src/providers/byokStream.ts +863 -0
  118. package/src/providers/dashscope-byok.js +98 -81
  119. package/src/providers/dashscope-byok.ts +114 -0
  120. package/src/providers/deepseek.js +74 -64
  121. package/src/providers/deepseek.ts +99 -0
  122. package/src/providers/factory.js +35 -28
  123. package/src/providers/factory.ts +40 -0
  124. package/src/providers/gemini.js +229 -253
  125. package/src/providers/gemini.ts +261 -0
  126. package/src/providers/loopGuard.js +9 -5
  127. package/src/providers/loopGuard.ts +10 -5
  128. package/src/providers/moonshot.js +71 -64
  129. package/src/providers/moonshot.ts +93 -0
  130. package/src/providers/muse.js +82 -152
  131. package/src/providers/muse.ts +122 -0
  132. package/src/providers/ollama.js +116 -93
  133. package/src/providers/ollama.ts +135 -0
  134. package/src/providers/openai-compatible.js +114 -65
  135. package/src/providers/openai-compatible.ts +139 -0
  136. package/src/providers/openai.js +22 -15
  137. package/src/providers/openai.ts +30 -0
  138. package/src/providers/openrouter.js +194 -98
  139. package/src/providers/openrouter.ts +202 -97
  140. package/src/providers/pi.js +6 -0
  141. package/src/providers/pi.ts +6 -0
  142. package/src/providers/qwen-byok.js +97 -71
  143. package/src/providers/qwen-byok.ts +113 -0
  144. package/src/providers/toolContracts.js +40 -14
  145. package/src/providers/toolContracts.ts +35 -14
  146. package/src/providers/wireNormalizer.js +78 -11
  147. package/src/providers/wireNormalizer.ts +68 -12
  148. package/src/providers/xai.js +74 -64
  149. package/src/providers/xai.ts +97 -0
  150. package/src/reliability/assetEvidence.js +4 -2
  151. package/src/reliability/assetEvidence.ts +4 -2
  152. package/src/sandbox.js +486 -530
  153. package/src/sandbox.ts +552 -0
  154. package/src/sandboxPolicy.js +1287 -0
  155. package/src/sandboxPolicy.ts +1381 -0
  156. package/src/sessionJournal.js +55 -3
  157. package/src/sessionJournal.ts +58 -3
  158. package/src/skills/skillResourceSafety.js +19 -8
  159. package/src/skills/skillResourceSafety.ts +16 -7
  160. package/src/skillsManager.js +3 -3
  161. package/src/skillsManager.ts +3 -3
  162. package/src/smartToolsUse.js +28 -4
  163. package/src/smartToolsUse.ts +29 -7
  164. package/src/stallGuard.js +45 -22
  165. package/src/stallGuard.ts +46 -22
  166. package/src/subagentJournal.js +6 -4
  167. package/src/subagentJournal.ts +6 -4
  168. package/src/textDiff.js +6 -1
  169. package/src/textDiff.ts +6 -1
  170. package/src/timeMachine.js +7 -1
  171. package/src/timeMachine.ts +7 -1
  172. package/src/tokenTracker.js +43 -28
  173. package/src/tokenTracker.ts +44 -30
  174. package/src/toolPacks.js +3 -1
  175. package/src/toolPacks.ts +3 -1
  176. package/src/tools/archive.js +245 -35
  177. package/src/tools/archive.ts +244 -35
  178. package/src/tools/computerUse.js +7 -3
  179. package/src/tools/computerUse.ts +7 -3
  180. package/src/tools/creativeApps.js +13 -8
  181. package/src/tools/creativeApps.ts +22 -9
  182. package/src/tools/deferredMcpSearch.js +26 -14
  183. package/src/tools/deferredMcpSearch.ts +26 -14
  184. package/src/tools/desktopOpen.js +69 -10
  185. package/src/tools/desktopOpen.ts +70 -11
  186. package/src/tools/documentForge.js +167 -82
  187. package/src/tools/documentForge.ts +169 -84
  188. package/src/tools/fsEdit.js +101 -30
  189. package/src/tools/fsEdit.ts +105 -32
  190. package/src/tools/fsFind.js +8 -5
  191. package/src/tools/fsFind.ts +7 -4
  192. package/src/tools/fsRead.js +119 -13
  193. package/src/tools/fsRead.ts +124 -13
  194. package/src/tools/fsWrite.js +17 -5
  195. package/src/tools/fsWrite.ts +17 -7
  196. package/src/tools/generateMediaViaApi.js +82 -19
  197. package/src/tools/generateMediaViaApi.ts +80 -19
  198. package/src/tools/memoryRecall.js +62 -11
  199. package/src/tools/memoryRecall.ts +70 -13
  200. package/src/tools/memoryWrite.js +27 -14
  201. package/src/tools/memoryWrite.ts +30 -14
  202. package/src/tools/multiEdit.js +100 -30
  203. package/src/tools/multiEdit.ts +104 -32
  204. package/src/tools/nativeEngine.js +33 -18
  205. package/src/tools/nativeEngine.ts +31 -18
  206. package/src/tools/openSourceToolProvisioner.js +49 -14
  207. package/src/tools/openSourceToolProvisioner.ts +54 -15
  208. package/src/tools/osSandbox.js +513 -0
  209. package/src/tools/osSandbox.ts +588 -0
  210. package/src/tools/payloadSanitizer.js +40 -8
  211. package/src/tools/payloadSanitizer.ts +39 -8
  212. package/src/tools/peerAgent.js +96 -34
  213. package/src/tools/peerAgent.ts +114 -37
  214. package/src/tools/persistentShell.js +8 -3
  215. package/src/tools/pluginsFactory.js +38 -6
  216. package/src/tools/pluginsFactory.ts +42 -6
  217. package/src/tools/readNativeSkill.js +10 -8
  218. package/src/tools/readNativeSkill.ts +10 -8
  219. package/src/tools/requestDecision.js +10 -3
  220. package/src/tools/requestDecision.ts +10 -3
  221. package/src/tools/resolveAutomator.js +91 -17
  222. package/src/tools/resolveAutomator.ts +102 -17
  223. package/src/tools/reverseEngineering.js +168 -41
  224. package/src/tools/reverseEngineering.ts +161 -41
  225. package/src/tools/subprocessEnv.js +197 -0
  226. package/src/tools/subprocessEnv.ts +212 -0
  227. package/src/tools/sysRun.js +108 -35
  228. package/src/tools/sysRun.ts +119 -31
  229. package/src/tools/toolDispatch.js +24 -1
  230. package/src/tools/toolDispatch.ts +21 -1
  231. package/src/tools/toolOutputStore.js +62 -23
  232. package/src/tools/toolOutputStore.ts +56 -23
  233. package/src/tools/toolScanner.js +13 -10
  234. package/src/tools/toolScanner.ts +13 -10
  235. package/src/tools/toolSelfRepair.js +94 -28
  236. package/src/tools/toolSelfRepair.ts +96 -28
  237. package/src/tools/uiForge.js +71 -6
  238. package/src/tools/uiForge.ts +74 -6
  239. package/src/tools/viewImage.js +62 -17
  240. package/src/tools/viewImage.ts +57 -12
  241. package/src/tools/visionInspector.js +15 -3
  242. package/src/tools/visionInspector.ts +15 -3
  243. package/src/tools/walkerSafety.js +2 -0
  244. package/src/tools/walkerSafety.ts +1 -0
  245. package/src/tools/webFetch.js +105 -10
  246. package/src/tools/webFetch.ts +105 -11
  247. package/src/tui/banner.js +3 -2
  248. package/src/tui/banner.ts +3 -2
  249. package/src/tui/consoleGuard.js +12 -4
  250. package/src/tui/consoleGuard.ts +9 -4
  251. package/src/tui/messageInteraction.js +2 -3
  252. package/src/tui/messageInteraction.ts +2 -3
  253. package/src/tui/modelPicker.js +1 -0
  254. package/src/tui/modelPicker.ts +1 -0
  255. package/src/tui/overlay.js +3 -1
  256. package/src/tui/overlay.ts +3 -1
  257. package/src/tui/sessionPicker.js +3 -2
  258. package/src/tui/sessionPicker.ts +3 -2
  259. package/src/tui/sessionPickerView.js +7 -1
  260. package/src/tui/sessionPickerView.ts +6 -1
  261. package/src/tui/toolOutputNormalizer.js +2 -3
  262. package/src/tui/toolOutputNormalizer.ts +4 -3
  263. package/src/tui/viewport.js +4 -4
  264. package/src/tui/viewport.ts +5 -5
  265. package/src/tui/workspaceIdentity.js +2 -1
  266. package/src/tui/workspaceIdentity.ts +2 -1
  267. package/src/uncertainty.js +8 -3
  268. package/src/uncertainty.ts +8 -3
  269. package/src/utils/paths.js +8 -5
  270. package/src/utils/paths.ts +9 -7
  271. package/src/vfeTracker.js +9 -3
  272. package/src/vfeTracker.ts +9 -3
  273. package/src/config.d.ts +0 -2
  274. package/src/providers/base.d.ts +0 -94
  275. package/src/providers/factory.d.ts +0 -1
  276. 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
@@ -4,6 +4,7 @@
4
4
  // causyne.com installer. A source checkout is never rewritten. Commands are
5
5
  // passed as argv arrays with shell disabled, and the only accepted package is
6
6
  // the public @causyne/agent package from the npm registry.
7
+ import crypto from 'node:crypto';
7
8
  import fs from 'node:fs';
8
9
  import path from 'node:path';
9
10
  import { fileURLToPath } from 'node:url';
@@ -11,6 +12,8 @@ import { spawnSync } from 'node:child_process';
11
12
  import { UI } from './utils/cli_ui.js';
12
13
  import { causyneHome } from './utils/paths.js';
13
14
  import { getPackageVersion } from './version.js';
15
+ import { probeOsSandbox, resolveOsSandboxMode } from './tools/osSandbox.js';
16
+ import { probeOsKeychain, resolveKeychainMode } from './osKeychain.js';
14
17
  const PACKAGE_NAME = '@causyne/agent';
15
18
  const REGISTRY_LATEST = 'https://registry.npmjs.org/@causyne%2fagent/latest';
16
19
  const DEFAULT_CHECK_INTERVAL_MS = 0; // A bare 'causyne' checks the published version on every launch
@@ -82,8 +85,11 @@ function managedPrefix(packageRoot = PACKAGE_ROOT, env = process.env) {
82
85
  ];
83
86
  for (const marker of markers) {
84
87
  const index = packageRoot.lastIndexOf(marker);
85
- if (index >= 0 && index + marker.length === packageRoot.length) {
86
- 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(/[\\/]$/, '');
87
93
  }
88
94
  }
89
95
  return null;
@@ -140,23 +146,110 @@ function writeState(state, options = {}) {
140
146
  // Update state is an optimisation. Failure must never stop the CLI.
141
147
  }
142
148
  }
143
- export async function latestPackageVersion(options = {}) {
149
+ const SRI_PATTERN = /^(sha512|sha384|sha256)-([A-Za-z0-9+/]+={0,2})$/;
150
+ function isOfficialRegistryHttpsUrl(rawUrl) {
151
+ if (typeof rawUrl !== 'string' || !rawUrl.trim())
152
+ return false;
153
+ try {
154
+ const parsed = new URL(rawUrl.trim());
155
+ return parsed.protocol === 'https:' && parsed.hostname === 'registry.npmjs.org';
156
+ }
157
+ catch {
158
+ return false;
159
+ }
160
+ }
161
+ /**
162
+ * Verifies constant-time SRI integrity (`sha512-...`, `sha384-...`, or `sha256-...`)
163
+ * of a downloaded tarball buffer against the registry-declared integrity string.
164
+ */
165
+ export function verifyTarballIntegrity(data, expectedIntegrity) {
166
+ if (!Buffer.isBuffer(data) || typeof expectedIntegrity !== 'string')
167
+ return false;
168
+ const match = expectedIntegrity.trim().match(SRI_PATTERN);
169
+ if (!match)
170
+ return false;
171
+ const algorithm = match[1];
172
+ const expectedDigest = Buffer.from(match[2], 'base64');
173
+ const actualDigest = crypto.createHash(algorithm).update(data).digest();
174
+ if (expectedDigest.length !== actualDigest.length)
175
+ return false;
176
+ return crypto.timingSafeEqual(expectedDigest, actualDigest);
177
+ }
178
+ /**
179
+ * Validates npm registry metadata for `@causyne/agent`, enforcing official HTTPS
180
+ * tarball origin, valid SRI integrity format, and optional Sigstore provenance
181
+ * attestation checks (`requireProvenance` or `CAUSYNE_REQUIRE_PROVENANCE=1`).
182
+ */
183
+ export function verifyRegistryMetadataIntegrity(metadata, options = {}) {
184
+ if (!metadata || typeof metadata !== 'object' || Array.isArray(metadata)) {
185
+ throw new Error('npm registry returned invalid package metadata');
186
+ }
187
+ const record = metadata;
188
+ if (record.name !== PACKAGE_NAME || typeof record.version !== 'string' || !versionParts(record.version)) {
189
+ throw new Error('npm registry returned invalid package metadata');
190
+ }
191
+ let tarballUrl;
192
+ let integrity;
193
+ let attestationUrl;
194
+ let provenanceVerified = false;
195
+ if (record.dist !== undefined) {
196
+ if (!record.dist || typeof record.dist !== 'object' || Array.isArray(record.dist)) {
197
+ throw new Error('npm registry returned malformed dist metadata');
198
+ }
199
+ if (record.dist.tarball !== undefined) {
200
+ if (!isOfficialRegistryHttpsUrl(record.dist.tarball)) {
201
+ throw new Error('npm registry tarball URL must use HTTPS on registry.npmjs.org');
202
+ }
203
+ tarballUrl = record.dist.tarball;
204
+ }
205
+ if (record.dist.integrity !== undefined) {
206
+ if (typeof record.dist.integrity !== 'string' || !SRI_PATTERN.test(record.dist.integrity.trim())) {
207
+ throw new Error('npm registry returned malformed SRI integrity digest');
208
+ }
209
+ integrity = record.dist.integrity.trim();
210
+ }
211
+ if (record.dist.attestations && typeof record.dist.attestations === 'object') {
212
+ const attUrl = record.dist.attestations.url;
213
+ const predicateType = record.dist.attestations.provenance?.predicateType;
214
+ if (isOfficialRegistryHttpsUrl(attUrl) && typeof predicateType === 'string' && predicateType.length > 0) {
215
+ attestationUrl = attUrl;
216
+ provenanceVerified = true;
217
+ }
218
+ }
219
+ }
220
+ if (options.requireProvenance && !provenanceVerified) {
221
+ throw new Error(`Release ${PACKAGE_NAME}@${record.version} lacks verified npm provenance attestations.`);
222
+ }
223
+ return {
224
+ version: record.version,
225
+ ...(tarballUrl ? { tarballUrl } : {}),
226
+ ...(integrity ? { integrity } : {}),
227
+ provenanceVerified,
228
+ ...(attestationUrl ? { attestationUrl } : {})
229
+ };
230
+ }
231
+ export async function latestPackageRelease(options = {}) {
144
232
  const fetchImpl = options.fetchImpl || globalThis.fetch;
145
233
  if (typeof fetchImpl !== 'function')
146
234
  throw new Error('This Node.js runtime has no fetch implementation.');
147
235
  const timeoutMs = options.timeoutMs || 3500;
148
236
  const signal = options.signal || AbortSignal.timeout(timeoutMs);
237
+ const env = options.env || process.env;
238
+ const requireProvenance = options.requireProvenance
239
+ ?? (env.CAUSYNE_REQUIRE_PROVENANCE === '1' || env.CAUSYNE_REQUIRE_PROVENANCE === 'true');
149
240
  const response = await fetchImpl(REGISTRY_LATEST, {
150
241
  headers: { accept: 'application/json', 'user-agent': `causyne/${getPackageVersion()}` },
242
+ redirect: 'error',
151
243
  signal
152
244
  });
153
245
  if (!response.ok)
154
246
  throw new Error(`npm registry returned HTTP ${response.status}`);
155
- const metadata = (await response.json());
156
- if (metadata.name !== PACKAGE_NAME || !versionParts(metadata.version)) {
157
- throw new Error('npm registry returned invalid package metadata');
158
- }
159
- return metadata.version;
247
+ const metadata = await response.json();
248
+ return verifyRegistryMetadataIntegrity(metadata, { requireProvenance });
249
+ }
250
+ export async function latestPackageVersion(options = {}) {
251
+ const release = await latestPackageRelease(options);
252
+ return release.version;
160
253
  }
161
254
  function installLatest(info, options = {}) {
162
255
  if (!info.prefix) {
@@ -195,8 +288,14 @@ function installLatest(info, options = {}) {
195
288
  }
196
289
  export async function checkForUpdate(options = {}) {
197
290
  const current = options.currentVersion || getPackageVersion();
198
- const latest = await latestPackageVersion(options);
199
- return { current, latest, available: compareVersions(latest, current) > 0 };
291
+ const release = await latestPackageRelease(options);
292
+ return {
293
+ current,
294
+ latest: release.version,
295
+ available: compareVersions(release.version, current) > 0,
296
+ provenanceVerified: release.provenanceVerified,
297
+ ...(release.integrity ? { integrity: release.integrity } : {})
298
+ };
200
299
  }
201
300
  export async function runSelfUpdate(verbose = false, options = {}) {
202
301
  const info = installationInfo(options);
@@ -277,14 +376,21 @@ export async function diagnoseInstallation(options = {}) {
277
376
  };
278
377
  }
279
378
  export function formatDoctorReport(status, runtime = process) {
379
+ const sandboxCap = probeOsSandbox();
380
+ const sandboxMode = resolveOsSandboxMode(runtime.env);
381
+ const keychainCap = probeOsKeychain({ env: runtime.env });
382
+ const keychainMode = resolveKeychainMode(runtime.env);
280
383
  const rows = [
281
384
  `Version : ${status.current || 'unknown'}`,
282
385
  `Latest : ${status.latest || `unavailable (${status.error || 'unknown error'})`}`,
386
+ `Provenance : ${status.provenanceVerified ? 'verified (npm Sigstore attestation)' : 'unverified / not reported'}`,
283
387
  `Installation : ${status.type}`,
284
388
  `Package root : ${status.packageRoot}`,
285
389
  `NPM command : ${status.npmCommand}`,
286
390
  `Node.js : ${runtime.version}`,
287
391
  `Platform : ${runtime.platform} ${runtime.arch}`,
392
+ `OS Sandbox : ${sandboxMode.mode} (backend: ${sandboxCap.backend}${sandboxCap.available ? ', available' : ', unavailable'})`,
393
+ `OS Keychain : ${keychainMode} (backend: ${keychainCap.backend}${keychainCap.available ? ', available' : ', unavailable'})`,
288
394
  `Auto updates : ${status.autoUpdates ? 'enabled' : 'disabled'}`,
289
395
  `Workspace : ${runtime.cwd()}`
290
396
  ];
package/src/autoUpdate.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  // passed as argv arrays with shell disabled, and the only accepted package is
6
6
  // the public @causyne/agent package from the npm registry.
7
7
 
8
+ import crypto from 'node:crypto';
8
9
  import fs from 'node:fs';
9
10
  import path from 'node:path';
10
11
  import { fileURLToPath } from 'node:url';
@@ -13,6 +14,8 @@ import { spawnSync, type SpawnSyncReturns } from 'node:child_process';
13
14
  import { UI } from './utils/cli_ui.js';
14
15
  import { causyneHome } from './utils/paths.js';
15
16
  import { getPackageVersion } from './version.js';
17
+ import { probeOsSandbox, resolveOsSandboxMode } from './tools/osSandbox.js';
18
+ import { probeOsKeychain, resolveKeychainMode } from './osKeychain.js';
16
19
 
17
20
  const PACKAGE_NAME = '@causyne/agent';
18
21
  const REGISTRY_LATEST = 'https://registry.npmjs.org/@causyne%2fagent/latest';
@@ -46,6 +49,15 @@ export interface CheckUpdateOptions {
46
49
  timeoutMs?: number;
47
50
  signal?: AbortSignal;
48
51
  env?: NodeJS.ProcessEnv;
52
+ requireProvenance?: boolean;
53
+ }
54
+
55
+ export interface VerifiedReleaseMetadata {
56
+ version: string;
57
+ tarballUrl?: string | undefined;
58
+ integrity?: string | undefined;
59
+ provenanceVerified: boolean;
60
+ attestationUrl?: string | undefined;
49
61
  }
50
62
 
51
63
  export interface SelfUpdateOptions extends CheckUpdateOptions {
@@ -61,6 +73,8 @@ export interface CheckResult {
61
73
  current: string;
62
74
  latest: string;
63
75
  available: boolean;
76
+ provenanceVerified?: boolean | undefined;
77
+ integrity?: string | undefined;
64
78
  }
65
79
 
66
80
  export interface UpdateResult extends InstallationInfo {
@@ -76,6 +90,8 @@ export interface DiagnosisResult extends InstallationInfo {
76
90
  current?: string | undefined;
77
91
  latest?: string | null | undefined;
78
92
  available?: boolean | undefined;
93
+ provenanceVerified?: boolean | undefined;
94
+ integrity?: string | undefined;
79
95
  autoUpdates: boolean;
80
96
  error?: string | undefined;
81
97
  }
@@ -137,8 +153,11 @@ function managedPrefix(packageRoot: string = PACKAGE_ROOT, env: NodeJS.ProcessEn
137
153
  ];
138
154
  for (const marker of markers) {
139
155
  const index = packageRoot.lastIndexOf(marker);
140
- if (index >= 0 && index + marker.length === packageRoot.length) {
141
- 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(/[\\/]$/, '');
142
161
  }
143
162
  }
144
163
  return null;
@@ -202,21 +221,128 @@ function writeState(state: UpdateState, options: { stateFile?: string; env?: Nod
202
221
  }
203
222
  }
204
223
 
205
- export async function latestPackageVersion(options: CheckUpdateOptions = {}): Promise<string> {
224
+ const SRI_PATTERN = /^(sha512|sha384|sha256)-([A-Za-z0-9+/]+={0,2})$/;
225
+
226
+ function isOfficialRegistryHttpsUrl(rawUrl: unknown): rawUrl is string {
227
+ if (typeof rawUrl !== 'string' || !rawUrl.trim()) return false;
228
+ try {
229
+ const parsed = new URL(rawUrl.trim());
230
+ return parsed.protocol === 'https:' && parsed.hostname === 'registry.npmjs.org';
231
+ } catch {
232
+ return false;
233
+ }
234
+ }
235
+
236
+ /**
237
+ * Verifies constant-time SRI integrity (`sha512-...`, `sha384-...`, or `sha256-...`)
238
+ * of a downloaded tarball buffer against the registry-declared integrity string.
239
+ */
240
+ export function verifyTarballIntegrity(data: Buffer, expectedIntegrity: string): boolean {
241
+ if (!Buffer.isBuffer(data) || typeof expectedIntegrity !== 'string') return false;
242
+ const match = expectedIntegrity.trim().match(SRI_PATTERN);
243
+ if (!match) return false;
244
+ const algorithm = match[1]!;
245
+ const expectedDigest = Buffer.from(match[2]!, 'base64');
246
+ const actualDigest = crypto.createHash(algorithm).update(data).digest();
247
+ if (expectedDigest.length !== actualDigest.length) return false;
248
+ return crypto.timingSafeEqual(expectedDigest, actualDigest);
249
+ }
250
+
251
+ /**
252
+ * Validates npm registry metadata for `@causyne/agent`, enforcing official HTTPS
253
+ * tarball origin, valid SRI integrity format, and optional Sigstore provenance
254
+ * attestation checks (`requireProvenance` or `CAUSYNE_REQUIRE_PROVENANCE=1`).
255
+ */
256
+ export function verifyRegistryMetadataIntegrity(
257
+ metadata: unknown,
258
+ options: { requireProvenance?: boolean | undefined } = {}
259
+ ): VerifiedReleaseMetadata {
260
+ if (!metadata || typeof metadata !== 'object' || Array.isArray(metadata)) {
261
+ throw new Error('npm registry returned invalid package metadata');
262
+ }
263
+ const record = metadata as {
264
+ name?: unknown;
265
+ version?: unknown;
266
+ dist?: {
267
+ tarball?: unknown;
268
+ integrity?: unknown;
269
+ attestations?: {
270
+ url?: unknown;
271
+ provenance?: { predicateType?: unknown };
272
+ };
273
+ };
274
+ };
275
+
276
+ if (record.name !== PACKAGE_NAME || typeof record.version !== 'string' || !versionParts(record.version)) {
277
+ throw new Error('npm registry returned invalid package metadata');
278
+ }
279
+
280
+ let tarballUrl: string | undefined;
281
+ let integrity: string | undefined;
282
+ let attestationUrl: string | undefined;
283
+ let provenanceVerified = false;
284
+
285
+ if (record.dist !== undefined) {
286
+ if (!record.dist || typeof record.dist !== 'object' || Array.isArray(record.dist)) {
287
+ throw new Error('npm registry returned malformed dist metadata');
288
+ }
289
+ if (record.dist.tarball !== undefined) {
290
+ if (!isOfficialRegistryHttpsUrl(record.dist.tarball)) {
291
+ throw new Error('npm registry tarball URL must use HTTPS on registry.npmjs.org');
292
+ }
293
+ tarballUrl = record.dist.tarball;
294
+ }
295
+ if (record.dist.integrity !== undefined) {
296
+ if (typeof record.dist.integrity !== 'string' || !SRI_PATTERN.test(record.dist.integrity.trim())) {
297
+ throw new Error('npm registry returned malformed SRI integrity digest');
298
+ }
299
+ integrity = record.dist.integrity.trim();
300
+ }
301
+ if (record.dist.attestations && typeof record.dist.attestations === 'object') {
302
+ const attUrl = record.dist.attestations.url;
303
+ const predicateType = record.dist.attestations.provenance?.predicateType;
304
+ if (isOfficialRegistryHttpsUrl(attUrl) && typeof predicateType === 'string' && predicateType.length > 0) {
305
+ attestationUrl = attUrl;
306
+ provenanceVerified = true;
307
+ }
308
+ }
309
+ }
310
+
311
+ if (options.requireProvenance && !provenanceVerified) {
312
+ throw new Error(`Release ${PACKAGE_NAME}@${record.version} lacks verified npm provenance attestations.`);
313
+ }
314
+
315
+ return {
316
+ version: record.version,
317
+ ...(tarballUrl ? { tarballUrl } : {}),
318
+ ...(integrity ? { integrity } : {}),
319
+ provenanceVerified,
320
+ ...(attestationUrl ? { attestationUrl } : {})
321
+ };
322
+ }
323
+
324
+ export async function latestPackageRelease(options: CheckUpdateOptions = {}): Promise<VerifiedReleaseMetadata> {
206
325
  const fetchImpl = options.fetchImpl || globalThis.fetch;
207
326
  if (typeof fetchImpl !== 'function') throw new Error('This Node.js runtime has no fetch implementation.');
208
327
  const timeoutMs = options.timeoutMs || 3500;
209
328
  const signal = options.signal || AbortSignal.timeout(timeoutMs);
329
+ const env = options.env || process.env;
330
+ const requireProvenance = options.requireProvenance
331
+ ?? (env.CAUSYNE_REQUIRE_PROVENANCE === '1' || env.CAUSYNE_REQUIRE_PROVENANCE === 'true');
332
+
210
333
  const response = await fetchImpl(REGISTRY_LATEST, {
211
334
  headers: { accept: 'application/json', 'user-agent': `causyne/${getPackageVersion()}` },
335
+ redirect: 'error',
212
336
  signal
213
337
  });
214
338
  if (!response.ok) throw new Error(`npm registry returned HTTP ${response.status}`);
215
- const metadata = (await response.json()) as { name?: string; version?: string };
216
- if (metadata.name !== PACKAGE_NAME || !versionParts(metadata.version)) {
217
- throw new Error('npm registry returned invalid package metadata');
218
- }
219
- return metadata.version as string;
339
+ const metadata: unknown = await response.json();
340
+ return verifyRegistryMetadataIntegrity(metadata, { requireProvenance });
341
+ }
342
+
343
+ export async function latestPackageVersion(options: CheckUpdateOptions = {}): Promise<string> {
344
+ const release = await latestPackageRelease(options);
345
+ return release.version;
220
346
  }
221
347
 
222
348
  function installLatest(info: InstallationInfo, options: SelfUpdateOptions = {}): void {
@@ -260,8 +386,14 @@ function installLatest(info: InstallationInfo, options: SelfUpdateOptions = {}):
260
386
 
261
387
  export async function checkForUpdate(options: CheckUpdateOptions = {}): Promise<CheckResult> {
262
388
  const current = options.currentVersion || getPackageVersion();
263
- const latest = await latestPackageVersion(options);
264
- return { current, latest, available: compareVersions(latest, current) > 0 };
389
+ const release = await latestPackageRelease(options);
390
+ return {
391
+ current,
392
+ latest: release.version,
393
+ available: compareVersions(release.version, current) > 0,
394
+ provenanceVerified: release.provenanceVerified,
395
+ ...(release.integrity ? { integrity: release.integrity } : {})
396
+ };
265
397
  }
266
398
 
267
399
  export async function runSelfUpdate(verbose: boolean = false, options: SelfUpdateOptions = {}): Promise<UpdateResult> {
@@ -344,14 +476,21 @@ export async function diagnoseInstallation(options: CheckUpdateOptions = {}): Pr
344
476
  }
345
477
 
346
478
  export function formatDoctorReport(status: DiagnosisResult, runtime: typeof process = process): string {
479
+ const sandboxCap = probeOsSandbox();
480
+ const sandboxMode = resolveOsSandboxMode(runtime.env);
481
+ const keychainCap = probeOsKeychain({ env: runtime.env });
482
+ const keychainMode = resolveKeychainMode(runtime.env);
347
483
  const rows = [
348
484
  `Version : ${status.current || 'unknown'}`,
349
485
  `Latest : ${status.latest || `unavailable (${status.error || 'unknown error'})`}`,
486
+ `Provenance : ${status.provenanceVerified ? 'verified (npm Sigstore attestation)' : 'unverified / not reported'}`,
350
487
  `Installation : ${status.type}`,
351
488
  `Package root : ${status.packageRoot}`,
352
489
  `NPM command : ${status.npmCommand}`,
353
490
  `Node.js : ${runtime.version}`,
354
491
  `Platform : ${runtime.platform} ${runtime.arch}`,
492
+ `OS Sandbox : ${sandboxMode.mode} (backend: ${sandboxCap.backend}${sandboxCap.available ? ', available' : ', unavailable'})`,
493
+ `OS Keychain : ${keychainMode} (backend: ${keychainCap.backend}${keychainCap.available ? ', available' : ', unavailable'})`,
355
494
  `Auto updates : ${status.autoUpdates ? 'enabled' : 'disabled'}`,
356
495
  `Workspace : ${runtime.cwd()}`
357
496
  ];
@@ -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);