opencode-fs-plugin 3.4.0 → 3.5.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 +173 -121
- package/SPEC.md +61 -40
- package/package.json +2 -2
- package/skills/filesystem/SKILL.md +93 -53
- package/src/core/format.ts +3 -9
- package/src/core/permissions.ts +32 -14
- package/src/core/relay-control.ts +343 -0
- package/src/core/relay-protocol.ts +229 -0
- package/src/core/types.ts +0 -5
- package/src/index.ts +55 -66
- package/src/tools/cat.ts +31 -46
- package/src/tools/command.ts +533 -0
- package/src/tools/{http_request.ts → curl.ts} +4 -4
- package/src/tools/pipe.ts +7 -7
- package/src/core/spill.ts +0 -145
- package/src/tools/exec.ts +0 -483
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-fs-plugin",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.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-
|
|
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"
|
|
@@ -24,8 +24,8 @@ With `execute` allowed, call it as `tools.fs.<command>`; agents without
|
|
|
24
24
|
| Metadata/predicate search | `fs.find` |
|
|
25
25
|
| Regex substitution or in-place edit | `fs.sed` |
|
|
26
26
|
| Recoverable deletion | `fs.trash` |
|
|
27
|
-
|
|
|
28
|
-
| Allowlisted package CLI | `fs.
|
|
27
|
+
| `curl` fetch, API call, or file download | `fs.curl` |
|
|
28
|
+
| Allowlisted package CLI | `fs.command` (no shell; default npm/npx/uv/uvx/pip/pip3) |
|
|
29
29
|
| Many independent fs calls | one multi-path call, else `Promise.all` in `execute` |
|
|
30
30
|
| Sequential byte pipeline | `fs.pipe` |
|
|
31
31
|
|
|
@@ -53,8 +53,8 @@ what `fs.stat`, `fs.ls`, `fs.hash`, `fs.diff`, or `fs.cat` can confirm.
|
|
|
53
53
|
| Temp and trash | `fs.mktemp`, `fs.trash` |
|
|
54
54
|
| Text filters | `fs.cat`, `fs.head`, `fs.tail`, `fs.grep`, `fs.sed`, `fs.sort`, `fs.uniq`, `fs.cut`, `fs.tr`, `fs.wc`, `fs.tee`, `fs.tac`, `fs.rev`, `fs.nl`, `fs.paste`, `fs.comm`, `fs.split`, `fs.shuf`, `fs.fold` |
|
|
55
55
|
| Compose filters | `fs.pipe` |
|
|
56
|
-
|
|
|
57
|
-
| Allowlisted package CLI | `fs.
|
|
56
|
+
| curl | `fs.curl` (`output`, `checksum`, `maxBytes`, `json`) |
|
|
57
|
+
| Allowlisted package CLI | `fs.command` (`command`, `args`, `cwd`, `stdin`, `timeoutMs`) |
|
|
58
58
|
| Processes | `fs.ps`, `fs.pgrep`, `fs.kill` (`dryRun` available) |
|
|
59
59
|
| System info | `fs.id`, `fs.uname`, `fs.uptime`, `fs.date`, `fs.findmnt`, `fs.mountpoint` |
|
|
60
60
|
| Binary inspection | `fs.file`, `fs.base64`, `fs.od`, `fs.strings` |
|
|
@@ -98,9 +98,9 @@ host drops unknown fields, so a name typo runs with defaults.
|
|
|
98
98
|
| `input` + `output` | `fs.dd` (`blockSize`, `count`, `skip`, `seek`) |
|
|
99
99
|
| `content` | `fs.tee` when there is no stdin |
|
|
100
100
|
| `paths` + optional `keep`/`force`/`stdout`/`level`/`suffix` | `fs.gzip`, `fs.gunzip` |
|
|
101
|
-
| `url` + optional `output` | `fs.
|
|
101
|
+
| `url` + optional `output` | `fs.curl` |
|
|
102
102
|
| `stages` + optional `input`/`output` | `fs.pipe` |
|
|
103
|
-
| `command` + `args` + optional `cwd`/`stdin`/`timeoutMs` | `fs.
|
|
103
|
+
| `command` + `args` + optional `cwd`/`stdin`/`timeoutMs` | `fs.command` |
|
|
104
104
|
|
|
105
105
|
`fs.head` takes `skip` for line ranges: `sed -n '20,40p'` is
|
|
106
106
|
`fs.head({ paths, skip: 19, lines: 21 })`. `fs.find` takes
|
|
@@ -139,54 +139,90 @@ removed, and deletion asserts `fs_rm`/`fs_trash`.
|
|
|
139
139
|
| `cat > f <<EOF` | built-in `write` or `fs.tee({ paths: [f], content })` |
|
|
140
140
|
| `rg pattern path` | `fs.grep({ pattern, paths })` or the built-in `grep` |
|
|
141
141
|
| `ls -l f` | `fs.ls({ paths: [f], long: true })` |
|
|
142
|
-
| `npm ...` / `uv run ...` | `fs.
|
|
142
|
+
| `npm ...` / `uv run ...` | `fs.command({ command, args })` (`fs_command` permission) |
|
|
143
143
|
|
|
144
144
|
`sed -n` applied to another command's stdout has no fs equivalent; keep that in
|
|
145
145
|
the command pipeline. `fs.find` has no arbitrary `-exec` by design; use
|
|
146
146
|
`action: "delete"` or `"trash"` for the common cleanup case, or list the paths and
|
|
147
147
|
remove them explicitly.
|
|
148
148
|
|
|
149
|
-
##
|
|
149
|
+
## Command
|
|
150
150
|
|
|
151
|
-
`fs.
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
`fs.command` runs an executable in a **procage sandbox** without a shell. It is
|
|
152
|
+
closest to the shell's `command <prog>`: one program with literal argv, not
|
|
153
|
+
`exec` (which replaces the shell) or `sh -c` (which parses shell syntax). The
|
|
154
|
+
executable allowlist is the `fs_command` permission: the tool asserts that action
|
|
155
|
+
with the bare executable name as its resource. Deny `*`, then allow the names
|
|
156
|
+
you need:
|
|
154
157
|
|
|
155
158
|
```jsonc
|
|
156
|
-
{ "
|
|
159
|
+
{ "permissions": [
|
|
160
|
+
{ "action": "fs_command", "resource": "*", "effect": "deny" },
|
|
161
|
+
{ "action": "fs_command", "resource": "npm", "effect": "allow" },
|
|
162
|
+
{ "action": "fs_command", "resource": "uv", "effect": "allow" }
|
|
163
|
+
] }
|
|
157
164
|
```
|
|
158
165
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
+
With no rule the base allow applies to every executable.
|
|
167
|
+
|
|
168
|
+
The project is read/write/exec. **Network egress needs Linux tier T1** and uses
|
|
169
|
+
procage's transparent relay. There are no per-call grants. Every TCP/UDP flow is
|
|
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.
|
|
174
|
+
|
|
175
|
+
DNS is authorized by QNAME. Allowed answers feed a per-run address-to-name
|
|
176
|
+
cache: a nameless flow is allowed by a fresh allowed name bound to its address,
|
|
177
|
+
else by the address. A named flow needs the exact `(name, address)` from an
|
|
178
|
+
allowed answer plus the allowed name, or both name and address allowed; a denied
|
|
179
|
+
named identity is never rescued by an allowed address. Allow an address in
|
|
180
|
+
addition to the name when a program connects to an IP literal, or when a named
|
|
181
|
+
flow's exact `(name, address)` was not returned by an allowed DNS answer.
|
|
182
|
+
|
|
183
|
+
DoH blocking is best-effort: TCP/853 and known DoH names are refused, but custom
|
|
184
|
+
or unknown DoH endpoints on other names or ports may not be recognized. ECH
|
|
185
|
+
detected in TLS or QUIC is visibly refused.
|
|
166
186
|
|
|
167
187
|
```js
|
|
168
|
-
await tools.fs.
|
|
188
|
+
await tools.fs.command({ command: "npm", args: ["install"], timeoutMs: 300000 })
|
|
169
189
|
```
|
|
170
190
|
|
|
191
|
+
Proxy variables (`HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`, `NO_PROXY`, lowercase
|
|
192
|
+
forms, npm proxy settings) pass through explicitly. The relay treats the proxy
|
|
193
|
+
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
|
|
195
|
+
it forwards. No other caller environment variable is forwarded explicitly, but
|
|
196
|
+
the preset's own allowlist still applies, and a proxy variable may itself carry
|
|
197
|
+
proxy credentials.
|
|
198
|
+
|
|
171
199
|
Denied paths ask `external_directory` and approval covers the denied path's
|
|
172
|
-
containing directory (or nearest existing ancestor)
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
the
|
|
200
|
+
containing directory (or nearest existing ancestor) only when procage reports a
|
|
201
|
+
structured **write** violation (`file-write-*`). Read, exec, network, and
|
|
202
|
+
unknown operations never add a write rule; otherwise no path grant is inferred
|
|
203
|
+
and access stays denied — pre-grant the path or configure a rule. A path printed
|
|
204
|
+
on stdout or stderr is reported, never auto-approved. Denied access returns
|
|
205
|
+
`violations` and a `hint`. On Linux T2 or macOS the relay is unavailable, and a
|
|
206
|
+
relay control server that cannot start is treated the same way: the run
|
|
207
|
+
retries once with networking off (`net: "none"`, no resolver sockets, no macOS
|
|
208
|
+
resolver grant) and reports `networkMode: "disabled"` plus `networkReason`. A
|
|
209
|
+
denial, lost control link, malformed frame, or decision timeout refuses the
|
|
210
|
+
flow; there is no direct-IP fallback. `command` is a bare name, `args` are
|
|
211
|
+
literal, and `cwd` is sandboxed. Direct calls return JSON with
|
|
212
|
+
`exitCode`/`stdout`/`stderr`, violations, and the network fields `network`,
|
|
213
|
+
`networkMode`, `networkHosts`, and `networkReason`; `externalPaths` lists the
|
|
214
|
+
external roots the run could write to. In `fs.pipe` the stage passes raw stdout.
|
|
179
215
|
|
|
180
216
|
```js
|
|
181
217
|
await tools.fs.pipe({
|
|
182
218
|
stages: [
|
|
183
|
-
{ tool: "
|
|
219
|
+
{ tool: "command", args: { command: "npm", args: ["test"] } },
|
|
184
220
|
{ tool: "grep", args: { pattern: "FAIL" } },
|
|
185
221
|
],
|
|
186
222
|
})
|
|
187
223
|
```
|
|
188
224
|
|
|
189
|
-
A non-zero exit is a normal result;
|
|
225
|
+
A non-zero exit is a normal result; permission denial, timeout, and abort are
|
|
190
226
|
handled explicitly. Procage kills every process the run started, including
|
|
191
227
|
detached descendants, and returns captured stdout/stderr in full. It requires Linux
|
|
192
228
|
x64/arm64, glibc 2.28+, and Node 22.12+.
|
|
@@ -263,15 +299,15 @@ await tools.fs.pipe({
|
|
|
263
299
|
| `output` | Write final stdout to a file (final `tee`) |
|
|
264
300
|
| `append` | Append to `output` instead of overwriting |
|
|
265
301
|
|
|
266
|
-
The first stage must be a source (`cat`, `
|
|
302
|
+
The first stage must be a source (`cat`, `curl`, `dd`, or a path-reading
|
|
267
303
|
text tool such as `tac`, `rev`, `nl`, `base64`, `od`, `strings`) or receive
|
|
268
304
|
`input`. A filter first (`grep`, `sort`, `head`, `wc`) emits
|
|
269
305
|
`ERROR: no input files and no stdin` as pipeline data. Archive writers (`tar`,
|
|
270
306
|
`zip`, `cpio`) emit nothing downstream, so put them last. `wc` and `hash` also
|
|
271
307
|
emit their result text, so they can end a chain or feed a later stage.
|
|
272
308
|
|
|
273
|
-
Stages exchange whole buffers. Set `maxBytes` on `
|
|
274
|
-
downloads prefer `fs.
|
|
309
|
+
Stages exchange whole buffers. Set `maxBytes` on `curl`; for large
|
|
310
|
+
downloads prefer `fs.curl({ output })`, which streams to disk. In-memory
|
|
275
311
|
text is allowed:
|
|
276
312
|
|
|
277
313
|
```js
|
|
@@ -284,7 +320,7 @@ await tools.fs.pipe({
|
|
|
284
320
|
```js
|
|
285
321
|
await tools.fs.pipe({
|
|
286
322
|
stages: [
|
|
287
|
-
{ tool: "
|
|
323
|
+
{ tool: "curl", args: { url: "https://example.com/app.log", maxBytes: 8_000_000 } },
|
|
288
324
|
{ tool: "grep", args: { pattern: "ERROR" } },
|
|
289
325
|
],
|
|
290
326
|
})
|
|
@@ -303,15 +339,16 @@ Common pipe mistakes:
|
|
|
303
339
|
- There is no shell, redirection operator, nested pipe, `find -exec`, or
|
|
304
340
|
`xargs`.
|
|
305
341
|
|
|
306
|
-
Pipeable filters include `
|
|
307
|
-
`
|
|
308
|
-
`
|
|
342
|
+
Pipeable filters include `base64`, `command`, `cut`, `fold`, `grep`, `gunzip`,
|
|
343
|
+
`gzip`, `head`, `nl`, `od`, `paste`, `rev`, `sed`, `shuf`, `sort`, `strings`,
|
|
344
|
+
`tac`, `tail`, `tee`, `tr`, and `uniq`. Unknown stage names fail with
|
|
345
|
+
`unsupported`.
|
|
309
346
|
|
|
310
347
|
## Background jobs
|
|
311
348
|
|
|
312
|
-
Every tool accepts `background: true`. It returns immediately
|
|
313
|
-
an atomic status-file path; use it for long copies, searches,
|
|
314
|
-
hashes, then keep working and collect the result later.
|
|
349
|
+
Every tool except `fs.job` accepts `background: true`. It returns immediately
|
|
350
|
+
with a job id and an atomic status-file path; use it for long copies, searches,
|
|
351
|
+
archives, or hashes, then keep working and collect the result later.
|
|
315
352
|
|
|
316
353
|
```js
|
|
317
354
|
const job = JSON.parse(
|
|
@@ -332,8 +369,9 @@ await tools.fs.job({ list: true }) // newest first
|
|
|
332
369
|
|
|
333
370
|
`wait` returns the original tool result once the job completes; on timeout it
|
|
334
371
|
returns the status with `timedOut: true`. Jobs are process-local and lost on
|
|
335
|
-
server restart. Status files live under `/tmp/opencode/fs-jobs/<server-pid
|
|
336
|
-
|
|
372
|
+
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.
|
|
337
375
|
|
|
338
376
|
To wait without blocking the session, combine the status file with `wait_for`.
|
|
339
377
|
Wait for any terminal state, then read the job for the result or error:
|
|
@@ -407,8 +445,8 @@ await tools.fs.cpio({ mode: "create", archive: "bundle.cpio", paths: ["dist"] })
|
|
|
407
445
|
await tools.fs.ar({ mode: "list", archive: "lib.a" })
|
|
408
446
|
|
|
409
447
|
// API call, then a verified download
|
|
410
|
-
await tools.fs.
|
|
411
|
-
await tools.fs.
|
|
448
|
+
await tools.fs.curl({ url: "https://api.github.com/repos/owner/repo/releases/latest" })
|
|
449
|
+
await tools.fs.curl({
|
|
412
450
|
url: "https://example.com/tool-1.0.0.tgz",
|
|
413
451
|
output: "tool-1.0.0.tgz",
|
|
414
452
|
checksum: "sha256:<hex>",
|
|
@@ -422,8 +460,9 @@ await tools.fs.http_request({
|
|
|
422
460
|
- Linux only; there is no Windows branch.
|
|
423
461
|
- `fs.sed` supports `s<delim>pattern<delim>replacement<delim>flags` with `g`,
|
|
424
462
|
`i` and `p`. It is not a full sed interpreter.
|
|
425
|
-
- `fs.
|
|
426
|
-
Network
|
|
463
|
+
- `fs.command` requires procage: Linux x64/arm64, glibc 2.28+, Node 22.12+.
|
|
464
|
+
Network egress needs Linux T1; elsewhere networking is disabled. External
|
|
465
|
+
paths are denied until approved.
|
|
427
466
|
- `fs.find` has no arbitrary `-exec`; use `action: "delete"`/`"trash"` for the
|
|
428
467
|
common cleanup case, or `fs.rm`/`fs.trash` separately.
|
|
429
468
|
- No `xz`, `zstd`, `7z`, `rar`, `chattr`, ACLs, xattrs, or `rsync`.
|
|
@@ -431,12 +470,12 @@ await tools.fs.http_request({
|
|
|
431
470
|
- `fs.tail` has bounded `follow` only; unbounded `tail -f` is not supported.
|
|
432
471
|
- `cp -a` preserves mode and timestamps but not ACLs or xattrs.
|
|
433
472
|
- `fs.tar`/`fs.zip` create from `input` or stdin; extraction is file-backed.
|
|
434
|
-
- `fs.
|
|
473
|
+
- `fs.curl` is HTTP(S) only: no FTP/SFTP, cookie jars, client
|
|
435
474
|
certificates, proxies, multipart uploads, or resumable downloads.
|
|
436
|
-
- Only `fs.
|
|
475
|
+
- Only `fs.command` starts processes, and only names allowed by `fs_command`; `nohup`,
|
|
437
476
|
`setsid`, and `timeout` wrappers are unavailable. `fs.kill` rejects pid 0,
|
|
438
477
|
pid 1, and process groups.
|
|
439
|
-
- No ICMP ping; use `fs.
|
|
478
|
+
- No ICMP ping; use `fs.curl` or a TCP port check. No ACL, xattr, or
|
|
440
479
|
`chattr` support. `rsync`/`scp` are out of scope; use the SSH MCP.
|
|
441
480
|
- `fs.comm` expects sorted input. `fs.ar` uses GNU short names (16 bytes max);
|
|
442
481
|
`fs.cpio` reads and writes newc only. `fs.dd` has no conversion flags.
|
|
@@ -477,12 +516,13 @@ Command actions are `fs_<command>` (for example `fs_cp`). `fs_*` wildcards work
|
|
|
477
516
|
in agent rules. `fs.pipe` asserts each stage's action; a denied stage cannot be
|
|
478
517
|
hidden inside a pipeline. Do not work around a denied tool with shell.
|
|
479
518
|
|
|
480
|
-
`
|
|
481
|
-
|
|
482
|
-
`fs_exec_network` with the
|
|
483
|
-
There
|
|
519
|
+
`fs.command` asserts `fs_command` with the executable name as its resource;
|
|
520
|
+
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.
|
|
522
|
+
There is no `*` fallback and no direct-IP mode; networking that cannot use the
|
|
523
|
+
relay is disabled. There are no per-call grants and no shell.
|
|
484
524
|
|
|
485
|
-
`
|
|
525
|
+
`fs_curl` reuses the built-in `webfetch` permission with the requested
|
|
486
526
|
URL as the resource, so one rule set covers both; each redirect hop is checked
|
|
487
527
|
against its URL. Nothing blocks localhost or private addresses by default.
|
|
488
528
|
|
package/src/core/format.ts
CHANGED
|
@@ -34,22 +34,16 @@ export function renderResult(result: ToolResult): RenderedResult {
|
|
|
34
34
|
return { content: "", metadata };
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
metadata.bytes = result.stdout.length;
|
|
38
38
|
|
|
39
39
|
if (isBinary(result.stdout)) {
|
|
40
40
|
metadata.encoding = "base64";
|
|
41
|
-
return { content:
|
|
41
|
+
return { content: result.stdout.toString("base64"), metadata };
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
let content = result.stdout.toString("utf8");
|
|
45
45
|
if (result.stderr) content += `${content.endsWith("\n") ? "" : "\n"}[stderr]\n${result.stderr}`;
|
|
46
|
-
return { content
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function spillNote(metadata: Record<string, unknown>, content: string): string {
|
|
50
|
-
const outputPath = metadata.outputPath;
|
|
51
|
-
if (typeof outputPath !== "string") return content;
|
|
52
|
-
return `${content}${content.endsWith("\n") ? "" : "\n"}[output spilled to ${outputPath}; ${String(metadata.bytes)} bytes]`;
|
|
46
|
+
return { content, metadata };
|
|
53
47
|
}
|
|
54
48
|
|
|
55
49
|
export function renderError(error: FsError, blocked: boolean): RenderedResult {
|
package/src/core/permissions.ts
CHANGED
|
@@ -46,17 +46,39 @@ export class PermissionGate {
|
|
|
46
46
|
private readonly assertPermission: PermissionAssert,
|
|
47
47
|
) {}
|
|
48
48
|
|
|
49
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* Assert an action on trusted tool-owned paths without an external gate.
|
|
51
|
+
* An empty list is a deliberate wildcard request; any other list saves its
|
|
52
|
+
* exact resources, so "allow always" never widens a specific host or path to
|
|
53
|
+
* every resource of the action.
|
|
54
|
+
*/
|
|
50
55
|
async assertTrusted(resources: readonly string[]): Promise<void> {
|
|
51
|
-
await this.assertAction(resources.length === 0 ? ["*"] : [...resources]
|
|
56
|
+
await this.assertAction(resources.length === 0 ? ["*"] : [...resources]);
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
async assert(entries: readonly PermissionEntry[]): Promise<void> {
|
|
55
60
|
if (entries.length === 0) {
|
|
56
|
-
await this.assertAction(["*"]
|
|
61
|
+
await this.assertAction(["*"]);
|
|
57
62
|
return;
|
|
58
63
|
}
|
|
59
64
|
|
|
65
|
+
await this.assertExternal(entries);
|
|
66
|
+
|
|
67
|
+
const resources = unique(
|
|
68
|
+
entries.map((entry) =>
|
|
69
|
+
entry.target.outside
|
|
70
|
+
? slash(entry.target.full)
|
|
71
|
+
: (entry.resource ?? this.sandboxResource(entry.target.full)),
|
|
72
|
+
),
|
|
73
|
+
);
|
|
74
|
+
await this.assertAction(resources);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Assert only the external_directory boundary for targets outside the
|
|
79
|
+
* project, without asserting this gate's action on their paths.
|
|
80
|
+
*/
|
|
81
|
+
async assertExternal(entries: readonly PermissionEntry[]): Promise<void> {
|
|
60
82
|
const external = entries.filter((entry) => entry.target.outside);
|
|
61
83
|
const boundaries = new Map<string, string[]>();
|
|
62
84
|
for (const entry of external) {
|
|
@@ -75,23 +97,19 @@ export class PermissionGate {
|
|
|
75
97
|
save: repoRoots.map((root) => `${slash(root)}/*`),
|
|
76
98
|
});
|
|
77
99
|
}
|
|
78
|
-
|
|
79
|
-
const resources = unique(
|
|
80
|
-
entries.map((entry) =>
|
|
81
|
-
entry.target.outside
|
|
82
|
-
? slash(entry.target.full)
|
|
83
|
-
: (entry.resource ?? this.sandboxResource(entry.target.full)),
|
|
84
|
-
),
|
|
85
|
-
);
|
|
86
|
-
await this.assertAction(resources, ["*"]);
|
|
87
100
|
}
|
|
88
101
|
|
|
89
|
-
|
|
102
|
+
/**
|
|
103
|
+
* `save` mirrors the asserted resources so a persisted "allow always" rule
|
|
104
|
+
* stays as narrow as the request. The only wildcard is the explicit `*` the
|
|
105
|
+
* caller asked for (an empty-call default or a supplied wildcard).
|
|
106
|
+
*/
|
|
107
|
+
private async assertAction(resources: string[]): Promise<void> {
|
|
90
108
|
await this.assertPermission({
|
|
91
109
|
...this.base(),
|
|
92
110
|
action: this.action,
|
|
93
111
|
resources,
|
|
94
|
-
save,
|
|
112
|
+
save: [...resources],
|
|
95
113
|
});
|
|
96
114
|
}
|
|
97
115
|
|