dsh-hiss-plugins 1.2.0 → 1.2.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.
package/README.md CHANGED
@@ -156,6 +156,7 @@ colgrep command:"init" / command:"status" / command:"clear"
156
156
  - **首轮即生效**:挂载发生在 `agent/created`(宿主会 await 这个监听器)里,会话第一次对话就能看到工具;插件 reload 时也会给已经活着的 agent 补挂一次。
157
157
  - **${VAR} 展开**:`${TOKEN}` / `${TOKEN:-默认值}` 在挂载时用宿主进程环境求值,`.mcp.json` 里不必写明文密钥。
158
158
  - **失败不致命**:坏 JSON、不支持的 transport、起不来的 server 都只影响它自己,打一条 warn,会话照常开。
159
+ - **`/mcp` 看状态**:在本项目的会话里执行 `/mcp`,逐条列出 `.mcp.json` 声明的 server 与其实时状态 —— `connected, N tools`(MCP 桥连上并同步工具后才注册工具)、`no tools`(没连上,或 server 本身不暴露工具)、`skipped`(条目映射不了)、`unusable`(宿主 MCP 桥的 schema 拒绝);另外报告本会话里来自项目外配置的 MCP 工具总数。状态读的是当前 agent 自己的工具表,所以列的是**此刻真正可用**的工具;命令不接受参数。
159
160
 
160
161
  `.mcp.json` 就是 Claude Code 的项目级 MCP 配置文件:
161
162
 
@@ -186,7 +187,7 @@ colgrep command:"init" / command:"status" / command:"clear"
186
187
 
187
188
  工作原理:`agent/created` → 会话 cwd → 向上找 `.mcp.json`(止于含 `.git` 的项目根)→ 解析 `mcpServers`、逐条映射成 `dsh-mcp-client` 的 config → 用宿主自己的 `McpClient.Config(...)` schema 校验 → `await agent.ctx.plugin(McpClient, config)` 挂进该 agent 的 scope。
188
189
 
189
- 验证:在某个项目根放一份 `.mcp.json`,重启 dsh,在该项目里开会话;问模型「列出你能用的 mcp 工具」,或直接调用 `mcp__<server>__<tool>`。宿主日志里能看到 `project-mcp: mounted N server(s) for <agent id>`。
190
+ 验证:在某个项目根放一份 `.mcp.json`,重启 dsh,在该项目里开会话;执行 `/mcp` 看每个 server 的实时状态,问模型「列出你能用的 mcp 工具」,或直接调用 `mcp__<server>__<tool>`。宿主日志里能看到 `project-mcp: mounted N server(s) for <agent id>`。
190
191
 
191
192
  安全边界:
192
193
 
@@ -198,6 +199,7 @@ colgrep command:"init" / command:"status" / command:"clear"
198
199
  2. **每个会话一套连接**:多会话同时开在同一项目会各起一份 MCP server 进程。
199
200
  3. **不支持 `sse`**:宿主 MCP 桥只支持 `stdio` 与 `streamable-http`,`sse` 条目会被跳过并告警。
200
201
  4. **只看 `.mcp.json`**:不读 `.dsh/mcp.yml`、用户层配置或 `~/.claude.json`。
202
+ 5. **`/mcp` 只列本项目声明的 server**:项目外(profile / preset 里)配置的 MCP server 只计入末尾的工具总数,不列名字 —— 宿主没有公开这些行的配置,公开的工具名也按设计不可反解出 server 名。
201
203
 
202
204
  ## 功能:git-bash
203
205
 
@@ -353,8 +355,8 @@ test/ node:test:<feature>/ 七个目录 + manifest / patch / c
353
355
  ## 发布(给维护者)
354
356
 
355
357
  ```powershell
356
- git tag dsh-hiss-plugins@1.2.0 # 必须与本目录 package.json 的 version 逐字一致
357
- git push origin dsh-hiss-plugins@1.2.0
358
+ git tag dsh-hiss-plugins@1.2.1 # 必须与本目录 package.json 的 version 逐字一致
359
+ git push origin dsh-hiss-plugins@1.2.1
358
360
  ```
359
361
 
360
362
  CI(`.github/workflows/publish.yml`,Windows runner)解析 tag、跑全量测试,再用 **npm trusted publishing(OIDC,无需任何 token)** 发布;包内 `prepublishOnly` 会再跑一次 `npm test`。手工发布:`npm publish`(`publishConfig.access` 已设为 public),发版前先 `node ../scripts/smoke-profile.mjs` 走一遍真实安装 + 真启动。发布新版本前记得递增 `package.json` 的 `version`。
