@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
@@ -82,6 +82,7 @@ export function cleanToolOutputPreview(payload: string, toolName = ''): string {
82
82
  if (!trimmed || trimmed.startsWith(DECAY_MARKER)) return '';
83
83
 
84
84
  let text = payload
85
+ .replace(/\r\n?/g, '\n')
85
86
  .replace(/\x1b\[(?:[12]K|\d*G)/g, '\n')
86
87
  .replace(/(https?:\/\/[^\s"'<>]+?\.[a-z]{2,10})([A-Z][a-z]{2,15}:\s)/g, '$1\n$2');
87
88
 
@@ -158,9 +159,9 @@ function recoverBrokenJsonOutput(raw: string, spillPath?: string | undefined): R
158
159
  if (outputMatch?.[1]) {
159
160
  const body = outputMatch[1]
160
161
  .replace(/"\s*\}\s*$/, '')
161
- .replace(/\\n/g, '\n')
162
- .replace(/\\"/g, '"')
163
- .replace(/\\\\/g, '\\');
162
+ .replace(/\\([\\nrt"])/g, (_m, ch: string) =>
163
+ ch === 'n' ? '\n' : ch === 'r' ? '\r' : ch === 't' ? '\t' : ch
164
+ );
164
165
  return {
165
166
  success,
166
167
  output: body,
@@ -52,11 +52,11 @@ export class ScrollAcceleration {
52
52
  this.streakTimeout = Number.isFinite(streakTimeout) && streakTimeout >= 0 ? streakTimeout : 150;
53
53
  this.minTickInterval = Number.isFinite(minTickInterval) && minTickInterval >= 0 ? minTickInterval : 6;
54
54
  this.intervals = [];
55
- this.lastTick = 0;
55
+ this.lastTick = null;
56
56
  }
57
57
  reset() {
58
58
  this.intervals = [];
59
- this.lastTick = 0;
59
+ this.lastTick = null;
60
60
  }
61
61
  tick(now = Date.now()) {
62
62
  if (!Number.isFinite(now))
@@ -64,13 +64,13 @@ export class ScrollAcceleration {
64
64
  const A = 0.8;
65
65
  const tau = 3;
66
66
  const maxMultiplier = 6;
67
- const gap = this.lastTick ? now - this.lastTick : Infinity;
67
+ const gap = this.lastTick !== null ? now - this.lastTick : Infinity;
68
68
  if (gap === Infinity || gap > this.streakTimeout) {
69
69
  this.lastTick = now;
70
70
  this.intervals = [];
71
71
  return 1;
72
72
  }
73
- if (gap < Math.max(0, this.minTickInterval))
73
+ if (gap <= 0 || gap < Math.max(0, this.minTickInterval))
74
74
  return 1;
75
75
  this.lastTick = now;
76
76
  if (this.historySize > 0) {
@@ -54,19 +54,19 @@ export class ScrollAcceleration {
54
54
  readonly streakTimeout: number;
55
55
  readonly minTickInterval: number;
56
56
  intervals: number[];
57
- lastTick: number;
57
+ lastTick: number | null;
58
58
 
59
59
  constructor({ history = 3, streakTimeout = 150, minTickInterval = 6 }: ScrollAccelerationOptions = {}) {
60
60
  this.historySize = Number.isFinite(history) ? Math.max(0, Math.floor(history)) : 3;
61
61
  this.streakTimeout = Number.isFinite(streakTimeout) && streakTimeout >= 0 ? streakTimeout : 150;
62
62
  this.minTickInterval = Number.isFinite(minTickInterval) && minTickInterval >= 0 ? minTickInterval : 6;
63
63
  this.intervals = [];
64
- this.lastTick = 0;
64
+ this.lastTick = null;
65
65
  }
66
66
 
67
67
  reset(): void {
68
68
  this.intervals = [];
69
- this.lastTick = 0;
69
+ this.lastTick = null;
70
70
  }
71
71
 
72
72
  tick(now: number = Date.now()): number {
@@ -75,13 +75,13 @@ export class ScrollAcceleration {
75
75
  const tau = 3;
76
76
  const maxMultiplier = 6;
77
77
 
78
- const gap = this.lastTick ? now - this.lastTick : Infinity;
78
+ const gap = this.lastTick !== null ? now - this.lastTick : Infinity;
79
79
  if (gap === Infinity || gap > this.streakTimeout) {
80
80
  this.lastTick = now;
81
81
  this.intervals = [];
82
82
  return 1;
83
83
  }
84
- if (gap < Math.max(0, this.minTickInterval)) return 1;
84
+ if (gap <= 0 || gap < Math.max(0, this.minTickInterval)) return 1;
85
85
 
86
86
  this.lastTick = now;
87
87
  if (this.historySize > 0) {
@@ -84,7 +84,8 @@ export function shortenWorkspacePath(workspacePath) {
84
84
  const prefix = cmpHome.endsWith(path.sep) ? cmpHome : `${cmpHome}${path.sep}`;
85
85
  if (cmpResolved.startsWith(prefix)) {
86
86
  const tail = resolved.slice(resolvedHome.length);
87
- return cleanInlineText(`~${tail}`) || '~';
87
+ const joined = tail.startsWith(path.sep) ? `~${tail}` : `~${path.sep}${tail}`;
88
+ return cleanInlineText(joined) || '~';
88
89
  }
89
90
  }
90
91
  return cleanInlineText(trimmed) || '(default)';
@@ -92,7 +92,8 @@ export function shortenWorkspacePath(workspacePath: string | undefined): string
92
92
  const prefix = cmpHome.endsWith(path.sep) ? cmpHome : `${cmpHome}${path.sep}`;
93
93
  if (cmpResolved.startsWith(prefix)) {
94
94
  const tail = resolved.slice(resolvedHome.length);
95
- return cleanInlineText(`~${tail}`) || '~';
95
+ const joined = tail.startsWith(path.sep) ? `~${tail}` : `~${path.sep}${tail}`;
96
+ return cleanInlineText(joined) || '~';
96
97
  }
97
98
  }
98
99
  return cleanInlineText(trimmed) || '(default)';
@@ -82,7 +82,8 @@ export function assessStep(signals = {}) {
82
82
  score += capped;
83
83
  fired.push(name);
84
84
  };
85
- const failures = Number(signals.consecutiveFailures) || 0;
85
+ const rawFailures = Number(signals.consecutiveFailures);
86
+ const failures = Number.isFinite(rawFailures) && rawFailures > 0 ? Math.floor(rawFailures) : 0;
86
87
  if (failures > 0)
87
88
  add(Math.min(failures, 3) * WEIGHTS.consecutiveFailure, `failures:${failures}`);
88
89
  if (signals.lastResult) {
@@ -96,8 +97,12 @@ export function assessStep(signals = {}) {
96
97
  if (signals.vfePlateau) {
97
98
  add(WEIGHTS.vfePlateau, 'vfe_plateau');
98
99
  }
99
- const bestPrior = Math.max(Number(signals.planSimilarity) || 0, Number(signals.lessonSimilarity) || 0);
100
- if (bestPrior === 0)
100
+ const finiteSim = (v) => {
101
+ const n = Number(v);
102
+ return Number.isFinite(n) ? n : 0;
103
+ };
104
+ const bestPrior = Math.max(0, finiteSim(signals.planSimilarity), finiteSim(signals.lessonSimilarity));
105
+ if (bestPrior <= 0)
101
106
  add(WEIGHTS.noPriorArt, 'no_prior_art');
102
107
  if (typeof signals.assistantText === 'string' && HEDGE.test(signals.assistantText)) {
103
108
  add(WEIGHTS.hedging, 'model_hedged');
@@ -170,7 +170,8 @@ export function assessStep(signals: StepSignals = {}): Assessment {
170
170
  fired.push(name);
171
171
  };
172
172
 
173
- const failures = Number(signals.consecutiveFailures) || 0;
173
+ const rawFailures = Number(signals.consecutiveFailures);
174
+ const failures = Number.isFinite(rawFailures) && rawFailures > 0 ? Math.floor(rawFailures) : 0;
174
175
  if (failures > 0) add(Math.min(failures, 3) * WEIGHTS.consecutiveFailure, `failures:${failures}`);
175
176
 
176
177
  if (signals.lastResult) {
@@ -186,8 +187,12 @@ export function assessStep(signals: StepSignals = {}): Assessment {
186
187
  add(WEIGHTS.vfePlateau, 'vfe_plateau');
187
188
  }
188
189
 
189
- const bestPrior = Math.max(Number(signals.planSimilarity) || 0, Number(signals.lessonSimilarity) || 0);
190
- if (bestPrior === 0) add(WEIGHTS.noPriorArt, 'no_prior_art');
190
+ const finiteSim = (v: unknown): number => {
191
+ const n = Number(v);
192
+ return Number.isFinite(n) ? n : 0;
193
+ };
194
+ const bestPrior = Math.max(0, finiteSim(signals.planSimilarity), finiteSim(signals.lessonSimilarity));
195
+ if (bestPrior <= 0) add(WEIGHTS.noPriorArt, 'no_prior_art');
191
196
 
192
197
  if (typeof signals.assistantText === 'string' && HEDGE.test(signals.assistantText)) {
193
198
  add(WEIGHTS.hedging, 'model_hedged');
@@ -1,14 +1,17 @@
1
1
  import fs from 'node:fs';
2
2
  import os from 'node:os';
3
3
  import path from 'node:path';
4
+ function isWithinDir(child, parent) {
5
+ const c = process.platform === 'win32' ? child.toLowerCase() : child;
6
+ const p = process.platform === 'win32' ? parent.toLowerCase() : parent;
7
+ const rel = path.relative(p, c);
8
+ return rel === '' || (rel !== '..' && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel));
9
+ }
4
10
  function isTempHome(dir) {
5
11
  const normalized = path.resolve(dir);
6
12
  const tmp = path.resolve(os.tmpdir());
7
- return (normalized.startsWith(tmp) ||
8
- normalized.startsWith('/tmp/') ||
9
- normalized.startsWith('/private/tmp/') ||
10
- normalized.startsWith('/var/folders/') ||
11
- normalized.startsWith('/private/var/folders/'));
13
+ const roots = [tmp, '/tmp', '/private/tmp', '/var/folders', '/private/var/folders'];
14
+ return roots.some((root) => isWithinDir(normalized, path.resolve(root)));
12
15
  }
13
16
  function isNodeTestRunner() {
14
17
  if (process.env['NODE_TEST_CONTEXT'])
@@ -2,16 +2,18 @@ import fs from 'node:fs';
2
2
  import os from 'node:os';
3
3
  import path from 'node:path';
4
4
 
5
+ function isWithinDir(child: string, parent: string): boolean {
6
+ const c = process.platform === 'win32' ? child.toLowerCase() : child;
7
+ const p = process.platform === 'win32' ? parent.toLowerCase() : parent;
8
+ const rel = path.relative(p, c);
9
+ return rel === '' || (rel !== '..' && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel));
10
+ }
11
+
5
12
  function isTempHome(dir: string): boolean {
6
13
  const normalized = path.resolve(dir);
7
14
  const tmp = path.resolve(os.tmpdir());
8
- return (
9
- normalized.startsWith(tmp) ||
10
- normalized.startsWith('/tmp/') ||
11
- normalized.startsWith('/private/tmp/') ||
12
- normalized.startsWith('/var/folders/') ||
13
- normalized.startsWith('/private/var/folders/')
14
- );
15
+ const roots = [tmp, '/tmp', '/private/tmp', '/var/folders', '/private/var/folders'];
16
+ return roots.some((root) => isWithinDir(normalized, path.resolve(root)));
15
17
  }
16
18
 
17
19
  function isNodeTestRunner(): boolean {
package/src/vfeTracker.js CHANGED
@@ -38,9 +38,15 @@ export class VFETracker {
38
38
  lastShiftStep;
39
39
  totalSteps;
40
40
  constructor(options = {}) {
41
- this.windowSize = options.windowSize || VFE_WINDOW_SIZE;
42
- this.varianceEpsilon = options.varianceEpsilon || VARIANCE_EPSILON;
43
- this.meanThreshold = options.meanThreshold || MEAN_ERROR_THRESHOLD;
41
+ this.windowSize = typeof options.windowSize === 'number' && Number.isFinite(options.windowSize) && options.windowSize >= 1
42
+ ? Math.floor(options.windowSize)
43
+ : VFE_WINDOW_SIZE;
44
+ this.varianceEpsilon = typeof options.varianceEpsilon === 'number' && Number.isFinite(options.varianceEpsilon) && options.varianceEpsilon >= 0
45
+ ? options.varianceEpsilon
46
+ : VARIANCE_EPSILON;
47
+ this.meanThreshold = typeof options.meanThreshold === 'number' && Number.isFinite(options.meanThreshold) && options.meanThreshold >= 0
48
+ ? options.meanThreshold
49
+ : MEAN_ERROR_THRESHOLD;
44
50
  this.history = [];
45
51
  this.lastShiftStep = -SHIFT_COOLDOWN_STEPS;
46
52
  this.totalSteps = 0;
package/src/vfeTracker.ts CHANGED
@@ -93,9 +93,15 @@ export class VFETracker {
93
93
  totalSteps: number;
94
94
 
95
95
  constructor(options: VFETrackerOptions = {}) {
96
- this.windowSize = options.windowSize || VFE_WINDOW_SIZE;
97
- this.varianceEpsilon = options.varianceEpsilon || VARIANCE_EPSILON;
98
- this.meanThreshold = options.meanThreshold || MEAN_ERROR_THRESHOLD;
96
+ this.windowSize = typeof options.windowSize === 'number' && Number.isFinite(options.windowSize) && options.windowSize >= 1
97
+ ? Math.floor(options.windowSize)
98
+ : VFE_WINDOW_SIZE;
99
+ this.varianceEpsilon = typeof options.varianceEpsilon === 'number' && Number.isFinite(options.varianceEpsilon) && options.varianceEpsilon >= 0
100
+ ? options.varianceEpsilon
101
+ : VARIANCE_EPSILON;
102
+ this.meanThreshold = typeof options.meanThreshold === 'number' && Number.isFinite(options.meanThreshold) && options.meanThreshold >= 0
103
+ ? options.meanThreshold
104
+ : MEAN_ERROR_THRESHOLD;
99
105
 
100
106
  this.history = [];
101
107
  this.lastShiftStep = -SHIFT_COOLDOWN_STEPS;
package/src/config.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export function loadConfig(): Record<string, unknown>;
2
- export function saveConfig(config: Record<string, unknown>): void;
@@ -1,94 +0,0 @@
1
- import type { RequestPermissionRequest, RequestPermissionResponse } from '../acp/protocol.js';
2
-
3
- export interface ProviderConfig {
4
- apiKey?: string | undefined;
5
- model?: string | undefined;
6
- baseUrl?: string | undefined;
7
- provider?: string | undefined;
8
- command?: string | undefined;
9
- args?: string[] | undefined;
10
- peer?: string | undefined;
11
- supportsVision?: boolean | undefined;
12
- [key: string]: any;
13
- }
14
-
15
- export interface ChatResponseUsage {
16
- promptTokens: number;
17
- completionTokens: number;
18
- cachedPromptTokens?: number | undefined;
19
- uncachedPromptTokens?: number | undefined;
20
- measurement?: 'provider_reported' | 'text_estimate' | undefined;
21
- cacheMeasurement?: 'provider_reported' | 'unavailable' | undefined;
22
- measurementScope?: 'last_model_call' | 'peer_reported' | undefined;
23
- totalTokens?: number | undefined;
24
- thinkingTokens?: number | undefined;
25
- }
26
-
27
- export interface ChatResponseToolCall {
28
- id: string;
29
- type: string;
30
- function: {
31
- name: string;
32
- arguments: string;
33
- };
34
- }
35
-
36
- export interface ChatResponseAction {
37
- id?: string | undefined;
38
- name: string;
39
- status: 'running' | 'completed' | 'failed';
40
- detail?: string | undefined;
41
- parameters?: Record<string, unknown> | undefined;
42
- }
43
-
44
- export interface ChatResponse {
45
- content: string;
46
- usage: ChatResponseUsage;
47
- toolCalls?: ChatResponseToolCall[] | undefined;
48
- reasoningContent?: string | undefined;
49
- thinkingBlocks?: any[] | undefined;
50
- externalActions?: ChatResponseAction[] | undefined;
51
- toolRoutingError?: { tool: string; message: string; parameters?: Record<string, unknown> | undefined } | undefined;
52
- incompleteTurn?: boolean | undefined;
53
- }
54
-
55
- export interface ChatOptions {
56
- onPeerPermission?: ((request: RequestPermissionRequest) => Promise<RequestPermissionResponse['outcome']>) | undefined;
57
- onPeerFileRead?: ((file: string, options?: { line?: number; limit?: number }) => Promise<string>) | undefined;
58
- onPeerFileWrite?: ((file: string, content: string) => Promise<void>) | undefined;
59
- peerMcpServers?: unknown[] | undefined;
60
- tokenBudgetBasis?: 'total' | 'noncached' | undefined;
61
- tools?: any[] | undefined;
62
- temperature?: number | undefined;
63
- maxRetries?: number | undefined;
64
- signal?: AbortSignal | undefined;
65
- onChunk?: ((chunk: string) => void) | undefined;
66
- onReasoningChunk?: ((chunk: string) => void) | undefined;
67
- onNativeAction?: ((action: ChatResponseAction) => void) | undefined;
68
- onPlanUpdate?: ((plan: unknown) => void) | undefined;
69
- coreToolCount?: number | undefined;
70
- [key: string]: any;
71
- }
72
-
73
- export class LLMProvider {
74
- apiKey?: string;
75
- model: string;
76
- baseUrl?: string;
77
- visionModels: string[];
78
- imagePayloadFormat: string;
79
- visionOverride: boolean | null;
80
- audioModels: string[];
81
- audioPayloadFormat: string;
82
-
83
- constructor(config?: ProviderConfig);
84
- get supportsVision(): boolean;
85
- get supportsAudio(): boolean;
86
- supportsToolSearch?(): boolean;
87
- prepareMessages(messages: any[]): any[];
88
- normalizeUsage(rawUsage: any): ChatResponseUsage;
89
- chat(messages: any[], options?: ChatOptions): Promise<ChatResponse>;
90
- }
91
-
92
- export function mimeTypeForAudioFormat(format: string): string;
93
- export function audioFormatForMimeType(mimeType: string): string;
94
- export function isAudioBlock(block: any): boolean;
@@ -1 +0,0 @@
1
- export function createProvider(...args: any[]): any;
package/src/sandbox.d.ts DELETED
@@ -1 +0,0 @@
1
- export const Sandbox: any;