@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,81 @@
1
+ /**
2
+ * sanitizeApiKey — defensive cleanup for API keys pasted via the wizard.
3
+ *
4
+ * Windows terminals (ConPTY, legacy cmd.exe, IME-active states) are the main
5
+ * source of breakage: bracketed-paste residue, CR endings, zero-width chars
6
+ * pulled in from rich-text sources (Notion / OneNote / web pages), full-width
7
+ * spaces from CJK IME, smart quotes from word processors. None of these are
8
+ * valid in any real provider's API key, so we strip them and warn.
9
+ */
10
+ const BRACKETED_PASTE_START = /^\x1b\[200~/;
11
+ const BRACKETED_PASTE_END = /\x1b\[201~$/;
12
+ // Zero-width + BOM + word joiner. These render as nothing but break auth.
13
+ // U+200B ZWSP, U+200C ZWNJ, U+200D ZWJ, U+2060 WORD JOINER, U+FEFF BOM.
14
+ // eslint-disable-next-line no-irregular-whitespace
15
+ const INVISIBLE_CHARS = /[​-‍⁠]/g;
16
+ // CJK full-width space (U+3000) — IME residue. Normal space is U+0020.
17
+ // eslint-disable-next-line no-irregular-whitespace
18
+ const FULLWIDTH_SPACE = / /g;
19
+ // Smart quotes — Word / web pages auto-convert ASCII quotes. Real keys
20
+ // never contain quotes, so strip them rather than replace.
21
+ // U+2018 ‘, U+2019 ’, U+201C “, U+201D ”.
22
+ const SMART_QUOTES = /[‘’“”]/g;
23
+ // All C0 (0x00-0x1F) and C1 (0x7F-0x9F) control chars, plus DEL.
24
+ // eslint-disable-next-line no-control-regex
25
+ const CONTROL_CHARS = /[\x00-\x1F\x7F-\x9F]/g;
26
+ export function sanitizeApiKey(raw) {
27
+ const warnings = [];
28
+ let v = raw;
29
+ // 1. Strip bracketed-paste wrapper if it leaked through parse-keypress.
30
+ if (BRACKETED_PASTE_START.test(v) || BRACKETED_PASTE_END.test(v)) {
31
+ v = v.replace(BRACKETED_PASTE_START, "").replace(BRACKETED_PASTE_END, "");
32
+ warnings.push("已剥离终端粘贴包裹符");
33
+ }
34
+ // 2. Drop every line break — keys are single-line.
35
+ if (/[\r\n]/.test(v)) {
36
+ v = v.replace(/[\r\n]+/g, "");
37
+ warnings.push("已移除换行符");
38
+ }
39
+ // 3. Invisible / zero-width characters.
40
+ if (INVISIBLE_CHARS.test(v)) {
41
+ v = v.replace(INVISIBLE_CHARS, "");
42
+ warnings.push("已移除零宽字符");
43
+ }
44
+ // 4. Full-width space (IME).
45
+ if (FULLWIDTH_SPACE.test(v)) {
46
+ v = v.replace(FULLWIDTH_SPACE, "");
47
+ warnings.push("已移除全角空格");
48
+ }
49
+ // 5. Smart quotes (Word/web).
50
+ if (SMART_QUOTES.test(v)) {
51
+ v = v.replace(SMART_QUOTES, "");
52
+ warnings.push("已移除中文/智能引号");
53
+ }
54
+ // 6. Any other control character (NUL, ESC, …).
55
+ if (CONTROL_CHARS.test(v)) {
56
+ v = v.replace(CONTROL_CHARS, "");
57
+ warnings.push("已移除控制字符");
58
+ }
59
+ // 7. Trim ASCII whitespace last.
60
+ const trimmed = v.trim();
61
+ if (trimmed !== v) {
62
+ v = trimmed;
63
+ // Don't warn on plain leading/trailing space — too noisy and obvious.
64
+ }
65
+ const changed = v !== raw;
66
+ return { value: v, changed, warnings };
67
+ }
68
+ /**
69
+ * Returns true when the sanitized key contains any non-ASCII-printable
70
+ * character. Real provider keys are uniformly ASCII (`[A-Za-z0-9_\-.]`-ish),
71
+ * so a stray non-ASCII char almost certainly means the user pasted the wrong
72
+ * thing (e.g. the surrounding sentence in Chinese).
73
+ */
74
+ export function hasNonAsciiPrintable(s) {
75
+ for (let i = 0; i < s.length; i++) {
76
+ const c = s.charCodeAt(i);
77
+ if (c < 0x20 || c > 0x7e)
78
+ return true;
79
+ }
80
+ return false;
81
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Capability layer — single entry point.
3
+ *
4
+ * `capabilitiesFor(kind, model)` walks the rules in `rules.ts`, returns
5
+ * a `Capability` describing what params the (provider, model) pair will
6
+ * accept. Clients spread the result into their request-build code.
7
+ *
8
+ * Pure function. No I/O, no caching beyond the rules array.
9
+ */
10
+ import type { ProviderKindName } from "../provider-kinds.js";
11
+ import { type Capability } from "./types.js";
12
+ export { DEFAULT_CAPABILITY } from "./types.js";
13
+ export type { Capability, ReasoningShape, ReasoningEffort, ThinkingSwitch, EchoReasoning, ParallelToolCallsShape, StreamUsageShape, } from "./types.js";
14
+ /**
15
+ * Resolve the capability for a given (provider kind, model id).
16
+ *
17
+ * First matching rule for the kind wins — rules.ts is ordered so that
18
+ * more specific patterns come before catch-alls.
19
+ */
20
+ export declare function capabilitiesFor(kind: ProviderKindName, model: string): Capability;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Capability layer — single entry point.
3
+ *
4
+ * `capabilitiesFor(kind, model)` walks the rules in `rules.ts`, returns
5
+ * a `Capability` describing what params the (provider, model) pair will
6
+ * accept. Clients spread the result into their request-build code.
7
+ *
8
+ * Pure function. No I/O, no caching beyond the rules array.
9
+ */
10
+ import { RULES } from "./rules.js";
11
+ import { DEFAULT_CAPABILITY, } from "./types.js";
12
+ export { DEFAULT_CAPABILITY } from "./types.js";
13
+ /**
14
+ * Resolve the capability for a given (provider kind, model id).
15
+ *
16
+ * First matching rule for the kind wins — rules.ts is ordered so that
17
+ * more specific patterns come before catch-alls.
18
+ */
19
+ export function capabilitiesFor(kind, model) {
20
+ for (const rule of RULES) {
21
+ if (rule.kind !== kind)
22
+ continue;
23
+ if (!rule.match.test(model))
24
+ continue;
25
+ return {
26
+ ...DEFAULT_CAPABILITY,
27
+ ...rule.capability,
28
+ // Set fields need explicit merge — Object spread copies the
29
+ // reference but the caller might mutate it. Keep DEFAULT immutable.
30
+ rejectedParams: rule.capability.rejectedParams
31
+ ? new Set(rule.capability.rejectedParams)
32
+ : new Set(DEFAULT_CAPABILITY.rejectedParams),
33
+ };
34
+ }
35
+ return {
36
+ ...DEFAULT_CAPABILITY,
37
+ rejectedParams: new Set(DEFAULT_CAPABILITY.rejectedParams),
38
+ };
39
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Per-(provider kind, model family) capability overrides.
3
+ *
4
+ * Each rule patches the conservative DEFAULT_CAPABILITY. First match per
5
+ * kind wins — order matters for overlapping families.
6
+ *
7
+ * Authority for every entry is the vendor's own docs; the `why` field
8
+ * cites the specific page. When a model 400s on something not captured
9
+ * here, add a rule, don't patch the client.
10
+ *
11
+ * Sources audited 2026-05-15:
12
+ * OpenAI: https://platform.openai.com/docs/guides/reasoning
13
+ * https://learn.microsoft.com/en-us/azure/foundry/openai/how-to/reasoning
14
+ * Anthropic: https://platform.claude.com/docs/en/build-with-claude/extended-thinking
15
+ * DeepSeek: https://api-docs.deepseek.com/guides/reasoning_model
16
+ * https://api-docs.deepseek.com/guides/thinking_mode
17
+ * Z.AI: https://docs.z.ai/guides/llm/glm-4.6
18
+ * Gemini: https://ai.google.dev/gemini-api/docs/openai
19
+ * https://ai.google.dev/gemini-api/docs/thinking
20
+ * OpenRouter: https://openrouter.ai/docs/guides/best-practices/reasoning-tokens
21
+ * xAI: https://docs.x.ai/docs/guides/reasoning
22
+ * Mistral: https://docs.mistral.ai/api/
23
+ * Groq: https://console.groq.com/docs/reasoning
24
+ */
25
+ import type { CapabilityRule } from "./types.js";
26
+ export declare const RULES: ReadonlyArray<CapabilityRule>;
@@ -0,0 +1,215 @@
1
+ /**
2
+ * Per-(provider kind, model family) capability overrides.
3
+ *
4
+ * Each rule patches the conservative DEFAULT_CAPABILITY. First match per
5
+ * kind wins — order matters for overlapping families.
6
+ *
7
+ * Authority for every entry is the vendor's own docs; the `why` field
8
+ * cites the specific page. When a model 400s on something not captured
9
+ * here, add a rule, don't patch the client.
10
+ *
11
+ * Sources audited 2026-05-15:
12
+ * OpenAI: https://platform.openai.com/docs/guides/reasoning
13
+ * https://learn.microsoft.com/en-us/azure/foundry/openai/how-to/reasoning
14
+ * Anthropic: https://platform.claude.com/docs/en/build-with-claude/extended-thinking
15
+ * DeepSeek: https://api-docs.deepseek.com/guides/reasoning_model
16
+ * https://api-docs.deepseek.com/guides/thinking_mode
17
+ * Z.AI: https://docs.z.ai/guides/llm/glm-4.6
18
+ * Gemini: https://ai.google.dev/gemini-api/docs/openai
19
+ * https://ai.google.dev/gemini-api/docs/thinking
20
+ * OpenRouter: https://openrouter.ai/docs/guides/best-practices/reasoning-tokens
21
+ * xAI: https://docs.x.ai/docs/guides/reasoning
22
+ * Mistral: https://docs.mistral.ai/api/
23
+ * Groq: https://console.groq.com/docs/reasoning
24
+ */
25
+ export const RULES = [
26
+ // ─── OpenAI native — gpt-5.5+ (and presumably 5.6+) ────────────
27
+ // gpt-5.5 dropped 'minimal' from reasoning_effort and added 'xhigh'.
28
+ // Supported values are now {none, low, medium, high, xhigh}.
29
+ // Trying to send 'minimal' returns a 400 that the SDK surfaces as
30
+ // "Request was aborted". List this rule BEFORE the broader gpt-5
31
+ // rule so 5.5+ doesn't fall into the old shape.
32
+ {
33
+ kind: "openai",
34
+ match: /^gpt-5\.(?:[5-9]|\d{2,})(?:[-.]|$)/i,
35
+ capability: {
36
+ supportsVision: true,
37
+ tokenLimitField: "max_completion_tokens",
38
+ rejectedParams: new Set([
39
+ "temperature", "top_p", "presence_penalty",
40
+ "frequency_penalty", "logit_bias", "logprobs", "top_logprobs",
41
+ ]),
42
+ reasoning: { kind: "openai-effort", disabledEffort: "none" },
43
+ echoReasoning: "optional",
44
+ },
45
+ why: "OpenAI gpt-5.5+ accepts reasoning_effort none|low|medium|high|xhigh (no `minimal`).",
46
+ },
47
+ // ─── OpenAI native — o-series + gpt-5 through gpt-5.4 ──────────
48
+ {
49
+ kind: "openai",
50
+ // o1/o3/o4-mini + gpt-5/5.1/5.2/5.3/5.4 + future digits.
51
+ // Anchored to start so OpenRouter-prefixed ids like `openai/gpt-5`
52
+ // never match this rule (OpenRouter rule below handles those).
53
+ match: /^(?:o[1-9]\d*|gpt-[5-9])(?:[-.]|$)/i,
54
+ capability: {
55
+ supportsVision: true,
56
+ tokenLimitField: "max_completion_tokens",
57
+ rejectedParams: new Set([
58
+ "temperature", "top_p", "presence_penalty",
59
+ "frequency_penalty", "logit_bias", "logprobs", "top_logprobs",
60
+ ]),
61
+ reasoning: { kind: "openai-effort" },
62
+ echoReasoning: "optional",
63
+ },
64
+ why: "OpenAI o-series + gpt-5..5.4 reject classic sampling params; use max_completion_tokens + reasoning_effort.",
65
+ },
66
+ // ─── DeepSeek ──────────────────────────────────────────────────
67
+ {
68
+ kind: "deepseek",
69
+ match: /^deepseek-v4(?:[-.]|$)/i,
70
+ capability: {
71
+ reasoning: { kind: "deepseek-thinking" },
72
+ // V4 + tools requires reasoning_content echoed; non-tool turns optional.
73
+ // Empty-string echo triggers an endpoint regression where the model
74
+ // returns an empty content. We backfill only when thinking is ON.
75
+ echoReasoning: "when-tools",
76
+ },
77
+ why: "DeepSeek V4 thinking mode — top-level thinking:{type}; echo reasoning_content when tools are present.",
78
+ },
79
+ {
80
+ kind: "deepseek",
81
+ match: /^deepseek-reasoner(?:[-.]|$)/i,
82
+ capability: {
83
+ reasoning: { kind: "none" },
84
+ // Sending reasoning_content back makes deepseek-reasoner 400.
85
+ echoReasoning: "never",
86
+ },
87
+ why: "deepseek-reasoner refuses prior reasoning_content in input; always-on reasoning, no toggle.",
88
+ },
89
+ // ─── Z.AI (GLM) ────────────────────────────────────────────────
90
+ {
91
+ kind: "zai",
92
+ // GLM-4.5, 4.6, 5.1 — same `thinking:{type}` shape as DeepSeek V4.
93
+ match: /^glm-[4-9](?:[-.]|$)/i,
94
+ capability: {
95
+ reasoning: { kind: "deepseek-thinking" },
96
+ echoReasoning: "optional",
97
+ },
98
+ why: "Z.AI GLM-4.5+ thinking shape is identical to DeepSeek V4; default is enabled.",
99
+ },
100
+ // ─── Anthropic direct ─────────────────────────────────────────
101
+ // Older Claude 4.x (≤4.5) accept explicit thinking:{type, budget_tokens}.
102
+ // The newer 4.6+ family (Opus 4.7 included) is adaptive — sending the
103
+ // opt-in field 400s. We check 4.6 boundary numerically below.
104
+ {
105
+ kind: "anthropic",
106
+ match: /^claude-(?:opus|sonnet|haiku)-4-[6-9](?:[-.]|$)/i,
107
+ capability: {
108
+ supportsVision: true,
109
+ reasoning: { kind: "anthropic-adaptive" },
110
+ echoReasoning: "when-tools",
111
+ parallelToolCalls: "anthropic-disable-flag",
112
+ streamUsage: "auto",
113
+ },
114
+ why: "Claude 4.6+ thinking is adaptive — no opt-in field. Echo thinking blocks on tool turns.",
115
+ },
116
+ {
117
+ kind: "anthropic",
118
+ match: /^claude-(?:opus|sonnet|haiku)-4(?:[-.]|$)/i,
119
+ capability: {
120
+ supportsVision: true,
121
+ reasoning: { kind: "anthropic-budget", minBudgetTokens: 1024 },
122
+ echoReasoning: "when-tools",
123
+ parallelToolCalls: "anthropic-disable-flag",
124
+ streamUsage: "auto",
125
+ },
126
+ why: "Claude 4.x ≤4.5 supports explicit thinking:{type:enabled, budget_tokens≥1024}.",
127
+ },
128
+ // Catch-all for Claude 3.x and earlier — no thinking field, but still
129
+ // needs Anthropic-shape tool_choice. Claude 3+ all support vision.
130
+ {
131
+ kind: "anthropic",
132
+ match: /^claude-/i,
133
+ capability: {
134
+ supportsVision: true,
135
+ parallelToolCalls: "anthropic-disable-flag",
136
+ streamUsage: "auto",
137
+ },
138
+ why: "Pre-Claude-4 — no extended thinking; keep Anthropic tool_choice/stream shape; vision supported since Claude 3.",
139
+ },
140
+ // ─── Gemini (OpenAI-compat endpoint) ───────────────────────────
141
+ {
142
+ kind: "google",
143
+ // 2.5+ all support thinking; OpenAI-compat surface maps reasoning_effort
144
+ // to thinkingConfig. Lite/flash families also accept it.
145
+ match: /^gemini-(?:[2-9]\.\d|[2-9])/i,
146
+ capability: {
147
+ supportsVision: true,
148
+ reasoning: { kind: "openai-effort" },
149
+ echoReasoning: "optional",
150
+ },
151
+ why: "Gemini 2.5+ via OpenAI-compat — reasoning_effort is auto-mapped to thinking_level; multimodal native.",
152
+ },
153
+ // ─── OpenRouter ────────────────────────────────────────────────
154
+ // OpenRouter normalizes everything under {reasoning: {...}}. It also
155
+ // accepts max_tokens for every model it routes (internal mapping).
156
+ // OpenRouter rules — check vision-specific backends first so the
157
+ // catch-all doesn't mask them.
158
+ {
159
+ kind: "openrouter",
160
+ // Most modern frontier models on OpenRouter are multimodal; flag the
161
+ // big families explicitly. The catch-all below stays vision=false so
162
+ // older/text-only routes don't get a green checkmark they don't earn.
163
+ match: /^(?:openai\/(?:gpt-4o|gpt-5|o[1-9])|anthropic\/claude-(?:3|4|opus|sonnet|haiku)|google\/gemini-[2-9]|x-ai\/grok-[4-9]|qwen\/qwen-?vl|meta\/llama-(?:3\.2|4))/i,
164
+ capability: {
165
+ supportsVision: true,
166
+ reasoning: { kind: "openrouter-reasoning" },
167
+ echoReasoning: "optional",
168
+ },
169
+ why: "OpenRouter routes to vision-capable backends for these slugs (GPT-4o, Claude 3+, Gemini 2.5+, Grok 4+, Qwen-VL, Llama 3.2/4).",
170
+ },
171
+ {
172
+ kind: "openrouter",
173
+ match: /./, // Any other model via OpenRouter
174
+ capability: {
175
+ reasoning: { kind: "openrouter-reasoning" },
176
+ // OpenRouter doesn't enforce per-provider echo contracts at its edge.
177
+ echoReasoning: "optional",
178
+ },
179
+ why: "OpenRouter exposes a unified reasoning:{effort,max_tokens,exclude,enabled} field for every backend.",
180
+ },
181
+ // ─── xAI Grok ──────────────────────────────────────────────────
182
+ {
183
+ kind: "xai",
184
+ // grok-4.3 has reasoning_effort: none|low|medium|high (no "minimal").
185
+ // Send "low" when the caller asks to disable — xAI rejects "minimal" 400.
186
+ match: /^grok-4\.3(?:[-.]|$)/i,
187
+ capability: {
188
+ supportsVision: true,
189
+ reasoning: { kind: "openai-effort", disabledEffort: "low" },
190
+ },
191
+ why: "xAI grok-4.3 supports reasoning_effort none|low|medium|high — no `minimal`; vision supported in grok-4+.",
192
+ },
193
+ // ─── Mistral ───────────────────────────────────────────────────
194
+ {
195
+ kind: "mistral",
196
+ // Magistral series exposes reasoning_effort: high|none — no minimal/low/medium.
197
+ match: /^magistral/i,
198
+ capability: {
199
+ reasoning: { kind: "openai-effort", disabledEffort: "none" },
200
+ },
201
+ why: "Mistral magistral models accept only reasoning_effort `high` or `none`.",
202
+ },
203
+ // ─── Groq ──────────────────────────────────────────────────────
204
+ {
205
+ kind: "groq",
206
+ match: /^(?:gpt-oss-(?:20b|120b)|qwen3-)/i,
207
+ capability: {
208
+ reasoning: { kind: "openai-effort" },
209
+ // Groq uses max_completion_tokens canonically (max_tokens is a
210
+ // deprecated alias). Safe to pin to the new field.
211
+ tokenLimitField: "max_completion_tokens",
212
+ },
213
+ why: "Groq reasoning-capable models use max_completion_tokens + reasoning_effort.",
214
+ },
215
+ ];
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Per-(provider, model) capability descriptor.
3
+ *
4
+ * Captures the subset of request-shape divergence we've actually observed
5
+ * cause HTTP 400s or behavior changes. Each rule in `rules.ts` produces
6
+ * one of these; clients spread it into the outgoing request.
7
+ *
8
+ * Sources for every field are documented next to the matching rule in
9
+ * `rules.ts` — vendor docs, not folklore.
10
+ */
11
+ import type { ProviderKindName } from "../provider-kinds.js";
12
+ /** OpenAI-style reasoning effort levels — shared by several vendors. */
13
+ export type ReasoningEffort = "minimal" | "low" | "medium" | "high";
14
+ /** A binary thinking switch, like DeepSeek V4 and Z.AI GLM use. */
15
+ export type ThinkingSwitch = "enabled" | "disabled";
16
+ /**
17
+ * How the vendor exposes a "think harder / think less" knob (or none).
18
+ * Each kind has different field names and value shapes — we keep them
19
+ * separate so the engine can't accidentally cross-pollinate.
20
+ */
21
+ export type ReasoningShape = {
22
+ kind: "none";
23
+ }
24
+ /** DeepSeek V4, Z.AI GLM-4.5+ — `{thinking: {type: "enabled"|"disabled"}}` at top level. */
25
+ | {
26
+ kind: "deepseek-thinking";
27
+ }
28
+ /**
29
+ * OpenAI o-series & gpt-5+ — `reasoning_effort: "minimal"|"low"|"medium"|"high"`.
30
+ * `disabledEffort` is the value we send when the caller asks for thinking
31
+ * "disabled" — defaults to `"minimal"` (OpenAI), but vendors with a
32
+ * narrower vocabulary override it (e.g. xAI Grok 4.3 has no `"minimal"`;
33
+ * Mistral Magistral only accepts `"high"` and `"none"`).
34
+ */
35
+ | {
36
+ kind: "openai-effort";
37
+ disabledEffort?: ReasoningEffort | "none";
38
+ }
39
+ /** Anthropic Claude 4.x ≤ 4.5 — `{thinking: {type: "enabled", budget_tokens: N}}`. */
40
+ | {
41
+ kind: "anthropic-budget";
42
+ minBudgetTokens: number;
43
+ }
44
+ /** Anthropic Claude 4.6+ — no opt-in, thinking is adaptive. Sending `type: "enabled"` 400s. */
45
+ | {
46
+ kind: "anthropic-adaptive";
47
+ }
48
+ /** OpenRouter normalized — `{reasoning: {effort, max_tokens, exclude, enabled}}`. */
49
+ | {
50
+ kind: "openrouter-reasoning";
51
+ };
52
+ /**
53
+ * How prior `reasoning_content` (or `thinking` blocks) must be threaded
54
+ * back into the next request.
55
+ */
56
+ export type EchoReasoning =
57
+ /** DeepSeek `deepseek-reasoner`: 400 if you echo it back at all. */
58
+ "never"
59
+ /** DeepSeek V4 + tools, Claude 4.x + tools: must echo or 400. */
60
+ | "when-tools"
61
+ /** Optional — echo if you have it, but absence is fine. */
62
+ | "optional";
63
+ /**
64
+ * Parallel-tool-call shape. OpenAI exposes `parallel_tool_calls: bool`.
65
+ * Anthropic exposes it inside `tool_choice.disable_parallel_tool_use`.
66
+ * Some endpoints don't support it at all.
67
+ */
68
+ export type ParallelToolCallsShape = "openai-flag" | "anthropic-disable-flag" | "unsupported";
69
+ /**
70
+ * Streaming usage signal. OpenAI-compat needs `stream_options:
71
+ * {include_usage: true}`; Anthropic always emits usage in
72
+ * `message_delta`; some endpoints reject the field.
73
+ */
74
+ export type StreamUsageShape = "include-usage-flag" | "auto" | "none";
75
+ export interface Capability {
76
+ /**
77
+ * Whether the model accepts image content blocks. UI gates image attachments
78
+ * on this — non-vision models surface a "this model does not accept images"
79
+ * message instead of silently dropping the upload.
80
+ */
81
+ supportsVision: boolean;
82
+ /** Token-limit request field. */
83
+ tokenLimitField: "max_tokens" | "max_completion_tokens";
84
+ /**
85
+ * Request fields the model 400s on (or silently drops). We just don't
86
+ * send them. Names are in OpenAI-compat spelling; clients translate
87
+ * for native protocols.
88
+ */
89
+ rejectedParams: ReadonlySet<"temperature" | "top_p" | "presence_penalty" | "frequency_penalty" | "logit_bias" | "logprobs" | "top_logprobs">;
90
+ /** How thinking is exposed (or not). */
91
+ reasoning: ReasoningShape;
92
+ /** Echo-back contract for prior reasoning. */
93
+ echoReasoning: EchoReasoning;
94
+ /** Parallel-tool-calls flag shape. */
95
+ parallelToolCalls: ParallelToolCallsShape;
96
+ /** Streaming usage reporting shape. */
97
+ streamUsage: StreamUsageShape;
98
+ }
99
+ /**
100
+ * Conservative default — used when no rule matches. Picks "send everything
101
+ * the vanilla OpenAI Chat Completions spec accepts," because that's what
102
+ * every OpenAI-compat endpoint at minimum understands.
103
+ */
104
+ export declare const DEFAULT_CAPABILITY: Capability;
105
+ export interface CapabilityRule {
106
+ /** Which provider kind this rule applies to. */
107
+ kind: ProviderKindName;
108
+ /** Model-id matcher. First matching rule wins (per kind). */
109
+ match: RegExp;
110
+ /** Patch applied on top of DEFAULT_CAPABILITY. */
111
+ capability: Partial<Capability>;
112
+ /** Free-text reason — shown in logs, helps future-you. */
113
+ why: string;
114
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Per-(provider, model) capability descriptor.
3
+ *
4
+ * Captures the subset of request-shape divergence we've actually observed
5
+ * cause HTTP 400s or behavior changes. Each rule in `rules.ts` produces
6
+ * one of these; clients spread it into the outgoing request.
7
+ *
8
+ * Sources for every field are documented next to the matching rule in
9
+ * `rules.ts` — vendor docs, not folklore.
10
+ */
11
+ /**
12
+ * Conservative default — used when no rule matches. Picks "send everything
13
+ * the vanilla OpenAI Chat Completions spec accepts," because that's what
14
+ * every OpenAI-compat endpoint at minimum understands.
15
+ */
16
+ export const DEFAULT_CAPABILITY = {
17
+ supportsVision: false,
18
+ tokenLimitField: "max_tokens",
19
+ rejectedParams: new Set(),
20
+ reasoning: { kind: "none" },
21
+ echoReasoning: "optional",
22
+ parallelToolCalls: "openai-flag",
23
+ streamUsage: "include-usage-flag",
24
+ };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Abstract base class for all LLM provider clients.
3
+ */
4
+ import type { LLMConfig, LLMResponse, TokenUsage } from "../types.js";
5
+ import type { CreateMessageOptions, LLMUsageTracker } from "./types.js";
6
+ export declare abstract class LLMClientBase {
7
+ protected readonly config: LLMConfig;
8
+ readonly provider: string;
9
+ readonly model: string;
10
+ readonly temperature: number;
11
+ readonly maxTokens: number;
12
+ readonly timeout: number;
13
+ readonly retryMaxAttempts: number;
14
+ readonly enableStreaming: boolean;
15
+ /**
16
+ * Process-wide hook fired on every LLM response. The CLI installs this in
17
+ * main.ts to feed the cost tracker; lives on the base class so every code
18
+ * path (REPL, run, arena, sub-agents) reports through one funnel without
19
+ * each call site needing to remember.
20
+ */
21
+ static onUsage?: (model: string, usage: TokenUsage) => void;
22
+ protected usage: LLMUsageTracker;
23
+ constructor(config: LLMConfig);
24
+ protected abstract initClient(): void;
25
+ abstract createMessage(options: CreateMessageOptions): Promise<LLMResponse>;
26
+ protected recordUsage(usage: TokenUsage, options?: CreateMessageOptions): void;
27
+ getUsage(): LLMUsageTracker;
28
+ protected withRetry<T>(fn: () => Promise<T>, maxAttempts?: number): Promise<T>;
29
+ }