feat(setup): register DeepSeek Harness through setup, doctor and uninstall (#1929)

* feat(setup): register DeepSeek Harness through setup, doctor and uninstall

DeepSeek Harness registers MCP clients through a Cordis YAML patch
sequence in the home patch rather than a server table, so setup could
not configure it and users had to append the documented entry by hand.

Add a dsh client: the home patch $DSH_HOME/cordis.patch.yml
(~/.dsh/cordis.patch.yml when unset) is parsed as a patch list, the REA
entry owns the stable rea-mcp id, and setup appends or replaces exactly
that entry while preserving unrelated patches and comments in place.
Doctor reports the registration through the same entry, and uninstall
removes it, dropping insert operations it emptied. Skill destinations
follow ~/.agents/skills ($DSH_AGENTS_HOME/skills when configured), the
home the rest of the client machinery already uses.

Fixes #1839

* fix(setup): carry environment and identity validation into DSH registrations

Address review: the DSH entry discarded discovered provider overrides;
config.env is now emitted and retained like the other dialects. An entry
carrying the rea-mcp id under a wrong or missing package name, or
duplicated entries, reads back as absent so setup rewrites exactly one
canonical entry instead of reporting unchanged. Doctor now requires
serverName rea and stdio transport before calling a DSH registration
aligned, and the Harness skill identifier in the docs matches the
installed reverse-engineer-anything skill.

* fix(setup): apply Cordis patch order and collapse DSH registrations

Address review: a later direct { id, config } operation replaces the
row's config under the native patch DSL, so the registration view now
applies patches in order instead of only reading insert operations;
doctor reports the effective command rather than the inserted one.
Setup rewrites exactly one canonical entry: duplicate id-matching rows
collapse to the first, direct patches to the entry are dropped from the
document and from the edited YAML, and uninstall removes them with the
entry. The client-location test fixture now clears DSH_HOME and
DSH_AGENTS_HOME so a developer environment cannot point the suite at
real Harness homes.

* fix(setup): repair direct-only registrations and preserve Cordis entry state

Serialize now edits the first insertion carrying rea-mcp in place, so a
grouped entry keeps its scope, neighbors, and comments instead of moving
to a fresh root-level insertion, and later carrying insertions and direct
patches collapse away. Entry-level disabled state projects into the
registration the doctor and setup compare, so a disabled row reads as
stale and the repair re-enables it. A direct-only registration no longer
suppresses the canonical insert append, and an update retains the
registration environment. Duplicate entries collapse across operations,
not only within one.

* fix(setup): preserve Harness row state through identity and refresh repairs

A wrong-package row still reads back as a server record carrying its
environment and caller fields, projected with a package marker the
alignment path treats as stale, instead of vanishing and dropping
config.env from the repair. A direct Cordis patch without a preceding
insertion configures nothing, so a direct-only registration reads as
absent even when its config matches and the repair appends the insert.
Caller-owned config fields beyond the REA-owned keys, such as the cwd
the native verifier sets, survive a refresh instead of being silently
dropped.

* fix(setup): preserve Cordis tags and collapse aligned Harness rows

A refresh rebuilt Harness config from parsed values, so a caller !!js
expression was written back as a literal. Owned keys are now overlaid on
the winning config node and other nodes stay in place. Two already-aligned
rea-mcp insertions read as stale, so setup collapses them to one row, and
the bundled skill lists dsh with the other clients.

* fix(setup): drop the unused DSH configuration type

Knip reports DshConfigurationFormat as an unused export. The format union
does not depend on that alias.

* fix(setup): keep Harness env tags and comment-only patches

A refresh replaced the whole env map, so a caller !!js value was written
back as a literal. Environment entries now stay in place unless the value
changed. A comment-only cordis.patch.yml parses as an empty patch list and
keeps those comments when the registration is appended. Docs describe
plain rea uninstall, which scans supported clients and has no --client flag.

* fix(setup): own Harness rows by entry id and expression state

Uninstall removes a rea-mcp row even when the launcher is stale or the
patch never established a server record. A non-boolean disabled value,
including a Cordis expression, reads as stale. Expression text on a known
environment setting is not validated as a literal path, so a refresh can
keep the tag.

* fix(setup): collapse aliased Harness insertions

An anchored insert followed by an alias parses as two rea-mcp rows, but
the YAML edit kept the alias, so readback stayed duplicated and setup
restored the file. Aliases that resolve to the owned entry are now
dropped, including an alias of the entry inside one insert. Aliases of
other patches stay.

* fix(setup): resolve aliased Harness lists and config maps

An insert value that aliases another entry list still loaded a second
rea-mcp row after the operation-level alias collapse. That alias is now
dropped once the anchored list is rewritten. A config: *cfg map is
resolved and cloned before the refresh, so a caller !!js field on the
aliased map is not rewritten as a plain literal.

* fix(setup): follow Harness aliases for ids, lists, and env tags

An insert alias whose anchor is not another insert is copied so
unrelated rows stay while the owned row is rewritten. An aliased
entry id is resolved before ownership checks, and an environment alias
of an unchanged !!js scalar is left in place.

* fix(setup): keep aliased Harness env maps through uninstall

An env alias is cloned before a refresh so tagged values are not rebuilt
as literals, and expression-key scans follow aliases before path checks.
Insert aliases that carry REA are recorded before uninstall empties their
anchor, so the later alias is dropped instead of dangling.

* fix(setup): follow root Harness aliases and mark dsh as main-only

Winning-config walks resolve a root alias before patch order, so a replayed direct config's !!js env is not validated as a literal path. Root aliases that own rea-mcp are recorded before uninstall empties their anchor. An insert whose only owned member is an external alias is cloned so Cordis tags survive. Docs state dsh is not in npm 6.4.0.

* fix(setup): keep rows behind inert Harness aliases

A root alias whose anchor is not a loaded operation is copied and only the owned row is edited, so unrelated rows stay active. Entry id aliases become a scalar before their anchor patch is dropped. Root-alias ownership follows insert-list aliases, so a replay is removed instead of dangling after uninstall.

* refactor(setup): centralize Cordis source ownership

* fix(javascript): share Electron mutation proof with wrapped calls

* test(mcp): align graph and catalog checks with current contracts

* fix(setup): separate Cordis ownership from editability

* docs: clarify ownership and interpretation boundaries

* fix(setup): preserve Cordis applicability and caller metadata

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
BaaRai 2026-10-12 05:06:26 +02:00 committed by GitHub
parent 04089d5bec
commit d9d2a17381
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 3065 additions and 52 deletions

View File

@ -46,7 +46,7 @@ rea setup --client codex --dry-run --json
Use the current supported client's ID: `claude_code`, `claude_desktop`, `codex`, Use the current supported client's ID: `claude_code`, `claude_desktop`, `codex`,
`cursor`, `gemini_cli`, `windsurf`, `devin`, `opencode`, `antigravity`, `cursor`, `gemini_cli`, `windsurf`, `devin`, `opencode`, `antigravity`,
`copilot_cli`, `commandcode`, `qwen_code`, `vscode`, `grok_build`, `omp`, `pi`, `copilot_cli`, `commandcode`, `qwen_code`, `vscode`, `grok_build`, `omp`, `pi`,
`hermes`, or `grok_bot`. If unknown, inspect `doctor --json` before choosing a `hermes`, `dsh`, or `grok_bot`. If unknown, inspect `doctor --json` before choosing a
scope. `grok_bot` uses a chat registration step rather than local `mcp.json`. scope. `grok_bot` uses a chat registration step rather than local `mcp.json`.
For unsupported clients, use version-pinned manual stdio registration or CLI. For unsupported clients, use version-pinned manual stdio registration or CLI.

View File

@ -89,8 +89,11 @@ running server or its registration.
The npm release checked on **2026-10-11** was **6.4.0**, published from The npm release checked on **2026-10-11** was **6.4.0**, published from
[`a56f7bb6`](https://github.com/morluto/rea/commit/a56f7bb668ab23fec8d33f7af353ac7ed2fe1895). [`a56f7bb6`](https://github.com/morluto/rea/commit/a56f7bb668ab23fec8d33f7af353ac7ed2fe1895).
The actual registry package accepted dry-run setup plans for all 17 client IDs The actual registry package accepted dry-run setup plans for the 17 client IDs
listed below, including Qwen Code, Pi and Hermes. OpenCode's plan selected in that release, including Qwen Code, Pi and Hermes. DeepSeek Harness (`dsh`)
is on main and is not in npm 6.4.0; `rea setup --client dsh` against `@latest`
reports an unsupported client until a release containing it is published.
OpenCode's plan selected
`OPENCODE_CONFIG_DIR` even when that directory did not yet exist. These checks `OPENCODE_CONFIG_DIR` even when that directory did not yet exist. These checks
used an isolated home on macOS with Node 24; they verify planning and argument used an isolated home on macOS with Node 24; they verify planning and argument
admission, without writing client configuration or establishing live integration admission, without writing client configuration or establishing live integration
@ -162,6 +165,10 @@ listed after the table because its connector is not one of these files:
| OMP | `omp` | | OMP | `omp` |
| Pi | `pi` | | Pi | `pi` |
| Hermes | `hermes` | | Hermes | `hermes` |
| DeepSeek Harness | `dsh` |
`dsh` is main-only until a release after 6.4.0. The registry check above does
not cover it.
For GitHub Copilot CLI 1.0.95, `gpt-4.1` model metadata can block ordinary For GitHub Copilot CLI 1.0.95, `gpt-4.1` model metadata can block ordinary
chat with REA's full input-schema profile before sending a model request chat with REA's full input-schema profile before sending a model request
@ -259,11 +266,15 @@ configuration and skill destinations; doctor and uninstall use those same paths.
### DeepSeek Harness ### DeepSeek Harness
DeepSeek Harness uses a Cordis YAML patch sequence rather than a `mcpServers` DeepSeek Harness registers MCP clients through a Cordis YAML patch sequence
object. REA's `setup --client` does not edit this format. For Harness rather than a `mcpServers` object. `rea setup --client dsh` appends (or
`0.2.0-rc.2`, append the following entry to `$DSH_HOME/cordis.patch.yml` replaces) the REA entry in the home patch `$DSH_HOME/cordis.patch.yml`
(`~/.dsh/cordis.patch.yml` when `DSH_HOME` is unset). Preserve existing patches (`~/.dsh/cordis.patch.yml` when `DSH_HOME` is unset), preserving unrelated
and replace the executable paths with absolute paths from your installation: patches and comments. `rea doctor --client dsh` checks that same entry id.
`rea uninstall` removes it by scanning supported clients; uninstall takes no
`--client` flag. The home patch applies to every Harness profile, so the
registration is written once and no per-profile edit is needed. The written
entry is:
```yaml ```yaml
- insert: - insert:
@ -274,17 +285,20 @@ and replace the executable paths with absolute paths from your installation:
transport: stdio transport: stdio
command: /absolute/path/to/node command: /absolute/path/to/node
args: ["/absolute/path/to/rea/scripts/rea.mjs", mcp] args: ["/absolute/path/to/rea/scripts/rea.mjs", mcp]
cwd: !!js process.cwd()
``` ```
Setup preserves caller-owned Cordis expressions and replaces launcher fields
with literal values that doctor can verify. It refuses to edit an expression
that produces the entire REA config, or a group-targeted REA insertion. Use a
literal config and a root-level insertion as shown above.
For a global npm installation, the launcher is under For a global npm installation, the launcher is under
`$(npm root -g)/rea-agents/scripts/rea.mjs`. Check the Node executable with `$(npm root -g)/rea-agents/scripts/rea.mjs`. Restart Harness after setup; it
`command -v node`. Register `serverName: rea` only once in each active profile, exposes tools as `mcp__rea__<tool_name>`. Run `rea setup --skill --dry-run`,
then restart Harness. It exposes tools as `mcp__rea__<tool_name>`. review the destination, then `rea setup --skill --yes` to install the workflow
Run `rea setup --skill --dry-run`, review the destination, then in `~/.agents/skills` (`$DSH_AGENTS_HOME/skills` when configured); Harness
`rea setup --skill --yes` to install the workflow in `~/.agents/skills`. discovers that directory, and its native `skill` tool can load
Harness discovers that directory, or `$DSH_AGENTS_HOME/skills` when configured; `reverse-engineer-anything`.
its native `skill` tool can load `reverse-engineer-anything`.
REA's optional [native client verification](testing.md#end-to-end-integration-and-golden-evidence) REA's optional [native client verification](testing.md#end-to-end-integration-and-golden-evidence)
checks headless chat, skill loading, all tool input schemas and actual analysis checks headless chat, skill loading, all tool input schemas and actual analysis

View File

@ -272,9 +272,13 @@ unverified; skill discovery uses an explicit isolated custom directory.
`verify:deepseek-client` requires an installed DeepSeek Harness (`dsh`; `verify:deepseek-client` requires an installed DeepSeek Harness (`dsh`;
verified with `@deepseek-ai/dsh@0.2.0-rc.2`) and Git. Set verified with `@deepseek-ai/dsh@0.2.0-rc.2`) and Git. Set
`REA_VERIFY_DEEPSEEK_COMMAND` to select its executable. This optional POSIX lane `REA_VERIFY_DEEPSEEK_COMMAND` to select its executable. This optional POSIX lane
installs the skill through `rea setup --skill`, writes the native Cordis MCP seeds caller model settings and a stale Cordis registration in an isolated
patch into an isolated `DSH_HOME`, and binds `HOME` and `USERPROFILE` to the `DSH_HOME`, then runs public `setup --client dsh` dry-run, setup, repeated setup,
disposable account. The native default `~/.agents/skills` search path discovers and scoped doctor. It checks the backup and unrelated patches before booting
Harness with the generated registration. After native execution it uninstalls
through the public CLI and checks that only caller patches remain. `HOME` and
`USERPROFILE` point to the disposable account. The native default
`~/.agents/skills` search path discovers
the installed skill without a `DSH_AGENTS_HOME` override. A separate Git root prevents inherited project skills from the installed skill without a `DSH_AGENTS_HOME` override. A separate Git root prevents inherited project skills from
masking a missing installation. The default `call` mode checks skill loading, masking a missing installation. The default `call` mode checks skill loading,
complete catalog discovery, the actual forwarded input schemas and regexes, complete catalog discovery, the actual forwarded input schemas and regexes,
@ -285,6 +289,12 @@ context capacity declared by its default DeepSeek Flash model; it does not
establish live DeepSeek API or native Windows coverage. Receipts include establish live DeepSeek API or native Windows coverage. Receipts include
request artifacts, result digests and owned-process lineage. request artifacts, result digests and owned-process lineage.
The DSH acceptance journey also exercises public setup, approval, doctor,
generated-launcher MCP startup and uninstall without an installed Harness.
That journey proves REA workflow behavior, not native Cordis expression
evaluation. Filesystem regressions retain tagged values and unrelated rows
across alias dependencies and check refusal of unsafe YAML without mutation.
Full E2E tests invoke the production command dispatcher and real providers, Full E2E tests invoke the production command dispatcher and real providers,
without fake launchers, runners or responses. `verify:keyed-archive` writes without fake launchers, runners or responses. `verify:keyed-archive` writes
Foundation binary, XML, and integer archives using one run-owned Swift module Foundation binary, XML, and integer archives using one run-owned Swift module

View File

@ -5,11 +5,12 @@ import { tmpdir } from "node:os";
import { dirname, join } from "node:path"; import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url"; import { fileURLToPath } from "node:url";
import { Ajv2020 } from "ajv/dist/2020.js"; import { Ajv2020 } from "ajv/dist/2020.js";
import { parse as parseYaml } from "yaml";
import { import {
TOOL_CONTRACTS, TOOL_CONTRACTS,
toolContract, toolContract,
} from "../dist/contracts/toolContracts.js"; } from "../dist/contracts/toolContracts.js";
import { exec } from "./lib/verify-package-core.mjs"; import { exec, pathExists } from "./lib/verify-package-core.mjs";
import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs"; import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs";
import { createOpenAiModelFixture } from "./verify/clients/model-fixture.mjs"; import { createOpenAiModelFixture } from "./verify/clients/model-fixture.mjs";
@ -32,6 +33,7 @@ const skillPath = join(
"SKILL.md", "SKILL.md",
); );
const cli = join(runtimeRoot, "scripts", "rea.mjs"); const cli = join(runtimeRoot, "scripts", "rea.mjs");
const configPath = join(profile, "cordis.patch.yml");
const verifier = createVerifierRun(); const verifier = createVerifierRun();
await Promise.all([ await Promise.all([
mkdir(account), mkdir(account),
@ -66,32 +68,32 @@ const clientVersion = (
timeout: 30_000, timeout: 30_000,
}) })
).stdout.trim(); ).stdout.trim();
for (const args of [ const lifecycle = [];
["setup", "--skill", "--dry-run"], const runRea = async (args, artifact) => {
["setup", "--skill", "--yes"],
]) {
const result = await exec(process.execPath, [cli, ...args, "--json"], { const result = await exec(process.execPath, [cli, ...args, "--json"], {
env: environment, env: environment,
cwd: workspace, cwd: workspace,
timeout: 60_000, timeout: 60_000,
}); });
const parsed = JSON.parse(result.stdout); await writeFile(join(lab, `${artifact}.json`), result.stdout);
assert.equal(parsed.status, args.includes("--dry-run") ? "planned" : "ready"); return JSON.parse(result.stdout);
if (args.includes("--dry-run")) { };
assert.equal(parsed.plannedActions.length, 1); const patches = (text) =>
assert.equal(parsed.plannedActions[0].kind, "install_skill"); parseYaml(text, {
assert.equal(parsed.plannedActions[0].target, dirname(skillPath)); customTags: [
} {
await writeFile( tag: "tag:yaml.org,2002:js",
join(lab, args.includes("--dry-run") ? "setup-plan.json" : "setup.json"), resolve: (source) => ({ __jsExpr: source }),
result.stdout, },
); ],
} });
assert( const withoutRea = (text) =>
(await readFile(skillPath, "utf8")).includes( patches(text).flatMap((op) => {
"name: reverse-engineer-anything", if (op.id === "rea-mcp") return [];
), if (!Array.isArray(op.insert)) return [op];
); const insert = op.insert.filter((entry) => entry.id !== "rea-mcp");
return insert.length === 0 ? [] : [{ ...op, insert }];
});
let catalog; let catalog;
let patternCount = 0; let patternCount = 0;
@ -247,10 +249,9 @@ const fixture = await createOpenAiModelFixture({
}); });
let failure; let failure;
try { try {
// Use the client's native Cordis patch DSL; generic `rea setup --client` does not edit it. // Seed model settings and a stale registration; the public setup workflow
await writeFile( // must produce the registration this native client actually boots.
join(profile, "cordis.patch.yml"), const original = `
`
- id: llm-pi-ai - id: llm-pi-ai
config: config:
providers: providers:
@ -275,13 +276,59 @@ try {
config: config:
serverName: rea serverName: rea
transport: stdio transport: stdio
command: ${JSON.stringify(process.execPath)} command: stale-launcher
args: ${JSON.stringify([cli, "mcp"])} args: [mcp]
cwd: !!js process.cwd() cwd: !!js process.cwd()
env: env:
REA_PROCESS_RUN_ID: ${JSON.stringify(verifier.run_id)} REA_PROCESS_RUN_ID: ${JSON.stringify(verifier.run_id)}
`, `;
await writeFile(configPath, original);
const planned = await runRea(
["setup", "--client", "dsh", "--dry-run"],
"setup-plan",
); );
assert.equal(planned.status, "planned");
assert(planned.plannedActions.some((action) => action.target === configPath));
assert(
planned.plannedActions.some(
(action) => action.target === dirname(skillPath),
),
);
assert(
planned.plannedActions.every(
(action) =>
action.target === configPath || action.target === dirname(skillPath),
),
);
assert.equal(await readFile(configPath, "utf8"), original);
assert.equal(await pathExists(`${configPath}.rea.backup`), false);
lifecycle.push("dry-run");
const setup = await runRea(["setup", "--client", "dsh", "--yes"], "setup");
assert.equal(setup.status, "ready");
assert.equal(await readFile(`${configPath}.rea.backup`, "utf8"), original);
const configured = await readFile(configPath, "utf8");
assert.deepEqual(withoutRea(configured), withoutRea(original));
assert(configured.includes("!!js process.cwd()"));
assert(
(await readFile(skillPath, "utf8")).includes(
"name: reverse-engineer-anything",
),
);
lifecycle.push("setup");
const repeated = await runRea(
["setup", "--client", "dsh", "--yes"],
"setup-repeat",
);
assert.deepEqual(repeated.appliedActions, []);
assert.equal(await readFile(configPath, "utf8"), configured);
assert.equal(await readFile(`${configPath}.rea.backup`, "utf8"), original);
lifecycle.push("idempotent-setup");
const doctor = await runRea(
["doctor", "--client", "dsh", "--skill"],
"doctor",
);
assert.equal(doctor.healthy, true);
lifecycle.push("doctor");
const execution = exec( const execution = exec(
command, command,
[ [
@ -304,6 +351,20 @@ try {
assert.equal(fixture.failure, undefined); assert.equal(fixture.failure, undefined);
assert(finalSeen && result.stdout.includes("REA_CLIENT_COMPATIBILITY_OK")); assert(finalSeen && result.stdout.includes("REA_CLIENT_COMPATIBILITY_OK"));
if (mode === "call") assert(evidenceSeen && skillLoaded); if (mode === "call") assert(evidenceSeen && skillLoaded);
lifecycle.push(mode === "call" ? "native-tool-invocation" : "native-chat");
const uninstall = await runRea(["uninstall"], "uninstall");
assert.equal(uninstall.status, "complete");
assert(
uninstall.items.some(
(item) => item.name === "dsh" && item.status === "removed",
),
);
assert.deepEqual(
patches(await readFile(configPath, "utf8")),
withoutRea(original),
);
assert.equal(await pathExists(skillPath), false);
lifecycle.push("uninstall");
} catch (cause) { } catch (cause) {
failure = cause; failure = cause;
if (typeof cause?.stdout === "string") if (typeof cause?.stdout === "string")
@ -316,6 +377,7 @@ try {
client: "deepseek-harness", client: "deepseek-harness",
clientVersion, clientVersion,
mode, mode,
lifecycle,
passed: failure === undefined, passed: failure === undefined,
artifacts: lab, artifacts: lab,
runtimeRoot, runtimeRoot,

View File

@ -5,6 +5,13 @@ import {
stringify as stringifyYaml, stringify as stringifyYaml,
} from "yaml"; } from "yaml";
import { isDeepStrictEqual } from "node:util"; import { isDeepStrictEqual } from "node:util";
import {
parseDshCordisDocument,
serializeDshDocument,
editDshDocument,
dshClientRegistrationEntry,
} from "./DshCordisPatch.js";
import { import {
applyEdits, applyEdits,
findNodeAtLocation, findNodeAtLocation,
@ -131,6 +138,8 @@ export const parseClientConfiguration = (
): ClientConfigurationDocument => { ): ClientConfigurationDocument => {
if (format === undefined || format === "unsupported") if (format === undefined || format === "unsupported")
throw new TypeError("client does not have a supported MCP config format"); throw new TypeError("client does not have a supported MCP config format");
// DeepSeek Harness stores a Cordis patch list, not a server table.
if (format === "dsh") return parseDshCordisDocument(text);
const document = parseDocument(text, format); const document = parseDocument(text, format);
const serversKey = clientConfigurationServersKey(format); const serversKey = clientConfigurationServersKey(format);
const value = document[serversKey]; const value = document[serversKey];
@ -184,6 +193,14 @@ export const withClientServers = (
servers: Record<string, unknown>, servers: Record<string, unknown>,
removeLegacy?: string, removeLegacy?: string,
): Record<string, unknown> => { ): Record<string, unknown> => {
// The Harness patch list upserts or removes by entry id, not by table.
if (parsed.dialect === "dsh")
return Object.hasOwn(servers, PRODUCT_IDENTITY.mcpServerKey)
? editDshDocument(
parsed,
objectSchema.parse(servers[PRODUCT_IDENTITY.mcpServerKey]),
)
: editDshDocument(parsed);
const [key = "", nested] = parsed.serversPath; const [key = "", nested] = parsed.serversPath;
if (nested === undefined) return { ...parsed.document, [key]: servers }; if (nested === undefined) return { ...parsed.document, [key]: servers };
const outer = { ...objectSchema.parse(parsed.document[key]) }; const outer = { ...objectSchema.parse(parsed.document[key]) };
@ -1280,6 +1297,7 @@ export const serializeClientConfiguration = (
return serializeGrokConfiguration(document, originalText); return serializeGrokConfiguration(document, originalText);
if (format === "hermes") if (format === "hermes")
return serializeHermesConfiguration(document, originalText); return serializeHermesConfiguration(document, originalText);
if (format === "dsh") return serializeDshDocument(document);
// An empty original holds no comments or settings to preserve. Writing a // An empty original holds no comments or settings to preserve. Writing a
// fresh document also keeps a lone BOM from shifting past the closing brace. // fresh document also keeps a lone BOM from shifting past the closing brace.
if ( if (
@ -1398,6 +1416,8 @@ export const clientRegistrationEntry = (
args, args,
...(Object.keys(environment).length === 0 ? {} : { env: environment }), ...(Object.keys(environment).length === 0 ? {} : { env: environment }),
}; };
case "dsh":
return dshClientRegistrationEntry(command, environment);
case "hermes": case "hermes":
// Hermes reads stdio servers from `mcp_servers.<name>` and connects them // Hermes reads stdio servers from `mcp_servers.<name>` and connects them
// unless `enabled` is false, so the entry states it explicitly. // unless `enabled` is false, so the entry states it explicitly.

View File

@ -9,12 +9,15 @@ import {
} from "./ClientConfigurationDocument.js"; } from "./ClientConfigurationDocument.js";
import { PRODUCT_IDENTITY } from "../identity.js"; import { PRODUCT_IDENTITY } from "../identity.js";
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js"; import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
import { dshDocument } from "./DshCordisPatch.js";
/** Read explicit REA overrides without dropping peers when one value is invalid. */ /** Read explicit REA overrides without dropping peers when one value is invalid. */
export const clientRegistrationEnvironment = ( export const clientRegistrationEnvironment = (
parsed: ClientConfigurationDocument | undefined, parsed: ClientConfigurationDocument | undefined,
overrides: Readonly<Record<string, string>> = {}, overrides: Readonly<Record<string, string>> = {},
): Result<Readonly<Record<string, string>>, ConfigurationError> => { ): Result<Readonly<Record<string, string>>, ConfigurationError> => {
if (parsed?.dialect === "dsh")
return dshDocument(parsed.document).environment(overrides);
const key = const key =
parsed?.dialect === "opencode" || parsed?.dialect === "opencode_v2" parsed?.dialect === "opencode" || parsed?.dialect === "opencode_v2"
? "environment" ? "environment"

View File

@ -26,6 +26,7 @@ import {
} from "./SupportedClients.js"; } from "./SupportedClients.js";
import type { SetupClient } from "./SupportedClients.js"; import type { SetupClient } from "./SupportedClients.js";
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js"; import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
import { dshDocument } from "./DshCordisPatch.js";
import type { ArtifactResourceScope } from "../artifacts/ArtifactResourceScope.js"; import type { ArtifactResourceScope } from "../artifacts/ArtifactResourceScope.js";
interface ClientRegistrationStatusBase { interface ClientRegistrationStatusBase {
@ -66,6 +67,7 @@ const registrationSchema = z
startup_timeout_sec: z.number().positive().optional(), startup_timeout_sec: z.number().positive().optional(),
type: z.string().optional(), type: z.string().optional(),
transport: z.string().optional(), transport: z.string().optional(),
serverName: z.string().optional(),
tools: z.array(z.string()).optional(), tools: z.array(z.string()).optional(),
disabled: z.boolean().optional(), disabled: z.boolean().optional(),
enabled: z.boolean().optional(), enabled: z.boolean().optional(),
@ -178,6 +180,7 @@ export const readClientRegistrationStatuses = async (
parsed, parsed,
PRODUCT_IDENTITY.mcpServerKey, PRODUCT_IDENTITY.mcpServerKey,
) && ) &&
(parsed.dialect !== "dsh" || dshDocument(parsed.document).ready) &&
policyBlock === undefined policyBlock === undefined
? "aligned" ? "aligned"
: "stale", : "stale",
@ -221,6 +224,13 @@ const registrationAligned = (
) )
return false; return false;
if (client.format === "vscode" && registration.type !== "stdio") return false; if (client.format === "vscode" && registration.type !== "stdio") return false;
// A Harness registration only connects as the rea stdio server; another
// server name or transport leaves the session without REA tools.
if (
client.format === "dsh" &&
(registration.serverName !== "rea" || registration.transport !== "stdio")
)
return false;
// OMP and Pi infer stdio for a command entry without an explicit type. // OMP and Pi infer stdio for a command entry without an explicit type.
if ( if (
(client.format === "omp" || client.format === "pi") && (client.format === "omp" || client.format === "pi") &&
@ -264,6 +274,11 @@ const parseRegistration = (
value: unknown, value: unknown,
client: SetupClient, client: SetupClient,
): z.output<typeof registrationSchema> => { ): z.output<typeof registrationSchema> => {
if (client.format === "dsh")
return registrationSchema
.pick({ command: true, args: true, serverName: true, transport: true })
.strip()
.parse(value);
if (client.format === "opencode") { if (client.format === "opencode") {
const entry = z const entry = z
.object({ .object({

View File

@ -0,0 +1,375 @@
import { isMap, isSeq, type Node, type YAMLMap } from "yaml";
import { parseEnvironment } from "../config/environment.js";
import { ConfigurationError } from "../domain/configurationErrors.js";
import { err, ok, type Result } from "../domain/result.js";
import type { ClientConfigurationDocument } from "./ClientConfigurationDocument.js";
import { CordisExpression, DshCordisYaml } from "./DshCordisYaml.js";
export const DSH_ENTRY_ID = "rea-mcp";
export const DSH_CLIENT_PACKAGE = "@deepseek-ai/dsh-mcp-client";
const LAUNCHER_KEYS = new Set(["serverName", "transport", "command", "args"]);
const isRecord = (value: unknown): value is Record<string, unknown> =>
typeof value === "object" &&
value !== null &&
!Array.isArray(value) &&
!(value instanceof CordisExpression);
interface PatchOperation {
readonly source: unknown;
readonly map: YAMLMap<unknown, unknown>;
readonly ownedRows: readonly number[];
readonly direct: boolean;
}
/** One interpretation of identity, ordered patch applicability and source nodes. */
export class DshCordisDocument {
readonly #yaml: DshCordisYaml;
readonly #operations: readonly PatchOperation[];
readonly #fields = new Map<string, unknown>();
#entryNode: YAMLMap<unknown, unknown> | undefined;
readonly #insertions: number;
#unknownSelector = false;
readonly config: Record<string, unknown> | undefined;
constructor(text: string) {
this.#yaml = new DshCordisYaml(text);
const root = this.#yaml.document.contents;
if (!isSeq(root))
throw new ConfigurationError("Cordis patches must be a list");
const operations: PatchOperation[] = [];
let insertions = 0;
for (const source of root.items) {
const map = this.#map(source);
if (map === undefined) continue;
const inserted = this.#yaml.resolve(this.#yaml.field(map, "insert"));
const targetId = this.#id(map);
const ownedRows = isSeq(inserted)
? inserted.items.flatMap((entry, index) =>
this.#id(entry) === DSH_ENTRY_ID ? [index] : [],
)
: [];
const direct = !isSeq(inserted) && targetId === DSH_ENTRY_ID;
if (ownedRows.length > 0 && targetId)
throw new ConfigurationError(
"Cannot establish the target group for a Cordis REA insertion from the home patch alone",
);
operations.push({ source, map, ownedRows, direct });
if (isSeq(inserted)) {
for (const index of ownedRows) {
const entry = this.#map(inserted.items[index]);
if (entry === undefined) continue;
insertions += 1;
this.#entryNode = entry;
this.#fields.clear();
this.#unknownSelector = false;
this.#readFields(entry);
}
} else if (direct) {
if (insertions === 0) continue;
// Cordis uses name as a selector, not a rename operation.
const selector = this.#yaml.value(this.#yaml.field(map, "name"));
if (
selector instanceof CordisExpression ||
(selector && this.#field("name") instanceof CordisExpression)
) {
this.#unknownSelector = true;
continue;
}
if (selector && selector !== this.#field("name")) continue;
this.#readFields(map, new Set(["id", "name"]));
}
}
this.#operations = operations;
this.#insertions = insertions;
const config = this.#field("config");
// Ownership survives malformed config so uninstall can remove the source row.
this.config = insertions === 0 ? undefined : isRecord(config) ? config : {};
}
#map(node: unknown): YAMLMap<unknown, unknown> | undefined {
const map = this.#yaml.resolve(node);
return isMap(map) ? map : undefined;
}
#id(node: unknown): unknown {
const id = this.#yaml.value(this.#yaml.field(this.#map(node), "id"));
if (id instanceof CordisExpression)
throw new ConfigurationError(
"Expression-backed Cordis IDs have unknown ownership; use literal IDs before changing registrations",
);
return id;
}
#field(key: string): unknown {
return this.#yaml.value(this.#fields.get(key));
}
#readFields(
map: YAMLMap<unknown, unknown>,
omitted: ReadonlySet<string> = new Set(),
): void {
for (const pair of map.items) {
const key = this.#yaml.value(pair.key);
if (typeof key === "string" && !omitted.has(key))
this.#fields.set(key, pair.value);
}
}
get carriesEntry(): boolean {
return this.#operations.some((op) => op.direct || op.ownedRows.length > 0);
}
get ready(): boolean {
const disabled = this.#field("disabled");
return (
this.#insertions === 1 &&
!this.#unknownSelector &&
this.#field("name") === DSH_CLIENT_PACKAGE &&
(disabled === undefined || disabled === false)
);
}
/** Validate literals without treating expression source as an environment value. */
environment(
overrides: Readonly<Record<string, string>> = {},
): Result<Readonly<Record<string, string>>, ConfigurationError> {
if (this.#unknownSelector)
return err(
new ConfigurationError(
"Expression-backed Cordis name selectors have unknown applicability; use literal selectors before setup",
{
settings: [
{
setting: "name",
constraint: "Use literal selectors before setup",
},
],
},
),
);
const config = this.#field("config");
if (config instanceof CordisExpression)
return err(
new ConfigurationError(
"Expression-backed Cordis config cannot be safely edited",
{
settings: [
{
setting: "config",
constraint:
"Use a literal mapping to preserve caller fields during setup",
},
],
},
),
);
if (config !== undefined && !isRecord(config))
return err(
new ConfigurationError("Cordis REA config must be a mapping", {
settings: [
{
setting: "config",
constraint: "Use a literal mapping before setup",
},
],
}),
);
const raw = this.config?.env;
if (raw !== undefined && !isRecord(raw))
return err(
new ConfigurationError("Cordis server environment must be a mapping"),
);
const literals: Record<string, string> = {};
for (const [key, value] of Object.entries(raw ?? {})) {
if (value instanceof CordisExpression) continue;
if (typeof value !== "string")
return err(
new ConfigurationError("Invalid Cordis server environment", {
settings: [
{
setting: `env.${key}`,
constraint:
"Environment values must be strings or Cordis expressions",
},
],
}),
);
literals[key] = value;
}
const environment = { ...literals, ...overrides };
const validated = parseEnvironment(environment);
return validated.ok ? ok(environment) : validated;
}
desired(
command: readonly string[],
overrides: Readonly<Record<string, string>>,
): Result<Record<string, unknown>, ConfigurationError> {
const environment = this.environment(overrides);
if (!environment.ok) return environment;
const env = {
...(isRecord(this.config?.env) ? this.config.env : {}),
...overrides,
};
const desired = { ...this.config, ...dshClientRegistrationEntry(command) };
delete desired.env;
if (Object.keys(env).length > 0) desired.env = env;
return ok(desired);
}
/** Plan every replacement from source snapshots before changing an output tree. */
serialize(desired?: Record<string, unknown>): string {
const root = this.#yaml.document.contents;
if (!isSeq(root))
throw new ConfigurationError("Cordis patches must be a list");
const replacements = new Map<unknown, unknown>();
const invalidated = new Set(
this.#operations.flatMap((op) =>
op.direct || op.ownedRows.length > 0
? this.#yaml.anchors(op.source)
: [],
),
);
let carried = false;
for (const op of this.#operations) {
if (op.direct) {
replacements.set(op.source, undefined);
continue;
}
if (op.ownedRows.length === 0) continue;
const copy = this.#yaml.detach(op.map, invalidated);
if (!isMap(copy))
throw new ConfigurationError("Cordis operation is not a mapping");
const inserted = this.#yaml.detach(
this.#yaml.resolve(this.#yaml.field(op.map, "insert")),
invalidated,
);
if (!isSeq(inserted))
throw new ConfigurationError("Cordis insertion is not a list");
copy.set("insert", inserted);
const owned = new Set(op.ownedRows);
inserted.items = inserted.items.flatMap((entry, index) => {
if (!owned.has(index)) return [entry];
if (carried || desired === undefined) return [];
carried = true;
return [this.#entry(desired, invalidated)] as typeof inserted.items;
});
replacements.set(
op.source,
inserted.items.length === 0 ? undefined : copy,
);
}
const output = this.#yaml.document.clone();
const outputRoot = output.contents;
if (!isSeq(outputRoot))
throw new ConfigurationError("Cordis patches must be a list");
outputRoot.items = root.items.flatMap((source) => {
const copy = replacements.has(source)
? replacements.get(source)
: this.#yaml.copy(source, invalidated);
return copy === undefined ? [] : [copy];
}) as typeof outputRoot.items;
if (!carried && desired !== undefined)
outputRoot.items.push(
output.createNode({
insert: [
{ id: DSH_ENTRY_ID, name: DSH_CLIENT_PACKAGE, config: desired },
],
}) as never,
);
return output.toString({ lineWidth: 0 });
}
#entry(
desired: Record<string, unknown>,
invalidated: ReadonlySet<Node>,
): YAMLMap<unknown, unknown> {
const entry = this.#yaml.detach(this.#entryNode, invalidated);
if (!isMap(entry))
throw new ConfigurationError("Cordis entry is not a mapping");
this.#yaml.setValue(entry, "id", DSH_ENTRY_ID);
this.#yaml.setValue(entry, "name", DSH_CLIENT_PACKAGE);
entry.delete("disabled");
for (const [key, value] of this.#fields) {
if (["id", "name", "config", "disabled"].includes(key)) continue;
entry.set(key, this.#yaml.detach(value, invalidated));
}
const sourceConfig = this.#map(this.#fields.get("config"));
const config =
sourceConfig === undefined
? this.#yaml.document.createNode({})
: this.#yaml.detach(sourceConfig, invalidated);
if (!isMap(config))
throw new ConfigurationError(
"Cordis registration config is not a mapping",
);
// Caller nodes keep their tags and spelling; only literal launcher values change.
for (const key of LAUNCHER_KEYS)
this.#yaml.setValue(config, key, desired[key]);
const env = this.#map(this.#yaml.field(sourceConfig, "env"));
const desiredEnv = desired.env;
if (isRecord(desiredEnv)) {
const nextEnv =
env === undefined
? this.#yaml.document.createNode({})
: this.#yaml.detach(env, invalidated);
if (!isMap(nextEnv))
throw new ConfigurationError("Cordis environment is not a mapping");
for (const [key, value] of Object.entries(desiredEnv)) {
this.#yaml.setValue(nextEnv, key, value);
}
config.set("env", nextEnv);
} else config.delete("env");
entry.set("config", config);
return entry;
}
}
class DshCordisEdit {
constructor(
readonly source: DshCordisDocument,
readonly desired?: Record<string, unknown>,
) {}
}
export const dshDocument = (
document: Record<string, unknown>,
): DshCordisDocument => {
if (!(document.cordis instanceof DshCordisDocument))
throw new ConfigurationError("Missing Cordis document owner");
return document.cordis;
};
export const parseDshCordisDocument = (
text: string,
): ClientConfigurationDocument => {
const source = new DshCordisDocument(text);
return {
document: { cordis: source },
servers: source.config === undefined ? {} : { rea: source.config },
serversPath: [],
dialect: "dsh",
legacyServers: {},
};
};
export const editDshDocument = (
parsed: ClientConfigurationDocument,
desired?: Record<string, unknown>,
): Record<string, unknown> => ({
cordis: new DshCordisEdit(dshDocument(parsed.document), desired),
});
export const serializeDshDocument = (
document: Record<string, unknown>,
): string => {
if (!(document.cordis instanceof DshCordisEdit))
throw new ConfigurationError("Missing Cordis edit plan");
return document.cordis.source.serialize(document.cordis.desired);
};
export const dshClientRegistrationEntry = (
command: readonly string[],
environment: Readonly<Record<string, string>> = {},
): Record<string, unknown> => {
const [executable = "rea", ...args] = command;
return {
serverName: "rea",
transport: "stdio",
command: executable,
args,
...(Object.keys(environment).length === 0
? {}
: { env: { ...environment } }),
};
};

View File

@ -0,0 +1,175 @@
import { isDeepStrictEqual } from "node:util";
import {
isAlias,
isMap,
isNode,
isScalar,
isSeq,
parseDocument,
visit,
type Document,
type Node,
type YAMLMap,
} from "yaml";
import { ConfigurationError } from "../domain/configurationErrors.js";
/** Expression source is never a literal value and is never evaluated by REA. */
export class CordisExpression {
readonly kind = "cordis-expression";
constructor(readonly source: string) {}
}
/** Immutable source graph; all alias resolution happens against this document. */
export class DshCordisYaml {
readonly document: Document;
readonly #values = new Map<Node, unknown>();
readonly #visiting = new Set<Node>();
constructor(text: string) {
this.document = parseDocument(text, {
customTags: [
{ tag: "tag:yaml.org,2002:js", resolve: (source: string) => source },
],
logLevel: "silent",
});
if (this.document.errors.length > 0 || this.document.warnings.length > 0)
throw new ConfigurationError("Invalid or unsupported Cordis YAML", {
cause: this.document.errors[0] ?? this.document.warnings[0],
});
if (this.document.contents === null)
this.document.contents = this.document.createNode([]);
if (!isSeq(this.document.contents))
throw new ConfigurationError(
"Cordis patches must be a YAML operation list",
);
this.value(this.document.contents);
try {
// Retain YAML's native alias-expansion admission before copying edits.
// This value is discarded; source nodes own every Cordis interpretation.
this.document.toJS();
} catch (cause) {
throw new ConfigurationError("Unsafe Cordis YAML alias expansion", {
cause,
});
}
}
resolve(node: unknown): unknown {
if (!isAlias(node)) return node;
const resolved = node.resolve(this.document);
if (resolved === undefined)
throw new ConfigurationError("Cordis YAML contains an unresolved alias");
return resolved;
}
value(node: unknown): unknown {
const resolved = this.resolve(node);
if (!isNode(resolved)) return resolved;
if (this.#values.has(resolved)) return this.#values.get(resolved);
if (this.#visiting.has(resolved))
throw new ConfigurationError(
"Cyclic Cordis YAML cannot be safely edited",
);
this.#visiting.add(resolved);
let value: unknown;
if (isScalar(resolved))
value =
resolved.tag === "tag:yaml.org,2002:js"
? new CordisExpression(String(resolved.value))
: resolved.value;
else if (isSeq(resolved))
value = resolved.items.map((item) => this.value(item));
else if (isMap(resolved)) {
const entries: [string, unknown][] = [];
for (const pair of resolved.items) {
entries.push([this.#key(pair.key), this.value(pair.value)]);
}
value = Object.fromEntries(entries);
}
this.#visiting.delete(resolved);
this.#values.set(resolved, value);
return value;
}
#key(node: unknown): string {
const key = this.value(node);
if (typeof key === "object" && key !== null)
throw new ConfigurationError(
"Cordis YAML mapping keys must be literal scalars",
);
// Match YAML's JS object projection while retaining the original key node.
return key === null ? "" : String(key);
}
field(map: YAMLMap | undefined, key: string): unknown {
return map?.items.findLast((pair) => this.#key(pair.key) === key)?.value;
}
/** Preserve unchanged nodes and carry their comments when replacing values. */
setValue(map: YAMLMap, key: string, value: unknown): void {
const original = this.field(map, key);
if (isDeepStrictEqual(this.value(original), value)) return;
const replacement = this.document.createNode(value);
if (isNode(original) && isNode(replacement)) {
if (original.comment !== undefined)
replacement.comment = original.comment;
if (original.commentBefore !== undefined)
replacement.commentBefore = original.commentBefore;
}
map.set(key, replacement);
}
/** Copy from the source before edits; materialized nodes own no anchors. */
copy(node: unknown, invalidated?: ReadonlySet<Node>): unknown {
if (isAlias(node)) {
const target = this.resolve(node);
return invalidated === undefined ||
(isNode(target) && invalidated.has(target))
? this.copy(target)
: node.clone();
}
if (!isNode(node)) return node;
const copied = node.clone();
if (
(invalidated === undefined || invalidated.has(node)) &&
(isScalar(copied) || isMap(copied) || isSeq(copied))
)
delete copied.anchor;
if (isSeq(node) && isSeq(copied))
copied.items = node.items.map((item) =>
this.copy(item, invalidated),
) as typeof copied.items;
if (isMap(node) && isMap(copied))
copied.items.forEach((pair, index) => {
pair.key = this.copy(node.items[index]!.key, invalidated);
pair.value = this.copy(node.items[index]!.value, invalidated);
});
return copied;
}
/** Replacing an anchor must not change untouched consumers of its old value. */
detach(node: unknown, invalidated: ReadonlySet<Node>): unknown {
const copied = this.copy(node, invalidated);
if (isNode(copied))
visit(copied, {
Pair: (_key, pair) => {
if (isAlias(pair.key)) pair.key = this.copy(this.resolve(pair.key));
},
Value: (_key, value) => {
delete value.anchor;
},
});
return copied;
}
anchors(node: unknown): readonly Node[] {
if (!isNode(node)) return [];
const anchors: Node[] = [];
visit(node, {
Value: (_key, value) => {
if (value.anchor) anchors.push(value);
},
});
return anchors;
}
}

View File

@ -12,6 +12,7 @@ import {
withClientServers, withClientServers,
type ClientConfigurationDocument, type ClientConfigurationDocument,
} from "./ClientConfigurationDocument.js"; } from "./ClientConfigurationDocument.js";
import { dshDocument, DshCordisDocument } from "./DshCordisPatch.js";
import { constants as fsConstants } from "node:fs"; import { constants as fsConstants } from "node:fs";
import { copyFile, mkdir, rm, writeFile } from "node:fs/promises"; import { copyFile, mkdir, rm, writeFile } from "node:fs/promises";
import { dirname } from "node:path"; import { dirname } from "node:path";
@ -89,7 +90,10 @@ const configureClientDocument = async (
let parsed: ClientConfigurationDocument; let parsed: ClientConfigurationDocument;
try { try {
parsed = parseClientConfiguration( parsed = parseClientConfiguration(
original ?? (format === "toml" || format === "grok" ? "" : "{}"), original ??
(format === "toml" || format === "grok" || format === "dsh"
? ""
: "{}"),
format, format,
); );
const policy = await readClientPolicyBlock( const policy = await readClientPolicyBlock(
@ -396,6 +400,7 @@ const registrationCurrent = (
parsed: ClientConfigurationDocument, parsed: ClientConfigurationDocument,
desired: unknown, desired: unknown,
): boolean => ): boolean =>
(parsed.dialect !== "dsh" || dshDocument(parsed.document).ready) &&
clientConfigurationValuesEqual( clientConfigurationValuesEqual(
parsed.servers[PRODUCT_IDENTITY.mcpServerKey], parsed.servers[PRODUCT_IDENTITY.mcpServerKey],
desired, desired,
@ -410,6 +415,17 @@ const clientConfigurationDesired = (
parsed?: ClientConfigurationDocument, parsed?: ClientConfigurationDocument,
) => { ) => {
const format = parsed?.dialect ?? client.format ?? "json"; const format = parsed?.dialect ?? client.format ?? "json";
const launcher =
command.length === 0 ? [PRODUCT_IDENTITY.cliBinary, "mcp"] : command;
if (format === "dsh") {
const desired = (
parsed === undefined
? new DshCordisDocument("")
: dshDocument(parsed.document)
).desired(launcher, providerEnvironment);
if (!desired.ok) throw desired.error;
return desired.value;
}
// Preserve explicitly configured server settings, never the ambient process // Preserve explicitly configured server settings, never the ambient process
// environment. Newly discovered provider paths win only for their own keys. // environment. Newly discovered provider paths win only for their own keys.
const environment = clientRegistrationEnvironment( const environment = clientRegistrationEnvironment(
@ -419,7 +435,7 @@ const clientConfigurationDesired = (
if (!environment.ok) throw environment.error; if (!environment.ok) throw environment.error;
const registration = clientRegistrationEntry( const registration = clientRegistrationEntry(
format, format,
command.length === 0 ? [PRODUCT_IDENTITY.cliBinary, "mcp"] : command, launcher,
environment.value, environment.value,
); );
return { return {

View File

@ -38,6 +38,7 @@ export interface SetupClient {
| "omp" | "omp"
| "pi" | "pi"
| "hermes" | "hermes"
| "dsh"
| "unsupported"; | "unsupported";
} }
@ -129,6 +130,12 @@ const qwenCodeDirectory = ({ home, env }: ClientPathContext): string => {
const grokDirectory = ({ home, env }: ClientPathContext): string => const grokDirectory = ({ home, env }: ClientPathContext): string =>
env.GROK_HOME || join(home, ".grok"); env.GROK_HOME || join(home, ".grok");
const dshHomeDirectory = ({ home, env }: ClientPathContext): string =>
env.DSH_HOME ?? join(home, ".dsh");
const dshPatchDirectory = (context: ClientPathContext): string =>
join(dshHomeDirectory(context), "cordis.patch.yml");
const hermesDirectory = ({ home, platform, env }: ClientPathContext): string => const hermesDirectory = ({ home, platform, env }: ClientPathContext): string =>
resolveHermesClientHome(home, platform, env); resolveHermesClientHome(home, platform, env);
@ -492,6 +499,17 @@ export const SUPPORTED_CLIENT_DEFINITIONS = [
markerPath: hermesDirectory, markerPath: hermesDirectory,
format: "hermes", format: "hermes",
}, },
{
name: "dsh",
displayName: "DeepSeek Harness",
// The home Cordis patch applies to every profile; the skill directory is
// shared agent storage Harness discovers.
skillPath: ({ home, env }: ClientPathContext) =>
join(env.DSH_AGENTS_HOME ?? join(home, ".agents"), "skills"),
configPath: dshPatchDirectory,
markerPath: dshHomeDirectory,
format: "dsh",
},
{ {
name: "grok_bot", name: "grok_bot",
displayName: "Grok Bot", displayName: "Grok Bot",

View File

@ -22,6 +22,7 @@ import {
skillDestinations, skillDestinations,
} from "./SetupSkill.js"; } from "./SetupSkill.js";
import { isOwnedClientRegistrationCommand } from "./ClientRegistrationIdentity.js"; import { isOwnedClientRegistrationCommand } from "./ClientRegistrationIdentity.js";
import { dshDocument } from "./DshCordisPatch.js";
import { resolveClientConfigTransactionPath } from "./ClientConfigPath.js"; import { resolveClientConfigTransactionPath } from "./ClientConfigPath.js";
import { readRegularFileText } from "./RegularFileRead.js"; import { readRegularFileText } from "./RegularFileRead.js";
import { ArtifactResourceScope } from "../artifacts/ArtifactResourceScope.js"; import { ArtifactResourceScope } from "../artifacts/ArtifactResourceScope.js";
@ -305,10 +306,15 @@ const removeClient = async (
// Beside a native OpenCode V2 table, OpenCode also loads a V1 `mcp.rea`. // Beside a native OpenCode V2 table, OpenCode also loads a V1 `mcp.rea`.
const legacyPath = legacyClientServerPath(parsed, name); const legacyPath = legacyClientServerPath(parsed, name);
const hasNative = Object.hasOwn(parsed.servers, name); const hasNative = Object.hasOwn(parsed.servers, name);
if (!hasNative && legacyPath === undefined) // Harness ownership is the stable entry id. A stale or malformed launcher
// still belongs to that id, and so does a direct patch that projects no row.
const carriesDshEntry =
parsed.dialect === "dsh" && dshDocument(parsed.document).carriesEntry;
if (!hasNative && legacyPath === undefined && !carriesDshEntry)
return item(client.name, "skipped", "REA registration is absent."); return item(client.name, "skipped", "REA registration is absent.");
const removeNative = const removeNative =
hasNative && isOwnedRegistration(parsed.servers[name], client); carriesDshEntry ||
(hasNative && isOwnedRegistration(parsed.servers[name], client));
const removeLegacy = const removeLegacy =
legacyPath !== undefined && legacyPath !== undefined &&
isOwnedRegistration(parsed.legacyServers[name], client); isOwnedRegistration(parsed.legacyServers[name], client);
@ -356,6 +362,8 @@ const removeClient = async (
); );
if ( if (
(removeNative && Object.hasOwn(readback.servers, name)) || (removeNative && Object.hasOwn(readback.servers, name)) ||
(readback.dialect === "dsh" &&
dshDocument(readback.document).carriesEntry) ||
(removeLegacy && Object.hasOwn(readback.legacyServers, name)) (removeLegacy && Object.hasOwn(readback.legacyServers, name))
) )
throw new Error("registration readback mismatch"); throw new Error("registration readback mismatch");

View File

@ -0,0 +1,232 @@
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { Client } from "@modelcontextprotocol/client";
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
import { expect } from "vitest";
import { parse } from "yaml";
import { z } from "zod";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
cliTest(
"DSH CLI previews, approves, repairs, launches MCP, repeats and uninstalls while preserving caller YAML",
async ({ cli }) => {
const home = await createTestTempDirectory("rea-dsh-lifecycle-");
const profile = join(home, "selected harness");
const config = join(profile, "cordis.patch.yml");
const skill = join(
home,
".agents/skills/reverse-engineer-anything/SKILL.md",
);
await mkdir(profile);
const original = `# caller home patch
- insert:
- id: rea-mcp
name: '@deepseek-ai/dsh-mcp-client'
config: {serverName: rea, transport: stdio, command: stale, args: [mcp]}
- holder: &op
insert:
- id: unrelated
name: caller-plugin
disabled: true
config: {cwd: !!js process.cwd()}
- id: rea-mcp
name: '@deepseek-ai/dsh-mcp-client'
config:
serverName: rea
transport: stdio
command: stale
args: [mcp]
cwd: !!js process.cwd()
env:
REA_LOG_LEVEL: !!js process.env.REA_LOG_LEVEL
- *op
`;
await writeFile(config, original);
const environment = { HOME: home, USERPROFILE: home, DSH_HOME: profile };
const run = (args: readonly string[]) =>
cli.run({
arguments: [...args, "--json"],
cwd: home,
environment,
timeoutMs: 20_000,
});
const plan = await run(["setup", "--client", "dsh", "--dry-run"]);
expect(plan.exitCode).toBe(0);
expect(plan.json).toMatchObject({
status: "planned",
appliedActions: [],
plannedActions: expect.arrayContaining([
expect.objectContaining({ id: "configure_client:dsh", target: config }),
expect.objectContaining({ id: "install_skill" }),
]),
});
expect(await readFile(config, "utf8")).toBe(original);
await expect(readFile(`${config}.rea.backup`)).rejects.toMatchObject({
code: "ENOENT",
});
const unapproved = await run(["setup", "--client", "dsh"]);
expect(unapproved.json).toMatchObject({
status: "needs_confirmation",
appliedActions: [],
});
expect(await readFile(config, "utf8")).toBe(original);
const configured = await run(["setup", "--client", "dsh", "--yes"]);
expect(configured.exitCode).toBe(0);
expect(configured.json).toMatchObject({
status: "ready",
clients: { dsh: { status: "configured" } },
});
const text = await readFile(config, "utf8");
expect(text).toContain("# caller home patch");
const patches = parse(text, {
customTags: [
{
tag: "tag:yaml.org,2002:js",
resolve: (source: string) => ({ __jsExpr: source }),
},
],
}) as { insert?: { id: string; config: unknown }[] }[];
const rows = patches.flatMap((patch) => patch.insert ?? []);
expect(rows.filter(({ id }) => id === "unrelated")).toEqual([
{
id: "unrelated",
name: "caller-plugin",
disabled: true,
config: { cwd: { __jsExpr: "process.cwd()" } },
},
]);
expect(rows.filter(({ id }) => id === "rea-mcp")).toHaveLength(1);
const registration = z
.object({
command: z.string(),
args: z.array(z.string()),
cwd: z.unknown(),
env: z.unknown(),
})
.parse(rows.find(({ id }) => id === "rea-mcp")?.config);
expect(registration.cwd).toEqual({ __jsExpr: "process.cwd()" });
expect(registration.env).toMatchObject({
REA_LOG_LEVEL: { __jsExpr: "process.env.REA_LOG_LEVEL" },
});
const doctor = await run(["doctor", "--client", "dsh", "--skill"]);
expect(doctor.exitCode).toBe(0);
expect(doctor.json).toMatchObject({
healthy: true,
identity: {
registrations: expect.arrayContaining([
expect.objectContaining({ client: "dsh", state: "aligned" }),
]),
},
});
await verifyGeneratedLauncher(registration, home, environment);
const repeated = await run(["setup", "--client", "dsh", "--yes"]);
expect(repeated.json).toMatchObject({
status: "ready",
appliedActions: [],
plannedActions: [],
});
expect(await readFile(config, "utf8")).toBe(text);
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(original);
const removed = await run(["uninstall"]);
expect(removed.exitCode).toBe(0);
expect(removed.json).toMatchObject({
status: "complete",
items: expect.arrayContaining([
expect.objectContaining({ name: "dsh", status: "removed" }),
]),
});
const remaining = parse(await readFile(config, "utf8"), {
logLevel: "silent",
}) as { insert?: { id: string }[] }[];
expect(
remaining.flatMap((patch) => patch.insert ?? []).map(({ id }) => id),
).toEqual(["unrelated"]);
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(original);
await expect(readFile(skill)).rejects.toMatchObject({ code: "ENOENT" });
},
);
async function verifyGeneratedLauncher(
registration: { command: string; args: string[] },
home: string,
environment: Record<string, string>,
): Promise<void> {
// Exercise the generated launcher. Native Cordis expression evaluation belongs
// to verify:deepseek-client, not this SDK transport journey.
const transport = new StdioClientTransport({
command: registration.command,
args: registration.args,
cwd: home,
env: { PATH: process.env.PATH ?? "", ...environment },
stderr: "pipe",
});
const client = new Client({ name: "dsh-setup-lifecycle", version: "1" });
try {
await client.connect(transport);
expect((await client.listTools()).tools.map(({ name }) => name)).toContain(
"binary_session",
);
const session = await client.callTool({
name: "binary_session",
arguments: {},
});
expect(session.isError).not.toBe(true);
expect(session.structuredContent).toMatchObject({
result: { open: false },
});
} finally {
await client.close();
await transport.close();
}
}
cliTest.for(["null", "caller-value", "[caller-value]"])(
"DSH CLI refuses to edit config %s and plain uninstall removes its owned row",
async (configValue, { cli }) => {
const home = await createTestTempDirectory("rea-dsh-malformed-config-");
const profile = join(home, ".dsh");
const config = join(profile, "cordis.patch.yml");
await mkdir(profile);
const initial = `# caller patch
- insert:
- id: other
name: caller-plugin
- id: rea-mcp
name: '@deepseek-ai/dsh-mcp-client'
config: ${configValue}
`;
await writeFile(config, initial);
const run = (args: readonly string[]) =>
cli.run({
arguments: [...args, "--json"],
cwd: home,
environment: { HOME: home, USERPROFILE: home, DSH_HOME: profile },
});
const configured = await run(["setup", "--client", "dsh", "--yes"]);
expect(configured.exitCode).not.toBe(0);
expect(configured.json).toMatchObject({
status: "needs_human",
appliedActions: [],
remediation: expect.stringContaining("config: Use a literal mapping"),
});
expect(await readFile(config, "utf8")).toBe(initial);
await expect(readFile(`${config}.rea.backup`)).rejects.toMatchObject({
code: "ENOENT",
});
const removed = await run(["uninstall"]);
expect(removed.exitCode).toBe(0);
expect(removed.json).toMatchObject({
status: "complete",
items: expect.arrayContaining([
expect.objectContaining({ name: "dsh", status: "removed" }),
]),
});
const remaining = await readFile(config, "utf8");
expect(remaining).toContain("# caller patch");
expect(parse(remaining)).toEqual([
{ insert: [{ id: "other", name: "caller-plugin" }] },
]);
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(initial);
},
);

View File

@ -67,6 +67,7 @@ describe("client configuration filesystem lifecycle", () => {
"omp", "omp",
"pi", "pi",
"hermes", "hermes",
"dsh",
"grok_bot", "grok_bot",
]); ]);
expect( expect(

File diff suppressed because it is too large Load Diff

View File

@ -15,6 +15,8 @@ export const CLIENT_LOCATION_ENVIRONMENT = [
"APPDATA", "APPDATA",
"CLAUDE_CONFIG_DIR", "CLAUDE_CONFIG_DIR",
"CODEX_HOME", "CODEX_HOME",
"DSH_HOME",
"DSH_AGENTS_HOME",
"COPILOT_HOME", "COPILOT_HOME",
"GROK_HOME", "GROK_HOME",
"GEMINI_CLI_HOME", "GEMINI_CLI_HOME",