opencode-fs-plugin 1.4.3 → 1.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/INSTALL.md +9 -9
- package/README.md +37 -8
- package/SPEC.md +31 -0
- package/package.json +1 -1
- package/skills/filesystem/SKILL.md +34 -9
- package/src/core/errors.ts +1 -1
- package/src/core/fsutil.ts +44 -17
- package/src/core/magic.ts +51 -0
- package/src/core/procfs.ts +84 -0
- package/src/index.ts +52 -0
- package/src/tools/ar.ts +179 -0
- package/src/tools/base64.ts +63 -0
- package/src/tools/chown.ts +89 -0
- package/src/tools/comm.ts +85 -0
- package/src/tools/cpio.ts +259 -0
- package/src/tools/date.ts +61 -0
- package/src/tools/dd.ts +120 -0
- package/src/tools/file.ts +62 -0
- package/src/tools/findmnt.ts +74 -0
- package/src/tools/fold.ts +64 -0
- package/src/tools/id.ts +70 -0
- package/src/tools/kill.ts +60 -0
- package/src/tools/mountpoint.ts +57 -0
- package/src/tools/nl.ts +51 -0
- package/src/tools/od.ts +58 -0
- package/src/tools/paste.ts +78 -0
- package/src/tools/pgrep.ts +59 -0
- package/src/tools/pipe.ts +13 -1
- package/src/tools/ps.ts +88 -0
- package/src/tools/rev.ts +41 -0
- package/src/tools/shuf.ts +49 -0
- package/src/tools/split.ts +103 -0
- package/src/tools/strings.ts +57 -0
- package/src/tools/sync.ts +51 -0
- package/src/tools/tac.ts +40 -0
- package/src/tools/uname.ts +45 -0
- package/src/tools/uptime.ts +46 -0
package/INSTALL.md
CHANGED
|
@@ -17,14 +17,14 @@ Add the registry package to the plugin list:
|
|
|
17
17
|
|
|
18
18
|
```jsonc
|
|
19
19
|
{
|
|
20
|
-
"plugins": ["opencode-fs-plugin@1.
|
|
20
|
+
"plugins": ["opencode-fs-plugin@1.5.0"]
|
|
21
21
|
}
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
Or let the CLI install and configure it:
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
|
-
opencode plugin add opencode-fs-plugin@1.
|
|
27
|
+
opencode plugin add opencode-fs-plugin@1.5.0
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
A bare `opencode-fs-plugin` follows `latest`. OpenCode installs it into its
|
|
@@ -36,7 +36,7 @@ Option A if you also want the skill.
|
|
|
36
36
|
Download the release artifact and install it as a normal npm package:
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
|
-
VERSION=1.
|
|
39
|
+
VERSION=1.5.0
|
|
40
40
|
curl -L -o "opencode-fs-plugin-${VERSION}.tgz" \
|
|
41
41
|
"https://github.com/masterjg/opencode-fs-plugin/releases/download/v${VERSION}/opencode-fs-plugin-${VERSION}.tgz"
|
|
42
42
|
npm install "./opencode-fs-plugin-${VERSION}.tgz"
|
|
@@ -64,20 +64,20 @@ OpenCode installs it from Git:
|
|
|
64
64
|
|
|
65
65
|
```jsonc
|
|
66
66
|
{
|
|
67
|
-
"plugins": ["github:masterjg/opencode-fs-plugin#v1.
|
|
67
|
+
"plugins": ["github:masterjg/opencode-fs-plugin#v1.5.0"]
|
|
68
68
|
}
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
`opencode plugin add 'github:masterjg/opencode-fs-plugin#v1.
|
|
71
|
+
`opencode plugin add 'github:masterjg/opencode-fs-plugin#v1.5.0'` installs the
|
|
72
72
|
same spec and writes the entry for you. The equivalent full URL is
|
|
73
|
-
`git+https://github.com/masterjg/opencode-fs-plugin.git#v1.
|
|
73
|
+
`git+https://github.com/masterjg/opencode-fs-plugin.git#v1.5.0`. A tag is
|
|
74
74
|
checked for updates; use a full commit hash to pin it.
|
|
75
75
|
|
|
76
76
|
Git plugins are installed under OpenCode's cache, so their package path is not
|
|
77
77
|
stable. For a stable skill path, install the tag with npm instead:
|
|
78
78
|
|
|
79
79
|
```bash
|
|
80
|
-
npm install "github:masterjg/opencode-fs-plugin#v1.
|
|
80
|
+
npm install "github:masterjg/opencode-fs-plugin#v1.5.0"
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
Then configure `./node_modules/opencode-fs-plugin` in `plugins` as in the
|
|
@@ -174,9 +174,9 @@ and description until the model loads it.
|
|
|
174
174
|
To let a coding agent install the plugin, use:
|
|
175
175
|
|
|
176
176
|
```text
|
|
177
|
-
Install opencode-fs-plugin 1.
|
|
177
|
+
Install opencode-fs-plugin 1.5.0 with "npm install opencode-fs-plugin@1.5.0",
|
|
178
178
|
or from its release tarball or the Git tag
|
|
179
|
-
"github:masterjg/opencode-fs-plugin#v1.
|
|
179
|
+
"github:masterjg/opencode-fs-plugin#v1.5.0". Add
|
|
180
180
|
"./node_modules/opencode-fs-plugin" to the plugins array in opencode.jsonc, add
|
|
181
181
|
"./node_modules/opencode-fs-plugin/skills" to the skills array, then verify that
|
|
182
182
|
the filesystem skill loads with the skill tool using id "filesystem".
|
package/README.md
CHANGED
|
@@ -45,6 +45,32 @@ unit, end-to-end and coverage tests.
|
|
|
45
45
|
| `mktemp` | `fs.mktemp` | `template`, `directory`, `tmpdir`, `suffix` |
|
|
46
46
|
| `trash` | `fs.trash` | XDG home trash |
|
|
47
47
|
| `diff` | `fs.diff` | `unified`, `brief`, `recursive`, `ignoreWhitespace`, `ignoreCase`, `exclude` |
|
|
48
|
+
| `chown` | `fs.chown` | `user`/`uid`, `group`/`gid`, `recursive`, `noDereference` |
|
|
49
|
+
| `ps` | `fs.ps` | `pids`, `user`, `command`, `sortBy`, `limit`, `noHeader`, `format` |
|
|
50
|
+
| `pgrep` | `fs.pgrep` | `pattern`, `full`, `ignoreCase`, `user`, `newest`, `oldest`, `count`, `delimiter` |
|
|
51
|
+
| `kill` | `fs.kill` | `pids`, `signal`, `dryRun`; pid 0/1 and groups rejected |
|
|
52
|
+
| `file` | `fs.file` | `paths`, `mime`; content magic detection |
|
|
53
|
+
| `base64` | `fs.base64` | `decode`, `wrap`, `ignoreGarbage` |
|
|
54
|
+
| `od` | `fs.od` | `offset`, `length`, `width` |
|
|
55
|
+
| `strings` | `fs.strings` | `minLength` |
|
|
56
|
+
| `id` | `fs.id` | `only` (`user`, `group`, `groups`) |
|
|
57
|
+
| `uname` | `fs.uname` | `kernel`, `nodename`, `release`, `version`, `machine` |
|
|
58
|
+
| `uptime` | `fs.uptime` | `pretty`, `loadAverage` |
|
|
59
|
+
| `date` | `fs.date` | `value`, `utc`, `format` (`iso`, `unix`, `rfc`, `date`) |
|
|
60
|
+
| `findmnt` | `fs.findmnt` | `paths`, `fsType`, `noHeader` |
|
|
61
|
+
| `mountpoint` | `fs.mountpoint` | `paths`, `quiet` |
|
|
62
|
+
| `tac` | `fs.tac` | reverse lines |
|
|
63
|
+
| `rev` | `fs.rev` | reverse characters per line |
|
|
64
|
+
| `nl` | `fs.nl` | `all`, `start`, `width`, `separator` |
|
|
65
|
+
| `paste` | `fs.paste` | `delimiters`, `serial` |
|
|
66
|
+
| `comm` | `fs.comm` | `suppress1`/`2`/`3`, `outputDelimiter` |
|
|
67
|
+
| `split` | `fs.split` | `lines`/`bytes`, `prefix`, `suffixLength`, `numeric`, `additionalSuffix` |
|
|
68
|
+
| `shuf` | `fs.shuf` | `headCount`, `zeroTerminated` |
|
|
69
|
+
| `fold` | `fs.fold` | `width`, `spaces` |
|
|
70
|
+
| `sync` | `fs.sync` | `paths`; file/directory fsync |
|
|
71
|
+
| `dd` | `fs.dd` | `input`, `output`, `blockSize`, `count`, `skip`, `seek`, `status` |
|
|
72
|
+
| `cpio` | `fs.cpio` | `create`/`list`/`extract` (newc), `directory`, `members`, `input`, `member`, `verbose` |
|
|
73
|
+
| `ar` | `fs.ar` | `create`/`list`/`extract`, `directory`, `members` |
|
|
48
74
|
| HTTP(S) | `fs.http_request` | `url`, `method`, `headers`, `body`, `json`, `output`, `checksum`, `maxBytes`, `timeoutMs`, `failOnError`, `followRedirects`, `maxRedirects` |
|
|
49
75
|
| shell pipe | `fs.pipe` | `stages`, `input`, `output`, `append` |
|
|
50
76
|
|
|
@@ -65,6 +91,9 @@ await tools.fs.pipe({
|
|
|
65
91
|
})
|
|
66
92
|
```
|
|
67
93
|
|
|
94
|
+
New filter stages: `tac`, `rev`, `nl`, `paste`, `shuf`, `fold`, `base64`, `od`,
|
|
95
|
+
and `strings`; `dd` and `cpio` are source/sink stages like `tar`.
|
|
96
|
+
|
|
68
97
|
`fs.http_request` is a pipe source, so network data can feed the same stages:
|
|
69
98
|
|
|
70
99
|
```js
|
|
@@ -166,18 +195,18 @@ Add the registry package directly to the plugin list:
|
|
|
166
195
|
|
|
167
196
|
```jsonc
|
|
168
197
|
{
|
|
169
|
-
"plugins": ["opencode-fs-plugin@1.
|
|
198
|
+
"plugins": ["opencode-fs-plugin@1.5.0"]
|
|
170
199
|
}
|
|
171
200
|
```
|
|
172
201
|
|
|
173
|
-
`opencode plugin add opencode-fs-plugin@1.
|
|
202
|
+
`opencode plugin add opencode-fs-plugin@1.5.0` installs it and writes the config
|
|
174
203
|
entry. A bare `opencode-fs-plugin` follows the `latest` tag.
|
|
175
204
|
|
|
176
205
|
OpenCode manages the package under its cache, so the path is not stable. If you
|
|
177
206
|
also want the packaged skill, install it into a project instead:
|
|
178
207
|
|
|
179
208
|
```bash
|
|
180
|
-
npm install opencode-fs-plugin@1.
|
|
209
|
+
npm install opencode-fs-plugin@1.5.0
|
|
181
210
|
```
|
|
182
211
|
|
|
183
212
|
```jsonc
|
|
@@ -192,7 +221,7 @@ npm install opencode-fs-plugin@1.4.3
|
|
|
192
221
|
Download the release tarball, then install it as a normal npm package:
|
|
193
222
|
|
|
194
223
|
```bash
|
|
195
|
-
VERSION=1.
|
|
224
|
+
VERSION=1.5.0
|
|
196
225
|
curl -L -o "opencode-fs-plugin-${VERSION}.tgz" \
|
|
197
226
|
"https://github.com/masterjg/opencode-fs-plugin/releases/download/v${VERSION}/opencode-fs-plugin-${VERSION}.tgz"
|
|
198
227
|
npm install "./opencode-fs-plugin-${VERSION}.tgz"
|
|
@@ -221,20 +250,20 @@ OpenCode installs it from Git:
|
|
|
221
250
|
|
|
222
251
|
```jsonc
|
|
223
252
|
{
|
|
224
|
-
"plugins": ["github:masterjg/opencode-fs-plugin#v1.
|
|
253
|
+
"plugins": ["github:masterjg/opencode-fs-plugin#v1.5.0"]
|
|
225
254
|
}
|
|
226
255
|
```
|
|
227
256
|
|
|
228
|
-
`opencode plugin add 'github:masterjg/opencode-fs-plugin#v1.
|
|
257
|
+
`opencode plugin add 'github:masterjg/opencode-fs-plugin#v1.5.0'` installs the
|
|
229
258
|
same spec and writes the config entry. The equivalent full URL is
|
|
230
|
-
`git+https://github.com/masterjg/opencode-fs-plugin.git#v1.
|
|
259
|
+
`git+https://github.com/masterjg/opencode-fs-plugin.git#v1.5.0`. A tag is
|
|
231
260
|
checked for updates; use a full commit hash to pin it.
|
|
232
261
|
|
|
233
262
|
Git plugins are installed under OpenCode's cache, so their package path is not
|
|
234
263
|
stable. If you also want the packaged skill, install with npm instead:
|
|
235
264
|
|
|
236
265
|
```bash
|
|
237
|
-
npm install "github:masterjg/opencode-fs-plugin#v1.
|
|
266
|
+
npm install "github:masterjg/opencode-fs-plugin#v1.5.0"
|
|
238
267
|
```
|
|
239
268
|
|
|
240
269
|
Then use `./node_modules/opencode-fs-plugin` in `plugins` and
|
package/SPEC.md
CHANGED
|
@@ -32,6 +32,29 @@ the `fs` namespace (`tools.fs.cp`, direct `fs_cp`).
|
|
|
32
32
|
- Results stay in memory and are returned by `fs.job`; status files contain only
|
|
33
33
|
state and metadata. Permission checks still apply to background work.
|
|
34
34
|
|
|
35
|
+
## Batch 1 tools
|
|
36
|
+
|
|
37
|
+
- `ps`, `pgrep`, and `kill` read `/proc` and use `process.kill`; no process can
|
|
38
|
+
be started or wrapped, so `nohup`, `setsid`, and `timeout` are out of scope.
|
|
39
|
+
- `kill` rejects pid 0, pid 1, and negative process groups.
|
|
40
|
+
- `file` reads the first 1 KiB and detects ELF, images, archives, compression,
|
|
41
|
+
SQLite, wasm, text, and generic data.
|
|
42
|
+
- `base64` encodes with optional wrapping and validates decoded input; decoded
|
|
43
|
+
bytes may be binary and are base64-encoded again by the renderer.
|
|
44
|
+
- `od` is an xxd-style hex/ASCII dump with offset, length, and width.
|
|
45
|
+
- `strings` extracts printable ASCII runs.
|
|
46
|
+
- `id`, `uname`, `uptime`, `date`, `findmnt`, and `mountpoint` read OS data;
|
|
47
|
+
`findmnt` parses `/proc/self/mountinfo`.
|
|
48
|
+
- `tac`, `rev`, `nl`, `paste`, `comm`, `split`, `shuf`, and `fold` cover text
|
|
49
|
+
primitives that `pipe` could not express. `comm` expects sorted input.
|
|
50
|
+
- `chown` uses `fs.chown`/`fs.lchown`, accepts names or ids, and walks
|
|
51
|
+
recursively with the shared concurrency limit.
|
|
52
|
+
- `sync` calls `fsync` per path; Node has no global sync syscall.
|
|
53
|
+
- `dd` supports `bs`, `count`, `skip`, `seek`, and `status`; it does not
|
|
54
|
+
implement conversions or `iflag`/`oflag`.
|
|
55
|
+
- `cpio` reads and writes newc archives; `ar` uses GNU short names (max 16 bytes).
|
|
56
|
+
Both reject traversal and unsafe member names.
|
|
57
|
+
|
|
35
58
|
## HTTP requests
|
|
36
59
|
|
|
37
60
|
- `fs.http_request` supports `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, and `HEAD`
|
|
@@ -65,6 +88,14 @@ These are not implemented:
|
|
|
65
88
|
- true streaming through pipe stages; `http_request` buffers unless `output` is set
|
|
66
89
|
- worker threads for CPU-bound stages (`sort`, `sed`, text diffing)
|
|
67
90
|
- parallel member reads inside a single `tar`/`zip` archive; member order is fixed
|
|
91
|
+
- process start, `nohup`, `setsid`, and `timeout` wrappers; the plugin never
|
|
92
|
+
uses `child_process`
|
|
93
|
+
- ICMP `ping` (raw sockets) and `ip`/netlink configuration
|
|
94
|
+
- `rsync`, `scp`, and other transfer protocols; use the SSH MCP for remote work
|
|
95
|
+
- ACLs, xattrs, and `chattr`/`lsattr`
|
|
96
|
+
- `awk`, full `jq`/`yq`, and the remaining `sed` command language
|
|
97
|
+
- `7z`, `rar`, `xz`, `zstd`, and `bzip2`; batch 2 may add pure-JS or native deps
|
|
98
|
+
- `fallocate`, `mkfifo`, `mknod`, `flock`, and mount operations
|
|
68
99
|
|
|
69
100
|
## Format details
|
|
70
101
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: Filesystem
|
|
3
|
-
description: Use when a task needs Linux-style filesystem, text, or
|
|
3
|
+
description: Use when a task needs Linux-style filesystem, text, network, process, or system operations beyond OpenCode's built-ins - copy, move, metadata, permissions, ownership, touch, truncate, symlinks, chmod/chown, hashes, disk usage, find, archives (tar/zip/cpio/ar), comparing files or directories, process listing and signals, system info, binary inspection, text primitives, HTTP(S) requests, API calls, or file downloads (curl replacement), trash, background jobs, or composing filters through a pipe. Covers the fs namespace, argument shapes, native options, permissions, limits, and verification.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Filesystem
|
|
@@ -46,12 +46,18 @@ what `fs.stat`, `fs.ls`, `fs.hash`, `fs.diff`, or `fs.cat` can confirm.
|
|
|
46
46
|
| Links and modes | `fs.ln`, `fs.readlink`, `fs.chmod` |
|
|
47
47
|
| Hash, usage | `fs.hash`, `fs.du`, `fs.df` |
|
|
48
48
|
| Predicate search | `fs.find` (`name`, `type`, `size`, `mtime`, `maxDepth`) |
|
|
49
|
-
| Archives | `fs.tar` (`create`/`extract`/`list`), `fs.zip`, `fs.unzip` (`extract`/`list`), `fs.gzip`, `fs.gunzip` |
|
|
49
|
+
| Archives | `fs.tar` (`create`/`extract`/`list`), `fs.zip`, `fs.unzip` (`extract`/`list`), `fs.cpio`, `fs.ar`, `fs.gzip`, `fs.gunzip` |
|
|
50
50
|
| Compare | `fs.diff` |
|
|
51
51
|
| Temp and trash | `fs.mktemp`, `fs.trash` |
|
|
52
|
-
| Text filters | `fs.cat`, `fs.head`, `fs.tail`, `fs.grep`, `fs.sed`, `fs.sort`, `fs.uniq`, `fs.cut`, `fs.tr`, `fs.wc`, `fs.tee` |
|
|
52
|
+
| 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` |
|
|
53
53
|
| Compose filters | `fs.pipe` |
|
|
54
54
|
| HTTP(S) | `fs.http_request` (`output`, `checksum`, `maxBytes`, `json`) |
|
|
55
|
+
| Processes | `fs.ps`, `fs.pgrep`, `fs.kill` (`dryRun` available) |
|
|
56
|
+
| System info | `fs.id`, `fs.uname`, `fs.uptime`, `fs.date`, `fs.findmnt`, `fs.mountpoint` |
|
|
57
|
+
| Binary inspection | `fs.file`, `fs.base64`, `fs.od`, `fs.strings` |
|
|
58
|
+
| Ownership | `fs.chown` (names or ids, `recursive`) |
|
|
59
|
+
| Block I/O | `fs.dd` (`blockSize`, `count`, `skip`, `seek`, `status`), `fs.sync` |
|
|
60
|
+
| cpio / ar | `fs.cpio`, `fs.ar` (`create`/`list`/`extract`) |
|
|
55
61
|
| Background jobs | `background: true`, then `fs.job` |
|
|
56
62
|
|
|
57
63
|
Recent parity additions:
|
|
@@ -75,11 +81,14 @@ the tool run with defaults (often `.`), not fail.
|
|
|
75
81
|
|---|---|
|
|
76
82
|
| `path` | `fs.mkdir` |
|
|
77
83
|
| `sources` + `destination` | `fs.cp`, `fs.mv`, `fs.ln` |
|
|
78
|
-
| `paths` | `fs.stat`, `fs.ls`, `fs.find`, `fs.rm`, `fs.rmdir`, `fs.touch`, `fs.truncate`, `fs.chmod`, `fs.readlink`, `fs.du`, `fs.df`, `fs.cat`, `fs.head`, `fs.tail`, `fs.tee`, `fs.wc`, `fs.sort`, `fs.uniq`, `fs.cut`, `fs.tr`, `fs.grep`, `fs.sed`, `fs.gzip`, `fs.gunzip`, `fs.trash` |
|
|
84
|
+
| `paths` | `fs.stat`, `fs.ls`, `fs.find`, `fs.rm`, `fs.rmdir`, `fs.touch`, `fs.truncate`, `fs.chmod`, `fs.chown`, `fs.readlink`, `fs.du`, `fs.df`, `fs.cat`, `fs.head`, `fs.tail`, `fs.tee`, `fs.wc`, `fs.sort`, `fs.uniq`, `fs.cut`, `fs.tr`, `fs.grep`, `fs.sed`, `fs.gzip`, `fs.gunzip`, `fs.trash`, `fs.file`, `fs.base64`, `fs.od`, `fs.strings`, `fs.sync`, `fs.mountpoint`, `fs.tac`, `fs.rev`, `fs.nl`, `fs.fold`, `fs.shuf` |
|
|
85
|
+
| `pids` | `fs.ps`, `fs.kill` |
|
|
86
|
+
| `pattern` | `fs.pgrep` |
|
|
79
87
|
| `files` | `fs.hash` |
|
|
80
|
-
| `left` + `right` | `fs.diff` |
|
|
81
|
-
| `archive` + `paths` | `fs.tar` create, `fs.zip` create |
|
|
82
|
-
| `archive` + `mode` | `fs.tar` (`create`/`extract`/`list`), `fs.unzip` (`extract`/`list`) |
|
|
88
|
+
| `left` + `right` | `fs.diff`, `fs.comm` |
|
|
89
|
+
| `archive` + `paths` | `fs.tar` create, `fs.zip` create, `fs.cpio` create, `fs.ar` create |
|
|
90
|
+
| `archive` + `mode` | `fs.tar`, `fs.cpio`, `fs.ar` (`create`/`extract`/`list`), `fs.unzip` (`extract`/`list`) |
|
|
91
|
+
| `input` + `output` | `fs.dd` (`blockSize`, `count`, `skip`, `seek`) |
|
|
83
92
|
| `content` | `fs.tee` when there is no stdin |
|
|
84
93
|
| `paths` + optional `keep`/`force`/`stdout`/`level`/`suffix` | `fs.gzip`, `fs.gunzip` |
|
|
85
94
|
| `url` + optional `output` | `fs.http_request` |
|
|
@@ -107,6 +116,9 @@ redirection operator, nested pipe, or `find -exec`. A filter stage needs
|
|
|
107
116
|
`input` or a preceding source stage. Set `grep.noFilename: true` in a pipe when
|
|
108
117
|
later stages need bare lines instead of `path:line`.
|
|
109
118
|
|
|
119
|
+
New filter stages: `tac`, `rev`, `nl`, `paste`, `shuf`, `fold`, `base64`, `od`,
|
|
120
|
+
and `strings`. `dd` and `cpio` are source/sink stages.
|
|
121
|
+
|
|
110
122
|
`http_request` is a source stage. Pipe stages exchange whole buffers, so set
|
|
111
123
|
`maxBytes` for large responses; use `output` for real streaming to disk.
|
|
112
124
|
|
|
@@ -217,8 +229,9 @@ permissions; loops do not bypass them. Code Mode has no timers, so use
|
|
|
217
229
|
|
|
218
230
|
All `fs` I/O is asynchronous. Independent work is parallelized automatically
|
|
219
231
|
within each call, up to `os.availableParallelism()`: tree copies, hashing,
|
|
220
|
-
gzip/gunzip, grep reads, `find`/`du`/`grep -r`/`chmod -R` traversal,
|
|
221
|
-
|
|
232
|
+
gzip/gunzip, grep reads, `find`/`du`/`grep -r`/`chmod -R`/`chown -R` traversal,
|
|
233
|
+
`diff -r`, `ls` formatting, `ps` /proc scans, and `split` writes. Do not add
|
|
234
|
+
your own concurrency for those.
|
|
222
235
|
|
|
223
236
|
The limit comes from the plugin `concurrency` option or
|
|
224
237
|
`OPENCODE_FS_CONCURRENCY`. CPU-bound `sort`, `sed`, and text diffing stay
|
|
@@ -247,6 +260,12 @@ await tools.fs.unzip({ archive: "bundle.zip", mode: "list" })
|
|
|
247
260
|
// compare two files
|
|
248
261
|
await tools.fs.diff({ left: "old.txt", right: "new.txt", unified: 3 })
|
|
249
262
|
|
|
263
|
+
// processes, binaries and archives
|
|
264
|
+
await tools.fs.ps({ command: "node", sortBy: "rss", limit: 5 })
|
|
265
|
+
await tools.fs.file({ paths: ["dist/app"] })
|
|
266
|
+
await tools.fs.cpio({ mode: "create", archive: "bundle.cpio", paths: ["dist"] })
|
|
267
|
+
await tools.fs.ar({ mode: "list", archive: "lib.a" })
|
|
268
|
+
|
|
250
269
|
// API call, then a verified download
|
|
251
270
|
await tools.fs.http_request({ url: "https://api.github.com/repos/owner/repo/releases/latest" })
|
|
252
271
|
await tools.fs.http_request({
|
|
@@ -270,6 +289,12 @@ await tools.fs.http_request({
|
|
|
270
289
|
- `fs.tar`/`fs.zip` create from `input` or stdin; extraction is file-backed.
|
|
271
290
|
- `fs.http_request` is HTTP(S) only: no FTP/SFTP, cookie jars, client
|
|
272
291
|
certificates, proxies, multipart uploads, or resumable downloads.
|
|
292
|
+
- No process can be started or wrapped: `nohup`, `setsid`, and `timeout` are
|
|
293
|
+
unavailable, and `fs.kill` rejects pid 0, pid 1, and process groups.
|
|
294
|
+
- No ICMP ping; use `fs.http_request` or a TCP port check. No ACL, xattr, or
|
|
295
|
+
`chattr` support. `rsync`/`scp` are out of scope; use the SSH MCP.
|
|
296
|
+
- `fs.comm` expects sorted input. `fs.ar` uses GNU short names (16 bytes max);
|
|
297
|
+
`fs.cpio` reads and writes newc only. `fs.dd` has no conversion flags.
|
|
273
298
|
- `fs.tar` resolves `paths` even when `directory` is set; pass absolute sources
|
|
274
299
|
with `directory` or the member path may not be found.
|
|
275
300
|
- `fs.du` reports allocated blocks like `du`; use `fs.stat` with `%s` for
|
package/src/core/errors.ts
CHANGED
|
@@ -60,7 +60,7 @@ export function isPermission(error: unknown): boolean {
|
|
|
60
60
|
export function fromErrno(error: unknown, fallback: FsErrorCode = "io"): FsError {
|
|
61
61
|
const code = errnoCode(error);
|
|
62
62
|
const message = errorMessage(error);
|
|
63
|
-
if (code === "ENOENT" || code === "ENOTDIR") {
|
|
63
|
+
if (code === "ENOENT" || code === "ENOTDIR" || code === "ESRCH") {
|
|
64
64
|
return new FsError(message, "not-found");
|
|
65
65
|
}
|
|
66
66
|
if (code === "EACCES" || code === "EPERM") {
|
package/src/core/fsutil.ts
CHANGED
|
@@ -246,26 +246,53 @@ export async function lookupGroup(gid: number): Promise<string> {
|
|
|
246
246
|
return (await lookupId("/etc/group", gid)) ?? String(gid);
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
-
|
|
249
|
+
interface IdTable {
|
|
250
|
+
readonly byId: Map<number, string>;
|
|
251
|
+
readonly byName: Map<string, number>;
|
|
252
|
+
}
|
|
250
253
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
254
|
+
const idTables = new Map<string, IdTable>();
|
|
255
|
+
|
|
256
|
+
async function loadIds(file: string): Promise<IdTable | undefined> {
|
|
257
|
+
const cached = idTables.get(file);
|
|
258
|
+
if (cached !== undefined) return cached;
|
|
259
|
+
let text: string;
|
|
260
|
+
try {
|
|
261
|
+
text = await fs.readFile(file, "utf8");
|
|
262
|
+
} catch {
|
|
263
|
+
/* v8 ignore next */
|
|
264
|
+
return undefined;
|
|
265
|
+
}
|
|
266
|
+
const table: IdTable = { byId: new Map(), byName: new Map() };
|
|
267
|
+
for (const line of text.split("\n")) {
|
|
268
|
+
const fields = line.split(":");
|
|
269
|
+
if (fields.length >= 3) {
|
|
270
|
+
const id = Number(fields[2]);
|
|
271
|
+
const name = fields[0] as string;
|
|
272
|
+
table.byId.set(id, name);
|
|
273
|
+
table.byName.set(name, id);
|
|
265
274
|
}
|
|
266
|
-
idCaches.set(file, cache);
|
|
267
275
|
}
|
|
268
|
-
|
|
276
|
+
idTables.set(file, table);
|
|
277
|
+
return table;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
async function lookupId(file: string, id: number): Promise<string | undefined> {
|
|
281
|
+
return (await loadIds(file))?.byId.get(id);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export async function resolveUid(value: string): Promise<number> {
|
|
285
|
+
if (/^\d+$/.test(value)) return Number(value);
|
|
286
|
+
const id = (await loadIds("/etc/passwd"))?.byName.get(value);
|
|
287
|
+
if (id === undefined) throw new FsError(`Unknown user: "${value}".`, "invalid");
|
|
288
|
+
return id;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export async function resolveGid(value: string): Promise<number> {
|
|
292
|
+
if (/^\d+$/.test(value)) return Number(value);
|
|
293
|
+
const id = (await loadIds("/etc/group"))?.byName.get(value);
|
|
294
|
+
if (id === undefined) throw new FsError(`Unknown group: "${value}".`, "invalid");
|
|
295
|
+
return id;
|
|
269
296
|
}
|
|
270
297
|
|
|
271
298
|
export function formatDate(date: Date, now = new Date()): string {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SPDX-License-Identifier: EPL-2.0
|
|
3
|
+
* license-wizard managed-header v1 EPL-2.0 short 73897e75828f
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface FileType {
|
|
7
|
+
readonly description: string;
|
|
8
|
+
readonly mime: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const MAGIC: ReadonlyArray<{ readonly bytes: readonly number[]; readonly type: FileType }> = [
|
|
12
|
+
{ bytes: [0x7f, 0x45, 0x4c, 0x46], type: { description: "ELF executable", mime: "application/x-elf" } },
|
|
13
|
+
{ bytes: [0x89, 0x50, 0x4e, 0x47], type: { description: "PNG image data", mime: "image/png" } },
|
|
14
|
+
{ bytes: [0xff, 0xd8, 0xff], type: { description: "JPEG image data", mime: "image/jpeg" } },
|
|
15
|
+
{ bytes: [0x47, 0x49, 0x46, 0x38], type: { description: "GIF image data", mime: "image/gif" } },
|
|
16
|
+
{ bytes: [0x25, 0x50, 0x44, 0x46, 0x2d], type: { description: "PDF document", mime: "application/pdf" } },
|
|
17
|
+
{ bytes: [0x1f, 0x8b], type: { description: "gzip compressed data", mime: "application/gzip" } },
|
|
18
|
+
{ bytes: [0x42, 0x5a, 0x68], type: { description: "bzip2 compressed data", mime: "application/x-bzip2" } },
|
|
19
|
+
{ bytes: [0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00], type: { description: "XZ compressed data", mime: "application/x-xz" } },
|
|
20
|
+
{ bytes: [0x28, 0xb5, 0x2f, 0xfd], type: { description: "Zstandard compressed data", mime: "application/zstd" } },
|
|
21
|
+
{ bytes: [0x50, 0x4b, 0x03, 0x04], type: { description: "Zip archive data", mime: "application/zip" } },
|
|
22
|
+
{ bytes: [0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c], type: { description: "7-zip archive data", mime: "application/x-7z-compressed" } },
|
|
23
|
+
{ bytes: [0x52, 0x61, 0x72, 0x21], type: { description: "RAR archive data", mime: "application/vnd.rar" } },
|
|
24
|
+
{ bytes: [0x53, 0x51, 0x4c, 0x69, 0x74, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x20, 0x33, 0x00], type: { description: "SQLite 3 database", mime: "application/vnd.sqlite3" } },
|
|
25
|
+
{ bytes: [0x00, 0x61, 0x73, 0x6d], type: { description: "WebAssembly binary module", mime: "application/wasm" } },
|
|
26
|
+
{ bytes: [0x30, 0x37, 0x30, 0x37, 0x30, 0x31], type: { description: "ASCII cpio archive", mime: "application/x-cpio" } },
|
|
27
|
+
{ bytes: [0x21, 0x3c, 0x61, 0x72, 0x63, 0x68, 0x3e, 0x0a], type: { description: "current ar archive", mime: "application/x-ar" } },
|
|
28
|
+
{ bytes: [0x4d, 0x5a], type: { description: "PE executable", mime: "application/vnd.microsoft.portable-executable" } },
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
export function detectFileType(data: Buffer): FileType {
|
|
32
|
+
if (data.length === 0) return { description: "empty", mime: "inode/x-empty" };
|
|
33
|
+
for (const entry of MAGIC) {
|
|
34
|
+
if (data.length >= entry.bytes.length && entry.bytes.every((byte, index) => data[index] === byte)) {
|
|
35
|
+
return entry.type;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (data.length >= 262 && data.subarray(257, 262).toString("latin1") === "ustar") {
|
|
39
|
+
return { description: "POSIX tar archive", mime: "application/x-tar" };
|
|
40
|
+
}
|
|
41
|
+
if (!data.includes(0)) {
|
|
42
|
+
const text = data.toString("utf8");
|
|
43
|
+
if (!text.includes("\uFFFD")) {
|
|
44
|
+
const ascii = data.every((byte) => byte < 0x80);
|
|
45
|
+
return ascii
|
|
46
|
+
? { description: "ASCII text", mime: "text/plain" }
|
|
47
|
+
: { description: "UTF-8 Unicode text", mime: "text/plain; charset=utf-8" };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return { description: "data", mime: "application/octet-stream" };
|
|
51
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SPDX-License-Identifier: EPL-2.0
|
|
3
|
+
* license-wizard managed-header v1 EPL-2.0 short 73897e75828f
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import * as fs from "node:fs/promises";
|
|
7
|
+
import { mapLimit } from "./parallel.js";
|
|
8
|
+
|
|
9
|
+
export interface ProcessInfo {
|
|
10
|
+
readonly pid: number;
|
|
11
|
+
readonly ppid: number;
|
|
12
|
+
readonly comm: string;
|
|
13
|
+
readonly state: string;
|
|
14
|
+
readonly uid: number;
|
|
15
|
+
readonly rssBytes: number;
|
|
16
|
+
readonly startTime: number;
|
|
17
|
+
readonly threads: number;
|
|
18
|
+
readonly command: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Read `/proc` with bounded parallelism; vanished processes are skipped. */
|
|
22
|
+
export async function listProcesses(concurrency: number, signal?: AbortSignal): Promise<ProcessInfo[]> {
|
|
23
|
+
const entries = await fs.readdir("/proc");
|
|
24
|
+
const pids = entries.filter((name) => /^\d+$/.test(name)).map(Number);
|
|
25
|
+
const rows = await mapLimit(
|
|
26
|
+
pids,
|
|
27
|
+
Math.max(1, concurrency),
|
|
28
|
+
(pid) => readProcess(pid),
|
|
29
|
+
signal,
|
|
30
|
+
);
|
|
31
|
+
return rows.filter((row): row is ProcessInfo => row !== undefined);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function readProcess(pid: number): Promise<ProcessInfo | undefined> {
|
|
35
|
+
const base = `/proc/${pid}`;
|
|
36
|
+
const [statText, cmdline, stats] = await Promise.all([
|
|
37
|
+
fs.readFile(`${base}/stat`, "utf8").catch(() => undefined),
|
|
38
|
+
fs.readFile(`${base}/cmdline`).catch(() => undefined),
|
|
39
|
+
fs.stat(base).catch(() => undefined),
|
|
40
|
+
]);
|
|
41
|
+
if (statText === undefined || stats === undefined) return undefined;
|
|
42
|
+
return parseStat(pid, statText, cmdline, stats.uid);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function parseStat(
|
|
46
|
+
pid: number,
|
|
47
|
+
text: string,
|
|
48
|
+
cmdline: Buffer | undefined,
|
|
49
|
+
uid: number,
|
|
50
|
+
): ProcessInfo | undefined {
|
|
51
|
+
const open = text.indexOf("(");
|
|
52
|
+
const close = text.lastIndexOf(")");
|
|
53
|
+
if (open < 0 || close < open) return undefined;
|
|
54
|
+
const comm = text.slice(open + 1, close);
|
|
55
|
+
const tail = text.slice(close + 2).trim().split(/\s+/);
|
|
56
|
+
if (tail.length < 22) return undefined;
|
|
57
|
+
const command = cmdline === undefined
|
|
58
|
+
? comm
|
|
59
|
+
: cmdline.toString("utf8").split("\0").filter(Boolean).join(" ") || comm;
|
|
60
|
+
return {
|
|
61
|
+
pid,
|
|
62
|
+
ppid: Number(tail[1]),
|
|
63
|
+
comm,
|
|
64
|
+
state: tail[0] as string,
|
|
65
|
+
uid,
|
|
66
|
+
rssBytes: Number(tail[21]) * 4096,
|
|
67
|
+
startTime: Number(tail[19]),
|
|
68
|
+
threads: Number(tail[17]),
|
|
69
|
+
command,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const SIGNALS: Readonly<Record<string, NodeJS.Signals>> = {
|
|
74
|
+
HUP: "SIGHUP",
|
|
75
|
+
INT: "SIGINT",
|
|
76
|
+
QUIT: "SIGQUIT",
|
|
77
|
+
KILL: "SIGKILL",
|
|
78
|
+
TERM: "SIGTERM",
|
|
79
|
+
USR1: "SIGUSR1",
|
|
80
|
+
USR2: "SIGUSR2",
|
|
81
|
+
STOP: "SIGSTOP",
|
|
82
|
+
CONT: "SIGCONT",
|
|
83
|
+
CHLD: "SIGCHLD",
|
|
84
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -14,31 +14,55 @@ import { clampConcurrency } from "./core/parallel.js";
|
|
|
14
14
|
import { Sandbox } from "./core/sandbox.js";
|
|
15
15
|
import { parseSchema } from "./core/schema.js";
|
|
16
16
|
import type { ToolSpec } from "./core/types.js";
|
|
17
|
+
import { arTool } from "./tools/ar.js";
|
|
18
|
+
import { base64Tool } from "./tools/base64.js";
|
|
17
19
|
import { catTool } from "./tools/cat.js";
|
|
18
20
|
import { chmodTool } from "./tools/chmod.js";
|
|
21
|
+
import { chownTool } from "./tools/chown.js";
|
|
22
|
+
import { commTool } from "./tools/comm.js";
|
|
19
23
|
import { cpTool } from "./tools/cp.js";
|
|
24
|
+
import { cpioTool } from "./tools/cpio.js";
|
|
20
25
|
import { cutTool } from "./tools/cut.js";
|
|
26
|
+
import { dateTool } from "./tools/date.js";
|
|
27
|
+
import { ddTool } from "./tools/dd.js";
|
|
21
28
|
import { dfTool } from "./tools/df.js";
|
|
22
29
|
import { diffTool } from "./tools/diff.js";
|
|
23
30
|
import { duTool } from "./tools/du.js";
|
|
31
|
+
import { fileTool } from "./tools/file.js";
|
|
24
32
|
import { findTool } from "./tools/find.js";
|
|
33
|
+
import { findmntTool } from "./tools/findmnt.js";
|
|
34
|
+
import { foldTool } from "./tools/fold.js";
|
|
25
35
|
import { grepTool } from "./tools/grep.js";
|
|
26
36
|
import { gunzipTool, gzipTool } from "./tools/gzip.js";
|
|
27
37
|
import { hashTool } from "./tools/hash.js";
|
|
28
38
|
import { headTool } from "./tools/head.js";
|
|
29
39
|
import { httpRequestTool } from "./tools/http_request.js";
|
|
40
|
+
import { idTool } from "./tools/id.js";
|
|
41
|
+
import { killTool } from "./tools/kill.js";
|
|
30
42
|
import { lnTool } from "./tools/ln.js";
|
|
31
43
|
import { lsTool } from "./tools/ls.js";
|
|
32
44
|
import { mkdirTool } from "./tools/mkdir.js";
|
|
33
45
|
import { mktempTool } from "./tools/mktemp.js";
|
|
46
|
+
import { mountpointTool } from "./tools/mountpoint.js";
|
|
34
47
|
import { mvTool } from "./tools/mv.js";
|
|
48
|
+
import { nlTool } from "./tools/nl.js";
|
|
49
|
+
import { odTool } from "./tools/od.js";
|
|
50
|
+
import { pasteTool } from "./tools/paste.js";
|
|
51
|
+
import { pgrepTool } from "./tools/pgrep.js";
|
|
35
52
|
import { pipeTool } from "./tools/pipe.js";
|
|
53
|
+
import { psTool } from "./tools/ps.js";
|
|
36
54
|
import { readlinkTool } from "./tools/readlink.js";
|
|
55
|
+
import { revTool } from "./tools/rev.js";
|
|
37
56
|
import { rmTool } from "./tools/rm.js";
|
|
38
57
|
import { rmdirTool } from "./tools/rmdir.js";
|
|
39
58
|
import { sedTool } from "./tools/sed.js";
|
|
59
|
+
import { shufTool } from "./tools/shuf.js";
|
|
40
60
|
import { sortTool } from "./tools/sort.js";
|
|
61
|
+
import { splitTool } from "./tools/split.js";
|
|
41
62
|
import { statTool } from "./tools/stat.js";
|
|
63
|
+
import { stringsTool } from "./tools/strings.js";
|
|
64
|
+
import { syncTool } from "./tools/sync.js";
|
|
65
|
+
import { tacTool } from "./tools/tac.js";
|
|
42
66
|
import { tailTool } from "./tools/tail.js";
|
|
43
67
|
import { tarTool } from "./tools/tar.js";
|
|
44
68
|
import { teeTool } from "./tools/tee.js";
|
|
@@ -46,7 +70,9 @@ import { touchTool } from "./tools/touch.js";
|
|
|
46
70
|
import { trTool } from "./tools/tr.js";
|
|
47
71
|
import { trashTool } from "./tools/trash.js";
|
|
48
72
|
import { truncateTool } from "./tools/truncate.js";
|
|
73
|
+
import { unameTool } from "./tools/uname.js";
|
|
49
74
|
import { uniqTool } from "./tools/uniq.js";
|
|
75
|
+
import { uptimeTool } from "./tools/uptime.js";
|
|
50
76
|
import { wcTool } from "./tools/wc.js";
|
|
51
77
|
import { unzipTool, zipTool } from "./tools/zip.js";
|
|
52
78
|
|
|
@@ -82,6 +108,32 @@ const TOOLS: readonly AnyTool[] = [
|
|
|
82
108
|
tailTool,
|
|
83
109
|
teeTool,
|
|
84
110
|
httpRequestTool,
|
|
111
|
+
psTool,
|
|
112
|
+
pgrepTool,
|
|
113
|
+
killTool,
|
|
114
|
+
fileTool,
|
|
115
|
+
base64Tool,
|
|
116
|
+
odTool,
|
|
117
|
+
stringsTool,
|
|
118
|
+
idTool,
|
|
119
|
+
unameTool,
|
|
120
|
+
uptimeTool,
|
|
121
|
+
dateTool,
|
|
122
|
+
findmntTool,
|
|
123
|
+
mountpointTool,
|
|
124
|
+
tacTool,
|
|
125
|
+
revTool,
|
|
126
|
+
nlTool,
|
|
127
|
+
pasteTool,
|
|
128
|
+
commTool,
|
|
129
|
+
splitTool,
|
|
130
|
+
shufTool,
|
|
131
|
+
foldTool,
|
|
132
|
+
chownTool,
|
|
133
|
+
syncTool,
|
|
134
|
+
ddTool,
|
|
135
|
+
cpioTool,
|
|
136
|
+
arTool,
|
|
85
137
|
wcTool,
|
|
86
138
|
sortTool,
|
|
87
139
|
uniqTool,
|