@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
@@ -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);
@@ -0,0 +1,263 @@
1
+ /**
2
+ * Causyne Agent — Optional OS Keychain Master-Key Backend (Sector 6C)
3
+ *
4
+ * Stores and retrieves the 32-byte AES-256-GCM vault master key in the host
5
+ * operating system's credential store when enabled via `CAUSYNE_KEYCHAIN=on|auto|strict`:
6
+ * - macOS (`darwin`): Keychain Services (`/usr/bin/security -i` via stdin, never argv)
7
+ * - Linux (`linux`): libsecret (`secret-tool` via stdin, never argv)
8
+ * - Windows (`win32`): DPAPI `CurrentUser` encrypted blob (`.vault_key.dpapi` via stdin)
9
+ *
10
+ * Defaults to `'off'` so headless CI runners, containers, and existing `.vault_key`
11
+ * users experience zero unexpected OS prompts.
12
+ */
13
+ import { spawnSync } from 'node:child_process';
14
+ import crypto from 'node:crypto';
15
+ import fs from 'node:fs';
16
+ import path from 'node:path';
17
+ const KEYCHAIN_SERVICE = 'causyne-agent';
18
+ const EXPECTED_KEY_BYTES = 32;
19
+ const EXPECTED_KEY_HEX_LEN = EXPECTED_KEY_BYTES * 2;
20
+ const MACOS_SECURITY_BIN = '/usr/bin/security';
21
+ export function resolveKeychainMode(env = process.env) {
22
+ const raw = typeof env.CAUSYNE_KEYCHAIN === 'string' ? env.CAUSYNE_KEYCHAIN.trim().toLowerCase() : '';
23
+ if (raw === 'strict')
24
+ return 'strict';
25
+ if (raw === 'on' || raw === '1' || raw === 'true')
26
+ return 'on';
27
+ if (raw === 'auto')
28
+ return 'auto';
29
+ return 'off';
30
+ }
31
+ export function keychainAccountForVaultDir(vaultDir) {
32
+ const digest = crypto.createHash('sha256').update(path.resolve(vaultDir)).digest('hex').slice(0, 12);
33
+ return `vault-key-${digest}`;
34
+ }
35
+ function isValidHexKey(raw) {
36
+ return raw.length === EXPECTED_KEY_HEX_LEN && /^[0-9a-fA-F]+$/.test(raw);
37
+ }
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
+ }
42
+ const pathVal = env.PATH || env.Path || '';
43
+ for (const rawDir of pathVal.split(path.delimiter)) {
44
+ const dir = rawDir.trim();
45
+ if (!dir || !path.isAbsolute(dir))
46
+ continue;
47
+ const full = path.join(dir, binary);
48
+ try {
49
+ fs.accessSync(full, fs.constants.X_OK);
50
+ if (fs.statSync(full).isFile())
51
+ return full;
52
+ }
53
+ catch {
54
+ continue;
55
+ }
56
+ }
57
+ return null;
58
+ }
59
+ export function probeOsKeychain(options = {}) {
60
+ const platform = options.platform ?? process.platform;
61
+ const env = options.env ?? process.env;
62
+ if (platform === 'darwin') {
63
+ const exists = fs.existsSync(MACOS_SECURITY_BIN);
64
+ return {
65
+ backend: exists ? 'macos-keychain' : 'none',
66
+ platform,
67
+ available: exists,
68
+ reason: exists ? 'macOS Keychain Services (/usr/bin/security) available.' : 'macOS security CLI not found.'
69
+ };
70
+ }
71
+ if (platform === 'linux') {
72
+ const secretTool = findInPath('secret-tool', env);
73
+ return {
74
+ backend: secretTool ? 'linux-secret-service' : 'none',
75
+ platform,
76
+ available: Boolean(secretTool),
77
+ reason: secretTool ? 'Linux Secret Service (secret-tool) available.' : 'secret-tool not installed.'
78
+ };
79
+ }
80
+ if (platform === 'win32') {
81
+ return {
82
+ backend: 'windows-dpapi',
83
+ platform,
84
+ available: true,
85
+ reason: 'Windows DPAPI (CurrentUser scope) available.'
86
+ };
87
+ }
88
+ return {
89
+ backend: 'none',
90
+ platform,
91
+ available: false,
92
+ reason: `No OS keychain backend implemented for platform "${platform}".`
93
+ };
94
+ }
95
+ function dpapiBlobPath(vaultDir) {
96
+ return path.join(path.resolve(vaultDir), '.vault_key.dpapi');
97
+ }
98
+ /**
99
+ * Loads the 32-byte vault key from the OS credential store, or returns `null` if absent/unavailable.
100
+ */
101
+ const SAFE_ACCOUNT_PATTERN = /^vault-key-[0-9a-f]{12}$/;
102
+ export function loadVaultKeyFromKeychain(vaultDir, options = {}) {
103
+ if (typeof vaultDir !== 'string' || !vaultDir.trim() || vaultDir.includes('\0'))
104
+ return null;
105
+ const platform = options.platform ?? process.platform;
106
+ const runner = options.spawnSyncImpl ?? spawnSync;
107
+ const account = keychainAccountForVaultDir(vaultDir);
108
+ if (platform === 'darwin') {
109
+ const res = runner(MACOS_SECURITY_BIN, ['find-generic-password', '-s', KEYCHAIN_SERVICE, '-a', account, '-w'], {
110
+ encoding: 'utf8',
111
+ stdio: ['ignore', 'pipe', 'pipe'],
112
+ timeout: 5000,
113
+ maxBuffer: 1024 * 1024,
114
+ windowsHide: true,
115
+ shell: false
116
+ });
117
+ if (!res || res.error || res.status !== 0 || typeof res.stdout !== 'string')
118
+ return null;
119
+ const hex = res.stdout.trim();
120
+ return isValidHexKey(hex) ? Buffer.from(hex, 'hex') : null;
121
+ }
122
+ if (platform === 'linux') {
123
+ const res = runner('secret-tool', ['lookup', 'service', KEYCHAIN_SERVICE, 'account', account], {
124
+ encoding: 'utf8',
125
+ stdio: ['ignore', 'pipe', 'pipe'],
126
+ timeout: 5000,
127
+ maxBuffer: 1024 * 1024,
128
+ windowsHide: true,
129
+ shell: false
130
+ });
131
+ if (res.status !== 0 || typeof res.stdout !== 'string')
132
+ return null;
133
+ const hex = res.stdout.trim();
134
+ return isValidHexKey(hex) ? Buffer.from(hex, 'hex') : null;
135
+ }
136
+ if (platform === 'win32') {
137
+ const blobFile = dpapiBlobPath(vaultDir);
138
+ if (!fs.existsSync(blobFile))
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
+ }
148
+ const protectedBase64 = fs.readFileSync(blobFile, 'utf8').trim();
149
+ if (!protectedBase64 || !/^[A-Za-z0-9+/=]+$/.test(protectedBase64))
150
+ return null;
151
+ const script = [
152
+ 'Add-Type -AssemblyName System.Security',
153
+ '$b64 = [Console]::In.ReadToEnd().Trim()',
154
+ '$enc = [Convert]::FromBase64String($b64)',
155
+ '$plain = [System.Security.Cryptography.ProtectedData]::Unprotect($enc, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)',
156
+ '[Console]::Out.Write([System.Text.Encoding]::UTF8.GetString($plain))'
157
+ ].join('; ');
158
+ const res = runner('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', script], {
159
+ input: protectedBase64,
160
+ encoding: 'utf8',
161
+ stdio: ['pipe', 'pipe', 'pipe'],
162
+ timeout: 8000,
163
+ maxBuffer: 1024 * 1024,
164
+ windowsHide: true,
165
+ shell: false
166
+ });
167
+ if (res.status !== 0 || typeof res.stdout !== 'string')
168
+ return null;
169
+ const hex = res.stdout.trim();
170
+ return isValidHexKey(hex) ? Buffer.from(hex, 'hex') : null;
171
+ }
172
+ return null;
173
+ }
174
+ /**
175
+ * Persists a 32-byte vault key into the OS credential store without passing
176
+ * secret material on command-line argv (always delivered via stdin).
177
+ */
178
+ export function saveVaultKeyToKeychain(vaultDir, key, options = {}) {
179
+ if (typeof vaultDir !== 'string' || !vaultDir.trim() || vaultDir.includes('\0'))
180
+ return false;
181
+ if (!Buffer.isBuffer(key) || key.length !== EXPECTED_KEY_BYTES)
182
+ return false;
183
+ const platform = options.platform ?? process.platform;
184
+ const runner = options.spawnSyncImpl ?? spawnSync;
185
+ const account = keychainAccountForVaultDir(vaultDir);
186
+ const hexKey = key.toString('hex');
187
+ if (!SAFE_ACCOUNT_PATTERN.test(account) || !isValidHexKey(hexKey))
188
+ return false;
189
+ if (platform === 'darwin') {
190
+ // Use interactive `-i` stdin mode so the hex key never appears in process argv (`ps`)
191
+ const stdinCmd = `add-generic-password -U -s "${KEYCHAIN_SERVICE}" -a "${account}" -w "${hexKey}"\n`;
192
+ const res = runner(MACOS_SECURITY_BIN, ['-i'], {
193
+ input: stdinCmd,
194
+ encoding: 'utf8',
195
+ stdio: ['pipe', 'pipe', 'pipe'],
196
+ timeout: 5000,
197
+ maxBuffer: 1024 * 1024,
198
+ windowsHide: true,
199
+ shell: false
200
+ });
201
+ return Boolean(res && !res.error && res.status === 0);
202
+ }
203
+ if (platform === 'linux') {
204
+ const res = runner('secret-tool', ['store', '--label', 'Causyne Agent Vault Key', 'service', KEYCHAIN_SERVICE, 'account', account], {
205
+ input: hexKey,
206
+ encoding: 'utf8',
207
+ stdio: ['pipe', 'pipe', 'pipe'],
208
+ timeout: 5000,
209
+ maxBuffer: 1024 * 1024,
210
+ windowsHide: true,
211
+ shell: false
212
+ });
213
+ return Boolean(res && !res.error && res.status === 0);
214
+ }
215
+ if (platform === 'win32') {
216
+ const script = [
217
+ 'Add-Type -AssemblyName System.Security',
218
+ '$hex = [Console]::In.ReadToEnd().Trim()',
219
+ '$bytes = [System.Text.Encoding]::UTF8.GetBytes($hex)',
220
+ '$enc = [System.Security.Cryptography.ProtectedData]::Protect($bytes, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)',
221
+ '[Console]::Out.Write([Convert]::ToBase64String($enc))'
222
+ ].join('; ');
223
+ const res = runner('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', script], {
224
+ input: hexKey,
225
+ encoding: 'utf8',
226
+ stdio: ['pipe', 'pipe', 'pipe'],
227
+ timeout: 8000,
228
+ maxBuffer: 1024 * 1024,
229
+ windowsHide: true,
230
+ shell: false
231
+ });
232
+ if (res.status !== 0 || typeof res.stdout !== 'string' || !res.stdout.trim())
233
+ return false;
234
+ const blobFile = dpapiBlobPath(vaultDir);
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
+ }
260
+ return true;
261
+ }
262
+ return false;
263
+ }
@@ -0,0 +1,287 @@
1
+ /**
2
+ * Causyne Agent — Optional OS Keychain Master-Key Backend (Sector 6C)
3
+ *
4
+ * Stores and retrieves the 32-byte AES-256-GCM vault master key in the host
5
+ * operating system's credential store when enabled via `CAUSYNE_KEYCHAIN=on|auto|strict`:
6
+ * - macOS (`darwin`): Keychain Services (`/usr/bin/security -i` via stdin, never argv)
7
+ * - Linux (`linux`): libsecret (`secret-tool` via stdin, never argv)
8
+ * - Windows (`win32`): DPAPI `CurrentUser` encrypted blob (`.vault_key.dpapi` via stdin)
9
+ *
10
+ * Defaults to `'off'` so headless CI runners, containers, and existing `.vault_key`
11
+ * users experience zero unexpected OS prompts.
12
+ */
13
+
14
+ import { spawnSync, type SpawnSyncReturns } from 'node:child_process';
15
+ import crypto from 'node:crypto';
16
+ import fs from 'node:fs';
17
+ import path from 'node:path';
18
+
19
+ export type OsKeychainMode = 'off' | 'auto' | 'on' | 'strict';
20
+ export type OsKeychainBackend = 'macos-keychain' | 'linux-secret-service' | 'windows-dpapi' | 'none';
21
+
22
+ export interface OsKeychainCapabilities {
23
+ backend: OsKeychainBackend;
24
+ platform: NodeJS.Platform;
25
+ available: boolean;
26
+ reason: string;
27
+ }
28
+
29
+ export interface KeychainSpawnOptions {
30
+ platform?: NodeJS.Platform | undefined;
31
+ env?: NodeJS.ProcessEnv | undefined;
32
+ spawnSyncImpl?: ((command: string, args: readonly string[], options: Record<string, unknown>) => SpawnSyncReturns<string>) | undefined;
33
+ }
34
+
35
+ const KEYCHAIN_SERVICE = 'causyne-agent';
36
+ const EXPECTED_KEY_BYTES = 32;
37
+ const EXPECTED_KEY_HEX_LEN = EXPECTED_KEY_BYTES * 2;
38
+ const MACOS_SECURITY_BIN = '/usr/bin/security';
39
+
40
+ export function resolveKeychainMode(env: NodeJS.ProcessEnv = process.env): OsKeychainMode {
41
+ const raw = typeof env.CAUSYNE_KEYCHAIN === 'string' ? env.CAUSYNE_KEYCHAIN.trim().toLowerCase() : '';
42
+ if (raw === 'strict') return 'strict';
43
+ if (raw === 'on' || raw === '1' || raw === 'true') return 'on';
44
+ if (raw === 'auto') return 'auto';
45
+ return 'off';
46
+ }
47
+
48
+ export function keychainAccountForVaultDir(vaultDir: string): string {
49
+ const digest = crypto.createHash('sha256').update(path.resolve(vaultDir)).digest('hex').slice(0, 12);
50
+ return `vault-key-${digest}`;
51
+ }
52
+
53
+ function isValidHexKey(raw: string): boolean {
54
+ return raw.length === EXPECTED_KEY_HEX_LEN && /^[0-9a-fA-F]+$/.test(raw);
55
+ }
56
+
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
+ }
61
+ const pathVal = env.PATH || env.Path || '';
62
+ for (const rawDir of pathVal.split(path.delimiter)) {
63
+ const dir = rawDir.trim();
64
+ if (!dir || !path.isAbsolute(dir)) continue;
65
+ const full = path.join(dir, binary);
66
+ try {
67
+ fs.accessSync(full, fs.constants.X_OK);
68
+ if (fs.statSync(full).isFile()) return full;
69
+ } catch {
70
+ continue;
71
+ }
72
+ }
73
+ return null;
74
+ }
75
+
76
+ export function probeOsKeychain(options: KeychainSpawnOptions = {}): OsKeychainCapabilities {
77
+ const platform = options.platform ?? process.platform;
78
+ const env = options.env ?? process.env;
79
+
80
+ if (platform === 'darwin') {
81
+ const exists = fs.existsSync(MACOS_SECURITY_BIN);
82
+ return {
83
+ backend: exists ? 'macos-keychain' : 'none',
84
+ platform,
85
+ available: exists,
86
+ reason: exists ? 'macOS Keychain Services (/usr/bin/security) available.' : 'macOS security CLI not found.'
87
+ };
88
+ }
89
+
90
+ if (platform === 'linux') {
91
+ const secretTool = findInPath('secret-tool', env);
92
+ return {
93
+ backend: secretTool ? 'linux-secret-service' : 'none',
94
+ platform,
95
+ available: Boolean(secretTool),
96
+ reason: secretTool ? 'Linux Secret Service (secret-tool) available.' : 'secret-tool not installed.'
97
+ };
98
+ }
99
+
100
+ if (platform === 'win32') {
101
+ return {
102
+ backend: 'windows-dpapi',
103
+ platform,
104
+ available: true,
105
+ reason: 'Windows DPAPI (CurrentUser scope) available.'
106
+ };
107
+ }
108
+
109
+ return {
110
+ backend: 'none',
111
+ platform,
112
+ available: false,
113
+ reason: `No OS keychain backend implemented for platform "${platform}".`
114
+ };
115
+ }
116
+
117
+ function dpapiBlobPath(vaultDir: string): string {
118
+ return path.join(path.resolve(vaultDir), '.vault_key.dpapi');
119
+ }
120
+
121
+ /**
122
+ * Loads the 32-byte vault key from the OS credential store, or returns `null` if absent/unavailable.
123
+ */
124
+ const SAFE_ACCOUNT_PATTERN = /^vault-key-[0-9a-f]{12}$/;
125
+
126
+ export function loadVaultKeyFromKeychain(
127
+ vaultDir: string,
128
+ options: KeychainSpawnOptions = {}
129
+ ): Buffer | null {
130
+ if (typeof vaultDir !== 'string' || !vaultDir.trim() || vaultDir.includes('\0')) return null;
131
+ const platform = options.platform ?? process.platform;
132
+ const runner = options.spawnSyncImpl ?? (spawnSync as unknown as NonNullable<KeychainSpawnOptions['spawnSyncImpl']>);
133
+ const account = keychainAccountForVaultDir(vaultDir);
134
+
135
+ if (platform === 'darwin') {
136
+ const res = runner(MACOS_SECURITY_BIN, ['find-generic-password', '-s', KEYCHAIN_SERVICE, '-a', account, '-w'], {
137
+ encoding: 'utf8',
138
+ stdio: ['ignore', 'pipe', 'pipe'],
139
+ timeout: 5000,
140
+ maxBuffer: 1024 * 1024,
141
+ windowsHide: true,
142
+ shell: false
143
+ });
144
+ if (!res || res.error || res.status !== 0 || typeof res.stdout !== 'string') return null;
145
+ const hex = res.stdout.trim();
146
+ return isValidHexKey(hex) ? Buffer.from(hex, 'hex') : null;
147
+ }
148
+
149
+ if (platform === 'linux') {
150
+ const res = runner('secret-tool', ['lookup', 'service', KEYCHAIN_SERVICE, 'account', account], {
151
+ encoding: 'utf8',
152
+ stdio: ['ignore', 'pipe', 'pipe'],
153
+ timeout: 5000,
154
+ maxBuffer: 1024 * 1024,
155
+ windowsHide: true,
156
+ shell: false
157
+ });
158
+ if (res.status !== 0 || typeof res.stdout !== 'string') return null;
159
+ const hex = res.stdout.trim();
160
+ return isValidHexKey(hex) ? Buffer.from(hex, 'hex') : null;
161
+ }
162
+
163
+ if (platform === 'win32') {
164
+ const blobFile = dpapiBlobPath(vaultDir);
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
+ }
172
+ const protectedBase64 = fs.readFileSync(blobFile, 'utf8').trim();
173
+ if (!protectedBase64 || !/^[A-Za-z0-9+/=]+$/.test(protectedBase64)) return null;
174
+ const script = [
175
+ 'Add-Type -AssemblyName System.Security',
176
+ '$b64 = [Console]::In.ReadToEnd().Trim()',
177
+ '$enc = [Convert]::FromBase64String($b64)',
178
+ '$plain = [System.Security.Cryptography.ProtectedData]::Unprotect($enc, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)',
179
+ '[Console]::Out.Write([System.Text.Encoding]::UTF8.GetString($plain))'
180
+ ].join('; ');
181
+ const res = runner('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', script], {
182
+ input: protectedBase64,
183
+ encoding: 'utf8',
184
+ stdio: ['pipe', 'pipe', 'pipe'],
185
+ timeout: 8000,
186
+ maxBuffer: 1024 * 1024,
187
+ windowsHide: true,
188
+ shell: false
189
+ });
190
+ if (res.status !== 0 || typeof res.stdout !== 'string') return null;
191
+ const hex = res.stdout.trim();
192
+ return isValidHexKey(hex) ? Buffer.from(hex, 'hex') : null;
193
+ }
194
+
195
+ return null;
196
+ }
197
+
198
+ /**
199
+ * Persists a 32-byte vault key into the OS credential store without passing
200
+ * secret material on command-line argv (always delivered via stdin).
201
+ */
202
+ export function saveVaultKeyToKeychain(
203
+ vaultDir: string,
204
+ key: Buffer,
205
+ options: KeychainSpawnOptions = {}
206
+ ): boolean {
207
+ if (typeof vaultDir !== 'string' || !vaultDir.trim() || vaultDir.includes('\0')) return false;
208
+ if (!Buffer.isBuffer(key) || key.length !== EXPECTED_KEY_BYTES) return false;
209
+ const platform = options.platform ?? process.platform;
210
+ const runner = options.spawnSyncImpl ?? (spawnSync as unknown as NonNullable<KeychainSpawnOptions['spawnSyncImpl']>);
211
+ const account = keychainAccountForVaultDir(vaultDir);
212
+ const hexKey = key.toString('hex');
213
+ if (!SAFE_ACCOUNT_PATTERN.test(account) || !isValidHexKey(hexKey)) return false;
214
+
215
+ if (platform === 'darwin') {
216
+ // Use interactive `-i` stdin mode so the hex key never appears in process argv (`ps`)
217
+ const stdinCmd = `add-generic-password -U -s "${KEYCHAIN_SERVICE}" -a "${account}" -w "${hexKey}"\n`;
218
+ const res = runner(MACOS_SECURITY_BIN, ['-i'], {
219
+ input: stdinCmd,
220
+ encoding: 'utf8',
221
+ stdio: ['pipe', 'pipe', 'pipe'],
222
+ timeout: 5000,
223
+ maxBuffer: 1024 * 1024,
224
+ windowsHide: true,
225
+ shell: false
226
+ });
227
+ return Boolean(res && !res.error && res.status === 0);
228
+ }
229
+
230
+ if (platform === 'linux') {
231
+ const res = runner(
232
+ 'secret-tool',
233
+ ['store', '--label', 'Causyne Agent Vault Key', 'service', KEYCHAIN_SERVICE, 'account', account],
234
+ {
235
+ input: hexKey,
236
+ encoding: 'utf8',
237
+ stdio: ['pipe', 'pipe', 'pipe'],
238
+ timeout: 5000,
239
+ maxBuffer: 1024 * 1024,
240
+ windowsHide: true,
241
+ shell: false
242
+ }
243
+ );
244
+ return Boolean(res && !res.error && res.status === 0);
245
+ }
246
+
247
+ if (platform === 'win32') {
248
+ const script = [
249
+ 'Add-Type -AssemblyName System.Security',
250
+ '$hex = [Console]::In.ReadToEnd().Trim()',
251
+ '$bytes = [System.Text.Encoding]::UTF8.GetBytes($hex)',
252
+ '$enc = [System.Security.Cryptography.ProtectedData]::Protect($bytes, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)',
253
+ '[Console]::Out.Write([Convert]::ToBase64String($enc))'
254
+ ].join('; ');
255
+ const res = runner('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', script], {
256
+ input: hexKey,
257
+ encoding: 'utf8',
258
+ stdio: ['pipe', 'pipe', 'pipe'],
259
+ timeout: 8000,
260
+ maxBuffer: 1024 * 1024,
261
+ windowsHide: true,
262
+ shell: false
263
+ });
264
+ if (res.status !== 0 || typeof res.stdout !== 'string' || !res.stdout.trim()) return false;
265
+ const blobFile = dpapiBlobPath(vaultDir);
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
+ }
283
+ return true;
284
+ }
285
+
286
+ return false;
287
+ }
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 {