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:
1 parent
c48e9cabd9
commit
40574505f2
7 files changed
+309
-27
No files matched your search
@@ -222,6 +222,23 @@ test('a child is never wider than its parent is now, narrowing included', () =>
|
||||
assert.equal(policy.scopeFor(spawned('c1', 's1')).root, '/w/src/room')
|
||||
})
|
||||
|
||||
test('a child started outside its parent facet is clamped to the parent root', () => {
|
||||
const policy = createFacetPolicy({ mode: 'deny', scopes: { s1: { focus: 'src/room' } } })
|
||||
assert.equal(policy.scopeFor(agentAt('/w', 's1')).root, '/w/src/room')
|
||||
|
||||
// The subagent tool takes a starting directory, and an agent can name one
|
||||
// outside the facet. The child's scope must not widen to it: the invariant is
|
||||
// one-directional, so a disjoint directory is clamped rather than trusted.
|
||||
const escaped = spawned('c1', 's1', '/etc')
|
||||
assert.equal(policy.scopeFor(escaped).root, '/w/src/room')
|
||||
// Its own directory still governs how its relative paths resolve; that is the
|
||||
// guard's question, decided against the inherited root.
|
||||
assert.equal(policy.scopeFor(escaped).cwd, '/etc')
|
||||
|
||||
// A child started inside the parent's root keeps its own, narrower directory.
|
||||
assert.equal(policy.scopeFor(spawned('c2', 's1', '/w/src/room/deep')).root, '/w/src/room/deep')
|
||||
})
|
||||
|
||||
test('a declaration for the child itself stands over what it would inherit', () => {
|
||||
const policy = createFacetPolicy({ mode: 'deny', scopes: { s1: { focus: 'src/room' }, c1: { focus: '.' } } })
|
||||
policy.scopeFor(agentAt('/w', 's1'))
|
||||
|
||||
Reference in new issue
Block a user