operon-agents-core 0.1.0-alpha.2 → 0.1.0-alpha.21

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 (289) hide show
  1. package/dist/agent/agent.d.ts +8 -7
  2. package/dist/agent/compose-hooks.d.ts +10 -1
  3. package/dist/agent/compose-hooks.js +61 -6
  4. package/dist/agent/concurrency.js +1 -1
  5. package/dist/agent/context-report.d.ts +2 -2
  6. package/dist/agent/durable-state.d.ts +22 -0
  7. package/dist/agent/durable-state.js +54 -0
  8. package/dist/agent/index.d.ts +2 -2
  9. package/dist/agent/index.js +1 -1
  10. package/dist/agent/instruction-context.d.ts +6 -6
  11. package/dist/agent/instruction-context.js +23 -23
  12. package/dist/agent/profile-builtins.js +1 -1
  13. package/dist/agent/run-support.d.ts +1 -1
  14. package/dist/agent/run-support.js +6 -5
  15. package/dist/agent/runner.d.ts +25 -22
  16. package/dist/agent/runner.js +217 -121
  17. package/dist/agent/session.d.ts +262 -156
  18. package/dist/agent/session.js +590 -418
  19. package/dist/agent/subagent-tools.js +3 -3
  20. package/dist/agent/subagent.js +28 -13
  21. package/dist/agent/toolset.d.ts +1 -0
  22. package/dist/agent/toolset.js +13 -7
  23. package/dist/agent/workflow/journal.d.ts +2 -2
  24. package/dist/agent/workflow/journal.js +2 -2
  25. package/dist/agent/workflow/manager.d.ts +1 -1
  26. package/dist/agent/workflow/manager.js +1 -1
  27. package/dist/agent/workflow/prompt.js +2 -2
  28. package/dist/agent/workflow/sandbox.d.ts +1 -1
  29. package/dist/agent/workflow/sandbox.js +1 -1
  30. package/dist/agent/workflow/tool.js +30 -43
  31. package/dist/agent/worktree.d.ts +8 -8
  32. package/dist/agent/worktree.js +15 -15
  33. package/dist/capabilities/assembler.d.ts +29 -5
  34. package/dist/capabilities/assembler.js +85 -9
  35. package/dist/capabilities/background/code-task.d.ts +43 -0
  36. package/dist/capabilities/background/code-task.js +75 -0
  37. package/dist/capabilities/background/command-task.d.ts +9 -2
  38. package/dist/capabilities/background/command-task.js +22 -6
  39. package/dist/capabilities/background/index.d.ts +6 -1
  40. package/dist/capabilities/background/index.js +26 -20
  41. package/dist/capabilities/background/manager.d.ts +57 -1
  42. package/dist/capabilities/background/manager.js +210 -45
  43. package/dist/capabilities/background/persist-disk.d.ts +1 -1
  44. package/dist/capabilities/background/persist-disk.js +1 -1
  45. package/dist/capabilities/background/persist.js +4 -2
  46. package/dist/capabilities/background/projections.d.ts +16 -0
  47. package/dist/capabilities/background/projections.js +86 -0
  48. package/dist/capabilities/background/stall-watchdog.d.ts +41 -0
  49. package/dist/capabilities/background/stall-watchdog.js +85 -0
  50. package/dist/capabilities/background/task.d.ts +8 -7
  51. package/dist/capabilities/background/tools.js +33 -7
  52. package/dist/capabilities/capability-data.d.ts +52 -0
  53. package/dist/capabilities/capability-data.js +88 -0
  54. package/dist/capabilities/capability-state.d.ts +2 -4
  55. package/dist/capabilities/capability-state.js +5 -23
  56. package/dist/capabilities/capability.d.ts +203 -38
  57. package/dist/capabilities/compaction/index.js +10 -4
  58. package/dist/capabilities/compaction/service.d.ts +20 -5
  59. package/dist/capabilities/compaction/service.js +27 -11
  60. package/dist/capabilities/goal/goal-store.d.ts +76 -12
  61. package/dist/capabilities/goal/goal-store.js +137 -53
  62. package/dist/capabilities/goal/index.d.ts +1 -1
  63. package/dist/capabilities/goal/index.js +30 -7
  64. package/dist/capabilities/index.d.ts +9 -6
  65. package/dist/capabilities/index.js +4 -3
  66. package/dist/capabilities/plan/index.js +22 -5
  67. package/dist/capabilities/plan/plan-mode.d.ts +30 -9
  68. package/dist/capabilities/plan/plan-mode.js +57 -32
  69. package/dist/capabilities/plan/tools.js +1 -1
  70. package/dist/capabilities/skills/flow-provider.js +3 -3
  71. package/dist/capabilities/skills/index.d.ts +13 -1
  72. package/dist/capabilities/skills/index.js +30 -21
  73. package/dist/capabilities/skills/parser.d.ts +2 -2
  74. package/dist/capabilities/skills/parser.js +3 -3
  75. package/dist/capabilities/skills/registry.d.ts +5 -6
  76. package/dist/capabilities/skills/registry.js +6 -9
  77. package/dist/capabilities/skills/scanner.d.ts +3 -3
  78. package/dist/capabilities/skills/scanner.js +14 -14
  79. package/dist/capabilities/skills/service.d.ts +2 -1
  80. package/dist/capabilities/skills/service.js +3 -3
  81. package/dist/capabilities/skills/skill-tool.d.ts +2 -0
  82. package/dist/capabilities/skills/skill-tool.js +1 -1
  83. package/dist/capabilities/task/index.js +2 -1
  84. package/dist/capabilities/task/persist-disk.d.ts +1 -1
  85. package/dist/capabilities/task/persist-disk.js +1 -1
  86. package/dist/capabilities/task/persist.js +1 -1
  87. package/dist/capabilities/todo/index.js +11 -6
  88. package/dist/capabilities/todo/injector.js +2 -1
  89. package/dist/capabilities/todo/todo-store.d.ts +28 -7
  90. package/dist/capabilities/todo/todo-store.js +44 -11
  91. package/dist/capabilities/todo/tools.js +8 -3
  92. package/dist/capabilities/tool-provider.d.ts +3 -3
  93. package/dist/capabilities/user-hooks/engine.d.ts +3 -3
  94. package/dist/capabilities/user-hooks/engine.js +7 -7
  95. package/dist/capabilities/user-hooks/index.js +2 -1
  96. package/dist/capabilities/workflow/index.d.ts +5 -3
  97. package/dist/capabilities/workflow/index.js +3 -2
  98. package/dist/commands/index.js +34 -32
  99. package/dist/config/index.d.ts +1 -1
  100. package/dist/config/provider-manager.js +0 -28
  101. package/dist/config/schema.d.ts +53 -4
  102. package/dist/config/schema.js +53 -1
  103. package/dist/events/events.d.ts +43 -11
  104. package/dist/events/events.js +1 -0
  105. package/dist/events/index.d.ts +2 -2
  106. package/dist/events/index.js +1 -1
  107. package/dist/events/projection.d.ts +49 -1
  108. package/dist/events/projection.js +144 -19
  109. package/dist/events/publisher.js +2 -21
  110. package/dist/home.d.ts +1 -1
  111. package/dist/home.js +1 -1
  112. package/dist/index.d.ts +3 -2
  113. package/dist/index.js +2 -1
  114. package/dist/internal.d.ts +5 -2
  115. package/dist/internal.js +5 -2
  116. package/dist/llm/define-model.d.ts +4 -0
  117. package/dist/llm/define-model.js +63 -25
  118. package/dist/llm/index.d.ts +1 -0
  119. package/dist/llm/index.js +1 -0
  120. package/dist/llm/model.d.ts +2 -0
  121. package/dist/llm/provider.d.ts +17 -0
  122. package/dist/llm/provider.js +14 -0
  123. package/dist/llm/retry.js +1 -1
  124. package/dist/loop/context.d.ts +21 -1
  125. package/dist/loop/context.js +47 -9
  126. package/dist/loop/events.d.ts +5 -1
  127. package/dist/loop/index.d.ts +2 -2
  128. package/dist/loop/index.js +1 -1
  129. package/dist/loop/interruption.d.ts +9 -4
  130. package/dist/loop/interruption.js +11 -25
  131. package/dist/loop/run-turn.d.ts +16 -3
  132. package/dist/loop/run-turn.js +13 -4
  133. package/dist/loop/steer.d.ts +78 -12
  134. package/dist/loop/steer.js +101 -38
  135. package/dist/loop/tool-call.d.ts +13 -2
  136. package/dist/loop/tool-call.js +135 -5
  137. package/dist/loop/turn-step.d.ts +13 -2
  138. package/dist/loop/turn-step.js +29 -7
  139. package/dist/loop/types.d.ts +6 -0
  140. package/dist/mcp/auth-tool.d.ts +3 -1
  141. package/dist/mcp/auth-tool.js +2 -2
  142. package/dist/mcp/capability.d.ts +13 -0
  143. package/dist/mcp/capability.js +36 -17
  144. package/dist/mcp/config-loader.d.ts +5 -5
  145. package/dist/mcp/config-loader.js +17 -17
  146. package/dist/mcp/credentials.d.ts +35 -0
  147. package/dist/mcp/credentials.js +2 -0
  148. package/dist/mcp/filter.d.ts +2 -2
  149. package/dist/mcp/index.d.ts +4 -3
  150. package/dist/mcp/index.js +1 -1
  151. package/dist/mcp/manager.d.ts +108 -6
  152. package/dist/mcp/manager.js +262 -18
  153. package/dist/mcp/oauth/callback-server.d.ts +10 -1
  154. package/dist/mcp/oauth/callback-server.js +82 -16
  155. package/dist/mcp/oauth/index.d.ts +2 -2
  156. package/dist/mcp/oauth/provider.d.ts +18 -0
  157. package/dist/mcp/oauth/provider.js +31 -1
  158. package/dist/mcp/oauth/service.d.ts +9 -3
  159. package/dist/mcp/oauth/service.js +29 -4
  160. package/dist/mcp/sdk-transport.js +1 -1
  161. package/dist/mcp/server.js +1 -1
  162. package/dist/permission/auto-approver/prompts-data.d.ts +1 -1
  163. package/dist/permission/auto-approver/prompts-data.js +1 -1
  164. package/dist/permission/manager.d.ts +5 -3
  165. package/dist/permission/manager.js +7 -3
  166. package/dist/permission/policies.d.ts +2 -2
  167. package/dist/permission/policies.js +4 -4
  168. package/dist/plugins/fields.d.ts +14 -0
  169. package/dist/plugins/fields.js +30 -0
  170. package/dist/plugins/hooks.d.ts +2 -2
  171. package/dist/plugins/hooks.js +12 -12
  172. package/dist/plugins/index.js +1 -0
  173. package/dist/plugins/manager.d.ts +8 -3
  174. package/dist/plugins/manager.js +18 -7
  175. package/dist/plugins/manifest.d.ts +2 -2
  176. package/dist/plugins/manifest.js +101 -91
  177. package/dist/plugins/marketplace.js +76 -57
  178. package/dist/plugins/store.d.ts +3 -3
  179. package/dist/plugins/store.js +6 -6
  180. package/dist/protocol/index.d.ts +1 -1
  181. package/dist/store/catalog-store.d.ts +4 -1
  182. package/dist/store/catalog-store.js +5 -1
  183. package/dist/store/checkpointing-store.d.ts +41 -0
  184. package/dist/store/checkpointing-store.js +86 -0
  185. package/dist/store/disk-store.d.ts +8 -0
  186. package/dist/store/disk-store.js +127 -5
  187. package/dist/store/index.d.ts +3 -2
  188. package/dist/store/index.js +2 -1
  189. package/dist/store/log-store.d.ts +9 -1
  190. package/dist/store/log-store.js +68 -4
  191. package/dist/store/migrate.d.ts +8 -2
  192. package/dist/store/migrate.js +9 -2
  193. package/dist/store/origin.d.ts +31 -6
  194. package/dist/store/origin.js +0 -14
  195. package/dist/store/pg.d.ts +1 -0
  196. package/dist/store/pg.js +37 -2
  197. package/dist/store/redis.d.ts +1 -0
  198. package/dist/store/redis.js +30 -0
  199. package/dist/store/repository.d.ts +13 -1
  200. package/dist/store/repository.js +45 -2
  201. package/dist/store/session-catalog.d.ts +4 -0
  202. package/dist/store/session-catalog.js +6 -0
  203. package/dist/store/storage.js +3 -0
  204. package/dist/store/store.d.ts +97 -34
  205. package/dist/store/store.js +64 -10
  206. package/dist/telemetry/appender.d.ts +43 -0
  207. package/dist/telemetry/appender.js +46 -0
  208. package/dist/telemetry/events.d.ts +142 -0
  209. package/dist/telemetry/events.js +141 -0
  210. package/dist/telemetry/index.d.ts +10 -0
  211. package/dist/telemetry/index.js +6 -0
  212. package/dist/telemetry/projection.d.ts +23 -0
  213. package/dist/telemetry/projection.js +185 -0
  214. package/dist/telemetry/redact.d.ts +20 -0
  215. package/dist/telemetry/redact.js +40 -0
  216. package/dist/telemetry/service.d.ts +49 -0
  217. package/dist/telemetry/service.js +137 -0
  218. package/dist/testing.d.ts +58 -0
  219. package/dist/testing.js +123 -0
  220. package/dist/tool/background.d.ts +9 -6
  221. package/dist/tool/background.js +7 -1
  222. package/dist/tool/builtin/ask-user-question.js +6 -5
  223. package/dist/tool/builtin/bash.d.ts +6 -0
  224. package/dist/tool/builtin/bash.js +79 -42
  225. package/dist/tool/builtin/edit.js +82 -109
  226. package/dist/tool/builtin/glob.js +13 -13
  227. package/dist/tool/builtin/grep.js +13 -13
  228. package/dist/tool/builtin/read.js +25 -15
  229. package/dist/tool/builtin/write.js +49 -33
  230. package/dist/tool/define.d.ts +14 -8
  231. package/dist/tool/define.js +8 -2
  232. package/dist/tool/{machine-base.d.ts → environment-base.d.ts} +37 -37
  233. package/dist/tool/{machine-base.js → environment-base.js} +45 -119
  234. package/dist/tool/{machine-local.d.ts → environment-local.d.ts} +9 -8
  235. package/dist/tool/{machine-local.js → environment-local.js} +60 -81
  236. package/dist/tool/{machine-null.d.ts → environment-null.d.ts} +9 -9
  237. package/dist/tool/{machine-null.js → environment-null.js} +9 -9
  238. package/dist/tool/{machine-ssh.d.ts → environment-ssh.d.ts} +33 -18
  239. package/dist/tool/{machine-ssh.js → environment-ssh.js} +118 -149
  240. package/dist/tool/{machine.d.ts → environment.d.ts} +53 -82
  241. package/dist/tool/environment.js +2 -0
  242. package/dist/tool/file-freshness.d.ts +33 -19
  243. package/dist/tool/file-freshness.js +39 -30
  244. package/dist/tool/filesystem-tools.d.ts +1 -1
  245. package/dist/tool/filesystem-tools.js +1 -1
  246. package/dist/tool/git-context.d.ts +2 -2
  247. package/dist/tool/git-context.js +8 -8
  248. package/dist/tool/index.d.ts +12 -12
  249. package/dist/tool/index.js +12 -10
  250. package/dist/tool/policies/path-access.d.ts +4 -4
  251. package/dist/tool/policies/path-access.js +12 -12
  252. package/dist/tool/questions.d.ts +8 -0
  253. package/dist/tool/search/catalog.d.ts +37 -0
  254. package/dist/tool/search/catalog.js +182 -0
  255. package/dist/tool/search/deferral.d.ts +3 -2
  256. package/dist/tool/search/loaded.d.ts +32 -0
  257. package/dist/tool/search/loaded.js +96 -0
  258. package/dist/tool/search/search-tool.d.ts +2 -6
  259. package/dist/tool/search/search-tool.js +16 -15
  260. package/dist/tool/shell-env.js +4 -0
  261. package/dist/tool/support/bash-paths.js +38 -7
  262. package/dist/tool/support/{machine-ops.d.ts → environment-ops.d.ts} +12 -14
  263. package/dist/tool/support/{machine-ops.js → environment-ops.js} +21 -2
  264. package/dist/tool/support/git-worktree.d.ts +3 -3
  265. package/dist/tool/support/git-worktree.js +6 -6
  266. package/dist/tool/support/rg-locator.d.ts +6 -6
  267. package/dist/tool/support/rg-locator.js +6 -6
  268. package/dist/tool/support/ripgrep-run.d.ts +5 -5
  269. package/dist/tool/support/ripgrep-run.js +3 -3
  270. package/dist/tool/support/tool-path.d.ts +3 -3
  271. package/dist/tool/support/tool-path.js +7 -7
  272. package/dist/tool/types.d.ts +54 -10
  273. package/dist/tool/web/fetch-url.js +1 -1
  274. package/dist/tool/web/web-search.js +1 -1
  275. package/dist/tool/workspace-spec.d.ts +3 -3
  276. package/dist/tool/workspace-spec.js +27 -27
  277. package/dist/tracing/bridge.d.ts +9 -1
  278. package/dist/tracing/bridge.js +307 -77
  279. package/dist/tracing/index.d.ts +2 -2
  280. package/dist/tracing/otel.d.ts +28 -1
  281. package/dist/tracing/otel.js +150 -38
  282. package/dist/tracing/processor.d.ts +22 -0
  283. package/dist/tracing/processor.js +2 -0
  284. package/dist/tracing/spans.d.ts +54 -0
  285. package/dist/tracing/spans.js +5 -0
  286. package/package.json +6 -2
  287. package/dist/tool/machine.js +0 -15
  288. package/dist/tool/search/activation.d.ts +0 -13
  289. package/dist/tool/search/activation.js +0 -31
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { defineTool } from "../../tool/define.js";
3
3
  import { ToolAccesses } from "../../tool/access.js";
