attocode 0.1.0

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 (488) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/LICENSE +21 -0
  3. package/README.md +164 -0
  4. package/dist/src/adapters.d.ts +83 -0
  5. package/dist/src/adapters.d.ts.map +1 -0
  6. package/dist/src/adapters.js +221 -0
  7. package/dist/src/adapters.js.map +1 -0
  8. package/dist/src/agent-tools/index.d.ts +7 -0
  9. package/dist/src/agent-tools/index.d.ts.map +1 -0
  10. package/dist/src/agent-tools/index.js +8 -0
  11. package/dist/src/agent-tools/index.js.map +1 -0
  12. package/dist/src/agent-tools/lsp-file-tools.d.ts +33 -0
  13. package/dist/src/agent-tools/lsp-file-tools.d.ts.map +1 -0
  14. package/dist/src/agent-tools/lsp-file-tools.js +200 -0
  15. package/dist/src/agent-tools/lsp-file-tools.js.map +1 -0
  16. package/dist/src/agent.d.ts +667 -0
  17. package/dist/src/agent.d.ts.map +1 -0
  18. package/dist/src/agent.js +2824 -0
  19. package/dist/src/agent.js.map +1 -0
  20. package/dist/src/cli.d.ts +36 -0
  21. package/dist/src/cli.d.ts.map +1 -0
  22. package/dist/src/cli.js +176 -0
  23. package/dist/src/cli.js.map +1 -0
  24. package/dist/src/commands/handler.d.ts +22 -0
  25. package/dist/src/commands/handler.d.ts.map +1 -0
  26. package/dist/src/commands/handler.js +1320 -0
  27. package/dist/src/commands/handler.js.map +1 -0
  28. package/dist/src/commands/init.d.ts +7 -0
  29. package/dist/src/commands/init.d.ts.map +1 -0
  30. package/dist/src/commands/init.js +153 -0
  31. package/dist/src/commands/init.js.map +1 -0
  32. package/dist/src/commands/types.d.ts +70 -0
  33. package/dist/src/commands/types.d.ts.map +1 -0
  34. package/dist/src/commands/types.js +8 -0
  35. package/dist/src/commands/types.js.map +1 -0
  36. package/dist/src/config.d.ts +22 -0
  37. package/dist/src/config.d.ts.map +1 -0
  38. package/dist/src/config.js +25 -0
  39. package/dist/src/config.js.map +1 -0
  40. package/dist/src/core/index.d.ts +32 -0
  41. package/dist/src/core/index.d.ts.map +1 -0
  42. package/dist/src/core/index.js +35 -0
  43. package/dist/src/core/index.js.map +1 -0
  44. package/dist/src/core/process-handlers.d.ts +43 -0
  45. package/dist/src/core/process-handlers.d.ts.map +1 -0
  46. package/dist/src/core/process-handlers.js +117 -0
  47. package/dist/src/core/process-handlers.js.map +1 -0
  48. package/dist/src/core/protocol/bridge.d.ts +117 -0
  49. package/dist/src/core/protocol/bridge.d.ts.map +1 -0
  50. package/dist/src/core/protocol/bridge.js +149 -0
  51. package/dist/src/core/protocol/bridge.js.map +1 -0
  52. package/dist/src/core/protocol/index.d.ts +8 -0
  53. package/dist/src/core/protocol/index.d.ts.map +1 -0
  54. package/dist/src/core/protocol/index.js +8 -0
  55. package/dist/src/core/protocol/index.js.map +1 -0
  56. package/dist/src/core/protocol/types.d.ts +539 -0
  57. package/dist/src/core/protocol/types.d.ts.map +1 -0
  58. package/dist/src/core/protocol/types.js +149 -0
  59. package/dist/src/core/protocol/types.js.map +1 -0
  60. package/dist/src/core/queues/atomic-counter.d.ts +36 -0
  61. package/dist/src/core/queues/atomic-counter.d.ts.map +1 -0
  62. package/dist/src/core/queues/atomic-counter.js +46 -0
  63. package/dist/src/core/queues/atomic-counter.js.map +1 -0
  64. package/dist/src/core/queues/event-queue.d.ts +126 -0
  65. package/dist/src/core/queues/event-queue.d.ts.map +1 -0
  66. package/dist/src/core/queues/event-queue.js +208 -0
  67. package/dist/src/core/queues/event-queue.js.map +1 -0
  68. package/dist/src/core/queues/index.d.ts +12 -0
  69. package/dist/src/core/queues/index.d.ts.map +1 -0
  70. package/dist/src/core/queues/index.js +15 -0
  71. package/dist/src/core/queues/index.js.map +1 -0
  72. package/dist/src/core/queues/submission-queue.d.ts +116 -0
  73. package/dist/src/core/queues/submission-queue.d.ts.map +1 -0
  74. package/dist/src/core/queues/submission-queue.js +236 -0
  75. package/dist/src/core/queues/submission-queue.js.map +1 -0
  76. package/dist/src/costs/index.d.ts +22 -0
  77. package/dist/src/costs/index.d.ts.map +1 -0
  78. package/dist/src/costs/index.js +22 -0
  79. package/dist/src/costs/index.js.map +1 -0
  80. package/dist/src/costs/model-registry.d.ts +80 -0
  81. package/dist/src/costs/model-registry.d.ts.map +1 -0
  82. package/dist/src/costs/model-registry.js +237 -0
  83. package/dist/src/costs/model-registry.js.map +1 -0
  84. package/dist/src/costs/types.d.ts +50 -0
  85. package/dist/src/costs/types.d.ts.map +1 -0
  86. package/dist/src/costs/types.js +2 -0
  87. package/dist/src/costs/types.js.map +1 -0
  88. package/dist/src/defaults.d.ts +114 -0
  89. package/dist/src/defaults.d.ts.map +1 -0
  90. package/dist/src/defaults.js +457 -0
  91. package/dist/src/defaults.js.map +1 -0
  92. package/dist/src/first-run.d.ts +35 -0
  93. package/dist/src/first-run.d.ts.map +1 -0
  94. package/dist/src/first-run.js +94 -0
  95. package/dist/src/first-run.js.map +1 -0
  96. package/dist/src/hello.d.ts +2 -0
  97. package/dist/src/hello.d.ts.map +1 -0
  98. package/dist/src/hello.js +4 -0
  99. package/dist/src/hello.js.map +1 -0
  100. package/dist/src/integrations/agent-registry.d.ts +160 -0
  101. package/dist/src/integrations/agent-registry.d.ts.map +1 -0
  102. package/dist/src/integrations/agent-registry.js +446 -0
  103. package/dist/src/integrations/agent-registry.js.map +1 -0
  104. package/dist/src/integrations/auto-compaction.d.ts +177 -0
  105. package/dist/src/integrations/auto-compaction.d.ts.map +1 -0
  106. package/dist/src/integrations/auto-compaction.js +428 -0
  107. package/dist/src/integrations/auto-compaction.js.map +1 -0
  108. package/dist/src/integrations/cancellation.d.ts +162 -0
  109. package/dist/src/integrations/cancellation.d.ts.map +1 -0
  110. package/dist/src/integrations/cancellation.js +339 -0
  111. package/dist/src/integrations/cancellation.js.map +1 -0
  112. package/dist/src/integrations/codebase-context.d.ts +319 -0
  113. package/dist/src/integrations/codebase-context.d.ts.map +1 -0
  114. package/dist/src/integrations/codebase-context.js +816 -0
  115. package/dist/src/integrations/codebase-context.js.map +1 -0
  116. package/dist/src/integrations/compaction.d.ts +192 -0
  117. package/dist/src/integrations/compaction.d.ts.map +1 -0
  118. package/dist/src/integrations/compaction.js +376 -0
  119. package/dist/src/integrations/compaction.js.map +1 -0
  120. package/dist/src/integrations/context-engineering.d.ts +246 -0
  121. package/dist/src/integrations/context-engineering.d.ts.map +1 -0
  122. package/dist/src/integrations/context-engineering.js +394 -0
  123. package/dist/src/integrations/context-engineering.js.map +1 -0
  124. package/dist/src/integrations/diff-utils.d.ts +105 -0
  125. package/dist/src/integrations/diff-utils.d.ts.map +1 -0
  126. package/dist/src/integrations/diff-utils.js +497 -0
  127. package/dist/src/integrations/diff-utils.js.map +1 -0
  128. package/dist/src/integrations/economics.d.ts +192 -0
  129. package/dist/src/integrations/economics.d.ts.map +1 -0
  130. package/dist/src/integrations/economics.js +431 -0
  131. package/dist/src/integrations/economics.js.map +1 -0
  132. package/dist/src/integrations/execution-policy.d.ts +189 -0
  133. package/dist/src/integrations/execution-policy.d.ts.map +1 -0
  134. package/dist/src/integrations/execution-policy.js +352 -0
  135. package/dist/src/integrations/execution-policy.js.map +1 -0
  136. package/dist/src/integrations/file-change-tracker.d.ts +161 -0
  137. package/dist/src/integrations/file-change-tracker.d.ts.map +1 -0
  138. package/dist/src/integrations/file-change-tracker.js +520 -0
  139. package/dist/src/integrations/file-change-tracker.js.map +1 -0
  140. package/dist/src/integrations/hierarchical-config.d.ts +212 -0
  141. package/dist/src/integrations/hierarchical-config.d.ts.map +1 -0
  142. package/dist/src/integrations/hierarchical-config.js +484 -0
  143. package/dist/src/integrations/hierarchical-config.js.map +1 -0
  144. package/dist/src/integrations/hooks.d.ts +114 -0
  145. package/dist/src/integrations/hooks.d.ts.map +1 -0
  146. package/dist/src/integrations/hooks.js +326 -0
  147. package/dist/src/integrations/hooks.js.map +1 -0
  148. package/dist/src/integrations/ignore.d.ts +143 -0
  149. package/dist/src/integrations/ignore.d.ts.map +1 -0
  150. package/dist/src/integrations/ignore.js +417 -0
  151. package/dist/src/integrations/ignore.js.map +1 -0
  152. package/dist/src/integrations/image-renderer.d.ts +119 -0
  153. package/dist/src/integrations/image-renderer.d.ts.map +1 -0
  154. package/dist/src/integrations/image-renderer.js +306 -0
  155. package/dist/src/integrations/image-renderer.js.map +1 -0
  156. package/dist/src/integrations/index.d.ts +42 -0
  157. package/dist/src/integrations/index.d.ts.map +1 -0
  158. package/dist/src/integrations/index.js +73 -0
  159. package/dist/src/integrations/index.js.map +1 -0
  160. package/dist/src/integrations/lsp.d.ts +196 -0
  161. package/dist/src/integrations/lsp.d.ts.map +1 -0
  162. package/dist/src/integrations/lsp.js +582 -0
  163. package/dist/src/integrations/lsp.js.map +1 -0
  164. package/dist/src/integrations/mcp-client.d.ts +270 -0
  165. package/dist/src/integrations/mcp-client.d.ts.map +1 -0
  166. package/dist/src/integrations/mcp-client.js +698 -0
  167. package/dist/src/integrations/mcp-client.js.map +1 -0
  168. package/dist/src/integrations/mcp-tool-search.d.ts +77 -0
  169. package/dist/src/integrations/mcp-tool-search.d.ts.map +1 -0
  170. package/dist/src/integrations/mcp-tool-search.js +220 -0
  171. package/dist/src/integrations/mcp-tool-search.js.map +1 -0
  172. package/dist/src/integrations/memory.d.ts +108 -0
  173. package/dist/src/integrations/memory.d.ts.map +1 -0
  174. package/dist/src/integrations/memory.js +288 -0
  175. package/dist/src/integrations/memory.js.map +1 -0
  176. package/dist/src/integrations/multi-agent.d.ts +150 -0
  177. package/dist/src/integrations/multi-agent.d.ts.map +1 -0
  178. package/dist/src/integrations/multi-agent.js +306 -0
  179. package/dist/src/integrations/multi-agent.js.map +1 -0
  180. package/dist/src/integrations/observability.d.ts +162 -0
  181. package/dist/src/integrations/observability.d.ts.map +1 -0
  182. package/dist/src/integrations/observability.js +406 -0
  183. package/dist/src/integrations/observability.js.map +1 -0
  184. package/dist/src/integrations/openrouter-pricing.d.ts +42 -0
  185. package/dist/src/integrations/openrouter-pricing.d.ts.map +1 -0
  186. package/dist/src/integrations/openrouter-pricing.js +124 -0
  187. package/dist/src/integrations/openrouter-pricing.js.map +1 -0
  188. package/dist/src/integrations/pending-plan.d.ts +171 -0
  189. package/dist/src/integrations/pending-plan.d.ts.map +1 -0
  190. package/dist/src/integrations/pending-plan.js +244 -0
  191. package/dist/src/integrations/pending-plan.js.map +1 -0
  192. package/dist/src/integrations/persistence.d.ts +48 -0
  193. package/dist/src/integrations/persistence.d.ts.map +1 -0
  194. package/dist/src/integrations/persistence.js +196 -0
  195. package/dist/src/integrations/persistence.js.map +1 -0
  196. package/dist/src/integrations/planning.d.ts +96 -0
  197. package/dist/src/integrations/planning.d.ts.map +1 -0
  198. package/dist/src/integrations/planning.js +338 -0
  199. package/dist/src/integrations/planning.js.map +1 -0
  200. package/dist/src/integrations/pty-shell.d.ts +169 -0
  201. package/dist/src/integrations/pty-shell.d.ts.map +1 -0
  202. package/dist/src/integrations/pty-shell.js +367 -0
  203. package/dist/src/integrations/pty-shell.js.map +1 -0
  204. package/dist/src/integrations/react.d.ts +139 -0
  205. package/dist/src/integrations/react.d.ts.map +1 -0
  206. package/dist/src/integrations/react.js +273 -0
  207. package/dist/src/integrations/react.js.map +1 -0
  208. package/dist/src/integrations/resources.d.ts +177 -0
  209. package/dist/src/integrations/resources.d.ts.map +1 -0
  210. package/dist/src/integrations/resources.js +311 -0
  211. package/dist/src/integrations/resources.js.map +1 -0
  212. package/dist/src/integrations/result-synthesizer.d.ts +389 -0
  213. package/dist/src/integrations/result-synthesizer.d.ts.map +1 -0
  214. package/dist/src/integrations/result-synthesizer.js +951 -0
  215. package/dist/src/integrations/result-synthesizer.js.map +1 -0
  216. package/dist/src/integrations/routing.d.ts +117 -0
  217. package/dist/src/integrations/routing.d.ts.map +1 -0
  218. package/dist/src/integrations/routing.js +347 -0
  219. package/dist/src/integrations/routing.js.map +1 -0
  220. package/dist/src/integrations/rules.d.ts +131 -0
  221. package/dist/src/integrations/rules.d.ts.map +1 -0
  222. package/dist/src/integrations/rules.js +284 -0
  223. package/dist/src/integrations/rules.js.map +1 -0
  224. package/dist/src/integrations/safety.d.ts +142 -0
  225. package/dist/src/integrations/safety.d.ts.map +1 -0
  226. package/dist/src/integrations/safety.js +342 -0
  227. package/dist/src/integrations/safety.js.map +1 -0
  228. package/dist/src/integrations/sandbox/basic.d.ts +74 -0
  229. package/dist/src/integrations/sandbox/basic.d.ts.map +1 -0
  230. package/dist/src/integrations/sandbox/basic.js +310 -0
  231. package/dist/src/integrations/sandbox/basic.js.map +1 -0
  232. package/dist/src/integrations/sandbox/docker.d.ts +94 -0
  233. package/dist/src/integrations/sandbox/docker.d.ts.map +1 -0
  234. package/dist/src/integrations/sandbox/docker.js +293 -0
  235. package/dist/src/integrations/sandbox/docker.js.map +1 -0
  236. package/dist/src/integrations/sandbox/index.d.ts +182 -0
  237. package/dist/src/integrations/sandbox/index.d.ts.map +1 -0
  238. package/dist/src/integrations/sandbox/index.js +382 -0
  239. package/dist/src/integrations/sandbox/index.js.map +1 -0
  240. package/dist/src/integrations/sandbox/landlock.d.ts +59 -0
  241. package/dist/src/integrations/sandbox/landlock.d.ts.map +1 -0
  242. package/dist/src/integrations/sandbox/landlock.js +326 -0
  243. package/dist/src/integrations/sandbox/landlock.js.map +1 -0
  244. package/dist/src/integrations/sandbox/seatbelt.d.ts +68 -0
  245. package/dist/src/integrations/sandbox/seatbelt.d.ts.map +1 -0
  246. package/dist/src/integrations/sandbox/seatbelt.js +298 -0
  247. package/dist/src/integrations/sandbox/seatbelt.js.map +1 -0
  248. package/dist/src/integrations/semantic-cache.d.ts +178 -0
  249. package/dist/src/integrations/semantic-cache.d.ts.map +1 -0
  250. package/dist/src/integrations/semantic-cache.js +372 -0
  251. package/dist/src/integrations/semantic-cache.js.map +1 -0
  252. package/dist/src/integrations/session-store.d.ts +183 -0
  253. package/dist/src/integrations/session-store.d.ts.map +1 -0
  254. package/dist/src/integrations/session-store.js +345 -0
  255. package/dist/src/integrations/session-store.js.map +1 -0
  256. package/dist/src/integrations/shared-blackboard.d.ts +403 -0
  257. package/dist/src/integrations/shared-blackboard.d.ts.map +1 -0
  258. package/dist/src/integrations/shared-blackboard.js +710 -0
  259. package/dist/src/integrations/shared-blackboard.js.map +1 -0
  260. package/dist/src/integrations/skills.d.ts +171 -0
  261. package/dist/src/integrations/skills.d.ts.map +1 -0
  262. package/dist/src/integrations/skills.js +403 -0
  263. package/dist/src/integrations/skills.js.map +1 -0
  264. package/dist/src/integrations/smart-decomposer.d.ts +322 -0
  265. package/dist/src/integrations/smart-decomposer.d.ts.map +1 -0
  266. package/dist/src/integrations/smart-decomposer.js +856 -0
  267. package/dist/src/integrations/smart-decomposer.js.map +1 -0
  268. package/dist/src/integrations/sourcegraph.d.ts +169 -0
  269. package/dist/src/integrations/sourcegraph.d.ts.map +1 -0
  270. package/dist/src/integrations/sourcegraph.js +379 -0
  271. package/dist/src/integrations/sourcegraph.js.map +1 -0
  272. package/dist/src/integrations/sqlite-store.d.ts +518 -0
  273. package/dist/src/integrations/sqlite-store.d.ts.map +1 -0
  274. package/dist/src/integrations/sqlite-store.js +1423 -0
  275. package/dist/src/integrations/sqlite-store.js.map +1 -0
  276. package/dist/src/integrations/streaming.d.ts +102 -0
  277. package/dist/src/integrations/streaming.d.ts.map +1 -0
  278. package/dist/src/integrations/streaming.js +362 -0
  279. package/dist/src/integrations/streaming.js.map +1 -0
  280. package/dist/src/integrations/thread-manager.d.ts +199 -0
  281. package/dist/src/integrations/thread-manager.d.ts.map +1 -0
  282. package/dist/src/integrations/thread-manager.js +357 -0
  283. package/dist/src/integrations/thread-manager.js.map +1 -0
  284. package/dist/src/main.d.ts +26 -0
  285. package/dist/src/main.d.ts.map +1 -0
  286. package/dist/src/main.js +170 -0
  287. package/dist/src/main.js.map +1 -0
  288. package/dist/src/modes/index.d.ts +10 -0
  289. package/dist/src/modes/index.d.ts.map +1 -0
  290. package/dist/src/modes/index.js +10 -0
  291. package/dist/src/modes/index.js.map +1 -0
  292. package/dist/src/modes/repl.d.ts +19 -0
  293. package/dist/src/modes/repl.d.ts.map +1 -0
  294. package/dist/src/modes/repl.js +393 -0
  295. package/dist/src/modes/repl.js.map +1 -0
  296. package/dist/src/modes/tui.d.ts +29 -0
  297. package/dist/src/modes/tui.d.ts.map +1 -0
  298. package/dist/src/modes/tui.js +272 -0
  299. package/dist/src/modes/tui.js.map +1 -0
  300. package/dist/src/modes.d.ts +179 -0
  301. package/dist/src/modes.d.ts.map +1 -0
  302. package/dist/src/modes.js +385 -0
  303. package/dist/src/modes.js.map +1 -0
  304. package/dist/src/observability/tracer.d.ts +111 -0
  305. package/dist/src/observability/tracer.d.ts.map +1 -0
  306. package/dist/src/observability/tracer.js +300 -0
  307. package/dist/src/observability/tracer.js.map +1 -0
  308. package/dist/src/observability/types.d.ts +271 -0
  309. package/dist/src/observability/types.d.ts.map +1 -0
  310. package/dist/src/observability/types.js +24 -0
  311. package/dist/src/observability/types.js.map +1 -0
  312. package/dist/src/paths.d.ts +101 -0
  313. package/dist/src/paths.d.ts.map +1 -0
  314. package/dist/src/paths.js +148 -0
  315. package/dist/src/paths.js.map +1 -0
  316. package/dist/src/persistence/index.d.ts +38 -0
  317. package/dist/src/persistence/index.d.ts.map +1 -0
  318. package/dist/src/persistence/index.js +48 -0
  319. package/dist/src/persistence/index.js.map +1 -0
  320. package/dist/src/persistence/migrator.d.ts +135 -0
  321. package/dist/src/persistence/migrator.d.ts.map +1 -0
  322. package/dist/src/persistence/migrator.js +303 -0
  323. package/dist/src/persistence/migrator.js.map +1 -0
  324. package/dist/src/persistence/schema.d.ts +101 -0
  325. package/dist/src/persistence/schema.d.ts.map +1 -0
  326. package/dist/src/persistence/schema.js +395 -0
  327. package/dist/src/persistence/schema.js.map +1 -0
  328. package/dist/src/providers/adapters/anthropic.d.ts +20 -0
  329. package/dist/src/providers/adapters/anthropic.d.ts.map +1 -0
  330. package/dist/src/providers/adapters/anthropic.js +124 -0
  331. package/dist/src/providers/adapters/anthropic.js.map +1 -0
  332. package/dist/src/providers/adapters/mock.d.ts +25 -0
  333. package/dist/src/providers/adapters/mock.d.ts.map +1 -0
  334. package/dist/src/providers/adapters/mock.js +133 -0
  335. package/dist/src/providers/adapters/mock.js.map +1 -0
  336. package/dist/src/providers/adapters/openai.d.ts +21 -0
  337. package/dist/src/providers/adapters/openai.d.ts.map +1 -0
  338. package/dist/src/providers/adapters/openai.js +126 -0
  339. package/dist/src/providers/adapters/openai.js.map +1 -0
  340. package/dist/src/providers/adapters/openrouter.d.ts +49 -0
  341. package/dist/src/providers/adapters/openrouter.d.ts.map +1 -0
  342. package/dist/src/providers/adapters/openrouter.js +363 -0
  343. package/dist/src/providers/adapters/openrouter.js.map +1 -0
  344. package/dist/src/providers/provider.d.ts +54 -0
  345. package/dist/src/providers/provider.d.ts.map +1 -0
  346. package/dist/src/providers/provider.js +111 -0
  347. package/dist/src/providers/provider.js.map +1 -0
  348. package/dist/src/providers/resilient-fetch.d.ts +99 -0
  349. package/dist/src/providers/resilient-fetch.d.ts.map +1 -0
  350. package/dist/src/providers/resilient-fetch.js +208 -0
  351. package/dist/src/providers/resilient-fetch.js.map +1 -0
  352. package/dist/src/providers/types.d.ts +227 -0
  353. package/dist/src/providers/types.d.ts.map +1 -0
  354. package/dist/src/providers/types.js +24 -0
  355. package/dist/src/providers/types.js.map +1 -0
  356. package/dist/src/session-picker.d.ts +28 -0
  357. package/dist/src/session-picker.d.ts.map +1 -0
  358. package/dist/src/session-picker.js +256 -0
  359. package/dist/src/session-picker.js.map +1 -0
  360. package/dist/src/test-sqlite.d.ts +2 -0
  361. package/dist/src/test-sqlite.d.ts.map +1 -0
  362. package/dist/src/test-sqlite.js +114 -0
  363. package/dist/src/test-sqlite.js.map +1 -0
  364. package/dist/src/tools/agent.d.ts +44 -0
  365. package/dist/src/tools/agent.d.ts.map +1 -0
  366. package/dist/src/tools/agent.js +110 -0
  367. package/dist/src/tools/agent.js.map +1 -0
  368. package/dist/src/tools/bash.d.ts +52 -0
  369. package/dist/src/tools/bash.d.ts.map +1 -0
  370. package/dist/src/tools/bash.js +141 -0
  371. package/dist/src/tools/bash.js.map +1 -0
  372. package/dist/src/tools/file.d.ts +47 -0
  373. package/dist/src/tools/file.d.ts.map +1 -0
  374. package/dist/src/tools/file.js +263 -0
  375. package/dist/src/tools/file.js.map +1 -0
  376. package/dist/src/tools/permission.d.ts +43 -0
  377. package/dist/src/tools/permission.d.ts.map +1 -0
  378. package/dist/src/tools/permission.js +216 -0
  379. package/dist/src/tools/permission.js.map +1 -0
  380. package/dist/src/tools/registry.d.ts +63 -0
  381. package/dist/src/tools/registry.d.ts.map +1 -0
  382. package/dist/src/tools/registry.js +250 -0
  383. package/dist/src/tools/registry.js.map +1 -0
  384. package/dist/src/tools/standard.d.ts +57 -0
  385. package/dist/src/tools/standard.d.ts.map +1 -0
  386. package/dist/src/tools/standard.js +113 -0
  387. package/dist/src/tools/standard.js.map +1 -0
  388. package/dist/src/tools/types.d.ts +146 -0
  389. package/dist/src/tools/types.d.ts.map +1 -0
  390. package/dist/src/tools/types.js +28 -0
  391. package/dist/src/tools/types.js.map +1 -0
  392. package/dist/src/tools/undo.d.ts +71 -0
  393. package/dist/src/tools/undo.d.ts.map +1 -0
  394. package/dist/src/tools/undo.js +123 -0
  395. package/dist/src/tools/undo.js.map +1 -0
  396. package/dist/src/tracing/cache-boundary-tracker.d.ts +189 -0
  397. package/dist/src/tracing/cache-boundary-tracker.d.ts.map +1 -0
  398. package/dist/src/tracing/cache-boundary-tracker.js +411 -0
  399. package/dist/src/tracing/cache-boundary-tracker.js.map +1 -0
  400. package/dist/src/tracing/trace-collector.d.ts +274 -0
  401. package/dist/src/tracing/trace-collector.d.ts.map +1 -0
  402. package/dist/src/tracing/trace-collector.js +727 -0
  403. package/dist/src/tracing/trace-collector.js.map +1 -0
  404. package/dist/src/tracing/types.d.ts +657 -0
  405. package/dist/src/tracing/types.d.ts.map +1 -0
  406. package/dist/src/tracing/types.js +39 -0
  407. package/dist/src/tracing/types.js.map +1 -0
  408. package/dist/src/tricks/failure-evidence.d.ts +268 -0
  409. package/dist/src/tricks/failure-evidence.d.ts.map +1 -0
  410. package/dist/src/tricks/failure-evidence.js +544 -0
  411. package/dist/src/tricks/failure-evidence.js.map +1 -0
  412. package/dist/src/tricks/json-utils.d.ts +77 -0
  413. package/dist/src/tricks/json-utils.d.ts.map +1 -0
  414. package/dist/src/tricks/json-utils.js +247 -0
  415. package/dist/src/tricks/json-utils.js.map +1 -0
  416. package/dist/src/tricks/kv-cache-context.d.ts +227 -0
  417. package/dist/src/tricks/kv-cache-context.d.ts.map +1 -0
  418. package/dist/src/tricks/kv-cache-context.js +377 -0
  419. package/dist/src/tricks/kv-cache-context.js.map +1 -0
  420. package/dist/src/tricks/recitation.d.ts +208 -0
  421. package/dist/src/tricks/recitation.d.ts.map +1 -0
  422. package/dist/src/tricks/recitation.js +374 -0
  423. package/dist/src/tricks/recitation.js.map +1 -0
  424. package/dist/src/tricks/reversible-compaction.d.ts +251 -0
  425. package/dist/src/tricks/reversible-compaction.d.ts.map +1 -0
  426. package/dist/src/tricks/reversible-compaction.js +555 -0
  427. package/dist/src/tricks/reversible-compaction.js.map +1 -0
  428. package/dist/src/tricks/serialization-diversity.d.ts +197 -0
  429. package/dist/src/tricks/serialization-diversity.d.ts.map +1 -0
  430. package/dist/src/tricks/serialization-diversity.js +460 -0
  431. package/dist/src/tricks/serialization-diversity.js.map +1 -0
  432. package/dist/src/tui/app.d.ts +42 -0
  433. package/dist/src/tui/app.d.ts.map +1 -0
  434. package/dist/src/tui/app.js +1076 -0
  435. package/dist/src/tui/app.js.map +1 -0
  436. package/dist/src/tui/components/ApprovalDialog.d.ts +28 -0
  437. package/dist/src/tui/components/ApprovalDialog.d.ts.map +1 -0
  438. package/dist/src/tui/components/ApprovalDialog.js +59 -0
  439. package/dist/src/tui/components/ApprovalDialog.js.map +1 -0
  440. package/dist/src/tui/components/InputArea.d.ts +35 -0
  441. package/dist/src/tui/components/InputArea.d.ts.map +1 -0
  442. package/dist/src/tui/components/InputArea.js +144 -0
  443. package/dist/src/tui/components/InputArea.js.map +1 -0
  444. package/dist/src/tui/components/MessageItem.d.ts +28 -0
  445. package/dist/src/tui/components/MessageItem.d.ts.map +1 -0
  446. package/dist/src/tui/components/MessageItem.js +27 -0
  447. package/dist/src/tui/components/MessageItem.js.map +1 -0
  448. package/dist/src/tui/components/ScrollableBox.d.ts +41 -0
  449. package/dist/src/tui/components/ScrollableBox.d.ts.map +1 -0
  450. package/dist/src/tui/components/ScrollableBox.js +101 -0
  451. package/dist/src/tui/components/ScrollableBox.js.map +1 -0
  452. package/dist/src/tui/components/ToolCallItem.d.ts +33 -0
  453. package/dist/src/tui/components/ToolCallItem.d.ts.map +1 -0
  454. package/dist/src/tui/components/ToolCallItem.js +91 -0
  455. package/dist/src/tui/components/ToolCallItem.js.map +1 -0
  456. package/dist/src/tui/components/index.d.ts +13 -0
  457. package/dist/src/tui/components/index.d.ts.map +1 -0
  458. package/dist/src/tui/components/index.js +15 -0
  459. package/dist/src/tui/components/index.js.map +1 -0
  460. package/dist/src/tui/event-display.d.ts +19 -0
  461. package/dist/src/tui/event-display.d.ts.map +1 -0
  462. package/dist/src/tui/event-display.js +178 -0
  463. package/dist/src/tui/event-display.js.map +1 -0
  464. package/dist/src/tui/index.d.ts +105 -0
  465. package/dist/src/tui/index.d.ts.map +1 -0
  466. package/dist/src/tui/index.js +214 -0
  467. package/dist/src/tui/index.js.map +1 -0
  468. package/dist/src/tui/input/CommandPalette.d.ts +55 -0
  469. package/dist/src/tui/input/CommandPalette.d.ts.map +1 -0
  470. package/dist/src/tui/input/CommandPalette.js +135 -0
  471. package/dist/src/tui/input/CommandPalette.js.map +1 -0
  472. package/dist/src/tui/input/index.d.ts +7 -0
  473. package/dist/src/tui/input/index.d.ts.map +1 -0
  474. package/dist/src/tui/input/index.js +7 -0
  475. package/dist/src/tui/input/index.js.map +1 -0
  476. package/dist/src/tui/theme/index.d.ts +45 -0
  477. package/dist/src/tui/theme/index.d.ts.map +1 -0
  478. package/dist/src/tui/theme/index.js +215 -0
  479. package/dist/src/tui/theme/index.js.map +1 -0
  480. package/dist/src/tui/types.d.ts +214 -0
  481. package/dist/src/tui/types.d.ts.map +1 -0
  482. package/dist/src/tui/types.js +27 -0
  483. package/dist/src/tui/types.js.map +1 -0
  484. package/dist/src/types.d.ts +905 -0
  485. package/dist/src/types.d.ts.map +1 -0
  486. package/dist/src/types.js +9 -0
  487. package/dist/src/types.js.map +1 -0
  488. package/package.json +89 -0
