@agent-native/core 0.19.0 → 0.19.3

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 (95) hide show
  1. package/dist/a2a/caller-auth.d.ts +1 -0
  2. package/dist/a2a/caller-auth.d.ts.map +1 -1
  3. package/dist/a2a/caller-auth.js +1 -1
  4. package/dist/a2a/caller-auth.js.map +1 -1
  5. package/dist/agent/production-agent.d.ts +1 -1
  6. package/dist/agent/production-agent.d.ts.map +1 -1
  7. package/dist/agent/production-agent.js +34 -2
  8. package/dist/agent/production-agent.js.map +1 -1
  9. package/dist/cli/code-agent-executor.d.ts.map +1 -1
  10. package/dist/cli/code-agent-executor.js +47 -256
  11. package/dist/cli/code-agent-executor.js.map +1 -1
  12. package/dist/cli/connect.d.ts +3 -2
  13. package/dist/cli/connect.d.ts.map +1 -1
  14. package/dist/cli/connect.js +12 -8
  15. package/dist/cli/connect.js.map +1 -1
  16. package/dist/cli/mcp-config-writers.d.ts +3 -3
  17. package/dist/cli/mcp-config-writers.d.ts.map +1 -1
  18. package/dist/cli/mcp-config-writers.js +19 -8
  19. package/dist/cli/mcp-config-writers.js.map +1 -1
  20. package/dist/client/AgentPanel.d.ts +3 -1
  21. package/dist/client/AgentPanel.d.ts.map +1 -1
  22. package/dist/client/AgentPanel.js +4 -4
  23. package/dist/client/AgentPanel.js.map +1 -1
  24. package/dist/client/AssistantChat.d.ts +3 -0
  25. package/dist/client/AssistantChat.d.ts.map +1 -1
  26. package/dist/client/AssistantChat.js +11 -3
  27. package/dist/client/AssistantChat.js.map +1 -1
  28. package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
  29. package/dist/client/MultiTabAssistantChat.js +4 -1
  30. package/dist/client/MultiTabAssistantChat.js.map +1 -1
  31. package/dist/client/dynamic-suggestions.d.ts +43 -0
  32. package/dist/client/dynamic-suggestions.d.ts.map +1 -0
  33. package/dist/client/dynamic-suggestions.js +344 -0
  34. package/dist/client/dynamic-suggestions.js.map +1 -0
  35. package/dist/client/index.d.ts +1 -0
  36. package/dist/client/index.d.ts.map +1 -1
  37. package/dist/client/index.js +1 -0
  38. package/dist/client/index.js.map +1 -1
  39. package/dist/client/settings/SettingsPanel.js +2 -2
  40. package/dist/client/settings/SettingsPanel.js.map +1 -1
  41. package/dist/coding-tools/index.d.ts +31 -0
  42. package/dist/coding-tools/index.d.ts.map +1 -0
  43. package/dist/coding-tools/index.js +411 -0
  44. package/dist/coding-tools/index.js.map +1 -0
  45. package/dist/mcp/build-server.d.ts +33 -1
  46. package/dist/mcp/build-server.d.ts.map +1 -1
  47. package/dist/mcp/build-server.js +33 -10
  48. package/dist/mcp/build-server.js.map +1 -1
  49. package/dist/mcp/builtin-tools.d.ts +3 -1
  50. package/dist/mcp/builtin-tools.d.ts.map +1 -1
  51. package/dist/mcp/builtin-tools.js +115 -26
  52. package/dist/mcp/builtin-tools.js.map +1 -1
  53. package/dist/mcp/connect-route.d.ts.map +1 -1
  54. package/dist/mcp/connect-route.js +382 -74
  55. package/dist/mcp/connect-route.js.map +1 -1
  56. package/dist/mcp/org-directory.d.ts +83 -0
  57. package/dist/mcp/org-directory.d.ts.map +1 -0
  58. package/dist/mcp/org-directory.js +201 -0
  59. package/dist/mcp/org-directory.js.map +1 -0
  60. package/dist/mcp/server.d.ts +38 -1
  61. package/dist/mcp/server.d.ts.map +1 -1
  62. package/dist/mcp/server.js +222 -77
  63. package/dist/mcp/server.js.map +1 -1
  64. package/dist/scripts/dev/index.d.ts +6 -4
  65. package/dist/scripts/dev/index.d.ts.map +1 -1
  66. package/dist/scripts/dev/index.js +28 -13
  67. package/dist/scripts/dev/index.js.map +1 -1
  68. package/dist/server/agent-chat-plugin.d.ts +6 -6
  69. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  70. package/dist/server/agent-chat-plugin.js +65 -32
  71. package/dist/server/agent-chat-plugin.js.map +1 -1
  72. package/dist/server/agent-teams.js +2 -2
  73. package/dist/server/agent-teams.js.map +1 -1
  74. package/dist/server/agents-bundle.d.ts +3 -3
  75. package/dist/server/agents-bundle.js +5 -5
  76. package/dist/server/agents-bundle.js.map +1 -1
  77. package/dist/server/auth.d.ts +8 -0
  78. package/dist/server/auth.d.ts.map +1 -1
  79. package/dist/server/auth.js +8 -1
  80. package/dist/server/auth.js.map +1 -1
  81. package/dist/server/sentry.d.ts.map +1 -1
  82. package/dist/server/sentry.js +17 -2
  83. package/dist/server/sentry.js.map +1 -1
  84. package/dist/vite/client.d.ts.map +1 -1
  85. package/dist/vite/client.js +1 -0
  86. package/dist/vite/client.js.map +1 -1
  87. package/docs/content/client.md +15 -0
  88. package/docs/content/code-agents-ui.md +11 -1
  89. package/docs/content/drop-in-agent.md +3 -1
  90. package/docs/content/external-agents.md +27 -6
  91. package/docs/content/frames.md +1 -1
  92. package/docs/content/mcp-clients.md +2 -0
  93. package/docs/content/mcp-protocol.md +4 -2
  94. package/docs/content/migration-workbench.md +5 -0
  95. package/package.json +1 -1
