@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,101 @@
1
+ /**
2
+ * ApplyPatch tool — atomic, multi-file V4A patch application.
3
+ *
4
+ * Adapted from openai/codex codex-rs/apply-patch (Apache-2.0). See LICENSE-codex.
5
+ *
6
+ * Compared to Codex's reference implementation:
7
+ * - We dry-run all hunks first; nothing is written until every hunk
8
+ * successfully resolves.
9
+ * - On commit we snapshot every target file, so a write failure rolls back
10
+ * to the pre-patch state instead of leaving partial changes.
11
+ *
12
+ * Compared to CodeShell's existing Edit:
13
+ * - Multi-file in one call (cuts LLM round-trips for large changes).
14
+ * - Supports create / update / delete / rename in one transaction.
15
+ * - Context-anchor matching tolerates whitespace and Unicode quirks.
16
+ */
17
+ import { fileCache } from "../file-cache.js";
18
+ import { applyPatch } from "./applier.js";
19
+ import { parsePatch } from "./parser.js";
20
+ export const applyPatchToolDef = {
21
+ name: "ApplyPatch",
22
+ description: "Apply a V4A-format patch atomically across one or more files. " +
23
+ "Supports create, update, delete, and rename operations in a single call. " +
24
+ "If any hunk fails to apply, the entire patch is rejected and no files are modified. " +
25
+ "Patch envelope:\n" +
26
+ " *** Begin Patch\n" +
27
+ " *** Add File: <path>\n" +
28
+ " +<line>\n" +
29
+ " *** Update File: <path>\n" +
30
+ " *** Move to: <new path> # optional rename\n" +
31
+ " @@ <context> # optional anchor\n" +
32
+ " <unchanged line>\n" +
33
+ " -<removed line>\n" +
34
+ " +<added line>\n" +
35
+ " *** End of File # optional, anchors to file end\n" +
36
+ " *** Delete File: <path>\n" +
37
+ " *** End Patch\n" +
38
+ "Use relative paths; they resolve against the working directory.",
39
+ inputSchema: {
40
+ type: "object",
41
+ properties: {
42
+ patch: {
43
+ type: "string",
44
+ description: "Full patch text including '*** Begin Patch' and '*** End Patch' markers. " +
45
+ "All paths must be relative (preferred) or absolute. " +
46
+ "Each Update hunk must include enough context lines (' '-prefixed) " +
47
+ "to uniquely locate the change within the file.",
48
+ },
49
+ },
50
+ required: ["patch"],
51
+ },
52
+ };
53
+ export async function applyPatchTool(args, ctx) {
54
+ const patchText = args.patch;
55
+ if (typeof patchText !== "string" || patchText.length === 0) {
56
+ return "Error: patch is required and must be a non-empty string";
57
+ }
58
+ let parsed;
59
+ try {
60
+ parsed = parsePatch(patchText, "lenient");
61
+ }
62
+ catch (err) {
63
+ return `Error: ${err.message}`;
64
+ }
65
+ if (parsed.hunks.length === 0) {
66
+ return "Error: patch contains no hunks";
67
+ }
68
+ // A4: resolve relative patch paths against the Engine's cwd, not the
69
+ // host process cwd. See standard §S5.
70
+ const cwd = ctx?.cwd ?? process.cwd();
71
+ let result;
72
+ try {
73
+ result = await applyPatch(parsed.hunks, { cwd });
74
+ }
75
+ catch (err) {
76
+ return `Error applying patch: ${err.message}`;
77
+ }
78
+ // Invalidate file cache for every touched path.
79
+ for (const hunk of parsed.hunks) {
80
+ fileCache.invalidate(hunk.path);
81
+ if (hunk.kind === "update" && hunk.movePath) {
82
+ fileCache.invalidate(hunk.movePath);
83
+ }
84
+ }
85
+ const parts = [];
86
+ if (result.added.length > 0)
87
+ parts.push(`added ${result.added.length}`);
88
+ if (result.modified.length > 0)
89
+ parts.push(`modified ${result.modified.length}`);
90
+ if (result.deleted.length > 0)
91
+ parts.push(`deleted ${result.deleted.length}`);
92
+ const summary = parts.join(", ");
93
+ const lines = [`Patch applied successfully — ${summary}`];
94
+ for (const p of result.added)
95
+ lines.push(` A ${p}`);
96
+ for (const p of result.modified)
97
+ lines.push(` M ${p}`);
98
+ for (const p of result.deleted)
99
+ lines.push(` D ${p}`);
100
+ return lines.join("\n");
101
+ }
@@ -0,0 +1,17 @@
1
+ import { Hunk } from "./types.js";
2
+ export declare const BEGIN_PATCH_MARKER = "*** Begin Patch";
3
+ export declare const END_PATCH_MARKER = "*** End Patch";
4
+ export declare const ADD_FILE_MARKER = "*** Add File: ";
5
+ export declare const DELETE_FILE_MARKER = "*** Delete File: ";
6
+ export declare const UPDATE_FILE_MARKER = "*** Update File: ";
7
+ export declare const MOVE_TO_MARKER = "*** Move to: ";
8
+ export declare const EOF_MARKER = "*** End of File";
9
+ export declare const CHANGE_CONTEXT_MARKER = "@@ ";
10
+ export declare const EMPTY_CHANGE_CONTEXT_MARKER = "@@";
11
+ export interface ParsedPatch {
12
+ hunks: Hunk[];
13
+ /** The patch body with any heredoc wrapper stripped. */
14
+ patch: string;
15
+ }
16
+ export type ParseMode = "strict" | "lenient";
17
+ export declare function parsePatch(text: string, mode?: ParseMode): ParsedPatch;
@@ -0,0 +1,212 @@
1
+ // Adapted from openai/codex codex-rs/apply-patch/src/parser.rs (Apache-2.0).
2
+ //
3
+ // V4A patch grammar (lenient form):
4
+ //
5
+ // start := begin_patch hunk* end_patch
6
+ // begin_patch := "*** Begin Patch" LF
7
+ // end_patch := "*** End Patch" LF?
8
+ // hunk := add_hunk | delete_hunk | update_hunk
9
+ // add_hunk := "*** Add File: " path LF ("+" line LF)+
10
+ // delete_hunk := "*** Delete File: " path LF
11
+ // update_hunk := "*** Update File: " path LF change_move? change?
12
+ // change_move := "*** Move to: " path LF
13
+ // change := (change_context | change_line)+ eof_line?
14
+ // change_line := (" " | "+" | "-") text LF
15
+ // eof_line := "*** End of File" LF
16
+ //
17
+ // Lenient extras:
18
+ // - Leading/trailing whitespace around begin/end markers tolerated.
19
+ // - First Update chunk may omit the leading `@@` context marker.
20
+ // - Patch text may be wrapped in <<EOF / <<'EOF' / <<"EOF" heredoc; we strip
21
+ // it so misformatted shell-style invocations still parse.
22
+ import { PatchParseError } from "./types.js";
23
+ export const BEGIN_PATCH_MARKER = "*** Begin Patch";
24
+ export const END_PATCH_MARKER = "*** End Patch";
25
+ export const ADD_FILE_MARKER = "*** Add File: ";
26
+ export const DELETE_FILE_MARKER = "*** Delete File: ";
27
+ export const UPDATE_FILE_MARKER = "*** Update File: ";
28
+ export const MOVE_TO_MARKER = "*** Move to: ";
29
+ export const EOF_MARKER = "*** End of File";
30
+ export const CHANGE_CONTEXT_MARKER = "@@ ";
31
+ export const EMPTY_CHANGE_CONTEXT_MARKER = "@@";
32
+ export function parsePatch(text, mode = "lenient") {
33
+ const trimmed = text.trim();
34
+ const lines = trimmed.length === 0 ? [] : trimmed.split("\n");
35
+ const inner = mode === "strict"
36
+ ? checkBoundariesStrict(lines)
37
+ : checkBoundariesLenient(lines);
38
+ const hunks = [];
39
+ let lineNumber = 2;
40
+ let i = 0;
41
+ while (i < inner.body.length) {
42
+ const { hunk, consumed } = parseOneHunk(inner.body, i, lineNumber);
43
+ hunks.push(hunk);
44
+ lineNumber += consumed;
45
+ i += consumed;
46
+ }
47
+ return { hunks, patch: inner.allLines.join("\n") };
48
+ }
49
+ function checkBoundariesStrict(lines) {
50
+ const first = lines[0]?.trim();
51
+ const last = lines[lines.length - 1]?.trim();
52
+ if (first !== BEGIN_PATCH_MARKER) {
53
+ throw new PatchParseError("InvalidPatch", "The first line of the patch must be '*** Begin Patch'");
54
+ }
55
+ if (lines.length < 2 || last !== END_PATCH_MARKER) {
56
+ throw new PatchParseError("InvalidPatch", "The last line of the patch must be '*** End Patch'");
57
+ }
58
+ return { allLines: lines, body: lines.slice(1, lines.length - 1) };
59
+ }
60
+ function checkBoundariesLenient(lines) {
61
+ try {
62
+ return checkBoundariesStrict(lines);
63
+ }
64
+ catch (err) {
65
+ const original = err;
66
+ if (lines.length >= 4) {
67
+ const first = lines[0];
68
+ const last = lines[lines.length - 1];
69
+ const isHeredoc = (first === "<<EOF" || first === "<<'EOF'" || first === '<<"EOF"') &&
70
+ last.endsWith("EOF");
71
+ if (isHeredoc) {
72
+ return checkBoundariesStrict(lines.slice(1, lines.length - 1));
73
+ }
74
+ }
75
+ throw original;
76
+ }
77
+ }
78
+ function parseOneHunk(lines, offset, lineNumber) {
79
+ const first = lines[offset].trim();
80
+ if (first.startsWith(ADD_FILE_MARKER)) {
81
+ const path = first.slice(ADD_FILE_MARKER.length);
82
+ let contents = "";
83
+ let consumed = 1;
84
+ for (let i = offset + 1; i < lines.length; i++) {
85
+ const line = lines[i];
86
+ if (line.startsWith("+")) {
87
+ contents += line.slice(1) + "\n";
88
+ consumed++;
89
+ }
90
+ else {
91
+ break;
92
+ }
93
+ }
94
+ return { hunk: { kind: "add", path, contents }, consumed };
95
+ }
96
+ if (first.startsWith(DELETE_FILE_MARKER)) {
97
+ return {
98
+ hunk: { kind: "delete", path: first.slice(DELETE_FILE_MARKER.length) },
99
+ consumed: 1,
100
+ };
101
+ }
102
+ if (first.startsWith(UPDATE_FILE_MARKER)) {
103
+ const path = first.slice(UPDATE_FILE_MARKER.length);
104
+ let cursor = offset + 1;
105
+ let consumed = 1;
106
+ let movePath;
107
+ if (cursor < lines.length && lines[cursor].startsWith(MOVE_TO_MARKER)) {
108
+ movePath = lines[cursor].slice(MOVE_TO_MARKER.length);
109
+ cursor++;
110
+ consumed++;
111
+ }
112
+ const chunks = [];
113
+ while (cursor < lines.length) {
114
+ // Skip blank lines between chunks.
115
+ if (lines[cursor].trim() === "") {
116
+ cursor++;
117
+ consumed++;
118
+ continue;
119
+ }
120
+ // Stop at any other top-level marker (`*** ...`).
121
+ if (lines[cursor].startsWith("*"))
122
+ break;
123
+ const result = parseUpdateChunk(lines, cursor, lineNumber + consumed, chunks.length === 0);
124
+ chunks.push(result.chunk);
125
+ cursor += result.consumed;
126
+ consumed += result.consumed;
127
+ }
128
+ if (chunks.length === 0) {
129
+ throw new PatchParseError("InvalidHunk", `Update file hunk for path '${path}' is empty`, lineNumber);
130
+ }
131
+ return {
132
+ hunk: { kind: "update", path, movePath, chunks },
133
+ consumed,
134
+ };
135
+ }
136
+ throw new PatchParseError("InvalidHunk", `'${first}' is not a valid hunk header. Valid hunk headers: ` +
137
+ `'*** Add File: {path}', '*** Delete File: {path}', '*** Update File: {path}'`, lineNumber);
138
+ }
139
+ function parseUpdateChunk(lines, offset, lineNumber, allowMissingContext) {
140
+ if (offset >= lines.length) {
141
+ throw new PatchParseError("InvalidHunk", "Update hunk does not contain any lines", lineNumber);
142
+ }
143
+ const head = lines[offset];
144
+ let changeContext;
145
+ let cursor = offset;
146
+ if (head === EMPTY_CHANGE_CONTEXT_MARKER) {
147
+ cursor = offset + 1;
148
+ }
149
+ else if (head.startsWith(CHANGE_CONTEXT_MARKER)) {
150
+ changeContext = head.slice(CHANGE_CONTEXT_MARKER.length);
151
+ cursor = offset + 1;
152
+ }
153
+ else if (!allowMissingContext) {
154
+ throw new PatchParseError("InvalidHunk", `Expected update hunk to start with a @@ context marker, got: '${head}'`, lineNumber);
155
+ }
156
+ if (cursor >= lines.length) {
157
+ throw new PatchParseError("InvalidHunk", "Update hunk does not contain any lines", lineNumber + 1);
158
+ }
159
+ const oldLines = [];
160
+ const newLines = [];
161
+ let isEndOfFile = false;
162
+ let bodyConsumed = 0;
163
+ for (let i = cursor; i < lines.length; i++) {
164
+ const line = lines[i];
165
+ if (line === EOF_MARKER) {
166
+ if (bodyConsumed === 0) {
167
+ throw new PatchParseError("InvalidHunk", "Update hunk does not contain any lines", lineNumber + 1);
168
+ }
169
+ isEndOfFile = true;
170
+ bodyConsumed++;
171
+ break;
172
+ }
173
+ if (line.length === 0) {
174
+ // Blank line — treat as a context line containing the empty string.
175
+ oldLines.push("");
176
+ newLines.push("");
177
+ bodyConsumed++;
178
+ continue;
179
+ }
180
+ const marker = line[0];
181
+ const rest = line.slice(1);
182
+ if (marker === " ") {
183
+ oldLines.push(rest);
184
+ newLines.push(rest);
185
+ }
186
+ else if (marker === "+") {
187
+ newLines.push(rest);
188
+ }
189
+ else if (marker === "-") {
190
+ oldLines.push(rest);
191
+ }
192
+ else {
193
+ // First unrecognized character at position 0 with no body yet → error.
194
+ // Otherwise, assume this is the start of the next hunk.
195
+ if (bodyConsumed === 0) {
196
+ throw new PatchParseError("InvalidHunk", `Unexpected line found in update hunk: '${line}'. Every line should start ` +
197
+ `with ' ' (context line), '+' (added line), or '-' (removed line)`, lineNumber + 1);
198
+ }
199
+ break;
200
+ }
201
+ bodyConsumed++;
202
+ }
203
+ return {
204
+ chunk: {
205
+ changeContext,
206
+ oldLines,
207
+ newLines,
208
+ isEndOfFile,
209
+ },
210
+ consumed: bodyConsumed + (cursor - offset),
211
+ };
212
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Locate `pattern` within `lines` starting at or after `start`.
3
+ *
4
+ * Tries four passes with decreasing strictness:
5
+ * 1. exact equality
6
+ * 2. trailing whitespace ignored
7
+ * 3. leading + trailing whitespace ignored
8
+ * 4. Unicode punctuation normalized to ASCII (smart quotes, em-dashes, NBSP, …)
9
+ *
10
+ * When `eof` is true, search begins at the position that would let `pattern`
11
+ * end exactly at the end of `lines` — useful for chunks marked
12
+ * `*** End of File`. Falls back to `start` if that position is out of range.
13
+ *
14
+ * Defensive cases:
15
+ * - Empty pattern returns `start` (no-op match).
16
+ * - Pattern longer than input returns `null`.
17
+ */
18
+ export declare function seekSequence(lines: string[], pattern: string[], start: number, eof: boolean): number | null;
@@ -0,0 +1,123 @@
1
+ // Adapted from openai/codex codex-rs/apply-patch/src/seek_sequence.rs (Apache-2.0).
2
+ /**
3
+ * Locate `pattern` within `lines` starting at or after `start`.
4
+ *
5
+ * Tries four passes with decreasing strictness:
6
+ * 1. exact equality
7
+ * 2. trailing whitespace ignored
8
+ * 3. leading + trailing whitespace ignored
9
+ * 4. Unicode punctuation normalized to ASCII (smart quotes, em-dashes, NBSP, …)
10
+ *
11
+ * When `eof` is true, search begins at the position that would let `pattern`
12
+ * end exactly at the end of `lines` — useful for chunks marked
13
+ * `*** End of File`. Falls back to `start` if that position is out of range.
14
+ *
15
+ * Defensive cases:
16
+ * - Empty pattern returns `start` (no-op match).
17
+ * - Pattern longer than input returns `null`.
18
+ */
19
+ export function seekSequence(lines, pattern, start, eof) {
20
+ if (pattern.length === 0)
21
+ return start;
22
+ if (pattern.length > lines.length)
23
+ return null;
24
+ const searchStart = eof && lines.length >= pattern.length ? lines.length - pattern.length : start;
25
+ const lastStart = lines.length - pattern.length;
26
+ // Pass 1: exact equality.
27
+ for (let i = searchStart; i <= lastStart; i++) {
28
+ let ok = true;
29
+ for (let p = 0; p < pattern.length; p++) {
30
+ if (lines[i + p] !== pattern[p]) {
31
+ ok = false;
32
+ break;
33
+ }
34
+ }
35
+ if (ok)
36
+ return i;
37
+ }
38
+ // Pass 2: trim trailing whitespace.
39
+ for (let i = searchStart; i <= lastStart; i++) {
40
+ let ok = true;
41
+ for (let p = 0; p < pattern.length; p++) {
42
+ if (rtrim(lines[i + p]) !== rtrim(pattern[p])) {
43
+ ok = false;
44
+ break;
45
+ }
46
+ }
47
+ if (ok)
48
+ return i;
49
+ }
50
+ // Pass 3: trim both sides.
51
+ for (let i = searchStart; i <= lastStart; i++) {
52
+ let ok = true;
53
+ for (let p = 0; p < pattern.length; p++) {
54
+ if (lines[i + p].trim() !== pattern[p].trim()) {
55
+ ok = false;
56
+ break;
57
+ }
58
+ }
59
+ if (ok)
60
+ return i;
61
+ }
62
+ // Pass 4: Unicode normalize (smart quotes / dashes / NBSP → ASCII).
63
+ for (let i = searchStart; i <= lastStart; i++) {
64
+ let ok = true;
65
+ for (let p = 0; p < pattern.length; p++) {
66
+ if (normalize(lines[i + p]) !== normalize(pattern[p])) {
67
+ ok = false;
68
+ break;
69
+ }
70
+ }
71
+ if (ok)
72
+ return i;
73
+ }
74
+ return null;
75
+ }
76
+ function rtrim(s) {
77
+ return s.replace(/[\s\uFEFF\xA0]+$/u, "");
78
+ }
79
+ function normalize(s) {
80
+ let out = "";
81
+ for (const ch of s.trim()) {
82
+ const code = ch.codePointAt(0);
83
+ // Various dash / hyphen code-points → ASCII '-'
84
+ if (code === 0x2010 ||
85
+ code === 0x2011 ||
86
+ code === 0x2012 ||
87
+ code === 0x2013 ||
88
+ code === 0x2014 ||
89
+ code === 0x2015 ||
90
+ code === 0x2212) {
91
+ out += "-";
92
+ }
93
+ else if (
94
+ // Fancy single quotes → '
95
+ code === 0x2018 ||
96
+ code === 0x2019 ||
97
+ code === 0x201a ||
98
+ code === 0x201b) {
99
+ out += "'";
100
+ }
101
+ else if (
102
+ // Fancy double quotes → "
103
+ code === 0x201c ||
104
+ code === 0x201d ||
105
+ code === 0x201e ||
106
+ code === 0x201f) {
107
+ out += '"';
108
+ }
109
+ else if (
110
+ // Non-breaking and exotic spaces → regular space
111
+ code === 0x00a0 ||
112
+ (code >= 0x2002 && code <= 0x200a) ||
113
+ code === 0x202f ||
114
+ code === 0x205f ||
115
+ code === 0x3000) {
116
+ out += " ";
117
+ }
118
+ else {
119
+ out += ch;
120
+ }
121
+ }
122
+ return out;
123
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * V4A patch AST. A parsed patch is a list of Hunks; each Hunk targets one file.
3
+ *
4
+ * Three variants:
5
+ * - AddFile: create a new file with the given contents
6
+ * - DeleteFile: remove an existing file
7
+ * - UpdateFile: in-place edit (optionally with a rename via movePath),
8
+ * expressed as one or more UpdateFileChunks.
9
+ */
10
+ export type Hunk = {
11
+ kind: "add";
12
+ path: string;
13
+ contents: string;
14
+ } | {
15
+ kind: "delete";
16
+ path: string;
17
+ } | {
18
+ kind: "update";
19
+ path: string;
20
+ movePath?: string;
21
+ chunks: UpdateFileChunk[];
22
+ };
23
+ export interface UpdateFileChunk {
24
+ /** Optional `@@ <context>` anchor that narrows where this chunk applies. */
25
+ changeContext?: string;
26
+ /** Lines that must match in the existing file (` ` and `-` markers). */
27
+ oldLines: string[];
28
+ /** Lines that should appear after the edit (` ` and `+` markers). */
29
+ newLines: string[];
30
+ /** True if this chunk ended with `*** End of File`; matches only at EOF. */
31
+ isEndOfFile: boolean;
32
+ }
33
+ export declare class PatchParseError extends Error {
34
+ readonly kind: "InvalidPatch" | "InvalidHunk";
35
+ readonly lineNumber?: number;
36
+ constructor(kind: "InvalidPatch" | "InvalidHunk", message: string, lineNumber?: number);
37
+ }
38
+ /**
39
+ * Result of staging (dry-run) a single file's planned change.
40
+ *
41
+ * A rename is represented as two PlannedFileChange entries: one for the
42
+ * source path with `newContent: null` (delete) and one for the destination
43
+ * path with the new content.
44
+ */
45
+ export interface PlannedFileChange {
46
+ path: string;
47
+ /** null = delete; string = create-or-overwrite with this content. */
48
+ newContent: string | null;
49
+ }
@@ -0,0 +1,13 @@
1
+ // Adapted from openai/codex codex-rs/apply-patch (Apache-2.0).
2
+ // Original Rust source: https://github.com/openai/codex/tree/main/codex-rs/apply-patch
3
+ // See LICENSE-codex in this directory.
4
+ export class PatchParseError extends Error {
5
+ kind;
6
+ lineNumber;
7
+ constructor(kind, message, lineNumber) {
8
+ super(message);
9
+ this.name = "PatchParseError";
10
+ this.kind = kind;
11
+ this.lineNumber = lineNumber;
12
+ }
13
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Built-in Arena tool — multi-model collaborative analysis.
3
+ *
4
+ * Launches an arena session where multiple LLM participants independently
5
+ * research a topic, cross-review each other's findings, and build consensus.
6
+ *
7
+ * The LLM config (baseUrl, apiKey) is injected at runtime by the Engine via
8
+ * setArenaLLMConfig(), following the same pattern as setAskUserFn() and
9
+ * setSubAgentConfig().
10
+ */
11
+ import type { ToolDefinition } from "../../types.js";
12
+ import type { ToolContext } from "../context.js";
13
+ export declare const arenaToolDef: ToolDefinition;
14
+ /**
15
+ * Snapshot of what Arena would do right now if invoked. Used by the
16
+ * `/arena` REPL command (via the protocol `arena_status` query) so
17
+ * users can see participants/endpoint before launching a run.
18
+ */
19
+ export interface ArenaStatus {
20
+ endpoint?: string;
21
+ defaultParticipants: Array<{
22
+ name: string;
23
+ model: string;
24
+ source: "pool" | "preset" | "raw";
25
+ compatible: boolean;
26
+ reason?: string;
27
+ }>;
28
+ poolSize: number;
29
+ }
30
+ export declare function getArenaStatus(): ArenaStatus;
31
+ export declare function arenaTool(args: Record<string, unknown>, ctx?: ToolContext): Promise<string>;