Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
912dd8ab23 | ||
|
|
387f7c3510 | ||
|
|
40574505f2 | ||
|
|
c48e9cabd9 | ||
|
|
4152c72730 | ||
|
|
1697c24c3c | ||
|
|
616cad75ce | ||
|
|
7e75bcf79e | ||
|
|
9065a5c9d6 | ||
|
|
4bc4296494 | ||
|
|
608b59639c | ||
|
|
c49acfdb2c |
No files matched your search
@@ -2,6 +2,43 @@
|
|||||||
|
|
||||||
Every release, newest first, generated from the commits in each release.
|
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
|
||||||
|
|
||||||
|
- stop the facet preset naming a prompt variable the harness dropped
|
||||||
|
|
||||||
|
|
||||||
|
## v0.4.0 — 2026-09-28
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- list files in the extras picker, not just folders
|
||||||
|
|
||||||
|
|
||||||
## v0.3.1 — 2026-09-27
|
## v0.3.1 — 2026-09-27
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ because otherwise there would be no way to grant anything at all.
|
|||||||
From the repository, following releases:
|
From the repository, following releases:
|
||||||
|
|
||||||
```sh
|
```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
|
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"
|
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
|
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`
|
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
|
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
|
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
|
workflow creates on every push to `master`. The range is written `>=` rather
|
||||||
against, so it only works once the first release has been published.
|
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
|
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
|
bundle in `dsh.profile.bundles` for you. A git-hosted plugin that builds on
|
||||||
@@ -173,14 +176,32 @@ scope it had.
|
|||||||
Both controls are a **directory listing**, not a text box: the panel's vocabulary
|
Both controls are a **directory listing**, not a text box: the panel's vocabulary
|
||||||
is paths relative to the session folder, and "which folder is `../shared`" is the
|
is paths relative to the session folder, and "which folder is `../shared`" is the
|
||||||
one question free text cannot answer. Pressing it opens a second dialog over the
|
one question free text cannot answer. Pressing it opens a second dialog over the
|
||||||
panel, shaped like the host's own workspace browser — one level of child folders,
|
panel, shaped like the host's own workspace browser — one level of children, a
|
||||||
a breadcrumb trail, a hidden-entries toggle — driven through
|
breadcrumb trail, a hidden-entries toggle, and a file-type glyph per row. A pick
|
||||||
`uiWorkspace.listDirectory`, the same Host primitive that browser uses. A pick is
|
is 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`.
|
||||||
`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
|
The listing is driven by **two Host listers**, because they answer different
|
||||||
a file — which is why that action reads **Add path or file** and its field **Path
|
questions and the extras need both:
|
||||||
or file**, rather than promising a folder the list would then fail to show.
|
|
||||||
|
| lister | returns | reach |
|
||||||
|
|---|---|---|
|
||||||
|
| `uiWorkspace.listDirectory` | folders | anywhere on the machine |
|
||||||
|
| `remote.workspaceFiles.list` | files and folders | the session's workspace only |
|
||||||
|
|
||||||
|
The extras picker takes the file listing while the level is inside the session
|
||||||
|
folder, which is how a file is chosen by clicking its name instead of typing it —
|
||||||
|
the same listing behind the sidebar's own file tree, applied one level at a time.
|
||||||
|
Above the session folder the Host confines it, and the level falls back to folders
|
||||||
|
and says so in the dialog: a file outside the workspace is still added by typing
|
||||||
|
its path, which is why the action reads **Add path or file** and its field **Path
|
||||||
|
or file**. The focus picker never offers files at all — a focus is a folder, so a
|
||||||
|
file row there would offer something that cannot be chosen.
|
||||||
|
|
||||||
|
A folder row is a way down; a file row is a thing to take. Clicking a file fills
|
||||||
|
the path field and marks the row, and the footer's action then adds it in declared
|
||||||
|
form; pressing Enter on a name the level already lists is not an error, because
|
||||||
|
the path is exactly what this dialog is for.
|
||||||
|
|
||||||
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
|
||||||
@@ -213,12 +234,67 @@ its default is not 8192 but `headroomTokens`, 65536.
|
|||||||
|
|
||||||
If you want that budget on *every* session rather than only scoped ones,
|
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
|
`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
|
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
|
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`
|
frozen copy of `standard` that will not follow the harness when `standard`
|
||||||
changes.
|
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
|
||||||
|
directory is {{cwd}}*. The harness registers prompt variables per section and an
|
||||||
|
unregistered reference **throws during prompt assembly**, which fails the entire
|
||||||
|
turn — not a warning, not a literal left in the text. That is not a hypothetical:
|
||||||
|
a harness release stopped registering `cwd` (only `provider` and `model` remain),
|
||||||
|
and every session on this bundle's preset failed with
|
||||||
|
`unknown prompt variable "{{cwd}}" in section "deployment:persona-suffix"`.
|
||||||
|
|
||||||
|
So neither preset carries that suffix now, and the folder is stated where it can
|
||||||
|
follow the session instead: `facet-guard`'s runtime binding names the facet, and
|
||||||
|
names the session folder too when the two differ — which is exactly the case
|
||||||
|
where relative tool paths need saying out loud. `test/presets.test.js` scans both
|
||||||
|
files for `{{…}}` and fails on any name outside `provider, model`, and the same
|
||||||
|
test holds this bundle's own rule and binding text to no references at all.
|
||||||
|
|
||||||
|
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
|
## What it does not cover
|
||||||
|
|
||||||
Honest boundaries, because each one is a decision rather than an oversight:
|
Honest boundaries, because each one is a decision rather than an oversight:
|
||||||
@@ -231,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
|
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.
|
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, and `present`'s nested `files[].path` (it shows the user a
|
||||||
tools whose path argument is a plain top-level string.
|
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
|
- **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
|
the harness — `dsh-fs-sandbox` states plainly that "reads pass through
|
||||||
untouched: every mode permits reading" — so anything that reads through
|
untouched: every mode permits reading" — so anything that reads through
|
||||||
@@ -246,7 +326,7 @@ Honest boundaries, because each one is a decision rather than an oversight:
|
|||||||
|
|
||||||
Verified:
|
Verified:
|
||||||
|
|
||||||
- 88 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
|
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
|
||||||
@@ -256,8 +336,18 @@ Verified:
|
|||||||
declared scope rather than the session directory, that a search naming no path
|
declared scope rather than the session directory, that a search naming no path
|
||||||
is refused when the directory it defaults to is outside the facet, that a
|
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
|
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
|
out of a self-narrowing, that both listings normalise into one picker level and
|
||||||
declared output schema.
|
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, 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
|
- 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`,
|
||||||
@@ -315,15 +405,17 @@ would publish.
|
|||||||
## Development
|
## Development
|
||||||
|
|
||||||
```sh
|
```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
|
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
|
`@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
|
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
|
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
|
## Layout
|
||||||
|
|
||||||
@@ -335,7 +427,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/ 88 tests
|
test/ 107 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
|
||||||
@@ -360,14 +452,16 @@ refuses a path that is not under a volatile node, and refusing is exactly right
|
|||||||
the panel is the only writer, and a plugin that could not serve the namespace
|
the panel is the only writer, and a plugin that could not serve the namespace
|
||||||
would be a control that silently stored nothing.
|
would be a control that silently stored nothing.
|
||||||
|
|
||||||
The listing reaches the panel through `ctx.get('uiWorkspace')` rather than through
|
The listings reach the panel through `ctx.get` rather than through an injection —
|
||||||
an injection, and the injection's `available()` is asked on every render. Both are
|
`uiWorkspace` for folders and `remote.workspaceFiles` for files — and each
|
||||||
deliberate: `ctx.inject` would make the whole context button conditional on a
|
`available()` is asked on every render. Both are deliberate: `ctx.inject` would
|
||||||
service the plugin does not own, and the panel is still the only way to declare
|
make the whole context button conditional on services the plugin does not own, and
|
||||||
scope in a deployment with no directory browser — it would simply have no listing
|
the panel is still the only way to declare scope in a deployment with no directory
|
||||||
to offer, which is what it says instead. The service is resolved at the call
|
browser — it would simply have no listing to offer, which is what it says instead.
|
||||||
because the renderer memoizes a registration's inject result, so a boolean read
|
The services are resolved at the call because the renderer memoizes a
|
||||||
there would freeze at whatever the first render saw.
|
registration's inject result, so a boolean read there would freeze at whatever the
|
||||||
|
first render saw. Both packages are named in this bundle's `dsh.client.inject`, so
|
||||||
|
a profile that installs this one gets the services its dialog asks for.
|
||||||
|
|
||||||
The two dialogs are wider than the primitive's 380px card, which is fixed in the
|
The two dialogs are wider than the primitive's 380px card, which is fixed in the
|
||||||
primitives' own stylesheet. `client/client.js` installs one small stylesheet of
|
primitives' own stylesheet. `client/client.js` installs one small stylesheet of
|
||||||
|
|||||||
+273
-33
@@ -46,6 +46,7 @@ window.__ModuleLoader__.load({
|
|||||||
SettingsFormModel,
|
SettingsFormModel,
|
||||||
SettingsValueField,
|
SettingsValueField,
|
||||||
IconFolderCloseRegular,
|
IconFolderCloseRegular,
|
||||||
|
FileTypeIcon,
|
||||||
} = primitives
|
} = primitives
|
||||||
|
|
||||||
const h = react.createElement
|
const h = react.createElement
|
||||||
@@ -448,7 +449,10 @@ window.__ModuleLoader__.load({
|
|||||||
*
|
*
|
||||||
* The Host's own business message is preferred to the transport error,
|
* The Host's own business message is preferred to the transport error,
|
||||||
* because a browse refusal is an answer — the folder is unreadable, the path
|
* because a browse refusal is an answer — the folder is unreadable, the path
|
||||||
* is not absolute — and that sentence is the one worth reading.
|
* is not absolute — and that sentence is the one worth reading. Both listers
|
||||||
|
* reach here: the folder primitive rejects with its own error and the remote
|
||||||
|
* one folds its failure into a `RemoteError`, which is an `Error` carrying
|
||||||
|
* the same message field.
|
||||||
*/
|
*/
|
||||||
function browseFailure(error) {
|
function browseFailure(error) {
|
||||||
const rpc = error !== null && typeof error === 'object' ? error.rpcError : undefined
|
const rpc = error !== null && typeof error === 'object' ? error.rpcError : undefined
|
||||||
@@ -456,6 +460,121 @@ window.__ModuleLoader__.load({
|
|||||||
return error instanceof Error ? error.message : String(error)
|
return error instanceof Error ? error.message : String(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── one level, in the picker's own vocabulary ────────────────────────────
|
||||||
|
//
|
||||||
|
// The Host has two listers and they answer different questions, so the
|
||||||
|
// picker reads them through one shape and does not care which answered:
|
||||||
|
//
|
||||||
|
// * `uiWorkspace.listDirectory` browses anywhere and returns folders only;
|
||||||
|
// * `remote.workspaceFiles.list` returns files as well, and confines itself
|
||||||
|
// to the session's workspace — the same listing the sidebar's file tree
|
||||||
|
// drives, and the only way this deployment can show a file at all.
|
||||||
|
//
|
||||||
|
// `{base, crumbs, entries, truncated, files}` is that shape. `files` says
|
||||||
|
// whether this level could carry file rows, which is what the copy under the
|
||||||
|
// path field tells the user.
|
||||||
|
|
||||||
|
/** Join one name onto a directory, with the separator the Host resolves. */
|
||||||
|
function joinUnder(base, name) {
|
||||||
|
return `${String(base).replace(/[\\/]+$/, '')}/${name}`
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Whether a path is a directory or sits inside one, either separator. */
|
||||||
|
function withinPath(inner, outer) {
|
||||||
|
const path = String(inner).replace(/\\/g, '/').replace(/\/+$/, '')
|
||||||
|
const base = String(outer).replace(/\\/g, '/').replace(/\/+$/, '')
|
||||||
|
return base !== '' && (path === base || path.startsWith(`${base}/`))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The last segment of a path, for a trail's first crumb. */
|
||||||
|
function basenameOf(path) {
|
||||||
|
const segments = pathSegments(path)
|
||||||
|
return segments.length === 0 ? String(path) : segments[segments.length - 1]
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ancestry of one path inside the workspace, workspace root first.
|
||||||
|
*
|
||||||
|
* The folder primitive reports its own trail — from the filesystem root, so
|
||||||
|
* the user can go above the session — and the file listing reports none,
|
||||||
|
* because the workspace root is as far up as it goes. This builds the one it
|
||||||
|
* does not send.
|
||||||
|
*/
|
||||||
|
function trailTo(workspace, path) {
|
||||||
|
const trail = [{ name: basenameOf(workspace), path: workspace }]
|
||||||
|
const rest = relativeTo(workspace, path)
|
||||||
|
// A path outside the workspace cannot be walked to from it, and `relativeTo`
|
||||||
|
// says so by answering in `..` segments or absolutely.
|
||||||
|
if (rest === '' || rest.startsWith('..') || isAbsolutePath(rest)) return trail
|
||||||
|
let walked = workspace
|
||||||
|
for (const segment of rest.split('/')) {
|
||||||
|
if (segment === '') continue
|
||||||
|
walked = joinUnder(walked, segment)
|
||||||
|
trail.push({ name: segment, path: walked })
|
||||||
|
}
|
||||||
|
return trail
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One folder listing, as the picker reads it.
|
||||||
|
*
|
||||||
|
* @param {object} listing - a `DirectoryListing` from the browse primitive.
|
||||||
|
* @param {string} [fallback] - the path asked for, when the answer carries none.
|
||||||
|
* @returns {object} the picker's level.
|
||||||
|
*/
|
||||||
|
function folderListing(listing, fallback) {
|
||||||
|
const base = typeof listing?.path === 'string' && listing.path !== '' ? listing.path : String(fallback ?? '')
|
||||||
|
const home = typeof listing?.home === 'string' ? listing.home : ''
|
||||||
|
return {
|
||||||
|
base,
|
||||||
|
crumbs: (Array.isArray(listing?.crumbs) ? listing.crumbs : []).map((crumb) => ({
|
||||||
|
// A root crumb carries its whole path as its name; "Home" is the label
|
||||||
|
// the host's own browser gives it.
|
||||||
|
name: crumb.path === home ? 'Home' : crumb.name,
|
||||||
|
path: crumb.path,
|
||||||
|
})),
|
||||||
|
entries: (Array.isArray(listing?.entries) ? listing.entries : []).map((entry) => ({
|
||||||
|
name: entry.name,
|
||||||
|
path: entry.path,
|
||||||
|
directory: true,
|
||||||
|
hidden: entry.hidden === true,
|
||||||
|
})),
|
||||||
|
truncated: listing?.truncated === true,
|
||||||
|
files: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One workspace listing, as the picker reads it.
|
||||||
|
*
|
||||||
|
* Paths arrive relative to the workspace root and the picker works in
|
||||||
|
* absolute paths, so they are joined here — with `/`, whatever the level's
|
||||||
|
* own separators, because the Host resolves mixed separators and this is only
|
||||||
|
* a key and something to display.
|
||||||
|
*
|
||||||
|
* @param {object} listing - a `WorkspaceDirectoryListing`.
|
||||||
|
* @param {string} workspace - the session folder, absolute.
|
||||||
|
* @returns {object} the picker's level.
|
||||||
|
*/
|
||||||
|
function workspaceListing(listing, workspace) {
|
||||||
|
const relative = typeof listing?.path === 'string' ? listing.path : ''
|
||||||
|
const base = relative === '' ? workspace : joinUnder(workspace, relative)
|
||||||
|
return {
|
||||||
|
base,
|
||||||
|
crumbs: trailTo(workspace, base),
|
||||||
|
entries: (Array.isArray(listing?.entries) ? listing.entries : []).map((entry) => ({
|
||||||
|
name: entry.name,
|
||||||
|
path: joinUnder(base, entry.name),
|
||||||
|
directory: entry.type === 'directory',
|
||||||
|
// The workspace listing has no hidden flag; the platform convention is
|
||||||
|
// the dot, which is what the folder primitive reports for the same name.
|
||||||
|
hidden: String(entry.name).startsWith('.'),
|
||||||
|
})),
|
||||||
|
truncated: listing?.truncated === true,
|
||||||
|
files: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The state behind the picker: the level on screen, the path being edited,
|
* The state behind the picker: the level on screen, the path being edited,
|
||||||
* and the last failure.
|
* and the last failure.
|
||||||
@@ -466,17 +585,25 @@ window.__ModuleLoader__.load({
|
|||||||
* a sequence number and only the newest may commit. It also keeps the whole
|
* a sequence number and only the newest may commit. It also keeps the whole
|
||||||
* interaction testable without a DOM, which is the same reason the settings
|
* interaction testable without a DOM, which is the same reason the settings
|
||||||
* card has a controller.
|
* card has a controller.
|
||||||
|
*
|
||||||
|
* Two listers in, one level out: see the note above {@link folderListing}
|
||||||
|
* for why there are two and what the picker does with either.
|
||||||
*/
|
*/
|
||||||
var DirectoryPickerModel = class {
|
var DirectoryPickerModel = class {
|
||||||
/**
|
/**
|
||||||
* @param {object} options
|
* @param {object} options
|
||||||
* @param {(path?: string, signal?: AbortSignal) => Promise<object>} options.list - the host listing call.
|
* @param {(path?: string, signal?: AbortSignal) => Promise<object>} options.folders - the folder listing; browses anywhere.
|
||||||
|
* @param {(sessionId: string, path: string, signal?: AbortSignal) => Promise<object>} [options.files] - the file listing; files and folders, confined to the workspace.
|
||||||
|
* @param {string} [options.sessionId] - the session whose workspace the file listing is confined to.
|
||||||
* @param {string} options.root - the session folder, absolute, or ''.
|
* @param {string} options.root - the session folder, absolute, or ''.
|
||||||
* @param {string} [options.start] - the directory to open first; the root by default.
|
* @param {string} [options.start] - the directory to open first; the root by default.
|
||||||
*/
|
*/
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
const root = typeof options.root === 'string' ? options.root : ''
|
const root = typeof options.root === 'string' ? options.root : ''
|
||||||
this.list = options.list
|
this.folders = options.folders
|
||||||
|
this.files = options.files
|
||||||
|
this.sessionId = options.sessionId
|
||||||
|
this.root = root
|
||||||
this.listeners = new Set()
|
this.listeners = new Set()
|
||||||
this.request = 0
|
this.request = 0
|
||||||
this.state = {
|
this.state = {
|
||||||
@@ -524,15 +651,53 @@ window.__ModuleLoader__.load({
|
|||||||
const target = String(path ?? '').trim()
|
const target = String(path ?? '').trim()
|
||||||
const request = (this.request += 1)
|
const request = (this.request += 1)
|
||||||
this.update({ loading: true, error: '', draft: target })
|
this.update({ loading: true, error: '', draft: target })
|
||||||
Promise.resolve()
|
this.read(target, request)
|
||||||
.then(() => this.list(target === '' ? undefined : target))
|
}
|
||||||
.then(
|
|
||||||
(listing) => {
|
/**
|
||||||
|
* One level, from whichever lister can answer for it.
|
||||||
|
*
|
||||||
|
* The file listing is tried first while the level is inside the session's
|
||||||
|
* workspace, because that is the listing the extras need: it carries files
|
||||||
|
* as well as folders. The Host confines it to the workspace, so a level
|
||||||
|
* above the workspace root — or a deployment with no file service — falls
|
||||||
|
* back to the folder listing, which browses anywhere and carries folders
|
||||||
|
* only. The fallback is also the answer to a file listing that failed for
|
||||||
|
* any other reason, so a level the file service cannot read is still
|
||||||
|
* browsable as folders rather than reported as unreadable.
|
||||||
|
*
|
||||||
|
* @param {string} target - the absolute directory, or '' for the Host's home.
|
||||||
|
* @param {number} request - the sequence number this read belongs to.
|
||||||
|
*/
|
||||||
|
read(target, request) {
|
||||||
|
const files = this.files
|
||||||
|
const inside = target === '' ? this.root !== '' : withinPath(target, this.root)
|
||||||
|
const asFolders = () => this.folders(target === '' ? undefined : target).then((listing) => folderListing(listing, target))
|
||||||
|
const listing =
|
||||||
|
files === undefined || !inside
|
||||||
|
? asFolders()
|
||||||
|
: files(this.sessionId, target === '' ? this.root : target)
|
||||||
|
.then((answer) => workspaceListing(answer, this.root))
|
||||||
|
.catch(asFolders)
|
||||||
|
Promise.resolve(listing).then(
|
||||||
|
(level) => {
|
||||||
if (request !== this.request) return
|
if (request !== this.request) return
|
||||||
this.update({ listing, loading: false, error: '', draft: String(listing?.path ?? target) })
|
this.update({ listing: level, loading: false, error: '', draft: level.base })
|
||||||
},
|
},
|
||||||
(reason) => {
|
(reason) => {
|
||||||
if (request !== this.request) return
|
if (request !== this.request) return
|
||||||
|
// A path that names a file in the level already on screen is not a
|
||||||
|
// failure, it is the thing this dialog is for: the list asked for is
|
||||||
|
// not a list, and the footer can still add what it names. That
|
||||||
|
// matters now that a file row is one keystroke away from the field.
|
||||||
|
const wanted = absoluteFrom(this.root, target)
|
||||||
|
const named = (this.state.listing?.entries ?? []).some(
|
||||||
|
(entry) => entry.directory !== true && entry.path === wanted,
|
||||||
|
)
|
||||||
|
if (named) {
|
||||||
|
this.update({ loading: false, error: '' })
|
||||||
|
return
|
||||||
|
}
|
||||||
this.update({ loading: false, error: browseFailure(reason) })
|
this.update({ loading: false, error: browseFailure(reason) })
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -571,6 +736,13 @@ window.__ModuleLoader__.load({
|
|||||||
}
|
}
|
||||||
const pickerNameStyle = { flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }
|
const pickerNameStyle = { flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }
|
||||||
const pickerGlyphStyle = { display: 'inline-flex', flex: 'none', color: 'var(--dsw-alias-label-secondary)' }
|
const pickerGlyphStyle = { display: 'inline-flex', flex: 'none', color: 'var(--dsw-alias-label-secondary)' }
|
||||||
|
/** A file row the path field already names, so a click is visibly a choice. */
|
||||||
|
const pickerChosenRowStyle = {
|
||||||
|
...pickerRowStyle,
|
||||||
|
// The token the Host's own directory browser uses for a chosen row, fallback
|
||||||
|
// and all, so a pick looks the same here as it does one panel over.
|
||||||
|
background: 'var(--dsw-alias-interactive-bg-active,var(--dsw-alias-interactive-bg-hover))',
|
||||||
|
}
|
||||||
const crumbStyle = {
|
const crumbStyle = {
|
||||||
flex: 'none',
|
flex: 'none',
|
||||||
border: 0,
|
border: 0,
|
||||||
@@ -599,7 +771,13 @@ window.__ModuleLoader__.load({
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The directory picker: one editable path, the ancestry above it, and one
|
* The directory picker: one editable path, the ancestry above it, and one
|
||||||
* level of child folders.
|
* level of children — folders always, and files wherever the Host will list
|
||||||
|
* them.
|
||||||
|
*
|
||||||
|
* A folder row is a way down; a file row is a thing to take, so it fills the
|
||||||
|
* path field rather than navigating, and the primary action adds what the
|
||||||
|
* field holds. That is the one interaction the two row kinds do not share,
|
||||||
|
* and it is why a file row is marked selected once the field names it.
|
||||||
*
|
*
|
||||||
* It drives no host call of its own — {@link DirectoryPickerModel} holds the
|
* It drives no host call of its own — {@link DirectoryPickerModel} holds the
|
||||||
* listing and the path, and the panel builds one per opening so each visit
|
* listing and the path, and the panel builds one per opening so each visit
|
||||||
@@ -622,6 +800,9 @@ window.__ModuleLoader__.load({
|
|||||||
// folder: the focus's own default, and for an extra — already the root —
|
// folder: the focus's own default, and for an extra — already the root —
|
||||||
// nothing worth adding.
|
// nothing worth adding.
|
||||||
const declared = relativeTo(root, typed)
|
const declared = relativeTo(root, typed)
|
||||||
|
// The field's own value as an absolute path, so a file row can tell whether
|
||||||
|
// it is the one the field names.
|
||||||
|
const chosen = absoluteFrom(root, typed)
|
||||||
|
|
||||||
const rows = entries.map((entry) =>
|
const rows = entries.map((entry) =>
|
||||||
h(
|
h(
|
||||||
@@ -630,14 +811,22 @@ window.__ModuleLoader__.load({
|
|||||||
key: entry.path,
|
key: entry.path,
|
||||||
type: 'button',
|
type: 'button',
|
||||||
className: ROW_CLASS,
|
className: ROW_CLASS,
|
||||||
style: pickerRowStyle,
|
style: entry.directory || entry.path !== chosen ? pickerRowStyle : pickerChosenRowStyle,
|
||||||
title: entry.path,
|
title: entry.path,
|
||||||
disabled: blocked || state.loading,
|
disabled: blocked || state.loading,
|
||||||
// A click walks down rather than picking: the primary action is the
|
// A folder is chosen by standing in it; a file is chosen by naming
|
||||||
// path field's own value, so a folder is chosen by standing in it.
|
// it, so the click puts it in the field for the footer to add. The
|
||||||
onClick: () => model.open(entry.path),
|
// field holds an absolute path everywhere else in this dialog, and
|
||||||
|
// the declared form is what the panel's write turns it into.
|
||||||
|
onClick: () => (entry.directory || target === 'focus' ? model.open(entry.path) : model.setDraft(entry.path)),
|
||||||
},
|
},
|
||||||
h('span', { style: pickerGlyphStyle }, h(IconFolderCloseRegular, { size: 14 })),
|
h(
|
||||||
|
'span',
|
||||||
|
{ style: pickerGlyphStyle },
|
||||||
|
entry.directory
|
||||||
|
? h(IconFolderCloseRegular, { size: 14 })
|
||||||
|
: h(FileTypeIcon, { path: entry.name, size: 16 }),
|
||||||
|
),
|
||||||
h('span', { style: pickerNameStyle }, entry.name),
|
h('span', { style: pickerNameStyle }, entry.name),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -656,10 +845,7 @@ window.__ModuleLoader__.load({
|
|||||||
disabled: blocked || state.loading,
|
disabled: blocked || state.loading,
|
||||||
onClick: () => model.open(crumb.path),
|
onClick: () => model.open(crumb.path),
|
||||||
},
|
},
|
||||||
// A root crumb carries its whole path as its name; "Home" is the
|
crumb.name,
|
||||||
// shorter label the host's own browser gives it, and the title
|
|
||||||
// attribute still names where it is.
|
|
||||||
crumb.path === listing.home ? 'Home' : crumb.name,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -672,9 +858,18 @@ window.__ModuleLoader__.load({
|
|||||||
: listing === null
|
: listing === null
|
||||||
? h('p', { key: 'status', style: pickerStatusStyle }, 'Type a folder to start from.')
|
? h('p', { key: 'status', style: pickerStatusStyle }, 'Type a folder to start from.')
|
||||||
: entries.length === 0
|
: entries.length === 0
|
||||||
? h('p', { key: 'status', style: pickerStatusStyle }, 'No folders in here.')
|
? h('p', { key: 'status', style: pickerStatusStyle }, 'Nothing in here.')
|
||||||
: listing.truncated === true
|
: listing.truncated === true
|
||||||
? h('p', { key: 'status', style: pickerStatusStyle }, 'Too many folders to list; only the beginning is shown.')
|
? h('p', { key: 'status', style: pickerStatusStyle }, 'Too many entries to list; only the beginning is shown.')
|
||||||
|
: // Above the session folder the Host's file listing stops — it is
|
||||||
|
// confined to the workspace — so the rows become folders only.
|
||||||
|
// Saying so is better than letting file rows silently vanish.
|
||||||
|
target === 'extra' && listing.files !== true
|
||||||
|
? h(
|
||||||
|
'p',
|
||||||
|
{ key: 'status', style: pickerStatusStyle },
|
||||||
|
'Files are listed inside the session folder only; above it the list is folders.',
|
||||||
|
)
|
||||||
: null
|
: null
|
||||||
|
|
||||||
return h(Modal, {
|
return h(Modal, {
|
||||||
@@ -702,8 +897,9 @@ window.__ModuleLoader__.load({
|
|||||||
value: typed,
|
value: typed,
|
||||||
disabled: blocked,
|
disabled: blocked,
|
||||||
spellCheck: false,
|
spellCheck: false,
|
||||||
// The Host lists folders, so this box is also how a file — or a
|
// The listing carries the files it can reach; the box is still how a
|
||||||
// folder the session will create — is named at all.
|
// path outside the session's workspace — or a folder the session
|
||||||
|
// will create — is named at all.
|
||||||
'data-modal-autofocus': true,
|
'data-modal-autofocus': true,
|
||||||
placeholder: root === '' ? absoluteFrom(root, 'src/shared') : 'relative/to/the/session/folder',
|
placeholder: root === '' ? absoluteFrom(root, 'src/shared') : 'relative/to/the/session/folder',
|
||||||
onChange: (event) => model.setDraft(event.target.value),
|
onChange: (event) => model.setDraft(event.target.value),
|
||||||
@@ -718,10 +914,10 @@ window.__ModuleLoader__.load({
|
|||||||
{ style: hintStyle },
|
{ style: hintStyle },
|
||||||
target === 'focus'
|
target === 'focus'
|
||||||
? 'Relative to the session folder, or absolute. Enter lists whatever is there.'
|
? 'Relative to the session folder, or absolute. Enter lists whatever is there.'
|
||||||
: // The list holds folders only — the Host's browse primitive has no
|
: // Files where the Host lists them, folders everywhere. The box is
|
||||||
// file rows — so the box is where a file is named, and saying so
|
// still where a path the listing cannot reach gets named, so both
|
||||||
// is the difference between a dead end and an instruction.
|
// halves of that are said rather than left to be discovered.
|
||||||
'Relative to the session folder, or absolute. The list holds folders; type a file\u2019s name to add the file itself.',
|
'Relative to the session folder, or absolute. Folders open; a file is taken as the path to add.',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
h(
|
h(
|
||||||
@@ -843,6 +1039,24 @@ window.__ModuleLoader__.load({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The file lister an opening should offer, if any.
|
||||||
|
*
|
||||||
|
* Files are what an extra may name, so that is the only control which offers
|
||||||
|
* them: a focus is a folder, and a listing that could hand the picker a file
|
||||||
|
* would only offer something that cannot be chosen. A deployment without the
|
||||||
|
* file service gets the folder listing as before, which is why this asks
|
||||||
|
* rather than assumes.
|
||||||
|
*
|
||||||
|
* @param {object} browse - the browsing face from {@link directoryBrowse}.
|
||||||
|
* @param {string} target - 'focus' or 'extra'.
|
||||||
|
* @returns {Function|undefined} the lister, or nothing to offer.
|
||||||
|
*/
|
||||||
|
function fileLister(browse, target) {
|
||||||
|
if (target !== 'extra') return undefined
|
||||||
|
return browse?.files?.available?.() === true ? browse.files.list : undefined
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The facet context panel: what this conversation may see, and who decides.
|
* The facet context panel: what this conversation may see, and who decides.
|
||||||
*
|
*
|
||||||
@@ -856,8 +1070,8 @@ window.__ModuleLoader__.load({
|
|||||||
* "which folder is `../shared`" is exactly the question a free-text box
|
* "which folder is `../shared`" is exactly the question a free-text box
|
||||||
* cannot answer; the listing answers it from the Host's own directory rather
|
* cannot answer; the listing answers it from the Host's own directory rather
|
||||||
* than from a guess about what the path was meant to name. The path field is
|
* than from a guess about what the path was meant to name. The path field is
|
||||||
* still editable inside the picker, because the Host lists folders and the
|
* still editable inside the picker, for a path no listing reaches: a folder
|
||||||
* extras may name a file.
|
* the session will create, or a file above the session's workspace.
|
||||||
*
|
*
|
||||||
* @param {object} props - the bound form, the session, its folder, the browse face, and the close command.
|
* @param {object} props - the bound form, the session, its folder, the browse face, and the close command.
|
||||||
*/
|
*/
|
||||||
@@ -911,7 +1125,9 @@ window.__ModuleLoader__.load({
|
|||||||
setPicker({
|
setPicker({
|
||||||
target,
|
target,
|
||||||
model: new DirectoryPickerModel({
|
model: new DirectoryPickerModel({
|
||||||
list: browse.list,
|
folders: browse.list,
|
||||||
|
files: fileLister(browse, target),
|
||||||
|
sessionId,
|
||||||
root,
|
root,
|
||||||
start: isAbsolutePath(stored) ? stored : '',
|
start: isAbsolutePath(stored) ? stored : '',
|
||||||
}),
|
}),
|
||||||
@@ -1016,7 +1232,7 @@ window.__ModuleLoader__.load({
|
|||||||
|
|
||||||
h('h3', { style: { ...sectionTitleStyle, marginTop: '18px' } }, 'Also allowed'),
|
h('h3', { style: { ...sectionTitleStyle, marginTop: '18px' } }, 'Also allowed'),
|
||||||
declared.extras.length === 0
|
declared.extras.length === 0
|
||||||
? h('p', { style: bodyStyle }, 'Nothing yet. Shared types, project docs, or a sibling folder go here.')
|
? h('p', { style: bodyStyle }, 'Nothing yet. Shared types, project docs, or a single file go here.')
|
||||||
: h('ul', { style: { listStyle: 'none', margin: 0, padding: 0 } }, rows),
|
: h('ul', { style: { listStyle: 'none', margin: 0, padding: 0 } }, rows),
|
||||||
h(
|
h(
|
||||||
'div',
|
'div',
|
||||||
@@ -1155,7 +1371,7 @@ window.__ModuleLoader__.load({
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The directory-browsing face the picker drives.
|
* The browsing face the picker drives: two listers, because the Host has two.
|
||||||
*
|
*
|
||||||
* `uiWorkspace` is read lazily rather than injected. Injecting it would make
|
* `uiWorkspace` is read lazily rather than injected. Injecting it would make
|
||||||
* the whole context button conditional on it, and the panel is still the
|
* the whole context button conditional on it, and the panel is still the
|
||||||
@@ -1168,8 +1384,8 @@ window.__ModuleLoader__.load({
|
|||||||
* would freeze at whatever the first render saw, and the service may well
|
* would freeze at whatever the first render saw, and the service may well
|
||||||
* activate after this bundle does.
|
* activate after this bundle does.
|
||||||
*
|
*
|
||||||
* @param {object} ctx - the client context to resolve the service from.
|
* @param {object} ctx - the client context to resolve the services from.
|
||||||
* @returns {object} `available()` and `list()`, the two calls the panel makes.
|
* @returns {object} `available()`/`list()` for folders, and the same pair again under `files`.
|
||||||
*/
|
*/
|
||||||
function directoryBrowse(ctx) {
|
function directoryBrowse(ctx) {
|
||||||
const workspace = () => ctx.get('uiWorkspace')
|
const workspace = () => ctx.get('uiWorkspace')
|
||||||
@@ -1183,6 +1399,24 @@ window.__ModuleLoader__.load({
|
|||||||
}
|
}
|
||||||
return service.listDirectory(path, signal)
|
return service.listDirectory(path, signal)
|
||||||
},
|
},
|
||||||
|
// Folders only, anywhere on the machine. The file lister below is what
|
||||||
|
// makes an extra selectable by name; this one is what makes it
|
||||||
|
// reachable at all, and the two are needed together.
|
||||||
|
files: {
|
||||||
|
available: () => typeof ctx.get('remote.workspaceFiles')?.list === 'function',
|
||||||
|
list: (sessionId, path, signal) => {
|
||||||
|
const server = ctx.get('remote.workspaceFiles')
|
||||||
|
if (server === undefined || typeof server.list !== 'function') {
|
||||||
|
return Promise.reject(new Error('This deployment cannot list files.'))
|
||||||
|
}
|
||||||
|
// The Host confines this to the Session's workspace, which is why the
|
||||||
|
// model falls back to the folder listing above the session folder.
|
||||||
|
return server.list(sessionId, path, signal).then((result) => {
|
||||||
|
if (result?.ok !== true) throw result?.error ?? new Error('The Host refused that listing.')
|
||||||
|
return result.value
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1266,7 +1500,13 @@ window.__ModuleLoader__.load({
|
|||||||
absoluteFrom,
|
absoluteFrom,
|
||||||
relativeTo,
|
relativeTo,
|
||||||
isAbsolutePath,
|
isAbsolutePath,
|
||||||
|
withinPath,
|
||||||
|
joinUnder,
|
||||||
|
trailTo,
|
||||||
|
folderListing,
|
||||||
|
workspaceListing,
|
||||||
directoryBrowse,
|
directoryBrowse,
|
||||||
|
fileLister,
|
||||||
}
|
}
|
||||||
return module.exports
|
return module.exports
|
||||||
},
|
},
|
||||||
|
|||||||
+58
-9
@@ -101,6 +101,49 @@ export function apply(ctx, config) {
|
|||||||
return true
|
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
|
// `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 —
|
// 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)
|
const scope = policy.scopeFor(exec.agent)
|
||||||
if (scope === undefined) return undefined
|
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) {
|
if (paths.length === 0) {
|
||||||
// A tool that names no path is judged against the path it will actually
|
// 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
|
// 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
|
// 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
|
// is the current working directory, which a narrowed facet does not
|
||||||
// "no opinion" there would hand the model a read the guard exists to
|
// contain, and "no opinion" there would hand the model a read the guard
|
||||||
// refuse. The containment test is the same one; only the path is ours
|
// exists to refuse. The containment test is the same one; only the path is
|
||||||
// rather than the model's.
|
// ours rather than the model's.
|
||||||
if (!IMPLICIT_SESSION_PATHS.includes(exec.name)) return undefined
|
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
|
if (verdict.inside) return undefined
|
||||||
const kind = mode === 'deny' ? 'deny' : 'ask'
|
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) {
|
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
|
if (verdict.inside) continue
|
||||||
const kind = mode === 'deny' ? 'deny' : 'ask'
|
const kind = mode === 'deny' ? 'deny' : 'ask'
|
||||||
return {
|
return {
|
||||||
kind,
|
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
|
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
|
* 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
|
* 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|undefined} sessionId - the session.
|
||||||
* @param {string} sessionCwd - its resolved working directory.
|
* @param {string} sessionCwd - its resolved working directory.
|
||||||
@@ -176,7 +181,8 @@ export function createFacetPolicy(config) {
|
|||||||
const declared = declaredScope(sessionId)?.focus
|
const declared = declaredScope(sessionId)?.focus
|
||||||
const stated = typeof declared === 'string' && declared.trim() !== ''
|
const stated = typeof declared === 'string' && declared.trim() !== ''
|
||||||
const own = stated ? resolve(sessionCwd, declared) : sessionCwd
|
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)
|
const agentFocus = sessionId === undefined ? undefined : narrowed.get(sessionId)
|
||||||
if (agentFocus !== undefined && within(agentFocus, base)) return agentFocus
|
if (agentFocus !== undefined && within(agentFocus, base)) return agentFocus
|
||||||
return base
|
return base
|
||||||
|
|||||||
+69
-6
@@ -42,16 +42,33 @@
|
|||||||
* reliably from argv, so the facet is enforced on the file tools and `bash`
|
* 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
|
* remains a legitimate way out. The prompt says so rather than pretending
|
||||||
* otherwise.
|
* 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({
|
export const PATH_ARGUMENTS = Object.freeze({
|
||||||
read: ['file_path'],
|
read: ['file_path', 'path'],
|
||||||
write: ['file_path'],
|
write: ['file_path', 'path'],
|
||||||
edit: ['file_path'],
|
edit: ['file_path', 'file', 'path'],
|
||||||
read_image: ['file_path'],
|
read_image: ['file_path', 'path'],
|
||||||
|
undo_last_edit: ['path'],
|
||||||
grep: ['path'],
|
grep: ['path'],
|
||||||
glob: ['path'],
|
glob: ['path'],
|
||||||
str_replace_editor: ['path'],
|
str_replace_editor: ['path'],
|
||||||
recall: ['path', 'focus'],
|
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 FACET_TOOL = 'facet'
|
||||||
export const WIDENING_ACTION = 'add'
|
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.
|
* 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 {string} toolName - the tool being called.
|
||||||
* @param {unknown} args - the raw model arguments.
|
* @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.
|
* @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 []
|
if (args === null || typeof args !== 'object') return []
|
||||||
const record = /** @type {Record<string, unknown>} */ (args)
|
const record = /** @type {Record<string, unknown>} */ (args)
|
||||||
|
|
||||||
const names = PATH_ARGUMENTS[toolName]
|
const names = pathParameterNames(toolName, declaredNames)
|
||||||
if (names === undefined) return []
|
if (names === undefined) return []
|
||||||
|
|
||||||
const out = []
|
const out = []
|
||||||
@@ -233,6 +284,18 @@ export function facetContextText(input) {
|
|||||||
// model needs a path it can reason about, and the user reading an approval
|
// model needs a path it can reason about, and the user reading an approval
|
||||||
// prompt needs to see which folder they are being asked about.
|
// prompt needs to see which folder they are being asked about.
|
||||||
const lines = [`facet: ${root}`]
|
const lines = [`facet: ${root}`]
|
||||||
|
// The session folder is named only when it is not the facet — the case wherever
|
||||||
|
// the user narrowed a conversation that started higher up — because that is when
|
||||||
|
// the two differ and relative paths in tool calls need saying out loud.
|
||||||
|
//
|
||||||
|
// It used to be the deployment persona's suffix that stated this, through the
|
||||||
|
// `cwd` prompt variable. The harness stopped registering that variable, and an
|
||||||
|
// unknown one now throws during prompt assembly instead of rendering as text, so
|
||||||
|
// a static template cannot carry a per-session fact any more. This can: it is
|
||||||
|
// rebuilt for each request from the same header the tool calls resolve against.
|
||||||
|
if (typeof cwd === 'string' && cwd !== '' && cwd !== root) {
|
||||||
|
lines.push(`session folder: ${cwd} — relative paths in tool calls resolve here`)
|
||||||
|
}
|
||||||
if (extras.length > 0) lines.push(`granted outside it: ${extras.map((path) => displayPath(cwd, path)).join(', ')}`)
|
if (extras.length > 0) lines.push(`granted outside it: ${extras.map((path) => displayPath(cwd, path)).join(', ')}`)
|
||||||
lines.push(`outside the facet: ${reach}`)
|
lines.push(`outside the facet: ${reach}`)
|
||||||
return lines.join('\n')
|
return lines.join('\n')
|
||||||
|
|||||||
+3
-2
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dsh-facet",
|
"name": "dsh-facet",
|
||||||
"version": "0.3.1",
|
"version": "0.4.3",
|
||||||
"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.",
|
||||||
@@ -51,7 +51,8 @@
|
|||||||
"@deepseek-ai/dsh-client-ui-settings",
|
"@deepseek-ai/dsh-client-ui-settings",
|
||||||
"@deepseek-ai/dsh-client-ui-plugin-manager",
|
"@deepseek-ai/dsh-client-ui-plugin-manager",
|
||||||
"@deepseek-ai/dsh-client-ui-conversation",
|
"@deepseek-ai/dsh-client-ui-conversation",
|
||||||
"@deepseek-ai/dsh-client-ui-workspace"
|
"@deepseek-ai/dsh-client-ui-workspace",
|
||||||
|
"@deepseek-ai/dsh-api-workspace-files"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+31
-35
@@ -1,21 +1,33 @@
|
|||||||
# Agent preset facet: one `@deepseek-ai/dsh-agent-preset` declaration inserted
|
# Agent preset facet: one `@deepseek-ai/dsh-agent-preset` declaration inserted
|
||||||
# after the web patch.
|
# after the web patch.
|
||||||
#
|
#
|
||||||
# The composition is `standard` with two changes, and this file is the only place
|
# The composition is the shipped `standard` patch with three changes, and this
|
||||||
# either of them is decided:
|
# file is the only place any of them is decided:
|
||||||
#
|
#
|
||||||
# * compaction is configured (see the `compaction` row below) so the pressure
|
# * 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
|
# trigger is a budget rather than a formality. The shipped ratio is 0.80 of a
|
||||||
# 1,000,000-token window, i.e. 800k, and on this deployment nothing has ever
|
# 1,000,000-token window, i.e. 800k, and on this deployment nothing has ever
|
||||||
# come within 1.5% of it — compaction had never once run;
|
# come within 1.5% of it — compaction had never once run;
|
||||||
#
|
#
|
||||||
# * `facet-guard` is mounted, which confines the session to its own folder.
|
# * `facet-guard` is mounted, which confines the session to its own folder;
|
||||||
|
#
|
||||||
|
# * 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
|
# Everything else is copied verbatim from the shipped `standard` patch, and that
|
||||||
# is deliberate: a preset declaration replaces the whole plugin list rather than
|
# 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
|
# 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
|
# whatever it drifted past — and a clone that keeps a row the harness has since
|
||||||
# this file and re-apply the two changes — do not hand-patch around it.
|
# 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:
|
- insert:
|
||||||
- id: preset-facet
|
- id: preset-facet
|
||||||
name: '@deepseek-ai/dsh-agent-preset'
|
name: '@deepseek-ai/dsh-agent-preset'
|
||||||
@@ -28,12 +40,13 @@
|
|||||||
- id: persona
|
- id: persona
|
||||||
name: '@deepseek-ai/dsh-persona'
|
name: '@deepseek-ai/dsh-persona'
|
||||||
config:
|
config:
|
||||||
suffix: Your working directory is {{cwd}}.
|
|
||||||
prefix: You are a coding agent powered by the {{model}} model.
|
prefix: You are a coding agent powered by the {{model}} model.
|
||||||
- id: agent-instructions
|
- id: agent-instructions
|
||||||
name: '@deepseek-ai/dsh-agent-instructions'
|
name: '@deepseek-ai/dsh-agent-instructions'
|
||||||
config:
|
config:
|
||||||
maxBytes: 65536
|
maxBytes: 65536
|
||||||
|
- id: time-context
|
||||||
|
name: '@deepseek-ai/dsh-time-context'
|
||||||
# The facet itself: a rule in the system prompt, the binding in the
|
# The facet itself: a rule in the system prompt, the binding in the
|
||||||
# runtime context, the `facet` tool, and the pre-execute guard that
|
# runtime context, the `facet` tool, and the pre-execute guard that
|
||||||
# asks before a file call leaves the session's folder. Configured by
|
# asks before a file call leaves the session's folder. Configured by
|
||||||
@@ -49,12 +62,17 @@
|
|||||||
disabled: !!js process.platform !== 'win32'
|
disabled: !!js process.platform !== 'win32'
|
||||||
- id: tool-fs
|
- id: tool-fs
|
||||||
name: '@deepseek-ai/dsh-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
|
- id: tool-fs-search
|
||||||
name: '@deepseek-ai/dsh-tool-fs-search'
|
name: '@deepseek-ai/dsh-tool-fs-search'
|
||||||
config:
|
config:
|
||||||
sampleOverCapGlobResults: false
|
sampleOverCapGlobResults: false
|
||||||
- id: tool-jobs
|
- id: tool-jobs
|
||||||
name: '@deepseek-ai/dsh-tool-jobs'
|
name: '@deepseek-ai/dsh-tool-jobs'
|
||||||
|
- id: tool-schedule
|
||||||
|
name: '@deepseek-ai/dsh-tool-schedule'
|
||||||
- id: skill-filesystem
|
- id: skill-filesystem
|
||||||
name: '@deepseek-ai/dsh-skill-filesystem'
|
name: '@deepseek-ai/dsh-skill-filesystem'
|
||||||
- id: tool-skill
|
- id: tool-skill
|
||||||
@@ -73,7 +91,7 @@
|
|||||||
name: '@deepseek-ai/dsh-plan-mode'
|
name: '@deepseek-ai/dsh-plan-mode'
|
||||||
config:
|
config:
|
||||||
section: |
|
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.
|
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.
|
||||||
|
|
||||||
@@ -94,7 +112,7 @@
|
|||||||
- id: compaction-basic
|
- id: compaction-basic
|
||||||
name: '@deepseek-ai/dsh-compaction-basic'
|
name: '@deepseek-ai/dsh-compaction-basic'
|
||||||
config:
|
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
|
# ever recorded here peaked at 787,668 pressure tokens: the
|
||||||
# trigger was never reached, so every token below it was re-read
|
# trigger was never reached, so every token below it was re-read
|
||||||
# on every subsequent step. 0.35 puts the ceiling at 350k.
|
# on every subsequent step. 0.35 puts the ceiling at 350k.
|
||||||
@@ -122,49 +140,24 @@
|
|||||||
config:
|
config:
|
||||||
- id: tool-subagent-control
|
- id: tool-subagent-control
|
||||||
name: '@deepseek-ai/dsh-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
|
- id: tool-subagent
|
||||||
name: '@deepseek-ai/dsh-tool-subagent'
|
name: '@deepseek-ai/dsh-tool-subagent'
|
||||||
config:
|
config:
|
||||||
provider: spawn
|
provider: spawn
|
||||||
toolName: subagent
|
toolName: subagent
|
||||||
modelSelectionSettings: true
|
modelSelection: true
|
||||||
backgroundMode: continuable
|
modelDiscovery: true
|
||||||
- id: tool-subagent-fork
|
- id: tool-subagent-fork
|
||||||
name: '@deepseek-ai/dsh-tool-subagent'
|
name: '@deepseek-ai/dsh-tool-subagent'
|
||||||
config:
|
config:
|
||||||
provider: fork
|
provider: fork
|
||||||
toolName: subagent_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
|
- id: workflow-ptc
|
||||||
name: '@deepseek-ai/dsh-workflow-ptc'
|
name: '@deepseek-ai/dsh-workflow-ptc'
|
||||||
config:
|
config:
|
||||||
provider: spawn
|
provider: spawn
|
||||||
- id: tool-workflow
|
- id: tool-workflow
|
||||||
name: '@deepseek-ai/dsh-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
|
- id: tool-ask-user
|
||||||
name: '@deepseek-ai/dsh-tool-ask-user'
|
name: '@deepseek-ai/dsh-tool-ask-user'
|
||||||
- id: tool-todo
|
- id: tool-todo
|
||||||
@@ -180,4 +173,7 @@
|
|||||||
name: '@deepseek-ai/dsh-tool-present'
|
name: '@deepseek-ai/dsh-tool-present'
|
||||||
- id: tool-plugin-manager
|
- id: tool-plugin-manager
|
||||||
name: '@deepseek-ai/dsh-plugin-manager/tools'
|
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
|
disabled: true
|
||||||
@@ -8,17 +8,25 @@
|
|||||||
#
|
#
|
||||||
# or add its path to `dsh.bundle.patch` in package.json.
|
# 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
|
# 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
|
# 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
|
# into it, so this file is a frozen copy of the shipped `standard` composition
|
||||||
# plus one change. 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
|
# 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
|
# will silently lose whatever was added, or fail to mount if the copy keeps a
|
||||||
# and re-apply when that happens; otherwise take the compaction settings into
|
# row the harness removed. Use it if you are prepared to re-copy and re-apply
|
||||||
# whichever preset you actually run.
|
# when that happens; otherwise take the compaction settings into whichever
|
||||||
|
# preset you actually run.
|
||||||
#
|
#
|
||||||
# The only change from the shipped file is the `compaction-basic` row's config.
|
# The one change from the shipped file is the `compaction-basic` row's config.
|
||||||
- insert:
|
# `test/presets.test.js` compares this file against the installed `standard`
|
||||||
|
# and fails on any other difference.
|
||||||
- id: preset-standard
|
- id: preset-standard
|
||||||
name: '@deepseek-ai/dsh-agent-preset'
|
name: '@deepseek-ai/dsh-agent-preset'
|
||||||
config:
|
config:
|
||||||
@@ -28,12 +36,13 @@
|
|||||||
- id: persona
|
- id: persona
|
||||||
name: '@deepseek-ai/dsh-persona'
|
name: '@deepseek-ai/dsh-persona'
|
||||||
config:
|
config:
|
||||||
suffix: Your working directory is {{cwd}}.
|
|
||||||
prefix: You are a coding agent powered by the {{model}} model.
|
prefix: You are a coding agent powered by the {{model}} model.
|
||||||
- id: agent-instructions
|
- id: agent-instructions
|
||||||
name: '@deepseek-ai/dsh-agent-instructions'
|
name: '@deepseek-ai/dsh-agent-instructions'
|
||||||
config:
|
config:
|
||||||
maxBytes: 65536
|
maxBytes: 65536
|
||||||
|
- id: time-context
|
||||||
|
name: '@deepseek-ai/dsh-time-context'
|
||||||
- id: tool-bash
|
- id: tool-bash
|
||||||
name: '@deepseek-ai/dsh-tool-bash'
|
name: '@deepseek-ai/dsh-tool-bash'
|
||||||
disabled: !!js process.platform === 'win32'
|
disabled: !!js process.platform === 'win32'
|
||||||
@@ -42,12 +51,17 @@
|
|||||||
disabled: !!js process.platform !== 'win32'
|
disabled: !!js process.platform !== 'win32'
|
||||||
- id: tool-fs
|
- id: tool-fs
|
||||||
name: '@deepseek-ai/dsh-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
|
- id: tool-fs-search
|
||||||
name: '@deepseek-ai/dsh-tool-fs-search'
|
name: '@deepseek-ai/dsh-tool-fs-search'
|
||||||
config:
|
config:
|
||||||
sampleOverCapGlobResults: false
|
sampleOverCapGlobResults: false
|
||||||
- id: tool-jobs
|
- id: tool-jobs
|
||||||
name: '@deepseek-ai/dsh-tool-jobs'
|
name: '@deepseek-ai/dsh-tool-jobs'
|
||||||
|
- id: tool-schedule
|
||||||
|
name: '@deepseek-ai/dsh-tool-schedule'
|
||||||
- id: skill-filesystem
|
- id: skill-filesystem
|
||||||
name: '@deepseek-ai/dsh-skill-filesystem'
|
name: '@deepseek-ai/dsh-skill-filesystem'
|
||||||
- id: tool-skill
|
- id: tool-skill
|
||||||
@@ -66,7 +80,7 @@
|
|||||||
name: '@deepseek-ai/dsh-plan-mode'
|
name: '@deepseek-ai/dsh-plan-mode'
|
||||||
config:
|
config:
|
||||||
section: |
|
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.
|
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.
|
||||||
|
|
||||||
@@ -107,49 +121,24 @@
|
|||||||
config:
|
config:
|
||||||
- id: tool-subagent-control
|
- id: tool-subagent-control
|
||||||
name: '@deepseek-ai/dsh-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
|
- id: tool-subagent
|
||||||
name: '@deepseek-ai/dsh-tool-subagent'
|
name: '@deepseek-ai/dsh-tool-subagent'
|
||||||
config:
|
config:
|
||||||
provider: spawn
|
provider: spawn
|
||||||
toolName: subagent
|
toolName: subagent
|
||||||
modelSelectionSettings: true
|
modelSelection: true
|
||||||
backgroundMode: continuable
|
modelDiscovery: true
|
||||||
- id: tool-subagent-fork
|
- id: tool-subagent-fork
|
||||||
name: '@deepseek-ai/dsh-tool-subagent'
|
name: '@deepseek-ai/dsh-tool-subagent'
|
||||||
config:
|
config:
|
||||||
provider: fork
|
provider: fork
|
||||||
toolName: subagent_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
|
- id: workflow-ptc
|
||||||
name: '@deepseek-ai/dsh-workflow-ptc'
|
name: '@deepseek-ai/dsh-workflow-ptc'
|
||||||
config:
|
config:
|
||||||
provider: spawn
|
provider: spawn
|
||||||
- id: tool-workflow
|
- id: tool-workflow
|
||||||
name: '@deepseek-ai/dsh-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
|
- id: tool-ask-user
|
||||||
name: '@deepseek-ai/dsh-tool-ask-user'
|
name: '@deepseek-ai/dsh-tool-ask-user'
|
||||||
- id: tool-todo
|
- id: tool-todo
|
||||||
@@ -165,4 +154,7 @@
|
|||||||
name: '@deepseek-ai/dsh-tool-present'
|
name: '@deepseek-ai/dsh-tool-present'
|
||||||
- id: tool-plugin-manager
|
- id: tool-plugin-manager
|
||||||
name: '@deepseek-ai/dsh-plugin-manager/tools'
|
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
|
disabled: true
|
||||||
+13
-21
@@ -5,10 +5,12 @@
|
|||||||
*
|
*
|
||||||
* ## Why this exists
|
* ## Why this exists
|
||||||
*
|
*
|
||||||
* The plugin imports `@deepseek-ai/dsh-tools` and `@deepseek-ai/schemastery`.
|
* The plugin imports `@deepseek-ai/dsh-tools` and `@deepseek-ai/schemastery`,
|
||||||
* Once installed into a profile those resolve from the profile's own
|
* and `test/presets.test.js` reads the shipped `standard` preset through
|
||||||
* `node_modules`, which is where the harness lives — but a bare checkout has no
|
* `js-yaml` to compare it with this bundle's frozen copies. Once installed into
|
||||||
* such tree, so the tests cannot even load the module under test.
|
* 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`
|
* 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
|
* 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 { dirname, join, resolve } from 'node:path'
|
||||||
import { fileURLToPath } from 'node:url'
|
import { fileURLToPath } from 'node:url'
|
||||||
|
|
||||||
|
import { findHarnessScope } from './harness-scope.mjs'
|
||||||
|
|
||||||
/** Packages this checkout imports at runtime, and which the harness must supply. */
|
/** 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 here = dirname(fileURLToPath(import.meta.url))
|
||||||
const packageRoot = resolve(here, '..')
|
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()
|
const scope = findHarnessScope()
|
||||||
if (scope === undefined) {
|
if (scope === undefined) {
|
||||||
console.error('dev-links: no dsh installation found. Set DSH_HARNESS_NODE_MODULES to its node_modules directory.')
|
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')
|
const target = join(packageRoot, 'node_modules')
|
||||||
mkdirSync(join(target, '@deepseek-ai'), { recursive: true })
|
mkdirSync(target, { recursive: true })
|
||||||
|
|
||||||
let linked = 0
|
let linked = 0
|
||||||
for (const name of NEEDED) {
|
for (const name of NEEDED) {
|
||||||
const source = join(scope, '@deepseek-ai', name)
|
const source = join(scope, name)
|
||||||
if (!existsSync(source)) {
|
if (!existsSync(source)) {
|
||||||
console.error(`dev-links: ${name} is not in ${scope}; skipping`)
|
console.error(`dev-links: ${name} is not in ${scope}; skipping`)
|
||||||
continue
|
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 })
|
if (existsSync(link)) rmSync(link, { recursive: true, force: true })
|
||||||
symlinkSync(source, link, 'dir')
|
symlinkSync(source, link, 'dir')
|
||||||
linked += 1
|
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]
|
||||||
|
}
|
||||||
+263
-17
@@ -35,9 +35,10 @@ async function loadClient() {
|
|||||||
SettingsForm: 'SettingsForm',
|
SettingsForm: 'SettingsForm',
|
||||||
SettingsValueField: 'SettingsValueField',
|
SettingsValueField: 'SettingsValueField',
|
||||||
SegmentedControl: 'SegmentedControl',
|
SegmentedControl: 'SegmentedControl',
|
||||||
// The listing's row glyph; a client half may only use what the primitives
|
// The listing's row glyphs; a client half may only use what the primitives
|
||||||
// actually export, so the stand-in is named the same way.
|
// actually export, so the stand-ins are named the same way.
|
||||||
IconFolderCloseRegular: 'IconFolderCloseRegular',
|
IconFolderCloseRegular: 'IconFolderCloseRegular',
|
||||||
|
FileTypeIcon: 'FileTypeIcon',
|
||||||
/** Stands in for the real model: records the specs and answers with the value. */
|
/** Stands in for the real model: records the specs and answers with the value. */
|
||||||
SettingsFormModel: class {
|
SettingsFormModel: class {
|
||||||
constructor(scope, specs) {
|
constructor(scope, specs) {
|
||||||
@@ -558,19 +559,46 @@ test('the browse face is read from uiWorkspace at the call, not at registration'
|
|||||||
const missing = mod.directoryBrowse({ get: () => undefined })
|
const missing = mod.directoryBrowse({ get: () => undefined })
|
||||||
assert.equal(missing.available(), false)
|
assert.equal(missing.available(), false)
|
||||||
await assert.rejects(missing.list('/tmp'), /no directory browser/)
|
await assert.rejects(missing.list('/tmp'), /no directory browser/)
|
||||||
|
// The file lister is a second service and probes separately: a deployment can
|
||||||
|
// have the folder browser without the workspace file service.
|
||||||
|
assert.equal(missing.files.available(), false)
|
||||||
|
await assert.rejects(missing.files.list('session-1', '/tmp'), /cannot list files/)
|
||||||
|
|
||||||
const calls = []
|
const calls = []
|
||||||
const present = mod.directoryBrowse({
|
const present = mod.directoryBrowse({
|
||||||
get: () => ({
|
get: (name) =>
|
||||||
|
({
|
||||||
|
uiWorkspace: {
|
||||||
listDirectory: (path, signal) => {
|
listDirectory: (path, signal) => {
|
||||||
calls.push([path, signal])
|
calls.push(['folders', path, signal])
|
||||||
return Promise.resolve('listing')
|
return Promise.resolve('listing')
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
|
'remote.workspaceFiles': {
|
||||||
|
list: (sessionId, path, signal) => {
|
||||||
|
calls.push(['files', sessionId, path, signal])
|
||||||
|
return Promise.resolve({ ok: true, value: 'workspace listing' })
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})[name],
|
||||||
})
|
})
|
||||||
assert.equal(present.available(), true)
|
assert.equal(present.available(), true)
|
||||||
assert.equal(await present.list('/tmp', 'signal'), 'listing')
|
assert.equal(await present.list('/tmp', 'signal'), 'listing')
|
||||||
assert.deepEqual(calls, [['/tmp', 'signal']])
|
assert.deepEqual(calls, [['folders', '/tmp', 'signal']])
|
||||||
|
|
||||||
|
// The remote answers with a result envelope rather than rejecting, so its
|
||||||
|
// failure branch is turned into one here — the model's catch expects a throw.
|
||||||
|
assert.equal(present.files.available(), true)
|
||||||
|
assert.equal(await present.files.list('session-1', '/work/root', 'signal'), 'workspace listing')
|
||||||
|
assert.deepEqual(calls[1], ['files', 'session-1', '/work/root', 'signal'])
|
||||||
|
|
||||||
|
const refusing = mod.directoryBrowse({
|
||||||
|
get: (name) =>
|
||||||
|
name === 'remote.workspaceFiles'
|
||||||
|
? { list: () => Promise.resolve({ ok: false, error: new Error('workspace files are unavailable') }) }
|
||||||
|
: undefined,
|
||||||
|
})
|
||||||
|
await assert.rejects(refusing.files.list('session-1', '/work/root'), /workspace files are unavailable/)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('the picker model lists a level, supersedes a stale one, and keeps a typed path on failure', async () => {
|
test('the picker model lists a level, supersedes a stale one, and keeps a typed path on failure', async () => {
|
||||||
@@ -578,7 +606,7 @@ test('the picker model lists a level, supersedes a stale one, and keeps a typed
|
|||||||
|
|
||||||
const asked = []
|
const asked = []
|
||||||
const model = new mod.DirectoryPickerModel({
|
const model = new mod.DirectoryPickerModel({
|
||||||
list: (path) => {
|
folders: (path) => {
|
||||||
asked.push(path)
|
asked.push(path)
|
||||||
return Promise.resolve(listingFixture())
|
return Promise.resolve(listingFixture())
|
||||||
},
|
},
|
||||||
@@ -588,7 +616,7 @@ test('the picker model lists a level, supersedes a stale one, and keeps a typed
|
|||||||
await settle()
|
await settle()
|
||||||
|
|
||||||
assert.deepEqual(asked, ['/work/root/src'], 'the opening level is listed, not guessed at')
|
assert.deepEqual(asked, ['/work/root/src'], 'the opening level is listed, not guessed at')
|
||||||
assert.equal(model.getSnapshot().listing.path, '/work/root/src')
|
assert.equal(model.getSnapshot().listing.base, '/work/root/src')
|
||||||
assert.equal(model.getSnapshot().draft, '/work/root/src', 'the field follows a successful listing')
|
assert.equal(model.getSnapshot().draft, '/work/root/src', 'the field follows a successful listing')
|
||||||
assert.equal(model.getSnapshot().loading, false)
|
assert.equal(model.getSnapshot().loading, false)
|
||||||
|
|
||||||
@@ -597,10 +625,11 @@ test('the picker model lists a level, supersedes a stale one, and keeps a typed
|
|||||||
model.open('/work/root/other')
|
model.open('/work/root/other')
|
||||||
model.setDraft('notes/CONTROLLER.md')
|
model.setDraft('notes/CONTROLLER.md')
|
||||||
|
|
||||||
// A failure keeps the level on screen and the path as typed: the Host lists
|
// A failure keeps the level on screen and the path as typed: a listing can
|
||||||
// folders, and the extras legitimately name a file.
|
// fail on a path this panel may still legitimately declare.
|
||||||
const failing = new mod.DirectoryPickerModel({
|
const failing = new mod.DirectoryPickerModel({
|
||||||
list: () => Promise.reject(Object.assign(new Error('transport'), { rpcError: { message: 'directory-unreadable' } })),
|
folders: () =>
|
||||||
|
Promise.reject(Object.assign(new Error('transport'), { rpcError: { message: 'directory-unreadable' } })),
|
||||||
root: '/work/root',
|
root: '/work/root',
|
||||||
start: 'notes/CONTROLLER.md',
|
start: 'notes/CONTROLLER.md',
|
||||||
})
|
})
|
||||||
@@ -613,7 +642,7 @@ test('the picker lists folders, hides hidden ones until asked, and answers in de
|
|||||||
const { module: mod } = await loadClient()
|
const { module: mod } = await loadClient()
|
||||||
|
|
||||||
const model = new mod.DirectoryPickerModel({
|
const model = new mod.DirectoryPickerModel({
|
||||||
list: () => Promise.resolve(listingFixture()),
|
folders: () => Promise.resolve(listingFixture()),
|
||||||
root: '/work/root',
|
root: '/work/root',
|
||||||
start: '/work/root/src',
|
start: '/work/root/src',
|
||||||
})
|
})
|
||||||
@@ -668,7 +697,7 @@ test('the extras picker names what it accepts and says what the list holds', asy
|
|||||||
const { module: mod } = await loadClient()
|
const { module: mod } = await loadClient()
|
||||||
|
|
||||||
const model = new mod.DirectoryPickerModel({
|
const model = new mod.DirectoryPickerModel({
|
||||||
list: () => Promise.resolve(listingFixture()),
|
folders: () => Promise.resolve(listingFixture()),
|
||||||
root: '/work/root',
|
root: '/work/root',
|
||||||
start: '/work/root/src',
|
start: '/work/root/src',
|
||||||
})
|
})
|
||||||
@@ -683,14 +712,14 @@ test('the extras picker names what it accepts and says what the list holds', asy
|
|||||||
onPick: () => {},
|
onPick: () => {},
|
||||||
})
|
})
|
||||||
|
|
||||||
// "folder or path" promised one thing and offered another: the rows are
|
// "folder or path" promised one thing and offered another. The rows now carry
|
||||||
// folders, and a file is added by naming it. The copy says both.
|
// files, and the copy says what a row of each kind does.
|
||||||
assert.equal(tree.props.title, 'Add a path or a file')
|
assert.equal(tree.props.title, 'Add a path or a file')
|
||||||
const texts = textsOf(tree)
|
const texts = textsOf(tree)
|
||||||
assert.ok(texts.includes('Path or file'), 'the field is named for what it accepts')
|
assert.ok(texts.includes('Path or file'), 'the field is named for what it accepts')
|
||||||
assert.ok(
|
assert.ok(
|
||||||
texts.some((text) => text.includes('The list holds folders')),
|
texts.some((text) => text.includes('Folders open; a file is taken')),
|
||||||
'the copy explains why no file rows are shown',
|
'the copy explains what a file row does',
|
||||||
)
|
)
|
||||||
assert.ok(
|
assert.ok(
|
||||||
buttonsOf(tree).some((button) => (button.children ?? [])[0] === 'Add'),
|
buttonsOf(tree).some((button) => (button.children ?? [])[0] === 'Add'),
|
||||||
@@ -698,3 +727,220 @@ test('the extras picker names what it accepts and says what the list holds', asy
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// ── files in the extras picker ───────────────────────────────────────────────
|
||||||
|
//
|
||||||
|
// Two Host listers, one of which carries files. The folder primitive browses
|
||||||
|
// anywhere and returns folders; the workspace file listing returns files and
|
||||||
|
// folders but confines itself to the session's workspace. The extras picker
|
||||||
|
// takes the file listing wherever the Host allows it, and the folder listing
|
||||||
|
// everywhere else, so a path above the session folder is still reachable.
|
||||||
|
|
||||||
|
/** A level shaped the way `remote.workspaceFiles.list` answers. */
|
||||||
|
function workspaceFixture() {
|
||||||
|
return {
|
||||||
|
path: 'src',
|
||||||
|
entries: [
|
||||||
|
{ name: 'shared', type: 'directory' },
|
||||||
|
{ name: '.git', type: 'directory' },
|
||||||
|
{ name: 'index.ts', type: 'file', size: 120 },
|
||||||
|
{ name: 'CONTROLLER.md', type: 'file', size: 900 },
|
||||||
|
{ name: 'socket', type: 'other' },
|
||||||
|
],
|
||||||
|
truncated: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test('the model takes the file listing inside the workspace and the folder listing above it', async () => {
|
||||||
|
const { module: mod } = await loadClient()
|
||||||
|
|
||||||
|
const asked = []
|
||||||
|
const model = new mod.DirectoryPickerModel({
|
||||||
|
folders: (path) => {
|
||||||
|
asked.push(['folders', path])
|
||||||
|
return Promise.resolve(listingFixture())
|
||||||
|
},
|
||||||
|
files: (sessionId, path) => {
|
||||||
|
asked.push(['files', sessionId, path])
|
||||||
|
return Promise.resolve(workspaceFixture())
|
||||||
|
},
|
||||||
|
sessionId: 'session-1',
|
||||||
|
root: '/work/root',
|
||||||
|
start: '/work/root/src',
|
||||||
|
})
|
||||||
|
await settle()
|
||||||
|
|
||||||
|
// Inside the workspace: the file listing, normalised into the picker's own
|
||||||
|
// shape, with the workspace-relative paths joined onto the session folder.
|
||||||
|
assert.deepEqual(asked, [['files', 'session-1', '/work/root/src']])
|
||||||
|
const level = model.getSnapshot().listing
|
||||||
|
assert.equal(level.base, '/work/root/src')
|
||||||
|
assert.equal(level.files, true, 'this level could carry file rows')
|
||||||
|
assert.deepEqual(
|
||||||
|
level.entries.map((entry) => [entry.name, entry.path, entry.directory, entry.hidden]),
|
||||||
|
[
|
||||||
|
['shared', '/work/root/src/shared', true, false],
|
||||||
|
['.git', '/work/root/src/.git', true, true],
|
||||||
|
['index.ts', '/work/root/src/index.ts', false, false],
|
||||||
|
['CONTROLLER.md', '/work/root/src/CONTROLLER.md', false, false],
|
||||||
|
['socket', '/work/root/src/socket', false, false],
|
||||||
|
],
|
||||||
|
)
|
||||||
|
// The trail is the workspace's own, root first: the file listing stops at the
|
||||||
|
// session folder, so there is nothing above it to offer.
|
||||||
|
assert.deepEqual(
|
||||||
|
level.crumbs.map((crumb) => crumb.path),
|
||||||
|
['/work/root', '/work/root/src'],
|
||||||
|
)
|
||||||
|
|
||||||
|
// Above the workspace root: the Host confines the file listing to the
|
||||||
|
// workspace, so the level falls back to folders — which browse anywhere.
|
||||||
|
model.open('/work')
|
||||||
|
await settle()
|
||||||
|
assert.deepEqual(asked[1], ['folders', '/work'])
|
||||||
|
assert.equal(model.getSnapshot().listing.files, false)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('a file listing that fails still leaves a browsable level', async () => {
|
||||||
|
const { module: mod } = await loadClient()
|
||||||
|
|
||||||
|
// The comparison the model makes is a prefix test on a path the Host may
|
||||||
|
// resolve differently — a symlinked session folder, say — so a refusal from
|
||||||
|
// the file listing is answered rather than shown: the folder listing runs.
|
||||||
|
const model = new mod.DirectoryPickerModel({
|
||||||
|
folders: () => Promise.resolve(listingFixture()),
|
||||||
|
files: () => Promise.reject(new Error('outside the workspace')),
|
||||||
|
sessionId: 'session-1',
|
||||||
|
root: '/work/root',
|
||||||
|
start: '/work/root/src',
|
||||||
|
})
|
||||||
|
await settle()
|
||||||
|
|
||||||
|
assert.equal(model.getSnapshot().error, '')
|
||||||
|
assert.equal(model.getSnapshot().listing.files, false)
|
||||||
|
assert.equal(model.getSnapshot().listing.base, '/work/root/src')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('a file row is taken as the path to add rather than walked into', async () => {
|
||||||
|
const { module: mod } = await loadClient()
|
||||||
|
|
||||||
|
// Both listers refuse a path that names a file, which is what the Host does:
|
||||||
|
// the file listing because a file has no children, the folder listing because
|
||||||
|
// the same. Only a level can be listed.
|
||||||
|
const isFile = (path) => /\.(md|ts)$/.test(String(path))
|
||||||
|
const refuseFile = (path, answer) =>
|
||||||
|
isFile(path) ? Promise.reject(new Error('not a directory')) : Promise.resolve(answer)
|
||||||
|
|
||||||
|
const model = new mod.DirectoryPickerModel({
|
||||||
|
folders: (path) => refuseFile(path, listingFixture()),
|
||||||
|
files: (sessionId, path) => refuseFile(path, workspaceFixture()),
|
||||||
|
sessionId: 'session-1',
|
||||||
|
root: '/work/root',
|
||||||
|
start: '/work/root/src',
|
||||||
|
})
|
||||||
|
await settle()
|
||||||
|
|
||||||
|
const picked = []
|
||||||
|
const render = () =>
|
||||||
|
mod.DirectoryPicker({
|
||||||
|
model,
|
||||||
|
root: '/work/root',
|
||||||
|
target: 'extra',
|
||||||
|
disabled: false,
|
||||||
|
onClose: () => {},
|
||||||
|
onPick: (path) => picked.push(path),
|
||||||
|
})
|
||||||
|
|
||||||
|
const rowAt = (tree, path) =>
|
||||||
|
buttonsOf(tree)
|
||||||
|
.filter((button) => button.props.className === mod.ROW_CLASS)
|
||||||
|
.find((button) => button.props.title === path)
|
||||||
|
|
||||||
|
const fileRow = rowAt(render(), '/work/root/src/CONTROLLER.md')
|
||||||
|
assert.notEqual(fileRow, undefined, 'the file is a row in the listing')
|
||||||
|
assert.equal(fileRow.props.style.background, 'transparent', 'an unpicked file row is not marked')
|
||||||
|
// A folder row carries the folder glyph and a file row the file-type one, which
|
||||||
|
// is the only thing telling the two apart before the click.
|
||||||
|
const glyphOf = (row) => (row.children ?? [])[0].children?.[0]?.type
|
||||||
|
assert.equal(glyphOf(fileRow), 'FileTypeIcon')
|
||||||
|
assert.equal(glyphOf(rowAt(render(), '/work/root/src/shared')), 'IconFolderCloseRegular')
|
||||||
|
|
||||||
|
// Clicking it fills the field instead of listing it, and marks the row: a file
|
||||||
|
// is taken, not entered.
|
||||||
|
fileRow.props.onClick()
|
||||||
|
assert.equal(model.getSnapshot().draft, '/work/root/src/CONTROLLER.md')
|
||||||
|
assert.notEqual(rowAt(render(), '/work/root/src/CONTROLLER.md').props.style.background, 'transparent')
|
||||||
|
|
||||||
|
// Enter on a file the level lists asks for a listing of a file, which is not a
|
||||||
|
// failure: the level stays and nothing is reported.
|
||||||
|
model.open(model.getSnapshot().draft)
|
||||||
|
await settle()
|
||||||
|
assert.equal(model.getSnapshot().error, '')
|
||||||
|
assert.equal(model.getSnapshot().listing.base, '/work/root/src', 'the level survives it')
|
||||||
|
|
||||||
|
// The footer then adds exactly that, in the declared form.
|
||||||
|
const addButton = render().props.footer.find((entry) => (entry.children ?? [])[0] === 'Add')
|
||||||
|
addButton.props.onClick()
|
||||||
|
assert.deepEqual(picked, ['src/CONTROLLER.md'])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('files are offered to the extras control only, and only where the Host has them', async () => {
|
||||||
|
const { module: mod } = await loadClient()
|
||||||
|
|
||||||
|
const browse = mod.directoryBrowse({
|
||||||
|
get: (name) => (name === 'remote.workspaceFiles' ? { list: () => {} } : undefined),
|
||||||
|
})
|
||||||
|
assert.equal(mod.fileLister(browse, 'extra'), browse.files.list, 'an extra can name a file')
|
||||||
|
// A focus is a folder, and file rows there would only offer something that
|
||||||
|
// cannot be chosen.
|
||||||
|
assert.equal(mod.fileLister(browse, 'focus'), undefined)
|
||||||
|
// No file service, or no browse face at all: the folder listing stands.
|
||||||
|
assert.equal(mod.fileLister(mod.directoryBrowse({ get: () => undefined }), 'extra'), undefined)
|
||||||
|
assert.equal(mod.fileLister({}, 'extra'), undefined)
|
||||||
|
assert.equal(mod.fileLister(undefined, 'extra'), undefined)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('the picker says so when a level is folders only, and not when it is not', async () => { const { module: mod } = await loadClient()
|
||||||
|
|
||||||
|
const model = new mod.DirectoryPickerModel({
|
||||||
|
folders: () => 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: () => {},
|
||||||
|
})
|
||||||
|
assert.ok(
|
||||||
|
textsOf(tree).some((text) => text.includes('Files are listed inside the session folder only')),
|
||||||
|
'a folders-only level explains itself',
|
||||||
|
)
|
||||||
|
|
||||||
|
// A level that does carry files needs no note about it.
|
||||||
|
const withFiles = new mod.DirectoryPickerModel({
|
||||||
|
folders: () => Promise.resolve(listingFixture()),
|
||||||
|
files: () => Promise.resolve(workspaceFixture()),
|
||||||
|
sessionId: 'session-1',
|
||||||
|
root: '/work/root',
|
||||||
|
start: '/work/root/src',
|
||||||
|
})
|
||||||
|
await settle()
|
||||||
|
assert.equal(
|
||||||
|
textsOf(
|
||||||
|
mod.DirectoryPicker({
|
||||||
|
model: withFiles,
|
||||||
|
root: '/work/root',
|
||||||
|
target: 'extra',
|
||||||
|
disabled: false,
|
||||||
|
onClose: () => {},
|
||||||
|
onPick: () => {},
|
||||||
|
}),
|
||||||
|
).some((text) => text.includes('Files are listed inside the session folder only')),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
})
|
||||||
+109
-3
@@ -66,14 +66,25 @@ const fsLikeLocal = {
|
|||||||
* deployment that composed no approval service at all — a case the tool pipeline
|
* deployment that composed no approval service at all — a case the tool pipeline
|
||||||
* denies outright, so the guard must treat it as no channel.
|
* 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 policy = createFacetPolicy(config ?? { mode, extraRoots })
|
||||||
const captured = { section: undefined, context: undefined, tool: undefined, preExecute: undefined }
|
const captured = { section: undefined, context: undefined, tool: undefined, preExecute: undefined }
|
||||||
const ctx = {
|
const ctx = {
|
||||||
facetPolicy: policy,
|
facetPolicy: policy,
|
||||||
fs: fsLikeLocal,
|
fs: fsLikeLocal,
|
||||||
get: (name) =>
|
get: (name) => {
|
||||||
name === 'approval' && approval !== undefined ? { effectivePolicy: () => approval } : undefined,
|
if (name === 'approval' && approval !== undefined) return { effectivePolicy: () => approval }
|
||||||
|
if (name === 'workingDirectory' && workingDirectory !== undefined) return workingDirectory
|
||||||
|
return undefined
|
||||||
|
},
|
||||||
systemPrompt: {
|
systemPrompt: {
|
||||||
section: (value) => {
|
section: (value) => {
|
||||||
captured.section = value
|
captured.section = value
|
||||||
@@ -86,6 +97,13 @@ function harness({ mode = 'ask', extraRoots = [], tool = true, config, approval
|
|||||||
register: (value) => {
|
register: (value) => {
|
||||||
captured.tool = 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) => {
|
on: (event, listener) => {
|
||||||
if (event === 'tools/pre-execute') captured.preExecute = 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' })
|
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 ───────────────────────────────────────────────────────
|
// ── delegated sessions ───────────────────────────────────────────────────────
|
||||||
//
|
//
|
||||||
// A session spawned or forked from a scoped one has no declaration of its own,
|
// 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')
|
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', () => {
|
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: '.' } } })
|
const policy = createFacetPolicy({ mode: 'deny', scopes: { s1: { focus: 'src/room' }, c1: { focus: '.' } } })
|
||||||
policy.scopeFor(agentAt('/w', 's1'))
|
policy.scopeFor(agentAt('/w', 's1'))
|
||||||
|
|||||||
@@ -0,0 +1,260 @@
|
|||||||
|
import assert from 'node:assert/strict'
|
||||||
|
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, 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')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The prompt variables the harness registers for a section.
|
||||||
|
*
|
||||||
|
* `dsh-agent-loop` puts each of these into the prompt registry, and an assembly
|
||||||
|
* substitutes only what is registered. An unknown reference is not rendered as
|
||||||
|
* text — interpolation throws, and the throw takes the entire turn with it, so
|
||||||
|
* the user sees "This turn failed" and nothing else. A harness release that
|
||||||
|
* stopped registering `cwd` is exactly how this bundle's preset stopped
|
||||||
|
* composing sessions: the persona suffix it copied from the deployment said
|
||||||
|
* "Your working directory is …" with that variable in it.
|
||||||
|
*/
|
||||||
|
const REGISTERED = ['provider', 'model']
|
||||||
|
|
||||||
|
/** Every `{{name}}` reference in one text, as the name alone. */
|
||||||
|
function referencesIn(text) {
|
||||||
|
return [...text.matchAll(/\{\{([^{}]*)\}\}/g)].map((match) => match[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
test('no preset references a prompt variable the harness does not register', () => {
|
||||||
|
const files = readdirSync(PRESETS).filter((name) => name.endsWith('.yml'))
|
||||||
|
assert.ok(files.length > 0, 'the bundle ships at least one preset')
|
||||||
|
|
||||||
|
const found = []
|
||||||
|
for (const file of files) {
|
||||||
|
for (const name of referencesIn(readFileSync(join(PRESETS, file), 'utf8'))) found.push([file, name])
|
||||||
|
}
|
||||||
|
|
||||||
|
// The model reference is the one that has to keep working, so the guard cannot
|
||||||
|
// be satisfied by a preset that references nothing at all.
|
||||||
|
assert.ok(
|
||||||
|
found.some(([, name]) => name === 'model'),
|
||||||
|
'a preset still names the model',
|
||||||
|
)
|
||||||
|
for (const [file, name] of found) {
|
||||||
|
assert.ok(
|
||||||
|
REGISTERED.includes(name),
|
||||||
|
`${file} references {{${name}}}; the harness registers only ${REGISTERED.join(', ')}, and an unregistered reference fails the whole turn`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
test('the text this bundle contributes to the prompt holds no variable references', () => {
|
||||||
|
// The rule and the binding are rebuilt from real values on every request, so a
|
||||||
|
// placeholder in either would be a reference the harness never resolves — the
|
||||||
|
// same failure, this time from the bundle's own hand.
|
||||||
|
const rule = facetRuleText()
|
||||||
|
const binding = facetContextText({ cwd: '/w', root: '/w/src', extras: ['/w/shared'], mode: 'ask' })
|
||||||
|
assert.ok(rule.length > 0 && binding.length > 0, 'both halves contribute text')
|
||||||
|
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' } }), [])
|
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', () => {
|
test('isWideningCall is true only for the one act that needs the user', () => {
|
||||||
assert.equal(isWideningCall('facet', { action: 'add', paths: ['x'] }), true)
|
assert.equal(isWideningCall('facet', { action: 'add', paths: ['x'] }), true)
|
||||||
// Narrowing and reading cannot show the agent anything new.
|
// Narrowing and reading cannot show the agent anything new.
|
||||||
@@ -74,6 +99,7 @@ test('facetContextText carries the binding that does change', () => {
|
|||||||
assert.equal(
|
assert.equal(
|
||||||
ask,
|
ask,
|
||||||
'facet: /w/src/room\n' +
|
'facet: /w/src/room\n' +
|
||||||
|
'session folder: /w — relative paths in tool calls resolve here\n' +
|
||||||
'outside the facet: put to the user as a question — say in one line what you need and why, then record it with `facet action=add` so the rest of the session does not have to ask again',
|
'outside the facet: put to the user as a question — say in one line what you need and why, then record it with `facet action=add` so the rest of the session does not have to ask again',
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -81,6 +107,7 @@ test('facetContextText carries the binding that does change', () => {
|
|||||||
assert.equal(
|
assert.equal(
|
||||||
deny,
|
deny,
|
||||||
'facet: /w/src/room\n' +
|
'facet: /w/src/room\n' +
|
||||||
|
'session folder: /w — relative paths in tool calls resolve here\n' +
|
||||||
'granted outside it: src/shared\n' +
|
'granted outside it: src/shared\n' +
|
||||||
'outside the facet: refused — ask the user to widen the facet from its context panel, or with `facet action=add` where that can be granted',
|
'outside the facet: refused — ask the user to widen the facet from its context panel, or with `facet action=add` where that can be granted',
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in new issue
Block a user