opencode-fs-plugin 1.1.0 → 1.2.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 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.1.0"]
20
+ "plugins": ["opencode-fs-plugin@1.2.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.1.0
27
+ opencode plugin add opencode-fs-plugin@1.2.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.1.0
39
+ VERSION=1.2.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.1.0"]
67
+ "plugins": ["github:masterjg/opencode-fs-plugin#v1.2.0"]
68
68
  }
69
69
  ```
70
70
 
71
- `opencode plugin add 'github:masterjg/opencode-fs-plugin#v1.1.0'` installs the
71
+ `opencode plugin add 'github:masterjg/opencode-fs-plugin#v1.2.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.1.0`. A tag is
73
+ `git+https://github.com/masterjg/opencode-fs-plugin.git#v1.2.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.1.0"
80
+ npm install "github:masterjg/opencode-fs-plugin#v1.2.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.1.0 with "npm install opencode-fs-plugin@1.1.0",
177
+ Install opencode-fs-plugin 1.2.0 with "npm install opencode-fs-plugin@1.2.0",
178
178
  or from its release tarball or the Git tag
179
- "github:masterjg/opencode-fs-plugin#v1.1.0". Add
179
+ "github:masterjg/opencode-fs-plugin#v1.2.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
@@ -15,8 +15,8 @@ unit, end-to-end and coverage tests.
15
15
  | `rm` | `fs.rm` | `recursive`, `force`, `dir`, `verbose` |
16
16
  | `cp` | `fs.cp` | `recursive`, `archive`, `force`, `noClobber`, `update`, `preserve`, `dereference`, `verbose` |
17
17
  | `mv` | `fs.mv` | `force`, `noClobber`, `update`, `verbose` |
18
- | `ls` | `fs.ls` | `all`, `almostAll`, `long`, `human`, `recursive`, `directory`, `inode`, `classify`, `sortBy`, `reverse`, `onePerLine` |
19
- | `stat` | `fs.stat` | `follow`, `format`, `filesystem` |
18
+ | `ls` | `fs.ls` | `all`, `almostAll`, `long`, `human`, `recursive`, `directory`, `inode`, `classify`, `size`, `numericIds`, `noGroup`, `noOwner`, `slash`, `quote`, `versionSort`, `extensionSort`, `fullTime`, `timeStyle`, `hide`, `ignore`, `groupDirectoriesFirst`, `sortBy`, `reverse`, `onePerLine` |
19
+ | `stat` | `fs.stat` | `follow`, `format`, `terse`, `filesystem` |
20
20
  | `touch` | `fs.touch` | `accessOnly`, `modifyOnly`, `noCreate`, `date`, `timestamp`, `reference`, `noDereference` |
21
21
  | `truncate` | `fs.truncate` | `size`, `reference`, `noCreate`, `noDereference` |
22
22
  | `ln` | `fs.ln` | `symbolic`, `force`, `noDereference`, `relative`, `verbose` |
@@ -25,20 +25,20 @@ unit, end-to-end and coverage tests.
25
25
  | `sha256sum`/`md5sum` | `fs.hash` | `algorithm`, `tag`; hashes files or stdin |
26
26
  | `du` | `fs.du` | `summarize`, `all`, `human`, `total`, `maxDepth`, `follow`, `oneFileSystem` |
27
27
  | `df` | `fs.df` | `human`, `inodes`, `printType`, `all` |
28
- | `find` | `fs.find` | `name`, `iname`, `pathPattern`, `type`, `size`, `mtime`, `mmin`, `maxDepth`, `minDepth`, `empty`, `perm`, `newer`, `follow`, `print0`, `sort` |
28
+ | `find` | `fs.find` | `name`, `iname`, `pathPattern`, `lname`, `ilname`, `regex`, `iregex`, `type`, `size`, `mtime`, `mmin`, `maxDepth`, `minDepth`, `empty`, `perm`, `uid`, `gid`, `user`, `group`, `links`, `inum`, `samefile`, `fstype`, `newer`, `newerXY`, `printf`, `follow`, `print0`, `sort` |
29
29
  | `cat` | `fs.cat` | `number`, `numberNonBlank`, `squeezeBlank`, `showEnds`, `showTabs`, `showNonPrinting` |
30
30
  | `head` | `fs.head` | `lines`, `bytes`, `quiet`, `verbose` |
31
- | `tail` | `fs.tail` | `lines`, `bytes`, `fromStart`, `quiet`, `verbose` |
31
+ | `tail` | `fs.tail` | `lines`, `bytes`, `fromStart`, `quiet`, `verbose`, `follow`, `timeoutMs`, `intervalMs`, `maxBytes` |
32
32
  | `tee` | `fs.tee` | `append`, `content` |
33
33
  | `wc` | `fs.wc` | `lines`, `words`, `bytes`, `chars`, `maxLineLength` |
34
- | `sort` | `fs.sort` | `numeric`, `reverse`, `unique`, `ignoreCase`, `ignoreLeadingBlanks`, `field`, `separator` |
34
+ | `sort` | `fs.sort` | `numeric`, `generalNumeric`, `humanNumeric`, `version`, `reverse`, `unique`, `ignoreCase`, `dictionary`, `ignoreNonPrinting`, `ignoreLeadingBlanks`, `stable`, `check`, `checkQuiet`, `zeroTerminated`, `keys`, `field`, `separator` |
35
35
  | `uniq` | `fs.uniq` | `count`, `repeated`, `uniqueOnly`, `ignoreCase`, `skipFields`, `skipChars` |
36
36
  | `cut` | `fs.cut` | `fields`, `characters`, `bytes`, `delimiter`, `outputDelimiter`, `complement`, `onlyDelimited` |
37
37
  | `tr` | `fs.tr` | `set1`, `set2`, `delete`, `squeeze`, `complement`; ranges and classes |
38
38
  | `sed` | `fs.sed` | `script`, `expressions`, `inPlace`, `extendedRegexp`, `quiet`; `s///` subset |
