dsh-hiss-plugins 1.2.0 → 1.2.2

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
@@ -55,7 +55,8 @@ Plugins 页(侧边栏 **插件**)里多出一个 `dsh-hiss-plugins` 标签
55
55
  - 浏览器半是 **`lib/client.js`** —— 手写的 lazy-CJS bundle,没有构建步骤:`window.__ModuleLoader__.load({ id: "dsh-hiss-plugins", factory })` 只注册工厂,模块体(slot 注册、locale 字典)在首次被 require 时执行。`id` 必须逐字等于包名(客户端图里的行 id 就是包名)。
56
56
  - `package.json` 里 `dsh.client.platform = "web"`、`exports["./client"]` 指向 `lib/client.js`;客户端模块系统按 Loader 行扫描,**只有本包有行挂载,这个文件才会被送进浏览器**。
57
57
  - 标签注册进 Plugins 页声明的 `plugins.tab` list slot(`ctx.slots.inject("plugins.tab", …)`),排在页面自己的「已安装」标签之后;文案来自包内的 `locale/*.json`。
58
- - `exports.inject` 是浏览器侧**服务名**(`slots`、`locale`、`remote`、`remote.pluginManager`);远程调用形如 `ctx.remote.<命名空间>.<方法>`,命名空间就是 host 侧服务名。
58
+ - `exports.inject` 是浏览器侧**服务名**(`slots`、`locale`、`remote`、`remote.pluginManager`、`uiConversation`);远程调用形如 `ctx.remote.<命名空间>.<方法>`,命名空间就是 host 侧服务名。
59
+ - 浏览器半还注册 **`/mcp` 的 chat 节点投影**(`ctx.uiConversation.events.register` + `conversation.chat.node` 的零尺寸渲染器)。原因:DSH 在会话还没有 `turn/start` 时把整段对话当 blank 隐藏(chat 视图的 `isActive` 只认非 `command` 节点),只写 command 事件的 `/mcp` 在新会话里会“看不见”;报告的文本仍由 DSH 的通用 command 卡片渲染。
59
60
  - `dsh.client.inject` 列的是**其它浏览器半的包名**(`@deepseek-ai/dsh-api-remotes`、`@deepseek-ai/dsh-client-modules`)—— 浏览器侧的图依赖,不是 npm 依赖。
60
61
 
61
62
  ## git-bash 行为什么自带 realm 隔离
@@ -156,6 +157,8 @@ colgrep command:"init" / command:"status" / command:"clear"
156
157
  - **首轮即生效**:挂载发生在 `agent/created`(宿主会 await 这个监听器)里,会话第一次对话就能看到工具;插件 reload 时也会给已经活着的 agent 补挂一次。
157
158
  - **${VAR} 展开**:`${TOKEN}` / `${TOKEN:-默认值}` 在挂载时用宿主进程环境求值,`.mcp.json` 里不必写明文密钥。
158
159
  - **失败不致命**:坏 JSON、不支持的 transport、起不来的 server 都只影响它自己,打一条 warn,会话照常开。
160
+ - **`/mcp` 看状态**:在本项目的会话里执行 `/mcp`,逐条列出 `.mcp.json` 声明的 server 与其实时状态 —— `connected, N tools`(MCP 桥连上并同步工具后才注册工具)、`no tools`(没连上,或 server 本身不暴露工具)、`skipped`(条目映射不了)、`unusable`(宿主 MCP 桥的 schema 拒绝);另外报告本会话里来自项目外配置的 MCP 工具总数。状态读的是当前 agent 自己的工具表,所以列的是**此刻真正可用**的工具;命令不接受参数。
161
+ - **新会话里立即显示**:DSH 的 Web 客户端在会话还没有任何 turn 时把整段对话当 blank 隐藏(只有 `turn/start` 会清 `sessionListMetadata.blank`),而 `/mcp` 只写 `command/run`/`command/done`。浏览器半因此给 `/mcp` 注册了一个非 `command` 的**伴随节点**(`hiss-mcp-command`,零尺寸),chat 视图立即激活——不必再先发一条消息。
159
162
 
160
163
  `.mcp.json` 就是 Claude Code 的项目级 MCP 配置文件:
161
164
 
@@ -186,7 +189,7 @@ colgrep command:"init" / command:"status" / command:"clear"
186
189
 
187
190
  工作原理:`agent/created` → 会话 cwd → 向上找 `.mcp.json`(止于含 `.git` 的项目根)→ 解析 `mcpServers`、逐条映射成 `dsh-mcp-client` 的 config → 用宿主自己的 `McpClient.Config(...)` schema 校验 → `await agent.ctx.plugin(McpClient, config)` 挂进该 agent 的 scope。
188
191
 
189
- 验证:在某个项目根放一份 `.mcp.json`,重启 dsh,在该项目里开会话;问模型「列出你能用的 mcp 工具」,或直接调用 `mcp__<server>__<tool>`。宿主日志里能看到 `project-mcp: mounted N server(s) for <agent id>`。
192
+ 验证:在某个项目根放一份 `.mcp.json`,重启 dsh,在该项目里开会话;执行 `/mcp` 看每个 server 的实时状态,问模型「列出你能用的 mcp 工具」,或直接调用 `mcp__<server>__<tool>`。宿主日志里能看到 `project-mcp: mounted N server(s) for <agent id>`。
190
193
 
