@hilariouhiss/dsh-codegraph 1.0.0 → 1.0.1

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.
Files changed (3) hide show
  1. package/README.md +2 -10
  2. package/lib/index.js +14 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -50,22 +50,14 @@ dsh plugin --profile web remove @hilariouhiss/dsh-codegraph
50
50
 
51
51
  ## 已知问题与限制
52
52
 
53
- 当前实现是「MCP server 直连 + 静态引导」的最小可行集成,已知有以下问题:
53
+ 当前实现是「MCP server 直连 + 动态引导」的最小可行集成,已知有以下问题:
54
54
 
55
- 1. **模型必须每次手动传 `projectPath`(最大痛点)**:DSH 宿主是单实例、多会话(多工作区),而 mcp-client 的 `cwd` 是宿主面静态配置(`process.cwd()`)。`codegraph_explore` 无法默认指向「当前会话工作区」,模型每次调用都要自己填 `projectPath` = 当前工作区。若漏填,会查询 server 的默认目录(通常没有 `.codegraph/` 索引),返回误导性的「无索引/请用内置工具」提示。理想做法是包装一个能自动注入会话 `cwd` 的工具,或让 server 按会话定位项目。
55
+ 1. **模型仍需手动传 `projectPath`(部分缓解)**:DSH 宿主是单实例、多会话(多工作区),而 mcp-client 的 `cwd` 是宿主面静态配置(`process.cwd()`)。`codegraph_explore` 无法默认指向「当前会话工作区」,模型每次调用仍要自己填 `projectPath`。引导文本现已**动态注入当前会话工作区的绝对路径**,降低漏填/填错概率;但工具本身仍未自动注入。理想做法是包装一个能自动注入会话 `cwd` 的工具,或让 server 按会话定位项目。
56
56
 
57
57
  2. **自动同步只覆盖 server 默认目录的项目**:codegraph 的文件 watcher 只持续监视 MCP server 启动 `cwd` 对应的项目;经 `projectPath` 查询的其它项目没有持续 watcher,索引不会随编辑自动刷新,需手动 `codegraph sync` 保持最新(本插件未做任何同步封装)。
58
58
 
59
59
  3. **不自动建索引**:每个项目必须手动 `codegraph init` 一次;插件不代建。未初始化时工具返回「无索引」引导而非真实结果。
60
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
61
  ## 开发
70
62
 
71
63
  ```powershell
package/lib/index.js CHANGED
@@ -9,9 +9,14 @@ const GUIDANCE = [
9
9
  "call `mcp__codegraph__codegraph_explore` directly instead of grepping or reading files one by one; ",
10
10
  "it returns the relevant symbols' source, call paths, and impact in one call. ",
11
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.",
12
+ "If the tool reports no index, tell the user to run `codegraph init` in that project first. ",
13
+ "If the `mcp__codegraph__*` tool is not listed, the codegraph CLI is not installed or failed to start — check the DSH host logs.",
13
14
  ].join("");
14
15
 
16
+ function guidanceFor(cwd) {
17
+ return `${GUIDANCE} Current workspace: ${cwd}; pass it as \`projectPath\`.`;
18
+ }
19
+
15
20
  /**
16
21
  * Stdio config for the CodeGraph MCP server. `command` resolves `codegraph`
17
22
  * from the DSH host process's PATH (installed globally), and `cwd` is only the
@@ -36,10 +41,15 @@ export function codegraphConfig(cwd = process.cwd()) {
36
41
 
37
42
  /**
38
43
  * 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`.
44
+ * server (registering `mcp__codegraph__*` tools globally) and injects usage
45
+ * guidance whose text carries the current session's workspace path, so agents
46
+ * prefer it and pass the right `projectPath`.
41
47
  */
42
48
  export function apply(ctx) {
43
49
  ctx.plugin({ inject: mcpClientInject, apply: mcpClientApply }, codegraphConfig());
44
- ctx.systemPrompt.section({ name: "codegraph:guidance", order: 100, text: GUIDANCE });
50
+ ctx.systemPrompt.section({
51
+ name: "codegraph:guidance",
52
+ order: 100,
53
+ text: (context) => guidanceFor(context.scope?.session?.header?.cwd ?? process.cwd()),
54
+ });
45
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hilariouhiss/dsh-codegraph",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
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
5
  "keywords": [
6
6
  "dsh",