39
39
  | `grep` | `fs.grep` | `recursive`, `include`, `exclude`, `ignoreCase`, `invert`, `lineNumbers`, `withFilename`, `noFilename`, `filesWithMatches`, `filesWithoutMatch`, `count`, `onlyMatching`, `word`, `line`, `fixed`, `context`, `before`, `after`, `maxCount`, `noMessages` |
40
- | `tar` | `fs.tar` | `create`/`extract`/`list`, `gzip`, `directory`, `stripComponents`, `exclude`, `verbose` |
41
- | `zip` | `fs.zip` | `archive`, `paths`, `level` |
40
+ | `tar` | `fs.tar` | `create`/`extract`/`list`, `gzip`, `directory`, `stripComponents`, `exclude`, `verbose`, `input`, `member` |
41
+ | `zip` | `fs.zip` | `archive`, `paths`, `level`, `input`, `member` |
42
42
  | `unzip` | `fs.unzip` | `extract`/`list`, `directory`, `overwrite`, `noOverwrite` |
43
43
  | `gzip` | `fs.gzip` | `keep`, `force`, `stdout`, `level` |
44
44
  | `gunzip` | `fs.gunzip` | `keep`, `force`, `stdout`, `suffix` |
@@ -127,18 +127,18 @@ Add the registry package directly to the plugin list:
127
127
 
128
128
  ```jsonc
129
129
  {
130
- "plugins": ["opencode-fs-plugin@1.1.0"]
130
+ "plugins": ["opencode-fs-plugin@1.2.0"]
131
131
  }
132
132
  ```
133
133
 
134
- `opencode plugin add opencode-fs-plugin@1.1.0` installs it and writes the config
134
+ `opencode plugin add opencode-fs-plugin@1.2.0` installs it and writes the config
135
135
  entry. A bare `opencode-fs-plugin` follows the `latest` tag.
136
136
 
137
137
  OpenCode manages the package under its cache, so the path is not stable. If you
138
138
  also want the packaged skill, install it into a project instead:
139
139
 
140
140
  ```bash
141
- npm install opencode-fs-plugin@1.1.0
141
+ npm install opencode-fs-plugin@1.2.0
142
142
  ```