191
194
  安全边界:
192
195
 
@@ -198,6 +201,7 @@ colgrep command:"init" / command:"status" / command:"clear"
198
201
  2. **每个会话一套连接**:多会话同时开在同一项目会各起一份 MCP server 进程。
199
202
  3. **不支持 `sse`**:宿主 MCP 桥只支持 `stdio` 与 `streamable-http`,`sse` 条目会被跳过并告警。
200
203
  4. **只看 `.mcp.json`**:不读 `.dsh/mcp.yml`、用户层配置或 `~/.claude.json`。
204
+ 5. **`/mcp` 只列本项目声明的 server**:项目外(profile / preset 里)配置的 MCP server 只计入末尾的工具总数,不列名字 —— 宿主没有公开这些行的配置,公开的工具名也按设计不可反解出 server 名。
201
205
 
202
206
  ## 功能:git-bash
203
207
 
@@ -353,8 +357,8 @@ test/ node:test:<feature>/ 七个目录 + manifest / patch / c
353
357
  ## 发布(给维护者)
354
358
 
355
359
  ```powershell
356
- git tag dsh-hiss-plugins@1.2.0 # 必须与本目录 package.json 的 version 逐字一致
357
- git push origin dsh-hiss-plugins@1.2.0
360
+ git tag dsh-hiss-plugins@1.2.2 # 必须与本目录 package.json 的 version 逐字一致
361
+ git push origin dsh-hiss-plugins@1.2.2
358
362
  ```
359
363
 
360
364
  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`。
package/lib/client.js CHANGED
@@ -321,12 +321,56 @@ window.__ModuleLoader__.load({
321
321
  });
322
322
  }
323
323
 
324
- /** Services required by the tab registration and its Remote answers. */
324
+ /** Host command whose run this browser half projects into the chat view. */
325
+ const MCP_COMMAND = "mcp";
326
+ /**
327
+ * Chat node kind of the `/mcp` projection.
328
+ *
329
+ * DSH hides the whole transcript while a session has no turn (the chat view counts only
330
+ * non-command nodes as activity, and only a turn clears the session's blank flag), so in a
331
+ * never-messaged session the `/mcp` result — logged as `command/run` + `command/done` — would
332
+ * stay invisible until the first message starts a turn. Registering this non-command node is
333
+ * how DSH's own `ui-goal` keeps `/goal` visible; the report itself stays in the generic
334
+ * command card, which is why the renderer below draws nothing.
335
+ */
336
+ const MCP_NODE_KIND = "hiss-mcp-command";
337
+
338
+ /**
339
+ * Project one `/mcp` run as an empty chat node.
340
+ * Only `command/run` is claimed: `command/done` still renders through the generic command card,
341
+ * and every other command is untouched.
342
+ */
343
+ const mcpCommandDefinition = {
344
+ kind: MCP_NODE_KIND,
345
+ target: "chat",
346
+ match: (event) => event.type === "command/run" && event.data.name === MCP_COMMAND
347
+ ? { id: String(event.data.commandId), role: "start" }
348
+ : null,
349
+ start: (_context, match) => ({ seq: match.event.seq, commandId: match.event.data.commandId }),
350
+ buildViewNode: (context) => ({
351
+ key: context.key,
352
+ kind: MCP_NODE_KIND,
353
+ id: context.id,
354
+ target: "chat",
355
+ anchorSeq: context.state.seq - 0.1,
356
+ location: context.start?.location ?? { kind: "unresolved" },
357
+ visibility: "visible",
358
+ data: { commandId: context.state.commandId },
359
+ }),
360
+ };
361
+
362
+ /** Zero-size renderer: the node exists to keep the chat view active, not to draw the report. */
363
+ function McpCommandNodeView() {
364
+ return null;
365
+ }
366
+
367
+ /** Services required by the tab registration, its Remote answers, and the `/mcp` projection. */
325
368
  const inject = [
326
369
  "slots",
327
370
  "locale",
328
371
  "remote",
329
- "remote.pluginManager"
372
+ "remote.pluginManager",
373
+ "uiConversation"
330
374
  ];
331
375
 
332
376
  /**
@@ -339,6 +383,12 @@ window.__ModuleLoader__.load({
339
383
  en
340
384
  }), "hiss-plugins: dictionaries");
341
385
  const t = ctx.locale.bind(NS);
386
+ ctx.uiConversation.events.register(mcpCommandDefinition);
387
+ ctx.slots.inject("conversation.chat.node", () => ctx.slots.register({
388
+ name: "conversation.chat.node",
389
+ key: MCP_NODE_KIND,
390
+ locale: NS,
391
+ }, McpCommandNodeView));
342
392
  /**
343
393
  * Read the running profile's rows.
344
394
  * @returns one projected row per feature this package contributes.
@@ -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.2",
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",