opencode-fs-plugin 3.5.0 → 3.6.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 CHANGED
@@ -126,7 +126,10 @@ await tools.fs.pipe({
126
126
  ```
127
127
 
128
128
  Pipe stages exchange whole buffers, so use `maxBytes` for large responses. For
129
- large downloads prefer `fs.curl({ output })`, which streams to disk.
129
+ large downloads prefer `fs.curl({ output })`, which streams to disk. A stage
130
+ that yields no stdout becomes an empty buffer, so `output` writes an empty file
131
+ instead of skipping it. The signal is checked before each stage and before the
132
+ final write, so an abort stops the chain without creating the output.
130
133
 
131
134
  There is no shell, redirection operator, nested pipe, or arbitrary `find -exec`.
132
135
 
@@ -159,9 +162,11 @@ when you want a closed set.
159
162
  The workspace (project) is read/write/exec. **Network egress needs Linux tier
160
163
  T1** (user namespaces and TPROXY). Every run gets procage's transparent relay:
161
164
  there is no direct route, and every TCP or UDP flow is named to the plugin as a
162
- DNS QNAME, TLS SNI, HTTP `Host`, QUIC SNI, or an IP literal. That exact resource
163
- must be approved through `fs_exec_network`; the port, URL, headers, and payload
164
- are never part of the permission. There is no separate network allowlist option:
165
+ DNS QNAME, TLS SNI, HTTP `Host`, QUIC SNI, or an IP literal. Bare IPv6 literals
166
+ and bracketed IPv6 `Host` forms with an optional port are accepted as
167
+ resources. That exact resource must be approved through `fs_exec_network`; the
168
+ port, URL, headers, and payload are never part of the permission. There is no
169
+ separate network allowlist option:
165
170
 
166
171
  ```jsonc
167
172
  {
@@ -327,11 +332,30 @@ await tools.wait.for({
327
332
 
328
333
  Jobs are process-local: they are lost on an OpenCode server restart, and their
329
334
  status files may remain under `/tmp/opencode/fs-jobs/<server-pid>/`; set the
330
- plugin option `jobDir` to move them. The manager allows 8 concurrent jobs and
331
- cleans up finished jobs after one hour. Results stay in memory and are returned
332
- by `fs.job`; the status file contains only the job state and metadata.
333
- Background permission prompts can appear after the starting call returns, and a
334
- denied permission fails the job.
335
+ plugin option `jobDir` to move them. The limits are global to one plugin
336
+ instance (one OpenCode server), not per session: at most 8 jobs run at once and
337
+ up to 64 are retained. Starting another evicts the oldest finished job and
338
+ deletes its status file; if no finished job is available to evict the start
339
+ fails with `busy`. Finished jobs are also cleaned up after one hour.
340
+
341
+ Each job is visible only to the session that started it: `fs.job` list, status,
342
+ wait, and cancel treat another session's id as not found. A background start or
343
+ `fs.job` call without a non-empty host session id fails with `invalid`. The
344
+ `jobDir` path is validated component by component: an existing symlink, a
345
+ non-directory component, or the filesystem root is refused, missing components
346
+ are created `0700`, and the final directory is `0700`. This is deliberately
347
+ fail-closed: a benign configured path that traverses a host symlink such as
348
+ `/home` is rejected, while the default `/tmp/opencode/fs-jobs/<pid>` path is
349
+ unaffected. A component swapped after validation remains a residual TOCTOU
350
+ race. Status files are `0600` and hold only id, tool, state, timing, and
351
+ `hasResult`; they omit the result, the raw error, and the absolute status path.
352
+ Results stay in memory and are returned by
353
+ `fs.job`, capped at 1 MiB per result. Longer text is truncated with
354
+ a `[truncated]` marker plus `truncated`/`originalBytes` metadata,
355
+ and an oversized base64/binary result becomes empty content. With 64 retained
356
+ results this can hold roughly 64 MiB of result text in the server process until
357
+ eviction. Background permission prompts can appear after the starting call
358
+ returns, and a denied permission fails the job.
335
359
 
336
360
  ## Installing from npm
337
361
 
@@ -463,7 +487,8 @@ The skill ID is `filesystem`; `@filesystem` loads it explicitly.
463
487
  Every tool asserts an action named after the tool (`fs_cp`, `fs_rm`,
464
488
  `fs_pipe` stages, and so on), except `fs.curl`, which reuses the
465
489
  built-in `webfetch` action. Internal paths use project-relative resources;
466
- external targets first require `external_directory` on the absolute boundary.
490
+ external targets first require `external_directory` on the absolute boundary,
491
+ computed from the canonical target rather than the symlink path.
467
492
  `allow always` saves the exact resources the call asserted — project-relative
468
493
  paths, absolute external boundaries, or network names/addresses. A specific
469
494
  resource saves narrowly; an explicitly requested `*` remains `*`.
@@ -533,18 +558,77 @@ when only some agents should be shell-free.
533
558
 
534
559
  - The sandbox root, its ancestors, `/`, `$HOME` and core system directories are
535
560
  hard stops for destructive operations.
536
- - Paths are resolved with symlink awareness. Traversing a link that escapes the
537
- project requires `external_directory`; removing or renaming the link itself is
538
- internal.
539
- - Archive extraction rejects absolute paths, `..`, and escaping symlinks.
540
- - `curl` accepts only `http:` and `https:`, keeps TLS verification on,
541
- re-checks permissions on redirect hops, and writes downloads to a temporary
542
- file before renaming. Localhost and private addresses are not blocked by
543
- default.
561
+ - Paths resolve to their canonical target before a permission is asserted, so a
562
+ symlink that escapes the project asks `external_directory` for the real
563
+ location; removing or renaming the link itself stays internal. Single-file
564
+ output tools (archives, `gzip`, `tee`, `split`, `dd`, `pipe`) open the resolved
565
+ final component with `O_NOFOLLOW`, so a link swapped in after the check fails
566
+ instead of being followed; `cp` refuses an existing symlink at a nested entry
567
+ but its final copy call is not no-follow. Node has no `openat`, so a
568
+ concurrently swapped parent directory remains a TOCTOU gap.
569
+ - `cp` follows a top-level destination symlink to its canonical target and gates
570
+ that path. Inside a recursive copy it refuses to write through an existing
571
+ symlink (directory or file) and fails closed; a copied symlink replaces the
572
+ destination link itself. A source/destination hard-link alias is rejected.
573
+ - `mv` refuses to move a directory into itself. A cross-device move (EXDEV)
574
+ refuses a destination symlink, copies with `preserve`, and removes the source
575
+ only after every entry was copied. If nothing was copied or a
576
+ `noClobber`/`update` entry was skipped, it reports `cross-device` and preserves
577
+ the source; the partially populated destination is left in place.
578
+ - `chown` refuses the sandbox root, its ancestors, `/`, `$HOME`, and core system
579
+ directories before asserting permission or changing ownership; recursive chown
580
+ skips traversal symlinks. With `noDereference` it resolves the parent chain to
581
+ its canonical directory but leaves the final component, so a parent symlink is
582
+ gated at its real location and `lchown` changes a final symlink itself.
583
+ - Archive create writes its output through the same no-follow final open.
584
+ Extraction first plans every member: destinations are resolved in their
585
+ canonical parents, an existing final symlink is refused, and one bulk
586
+ permission check covers all targets before anything is written, so a denial
587
+ writes no archive members. A symlink member is refused over any existing
588
+ destination, and absolute names, `..`, and absolute or traversing link targets
589
+ are rejected. Extracted file modes apply the process umask and strip
590
+ setuid/setgid; directory modes also preserve the sticky bit. ZIP entries with
591
+ no Unix mode default to `0644` files and `0755` directories before the umask.
592
+ Directory modes are deduplicated by canonical target (last entry wins) and
593
+ applied deepest-first. Ordinary file and directory mode changes use opened
594
+ `O_NOFOLLOW` handles; an `EACCES` fallback for an unreadable existing
595
+ directory uses a guarded pathname `chmod`, keeping a final-component TOCTOU
596
+ race. Parent-component races remain. An abort before an archive create write
597
+ leaves no archive file. A parent directory swapped after planning can still redirect a
598
+ write, an existing destination hardlink can be written through, and an OS
599
+ error or abort can leave earlier members or a truncated file. Archive create
600
+ and extraction buffer the whole archive (extraction also buffers each member)
601
+ in memory and have no global archive-size cap, so large archives can consume
602
+ substantial memory.
603
+ - `tar` and `cpio` create resolve relative `paths` under `directory`; absolute
604
+ sources are named relative to `directory` first, then the project, and fall
605
+ back to the basename (a traversing source uses its basename). `tar`/`zip` store
606
+ files, directories, and symlinks (no hardlinks, devices, ACLs, or xattrs);
607
+ `cpio` is newc with GNU 4-byte padding, and its decoder also accepts the prior
608
+ 3.x plugin padding; strict decode rejects nonzero data after the trailer
609
+ (concatenated archives). `cpio` fields must fit 0..0xffffffff; `ar` uses 16-byte
610
+ GNU short names.
611
+ - `split` checks suffix capacity before writing: alphabetic suffixes cover
612
+ `26^suffixLength` chunks and `numeric` covers `10^suffixLength`; more chunks
613
+ fail with `invalid`.
614
+ - `curl` accepts only `http:` and `https:`, keeps TLS verification on, and
615
+ re-checks permissions on every redirect hop. A same-origin redirect keeps the
616
+ request. A cross-origin redirect is refused unless it is a bodyless `GET` or
617
+ `HEAD` whose caller headers are all in the safe set (`accept`,
618
+ `accept-language`, `cache-control`, `pragma`, `range`, `user-agent`);
619
+ credentials, custom headers, other methods, a request body, and embedded URL
620
+ credentials are refused, not stripped. A 303 rewrites `POST` to a bodyless
621
+ `GET` before that policy, so a safe resulting GET may cross origins; 301/302
622
+ rewrite `POST` after the policy, and 307/308 keep the method and body. An
623
+ HTTPS to HTTP redirect is always refused. For `output`, the resolved file's
624
+ containing directory is the permission boundary, so an external destination
625
+ asks `external_directory` for that directory. Downloads stream to a temporary
626
+ file and are renamed only after the body and checksum complete. Localhost and
627
+ private addresses are not blocked by default.
544
628
  - `rm` is permanent. `trash` uses the XDG home trash and refuses cross-device
545
629
  moves instead of silently copying.
546
- - The sandbox is a guardrail, not a kernel security boundary. Symlink races
547
- remain possible.
630
+ - The sandbox is a guardrail, not a kernel security boundary.
631
+ Parent/hardlink races and partial writes remain possible.
548
632
 
549
633
  ## Development
550
634
 
package/SPEC.md CHANGED
@@ -31,12 +31,58 @@ Aliases are accepted only where noted: `path` for one `paths` element (`stat`,
31
31
 
32
32
  - Every tool accepts `background: true`; it returns a job id and an atomic
33
33
  status-file path instead of waiting.
34
- - `fs.job` exposes `status`, `wait`, `cancel`, and `list`.
34
+ - `fs.job` exposes `status`, `wait`, `cancel`, and `list`. Access is scoped to
35
+ the originating session; another session's id is reported as `not-found`.
35
36
  - Jobs are process-local and are lost on server restart. Status files live under
36
37
  `/tmp/opencode/fs-jobs/<server-pid>/`; finished jobs are cleaned after one hour.
37
- - At most eight jobs run concurrently. Excess starts fail with `busy`.
38
- - Results stay in memory and are returned by `fs.job`; status files contain only
39
- state and metadata. Permission checks still apply to background work.
38
+ - The caps are global to one plugin instance (one server), not per session. At
39
+ most eight jobs run concurrently. Excess starts fail with `busy`.
40
+ - Up to 64 jobs are retained: admitting a new job evicts the oldest finished one
41
+ and deletes its status file; if no finished job is available to evict, the
42
+ start fails with `busy`.
43
+ - A background start or `fs.job` call requires a non-empty host session id and
44
+ fails with `invalid` otherwise.
45
+ - The `jobDir` path is validated component by component: an existing symlink, a
46
+ non-directory component, or the filesystem root is refused; missing components
47
+ are created `0700` and the final directory is `0700`. This is deliberately
48
+ fail-closed: a benign path through a host symlink such as `/home` is rejected,
49
+ while the default `/tmp/opencode/fs-jobs/<pid>` path is unaffected. A
50
+ component swapped after validation remains a TOCTOU gap. Each status file is
51
+ `0600` and holds only id, tool, state, timing, and `hasResult`; it omits the
52
+ result, the raw error, and the absolute status path.
53
+ - Results stay in memory and are returned by `fs.job`, capped at 1 MiB each.
54
+ Longer text is truncated with `[truncated]` and
55
+ `truncated`/`originalBytes` metadata; an oversized base64/binary result
56
+ becomes empty content. Retaining 64 such results can hold roughly 64 MiB in
57
+ the server process until eviction. Permission checks still apply to
58
+ background work.
59
+
60
+ ## Paths and links
61
+
62
+ - A path is resolved to its canonical target before the permission resource is
63
+ derived, so a link that leaves the project asserts its real boundary.
64
+ Single-file output tools open the resolved final component with `O_NOFOLLOW`;
65
+ a link swapped in after resolution fails with a stable error instead of being
66
+ followed. `cp` rejects an existing symlink at a nested entry but its final copy
67
+ call is not no-follow.
68
+ - Node has no `openat`, so a parent directory swapped between resolution and the
69
+ syscall remains a TOCTOU gap. The sandbox is a guardrail, not a kernel
70
+ boundary.
71
+ - `cp` follows a top-level destination symlink and gates its canonical target.
72
+ A recursive copy refuses to write through an existing symlink at any entry
73
+ (directory or file) and fails closed; an archived symlink replaces the
74
+ destination link itself. Hard-link aliases of the source are rejected.
75
+ - `mv` falls back to copy-then-remove on EXDEV and first refuses a directory
76
+ destination under the source. The fallback refuses a destination symlink and
77
+ copies with `preserve`; the source is removed only after every entry was
78
+ copied. No copied entry or a skipped `noClobber`/`update` destination raises
79
+ `cross-device` and keeps the source, leaving a partial destination in place.
80
+ - `chown` refuses the sandbox root, its ancestors, `/`, `$HOME`, and core system
81
+ directories before asserting permission or changing ownership. Recursive chown
82
+ skips traversal symlinks. With `noDereference`, the parent chain resolves to
83
+ its canonical directory while the final component is left as a link, so a
84
+ parent symlink is gated at its real location and `lchown` changes a final
85
+ symlink itself.
40
86
 
41
87
  ## Batch 1 tools
42
88
 
@@ -53,15 +99,23 @@ Aliases are accepted only where noted: `path` for one `paths` element (`stat`,
53
99
  `findmnt` parses `/proc/self/mountinfo`.
54
100
  - `tac`, `rev`, `nl`, `paste`, `comm`, `split`, `shuf`, and `fold` cover text
55
101
  primitives that `pipe` could not express. `comm` expects sorted input.
102
+ `split` takes 1-16 suffix characters; the chunk count must fit `26^n` with
103
+ alphabetic suffixes or `10^n` with `numeric`, checked before any chunk file is
104
+ written.
56
105
  - `chown` uses `fs.chown`/`fs.lchown`, accepts names or ids, and walks
57
- recursively with the shared concurrency limit.
106
+ recursively with the shared concurrency limit. `noDereference` uses `lchown`
107
+ on the resolved parent plus the final component, so parent symlinks are
108
+ canonicalized and a final symlink itself is changed.
58
109
  - `sync` calls `fsync` per path; Node has no global sync syscall.
59
110
  - `dd` supports `bs`, `count`, `skip`, `seek`, and `status`; it does not
60
111
  implement conversions or `iflag`/`oflag`.
61
- - `cpio` reads and writes newc archives; `ar` uses GNU short names (max 16 bytes).
62
- Both reject traversal and unsafe member names. Like `tar`, create resolves
63
- `paths` against the project; pass absolute sources plus `directory` for
64
- relative member names.
112
+ - `cpio` reads and writes newc archives; the writer uses GNU 4-byte padding and
113
+ the decoder also accepts the prior 3.x plugin padding. Strict decode rejects
114
+ nonzero trailing data and concatenated archives. `ar` uses GNU short names
115
+ (max 16 bytes). Both reject traversal and unsafe member names. Create resolves
116
+ archive-output writes through a no-follow final open; extraction plans and
117
+ gates every member before writing. `cpio` writes 8-hex-digit fields and rejects
118
+ values outside `0..0xffffffff`.
65
119
 
66
120
  ## HTTP requests
67
121
 
@@ -70,10 +124,19 @@ Aliases are accepted only where noted: `path` for one `paths` element (`stat`,
70
124
  - Requests are allowed by default. `fs.curl` asserts the built-in
71
125
  `webfetch` action with the requested URL as the resource; there is no separate
72
126
  `fs_curl` action. Every redirect hop re-asserts it for the new URL.
73
- - Redirects are followed manually: 301/302 rewrite `POST` to `GET`, 303 always
74
- does, and the hop count is bounded by `maxRedirects`.
75
- - `output` streams the response to a temporary file in the target directory and
76
- renames it only after the body and checksum are complete.
127
+ - Redirects are followed manually. 303 rewrites `POST` to a bodyless `GET`
128
+ before the cross-origin policy; 301/302 rewrite `POST` to `GET` after the
129
+ policy; 307/308 keep the method and body. The hop count is bounded by
130
+ `maxRedirects`.
131
+ - A same-origin redirect keeps the request unchanged. A cross-origin redirect is
132
+ refused unless it is a bodyless `GET`/`HEAD` and every caller header is in
133
+ `accept`, `accept-language`, `cache-control`, `pragma`, `range`, or
134
+ `user-agent`. Credentials, custom headers, other methods, a request body, and
135
+ embedded URL credentials are refused rather than stripped. An HTTPS to HTTP
136
+ redirect is always refused before the next request is sent.
137
+ - `output` streams the response to a temporary file in the target's containing
138
+ directory, which is also the `external_directory` boundary, and renames it only
139
+ after the body and checksum are complete.
77
140
  - `checksum` accepts `<md5|sha1|sha256|sha512>:<hex>`; a bare digest means
78
141
  SHA-256. Mismatches fail with `checksum` and leave no partial file.
79
142
  - `maxBytes` is enforced while reading, for buffered and downloaded bodies.
@@ -94,9 +157,11 @@ Aliases are accepted only where noted: `path` for one `paths` element (`stat`,
94
157
  validates HELLO against the run id, and multiplexes at most 64 decisions over
95
158
  the length-prefixed protocol in `src/core/relay-protocol.ts`.
96
159
  - Every TCP/UDP flow is named as a DNS QNAME, TLS SNI, HTTP `Host`, QUIC SNI, or
97
- IP literal. That exact resource is asserted with `fs_exec_network`; the port,
98
- protocol, URL, headers, and payload never reach the permission. The permission
99
- rules are the only network allowlist; there is no plugin option for it.
160
+ IP literal. Bare IPv6 literals and bracketed IPv6 `Host` forms with an
161
+ optional port pass resource validation. That exact resource is asserted with
162
+ `fs_exec_network`; the port, protocol, URL, headers, and payload never reach
163
+ the permission. The permission rules are the only network allowlist; there is
164
+ no plugin option for it.
100
165
  - DNS queries are decisions too. An allowed QNAME is forwarded to the parent
101
166
  resolver; procage's discovery reads `/etc/resolv.conf` and systemd-resolved
102
167
  paths, including a loopback stub, and the plugin leaves `relay_dns_upstream`
@@ -165,6 +230,7 @@ These are not implemented:
165
230
  delete/trash only
166
231
  - `chgrp`, `chattr`, `rsync`
167
232
  - ACL and xattr preservation in `cp -a`
233
+ - archive hard links, device nodes, and ACL/xattr metadata
168
234
  - remaining GNU edge-flag parity for `ls`, `stat`, `sort`, `find`
169
235
  - symlink-race-proof sandboxing
170
236
  - unbounded `tail -f`; use bounded `follow` or the wait plugin
@@ -197,11 +263,39 @@ These are not implemented:
197
263
  - `find action: "delete"|"trash"` reuses the `fs_rm`/`fs_trash` gates, removes
198
264
  deepest matches first, and never removes the starting directory itself.
199
265
  - `sort -k` accepts field/character ranges with modifiers `bdfghiMnrV`.
200
- - `tar`/`zip` extraction rejects path traversal and escaping links.
266
+ - Archive create writes the output through its resolved target with a no-follow
267
+ final open; an abort before the write leaves no archive file.
268
+ - `tar` and `cpio` create resolve relative `paths` under `directory`; an absolute
269
+ source is named relative to `directory`, then the project, and otherwise by
270
+ basename. A traversing source also falls back to its basename.
271
+ - Extraction plans every member before writing: each target is resolved in its
272
+ canonical parent, an existing final symlink is refused, and one bulk
273
+ permission check covers every target plus the extraction root. A denial
274
+ therefore writes no archive members. A symlink member is refused over any
275
+ existing destination; absolute names, `..`, and absolute or traversing link
276
+ targets are rejected.
277
+ - Extracted file modes apply the process umask and strip setuid/setgid;
278
+ directory modes also preserve the sticky bit. ZIP entries without a Unix mode
279
+ default to `0644` files and `0755` directories before the umask.
280
+ Directory modes are deduplicated by canonical target (last entry wins) and
281
+ applied deepest-first. Ordinary file and directory mode changes use opened
282
+ `O_NOFOLLOW` handles; an `EACCES` fallback for an unreadable existing
283
+ directory uses a guarded pathname `chmod`, keeping a final-component TOCTOU
284
+ race. Parent-directory races remain.
285
+ - A parent directory swapped after planning can still redirect a write, an
286
+ existing hardlink at a destination is written through, and an OS error or
287
+ abort can leave earlier members or a truncated file.
288
+ - Archive create and extraction buffer the whole archive in memory (extraction
289
+ also buffers each member) and enforce no global archive-size cap; large
290
+ archives can consume substantial memory.
291
+ - `tar`/`zip` store files, directories, and symlinks. Hard links, device nodes,
292
+ and ACL/xattr metadata are not preserved.
201
293
  - `pipe` passes raw bytes and only accepts registered pipeable stages; `tar` and
202
294
  `zip` are sink stages. Each stage asserts its own `fs_<tool>` action before it
203
- runs, so per-tool denial also applies inside a pipe. It is sequential and not a
204
- batch primitive: independent
295
+ runs, so per-tool denial also applies inside a pipe. A stage that yields no
296
+ stdout produces an empty buffer, so `output` still writes an empty file; the
297
+ signal is checked before every stage and before the final write. It is
298
+ sequential and not a batch primitive: independent
205
299
  calls fan out with `Promise.all` in `execute`.
206
300
 
207
301
  ## Coverage policy
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-fs-plugin",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=22.12"
@@ -169,8 +169,10 @@ The project is read/write/exec. **Network egress needs Linux tier T1** and uses
169
169
  procage's transparent relay. There are no per-call grants. Every TCP/UDP flow is
170
170
  named as a DNS QNAME, TLS SNI, HTTP `Host`, QUIC SNI, or IP literal, and that
171
171
  exact resource is approved through `fs_exec_network`; ports, URLs, and payloads
172
- are never part of the permission. The permission rules are the network allowlist:
173
- a `*` deny plus name/address allows fails closed for anything else.
172
+ are never part of the permission. Bare IPv6 literals and bracketed IPv6 `Host`
173
+ forms with an optional port are valid resources. The permission rules are the
174
+ network allowlist: a `*` deny plus name/address allows fails closed for anything
175
+ else.
174
176
 
175
177
  DNS is authorized by QNAME. Allowed answers feed a per-run address-to-name
176
178
  cache: a nameless flow is allowed by a fresh allowed name bound to its address,
@@ -328,7 +330,9 @@ await tools.fs.pipe({
328
330
 
329
331
  `output` and `append` assert `fs_tee` on the destination. The result metadata
330
332
  lists each stage's `bytesIn`, `bytesOut`, and `exitCode`; use it as the
331
- verification trail.
333
+ verification trail. A stage that yields no stdout becomes an empty buffer, so
334
+ `output` writes an empty file. The signal is checked before each stage and
335
+ before the final write, so an abort stops the chain before creating output.
332
336
 
333
337
  Common pipe mistakes:
334
338
 
@@ -370,8 +374,22 @@ await tools.fs.job({ list: true }) // newest first
370
374
  `wait` returns the original tool result once the job completes; on timeout it
371
375
  returns the status with `timedOut: true`. Jobs are process-local and lost on
372
376
  server restart. Status files live under `/tmp/opencode/fs-jobs/<server-pid>/`
373
- by default; set the plugin option `jobDir` to move them. Eight jobs may run at
374
- once and finished jobs are cleaned after one hour.
377
+ by default; set the plugin option `jobDir` to move them. The caps are global to
378
+ one server, not per session: eight jobs may run at once and 64 are retained,
379
+ evicting the oldest finished job and deleting its status file; finished jobs are
380
+ cleaned after one hour. A background start or `fs.job` call without a non-empty
381
+ session id fails with `invalid`. Jobs are visible only to the session that
382
+ started them; the `jobDir` path is validated component by component (an existing
383
+ symlink, non-directory component, or `/` is refused; missing components and the
384
+ final directory become `0700`), and status files are `0600`. This is deliberately
385
+ fail-closed: a benign path through a host symlink such as `/home` is rejected,
386
+ while the default `/tmp/opencode/fs-jobs/<pid>` path is unaffected. A component
387
+ swapped after validation is a residual TOCTOU gap. Status files omit the result,
388
+ raw error, and absolute status path. Each
389
+ in-memory result is capped at 1 MiB: longer text is truncated with
390
+ `[truncated]`/`truncated`/`originalBytes`, and oversized base64/binary output
391
+ becomes empty. Retaining 64 results can hold roughly 64 MiB in the server
392
+ process until eviction.
375
393
 
376
394
  To wait without blocking the session, combine the status file with `wait_for`.
377
395
  Wait for any terminal state, then read the job for the result or error:
@@ -478,9 +496,43 @@ await tools.fs.curl({
478
496
  - No ICMP ping; use `fs.curl` or a TCP port check. No ACL, xattr, or
479
497
  `chattr` support. `rsync`/`scp` are out of scope; use the SSH MCP.
480
498
  - `fs.comm` expects sorted input. `fs.ar` uses GNU short names (16 bytes max);
481
- `fs.cpio` reads and writes newc only. `fs.dd` has no conversion flags.
482
- - `fs.tar` resolves `paths` even when `directory` is set; pass absolute sources
483
- with `directory` or the member path may not be found.
499
+ `fs.cpio` writes newc with GNU 4-byte padding, reads both that and the prior
500
+ 3.x plugin padding, and rejects nonzero data after the trailer (concatenated
501
+ archives); its fields must fit `0..0xffffffff`. `fs.dd` has no conversion
502
+ flags.
503
+ Archives store files, directories, and symlinks only; hard links, device
504
+ nodes, and ACL/xattr metadata are dropped.
505
+ - `fs.tar` and `fs.cpio` create resolve relative `paths` under `directory`; an
506
+ absolute source is named relative to `directory` first, then the project, else
507
+ by basename (a traversing source also uses its basename).
508
+ - `fs.cp` fails closed on an existing symlink inside a recursive destination;
509
+ `fs.mv` refuses a directory destination under the source, and EXDEV falls back
510
+ to copy-then-remove that refuses a destination symlink. If nothing was copied
511
+ or an entry was skipped, the source is kept and a partial destination remains.
512
+ - `fs.chown` refuses the sandbox root, ancestors, `/`, `$HOME`, and core system
513
+ dirs before permission or mutation. `noDereference` canonicalizes the parent
514
+ chain but leaves the final link, so `lchown` changes a final symlink itself.
515
+ - `fs.split` takes 1-16 suffix characters and fails with `invalid` before
516
+ writing when the chunk count exceeds `26^n` (alphabetic) or `10^n`
517
+ (`numeric`).
518
+ - `fs.curl` refuses a cross-origin redirect unless it is a bodyless `GET`/`HEAD`
519
+ with only safe headers (`accept`, `accept-language`, `cache-control`,
520
+ `pragma`, `range`, `user-agent`), and refuses an HTTPS to HTTP hop. A 303
521
+ becomes a bodyless `GET` before that check; 301/302 rewrite `POST` after it;
522
+ 307/308 keep the method and body. `output` asks `external_directory` for the
523
+ file's containing directory.
524
+ - Archive extraction plans every member, refuses an existing final symlink,
525
+ applies the process umask to extracted file modes (strips setuid/setgid), and
526
+ preserves sticky on directories. ZIP entries without a Unix mode default to
527
+ `0644` files and `0755` directories before the umask. Directory modes are
528
+ deduplicated by canonical target (last entry wins) and applied deepest-first.
529
+ Ordinary mode changes use opened `O_NOFOLLOW` handles; an `EACCES` fallback for
530
+ an unreadable existing directory uses guarded pathname `chmod`, keeping a
531
+ final-component TOCTOU race. A bulk permission denial writes no members. A
532
+ swapped parent, an existing destination hardlink, an OS error, or an abort can
533
+ still redirect or partially write members.
534
+ Archive create and extraction buffer the whole archive and each extracted
535
+ member in memory, with no global archive-size cap.
484
536
  - `fs.du` reports allocated blocks like `du`; use `fs.stat` with `%s` for
485
537
  apparent file bytes.
486
538
  - `fs.trash` uses the XDG home trash only and refuses cross-device moves.
@@ -494,19 +546,32 @@ await tools.fs.curl({
494
546
 
495
547
  ## Paths and safety
496
548
 
497
- - Paths resolve against the project directory. Paths outside it require
498
- `external_directory` approval, except tool-owned temp/trash paths.
499
- - The global config allows `/tmp/opencode/**` and the OpenCode cache, state, and
500
- config trees (`$HOME/.cache/opencode/**`, `$HOME/.local/share/opencode/**`,
501
- `$HOME/.local/state/opencode/**`, `$HOME/.config/opencode/**`). Prefer
502
- `fs.mktemp` for scratch files; a denied path is a blocker, not a reason to
503
- switch to shell.
549
+ - Paths resolve to their canonical target before permissions are asserted, so a
550
+ symlink out of the project asks `external_directory` for the real location.
551
+ Single-file output tools open the final component no-follow; `cp` rejects an
552
+ existing symlink at a nested entry but its copy call is not no-follow. A
553
+ parent directory swapped concurrently is still a TOCTOU gap, so treat the
554
+ sandbox as a guardrail.
555
+ - This installation's global config allows `/tmp/opencode/**` and the OpenCode
556
+ cache, state, and config trees; prefer `fs.mktemp` for scratch files, and treat
557
+ a denied path as a blocker rather than switching to shell.
504
558
  - Symlinks are handled per command: `rm`/`mv` never follow the final link, `cp`
505
- follows unless `archive`/`dereference: false`, and `stat`/`ls` use lstat
559
+ follows a top-level destination link and gates its target but refuses to write
560
+ through an existing symlink inside a recursive copy, and `stat`/`ls` use lstat
506
561
  unless asked to follow.
507
562
  - The project root, its ancestors, `/`, `$HOME`, and core system directories are
508
- hard stops for destructive operations.
509
- - Archive extraction rejects absolute paths, `..`, and escaping links.
563
+ hard stops for destructive operations; `fs.chown` enforces them before
564
+ permission or mutation.
565
+ - Archive extraction plans every member before writing and asserts one bulk
566
+ permission check for all targets: a denied member means nothing is written.
567
+ Existing final symlinks, absolute names, `..`, and escaping links are
568
+ rejected. File modes apply the umask and strip setuid/setgid; directory modes
569
+ preserve sticky. Directory modes are deduplicated by canonical target (last
570
+ entry wins) and applied deepest-first. Ordinary mode changes use `O_NOFOLLOW`
571
+ handles; an `EACCES` fallback uses guarded pathname `chmod` with a
572
+ final-component TOCTOU race. A swapped parent, an existing destination
573
+ hardlink, an OS error, or an abort can still redirect or partially write
574
+ members.
510
575
  - `rm` is permanent; prefer `trash` for recoverable deletes.
511
576
  - Pass `recursive: true` only when you intend to remove a whole tree.
512
577