@buildanagent/harness 0.1.0-alpha.28 → 0.1.0-alpha.29
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.
- package/README.md +111 -5
- package/dist/context/file-spill.d.ts +11 -1
- package/dist/context/file-spill.js +23 -8
- package/dist/context/file-spill.js.map +1 -1
- package/dist/context/spill.d.ts +5 -1
- package/dist/context/spill.js +6 -2
- package/dist/context/spill.js.map +1 -1
- package/dist/credentials/allowlist.d.ts +22 -2
- package/dist/credentials/allowlist.js +74 -17
- package/dist/credentials/allowlist.js.map +1 -1
- package/dist/credentials/egress-policy.d.ts +69 -0
- package/dist/credentials/egress-policy.js +170 -0
- package/dist/credentials/egress-policy.js.map +1 -0
- package/dist/credentials/egress-proxy.d.ts +13 -1
- package/dist/credentials/egress-proxy.js +179 -11
- package/dist/credentials/egress-proxy.js.map +1 -1
- package/dist/credentials/git-route.d.ts +68 -0
- package/dist/credentials/git-route.js +288 -0
- package/dist/credentials/git-route.js.map +1 -0
- package/dist/credentials/index.d.ts +5 -1
- package/dist/credentials/index.js +5 -1
- package/dist/credentials/index.js.map +1 -1
- package/dist/credentials/scrub.d.ts +7 -0
- package/dist/credentials/scrub.js +22 -0
- package/dist/credentials/scrub.js.map +1 -1
- package/dist/errors.d.ts +9 -5
- package/dist/errors.js +8 -4
- package/dist/errors.js.map +1 -1
- package/dist/sandbox/base.d.ts +11 -1
- package/dist/sandbox/base.js +14 -0
- package/dist/sandbox/base.js.map +1 -1
- package/dist/sandbox/docker/index.d.ts +8 -2
- package/dist/sandbox/docker/index.js +63 -14
- package/dist/sandbox/docker/index.js.map +1 -1
- package/dist/sandbox/errors.d.ts +30 -2
- package/dist/sandbox/errors.js +36 -1
- package/dist/sandbox/errors.js.map +1 -1
- package/dist/sandbox/host-files.d.ts +2 -0
- package/dist/sandbox/host-files.js +10 -0
- package/dist/sandbox/host-files.js.map +1 -1
- package/dist/sandbox/index.d.ts +6 -4
- package/dist/sandbox/index.js +5 -3
- package/dist/sandbox/index.js.map +1 -1
- package/dist/sandbox/policy.d.ts +49 -0
- package/dist/sandbox/policy.js +149 -0
- package/dist/sandbox/policy.js.map +1 -0
- package/dist/sandbox/process.js +1 -1
- package/dist/sandbox/process.js.map +1 -1
- package/dist/sandbox/srt/index.d.ts +5 -2
- package/dist/sandbox/srt/index.js +27 -8
- package/dist/sandbox/srt/index.js.map +1 -1
- package/dist/sandbox/srt/settings.d.ts +17 -5
- package/dist/sandbox/srt/settings.js +53 -0
- package/dist/sandbox/srt/settings.js.map +1 -1
- package/dist/sandbox/types.d.ts +41 -4
- package/dist/sandbox/types.js.map +1 -1
- package/dist/testing/fake-sandbox.d.ts +21 -3
- package/dist/testing/fake-sandbox.js +157 -8
- package/dist/testing/fake-sandbox.js.map +1 -1
- package/dist/testing/sandbox-conformance.js +108 -1
- package/dist/testing/sandbox-conformance.js.map +1 -1
- package/dist/tools/builtins/bash.d.ts +9 -0
- package/dist/tools/builtins/bash.js +75 -0
- package/dist/tools/builtins/bash.js.map +1 -0
- package/dist/tools/builtins/builtins.d.ts +38 -0
- package/dist/tools/builtins/builtins.js +48 -0
- package/dist/tools/builtins/builtins.js.map +1 -0
- package/dist/tools/builtins/descriptions.d.ts +69 -0
- package/dist/tools/builtins/descriptions.js +94 -0
- package/dist/tools/builtins/descriptions.js.map +1 -0
- package/dist/tools/builtins/fetch.d.ts +12 -0
- package/dist/tools/builtins/fetch.js +157 -0
- package/dist/tools/builtins/fetch.js.map +1 -0
- package/dist/tools/builtins/files.d.ts +27 -0
- package/dist/tools/builtins/files.js +274 -0
- package/dist/tools/builtins/files.js.map +1 -0
- package/dist/tools/builtins/paths.d.ts +30 -0
- package/dist/tools/builtins/paths.js +62 -0
- package/dist/tools/builtins/paths.js.map +1 -0
- package/dist/tools/builtins/results.d.ts +15 -0
- package/dist/tools/builtins/results.js +31 -0
- package/dist/tools/builtins/results.js.map +1 -0
- package/dist/tools/builtins/search.d.ts +18 -0
- package/dist/tools/builtins/search.js +217 -0
- package/dist/tools/builtins/search.js.map +1 -0
- package/dist/tools/index.d.ts +6 -2
- package/dist/tools/index.js +5 -2
- package/dist/tools/index.js.map +1 -1
- package/llms.txt +34 -0
- package/package.json +5 -5
|
@@ -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,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAIpF,MAAM,OAAO,GAAG,IAAI,WAAW,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AAK,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"]}
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@buildanagent/harness/tools`: the tool registry, which names, defers and wraps the tools of every source,
|
|
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";
|
package/dist/tools/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@buildanagent/harness/tools`: the tool registry, which names, defers and wraps the tools of every source,
|
|
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";
|
package/dist/tools/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA
|
|
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"]}
|
package/llms.txt
CHANGED
|
@@ -11,10 +11,14 @@ The sections of README.md and every public export, generated from this package's
|
|
|
11
11
|
- [A sandbox says what it stops, and the host decides what it may touch](README.md#a-sandbox-says-what-it-stops-and-the-host-decides-what-it-may-touch)
|
|
12
12
|
- [The srt backend confines each command with Anthropic's OS sandbox](README.md#the-srt-backend-confines-each-command-with-anthropics-os-sandbox)
|
|
13
13
|
- [The Docker backend runs each command in a locked-down container](README.md#the-docker-backend-runs-each-command-in-a-locked-down-container)
|
|
14
|
+
- [A backend that claims a stop reads its policy back, and one that can't resume says so](README.md#a-backend-that-claims-a-stop-reads-its-policy-back-and-one-that-cant-resume-says-so)
|
|
14
15
|
- [The egress proxy keeps every credential outside the sandbox](README.md#the-egress-proxy-keeps-every-credential-outside-the-sandbox)
|
|
16
|
+
- [An egress policy names a credential and never holds one](README.md#an-egress-policy-names-a-credential-and-never-holds-one)
|
|
17
|
+
- [A git route lets a push reach listed branches and nothing else](README.md#a-git-route-lets-a-push-reach-listed-branches-and-nothing-else)
|
|
15
18
|
- [Every spawned process gets a cleared environment](README.md#every-spawned-process-gets-a-cleared-environment)
|
|
16
19
|
- [Test a sandbox with the fake and the conformance suite](README.md#test-a-sandbox-with-the-fake-and-the-conformance-suite)
|
|
17
20
|
- [One registry names, defers and wraps every tool](README.md#one-registry-names-defers-and-wraps-every-tool)
|
|
21
|
+
- [The built-in tools reach files, commands and the web only through the sandbox and the egress proxy](README.md#the-built-in-tools-reach-files-commands-and-the-web-only-through-the-sandbox-and-the-egress-proxy)
|
|
18
22
|
- [One pipeline decides every tool call, and a call no rule settles is denied when nobody can answer](README.md#one-pipeline-decides-every-tool-call-and-a-call-no-rule-settles-is-denied-when-nobody-can-answer)
|
|
19
23
|
- [A session belongs to a user, and every store call names both](README.md#a-session-belongs-to-a-user-and-every-store-call-names-both)
|
|
20
24
|
- [One writer holds a session's lock, and a lock outlives a crash only by its lease](README.md#one-writer-holds-a-sessions-lock-and-a-lock-outlives-a-crash-only-by-its-lease)
|
|
@@ -205,12 +209,18 @@ The sections of README.md and every public export, generated from this package's
|
|
|
205
209
|
## Exports from `@buildanagent/harness/context/file`
|
|
206
210
|
|
|
207
211
|
- `fileSpillStore()`: A spill store that writes `<dir>/<user>/<session>/<callId>.txt` and returns that path.
|
|
212
|
+
- `interface FileSpillStore`: A spill store in files, which can also read back the spills of one session.
|
|
208
213
|
|
|
209
214
|
## Exports from `@buildanagent/harness/tools`
|
|
210
215
|
|
|
211
216
|
- `type ApprovalReuse`: Which approvals may cover later calls: a sticky one, a grouped one, both, or none, so each call asks.
|
|
217
|
+
- `BUILTIN_TOOL_DEFAULTS`: The built-in tools' descriptions, limits and defaults, frozen.
|
|
218
|
+
- `BUILTIN_TOOLS_HASH`: The SHA-256 of the canonical JSON of `BUILTIN_TOOL_DEFAULTS`.
|
|
219
|
+
- `builtinTools()`: The built-in tools for one sandbox: `read`, `write`, `edit`, `bash`, `grep`, `glob` and, when `proxy` is given, `fetch`.
|
|
220
|
+
- `interface BuiltinToolsOptions`: The options of `builtinTools()`.
|
|
212
221
|
- `createToolRegistry()`: Creates an empty registry.
|
|
213
222
|
- `class DuplicateToolError`: Thrown by `register()` when a registry already holds a tool, or an alias, by that name.
|
|
223
|
+
- `type FetchProxy`: What the `fetch` tool needs of an egress proxy.
|
|
214
224
|
- `type HostPattern`: How a tool's code is reached: in this process, or by asking the client through a `tool/call` server request.
|
|
215
225
|
- `type OutputTrust`: Whether a tool's output may carry instructions an attacker wrote.
|
|
216
226
|
- `interface PreambleOptions`: The options of `preambleTokens()`.
|
|
@@ -264,20 +274,30 @@ The sections of README.md and every public export, generated from this package's
|
|
|
264
274
|
## Exports from `@buildanagent/harness/sandbox`
|
|
265
275
|
|
|
266
276
|
- `type ApprovalPolicy`: When a denied action may be asked for again, which is the host's decision and never the sandbox's.
|
|
277
|
+
- `confirmPolicy()`: Reads back the policy `sandbox` applied and compares it with `requested`.
|
|
267
278
|
- `interface ExecOptions`: The options of `Sandbox.exec()`.
|
|
268
279
|
- `type ExecResult`: What a command did: its exit status and output, or the denial that stopped it.
|
|
280
|
+
- `hasCapability()`: Whether `client` lists `capability`.
|
|
269
281
|
- `NONE_SANDBOX_WARNING`: The warning written when a sandbox starts.
|
|
270
282
|
- `noneSandbox()`: Builds the `none` backend.
|
|
271
283
|
- `interface NoneSandboxOptions`: The options of `noneSandbox()`.
|
|
284
|
+
- `pauseSandbox()`: Pauses `sandbox` until `resumeSandbox()` with its `id`, or throws `SandboxUnsupportedError`.
|
|
285
|
+
- `policyDifference()`: The first field in which `applied` differs from `requested`, or `undefined` when they hold the same entries.
|
|
286
|
+
- `resumeSandbox()`: Reattaches to a sandbox by its id, or starts one from a snapshot's id, then confirms its policy as `provision()` does and sets the sandbox's `stops` to what the confirmed policy delivers.
|
|
272
287
|
- `interface Sandbox`: A provisioned sandbox.
|
|
288
|
+
- `type SandboxCapability`: What a backend can do besides provisioning.
|
|
273
289
|
- `interface SandboxClient`: A sandbox backend.
|
|
274
290
|
- `interface SandboxDenial`: What the policy refused.
|
|
275
291
|
- `class SandboxDeniedError`: Thrown when the policy refuses a file read or write.
|
|
276
292
|
- `interface SandboxPolicy`: What a sandbox may touch.
|
|
293
|
+
- `class SandboxPolicyMismatchError`: Thrown when the policy a backend read back from what it applied differs from the policy it was asked for, after `provision()` or a resume.
|
|
277
294
|
- `type SandboxStop`: What a backend claims to stop.
|
|
278
295
|
- `type SandboxTier`: How strongly a backend confines a process.
|
|
279
296
|
- `class SandboxUnavailableError`: Thrown by `provision()` when a backend can't start, such as a missing binary.
|
|
297
|
+
- `class SandboxUnsupportedError`: Thrown by `resumeSandbox()`, `snapshotSandbox()` and `pauseSandbox()` for a capability the backend doesn't list.
|
|
298
|
+
- `snapshotSandbox()`: Snapshots `sandbox` and resolves with the id `resumeSandbox()` takes, or throws `SandboxUnsupportedError`.
|
|
280
299
|
- `spawnEnv()`: The environment for a spawned process: `PATH`, a fresh temp `HOME`, `TMPDIR` and `LANG`, plus the parent variables named in `allow` that are set, plus every `extra`.
|
|
300
|
+
- `stopsFor()`: The stops a backend of `tier` delivers under `policy`.
|
|
281
301
|
- `interface WorkspaceManifest`: The workspace a sandbox is provisioned for: its root directory and the files to put there first.
|
|
282
302
|
|
|
283
303
|
## Exports from `@buildanagent/harness/sandbox/srt`
|
|
@@ -285,6 +305,8 @@ The sections of README.md and every public export, generated from this package's
|
|
|
285
305
|
- `SRT_ADDED_ENVIRONMENT`: The variables `srt` 0.0.83 adds to a command's environment, which are its proxy settings and the few that go with them.
|
|
286
306
|
- `SRT_SYSTEM_READ_ROOTS`: The system folders a program needs to start.
|
|
287
307
|
- `interface SrtPathEntry`: A path that `srt` must read as written.
|
|
308
|
+
- `srtPolicyFromSettings()`: The policy a settings file applies, in the spelling of the request.
|
|
309
|
+
- `interface SrtPolicyNames`: How a settings file's real paths map back to the spelling of the request, for `srtPolicyFromSettings()`.
|
|
288
310
|
- `srtSandbox()`: Builds the `srt` backend.
|
|
289
311
|
- `interface SrtSandboxOptions`: The options of `srtSandbox()`.
|
|
290
312
|
- `srtSettings()`: Denies every read and then allows the policy's read and write roots, the system folders and the helper folders back.
|
|
@@ -299,12 +321,24 @@ The sections of README.md and every public export, generated from this package's
|
|
|
299
321
|
|
|
300
322
|
## Exports from `@buildanagent/harness/credentials`
|
|
301
323
|
|
|
324
|
+
- `interface CompiledEgressPolicy`: A compiled policy: the `allow` and `routes` options of `startEgressProxy()`.
|
|
325
|
+
- `interface CompileEgressOptions`: The options of `compileEgressPolicy()`.
|
|
326
|
+
- `compileEgressPolicy()`: Checks `policy` and compiles it for `startEgressProxy()`: pass the result's `allow` and `routes` with a `log`.
|
|
302
327
|
- `interface CredentialRoute`: One credential route: where a request for `/<route>/…` goes, and how the proxy adds the credential.
|
|
328
|
+
- `interface EgressPolicy`: What a sandbox may reach: the hosts it may tunnel to, and the routes that add a credential on its behalf.
|
|
303
329
|
- `interface EgressProxy`: A running egress proxy.
|
|
304
330
|
- `interface EgressProxyOptions`: The options of `startEgressProxy()`.
|
|
305
331
|
- `interface EgressRecord`: One line of the egress log.
|
|
332
|
+
- `type EgressRoute`: One credential route of an `EgressPolicy`.
|
|
333
|
+
- `GIT_MAX_COMMAND_BYTES`: The most bytes of a push's command list, before its flush, that the route reads.
|
|
334
|
+
- `GIT_MAX_COMMANDS`: The most ref updates in one push.
|
|
335
|
+
- `interface GitEgressRoute`: A route for git over HTTPS: git's smart HTTP requests for the listed repositories only, and a push only to the listed branches.
|
|
336
|
+
- `interface GitRouteFilter`: What a git route lets through.
|
|
337
|
+
- `interface HeaderEgressRoute`: A route that swaps the sentinel in one request header for a credential, as `startEgressProxy()`'s routes do.
|
|
306
338
|
- `isAddressLiteral()`: Whether `text` is an IPv4 or IPv6 address, as a host name that must not be looked up.
|
|
307
339
|
- `isPublicAddress()`: Whether `address` is a public one a proxy may connect to.
|
|
340
|
+
- `isValidRefName()`: Whether `name` is a ref name git itself would accept, by `git check-ref-format`'s rules, under `refs/`.
|
|
341
|
+
- `pushVerdict()`: The route's verdict on the start of a push body: `incomplete` while the command list hasn't reached its flush, `allowed` once every command creates or updates a ref the patterns allow, or the reason it is refused.
|
|
308
342
|
- `REDACTED`: What replaces a secret.
|
|
309
343
|
- `scrubSecrets()`: Returns a copy of `entry` with every secret replaced by `[REDACTED]`, in every string value and every key, at any depth.
|
|
310
344
|
- `startEgressProxy()`: Starts the egress proxy on `127.0.0.1` with a port the system picks, or on `socketPath`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buildanagent/harness",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.29",
|
|
4
4
|
"description": "The buildanagent harness: the session log, context policy, tools, permissions, sandbox and credentials around the SDK's loop.",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"repository": {
|
|
@@ -103,10 +103,10 @@
|
|
|
103
103
|
"@anthropic-ai/sandbox-runtime": "0.0.83",
|
|
104
104
|
"@earendil-works/pi-schema": "1.5.2",
|
|
105
105
|
"@modelcontextprotocol/client": "2.4.0",
|
|
106
|
-
"@buildanagent/agent-safety": "0.1.0-alpha.
|
|
107
|
-
"@buildanagent/gateway": "0.1.0-alpha.
|
|
108
|
-
"@buildanagent/
|
|
109
|
-
"@buildanagent/
|
|
106
|
+
"@buildanagent/agent-safety": "0.1.0-alpha.29",
|
|
107
|
+
"@buildanagent/gateway": "0.1.0-alpha.29",
|
|
108
|
+
"@buildanagent/protocol": "0.1.0-alpha.29",
|
|
109
|
+
"@buildanagent/sdk": "0.1.0-alpha.29"
|
|
110
110
|
},
|
|
111
111
|
"devDependencies": {
|
|
112
112
|
"@modelcontextprotocol/server": "2.4.0",
|