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
@@ -40,6 +40,31 @@ test('pathArgumentsFor has no opinion where it cannot have one', () => {
|
||||
assert.deepEqual(pathArgumentsFor('grep', { path: { nested: '/etc' } }), [])
|
||||
})
|
||||
|
||||
test('a shadowed tool is judged by the arguments its own schema declares', () => {
|
||||
// `dsh-better-edit` replaces read/edit on the agent's layer with different
|
||||
// argument names; trusting the built-in's `file_path` left the busiest read
|
||||
// tool unguarded.
|
||||
assert.deepEqual(pathArgumentsFor('read', { path: 'src/a.ts', limit: 10 }, ['path', 'limit']), ['src/a.ts'])
|
||||
assert.deepEqual(pathArgumentsFor('edit', { file: 'src/a.ts', edits: [] }, ['file', 'edits']), ['src/a.ts'])
|
||||
// A declared path-shaped name the table does not list is still found.
|
||||
assert.deepEqual(pathArgumentsFor('write', { path: 'src/a.ts', content: 'x' }, ['path', 'content']), ['src/a.ts'])
|
||||
// The table is the fallback when the schema cannot be read.
|
||||
assert.deepEqual(pathArgumentsFor('read', { path: 'src/a.ts' }), ['src/a.ts'])
|
||||
})
|
||||
|
||||
test('the tools that move the scope are judged like any other path', () => {
|
||||
assert.deepEqual(pathArgumentsFor('working_directory', { cd: '../elsewhere' }, ['cd']), ['../elsewhere'])
|
||||
assert.deepEqual(
|
||||
pathArgumentsFor('subagent', { cwd: '../elsewhere', prompt: 'x' }, ['cwd', 'prompt']),
|
||||
['../elsewhere'],
|
||||
)
|
||||
assert.deepEqual(pathArgumentsFor('subagent_fork', { cwd: 'sub', prompt: 'x' }, ['cwd', 'prompt']), ['sub'])
|
||||
// Reading the directory names nothing, and moves nothing.
|
||||
assert.deepEqual(pathArgumentsFor('working_directory', {}, ['cd']), [])
|
||||
// The undo tool writes a file back, so it is a path like any other.
|
||||
assert.deepEqual(pathArgumentsFor('undo_last_edit', { path: 'src/a.ts' }), ['src/a.ts'])
|
||||
})
|
||||
|
||||
test('isWideningCall is true only for the one act that needs the user', () => {
|
||||
assert.equal(isWideningCall('facet', { action: 'add', paths: ['x'] }), true)
|
||||
// Narrowing and reading cannot show the agent anything new.
|
||||
|
||||
Reference in new issue
Block a user