@cjhyy/code-shell-core 0.5.0-rc.0 → 0.5.0-rc.2

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 (283) hide show
  1. package/dist/agent/agent-definition-registry.d.ts +29 -0
  2. package/dist/agent/agent-definition-registry.js +74 -0
  3. package/dist/agent/agent-definition.d.ts +37 -0
  4. package/dist/agent/agent-definition.js +59 -0
  5. package/dist/arena/arena.js +11 -12
  6. package/dist/arena/context/context-tools.js +2 -4
  7. package/dist/arena/context/within-root.d.ts +7 -0
  8. package/dist/arena/context/within-root.js +15 -0
  9. package/dist/arena/iterate/phases/argue.js +8 -2
  10. package/dist/arena/iterate/phases/revise.js +1 -1
  11. package/dist/arena/iterate/phases/tournament.js +3 -3
  12. package/dist/arena/phases/adjudication.js +1 -4
  13. package/dist/arena/phases/build-consensus.js +1 -4
  14. package/dist/arena/phases/cross-review.js +2 -8
  15. package/dist/arena/phases/debate-rounds.js +1 -4
  16. package/dist/arena/phases/participant-research.js +1 -4
  17. package/dist/arena/phases/planning-detail-expansion.js +8 -10
  18. package/dist/arena/planner.js +0 -1
  19. package/dist/arena/providers/docs.d.ts +1 -0
  20. package/dist/arena/providers/docs.js +5 -2
  21. package/dist/arena/providers/repo.d.ts +1 -0
  22. package/dist/arena/providers/repo.js +5 -2
  23. package/dist/arena/strategies/utils.js +36 -3
  24. package/dist/arena/transitions.d.ts +7 -2
  25. package/dist/arena/transitions.js +9 -4
  26. package/dist/arena/types.d.ts +8 -2
  27. package/dist/automation/cron-expr.d.ts +31 -0
  28. package/dist/automation/cron-expr.js +151 -0
  29. package/dist/automation/index.d.ts +41 -0
  30. package/dist/automation/index.js +39 -0
  31. package/dist/automation/runner.d.ts +67 -0
  32. package/dist/automation/runner.js +56 -0
  33. package/dist/automation/scheduler.d.ts +156 -0
  34. package/dist/automation/scheduler.js +546 -0
  35. package/dist/automation/store.d.ts +39 -0
  36. package/dist/automation/store.js +119 -0
  37. package/dist/automation/write-policy.d.ts +34 -0
  38. package/dist/automation/write-policy.js +113 -0
  39. package/dist/automation/write-run.d.ts +51 -0
  40. package/dist/automation/write-run.js +38 -0
  41. package/dist/capability-control/index.d.ts +5 -0
  42. package/dist/capability-control/index.js +3 -0
  43. package/dist/capability-control/overlay.d.ts +49 -0
  44. package/dist/capability-control/overlay.js +89 -0
  45. package/dist/capability-control/project.d.ts +65 -0
  46. package/dist/capability-control/project.js +147 -0
  47. package/dist/capability-control/service.d.ts +70 -0
  48. package/dist/capability-control/service.js +147 -0
  49. package/dist/capability-control/types.d.ts +62 -0
  50. package/dist/capability-control/types.js +17 -0
  51. package/dist/cli/agent-server-stdio.d.ts +12 -1
  52. package/dist/cli/agent-server-stdio.js +118 -18
  53. package/dist/cli/agent-server-tcp.d.ts +20 -0
  54. package/dist/cli/agent-server-tcp.js +120 -0
  55. package/dist/cli/graceful-shutdown.d.ts +27 -0
  56. package/dist/cli/graceful-shutdown.js +30 -0
  57. package/dist/context/compaction.js +23 -15
  58. package/dist/context/manager.d.ts +0 -20
  59. package/dist/context/manager.js +0 -37
  60. package/dist/cron/cron-runtime.d.ts +2 -0
  61. package/dist/cron/cron-runtime.js +2 -0
  62. package/dist/cron/cron-store.d.ts +2 -0
  63. package/dist/cron/cron-store.js +2 -0
  64. package/dist/cron/scheduler.d.ts +5 -32
  65. package/dist/cron/scheduler.js +5 -113
  66. package/dist/data/openrouter-sync.js +1 -1
  67. package/dist/engine/engine.d.ts +256 -16
  68. package/dist/engine/engine.js +856 -200
  69. package/dist/engine/goal.d.ts +42 -0
  70. package/dist/engine/goal.js +52 -0
  71. package/dist/engine/image-compression.d.ts +81 -0
  72. package/dist/engine/image-compression.js +186 -0
  73. package/dist/engine/image-policy.d.ts +152 -0
  74. package/dist/engine/image-policy.js +165 -0
  75. package/dist/engine/reactive-threshold.d.ts +13 -0
  76. package/dist/engine/reactive-threshold.js +17 -0
  77. package/dist/engine/runtime.js +7 -0
  78. package/dist/engine/session-title.d.ts +13 -0
  79. package/dist/engine/session-title.js +34 -0
  80. package/dist/engine/turn-loop.d.ts +29 -8
  81. package/dist/engine/turn-loop.js +498 -316
  82. package/dist/git/parse-log.d.ts +13 -0
  83. package/dist/git/parse-log.js +21 -0
  84. package/dist/git/utils.d.ts +8 -6
  85. package/dist/git/utils.js +57 -26
  86. package/dist/git/worktree.js +33 -18
  87. package/dist/hooks/events.d.ts +23 -1
  88. package/dist/hooks/goal-stop-hook.d.ts +30 -0
  89. package/dist/hooks/goal-stop-hook.js +102 -0
  90. package/dist/hooks/hook-output.d.ts +33 -0
  91. package/dist/hooks/hook-output.js +79 -0
  92. package/dist/hooks/registry.d.ts +7 -0
  93. package/dist/hooks/registry.js +38 -1
  94. package/dist/hooks/shell-runner.d.ts +2 -0
  95. package/dist/hooks/shell-runner.js +43 -2
  96. package/dist/index.d.ts +32 -7
  97. package/dist/index.js +30 -3
  98. package/dist/llm/capabilities/reasoning-control.d.ts +24 -0
  99. package/dist/llm/capabilities/reasoning-control.js +38 -0
  100. package/dist/llm/capabilities/rules.js +33 -3
  101. package/dist/llm/capabilities/types.d.ts +22 -2
  102. package/dist/llm/clamp-max-tokens.d.ts +11 -0
  103. package/dist/llm/clamp-max-tokens.js +17 -0
  104. package/dist/llm/client-base.d.ts +41 -4
  105. package/dist/llm/client-base.js +67 -13
  106. package/dist/llm/client-factory.d.ts +3 -3
  107. package/dist/llm/client-factory.js +2 -2
  108. package/dist/llm/model-pool.d.ts +15 -11
  109. package/dist/llm/model-pool.js +23 -20
  110. package/dist/llm/provider-catalog.d.ts +2 -2
  111. package/dist/llm/providers/anthropic.d.ts +32 -2
  112. package/dist/llm/providers/anthropic.js +147 -8
  113. package/dist/llm/providers/openai.d.ts +11 -2
  114. package/dist/llm/providers/openai.js +253 -52
  115. package/dist/llm/reasoning-setting.d.ts +51 -0
  116. package/dist/llm/reasoning-setting.js +32 -0
  117. package/dist/llm/stop-reason.d.ts +13 -0
  118. package/dist/llm/stop-reason.js +21 -0
  119. package/dist/llm/strip-vision.d.ts +32 -0
  120. package/dist/llm/strip-vision.js +94 -0
  121. package/dist/llm/types.d.ts +5 -6
  122. package/dist/logging/logger.js +18 -4
  123. package/dist/logging/sanitize-messages.d.ts +10 -0
  124. package/dist/logging/sanitize-messages.js +90 -0
  125. package/dist/lsp/client.js +28 -8
  126. package/dist/lsp/manager.js +2 -1
  127. package/dist/lsp/root-path.d.ts +9 -0
  128. package/dist/lsp/root-path.js +12 -0
  129. package/dist/onboarding.js +18 -11
  130. package/dist/plugins/gitOps.d.ts +34 -0
  131. package/dist/plugins/gitOps.js +59 -3
  132. package/dist/plugins/installer/codex/convertAgents.d.ts +7 -0
  133. package/dist/plugins/installer/codex/convertAgents.js +55 -0
  134. package/dist/plugins/installer/codex/convertMcp.d.ts +8 -0
  135. package/dist/plugins/installer/codex/convertMcp.js +45 -0
  136. package/dist/plugins/installer/codex/convertSkills.d.ts +12 -0
  137. package/dist/plugins/installer/codex/convertSkills.js +33 -0
  138. package/dist/plugins/installer/detectFormat.d.ts +2 -0
  139. package/dist/plugins/installer/detectFormat.js +6 -0
  140. package/dist/plugins/installer/install.d.ts +7 -0
  141. package/dist/plugins/installer/install.js +99 -0
  142. package/dist/plugins/installer/installFromSource.d.ts +13 -0
  143. package/dist/plugins/installer/installFromSource.js +45 -0
  144. package/dist/plugins/installer/list.d.ts +9 -0
  145. package/dist/plugins/installer/list.js +30 -0
  146. package/dist/plugins/installer/loadPluginAgents.d.ts +3 -0
  147. package/dist/plugins/installer/loadPluginAgents.js +23 -0
  148. package/dist/plugins/installer/loadPluginMcp.d.ts +7 -0
  149. package/dist/plugins/installer/loadPluginMcp.js +74 -0
  150. package/dist/plugins/installer/parseSource.d.ts +20 -0
  151. package/dist/plugins/installer/parseSource.js +74 -0
  152. package/dist/plugins/installer/paths.d.ts +5 -0
  153. package/dist/plugins/installer/paths.js +25 -0
  154. package/dist/plugins/installer/types.d.ts +49 -0
  155. package/dist/plugins/installer/types.js +27 -0
  156. package/dist/plugins/installer/uninstall.d.ts +2 -0
  157. package/dist/plugins/installer/uninstall.js +14 -0
  158. package/dist/plugins/installer/update.d.ts +14 -0
  159. package/dist/plugins/installer/update.js +65 -0
  160. package/dist/plugins/loadPluginHooks.d.ts +8 -1
  161. package/dist/plugins/loadPluginHooks.js +11 -1
  162. package/dist/plugins/marketplaceManager.d.ts +8 -1
  163. package/dist/plugins/marketplaceManager.js +38 -4
  164. package/dist/plugins/pluginCommandHook.js +34 -0
  165. package/dist/plugins/pluginInstaller.d.ts +21 -0
  166. package/dist/plugins/pluginInstaller.js +128 -29
  167. package/dist/plugins/schemas.js +40 -6
  168. package/dist/plugins/types.d.ts +4 -0
  169. package/dist/preset/index.js +16 -0
  170. package/dist/prompt/composer.d.ts +10 -0
  171. package/dist/prompt/composer.js +29 -4
  172. package/dist/prompt/sections/orchestration.md +8 -0
  173. package/dist/protocol/chat-session-manager.d.ts +8 -1
  174. package/dist/protocol/chat-session-manager.js +10 -0
  175. package/dist/protocol/chat-session.d.ts +17 -0
  176. package/dist/protocol/chat-session.js +28 -0
  177. package/dist/protocol/redact.d.ts +50 -0
  178. package/dist/protocol/redact.js +71 -0
  179. package/dist/protocol/server.d.ts +41 -2
  180. package/dist/protocol/server.js +231 -33
  181. package/dist/protocol/tcp-transport.d.ts +45 -0
  182. package/dist/protocol/tcp-transport.js +74 -0
  183. package/dist/protocol/types.d.ts +23 -0
  184. package/dist/protocol/types.js +6 -0
  185. package/dist/remote/bridge.d.ts +11 -2
  186. package/dist/remote/bridge.js +61 -33
  187. package/dist/run/ArtifactTracker.js +5 -4
  188. package/dist/run/EngineRunner.d.ts +27 -1
  189. package/dist/run/EngineRunner.js +46 -8
  190. package/dist/run/FileRunStore.js +32 -8
  191. package/dist/run/RunLock.d.ts +28 -2
  192. package/dist/run/RunLock.js +49 -7
  193. package/dist/run/RunManager.js +51 -3
  194. package/dist/run/RunQueue.d.ts +1 -0
  195. package/dist/run/RunQueue.js +8 -2
  196. package/dist/run/factory.d.ts +7 -0
  197. package/dist/run/factory.js +1 -0
  198. package/dist/run/index.d.ts +2 -2
  199. package/dist/run/index.js +1 -1
  200. package/dist/run/redirect-target.d.ts +7 -0
  201. package/dist/run/redirect-target.js +13 -0
  202. package/dist/run/types.js +1 -1
  203. package/dist/services/browser-open.d.ts +13 -0
  204. package/dist/services/browser-open.js +16 -0
  205. package/dist/services/dream-consolidation.d.ts +57 -0
  206. package/dist/services/dream-consolidation.js +151 -0
  207. package/dist/services/memory-orchestrator.js +18 -0
  208. package/dist/services/notifier.d.ts +8 -0
  209. package/dist/services/notifier.js +39 -25
  210. package/dist/services/oauth.js +5 -7
  211. package/dist/services/session-memory-sort.d.ts +8 -0
  212. package/dist/services/session-memory-sort.js +9 -0
  213. package/dist/services/session-memory.js +8 -9
  214. package/dist/session/file-history.js +10 -3
  215. package/dist/session/session-manager.d.ts +23 -1
  216. package/dist/session/session-manager.js +73 -2
  217. package/dist/settings/disk-defaults.d.ts +35 -0
  218. package/dist/settings/disk-defaults.js +24 -0
  219. package/dist/settings/manager.d.ts +45 -1
  220. package/dist/settings/manager.js +121 -17
  221. package/dist/settings/manager.test.d.ts +1 -0
  222. package/dist/settings/manager.test.js +73 -0
  223. package/dist/settings/personalization.d.ts +19 -0
  224. package/dist/settings/personalization.js +7 -0
  225. package/dist/settings/schema.d.ts +1163 -126
  226. package/dist/settings/schema.js +126 -10
  227. package/dist/skills/scanner.d.ts +13 -6
  228. package/dist/skills/scanner.js +23 -4
  229. package/dist/tool-system/builtin/add-marketplace.d.ts +12 -0
  230. package/dist/tool-system/builtin/add-marketplace.js +76 -0
  231. package/dist/tool-system/builtin/agent-registry.d.ts +15 -0
  232. package/dist/tool-system/builtin/agent-registry.js +14 -4
  233. package/dist/tool-system/builtin/agent.d.ts +55 -0
  234. package/dist/tool-system/builtin/agent.js +165 -17
  235. package/dist/tool-system/builtin/apply-patch/index.js +22 -3
  236. package/dist/tool-system/builtin/arena.js +6 -7
  237. package/dist/tool-system/builtin/complete-goal.d.ts +25 -0
  238. package/dist/tool-system/builtin/complete-goal.js +45 -0
  239. package/dist/tool-system/builtin/cron.js +53 -9
  240. package/dist/tool-system/builtin/edit.d.ts +2 -1
  241. package/dist/tool-system/builtin/edit.js +6 -1
  242. package/dist/tool-system/builtin/generate-image.d.ts +25 -0
  243. package/dist/tool-system/builtin/generate-image.js +146 -0
  244. package/dist/tool-system/builtin/glob.js +7 -0
  245. package/dist/tool-system/builtin/grep.js +6 -0
  246. package/dist/tool-system/builtin/index.d.ts +18 -1
  247. package/dist/tool-system/builtin/index.js +62 -1
  248. package/dist/tool-system/builtin/notebook-edit.d.ts +2 -1
  249. package/dist/tool-system/builtin/notebook-edit.js +8 -1
  250. package/dist/tool-system/builtin/read.d.ts +2 -1
  251. package/dist/tool-system/builtin/read.js +9 -1
  252. package/dist/tool-system/builtin/skill.js +23 -5
  253. package/dist/tool-system/builtin/sleep.js +9 -3
  254. package/dist/tool-system/builtin/task.js +4 -1
  255. package/dist/tool-system/builtin/update-automation-memory.d.ts +24 -0
  256. package/dist/tool-system/builtin/update-automation-memory.js +60 -0
  257. package/dist/tool-system/builtin/view-image.d.ts +18 -0
  258. package/dist/tool-system/builtin/view-image.js +96 -0
  259. package/dist/tool-system/builtin/web-search.d.ts +4 -1
  260. package/dist/tool-system/builtin/web-search.js +36 -3
  261. package/dist/tool-system/builtin/write.d.ts +2 -1
  262. package/dist/tool-system/builtin/write.js +7 -1
  263. package/dist/tool-system/context.d.ts +43 -0
  264. package/dist/tool-system/executor.d.ts +0 -1
  265. package/dist/tool-system/executor.js +34 -40
  266. package/dist/tool-system/investigation-guard.d.ts +4 -1
  267. package/dist/tool-system/investigation-guard.js +19 -3
  268. package/dist/tool-system/mcp-manager.d.ts +36 -12
  269. package/dist/tool-system/mcp-manager.js +173 -10
  270. package/dist/tool-system/path-policy.d.ts +94 -0
  271. package/dist/tool-system/path-policy.js +279 -0
  272. package/dist/tool-system/permission.js +43 -50
  273. package/dist/tool-system/plan-mode-allowlist.d.ts +21 -0
  274. package/dist/tool-system/plan-mode-allowlist.js +43 -0
  275. package/dist/tool-system/registry.js +12 -1
  276. package/dist/tool-system/validation.d.ts +10 -0
  277. package/dist/tool-system/validation.js +16 -3
  278. package/dist/types.d.ts +90 -15
  279. package/dist/utils/format.js +4 -2
  280. package/dist/utils/lockfile.js +9 -2
  281. package/dist/utils/theme.d.ts +6 -0
  282. package/dist/utils/theme.js +4 -2
  283. package/package.json +2 -1
