opencode-fs-plugin 3.4.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/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,27 +99,44 @@ 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
 
68
- - `fs.http_request` supports `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, and `HEAD`
122
+ - `fs.curl` supports `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, and `HEAD`
69
123
  over `http:`/`https:` only; other schemes fail with `unsupported`.
70
- - Requests are allowed by default. `fs.http_request` asserts the built-in
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
- `fs_http_request` 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.
126
+ `fs_curl` action. Every redirect hop re-asserts it for the new URL.
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.
@@ -81,36 +144,68 @@ Aliases are accepted only where noted: `path` for one `paths` element (`stat`,
81
144
 
82
145
  ## Process execution
83
146
 
84
- - `fs.exec` is the only tool that starts processes, through `procage`; it never
147
+ - `fs.command` is the only tool that starts processes, through `procage`; it never
85
148
  uses `child_process`, `spawn`, or a shell.
86
- - `command` must be a bare executable name and must match the allowlist exactly.
87
- Default: `npm`, `npx`, `uv`, `uvx`, `pip`, `pip3`. Override with the plugin
88
- option `execAllowlist`; an empty list disables execution.
149
+ - `command` must be a bare executable name. The executable allowlist is the
150
+ `fs_command` permission: the tool asserts that action with the bare name as its
151
+ resource. With no rule the base allow applies to every executable; a `*` deny
152
+ plus name allows closes the set.
89
153
  - The policy is procage `agent_workspace` v3: the project is read/write/exec.
90
- Network is proxy-only and external paths are denied by default; there are no
91
- per-call grants.
92
- - Network is proxy-only by default: the cage gets a procage proxy whose
93
- allowlist is the hosts approved through `fs_exec_network` in this run. A
94
- refused host asks with the host as the resource, then the run retries with it
95
- added. The permission rules are the only allowlist; there is no plugin option
96
- for it.
97
- - `execNetworkMode: "ip"` opts into all-IP networking after `fs_exec_network`
98
- approval. In `ip` mode the policy also opens the resolver sockets used by
99
- systemd-resolved, nscd, and SSSD. Plain UDP DNS needs none; other Unix
100
- sockets stay blocked. Landlock ignores paths absent on the host. On T2 below
101
- Landlock ABI 9 the sockets cannot be scoped, so `no-unix-sockets` drops them
102
- and only UDP DNS remains.
103
- - Proxy mode needs Linux T1 or macOS. On T2 the cage fails with the `net-proxy`
104
- gap; `fs.exec` retries in `ip` mode and asks on a socket denial.
154
+ External paths are denied by default and there are no per-call grants.
155
+ - Network egress uses procage's transparent relay on Linux tier T1. A per-run
156
+ `AF_UNIX` control server in a 0700 directory accepts exactly one connection,
157
+ validates HELLO against the run id, and multiplexes at most 64 decisions over
158
+ the length-prefixed protocol in `src/core/relay-protocol.ts`.
159
+ - Every TCP/UDP flow is named as a DNS QNAME, TLS SNI, HTTP `Host`, QUIC SNI, or
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.
165
+ - DNS queries are decisions too. An allowed QNAME is forwarded to the parent
166
+ resolver; procage's discovery reads `/etc/resolv.conf` and systemd-resolved
167
+ paths, including a loopback stub, and the plugin leaves `relay_dns_upstream`
168
+ and `relay_resolv_conf` unset. A denied QNAME gets `REFUSED`. An allowed
169
+ answer feeds procage's bounded per-run address-to-name cache. A nameless flow
170
+ to an address is authorized by a fresh allowed name bound to it, else by the
171
+ address. A named flow requires the exact `(name, address)` from an allowed
172
+ answer plus the allowed name, or both name and address explicitly allowed; a
173
+ denied named identity is never rescued by an allowed address. Allow an address
174
+ in addition to the name when a program connects to an IP literal, or when a
175
+ named flow's exact `(name, address)` was not returned by an allowed DNS
176
+ answer. TCP/853 and the finite list of known DoH names are refused without
177
+ asking; custom or unknown DoH endpoints on other names or ports may not be
178
+ recognized, so DoH blocking is best-effort. ECH detected in TLS or QUIC is
179
+ visibly refused.
180
+ - Denials, a closed control link, a failed handshake, an oversized or malformed
181
+ frame, an exhausted in-flight window, and a decision timeout all refuse the
182
+ flow. Completed decision ids are retained in a bounded 1024-entry window so a
183
+ replay is rejected without unbounded memory. There is no direct-route
184
+ fallback.
185
+ - On Linux T2 and macOS procage reports the `net-relay` gap; a relay control
186
+ server that cannot start is treated the same way. The run retries once with
187
+ networking off (`net: "none"`), no resolver sockets, and no macOS resolver
188
+ exception, and reports `networkMode: "disabled"` plus `networkReason`.
189
+ - External proxy variables (`HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`,
190
+ `NO_PROXY`, lowercase forms, and npm proxy variables) are passed explicitly
191
+ because they are not in the preset environment allowlist. The relay treats
192
+ the proxy as the destination, never its `CONNECT` target, so the proxy's
193
+ address or cached DNS name must be allowed in `fs_exec_network`. No other
194
+ caller environment variable is forwarded explicitly; the preset's own
195
+ allowlist still applies, and a proxy variable may itself carry credentials.
105
196
  - Denied paths ask `external_directory` on their containing directory (or the
106
- nearest existing ancestor for a missing or redacted path). Access handling is
107
- bounded to twelve attempts.
197
+ nearest existing ancestor for a missing or redacted path) only when procage
198
+ reports a structured **write** violation (`file-write-*`). Read, exec,
199
+ network, and unknown operations never add a write rule; without a write
200
+ violation no path grant is inferred and access stays denied — pre-grant the
201
+ path or configure a rule. Child stdout/stderr is never parsed for paths.
202
+ Access handling is bounded to twelve attempts.
108
203
  - If a path or socket stays blocked after approval, the result reports
