From 52c92bce36b0b2b134fae642b5f5b7468f4a16bb Mon Sep 17 00:00:00 2001 From: magalz Date: Fri, 20 Nov 2026 14:21:23 -0300 Subject: [PATCH 1/3] feat!: route Memtrace MCP calls per Session working directory (v0.3.0) Set perWorkingDirectory: true on the mcp-memtrace row so dsh-mcp-client starts each tool call in a child in the calling Session's working directory (git worktrees resolve to the main repository's store). This needs dsh-mcp-client with that option; a stock dsh ignores the unknown key, and there a restated row's cwd: is the fallback. Remove the published dsh-plugin-memtrace-mcp bin, its launcher, and the memtrace resolver; package.json drops bin and bin/ and moves to 0.3.0. README (en/zh) and the arc42 docs describe the option, the patched-client requirement, and the cwd restate. Co-Authored-By: Claude Opus 5.5 --- README.md | 10 ++++----- README.zh.md | 14 ++++++++++--- bin/memtrace-mcp.js | 20 ------------------ cordis.patch.yml | 26 ++++++++--------------- docs/02_architecture_constraints.md | 2 +- docs/05_building_block_view.md | 4 +--- lib/resolve-memtrace-mcp.js | 31 ---------------------------- package.json | 6 +----- test/manifest.test.js | 15 ++++++++++---- test/resolve-memtrace-mcp.test.js | 32 ----------------------------- 10 files changed, 38 insertions(+), 122 deletions(-) delete mode 100755 bin/memtrace-mcp.js delete mode 100644 lib/resolve-memtrace-mcp.js delete mode 100644 test/resolve-memtrace-mcp.test.js diff --git a/README.md b/README.md index 821c789..d60e55f 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ npx -y @deepseek-ai/dsh plugin --profile web add github:syncable-dev/dsh-plugin- dsh --profile web --dump-config | grep -A4 'id: dsh-plugin-memtrace' ``` -The row pins `command: memtrace` (override with `MEMTRACE_BIN`; for a zero-install fetch restate the row with `command: npx` and `args: ['-y', 'memtrace', 'mcp']`). One child serves the whole profile — give a project its own graph by restating the `mcp-memtrace` row in the profile's `cordis.patch.yml` with `cwd: ` (restate the whole row, DSH does not deep-merge). +The row pins `command: memtrace` (override with `MEMTRACE_BIN`; for a zero-install fetch restate the row with `command: npx` and `args: ['-y', 'memtrace', 'mcp']`). With a client that supports `perWorkingDirectory`, each Session's calls run in that Session's working directory. On a stock dsh that key is ignored — restate the `mcp-memtrace` row in the profile's `cordis.patch.yml` with `cwd: ` (restate the whole row, DSH does not deep-merge). Then open the Web UI and index the workspace: @@ -96,7 +96,7 @@ flowchart LR Two Cordis rows, both owned by this bundle: 1. **`dsh-plugin-memtrace`** — reads `skills/*/SKILL.md` and registers each skill at apply time. Unload disposes them. -2. **`mcp-memtrace`** — official MCP client, `serverName: memtrace`, stdio, `memtrace mcp` with the command pinned (`MEMTRACE_BIN`, else `memtrace` on PATH — no per-child npx fetch). No workspace flag: `memtrace mcp` anchors on its working directory and opens the repository's own `.memdb` — per project once the host keys MCP children per session workspace; per restated row today. +2. **`mcp-memtrace`** — official MCP client, `serverName: memtrace`, stdio, `memtrace mcp` with the command pinned (`MEMTRACE_BIN`, else `memtrace` on PATH — no per-child npx fetch). No workspace flag: `memtrace mcp` anchors on its working directory and opens the repository's own `.memdb`. `perWorkingDirectory: true` starts each tool call in a child in the calling Session's working directory, so each project gets its own store (a git worktree resolves to the main repository's store). This needs a dsh-mcp-client with the option; a stock dsh ignores the key, and then a restated row's `cwd` sets the project. We do **not** patch the filesystem skill provider's config. That row is last-write-wins; runtime registration does not collide with other skill packs. @@ -136,11 +136,11 @@ All 27 bundles live under [`skills/`](skills/). | Variable | Effect | | --- | --- | -| `MEMTRACE_BIN` | Absolute path or command the MCP row launches instead of the `memtrace` on PATH (also the shipped launcher's preference) | +| `MEMTRACE_BIN` | Absolute path or command the MCP row launches instead of the `memtrace` on PATH | Override the MCP row in the profile's `cordis.patch.yml` if you already run a Streamable HTTP Memtrace endpoint — restate the whole `mcp-memtrace` config (DSH does not deep-merge). -MCP stdio carries no per-call session identity: one child receives every session's calls, so repository identity must travel with the process — `memtrace mcp` with no flags opens the `.memdb` anchored by its working directory (the project-editor pattern from `memtrace mcp --help`). dsh-mcp-client (0.2.2-rc.5) mounts one child per row with a static `cwd`, so per-session keying needs a host-side change; until then, restating the `mcp-memtrace` row with `cwd: ` gives that project its own child, its own store, and no split-brain refusal (memtrace still refuses to index a repo into a store other than the one that path resolves to). +`memtrace mcp` opens the `.memdb` anchored by its working directory (the project-editor pattern from `memtrace mcp --help`). With `perWorkingDirectory: true`, each tool call runs in a child started in the calling Session's working directory, so a Session on a git worktree resolves to the main repository's store. This requires a dsh-mcp-client that implements the option. A stock dsh keeps the unknown key and ignores it, so every call reaches the one child in the profile directory, which has no workspace owner; there, restate the `mcp-memtrace` row in the profile's `cordis.patch.yml` with `cwd: ` and the whole config (DSH does not deep-merge). ## Compatibility @@ -154,7 +154,7 @@ MCP stdio carries no per-call session identity: one child receives every session ## Permissions & data -- Spawns `memtrace mcp` (`MEMTRACE_BIN` overrides the command); the per-project working directory comes from the session-workspace keying described above, or your restated row's `cwd` (reads the repo to index; writes `.memdb` next to the project). +- Spawns `memtrace mcp` (`MEMTRACE_BIN` overrides the command) in each Session's working directory via `perWorkingDirectory`, or in your restated row's `cwd` on a stock dsh (reads the repo to index; writes `.memdb` next to the project). - Registers skills from this package only. - Does not send code to Memtrace cloud. Local graph. diff --git a/README.zh.md b/README.zh.md index 375c4b8..d7ebe93 100644 --- a/README.zh.md +++ b/README.zh.md @@ -60,7 +60,7 @@ npx -y @deepseek-ai/dsh plugin --profile web add github:syncable-dev/dsh-plugin- dsh --profile web --dump-config | grep -A4 'id: dsh-plugin-memtrace' ``` -row 固定 `command: memtrace`(用 `MEMTRACE_BIN` 覆盖;零安装可整行重述为 `command: npx`、`args: ['-y', 'memtrace', 'mcp']`)。一个 child 服务整个 profile —— 想让某个项目有自己的图谱,在 profile 的 `cordis.patch.yml` 里整行重述 `mcp-memtrace` 并设 `cwd: <仓库根目录>`(DSH 不做深度合并,需重述整行)。 +row 固定 `command: memtrace`(用 `MEMTRACE_BIN` 覆盖;零安装可整行重述为 `command: npx`、`args: ['-y', 'memtrace', 'mcp']`)。客户端支持 `perWorkingDirectory` 时,每个 Session 的调用都在该 Session 的工作目录里运行。原版 dsh 会忽略该键 —— 此时在 profile 的 `cordis.patch.yml` 里整行重述 `mcp-memtrace` 并设 `cwd: <仓库根目录>`(DSH 不做深度合并,需重述整行)。 然后在 Web UI 里: @@ -87,11 +87,19 @@ row 固定 `command: memtrace`(用 `MEMTRACE_BIN` 覆盖;零安装可整行 两条 Cordis 行,都由本包拥有: 1. **`dsh-plugin-memtrace`** — 读取 `skills/*/SKILL.md`,在 `apply` 时注册;卸载即注销。 -2. **`mcp-memtrace`** — 官方 MCP 客户端,`serverName: memtrace`,`memtrace mcp`,命令固定(`MEMTRACE_BIN`,否则 PATH 上的 `memtrace` —— 不会按 child 重复拉取 npx)。不带 workspace 旗标:`memtrace mcp` 以其工作目录为锚,打开仓库自己的 `.memdb` —— 等 host 按会话 workspace 启动 child 后即为按项目;当前则靠整行重述本 row。 +2. **`mcp-memtrace`** — 官方 MCP 客户端,`serverName: memtrace`,`memtrace mcp`,命令固定(`MEMTRACE_BIN`,否则 PATH 上的 `memtrace` —— 不会按 child 重复拉取 npx)。不带 workspace 旗标:`memtrace mcp` 以其工作目录为锚,打开仓库自己的 `.memdb`。`perWorkingDirectory: true` 让每次工具调用都在发起调用的 Session 工作目录里启动 child,每个项目因此有自己的 store(git worktree 解析到主仓库的 store)。这需要实现了该选项的 dsh-mcp-client;原版 dsh 会忽略该键,此时靠整行重述本 row 的 `cwd` 指定项目。 不会去改文件系统 skill provider 的 `config`(整行覆盖、后写赢)。运行时注册不会和其他 skill 包打架。 -MCP stdio 不携带每次调用的会话身份:一个 child 收到所有会话的调用,仓库身份必须随进程传递 —— 不带旗标的 `memtrace mcp` 打开由其工作目录锚定的 `.memdb`(`memtrace mcp --help` 的 project-editor 模式)。dsh-mcp-client(0.2.2-rc.5)按 row 挂一个静态 `cwd` 的 child,按会话 keying 需要 host 侧改动;在此之前,整行重述 `mcp-memtrace` 并设 `cwd: <仓库根目录>` 即可让该项目拥有自己的 child、自己的 store,也不会触发防脑裂拒绝。 +`memtrace mcp` 打开由其工作目录锚定的 `.memdb`(`memtrace mcp --help` 的 project-editor 模式)。`perWorkingDirectory: true` 让每次工具调用都在发起调用的 Session 工作目录里启动 child,因此 git worktree 上的 Session 会解析到主仓库的 store。这需要实现了该选项的 dsh-mcp-client。原版 dsh 会保留这个未知键但忽略它,所有调用都落到 profile 目录里唯一的 child,而该目录没有 workspace owner;此时在 profile 的 `cordis.patch.yml` 里整行重述 `mcp-memtrace` 并设 `cwd: <仓库根目录>`(DSH 不做深度合并)。 + +## 配置与权限 + +| 变量 | 作用 | +| --- | --- | +| `MEMTRACE_BIN` | MCP 行使用的命令(绝对路径或命令),覆盖 PATH 上的 `memtrace` | + +`perWorkingDirectory` 开启时按 Session 工作目录启动 `memtrace mcp`(读取仓库以建索引,`.memdb` 写在项目旁);原版 dsh 则用重述行的 `cwd`。本包只注册自己的 skill,不向 Memtrace 云端发送代码,图谱保存在本机。 ## 许可证 diff --git a/bin/memtrace-mcp.js b/bin/memtrace-mcp.js deleted file mode 100755 index 9b7893e..0000000 --- a/bin/memtrace-mcp.js +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env node -import { spawn } from 'node:child_process' -import { memtraceOnPath, resolveMemtraceLaunch } from '../lib/resolve-memtrace-mcp.js' - -const launch = resolveMemtraceLaunch({ - env: process.env, - memtraceOnPath: memtraceOnPath(), -}) - -const child = spawn(launch.command, [...launch.args, 'mcp'], { - stdio: 'inherit', - cwd: process.cwd(), - env: process.env, - shell: process.platform === 'win32', -}) - -child.on('exit', (code, signal) => { - if (signal) process.kill(process.pid, signal) - process.exit(code ?? 1) -}) diff --git a/cordis.patch.yml b/cordis.patch.yml index ef4fd99..2b3afe8 100644 --- a/cordis.patch.yml +++ b/cordis.patch.yml @@ -1,22 +1,11 @@ -# Memtrace bundle layer for DeepSeek Harness. -# -# Two rows, both owned by this package: +# Memtrace bundle layer for DeepSeek Harness: two rows owned by this package. # - dsh-plugin-memtrace registers the Memtrace agent skills at apply time. -# - mcp-memtrace is the official DSH MCP client pointed at `memtrace mcp`. -# -# Per-project model: `memtrace mcp` with no workspace flag anchors on its -# working directory and opens the repository's own .memdb — the -# project-editor pattern from `memtrace mcp --help`. MCP stdio carries no -# per-call session identity, so the child must be keyed per session -# workspace by the host; dsh-mcp-client (0.2.2-rc.5) mounts one child per -# row with a static cwd, so per-session keying needs a host-side change. -# Until then, restate this row in the profile's cordis.patch.yml with -# `cwd: ` to give one project its own child and store; without -# a cwd the child inherits the app profile directory, which has no -# repository scope. The command is pinned (MEMTRACE_BIN, else `memtrace` -# on PATH) so per-project children never multiply npx fetches. Values stay -# literal except the scalar command expression: the 0.2.x patch composer -# mangles evaluated !!js values that return arrays. +# - mcp-memtrace is the official DSH MCP client running `memtrace mcp`. +# `memtrace mcp` anchors on its working directory. `perWorkingDirectory` +# routes each tool call to a child in the calling Session's directory; a +# dsh-mcp-client without it ignores the key, so restate this row with +# `cwd: `. Values stay literal except the scalar command: the +# 0.2.x composer mangles `!!js` values that return arrays. - insert: - id: dsh-plugin-memtrace name: dsh-plugin-memtrace @@ -25,6 +14,7 @@ config: serverName: memtrace transport: stdio + perWorkingDirectory: true command: !!js process.env.MEMTRACE_BIN || 'memtrace' args: - mcp diff --git a/docs/02_architecture_constraints.md b/docs/02_architecture_constraints.md index fd10d54..2fe0c84 100644 --- a/docs/02_architecture_constraints.md +++ b/docs/02_architecture_constraints.md @@ -6,5 +6,5 @@ - DSH compatibility declared via `engines.dsh` `>=0.1.0-rc.6 <0.3.0-0` (decides on DSH `0.2.1-alpha.3+`); the `@deepseek-ai/dsh` peer range mirrors it for older DSH. - Patch rows must not overwrite another plugin's `config` (no deep merge). - Bundle patch config stays literal: the 0.2.x patch composer mangles evaluated `!!js` values that return arrays (the mcp-memtrace row is static for this reason). -- MCP child store identity: `memtrace mcp` anchors on its working directory and opens the repo's own `.memdb` (per project); per-session keying of MCP children by workspace is a pending host-side change — until then a restated row's `cwd` sets the project. No shared named-workspace store; memtrace refuses cross-store indexing. +- MCP child store identity: `memtrace mcp` anchors on its working directory and opens the repo's own `.memdb`; the `mcp-memtrace` row sets `perWorkingDirectory: true`, so each tool call runs in a child started in the calling Session's working directory (a git worktree resolves to the main repo's store). This needs a dsh-mcp-client that implements the option; a stock dsh ignores it, and a restated row's `cwd` sets the project. No shared named-workspace store; memtrace refuses cross-store indexing. - Node `>=22.19` (plugin floor; Harness `0.2.x` hosts themselves require `>=24.9`). diff --git a/docs/05_building_block_view.md b/docs/05_building_block_view.md index 1f3c01d..56613d7 100644 --- a/docs/05_building_block_view.md +++ b/docs/05_building_block_view.md @@ -7,7 +7,6 @@ C4Container title Container diagram — dsh-plugin-memtrace Container(skills, "Skill registrar", "index.js", "Registers every bundled SKILL.md on ctx.skills") Container(patch, "Bundle patch", "cordis.patch.yml", "Inserts skill row + MCP client row") - Container(launcher, "MCP launcher", "bin/memtrace-mcp.js", "Resolves memtrace binary vs npx") Container_Ext(mcpClient, "dsh-mcp-client", "Official DSH plugin", "Discovers tools as mcp__memtrace__*") Container_Ext(server, "memtrace mcp", "stdio", "Graph tools") Rel(patch, skills, "loads", "Cordis row") @@ -19,10 +18,9 @@ C4 Level 3 — folders in this package, matching screaming architecture: | Folder | Responsibility | | --- | --- | -| `lib/` | Skill parse/load, MCP launch resolution, Cordis apply factory | +| `lib/` | Skill parse/load, Cordis apply factory | | `skills/` | One Memtrace workflow per directory | | `references/` | Shared MCP parameter spec for skill bodies | -| `bin/` | stdio launcher used when users point DSH at this package | | `assets/` | Icon, hero, social preview | | `docs/` | arc42 | | `test/` | Fast node:test suite | diff --git a/lib/resolve-memtrace-mcp.js b/lib/resolve-memtrace-mcp.js deleted file mode 100644 index efc9ffb..0000000 --- a/lib/resolve-memtrace-mcp.js +++ /dev/null @@ -1,31 +0,0 @@ -import { spawnSync } from 'node:child_process' - -const NPX_MEMTRACE = Object.freeze({ command: 'npx', args: Object.freeze(['-y', 'memtrace']) }) - -/** - * Resolve the memtrace binary launch prefix. MEMTRACE_BIN wins, then a - * `memtrace` on PATH, then `npx -y memtrace` (which downloads on first use). - */ -export function resolveMemtraceLaunch({ env, memtraceOnPath }) { - const override = env.MEMTRACE_BIN?.trim() - if (override) { - return { command: override, args: [] } - } - if (memtraceOnPath) { - return { command: 'memtrace', args: [] } - } - return { command: NPX_MEMTRACE.command, args: [...NPX_MEMTRACE.args] } -} - -/** Resolve the launch for the Memtrace MCP server. */ -export function resolveMemtraceMcpLaunch({ env, memtraceOnPath }) { - const launch = resolveMemtraceLaunch({ env, memtraceOnPath }) - return { command: launch.command, args: [...launch.args, 'mcp'] } -} - -/** Whether a `memtrace` command resolves on PATH. */ -export function memtraceOnPath() { - const probe = process.platform === 'win32' ? 'where' : 'which' - const result = spawnSync(probe, ['memtrace'], { encoding: 'utf8' }) - return result.status === 0 -} diff --git a/package.json b/package.json index 150e631..8dde0aa 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,13 @@ { "name": "dsh-plugin-memtrace", - "version": "0.2.3", + "version": "0.3.0", "description": "Local-first code intelligence graph for DeepSeek Harness: structural search, blast radius, temporal memory, and 27 agent skills over Memtrace MCP.", "icon": "./assets/icon.svg", "type": "module", "main": "index.js", - "bin": { - "dsh-plugin-memtrace-mcp": "./bin/memtrace-mcp.js" - }, "files": [ "index.js", "lib/", - "bin/", "skills/", "references/", "assets/", diff --git a/test/manifest.test.js b/test/manifest.test.js index f1c4352..ee25b3c 100644 --- a/test/manifest.test.js +++ b/test/manifest.test.js @@ -12,7 +12,9 @@ describe('DSH bundle contract', () => { assert.equal(manifest.name, 'dsh-plugin-memtrace') assert.equal(manifest.dsh.bundle.patch, './cordis.patch.yml') assert.ok(manifest.keywords.includes('dsh-plugin')) - assert.ok(manifest.bin['dsh-plugin-memtrace-mcp']) + // No published launcher: the MCP client spawns `memtrace` directly. + assert.equal(manifest.bin, undefined) + assert.ok(!manifest.files.includes('bin/')) }) it('inserts the skill plugin and the official MCP client under stable ids', () => { @@ -23,13 +25,18 @@ describe('DSH bundle contract', () => { assert.match(patch, /name:\s*'@deepseek-ai\/dsh-mcp-client'/) assert.match(patch, /serverName:\s*memtrace/) assert.match(patch, /transport:\s*stdio/) + // Per-session working directory: the client starts one child in cwd for + // tool discovery, then routes each call to a child in the Session's + // directory. A static row-level cwd is not used (comments are ignored). + assert.match(patch, /perWorkingDirectory:\s*true/) + assert.doesNotMatch(patch.replace(/^#.*$/gm, ''), /^\s*cwd:/m) // The 0.2.x patch composer mangles evaluated !!js values that return // arrays (args became {"[object Object]": [...]}), so args stays literal // while the command may evaluate a scalar. Comment lines are ignored. assert.doesNotMatch(patch.replace(/^#.*$/gm, ''), /args:\s*!!js/) - // Per-project model: pinned command, no workspace flag — the child - // anchors on its working directory (the session workspace once the host - // keys MCP children per workspace; a restated row's cwd today). + // Per-project model: pinned command, no workspace flag — the host keys + // MCP children per Session working directory via perWorkingDirectory; + // a restated row's cwd is the stock-dsh fallback. assert.match(patch, /command:\s*!!js process\.env\.MEMTRACE_BIN \|\| 'memtrace'/) assert.doesNotMatch(patch.replace(/^#.*$/gm, ''), /--workspace/) assert.doesNotMatch(patch, /workspace create/) diff --git a/test/resolve-memtrace-mcp.test.js b/test/resolve-memtrace-mcp.test.js deleted file mode 100644 index 7c769ce..0000000 --- a/test/resolve-memtrace-mcp.test.js +++ /dev/null @@ -1,32 +0,0 @@ -import assert from 'node:assert/strict' -import { describe, it } from 'node:test' -import { resolveMemtraceMcpLaunch } from '../lib/resolve-memtrace-mcp.js' - -describe('resolveMemtraceMcpLaunch', () => { - it('prefers MEMTRACE_BIN when set', () => { - const launch = resolveMemtraceMcpLaunch({ - env: { MEMTRACE_BIN: '/opt/memtrace' }, - memtraceOnPath: true, - }) - - assert.deepEqual(launch, { command: '/opt/memtrace', args: ['mcp'] }) - }) - - it('uses memtrace on PATH when no override is set', () => { - const launch = resolveMemtraceMcpLaunch({ - env: {}, - memtraceOnPath: true, - }) - - assert.deepEqual(launch, { command: 'memtrace', args: ['mcp'] }) - }) - - it('falls back to npx memtrace mcp so a fresh DSH install still boots the server', () => { - const launch = resolveMemtraceMcpLaunch({ - env: {}, - memtraceOnPath: false, - }) - - assert.deepEqual(launch, { command: 'npx', args: ['-y', 'memtrace', 'mcp'] }) - }) -}) From 09ca0126936cbb6e435803dca808a02c3810255a Mon Sep 17 00:00:00 2001 From: magalz Date: Fri, 20 Nov 2026 14:31:01 -0300 Subject: [PATCH 2/3] docs: drop the npx fallback and describe per-Session routing Rewrite the runtime, deployment, risk, and ADR docs for the pinned `memtrace` command and per-Session `perWorkingDirectory` routing, with the stock-dsh `cwd` restate. Deduplicate the README explanation (EN/ZH) into How it works and add a Compatibility row for the patched client. Drop the unused directory/resourceDirectory fields from load-skills and their test assertions. Co-Authored-By: Claude Opus 5.5 --- README.md | 9 +++-- README.zh.md | 9 +++-- docs/02_architecture_constraints.md | 2 +- docs/03_context_and_scope.md | 2 +- docs/04_solution_strategy.md | 1 - docs/06_runtime_view.md | 2 +- docs/07_deployment_view.md | 2 +- .../0001-official-mcp-client.md | 2 + docs/11_risks_and_technical_debt.md | 3 +- lib/load-skills.js | 2 - test/bundled-skills.test.js | 3 +- test/load-skills.test.js | 3 +- test/manifest.test.js | 37 ++++++++----------- 13 files changed, 36 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index d60e55f..206419c 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ npx -y @deepseek-ai/dsh plugin --profile web add github:syncable-dev/dsh-plugin- dsh --profile web --dump-config | grep -A4 'id: dsh-plugin-memtrace' ``` -The row pins `command: memtrace` (override with `MEMTRACE_BIN`; for a zero-install fetch restate the row with `command: npx` and `args: ['-y', 'memtrace', 'mcp']`). With a client that supports `perWorkingDirectory`, each Session's calls run in that Session's working directory. On a stock dsh that key is ignored — restate the `mcp-memtrace` row in the profile's `cordis.patch.yml` with `cwd: ` (restate the whole row, DSH does not deep-merge). +The row pins `command: memtrace` (override with `MEMTRACE_BIN`; for a zero-install fetch restate the row with `command: npx` and `args: ['-y', 'memtrace', 'mcp']`). With `perWorkingDirectory`, each tool call runs in the Session's working directory — see [How it works](#how-it-works) for the stock-dsh fallback. Then open the Web UI and index the workspace: @@ -96,7 +96,7 @@ flowchart LR Two Cordis rows, both owned by this bundle: 1. **`dsh-plugin-memtrace`** — reads `skills/*/SKILL.md` and registers each skill at apply time. Unload disposes them. -2. **`mcp-memtrace`** — official MCP client, `serverName: memtrace`, stdio, `memtrace mcp` with the command pinned (`MEMTRACE_BIN`, else `memtrace` on PATH — no per-child npx fetch). No workspace flag: `memtrace mcp` anchors on its working directory and opens the repository's own `.memdb`. `perWorkingDirectory: true` starts each tool call in a child in the calling Session's working directory, so each project gets its own store (a git worktree resolves to the main repository's store). This needs a dsh-mcp-client with the option; a stock dsh ignores the key, and then a restated row's `cwd` sets the project. +2. **`mcp-memtrace`** — official MCP client, `serverName: memtrace`, stdio, `memtrace mcp` with the command pinned (`MEMTRACE_BIN`, else `memtrace` on PATH — no per-child npx fetch). No workspace flag: `memtrace mcp` anchors on its working directory and opens the repository's own `.memdb`. A listing child runs in the row's `cwd`; with `perWorkingDirectory: true`, each tool call runs in a child started in the calling Session's working directory, so each project gets its own store, and a Session on a git worktree resolves to the main repository's store. This needs a dsh-mcp-client with the option; a stock dsh ignores the key, so restate the row with `cwd: `. We do **not** patch the filesystem skill provider's config. That row is last-write-wins; runtime registration does not collide with other skill packs. @@ -140,13 +140,14 @@ All 27 bundles live under [`skills/`](skills/). Override the MCP row in the profile's `cordis.patch.yml` if you already run a Streamable HTTP Memtrace endpoint — restate the whole `mcp-memtrace` config (DSH does not deep-merge). -`memtrace mcp` opens the `.memdb` anchored by its working directory (the project-editor pattern from `memtrace mcp --help`). With `perWorkingDirectory: true`, each tool call runs in a child started in the calling Session's working directory, so a Session on a git worktree resolves to the main repository's store. This requires a dsh-mcp-client that implements the option. A stock dsh keeps the unknown key and ignores it, so every call reaches the one child in the profile directory, which has no workspace owner; there, restate the `mcp-memtrace` row in the profile's `cordis.patch.yml` with `cwd: ` and the whole config (DSH does not deep-merge). +On a stock dsh, `perWorkingDirectory` is ignored: restate the `mcp-memtrace` row in the profile's `cordis.patch.yml` with `cwd: ` (restate the whole row, DSH does not deep-merge). ## Compatibility | Surface | Status | | --- | --- | | Harness | DeepSeek Harness `>=0.1.0-rc.6 <0.3.0` — verified against `0.2.2-rc.5` (current release) | +| Per-Session routing | Needs a dsh-mcp-client with `perWorkingDirectory`; stock `0.2.2-rc.5` needs the row restated with `cwd` | | Compat check | `engines.dsh` decides on DSH `0.2.1-alpha.3`+; older DSH reads the `@deepseek-ai/dsh` peer range | | Node | `>=22.19.0` (DSH `0.2.x` itself requires Node `>=24.9`; the desktop app bundles its own runtime) | | Platforms | macOS, Linux, Windows (Memtrace native binary via npm optional deps) | @@ -154,7 +155,7 @@ Override the MCP row in the profile's `cordis.patch.yml` if you already run a St ## Permissions & data -- Spawns `memtrace mcp` (`MEMTRACE_BIN` overrides the command) in each Session's working directory via `perWorkingDirectory`, or in your restated row's `cwd` on a stock dsh (reads the repo to index; writes `.memdb` next to the project). +- Spawns `memtrace mcp` (`MEMTRACE_BIN` overrides the command) as described under How it works (reads the repo to index; writes `.memdb` next to the project). - Registers skills from this package only. - Does not send code to Memtrace cloud. Local graph. diff --git a/README.zh.md b/README.zh.md index d7ebe93..3f0ecd3 100644 --- a/README.zh.md +++ b/README.zh.md @@ -60,7 +60,7 @@ npx -y @deepseek-ai/dsh plugin --profile web add github:syncable-dev/dsh-plugin- dsh --profile web --dump-config | grep -A4 'id: dsh-plugin-memtrace' ``` -row 固定 `command: memtrace`(用 `MEMTRACE_BIN` 覆盖;零安装可整行重述为 `command: npx`、`args: ['-y', 'memtrace', 'mcp']`)。客户端支持 `perWorkingDirectory` 时,每个 Session 的调用都在该 Session 的工作目录里运行。原版 dsh 会忽略该键 —— 此时在 profile 的 `cordis.patch.yml` 里整行重述 `mcp-memtrace` 并设 `cwd: <仓库根目录>`(DSH 不做深度合并,需重述整行)。 +row 固定 `command: memtrace`(用 `MEMTRACE_BIN` 覆盖;零安装可整行重述为 `command: npx`、`args: ['-y', 'memtrace', 'mcp']`)。`perWorkingDirectory` 让每次工具调用都在 Session 的工作目录里运行 —— 原版 dsh 的 `cwd` 回退见「工作原理」。 然后在 Web UI 里: @@ -79,6 +79,7 @@ row 固定 `command: memtrace`(用 `MEMTRACE_BIN` 覆盖;零安装可整行 ## 兼容性 - DeepSeek Harness `>=0.1.0-rc.6 <0.3.0`(已对照当前版本 `0.2.2-rc.5` 验证)。 +- 按 Session 路由需要带 `perWorkingDirectory` 的 dsh-mcp-client;原版 `0.2.2-rc.5` 需整行重述并设 `cwd`。 - DSH `0.2.1-alpha.3+` 以 `engines.dsh` 判定兼容;更早的 DSH 读取 `@deepseek-ai/dsh` peer 范围。 - Node `>=22.19.0`(DSH `0.2.x` 自身要求 Node `>=24.9`;桌面应用自带运行时)。 @@ -87,11 +88,11 @@ row 固定 `command: memtrace`(用 `MEMTRACE_BIN` 覆盖;零安装可整行 两条 Cordis 行,都由本包拥有: 1. **`dsh-plugin-memtrace`** — 读取 `skills/*/SKILL.md`,在 `apply` 时注册;卸载即注销。 -2. **`mcp-memtrace`** — 官方 MCP 客户端,`serverName: memtrace`,`memtrace mcp`,命令固定(`MEMTRACE_BIN`,否则 PATH 上的 `memtrace` —— 不会按 child 重复拉取 npx)。不带 workspace 旗标:`memtrace mcp` 以其工作目录为锚,打开仓库自己的 `.memdb`。`perWorkingDirectory: true` 让每次工具调用都在发起调用的 Session 工作目录里启动 child,每个项目因此有自己的 store(git worktree 解析到主仓库的 store)。这需要实现了该选项的 dsh-mcp-client;原版 dsh 会忽略该键,此时靠整行重述本 row 的 `cwd` 指定项目。 +2. **`mcp-memtrace`** — 官方 MCP 客户端,`serverName: memtrace`,`memtrace mcp`,命令固定(`MEMTRACE_BIN`,否则 PATH 上的 `memtrace` —— 不会按 child 重复拉取 npx)。不带 workspace 旗标:`memtrace mcp` 以其工作目录为锚,打开仓库自己的 `.memdb`。用于列工具的 child 运行在 row 的 `cwd`;`perWorkingDirectory: true` 让每次工具调用都在发起调用的 Session 工作目录里启动 child,每个项目因此有自己的 store,git worktree 上的 Session 也会解析到主仓库的 store。这需要实现了该选项的 dsh-mcp-client;原版 dsh 会忽略该键,此时整行重述本 row 并设 `cwd: <仓库根目录>`。 不会去改文件系统 skill provider 的 `config`(整行覆盖、后写赢)。运行时注册不会和其他 skill 包打架。 -`memtrace mcp` 打开由其工作目录锚定的 `.memdb`(`memtrace mcp --help` 的 project-editor 模式)。`perWorkingDirectory: true` 让每次工具调用都在发起调用的 Session 工作目录里启动 child,因此 git worktree 上的 Session 会解析到主仓库的 store。这需要实现了该选项的 dsh-mcp-client。原版 dsh 会保留这个未知键但忽略它,所有调用都落到 profile 目录里唯一的 child,而该目录没有 workspace owner;此时在 profile 的 `cordis.patch.yml` 里整行重述 `mcp-memtrace` 并设 `cwd: <仓库根目录>`(DSH 不做深度合并)。 +原版 dsh 会忽略 `perWorkingDirectory`:在 profile 的 `cordis.patch.yml` 里整行重述 `mcp-memtrace` 并设 `cwd: <仓库根目录>`(DSH 不做深度合并)。 ## 配置与权限 @@ -99,7 +100,7 @@ row 固定 `command: memtrace`(用 `MEMTRACE_BIN` 覆盖;零安装可整行 | --- | --- | | `MEMTRACE_BIN` | MCP 行使用的命令(绝对路径或命令),覆盖 PATH 上的 `memtrace` | -`perWorkingDirectory` 开启时按 Session 工作目录启动 `memtrace mcp`(读取仓库以建索引,`.memdb` 写在项目旁);原版 dsh 则用重述行的 `cwd`。本包只注册自己的 skill,不向 Memtrace 云端发送代码,图谱保存在本机。 +`MEMTRACE_BIN` 与 `perWorkingDirectory` 见「工作原理」;启动的 `memtrace mcp` 读取仓库建索引,`.memdb` 写在项目旁。本包只注册自己的 skill,不向 Memtrace 云端发送代码,图谱保存在本机。 ## 许可证 diff --git a/docs/02_architecture_constraints.md b/docs/02_architecture_constraints.md index 2fe0c84..7d8df1d 100644 --- a/docs/02_architecture_constraints.md +++ b/docs/02_architecture_constraints.md @@ -5,6 +5,6 @@ - Official `@deepseek-ai/*` packages are peer dependencies, never bundled. - DSH compatibility declared via `engines.dsh` `>=0.1.0-rc.6 <0.3.0-0` (decides on DSH `0.2.1-alpha.3+`); the `@deepseek-ai/dsh` peer range mirrors it for older DSH. - Patch rows must not overwrite another plugin's `config` (no deep merge). -- Bundle patch config stays literal: the 0.2.x patch composer mangles evaluated `!!js` values that return arrays (the mcp-memtrace row is static for this reason). +- Bundle patch config stays literal: the 0.2.x patch composer mangles evaluated `!!js` values that return arrays (values stay literal except the scalar command for this reason). - MCP child store identity: `memtrace mcp` anchors on its working directory and opens the repo's own `.memdb`; the `mcp-memtrace` row sets `perWorkingDirectory: true`, so each tool call runs in a child started in the calling Session's working directory (a git worktree resolves to the main repo's store). This needs a dsh-mcp-client that implements the option; a stock dsh ignores it, and a restated row's `cwd` sets the project. No shared named-workspace store; memtrace refuses cross-store indexing. - Node `>=22.19` (plugin floor; Harness `0.2.x` hosts themselves require `>=24.9`). diff --git a/docs/03_context_and_scope.md b/docs/03_context_and_scope.md index a6cf7a8..f85cf0f 100644 --- a/docs/03_context_and_scope.md +++ b/docs/03_context_and_scope.md @@ -11,7 +11,7 @@ C4Context System_Ext(memtrace, "Memtrace MCP", "Local code-intelligence graph server") Rel(dev, dsh, "asks the agent about the codebase") Rel(dsh, plugin, "loads bundle layer", "Cordis") - Rel(plugin, memtrace, "stdio MCP", "memtrace mcp / npx memtrace mcp") + Rel(plugin, memtrace, "stdio MCP", "memtrace mcp") ``` Scope: this package. It does not index code itself; Memtrace does. diff --git a/docs/04_solution_strategy.md b/docs/04_solution_strategy.md index e3975d8..7774693 100644 --- a/docs/04_solution_strategy.md +++ b/docs/04_solution_strategy.md @@ -3,4 +3,3 @@ 1. **Compose, don't reimplement.** MCP tools come from `@deepseek-ai/dsh-mcp-client` pointed at `memtrace mcp`. 2. **Register skills at runtime.** `ctx.skills.register()` avoids the wholesale-config trap on the filesystem skill provider. 3. **Plain ESM, no build.** Git installs work without a `prepare` script. -4. **npx fallback.** A machine without a global `memtrace` still gets the server via `npx -y memtrace mcp`. diff --git a/docs/06_runtime_view.md b/docs/06_runtime_view.md index 53ce98b..e98d6df 100644 --- a/docs/06_runtime_view.md +++ b/docs/06_runtime_view.md @@ -5,7 +5,7 @@ 1. Profile lists `dsh-plugin-memtrace` in `dsh.profile.bundles`. 2. Cordis applies `cordis.patch.yml`. 3. Skill plugin `apply()` registers every `skills/*/SKILL.md`. -4. MCP client spawns `npx -y memtrace mcp` (or `MEMTRACE_BIN mcp`). +4. The MCP client runs `MEMTRACE_BIN`, else `memtrace` from PATH; the listing child runs in the row `cwd`, and each tool call runs in a child in the Session's working directory (`perWorkingDirectory`). On a stock dsh, restate the row with `cwd: `. 5. Tools appear as `mcp__memtrace__find_symbol`, `mcp__memtrace__get_impact`, … ## Unload diff --git a/docs/07_deployment_view.md b/docs/07_deployment_view.md index faf12dd..acfdb37 100644 --- a/docs/07_deployment_view.md +++ b/docs/07_deployment_view.md @@ -8,4 +8,4 @@ dsh plugin --profile web add github:syncable-dev/dsh-plugin-memtrace or `dsh plugin --profile web add dsh-plugin-memtrace` from npm. -The MCP child runs in the session working directory so Memtrace sees the repo the agent is editing. +Per-Session cwd needs a dsh-mcp-client with `perWorkingDirectory`; each tool call then runs in the Session's working directory so Memtrace sees the repo the agent is editing. A stock dsh needs the row restated with `cwd`. diff --git a/docs/09_architecture_decisions/0001-official-mcp-client.md b/docs/09_architecture_decisions/0001-official-mcp-client.md index 7ccce5e..98abe36 100644 --- a/docs/09_architecture_decisions/0001-official-mcp-client.md +++ b/docs/09_architecture_decisions/0001-official-mcp-client.md @@ -10,6 +10,8 @@ Memtrace already speaks MCP (stdio `memtrace mcp`) for Claude, Cursor, Codex, an We will insert `@deepseek-ai/dsh-mcp-client` with `serverName: memtrace` and spawn `memtrace mcp` (npx fallback). Skills are a separate Cordis row registered via `ctx.skills.register`. +Note (0.3.0): the npx fallback was superseded — the row now runs `MEMTRACE_BIN`, else `memtrace` from PATH. + ## Consequences Tools show up as `mcp__memtrace__*`. We inherit DSH MCP reconnect and naming rules. We cannot rename tools to bare names without a second native registrar. diff --git a/docs/11_risks_and_technical_debt.md b/docs/11_risks_and_technical_debt.md index 8f76a34..df17b5a 100644 --- a/docs/11_risks_and_technical_debt.md +++ b/docs/11_risks_and_technical_debt.md @@ -3,5 +3,6 @@ | Priority | Risk | Mitigation | | --- | --- | --- | | P1 | First DSH turn can race MCP discovery | `failOnStartupError: false` + reconnect; README tells users to wait or send a second prompt | -| P2 | `npx -y memtrace mcp` is slow cold | Document `npm i -g memtrace` and `MEMTRACE_BIN` | +| P2 | `memtrace` missing from PATH: the MCP server never starts and its tools silently don't appear (`failOnStartupError: false`) | Document `npm i -g memtrace` and `MEMTRACE_BIN` | +| P2 | A stock dsh ignores `perWorkingDirectory`, so calls fail with "no workspace owner" | Restate the `mcp-memtrace` row with `cwd: `; ship the option upstream in dsh-mcp-client | | P3 | Skills snapshot can drift from the Memtrace installer | `npm run sync-skills` from the product monorepo | diff --git a/lib/load-skills.js b/lib/load-skills.js index 0f64302..03551ee 100644 --- a/lib/load-skills.js +++ b/lib/load-skills.js @@ -17,8 +17,6 @@ export function loadSkillsFrom(packageRoot) { skills.push({ ...parsed, path: skillPath, - directory, - resourceDirectory: directory, }) } diff --git a/test/bundled-skills.test.js b/test/bundled-skills.test.js index 549dd7b..fd2d29c 100644 --- a/test/bundled-skills.test.js +++ b/test/bundled-skills.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict' -import { dirname, join } from 'node:path' +import { dirname } from 'node:path' import { describe, it } from 'node:test' import { fileURLToPath } from 'node:url' import { loadSkillsFrom } from '../lib/load-skills.js' @@ -19,7 +19,6 @@ describe('bundled Memtrace skills', () => { for (const skill of skills) { assert.ok(skill.description.length > 20, skill.name) assert.ok(skill.body.includes('\n'), skill.name) - assert.equal(skill.directory, join(packageRoot, 'skills', skill.name)) } }) }) diff --git a/test/load-skills.test.js b/test/load-skills.test.js index d0b3d6e..5b1deaa 100644 --- a/test/load-skills.test.js +++ b/test/load-skills.test.js @@ -6,7 +6,7 @@ import { describe, it } from 'node:test' import { loadSkillsFrom } from '../lib/load-skills.js' describe('loadSkillsFrom', () => { - it('loads every SKILL.md bundle under skills/ and keeps directory resource bases', () => { + it('loads every SKILL.md bundle under skills/', () => { const root = mkdtempSync(join(tmpdir(), 'dsh-memtrace-skills-')) const firstDir = join(root, 'skills', 'memtrace-first') const searchDir = join(root, 'skills', 'memtrace-search') @@ -40,7 +40,6 @@ Search body. skills.map((skill) => skill.name).sort(), ['memtrace-first', 'memtrace-search'], ) - assert.equal(skills[0].resourceDirectory, join(root, 'skills', skills[0].name)) }) it('returns an empty list when the skills directory is missing', () => { diff --git a/test/manifest.test.js b/test/manifest.test.js index ee25b3c..13a39cd 100644 --- a/test/manifest.test.js +++ b/test/manifest.test.js @@ -19,27 +19,22 @@ describe('DSH bundle contract', () => { it('inserts the skill plugin and the official MCP client under stable ids', () => { const patch = readFileSync(join(packageRoot, 'cordis.patch.yml'), 'utf8') - assert.match(patch, /id:\s*dsh-plugin-memtrace/) - assert.match(patch, /name:\s*dsh-plugin-memtrace/) - assert.match(patch, /id:\s*mcp-memtrace/) - assert.match(patch, /name:\s*'@deepseek-ai\/dsh-mcp-client'/) - assert.match(patch, /serverName:\s*memtrace/) - assert.match(patch, /transport:\s*stdio/) - // Per-session working directory: the client starts one child in cwd for - // tool discovery, then routes each call to a child in the Session's - // directory. A static row-level cwd is not used (comments are ignored). - assert.match(patch, /perWorkingDirectory:\s*true/) - assert.doesNotMatch(patch.replace(/^#.*$/gm, ''), /^\s*cwd:/m) - // The 0.2.x patch composer mangles evaluated !!js values that return - // arrays (args became {"[object Object]": [...]}), so args stays literal - // while the command may evaluate a scalar. Comment lines are ignored. - assert.doesNotMatch(patch.replace(/^#.*$/gm, ''), /args:\s*!!js/) - // Per-project model: pinned command, no workspace flag — the host keys - // MCP children per Session working directory via perWorkingDirectory; - // a restated row's cwd is the stock-dsh fallback. - assert.match(patch, /command:\s*!!js process\.env\.MEMTRACE_BIN \|\| 'memtrace'/) - assert.doesNotMatch(patch.replace(/^#.*$/gm, ''), /--workspace/) - assert.doesNotMatch(patch, /workspace create/) + // Comment lines are ignored. Only the scalar command may evaluate !!js, + // because the 0.2.x composer mangles evaluated values that return arrays; + // perWorkingDirectory routes each tool call to the Session's directory. + const body = patch.replace(/^#.*$/gm, '') + assert.match(body, /id:\s*dsh-plugin-memtrace/) + assert.match(body, /name:\s*dsh-plugin-memtrace/) + assert.match(body, /id:\s*mcp-memtrace/) + assert.match(body, /name:\s*'@deepseek-ai\/dsh-mcp-client'/) + assert.match(body, /serverName:\s*memtrace/) + assert.match(body, /transport:\s*stdio/) + assert.match(body, /perWorkingDirectory:\s*true/) + assert.doesNotMatch(body, /^\s*cwd:/m) + assert.doesNotMatch(body, /args:\s*!!js/) + assert.match(body, /command:\s*!!js process\.env\.MEMTRACE_BIN \|\| 'memtrace'/) + assert.doesNotMatch(body, /--workspace/) + assert.doesNotMatch(body, /workspace create/) }) it('declares the DSH 0.2 compatibility contract: engines.dsh mirrors the peer range', () => { From d25b2d53780fb11d313ac6e9ff5f28e4b43e6616 Mon Sep 17 00:00:00 2001 From: magalz Date: Fri, 20 Nov 2026 20:42:02 -0300 Subject: [PATCH 3/3] chore: ignore the local .memtrace-workspace marker Co-Authored-By: Claude Opus 5.5 --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d96040d..67167ca 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules/ *.tgz coverage/ .memdb/ +.memtrace-workspace