@better-fs-tools/write 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +122 -106
- package/dist/bundle/create-fs-tools.d.ts +83 -21
- package/dist/bundle/create-fs-tools.js +61 -22
- package/dist/bundle/definitions.d.ts +51 -0
- package/dist/bundle/definitions.js +42 -0
- package/dist/contract/deps.d.ts +13 -5
- package/dist/contract/messages.d.ts +0 -23
- package/dist/contract/preconditions.d.ts +5 -1
- package/dist/contract/preconditions.js +1 -1
- package/dist/core/commit.d.ts +0 -1
- package/dist/core/commit.js +1 -35
- package/dist/core/create-tools.d.ts +9 -9
- package/dist/core/create-tools.js +11 -11
- package/dist/core/deps.d.ts +4 -4
- package/dist/core/deps.js +10 -7
- package/dist/core/format.js +1 -15
- package/dist/core/hooks.js +1 -8
- package/dist/core/load.js +1 -1
- package/dist/core/messages.js +8 -11
- package/dist/core/patch-hunks.js +31 -3
- package/dist/core/patch-pipeline.js +1 -2
- package/dist/core/pipeline.js +2 -2
- package/dist/core/plan-edit.d.ts +2 -0
- package/dist/core/plan-edit.js +3 -3
- package/dist/core/precondition.js +2 -13
- package/dist/core/record.js +1 -0
- package/dist/formatters/default.d.ts +7 -1
- package/dist/formatters/default.js +23 -5
- package/dist/guards/index.d.ts +9 -3
- package/dist/guards/index.js +11 -3
- package/dist/guards/non-text.d.ts +5 -1
- package/dist/guards/non-text.js +5 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/matchers/index.d.ts +4 -1
- package/dist/matchers/index.js +5 -3
- package/dist/matchers/keep-bytes.d.ts +22 -0
- package/dist/matchers/keep-bytes.js +51 -0
- package/dist/matchers/line-trimmed.d.ts +4 -1
- package/dist/matchers/line-trimmed.js +9 -1
- package/dist/matchers/normalized.d.ts +2 -1
- package/dist/matchers/normalized.js +7 -1
- package/dist/signature/definition.d.ts +41 -0
- package/dist/signature/definition.js +66 -0
- package/dist/signature/edit.d.ts +4 -5
- package/dist/signature/edit.js +5 -13
- package/dist/signature/index.d.ts +6 -2
- package/dist/signature/index.js +4 -2
- package/dist/signature/patch.d.ts +4 -1
- package/dist/signature/patch.js +4 -1
- package/dist/signature/write.d.ts +1 -6
- package/dist/signature/write.js +1 -8
- package/docs/architecture.md +14 -11
- package/docs/hosts.md +134 -55
- package/docs/result-schema.md +20 -26
- package/package.json +4 -4
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { createApplyPatchTool, createEditTool, createWriteTool } from "../core/create-tools.js";
|
|
2
|
+
import { parseApplyPatchInput, parseEditInput, parseWriteInput } from "../core/input.js";
|
|
3
|
+
import { resolveWriteLimits } from "../core/limits.js";
|
|
4
|
+
import { defaultEditSignature } from "./edit.js";
|
|
5
|
+
import { writeSignatureMessages } from "./messages.js";
|
|
6
|
+
import { defaultPatchSignature } from "./patch.js";
|
|
7
|
+
import { defaultWriteSignature } from "./write.js";
|
|
8
|
+
/**
|
|
9
|
+
* Creates the edit tool and binds it to a signature. The signature's `param`
|
|
10
|
+
* message goes under `options.messages`, so a host message still wins. Throws
|
|
11
|
+
* TypeError where createEditTool() does.
|
|
12
|
+
*/
|
|
13
|
+
export function editToolDefinition(options) {
|
|
14
|
+
checkOptions(options, "editToolDefinition");
|
|
15
|
+
const { signature: given, ...rest } = options;
|
|
16
|
+
const signature = given ?? defaultEditSignature(rest.matchers === undefined ? {} : { matchers: rest.matchers });
|
|
17
|
+
const edit = createEditTool({
|
|
18
|
+
...rest,
|
|
19
|
+
messages: { ...writeSignatureMessages(signature), ...rest.messages },
|
|
20
|
+
});
|
|
21
|
+
return bindMutationTool(signature, edit, parseEditInput, rest.limits);
|
|
22
|
+
}
|
|
23
|
+
/** Creates the write tool and binds it to a signature, as editToolDefinition(). */
|
|
24
|
+
export function writeToolDefinition(options) {
|
|
25
|
+
checkOptions(options, "writeToolDefinition");
|
|
26
|
+
const { signature = defaultWriteSignature(), ...rest } = options;
|
|
27
|
+
const write = createWriteTool({
|
|
28
|
+
...rest,
|
|
29
|
+
messages: { ...writeSignatureMessages(signature), ...rest.messages },
|
|
30
|
+
});
|
|
31
|
+
return bindMutationTool(signature, write, parseWriteInput, rest.limits);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates the apply_patch tool and binds it to a signature, as
|
|
35
|
+
* editToolDefinition(). A grammar on the signature is copied to the definition.
|
|
36
|
+
*/
|
|
37
|
+
export function applyPatchToolDefinition(options) {
|
|
38
|
+
checkOptions(options, "applyPatchToolDefinition");
|
|
39
|
+
const { signature = defaultPatchSignature(), ...rest } = options;
|
|
40
|
+
const applyPatch = createApplyPatchTool({
|
|
41
|
+
...rest,
|
|
42
|
+
messages: { ...writeSignatureMessages(signature), ...rest.messages },
|
|
43
|
+
});
|
|
44
|
+
return bindMutationTool(signature, applyPatch, parseApplyPatchInput, rest.limits);
|
|
45
|
+
}
|
|
46
|
+
function bindMutationTool(signature, tool, parse, limitOverrides) {
|
|
47
|
+
const limits = resolveWriteLimits(limitOverrides);
|
|
48
|
+
return Object.freeze({
|
|
49
|
+
name: signature.name,
|
|
50
|
+
description: signature.description,
|
|
51
|
+
inputSchema: signature.schema,
|
|
52
|
+
...(signature.grammar === undefined ? {} : { grammar: signature.grammar }),
|
|
53
|
+
signature,
|
|
54
|
+
validate(modelInput) {
|
|
55
|
+
const input = signature.toInput(modelInput);
|
|
56
|
+
parse(input, limits);
|
|
57
|
+
return input;
|
|
58
|
+
},
|
|
59
|
+
execute: async (modelInput, ctx) => tool(signature.toInput(modelInput), ctx),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function checkOptions(options, label) {
|
|
63
|
+
if (options === null || typeof options !== "object" || Array.isArray(options)) {
|
|
64
|
+
throw new TypeError(`${label} options must be an object`);
|
|
65
|
+
}
|
|
66
|
+
}
|
package/dist/signature/edit.d.ts
CHANGED
|
@@ -4,13 +4,12 @@ import type { EditSignature } from "./contract.ts";
|
|
|
4
4
|
type MatcherOption = {
|
|
5
5
|
readonly matchers?: readonly Matcher[];
|
|
6
6
|
};
|
|
7
|
-
/** edit({ path, old_string, new_string, replace_all? }). Name "edit". */
|
|
8
|
-
export declare function defaultEditSignature(options?: SignatureDocs<"path" | "old_string" | "new_string" | "replace_all"> & MatcherOption): EditSignature;
|
|
9
7
|
/**
|
|
10
|
-
* edit({
|
|
11
|
-
* The
|
|
8
|
+
* edit({ path, old_string, new_string, replace_all? }). Name "edit". `names`
|
|
9
|
+
* renames any parameter. The description names the fuzzy matchers in
|
|
10
|
+
* `matchers`, which defaults to defaultEditMatchers().
|
|
12
11
|
*/
|
|
13
|
-
export declare function
|
|
12
|
+
export declare function defaultEditSignature(options?: SignatureDocs<"path" | "old_string" | "new_string" | "replace_all"> & MatcherOption): EditSignature;
|
|
14
13
|
/**
|
|
15
14
|
* edit({ path, edits: [{ oldText, newText }] }). Pi and Cloudflare Computer.
|
|
16
15
|
* Has no replaceAll parameter, so no message suggests one.
|
package/dist/signature/edit.js
CHANGED
|
@@ -5,7 +5,11 @@ const PATH_TEXT = "Path of the file to edit, relative to the working directory o
|
|
|
5
5
|
const READ_FIRST = "Read the file with the read tool before you edit it.";
|
|
6
6
|
const NO_PREFIX = "Copy old text from the file without the line-number prefix the read tool adds.";
|
|
7
7
|
const USE_WRITE = "To create a file or replace all of its content, use the write tool.";
|
|
8
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* edit({ path, old_string, new_string, replace_all? }). Name "edit". `names`
|
|
10
|
+
* renames any parameter. The description names the fuzzy matchers in
|
|
11
|
+
* `matchers`, which defaults to defaultEditMatchers().
|
|
12
|
+
*/
|
|
9
13
|
export function defaultEditSignature(options = {}) {
|
|
10
14
|
return singleEditSignature(options, "defaultEditSignature", {
|
|
11
15
|
path: "path",
|
|
@@ -14,18 +18,6 @@ export function defaultEditSignature(options = {}) {
|
|
|
14
18
|
all: "replace_all",
|
|
15
19
|
});
|
|
16
20
|
}
|
|
17
|
-
/**
|
|
18
|
-
* edit({ filePath, oldString, newString, replaceAll? }). OpenCode and Kilo Code.
|
|
19
|
-
* The same as defaultEditSignature with camel-case names.
|
|
20
|
-
*/
|
|
21
|
-
export function camelCaseEditSignature(options = {}) {
|
|
22
|
-
return singleEditSignature(options, "camelCaseEditSignature", {
|
|
23
|
-
path: "filePath",
|
|
24
|
-
old: "oldString",
|
|
25
|
-
new: "newString",
|
|
26
|
-
all: "replaceAll",
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
21
|
function singleEditSignature(options, label, presetNames) {
|
|
30
22
|
const checked = checkDocs(options, label, [
|
|
31
23
|
presetNames.path,
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/** The `./signature` subpath: model-facing names, schemas, and descriptions for the three tools. */
|
|
2
2
|
export type { EditSignature, MutationSignature, PatchSignature, WriteSignature, } from "./contract.ts";
|
|
3
|
-
export {
|
|
3
|
+
export { fsToolDefinitions } from "../bundle/definitions.ts";
|
|
4
|
+
export type { FsToolDefinitions, FsToolDefinitionsOptions } from "../bundle/definitions.ts";
|
|
5
|
+
export { applyPatchToolDefinition, editToolDefinition, writeToolDefinition } from "./definition.ts";
|
|
6
|
+
export type { ApplyPatchToolDefinition, ApplyPatchToolDefinitionOptions, EditToolDefinition, EditToolDefinitionOptions, MutationToolDefinition, WriteToolDefinition, WriteToolDefinitionOptions, } from "./definition.ts";
|
|
7
|
+
export { defaultEditSignature, multiEditSignature } from "./edit.ts";
|
|
4
8
|
export { writeSignatureMessages } from "./messages.ts";
|
|
5
9
|
export { defaultPatchSignature, freeformPatchSignature } from "./patch.ts";
|
|
6
|
-
export { defaultWriteSignature
|
|
10
|
+
export { defaultWriteSignature } from "./write.ts";
|
package/dist/signature/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { fsToolDefinitions } from "../bundle/definitions.js";
|
|
2
|
+
export { applyPatchToolDefinition, editToolDefinition, writeToolDefinition } from "./definition.js";
|
|
3
|
+
export { defaultEditSignature, multiEditSignature } from "./edit.js";
|
|
2
4
|
export { writeSignatureMessages } from "./messages.js";
|
|
3
5
|
export { defaultPatchSignature, freeformPatchSignature } from "./patch.js";
|
|
4
|
-
export { defaultWriteSignature
|
|
6
|
+
export { defaultWriteSignature } from "./write.js";
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { SignatureDocs } from "@better-fs-tools/read";
|
|
2
2
|
import type { PatchSignature } from "./contract.ts";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* apply_patch({ patch }) as JSON, with a short example in the description. For
|
|
5
|
+
* a host with grammar tools, use freeformPatchSignature().
|
|
6
|
+
*/
|
|
4
7
|
export declare function defaultPatchSignature(options?: SignatureDocs<"patch">): PatchSignature;
|
|
5
8
|
/** defaultPatchSignature plus the Codex Lark grammar, for hosts with grammar tools. */
|
|
6
9
|
export declare function freeformPatchSignature(options?: SignatureDocs<"patch">): PatchSignature;
|
package/dist/signature/patch.js
CHANGED
|
@@ -21,7 +21,10 @@ const patchDescription = (patch) => "Apply a patch that adds, updates, moves, or
|
|
|
21
21
|
"`*** Move to: <path>` after an Update line to rename the file. Every line of an Add " +
|
|
22
22
|
"starts with `+`. Every hunk is checked before any file changes: when one fails, no file " +
|
|
23
23
|
"changes. Read each file you update or delete with the read tool first.";
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* apply_patch({ patch }) as JSON, with a short example in the description. For
|
|
26
|
+
* a host with grammar tools, use freeformPatchSignature().
|
|
27
|
+
*/
|
|
25
28
|
export function defaultPatchSignature(options = {}) {
|
|
26
29
|
return patchSignature(options, "defaultPatchSignature");
|
|
27
30
|
}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import type { SignatureDocs } from "@better-fs-tools/read";
|
|
2
2
|
import type { WriteSignature } from "./contract.ts";
|
|
3
|
-
/** write({ path, content }). */
|
|
3
|
+
/** write({ path, content }). Name "write". `names` renames either parameter. */
|
|
4
4
|
export declare function defaultWriteSignature(options?: SignatureDocs<"path" | "content">): WriteSignature;
|
|
5
|
-
/**
|
|
6
|
-
* write_file({ file_path, content }). Claude Code. The same as
|
|
7
|
-
* defaultWriteSignature with another tool name and path name.
|
|
8
|
-
*/
|
|
9
|
-
export declare function snakeCaseWriteSignature(options?: SignatureDocs<"file_path" | "content">): WriteSignature;
|
package/dist/signature/write.js
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import { checkDocs, deepFreeze, objectSchema, pathSchema, readObject, readPath, readString, stringSchema, } from "./schema.js";
|
|
2
|
-
/** write({ path, content }). */
|
|
2
|
+
/** write({ path, content }). Name "write". `names` renames either parameter. */
|
|
3
3
|
export function defaultWriteSignature(options = {}) {
|
|
4
4
|
return writeSignature(options, "defaultWriteSignature", "write", "path");
|
|
5
5
|
}
|
|
6
|
-
/**
|
|
7
|
-
* write_file({ file_path, content }). Claude Code. The same as
|
|
8
|
-
* defaultWriteSignature with another tool name and path name.
|
|
9
|
-
*/
|
|
10
|
-
export function snakeCaseWriteSignature(options = {}) {
|
|
11
|
-
return writeSignature(options, "snakeCaseWriteSignature", "write_file", "file_path");
|
|
12
|
-
}
|
|
13
6
|
function writeSignature(options, label, name, presetPathName) {
|
|
14
7
|
const checked = checkDocs(options, label, [presetPathName, "content"]);
|
|
15
8
|
const { describe } = checked;
|
package/docs/architecture.md
CHANGED
|
@@ -33,7 +33,7 @@ formatter.format(report, { mode: "model", call, ... }) ─▶ content
|
|
|
33
33
|
MutationResult
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
| Stage |
|
|
36
|
+
| Stage | Option | What happens |
|
|
37
37
|
| ------------ | --------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
38
38
|
| Input | `limits` | `parseEditInput`, `parseWriteInput`, or `parseApplyPatchInput`. Unknown keys and blank paths are refused. `apply_patch` also parses the patch here |
|
|
39
39
|
| Filesystem | `fs` | A `WritableFileSystem`, or a factory of the call context. The factory runs once for each call |
|
|
@@ -53,14 +53,14 @@ MutationResult
|
|
|
53
53
|
| Record | `state`, `digest`, `clock` | Stores a record for each committed file. A store failure does not fail the call |
|
|
54
54
|
| Format | `formatter`, `messages` | Turns the report into content parts |
|
|
55
55
|
|
|
56
|
-
Some stages cannot be removed by any
|
|
56
|
+
Some stages cannot be removed by any option: input validation, the type check, the order of the access authorize before any content read, the lock, the load cap, the codec round trip, the precondition check when a store is set, the literal splice, the check of every change before the first commit, and the record after a commit. They are the reason the package exists. Everything else is an option.
|
|
57
57
|
|
|
58
58
|
## Source layout
|
|
59
59
|
|
|
60
60
|
| Path | Role |
|
|
61
61
|
| ------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------- |
|
|
62
62
|
| `src/contract/` | The public types, one file for each area. No runtime code |
|
|
63
|
-
| `src/core/create-tools.ts`, `core/deps.ts` | The three factories. They check and resolve the
|
|
63
|
+
| `src/core/create-tools.ts`, `core/deps.ts` | The three factories. They check and resolve the options once, synchronously |
|
|
64
64
|
| `src/core/pipeline.ts` | The stage order for `edit` and `write`. `apply_patch` has its own order in `core/patch-pipeline.ts` |
|
|
65
65
|
| `src/core/scope.ts` | Per-call state: the call object, the phase, `fs(call)`, `state(call)`, notes, abort checks, and failures |
|
|
66
66
|
| `src/core/resolve.ts`, `target.ts`, `lock.ts`, `load.ts`, `precondition.ts` | Resolve, stat, lock, load, and the precondition table |
|
|
@@ -75,7 +75,7 @@ Some stages cannot be removed by any dependency: input validation, the type chec
|
|
|
75
75
|
|
|
76
76
|
A host passes `{ signal?, callId?, host }`, the read tool's `ToolCallContext`. The core passes this object by reference to every stage and every host function, as `ctx.call`. It never reads, copies, freezes, or stores `host`. `host` never appears in the result, a record, a note, or content.
|
|
77
77
|
|
|
78
|
-
A throw or a malformed return from host code gives `EXTENSION_FAILED` with `data: { extension, phase, id? }`. After the commit, hooks are the exception: the file is already written, so a hook failure
|
|
78
|
+
A throw or a malformed return from host code gives `EXTENSION_FAILED` with `data: { extension, phase, id? }`. After the commit, hooks are the exception: the file is already written, so a hook failure adds no note and the status stays `ok`. A formatter failure is the other exception: when a formatter throws or returns neither a string nor an array, the default formatter formats the report and no note is added. The status, `changes`, and `commit` stay, so a committed change is never lost.
|
|
79
79
|
|
|
80
80
|
The signal is checked before each stage and raced against each host function and backend call. From the first commit call to the end of the call, the signal is ignored. A started commit finishes or rolls back, and the record is stored. A half-published patch would be worse than a late abort. Hooks after the commit are not raced against the signal either, so a hook that never settles holds the call open.
|
|
81
81
|
|
|
@@ -115,10 +115,12 @@ The precondition stage reads the record at the real path. A record of another sc
|
|
|
115
115
|
| No record | `NOT_READ` | `NOT_READ` | `NOT_READ` |
|
|
116
116
|
| Partial record, partial not allowed | `NOT_READ` (`wholeFile: true`) | same | same |
|
|
117
117
|
| Fresh | Go on | Go on | Go on |
|
|
118
|
-
| Not fresh, `onStale: "rematch"` | Exact rematch of every pair, or `STALE` | `STALE` | Exact rematch of every hunk, or `STALE`. A Delete gives `STALE` |
|
|
119
118
|
| Not fresh, `onStale: "reject"` | `STALE` | `STALE` | `STALE` |
|
|
119
|
+
| Not fresh, `onStale: "rematch"` | Exact rematch of every pair, or `STALE` | `STALE` | Exact rematch of every hunk, or `STALE`. A Delete gives `STALE` |
|
|
120
|
+
|
|
121
|
+
`onStale` defaults to `"reject"`. `"rematch"` is opt-in.
|
|
120
122
|
|
|
121
|
-
The commit carries a precondition: `absent` for a create, and the loaded `version` for a replace or a remove. A backend that reports `compareAndSwap: true` checks it next to the publish. For a backend that does not, the core stats the target again just before the write and gives `STALE` or `EXISTS` itself
|
|
123
|
+
The commit carries a precondition: `absent` for a create, and the loaded `version` for a replace or a remove. A backend that reports `compareAndSwap: true` checks it next to the publish. For a backend that does not, the core stats the target again just before the write and gives `STALE` or `EXISTS` itself. The window between that stat and the write stays.
|
|
122
124
|
|
|
123
125
|
## Matching
|
|
124
126
|
|
|
@@ -127,17 +129,18 @@ The commit carries a precondition: `absent` for a create, and the loaded `versio
|
|
|
127
129
|
The core owns the rules on every hit:
|
|
128
130
|
|
|
129
131
|
- The splice is literal: `text.slice(0, start) + newText + text.slice(end)`. `String.prototype.replace` is never called, so `$&` and `$1` stay as written.
|
|
132
|
+
- A matcher's `adapt()` can rewrite the new text for its hit before the splice. `normalizedMatcher()` and `lineTrimmedMatcher()` use it so that the leading and trailing lines the new text leaves as they were keep the file's bytes, and each replaced line keeps the CR of the file line it replaces. When the old text and the new text are the same, the new text keeps its characters.
|
|
130
133
|
- A loose hit much longer than the old text (`span`), a hit that starts or ends inside a folded span (`boundary`), and a loose hit whose new text adds escape sequences the matched text does not have (`escape`) give `MATCH_REFUSED`.
|
|
131
134
|
- Ranges of different pairs must not overlap. Splices apply from the end.
|
|
132
135
|
- A result equal to the original gives `NO_CHANGE`, unless every pair is already applied.
|
|
133
136
|
|
|
134
|
-
A miss gets help: an `already-applied` note when the new text is in the file and the old text is not,
|
|
137
|
+
A miss is `NO_MATCH`, with a trailing-newline hint when that is the only difference. With `recovery: true`, a miss gets more help: an `already-applied` note when the new text is in the file and the old text is not, the closest region with line numbers, and after three misses in a row on one file a `repeated-miss` note. The miss count lives in the tool instance, not in the store.
|
|
135
138
|
|
|
136
139
|
## apply_patch
|
|
137
140
|
|
|
138
141
|
The order is parse, resolve, stat, access, lock, stat again, load, preconditions, verify every hunk, plan, guards, change authorize, encode, commit, hooks, record.
|
|
139
142
|
|
|
140
|
-
Verification collects every problem before anything changes: an Add on an existing file, an Update or Delete on a missing file, a move onto an existing file, two operations on one file, a missing `remove()` for a Delete or Move, and each hunk that does not match. Each hunk matches at the first place after the previous hunk (Codex). The chain runs on whole lines. A ` ` context line takes the file's own line, so its bytes stay the same.
|
|
143
|
+
Verification collects every problem before anything changes: an Add on an existing file, an Update or Delete on a missing file, a move onto an existing file, two operations on one file, a missing `remove()` for a Delete or Move, and each hunk that does not match. Each hunk matches at the first place after the previous hunk (Codex). The chain runs on whole lines. A ` ` context line takes the file's own line, so its bytes stay the same. In each run of `-` and `+` lines, a `-` line that comes back unchanged as a `+` line also takes the file's line, and each other `+` line takes the CR of the file line it replaces. A hunk whose old and new lines are the same writes its `+` lines as given, with those CRs.
|
|
141
144
|
|
|
142
145
|
The commit keeps a journal:
|
|
143
146
|
|
|
@@ -165,7 +168,7 @@ Hooks run after the whole commit, once for each committed file, in order. `newFi
|
|
|
165
168
|
|
|
166
169
|
## Records
|
|
167
170
|
|
|
168
|
-
After a commit, each committed file gets a record with `schema: 2`, `origin: "write"`, the new version, and the content hash of the written bytes. `request` is `null`, and `viewId` equals `contentId`. `wholeFileVisible` is true after a `write` and a patch Add. After an `edit` or a patch Update it keeps the previous record's value. It is false when an authorizer replaced the content, a hook rewrote the file, or an edit went ahead on a stale record: the model has not seen those bytes, so a later `write` needs a read. A move stores the destination and deletes the source key. A Delete deletes the key. `no-change` stores nothing.
|
|
171
|
+
After a commit, each committed file gets a record with `schema: 2`, `origin: "write"`, the new version, and the content hash of the written bytes. `request` is `null`, `seenLines` is empty, and `viewId` equals `contentId`. `wholeFileVisible` is true after a `write` and a patch Add. After an `edit` or a patch Update it keeps the previous record's value. It is false when an authorizer replaced the content, a hook rewrote the file, or an edit went ahead on a stale record: the model has not seen those bytes, so a later `write` needs a read. A move stores the destination and deletes the source key. A Delete deletes the key. `no-change` stores nothing.
|
|
169
172
|
|
|
170
173
|
`memoryStore()` keeps 1 000 records for 30 minutes. A read older than that needs a new read before an edit.
|
|
171
174
|
|
|
@@ -201,14 +204,14 @@ A backend keeps the policy. The core never checks roots or symlinks itself. A wr
|
|
|
201
204
|
- never replaces a symbolic link: it follows a link inside the roots to its real path, or refuses it;
|
|
202
205
|
- reports a `version` that changes with every change of the bytes, and the same token from `stat()` and from `open().info.version`;
|
|
203
206
|
- enforces `absent`, `version`, and `any`, and gives `exists` or `changed`;
|
|
204
|
-
- reports `writeCapabilities` honestly.
|
|
207
|
+
- reports `writeCapabilities.compareAndSwap` honestly. When it is false, the core checks the precondition itself just before the write.
|
|
205
208
|
|
|
206
209
|
`runWritableFileSystemConformance(fs, { scratchDirectory })` from `@better-fs-tools/fs` checks these rules. The three virtual adapters show three ways to meet them with weaker backends:
|
|
207
210
|
|
|
208
211
|
| Adapter | Backend calls | How it meets the contract |
|
|
209
212
|
| -------------------------------- | --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
210
213
|
| `cloudflareShellFileSystem()` | `writeFileBytes`, `mkdir`, `rm` | Walks the path with `lstat` first, because `writeFileBytes` creates parents and follows a leaf link. Passes the old mime type back. No modes |
|
|
211
|
-
| `cloudflareComputerFileSystem()` | `writeFile`, `mkdir`, `rm` | One transaction, so
|
|
214
|
+
| `cloudflareComputerFileSystem()` | `writeFile`, `mkdir`, `rm` | One transaction, so a replace is atomic. `exclusive: true` for a create. Passes the old mode back, because `writeFile` resets it |
|
|
212
215
|
| `justBashFileSystem()` | `writeFile`, `mkdir`, `rm`, `chmod`, `utimes` | `chmod` after a replace, because `InMemoryFs` resets the mode. Moves `mtime` on by 1 ms when a write left it the same, so the version changes |
|
|
213
216
|
|
|
214
217
|
None of them has `stage()`, so `apply_patch` writes each file in turn and undoes the journal on a failure.
|
package/docs/hosts.md
CHANGED
|
@@ -1,67 +1,146 @@
|
|
|
1
1
|
# Hosts and backends
|
|
2
2
|
|
|
3
|
-
This page helps you choose
|
|
3
|
+
This page helps you choose an integration and a filesystem backend. It lists the defaults that every integration shares, the few options that only one host has, a recommended configuration for each host, and what each backend can do. The READMEs of the integration and backend packages link here. The docs site has the same facts on [Choose an integration](https://better-fs-tools.gandrew.com/integrations) and [Filesystems](https://better-fs-tools.gandrew.com/filesystems).
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## One interface in three layers
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
| Layer | Factories | Takes |
|
|
8
|
+
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
|
|
9
|
+
| Core | `createReadTool()`, `createEditTool()`, `createWriteTool()`, `createApplyPatchTool()`, `createBashTool()`, `createFsTools()` | `XxxToolOptions` and `FsToolsOptions`. `fs` is required. bash needs `runner` and `env` |
|
|
10
|
+
| Definitions | `readToolDefinition()`, `editToolDefinition()`, `writeToolDefinition()`, `applyPatchToolDefinition()`, `bashToolDefinition()`, `fsToolDefinitions()` in the `./signature` subpaths | the core options, plus `signature` |
|
|
11
|
+
| Integration | the AI SDK, Pi, pi-agent-core, and pi-durable factories | the core options, plus `signature`, plus host display or registration options |
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
| ---------------------- | ------------------------- | ------------------------------------------------------------------------------------------- |
|
|
11
|
-
| `createFsTools()` | `@better-fs-tools/write` | You write your own host glue, or you run in a Worker with a Cloudflare or just-bash backend |
|
|
12
|
-
| `createNodeFsTools()` | `@better-fs-tools/node` | You run on Node or Bun and want the local filesystem |
|
|
13
|
-
| `createPiFsTools()` | `@better-fs-tools/pi` | You write a Pi coding agent extension |
|
|
14
|
-
| `createAiSdkFsTools()` | `@better-fs-tools/ai-sdk` | You pass the tools to AI SDK 7 `generateText` or `streamText`, with any backend |
|
|
13
|
+
A definition binds a core tool to its signature: the name, description, and JSON Schema to declare, a `validate` for model input, and an `execute` that maps model input and runs the tool. Every integration is an adapter over the definitions, so a host of your own gets the same behaviour from them.
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
| Integration | Single tools | Bundle |
|
|
16
|
+
| ------------------ | -------------------------------------------------------------------------------------- | ----------------------------------------------------- |
|
|
17
|
+
| AI SDK 7 | `createAiSdkReadTool()` and the four others | `createAiSdkFsTools()` |
|
|
18
|
+
| Pi coding agent | `createPiReadTool()` and the four others | `createPiFsTools()` |
|
|
19
|
+
| Pi agent core | `createAgentCoreReadTool()` and the four others, from `@better-fs-tools/pi/agent-core` | `createAgentCoreFsTools()` |
|
|
20
|
+
| Pi durable harness | none: tools register inside an extension | `createDurableFsTools()`, which returns the extension |
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
The Node, just-bash, Cloudflare Shell, and Cloudflare Computer packages are backends, not integrations. Pass their filesystem as `fs`, and a runner as the bash `runner`, to any factory.
|
|
19
23
|
|
|
20
|
-
|
|
21
|
-
| --------------------------------- | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | --------------------------------------------------------------------- |
|
|
22
|
-
| `fs` | required: a backend, or a factory of the call | `nodeFileSystem({ cwd, allowedRoots: [cwd] })`, `cwd` default `process.cwd()` | a `nodeFileSystem` rooted at `ctx.cwd` on each call. `fs`, `cwd`, and `allowedRoots` throw | required, as in `createFsTools()` |
|
|
23
|
-
| Tool input | canonical | canonical | the Pi signatures below | the AI SDK signatures below, `strict: true` |
|
|
24
|
-
| `state` | `memoryStore({ clock })` | `memoryStore({ clock })` | `memoryStore({ clock })` | `memoryStore({ clock })` |
|
|
25
|
-
| `digest` | `sha256Digest()`, plain JavaScript | `nodeDigest()` | `nodeDigest()` | `sha256Digest()` |
|
|
26
|
-
| `locks` | `memoryLocks()` | `memoryLocks()` | `memoryLocks()` | `memoryLocks()` |
|
|
27
|
-
| `clock` | `() => new Date()` | `() => new Date()` | `() => new Date()` | `() => new Date()` |
|
|
28
|
-
| `bash` | off. An options object with `runner` and `env` adds it. `true` throws | off. `true` or an options object adds it | none. Register `createPiBashTool()` on its own | off. An options object with `runner` and `env` adds it. `true` throws |
|
|
29
|
-
| bash `runner` | required | `nodeCommandRunner({ cwd })` | `createPiBashTool()`: a Node runner at `ctx.cwd` | required |
|
|
30
|
-
| bash `env` | required | `shellEnv(() => process.env)` | `createPiBashTool()`: `shellEnv(() => process.env)` | required |
|
|
31
|
-
| New file and directory modes | the backend's | `0o666` and `0o777` less the process umask. `newFileMode` and `newDirectoryMode` set them exactly | as Node | the backend's |
|
|
32
|
-
| `symlinks`, `identity`, buffering | the backend's | `"follow-within-roots"`, `"required"`, streams | as Node | the backend's |
|
|
33
|
-
| `invalidate` | `(path, call?)` | `(path, call?)`, `call` ignored | `(path, call?)`, pass the call | `(path, call?)` |
|
|
24
|
+
## Defaults
|
|
34
25
|
|
|
35
|
-
|
|
26
|
+
Every core tool, bundle, and integration has these defaults.
|
|
27
|
+
|
|
28
|
+
| Option | Default |
|
|
29
|
+
| --------------------------------- | ------------------------------------------------------------------------------------------------------------- |
|
|
30
|
+
| `fs` | required: a backend, or a factory of the call |
|
|
31
|
+
| `state` | `null`: no read-before-write. A store, such as `memoryStore({ clock })`, or a factory of the call turns it on |
|
|
32
|
+
| `digest` | `sha256Digest()`, plain JavaScript. `null` turns observations off, and then `state` must be `null` |
|
|
33
|
+
| `locks` | `memoryLocks()` |
|
|
34
|
+
| `clock` | `() => new Date()` |
|
|
35
|
+
| `read.converters` | `[imageConverter()]`: an image becomes a media part. `[]` turns images off |
|
|
36
|
+
| `applyPatch` in a bundle | off. `true` or an options object adds `apply_patch` |
|
|
37
|
+
| `bash` in a bundle | off. An options object with `runner` and `env` adds it. `true` throws |
|
|
38
|
+
| bash `runner`, `env` | required |
|
|
39
|
+
| bash `cwd` | the runner's `cwd` |
|
|
40
|
+
| New file and directory modes | the backend's |
|
|
41
|
+
| `symlinks`, `identity`, buffering | the backend's |
|
|
42
|
+
| `invalidate` of a bundle | `(path, call?)`. Pass the call when `fs` or `state` is a factory |
|
|
43
|
+
|
|
44
|
+
`sha256Digest()` and `nodeDigest()` give the same digest, with the id `sha256`, so records made with one are valid for the other. `nodeDigest()` uses `node:crypto` and is faster. `sha256Digest()` runs in a Worker.
|
|
45
|
+
|
|
46
|
+
In every bundle, a shared key (`fs`, `state`, `digest`, `locks`, `clock`) inside one tool's options throws `TypeError`, and so does an unknown option key. The bash tool gets the bundle's digest and clock, so `ctx.digest` and `ctx.clock` in a bash hook match the file tools. The allowed roots never limit what a bash command touches.
|
|
47
|
+
|
|
48
|
+
A single-tool factory shares nothing with another one: each write tool makes its own lock manager, and there is no read store unless you pass one. Use a bundle when a host installs more than one tool.
|
|
36
49
|
|
|
37
50
|
### Tool signatures
|
|
38
51
|
|
|
39
|
-
A signature is the model-facing shape of a tool. The core
|
|
52
|
+
A signature is the model-facing shape of a tool. The core tools take the canonical input. Every definition and integration has the same default signatures.
|
|
53
|
+
|
|
54
|
+
| Tool | Canonical input (core) | Default signature |
|
|
55
|
+
| ------------- | ------------------------------------------------------ | --------------------------------------------------------------------------------------------- |
|
|
56
|
+
| `read` | `{ path, offset?, limit? }` | `defaultReadSignature()`: `read({ path, offset?, limit? })` |
|
|
57
|
+
| `edit` | `{ path, edits: [{ oldText, newText, replaceAll? }] }` | `defaultEditSignature({ matchers })`: `edit({ path, old_string, new_string, replace_all? })` |
|
|
58
|
+
| `write` | `{ path, content }` | `defaultWriteSignature()`: `write({ path, content })` |
|
|
59
|
+
| `apply_patch` | `{ patch }` | `defaultPatchSignature()`: `apply_patch({ patch })` as JSON |
|
|
60
|
+
| `bash` | `{ command, timeoutMs?, cwd? }` | `defaultBashSignature({ runner, limits })`: `bash({ command, timeout?, cwd? })`, milliseconds |
|
|
61
|
+
|
|
62
|
+
To give a model other names, pass a default signature with options as the tool's `signature`. For example, `defaultBashSignature({ timeoutUnit: "s", cwd: false })` gives `bash({ command, timeout? })` in seconds. Every default signature takes `name`, `description`, `describe`, and `names`. `names` renames a parameter, keyed by the signature's own parameter names. Three presets give another shape: `multiEditSignature()` gives `edit({ path, edits: [{ oldText, newText }] })` for many replacements in one call, `lineRangeSignature()` gives `read({ path, start?, end? })` with inclusive lines, and `freeformPatchSignature()` adds the Codex patch grammar. The Pi, pi-agent-core, and pi-durable integrations send that grammar as `constrainedSampling`. The AI SDK sends only the JSON schema. For any other shape, write your own signature.
|
|
63
|
+
|
|
64
|
+
### Host options
|
|
65
|
+
|
|
66
|
+
An integration adds options only for its host's display or registration. It changes no default.
|
|
67
|
+
|
|
68
|
+
| Integration | Options | Default | Why |
|
|
69
|
+
| ----------- | ----------------------------------- | --------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
70
|
+
| AI SDK | `contextSchema` | none | The AI SDK validates the `toolsContext` entry of a tool with it. |
|
|
71
|
+
| Pi | `promptSnippet`, `promptGuidelines` | the first sentence of the signature description, and `[]` | Pi lists a tool under "Available tools" only when it has a snippet. The text comes from the shared signature. |
|
|
72
|
+
| pi-durable | `name`, `outputLimits` | `"better-fs-tools"`, and 128 KiB and 4,000 lines | Durable extensions have names. The Harness cuts tool output again, and these limits are above the `read` view, so the output is not cut twice. |
|
|
73
|
+
|
|
74
|
+
`piToolRenderers()` from `@better-fs-tools/pi` is a renderer resolver, not an option. Pi draws a tool named `read`, `edit`, `write`, or `bash` with its built-in renderer, which reads Pi's argument names. The resolver maps the shared arguments to them.
|
|
75
|
+
|
|
76
|
+
## Recommended configurations
|
|
77
|
+
|
|
78
|
+
Each host has choices that suit it. They are options, not defaults, so each one is visible in your code.
|
|
79
|
+
|
|
80
|
+
### Pi coding agent
|
|
81
|
+
|
|
82
|
+
The `./extension` entry of `@better-fs-tools/pi` uses the first three options. It registers `read`, `edit`, and `write`, so Pi keeps its own bash:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import { createPiFsTools, piMutationQueueLocks } from "@better-fs-tools/pi";
|
|
86
|
+
import { piCwdCommandRunner, piCwdFileSystem } from "@better-fs-tools/pi/node";
|
|
87
|
+
import { nodeDigest } from "@better-fs-tools/node";
|
|
88
|
+
import { shellEnv } from "@better-fs-tools/shell";
|
|
89
|
+
|
|
90
|
+
createPiFsTools({
|
|
91
|
+
fs: piCwdFileSystem(), // a Node filesystem rooted at ctx.cwd on each call
|
|
92
|
+
locks: piMutationQueueLocks(), // the per-file queue of Pi's own edit and write
|
|
93
|
+
digest: nodeDigest(), // faster on Node than sha256Digest()
|
|
94
|
+
// To replace Pi's own bash too:
|
|
95
|
+
bash: { runner: piCwdCommandRunner(), env: shellEnv(() => process.env) },
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Alternatives: `memoryLocks()` when no other extension writes files, `state: memoryStore()` for read-before-write, and `piCwdFileSystem({ denyRoots, symlinks })` to narrow the root.
|
|
100
|
+
|
|
101
|
+
### AI SDK on Node or Bun
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import { createAiSdkFsTools } from "@better-fs-tools/ai-sdk";
|
|
105
|
+
import { nodeCommandRunner, nodeDigest, nodeFileSystem } from "@better-fs-tools/node";
|
|
106
|
+
import { shellEnv } from "@better-fs-tools/shell";
|
|
107
|
+
|
|
108
|
+
const cwd = process.cwd();
|
|
109
|
+
createAiSdkFsTools({
|
|
110
|
+
fs: nodeFileSystem({ cwd, allowedRoots: [cwd] }),
|
|
111
|
+
digest: nodeDigest(),
|
|
112
|
+
bash: { runner: nodeCommandRunner({ cwd }), env: shellEnv(() => process.env) },
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
In a Worker, pass `cloudflareShellFileSystem()` or `justBashFileSystem()` as `fs` and keep the default digest.
|
|
117
|
+
|
|
118
|
+
### Pi agent core
|
|
40
119
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
| `edit` | `{ path, edits: [{ oldText, newText, replaceAll? }] }` | `multiEditSignature()`: `edit({ path, edits: [{ oldText, newText }] })` | `defaultEditSignature()`: `edit({ path, old_string, new_string, replace_all? })` |
|
|
45
|
-
| `write` | `{ path, content }` | `defaultWriteSignature()`: `write({ path, content })` | `defaultWriteSignature()`: `write({ path, content })` |
|
|
46
|
-
| `apply_patch` | `{ patch }` | `freeformPatchSignature()`: `apply_patch({ patch })` plus the Codex grammar | `defaultPatchSignature()`: `apply_patch({ patch })` as JSON |
|
|
47
|
-
| `bash` | `{ command, timeoutMs?, cwd? }` | `createPiBashTool()`: `bash({ command, timeout? })`, seconds, no `cwd` | `defaultBashSignature({ runner, limits })`: `bash({ command, timeout?, cwd? })`, milliseconds |
|
|
120
|
+
```ts
|
|
121
|
+
import { createAgentCoreFsTools } from "@better-fs-tools/pi/agent-core";
|
|
122
|
+
import { memoryFileSystem } from "@better-fs-tools/fs";
|
|
48
123
|
|
|
49
|
-
|
|
124
|
+
createAgentCoreFsTools({ fs: memoryFileSystem() }); // any writable filesystem; no Node import
|
|
125
|
+
```
|
|
50
126
|
|
|
51
|
-
###
|
|
127
|
+
### Pi durable harness
|
|
52
128
|
|
|
53
|
-
|
|
129
|
+
```ts
|
|
130
|
+
import {
|
|
131
|
+
createDurableFsTools,
|
|
132
|
+
documentReadStore,
|
|
133
|
+
durableEnvFileSystem,
|
|
134
|
+
durableEnvRunner,
|
|
135
|
+
} from "@better-fs-tools/pi-durable";
|
|
136
|
+
import { shellEnv } from "@better-fs-tools/shell";
|
|
54
137
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
| `createPiReadTool()` and the Pi write tools | none | `nodeDigest()` | none |
|
|
62
|
-
| `createPiBashTool()` | none | none | `shellEnv(() => process.env)` |
|
|
63
|
-
| `createAiSdkReadTool()` and the AI SDK write tools | none | none. A `state` without a `digest` throws | none |
|
|
64
|
-
| `createAiSdkBashTool()` | none | none | required |
|
|
138
|
+
createDurableFsTools({
|
|
139
|
+
fs: durableEnvFileSystem({ allowedRoots: ["."] }), // through the call's ExecutionEnv
|
|
140
|
+
state: documentReadStore(), // read records follow the conversation and its forks
|
|
141
|
+
bash: { runner: durableEnvRunner(), env: shellEnv() }, // the environment's exec()
|
|
142
|
+
});
|
|
143
|
+
```
|
|
65
144
|
|
|
66
145
|
## Backends
|
|
67
146
|
|
|
@@ -75,13 +154,13 @@ Every backend takes the shared `FileSystemRootOptions` from `@better-fs-tools/fs
|
|
|
75
154
|
| `cloudflareShellFileSystem()` | `@better-fs-tools/cloudflare-shell` | buffered in `open()` | the whole file | 16 MiB | `"reject"` only | `"none"` only |
|
|
76
155
|
| `cloudflareComputerFileSystem()` | `@better-fs-tools/cloudflare-computer` | stream, opened in `open()` | the read request is sent, but no chunk is read | none | `"reject"` only | `"none"` only |
|
|
77
156
|
|
|
78
|
-
| Backend | Several `allowedRoots` | `denyRoots` | `cwd` default | Write methods | `stage()` | `remove()` | New file mode
|
|
79
|
-
| -------------------------------- | --------------------------------- | ------------------------------------- | ---------------------- | ------------------------------------- | --------- | ---------- |
|
|
80
|
-
| `nodeFileSystem()` | yes | yes, added to `/dev`, `/proc`, `/sys` | `process.cwd()` | always | yes | yes | `0o666` less the umask
|
|
81
|
-
| `memoryFileSystem()` | no, every absolute path is inside | yes | none | always. `readOnly: true` refuses them | yes | yes | `0o644`
|
|
82
|
-
| `justBashFileSystem()` | yes | yes | `/` | checked at use | no | yes | `0o644`
|
|
83
|
-
| `cloudflareShellFileSystem()` | yes | yes | the first allowed root | checked at use | no | yes | none: Shell has no modes
|
|
84
|
-
| `cloudflareComputerFileSystem()` | yes | yes | the first allowed root | checked at use | no | yes | `0o644`
|
|
157
|
+
| Backend | Several `allowedRoots` | `denyRoots` | `cwd` default | Write methods | `stage()` | `remove()` | New file mode |
|
|
158
|
+
| -------------------------------- | --------------------------------- | ------------------------------------- | ---------------------- | ------------------------------------- | --------- | ---------- | ---------------------------------------------- |
|
|
159
|
+
| `nodeFileSystem()` | yes | yes, added to `/dev`, `/proc`, `/sys` | `process.cwd()` | always | yes | yes | `0o666` less the umask |
|
|
160
|
+
| `memoryFileSystem()` | no, every absolute path is inside | yes | none | always. `readOnly: true` refuses them | yes | yes | `0o644` |
|
|
161
|
+
| `justBashFileSystem()` | yes | yes | `/` | checked at use | no | yes | the backend's default. `0o644` in `InMemoryFs` |
|
|
162
|
+
| `cloudflareShellFileSystem()` | yes | yes | the first allowed root | checked at use | no | yes | none: Shell has no modes |
|
|
163
|
+
| `cloudflareComputerFileSystem()` | yes | yes | the first allowed root | checked at use | no | yes | `0o644` |
|
|
85
164
|
|
|
86
165
|
- "Checked at use": the adapter builds over a backend object without its write methods. Reads work, and a write gives `unsupported`, which the write tools report as `UNSUPPORTED_BACKEND`.
|
|
87
166
|
- A deny root gives `dangerous-path` in every backend.
|
|
@@ -90,6 +169,6 @@ Every backend takes the shared `FileSystemRootOptions` from `@better-fs-tools/fs
|
|
|
90
169
|
|
|
91
170
|
### Buffered reads and authorization
|
|
92
171
|
|
|
93
|
-
The read tool calls `authorize` after `fs.open()` and before it reads any content byte. A buffered backend (just-bash and Cloudflare Shell) has already fetched the whole file inside `open()`, so those bytes have left the backend before `authorize` runs. Cloudflare Computer opens the read stream in `open()`: the request reaches the backend, but no chunk is read. In every backend, the core passes no content byte to a classifier, a converter, or the model until `authorize` allows it.
|
|
172
|
+
The read tool calls `authorize` after `fs.open()` and before it reads any content byte. A buffered backend (just-bash and Cloudflare Shell) has already fetched the whole file inside `open()`, so those bytes have left the backend before `authorize` runs. Cloudflare Computer opens the read stream in `open()`: the request reaches the backend, but no chunk is read. In every backend, the core passes no content byte to a classifier, a converter, or the model until `authorize` allows it.
|
|
94
173
|
|
|
95
174
|
If a denied read must not reach the backend at all, refuse the path in the backend itself, with `denyRoots` or by leaving it out of `allowedRoots`. The write tools are not affected: they authorize after `stat`, before they open the file.
|