@buildanagent/harness 0.1.0-alpha.28 → 0.1.0-alpha.30

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 (113) hide show
  1. package/README.md +152 -5
  2. package/dist/context/file-spill.d.ts +11 -1
  3. package/dist/context/file-spill.js +23 -8
  4. package/dist/context/file-spill.js.map +1 -1
  5. package/dist/context/spill.d.ts +5 -1
  6. package/dist/context/spill.js +6 -2
  7. package/dist/context/spill.js.map +1 -1
  8. package/dist/credentials/addresses.d.ts +11 -0
  9. package/dist/credentials/addresses.js +41 -2
  10. package/dist/credentials/addresses.js.map +1 -1
  11. package/dist/credentials/allowlist.d.ts +22 -2
  12. package/dist/credentials/allowlist.js +74 -17
  13. package/dist/credentials/allowlist.js.map +1 -1
  14. package/dist/credentials/egress-policy.d.ts +69 -0
  15. package/dist/credentials/egress-policy.js +170 -0
  16. package/dist/credentials/egress-policy.js.map +1 -0
  17. package/dist/credentials/egress-proxy.d.ts +13 -1
  18. package/dist/credentials/egress-proxy.js +179 -11
  19. package/dist/credentials/egress-proxy.js.map +1 -1
  20. package/dist/credentials/git-route.d.ts +68 -0
  21. package/dist/credentials/git-route.js +288 -0
  22. package/dist/credentials/git-route.js.map +1 -0
  23. package/dist/credentials/index.d.ts +5 -1
  24. package/dist/credentials/index.js +5 -1
  25. package/dist/credentials/index.js.map +1 -1
  26. package/dist/credentials/scrub.d.ts +7 -0
  27. package/dist/credentials/scrub.js +22 -0
  28. package/dist/credentials/scrub.js.map +1 -1
  29. package/dist/errors.d.ts +14 -7
  30. package/dist/errors.js +13 -6
  31. package/dist/errors.js.map +1 -1
  32. package/dist/sandbox/base.d.ts +11 -1
  33. package/dist/sandbox/base.js +14 -0
  34. package/dist/sandbox/base.js.map +1 -1
  35. package/dist/sandbox/docker/index.d.ts +8 -2
  36. package/dist/sandbox/docker/index.js +63 -14
  37. package/dist/sandbox/docker/index.js.map +1 -1
  38. package/dist/sandbox/errors.d.ts +30 -2
  39. package/dist/sandbox/errors.js +36 -1
  40. package/dist/sandbox/errors.js.map +1 -1
  41. package/dist/sandbox/escalation-table.d.ts +38 -0
  42. package/dist/sandbox/escalation-table.js +95 -0
  43. package/dist/sandbox/escalation-table.js.map +1 -0
  44. package/dist/sandbox/escalation.d.ts +191 -0
  45. package/dist/sandbox/escalation.js +370 -0
  46. package/dist/sandbox/escalation.js.map +1 -0
  47. package/dist/sandbox/host-files.d.ts +2 -0
  48. package/dist/sandbox/host-files.js +10 -0
  49. package/dist/sandbox/host-files.js.map +1 -1
  50. package/dist/sandbox/index.d.ts +9 -4
  51. package/dist/sandbox/index.js +8 -3
  52. package/dist/sandbox/index.js.map +1 -1
  53. package/dist/sandbox/policy.d.ts +49 -0
  54. package/dist/sandbox/policy.js +149 -0
  55. package/dist/sandbox/policy.js.map +1 -0
  56. package/dist/sandbox/process.js +1 -1
  57. package/dist/sandbox/process.js.map +1 -1
  58. package/dist/sandbox/srt/index.d.ts +5 -2
  59. package/dist/sandbox/srt/index.js +27 -8
  60. package/dist/sandbox/srt/index.js.map +1 -1
  61. package/dist/sandbox/srt/settings.d.ts +17 -5
  62. package/dist/sandbox/srt/settings.js +53 -0
  63. package/dist/sandbox/srt/settings.js.map +1 -1
  64. package/dist/sandbox/types.d.ts +41 -4
  65. package/dist/sandbox/types.js.map +1 -1
  66. package/dist/sandbox/widen.d.ts +10 -0
  67. package/dist/sandbox/widen.js +150 -0
  68. package/dist/sandbox/widen.js.map +1 -0
  69. package/dist/session/approvals.d.ts +30 -1
  70. package/dist/session/approvals.js +12 -4
  71. package/dist/session/approvals.js.map +1 -1
  72. package/dist/session/code-call.d.ts +15 -1
  73. package/dist/session/code-call.js +2 -1
  74. package/dist/session/code-call.js.map +1 -1
  75. package/dist/session/escalation-log.d.ts +65 -0
  76. package/dist/session/escalation-log.js +84 -0
  77. package/dist/session/escalation-log.js.map +1 -0
  78. package/dist/session/rebuild.js +12 -3
  79. package/dist/session/rebuild.js.map +1 -1
  80. package/dist/testing/fake-sandbox.d.ts +21 -3
  81. package/dist/testing/fake-sandbox.js +157 -8
  82. package/dist/testing/fake-sandbox.js.map +1 -1
  83. package/dist/testing/sandbox-conformance.js +108 -1
  84. package/dist/testing/sandbox-conformance.js.map +1 -1
  85. package/dist/tools/builtins/bash.d.ts +9 -0
  86. package/dist/tools/builtins/bash.js +75 -0
  87. package/dist/tools/builtins/bash.js.map +1 -0
  88. package/dist/tools/builtins/builtins.d.ts +38 -0
  89. package/dist/tools/builtins/builtins.js +48 -0
  90. package/dist/tools/builtins/builtins.js.map +1 -0
  91. package/dist/tools/builtins/descriptions.d.ts +69 -0
  92. package/dist/tools/builtins/descriptions.js +94 -0
  93. package/dist/tools/builtins/descriptions.js.map +1 -0
  94. package/dist/tools/builtins/fetch.d.ts +12 -0
  95. package/dist/tools/builtins/fetch.js +157 -0
  96. package/dist/tools/builtins/fetch.js.map +1 -0
  97. package/dist/tools/builtins/files.d.ts +27 -0
  98. package/dist/tools/builtins/files.js +274 -0
  99. package/dist/tools/builtins/files.js.map +1 -0
  100. package/dist/tools/builtins/paths.d.ts +30 -0
  101. package/dist/tools/builtins/paths.js +62 -0
  102. package/dist/tools/builtins/paths.js.map +1 -0
  103. package/dist/tools/builtins/results.d.ts +15 -0
  104. package/dist/tools/builtins/results.js +31 -0
  105. package/dist/tools/builtins/results.js.map +1 -0
  106. package/dist/tools/builtins/search.d.ts +18 -0
  107. package/dist/tools/builtins/search.js +217 -0
  108. package/dist/tools/builtins/search.js.map +1 -0
  109. package/dist/tools/index.d.ts +6 -2
  110. package/dist/tools/index.js +5 -2
  111. package/dist/tools/index.js.map +1 -1
  112. package/llms.txt +52 -0
  113. package/package.json +5 -5
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.js","sourceRoot":"","sources":["../../../src/tools/builtins/files.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,UAAU,EAAwC,MAAM,mBAAmB,CAAC;AACrF,OAAO,EAAE,Y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,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;QACzB,WAAW,EAAE,GAAG,EAAE,CAAC,aAAa;QAChC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;KAC1C,CAAY,CAAC;AAChB,CAAC","sourcesContent":["/**\n * `read`, `write` and `edit`: the file tools. Each checks its path against the policy's roots before it calls the\n * sandbox, and reads and writes only through `Sandbox.readFile()` and `Sandbox.writeFile()`. `read` keeps the input\n * names `path`, `file_path`, `offset` and `limit`, which the skill loader matches when it records a skill as loaded.\n */\nimport { defineTool, type ToolDefinition, type ToolResult } from \"@buildanagent/sdk\";\nimport { escapedBytes } from \"../../context/write-cap.js\";\nimport { normalizePath } from \"../../permissions/match.js\";\nimport type { Sandbox } from \"../../sandbox/types.js\";\nimport { BUILTIN_TOOL_DEFAULTS } from \"./descriptions.js\";\nimport { type Bounds, checkPath, pathInput, unusablePath } from \"./paths.js\";\nimport { errorResult, failureResult, textResult } from \"./results.js\";\n\n/** What the file and search tools share: the sandbox, the bounds its policy sets, and the session's spill reader. */\nexport interface FileDeps {\n readonly sandbox: Sandbox;\n readonly bounds: Bounds;\n readonly spills?: (path: string) => string | undefined | Promise<string | undefined>;\n}\n\ntype AnyTool = ToolDefinition<unknown, unknown, unknown>;\n\n/**\n * Every file and search tool returns this key, so the step scheduler treats the workspace as one resource: reads run\n * together and wait for the writes the model sent before them, and a write waits for the reads before it.\n */\nexport const WORKSPACE_KEY = \"workspace\";\n\nconst ENCODER = new TextEncoder();\nconst DECODER = new TextDecoder();\n// `edit` writes the whole file back, so it reads it strictly: a byte that is not UTF-8 refuses the edit instead of\n// becoming U+FFFD, and a byte order mark stays in the text, so it is written back too.\nconst STRICT_DECODER = new TextDecoder(\"utf-8\", { fatal: true, ignoreBOM: true });\n// A NUL byte in the first part of a file marks it as binary, as grep and git decide.\nconst BINARY_PROBE_BYTES = 8000;\n\nconst PATH_PROPERTIES = {\n path: { type: \"string\", description: \"The file, relative to the workspace root or absolute.\" },\n file_path: { type: \"string\", description: \"The same as `path`, under the name some models use.\" },\n} as const;\n\ninterface ReadInput {\n readonly path?: string;\n readonly file_path?: string;\n readonly offset?: number;\n readonly column?: number;\n readonly limit?: number;\n}\n\n/**\n * The longest start of `text` whose JSON-escaped form fits in `bytes`, without splitting a character, and never less\n * than one character. Every character takes at least one byte, so the start is at most `bytes` characters long, and a\n * binary search over that range finds it in a few measures.\n */\nfunction headOf(text: string, bytes: number): string {\n let low = 0;\n let high = Math.min(text.length, bytes);\n while (low < high) {\n const middle = (low + high + 1) >> 1;\n if (escapedBytes(text.slice(0, middle)) <= bytes) low = middle;\n else high = middle - 1;\n }\n // A start that ends on the first half of a surrogate pair would split its character.\n const code = text.charCodeAt(low - 1);\n const end = low > 0 && code >= 0xd800 && code <= 0xdbff ? low - 1 : low;\n return end === 0 ? String.fromCodePoint(text.codePointAt(0) ?? 0) : text.slice(0, end);\n}\n\n/** Where a page starts and how far it may go: 0-based line indexes, and the column of the first line to start at. */\ninterface Span {\n readonly start: number;\n readonly column: number;\n readonly last: number;\n}\n\n// A page is measured as the write cap measures a result: by its bytes inside the log's JSON string. A quote, a\n// backslash or a newline takes two bytes there and a control character six, so a page budgeted by raw bytes could pass\n// the cap, be cut and spilled again, and a spill read that way would never show its whole text.\nconst NEWLINE_BYTES = escapedBytes(\"\\n\");\n\n/**\n * The lines of `span`, at most `maxBytes` of them once JSON-escaped, with a line that says where to read on when some\n * are left. A first line longer than a page is shown in part, with the column the next part starts at.\n */\nfunction pageOf(lines: readonly string[], path: string, span: Span): ToolResult {\n const { start, column, last } = span;\n const total = lines.length;\n const from = column > 0 ? { column: column + 1 } : {};\n let shown = \"\";\n let budget = BUILTIN_TOOL_DEFAULTS.read.maxBytes;\n let line = start;\n for (; line < last; line += 1) {\n const piece = line === start ? (lines[line] ?? \"\").slice(column) : (lines[line] ?? \"\");\n const size = escapedBytes(piece) + NEWLINE_BYTES;\n if (size > budget && line > start) break;\n if (size > budget) {\n const part = headOf(piece, budget - NEWLINE_BYTES);\n const more = `[line ${line + 1} of ${total} goes on; read on with offset ${line + 1} and column ${column + part.length + 1}]`;\n return textResult(`${part}\\n${more}`, { path, from: line + 1, to: line + 1, ...from, lines: total });\n }\n shown += `${piece}\\n`;\n budget -= size;\n }\n const more = line < total ? `[lines ${start + 1} to ${line} of ${total}; read on with offset ${line + 1}]` : \"\";\n return textResult(`${shown}${more}`, { path, from: start + 1, to: line, ...from, lines: total });\n}\n\n/**\n * The part of `text` that `offset`, `column` and `limit` select, at most `maxBytes` of it once JSON-escaped. A line\n * longer than a page is shown in parts, each naming the column the next starts at, so every byte of a long result can\n * be read, even one that is a single line.\n */\nfunction page(text: string, path: string, input: ReadInput): ToolResult {\n const { defaultLimit, maxBytes } = BUILTIN_TOOL_DEFAULTS.read;\n if (text === \"\") return textResult(`(${path} is empty)`, { path, lines: 0 });\n const lines = text.split(\"\\n\");\n if (text.endsWith(\"\\n\")) lines.pop();\n const total = lines.length;\n const unpaged = input.offset === undefined && input.limit === undefined && input.column === undefined;\n if (unpaged && total <= defaultLimit && escapedBytes(text) <= maxBytes)\n return textResult(text, { path, lines: total });\n const start = (input.offset ?? 1) - 1;\n if (start >= total)\n return errorResult(`The offset ${start + 1} is past the end of ${path}, which has ${total} lines.`);\n const column = (input.column ?? 1) - 1;\n if (column > 0 && column >= (lines[start] ?? \"\").length) {\n return errorResult(`The column ${column + 1} is past the end of line ${start + 1} of ${path}, which is shorter.`);\n }\n return pageOf(lines, path, { start, column, last: Math.min(total, start + (input.limit ?? defaultLimit)) });\n}\n\nasync function readFile(deps: FileDeps, input: ReadInput): Promise<ToolResult> {\n const chosen = pathInput(input);\n if (typeof chosen !== \"string\") return errorResult(chosen.refused);\n const unusable = unusablePath(chosen);\n if (unusable !== undefined) return errorResult(unusable);\n // A spill file is the harness's own copy of an earlier result, outside the sandbox, and the cap names it by an\n // absolute path. Only such a path asks the spill reader, so a relative path always means a workspace file, never a\n // spill that happens to share its name.\n if (deps.spills !== undefined && chosen.startsWith(\"/\")) {\n const spillPath = normalizePath(chosen);\n const spilled = await deps.spills(spillPath);\n if (spilled !== undefined) return page(spilled, spillPath, input);\n }\n const checked = checkPath(deps.bounds, chosen, \"read\");\n if (\"refused\" in checked) return errorResult(checked.refused);\n let bytes: Uint8Array;\n try {\n bytes = await deps.sandbox.readFile(checked.path);\n } catch (error) {\n return failureResult(error);\n }\n if (bytes.subarray(0, BINARY_PROBE_BYTES).includes(0)) {\n return errorResult(`${checked.path} is a binary file of ${bytes.length} bytes, and read returns only text.`);\n }\n return page(DECODER.decode(bytes), checked.path, input);\n}\n\n/** The `read` tool. */\nexport function readTool(deps: FileDeps): AnyTool {\n return defineTool<ReadInput>({\n name: \"read\",\n description: BUILTIN_TOOL_DEFAULTS.read.description,\n inputSchema: {\n type: \"object\",\n properties: {\n ...PATH_PROPERTIES,\n offset: { type: \"integer\", minimum: 1, description: \"The first line to read, counting from 1.\" },\n column: {\n type: \"integer\",\n minimum: 1,\n description: \"Where to start in the first line, counting from 1, to read on in a line too long for one page.\",\n },\n limit: { type: \"integer\", minimum: 1, description: \"How many lines to read.\" },\n },\n additionalProperties: false,\n },\n firstParty: true,\n annotations: { readOnlyHint: true },\n resourceKey: () => WORKSPACE_KEY,\n execute: (input) => readFile(deps, input),\n }) as AnyTool;\n}\n\ninterface WriteInput {\n readonly path?: string;\n readonly file_path?: string;\n readonly content: string;\n}\n\n/** The `write` tool. */\nexport function writeTool(deps: FileDeps): AnyTool {\n return defineTool<WriteInput>({\n name: \"write\",\n description: BUILTIN_TOOL_DEFAULTS.write.description,\n inputSchema: {\n type: \"object\",\n properties: { ...PATH_PROPERTIES, content: { type: \"string\", description: \"The file's whole new text.\" } },\n required: [\"content\"],\n additionalProperties: false,\n },\n firstParty: true,\n effect: { kind: \"write\" },\n resourceKey: () => WORKSPACE_KEY,\n async execute(input) {\n const chosen = pathInput(input);\n if (typeof chosen !== \"string\") return errorResult(chosen.refused);\n const checked = checkPath(deps.bounds, chosen, \"write\");\n if (\"refused\" in checked) return errorResult(checked.refused);\n const bytes = ENCODER.encode(input.content);\n try {\n await deps.sandbox.writeFile(checked.path, bytes);\n } catch (error) {\n return failureResult(error);\n }\n return textResult(`Wrote ${bytes.length} bytes to ${checked.path}.`, { path: checked.path, bytes: bytes.length });\n },\n }) as AnyTool;\n}\n\ninterface EditInput {\n readonly path?: string;\n readonly file_path?: string;\n readonly old_string: string;\n readonly new_string: string;\n readonly replace_all?: boolean;\n}\n\n/** How many times `needle` occurs in `text`, counting matches that don't overlap. */\nfunction occurrences(text: string, needle: string): number {\n let count = 0;\n for (let at = text.indexOf(needle); at >= 0; at = text.indexOf(needle, at + needle.length)) count += 1;\n return count;\n}\n\n/** The edited text, or the sentence that says why the edit can't be made and nothing was changed. */\nfunction edited(text: string, input: EditInput, path: string): string | { refused: string } {\n if (input.old_string === \"\") return { refused: \"`old_string` is empty; use write to create or replace a file.\" };\n if (input.old_string === input.new_string) return { refused: \"`old_string` and `new_string` are the same.\" };\n const count = occurrences(text, input.old_string);\n if (count === 0) return { refused: `\\`old_string\\` does not occur in ${path}, so nothing was changed.` };\n if (count > 1 && input.replace_all !== true) {\n return {\n refused:\n `\\`old_string\\` occurs ${count} times in ${path}, so nothing was changed. Add surrounding lines until it ` +\n \"is unique, or set `replace_all` to replace every match.\",\n };\n }\n // A function replacement keeps `$&` and the other replacement patterns in `new_string` as written.\n return input.replace_all === true\n ? text.replaceAll(input.old_string, () => input.new_string)\n : text.replace(input.old_string, () => input.new_string);\n}\n\nasync function editFile(deps: FileDeps, input: EditInput): Promise<ToolResult> {\n const chosen = pathInput(input);\n if (typeof chosen !== \"string\") return errorResult(chosen.refused);\n const checked = checkPath(deps.bounds, chosen, \"write\");\n if (\"refused\" in checked) return errorResult(checked.refused);\n try {\n const bytes = await deps.sandbox.readFile(checked.path);\n if (bytes.subarray(0, BINARY_PROBE_BYTES).includes(0)) {\n return errorResult(`${checked.path} is a binary file, and edit changes only text, so nothing was changed.`);\n }\n let text: string;\n try {\n text = STRICT_DECODER.decode(bytes);\n } catch {\n return errorResult(\n `${checked.path} is not UTF-8 text, and edit would corrupt it, so nothing was changed. Use bash to change it.`,\n );\n }\n const next = edited(text, input, checked.path);\n if (typeof next !== \"string\") return errorResult(next.refused);\n await deps.sandbox.writeFile(checked.path, ENCODER.encode(next));\n const count = input.replace_all === true ? occurrences(text, input.old_string) : 1;\n return textResult(`Replaced ${count} match${count === 1 ? \"\" : \"es\"} in ${checked.path}.`, {\n path: checked.path,\n replaced: count,\n });\n } catch (error) {\n return failureResult(error);\n }\n}\n\n/** The `edit` tool. */\nexport function editTool(deps: FileDeps): AnyTool {\n return defineTool<EditInput>({\n name: \"edit\",\n description: BUILTIN_TOOL_DEFAULTS.edit.description,\n inputSchema: {\n type: \"object\",\n properties: {\n ...PATH_PROPERTIES,\n old_string: { type: \"string\", description: \"The exact text to replace.\" },\n new_string: { type: \"string\", description: \"The text to put in its place.\" },\n replace_all: { type: \"boolean\", description: \"Replace every match instead of requiring exactly one.\" },\n },\n required: [\"old_string\", \"new_string\"],\n additionalProperties: false,\n },\n firstParty: true,\n effect: { kind: \"write\" },\n resourceKey: () => WORKSPACE_KEY,\n execute: (input) => editFile(deps, input),\n }) as AnyTool;\n}\n"]}
@@ -0,0 +1,30 @@
1
+ import type { SandboxPolicy } from "../../sandbox/types.js";
2
+ /** What a file tool may touch: the workspace root and the policy's roots, each absolute and without `.` or `..`. */
3
+ export interface Bounds {
4
+ readonly root: string;
5
+ readonly read: readonly string[];
6
+ readonly write: readonly string[];
7
+ }
8
+ /** A path inside the roots, or the sentence that tells the model why it is refused. */
9
+ export type Checked = {
10
+ readonly path: string;
11
+ } | {
12
+ readonly refused: string;
13
+ };
14
+ /** The bounds of a workspace, checked once, so a relative root can't make every path resolve somewhere unexpected. */
15
+ export declare function boundsOf(root: string, policy: SandboxPolicy): Bounds;
16
+ /**
17
+ * Why `path` can't name a file, or `undefined` when it can. A backslash is refused because the workspace is a POSIX
18
+ * one, where `\` is part of a name, while the permission rules' matcher reads it as a separator: refusing it keeps the
19
+ * path a rule checked, the path the skill loader matches and the file the sandbox opens the same.
20
+ */
21
+ export declare function unusablePath(path: string): string | undefined;
22
+ /** The absolute form of `path` against the root, or a refusal when it is outside the roots for `access`. */
23
+ export declare function checkPath(bounds: Bounds, path: string, access: "read" | "write"): Checked;
24
+ /** The tool input's path, from `path` or `file_path`; both may be given only when they agree. */
25
+ export declare function pathInput(input: {
26
+ readonly path?: string;
27
+ readonly file_path?: string;
28
+ }): string | {
29
+ refused: string;
30
+ };
@@ -0,0 +1,62 @@
1
+ /**
2
+ * The path check every file tool makes before it calls the sandbox. It works on the path's text: it joins a relative
3
+ * path to the workspace root, removes `.` and `..`, and refuses a path outside the roots.
4
+ *
5
+ * It can't see a symlink, because the sandbox interface has no call that resolves one, so the sandbox's own check of
6
+ * the real path stays the second line, and its denial becomes the tool's error result. The tool hands the sandbox the
7
+ * path it checked, never the model's text, so the two checks see the same path.
8
+ */
9
+ import { HarnessError } from "../../errors.js";
10
+ import { normalizePath } from "../../permissions/match.js";
11
+ const within = (path, root) => root === "/" || path === root || path.startsWith(`${root}/`);
12
+ function absolute(path, what) {
13
+ if (typeof path !== "string" || !path.startsWith("/")) {
14
+ throw new HarnessError("invalid_tool_options", `${what} must be an absolute path, not ${JSON.stringify(path)}`);
15
+ }
16
+ return normalizePath(path);
17
+ }
18
+ /** The bounds of a workspace, checked once, so a relative root can't make every path resolve somewhere unexpected. */
19
+ export function boundsOf(root, policy) {
20
+ if (!Array.isArray(policy?.readRoots) || !Array.isArray(policy.writeRoots)) {
21
+ throw new HarnessError("invalid_tool_options", "the built-in tools need the sandbox policy's readRoots and writeRoots");
22
+ }
23
+ const write = policy.writeRoots.map((path) => absolute(path, "a write root"));
24
+ // The write roots are readable too, as the sandbox policy says.
25
+ const read = [...policy.readRoots.map((path) => absolute(path, "a read root")), ...write];
26
+ return { root: absolute(root, "the workspace root"), read, write };
27
+ }
28
+ /**
29
+ * Why `path` can't name a file, or `undefined` when it can. A backslash is refused because the workspace is a POSIX
30
+ * one, where `\` is part of a name, while the permission rules' matcher reads it as a separator: refusing it keeps the
31
+ * path a rule checked, the path the skill loader matches and the file the sandbox opens the same.
32
+ */
33
+ export function unusablePath(path) {
34
+ if (path === "" || path.includes("\u0000"))
35
+ return `The path ${JSON.stringify(path)} is not a usable path.`;
36
+ if (path.includes("\\")) {
37
+ return `The path ${path} holds a backslash; separate folders with \`/\`, because \`\\\` is not a separator here.`;
38
+ }
39
+ return undefined;
40
+ }
41
+ /** The absolute form of `path` against the root, or a refusal when it is outside the roots for `access`. */
42
+ export function checkPath(bounds, path, access) {
43
+ const unusable = unusablePath(path);
44
+ if (unusable !== undefined)
45
+ return { refused: unusable };
46
+ const resolved = normalizePath(path.startsWith("/") ? path : `${bounds.root}/${path}`);
47
+ const roots = access === "write" ? bounds.write : bounds.read;
48
+ if (roots.some((root) => within(resolved, root)))
49
+ return { path: resolved };
50
+ const where = roots.length === 0 ? "no folder" : roots.join(", ");
51
+ return { refused: `The path ${path} is outside the folders this tool may ${access}: ${where}.` };
52
+ }
53
+ /** The tool input's path, from `path` or `file_path`; both may be given only when they agree. */
54
+ export function pathInput(input) {
55
+ const { path, file_path: filePath } = input;
56
+ if (path !== undefined && filePath !== undefined && path !== filePath) {
57
+ return { refused: "Pass the file as `path` or as `file_path`, not two different paths." };
58
+ }
59
+ const chosen = filePath ?? path;
60
+ return chosen === undefined ? { refused: "Pass the file to use as `path`." } : chosen;
61
+ }
62
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.js","sourceRoot":"","sources":["../../../src/tools/builtins/paths.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAa3D,MAAM,MAAM,GAAG,CAAC,IAAY,EA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S,CAAC,KAGzB;IACC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAC5C,IAAI,IAAI,KAAK,SAAS,IAAI,QAAQ,KAAK,SAAS,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtE,OAAO,EAAE,OAAO,EAAE,qEAAqE,EAAE,CAAC;IAC5F,CAAC;IACD,MAAM,MAAM,GAAG,QAAQ,IAAI,IAAI,CAAC;IAChC,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,iCAAiC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;AACxF,CAAC","sourcesContent":["/**\n * The path check every file tool makes before it calls the sandbox. It works on the path's text: it joins a relative\n * path to the workspace root, removes `.` and `..`, and refuses a path outside the roots.\n *\n * It can't see a symlink, because the sandbox interface has no call that resolves one, so the sandbox's own check of\n * the real path stays the second line, and its denial becomes the tool's error result. The tool hands the sandbox the\n * path it checked, never the model's text, so the two checks see the same path.\n */\nimport { HarnessError } from \"../../errors.js\";\nimport { normalizePath } from \"../../permissions/match.js\";\nimport type { SandboxPolicy } from \"../../sandbox/types.js\";\n\n/** What a file tool may touch: the workspace root and the policy's roots, each absolute and without `.` or `..`. */\nexport interface Bounds {\n readonly root: string;\n readonly read: readonly string[];\n readonly write: readonly string[];\n}\n\n/** A path inside the roots, or the sentence that tells the model why it is refused. */\nexport type Checked = { readonly path: string } | { readonly refused: string };\n\nconst within = (path: string, root: string): boolean => root === \"/\" || path === root || path.startsWith(`${root}/`);\n\nfunction absolute(path: unknown, what: string): string {\n if (typeof path !== \"string\" || !path.startsWith(\"/\")) {\n throw new HarnessError(\"invalid_tool_options\", `${what} must be an absolute path, not ${JSON.stringify(path)}`);\n }\n return normalizePath(path);\n}\n\n/** The bounds of a workspace, checked once, so a relative root can't make every path resolve somewhere unexpected. */\nexport function boundsOf(root: string, policy: SandboxPolicy): Bounds {\n if (!Array.isArray(policy?.readRoots) || !Array.isArray(policy.writeRoots)) {\n throw new HarnessError(\n \"invalid_tool_options\",\n \"the built-in tools need the sandbox policy's readRoots and writeRoots\",\n );\n }\n const write = policy.writeRoots.map((path) => absolute(path, \"a write root\"));\n // The write roots are readable too, as the sandbox policy says.\n const read = [...policy.readRoots.map((path) => absolute(path, \"a read root\")), ...write];\n return { root: absolute(root, \"the workspace root\"), read, write };\n}\n\n/**\n * Why `path` can't name a file, or `undefined` when it can. A backslash is refused because the workspace is a POSIX\n * one, where `\\` is part of a name, while the permission rules' matcher reads it as a separator: refusing it keeps the\n * path a rule checked, the path the skill loader matches and the file the sandbox opens the same.\n */\nexport function unusablePath(path: string): string | undefined {\n if (path === \"\" || path.includes(\"\\u0000\")) return `The path ${JSON.stringify(path)} is not a usable path.`;\n if (path.includes(\"\\\\\")) {\n return `The path ${path} holds a backslash; separate folders with \\`/\\`, because \\`\\\\\\` is not a separator here.`;\n }\n return undefined;\n}\n\n/** The absolute form of `path` against the root, or a refusal when it is outside the roots for `access`. */\nexport function checkPath(bounds: Bounds, path: string, access: \"read\" | \"write\"): Checked {\n const unusable = unusablePath(path);\n if (unusable !== undefined) return { refused: unusable };\n const resolved = normalizePath(path.startsWith(\"/\") ? path : `${bounds.root}/${path}`);\n const roots = access === \"write\" ? bounds.write : bounds.read;\n if (roots.some((root) => within(resolved, root))) return { path: resolved };\n const where = roots.length === 0 ? \"no folder\" : roots.join(\", \");\n return { refused: `The path ${path} is outside the folders this tool may ${access}: ${where}.` };\n}\n\n/** The tool input's path, from `path` or `file_path`; both may be given only when they agree. */\nexport function pathInput(input: {\n readonly path?: string;\n readonly file_path?: string;\n}): string | { refused: string } {\n const { path, file_path: filePath } = input;\n if (path !== undefined && filePath !== undefined && path !== filePath) {\n return { refused: \"Pass the file as `path` or as `file_path`, not two different paths.\" };\n }\n const chosen = filePath ?? path;\n return chosen === undefined ? { refused: \"Pass the file to use as `path`.\" } : chosen;\n}\n"]}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The results the built-in tools return. A refusal or a failed file call is a result the model reads and can act on,
3
+ * not a thrown error, so the model sees one plain sentence instead of the SDK's generic failure text. A thrown error
4
+ * that is not one of those, such as a disposed sandbox, is a fault of the host and propagates.
5
+ */
6
+ import type { ToolResult } from "@buildanagent/sdk";
7
+ import type { SandboxDenial } from "../../sandbox/types.js";
8
+ /** A result of one text block. */
9
+ export declare function textResult(text: string, details?: unknown): ToolResult;
10
+ /** An error result of one text block. */
11
+ export declare function errorResult(text: string): ToolResult;
12
+ /** The error result for a command the sandbox's policy stopped. */
13
+ export declare function deniedResult(denial: SandboxDenial): ToolResult;
14
+ /** The error result for a failure the model caused, or the error itself, rethrown, for any other. */
15
+ export declare function failureResult(error: unknown): ToolResult;
@@ -0,0 +1,31 @@
1
+ import { isHarnessError } from "../../errors.js";
2
+ /** A result of one text block. */
3
+ export function textResult(text, details) {
4
+ return { content: [{ type: "text", text }], ...(details === undefined ? {} : { details }) };
5
+ }
6
+ /** An error result of one text block. */
7
+ export function errorResult(text) {
8
+ return { content: [{ type: "text", text }], isError: true };
9
+ }
10
+ /** The error result for a command the sandbox's policy stopped. */
11
+ export function deniedResult(denial) {
12
+ return errorResult(`The sandbox denied a ${denial.kind.replace("_", " ")} of ${denial.target}: ${denial.reason}.`);
13
+ }
14
+ // The failures that come from what the model asked for: a path the policy refuses, a missing file, a file the call
15
+ // could not read, and a host the egress proxy refuses.
16
+ const MODEL_FAILURES = new Set([
17
+ "sandbox_denied",
18
+ "sandbox_not_found",
19
+ "sandbox_io_failed",
20
+ "egress_denied",
21
+ ]);
22
+ /** The error result for a failure the model caused, or the error itself, rethrown, for any other. */
23
+ export function failureResult(error) {
24
+ if (isHarnessError(error) && MODEL_FAILURES.has(error.code)) {
25
+ const sentence = `${error.message.charAt(0).toUpperCase()}${error.message.slice(1)}`;
26
+ // A message that already ends a sentence keeps its own stop, so the model never reads "x..".
27
+ return errorResult(/[.!?]$/.test(sentence) ? sentence : `${sentence}.`);
28
+ }
29
+ throw error;
30
+ }
31
+ //# sourceMappingURL=results.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"results.js","sourceRoot":"","sources":["../../../src/tools/builtins/results.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjD,kCAAkC;AAClC,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,OAAiB;IACxD,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;AAC9F,CAAC;AAED,yCAAyC;AACzC,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC9D,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,YAAY,CAAC,MAAqB;IAChD,OAAO,WAAW,CAAC,wBAAwB,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;AACrH,CAAC;AAED,mHAAmH;AACnH,uDAAuD;AACvD,MAAM,cAAc,GAAwB,IAAI,GAAG,CAAC;IAClD,gBAAgB;IAChB,mBAAmB;IACnB,mBAAmB;IACnB,eAAe;CAChB,CAAC,CAAC;AAEH,qGAAqG;AACrG,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,IAAI,cAAc,CAAC,KAAK,CAAC,IAAI,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5D,MAAM,QAAQ,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QACrF,6FAA6F;QAC7F,OAAO,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,GAAG,CAAC,CAAC;IAC1E,CAAC;IACD,MAAM,KAAK,CAAC;AACd,CAAC","sourcesContent":["/**\n * The results the built-in tools return. A refusal or a failed file call is a result the model reads and can act on,\n * not a thrown error, so the model sees one plain sentence instead of the SDK's generic failure text. A thrown error\n * that is not one of those, such as a disposed sandbox, is a fault of the host and propagates.\n */\nimport type { ToolResult } from \"@buildanagent/sdk\";\nimport { isHarnessError } from \"../../errors.js\";\nimport type { SandboxDenial } from \"../../sandbox/types.js\";\n\n/** A result of one text block. */\nexport function textResult(text: string, details?: unknown): ToolResult {\n return { content: [{ type: \"text\", text }], ...(details === undefined ? {} : { details }) };\n}\n\n/** An error result of one text block. */\nexport function errorResult(text: string): ToolResult {\n return { content: [{ type: \"text\", text }], isError: true };\n}\n\n/** The error result for a command the sandbox's policy stopped. */\nexport function deniedResult(denial: SandboxDenial): ToolResult {\n return errorResult(`The sandbox denied a ${denial.kind.replace(\"_\", \" \")} of ${denial.target}: ${denial.reason}.`);\n}\n\n// The failures that come from what the model asked for: a path the policy refuses, a missing file, a file the call\n// could not read, and a host the egress proxy refuses.\nconst MODEL_FAILURES: ReadonlySet<string> = new Set([\n \"sandbox_denied\",\n \"sandbox_not_found\",\n \"sandbox_io_failed\",\n \"egress_denied\",\n]);\n\n/** The error result for a failure the model caused, or the error itself, rethrown, for any other. */\nexport function failureResult(error: unknown): ToolResult {\n if (isHarnessError(error) && MODEL_FAILURES.has(error.code)) {\n const sentence = `${error.message.charAt(0).toUpperCase()}${error.message.slice(1)}`;\n // A message that already ends a sentence keeps its own stop, so the model never reads \"x..\".\n return errorResult(/[.!?]$/.test(sentence) ? sentence : `${sentence}.`);\n }\n throw error;\n}\n"]}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * `grep` and `glob`: read-only search, run inside the sandbox with `find` and `grep`, so a pattern the model wrote is
3
+ * matched by a sandboxed process with a timeout and never by a regular expression in the host's own loop. Both list
4
+ * files with `find`, which never follows a symlink, and filter the list here with the permission rules' own glob
5
+ * matcher, so `glob` and `grep`'s file filter read a pattern the same way on every backend.
6
+ */
7
+ import { type ToolDefinition } from "@buildanagent/sdk";
8
+ import { type FileDeps } from "./files.js";
9
+ type AnyTool = ToolDefinition<unknown, unknown, unknown>;
10
+ /** What the search tools share with the file tools, plus the environment their commands run with. */
11
+ export interface SearchDeps extends FileDeps {
12
+ readonly env: Readonly<Record<string, string>>;
13
+ }
14
+ /** The `glob` tool. */
15
+ export declare function globTool(deps: SearchDeps): AnyTool;
16
+ /** The `grep` tool. */
17
+ export declare function grepTool(deps: SearchDeps): AnyTool;
18
+ export {};
@@ -0,0 +1,217 @@
1
+ /**
2
+ * `grep` and `glob`: read-only search, run inside the sandbox with `find` and `grep`, so a pattern the model wrote is
3
+ * matched by a sandboxed process with a timeout and never by a regular expression in the host's own loop. Both list
4
+ * files with `find`, which never follows a symlink, and filter the list here with the permission rules' own glob
5
+ * matcher, so `glob` and `grep`'s file filter read a pattern the same way on every backend.
6
+ */
7
+ import { defineTool } from "@buildanagent/sdk";
8
+ import { globToRegExp } from "../../permissions/match.js";
9
+ import { BUILTIN_TOOL_DEFAULTS } from "./descriptions.js";
10
+ import { WORKSPACE_KEY } from "./files.js";
11
+ import { checkPath } from "./paths.js";
12
+ import { deniedResult, errorResult, failureResult, textResult } from "./results.js";
13
+ const ENCODER = new TextEncoder();
14
+ const DECODER = new TextDecoder();
15
+ // The most bytes of a command's standard error a warning quotes, so many unreadable files can't flood the result.
16
+ const WARNING_BYTES = 2048;
17
+ /** The line that tells the model a command failed on part of its input, quoting its first lines of standard error. */
18
+ function warningOf(what, result) {
19
+ const stderr = result.stderr.trim();
20
+ const quoted = stderr.length > WARNING_BYTES ? `${stderr.slice(0, WARNING_BYTES)}...` : stderr;
21
+ return `\n[${what} exited with ${result.exitCode}, so some files may be missing: ${quoted}]`;
22
+ }
23
+ async function exec(deps, command, options, signal) {
24
+ return deps.sandbox.exec(command, { env: deps.env, signal, ...options });
25
+ }
26
+ /** `path` as a `find -path` pattern that matches only itself. */
27
+ const literalPattern = (path) => path.replace(/[\\*?[\]]/g, "\\$&");
28
+ /** Lists the regular files under `base` inside the sandbox, skipping the folders search never enters. */
29
+ async function listFiles(deps, base, timeoutMs, signal) {
30
+ const skipped = BUILTIN_TOOL_DEFAULTS.search.skippedFolders.flatMap((name, index) => index === 0 ? ["-name", name] : ["-o", "-name", name]);
31
+ // The starting point is exempt from the prune, so a search of `node_modules` itself still lists its files.
32
+ const prune = ["(", "!", "-path", literalPattern(base), "(", ...skipped, ")", "-prune", ")"];
33
+ const command = ["find", base, ...prune, "-o", "-type", "f", "-print0"];
34
+ let result;
35
+ try {
36
+ result = await exec(deps, command, { timeoutMs }, signal);
37
+ }
38
+ catch (error) {
39
+ return { result: failureResult(error) };
40
+ }
41
+ if ("denied" in result)
42
+ return { result: deniedResult(result.denied) };
43
+ const names = result.stdout.split("\u0000");
44
+ // The last name is empty after a whole listing, and only part of a path when the output was cut.
45
+ names.pop();
46
+ // find exits with 1 when it could not read part of the tree, and still prints what it could: keep that.
47
+ if (result.exitCode !== 0 && names.length === 0) {
48
+ return { result: errorResult(`Listing ${base} failed with exit code ${result.exitCode}: ${result.stderr.trim()}`) };
49
+ }
50
+ const warning = result.exitCode === 0 ? "" : warningOf("find", result);
51
+ return { files: names, cut: result.truncated === true, warning };
52
+ }
53
+ // A base of "/" already ends in the separator, so the slice starts right after it.
54
+ const relativeTo = (base, path) => path === base ? (path.split("/").at(-1) ?? "") : path.slice(base === "/" ? 1 : base.length + 1);
55
+ /** A filter for the listed files: an absolute glob matches the whole path, and a relative one the path below `base`. */
56
+ function matcher(pattern, base, byName) {
57
+ const regex = globToRegExp(pattern);
58
+ if (pattern.startsWith("/"))
59
+ return (path) => regex.test(path);
60
+ if (byName && !pattern.includes("/"))
61
+ return (path) => regex.test(path.split("/").at(-1) ?? "");
62
+ return (path) => regex.test(relativeTo(base, path));
63
+ }
64
+ async function globFiles(deps, input, signal) {
65
+ const checked = checkPath(deps.bounds, input.path ?? deps.bounds.root, "read");
66
+ if ("refused" in checked)
67
+ return errorResult(checked.refused);
68
+ const listing = await listFiles(deps, checked.path, BUILTIN_TOOL_DEFAULTS.glob.timeoutMs, signal);
69
+ if ("result" in listing)
70
+ return listing.result;
71
+ const matches = matcher(input.pattern, checked.path, false);
72
+ const found = listing.files.filter(matches).sort();
73
+ const cut = `${listing.cut ? "\n[the file listing was cut, so some matches may be missing]" : ""}${listing.warning}`;
74
+ if (found.length === 0)
75
+ return textResult(`No file under ${checked.path} matches ${input.pattern}.${cut}`);
76
+ return textResult(`${found.join("\n")}${cut}`, { files: found.length });
77
+ }
78
+ /** The `glob` tool. */
79
+ export function globTool(deps) {
80
+ return defineTool({
81
+ name: "glob",
82
+ description: BUILTIN_TOOL_DEFAULTS.glob.description,
83
+ inputSchema: {
84
+ type: "object",
85
+ properties: {
86
+ pattern: { type: "string", minLength: 1, description: "The glob to match, such as `**/*.ts`." },
87
+ path: { type: "string", description: "The folder to search, relative to the workspace root or absolute." },
88
+ },
89
+ required: ["pattern"],
90
+ additionalProperties: false,
91
+ },
92
+ firstParty: true,
93
+ annotations: { readOnlyHint: true },
94
+ resourceKey: () => WORKSPACE_KEY,
95
+ execute: (input, ctx) => globFiles(deps, input, ctx.signal),
96
+ });
97
+ }
98
+ /**
99
+ * Where grep's first match in `stdout` is: the file of `batch` that the output starts with, and its line number. grep
100
+ * prints `path:line:text`, and a path may itself hold a colon, so the path is matched against the files searched.
101
+ */
102
+ function firstMatch(stdout, batch) {
103
+ const path = batch.find((file) => stdout.startsWith(`${file}:`));
104
+ if (path === undefined)
105
+ return {};
106
+ const line = /^(\d+):/.exec(stdout.slice(path.length + 1))?.[1];
107
+ return line === undefined ? { path } : { path, line: Number(line) };
108
+ }
109
+ /** The longest start of `text` that ends a line and fits in `bytes` UTF-8 bytes. */
110
+ function wholeLines(text, bytes) {
111
+ const encoded = ENCODER.encode(text);
112
+ if (encoded.length <= bytes)
113
+ return text.endsWith("\n") ? text : text.slice(0, text.lastIndexOf("\n") + 1);
114
+ const end = encoded.subarray(0, bytes).lastIndexOf(10);
115
+ return DECODER.decode(encoded.subarray(0, end + 1));
116
+ }
117
+ /** Runs one `grep` command over `batch`, and returns what it did, or the result that ends the call. */
118
+ async function grepBatch(deps, flags, batch, signal) {
119
+ const { timeoutMs, maxOutputBytes } = BUILTIN_TOOL_DEFAULTS.grep;
120
+ let result;
121
+ try {
122
+ result = await exec(deps, ["grep", ...flags, "--", ...batch], { timeoutMs, maxOutputBytes }, signal);
123
+ }
124
+ catch (error) {
125
+ return { result: failureResult(error) };
126
+ }
127
+ return "denied" in result ? { result: deniedResult(result.denied) } : result;
128
+ }
129
+ const CUT_NOTICE = `\n[the matches passed ${BUILTIN_TOOL_DEFAULTS.grep.maxOutputBytes} bytes, so the rest were dropped and some files ` +
130
+ "were not searched; narrow the pattern, path or glob to see them]";
131
+ /**
132
+ * Runs `grep` over `files` in batches, and returns the matching lines, or the result that ends the call. The lines stop
133
+ * at the tool's output cap, across all the batches, and a batch with a file grep could not read keeps its matches and
134
+ * adds a warning. The call fails only when no batch matched and one failed, as an unreadable pattern makes every one.
135
+ */
136
+ async function grepFiles(deps, input, files, signal) {
137
+ const { filesPerCommand } = BUILTIN_TOOL_DEFAULTS.search;
138
+ const { maxOutputBytes } = BUILTIN_TOOL_DEFAULTS.grep;
139
+ const flags = ["-n", "-H", "-I", "-E", ...(input.ignore_case === true ? ["-i"] : []), "-e", input.pattern];
140
+ let lines = "";
141
+ let size = 0;
142
+ let failed;
143
+ const warning = () => (failed === undefined ? "" : warningOf("grep", failed));
144
+ for (let at = 0; at < files.length; at += filesPerCommand) {
145
+ const batch = files.slice(at, at + filesPerCommand);
146
+ const result = await grepBatch(deps, flags, batch, signal);
147
+ if ("result" in result)
148
+ return result;
149
+ // grep exits with 1 when nothing matched, and with 2 for an error, such as a file it can't read or a bad pattern.
150
+ if (result.exitCode > 1)
151
+ failed ??= result;
152
+ // A cut stream ends part way through a line, so only its whole lines are kept.
153
+ const kept = wholeLines(result.stdout, maxOutputBytes - size);
154
+ lines += kept;
155
+ size += ENCODER.encode(kept).length;
156
+ if (result.truncated === true || kept.length < result.stdout.length) {
157
+ // A match whose line alone passes the cap leaves no whole line to show, but it is still a match: say so, so the
158
+ // model never reads that the pattern matched nothing.
159
+ const tooLong = lines === "" && result.stdout !== "" ? { tooLong: firstMatch(result.stdout, batch) } : {};
160
+ return { lines, notes: `${CUT_NOTICE}${warning()}`, ...tooLong };
161
+ }
162
+ }
163
+ if (failed !== undefined && lines === "")
164
+ return { result: errorResult(`grep failed: ${failed.stderr.trim()}`) };
165
+ return { lines, notes: warning() };
166
+ }
167
+ /** The sentence for matches whose lines are each too long to show: they exist, where the first is, and what to do. */
168
+ function tooLongSentence(base, pattern, first) {
169
+ const { maxOutputBytes } = BUILTIN_TOOL_DEFAULTS.grep;
170
+ const where = first.path === undefined
171
+ ? ""
172
+ : ` The first is in ${first.path}${first.line === undefined ? "" : `, on line ${first.line}`}.`;
173
+ return (`Lines under ${base} match ${pattern}, but the first matching line is longer than ${maxOutputBytes} bytes, so ` +
174
+ `none can be shown.${where} Narrow the pattern, path or glob, or read the matching file with read, in parts.`);
175
+ }
176
+ async function grep(deps, input, signal) {
177
+ const checked = checkPath(deps.bounds, input.path ?? deps.bounds.root, "read");
178
+ if ("refused" in checked)
179
+ return errorResult(checked.refused);
180
+ const listing = await listFiles(deps, checked.path, BUILTIN_TOOL_DEFAULTS.grep.timeoutMs, signal);
181
+ if ("result" in listing)
182
+ return listing.result;
183
+ const files = input.glob === undefined ? listing.files : listing.files.filter(matcher(input.glob, checked.path, true));
184
+ const found = files.length === 0 ? { lines: "", notes: "" } : await grepFiles(deps, input, [...files].sort(), signal);
185
+ if ("result" in found)
186
+ return found.result;
187
+ const cut = listing.cut ? "\n[the file listing was cut, so some files were not searched]" : "";
188
+ const notes = `${found.notes}${cut}${listing.warning}`;
189
+ if (found.tooLong !== undefined)
190
+ return textResult(`${tooLongSentence(checked.path, input.pattern, found.tooLong)}${notes}`);
191
+ if (found.lines === "")
192
+ return textResult(`No line under ${checked.path} matches ${input.pattern}.${notes}`);
193
+ return textResult(`${found.lines.trimEnd()}${notes}`);
194
+ }
195
+ /** The `grep` tool. */
196
+ export function grepTool(deps) {
197
+ return defineTool({
198
+ name: "grep",
199
+ description: BUILTIN_TOOL_DEFAULTS.grep.description,
200
+ inputSchema: {
201
+ type: "object",
202
+ properties: {
203
+ pattern: { type: "string", minLength: 1, description: "The extended regular expression to find." },
204
+ path: { type: "string", description: "The file or folder to search. Default the workspace root." },
205
+ glob: { type: "string", description: "Only files that match this glob, such as `*.ts`." },
206
+ ignore_case: { type: "boolean", description: "Match without regard to case." },
207
+ },
208
+ required: ["pattern"],
209
+ additionalProperties: false,
210
+ },
211
+ firstParty: true,
212
+ annotations: { readOnlyHint: true },
213
+ resourceKey: () => WORKSPACE_KEY,
214
+ execute: (input, ctx) => grep(deps, input, ctx.signal),
215
+ });
216
+ }
217
+ //# sourceMappingURL=search.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.js","sourceRoot":"","sources":["../../../src/tools/builtins/search.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,UAAU,EAAwC,MAAM,mBAAmB,CAAC;AACrF,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAiB,aAAa,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,WAAW,E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AChC,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC;KACvD,CAAY,CAAC;AAChB,CAAC","sourcesContent":["/**\n * `grep` and `glob`: read-only search, run inside the sandbox with `find` and `grep`, so a pattern the model wrote is\n * matched by a sandboxed process with a timeout and never by a regular expression in the host's own loop. Both list\n * files with `find`, which never follows a symlink, and filter the list here with the permission rules' own glob\n * matcher, so `glob` and `grep`'s file filter read a pattern the same way on every backend.\n */\nimport { defineTool, type ToolDefinition, type ToolResult } from \"@buildanagent/sdk\";\nimport { globToRegExp } from \"../../permissions/match.js\";\nimport type { ExecResult } from \"../../sandbox/types.js\";\nimport { BUILTIN_TOOL_DEFAULTS } from \"./descriptions.js\";\nimport { type FileDeps, WORKSPACE_KEY } from \"./files.js\";\nimport { checkPath } from \"./paths.js\";\nimport { deniedResult, errorResult, failureResult, textResult } from \"./results.js\";\n\ntype AnyTool = ToolDefinition<unknown, unknown, unknown>;\n\nconst ENCODER = new TextEncoder();\nconst DECODER = new TextDecoder();\n\n/** What the search tools share with the file tools, plus the environment their commands run with. */\nexport interface SearchDeps extends FileDeps {\n readonly env: Readonly<Record<string, string>>;\n}\n\n/**\n * Either the files under `base` (with a warning when `find` could not read part of the tree) or the result that ends\n * the call: a refusal, a denial or a listing that produced nothing.\n */\ntype Listing =\n | { readonly files: readonly string[]; readonly cut: boolean; readonly warning: string }\n | { readonly result: ToolResult };\n\n// The most bytes of a command's standard error a warning quotes, so many unreadable files can't flood the result.\nconst WARNING_BYTES = 2048;\n\n/** The line that tells the model a command failed on part of its input, quoting its first lines of standard error. */\nfunction warningOf(what: string, result: { exitCode: number; stderr: string }): string {\n const stderr = result.stderr.trim();\n const quoted = stderr.length > WARNING_BYTES ? `${stderr.slice(0, WARNING_BYTES)}...` : stderr;\n return `\\n[${what} exited with ${result.exitCode}, so some files may be missing: ${quoted}]`;\n}\n\nasync function exec(\n deps: SearchDeps,\n command: string[],\n options: { readonly timeoutMs: number; readonly maxOutputBytes?: number },\n signal: AbortSignal,\n): Promise<ExecResult> {\n return deps.sandbox.exec(command, { env: deps.env, signal, ...options });\n}\n\n/** `path` as a `find -path` pattern that matches only itself. */\nconst literalPattern = (path: string): string => path.replace(/[\\\\*?[\\]]/g, \"\\\\$&\");\n\n/** Lists the regular files under `base` inside the sandbox, skipping the folders search never enters. */\nasync function listFiles(deps: SearchDeps, base: string, timeoutMs: number, signal: AbortSignal): Promise<Listing> {\n const skipped = BUILTIN_TOOL_DEFAULTS.search.skippedFolders.flatMap((name, index) =>\n index === 0 ? [\"-name\", name] : [\"-o\", \"-name\", name],\n );\n // The starting point is exempt from the prune, so a search of `node_modules` itself still lists its files.\n const prune = [\"(\", \"!\", \"-path\", literalPattern(base), \"(\", ...skipped, \")\", \"-prune\", \")\"];\n const command = [\"find\", base, ...prune, \"-o\", \"-type\", \"f\", \"-print0\"];\n let result: ExecResult;\n try {\n result = await exec(deps, command, { timeoutMs }, signal);\n } catch (error) {\n return { result: failureResult(error) };\n }\n if (\"denied\" in result) return { result: deniedResult(result.denied) };\n const names = result.stdout.split(\"\\u0000\");\n // The last name is empty after a whole listing, and only part of a path when the output was cut.\n names.pop();\n // find exits with 1 when it could not read part of the tree, and still prints what it could: keep that.\n if (result.exitCode !== 0 && names.length === 0) {\n return { result: errorResult(`Listing ${base} failed with exit code ${result.exitCode}: ${result.stderr.trim()}`) };\n }\n const warning = result.exitCode === 0 ? \"\" : warningOf(\"find\", result);\n return { files: names, cut: result.truncated === true, warning };\n}\n\n// A base of \"/\" already ends in the separator, so the slice starts right after it.\nconst relativeTo = (base: string, path: string): string =>\n path === base ? (path.split(\"/\").at(-1) ?? \"\") : path.slice(base === \"/\" ? 1 : base.length + 1);\n\n/** A filter for the listed files: an absolute glob matches the whole path, and a relative one the path below `base`. */\nfunction matcher(pattern: string, base: string, byName: boolean): (path: string) => boolean {\n const regex = globToRegExp(pattern);\n if (pattern.startsWith(\"/\")) return (path) => regex.test(path);\n if (byName && !pattern.includes(\"/\")) return (path) => regex.test(path.split(\"/\").at(-1) ?? \"\");\n return (path) => regex.test(relativeTo(base, path));\n}\n\ninterface GlobInput {\n readonly pattern: string;\n readonly path?: string;\n}\n\nasync function globFiles(deps: SearchDeps, input: GlobInput, signal: AbortSignal): Promise<ToolResult> {\n const checked = checkPath(deps.bounds, input.path ?? deps.bounds.root, \"read\");\n if (\"refused\" in checked) return errorResult(checked.refused);\n const listing = await listFiles(deps, checked.path, BUILTIN_TOOL_DEFAULTS.glob.timeoutMs, signal);\n if (\"result\" in listing) return listing.result;\n const matches = matcher(input.pattern, checked.path, false);\n const found = listing.files.filter(matches).sort();\n const cut = `${listing.cut ? \"\\n[the file listing was cut, so some matches may be missing]\" : \"\"}${listing.warning}`;\n if (found.length === 0) return textResult(`No file under ${checked.path} matches ${input.pattern}.${cut}`);\n return textResult(`${found.join(\"\\n\")}${cut}`, { files: found.length });\n}\n\n/** The `glob` tool. */\nexport function globTool(deps: SearchDeps): AnyTool {\n return defineTool<GlobInput>({\n name: \"glob\",\n description: BUILTIN_TOOL_DEFAULTS.glob.description,\n inputSchema: {\n type: \"object\",\n properties: {\n pattern: { type: \"string\", minLength: 1, description: \"The glob to match, such as `**/*.ts`.\" },\n path: { type: \"string\", description: \"The folder to search, relative to the workspace root or absolute.\" },\n },\n required: [\"pattern\"],\n additionalProperties: false,\n },\n firstParty: true,\n annotations: { readOnlyHint: true },\n resourceKey: () => WORKSPACE_KEY,\n execute: (input, ctx) => globFiles(deps, input, ctx.signal),\n }) as AnyTool;\n}\n\ninterface GrepInput {\n readonly pattern: string;\n readonly path?: string;\n readonly glob?: string;\n readonly ignore_case?: boolean;\n}\n\n/**\n * What the grep commands found: the matching lines, the notices that say what they may have missed, and, when matches\n * were found but none fits whole, where the first one is.\n */\ninterface Found {\n readonly lines: string;\n readonly notes: string;\n readonly tooLong?: { readonly path?: string; readonly line?: number };\n}\n\n/**\n * Where grep's first match in `stdout` is: the file of `batch` that the output starts with, and its line number. grep\n * prints `path:line:text`, and a path may itself hold a colon, so the path is matched against the files searched.\n */\nfunction firstMatch(stdout: string, batch: readonly string[]): { path?: string; line?: number } {\n const path = batch.find((file) => stdout.startsWith(`${file}:`));\n if (path === undefined) return {};\n const line = /^(\\d+):/.exec(stdout.slice(path.length + 1))?.[1];\n return line === undefined ? { path } : { path, line: Number(line) };\n}\n\n/** The longest start of `text` that ends a line and fits in `bytes` UTF-8 bytes. */\nfunction wholeLines(text: string, bytes: number): string {\n const encoded = ENCODER.encode(text);\n if (encoded.length <= bytes) return text.endsWith(\"\\n\") ? text : text.slice(0, text.lastIndexOf(\"\\n\") + 1);\n const end = encoded.subarray(0, bytes).lastIndexOf(10);\n return DECODER.decode(encoded.subarray(0, end + 1));\n}\n\n/** Runs one `grep` command over `batch`, and returns what it did, or the result that ends the call. */\nasync function grepBatch(\n deps: SearchDeps,\n flags: readonly string[],\n batch: readonly string[],\n signal: AbortSignal,\n): Promise<Extract<ExecResult, { exitCode: number }> | { readonly result: ToolResult }> {\n const { timeoutMs, maxOutputBytes } = BUILTIN_TOOL_DEFAULTS.grep;\n let result: ExecResult;\n try {\n result = await exec(deps, [\"grep\", ...flags, \"--\", ...batch], { timeoutMs, maxOutputBytes }, signal);\n } catch (error) {\n return { result: failureResult(error) };\n }\n return \"denied\" in result ? { result: deniedResult(result.denied) } : result;\n}\n\nconst CUT_NOTICE =\n `\\n[the matches passed ${BUILTIN_TOOL_DEFAULTS.grep.maxOutputBytes} bytes, so the rest were dropped and some files ` +\n \"were not searched; narrow the pattern, path or glob to see them]\";\n\n/**\n * Runs `grep` over `files` in batches, and returns the matching lines, or the result that ends the call. The lines stop\n * at the tool's output cap, across all the batches, and a batch with a file grep could not read keeps its matches and\n * adds a warning. The call fails only when no batch matched and one failed, as an unreadable pattern makes every one.\n */\nasync function grepFiles(\n deps: SearchDeps,\n input: GrepInput,\n files: readonly string[],\n signal: AbortSignal,\n): Promise<Found | { readonly result: ToolResult }> {\n const { filesPerCommand } = BUILTIN_TOOL_DEFAULTS.search;\n const { maxOutputBytes } = BUILTIN_TOOL_DEFAULTS.grep;\n const flags = [\"-n\", \"-H\", \"-I\", \"-E\", ...(input.ignore_case === true ? [\"-i\"] : []), \"-e\", input.pattern];\n let lines = \"\";\n let size = 0;\n let failed: Extract<ExecResult, { exitCode: number }> | undefined;\n const warning = () => (failed === undefined ? \"\" : warningOf(\"grep\", failed));\n for (let at = 0; at < files.length; at += filesPerCommand) {\n const batch = files.slice(at, at + filesPerCommand);\n const result = await grepBatch(deps, flags, batch, signal);\n if (\"result\" in result) return result;\n // grep exits with 1 when nothing matched, and with 2 for an error, such as a file it can't read or a bad pattern.\n if (result.exitCode > 1) failed ??= result;\n // A cut stream ends part way through a line, so only its whole lines are kept.\n const kept = wholeLines(result.stdout, maxOutputBytes - size);\n lines += kept;\n size += ENCODER.encode(kept).length;\n if (result.truncated === true || kept.length < result.stdout.length) {\n // A match whose line alone passes the cap leaves no whole line to show, but it is still a match: say so, so the\n // model never reads that the pattern matched nothing.\n const tooLong = lines === \"\" && result.stdout !== \"\" ? { tooLong: firstMatch(result.stdout, batch) } : {};\n return { lines, notes: `${CUT_NOTICE}${warning()}`, ...tooLong };\n }\n }\n if (failed !== undefined && lines === \"\") return { result: errorResult(`grep failed: ${failed.stderr.trim()}`) };\n return { lines, notes: warning() };\n}\n\n/** The sentence for matches whose lines are each too long to show: they exist, where the first is, and what to do. */\nfunction tooLongSentence(base: string, pattern: string, first: { path?: string; line?: number }): string {\n const { maxOutputBytes } = BUILTIN_TOOL_DEFAULTS.grep;\n const where =\n first.path === undefined\n ? \"\"\n : ` The first is in ${first.path}${first.line === undefined ? \"\" : `, on line ${first.line}`}.`;\n return (\n `Lines under ${base} match ${pattern}, but the first matching line is longer than ${maxOutputBytes} bytes, so ` +\n `none can be shown.${where} Narrow the pattern, path or glob, or read the matching file with read, in parts.`\n );\n}\n\nasync function grep(deps: SearchDeps, input: GrepInput, signal: AbortSignal): Promise<ToolResult> {\n const checked = checkPath(deps.bounds, input.path ?? deps.bounds.root, \"read\");\n if (\"refused\" in checked) return errorResult(checked.refused);\n const listing = await listFiles(deps, checked.path, BUILTIN_TOOL_DEFAULTS.grep.timeoutMs, signal);\n if (\"result\" in listing) return listing.result;\n const files =\n input.glob === undefined ? listing.files : listing.files.filter(matcher(input.glob, checked.path, true));\n const found = files.length === 0 ? { lines: \"\", notes: \"\" } : await grepFiles(deps, input, [...files].sort(), signal);\n if (\"result\" in found) return found.result;\n const cut = listing.cut ? \"\\n[the file listing was cut, so some files were not searched]\" : \"\";\n const notes = `${found.notes}${cut}${listing.warning}`;\n if (found.tooLong !== undefined)\n return textResult(`${tooLongSentence(checked.path, input.pattern, found.tooLong)}${notes}`);\n if (found.lines === \"\") return textResult(`No line under ${checked.path} matches ${input.pattern}.${notes}`);\n return textResult(`${found.lines.trimEnd()}${notes}`);\n}\n\n/** The `grep` tool. */\nexport function grepTool(deps: SearchDeps): AnyTool {\n return defineTool<GrepInput>({\n name: \"grep\",\n description: BUILTIN_TOOL_DEFAULTS.grep.description,\n inputSchema: {\n type: \"object\",\n properties: {\n pattern: { type: \"string\", minLength: 1, description: \"The extended regular expression to find.\" },\n path: { type: \"string\", description: \"The file or folder to search. Default the workspace root.\" },\n glob: { type: \"string\", description: \"Only files that match this glob, such as `*.ts`.\" },\n ignore_case: { type: \"boolean\", description: \"Match without regard to case.\" },\n },\n required: [\"pattern\"],\n additionalProperties: false,\n },\n firstParty: true,\n annotations: { readOnlyHint: true },\n resourceKey: () => WORKSPACE_KEY,\n execute: (input, ctx) => grep(deps, input, ctx.signal),\n }) as AnyTool;\n}\n"]}
@@ -1,7 +1,11 @@
1
1
  /**
2
- * `@buildanagent/harness/tools`: the tool registry, which names, defers and wraps the tools of every source, and the
3
- * tool search that activates deferred ones.
2
+ * `@buildanagent/harness/tools`: the tool registry, which names, defers and wraps the tools of every source, the
3
+ * tool search that activates deferred ones, and the built-in tools, which reach files, commands and the web only
4
+ * through a sandbox and an egress proxy.
4
5
  */
