strands-darwin 0.0.35 → 0.0.36

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 (231) hide show
  1. package/README.md +20 -3
  2. package/README.zh-CN.md +20 -3
  3. package/dist/src/agent/prompt-cache.js +15 -2
  4. package/dist/src/agent/prompt-cache.js.map +1 -1
  5. package/dist/src/agent/rewind.d.ts +2 -0
  6. package/dist/src/agent/rewind.js +4 -1
  7. package/dist/src/agent/rewind.js.map +1 -1
  8. package/dist/src/agent/runtime.d.ts +64 -10
  9. package/dist/src/agent/runtime.js +192 -33
  10. package/dist/src/agent/runtime.js.map +1 -1
  11. package/dist/src/agent/session.d.ts +96 -4
  12. package/dist/src/agent/session.js +249 -9
  13. package/dist/src/agent/session.js.map +1 -1
  14. package/dist/src/agent/stream-idle.d.ts +16 -0
  15. package/dist/src/agent/stream-idle.js +127 -0
  16. package/dist/src/agent/stream-idle.js.map +1 -0
  17. package/dist/src/agent/working-context.d.ts +21 -1
  18. package/dist/src/agent/working-context.js +28 -1
  19. package/dist/src/agent/working-context.js.map +1 -1
  20. package/dist/src/agent/workspace-trust.d.ts +112 -0
  21. package/dist/src/agent/workspace-trust.js +207 -0
  22. package/dist/src/agent/workspace-trust.js.map +1 -0
  23. package/dist/src/agentcore/auto-policy.d.ts +7 -0
  24. package/dist/src/agentcore/auto-policy.js +50 -0
  25. package/dist/src/agentcore/auto-policy.js.map +1 -0
  26. package/dist/src/agentcore/auto-state.d.ts +43 -0
  27. package/dist/src/agentcore/auto-state.js +73 -0
  28. package/dist/src/agentcore/auto-state.js.map +1 -0
  29. package/dist/src/agentcore/cli.d.ts +2 -0
  30. package/dist/src/agentcore/cli.js +38 -0
  31. package/dist/src/agentcore/cli.js.map +1 -0
  32. package/dist/src/agentcore/config.d.ts +48 -0
  33. package/dist/src/agentcore/config.js +44 -0
  34. package/dist/src/agentcore/config.js.map +1 -0
  35. package/dist/src/agentcore/controller.d.ts +105 -0
  36. package/dist/src/agentcore/controller.js +979 -0
  37. package/dist/src/agentcore/controller.js.map +1 -0
  38. package/dist/src/agentcore/projection.d.ts +2 -0
  39. package/dist/src/agentcore/projection.js +8 -0
  40. package/dist/src/agentcore/projection.js.map +1 -0
  41. package/dist/src/agentcore/records.d.ts +41 -0
  42. package/dist/src/agentcore/records.js +149 -0
  43. package/dist/src/agentcore/records.js.map +1 -0
  44. package/dist/src/agentcore/state.d.ts +16 -0
  45. package/dist/src/agentcore/state.js +149 -0
  46. package/dist/src/agentcore/state.js.map +1 -0
  47. package/dist/src/agentcore/tools.d.ts +3 -0
  48. package/dist/src/agentcore/tools.js +11 -0
  49. package/dist/src/agentcore/tools.js.map +1 -0
  50. package/dist/src/agentcore/transport.d.ts +37 -0
  51. package/dist/src/agentcore/transport.js +242 -0
  52. package/dist/src/agentcore/transport.js.map +1 -0
  53. package/dist/src/agentcore/upload-projection.d.ts +208 -0
  54. package/dist/src/agentcore/upload-projection.js +823 -0
  55. package/dist/src/agentcore/upload-projection.js.map +1 -0
  56. package/dist/src/agents/child-recipe.js +4 -1
  57. package/dist/src/agents/child-recipe.js.map +1 -1
  58. package/dist/src/agents/loader.d.ts +12 -0
  59. package/dist/src/agents/loader.js +15 -1
  60. package/dist/src/agents/loader.js.map +1 -1
  61. package/dist/src/agents/subagent-tool.js +2 -4
  62. package/dist/src/agents/subagent-tool.js.map +1 -1
  63. package/dist/src/agents/workflow-tool.js +2 -4
  64. package/dist/src/agents/workflow-tool.js.map +1 -1
  65. package/dist/src/cli-doctor.js +7 -0
  66. package/dist/src/cli-doctor.js.map +1 -1
  67. package/dist/src/cli-import.d.ts +1 -0
  68. package/dist/src/cli-import.js +26 -0
  69. package/dist/src/cli-import.js.map +1 -0
  70. package/dist/src/cli-main.js +60 -10
  71. package/dist/src/cli-main.js.map +1 -1
  72. package/dist/src/cli-permissions.d.ts +2 -0
  73. package/dist/src/cli-permissions.js +20 -0
  74. package/dist/src/cli-permissions.js.map +1 -0
  75. package/dist/src/cli-sessions.js +6 -2
  76. package/dist/src/cli-sessions.js.map +1 -1
  77. package/dist/src/cli-usage.d.ts +9 -1
  78. package/dist/src/cli-usage.js +13 -0
  79. package/dist/src/cli-usage.js.map +1 -1
  80. package/dist/src/cli.js +19 -2
  81. package/dist/src/cli.js.map +1 -1
  82. package/dist/src/commands/custom-commands.d.ts +1 -1
  83. package/dist/src/commands/custom-commands.js +14 -6
  84. package/dist/src/commands/custom-commands.js.map +1 -1
  85. package/dist/src/commands/review-command.d.ts +10 -0
  86. package/dist/src/commands/review-command.js +28 -0
  87. package/dist/src/commands/review-command.js.map +1 -0
  88. package/dist/src/config-file.d.ts +9 -0
  89. package/dist/src/config-file.js +82 -0
  90. package/dist/src/config-file.js.map +1 -0
  91. package/dist/src/config.d.ts +66 -5
  92. package/dist/src/config.js +126 -42
  93. package/dist/src/config.js.map +1 -1
  94. package/dist/src/dev-repl.js +17 -1
  95. package/dist/src/dev-repl.js.map +1 -1
  96. package/dist/src/headless-protocol.d.ts +24 -1
  97. package/dist/src/headless-protocol.js +18 -0
  98. package/dist/src/headless-protocol.js.map +1 -1
  99. package/dist/src/headless-runner.d.ts +8 -0
  100. package/dist/src/headless-runner.js +37 -1
  101. package/dist/src/headless-runner.js.map +1 -1
  102. package/dist/src/hooks/hook-process.js +7 -2
  103. package/dist/src/hooks/hook-process.js.map +1 -1
  104. package/dist/src/hooks/lifecycle-hooks.js +3 -1
  105. package/dist/src/hooks/lifecycle-hooks.js.map +1 -1
  106. package/dist/src/hooks/tool-hooks.js +3 -1
  107. package/dist/src/hooks/tool-hooks.js.map +1 -1
  108. package/dist/src/import-claude-files.d.ts +28 -0
  109. package/dist/src/import-claude-files.js +227 -0
  110. package/dist/src/import-claude-files.js.map +1 -0
  111. package/dist/src/import-claude-snippets.d.ts +2 -0
  112. package/dist/src/import-claude-snippets.js +105 -0
  113. package/dist/src/import-claude-snippets.js.map +1 -0
  114. package/dist/src/import-claude.d.ts +13 -0
  115. package/dist/src/import-claude.js +287 -0
  116. package/dist/src/import-claude.js.map +1 -0
  117. package/dist/src/mcp/registry.d.ts +57 -1
  118. package/dist/src/mcp/registry.js +78 -6
  119. package/dist/src/mcp/registry.js.map +1 -1
  120. package/dist/src/memory/command.d.ts +1 -1
  121. package/dist/src/memory/command.js +89 -4
  122. package/dist/src/memory/command.js.map +1 -1
  123. package/dist/src/memory/controller.d.ts +32 -0
  124. package/dist/src/memory/controller.js +39 -3
  125. package/dist/src/memory/controller.js.map +1 -1
  126. package/dist/src/memory/state.d.ts +6 -0
  127. package/dist/src/memory/state.js +6 -1
  128. package/dist/src/memory/state.js.map +1 -1
  129. package/dist/src/memory/store.d.ts +13 -0
  130. package/dist/src/memory/store.js +38 -2
  131. package/dist/src/memory/store.js.map +1 -1
  132. package/dist/src/memory/tools.d.ts +7 -0
  133. package/dist/src/memory/tools.js +12 -1
  134. package/dist/src/memory/tools.js.map +1 -1
  135. package/dist/src/paths.js +3 -0
  136. package/dist/src/paths.js.map +1 -1
  137. package/dist/src/permissions-test.d.ts +18 -0
  138. package/dist/src/permissions-test.js +207 -0
  139. package/dist/src/permissions-test.js.map +1 -0
  140. package/dist/src/pricing/model-prices.d.ts +8 -5
  141. package/dist/src/pricing/model-prices.js +30 -15
  142. package/dist/src/pricing/model-prices.js.map +1 -1
  143. package/dist/src/project-identity.d.ts +3 -0
  144. package/dist/src/project-identity.js +8 -0
  145. package/dist/src/project-identity.js.map +1 -0
  146. package/dist/src/project-overrides.d.ts +57 -0
  147. package/dist/src/project-overrides.js +79 -0
  148. package/dist/src/project-overrides.js.map +1 -0
  149. package/dist/src/skills/builtin/setup-agentcore-memory/SKILL.md +158 -0
  150. package/dist/src/skills/loader.d.ts +1 -1
  151. package/dist/src/skills/loader.js +4 -1
  152. package/dist/src/skills/loader.js.map +1 -1
  153. package/dist/src/tools/background-bash.d.ts +6 -0
  154. package/dist/src/tools/background-bash.js +26 -0
  155. package/dist/src/tools/background-bash.js.map +1 -1
  156. package/dist/src/tools/shell-env.d.ts +24 -0
  157. package/dist/src/tools/shell-env.js +34 -0
  158. package/dist/src/tools/shell-env.js.map +1 -1
  159. package/dist/src/trajectory/reader.d.ts +1 -1
  160. package/dist/src/trajectory/reader.js +23 -3
  161. package/dist/src/trajectory/reader.js.map +1 -1
  162. package/dist/src/trajectory/resume-recap.d.ts +11 -1
  163. package/dist/src/trajectory/resume-recap.js +10 -1
  164. package/dist/src/trajectory/resume-recap.js.map +1 -1
  165. package/dist/src/trajectory/rewind-history.d.ts +8 -0
  166. package/dist/src/trajectory/rewind-history.js +81 -0
  167. package/dist/src/trajectory/rewind-history.js.map +1 -0
  168. package/dist/src/tui/App.d.ts +5 -1
  169. package/dist/src/tui/App.js +284 -51
  170. package/dist/src/tui/App.js.map +1 -1
  171. package/dist/src/tui/InputBox.d.ts +1 -1
  172. package/dist/src/tui/InputBox.js +1 -1
  173. package/dist/src/tui/MessageList.js +1 -1
  174. package/dist/src/tui/MessageList.js.map +1 -1
  175. package/dist/src/tui/PermissionPrompt.js +5 -3
  176. package/dist/src/tui/PermissionPrompt.js.map +1 -1
  177. package/dist/src/tui/QueuedMessages.js +14 -8
  178. package/dist/src/tui/QueuedMessages.js.map +1 -1
  179. package/dist/src/tui/ToolCallPanel.js +2 -2
  180. package/dist/src/tui/ToolCallPanel.js.map +1 -1
  181. package/dist/src/tui/WorkspaceTrustPrompt.d.ts +8 -0
  182. package/dist/src/tui/WorkspaceTrustPrompt.js +37 -0
  183. package/dist/src/tui/WorkspaceTrustPrompt.js.map +1 -0
  184. package/dist/src/tui/draft-stash.d.ts +25 -0
  185. package/dist/src/tui/draft-stash.js +49 -0
  186. package/dist/src/tui/draft-stash.js.map +1 -0
  187. package/dist/src/tui/frame-budget.d.ts +2 -2
  188. package/dist/src/tui/frame-budget.js +3 -3
  189. package/dist/src/tui/frame-budget.js.map +1 -1
  190. package/dist/src/tui/help-format.d.ts +2 -2
  191. package/dist/src/tui/help-format.js +3 -3
  192. package/dist/src/tui/help-format.js.map +1 -1
  193. package/dist/src/tui/mcp-format.d.ts +9 -0
  194. package/dist/src/tui/mcp-format.js +5 -3
  195. package/dist/src/tui/mcp-format.js.map +1 -1
  196. package/dist/src/tui/permission-rule-preview.d.ts +23 -0
  197. package/dist/src/tui/permission-rule-preview.js +38 -0
  198. package/dist/src/tui/permission-rule-preview.js.map +1 -0
  199. package/dist/src/tui/prompt-editor.d.ts +12 -0
  200. package/dist/src/tui/prompt-editor.js +38 -28
  201. package/dist/src/tui/prompt-editor.js.map +1 -1
  202. package/dist/src/tui/prompt-history-search.js +3 -2
  203. package/dist/src/tui/prompt-history-search.js.map +1 -1
  204. package/dist/src/tui/prompt-queue.d.ts +4 -2
  205. package/dist/src/tui/prompt-queue.js +18 -3
  206. package/dist/src/tui/prompt-queue.js.map +1 -1
  207. package/dist/src/tui/rewind-search.js +4 -3
  208. package/dist/src/tui/rewind-search.js.map +1 -1
  209. package/dist/src/tui/search-preview.d.ts +2 -0
  210. package/dist/src/tui/search-preview.js +9 -0
  211. package/dist/src/tui/search-preview.js.map +1 -0
  212. package/dist/src/tui/shell-command.js +4 -1
  213. package/dist/src/tui/shell-command.js.map +1 -1
  214. package/dist/src/tui/spinner.d.ts +1 -0
  215. package/dist/src/tui/spinner.js +6 -0
  216. package/dist/src/tui/spinner.js.map +1 -0
  217. package/dist/src/tui/status-format.d.ts +9 -0
  218. package/dist/src/tui/status-format.js +37 -2
  219. package/dist/src/tui/status-format.js.map +1 -1
  220. package/dist/src/tui/subagent-format.js +6 -0
  221. package/dist/src/tui/subagent-format.js.map +1 -1
  222. package/dist/src/tui/task-format.d.ts +5 -0
  223. package/dist/src/tui/task-format.js +15 -0
  224. package/dist/src/tui/task-format.js.map +1 -1
  225. package/dist/src/tui/trust-format.d.ts +31 -0
  226. package/dist/src/tui/trust-format.js +102 -0
  227. package/dist/src/tui/trust-format.js.map +1 -0
  228. package/dist/src/tui/turn-state.d.ts +1 -0
  229. package/dist/src/tui/turn-state.js +2 -0
  230. package/dist/src/tui/turn-state.js.map +1 -1
  231. package/package.json +2 -1
