operon-agents-core 0.1.0-alpha.33 → 0.1.0-alpha.35

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.
@@ -51,6 +51,8 @@ export interface BuildAgentOptions {
51
51
  * Only invoked when a `tools` registry was provided. Default: silent (unchanged behavior).
52
52
  */
53
53
  readonly onUnknownTool?: (toolName: string) => void;
54
+ /** Tools the agent gets on top of the ones the profile picks. A name the profile already uses throws. */
55
+ readonly extraTools?: readonly Tool[];
54
56
  /** Force the built agent's model, overriding the profile's `model`. Omit to keep the profile's ref
55
57
  * (or inherit the session model when the profile declares none). */
56
58
  readonly model?: string | ChatModel;
@@ -148,6 +148,12 @@ export async function buildAgentFromProfile(profile, options = {}) {
148
148
  else if (options.tools !== undefined)
149
149
  options.onUnknownTool?.(name);
150
150
  }
151
+ for (const tool of options.extraTools ?? []) {
152
+ if (toolset.some((own) => own.schema.name === tool.schema.name)) {
153
+ throw new Error(`extra tool "${tool.schema.name}" has the name of a tool the "${profile.name}" profile already uses`);
154
+ }
155
+ toolset.push(tool);
156
+ }
151
157
  const model = options.model ??
152
158
  (profile.model !== undefined && options.resolveModel !== undefined ? await options.resolveModel(profile.model) : undefined);
153
159
  const roleAdditional = options.roleAdditional;
@@ -61,6 +61,12 @@ export interface RunnerConfig<TContext = unknown> {
61
61
  * `Agent` tool is untouched — only `Workflow` is withheld.
62
62
  */
63
63
  readonly workflowTool?: boolean;
64
+ /**
65
+ * Tools no run offers, by name, wherever they come from (the agent's own, a capability's, an MCP
66
+ * server's, `Agent`/`Workflow`). Left out of the request and of what a program can call, so a
67
+ * call to one fails as an unknown tool. Subagents inherit it.
68
+ */
69
+ readonly disabledTools?: readonly string[];
64
70
  }
65
71
  export type AgentInput = string | Message[];
66
72
  /**
@@ -141,6 +147,8 @@ export interface RunOptions<TContext = unknown> {
141
147
  readonly maxConcurrentSubagents?: number;
142
148
  /** Replaces `RunnerConfig.workflowTool` for this run. */
143
149
  readonly workflowTool?: boolean;
150
+ /** Replaces `RunnerConfig.disabledTools` for this run. */
151
+ readonly disabledTools?: readonly string[];
144
152
  }
145
153
  /**
146
154
  * A run's runtime: the shared environment (session/store/environment/permission/…, one per
@@ -171,6 +179,8 @@ export interface RunState<TContext> {
171
179
  readonly maxConcurrentSubagents?: number;
172
180
  /** False when the host withholds the builtin `Workflow` tool (see RunnerConfig). */
173
181
  readonly workflowTool?: boolean;
182
+ /** Tools this run never offers (see RunnerConfig). */
183
+ readonly disabledTools?: readonly string[];
174
184
  readonly permission: PermissionManager;
175
185
  readonly capabilities: AssembledCapabilities;
176
186
  readonly steer: SteerBus;