143
143
 
144
144
  ```jsonc
@@ -153,7 +153,7 @@ npm install opencode-fs-plugin@1.1.0
153
153
  Download the release tarball, then install it as a normal npm package:
154
154
 
155
155
  ```bash
156
- VERSION=1.1.0
156
+ VERSION=1.2.0
157
157
  curl -L -o "opencode-fs-plugin-${VERSION}.tgz" \
158
158
  "https://github.com/masterjg/opencode-fs-plugin/releases/download/v${VERSION}/opencode-fs-plugin-${VERSION}.tgz"
159
159
  npm install "./opencode-fs-plugin-${VERSION}.tgz"
@@ -182,20 +182,20 @@ OpenCode installs it from Git:
182
182
 
183
183
  ```jsonc
184
184
  {
185
- "plugins": ["github:masterjg/opencode-fs-plugin#v1.1.0"]
185
+ "plugins": ["github:masterjg/opencode-fs-plugin#v1.2.0"]
186
186
  }
187
187
  ```
188
188
 
189
- `opencode plugin add 'github:masterjg/opencode-fs-plugin#v1.1.0'` installs the
189
+ `opencode plugin add 'github:masterjg/opencode-fs-plugin#v1.2.0'` installs the
190
190
  same spec and writes the config entry. The equivalent full URL is
191
- `git+https://github.com/masterjg/opencode-fs-plugin.git#v1.1.0`. A tag is
191
+ `git+https://github.com/masterjg/opencode-fs-plugin.git#v1.2.0`. A tag is
192
192
  checked for updates; use a full commit hash to pin it.
193
193
 
194
194
  Git plugins are installed under OpenCode's cache, so their package path is not
195
195
  stable. If you also want the packaged skill, install with npm instead:
196
196
 
197
197
  ```bash
198
- npm install "github:masterjg/opencode-fs-plugin#v1.1.0"
198
+ npm install "github:masterjg/opencode-fs-plugin#v1.2.0"
199
199
  ```
200
200
 
201
201
  Then use `./node_modules/opencode-fs-plugin` in `plugins` and
package/SPEC.md CHANGED
@@ -30,23 +30,27 @@ the `fs` namespace (`tools.fs.cp`, direct `fs_cp`).
30
30
  These are not implemented:
31
31
 
32
32
  - `xz`, `zstd`, `7z`, `rar`
33
- - `awk`, full `sed` command language, `find -exec`, `tail -f`
33
+ - `awk`, full `sed` command language, `find -exec`
34
34
  - `chown`, `chgrp`, `chattr`, `dd`, `rsync`
35
35
  - ACL and xattr preservation in `cp -a`
36
- - full GNU edge-flag parity for `ls`, `stat`, `sort`, `find`
36
+ - remaining GNU edge-flag parity for `ls`, `stat`, `sort`, `find`
37
37
  - symlink-race-proof sandboxing
38
- - `tar`/`zip` creation from arbitrary streams; archives are file-backed
38
+ - unbounded `tail -f`; use bounded `follow` or the wait plugin
39
+ - archive extraction from arbitrary streams; create accepts text/stdin stream input
39
40
  - cross-filesystem `trash`; use `rm` or a mount-trash helper
40
41
 
41
42
  ## Format details
42
43
 
43
- - `stat` supports `%n %N %s %F %a %A %u %U %g %G %d %i %h %b %B %o %x %X %y
44
- %Y %z %Z %t %T %L`, plus `\n`, `\t`, `\\` and `%%`.
44
+ - `stat` supports `%n %N %s %F %a %A %f %u %U %g %G %d %i %h %b %B %o %m %r
45
+ %x %X %y %Y %z %Z %w %W %t %T %C %L`, plus `\n`, `\t`, `\\` and `%%`.
46
+ `%C` returns `?` because Node does not expose the SELinux file context.
45
47
  - `chmod` supports octal modes and symbolic `[ugoa]*[-+=][rwxXst]*` clauses.
46
48
  - `find -size` uses binary suffixes (`K`, `M`, `G`, ...); `-mtime`/`-mmin`
