mindweave 0.0.1 → 2.1.2

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 (481) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +171 -14
  3. package/dist/alternator/chassis/cache.js +47 -0
  4. package/dist/alternator/chassis/cache.js.map +1 -0
  5. package/dist/alternator/chassis/domRefs.js +53 -0
  6. package/dist/alternator/chassis/domRefs.js.map +1 -0
  7. package/dist/alternator/chassis/extractWorker.js +65 -0
  8. package/dist/alternator/chassis/extractWorker.js.map +1 -0
  9. package/dist/alternator/chassis/graph.js +221 -0
  10. package/dist/alternator/chassis/graph.js.map +1 -0
  11. package/dist/alternator/chassis/index.js +463 -0
  12. package/dist/alternator/chassis/index.js.map +1 -0
  13. package/dist/alternator/chassis/isolation.js +336 -0
  14. package/dist/alternator/chassis/isolation.js.map +1 -0
  15. package/dist/alternator/chassis/langCases.js +69 -0
  16. package/dist/alternator/chassis/langCases.js.map +1 -0
  17. package/dist/alternator/chassis/lsp.js +469 -0
  18. package/dist/alternator/chassis/lsp.js.map +1 -0
  19. package/dist/alternator/chassis/markup.js +262 -0
  20. package/dist/alternator/chassis/markup.js.map +1 -0
  21. package/dist/alternator/chassis/provision.js +198 -0
  22. package/dist/alternator/chassis/provision.js.map +1 -0
  23. package/dist/alternator/chassis/rank.js +72 -0
  24. package/dist/alternator/chassis/rank.js.map +1 -0
  25. package/dist/alternator/chassis/servers.js +215 -0
  26. package/dist/alternator/chassis/servers.js.map +1 -0
  27. package/dist/alternator/chassis/treesitter.js +608 -0
  28. package/dist/alternator/chassis/treesitter.js.map +1 -0
  29. package/dist/alternator/chassis/types.js +24 -0
  30. package/dist/alternator/chassis/types.js.map +1 -0
  31. package/dist/alternator/lane.js +67 -0
  32. package/dist/alternator/lane.js.map +1 -0
  33. package/dist/cli/App.js +2586 -0
  34. package/dist/cli/App.js.map +1 -0
  35. package/dist/cli/altScreen.js +67 -0
  36. package/dist/cli/altScreen.js.map +1 -0
  37. package/dist/cli/approvalChannel.js +72 -0
  38. package/dist/cli/approvalChannel.js.map +1 -0
  39. package/dist/cli/attachments.js +188 -0
  40. package/dist/cli/attachments.js.map +1 -0
  41. package/dist/cli/bootstrap.js +279 -0
  42. package/dist/cli/bootstrap.js.map +1 -0
  43. package/dist/cli/chatAnchor.js +94 -0
  44. package/dist/cli/chatAnchor.js.map +1 -0
  45. package/dist/cli/commandArgs.js +79 -0
  46. package/dist/cli/commandArgs.js.map +1 -0
  47. package/dist/cli/commandRoute.js +78 -0
  48. package/dist/cli/commandRoute.js.map +1 -0
  49. package/dist/cli/compaction.js +69 -0
  50. package/dist/cli/compaction.js.map +1 -0
  51. package/dist/cli/components/ApprovalBox.js +100 -0
  52. package/dist/cli/components/ApprovalBox.js.map +1 -0
  53. package/dist/cli/components/BlockView.js +128 -0
  54. package/dist/cli/components/BlockView.js.map +1 -0
  55. package/dist/cli/components/FirstRunFrame.js +41 -0
  56. package/dist/cli/components/FirstRunFrame.js.map +1 -0
  57. package/dist/cli/components/KeyManager.js +197 -0
  58. package/dist/cli/components/KeyManager.js.map +1 -0
  59. package/dist/cli/components/KeySetup.js +125 -0
  60. package/dist/cli/components/KeySetup.js.map +1 -0
  61. package/dist/cli/components/MenuFrame.js +24 -0
  62. package/dist/cli/components/MenuFrame.js.map +1 -0
  63. package/dist/cli/components/Picker.js +82 -0
  64. package/dist/cli/components/Picker.js.map +1 -0
  65. package/dist/cli/components/PromptInput.js +509 -0
  66. package/dist/cli/components/PromptInput.js.map +1 -0
  67. package/dist/cli/components/SubagentView.js +86 -0
  68. package/dist/cli/components/SubagentView.js.map +1 -0
  69. package/dist/cli/components/ToolGroup.js +60 -0
  70. package/dist/cli/components/ToolGroup.js.map +1 -0
  71. package/dist/cli/components/ToolLine.js +123 -0
  72. package/dist/cli/components/ToolLine.js.map +1 -0
  73. package/dist/cli/components/TrustGate.js +37 -0
  74. package/dist/cli/components/TrustGate.js.map +1 -0
  75. package/dist/cli/costView.js +40 -0
  76. package/dist/cli/costView.js.map +1 -0
  77. package/dist/cli/frameRate.js +30 -0
  78. package/dist/cli/frameRate.js.map +1 -0
  79. package/dist/cli/framebuffer/paint.js +165 -0
  80. package/dist/cli/framebuffer/paint.js.map +1 -0
  81. package/dist/cli/framebuffer/parse.js +266 -0
  82. package/dist/cli/framebuffer/parse.js.map +1 -0
  83. package/dist/cli/framebuffer/screen.js +196 -0
  84. package/dist/cli/framebuffer/screen.js.map +1 -0
  85. package/dist/cli/framebuffer/writer.js +139 -0
  86. package/dist/cli/framebuffer/writer.js.map +1 -0
  87. package/dist/cli/groupReveal.js +51 -0
  88. package/dist/cli/groupReveal.js.map +1 -0
  89. package/dist/cli/help.js +55 -0
  90. package/dist/cli/help.js.map +1 -0
  91. package/dist/cli/inputView.js +105 -0
  92. package/dist/cli/inputView.js.map +1 -0
  93. package/dist/cli/keyManager.js +65 -0
  94. package/dist/cli/keyManager.js.map +1 -0
  95. package/dist/cli/keySetup.js +35 -0
  96. package/dist/cli/keySetup.js.map +1 -0
  97. package/dist/cli/keyStore.js +73 -0
  98. package/dist/cli/keyStore.js.map +1 -0
  99. package/dist/cli/markdown.js +460 -0
  100. package/dist/cli/markdown.js.map +1 -0
  101. package/dist/cli/messageQueue.js +96 -0
  102. package/dist/cli/messageQueue.js.map +1 -0
  103. package/dist/cli/modes.js +90 -0
  104. package/dist/cli/modes.js.map +1 -0
  105. package/dist/cli/mouse.js +78 -0
  106. package/dist/cli/mouse.js.map +1 -0
  107. package/dist/cli/pasteAssembler.js +44 -0
  108. package/dist/cli/pasteAssembler.js.map +1 -0
  109. package/dist/cli/pathComplete.js +39 -0
  110. package/dist/cli/pathComplete.js.map +1 -0
  111. package/dist/cli/perfLog.js +90 -0
  112. package/dist/cli/perfLog.js.map +1 -0
  113. package/dist/cli/reveal.js +32 -0
  114. package/dist/cli/reveal.js.map +1 -0
  115. package/dist/cli/revealPace.js +59 -0
  116. package/dist/cli/revealPace.js.map +1 -0
  117. package/dist/cli/sessionCarry.js +19 -0
  118. package/dist/cli/sessionCarry.js.map +1 -0
  119. package/dist/cli/smoothScroll.js +74 -0
  120. package/dist/cli/smoothScroll.js.map +1 -0
  121. package/dist/cli/startupArgs.js +96 -0
  122. package/dist/cli/startupArgs.js.map +1 -0
  123. package/dist/cli/terminalRestore.js +34 -0
  124. package/dist/cli/terminalRestore.js.map +1 -0
  125. package/dist/cli/toolDisplay.js +219 -0
  126. package/dist/cli/toolDisplay.js.map +1 -0
  127. package/dist/cli/toolItems.js +65 -0
  128. package/dist/cli/toolItems.js.map +1 -0
  129. package/dist/cli/transcript.js +351 -0
  130. package/dist/cli/transcript.js.map +1 -0
  131. package/dist/cli/trust.js +79 -0
  132. package/dist/cli/trust.js.map +1 -0
  133. package/dist/cli/updateCheck.js +107 -0
  134. package/dist/cli/updateCheck.js.map +1 -0
  135. package/dist/cli/version.js +39 -0
  136. package/dist/cli/version.js.map +1 -0
  137. package/dist/cli/viewport.js +179 -0
  138. package/dist/cli/viewport.js.map +1 -0
  139. package/dist/cli/virtualWindow.js +103 -0
  140. package/dist/cli/virtualWindow.js.map +1 -0
  141. package/dist/cli/workingVerb.js +37 -0
  142. package/dist/cli/workingVerb.js.map +1 -0
  143. package/dist/cli/wrap.js +145 -0
  144. package/dist/cli/wrap.js.map +1 -0
  145. package/dist/drivers/anthropic/cachePoints.js +77 -0
  146. package/dist/drivers/anthropic/cachePoints.js.map +1 -0
  147. package/dist/drivers/anthropic/client.js +432 -0
  148. package/dist/drivers/anthropic/client.js.map +1 -0
  149. package/dist/drivers/anthropic/index.js +10 -0
  150. package/dist/drivers/anthropic/index.js.map +1 -0
  151. package/dist/drivers/anthropic/manifest.js +221 -0
  152. package/dist/drivers/anthropic/manifest.js.map +1 -0
  153. package/dist/drivers/cerebras/client.js +69 -0
  154. package/dist/drivers/cerebras/client.js.map +1 -0
  155. package/dist/drivers/cerebras/index.js +5 -0
  156. package/dist/drivers/cerebras/index.js.map +1 -0
  157. package/dist/drivers/cerebras/manifest.js +140 -0
  158. package/dist/drivers/cerebras/manifest.js.map +1 -0
  159. package/dist/drivers/clientId.js +41 -0
  160. package/dist/drivers/clientId.js.map +1 -0
  161. package/dist/drivers/contextOverflow.js +77 -0
  162. package/dist/drivers/contextOverflow.js.map +1 -0
  163. package/dist/drivers/deepseek/client.js +168 -0
  164. package/dist/drivers/deepseek/client.js.map +1 -0
  165. package/dist/drivers/deepseek/index.js +16 -0
  166. package/dist/drivers/deepseek/index.js.map +1 -0
  167. package/dist/drivers/deepseek/inlineTools.js +46 -0
  168. package/dist/drivers/deepseek/inlineTools.js.map +1 -0
  169. package/dist/drivers/deepseek/manifest.js +166 -0
  170. package/dist/drivers/deepseek/manifest.js.map +1 -0
  171. package/dist/drivers/gemini/client.js +38 -0
  172. package/dist/drivers/gemini/client.js.map +1 -0
  173. package/dist/drivers/gemini/index.js +5 -0
  174. package/dist/drivers/gemini/index.js.map +1 -0
  175. package/dist/drivers/gemini/manifest.js +150 -0
  176. package/dist/drivers/gemini/manifest.js.map +1 -0
  177. package/dist/drivers/glm/client.js +90 -0
  178. package/dist/drivers/glm/client.js.map +1 -0
  179. package/dist/drivers/glm/index.js +9 -0
  180. package/dist/drivers/glm/index.js.map +1 -0
  181. package/dist/drivers/glm/manifest.js +183 -0
  182. package/dist/drivers/glm/manifest.js.map +1 -0
  183. package/dist/drivers/groq/client.js +80 -0
  184. package/dist/drivers/groq/client.js.map +1 -0
  185. package/dist/drivers/groq/index.js +5 -0
  186. package/dist/drivers/groq/index.js.map +1 -0
  187. package/dist/drivers/groq/manifest.js +160 -0
  188. package/dist/drivers/groq/manifest.js.map +1 -0
  189. package/dist/drivers/kimi/client.js +82 -0
  190. package/dist/drivers/kimi/client.js.map +1 -0
  191. package/dist/drivers/kimi/index.js +9 -0
  192. package/dist/drivers/kimi/index.js.map +1 -0
  193. package/dist/drivers/kimi/manifest.js +168 -0
  194. package/dist/drivers/kimi/manifest.js.map +1 -0
  195. package/dist/drivers/meta/client.js +30 -0
  196. package/dist/drivers/meta/client.js.map +1 -0
  197. package/dist/drivers/meta/index.js +5 -0
  198. package/dist/drivers/meta/index.js.map +1 -0
  199. package/dist/drivers/meta/manifest.js +101 -0
  200. package/dist/drivers/meta/manifest.js.map +1 -0
  201. package/dist/drivers/minimax/client.js +36 -0
  202. package/dist/drivers/minimax/client.js.map +1 -0
  203. package/dist/drivers/minimax/index.js +5 -0
  204. package/dist/drivers/minimax/index.js.map +1 -0
  205. package/dist/drivers/minimax/manifest.js +120 -0
  206. package/dist/drivers/minimax/manifest.js.map +1 -0
  207. package/dist/drivers/mistral/client.js +54 -0
  208. package/dist/drivers/mistral/client.js.map +1 -0
  209. package/dist/drivers/mistral/index.js +5 -0
  210. package/dist/drivers/mistral/index.js.map +1 -0
  211. package/dist/drivers/mistral/manifest.js +118 -0
  212. package/dist/drivers/mistral/manifest.js.map +1 -0
  213. package/dist/drivers/openai/client.js +290 -0
  214. package/dist/drivers/openai/client.js.map +1 -0
  215. package/dist/drivers/openai/index.js +9 -0
  216. package/dist/drivers/openai/index.js.map +1 -0
  217. package/dist/drivers/openai/manifest.js +133 -0
  218. package/dist/drivers/openai/manifest.js.map +1 -0
  219. package/dist/drivers/openaiCompat/wire.js +493 -0
  220. package/dist/drivers/openaiCompat/wire.js.map +1 -0
  221. package/dist/drivers/partialTurn.js +23 -0
  222. package/dist/drivers/partialTurn.js.map +1 -0
  223. package/dist/drivers/providerError.js +181 -0
  224. package/dist/drivers/providerError.js.map +1 -0
  225. package/dist/drivers/qwen/client.js +93 -0
  226. package/dist/drivers/qwen/client.js.map +1 -0
  227. package/dist/drivers/qwen/index.js +9 -0
  228. package/dist/drivers/qwen/index.js.map +1 -0
  229. package/dist/drivers/qwen/manifest.js +146 -0
  230. package/dist/drivers/qwen/manifest.js.map +1 -0
  231. package/dist/drivers/registry.js +177 -0
  232. package/dist/drivers/registry.js.map +1 -0
  233. package/dist/drivers/retryPolicy.js +129 -0
  234. package/dist/drivers/retryPolicy.js.map +1 -0
  235. package/dist/drivers/searchBlocks.js +61 -0
  236. package/dist/drivers/searchBlocks.js.map +1 -0
  237. package/dist/drivers/types.js +2 -0
  238. package/dist/drivers/types.js.map +1 -0
  239. package/dist/drivers/xai/client.js +63 -0
  240. package/dist/drivers/xai/client.js.map +1 -0
  241. package/dist/drivers/xai/index.js +5 -0
  242. package/dist/drivers/xai/index.js.map +1 -0
  243. package/dist/drivers/xai/manifest.js +137 -0
  244. package/dist/drivers/xai/manifest.js.map +1 -0
  245. package/dist/dynamo/_probe.tmp.js +20 -0
  246. package/dist/dynamo/_probe.tmp.js.map +1 -0
  247. package/dist/dynamo/cacheBreak.js +88 -0
  248. package/dist/dynamo/cacheBreak.js.map +1 -0
  249. package/dist/dynamo/contextWindow.js +243 -0
  250. package/dist/dynamo/contextWindow.js.map +1 -0
  251. package/dist/dynamo/engine.js +2011 -0
  252. package/dist/dynamo/engine.js.map +1 -0
  253. package/dist/dynamo/guard.js +132 -0
  254. package/dist/dynamo/guard.js.map +1 -0
  255. package/dist/dynamo/liveMeter.js +58 -0
  256. package/dist/dynamo/liveMeter.js.map +1 -0
  257. package/dist/dynamo/model.js +172 -0
  258. package/dist/dynamo/model.js.map +1 -0
  259. package/dist/dynamo/planArtifact.js +125 -0
  260. package/dist/dynamo/planArtifact.js.map +1 -0
  261. package/dist/dynamo/pricing.js +140 -0
  262. package/dist/dynamo/pricing.js.map +1 -0
  263. package/dist/dynamo/prompt.js +264 -0
  264. package/dist/dynamo/prompt.js.map +1 -0
  265. package/dist/dynamo/spend.js +45 -0
  266. package/dist/dynamo/spend.js.map +1 -0
  267. package/dist/dynamo/verify.js +483 -0
  268. package/dist/dynamo/verify.js.map +1 -0
  269. package/dist/governor/forbidden.js +181 -0
  270. package/dist/governor/forbidden.js.map +1 -0
  271. package/dist/governor/freshness.js +83 -0
  272. package/dist/governor/freshness.js.map +1 -0
  273. package/dist/governor/frontmatter.js +38 -0
  274. package/dist/governor/frontmatter.js.map +1 -0
  275. package/dist/governor/glob.js +75 -0
  276. package/dist/governor/glob.js.map +1 -0
  277. package/dist/governor/index.js +87 -0
  278. package/dist/governor/index.js.map +1 -0
  279. package/dist/governor/rules.js +80 -0
  280. package/dist/governor/rules.js.map +1 -0
  281. package/dist/governor/scope.js +91 -0
  282. package/dist/governor/scope.js.map +1 -0
  283. package/dist/governor/skills.js +176 -0
  284. package/dist/governor/skills.js.map +1 -0
  285. package/dist/governor/types.js +16 -0
  286. package/dist/governor/types.js.map +1 -0
  287. package/dist/governor/write.js +182 -0
  288. package/dist/governor/write.js.map +1 -0
  289. package/dist/index.js +89 -0
  290. package/dist/index.js.map +1 -0
  291. package/dist/mcp/catalog.js +232 -0
  292. package/dist/mcp/catalog.js.map +1 -0
  293. package/dist/mcp/config.js +116 -0
  294. package/dist/mcp/config.js.map +1 -0
  295. package/dist/mcp/configWrite.js +254 -0
  296. package/dist/mcp/configWrite.js.map +1 -0
  297. package/dist/mcp/connection.js +504 -0
  298. package/dist/mcp/connection.js.map +1 -0
  299. package/dist/mcp/deferred.js +104 -0
  300. package/dist/mcp/deferred.js.map +1 -0
  301. package/dist/mcp/discover.js +128 -0
  302. package/dist/mcp/discover.js.map +1 -0
  303. package/dist/mcp/manager.js +679 -0
  304. package/dist/mcp/manager.js.map +1 -0
  305. package/dist/mcp/paramHeaders.js +163 -0
  306. package/dist/mcp/paramHeaders.js.map +1 -0
  307. package/dist/mcp/prompts.js +136 -0
  308. package/dist/mcp/prompts.js.map +1 -0
  309. package/dist/mcp/protocol.js +171 -0
  310. package/dist/mcp/protocol.js.map +1 -0
  311. package/dist/mcp/resources.js +119 -0
  312. package/dist/mcp/resources.js.map +1 -0
  313. package/dist/mcp/resultStore.js +180 -0
  314. package/dist/mcp/resultStore.js.map +1 -0
  315. package/dist/mcp/subscriptions.js +74 -0
  316. package/dist/mcp/subscriptions.js.map +1 -0
  317. package/dist/mcp/transport/headerValue.js +40 -0
  318. package/dist/mcp/transport/headerValue.js.map +1 -0
  319. package/dist/mcp/transport/http.js +321 -0
  320. package/dist/mcp/transport/http.js.map +1 -0
  321. package/dist/mcp/transport/stdio.js +234 -0
  322. package/dist/mcp/transport/stdio.js.map +1 -0
  323. package/dist/mcp/transport/types.js +27 -0
  324. package/dist/mcp/transport/types.js.map +1 -0
  325. package/dist/mcp/trust.js +98 -0
  326. package/dist/mcp/trust.js.map +1 -0
  327. package/dist/mcp/trustStore.js +55 -0
  328. package/dist/mcp/trustStore.js.map +1 -0
  329. package/dist/memory/autoMemory.js +340 -0
  330. package/dist/memory/autoMemory.js.map +1 -0
  331. package/dist/memory/compaction.js +513 -0
  332. package/dist/memory/compaction.js.map +1 -0
  333. package/dist/memory/images.js +173 -0
  334. package/dist/memory/images.js.map +1 -0
  335. package/dist/memory/presence.js +59 -0
  336. package/dist/memory/presence.js.map +1 -0
  337. package/dist/memory/projectNotes.js +247 -0
  338. package/dist/memory/projectNotes.js.map +1 -0
  339. package/dist/memory/restore.js +72 -0
  340. package/dist/memory/restore.js.map +1 -0
  341. package/dist/memory/session.js +472 -0
  342. package/dist/memory/session.js.map +1 -0
  343. package/dist/memory/sessionMemory.js +142 -0
  344. package/dist/memory/sessionMemory.js.map +1 -0
  345. package/dist/memory/sessionMemoryCompact.js +136 -0
  346. package/dist/memory/sessionMemoryCompact.js.map +1 -0
  347. package/dist/memory/store.js +217 -0
  348. package/dist/memory/store.js.map +1 -0
  349. package/dist/memory/types.js +14 -0
  350. package/dist/memory/types.js.map +1 -0
  351. package/dist/memory/workingSet.js +383 -0
  352. package/dist/memory/workingSet.js.map +1 -0
  353. package/dist/project/context.js +425 -0
  354. package/dist/project/context.js.map +1 -0
  355. package/dist/tools/approval.js +189 -0
  356. package/dist/tools/approval.js.map +1 -0
  357. package/dist/tools/askUser.js +103 -0
  358. package/dist/tools/askUser.js.map +1 -0
  359. package/dist/tools/atomicWrite.js +151 -0
  360. package/dist/tools/atomicWrite.js.map +1 -0
  361. package/dist/tools/backgroundShells.js +468 -0
  362. package/dist/tools/backgroundShells.js.map +1 -0
  363. package/dist/tools/captureSweep.js +77 -0
  364. package/dist/tools/captureSweep.js.map +1 -0
  365. package/dist/tools/chassisMux.js +92 -0
  366. package/dist/tools/chassisMux.js.map +1 -0
  367. package/dist/tools/checkpoints.js +328 -0
  368. package/dist/tools/checkpoints.js.map +1 -0
  369. package/dist/tools/codeIntel.js +267 -0
  370. package/dist/tools/codeIntel.js.map +1 -0
  371. package/dist/tools/deferredNative.js +121 -0
  372. package/dist/tools/deferredNative.js.map +1 -0
  373. package/dist/tools/detail.js +135 -0
  374. package/dist/tools/detail.js.map +1 -0
  375. package/dist/tools/diagnostics.js +174 -0
  376. package/dist/tools/diagnostics.js.map +1 -0
  377. package/dist/tools/edit.js +167 -0
  378. package/dist/tools/edit.js.map +1 -0
  379. package/dist/tools/editCore.js +283 -0
  380. package/dist/tools/editCore.js.map +1 -0
  381. package/dist/tools/editFile.js +183 -0
  382. package/dist/tools/editFile.js.map +1 -0
  383. package/dist/tools/editRipple.js +126 -0
  384. package/dist/tools/editRipple.js.map +1 -0
  385. package/dist/tools/editTarget.js +131 -0
  386. package/dist/tools/editTarget.js.map +1 -0
  387. package/dist/tools/editWindow.js +49 -0
  388. package/dist/tools/editWindow.js.map +1 -0
  389. package/dist/tools/eol.js +56 -0
  390. package/dist/tools/eol.js.map +1 -0
  391. package/dist/tools/exitPlan.js +175 -0
  392. package/dist/tools/exitPlan.js.map +1 -0
  393. package/dist/tools/focus.js +42 -0
  394. package/dist/tools/focus.js.map +1 -0
  395. package/dist/tools/gitignore.js +148 -0
  396. package/dist/tools/gitignore.js.map +1 -0
  397. package/dist/tools/glob.js +134 -0
  398. package/dist/tools/glob.js.map +1 -0
  399. package/dist/tools/governorTools.js +258 -0
  400. package/dist/tools/governorTools.js.map +1 -0
  401. package/dist/tools/grep.js +450 -0
  402. package/dist/tools/grep.js.map +1 -0
  403. package/dist/tools/guard.js +220 -0
  404. package/dist/tools/guard.js.map +1 -0
  405. package/dist/tools/killTree.js +215 -0
  406. package/dist/tools/killTree.js.map +1 -0
  407. package/dist/tools/listDir.js +143 -0
  408. package/dist/tools/listDir.js.map +1 -0
  409. package/dist/tools/mcpAdd.js +176 -0
  410. package/dist/tools/mcpAdd.js.map +1 -0
  411. package/dist/tools/mcpResources.js +116 -0
  412. package/dist/tools/mcpResources.js.map +1 -0
  413. package/dist/tools/mcpSearch.js +123 -0
  414. package/dist/tools/mcpSearch.js.map +1 -0
  415. package/dist/tools/multiEdit.js +168 -0
  416. package/dist/tools/multiEdit.js.map +1 -0
  417. package/dist/tools/paths.js +225 -0
  418. package/dist/tools/paths.js.map +1 -0
  419. package/dist/tools/posixShell.js +123 -0
  420. package/dist/tools/posixShell.js.map +1 -0
  421. package/dist/tools/readFile.js +371 -0
  422. package/dist/tools/readFile.js.map +1 -0
  423. package/dist/tools/readSymbol.js +145 -0
  424. package/dist/tools/readSymbol.js.map +1 -0
  425. package/dist/tools/registry.js +120 -0
  426. package/dist/tools/registry.js.map +1 -0
  427. package/dist/tools/replaceSymbol.js +141 -0
  428. package/dist/tools/replaceSymbol.js.map +1 -0
  429. package/dist/tools/results.js +15 -0
  430. package/dist/tools/results.js.map +1 -0
  431. package/dist/tools/ripgrep.js +145 -0
  432. package/dist/tools/ripgrep.js.map +1 -0
  433. package/dist/tools/runCommand.js +633 -0
  434. package/dist/tools/runCommand.js.map +1 -0
  435. package/dist/tools/saveMemory.js +102 -0
  436. package/dist/tools/saveMemory.js.map +1 -0
  437. package/dist/tools/screenshot.js +200 -0
  438. package/dist/tools/screenshot.js.map +1 -0
  439. package/dist/tools/screenshotWin.js +227 -0
  440. package/dist/tools/screenshotWin.js.map +1 -0
  441. package/dist/tools/search.js +121 -0
  442. package/dist/tools/search.js.map +1 -0
  443. package/dist/tools/sessionTools.js +187 -0
  444. package/dist/tools/sessionTools.js.map +1 -0
  445. package/dist/tools/shellCheckpoint.js +123 -0
  446. package/dist/tools/shellCheckpoint.js.map +1 -0
  447. package/dist/tools/shellLint.js +102 -0
  448. package/dist/tools/shellLint.js.map +1 -0
  449. package/dist/tools/shellTools.js +203 -0
  450. package/dist/tools/shellTools.js.map +1 -0
  451. package/dist/tools/spanCore.js +78 -0
  452. package/dist/tools/spanCore.js.map +1 -0
  453. package/dist/tools/subagent.js +224 -0
  454. package/dist/tools/subagent.js.map +1 -0
  455. package/dist/tools/subagentReport.js +114 -0
  456. package/dist/tools/subagentReport.js.map +1 -0
  457. package/dist/tools/tempSweep.js +118 -0
  458. package/dist/tools/tempSweep.js.map +1 -0
  459. package/dist/tools/todo.js +117 -0
  460. package/dist/tools/todo.js.map +1 -0
  461. package/dist/tools/types.js +2 -0
  462. package/dist/tools/types.js.map +1 -0
  463. package/dist/tools/untrusted.js +46 -0
  464. package/dist/tools/untrusted.js.map +1 -0
  465. package/dist/tools/useSkill.js +62 -0
  466. package/dist/tools/useSkill.js.map +1 -0
  467. package/dist/tools/walk.js +152 -0
  468. package/dist/tools/walk.js.map +1 -0
  469. package/dist/tools/web.js +61 -0
  470. package/dist/tools/web.js.map +1 -0
  471. package/dist/tools/webFetch.js +444 -0
  472. package/dist/tools/webFetch.js.map +1 -0
  473. package/dist/tools/webSearch.js +130 -0
  474. package/dist/tools/webSearch.js.map +1 -0
  475. package/dist/tools/workspace.js +212 -0
  476. package/dist/tools/workspace.js.map +1 -0
  477. package/dist/tools/workspaceDiscover.js +216 -0
  478. package/dist/tools/workspaceDiscover.js.map +1 -0
  479. package/dist/tools/writeFile.js +162 -0
  480. package/dist/tools/writeFile.js.map +1 -0
  481. package/package.json +74 -28
