@tomsun28/pizza 0.0.9 → 0.1.1

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 (382) hide show
  1. package/README.md +20 -143
  2. package/README.zh-CN.md +36 -0
  3. package/dist/bun/cli.d.ts +2 -0
  4. package/dist/bun/cli.js +6 -0
  5. package/dist/bun/register-bedrock.d.ts +1 -0
  6. package/dist/bun/register-bedrock.js +3 -0
  7. package/dist/cli/args.d.ts +48 -0
  8. package/dist/cli/args.js +330 -0
  9. package/dist/cli/config-selector.d.ts +13 -0
  10. package/dist/cli/config-selector.js +30 -0
  11. package/dist/cli/file-processor.d.ts +14 -0
  12. package/dist/cli/file-processor.js +82 -0
  13. package/dist/cli/initial-message.d.ts +17 -0
  14. package/dist/cli/initial-message.js +21 -0
  15. package/dist/cli/list-models.d.ts +8 -0
  16. package/dist/cli/list-models.js +96 -0
  17. package/dist/cli.d.ts +2 -0
  18. package/dist/cli.js +68 -0
  19. package/dist/config.d.ts +79 -0
  20. package/dist/config.js +223 -0
  21. package/dist/core/agent/index.d.ts +6 -0
  22. package/dist/core/agent/index.js +6 -0
  23. package/dist/core/agent/types.d.ts +202 -0
  24. package/dist/core/agent/types.js +51 -0
  25. package/dist/core/auth-storage.d.ts +135 -0
  26. package/dist/core/auth-storage.js +417 -0
  27. package/dist/core/bash-executor.d.ts +31 -0
  28. package/dist/core/bash-executor.js +107 -0
  29. package/dist/core/compaction/branch-summarization.d.ts +87 -0
  30. package/dist/core/compaction/branch-summarization.js +242 -0
  31. package/dist/core/compaction/compaction-engine.d.ts +40 -0
  32. package/dist/core/compaction/compaction-engine.js +292 -0
  33. package/dist/core/compaction/compaction.d.ts +106 -0
  34. package/dist/core/compaction/compaction.js +295 -0
  35. package/dist/core/compaction/index.d.ts +7 -0
  36. package/dist/core/compaction/index.js +7 -0
  37. package/dist/core/compaction/utils.d.ts +37 -0
  38. package/dist/core/compaction/utils.js +152 -0
  39. package/dist/core/defaults.d.ts +2 -0
  40. package/dist/core/defaults.js +1 -0
  41. package/dist/core/diagnostics.d.ts +14 -0
  42. package/dist/core/diagnostics.js +1 -0
  43. package/dist/core/event-bus.d.ts +8 -0
  44. package/dist/core/event-bus.js +24 -0
  45. package/dist/core/event-store/events.d.ts +465 -0
  46. package/dist/core/event-store/events.js +6 -0
  47. package/dist/core/event-store/index.d.ts +10 -0
  48. package/dist/core/event-store/index.js +10 -0
  49. package/dist/core/event-store/sqlite-store.d.ts +27 -0
  50. package/dist/core/event-store/sqlite-store.js +275 -0
  51. package/dist/core/event-store/store.d.ts +91 -0
  52. package/dist/core/event-store/store.js +7 -0
  53. package/dist/core/event-store/thread-scoped-store.d.ts +29 -0
  54. package/dist/core/event-store/thread-scoped-store.js +50 -0
  55. package/dist/core/event-store/types.d.ts +70 -0
  56. package/dist/core/event-store/types.js +7 -0
  57. package/dist/core/event-store/workspace.d.ts +37 -0
  58. package/dist/core/event-store/workspace.js +71 -0
  59. package/dist/core/exec.d.ts +28 -0
  60. package/dist/core/exec.js +74 -0
  61. package/dist/core/export-html/ansi-to-html.d.ts +21 -0
  62. package/dist/core/export-html/ansi-to-html.js +248 -0
  63. package/dist/core/export-html/index.d.ts +29 -0
  64. package/dist/core/export-html/index.js +186 -0
  65. package/dist/core/export-html/template.css +1017 -0
  66. package/dist/core/export-html/template.html +55 -0
  67. package/dist/core/export-html/template.js +1742 -0
  68. package/dist/core/export-html/tool-renderer.d.ts +39 -0
  69. package/dist/core/export-html/tool-renderer.js +94 -0
  70. package/dist/core/export-html/vendor/highlight.min.js +1213 -0
  71. package/dist/core/export-html/vendor/marked.min.js +6 -0
  72. package/dist/core/extensions/index.d.ts +12 -0
  73. package/dist/core/extensions/index.js +9 -0
  74. package/dist/core/extensions/loader.d.ts +24 -0
  75. package/dist/core/extensions/loader.js +492 -0
  76. package/dist/core/extensions/runner.d.ts +167 -0
  77. package/dist/core/extensions/runner.js +898 -0
  78. package/dist/core/extensions/session-context.d.ts +67 -0
  79. package/dist/core/extensions/session-context.js +272 -0
  80. package/dist/core/extensions/types.d.ts +1147 -0
  81. package/dist/core/extensions/types.js +44 -0
  82. package/dist/core/extensions/wrapper.d.ts +19 -0
  83. package/dist/core/extensions/wrapper.js +21 -0
  84. package/dist/core/footer-data-provider.d.ts +47 -0
  85. package/dist/core/footer-data-provider.js +321 -0
  86. package/dist/core/goal/index.d.ts +3 -0
  87. package/dist/core/goal/index.js +1 -0
  88. package/dist/core/goal/scheduler.d.ts +83 -0
  89. package/dist/core/goal/scheduler.js +154 -0
  90. package/dist/core/goal/types.d.ts +182 -0
  91. package/dist/core/goal/types.js +11 -0
  92. package/dist/core/index.d.ts +8 -0
  93. package/dist/core/index.js +8 -0
  94. package/dist/core/intent/classifier.d.ts +53 -0
  95. package/dist/core/intent/classifier.js +353 -0
  96. package/dist/core/intent/index.d.ts +8 -0
  97. package/dist/core/intent/index.js +8 -0
  98. package/dist/core/intent/tool-adapter.d.ts +31 -0
  99. package/dist/core/intent/tool-adapter.js +168 -0
  100. package/dist/core/intent/types.d.ts +71 -0
  101. package/dist/core/intent/types.js +6 -0
  102. package/dist/core/keybindings.d.ts +297 -0
  103. package/dist/core/keybindings.js +250 -0
  104. package/dist/core/messages.d.ts +30 -0
  105. package/dist/core/messages.js +134 -0
  106. package/dist/core/model-registry.d.ts +131 -0
  107. package/dist/core/model-registry.js +634 -0
  108. package/dist/core/model-resolver.d.ts +109 -0
  109. package/dist/core/model-resolver.js +486 -0
  110. package/dist/core/output-guard.d.ts +5 -0
  111. package/dist/core/output-guard.js +58 -0
  112. package/dist/core/package-manager.d.ts +196 -0
  113. package/dist/core/package-manager.js +1873 -0
  114. package/dist/core/projection/boundary-inferrer.d.ts +58 -0
  115. package/dist/core/projection/boundary-inferrer.js +122 -0
  116. package/dist/core/projection/event-to-message.d.ts +35 -0
  117. package/dist/core/projection/event-to-message.js +253 -0
  118. package/dist/core/projection/goal-projection.d.ts +67 -0
  119. package/dist/core/projection/goal-projection.js +339 -0
  120. package/dist/core/projection/index.d.ts +13 -0
  121. package/dist/core/projection/index.js +13 -0
  122. package/dist/core/projection/session-manager.d.ts +100 -0
  123. package/dist/core/projection/session-manager.js +331 -0
  124. package/dist/core/projection/session-projection.d.ts +58 -0
  125. package/dist/core/projection/session-projection.js +257 -0
  126. package/dist/core/projection/task-history.d.ts +13 -0
  127. package/dist/core/projection/task-history.js +61 -0
  128. package/dist/core/projection/timeline-projection.d.ts +82 -0
  129. package/dist/core/projection/timeline-projection.js +276 -0
  130. package/dist/core/projection/types.d.ts +69 -0
  131. package/dist/core/projection/types.js +6 -0
  132. package/dist/core/prompt-templates.d.ts +51 -0
  133. package/dist/core/prompt-templates.js +249 -0
  134. package/dist/core/resolve-config-value.d.ts +22 -0
  135. package/dist/core/resolve-config-value.js +125 -0
  136. package/dist/core/resource-loader.d.ts +193 -0
  137. package/dist/core/resource-loader.js +685 -0
  138. package/dist/core/runtime/ai-client.d.ts +12 -0
  139. package/dist/core/runtime/ai-client.js +153 -0
  140. package/dist/core/runtime/checkpoint.d.ts +12 -0
  141. package/dist/core/runtime/checkpoint.js +78 -0
  142. package/dist/core/runtime/index.d.ts +12 -0
  143. package/dist/core/runtime/index.js +12 -0
  144. package/dist/core/runtime/llm-types.d.ts +99 -0
  145. package/dist/core/runtime/llm-types.js +6 -0
  146. package/dist/core/runtime/local-runtime.d.ts +23 -0
  147. package/dist/core/runtime/local-runtime.js +59 -0
  148. package/dist/core/runtime/policies.d.ts +72 -0
  149. package/dist/core/runtime/policies.js +37 -0
  150. package/dist/core/runtime/reactor.d.ts +213 -0
  151. package/dist/core/runtime/reactor.js +992 -0
  152. package/dist/core/runtime/runtime.d.ts +191 -0
  153. package/dist/core/runtime/runtime.js +449 -0
  154. package/dist/core/runtime/types.d.ts +42 -0
  155. package/dist/core/runtime/types.js +1 -0
  156. package/dist/core/sdk.d.ts +12 -0
  157. package/dist/core/sdk.js +10 -0
  158. package/dist/core/session-context-builder.d.ts +9 -0
  159. package/dist/core/session-context-builder.js +87 -0
  160. package/dist/core/session-cwd.d.ts +18 -0
  161. package/dist/core/session-cwd.js +36 -0
  162. package/dist/core/session-facade-factory.d.ts +79 -0
  163. package/dist/core/session-facade-factory.js +460 -0
  164. package/dist/core/session-facade.d.ts +57 -0
  165. package/dist/core/session-facade.js +91 -0
  166. package/dist/core/session-listing.d.ts +30 -0
  167. package/dist/core/session-listing.js +168 -0
  168. package/dist/core/session-reader.d.ts +19 -0
  169. package/dist/core/session-reader.js +101 -0
  170. package/dist/core/session-ref.d.ts +7 -0
  171. package/dist/core/session-ref.js +25 -0
  172. package/dist/core/session-services.d.ts +51 -0
  173. package/dist/core/session-services.js +90 -0
  174. package/dist/core/session-stats.d.ts +43 -0
  175. package/dist/core/session-stats.js +41 -0
  176. package/dist/core/settings-manager.d.ts +236 -0
  177. package/dist/core/settings-manager.js +706 -0
  178. package/dist/core/skill-block-parser.d.ts +12 -0
  179. package/dist/core/skill-block-parser.js +15 -0
  180. package/dist/core/skills.d.ts +59 -0
  181. package/dist/core/skills.js +408 -0
  182. package/dist/core/slash-commands.d.ts +13 -0
  183. package/dist/core/slash-commands.js +17 -0
  184. package/dist/core/source-info.d.ts +17 -0
  185. package/dist/core/source-info.js +18 -0
  186. package/dist/core/system-prompt.d.ts +27 -0
  187. package/dist/core/system-prompt.js +179 -0
  188. package/dist/core/timings.d.ts +7 -0
  189. package/dist/core/timings.js +30 -0
  190. package/dist/core/tools/bash.d.ts +95 -0
  191. package/dist/core/tools/bash.js +513 -0
  192. package/dist/core/tools/builtin-commands.d.ts +75 -0
  193. package/dist/core/tools/builtin-commands.js +503 -0
  194. package/dist/core/tools/compat-commands.d.ts +12 -0
  195. package/dist/core/tools/compat-commands.js +1280 -0
  196. package/dist/core/tools/edit-diff.d.ts +59 -0
  197. package/dist/core/tools/edit-diff.js +263 -0
  198. package/dist/core/tools/edit.d.ts +49 -0
  199. package/dist/core/tools/edit.js +340 -0
  200. package/dist/core/tools/file-mutation-queue.d.ts +5 -0
  201. package/dist/core/tools/file-mutation-queue.js +36 -0
  202. package/dist/core/tools/find.d.ts +34 -0
  203. package/dist/core/tools/find.js +459 -0
  204. package/dist/core/tools/grep.d.ts +36 -0
  205. package/dist/core/tools/grep.js +422 -0
  206. package/dist/core/tools/index.d.ts +70 -0
  207. package/dist/core/tools/index.js +129 -0
  208. package/dist/core/tools/line-anchors.d.ts +33 -0
  209. package/dist/core/tools/line-anchors.js +151 -0
  210. package/dist/core/tools/ls.d.ts +36 -0
  211. package/dist/core/tools/ls.js +268 -0
  212. package/dist/core/tools/path-utils.d.ts +7 -0
  213. package/dist/core/tools/path-utils.js +80 -0
  214. package/dist/core/tools/read.d.ts +35 -0
  215. package/dist/core/tools/read.js +244 -0
  216. package/dist/core/tools/render-utils.d.ts +20 -0
  217. package/dist/core/tools/render-utils.js +48 -0
  218. package/dist/core/tools/session-split.d.ts +9 -0
  219. package/dist/core/tools/session-split.js +77 -0
  220. package/dist/core/tools/tool-definition-wrapper.d.ts +13 -0
  221. package/dist/core/tools/tool-definition-wrapper.js +32 -0
  222. package/dist/core/tools/truncate.d.ts +69 -0
  223. package/dist/core/tools/truncate.js +204 -0
  224. package/dist/core/tools/write.d.ts +25 -0
  225. package/dist/core/tools/write.js +211 -0
  226. package/dist/core/types/session-types.d.ts +123 -0
  227. package/dist/core/types/session-types.js +8 -0
  228. package/dist/index.d.ts +27 -0
  229. package/dist/index.js +38 -0
  230. package/dist/main.d.ts +11 -2
  231. package/dist/main.js +577 -149
  232. package/dist/modes/event-mapper.d.ts +115 -0
  233. package/dist/modes/event-mapper.js +200 -0
  234. package/dist/modes/gui/server.d.ts +14 -0
  235. package/dist/modes/gui/server.js +1032 -0
  236. package/dist/modes/index.d.ts +10 -0
  237. package/dist/modes/index.js +9 -0
  238. package/dist/modes/interactive/assets/clankolas.png +0 -0
  239. package/dist/modes/interactive/components/armin.d.ts +33 -0
  240. package/dist/modes/interactive/components/armin.js +328 -0
  241. package/dist/modes/interactive/components/assistant-message.d.ts +19 -0
  242. package/dist/modes/interactive/components/assistant-message.js +115 -0
  243. package/dist/modes/interactive/components/bash-execution.d.ts +33 -0
  244. package/dist/modes/interactive/components/bash-execution.js +169 -0
  245. package/dist/modes/interactive/components/bordered-loader.d.ts +15 -0
  246. package/dist/modes/interactive/components/bordered-loader.js +50 -0
  247. package/dist/modes/interactive/components/branch-summary-message.d.ts +15 -0
  248. package/dist/modes/interactive/components/branch-summary-message.js +41 -0
  249. package/dist/modes/interactive/components/brand-header.d.ts +33 -0
  250. package/dist/modes/interactive/components/brand-header.js +235 -0
  251. package/dist/modes/interactive/components/compaction-summary-message.d.ts +15 -0
  252. package/dist/modes/interactive/components/compaction-summary-message.js +42 -0
  253. package/dist/modes/interactive/components/config-selector.d.ts +70 -0
  254. package/dist/modes/interactive/components/config-selector.js +469 -0
  255. package/dist/modes/interactive/components/countdown-timer.d.ts +13 -0
  256. package/dist/modes/interactive/components/countdown-timer.js +27 -0
  257. package/dist/modes/interactive/components/custom-editor.d.ts +27 -0
  258. package/dist/modes/interactive/components/custom-editor.js +94 -0
  259. package/dist/modes/interactive/components/custom-message.d.ts +19 -0
  260. package/dist/modes/interactive/components/custom-message.js +73 -0
  261. package/dist/modes/interactive/components/daxnuts.d.ts +22 -0
  262. package/dist/modes/interactive/components/daxnuts.js +137 -0
  263. package/dist/modes/interactive/components/diff.d.ts +11 -0
  264. package/dist/modes/interactive/components/diff.js +132 -0
  265. package/dist/modes/interactive/components/dynamic-border.d.ts +14 -0
  266. package/dist/modes/interactive/components/dynamic-border.js +19 -0
  267. package/dist/modes/interactive/components/earendil-announcement.d.ts +4 -0
  268. package/dist/modes/interactive/components/earendil-announcement.js +39 -0
  269. package/dist/modes/interactive/components/extension-editor.d.ts +19 -0
  270. package/dist/modes/interactive/components/extension-editor.js +105 -0
  271. package/dist/modes/interactive/components/extension-input.d.ts +22 -0
  272. package/dist/modes/interactive/components/extension-input.js +54 -0
  273. package/dist/modes/interactive/components/extension-selector.d.ts +23 -0
  274. package/dist/modes/interactive/components/extension-selector.js +70 -0
  275. package/dist/modes/interactive/components/footer.d.ts +55 -0
  276. package/dist/modes/interactive/components/footer.js +207 -0
  277. package/dist/modes/interactive/components/index.d.ts +31 -0
  278. package/dist/modes/interactive/components/index.js +32 -0
  279. package/dist/modes/interactive/components/keybinding-hints.d.ts +7 -0
  280. package/dist/modes/interactive/components/keybinding-hints.js +21 -0
  281. package/dist/modes/interactive/components/login-dialog.d.ts +41 -0
  282. package/dist/modes/interactive/components/login-dialog.js +138 -0
  283. package/dist/modes/interactive/components/model-selector.d.ts +32 -0
  284. package/dist/modes/interactive/components/model-selector.js +209 -0
  285. package/dist/modes/interactive/components/oauth-selector.d.ts +18 -0
  286. package/dist/modes/interactive/components/oauth-selector.js +91 -0
  287. package/dist/modes/interactive/components/settings-selector.d.ts +57 -0
  288. package/dist/modes/interactive/components/settings-selector.js +299 -0
  289. package/dist/modes/interactive/components/show-images-selector.d.ts +9 -0
  290. package/dist/modes/interactive/components/show-images-selector.js +37 -0
  291. package/dist/modes/interactive/components/skill-invocation-message.d.ts +16 -0
  292. package/dist/modes/interactive/components/skill-invocation-message.js +44 -0
  293. package/dist/modes/interactive/components/theme-selector.d.ts +10 -0
  294. package/dist/modes/interactive/components/theme-selector.js +47 -0
  295. package/dist/modes/interactive/components/thinking-selector.d.ts +10 -0
  296. package/dist/modes/interactive/components/thinking-selector.js +50 -0
  297. package/dist/modes/interactive/components/timeline-view.d.ts +31 -0
  298. package/dist/modes/interactive/components/timeline-view.js +81 -0
  299. package/dist/modes/interactive/components/tool-execution.d.ts +64 -0
  300. package/dist/modes/interactive/components/tool-execution.js +305 -0
  301. package/dist/modes/interactive/components/tree-selector.d.ts +88 -0
  302. package/dist/modes/interactive/components/tree-selector.js +1072 -0
  303. package/dist/modes/interactive/components/user-message-selector.d.ts +29 -0
  304. package/dist/modes/interactive/components/user-message-selector.js +110 -0
  305. package/dist/modes/interactive/components/user-message.d.ts +9 -0
  306. package/dist/modes/interactive/components/user-message.js +27 -0
  307. package/dist/modes/interactive/components/visual-truncate.d.ts +23 -0
  308. package/dist/modes/interactive/components/visual-truncate.js +32 -0
  309. package/dist/modes/interactive/interactive-mode.d.ts +394 -0
  310. package/dist/modes/interactive/interactive-mode.js +4116 -0
  311. package/dist/modes/interactive/theme/dark.json +85 -0
  312. package/dist/modes/interactive/theme/light.json +84 -0
  313. package/dist/modes/interactive/theme/theme-schema.json +335 -0
  314. package/dist/modes/interactive/theme/theme.d.ts +80 -0
  315. package/dist/modes/interactive/theme/theme.js +973 -0
  316. package/dist/modes/print-mode.d.ts +27 -0
  317. package/dist/modes/print-mode.js +102 -0
  318. package/dist/modes/rpc/jsonl.d.ts +16 -0
  319. package/dist/modes/rpc/jsonl.js +48 -0
  320. package/dist/modes/rpc/rpc-client.d.ts +219 -0
  321. package/dist/modes/rpc/rpc-client.js +405 -0
  322. package/dist/modes/rpc/rpc-mode.d.ts +19 -0
  323. package/dist/modes/rpc/rpc-mode.js +381 -0
  324. package/dist/modes/rpc/rpc-types.d.ts +406 -0
  325. package/dist/modes/rpc/rpc-types.js +7 -0
  326. package/dist/package-manager-cli.d.ts +3 -0
  327. package/dist/package-manager-cli.js +233 -0
  328. package/dist/utils/changelog.d.ts +20 -0
  329. package/dist/utils/changelog.js +86 -0
  330. package/dist/utils/child-process.d.ts +10 -0
  331. package/dist/utils/child-process.js +77 -0
  332. package/dist/utils/clipboard-image.d.ts +10 -0
  333. package/dist/utils/clipboard-image.js +244 -0
  334. package/dist/utils/clipboard-native.d.ts +7 -0
  335. package/dist/utils/clipboard-native.js +13 -0
  336. package/dist/utils/clipboard.d.ts +1 -0
  337. package/dist/utils/clipboard.js +77 -0
  338. package/dist/utils/exif-orientation.d.ts +4 -0
  339. package/dist/utils/exif-orientation.js +157 -0
  340. package/dist/utils/frontmatter.d.ts +7 -0
  341. package/dist/utils/frontmatter.js +25 -0
  342. package/dist/utils/git.d.ts +25 -0
  343. package/dist/utils/git.js +162 -0
  344. package/dist/utils/image-convert.d.ts +8 -0
  345. package/dist/utils/image-convert.js +38 -0
  346. package/dist/utils/image-resize.d.ts +35 -0
  347. package/dist/utils/image-resize.js +136 -0
  348. package/dist/utils/mime.d.ts +1 -0
  349. package/dist/utils/mime.js +25 -0
  350. package/dist/utils/path-shims.d.ts +1 -0
  351. package/dist/utils/path-shims.js +90 -0
  352. package/dist/utils/paths.d.ts +6 -0
  353. package/dist/utils/paths.js +18 -0
  354. package/dist/utils/photon.d.ts +20 -0
  355. package/dist/utils/photon.js +120 -0
  356. package/dist/utils/shell.d.ts +29 -0
  357. package/dist/utils/shell.js +189 -0
  358. package/dist/utils/sleep.d.ts +4 -0
  359. package/dist/utils/sleep.js +16 -0
  360. package/dist/utils/tools-manager.d.ts +3 -0
  361. package/dist/utils/tools-manager.js +101 -0
  362. package/dist/vendor/bin/darwin-arm64/fd +0 -0
  363. package/dist/vendor/bin/darwin-arm64/rg +0 -0
  364. package/dist/vendor/bin/darwin-x64/fd +0 -0
  365. package/dist/vendor/bin/darwin-x64/rg +0 -0
  366. package/dist/vendor/bin/linux-arm64/fd +0 -0
  367. package/dist/vendor/bin/linux-arm64/rg +0 -0
  368. package/dist/vendor/bin/linux-x64/fd +0 -0
  369. package/dist/vendor/bin/linux-x64/rg +0 -0
  370. package/dist/vendor/bin/win32-arm64/fd.exe +0 -0
  371. package/dist/vendor/bin/win32-arm64/rg.exe +0 -0
  372. package/dist/vendor/bin/win32-x64/fd.exe +0 -0
  373. package/dist/vendor/bin/win32-x64/rg.exe +0 -0
  374. package/package.json +90 -26
  375. package/dist/extension/core.d.ts +0 -69
  376. package/dist/extension/core.js +0 -270
  377. package/dist/extension/core.js.map +0 -1
  378. package/dist/extension/index.d.ts +0 -25
  379. package/dist/extension/index.js +0 -303
  380. package/dist/extension/index.js.map +0 -1
  381. package/dist/main.js.map +0 -1
  382. package/themes/pizza.json +0 -87
