opencode-fs-plugin 1.10.0 → 1.10.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 +23 -9
- package/SPEC.md +8 -2
- package/package.json +1 -1
- package/skills/filesystem/SKILL.md +8 -4
- package/src/tools/exec.ts +50 -12
package/README.md
CHANGED
|
@@ -143,7 +143,9 @@ The workspace (project) is read/write/exec, but **network and external paths are
|
|
|
143
143
|
denied by default**. There are no per-call grants: when the sandbox blocks a
|
|
144
144
|
path or a socket, `fs.exec` asks the matching permission and retries the run.
|
|
145
145
|
|
|
146
|
-
- blocked path → `external_directory` for the
|
|
146
|
+
- blocked path → `external_directory` for its containing directory; the sandbox
|
|
147
|
+
then grants read/write there. A missing or `***`-redacted path resolves to the
|
|
148
|
+
nearest existing ancestor.
|
|
147
149
|
- blocked socket → `fs_exec_network`
|
|
148
150
|
|
|
149
151
|
The decision comes from your `opencode.jsonc` rules (`ask`, `allow`, `deny`), the
|
|
@@ -151,6 +153,13 @@ same as every other tool. If a path is still blocked after approval, the result
|
|
|
151
153
|
reports `violations` and a `hint`. `fs.exec` also kills every process it started
|
|
152
154
|
when the run ends, including detached descendants.
|
|
153
155
|
|
|
156
|
+
With network enabled, the policy also opens the resolver sockets used by
|
|
157
|
+
systemd-resolved, nscd, and SSSD (`/run/systemd/resolve`, `/run/nscd`,
|
|
158
|
+
`/var/lib/sss/pipes`), so DNS works across common Linux distributions. Plain
|
|
159
|
+
UDP DNS needs none of them; other Unix sockets stay blocked. On kernels where
|
|
160
|
+
procage cannot scope Unix sockets (T2 below Landlock ABI 9), the policy drops
|
|
161
|
+
them via `no-unix-sockets`; DNS then works only through a plain UDP resolver.
|
|
162
|
+
|
|
154
163
|
```js
|
|
155
164
|
await tools.fs.exec({ command: "npm", args: ["install"], timeoutMs: 300000 })
|
|
156
165
|
```
|
|
@@ -259,18 +268,18 @@ Add the registry package directly to the plugin list:
|
|
|
259
268
|
|
|
260
269
|
```jsonc
|
|
261
270
|
{
|
|
262
|
-
"plugins": ["opencode-fs-plugin@1.10.
|
|
271
|
+
"plugins": ["opencode-fs-plugin@1.10.1"]
|
|
263
272
|
}
|
|
264
273
|
```
|
|
265
274
|
|
|
266
|
-
`opencode plugin add opencode-fs-plugin@1.10.
|
|
275
|
+
`opencode plugin add opencode-fs-plugin@1.10.1` installs it and writes the config
|
|
267
276
|
entry. A bare `opencode-fs-plugin` follows the `latest` tag.
|
|
268
277
|
|
|
269
278
|
OpenCode manages the package under its cache, so the path is not stable. If you
|
|
270
279
|
also want the packaged skill, install it into a project instead:
|
|
271
280
|
|
|
272
281
|
```bash
|
|
273
|
-
npm install opencode-fs-plugin@1.10.
|
|
282
|
+
npm install opencode-fs-plugin@1.10.1
|
|
274
283
|
```
|
|
275
284
|
|
|
276
285
|
```jsonc
|
|
@@ -285,7 +294,7 @@ npm install opencode-fs-plugin@1.10.0
|
|
|
285
294
|
Download the release tarball, then install it as a normal npm package:
|
|
286
295
|
|
|
287
296
|
```bash
|
|
288
|
-
VERSION=1.10.
|
|
297
|
+
VERSION=1.10.1
|
|
289
298
|
curl -L -o "opencode-fs-plugin-${VERSION}.tgz" \
|
|
290
299
|
"https://github.com/masterjg/opencode-fs-plugin/releases/download/v${VERSION}/opencode-fs-plugin-${VERSION}.tgz"
|
|
291
300
|
npm install "./opencode-fs-plugin-${VERSION}.tgz"
|
|
@@ -314,20 +323,20 @@ OpenCode installs it from Git:
|
|
|
314
323
|
|
|
315
324
|
```jsonc
|
|
316
325
|
{
|
|
317
|
-
"plugins": ["github:masterjg/opencode-fs-plugin#v1.10.
|
|
326
|
+
"plugins": ["github:masterjg/opencode-fs-plugin#v1.10.1"]
|
|
318
327
|
}
|
|
319
328
|
```
|
|
320
329
|
|
|
321
|
-
`opencode plugin add 'github:masterjg/opencode-fs-plugin#v1.10.
|
|
330
|
+
`opencode plugin add 'github:masterjg/opencode-fs-plugin#v1.10.1'` installs the
|
|
322
331
|
same spec and writes the config entry. The equivalent full URL is
|
|
323
|
-
`git+https://github.com/masterjg/opencode-fs-plugin.git#v1.10.
|
|
332
|
+
`git+https://github.com/masterjg/opencode-fs-plugin.git#v1.10.1`. A tag is
|
|
324
333
|
checked for updates; use a full commit hash to pin it.
|
|
325
334
|
|
|
326
335
|
Git plugins are installed under OpenCode's cache, so their package path is not
|
|
327
336
|
stable. If you also want the packaged skill, install with npm instead:
|
|
328
337
|
|
|
329
338
|
```bash
|
|
330
|
-
npm install "github:masterjg/opencode-fs-plugin#v1.10.
|
|
339
|
+
npm install "github:masterjg/opencode-fs-plugin#v1.10.1"
|
|
331
340
|
```
|
|
332
341
|
|
|
333
342
|
Then use `./node_modules/opencode-fs-plugin` in `plugins` and
|
|
@@ -397,6 +406,11 @@ blocked path and `fs_exec_network` for blocked sockets before retrying:
|
|
|
397
406
|
}
|
|
398
407
|
```
|
|
399
408
|
|
|
409
|
+
Keep both rules explicit. Plugin actions match OpenCode's base
|
|
410
|
+
`{ "action": "*", "resource": "*", "effect": "allow" }` rule, so an unlisted
|
|
411
|
+
`fs_exec_network` or `external_directory` resource is allowed without a prompt,
|
|
412
|
+
not asked.
|
|
413
|
+
|
|
400
414
|
`fs.http_request` is allowed by default, like `fetch`. Its resource is the
|
|
401
415
|
request host (`example.com:8443`), so requests can be restricted per host:
|
|
402
416
|
|
package/SPEC.md
CHANGED
|
@@ -88,9 +88,15 @@ Aliases are accepted only where noted: `path` for one `paths` element (`stat`,
|
|
|
88
88
|
- The policy is procage `agent_workspace` v3: the project is read/write/exec.
|
|
89
89
|
Network and external paths are denied by default; there are no per-call
|
|
90
90
|
grants.
|
|
91
|
+
- When network is enabled, the policy is `ip` (IPv4/IPv6) plus the resolver
|
|
92
|
+
sockets used by systemd-resolved, nscd, and SSSD. Plain UDP DNS needs none;
|
|
93
|
+
other Unix sockets stay blocked. Landlock ignores paths absent on the host.
|
|
94
|
+
On T2 below Landlock ABI 9 the sockets cannot be scoped, so the
|
|
95
|
+
`no-unix-sockets` relaxation drops them and only UDP DNS remains.
|
|
91
96
|
- Denied access is handled by asserting the configured permission and retrying,
|
|
92
|
-
bounded to six attempts: a blocked path asks `external_directory` on
|
|
93
|
-
|
|
97
|
+
bounded to six attempts: a blocked path asks `external_directory` on its
|
|
98
|
+
containing directory (or the nearest existing ancestor for a missing or
|
|
99
|
+
redacted path), a blocked socket asks `fs_exec_network`. The `allow`/`ask`/`deny`
|
|
94
100
|
decision comes from `opencode.jsonc`, not from the tool call.
|
|
95
101
|
- If a path or socket stays blocked after approval, the result reports
|
|
96
102
|
`violations` plus a `hint`; stderr containing EACCES/EPERM/EROFS marks
|
package/package.json
CHANGED
|
@@ -165,10 +165,14 @@ socket, then retries; the decision comes from `opencode.jsonc`:
|
|
|
165
165
|
await tools.fs.exec({ command: "npm", args: ["install"], timeoutMs: 300000 })
|
|
166
166
|
```
|
|
167
167
|
|
|
168
|
-
Denied access returns `violations` and a `hint`;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
168
|
+
Denied access returns `violations` and a `hint`; approval covers the denied
|
|
169
|
+
path's containing directory (or nearest existing ancestor), and a path still
|
|
170
|
+
blocked after approval is reported. With network approved, DNS works through the
|
|
171
|
+
systemd-resolved, nscd, or SSSD sockets where the kernel can scope them; other
|
|
172
|
+
Unix sockets stay blocked and plain UDP DNS works everywhere.
|
|
173
|
+
`command` is a bare name, `args` are literal, and `cwd` is sandboxed. Direct
|
|
174
|
+
calls return JSON with `exitCode`/`stdout`/`stderr` and violations; in `fs.pipe`
|
|
175
|
+
the stage passes raw stdout.
|
|
172
176
|
|
|
173
177
|
```js
|
|
174
178
|
await tools.fs.pipe({
|
package/src/tools/exec.ts
CHANGED
|
@@ -48,12 +48,26 @@ const Schema = Type.Object(
|
|
|
48
48
|
|
|
49
49
|
type Input = Static<typeof Schema>;
|
|
50
50
|
|
|
51
|
-
interface PolicyDocument {
|
|
51
|
+
export interface PolicyDocument {
|
|
52
52
|
fs: Array<{ access: string; target: { subpath: string } }>;
|
|
53
53
|
net: string;
|
|
54
|
+
ipc: { unix_sockets: string[] };
|
|
54
55
|
[key: string]: unknown;
|
|
55
56
|
}
|
|
56
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Sockets used by the name-service resolvers on common Linux systems:
|
|
60
|
+
* systemd-resolved, nscd, and SSSD. Plain glibc/musl DNS over UDP needs none.
|
|
61
|
+
* Landlock ignores paths that do not exist on the host.
|
|
62
|
+
*/
|
|
63
|
+
export const RESOLVER_SOCKETS = ["/run/systemd/resolve", "/run/nscd", "/var/lib/sss/pipes"] as const;
|
|
64
|
+
|
|
65
|
+
/** Set the network mode, plus the resolver sockets it needs. */
|
|
66
|
+
export function applyNetworkPolicy(doc: PolicyDocument, network: boolean): void {
|
|
67
|
+
doc.net = network ? "ip" : "none";
|
|
68
|
+
if (network) doc.ipc.unix_sockets = [...RESOLVER_SOCKETS];
|
|
69
|
+
}
|
|
70
|
+
|
|
57
71
|
export interface ExecOutcome {
|
|
58
72
|
stdout: Buffer;
|
|
59
73
|
stderr: Buffer;
|
|
@@ -138,10 +152,17 @@ export const execTool: ToolSpec<Input> = {
|
|
|
138
152
|
|
|
139
153
|
let added = false;
|
|
140
154
|
for (const candidate of deniedPaths) {
|
|
141
|
-
const target = await ctx
|
|
155
|
+
const target = await existingBoundary(ctx, candidate);
|
|
142
156
|
if (target === undefined) continue;
|
|
143
|
-
|
|
144
|
-
|
|
157
|
+
/* v8 ignore next */
|
|
158
|
+
const stats = await ctx.sandbox.stat(target.full, candidate).catch(() => undefined);
|
|
159
|
+
/* v8 ignore next */
|
|
160
|
+
if (stats === undefined) continue;
|
|
161
|
+
const boundary = stats.isDirectory() ? target.full : path.dirname(target.full);
|
|
162
|
+
const dirTarget = await ctx.sandbox.resolveExisting(boundary, { allowRoot: true });
|
|
163
|
+
if (approved.some((entry) => entry.full === dirTarget.full)) continue;
|
|
164
|
+
await ctx.permission.assert([{ target: dirTarget, boundary: dirTarget.full }]);
|
|
165
|
+
approved.push({ full: dirTarget.full });
|
|
145
166
|
added = true;
|
|
146
167
|
}
|
|
147
168
|
if (!added) break;
|
|
@@ -218,7 +239,7 @@ async function runCaged(ctx: RunContext, input: CagedInput): Promise<ExecOutcome
|
|
|
218
239
|
}
|
|
219
240
|
|
|
220
241
|
const doc = api.Policy.preset("agent_workspace", 3, { workspace: ctx.sandbox.root }).toJSON() as PolicyDocument;
|
|
221
|
-
doc
|
|
242
|
+
applyNetworkPolicy(doc, input.network);
|
|
222
243
|
addRule(doc, "exec", path.dirname(input.executable.path));
|
|
223
244
|
addRule(doc, "exec", path.dirname(input.executable.real));
|
|
224
245
|
addRule(doc, "exec", path.dirname(process.execPath));
|
|
@@ -245,7 +266,7 @@ async function runCaged(ctx: RunContext, input: CagedInput): Promise<ExecOutcome
|
|
|
245
266
|
cage = new api.Cage(policy, {
|
|
246
267
|
violations: true,
|
|
247
268
|
acceptSpawnSnapshot: true,
|
|
248
|
-
relax: ["waive:trust-handoff", "signals-same-user"],
|
|
269
|
+
relax: ["waive:trust-handoff", "signals-same-user", "no-unix-sockets"],
|
|
249
270
|
});
|
|
250
271
|
} catch (error) {
|
|
251
272
|
/* v8 ignore next */
|
|
@@ -314,6 +335,23 @@ async function runCaged(ctx: RunContext, input: CagedInput): Promise<ExecOutcome
|
|
|
314
335
|
}
|
|
315
336
|
}
|
|
316
337
|
|
|
338
|
+
/**
|
|
339
|
+
* Resolve a denied path to the nearest existing ancestor, so a missing
|
|
340
|
+
* directory or a redacted temp name still yields an approvable boundary.
|
|
341
|
+
* The filesystem root is never exposed.
|
|
342
|
+
*/
|
|
343
|
+
async function existingBoundary(ctx: RunContext, candidate: string) {
|
|
344
|
+
let current = candidate;
|
|
345
|
+
for (;;) {
|
|
346
|
+
/* v8 ignore next */
|
|
347
|
+
const target = await ctx.sandbox.resolveExisting(current, { allowRoot: true }).catch(() => undefined);
|
|
348
|
+
if (target !== undefined) {
|
|
349
|
+
return target.full === path.parse(target.full).root ? undefined : target;
|
|
350
|
+
}
|
|
351
|
+
current = path.dirname(current);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
317
355
|
function addRule(doc: PolicyDocument, access: string, target: string): void {
|
|
318
356
|
const subpath = path.resolve(target);
|
|
319
357
|
if (doc.fs.some((rule) => rule.access === access && rule.target.subpath === subpath)) return;
|
|
@@ -345,12 +383,11 @@ export function discoverExternalPaths(ctx: RunContext, outcome: ExecOutcome): st
|
|
|
345
383
|
}
|
|
346
384
|
|
|
347
385
|
const stderr = outcome.stderr.toString("utf8");
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
found.add(match[1]!);
|
|
386
|
+
if (/EACCES|EPERM|EROFS|Permission denied|Read-only file system|error writing|not written|cannot open|failed to open/i.test(stderr)) {
|
|
387
|
+
for (const line of stderr.split("\n")) {
|
|
388
|
+
for (const match of line.matchAll(/(?:^|[\s'"`(])(\/[^\s'"`),]+)/g)) {
|
|
389
|
+
found.add(match[1]!);
|
|
390
|
+
}
|
|
354
391
|
}
|
|
355
392
|
}
|
|
356
393
|
for (const match of stderr.matchAll(/path:\s*['"]([^'"]+)['"]/g)) {
|
|
@@ -360,6 +397,7 @@ export function discoverExternalPaths(ctx: RunContext, outcome: ExecOutcome): st
|
|
|
360
397
|
const root = ctx.sandbox.root;
|
|
361
398
|
return [...found]
|
|
362
399
|
.map((candidate) => path.resolve(candidate))
|
|
400
|
+
.map((candidate) => candidate.replace(/\/\*+$/, ""))
|
|
363
401
|
.filter((candidate) => candidate !== root && !candidate.startsWith(`${root}${path.sep}`))
|
|
364
402
|
.filter((candidate, index, all) => all.indexOf(candidate) === index);
|
|
365
403
|
}
|