opencode-fs-plugin 3.5.0 → 3.6.1

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,16 +162,24 @@ 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_command_network`; the
168
+ port, URL, headers, and payload are never part of the permission. There is no
169
+ separate network allowlist option.
170
+
171
+ > **Migration from `fs_exec_network`:** replace every old rule with
172
+ > `fs_command_network` before upgrading. Old rules are ignored, and an unlisted
173
+ > `fs_command_network` resource can be allowed by the base rule unless another
174
+ > matching rule applies, so a previous `fs_exec_network` `deny *` no longer
175
+ > closes network egress.
165
176
 
166
177
  ```jsonc
167
178
  {
168
179
  "permissions": [
169
- { "action": "fs_exec_network", "resource": "*", "effect": "deny" },
170
- { "action": "fs_exec_network", "resource": "registry.npmjs.org", "effect": "allow" },
171
- { "action": "fs_exec_network", "resource": "pypi.org", "effect": "allow" }
180
+ { "action": "fs_command_network", "resource": "*", "effect": "deny" },
181
+ { "action": "fs_command_network", "resource": "registry.npmjs.org", "effect": "allow" },
182
+ { "action": "fs_command_network", "resource": "pypi.org", "effect": "allow" }
172
183
  ]
173
184
  }
174
185
  ```
@@ -197,7 +208,7 @@ External proxy settings are preserved: `HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`,
197
208
  `NO_PROXY`, their lowercase forms, and the npm proxy variables are passed to the
198
209
  child explicitly, because they are not in the preset's environment allowlist.
199
210
  The relay treats the proxy as the destination, never its `CONNECT` target, so
200
- an external proxy works only when `fs_exec_network` allows the proxy's address
211
+ an external proxy works only when `fs_command_network` allows the proxy's address
201
212
  (or its cached DNS name, which also needs its DNS query allowed). That approval
202
213
  lets the proxy forward to whatever it reaches; it is not scoped to the target
203
214
  URL behind the proxy. No other caller environment variable is forwarded
@@ -327,11 +338,30 @@ await tools.wait.for({
327
338
 
328
339
  Jobs are process-local: they are lost on an OpenCode server restart, and their
329
340
  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.
341
+ plugin option `jobDir` to move them. The limits are global to one plugin
342
+ instance (one OpenCode server), not per session: at most 8 jobs run at once and
343
+ up to 64 are retained. Starting another evicts the oldest finished job and
344
+ deletes its status file; if no finished job is available to evict the start
345
+ fails with `busy`. Finished jobs are also cleaned up after one hour.
346
+
347
+ Each job is visible only to the session that started it: `fs.job` list, status,
348
+ wait, and cancel treat another session's id as not found. A background start or
349
+ `fs.job` call without a non-empty host session id fails with `invalid`. The
350
+ `jobDir` path is validated component by component: an existing symlink, a
351
+ non-directory component, or the filesystem root is refused, missing components
352
+ are created `0700`, and the final directory is `0700`. This is deliberately
353
+ fail-closed: a benign configured path that traverses a host symlink such as
354
+ `/home` is rejected, while the default `/tmp/opencode/fs-jobs/<pid>` path is
355
+ unaffected. A component swapped after validation remains a residual TOCTOU
356
+ race. Status files are `0600` and hold only id, tool, state, timing, and
357
+ `hasResult`; they omit the result, the raw error, and the absolute status path.
358
+ Results stay in memory and are returned by
359
+ `fs.job`, capped at 1 MiB per result. Longer text is truncated with
360
+ a `[truncated]` marker plus `truncated`/`originalBytes` metadata,
361
+ and an oversized base64/binary result becomes empty content. With 64 retained
362
+ results this can hold roughly 64 MiB of result text in the server process until
363
+ eviction. Background permission prompts can appear after the starting call
364
+ returns, and a denied permission fails the job.
335
365
 
336
366
  ## Installing from npm
337
367
 
@@ -463,13 +493,14 @@ The skill ID is `filesystem`; `@filesystem` loads it explicitly.
463
493
  Every tool asserts an action named after the tool (`fs_cp`, `fs_rm`,
464
494
  `fs_pipe` stages, and so on), except `fs.curl`, which reuses the
465
495
  built-in `webfetch` action. Internal paths use project-relative resources;
466
- external targets first require `external_directory` on the absolute boundary.
496
+ external targets first require `external_directory` on the absolute boundary,
497
+ computed from the canonical target rather than the symlink path.
467
498
  `allow always` saves the exact resources the call asserted — project-relative
468
499
  paths, absolute external boundaries, or network names/addresses. A specific
469
500
  resource saves narrowly; an explicitly requested `*` remains `*`.
470
501
 
471
502
  `fs.command` asserts `fs_command` with the executable name, asks
472
- `external_directory` for any blocked path, and asks `fs_exec_network` for the
503
+ `external_directory` for any blocked path, and asks `fs_command_network` for the
473
504
  exact DNS name or IP address the transparent relay named. There is no `*`
474
505
  fallback and no direct-IP mode; networking that cannot use the relay is
475
506
  disabled:
@@ -480,15 +511,15 @@ disabled:
480
511
  { "action": "fs_command", "resource": "*", "effect": "deny" },
481
512
  { "action": "fs_command", "resource": "npm", "effect": "allow" },
482
513
  { "action": "external_directory", "resource": "$HOME/.npm/**", "effect": "ask" },
483
- { "action": "fs_exec_network", "resource": "*", "effect": "deny" },
484
- { "action": "fs_exec_network", "resource": "registry.npmjs.org", "effect": "allow" }
514
+ { "action": "fs_command_network", "resource": "*", "effect": "deny" },
515
+ { "action": "fs_command_network", "resource": "registry.npmjs.org", "effect": "allow" }
485
516
  ]
486
517
  }
487
518
  ```
