@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
@@ -271,25 +271,35 @@ export function extractToolCallJsonObjects(text, allowUnclosedHealing = true) {
271
271
  }
272
272
  return results;
273
273
  }
274
- const TRAILING_PARTIAL_TOOL_TAG = /<\/?(?:t(?:o(?:o(?:l(?:_(?:c(?:a(?:l(?:l)?)?)?)?)?)?)?)?|f(?:u(?:n(?:c(?:t(?:i(?:o(?:n(?:_(?:c(?:a(?:l(?:l(?:s)?)?)?)?)?)?)?)?)?)?)?)?)?|i(?:n(?:v(?:o(?:k(?:e)?)?)?)?)?|[||][^\n>]*)$/i;
274
+ const TRAILING_PARTIAL_TOOL_TAG = /<\/?(?:t(?:o(?:o(?:l(?:_(?:c(?:a(?:l(?:l)?)?)?)?)?)?)?)?|f(?:u(?:n(?:c(?:t(?:i(?:o(?:n(?:_(?:c(?:a(?:l(?:l(?:s)?)?)?)?)?)?)?)?)?)?)?)?)?|i(?:n(?:v(?:o(?:k(?:e)?)?)?)?)?|[||][^\n><]*)$/i;
275
275
  const TRAILING_PARTIAL_THINK_TAG = /<\/?(?:t(?:h(?:i(?:n(?:k(?:i(?:n(?:g)?)?)?)?|o(?:u(?:g(?:h(?:t)?)?)?)?)?)?)?|r(?:e(?:a(?:s(?:o(?:n(?:i(?:n(?:g(?:_(?:s(?:c(?:r(?:a(?:t(?:c(?:h(?:p(?:a(?:d)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)$/i;
276
276
  export function stripToolCallMarkup(text) {
277
277
  if (!text || typeof text !== 'string')
278
278
  return '';
279
- return text
280
- .replace(/<tool_call>[\s\S]*?(?:<\/tool_call>|(?:\s*<\/?[||]DSML[||][^>]*>)+|$)/gi, '')
281
- .replace(/<[||]DSML[||][\s\S]*?(?:<\/[||]DSML[||]\s*calls>|$)/gi, '')
282
- .replace(/(?:\s*<\/?[||]DSML[||][^>]*>)+/gi, '')
283
- .replace(TRAILING_PARTIAL_TOOL_TAG, '')
284
- .trim();
279
+ let out = text;
280
+ let prev;
281
+ do {
282
+ prev = out;
283
+ out = out
284
+ .replace(/<tool_call>[\s\S]*?(?:<\/tool_call>|(?:\s*<\/?[||]DSML[||][^>]*>)+|$)/gi, '')
285
+ .replace(/<[||]DSML[||][\s\S]*?(?:<\/[||]DSML[||]\s*calls>|$)/gi, '')
286
+ .replace(/(?:\s*<\/?[||]DSML[||][^>]*>)+/gi, '')
287
+ .replace(TRAILING_PARTIAL_TOOL_TAG, '');
288
+ } while (out !== prev);
289
+ return out.trim();
285
290
  }
286
291
  export function stripThinkBlocks(text) {
287
292
  if (!text || typeof text !== 'string')
288
293
  return '';
289
- return text
290
- .replace(/<(?:think|thought|reasoning|thinking|REASONING_SCRATCHPAD)>[\s\S]*?(?:<\/(?:think|thought|reasoning|thinking|REASONING_SCRATCHPAD)>|$)/gi, '')
291
- .replace(TRAILING_PARTIAL_THINK_TAG, '')
292
- .trim();
294
+ let out = text;
295
+ let prev;
296
+ do {
297
+ prev = out;
298
+ out = out
299
+ .replace(/<(?:think|thought|reasoning|thinking|REASONING_SCRATCHPAD)>[\s\S]*?(?:<\/(?:think|thought|reasoning|thinking|REASONING_SCRATCHPAD)>|$)/gi, '')
300
+ .replace(TRAILING_PARTIAL_THINK_TAG, '');
301
+ } while (out !== prev);
302
+ return out.trim();
293
303
  }
294
304
  export function extractLivePlanFromText(text, allowTrailing = false) {
295
305
  if (!text || typeof text !== 'string')
@@ -272,25 +272,35 @@ export function extractToolCallJsonObjects(text: string, allowUnclosedHealing =
272
272
  return results;
273
273
  }
274
274
 
275
- const TRAILING_PARTIAL_TOOL_TAG = /<\/?(?:t(?:o(?:o(?:l(?:_(?:c(?:a(?:l(?:l)?)?)?)?)?)?)?)?|f(?:u(?:n(?:c(?:t(?:i(?:o(?:n(?:_(?:c(?:a(?:l(?:l(?:s)?)?)?)?)?)?)?)?)?)?)?)?)?|i(?:n(?:v(?:o(?:k(?:e)?)?)?)?)?|[||][^\n>]*)$/i;
275
+ const TRAILING_PARTIAL_TOOL_TAG = /<\/?(?:t(?:o(?:o(?:l(?:_(?:c(?:a(?:l(?:l)?)?)?)?)?)?)?)?|f(?:u(?:n(?:c(?:t(?:i(?:o(?:n(?:_(?:c(?:a(?:l(?:l(?:s)?)?)?)?)?)?)?)?)?)?)?)?)?|i(?:n(?:v(?:o(?:k(?:e)?)?)?)?)?|[||][^\n><]*)$/i;
276
276
  const TRAILING_PARTIAL_THINK_TAG = /<\/?(?:t(?:h(?:i(?:n(?:k(?:i(?:n(?:g)?)?)?)?|o(?:u(?:g(?:h(?:t)?)?)?)?)?)?)?|r(?:e(?:a(?:s(?:o(?:n(?:i(?:n(?:g(?:_(?:s(?:c(?:r(?:a(?:t(?:c(?:h(?:p(?:a(?:d)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)$/i;
277
277
 
278
278
  export function stripToolCallMarkup(text: string): string {
279
279
  if (!text || typeof text !== 'string') return '';
280
- return text
281
- .replace(/<tool_call>[\s\S]*?(?:<\/tool_call>|(?:\s*<\/?[||]DSML[||][^>]*>)+|$)/gi, '')
282
- .replace(/<[||]DSML[||][\s\S]*?(?:<\/[||]DSML[||]\s*calls>|$)/gi, '')
283
- .replace(/(?:\s*<\/?[||]DSML[||][^>]*>)+/gi, '')
284
- .replace(TRAILING_PARTIAL_TOOL_TAG, '')
285
- .trim();
280
+ let out = text;
281
+ let prev: string;
282
+ do {
283
+ prev = out;
284
+ out = out
285
+ .replace(/<tool_call>[\s\S]*?(?:<\/tool_call>|(?:\s*<\/?[||]DSML[||][^>]*>)+|$)/gi, '')
286
+ .replace(/<[||]DSML[||][\s\S]*?(?:<\/[||]DSML[||]\s*calls>|$)/gi, '')
287
+ .replace(/(?:\s*<\/?[||]DSML[||][^>]*>)+/gi, '')
288
+ .replace(TRAILING_PARTIAL_TOOL_TAG, '');
289
+ } while (out !== prev);
290
+ return out.trim();
286
291
  }
287
292
 
288
293
  export function stripThinkBlocks(text: string): string {
289
294
  if (!text || typeof text !== 'string') return '';
290
- return text
291
- .replace(/<(?:think|thought|reasoning|thinking|REASONING_SCRATCHPAD)>[\s\S]*?(?:<\/(?:think|thought|reasoning|thinking|REASONING_SCRATCHPAD)>|$)/gi, '')
292
- .replace(TRAILING_PARTIAL_THINK_TAG, '')
293
- .trim();
295
+ let out = text;
296
+ let prev: string;
297
+ do {
298
+ prev = out;
299
+ out = out
300
+ .replace(/<(?:think|thought|reasoning|thinking|REASONING_SCRATCHPAD)>[\s\S]*?(?:<\/(?:think|thought|reasoning|thinking|REASONING_SCRATCHPAD)>|$)/gi, '')
301
+ .replace(TRAILING_PARTIAL_THINK_TAG, '');
302
+ } while (out !== prev);
303
+ return out.trim();
294
304
  }
295
305
 
296
306
  export function extractLivePlanFromText(text: string, allowTrailing = false): PlanUpdate | null {
@@ -14,7 +14,10 @@ import * as crypto from 'node:crypto';
14
14
  export function atomicWriteFileSync(targetPath, content, options = {}) {
15
15
  const resolved = path.resolve(targetPath);
16
16
  const dir = path.dirname(resolved);
17
- fs.mkdirSync(dir, { recursive: true, mode: options.mode ?? 0o755 });
17
+ const dirMode = options.mode !== undefined
18
+ ? (options.mode | ((options.mode & 0o444) >> 2))
19
+ : 0o755;
20
+ fs.mkdirSync(dir, { recursive: true, mode: dirMode });
18
21
  const randomSuffix = crypto.randomBytes(6).toString('hex');
19
22
  const tempPath = path.join(dir, `.${path.basename(resolved)}.${randomSuffix}.tmp`);
20
23
  try {
@@ -25,7 +25,10 @@ export function atomicWriteFileSync(
25
25
  ): void {
26
26
  const resolved = path.resolve(targetPath);
27
27
  const dir = path.dirname(resolved);
28
- fs.mkdirSync(dir, { recursive: true, mode: options.mode ?? 0o755 });
28
+ const dirMode = options.mode !== undefined
29
+ ? (options.mode | ((options.mode & 0o444) >> 2))
30
+ : 0o755;
31
+ fs.mkdirSync(dir, { recursive: true, mode: dirMode });
29
32
 
30
33
  const randomSuffix = crypto.randomBytes(6).toString('hex');
31
34
  const tempPath = path.join(dir, `.${path.basename(resolved)}.${randomSuffix}.tmp`);
@@ -83,7 +83,7 @@ export function readOnlyScopeError(tool, args, prompt) {
83
83
  }
84
84
  if (tool === 'sysRun' || tool === 'sysRunBg' || tool === 'terminal_persistent_shell') {
85
85
  const command = String(args.command ?? args.input ?? '').trim();
86
- if (READ_ONLY_COMMAND.test(command) && !MUTATING_INSPECTION_OPTIONS.test(command) && !/[;&|><`$()]/.test(command)) {
86
+ if (READ_ONLY_COMMAND.test(command) && !MUTATING_INSPECTION_OPTIONS.test(command) && !hasShellControlOperators(command)) {
87
87
  return null;
88
88
  }
89
89
  return 'A read-only inquiry authorizes only non-mutating status inspection commands (e.g. pwd, git status, cat), not arbitrary execution.';
@@ -88,7 +88,7 @@ export function readOnlyScopeError(
88
88
  }
89
89
  if (tool === 'sysRun' || tool === 'sysRunBg' || tool === 'terminal_persistent_shell') {
90
90
  const command = String(args.command ?? args.input ?? '').trim();
91
- if (READ_ONLY_COMMAND.test(command) && !MUTATING_INSPECTION_OPTIONS.test(command) && !/[;&|><`$()]/.test(command)) {
91
+ if (READ_ONLY_COMMAND.test(command) && !MUTATING_INSPECTION_OPTIONS.test(command) && !hasShellControlOperators(command)) {
92
92
  return null;
93
93
  }
94
94
  return 'A read-only inquiry authorizes only non-mutating status inspection commands (e.g. pwd, git status, cat), not arbitrary execution.';
@@ -15,7 +15,7 @@ function normalizeWorkspace(workspace) {
15
15
  }
16
16
  function isPathWithinOrSame(candidatePath, rootPath) {
17
17
  const rel = path.relative(path.resolve(rootPath), path.resolve(candidatePath));
18
- return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));
18
+ return rel === '' || (rel !== '..' && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel));
19
19
  }
20
20
  function extractEmbeddedAbsolutePaths(text) {
21
21
  const found = [];
@@ -40,7 +40,7 @@ function normalizeWorkspace(workspace?: string | null): string | undefined {
40
40
 
41
41
  function isPathWithinOrSame(candidatePath: string, rootPath: string): boolean {
42
42
  const rel = path.relative(path.resolve(rootPath), path.resolve(candidatePath));
43
- return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));
43
+ return rel === '' || (rel !== '..' && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel));
44
44
  }
45
45
 
46
46
  function extractEmbeddedAbsolutePaths(text: string): string[] {
@@ -161,6 +161,7 @@ function extractCollapsedSignature(lines, startIndex, kind) {
161
161
  function findBraceBlockEnd(lines, startIndex, kind) {
162
162
  const isCallable = kind === 'function' || kind === 'method';
163
163
  let inBlockComment = false;
164
+ let inTemplate = false;
164
165
  let parenDepth = 0;
165
166
  let seenParamsOpen = false;
166
167
  let seenParamsClose = !isCallable;
@@ -172,7 +173,6 @@ function findBraceBlockEnd(lines, startIndex, kind) {
172
173
  const line = lines[i] ?? '';
173
174
  let inSingleQuote = false;
174
175
  let inDoubleQuote = false;
175
- let inTemplate = false;
176
176
  for (let c = 0; c < line.length; c++) {
177
177
  const ch = line[c] ?? '';
178
178
  const next = line[c + 1] ?? '';
@@ -174,6 +174,7 @@ function extractCollapsedSignature(lines: readonly string[], startIndex: number,
174
174
  function findBraceBlockEnd(lines: readonly string[], startIndex: number, kind: FoldedSymbolKind): number {
175
175
  const isCallable = kind === 'function' || kind === 'method';
176
176
  let inBlockComment = false;
177
+ let inTemplate = false;
177
178
  let parenDepth = 0;
178
179
  let seenParamsOpen = false;
179
180
  let seenParamsClose = !isCallable;
@@ -186,7 +187,6 @@ function findBraceBlockEnd(lines: readonly string[], startIndex: number, kind: F
186
187
  const line = lines[i] ?? '';
187
188
  let inSingleQuote = false;
188
189
  let inDoubleQuote = false;
189
- let inTemplate = false;
190
190
 
191
191
  for (let c = 0; c < line.length; c++) {
192
192
  const ch = line[c] ?? '';
@@ -47,7 +47,7 @@ export function resolveRoute(config, kind) {
47
47
  reason: 'utility route set explicitly in config'
48
48
  };
49
49
  }
50
- const cheap = UTILITY_MODEL_BY_PROVIDER[provider];
50
+ const cheap = Object.hasOwn(UTILITY_MODEL_BY_PROVIDER, provider) ? UTILITY_MODEL_BY_PROVIDER[provider] : undefined;
51
51
  if (!cheap) {
52
52
  return { ...stay, reason: `no published utility tier for ${provider}; paying full rate` };
53
53
  }
@@ -101,7 +101,7 @@ export function resolveRoute(config: RouterConfig | undefined | null, kind: Rout
101
101
  };
102
102
  }
103
103
 
104
- const cheap = UTILITY_MODEL_BY_PROVIDER[provider];
104
+ const cheap = Object.hasOwn(UTILITY_MODEL_BY_PROVIDER, provider) ? UTILITY_MODEL_BY_PROVIDER[provider] : undefined;
105
105
  if (!cheap) {
106
106
  return { ...stay, reason: `no published utility tier for ${provider}; paying full rate` };
107
107
  }
@@ -275,7 +275,9 @@ function scanWrite(toolName, args, workspaceRoot, evidence) {
275
275
  const resolved = resolveTarget(workspaceRoot, rawTarget);
276
276
  const base = path.basename(resolved.physical);
277
277
  if (!resolved.inside) {
278
- const temporary = resolved.physical.startsWith(safeRealpath(os.tmpdir()));
278
+ const tmpRoot = safeRealpath(os.tmpdir());
279
+ const tmpRel = path.relative(tmpRoot, resolved.physical);
280
+ const temporary = tmpRel === '' || (tmpRel !== '..' && !tmpRel.startsWith(`..${path.sep}`) && !path.isAbsolute(tmpRel));
279
281
  add(evidence, temporary ? 'write-temporary' : 'write-outside-workspace', temporary ? 'low' : 'high', `${toolName} writes outside the workspace: ${rawTarget}`, 0.82);
280
282
  }
281
283
  if (resolved.physical.includes(`${path.sep}.git${path.sep}`) || base === '.git') {
@@ -289,7 +291,7 @@ function scanWrite(toolName, args, workspaceRoot, evidence) {
289
291
  }
290
292
  const originalSize = readSize(resolved.physical);
291
293
  let replacementSize = null;
292
- if (toolName === 'fs_write') {
294
+ if (toolName === 'fs_write' || toolName === 'write_file' || toolName === 'write_to_file' || toolName === 'write') {
293
295
  const content = typeof args.content === 'string' ? args.content : typeof args.text === 'string' ? args.text : '';
294
296
  replacementSize = Buffer.byteLength(content, 'utf8');
295
297
  if (replacementSize === 0 && originalSize !== null && originalSize > 0) {
@@ -393,7 +395,7 @@ function scanMove(args, workspaceRoot, evidence) {
393
395
  export function scanMutation(toolName, args, context) {
394
396
  const evidence = [];
395
397
  const workspaceRoot = context.workspaceRoot || process.cwd();
396
- if (['sysRun', 'sysRunBg', 'terminal_persistent_shell'].includes(toolName)) {
398
+ if (['sysRun', 'sysRunBg', 'terminal_persistent_shell', 'bash', 'execute'].includes(toolName)) {
397
399
  const command = typeof args.command === 'string'
398
400
  ? args.command
399
401
  : typeof args.cmd === 'string' ? args.cmd : '';
@@ -403,7 +405,11 @@ export function scanMutation(toolName, args, context) {
403
405
  const command = typeof args.command === 'string' ? `git ${args.command}` : '';
404
406
  scanShell(command, workspaceRoot, evidence);
405
407
  }
406
- else if (toolName === 'fs_write' || toolName === 'fs_edit' || toolName === 'MultiEdit') {
408
+ else if ([
409
+ 'fs_write', 'fs_edit', 'MultiEdit',
410
+ 'write_file', 'write_to_file', 'write',
411
+ 'edit_file', 'replace_file_content', 'multi_replace_file_content', 'edit', 'multiedit'
412
+ ].includes(toolName)) {
407
413
  scanWrite(toolName, args, workspaceRoot, evidence);
408
414
  }
409
415
  else if (toolName === 'fs_delete') {
@@ -333,7 +333,9 @@ function scanWrite(toolName: string, args: Record<string, unknown>, workspaceRoo
333
333
  const base = path.basename(resolved.physical);
334
334
 
335
335
  if (!resolved.inside) {
336
- const temporary = resolved.physical.startsWith(safeRealpath(os.tmpdir()));
336
+ const tmpRoot = safeRealpath(os.tmpdir());
337
+ const tmpRel = path.relative(tmpRoot, resolved.physical);
338
+ const temporary = tmpRel === '' || (tmpRel !== '..' && !tmpRel.startsWith(`..${path.sep}`) && !path.isAbsolute(tmpRel));
337
339
  add(
338
340
  evidence,
339
341
  temporary ? 'write-temporary' : 'write-outside-workspace',
@@ -357,7 +359,7 @@ function scanWrite(toolName: string, args: Record<string, unknown>, workspaceRoo
357
359
 
358
360
  const originalSize = readSize(resolved.physical);
359
361
  let replacementSize: number | null = null;
360
- if (toolName === 'fs_write') {
362
+ if (toolName === 'fs_write' || toolName === 'write_file' || toolName === 'write_to_file' || toolName === 'write') {
361
363
  const content = typeof args.content === 'string' ? args.content : typeof args.text === 'string' ? args.text : '';
362
364
  replacementSize = Buffer.byteLength(content, 'utf8');
363
365
  if (replacementSize === 0 && originalSize !== null && originalSize > 0) {
@@ -464,7 +466,7 @@ export function scanMutation(toolName: string, args: Record<string, unknown>, co
464
466
  const evidence: RiskEvidence[] = [];
465
467
  const workspaceRoot = context.workspaceRoot || process.cwd();
466
468
 
467
- if (['sysRun', 'sysRunBg', 'terminal_persistent_shell'].includes(toolName)) {
469
+ if (['sysRun', 'sysRunBg', 'terminal_persistent_shell', 'bash', 'execute'].includes(toolName)) {
468
470
  const command = typeof args.command === 'string'
469
471
  ? args.command
470
472
  : typeof args.cmd === 'string' ? args.cmd : '';
@@ -472,7 +474,11 @@ export function scanMutation(toolName: string, args: Record<string, unknown>, co
472
474
  } else if (toolName === 'gitOp') {
473
475
  const command = typeof args.command === 'string' ? `git ${args.command}` : '';
474
476
  scanShell(command, workspaceRoot, evidence);
475
- } else if (toolName === 'fs_write' || toolName === 'fs_edit' || toolName === 'MultiEdit') {
477
+ } else if ([
478
+ 'fs_write', 'fs_edit', 'MultiEdit',
479
+ 'write_file', 'write_to_file', 'write',
480
+ 'edit_file', 'replace_file_content', 'multi_replace_file_content', 'edit', 'multiedit'
481
+ ].includes(toolName)) {
476
482
  scanWrite(toolName, args, workspaceRoot, evidence);
477
483
  } else if (toolName === 'fs_delete') {
478
484
  scanDelete(args, workspaceRoot, evidence);
package/src/osKeychain.js CHANGED
@@ -36,9 +36,13 @@ function isValidHexKey(raw) {
36
36
  return raw.length === EXPECTED_KEY_HEX_LEN && /^[0-9a-fA-F]+$/.test(raw);
37
37
  }
38
38
  function findInPath(binary, env = process.env) {
39
+ if (!binary || binary.includes('..') || binary.includes('/') || binary.includes('\\') || /[\r\n\0]/.test(binary)) {
40
+ return null;
41
+ }
39
42
  const pathVal = env.PATH || env.Path || '';
40
- for (const dir of pathVal.split(path.delimiter)) {
41
- if (!dir)
43
+ for (const rawDir of pathVal.split(path.delimiter)) {
44
+ const dir = rawDir.trim();
45
+ if (!dir || !path.isAbsolute(dir))
42
46
  continue;
43
47
  const full = path.join(dir, binary);
44
48
  try {
@@ -94,7 +98,10 @@ function dpapiBlobPath(vaultDir) {
94
98
  /**
95
99
  * Loads the 32-byte vault key from the OS credential store, or returns `null` if absent/unavailable.
96
100
  */
101
+ const SAFE_ACCOUNT_PATTERN = /^vault-key-[0-9a-f]{12}$/;
97
102
  export function loadVaultKeyFromKeychain(vaultDir, options = {}) {
103
+ if (typeof vaultDir !== 'string' || !vaultDir.trim() || vaultDir.includes('\0'))
104
+ return null;
98
105
  const platform = options.platform ?? process.platform;
99
106
  const runner = options.spawnSyncImpl ?? spawnSync;
100
107
  const account = keychainAccountForVaultDir(vaultDir);
@@ -103,9 +110,11 @@ export function loadVaultKeyFromKeychain(vaultDir, options = {}) {
103
110
  encoding: 'utf8',
104
111
  stdio: ['ignore', 'pipe', 'pipe'],
105
112
  timeout: 5000,
113
+ maxBuffer: 1024 * 1024,
114
+ windowsHide: true,
106
115
  shell: false
107
116
  });
108
- if (res.status !== 0 || typeof res.stdout !== 'string')
117
+ if (!res || res.error || res.status !== 0 || typeof res.stdout !== 'string')
109
118
  return null;
110
119
  const hex = res.stdout.trim();
111
120
  return isValidHexKey(hex) ? Buffer.from(hex, 'hex') : null;
@@ -115,6 +124,8 @@ export function loadVaultKeyFromKeychain(vaultDir, options = {}) {
115
124
  encoding: 'utf8',
116
125
  stdio: ['ignore', 'pipe', 'pipe'],
117
126
  timeout: 5000,
127
+ maxBuffer: 1024 * 1024,
128
+ windowsHide: true,
118
129
  shell: false
119
130
  });
120
131
  if (res.status !== 0 || typeof res.stdout !== 'string')
@@ -126,8 +137,16 @@ export function loadVaultKeyFromKeychain(vaultDir, options = {}) {
126
137
  const blobFile = dpapiBlobPath(vaultDir);
127
138
  if (!fs.existsSync(blobFile))
128
139
  return null;
140
+ try {
141
+ const stat = fs.lstatSync(blobFile);
142
+ if (stat.isSymbolicLink() || !stat.isFile() || stat.size === 0 || stat.size > 65_536)
143
+ return null;
144
+ }
145
+ catch {
146
+ return null;
147
+ }
129
148
  const protectedBase64 = fs.readFileSync(blobFile, 'utf8').trim();
130
- if (!protectedBase64)
149
+ if (!protectedBase64 || !/^[A-Za-z0-9+/=]+$/.test(protectedBase64))
131
150
  return null;
132
151
  const script = [
133
152
  'Add-Type -AssemblyName System.Security',
@@ -141,6 +160,8 @@ export function loadVaultKeyFromKeychain(vaultDir, options = {}) {
141
160
  encoding: 'utf8',
142
161
  stdio: ['pipe', 'pipe', 'pipe'],
143
162
  timeout: 8000,
163
+ maxBuffer: 1024 * 1024,
164
+ windowsHide: true,
144
165
  shell: false
145
166
  });
146
167
  if (res.status !== 0 || typeof res.stdout !== 'string')
@@ -155,12 +176,16 @@ export function loadVaultKeyFromKeychain(vaultDir, options = {}) {
155
176
  * secret material on command-line argv (always delivered via stdin).
156
177
  */
157
178
  export function saveVaultKeyToKeychain(vaultDir, key, options = {}) {
179
+ if (typeof vaultDir !== 'string' || !vaultDir.trim() || vaultDir.includes('\0'))
180
+ return false;
158
181
  if (!Buffer.isBuffer(key) || key.length !== EXPECTED_KEY_BYTES)
159
182
  return false;
160
183
  const platform = options.platform ?? process.platform;
161
184
  const runner = options.spawnSyncImpl ?? spawnSync;
162
185
  const account = keychainAccountForVaultDir(vaultDir);
163
186
  const hexKey = key.toString('hex');
187
+ if (!SAFE_ACCOUNT_PATTERN.test(account) || !isValidHexKey(hexKey))
188
+ return false;
164
189
  if (platform === 'darwin') {
165
190
  // Use interactive `-i` stdin mode so the hex key never appears in process argv (`ps`)
166
191
  const stdinCmd = `add-generic-password -U -s "${KEYCHAIN_SERVICE}" -a "${account}" -w "${hexKey}"\n`;
@@ -169,9 +194,11 @@ export function saveVaultKeyToKeychain(vaultDir, key, options = {}) {
169
194
  encoding: 'utf8',
170
195
  stdio: ['pipe', 'pipe', 'pipe'],
171
196
  timeout: 5000,
197
+ maxBuffer: 1024 * 1024,
198
+ windowsHide: true,
172
199
  shell: false
173
200
  });
174
- return res.status === 0;
201
+ return Boolean(res && !res.error && res.status === 0);
175
202
  }
176
203
  if (platform === 'linux') {
177
204
  const res = runner('secret-tool', ['store', '--label', 'Causyne Agent Vault Key', 'service', KEYCHAIN_SERVICE, 'account', account], {
@@ -179,9 +206,11 @@ export function saveVaultKeyToKeychain(vaultDir, key, options = {}) {
179
206
  encoding: 'utf8',
180
207
  stdio: ['pipe', 'pipe', 'pipe'],
181
208
  timeout: 5000,
209
+ maxBuffer: 1024 * 1024,
210
+ windowsHide: true,
182
211
  shell: false
183
212
  });
184
- return res.status === 0;
213
+ return Boolean(res && !res.error && res.status === 0);
185
214
  }
186
215
  if (platform === 'win32') {
187
216
  const script = [
@@ -196,13 +225,38 @@ export function saveVaultKeyToKeychain(vaultDir, key, options = {}) {
196
225
  encoding: 'utf8',
197
226
  stdio: ['pipe', 'pipe', 'pipe'],
198
227
  timeout: 8000,
228
+ maxBuffer: 1024 * 1024,
229
+ windowsHide: true,
199
230
  shell: false
200
231
  });
201
232
  if (res.status !== 0 || typeof res.stdout !== 'string' || !res.stdout.trim())
202
233
  return false;
203
234
  const blobFile = dpapiBlobPath(vaultDir);
204
- fs.mkdirSync(path.dirname(blobFile), { recursive: true });
205
- fs.writeFileSync(blobFile, `${res.stdout.trim()}\n`, { encoding: 'utf8', mode: 0o600 });
235
+ const dir = path.dirname(blobFile);
236
+ fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
237
+ try {
238
+ const existing = fs.lstatSync(blobFile);
239
+ if (existing.isSymbolicLink() || !existing.isFile())
240
+ return false;
241
+ }
242
+ catch (err) {
243
+ const code = typeof err === 'object' && err !== null && 'code' in err ? String(err.code) : '';
244
+ if (code !== 'ENOENT')
245
+ return false;
246
+ }
247
+ const tempFile = path.join(dir, `.vault_key.dpapi.${process.pid}.${crypto.randomBytes(6).toString('hex')}.tmp`);
248
+ try {
249
+ fs.writeFileSync(tempFile, `${res.stdout.trim()}\n`, { encoding: 'utf8', mode: 0o600, flag: 'wx' });
250
+ fs.renameSync(tempFile, blobFile);
251
+ }
252
+ catch {
253
+ try {
254
+ if (fs.existsSync(tempFile))
255
+ fs.unlinkSync(tempFile);
256
+ }
257
+ catch { /* ignore */ }
258
+ return false;
259
+ }
206
260
  return true;
207
261
  }
208
262
  return false;
package/src/osKeychain.ts CHANGED
@@ -55,9 +55,13 @@ function isValidHexKey(raw: string): boolean {
55
55
  }
56
56
 
57
57
  function findInPath(binary: string, env: NodeJS.ProcessEnv = process.env): string | null {
58
+ if (!binary || binary.includes('..') || binary.includes('/') || binary.includes('\\') || /[\r\n\0]/.test(binary)) {
59
+ return null;
60
+ }
58
61
  const pathVal = env.PATH || env.Path || '';
59
- for (const dir of pathVal.split(path.delimiter)) {
60
- if (!dir) continue;
62
+ for (const rawDir of pathVal.split(path.delimiter)) {
63
+ const dir = rawDir.trim();
64
+ if (!dir || !path.isAbsolute(dir)) continue;
61
65
  const full = path.join(dir, binary);
62
66
  try {
63
67
  fs.accessSync(full, fs.constants.X_OK);
@@ -117,10 +121,13 @@ function dpapiBlobPath(vaultDir: string): string {
117
121
  /**
118
122
  * Loads the 32-byte vault key from the OS credential store, or returns `null` if absent/unavailable.
119
123
  */
124
+ const SAFE_ACCOUNT_PATTERN = /^vault-key-[0-9a-f]{12}$/;
125
+
120
126
  export function loadVaultKeyFromKeychain(
121
127
  vaultDir: string,
122
128
  options: KeychainSpawnOptions = {}
123
129
  ): Buffer | null {
130
+ if (typeof vaultDir !== 'string' || !vaultDir.trim() || vaultDir.includes('\0')) return null;
124
131
  const platform = options.platform ?? process.platform;
125
132
  const runner = options.spawnSyncImpl ?? (spawnSync as unknown as NonNullable<KeychainSpawnOptions['spawnSyncImpl']>);
126
133
  const account = keychainAccountForVaultDir(vaultDir);
@@ -130,9 +137,11 @@ export function loadVaultKeyFromKeychain(
130
137
  encoding: 'utf8',
131
138
  stdio: ['ignore', 'pipe', 'pipe'],
132
139
  timeout: 5000,
140
+ maxBuffer: 1024 * 1024,
141
+ windowsHide: true,
133
142
  shell: false
134
143
  });
135
- if (res.status !== 0 || typeof res.stdout !== 'string') return null;
144
+ if (!res || res.error || res.status !== 0 || typeof res.stdout !== 'string') return null;
136
145
  const hex = res.stdout.trim();
137
146
  return isValidHexKey(hex) ? Buffer.from(hex, 'hex') : null;
138
147
  }
@@ -142,6 +151,8 @@ export function loadVaultKeyFromKeychain(
142
151
  encoding: 'utf8',
143
152
  stdio: ['ignore', 'pipe', 'pipe'],
144
153
  timeout: 5000,
154
+ maxBuffer: 1024 * 1024,
155
+ windowsHide: true,
145
156
  shell: false
146
157
  });
147
158
  if (res.status !== 0 || typeof res.stdout !== 'string') return null;
@@ -152,8 +163,14 @@ export function loadVaultKeyFromKeychain(
152
163
  if (platform === 'win32') {
153
164
  const blobFile = dpapiBlobPath(vaultDir);
154
165
  if (!fs.existsSync(blobFile)) return null;
166
+ try {
167
+ const stat = fs.lstatSync(blobFile);
168
+ if (stat.isSymbolicLink() || !stat.isFile() || stat.size === 0 || stat.size > 65_536) return null;
169
+ } catch {
170
+ return null;
171
+ }
155
172
  const protectedBase64 = fs.readFileSync(blobFile, 'utf8').trim();
156
- if (!protectedBase64) return null;
173
+ if (!protectedBase64 || !/^[A-Za-z0-9+/=]+$/.test(protectedBase64)) return null;
157
174
  const script = [
158
175
  'Add-Type -AssemblyName System.Security',
159
176
  '$b64 = [Console]::In.ReadToEnd().Trim()',
@@ -166,6 +183,8 @@ export function loadVaultKeyFromKeychain(
166
183
  encoding: 'utf8',
167
184
  stdio: ['pipe', 'pipe', 'pipe'],
168
185
  timeout: 8000,
186
+ maxBuffer: 1024 * 1024,
187
+ windowsHide: true,
169
188
  shell: false
170
189
  });
171
190
  if (res.status !== 0 || typeof res.stdout !== 'string') return null;
@@ -185,11 +204,13 @@ export function saveVaultKeyToKeychain(
185
204
  key: Buffer,
186
205
  options: KeychainSpawnOptions = {}
187
206
  ): boolean {
207
+ if (typeof vaultDir !== 'string' || !vaultDir.trim() || vaultDir.includes('\0')) return false;
188
208
  if (!Buffer.isBuffer(key) || key.length !== EXPECTED_KEY_BYTES) return false;
189
209
  const platform = options.platform ?? process.platform;
190
210
  const runner = options.spawnSyncImpl ?? (spawnSync as unknown as NonNullable<KeychainSpawnOptions['spawnSyncImpl']>);
191
211
  const account = keychainAccountForVaultDir(vaultDir);
192
212
  const hexKey = key.toString('hex');
213
+ if (!SAFE_ACCOUNT_PATTERN.test(account) || !isValidHexKey(hexKey)) return false;
193
214
 
194
215
  if (platform === 'darwin') {
195
216
  // Use interactive `-i` stdin mode so the hex key never appears in process argv (`ps`)
@@ -199,9 +220,11 @@ export function saveVaultKeyToKeychain(
199
220
  encoding: 'utf8',
200
221
  stdio: ['pipe', 'pipe', 'pipe'],
201
222
  timeout: 5000,
223
+ maxBuffer: 1024 * 1024,
224
+ windowsHide: true,
202
225
  shell: false
203
226
  });
204
- return res.status === 0;
227
+ return Boolean(res && !res.error && res.status === 0);
205
228
  }
206
229
 
207
230
  if (platform === 'linux') {
@@ -213,10 +236,12 @@ export function saveVaultKeyToKeychain(
213
236
  encoding: 'utf8',
214
237
  stdio: ['pipe', 'pipe', 'pipe'],
215
238
  timeout: 5000,
239
+ maxBuffer: 1024 * 1024,
240
+ windowsHide: true,
216
241
  shell: false
217
242
  }
218
243
  );
219
- return res.status === 0;
244
+ return Boolean(res && !res.error && res.status === 0);
220
245
  }
221
246
 
222
247
  if (platform === 'win32') {
@@ -232,12 +257,29 @@ export function saveVaultKeyToKeychain(
232
257
  encoding: 'utf8',
233
258
  stdio: ['pipe', 'pipe', 'pipe'],
234
259
  timeout: 8000,
260
+ maxBuffer: 1024 * 1024,
261
+ windowsHide: true,
235
262
  shell: false
236
263
  });
237
264
  if (res.status !== 0 || typeof res.stdout !== 'string' || !res.stdout.trim()) return false;
238
265
  const blobFile = dpapiBlobPath(vaultDir);
239
- fs.mkdirSync(path.dirname(blobFile), { recursive: true });
240
- fs.writeFileSync(blobFile, `${res.stdout.trim()}\n`, { encoding: 'utf8', mode: 0o600 });
266
+ const dir = path.dirname(blobFile);
267
+ fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
268
+ try {
269
+ const existing = fs.lstatSync(blobFile);
270
+ if (existing.isSymbolicLink() || !existing.isFile()) return false;
271
+ } catch (err: unknown) {
272
+ const code = typeof err === 'object' && err !== null && 'code' in err ? String(err.code) : '';
273
+ if (code !== 'ENOENT') return false;
274
+ }
275
+ const tempFile = path.join(dir, `.vault_key.dpapi.${process.pid}.${crypto.randomBytes(6).toString('hex')}.tmp`);
276
+ try {
277
+ fs.writeFileSync(tempFile, `${res.stdout.trim()}\n`, { encoding: 'utf8', mode: 0o600, flag: 'wx' });
278
+ fs.renameSync(tempFile, blobFile);
279
+ } catch {
280
+ try { if (fs.existsSync(tempFile)) fs.unlinkSync(tempFile); } catch { /* ignore */ }
281
+ return false;
282
+ }
241
283
  return true;
242
284
  }
243
285
 
package/src/perception.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
  import os from 'node:os';
4
+ import { resolveUserPath } from './utils/paths.js';
4
5
  const SKIP_DIRECTORIES = new Set([
5
6
  'node_modules', '.git', 'dist', 'build', 'out', 'target',
6
7
  '.next', '.nuxt', '.venv', 'venv', '__pycache__', '.gradle',
@@ -8,7 +9,7 @@ const SKIP_DIRECTORIES = new Set([
8
9
  ]);
9
10
  export class WorkspacePerception {
10
11
  async buildContext(workspacePath) {
11
- const resolvedPath = workspacePath.replace(/^~\//, os.homedir() + '/');
12
+ const resolvedPath = resolveUserPath(workspacePath);
12
13
  const context = {
13
14
  cwd: resolvedPath,
14
15
  projectName: path.basename(resolvedPath)
@@ -363,7 +364,7 @@ export class WorkspacePerception {
363
364
  return null;
364
365
  }
365
366
  async detectGitInfo(dir) {
366
- let current = dir;
367
+ let current = path.resolve(dir);
367
368
  for (let depth = 0; depth < 5; depth++) {
368
369
  const gitDir = path.join(current, '.git');
369
370
  try {