@hyperwindmill/caretaker-cli 0.20.0 → 0.21.0

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 (42) hide show
  1. package/dist/cli/mcp.js +5 -5
  2. package/dist/cli/web/mcp_bridge.d.ts +1 -1
  3. package/dist/cli/web/mcp_bridge.d.ts.map +1 -1
  4. package/dist/cli/web/mcp_bridge.js +23 -7
  5. package/dist/cli/web/scheduler/heartbeat.d.ts +2 -2
  6. package/dist/cli/web/scheduler/heartbeat.d.ts.map +1 -1
  7. package/dist/cli/web/scheduler/strategy.d.ts +3 -3
  8. package/dist/cli/web/scheduler/strategy.d.ts.map +1 -1
  9. package/dist/cli/web/scheduler/task_roles.d.ts +0 -4
  10. package/dist/cli/web/scheduler/task_roles.d.ts.map +1 -1
  11. package/dist/cli/web/scheduler/task_roles.js +12 -2
  12. package/dist/cli/web/scheduler/task_strategy.d.ts.map +1 -1
  13. package/dist/cli/web/scheduler/task_strategy.js +4 -1
  14. package/dist/cli/web/scheduler/telegram.d.ts.map +1 -1
  15. package/dist/cli/web/scheduler/telegram.js +4 -1
  16. package/dist/cli/web/server.d.ts.map +1 -1
  17. package/dist/cli/web/server.js +10 -4
  18. package/dist/harness/claude_code_runner.d.ts.map +1 -1
  19. package/dist/harness/claude_code_runner.js +5 -1
  20. package/dist/harness/tools/builtin/email_tools.d.ts +5 -0
  21. package/dist/harness/tools/builtin/email_tools.d.ts.map +1 -0
  22. package/dist/harness/tools/builtin/email_tools.js +182 -0
  23. package/dist/harness/tools/builtin/index.d.ts +2 -1
  24. package/dist/harness/tools/builtin/index.d.ts.map +1 -1
  25. package/dist/harness/tools/builtin/index.js +7 -1
  26. package/dist/harness/tools/resolve.d.ts.map +1 -1
  27. package/dist/harness/tools/resolve.js +9 -4
  28. package/dist/lib/email.d.ts +132 -0
  29. package/dist/lib/email.d.ts.map +1 -0
  30. package/dist/lib/email.js +306 -0
  31. package/dist/mcp/builtin_server.d.ts +13 -0
  32. package/dist/mcp/builtin_server.d.ts.map +1 -0
  33. package/dist/mcp/builtin_server.js +65 -0
  34. package/dist/store/json.d.ts.map +1 -1
  35. package/dist/store/json.js +6 -0
  36. package/dist/tui/agents.js +36 -14
  37. package/dist/webview/standalone.js +340 -35
  38. package/dist/webview/standalone.js.map +3 -3
  39. package/package.json +8 -3
  40. package/dist/mcp/task_server.d.ts +0 -9
  41. package/dist/mcp/task_server.d.ts.map +0 -1
  42. package/dist/mcp/task_server.js +0 -48
package/dist/cli/mcp.js CHANGED
@@ -1,12 +1,12 @@
1
- // `caretaker-cli mcp` — serve the built-in mcp__task__* tools over stdio so an
2
- // external MCP client (e.g. Claude Code) can steer caretaker's task/project
3
- // system symmetrically. No auth: the trust boundary is local process access to
1
+ // `caretaker-cli mcp` — serve the built-in mcp__task__* / mcp__email__* tools
2
+ // over stdio so an external MCP client (e.g. Claude Code) can steer caretaker's
3
+ // task/project system symmetrically and send mail through a configured account. No auth: the trust boundary is local process access to
4
4
  // CARETAKER_HOME (the caller could edit the folder DB directly). stdout carries
5
5
  // the JSON-RPC wire — never write anything else to it here.
