@cjhyy/code-shell-core 0.5.0-rc.1 → 0.6.0-rc.1

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 (528) hide show
  1. package/README.md +13 -10
  2. package/dist/agent/agent-definition-registry.d.ts +21 -3
  3. package/dist/agent/agent-definition-registry.js +49 -18
  4. package/dist/agent/agent-definition.d.ts +32 -0
  5. package/dist/agent/agent-definition.js +49 -4
  6. package/dist/arena/arena.js +11 -12
  7. package/dist/arena/context/context-tools.js +47 -6
  8. package/dist/arena/context/within-root.d.ts +7 -0
  9. package/dist/arena/context/within-root.js +15 -0
  10. package/dist/arena/iterate/phases/argue.js +8 -2
  11. package/dist/arena/iterate/phases/revise.js +1 -1
  12. package/dist/arena/iterate/phases/tournament.js +3 -3
  13. package/dist/arena/ledger.js +9 -1
  14. package/dist/arena/phases/adjudication.js +1 -4
  15. package/dist/arena/phases/build-consensus.js +1 -4
  16. package/dist/arena/phases/cross-review.js +2 -8
  17. package/dist/arena/phases/debate-rounds.js +1 -4
  18. package/dist/arena/phases/participant-research.js +1 -4
  19. package/dist/arena/phases/planning-detail-expansion.js +8 -10
  20. package/dist/arena/planner.js +0 -1
  21. package/dist/arena/providers/docs.d.ts +1 -0
  22. package/dist/arena/providers/docs.js +5 -2
  23. package/dist/arena/providers/repo.d.ts +1 -0
  24. package/dist/arena/providers/repo.js +5 -2
  25. package/dist/arena/strategies/utils.d.ts +1 -4
  26. package/dist/arena/strategies/utils.js +7 -51
  27. package/dist/arena/transitions.d.ts +7 -2
  28. package/dist/arena/transitions.js +9 -4
  29. package/dist/arena/types.d.ts +8 -2
  30. package/dist/automation/cron-expr.d.ts +41 -0
  31. package/dist/automation/cron-expr.js +169 -0
  32. package/dist/automation/index.d.ts +41 -0
  33. package/dist/automation/index.js +39 -0
  34. package/dist/automation/runner.d.ts +84 -0
  35. package/dist/automation/runner.js +92 -0
  36. package/dist/automation/scheduler.d.ts +194 -0
  37. package/dist/automation/scheduler.js +623 -0
  38. package/dist/automation/store.d.ts +39 -0
  39. package/dist/automation/store.js +122 -0
  40. package/dist/automation/write-policy.d.ts +34 -0
  41. package/dist/automation/write-policy.js +113 -0
  42. package/dist/automation/write-run.d.ts +51 -0
  43. package/dist/automation/write-run.js +38 -0
  44. package/dist/capability-control/disabled-lists.d.ts +25 -0
  45. package/dist/capability-control/disabled-lists.js +57 -0
  46. package/dist/capability-control/index.d.ts +5 -0
  47. package/dist/capability-control/index.js +3 -0
  48. package/dist/capability-control/overlay.d.ts +64 -0
  49. package/dist/capability-control/overlay.js +116 -0
  50. package/dist/capability-control/project.d.ts +65 -0
  51. package/dist/capability-control/project.js +147 -0
  52. package/dist/capability-control/service.d.ts +70 -0
  53. package/dist/capability-control/service.js +147 -0
  54. package/dist/capability-control/types.d.ts +62 -0
  55. package/dist/capability-control/types.js +17 -0
  56. package/dist/cc-orchestrator/agent-adapter.d.ts +50 -0
  57. package/dist/cc-orchestrator/agent-adapter.js +133 -0
  58. package/dist/cc-orchestrator/cc-capability.d.ts +19 -0
  59. package/dist/cc-orchestrator/cc-capability.js +53 -0
  60. package/dist/cc-orchestrator/codex-session-discovery.d.ts +24 -0
  61. package/dist/cc-orchestrator/codex-session-discovery.js +191 -0
  62. package/dist/cc-orchestrator/codex-session-history.d.ts +25 -0
  63. package/dist/cc-orchestrator/codex-session-history.js +187 -0
  64. package/dist/cc-orchestrator/external-agent-changes.d.ts +19 -0
  65. package/dist/cc-orchestrator/external-agent-changes.js +214 -0
  66. package/dist/cc-orchestrator/external-agent-driver.d.ts +18 -0
  67. package/dist/cc-orchestrator/external-agent-driver.js +69 -0
  68. package/dist/cc-orchestrator/index.d.ts +8 -0
  69. package/dist/cc-orchestrator/index.js +8 -0
  70. package/dist/cc-orchestrator/relevance-judge.d.ts +15 -0
  71. package/dist/cc-orchestrator/relevance-judge.js +29 -0
  72. package/dist/cc-orchestrator/session-discovery.d.ts +46 -0
  73. package/dist/cc-orchestrator/session-discovery.js +125 -0
  74. package/dist/cc-orchestrator/session-history.d.ts +19 -0
  75. package/dist/cc-orchestrator/session-history.js +67 -0
  76. package/dist/cli/agent-server-stdio.d.ts +26 -1
  77. package/dist/cli/agent-server-stdio.js +221 -28
  78. package/dist/cli/agent-server-tcp.d.ts +20 -0
  79. package/dist/cli/agent-server-tcp.js +134 -0
  80. package/dist/cli/graceful-shutdown.d.ts +27 -0
  81. package/dist/cli/graceful-shutdown.js +30 -0
  82. package/dist/context/compaction.d.ts +56 -0
  83. package/dist/context/compaction.js +209 -15
  84. package/dist/context/manager.d.ts +0 -20
  85. package/dist/context/manager.js +25 -41
  86. package/dist/cost-tracker.js +5 -61
  87. package/dist/credentials/cipher.d.ts +49 -0
  88. package/dist/credentials/cipher.js +45 -0
  89. package/dist/credentials/cookie-jar.d.ts +24 -0
  90. package/dist/credentials/cookie-jar.js +40 -0
  91. package/dist/credentials/index.d.ts +7 -0
  92. package/dist/credentials/index.js +5 -0
  93. package/dist/credentials/inject-credential-tool.d.ts +20 -0
  94. package/dist/credentials/inject-credential-tool.js +130 -0
  95. package/dist/credentials/store.d.ts +72 -0
  96. package/dist/credentials/store.js +184 -0
  97. package/dist/credentials/types.d.ts +56 -0
  98. package/dist/credentials/use-credential-tool.d.ts +29 -0
  99. package/dist/credentials/use-credential-tool.js +205 -0
  100. package/dist/credentials/use-gate.d.ts +56 -0
  101. package/dist/credentials/use-gate.js +52 -0
  102. package/dist/cron/cron-runtime.d.ts +2 -0
  103. package/dist/cron/cron-runtime.js +2 -0
  104. package/dist/cron/cron-store.d.ts +2 -0
  105. package/dist/cron/cron-store.js +2 -0
  106. package/dist/cron/scheduler.d.ts +5 -32
  107. package/dist/cron/scheduler.js +5 -113
  108. package/dist/data/model-metadata.d.ts +77 -0
  109. package/dist/data/model-metadata.js +56 -0
  110. package/dist/data/model-metadata.json +216 -0
  111. package/dist/data/openrouter-models.d.ts +18 -7
  112. package/dist/data/openrouter-models.js +35 -8
  113. package/dist/data/openrouter-sync.js +1 -1
  114. package/dist/engine/aux-key.d.ts +10 -0
  115. package/dist/engine/aux-key.js +11 -0
  116. package/dist/engine/dynamic-tool-defs.d.ts +19 -0
  117. package/dist/engine/dynamic-tool-defs.js +36 -0
  118. package/dist/engine/engine.d.ts +431 -108
  119. package/dist/engine/engine.js +1630 -279
  120. package/dist/engine/friendly-error.d.ts +18 -0
  121. package/dist/engine/friendly-error.js +63 -0
  122. package/dist/engine/goal.d.ts +187 -0
  123. package/dist/engine/goal.js +196 -0
  124. package/dist/engine/image-compression.d.ts +81 -0
  125. package/dist/engine/image-compression.js +186 -0
  126. package/dist/engine/image-policy.d.ts +165 -0
  127. package/dist/engine/image-policy.js +189 -0
  128. package/dist/engine/model-connections-pool.d.ts +17 -0
  129. package/dist/engine/model-connections-pool.js +66 -0
  130. package/dist/engine/model-facade.d.ts +10 -0
  131. package/dist/engine/model-facade.js +25 -0
  132. package/dist/engine/patch-orphaned-tools.js +3 -0
  133. package/dist/engine/reactive-threshold.d.ts +13 -0
  134. package/dist/engine/reactive-threshold.js +17 -0
  135. package/dist/engine/resolve-llm-config.d.ts +16 -0
  136. package/dist/engine/resolve-llm-config.js +44 -0
  137. package/dist/engine/runtime.js +9 -1
  138. package/dist/engine/sandbox-cache-key.d.ts +10 -0
  139. package/dist/engine/sandbox-cache-key.js +9 -0
  140. package/dist/engine/sandbox-config.d.ts +31 -0
  141. package/dist/engine/sandbox-config.js +38 -0
  142. package/dist/engine/session-title.d.ts +13 -0
  143. package/dist/engine/session-title.js +34 -0
  144. package/dist/engine/session-usage.d.ts +19 -0
  145. package/dist/engine/session-usage.js +25 -0
  146. package/dist/engine/steer-queue.d.ts +32 -0
  147. package/dist/engine/steer-queue.js +26 -0
  148. package/dist/engine/streaming-tool-queue.d.ts +12 -0
  149. package/dist/engine/streaming-tool-queue.js +50 -10
  150. package/dist/engine/turn-loop.d.ts +94 -9
  151. package/dist/engine/turn-loop.js +775 -342
  152. package/dist/engine/types.d.ts +175 -0
  153. package/dist/engine/types.js +13 -0
  154. package/dist/external-agents/config.d.ts +2 -0
  155. package/dist/external-agents/config.js +15 -0
  156. package/dist/external-agents/types.d.ts +31 -0
  157. package/dist/external-agents/types.js +1 -0
  158. package/dist/git/parse-log.d.ts +13 -0
  159. package/dist/git/parse-log.js +21 -0
  160. package/dist/git/utils.d.ts +8 -6
  161. package/dist/git/utils.js +62 -26
  162. package/dist/git/worktree.d.ts +48 -0
  163. package/dist/git/worktree.js +111 -20
  164. package/dist/hooks/events.d.ts +23 -1
  165. package/dist/hooks/goal-stop-hook.d.ts +58 -0
  166. package/dist/hooks/goal-stop-hook.js +279 -0
  167. package/dist/hooks/hook-output.d.ts +33 -0
  168. package/dist/hooks/hook-output.js +79 -0
  169. package/dist/hooks/registry.d.ts +15 -0
  170. package/dist/hooks/registry.js +57 -1
  171. package/dist/hooks/shell-runner.d.ts +2 -0
  172. package/dist/hooks/shell-runner.js +48 -18
  173. package/dist/index.d.ts +79 -11
  174. package/dist/index.js +89 -6
  175. package/dist/llm/capabilities/param-specs.d.ts +14 -0
  176. package/dist/llm/capabilities/param-specs.js +62 -0
  177. package/dist/llm/capabilities/reasoning-control.d.ts +24 -0
  178. package/dist/llm/capabilities/reasoning-control.js +38 -0
  179. package/dist/llm/capabilities/rules.js +37 -3
  180. package/dist/llm/capabilities/types.d.ts +32 -2
  181. package/dist/llm/clamp-max-tokens.d.ts +11 -0
  182. package/dist/llm/clamp-max-tokens.js +17 -0
  183. package/dist/llm/client-base.d.ts +69 -5
  184. package/dist/llm/client-base.js +185 -25
  185. package/dist/llm/client-factory.d.ts +3 -3
  186. package/dist/llm/client-factory.js +2 -2
  187. package/dist/llm/model-cache.js +4 -2
  188. package/dist/llm/model-pool.d.ts +29 -11
  189. package/dist/llm/model-pool.js +36 -20
  190. package/dist/llm/provider-auth.d.ts +41 -0
  191. package/dist/llm/provider-auth.js +76 -0
  192. package/dist/llm/provider-catalog.d.ts +6 -2
  193. package/dist/llm/providers/anthropic.d.ts +32 -2
  194. package/dist/llm/providers/anthropic.js +207 -18
  195. package/dist/llm/providers/openai.d.ts +47 -2
  196. package/dist/llm/providers/openai.js +478 -71
  197. package/dist/llm/reasoning-setting.d.ts +51 -0
  198. package/dist/llm/reasoning-setting.js +40 -0
  199. package/dist/llm/stop-reason.d.ts +13 -0
  200. package/dist/llm/stop-reason.js +21 -0
  201. package/dist/llm/stream-watchdog.js +5 -1
  202. package/dist/llm/strip-vision.d.ts +32 -0
  203. package/dist/llm/strip-vision.js +94 -0
  204. package/dist/llm/token-counter.js +9 -2
  205. package/dist/llm/types.d.ts +9 -6
  206. package/dist/logging/logger.js +18 -4
  207. package/dist/logging/sanitize-messages.d.ts +10 -0
  208. package/dist/logging/sanitize-messages.js +112 -0
  209. package/dist/lsp/client.js +28 -8
  210. package/dist/lsp/manager.d.ts +1 -1
  211. package/dist/lsp/manager.js +42 -11
  212. package/dist/lsp/root-path.d.ts +9 -0
  213. package/dist/lsp/root-path.js +12 -0
  214. package/dist/model-catalog/builtin.d.ts +12 -0
  215. package/dist/model-catalog/builtin.js +407 -0
  216. package/dist/model-catalog/gen-connections.d.ts +20 -0
  217. package/dist/model-catalog/gen-connections.js +28 -0
  218. package/dist/model-catalog/index.d.ts +41 -0
  219. package/dist/model-catalog/index.js +90 -0
  220. package/dist/model-catalog/params.d.ts +20 -0
  221. package/dist/model-catalog/params.js +45 -0
  222. package/dist/model-catalog/resolve.d.ts +48 -0
  223. package/dist/model-catalog/resolve.js +33 -0
  224. package/dist/model-catalog/save-entry.d.ts +32 -0
  225. package/dist/model-catalog/save-entry.js +104 -0
  226. package/dist/model-catalog/types.d.ts +561 -0
  227. package/dist/model-catalog/types.js +93 -0
  228. package/dist/model-catalog/upsert.d.ts +9 -0
  229. package/dist/model-catalog/upsert.js +8 -0
  230. package/dist/onboarding.d.ts +12 -82
  231. package/dist/onboarding.js +75 -333
  232. package/dist/plugins/gitOps.d.ts +53 -0
  233. package/dist/plugins/gitOps.js +130 -5
  234. package/dist/plugins/installer/checkUpdate.d.ts +16 -0
  235. package/dist/plugins/installer/checkUpdate.js +32 -0
  236. package/dist/plugins/installer/codex/convertAgents.d.ts +7 -0
  237. package/dist/plugins/installer/codex/convertAgents.js +55 -0
  238. package/dist/plugins/installer/codex/convertCommands.d.ts +19 -0
  239. package/dist/plugins/installer/codex/convertCommands.js +46 -0
  240. package/dist/plugins/installer/codex/convertMcp.d.ts +11 -0
  241. package/dist/plugins/installer/codex/convertMcp.js +85 -0
  242. package/dist/plugins/installer/codex/convertSkills.d.ts +12 -0
  243. package/dist/plugins/installer/codex/convertSkills.js +33 -0
  244. package/dist/plugins/installer/detectFormat.d.ts +2 -0
  245. package/dist/plugins/installer/detectFormat.js +6 -0
  246. package/dist/plugins/installer/install.d.ts +7 -0
  247. package/dist/plugins/installer/install.js +123 -0
  248. package/dist/plugins/installer/installFromArchive.d.ts +43 -0
  249. package/dist/plugins/installer/installFromArchive.js +134 -0
  250. package/dist/plugins/installer/installFromSource.d.ts +13 -0
  251. package/dist/plugins/installer/installFromSource.js +51 -0
  252. package/dist/plugins/installer/list.d.ts +9 -0
  253. package/dist/plugins/installer/list.js +30 -0
  254. package/dist/plugins/installer/loadPluginAgents.d.ts +3 -0
  255. package/dist/plugins/installer/loadPluginAgents.js +27 -0
  256. package/dist/plugins/installer/loadPluginMcp.d.ts +14 -0
  257. package/dist/plugins/installer/loadPluginMcp.js +107 -0
  258. package/dist/plugins/installer/parseSource.d.ts +20 -0
  259. package/dist/plugins/installer/parseSource.js +74 -0
  260. package/dist/plugins/installer/paths.d.ts +5 -0
  261. package/dist/plugins/installer/paths.js +25 -0
  262. package/dist/plugins/installer/pruneDisabled.d.ts +24 -0
  263. package/dist/plugins/installer/pruneDisabled.js +73 -0
  264. package/dist/plugins/installer/types.d.ts +52 -0
  265. package/dist/plugins/installer/types.js +28 -0
  266. package/dist/plugins/installer/uninstall.d.ts +2 -0
  267. package/dist/plugins/installer/uninstall.js +18 -0
  268. package/dist/plugins/installer/unzip.d.ts +14 -0
  269. package/dist/plugins/installer/unzip.js +82 -0
  270. package/dist/plugins/installer/update.d.ts +28 -0
  271. package/dist/plugins/installer/update.js +97 -0
  272. package/dist/plugins/loadPluginHooks.d.ts +54 -1
  273. package/dist/plugins/loadPluginHooks.js +83 -1
  274. package/dist/plugins/marketplaceManager.d.ts +15 -1
  275. package/dist/plugins/marketplaceManager.js +58 -4
  276. package/dist/plugins/pluginCommandHook.js +34 -14
  277. package/dist/plugins/pluginContent.d.ts +30 -0
  278. package/dist/plugins/pluginContent.js +83 -0
  279. package/dist/plugins/pluginInstaller.d.ts +34 -0
  280. package/dist/plugins/pluginInstaller.js +168 -35
  281. package/dist/plugins/schemas.js +41 -6
  282. package/dist/plugins/types.d.ts +10 -0
  283. package/dist/preset/index.d.ts +7 -1
  284. package/dist/preset/index.js +112 -6
  285. package/dist/product/types.d.ts +1 -1
  286. package/dist/prompt/composer.d.ts +31 -0
  287. package/dist/prompt/composer.js +95 -25
  288. package/dist/prompt/instruction-scanner.js +5 -3
  289. package/dist/prompt/section-loader.js +1 -0
  290. package/dist/prompt/sections/base.md +1 -0
  291. package/dist/prompt/sections/browser.md +10 -0
  292. package/dist/prompt/sections/coding.md +4 -0
  293. package/dist/prompt/sections/orchestration.md +8 -0
  294. package/dist/protocol/chat-session-manager.d.ts +15 -2
  295. package/dist/protocol/chat-session-manager.js +46 -0
  296. package/dist/protocol/chat-session.d.ts +82 -0
  297. package/dist/protocol/chat-session.js +121 -1
  298. package/dist/protocol/client.d.ts +27 -0
  299. package/dist/protocol/client.js +38 -0
  300. package/dist/protocol/redact.d.ts +50 -0
  301. package/dist/protocol/redact.js +71 -0
  302. package/dist/protocol/server.d.ts +153 -2
  303. package/dist/protocol/server.js +807 -39
  304. package/dist/protocol/tcp-transport.d.ts +45 -0
  305. package/dist/protocol/tcp-transport.js +74 -0
  306. package/dist/protocol/transport.js +3 -2
  307. package/dist/protocol/types.d.ts +69 -0
  308. package/dist/protocol/types.js +22 -0
  309. package/dist/quota/credentials.d.ts +3 -0
  310. package/dist/quota/credentials.js +80 -0
  311. package/dist/quota/index.d.ts +36 -0
  312. package/dist/quota/index.js +155 -0
  313. package/dist/quota/types.d.ts +48 -0
  314. package/dist/quota/types.js +13 -0
  315. package/dist/remote/bridge.d.ts +11 -2
  316. package/dist/remote/bridge.js +61 -33
  317. package/dist/review/review-prompt.d.ts +28 -0
  318. package/dist/review/review-prompt.js +81 -0
  319. package/dist/run/ArtifactTracker.js +5 -4
  320. package/dist/run/EngineRunner.d.ts +27 -1
  321. package/dist/run/EngineRunner.js +46 -8
  322. package/dist/run/FileRunStore.js +40 -11
  323. package/dist/run/RunApprovalBackend.js +25 -5
  324. package/dist/run/RunLock.d.ts +28 -2
  325. package/dist/run/RunLock.js +49 -7
  326. package/dist/run/RunManager.d.ts +12 -0
  327. package/dist/run/RunManager.js +86 -3
  328. package/dist/run/RunQueue.d.ts +1 -0
  329. package/dist/run/RunQueue.js +8 -2
  330. package/dist/run/factory.d.ts +8 -1
  331. package/dist/run/factory.js +1 -0
  332. package/dist/run/index.d.ts +2 -2
  333. package/dist/run/index.js +1 -1
  334. package/dist/run/redirect-target.d.ts +7 -0
  335. package/dist/run/redirect-target.js +13 -0
  336. package/dist/run/types.js +1 -1
  337. package/dist/runtime/background-shell.d.ts +139 -0
  338. package/dist/runtime/background-shell.js +495 -0
  339. package/dist/runtime/output-clean.d.ts +24 -0
  340. package/dist/runtime/output-clean.js +41 -0
  341. package/dist/runtime/ring-file.d.ts +64 -0
  342. package/dist/runtime/ring-file.js +174 -0
  343. package/dist/runtime/safe-spawn.js +15 -34
  344. package/dist/runtime/spawn-common.d.ts +148 -0
  345. package/dist/runtime/spawn-common.js +303 -0
  346. package/dist/runtime/truncate-output.d.ts +22 -0
  347. package/dist/runtime/truncate-output.js +49 -0
  348. package/dist/runtime/utf8-cut.d.ts +11 -0
  349. package/dist/runtime/utf8-cut.js +23 -0
  350. package/dist/services/auto-dream.d.ts +4 -0
  351. package/dist/services/auto-dream.js +26 -26
  352. package/dist/services/browser-open.d.ts +13 -0
  353. package/dist/services/browser-open.js +16 -0
  354. package/dist/services/diagnostics.d.ts +1 -2
  355. package/dist/services/diagnostics.js +12 -7
  356. package/dist/services/dream-consolidation.d.ts +57 -0
  357. package/dist/services/dream-consolidation.js +151 -0
  358. package/dist/services/extract-memories.d.ts +14 -1
  359. package/dist/services/extract-memories.js +45 -6
  360. package/dist/services/memory-orchestrator.d.ts +21 -0
  361. package/dist/services/memory-orchestrator.js +125 -32
  362. package/dist/services/notifier.d.ts +8 -0
  363. package/dist/services/notifier.js +39 -25
  364. package/dist/services/oauth.js +5 -7
  365. package/dist/services/session-memory-sort.d.ts +8 -0
  366. package/dist/services/session-memory-sort.js +9 -0
  367. package/dist/services/session-memory.js +30 -19
  368. package/dist/session/file-history.d.ts +124 -1
  369. package/dist/session/file-history.js +232 -9
  370. package/dist/session/memory.d.ts +116 -2
  371. package/dist/session/memory.js +250 -28
  372. package/dist/session/session-manager.d.ts +63 -1
  373. package/dist/session/session-manager.js +186 -5
  374. package/dist/session/simple-diff.d.ts +23 -0
  375. package/dist/session/simple-diff.js +84 -0
  376. package/dist/session/transcript.d.ts +25 -1
  377. package/dist/session/transcript.js +35 -2
  378. package/dist/session/undo-target.d.ts +67 -0
  379. package/dist/session/undo-target.js +144 -0
  380. package/dist/settings/disk-defaults.d.ts +42 -0
  381. package/dist/settings/disk-defaults.js +33 -0
  382. package/dist/settings/feature-flags.d.ts +64 -0
  383. package/dist/settings/feature-flags.js +61 -0
  384. package/dist/settings/manager.d.ts +101 -1
  385. package/dist/settings/manager.js +345 -15
  386. package/dist/settings/migrate-config.d.ts +45 -0
  387. package/dist/settings/migrate-config.js +125 -0
  388. package/dist/settings/personalization.d.ts +19 -0
  389. package/dist/settings/personalization.js +7 -0
  390. package/dist/settings/schema-export.d.ts +25 -0
  391. package/dist/settings/schema-export.js +38 -0
  392. package/dist/settings/schema.d.ts +1827 -396
  393. package/dist/settings/schema.js +361 -81
  394. package/dist/skills/scanner.d.ts +9 -0
  395. package/dist/skills/scanner.js +30 -2
  396. package/dist/stt/resolve-transcribe.d.ts +31 -0
  397. package/dist/stt/resolve-transcribe.js +108 -0
  398. package/dist/stt/transcribe.d.ts +51 -0
  399. package/dist/stt/transcribe.js +65 -0
  400. package/dist/tool-system/browser-bridge.d.ts +226 -0
  401. package/dist/tool-system/browser-bridge.js +163 -0
  402. package/dist/tool-system/builtin/add-marketplace.d.ts +12 -0
  403. package/dist/tool-system/builtin/add-marketplace.js +76 -0
  404. package/dist/tool-system/builtin/agent-heartbeat.d.ts +49 -0
  405. package/dist/tool-system/builtin/agent-heartbeat.js +89 -0
  406. package/dist/tool-system/builtin/agent-notifications.d.ts +12 -3
  407. package/dist/tool-system/builtin/agent-notifications.js +9 -3
  408. package/dist/tool-system/builtin/agent-output-file.d.ts +38 -0
  409. package/dist/tool-system/builtin/agent-output-file.js +72 -0
  410. package/dist/tool-system/builtin/agent-registry.d.ts +23 -0
  411. package/dist/tool-system/builtin/agent-registry.js +16 -4
  412. package/dist/tool-system/builtin/agent.d.ts +50 -11
  413. package/dist/tool-system/builtin/agent.js +576 -73
  414. package/dist/tool-system/builtin/apply-patch/applier.js +66 -8
  415. package/dist/tool-system/builtin/apply-patch/backup-targets.d.ts +10 -0
  416. package/dist/tool-system/builtin/apply-patch/backup-targets.js +30 -0
  417. package/dist/tool-system/builtin/apply-patch/index.js +7 -3
  418. package/dist/tool-system/builtin/arena.js +6 -7
  419. package/dist/tool-system/builtin/background-jobs.d.ts +76 -0
  420. package/dist/tool-system/builtin/background-jobs.js +124 -0
  421. package/dist/tool-system/builtin/background-shell-tools.d.ts +20 -0
  422. package/dist/tool-system/builtin/background-shell-tools.js +108 -0
  423. package/dist/tool-system/builtin/background-work.d.ts +67 -0
  424. package/dist/tool-system/builtin/background-work.js +86 -0
  425. package/dist/tool-system/builtin/bash-output-style.d.ts +32 -0
  426. package/dist/tool-system/builtin/bash-output-style.js +40 -0
  427. package/dist/tool-system/builtin/bash.d.ts +5 -2
  428. package/dist/tool-system/builtin/bash.js +98 -62
  429. package/dist/tool-system/builtin/browser-tools.d.ts +33 -0
  430. package/dist/tool-system/builtin/browser-tools.js +312 -0
  431. package/dist/tool-system/builtin/cancel-goal.d.ts +31 -0
  432. package/dist/tool-system/builtin/cancel-goal.js +64 -0
  433. package/dist/tool-system/builtin/check-quota.d.ts +15 -0
  434. package/dist/tool-system/builtin/check-quota.js +34 -0
  435. package/dist/tool-system/builtin/complete-goal.d.ts +25 -0
  436. package/dist/tool-system/builtin/complete-goal.js +45 -0
  437. package/dist/tool-system/builtin/config.js +7 -0
  438. package/dist/tool-system/builtin/cron.d.ts +7 -0
  439. package/dist/tool-system/builtin/cron.js +105 -9
  440. package/dist/tool-system/builtin/drive-claude-code.d.ts +30 -0
  441. package/dist/tool-system/builtin/drive-claude-code.js +157 -0
  442. package/dist/tool-system/builtin/edit-model-catalog.d.ts +3 -0
  443. package/dist/tool-system/builtin/edit-model-catalog.js +94 -0
  444. package/dist/tool-system/builtin/edit.d.ts +2 -1
  445. package/dist/tool-system/builtin/edit.js +21 -12
  446. package/dist/tool-system/builtin/eol.d.ts +29 -0
  447. package/dist/tool-system/builtin/eol.js +37 -0
  448. package/dist/tool-system/builtin/file-cache.d.ts +6 -0
  449. package/dist/tool-system/builtin/file-cache.js +8 -0
  450. package/dist/tool-system/builtin/generate-image.d.ts +60 -0
  451. package/dist/tool-system/builtin/generate-image.js +374 -0
  452. package/dist/tool-system/builtin/generate-video.d.ts +55 -0
  453. package/dist/tool-system/builtin/generate-video.js +361 -0
  454. package/dist/tool-system/builtin/grep.js +6 -2
  455. package/dist/tool-system/builtin/image-providers.d.ts +86 -0
  456. package/dist/tool-system/builtin/image-providers.js +190 -0
  457. package/dist/tool-system/builtin/image-uploader.d.ts +33 -0
  458. package/dist/tool-system/builtin/image-uploader.js +74 -0
  459. package/dist/tool-system/builtin/index.d.ts +24 -1
  460. package/dist/tool-system/builtin/index.js +310 -25
  461. package/dist/tool-system/builtin/mcp-tools.js +23 -3
  462. package/dist/tool-system/builtin/memory.js +45 -7
  463. package/dist/tool-system/builtin/notebook-edit.d.ts +2 -1
  464. package/dist/tool-system/builtin/notebook-edit.js +1 -1
  465. package/dist/tool-system/builtin/powershell.js +4 -1
  466. package/dist/tool-system/builtin/read.d.ts +2 -1
  467. package/dist/tool-system/builtin/read.js +11 -3
  468. package/dist/tool-system/builtin/repl.js +4 -1
  469. package/dist/tool-system/builtin/skill.js +9 -0
  470. package/dist/tool-system/builtin/sleep.js +12 -5
  471. package/dist/tool-system/builtin/task.js +4 -1
  472. package/dist/tool-system/builtin/tool-search.js +25 -7
  473. package/dist/tool-system/builtin/update-automation-memory.d.ts +24 -0
  474. package/dist/tool-system/builtin/update-automation-memory.js +60 -0
  475. package/dist/tool-system/builtin/video-providers.d.ts +154 -0
  476. package/dist/tool-system/builtin/video-providers.js +235 -0
  477. package/dist/tool-system/builtin/view-image.d.ts +18 -0
  478. package/dist/tool-system/builtin/view-image.js +96 -0
  479. package/dist/tool-system/builtin/web-fetch.js +12 -2
  480. package/dist/tool-system/builtin/web-search.d.ts +4 -1
  481. package/dist/tool-system/builtin/web-search.js +57 -10
  482. package/dist/tool-system/builtin/worktree.d.ts +2 -1
  483. package/dist/tool-system/builtin/worktree.js +31 -4
  484. package/dist/tool-system/builtin/write.d.ts +2 -1
  485. package/dist/tool-system/builtin/write.js +1 -1
  486. package/dist/tool-system/context.d.ts +166 -6
  487. package/dist/tool-system/executor.d.ts +3 -2
  488. package/dist/tool-system/executor.js +197 -119
  489. package/dist/tool-system/investigation-guard.d.ts +4 -1
  490. package/dist/tool-system/investigation-guard.js +20 -4
  491. package/dist/tool-system/mcp-manager.d.ts +78 -16
  492. package/dist/tool-system/mcp-manager.js +357 -28
  493. package/dist/tool-system/path-policy.d.ts +99 -0
  494. package/dist/tool-system/path-policy.js +578 -0
  495. package/dist/tool-system/permission.d.ts +36 -1
  496. package/dist/tool-system/permission.js +322 -117
  497. package/dist/tool-system/plan-mode-allowlist.d.ts +32 -0
  498. package/dist/tool-system/plan-mode-allowlist.js +65 -0
  499. package/dist/tool-system/registry.d.ts +1 -0
  500. package/dist/tool-system/registry.js +26 -1
  501. package/dist/tool-system/sandbox/index.d.ts +8 -0
  502. package/dist/tool-system/sandbox/index.js +7 -2
  503. package/dist/tool-system/validate-tool-metadata.d.ts +36 -0
  504. package/dist/tool-system/validate-tool-metadata.js +63 -0
  505. package/dist/tool-system/validation.d.ts +10 -0
  506. package/dist/tool-system/validation.js +16 -3
  507. package/dist/types.d.ts +301 -15
  508. package/dist/updater.js +20 -9
  509. package/dist/utils/envUtils.d.ts +0 -9
  510. package/dist/utils/envUtils.js +3 -28
  511. package/dist/utils/exec.d.ts +40 -0
  512. package/dist/utils/exec.js +144 -0
  513. package/dist/utils/format.js +4 -2
  514. package/dist/utils/json.d.ts +12 -0
  515. package/dist/utils/json.js +92 -0
  516. package/dist/utils/lockfile.js +9 -2
  517. package/dist/utils/theme.d.ts +7 -1
  518. package/dist/utils/theme.js +5 -3
  519. package/dist/utils/toolDisplay.js +0 -1
  520. package/package.json +14 -7
  521. package/dist/agent/coordinator.d.ts +0 -49
  522. package/dist/agent/coordinator.js +0 -77
  523. package/dist/settings/manager.test.js +0 -73
  524. package/dist/tool-system/builtin/remote-trigger.d.ts +0 -6
  525. package/dist/tool-system/builtin/remote-trigger.js +0 -54
  526. package/dist/tool-system/builtin/send-message.d.ts +0 -6
  527. package/dist/tool-system/builtin/send-message.js +0 -47
  528. /package/dist/{settings/manager.test.d.ts → credentials/types.js} +0 -0
