@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,65 @@
1
+ /**
2
+ * Auto-update — checks npm registry for newer versions; can optionally install
3
+ * the new version in the background after the current process exits.
4
+ *
5
+ * Flow:
6
+ * 1. `checkForUpdate()` runs at startup (non-blocking). Stores result in
7
+ * module state for the UI to read via `getUpdateAvailable()`.
8
+ * 2. UI re-polls every 30 min via `pollForUpdate()`.
9
+ * 3. If the user has write permission on the npm global prefix, we register
10
+ * `scheduleAutoInstallOnExit()` so that on process exit a detached
11
+ * `npm i -g` spawns and survives the parent. Next startup picks up
12
+ * the new version.
13
+ * 4. If the user has NO permission, UI shows the manual command instead.
14
+ *
15
+ * Concurrency: multiple `code-shell` processes can run at once. A file lock
16
+ * at `~/.code-shell/.update.lock` prevents both from launching `npm i -g`
17
+ * simultaneously (which corrupts the install).
18
+ *
19
+ * Headless safety: `checkForUpdate()` and `scheduleAutoInstallOnExit()` are
20
+ * only invoked from the Ink-based UpdateBanner component, never from the
21
+ * `run` / `arena` headless code paths. Keep it that way — wiring the updater
22
+ * into bare CLI commands would surprise CI users with background `npm i -g`
23
+ * on every short-lived `code-shell run …` invocation. If you need updater
24
+ * behavior in a new headless entry point, gate it on something explicit
25
+ * (e.g. `--auto-update` flag) rather than calling it unconditionally.
26
+ */
27
+ export interface UpdateInfo {
28
+ latestVersion: string;
29
+ /** True if `<npm prefix>` is writable by current user — can self-install. */
30
+ canAutoInstall: boolean;
31
+ /** Cached npm global prefix path (for diagnostics / manual command hint). */
32
+ npmPrefix: string | null;
33
+ }
34
+ /**
35
+ * Kick off an update check. Non-blocking: returns immediately, fills module
36
+ * state when network/npm respond. Safe to call multiple times (e.g. on a 30min
37
+ * timer).
38
+ */
39
+ export declare function checkForUpdate(packageName?: string): void;
40
+ /** Returns update info if a newer version was found, else undefined. */
41
+ export declare function getUpdateAvailable(): UpdateInfo | undefined;
42
+ /** Returns "why is auto-update off" — for /doctor-style diagnostics. */
43
+ export declare function getAutoUpdateDisabledReason(): string | null;
44
+ /**
45
+ * Install the on-exit hook so that the new version is installed AFTER the
46
+ * current process exits (avoids overwriting files the running process still
47
+ * has open). Idempotent — calling twice is a no-op.
48
+ */
49
+ export declare function scheduleAutoInstallOnExit(): void;
50
+ export declare function getCurrentVersion(): string;
51
+ declare function getLockFilePath(): string;
52
+ /**
53
+ * Try to acquire the update lock. Returns true on success.
54
+ * Uses `O_EXCL` (writeFile flag 'wx') for atomic create. Stale locks (mtime
55
+ * older than LOCK_TIMEOUT_MS) are taken over, re-verifying staleness right
56
+ * before unlink to close the TOCTOU race.
57
+ */
58
+ declare function acquireLock(): Promise<boolean>;
59
+ declare function releaseLock(): Promise<void>;
60
+ export declare const __internal: {
61
+ acquireLock: typeof acquireLock;
62
+ releaseLock: typeof releaseLock;
63
+ getLockFilePath: typeof getLockFilePath;
64
+ };
65
+ export {};
@@ -0,0 +1,405 @@
1
+ /**
2
+ * Auto-update — checks npm registry for newer versions; can optionally install
3
+ * the new version in the background after the current process exits.
4
+ *
5
+ * Flow:
6
+ * 1. `checkForUpdate()` runs at startup (non-blocking). Stores result in
7
+ * module state for the UI to read via `getUpdateAvailable()`.
8
+ * 2. UI re-polls every 30 min via `pollForUpdate()`.
9
+ * 3. If the user has write permission on the npm global prefix, we register
10
+ * `scheduleAutoInstallOnExit()` so that on process exit a detached
11
+ * `npm i -g` spawns and survives the parent. Next startup picks up
12
+ * the new version.
13
+ * 4. If the user has NO permission, UI shows the manual command instead.
14
+ *
15
+ * Concurrency: multiple `code-shell` processes can run at once. A file lock
16
+ * at `~/.code-shell/.update.lock` prevents both from launching `npm i -g`
17
+ * simultaneously (which corrupts the install).
18
+ *
19
+ * Headless safety: `checkForUpdate()` and `scheduleAutoInstallOnExit()` are
20
+ * only invoked from the Ink-based UpdateBanner component, never from the
21
+ * `run` / `arena` headless code paths. Keep it that way — wiring the updater
22
+ * into bare CLI commands would surprise CI users with background `npm i -g`
23
+ * on every short-lived `code-shell run …` invocation. If you need updater
24
+ * behavior in a new headless entry point, gate it on something explicit
25
+ * (e.g. `--auto-update` flag) rather than calling it unconditionally.
26
+ */
27
+ import { execFile, spawn } from "node:child_process";
28
+ import { constants as fsConstants } from "node:fs";
29
+ import { access, mkdir, readFile, stat, unlink, writeFile } from "node:fs/promises";
30
+ import { createRequire } from "node:module";
31
+ import { homedir } from "node:os";
32
+ import { dirname, join, resolve } from "node:path";
33
+ import { readFileSync } from "node:fs";
34
+ import { fileURLToPath } from "node:url";
35
+ import { promisify } from "node:util";
36
+ import { gt } from "./utils/semver.js";
37
+ const execFileAsync = promisify(execFile);
38
+ const PACKAGE_NAME = "@cjhyy/code-shell";
39
+ const LOCK_FILE = ".update.lock";
40
+ const LOCK_TIMEOUT_MS = 5 * 60 * 1000; // 5 min — stale-lock takeover threshold
41
+ const NPM_VIEW_TIMEOUT_MS = 5_000;
42
+ let _updateInfo;
43
+ let _exitHookInstalled = false;
44
+ let _disabledReason = null;
45
+ // ─── Public API ────────────────────────────────────────────────────────
46
+ /**
47
+ * Kick off an update check. Non-blocking: returns immediately, fills module
48
+ * state when network/npm respond. Safe to call multiple times (e.g. on a 30min
49
+ * timer).
50
+ */
51
+ export function checkForUpdate(packageName = PACKAGE_NAME) {
52
+ void runCheck(packageName);
53
+ }
54
+ /** Returns update info if a newer version was found, else undefined. */
55
+ export function getUpdateAvailable() {
56
+ return _updateInfo;
57
+ }
58
+ /** Returns "why is auto-update off" — for /doctor-style diagnostics. */
59
+ export function getAutoUpdateDisabledReason() {
60
+ return _disabledReason;
61
+ }
62
+ /**
63
+ * Install the on-exit hook so that the new version is installed AFTER the
64
+ * current process exits (avoids overwriting files the running process still
65
+ * has open). Idempotent — calling twice is a no-op.
66
+ */
67
+ export function scheduleAutoInstallOnExit() {
68
+ if (_exitHookInstalled)
69
+ return;
70
+ _exitHookInstalled = true;
71
+ const fire = () => {
72
+ const info = _updateInfo;
73
+ if (!info || !info.canAutoInstall)
74
+ return;
75
+ // Best-effort: spawn and forget. Errors logged to ~/.code-shell/update.log.
76
+ try {
77
+ launchDetachedInstall(info.latestVersion);
78
+ }
79
+ catch {
80
+ // intentionally swallowed — we're in process.exit
81
+ }
82
+ };
83
+ process.once("exit", fire);
84
+ }
85
+ // ─── Version detection ─────────────────────────────────────────────────
86
+ let _cachedVersion;
87
+ export function getCurrentVersion() {
88
+ if (_cachedVersion)
89
+ return _cachedVersion;
90
+ const found = resolveVersion();
91
+ _cachedVersion = found;
92
+ return found;
93
+ }
94
+ function resolveVersion() {
95
+ // Walk up from this module until we find a package.json with a "version" field.
96
+ // Works in ESM and CJS builds, and in dev (bun src).
97
+ try {
98
+ const here = typeof import.meta !== "undefined" && import.meta.url
99
+ ? dirname(fileURLToPath(import.meta.url))
100
+ : __dirname;
101
+ let dir = here;
102
+ for (let i = 0; i < 6; i++) {
103
+ try {
104
+ const pkg = JSON.parse(readFileSync(resolve(dir, "package.json"), "utf-8"));
105
+ if (pkg && typeof pkg.version === "string")
106
+ return pkg.version;
107
+ }
108
+ catch {
109
+ // not here, walk up
110
+ }
111
+ const parent = dirname(dir);
112
+ if (parent === dir)
113
+ break;
114
+ dir = parent;
115
+ }
116
+ }
117
+ catch {
118
+ // fall through
119
+ }
120
+ try {
121
+ const req = createRequire(import.meta.url ?? __filename);
122
+ const pkg = req("../../package.json");
123
+ if (pkg?.version)
124
+ return pkg.version;
125
+ }
126
+ catch {
127
+ // ignore
128
+ }
129
+ return "0.0.0";
130
+ }
131
+ // ─── Check logic ───────────────────────────────────────────────────────
132
+ async function runCheck(packageName) {
133
+ const disabled = isAutoUpdaterDisabled();
134
+ if (disabled) {
135
+ _disabledReason = disabled;
136
+ return;
137
+ }
138
+ _disabledReason = null;
139
+ try {
140
+ const currentVersion = getCurrentVersion();
141
+ const latestVersion = await getLatestVersion(packageName);
142
+ if (!latestVersion)
143
+ return;
144
+ // Compare with real semver — handles 1.0.0-alpha.3 < 1.0.0 correctly.
145
+ // gt() throws on invalid input; guard with try.
146
+ let isNewer = false;
147
+ try {
148
+ isNewer = gt(latestVersion, currentVersion);
149
+ }
150
+ catch {
151
+ // Fall back to strict-string-inequality for non-semver build SHAs.
152
+ isNewer = latestVersion !== currentVersion;
153
+ }
154
+ if (!isNewer) {
155
+ _updateInfo = undefined;
156
+ return;
157
+ }
158
+ const { hasPermissions, npmPrefix } = await checkGlobalInstallPermissions();
159
+ _updateInfo = { latestVersion, canAutoInstall: hasPermissions, npmPrefix };
160
+ }
161
+ catch {
162
+ // Network down, npm not installed, etc. — silently leave _updateInfo as-is.
163
+ }
164
+ }
165
+ async function getLatestVersion(packageName) {
166
+ // Run from $HOME so a malicious project-level .npmrc cannot redirect us
167
+ // to an attacker's registry.
168
+ try {
169
+ const { stdout } = await execFileAsync("npm", ["view", `${packageName}@latest`, "version", "--prefer-online"], { cwd: homedir(), timeout: NPM_VIEW_TIMEOUT_MS });
170
+ const v = stdout.trim();
171
+ return v.length > 0 ? v : null;
172
+ }
173
+ catch {
174
+ return null;
175
+ }
176
+ }
177
+ // ─── Permission probe ──────────────────────────────────────────────────
178
+ async function checkGlobalInstallPermissions() {
179
+ let prefix = null;
180
+ try {
181
+ const { stdout } = await execFileAsync("npm", ["-g", "config", "get", "prefix"], { cwd: homedir(), timeout: 5_000 });
182
+ prefix = stdout.trim();
183
+ }
184
+ catch {
185
+ return { hasPermissions: false, npmPrefix: null };
186
+ }
187
+ if (!prefix)
188
+ return { hasPermissions: false, npmPrefix: null };
189
+ try {
190
+ await access(prefix, fsConstants.W_OK);
191
+ return { hasPermissions: true, npmPrefix: prefix };
192
+ }
193
+ catch {
194
+ return { hasPermissions: false, npmPrefix: prefix };
195
+ }
196
+ }
197
+ // ─── Lock + install ────────────────────────────────────────────────────
198
+ function userHome() {
199
+ return process.env.HOME ?? homedir();
200
+ }
201
+ function configDir() {
202
+ return join(userHome(), ".code-shell");
203
+ }
204
+ function getLockFilePath() {
205
+ return join(configDir(), LOCK_FILE);
206
+ }
207
+ function getUpdateLogPath() {
208
+ return join(configDir(), "update.log");
209
+ }
210
+ /**
211
+ * Try to acquire the update lock. Returns true on success.
212
+ * Uses `O_EXCL` (writeFile flag 'wx') for atomic create. Stale locks (mtime
213
+ * older than LOCK_TIMEOUT_MS) are taken over, re-verifying staleness right
214
+ * before unlink to close the TOCTOU race.
215
+ */
216
+ async function acquireLock() {
217
+ const lockPath = getLockFilePath();
218
+ try {
219
+ const s = await stat(lockPath);
220
+ if (Date.now() - s.mtimeMs < LOCK_TIMEOUT_MS)
221
+ return false;
222
+ // Stale — verify again, then unlink.
223
+ try {
224
+ const recheck = await stat(lockPath);
225
+ if (Date.now() - recheck.mtimeMs < LOCK_TIMEOUT_MS)
226
+ return false;
227
+ await unlink(lockPath);
228
+ }
229
+ catch (err) {
230
+ if (!isENOENT(err))
231
+ return false;
232
+ }
233
+ }
234
+ catch (err) {
235
+ if (!isENOENT(err))
236
+ return false;
237
+ // ENOENT: no lock, proceed to create.
238
+ }
239
+ try {
240
+ await writeFile(lockPath, String(process.pid), { encoding: "utf8", flag: "wx" });
241
+ return true;
242
+ }
243
+ catch (err) {
244
+ const code = errnoCode(err);
245
+ if (code === "EEXIST")
246
+ return false;
247
+ if (code === "ENOENT") {
248
+ try {
249
+ await mkdir(configDir(), { recursive: true });
250
+ await writeFile(lockPath, String(process.pid), { encoding: "utf8", flag: "wx" });
251
+ return true;
252
+ }
253
+ catch {
254
+ return false;
255
+ }
256
+ }
257
+ return false;
258
+ }
259
+ }
260
+ async function releaseLock() {
261
+ const lockPath = getLockFilePath();
262
+ try {
263
+ const data = await readFile(lockPath, "utf8");
264
+ if (data === String(process.pid))
265
+ await unlink(lockPath);
266
+ }
267
+ catch {
268
+ // ENOENT or someone else holds it — leave alone
269
+ }
270
+ }
271
+ /**
272
+ * Spawn `npm i -g <pkg>@<version>` detached so it survives our exit. We can't
273
+ * await it (we're inside process.exit handler) — we only acquire the lock
274
+ * synchronously-ish and let the child do its thing.
275
+ *
276
+ * The child writes to ~/.code-shell/update.log so users can diagnose failures.
277
+ */
278
+ function launchDetachedInstall(version) {
279
+ const lockPath = getLockFilePath();
280
+ // Synchronous best-effort lock: writeFileSync with 'wx'. If another process
281
+ // already holds it, give up silently — they'll do the install.
282
+ try {
283
+ // Avoid `mkdirSync recursive` failures if dir exists.
284
+ try {
285
+ const fs = require("node:fs");
286
+ fs.mkdirSync(configDir(), { recursive: true });
287
+ fs.writeFileSync(lockPath, String(process.pid), { encoding: "utf8", flag: "wx" });
288
+ }
289
+ catch (err) {
290
+ if (errnoCode(err) === "EEXIST") {
291
+ // Lock held — check freshness; if stale, take over.
292
+ try {
293
+ const fs = require("node:fs");
294
+ const s = fs.statSync(lockPath);
295
+ if (Date.now() - s.mtimeMs < LOCK_TIMEOUT_MS)
296
+ return; // fresh — back off
297
+ fs.unlinkSync(lockPath);
298
+ fs.writeFileSync(lockPath, String(process.pid), { encoding: "utf8", flag: "wx" });
299
+ }
300
+ catch {
301
+ return;
302
+ }
303
+ }
304
+ else {
305
+ return;
306
+ }
307
+ }
308
+ }
309
+ catch {
310
+ return;
311
+ }
312
+ const fs = require("node:fs");
313
+ const logFd = fs.openSync(getUpdateLogPath(), "a");
314
+ try {
315
+ fs.writeSync(logFd, `\n[${new Date().toISOString()}] code-shell auto-update: installing ${PACKAGE_NAME}@${version} (pid=${process.pid})\n`);
316
+ }
317
+ catch {
318
+ // ignore
319
+ }
320
+ // Wrap install + lock cleanup in a tiny shell so the lock file is removed
321
+ // even if npm fails. `-c` style runs as a single child, detached from us.
322
+ const cmd = [
323
+ `npm install -g ${PACKAGE_NAME}@${shellEscape(version)}`,
324
+ `; rm -f ${shellEscape(lockPath)}`,
325
+ ].join(" ");
326
+ try {
327
+ const child = spawn("sh", ["-c", cmd], {
328
+ detached: true,
329
+ stdio: ["ignore", logFd, logFd],
330
+ cwd: homedir(),
331
+ });
332
+ child.unref();
333
+ }
334
+ catch {
335
+ // If spawn itself fails, free the lock so the next run can try.
336
+ try {
337
+ fs.unlinkSync(lockPath);
338
+ }
339
+ catch {
340
+ // ignore
341
+ }
342
+ }
343
+ }
344
+ // ─── Disabled-reason resolution ────────────────────────────────────────
345
+ /**
346
+ * Returns a human-readable reason if auto-update is disabled, else null.
347
+ * Checked in order:
348
+ * 1. NODE_ENV=development
349
+ * 2. DISABLE_AUTOUPDATER env var (truthy)
350
+ * 3. settings.autoUpdates === false
351
+ */
352
+ function isAutoUpdaterDisabled() {
353
+ if (process.env.NODE_ENV === "development")
354
+ return "development build";
355
+ if (isEnvTruthy(process.env.DISABLE_AUTOUPDATER))
356
+ return "DISABLE_AUTOUPDATER set";
357
+ // Best-effort: read user settings.json directly. Avoids pulling in the
358
+ // SettingsManager (and its zod validation) just to read one flag, and dodges
359
+ // the circular-import risk between settings/ and cli/.
360
+ if (readAutoUpdatesFlagFromDisk() === false)
361
+ return "settings.autoUpdates = false";
362
+ return null;
363
+ }
364
+ /**
365
+ * Read `autoUpdates` from the user settings file. Returns undefined if the
366
+ * file is missing/unreadable or the key isn't set (caller treats undefined as
367
+ * "default on"). Checks ~/.code-shell first, then ~/.claude as a fallback —
368
+ * matches what SettingsManager loads at user scope.
369
+ */
370
+ function readAutoUpdatesFlagFromDisk() {
371
+ // ~/.code-shell/ only — Claude Code compat path was dropped from settings
372
+ // loading (their `model` field is a string, ours is an object).
373
+ const path = join(userHome(), ".code-shell", "settings.json");
374
+ try {
375
+ const raw = readFileSync(path, "utf8");
376
+ const parsed = JSON.parse(raw);
377
+ if (typeof parsed.autoUpdates === "boolean")
378
+ return parsed.autoUpdates;
379
+ }
380
+ catch {
381
+ // missing / invalid JSON / wrong type — fall through to undefined
382
+ }
383
+ return undefined;
384
+ }
385
+ function isEnvTruthy(v) {
386
+ if (!v)
387
+ return false;
388
+ const lower = v.toLowerCase();
389
+ return lower === "1" || lower === "true" || lower === "yes" || lower === "on";
390
+ }
391
+ // ─── Helpers ───────────────────────────────────────────────────────────
392
+ function errnoCode(err) {
393
+ return typeof err === "object" && err !== null && "code" in err
394
+ ? String(err.code)
395
+ : undefined;
396
+ }
397
+ function isENOENT(err) {
398
+ return errnoCode(err) === "ENOENT";
399
+ }
400
+ function shellEscape(s) {
401
+ // Quote-and-escape for `sh -c`. Acceptable since `version` comes from npm.
402
+ return `'${s.replace(/'/g, `'\\''`)}'`;
403
+ }
404
+ // Re-export the lock release for tests / shutdown paths if needed.
405
+ export const __internal = { acquireLock, releaseLock, getLockFilePath };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Debug logging — thin facade over the unified logger.
3
+ *
4
+ * Historically this module wrote to ~/.code-shell/debug/<session>.txt.
5
+ * It now delegates to logger so all output lands in ~/.code-shell/logs/.
6
+ *
7
+ * Activation knobs (still honored, parsed inside logger):
8
+ * CODE_SHELL_LOG_LEVEL=debug — explicit level
9
+ * CODE_SHELL_DEBUG=mcp,api — category filter
10
+ * --debug — local dev: defaults to debug level
11
+ * --debug=mcp,api — category filter (CLI form)
12
+ * --debug-to-stderr / -d2e — echo to stderr instead of file
13
+ */
14
+ import { type LogLevel } from "../logging/logger.js";
15
+ export type DebugLogLevel = "verbose" | LogLevel;
16
+ export declare function setDebugSessionId(id: string): void;
17
+ export declare function isDebugMode(): boolean;
18
+ export declare function enableDebugLogging(): boolean;
19
+ export declare function isDebugToStdErr(): boolean;
20
+ export declare function getMinDebugLogLevel(): DebugLogLevel;
21
+ /**
22
+ * Log a debug message. Optional level via opts.level.
23
+ * Embedded `[category]` tags are extracted into the structured `cat` field.
24
+ */
25
+ export declare function logForDebugging(message: string, opts?: {
26
+ level?: DebugLogLevel | string;
27
+ }): void;
28
+ /**
29
+ * Category-scoped debug logger.
30
+ * Usage: const log = debugCategory("mcp"); log("connecting...");
31
+ */
32
+ export declare function debugCategory(category: string): (msg: string) => void;
33
+ /**
34
+ * Time a function and log the duration at debug level.
35
+ */
36
+ export declare function debugTiming<T>(label: string, fn: () => T | Promise<T>): Promise<T>;
37
+ export declare function logAntError(msg: string, _err?: unknown): void;
38
+ export declare function getDebugFilePath(): string | null;
39
+ export declare function setHasFormattedOutput(_v: boolean): void;
40
+ export declare function getHasFormattedOutput(): boolean;
41
+ export declare function flushDebugLogs(): Promise<void>;
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Debug logging — thin facade over the unified logger.
3
+ *
4
+ * Historically this module wrote to ~/.code-shell/debug/<session>.txt.
5
+ * It now delegates to logger so all output lands in ~/.code-shell/logs/.
6
+ *
7
+ * Activation knobs (still honored, parsed inside logger):
8
+ * CODE_SHELL_LOG_LEVEL=debug — explicit level
9
+ * CODE_SHELL_DEBUG=mcp,api — category filter
10
+ * --debug — local dev: defaults to debug level
11
+ * --debug=mcp,api — category filter (CLI form)
12
+ * --debug-to-stderr / -d2e — echo to stderr instead of file
13
+ */
14
+ import { logger } from "../logging/logger.js";
15
+ // ─── Session tag ───────────────────────────────────────────────────
16
+ //
17
+ // Session id lives on the logger (process-wide). The logger seeds itself
18
+ // with a random tag at module load; the Engine overwrites it with the
19
+ // authoritative id once a run resolves it (see engine.run → logger.setSid).
20
+ export function setDebugSessionId(id) {
21
+ logger.setSid(id);
22
+ }
23
+ // ─── Mode introspection ────────────────────────────────────────────
24
+ export function isDebugMode() {
25
+ return logger.getMinLevel() === "debug";
26
+ }
27
+ export function enableDebugLogging() {
28
+ // Level is fixed at logger construction; flip env so future child loggers
29
+ // (and a fresh process) pick up debug. The current logger keeps its level.
30
+ const wasActive = isDebugMode();
31
+ process.env.CODE_SHELL_LOG_LEVEL = "debug";
32
+ return wasActive;
33
+ }
34
+ export function isDebugToStdErr() {
35
+ return (process.env.CODE_SHELL_DEBUG === "1" ||
36
+ process.argv.includes("--debug-to-stderr") ||
37
+ process.argv.includes("-d2e"));
38
+ }
39
+ export function getMinDebugLogLevel() {
40
+ const raw = process.env.CODE_SHELL_DEBUG_LOG_LEVEL?.toLowerCase().trim();
41
+ if (raw === "verbose")
42
+ return "verbose";
43
+ return logger.getMinLevel();
44
+ }
45
+ // ─── Core API ──────────────────────────────────────────────────────
46
+ /**
47
+ * Log a debug message. Optional level via opts.level.
48
+ * Embedded `[category]` tags are extracted into the structured `cat` field.
49
+ */
50
+ export function logForDebugging(message, opts) {
51
+ const requested = (opts?.level ?? "debug");
52
+ const level = requested === "error" || requested === "warn" || requested === "info"
53
+ ? requested
54
+ : "debug"; // verbose collapses into debug
55
+ // Extract leading [category] tag if present.
56
+ const match = message.match(/^\s*\[([^\]]+)\]\s*(.*)$/);
57
+ const cat = match ? match[1].toLowerCase() : undefined;
58
+ const cleanMsg = match ? match[2] : message;
59
+ const data = {};
60
+ if (cat)
61
+ data.cat = cat;
62
+ switch (level) {
63
+ case "error":
64
+ logger.error(cleanMsg, data);
65
+ break;
66
+ case "warn":
67
+ logger.warn(cleanMsg, data);
68
+ break;
69
+ case "info":
70
+ logger.info(cleanMsg, data);
71
+ break;
72
+ default:
73
+ logger.debug(cleanMsg, data);
74
+ break;
75
+ }
76
+ }
77
+ /**
78
+ * Category-scoped debug logger.
79
+ * Usage: const log = debugCategory("mcp"); log("connecting...");
80
+ */
81
+ export function debugCategory(category) {
82
+ const child = logger.child({ cat: category.toLowerCase() });
83
+ return (msg) => child.debug(msg);
84
+ }
85
+ /**
86
+ * Time a function and log the duration at debug level.
87
+ */
88
+ export async function debugTiming(label, fn) {
89
+ if (!isDebugMode())
90
+ return fn();
91
+ const start = performance.now();
92
+ try {
93
+ const result = await fn();
94
+ logger.debug(`${label}: ${(performance.now() - start).toFixed(1)}ms`);
95
+ return result;
96
+ }
97
+ catch (err) {
98
+ const ms = (performance.now() - start).toFixed(1);
99
+ logger.error(`${label}: FAILED after ${ms}ms — ${err.message}`);
100
+ throw err;
101
+ }
102
+ }
103
+ // ─── CC compatibility shims ────────────────────────────────────────
104
+ export function logAntError(msg, _err) {
105
+ logger.error(msg);
106
+ }
107
+ export function getDebugFilePath() { return null; }
108
+ export function setHasFormattedOutput(_v) { }
109
+ export function getHasFormattedOutput() { return false; }
110
+ export async function flushDebugLogs() { }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Early Input Capture
3
+ *
4
+ * This module captures terminal input that is typed before the REPL is fully
5
+ * initialized. Users often type `claude` and immediately start typing their
6
+ * prompt, but those early keystrokes would otherwise be lost during startup.
7
+ *
8
+ * Usage:
9
+ * 1. Call startCapturingEarlyInput() as early as possible in cli.tsx
10
+ * 2. When REPL is ready, call consumeEarlyInput() to get any buffered text
11
+ * 3. stopCapturingEarlyInput() is called automatically when input is consumed
12
+ */
13
+ /**
14
+ * Start capturing stdin data early, before the REPL is initialized.
15
+ * Should be called as early as possible in the startup sequence.
16
+ *
17
+ * Only captures if stdin is a TTY (interactive terminal).
18
+ */
19
+ export declare function startCapturingEarlyInput(): void;
20
+ /**
21
+ * Stop capturing early input.
22
+ * Called automatically when input is consumed, or can be called manually.
23
+ */
24
+ export declare function stopCapturingEarlyInput(): void;
25
+ /**
26
+ * Consume any early input that was captured.
27
+ * Returns the captured input and clears the buffer.
28
+ * Automatically stops capturing when called.
29
+ */
30
+ export declare function consumeEarlyInput(): string;
31
+ /**
32
+ * Check if there is any early input available without consuming it.
33
+ */
34
+ export declare function hasEarlyInput(): boolean;
35
+ /**
36
+ * Seed the early input buffer with text that will appear pre-filled
37
+ * in the prompt input when the REPL renders. Does not auto-submit.
38
+ */
39
+ export declare function seedEarlyInput(text: string): void;
40
+ /**
41
+ * Check if early input capture is currently active.
42
+ */
43
+ export declare function isCapturingEarlyInput(): boolean;