@cjhyy/code-shell-core 0.5.0-rc.1 → 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 (278) hide show
  1. package/dist/agent/agent-definition-registry.d.ts +18 -3
  2. package/dist/agent/agent-definition-registry.js +47 -18
  3. package/dist/agent/agent-definition.d.ts +17 -0
  4. package/dist/agent/agent-definition.js +22 -1
  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 +114 -19
  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 +208 -14
  68. package/dist/engine/engine.js +754 -169
  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 +31 -6
  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 +4 -0
  171. package/dist/prompt/composer.js +28 -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 +33 -0
  220. package/dist/settings/manager.js +94 -1
  221. package/dist/settings/personalization.d.ts +19 -0
  222. package/dist/settings/personalization.js +7 -0
  223. package/dist/settings/schema.d.ts +1142 -126
  224. package/dist/settings/schema.js +119 -10
  225. package/dist/tool-system/builtin/add-marketplace.d.ts +12 -0
  226. package/dist/tool-system/builtin/add-marketplace.js +76 -0
  227. package/dist/tool-system/builtin/agent-registry.d.ts +11 -0
  228. package/dist/tool-system/builtin/agent-registry.js +8 -4
  229. package/dist/tool-system/builtin/agent.d.ts +29 -10
  230. package/dist/tool-system/builtin/agent.js +108 -52
  231. package/dist/tool-system/builtin/apply-patch/index.js +22 -3
  232. package/dist/tool-system/builtin/arena.js +6 -7
  233. package/dist/tool-system/builtin/complete-goal.d.ts +25 -0
  234. package/dist/tool-system/builtin/complete-goal.js +45 -0
  235. package/dist/tool-system/builtin/cron.js +53 -9
  236. package/dist/tool-system/builtin/edit.d.ts +2 -1
  237. package/dist/tool-system/builtin/edit.js +6 -1
  238. package/dist/tool-system/builtin/generate-image.d.ts +25 -0
  239. package/dist/tool-system/builtin/generate-image.js +146 -0
  240. package/dist/tool-system/builtin/glob.js +7 -0
  241. package/dist/tool-system/builtin/grep.js +6 -0
  242. package/dist/tool-system/builtin/index.d.ts +18 -1
  243. package/dist/tool-system/builtin/index.js +62 -1
  244. package/dist/tool-system/builtin/notebook-edit.d.ts +2 -1
  245. package/dist/tool-system/builtin/notebook-edit.js +8 -1
  246. package/dist/tool-system/builtin/read.d.ts +2 -1
  247. package/dist/tool-system/builtin/read.js +9 -1
  248. package/dist/tool-system/builtin/sleep.js +9 -3
  249. package/dist/tool-system/builtin/task.js +4 -1
  250. package/dist/tool-system/builtin/update-automation-memory.d.ts +24 -0
  251. package/dist/tool-system/builtin/update-automation-memory.js +60 -0
  252. package/dist/tool-system/builtin/view-image.d.ts +18 -0
  253. package/dist/tool-system/builtin/view-image.js +96 -0
  254. package/dist/tool-system/builtin/web-search.d.ts +4 -1
  255. package/dist/tool-system/builtin/web-search.js +36 -3
  256. package/dist/tool-system/builtin/write.d.ts +2 -1
  257. package/dist/tool-system/builtin/write.js +7 -1
  258. package/dist/tool-system/context.d.ts +12 -0
  259. package/dist/tool-system/executor.d.ts +0 -1
  260. package/dist/tool-system/executor.js +34 -40
  261. package/dist/tool-system/investigation-guard.d.ts +4 -1
  262. package/dist/tool-system/investigation-guard.js +19 -3
  263. package/dist/tool-system/mcp-manager.d.ts +36 -12
  264. package/dist/tool-system/mcp-manager.js +173 -10
  265. package/dist/tool-system/path-policy.d.ts +94 -0
  266. package/dist/tool-system/path-policy.js +279 -0
  267. package/dist/tool-system/permission.js +43 -50
  268. package/dist/tool-system/plan-mode-allowlist.d.ts +21 -0
  269. package/dist/tool-system/plan-mode-allowlist.js +43 -0
  270. package/dist/tool-system/registry.js +12 -1
  271. package/dist/tool-system/validation.d.ts +10 -0
  272. package/dist/tool-system/validation.js +16 -3
  273. package/dist/types.d.ts +90 -15
  274. package/dist/utils/format.js +4 -2
  275. package/dist/utils/lockfile.js +9 -2
  276. package/dist/utils/theme.d.ts +6 -0
  277. package/dist/utils/theme.js +4 -2
  278. package/package.json +2 -1
