@better-fs-tools/write 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +442 -2
- package/dist/authorize/ask-before-write.d.ts +11 -0
- package/dist/authorize/ask-before-write.js +49 -0
- package/dist/authorize/index.d.ts +3 -0
- package/dist/authorize/index.js +3 -0
- package/dist/authorize/protect-paths.d.ts +12 -0
- package/dist/authorize/protect-paths.js +74 -0
- package/dist/authorize/write-authorizers.d.ts +9 -0
- package/dist/authorize/write-authorizers.js +48 -0
- package/dist/bundle/create-fs-tools.d.ts +71 -0
- package/dist/bundle/create-fs-tools.js +125 -0
- package/dist/codecs/index.d.ts +1 -0
- package/dist/codecs/index.js +1 -0
- package/dist/codecs/utf8.d.ts +7 -0
- package/dist/codecs/utf8.js +61 -0
- package/dist/contract/codec.d.ts +26 -0
- package/dist/contract/codec.js +0 -0
- package/dist/contract/context.d.ts +14 -0
- package/dist/contract/context.js +0 -0
- package/dist/contract/deps.d.ts +55 -0
- package/dist/contract/deps.js +0 -0
- package/dist/contract/extensions.d.ts +103 -0
- package/dist/contract/extensions.js +0 -0
- package/dist/contract/format.d.ts +15 -0
- package/dist/contract/format.js +0 -0
- package/dist/contract/input.d.ts +35 -0
- package/dist/contract/input.js +0 -0
- package/dist/contract/limits.d.ts +26 -0
- package/dist/contract/limits.js +0 -0
- package/dist/contract/locks.d.ts +14 -0
- package/dist/contract/locks.js +0 -0
- package/dist/contract/matcher.d.ts +30 -0
- package/dist/contract/matcher.js +0 -0
- package/dist/contract/messages.d.ts +211 -0
- package/dist/contract/messages.js +0 -0
- package/dist/contract/patch.d.ts +50 -0
- package/dist/contract/patch.js +0 -0
- package/dist/contract/preconditions.d.ts +9 -0
- package/dist/contract/preconditions.js +5 -0
- package/dist/contract/result.d.ts +102 -0
- package/dist/contract/result.js +0 -0
- package/dist/core/abort.d.ts +4 -0
- package/dist/core/abort.js +23 -0
- package/dist/core/authorize.d.ts +9 -0
- package/dist/core/authorize.js +87 -0
- package/dist/core/bytes.d.ts +3 -0
- package/dist/core/bytes.js +14 -0
- package/dist/core/commit-patch.d.ts +20 -0
- package/dist/core/commit-patch.js +224 -0
- package/dist/core/commit.d.ts +9 -0
- package/dist/core/commit.js +111 -0
- package/dist/core/create-tools.d.ts +23 -0
- package/dist/core/create-tools.js +54 -0
- package/dist/core/deps.d.ts +11 -0
- package/dist/core/deps.js +207 -0
- package/dist/core/diff.d.ts +10 -0
- package/dist/core/diff.js +221 -0
- package/dist/core/encode.d.ts +3 -0
- package/dist/core/encode.js +26 -0
- package/dist/core/extension-error.d.ts +8 -0
- package/dist/core/extension-error.js +17 -0
- package/dist/core/format.d.ts +4 -0
- package/dist/core/format.js +36 -0
- package/dist/core/guards.d.ts +3 -0
- package/dist/core/guards.js +45 -0
- package/dist/core/hints.d.ts +14 -0
- package/dist/core/hints.js +75 -0
- package/dist/core/hooks.d.ts +15 -0
- package/dist/core/hooks.js +115 -0
- package/dist/core/input.d.ts +20 -0
- package/dist/core/input.js +91 -0
- package/dist/core/limits.d.ts +10 -0
- package/dist/core/limits.js +48 -0
- package/dist/core/line-index.d.ts +10 -0
- package/dist/core/line-index.js +38 -0
- package/dist/core/load.d.ts +14 -0
- package/dist/core/load.js +221 -0
- package/dist/core/lock.d.ts +2 -0
- package/dist/core/lock.js +56 -0
- package/dist/core/match.d.ts +15 -0
- package/dist/core/match.js +66 -0
- package/dist/core/messages.d.ts +8 -0
- package/dist/core/messages.js +147 -0
- package/dist/core/outcomes.d.ts +21 -0
- package/dist/core/outcomes.js +127 -0
- package/dist/core/parse-patch.d.ts +3 -0
- package/dist/core/parse-patch.js +64 -0
- package/dist/core/patch-hunks.d.ts +25 -0
- package/dist/core/patch-hunks.js +177 -0
- package/dist/core/patch-pipeline.d.ts +4 -0
- package/dist/core/patch-pipeline.js +285 -0
- package/dist/core/pipeline.d.ts +22 -0
- package/dist/core/pipeline.js +153 -0
- package/dist/core/plan-edit.d.ts +13 -0
- package/dist/core/plan-edit.js +215 -0
- package/dist/core/plan-patch.d.ts +29 -0
- package/dist/core/plan-patch.js +169 -0
- package/dist/core/plan-write.d.ts +6 -0
- package/dist/core/plan-write.js +27 -0
- package/dist/core/planned.d.ts +35 -0
- package/dist/core/planned.js +36 -0
- package/dist/core/precondition.d.ts +10 -0
- package/dist/core/precondition.js +76 -0
- package/dist/core/record.d.ts +3 -0
- package/dist/core/record.js +58 -0
- package/dist/core/resolve.d.ts +3 -0
- package/dist/core/resolve.js +65 -0
- package/dist/core/scope.d.ts +33 -0
- package/dist/core/scope.js +109 -0
- package/dist/core/snippet.d.ts +4 -0
- package/dist/core/snippet.js +36 -0
- package/dist/core/splice.d.ts +10 -0
- package/dist/core/splice.js +19 -0
- package/dist/core/target.d.ts +10 -0
- package/dist/core/target.js +46 -0
- package/dist/formatters/default.d.ts +16 -0
- package/dist/formatters/default.js +122 -0
- package/dist/formatters/index.d.ts +2 -0
- package/dist/formatters/index.js +1 -0
- package/dist/guards/generated-file.d.ts +10 -0
- package/dist/guards/generated-file.js +39 -0
- package/dist/guards/index.d.ts +13 -0
- package/dist/guards/index.js +25 -0
- package/dist/guards/non-text.d.ts +3 -0
- package/dist/guards/non-text.js +46 -0
- package/dist/guards/omission.d.ts +9 -0
- package/dist/guards/omission.js +48 -0
- package/dist/guards/read-prefix.d.ts +12 -0
- package/dist/guards/read-prefix.js +87 -0
- package/dist/guards/shared.d.ts +11 -0
- package/dist/guards/shared.js +46 -0
- package/dist/guards/syntax.d.ts +10 -0
- package/dist/guards/syntax.js +54 -0
- package/dist/guards/truncation-notice.d.ts +8 -0
- package/dist/guards/truncation-notice.js +32 -0
- package/dist/hooks/executable-shebang.d.ts +9 -0
- package/dist/hooks/executable-shebang.js +46 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/verify-write.d.ts +9 -0
- package/dist/hooks/verify-write.js +63 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +15 -0
- package/dist/locks/index.d.ts +1 -0
- package/dist/locks/index.js +1 -0
- package/dist/locks/memory-locks.d.ts +9 -0
- package/dist/locks/memory-locks.js +94 -0
- package/dist/matchers/block-anchor.d.ts +9 -0
- package/dist/matchers/block-anchor.js +69 -0
- package/dist/matchers/escape.d.ts +6 -0
- package/dist/matchers/escape.js +32 -0
- package/dist/matchers/exact.d.ts +4 -0
- package/dist/matchers/exact.js +29 -0
- package/dist/matchers/fold.d.ts +11 -0
- package/dist/matchers/fold.js +144 -0
- package/dist/matchers/indentation.d.ts +3 -0
- package/dist/matchers/indentation.js +81 -0
- package/dist/matchers/index.d.ts +11 -0
- package/dist/matchers/index.js +18 -0
- package/dist/matchers/line-trimmed.d.ts +3 -0
- package/dist/matchers/line-trimmed.js +32 -0
- package/dist/matchers/lines.d.ts +24 -0
- package/dist/matchers/lines.js +74 -0
- package/dist/matchers/normalized.d.ts +7 -0
- package/dist/matchers/normalized.js +69 -0
- package/dist/patch/grammar.d.ts +5 -0
- package/dist/patch/grammar.js +24 -0
- package/dist/patch/index.d.ts +4 -0
- package/dist/patch/index.js +3 -0
- package/dist/patch/parse.d.ts +11 -0
- package/dist/patch/parse.js +209 -0
- package/dist/signature/contract.d.ts +8 -0
- package/dist/signature/contract.js +0 -0
- package/dist/signature/edit.d.ts +19 -0
- package/dist/signature/edit.js +158 -0
- package/dist/signature/index.d.ts +6 -0
- package/dist/signature/index.js +4 -0
- package/dist/signature/matching.d.ts +3 -0
- package/dist/signature/matching.js +25 -0
- package/dist/signature/messages.d.ts +4 -0
- package/dist/signature/messages.js +9 -0
- package/dist/signature/patch.d.ts +6 -0
- package/dist/signature/patch.js +55 -0
- package/dist/signature/schema.d.ts +19 -0
- package/dist/signature/schema.js +117 -0
- package/dist/signature/write.d.ts +9 -0
- package/dist/signature/write.js +52 -0
- package/dist/state/index.d.ts +2 -0
- package/dist/state/index.js +1 -0
- package/dist/state/invalidate.d.ts +29 -0
- package/dist/state/invalidate.js +37 -0
- package/docs/architecture.md +221 -0
- package/docs/hosts.md +95 -0
- package/docs/result-schema.md +268 -0
- package/package.json +54 -4
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
# Result schema
|
|
2
|
+
|
|
3
|
+
Every `edit`, `write`, and `apply_patch` call returns a `MutationResult`: a `MutationReport` plus `content`, the parts that the formatter made for the model.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
type MutationResult = MutationReport & { readonly content: readonly ContentPart[] };
|
|
7
|
+
|
|
8
|
+
type MutationReport = MutationOk | MutationNoChange | MutationFailure;
|
|
9
|
+
|
|
10
|
+
// Every variant has these fields.
|
|
11
|
+
interface MutationFields {
|
|
12
|
+
tool: "edit" | "write" | "apply_patch";
|
|
13
|
+
changes: readonly FileChange[];
|
|
14
|
+
unchanged: readonly string[];
|
|
15
|
+
notes: readonly Note[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface MutationOk extends MutationFields {
|
|
19
|
+
status: "ok";
|
|
20
|
+
commit: null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface MutationNoChange extends MutationFields {
|
|
24
|
+
status: "no-change";
|
|
25
|
+
commit: null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface MutationFailure extends MutationFields {
|
|
29
|
+
status: "error";
|
|
30
|
+
error: WriteError;
|
|
31
|
+
commit: CommitReport | null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ToolError<WriteErrorCode, WritePhase>: the same shape as the read and bash errors.
|
|
35
|
+
interface WriteError {
|
|
36
|
+
code: WriteErrorCode;
|
|
37
|
+
phase: WritePhase;
|
|
38
|
+
message: string;
|
|
39
|
+
data?: JsonObject;
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`MutationReport` is a discriminated union on `status`. Only the `error` variant has an `error` field, and it is never null there, so a plain `if (result.status === "error")` narrows it. `error.message` and `error.data` are copied from the error note.
|
|
44
|
+
|
|
45
|
+
`textOf(result)` from `@better-fs-tools/read` (also exported here) joins the text parts of `content` with `"\n"`. The report is plain data. Nothing in it comes from `ctx.host`.
|
|
46
|
+
|
|
47
|
+
## Statuses
|
|
48
|
+
|
|
49
|
+
| Status | When |
|
|
50
|
+
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
51
|
+
| `ok` | Every planned change is committed. `changes` lists them |
|
|
52
|
+
| `no-change` | Nothing needed writing: `write` with the same content, `edit` where every pair is already applied, or a patch that changes nothing. Not an error |
|
|
53
|
+
| `error` | The call stopped. `error.code` says why and `error.phase` says where. Nothing was written, unless `commit` says otherwise |
|
|
54
|
+
|
|
55
|
+
`unchanged` lists the display paths that a `no-change` result left as they were. It is empty for the other statuses.
|
|
56
|
+
|
|
57
|
+
`commit` is set only when an `apply_patch` commit failed after its first publish step. `changes` is empty on an error, except for a `PARTIAL_COMMIT`, where it lists the files left changed.
|
|
58
|
+
|
|
59
|
+
## `FileChange`
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
interface FileChange {
|
|
63
|
+
kind: "create" | "update" | "delete" | "move";
|
|
64
|
+
path: string; // display path; for a move, the destination
|
|
65
|
+
requestedPath: string;
|
|
66
|
+
resolvedPath: string;
|
|
67
|
+
movedFrom: string | null; // display path of a move source
|
|
68
|
+
before: FileVersion | null; // null for a create
|
|
69
|
+
after: FileVersion | null; // null for a delete
|
|
70
|
+
linesAdded: number;
|
|
71
|
+
linesRemoved: number;
|
|
72
|
+
diff: string; // unified diff with a/ and b/ headers
|
|
73
|
+
diffTruncated: boolean; // cut at limits.maxDiffLines
|
|
74
|
+
matches: readonly MatchInfo[]; // edit pairs and patch hunks
|
|
75
|
+
snippets: readonly Snippet[]; // new lines around each change
|
|
76
|
+
userModified: boolean; // an authorizer replaced the content
|
|
77
|
+
createdDirectories: readonly string[]; // resolved paths, outermost first
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
interface FileVersion {
|
|
81
|
+
contentId: string | null; // null without a digest
|
|
82
|
+
version: string | null; // the backend version; null when it gave none
|
|
83
|
+
bytes: number;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface MatchInfo {
|
|
87
|
+
index: number; // zero-based pair or hunk
|
|
88
|
+
matcher: string; // for example "exact" or "normalized"
|
|
89
|
+
fuzzy: boolean;
|
|
90
|
+
lines: readonly [number, number]; // one-based, in the file before the change
|
|
91
|
+
count: number; // more than 1 only with replaceAll
|
|
92
|
+
replaced: readonly (readonly [number, number])[]; // each replacement in the file after
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
interface Snippet {
|
|
96
|
+
startLine: number; // one-based, in the file after the change
|
|
97
|
+
lines: readonly string[];
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`matches` is empty for `write`. An already applied pair has no entry. `snippets` is empty for `write` and for a delete. The model text shows the snippets. The full diff is only in `diff`, unless the formatter has `diff: true`.
|
|
102
|
+
|
|
103
|
+
## `CommitReport`
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
interface CommitReport {
|
|
107
|
+
rolledBack: boolean; // true when every published step was undone
|
|
108
|
+
files: readonly {
|
|
109
|
+
path: string;
|
|
110
|
+
state: "unchanged" | "committed" | "restored" | "rollback-failed";
|
|
111
|
+
code?: WriteErrorCode;
|
|
112
|
+
}[];
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
`files` lists every file of the patch, in patch order. A move lists its source, then its destination. Every undo step is tried, so a published file ends `restored` or `rollback-failed`.
|
|
117
|
+
|
|
118
|
+
## Error codes
|
|
119
|
+
|
|
120
|
+
| `code` | Phase | Meaning | `data` |
|
|
121
|
+
| ----------------------- | ------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
122
|
+
| `INVALID_INPUT` | `input` | The input failed validation | `{ path }` when the input had a string path |
|
|
123
|
+
| `NOT_FOUND` | `resolve`, `stat`, `plan` | `edit` on a missing file, or a path the resolver or backend did not find | from the backend |
|
|
124
|
+
| `NOT_A_FILE` | `stat`, `load` | A directory, FIFO, socket, or device | `{ kind }` |
|
|
125
|
+
| `DANGEROUS_PATH` | any backend call | A refused namespace or deny root | from the backend |
|
|
126
|
+
| `OUTSIDE_ALLOWED_ROOTS` | any backend call | Outside every allowed root | from the backend |
|
|
127
|
+
| `PERMISSION_DENIED` | any backend call | The operating system refused access | from the backend |
|
|
128
|
+
| `DENIED` | `authorize`, or any backend call | An authorizer, or a backend rule such as a refused symlink | the authorizer's data, with its own code in `source` |
|
|
129
|
+
| `READ_ONLY` | `commit` | The backend is read-only | from the backend |
|
|
130
|
+
| `NO_SPACE` | `commit` | The backend is out of space | from the backend |
|
|
131
|
+
| `UNSUPPORTED_BACKEND` | `resolve`, `load`, `commit` | `load`: no classifier had an opinion. `resolve`: a per-call `fs` factory returned a backend with no write methods. `commit`: the backend lacks the write method the call needs, which the Cloudflare and just-bash adapters check at use | `{ detail }` from the backend |
|
|
132
|
+
| `ABORTED` | `input`, or the phase at the time | The signal fired before the commit. A signal that had fired before the call is `input` | `{ phase }` |
|
|
133
|
+
| `IO_ERROR` | any | Any other backend failure, including a method that threw | `{ detail }` |
|
|
134
|
+
| `EXTENSION_FAILED` | the phase of the host code | Host code threw or returned a malformed value | `{ extension, phase, id? }` |
|
|
135
|
+
| `LOCK_TIMEOUT` | `lock` | Another call held a path for `timeoutMs` | none |
|
|
136
|
+
| `NOT_READ` | `precondition` | No read record, or a partial one where a whole read is needed | `{ wholeFile: true }` for the second case |
|
|
137
|
+
| `STALE` | `stat`, `load`, `precondition`, `plan`, `commit` | The file changed since the read, or between the checks and the commit | `{ index }` for an edit rematch, `{ path, hunk? }` for a patch |
|
|
138
|
+
| `EXISTS` | `commit` | A create found a file | none |
|
|
139
|
+
| `TOO_LARGE` | `load`, `encode`, `input`, `commit` | A file over `maxFileBytes`, content over `maxWriteBytes`, a patch over `maxPatchFiles`, or a backend byte ceiling such as `maxBufferedBytes` | `{ limit, bytes? }`, `{ limit, operations }`, or from a backend `{ limit, size, detail?, cause? }` |
|
|
140
|
+
| `NOT_TEXT` | `load` | The file is not text, cannot be decoded, or does not encode back to the same bytes | `{ code, classifier? }` |
|
|
141
|
+
| `NO_MATCH` | `plan` | An old text was not found | `{ index, closest?, trailingNewline? }` |
|
|
142
|
+
| `AMBIGUOUS_MATCH` | `plan` | An old text was found more than once without `replaceAll` | `{ index, lines, total }` |
|
|
143
|
+
| `MATCH_REFUSED` | `plan` | A hit that the core does not trust | `{ index, matcher, reason }`. `reason` is `span`, `boundary`, `escape`, `fuzzy-replace-all`, or `too-many` |
|
|
144
|
+
| `OVERLAP` | `plan` | Two pairs match overlapping text | `{ first, second }` |
|
|
145
|
+
| `NO_CHANGE` | `plan`, `encode` | The edits leave the file as it is | none |
|
|
146
|
+
| `GUARD_REFUSED` | `guards` | A guard refused a planned change | the guard's data, with its own code in `source` |
|
|
147
|
+
| `PATCH_PARSE` | `input` | The patch text is not a valid patch | `{ line, detail }` |
|
|
148
|
+
| `PATCH_VERIFY` | `stat`, `plan` | One or more operations cannot apply. Nothing was written. `stat`: two operations on one file, or a Delete or Move on a backend without `remove()`. `plan`: the rest | `{ problems: [{ path, reason, hunk? }] }` |
|
|
149
|
+
| `PARTIAL_COMMIT` | `commit` | A patch step failed and an undo step failed too. `commit.files` has the state of each file | none |
|
|
150
|
+
|
|
151
|
+
An `apply_patch` precondition failure on several files gives one note with the first failure's code and `data.failures`, one entry for each path.
|
|
152
|
+
|
|
153
|
+
## Notes
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
{ code, severity: "info" | "warning", message, data?: JsonObject }
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
`code` is stable. The default formatter prints a note as `[<tool>:<code>] <message>`. Key your code on `code`, not on the wording. `messages` overrides change the wording only.
|
|
160
|
+
|
|
161
|
+
Every error result has exactly one warning note whose `code` is the error code in kebab case, for example `not-read` for `NOT_READ`. The error note is always first in `notes`. When an authorizer or a guard refuses with its own `note`, the note keeps its message and data, its code becomes the error code in kebab case, its severity becomes `warning`, and the host's own code moves to `data.source`. Read and bash use the same rule.
|
|
162
|
+
|
|
163
|
+
Notes on a successful call:
|
|
164
|
+
|
|
165
|
+
| `code` | Severity | From | `data` |
|
|
166
|
+
| ---------------------------------- | -------- | ---------------------------------------------------- | ------------------------------------------------------------------- |
|
|
167
|
+
| `fuzzy-match` | info | a loose match | edit: `{ index, matcher, lines }`. patch: `{ path, hunk, matcher }` |
|
|
168
|
+
| `already-applied` | info | `edit` | `{ index }` |
|
|
169
|
+
| `stale-rematched` | info | `edit`, `apply_patch` | none |
|
|
170
|
+
| `repeated-miss` | info | `edit`, with a `NO_MATCH` | `{ misses }` |
|
|
171
|
+
| `read-before-write-off` | warning | no store | none |
|
|
172
|
+
| `user-modified` | warning | an authorizer returned `content` | none |
|
|
173
|
+
| `directories-created` | info | the commit | `{ paths }` |
|
|
174
|
+
| `not-atomic` | warning | `writeCapabilities.atomic` false | none |
|
|
175
|
+
| `no-compare-and-swap` | info | `writeCapabilities.compareAndSwap` false | none |
|
|
176
|
+
| `mode-not-kept` | info | `writeCapabilities.preserveMode` false, on a replace | none |
|
|
177
|
+
| `hook-failed` | warning | a hook threw after the commit | `{ hook }` |
|
|
178
|
+
| `extension-failed` | warning | the formatter failed; the default formatter ran | `{ extension: "formatter", id? }` |
|
|
179
|
+
| `hook-rewrote` | warning | a hook returned `rewrote: true` | `{ hook }` |
|
|
180
|
+
| `executable` | info | `executableShebang()` | `{ mode }` |
|
|
181
|
+
| `verify-mismatch`, `verify-failed` | warning | `verifyWrite()` | none |
|
|
182
|
+
|
|
183
|
+
Guards and authorizers may add allow notes of their own.
|
|
184
|
+
|
|
185
|
+
## Content
|
|
186
|
+
|
|
187
|
+
The formatter makes `content` once, with `mode: "model"`. A formatter that returns a string gives one text part. `defaultWriteFormatter()` prints a header, a body, then a blank line and the note lines. An error prints the note lines only.
|
|
188
|
+
|
|
189
|
+
| Tool | Header | Body |
|
|
190
|
+
| ------------- | ----------------------------------------------------------------------------- | --------------------------------------------------------------- |
|
|
191
|
+
| `edit` | `Edited <path>: 1 replacement at line 4.` or `2 replacements at lines 3, 15.` | The snippets, with the read tool's `12\|` gutter, `...` between |
|
|
192
|
+
| `write` | `Created <path> (3 lines).` or `Updated <path> (+2 -1 lines).` | none |
|
|
193
|
+
| `apply_patch` | `Success. Updated the following files:` | One line for each file: `A`, `M`, or `D` and the path |
|
|
194
|
+
| any | `No change to <path>.` for `no-change`. `write` adds the reason | none |
|
|
195
|
+
|
|
196
|
+
`defaultWriteFormatter({ diff: true })` adds each file's diff in a fenced block. `gutter` and `noteLine` change the snippet gutter and the note line.
|
|
197
|
+
|
|
198
|
+
## The stored record
|
|
199
|
+
|
|
200
|
+
With a `state` store and a `digest`, each committed file gets a record under its resolved path:
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
{
|
|
204
|
+
schema: 2,
|
|
205
|
+
origin: "write",
|
|
206
|
+
observationId, resolvedPath, identity, version, digest,
|
|
207
|
+
contentId, viewId, observedAt, wholeFileVisible,
|
|
208
|
+
totalsExact: true,
|
|
209
|
+
request: null
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
- `version` and `identity` come from the backend's `MutatedFile`. `contentId` is the digest of the written bytes, and `viewId` equals it.
|
|
214
|
+
- `wholeFileVisible` is true after a `write` and a patch Add. An `edit` and a patch Update keep the previous value. It is false when an authorizer replaced the content, a hook rewrote the file, or an edit went ahead on a stale record.
|
|
215
|
+
- A move stores the destination and deletes the source key. A Delete deletes the key. `no-change` stores nothing.
|
|
216
|
+
- A store failure never fails the call.
|
|
217
|
+
|
|
218
|
+
## Statuses and error codes of every tool
|
|
219
|
+
|
|
220
|
+
The read, write, and bash results share one envelope: `tool`, `status`, and on `status: "error"` only, `error: { code, phase, message, data? }`. Error codes are UPPER_SNAKE. Note codes are kebab case, and each error note's code is its error code in kebab case. The tables below list every status and error code. Each tool's own schema has the details and the notes: this file for the write tools, `docs/result-schema.md` in `@better-fs-tools/read` for `read`, and `docs/result-schema.md` in `@better-fs-tools/shell` for `bash`.
|
|
221
|
+
|
|
222
|
+
| Status | `read` | `edit`, `write`, `apply_patch` | `bash` |
|
|
223
|
+
| ------------- | ------------------------------------------------- | ------------------------------ | ------------------------------------------------- |
|
|
224
|
+
| `ok` | text was read | every change is committed | exit code 0 |
|
|
225
|
+
| `media` | a converter returned media parts | no | no |
|
|
226
|
+
| `unsupported` | a classifier or converter refused; `code` is open | no | no |
|
|
227
|
+
| `no-change` | no | nothing needed writing | no |
|
|
228
|
+
| `failed` | no | no | another exit code, or a signal |
|
|
229
|
+
| `timeout` | no | no | the timeout stopped the command |
|
|
230
|
+
| `error` | the read failed | the call stopped | the call stopped, or the core stopped the command |
|
|
231
|
+
|
|
232
|
+
Each cell is the `error.phase` values of that code, or "no" when the tool never gives it. "Backend" means the phase of whichever backend call failed.
|
|
233
|
+
|
|
234
|
+
| `error.code` | `read` | `edit`, `write`, `apply_patch` | `bash` |
|
|
235
|
+
| --------------------------------------------------------- | ------------------------------------------------------------------------ | ---------------------------------------------------- | ---------------------------------------------------------- |
|
|
236
|
+
| `INVALID_INPUT` | `input` | `input` | `input` |
|
|
237
|
+
| `NOT_FOUND` | `resolve` | `resolve`, `stat`, `plan` | no |
|
|
238
|
+
| `NOT_A_FILE` | `open`, `verification` | `stat`, `load` | no |
|
|
239
|
+
| `DANGEROUS_PATH` | `open`, `verification`, `conversion` | backend | no |
|
|
240
|
+
| `OUTSIDE_ALLOWED_ROOTS` | `open`, `verification`, `conversion` | backend | no |
|
|
241
|
+
| `PERMISSION_DENIED` | `open`, `verification`, `conversion` | backend | no |
|
|
242
|
+
| `DENIED` | `authorize`, or backend | `authorize`, or backend | `authorize` |
|
|
243
|
+
| `REFUSED` | no | no | `beforeRun` |
|
|
244
|
+
| `TOO_LARGE` | `open` (a backend ceiling; converter and media limits are `unsupported`) | `input`, `load`, `encode`, `commit` | no |
|
|
245
|
+
| `CHANGED_DURING_READ` | `verification` | no | no |
|
|
246
|
+
| `READ_ONLY` | no | `commit` | no |
|
|
247
|
+
| `NO_SPACE` | no | `commit` | no |
|
|
248
|
+
| `UNSUPPORTED_BACKEND` | `open`, `sampling`, `scan` | `resolve`, `load`, `commit` | no |
|
|
249
|
+
| `ABORTED` | `input`, or the phase at the time | `input`, or the phase at the time, before the commit | `input`, `resolve`, `beforeRun`, `authorize`, `env`, `run` |
|
|
250
|
+
| `IO_ERROR` | any | any | no |
|
|
251
|
+
| `EXTENSION_FAILED` | the phase of the host code | the phase of the host code | the phase of the host code |
|
|
252
|
+
| `LOCK_TIMEOUT` | no | `lock` | no |
|
|
253
|
+
| `NOT_READ` | no | `precondition` | no |
|
|
254
|
+
| `STALE` | no | `stat`, `load`, `precondition`, `plan`, `commit` | no |
|
|
255
|
+
| `EXISTS` | no | `commit` | no |
|
|
256
|
+
| `NOT_TEXT` | no | `load` | no |
|
|
257
|
+
| `NO_MATCH`, `AMBIGUOUS_MATCH`, `MATCH_REFUSED`, `OVERLAP` | no | `plan`, `edit` only | no |
|
|
258
|
+
| `NO_CHANGE` | no | `plan`, `encode`, `edit` only | no |
|
|
259
|
+
| `GUARD_REFUSED` | no | `guards` | no |
|
|
260
|
+
| `PATCH_PARSE` | no | `input`, `apply_patch` only | no |
|
|
261
|
+
| `PATCH_VERIFY` | no | `stat`, `plan`, `apply_patch` only | no |
|
|
262
|
+
| `PARTIAL_COMMIT` | no | `commit`, `apply_patch` only | no |
|
|
263
|
+
| `CWD_NOT_FOUND` | no | no | `resolve`, `run` |
|
|
264
|
+
| `CWD_NOT_A_DIRECTORY` | no | no | `run` |
|
|
265
|
+
| `SPAWN_FAILED` | no | no | `run` |
|
|
266
|
+
| `OUTPUT_CAP` | no | no | `run` |
|
|
267
|
+
|
|
268
|
+
A formatter failure is never an error in any tool. The status stays, and an `extension-failed` warning is added.
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-fs-tools/write",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Edit, write, and apply_patch tools for TypeScript agents.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/gingerhendrix/better-fs-tools.git",
|
|
9
|
+
"directory": "packages/write"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"docs"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./patch": {
|
|
23
|
+
"types": "./dist/patch/index.d.ts",
|
|
24
|
+
"import": "./dist/patch/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./signature": {
|
|
27
|
+
"types": "./dist/signature/index.d.ts",
|
|
28
|
+
"import": "./dist/signature/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"import": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./patch": {
|
|
38
|
+
"types": "./dist/patch/index.d.ts",
|
|
39
|
+
"import": "./dist/patch/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./signature": {
|
|
42
|
+
"types": "./dist/signature/index.d.ts",
|
|
43
|
+
"import": "./dist/signature/index.js"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@better-fs-tools/fs": "^0.1.0",
|
|
50
|
+
"@better-fs-tools/read": "^0.1.0",
|
|
51
|
+
"@better-fs-tools/shell": "^0.1.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"typebox": "^1.3.16"
|
|
55
|
+
}
|
|
56
|
+
}
|