@tomsun28/pizza 0.1.0 → 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 -14
  379. package/dist/extension/index.js +0 -374
  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,353 @@
1
+ /**
2
+ * Intent Classifier
3
+ *
4
+ * Classifies LLM-proposed tool calls by risk level and approval requirements.
5
+ */
6
+ const DEFAULT_CLASSIFIER_CONFIG = {
7
+ require_approval_writes: true,
8
+ require_approval_edits: true,
9
+ require_approval_shell_moderate: false,
10
+ require_approval_unknown: true,
11
+ };
12
+ // ============================================================================
13
+ // Intent Classifier
14
+ // ============================================================================
15
+ /**
16
+ * Classifies tool calls by risk level and approval requirements.
17
+ *
18
+ * Default policy:
19
+ * - file_read, shell_safe: auto-approve
20
+ * - file_write, network, unknown: require approval (configurable)
21
+ * - shell_moderate: auto-approve by default (configurable)
22
+ * - file_delete, shell_dangerous: always require approval
23
+ */
24
+ export class IntentClassifier {
25
+ constructor(config = {}) {
26
+ this.config = resolveClassifierConfig(config);
27
+ }
28
+ /**
29
+ * Classify a tool call by name and arguments.
30
+ */
31
+ classify(toolName, args) {
32
+ // Built-in tool classification
33
+ switch (toolName) {
34
+ case "read":
35
+ case "find":
36
+ case "grep":
37
+ case "ls":
38
+ case "path_utils":
39
+ return {
40
+ risk: "safe",
41
+ requires_approval: false,
42
+ category: "file_read",
43
+ description: `Read ${args.path ?? ""}`,
44
+ };
45
+ case "write":
46
+ return {
47
+ risk: "moderate",
48
+ requires_approval: this.config.require_approval_writes,
49
+ category: "file_write",
50
+ affected_files: [String(args.path)],
51
+ description: `Write to ${args.path}`,
52
+ };
53
+ case "edit":
54
+ case "edit_diff":
55
+ return {
56
+ risk: "moderate",
57
+ requires_approval: this.config.require_approval_edits,
58
+ category: "file_write",
59
+ affected_files: [String(args.path)],
60
+ description: `Edit ${args.path}`,
61
+ };
62
+ case "cli":
63
+ case "bash":
64
+ return this._classifyBashCommand(String(args.command ?? ""));
65
+ case "truncate":
66
+ return {
67
+ risk: "dangerous",
68
+ requires_approval: true,
69
+ category: "file_delete",
70
+ description: `Truncate ${args.path ?? ""}`,
71
+ };
72
+ case "builtin":
73
+ return this._classifyBuiltinCommand(String(args.command ?? ""));
74
+ default:
75
+ return {
76
+ risk: "moderate",
77
+ requires_approval: this.config.require_approval_unknown,
78
+ category: "unknown",
79
+ description: `Execute ${toolName}`,
80
+ };
81
+ }
82
+ }
83
+ /**
84
+ * Classify a bash command by its content.
85
+ */
86
+ _classifyBashCommand(command) {
87
+ const trimmed = command.trim();
88
+ const builtin = parseBuiltinInvocation(trimmed);
89
+ if (builtin) {
90
+ if (builtin.command === "read") {
91
+ return {
92
+ risk: "safe",
93
+ requires_approval: false,
94
+ category: "file_read",
95
+ affected_files: builtin.path ? [builtin.path] : undefined,
96
+ description: `Read ${builtin.path ?? ""}`,
97
+ };
98
+ }
99
+ if (builtin.command === "write") {
100
+ return {
101
+ risk: "moderate",
102
+ requires_approval: this.config.require_approval_writes,
103
+ category: "file_write",
104
+ affected_files: builtin.path ? [builtin.path] : undefined,
105
+ description: `Write to ${builtin.path ?? ""}`,
106
+ };
107
+ }
108
+ if (builtin.command === "edit") {
109
+ return {
110
+ risk: "moderate",
111
+ requires_approval: this.config.require_approval_edits,
112
+ category: "file_write",
113
+ affected_files: builtin.path ? [builtin.path] : undefined,
114
+ description: `Edit ${builtin.path ?? ""}`,
115
+ };
116
+ }
117
+ }
118
+ // Dangerous patterns
119
+ const dangerousPatterns = [
120
+ { pattern: /\brm\s+-[a-z]*r/i, description: "Recursive delete" },
121
+ { pattern: /\brm\s+-[rf]\s+\//i, description: "Delete from root" },
122
+ { pattern: /\bsudo\s+/i, description: "Elevated privileges" },
123
+ { pattern: /\bcurl\b.*\|\s*bash/i, description: "Download and execute" },
124
+ { pattern: /\bwget\b.*\|\s*bash/i, description: "Download and execute" },
125
+ { pattern: /\bchmod\s+777/i, description: "World-writable permissions" },
126
+ { pattern: /\b>\s*\/dev\/(?!null\b)/i, description: "Redirect to device" },
127
+ { pattern: /\n\s*rm\s+/i, description: "Embedded delete command" },
128
+ { pattern: /\bdd\b/i, description: "Direct disk access" },
129
+ { pattern: /\bmkfs\b/i, description: "Filesystem format" },
130
+ ];
131
+ for (const { pattern, description } of dangerousPatterns) {
132
+ if (pattern.test(trimmed)) {
133
+ return {
134
+ risk: "dangerous",
135
+ requires_approval: true,
136
+ category: "shell_dangerous",
137
+ description: `DANGEROUS: ${description}`,
138
+ };
139
+ }
140
+ }
141
+ const redirectedPath = getNonNullRedirectPath(trimmed);
142
+ if (redirectedPath) {
143
+ return {
144
+ risk: "moderate",
145
+ requires_approval: this.config.require_approval_writes,
146
+ category: "file_write",
147
+ affected_files: [redirectedPath],
148
+ description: `Shell redirection to ${redirectedPath}`,
149
+ };
150
+ }
151
+ // Safe patterns
152
+ const safePatterns = [
153
+ /^(echo|cat|pwd|ls|find|grep|head|tail|wc|date|whoami|id|uname)\b/,
154
+ /^git\s+(status|log|diff|branch|show|remote)\b/,
155
+ /^npm\s+(list|config|root)\b/,
156
+ /^yarn\s+(info|list)\b/,
157
+ /^pnpm\s+(list|root)\b/,
158
+ /^docker\s+(ps|images|logs)\b/,
159
+ ];
160
+ if (isSingleSafeShellCommand(trimmed)) {
161
+ for (const pattern of safePatterns) {
162
+ if (!pattern.test(trimmed))
163
+ continue;
164
+ return {
165
+ risk: "safe",
166
+ requires_approval: false,
167
+ category: "shell_safe",
168
+ description: trimmed.length > 50 ? trimmed.slice(0, 50) + "..." : trimmed,
169
+ };
170
+ }
171
+ }
172
+ // Moderate (default for shell)
173
+ return {
174
+ risk: "moderate",
175
+ requires_approval: this.config.require_approval_shell_moderate,
176
+ category: "shell_moderate",
177
+ description: trimmed.length > 50 ? trimmed.slice(0, 50) + "..." : trimmed,
178
+ };
179
+ }
180
+ /**
181
+ * Classify a builtin command.
182
+ */
183
+ _classifyBuiltinCommand(command) {
184
+ const trimmed = command.trim().toLowerCase();
185
+ // Safe builtin commands
186
+ const safeCommands = ["help", "version", "list", "ls", "status"];
187
+ if (safeCommands.includes(trimmed)) {
188
+ return {
189
+ risk: "safe",
190
+ requires_approval: false,
191
+ category: "shell_safe",
192
+ description: `Builtin: ${command}`,
193
+ };
194
+ }
195
+ // Everything else is moderate
196
+ return {
197
+ risk: "moderate",
198
+ requires_approval: false,
199
+ category: "shell_moderate",
200
+ description: `Builtin: ${command}`,
201
+ };
202
+ }
203
+ /**
204
+ * Classify by intent category directly.
205
+ */
206
+ classifyByCategory(category, args) {
207
+ const toolName = String(args.tool_name ?? "unknown");
208
+ switch (category) {
209
+ case "file_read":
210
+ return {
211
+ risk: "safe",
212
+ requires_approval: false,
213
+ category,
214
+ description: `Read ${args.path ?? ""}`,
215
+ };
216
+ case "file_write":
217
+ return {
218
+ risk: "moderate",
219
+ requires_approval: this.config.require_approval_writes,
220
+ category,
221
+ affected_files: [String(args.path)],
222
+ description: `Write to ${args.path}`,
223
+ };
224
+ case "file_delete":
225
+ return {
226
+ risk: "dangerous",
227
+ requires_approval: true,
228
+ category,
229
+ description: `Delete ${args.path ?? ""}`,
230
+ };
231
+ case "shell_safe":
232
+ return {
233
+ risk: "safe",
234
+ requires_approval: false,
235
+ category,
236
+ description: toolName,
237
+ };
238
+ case "shell_moderate":
239
+ return {
240
+ risk: "moderate",
241
+ requires_approval: this.config.require_approval_shell_moderate,
242
+ category,
243
+ description: toolName,
244
+ };
245
+ case "shell_dangerous":
246
+ return {
247
+ risk: "dangerous",
248
+ requires_approval: true,
249
+ category,
250
+ description: `DANGEROUS: ${toolName}`,
251
+ };
252
+ case "network":
253
+ return {
254
+ risk: "moderate",
255
+ requires_approval: this.config.require_approval_unknown,
256
+ category,
257
+ description: `Network: ${args.url ?? toolName}`,
258
+ };
259
+ case "unknown":
260
+ return {
261
+ risk: "moderate",
262
+ requires_approval: this.config.require_approval_unknown,
263
+ category,
264
+ description: toolName,
265
+ };
266
+ }
267
+ }
268
+ }
269
+ function resolveClassifierConfig(config) {
270
+ return {
271
+ require_approval_writes: config.require_approval_writes ?? config.approve_writes ?? DEFAULT_CLASSIFIER_CONFIG.require_approval_writes,
272
+ require_approval_edits: config.require_approval_edits ?? config.approve_edits ?? DEFAULT_CLASSIFIER_CONFIG.require_approval_edits,
273
+ require_approval_shell_moderate: config.require_approval_shell_moderate ??
274
+ config.approve_shell_moderate ??
275
+ DEFAULT_CLASSIFIER_CONFIG.require_approval_shell_moderate,
276
+ require_approval_unknown: config.require_approval_unknown ?? config.approve_unknown ?? DEFAULT_CLASSIFIER_CONFIG.require_approval_unknown,
277
+ };
278
+ }
279
+ function parseBuiltinInvocation(command) {
280
+ const firstLine = command.split("\n", 1)[0]?.trim() ?? "";
281
+ const parts = splitShellWords(firstLine);
282
+ const builtin = parts[0]?.toLowerCase();
283
+ if (builtin !== "read" && builtin !== "write" && builtin !== "edit")
284
+ return undefined;
285
+ let path;
286
+ for (let i = 1; i < parts.length; i++) {
287
+ const arg = parts[i];
288
+ if ((arg === "--path" || arg === "-p") && parts[i + 1]) {
289
+ path = parts[i + 1];
290
+ break;
291
+ }
292
+ if (!arg.startsWith("-") && !path) {
293
+ path = arg;
294
+ break;
295
+ }
296
+ }
297
+ return { command: builtin, path };
298
+ }
299
+ function splitShellWords(input) {
300
+ const words = [];
301
+ let current = "";
302
+ let quote;
303
+ let escaped = false;
304
+ for (const char of input) {
305
+ if (escaped) {
306
+ current += char;
307
+ escaped = false;
308
+ continue;
309
+ }
310
+ if (char === "\\") {
311
+ escaped = true;
312
+ continue;
313
+ }
314
+ if (quote) {
315
+ if (char === quote) {
316
+ quote = undefined;
317
+ }
318
+ else {
319
+ current += char;
320
+ }
321
+ continue;
322
+ }
323
+ if (char === "'" || char === "\"") {
324
+ quote = char;
325
+ continue;
326
+ }
327
+ if (/\s/.test(char)) {
328
+ if (current) {
329
+ words.push(current);
330
+ current = "";
331
+ }
332
+ continue;
333
+ }
334
+ current += char;
335
+ }
336
+ if (current)
337
+ words.push(current);
338
+ return words;
339
+ }
340
+ function getNonNullRedirectPath(command) {
341
+ const matches = command.matchAll(/(?:^|[\s;|&])(?:\d*)>>?\s*(['"]?)([^'"\s;&|]+)\1/g);
342
+ for (const match of matches) {
343
+ const path = match[2];
344
+ if (!path || path === "/dev/null")
345
+ continue;
346
+ return path;
347
+ }
348
+ return undefined;
349
+ }
350
+ function isSingleSafeShellCommand(command) {
351
+ const withoutNullRedirects = command.replace(/\s+\d*>\/dev\/null\b/g, "");
352
+ return !/[|;&<>`$()]/.test(withoutNullRedirects);
353
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Intent Module
3
+ *
4
+ * Handles intent classification and deterministic execution.
5
+ */
6
+ export * from "./types.js";
7
+ export * from "./classifier.js";
8
+ export * from "./tool-adapter.js";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Intent Module
3
+ *
4
+ * Handles intent classification and deterministic execution.
5
+ */
6
+ export * from "./types.js";
7
+ export * from "./classifier.js";
8
+ export * from "./tool-adapter.js";
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Tool Adapter
3
+ *
4
+ * Adapts legacy AgentTool instances to the new ToolExecutor / ToolRegistry
5
+ * interface used by the event-sourced runtime.
6
+ *
7
+ * Key responsibilities:
8
+ * - Convert AgentTool.execute(toolCallId, params, signal, onUpdate) → ToolExecutor.execute(args, options)
9
+ * - Detect file mutations from tool results and populate file_mutations
10
+ * - Build a ToolRegistry from an array of AgentTools
11
+ */
12
+ import type { AgentTool } from "../agent/types.js";
13
+ import type { ToolExecutionOptions, ToolExecutionResult, ToolExecutor, ToolMetadata, ToolRegistry } from "./types.js";
14
+ /**
15
+ * Wraps a legacy AgentTool as a ToolExecutor for the event-sourced runtime.
16
+ */
17
+ export declare class AgentToolAdapter implements ToolExecutor {
18
+ private tool;
19
+ private metadata;
20
+ constructor(tool: AgentTool<any, any>);
21
+ execute(args: Record<string, unknown>, options?: ToolExecutionOptions): Promise<ToolExecutionResult>;
22
+ getMetadata(): ToolMetadata;
23
+ }
24
+ /**
25
+ * Build a ToolRegistry from an array of AgentTool instances.
26
+ *
27
+ * Usage:
28
+ * const tools = createTools(cwd, options);
29
+ * const registry = createToolRegistry(tools);
30
+ */
31
+ export declare function createToolRegistry(tools: AgentTool<any, any>[]): ToolRegistry;
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Tool Adapter
3
+ *
4
+ * Adapts legacy AgentTool instances to the new ToolExecutor / ToolRegistry
5
+ * interface used by the event-sourced runtime.
6
+ *
7
+ * Key responsibilities:
8
+ * - Convert AgentTool.execute(toolCallId, params, signal, onUpdate) → ToolExecutor.execute(args, options)
9
+ * - Detect file mutations from tool results and populate file_mutations
10
+ * - Build a ToolRegistry from an array of AgentTools
11
+ */
12
+ // ============================================================================
13
+ // File Mutation Detection
14
+ // ============================================================================
15
+ /** Tools known to mutate files */
16
+ const FILE_MUTATING_TOOLS = new Set(["edit", "edit_diff", "write", "cli", "bash"]);
17
+ /**
18
+ * Infer file mutations from a tool execution.
19
+ *
20
+ * For write/edit tools, the path is in the arguments.
21
+ * For cli/bash, we cannot reliably detect mutations (best-effort).
22
+ */
23
+ function inferFileMutations(toolName, args, _result) {
24
+ if (!FILE_MUTATING_TOOLS.has(toolName))
25
+ return undefined;
26
+ switch (toolName) {
27
+ case "edit":
28
+ case "edit_diff": {
29
+ const path = args.path;
30
+ if (path)
31
+ return [{ path, operation: "modify" }];
32
+ return undefined;
33
+ }
34
+ case "write": {
35
+ const path = args.path;
36
+ if (path)
37
+ return [{ path, operation: "create" }];
38
+ return undefined;
39
+ }
40
+ case "cli":
41
+ case "bash": {
42
+ const details = _result.details;
43
+ const builtin = details?.builtin;
44
+ if (builtin?.name === "write" && builtin.args.path) {
45
+ return [{ path: builtin.args.path, operation: "create" }];
46
+ }
47
+ if (builtin?.name === "edit" && builtin.args.path) {
48
+ return [{ path: builtin.args.path, operation: "modify" }];
49
+ }
50
+ return undefined;
51
+ }
52
+ default:
53
+ return undefined;
54
+ }
55
+ }
56
+ // ============================================================================
57
+ // Tool Category Mapping
58
+ // ============================================================================
59
+ /** Map AgentTool name to IntentCategory */
60
+ function inferCategory(toolName) {
61
+ switch (toolName) {
62
+ case "read":
63
+ case "find":
64
+ case "grep":
65
+ case "ls":
66
+ case "path_utils":
67
+ return "file_read";
68
+ case "write":
69
+ case "edit":
70
+ case "edit_diff":
71
+ return "file_write";
72
+ case "cli":
73
+ case "bash":
74
+ return "shell_moderate";
75
+ case "truncate":
76
+ return "file_delete";
77
+ default:
78
+ return "unknown";
79
+ }
80
+ }
81
+ /** Map category to default risk */
82
+ function inferRisk(category) {
83
+ switch (category) {
84
+ case "file_read":
85
+ case "shell_safe":
86
+ return "safe";
87
+ case "file_write":
88
+ case "shell_moderate":
89
+ case "network":
90
+ return "moderate";
91
+ case "file_delete":
92
+ case "shell_dangerous":
93
+ case "unknown":
94
+ return "dangerous";
95
+ }
96
+ }
97
+ // ============================================================================
98
+ // ToolExecutor Adapter
99
+ // ============================================================================
100
+ /**
101
+ * Wraps a legacy AgentTool as a ToolExecutor for the event-sourced runtime.
102
+ */
103
+ export class AgentToolAdapter {
104
+ constructor(tool) {
105
+ this.tool = tool;
106
+ const category = inferCategory(tool.name);
107
+ this.metadata = {
108
+ name: tool.name,
109
+ description: tool.description,
110
+ category,
111
+ defaultRisk: inferRisk(category),
112
+ };
113
+ }
114
+ async execute(args, options) {
115
+ const toolCallId = options?.tool_call_id ?? `tc_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
116
+ // Prepare arguments if the tool has a prepareArguments hook
117
+ const prepared = this.tool.prepareArguments ? this.tool.prepareArguments(args) : args;
118
+ try {
119
+ const result = await this.tool.execute(toolCallId, prepared, options?.signal, options?.onUpdate);
120
+ const executionResult = {
121
+ content: result.content.map((block) => ({ ...block })),
122
+ details: result.details,
123
+ is_error: false,
124
+ };
125
+ // Detect file mutations
126
+ const mutations = inferFileMutations(this.tool.name, args, executionResult);
127
+ if (mutations?.length) {
128
+ executionResult.file_mutations = mutations;
129
+ }
130
+ return executionResult;
131
+ }
132
+ catch (err) {
133
+ const msg = err instanceof Error ? err.message : String(err);
134
+ return {
135
+ content: [{ type: "text", text: msg }],
136
+ is_error: true,
137
+ error_message: msg,
138
+ };
139
+ }
140
+ }
141
+ getMetadata() {
142
+ return this.metadata;
143
+ }
144
+ }
145
+ // ============================================================================
146
+ // ToolRegistry from AgentTools
147
+ // ============================================================================
148
+ /**
149
+ * Build a ToolRegistry from an array of AgentTool instances.
150
+ *
151
+ * Usage:
152
+ * const tools = createTools(cwd, options);
153
+ * const registry = createToolRegistry(tools);
154
+ */
155
+ export function createToolRegistry(tools) {
156
+ const executors = new Map();
157
+ for (const tool of tools) {
158
+ executors.set(tool.name, new AgentToolAdapter(tool));
159
+ }
160
+ return {
161
+ get(name) {
162
+ return executors.get(name);
163
+ },
164
+ list() {
165
+ return Array.from(executors.keys());
166
+ },
167
+ };
168
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Intent Classification Types
3
+ *
4
+ * Defines the risk levels and categories for LLM-proposed tool calls.
5
+ */
6
+ import type { FileMutation } from "../event-store/types.js";
7
+ /** Intent risk level */
8
+ export type IntentRisk = "safe" | "moderate" | "dangerous";
9
+ /** Intent category */
10
+ export type IntentCategory = "file_read" | "file_write" | "file_delete" | "shell_safe" | "shell_moderate" | "shell_dangerous" | "network" | "unknown";
11
+ /** Intent classification result */
12
+ export interface IntentClassification {
13
+ risk: IntentRisk;
14
+ /** Whether this intent requires user approval */
15
+ requires_approval: boolean;
16
+ category: IntentCategory;
17
+ /** Files affected by this intent */
18
+ affected_files?: string[];
19
+ /** Human-readable description */
20
+ description: string;
21
+ }
22
+ /** Tool execution result */
23
+ export interface ToolExecutionResult {
24
+ content: Array<{
25
+ type: string;
26
+ [key: string]: unknown;
27
+ }>;
28
+ /** Optional structured payload for logs/UI. */
29
+ details?: unknown;
30
+ is_error: boolean;
31
+ /** File mutations produced by this execution */
32
+ file_mutations?: FileMutation[];
33
+ /** Error message if is_error */
34
+ error_message?: string;
35
+ }
36
+ /** Partial tool execution update emitted while a tool is running. */
37
+ export interface ToolExecutionUpdate {
38
+ content: Array<{
39
+ type: string;
40
+ }>;
41
+ details?: unknown;
42
+ progress?: number;
43
+ }
44
+ /** Runtime-provided execution context for a tool call. */
45
+ export interface ToolExecutionOptions {
46
+ tool_call_id?: string;
47
+ signal?: AbortSignal;
48
+ onUpdate?: (partial: ToolExecutionUpdate) => void;
49
+ }
50
+ /** Tool registry interface */
51
+ export interface ToolRegistry {
52
+ get(name: string): ToolExecutor | undefined;
53
+ list(): string[];
54
+ }
55
+ /** Tool executor interface */
56
+ export interface ToolExecutor {
57
+ execute(args: Record<string, unknown>, options?: ToolExecutionOptions): Promise<ToolExecutionResult>;
58
+ getMetadata(): ToolMetadata;
59
+ }
60
+ /** Tool metadata */
61
+ export interface ToolMetadata {
62
+ name: string;
63
+ description?: string;
64
+ category: IntentCategory;
65
+ defaultRisk: IntentRisk;
66
+ }
67
+ /** Approval handler for UI integration */
68
+ export interface ApprovalHandler {
69
+ requestApproval(intentEventId: string, classification: IntentClassification): void;
70
+ cancelApproval(intentEventId: string): void;
71
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Intent Classification Types
3
+ *
4
+ * Defines the risk levels and categories for LLM-proposed tool calls.
5
+ */
6
+ export {};