@@ -16,6 +16,10 @@ export interface ComposerOptions {
16
16
  preset?: AgentPreset;
17
17
  customSystemPrompt?: string;
18
18
  appendSystemPrompt?: string;
19
+ /** User's preferred response language (free text), injected as a stable system section. */
20
+ responseLanguage?: string;
21
+ /** How to address the user / short profile (free text). */
22
+ userProfile?: string;
19
23
  /**
20
24
  * Skill names (full names including any "<plugin>:" prefix) the user
21
25
  * has disabled in settings. Filtered out of the LLM's skills listing
@@ -29,6 +33,20 @@ export interface ComposerOptions {
29
33
  * `${pluginName}:` is filtered. See scanSkills(opts.disabledPlugins).
30
34
  */
31
35
  disabledPlugins?: string[];
36
+ /**
37
+ * Sub-agent skill allowlist (hard isolation). When set, only these skills
38
+ * appear in the LLM's skills listing — applied on top of the disabled
39
+ * lists. Undefined → the full (non-disabled) pool. Mirrors
40
+ * scanSkills(opts.skillAllowlist) so the prompt matches the Skill tool's
41
+ * dispatch gate.
42
+ */
43
+ skillAllowlist?: string[];
44
+ /**
45
+ * settings.memories.maxAge (days). When > 0, memories whose file mtime is
46
+ * older than this are dropped from the injected memory context (TODO 8.1).
47
+ * Undefined/0 → inject all.
48
+ */
49
+ memoriesMaxAgeDays?: number;
32
50
  }
