Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a40040ec17 | ||
|
|
8ab3299694 | ||
|
|
a9a25490db | ||
|
|
b0902017fd |
No files matched your search
@@ -2,6 +2,15 @@
|
|||||||
|
|
||||||
Every release, newest first, generated from the commits in each release.
|
Every release, newest first, generated from the commits in each release.
|
||||||
|
|
||||||
|
## v0.3.1 — 2026-09-27
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- a delegated session inherits the facet it was spawned under
|
||||||
|
- judge a search that names no path against the directory it would use
|
||||||
|
- name the allowed-paths action for what it adds, a path or a file
|
||||||
|
|
||||||
|
|
||||||
## v0.3.0 — 2026-09-27
|
## v0.3.0 — 2026-09-27
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -48,6 +48,15 @@ wrong, and an agent that cannot reach a shared type does not stop needing it.
|
|||||||
So an out-of-scope file call is put to you, and saying yes records the grant for
|
So an out-of-scope file call is put to you, and saying yes records the grant for
|
||||||
the rest of the conversation.
|
the rest of the conversation.
|
||||||
|
|
||||||
|
**A tool that names no path is judged on the path it would use.** `grep`, `glob`
|
||||||
|
and `recall` all default to a directory when the model omits one — the session
|
||||||
|
directory for the first two, a marker-chosen one for the third — and on a session
|
||||||
|
whose facet is narrower than its directory, that default reads outside the facet.
|
||||||
|
An absent argument is not an absent path, so those three are judged against the
|
||||||
|
default they would have searched, and the refusal says which argument to add.
|
||||||
|
`lib/scope.js` holds the list; a tool with no path argument at all is still left
|
||||||
|
alone, because it has no default that could leave.
|
||||||
|
|
||||||
### The `facet` tool
|
### The `facet` tool
|
||||||
|
|
||||||
| action | effect |
|
| action | effect |
|
||||||
@@ -145,6 +154,15 @@ and your root otherwise. So an agent that goes wrong cannot widen its own scope,
|
|||||||
and `facet action=reset` returns it to what you declared rather than to the
|
and `facet action=reset` returns it to what you declared rather than to the
|
||||||
session directory — landing on the directory would have made `reset` a widening.
|
session directory — landing on the directory would have made `reset` a widening.
|
||||||
|
|
||||||
|
**A session spawned or forked from a scoped one inherits its root.** Your
|
||||||
|
declaration is keyed by session id, and a subagent or a fork has none of its own,
|
||||||
|
so without this its facet would be its own working directory — one level up, and
|
||||||
|
a way to delegate around the scope rather than work inside it. The inherited root
|
||||||
|
already includes the parent's own narrowing, so delegating is not a way back out
|
||||||
|
of a focus the agent set for itself either, and it is recorded per level, so it
|
||||||
|
holds at any depth of delegation. It applies only where you made no statement:
|
||||||
|
a declaration for the child session is the more specific answer and stands.
|
||||||
|
|
||||||
You set the declaration from the **crosshair button on the composer tool row**,
|
You set the declaration from the **crosshair button on the composer tool row**,
|
||||||
which appears only in sessions running the `facet` preset. It shows the focus and
|
which appears only in sessions running the `facet` preset. It shows the focus and
|
||||||
the allowed paths, adds and removes them, and carries the mode details and usage
|
the allowed paths, adds and removes them, and carries the mode details and usage
|
||||||
@@ -161,7 +179,8 @@ a breadcrumb trail, a hidden-entries toggle — driven through
|
|||||||
stored in the form that keeps its meaning: `/work/root/src/shared` becomes
|
stored in the form that keeps its meaning: `/work/root/src/shared` becomes
|
||||||
`src/shared` when the session started in `/work/root`. The picker's own path field
|
`src/shared` when the session started in `/work/root`. The picker's own path field
|
||||||
stays editable, because the Host lists folders and an extra may legitimately name
|
stays editable, because the Host lists folders and an extra may legitimately name
|
||||||
a file.
|
a file — which is why that action reads **Add path or file** and its field **Path
|
||||||
|
or file**, rather than promising a folder the list would then fail to show.
|
||||||
|
|
||||||
Because the panel owns widening, `facet action=add` is the *other* path and the
|
Because the panel owns widening, `facet action=add` is the *other* path and the
|
||||||
narrower one: it is gated on an approval channel, and a deployment with none — the
|
narrower one: it is gated on an approval channel, and a deployment with none — the
|
||||||
@@ -207,7 +226,10 @@ Honest boundaries, because each one is a decision rather than an oversight:
|
|||||||
- **`bash` is not guarded.** A shell command cannot be judged reliably from
|
- **`bash` is not guarded.** A shell command cannot be judged reliably from
|
||||||
argv, so the facet is enforced on the file tools and `bash` remains a
|
argv, so the facet is enforced on the file tools and `bash` remains a
|
||||||
legitimate way out. The prompt tells the model this rather than pretending
|
legitimate way out. The prompt tells the model this rather than pretending
|
||||||
otherwise.
|
otherwise. It is not a theoretical hole: the first deployment to run this had
|
||||||
|
an agent scoped to one module use a shell command to parse a config file
|
||||||
|
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** —
|
- **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
|
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.
|
tools whose path argument is a plain top-level string.
|
||||||
@@ -224,26 +246,31 @@ Honest boundaries, because each one is a decision rather than an oversight:
|
|||||||
|
|
||||||
Verified:
|
Verified:
|
||||||
|
|
||||||
- 73 tests (`npm test`) over the scope algebra, the policy state, the guard, and
|
- 88 tests (`npm test`) over the scope algebra, the policy state, the guard, and
|
||||||
the browser half — including that containment is decided on canonical targets
|
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
|
(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
|
not a parent (`/a/room` does not contain `/a/roommate`), that a malformed tool
|
||||||
call never makes the guard throw, that a live `mode` edit decides the next call
|
call never makes the guard throw, that a live `mode` edit decides the next call
|
||||||
without the guard being remounted, that an agent narrowing the user has since
|
without the guard being remounted, that an agent narrowing the user has since
|
||||||
narrowed past is dropped rather than honoured, that `reset` lands on the
|
narrowed past is dropped rather than honoured, that `reset` lands on the
|
||||||
declared scope rather than the session directory, and that every `facet` result
|
declared scope rather than the session directory, that a search naming no path
|
||||||
satisfies the tool's own declared output schema.
|
is refused when the directory it defaults to is outside the facet, that a
|
||||||
|
delegated session inherits its parent's root at any depth and is not a way back
|
||||||
|
out of a self-narrowing, 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
|
- The bundle's patch layers parse, merge and land correctly against the real
|
||||||
profile: `dsh --profile web --patch ./cordis.patch.yml --patch
|
profile: `dsh --profile web --patch ./cordis.patch.yml --patch
|
||||||
./presets/facet.patch.yml --dump-config` shows `facet-policy`, `preset-facet`,
|
./presets/facet.patch.yml --dump-config` shows `facet-policy`, `preset-facet`,
|
||||||
the `facet-guard` row and the compaction config, with `preset-standard`
|
the `facet-guard` row and the compaction config, with `preset-standard`
|
||||||
untouched. The optional `standard-compaction` overlay was checked the same way.
|
untouched. The optional `standard-compaction` overlay was checked the same way.
|
||||||
|
|
||||||
**Not yet verified: a live session.** The plugin has not been loaded by a running
|
**Verified live.** The bundle is installed in a `web` profile and composing
|
||||||
harness, because that needs the bundle installed. The first thing to check after
|
sessions: the runtime binding is in the running session's context, the crosshair
|
||||||
installing is that `preset-facet` is not `broken` — a preset whose child row
|
panel writes the declaration, and the guard decides the calls it names. That is
|
||||||
fails to resolve still appears on the roster, with its diagnostic, and cannot
|
also where the `bash` boundary above was confirmed the hard way. The first thing
|
||||||
compose a session:
|
to check after any change is still that `preset-facet` is not `broken` — a preset
|
||||||
|
whose child row fails to resolve still appears on the roster, with its
|
||||||
|
diagnostic, and cannot compose a session:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
dsh --profile web --dump-config | grep -A 3 preset-facet
|
dsh --profile web --dump-config | grep -A 3 preset-facet
|
||||||
@@ -308,7 +335,7 @@ lib/scope.js the pure half — argument extraction, text, reason
|
|||||||
lib/guard.js preset row: rule, binding, tool, pre-execute guard
|
lib/guard.js preset row: rule, binding, tool, pre-execute guard
|
||||||
presets/facet.patch.yml the `facet` agent preset
|
presets/facet.patch.yml the `facet` agent preset
|
||||||
presets/standard-compaction.patch.yml optional: the same budget for `standard`
|
presets/standard-compaction.patch.yml optional: the same budget for `standard`
|
||||||
test/ 78 tests
|
test/ 88 tests
|
||||||
```
|
```
|
||||||
|
|
||||||
`client/client.js` is a browser half rather than a module the host imports, and
|
`client/client.js` is a browser half rather than a module the host imports, and
|
||||||
|
|||||||
+13
-4
@@ -680,7 +680,7 @@ window.__ModuleLoader__.load({
|
|||||||
return h(Modal, {
|
return h(Modal, {
|
||||||
open: true,
|
open: true,
|
||||||
onClose,
|
onClose,
|
||||||
title: target === 'focus' ? 'Choose the focus folder' : 'Add a folder or a path',
|
title: target === 'focus' ? 'Choose the focus folder' : 'Add a path or a file',
|
||||||
closeLabel: 'Close',
|
closeLabel: 'Close',
|
||||||
className: PICKER_CLASS,
|
className: PICKER_CLASS,
|
||||||
// One scroll region around everything but the footer, so the card is
|
// One scroll region around everything but the footer, so the card is
|
||||||
@@ -694,7 +694,7 @@ window.__ModuleLoader__.load({
|
|||||||
h(
|
h(
|
||||||
'div',
|
'div',
|
||||||
{ key: 'path' },
|
{ key: 'path' },
|
||||||
h('label', { style: labelStyle, htmlFor: 'facet-picker-path' }, target === 'focus' ? 'Folder' : 'Path'),
|
h('label', { style: labelStyle, htmlFor: 'facet-picker-path' }, target === 'focus' ? 'Folder' : 'Path or file'),
|
||||||
h('input', {
|
h('input', {
|
||||||
id: 'facet-picker-path',
|
id: 'facet-picker-path',
|
||||||
type: 'text',
|
type: 'text',
|
||||||
@@ -713,7 +713,16 @@ window.__ModuleLoader__.load({
|
|||||||
model.open(typed)
|
model.open(typed)
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
h('p', { style: hintStyle }, 'Relative to the session folder, or absolute. Enter lists whatever is there.'),
|
h(
|
||||||
|
'p',
|
||||||
|
{ style: hintStyle },
|
||||||
|
target === 'focus'
|
||||||
|
? 'Relative to the session folder, or absolute. Enter lists whatever is there.'
|
||||||
|
: // The list holds folders only — the Host's browse primitive has no
|
||||||
|
// file rows — so the box is where a file is named, and saying so
|
||||||
|
// is the difference between a dead end and an instruction.
|
||||||
|
'Relative to the session folder, or absolute. The list holds folders; type a file\u2019s name to add the file itself.',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
h(
|
h(
|
||||||
'div',
|
'div',
|
||||||
@@ -1015,7 +1024,7 @@ window.__ModuleLoader__.load({
|
|||||||
h(
|
h(
|
||||||
'button',
|
'button',
|
||||||
{ type: 'button', style: quietButtonStyle, disabled: !canBrowse, onClick: () => openPicker('extra') },
|
{ type: 'button', style: quietButtonStyle, disabled: !canBrowse, onClick: () => openPicker('extra') },
|
||||||
'+ Add folder or path\u2026',
|
'+ Add path or file\u2026',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
h(
|
h(
|
||||||
|
|||||||
+16
-1
@@ -37,6 +37,8 @@ import {
|
|||||||
FACET_TOOL,
|
FACET_TOOL,
|
||||||
facetContextText,
|
facetContextText,
|
||||||
facetRuleText,
|
facetRuleText,
|
||||||
|
IMPLICIT_SESSION_PATHS,
|
||||||
|
implicitSearchReason,
|
||||||
isWideningCall,
|
isWideningCall,
|
||||||
outsideReason,
|
outsideReason,
|
||||||
pathArgumentsFor,
|
pathArgumentsFor,
|
||||||
@@ -181,7 +183,20 @@ export function apply(ctx, config) {
|
|||||||
if (scope === undefined) return undefined
|
if (scope === undefined) return undefined
|
||||||
|
|
||||||
const paths = pathArgumentsFor(exec.name, exec.arguments)
|
const paths = pathArgumentsFor(exec.name, exec.arguments)
|
||||||
if (paths.length === 0) return undefined
|
if (paths.length === 0) {
|
||||||
|
// A tool that names no path is judged against the path it will actually
|
||||||
|
// use. For most of them that is nothing — a tool with no path argument
|
||||||
|
// cannot leave the facet. For the ones whose own default is a directory it
|
||||||
|
// is the session directory, which a narrowed facet does not contain, and
|
||||||
|
// "no opinion" there would hand the model a read the guard exists to
|
||||||
|
// refuse. The containment test is the same one; only the path is ours
|
||||||
|
// rather than the model's.
|
||||||
|
if (!IMPLICIT_SESSION_PATHS.includes(exec.name)) return undefined
|
||||||
|
const verdict = await inside(scope, scope.cwd, exec.signal)
|
||||||
|
if (verdict.inside) return undefined
|
||||||
|
const kind = mode === 'deny' ? 'deny' : 'ask'
|
||||||
|
return { kind, reason: implicitSearchReason({ cwd: scope.cwd, root: scope.root }) }
|
||||||
|
}
|
||||||
|
|
||||||
for (const raw of paths) {
|
for (const raw of paths) {
|
||||||
const verdict = await inside(scope, raw, exec.signal)
|
const verdict = await inside(scope, raw, exec.signal)
|
||||||
|
|||||||
+94
-7
@@ -97,6 +97,29 @@ export function createFacetPolicy(config) {
|
|||||||
const grants = new Map()
|
const grants = new Map()
|
||||||
/** @type {Map<string, string>} session id → the agent's narrowing focus, absolute. */
|
/** @type {Map<string, string>} session id → the agent's narrowing focus, absolute. */
|
||||||
const narrowed = new Map()
|
const narrowed = new Map()
|
||||||
|
/**
|
||||||
|
* The root resolved for each session, recorded as it is computed.
|
||||||
|
*
|
||||||
|
* A session spawned or forked from this one has no declaration of its own, so
|
||||||
|
* without this its facet would be its own working directory — wider than the
|
||||||
|
* conversation it came from, which is the one direction this whole plugin
|
||||||
|
* promises cannot happen. The recorded root already includes the parent's own
|
||||||
|
* narrowing, so a child is never wider than the parent is *now*, and the
|
||||||
|
* record's existence is what makes the inheritance work per level rather than
|
||||||
|
* for one hop.
|
||||||
|
*
|
||||||
|
* @type {Map<string, string>} session id → the root in force for it.
|
||||||
|
*/
|
||||||
|
const roots = new Map()
|
||||||
|
/**
|
||||||
|
* Child session id → the session it inherited from, for as long as both live.
|
||||||
|
*
|
||||||
|
* Kept so {@link forget} can tell a root nobody needs any more from one a
|
||||||
|
* delegated child is still answering to.
|
||||||
|
*
|
||||||
|
* @type {Map<string, string>}
|
||||||
|
*/
|
||||||
|
const spawnedFrom = new Map()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* What the user declared for one session, read fresh.
|
* What the user declared for one session, read fresh.
|
||||||
@@ -112,6 +135,23 @@ export function createFacetPolicy(config) {
|
|||||||
return entry !== null && typeof entry === 'object' ? entry : undefined
|
return entry !== null && typeof entry === 'object' ? entry : undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The session this one was spawned or forked from, when the header says so.
|
||||||
|
*
|
||||||
|
* The harness's own durable lineage field, so the link survives a restart and
|
||||||
|
* a child whose parent is no longer running is still contained. `fork` records
|
||||||
|
* the session it was seeded from and a subagent its direct parent; both are
|
||||||
|
* one conversation's work continuing, which is what makes inheriting the right
|
||||||
|
* answer for either.
|
||||||
|
*
|
||||||
|
* @param {{session?: {header?: {parentSession?: unknown}}}|undefined} agent - the calling agent.
|
||||||
|
* @returns {string|undefined} the parent's session id.
|
||||||
|
*/
|
||||||
|
function parentOf(agent) {
|
||||||
|
const parent = agent?.session?.header?.parentSession
|
||||||
|
return typeof parent === 'string' && parent !== '' ? parent : undefined
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The root in force for one session.
|
* The root in force for one session.
|
||||||
*
|
*
|
||||||
@@ -123,16 +163,22 @@ export function createFacetPolicy(config) {
|
|||||||
* place — this one only has to notice a root that has since moved out from
|
* place — this one only has to notice a root that has since moved out from
|
||||||
* under it.
|
* under it.
|
||||||
*
|
*
|
||||||
|
* Inheritance is the same kind of test, and it is skipped when the user made a
|
||||||
|
* declaration of their own: that is their decision about *this* session, and
|
||||||
|
* the point of inheriting is to answer the case where they made none.
|
||||||
|
*
|
||||||
* @param {string|undefined} sessionId - the session.
|
* @param {string|undefined} sessionId - the session.
|
||||||
* @param {string} sessionCwd - its resolved working directory.
|
* @param {string} sessionCwd - its resolved working directory.
|
||||||
|
* @param {string} [inherited] - the root of the session it came from, if known.
|
||||||
* @returns {string} the absolute facet root.
|
* @returns {string} the absolute facet root.
|
||||||
*/
|
*/
|
||||||
function rootFor(sessionId, sessionCwd) {
|
function rootFor(sessionId, sessionCwd, inherited) {
|
||||||
const declared = declaredScope(sessionId)?.focus
|
const declared = declaredScope(sessionId)?.focus
|
||||||
const base = typeof declared === 'string' && declared.trim() !== '' ? resolve(sessionCwd, declared) : sessionCwd
|
const stated = typeof declared === 'string' && declared.trim() !== ''
|
||||||
|
const own = stated ? resolve(sessionCwd, declared) : sessionCwd
|
||||||
|
const base = !stated && inherited !== undefined && within(inherited, own) ? inherited : own
|
||||||
const agentFocus = sessionId === undefined ? undefined : narrowed.get(sessionId)
|
const agentFocus = sessionId === undefined ? undefined : narrowed.get(sessionId)
|
||||||
if (agentFocus === undefined) return base
|
if (agentFocus !== undefined && within(agentFocus, base)) return agentFocus
|
||||||
if (agentFocus === base || agentFocus.startsWith(base.endsWith(sep) ? base : `${base}${sep}`)) return agentFocus
|
|
||||||
return base
|
return base
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,7 +208,13 @@ export function createFacetPolicy(config) {
|
|||||||
* resolve against. A declaration written relative to the session keeps the
|
* resolve against. A declaration written relative to the session keeps the
|
||||||
* same meaning whatever the session is focused on.
|
* same meaning whatever the session is focused on.
|
||||||
*
|
*
|
||||||
* @param {{session?: {header?: {cwd?: unknown}, id?: unknown}}|undefined} agent - the calling agent.
|
* Resolving a scope is also where a session's own root is *recorded*, which is
|
||||||
|
* what a session spawned from it later inherits. Every session resolves a
|
||||||
|
* scope before it can call anything — the binding is assembled for each model
|
||||||
|
* request, and the guard classifies each tool call — so a parent's root is
|
||||||
|
* always on the record by the time it can spawn or fork.
|
||||||
|
*
|
||||||
|
* @param {{session?: {header?: {cwd?: unknown, parentSession?: unknown}, id?: unknown}}|undefined} agent - the calling agent.
|
||||||
* @returns {FacetScope|undefined} the scope.
|
* @returns {FacetScope|undefined} the scope.
|
||||||
*/
|
*/
|
||||||
function scopeFor(agent) {
|
function scopeFor(agent) {
|
||||||
@@ -170,9 +222,13 @@ export function createFacetPolicy(config) {
|
|||||||
if (typeof cwd !== 'string' || cwd.trim() === '') return undefined
|
if (typeof cwd !== 'string' || cwd.trim() === '') return undefined
|
||||||
const sessionCwd = resolve(cwd)
|
const sessionCwd = resolve(cwd)
|
||||||
const sessionId = idOf(agent)
|
const sessionId = idOf(agent)
|
||||||
|
const parent = parentOf(agent)
|
||||||
|
if (sessionId !== undefined && parent !== undefined) spawnedFrom.set(sessionId, parent)
|
||||||
|
const root = rootFor(sessionId, sessionCwd, parent === undefined ? undefined : roots.get(parent))
|
||||||
|
if (sessionId !== undefined) roots.set(sessionId, root)
|
||||||
return {
|
return {
|
||||||
cwd: sessionCwd,
|
cwd: sessionCwd,
|
||||||
root: rootFor(sessionId, sessionCwd),
|
root,
|
||||||
extras: extrasFor(agent, sessionCwd),
|
extras: extrasFor(agent, sessionCwd),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -284,10 +340,22 @@ export function createFacetPolicy(config) {
|
|||||||
return [...(grants.get(sessionId) ?? [])]
|
return [...(grants.get(sessionId) ?? [])]
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Drop a finished session's grants. Called on `session/disposed`. */
|
/**
|
||||||
|
* Drop a finished session's state. Called on `session/disposed`.
|
||||||
|
*
|
||||||
|
* The root is the one entry that is not simply dropped: a session spawned from
|
||||||
|
* this one may still be running, and it answers to the facet it was spawned
|
||||||
|
* under. So the record is kept while any live session still records this one
|
||||||
|
* as its parent, and released the moment none does. Without that, disposing a
|
||||||
|
* parent would quietly widen its children back to their own directory.
|
||||||
|
*
|
||||||
|
* @param {string} sessionId - the session being disposed.
|
||||||
|
*/
|
||||||
function forget(sessionId) {
|
function forget(sessionId) {
|
||||||
grants.delete(sessionId)
|
grants.delete(sessionId)
|
||||||
narrowed.delete(sessionId)
|
narrowed.delete(sessionId)
|
||||||
|
spawnedFrom.delete(sessionId)
|
||||||
|
if (![...spawnedFrom.values()].includes(sessionId)) roots.delete(sessionId)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -325,6 +393,25 @@ function isPath(value) {
|
|||||||
return typeof value === 'string' && value.trim() !== ''
|
return typeof value === 'string' && value.trim() !== ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether one absolute path is the other, or sits inside it.
|
||||||
|
*
|
||||||
|
* A string test, deliberately, and the only one in this module. The guard's
|
||||||
|
* containment check — the one that decides whether a *call* may proceed — runs
|
||||||
|
* on canonical filesystem targets, because a symlink inside the facet must not
|
||||||
|
* open it. This one only compares two roots the plugin itself derived from the
|
||||||
|
* session directory, where there is nothing to resolve and a symlink would have
|
||||||
|
* had to be introduced by the declaration.
|
||||||
|
*
|
||||||
|
* @param {string} inner - the path that may be inside.
|
||||||
|
* @param {string} outer - the path that may contain it.
|
||||||
|
* @returns {boolean} whether it is inside.
|
||||||
|
*/
|
||||||
|
function within(inner, outer) {
|
||||||
|
if (inner === outer) return true
|
||||||
|
return inner.startsWith(outer.endsWith(sep) ? outer : `${outer}${sep}`)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The session id of a calling agent, when it has one.
|
* The session id of a calling agent, when it has one.
|
||||||
*
|
*
|
||||||
|
|||||||
+49
-1
@@ -54,6 +54,28 @@ export const PATH_ARGUMENTS = Object.freeze({
|
|||||||
recall: ['path', 'focus'],
|
recall: ['path', 'focus'],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tools that will search the session directory when the model names no path.
|
||||||
|
*
|
||||||
|
* The guard's rule is that a call naming no path is not judged, because a tool
|
||||||
|
* that names no path cannot leave the facet. That holds for a tool with no path
|
||||||
|
* argument at all, and fails for these three: their *own* default is the session
|
||||||
|
* workspace. `grep` and `glob` document both their path arguments as "Defaults to
|
||||||
|
* the session workspace", and `recall` falls back to a directory its own marker
|
||||||
|
* search picks — an ancestor of the facet whenever the facet carries no
|
||||||
|
* `CONTROLLER.md` of its own.
|
||||||
|
*
|
||||||
|
* So on any session whose facet is narrower than its directory — every session
|
||||||
|
* whose focus was set from the panel rather than by starting the conversation in
|
||||||
|
* the folder — a bare `grep` reads outside the facet. An absent argument is not
|
||||||
|
* an absent path; it is the default one, and that is the path the guard judges.
|
||||||
|
*
|
||||||
|
* `recall` is another package's tool and is named here because the coupling to
|
||||||
|
* its two path arguments already exists in {@link PATH_ARGUMENTS}: leaving it
|
||||||
|
* out would keep a read path the table claims to cover.
|
||||||
|
*/
|
||||||
|
export const IMPLICIT_SESSION_PATHS = Object.freeze(['grep', 'glob', 'recall'])
|
||||||
|
|
||||||
/** The tool this plugin registers, and the action on it that widens the scope. */
|
/** The tool this plugin registers, and the action on it that widens the scope. */
|
||||||
export const FACET_TOOL = 'facet'
|
export const FACET_TOOL = 'facet'
|
||||||
export const WIDENING_ACTION = 'add'
|
export const WIDENING_ACTION = 'add'
|
||||||
@@ -66,7 +88,10 @@ export const WIDENING_ACTION = 'add'
|
|||||||
* Anything that is not a non-empty string is skipped.
|
* Anything that is not a non-empty string is skipped.
|
||||||
*
|
*
|
||||||
* An empty result means "no opinion" — either the tool names no path (so it
|
* An empty result means "no opinion" — either the tool names no path (so it
|
||||||
* cannot leave the facet) or it names one in a shape we refuse to guess at.
|
* cannot leave the facet) or it names one in a shape we refuse to guess at. The
|
||||||
|
* first half of that is not true of every tool: the ones whose own default is a
|
||||||
|
* directory are listed in {@link IMPLICIT_SESSION_PATHS}, and the guard judges
|
||||||
|
* them against the directory they will actually search.
|
||||||
*
|
*
|
||||||
* @param {string} toolName - the tool being called.
|
* @param {string} toolName - the tool being called.
|
||||||
* @param {unknown} args - the raw model arguments.
|
* @param {unknown} args - the raw model arguments.
|
||||||
@@ -236,6 +261,29 @@ export function outsideReason(input) {
|
|||||||
return `${what} is ${verb} — this session's facet is ${root}. Ask the user to grant it (\`facet action=add\`), or work within the facet.`
|
return `${what} is ${verb} — this session's facet is ${root}. Ask the user to grant it (\`facet action=add\`), or work within the facet.`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Why a search that named no directory is being questioned.
|
||||||
|
*
|
||||||
|
* A separate sentence from {@link outsideReason} because the fault is different.
|
||||||
|
* There, the model named a path outside the facet and is told which one. Here it
|
||||||
|
* named nothing, so the path at issue is one it never wrote: the tool's own
|
||||||
|
* default. Saying so is the whole remedy — the fix is a second argument, not a
|
||||||
|
* grant — so the reason names the directory the search would have covered and
|
||||||
|
* the one it had to stay in.
|
||||||
|
*
|
||||||
|
* @param {object} input
|
||||||
|
* @param {string} input.cwd - the session working directory the tool defaults to.
|
||||||
|
* @param {string} input.root - the facet root.
|
||||||
|
* @returns {string} the reason.
|
||||||
|
*/
|
||||||
|
export function implicitSearchReason(input) {
|
||||||
|
const { cwd, root } = input
|
||||||
|
return (
|
||||||
|
`This search names no \`path\`, so it would cover this session's directory ${cwd} — and this session's ` +
|
||||||
|
`facet is ${root}. Name a folder inside the facet, or ask the user to grant the one you need.`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Why widening the scope is being put to the user.
|
* Why widening the scope is being put to the user.
|
||||||
*
|
*
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dsh-facet",
|
"name": "dsh-facet",
|
||||||
"version": "0.3.0",
|
"version": "0.3.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "Scope an agent session to one facet of a multi-faceted system: the session's own folder, plus whatever files the user grants it.",
|
"description": "Scope an agent session to one facet of a multi-faceted system: the session's own folder, plus whatever files the user grants it.",
|
||||||
|
|||||||
+39
-2
@@ -423,7 +423,7 @@ test('the panel renders the scope, the guidance, and a way to add and remove', a
|
|||||||
// already did.
|
// already did.
|
||||||
assert.ok(buttons.some((button) => labelOf(button) === 'Browse\u2026'))
|
assert.ok(buttons.some((button) => labelOf(button) === 'Browse\u2026'))
|
||||||
assert.ok(buttons.some((button) => labelOf(button) === 'Clear'))
|
assert.ok(buttons.some((button) => labelOf(button) === 'Clear'))
|
||||||
assert.ok(buttons.some((button) => labelOf(button) === '+ Add folder or path\u2026'))
|
assert.ok(buttons.some((button) => labelOf(button) === '+ Add path or file\u2026'))
|
||||||
assert.ok(!buttons.some((button) => labelOf(button) === 'Set'))
|
assert.ok(!buttons.some((button) => labelOf(button) === 'Set'))
|
||||||
assert.deepEqual(inputs, [], 'the panel itself has no free-text box left')
|
assert.deepEqual(inputs, [], 'the panel itself has no free-text box left')
|
||||||
})
|
})
|
||||||
@@ -456,7 +456,7 @@ test('a deployment with no directory browser keeps the panel and says so', async
|
|||||||
)
|
)
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
buttonsOf(tree)
|
buttonsOf(tree)
|
||||||
.filter((button) => label(button) === '+ Add folder or path\u2026')
|
.filter((button) => label(button) === '+ Add path or file\u2026')
|
||||||
.map((button) => button.props.disabled),
|
.map((button) => button.props.disabled),
|
||||||
[true],
|
[true],
|
||||||
)
|
)
|
||||||
@@ -520,7 +520,10 @@ function walkTree(node, visit) {
|
|||||||
}
|
}
|
||||||
visit(node)
|
visit(node)
|
||||||
if (Array.isArray(node.children)) node.children.forEach((child) => walkTree(child, visit))
|
if (Array.isArray(node.children)) node.children.forEach((child) => walkTree(child, visit))
|
||||||
|
// `footer` is a prop rather than a child, and it is rendered: a control there
|
||||||
|
// is as much part of the tree as one in the body.
|
||||||
walkTree(node.props?.children, visit)
|
walkTree(node.props?.children, visit)
|
||||||
|
walkTree(node.props?.footer, visit)
|
||||||
}
|
}
|
||||||
|
|
||||||
test('a path is declared relative to the session folder wherever it can be', async () => {
|
test('a path is declared relative to the session folder wherever it can be', async () => {
|
||||||
@@ -661,3 +664,37 @@ test('the picker lists folders, hides hidden ones until asked, and answers in de
|
|||||||
await settle()
|
await settle()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('the extras picker names what it accepts and says what the list holds', async () => {
|
||||||
|
const { module: mod } = await loadClient()
|
||||||
|
|
||||||
|
const model = new mod.DirectoryPickerModel({
|
||||||
|
list: () => Promise.resolve(listingFixture()),
|
||||||
|
root: '/work/root',
|
||||||
|
start: '/work/root/src',
|
||||||
|
})
|
||||||
|
await settle()
|
||||||
|
|
||||||
|
const tree = mod.DirectoryPicker({
|
||||||
|
model,
|
||||||
|
root: '/work/root',
|
||||||
|
target: 'extra',
|
||||||
|
disabled: false,
|
||||||
|
onClose: () => {},
|
||||||
|
onPick: () => {},
|
||||||
|
})
|
||||||
|
|
||||||
|
// "folder or path" promised one thing and offered another: the rows are
|
||||||
|
// folders, and a file is added by naming it. The copy says both.
|
||||||
|
assert.equal(tree.props.title, 'Add a path or a file')
|
||||||
|
const texts = textsOf(tree)
|
||||||
|
assert.ok(texts.includes('Path or file'), 'the field is named for what it accepts')
|
||||||
|
assert.ok(
|
||||||
|
texts.some((text) => text.includes('The list holds folders')),
|
||||||
|
'the copy explains why no file rows are shown',
|
||||||
|
)
|
||||||
|
assert.ok(
|
||||||
|
buttonsOf(tree).some((button) => (button.children ?? [])[0] === 'Add'),
|
||||||
|
'the action is Add for an extra, not Set focus',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
+125
-1
@@ -170,13 +170,59 @@ test('a prefix is not a parent', async () => {
|
|||||||
assert.equal(decision.kind, 'ask')
|
assert.equal(decision.kind, 'ask')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('an omitted path means the session directory, which is in scope', async () => {
|
test('an omitted path means the session directory, which here is the facet', async () => {
|
||||||
const { captured } = harness()
|
const { captured } = harness()
|
||||||
|
// Allowed because the default and the facet are the same folder — not because
|
||||||
|
// the call named nothing. The next test is the case where they differ.
|
||||||
assert.deepEqual(await dispatch(captured, { name: 'glob', args: { pattern: '**/*.ts' }, agent: agent() }), {
|
assert.deepEqual(await dispatch(captured, { name: 'glob', args: { pattern: '**/*.ts' }, agent: agent() }), {
|
||||||
kind: 'allow',
|
kind: 'allow',
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('a search that names no path is judged against the directory it would cover', async () => {
|
||||||
|
// The session directory is the facet's parent here: the user narrowed this
|
||||||
|
// conversation to `inner`, while the search tools still default to the whole
|
||||||
|
// session directory. An absent argument is not an absent path — it is the
|
||||||
|
// default one, and the default one leaves the facet.
|
||||||
|
const { captured } = harness({ config: { mode: 'ask', scopes: { 'session-1': { focus: 'inner' } } } })
|
||||||
|
|
||||||
|
const decision = await dispatch(captured, { name: 'grep', args: { pattern: 'motion_learning' }, agent: agent() })
|
||||||
|
assert.equal(decision.kind, 'ask')
|
||||||
|
assert.match(decision.reason, /names no `path`/)
|
||||||
|
assert.match(decision.reason, /inner/, 'the reason names the boundary the call crossed')
|
||||||
|
|
||||||
|
// Naming the folder is the whole remedy, and it costs no grant.
|
||||||
|
assert.deepEqual(
|
||||||
|
await dispatch(captured, { name: 'grep', args: { pattern: 'x', path: 'inner' }, agent: agent() }),
|
||||||
|
{ kind: 'allow' },
|
||||||
|
)
|
||||||
|
// The same rule reaches the other two tools whose default is a directory.
|
||||||
|
assert.equal(
|
||||||
|
(await dispatch(captured, { name: 'glob', args: { pattern: '**/*.ts' }, agent: agent() })).kind,
|
||||||
|
'ask',
|
||||||
|
)
|
||||||
|
assert.equal(
|
||||||
|
(await dispatch(captured, { name: 'recall', args: { query: 'motion learning' }, agent: agent() })).kind,
|
||||||
|
'ask',
|
||||||
|
)
|
||||||
|
// A tool with no path argument at all is still left alone: it has no default
|
||||||
|
// that could leave the facet.
|
||||||
|
assert.deepEqual(await dispatch(captured, { name: 'todo_write', args: { todos: [] }, agent: agent() }), {
|
||||||
|
kind: 'allow',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
test('recall is judged on the scope it names, because that is what it will search', async () => {
|
||||||
|
const { captured } = harness({ config: { mode: 'deny', scopes: { 'session-1': { focus: 'inner' } } } })
|
||||||
|
assert.deepEqual(await dispatch(captured, { name: 'recall', args: { query: 'x', focus: 'inner' }, agent: agent() }), {
|
||||||
|
kind: 'allow',
|
||||||
|
})
|
||||||
|
assert.equal(
|
||||||
|
(await dispatch(captured, { name: 'recall', args: { query: 'x', path: '..' }, agent: agent() })).kind,
|
||||||
|
'deny',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
test('tools the guard cannot judge are left alone, deliberately', async () => {
|
test('tools the guard cannot judge are left alone, deliberately', async () => {
|
||||||
const { captured } = harness()
|
const { captured } = harness()
|
||||||
// A shell command cannot be read reliably from argv, so the facet is enforced
|
// A shell command cannot be read reliably from argv, so the facet is enforced
|
||||||
@@ -195,6 +241,84 @@ test('an agent with no working directory is not scoped', async () => {
|
|||||||
assert.deepEqual(await dispatch(captured, { name: 'read', args: { file_path: '/etc/hosts' } }), { kind: 'allow' })
|
assert.deepEqual(await dispatch(captured, { name: 'read', args: { file_path: '/etc/hosts' } }), { kind: 'allow' })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// ── delegated sessions ───────────────────────────────────────────────────────
|
||||||
|
//
|
||||||
|
// A session spawned or forked from a scoped one has no declaration of its own,
|
||||||
|
// and the user's declaration is keyed by session id. Without inheritance its
|
||||||
|
// facet would be its own working directory — wider than the conversation it came
|
||||||
|
// from, which is the one direction this plugin promises cannot happen.
|
||||||
|
|
||||||
|
/** A session that was spawned from another, as the harness records lineage. */
|
||||||
|
const childOf = (parentId, id = 'child-1', cwd = facet) => ({
|
||||||
|
session: { id, header: { cwd, parentSession: parentId } },
|
||||||
|
})
|
||||||
|
|
||||||
|
test('a session spawned from a scoped one starts inside the same facet', async () => {
|
||||||
|
const { captured } = harness({ config: { mode: 'ask', scopes: { 'session-1': { focus: 'inner' } } } })
|
||||||
|
|
||||||
|
// The parent's root is on the record as soon as it resolves a scope, which
|
||||||
|
// happens for every model request and every tool call — so before it can
|
||||||
|
// spawn anything.
|
||||||
|
assert.deepEqual(
|
||||||
|
await dispatch(captured, { name: 'read', args: { file_path: 'inner/index.ts' }, agent: agent() }),
|
||||||
|
{ kind: 'allow' },
|
||||||
|
)
|
||||||
|
|
||||||
|
const child = childOf('session-1')
|
||||||
|
// Without inheritance this would be ordinary work for the child: its root
|
||||||
|
// would be the session directory, one level up from its parent's facet.
|
||||||
|
const decision = await dispatch(captured, { name: 'read', args: { file_path: 'index.ts' }, agent: child })
|
||||||
|
assert.equal(decision.kind, 'ask')
|
||||||
|
assert.match(decision.reason, /inner/)
|
||||||
|
// Inside the inherited facet is inside the child's scope, as it should be.
|
||||||
|
assert.deepEqual(
|
||||||
|
await dispatch(captured, { name: 'read', args: { file_path: 'inner/index.ts' }, agent: child }),
|
||||||
|
{ kind: 'allow' },
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('inheritance holds at depth, and is not a way around a self-narrowing', async () => {
|
||||||
|
// No declaration: the user left the session at its directory, and the only
|
||||||
|
// thing that will keep a child inside `inner` is the inherited root.
|
||||||
|
const { captured } = harness({ config: { mode: 'deny' } })
|
||||||
|
await captured.tool.execute({ action: 'focus', paths: ['inner'] }, { agent: agent() })
|
||||||
|
|
||||||
|
const child = childOf('session-1')
|
||||||
|
const grandchild = childOf('child-1', 'grand-1')
|
||||||
|
// The child's own scope is resolved by its first call, which is what puts its
|
||||||
|
// root on the record for the grandchild to inherit.
|
||||||
|
for (const descendant of [child, grandchild]) {
|
||||||
|
assert.equal(
|
||||||
|
(await dispatch(captured, { name: 'read', args: { file_path: 'inner/index.ts' }, agent: descendant })).kind,
|
||||||
|
'allow',
|
||||||
|
`${descendant.session.id} is inside the inherited facet`,
|
||||||
|
)
|
||||||
|
assert.equal(
|
||||||
|
(await dispatch(captured, { name: 'read', args: { file_path: 'index.ts' }, agent: descendant })).kind,
|
||||||
|
'deny',
|
||||||
|
`${descendant.session.id} cannot delegate its way back out of the narrowing`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
test('a declaration for the child itself stands over what it would inherit', async () => {
|
||||||
|
const { captured } = harness({
|
||||||
|
config: { mode: 'ask', scopes: { 'session-1': { focus: 'inner' }, 'child-1': { focus: '.' } } },
|
||||||
|
})
|
||||||
|
assert.deepEqual(
|
||||||
|
await dispatch(captured, { name: 'read', args: { file_path: 'inner/index.ts' }, agent: agent() }),
|
||||||
|
{ kind: 'allow' },
|
||||||
|
)
|
||||||
|
|
||||||
|
// The user is the authority on this session too: a declaration made for the
|
||||||
|
// child is a statement about the child, and inheritance only answers the case
|
||||||
|
// where they made none.
|
||||||
|
assert.deepEqual(
|
||||||
|
await dispatch(captured, { name: 'read', args: { file_path: 'index.ts' }, agent: childOf('session-1') }),
|
||||||
|
{ kind: 'allow' },
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
test('a standing grant and a session grant both open the scope', async () => {
|
test('a standing grant and a session grant both open the scope', async () => {
|
||||||
const standing = harness({ extraRoots: ['../../shared'] })
|
const standing = harness({ extraRoots: ['../../shared'] })
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
|
|||||||
@@ -187,3 +187,61 @@ test('junk in a declaration is ignored rather than thrown on', () => {
|
|||||||
assert.deepEqual(policy.scopeFor(agentAt('/w', 's1')).extras, ['/w/ok'])
|
assert.deepEqual(policy.scopeFor(agentAt('/w', 's1')).extras, ['/w/ok'])
|
||||||
assert.equal(policy.scopeFor(agentAt('/w', 's2')).root, '/w')
|
assert.equal(policy.scopeFor(agentAt('/w', 's2')).root, '/w')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// ── delegated sessions ───────────────────────────────────────────────────────
|
||||||
|
//
|
||||||
|
// A session spawned or forked from this one has no declaration of its own, and
|
||||||
|
// the user's declaration is keyed by session id. What stops it starting wider
|
||||||
|
// than its parent is the parent's own resolved root, recorded as the parent
|
||||||
|
// resolves a scope — which it does for every model request and every tool call,
|
||||||
|
// so the record is always there before it can spawn anything.
|
||||||
|
|
||||||
|
/** An agent whose header carries the lineage the harness writes for a child. */
|
||||||
|
const spawned = (id, parentSession, cwd = '/w') => ({
|
||||||
|
session: { id, header: { cwd, parentSession } },
|
||||||
|
})
|
||||||
|
|
||||||
|
test('a session spawned from a scoped one inherits its root, at any depth', () => {
|
||||||
|
const policy = createFacetPolicy({ mode: 'deny', scopes: { s1: { focus: 'src/room' } } })
|
||||||
|
assert.equal(policy.scopeFor(agentAt('/w', 's1')).root, '/w/src/room')
|
||||||
|
|
||||||
|
const child = spawned('c1', 's1')
|
||||||
|
assert.equal(policy.scopeFor(child).root, '/w/src/room')
|
||||||
|
// Relative paths still resolve from the child's own directory, as for anyone.
|
||||||
|
assert.equal(policy.scopeFor(child).cwd, '/w')
|
||||||
|
assert.equal(policy.scopeFor(spawned('g1', 'c1')).root, '/w/src/room')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('a child is never wider than its parent is now, narrowing included', () => {
|
||||||
|
const policy = createFacetPolicy({ mode: 'deny' })
|
||||||
|
policy.narrowTo('s1', '/w/src/room')
|
||||||
|
|
||||||
|
// The narrowing is the agent's own decision; spawning a child is not a way to
|
||||||
|
// undo it, because the root the child inherits already includes it.
|
||||||
|
assert.equal(policy.scopeFor(agentAt('/w', 's1')).root, '/w/src/room')
|
||||||
|
assert.equal(policy.scopeFor(spawned('c1', 's1')).root, '/w/src/room')
|
||||||
|
})
|
||||||
|
|
||||||
|
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'))
|
||||||
|
|
||||||
|
// Inheritance answers the case where the user made no statement about this
|
||||||
|
// session; a statement they did make is the more specific one and stands.
|
||||||
|
assert.equal(policy.scopeFor(spawned('c1', 's1')).root, '/w')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('a root is kept while a session that inherited it is still alive', () => {
|
||||||
|
const policy = createFacetPolicy({ mode: 'deny', scopes: { s1: { focus: 'src/room' } } })
|
||||||
|
const child = spawned('c1', 's1')
|
||||||
|
policy.scopeFor(agentAt('/w', 's1'))
|
||||||
|
policy.scopeFor(child)
|
||||||
|
|
||||||
|
// Disposing the parent must not quietly widen the child that is still running.
|
||||||
|
policy.forget('s1')
|
||||||
|
assert.equal(policy.scopeFor(child).root, '/w/src/room')
|
||||||
|
|
||||||
|
// With nothing left to inherit it, the record goes too.
|
||||||
|
policy.forget('c1')
|
||||||
|
assert.equal(policy.scopeFor(agentAt('/w', 's1')).root, '/w/src/room')
|
||||||
|
})
|
||||||
Reference in new issue
Block a user