@@ -0,0 +1,161 @@
1
+ /**
2
+ * File Change Tracker
3
+ *
4
+ * Tracks file changes for undo capability in agent sessions.
5
+ * Provides before/after content capture, diff generation, and undo functionality.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import Database from 'better-sqlite3';
10
+ * import { FileChangeTracker } from './file-change-tracker.js';
11
+ *
12
+ * const db = new Database('sessions.db');
13
+ * const tracker = new FileChangeTracker(db, 'session-123');
14
+ *
15
+ * // Record a file change
16
+ * const changeId = await tracker.recordChange({
17
+ * filePath: '/path/to/file.ts',
18
+ * operation: 'edit',
19
+ * contentBefore: 'old content',
20
+ * contentAfter: 'new content',
21
+ * turnNumber: 1,
22
+ * });
23
+ *
24
+ * // Undo the change
25
+ * const result = await tracker.undoChange(changeId);
26
+ * ```
27
+ */
28
+ import Database from 'better-sqlite3';
29
+ /**
30
+ * Configuration for FileChangeTracker.
31
+ */
32
+ export interface FileChangeTrackerConfig {
33
+ /** Whether tracking is enabled (default: true) */
34
+ enabled?: boolean;
35
+ /** Maximum bytes for full content storage (default: 50KB). Above this, store diff only. */
36
+ maxFullContentBytes?: number;
37
+ }
38
+ /**
39
+ * Represents a file change record.
40
+ */
41
+ export interface FileChange {
42
+ /** Unique change ID */
43
+ id: number;
44
+ /** Session this change belongs to */
45
+ sessionId: string;
46
+ /** Turn number when change occurred */
47
+ turnNumber: number;
48
+ /** Path to the changed file */
49
+ filePath: string;
50
+ /** Type of operation */
51
+ operation: 'create' | 'write' | 'edit' | 'delete';
52
+ /** Content before the change (null for creates) */
53
+ contentBefore: string | null;
54
+ /** Content after the change (null for deletes) */
55
+ contentAfter: string | null;
56
+ /** Unified diff (when using diff storage mode) */
57
+ diffUnified: string | null;
58
+ /** How content is stored */
59
+ storageMode: 'full' | 'diff';
60
+ /** Bytes before change */
61
+ bytesBefore: number;
62
+ /** Bytes after change */
63
+ bytesAfter: number;
64
+ /** Whether this change has been undone */
65
+ isUndone: boolean;
66
+ /** ID of the change that undid this one */
67
+ undoChangeId: number | null;
68
+ /** Tool call ID that made this change */
69
+ toolCallId: string | null;
70
+ /** ISO timestamp of when change was recorded */
71
+ createdAt: string;
72
+ }
73
+ /**
74
+ * Result of an undo operation.
75
+ */
76
+ export interface UndoResult {
77
+ /** Whether the undo succeeded */
78
+ success: boolean;
79
+ /** Path to the affected file */
80
+ filePath: string;
81
+ /** Human-readable message */
82
+ message: string;
83
+ /** Change ID that was undone (if successful) */
84
+ changeId?: number;
85
+ }
86
+ /**
87
+ * Summary of changes in a session.
88
+ */
89
+ export interface ChangeSummary {
90
+ /** Total number of changes */
91
+ totalChanges: number;
92
+ /** Number of active (non-undone) changes */
93
+ activeChanges: number;
94
+ /** Number of undone changes */
95
+ undoneChanges: number;
96
+ /** Files that were modified */
97
+ filesModified: string[];
98
+ /** Changes by operation type */
99
+ byOperation: {
100
+ create: number;
101
+ write: number;
102
+ edit: number;
103
+ delete: number;
104
+ };
105
+ }
106
+ /**
107
+ * Tracks file changes for undo capability.
108
+ */
109
+ export declare class FileChangeTracker {
110
+ private db;
111
+ private sessionId;
112
+ private config;
113
+ private stmts;
114
+ constructor(db: Database.Database, sessionId: string, config?: FileChangeTrackerConfig);
115
+ /**
116
+ * Prepare SQL statements for reuse.
117
+ */
118
+ private prepareStatements;
119
+ /**
120
+ * Record a file change.
121
+ */
122
+ recordChange(params: {
123
+ filePath: string;
124
+ operation: 'create' | 'write' | 'edit' | 'delete';
125
+ contentBefore?: string;
126
+ contentAfter?: string;
127
+ turnNumber: number;
128
+ toolCallId?: string;
129
+ }): Promise<number>;
130
+ /**
131
+ * Undo a specific change by ID.
132
+ */
133
+ undoChange(changeId: number): Promise<UndoResult>;
134
+ /**
135
+ * Undo the last change to a specific file.
136
+ */
137
+ undoLastChange(filePath: string): Promise<UndoResult>;
138
+ /**
139
+ * Undo all changes in a turn.
140
+ */
141
+ undoTurn(turnNumber: number): Promise<UndoResult[]>;
142
+ /**
143
+ * Get all changes for a file.
144
+ */
145
+ getFileHistory(filePath: string): FileChange[];
146
+ /**
147
+ * Get all changes in session.
148
+ */
149
+ getChanges(options?: {
150
+ filePath?: string;
151
+ }): FileChange[];
152
+ /**
153
+ * Get session change summary.
154
+ */
155
+ getSessionChangeSummary(): ChangeSummary;
156
+ }
157
+ /**
158
+ * Create a FileChangeTracker instance.
159
+ */
160
+ export declare function createFileChangeTracker(db: Database.Database, sessionId: string, config?: FileChangeTrackerConfig): FileChangeTracker;
161
+ //# sourceMappingURL=file-change-tracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-change-tracker.d.ts","sourceRoot":"","sources":["../../../src/integrations/file-change-tracker.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,520 @@
1
+ /**
2
+ * File Change Tracker
3
+ *
4
+ * Tracks file changes for undo capability in agent sessions.
5
+ * Provides before/after content capture, diff generation, and undo functionality.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import Database from 'better-sqlite3';
10
+ * import { FileChangeTracker } from './file-change-tracker.js';
11
+ *
12
+ * const db = new Database('sessions.db');
13
+ * const tracker = new FileChangeTracker(db, 'session-123');
14
+ *
15
+ * // Record a file change
16
+ * const changeId = await tracker.recordChange({
17
+ * filePath: '/path/to/file.ts',
18
+ * operation: 'edit',
19
+ * contentBefore: 'old content',
20
+ * contentAfter: 'new content',
21
+ * turnNumber: 1,
22
+ * });
23
+ *
24
+ * // Undo the change
25
+ * const result = await tracker.undoChange(changeId);
26
+ * ```
27
+ */
28
+ import { writeFile, unlink } from 'node:fs/promises';
29
+ import { existsSync } from 'node:fs';
30
+ // =============================================================================
31
+ // DIFF UTILITIES
32
+ // =============================================================================
33
+ /**
34
+ * Generate a simple unified diff between two strings.
35
+ * This is a basic implementation - for production, consider using a proper diff library.
36
+ */
37
+ function generateUnifiedDiff(before, after, filePath) {
38
+ const beforeLines = before.split('\n');
39
+ const afterLines = after.split('\n');
40
+ const header = [
41
+ `--- a/${filePath}`,
42
+ `+++ b/${filePath}`,
43
+ ];
44
+ // Simple line-by-line diff (not optimal but functional)
45
+ const hunks = [];
46
+ let i = 0;
47
+ let j = 0;
48
+ while (i < beforeLines.length || j < afterLines.length) {
49
+ // Find next difference
50
+ const startI = i;
51
+ const startJ = j;
52
+ // Skip matching lines
53
+ while (i < beforeLines.length && j < afterLines.length && beforeLines[i] === afterLines[j]) {
54
+ i++;
55
+ j++;
56
+ }
57
+ // If we've found a difference or reached the end
58
+ if (i < beforeLines.length || j < afterLines.length) {
59
+ // Determine the hunk boundaries
60
+ const contextBefore = Math.max(0, i - 3);
61
+ const hunkStart = contextBefore + 1;
62
+ // Find the extent of the difference
63
+ const diffStartI = i;
64
+ const diffStartJ = j;
65
+ // Advance through differing lines
66
+ while (i < beforeLines.length || j < afterLines.length) {
67
+ if (i < beforeLines.length && j < afterLines.length && beforeLines[i] === afterLines[j]) {
68
+ // Found a match - check if it's the end of the diff section
69
+ let matchCount = 0;
70
+ let tempI = i;
71
+ let tempJ = j;
72
+ while (tempI < beforeLines.length && tempJ < afterLines.length &&
73
+ beforeLines[tempI] === afterLines[tempJ] && matchCount < 3) {
74
+ matchCount++;
75
+ tempI++;
76
+ tempJ++;
77
+ }
78
+ if (matchCount >= 3) {
79
+ break;
80
+ }
81
+ }
82
+ if (i < beforeLines.length)
83
+ i++;
84
+ if (j < afterLines.length)
85
+ j++;
86
+ }
87
+ // Build the hunk
88
+ const hunkLines = [];
89
+ const beforeCount = i - contextBefore;
90
+ const afterCount = j - (startJ + (contextBefore - startI));
91
+ hunkLines.push(`@@ -${hunkStart},${beforeCount} +${hunkStart},${afterCount} @@`);
92
+ // Add context before
93
+ for (let k = contextBefore; k < diffStartI; k++) {
94
+ hunkLines.push(` ${beforeLines[k]}`);
95
+ }
96
+ // Add removed lines
97
+ for (let k = diffStartI; k < i; k++) {
98
+ if (k < beforeLines.length) {
99
+ hunkLines.push(`-${beforeLines[k]}`);
100
+ }
101
+ }
102
+ // Add added lines
103
+ for (let k = diffStartJ; k < j; k++) {
104
+ if (k < afterLines.length) {
105
+ hunkLines.push(`+${afterLines[k]}`);
106
+ }
107
+ }
108
+ hunks.push(hunkLines.join('\n'));
109
+ }
110
+ }
111
+ return [...header, ...hunks].join('\n');
112
+ }
113
+ /**
114
+ * Apply a unified diff to restore original content.
115
+ * Returns the original content before the diff was applied.
116
+ */
117
+ function applyReverseDiff(currentContent, diff) {
118
+ // Parse diff hunks
119
+ const lines = diff.split('\n');
120
+ const resultLines = currentContent.split('\n');
121
+ let lineIndex = 0;
122
+ let i = 0;
123
+ // Skip header lines
124
+ while (i < lines.length && !lines[i].startsWith('@@')) {
125
+ i++;
126
+ }
127
+ while (i < lines.length) {
128
+ const line = lines[i];
129
+ if (line.startsWith('@@')) {
130
+ // Parse hunk header: @@ -start,count +start,count @@
131
+ const match = line.match(/@@ -(\d+),?\d* \+(\d+),?\d* @@/);
132
+ if (match) {
133
+ lineIndex = parseInt(match[2], 10) - 1;
134
+ }
135
+ i++;
136
+ continue;
137
+ }
138
+ if (line.startsWith('+')) {
139
+ // This was an addition - remove it to reverse
140
+ if (lineIndex < resultLines.length && resultLines[lineIndex] === line.slice(1)) {
141
+ resultLines.splice(lineIndex, 1);
142
+ }
143
+ i++;
144
+ continue;
145
+ }
146
+ if (line.startsWith('-')) {
147
+ // This was a removal - add it back to reverse
148
+ resultLines.splice(lineIndex, 0, line.slice(1));
149
+ lineIndex++;
150
+ i++;
151
+ continue;
152
+ }
153
+ if (line.startsWith(' ')) {
154
+ // Context line
155
+ lineIndex++;
156
+ i++;
157
+ continue;
158
+ }
159
+ i++;
160
+ }
161
+ return resultLines.join('\n');
162
+ }
163
+ // =============================================================================
164
+ // FILE CHANGE TRACKER
165
+ // =============================================================================
166
+ /**
167
+ * Tracks file changes for undo capability.
168
+ */
169
+ export class FileChangeTracker {
170
+ db;
171
+ sessionId;
172
+ config;
173
+ stmts;
174
+ constructor(db, sessionId, config) {
175
+ this.db = db;
176
+ this.sessionId = sessionId;
177
+ this.config = {
178
+ enabled: config?.enabled ?? true,
179
+ maxFullContentBytes: config?.maxFullContentBytes ?? 50 * 1024, // 50KB
180
+ };
181
+ this.prepareStatements();
182
+ }
183
+ /**
184
+ * Prepare SQL statements for reuse.
185
+ */
186
+ prepareStatements() {
187
+ this.stmts = {
188
+ insertChange: this.db.prepare(`
189
+ INSERT INTO file_changes (
190
+ session_id, entry_id, tool_call_id, turn_number, file_path,
191
+ operation, content_before, content_after, diff_unified,
192
+ storage_mode, bytes_before, bytes_after, is_undone,
193
+ undo_change_id, created_at
194
+ )
195
+ VALUES (
196
+ @sessionId, @entryId, @toolCallId, @turnNumber, @filePath,
197
+ @operation, @contentBefore, @contentAfter, @diffUnified,
198
+ @storageMode, @bytesBefore, @bytesAfter, @isUndone,
199
+ @undoChangeId, @createdAt
200
+ )
201
+ `),
202
+ getChange: this.db.prepare(`
203
+ SELECT
204
+ id, session_id as sessionId, turn_number as turnNumber,
205
+ file_path as filePath, operation, content_before as contentBefore,
206
+ content_after as contentAfter, diff_unified as diffUnified,
207
+ storage_mode as storageMode, bytes_before as bytesBefore,
208
+ bytes_after as bytesAfter, is_undone as isUndone,
209
+ undo_change_id as undoChangeId, tool_call_id as toolCallId,
210
+ created_at as createdAt
211
+ FROM file_changes
212
+ WHERE id = ? AND session_id = ?
213
+ `),
214
+ getChanges: this.db.prepare(`
215
+ SELECT
216
+ id, session_id as sessionId, turn_number as turnNumber,
217
+ file_path as filePath, operation, content_before as contentBefore,
218
+ content_after as contentAfter, diff_unified as diffUnified,
219
+ storage_mode as storageMode, bytes_before as bytesBefore,
220
+ bytes_after as bytesAfter, is_undone as isUndone,
221
+ undo_change_id as undoChangeId, tool_call_id as toolCallId,
222
+ created_at as createdAt
223
+ FROM file_changes
224
+ WHERE session_id = ?
225
+ ORDER BY id ASC
226
+ `),
227
+ getFileChanges: this.db.prepare(`
228
+ SELECT
229
+ id, session_id as sessionId, turn_number as turnNumber,
230
+ file_path as filePath, operation, content_before as contentBefore,
231
+ content_after as contentAfter, diff_unified as diffUnified,
232
+ storage_mode as storageMode, bytes_before as bytesBefore,
233
+ bytes_after as bytesAfter, is_undone as isUndone,
234
+ undo_change_id as undoChangeId, tool_call_id as toolCallId,
235
+ created_at as createdAt
236
+ FROM file_changes
237
+ WHERE session_id = ? AND file_path = ?
238
+ ORDER BY id ASC
239
+ `),
240
+ getLastFileChange: this.db.prepare(`
241
+ SELECT
242
+ id, session_id as sessionId, turn_number as turnNumber,
243
+ file_path as filePath, operation, content_before as contentBefore,
244
+ content_after as contentAfter, diff_unified as diffUnified,
245
+ storage_mode as storageMode, bytes_before as bytesBefore,
246
+ bytes_after as bytesAfter, is_undone as isUndone,
247
+ undo_change_id as undoChangeId, tool_call_id as toolCallId,
248
+ created_at as createdAt
249
+ FROM file_changes
250
+ WHERE session_id = ? AND file_path = ? AND is_undone = 0
251
+ ORDER BY id DESC
252
+ LIMIT 1
253
+ `),
254
+ getTurnChanges: this.db.prepare(`
255
+ SELECT
256
+ id, session_id as sessionId, turn_number as turnNumber,
257
+ file_path as filePath, operation, content_before as contentBefore,
258
+ content_after as contentAfter, diff_unified as diffUnified,
259
+ storage_mode as storageMode, bytes_before as bytesBefore,
260
+ bytes_after as bytesAfter, is_undone as isUndone,
261
+ undo_change_id as undoChangeId, tool_call_id as toolCallId,
262
+ created_at as createdAt
263
+ FROM file_changes
264
+ WHERE session_id = ? AND turn_number = ? AND is_undone = 0
265
+ ORDER BY id DESC
266
+ `),
267
+ markUndone: this.db.prepare(`
268
+ UPDATE file_changes
269
+ SET is_undone = 1, undo_change_id = ?
270
+ WHERE id = ? AND session_id = ?
271
+ `),
272
+ getSessionSummary: this.db.prepare(`
273
+ SELECT
274
+ COUNT(*) as totalChanges,
275
+ SUM(CASE WHEN is_undone = 0 THEN 1 ELSE 0 END) as activeChanges,
276
+ SUM(CASE WHEN is_undone = 1 THEN 1 ELSE 0 END) as undoneChanges,
277
+ SUM(CASE WHEN operation = 'create' AND is_undone = 0 THEN 1 ELSE 0 END) as createCount,
278
+ SUM(CASE WHEN operation = 'write' AND is_undone = 0 THEN 1 ELSE 0 END) as writeCount,
279
+ SUM(CASE WHEN operation = 'edit' AND is_undone = 0 THEN 1 ELSE 0 END) as editCount,
280
+ SUM(CASE WHEN operation = 'delete' AND is_undone = 0 THEN 1 ELSE 0 END) as deleteCount
281
+ FROM file_changes
282
+ WHERE session_id = ?
283
+ `),
284
+ };
285
+ }
286
+ /**
287
+ * Record a file change.
288
+ */
289
+ async recordChange(params) {
290
+ if (!this.config.enabled) {
291
+ return -1;
292
+ }
293
+ const now = new Date().toISOString();
294
+ const contentBefore = params.contentBefore ?? null;
295
+ const contentAfter = params.contentAfter ?? null;
296
+ const bytesBefore = contentBefore ? Buffer.byteLength(contentBefore, 'utf-8') : 0;
297
+ const bytesAfter = contentAfter ? Buffer.byteLength(contentAfter, 'utf-8') : 0;
298
+ // Determine storage mode
299
+ let storageMode = 'full';
300
+ let diffUnified = null;
301
+ let storedBefore = contentBefore;
302
+ let storedAfter = contentAfter;
303
+ // Use diff mode for large files
304
+ const totalBytes = bytesBefore + bytesAfter;
305
+ if (totalBytes > this.config.maxFullContentBytes && contentBefore && contentAfter) {
306
+ storageMode = 'diff';
307
+ diffUnified = generateUnifiedDiff(contentBefore, contentAfter, params.filePath);
308
+ // In diff mode, we only store the after content (current state) and the diff
309
+ // to reconstruct the before content
310
+ storedBefore = null;
311
+ storedAfter = contentAfter;
312
+ }
313
+ const result = this.stmts.insertChange.run({
314
+ sessionId: this.sessionId,
315
+ entryId: null,
316
+ toolCallId: params.toolCallId ?? null,
317
+ turnNumber: params.turnNumber,
318
+ filePath: params.filePath,
319
+ operation: params.operation,
320
+ contentBefore: storedBefore,
321
+ contentAfter: storedAfter,
322
+ diffUnified,
323
+ storageMode,
324
+ bytesBefore,
325
+ bytesAfter,
326
+ isUndone: 0,
327
+ undoChangeId: null,
328
+ createdAt: now,
329
+ });
330
+ return result.lastInsertRowid;
331
+ }
332
+ /**
333
+ * Undo a specific change by ID.
334
+ */
335
+ async undoChange(changeId) {
336
+ const row = this.stmts.getChange.get(changeId, this.sessionId);
337
+ if (!row) {
338
+ return {
339
+ success: false,
340
+ filePath: '',
341
+ message: `Change ${changeId} not found`,
342
+ };
343
+ }
344
+ if (row.isUndone) {
345
+ return {
346
+ success: false,
347
+ filePath: row.filePath,
348
+ message: `Change ${changeId} has already been undone`,
349
+ };
350
+ }
351
+ const filePath = row.filePath;
352
+ try {
353
+ // Determine what content to restore
354
+ let contentToRestore = null;
355
+ if (row.storageMode === 'full') {
356
+ contentToRestore = row.contentBefore;
357
+ }
358
+ else if (row.storageMode === 'diff' && row.diffUnified && row.contentAfter) {
359
+ // Reconstruct the before content from the diff
360
+ contentToRestore = applyReverseDiff(row.contentAfter, row.diffUnified);
361
+ }
362
+ // Perform the undo based on operation type
363
+ switch (row.operation) {
364
+ case 'create':
365
+ // Undo create = delete the file
366
+ if (existsSync(filePath)) {
367
+ await unlink(filePath);
368
+ }
369
+ break;
370
+ case 'write':
371
+ case 'edit':
372
+ // Undo write/edit = restore previous content
373
+ if (contentToRestore !== null) {
374
+ await writeFile(filePath, contentToRestore, 'utf-8');
375
+ }
376
+ else if (row.operation === 'write') {
377
+ // If no previous content for a write, delete the file
378
+ if (existsSync(filePath)) {
379
+ await unlink(filePath);
380
+ }
381
+ }
382
+ break;
383
+ case 'delete':
384
+ // Undo delete = recreate the file with original content
385
+ if (contentToRestore !== null) {
386
+ await writeFile(filePath, contentToRestore, 'utf-8');
387
+ }
388
+ break;
389
+ }
390
+ // Mark as undone (no undo change id since this isn't creating a new change record)
391
+ this.stmts.markUndone.run(null, changeId, this.sessionId);
392
+ return {
393
+ success: true,
394
+ filePath,
395
+ message: `Successfully undid ${row.operation} on ${filePath}`,
396
+ changeId,
397
+ };
398
+ }
399
+ catch (error) {
400
+ return {
401
+ success: false,
402
+ filePath,
403
+ message: `Failed to undo change: ${error instanceof Error ? error.message : String(error)}`,
404
+ changeId,
405
+ };
406
+ }
407
+ }
408
+ /**
409
+ * Undo the last change to a specific file.
410
+ */
411
+ async undoLastChange(filePath) {
412
+ const row = this.stmts.getLastFileChange.get(this.sessionId, filePath);
413
+ if (!row) {
414
+ return {
415
+ success: false,
416
+ filePath,
417
+ message: `No undoable changes found for ${filePath}`,
418
+ };
419
+ }
420
+ return this.undoChange(row.id);
421
+ }
422
+ /**
423
+ * Undo all changes in a turn.
424
+ */
425
+ async undoTurn(turnNumber) {
426
+ const rows = this.stmts.getTurnChanges.all(this.sessionId, turnNumber);
427
+ const results = [];
428
+ // Undo in reverse order (last change first)
429
+ for (const row of rows) {
430
+ const result = await this.undoChange(row.id);
431
+ results.push(result);
432
+ }
433
+ return results;
434
+ }
435
+ /**
436
+ * Get all changes for a file.
437
+ */
438
+ getFileHistory(filePath) {
439
+ const rows = this.stmts.getFileChanges.all(this.sessionId, filePath);
440
+ return rows.map(row => ({
441
+ id: row.id,
442
+ sessionId: row.sessionId,
443
+ turnNumber: row.turnNumber,
444
+ filePath: row.filePath,
445
+ operation: row.operation,
446
+ contentBefore: row.contentBefore,
447
+ contentAfter: row.contentAfter,
448
+ diffUnified: row.diffUnified,
449
+ storageMode: row.storageMode,
450
+ bytesBefore: row.bytesBefore,
451
+ bytesAfter: row.bytesAfter,
452
+ isUndone: row.isUndone === 1,
453
+ undoChangeId: row.undoChangeId,
454
+ toolCallId: row.toolCallId,
455
+ createdAt: row.createdAt,
456
+ }));
457
+ }
458
+ /**
459
+ * Get all changes in session.
460
+ */
461
+ getChanges(options) {
462
+ if (options?.filePath) {
463
+ return this.getFileHistory(options.filePath);
464
+ }
465
+ const rows = this.stmts.getChanges.all(this.sessionId);
466
+ return rows.map(row => ({
467
+ id: row.id,
468
+ sessionId: row.sessionId,
469
+ turnNumber: row.turnNumber,
470
+ filePath: row.filePath,
471
+ operation: row.operation,
472
+ contentBefore: row.contentBefore,
473
+ contentAfter: row.contentAfter,
474
+ diffUnified: row.diffUnified,
475
+ storageMode: row.storageMode,
476
+ bytesBefore: row.bytesBefore,
477
+ bytesAfter: row.bytesAfter,
478
+ isUndone: row.isUndone === 1,
479
+ undoChangeId: row.undoChangeId,
480
+ toolCallId: row.toolCallId,
481
+ createdAt: row.createdAt,
482
+ }));
483
+ }
484
+ /**
485
+ * Get session change summary.
486
+ */
487
+ getSessionChangeSummary() {
488
+ const row = this.stmts.getSessionSummary.get(this.sessionId);
489
+ // Get unique file paths from active changes
490
+ const changes = this.getChanges();
491
+ const activeFiles = new Set();
492
+ for (const change of changes) {
493
+ if (!change.isUndone) {
494
+ activeFiles.add(change.filePath);
495
+ }
496
+ }
497
+ return {
498
+ totalChanges: row.totalChanges || 0,
499
+ activeChanges: row.activeChanges || 0,
500
+ undoneChanges: row.undoneChanges || 0,
501
+ filesModified: Array.from(activeFiles),
502
+ byOperation: {
503
+ create: row.createCount || 0,
504
+ write: row.writeCount || 0,
505
+ edit: row.editCount || 0,
506
+ delete: row.deleteCount || 0,
507
+ },
508
+ };
509
+ }
510
+ }
511
+ // =============================================================================
512
+ // FACTORY
513
+ // =============================================================================
514
+ /**
515
+ * Create a FileChangeTracker instance.
516
+ */
517
+ export function createFileChangeTracker(db, sessionId, config) {
518
+ return new FileChangeTracker(db, sessionId, config);
519
+ }
520
+ //# sourceMappingURL=file-change-tracker.js.map