@@ -1,5 +1,6 @@
1
1
  import * as McpClient from "@deepseek-ai/dsh-mcp-client";
2
2
  import { findConfigPath, loadServers } from "./config.js";
3
+ import { countTools, renderStatus } from "./status.js";
3
4
 
4
5
  export const name = "project-mcp";
5
6
  export const inject = ["agents"];
@@ -63,6 +64,81 @@ export async function mountProjectMcp(ctx, agent) {
63
64
  return mounted;
64
65
  }
65
66
 
67
+ /**
68
+ * Register the `/mcp` command beside the mount wiring.
69
+ *
70
+ * Mounting does not need `commands` or `tools`, so the command is registered
71
+ * through `ctx.inject`: a host missing either service loses the status command,
72
+ * never the mount. Both are optional host services from this row's point of view.
73
+ *
74
+ * @param {import("@deepseek-ai/cordis").Context} ctx - the host context.
75
+ */
76
+ function registerStatusCommand(ctx) {
77
+ ctx.inject(["commands", "tools"], (commandCtx) => {
78
+ commandCtx.commands.register({
79
+ name: "mcp",
80
+ description: "Show this project's MCP servers and their status",
81
+ handler: (invocation) => runMcp(commandCtx, invocation),
82
+ });
83
+ });
84
+ }
85
+
86
+ /**
87
+ * Report the session project's MCP servers and which of them are live.
88
+ *
89
+ * Liveness comes from the agent's own tool registry, not from the mount attempt:
90
+ * the bridge registers a server's tools only after a successful connect and tool
91
+ * sync, and removes them when the reconnect budget runs out. A declared server
92
+ * with no tools is therefore not connected (or genuinely exposes none); the host
93
+ * log has the reason.
94
+ *
95
+ * @param {object} ctx - host context carrying `tools`.
96
+ * @param {object} invocation - the command invocation.
97
+ * @returns {Promise<{ kind: "success" | "error", text: string }>} the command result.
98
+ */
99
+ async function runMcp(ctx, invocation) {
100
+ if (invocation.rawInput.trim() !== "") return { kind: "error", text: "Usage: /mcp (no arguments)" };
101
+ const cwd = invocation.agent?.session?.header?.cwd;
102
+ if (typeof cwd !== "string" || cwd === "") {
103
+ return { kind: "error", text: "No session working directory; no project MCP servers are mounted." };
104
+ }
105
+ const toolNames = ctx.tools.schemas(invocation.agent).map((schema) => schema.name);
106
+ const configPath = await findConfigPath(cwd);
107
+ if (configPath === undefined) {
108
+ return { kind: "success", text: renderStatus({ cwd, otherTools: countTools(toolNames, []).other }) };
109
+ }
110
+ let loaded;
111
+ try {
112
+ loaded = await loadServers(configPath, cwd);
113
+ } catch (error) {
114
+ return { kind: "error", text: message(error) };
115
+ }
116
+ const accepted = [];
117
+ const invalid = [];
118
+ for (const { serverName, spec } of loaded.servers) {
119
+ try {
120
+ // Re-judge the entry with the same schema the mount used, so the report
121
+ // never claims a server is fine when the bridge would have refused it.
122
+ McpClient.Config(spec);
123
+ accepted.push(serverName);
124
+ } catch (error) {
125
+ invalid.push({ serverName, reason: message(error) });
126
+ }
127
+ }
128
+ const { tools, other } = countTools(toolNames, accepted);
129
+ return {
130
+ kind: "success",
131
+ text: renderStatus({
132
+ cwd,
133
+ configPath,
134
+ servers: accepted.map((serverName) => ({ serverName, tools: tools.get(serverName) })),
135
+ invalid,
136
+ skipped: loaded.skipped,
137
+ otherTools: other,
138
+ }),
139
+ };
140
+ }
141
+
66
142
  /**
67
143
  * Mount the project's servers for every agent whose session directory declares
68
144
  * them. The registration is awaited by the agent registry before creation
@@ -82,4 +158,5 @@ export function apply(ctx) {
82
158
  ctx.on("agent/created", ({ agent }) => wire(agent));
83
159
  // A reload mid-session must reach agents that are already live.
84
160
  for (const agent of ctx.agents.list()) void wire(agent);
161
+ registerStatusCommand(ctx);
85
162
  }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * The `/mcp` report: pure formatting and tool attribution, so the command seam in
3
+ * `index.js` stays thin and every branch is testable without a host.
4
+ *
5
+ * @module dsh-hiss-plugins/project-mcp/status
6
+ */
7
+
8
+ /** Prefix the MCP bridge puts on every tool it registers. */
9
+ const MCP_PREFIX = "mcp__";
10
+
11
+ /**
12
+ * Count the live MCP tools each declared server owns.
13
+ *
14
+ * The bridge names a tool `mcp__<serverName>__<rawName>` and never parses that
15
+ * name back, because both halves may contain underscores. Attribution here is a
16
+ * prefix match against the names this project actually declares; when two names
17
+ * both match (a declared `foo` and `foo__bar`), the longer one owns the tool.
18
+ * Everything else with the bridge prefix belongs to a server configured outside
19
+ * this project.
20
+ *
21
+ * @param {string[]} toolNames - names visible to the session's agent.
22
+ * @param {string[]} serverNames - server names this project declares.
23
+ * @returns {{ tools: Map<string, number>, other: number }} the per-server tool
24
+ * counts and how many bridge tools no declared server owns.
25
+ */
26
+ export function countTools(toolNames, serverNames) {
27
+ const tools = new Map(serverNames.map((serverName) => [serverName, 0]));
28
+ const longestFirst = [...serverNames].sort((left, right) => right.length - left.length);
29
+ let other = 0;
30
+ for (const toolName of toolNames) {
31
+ if (!toolName.startsWith(MCP_PREFIX)) continue;
32
+ const owner = longestFirst.find((serverName) => toolName.startsWith(`${MCP_PREFIX}${serverName}__`));
33
+ if (owner === undefined) other += 1;
34
+ else tools.set(owner, tools.get(owner) + 1);
35
+ }
36
+ return { tools, other };
37
+ }
38
+
39
+ /**
40
+ * Append the session-wide MCP tool count, when there is one to report.
41
+ * @param {string} text - the project-scoped report.
42
+ * @param {number} other - bridge tools from servers declared outside this project.
43
+ * @returns {string} the report, with the extra line when it applies.
44
+ */
45
+ function withOther(text, other) {
46
+ if (other === 0) return text;
47
+ return `${text}\n\nOther MCP tools in this session: ${other} (servers configured outside this project).`;
48
+ }
49
+
50
+ /**
51
+ * Format the `/mcp` report.
52
+ *
53
+ * @param {object} report - what the command observed.
54
+ * @param {string} report.cwd - the session's working directory.
55
+ * @param {string} [report.configPath] - the project's `.mcp.json`, when one governs the session.
56
+ * @param {{ serverName: string, tools: number }[]} [report.servers] - servers the bridge accepted.
57
+ * @param {{ serverName: string, reason: string }[]} [report.invalid] - accepted entries the bridge schema refused.
58
+ * @param {{ serverName: string, reason: string }[]} [report.skipped] - entries that could not be mapped.
59
+ * @param {number} [report.otherTools] - bridge tools from servers not declared here.
60
+ * @returns {string} the command text.
61
+ */
62
+ export function renderStatus({ cwd, configPath, servers = [], invalid = [], skipped = [], otherTools = 0 }) {
63
+ if (configPath === undefined) {
64
+ return withOther(`No .mcp.json found for this project (${cwd}).`, otherTools);
65
+ }
66
+ const lines = [`MCP servers for ${configPath}:`];
67
+ if (servers.length + invalid.length + skipped.length === 0) lines.push("- none declared");
68
+ for (const { serverName, tools } of servers) {
69
+ lines.push(
70
+ tools === 0
71
+ ? `- ${serverName}: no tools (not connected, or the server exposes none)`
72
+ : `- ${serverName}: connected, ${tools} tool${tools === 1 ? "" : "s"}`,
73
+ );
74
+ }
75
+ for (const { serverName, reason } of invalid) lines.push(`- ${serverName}: unusable - ${reason}`);
76
+ for (const { serverName, reason } of skipped) lines.push(`- ${serverName}: skipped - ${reason}`);
77
+ return withOther(lines.join("\n"), otherTools);
78
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-hiss-plugins",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "dsh-hiss-plugins — one DeepSeek Harness bundle carrying seven independently switchable plugins (colgrep, codegraph, project-mcp, git-bash, superpowers, ponytail, init) plus a management tab in the Plugins page.",
5
5
  "keywords": [
6
6
  "dsh",