109
204
  `violations` plus a `hint`; stderr containing EACCES/EPERM/EROFS marks
110
- `sandboxBlocked`. Results carry `network`, `networkMode`, `networkHosts`, and
111
- `externalPaths`.
205
+ `sandboxBlocked`. Results carry `network`, `networkMode`, `networkHosts`,
206
+ `networkReason` when the relay was unavailable, and `externalPaths`.
112
207
  - `args` are passed verbatim. `cwd` resolves inside the sandbox and asserts
113
- `external_directory` when it leaves the project; the action is `fs_exec`.
208
+ `external_directory` when it leaves the project; the action is `fs_command`.
114
209
  - Timeout defaults to 120000 ms, capped at 600000. Procage ends the run and kills
115
210
  every process it started, including detached descendants; `timedOut: true`
116
211
  and exit code 124 are returned.
@@ -119,21 +214,12 @@ Aliases are accepted only where noted: `path` for one `paths` element (`stat`,
119
214
  the sandbox decision. In `fs.pipe`, the stage returns raw stdout and composes as
120
215
  a source or filter.
121
216
  - A non-zero exit is a normal result, not a tool error.
122
- - `procage` is lazy-loaded; if the host cannot load it, `fs.exec` fails with
217
+ - `procage` is lazy-loaded; if the host cannot load it, `fs.command` fails with
123
218
  `unsupported` while the other fs tools continue to work. Requires Linux
124
219
  x64/arm64, glibc 2.28+, and Node 22.12+. On kernels before Landlock ABI 6,
125
220
  signals are relaxed from self-and-children to same-user, as procage requires.
126
221
  The trust-handoff class is waived so package tools can update workspace files
127
- such as `.git/hooks`; the executable allowlist remains the trust boundary.
128
-
129
- ## Large output
130
-
131
- A direct tool result larger than the spill threshold is written to
132
- `/tmp/opencode/fs-spill/<tool>-<uuid>.out`. The threshold is a quarter of free
133
- memory, clamped to 16 MiB..512 MiB, or the `spillThresholdBytes` plugin option.
134
- The tool returns a 64 KiB preview, `outputPath`, `bytes`, and `spilled: true`,
135
- and `renderResult` appends a note with the path. `fs.cat` streams into the sink;
136
- other tools spill their finished result. Pipe stages stay in memory.
222
+ such as `.git/hooks`; the `fs_command` permission remains the trust boundary.
137
223
 
138
224
  ## Deliberate gaps
139
225
 
@@ -144,6 +230,7 @@ These are not implemented:
144
230
  delete/trash only
145
231
  - `chgrp`, `chattr`, `rsync`
146
232
  - ACL and xattr preservation in `cp -a`
233
+ - archive hard links, device nodes, and ACL/xattr metadata
147
234
  - remaining GNU edge-flag parity for `ls`, `stat`, `sort`, `find`
148
235
  - symlink-race-proof sandboxing
149
236
  - unbounded `tail -f`; use bounded `follow` or the wait plugin
@@ -151,10 +238,10 @@ These are not implemented:
151
238
  - cross-filesystem `trash`; use `rm` or a mount-trash helper
152
239
  - curl protocols beyond HTTP(S), cookie jars, client certificates, proxies,
153
240
  multipart uploads, and resumable/range downloads
154
- - true streaming through pipe stages; `http_request` buffers unless `output` is set
241
+ - true streaming through pipe stages; `curl` buffers unless `output` is set
155
242
  - worker threads for CPU-bound stages (`sort`, `sed`, text diffing)
156
243
  - parallel member reads inside a single `tar`/`zip` archive; member order is fixed
157
- - process start beyond the allowlisted `exec` tool; `nohup`, `setsid`, and
244
+ - process start beyond the permission-gated `command` tool; `nohup`, `setsid`, and
158
245
  `timeout` wrappers are unavailable
159
246
  - ICMP `ping` (raw sockets) and `ip`/netlink configuration
160
247
  - `rsync`, `scp`, and other transfer protocols; use the SSH MCP for remote work
@@ -176,11 +263,39 @@ These are not implemented:
176
263
  - `find action: "delete"|"trash"` reuses the `fs_rm`/`fs_trash` gates, removes
177
264
  deepest matches first, and never removes the starting directory itself.
178
265
  - `sort -k` accepts field/character ranges with modifiers `bdfghiMnrV`.
179
- - `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.
180
293
  - `pipe` passes raw bytes and only accepts registered pipeable stages; `tar` and
181
294
  `zip` are sink stages. Each stage asserts its own `fs_<tool>` action before it
182
- runs, so per-tool denial also applies inside a pipe. It is sequential and not a
183
- 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
184
299
  calls fan out with `Promise.all` in `execute`.
185
300
 
186
301
  ## Coverage policy
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-fs-plugin",
3
- "version": "3.4.0",
3
+ "version": "3.6.0",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=22.12"
@@ -36,7 +36,7 @@
36
36
  "@sinclair/typebox": "^0.34.52",
37
37
  "diff": "^9.0.0",
38
38
  "picomatch": "^4.0.7",
39
- "procage": "https://github.com/masterjg/procage/releases/download/node-proxy-v1/procage-0.8.0.tgz",
39
+ "procage": "https://github.com/masterjg/procage/releases/download/node-proxy-v2/procage-0.8.0.tgz",
40
40
  "tar-stream": "^3.2.2",
41
41
  "yauzl": "^3.4.0",
42
42
  "yazl": "^3.3.1"