488
519
 
489
520
  Keep the rules explicit. Plugin actions match OpenCode's base
490
521
  `{ "action": "*", "resource": "*", "effect": "allow" }` rule, so an unlisted
491
- `fs_command`, `fs_exec_network`, or `external_directory` resource is allowed
522
+ `fs_command`, `fs_command_network`, or `external_directory` resource is allowed
492
523
  without a prompt, not asked.
493
524
 
494
525
  `fs.curl` reuses the built-in `webfetch` permission, with the requested
@@ -533,18 +564,77 @@ when only some agents should be shell-free.
533
564
 
534
565
  - The sandbox root, its ancestors, `/`, `$HOME` and core system directories are
535
566
  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.
567
+ - Paths resolve to their canonical target before a permission is asserted, so a
568
+ symlink that escapes the project asks `external_directory` for the real
569
+ location; removing or renaming the link itself stays internal. Single-file
570
+ output tools (archives, `gzip`, `tee`, `split`, `dd`, `pipe`) open the resolved
571
+ final component with `O_NOFOLLOW`, so a link swapped in after the check fails
572
+ instead of being followed; `cp` refuses an existing symlink at a nested entry
573
+ but its final copy call is not no-follow. Node has no `openat`, so a
574
+ concurrently swapped parent directory remains a TOCTOU gap.
575
+ - `cp` follows a top-level destination symlink to its canonical target and gates
576
+ that path. Inside a recursive copy it refuses to write through an existing
577
+ symlink (directory or file) and fails closed; a copied symlink replaces the
578
+ destination link itself. A source/destination hard-link alias is rejected.
579
+ - `mv` refuses to move a directory into itself. A cross-device move (EXDEV)
580
+ refuses a destination symlink, copies with `preserve`, and removes the source
581
+ only after every entry was copied. If nothing was copied or a
582
+ `noClobber`/`update` entry was skipped, it reports `cross-device` and preserves
583
+ the source; the partially populated destination is left in place.
584
+ - `chown` refuses the sandbox root, its ancestors, `/`, `$HOME`, and core system
585
+ directories before asserting permission or changing ownership; recursive chown
586
+ skips traversal symlinks. With `noDereference` it resolves the parent chain to
587
+ its canonical directory but leaves the final component, so a parent symlink is
588
+ gated at its real location and `lchown` changes a final symlink itself.
589
+ - Archive create writes its output through the same no-follow final open.
590
+ Extraction first plans every member: destinations are resolved in their
591
+ canonical parents, an existing final symlink is refused, and one bulk
592
+ permission check covers all targets before anything is written, so a denial
593
+ writes no archive members. A symlink member is refused over any existing
594
+ destination, and absolute names, `..`, and absolute or traversing link targets
595
+ are rejected. Extracted file modes apply the process umask and strip
596
+ setuid/setgid; directory modes also preserve the sticky bit. ZIP entries with
597
+ no Unix mode default to `0644` files and `0755` directories before the umask.
598
+ Directory modes are deduplicated by canonical target (last entry wins) and
599
+ applied deepest-first. Ordinary file and directory mode changes use opened
600
+ `O_NOFOLLOW` handles; an `EACCES` fallback for an unreadable existing
601
+ directory uses a guarded pathname `chmod`, keeping a final-component TOCTOU
602
+ race. Parent-component races remain. An abort before an archive create write
603
+ leaves no archive file. A parent directory swapped after planning can still redirect a
604
+ write, an existing destination hardlink can be written through, and an OS
605
+ error or abort can leave earlier members or a truncated file. Archive create
606
+ and extraction buffer the whole archive (extraction also buffers each member)
607
+ in memory and have no global archive-size cap, so large archives can consume
608
+ substantial memory.
609
+ - `tar` and `cpio` create resolve relative `paths` under `directory`; absolute
610
+ sources are named relative to `directory` first, then the project, and fall
611
+ back to the basename (a traversing source uses its basename). `tar`/`zip` store
612
+ files, directories, and symlinks (no hardlinks, devices, ACLs, or xattrs);
613
+ `cpio` is newc with GNU 4-byte padding, and its decoder also accepts the prior
614
+ 3.x plugin padding; strict decode rejects nonzero data after the trailer
615
+ (concatenated archives). `cpio` fields must fit 0..0xffffffff; `ar` uses 16-byte
616
+ GNU short names.
617
+ - `split` checks suffix capacity before writing: alphabetic suffixes cover
618
+ `26^suffixLength` chunks and `numeric` covers `10^suffixLength`; more chunks
619
+ fail with `invalid`.
620
+ - `curl` accepts only `http:` and `https:`, keeps TLS verification on, and
621
+ re-checks permissions on every redirect hop. A same-origin redirect keeps the
622
+ request. A cross-origin redirect is refused unless it is a bodyless `GET` or
623
+ `HEAD` whose caller headers are all in the safe set (`accept`,
624
+ `accept-language`, `cache-control`, `pragma`, `range`, `user-agent`);
625
+ credentials, custom headers, other methods, a request body, and embedded URL
626
+ credentials are refused, not stripped. A 303 rewrites `POST` to a bodyless
627
+ `GET` before that policy, so a safe resulting GET may cross origins; 301/302
628
+ rewrite `POST` after the policy, and 307/308 keep the method and body. An
629
+ HTTPS to HTTP redirect is always refused. For `output`, the resolved file's
630
+ containing directory is the permission boundary, so an external destination
631
+ asks `external_directory` for that directory. Downloads stream to a temporary
632
+ file and are renamed only after the body and checksum complete. Localhost and
633
+ private addresses are not blocked by default.
544
634
  - `rm` is permanent. `trash` uses the XDG home trash and refuses cross-device