47
- accept `+N` (older), `-N` (newer), and exact `N`.
49
+ accept `+N` (older), `-N` (newer), and exact `N`. `newerXY` uses `XY:path`.
50
+ - `sort -k` accepts field/character ranges with modifiers `bdfghiMnrV`.
48
51
  - `tar`/`zip` extraction rejects path traversal and escaping links.
49
- - `pipe` passes raw bytes and only accepts registered pipeable stages.
52
+ - `pipe` passes raw bytes and only accepts registered pipeable stages; `tar` and
53
+ `zip` are sink stages.
50
54
 
51
55
  ## Coverage policy
52
56
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-fs-plugin",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "description": "OpenCode 2 plugin: Linux-style filesystem and text tools under the fs namespace.",
6
6
  "repository": {
@@ -24,10 +24,15 @@ 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
+ | Batching or loops | `execute` JS loops over `tools.fs.*` |
27
28
 
28
29
  Do not duplicate a built-in when it already covers the job. `fs` exists for the
29
30
  operations the built-ins do not cover, and for composable text/archive work.
30
31
 
32
+ Use the `fs` tool for both the operation and its verification. Do not route an
33
+ `fs` operation through a shell or `toolbox.run`, and do not use shell to check
34
+ what `fs.stat`, `fs.ls`, `fs.hash`, `fs.diff`, or `fs.cat` can confirm.
35
+
31
36
  ## Command map
32
37
 
33
38
  | Need | Command |
@@ -40,13 +45,18 @@ operations the built-ins do not cover, and for composable text/archive work.
40
45
  | Links and modes | `fs.ln`, `fs.readlink`, `fs.chmod` |
41
46
  | Hash, usage | `fs.hash`, `fs.du`, `fs.df` |
42
47
  | Predicate search | `fs.find` (`name`, `type`, `size`, `mtime`, `maxDepth`) |
43
- | Archives | `fs.tar`, `fs.zip`, `fs.unzip`, `fs.gzip`, `fs.gunzip` |
48
+ | Archives | `fs.tar` (`create`/`extract`/`list`), `fs.zip`, `fs.unzip` (`extract`/`list`), `fs.gzip`, `fs.gunzip` |
44
49
  | Compare | `fs.diff` |
45
50
  | Temp and trash | `fs.mktemp`, `fs.trash` |
46
51
  | Text filters | `fs.cat`, `fs.head`, `fs.tail`, `fs.grep`, `fs.sed`, `fs.sort`, `fs.uniq`, `fs.cut`, `fs.tr`, `fs.wc`, `fs.tee` |
47
52
  | Compose filters | `fs.pipe` |
48
53
  | Background jobs | `background: true`, then `fs.job` |
49
54
 
55
+ Parity additions: `fs.sort` accepts GNU key ranges (`keys: ["2,2n"]`);
56
+ `fs.find` adds `lname`/`regex`/owner/link/inode/fstype/`newerXY`/`printf`;
57
+ `fs.ls` and `fs.stat` add more GNU flags and format tokens; `fs.tail` has
58
+ bounded `follow`; `fs.tar`/`fs.zip` accept `input`/`member` and pipe stdin.
59
+
50
60
  ## Argument shapes
51
61
 
52
62
  Use the exact field names; scalar `path` is only valid for `fs.mkdir`.
@@ -59,7 +69,8 @@ Use the exact field names; scalar `path` is only valid for `fs.mkdir`.
59
69
  | `files` | `fs.hash` |
60
70
  | `left` + `right` | `fs.diff` |
61
71
  | `archive` + `paths` | `fs.tar` create, `fs.zip` create |
62
- | `archive` + `mode` | `fs.tar`, `fs.unzip` |
72
+ | `archive` + `mode` | `fs.tar` (`create`/`extract`/`list`), `fs.unzip` (`extract`/`list`) |
73
+ | `content` | `fs.tee` when there is no stdin |
63
74
  | `stages` + optional `input`/`output` | `fs.pipe` |
64
75
 
65
76
  ## Pipe
@@ -111,15 +122,72 @@ returns the status with `timedOut: true`. Jobs are process-local and lost on
111
122
  server restart. Status files live under `/tmp/opencode/fs-jobs/<server-pid>/`;
112
123
  eight jobs may run at once and finished jobs are cleaned after one hour.
113
124
 
114
- To wait without blocking the session, combine the status file with `wait_for`:
125
+ To wait without blocking the session, combine the status file with `wait_for`.
126
+ Wait for any terminal state, then read the job for the result or error:
115
127
 
116
128
  ```js
117
129
  await tools.wait.for({
118
- condition: { type: "file_contains", path: job.statusPath, pattern: '"state":"completed"' },
130
+ condition: {
131
+ type: "file_contains",
132
+ path: job.statusPath,
133
+ pattern: '"state":"(completed|failed|cancelled)"',
134
+ regex: true,
135
+ },
119
136
  timeoutMs: 600000,
137
+ intervalMs: 500,
120
138
  })
139
+ const status = JSON.parse(await tools.fs.job({ id: job.jobId }))
121
140
  ```
122
141
 
142
+ A job that produces no text returns empty content from `fs.job wait`; verify the
143
+ effect with `fs.stat`, `fs.ls`, or `fs.diff`, and use `fs.job({ id })` for state.
144
+
145
+ ## Loops and batching
146
+
147
+ `execute` is always available and is the orchestration layer for every `fs` tool.
148
+ Use ordinary JavaScript for iteration, conditionals, retries, and parallel calls.
149
+ Do not use a shell or `toolbox.run` for batching.
150
+
151
+ Sequential is the safe default for writes, destructive work, ordering, and
152
+ permission prompts:
153
+
154
+ ```js
155
+ const files = (
156
+ await tools.fs.find({
157
+ paths: ["src"],
158
+ name: "*.sh",
159
+ type: "f",
160
+ print0: true,
161
+ })
162
+ ).split("\0").filter(Boolean)
163
+
164
+ for (const file of files) {
165
+ await tools.fs.chmod({ paths: [file], mode: "640" })
166
+ }
167
+ ```
168
+
169
+ Use `Promise.all` only for independent work. It rejects on the first failure
170
+ while the other calls continue, so prefer `Promise.allSettled` when partial
171
+ results are useful. Bound concurrency to about 4–8:
172
+
173
+ ```js
174
+ async function mapLimit(items, limit, fn) {
175
+ const results = []
176
+ for (let i = 0; i < items.length; i += limit) {
177
+ results.push(...(await Promise.all(items.slice(i, i + limit).map(fn))))
178
+ }
179
+ return results
180
+ }
181
+
182
+ const stats = await mapLimit(files, 4, (file) =>
183
+ tools.fs.stat({ paths: [file], format: "%n %s" }),
184
+ )
185
+ ```
186
+
187
+ Each call still enforces its own `fs_<tool>` and `external_directory`
188
+ permissions; loops do not bypass them. Code Mode has no timers, so use
189
+ `wait_for` for time-based waits and `background: true` for long jobs.
190
+
123
191
  ## Recipes
124
192
 
125
193
  ```js
@@ -134,9 +202,11 @@ await tools.fs.ls({ paths: ["dist"], long: true, human: true })
134
202
  await tools.fs.find({ paths: ["."], name: "*.log", size: "+10M" })
135
203
  await tools.fs.trash({ paths: ["old.log"] })
136
204
 
137
- // create and extract an archive
205
+ // create, list, and extract an archive
138
206
  await tools.fs.tar({ mode: "create", archive: "dist.tgz", paths: ["dist"], gzip: true })
207
+ await tools.fs.tar({ mode: "list", archive: "dist.tgz" })
139
208
  await tools.fs.tar({ mode: "extract", archive: "dist.tgz", directory: "out" })
209
+ await tools.fs.unzip({ archive: "bundle.zip", mode: "list" })
140
210
 
141
211
  // compare two files
142
212
  await tools.fs.diff({ left: "old.txt", right: "new.txt", unified: 3 })
@@ -152,7 +222,13 @@ await tools.fs.diff({ left: "old.txt", right: "new.txt", unified: 3 })
152
222
  - `fs.tail` has no follow mode; `fs.diff` compares files/directories only.
153
223
  - `cp -a` preserves mode and timestamps but not ACLs or xattrs.
154
224
  - `fs.tar`/`fs.zip` are file-backed; they are not pipe stages.
225
+ - `fs.tar` resolves `paths` even when `directory` is set; pass absolute sources
226
+ with `directory` or the member path may not be found.
227
+ - `fs.du` reports allocated blocks like `du`; use `fs.stat` with `%s` for
228
+ apparent file bytes.
155
229
  - `fs.trash` uses the XDG home trash only and refuses cross-device moves.
230
+ Files under `/tmp` are usually on another filesystem; use a project path or a
231
+ same-filesystem holding directory instead.
156
232
  - `fs.mktemp` uses the OS temp directory unless `tmpdir` is supplied.
157
233
 
158
234
  ## Paths and safety
@@ -181,11 +257,13 @@ hidden inside a pipeline. Do not work around a denied tool with shell.
181
257
  - `fs.grep` with no matches and `fs.diff` with differences return exit code 1;
182
258
  that is a result, not a tool failure.
183
259
  - Binary output is returned as base64 when no `output` file is supplied.
260
+ - Tools that produce no text (`cp`, `mv`, `rm`, `touch`, `chmod`, `sed -i`) return
261
+ empty content; verify the effect with `fs.stat`, `fs.ls`, or `fs.diff`.
184
262
  - Invalid arguments return `ERROR: Invalid ...`; fix the field names or option
185
263
  values rather than retrying the same call.
186
264
 
187
265
  ## Verification
188
266
 
189
267
  Use `fs.stat`, `fs.ls`, `fs.hash`, `fs.cat`, or `fs.diff` to confirm the result.
190
- Report the tool result, such as `copied: 1`, `found: 2`, or
191
- `differences: true`.
268
+ Do not verify with a shell command. Report the tool result or the verified state,
269
+ such as `copied: 1`, `found: 2`, or `differences: true`.
package/src/tools/du.ts CHANGED
@@ -50,7 +50,7 @@ export const duTool: ToolSpec<Input> = {
50
50
  : await ctx.sandbox.lstat(target.full, requested);
51
51
  const rootDev = num(rootStats.dev);
52
52
  const seen = new Set<string>();
53
- let total = usage(target.full, rootStats, seen);
53
+ let total = usage(rootStats, seen);
54
54
  const local: Row[] = [];
55
55
  if (input.all === true && !rootStats.isDirectory()) {
56
56
  local.push({ path: requested, bytes: total });
@@ -65,7 +65,7 @@ export const duTool: ToolSpec<Input> = {
65
65
  })) {
66
66
  /* v8 ignore next */
67
67
  if (input.oneFileSystem === true && num(entry.stats.dev) !== rootDev) continue;
68
- const bytes = usage(entry.path, entry.stats, seen);
68
+ const bytes = usage(entry.stats, seen);
69
69
  total += bytes;
70
70
  if (input.all === true || entry.stats.isDirectory()) {
71
71
  local.push({ path: entry.path, bytes });
@@ -89,14 +89,12 @@ export const duTool: ToolSpec<Input> = {
89
89
  },
90
90
  };
91
91
 
92
- function usage(path: string, stats: Awaited<ReturnType<typeof fs.lstat>>, seen: Set<string>): number {
93
- /* v8 ignore next */
94
- if (!stats.isFile()) return stats.isDirectory() ? num(stats.blocks) * 512 : 0;
95
- if (num(stats.nlink) > 1) {
92
+ function usage(stats: Awaited<ReturnType<typeof fs.lstat>>, seen: Set<string>): number {
93
+ if (!stats.isDirectory() && num(stats.nlink) > 1) {
96
94
  const key = `${num(stats.dev)}:${num(stats.ino)}`;
97
95
  /* v8 ignore next */
98
96
  if (seen.has(key)) return 0;
99
97
  seen.add(key);
100
98
  }
101
- return num(stats.size);
99
+ return num(stats.blocks) * 512;
102
100
  }