opencode-fs-plugin 1.6.0 → 1.6.2
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 +5 -0
- package/SPEC.md +2 -1
- package/package.json +1 -1
- package/skills/filesystem/SKILL.md +103 -59
package/README.md
CHANGED
|
@@ -117,6 +117,11 @@ large downloads prefer `fs.http_request({ output })`, which streams to disk.
|
|
|
117
117
|
|
|
118
118
|
There is no shell, redirection operator, nested pipe, or `find -exec`.
|
|
119
119
|
|
|
120
|
+
`fs.pipe` is sequential by design and is not a batch primitive. For independent
|
|
121
|
+
work, fan out with `Promise.all` over `tools.fs.*` (or one multi-path call).
|
|
122
|
+
`fs` domain errors resolve as `ERROR:`/`BLOCKED:` text, so check each result;
|
|
123
|
+
permission denials throw.
|
|
124
|
+
|
|
120
125
|
## Performance and concurrency
|
|
121
126
|
|
|
122
127
|
All I/O is asynchronous; the plugin never calls a synchronous `fs` API.
|
package/SPEC.md
CHANGED
|
@@ -117,7 +117,8 @@ These are not implemented:
|
|
|
117
117
|
- `sort -k` accepts field/character ranges with modifiers `bdfghiMnrV`.
|
|
118
118
|
- `tar`/`zip` extraction rejects path traversal and escaping links.
|
|
119
119
|
- `pipe` passes raw bytes and only accepts registered pipeable stages; `tar` and
|
|
120
|
-
`zip` are sink stages.
|
|
120
|
+
`zip` are sink stages. It is sequential and not a batch primitive: independent
|
|
121
|
+
calls fan out with `Promise.all` in `execute`.
|
|
121
122
|
|
|
122
123
|
## Coverage policy
|
|
123
124
|
|
package/package.json
CHANGED
|
@@ -25,7 +25,8 @@ With `execute` allowed, call it as `tools.fs.<command>`; agents without
|
|
|
25
25
|
| Regex substitution or in-place edit | `fs.sed` |
|
|
26
26
|
| Recoverable deletion | `fs.trash` |
|
|
27
27
|
| HTTP(S) fetch, API call, or file download | `fs.http_request` |
|
|
28
|
-
|
|
|
28
|
+
| Many independent fs calls | one multi-path call, else `Promise.all` in `execute` |
|
|
29
|
+
| Sequential byte pipeline | `fs.pipe` |
|
|
29
30
|
|
|
30
31
|
Do not duplicate a built-in when it already covers the job. `fs` exists for the
|
|
31
32
|
operations the built-ins do not cover, and for composable text/archive work.
|
|
@@ -112,10 +113,59 @@ host drops unknown fields, so a name typo runs with defaults.
|
|
|
112
113
|
- `fs.mktemp` needs a template ending in at least three `X`; use `suffix` for an
|
|
113
114
|
extension.
|
|
114
115
|
|
|
116
|
+
## Batch independent calls
|
|
117
|
+
|
|
118
|
+
`execute` is a JS runtime. Do not `await` independent fs calls one at a time.
|
|
119
|
+
|
|
120
|
+
1. **Use the widest native call first.** `cat`, `stat`, `hash`, `ls`, `grep`,
|
|
121
|
+
`tee`, `wc`, `chmod`, `touch`, `rm`, and `trash` take `paths` arrays. Use one
|
|
122
|
+
call when combined output is enough:
|
|
123
|
+
|
|
124
|
+
```js
|
|
125
|
+
const stats = await tools.fs.stat({ paths: files, format: "%n %s" })
|
|
126
|
+
const sums = await tools.fs.hash({ files })
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
2. **Fan out when you need per-item results.** `Promise.all` preserves input
|
|
130
|
+
order:
|
|
131
|
+
|
|
132
|
+
```js
|
|
133
|
+
const rows = await Promise.all(files.map(async (f) => {
|
|
134
|
+
const text = String(await tools.fs.cat({ paths: [f] }))
|
|
135
|
+
return { f, text, ok: !/^(ERROR|BLOCKED):/.test(text) }
|
|
136
|
+
}))
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`fs` domain errors resolve as `ERROR:`/`BLOCKED:` text; they do not reject.
|
|
140
|
+
Permission denials and host validation throw, so use `Promise.allSettled`
|
|
141
|
+
only when those should not cancel the batch.
|
|
142
|
+
|
|
143
|
+
3. **Bound very large fan-outs.** One tool call per item is expensive; use a
|
|
144
|
+
small worker pool (for example 8) instead of `Promise.all` over thousands:
|
|
145
|
+
|
|
146
|
+
```js
|
|
147
|
+
async function mapLimit(items, limit, fn) {
|
|
148
|
+
const out = new Array(items.length)
|
|
149
|
+
let next = 0
|
|
150
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
151
|
+
while (next < items.length) {
|
|
152
|
+
const i = next++
|
|
153
|
+
out[i] = await fn(items[i], i)
|
|
154
|
+
}
|
|
155
|
+
}))
|
|
156
|
+
return out
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Keep `for (const x of items) { await ... }` only when each step depends on the
|
|
161
|
+
previous result, such as read → transform → write the same file. Use `fs.pipe`
|
|
162
|
+
for a sequential byte chain; use this section for independent work.
|
|
163
|
+
|
|
115
164
|
## Pipe
|
|
116
165
|
|
|
117
|
-
|
|
118
|
-
|
|
166
|
+
`fs.pipe` runs fs tools as a **sequential byte pipeline**: each stage's stdout
|
|
167
|
+
is the next stage's stdin. Use it for filter chains; use the batching pattern
|
|
168
|
+
above for parallel fan-out.
|
|
119
169
|
|
|
120
170
|
```js
|
|
121
171
|
await tools.fs.pipe({
|
|
@@ -128,17 +178,30 @@ await tools.fs.pipe({
|
|
|
128
178
|
})
|
|
129
179
|
```
|
|
130
180
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
`input`
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
181
|
+
| Field | Meaning |
|
|
182
|
+
|---|---|
|
|
183
|
+
| `stages` | 1–50 `{ tool, args }` entries; names are short (`cat`, not `fs.cat`) |
|
|
184
|
+
| `input` | Initial stdin text when the first stage is a filter |
|
|
185
|
+
| `output` | Write final stdout to a file (final `tee`) |
|
|
186
|
+
| `append` | Append to `output` instead of overwriting |
|
|
187
|
+
|
|
188
|
+
The first stage must be a source (`cat`, `http_request`, `dd`, or a path-reading
|
|
189
|
+
text tool such as `tac`, `rev`, `nl`, `base64`, `od`, `strings`) or receive
|
|
190
|
+
`input`. A filter first (`grep`, `sort`, `head`, `wc`) emits
|
|
191
|
+
`ERROR: no input files and no stdin` as pipeline data. Archive writers (`tar`,
|
|
192
|
+
`zip`, `cpio`) emit nothing downstream, so put them last. `wc` and `hash` also
|
|
193
|
+
emit their result text, so they can end a chain or feed a later stage.
|
|
194
|
+
|
|
195
|
+
Stages exchange whole buffers. Set `maxBytes` on `http_request`; for large
|
|
196
|
+
downloads prefer `fs.http_request({ output })`, which streams to disk. In-memory
|
|
197
|
+
text is allowed:
|
|
139
198
|
|
|
140
|
-
|
|
141
|
-
|
|
199
|
+
```js
|
|
200
|
+
await tools.fs.pipe({
|
|
201
|
+
input: "b\na\nb\n",
|
|
202
|
+
stages: [{ tool: "sort", args: { unique: true } }],
|
|
203
|
+
})
|
|
204
|
+
```
|
|
142
205
|
|
|
143
206
|
```js
|
|
144
207
|
await tools.fs.pipe({
|
|
@@ -149,6 +212,23 @@ await tools.fs.pipe({
|
|
|
149
212
|
})
|
|
150
213
|
```
|
|
151
214
|
|
|
215
|
+
`output` and `append` assert `fs_tee` on the destination. The result metadata
|
|
216
|
+
lists each stage's `bytesIn`, `bytesOut`, and `exitCode`; use it as the
|
|
217
|
+
verification trail.
|
|
218
|
+
|
|
219
|
+
Common pipe mistakes:
|
|
220
|
+
|
|
221
|
+
- `commands` is not a field; the field is `stages`.
|
|
222
|
+
- A bare `{ tool: "sort", args: {} }` first stage returns
|
|
223
|
+
`ERROR: no input files and no stdin`; add a source stage or `input`.
|
|
224
|
+
- Stage names are `cat`, not `fs.cat`.
|
|
225
|
+
- There is no shell, redirection operator, nested pipe, `find -exec`, or
|
|
226
|
+
`xargs`.
|
|
227
|
+
|
|
228
|
+
Pipeable filters include `head`, `tail`, `grep`, `sed`, `sort`, `uniq`, `cut`,
|
|
229
|
+
`tr`, `tee`, `gzip`, `gunzip`, `tac`, `rev`, `nl`, `paste`, `shuf`, `fold`,
|
|
230
|
+
`base64`, `od`, and `strings`. Unknown stage names fail with `unsupported`.
|
|
231
|
+
|
|
152
232
|
## Background jobs
|
|
153
233
|
|
|
154
234
|
Every tool accepts `background: true`. It returns immediately with a job id and
|
|
@@ -197,59 +277,23 @@ const status = JSON.parse(await tools.fs.job({ id: job.jobId }))
|
|
|
197
277
|
A job that produces no text returns empty content from `fs.job wait`; verify the
|
|
198
278
|
effect with `fs.stat`, `fs.ls`, or `fs.diff`, and use `fs.job({ id })` for state.
|
|
199
279
|
|
|
200
|
-
##
|
|
201
|
-
|
|
202
|
-
`execute` is always available and is the orchestration layer for every `fs` tool.
|
|
203
|
-
Use ordinary JavaScript for iteration, conditionals, retries, and parallel calls.
|
|
204
|
-
Do not use a shell or `toolbox.run` for batching.
|
|
205
|
-
|
|
206
|
-
Sequential is the safe default for writes, destructive work, ordering, and
|
|
207
|
-
permission prompts:
|
|
208
|
-
|
|
209
|
-
```js
|
|
210
|
-
const files = (
|
|
211
|
-
await tools.fs.find({
|
|
212
|
-
paths: ["src"],
|
|
213
|
-
name: "*.sh",
|
|
214
|
-
type: "f",
|
|
215
|
-
print0: true,
|
|
216
|
-
})
|
|
217
|
-
).split("\0").filter(Boolean)
|
|
218
|
-
|
|
219
|
-
for (const file of files) {
|
|
220
|
-
await tools.fs.chmod({ paths: [file], mode: "640" })
|
|
221
|
-
}
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
Use `Promise.all` only for independent work. It rejects on the first failure
|
|
225
|
-
while the other calls continue, so prefer `Promise.allSettled` when partial
|
|
226
|
-
results are useful. Bound concurrency to about 4–8:
|
|
227
|
-
|
|
228
|
-
```js
|
|
229
|
-
async function mapLimit(items, limit, fn) {
|
|
230
|
-
const results = []
|
|
231
|
-
for (let i = 0; i < items.length; i += limit) {
|
|
232
|
-
results.push(...(await Promise.all(items.slice(i, i + limit).map(fn))))
|
|
233
|
-
}
|
|
234
|
-
return results
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
const stats = await mapLimit(files, 4, (file) =>
|
|
238
|
-
tools.fs.stat({ paths: [file], format: "%n %s" }),
|
|
239
|
-
)
|
|
240
|
-
```
|
|
280
|
+
## Orchestration notes
|
|
241
281
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
282
|
+
`execute` is the orchestration layer for every `fs` tool. Each batched call still
|
|
283
|
+
asserts its own `fs_<tool>` and `external_directory` permission, so fan-out does
|
|
284
|
+
not bypass permissions. Code Mode has no timers: use `wait_for` for time-based
|
|
285
|
+
waits and `background: true` for long jobs. Writes and destructive operations
|
|
286
|
+
may fan out too when their targets are independent; keep ordering only when a
|
|
287
|
+
later step depends on an earlier result.
|
|
245
288
|
|
|
246
289
|
## Performance
|
|
247
290
|
|
|
248
291
|
All `fs` I/O is asynchronous. Independent work is parallelized automatically
|
|
249
292
|
within each call, up to `os.availableParallelism()`: tree copies, hashing,
|
|
250
293
|
gzip/gunzip, grep reads, `find`/`du`/`grep -r`/`chmod -R`/`chown -R` traversal,
|
|
251
|
-
`diff -r`, `ls` formatting, `ps` /proc scans, and `split` writes. Do not
|
|
252
|
-
|
|
294
|
+
`diff -r`, `ls` formatting, `ps` /proc scans, and `split` writes. Do not
|
|
295
|
+
re-implement that internal concurrency; fan out separate tool calls only as
|
|
296
|
+
described in Batch independent calls.
|
|
253
297
|
|
|
254
298
|
The limit comes from the plugin `concurrency` option or
|
|
255
299
|
`OPENCODE_FS_CONCURRENCY`. CPU-bound `sort`, `sed`, and text diffing stay
|