545
635
  moves instead of silently copying.
546
- - The sandbox is a guardrail, not a kernel security boundary. Symlink races
547
- remain possible.
636
+ - The sandbox is a guardrail, not a kernel security boundary.
637
+ Parent/hardlink races and partial writes remain possible.
548
638
 
549
639
  ## Development
550
640
 
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,16 @@ 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_command_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.
165
+ - **Migration from `fs_exec_network`:** replace every old rule with
166
+ `fs_command_network` before upgrading. Old rules are ignored; an unlisted
167
+ `fs_command_network` resource can fall back to the base allow unless another
168
+ matching rule applies, so an old `fs_exec_network` `deny *` no longer closes
169
+ egress.
100
170
  - DNS queries are decisions too. An allowed QNAME is forwarded to the parent
101
171
  resolver; procage's discovery reads `/etc/resolv.conf` and systemd-resolved
102
172
  paths, including a loopback stub, and the plugin leaves `relay_dns_upstream`
@@ -125,7 +195,7 @@ Aliases are accepted only where noted: `path` for one `paths` element (`stat`,
125
195
  `NO_PROXY`, lowercase forms, and npm proxy variables) are passed explicitly
126
196
  because they are not in the preset environment allowlist. The relay treats
127
197
  the proxy as the destination, never its `CONNECT` target, so the proxy's
128
- address or cached DNS name must be allowed in `fs_exec_network`. No other
198
+ address or cached DNS name must be allowed in `fs_command_network`. No other
129
199
  caller environment variable is forwarded explicitly; the preset's own