@@ -1,24 +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";
13
15
  import { type SettingsScope } from "../settings/manager.js";
16
+ import type { CapabilityOverride } from "../settings/schema.js";
14
17
  import type { ToolContext } from "../tool-system/context.js";
15
18
  import { type SandboxConfig } from "../tool-system/sandbox/index.js";
16
19
  import { type AgentPresetName } from "../preset/index.js";
17
20
  import { ModelPool, type ModelEntry } from "../llm/model-pool.js";
18
21
  import { AgentDefinitionRegistry } from "../agent/agent-definition-registry.js";
19
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[];
20
34
  export interface EngineConfig {
21
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;
22
42
  cwd?: string;
23
43
  maxTurns?: number;
24
44
  maxToolCallsPerTurn?: number;
@@ -28,6 +48,23 @@ export interface EngineConfig {
28
48
  disabledBuiltinTools?: string[];
29
49
  customSystemPrompt?: string;
30
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;
31
68
  sessionStorageDir?: string;
32
69
  maxContextTokens?: number;
33
70
  approvalBackend?: ApprovalBackend;
@@ -48,6 +85,11 @@ export interface EngineConfig {
48
85
  * Defaults to false.
49
86
  */
50
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;
51
93
  /**
52
94
  * Sandbox configuration for shell-tool execution. When omitted, headless
53
95
  * runs default to "auto" (Seatbelt on macOS / bwrap on Linux when
@@ -63,6 +105,12 @@ export interface EngineConfig {
63
105
  * pool, the runtime check still blocks the call.
64
106
  */
65
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;
66
114
  /**
67
115
  * Optional shared EngineRuntime providing pre-constructed shared resources
68
116
  * (modelPool, toolRegistry, etc.). When provided, Engine uses these instead
@@ -81,6 +129,7 @@ export interface EngineConfig {
81
129
  */
82
130
  settingsScope?: SettingsScope;
83
131
  }
132
+ export { diskDefaultsFrom, type DiskDefaultPatch } from "../settings/disk-defaults.js";
84
133
  export interface EngineHookConfig {
85
134
  event: HookEventName;
86
135
  handler: HookHandler;
@@ -96,14 +145,35 @@ export interface EngineResult {
96
145
  }
97
146
  /**
98
147
  * Resolve the LLM config for a spawned child Engine.
99
- * - `modelKey` set + present in pool → that model's config (over parent base).
148
+ * - `modelKey` set + present in pool → that model's config (pure entry-derived
149
+ * identity; the parent's llm is NOT consulted).
100
150
  * - otherwise (no key, no pool, or key miss) → the parent's llm unchanged.
101
151
  * Key miss is a soft fallback, NOT an error: a stale agent definition must not
102
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.
103
157
  */
104
158
  export declare function resolveChildLlm(modelKey: string | undefined, pool: ModelPool | undefined, parentLlm: LLMConfig): LLMConfig;
105
- /** Load reusable sub-agent role definitions from <cwd>/.code-shell/agents. */
106
- export declare function loadAgentDefinitionsForCwd(cwd: string): AgentDefinitionRegistry;
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[];
107
177
  /**
108
178
  * Compute a child Engine's tool scope.
109
179
  * - `allowlist` set → child enabled = allowlist minus nested-agent tools
@@ -117,21 +187,44 @@ export declare function resolveChildToolScope(allowlist: string[] | undefined, p
117
187
  };
118
188
  export declare class Engine {
119
189
  private config;
120
- private readonly preset;
190
+ private preset;
121
191
  private toolRegistry;
122
192
  private hooks;
123
193
  private sessionManager;
124
194
  private mcpManager;
125
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;
126
211
  /** Memoized sub-agent role registry, keyed by the cwd it was loaded from. */
127
212
  private agentDefsCache?;
128
213
  /** Shared resources supplied at construction (adapter pattern — null when self-constructed). */
129
214
  readonly runtime: EngineRuntime | null;
215
+ private readonly sandboxCache;
130
216
  /** Active permission mode for this Engine instance. */
131
217
  permissionMode: NonNullable<EngineConfig["permissionMode"]>;
132
218
  /** True when permissionMode === "plan". */
133
219
  planMode: boolean;
134
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?;
135
228
  private lastContextManager;
136
229
  private lastMessages;
137
230
  private lastSessionId;
@@ -171,6 +264,19 @@ export declare class Engine {
171
264
  * should register SDK-side handlers.
172
265
  */
173
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;
174
280
  constructor(config: EngineConfig);
175
281
  /**
176
282
  * Load models[] / providers[] from settings into the active ModelPool and
@@ -195,13 +301,18 @@ export declare class Engine {
195
301
  * Register a custom tool (from product adapter) into the tool registry.
196
302
  * Must be called before run().
197
303
  */
198
- registerCustomTool(definition: import("../types.js").RegisteredTool, executor: (args: Record<string, unknown>) => Promise<string>): void;
304
+ registerCustomTool(definition: import("../types.js").RegisteredTool, executor: BuiltinToolFn): void;
199
305
  /**
200
306
  * Inject the askUser handler after construction. Used by AgentServer
201
307
  * to wire its protocol-backed askUser into an Engine that was created
202
308
  * before the server existed (chicken-and-egg: server takes engine in ctor).
203
309
  */
204
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;
205
316
  /**
206
317
  * Run a task from start to finish.
207
318
  */
@@ -210,12 +321,28 @@ export declare class Engine {
210
321
  onStream?: StreamCallback;
211
322
  signal?: AbortSignal;
212
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;
213
331
  }): Promise<EngineResult>;
214
332
  /**
215
333
  * Run the end-of-session memory pipeline as a fire-and-forget background
216
334
  * task. Extracts durable memories from the transcript, saves a session
217
335
  * summary, and conditionally triggers auto-dream consolidation.
218
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;
219
346
  private runMemoryPipeline;
220
347
  /**
221
348
  * Drive the auto-dream tool-call loop.
@@ -234,14 +361,6 @@ export declare class Engine {
234
361
  * bailed before the first LLM call (e.g. registry missing the tools).
235
362
  */
236
363
  private runDreamLoop;
237
- /**
238
- * Execute one memory tool call inside the dream loop. Enforces the two
239
- * dream-loop invariants the prompt also states:
240
- * - Only the 4 memory tools are dispatchable.
241
- * - Save/Delete in "user" scope is refused (returned as a tool error)
242
- * because dream runs without an interactive permission backend.
243
- */
244
- private dispatchDreamTool;
245
364
  getToolRegistry(): ToolRegistry;
246
365
  /**
247
366
  * Switch the active model by pool key. Takes effect on the next run() call.
@@ -270,6 +389,44 @@ export declare class Engine {
270
389
  getHookRegistry(): HookRegistry;
271
390
  getSessionManager(): SessionManager;
272
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;
273
430
  /**
274
431
  * Inject context into a session's transcript without triggering a LLM turn.
275
432
  * The injected content appears as an assistant message so the LLM can see it
@@ -314,17 +471,54 @@ export declare class Engine {
314
471
  * Also syncs permissionMode to keep both fields consistent.
315
472
  */
316
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;
317
492
  /**
318
493
  * Sub-agent role registry for the given cwd, memoized per-cwd so the
319
494
  * directory is read once rather than every turn. A new cwd (e.g. via
320
495
  * run({ cwd })) reloads.
321
496
  */
322
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;
323
516
  /**
324
517
  * Build a base ToolContext for this Engine. Used by run() (which then
325
518
  * overlays turn-specific fields like sandbox and subAgentSpawner) and
326
519
  * by tests that want a ToolContext without a full run() cycle.
327
520
  */
521
+ private resolveSandboxWithoutRuntime;
328
522
  buildToolContext(): ToolContext;
329
523
  /**
330
524
  * Read settings.disabledSkills + settings.disabledPlugins in a single