6
+ export { type BuiltinToolsOptions, builtinTools } from "./builtins/builtins.js";
7
+ export { BUILTIN_TOOL_DEFAULTS, BUILTIN_TOOLS_HASH } from "./builtins/descriptions.js";
8
+ export type { FetchProxy } from "./builtins/fetch.js";
5
9
  export { DuplicateToolError } from "./errors.js";
6
10
  export { createToolRegistry } from "./registry.js";
7
11
  export { type ToolSearchOptions, toolSearchInterceptors, toolSearchTool } from "./tool-search.js";
@@ -1,7 +1,10 @@
1
1
  /**
2
- * `@buildanagent/harness/tools`: the tool registry, which names, defers and wraps the tools of every source, and the
3
- * tool search that activates deferred ones.
2
+ * `@buildanagent/harness/tools`: the tool registry, which names, defers and wraps the tools of every source, the
3
+ * tool search that activates deferred ones, and the built-in tools, which reach files, commands and the web only
4
+ * through a sandbox and an egress proxy.
4
5
  */
6
+ export { builtinTools } from "./builtins/builtins.js";
7
+ export { BUILTIN_TOOL_DEFAULTS, BUILTIN_TOOLS_HASH } from "./builtins/descriptions.js";
5
8
  export { DuplicateToolError } from "./errors.js";
