@better-fs-tools/write 0.2.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.
@@ -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;
@@ -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;
@@ -33,7 +33,7 @@ formatter.format(report, { mode: "model", call, ... }) ─▶ content
33
33
  MutationResult
34
34
  ```
35
35
 
36
- | Stage | Dependency | What happens |
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 dependency: 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 a dependency.
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 dependencies once, synchronously |
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 |
@@ -129,6 +129,7 @@ The commit carries a precondition: `absent` for a create, and the loaded `versio
129
129
  The core owns the rules on every hit:
130
130
 
131
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.
132
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`.
133
134
  - Ranges of different pairs must not overlap. Splices apply from the end.
134
135
  - A result equal to the original gives `NO_CHANGE`, unless every pair is already applied.
@@ -139,7 +140,7 @@ A miss is `NO_MATCH`, with a trailing-newline hint when that is the only differe
139
140
 
140
141
  The order is parse, resolve, stat, access, lock, stat again, load, preconditions, verify every hunk, plan, guards, change authorize, encode, commit, hooks, record.
141
142
 
142
- 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.
143
144
 
144
145
  The commit keeps a journal:
145
146
 
@@ -167,7 +168,7 @@ Hooks run after the whole commit, once for each committed file, in order. `newFi
167
168
 
168
169
  ## Records
169
170
 
170
- 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.
171
172
 
172
173
  `memoryStore()` keeps 1 000 records for 30 minutes. A read older than that needs a new read before an edit.
173
174
 
package/docs/hosts.md CHANGED
@@ -1,68 +1,146 @@
1
1
  # Hosts and backends
2
2
 
3
- This page helps you choose a host package and a filesystem backend. It lists what each one sets by default, and what each backend can do. The READMEs of the host and backend packages link here.
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
- ## Choose a bundle
5
+ ## One interface in three layers
6
6
 
7
- Every bundle builds `read`, `edit`, and `write` over one backend, and `apply_patch` when the host asks for it. The tools share one digest, one lock manager, and one clock. With `state`, they also share one read store, so `edit` and `write` know what the model has read. `createFsTools()` is the portable core. The other three wrap it.
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
- | Bundle | Package | Use it when |
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
- The just-bash, Cloudflare Shell, and Cloudflare Computer packages are backends, not bundles. Pass their filesystem as `fs` to `createFsTools()` or `createAiSdkFsTools()`.
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
- ## Bundle defaults
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
- | Setting | `createFsTools()` | `createNodeFsTools()` | `createPiFsTools()` | `createAiSdkFsTools()` |
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` | `null`: no read-before-write. `memoryStore({ clock })` turns it on | `null`, as `createFsTools()` | `null`, as `createFsTools()` | `null`, as `createFsTools()` |
25
- | `applyPatch` | off. `true` or an options object adds `apply_patch` | off, as `createFsTools()` | off, as `createFsTools()`. The `pi.extensions` entry does not register it | off, as `createFsTools()`. When off, `tools` has no `apply_patch` key |
26
- | `digest` | `sha256Digest()`, plain JavaScript | `nodeDigest()` | `nodeDigest()` | `sha256Digest()` |
27
- | `locks` | `memoryLocks()` | `memoryLocks()` | `memoryLocks()` | `memoryLocks()` |
28
- | `clock` | `() => new Date()` | `() => new Date()` | `() => new Date()` | `() => new Date()` |
29
- | `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 |
30
- | bash `runner` | required | `nodeCommandRunner({ cwd })` | `createPiBashTool()`: a Node runner at `ctx.cwd` | required |
31
- | bash `env` | required | `shellEnv(() => process.env)` | `createPiBashTool()`: `shellEnv(() => process.env)` | required |
32
- | 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 |
33
- | `symlinks`, `identity`, buffering | the backend's | `"follow-within-roots"`, `"required"`, streams | as Node | the backend's |
34
- | `invalidate` | `(path, call?)` | `(path, call?)`, `call` ignored | `(path, call?)`, pass the call | `(path, call?)` |
24
+ ## Defaults
35
25
 
36
- 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. A bundle takes `state` as one store or `null`. The single tools also take a per-call store factory; a bundle does not, and throws a `TypeError` that names the bundle. 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.
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.
37
49
 
38
50
  ### Tool signatures
39
51
 
40
- A signature is the model-facing shape of a tool. The core and Node tools take the canonical input and have no signature. Pi and the AI SDK each default to the shape their models know.
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
41
119
 