@@ -0,0 +1,295 @@
1
+ /**
2
+ * Context compaction for long sessions.
3
+ *
4
+ * Pure functions for compaction logic. The session manager handles I/O,
5
+ * and after compaction the session is reloaded.
6
+ */
7
+ export const DEFAULT_COMPACTION_SETTINGS = {
8
+ enabled: true,
9
+ reserveTokens: 16384,
10
+ keepRecentTokens: 20000,
11
+ };
12
+ // ============================================================================
13
+ // Token calculation
14
+ // ============================================================================
15
+ /**
16
+ * Calculate total context tokens from usage.
17
+ * Uses the native totalTokens field when available, falls back to computing from components.
18
+ */
19
+ export function calculateContextTokens(usage) {
20
+ return usage.totalTokens || usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
21
+ }
22
+ /**
23
+ * Get usage from an assistant message if available.
24
+ * Skips aborted and error messages as they don't have valid usage data.
25
+ */
26
+ function getAssistantUsage(msg) {
27
+ if (msg.role === "assistant" && "usage" in msg) {
28
+ const assistantMsg = msg;
29
+ if (assistantMsg.stopReason !== "aborted" && assistantMsg.stopReason !== "error" && assistantMsg.usage) {
30
+ return assistantMsg.usage;
31
+ }
32
+ }
33
+ return undefined;
34
+ }
35
+ /**
36
+ * Find the last non-aborted assistant message usage from session entries.
37
+ */
38
+ export function getLastAssistantUsage(entries) {
39
+ for (let i = entries.length - 1; i >= 0; i--) {
40
+ const entry = entries[i];
41
+ if (entry.type === "message") {
42
+ const usage = getAssistantUsage(entry.message);
43
+ if (usage)
44
+ return usage;
45
+ }
46
+ }
47
+ return undefined;
48
+ }
49
+ function getLastAssistantUsageInfo(messages) {
50
+ for (let i = messages.length - 1; i >= 0; i--) {
51
+ const usage = getAssistantUsage(messages[i]);
52
+ if (usage)
53
+ return { usage, index: i };
54
+ }
55
+ return undefined;
56
+ }
57
+ /**
58
+ * Estimate context tokens from messages, using the last assistant usage when available.
59
+ * If there are messages after the last usage, estimate their tokens with estimateTokens.
60
+ */
61
+ export function estimateContextTokens(messages) {
62
+ const usageInfo = getLastAssistantUsageInfo(messages);
63
+ if (!usageInfo) {
64
+ let estimated = 0;
65
+ for (const message of messages) {
66
+ estimated += estimateTokens(message);
67
+ }
68
+ return {
69
+ tokens: estimated,
70
+ usageTokens: 0,
71
+ trailingTokens: estimated,
72
+ lastUsageIndex: null,
73
+ };
74
+ }
75
+ const usageTokens = calculateContextTokens(usageInfo.usage);
76
+ let trailingTokens = 0;
77
+ for (let i = usageInfo.index + 1; i < messages.length; i++) {
78
+ trailingTokens += estimateTokens(messages[i]);
79
+ }
80
+ return {
81
+ tokens: usageTokens + trailingTokens,
82
+ usageTokens,
83
+ trailingTokens,
84
+ lastUsageIndex: usageInfo.index,
85
+ };
86
+ }
87
+ /**
88
+ * Check if compaction should trigger based on context usage.
89
+ */
90
+ export function shouldCompact(contextTokens, contextWindow, settings) {
91
+ if (!settings.enabled)
92
+ return false;
93
+ return contextTokens > contextWindow - settings.reserveTokens;
94
+ }
95
+ // ============================================================================
96
+ // Cut point detection
97
+ // ============================================================================
98
+ /**
99
+ * Estimate token count for a message using chars/4 heuristic.
100
+ * This is conservative (overestimates tokens).
101
+ */
102
+ export function estimateTokens(message) {
103
+ let chars = 0;
104
+ switch (message.role) {
105
+ case "user": {
106
+ const content = message.content;
107
+ if (typeof content === "string") {
108
+ chars = content.length;
109
+ }
110
+ else if (Array.isArray(content)) {
111
+ for (const block of content) {
112
+ if (block.type === "text" && block.text) {
113
+ chars += block.text.length;
114
+ }
115
+ }
116
+ }
117
+ return Math.ceil(chars / 4);
118
+ }
119
+ case "assistant": {
120
+ const assistant = message;
121
+ for (const block of assistant.content) {
122
+ if (block.type === "text") {
123
+ chars += block.text.length;
124
+ }
125
+ else if (block.type === "thinking") {
126
+ chars += block.thinking.length;
127
+ }
128
+ else if (block.type === "toolCall") {
129
+ chars += block.name.length + JSON.stringify(block.arguments).length;
130
+ }
131
+ }
132
+ return Math.ceil(chars / 4);
133
+ }
134
+ case "custom":
135
+ case "toolResult": {
136
+ if (typeof message.content === "string") {
137
+ chars = message.content.length;
138
+ }
139
+ else {
140
+ for (const block of message.content) {
141
+ if (block.type === "text" && block.text) {
142
+ chars += block.text.length;
143
+ }
144
+ if (block.type === "image") {
145
+ chars += 4800; // Estimate images as 4000 chars, or 1200 tokens
146
+ }
147
+ }
148
+ }
149
+ return Math.ceil(chars / 4);
150
+ }
151
+ case "bashExecution": {
152
+ chars = message.command.length + message.output.length;
153
+ return Math.ceil(chars / 4);
154
+ }
155
+ case "branchSummary":
156
+ case "compactionSummary": {
157
+ chars = message.summary.length;
158
+ return Math.ceil(chars / 4);
159
+ }
160
+ }
161
+ return 0;
162
+ }
163
+ /**
164
+ * Find valid cut points: indices of user, assistant, custom, or bashExecution messages.
165
+ * Never cut at tool results (they must follow their tool call).
166
+ * When we cut at an assistant message with tool calls, its tool results follow it
167
+ * and will be kept.
168
+ * BashExecutionMessage is treated like a user message (user-initiated context).
169
+ */
170
+ function findValidCutPoints(entries, startIndex, endIndex) {
171
+ const cutPoints = [];
172
+ for (let i = startIndex; i < endIndex; i++) {
173
+ const entry = entries[i];
174
+ switch (entry.type) {
175
+ case "message": {
176
+ const role = entry.message.role;
177
+ switch (role) {
178
+ case "bashExecution":
179
+ case "custom":
180
+ case "branchSummary":
181
+ case "compactionSummary":
182
+ case "user":
183
+ case "assistant":
184
+ cutPoints.push(i);
185
+ break;
186
+ case "toolResult":
187
+ break;
188
+ }
189
+ break;
190
+ }
191
+ case "thinking_level_change":
192
+ case "model_change":
193
+ case "compaction":
194
+ case "branch_summary":
195
+ case "custom":
196
+ case "custom_message":
197
+ case "label":
198
+ case "session_info":
199
+ break;
200
+ }
201
+ // branch_summary and custom_message are user-role messages, valid cut points
202
+ if (entry.type === "branch_summary" || entry.type === "custom_message") {
203
+ cutPoints.push(i);
204
+ }
205
+ }
206
+ return cutPoints;
207
+ }
208
+ /**
209
+ * Find the user message (or bashExecution) that starts the turn containing the given entry index.
210
+ * Returns -1 if no turn start found before the index.
211
+ * BashExecutionMessage is treated like a user message for turn boundaries.
212
+ */
213
+ export function findTurnStartIndex(entries, entryIndex, startIndex) {
214
+ for (let i = entryIndex; i >= startIndex; i--) {
215
+ const entry = entries[i];
216
+ // branch_summary and custom_message are user-role messages, can start a turn
217
+ if (entry.type === "branch_summary" || entry.type === "custom_message") {
218
+ return i;
219
+ }
220
+ if (entry.type === "message") {
221
+ const role = entry.message.role;
222
+ if (role === "user" || role === "bashExecution") {
223
+ return i;
224
+ }
225
+ }
226
+ }
227
+ return -1;
228
+ }
229
+ /**
230
+ * Find the cut point in session entries that keeps approximately `keepRecentTokens`.
231
+ *
232
+ * Algorithm: Walk backwards from newest, accumulating estimated message sizes.
233
+ * Stop when we've accumulated >= keepRecentTokens. Cut at that point.
234
+ *
235
+ * Can cut at user OR assistant messages (never tool results). When cutting at an
236
+ * assistant message with tool calls, its tool results come after and will be kept.
237
+ *
238
+ * Returns CutPointResult with:
239
+ * - firstKeptEntryIndex: the entry index to start keeping from
240
+ * - turnStartIndex: if cutting mid-turn, the user message that started that turn
241
+ * - isSplitTurn: whether we're cutting in the middle of a turn
242
+ *
243
+ * Only considers entries between `startIndex` and `endIndex` (exclusive).
244
+ */
245
+ export function findCutPoint(entries, startIndex, endIndex, keepRecentTokens) {
246
+ const cutPoints = findValidCutPoints(entries, startIndex, endIndex);
247
+ if (cutPoints.length === 0) {
248
+ return { firstKeptEntryIndex: startIndex, turnStartIndex: -1, isSplitTurn: false };
249
+ }
250
+ // Walk backwards from newest, accumulating estimated message sizes
251
+ let accumulatedTokens = 0;
252
+ let cutIndex = cutPoints[0]; // Default: keep from first message (not header)
253
+ for (let i = endIndex - 1; i >= startIndex; i--) {
254
+ const entry = entries[i];
255
+ if (entry.type !== "message")
256
+ continue;
257
+ // Estimate this message's size
258
+ const messageTokens = estimateTokens(entry.message);
259
+ accumulatedTokens += messageTokens;
260
+ // Check if we've exceeded the budget
261
+ if (accumulatedTokens >= keepRecentTokens) {
262
+ // Find the closest valid cut point at or after this entry
263
+ for (let c = 0; c < cutPoints.length; c++) {
264
+ if (cutPoints[c] >= i) {
265
+ cutIndex = cutPoints[c];
266
+ break;
267
+ }
268
+ }
269
+ break;
270
+ }
271
+ }
272
+ // Scan backwards from cutIndex to include any non-message entries (bash, settings, etc.)
273
+ while (cutIndex > startIndex) {
274
+ const prevEntry = entries[cutIndex - 1];
275
+ // Stop at session header or compaction boundaries
276
+ if (prevEntry.type === "compaction") {
277
+ break;
278
+ }
279
+ if (prevEntry.type === "message") {
280
+ // Stop if we hit any message
281
+ break;
282
+ }
283
+ // Include this non-message entry (bash, settings change, etc.)
284
+ cutIndex--;
285
+ }
286
+ // Determine if this is a split turn
287
+ const cutEntry = entries[cutIndex];
288
+ const isUserMessage = cutEntry.type === "message" && cutEntry.message.role === "user";
289
+ const turnStartIndex = isUserMessage ? -1 : findTurnStartIndex(entries, cutIndex, startIndex);
290
+ return {
291
+ firstKeptEntryIndex: cutIndex,
292
+ turnStartIndex,
293
+ isSplitTurn: !isUserMessage && turnStartIndex !== -1,
294
+ };
295
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Compaction and summarization utilities.
3
+ */
4
+ export * from "./branch-summarization.js";
5
+ export * from "./compaction.js";
6
+ export * from "./compaction-engine.js";
7
+ export * from "./utils.js";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Compaction and summarization utilities.
3
+ */
4
+ export * from "./branch-summarization.js";
5
+ export * from "./compaction.js";
6
+ export * from "./compaction-engine.js";
7
+ export * from "./utils.js";
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Shared utilities for compaction and branch summarization.
3
+ */
4
+ import type { AgentMessage } from "../agent/types.js";
5
+ import type { Message } from "@earendil-works/pi-ai/compat";
6
+ export interface FileOperations {
7
+ read: Set<string>;
8
+ written: Set<string>;
9
+ edited: Set<string>;
10
+ }
11
+ export declare function createFileOps(): FileOperations;
12
+ /**
13
+ * Extract file operations from tool calls in an assistant message.
14
+ */
15
+ export declare function extractFileOpsFromMessage(message: AgentMessage, fileOps: FileOperations): void;
16
+ /**
17
+ * Compute final file lists from file operations.
18
+ * Returns readFiles (files only read, not modified) and modifiedFiles.
19
+ */
20
+ export declare function computeFileLists(fileOps: FileOperations): {
21
+ readFiles: string[];
22
+ modifiedFiles: string[];
23
+ };
24
+ /**
25
+ * Format file operations as XML tags for summary.
26
+ */
27
+ export declare function formatFileOperations(readFiles: string[], modifiedFiles: string[]): string;
28
+ /**
29
+ * Serialize LLM messages to text for summarization.
30
+ * This prevents the model from treating it as a conversation to continue.
31
+ * Call convertToLlm() first to handle custom message types.
32
+ *
33
+ * Tool results are truncated to keep the summarization request within
34
+ * reasonable token budgets. Full content is not needed for summarization.
35
+ */
36
+ export declare function serializeConversation(messages: Message[]): string;
37
+ export declare const SUMMARIZATION_SYSTEM_PROMPT = "You are a context summarization assistant. Your task is to read a conversation between a user and an AI coding assistant, then produce a structured summary following the exact format specified.\n\nDo NOT continue the conversation. Do NOT respond to any questions in the conversation. ONLY output the structured summary.";
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Shared utilities for compaction and branch summarization.
3
+ */
4
+ export function createFileOps() {
5
+ return {
6
+ read: new Set(),
7
+ written: new Set(),
8
+ edited: new Set(),
9
+ };
10
+ }
11
+ /**
12
+ * Extract file operations from tool calls in an assistant message.
13
+ */
14
+ export function extractFileOpsFromMessage(message, fileOps) {
15
+ if (message.role !== "assistant")
16
+ return;
17
+ if (!("content" in message) || !Array.isArray(message.content))
18
+ return;
19
+ for (const block of message.content) {
20
+ if (typeof block !== "object" || block === null)
21
+ continue;
22
+ if (!("type" in block) || block.type !== "toolCall")
23
+ continue;
24
+ if (!("arguments" in block) || !("name" in block))
25
+ continue;
26
+ const args = block.arguments;
27
+ if (!args)
28
+ continue;
29
+ const path = typeof args.path === "string" ? args.path : undefined;
30
+ if (!path)
31
+ continue;
32
+ switch (block.name) {
33
+ case "read":
34
+ fileOps.read.add(path);
35
+ break;
36
+ case "write":
37
+ fileOps.written.add(path);
38
+ break;
39
+ case "edit":
40
+ fileOps.edited.add(path);
41
+ break;
42
+ }
43
+ }
44
+ }
45
+ /**
46
+ * Compute final file lists from file operations.
47
+ * Returns readFiles (files only read, not modified) and modifiedFiles.
48
+ */
49
+ export function computeFileLists(fileOps) {
50
+ const modified = new Set([...fileOps.edited, ...fileOps.written]);
51
+ const readOnly = [...fileOps.read].filter((f) => !modified.has(f)).sort();
52
+ const modifiedFiles = [...modified].sort();
53
+ return { readFiles: readOnly, modifiedFiles };
54
+ }
55
+ /**
56
+ * Format file operations as XML tags for summary.
57
+ */
58
+ export function formatFileOperations(readFiles, modifiedFiles) {
59
+ const sections = [];
60
+ if (readFiles.length > 0) {
61
+ sections.push(`<read-files>\n${readFiles.join("\n")}\n</read-files>`);
62
+ }
63
+ if (modifiedFiles.length > 0) {
64
+ sections.push(`<modified-files>\n${modifiedFiles.join("\n")}\n</modified-files>`);
65
+ }
66
+ if (sections.length === 0)
67
+ return "";
68
+ return `\n\n${sections.join("\n\n")}`;
69
+ }
70
+ // ============================================================================
71
+ // Message Serialization
72
+ // ============================================================================
73
+ /** Maximum characters for a tool result in serialized summaries. */
74
+ const TOOL_RESULT_MAX_CHARS = 2000;
75
+ /**
76
+ * Truncate text to a maximum character length for summarization.
77
+ * Keeps the beginning and appends a truncation marker.
78
+ */
79
+ function truncateForSummary(text, maxChars) {
80
+ if (text.length <= maxChars)
81
+ return text;
82
+ const truncatedChars = text.length - maxChars;
83
+ return `${text.slice(0, maxChars)}\n\n[... ${truncatedChars} more characters truncated]`;
84
+ }
85
+ /**
86
+ * Serialize LLM messages to text for summarization.
87
+ * This prevents the model from treating it as a conversation to continue.
88
+ * Call convertToLlm() first to handle custom message types.
89
+ *
90
+ * Tool results are truncated to keep the summarization request within
91
+ * reasonable token budgets. Full content is not needed for summarization.
92
+ */
93
+ export function serializeConversation(messages) {
94
+ const parts = [];
95
+ for (const msg of messages) {
96
+ if (msg.role === "user") {
97
+ const content = typeof msg.content === "string"
98
+ ? msg.content
99
+ : msg.content
100
+ .filter((c) => c.type === "text")
101
+ .map((c) => c.text)
102
+ .join("");
103
+ if (content)
104
+ parts.push(`[User]: ${content}`);
105
+ }
106
+ else if (msg.role === "assistant") {
107
+ const textParts = [];
108
+ const thinkingParts = [];
109
+ const toolCalls = [];
110
+ for (const block of msg.content) {
111
+ if (block.type === "text") {
112
+ textParts.push(block.text);
113
+ }
114
+ else if (block.type === "thinking") {
115
+ thinkingParts.push(block.thinking);
116
+ }
117
+ else if (block.type === "toolCall") {
118
+ const args = block.arguments;
119
+ const argsStr = Object.entries(args)
120
+ .map(([k, v]) => `${k}=${JSON.stringify(v)}`)
121
+ .join(", ");
122
+ toolCalls.push(`${block.name}(${argsStr})`);
123
+ }
124
+ }
125
+ if (thinkingParts.length > 0) {
126
+ parts.push(`[Assistant thinking]: ${thinkingParts.join("\n")}`);
127
+ }
128
+ if (textParts.length > 0) {
129
+ parts.push(`[Assistant]: ${textParts.join("\n")}`);
130
+ }
131
+ if (toolCalls.length > 0) {
132
+ parts.push(`[Assistant tool calls]: ${toolCalls.join("; ")}`);
133
+ }
134
+ }
135
+ else if (msg.role === "toolResult") {
136
+ const content = msg.content
137
+ .filter((c) => c.type === "text")
138
+ .map((c) => c.text)
139
+ .join("");
140
+ if (content) {
141
+ parts.push(`[Tool result]: ${truncateForSummary(content, TOOL_RESULT_MAX_CHARS)}`);
142
+ }
143
+ }
144
+ }
145
+ return parts.join("\n\n");
146
+ }
147
+ // ============================================================================
148
+ // Summarization System Prompt
149
+ // ============================================================================
150
+ export const SUMMARIZATION_SYSTEM_PROMPT = `You are a context summarization assistant. Your task is to read a conversation between a user and an AI coding assistant, then produce a structured summary following the exact format specified.
151
+
152
+ Do NOT continue the conversation. Do NOT respond to any questions in the conversation. ONLY output the structured summary.`;
@@ -0,0 +1,2 @@
1
+ import type { ThinkingLevel } from "./agent/types.js";
2
+ export declare const DEFAULT_THINKING_LEVEL: ThinkingLevel;
@@ -0,0 +1 @@
1
+ export const DEFAULT_THINKING_LEVEL = "medium";
@@ -0,0 +1,14 @@
1
+ export interface ResourceCollision {
2
+ resourceType: "extension" | "skill" | "prompt" | "theme";
3
+ name: string;
4
+ winnerPath: string;
5
+ loserPath: string;
6
+ winnerSource?: string;
7
+ loserSource?: string;
8
+ }
9
+ export interface ResourceDiagnostic {
10
+ type: "warning" | "error" | "collision";
11
+ message: string;
12
+ path?: string;
13
+ collision?: ResourceCollision;
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ export interface EventBus {
2
+ emit(channel: string, data: unknown): void;
3
+ on(channel: string, handler: (data: unknown) => void): () => void;
4
+ }
5
+ export interface EventBusController extends EventBus {
6
+ clear(): void;
7
+ }
8
+ export declare function createEventBus(): EventBusController;
@@ -0,0 +1,24 @@
1
+ import { EventEmitter } from "node:events";
2
+ export function createEventBus() {
3
+ const emitter = new EventEmitter();
4
+ return {
5
+ emit: (channel, data) => {
6
+ emitter.emit(channel, data);
7
+ },
8
+ on: (channel, handler) => {
9
+ const safeHandler = async (data) => {
10
+ try {
11
+ await handler(data);
12
+ }
13
+ catch (err) {
14
+ console.error(`Event handler error (${channel}):`, err);
15
+ }
16
+ };
17
+ emitter.on(channel, safeHandler);
18
+ return () => emitter.off(channel, safeHandler);
19
+ },
20
+ clear: () => {
21
+ emitter.removeAllListeners();
22
+ },
23
+ };
24
+ }