4
+ import { DEFAULT_ADDRESS } from "../../store/index.js";
4
5
  import { TODO_LIST_TOOL_NAME } from "./todo-store.js";
5
6
  export { TODO_LIST_TOOL_NAME } from "./todo-store.js";
6
7
  const TODO_LIST_WRITE_REMINDER = "Ensure that you continue to use the todo list to track progress. Mark tasks done immediately after finishing them, and keep exactly one task in_progress when work is underway.";
@@ -34,12 +35,16 @@ export function todoListTool(store) {
34
35
  approvalRule: TODO_LIST_TOOL_NAME,
35
36
  accesses: ToolAccesses.none(),
36
37
  display: { title },
37
- run: async () => {
38
+ run: async (ctx) => {
39
+ // Whose list this is: the frame running the call. A subagent plans its own work, and
40
+ // its result lands in its own shard, so the fold on resume puts it back where it came
41
+ // from. `address` is absent only in a hand-built context — treat that as the root.
42
+ const address = ctx.address ?? DEFAULT_ADDRESS;
38
43
  // Read mode carries the current list too, so a resumed/forked session reconstructs
39
44
  // from the latest TodoList result even when the last write was on a parent node.
40
45
  if (args.todos === undefined)
41
- return todoResult(renderTodoList(store.get()), store.get());
42
- const stored = store.set(args.todos);
46
+ return todoResult(renderTodoList(store.get(address)), store.get(address));
47
+ const stored = store.set(address, args.todos);
43
48
  if (stored.length === 0)
44
49
  return todoResult("Todo list cleared.", stored);
45
50
  return todoResult(`Todo list updated.\n${renderTodoList(stored)}\n\n${TODO_LIST_WRITE_REMINDER}`, stored);
@@ -1,9 +1,9 @@
1
1
  import type { Tool } from "../tool/types.ts";
2
- import type { CapabilityContext } from "./capability.ts";
2
+ import type { RunContext } from "./capability.ts";
3
3
  export interface ToolProvider {
4
4
  readonly id: string;
5
- listTools(ctx: CapabilityContext): Promise<readonly Tool[]> | readonly Tool[];
6
- start?(ctx: CapabilityContext): Promise<void> | void;
5
+ listTools(ctx: RunContext): Promise<readonly Tool[]> | readonly Tool[];
6
+ start?(ctx: RunContext): Promise<void> | void;
7
7
  stop?(): Promise<void> | void;
8
8
  }
9
9
  export declare function staticToolProvider(id: string, tools: readonly Tool[]): ToolProvider;
@@ -1,10 +1,10 @@
1
- import type { Machine } from "../../tool/machine.ts";
1
+ import type { Environment } from "../../tool/environment.ts";
2
2
  import { type HookBlockResult, type HookDef, type HookEventType, type HookTriggerArgs } from "./types.ts";
3
3
  export declare class HookEngine {
4
4
  private readonly hooks;
5
- private machine;
5
+ private environment;
6
6
  constructor(hooks: readonly HookDef[]);
7
- attachMachine(machine: Machine): void;
7
+ attachEnvironment(environment: Environment): void;
8
8
  has(event: HookEventType): boolean;
9
9
  triggerBlock(event: HookEventType, args?: HookTriggerArgs): Promise<HookBlockResult>;
10
10
  trigger(event: HookEventType, args?: HookTriggerArgs): Promise<string>;
@@ -1,12 +1,12 @@
1
1
  import { DEFAULT_HOOK_TIMEOUT_MS, } from "./types.js";
2
2
  export class HookEngine {
3
3
  hooks;
4
- machine = null;
4
+ environment = null;
5
5
  constructor(hooks) {
6
6
  this.hooks = hooks;
7
7
  }
8
- attachMachine(machine) {
9
- this.machine = machine;
8
+ attachEnvironment(environment) {
9
+ this.environment = environment;
10
10
  }
11
11
  has(event) {
12
12
  return this.hooks.some((h) => h.event === event);
@@ -65,11 +65,11 @@ export class HookEngine {
65
65
  * timed-out hook has no opinion to report.
66
66
  */
67
67
  async runHook(hook, args) {
68
- if (!this.machine)
69
- throw new Error("HookEngine has no machine attached.");
68
+ if (!this.environment)
69
+ throw new Error("HookEngine has no environment attached.");
70
70
  const timeoutMs = hook.timeout ?? DEFAULT_HOOK_TIMEOUT_MS;
71
- const shell = this.machine.osEnv.shellPath || "/bin/sh";
72
- const result = await this.machine.run([shell, "-c", hook.command], {
71
+ const shell = this.environment.osInfo.shellPath || "/bin/sh";
72
+ const result = await this.environment.run([shell, "-c", hook.command], {
73
73
  stdin: JSON.stringify(args.inputData ?? {}),
74
74
  timeoutMs,
75
75
  ...(args.signal !== undefined ? { signal: args.signal } : {}),
@@ -50,6 +50,7 @@ export function userHooksCapability(hooks) {
50
50
  let unsubscribe;
51
51
  return {
52
52
  name: "user-hooks",
53
+ contract: "invariant",
53
54
  policies: [preToolCallHookPolicy(engine)],
54
55
  injectors: [new SessionStartInjector(() => sessionStartOutput)],
55
56
  hooks: {
@@ -67,7 +68,7 @@ export function userHooksCapability(hooks) {
67
68
  },
68
69
  service: engine,
69
70
  openSession: async (ctx) => {
70
- engine.attachMachine(ctx.machine);
71
+ engine.attachEnvironment(ctx.environment);
71
72
  if (engine.has("SessionStart")) {
72
73
  sessionStartOutput = await engine
73
74
  .trigger("SessionStart", { inputData: { session_id: ctx.sessionId }, signal: ctx.signal })
@@ -1,12 +1,14 @@
1
1
  /**
2
2
  * Workflow capability — exposes the WorkflowManager as a session service
3
- * (`session.workflow`), mirroring how `background` exposes the BackgroundManager.
3
+ * (`session.workflow`, i.e. `session.service("workflow")`), mirroring how `background` exposes the
4
+ * BackgroundManager.
4
5
  *
5
6
  * It contributes NO tools: the `Workflow` tool is built by the Runner (it needs
6
7
  * runLoop to spawn subagents), and reaches this service through the session to read
7
8
  * its configured directories and persist run snapshots. The capability's job is
8
- * purely to make the management/read machine available to upper layers and the
9
- * `/workflows` command.
9
+ * purely to make the management/read environment available to upper layers and the
10
+ * `/workflows` command. A session opened WITHOUT this capability still has a
11
+ * `workflow` service: `Session.open` provides an in-memory fallback.
10
12
  */
11
13
  import type { Capability } from "../capability.ts";
12
14
  import { WorkflowManager } from "../../agent/workflow/manager.ts";
@@ -3,10 +3,11 @@ export { WorkflowManager } from "../../agent/workflow/manager.js";
3
3
  export function workflowCapability(manager = new WorkflowManager()) {
4
4
  return {
5
5
  name: "workflow",
6
+ contract: "detachable",
6
7
  service: manager,
7
8
  openSession: (ctx) => {
8
- // Bookkeeping goes through the SessionStore, never the Machine: without a
9
- // durable store the manager stays on its in-memory store for the session's lifetime.
9
+ // Bookkeeping goes through the SessionStore, never the Environment: without a durable
10
+ // store the manager stays on its in-memory store for the session's lifetime.
10
11
  if (ctx.store !== undefined)
11
12
  manager.attachStore(ctx.store);
12
13
  },
@@ -33,15 +33,17 @@ export class CommandRegistry {
33
33
  }
34
34
  }
35
35
  /**
36
- * Commands contributed at runtime — the duck protocol: any capability whose `service` object
37
- * exposes `sessionCommands(): HeadlessCommand[]` adds to the session's command set (the
38
- * extensions runtime uses this to surface `api.registerCommand` registrations). No names, no
39
- * imports: the registry stays ignorant of who contributes.
36
+ * Commands the session's open capabilities contribute: each one's `commands`, plus — for the
37
+ * extensions runtime, whose commands are registered while the session runs — any service that
38
+ * exposes `sessionCommands(): HeadlessCommand[]`. No names, no imports: the registry stays
39
+ * ignorant of who contributes.
40
40
  */
41
41
  function dynamicCommands(session) {
42
42
  const out = [];
43
43
  for (const capability of session.capabilities) {
44
- const service = capability.service;
44
+ if (capability.commands !== undefined)
45
+ out.push(...capability.commands);
46
+ const service = session.service(capability.name);
45
47
  if (typeof service?.sessionCommands === "function")
46
48
  out.push(...service.sessionCommands());
47
49
  }
@@ -69,7 +71,7 @@ export function registerExtensionCommands(registry) {
69
71
  name: "skills",
70
72
  description: "List available skills.",
71
73
  run: async ({ session }) => {
72
- const skills = await session.listSkills();
74
+ const skills = await session.skills.listSkills();
73
75
  return { ok: true, message: `${skills.length} skill(s) available.`, data: skills };
74
76
  },
75
77
  });
@@ -80,7 +82,7 @@ export function registerExtensionCommands(registry) {
80
82
  const { head: name, tail: skillArgs } = splitHead(args);
81
83
  if (name.length === 0)
82
84
  return { ok: false, message: "Usage: /skill <name> [args] or /skill:<name> [args]" };
83
- const activation = await session.activateSkill({ name, args: skillArgs, trigger: "user-slash" });
85
+ const activation = await session.skills.activateSkill({ name, args: skillArgs, trigger: "user-slash" });
84
86
  return { ok: true, message: `Activated skill ${activation.skillName}.`, data: activation };
85
87
  },
86
88
  });
@@ -90,38 +92,38 @@ export function registerExtensionCommands(registry) {
90
92
  run: async ({ session }, rawArgs) => {
91
93
  const { head: sub, tail } = splitHead(rawArgs);
92
94
  if (sub.length === 0 || sub === "list") {
93
- const plugins = await session.listPlugins();
95
+ const plugins = await session.plugins.summaries();
94
96
  return { ok: true, message: `${plugins.length} plugin(s) installed.`, data: plugins };
95
97
  }
96
98
  if (sub === "install") {
97
99
  if (tail.length === 0)
98
100
  return { ok: false, message: "Usage: /plugins install <local-path-or-zip-url>" };
99
- const plugin = await session.installPlugin(tail);
101
+ const plugin = await session.plugins.installSummary(tail);
100
102
  return { ok: true, message: `Installed plugin ${plugin.id}.`, data: plugin };
101
103
  }
102
104
  if (sub === "enable" || sub === "disable") {
103
105
  const { head: id } = splitHead(tail);
104
106
  if (id.length === 0)
105
107
  return { ok: false, message: `Usage: /plugins ${sub} <id>` };
106
- await session.setPluginEnabled(id, sub === "enable");
108
+ await session.plugins.setEnabled(id, sub === "enable");
107
109
  return { ok: true, message: `${sub === "enable" ? "Enabled" : "Disabled"} plugin ${id}.` };
108
110
  }
109
111
  if (sub === "remove") {
110
112
  const { head: id } = splitHead(tail);
111
113
  if (id.length === 0)
112
114
  return { ok: false, message: "Usage: /plugins remove <id>" };
113
- await session.removePlugin(id);
115
+ await session.plugins.remove(id);
114
116
  return { ok: true, message: `Removed plugin ${id}.` };
115
117
  }
116
118
  if (sub === "reload") {
117
- const summary = await session.reloadPlugins();
119
+ const summary = await session.plugins.reload();
118
120
  return { ok: true, message: "Reloaded plugins.", data: summary };
119
121
  }
120
122
  if (sub === "info") {
121
123
  const { head: id } = splitHead(tail);
122
124
  if (id.length === 0)
123
125
  return { ok: false, message: "Usage: /plugins info <id>" };
124
- const info = await session.getPluginInfo(id);
126
+ const info = await session.plugins.info(id);
125
127
  return info === undefined
126
128
  ? { ok: false, message: `Plugin "${id}" is not installed.` }
127
129
  : { ok: true, message: `Plugin ${info.id}.`, data: info };
@@ -133,10 +135,10 @@ export function registerExtensionCommands(registry) {
133
135
  if ((action !== "enable" && action !== "disable") || id.length === 0 || server.length === 0) {
134
136
  return { ok: false, message: "Usage: /plugins mcp enable|disable <id> <server>" };
135
137
  }
136
- await session.setPluginMcpServerEnabled(id, server, action === "enable");
138
+ await session.plugins.setMcpServerEnabled(id, server, action === "enable");
137
139
  return { ok: true, message: `${action === "enable" ? "Enabled" : "Disabled"} MCP server ${server} for ${id}.` };
138
140
  }
139
- const info = await session.getPluginInfo(sub);
141
+ const info = await session.plugins.info(sub);
140
142
  return info === undefined
141
143
  ? { ok: false, message: `Unknown /plugins action or plugin: ${sub}` }
142
144
  : { ok: true, message: `Plugin ${info.id}.`, data: info };
@@ -152,21 +154,21 @@ export function registerCapabilityCommands(registry) {
152
154
  const { head: sub, tail } = splitHead(rawArgs);
153
155
  if (sub.length === 0 || sub === "list" || sub === "active") {
154
156
  const activeOnly = sub === "active" || tail.trim() === "active";
155
- const tasks = await session.listBackgroundTasks(activeOnly ? { activeOnly: true } : {});
157
+ const tasks = session.requireService("background").list(activeOnly, undefined);
156
158
  return { ok: true, message: `${tasks.length} background task(s).`, data: tasks };
157
159
  }
158
160
  if (sub === "output") {
159
161
  const { head: id } = splitHead(tail);
160
162
  if (id.length === 0)
161
163
  return { ok: false, message: "Usage: /tasks output <id>" };
162
- const snapshot = await session.readBackgroundTaskOutput(id);
164
+ const snapshot = await session.requireService("background").readOutput(id, 16 * 1024);
163
165
  return { ok: true, message: `Output for task ${id}.`, data: snapshot };
164
166
  }
165
167
  if (sub === "stop") {
166
168
  const { head: id, tail: reason } = splitHead(tail);
167
169
  if (id.length === 0)
168
170
  return { ok: false, message: "Usage: /tasks stop <id> [reason]" };
169
- const info = await session.stopBackgroundTask(id, reason.length > 0 ? reason : undefined);
171
+ const info = await session.requireService("background").stop(id, reason.length > 0 ? reason : undefined);
170
172
  return info === undefined
171
173
  ? { ok: false, message: `No background task "${id}".` }
172
174
  : { ok: true, message: `Stopped task ${id}.`, data: info };
@@ -180,7 +182,7 @@ export function registerCapabilityCommands(registry) {
180
182
  run: async ({ session }, rawArgs) => {
181
183
  const { head: sub, tail } = splitHead(rawArgs);
182
184
  if (sub.length === 0 || sub === "show" || sub === "status") {
183
- const goal = await session.getGoal();
185
+ const goal = await session.goal.snapshot();
184
186
  return goal === null
185
187
  ? { ok: true, message: "No active goal.", data: null }
186
188
  : { ok: true, message: `Goal is ${goal.status}.`, data: goal };
@@ -189,16 +191,16 @@ export function registerCapabilityCommands(registry) {
189
191
  const objective = tail.trim();
190
192
  if (objective.length === 0)
191
193
  return { ok: false, message: "Usage: /goal set <objective>" };
192
- const goal = await session.createGoal({ objective });
194
+ const goal = await session.goal.create({ objective });
193
195
  return { ok: true, message: "Goal set.", data: goal };
194
196
  }
195
197
  if (sub === "pause" || sub === "resume" || sub === "cancel") {
196
198
  const reason = tail.trim().length > 0 ? tail.trim() : undefined;
197
199
  const goal = sub === "pause"
198
- ? await session.pauseGoal({ reason })
200
+ ? await session.goal.pause(reason)
199
201
  : sub === "resume"
200
- ? await session.resumeGoal({ reason })
201
- : await session.cancelGoal({ reason });
202
+ ? await session.goal.resume(reason)
203
+ : await session.goal.cancel(reason);
202
204
  if (goal === null)
203
205
  return { ok: false, message: "No active goal." };
204
206
  const verb = sub === "pause" ? "Paused" : sub === "resume" ? "Resumed" : "Cancelled";
@@ -208,7 +210,7 @@ export function registerCapabilityCommands(registry) {
208
210
  const budget = parseGoalBudget(tail);
209
211
  if (budget === undefined)
210
212
  return { ok: false, message: "Usage: /goal budget <turns=N tokens=N wallClockMs=N>" };
211
- const goal = await session.setGoalBudget(budget);
213
+ const goal = await session.goal.changeBudget(budget);
212
214
  if (goal === null)
213
215
  return { ok: false, message: "No active goal." };
214
216
  return { ok: true, message: "Goal budget updated.", data: goal };
@@ -223,14 +225,14 @@ export function registerCapabilityCommands(registry) {
223
225
  run: async ({ session }, rawArgs) => {
224
226
  const { head: sub, tail } = splitHead(rawArgs);
225
227
  if (sub.length === 0 || sub === "list") {
226
- const runs = await session.listWorkflows();
228
+ const runs = await session.background?.listWorkflows() ?? [];
227
229
  return { ok: true, message: `${runs.length} workflow run(s).`, data: runs };
228
230
  }
229
231
  if (sub === "info" || sub === "show" || sub === "get") {
230
232
  const { head: runId } = splitHead(tail);
231
233
  if (runId.length === 0)
232
234
  return { ok: false, message: "Usage: /workflows info <runId>" };
233
- const run = await session.getWorkflow(runId);
235
+ const run = await session.background?.getWorkflow(runId);
234
236
  return run === undefined
235
237
  ? { ok: false, message: `No workflow run "${runId}".` }
236
238
  : { ok: true, message: `Workflow ${run.workflowName} is ${run.status}.`, data: run };
@@ -244,15 +246,15 @@ export function registerCapabilityCommands(registry) {
244
246
  run: async ({ session }, rawArgs) => {
245
247
  const { head: sub } = splitHead(rawArgs);
246
248
  if (sub.length === 0 || sub === "show" || sub === "status") {
247
- const plan = await session.getPlan();
249
+ const plan = await session.plan.data();
248
250
  return { ok: true, message: plan === null ? "Plan mode is off." : "Plan mode is on.", data: plan };
249
251
  }
250
252
  if (sub === "on" || sub === "enter") {
251
- const plan = await session.setPlanMode(true);
253
+ const plan = await session.plan.setEnabled(true);
252
254
  return { ok: true, message: "Plan mode on.", data: plan };
253
255
  }
254
256
  if (sub === "off" || sub === "exit" || sub === "clear") {
255
- const plan = await session.setPlanMode(false);
257
+ const plan = await session.plan.setEnabled(false);
256
258
  return { ok: true, message: "Plan mode off.", data: plan };
257
259
  }
258
260
  return { ok: false, message: `Unknown /plan action: ${sub}` };
@@ -264,17 +266,17 @@ export function registerCapabilityCommands(registry) {
264
266
  run: async ({ session }, rawArgs) => {
265
267
  const lower = rawArgs.trim().toLowerCase();
266
268
  if (lower === "status" || lower === "pending") {
267
- const pending = await session.pendingCompaction();
269
+ const pending = await session.compaction.pending();
268
270
  return { ok: true, message: pending === null ? "No pending compaction." : "Compaction pending.", data: pending };
269
271
  }
270
272
  if (lower === "cancel") {
271
- const cancelled = await session.cancelCompaction();
273
+ const cancelled = await session.compaction.cancel();
272
274
  return cancelled === null
273
275
  ? { ok: false, message: "No pending compaction to cancel." }
274
276
  : { ok: true, message: "Cancelled pending compaction.", data: cancelled };
275
277
  }
276
278
  const instruction = rawArgs.trim();
277
- const pending = await session.compact(instruction.length > 0 ? { instruction } : {});
279
+ const pending = session.compaction.request(instruction.length > 0 ? { instruction } : {});
278
280
  return { ok: true, message: "Compaction requested.", data: pending };
279
281
  },
280
282
  });
@@ -1,5 +1,5 @@
1
1
  export { AgentFrameworkConfigSchema, ModelCredentialsSchema, ModelAliasSchema, McpServerConfigSchema, PermissionRuleConfigSchema, ProviderConfigSchema, parseConfig, } from "./schema.ts";
2
- export type { AgentFrameworkConfig, HookDefConfig, LoopControl, McpServerConfig, ModelAlias, ModelCredentialsConfig, PermissionConfig, PermissionRuleConfig, PluginRef, ProviderConfig, ProviderType, ThinkingConfig, } from "./schema.ts";
2
+ export type { AgentFrameworkConfig, HookDefConfig, LoopControl, McpServerConfig, McpOAuthClientConfig, ModelAlias, ModelCredentialsConfig, PermissionConfig, PermissionRuleConfig, PluginRef, ProviderConfig, ProviderType, ThinkingConfig, } from "./schema.ts";
3
3
  export { mergeConfigs } from "./merge.ts";
4
4
  export { ModelCatalog } from "./model-catalog.ts";
5
5
  export type { ModelCapabilityInfo } from "./model-catalog.ts";
@@ -159,16 +159,6 @@ function configureKnownModel(model, providerId, config) {
159
159
  ...(config.customHeaders !== undefined
160
160
  ? { headers: { ...(model.headers ?? {}), ...config.customHeaders } }
161
161
  : {}),
162
- ...(config.type === "kimi"
163
- ? { compat: { ...model.compat, deferredToolsMode: "kimi" } }
164
- : config.type === "anthropic"
165
- ? {
166
- compat: {
167
- ...model.compat,
168
- supportsToolReferences: defaultAnthropicToolReferences(model.id),
169
- },
170
- }
171
- : {}),
172
162
  };
173
163
  }
174
164
  function buildCustomPiModel(alias, providerId, providerConfig) {
@@ -177,11 +167,6 @@ function buildCustomPiModel(alias, providerId, providerConfig) {
177
167
  ? ["text", "image"]
178
168
  : ["text"];
179
169
  const api = apiForProviderType(providerConfig.type);
180
- const compat = providerConfig.type === "kimi"
181
- ? { deferredToolsMode: "kimi" }
182
- : providerConfig.type === "anthropic"
183
- ? { supportsToolReferences: defaultAnthropicToolReferences(alias.model) }
184
- : undefined;
185
170
  return {
186
171
  id: alias.model,
187
172
  name: alias.displayName ?? alias.model,
@@ -198,7 +183,6 @@ function buildCustomPiModel(alias, providerId, providerConfig) {
198
183
  ...(providerConfig.customHeaders !== undefined
199
184
  ? { headers: providerConfig.customHeaders }
200
185
  : {}),
201
- ...(compat !== undefined ? { compat } : {}),
202
186
  };
203
187
  }
204
188
  function configuredAuth(providerId, config, base, resolveApiKey) {
@@ -328,17 +312,5 @@ function apiForProviderType(type) {
328
312
  return "google-vertex";
329
313
  }
330
314
  }
331
- function defaultAnthropicToolReferences(modelId) {
332
- if (modelId.includes("haiku"))
333
- return false;
334
- const version = modelId.match(/^claude-(?:opus|sonnet|fable)-(\d+)(?:-(\d+))?(?:-|$)/);
335
- if (version === null)
336
- return false;
337
- const major = Number(version[1]);
338
- const minor = version[2] !== undefined && version[2].length < 8
339
- ? Number(version[2])
340
- : 0;
341
- return major > 4 || (major === 4 && minor >= 5);
342
- }
343
315
  export { UNKNOWN_CAPABILITY };
344
316
  //# sourceMappingURL=provider-manager.js.map
@@ -137,7 +137,13 @@ export declare const ThinkingConfigSchema: z.ZodObject<{
137
137
  high: "high";
138
138
  }>>;
139
139
  }, z.core.$strip>;
140
- export declare const McpServerConfigSchema: z.ZodPipe<z.ZodObject<{
140
+ export declare const McpOAuthClientConfigSchema: z.ZodObject<{
141
+ clientId: z.ZodString;
142
+ clientSecret: z.ZodOptional<z.ZodString>;
143
+ callbackPort: z.ZodOptional<z.ZodNumber>;
144
+ callbackUrl: z.ZodOptional<z.ZodString>;
145
+ }, z.core.$strip>;
146
+ export declare const McpServerConfigSchema: z.ZodPreprocess<z.ZodPipe<z.ZodObject<{
141
147
  type: z.ZodOptional<z.ZodEnum<{
142
148
  stdio: "stdio";
143
149
  http: "http";
@@ -160,6 +166,13 @@ export declare const McpServerConfigSchema: z.ZodPipe<z.ZodObject<{
160
166
  bearerTokenEnvVar: z.ZodOptional<z.ZodString>;
161
167
  keepAliveIntervalMs: z.ZodOptional<z.ZodNumber>;
162
168
  keepAliveTimeoutMs: z.ZodOptional<z.ZodNumber>;
169
+ oauth: z.ZodOptional<z.ZodObject<{
170
+ clientId: z.ZodString;
171
+ clientSecret: z.ZodOptional<z.ZodString>;
172
+ callbackPort: z.ZodOptional<z.ZodNumber>;
173
+ callbackUrl: z.ZodOptional<z.ZodString>;
174
+ }, z.core.$strip>>;
175
+ scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
163
176
  }, z.core.$strip>, z.ZodTransform<{
164
177
  transport: "stdio" | "http";
165
178
  command?: string | undefined;
@@ -176,6 +189,13 @@ export declare const McpServerConfigSchema: z.ZodPipe<z.ZodObject<{
176
189
  bearerTokenEnvVar?: string | undefined;
177
190
  keepAliveIntervalMs?: number | undefined;
178
191
  keepAliveTimeoutMs?: number | undefined;
192
+ oauth?: {
193
+ clientId: string;
194
+ clientSecret?: string | undefined;
195
+ callbackPort?: number | undefined;
196
+ callbackUrl?: string | undefined;
197
+ } | undefined;
198
+ scopes?: string[] | undefined;
179
199
  }, {
180
200
  type?: "stdio" | "http" | undefined;
181
201
  transport?: "stdio" | "http" | undefined;
@@ -193,7 +213,14 @@ export declare const McpServerConfigSchema: z.ZodPipe<z.ZodObject<{
193
213
  bearerTokenEnvVar?: string | undefined;
194
214
  keepAliveIntervalMs?: number | undefined;
195
215
  keepAliveTimeoutMs?: number | undefined;
196
- }>>;
216
+ oauth?: {
217
+ clientId: string;
218
+ clientSecret?: string | undefined;
219
+ callbackPort?: number | undefined;
220
+ callbackUrl?: string | undefined;
221
+ } | undefined;
222
+ scopes?: string[] | undefined;
223
+ }>>>;
197
224
  export declare const HookDefConfigSchema: z.ZodObject<{
198
225
  event: z.ZodString;
199
226
  matcher: z.ZodOptional<z.ZodString>;
@@ -297,7 +324,7 @@ export declare const AgentFrameworkConfigSchema: z.ZodObject<{
297
324
  high: "high";
298
325
  }>>;
299
326
  }, z.core.$strip>>;
300
- mcpServers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodPipe<z.ZodObject<{
327
+ mcpServers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodPreprocess<z.ZodPipe<z.ZodObject<{
301
328
  type: z.ZodOptional<z.ZodEnum<{
302
329
  stdio: "stdio";
303
330
  http: "http";
@@ -320,6 +347,13 @@ export declare const AgentFrameworkConfigSchema: z.ZodObject<{
320
347
  bearerTokenEnvVar: z.ZodOptional<z.ZodString>;
321
348
  keepAliveIntervalMs: z.ZodOptional<z.ZodNumber>;
322
349
  keepAliveTimeoutMs: z.ZodOptional<z.ZodNumber>;
350
+ oauth: z.ZodOptional<z.ZodObject<{
351
+ clientId: z.ZodString;
352
+ clientSecret: z.ZodOptional<z.ZodString>;
353
+ callbackPort: z.ZodOptional<z.ZodNumber>;
354
+ callbackUrl: z.ZodOptional<z.ZodString>;
355
+ }, z.core.$strip>>;
356
+ scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
323
357
  }, z.core.$strip>, z.ZodTransform<{
324
358
  transport: "stdio" | "http";
325
359
  command?: string | undefined;
@@ -336,6 +370,13 @@ export declare const AgentFrameworkConfigSchema: z.ZodObject<{
336
370
  bearerTokenEnvVar?: string | undefined;
337
371
  keepAliveIntervalMs?: number | undefined;
338
372
  keepAliveTimeoutMs?: number | undefined;
373
+ oauth?: {
374
+ clientId: string;
375
+ clientSecret?: string | undefined;
376
+ callbackPort?: number | undefined;
377
+ callbackUrl?: string | undefined;
378
+ } | undefined;
379
+ scopes?: string[] | undefined;
339
380
  }, {
340
381
  type?: "stdio" | "http" | undefined;
341
382
  transport?: "stdio" | "http" | undefined;
@@ -353,7 +394,14 @@ export declare const AgentFrameworkConfigSchema: z.ZodObject<{
353
394
  bearerTokenEnvVar?: string | undefined;
354
395
  keepAliveIntervalMs?: number | undefined;
355
396
  keepAliveTimeoutMs?: number | undefined;
356
- }>>>>;
397
+ oauth?: {
398
+ clientId: string;
399
+ clientSecret?: string | undefined;
400
+ callbackPort?: number | undefined;
401
+ callbackUrl?: string | undefined;
402
+ } | undefined;
403
+ scopes?: string[] | undefined;
404
+ }>>>>>;
357
405
  hooks: z.ZodDefault<z.ZodArray<z.ZodObject<{
358
406
  event: z.ZodString;
359
407
  matcher: z.ZodOptional<z.ZodString>;
@@ -382,6 +430,7 @@ export type PermissionConfig = z.infer<typeof PermissionConfigSchema>;
382
430
  export type LoopControl = z.infer<typeof LoopControlSchema>;
383
431
  export type ThinkingConfig = z.infer<typeof ThinkingConfigSchema>;
384
432
  export type McpServerConfig = z.infer<typeof McpServerConfigSchema>;
433
+ export type McpOAuthClientConfig = z.infer<typeof McpOAuthClientConfigSchema>;
385
434
  export type HookDefConfig = z.infer<typeof HookDefConfigSchema>;
386
435
  export type PluginRef = z.infer<typeof PluginRefSchema>;
387
436
  export type AgentFrameworkConfig = z.infer<typeof AgentFrameworkConfigSchema>;
@@ -68,7 +68,55 @@ export const ThinkingConfigSchema = z.object({
68
68
  mode: z.enum(["auto", "on", "off"]),
69
69
  effort: z.enum(["low", "medium", "high"]).optional(),
70
70
  });
71
- export const McpServerConfigSchema = z.object({
71
+ // A pre-registered OAuth client for an MCP server (Codex `.mcp.json` `oauth` block). When set, the
72
+ // login flow uses this client instead of dynamic client registration — for providers that don't
73
+ // support DCR (GitHub, Slack) and publish a public client for local agents.
74
+ export const McpOAuthClientConfigSchema = z.object({
75
+ clientId: z.string().min(1),
76
+ clientSecret: z.string().min(1).optional(),
77
+ // Fixed loopback port for the callback listener (the provider registered it). Random when unset.
78
+ callbackPort: z.number().int().min(1).max(65535).optional(),
79
+ // Exact redirect URI the provider registered; its port and path drive the callback listener.
80
+ callbackUrl: z.string().url().optional(),
81
+ });
82
+ // Codex writes `.mcp.json` in snake_case (`bearer_token_env_var`, `oauth.client_id`, …). Rename
83
+ // those keys to the camelCase config spelling before validation so a plugin's server config keeps
84
+ // them instead of having zod strip them as unknown keys.
85
+ const MCP_SNAKE_CASE_KEYS = {
86
+ bearer_token_env_var: "bearerTokenEnvVar",
87
+ allowed_tools: "allowedTools",
88
+ blocked_tools: "blockedTools",
89
+ startup_timeout_ms: "startupTimeoutMs",
90
+ tool_timeout_ms: "toolTimeoutMs",
91
+ };
92
+ const MCP_OAUTH_SNAKE_CASE_KEYS = {
93
+ client_id: "clientId",
94
+ client_secret: "clientSecret",
95
+ callback_port: "callbackPort",
96
+ callback_url: "callbackUrl",
97
+ };
98
+ function renameKeys(value, keys) {
99
+ const out = {};
100
+ for (const [key, v] of Object.entries(value)) {
101
+ const renamed = keys[key];
102
+ // An explicit camelCase key wins over its snake_case twin.
103
+ if (renamed !== undefined && renamed in value)
104
+ continue;
105
+ out[renamed ?? key] = v;
106
+ }
107
+ return out;
108
+ }
109
+ function normalizeMcpServerKeys(value) {
110
+ if (typeof value !== "object" || value === null || Array.isArray(value))
111
+ return value;
112
+ const out = renameKeys(value, MCP_SNAKE_CASE_KEYS);
113
+ const oauth = out["oauth"];
114
+ if (typeof oauth === "object" && oauth !== null && !Array.isArray(oauth)) {
115
+ out["oauth"] = renameKeys(oauth, MCP_OAUTH_SNAKE_CASE_KEYS);
116
+ }
117
+ return out;
118
+ }
119
+ const McpServerConfigObjectSchema = z.object({
72
120
  // spelling. Accept both, but normalise output to `transport`.
73
121
  type: z.enum(["stdio", "http"]).optional(),
74
122
  transport: z.enum(["stdio", "http"]).optional(),
@@ -87,6 +135,9 @@ export const McpServerConfigSchema = z.object({
87
135
  bearerTokenEnvVar: z.string().min(1).optional(),
88
136
  keepAliveIntervalMs: z.number().int().min(1).optional(),
89
137
  keepAliveTimeoutMs: z.number().int().min(1).optional(),
138
+ oauth: McpOAuthClientConfigSchema.optional(),
139
+ // OAuth scopes to request. Overrides what the server's protected-resource metadata advertises.
140
+ scopes: z.array(z.string().min(1)).optional(),
90
141
  }).superRefine((value, ctx) => {
91
142
  if (value.type !== undefined && value.transport !== undefined && value.type !== value.transport) {
92
143
  ctx.addIssue({
@@ -99,6 +150,7 @@ export const McpServerConfigSchema = z.object({
99
150
  ...rest,
100
151
  transport: transport ?? type ?? "stdio",
101
152
  }));
153
+ export const McpServerConfigSchema = z.preprocess(normalizeMcpServerKeys, McpServerConfigObjectSchema);
102
154
  export const HookDefConfigSchema = z.object({
103
155
  event: z.string(),
104
156
  matcher: z.string().optional(),