@@ -533,6 +533,7 @@ export class Runner {
533
533
  subagentProvider: opts?.subagentProvider === null ? undefined : opts?.subagentProvider ?? this.config.subagentProvider,
534
534
  ...(maxConcurrentSubagents !== undefined ? { maxConcurrentSubagents } : {}),
535
535
  workflowTool: opts?.workflowTool ?? this.config.workflowTool,
536
+ disabledTools: opts?.disabledTools ?? this.config.disabledTools,
536
537
  permission,
537
538
  capabilities,
538
539
  steer: session.steer,
@@ -9,7 +9,9 @@ export async function buildRunTools(active, state, runAgent, model) {
9
9
  // Capability (MCP) tools are the deferred-loading candidates. When the agent
10
10
  // opts in, they stay executable but are omitted from the model-facing schema
11
11
  // projection until a SearchTool result adds their names to the transcript.
12
- const rawCapTools = await state.capabilities.listTools();
12
+ // A disabled tool is not even a deferred-loading candidate: SearchTool must not turn it up.
13
+ const disabled = new Set(state.disabledTools ?? []);
14
+ const rawCapTools = (await state.capabilities.listTools()).filter((tool) => !disabled.has(tool.schema.name));
13
15
  // A tagged (dynamically contributed) tool loses a name clash and says so; untagged tools are
14
16
  // trusted contributors and keep theirs. Between two tagged claimants the first one survives,
15
17
  // so a clash never makes the name vanish entirely. See `tagToolSource`.
@@ -59,17 +61,21 @@ export async function buildRunTools(active, state, runAgent, model) {
59
61
  return finish(state, tools, deferredToolNames, deferEnabled);
60
62
  }
61
63
  /**
62
- * Last stop before the turn: let capabilities narrow the complete registry (the extension
63
- * runtime's `setActiveTools` rides this). Filtering happens AFTER assembly so a filter sees
64
- * handoff and subagent tools too, and the deferred-name set is pruned to whatever survived.
64
+ * Last stop before the turn: drop the run's disabled tools, then let capabilities narrow the
65
+ * complete registry (the extension runtime's `setActiveTools` rides this). Filtering happens AFTER
66
+ * assembly so it sees handoff and subagent tools too, and the deferred-name set is pruned to
67
+ * whatever survived. What is dropped here is gone for the turn: not in the request, not in what a
68
+ * program can call, not executable.
65
69
  */
66
- function finish(state, tools, deferredToolNames, deferEnabled) {
70
+ function finish(state, assembled, deferredToolNames, deferEnabled) {
71
+ const disabled = state.disabledTools?.length ? new Set(state.disabledTools) : undefined;
72
+ const tools = disabled ? assembled.filter((tool) => !disabled.has(tool.schema.name)) : assembled;
67
73
  const filtered = state.capabilities.applyToolFilters(tools, {
68
74
  address: state.address,
69
75
  isRootAgent: state.address === DEFAULT_ADDRESS,
70
76
  });
71
77
  const enabled = deferEnabled && filtered.some((tool) => tool.schema.name === "SearchTool");
72
- if (filtered === tools)
78
+ if (filtered === assembled)
73
79
  return { tools, deferredToolNames, deferEnabled: enabled };
74
80
  const surviving = new Set(filtered.map((tool) => tool.schema.name));
75
81
  return {
@@ -23,6 +23,7 @@ function mergeOne(base, layer) {
23
23
  model: layer.model ?? base.model,
24
24
  agent: layer.agent ?? base.agent,
25
25
  tools: layer.tools ?? base.tools,
26
+ disabledTools: layer.disabledTools ?? base.disabledTools,
26
27
  appendSystemPrompt: layer.appendSystemPrompt ?? base.appendSystemPrompt,
27
28
  extensions: layer.extensions !== undefined || base.extensions !== undefined ? { ...base.extensions, ...layer.extensions } : undefined,
28
29
  skills: layer.skills ?? base.skills,
@@ -232,6 +232,7 @@ export declare const AgentFrameworkConfigSchema: z.ZodObject<{
232
232
  model: z.ZodOptional<z.ZodString>;
233
233
  agent: z.ZodOptional<z.ZodString>;
234
234
  tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
235
+ disabledTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
235
236
  appendSystemPrompt: z.ZodOptional<z.ZodString>;
236
237
  extensions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
237
238
  skills: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodObject<{
@@ -173,6 +173,8 @@ export const AgentFrameworkConfigSchema = z.object({
173
173
  agent: z.string().min(1).optional(),
174
174
  /** Names of the registered tools the default agent may draw on by default (see `SessionConfig.tools`). */
175
175
  tools: z.array(z.string().min(1)).optional(),
176
+ /** Tools sessions never offer by default (see `SessionConfig.disabledTools`). */
177
+ disabledTools: z.array(z.string().min(1)).optional(),
176
178
  appendSystemPrompt: z.string().optional(),
177
179
  /** Per-extension session parameters by extension id; `false` skips that extension. */
178
180
  extensions: z.record(z.string(), z.unknown()).optional(),
@@ -148,6 +148,7 @@ export declare const SessionConfigSchema: z.ZodObject<{
148
148
  thinking: z.ZodOptional<z.ZodString>;
149
149
  agent: z.ZodOptional<z.ZodString>;
150
150
  tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
151
+ disabledTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
151
152
  appendSystemPrompt: z.ZodOptional<z.ZodString>;
152
153
  mcp: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodObject<{
153
154
  servers: z.ZodRecord<z.ZodString, z.ZodPreprocess<z.ZodPipe<z.ZodObject<{
@@ -308,7 +309,7 @@ export interface HarnessConfig {
308
309
  export declare function parseSessionConfig(input: unknown, where?: string): SessionConfig;
309
310
  /**
310
311
  * The configuration a session runs on: `explicit` over `defaults`. A field the session gives wins
311
- * whole — collections (`tools`, `hooks`, `mcp.servers`, `permission.rules`) are replaced, never
312
+ * whole — collections (`tools`, `disabledTools`, `hooks`, `mcp.servers`, `permission.rules`) are replaced, never
312
313
  * concatenated. Three sections are settings rather than collections and are overridden one key at a
313
314
  * time: `permission` (`mode` and `rules` separately), `limits`, and `extensions` (per extension id).
314
315
  */
@@ -54,6 +54,11 @@ export const SessionConfigSchema = z.strictObject({
54
54
  * uses by name and those names resolve against this set, so naming fewer narrows the agent; a
55
55
  * tool the profile does not list is not added by naming it here. */
56
56
  tools: z.array(z.string().min(1)).optional(),
57
+ /** Tools this session never offers, by name, wherever they come from: built-in, a capability's
58
+ * (`CronCreate`, `Skill`…), an MCP server's (`mcp__server__tool`), `Agent`/`Workflow`. A disabled
59
+ * tool is left out of every request and cannot be called, from a program either; the permission
60
+ * mode does not bring it back. Applies to the session's subagents too. */
61
+ disabledTools: z.array(z.string().min(1)).optional(),
57
62
  appendSystemPrompt: z.string().optional(),
58
63
  mcp: SessionMcpConfigSchema.optional(),
59
64
  skills: SkillsConfigSchema.optional(),
@@ -84,7 +89,7 @@ function keyed(base, over) {
84
89
  }
85
90
  /**
86
91
  * The configuration a session runs on: `explicit` over `defaults`. A field the session gives wins
87
- * whole — collections (`tools`, `hooks`, `mcp.servers`, `permission.rules`) are replaced, never
92
+ * whole — collections (`tools`, `disabledTools`, `hooks`, `mcp.servers`, `permission.rules`) are replaced, never
88
93
  * concatenated. Three sections are settings rather than collections and are overridden one key at a
89
94
  * time: `permission` (`mode` and `rules` separately), `limits`, and `extensions` (per extension id).
90
95
  */
@@ -178,6 +183,7 @@ export function normalizeHarnessConfig(raw) {
178
183
  model: file.model,
179
184
  agent: file.agent,
180
185
  tools: file.tools,
186
+ disabledTools: file.disabledTools,
181
187
  appendSystemPrompt: file.appendSystemPrompt,
182
188
  thinking: thinkingLevelOf(file.thinking),
183
189
  mcp: Object.keys(file.mcpServers).length > 0 ? { servers: file.mcpServers } : undefined,
@@ -69,6 +69,8 @@ export interface ServerFromConfigOptions {
69
69
  readonly transport?: MCPTransport;
70
70
  /** A provider's answer for this connect. Takes the place of the OAuth service. */
71
71
  readonly credential?: McpCredential;
72
+ /** The workspace directories the server is told about (MCP `roots`). See {@link McpServersCapabilityOptions.roots}. */
73
+ readonly roots?: readonly string[];
72
74
  }
73
75
  export declare function serverFromConfig(name: string, rawConfig: McpServerConfig, opts?: ServerFromConfigOptions): TransportMCPServer;
74
76
  /** The OAuth client/scopes a server config pins (Codex `.mcp.json` `oauth` / `scopes`). */
@@ -85,6 +87,14 @@ export interface McpServersCapabilityOptions {
85
87
  readonly allowedTransports?: readonly McpTransportKind[];
86
88
  readonly cacheToolsList?: boolean;
87
89
  readonly transportFactory?: McpTransportFactory;
90
+ /**
91
+ * The workspace these servers serve, as absolute directories. Each server is told about them
92
+ * through MCP `roots` (the client declares the capability and answers `roots/list`), and an
93
+ * stdio server with no `cwd` of its own is started in the first one. Omitted: no `roots`
94
+ * capability, and an stdio server inherits the host's cwd — right for a process-wide set that
95
+ * serves every directory, wrong for one bound to a workspace.
96
+ */
97
+ readonly roots?: readonly string[];
88
98
  readonly reconnectPolicy?: ReconnectPolicy;
89
99
  readonly keepAlive?: KeepAlivePolicy;
90
100
  readonly timer?: McpTimer;
@@ -88,7 +88,7 @@ export function serverFromConfig(name, rawConfig, opts = {}) {
88
88
  const { config, error } = normalizeServerConfig(name, rawConfig);
89
89
  if (error !== undefined)
90
90
  throw new Error(error);
91
- const transport = opts.transport ?? transportFromConfig(name, config, opts.oauthService, opts.credential);
91
+ const transport = opts.transport ?? transportFromConfig(name, config, opts.oauthService, opts.credential, opts.roots);
92
92
  const filter = staticFilterFromConfig(config);
93
93
  return new TransportMCPServer({
94
94
  name,
@@ -108,17 +108,22 @@ function staticFilterFromConfig(config) {
108
108
  ...(blocked !== undefined ? { blockedToolNames: blocked } : {}),
109
109
  };
110
110
  }
111
- function transportFromConfig(name, config, oauthService, credential) {
111
+ function transportFromConfig(name, config, oauthService, credential, roots) {
112
112
  if (config.transport === "stdio") {
113
113
  if (config.command === undefined)
114
114
  throw new Error(`MCP server "${name}": stdio transport requires "command".`);
115
+ // A server with no cwd of its own runs in the workspace: it resolves a relative path the
116
+ // model hands it against its process cwd, and the host's cwd (`/` for an app launched from
117
+ // the Finder) is no place to write `test-results/shot.png` to.
118
+ const cwd = config.cwd ?? roots?.[0];
115
119
  return mcpStdioTransport({
116
120
  name,
117
121
  command: config.command,
118
122
  ...(config.args !== undefined ? { args: config.args } : {}),
119
123
  ...(config.env !== undefined ? { env: config.env } : {}),
120
- ...(config.cwd !== undefined ? { cwd: config.cwd } : {}),
124
+ ...(cwd !== undefined ? { cwd } : {}),
121
125
  ...(config.toolTimeoutMs !== undefined ? { toolTimeoutMs: config.toolTimeoutMs } : {}),
126
+ ...(roots !== undefined ? { roots } : {}),
122
127
  });
123
128
  }
124
129
  if (config.url === undefined)
@@ -132,6 +137,7 @@ function transportFromConfig(name, config, oauthService, credential) {
132
137
  ...(config.bearerTokenEnvVar !== undefined ? { bearerTokenEnvVar: config.bearerTokenEnvVar } : {}),
133
138
  ...(config.toolTimeoutMs !== undefined ? { toolTimeoutMs: config.toolTimeoutMs } : {}),
134
139
  ...(oauthProvider !== undefined ? { oauthProvider } : {}),
140
+ ...(roots !== undefined ? { roots } : {}),
135
141
  });
136
142
  }
137
143
  function resolveOAuthProvider(name, config, oauthService) {
@@ -176,6 +182,7 @@ class McpServerController {
176
182
  credentials;
177
183
  cacheToolsList;
178
184
  transportFactory;
185
+ roots;
179
186
  onStatusChange;
180
187
  reconnectPolicy;
181
188
  keepAlivePolicy;
@@ -197,6 +204,7 @@ class McpServerController {
197
204
  this.credentials = opts.credentials;
198
205
  this.cacheToolsList = opts.cacheToolsList;
199
206
  this.transportFactory = opts.transportFactory;
207
+ this.roots = opts.roots;
200
208
  this.onStatusChange = opts.onStatusChange;
201
209
  this.reconnectPolicy = opts.reconnectPolicy;
202
210
  this.keepAlivePolicy = opts.keepAlivePolicy;
@@ -259,6 +267,7 @@ class McpServerController {
259
267
  ...(this.oauthService !== undefined ? { oauthService: this.oauthService } : {}),
260
268
  cacheToolsList: this.cacheToolsList,
261
269
  ...(credential !== undefined ? { credential } : {}),
270
+ ...(this.roots !== undefined ? { roots: this.roots } : {}),
262
271
  ...(this.transportFactory !== undefined ? { transport: this.transportFactory(this.name, this.config, credential) } : {}),
263
272
  });
264
273
  const mine = server;
@@ -534,6 +543,7 @@ export function createMcpServers(configs, options = {}) {
534
543
  ...(options.credentials !== undefined ? { credentials: options.credentials } : {}),
535
544
  cacheToolsList: options.cacheToolsList ?? DEFAULT_CACHE_TOOLS,
536
545
  ...(options.transportFactory !== undefined ? { transportFactory: options.transportFactory } : {}),
546
+ ...(options.roots !== undefined ? { roots: options.roots } : {}),
537
547
  ...(options.reconnectPolicy !== undefined ? { reconnectPolicy: options.reconnectPolicy } : {}),
538
548
  ...keepAliveOptions(config, options.keepAlive),
539
549
  onStatusChange: notify,
@@ -7,6 +7,8 @@ export interface MCPStdioConfig {
7
7
  readonly env?: Record<string, string>;
8
8
  readonly cwd?: string;
9
9
  readonly toolTimeoutMs?: number;
10
+ /** Absolute directories the server may treat as the workspace (MCP `roots`). */
11
+ readonly roots?: readonly string[];
10
12
  }
11
13
  export declare function mcpStdioTransport(config: MCPStdioConfig): MCPTransport;
12
14
  export declare function mergeStdioEnv(configEnv?: Record<string, string>): Record<string, string>;
@@ -18,6 +20,8 @@ export interface MCPHttpConfig {
18
20
  readonly toolTimeoutMs?: number;
19
21
  readonly oauthProvider?: OAuthClientProvider;
20
22
  readonly envLookup?: (name: string) => string | undefined;
23
+ /** Absolute directories the server may treat as the workspace (MCP `roots`). */
24
+ readonly roots?: readonly string[];
21
25
  }
22
26
  export declare function mcpStreamableHttpTransport(config: MCPHttpConfig): MCPTransport;
23
27
  export declare function isTerminalTransportError(error: Error): boolean;
@@ -1,8 +1,21 @@
1
1
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
2
  import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
3
3
  import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
4
+ import { ListRootsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
5
+ import { basename } from "node:path";
6
+ import { pathToFileURL } from "node:url";
4
7
  const CLIENT_INFO = { name: "operon", version: "0.0.0" };
5
8
  const STDERR_BUFFER_CAPACITY = 4 * 1024;
9
+ /**
10
+ * The client side of MCP `roots`: the directories a server may treat as the workspace. A server
11
+ * that checks paths against roots (chrome-devtools-mcp writing a screenshot, a filesystem server)
12
+ * otherwise falls back to its own default — usually the OS temp directory only — so a client that
13
+ * never declares the capability gets "path is not within any of the configured workspace roots"
14
+ * for every path in the project it is working on.
15
+ */
16
+ function rootsResult(roots) {
17
+ return { roots: roots.map((dir) => ({ uri: pathToFileURL(dir).href, name: basename(dir) || dir })) };
18
+ }
6
19
  class SdkMcpTransport {
7
20
  name;
8
21
  cfg;
@@ -33,7 +46,12 @@ class SdkMcpTransport {
33
46
  const sdkTransport = this.cfg.makeSdkTransport();
34
47
  if (this.cfg.captureStderr)
35
48
  this.attachStderr(sdkTransport);
36
- const client = new Client(CLIENT_INFO, { capabilities: {} });
49
+ const roots = this.cfg.roots;
50
+ // The roots are fixed for the transport's lifetime, so `listChanged` is never sent.
51
+ const capabilities = roots !== undefined ? { roots: { listChanged: false } } : {};
52
+ const client = new Client(CLIENT_INFO, { capabilities });
53
+ if (roots !== undefined)
54
+ client.setRequestHandler(ListRootsRequestSchema, () => rootsResult(roots));
37
55
  this.client = client;
38
56
  // Hooks BEFORE the handshake so an onclose firing between handshake completion and our
39
57
  // wiring is never lost; the hooks themselves gate on `ready`.
@@ -177,6 +195,7 @@ export function mcpStdioTransport(config) {
177
195
  return new SdkMcpTransport({
178
196
  name: config.name,
179
197
  captureStderr: true,
198
+ ...(config.roots !== undefined ? { roots: config.roots } : {}),
180
199
  ...(config.toolTimeoutMs !== undefined ? { toolTimeoutMs: config.toolTimeoutMs } : {}),
181
200
  makeSdkTransport: () => new StdioClientTransport({
182
201
  command: config.command,
@@ -204,6 +223,7 @@ export function mcpStreamableHttpTransport(config) {
204
223
  name: config.name,
205
224
  captureStderr: false,
206
225
  isTerminalError: isTerminalTransportError,
226
+ ...(config.roots !== undefined ? { roots: config.roots } : {}),
207
227
  ...(config.toolTimeoutMs !== undefined ? { toolTimeoutMs: config.toolTimeoutMs } : {}),
208
228
  makeSdkTransport: () => new StreamableHTTPClientTransport(new URL(config.url), {
209
229
  ...(headers !== undefined ? { requestInit: { headers } } : {}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "operon-agents-core",
3
- "version": "0.1.0-alpha.33",
3
+ "version": "0.1.0-alpha.35",
4
4
  "description": "Internal engine for operon-agents. Prefer operon-agents for application code.",
5
5
  "type": "module",
6
6
  "engines": {