@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,228 @@
1
+ /**
2
+ * Install / uninstall plugins from a known marketplace. Mirrors Claude
3
+ * Code's installResolvedPlugin pattern at the MVP subset: four entry
4
+ * source types (path / git / github / git-subdir), no dependencies, no
5
+ * sparse-checkout, no npm/pip.
6
+ */
7
+ import { cpSync, existsSync, mkdirSync, mkdtempSync, rmSync, } from "node:fs";
8
+ import { dirname, isAbsolute, join, resolve } from "node:path";
9
+ import { homedir, tmpdir } from "node:os";
10
+ import { gitClone, gitRevParseHead, githubRepoToCloneUrl } from "./gitOps.js";
11
+ import { loadMarketplace } from "./marketplaceManager.js";
12
+ import { readKnownMarketplaces } from "./knownMarketplaces.js";
13
+ import { appendInstallEntry, pluginInstallKey, readInstalledPlugins, removeInstallEntries, } from "./installedPlugins.js";
14
+ import { rewritePluginVars } from "./varRewrite.js";
15
+ function userHome() {
16
+ return process.env.HOME ?? homedir();
17
+ }
18
+ function pluginCacheRoot() {
19
+ return join(userHome(), ".code-shell", "plugins", "cache");
20
+ }
21
+ function pluginCacheDir(marketplace, plugin, version) {
22
+ return join(pluginCacheRoot(), marketplace, plugin, version);
23
+ }
24
+ async function materializePath(marketplaceInstallLocation, relativePath, cacheTarget) {
25
+ const src = isAbsolute(relativePath)
26
+ ? relativePath
27
+ : resolve(marketplaceInstallLocation, relativePath);
28
+ if (!existsSync(src)) {
29
+ return { ok: false, error: `plugin source path "${relativePath}" not found in marketplace` };
30
+ }
31
+ mkdirSync(dirname(cacheTarget), { recursive: true });
32
+ if (existsSync(cacheTarget))
33
+ rmSync(cacheTarget, { recursive: true, force: true });
34
+ cpSync(src, cacheTarget, { recursive: true });
35
+ return { ok: true, sha: undefined };
36
+ }
37
+ async function materializeGit(url, ref, cacheTarget) {
38
+ mkdirSync(dirname(cacheTarget), { recursive: true });
39
+ if (existsSync(cacheTarget))
40
+ rmSync(cacheTarget, { recursive: true, force: true });
41
+ const clone = await gitClone(url, cacheTarget, ref ? { ref } : undefined);
42
+ if (!clone.ok)
43
+ return { ok: false, error: clone.error };
44
+ const head = await gitRevParseHead(cacheTarget);
45
+ if (!head.ok)
46
+ return { ok: false, error: head.error };
47
+ return { ok: true, sha: head.stdout };
48
+ }
49
+ async function materializeGitSubdir(url, subPath, ref, cacheTarget) {
50
+ // Clone to a tempdir, then copy the subdir over.
51
+ const tmp = mkdtempSync(join(tmpdir(), "plugin-clone-"));
52
+ try {
53
+ const clone = await gitClone(url, tmp + "/repo", ref ? { ref } : undefined);
54
+ if (!clone.ok)
55
+ return { ok: false, error: clone.error };
56
+ const head = await gitRevParseHead(tmp + "/repo");
57
+ if (!head.ok)
58
+ return { ok: false, error: head.error };
59
+ const src = join(tmp, "repo", subPath);
60
+ if (!existsSync(src)) {
61
+ return {
62
+ ok: false,
63
+ error: `git-subdir path "${subPath}" not found in cloned repository`,
64
+ };
65
+ }
66
+ mkdirSync(dirname(cacheTarget), { recursive: true });
67
+ if (existsSync(cacheTarget))
68
+ rmSync(cacheTarget, { recursive: true, force: true });
69
+ cpSync(src, cacheTarget, { recursive: true });
70
+ return { ok: true, sha: head.stdout };
71
+ }
72
+ finally {
73
+ rmSync(tmp, { recursive: true, force: true });
74
+ }
75
+ }
76
+ function shortSha(sha) {
77
+ if (!sha)
78
+ return "unknown";
79
+ return sha.slice(0, 12);
80
+ }
81
+ async function materialize(source, marketplaceInstallLocation, marketplace, plugin) {
82
+ // First pass: install into a placeholder dir, then rename to the SHA dir
83
+ // once we know it. For path sources there's no SHA — use "local".
84
+ const placeholder = pluginCacheDir(marketplace, plugin, "_pending_");
85
+ if (typeof source === "string") {
86
+ const r = await materializePath(marketplaceInstallLocation, source, placeholder);
87
+ if (!r.ok)
88
+ return r;
89
+ const finalDir = pluginCacheDir(marketplace, plugin, "local");
90
+ if (existsSync(finalDir))
91
+ rmSync(finalDir, { recursive: true, force: true });
92
+ mkdirSync(dirname(finalDir), { recursive: true });
93
+ cpSync(placeholder, finalDir, { recursive: true });
94
+ rmSync(placeholder, { recursive: true, force: true });
95
+ return { ok: true, cacheDir: finalDir, version: "local", sha: undefined };
96
+ }
97
+ if (source.source === "git" || source.source === "github") {
98
+ const url = source.source === "github" ? githubRepoToCloneUrl(source.repo) : source.url;
99
+ const r = await materializeGit(url, source.ref, placeholder);
100
+ if (!r.ok) {
101
+ if (existsSync(placeholder))
102
+ rmSync(placeholder, { recursive: true, force: true });
103
+ return r;
104
+ }
105
+ const version = shortSha(r.sha);
106
+ const finalDir = pluginCacheDir(marketplace, plugin, version);
107
+ if (existsSync(finalDir))
108
+ rmSync(finalDir, { recursive: true, force: true });
109
+ mkdirSync(dirname(finalDir), { recursive: true });
110
+ cpSync(placeholder, finalDir, { recursive: true });
111
+ rmSync(placeholder, { recursive: true, force: true });
112
+ return { ok: true, cacheDir: finalDir, version, sha: r.sha };
113
+ }
114
+ if (source.source === "git-subdir") {
115
+ const r = await materializeGitSubdir(source.url, source.path, source.ref, placeholder);
116
+ if (!r.ok) {
117
+ if (existsSync(placeholder))
118
+ rmSync(placeholder, { recursive: true, force: true });
119
+ return r;
120
+ }
121
+ const version = shortSha(r.sha);
122
+ const finalDir = pluginCacheDir(marketplace, plugin, version);
123
+ if (existsSync(finalDir))
124
+ rmSync(finalDir, { recursive: true, force: true });
125
+ mkdirSync(dirname(finalDir), { recursive: true });
126
+ cpSync(placeholder, finalDir, { recursive: true });
127
+ rmSync(placeholder, { recursive: true, force: true });
128
+ return { ok: true, cacheDir: finalDir, version, sha: r.sha };
129
+ }
130
+ return { ok: false, error: `unsupported source type "${source.source}"` };
131
+ }
132
+ /**
133
+ * Install a plugin from a previously-added marketplace into the user
134
+ * cache. Idempotent within a process: re-installing replaces the
135
+ * cached files and updates the manifest entry.
136
+ */
137
+ export async function installPlugin(pluginName, marketplaceName) {
138
+ const known = readKnownMarketplaces();
139
+ const km = known[marketplaceName];
140
+ if (!km) {
141
+ return {
142
+ ok: false,
143
+ error: `marketplace "${marketplaceName}" not found. Run /plugin marketplace add first.`,
144
+ };
145
+ }
146
+ const manifest = loadMarketplace(marketplaceName);
147
+ if (!manifest) {
148
+ return {
149
+ ok: false,
150
+ error: `marketplace "${marketplaceName}" is registered but its manifest could not be loaded.`,
151
+ };
152
+ }
153
+ const entry = manifest.plugins.find((p) => p.name === pluginName);
154
+ if (!entry) {
155
+ return { ok: false, error: `plugin "${pluginName}" not found in marketplace "${marketplaceName}".` };
156
+ }
157
+ const mat = await materialize(entry.source, km.installLocation, marketplaceName, pluginName);
158
+ if (!mat.ok)
159
+ return mat;
160
+ // Rewrite ${CLAUDE_PLUGIN_ROOT} → ${CODESHELL_PLUGIN_ROOT} across every
161
+ // text file in the materialized tree. Plugins authored against Claude
162
+ // Code's protocol bake CLAUDE_PLUGIN_ROOT into hooks.json and shell
163
+ // scripts; we normalize at install time so the runtime only ever sets
164
+ // CODESHELL_PLUGIN_ROOT and host-detection branches in plugin scripts
165
+ // pick the codeshell-native code path. The breadcrumb file dropped at
166
+ // the root documents the rewrite for users debugging upstream diffs.
167
+ const rewriteSummary = rewritePluginVars(mat.cacheDir);
168
+ // Remove old install entries for the same key so we don't pile up
169
+ // historical versions (Phase A: single-scope only).
170
+ const key = pluginInstallKey(pluginName, marketplaceName);
171
+ removeInstallEntries(key);
172
+ const now = new Date().toISOString();
173
+ const installEntry = {
174
+ scope: "user",
175
+ installPath: mat.cacheDir,
176
+ version: mat.version,
177
+ installedAt: now,
178
+ lastUpdated: now,
179
+ ...(mat.sha ? { gitCommitSha: mat.sha } : {}),
180
+ };
181
+ appendInstallEntry(key, installEntry);
182
+ return {
183
+ ok: true,
184
+ entry: installEntry,
185
+ freshlyCloned: true,
186
+ varRewrite: {
187
+ filesScanned: rewriteSummary.filesScanned,
188
+ filesRewritten: rewriteSummary.filesRewritten,
189
+ },
190
+ };
191
+ }
192
+ export function uninstallPlugin(pluginName, marketplaceName) {
193
+ const key = pluginInstallKey(pluginName, marketplaceName);
194
+ const data = readInstalledPlugins();
195
+ const entries = data.plugins[key];
196
+ let removedFromDisk = false;
197
+ if (entries) {
198
+ for (const e of entries) {
199
+ if (e.installPath && existsSync(e.installPath)) {
200
+ rmSync(e.installPath, { recursive: true, force: true });
201
+ removedFromDisk = true;
202
+ }
203
+ }
204
+ // Also clean up the per-plugin parent if empty.
205
+ const pluginParent = join(pluginCacheRoot(), marketplaceName, pluginName);
206
+ try {
207
+ // rmdir succeeds only when empty; ignore failures.
208
+ const fs = require("node:fs");
209
+ fs.rmdirSync(pluginParent);
210
+ }
211
+ catch {
212
+ // not empty or doesn't exist — fine
213
+ }
214
+ }
215
+ const removedFromManifest = removeInstallEntries(key);
216
+ return { ok: removedFromManifest || removedFromDisk, removedFromManifest, removedFromDisk };
217
+ }
218
+ export function listInstalled() {
219
+ const data = readInstalledPlugins();
220
+ const out = [];
221
+ for (const [key, entries] of Object.entries(data.plugins)) {
222
+ for (const e of entries) {
223
+ out.push({ key, entry: e });
224
+ }
225
+ }
226
+ out.sort((a, b) => a.key.localeCompare(b.key));
227
+ return out;
228
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Lightweight validators for plugin marketplace JSON shapes. Returns
3
+ * { ok, value } | { ok: false, error } so callers can use the error
4
+ * string in user-facing slash command output.
5
+ */
6
+ import type { PluginMarketplace, PluginMarketplaceEntry, PluginEntrySource, ValidationResult } from "./types.js";
7
+ export declare function validatePluginEntrySource(raw: unknown, path: string): ValidationResult<PluginEntrySource>;
8
+ export declare function validatePluginEntry(raw: unknown, index: number): ValidationResult<PluginMarketplaceEntry>;
9
+ export declare function validateMarketplace(raw: unknown): ValidationResult<PluginMarketplace>;
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Lightweight validators for plugin marketplace JSON shapes. Returns
3
+ * { ok, value } | { ok: false, error } so callers can use the error
4
+ * string in user-facing slash command output.
5
+ */
6
+ function isObject(v) {
7
+ return typeof v === "object" && v !== null && !Array.isArray(v);
8
+ }
9
+ export function validatePluginEntrySource(raw, path) {
10
+ if (typeof raw === "string") {
11
+ if (raw.length === 0)
12
+ return { ok: false, error: `${path}: source string is empty` };
13
+ return { ok: true, value: raw };
14
+ }
15
+ if (!isObject(raw)) {
16
+ return { ok: false, error: `${path}: source must be a string or object` };
17
+ }
18
+ const kind = raw.source;
19
+ if (kind === "git") {
20
+ if (typeof raw.url !== "string" || !raw.url) {
21
+ return { ok: false, error: `${path}: git source requires url` };
22
+ }
23
+ return {
24
+ ok: true,
25
+ value: {
26
+ source: "git",
27
+ url: raw.url,
28
+ ref: typeof raw.ref === "string" ? raw.ref : undefined,
29
+ sha: typeof raw.sha === "string" ? raw.sha : undefined,
30
+ },
31
+ };
32
+ }
33
+ if (kind === "github") {
34
+ if (typeof raw.repo !== "string" || !raw.repo.includes("/")) {
35
+ return { ok: false, error: `${path}: github source requires repo "owner/name"` };
36
+ }
37
+ return {
38
+ ok: true,
39
+ value: {
40
+ source: "github",
41
+ repo: raw.repo,
42
+ ref: typeof raw.ref === "string" ? raw.ref : undefined,
43
+ sha: typeof raw.sha === "string" ? raw.sha : undefined,
44
+ },
45
+ };
46
+ }
47
+ if (kind === "git-subdir") {
48
+ if (typeof raw.url !== "string" || !raw.url) {
49
+ return { ok: false, error: `${path}: git-subdir source requires url` };
50
+ }
51
+ if (typeof raw.path !== "string" || !raw.path) {
52
+ return { ok: false, error: `${path}: git-subdir source requires path` };
53
+ }
54
+ return {
55
+ ok: true,
56
+ value: {
57
+ source: "git-subdir",
58
+ url: raw.url,
59
+ path: raw.path,
60
+ ref: typeof raw.ref === "string" ? raw.ref : undefined,
61
+ sha: typeof raw.sha === "string" ? raw.sha : undefined,
62
+ },
63
+ };
64
+ }
65
+ return {
66
+ ok: false,
67
+ error: `${path}: unsupported source type "${String(kind)}" (MVP supports git, github, git-subdir, or a string path)`,
68
+ };
69
+ }
70
+ export function validatePluginEntry(raw, index) {
71
+ const path = `plugins[${index}]`;
72
+ if (!isObject(raw))
73
+ return { ok: false, error: `${path}: must be an object` };
74
+ if (typeof raw.name !== "string" || !raw.name) {
75
+ return { ok: false, error: `${path}: name is required` };
76
+ }
77
+ if (raw.source === undefined) {
78
+ return { ok: false, error: `${path}: source is required` };
79
+ }
80
+ const source = validatePluginEntrySource(raw.source, `${path}.source`);
81
+ if (!source.ok)
82
+ return source;
83
+ let author;
84
+ if (raw.author !== undefined) {
85
+ if (!isObject(raw.author) || typeof raw.author.name !== "string") {
86
+ return { ok: false, error: `${path}.author: must be an object with name` };
87
+ }
88
+ author = {
89
+ name: raw.author.name,
90
+ email: typeof raw.author.email === "string" ? raw.author.email : undefined,
91
+ };
92
+ }
93
+ return {
94
+ ok: true,
95
+ value: {
96
+ name: raw.name,
97
+ description: typeof raw.description === "string" ? raw.description : undefined,
98
+ author,
99
+ category: typeof raw.category === "string" ? raw.category : undefined,
100
+ source: source.value,
101
+ homepage: typeof raw.homepage === "string" ? raw.homepage : undefined,
102
+ },
103
+ };
104
+ }
105
+ export function validateMarketplace(raw) {
106
+ if (!isObject(raw))
107
+ return { ok: false, error: "marketplace.json: not an object" };
108
+ if (typeof raw.name !== "string" || !raw.name) {
109
+ return { ok: false, error: "marketplace.json: name is required" };
110
+ }
111
+ if (!isObject(raw.owner) || typeof raw.owner.name !== "string") {
112
+ return { ok: false, error: "marketplace.json: owner.name is required" };
113
+ }
114
+ if (!Array.isArray(raw.plugins)) {
115
+ return { ok: false, error: "marketplace.json: plugins must be an array" };
116
+ }
117
+ const plugins = [];
118
+ for (let i = 0; i < raw.plugins.length; i++) {
119
+ const r = validatePluginEntry(raw.plugins[i], i);
120
+ if (!r.ok)
121
+ return r;
122
+ plugins.push(r.value);
123
+ }
124
+ return {
125
+ ok: true,
126
+ value: {
127
+ name: raw.name,
128
+ description: typeof raw.description === "string" ? raw.description : undefined,
129
+ owner: {
130
+ name: raw.owner.name,
131
+ email: typeof raw.owner.email === "string" ? raw.owner.email : undefined,
132
+ },
133
+ plugins,
134
+ },
135
+ };
136
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Plugin marketplace type definitions for codeshell. Schemas mirror Claude
3
+ * Code's plugin system (see claude-code-sourcemap/restored-src/src/utils/plugins/schemas.ts)
4
+ * at the MVP subset documented in
5
+ * docs/superpowers/specs/2026-05-19-plugin-marketplace-design.md.
6
+ */
7
+ export type MarketplaceSource = {
8
+ source: "github";
9
+ repo: string;
10
+ } | {
11
+ source: "git";
12
+ url: string;
13
+ };
14
+ export interface KnownMarketplace {
15
+ source: MarketplaceSource;
16
+ installLocation: string;
17
+ lastUpdated: string;
18
+ }
19
+ export type KnownMarketplaces = Record<string, KnownMarketplace>;
20
+ export type PluginEntrySource = string | {
21
+ source: "git";
22
+ url: string;
23
+ ref?: string;
24
+ sha?: string;
25
+ } | {
26
+ source: "github";
27
+ repo: string;
28
+ ref?: string;
29
+ sha?: string;
30
+ } | {
31
+ source: "git-subdir";
32
+ url: string;
33
+ path: string;
34
+ ref?: string;
35
+ sha?: string;
36
+ };
37
+ export interface PluginMarketplaceEntry {
38
+ name: string;
39
+ description?: string;
40
+ author?: {
41
+ name: string;
42
+ email?: string;
43
+ };
44
+ category?: string;
45
+ source: PluginEntrySource;
46
+ homepage?: string;
47
+ }
48
+ export interface PluginMarketplace {
49
+ name: string;
50
+ description?: string;
51
+ owner: {
52
+ name: string;
53
+ email?: string;
54
+ };
55
+ plugins: PluginMarketplaceEntry[];
56
+ }
57
+ export interface PluginInstallEntry {
58
+ scope: "user";
59
+ installPath: string;
60
+ version: string;
61
+ installedAt: string;
62
+ lastUpdated: string;
63
+ gitCommitSha?: string;
64
+ }
65
+ export interface InstalledPluginsV2 {
66
+ version: 2;
67
+ plugins: Record<string, PluginInstallEntry[]>;
68
+ }
69
+ export type ValidationResult<T> = {
70
+ ok: true;
71
+ value: T;
72
+ } | {
73
+ ok: false;
74
+ error: string;
75
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Plugin marketplace type definitions for codeshell. Schemas mirror Claude
3
+ * Code's plugin system (see claude-code-sourcemap/restored-src/src/utils/plugins/schemas.ts)
4
+ * at the MVP subset documented in
5
+ * docs/superpowers/specs/2026-05-19-plugin-marketplace-design.md.
6
+ */
7
+ export {};
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Plugin variable rewriter.
3
+ *
4
+ * After a plugin is materialized into the cache dir, walk its files and
5
+ * rewrite every occurrence of `CLAUDE_PLUGIN_ROOT` to `CODESHELL_PLUGIN_ROOT`.
6
+ *
7
+ * Why: plugins authored against Claude Code's protocol embed
8
+ * `${CLAUDE_PLUGIN_ROOT}` in their hooks.json command strings and inside
9
+ * shell scripts. codeshell uses its own env var name (`CODESHELL_PLUGIN_ROOT`)
10
+ * to keep plugin-side host detection unambiguous — so we rewrite the file
11
+ * tree at install time once, instead of dual-setting env vars at every hook
12
+ * invocation (which would let plugins falsely conclude they're running on
13
+ * Claude Code and emit CC-specific output formats).
14
+ *
15
+ * The rewrite is whole-token (not regex with word boundaries — Node's
16
+ * `String.replaceAll` on a literal substring is sufficient because no
17
+ * substring of the source contains the target as a prefix/suffix of another
18
+ * identifier in any plugin we've seen). If a plugin author chose
19
+ * `CLAUDE_PLUGIN_ROOT_SUFFIX` as an identifier this would also get rewritten,
20
+ * but that case is implausible enough we accept the risk over more complex
21
+ * tokenization.
22
+ *
23
+ * Binary files are skipped via NUL-byte heuristic on first 8 KiB.
24
+ *
25
+ * A breadcrumb file (`.code-shell-installed.json`) records the rewrite so
26
+ * a user debugging "why does this file differ from upstream?" has an
27
+ * explanation in-place.
28
+ */
29
+ export interface RewriteSummary {
30
+ filesScanned: number;
31
+ filesRewritten: number;
32
+ rewrittenPaths: string[];
33
+ }
34
+ /**
35
+ * Rewrite every `CLAUDE_PLUGIN_ROOT` → `CODESHELL_PLUGIN_ROOT` under
36
+ * `installPath`, then drop a breadcrumb file at the root.
37
+ *
38
+ * Idempotent: re-running on an already-rewritten tree is a no-op for the
39
+ * rewrite (no `CLAUDE_PLUGIN_ROOT` left) but refreshes the breadcrumb's
40
+ * timestamp so the user can see when the most recent install/update ran.
41
+ */
42
+ export declare function rewritePluginVars(installPath: string): RewriteSummary;
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Plugin variable rewriter.
3
+ *
4
+ * After a plugin is materialized into the cache dir, walk its files and
5
+ * rewrite every occurrence of `CLAUDE_PLUGIN_ROOT` to `CODESHELL_PLUGIN_ROOT`.
6
+ *
7
+ * Why: plugins authored against Claude Code's protocol embed
8
+ * `${CLAUDE_PLUGIN_ROOT}` in their hooks.json command strings and inside
9
+ * shell scripts. codeshell uses its own env var name (`CODESHELL_PLUGIN_ROOT`)
10
+ * to keep plugin-side host detection unambiguous — so we rewrite the file
11
+ * tree at install time once, instead of dual-setting env vars at every hook
12
+ * invocation (which would let plugins falsely conclude they're running on
13
+ * Claude Code and emit CC-specific output formats).
14
+ *
15
+ * The rewrite is whole-token (not regex with word boundaries — Node's
16
+ * `String.replaceAll` on a literal substring is sufficient because no
17
+ * substring of the source contains the target as a prefix/suffix of another
18
+ * identifier in any plugin we've seen). If a plugin author chose
19
+ * `CLAUDE_PLUGIN_ROOT_SUFFIX` as an identifier this would also get rewritten,
20
+ * but that case is implausible enough we accept the risk over more complex
21
+ * tokenization.
22
+ *
23
+ * Binary files are skipped via NUL-byte heuristic on first 8 KiB.
24
+ *
25
+ * A breadcrumb file (`.code-shell-installed.json`) records the rewrite so
26
+ * a user debugging "why does this file differ from upstream?" has an
27
+ * explanation in-place.
28
+ */
29
+ import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
30
+ import { join } from "node:path";
31
+ const FROM = "CLAUDE_PLUGIN_ROOT";
32
+ const TO = "CODESHELL_PLUGIN_ROOT";
33
+ const SCAN_BYTES = 8192;
34
+ function isLikelyBinary(buf) {
35
+ const len = Math.min(buf.length, SCAN_BYTES);
36
+ for (let i = 0; i < len; i++) {
37
+ if (buf[i] === 0)
38
+ return true;
39
+ }
40
+ return false;
41
+ }
42
+ function walkAndRewrite(dir, summary) {
43
+ let entries;
44
+ try {
45
+ entries = readdirSync(dir, { withFileTypes: true });
46
+ }
47
+ catch {
48
+ return;
49
+ }
50
+ for (const ent of entries) {
51
+ const full = join(dir, ent.name);
52
+ if (ent.isSymbolicLink())
53
+ continue;
54
+ if (ent.isDirectory()) {
55
+ // Skip VCS metadata: we never want to mutate a plugin's .git internals,
56
+ // even though we don't expect one in a cache dir.
57
+ if (ent.name === ".git")
58
+ continue;
59
+ walkAndRewrite(full, summary);
60
+ continue;
61
+ }
62
+ if (!ent.isFile())
63
+ continue;
64
+ let raw;
65
+ try {
66
+ raw = readFileSync(full);
67
+ }
68
+ catch {
69
+ continue;
70
+ }
71
+ summary.filesScanned += 1;
72
+ if (isLikelyBinary(raw))
73
+ continue;
74
+ const text = raw.toString("utf8");
75
+ if (!text.includes(FROM))
76
+ continue;
77
+ const rewritten = text.split(FROM).join(TO);
78
+ try {
79
+ writeFileSync(full, rewritten, "utf8");
80
+ summary.filesRewritten += 1;
81
+ summary.rewrittenPaths.push(full);
82
+ }
83
+ catch {
84
+ // Read-only file (e.g. EACCES on a permissioned drop-in) — log via
85
+ // count but don't crash the install.
86
+ }
87
+ }
88
+ }
89
+ /**
90
+ * Rewrite every `CLAUDE_PLUGIN_ROOT` → `CODESHELL_PLUGIN_ROOT` under
91
+ * `installPath`, then drop a breadcrumb file at the root.
92
+ *
93
+ * Idempotent: re-running on an already-rewritten tree is a no-op for the
94
+ * rewrite (no `CLAUDE_PLUGIN_ROOT` left) but refreshes the breadcrumb's
95
+ * timestamp so the user can see when the most recent install/update ran.
96
+ */
97
+ export function rewritePluginVars(installPath) {
98
+ const summary = {
99
+ filesScanned: 0,
100
+ filesRewritten: 0,
101
+ rewrittenPaths: [],
102
+ };
103
+ let exists = false;
104
+ try {
105
+ exists = statSync(installPath).isDirectory();
106
+ }
107
+ catch {
108
+ exists = false;
109
+ }
110
+ if (!exists)
111
+ return summary;
112
+ walkAndRewrite(installPath, summary);
113
+ const breadcrumb = {
114
+ rewrittenAt: new Date().toISOString(),
115
+ from: FROM,
116
+ to: TO,
117
+ filesScanned: summary.filesScanned,
118
+ filesRewritten: summary.filesRewritten,
119
+ note: "codeshell rewrote plugin files at install time so ${CLAUDE_PLUGIN_ROOT} placeholders use codeshell's native env var. " +
120
+ "Upstream plugin sources are unchanged; only this local copy was modified.",
121
+ };
122
+ try {
123
+ writeFileSync(join(installPath, ".code-shell-installed.json"), JSON.stringify(breadcrumb, null, 2) + "\n", "utf8");
124
+ }
125
+ catch {
126
+ // Non-fatal — the rewrite already succeeded.
127
+ }
128
+ return summary;
129
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Built-in agent presets.
3
+ *
4
+ * Presets keep the core engine domain-agnostic while letting callers choose
5
+ * a default prompt, default tools, and safe permission shortcuts.
6
+ *
7
+ * System prompts are assembled from reusable markdown sections in
8
+ * src/prompt/sections/*.md — each preset declares which sections to include.
9
+ */
10
+ import type { PermissionRule } from "../types.js";
11
+ export declare const AGENT_PRESET_NAMES: readonly ["general", "terminal-coding"];
12
+ /** Built-in preset names. Custom presets use arbitrary strings via registerPreset(). */
13
+ export type BuiltinPresetName = (typeof AGENT_PRESET_NAMES)[number];
14
+ /** Any preset name — built-in or custom-registered. */
15
+ export type AgentPresetName = BuiltinPresetName | (string & {});
16
+ export interface AgentPreset {
17
+ name: AgentPresetName;
18
+ label: string;
19
+ description: string;
20
+ /** Ordered list of prompt section filenames (without .md). */
21
+ promptSections: readonly string[];
22
+ /** Whether to inject git status into system context. */
23
+ injectGitStatus: boolean;
24
+ builtinTools: string[];
25
+ defaultPermissionRules: PermissionRule[];
26
+ }
27
+ export declare const BUILTIN_AGENT_PRESETS: Record<AgentPresetName, AgentPreset>;
28
+ export declare const DEFAULT_AGENT_PRESET: AgentPresetName;
29
+ export declare const DEFAULT_CLI_PRESET: AgentPresetName;
30
+ /**
31
+ * Register a custom agent preset.
32
+ *
33
+ * External repos can call this to add their own presets:
34
+ * ```ts
35
+ * import { registerPreset } from "code-shell";
36
+ *
37
+ * registerPreset({
38
+ * name: "data-pipeline" as AgentPresetName,
39
+ * label: "Data Pipeline Orchestrator",
40
+ * description: "Manages ETL workflows and data quality checks.",
41
+ * promptSections: ["base", "orchestration"],
42
+ * injectGitStatus: false,
43
+ * builtinTools: ["Read", "Write", "Bash", "Glob", "Grep", "Agent"],
44
+ * defaultPermissionRules: [{ tool: "Read", decision: "allow" }],
45
+ * });
46
+ * ```
47
+ */
48
+ export declare function registerPreset(preset: AgentPreset): void;
49
+ /** List all available preset names (built-in + custom). */
50
+ export declare function listPresetNames(): string[];
51
+ export declare function resolveAgentPreset(name?: string): AgentPreset;
52
+ /**
53
+ * Build the full system prompt for a preset by loading and joining its sections.
54
+ */
55
+ export declare function buildPresetSystemPrompt(preset: AgentPreset): string;
56
+ export declare function resolveBuiltinToolNames(options?: {
57
+ preset?: string;
58
+ enabledBuiltinTools?: string[];
59
+ disabledBuiltinTools?: string[];
60
+ }): string[];