@@ -4,6 +4,8 @@ import { type PromptCacheTtl } from './agent/prompt-cache.js';
4
4
  import { type ThinkingEffort, type ThinkingPlan } from './agent/thinking.js';
5
5
  import { type CodexHooksConfig } from './hooks/codex-hooks.js';
6
6
  import type { ToolHooksConfig } from './hooks/tool-hooks.js';
7
+ import { type AgentCoreConfig } from './agentcore/config.js';
8
+ import { type ProjectOverrides } from './project-overrides.js';
7
9
  /** Raised for malformed or unusable configuration. Always carries a fix hint. */
8
10
  export declare class ConfigError extends Error {
9
11
  constructor(message: string);
@@ -175,6 +177,8 @@ export interface SessionFields {
175
177
  * Set to 0 to disable. Default: 0.8.
176
178
  */
177
179
  contextWarnRatio: number;
180
+ /** Parent model-stream inactivity in seconds; 0 disables. Default: 120. */
181
+ streamIdleTimeoutSeconds?: number;
178
182
  /**
179
183
  * Offload oversized tool results to session-scoped storage, keeping a preview
180
184
  * plus a reference in context. On by default; explicit `false` opts out.
@@ -303,6 +307,9 @@ export interface SessionFields {
303
307
  * disable age expiry; current-source validation still applies.
304
308
  */
305
309
  memoryHorizonDays?: number;
310
+ /** Optional cloud memory; independent of model provider and local project memory. */
311
+ agentCoreMemory?: AgentCoreConfig;
312
+ projectOverrides?: ProjectOverrides;
306
313
  /**
307
314
  * Ceiling on concurrently running child dispatches (`subagent` calls plus
308
315
  * `workflow` nodes, counted on the one dispatch registry). A call that would
@@ -346,7 +353,7 @@ export declare const MODEL_KEYS: readonly ['provider', 'name', 'model', 'region'
346
353
  * that silently applied to one model and not another would be a security
347
354
  * surprise, which is why an entry carrying one is rejected rather than ignored.
348
355
  */
349
- export declare const SESSION_KEYS: readonly ['permissionMode', 'hooks', 'summaryRatio', 'preserveRecentMessages', 'contextWarnRatio', 'contextOffload', 'maxResultTokens', 'terminalBell', 'terminalNotify', 'terminalTitle', 'backgroundTaskWake', 'shellEnv', 'trajectory', 'diagnostics', 'memory', 'memoryHorizonDays', 'maxConcurrentSubagents', 'systemPrompt'];
356
+ export declare const SESSION_KEYS: readonly ['permissionMode', 'hooks', 'summaryRatio', 'preserveRecentMessages', 'contextWarnRatio', 'streamIdleTimeoutSeconds', 'contextOffload', 'maxResultTokens', 'terminalBell', 'terminalNotify', 'terminalTitle', 'backgroundTaskWake', 'shellEnv', 'trajectory', 'diagnostics', 'memory', 'memoryHorizonDays', 'agentCoreMemory', 'projectOverrides', 'maxConcurrentSubagents', 'systemPrompt'];
350
357
  /**
351
358
  * `~/.darwin/config.json`, derived and nothing else: no directory is created.
352
359
  *
@@ -472,10 +479,64 @@ export interface ProjectPolicy {
472
479
  hookShadowNotices: HookShadowNotice[];
473
480
  legacyRules: boolean;
474
481
  }
482
+ /**
483
+ * Which repository-supplied layers {@link loadProjectPolicy} arms (SER-090).
484
+ *
485
+ * `armed` (the default, and what every caller before workspace trust got) reads the
486
+ * project hook roots and the legacy `.darwin/config.json` `permissionRules`
487
+ * fallback. `held` skips exactly those — the user-owned global hook roots and the
488
+ * user-owned `permission-rules.json` still load — without reading or validating the
489
+ * skipped files, so an untrusted checkout can neither run a hook command nor fail
490
+ * startup with a malformed one. Nothing is an error here: holding a layer back is a
491
+ * decision the user made, stated by the drivers, not a failure.
492
+ */
493
+ export interface ProjectPolicyOptions {
494
+ projectLayers?: 'armed' | 'held';
495
+ }
475
496
  /** Loads project-scoped rules and all executable hook extension layers. */
476
- export declare function loadProjectPolicy(projectRoot: string): Promise<ProjectPolicy>;
477
- /** Adds one project-scoped allow rule, promoting legacy rules on first write. */
478
- export declare function appendAllowRule(projectRoot: string, rule: string): Promise<void>;
497
+ export declare function loadProjectPolicy(projectRoot: string, options?: ProjectPolicyOptions): Promise<ProjectPolicy>;
498
+ /** One repository-supplied hook source as the workspace-trust inventory lists it (SER-090). */
499
+ export interface ProjectHookSourceInventory {
500
+ file: string;
501
+ dialect: 'native' | 'codex';
502
+ /** Command hooks per event, in the file's own dialect vocabulary; events with none are absent. */
503
+ eventCounts: Record<string, number>;
504
+ }
505
+ /**
506
+ * What a checkout's `.darwin`/`.agents` roots would arm if the project were trusted
507
+ * (SER-090): the same `loadHookLayer` parse `loadProjectPolicy` activates from, over
508
+ * the *project* roots only, with nothing activated — no runner is built and no
509
+ * command runs. One grammar: a file this lists is exactly a file the policy would
510
+ * load, and a file the policy rejects is listed under `problems` with the loader's own
511
+ * message, because a checkout that carries an unparseable hook file still carries
512
+ * executable configuration the user should see before trusting it. The legacy
513
+ * `.darwin/config.json` rule fallback is inventoried only when it would be *in force*
514
+ * — the user-owned `permission-rules.json` makes it inert, and an inert layer grants
515
+ * nothing to consent to.
516
+ */
517
+ export interface ProjectPolicyInventory {
518
+ hookSources: ProjectHookSourceInventory[];
519
+ /** Project hook layers the loader refused, by root: still repository-supplied, stated as unreadable. */
520
+ problems: {
521
+ file: string;
522
+ problem: string;
523
+ }[];
524
+ legacyRules: {
525
+ file: string;
526
+ allow: number;
527
+ deny: number;
528
+ } | undefined;
529
+ }
530
+ export declare function inventoryProjectPolicy(projectRoot: string): Promise<ProjectPolicyInventory>;
531
+ /**
532
+ * Adds one project-scoped allow rule, promoting legacy rules on first write.
533
+ *
534
+ * `options.projectLayers: 'held'` (SER-090) keeps the promotion from ever copying a
535
+ * *committed* `.darwin/config.json` rule set into the user-owned file: in an untrusted
536
+ * project the legacy fallback was never in force, so the first write starts from the
537
+ * empty list — exactly what the gate was honouring.
538
+ */
539
+ export declare function appendAllowRule(projectRoot: string, rule: string, options?: ProjectPolicyOptions): Promise<void>;
479
540
  /**
480
541
  * Persists a revocation: removes the given rules from the project-scoped file,
481
542
  * promoting legacy rules on first write exactly like {@link appendAllowRule}.
@@ -486,7 +547,7 @@ export declare function appendAllowRule(projectRoot: string, rule: string): Prom
486
547
  * prompt, never a silent widening. Deny-rules (SER-076) pass through untouched:
487
548
  * this writer never sees them as a target.
488
549
  */
489
- export declare function removeAllowRules(projectRoot: string, rules: readonly string[]): Promise<void>;
550
+ export declare function removeAllowRules(projectRoot: string, rules: readonly string[], options?: ProjectPolicyOptions): Promise<void>;
490
551
  /**
491
552
  * Persists `thinkingEffort` in `~/.darwin/config.json`, so a level chosen with
492
553
  * `/effort` is still in effect next session.
@@ -7,6 +7,7 @@
7
7
  import { lstat, mkdir, readFile, readdir, realpath, writeFile } from 'node:fs/promises';
8
8
  import { mkdirSync } from 'node:fs';
9
9
  import path from 'node:path';
10
+ import { DEFAULT_STREAM_IDLE_TIMEOUT_SECONDS, MAX_STREAM_IDLE_TIMEOUT_SECONDS, modelStreamMiddleware } from './agent/stream-idle.js';
10
11
  import { BedrockModel } from '@strands-agents/sdk';
11
12
  import { isValidRule } from './agent/permission-rules.js';
12
13
  import { APPROVAL_MODES, isApprovalMode } from './agent/permission.js';
@@ -15,6 +16,9 @@ import { claudeThinkingFields, DEFAULT_THINKING_EFFORT, isThinkingEffort, openai
15
16
  import { decodeCodexHooks, CODEX_HOOK_EVENTS } from './hooks/codex-hooks.js';
16
17
  import { darwinDir, hookExtensionRoots, userDarwinDir, userProjectDir } from './paths.js';
17
18
  import { passthroughEntryProblem } from './tools/shell-env.js';
19
+ import { parseAgentCoreConfig } from './agentcore/config.js';
20
+ import { readConfigBytes, updateConfigFile } from './config-file.js';
21
+ import { effectiveCloudPolicy, parseProjectOverrides } from './project-overrides.js';
18
22
  /** Raised for malformed or unusable configuration. Always carries a fix hint. */
19
23
  export class ConfigError extends Error {
20
24
  constructor(message) {
@@ -70,6 +74,7 @@ export const SESSION_KEYS = [
70
74
  'summaryRatio',
71
75
  'preserveRecentMessages',
72
76
  'contextWarnRatio',
77
+ 'streamIdleTimeoutSeconds',
73
78
  'contextOffload',
74
79
  'maxResultTokens',
75
80
  'terminalBell',
@@ -81,6 +86,8 @@ export const SESSION_KEYS = [
81
86
  'diagnostics',
82
87
  'memory',
83
88
  'memoryHorizonDays',
89
+ 'agentCoreMemory',
90
+ 'projectOverrides',
84
91
  'maxConcurrentSubagents',
85
92
  'systemPrompt',
86
93
  ];
@@ -356,8 +363,8 @@ export function withModelChoice(config, target) {
356
363
  return {
357
364
  // Safe: SESSION_KEYS are exactly the keys of SessionFields, and the required
358
365
  // ones are always present on a validated AppConfig.
359
- ...session,
360
366
  ...target.fields,
367
+ ...session,
361
368
  modelChoices: config.modelChoices.map((choice) => ({ ...choice, enabled: choice.index === target.index })),
362
369
  };
363
370
  }
@@ -372,7 +379,10 @@ export async function loadConfig(projectRoot) {
372
379
  const file = configFilePath();
373
380
  let raw;
374
381
  try {
375
- raw = await readFile(file, 'utf8');
382
+ const bytes = await readConfigBytes(file);
383
+ if (bytes === undefined)
384
+ return defaultConfig();
385
+ raw = bytes;
376
386
  }
377
387
  catch (error) {
378
388
  if (isFileNotFound(error))
@@ -394,7 +404,13 @@ export async function loadConfig(projectRoot) {
394
404
  `Move them to ${permissionRulesPath(projectRoot)}.`);
395
405
  }
396
406
  const embeddedHooksActive = !(await pathExists(globalHooksPath())) && !(await hookDirectoryHasJson(userDarwinDir()));
397
- return validate(parsed, file, embeddedHooksActive);
407
+ const config = validate(parsed, file, embeddedHooksActive);
408
+ const cloud = effectiveCloudPolicy(config.agentCoreMemory, config.projectOverrides, projectRoot);
409
+ if (cloud !== undefined)
410
+ config.agentCoreMemory = cloud;
411
+ if (config.agentCoreMemory?.upload !== undefined && config.agentCoreMemory.upload !== 'off' && config.trajectory === false)
412
+ throw new ConfigError('agentCoreMemory uploads require trajectory recording.');
413
+ return config;
398
414
  }
399
415
  function validate(parsed, configPath, validateEmbeddedHooks = true) {
400
416
  if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
@@ -755,6 +771,8 @@ function validateSessionFields(input, configPath, validateEmbeddedHooks) {
755
771
  DEFAULTS.preserveRecentMessages,
756
772
  contextWarnRatio: numberField(input, 'contextWarnRatio', configPath, { min: 0, max: 1 }) ??
757
773
  DEFAULTS.contextWarnRatio,
774
+ streamIdleTimeoutSeconds: numberField(input, 'streamIdleTimeoutSeconds', configPath, { min: 0, max: MAX_STREAM_IDLE_TIMEOUT_SECONDS }) ??
775
+ DEFAULT_STREAM_IDLE_TIMEOUT_SECONDS,
758
776
  contextOffload: booleanField(input, 'contextOffload', configPath) ?? DEFAULTS.contextOffload,
759
777
  terminalBell: booleanField(input, 'terminalBell', configPath) ?? DEFAULTS.terminalBell,
760
778
  terminalNotify: booleanField(input, 'terminalNotify', configPath) ?? DEFAULTS.terminalNotify,
@@ -773,6 +791,17 @@ function validateSessionFields(input, configPath, validateEmbeddedHooks) {
773
791
  const trajectory = booleanField(input, 'trajectory', configPath);
774
792
  if (trajectory !== undefined)
775
793
  fields.trajectory = trajectory;
794
+ try {
795
+ const cloud = parseAgentCoreConfig(input['agentCoreMemory']);
796
+ const overrides = parseProjectOverrides(input['projectOverrides']);
797
+ if (overrides !== undefined)
798
+ fields.projectOverrides = overrides;
799
+ if (cloud !== undefined)
800
+ fields.agentCoreMemory = cloud;
801
+ }
802
+ catch (error) {
803
+ throw new ConfigError(`${configPath}: ${error.message}`);
804
+ }
776
805
  // Off unless asked for: unlike default-on oversized-result offload, the SDK's
777
806
  // debug output interpolates provider payloads, so a log the user did not ask
778
807
  // for could hold conversation-derived material they did not expect on disk. Stored
@@ -994,11 +1023,12 @@ export function projectHooksPath(projectRoot) {
994
1023
  return path.join(darwinDir(projectRoot), HOOKS_FILENAME);
995
1024
  }
996
1025
  /** Loads project-scoped rules and all executable hook extension layers. */
997
- export async function loadProjectPolicy(projectRoot) {
1026
+ export async function loadProjectPolicy(projectRoot, options = {}) {
1027
+ const held = options.projectLayers === 'held';
998
1028
  const primaryRules = permissionRulesPath(projectRoot);
999
1029
  const legacyProject = path.join(darwinDir(projectRoot), CONFIG_FILENAME);
1000
1030
  const primaryRecord = await readOptionalRecord(primaryRules);
1001
- const legacyRecord = primaryRecord === undefined ? await readOptionalRecord(legacyProject) : undefined;
1031
+ const legacyRecord = primaryRecord === undefined && !held ? await readOptionalRecord(legacyProject) : undefined;
1002
1032
  const { allow: allowRules, deny: denyRules } = primaryRecord === undefined
1003
1033
  ? legacyRecord?.['permissionRules'] === undefined
1004
1034
  ? { allow: [], deny: [] }
@@ -1009,6 +1039,8 @@ export async function loadProjectPolicy(projectRoot) {
1009
1039
  // exact Pre wrapper order stated to the user.
1010
1040
  const loaded = [];
1011
1041
  for (const layer of hookExtensionRoots(projectRoot)) {
1042
+ if (held && layer.scope === 'project')
1043
+ continue;
1012
1044
  loaded.push(await loadHookLayer(layer, projectRoot));
1013
1045
  }
1014
1046
  const active = loaded.flatMap((layer) => layer.sources);
@@ -1141,6 +1173,52 @@ async function readRequiredRecord(file) {
1141
1173
  throw new ConfigError(`${file} does not exist.`);
1142
1174
  return record;
1143
1175
  }
1176
+ export async function inventoryProjectPolicy(projectRoot) {
1177
+ const hookSources = [];
1178
+ const problems = [];
1179
+ for (const layer of hookExtensionRoots(projectRoot)) {
1180
+ if (layer.scope !== 'project')
1181
+ continue;
1182
+ try {
1183
+ const loaded = await loadHookLayer(layer, projectRoot);
1184
+ for (const source of loaded.codexSources) {
1185
+ hookSources.push({ file: source.file, dialect: 'codex', eventCounts: countHooks(source.hooks) });
1186
+ }
1187
+ for (const source of loaded.sources) {
1188
+ hookSources.push({ file: source.file, dialect: 'native', eventCounts: countHooks(source.hooks) });
1189
+ }
1190
+ }
1191
+ catch (error) {
1192
+ problems.push({ file: layer.root, problem: describe(error) });
1193
+ }
1194
+ }
1195
+ let legacyRules;
1196
+ const legacyProject = path.join(darwinDir(projectRoot), CONFIG_FILENAME);
1197
+ try {
1198
+ const primaryRecord = await readOptionalRecord(permissionRulesPath(projectRoot));
1199
+ const legacyRecord = primaryRecord === undefined ? await readOptionalRecord(legacyProject) : undefined;
1200
+ if (legacyRecord?.['permissionRules'] !== undefined) {
1201
+ const { allow, deny } = permissionRulesFields(legacyRecord['permissionRules'], legacyProject);
1202
+ legacyRules = { file: legacyProject, allow: allow.length, deny: deny.length };
1203
+ }
1204
+ }
1205
+ catch (error) {
1206
+ problems.push({ file: legacyProject, problem: describe(error) });
1207
+ }
1208
+ return { hookSources, problems, legacyRules };
1209
+ }
1210
+ /** Command hooks per event — the count the inventory shows, never the commands themselves. */
1211
+ function countHooks(hooks) {
1212
+ const counts = {};
1213
+ for (const [event, groups] of Object.entries(hooks)) {
1214
+ if (groups === undefined)
1215
+ continue;
1216
+ const total = groups.reduce((sum, group) => sum + group.hooks.length, 0);
1217
+ if (total > 0)
1218
+ counts[event] = total;
1219
+ }
1220
+ return counts;
1221
+ }
1144
1222
  async function pathExists(file) {
1145
1223
  try {
1146
1224
  await lstat(file);
@@ -1166,12 +1244,19 @@ async function hookDirectoryHasJson(extensionRoot) {
1166
1244
  throw new ConfigError(`${path.join(extensionRoot, 'hooks')} could not be loaded: ${describe(error)}`);
1167
1245
  }
1168
1246
  }
1169
- /** Adds one project-scoped allow rule, promoting legacy rules on first write. */
1170
- export async function appendAllowRule(projectRoot, rule) {
1247
+ /**
1248
+ * Adds one project-scoped allow rule, promoting legacy rules on first write.
1249
+ *
1250
+ * `options.projectLayers: 'held'` (SER-090) keeps the promotion from ever copying a
1251
+ * *committed* `.darwin/config.json` rule set into the user-owned file: in an untrusted
1252
+ * project the legacy fallback was never in force, so the first write starts from the
1253
+ * empty list — exactly what the gate was honouring.
1254
+ */
1255
+ export async function appendAllowRule(projectRoot, rule, options = {}) {
1171
1256
  if (!isValidRule(rule)) {
1172
1257
  throw new ConfigError(`Refusing to save ${JSON.stringify(rule)}: it is not a permission rule.`);
1173
1258
  }
1174
- const policy = await loadProjectPolicy(projectRoot);
1259
+ const policy = await loadProjectPolicy(projectRoot, options);
1175
1260
  const allow = [...policy.allowRules];
1176
1261
  if (!allow.includes(rule))
1177
1262
  allow.push(rule);
@@ -1187,8 +1272,8 @@ export async function appendAllowRule(projectRoot, rule) {
1187
1272
  * prompt, never a silent widening. Deny-rules (SER-076) pass through untouched:
1188
1273
  * this writer never sees them as a target.
1189
1274
  */
1190
- export async function removeAllowRules(projectRoot, rules) {
1191
- const policy = await loadProjectPolicy(projectRoot);
1275
+ export async function removeAllowRules(projectRoot, rules, options = {}) {
1276
+ const policy = await loadProjectPolicy(projectRoot, options);
1192
1277
  const allow = policy.allowRules.filter((rule) => !rules.includes(rule));
1193
1278
  await writeConfigRecord(permissionRulesPath(projectRoot), rulesRecord(allow, policy.denyRules));
1194
1279
  }
@@ -1235,14 +1320,14 @@ export async function saveThinkingEffort(projectRoot, effort) {
1235
1320
  if (!isThinkingEffort(effort)) {
1236
1321
  throw new ConfigError(`Refusing to save ${JSON.stringify(effort)}: it is not a thinking effort level.`);
1237
1322
  }
1238
- const file = configPath(projectRoot);
1239
- const { record } = await readConfigRecord(file);
1240
- // Reuses the loader's own selection so the level cannot land on a different
1241
- // entry than the session is running: one rule for "which model is enabled".
1242
- const entries = record['models'] === undefined ? undefined : modelEntries(record, file);
1243
- const target = entries === undefined ? record : entries[selectEnabledIndex(entries, file)];
1244
- target['thinkingEffort'] = effort;
1245
- await writeConfigRecord(file, record);
1323
+ const file = configFilePath();
1324
+ await updateConfigFile(file, (record) => {
1325
+ // Reuses the loader's own selection so the level cannot land on a different
1326
+ // entry than the session is running: one rule for "which model is enabled".
1327
+ const entries = record['models'] === undefined ? undefined : modelEntries(record, file);
1328
+ const target = entries === undefined ? record : entries[selectEnabledIndex(entries, file)];
1329
+ target['thinkingEffort'] = effort;
1330
+ });
1246
1331
  }
1247
1332
  /**
1248
1333
  * Moves `enable: true` to the entry at `index`, switching every other entry off,
@@ -1262,26 +1347,26 @@ export async function saveThinkingEffort(projectRoot, effort) {
1262
1347
  * failed write costs only the memory of the choice.
1263
1348
  */
1264
1349
  export async function saveEnabledModel(projectRoot, index) {
1265
- const file = configPath(projectRoot);
1266
- const { record, existed } = await readConfigRecord(file);
1267
- if (record['models'] === undefined) {
1268
- if (existed) {
1269
- throw new ConfigError(`${file} configures a single model, so there is nothing to switch between. ` +
1270
- `Move it into a "models" array to keep more than one configuration.`);
1350
+ const file = configFilePath();
1351
+ await updateConfigFile(file, (record, existed) => {
1352
+ if (record['models'] === undefined) {
1353
+ if (existed) {
1354
+ throw new ConfigError(`${file} configures a single model, so there is nothing to switch between. ` +
1355
+ `Move it into a "models" array to keep more than one configuration.`);
1356
+ }
1357
+ record['models'] = DEFAULT_MODELS.map((fields, choiceIndex) => ({
1358
+ ...fields,
1359
+ enable: choiceIndex === index,
1360
+ }));
1271
1361
  }
1272
- record['models'] = DEFAULT_MODELS.map((fields, choiceIndex) => ({
1273
- ...fields,
1274
- enable: choiceIndex === index,
1275
- }));
1276
- }
1277
- const entries = modelEntries(record, file);
1278
- const target = entries[index];
1279
- if (target === undefined) {
1280
- throw new ConfigError(`${file}: there is no models[${index}] to enable (${entries.length} entries).`);
1281
- }
1282
- for (const entry of entries)
1283
- entry['enable'] = entry === target;
1284
- await writeConfigRecord(file, record);
1362
+ const entries = modelEntries(record, file);
1363
+ const target = entries[index];
1364
+ if (target === undefined) {
1365
+ throw new ConfigError(`${file}: there is no models[${index}] to enable (${entries.length} entries).`);
1366
+ }
1367
+ for (const entry of entries)
1368
+ entry['enable'] = entry === target;
1369
+ });
1285
1370
  }
1286
1371
  /** Writes the config file back, creating `.darwin/` when this is the first write. */
1287
1372
  async function writeConfigRecord(file, record) {
@@ -1391,11 +1476,10 @@ async function createAnthropicModel(config) {
1391
1476
  // Tools, system prompt and last user message, one TTL — the same three cache
1392
1477
  // points Bedrock gets; omitted entirely when caching is off.
1393
1478
  ...(cacheConfig !== undefined && { cacheConfig }),
1394
- // `clientConfig` is spread into the SDK's own `new Anthropic({...})`, which is
1395
- // how a Messages-API-compatible endpoint is reached without darwin importing
1396
- // the client package itself. Omitted entirely when nothing resolved, so the
1397
- // default install passes exactly what it always has.
1398
- ...(baseURL !== undefined && { clientConfig: { baseURL } }),
1479
+ // The pinned provider does not forward StreamOptions.cancelSignal. The
1480
+ // client's supported middleware carries only the scoped parent stream
1481
+ // signal; outside that scope (children/counting) it delegates unchanged.
1482
+ clientConfig: { ...(baseURL !== undefined && { baseURL }), middleware: [modelStreamMiddleware] },
1399
1483
  ...(thinking !== undefined && { params: thinking }),
1400
1484
  });
1401
1485
  }