@@ -1,22 +1,44 @@
1
1
  /**
2
2
  * Engine — the main facade that wires all components together.
3
3
  */
4
- import type { LLMConfig, StreamCallback, TerminalReason, TokenUsage } from "../types.js";
4
+ import type { ClientDefaults, LLMConfig, SessionOrigin, StreamCallback, TerminalReason, TokenUsage } from "../types.js";
5
5
  import { ToolRegistry } from "../tool-system/registry.js";
6
+ import { type BuiltinToolFn } from "../tool-system/builtin/index.js";
6
7
  import { type ApprovalBackend } from "../tool-system/permission.js";
7
8
  import { HookRegistry } from "../hooks/registry.js";
8
9
  import type { HookEventName } from "../hooks/events.js";
9
10
  import type { HookHandler } from "../hooks/registry.js";
11
+ import { type GoalConfig } from "./goal.js";
10
12
  import { SessionManager } from "../session/session-manager.js";
11
13
  import type { CostStateStore } from "./cost-store.js";
12
14
  import type { AskUserFn } from "../tool-system/builtin/ask-user.js";
15
+ import { type SettingsScope } from "../settings/manager.js";
16
+ import type { CapabilityOverride } from "../settings/schema.js";
13
17
  import type { ToolContext } from "../tool-system/context.js";