6
9
  export { createToolRegistry } from "./registry.js";
7
10
  export { toolSearchInterceptors, toolSearchTool } from "./tool-search.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAA0B,sBAAsB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["/**\n * `@buildanagent/harness/tools`: the tool registry, which names, defers and wraps the tools of every source, and the\n * tool search that activates deferred ones.\n */\nexport { DuplicateToolError } from \"./errors.js\";\nexport { createToolRegistry } from \"./registry.js\";\nexport { type ToolSearchOptions, toolSearchInterceptors, toolSearchTool } from \"./tool-search.js\";\nexport type {\n ApprovalReuse,\n HostPattern,\n OutputTrust,\n PreambleOptions,\n RegisteredTool,\n ToolExposure,\n ToolRegistration,\n ToolRegistry,\n ToolSource,\n ToolWrapper,\n} from \"./types.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAA4B,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEvF,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAA0B,sBAAsB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["/**\n * `@buildanagent/harness/tools`: the tool registry, which names, defers and wraps the tools of every source, the\n * tool search that activates deferred ones, and the built-in tools, which reach files, commands and the web only\n * through a sandbox and an egress proxy.\n */\nexport { type BuiltinToolsOptions, builtinTools } from \"./builtins/builtins.js\";\nexport { BUILTIN_TOOL_DEFAULTS, BUILTIN_TOOLS_HASH } from \"./builtins/descriptions.js\";\nexport type { FetchProxy } from \"./builtins/fetch.js\";\nexport { DuplicateToolError } from \"./errors.js\";\nexport { createToolRegistry } from \"./registry.js\";\nexport { type ToolSearchOptions, toolSearchInterceptors, toolSearchTool } from \"./tool-search.js\";\nexport type {\n ApprovalReuse,\n HostPattern,\n OutputTrust,\n PreambleOptions,\n RegisteredTool,\n ToolExposure,\n ToolRegistration,\n ToolRegistry,\n ToolSource,\n ToolWrapper,\n} from \"./types.js\";\n"]}