33
51
  export declare class PromptComposer {
34
52
  private readonly options;
@@ -48,6 +66,19 @@ export declare class PromptComposer {
48
66
  * Only injects git status if the resolved preset opts in.
49
67
  */
50
68
  buildSystemContext(): Promise<string>;
69
+ /**
70
+ * Per-turn dynamic context, delivered as a trailing <system-reminder> user
71
+ * message rather than baked into the system prefix.
72
+ *
73
+ * Holds the two things that change *within* a session — the skills listing
74
+ * (changes when a skill is installed/disabled) and the git-status snapshot
75
+ * (changes whenever the working tree changes). Keeping them out of the
76
+ * system prompt means installing a skill or editing a file no longer
77
+ * invalidates the cached system prefix. Placed at the END of the messages
78
+ * array (after the user task) so it sits past the conversation's cache
79
+ * breakpoint — a change here never re-bills the history prefix.
80
+ */
81
+ buildDynamicContextMessage(): Promise<Message | null>;
51
82
  invalidateCache(sectionName?: string): void;
52
83
  private getSections;
53
84
  private getInstructions;
@@ -31,15 +31,21 @@ export class PromptComposer {
31
31
  */
32
32
  buildUserContextMessage() {
33
33
  const instructions = this.getInstructions();
34
- const memoryContext = this.getMemoryContext();
35
- if (!instructions && !memoryContext)
34
+ // NOTE: memory is intentionally NOT here. It used to be, but memory mutates
35
+ // constantly (extraction, recall usage++/lastUsed, approve/demote), and this
36
+ // message sits in the cacheable system prefix — so every memory change
37
+ // invalidated the whole prefix and re-billed it. Memory now rides
38
+ // buildDynamicContextMessage (tail, past the cache breakpoint), same as the
39
+ // skills listing and git status which had the identical problem.
40
+ if (!instructions)
36
41
  return null;
37
- const currentDate = `Today's date is ${new Date().toISOString().split("T")[0]}.`;
42
+ // Local date, not UTC toISOString() is UTC and would show the wrong
43
+ // "today" for users whose timezone has crossed midnight (review-2026-05-30).
44
+ const now = new Date();
45
+ const ymd = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")}`;
46
+ const currentDate = `Today's date is ${ymd}.`;
38
47
  let content = `<system-reminder>\n${currentDate}\n\n`;
39
- if (instructions)
40
- content += `${instructions}\n\n`;
41
- if (memoryContext)
42
- content += `${memoryContext}\n`;
48
+ content += `${instructions}\n`;
43
49
  content += `</system-reminder>`;
44
50
  return { role: "user", content };
45
51
  }
@@ -83,6 +89,38 @@ export class PromptComposer {
83
89
  }
84
90
  return gitStatus;
85
91
  }
92
+ /**
93
+ * Per-turn dynamic context, delivered as a trailing <system-reminder> user
94
+ * message rather than baked into the system prefix.
95
+ *
96
+ * Holds the two things that change *within* a session — the skills listing
97
+ * (changes when a skill is installed/disabled) and the git-status snapshot
98
+ * (changes whenever the working tree changes). Keeping them out of the
99
+ * system prompt means installing a skill or editing a file no longer
100
+ * invalidates the cached system prefix. Placed at the END of the messages
101
+ * array (after the user task) so it sits past the conversation's cache
102
+ * breakpoint — a change here never re-bills the history prefix.
103
+ */
104
+ async buildDynamicContextMessage() {
105
+ const skills = scanSkills(this.options.cwd, {
106
+ disabledSkills: this.options.disabledSkills,
107
+ disabledPlugins: this.options.disabledPlugins,
108
+ skillAllowlist: this.options.skillAllowlist,
109
+ });
110
+ const skillsListing = buildSkillListing(skills);
111
+ const gitStatus = await this.buildSystemContext();
112
+ // Memory rides here (tail, past the cache breakpoint) — not the system
113
+ // prefix — so a memory change (extraction / recall usage++ / approve) never
114
+ // re-bills the cached prefix. See buildUserContextMessage for the rationale.
115
+ const memoryContext = this.getMemoryContext();
116
+ const parts = [skillsListing, gitStatus, memoryContext].filter(Boolean);
117
+ if (parts.length === 0)
118
+ return null;
119
+ return {
120
+ role: "user",
121
+ content: `<system-reminder>\n${parts.join("\n\n")}\n</system-reminder>`,
122
+ };
123
+ }
86
124
  invalidateCache(sectionName) {
87
125
  this.sectionCache.invalidate(sectionName);
88
126
  if (!sectionName) {
@@ -111,36 +149,45 @@ export class PromptComposer {
111
149
  compute: () => this.options.customSystemPrompt,
112
150
  });
113
151
  }
114
- // Tool definitions
152
+ // Tool listing — name + one-line description only. The full JSON schema
153
+ // is NOT repeated here: the provider clients already send it in the
154
+ // native `tools` field (Anthropic tools / OpenAI functions), so dumping
155
+ // `Parameters: {...}` into the system prompt sent every tool's schema
156
+ // twice — a large, per-request token cost for no added model signal.
115
157
  if (tools.length > 0) {
116
158
  sections.push({
117
159
  name: "tool_definitions",
118
160
  compute: () => {
119
- const toolLines = tools.map((t) => `### ${t.name}\n${t.description}\n` +
120
- `Parameters: ${JSON.stringify(t.inputSchema, null, 2)}`);
161
+ const toolLines = tools.map((t) => `### ${t.name}\n${t.description}`);
121
162
  return `# Available Tools\n\n${toolLines.join("\n\n")}`;
122
163
  },
123
164
  });
124
165
  }
125
- // Behavioral instructions — loaded from preset's section files
166
+ // Behavioral instructions — loaded from preset's section files. Pass the
167
+ // turn's effective tool names so tool-gated sections (e.g. "browser") drop
168
+ // when their tools are disabled: browser capability = tools + instructions
169
+ // as one on/off unit.
170
+ const activeToolNames = tools.map((t) => t.name);
126
171
  sections.push({
127
172
  name: "behavior",
173
+ // cacheBreak: this section's content varies by activeToolNames (tool-gated
174
+ // sections like "browser" drop when their tools are off). The cache is
175
+ // keyed by section NAME only, so without cacheBreak a reused composer could
176
+ // serve a stale behavior block across an on/off change. Recompute always —
177
+ // it's a cheap string join, and it makes the browser on/off unit correct
178
+ // regardless of composer lifetime.
179
+ cacheBreak: true,
128
180
  compute: () => {
129
181
  const preset = this.options.preset ?? resolveAgentPreset();
130
- return buildPresetSystemPrompt(preset);
131
- },
132
- });
133
- // Skills listing
134
- sections.push({
135
- name: "skills",
136
- compute: () => {
137
- const skills = scanSkills(this.options.cwd, {
138
- disabledSkills: this.options.disabledSkills,
139
- disabledPlugins: this.options.disabledPlugins,
140
- });
141
- return buildSkillListing(skills);
182
+ return buildPresetSystemPrompt(preset, activeToolNames);
142
183
  },
143
184
  });
185
+ // Skills listing is intentionally NOT a system section: it changes when a
186
+ // skill is installed/disabled, which would invalidate the whole cached
187
+ // system prefix on every change. It rides in the per-turn dynamic-context
188
+ // message instead (buildDynamicContextMessage). Same reasoning keeps the
189
+ // git-status snapshot out of the system prefix — see buildSystemContext's
190
+ // callers.
144
191
  // Append system prompt
145
192
  if (this.options.appendSystemPrompt) {
146
193
  sections.push({
@@ -148,6 +195,23 @@ export class PromptComposer {
148
195
  compute: () => this.options.appendSystemPrompt,
149
196
  });
150
197
  }
198
+ // Personalization — stable user preferences (language + how to address
199
+ // the user). Placed in the cacheable system prefix because it doesn't
200
+ // change per-turn. Only emitted when at least one field is set.
201
+ const { responseLanguage, userProfile } = this.options;
202
+ if (responseLanguage || userProfile) {
203
+ sections.push({
204
+ name: "personalization",
205
+ compute: () => {
206
+ const lines = ["# User & Response Preferences"];
207
+ if (userProfile)
208
+ lines.push(`- About the user: ${userProfile}`);
209
+ if (responseLanguage)
210
+ lines.push(`- Response language: ${responseLanguage}`);
211
+ return lines.join("\n");
212
+ },
213
+ });
214
+ }
151
215
  return sections;
152
216
  }
153
217
  getInstructions() {
@@ -159,8 +223,14 @@ export class PromptComposer {
159
223
  }
160
224
  getMemoryContext() {
161
225
  try {
162
- const mm = new MemoryManager(this.options.cwd);
163
- return mm.buildMemoryContext();
226
+ // Two-layer injection (用户拍板): a compact index merging GLOBAL +
227
+ // PROJECT memories. Global memories are now surfaced every session
228
+ // regardless of cwd (the fix for "global memory never shows up"); the
229
+ // model reads full bodies on demand via MemoryRead.
230
+ return MemoryManager.buildInjectionIndex({
231
+ projectDir: this.options.cwd,
232
+ maxAgeDays: this.options.memoriesMaxAgeDays,
233
+ });
164
234
  }
165
235
  catch {
166
236
  return "";
@@ -17,7 +17,7 @@
17
17
  import { readFileSync, existsSync, readdirSync, statSync } from "node:fs";
18
18
  import { join, dirname, resolve } from "node:path";
19
19
  import { execSync } from "node:child_process";
20
- import { homedir } from "node:os";
20
+ import { userHome } from "../settings/manager.js";
21
21
  // ─── Public API ─────────────────────────────────────────────────────
22
22
  /**
23
23
  * Scan for instruction files from cwd up to the project root,
@@ -32,8 +32,10 @@ export function scanInstructions(cwd, options = {}) {
32
32
  const configDirs = [".codeshell", ...(options.scanDirs ?? []), ".claude"];
33
33
  const entries = [];
34
34
  // 1. User-level instructions
35
- const homeConfigDir = join(homedir(), ".code-shell");
36
- const homeCompatDir = join(homedir(), ".claude");
35
+ // userHome() (not raw homedir(), bun-cached) so a test/host HOME override
36
+ // scans the intended user-level dirs, not the developer's real ~/.code-shell.
37
+ const homeConfigDir = join(userHome(), ".code-shell");
38
+ const homeCompatDir = join(userHome(), ".claude");
37
39
  for (const name of allNames) {
38
40
  tryAddFile(join(homeConfigDir, name), "user", -1, entries);
39
41
  }
@@ -13,6 +13,7 @@ const BUILTIN_SECTIONS = {
13
13
  base: readSectionFile("base"),
14
14
  orchestration: readSectionFile("orchestration"),
15
15
  coding: readSectionFile("coding"),
16
+ browser: readSectionFile("browser"),
16
17
  tone: readSectionFile("tone"),
17
18
  };
18
19
  /** Registry for custom sections added at runtime. */
@@ -31,5 +31,6 @@ When you encounter an obstacle, do not use destructive actions as a shortcut to
31
31
  - To search for files use Glob instead of find or ls
32
32
  - To search the content of files, use Grep instead of grep or rg
33
33
  - Reserve using the Bash exclusively for system commands and terminal operations that require shell execution.
34
+ - For long-lived processes that don't exit on their own — a dev server (`npm run dev`, `vite`), a watcher, a tunnel — call Bash with `run_in_background: true`. It returns a `shell_id` immediately instead of blocking until a timeout. Then use `BashOutput(shell_id)` to read its logs (e.g. to confirm it started or to see an error), `ListShells()` to see what's running, and `KillShell(shell_id)` to stop it. Never run such a command in the foreground — it will just block until it's killed. Plain one-shot commands (build, test, git) stay foreground.
34
35
  - Break down and manage multi-step work with the TodoWrite tool. Pass the complete todo list each call; rewrite it as items move pending → in_progress → completed.
35
36
  - You can call multiple tools in a single response. If you intend to call multiple tools and there are no dependencies between them, make all independent tool calls in parallel.
@@ -0,0 +1,10 @@
1
+ ## Browser automation (browser_observe / browser_act / browser_navigate)
2
+ - When a task needs you to operate a real web page — search a site, open a result, read/extract an article, fill a form — drive the built-in browser panel with the three browser tools. They run on the panel's logged-in session, so the user's existing logins are reused.
3
+ - You do NOT need the user to open the panel first: if none is open, just call `browser_navigate{url}` and the panel opens automatically. After navigating, `browser_act{action:"wait"}` then `browser_observe`.
4
+ - The loop is observe → act → re-observe: ALWAYS `browser_observe` first (default mode `snapshot`) to see the page's interactive elements (each tagged `[ref=eN]`), then `browser_act` on elements BY THAT ref: `{action:"click",ref}`, `{action:"type",ref,text}`, `{action:"select",ref,value}` (native `<select>`), `{action:"hover",ref}`. Refs are only valid for the most recent snapshot — after any navigation, content-loading click, or `{action:"scroll"}`, run `{action:"wait"}` then `browser_observe` again. If an action says a ref is stale, re-observe.
5
+ - To submit a search: `browser_act{action:"type",ref,text}` into the search box, then `browser_act{action:"press_key",key:"Enter"}`, then `{action:"wait"}` + `browser_observe`. `press_key` also does Tab / Escape / arrows / combos like `Control+a`.
6
+ - To extract/summarize page content, navigate/click to it, `browser_act{action:"wait"}`, then `browser_observe{mode:"read"}` — cleaned readable text to summarize (long pages truncate; `{action:"scroll"}` + read again). For the real link/image/video URLs the snapshot omits, use `browser_observe{mode:"extract"}` (each image/video tagged [ref=imgN/vidN]).
7
+ - To SEE an actual image's content (e.g. a 小红书 笔记配图 or product photo), `browser_observe{mode:"extract"}` to get image refs, then `browser_observe{mode:"image", refs:["img3"]}` — it loads the real pixels (works behind hotlink protection). A vidN ref grabs the video's current frame. To see the rendered layout/canvas/chart, `browser_observe{mode:"vision"}` (optionally `ref` for one region). Use images sparingly — they cost tokens; prefer snapshot/read. (Both need a vision-capable model; on a non-vision model they're skipped.) Do NOT repeat `vision` on the same page hoping for a clearer view — one screenshot is all you get. If snapshot/screenshot don't reveal what you need (infinite-scroll/canvas feeds), scroll + re-observe or extract the URLs and act on them — don't loop screenshots.
8
+ - Multiple tabs: `browser_act{action:"list_tabs"}` shows open tabs (tabId/url/title/active); `browser_act{action:"switch_tab", tabId}` makes another the active one (then re-observe). Any action also accepts `tabId` to target a specific tab (it switches first). Refs are per-tab — re-observe after switching.
9
+ - If `browser_observe` reports a sign-in is required (or you hit a login wall / 2FA), STOP and ask the user to log in manually in the browser panel, then continue — do not attempt to enter credentials yourself. Sensitive actions (payment, delete, entering card/password values) require user approval.
10
+ - These tools need the desktop app's browser panel; if they report unavailable, the environment has no panel (headless) — say so rather than retrying.
@@ -26,6 +26,10 @@ The default job in this preset is software engineering in the current working di
26
26
  - When referencing specific functions or pieces of code include the pattern file_path:line_number to allow the user to easily navigate to the source code location.
27
27
  - When referencing GitHub issues or pull requests, use the owner/repo#123 format so they render as clickable links.
28
28
 
29
+ ## Opening URLs and local previews
30
+ - To show the user a web page or a local dev-server preview, print the address in your reply as a bare URL or a markdown link (e.g. `http://localhost:5173` or [预览](http://localhost:5173)) — do NOT wrap it in backticks. The desktop app turns a link in your answer into a clickable link that opens inside its built-in browser panel; backtick-wrapped URLs render as plain code and are not clickable.
31
+ - Do NOT run shell commands to open a URL (`open <url>` on macOS, `xdg-open` on Linux, `start <url>` on Windows). Those launch the user's external system browser and bypass the in-app browser panel. Start the dev server, then just tell the user the address as a link.
32
+
29
33
  ## Coding tools
30
34
  - Use git/worktree/LSP/notebook tools when they help, but treat them as optional helpers rather than core assumptions.
31
35
  - If the user asks for help or feedback, point them to /help and the project repository.
@@ -6,6 +6,14 @@
6
6
  - Avoid creating files unless they are genuinely needed. Prefer editing existing files to creating new ones.
7
7
  - Avoid giving time estimates or predictions for how long tasks will take.
8
8
 
9
+ # Delegating to sub-agents (Agent)
10
+ - A sub-agent runs in its own **clean, isolated context** and returns only its final report. It is stateless — you cannot send follow-up messages, so its prompt must be a complete, self-contained task description.
11
+ - **The primary reason to delegate is context hygiene, not speed.** When a task needs to read many files or run a long exploration but you only need the *conclusion*, hand it to a sub-agent: it does the noisy work in its own context and you keep the answer, not the file dumps. This is the default move for any sweep that would otherwise flood your own context with intermediate output.
12
+ - **Parallel fan-out is the exception, not the default.** Only launch several sub-agents at once when the work genuinely splits into independent pieces with no shared state or ordering. Don't open multiple agents just because a task *could* be subdivided — one well-scoped delegation usually beats a swarm.
13
+ - **Delegate the dirty work, keep the thinking.** Push file-reading, searching, and broad investigation into sub-agents; do the synthesis, decisions, and edits yourself in the main thread.
14
+ - **Don't delegate trivial lookups.** If you know the file/symbol/value and expect a few matches, use Read/Grep/Glob directly — spinning up an agent for that wastes a turn and tokens.
15
+ - If you delegate a chunk of work, add a TodoWrite item for it so the user sees it without reading the sub-agent's transcript.
16
+
9
17
  # Task tracking (TodoWrite)
10
18
  - When the user's request decomposes into 3+ discrete steps, call **TodoWrite** with the complete list up front. The user has a pinned task panel and relies on it to see what's queued, in progress, and done.
11
19
  - **TodoWrite takes the complete list each time** — there is no per-item update. To change a status, call TodoWrite again with the whole list, only that item's `status` changed. Your previous TodoWrite input IS the source of truth — re-read it before rewriting.
@@ -1,8 +1,8 @@
1
1
  import { ChatSession } from "./chat-session.js";
2
2
  import type { Engine } from "../engine/engine.js";
3
3
  import type { EngineRuntime } from "../engine/runtime.js";
4
- import type { EngineConfig } from "../engine/engine.js";
5
- export type EngineConfigSlice = Pick<EngineConfig, "permissionMode" | "preset" | "customSystemPrompt" | "appendSystemPrompt" | "maxTurns" | "maxContextTokens" | "cwd">;
4
+ import type { EngineConfig } from "../engine/types.js";
5
+ export type EngineConfigSlice = Pick<EngineConfig, "permissionMode" | "preset" | "customSystemPrompt" | "appendSystemPrompt" | "goal" | "maxTurns" | "maxContextTokens" | "cwd" | "projectTrusted">;
6
6
  export interface ChatSessionManagerOptions {
7
7
  /**
8
8
  * Shared runtime, supplied here so callers and engineFactory closures
@@ -24,8 +24,21 @@ export declare class ChatSessionManager {
24
24
  constructor(opts: ChatSessionManagerOptions);
25
25
  getOrCreate(sessionId: string, slice: EngineConfigSlice): ChatSession;
26
26
  get(sessionId: string): ChatSession | undefined;
27
+ /**
28
+ * Iterate every live session once. Public iterator so callers (e.g. the
29
+ * protocol server's config hot-reload / sessions query) don't reach into
30
+ * the private `sessions` map with an `as any` cast. Iterates a snapshot of
31
+ * the values so a callback that closes a session can't perturb the walk.
32
+ */
33
+ forEachSession(fn: (s: ChatSession) => void): void;
27
34
  close(sessionId: string): void;
28
35
  closeAll(): void;
36
+ /**
37
+ * Await-able shutdown. Cancels every session and reaps every background
38
+ * shell, *waiting* for the kill grace so a caller that exits the process
39
+ * immediately afterward (the TUI REPL) doesn't orphan detached dev servers.
40
+ */
41
+ closeAllAsync(): Promise<void>;
29
42
  sessionCount(): number;
30
43
  sweepIdle(): void;
31
44
  startIdleSweeper(intervalMs?: number): void;
@@ -1,4 +1,6 @@
1
1
  import { ChatSession } from "./chat-session.js";
2
+ import { backgroundShellManager } from "../runtime/background-shell.js";
3
+ import { clearAgentOutputFiles } from "../tool-system/builtin/agent-output-file.js";
2
4
  export class ChatSessionManager {
3
5
  sessions = new Map();
4
6
  factory;
@@ -14,6 +16,17 @@ export class ChatSessionManager {
14
16
  const existing = this.sessions.get(sessionId);
15
17
  if (existing) {
16
18
  existing.lastActivityAt = Date.now();
19
+ // Re-apply the per-send permission mode so a pill change on an
20
+ // already-running session takes effect on the NEXT turn. Without this the
21
+ // engine kept whatever mode it was first created with — changing the pill
22
+ // on a resumed session was silently ignored at enforcement time (#11
23
+ // secondary: "档位 doesn't take effect after first send"). setPermissionMode
24
+ // reconfigures the live permission backend, so it's safe between turns.
25
+ if (slice.permissionMode &&
26
+ typeof existing.engine.getPermissionMode === "function" &&
27
+ existing.engine.getPermissionMode() !== slice.permissionMode) {
28
+ existing.engine.setPermissionMode(slice.permissionMode);
29
+ }
17
30
  return existing;
18
31
  }
19
32
  if (this.sessions.size >= this.maxSessions) {
@@ -29,6 +42,16 @@ export class ChatSessionManager {
29
42
  get(sessionId) {
30
43
  return this.sessions.get(sessionId);
31
44
  }
45
+ /**
46
+ * Iterate every live session once. Public iterator so callers (e.g. the
47
+ * protocol server's config hot-reload / sessions query) don't reach into
48
+ * the private `sessions` map with an `as any` cast. Iterates a snapshot of
49
+ * the values so a callback that closes a session can't perturb the walk.
50
+ */
51
+ forEachSession(fn) {
52
+ for (const s of [...this.sessions.values()])
53
+ fn(s);
54
+ }
32
55
  close(sessionId) {
33
56
  const s = this.sessions.get(sessionId);
34
57
  if (!s)
@@ -37,8 +60,31 @@ export class ChatSessionManager {
37
60
  this.sessions.delete(sessionId);
38
61
  }
39
62
  closeAll() {
63
+ // Fire-and-forget variant for callers that can't await (e.g. AgentServer
64
+ // teardown inside a sync stop path). The TUI exit path uses closeAllAsync()
65
+ // below so the SIGTERM→SIGKILL grace actually completes before the process
66
+ // exits — otherwise startInkRepl's process.exit(0) races the kill and the
67
+ // detached shells leak as orphans.
68
+ void this.closeAllAsync();
69
+ }
70
+ /**
71
+ * Await-able shutdown. Cancels every session and reaps every background
72
+ * shell, *waiting* for the kill grace so a caller that exits the process
73
+ * immediately afterward (the TUI REPL) doesn't orphan detached dev servers.
74
+ */
75
+ async closeAllAsync() {
40
76
  for (const id of [...this.sessions.keys()])
41
77
  this.close(id);
78
+ // App/worker shutdown — reap every background shell so a detached
79
+ // `npm run dev` doesn't outlive the process as an orphan holding a port
80
+ // (design §6 / §难点1). NOTE: deliberately NOT in close()/sweepIdle() —
81
+ // an idle chat tab must keep its dev server alive (§6 "切走再回来 server 还在").
82
+ await backgroundShellManager.killAll();
83
+ // Background-agent output files are a debugging convenience, not durable
84
+ // state — wipe them on shutdown so ~/.code-shell/agents doesn't grow
85
+ // unbounded across runs. (notificationQueue, the real result path, is
86
+ // in-memory and already gone.)
87
+ await clearAgentOutputFiles();
42
88
  }
43
89
  sessionCount() {
44
90
  return this.sessions.size;
@@ -10,6 +10,13 @@ export interface TurnOpts {
10
10
  * configured cwd. */
11
11
  cwd?: string;
12
12
  onStream?: (event: StreamEvent) => void;
13
+ /** Goal mode for this turn — forwarded to engine.run (loop-until-done).
14
+ * String objective or full GoalConfig (objective + optional budgets). */
15
+ goal?: string | import("../engine/goal.js").GoalConfig;
16
+ /** Marks this turn as a synthetic system-reminder injection (background-job
17
+ * completion notification) rather than the user's own input — persisted so
18
+ * the disk reader skips it as a user bubble on replay. See Engine.run. */
19
+ injected?: boolean;
13
20
  }
14
21
  /**
15
22
  * One ChatSession per UI chat tab. Owns a single Engine, an AbortController
@@ -32,8 +39,39 @@ export declare class ChatSession {
32
39
  private active;
33
40
  private controller;
34
41
  private readonly defaultOnStream?;
42
+ /**
43
+ * Model-pool key requested via requestModelSwitch while a turn was in
44
+ * flight. Applied at the next run boundary (before the next turn starts) so
45
+ * we never swap the model out from under a running LLM client — the bug the
46
+ * session-isolation research flagged. null = nothing pending.
47
+ */
48
+ private pendingModel;
49
+ /**
50
+ * Set by cancel() so the in-flight turn's abort error resolves as a clean
51
+ * "cancelled" result instead of rejecting (which the RPC layer would surface
52
+ * as a scary red Error in the UI for what was a user-initiated Stop). The
53
+ * onboarding flow cancels + immediately re-runs the same task; without this
54
+ * the cancelled first run popped "Error: Request cancelled".
55
+ */
56
+ private cancelledActive;
57
+ /**
58
+ * Sticky flag: the user cancelled (Stop) and has not started a new turn
59
+ * since. cancel() leaves the session idle (active=null), so isBusy() can't
60
+ * distinguish "naturally idle" from "user just stopped me". A background-job
61
+ * completion that lands in this window must NOT auto-resume the session —
62
+ * that would defeat the Stop. Cleared the moment a real turn is enqueued
63
+ * (the user is engaging again) so normal wakeups resume working afterward.
64
+ */
65
+ private cancelledSinceLastTurn;
35
66
  constructor(opts: ChatSessionOptions);
36
67
  enqueueTurn(task: string, opts: TurnOpts): Promise<EngineResult>;
68
+ /**
69
+ * True when the user hit Stop and hasn't started a new turn since. The server
70
+ * consults this before auto-waking an idle session on a background-job
71
+ * completion, so a download finishing right after Stop doesn't restart the
72
+ * agent the user just halted.
73
+ */
74
+ wasCancelledSinceLastTurn(): boolean;
37
75
  /**
38
76
  * Abort the in-flight turn and drain queued turns.
39
77
  *
@@ -44,6 +82,50 @@ export declare class ChatSession {
44
82
  */
45
83
  cancel(): void;
46
84
  isBusy(): boolean;
85
+ /**
86
+ * Extend the in-flight goal run's turn/budget ceilings (TODO 3.1). Delegates
87
+ * to the engine, which forwards to the active TurnLoop. Returns null when no
88
+ * run is active (or the run has no extendable loop). Mirrors the cancel()
89
+ * mid-run control path.
90
+ */
91
+ extendGoalRun(opts: {
92
+ addTurns?: number;
93
+ addTokenBudget?: number;
94
+ addTimeBudgetMs?: number;
95
+ addStopBlocks?: number;
96
+ }): {
97
+ maxTurns: number;
98
+ tokenBudget?: number;
99
+ timeBudgetMs?: number;
100
+ maxStopBlocks: number;
101
+ } | null;
102
+ /**
103
+ * Read this session's persisted active goal (state.activeGoal), or undefined
104
+ * when none. Cheap — reads only state.json. The host calls this on session
105
+ * load to re-surface the goal block + Cancel button after a reload.
106
+ */
107
+ getGoal(): import("../engine/goal.js").GoalConfig | undefined;
108
+ /**
109
+ * Clear this session's persisted active goal (CC /goal clear). Works idle or
110
+ * mid-run. Returns true if a goal was actually cleared.
111
+ */
112
+ clearGoal(): boolean;
113
+ /**
114
+ * Switch this session's active model (per-session, not worker-global).
115
+ * Applies immediately when idle; defers to the next run boundary when a
116
+ * turn is in flight so a hot switch never mutates the model under a
117
+ * running LLM client.
118
+ */
119
+ requestModelSwitch(key: string): void;
120
+ /**
121
+ * Perform the actual model switch for this session: rotate the engine's model
122
+ * and reset the session's cumulative usage on disk — a different model has a
123
+ * different prompt cache, so the old cache-hit stats no longer apply. The
124
+ * renderer zeroes its own cumulative display when it issues the switch (it's
125
+ * renderer-initiated), so no stream event is needed here. Shared by the idle
126
+ * path and the deferred run-boundary path.
127
+ */
128
+ private applyModelSwitch;
47
129
  queueDepth(): number;
48
130
  private pump;
49
131
  }