@@ -0,0 +1,31 @@
1
+ import type { ActionEntry } from "../agent/production-agent.js";
2
+ export interface CodingCommandResult {
3
+ code: number | null;
4
+ stdout: string;
5
+ stderr: string;
6
+ timedOut: boolean;
7
+ }
8
+ export interface CreateCodingToolRegistryOptions {
9
+ cwd?: string;
10
+ restrictToCwd?: boolean;
11
+ commandTimeoutMs?: number;
12
+ maxOutputChars?: number;
13
+ maxFileReadChars?: number;
14
+ bashThrowsOnNonZero?: boolean;
15
+ canWrite?: (toolName: "edit" | "write") => string | null;
16
+ beforeBash?: (input: {
17
+ command: string;
18
+ cwd: string;
19
+ timeoutMs: number;
20
+ }) => string | null | Promise<string | null>;
21
+ }
22
+ export declare function createCodingToolRegistry(options?: CreateCodingToolRegistryOptions): Record<"bash" | "read" | "edit" | "write", ActionEntry>;
23
+ export declare function runCodingCommand(command: string, cwd: string, timeoutMs: number, options?: {
24
+ stdin?: string;
25
+ }): Promise<CodingCommandResult>;
26
+ export declare function formatCodingCommandResult(result: CodingCommandResult, maxChars?: number, options?: {
27
+ omitEmptyExitCode?: boolean;
28
+ }): string;
29
+ export declare function truncateCodingOutput(value: string, max: number): string;
30
+ export declare function isReadOnlyShellCommand(command: string): boolean;
31
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/coding-tools/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEhE,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,+BAA+B;IAC9C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,KAAK,MAAM,GAAG,IAAI,CAAC;IACzD,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE;QACnB,OAAO,EAAE,MAAM,CAAC;QAChB,GAAG,EAAE,MAAM,CAAC;QACZ,SAAS,EAAE,MAAM,CAAC;KACnB,KAAK,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAC9C;AAcD,wBAAgB,wBAAwB,CACtC,OAAO,GAAE,+BAAoC,GAC5C,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,EAAE,WAAW,CAAC,CA+OzD;AAED,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAC/B,OAAO,CAAC,mBAAmB,CAAC,CA4B9B;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,mBAAmB,EAC3B,QAAQ,SAA2B,EACnC,OAAO,GAAE;IAAE,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAAO,GAC5C,MAAM,CAUR;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAGvE;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAqC/D"}
@@ -0,0 +1,411 @@
1
+ import { spawn } from "node:child_process";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ const DEFAULT_COMMAND_TIMEOUT_MS = 30_000;
5
+ const DEFAULT_MAX_OUTPUT_CHARS = 50_000;
6
+ const DEFAULT_MAX_FILE_READ_CHARS = 120_000;
7
+ const mutationQueues = new Map();
8
+ export function createCodingToolRegistry(options = {}) {
9
+ const cwd = path.resolve(options.cwd ?? process.cwd());
10
+ const restrictToCwd = options.restrictToCwd ?? false;
11
+ const commandTimeoutMs = options.commandTimeoutMs ?? DEFAULT_COMMAND_TIMEOUT_MS;
12
+ const maxOutputChars = options.maxOutputChars ?? DEFAULT_MAX_OUTPUT_CHARS;
13
+ const maxFileReadChars = options.maxFileReadChars ?? DEFAULT_MAX_FILE_READ_CHARS;
14
+ return {
15
+ bash: {
16
+ tool: {
17
+ description: "Run a bash command. Use this for file discovery and search (rg --files, rg, find, ls), tests, builds, package commands, git status/diff, and project CLIs.",
18
+ parameters: {
19
+ type: "object",
20
+ properties: {
21
+ command: {
22
+ type: "string",
23
+ description: "The bash command to run.",
24
+ },
25
+ cwd: {
26
+ type: "string",
27
+ description: "Optional working directory, relative to the workspace unless absolute paths are allowed.",
28
+ },
29
+ timeoutMs: {
30
+ type: "string",
31
+ description: "Optional timeout in milliseconds.",
32
+ },
33
+ stdin: {
34
+ type: "string",
35
+ description: "Optional stdin to pipe into the command.",
36
+ },
37
+ },
38
+ required: ["command"],
39
+ },
40
+ },
41
+ run: async (args) => {
42
+ const command = stringArg(args.command);
43
+ if (!command)
44
+ return "Error: command is required.";
45
+ const commandCwd = resolveCodingPath(cwd, stringArg(args.cwd) || ".", {
46
+ restrictToCwd,
47
+ allowEmpty: true,
48
+ }) ?? "";
49
+ if (!commandCwd) {
50
+ return "Error: cwd must stay inside the workspace.";
51
+ }
52
+ const requestedTimeoutMs = Number(args.timeoutMs);
53
+ const timeoutMs = Number.isFinite(requestedTimeoutMs) && requestedTimeoutMs > 0
54
+ ? Math.min(requestedTimeoutMs, 10 * 60_000)
55
+ : commandTimeoutMs;
56
+ const policyResult = (await options.beforeBash?.({
57
+ command,
58
+ cwd: commandCwd,
59
+ timeoutMs,
60
+ })) ?? null;
61
+ if (policyResult)
62
+ return policyResult;
63
+ const result = await runCodingCommand(command, commandCwd, timeoutMs, {
64
+ stdin: stringArg(args.stdin) || undefined,
65
+ });
66
+ if (options.bashThrowsOnNonZero && result.code !== 0) {
67
+ throw new Error(formatCodingCommandResult(result, maxOutputChars));
68
+ }
69
+ return formatCodingCommandResult(result, maxOutputChars, {
70
+ omitEmptyExitCode: options.bashThrowsOnNonZero && result.code === 0,
71
+ });
72
+ },
73
+ },
74
+ read: {
75
+ readOnly: true,
76
+ tool: {
77
+ description: "Read a UTF-8 text file with line numbers. Use bash for directories, file lists, and search.",
78
+ parameters: {
79
+ type: "object",
80
+ properties: {
81
+ path: {
82
+ type: "string",
83
+ description: "File path to read.",
84
+ },
85
+ offset: {
86
+ type: "string",
87
+ description: "1-based line number to start reading from.",
88
+ },
89
+ limit: {
90
+ type: "string",
91
+ description: "Maximum number of lines to read.",
92
+ },
93
+ },
94
+ required: ["path"],
95
+ },
96
+ },
97
+ run: async (args) => {
98
+ const requestedPath = stringArg(args.path);
99
+ const filePath = resolveCodingPath(cwd, requestedPath, {
100
+ restrictToCwd,
101
+ });
102
+ if (!filePath)
103
+ return "Error: path must stay inside the workspace.";
104
+ if (!fs.existsSync(filePath)) {
105
+ return `Error: file not found: ${requestedPath}`;
106
+ }
107
+ const stat = fs.statSync(filePath);
108
+ if (!stat.isFile()) {
109
+ return `Error: ${requestedPath} is not a file. Use bash for directories and file lists.`;
110
+ }
111
+ const content = fs.readFileSync(filePath, "utf8");
112
+ return truncateCodingOutput(formatFileReadOutput(cwd, filePath, content, args), maxFileReadChars);
113
+ },
114
+ },
115
+ edit: {
116
+ tool: {
117
+ description: "Edit an existing UTF-8 text file by replacing exact text. Prefer this for focused source changes. oldText must match exactly and uniquely unless replaceAll is true. For batch edits, pass edits as a JSON array of {oldText,newText,replaceAll}.",
118
+ parameters: {
119
+ type: "object",
120
+ properties: {
121
+ path: {
122
+ type: "string",
123
+ description: "File path to edit.",
124
+ },
125
+ oldText: {
126
+ type: "string",
127
+ description: "Exact text to replace for a single edit.",
128
+ },
129
+ newText: {
130
+ type: "string",
131
+ description: "Replacement text for a single edit.",
132
+ },
133
+ replaceAll: {
134
+ type: "string",
135
+ description: 'Set to "true" to replace every occurrence.',
136
+ enum: ["true", "false"],
137
+ },
138
+ edits: {
139
+ type: "string",
140
+ description: 'Optional JSON array of edits, e.g. [{"oldText":"foo","newText":"bar"}].',
141
+ },
142
+ },
143
+ required: ["path"],
144
+ },
145
+ },
146
+ run: async (args) => {
147
+ const permissionError = options.canWrite?.("edit") ?? null;
148
+ if (permissionError)
149
+ return permissionError;
150
+ const requestedPath = stringArg(args.path);
151
+ const filePath = resolveCodingPath(cwd, requestedPath, {
152
+ restrictToCwd,
153
+ });
154
+ if (!filePath)
155
+ return "Error: path must stay inside the workspace.";
156
+ const edits = parseEditOperations(args);
157
+ return queueFileMutation(filePath, async () => {
158
+ if (!fs.existsSync(filePath)) {
159
+ throw new Error(`file not found: ${requestedPath}`);
160
+ }
161
+ const stat = fs.statSync(filePath);
162
+ if (!stat.isFile()) {
163
+ throw new Error(`${requestedPath} is not a file`);
164
+ }
165
+ let content = fs.readFileSync(filePath, "utf8");
166
+ let replacements = 0;
167
+ for (const edit of edits) {
168
+ const count = countOccurrences(content, edit.oldText);
169
+ if (count === 0) {
170
+ throw new Error(`oldText was not found in ${requestedPath}: ${previewText(edit.oldText)}`);
171
+ }
172
+ if (!edit.replaceAll && count !== 1) {
173
+ throw new Error(`oldText matched ${count} times in ${requestedPath}; make it unique or set replaceAll=true.`);
174
+ }
175
+ content = edit.replaceAll
176
+ ? content.split(edit.oldText).join(edit.newText)
177
+ : content.replace(edit.oldText, edit.newText);
178
+ replacements += edit.replaceAll ? count : 1;
179
+ }
180
+ fs.writeFileSync(filePath, content, "utf8");
181
+ return `Edited ${path.relative(cwd, filePath) || requestedPath} (${replacements} replacement${replacements === 1 ? "" : "s"}).`;
182
+ });
183
+ },
184
+ },
185
+ write: {
186
+ tool: {
187
+ description: "Create or fully overwrite a UTF-8 text file. Prefer edit for existing files unless a complete rewrite is intended.",
188
+ parameters: {
189
+ type: "object",
190
+ properties: {
191
+ path: {
192
+ type: "string",
193
+ description: "File path to write.",
194
+ },
195
+ content: {
196
+ type: "string",
197
+ description: "Full file content.",
198
+ },
199
+ },
200
+ required: ["path", "content"],
201
+ },
202
+ },
203
+ run: async (args) => {
204
+ const permissionError = options.canWrite?.("write") ?? null;
205
+ if (permissionError)
206
+ return permissionError;
207
+ const requestedPath = stringArg(args.path);
208
+ const filePath = resolveCodingPath(cwd, requestedPath, {
209
+ restrictToCwd,
210
+ });
211
+ if (!filePath)
212
+ return "Error: path must stay inside the workspace.";
213
+ const content = stringArg(args.content);
214
+ return queueFileMutation(filePath, async () => {
215
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
216
+ const existed = fs.existsSync(filePath);
217
+ fs.writeFileSync(filePath, content, "utf8");
218
+ const bytes = Buffer.byteLength(content, "utf8");
219
+ const lines = content.split("\n").length;
220
+ return `${existed ? "Updated" : "Created"} ${path.relative(cwd, filePath) || requestedPath} (${lines} lines, ${bytes} bytes).`;
221
+ });
222
+ },
223
+ },
224
+ };
225
+ }
226
+ export async function runCodingCommand(command, cwd, timeoutMs, options = {}) {
227
+ const child = spawn(command, {
228
+ cwd,
229
+ shell: true,
230
+ stdio: ["pipe", "pipe", "pipe"],
231
+ env: { ...process.env, FORCE_COLOR: "0" },
232
+ });
233
+ let stdout = "";
234
+ let stderr = "";
235
+ let timedOut = false;
236
+ const timer = setTimeout(() => {
237
+ timedOut = true;
238
+ child.kill("SIGTERM");
239
+ }, timeoutMs);
240
+ child.stdout?.on("data", (chunk) => {
241
+ stdout += chunk.toString();
242
+ });
243
+ child.stderr?.on("data", (chunk) => {
244
+ stderr += chunk.toString();
245
+ });
246
+ if (options.stdin)
247
+ child.stdin?.end(options.stdin);
248
+ else
249
+ child.stdin?.end();
250
+ const code = await new Promise((resolve, reject) => {
251
+ child.once("error", reject);
252
+ child.once("exit", resolve);
253
+ });
254
+ clearTimeout(timer);
255
+ return { code, stdout, stderr, timedOut };
256
+ }
257
+ export function formatCodingCommandResult(result, maxChars = DEFAULT_MAX_OUTPUT_CHARS, options = {}) {
258
+ const parts = [
259
+ options.omitEmptyExitCode && result.code === 0
260
+ ? ""
261
+ : `exitCode: ${result.code}`,
262
+ result.timedOut ? "timedOut: true" : "",
263
+ result.stdout ? `stdout:\n${result.stdout}` : "",
264
+ result.stderr ? `stderr:\n${result.stderr}` : "",
265
+ ].filter(Boolean);
266
+ return truncateCodingOutput(parts.join("\n\n") || "(no output)", maxChars);
267
+ }
268
+ export function truncateCodingOutput(value, max) {
269
+ if (value.length <= max)
270
+ return value;
271
+ return `${value.slice(0, max)}\n\n...[truncated ${value.length - max} chars]`;
272
+ }
273
+ export function isReadOnlyShellCommand(command) {
274
+ const normalized = command.trim().toLowerCase();
275
+ if (!normalized)
276
+ return false;
277
+ // Read-only modes get a deliberately tiny shell grammar: one command only,
278
+ // no redirection, pipes, sequencing, backgrounding, or command substitution.
279
+ // Prefix allowlists are not safe until these shell forms are excluded.
280
+ if (/[\n\r;&|<>]/.test(normalized))
281
+ return false;
282
+ if (/\$\(|`|\${|\\\n/.test(command))
283
+ return false;
284
+ // `sed` can WRITE even in `-n` mode via the `w`/`W` commands or `-i`
285
+ // (e.g. `sed -n '1w out.txt' file`), so the `^sed -n` allowlist entry
286
+ // below is not safe on its own. Reject any sed that can write.
287
+ if (/^sed\b/.test(normalized)) {
288
+ if (/(^|\s)-i(\b|=)|--in-place/.test(normalized))
289
+ return false;
290
+ // `w`/`W` used as a sed command: preceded by an address/separator
291
+ // (digit, $, /, }, ;, quote, space) and followed by a filename arg or
292
+ // end. Catches `1w f`, `$w f`, `/re/w f`, `s/x/y/w f`, `2W f`; leaves
293
+ // prints like `/window/p`, `1,5p`, `s/a/b/` untouched.
294
+ if (/[\s'"0-9$}/;](w|W)([\s'"]|$)/.test(normalized))
295
+ return false;
296
+ }
297
+ const allowedPrefixes = [
298
+ /^pwd\b/,
299
+ /^ls\b/,
300
+ /^find\b/,
301
+ /^rg\b/,
302
+ /^grep\b/,
303
+ /^cat\b/,
304
+ /^sed\s+-n\b/,
305
+ /^head\b/,
306
+ /^tail\b/,
307
+ /^wc\b/,
308
+ /^git\s+(status|diff|show|log)\b/,
309
+ /^git\s+branch\s+--show-current\b/,
310
+ ];
311
+ return allowedPrefixes.some((pattern) => pattern.test(normalized));
312
+ }
313
+ function resolveCodingPath(cwd, value, options) {
314
+ if (!value.trim() && !options.allowEmpty)
315
+ return null;
316
+ const target = value.trim() || ".";
317
+ const resolved = path.isAbsolute(target)
318
+ ? path.resolve(target)
319
+ : path.resolve(cwd, target);
320
+ if (!options.restrictToCwd)
321
+ return resolved;
322
+ const relative = path.relative(cwd, resolved);
323
+ if (relative.startsWith("..") || path.isAbsolute(relative))
324
+ return null;
325
+ return resolved;
326
+ }
327
+ function formatFileReadOutput(cwd, filePath, content, args) {
328
+ const lines = content.split("\n");
329
+ const offset = positiveInteger(args.offset, 1);
330
+ const limit = positiveInteger(args.limit, lines.length - offset + 1);
331
+ const selected = lines.slice(offset - 1, offset - 1 + limit);
332
+ const body = selected
333
+ .map((line, index) => `${String(offset + index).padStart(5)} | ${line}`)
334
+ .join("\n");
335
+ return `${path.relative(cwd, filePath) || filePath} (${lines.length} lines)\n${body}`;
336
+ }
337
+ function parseEditOperations(args) {
338
+ const editsJson = stringArg(args.edits);
339
+ if (editsJson.trim()) {
340
+ let parsed;
341
+ try {
342
+ parsed = JSON.parse(editsJson);
343
+ }
344
+ catch (err) {
345
+ throw new Error(`edits must be valid JSON: ${err instanceof Error ? err.message : String(err)}`);
346
+ }
347
+ if (!Array.isArray(parsed) || parsed.length === 0) {
348
+ throw new Error("edits must be a non-empty JSON array.");
349
+ }
350
+ return parsed.map((edit, index) => {
351
+ if (!edit || typeof edit !== "object") {
352
+ throw new Error(`edits[${index}] must be an object.`);
353
+ }
354
+ return normalizeEditOperation(edit, index);
355
+ });
356
+ }
357
+ return [normalizeEditOperation(args, 0)];
358
+ }
359
+ function normalizeEditOperation(edit, index) {
360
+ const oldText = typeof edit.oldText === "string" ? edit.oldText : undefined;
361
+ const newText = typeof edit.newText === "string" ? edit.newText : undefined;
362
+ if (!oldText) {
363
+ throw new Error(index === 0
364
+ ? "oldText is required and cannot be empty."
365
+ : `edits[${index}].oldText is required and cannot be empty.`);
366
+ }
367
+ if (newText === undefined) {
368
+ throw new Error(index === 0
369
+ ? "newText is required."
370
+ : `edits[${index}].newText is required.`);
371
+ }
372
+ return {
373
+ oldText,
374
+ newText,
375
+ replaceAll: stringArg(edit.replaceAll).toLowerCase() === "true",
376
+ };
377
+ }
378
+ function countOccurrences(value, needle) {
379
+ let count = 0;
380
+ let index = 0;
381
+ while (true) {
382
+ index = value.indexOf(needle, index);
383
+ if (index === -1)
384
+ return count;
385
+ count += 1;
386
+ index += needle.length;
387
+ }
388
+ }
389
+ function queueFileMutation(filePath, task) {
390
+ const previous = mutationQueues.get(filePath) ?? Promise.resolve();
391
+ const next = previous.catch(() => undefined).then(task);
392
+ let queued;
393
+ queued = next.finally(() => {
394
+ if (mutationQueues.get(filePath) === queued)
395
+ mutationQueues.delete(filePath);
396
+ });
397
+ mutationQueues.set(filePath, queued);
398
+ return next;
399
+ }
400
+ function previewText(value) {
401
+ const oneLine = value.replace(/\s+/g, " ").trim();
402
+ return oneLine.length > 80 ? `${oneLine.slice(0, 80)}...` : oneLine;
403
+ }
404
+ function stringArg(value) {
405
+ return typeof value === "string" ? value : "";
406
+ }
407
+ function positiveInteger(value, fallback) {
408
+ const parsed = Number(value);
409
+ return Number.isFinite(parsed) && parsed > 0 ? Math.floor(parsed) : fallback;
410
+ }
411
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/coding-tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAgC7B,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAC1C,MAAM,wBAAwB,GAAG,MAAM,CAAC;AACxC,MAAM,2BAA2B,GAAG,OAAO,CAAC;AAE5C,MAAM,cAAc,GAAG,IAAI,GAAG,EAA4B,CAAC;AAE3D,MAAM,UAAU,wBAAwB,CACtC,UAA2C,EAAE;IAE7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACvD,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,KAAK,CAAC;IACrD,MAAM,gBAAgB,GACpB,OAAO,CAAC,gBAAgB,IAAI,0BAA0B,CAAC;IACzD,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,wBAAwB,CAAC;IAC1E,MAAM,gBAAgB,GACpB,OAAO,CAAC,gBAAgB,IAAI,2BAA2B,CAAC;IAE1D,OAAO;QACL,IA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,CAAC,CAAC,CAAC;IACH,cAAc,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACrC,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,WAAW,CAAC,KAAa;IAChC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAClD,OAAO,OAAO,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC;AACtE,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AAChD,CAAC;AAED,SAAS,eAAe,CAAC,KAAc,EAAE,QAAgB;IACvD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7B,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC/E,CAAC","sourcesContent":["import { spawn } from \"node:child_process\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\n\nimport type { ActionEntry } from \"../agent/production-agent.js\";\n\nexport interface CodingCommandResult {\n code: number | null;\n stdout: string;\n stderr: string;\n timedOut: boolean;\n}\n\nexport interface CreateCodingToolRegistryOptions {\n cwd?: string;\n restrictToCwd?: boolean;\n commandTimeoutMs?: number;\n maxOutputChars?: number;\n maxFileReadChars?: number;\n bashThrowsOnNonZero?: boolean;\n canWrite?: (toolName: \"edit\" | \"write\") => string | null;\n beforeBash?: (input: {\n command: string;\n cwd: string;\n timeoutMs: number;\n }) => string | null | Promise<string | null>;\n}\n\ninterface EditOperation {\n oldText: string;\n newText: string;\n replaceAll: boolean;\n}\n\nconst DEFAULT_COMMAND_TIMEOUT_MS = 30_000;\nconst DEFAULT_MAX_OUTPUT_CHARS = 50_000;\nconst DEFAULT_MAX_FILE_READ_CHARS = 120_000;\n\nconst mutationQueues = new Map<string, Promise<unknown>>();\n\nexport function createCodingToolRegistry(\n options: CreateCodingToolRegistryOptions = {},\n): Record<\"bash\" | \"read\" | \"edit\" | \"write\", ActionEntry> {\n const cwd = path.resolve(options.cwd ?? process.cwd());\n const restrictToCwd = options.restrictToCwd ?? false;\n const commandTimeoutMs =\n options.commandTimeoutMs ?? DEFAULT_COMMAND_TIMEOUT_MS;\n const maxOutputChars = options.maxOutputChars ?? DEFAULT_MAX_OUTPUT_CHARS;\n const maxFileReadChars =\n options.maxFileReadChars ?? DEFAULT_MAX_FILE_READ_CHARS;\n\n return {\n bash: {\n tool: {\n description:\n \"Run a bash command. Use this for file discovery and search (rg --files, rg, find, ls), tests, builds, package commands, git status/diff, and project CLIs.\",\n parameters: {\n type: \"object\",\n properties: {\n command: {\n type: \"string\",\n description: \"The bash command to run.\",\n },\n cwd: {\n type: \"string\",\n description:\n \"Optional working directory, relative to the workspace unless absolute paths are allowed.\",\n },\n timeoutMs: {\n type: \"string\",\n description: \"Optional timeout in milliseconds.\",\n },\n stdin: {\n type: \"string\",\n description: \"Optional stdin to pipe into the command.\",\n },\n },\n required: [\"command\"],\n },\n },\n run: async (args) => {\n const command = stringArg(args.command);\n if (!command) return \"Error: command is required.\";\n const commandCwd =\n resolveCodingPath(cwd, stringArg(args.cwd) || \".\", {\n restrictToCwd,\n allowEmpty: true,\n }) ?? \"\";\n if (!commandCwd) {\n return \"Error: cwd must stay inside the workspace.\";\n }\n const requestedTimeoutMs = Number(args.timeoutMs);\n const timeoutMs =\n Number.isFinite(requestedTimeoutMs) && requestedTimeoutMs > 0\n ? Math.min(requestedTimeoutMs, 10 * 60_000)\n : commandTimeoutMs;\n\n const policyResult =\n (await options.beforeBash?.({\n command,\n cwd: commandCwd,\n timeoutMs,\n })) ?? null;\n if (policyResult) return policyResult;\n\n const result = await runCodingCommand(command, commandCwd, timeoutMs, {\n stdin: stringArg(args.stdin) || undefined,\n });\n if (options.bashThrowsOnNonZero && result.code !== 0) {\n throw new Error(formatCodingCommandResult(result, maxOutputChars));\n }\n return formatCodingCommandResult(result, maxOutputChars, {\n omitEmptyExitCode: options.bashThrowsOnNonZero && result.code === 0,\n });\n },\n },\n read: {\n readOnly: true,\n tool: {\n description:\n \"Read a UTF-8 text file with line numbers. Use bash for directories, file lists, and search.\",\n parameters: {\n type: \"object\",\n properties: {\n path: {\n type: \"string\",\n description: \"File path to read.\",\n },\n offset: {\n type: \"string\",\n description: \"1-based line number to start reading from.\",\n },\n limit: {\n type: \"string\",\n description: \"Maximum number of lines to read.\",\n },\n },\n required: [\"path\"],\n },\n },\n run: async (args) => {\n const requestedPath = stringArg(args.path);\n const filePath = resolveCodingPath(cwd, requestedPath, {\n restrictToCwd,\n });\n if (!filePath) return \"Error: path must stay inside the workspace.\";\n if (!fs.existsSync(filePath)) {\n return `Error: file not found: ${requestedPath}`;\n }\n const stat = fs.statSync(filePath);\n if (!stat.isFile()) {\n return `Error: ${requestedPath} is not a file. Use bash for directories and file lists.`;\n }\n const content = fs.readFileSync(filePath, \"utf8\");\n return truncateCodingOutput(\n formatFileReadOutput(cwd, filePath, content, args),\n maxFileReadChars,\n );\n },\n },\n edit: {\n tool: {\n description:\n \"Edit an existing UTF-8 text file by replacing exact text. Prefer this for focused source changes. oldText must match exactly and uniquely unless replaceAll is true. For batch edits, pass edits as a JSON array of {oldText,newText,replaceAll}.\",\n parameters: {\n type: \"object\",\n properties: {\n path: {\n type: \"string\",\n description: \"File path to edit.\",\n },\n oldText: {\n type: \"string\",\n description: \"Exact text to replace for a single edit.\",\n },\n newText: {\n type: \"string\",\n description: \"Replacement text for a single edit.\",\n },\n replaceAll: {\n type: \"string\",\n description: 'Set to \"true\" to replace every occurrence.',\n enum: [\"true\", \"false\"],\n },\n edits: {\n type: \"string\",\n description:\n 'Optional JSON array of edits, e.g. [{\"oldText\":\"foo\",\"newText\":\"bar\"}].',\n },\n },\n required: [\"path\"],\n },\n },\n run: async (args) => {\n const permissionError = options.canWrite?.(\"edit\") ?? null;\n if (permissionError) return permissionError;\n\n const requestedPath = stringArg(args.path);\n const filePath = resolveCodingPath(cwd, requestedPath, {\n restrictToCwd,\n });\n if (!filePath) return \"Error: path must stay inside the workspace.\";\n const edits = parseEditOperations(args);\n\n return queueFileMutation(filePath, async () => {\n if (!fs.existsSync(filePath)) {\n throw new Error(`file not found: ${requestedPath}`);\n }\n const stat = fs.statSync(filePath);\n if (!stat.isFile()) {\n throw new Error(`${requestedPath} is not a file`);\n }\n\n let content = fs.readFileSync(filePath, \"utf8\");\n let replacements = 0;\n for (const edit of edits) {\n const count = countOccurrences(content, edit.oldText);\n if (count === 0) {\n throw new Error(\n `oldText was not found in ${requestedPath}: ${previewText(\n edit.oldText,\n )}`,\n );\n }\n if (!edit.replaceAll && count !== 1) {\n throw new Error(\n `oldText matched ${count} times in ${requestedPath}; make it unique or set replaceAll=true.`,\n );\n }\n content = edit.replaceAll\n ? content.split(edit.oldText).join(edit.newText)\n : content.replace(edit.oldText, edit.newText);\n replacements += edit.replaceAll ? count : 1;\n }\n\n fs.writeFileSync(filePath, content, \"utf8\");\n return `Edited ${path.relative(cwd, filePath) || requestedPath} (${replacements} replacement${replacements === 1 ? \"\" : \"s\"}).`;\n });\n },\n },\n write: {\n tool: {\n description:\n \"Create or fully overwrite a UTF-8 text file. Prefer edit for existing files unless a complete rewrite is intended.\",\n parameters: {\n type: \"object\",\n properties: {\n path: {\n type: \"string\",\n description: \"File path to write.\",\n },\n content: {\n type: \"string\",\n description: \"Full file content.\",\n },\n },\n required: [\"path\", \"content\"],\n },\n },\n run: async (args) => {\n const permissionError = options.canWrite?.(\"write\") ?? null;\n if (permissionError) return permissionError;\n\n const requestedPath = stringArg(args.path);\n const filePath = resolveCodingPath(cwd, requestedPath, {\n restrictToCwd,\n });\n if (!filePath) return \"Error: path must stay inside the workspace.\";\n const content = stringArg(args.content);\n\n return queueFileMutation(filePath, async () => {\n fs.mkdirSync(path.dirname(filePath), { recursive: true });\n const existed = fs.existsSync(filePath);\n fs.writeFileSync(filePath, content, \"utf8\");\n const bytes = Buffer.byteLength(content, \"utf8\");\n const lines = content.split(\"\\n\").length;\n return `${existed ? \"Updated\" : \"Created\"} ${path.relative(cwd, filePath) || requestedPath} (${lines} lines, ${bytes} bytes).`;\n });\n },\n },\n };\n}\n\nexport async function runCodingCommand(\n command: string,\n cwd: string,\n timeoutMs: number,\n options: { stdin?: string } = {},\n): Promise<CodingCommandResult> {\n const child = spawn(command, {\n cwd,\n shell: true,\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n env: { ...process.env, FORCE_COLOR: \"0\" },\n });\n let stdout = \"\";\n let stderr = \"\";\n let timedOut = false;\n const timer = setTimeout(() => {\n timedOut = true;\n child.kill(\"SIGTERM\");\n }, timeoutMs);\n child.stdout?.on(\"data\", (chunk) => {\n stdout += chunk.toString();\n });\n child.stderr?.on(\"data\", (chunk) => {\n stderr += chunk.toString();\n });\n if (options.stdin) child.stdin?.end(options.stdin);\n else child.stdin?.end();\n const code = await new Promise<number | null>((resolve, reject) => {\n child.once(\"error\", reject);\n child.once(\"exit\", resolve);\n });\n clearTimeout(timer);\n return { code, stdout, stderr, timedOut };\n}\n\nexport function formatCodingCommandResult(\n result: CodingCommandResult,\n maxChars = DEFAULT_MAX_OUTPUT_CHARS,\n options: { omitEmptyExitCode?: boolean } = {},\n): string {\n const parts = [\n options.omitEmptyExitCode && result.code === 0\n ? \"\"\n : `exitCode: ${result.code}`,\n result.timedOut ? \"timedOut: true\" : \"\",\n result.stdout ? `stdout:\\n${result.stdout}` : \"\",\n result.stderr ? `stderr:\\n${result.stderr}` : \"\",\n ].filter(Boolean);\n return truncateCodingOutput(parts.join(\"\\n\\n\") || \"(no output)\", maxChars);\n}\n\nexport function truncateCodingOutput(value: string, max: number): string {\n if (value.length <= max) return value;\n return `${value.slice(0, max)}\\n\\n...[truncated ${value.length - max} chars]`;\n}\n\nexport function isReadOnlyShellCommand(command: string): boolean {\n const normalized = command.trim().toLowerCase();\n if (!normalized) return false;\n\n // Read-only modes get a deliberately tiny shell grammar: one command only,\n // no redirection, pipes, sequencing, backgrounding, or command substitution.\n // Prefix allowlists are not safe until these shell forms are excluded.\n if (/[\\n\\r;&|<>]/.test(normalized)) return false;\n if (/\\$\\(|`|\\${|\\\\\\n/.test(command)) return false;\n\n // `sed` can WRITE even in `-n` mode via the `w`/`W` commands or `-i`\n // (e.g. `sed -n '1w out.txt' file`), so the `^sed -n` allowlist entry\n // below is not safe on its own. Reject any sed that can write.\n if (/^sed\\b/.test(normalized)) {\n if (/(^|\\s)-i(\\b|=)|--in-place/.test(normalized)) return false;\n // `w`/`W` used as a sed command: preceded by an address/separator\n // (digit, $, /, }, ;, quote, space) and followed by a filename arg or\n // end. Catches `1w f`, `$w f`, `/re/w f`, `s/x/y/w f`, `2W f`; leaves\n // prints like `/window/p`, `1,5p`, `s/a/b/` untouched.\n if (/[\\s'\"0-9$}/;](w|W)([\\s'\"]|$)/.test(normalized)) return false;\n }\n\n const allowedPrefixes = [\n /^pwd\\b/,\n /^ls\\b/,\n /^find\\b/,\n /^rg\\b/,\n /^grep\\b/,\n /^cat\\b/,\n /^sed\\s+-n\\b/,\n /^head\\b/,\n /^tail\\b/,\n /^wc\\b/,\n /^git\\s+(status|diff|show|log)\\b/,\n /^git\\s+branch\\s+--show-current\\b/,\n ];\n return allowedPrefixes.some((pattern) => pattern.test(normalized));\n}\n\nfunction resolveCodingPath(\n cwd: string,\n value: string,\n options: { restrictToCwd: boolean; allowEmpty?: boolean },\n): string | null {\n if (!value.trim() && !options.allowEmpty) return null;\n const target = value.trim() || \".\";\n const resolved = path.isAbsolute(target)\n ? path.resolve(target)\n : path.resolve(cwd, target);\n if (!options.restrictToCwd) return resolved;\n\n const relative = path.relative(cwd, resolved);\n if (relative.startsWith(\"..\") || path.isAbsolute(relative)) return null;\n return resolved;\n}\n\nfunction formatFileReadOutput(\n cwd: string,\n filePath: string,\n content: string,\n args: Record<string, unknown>,\n): string {\n const lines = content.split(\"\\n\");\n const offset = positiveInteger(args.offset, 1);\n const limit = positiveInteger(args.limit, lines.length - offset + 1);\n const selected = lines.slice(offset - 1, offset - 1 + limit);\n const body = selected\n .map((line, index) => `${String(offset + index).padStart(5)} | ${line}`)\n .join(\"\\n\");\n return `${path.relative(cwd, filePath) || filePath} (${lines.length} lines)\\n${body}`;\n}\n\nfunction parseEditOperations(args: Record<string, unknown>): EditOperation[] {\n const editsJson = stringArg(args.edits);\n if (editsJson.trim()) {\n let parsed: unknown;\n try {\n parsed = JSON.parse(editsJson);\n } catch (err) {\n throw new Error(\n `edits must be valid JSON: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n if (!Array.isArray(parsed) || parsed.length === 0) {\n throw new Error(\"edits must be a non-empty JSON array.\");\n }\n return parsed.map((edit, index) => {\n if (!edit || typeof edit !== \"object\") {\n throw new Error(`edits[${index}] must be an object.`);\n }\n return normalizeEditOperation(edit as Record<string, unknown>, index);\n });\n }\n\n return [normalizeEditOperation(args, 0)];\n}\n\nfunction normalizeEditOperation(\n edit: Record<string, unknown>,\n index: number,\n): EditOperation {\n const oldText = typeof edit.oldText === \"string\" ? edit.oldText : undefined;\n const newText = typeof edit.newText === \"string\" ? edit.newText : undefined;\n if (!oldText) {\n throw new Error(\n index === 0\n ? \"oldText is required and cannot be empty.\"\n : `edits[${index}].oldText is required and cannot be empty.`,\n );\n }\n if (newText === undefined) {\n throw new Error(\n index === 0\n ? \"newText is required.\"\n : `edits[${index}].newText is required.`,\n );\n }\n return {\n oldText,\n newText,\n replaceAll: stringArg(edit.replaceAll).toLowerCase() === \"true\",\n };\n}\n\nfunction countOccurrences(value: string, needle: string): number {\n let count = 0;\n let index = 0;\n while (true) {\n index = value.indexOf(needle, index);\n if (index === -1) return count;\n count += 1;\n index += needle.length;\n }\n}\n\nfunction queueFileMutation<T>(filePath: string, task: () => Promise<T> | T) {\n const previous = mutationQueues.get(filePath) ?? Promise.resolve();\n const next = previous.catch(() => undefined).then(task);\n let queued: Promise<unknown>;\n queued = next.finally(() => {\n if (mutationQueues.get(filePath) === queued)\n mutationQueues.delete(filePath);\n });\n mutationQueues.set(filePath, queued);\n return next;\n}\n\nfunction previewText(value: string): string {\n const oneLine = value.replace(/\\s+/g, \" \").trim();\n return oneLine.length > 80 ? `${oneLine.slice(0, 80)}...` : oneLine;\n}\n\nfunction stringArg(value: unknown): string {\n return typeof value === \"string\" ? value : \"\";\n}\n\nfunction positiveInteger(value: unknown, fallback: number): number {\n const parsed = Number(value);\n return Number.isFinite(parsed) && parsed > 0 ? Math.floor(parsed) : fallback;\n}\n"]}
@@ -36,6 +36,19 @@ export interface MCPConfig {
36
36
  version?: string;
37
37
  /** Action registry — same as agent chat and A2A */
38
38
  actions: Record<string, ActionEntry>;
39
+ /**
40
+ * Full ("production") action surface served to an **authenticated real
41
+ * caller** — a connect-minted token, an `agent-native mcp install` stdio
42
+ * proxy (owner-email header / `AGENT_NATIVE_OWNER_EMAIL`), or a deployed /
43
+ * `AGENT_MODE=production` app. In local dev `actions` is intentionally the
44
+ * sparse, dev-toggled surface (builtins + read-only public-agent actions)
45
+ * so the local agent chat and unauthenticated dev probes don't see every
46
+ * mutating tool; but per the external-agents contract a real caller that
47
+ * connected with a token MUST get the full surface even in dev. When unset
48
+ * (production, where `actions` already IS the full set) the swap is a
49
+ * no-op. See `external-agents` skill, "Dev vs production tool surface".
50
+ */
51
+ productionActions?: Record<string, ActionEntry>;
39
52
  /** Handler for the ask-agent meta-tool — runs the full agent loop */
40
53
  askAgent?: (message: string) => Promise<string>;
41
54
  /**
@@ -68,6 +81,15 @@ export interface MCPRequestMeta {
68
81
  origin?: string;
69
82
  /** Optional client preference for which URL the *markdown* link uses. */
70
83
  target?: "browser" | "desktop" | "terminal";
84
+ /**
85
+ * The caller authenticated with a real credential (verified A2A/connect
86
+ * JWT, matching ACCESS_TOKEN, or a forwarded owner-email header from
87
+ * `agent-native mcp install`) — not the unauthenticated local dev-open
88
+ * path. When true, `createMCPServerForRequest` serves
89
+ * `config.productionActions` (the full surface) instead of the sparse dev
90
+ * `config.actions`. Set by `mountMCP` from `verifyAuth`.
91
+ */
92
+ fullSurface?: boolean;
71
93
  }
72
94
  /**
73
95
  * Build the deep-link content block + structured `_meta` for a tool result.
@@ -144,9 +166,19 @@ export declare function getAccessTokens(): string[];
144
166
  * verified JWT identity), so the install flow runs tools as the configured
145
167
  * owner instead of an unscoped anonymous caller.
146
168
  */
147
- export declare function verifyAuth(authHeader: string | undefined, ownerEmailHeader?: string | undefined): Promise<{
169
+ export declare function verifyAuth(authHeader: string | undefined, ownerEmailHeader?: string | undefined, options?: {
170
+ allowDevOpen?: boolean;
171
+ }): Promise<{
148
172
  authed: boolean;
149
173
  identity?: MCPCallerIdentity;
174
+ /**
175
+ * The caller presented a real credential — a verified A2A/connect JWT, a
176
+ * matching ACCESS_TOKEN, or (on the no-auth-configured path) a forwarded
177
+ * owner-email header from `agent-native mcp install`. Drives the full vs
178
+ * sparse MCP tool surface in local dev. The pure unauthenticated dev-open
179
+ * path (no secret, no token, no owner header) is `false`.
180
+ */
181
+ fullSurface?: boolean;
150
182
  }>;
151
183
  export declare function resolveOrgIdFromDomain(orgDomain: string | undefined): Promise<string | undefined>;
152
184
  //# sourceMappingURL=build-server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"build-server.d.ts","sourceRoot":"","sources":["../../src/mcp/build-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAMhE,MAAM,WAAW,SAAS;IACxB,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sBA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