14
18
  import { type SandboxConfig } from "../tool-system/sandbox/index.js";
15
19
  import { type AgentPresetName } from "../preset/index.js";
16
20
  import { ModelPool, type ModelEntry } from "../llm/model-pool.js";
21
+ import { AgentDefinitionRegistry } from "../agent/agent-definition-registry.js";
17
22
  import { EngineRuntime } from "./runtime.js";
23
+ /**
24
+ * Build ScanOptions.compatFileNames from the user's instruction compat toggles.
25
+ * Primary file name stays hard-wired to CODESHELL.md (not exposed). Turning a
26
+ * compat flag off only drops the same-named .md (CLAUDE.md / AGENTS.md); the
27
+ * .claude/ subdir, *.local.md and rules/ are intentionally NOT linked.
28
+ * undefined (instructions omitted) means both stay on — backward compatible.
29
+ */
30
+ export declare function compatFileNamesFrom(instructions?: {
31
+ compatClaude?: boolean;
32
+ compatCodex?: boolean;
33
+ }): string[];
18
34
  export interface EngineConfig {
19
35
  llm: LLMConfig;
36
+ /**
37
+ * Cross-model runtime knobs (temperature/timeout/retryMaxAttempts/imageDetail).
38
+ * Stays stable across hot model switches — only `llm` rotates. When omitted,
39
+ * Engine reads settings.json (model.temperature, images.detail) on construction.
40
+ */
41
+ clientDefaults?: ClientDefaults;
20
42
  cwd?: string;
21
43
  maxTurns?: number;
22
44
  maxToolCallsPerTurn?: number;
@@ -26,6 +48,23 @@ export interface EngineConfig {
26
48
  disabledBuiltinTools?: string[];
27
49
  customSystemPrompt?: string;
28
50
  appendSystemPrompt?: string;
51
+ responseLanguage?: string;
52
+ userProfile?: string;
53
+ instructions?: {
54
+ compatClaude?: boolean;
55
+ compatCodex?: boolean;
56
+ };
57
+ /**
58
+ * Goal mode: when set, the engine registers a GoalStopHook on `on_stop`
59
+ * so the turn loop runs until the session model judges this goal met
60
+ * (bounded by maxStopBlocks + maxTurns). Orthogonal to permissionMode —
61
+ * the desktop UI defaults permission to bypass when a goal is set, but
62
+ * the engine treats the two independently.
63
+ *
64
+ * Accepts a raw string (objective only) or a full GoalConfig (objective +
65
+ * optional token/time budgets); the run boundary normalizes it once.
66
+ */
67
+ goal?: string | GoalConfig;
29
68
  sessionStorageDir?: string;
30
69
  maxContextTokens?: number;
31
70
  approvalBackend?: ApprovalBackend;
@@ -46,6 +85,11 @@ export interface EngineConfig {
46
85
  * Defaults to false.
47
86
  */
48
87
  headless?: boolean;
88
+ /**
89
+ * When true, treat like headless for InvestigationGuard soft-mode — a
90
+ * read-only session should never be hard-blocked for repeated reads.
91
+ */
92
+ readOnlySession?: boolean;
49
93
  /**
50
94
  * Sandbox configuration for shell-tool execution. When omitted, headless
51
95
  * runs default to "auto" (Seatbelt on macOS / bwrap on Linux when
@@ -61,6 +105,12 @@ export interface EngineConfig {
61
105
  * pool, the runtime check still blocks the call.
62
106
  */
63
107
  isSubAgent?: boolean;
108
+ /**
109
+ * Host/context that created this Engine's sessions — written to state.json's
110
+ * `origin` so the desktop disk-rebuild can filter the sidebar (desktop +
111
+ * automation shown; tui hidden). Sub-agents override to "subagent".
112
+ */
113
+ origin?: SessionOrigin;
64
114
  /**
65
115
  * Optional shared EngineRuntime providing pre-constructed shared resources
66
116
  * (modelPool, toolRegistry, etc.). When provided, Engine uses these instead
@@ -68,7 +118,18 @@ export interface EngineConfig {
68
118
  * work unchanged — T11 will migrate them.
69
119
  */
70
120
  runtime?: EngineRuntime;
121
+ /**
122
+ * Which disk config layers this Engine may read. Defaults to 'project' —
123
+ * the safe default: a library/SDK embedding never silently inherits the
124
+ * host user's personal ~/.code-shell config (keys, models, MCP, hooks); it
125
+ * only reads the project-level ${cwd}/.code-shell that travels with a repo.
126
+ * Host-terminal entrypoints (TUI/desktop/CLI) pass 'full' to restore the
127
+ * managed+user+project+local behavior. 'isolated' reads no disk at all.
128
+ * Subagents inherit the parent Engine's scope. See SettingsScope.
129
+ */
130
+ settingsScope?: SettingsScope;
71
131
  }
132
+ export { diskDefaultsFrom, type DiskDefaultPatch } from "../settings/disk-defaults.js";
72
133
  export interface EngineHookConfig {
73
134
  event: HookEventName;
74
135
  handler: HookHandler;
@@ -82,21 +143,88 @@ export interface EngineResult {
82
143
  turnCount: number;
83
144
  usage: TokenUsage;
84
145
  }
146
+ /**
147
+ * Resolve the LLM config for a spawned child Engine.
148
+ * - `modelKey` set + present in pool → that model's config (pure entry-derived
149
+ * identity; the parent's llm is NOT consulted).
150
+ * - otherwise (no key, no pool, or key miss) → the parent's llm unchanged.
151
+ * Key miss is a soft fallback, NOT an error: a stale agent definition must not
152
+ * crash the spawn.
153
+ *
154
+ * ClientDefaults (temperature/timeout/etc.) are inherited from the parent
155
+ * Engine directly via EngineConfig.clientDefaults — they do not flow through
156
+ * this helper because they're not part of LLMConfig anymore.
157
+ */
158
+ export declare function resolveChildLlm(modelKey: string | undefined, pool: ModelPool | undefined, parentLlm: LLMConfig): LLMConfig;
159
+ /**
160
+ * Load reusable sub-agent role definitions, merging:
161
+ * 1. project-level <cwd>/.code-shell/agents/*.md (ships built-ins)
162
+ * 2. user-level ~/.code-shell/agents/*.md (user wins on name)
163
+ * Names in `disabledAgents` are filtered out so the LLM never sees them.
164
+ */
165
+ export declare function loadAgentDefinitionsForCwd(cwd: string, disabledAgents?: string[], disabledPlugins?: string[]): AgentDefinitionRegistry;
166
+ /**
167
+ * #7: apply a project's per-turn builtin capability override to a tool list.
168
+ * A builtin marked `off` for the current cwd is HIDDEN from the turn's tool
169
+ * list (matching how skills/plugins/agents `off` apply mid-session). `on` /
170
+ * `inherit` / absent keep the tool — we can't re-add a tool the ctor-frozen
171
+ * registry omitted, but `on` for a tool already present is a no-op. Pure +
172
+ * exported so it's unit-testable without a full run() turn.
173
+ */
174
+ export declare function applyBuiltinOverrideVisibility<T extends {
175
+ name: string;
176
+ }>(tools: T[], override: Record<string, CapabilityOverride> | undefined): T[];
177
+ /**
178
+ * Compute a child Engine's tool scope.
179
+ * - `allowlist` set → child enabled = allowlist minus nested-agent tools
180
+ * (a per-role tool whitelist, e.g. a read-only researcher).
181
+ * - `allowlist` undefined → inherit parent enabled/disabled, always with the
182
+ * nested-agent tools forced into `disabled` (no grandchildren).
183
+ */
184
+ export declare function resolveChildToolScope(allowlist: string[] | undefined, parentDisabled: string[] | undefined, parentEnabled: string[] | undefined): {
185
+ enabled?: string[];
186
+ disabled: string[];
187
+ };
85
188
  export declare class Engine {
86
189
  private config;
87
- private readonly preset;
190
+ private preset;
88
191
  private toolRegistry;
89
192
  private hooks;
90
193
  private sessionManager;
91
194
  private mcpManager;
92
195
  private modelPool;
196
+ /**
197
+ * Handles for the settings-sourced hook handlers registered by
198
+ * registerSettingsHooks(), so reloadHooks() can unregister exactly those
199
+ * (and nothing else — plugin hooks, goal/builtin hooks are untouched) before
200
+ * re-registering from fresh settings. Without this, a reload would
201
+ * accumulate duplicate settings-hook handlers that all fire per event.
202
+ */
203
+ private settingsHookHandles;
204
+ /**
205
+ * Highest config-reload version applied so far. refreshRuntimeConfig drops
206
+ * any payload whose version is <= this, so out-of-order reload deliveries
207
+ * (multiple quick settings saves) can't let an older config clobber a newer
208
+ * one.
209
+ */
210
+ private lastAppliedConfigVersion;
211
+ /** Memoized sub-agent role registry, keyed by the cwd it was loaded from. */
212
+ private agentDefsCache?;
93
213
  /** Shared resources supplied at construction (adapter pattern — null when self-constructed). */
94
214
  readonly runtime: EngineRuntime | null;
215
+ private readonly sandboxCache;
95
216
  /** Active permission mode for this Engine instance. */
96
217
  permissionMode: NonNullable<EngineConfig["permissionMode"]>;
97
218
  /** True when permissionMode === "plan". */
98
219
  planMode: boolean;
99
220
  private settingsManager;
221
+ /**
222
+ * Cached auxiliary-task LLM client, keyed by the models[].key it was built
223
+ * from. Background calls (memory extraction, auto-dream) reuse it across
224
+ * runs so we don't redo the provider handshake every session. Invalidated
225
+ * implicitly: a changed auxModelKey produces a different cache key.
226
+ */
227
+ private auxClientCache?;
100
228
  private lastContextManager;
101
229
  private lastMessages;
102
230
  private lastSessionId;
@@ -136,6 +264,19 @@ export declare class Engine {
136
264
  * should register SDK-side handlers.
137
265
  */
138
266
  private registerSettingsHooks;
267
+ /**
268
+ * Re-apply settings.hooks onto the live HookRegistry after a settings
269
+ * change (config hot-reload layer 2). Surgical: removes ONLY the
270
+ * settings-sourced handlers this Engine previously registered (tracked in
271
+ * settingsHookHandles by identity) and re-runs registerSettingsHooks() from
272
+ * fresh disk settings. Plugin hooks (registered once at construction at
273
+ * priority 80) and goal/builtin/SDK-config hooks are never touched.
274
+ *
275
+ * The SettingsManager cache is invalidated first so the re-read reflects the
276
+ * latest settings.json on disk (mirrors freshSettings()'s load() semantics).
277
+ * Sub-agents never register settings hooks, so this is a no-op for them.
278
+ */
279
+ reloadHooks(): void;
139
280
  constructor(config: EngineConfig);
140
281
  /**
141
282
  * Load models[] / providers[] from settings into the active ModelPool and
@@ -160,13 +301,18 @@ export declare class Engine {
160
301
  * Register a custom tool (from product adapter) into the tool registry.
161
302
  * Must be called before run().
162
303
  */
163
- registerCustomTool(definition: import("../types.js").RegisteredTool, executor: (args: Record<string, unknown>) => Promise<string>): void;
304
+ registerCustomTool(definition: import("../types.js").RegisteredTool, executor: BuiltinToolFn): void;
164
305
  /**
165
306
  * Inject the askUser handler after construction. Used by AgentServer
166
307
  * to wire its protocol-backed askUser into an Engine that was created
167
308
  * before the server existed (chicken-and-egg: server takes engine in ctor).
168
309
  */
169
310
  setAskUser(fn: AskUserFn | undefined): void;
311
+ /**
312
+ * Whether this engine runs unattended (no interactive human). Used by the
313
+ * in-process AgentServer to decide whether to wire an interactive askUser.
314
+ */
315
+ isHeadless(): boolean;
170
316
  /**
171
317
  * Run a task from start to finish.
172
318
  */
@@ -175,12 +321,28 @@ export declare class Engine {
175
321
  onStream?: StreamCallback;
176
322
  signal?: AbortSignal;
177
323
  sessionId?: string;
324
+ /**
325
+ * Goal mode for this run: the engine registers a GoalStopHook so the
326
+ * turn loop runs until the session model judges this goal met. Falls
327
+ * back to config.goal. Orthogonal to permissionMode. Accepts a raw
328
+ * string or a full GoalConfig; normalized once at the run boundary.
329
+ */
330
+ goal?: string | GoalConfig;
178
331
  }): Promise<EngineResult>;
179
332
  /**
180
333
  * Run the end-of-session memory pipeline as a fire-and-forget background
181
334
  * task. Extracts durable memories from the transcript, saves a session
182
335
  * summary, and conditionally triggers auto-dream consolidation.
183
336
  */
337
+ /**
338
+ * Resolve the LLM client for background/auxiliary work (memory extraction,
339
+ * auto-dream). When settings.auxModelKey names a valid pool model, build (and
340
+ * cache) a dedicated client for it so per-turn book-keeping runs on a cheap
341
+ * fast model instead of the expensive primary. Falls back to `fallback` (the
342
+ * active run's client) when unset, unknown, or on any build failure — aux
343
+ * work is best-effort and must never break a run.
344
+ */
345
+ private resolveAuxClient;
184
346
  private runMemoryPipeline;
185
347
  /**
186
348
  * Drive the auto-dream tool-call loop.
@@ -199,14 +361,6 @@ export declare class Engine {
199
361
  * bailed before the first LLM call (e.g. registry missing the tools).
200
362
  */
201
363
  private runDreamLoop;
202
- /**
203
- * Execute one memory tool call inside the dream loop. Enforces the two
204
- * dream-loop invariants the prompt also states:
205
- * - Only the 4 memory tools are dispatchable.
206
- * - Save/Delete in "user" scope is refused (returned as a tool error)
207
- * because dream runs without an interactive permission backend.
208
- */
209
- private dispatchDreamTool;
210
364
  getToolRegistry(): ToolRegistry;
211
365
  /**
212
366
  * Switch the active model by pool key. Takes effect on the next run() call.
@@ -235,6 +389,44 @@ export declare class Engine {
235
389
  getHookRegistry(): HookRegistry;
236
390
  getSessionManager(): SessionManager;
237
391
  getConfig(): EngineConfig;
392
+ /**
393
+ * Config hot-reload "layer 2": merge a disk-default config patch into this
394
+ * ALREADY-RUNNING session's `this.config`, reload settings hooks, and
395
+ * incrementally connect any newly-added MCP servers. Applied at the next
396
+ * turn boundary — an in-flight turn is NOT interrupted: it keeps using the
397
+ * PromptComposer it was built with, and the next turn rebuilds the composer
398
+ * from the freshly-merged config (composer is rebuilt per-turn).
399
+ *
400
+ * `version` is a monotonic counter from the server: stale (<=last applied)
401
+ * payloads are dropped so out-of-order reload deliveries can't let an older
402
+ * config clobber a newer one (Q5).
403
+ *
404
+ * MCP: only connects (idempotent — already-connected servers are skipped);
405
+ * never disconnects, so an in-flight tool call on an existing server is
406
+ * never severed (Q3). Removed servers are deferred to the next session
407
+ * rebuild. If mcpManager isn't built yet (no MCP run has happened), the
408
+ * new servers will be connected on the next run via the existing per-run
409
+ * connectAll path — so we skip the connect here.
410
+ *
411
+ * Preset (#2): a preset hot-reload re-resolves `this.preset` so the next-turn
412
+ * PromptComposer picks up the new preset's system prompt / behavior — that's
413
+ * the main user-visible preset effect and it IS hot. The toolRegistry's
414
+ * builtin tool SET, however, is ctor-frozen (and may be shared via runtime):
415
+ * it is NOT rebuilt here. So a preset change that alters the builtin tool set
416
+ * (e.g. general → terminal-coding adds LSP/Brief) only takes effect on the
417
+ * next session restart; we log a warning when that case is detected.
418
+ *
419
+ * disk-default-vs-slice caveat (#8): the patch carries pure DISK-default
420
+ * values (preset/customSystemPrompt/appendSystemPrompt/responseLanguage/
421
+ * userProfile — see diskDefaultsFrom). Spreading them here OVERRIDES any
422
+ * per-request slice override of the same field. This is correct for the
423
+ * desktop host today (its per-request slice only carries permissionMode+cwd,
424
+ * which are excluded from the disk patch). A future host that sets
425
+ * slice.preset (or the other prompt fields) per-request MUST exclude those
426
+ * from the reload patch — or track per-request overrides separately — or this
427
+ * reload will clobber them back to disk values.
428
+ */
429
+ refreshRuntimeConfig(patch: Partial<EngineConfig>, version: number): void;
238
430
  /**
239
431
  * Inject context into a session's transcript without triggering a LLM turn.
240
432
  * The injected content appears as an assistant message so the LLM can see it
@@ -279,17 +471,65 @@ export declare class Engine {
279
471
  * Also syncs permissionMode to keep both fields consistent.
280
472
  */
281
473
  setPlanMode(value: boolean): void;
474
+ /**
475
+ * Block until a background agent's state changes (finishes / its result is
476
+ * enqueued) or `signal` aborts. Resolves `true` if aborted, `false` on a
477
+ * change. The caller re-checks `hasRunningForSession` after each wake, so a
478
+ * spurious wake (another session's agent) just loops again.
479
+ *
480
+ * Subscribes to BOTH the registry AND the notification queue — and that's
481
+ * load-bearing, not belt-and-suspenders. A completing agent calls
482
+ * `markCompleted` (registry notify) and only THEN `enqueue` (queue notify),
483
+ * as two separate statements. If we woke on the registry notify alone, the
484
+ * loop could re-check, see no running agents, and `drainAll` BEFORE the
485
+ * result was enqueued — silently losing the last agent's output. Waking on
486
+ * the queue notify guarantees the item is already in the bucket. But a
487
+ * *cancelled* agent marks-but-never-enqueues (by design), so we also need
488
+ * the registry notify or a final cancel would hang the wait forever. Hence
489
+ * both. Subscribe-before-await closes the check/wait race either way.
490
+ */
491
+ private waitForBackgroundAgentChange;
492
+ /**
493
+ * Sub-agent role registry for the given cwd, memoized per-cwd so the
494
+ * directory is read once rather than every turn. A new cwd (e.g. via
495
+ * run({ cwd })) reloads.
496
+ */
497
+ private getAgentDefinitions;
498
+ /**
499
+ * Read settings.disabledAgents, folded with the project's
500
+ * capabilityOverrides.agents overlay for `cwd`. Unlike disabledSkills,
501
+ * sub-agents do NOT skip this — a disabled role must stay invisible
502
+ * everywhere. The overlay lets a project force-enable a globally-disabled
503
+ * role or force-disable a globally-enabled one (tri-state); read UNMERGED
504
+ * (getForScope) so inherit survives. No cwd / no overlay → baseline
505
+ * unchanged. Mirrors readDisabledLists (skills/plugins).
506
+ */
507
+ private readDisabledAgents;
508
+ /**
509
+ * Read the project's capabilityOverrides.builtin bucket for `cwd`, read
510
+ * UNMERGED (getForScope) so tri-state inherit survives. Sub-agents skip the
511
+ * overlay (minimal surface, same as readDisabledLists) — their builtin lists
512
+ * are already narrowed by resolveChildToolScope. No cwd / error → undefined,
513
+ * so the caller's baseline builtin lists pass through unchanged.
514
+ */
515
+ private readBuiltinOverride;
282
516
  /**
283
517
  * Build a base ToolContext for this Engine. Used by run() (which then
284
518
  * overlays turn-specific fields like sandbox and subAgentSpawner) and
285
519
  * by tests that want a ToolContext without a full run() cycle.
286
520
  */
521
+ private resolveSandboxWithoutRuntime;
287
522
  buildToolContext(): ToolContext;
288
523
  /**
289
- * Read settings.disabledSkills. Sub-agents skip this for the same
290
- * reason they skip settings.hooks / plugin hooks (registerSettingsHooks
291
- * at ~line 237): they run with a minimal surface area. Defaults to []
292
- * so callers don't have to null-check.
524
+ * Read settings.disabledSkills + settings.disabledPlugins in a single
525
+ * pass. Sub-agents skip both for the same reason they skip
526
+ * settings.hooks / plugin hooks (registerSettingsHooks at ~line 237):
527
+ * they run with a minimal surface area. Defaults to [] for both
528
+ * fields so callers don't have to null-check.
529
+ *
530
+ * Combined read avoids drift if settings change between two separate
531
+ * reads — the prompt composer and the tool context will always see
532
+ * the same snapshot.
293
533
  */
294
- private readDisabledSkills;
534
+ private readDisabledLists;
295
535
  }