6
6
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
7
- import { buildTaskMcpServer } from '../mcp/task_server.js';
7
+ import { buildBuiltinMcpServer } from '../mcp/builtin_server.js';
8
8
  export async function startMcpStdioServer() {
9
- const server = buildTaskMcpServer({ name: 'caretaker', version: '0.0.0' });
9
+ const server = buildBuiltinMcpServer({ name: 'caretaker', version: '0.0.0' });
10
10
  const transport = new StdioServerTransport();
11
11
  await server.connect(transport);
12
12
  // Stay alive until the client closes stdin. Resolve on transport close so
@@ -1,5 +1,5 @@
1
1
  import type { Hono } from 'hono';
2
- export declare function issueBridgeToken(): string;
2
+ export declare function issueBridgeToken(agentId?: string): string;
3
3
  export declare function revokeBridgeToken(token: string): void;
4
4
  export declare function setTaskBridgeUrl(url: string): void;
5
5
  export declare function getTaskBridgeUrl(): string | null;
@@ -1 +1 @@
1
- {"version":3,"file":"mcp_bridge.d.ts","sourceRoot":"","sources":["../../../src/cli/web/mcp_bridge.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAOjC,wBAAgB,gBAAgB,IAAI,MAAM,CAIzC;AACD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAErD;AAGD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAElD;AACD,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,IAAI,CAEhD;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,IAAI,GAAG,IAAI,CAgBlD"}
1
+ {"version":3,"file":"mcp_bridge.d.ts","sourceRoot":"","sources":["../../../src/cli/web/mcp_bridge.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AASjC,wBAAgB,gBAAgB,CAAC,OAAO,SAAK,GAAG,MAAM,CAIrD;AACD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAErD;AAGD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAElD;AACD,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,IAAI,CAEhD;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,IAAI,GAAG,IAAI,CAuBlD"}
@@ -1,17 +1,26 @@
1
- // Exposes the built-in mcp__task__* tools as a streamable-HTTP MCP endpoint
2
- // so claude-code agents can drive the task state machine. Token-guarded:
1
+ // Exposes the built-in mcp__task__* / mcp__email__* tools as a streamable-HTTP
2
+ // MCP endpoint so claude-code agents can drive the task state machine (and send
3
+ // mail through a configured account). Token-guarded:
3
4
  // the task heartbeat issues a per-run bearer token and revokes it after.
4
5
  // Stateless MCP (no session): a fresh Server per request. The task tools
5
6
  // are context-free (they take task_id as an argument), so no per-run
6
7
  // injection is needed.
8
+ //
9
+ // The token also carries WHO the run belongs to: the email tools scope which
10
+ // accounts an agent may see (ServiceConfig.allowedAgents), and a claude-code
11
+ // agent has no other way to identify itself — it speaks MCP over HTTP, not the
12
+ // in-process ToolContext. Without this the whole per-agent boundary would be
13
+ // bypassed on exactly the surface that matters most, the autonomous task run.
7
14
  import { randomBytes } from 'node:crypto';
8
15
  import { RESPONSE_ALREADY_SENT } from '@hono/node-server/utils/response';
9
16
  import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
10
- import { buildTaskMcpServer } from '../../mcp/task_server.js';
11
- const activeTokens = new Set();
12
- export function issueBridgeToken() {
17
+ import { buildBuiltinMcpServer } from '../../mcp/builtin_server.js';
18
+ import { loadAgents } from '../../store/json.js';
19
+ /** token → the agent id the run belongs to ('' when the caller didn't say). */
20
+ const activeTokens = new Map();
21
+ export function issueBridgeToken(agentId = '') {
13
22
  const token = randomBytes(24).toString('hex');
14
- activeTokens.add(token);
23
+ activeTokens.set(token, agentId);
15
24
  return token;
16
25
  }
17
26
  export function revokeBridgeToken(token) {
@@ -31,7 +40,14 @@ export function registerTaskBridge(app) {
31
40
  if (!token || !activeTokens.has(token))
32
41
  return c.json({ error: 'unauthorized' }, 401);
33
42
  const body = await c.req.json().catch(() => null);
34
- const server = buildTaskMcpServer();
43
+ // Resolve the run's agent so ctx.callerAgent is set for the tools that scope
44
+ // by it. A token issued without an agent id (or pointing at a since-deleted
45
+ // agent) leaves it unset, which the email tools treat as an unscoped caller.
46
+ const agentId = activeTokens.get(token) ?? '';
47
+ const callerAgent = agentId
48
+ ? (await loadAgents().catch(() => [])).find((a) => a.id === agentId)
49
+ : undefined;
50
+ const server = buildBuiltinMcpServer(undefined, { callerAgent });
35
51
  const transport = new StreamableHTTPServerTransport({
36
52
  sessionIdGenerator: undefined, // stateless
37
53
  enableJsonResponse: true, // plain JSON responses, no SSE needed
@@ -1,4 +1,4 @@
1
- import type { ScheduledTaskConfig } from '../../../types.js';
1
+ import type { ServiceConfig } from '../../../types.js';
2
2
  import type { SchedulerStrategy } from './strategy.js';
3
3
  /**
4
4
  * Parses and evaluates a cron expression string against a given Date.
@@ -11,6 +11,6 @@ export declare function matchesCron(cronStr: string, date: Date): boolean;
11
11
  * Runs completely in background, automatically approving tool runs.
12
12
  * Guards against concurrent execution: if the task is already running, skips.
13
13
  */
14
- export declare function executeTaskRun(task: ScheduledTaskConfig): Promise<void>;
14
+ export declare function executeTaskRun(task: ServiceConfig): Promise<void>;
15
15
  export declare const HeartbeatStrategy: SchedulerStrategy;
16
16
  //# sourceMappingURL=heartbeat.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"heartbeat.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/heartbeat.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAG7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CA2DhE;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgH7E;AAID,eAAO,MAAM,iBAAiB,EAAE,iBAgB/B,CAAC"}
1
+ {"version":3,"file":"heartbeat.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/heartbeat.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CA2DhE;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAgHvE;AAID,eAAO,MAAM,iBAAiB,EAAE,iBAgB/B,CAAC"}
@@ -1,6 +1,6 @@
1
- import type { ScheduledTaskConfig } from '../../../types.js';
1
+ import type { ServiceConfig } from '../../../types.js';
2
2
  export interface SchedulerStrategy {
3
- type: ScheduledTaskConfig['type'];
4
- tick(task: ScheduledTaskConfig, now: Date): Promise<void>;
3
+ type: ServiceConfig['type'];
4
+ tick(task: ServiceConfig, now: Date): Promise<void>;
5
5
  }
6
6
  //# sourceMappingURL=strategy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE7D,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAClC,IAAI,CAAC,IAAI,EAAE,mBAAmB,EAAE,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3D"}
1
+ {"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC5B,IAAI,CAAC,IAAI,EAAE,aAAa,EAAE,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrD"}
@@ -22,10 +22,6 @@ export declare function resolveSddEnabled(task: Pick<Task, 'sddEnabled'>, projec
22
22
  * message stream, like review rounds — no stored phase counter.
23
23
  */
24
24
  export declare function activationStatus(task: Task, project: ProjectConfig | undefined): Promise<'planning' | 'active'>;
25
- /** Builtins the planner must not have: everything that mutates the workspace.
26
- * bash is stripped too — it cannot be made read-only, and the planner keeps
27
- * read_file/glob/grep for exploration. Same post-filter mechanism as the
28
- * reviewer's mcp__task__* strip in task_review.ts. */
29
25
  export declare const PLANNER_TOOL_DENYLIST: Set<string>;
30
26
  export declare function filterPlannerTools(tools: Tool[], sdd?: boolean): Tool[];
31
27
  //# sourceMappingURL=task_roles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"task_roles.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/task_roles.ts"],"names":[],"mappings":"AAGA,OAAO,EAAY,IAAI,EAAe,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AAE5D,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,WAAW,GAAG,UAAU,CAAC;AAO5D,eAAO,MAAM,mBAAmB,MAAM,CAAC;AACvC,eAAO,MAAM,+BAA+B,QAAU,CAAC;AAEvD,sFAAsF;AACtF,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,eAAe,CAAC,EACjC,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,eAAe,CAAC,GAAG,IAAI,GAAG,SAAS,EAChE,YAAY,EAAE,OAAO,GACpB,MAAM,CAIR;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,EAC9B,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,aAAa,CAAC,GAAG,IAAI,GAAG,SAAS,GAC7D,MAAM,GAAG,IAAI,CAGf;AAED,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,aAAa,GAAG,SAAS,EAClC,MAAM,EAAE,WAAW,EAAE,GACpB,WAAW,GAAG,SAAS,CAOzB;AAED,wBAAgB,sBAAsB,CACp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,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,UAAQ,GAAG,IAAI,EAAE,CAOrE"}
@@ -58,7 +58,17 @@ export async function activationStatus(task, project) {
58
58
  * bash is stripped too — it cannot be made read-only, and the planner keeps
59
59
  * read_file/glob/grep for exploration. Same post-filter mechanism as the
60
60
  * reviewer's mcp__task__* strip in task_review.ts. */
61
- export const PLANNER_TOOL_DENYLIST = new Set(['write', 'edit', 'multiedit', 'bash']);
61
+ /** Denied to the planner in every mode, SDD included: `bash` is the real
62
+ * implementation brake, and sending mail is an *external* side effect — worse
63
+ * than an unreviewed write, which is what the read-only planner exists to
64
+ * prevent. Listing the accounts stays allowed; a plan may name one. */
65
+ const PLANNER_ALWAYS_DENIED = new Set(['bash', 'mcp__email__email_send']);
66
+ export const PLANNER_TOOL_DENYLIST = new Set([
67
+ 'write',
68
+ 'edit',
69
+ 'multiedit',
70
+ ...PLANNER_ALWAYS_DENIED,
71
+ ]);
62
72
  /** Tools the SDD wrapper applies to: workspace writers that take a `path` arg. */
63
73
  const SDD_WRAPPED_TOOLS = new Set(['write', 'edit', 'multiedit']);
64
74
  /** Wrap a writing tool so it only accepts markdown targets. Everything else
@@ -83,6 +93,6 @@ export function filterPlannerTools(tools, sdd = false) {
83
93
  // SDD mode: bash stays out (the actual implementation brake); the file
84
94
  // writers survive but only for markdown targets.
85
95
  return tools
86
- .filter((t) => t.name !== 'bash')
96
+ .filter((t) => !PLANNER_ALWAYS_DENIED.has(t.name))
87
97
  .map((t) => (SDD_WRAPPED_TOOLS.has(t.name) ? markdownOnly(t) : t));
88
98
  }
@@ -1 +1 @@
1
- {"version":3,"file":"task_strategy.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/task_strategy.ts"],"names":[],"mappings":"AAyHA,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAidnE"}
1
+ {"version":3,"file":"task_strategy.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/task_strategy.ts"],"names":[],"mappings":"AAyHA,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAodnE"}
@@ -368,7 +368,10 @@ export async function runTaskHeartbeatTick(now) {
368
368
  const runTimer = setTimeout(() => abortController.abort(), maxRunSeconds * 1000);
369
369
  if (isClaudeCode) {
370
370
  const bridgeUrl = getTaskBridgeUrl();
371
- bridgeToken = bridgeUrl ? issueBridgeToken() : undefined;
371
+ // The token carries the role-resolved agent's id: it is the only identity
372
+ // a claude-code run has on the bridge, and the email tools scope accounts
373
+ // by it (ServiceConfig.allowedAgents).
374
+ bridgeToken = bridgeUrl ? issueBridgeToken(effectiveAgent.id) : undefined;
372
375
  claudeCode = claudeCodeTaskExtras({
373
376
  planning,
374
377
  sdd,
@@ -1 +1 @@
1
- {"version":3,"file":"telegram.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/telegram.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAsBxF;AAED,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAUpF;AAiED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,SAAO,GAAG,MAAM,EAAE,CA8ClE;AAkSD,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC,CAiB3D;AAED,eAAO,MAAM,gBAAgB,EAAE,iBAK9B,CAAC"}
1
+ {"version":3,"file":"telegram.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/telegram.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAyBxF;AAED,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAUpF;AAiED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,SAAO,GAAG,MAAM,EAAE,CA8ClE;AAkSD,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC,CAiB3D;AAED,eAAO,MAAM,gBAAgB,EAAE,iBAK9B,CAAC"}
@@ -6,9 +6,12 @@ import * as harness from '../../../harness/index.js';
6
6
  import { loadAgents, loadConfig } from '../../../store/json.js';
7
7
  import { __forTesting, readSession, createSession, appendMessage, userMessage, } from '../../../session/store.js';
8
8
  import { decrypt, isEncrypted } from '../../../lib/encryption.js';
9
- import { schedulerLogsDir } from './logs.js';
9
+ import { schedulerLogsDir, ensureSchedulerLogsDir } from './logs.js';
10
10
  import { runningTasks } from './locks.js';
11
11
  export async function saveTelegramOffset(taskId, updateId) {
12
+ // The offset is committed before any run is logged, so this can be the very
13
+ // first write into scheduler-logs/ — the dir may not exist yet.
14
+ await ensureSchedulerLogsDir();
12
15
  const path = join(schedulerLogsDir(), `${taskId}.offset`);
13
16
  const tmpPath = `${path}.tmp.${process.pid}.${Date.now()}`;
14
17
  await writeFile(tmpPath, String(updateId), 'utf8');
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/cli/web/server.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;AAyClD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAgC,MAAM,gBAAgB,CAAC;AAChG,OAAO,KAAK,EAAE,eAAe,EAA0B,MAAM,mBAAmB,CAAC;AAgBjF,MAAM,WAAW,aAAa;IAC5B,OAAO,EA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B,OAAO,CAAC,UAAU,CAAkC;IACpD,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAc;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAS;gBAGjB,IAAI,EAAE;QACrB,KAAK,EAAE,WAAW,CAAC;QACnB,QAAQ,EAAE,cAAc,CAAC;QACzB,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB;IAMH,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,eAAe,IAAI,GAAG;IAIhB,KAAK,CACT,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,aAAa,EACjB,cAAc,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,EACtE,iBAAiB,CAAC,EAAE,OAAO,GAC1B,OAAO,CAAC,IAAI,CAAC;IAgFhB,KAAK,IAAI,IAAI;CAGd;AAED,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAomC3E"}
@@ -845,10 +845,16 @@ export async function startServer(port, host) {
845
845
  loadPlugins(),
846
846
  loadMcpServers(),
847
847
  ]);
848
- const availableTools = harness.tools.list()
849
- .map((t) => t.name)
850
- .filter((name) => !name.startsWith('mcp__task__'));
851
- availableTools.push('mcp__task__*');
848
+ // Collapse every builtin `mcp__<ns>__` namespace (task, email, …) into a
849
+ // single wildcard entry: the picker offers the namespace, so a namespace
850
+ // gaining a tool needs no config change. resolveAgentTools expands it.
851
+ const toolNames = harness.tools.list().map((t) => t.name);
852
+ const namespaces = [
853
+ ...new Set(toolNames.map((name) => /^mcp__[a-z]+__/.exec(name)?.[0]).filter((p) => !!p)),
854
+ ];
855
+ const availableTools = toolNames
856
+ .filter((name) => !namespaces.some((p) => name.startsWith(p)))
857
+ .concat(namespaces.map((p) => `${p}*`));
852
858
  const enrichedServers = mcpServersFile.servers.map((server) => {
853
859
  let hasMcpTokens = false;
854
860
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"claude_code_runner.d.ts","sourceRoot":"","sources":["../../src/harness/claude_code_runner.ts"],"names":[],"mappings":"AAMA,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAM3E,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAiBrE,MAAM,MAAM,mBAAmB,GAAG;IAChC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC,CAAC;IAClG,MAAM,CAAC,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACjD,CAAC;AAQF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;IACrC,KAAK,EAAE,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;IACpC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC;IAChD,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,IAAI,EA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p) {
81
81
  const allowedTools = ['Read', 'Glob', 'Grep', 'mcp__task'];
82
82
  if (p.sdd)
83
83
  allowedTools.push('Write(**/*.md)', 'Edit(**/*.md)', 'MultiEdit(**/*.md)');
84
- return { permissionMode: 'dontAsk', allowedTools, disallowedTools: ['Bash'], extraMcpServers };
84
+ // The bridge serves the email tools on the same `task` server, so the prefix
85
+ // allowlist above would reach email_send too. Deny it explicitly: the mirror
86
+ // of PLANNER_ALWAYS_DENIED on the native path (see scheduler/task_roles.ts).
87
+ const disallowedTools = ['Bash', 'mcp__task__email_send'];
88
+ return { permissionMode: 'dontAsk', allowedTools, disallowedTools, extraMcpServers };
85
89
  }
86
90
  async function buildMcpConfigFile(serverIds, extra) {
87
91
  const servers = {};
@@ -0,0 +1,5 @@
1
+ import type { Tool } from '../types.js';
2
+ export declare const emailListAccountsTool: Tool;
3
+ export declare const emailFetchTool: Tool;
4
+ export declare const emailSendTool: Tool;
5
+ //# sourceMappingURL=email_tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email_tools.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/email_tools.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,aAAa,CAAC;AAkCpD,eAAO,MAAM,qBAAqB,EAAE,IAqBnC,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IAiE5B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,IAwE3B,CAAC"}
@@ -0,0 +1,182 @@
1
+ // Agent-facing email tools. Named `mcp__email__*` so the shared builtin MCP
2
+ // server (mcp/builtin_server.ts) picks them up by prefix and serves them over
3
+ // both the stdio subcommand and the per-task HTTP bridge, exactly like the
4
+ // `mcp__task__*` set.
5
+ //
6
+ // Accounts come from the Services collection (`type: 'email'`); see lib/email.ts.
7
+ // Three boundaries, all host-side and none of them the model's choice:
8
+ // - which accounts exist at all for this agent (`allowedAgents`, resolved from
9
+ // ctx.callerAgent — a scoped account is invisible, not refused);
10
+ // - who an account may send to (`allowedRecipients`, checked before connecting);
11
+ // - whose mail it may read (`allowedSenders`, checked on the envelope pass).
12
+ import { listEmailAccounts, findAccount, matchesAllowlist, bareAddress, sendEmail, fetchInbox, canSend, canRead, clampLimit, MAX_FETCH, } from '../../../lib/email.js';
13
+ function err(msg) {
14
+ return { content: JSON.stringify({ error: msg }) };
15
+ }
16
+ /** Accept either a single address or a list of them. */
17
+ function toList(value) {
18
+ if (value === undefined || value === null || value === '')
19
+ return [];
20
+ if (typeof value === 'string') {
21
+ const items = value
22
+ .split(/[,;\n]/)
23
+ .map((s) => s.trim())
24
+ .filter(Boolean);
25
+ return items;
26
+ }
27
+ if (Array.isArray(value) && value.every((v) => typeof v === 'string')) {
28
+ return value.map((v) => v.trim()).filter(Boolean);
29
+ }
30
+ return null;
31
+ }
32
+ export const emailListAccountsTool = {
33
+ name: 'mcp__email__email_list_accounts',
34
+ description: 'List the configured email accounts. Returns each account name (use it as the `account` argument of email_send / email_fetch), its From address, whether it can send and/or be read, and its address allowlists. Passwords are never returned.',
35
+ parameters: { type: 'object', properties: {}, additionalProperties: false },
36
+ execute: async (_args, ctx) => {
37
+ const accounts = await listEmailAccounts(ctx.callerAgent?.id);
38
+ return {
39
+ content: JSON.stringify({
40
+ accounts: accounts.map((a) => ({
41
+ name: a.name,
42
+ from: a.from,
43
+ // Empty list = no restriction; say so instead of showing `[]`.
44
+ canSend: canSend(a) ? `${a.smtpHost}:${a.smtpPort}` : false,
45
+ canRead: canRead(a) ? `${a.imapHost}:${a.imapPort}` : false,
46
+ allowedRecipients: a.allowedRecipients.length ? a.allowedRecipients : 'any',
47
+ allowedSenders: a.allowedSenders.length ? a.allowedSenders : 'any',
48
+ })),
49
+ }),
50
+ };
51
+ },
52
+ };
53
+ export const emailFetchTool = {
54
+ name: 'mcp__email__email_fetch',
55
+ description: 'Read the oldest unread messages from an account inbox and mark them read, so a later run does not see them again. Messages from senders outside the account allowlist are never returned. Bodies are plain text and may be truncated; attachments are listed by name only, not downloaded.',
56
+ parameters: {
57
+ type: 'object',
58
+ properties: {
59
+ account: { type: 'string', description: 'Account name from email_list_accounts.' },
60
+ limit: {
61
+ type: 'number',
62
+ description: `How many messages to read this call. Default 10, hard maximum ${MAX_FETCH}.`,
63
+ },
64
+ unread_only: {
65
+ type: 'boolean',
66
+ description: 'Default true. Set false to re-read messages already marked read.',
67
+ },
68
+ subject: { type: 'string', description: 'Only messages whose subject contains this text.' },
69
+ mark_seen: {
70
+ type: 'boolean',
71
+ description: 'Default true. Set false to leave the messages unread — they will come back on the next call.',
72
+ },
73
+ },
74
+ required: ['account'],
75
+ },
76
+ execute: async (args, ctx) => {
77
+ const name = typeof args?.account === 'string' ? args.account : '';
78
+ if (!name.trim())
79
+ return err('account must be a non-empty string');
80
+ const accounts = await listEmailAccounts(ctx.callerAgent?.id);
81
+ const account = findAccount(accounts, name);
82
+ if (!account) {
83
+ const available = accounts.filter(canRead).map((a) => a.name);
84
+ return err(available.length
85
+ ? `Unknown email account "${name}". Readable accounts: ${available.join(', ')}`
86
+ : `Unknown email account "${name}". No account is configured for reading — an email service needs an IMAP host and must be enabled.`);
87
+ }
88
+ if (!canRead(account)) {
89
+ return err(`Account "${account.name}" has no IMAP host, so it cannot be read.`);
90
+ }
91
+ try {
92
+ const { messages, refused } = await fetchInbox(account, {
93
+ limit: clampLimit(args?.limit),
94
+ unreadOnly: args?.unread_only !== false,
95
+ subject: typeof args?.subject === 'string' ? args.subject : undefined,
96
+ markSeen: args?.mark_seen !== false,
97
+ signal: ctx.signal,
98
+ });
99
+ return {
100
+ content: JSON.stringify({
101
+ account: account.name,
102
+ count: messages.length,
103
+ // Surfaced rather than silent: "nothing new" and "3 messages you are
104
+ // not allowed to see" are different situations for the agent.
105
+ ...(refused ? { refusedBySenderAllowlist: refused } : {}),
106
+ messages,
107
+ }),
108
+ };
109
+ }
110
+ catch (e) {
111
+ return err(`IMAP fetch failed: ${e?.message ?? String(e)}`);
112
+ }
113
+ },
114
+ };
115
+ export const emailSendTool = {
116
+ name: 'mcp__email__email_send',
117
+ description: 'Send a plain-text email through one of the configured accounts. Pick the account by its name from email_list_accounts. Recipients outside the account allowlist are refused and nothing is sent.',
118
+ parameters: {
119
+ type: 'object',
120
+ properties: {
121
+ account: { type: 'string', description: 'Account name from email_list_accounts.' },
122
+ to: {
123
+ type: 'array',
124
+ items: { type: 'string' },
125
+ description: 'Recipient addresses. A single comma-separated string is also accepted.',
126
+ },
127
+ cc: { type: 'array', items: { type: 'string' } },
128
+ bcc: { type: 'array', items: { type: 'string' } },
129
+ subject: { type: 'string' },
130
+ body: { type: 'string', description: 'Plain text. No HTML, no attachments.' },
131
+ },
132
+ required: ['account', 'to', 'subject', 'body'],
133
+ },
134
+ dangerous: true,
135
+ execute: async (args, ctx) => {
136
+ const name = typeof args?.account === 'string' ? args.account : '';
137
+ if (!name.trim())
138
+ return err('account must be a non-empty string');
139
+ const subject = typeof args?.subject === 'string' ? args.subject : '';
140
+ const body = typeof args?.body === 'string' ? args.body : '';
141
+ if (!subject.trim())
142
+ return err('subject must be a non-empty string');
143
+ if (typeof args?.body !== 'string')
144
+ return err('body must be a string');
145
+ const to = toList(args?.to);
146
+ const cc = toList(args?.cc);
147
+ const bcc = toList(args?.bcc);
148
+ if (!to || !cc || !bcc)
149
+ return err('to/cc/bcc must be a string or an array of strings');
150
+ if (to.length === 0)
151
+ return err('to must contain at least one recipient');
152
+ const accounts = await listEmailAccounts(ctx.callerAgent?.id);
153
+ const account = findAccount(accounts, name);
154
+ if (!account) {
155
+ const available = accounts.filter(canSend).map((a) => a.name);
156
+ return err(available.length
157
+ ? `Unknown email account "${name}". Available: ${available.join(', ')}`
158
+ : `Unknown email account "${name}". No account is configured for sending — an email service needs an SMTP host and must be enabled.`);
159
+ }
160
+ if (!canSend(account)) {
161
+ return err(`Account "${account.name}" has no SMTP host, so it cannot send.`);
162
+ }
163
+ if (!account.from) {
164
+ return err(`Account "${account.name}" has no From address — set its From or IMAP user.`);
165
+ }
166
+ // Allowlist first, for every recipient kind: a refusal must cost no I/O and
167
+ // must never leave a partially delivered message behind.
168
+ const refused = [...to, ...cc, ...bcc].filter((r) => !matchesAllowlist(bareAddress(r), account.allowedRecipients));
169
+ if (refused.length) {
170
+ return err(`Recipient(s) not allowed by account "${account.name}": ${refused.join(', ')}. Allowed patterns: ${account.allowedRecipients.join(', ')}`);
171
+ }
172
+ try {
173
+ const messageId = await sendEmail(account, { to, cc, bcc, subject, body }, ctx.signal);
174
+ return {
175
+ content: JSON.stringify({ ok: true, messageId, from: account.from, to, cc, bcc }),
176
+ };
177
+ }
178
+ catch (e) {
179
+ return err(`SMTP send failed: ${e?.message ?? String(e)}`);
180
+ }
181
+ },
182
+ };
@@ -17,7 +17,8 @@ import { invokeAgentTool } from './invoke_agent.js';
17
17
  import { listCommandsTool } from './list_commands.js';
18
18
  import { invokeCommandTool } from './invoke_command.js';
19
19
  import { getAgentContextTool } from './get_agent_context.js';
20
+ import { emailListAccountsTool, emailSendTool, emailFetchTool } from './email_tools.js';
20
21
  import { getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool, taskUpdateDetailsTool } from './task_tools.js';
21
22
  export declare function registerBuiltins(registry: ToolRegistry): void;
22
- export { readFileTool, readDocumentTool, readImageTool, readAttachmentTool, writeTool, editTool, multieditTool, globTool, grepTool, fetchTool, bashTool, listSkillsTool, readSkillTool, listAgentsTool, invokeAgentTool, listCommandsTool, invokeCommandTool, getAgentContextTool, getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool, taskUpdateDetailsTool, };
23
+ export { readFileTool, readDocumentTool, readImageTool, readAttachmentTool, writeTool, editTool, multieditTool, globTool, grepTool, fetchTool, bashTool, listSkillsTool, readSkillTool, listAgentsTool, invokeAgentTool, listCommandsTool, invokeCommandTool, getAgentContextTool, getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool, taskUpdateDetailsTool, emailListAccountsTool, emailSendTool, emailFetchTool, };
23
24
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,cAAc,EA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,gBAAgB,EAChB,eAAe,EACf,uBAAuB,EACvB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACtB,MAAM,iBAAiB,CAAC;AAEzB,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CA0D7D;AAED,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,SAAS,EACT,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,cAAc,EACd,aAAa,EACb,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,eAAe,EACf,cAAc,EACd,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,uBAAuB,EACvB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,aAAa,EACb,cAAc,GACf,CAAC"}
@@ -19,6 +19,7 @@ import { invokeAgentTool } from './invoke_agent.js';
19
19
  import { listCommandsTool } from './list_commands.js';
20
20
  import { invokeCommandTool } from './invoke_command.js';
21
21
  import { getAgentContextTool } from './get_agent_context.js';
22
+ import { emailListAccountsTool, emailSendTool, emailFetchTool } from './email_tools.js';
22
23
  import { getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool, taskUpdateDetailsTool, } from './task_tools.js';
23
24
  export function registerBuiltins(registry) {
24
25
  // Filesystem (sandboxed to ctx.workingDir).
@@ -71,5 +72,10 @@ export function registerBuiltins(registry) {
71
72
  registry.register(taskSetAgentTool);
72
73
  registry.register(submitPlanTool);
73
74
  registry.register(taskUpdateDetailsTool);
75
+ // Email tools. Same mcp__* naming as the task tools, so the shared builtin
76
+ // MCP server exposes them over stdio and the per-task bridge alike.
77
+ registry.register(emailListAccountsTool);
78
+ registry.register(emailSendTool);
79
+ registry.register(emailFetchTool);
74
80
  }
75
- export { readFileTool, readDocumentTool, readImageTool, readAttachmentTool, writeTool, editTool, multieditTool, globTool, grepTool, fetchTool, bashTool, listSkillsTool, readSkillTool, listAgentsTool, invokeAgentTool, listCommandsTool, invokeCommandTool, getAgentContextTool, getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool, taskUpdateDetailsTool, };
81
+ export { readFileTool, readDocumentTool, readImageTool, readAttachmentTool, writeTool, editTool, multieditTool, globTool, grepTool, fetchTool, bashTool, listSkillsTool, readSkillTool, listAgentsTool, invokeAgentTool, listCommandsTool, invokeCommandTool, getAgentContextTool, getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool, taskUpdateDetailsTool, emailListAccountsTool, emailSendTool, emailFetchTool, };
@@ -1 +1 @@
1
- {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../../src/harness/tools/resolve.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAgBvC,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,YAAY,GACrB,OAAO,CAAC,IAAI,EAAE,CAAC,CA2BjB"}
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../../src/harness/tools/resolve.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAgBvC,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,YAAY,GACrB,OAAO,CAAC,IAAI,EAAE,CAAC,CA+BjB"}
@@ -37,11 +37,16 @@ function autoInclude(tools, registry, names) {
37
37
  }
38
38
  export async function resolveAgentTools(agent, registry) {
39
39
  const tools = registry.filtered(agent.allowedTools);
40
- if (agent.allowedTools.includes('mcp__task__*')) {
41
- const taskTools = registry.list().filter((t) => t.name.startsWith('mcp__task__'));
40
+ // Namespace wildcards: `mcp__task__*`, `mcp__email__*`, … pull in every
41
+ // builtin carrying that prefix. The picker offers the wildcard, not the
42
+ // individual tools, so a namespace gaining a tool needs no config change.
43
+ for (const entry of agent.allowedTools) {
44
+ const ns = /^(mcp__[a-z]+__)\*$/.exec(entry);
45
+ if (!ns)
46
+ continue;
42
47
  const have = new Set(tools.map((t) => t.name));
43
- for (const t of taskTools) {
44
- if (!have.has(t.name)) {
48
+ for (const t of registry.list()) {
49
+ if (t.name.startsWith(ns[1]) && !have.has(t.name)) {
45
50
  tools.push(t);
46
51
  }
47
52
  }