42
- | Tool | Canonical input (core, Node) | Pi default | AI SDK default |
43
- | ------------- | ------------------------------------------------------ | --------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
44
- | `read` | `{ path, offset?, limit? }` | `defaultReadSignature({ name: "read" })`: `read({ path, offset?, limit? })` | `defaultReadSignature()`: `read({ path, offset?, limit? })` |
45
- | `edit` | `{ path, edits: [{ oldText, newText, replaceAll? }] }` | `multiEditSignature()`: `edit({ path, edits: [{ oldText, newText }] })` | `defaultEditSignature()`: `edit({ path, old_string, new_string, replace_all? })` |
46
- | `write` | `{ path, content }` | `defaultWriteSignature()`: `write({ path, content })` | `defaultWriteSignature()`: `write({ path, content })` |
47
- | `apply_patch` | `{ patch }` | `freeformPatchSignature()`: `apply_patch({ patch })` plus the Codex grammar | `defaultPatchSignature()`: `apply_patch({ patch })` as JSON |
48
- | `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";
49
123
 
50
- Every preset takes `name`, `description`, `describe`, and `names`. `names` renames a parameter, keyed by the preset's own parameter names.
124
+ createAgentCoreFsTools({ fs: memoryFileSystem() }); // any writable filesystem; no Node import
125
+ ```
51
126
 
52
- ### Single-tool factories
127
+ ### Pi durable harness
53
128
 
54
- Each tool also has its own factory. A single 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.
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";
55
137
 
56
- | Factory | `state` | `digest` | bash `env` |
57
- | ------------------------------------------------------------------------------------- | ------- | ------------------------------------------- | ----------------------------- |
58
- | `createReadTool()`, `createEditTool()`, `createWriteTool()`, `createApplyPatchTool()` | none | none. A `state` without a `digest` throws | none |
59
- | `createBashTool()` | none | none | required |
60
- | `createNodeReadTool()` and the Node write tools | none | `nodeDigest()`. `digest: null` turns it off | none |
61
- | `createNodeBashTool()` | none | none | `shellEnv(() => process.env)` |
62
- | `createPiReadTool()` and the Pi write tools | none | `nodeDigest()` | none |
63
- | `createPiBashTool()` | none | none | `shellEnv(() => process.env)` |
64
- | `createAiSdkReadTool()` and the AI SDK write tools | none | none. A `state` without a `digest` throws | none |
65
- | `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
+ ```
66
144
 
67
145
  ## Backends
68
146
 
@@ -76,13 +154,13 @@ Every backend takes the shared `FileSystemRootOptions` from `@better-fs-tools/fs
76
154
  | `cloudflareShellFileSystem()` | `@better-fs-tools/cloudflare-shell` | buffered in `open()` | the whole file | 16 MiB | `"reject"` only | `"none"` only |
77
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 |
78
156
 
79
- | Backend | Several `allowedRoots` | `denyRoots` | `cwd` default | Write methods | `stage()` | `remove()` | New file mode |
80
- | -------------------------------- | --------------------------------- | ------------------------------------- | ---------------------- | ------------------------------------- | --------- | ---------- | ------------------------ |
81
- | `nodeFileSystem()` | yes | yes, added to `/dev`, `/proc`, `/sys` | `process.cwd()` | always | yes | yes | `0o666` less the umask |
82
- | `memoryFileSystem()` | no, every absolute path is inside | yes | none | always. `readOnly: true` refuses them | yes | yes | `0o644` |
83
- | `justBashFileSystem()` | yes | yes | `/` | checked at use | no | yes | `0o644` |
84
- | `cloudflareShellFileSystem()` | yes | yes | the first allowed root | checked at use | no | yes | none: Shell has no modes |
85
- | `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` |
86
164
 
87
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`.
88
166
  - A deny root gives `dangerous-path` in every backend.
@@ -198,6 +198,7 @@ With a `state` store and a `digest`, each committed file gets a record under its
198
198
  origin: "write",
199
199
  observationId, resolvedPath, identity, version, digest,
200
200
  contentId, viewId, observedAt, wholeFileVisible,
201
+ seenLines: [],
201
202
  totalsExact: true,
202
203
  request: null
203
204
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-fs-tools/write",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Edit, write, and apply_patch tools for TypeScript agents.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -46,9 +46,9 @@
46
46
  "access": "public"
47
47
  },
48
48
  "dependencies": {
49
- "@better-fs-tools/fs": "^0.2.0",
50
- "@better-fs-tools/read": "^0.2.0",
51
- "@better-fs-tools/shell": "^0.2.0"
49
+ "@better-fs-tools/fs": "^0.3.0",
50
+ "@better-fs-tools/read": "^0.3.0",
51
+ "@better-fs-tools/shell": "^0.3.0"
52
52
  },
53
53
  "devDependencies": {
54
54
  "typebox": "^1.3.16"