@hilariouhiss/dsh-codegraph 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-codegraph contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # @hilariouhiss/dsh-codegraph
2
+
3
+ 把 [codegraph](https://github.com/colbymchenry/codegraph)(本地优先的代码图 / 知识图谱,让 AI agent 用「预建的符号·调用边·依赖图」回答代码结构问题,而非逐文件 grep)接入 DeepSeek Harness。
4
+
5
+ 本插件以 DSH **bundle 插件**形式,通过 DSH 内置的 MCP 客户端桥(`@deepseek-ai/dsh-mcp-client`)连接 CodeGraph 的 MCP server,注册 `mcp__codegraph__*` 工具,并注入一条轻量使用引导。安装后对 `web`、`headless` 等任意 profile 的所有会话生效。
6
+
7
+ ## 功能
8
+
9
+ - 注册 **`mcp__codegraph__codegraph_explore`** 工具:一次调用返回相关符号的逐字源码(按文件分组)、符号间调用链(含动态分派跳转)与影响范围(blast radius)。
10
+ - 注入系统提示词引导,让智能体对结构性问题(「X 如何工作」「X 如何到达 Y」「改某处会影响什么」)**优先直接调 `codegraph_explore`**,而不是 grep/逐文件读,并**传 `projectPath`** 指向当前工作区。
11
+
12
+ ## 前置要求
13
+
14
+ 1. 全局安装 CodeGraph CLI(`codegraph` 需在 DSH 宿主进程的 PATH 上):
15
+
16
+ ```powershell
17
+ npm i -g @colbymchenry/codegraph
18
+ # 或:irm https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.ps1 | iex
19
+ ```
20
+
21
+ 2. 每个项目首次建图(生成 `.codegraph/` 索引;之后 MCP server 的 watcher 自动增量同步):
22
+
23
+ ```powershell
24
+ cd <your-project>
25
+ codegraph init
26
+ ```
27
+
28
+ ## 安装
29
+
30
+ ```powershell
31
+ dsh plugin --profile web add @hilariouhiss/dsh-codegraph
32
+ ```
33
+
34
+ 把 `web` 换成你的 profile 名(例如 `headless`)。然后**重启 dsh**。
35
+
36
+ `dsh plugin` 会把本包安装进 profile 的 `node_modules`;因为 `package.json` 声明了 `dsh.bundle.patch`,profile 的 bundle 列表会自动追加 `@hilariouhiss/dsh-codegraph`,重启后插件行自动激活。
37
+
38
+ ## 验证
39
+
40
+ 1. 重启后,让模型回答一个代码结构问题(如「这个请求是怎么到达数据库的」),观察它调用 `mcp__codegraph__codegraph_explore` 且返回源码 + 调用链。
41
+ 2. 若某项目尚未建图,工具会返回「无索引」提示——在该项目跑一次 `codegraph init` 即可。
42
+
43
+ ## 卸载
44
+
45
+ ```powershell
46
+ dsh plugin --profile web remove @hilariouhiss/dsh-codegraph
47
+ ```
48
+
49
+ 然后重启 dsh。
50
+
51
+ ## 已知问题与限制
52
+
53
+ 当前实现是「MCP server 直连 + 静态引导」的最小可行集成,已知有以下问题:
54
+
55
+ 1. **模型必须每次手动传 `projectPath`(最大痛点)**:DSH 宿主是单实例、多会话(多工作区),而 mcp-client 的 `cwd` 是宿主面静态配置(`process.cwd()`)。`codegraph_explore` 无法默认指向「当前会话工作区」,模型每次调用都要自己填 `projectPath` = 当前工作区。若漏填,会查询 server 的默认目录(通常没有 `.codegraph/` 索引),返回误导性的「无索引/请用内置工具」提示。理想做法是包装一个能自动注入会话 `cwd` 的工具,或让 server 按会话定位项目。
56
+
57
+ 2. **自动同步只覆盖 server 默认目录的项目**:codegraph 的文件 watcher 只持续监视 MCP server 启动 `cwd` 对应的项目;经 `projectPath` 查询的其它项目没有持续 watcher,索引不会随编辑自动刷新,需手动 `codegraph sync` 保持最新(本插件未做任何同步封装)。
58
+
59
+ 3. **不自动建索引**:每个项目必须手动 `codegraph init` 一次;插件不代建。未初始化时工具返回「无索引」引导而非真实结果。
60
+
61
+ 4. **依赖全局 `codegraph` CLI**:插件只负责连 MCP,不安装、不校验 `codegraph`。若未全局安装,mcp-client 启动失败并重试后静默注销工具,模型看不到原因(只能查 DSH 日志)。
62
+
63
+ 5. **引导是静态文本**:`systemPrompt.section` 只能写死「传 `projectPath` = 你的工作区」,无法把当前工作区的绝对路径动态注入提示词。
64
+
65
+ 6. **未端到端验证**:尚未在真实 profile 里走完 `dsh plugin add` → 重启 → 实际调用 `mcp__codegraph__codegraph_explore` 的闭环(当前仅单元测试 + 按 codegraph 官方 stdio 配置对齐)。
66
+
67
+ 7. **遥测默认开启**:codegraph 的匿名遥测默认开(不采集代码/路径/查询内容);本插件未关闭。可用 `codegraph telemetry off` 或环境变量 `CODEGRAPH_TELEMETRY=0` 关闭。
68
+
69
+ ## 开发
70
+
71
+ ```powershell
72
+ pnpm install
73
+ pnpm test
74
+ ```
75
+
76
+ 结构:
77
+
78
+ ```
79
+ lib/index.js 插件入口:apply(ctx) 用 ctx.plugin 加载 mcp-client + 注入引导
80
+ cordis.patch.yml bundle patch:插入本插件的宿主行
81
+ test/ node:test 单元测试(config 组装、plugin 加载、引导注册)
82
+ ```
83
+
84
+ ## 发布(给维护者)
85
+
86
+ ```powershell
87
+ cd dsh-codegraph
88
+ pnpm install
89
+ pnpm test
90
+ npm login # 首次发布前登录 npm
91
+ npm publish # publishConfig.access 已设为 public
92
+ ```
93
+
94
+ `prepublishOnly` 会在每次发布前自动运行 `npm test`;发布新版本前记得递增 `package.json` 的 `version`。
95
+
96
+ ## 许可与来源
97
+
98
+ 本插件为 MIT 许可。它只通过 MCP 连接外部的 `codegraph` CLI,未内置 codegraph 源码;codegraph 本身来自 [colbymchenry/codegraph](https://github.com/colbymchenry/codegraph)(© Colby McHenry,MIT,其自身许可见上游仓库)。
99
+
100
+ > 提示:若日后升级 dsh 后 `@deepseek-ai/dsh-mcp-client` 的公开 API 发生变化,需同步更新本插件的依赖版本。
@@ -0,0 +1,12 @@
1
+ # @hilariouhiss/dsh-codegraph bundle patch: one self-referencing host row.
2
+ #
3
+ # `dsh plugin --profile <name> add @hilariouhiss/dsh-codegraph` installs this
4
+ # package into the profile; because it declares `dsh.bundle.patch`, the profile
5
+ # manifest appends it to the bundle list, and this patch is applied as a layer
6
+ # on boot. The row resolves `@hilariouhiss/dsh-codegraph` from the profile's own
7
+ # node_modules, so the plugin's `apply(ctx)` runs in the host plane: it loads
8
+ # the DSH MCP client bridge for the CodeGraph server (registering
9
+ # `mcp__codegraph__*` tools globally) and injects usage guidance.
10
+ - insert:
11
+ - id: codegraph
12
+ name: '@hilariouhiss/dsh-codegraph'
package/lib/index.js ADDED
@@ -0,0 +1,45 @@
1
+ import { apply as mcpClientApply, inject as mcpClientInject } from "@deepseek-ai/dsh-mcp-client";
2
+
3
+ export const name = "codegraph";
4
+ export const inject = ["systemPrompt"];
5
+
6
+ const GUIDANCE = [
7
+ "CodeGraph (semantic code intelligence) is available through the `mcp__codegraph__codegraph_explore` tool. ",
8
+ "For structural questions about the codebase — how a component works, how X reaches Y, the blast radius of a change — ",
9
+ "call `mcp__codegraph__codegraph_explore` directly instead of grepping or reading files one by one; ",
10
+ "it returns the relevant symbols' source, call paths, and impact in one call. ",
11
+ "Always pass `projectPath` as the workspace directory you are working in (or a subdirectory that has a `.codegraph/` index). ",
12
+ "If the tool reports no index, tell the user to run `codegraph init` in that project first.",
13
+ ].join("");
14
+
15
+ /**
16
+ * Stdio config for the CodeGraph MCP server. `command` resolves `codegraph`
17
+ * from the DSH host process's PATH (installed globally), and `cwd` is only the
18
+ * server's default project — the model always passes `projectPath` to target
19
+ * the actual workspace.
20
+ *
21
+ * @param {string} [cwd] default project directory for the spawned server.
22
+ * @returns {import("@deepseek-ai/dsh-mcp-client").StdioConfig}
23
+ */
24
+ export function codegraphConfig(cwd = process.cwd()) {
25
+ return {
26
+ transport: "stdio",
27
+ serverName: "codegraph",
28
+ command: "codegraph",
29
+ args: ["serve", "--mcp"],
30
+ env: {},
31
+ cwd,
32
+ toolCallTimeoutMs: 120000,
33
+ failOnStartupError: false,
34
+ };
35
+ }
36
+
37
+ /**
38
+ * DSH plugin entry point. Loads the DSH MCP client bridge for the CodeGraph
39
+ * server (registering `mcp__codegraph__*` tools globally) and injects a small
40
+ * usage guidance section so agents prefer it and pass `projectPath`.
41
+ */
42
+ export function apply(ctx) {
43
+ ctx.plugin({ inject: mcpClientInject, apply: mcpClientApply }, codegraphConfig());
44
+ ctx.systemPrompt.section({ name: "codegraph:guidance", order: 100, text: GUIDANCE });
45
+ }
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@hilariouhiss/dsh-codegraph",
3
+ "version": "1.0.0",
4
+ "description": "CodeGraph — semantic code intelligence (MCP) for DeepSeek Harness. Adds codegraph_explore so agents answer structural code questions from a pre-built code graph.",
5
+ "keywords": [
6
+ "dsh",
7
+ "deepseek-harness",
8
+ "dsh-plugin",
9
+ "codegraph",
10
+ "code-graph",
11
+ "code-intelligence",
12
+ "mcp"
13
+ ],
14
+ "license": "MIT",
15
+ "author": {
16
+ "name": "dsh-codegraph contributors"
17
+ },
18
+ "homepage": "https://github.com/hilariouhiss/dsh-hiss-plugins/tree/main/dsh-codegraph",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/hilariouhiss/dsh-hiss-plugins.git",
22
+ "directory": "dsh-codegraph"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "type": "module",
28
+ "main": "./lib/index.js",
29
+ "exports": {
30
+ ".": "./lib/index.js",
31
+ "./package.json": "./package.json"
32
+ },
33
+ "files": [
34
+ "lib/",
35
+ "cordis.patch.yml",
36
+ "README.md",
37
+ "LICENSE"
38
+ ],
39
+ "dependencies": {
40
+ "@deepseek-ai/dsh-mcp-client": "0.1.1-rc.2"
41
+ },
42
+ "dsh": {
43
+ "bundle": {
44
+ "patch": "./cordis.patch.yml"
45
+ }
46
+ },
47
+ "engines": {
48
+ "node": ">=20"
49
+ },
50
+ "scripts": {
51
+ "test": "node --test"
52
+ }
53
+ }