Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
912dd8ab23 | ||
|
|
387f7c3510 | ||
|
|
40574505f2 | ||
|
|
c48e9cabd9 | ||
|
|
4152c72730 | ||
|
|
1697c24c3c | ||
|
|
616cad75ce |
No files matched your search
@@ -2,6 +2,29 @@
|
||||
|
||||
Every release, newest first, generated from the commits in each release.
|
||||
|
||||
## v0.4.3 — 2026-11-09
|
||||
|
||||
### Fixed
|
||||
|
||||
- override the shipped standard preset in the compaction overlay
|
||||
- judge the working directory and the arguments a tool declares
|
||||
|
||||
|
||||
## v0.4.2 — 2026-11-06
|
||||
|
||||
### Fixed
|
||||
|
||||
- rebuild both shipped presets from the harness standard
|
||||
|
||||
### Documented
|
||||
|
||||
- install the latest release, not the 0.1 line
|
||||
|
||||
### Other
|
||||
|
||||
- fail when a preset drifts from the harness standard
|
||||
|
||||
|
||||
## v0.4.1 — 2026-10-19
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -74,7 +74,7 @@ because otherwise there would be no way to grant anything at all.
|
||||
From the repository, following releases:
|
||||
|
||||
```sh
|
||||
dsh plugin --profile web add "git+https://git.notexpectedyet.com/Not-Expected-Yet/dsh-facet.git#semver:^0.1.0"
|
||||
dsh plugin --profile web add "git+https://git.notexpectedyet.com/Not-Expected-Yet/dsh-facet.git#semver:>=0.1.0"
|
||||
dsh --profile web --dump-config | grep preset-facet # expect the row
|
||||
```
|
||||
|
||||
@@ -84,13 +84,16 @@ Or from a checkout, while working on the plugin itself:
|
||||
dsh plugin --profile web add "/path/to/dsh-facet"
|
||||
```
|
||||
|
||||
The `#semver:^0.1.0` fragment is the difference between an install that can be
|
||||
The `#semver:>=0.1.0` fragment is the difference between an install that can be
|
||||
updated and one that cannot. Leave it off and pnpm resolves the default branch to
|
||||
a **commit** and records that commit in `pnpm-lock.yaml` — `dsh plugin update`
|
||||
then has no version to move to, because there is nothing to move between. With
|
||||
the fragment, pnpm resolves against the repository's tags, which the release
|
||||
workflow creates on every push to `master`. The fragment needs a tag to resolve
|
||||
against, so it only works once the first release has been published.
|
||||
workflow creates on every push to `master`. The range is written `>=` rather
|
||||
than `^` because this package is still `0.x`: a caret range stops before the next
|
||||
minor, so `^0.1.0` can never reach the `0.4.x` line and would silently install an
|
||||
old release. The fragment needs a tag to resolve against, so it only works once
|
||||
the first release has been published.
|
||||
|
||||
Either way the command is `pnpm add` run inside the profile, and it registers the
|
||||
bundle in `dsh.profile.bundles` for you. A git-hosted plugin that builds on
|
||||
@@ -231,12 +234,30 @@ 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`
|
||||
changes.
|
||||
|
||||
### Preset drift, and why one dead row breaks the preset
|
||||
|
||||
A preset declaration mounts every row it lists, so a single row the harness no
|
||||
longer provides fails the whole declaration rather than just that tool: the
|
||||
roster shows the preset with a `broken` diagnostic and no session can compose it.
|
||||
That is how this bundle broke on dsh `0.2.2-rc.1`. The harness folded
|
||||
`list_agents` into `@deepseek-ai/dsh-tool-subagent-control` and stopped exporting
|
||||
its `./list-agents` subpath; the frozen copy still named it, the row could never
|
||||
start, and every session on the `facet` preset failed to resume.
|
||||
|
||||
`test/presets.test.js` now compares both files under `presets/` against the
|
||||
`standard` preset of the installed harness — after removing the documented
|
||||
deltas — and resolves every plugin name they list, so the next time the harness
|
||||
moves a row the copy fails the tests instead of failing sessions.
|
||||
|
||||
### Prompt variables, and why the preset's persona has no suffix
|
||||
|
||||
Both preset files used to copy the deployment's persona line, *Your working
|
||||
@@ -258,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:
|
||||
@@ -270,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
|
||||
@@ -285,7 +326,7 @@ Honest boundaries, because each one is a decision rather than an oversight:
|
||||
|
||||
Verified:
|
||||
|
||||
- 95 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
|
||||
@@ -298,8 +339,15 @@ Verified:
|
||||
out of a self-narrowing, that both listings normalise into one picker level and
|
||||
that a file listing the Host confines still leaves a browsable one, that no
|
||||
preset or contributed prompt text references a prompt variable the harness
|
||||
does not register, and that every `facet` result satisfies the tool's own
|
||||
declared output schema.
|
||||
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, 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`,
|
||||
@@ -357,15 +405,17 @@ would publish.
|
||||
## Development
|
||||
|
||||
```sh
|
||||
node scripts/dev-links.mjs # link the harness's cordis/schemastery/dsh-tools
|
||||
node scripts/dev-links.mjs # link the harness's cordis/schemastery/dsh-tools/js-yaml
|
||||
npm test
|
||||
```
|
||||
|
||||
`dev-links.mjs` links rather than installs those three packages, and for
|
||||
`dev-links.mjs` links rather than installs those four packages, and for
|
||||
`@deepseek-ai/cordis` that is a correctness requirement rather than tidiness: a
|
||||
second copy of Cordis means a second `Context` class, two service registries in
|
||||
one process, and a plugin whose services are invisible to the harness that loaded
|
||||
it.
|
||||
it. `js-yaml` is there so the preset-drift tests can read the harness's own
|
||||
`standard` patch; the scope search both share lives in
|
||||
`scripts/harness-scope.mjs`.
|
||||
|
||||
## Layout
|
||||
|
||||
@@ -377,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/ 95 tests
|
||||
test/ 107 tests
|
||||
```
|
||||
|
||||
`client/client.js` is a browser half rather than a module the host imports, and
|
||||
|
||||
+58
-9
@@ -101,6 +101,49 @@ export function apply(ctx, config) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The directory a relative argument will actually resolve against.
|
||||
*
|
||||
* The file tools resolve against the session's *current* working directory
|
||||
* (`ctx.workingDirectory`), which the `working_directory` tool can change; the
|
||||
* session header keeps the directory the conversation started in. Judging
|
||||
* `../../x` against the header would ask the wrong question — after a `cd`, a
|
||||
* relative read resolves somewhere else entirely — so the guard asks the same
|
||||
* service the tools ask. Read lazily and tolerantly: a deployment without the
|
||||
* service keeps the header's directory, and a transient failure must not turn
|
||||
* into a denial.
|
||||
*/
|
||||
const cwdNow = (agent) => {
|
||||
const service = ctx.get('workingDirectory')
|
||||
if (service === undefined || agent?.session === undefined) return undefined
|
||||
try {
|
||||
const cwd = service.get(agent.session)
|
||||
return typeof cwd === 'string' && cwd !== '' ? cwd : undefined
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The property names the tool declares, when the guard can see them.
|
||||
*
|
||||
* A tool can be shadowed per agent (`dsh-better-edit` replaces `read` and
|
||||
* `edit` on the agent's own layer), and the shadow may name its path argument
|
||||
* differently. Reading the declaration is what keeps the guard judging the
|
||||
* argument the tool will actually use rather than the one the built-in took.
|
||||
* An unreadable schema is not evidence that the path went away; the table
|
||||
* still applies.
|
||||
*/
|
||||
const declaredParameterNames = (exec) => {
|
||||
try {
|
||||
const declared = exec.schema?.parameters ?? ctx.tools.get(exec.name, exec.agent)?.parameters
|
||||
const properties = declared?.properties
|
||||
if (properties === null || typeof properties !== 'object' || Array.isArray(properties)) return undefined
|
||||
return Object.keys(properties)
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
// `off` is the one part that stays a mount-time decision. Deciding it here
|
||||
// means an `off` deployment contributes no rule, no binding and no tool —
|
||||
@@ -182,29 +225,35 @@ export function apply(ctx, config) {
|
||||
const scope = policy.scopeFor(exec.agent)
|
||||
if (scope === undefined) return undefined
|
||||
|
||||
const paths = pathArgumentsFor(exec.name, exec.arguments)
|
||||
// Relative arguments are resolved by the tool against its current working
|
||||
// directory, which `working_directory` can move; judge them against the same
|
||||
// directory or the check answers for a path the tool will not use.
|
||||
const cwd = cwdNow(exec.agent)
|
||||
const current = cwd === undefined || cwd === scope.cwd ? scope : { ...scope, cwd }
|
||||
|
||||
const paths = pathArgumentsFor(exec.name, exec.arguments, declaredParameterNames(exec))
|
||||
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.
|
||||
// is the current working 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)
|
||||
const verdict = await inside(current, current.cwd, exec.signal)
|
||||
if (verdict.inside) return undefined
|
||||
const kind = mode === 'deny' ? 'deny' : 'ask'
|
||||
return { kind, reason: implicitSearchReason({ cwd: scope.cwd, root: scope.root }) }
|
||||
return { kind, reason: implicitSearchReason({ cwd: current.cwd, root: scope.root }) }
|
||||
}
|
||||
|
||||
for (const raw of paths) {
|
||||
const verdict = await inside(scope, raw, exec.signal)
|
||||
const verdict = await inside(current, raw, exec.signal)
|
||||
if (verdict.inside) continue
|
||||
const kind = mode === 'deny' ? 'deny' : 'ask'
|
||||
return {
|
||||
kind,
|
||||
reason: outsideReason({ cwd: scope.cwd, path: verdict.display, root: scope.root, mode: kind }),
|
||||
reason: outsideReason({ cwd: current.cwd, path: verdict.display, root: scope.root, mode: kind }),
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
|
||||
+8
-2
@@ -165,7 +165,12 @@ export function createFacetPolicy(config) {
|
||||
*
|
||||
* 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.
|
||||
* the point of inheriting is to answer the case where they made none. A child
|
||||
* whose own directory is *outside* the inherited root is clamped to the
|
||||
* inherited root rather than trusted with its own: a delegated session may be
|
||||
* started anywhere, and "somewhere else" is the one direction the invariant
|
||||
* forbids. A child started inside the inherited root keeps its own, narrower
|
||||
* directory.
|
||||
*
|
||||
* @param {string|undefined} sessionId - the session.
|
||||
* @param {string} sessionCwd - its resolved working directory.
|
||||
@@ -176,7 +181,8 @@ export function createFacetPolicy(config) {
|
||||
const declared = declaredScope(sessionId)?.focus
|
||||
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 base =
|
||||
!stated && inherited !== undefined ? (within(own, inherited) ? own : inherited) : own
|
||||
const agentFocus = sessionId === undefined ? undefined : narrowed.get(sessionId)
|
||||
if (agentFocus !== undefined && within(agentFocus, base)) return agentFocus
|
||||
return base
|
||||
|
||||
+57
-6
@@ -42,16 +42,33 @@
|
||||
* reliably from argv, so the facet is enforced on the file tools and `bash`
|
||||
* remains a legitimate way out. The prompt says so rather than pretending
|
||||
* otherwise.
|
||||
*
|
||||
* The names are the union of what the harness's own tools declare and what the
|
||||
* overrides this deployment installs declare. `dsh-better-edit` shadows `read`
|
||||
* with `path` and `edit` with `file`, so a table written only against the
|
||||
* built-in `file_path` left the busiest read tool unguarded. Where the tool's
|
||||
* declared schema is available, {@link pathArgumentsFor} narrows this list to
|
||||
* the names the tool actually declares and adds any name in
|
||||
* {@link PATH_PARAMETER_NAMES}; the table is the fallback for a schema the
|
||||
* guard cannot see. `working_directory` and the delegation tools are here
|
||||
* because they change the directory later calls resolve against, and the child
|
||||
* they start — both are part of the scope, not a separate one.
|
||||
*/
|
||||
export const PATH_PARAMETER_NAMES = Object.freeze(['file_path', 'path', 'file', 'dir', 'directory'])
|
||||
|
||||
export const PATH_ARGUMENTS = Object.freeze({
|
||||
read: ['file_path'],
|
||||
write: ['file_path'],
|
||||
edit: ['file_path'],
|
||||
read_image: ['file_path'],
|
||||
read: ['file_path', 'path'],
|
||||
write: ['file_path', 'path'],
|
||||
edit: ['file_path', 'file', 'path'],
|
||||
read_image: ['file_path', 'path'],
|
||||
undo_last_edit: ['path'],
|
||||
grep: ['path'],
|
||||
glob: ['path'],
|
||||
str_replace_editor: ['path'],
|
||||
recall: ['path', 'focus'],
|
||||
working_directory: ['cd'],
|
||||
subagent: ['cwd'],
|
||||
subagent_fork: ['cwd'],
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -80,6 +97,38 @@ export const IMPLICIT_SESSION_PATHS = Object.freeze(['grep', 'glob', 'recall'])
|
||||
export const FACET_TOOL = 'facet'
|
||||
export const WIDENING_ACTION = 'add'
|
||||
|
||||
/**
|
||||
* The parameter names the guard should read for one tool call.
|
||||
*
|
||||
* The table is the intent; the tool's declaration is the truth. When the call
|
||||
* carries a schema (a PTC inner call) or the registry can supply one, the names
|
||||
* are restricted to what the tool declares — that is what keeps a shadowed tool
|
||||
* honest — and any declared parameter in {@link PATH_PARAMETER_NAMES} is added
|
||||
* even when the table did not list it. With no readable schema the table is
|
||||
* used unchanged: a declaration the guard cannot see is not evidence that the
|
||||
* path went away.
|
||||
*
|
||||
* @param {string} toolName - the tool being called.
|
||||
* @param {readonly string[]|undefined} declaredNames - property names from the
|
||||
* tool's own parameter schema, when the guard can read it.
|
||||
* @returns {readonly string[]|undefined} names to read, or undefined for an
|
||||
* unguarded tool.
|
||||
*/
|
||||
export function pathParameterNames(toolName, declaredNames) {
|
||||
const fallback = PATH_ARGUMENTS[toolName]
|
||||
if (fallback === undefined) return undefined
|
||||
if (declaredNames === undefined) return fallback
|
||||
|
||||
const declared = new Set(declaredNames)
|
||||
const names = [
|
||||
...new Set([
|
||||
...fallback.filter((name) => declared.has(name)),
|
||||
...declaredNames.filter((name) => PATH_PARAMETER_NAMES.includes(name)),
|
||||
]),
|
||||
]
|
||||
return names.length > 0 ? names : fallback
|
||||
}
|
||||
|
||||
/**
|
||||
* Every path a tool call names, as the model wrote them.
|
||||
*
|
||||
@@ -95,13 +144,15 @@ export const WIDENING_ACTION = 'add'
|
||||
*
|
||||
* @param {string} toolName - the tool being called.
|
||||
* @param {unknown} args - the raw model arguments.
|
||||
* @param {readonly string[]|undefined} [declaredNames] - property names from the
|
||||
* tool's own parameter schema, when the guard can read it.
|
||||
* @returns {string[]} raw paths, in argument order.
|
||||
*/
|
||||
export function pathArgumentsFor(toolName, args) {
|
||||
export function pathArgumentsFor(toolName, args, declaredNames) {
|
||||
if (args === null || typeof args !== 'object') return []
|
||||
const record = /** @type {Record<string, unknown>} */ (args)
|
||||
|
||||
const names = PATH_ARGUMENTS[toolName]
|
||||
const names = pathParameterNames(toolName, declaredNames)
|
||||
if (names === undefined) return []
|
||||
|
||||
const out = []
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dsh-facet",
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.3",
|
||||
"private": true,
|
||||
"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.",
|
||||
|
||||
+29
-45
@@ -1,8 +1,8 @@
|
||||
# Agent preset facet: one `@deepseek-ai/dsh-agent-preset` declaration inserted
|
||||
# after the web patch.
|
||||
#
|
||||
# The composition is `standard` with three changes, and this file is the only
|
||||
# place any of them is decided:
|
||||
# The composition is the shipped `standard` patch with three changes, and this
|
||||
# file is the only place any of them is decided:
|
||||
#
|
||||
# * compaction is configured (see the `compaction` row below) so the pressure
|
||||
# trigger is a budget rather than a formality. The shipped ratio is 0.80 of a
|
||||
@@ -11,17 +11,23 @@
|
||||
#
|
||||
# * `facet-guard` is mounted, which confines the session to its own folder;
|
||||
#
|
||||
# * the persona row carries no suffix. The shipped one states the working
|
||||
# directory through a prompt variable the harness no longer registers, and
|
||||
# an unregistered variable fails the whole turn — see the note on that row.
|
||||
# * the persona row carries no suffix. The shipped one used to state the
|
||||
# working directory through a prompt variable the harness no longer
|
||||
# registers, and an unregistered variable fails the whole turn — see the
|
||||
# note on that row.
|
||||
#
|
||||
# Everything else is copied verbatim from the shipped `standard` patch, and that
|
||||
# is deliberate: a preset declaration replaces the whole plugin list rather than
|
||||
# merging into it, so a clone that drifts from the original silently loses
|
||||
# whatever it drifted past. When the harness next changes `standard`, re-copy
|
||||
# this file and re-apply the three changes — do not hand-patch around it. The
|
||||
# persona row must be re-checked by hand: re-copying it from `standard` restores
|
||||
# the suffix, and the harness's variable set is what decides whether it composes.
|
||||
# whatever it drifted past — and a clone that keeps a row the harness has since
|
||||
# removed fails to mount at all. That is how this preset broke on dsh
|
||||
# 0.2.2-rc.1: the harness folded `list_agents` into
|
||||
# `@deepseek-ai/dsh-tool-subagent-control` and stopped exporting its
|
||||
# `./list-agents` subpath, so the copied row could never start and the whole
|
||||
# preset reported as broken. When the harness next changes `standard`, re-copy
|
||||
# this file and re-apply the three changes — do not hand-patch around it.
|
||||
# `test/presets.test.js` compares this file against the installed `standard`
|
||||
# and fails on any drift, so the reminder is enforced rather than remembered.
|
||||
- insert:
|
||||
- id: preset-facet
|
||||
name: '@deepseek-ai/dsh-agent-preset'
|
||||
@@ -31,13 +37,6 @@
|
||||
description: One module of the system, not all of it — the session's own folder, plus the files you grant.
|
||||
order: 5
|
||||
plugins:
|
||||
# No suffix. It used to state the working directory through the `cwd`
|
||||
# prompt variable, which the harness does not register — and an unknown
|
||||
# variable is not rendered as text: assembly throws and the whole turn
|
||||
# fails with it. Only `provider` and `model` are registered now, so the
|
||||
# prefix keeps its model reference and the folder is stated per session
|
||||
# by `facet-guard`'s runtime binding instead, which follows the user
|
||||
# when they narrow it.
|
||||
- id: persona
|
||||
name: '@deepseek-ai/dsh-persona'
|
||||
config:
|
||||
@@ -46,6 +45,8 @@
|
||||
name: '@deepseek-ai/dsh-agent-instructions'
|
||||
config:
|
||||
maxBytes: 65536
|
||||
- id: time-context
|
||||
name: '@deepseek-ai/dsh-time-context'
|
||||
# The facet itself: a rule in the system prompt, the binding in the
|
||||
# runtime context, the `facet` tool, and the pre-execute guard that
|
||||
# asks before a file call leaves the session's folder. Configured by
|
||||
@@ -61,12 +62,17 @@
|
||||
disabled: !!js process.platform !== 'win32'
|
||||
- id: tool-fs
|
||||
name: '@deepseek-ai/dsh-tool-fs'
|
||||
config:
|
||||
# Set false to drop the apply_patch tool beside edit.
|
||||
applyPatch: false
|
||||
- id: tool-fs-search
|
||||
name: '@deepseek-ai/dsh-tool-fs-search'
|
||||
config:
|
||||
sampleOverCapGlobResults: false
|
||||
- id: tool-jobs
|
||||
name: '@deepseek-ai/dsh-tool-jobs'
|
||||
- id: tool-schedule
|
||||
name: '@deepseek-ai/dsh-tool-schedule'
|
||||
- id: skill-filesystem
|
||||
name: '@deepseek-ai/dsh-skill-filesystem'
|
||||
- id: tool-skill
|
||||
@@ -85,7 +91,7 @@
|
||||
name: '@deepseek-ai/dsh-plan-mode'
|
||||
config:
|
||||
section: |
|
||||
You are in plan mode. Stay in plan mode until exit_plan_mode succeeds or the user switches the session mode. Imperative language to implement changes means plan the implementation, not execute it. A user's conversational agreement — including an answer confirming something you asked — approves nothing and does not end plan mode; fold the confirmed decision into the plan and submit it through exit_plan_mode.
|
||||
You are in plan mode. Stay in plan mode until the user approves your plan through exit_plan_mode or switches the session mode. Imperative language to implement changes means plan the implementation, not execute it. A user's conversational agreement — including an answer confirming something you asked — approves nothing and does not end plan mode; fold the confirmed decision into the plan and submit it through exit_plan_mode.
|
||||
|
||||
Explore first. Use non-mutating reads, searches, static analysis, and checks to ground the plan in the actual repository. Do not edit or write files, change configuration, run formatters or code generation that rewrites tracked files, commit, or otherwise carry out the plan. Prefer existing functions and patterns over new machinery.
|
||||
|
||||
@@ -106,7 +112,7 @@
|
||||
- id: compaction-basic
|
||||
name: '@deepseek-ai/dsh-compaction-basic'
|
||||
config:
|
||||
# 0.80 of a 1M window is a 800k trigger, and the deepest session
|
||||
# 0.80 of a 1M window is an 800k trigger, and the deepest session
|
||||
# ever recorded here peaked at 787,668 pressure tokens: the
|
||||
# trigger was never reached, so every token below it was re-read
|
||||
# on every subsequent step. 0.35 puts the ceiling at 350k.
|
||||
@@ -134,49 +140,24 @@
|
||||
config:
|
||||
- id: tool-subagent-control
|
||||
name: '@deepseek-ai/dsh-tool-subagent-control'
|
||||
- id: tool-subagent-list-agents
|
||||
name: '@deepseek-ai/dsh-tool-subagent-control/list-agents'
|
||||
- id: tool-subagent
|
||||
name: '@deepseek-ai/dsh-tool-subagent'
|
||||
config:
|
||||
provider: spawn
|
||||
toolName: subagent
|
||||
modelSelectionSettings: true
|
||||
backgroundMode: continuable
|
||||
modelSelection: true
|
||||
modelDiscovery: true
|
||||
- id: tool-subagent-fork
|
||||
name: '@deepseek-ai/dsh-tool-subagent'
|
||||
config:
|
||||
provider: fork
|
||||
toolName: subagent_fork
|
||||
backgroundMode: continuable
|
||||
- id: tool-subagent-codex
|
||||
name: '@deepseek-ai/dsh-tool-subagent'
|
||||
disabled: true
|
||||
config:
|
||||
provider: codex
|
||||
toolName: subagent_codex
|
||||
backgroundMode: one-shot
|
||||
maxDepth: provider-managed
|
||||
- id: tool-subagent-claude-code
|
||||
name: '@deepseek-ai/dsh-tool-subagent'
|
||||
disabled: true
|
||||
config:
|
||||
provider: claude-code
|
||||
toolName: subagent_claude_code
|
||||
backgroundMode: one-shot
|
||||
maxDepth: provider-managed
|
||||
- id: workflow-ptc
|
||||
name: '@deepseek-ai/dsh-workflow-ptc'
|
||||
config:
|
||||
provider: spawn
|
||||
- id: tool-workflow
|
||||
name: '@deepseek-ai/dsh-tool-workflow'
|
||||
- id: tool-ralph
|
||||
name: '@deepseek-ai/dsh-tool-ralph'
|
||||
disabled: true
|
||||
config:
|
||||
subagentProvider: spawn
|
||||
maxRounds: 64
|
||||
- id: tool-ask-user
|
||||
name: '@deepseek-ai/dsh-tool-ask-user'
|
||||
- id: tool-todo
|
||||
@@ -192,4 +173,7 @@
|
||||
name: '@deepseek-ai/dsh-tool-present'
|
||||
- id: tool-plugin-manager
|
||||
name: '@deepseek-ai/dsh-plugin-manager/tools'
|
||||
disabled: !!js "!ctx.get('profileContext')"
|
||||
- id: tool-plugin-market
|
||||
name: '@deepseek-ai/dsh-plugin-market/tools'
|
||||
disabled: true
|
||||
@@ -8,33 +8,31 @@
|
||||
#
|
||||
# or add its path to `dsh.bundle.patch` in package.json.
|
||||
#
|
||||
# It overrides the shipped `preset-standard` row by id rather than inserting a
|
||||
# second declaration. With two rows carrying the same preset id, which one mounts
|
||||
# is decided by the loader's duplicate-id handling rather than by the patch — the
|
||||
# insert form worked only as long as that ordering held. The override is explicit
|
||||
# and must be applied after the web-app layer, which both ways above are.
|
||||
#
|
||||
# It is deliberately not applied for you, and the reason is a real hazard rather
|
||||
# than caution: a preset declaration replaces the whole plugin list, never merges
|
||||
# into it, so this file is a frozen copy of the shipped `standard` composition
|
||||
# plus two changes. When the harness next updates `standard` — a new tool, a
|
||||
# plus one change. When the harness next updates `standard` — a new tool, a
|
||||
# renamed row — this copy will not follow it, and the sessions on this preset
|
||||
# will silently lose whatever was added. Use it if you are prepared to re-copy
|
||||
# and re-apply when that happens; otherwise take the compaction settings into
|
||||
# whichever preset you actually run.
|
||||
# will silently lose whatever was added, or fail to mount if the copy keeps a
|
||||
# row the harness removed. Use it if you are prepared to re-copy and re-apply
|
||||
# when that happens; otherwise take the compaction settings into whichever
|
||||
# preset you actually run.
|
||||
#
|
||||
# The two changes from the shipped file are the `compaction-basic` row's config,
|
||||
# and the persona row's missing suffix: the shipped one names the working
|
||||
# directory with a prompt variable the harness no longer registers, and an
|
||||
# unregistered variable fails the whole turn instead of rendering. Re-copying
|
||||
# this file from a newer `standard` reintroduces that suffix — re-apply both.
|
||||
- insert:
|
||||
- id: preset-standard
|
||||
# The one change from the shipped file is the `compaction-basic` row's config.
|
||||
# `test/presets.test.js` compares this file against the installed `standard`
|
||||
# and fails on any other difference.
|
||||
- id: preset-standard
|
||||
name: '@deepseek-ai/dsh-agent-preset'
|
||||
config:
|
||||
id: standard
|
||||
order: 1
|
||||
plugins:
|
||||
# No suffix, for the reason in `facet.patch.yml`: the harness registers
|
||||
# only `provider` and `model` as prompt variables, and an unregistered
|
||||
# one now throws instead of rendering. Nothing in this preset states the
|
||||
# session's working directory any more — a static prompt template cannot
|
||||
# name a folder that changes per session, so a deployment that needs it
|
||||
# belongs in the runtime context rather than here.
|
||||
- id: persona
|
||||
name: '@deepseek-ai/dsh-persona'
|
||||
config:
|
||||
@@ -43,6 +41,8 @@
|
||||
name: '@deepseek-ai/dsh-agent-instructions'
|
||||
config:
|
||||
maxBytes: 65536
|
||||
- id: time-context
|
||||
name: '@deepseek-ai/dsh-time-context'
|
||||
- id: tool-bash
|
||||
name: '@deepseek-ai/dsh-tool-bash'
|
||||
disabled: !!js process.platform === 'win32'
|
||||
@@ -51,12 +51,17 @@
|
||||
disabled: !!js process.platform !== 'win32'
|
||||
- id: tool-fs
|
||||
name: '@deepseek-ai/dsh-tool-fs'
|
||||
config:
|
||||
# Set false to drop the apply_patch tool beside edit.
|
||||
applyPatch: false
|
||||
- id: tool-fs-search
|
||||
name: '@deepseek-ai/dsh-tool-fs-search'
|
||||
config:
|
||||
sampleOverCapGlobResults: false
|
||||
- id: tool-jobs
|
||||
name: '@deepseek-ai/dsh-tool-jobs'
|
||||
- id: tool-schedule
|
||||
name: '@deepseek-ai/dsh-tool-schedule'
|
||||
- id: skill-filesystem
|
||||
name: '@deepseek-ai/dsh-skill-filesystem'
|
||||
- id: tool-skill
|
||||
@@ -75,7 +80,7 @@
|
||||
name: '@deepseek-ai/dsh-plan-mode'
|
||||
config:
|
||||
section: |
|
||||
You are in plan mode. Stay in plan mode until exit_plan_mode succeeds or the user switches the session mode. Imperative language to implement changes means plan the implementation, not execute it. A user's conversational agreement — including an answer confirming something you asked — approves nothing and does not end plan mode; fold the confirmed decision into the plan and submit it through exit_plan_mode.
|
||||
You are in plan mode. Stay in plan mode until the user approves your plan through exit_plan_mode or switches the session mode. Imperative language to implement changes means plan the implementation, not execute it. A user's conversational agreement — including an answer confirming something you asked — approves nothing and does not end plan mode; fold the confirmed decision into the plan and submit it through exit_plan_mode.
|
||||
|
||||
Explore first. Use non-mutating reads, searches, static analysis, and checks to ground the plan in the actual repository. Do not edit or write files, change configuration, run formatters or code generation that rewrites tracked files, commit, or otherwise carry out the plan. Prefer existing functions and patterns over new machinery.
|
||||
|
||||
@@ -116,49 +121,24 @@
|
||||
config:
|
||||
- id: tool-subagent-control
|
||||
name: '@deepseek-ai/dsh-tool-subagent-control'
|
||||
- id: tool-subagent-list-agents
|
||||
name: '@deepseek-ai/dsh-tool-subagent-control/list-agents'
|
||||
- id: tool-subagent
|
||||
name: '@deepseek-ai/dsh-tool-subagent'
|
||||
config:
|
||||
provider: spawn
|
||||
toolName: subagent
|
||||
modelSelectionSettings: true
|
||||
backgroundMode: continuable
|
||||
modelSelection: true
|
||||
modelDiscovery: true
|
||||
- id: tool-subagent-fork
|
||||
name: '@deepseek-ai/dsh-tool-subagent'
|
||||
config:
|
||||
provider: fork
|
||||
toolName: subagent_fork
|
||||
backgroundMode: continuable
|
||||
- id: tool-subagent-codex
|
||||
name: '@deepseek-ai/dsh-tool-subagent'
|
||||
disabled: true
|
||||
config:
|
||||
provider: codex
|
||||
toolName: subagent_codex
|
||||
backgroundMode: one-shot
|
||||
maxDepth: provider-managed
|
||||
- id: tool-subagent-claude-code
|
||||
name: '@deepseek-ai/dsh-tool-subagent'
|
||||
disabled: true
|
||||
config:
|
||||
provider: claude-code
|
||||
toolName: subagent_claude_code
|
||||
backgroundMode: one-shot
|
||||
maxDepth: provider-managed
|
||||
- id: workflow-ptc
|
||||
name: '@deepseek-ai/dsh-workflow-ptc'
|
||||
config:
|
||||
provider: spawn
|
||||
- id: tool-workflow
|
||||
name: '@deepseek-ai/dsh-tool-workflow'
|
||||
- id: tool-ralph
|
||||
name: '@deepseek-ai/dsh-tool-ralph'
|
||||
disabled: true
|
||||
config:
|
||||
subagentProvider: spawn
|
||||
maxRounds: 64
|
||||
- id: tool-ask-user
|
||||
name: '@deepseek-ai/dsh-tool-ask-user'
|
||||
- id: tool-todo
|
||||
@@ -174,4 +154,7 @@
|
||||
name: '@deepseek-ai/dsh-tool-present'
|
||||
- id: tool-plugin-manager
|
||||
name: '@deepseek-ai/dsh-plugin-manager/tools'
|
||||
disabled: !!js "!ctx.get('profileContext')"
|
||||
- id: tool-plugin-market
|
||||
name: '@deepseek-ai/dsh-plugin-market/tools'
|
||||
disabled: true
|
||||
+13
-21
@@ -5,10 +5,12 @@
|
||||
*
|
||||
* ## Why this exists
|
||||
*
|
||||
* The plugin imports `@deepseek-ai/dsh-tools` and `@deepseek-ai/schemastery`.
|
||||
* Once installed into a profile those resolve from the profile's own
|
||||
* `node_modules`, which is where the harness lives — but a bare checkout has no
|
||||
* such tree, so the tests cannot even load the module under test.
|
||||
* The plugin imports `@deepseek-ai/dsh-tools` and `@deepseek-ai/schemastery`,
|
||||
* and `test/presets.test.js` reads the shipped `standard` preset through
|
||||
* `js-yaml` to compare it with this bundle's frozen copies. Once installed into
|
||||
* a profile those resolve from the profile's own `node_modules`, which is where
|
||||
* the harness lives — but a bare checkout has no such tree, so the tests cannot
|
||||
* even load the module under test.
|
||||
*
|
||||
* The alternative is declaring them as dependencies, and for `@deepseek-ai/cordis`
|
||||
* that would be a genuine bug rather than untidiness: a second copy of Cordis
|
||||
@@ -23,25 +25,14 @@ import { existsSync, mkdirSync, readdirSync, rmSync, symlinkSync } from 'node:fs
|
||||
import { dirname, join, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
import { findHarnessScope } from './harness-scope.mjs'
|
||||
|
||||
/** Packages this checkout imports at runtime, and which the harness must supply. */
|
||||
const NEEDED = ['cordis', 'schemastery', 'dsh-tools']
|
||||
const NEEDED = ['@deepseek-ai/cordis', '@deepseek-ai/schemastery', '@deepseek-ai/dsh-tools', 'js-yaml']
|
||||
|
||||
const here = dirname(fileURLToPath(import.meta.url))
|
||||
const packageRoot = resolve(here, '..')
|
||||
|
||||
/** Where a dsh installation keeps the scope, newest layout first. */
|
||||
function findHarnessScope() {
|
||||
const candidates = [
|
||||
process.env.DSH_HARNESS_NODE_MODULES,
|
||||
resolve(process.env.DSH_HOME ?? join(process.env.HOME ?? '', '.dsh'), 'profiles', 'node_modules'),
|
||||
'/usr/local/lib/node_modules/@deepseek-ai/dsh/node_modules',
|
||||
]
|
||||
for (const candidate of candidates) {
|
||||
if (typeof candidate === 'string' && existsSync(join(candidate, '@deepseek-ai', 'cordis'))) return candidate
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
const scope = findHarnessScope()
|
||||
if (scope === undefined) {
|
||||
console.error('dev-links: no dsh installation found. Set DSH_HARNESS_NODE_MODULES to its node_modules directory.')
|
||||
@@ -49,16 +40,17 @@ if (scope === undefined) {
|
||||
}
|
||||
|
||||
const target = join(packageRoot, 'node_modules')
|
||||
mkdirSync(join(target, '@deepseek-ai'), { recursive: true })
|
||||
mkdirSync(target, { recursive: true })
|
||||
|
||||
let linked = 0
|
||||
for (const name of NEEDED) {
|
||||
const source = join(scope, '@deepseek-ai', name)
|
||||
const source = join(scope, name)
|
||||
if (!existsSync(source)) {
|
||||
console.error(`dev-links: ${name} is not in ${scope}; skipping`)
|
||||
continue
|
||||
}
|
||||
const link = join(target, '@deepseek-ai', name)
|
||||
const link = join(target, name)
|
||||
mkdirSync(dirname(link), { recursive: true })
|
||||
if (existsSync(link)) rmSync(link, { recursive: true, force: true })
|
||||
symlinkSync(source, link, 'dir')
|
||||
linked += 1
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Locate a dsh installation's dependency scope from a checkout.
|
||||
*
|
||||
* The plugin links harness packages into a bare checkout (see `dev-links.mjs`)
|
||||
* and `test/presets.test.js` reads the shipped `standard` preset to compare it
|
||||
* with this bundle's frozen copies. Both need the same answer to "where is the
|
||||
* harness?", so the search lives here rather than twice.
|
||||
*
|
||||
* There can be more than one answer. A harness home may carry the legacy
|
||||
* `profiles/node_modules` mirror that an older link backend projected, and that
|
||||
* mirror is a snapshot: packages added to the installation later are missing
|
||||
* from it. Callers that resolve more than one package should therefore try
|
||||
* every scope, not only {@link findHarnessScope}'s first answer.
|
||||
*/
|
||||
|
||||
import { existsSync } from 'node:fs'
|
||||
import { join, resolve } from 'node:path'
|
||||
|
||||
/**
|
||||
* Every dependency scope a dsh installation may occupy, newest layout first.
|
||||
*
|
||||
* @returns the directories that hold `@deepseek-ai/cordis`, deduplicated, in
|
||||
* preference order.
|
||||
*/
|
||||
export function harnessScopes() {
|
||||
const candidates = [
|
||||
process.env.DSH_HARNESS_NODE_MODULES,
|
||||
resolve(process.env.DSH_HOME ?? join(process.env.HOME ?? '', '.dsh'), 'profiles', 'node_modules'),
|
||||
'/usr/local/lib/node_modules/@deepseek-ai/dsh/node_modules',
|
||||
]
|
||||
const scopes = []
|
||||
for (const candidate of candidates) {
|
||||
if (typeof candidate !== 'string' || !existsSync(join(candidate, '@deepseek-ai', 'cordis'))) continue
|
||||
if (!scopes.includes(candidate)) scopes.push(candidate)
|
||||
}
|
||||
return scopes
|
||||
}
|
||||
|
||||
/**
|
||||
* The preferred dependency scope of a dsh installation.
|
||||
*
|
||||
* @returns the first directory that holds `@deepseek-ai/cordis`, or undefined.
|
||||
*/
|
||||
export function findHarnessScope() {
|
||||
return harnessScopes()[0]
|
||||
}
|
||||
+109
-3
@@ -66,14 +66,25 @@ const fsLikeLocal = {
|
||||
* deployment that composed no approval service at all — a case the tool pipeline
|
||||
* denies outright, so the guard must treat it as no channel.
|
||||
*/
|
||||
function harness({ mode = 'ask', extraRoots = [], tool = true, config, approval } = {}) {
|
||||
function harness({
|
||||
mode = 'ask',
|
||||
extraRoots = [],
|
||||
tool = true,
|
||||
config,
|
||||
approval,
|
||||
workingDirectory,
|
||||
toolSchemas,
|
||||
} = {}) {
|
||||
const policy = createFacetPolicy(config ?? { mode, extraRoots })
|
||||
const captured = { section: undefined, context: undefined, tool: undefined, preExecute: undefined }
|
||||
const ctx = {
|
||||
facetPolicy: policy,
|
||||
fs: fsLikeLocal,
|
||||
get: (name) =>
|
||||
name === 'approval' && approval !== undefined ? { effectivePolicy: () => approval } : undefined,
|
||||
get: (name) => {
|
||||
if (name === 'approval' && approval !== undefined) return { effectivePolicy: () => approval }
|
||||
if (name === 'workingDirectory' && workingDirectory !== undefined) return workingDirectory
|
||||
return undefined
|
||||
},
|
||||
systemPrompt: {
|
||||
section: (value) => {
|
||||
captured.section = value
|
||||
@@ -86,6 +97,13 @@ function harness({ mode = 'ask', extraRoots = [], tool = true, config, approval
|
||||
register: (value) => {
|
||||
captured.tool = value
|
||||
},
|
||||
// The registry lookup the guard uses to learn a shadowed tool's argument
|
||||
// names; `toolSchemas` is a name-to-parameter-names map.
|
||||
get: (name) => {
|
||||
const names = toolSchemas?.[name]
|
||||
if (names === undefined) return undefined
|
||||
return { parameters: { properties: Object.fromEntries(names.map((parameter) => [parameter, {}])) } }
|
||||
},
|
||||
},
|
||||
on: (event, listener) => {
|
||||
if (event === 'tools/pre-execute') captured.preExecute = listener
|
||||
@@ -241,6 +259,94 @@ 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' })
|
||||
})
|
||||
|
||||
// ── the working directory is part of the scope ──────────────────────────────
|
||||
//
|
||||
// The file tools resolve relative arguments against the session's *current*
|
||||
// directory, not the header it started with. A guard that asked the header would
|
||||
// answer for a path the tool never touches, and one that ignored
|
||||
// `working_directory` would let a `cd` do the stepping out.
|
||||
|
||||
test('a working directory outside the facet cannot be entered', async () => {
|
||||
const { captured } = harness({ mode: 'deny' })
|
||||
const decision = await dispatch(captured, { name: 'working_directory', args: { cd: '../../shared' }, agent: agent() })
|
||||
assert.equal(decision.kind, 'deny')
|
||||
assert.match(decision.reason, /src\/shared/)
|
||||
|
||||
// Inside the facet is ordinary work, and reading the directory changes nothing.
|
||||
assert.deepEqual(
|
||||
await dispatch(captured, { name: 'working_directory', args: { cd: 'inner' }, agent: agent() }),
|
||||
{ kind: 'allow' },
|
||||
)
|
||||
assert.deepEqual(await dispatch(captured, { name: 'working_directory', args: {}, agent: agent() }), {
|
||||
kind: 'allow',
|
||||
})
|
||||
})
|
||||
|
||||
test('a relative path is judged against the directory the tool will use', async () => {
|
||||
// The session header says `room`; the tool will resolve `types.ts` under
|
||||
// `shared`, which is outside. Judging the header would call this inside.
|
||||
const { captured } = harness({ mode: 'deny', workingDirectory: { get: () => join(root, 'src', 'shared') } })
|
||||
const decision = await dispatch(captured, { name: 'read', args: { file_path: 'types.ts' }, agent: agent() })
|
||||
assert.equal(decision.kind, 'deny')
|
||||
// The reason is shown relative to the directory the tool will use.
|
||||
assert.match(decision.reason, /types\.ts/)
|
||||
assert.match(decision.reason, /src\/controllers\/room/, 'the reason names the facet')
|
||||
})
|
||||
|
||||
test('a search with no path follows the current directory into the facet', async () => {
|
||||
// The session is the facet's parent and the user narrowed to `inner`; the
|
||||
// current directory is `inner`, so a bare grep searches inside the facet even
|
||||
// though the session directory is outside it.
|
||||
const { captured } = harness({
|
||||
mode: 'deny',
|
||||
config: { scopes: { 'session-1': { focus: 'inner' } } },
|
||||
workingDirectory: { get: () => join(facet, 'inner') },
|
||||
})
|
||||
assert.deepEqual(await dispatch(captured, { name: 'grep', args: { pattern: 'x' }, agent: agent() }), {
|
||||
kind: 'allow',
|
||||
})
|
||||
})
|
||||
|
||||
// ── shadowed tools ───────────────────────────────────────────────────────────
|
||||
//
|
||||
// A deployment plugin can replace a built-in tool with one that names its path
|
||||
// argument differently — `dsh-better-edit` shadows `read` (path) and `edit`
|
||||
// (file). The guard reads the declaration, so the shadow stays guarded.
|
||||
|
||||
test('a tool shadowed with a different argument name is still judged', async () => {
|
||||
const { captured } = harness({ mode: 'deny', toolSchemas: { read: ['path', 'offset'], edit: ['file', 'edits'] } })
|
||||
|
||||
const read = await dispatch(captured, { name: 'read', args: { path: '../../shared/types.ts' }, agent: agent() })
|
||||
assert.equal(read.kind, 'deny')
|
||||
assert.match(read.reason, /src\/shared\/types\.ts/)
|
||||
|
||||
const edit = await dispatch(captured, {
|
||||
name: 'edit',
|
||||
args: { file: '../../shared/types.ts', edits: [] },
|
||||
agent: agent(),
|
||||
})
|
||||
assert.equal(edit.kind, 'deny')
|
||||
})
|
||||
|
||||
test('a delegated session cannot be started outside the facet', async () => {
|
||||
const { captured } = harness({ mode: 'deny', toolSchemas: { subagent: ['cwd', 'description', 'prompt'] } })
|
||||
assert.equal(
|
||||
(
|
||||
await dispatch(captured, {
|
||||
name: 'subagent',
|
||||
args: { cwd: '../../shared', description: 'x', prompt: 'y' },
|
||||
agent: agent(),
|
||||
})
|
||||
).kind,
|
||||
'deny',
|
||||
)
|
||||
// Omitted means the child inherits this directory, which is inside.
|
||||
assert.deepEqual(
|
||||
await dispatch(captured, { name: 'subagent', args: { description: 'x', prompt: 'y' }, agent: agent() }),
|
||||
{ kind: 'allow' },
|
||||
)
|
||||
})
|
||||
|
||||
// ── delegated sessions ───────────────────────────────────────────────────────
|
||||
//
|
||||
// A session spawned or forked from a scoped one has no declaration of its own,
|
||||
|
||||
@@ -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'))
|
||||
|
||||
+201
-2
@@ -1,10 +1,14 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync, readdirSync } from 'node:fs'
|
||||
import { existsSync, readFileSync, readdirSync } from 'node:fs'
|
||||
import { createRequire } from 'node:module'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { test } from 'node:test'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url'
|
||||
|
||||
import yaml from 'js-yaml'
|
||||
|
||||
import { facetContextText, facetRuleText } from '../lib/scope.js'
|
||||
import { harnessScopes } from '../scripts/harness-scope.mjs'
|
||||
|
||||
const PRESETS = join(dirname(fileURLToPath(import.meta.url)), '..', 'presets')
|
||||
|
||||
@@ -59,3 +63,198 @@ test('the text this bundle contributes to the prompt holds no variable reference
|
||||
assert.deepEqual(referencesIn(rule), [])
|
||||
assert.deepEqual(referencesIn(binding), [])
|
||||
})
|
||||
|
||||
/*
|
||||
* Drift against the shipped `standard` composition.
|
||||
*
|
||||
* A preset declaration replaces the whole plugin list rather than merging into
|
||||
* it, so both files under `presets/` are frozen copies of the harness's
|
||||
* `standard` patch. That copy is what breaks when the harness changes: on dsh
|
||||
* 0.2.2-rc.1 the harness folded `list_agents` into
|
||||
* `@deepseek-ai/dsh-tool-subagent-control` and dropped its `./list-agents`
|
||||
* subpath, and the copied row could never start — which breaks the *whole*
|
||||
* preset, because one row that fails to mount fails the declaration. These
|
||||
* tests turn "remember to re-copy it" into a build failure.
|
||||
*
|
||||
* They need the installed harness, so they skip on a checkout without one.
|
||||
*/
|
||||
|
||||
const PACKAGE_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
|
||||
const FACET_PRESET = join(PRESETS, 'facet.patch.yml')
|
||||
const COMPACTION_PRESET = join(PRESETS, 'standard-compaction.patch.yml')
|
||||
const HARNESS_SCOPES = harnessScopes()
|
||||
const STANDARD_PRESET = HARNESS_SCOPES
|
||||
.map((scope) => join(scope, '@deepseek-ai', 'dsh-web-app', 'presets', 'standard.patch.yml'))
|
||||
.find((file) => existsSync(file))
|
||||
const APP_BOOT = HARNESS_SCOPES
|
||||
.map((scope) => join(scope, '@deepseek-ai', 'dsh-app-boot', 'lib', 'index.js'))
|
||||
.find((file) => existsSync(file))
|
||||
|
||||
const SKIP_DRIFT =
|
||||
HARNESS_SCOPES.length === 0
|
||||
? 'no dsh installation found; set DSH_HARNESS_NODE_MODULES to compare against the shipped standard preset'
|
||||
: STANDARD_PRESET === undefined
|
||||
? 'the shipped standard preset was not found in any harness scope'
|
||||
: false
|
||||
|
||||
/** The `!!js` tag carries a source expression; both compared sides keep it as text. */
|
||||
const PRESET_SCHEMA = yaml.DEFAULT_SCHEMA.extend([
|
||||
new yaml.Type('tag:yaml.org,2002:js', { kind: 'scalar', construct: (value) => value }),
|
||||
])
|
||||
|
||||
/** The plugin rows of a single-preset patch file, as written. */
|
||||
function presetPlugins(file) {
|
||||
const [patch] = yaml.load(readFileSync(file, 'utf8'), { schema: PRESET_SCHEMA })
|
||||
// The facet preset is an insert; the optional overlay overrides the shipped
|
||||
// row by id and carries the full config instead.
|
||||
const declaration = patch.insert === undefined ? patch : patch.insert[0]
|
||||
return declaration.config.plugins
|
||||
}
|
||||
|
||||
/** Drop absent keys, so a missing field and an undefined field compare the same. */
|
||||
function normalizedRows(rows) {
|
||||
return rows.map((row) => ({
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
...(row.disabled === undefined ? {} : { disabled: row.disabled }),
|
||||
...(row.group === true ? { group: true } : {}),
|
||||
...(row.isolate === undefined ? {} : { isolate: row.isolate }),
|
||||
...(row.config === undefined ? {} : { config: Array.isArray(row.config) ? normalizedRows(row.config) : row.config }),
|
||||
}))
|
||||
}
|
||||
|
||||
/** One row by id, at any depth. */
|
||||
function rowById(rows, id) {
|
||||
for (const row of rows) {
|
||||
if (row.id === id) return row
|
||||
if (Array.isArray(row.config)) {
|
||||
const found = rowById(row.config, id)
|
||||
if (found !== undefined) return found
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
/** A copy with the bundle's compaction budget removed, so everything else can be compared. */
|
||||
function withoutCompactionBudget(rows) {
|
||||
const copy = structuredClone(rows)
|
||||
const strip = (list) => {
|
||||
for (const row of list) {
|
||||
if (row.id === 'compaction-basic') delete row.config
|
||||
if (Array.isArray(row.config)) strip(row.config)
|
||||
}
|
||||
}
|
||||
strip(copy)
|
||||
return copy
|
||||
}
|
||||
|
||||
/** The only settings either file adds to a `standard` row. */
|
||||
const COMPACTION_BUDGET = { thresholdRatio: 0.35, retainTokens: 80000, maxTokens: 16384 }
|
||||
|
||||
test('the facet preset is the shipped standard composition plus its documented changes', { skip: SKIP_DRIFT }, () => {
|
||||
const standard = normalizedRows(presetPlugins(STANDARD_PRESET))
|
||||
const facet = normalizedRows(presetPlugins(FACET_PRESET))
|
||||
|
||||
const guard = facet.filter((row) => row.id === 'facet-guard')
|
||||
assert.deepEqual(guard, [{ id: 'facet-guard', name: 'dsh-facet/guard' }], 'the facet preset mounts facet-guard exactly once')
|
||||
|
||||
const withoutGuard = facet.filter((row) => row.id !== 'facet-guard')
|
||||
assert.deepEqual(
|
||||
withoutCompactionBudget(withoutGuard),
|
||||
withoutCompactionBudget(standard),
|
||||
'presets/facet.patch.yml has drifted from the shipped standard composition; re-copy it from the harness and re-apply only the guard and the compaction budget',
|
||||
)
|
||||
assert.deepEqual(
|
||||
rowById(withoutGuard, 'compaction-basic')?.config,
|
||||
COMPACTION_BUDGET,
|
||||
'the facet preset keeps its compaction budget',
|
||||
)
|
||||
})
|
||||
|
||||
test('the standard-compaction overlay is the shipped standard composition plus the compaction budget', { skip: SKIP_DRIFT }, () => {
|
||||
const standard = normalizedRows(presetPlugins(STANDARD_PRESET))
|
||||
const overlay = normalizedRows(presetPlugins(COMPACTION_PRESET))
|
||||
|
||||
assert.deepEqual(
|
||||
rowById(overlay, 'compaction-basic')?.config,
|
||||
COMPACTION_BUDGET,
|
||||
'the optional overlay configures the compaction budget',
|
||||
)
|
||||
assert.deepEqual(
|
||||
withoutCompactionBudget(overlay),
|
||||
withoutCompactionBudget(standard),
|
||||
'presets/standard-compaction.patch.yml has drifted from the shipped standard composition; re-copy it from the harness and re-apply only the compaction budget',
|
||||
)
|
||||
})
|
||||
|
||||
test(
|
||||
'the standard-compaction overlay replaces the shipped preset instead of adding a second declaration',
|
||||
{ skip: SKIP_DRIFT },
|
||||
async (t) => {
|
||||
if (APP_BOOT === undefined) return t.skip('the harness app-boot package was not found in any scope')
|
||||
|
||||
// Compose the way the launcher does: the shipped declaration first, then the
|
||||
// overlay. A second declaration carrying the same preset id would register
|
||||
// in the wrong order and lose — which is how this overlay used to do nothing.
|
||||
const { composeEntries } = await import(pathToFileURL(APP_BOOT).href)
|
||||
const standardPatch = yaml.load(readFileSync(STANDARD_PRESET, 'utf8'), { schema: PRESET_SCHEMA })
|
||||
const overlayPatch = yaml.load(readFileSync(COMPACTION_PRESET, 'utf8'), { schema: PRESET_SCHEMA })
|
||||
const warnings = []
|
||||
const entries = composeEntries([standardPatch, overlayPatch], (message) => warnings.push(message))
|
||||
|
||||
assert.deepEqual(warnings, [], 'the overlay applies without a skipped patch')
|
||||
const declarations = entries.filter((entry) => entry.id === 'preset-standard')
|
||||
assert.equal(
|
||||
declarations.length,
|
||||
1,
|
||||
'the overlay overrides the row; a second declaration would be ignored by the registry',
|
||||
)
|
||||
assert.deepEqual(
|
||||
rowById(declarations[0].config.plugins, 'compaction-basic')?.config,
|
||||
COMPACTION_BUDGET,
|
||||
'the applied overlay carries the compaction budget',
|
||||
)
|
||||
},
|
||||
)
|
||||
/** Every row's id and module specifier, groups included. */
|
||||
function namedRows(rows) {
|
||||
return rows.flatMap((row) => [
|
||||
{ id: row.id, name: row.name },
|
||||
...(Array.isArray(row.config) ? namedRows(row.config) : []),
|
||||
])
|
||||
}
|
||||
|
||||
test('every plugin a shipped preset names resolves against the installed harness', { skip: SKIP_DRIFT }, () => {
|
||||
// Anchoring inside a scope makes Node look in that scope's own node_modules:
|
||||
// its parent directory carries the scope as a `node_modules` entry, which is
|
||||
// exactly the lookup the profile uses. Several scopes are tried because a
|
||||
// legacy `profiles/node_modules` mirror is only a snapshot of the installation.
|
||||
const harnessResolvers = HARNESS_SCOPES.map((scope) => createRequire(join(scope, 'noop.mjs')))
|
||||
const fromPlugin = createRequire(join(PACKAGE_ROOT, 'package.json'))
|
||||
const unresolved = []
|
||||
|
||||
for (const file of [FACET_PRESET, COMPACTION_PRESET]) {
|
||||
for (const { id, name } of namedRows(presetPlugins(file))) {
|
||||
// `cordis:group` is a loader builtin rather than an installed package.
|
||||
if (name === 'cordis:group') continue
|
||||
const resolvers = name === 'dsh-facet/guard' ? [fromPlugin] : harnessResolvers
|
||||
let failure
|
||||
const resolved = resolvers.some((resolver) => {
|
||||
try {
|
||||
resolver.resolve(name)
|
||||
return true
|
||||
} catch (error) {
|
||||
failure = error
|
||||
return false
|
||||
}
|
||||
})
|
||||
if (!resolved) unresolved.push(`${file.split('/').pop()}: ${id} (${name}): ${failure?.code ?? failure?.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
assert.deepEqual(
|
||||
unresolved,
|
||||
[],
|
||||
'a preset names a plugin or subpath the harness no longer provides; re-copy the preset from the shipped standard',
|
||||
)
|
||||
})
|
||||
@@ -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