fix: judge the working directory and the arguments a tool declares

The guard resolved relative paths against the session directory the conversation
started in, but the file tools resolve them against the session's *current*
working directory — which `working_directory` can change with no guard opinion.
In a `deny` facet, `cd /etc` followed by `read` of a relative path read from
/etc. The same mismatch made a shadowed tool invisible: this deployment installs
`dsh-better-edit`, which replaces `read` (argument `path`) and `edit` (argument
`file`), so a table written against the built-in `file_path` left the busiest
read tool unguarded — an outside file could be read with `deny` in force.

Now:

- `working_directory` is in the path table, so a `cd` outside the facet is
  refused (or put to the user, by mode) like any other out-of-facet path;
- a relative argument is judged against the directory the tool will actually
  use, read lazily from `ctx.workingDirectory`, and the implicit-search rule
  judges that same directory;
- path parameter names come from the tool's own declaration when the registry
  can supply one, so a shadowed tool is judged by the arguments it really takes;
- a delegated session started with a `subagent` `cwd` outside the parent's facet
  is clamped to the parent root instead of being scoped to the outside directory.

`undo_last_edit` (write-like) and the delegation tools join the table. Verified
against a profile with dsh-better-edit: in `deny` mode the outside `read`,
`edit`, `cd /etc` and `subagent cwd /etc` are all refused, while an inside read
still works — and the relative-read bypass from the same profile now stays
inside.
This commit is contained in:
NotExpectedYet committed 2026-11-09 08:30:07 +00:00
1 parent c48e9cabd9
commit 40574505f2
7 files changed
+309 -27

No files matched your search

+35 -7
View File
@@ -234,7 +234,10 @@ its default is not 8192 but `headroomTokens`, 65536.
If you want that budget on *every* session rather than only scoped ones,
`presets/standard-compaction.patch.yml` is an opt-in overlay that applies the
same row to the shipped `standard` preset. It is not in the bundle's default
same row to the shipped `standard` preset. It overrides that row by id rather
than declaring a second one — with two declarations the mounted one would be
decided by the loader's duplicate-id handling rather than by the patch. It is not
in the bundle's default
patch list, and the header of that file explains why: a preset declaration
replaces the whole plugin list rather than merging into it, so the file is a
frozen copy of `standard` that will not follow the harness when `standard`
@@ -276,6 +279,22 @@ If a *deployment* still fails with that message on a non-facet preset, the
reference is in the deployment's own `system-prompt` config (`personaSuffix`) or
in a copy of the shipped `standard` patch, not in this bundle.
### The working directory is part of the scope
The file tools resolve a relative argument against the session's *current*
directory, and `working_directory` can change that. So the scope follows it: a
`cd` outside the facet is refused (or put to the user, by mode) like any other
out-of-facet path, and a relative `read`, `write` or `edit` is judged against the
directory the tool will actually use — not the one the conversation started in.
A delegated session started with its own `cwd` is clamped to the parent's facet;
it cannot be handed a wider scope by pointing it somewhere else.
A deployment can also shadow a built-in tool with one that names its path
argument differently — `dsh-better-edit` replaces `read` with `path` and `edit`
with `file`. The guard reads the argument names the tool actually declares for
the operations it guards, so a shadow is still judged; the table in
`lib/scope.js` is the fallback when the declaration cannot be read.
## What it does not cover
Honest boundaries, because each one is a decision rather than an oversight:
@@ -288,8 +307,12 @@ Honest boundaries, because each one is a decision rather than an oversight:
outside its facet, having been told in the same prompt not to. A prompt is not
a guard, which is what the rest of this plugin is for.
- **Tools that name a path in a shape the table cannot read are not guessed at** —
including MCP tools. See `PATH_ARGUMENTS` in `lib/scope.js`; it is a list of
tools whose path argument is a plain top-level string.
including MCP tools, and `present`'s nested `files[].path` (it shows the user a
file rather than reading it back to the model). See `PATH_ARGUMENTS` in
`lib/scope.js`; it is a list of tools whose path argument is a plain top-level
string. `apply_patch` is switched off in this bundle's preset for the same
reason — its paths live inside patch text — so a deployment that turns it on
gets no guard on it.
- **This guards the tool pipeline, not the filesystem.** There is no read seam in
the harness — `dsh-fs-sandbox` states plainly that "reads pass through
untouched: every mode permits reading" — so anything that reads through
@@ -303,7 +326,7 @@ Honest boundaries, because each one is a decision rather than an oversight:
Verified:
- 98 tests (`npm test`) over the scope algebra, the policy state, the guard, and
- 107 tests (`npm test`) over the scope algebra, the policy state, the guard, and
the browser half — including that containment is decided on canonical targets
(a symlink inside the facet pointing outside it is refused), that a prefix is
not a parent (`/a/room` does not contain `/a/roommate`), that a malformed tool
@@ -318,8 +341,13 @@ Verified:
preset or contributed prompt text references a prompt variable the harness
does not register, that each shipped preset is the installed harness's
`standard` composition plus only its documented changes and names only plugins
the harness provides, and that every `facet` result satisfies the tool's own
declared output schema.
the harness provides, that a `cd` outside the facet is refused while a
relative path is judged against the directory the tool will use, that a tool
shadowed onto different argument names is still guarded, that a delegated
session cannot be started outside its parent's facet, that the optional
compaction overlay replaces the shipped preset rather than adding a second
declaration, and that every `facet` result satisfies the tool's own declared
output schema.
- The bundle's patch layers parse, merge and land correctly against the real
profile: `dsh --profile web --patch ./cordis.patch.yml --patch
./presets/facet.patch.yml --dump-config` shows `facet-policy`, `preset-facet`,
@@ -399,7 +427,7 @@ lib/scope.js the pure half — argument extraction, text, reason
lib/guard.js preset row: rule, binding, tool, pre-execute guard
presets/facet.patch.yml the `facet` agent preset
presets/standard-compaction.patch.yml optional: the same budget for `standard`
test/ 98 tests
test/ 107 tests
```
`client/client.js` is a browser half rather than a module the host imports, and