130
200
  allowlist still applies, and a proxy variable may itself carry credentials.
131
201
  - Denied paths ask `external_directory` on their containing directory (or the
@@ -165,6 +235,7 @@ These are not implemented:
165
235
  delete/trash only
166
236
  - `chgrp`, `chattr`, `rsync`
167
237
  - ACL and xattr preservation in `cp -a`
238
+ - archive hard links, device nodes, and ACL/xattr metadata
168
239
  - remaining GNU edge-flag parity for `ls`, `stat`, `sort`, `find`
169
240
  - symlink-race-proof sandboxing
170
241
  - unbounded `tail -f`; use bounded `follow` or the wait plugin
@@ -197,11 +268,39 @@ These are not implemented:
197
268
  - `find action: "delete"|"trash"` reuses the `fs_rm`/`fs_trash` gates, removes
198
269
  deepest matches first, and never removes the starting directory itself.
199
270
  - `sort -k` accepts field/character ranges with modifiers `bdfghiMnrV`.
200
- - `tar`/`zip` extraction rejects path traversal and escaping links.
271
+ - Archive create writes the output through its resolved target with a no-follow
272
+ final open; an abort before the write leaves no archive file.
273
+ - `tar` and `cpio` create resolve relative `paths` under `directory`; an absolute
274
+ source is named relative to `directory`, then the project, and otherwise by
275
+ basename. A traversing source also falls back to its basename.
276
+ - Extraction plans every member before writing: each target is resolved in its
277
+ canonical parent, an existing final symlink is refused, and one bulk
278
+ permission check covers every target plus the extraction root. A denial
279
+ therefore writes no archive members. A symlink member is refused over any
280
+ existing destination; absolute names, `..`, and absolute or traversing link
281
+ targets are rejected.
282
+ - Extracted file modes apply the process umask and strip setuid/setgid;
283
+ directory modes also preserve the sticky bit. ZIP entries without a Unix mode
284
+ default to `0644` files and `0755` directories before the umask.
285
+ Directory modes are deduplicated by canonical target (last entry wins) and
286
+ applied deepest-first. Ordinary file and directory mode changes use opened
287
+ `O_NOFOLLOW` handles; an `EACCES` fallback for an unreadable existing
288
+ directory uses a guarded pathname `chmod`, keeping a final-component TOCTOU
289
+ race. Parent-directory races remain.
290
+ - A parent directory swapped after planning can still redirect a write, an
291
+ existing hardlink at a destination is written through, and an OS error or
292
+ abort can leave earlier members or a truncated file.
293
+ - Archive create and extraction buffer the whole archive in memory (extraction
294
+ also buffers each member) and enforce no global archive-size cap; large
295
+ archives can consume substantial memory.
296
+ - `tar`/`zip` store files, directories, and symlinks. Hard links, device nodes,
297
+ and ACL/xattr metadata are not preserved.
201
298
  - `pipe` passes raw bytes and only accepts registered pipeable stages; `tar` and
202
299
  `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
300
+ runs, so per-tool denial also applies inside a pipe. A stage that yields no
301
+ stdout produces an empty buffer, so `output` still writes an empty file; the
302
+ signal is checked before every stage and before the final write. It is
303
+ sequential and not a batch primitive: independent
205
304
  calls fan out with `Promise.all` in `execute`.
206
305
 
207
306
  ## 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.1",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=22.12"
@@ -168,9 +168,17 @@ With no rule the base allow applies to every executable.
168
168
  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
- 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.
171
+ exact resource is approved through `fs_command_network`; ports, URLs, and payloads
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.
176
+
177
+ > **Migration from `fs_exec_network`:** replace every old rule with
178
+ > `fs_command_network` before upgrading. Old rules are ignored; an unlisted
179
+ > `fs_command_network` resource can fall back to the base allow unless another
180
+ > matching rule applies, so an old `fs_exec_network` `deny *` no longer closes
181
+ > egress.
174
182
 
175
183
  DNS is authorized by QNAME. Allowed answers feed a per-run address-to-name
176
184
  cache: a nameless flow is allowed by a fresh allowed name bound to its address,
@@ -191,7 +199,7 @@ await tools.fs.command({ command: "npm", args: ["install"], timeoutMs: 300000 })
191
199
  Proxy variables (`HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`, `NO_PROXY`, lowercase
192
200
  forms, npm proxy settings) pass through explicitly. The relay treats the proxy
193
201
  as the destination, never its `CONNECT` target, so allow the proxy's address or
194
- cached DNS name in `fs_exec_network`; approving it lets the proxy reach whatever
202
+ cached DNS name in `fs_command_network`; approving it lets the proxy reach whatever
195
203
  it forwards. No other caller environment variable is forwarded explicitly, but
196
204
  the preset's own allowlist still applies, and a proxy variable may itself carry
197
205
  proxy credentials.
@@ -328,7 +336,9 @@ await tools.fs.pipe({
328
336
 
329
337
  `output` and `append` assert `fs_tee` on the destination. The result metadata
330
338
  lists each stage's `bytesIn`, `bytesOut`, and `exitCode`; use it as the
331
- verification trail.
339
+ verification trail. A stage that yields no stdout becomes an empty buffer, so
340
+ `output` writes an empty file. The signal is checked before each stage and
341
+ before the final write, so an abort stops the chain before creating output.
332
342
 
333
343
  Common pipe mistakes:
334
344
 
@@ -370,8 +380,22 @@ await tools.fs.job({ list: true }) // newest first
370
380
  `wait` returns the original tool result once the job completes; on timeout it
371
381
  returns the status with `timedOut: true`. Jobs are process-local and lost on
372
382
  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.
383
+ by default; set the plugin option `jobDir` to move them. The caps are global to
384
+ one server, not per session: eight jobs may run at once and 64 are retained,
385
+ evicting the oldest finished job and deleting its status file; finished jobs are
386
+ cleaned after one hour. A background start or `fs.job` call without a non-empty
387
+ session id fails with `invalid`. Jobs are visible only to the session that
388
+ started them; the `jobDir` path is validated component by component (an existing
389
+ symlink, non-directory component, or `/` is refused; missing components and the
390
+ final directory become `0700`), and status files are `0600`. This is deliberately
391
+ fail-closed: a benign path through a host symlink such as `/home` is rejected,
392
+ while the default `/tmp/opencode/fs-jobs/<pid>` path is unaffected. A component
393
+ swapped after validation is a residual TOCTOU gap. Status files omit the result,
394
+ raw error, and absolute status path. Each
395
+ in-memory result is capped at 1 MiB: longer text is truncated with
396
+ `[truncated]`/`truncated`/`originalBytes`, and oversized base64/binary output
397
+ becomes empty. Retaining 64 results can hold roughly 64 MiB in the server
398
+ process until eviction.
375
399
 
376
400
  To wait without blocking the session, combine the status file with `wait_for`.
377
401
  Wait for any terminal state, then read the job for the result or error:
@@ -478,9 +502,43 @@ await tools.fs.curl({
478
502
  - No ICMP ping; use `fs.curl` or a TCP port check. No ACL, xattr, or
479
503
  `chattr` support. `rsync`/`scp` are out of scope; use the SSH MCP.
480
504
  - `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.
505
+ `fs.cpio` writes newc with GNU 4-byte padding, reads both that and the prior
506
+ 3.x plugin padding, and rejects nonzero data after the trailer (concatenated
507
+ archives); its fields must fit `0..0xffffffff`. `fs.dd` has no conversion
508
+ flags.
509
+ Archives store files, directories, and symlinks only; hard links, device
510
+ nodes, and ACL/xattr metadata are dropped.
511
+ - `fs.tar` and `fs.cpio` create resolve relative `paths` under `directory`; an
512
+ absolute source is named relative to `directory` first, then the project, else
513
+ by basename (a traversing source also uses its basename).
514
+ - `fs.cp` fails closed on an existing symlink inside a recursive destination;
515
+ `fs.mv` refuses a directory destination under the source, and EXDEV falls back
516
+ to copy-then-remove that refuses a destination symlink. If nothing was copied
517
+ or an entry was skipped, the source is kept and a partial destination remains.
518
+ - `fs.chown` refuses the sandbox root, ancestors, `/`, `$HOME`, and core system
519
+ dirs before permission or mutation. `noDereference` canonicalizes the parent
520
+ chain but leaves the final link, so `lchown` changes a final symlink itself.
521
+ - `fs.split` takes 1-16 suffix characters and fails with `invalid` before
522
+ writing when the chunk count exceeds `26^n` (alphabetic) or `10^n`
523
+ (`numeric`).
524
+ - `fs.curl` refuses a cross-origin redirect unless it is a bodyless `GET`/`HEAD`
525
+ with only safe headers (`accept`, `accept-language`, `cache-control`,
526
+ `pragma`, `range`, `user-agent`), and refuses an HTTPS to HTTP hop. A 303
527
+ becomes a bodyless `GET` before that check; 301/302 rewrite `POST` after it;
528
+ 307/308 keep the method and body. `output` asks `external_directory` for the
529
+ file's containing directory.
530
+ - Archive extraction plans every member, refuses an existing final symlink,
531
+ applies the process umask to extracted file modes (strips setuid/setgid), and
532
+ preserves sticky on directories. ZIP entries without a Unix mode default to
533
+ `0644` files and `0755` directories before the umask. Directory modes are
534
+ deduplicated by canonical target (last entry wins) and applied deepest-first.
535
+ Ordinary mode changes use opened `O_NOFOLLOW` handles; an `EACCES` fallback for
536
+ an unreadable existing directory uses guarded pathname `chmod`, keeping a
537
+ final-component TOCTOU race. A bulk permission denial writes no members. A
538
+ swapped parent, an existing destination hardlink, an OS error, or an abort can
539
+ still redirect or partially write members.
540
+ Archive create and extraction buffer the whole archive and each extracted
541
+ member in memory, with no global archive-size cap.
484
542
  - `fs.du` reports allocated blocks like `du`; use `fs.stat` with `%s` for
485
543
  apparent file bytes.
486
544
  - `fs.trash` uses the XDG home trash only and refuses cross-device moves.
@@ -494,19 +552,32 @@ await tools.fs.curl({
494
552
 
495
553
  ## Paths and safety
496
554
 
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.
555
+ - Paths resolve to their canonical target before permissions are asserted, so a
556
+ symlink out of the project asks `external_directory` for the real location.
557
+ Single-file output tools open the final component no-follow; `cp` rejects an
558
+ existing symlink at a nested entry but its copy call is not no-follow. A
559
+ parent directory swapped concurrently is still a TOCTOU gap, so treat the
560
+ sandbox as a guardrail.
561
+ - This installation's global config allows `/tmp/opencode/**` and the OpenCode
562
+ cache, state, and config trees; prefer `fs.mktemp` for scratch files, and treat
563
+ a denied path as a blocker rather than switching to shell.
504
564
  - Symlinks are handled per command: `rm`/`mv` never follow the final link, `cp`
505
- follows unless `archive`/`dereference: false`, and `stat`/`ls` use lstat
565
+ follows a top-level destination link and gates its target but refuses to write
566
+ through an existing symlink inside a recursive copy, and `stat`/`ls` use lstat
506
567
  unless asked to follow.
507
568
  - 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.
569
+ hard stops for destructive operations; `fs.chown` enforces them before
570
+ permission or mutation.
571
+ - Archive extraction plans every member before writing and asserts one bulk
572
+ permission check for all targets: a denied member means nothing is written.
573
+ Existing final symlinks, absolute names, `..`, and escaping links are
574
+ rejected. File modes apply the umask and strip setuid/setgid; directory modes
575
+ preserve sticky. Directory modes are deduplicated by canonical target (last
576
+ entry wins) and applied deepest-first. Ordinary mode changes use `O_NOFOLLOW`
577
+ handles; an `EACCES` fallback uses guarded pathname `chmod` with a
578
+ final-component TOCTOU race. A swapped parent, an existing destination
579
+ hardlink, an OS error, or an abort can still redirect or partially write
580
+ members.
510
581
  - `rm` is permanent; prefer `trash` for recoverable deletes.
511
582
  - Pass `recursive: true` only when you intend to remove a whole tree.
512
583
 
@@ -518,7 +589,7 @@ hidden inside a pipeline. Do not work around a denied tool with shell.
518
589
 
519
590
  `fs.command` asserts `fs_command` with the executable name as its resource;
520
591
  deny `*` for a closed set. It asks `external_directory` for a blocked path and
521
- `fs_exec_network` with the exact DNS name or IP address named by the relay.
592
+ `fs_command_network` with the exact DNS name or IP address named by the relay.
522
593
  There is no `*` fallback and no direct-IP mode; networking that cannot use the
523
594
  relay is disabled. There are no per-call grants and no shell.
524
595