@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,109 @@
1
+ /**
2
+ * macOS Seatbelt backend.
3
+ *
4
+ * Builds a sandbox-exec profile that:
5
+ * - Allows reading most of the filesystem (denying everything breaks tooling)
6
+ * - Denies reads of sensitive credential directories
7
+ * - Restricts writes to the workspace + writableRoots
8
+ * - Optionally denies outbound network
9
+ *
10
+ * The profile is written to a fresh temp file per command (cheap; users can
11
+ * have arbitrary writableRoots so we can't cache). The spawned process and
12
+ * its entire subprocess tree inherit the profile via XNU's sandbox framework.
13
+ *
14
+ * sandbox-exec is technically deprecated by Apple but remains the only
15
+ * working OS-level sandbox on macOS and is what Codex CLI / Cursor use today.
16
+ */
17
+ import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
18
+ import { tmpdir } from "node:os";
19
+ import { join } from "node:path";
20
+ export function createSeatbeltBackend(config) {
21
+ return {
22
+ name: "seatbelt",
23
+ wrap(command, opts) {
24
+ const profile = buildProfile(config);
25
+ const dir = mkdtempSync(join(tmpdir(), "codeshell-sandbox-"));
26
+ const profilePath = join(dir, "profile.sb");
27
+ writeFileSync(profilePath, profile, "utf-8");
28
+ return {
29
+ file: "/usr/bin/sandbox-exec",
30
+ args: ["-f", profilePath, opts.shell, "-c", command],
31
+ cleanup: () => {
32
+ // sandbox-exec has already exited (this runs from Bash tool's
33
+ // child `close` handler), so removing the profile file is safe.
34
+ // force=true swallows ENOENT in case the dir was already cleaned
35
+ // up out-of-band (e.g. system tmpwatch).
36
+ try {
37
+ rmSync(dir, { recursive: true, force: true });
38
+ }
39
+ catch {
40
+ // Best-effort. A leftover dir is recoverable; throwing here
41
+ // would mask the actual command output we just sent back.
42
+ }
43
+ },
44
+ };
45
+ },
46
+ hintForBlockedOutput(stderr) {
47
+ if (/Operation not permitted|sandbox/.test(stderr)) {
48
+ return ("\n[sandbox:seatbelt] A syscall was blocked by the sandbox. " +
49
+ "If this path should be writable or this network call legitimate, " +
50
+ "ask the user to update sandbox.writableRoots / sandbox.network in settings.json.");
51
+ }
52
+ return undefined;
53
+ },
54
+ };
55
+ }
56
+ function buildProfile(config) {
57
+ const writeAllows = config.writableRoots
58
+ .map((p) => ` (subpath ${quote(p)})`)
59
+ .join("\n");
60
+ const readDenies = config.deniedReads
61
+ .map((p) => ` (subpath ${quote(p)})`)
62
+ .join("\n");
63
+ const networkClause = config.network === "deny" ? "(deny network-outbound)" : "(allow network*)";
64
+ // SBPL evaluation note: when a broad `(allow file-read*)` and a specific
65
+ // `(deny file-read* (subpath …))` both match, the more specific subpath
66
+ // rule wins — order between the two clauses does not matter. We tested
67
+ // this empirically (both orderings block reads of denied subpaths) and
68
+ // the integration test in tests/sandbox.test.ts uses `cat <secret>` to
69
+ // verify reads are actually blocked, not just `ls`. The only previously
70
+ // observed leak was when the denied path was given as `/tmp/...` while
71
+ // `/tmp` symlinks to `/private/tmp`; sandbox-exec matches subpaths on
72
+ // canonical paths, so `expandConfig()` runs `realpathSync` up front.
73
+ return `(version 1)
74
+ (deny default)
75
+
76
+ ;; Process control
77
+ (allow process-fork)
78
+ (allow process-exec)
79
+ (allow signal (target self))
80
+ (allow signal (target children))
81
+
82
+ ;; Reads: broadly allowed, then explicit deny of sensitive paths
83
+ (allow file-read*)
84
+ ${readDenies ? `(deny file-read*\n${readDenies})` : ""}
85
+
86
+ ;; Writes: workspace + listed roots only
87
+ (allow file-write*
88
+ ${writeAllows})
89
+ (allow file-write-data
90
+ (literal "/dev/null")
91
+ (literal "/dev/zero")
92
+ (literal "/dev/random")
93
+ (literal "/dev/urandom")
94
+ (literal "/dev/dtracehelper"))
95
+
96
+ ;; IPC & system services common tools need
97
+ (allow mach-lookup)
98
+ (allow ipc-posix-shm)
99
+ (allow sysctl-read)
100
+ (allow system-socket)
101
+ (allow iokit-open)
102
+
103
+ ;; Network
104
+ ${networkClause}
105
+ `;
106
+ }
107
+ function quote(path) {
108
+ return `"${path.replace(/"/g, '\\"')}"`;
109
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * TaskGuard — nudges the model to update stale in_progress todos.
3
+ *
4
+ * Background: a TodoWrite snapshot is sticky in the model's working
5
+ * memory only for the first few turns. After enough intervening tool
6
+ * results (Read/Edit/Bash) the "I have an open todo" signal gets
7
+ * diluted and the model finishes its work without rewriting the
8
+ * snapshot — so the UI's pinned panel keeps showing an item as
9
+ * in_progress even though the model considers it done.
10
+ *
11
+ * Same shape as InvestigationGuard.turnEnded: the turn loop polls at
12
+ * the end of each turn; if anything is in_progress and hasn't been
13
+ * touched in N turns, we emit a <system-reminder> that lands at the
14
+ * top of the next turn.
15
+ *
16
+ * Re-nag policy: don't fire more than once per (todo, threshold)
17
+ * pair. Identity is the position-based id ("1", "2", …) carried on
18
+ * TaskInfo. Re-arranging the list creates a new identity, which is
19
+ * already a refresh, so the nag resets naturally.
20
+ */
21
+ import type { TaskInfo } from "../types.js";
22
+ export declare class TaskGuard {
23
+ private snapshotSource;
24
+ private lastNagTurn;
25
+ private inProgressSince;
26
+ constructor(snapshotSource: () => TaskInfo[]);
27
+ turnEnded(turnNumber: number): string | undefined;
28
+ reset(): void;
29
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * TaskGuard — nudges the model to update stale in_progress todos.
3
+ *
4
+ * Background: a TodoWrite snapshot is sticky in the model's working
5
+ * memory only for the first few turns. After enough intervening tool
6
+ * results (Read/Edit/Bash) the "I have an open todo" signal gets
7
+ * diluted and the model finishes its work without rewriting the
8
+ * snapshot — so the UI's pinned panel keeps showing an item as
9
+ * in_progress even though the model considers it done.
10
+ *
11
+ * Same shape as InvestigationGuard.turnEnded: the turn loop polls at
12
+ * the end of each turn; if anything is in_progress and hasn't been
13
+ * touched in N turns, we emit a <system-reminder> that lands at the
14
+ * top of the next turn.
15
+ *
16
+ * Re-nag policy: don't fire more than once per (todo, threshold)
17
+ * pair. Identity is the position-based id ("1", "2", …) carried on
18
+ * TaskInfo. Re-arranging the list creates a new identity, which is
19
+ * already a refresh, so the nag resets naturally.
20
+ */
21
+ const STALE_TURN_THRESHOLD = 3;
22
+ const RENAG_INTERVAL = 3;
23
+ export class TaskGuard {
24
+ snapshotSource;
25
+ lastNagTurn = new Map();
26
+ inProgressSince = new Map();
27
+ constructor(snapshotSource) {
28
+ this.snapshotSource = snapshotSource;
29
+ }
30
+ turnEnded(turnNumber) {
31
+ const tasks = this.snapshotSource();
32
+ const open = tasks.filter((t) => t.status === "in_progress");
33
+ const trackedIds = [...this.inProgressSince.keys()];
34
+ for (const id of trackedIds) {
35
+ const stillOpen = open.some((t) => t.id === id);
36
+ if (!stillOpen) {
37
+ this.inProgressSince.delete(id);
38
+ this.lastNagTurn.delete(id);
39
+ }
40
+ }
41
+ for (const t of open) {
42
+ if (!this.inProgressSince.has(t.id)) {
43
+ this.inProgressSince.set(t.id, turnNumber);
44
+ }
45
+ }
46
+ const stale = open
47
+ .map((t) => ({ task: t, age: turnNumber - (this.inProgressSince.get(t.id) ?? turnNumber) }))
48
+ .filter(({ task, age }) => {
49
+ if (age < STALE_TURN_THRESHOLD)
50
+ return false;
51
+ const last = this.lastNagTurn.get(task.id);
52
+ if (last === undefined)
53
+ return true;
54
+ return turnNumber - last >= RENAG_INTERVAL;
55
+ });
56
+ if (stale.length === 0)
57
+ return undefined;
58
+ for (const { task } of stale) {
59
+ this.lastNagTurn.set(task.id, turnNumber);
60
+ }
61
+ const lines = stale.map(({ task, age }) => ` - "${task.subject}" (in_progress for ${age} turns)`);
62
+ return (`<system-reminder>You have ${stale.length === 1 ? "an open" : `${stale.length} open`} in_progress todo${stale.length === 1 ? "" : "s"} that ${stale.length === 1 ? "has" : "have"} not been updated recently:\n` +
63
+ lines.join("\n") +
64
+ `\nCall TodoWrite again with the updated snapshot — mark items completed when done, or drop them if abandoned. The UI's pinned panel keeps showing in_progress until the next TodoWrite arrives.</system-reminder>`);
65
+ }
66
+ reset() {
67
+ this.lastNagTurn.clear();
68
+ this.inProgressSince.clear();
69
+ }
70
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Validate tool args against the tool's inputSchema.
3
+ * Returns null if valid, error string if invalid.
4
+ */
5
+ export declare function validateToolArgs(toolName: string, args: Record<string, unknown>, schema: Record<string, unknown>): string | null;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Validate tool args against the tool's inputSchema.
3
+ * Returns null if valid, error string if invalid.
4
+ */
5
+ export function validateToolArgs(toolName, args, schema) {
6
+ try {
7
+ const properties = schema.properties;
8
+ const required = schema.required ?? [];
9
+ if (!properties)
10
+ return null;
11
+ // Check required fields
12
+ for (const field of required) {
13
+ if (args[field] === undefined || args[field] === null) {
14
+ return `Missing required parameter: ${field}`;
15
+ }
16
+ }
17
+ // Type check each provided field
18
+ for (const [key, value] of Object.entries(args)) {
19
+ const propSchema = properties[key];
20
+ if (!propSchema)
21
+ continue; // Extra fields are OK
22
+ const expectedType = propSchema.type;
23
+ const actualType = typeof value;
24
+ if (expectedType === "string" && actualType !== "string") {
25
+ return `Parameter '${key}' must be a string, got ${actualType}`;
26
+ }
27
+ if (expectedType === "number" && actualType !== "number") {
28
+ return `Parameter '${key}' must be a number, got ${actualType}`;
29
+ }
30
+ if (expectedType === "boolean" && actualType !== "boolean") {
31
+ return `Parameter '${key}' must be a boolean, got ${actualType}`;
32
+ }
33
+ }
34
+ return null;
35
+ }
36
+ catch {
37
+ return null; // Don't block on validation errors
38
+ }
39
+ }
@@ -0,0 +1,376 @@
1
+ /**
2
+ * Core type definitions for the code-shell orchestration framework.
3
+ */
4
+ export interface ContentBlock {
5
+ type: "text" | "tool_use" | "tool_result" | "image" | "reasoning";
6
+ text?: string;
7
+ id?: string;
8
+ name?: string;
9
+ input?: Record<string, unknown>;
10
+ content?: string | ContentBlock[];
11
+ tool_use_id?: string;
12
+ source?: {
13
+ type: "base64";
14
+ media_type: string;
15
+ data: string;
16
+ };
17
+ reasoningContent?: string;
18
+ }
19
+ export interface Message {
20
+ role: "system" | "user" | "assistant" | "tool";
21
+ content: string | ContentBlock[];
22
+ name?: string;
23
+ tool_call_id?: string;
24
+ }
25
+ export interface ToolDefinition {
26
+ name: string;
27
+ description: string;
28
+ inputSchema: Record<string, unknown>;
29
+ }
30
+ export interface ToolCall {
31
+ id: string;
32
+ toolName: string;
33
+ serverName?: string;
34
+ args: Record<string, unknown>;
35
+ }
36
+ export interface ToolResult {
37
+ id: string;
38
+ toolName: string;
39
+ result?: string;
40
+ error?: string;
41
+ isError?: boolean;
42
+ }
43
+ export type ToolSource = "builtin" | "mcp";
44
+ export interface RegisteredTool {
45
+ name: string;
46
+ description: string;
47
+ inputSchema: Record<string, unknown>;
48
+ source: ToolSource;
49
+ serverName?: string;
50
+ permissionDefault: PermissionDecision;
51
+ isConcurrencySafe?: boolean;
52
+ isReadOnly?: boolean;
53
+ /**
54
+ * Override the default tool execution timeout (ms).
55
+ * Falls back to DEFAULT_TOOL_TIMEOUT_MS (120s) if unset.
56
+ * The caller of executeTool() can still override via options.timeoutMs.
57
+ */
58
+ timeoutMs?: number;
59
+ }
60
+ export type TranscriptEventType = "message" | "tool_use" | "tool_result" | "summary" | "content_replace" | "file_history" | "plan_operation" | "session_meta" | "turn_boundary" | "error";
61
+ export interface TranscriptEvent {
62
+ id: string;
63
+ type: TranscriptEventType;
64
+ timestamp: number;
65
+ turnNumber: number;
66
+ data: Record<string, unknown>;
67
+ }
68
+ /**
69
+ * Session lifecycle state persisted in state.json. `"active"` means a run is
70
+ * currently in flight (or was, at the moment of the last heartbeat). All other
71
+ * values match the {@link TerminalReason} the last run returned, so callers
72
+ * can distinguish a user-cancelled session (`"aborted_streaming"`) from an
73
+ * actual error (`"model_error"`, `"prompt_too_long"`, ...).
74
+ */
75
+ export type SessionStatus = "active" | "paused" | TerminalReason;
76
+ export interface SessionState {
77
+ sessionId: string;
78
+ cwd: string;
79
+ startedAt: number;
80
+ model: string;
81
+ provider: string;
82
+ tokenUsage: TokenUsage;
83
+ turnCount: number;
84
+ invokedSkills: string[];
85
+ parentSessionId?: string;
86
+ status: SessionStatus;
87
+ /** Short summary derived from the first user message */
88
+ summary?: string;
89
+ /** Persisted cost tracking state (survives process restart). */
90
+ costState?: Record<string, unknown>;
91
+ }
92
+ export interface TokenUsage {
93
+ promptTokens: number;
94
+ completionTokens: number;
95
+ totalTokens: number;
96
+ cacheReadTokens?: number;
97
+ cacheCreationTokens?: number;
98
+ }
99
+ export interface CompiledInput {
100
+ messages: Message[];
101
+ rawText: string;
102
+ options: InputOptions;
103
+ }
104
+ export interface InputOptions {
105
+ slashCommand?: string;
106
+ attachments?: Attachment[];
107
+ mentionedFiles?: string[];
108
+ images?: ImageAttachment[];
109
+ allowedTools?: string[];
110
+ modelOverride?: string;
111
+ }
112
+ export interface Attachment {
113
+ path: string;
114
+ content: string;
115
+ mimeType: string;
116
+ }
117
+ export interface ImageAttachment {
118
+ data: string;
119
+ mediaType: string;
120
+ }
121
+ export type PermissionDecision = "allow" | "deny" | "ask";
122
+ export type PermissionMode = "default" | "acceptEdits" | "dontAsk" | "bypassPermissions" | "auto" | "plan";
123
+ export interface PermissionRule {
124
+ tool: string;
125
+ argsPattern?: Record<string, string | RegExp>;
126
+ decision: PermissionDecision;
127
+ reason?: string;
128
+ }
129
+ export interface ApprovalRequest {
130
+ toolName: string;
131
+ args: Record<string, unknown>;
132
+ description: string;
133
+ riskLevel: "low" | "medium" | "high";
134
+ }
135
+ /**
136
+ * Scope of an "always allow" decision.
137
+ * "once" — this single call only (default when always not set)
138
+ * "session" — remembered for the rest of the REPL session (in-memory)
139
+ * "project" — persisted to <cwd>/.code-shell/settings.local.json so it
140
+ * survives restart for the current project. Not committed.
141
+ */
142
+ export type ApprovalScope = "once" | "session" | "project";
143
+ export type ApprovalResult = {
144
+ approved: true;
145
+ permanent?: boolean;
146
+ always?: boolean;
147
+ scope?: ApprovalScope;
148
+ /** Used by AskUserQuestion to carry the user's free-text answer. */ answer?: string;
149
+ } | {
150
+ approved: false;
151
+ reason?: string;
152
+ always?: boolean;
153
+ scope?: ApprovalScope;
154
+ };
155
+ export type TurnPhase = "pre_check" | "model_call" | "post_check" | "tool_exec" | "context_mgmt" | "hook_notify" | "complete" | "error";
156
+ export interface TurnResult {
157
+ text: string;
158
+ toolCalls: ToolCall[];
159
+ status: "completed" | "tool_use" | "error" | "max_turns" | "aborted";
160
+ error?: string;
161
+ }
162
+ export type TerminalReason = "completed" | "stop_hook_prevented" | "hook_stopped" | "prompt_too_long" | "model_error" | "aborted_streaming" | "aborted_tools" | "max_turns" | "image_error";
163
+ export interface TaskInfo {
164
+ id: string;
165
+ subject: string;
166
+ activeForm?: string;
167
+ status: "pending" | "in_progress" | "completed" | "stopped";
168
+ }
169
+ export type StreamEvent = {
170
+ type: "session_started";
171
+ sessionId: string;
172
+ promptTokens: number;
173
+ } | {
174
+ type: "stream_request_start";
175
+ turnNumber: number;
176
+ agentId?: string;
177
+ } | {
178
+ type: "text_delta";
179
+ text: string;
180
+ tokens?: number;
181
+ agentId?: string;
182
+ } | {
183
+ type: "tool_use_start";
184
+ toolCall: ToolCall;
185
+ agentId?: string;
186
+ } | {
187
+ type: "tool_use_args_delta";
188
+ toolCallId: string;
189
+ args: Record<string, unknown>;
190
+ agentId?: string;
191
+ } | {
192
+ type: "tool_result";
193
+ result: ToolResult;
194
+ agentId?: string;
195
+ } | {
196
+ type: "assistant_message";
197
+ message: Message;
198
+ agentId?: string;
199
+ } | {
200
+ type: "turn_complete";
201
+ reason: TerminalReason;
202
+ agentId?: string;
203
+ } | {
204
+ type: "error";
205
+ error: string;
206
+ agentId?: string;
207
+ } | {
208
+ type: "tombstone";
209
+ messageId: string;
210
+ } | {
211
+ type: "task_update";
212
+ tasks: TaskInfo[];
213
+ } | {
214
+ type: "thinking_delta";
215
+ text: string;
216
+ agentId?: string;
217
+ } | {
218
+ type: "agent_start";
219
+ agentId: string;
220
+ name?: string;
221
+ description: string;
222
+ } | {
223
+ type: "agent_end";
224
+ agentId: string;
225
+ name?: string;
226
+ description: string;
227
+ text?: string;
228
+ error?: string;
229
+ } | {
230
+ type: "tool_summary";
231
+ summary: string;
232
+ } | {
233
+ type: "context_compact";
234
+ strategy: "micro" | "summary" | "window" | "snip" | "emergency";
235
+ before: number;
236
+ after: number;
237
+ agentId?: string;
238
+ } | {
239
+ type: "usage_update";
240
+ promptTokens: number;
241
+ agentId?: string;
242
+ } | {
243
+ type: "background_agent_completed";
244
+ agentId: string;
245
+ name?: string;
246
+ description: string;
247
+ status: "completed" | "failed";
248
+ /** Final assistant text (status === "completed" only). */
249
+ finalText?: string;
250
+ /** Error message (status === "failed" only). */
251
+ error?: string;
252
+ /** When the bg agent finished (Date.now() value). */
253
+ enqueuedAt: number;
254
+ };
255
+ /**
256
+ * Convenience extraction so SDK consumers and tests can import the
257
+ * `background_agent_completed` payload shape without re-destructuring
258
+ * the StreamEvent union themselves.
259
+ */
260
+ export type BackgroundAgentCompletedEvent = Extract<StreamEvent, {
261
+ type: "background_agent_completed";
262
+ }>;
263
+ export type StreamCallback = (event: StreamEvent) => void | Promise<void>;
264
+ export interface LLMConfig {
265
+ provider: string;
266
+ model: string;
267
+ apiKey?: string;
268
+ baseUrl?: string;
269
+ temperature?: number;
270
+ topP?: number;
271
+ maxTokens?: number;
272
+ timeout?: number;
273
+ retryMaxAttempts?: number;
274
+ enableStreaming?: boolean;
275
+ /**
276
+ * Default thinking-mode for DeepSeek V4. Per-call `options.thinking`
277
+ * (e.g. summarize sub-calls) overrides this. Ignored on other providers.
278
+ */
279
+ thinking?: "enabled" | "disabled";
280
+ /**
281
+ * The provider's `kind` (deepseek/openai/zai/openrouter/...). Used by
282
+ * the capability layer to look up per-(kind, model) request-shape rules
283
+ * (token-limit field, rejected sampling params, thinking shape, etc.).
284
+ * Distinct from `provider` above, which is the protocol family
285
+ * ("openai" or "anthropic") that picks which client class to use.
286
+ */
287
+ providerKind?: string;
288
+ }
289
+ export interface LLMResponse {
290
+ text: string;
291
+ toolCalls: ToolCall[];
292
+ usage?: TokenUsage;
293
+ stopReason?: string;
294
+ reasoningContent?: string;
295
+ }
296
+ export interface LLMStreamChunk {
297
+ type: "text" | "tool_use_start" | "tool_use_delta" | "tool_use_end" | "stop";
298
+ text?: string;
299
+ /** Token count for this text delta, when provider can compute it. */
300
+ tokens?: number;
301
+ toolCall?: Partial<ToolCall>;
302
+ stopReason?: string;
303
+ }
304
+ export type MCPTransport = "stdio" | "sse" | "streamable-http" | "inprocess";
305
+ export interface MCPServerConfig {
306
+ name: string;
307
+ command?: string;
308
+ args?: string[];
309
+ env?: Record<string, string>;
310
+ url?: string;
311
+ transport?: MCPTransport;
312
+ headers?: Record<string, string>;
313
+ }
314
+ /**
315
+ * Shell-hook configuration entry from settings.json. Each entry binds
316
+ * a hook event to a shell command. The command runs as a child process
317
+ * on every emit (filtered by `matcher` when present), receives ctx
318
+ * JSON on stdin, and returns a HookResult JSON on stdout. See
319
+ * src/hooks/shell-runner.ts for the protocol spec.
320
+ */
321
+ export interface SettingsHookConfig {
322
+ event: string;
323
+ command: string;
324
+ /**
325
+ * Optional regex (matched with new RegExp(matcher).test(toolName)) to
326
+ * filter which tools fire this hook. Currently honored for
327
+ * pre_tool_use / post_tool_use / on_tool_start / on_tool_end /
328
+ * on_permission_check / file_changed. Ignored for events without a
329
+ * meaningful toolName (session/turn/prompt/notification/compact).
330
+ */
331
+ matcher?: string;
332
+ /** Per-hook timeout in milliseconds. Defaults to 60_000. */
333
+ timeout_ms?: number;
334
+ /**
335
+ * Optional working directory for the spawned command. Defaults to
336
+ * Engine.cwd. Useful for hooks that need to run in a sibling repo.
337
+ */
338
+ cwd?: string;
339
+ }
340
+ export interface Settings {
341
+ model: {
342
+ provider: string;
343
+ name: string;
344
+ apiKey?: string;
345
+ baseUrl?: string;
346
+ temperature?: number;
347
+ maxTokens?: number;
348
+ };
349
+ permissions: {
350
+ defaultMode: PermissionMode;
351
+ rules: PermissionRule[];
352
+ };
353
+ context: {
354
+ maxTokens: number;
355
+ compactAtRatio: number;
356
+ summarizeAtRatio: number;
357
+ };
358
+ session: {
359
+ storageDir: string;
360
+ maxHistory: number;
361
+ };
362
+ mcpServers: Record<string, MCPServerConfig>;
363
+ instructions: {
364
+ fileName: string;
365
+ scanDirs: string[];
366
+ };
367
+ output: {
368
+ format: "text" | "json" | "jsonl" | "stream-json";
369
+ };
370
+ /**
371
+ * Optional shell-hook entries. Engine reads on construction and
372
+ * registers a wrapper handler per entry that spawns the command and
373
+ * parses the HookResult. Empty / missing = no shell hooks.
374
+ */
375
+ hooks?: SettingsHookConfig[];
376
+ }
package/dist/types.js ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Core type definitions for the code-shell orchestration framework.
3
+ */
4
+ export {};