dsh-extra-paths 0.2.1 → 0.3.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 +189 -28
- package/README.zh.md +163 -21
- package/lib/argv.js +96 -24
- package/lib/argv.js.map +1 -1
- package/lib/client.js +1169 -467
- package/lib/config.js +140 -44
- package/lib/config.js.map +1 -1
- package/lib/context.js +48 -12
- package/lib/context.js.map +1 -1
- package/lib/denial.js +132 -0
- package/lib/denial.js.map +1 -0
- package/lib/index.js +40 -5
- package/lib/index.js.map +1 -1
- package/lib/name-rule.js +217 -0
- package/lib/name-rule.js.map +1 -0
- package/lib/paths.js +155 -27
- package/lib/paths.js.map +1 -1
- package/lib/pattern.js +128 -62
- package/lib/pattern.js.map +1 -1
- package/lib/platform.js +325 -0
- package/lib/platform.js.map +1 -0
- package/lib/preview.js +47 -20
- package/lib/preview.js.map +1 -1
- package/lib/resolve.js +345 -64
- package/lib/resolve.js.map +1 -1
- package/lib/schema.js +19 -6
- package/lib/schema.js.map +1 -1
- package/lib/shell-dialect.js +92 -0
- package/lib/shell-dialect.js.map +1 -0
- package/lib/tool-guard.js +214 -0
- package/lib/tool-guard.js.map +1 -0
- package/lib/types/argv.d.ts +50 -12
- package/lib/types/config.d.ts +29 -13
- package/lib/types/context.d.ts +6 -1
- package/lib/types/denial.d.ts +88 -0
- package/lib/types/index.d.ts +8 -4
- package/lib/types/name-rule.d.ts +112 -0
- package/lib/types/paths.d.ts +55 -10
- package/lib/types/pattern.d.ts +43 -5
- package/lib/types/platform.d.ts +148 -0
- package/lib/types/preview.d.ts +39 -3
- package/lib/types/resolve.d.ts +129 -23
- package/lib/types/schema.d.ts +24 -8
- package/lib/types/shell-dialect.d.ts +60 -0
- package/lib/types/tool-guard.d.ts +103 -0
- package/lib/types/wrap-fs.d.ts +86 -4
- package/lib/types/wrap-sandbox.d.ts +26 -6
- package/lib/wrap-fs.js +323 -47
- package/lib/wrap-fs.js.map +1 -1
- package/lib/wrap-sandbox.js +149 -12
- package/lib/wrap-sandbox.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
English | [中文](README.zh.md)
|
|
4
4
|
|
|
5
|
-
Let DSH **write to
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
Let DSH **write to configured external paths on the first try, with no approval** — for the `write`/`edit` tools and
|
|
6
|
+
`bash` subprocesses alike — and, since 0.3.0, **restrict** paths per access level: `deny` (no read or write), `read`
|
|
7
|
+
(read-only), `write` and `always-write`. Paths may be spelled for Windows, macOS/Linux or WSL, so one configuration can
|
|
8
|
+
be shared across machines. The plugin works by wrapping services (it does not change DSH core) and ships a Web settings
|
|
9
|
+
page plus a live preview of the effective rules for the current workspace.
|
|
8
10
|
|
|
9
11
|
## Install
|
|
10
12
|
|
|
@@ -27,6 +29,36 @@ plugin's own row: open the `dsh-extra-paths` bundle, then hit that row's **Confi
|
|
|
27
29
|
The page follows DSH's own language selection (**Settings → General → Language**): it ships Simplified Chinese and
|
|
28
30
|
English copy, and every other UI language falls back to English.
|
|
29
31
|
|
|
32
|
+
## Access levels
|
|
33
|
+
|
|
34
|
+
Every configured path carries one access level and a set of **surfaces**. `deny` and `read` are new in 0.3.0; before
|
|
35
|
+
that every entry was a write grant (`write` / `always-write`, spelled `scope` back then).
|
|
36
|
+
|
|
37
|
+
| `access` | fs tools: read | fs tools: write | bash: read | bash: write |
|
|
38
|
+
|---|---|---|---|---|
|
|
39
|
+
| `deny` | refused | refused | refused¹ | refused¹ |
|
|
40
|
+
| `read` | allowed | refused, even inside the workspace | allowed | refused¹ |
|
|
41
|
+
| `write` (default) | allowed | allowed while the session is `workspace-write` | allowed | allowed while `workspace-write`² |
|
|
42
|
+
| `always-write` | allowed | allowed even under `read-only` | allowed | allowed even under `read-only`² |
|
|
43
|
+
|
|
44
|
+
¹ Only where the shell sandbox can subtract permissions: macOS seatbelt and Linux bwrap. On Linux landlock (used when
|
|
45
|
+
bwrap is unavailable) and on Windows ACL, bash does not honor `deny`/`read`; the fs tools still do — see
|
|
46
|
+
[Known limits](#known-limits). ² The host cannot express extra bash grants on Windows; the fs tools still grant there.
|
|
47
|
+
|
|
48
|
+
- **The strictest rule wins**: for one target, `deny` > `read` > `write`/`always-write`. A `read`/`deny` rule is never
|
|
49
|
+
widened by a broader writable rule that covers it, so a denied subdirectory stays denied inside a writable root.
|
|
50
|
+
`write` and `always-write` merge to `always-write`, and the levels are reconciled **per surface**: one root can be
|
|
51
|
+
writable for the fs tools while bash may only read it.
|
|
52
|
+
- **`deny` is a hard rule**: it refuses content reads (the `read` tool, image/byte reads, listings and `watch`) and every
|
|
53
|
+
write. The `deny` and `read` rules hold for the fs tools even under `danger-full-access`; that mode has no shell sandbox
|
|
54
|
+
for them to attach to, so `bash` is not covered there.
|
|
55
|
+
- **`read` downgrades writes while keeping reads**: use it for directories inside the workspace that must stay
|
|
56
|
+
write-protected (`.git`, `node_modules`, build output).
|
|
57
|
+
- **Surfaces** (default `[fs, shell]`): `fs` = the fs tools — reads/listings as well as `write`/`edit`/apply-patch and
|
|
58
|
+
the delete/move operations; `shell` = `bash` subprocesses. A rule only applies to the surfaces it lists, so an
|
|
59
|
+
`fs`-only `deny` does not stop bash from reading the path (and vice versa).
|
|
60
|
+
- Read **metadata** (`stat`/`lstat`/`resolve`) is not blocked — only content access is; see Known limits.
|
|
61
|
+
|
|
30
62
|
## Configuration
|
|
31
63
|
|
|
32
64
|
Write it into the `extra-paths` section of the settings document `~/.dsh/settings.yaml`, or just use the settings page
|
|
@@ -35,27 +67,37 @@ holds your projects (an absolute path, or one starting with `~/`) — replace it
|
|
|
35
67
|
|
|
36
68
|
```yaml
|
|
37
69
|
extra-paths:
|
|
70
|
+
defaultAccess: write # default access for entries that omit it (default: write)
|
|
71
|
+
defaultSurfaces: [fs, shell] # default surfaces (default: fs + shell)
|
|
38
72
|
paths:
|
|
39
|
-
- <work root>/notes/home # default
|
|
73
|
+
- <work root>/notes/home # bare string = default access/surfaces
|
|
40
74
|
- path: ../../notes/home # relative paths resolve against the session workspace
|
|
41
|
-
|
|
75
|
+
access: always-write
|
|
42
76
|
- path: <work root>/some-repo
|
|
43
|
-
|
|
44
|
-
surfaces: [fs] # only
|
|
77
|
+
access: write
|
|
78
|
+
surfaces: [fs] # fs tools only: bash gets neither a grant nor a restriction
|
|
79
|
+
- path: ~/.ssh
|
|
80
|
+
access: deny # refuse reads and writes (bash too, where the platform can)
|
|
45
81
|
```
|
|
46
82
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
| `write` (default) | denied | writable |
|
|
50
|
-
| `always-write` | writable | writable |
|
|
83
|
+
Access levels are `deny` / `read` / `write` / `always-write`; surfaces are `fs` / `shell`. A bare-string entry inherits
|
|
84
|
+
`defaultAccess` and `defaultSurfaces`, and an object entry may omit either field to inherit it.
|
|
51
85
|
|
|
52
|
-
|
|
53
|
-
|
|
86
|
+
### Migrating from 0.2.x
|
|
87
|
+
|
|
88
|
+
The old vocabulary is still accepted: an entry's `scope: write|always-write` maps onto the same `access` level, and
|
|
89
|
+
`defaultScope` is the legacy alias of `defaultAccess`. Nothing has to change. If one entry spells both `scope` and
|
|
90
|
+
`access` with different values, the save is rejected instead of silently preferring one.
|
|
91
|
+
|
|
92
|
+
**One deliberate semantic change:** a spelling with no `/` (`notes`, `secrets`, `.git`) used to mean
|
|
93
|
+
`<workspace>/<name>` and is now a [name rule](#bare-name-rules-one-name-matched-at-any-depth) (that name at any depth).
|
|
94
|
+
Write `./notes` to keep the old literal meaning.
|
|
54
95
|
|
|
55
96
|
### How relative paths resolve
|
|
56
97
|
|
|
57
98
|
Relative paths resolve against **each session's own workspace** (the settings page has a "base workspace" field so you
|
|
58
|
-
can preview this)
|
|
99
|
+
can preview this); a spelling with **no separator** is a name rule instead — see
|
|
100
|
+
[Bare-name rules](#bare-name-rules-one-name-matched-at-any-depth):
|
|
59
101
|
|
|
60
102
|
| Spelling | Resolves to | Notes |
|
|
61
103
|
|---|---|---|
|
|
@@ -64,10 +106,46 @@ can preview this):
|
|
|
64
106
|
| `../../notes/home` | `<work root>/notes/home` | go up a few levels and into another tree |
|
|
65
107
|
| `~/notes/home` | under your home | independent of the workspace; `~user` is not expanded (same as the host) |
|
|
66
108
|
|
|
109
|
+
### Bare-name rules: one name, matched at any depth
|
|
110
|
+
|
|
111
|
+
A `path` with **no separator** (`.git`, `.env`, `node_modules`) is a **name rule**, not a path: it matches that
|
|
112
|
+
component — file or directory — at **any depth** under the session workspace plus every configured **writable root**,
|
|
113
|
+
and covers each match's whole subtree. One line protects the same structure in every repository, without a
|
|
114
|
+
per-checkout path or a walk-everything pattern:
|
|
115
|
+
|
|
116
|
+
```yaml
|
|
117
|
+
paths:
|
|
118
|
+
- path: .git
|
|
119
|
+
access: deny # repository metadata, wherever it is
|
|
120
|
+
surfaces: [fs] # name rules are fs-only (see below)
|
|
121
|
+
- path: .env
|
|
122
|
+
access: deny # secret files anywhere under the scope roots
|
|
123
|
+
- path: node_modules
|
|
124
|
+
access: read # dependency trees: readable, never writable
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
- **Scope**: matching starts only at the session workspace and the configured writable roots (the scope roots the
|
|
128
|
+
preview lists); the plugin never walks the whole disk.
|
|
129
|
+
- **Escape hatch**: `./notes` — a spelling WITH a separator — is still a literal workspace-relative path, so use it
|
|
130
|
+
when a single component must mean exactly `<workspace>/name` instead of "any depth".
|
|
131
|
+
- **Every access level is legal**, but `deny` / `read` are the recommended ones: a name-scoped grant
|
|
132
|
+
(`write` / `always-write`) would grant every same-named directory under the scope roots.
|
|
133
|
+
- **fs tools only — deliberately.** Name rules are matched lexically on every fs call: exact, live (a directory created a
|
|
134
|
+
moment ago is already covered) and with no directory walk. The shell surface **cannot** express a bare name, and
|
|
135
|
+
enumerating "the paths it matches right now" before commands turned out to be costly, stale for up to 30 s and
|
|
136
|
+
silently partial whenever one writable root was deep or unreadable — so it is **not done**: a name rule never
|
|
137
|
+
restricts `bash`. If the shell must be covered, write concrete paths or a `*` pattern (those are exact on both
|
|
138
|
+
surfaces). A name rule that still lists `shell` in `surfaces` gets a one-time host warning — the fs tools stay
|
|
139
|
+
protected, bash does not.
|
|
140
|
+
- **Need bash covered? Use a pattern.** A spelling containing `*` is a pattern (never a name rule) and patterns are the
|
|
141
|
+
one form the shell surface can inject. A leading wildcard anchors at the **session workspace**, so `**/.git` protects
|
|
142
|
+
every repository's `.git` under it without hard-coding a machine-specific root; a literal final segment also matches
|
|
143
|
+
**files**, so `**/.env` works. See below.
|
|
144
|
+
|
|
67
145
|
### Patterns: anchor a grant to directory structure (no hard-coded paths)
|
|
68
146
|
|
|
69
|
-
A `path` can use wildcards to describe **a group of directories
|
|
70
|
-
path" into a condition:
|
|
147
|
+
A `path` can use wildcards to describe **a group of paths** — directories, or files when the final segment is a literal
|
|
148
|
+
name — turning "a certain structure exists somewhere in this path" into a condition:
|
|
71
149
|
|
|
72
150
|
| Spelling | Matches (the granted root) |
|
|
73
151
|
|---|---|
|
|
@@ -75,29 +153,112 @@ path" into a condition:
|
|
|
75
153
|
| `<work root>/**/.worktrees/*` | each individual worktree (`.git` and the main checkout are never touched) |
|
|
76
154
|
| `<work root>/<some-repo>/.worktrees/*` | every worktree of one repository (**zero traversal cost**, recommended) |
|
|
77
155
|
| `<work root>/*/notes` | the `notes` directory under every repository/project |
|
|
156
|
+
| `**/.git` | every `.git` directory under the **session workspace**, up to the depth bound |
|
|
157
|
+
| `**/.env` | every `.env` **file** under the session workspace |
|
|
158
|
+
| `<work root>/**/.git` | the same, anchored at an absolute work root so every session shares it |
|
|
159
|
+
|
|
160
|
+
Syntax: `*` = exactly one level, `**` = at most 3 levels (**only existing paths** match, so "`.worktrees` must exist" comes
|
|
161
|
+
for free); a **literal final segment also matches files** (`**/.env`); a trailing `..` moves up **after** matching (so
|
|
162
|
+
`…/.worktrees/..` is "the parent of `.worktrees`", rather than something lexical collapsing eats away).
|
|
78
163
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
164
|
+
**Anchor:** absolute (`~`, `/…`, `C:\…`) or **workspace-relative** — a leading wildcard (`**/.git`, `*/src`) or a
|
|
165
|
+
literal prefix (`services/**/notes`, `../**/.git`) is anchored at the **session workspace**, exactly like a relative
|
|
166
|
+
path, so the same configuration works in every checkout without a machine-specific work root. A Windows spelling with
|
|
167
|
+
`\` separators is parsed in its own dialect; a pattern whose absolute anchor belongs to another platform becomes
|
|
168
|
+
inactive (`foreign`) with a warning instead of failing the save.
|
|
82
169
|
|
|
83
170
|
Safety bounds (hard constraints, not advice):
|
|
84
171
|
|
|
85
|
-
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
172
|
+
- **absolute / `~` anchors** need at least two literal segments and must not start at a volume root — `/**`, `~/**`,
|
|
173
|
+
`/srv/**` are refused outright; **workspace-relative anchors** need at least one literal segment, so `**` / `**/*`
|
|
174
|
+
(a pure workspace sweep) is refused too
|
|
175
|
+
- traversal **never enters** `node_modules` or `.git`, and `**` never enters hidden directories — but a **final literal
|
|
176
|
+
segment may match `.git` itself** (that is how `**/.git` works), it just never looks inside it
|
|
89
177
|
- bounded: `**` covers at most 3 levels, and more than 4096 directories or more than 256 matches makes **the whole
|
|
90
178
|
pattern inert** (fail closed — never a partial, unpredictable grant); the reason is reported as a warning
|
|
91
|
-
- expansions are cached for 30 seconds, so a **newly created worktree is picked up within 30 seconds**
|
|
179
|
+
- expansions are cached for 30 seconds, so a **newly created worktree/.git is picked up within 30 seconds**
|
|
180
|
+
- a pattern is also the form the **shell surface** can express: on macOS seatbelt and Linux bwrap the matched paths are
|
|
181
|
+
injected into the sandbox (bounded + cached); landlock and Windows ACL still cannot subtract access
|
|
182
|
+
|
|
183
|
+
The preview panel shows the **host's answer for every configured entry**: the resolved absolute path (symlinks as the
|
|
184
|
+
host canonicalizes them), the status badge (`[active]`, `[missing]`, `[rejected]`, `[not applicable on this host]`), and —
|
|
185
|
+
for a pattern or a name rule — how many paths currently match. Zero matches, blocked patterns and platform-mismatched
|
|
186
|
+
entries are all spelled out, so there is no need to "save first and then check whether it resolved".
|
|
187
|
+
|
|
188
|
+
## Windows, WSL and macOS/Linux: one configuration for every machine
|
|
189
|
+
|
|
190
|
+
A configured path may be written in any platform's spelling; the **host** resolves it and translates between Windows and
|
|
191
|
+
WSL where it can, then verifies the result against the real filesystem. The page always shows the host's answer — the
|
|
192
|
+
browser never guesses the platform (under WSL the browser is Windows Chrome while the host is Linux, and a remote web
|
|
193
|
+
client is another machine).
|
|
194
|
+
|
|
195
|
+
| Spelling | Meaning |
|
|
196
|
+
|---|---|
|
|
197
|
+
| `C:\work\shared`, `C:/work/shared` | a Windows drive path, either separator accepted |
|
|
198
|
+
| `\\server\share\docs` | a Windows UNC share |
|
|
199
|
+
| `C:foo` | rejected at save time (drive-relative — it depends on that drive's current directory) |
|
|
200
|
+
| `/mnt/c/work` | WSL spelling of `C:\work` (the mount root is detected from the mount table; `/mnt` is the fallback) |
|
|
201
|
+
| `/c/work` | git-bash/MSYS spelling of `C:\work`; only usable when that drive exists on the host (otherwise `missing`) |
|
|
202
|
+
| `~/projects`, `~\projects` | your home directory; both separators accepted |
|
|
203
|
+
|
|
204
|
+
- **WSL ⇄ Windows translation**: inside WSL a Windows drive path `C:\x` (or `C:/x`) becomes `/mnt/c/x`; on a native
|
|
205
|
+
Windows host `/mnt/c/…` or `/c/…` becomes `C:\…` (a drive that does not exist there is simply `missing`). UNC paths
|
|
206
|
+
have no reliable WSL mapping, so they are `foreign` inside WSL. Translation is never trusted lexically — the
|
|
207
|
+
translated path still has to resolve.
|
|
208
|
+
- **Foreign entries stay inactive**: a spelling this host cannot express (a Windows path on macOS/Linux, an unmappable
|
|
209
|
+
POSIX path on Windows) is **inactive with a warning**; the configuration still saves, so the same document can be used
|
|
210
|
+
on several machines (dotfiles, a shared settings repo) without per-machine copies.
|
|
211
|
+
- **Save-time validation**: filesystem/volume roots (`/`, `C:`, `C:\`, a UNC share root), drive-relative spellings and
|
|
212
|
+
duplicate paths (case-insensitively on Windows) are rejected. A spelling that only becomes a volume root after
|
|
213
|
+
translation (WSL's `/mnt/c`) is reported `[rejected]` and ignored at resolution time.
|
|
214
|
+
|
|
215
|
+
## Settings page: one plain-text editor, one Save
|
|
216
|
+
|
|
217
|
+
The page is a **single plain-text editor for all rules** — no row list, no mode switch and exactly **one action:
|
|
218
|
+
Save**. Each line is `path | access | surfaces`; the editor always renders the explicit three-field form, and a bare
|
|
219
|
+
name (`.git`, `.env`) is a name rule. Hand-written comments (`# …`) and blank lines are ignored.
|
|
92
220
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
221
|
+
- **Defaults when fields are omitted**: the page shows the live values in a line above the editor — access falls back
|
|
222
|
+
to `defaultAccess` (default **write**, i.e. writable while the session is workspace-write) and surfaces to
|
|
223
|
+
`defaultSurfaces` (default **fs+shell**); both can be changed in the config document under the `extra-paths` section.
|
|
224
|
+
- **Built-in examples**: a collapsible **Examples and supported forms** block sits right above the editor with the
|
|
225
|
+
common spellings (access levels, surfaces, bare-name rules, patterns, Windows/WSL paths) and the same defaults note.
|
|
226
|
+
- **The base-workspace field** only feeds the preview and the host-side resolution — it is not part of the saved
|
|
227
|
+
configuration.
|
|
228
|
+
- **Save** parses the whole text (all-or-nothing) and writes the structured `paths` array in one step; invalid lines are
|
|
229
|
+
reported with their line number and nothing is saved. The host's refusal (a home/CLI override owns the namespace) is
|
|
230
|
+
shown instead of silently pretending to save.
|
|
231
|
+
- **The preview panel** answers for the draft: effective writable roots, read-only roots, denied roots, per-entry
|
|
232
|
+
status (`[active]`, `[missing]`, `[rejected]`, `[not applicable on this host]`) and warnings. It is collapsed by
|
|
233
|
+
default.
|
|
234
|
+
- Rows/pattern/name details now live **in the text itself**; the preview shows the resolved result, so there is no
|
|
235
|
+
second editor to keep in sync.
|
|
96
236
|
|
|
97
237
|
## Known limits
|
|
98
238
|
|
|
239
|
+
- **Shell-side `deny`/`read` is only reliable on macOS (seatbelt) and Linux with bwrap.** The Linux landlock runner is an
|
|
240
|
+
allow-list — it can grant, not subtract — and WSL installs without bwrap end up there; the Windows ACL runner rejects
|
|
241
|
+
unknown flags. On those hosts bash will not honor `deny`/`read`: the plugin does not invent flags, it warns once per
|
|
242
|
+
dialect and rule set, and the page shows the capability banner. The fs tools always enforce the rules.
|
|
243
|
+
- **A bare-name rule protects the fs tools, NOT bash.** `.git`, `.env`, `node_modules` are matched lexically by
|
|
244
|
+
`read`/`write`/`edit`/apply-patch and friends (and by the `grep`/`glob` argument guard); `bash` can still read or
|
|
245
|
+
write them, because a sandbox profile can only name concrete paths and per-command enumeration was rejected
|
|
246
|
+
(cost, staleness, partial coverage). Use a path pattern if bash must be restricted too — e.g. `**/.git` (anchored at
|
|
247
|
+
the session workspace) or `<work root>/**/.git`; patterns are exact on both surfaces where the platform can subtract.
|
|
248
|
+
- **`grep`/`glob` bypass `ctx.fs`**: the host runs its bundled ripgrep directly. The plugin's tool-level guard reliably
|
|
249
|
+
refuses `grep`/`glob` calls whose own `path` argument names a denied path, but a default workspace-wide search can
|
|
250
|
+
still surface a denied subdirectory in its results. Keep sensitive data outside the workspace and `deny` it there —
|
|
251
|
+
on platforms where the shell can subtract, bash is blocked as well.
|
|
252
|
+
- **Metadata is not blocked**: `stat`/`lstat`/`resolve` and similar methods exchange only metadata, so the existence,
|
|
253
|
+
size and identity of a denied path can still be observed. Content reads, listings and `watch` are refused.
|
|
254
|
+
- **Consumers outside the proxy**: services that reach the filesystem through `ctx.get('fs')`, LSP/MCP subprocesses, and
|
|
255
|
+
host services that cached `ctx.fs` at load time are not constrained by the proxy.
|
|
256
|
+
- **Windows shell grants remain unsupported by the host** (a 0.2.2 architecture limit): extra paths are not widened for
|
|
257
|
+
bash on Windows, and 0.3.0 does not change that. The fs tools still work.
|
|
258
|
+
- **Under `danger-full-access`** there is no shell sandbox to inject rules into, so shell-surface `deny`/`read` cannot be
|
|
259
|
+
enforced in that mode; the fs tools still enforce them.
|
|
99
260
|
- Per-path "no restrictions at all" is not achievable: the bash sandbox works at whole-invocation granularity.
|
|
100
261
|
- Relative paths resolve against the session workspace, so the same entry points at different directories in different
|
|
101
262
|
workspaces — the settings page preview shows the actual resolution.
|
|
102
|
-
-
|
|
263
|
+
- `always-write` weakens what the `read-only` stop button can do for that path.
|
|
103
264
|
- Files written outside the workspace do not appear in the `deliverables` workspace-changes card.
|
package/README.zh.md
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
[English](README.md) | 中文
|
|
4
4
|
|
|
5
5
|
让 DSH 对一组配置的外部路径**首次尝试即可写、无需审批**:既覆盖 `write`/`edit` 工具,也覆盖 `bash` 子进程。
|
|
6
|
-
|
|
6
|
+
0.3.0 起每条路径还带**访问级别**:`deny`(禁止读写)、`read`(只读)、`write`、`always-write`;路径可以按
|
|
7
|
+
Windows、macOS/Linux 或 WSL 的写法书写,因此同一份配置能跨机器共用。插件以服务包装实现,不改 DSH 核心代码,
|
|
8
|
+
并提供 Web 设置页与「当前工作区解析出的生效规则」实时预览。
|
|
7
9
|
|
|
8
10
|
## 安装
|
|
9
11
|
|
|
@@ -26,6 +28,32 @@ dsh plugin --profile <name> add /path/to/dsh-extra-paths # 路径=本仓库的
|
|
|
26
28
|
页面文案跟随 DSH 自己的语言选择(**设置 → 常规 → 语言**):内置简体中文与英文两套文案,
|
|
27
29
|
其它界面语言回落到英文。
|
|
28
30
|
|
|
31
|
+
## 访问级别
|
|
32
|
+
|
|
33
|
+
每条路径有一个访问级别和一组**作用面**。`deny` 与 `read` 是 0.3.0 新增的——在此之前每条都只是写授权
|
|
34
|
+
(`write` / `always-write`,当时写作 `scope`)。
|
|
35
|
+
|
|
36
|
+
| `access` | fs 工具:读 | fs 工具:写 | bash:读 | bash:写 |
|
|
37
|
+
|---|---|---|---|---|
|
|
38
|
+
| `deny` | 拒绝 | 拒绝 | 拒绝¹ | 拒绝¹ |
|
|
39
|
+
| `read` | 允许 | 拒绝(即使在工作区内) | 允许 | 拒绝¹ |
|
|
40
|
+
| `write`(默认) | 允许 | 会话为 `workspace-write` 时允许 | 允许 | `workspace-write` 时允许² |
|
|
41
|
+
| `always-write` | 允许 | `read-only` 会话也允许 | 允许 | `read-only` 会话也允许² |
|
|
42
|
+
|
|
43
|
+
¹ 仅当 shell 沙箱能**扣减**权限时可保证:macOS seatbelt 与 Linux bwrap。Linux landlock(没有 bwrap 时的后备,
|
|
44
|
+
含未装 bwrap 的 WSL)与 Windows ACL 上 bash 不遵守 `deny`/`read`,但 fs 工具仍然执行——见
|
|
45
|
+
[已知边界](#已知边界)。² 宿主无法在 Windows 上表达额外的 bash 授权;fs 工具侧照常授权。
|
|
46
|
+
|
|
47
|
+
- **最严规则胜出**:对同一目标,`deny` > `read` > `write`/`always-write`。覆盖同一目标的更宽可写规则**不会**放大
|
|
48
|
+
`read`/`deny` 规则(可写根里被 deny 的子目录依然被拒)。`write` 与 `always-write` 合并取 `always-write`;访问级别
|
|
49
|
+
按**作用面**分别结算——同一个根可以「fs 工具可写、bash 只读」。
|
|
50
|
+
- **`deny` 是硬规则**:拒绝内容读取(`read` 工具、图片/字节读取、目录列举与 `watch`)与所有写入;`deny` 与
|
|
51
|
+
`read` 在 `danger-full-access` 下对 fs 工具照样生效(该模式没有 shell 沙箱层,因此 bash 不受这条规则约束)。
|
|
52
|
+
- **`read` 只降级写入、保留读取**:适合工作区内需要保持写保护(只读)的目录(`.git`、`node_modules`、构建产物)。
|
|
53
|
+
- **作用面**(默认 `[fs, shell]`):`fs` = fs 工具——读取/列举,以及 `write`/`edit`、apply-patch 与删除/移动操作;
|
|
54
|
+
`shell` = `bash` 子进程。规则只在列出的表面上生效,所以只在 `fs` 上的 `deny` 不会阻止 bash 读该路径(反之亦然)。
|
|
55
|
+
- 读的**元数据**(`stat`/`lstat`/`resolve`)不拦截,只拦内容访问——见「已知边界」。
|
|
56
|
+
|
|
29
57
|
## 配置
|
|
30
58
|
|
|
31
59
|
写进设置文档 `~/.dsh/settings.yaml` 的 `extra-paths` 段,或直接用设置页(**保存即生效,无需重启**)。
|
|
@@ -33,25 +61,34 @@ dsh plugin --profile <name> add /path/to/dsh-extra-paths # 路径=本仓库的
|
|
|
33
61
|
|
|
34
62
|
```yaml
|
|
35
63
|
extra-paths:
|
|
64
|
+
defaultAccess: write # 条目省略 access 时的默认级别(默认 write)
|
|
65
|
+
defaultSurfaces: [fs, shell] # 默认作用面(默认 fs + shell)
|
|
36
66
|
paths:
|
|
37
|
-
- <工作根>/notes/home #
|
|
67
|
+
- <工作根>/notes/home # 裸字符串 = 用默认访问级别/作用面
|
|
38
68
|
- path: ../../notes/home # 相对路径按「会话工作区」解析
|
|
39
|
-
|
|
69
|
+
access: always-write
|
|
40
70
|
- path: <工作根>/some-repo
|
|
41
|
-
|
|
42
|
-
surfaces: [fs] #
|
|
71
|
+
access: write
|
|
72
|
+
surfaces: [fs] # 只作用于 fs 工具:bash 既不放行也不限制
|
|
73
|
+
- path: ~/.ssh
|
|
74
|
+
access: deny # 拒绝读写(平台支持时 bash 也拒)
|
|
43
75
|
```
|
|
44
76
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
77
|
+
访问级别为 `deny` / `read` / `write` / `always-write`;作用面为 `fs` / `shell`。裸字符串条目继承 `defaultAccess`
|
|
78
|
+
与 `defaultSurfaces`;对象条目省略其中任一字段时也继承对应默认值。
|
|
79
|
+
|
|
80
|
+
### 从 0.2.x 迁移
|
|
81
|
+
|
|
82
|
+
旧写法继续被接受:条目上的 `scope: write|always-write` 映射到同名的 `access`,`defaultScope` 是 `defaultAccess`
|
|
83
|
+
的旧别名。配置无需改动。若同一条目同时写了 `scope` 与 `access` 且值不一致,保存会被拒绝,而不是悄悄取其中一个。
|
|
49
84
|
|
|
50
|
-
|
|
85
|
+
**一处有意的语义变化**:不含 `/` 的写法(`notes`、`secrets`、`.git`)以前指 `<工作区>/<名字>`,现在表示
|
|
86
|
+
[名称规则](#名称规则裸名一个名称任意深度匹配)(该名字在任意深度匹配)。要保留原来的字面含义请写 `./notes`。
|
|
51
87
|
|
|
52
88
|
### 相对路径怎么写
|
|
53
89
|
|
|
54
|
-
|
|
90
|
+
相对路径按**各会话自己的工作区**解析(设置页里可以改「基准工作区」来预览);**不含分隔符**的写法是名称规则,见
|
|
91
|
+
[名称规则(裸名)](#名称规则裸名一个名称任意深度匹配):
|
|
55
92
|
|
|
56
93
|
| 写法 | 解析成 | 说明 |
|
|
57
94
|
|---|---|---|
|
|
@@ -60,9 +97,40 @@ extra-paths:
|
|
|
60
97
|
| `../../notes/home` | `<工作根>/notes/home` | 往上几层再进别的树 |
|
|
61
98
|
| `~/notes/home` | 家目录下 | 与工作区无关;`~user` 不展开(与宿主一致) |
|
|
62
99
|
|
|
63
|
-
###
|
|
100
|
+
### 名称规则(裸名):一个名称,任意深度匹配
|
|
64
101
|
|
|
65
|
-
`path`
|
|
102
|
+
`path` 里**不含分隔符**时(`.git`、`.env`、`node_modules`)是**名称规则**而不是路径:匹配「会话工作区 + 所有配置的
|
|
103
|
+
可写根」内**任意深度**的同名组件(文件或目录),并覆盖每个匹配的整棵子树。一行配置就能保护每个仓库里的同一种结构,
|
|
104
|
+
既不用逐仓库写路径,也不用"遍历全盘"的模式:
|
|
105
|
+
|
|
106
|
+
```yaml
|
|
107
|
+
paths:
|
|
108
|
+
- path: .git
|
|
109
|
+
access: deny # 无论在哪个仓库,都拒绝仓库元数据
|
|
110
|
+
surfaces: [fs] # 名称规则只作用于 fs 工具(见下)
|
|
111
|
+
- path: .env
|
|
112
|
+
access: deny # 作用范围内任意位置的密钥文件
|
|
113
|
+
- path: node_modules
|
|
114
|
+
access: read # 依赖目录:可读、不可写
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
- **作用范围**:只从会话工作区与已配置的可写根(预览里列出的作用根)开始匹配,不会遍历整个磁盘。
|
|
118
|
+
- **逃生写法**:`./notes` 带分隔符,仍是字面量的工作区相对路径;当某个单段名称必须表示"工作区下的这个目录"而不是
|
|
119
|
+
「任意深度」时用它。
|
|
120
|
+
- **四种访问级别都合法**,但推荐 `deny` / `read`:名称级别的授权(`write` / `always-write`)会把作用范围内所有同名
|
|
121
|
+
目录一起授权。
|
|
122
|
+
- **只作用于 fs 工具——这是有意的。** 名称规则在每次 fs 调用时按路径段词法匹配:精确、实时(刚创建的目录立刻
|
|
123
|
+
生效)、零目录遍历。shell 面无法表达"名称",而"按命令枚举当前匹配"的实现在真机上被证明代价高、最多滞后 30 秒、
|
|
124
|
+
且某个可写根很深/不可读时只能部分覆盖——所以**不做**:名称规则**不约束 bash**。要让 shell 也受约束,请写具体
|
|
125
|
+
路径或 `*` 模式(两者在 fs/shell 两侧都精确)。名称规则即使写了 `shell` 作用面,宿主也只会告警一次:fs 工具
|
|
126
|
+
照常保护,bash 不受约束。
|
|
127
|
+
- **要让 bash 也受约束?用模式。** 含 `*` 的写法是模式(永远不会被当作名称规则),而模式正是 shell 面唯一能表达
|
|
128
|
+
的形式:以通配符开头的模式锚定在**会话工作区**,所以 `**/.git` 不用写死本机工作根就能保护其下每个仓库的
|
|
129
|
+
`.git`;最后一段是字面量时还能匹配**文件**(`**/.env`)。见下节。
|
|
130
|
+
|
|
131
|
+
### 模式:按路径结构锚定(不用写死路径)
|
|
132
|
+
|
|
133
|
+
`path` 里可以用通配符描述**一组路径**(目录,或最后一段为字面量时的文件),于是"路径里存在某个结构"可以变成一个条件:
|
|
66
134
|
|
|
67
135
|
| 写法 | 命中(授予的根) |
|
|
68
136
|
|---|---|
|
|
@@ -70,23 +138,97 @@ extra-paths:
|
|
|
70
138
|
| `<工作根>/**/.worktrees/*` | 每个具体 worktree(不碰 `.git` 与主检出) |
|
|
71
139
|
| `<工作根>/<某仓库>/.worktrees/*` | 某一个仓库下所有 worktree(**零遍历开销**,最推荐) |
|
|
72
140
|
| `<工作根>/*/notes` | 每个仓库/项目下的 `notes` 目录 |
|
|
141
|
+
| `**/.git` | **会话工作区**下每个 `.git` 目录(受深度上限约束) |
|
|
142
|
+
| `**/.env` | 会话工作区下每个 `.env` **文件** |
|
|
143
|
+
| `<工作根>/**/.git` | 同上,但锚定在绝对工作根,所有会话共用 |
|
|
144
|
+
|
|
145
|
+
语法:`*` = 恰好一层、`**` = 最多 3 层(**只匹配真实存在的路径**,所以"必须存在 `.worktrees`"是自然结果);
|
|
146
|
+
**最后一段是字面量时也会匹配文件**(`**/.env`);结尾的 `..` 在**命中之后**再上移(因此 `…/.worktrees/..` 就是
|
|
147
|
+
"`.worktrees` 的上级",不会被词法折叠吃掉)。
|
|
73
148
|
|
|
74
|
-
|
|
75
|
-
|
|
149
|
+
**锚点**:可以是绝对路径(`~`、`/…`、`C:\…`),也可以是**工作区相对**——以通配符开头(`**/.git`、`*/src`)或
|
|
150
|
+
带字面量前缀(`services/**/notes`、`../**/.git`)的模式锚定在**会话工作区**,与相对路径一致,因此同一份配置在
|
|
151
|
+
每个检出里都能用、无需写死本机工作根。带 `\` 分隔符的 Windows 写法会按它自己的方言解析;锚点属于另一种平台的
|
|
152
|
+
模式变为 inactive(`foreign`)并给出告警,而不是保存失败。
|
|
76
153
|
|
|
77
154
|
安全边界(都是硬约束,不是建议):
|
|
78
155
|
|
|
79
|
-
-
|
|
80
|
-
|
|
156
|
+
- **绝对 / `~` 锚点**至少两层字面量且不能是卷根 —— `/**`、`~/**`、`/srv/**` 一律拒绝;**工作区相对锚点**至少要
|
|
157
|
+
有一个字面量段,`**` / `**/*` 这种"扫全工作区"的纯通配一律拒绝
|
|
158
|
+
- 遍历**不进入** `node_modules`、`.git`,`**` 也不进入隐藏目录——但**最后一段字面量可以命中 `.git` 本身**
|
|
159
|
+
(`**/.git` 就是这么工作的),只是永远不会看进它内部
|
|
81
160
|
- 有界:`**` 最多 3 层、目录数 > 4096 或命中 > 256 时**整个模式不生效**(fail closed,绝不给"部分命中"这种不可预期的授权);触顶原因会写进告警
|
|
82
|
-
- 展开结果缓存 30 秒,因此**新建的 worktree 最迟 30 秒**被纳入
|
|
161
|
+
- 展开结果缓存 30 秒,因此**新建的 worktree/`.git` 最迟 30 秒**被纳入
|
|
162
|
+
- 模式也是 **shell 面**能表达的形式:macOS seatbelt 与 Linux bwrap 上会把命中路径注入沙箱(有界 + 缓存);
|
|
163
|
+
landlock 与 Windows ACL 仍然无法扣减
|
|
83
164
|
|
|
84
|
-
|
|
85
|
-
|
|
165
|
+
解析预览会显示宿主对**每一条配置的答案**:解析到的绝对路径(符号链接以宿主规范化后的结果为准)、状态徽标
|
|
166
|
+
(`[生效]`、`[缺失]`、`[已拒绝]`、`[当前平台不适用]`),以及模式/名称规则当前的命中数。0 命中、被拦截、
|
|
167
|
+
平台不匹配的条目都会明确说明,所以不必"先保存再看解析对不对"。
|
|
168
|
+
|
|
169
|
+
## Windows、WSL 与 macOS/Linux:一份配置到处可用
|
|
170
|
+
|
|
171
|
+
配置里的路径可以按任意平台的写法书写;由**宿主**解析,并在可以映射时做 Windows ⇄ WSL 互译,然后拿真实文件系统
|
|
172
|
+
校验。页面只显示宿主的答案——浏览器从不自己猜平台(WSL 下浏览器是 Windows Chrome 而宿主是 Linux,远程 Web
|
|
173
|
+
客户端更是另一台机器)。
|
|
174
|
+
|
|
175
|
+
| 写法 | 含义 |
|
|
176
|
+
|---|---|
|
|
177
|
+
| `C:\work\shared`、`C:/work/shared` | Windows 盘符路径,两种分隔符都接受 |
|
|
178
|
+
| `\\server\share\docs` | Windows UNC 共享 |
|
|
179
|
+
| `C:foo` | 保存时拒绝(盘符相对路径,取决于该盘的当前目录) |
|
|
180
|
+
| `/mnt/c/work` | `C:\work` 的 WSL 写法(挂载根从挂载表探测,缺省 `/mnt`) |
|
|
181
|
+
| `/c/work` | `C:\work` 的 git-bash/MSYS 写法;仅当宿主机上该盘存在时可用(否则为 `missing`) |
|
|
182
|
+
| `~/projects`、`~\projects` | 家目录;两种分隔符都接受 |
|
|
183
|
+
|
|
184
|
+
- **WSL ⇄ Windows 互译**:WSL 里 Windows 盘符路径 `C:\x`(或 `C:/x`)解析为 `/mnt/c/x`;原生 Windows 宿主上
|
|
185
|
+
`/mnt/c/…` 或 `/c/…` 解析为 `C:\…`(该盘不存在时就是 `missing`)。UNC 在 WSL 里没有可靠映射,因此是 `foreign`。
|
|
186
|
+
翻译不靠词法信任——翻译后的路径仍必须能真实解析。
|
|
187
|
+
- **foreign 条目保持 inactive**:当前宿主无法表达的写法(macOS/Linux 上的 Windows 路径、Windows 上无法映射的
|
|
188
|
+
POSIX 路径)变为 **inactive + 告警**,配置照常保存,因此同一份文档可以在多台机器上共用(dotfiles、共享的
|
|
189
|
+
设置仓库),不需要为每台机器写一份。
|
|
190
|
+
- **保存时校验**:文件系统/卷根(`/`、`C:`、`C:\`、UNC 共享根)、盘符相对写法、重复路径(Windows 上大小写不敏感)
|
|
191
|
+
会被拒绝。翻译之后才成为卷根的写法(WSL 的 `/mnt/c`)显示为 `[已拒绝]` 并在解析时忽略。
|
|
192
|
+
|
|
193
|
+
## 设置页:一个纯文本编辑器,一个保存按钮
|
|
194
|
+
|
|
195
|
+
整页就是**一个编辑全部规则的纯文本编辑器**——没有行列表、没有模式切换,只有一个 **保存** 按钮。每行
|
|
196
|
+
`路径 | 访问级别 | 作用面`;编辑器总是渲染完整三段,不带分隔符的裸名(`.git`、`.env`)是名称规则。手写的
|
|
197
|
+
`#` 注释与空行会被忽略。
|
|
198
|
+
|
|
199
|
+
- **省略字段时的默认值**:编辑器上方会显示当前生效的默认值——访问级别取 `defaultAccess`(默认 **write**,即
|
|
200
|
+
会话为 workspace-write 时可写),作用面取 `defaultSurfaces`(默认 **fs+shell**);两者可在配置文档的
|
|
201
|
+
`extra-paths` 段里修改。
|
|
202
|
+
- **内置示例**:编辑器上方有可展开的「示例与支持的写法」,列出常用形式(访问级别、作用面、名称规则、模式、
|
|
203
|
+
Windows/WSL 路径),并同样写明默认值。
|
|
204
|
+
- **基准工作区**只用于预览与宿主侧解析,不属于保存的配置内容。
|
|
205
|
+
- **保存** 一步解析整段文本(全有或全无)并写入结构化的 `paths` 数组;解析错误按行号提示、不保存任何内容。
|
|
206
|
+
宿主拒绝写入(命名空间被 home/CLI 覆盖)时会明确显示原因,不会假装保存成功。
|
|
207
|
+
- **解析预览**按草稿给出答案:生效可写根、只读根、被禁止的根、逐条状态(`[生效]`、`[缺失]`、`[已拒绝]`、
|
|
208
|
+
`[当前平台不适用]`)与告警;默认折叠成一行。
|
|
209
|
+
- 行/模式/名称规则的细节现在都在文本里,预览展示解析结果——不再有第二个需要同步的编辑器。
|
|
86
210
|
|
|
87
211
|
## 已知边界
|
|
88
212
|
|
|
213
|
+
- **shell 侧的 `deny`/`read` 仅在 macOS(seatbelt)与 Linux bwrap 下可靠。** Linux landlock 是纯 allow-list——
|
|
214
|
+
只能加不能减(没有 bwrap 的 WSL 安装会落到这里);Windows ACL runner 会拒绝不认识的参数。这些平台上 bash
|
|
215
|
+
不遵守 `deny`/`read`:插件不会硬塞参数,而是按「方言 + 规则集」只告警一次,页面显示能力横幅。fs 工具始终执行规则。
|
|
216
|
+
- **裸名规则只保护 fs 工具,不保护 bash。** `.git`、`.env`、`node_modules` 由 `read`/`write`/`edit`/apply-patch
|
|
217
|
+
等工具与 `grep`/`glob` 参数守卫按词法实时匹配;`bash` 仍可读写它们——沙箱 profile 只能写具体路径,而"按命令枚举"
|
|
218
|
+
方案(成本、滞后、部分覆盖)已被否决。要让 shell 也受约束,请改用路径模式,例如 `**/.git`(锚定当前会话
|
|
219
|
+
工作区)或 `<工作根>/**/.git`;在能扣减权限的平台上,模式在 fs/shell 两侧都精确。
|
|
220
|
+
- **`grep`/`glob` 绕过 `ctx.fs`**:宿主直接运行打包的 ripgrep。插件的工具层守卫会可靠拒绝**显式 `path` 参数**
|
|
221
|
+
命中被禁路径的 `grep`/`glob` 调用,但默认的整个工作区搜索仍可能在结果里带出被禁子目录。敏感数据请放在工作区
|
|
222
|
+
之外并 deny——在 shell 能扣减权限的平台上,bash 也会被拦。
|
|
223
|
+
- **元数据不拦截**:`stat`/`lstat`/`resolve` 等方法只交换元数据,因此被禁路径的存在性、大小与身份仍可能被观察到;
|
|
224
|
+
内容读取、目录列举与 `watch` 会被拒绝。
|
|
225
|
+
- **代理之外的消费者**:经 `ctx.get('fs')` 直接拿文件系统的服务、LSP/MCP 子进程、以及在加载期缓存了 `ctx.fs`
|
|
226
|
+
的宿主服务,不受代理约束。
|
|
227
|
+
- **Windows 的 shell 侧授权仍不受宿主支持**(0.2.2 架构限制):Windows 上不会为 bash 放行额外路径,0.3.0 不改变
|
|
228
|
+
这一点。fs 工具侧照常工作。
|
|
229
|
+
- **`danger-full-access` 下**没有 shell 沙箱可注入规则,因此该模式下 shell 侧的 `deny`/`read` 无法执行;fs 工具
|
|
230
|
+
仍按规则拒绝。
|
|
89
231
|
- 逐路径的"完全不受限"做不到:bash 沙箱是整次调用粒度。
|
|
90
232
|
- 相对路径按会话工作区解析,因此同一份配置在不同工作区指向不同目录——设置页的预览会显示实际解析结果。
|
|
91
|
-
-
|
|
233
|
+
- `always-write` 会削弱 `read-only` 急停按钮对该路径的作用。
|
|
92
234
|
- 写在工作区外的文件不会出现在 `deliverables` 的工作区变更卡片里。
|