@@ -0,0 +1,513 @@
1
+ /**
2
+ * compaction.ts — keeping the model sharp as a session grows (pure half).
3
+ *
4
+ * A long transcript hurts two ways: the live task gets buried under stale tool
5
+ * output (a coding model "loses its moment" well before any hard context limit —
6
+ * multi-needle retrieval, which is what recalling a long session actually is,
7
+ * sags long before the storage cap), and on BYOK every wasted token is the
8
+ * user's money. The per-model sharp windows live in the drivers.
9
+ * The cascade, cheapest first:
10
+ *
11
+ * 1. MICROCOMPACT (no model call, lossless): once the transcript passes a low
12
+ * bar, clear the BODIES of old tool results — keep the last N verbatim — so
13
+ * the recent working set stays dense. The model can always re-read; a
14
+ * cleared result leaves a stub saying so. Fires early and often.
15
+ * 2. AUTOCOMPACT (one model call): the backstop. When microcompact can't keep
16
+ * the transcript under the higher bar, replace the old prefix with a
17
+ * 9-section structured summary and keep the last N turns verbatim. The
18
+ * engine pairs this with re-reading the working-set files (restoration) so
19
+ * nothing the model was mid-edit on is lost.
20
+ *
21
+ * This module is PURE — estimation, the microcompact transform, the summary
22
+ * prompt, and the splice. It does no I/O and makes no model calls (the engine
23
+ * owns "when" and the summarizer call), so it stays trivially testable and could
24
+ * run on either side of the future client/server line.
25
+ */
26
+ import { basename } from "node:path";
27
+ import { fullPathsOf } from "./types.js";
28
+ import { estimateImagesTokens } from "./images.js";
29
+ // ~3.5 chars/token, deliberately tokenizer-free: triggers need a cheap, stable,
30
+ // slightly-conservative proxy, not an exact count (better to compact a touch
31
+ // early than to overflow).
32
+ const CHARS_PER_TOKEN = 3.5;
33
+ // The BARS themselves live in `dynamo/contextWindow.ts` and are derived from the
34
+ // driver's sharp window, so they move with the model instead of being frozen here.
35
+ // This module used to also export fixed MICROCOMPACT_TOKENS / AUTOCOMPACT_TOKENS
36
+ // constants; nothing read them once the engine went model-anchored, and their
37
+ // doc comment went on asserting 45K/90K while the live bars were 38K/95K. Deleted
38
+ // rather than corrected: a second source of truth for the same number is the
39
+ // stale-claim trap in BOUNDARY.md. The env overrides
40
+ // (MINDWEAVE_MICROCOMPACT_TOKENS / MINDWEAVE_AUTOCOMPACT_TOKENS) are unaffected —
41
+ // the engine reads them directly at the point of use.
42
+ /** Tool observations kept verbatim; older ones get their body cleared. Kept deliberately
43
+ * tight — a weaker model regresses on stale tool noise sooner, so we keep less. */
44
+ export const KEEP_LAST_N = 8;
45
+ /** At a TASK BOUNDARY (a finished task, a new request) we sweep hard: keep only this
46
+ * many recent observations, since the finished task's detail is no longer load-bearing. */
47
+ export const KEEP_LAST_N_BOUNDARY = 2;
48
+ export const CLEARED_STUB = "[old tool result cleared to save context — re-read the file/search if you need it again]";
49
+ /** Old assistant prose (a "here's what I built" recap) is what a weaker model latches
50
+ * onto and regresses to. Beyond the recent window we condense these to a stub so a
51
+ * finished task can't resurface. Only pure-text replies (no tool calls) and only
52
+ * genuine recaps (long enough) are touched — short acknowledgements stay. */
53
+ const RECAP_STUB = "[earlier status update condensed — this work is done; focus on the current task]";
54
+ const RECAP_MIN_CHARS = 220;
55
+ /** Left behind when an attached image's payload is evicted. Names the file, so asking
56
+ * for it again is an ordinary request rather than a lost capability. */
57
+ export const IMAGE_CLEARED_STUB = "was attached here but is no longer in context — ask me to re-attach it if you need to look again";
58
+ /** Edit/write tools whose call INPUT carries bulky content (a whole file, a diff, a
59
+ * symbol body). Once such an edit is old and its result already cleared, the content
60
+ * it wrote is dead weight — the live file is in the working set or a re-read away — so
61
+ * we clear the input too. Done here on the transcript, this is provider-AGNOSTIC —
62
+ * every model, not just DeepSeek, gets the saving, and it stays correct even once a
63
+ * provider offers an equivalent feature natively. */
64
+ const CONTENT_CARRYING_TOOLS = new Set(["edit", "write_file", "replace_symbol_body"]);
65
+ const CLEARED_INPUT_NOTE = "content cleared to save context — the file's current state is in the working set, or re-read it";
66
+ /** Shrink a mutation tool-call's arguments to just its identifying fields (which file
67
+ * or symbol), dropping the bulky payload. Returns null when there's nothing to do —
68
+ * malformed JSON, or already cleared (idempotent). Keeps valid JSON so the call stays
69
+ * well-formed on the wire for every provider. */
70
+ function clearMutationArgs(raw) {
71
+ let obj;
72
+ try {
73
+ obj = JSON.parse(raw);
74
+ }
75
+ catch {
76
+ return null;
77
+ }
78
+ if (!obj || typeof obj !== "object" || obj._cleared)
79
+ return null;
80
+ const kept = {};
81
+ for (const key of ["path", "symbol", "name"]) {
82
+ if (typeof obj[key] === "string")
83
+ kept[key] = obj[key];
84
+ }
85
+ kept._cleared = CLEARED_INPUT_NOTE;
86
+ return JSON.stringify(kept);
87
+ }
88
+ /** Cheap token estimate for a string. */
89
+ export function estimateTokens(text) {
90
+ return estimateTokensForChars(text.length);
91
+ }
92
+ /**
93
+ * The same estimate, from a character COUNT rather than the characters themselves —
94
+ * for callers that are counting a stream as it arrives and never hold the whole string
95
+ * (the live token meter). Same arithmetic, so the two agree by construction.
96
+ */
97
+ export function estimateTokensForChars(chars) {
98
+ return chars > 0 ? Math.ceil(chars / CHARS_PER_TOKEN) + 1 : 0;
99
+ }
100
+ /**
101
+ * Estimated token footprint of a transcript (content + tool-call arguments + attached
102
+ * images + small overhead).
103
+ *
104
+ * Images are counted by AREA, not by the length of their path. A screenshot is a few
105
+ * dozen characters of text and a few thousand tokens of context, so leaving it out
106
+ * would make every compaction bar fire late by exactly the amount that matters most.
107
+ */
108
+ export function estimateEntriesTokens(entries) {
109
+ let total = 0;
110
+ for (const e of entries) {
111
+ total += estimateTokens(e.content) + 4;
112
+ if (e.role === "user" && e.images)
113
+ total += estimateImagesTokens(e.images);
114
+ if (e.role === "assistant" && e.toolCalls) {
115
+ for (const tc of e.toolCalls)
116
+ total += estimateTokens(tc.arguments) + estimateTokens(tc.name);
117
+ }
118
+ }
119
+ return total;
120
+ }
121
+ /**
122
+ * Layer 1: clear the bodies of OLD tool results, keeping the last `keepLastN`
123
+ * intact. Pure — returns a new transcript and how many were cleared.
124
+ *
125
+ * WHAT GOES FIRST, AND WHY. The order below is not taste; it falls out of one rule:
126
+ * evict by RECONSTRUCTIBILITY — the more cheaply an authoritative record elsewhere can
127
+ * regenerate a thing, the sooner it goes, and whatever is left behind must carry the
128
+ * key needed to get it back. So: the inputs of old edit/write calls go first and go to
129
+ * nothing, because the filesystem is the record and the sent body is already dead
130
+ * weight. Then the bodies of old tool results, whose source of truth is external (a
131
+ * file, a command, a search) — to a STUB that keeps the first line, and that first line
132
+ * is the restoration key: it is what makes re-acquisition an ordinary tool call instead
133
+ * of a special mechanism. Then old assistant recaps, reconstructible from the summary
134
+ * layer. The conversation itself is never touched at this layer, because no record
135
+ * anywhere can regenerate intent — summarization is its only admissible compression.
136
+ * And results the model has not acted on yet are never touched at any bar: unacted
137
+ * knowledge is full fidelity or the model is working blind.
138
+ *
139
+ * What it must never touch: user/assistant messages (the actual conversation),
140
+ * the last N tool results (the live working set), and any tool result that
141
+ * hasn't been superseded by a newer assistant tool-call round (the model has not
142
+ * even seen those yet). An already-cleared stub is left alone (idempotent).
143
+ */
144
+ export function microcompact(entries, keepLastN = KEEP_LAST_N, supersededPaths = new Set()) {
145
+ const toolIdx = entries.flatMap((e, i) => (e.role === "tool" ? [i] : []));
146
+ let clearable = new Set(keepLastN > 0 ? toolIdx.slice(0, -keepLastN) : toolIdx);
147
+ // Never clear the most recent tool round — the results after the last
148
+ // assistant tool-call are fresh reads the model hasn't acted on yet.
149
+ let lastRoundStart = -1;
150
+ for (let i = 0; i < entries.length; i++) {
151
+ const e = entries[i];
152
+ if (e.role === "assistant" && e.toolCalls && e.toolCalls.length > 0)
153
+ lastRoundStart = i;
154
+ }
155
+ if (lastRoundStart >= 0) {
156
+ clearable = new Set([...clearable].filter((i) => i < lastRoundStart));
157
+ }
158
+ // A file the WORKING SET carries in full is represented twice: once here in the
159
+ // transcript, and once again in the <working_files> block that is rebuilt at the
160
+ // boundary every step. Those copies are not equivalent — the working-set one is
161
+ // current by construction, and the transcript one is a snapshot of whatever the file
162
+ // said when it was read — so the transcript copy is the redundant one, and clearing
163
+ // it costs the model nothing it cannot already see, fresher.
164
+ //
165
+ // This deliberately overrides BOTH protections above. keepLastN and the live-round
166
+ // rule exist so the model is never left blind on something it has not acted on; a
167
+ // file rendered whole at the boundary is the one case where neither concern applies.
168
+ //
169
+ // It also deliberately happens HERE rather than eagerly each turn. Clearing an entry
170
+ // rewrites the transcript, and the transcript is the CACHED half of the request: doing
171
+ // it on an ordinary turn would trade a cheap cached-read for a full prefix rewrite at
172
+ // 1.25x, which is a straight loss. Microcompaction is already discarding that cache,
173
+ // so riding along with it is the version that is actually free.
174
+ if (supersededPaths.size > 0) {
175
+ for (let i = 0; i < entries.length; i++) {
176
+ const e = entries[i];
177
+ // EVERY file the entry carries must be superseded before its body can go. One
178
+ // read of four files is one entry; clearing it because one of the four was
179
+ // re-read would drop the other three out from under the model.
180
+ const carried = e ? fullPathsOf(e) : [];
181
+ if (carried.length > 0 && carried.every((path) => supersededPaths.has(path))) {
182
+ clearable.add(i);
183
+ }
184
+ }
185
+ }
186
+ // Which edit/write tool-call INPUTS to clear: map each clearable RESULT back to the
187
+ // call that produced it; if that call was a content-carrying edit/write, its input is
188
+ // dead weight now too. Keyed off the SAME clearable window, so recent edits stay whole.
189
+ const callNameById = new Map();
190
+ for (const e of entries) {
191
+ if (e.role === "assistant" && e.toolCalls)
192
+ for (const tc of e.toolCalls)
193
+ callNameById.set(tc.id, tc.name);
194
+ }
195
+ const clearInputIds = new Set();
196
+ for (const i of clearable) {
197
+ const e = entries[i];
198
+ if (e && e.role === "tool") {
199
+ const name = callNameById.get(e.toolCallId);
200
+ if (name && CONTENT_CARRYING_TOOLS.has(name))
201
+ clearInputIds.add(e.toolCallId);
202
+ }
203
+ }
204
+ // Old assistant recaps are condensed beyond the recent window — this is what stops a
205
+ // finished task from resurfacing. Recent replies (last keepLastN entries) are kept.
206
+ const recapBoundary = Math.max(0, entries.length - keepLastN);
207
+ // Images additionally respect the live tool round, exactly as tool-result bodies do:
208
+ // whatever the model has not acted on yet is full fidelity or it is working blind,
209
+ // and that rule cannot hold for text and not for pictures.
210
+ const imageBoundary = lastRoundStart >= 0 ? Math.min(recapBoundary, lastRoundStart) : recapBoundary;
211
+ let cleared = 0;
212
+ let recapsCleared = 0;
213
+ let inputsCleared = 0;
214
+ let imagesCleared = 0;
215
+ const clearedIds = [];
216
+ const out = entries.map((e, i) => {
217
+ // 1) Old tool-result bodies → stub (with first line kept for navigation).
218
+ if (clearable.has(i) && e.role === "tool") {
219
+ if (e.content.includes(CLEARED_STUB))
220
+ return e; // already cleared
221
+ cleared++;
222
+ clearedIds.push(e.toolCallId); // so the caller can drop the file from the read ledger
223
+ const firstLine = e.content.split("\n", 1)[0]?.trim() ?? "";
224
+ const stub = firstLine && firstLine.length < 120 ? `${firstLine}\n${CLEARED_STUB}` : CLEARED_STUB;
225
+ return { ...e, content: stub };
226
+ }
227
+ // 2) Old standalone assistant recaps → stub (pure text, no tool calls, long enough).
228
+ if (i < recapBoundary &&
229
+ e.role === "assistant" &&
230
+ !(e.toolCalls && e.toolCalls.length > 0) &&
231
+ e.content.length >= RECAP_MIN_CHARS &&
232
+ e.content !== RECAP_STUB) {
233
+ recapsCleared++;
234
+ return { ...e, content: RECAP_STUB };
235
+ }
236
+ // 3) Old edit/write tool-call INPUTS → shrunk to just which file, dropping the
237
+ // content payload. Its paired result is already being cleared above.
238
+ if (e.role === "assistant" && e.toolCalls && e.toolCalls.some((tc) => clearInputIds.has(tc.id))) {
239
+ const toolCalls = e.toolCalls.map((tc) => {
240
+ if (!clearInputIds.has(tc.id))
241
+ return tc;
242
+ const shrunk = clearMutationArgs(tc.arguments);
243
+ if (shrunk == null)
244
+ return tc;
245
+ inputsCleared++;
246
+ return { ...tc, arguments: shrunk };
247
+ });
248
+ return { ...e, toolCalls };
249
+ }
250
+ // 4) Old image attachments → dropped, leaving a line that names the file.
251
+ // An image is the most expensive thing a turn can carry (thousands of tokens
252
+ // for a screenshot, re-sent on EVERY subsequent request) and also the most
253
+ // perfectly reconstructible: the file is still on disk. The note it leaves is
254
+ // the path, which is exactly the restoration key the rule above asks for. The
255
+ // user's own words are untouched — only the payload goes.
256
+ //
257
+ // The window is `imageBoundary`, which is the recap window ALSO held back to
258
+ // the last tool round. That last clause is the point: this used to key off the
259
+ // raw entry index alone, while tool-result bodies key off a window that is
260
+ // additionally capped at `lastRoundStart`, so an image attached during the
261
+ // live round could be evicted while every tool result around it was kept —
262
+ // dropping the picture the model was in the middle of looking at. The comment
263
+ // here claimed the two windows already matched. They did not.
264
+ if (i < imageBoundary && e.role === "user" && e.images && e.images.length > 0) {
265
+ imagesCleared += e.images.length;
266
+ const names = e.images.map((img) => basename(img.path)).join(", ");
267
+ const { images: _dropped, ...rest } = e;
268
+ return { ...rest, content: `${e.content}\n\n[${names} ${IMAGE_CLEARED_STUB}]` };
269
+ }
270
+ return e;
271
+ });
272
+ if (cleared === 0 && recapsCleared === 0 && inputsCleared === 0 && imagesCleared === 0) {
273
+ return { entries: [...entries], cleared: 0, clearedIds: [], recapsCleared: 0, inputsCleared: 0, imagesCleared: 0 };
274
+ }
275
+ return { entries: out, cleared, clearedIds, recapsCleared, inputsCleared, imagesCleared };
276
+ }
277
+ // Trivial continuations that do NOT open a new task — so a "continue"/"yes" after a
278
+ // finished task doesn't trigger a task-boundary sweep (there's no new task to make
279
+ // room for; the model is resuming the same one). Pure.
280
+ const CONTINUATION_RE = /^(continue|keep going|go on|go ahead|proceed|resume|yes|yep|yeah|yup|ok|okay|sure|next|do it|carry on|and\b|also\b)/i;
281
+ /** Whether a new user message is a trivial continuation rather than a new task. */
282
+ export function isContinuation(text) {
283
+ const t = text.trim();
284
+ if (t.length === 0)
285
+ return true;
286
+ // A short affirmation/continuation; a long message is treated as a real new request.
287
+ return t.length <= 40 && CONTINUATION_RE.test(t);
288
+ }
289
+ // The 9-section structured summary. NOT "summarize this" — a forced structure
290
+ // that preserves intent, the code touched and why, errors already fixed, and a
291
+ // verbatim next step, so the loop resumes across the boundary as if nothing
292
+ // happened.
293
+ export const SUMMARY_SYSTEM_PROMPT = "You are compacting a software-engineering conversation so it can continue " +
294
+ "without losing context. Produce a STRUCTURED summary — not a paragraph. Be " +
295
+ "precise and concrete; this summary REPLACES the older transcript, so anything " +
296
+ "you omit is gone.";
297
+ export const SUMMARY_REQUEST = `Summarize the conversation so far into these nine numbered sections, in order:
298
+
299
+ 1. Primary Request & Intent — what the user is ultimately trying to build or solve, in their own framing.
300
+ 2. Key Technical Concepts — frameworks, patterns, files, and decisions that matter.
301
+ 3. Files & Code — every file touched or discussed, with the relevant snippet(s) AND why each matters. Keep code that future edits depend on.
302
+ 4. Errors & Fixes — each error hit and how it was resolved, so it is not repeated.
303
+ 5. Problem Solving — approaches tried, what worked, what was ruled out.
304
+ 6. All User Messages — list every non-tool message the user sent, as close to verbatim as possible.
305
+ 7. Pending Tasks — what still needs doing.
306
+ 8. Current Work — exactly what was happening right before this summary, including the specific file/line/command in flight.
307
+ 9. Next Step — the single most likely next action; quote the relevant user instruction verbatim so intent does not drift.
308
+
309
+ Think first inside <analysis>…</analysis> (which will be discarded), then output the nine sections.`;
310
+ // Prepended to the summary when the compacted transcript resumes, so the model
311
+ // continues seamlessly instead of narrating that a summary happened.
312
+ const RESUME_PREFIX = "[Earlier conversation summarized to save context. Continue as if the break " +
313
+ "never happened — do not acknowledge the summary or recap it.]\n\n";
314
+ /** Render a transcript into plain text for the summarizer's single user turn. */
315
+ export function formatTranscriptForSummary(entries) {
316
+ return entries
317
+ .map((e) => {
318
+ if (e.role === "tool")
319
+ return `=== TOOL RESULT ===\n${e.content}`;
320
+ if (e.role === "assistant") {
321
+ const calls = e.toolCalls?.length
322
+ ? `\n[called: ${e.toolCalls.map((c) => c.name).join(", ")}]`
323
+ : "";
324
+ return `=== ASSISTANT ===\n${e.content}${calls}`;
325
+ }
326
+ return `=== ${e.role.toUpperCase()} ===\n${e.content}`;
327
+ })
328
+ .join("\n\n");
329
+ }
330
+ /**
331
+ * Strip the model's <analysis> scratchpad, keeping only the nine sections.
332
+ *
333
+ * Handles the UNCLOSED case too, which is what a cut-off reply looks like: an opening
334
+ * tag with no closing one means the answer stopped mid-scratchpad, so everything from
335
+ * that tag onward is thinking rather than summary. Without this, a truncated reply
336
+ * strips to nothing and the model's raw reasoning becomes the record of the session.
337
+ */
338
+ export function stripAnalysis(summary) {
339
+ const closed = summary.replace(/<analysis>[\s\S]*?<\/analysis>/g, "");
340
+ const dangling = closed.indexOf("<analysis>");
341
+ return (dangling === -1 ? closed : closed.slice(0, dangling)).trim();
342
+ }
343
+ /**
344
+ * Decide whether a summarizer reply may replace the transcript. Returns the usable
345
+ * summary, or null to reject it. Pure.
346
+ *
347
+ * This is the single most destructive operation in the system: it throws away the
348
+ * conversation and keeps what comes back instead. So the reply is treated as
349
+ * UNTRUSTED, and every way it can be unusable is checked in one place:
350
+ *
351
+ * - `truncated` — the reply hit the output ceiling mid-summary. It looks exactly
352
+ * like a finished one (see StopReason), and accepting it discards the real
353
+ * transcript in favour of half a summary.
354
+ * - all scratchpad — the prompt asks the model to think inside <analysis> first, so
355
+ * a reply that never got past thinking is non-empty before stripping and empty
356
+ * after. Checking emptiness on the RAW text let that through, and the transcript
357
+ * was replaced with a heading and nothing else.
358
+ * - empty or trivial — nothing usable came back.
359
+ *
360
+ * Rejecting is always safe: the caller keeps the full transcript and counts a failure.
361
+ * Compacting late costs tokens; compacting into nothing costs the session.
362
+ */
363
+ const MIN_SUMMARY_CHARS = 40;
364
+ /** Numbered sections the reply must show before it is believed to be a summary. */
365
+ const MIN_SUMMARY_SECTIONS = 2;
366
+ /**
367
+ * How many DISTINCT numbered markers the text carries (pure).
368
+ *
369
+ * Deliberately loose: markers are counted anywhere rather than only at the start of
370
+ * a line, so a summary that arrives on one line still passes. The job is telling a
371
+ * structured answer apart from a sentence of prose, not grading the structure.
372
+ */
373
+ function numberedSections(text) {
374
+ const seen = new Set();
375
+ for (const m of text.matchAll(/(?:^|\s)(\d)[.)]\s/g))
376
+ seen.add(m[1]);
377
+ return seen.size;
378
+ }
379
+ export function usableSummary(content, stop) {
380
+ // Accept only a CLEAN finish. This was a list of bad stop reasons containing
381
+ // exactly one of them, `truncated`, while the type carries four: a refusal, an
382
+ // overflow, and an overloaded provider all returned text that passed every check
383
+ // below and replaced the conversation. Naming the good case instead means a stop
384
+ // reason added by a future driver fails safe rather than passing by omission —
385
+ // absent still means `end`, which is what a provider means by saying nothing.
386
+ if (stop !== undefined && stop !== "end")
387
+ return null;
388
+ const cleaned = stripAnalysis(content);
389
+ if (cleaned.length < MIN_SUMMARY_CHARS)
390
+ return null;
391
+ // A refusal is fluent, well over the length floor, and structurally nothing like
392
+ // the nine numbered sections that were asked for. Length alone could not tell them
393
+ // apart, and the reply is trusted to REPLACE the session.
394
+ if (numberedSections(cleaned) < MIN_SUMMARY_SECTIONS)
395
+ return null;
396
+ return cleaned;
397
+ }
398
+ /**
399
+ * Layer 2 apply: replace the old prefix with the summary, keep the last
400
+ * `keepLastN` entries verbatim. Pure.
401
+ *
402
+ * The kept tail must start on a clean boundary — a `tool` entry is only valid
403
+ * immediately after the assistant `toolCalls` that produced it, so if the cut
404
+ * lands mid-round we drop the orphaned leading tool results (their parent turn
405
+ * is captured in the summary). The discriminated union makes this check exhaustive.
406
+ */
407
+ export function spliceSummary(entries, summary, keepLastN = KEEP_LAST_N) {
408
+ let tail = keepLastN > 0 ? entries.slice(-keepLastN) : [];
409
+ while (tail.length > 0 && tail[0].role === "tool")
410
+ tail = tail.slice(1);
411
+ const summaryEntry = { role: "summary", content: RESUME_PREFIX + stripAnalysis(summary) };
412
+ return [summaryEntry, ...tail];
413
+ }
414
+ /**
415
+ * Split the transcript at API-ROUND boundaries: one group per model round-trip.
416
+ *
417
+ * A boundary fires when a NEW assistant entry begins, because that is the one split
418
+ * point the wire format guarantees is safe. Every tool result must be resolved before
419
+ * the next assistant turn, so a group that starts at an assistant carries that
420
+ * assistant's tool calls AND their results together — pairing validity falls out of the
421
+ * boundary rather than needing to be checked.
422
+ *
423
+ * The first group is the preamble (whatever precedes the first assistant entry: the
424
+ * opening user message, a restored summary). Every later group starts with an assistant.
425
+ *
426
+ * Rounds, not entries, is the unit that matters when something has to be DROPPED: a
427
+ * single round with six parallel tool calls is seven entries, so counting entries can
428
+ * cut a round in half or keep one round while claiming to keep eight things.
429
+ */
430
+ export function groupByRound(entries) {
431
+ const groups = [];
432
+ let current = [];
433
+ for (const e of entries) {
434
+ if (e.role === "assistant" && current.length > 0) {
435
+ groups.push(current);
436
+ current = [];
437
+ }
438
+ current.push(e);
439
+ }
440
+ if (current.length > 0)
441
+ groups.push(current);
442
+ return groups;
443
+ }
444
+ /** Fallback share of the conversation to drop when the provider gave no token gap. */
445
+ const OVERFLOW_DROP_SHARE = 0.2;
446
+ /**
447
+ * Drop the OLDEST whole rounds so an over-long conversation fits, keeping the newest.
448
+ *
449
+ * The failure this exists for: the provider refuses the request because the prompt no
450
+ * longer fits, and the turn simply ends. The user is told to compact by hand, mid-task,
451
+ * having already paid for the refused call. Dropping the oldest rounds and retrying is
452
+ * what turns that into a recoverable hiccup.
453
+ *
454
+ * `tokenGap` is how much the request overshot, when the provider says so; rounds are
455
+ * dropped until that much is reclaimed. Without it, drop a fixed share — enough to make
456
+ * progress, small enough not to throw away a conversation to fix a slight overrun.
457
+ *
458
+ * ALWAYS keeps at least one group. It cannot return a sequence starting with an orphaned
459
+ * tool result, and that is a property of the SPLIT rather than a check performed here:
460
+ * every group after the first begins with an assistant entry, so whatever survives
461
+ * begins with one too. A defensive strip was written here first and deleted — it could
462
+ * never fire, and an unreachable guard reads as protection while providing none.
463
+ */
464
+ export function dropOldestRounds(entries, tokenGap, estimate = estimateEntriesTokens) {
465
+ const groups = groupByRound(entries);
466
+ if (groups.length < 2)
467
+ return null;
468
+ let dropCount = 0;
469
+ if (tokenGap !== undefined && tokenGap > 0) {
470
+ let freed = 0;
471
+ for (const g of groups) {
472
+ freed += estimate(g);
473
+ dropCount++;
474
+ if (freed >= tokenGap)
475
+ break;
476
+ }
477
+ }
478
+ else {
479
+ dropCount = Math.max(1, Math.floor(groups.length * OVERFLOW_DROP_SHARE));
480
+ }
481
+ dropCount = Math.min(dropCount, groups.length - 1);
482
+ if (dropCount < 1)
483
+ return null;
484
+ const kept = groups.slice(dropCount).flat();
485
+ return kept.length > 0 ? kept : null;
486
+ }
487
+ /**
488
+ * The summary request, optionally pointed at what the user cares about.
489
+ *
490
+ * `/compact focus on the auth work` used to be discarded without a word. It is a real
491
+ * feature — the person compacting usually knows which thread they are about to keep
492
+ * working on, and the summarizer does not.
493
+ *
494
+ * The focus is ADDITIVE and says so twice, because the failure mode here is severe and
495
+ * silent: this summary REPLACES the older transcript, so a model that reads "focus on
496
+ * X" as "only keep X" destroys the rest of the session permanently. The instruction
497
+ * therefore never narrows the nine sections, it only ranks detail within them.
498
+ *
499
+ * The user's text is quoted rather than interpolated bare so an instruction that looks
500
+ * like a directive to the summarizer ("ignore the sections above") reads as something
501
+ * the user said, not as something the system is asking for.
502
+ */
503
+ export function summaryRequest(focus) {
504
+ const wanted = focus?.trim();
505
+ if (!wanted)
506
+ return SUMMARY_REQUEST;
507
+ return (`${SUMMARY_REQUEST}\n\n` +
508
+ `The user asked for this summary with a particular focus, quoted here: "${wanted}".\n` +
509
+ `Give that subject the most detail. Do NOT drop or shorten any of the nine sections ` +
510
+ `to make room for it — this summary replaces the older transcript, so anything left ` +
511
+ `out is gone regardless of the focus.`);
512
+ }
513
+ //# sourceMappingURL=compaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compaction.js","sourceRoot":"","sources":["../../src/memory/compaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,gFAAgF;AAChF,6EAA6E;AAC7E,2BAA2B;AAC3B,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,iFAAiF;AACjF,mFAAmF;AACnF,iFAAiF;AACjF,8EAA8E;AAC9E,kFAAkF;AAClF,6EAA6E;AAC7E,qDAAqD;AACrD,kFAAkF;AAClF,sDAAsD;AAEtD;oFACoF;AACpF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC;AAE7B;4FAC4F;AAC5F,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAEtC,MAAM,CAAC,MAAM,YAAY,GACvB,0FAA0F,CAAC;AAE7F;;;8EAG8E;AAC9E,M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