@cjhyy/code-shell-core 0.5.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (484) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +162 -0
  3. package/dist/agent/coordinator.d.ts +49 -0
  4. package/dist/agent/coordinator.js +77 -0
  5. package/dist/arena/arena.d.ts +43 -0
  6. package/dist/arena/arena.js +334 -0
  7. package/dist/arena/context/context-tools.d.ts +16 -0
  8. package/dist/arena/context/context-tools.js +231 -0
  9. package/dist/arena/detect-mode.d.ts +20 -0
  10. package/dist/arena/detect-mode.js +78 -0
  11. package/dist/arena/digest-builder.d.ts +25 -0
  12. package/dist/arena/digest-builder.js +120 -0
  13. package/dist/arena/index.d.ts +29 -0
  14. package/dist/arena/index.js +29 -0
  15. package/dist/arena/iterate/convergence.d.ts +25 -0
  16. package/dist/arena/iterate/convergence.js +103 -0
  17. package/dist/arena/iterate/formats/index.d.ts +22 -0
  18. package/dist/arena/iterate/formats/index.js +283 -0
  19. package/dist/arena/iterate/index.d.ts +11 -0
  20. package/dist/arena/iterate/index.js +9 -0
  21. package/dist/arena/iterate/iterative-arena.d.ts +23 -0
  22. package/dist/arena/iterate/iterative-arena.js +237 -0
  23. package/dist/arena/iterate/parse.d.ts +42 -0
  24. package/dist/arena/iterate/parse.js +123 -0
  25. package/dist/arena/iterate/phases/argue.d.ts +22 -0
  26. package/dist/arena/iterate/phases/argue.js +159 -0
  27. package/dist/arena/iterate/phases/revise.d.ts +16 -0
  28. package/dist/arena/iterate/phases/revise.js +62 -0
  29. package/dist/arena/iterate/phases/tournament.d.ts +34 -0
  30. package/dist/arena/iterate/phases/tournament.js +113 -0
  31. package/dist/arena/iterate/tools/web-tools.d.ts +13 -0
  32. package/dist/arena/iterate/tools/web-tools.js +54 -0
  33. package/dist/arena/iterate/types.d.ts +152 -0
  34. package/dist/arena/iterate/types.js +8 -0
  35. package/dist/arena/ledger.d.ts +47 -0
  36. package/dist/arena/ledger.js +151 -0
  37. package/dist/arena/lenses/architecture.d.ts +5 -0
  38. package/dist/arena/lenses/architecture.js +22 -0
  39. package/dist/arena/lenses/engineering.d.ts +5 -0
  40. package/dist/arena/lenses/engineering.js +22 -0
  41. package/dist/arena/lenses/general.d.ts +5 -0
  42. package/dist/arena/lenses/general.js +20 -0
  43. package/dist/arena/lenses/index.d.ts +16 -0
  44. package/dist/arena/lenses/index.js +47 -0
  45. package/dist/arena/lenses/product.d.ts +5 -0
  46. package/dist/arena/lenses/product.js +22 -0
  47. package/dist/arena/model-presets.d.ts +23 -0
  48. package/dist/arena/model-presets.js +44 -0
  49. package/dist/arena/phases/adjudication.d.ts +24 -0
  50. package/dist/arena/phases/adjudication.js +144 -0
  51. package/dist/arena/phases/build-consensus.d.ts +29 -0
  52. package/dist/arena/phases/build-consensus.js +86 -0
  53. package/dist/arena/phases/claim-registry.d.ts +26 -0
  54. package/dist/arena/phases/claim-registry.js +60 -0
  55. package/dist/arena/phases/cross-review.d.ts +45 -0
  56. package/dist/arena/phases/cross-review.js +224 -0
  57. package/dist/arena/phases/debate-rounds.d.ts +27 -0
  58. package/dist/arena/phases/debate-rounds.js +162 -0
  59. package/dist/arena/phases/participant-research.d.ts +38 -0
  60. package/dist/arena/phases/participant-research.js +317 -0
  61. package/dist/arena/phases/planning-detail-expansion.d.ts +38 -0
  62. package/dist/arena/phases/planning-detail-expansion.js +121 -0
  63. package/dist/arena/planner.d.ts +27 -0
  64. package/dist/arena/planner.js +312 -0
  65. package/dist/arena/providers/docs.d.ts +6 -0
  66. package/dist/arena/providers/docs.js +108 -0
  67. package/dist/arena/providers/git.d.ts +8 -0
  68. package/dist/arena/providers/git.js +174 -0
  69. package/dist/arena/providers/index.d.ts +32 -0
  70. package/dist/arena/providers/index.js +132 -0
  71. package/dist/arena/providers/none.d.ts +7 -0
  72. package/dist/arena/providers/none.js +11 -0
  73. package/dist/arena/providers/repo.d.ts +6 -0
  74. package/dist/arena/providers/repo.js +255 -0
  75. package/dist/arena/render/session.d.ts +17 -0
  76. package/dist/arena/render/session.js +190 -0
  77. package/dist/arena/render/terminal.d.ts +34 -0
  78. package/dist/arena/render/terminal.js +286 -0
  79. package/dist/arena/strategies/discussion.d.ts +25 -0
  80. package/dist/arena/strategies/discussion.js +143 -0
  81. package/dist/arena/strategies/index.d.ts +15 -0
  82. package/dist/arena/strategies/index.js +28 -0
  83. package/dist/arena/strategies/language-wrapper.d.ts +17 -0
  84. package/dist/arena/strategies/language-wrapper.js +102 -0
  85. package/dist/arena/strategies/lens-wrapper.d.ts +16 -0
  86. package/dist/arena/strategies/lens-wrapper.js +236 -0
  87. package/dist/arena/strategies/planning.d.ts +30 -0
  88. package/dist/arena/strategies/planning.js +225 -0
  89. package/dist/arena/strategies/review.d.ts +26 -0
  90. package/dist/arena/strategies/review.js +168 -0
  91. package/dist/arena/strategies/utils.d.ts +39 -0
  92. package/dist/arena/strategies/utils.js +647 -0
  93. package/dist/arena/tools/selector.d.ts +17 -0
  94. package/dist/arena/tools/selector.js +61 -0
  95. package/dist/arena/transitions.d.ts +48 -0
  96. package/dist/arena/transitions.js +92 -0
  97. package/dist/arena/types.d.ts +508 -0
  98. package/dist/arena/types.js +27 -0
  99. package/dist/cli/agent-server-stdio.d.ts +32 -0
  100. package/dist/cli/agent-server-stdio.js +116 -0
  101. package/dist/colorizer.d.ts +23 -0
  102. package/dist/colorizer.js +12 -0
  103. package/dist/context/compaction.d.ts +116 -0
  104. package/dist/context/compaction.js +534 -0
  105. package/dist/context/manager.d.ts +145 -0
  106. package/dist/context/manager.js +423 -0
  107. package/dist/context/token-counter.d.ts +27 -0
  108. package/dist/context/token-counter.js +91 -0
  109. package/dist/context/tool-result-storage.d.ts +96 -0
  110. package/dist/context/tool-result-storage.js +296 -0
  111. package/dist/cost-tracker.d.ts +64 -0
  112. package/dist/cost-tracker.js +314 -0
  113. package/dist/cron/scheduler.d.ts +34 -0
  114. package/dist/cron/scheduler.js +115 -0
  115. package/dist/data/deepseek-models.json +46 -0
  116. package/dist/data/gemini-models.json +67 -0
  117. package/dist/data/openai-models.json +175 -0
  118. package/dist/data/openrouter-models.d.ts +35 -0
  119. package/dist/data/openrouter-models.js +36 -0
  120. package/dist/data/openrouter-models.json +4626 -0
  121. package/dist/data/openrouter-sync.d.ts +16 -0
  122. package/dist/data/openrouter-sync.js +53 -0
  123. package/dist/data/static-catalogs.d.ts +25 -0
  124. package/dist/data/static-catalogs.js +26 -0
  125. package/dist/data/zai-models.json +56 -0
  126. package/dist/engine/cost-store.d.ts +22 -0
  127. package/dist/engine/cost-store.js +15 -0
  128. package/dist/engine/engine.d.ts +295 -0
  129. package/dist/engine/engine.js +1467 -0
  130. package/dist/engine/model-facade.d.ts +24 -0
  131. package/dist/engine/model-facade.js +194 -0
  132. package/dist/engine/parse-task.d.ts +59 -0
  133. package/dist/engine/parse-task.js +135 -0
  134. package/dist/engine/patch-orphaned-tools.d.ts +52 -0
  135. package/dist/engine/patch-orphaned-tools.js +95 -0
  136. package/dist/engine/query.d.ts +50 -0
  137. package/dist/engine/query.js +107 -0
  138. package/dist/engine/runtime.d.ts +50 -0
  139. package/dist/engine/runtime.js +59 -0
  140. package/dist/engine/streaming-tool-queue.d.ts +34 -0
  141. package/dist/engine/streaming-tool-queue.js +61 -0
  142. package/dist/engine/token-budget.d.ts +22 -0
  143. package/dist/engine/token-budget.js +40 -0
  144. package/dist/engine/tool-summary.d.ts +13 -0
  145. package/dist/engine/tool-summary.js +35 -0
  146. package/dist/engine/turn-loop.d.ts +122 -0
  147. package/dist/engine/turn-loop.js +602 -0
  148. package/dist/engine/turn-state.d.ts +20 -0
  149. package/dist/engine/turn-state.js +17 -0
  150. package/dist/exceptions.d.ts +61 -0
  151. package/dist/exceptions.js +116 -0
  152. package/dist/git/utils.d.ts +35 -0
  153. package/dist/git/utils.js +98 -0
  154. package/dist/git/worktree.d.ts +36 -0
  155. package/dist/git/worktree.js +139 -0
  156. package/dist/hooks/events.d.ts +114 -0
  157. package/dist/hooks/events.js +4 -0
  158. package/dist/hooks/inject.d.ts +19 -0
  159. package/dist/hooks/inject.js +29 -0
  160. package/dist/hooks/registry.d.ts +15 -0
  161. package/dist/hooks/registry.js +84 -0
  162. package/dist/hooks/shell-runner.d.ts +45 -0
  163. package/dist/hooks/shell-runner.js +173 -0
  164. package/dist/index.d.ts +117 -0
  165. package/dist/index.js +145 -0
  166. package/dist/llm/api-key-sanitize.d.ts +22 -0
  167. package/dist/llm/api-key-sanitize.js +81 -0
  168. package/dist/llm/capabilities/index.d.ts +20 -0
  169. package/dist/llm/capabilities/index.js +39 -0
  170. package/dist/llm/capabilities/rules.d.ts +26 -0
  171. package/dist/llm/capabilities/rules.js +215 -0
  172. package/dist/llm/capabilities/types.d.ts +114 -0
  173. package/dist/llm/capabilities/types.js +24 -0
  174. package/dist/llm/client-base.d.ts +29 -0
  175. package/dist/llm/client-base.js +137 -0
  176. package/dist/llm/client-factory.d.ts +10 -0
  177. package/dist/llm/client-factory.js +29 -0
  178. package/dist/llm/model-cache.d.ts +21 -0
  179. package/dist/llm/model-cache.js +46 -0
  180. package/dist/llm/model-fetcher.d.ts +29 -0
  181. package/dist/llm/model-fetcher.js +282 -0
  182. package/dist/llm/model-pool.d.ts +95 -0
  183. package/dist/llm/model-pool.js +246 -0
  184. package/dist/llm/provider-catalog.d.ts +32 -0
  185. package/dist/llm/provider-catalog.js +50 -0
  186. package/dist/llm/provider-kinds.d.ts +21 -0
  187. package/dist/llm/provider-kinds.js +132 -0
  188. package/dist/llm/providers/anthropic.d.ts +19 -0
  189. package/dist/llm/providers/anthropic.js +267 -0
  190. package/dist/llm/providers/openai.d.ts +64 -0
  191. package/dist/llm/providers/openai.js +606 -0
  192. package/dist/llm/retry.d.ts +12 -0
  193. package/dist/llm/retry.js +17 -0
  194. package/dist/llm/stream-watchdog.d.ts +42 -0
  195. package/dist/llm/stream-watchdog.js +70 -0
  196. package/dist/llm/token-counter.d.ts +17 -0
  197. package/dist/llm/token-counter.js +36 -0
  198. package/dist/llm/types.d.ts +37 -0
  199. package/dist/llm/types.js +4 -0
  200. package/dist/logging/logger.d.ts +109 -0
  201. package/dist/logging/logger.js +390 -0
  202. package/dist/logging/sanitize-messages.d.ts +42 -0
  203. package/dist/logging/sanitize-messages.js +150 -0
  204. package/dist/logging/session-recorder.d.ts +90 -0
  205. package/dist/logging/session-recorder.js +304 -0
  206. package/dist/lsp/client.d.ts +41 -0
  207. package/dist/lsp/client.js +166 -0
  208. package/dist/lsp/manager.d.ts +40 -0
  209. package/dist/lsp/manager.js +124 -0
  210. package/dist/lsp/servers.d.ts +16 -0
  211. package/dist/lsp/servers.js +60 -0
  212. package/dist/migrate-models.d.ts +45 -0
  213. package/dist/migrate-models.js +179 -0
  214. package/dist/onboarding.d.ts +189 -0
  215. package/dist/onboarding.js +625 -0
  216. package/dist/plugins/gitOps.d.ts +32 -0
  217. package/dist/plugins/gitOps.js +62 -0
  218. package/dist/plugins/installedPlugins.d.ts +15 -0
  219. package/dist/plugins/installedPlugins.js +56 -0
  220. package/dist/plugins/knownMarketplaces.d.ts +10 -0
  221. package/dist/plugins/knownMarketplaces.js +46 -0
  222. package/dist/plugins/loadPluginHooks.d.ts +52 -0
  223. package/dist/plugins/loadPluginHooks.js +162 -0
  224. package/dist/plugins/marketplaceManager.d.ts +49 -0
  225. package/dist/plugins/marketplaceManager.js +142 -0
  226. package/dist/plugins/parseMarketplaceInput.d.ts +16 -0
  227. package/dist/plugins/parseMarketplaceInput.js +73 -0
  228. package/dist/plugins/pluginCommandHook.d.ts +54 -0
  229. package/dist/plugins/pluginCommandHook.js +180 -0
  230. package/dist/plugins/pluginCommandsLoader.d.ts +25 -0
  231. package/dist/plugins/pluginCommandsLoader.js +114 -0
  232. package/dist/plugins/pluginInstaller.d.ts +36 -0
  233. package/dist/plugins/pluginInstaller.js +228 -0
  234. package/dist/plugins/schemas.d.ts +9 -0
  235. package/dist/plugins/schemas.js +136 -0
  236. package/dist/plugins/types.d.ts +75 -0
  237. package/dist/plugins/types.js +7 -0
  238. package/dist/plugins/varRewrite.d.ts +42 -0
  239. package/dist/plugins/varRewrite.js +129 -0
  240. package/dist/preset/index.d.ts +60 -0
  241. package/dist/preset/index.js +159 -0
  242. package/dist/product/define.d.ts +60 -0
  243. package/dist/product/define.js +123 -0
  244. package/dist/product/index.d.ts +5 -0
  245. package/dist/product/index.js +4 -0
  246. package/dist/product/types.d.ts +111 -0
  247. package/dist/product/types.js +21 -0
  248. package/dist/prompt/composer.d.ts +49 -0
  249. package/dist/prompt/composer.js +168 -0
  250. package/dist/prompt/instruction-scanner.d.ts +54 -0
  251. package/dist/prompt/instruction-scanner.js +187 -0
  252. package/dist/prompt/section-cache.d.ts +15 -0
  253. package/dist/prompt/section-cache.js +31 -0
  254. package/dist/prompt/section-loader.d.ts +26 -0
  255. package/dist/prompt/section-loader.js +53 -0
  256. package/dist/prompt/sections/base.md +35 -0
  257. package/dist/prompt/sections/coding.md +31 -0
  258. package/dist/prompt/sections/orchestration.md +16 -0
  259. package/dist/prompt/sections/tone.md +9 -0
  260. package/dist/protocol/chat-session-manager.d.ts +33 -0
  261. package/dist/protocol/chat-session-manager.js +65 -0
  262. package/dist/protocol/chat-session.d.ts +49 -0
  263. package/dist/protocol/chat-session.js +86 -0
  264. package/dist/protocol/client.d.ts +104 -0
  265. package/dist/protocol/client.js +260 -0
  266. package/dist/protocol/factories.d.ts +93 -0
  267. package/dist/protocol/factories.js +64 -0
  268. package/dist/protocol/helpers.d.ts +42 -0
  269. package/dist/protocol/helpers.js +55 -0
  270. package/dist/protocol/index.d.ts +4 -0
  271. package/dist/protocol/index.js +4 -0
  272. package/dist/protocol/server.d.ts +80 -0
  273. package/dist/protocol/server.js +855 -0
  274. package/dist/protocol/transport.d.ts +37 -0
  275. package/dist/protocol/transport.js +85 -0
  276. package/dist/protocol/types.d.ts +221 -0
  277. package/dist/protocol/types.js +61 -0
  278. package/dist/remote/bridge.d.ts +37 -0
  279. package/dist/remote/bridge.js +103 -0
  280. package/dist/run/ArtifactTracker.d.ts +38 -0
  281. package/dist/run/ArtifactTracker.js +132 -0
  282. package/dist/run/CheckpointWriter.d.ts +53 -0
  283. package/dist/run/CheckpointWriter.js +135 -0
  284. package/dist/run/EngineRunner.d.ts +72 -0
  285. package/dist/run/EngineRunner.js +119 -0
  286. package/dist/run/Evaluator.d.ts +56 -0
  287. package/dist/run/Evaluator.js +62 -0
  288. package/dist/run/FileRunStore.d.ts +39 -0
  289. package/dist/run/FileRunStore.js +176 -0
  290. package/dist/run/Heartbeat.d.ts +54 -0
  291. package/dist/run/Heartbeat.js +123 -0
  292. package/dist/run/RunApprovalBackend.d.ts +53 -0
  293. package/dist/run/RunApprovalBackend.js +85 -0
  294. package/dist/run/RunLock.d.ts +40 -0
  295. package/dist/run/RunLock.js +98 -0
  296. package/dist/run/RunManager.d.ts +82 -0
  297. package/dist/run/RunManager.js +587 -0
  298. package/dist/run/RunQueue.d.ts +27 -0
  299. package/dist/run/RunQueue.js +73 -0
  300. package/dist/run/RunStore.d.ts +25 -0
  301. package/dist/run/RunStore.js +9 -0
  302. package/dist/run/factory.d.ts +63 -0
  303. package/dist/run/factory.js +51 -0
  304. package/dist/run/index.d.ts +17 -0
  305. package/dist/run/index.js +23 -0
  306. package/dist/run/types.d.ts +136 -0
  307. package/dist/run/types.js +28 -0
  308. package/dist/runtime/safe-spawn.d.ts +118 -0
  309. package/dist/runtime/safe-spawn.js +268 -0
  310. package/dist/services/analytics.d.ts +29 -0
  311. package/dist/services/analytics.js +84 -0
  312. package/dist/services/auto-dream.d.ts +49 -0
  313. package/dist/services/auto-dream.js +124 -0
  314. package/dist/services/diagnostics.d.ts +41 -0
  315. package/dist/services/diagnostics.js +99 -0
  316. package/dist/services/extract-memories.d.ts +31 -0
  317. package/dist/services/extract-memories.js +71 -0
  318. package/dist/services/index.d.ts +11 -0
  319. package/dist/services/index.js +17 -0
  320. package/dist/services/memory-orchestrator.d.ts +60 -0
  321. package/dist/services/memory-orchestrator.js +133 -0
  322. package/dist/services/notifier.d.ts +25 -0
  323. package/dist/services/notifier.js +69 -0
  324. package/dist/services/oauth.d.ts +27 -0
  325. package/dist/services/oauth.js +153 -0
  326. package/dist/services/session-memory.d.ts +37 -0
  327. package/dist/services/session-memory.js +81 -0
  328. package/dist/session/file-history.d.ts +41 -0
  329. package/dist/session/file-history.js +115 -0
  330. package/dist/session/memory.d.ts +104 -0
  331. package/dist/session/memory.js +310 -0
  332. package/dist/session/session-manager.d.ts +41 -0
  333. package/dist/session/session-manager.js +261 -0
  334. package/dist/session/transcript.d.ts +39 -0
  335. package/dist/session/transcript.js +186 -0
  336. package/dist/settings/manager.d.ts +36 -0
  337. package/dist/settings/manager.js +187 -0
  338. package/dist/settings/schema.d.ts +1219 -0
  339. package/dist/settings/schema.js +246 -0
  340. package/dist/skills/frontmatter.d.ts +13 -0
  341. package/dist/skills/frontmatter.js +70 -0
  342. package/dist/skills/index.d.ts +7 -0
  343. package/dist/skills/index.js +6 -0
  344. package/dist/skills/scanner.d.ts +31 -0
  345. package/dist/skills/scanner.js +171 -0
  346. package/dist/state.d.ts +160 -0
  347. package/dist/state.js +267 -0
  348. package/dist/tool-system/builtin/agent-notifications.d.ts +84 -0
  349. package/dist/tool-system/builtin/agent-notifications.js +197 -0
  350. package/dist/tool-system/builtin/agent-registry.d.ts +67 -0
  351. package/dist/tool-system/builtin/agent-registry.js +126 -0
  352. package/dist/tool-system/builtin/agent-transcript-translator.d.ts +22 -0
  353. package/dist/tool-system/builtin/agent-transcript-translator.js +160 -0
  354. package/dist/tool-system/builtin/agent.d.ts +16 -0
  355. package/dist/tool-system/builtin/agent.js +364 -0
  356. package/dist/tool-system/builtin/apply-patch/applier.d.ts +26 -0
  357. package/dist/tool-system/builtin/apply-patch/applier.js +250 -0
  358. package/dist/tool-system/builtin/apply-patch/index.d.ts +20 -0
  359. package/dist/tool-system/builtin/apply-patch/index.js +101 -0
  360. package/dist/tool-system/builtin/apply-patch/parser.d.ts +17 -0
  361. package/dist/tool-system/builtin/apply-patch/parser.js +212 -0
  362. package/dist/tool-system/builtin/apply-patch/seek-sequence.d.ts +18 -0
  363. package/dist/tool-system/builtin/apply-patch/seek-sequence.js +123 -0
  364. package/dist/tool-system/builtin/apply-patch/types.d.ts +49 -0
  365. package/dist/tool-system/builtin/apply-patch/types.js +13 -0
  366. package/dist/tool-system/builtin/arena.d.ts +31 -0
  367. package/dist/tool-system/builtin/arena.js +416 -0
  368. package/dist/tool-system/builtin/ask-user.d.ts +20 -0
  369. package/dist/tool-system/builtin/ask-user.js +99 -0
  370. package/dist/tool-system/builtin/bash.d.ts +21 -0
  371. package/dist/tool-system/builtin/bash.js +149 -0
  372. package/dist/tool-system/builtin/brief.d.ts +6 -0
  373. package/dist/tool-system/builtin/brief.js +41 -0
  374. package/dist/tool-system/builtin/config.d.ts +6 -0
  375. package/dist/tool-system/builtin/config.js +67 -0
  376. package/dist/tool-system/builtin/cron.d.ts +10 -0
  377. package/dist/tool-system/builtin/cron.js +61 -0
  378. package/dist/tool-system/builtin/edit.d.ts +6 -0
  379. package/dist/tool-system/builtin/edit.js +100 -0
  380. package/dist/tool-system/builtin/file-cache.d.ts +11 -0
  381. package/dist/tool-system/builtin/file-cache.js +39 -0
  382. package/dist/tool-system/builtin/glob.d.ts +7 -0
  383. package/dist/tool-system/builtin/glob.js +76 -0
  384. package/dist/tool-system/builtin/grep.d.ts +7 -0
  385. package/dist/tool-system/builtin/grep.js +150 -0
  386. package/dist/tool-system/builtin/index.d.ts +20 -0
  387. package/dist/tool-system/builtin/index.js +449 -0
  388. package/dist/tool-system/builtin/lsp.d.ts +6 -0
  389. package/dist/tool-system/builtin/lsp.js +141 -0
  390. package/dist/tool-system/builtin/mcp-tools.d.ts +10 -0
  391. package/dist/tool-system/builtin/mcp-tools.js +102 -0
  392. package/dist/tool-system/builtin/memory.d.ts +26 -0
  393. package/dist/tool-system/builtin/memory.js +226 -0
  394. package/dist/tool-system/builtin/notebook-edit.d.ts +6 -0
  395. package/dist/tool-system/builtin/notebook-edit.js +124 -0
  396. package/dist/tool-system/builtin/plan.d.ts +15 -0
  397. package/dist/tool-system/builtin/plan.js +55 -0
  398. package/dist/tool-system/builtin/powershell.d.ts +11 -0
  399. package/dist/tool-system/builtin/powershell.js +64 -0
  400. package/dist/tool-system/builtin/read.d.ts +6 -0
  401. package/dist/tool-system/builtin/read.js +70 -0
  402. package/dist/tool-system/builtin/remote-trigger.d.ts +6 -0
  403. package/dist/tool-system/builtin/remote-trigger.js +54 -0
  404. package/dist/tool-system/builtin/repl.d.ts +11 -0
  405. package/dist/tool-system/builtin/repl.js +82 -0
  406. package/dist/tool-system/builtin/send-message.d.ts +6 -0
  407. package/dist/tool-system/builtin/send-message.js +47 -0
  408. package/dist/tool-system/builtin/skill-prompt.d.ts +20 -0
  409. package/dist/tool-system/builtin/skill-prompt.js +52 -0
  410. package/dist/tool-system/builtin/skill.d.ts +9 -0
  411. package/dist/tool-system/builtin/skill.js +55 -0
  412. package/dist/tool-system/builtin/sleep.d.ts +6 -0
  413. package/dist/tool-system/builtin/sleep.js +33 -0
  414. package/dist/tool-system/builtin/task.d.ts +48 -0
  415. package/dist/tool-system/builtin/task.js +139 -0
  416. package/dist/tool-system/builtin/tool-search.d.ts +11 -0
  417. package/dist/tool-system/builtin/tool-search.js +90 -0
  418. package/dist/tool-system/builtin/web-fetch.d.ts +10 -0
  419. package/dist/tool-system/builtin/web-fetch.js +328 -0
  420. package/dist/tool-system/builtin/web-search.d.ts +25 -0
  421. package/dist/tool-system/builtin/web-search.js +174 -0
  422. package/dist/tool-system/builtin/worktree.d.ts +10 -0
  423. package/dist/tool-system/builtin/worktree.js +95 -0
  424. package/dist/tool-system/builtin/write.d.ts +6 -0
  425. package/dist/tool-system/builtin/write.js +36 -0
  426. package/dist/tool-system/context.d.ts +165 -0
  427. package/dist/tool-system/context.js +18 -0
  428. package/dist/tool-system/executor.d.ts +49 -0
  429. package/dist/tool-system/executor.js +495 -0
  430. package/dist/tool-system/investigation-guard.d.ts +46 -0
  431. package/dist/tool-system/investigation-guard.js +155 -0
  432. package/dist/tool-system/mcp-manager.d.ts +67 -0
  433. package/dist/tool-system/mcp-manager.js +249 -0
  434. package/dist/tool-system/permission.d.ts +111 -0
  435. package/dist/tool-system/permission.js +774 -0
  436. package/dist/tool-system/registry.d.ts +32 -0
  437. package/dist/tool-system/registry.js +131 -0
  438. package/dist/tool-system/sandbox/bwrap.d.ts +13 -0
  439. package/dist/tool-system/sandbox/bwrap.js +63 -0
  440. package/dist/tool-system/sandbox/index.d.ts +78 -0
  441. package/dist/tool-system/sandbox/index.js +222 -0
  442. package/dist/tool-system/sandbox/off.d.ts +2 -0
  443. package/dist/tool-system/sandbox/off.js +8 -0
  444. package/dist/tool-system/sandbox/seatbelt.d.ts +18 -0
  445. package/dist/tool-system/sandbox/seatbelt.js +109 -0
  446. package/dist/tool-system/task-guard.d.ts +29 -0
  447. package/dist/tool-system/task-guard.js +70 -0
  448. package/dist/tool-system/validation.d.ts +5 -0
  449. package/dist/tool-system/validation.js +39 -0
  450. package/dist/types.d.ts +376 -0
  451. package/dist/types.js +4 -0
  452. package/dist/updater.d.ts +65 -0
  453. package/dist/updater.js +405 -0
  454. package/dist/utils/debug.d.ts +41 -0
  455. package/dist/utils/debug.js +110 -0
  456. package/dist/utils/earlyInput.d.ts +43 -0
  457. package/dist/utils/earlyInput.js +166 -0
  458. package/dist/utils/env.d.ts +24 -0
  459. package/dist/utils/env.js +104 -0
  460. package/dist/utils/envUtils.d.ts +51 -0
  461. package/dist/utils/envUtils.js +135 -0
  462. package/dist/utils/execFileNoThrow.d.ts +39 -0
  463. package/dist/utils/execFileNoThrow.js +74 -0
  464. package/dist/utils/format.d.ts +44 -0
  465. package/dist/utils/format.js +236 -0
  466. package/dist/utils/intl.d.ts +22 -0
  467. package/dist/utils/intl.js +83 -0
  468. package/dist/utils/lockfile.d.ts +15 -0
  469. package/dist/utils/lockfile.js +30 -0
  470. package/dist/utils/memoize.d.ts +19 -0
  471. package/dist/utils/memoize.js +14 -0
  472. package/dist/utils/semver.d.ts +6 -0
  473. package/dist/utils/semver.js +13 -0
  474. package/dist/utils/sliceAnsi.d.ts +12 -0
  475. package/dist/utils/sliceAnsi.js +62 -0
  476. package/dist/utils/systemTheme.d.ts +40 -0
  477. package/dist/utils/systemTheme.js +108 -0
  478. package/dist/utils/task-sanitizer.d.ts +6 -0
  479. package/dist/utils/task-sanitizer.js +24 -0
  480. package/dist/utils/theme.d.ts +93 -0
  481. package/dist/utils/theme.js +544 -0
  482. package/dist/utils/toolDisplay.d.ts +31 -0
  483. package/dist/utils/toolDisplay.js +188 -0
  484. package/package.json +72 -0
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Custom exception hierarchy for the code-shell framework.
3
+ */
4
+ export declare class FrameworkError extends Error {
5
+ readonly details?: Record<string, unknown> | undefined;
6
+ constructor(message: string, details?: Record<string, unknown> | undefined);
7
+ }
8
+ export declare class LLMError extends FrameworkError {
9
+ readonly provider?: string | undefined;
10
+ constructor(message: string, provider?: string | undefined, details?: Record<string, unknown>);
11
+ }
12
+ export declare class LLMRateLimitError extends LLMError {
13
+ readonly retryAfter?: number | undefined;
14
+ constructor(provider: string, retryAfter?: number | undefined);
15
+ }
16
+ export declare class ContextLimitError extends LLMError {
17
+ constructor(provider?: string);
18
+ }
19
+ export declare class ToolError extends FrameworkError {
20
+ readonly toolName?: string | undefined;
21
+ constructor(message: string, toolName?: string | undefined, details?: Record<string, unknown>);
22
+ }
23
+ export declare class ToolNotFoundError extends ToolError {
24
+ constructor(toolName: string);
25
+ }
26
+ export declare class ToolExecutionError extends ToolError {
27
+ constructor(toolName: string, cause: string);
28
+ }
29
+ export declare class ToolTimeoutError extends ToolError {
30
+ readonly timeoutMs: number;
31
+ constructor(toolName: string, timeoutMs: number);
32
+ }
33
+ export declare class PermissionDeniedError extends FrameworkError {
34
+ constructor(toolName: string, reason?: string);
35
+ }
36
+ export declare class SessionError extends FrameworkError {
37
+ constructor(message: string, details?: Record<string, unknown>);
38
+ }
39
+ export declare class TranscriptError extends FrameworkError {
40
+ constructor(message: string, details?: Record<string, unknown>);
41
+ }
42
+ export declare class ConfigError extends FrameworkError {
43
+ constructor(message: string, details?: Record<string, unknown>);
44
+ }
45
+ /**
46
+ * Thrown by `resolveSandboxBackend` when an explicit sandbox mode is
47
+ * requested but the corresponding backend is unavailable on this host
48
+ * (e.g. `mode=seatbelt` on Linux, `mode=bwrap` without bubblewrap
49
+ * installed). The literal `code` field lets SDK callers narrow without
50
+ * `instanceof`: `if (err.code === "SANDBOX_UNAVAILABLE") { ... }`.
51
+ *
52
+ * Per standard §S4, explicit modes fail closed — only `auto` may
53
+ * silently downgrade to `off`. `mode` here is always one of the two
54
+ * explicit modes that can throw; `off` and `auto` never throw.
55
+ */
56
+ export declare class SandboxUnavailableError extends FrameworkError {
57
+ readonly mode: "seatbelt" | "bwrap";
58
+ readonly platform: NodeJS.Platform;
59
+ readonly code: "SANDBOX_UNAVAILABLE";
60
+ constructor(mode: "seatbelt" | "bwrap", platform: NodeJS.Platform, message: string);
61
+ }
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Custom exception hierarchy for the code-shell framework.
3
+ */
4
+ export class FrameworkError extends Error {
5
+ details;
6
+ constructor(message, details) {
7
+ super(message);
8
+ this.details = details;
9
+ this.name = "FrameworkError";
10
+ }
11
+ }
12
+ // ─── LLM Errors ───────────────────────────────────────────────────
13
+ export class LLMError extends FrameworkError {
14
+ provider;
15
+ constructor(message, provider, details) {
16
+ super(message, details);
17
+ this.provider = provider;
18
+ this.name = "LLMError";
19
+ }
20
+ }
21
+ export class LLMRateLimitError extends LLMError {
22
+ retryAfter;
23
+ constructor(provider, retryAfter) {
24
+ super(`Rate limit exceeded for ${provider}`, provider, { retryAfter });
25
+ this.retryAfter = retryAfter;
26
+ this.name = "LLMRateLimitError";
27
+ }
28
+ }
29
+ export class ContextLimitError extends LLMError {
30
+ constructor(provider) {
31
+ super("Context limit exceeded", provider);
32
+ this.name = "ContextLimitError";
33
+ }
34
+ }
35
+ // ─── Tool Errors ──────────────────────────────────────────────────
36
+ export class ToolError extends FrameworkError {
37
+ toolName;
38
+ constructor(message, toolName, details) {
39
+ super(message, details);
40
+ this.toolName = toolName;
41
+ this.name = "ToolError";
42
+ }
43
+ }
44
+ export class ToolNotFoundError extends ToolError {
45
+ constructor(toolName) {
46
+ super(`Tool not found: ${toolName}`, toolName);
47
+ this.name = "ToolNotFoundError";
48
+ }
49
+ }
50
+ export class ToolExecutionError extends ToolError {
51
+ constructor(toolName, cause) {
52
+ super(`Tool execution failed: ${toolName} - ${cause}`, toolName, { cause });
53
+ this.name = "ToolExecutionError";
54
+ }
55
+ }
56
+ export class ToolTimeoutError extends ToolError {
57
+ timeoutMs;
58
+ constructor(toolName, timeoutMs) {
59
+ super(`Tool timed out after ${timeoutMs}ms: ${toolName}`, toolName, { timeoutMs });
60
+ this.timeoutMs = timeoutMs;
61
+ this.name = "ToolTimeoutError";
62
+ }
63
+ }
64
+ // ─── Permission Errors ────────────────────────────────────────────
65
+ export class PermissionDeniedError extends FrameworkError {
66
+ constructor(toolName, reason) {
67
+ super(`Permission denied for tool: ${toolName}${reason ? ` - ${reason}` : ""}`, {
68
+ toolName,
69
+ reason,
70
+ });
71
+ this.name = "PermissionDeniedError";
72
+ }
73
+ }
74
+ // ─── Session Errors ───────────────────────────────────────────────
75
+ export class SessionError extends FrameworkError {
76
+ constructor(message, details) {
77
+ super(message, details);
78
+ this.name = "SessionError";
79
+ }
80
+ }
81
+ export class TranscriptError extends FrameworkError {
82
+ constructor(message, details) {
83
+ super(message, details);
84
+ this.name = "TranscriptError";
85
+ }
86
+ }
87
+ // ─── Config Errors ────────────────────────────────────────────────
88
+ export class ConfigError extends FrameworkError {
89
+ constructor(message, details) {
90
+ super(message, details);
91
+ this.name = "ConfigError";
92
+ }
93
+ }
94
+ // ─── Sandbox Errors ───────────────────────────────────────────────
95
+ /**
96
+ * Thrown by `resolveSandboxBackend` when an explicit sandbox mode is
97
+ * requested but the corresponding backend is unavailable on this host
98
+ * (e.g. `mode=seatbelt` on Linux, `mode=bwrap` without bubblewrap
99
+ * installed). The literal `code` field lets SDK callers narrow without
100
+ * `instanceof`: `if (err.code === "SANDBOX_UNAVAILABLE") { ... }`.
101
+ *
102
+ * Per standard §S4, explicit modes fail closed — only `auto` may
103
+ * silently downgrade to `off`. `mode` here is always one of the two
104
+ * explicit modes that can throw; `off` and `auto` never throw.
105
+ */
106
+ export class SandboxUnavailableError extends FrameworkError {
107
+ mode;
108
+ platform;
109
+ code = "SANDBOX_UNAVAILABLE";
110
+ constructor(mode, platform, message) {
111
+ super(message, { code: "SANDBOX_UNAVAILABLE", mode, platform });
112
+ this.mode = mode;
113
+ this.platform = platform;
114
+ this.name = "SandboxUnavailableError";
115
+ }
116
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Git utility functions for the git workflow commands.
3
+ */
4
+ export interface GitStatusEntry {
5
+ status: string;
6
+ path: string;
7
+ }
8
+ export interface GitLogEntry {
9
+ hash: string;
10
+ message: string;
11
+ author: string;
12
+ date: string;
13
+ }
14
+ export declare function isGitRepo(cwd: string): boolean;
15
+ export declare function getCurrentBranch(cwd: string): string;
16
+ export declare function getGitStatus(cwd: string): GitStatusEntry[];
17
+ export declare function getGitDiff(cwd: string, opts?: {
18
+ staged?: boolean;
19
+ file?: string;
20
+ }): string;
21
+ export declare function getGitDiffStat(cwd: string, opts?: {
22
+ staged?: boolean;
23
+ file?: string;
24
+ }): string;
25
+ export declare function getGitLog(cwd: string, n?: number): GitLogEntry[];
26
+ export declare function getRemoteUrl(cwd: string): string | undefined;
27
+ export declare function gitAdd(cwd: string, files?: string[]): void;
28
+ export declare function gitCommit(cwd: string, message: string): string;
29
+ export declare function gitListBranches(cwd: string): {
30
+ name: string;
31
+ current: boolean;
32
+ }[];
33
+ export declare function gitCheckout(cwd: string, branch: string, create?: boolean): void;
34
+ export declare function ghAvailable(): boolean;
35
+ export declare function ghPrComments(cwd: string, prUrl: string): string;
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Git utility functions for the git workflow commands.
3
+ */
4
+ import { execSync } from "node:child_process";
5
+ export function isGitRepo(cwd) {
6
+ try {
7
+ execSync("git rev-parse --is-inside-work-tree", { cwd, encoding: "utf-8", timeout: 5000 });
8
+ return true;
9
+ }
10
+ catch {
11
+ return false;
12
+ }
13
+ }
14
+ export function getCurrentBranch(cwd) {
15
+ return execSync("git branch --show-current", { cwd, encoding: "utf-8", timeout: 5000 }).trim();
16
+ }
17
+ export function getGitStatus(cwd) {
18
+ const raw = execSync("git status --porcelain", { cwd, encoding: "utf-8", timeout: 10000 }).trim();
19
+ if (!raw)
20
+ return [];
21
+ return raw.split("\n").map((line) => ({
22
+ status: line.slice(0, 2).trim(),
23
+ path: line.slice(3),
24
+ }));
25
+ }
26
+ export function getGitDiff(cwd, opts) {
27
+ const args = ["git", "diff", "--no-color"];
28
+ if (opts?.staged)
29
+ args.push("--staged");
30
+ if (opts?.file)
31
+ args.push("--", opts.file);
32
+ return execSync(args.join(" "), { cwd, encoding: "utf-8", timeout: 30000 }).trim();
33
+ }
34
+ export function getGitDiffStat(cwd, opts) {
35
+ const args = ["git", "diff", "--stat", "--no-color"];
36
+ if (opts?.staged)
37
+ args.push("--staged");
38
+ if (opts?.file)
39
+ args.push("--", opts.file);
40
+ return execSync(args.join(" "), { cwd, encoding: "utf-8", timeout: 10000 }).trim();
41
+ }
42
+ export function getGitLog(cwd, n = 10) {
43
+ const raw = execSync(`git log --oneline --format="%H|%s|%an|%ci" -${n}`, { cwd, encoding: "utf-8", timeout: 10000 }).trim();
44
+ if (!raw)
45
+ return [];
46
+ return raw.split("\n").map((line) => {
47
+ const [hash, message, author, date] = line.split("|");
48
+ return { hash: hash.slice(0, 8), message, author, date };
49
+ });
50
+ }
51
+ export function getRemoteUrl(cwd) {
52
+ try {
53
+ return execSync("git remote get-url origin", { cwd, encoding: "utf-8", timeout: 5000 }).trim();
54
+ }
55
+ catch {
56
+ return undefined;
57
+ }
58
+ }
59
+ export function gitAdd(cwd, files = ["."]) {
60
+ const fileArgs = files.map((f) => `"${f}"`).join(" ");
61
+ execSync(`git add ${fileArgs}`, { cwd, timeout: 10000 });
62
+ }
63
+ export function gitCommit(cwd, message) {
64
+ return execSync(`git commit -m ${JSON.stringify(message)}`, {
65
+ cwd,
66
+ encoding: "utf-8",
67
+ timeout: 30000,
68
+ }).trim();
69
+ }
70
+ export function gitListBranches(cwd) {
71
+ const raw = execSync("git branch --no-color", { cwd, encoding: "utf-8", timeout: 5000 }).trim();
72
+ if (!raw)
73
+ return [];
74
+ return raw.split("\n").map((line) => ({
75
+ current: line.startsWith("*"),
76
+ name: line.replace(/^\*?\s+/, "").trim(),
77
+ }));
78
+ }
79
+ export function gitCheckout(cwd, branch, create = false) {
80
+ const flag = create ? "-b" : "";
81
+ execSync(`git checkout ${flag} ${branch}`, { cwd, timeout: 10000 });
82
+ }
83
+ export function ghAvailable() {
84
+ try {
85
+ execSync("gh --version", { encoding: "utf-8", timeout: 5000 });
86
+ return true;
87
+ }
88
+ catch {
89
+ return false;
90
+ }
91
+ }
92
+ export function ghPrComments(cwd, prUrl) {
93
+ return execSync(`gh pr view ${prUrl} --comments --json comments -q ".comments[].body"`, {
94
+ cwd,
95
+ encoding: "utf-8",
96
+ timeout: 30000,
97
+ }).trim();
98
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Git worktree management — create/remove isolated worktrees for agents.
3
+ */
4
+ export interface WorktreeSession {
5
+ originalCwd: string;
6
+ worktreePath: string;
7
+ worktreeName: string;
8
+ worktreeBranch: string;
9
+ originalBranch?: string;
10
+ sessionId: string;
11
+ createdAt: number;
12
+ }
13
+ /**
14
+ * Validate worktree slug to prevent path traversal attacks.
15
+ */
16
+ export declare function validateWorktreeSlug(slug: string): void;
17
+ /**
18
+ * Find the canonical git root (resolves worktree → main repo).
19
+ */
20
+ export declare function findGitRoot(cwd: string): string;
21
+ /**
22
+ * Create an isolated git worktree for an agent session.
23
+ */
24
+ export declare function createWorktree(cwd: string, slug: string, sessionId: string): WorktreeSession;
25
+ /**
26
+ * Remove a worktree and optionally its branch.
27
+ */
28
+ export declare function removeWorktree(worktreePath: string, removeBranch?: boolean): void;
29
+ /**
30
+ * List active worktrees.
31
+ */
32
+ export declare function listWorktrees(cwd: string): Array<{
33
+ path: string;
34
+ branch: string;
35
+ head: string;
36
+ }>;
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Git worktree management — create/remove isolated worktrees for agents.
3
+ */
4
+ import { execSync } from "node:child_process";
5
+ import { existsSync, symlinkSync, lstatSync } from "node:fs";
6
+ import { join, resolve } from "node:path";
7
+ /**
8
+ * Validate worktree slug to prevent path traversal attacks.
9
+ */
10
+ export function validateWorktreeSlug(slug) {
11
+ if (slug.length > 64)
12
+ throw new Error("Worktree slug too long (max 64 chars)");
13
+ if (/[^a-zA-Z0-9._-]/.test(slug))
14
+ throw new Error("Worktree slug contains invalid characters");
15
+ if (slug.startsWith(".") || slug.includes(".."))
16
+ throw new Error("Worktree slug cannot start with '.' or contain '..'");
17
+ }
18
+ /**
19
+ * Find the canonical git root (resolves worktree → main repo).
20
+ */
21
+ export function findGitRoot(cwd) {
22
+ return execSync("git rev-parse --show-toplevel", { cwd, encoding: "utf-8", timeout: 5000 }).trim();
23
+ }
24
+ /**
25
+ * Create an isolated git worktree for an agent session.
26
+ */
27
+ export function createWorktree(cwd, slug, sessionId) {
28
+ validateWorktreeSlug(slug);
29
+ const gitRoot = findGitRoot(cwd);
30
+ const branchName = `worktree/${slug}-${sessionId.slice(0, 8)}`;
31
+ const worktreePath = resolve(gitRoot, "..", `.worktrees/${slug}-${sessionId.slice(0, 8)}`);
32
+ // Get current branch for later reference
33
+ let originalBranch;
34
+ try {
35
+ originalBranch = execSync("git branch --show-current", {
36
+ cwd: gitRoot,
37
+ encoding: "utf-8",
38
+ timeout: 5000,
39
+ }).trim();
40
+ }
41
+ catch {
42
+ // Detached HEAD
43
+ }
44
+ // Create the worktree
45
+ execSync(`git worktree add -b "${branchName}" "${worktreePath}"`, {
46
+ cwd: gitRoot,
47
+ timeout: 30000,
48
+ });
49
+ // Symlink large directories to avoid disk bloat
50
+ symlinkLargeDirectories(gitRoot, worktreePath);
51
+ return {
52
+ originalCwd: cwd,
53
+ worktreePath,
54
+ worktreeName: slug,
55
+ worktreeBranch: branchName,
56
+ originalBranch,
57
+ sessionId,
58
+ createdAt: Date.now(),
59
+ };
60
+ }
61
+ /**
62
+ * Remove a worktree and optionally its branch.
63
+ */
64
+ export function removeWorktree(worktreePath, removeBranch = false) {
65
+ try {
66
+ const gitRoot = findGitRoot(worktreePath);
67
+ execSync(`git worktree remove "${worktreePath}" --force`, {
68
+ cwd: gitRoot,
69
+ timeout: 30000,
70
+ });
71
+ if (removeBranch) {
72
+ // Extract branch name from worktree
73
+ try {
74
+ const branch = execSync("git branch --show-current", {
75
+ cwd: worktreePath,
76
+ encoding: "utf-8",
77
+ timeout: 5000,
78
+ }).trim();
79
+ if (branch.startsWith("worktree/")) {
80
+ execSync(`git branch -D "${branch}"`, { cwd: gitRoot, timeout: 10000 });
81
+ }
82
+ }
83
+ catch {
84
+ // Branch might already be removed
85
+ }
86
+ }
87
+ }
88
+ catch {
89
+ // Worktree might already be removed
90
+ }
91
+ }
92
+ /**
93
+ * List active worktrees.
94
+ */
95
+ export function listWorktrees(cwd) {
96
+ const raw = execSync("git worktree list --porcelain", {
97
+ cwd,
98
+ encoding: "utf-8",
99
+ timeout: 10000,
100
+ }).trim();
101
+ if (!raw)
102
+ return [];
103
+ const entries = [];
104
+ let current = { path: "", branch: "", head: "" };
105
+ for (const line of raw.split("\n")) {
106
+ if (line.startsWith("worktree ")) {
107
+ if (current.path)
108
+ entries.push(current);
109
+ current = { path: line.slice(9), branch: "", head: "" };
110
+ }
111
+ else if (line.startsWith("HEAD ")) {
112
+ current.head = line.slice(5, 13);
113
+ }
114
+ else if (line.startsWith("branch ")) {
115
+ current.branch = line.slice(7).replace("refs/heads/", "");
116
+ }
117
+ }
118
+ if (current.path)
119
+ entries.push(current);
120
+ return entries;
121
+ }
122
+ /**
123
+ * Symlink large directories (node_modules, .venv, etc.) from main repo to worktree.
124
+ */
125
+ function symlinkLargeDirectories(sourceRoot, worktreePath) {
126
+ const largeDirs = ["node_modules", ".venv", "vendor", ".pnpm-store"];
127
+ for (const dir of largeDirs) {
128
+ const source = join(sourceRoot, dir);
129
+ const target = join(worktreePath, dir);
130
+ if (existsSync(source) && lstatSync(source).isDirectory() && !existsSync(target)) {
131
+ try {
132
+ symlinkSync(source, target, "dir");
133
+ }
134
+ catch {
135
+ // Symlink might fail on some systems
136
+ }
137
+ }
138
+ }
139
+ }
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Hook event type definitions.
3
+ */
4
+ /**
5
+ * Lifecycle hooks the engine emits.
6
+ *
7
+ * **Currently emitted** (handlers registered here will actually fire):
8
+ * - on_session_start / on_session_end (engine.ts) — fires once per Engine.run().
9
+ * on_session_start handlers may return
10
+ * `messages` to inject a <system-reminder>
11
+ * at the head of the conversation, before
12
+ * the current user prompt.
13
+ * - on_agent_start / on_agent_end (engine.ts) — notify-only; returned
14
+ * messages are NOT consumed (the loop
15
+ * is already armed by the time these
16
+ * fire). Use on_session_start instead.
17
+ * - user_prompt_submit (engine.ts) — fires once per run() for
18
+ * every new user prompt (cold-start and
19
+ * resume both qualify). Returned messages
20
+ * are merged into the same lifecycle
21
+ * <system-reminder> as on_session_start.
22
+ * - on_turn_start / on_turn_end (turn-loop.ts) — on_turn_start handlers
23
+ * may return `messages` to inject a
24
+ * per-turn reminder appended to the
25
+ * conversation right before the model call.
26
+ * - pre_tool_use / post_tool_use (executor.ts) — pre_tool_use honors
27
+ * `decision: "deny"` to short-circuit
28
+ * the call (executor.ts:131).
29
+ * - on_tool_start / on_tool_end (executor.ts)
30
+ * - file_changed (executor.ts, Write/Edit only)
31
+ * - on_permission_check (executor.ts) — fires after the
32
+ * classifier runs and before its
33
+ * decision is acted on. Handler can
34
+ * override via `decision`; the
35
+ * override is logged as
36
+ * `permission.hook_override`. ctx.data
37
+ * carries `classifierDecision` so
38
+ * handlers can branch on the rule
39
+ * set's verdict.
40
+ * - post_compact (turn-loop.ts) — fires after
41
+ * ContextManager.manageAsync() runs
42
+ * a non-micro compaction. Handlers
43
+ * may return `messages` to inject a
44
+ * <system-reminder> into the same
45
+ * turn before the model call. ctx.data
46
+ * carries `strategy` (summary/snip/
47
+ * window/emergency), `beforeTokens`,
48
+ * `afterTokens`. Microcompact is
49
+ * intentionally suppressed.
50
+ * - notification (agent.ts) — fired when a background
51
+ * sub-agent transitions to a terminal
52
+ * state. ctx.data carries `kind`
53
+ * ("agent_completed" / "agent_failed" /
54
+ * "agent_cancelled"), `agentId`,
55
+ * `name`, `description`, plus
56
+ * `finalText` (completed) or `error`
57
+ * (failed). Fired void — handler
58
+ * latency does not block the main
59
+ * loop. Not consumed by the engine
60
+ * (bg-agent feed renders the same
61
+ * info via notificationQueue);
62
+ * intended for shell hooks (osascript
63
+ * / desktop notifications).
64
+ *
65
+ * All Engine-side emits run through Engine.emitHook / TurnLoop.emitHook, which
66
+ * auto-merge `isSubAgent` (and sessionId, for turn-loop) into ctx.data so
67
+ * handlers can skip noisy injections for spawned children.
68
+ *
69
+ * **Reserved / not-yet-emitted** (defined so downstream can register handlers
70
+ * in anticipation; wire the emitter before relying on them):
71
+ * - pre_compact — would require pre-flight prediction inside
72
+ * ContextManager; current implementation only knows
73
+ * after-the-fact (use post_compact instead).
74
+ */
75
+ export type HookEventName = "on_agent_start" | "on_agent_end" | "on_turn_start" | "on_turn_end" | "on_tool_start" | "on_tool_end" | "on_permission_check" | "on_session_start" | "on_session_end" | "pre_tool_use" | "post_tool_use" | "user_prompt_submit" | "pre_compact" | "post_compact" | "file_changed" | "notification";
76
+ export interface HookContext {
77
+ eventName: HookEventName;
78
+ data: Record<string, unknown>;
79
+ sessionId?: string;
80
+ turnNumber?: number;
81
+ }
82
+ export interface HookResult {
83
+ /** If true, stop the hook chain */
84
+ stop?: boolean;
85
+ /** Modified data to pass along */
86
+ data?: Record<string, unknown>;
87
+ /** Additional messages to inject */
88
+ messages?: string[];
89
+ /** Allow/deny/ask override for permission hooks */
90
+ decision?: "allow" | "deny" | "ask";
91
+ /**
92
+ * For pre_tool_use: replace the tool's args before execution. Used by
93
+ * "sanitizer" handlers (e.g. redact secrets in Bash commands, normalize
94
+ * file paths, inject a default flag). Last handler in the chain wins.
95
+ * Args are re-validated against the tool's input schema before the
96
+ * tool runs, so a malformed updatedInput still surfaces as an
97
+ * "Invalid input" error rather than silently passing through.
98
+ */
99
+ updatedInput?: Record<string, unknown>;
100
+ /**
101
+ * For post_tool_use: text appended to the tool's content (visible to
102
+ * the model on the next LLM call). Used by linter/typecheck handlers
103
+ * to surface results without re-running the tool. Multiple handlers'
104
+ * additionalContext entries are joined with two newlines.
105
+ */
106
+ additionalContext?: string;
107
+ /**
108
+ * For user_prompt_submit: replace the most recent user message text
109
+ * with this string. Last handler wins. Used to auto-prepend project
110
+ * context, mask secrets, or rewrite shorthand prompts. The original
111
+ * prompt is logged at info level for audit purposes.
112
+ */
113
+ updatedPrompt?: string;
114
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Hook event type definitions.
3
+ */
4
+ export {};
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Hook message injection helper.
3
+ *
4
+ * Handlers return raw markdown strings via HookResult.messages. The emit
5
+ * site uses wrapHookMessages() to package them into a single user-role
6
+ * <system-reminder> Message so the model sees them as one block instead
7
+ * of a noisy sequence of separate user turns.
8
+ *
9
+ * Contract:
10
+ * - Handlers do NOT wrap their own <system-reminder>; emit-site owns the
11
+ * wrapper. Keeps formatting consistent and lets us evolve it (e.g. add
12
+ * a trailing close-tag, tag attributes) without touching every handler.
13
+ * - Empty / whitespace-only messages are dropped before wrapping; if
14
+ * nothing remains, returns null (caller skips the injection).
15
+ * - Multiple handlers' messages are joined with a blank line between
16
+ * blocks so each is visually distinct inside the reminder.
17
+ */
18
+ import type { Message } from "../types.js";
19
+ export declare function wrapHookMessages(messages: string[] | undefined): Message | null;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Hook message injection helper.
3
+ *
4
+ * Handlers return raw markdown strings via HookResult.messages. The emit
5
+ * site uses wrapHookMessages() to package them into a single user-role
6
+ * <system-reminder> Message so the model sees them as one block instead
7
+ * of a noisy sequence of separate user turns.
8
+ *
9
+ * Contract:
10
+ * - Handlers do NOT wrap their own <system-reminder>; emit-site owns the
11
+ * wrapper. Keeps formatting consistent and lets us evolve it (e.g. add
12
+ * a trailing close-tag, tag attributes) without touching every handler.
13
+ * - Empty / whitespace-only messages are dropped before wrapping; if
14
+ * nothing remains, returns null (caller skips the injection).
15
+ * - Multiple handlers' messages are joined with a blank line between
16
+ * blocks so each is visually distinct inside the reminder.
17
+ */
18
+ export function wrapHookMessages(messages) {
19
+ if (!messages?.length)
20
+ return null;
21
+ const cleaned = messages.map((m) => m.trim()).filter((m) => m.length > 0);
22
+ if (cleaned.length === 0)
23
+ return null;
24
+ const body = cleaned.join("\n\n");
25
+ return {
26
+ role: "user",
27
+ content: `<system-reminder>\n${body}\n</system-reminder>`,
28
+ };
29
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Hook registry with priority-based chain-of-responsibility execution.
3
+ */
4
+ import type { HookEventName, HookContext, HookResult } from "./events.js";
5
+ export type HookHandler = (ctx: HookContext) => HookResult | Promise<HookResult>;
6
+ export declare class HookRegistry {
7
+ private hooks;
8
+ register(eventName: HookEventName, handler: HookHandler, priority?: number, name?: string): void;
9
+ emit(eventName: HookEventName, data?: Record<string, unknown>): Promise<HookResult>;
10
+ hasHooks(eventName: HookEventName): boolean;
11
+ clear(eventName?: HookEventName): void;
12
+ listHooks(): Map<HookEventName, string[]>;
13
+ listEvents(): HookEventName[];
14
+ countHandlers(eventName: HookEventName): number;
15
+ }