@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,685 @@
1
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { join, resolve, sep } from "node:path";
4
+ import chalk from "chalk";
5
+ import { CONFIG_DIR_NAME } from "../config.js";
6
+ import { loadThemeFromPath } from "../modes/interactive/theme/theme.js";
7
+ import { isLocalPath } from "../utils/paths.js";
8
+ import { createEventBus } from "./event-bus.js";
9
+ import { createExtensionRuntime, loadExtensionFromFactory, loadExtensions } from "./extensions/loader.js";
10
+ import { DefaultPackageManager } from "./package-manager.js";
11
+ import { loadPromptTemplates } from "./prompt-templates.js";
12
+ import { SettingsManager } from "./settings-manager.js";
13
+ import { loadSkills } from "./skills.js";
14
+ import { createSourceInfo } from "./source-info.js";
15
+ function resolvePromptInput(input, description) {
16
+ if (!input) {
17
+ return undefined;
18
+ }
19
+ if (existsSync(input)) {
20
+ try {
21
+ return readFileSync(input, "utf-8");
22
+ }
23
+ catch (error) {
24
+ console.error(chalk.yellow(`Warning: Could not read ${description} file ${input}: ${error}`));
25
+ return input;
26
+ }
27
+ }
28
+ return input;
29
+ }
30
+ function loadContextFileFromDir(dir) {
31
+ const candidates = ["AGENTS.md", "CLAUDE.md"];
32
+ for (const filename of candidates) {
33
+ const filePath = join(dir, filename);
34
+ if (existsSync(filePath)) {
35
+ try {
36
+ return {
37
+ path: filePath,
38
+ content: readFileSync(filePath, "utf-8"),
39
+ };
40
+ }
41
+ catch (error) {
42
+ console.error(chalk.yellow(`Warning: Could not read ${filePath}: ${error}`));
43
+ }
44
+ }
45
+ }
46
+ return null;
47
+ }
48
+ export function loadProjectContextFiles(options) {
49
+ const resolvedCwd = options.cwd;
50
+ const resolvedAgentDir = options.agentDir;
51
+ const contextFiles = [];
52
+ const seenPaths = new Set();
53
+ const globalContext = loadContextFileFromDir(resolvedAgentDir);
54
+ if (globalContext) {
55
+ contextFiles.push(globalContext);
56
+ seenPaths.add(globalContext.path);
57
+ }
58
+ const ancestorContextFiles = [];
59
+ let currentDir = resolvedCwd;
60
+ const root = resolve("/");
61
+ while (true) {
62
+ const contextFile = loadContextFileFromDir(currentDir);
63
+ if (contextFile && !seenPaths.has(contextFile.path)) {
64
+ ancestorContextFiles.unshift(contextFile);
65
+ seenPaths.add(contextFile.path);
66
+ }
67
+ if (currentDir === root)
68
+ break;
69
+ const parentDir = resolve(currentDir, "..");
70
+ if (parentDir === currentDir)
71
+ break;
72
+ currentDir = parentDir;
73
+ }
74
+ contextFiles.push(...ancestorContextFiles);
75
+ return contextFiles;
76
+ }
77
+ export class DefaultResourceLoader {
78
+ constructor(options) {
79
+ this.cwd = options.cwd;
80
+ this.agentDir = options.agentDir;
81
+ this.settingsManager = options.settingsManager ?? SettingsManager.create(this.cwd, this.agentDir);
82
+ this.eventBus = options.eventBus ?? createEventBus();
83
+ this.packageManager = new DefaultPackageManager({
84
+ cwd: this.cwd,
85
+ agentDir: this.agentDir,
86
+ settingsManager: this.settingsManager,
87
+ });
88
+ this.additionalExtensionPaths = options.additionalExtensionPaths ?? [];
89
+ this.additionalSkillPaths = options.additionalSkillPaths ?? [];
90
+ this.additionalPromptTemplatePaths = options.additionalPromptTemplatePaths ?? [];
91
+ this.additionalThemePaths = options.additionalThemePaths ?? [];
92
+ this.extensionFactories = options.extensionFactories ?? [];
93
+ this.noExtensions = options.noExtensions ?? false;
94
+ this.noSkills = options.noSkills ?? false;
95
+ this.noPromptTemplates = options.noPromptTemplates ?? false;
96
+ this.noThemes = options.noThemes ?? false;
97
+ this.noContextFiles = options.noContextFiles ?? false;
98
+ this.systemPromptSource = options.systemPrompt;
99
+ this.appendSystemPromptSource = options.appendSystemPrompt;
100
+ this.extensionsOverride = options.extensionsOverride;
101
+ this.skillsOverride = options.skillsOverride;
102
+ this.promptsOverride = options.promptsOverride;
103
+ this.themesOverride = options.themesOverride;
104
+ this.agentsFilesOverride = options.agentsFilesOverride;
105
+ this.systemPromptOverride = options.systemPromptOverride;
106
+ this.appendSystemPromptOverride = options.appendSystemPromptOverride;
107
+ this.extensionsResult = { extensions: [], errors: [], runtime: createExtensionRuntime() };
108
+ this.skills = [];
109
+ this.skillDiagnostics = [];
110
+ this.prompts = [];
111
+ this.promptDiagnostics = [];
112
+ this.themes = [];
113
+ this.themeDiagnostics = [];
114
+ this.agentsFiles = [];
115
+ this.appendSystemPrompt = [];
116
+ this.lastSkillPaths = [];
117
+ this.extensionSkillSourceInfos = new Map();
118
+ this.extensionPromptSourceInfos = new Map();
119
+ this.extensionThemeSourceInfos = new Map();
120
+ this.lastPromptPaths = [];
121
+ this.lastThemePaths = [];
122
+ }
123
+ getExtensions() {
124
+ return this.extensionsResult;
125
+ }
126
+ getSkills() {
127
+ return { skills: this.skills, diagnostics: this.skillDiagnostics };
128
+ }
129
+ getPrompts() {
130
+ return { prompts: this.prompts, diagnostics: this.promptDiagnostics };
131
+ }
132
+ getThemes() {
133
+ return { themes: this.themes, diagnostics: this.themeDiagnostics };
134
+ }
135
+ getAgentsFiles() {
136
+ return { agentsFiles: this.agentsFiles };
137
+ }
138
+ getSystemPrompt() {
139
+ return this.systemPrompt;
140
+ }
141
+ getAppendSystemPrompt() {
142
+ return this.appendSystemPrompt;
143
+ }
144
+ extendResources(paths) {
145
+ const skillPaths = this.normalizeExtensionPaths(paths.skillPaths ?? []);
146
+ const promptPaths = this.normalizeExtensionPaths(paths.promptPaths ?? []);
147
+ const themePaths = this.normalizeExtensionPaths(paths.themePaths ?? []);
148
+ for (const entry of skillPaths) {
149
+ this.extensionSkillSourceInfos.set(entry.path, createSourceInfo(entry.path, entry.metadata));
150
+ }
151
+ for (const entry of promptPaths) {
152
+ this.extensionPromptSourceInfos.set(entry.path, createSourceInfo(entry.path, entry.metadata));
153
+ }
154
+ for (const entry of themePaths) {
155
+ this.extensionThemeSourceInfos.set(entry.path, createSourceInfo(entry.path, entry.metadata));
156
+ }
157
+ if (skillPaths.length > 0) {
158
+ this.lastSkillPaths = this.mergePaths(this.lastSkillPaths, skillPaths.map((entry) => entry.path));
159
+ this.updateSkillsFromPaths(this.lastSkillPaths);
160
+ }
161
+ if (promptPaths.length > 0) {
162
+ this.lastPromptPaths = this.mergePaths(this.lastPromptPaths, promptPaths.map((entry) => entry.path));
163
+ this.updatePromptsFromPaths(this.lastPromptPaths);
164
+ }
165
+ if (themePaths.length > 0) {
166
+ this.lastThemePaths = this.mergePaths(this.lastThemePaths, themePaths.map((entry) => entry.path));
167
+ this.updateThemesFromPaths(this.lastThemePaths);
168
+ }
169
+ }
170
+ async reload() {
171
+ await this.settingsManager.reload();
172
+ const resolvedPaths = await this.packageManager.resolve();
173
+ const cliExtensionPaths = await this.packageManager.resolveExtensionSources(this.additionalExtensionPaths, {
174
+ temporary: true,
175
+ });
176
+ const metadataByPath = new Map();
177
+ this.extensionSkillSourceInfos = new Map();
178
+ this.extensionPromptSourceInfos = new Map();
179
+ this.extensionThemeSourceInfos = new Map();
180
+ // Helper to extract enabled paths and store metadata
181
+ const getEnabledResources = (resources) => {
182
+ for (const r of resources) {
183
+ if (!metadataByPath.has(r.path)) {
184
+ metadataByPath.set(r.path, r.metadata);
185
+ }
186
+ }
187
+ return resources.filter((r) => r.enabled);
188
+ };
189
+ const getEnabledPaths = (resources) => getEnabledResources(resources).map((r) => r.path);
190
+ const enabledExtensions = getEnabledPaths(resolvedPaths.extensions);
191
+ const enabledSkillResources = getEnabledResources(resolvedPaths.skills);
192
+ const enabledPrompts = getEnabledPaths(resolvedPaths.prompts);
193
+ const enabledThemes = getEnabledPaths(resolvedPaths.themes);
194
+ const mapSkillPath = (resource) => {
195
+ if (resource.metadata.source !== "auto" && resource.metadata.origin !== "package") {
196
+ return resource.path;
197
+ }
198
+ try {
199
+ const stats = statSync(resource.path);
200
+ if (!stats.isDirectory()) {
201
+ return resource.path;
202
+ }
203
+ }
204
+ catch {
205
+ return resource.path;
206
+ }
207
+ const skillFile = join(resource.path, "SKILL.md");
208
+ if (existsSync(skillFile)) {
209
+ if (!metadataByPath.has(skillFile)) {
210
+ metadataByPath.set(skillFile, resource.metadata);
211
+ }
212
+ return skillFile;
213
+ }
214
+ return resource.path;
215
+ };
216
+ const enabledSkills = enabledSkillResources.map(mapSkillPath);
217
+ // Add CLI paths metadata
218
+ for (const r of cliExtensionPaths.extensions) {
219
+ if (!metadataByPath.has(r.path)) {
220
+ metadataByPath.set(r.path, { source: "cli", scope: "temporary", origin: "top-level" });
221
+ }
222
+ }
223
+ for (const r of cliExtensionPaths.skills) {
224
+ if (!metadataByPath.has(r.path)) {
225
+ metadataByPath.set(r.path, { source: "cli", scope: "temporary", origin: "top-level" });
226
+ }
227
+ }
228
+ const cliEnabledExtensions = getEnabledPaths(cliExtensionPaths.extensions);
229
+ const cliEnabledSkills = getEnabledPaths(cliExtensionPaths.skills);
230
+ const cliEnabledPrompts = getEnabledPaths(cliExtensionPaths.prompts);
231
+ const cliEnabledThemes = getEnabledPaths(cliExtensionPaths.themes);
232
+ const extensionPaths = this.noExtensions
233
+ ? cliEnabledExtensions
234
+ : this.mergePaths(cliEnabledExtensions, enabledExtensions);
235
+ const extensionsResult = await loadExtensions(extensionPaths, this.cwd, this.eventBus);
236
+ const inlineExtensions = await this.loadExtensionFactories(extensionsResult.runtime);
237
+ extensionsResult.extensions.push(...inlineExtensions.extensions);
238
+ extensionsResult.errors.push(...inlineExtensions.errors);
239
+ // Detect extension conflicts (tools, commands, flags with same names from different extensions)
240
+ // Keep all extensions loaded. Conflicts are reported as diagnostics, and precedence is handled by load order.
241
+ const conflicts = this.detectExtensionConflicts(extensionsResult.extensions);
242
+ for (const conflict of conflicts) {
243
+ extensionsResult.errors.push({ path: conflict.path, error: conflict.message });
244
+ }
245
+ for (const p of this.additionalExtensionPaths) {
246
+ if (isLocalPath(p) && !existsSync(p)) {
247
+ extensionsResult.errors.push({ path: p, error: `Extension path does not exist: ${p}` });
248
+ }
249
+ }
250
+ this.extensionsResult = this.extensionsOverride ? this.extensionsOverride(extensionsResult) : extensionsResult;
251
+ this.applyExtensionSourceInfo(this.extensionsResult.extensions, metadataByPath);
252
+ const skillPaths = this.noSkills
253
+ ? this.mergePaths(cliEnabledSkills, this.additionalSkillPaths)
254
+ : this.mergePaths([...cliEnabledSkills, ...enabledSkills], this.additionalSkillPaths);
255
+ this.lastSkillPaths = skillPaths;
256
+ this.updateSkillsFromPaths(skillPaths, metadataByPath);
257
+ for (const p of this.additionalSkillPaths) {
258
+ if (isLocalPath(p) && !existsSync(p) && !this.skillDiagnostics.some((d) => d.path === p)) {
259
+ this.skillDiagnostics.push({ type: "error", message: "Skill path does not exist", path: p });
260
+ }
261
+ }
262
+ const promptPaths = this.noPromptTemplates
263
+ ? this.mergePaths(cliEnabledPrompts, this.additionalPromptTemplatePaths)
264
+ : this.mergePaths([...cliEnabledPrompts, ...enabledPrompts], this.additionalPromptTemplatePaths);
265
+ this.lastPromptPaths = promptPaths;
266
+ this.updatePromptsFromPaths(promptPaths, metadataByPath);
267
+ for (const p of this.additionalPromptTemplatePaths) {
268
+ if (isLocalPath(p) && !existsSync(p) && !this.promptDiagnostics.some((d) => d.path === p)) {
269
+ this.promptDiagnostics.push({ type: "error", message: "Prompt template path does not exist", path: p });
270
+ }
271
+ }
272
+ const themePaths = this.noThemes
273
+ ? this.mergePaths(cliEnabledThemes, this.additionalThemePaths)
274
+ : this.mergePaths([...cliEnabledThemes, ...enabledThemes], this.additionalThemePaths);
275
+ this.lastThemePaths = themePaths;
276
+ this.updateThemesFromPaths(themePaths, metadataByPath);
277
+ for (const p of this.additionalThemePaths) {
278
+ if (!existsSync(p) && !this.themeDiagnostics.some((d) => d.path === p)) {
279
+ this.themeDiagnostics.push({ type: "error", message: "Theme path does not exist", path: p });
280
+ }
281
+ }
282
+ const agentsFiles = {
283
+ agentsFiles: this.noContextFiles ? [] : loadProjectContextFiles({ cwd: this.cwd, agentDir: this.agentDir }),
284
+ };
285
+ const resolvedAgentsFiles = this.agentsFilesOverride ? this.agentsFilesOverride(agentsFiles) : agentsFiles;
286
+ this.agentsFiles = resolvedAgentsFiles.agentsFiles;
287
+ const baseSystemPrompt = resolvePromptInput(this.systemPromptSource ?? this.discoverSystemPromptFile(), "system prompt");
288
+ this.systemPrompt = this.systemPromptOverride ? this.systemPromptOverride(baseSystemPrompt) : baseSystemPrompt;
289
+ const appendSources = this.appendSystemPromptSource ??
290
+ (this.discoverAppendSystemPromptFile() ? [this.discoverAppendSystemPromptFile()] : []);
291
+ const baseAppend = appendSources
292
+ .map((s) => resolvePromptInput(s, "append system prompt"))
293
+ .filter((s) => s !== undefined);
294
+ this.appendSystemPrompt = this.appendSystemPromptOverride
295
+ ? this.appendSystemPromptOverride(baseAppend)
296
+ : baseAppend;
297
+ }
298
+ normalizeExtensionPaths(entries) {
299
+ return entries.map((entry) => ({
300
+ path: this.resolveResourcePath(entry.path),
301
+ metadata: entry.metadata,
302
+ }));
303
+ }
304
+ updateSkillsFromPaths(skillPaths, metadataByPath) {
305
+ let skillsResult;
306
+ if (this.noSkills && skillPaths.length === 0) {
307
+ skillsResult = { skills: [], diagnostics: [] };
308
+ }
309
+ else {
310
+ skillsResult = loadSkills({
311
+ cwd: this.cwd,
312
+ agentDir: this.agentDir,
313
+ skillPaths,
314
+ includeDefaults: false,
315
+ });
316
+ }
317
+ const resolvedSkills = this.skillsOverride ? this.skillsOverride(skillsResult) : skillsResult;
318
+ this.skills = resolvedSkills.skills.map((skill) => ({
319
+ ...skill,
320
+ sourceInfo: this.findSourceInfoForPath(skill.filePath, this.extensionSkillSourceInfos, metadataByPath) ??
321
+ skill.sourceInfo ??
322
+ this.getDefaultSourceInfoForPath(skill.filePath),
323
+ }));
324
+ this.skillDiagnostics = resolvedSkills.diagnostics;
325
+ }
326
+ updatePromptsFromPaths(promptPaths, metadataByPath) {
327
+ let promptsResult;
328
+ if (this.noPromptTemplates && promptPaths.length === 0) {
329
+ promptsResult = { prompts: [], diagnostics: [] };
330
+ }
331
+ else {
332
+ const allPrompts = loadPromptTemplates({
333
+ cwd: this.cwd,
334
+ agentDir: this.agentDir,
335
+ promptPaths,
336
+ includeDefaults: false,
337
+ });
338
+ promptsResult = this.dedupePrompts(allPrompts);
339
+ }
340
+ const resolvedPrompts = this.promptsOverride ? this.promptsOverride(promptsResult) : promptsResult;
341
+ this.prompts = resolvedPrompts.prompts.map((prompt) => ({
342
+ ...prompt,
343
+ sourceInfo: this.findSourceInfoForPath(prompt.filePath, this.extensionPromptSourceInfos, metadataByPath) ??
344
+ prompt.sourceInfo ??
345
+ this.getDefaultSourceInfoForPath(prompt.filePath),
346
+ }));
347
+ this.promptDiagnostics = resolvedPrompts.diagnostics;
348
+ }
349
+ updateThemesFromPaths(themePaths, metadataByPath) {
350
+ let themesResult;
351
+ if (this.noThemes && themePaths.length === 0) {
352
+ themesResult = { themes: [], diagnostics: [] };
353
+ }
354
+ else {
355
+ const loaded = this.loadThemes(themePaths, false);
356
+ const deduped = this.dedupeThemes(loaded.themes);
357
+ themesResult = { themes: deduped.themes, diagnostics: [...loaded.diagnostics, ...deduped.diagnostics] };
358
+ }
359
+ const resolvedThemes = this.themesOverride ? this.themesOverride(themesResult) : themesResult;
360
+ this.themes = resolvedThemes.themes.map((theme) => {
361
+ const sourcePath = theme.sourcePath;
362
+ theme.sourceInfo = sourcePath
363
+ ? (this.findSourceInfoForPath(sourcePath, this.extensionThemeSourceInfos, metadataByPath) ??
364
+ theme.sourceInfo ??
365
+ this.getDefaultSourceInfoForPath(sourcePath))
366
+ : theme.sourceInfo;
367
+ return theme;
368
+ });
369
+ this.themeDiagnostics = resolvedThemes.diagnostics;
370
+ }
371
+ applyExtensionSourceInfo(extensions, metadataByPath) {
372
+ for (const extension of extensions) {
373
+ extension.sourceInfo =
374
+ this.findSourceInfoForPath(extension.path, undefined, metadataByPath) ??
375
+ this.getDefaultSourceInfoForPath(extension.path);
376
+ for (const command of extension.commands.values()) {
377
+ command.sourceInfo = extension.sourceInfo;
378
+ }
379
+ for (const tool of extension.tools.values()) {
380
+ tool.sourceInfo = extension.sourceInfo;
381
+ }
382
+ }
383
+ }
384
+ findSourceInfoForPath(resourcePath, extraSourceInfos, metadataByPath) {
385
+ if (!resourcePath) {
386
+ return undefined;
387
+ }
388
+ if (resourcePath.startsWith("<")) {
389
+ return this.getDefaultSourceInfoForPath(resourcePath);
390
+ }
391
+ const normalizedResourcePath = resolve(resourcePath);
392
+ if (extraSourceInfos) {
393
+ for (const [sourcePath, sourceInfo] of extraSourceInfos.entries()) {
394
+ const normalizedSourcePath = resolve(sourcePath);
395
+ if (normalizedResourcePath === normalizedSourcePath ||
396
+ normalizedResourcePath.startsWith(`${normalizedSourcePath}${sep}`)) {
397
+ return { ...sourceInfo, path: resourcePath };
398
+ }
399
+ }
400
+ }
401
+ if (metadataByPath) {
402
+ const exact = metadataByPath.get(normalizedResourcePath) ?? metadataByPath.get(resourcePath);
403
+ if (exact) {
404
+ return createSourceInfo(resourcePath, exact);
405
+ }
406
+ for (const [sourcePath, metadata] of metadataByPath.entries()) {
407
+ const normalizedSourcePath = resolve(sourcePath);
408
+ if (normalizedResourcePath === normalizedSourcePath ||
409
+ normalizedResourcePath.startsWith(`${normalizedSourcePath}${sep}`)) {
410
+ return createSourceInfo(resourcePath, metadata);
411
+ }
412
+ }
413
+ }
414
+ return undefined;
415
+ }
416
+ getDefaultSourceInfoForPath(filePath) {
417
+ if (filePath.startsWith("<") && filePath.endsWith(">")) {
418
+ return {
419
+ path: filePath,
420
+ source: filePath.slice(1, -1).split(":")[0] || "temporary",
421
+ scope: "temporary",
422
+ origin: "top-level",
423
+ };
424
+ }
425
+ const normalizedPath = resolve(filePath);
426
+ const agentRoots = [
427
+ join(this.agentDir, "skills"),
428
+ join(this.agentDir, "prompts"),
429
+ join(this.agentDir, "themes"),
430
+ join(this.agentDir, "extensions"),
431
+ ];
432
+ const projectRoots = [
433
+ join(this.cwd, CONFIG_DIR_NAME, "skills"),
434
+ join(this.cwd, CONFIG_DIR_NAME, "prompts"),
435
+ join(this.cwd, CONFIG_DIR_NAME, "themes"),
436
+ join(this.cwd, CONFIG_DIR_NAME, "extensions"),
437
+ ];
438
+ for (const root of agentRoots) {
439
+ if (this.isUnderPath(normalizedPath, root)) {
440
+ return { path: filePath, source: "local", scope: "user", origin: "top-level", baseDir: root };
441
+ }
442
+ }
443
+ for (const root of projectRoots) {
444
+ if (this.isUnderPath(normalizedPath, root)) {
445
+ return { path: filePath, source: "local", scope: "project", origin: "top-level", baseDir: root };
446
+ }
447
+ }
448
+ return {
449
+ path: filePath,
450
+ source: "local",
451
+ scope: "temporary",
452
+ origin: "top-level",
453
+ baseDir: statSync(normalizedPath).isDirectory() ? normalizedPath : resolve(normalizedPath, ".."),
454
+ };
455
+ }
456
+ mergePaths(primary, additional) {
457
+ const merged = [];
458
+ const seen = new Set();
459
+ for (const p of [...primary, ...additional]) {
460
+ const resolved = this.resolveResourcePath(p);
461
+ if (seen.has(resolved))
462
+ continue;
463
+ seen.add(resolved);
464
+ merged.push(resolved);
465
+ }
466
+ return merged;
467
+ }
468
+ resolveResourcePath(p) {
469
+ const trimmed = p.trim();
470
+ let expanded = trimmed;
471
+ if (trimmed === "~") {
472
+ expanded = homedir();
473
+ }
474
+ else if (trimmed.startsWith("~/")) {
475
+ expanded = join(homedir(), trimmed.slice(2));
476
+ }
477
+ else if (trimmed.startsWith("~")) {
478
+ expanded = join(homedir(), trimmed.slice(1));
479
+ }
480
+ return resolve(this.cwd, expanded);
481
+ }
482
+ loadThemes(paths, includeDefaults = true) {
483
+ const themes = [];
484
+ const diagnostics = [];
485
+ if (includeDefaults) {
486
+ const defaultDirs = [join(this.agentDir, "themes"), join(this.cwd, CONFIG_DIR_NAME, "themes")];
487
+ for (const dir of defaultDirs) {
488
+ this.loadThemesFromDir(dir, themes, diagnostics);
489
+ }
490
+ }
491
+ for (const p of paths) {
492
+ const resolved = resolve(this.cwd, p);
493
+ if (!existsSync(resolved)) {
494
+ diagnostics.push({ type: "warning", message: "theme path does not exist", path: resolved });
495
+ continue;
496
+ }
497
+ try {
498
+ const stats = statSync(resolved);
499
+ if (stats.isDirectory()) {
500
+ this.loadThemesFromDir(resolved, themes, diagnostics);
501
+ }
502
+ else if (stats.isFile() && resolved.endsWith(".json")) {
503
+ this.loadThemeFromFile(resolved, themes, diagnostics);
504
+ }
505
+ else {
506
+ diagnostics.push({ type: "warning", message: "theme path is not a json file", path: resolved });
507
+ }
508
+ }
509
+ catch (error) {
510
+ const message = error instanceof Error ? error.message : "failed to read theme path";
511
+ diagnostics.push({ type: "warning", message, path: resolved });
512
+ }
513
+ }
514
+ return { themes, diagnostics };
515
+ }
516
+ loadThemesFromDir(dir, themes, diagnostics) {
517
+ if (!existsSync(dir)) {
518
+ return;
519
+ }
520
+ try {
521
+ const entries = readdirSync(dir, { withFileTypes: true });
522
+ for (const entry of entries) {
523
+ let isFile = entry.isFile();
524
+ if (entry.isSymbolicLink()) {
525
+ try {
526
+ isFile = statSync(join(dir, entry.name)).isFile();
527
+ }
528
+ catch {
529
+ continue;
530
+ }
531
+ }
532
+ if (!isFile) {
533
+ continue;
534
+ }
535
+ if (!entry.name.endsWith(".json")) {
536
+ continue;
537
+ }
538
+ this.loadThemeFromFile(join(dir, entry.name), themes, diagnostics);
539
+ }
540
+ }
541
+ catch (error) {
542
+ const message = error instanceof Error ? error.message : "failed to read theme directory";
543
+ diagnostics.push({ type: "warning", message, path: dir });
544
+ }
545
+ }
546
+ loadThemeFromFile(filePath, themes, diagnostics) {
547
+ try {
548
+ themes.push(loadThemeFromPath(filePath));
549
+ }
550
+ catch (error) {
551
+ const message = error instanceof Error ? error.message : "failed to load theme";
552
+ diagnostics.push({ type: "warning", message, path: filePath });
553
+ }
554
+ }
555
+ async loadExtensionFactories(runtime) {
556
+ const extensions = [];
557
+ const errors = [];
558
+ for (const [index, factory] of this.extensionFactories.entries()) {
559
+ const extensionPath = `<inline:${index + 1}>`;
560
+ try {
561
+ const extension = await loadExtensionFromFactory(factory, this.cwd, this.eventBus, runtime, extensionPath);
562
+ extensions.push(extension);
563
+ }
564
+ catch (error) {
565
+ const message = error instanceof Error ? error.message : "failed to load extension";
566
+ errors.push({ path: extensionPath, error: message });
567
+ }
568
+ }
569
+ return { extensions, errors };
570
+ }
571
+ dedupePrompts(prompts) {
572
+ const seen = new Map();
573
+ const diagnostics = [];
574
+ for (const prompt of prompts) {
575
+ const existing = seen.get(prompt.name);
576
+ if (existing) {
577
+ diagnostics.push({
578
+ type: "collision",
579
+ message: `name "/${prompt.name}" collision`,
580
+ path: prompt.filePath,
581
+ collision: {
582
+ resourceType: "prompt",
583
+ name: prompt.name,
584
+ winnerPath: existing.filePath,
585
+ loserPath: prompt.filePath,
586
+ },
587
+ });
588
+ }
589
+ else {
590
+ seen.set(prompt.name, prompt);
591
+ }
592
+ }
593
+ return { prompts: Array.from(seen.values()), diagnostics };
594
+ }
595
+ dedupeThemes(themes) {
596
+ const seen = new Map();
597
+ const diagnostics = [];
598
+ for (const t of themes) {
599
+ const name = t.name ?? "unnamed";
600
+ const existing = seen.get(name);
601
+ if (existing) {
602
+ diagnostics.push({
603
+ type: "collision",
604
+ message: `name "${name}" collision`,
605
+ path: t.sourcePath,
606
+ collision: {
607
+ resourceType: "theme",
608
+ name,
609
+ winnerPath: existing.sourcePath ?? "<builtin>",
610
+ loserPath: t.sourcePath ?? "<builtin>",
611
+ },
612
+ });
613
+ }
614
+ else {
615
+ seen.set(name, t);
616
+ }
617
+ }
618
+ return { themes: Array.from(seen.values()), diagnostics };
619
+ }
620
+ discoverSystemPromptFile() {
621
+ const projectPath = join(this.cwd, CONFIG_DIR_NAME, "SYSTEM.md");
622
+ if (existsSync(projectPath)) {
623
+ return projectPath;
624
+ }
625
+ const globalPath = join(this.agentDir, "SYSTEM.md");
626
+ if (existsSync(globalPath)) {
627
+ return globalPath;
628
+ }
629
+ return undefined;
630
+ }
631
+ discoverAppendSystemPromptFile() {
632
+ const projectPath = join(this.cwd, CONFIG_DIR_NAME, "APPEND_SYSTEM.md");
633
+ if (existsSync(projectPath)) {
634
+ return projectPath;
635
+ }
636
+ const globalPath = join(this.agentDir, "APPEND_SYSTEM.md");
637
+ if (existsSync(globalPath)) {
638
+ return globalPath;
639
+ }
640
+ return undefined;
641
+ }
642
+ isUnderPath(target, root) {
643
+ const normalizedRoot = resolve(root);
644
+ if (target === normalizedRoot) {
645
+ return true;
646
+ }
647
+ const prefix = normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`;
648
+ return target.startsWith(prefix);
649
+ }
650
+ detectExtensionConflicts(extensions) {
651
+ const conflicts = [];
652
+ // Track which extension registered each tool and flag
653
+ const toolOwners = new Map();
654
+ const flagOwners = new Map();
655
+ for (const ext of extensions) {
656
+ // Check tools
657
+ for (const toolName of ext.tools.keys()) {
658
+ const existingOwner = toolOwners.get(toolName);
659
+ if (existingOwner && existingOwner !== ext.path) {
660
+ conflicts.push({
661
+ path: ext.path,
662
+ message: `Tool "${toolName}" conflicts with ${existingOwner}`,
663
+ });
664
+ }
665
+ else {
666
+ toolOwners.set(toolName, ext.path);
667
+ }
668
+ }
669
+ // Check flags
670
+ for (const flagName of ext.flags.keys()) {
671
+ const existingOwner = flagOwners.get(flagName);
672
+ if (existingOwner && existingOwner !== ext.path) {
673
+ conflicts.push({
674
+ path: ext.path,
675
+ message: `Flag "--${flagName}" conflicts with ${existingOwner}`,
676
+ });
677
+ }
678
+ else {
679
+ flagOwners.set(flagName, ext.path);
680
+ }
681
+ }
682
+ }
683
+ return conflicts;
684
+ }
685
+ }
@@ -0,0 +1,12 @@
1
+ import type { Context, Model, SimpleStreamOptions, streamSimple } from "@earendil-works/pi-ai/compat";
2
+ import type { LLMClient, ModelConfig } from "./llm-types.js";
3
+ export type AiStreamFn = (model: Model<any>, context: Context, options?: SimpleStreamOptions) => ReturnType<typeof streamSimple> | Promise<ReturnType<typeof streamSimple>>;
4
+ /** Build an EventSourcedRuntime LLMClient around the configured AI stream function. */
5
+ export declare function buildLlmClientFromStreamFn(model: Model<any>, streamFn: AiStreamFn, options?: {
6
+ getApiKey?: (provider: string) => Promise<string | undefined> | string | undefined;
7
+ thinkingBudgets?: any;
8
+ transport?: any;
9
+ onPayload?: any;
10
+ onResponse?: any;
11
+ }): LLMClient;
12
+ export declare function toModelConfig(model: Model<any>, thinkingLevel: string | undefined): ModelConfig;