dsh-hiss-plugins 1.1.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
@@ -1,12 +1,12 @@
1
1
  # dsh-hiss-plugins
2
2
 
3
- 一个 DeepSeek Harness **bundle 插件**,把六个功能装在一个包里:**colgrep**(语义代码检索)、**codegraph**(代码图 MCP)、**project-mcp**(项目 `.mcp.json`)、**git-bash**(Windows 上的 Git Bash shell)、**superpowers**(superpowers 技能常驻引导)、**ponytail**(ponytail 采纳提示与 `/ponytail` 等级切换)。六个功能各占一条顶层行,可以在 **Plugins 页**里单独开关;包还带一个管理标签,就挂在那个页面上。
3
+ 一个 DeepSeek Harness **bundle 插件**,把七个功能装在一个包里:**colgrep**(语义代码检索)、**codegraph**(代码图 MCP)、**project-mcp**(项目 `.mcp.json`)、**git-bash**(Windows 上的 Git Bash shell)、**superpowers**(superpowers 技能常驻引导)、**ponytail**(ponytail 采纳提示与 `/ponytail` 等级切换)、**init**(读项目生成 `AGENTS.md`)。七个功能各占一条顶层行,可以在 **Plugins 页**里单独开关;包还带一个管理标签,就挂在那个页面上。
4
4
 
5
5
  安装后对 `web`、`headless` 等任意 profile 的**所有 preset、所有会话**生效。
6
6
 
7
- ## 七条行与六个开关
7
+ ## 八条行与七个开关
8
8
 
9
- `cordis.patch.yml` 只做一件事:`insert` 七条**顶层行**。宿主用 `name`(模块说明符)解析模块,用 `id` 记住开关状态。
9
+ `cordis.patch.yml` 只做一件事:`insert` 八条**顶层行**。宿主用 `name`(模块说明符)解析模块,用 `id` 记住开关状态。
10
10
 
11
11
  | 行 id | 模块 | 作用 | 默认 |
12
12
  |---|---|---|---|
@@ -17,8 +17,9 @@
17
17
  | `dsh-hiss-plugins-gitbash` | `dsh-hiss-plugins/gitbash` | Windows 上接入 Git Bash:提供 `ctx.shell` + 宿主 `bash` 工具 | 非 Windows 关 |
18
18
  | `dsh-hiss-plugins-superpowers` | `dsh-hiss-plugins/superpowers` | superpowers 技能常驻引导:任何回复前先检查有没有适用的技能,有就先加载(技能集本身由 DSH 原生发现) | 开 |
19
19
  | `dsh-hiss-plugins-ponytail` | `dsh-hiss-plugins/ponytail` | ponytail 采纳提示(随等级变化)+ 宿主 `/ponytail` 等级命令 | 开 |
20
+ | `dsh-hiss-plugins-init` | `dsh-hiss-plugins/init` | 宿主 `/init` 命令:读项目、生成/更新 `AGENTS.md` | 开 |
20
21
 
21
- **六条功能行就是 Plugins 页里那六个开关。** 载体行不在标签的开关列表里 —— 它是空的 host 半,但只有它在,浏览器半才会被送进页面;关掉它,管理标签本身就没了。
22
+ **七条功能行就是 Plugins 页里那七个开关。** 载体行不在标签的开关列表里 —— 它是空的 host 半,但只有它在,浏览器半才会被送进页面;关掉它,管理标签本身就没了。
22
23
 
23
24
  为什么必须是顶层行:插件管理器只为「组合后的 patch 里存在同 `id`、同 `name`,且挂载后父 entry 就是 profile 的 `include`」的行持久化开关。包在 `cordis:group` 里的子行在 `listPlugins()` 里被判为 `unaddressable`,**永远不会有开关**。所以这里没有组:git-bash 行把 realm 隔离写在自己身上(见下)。
24
25
 
@@ -30,7 +31,7 @@
30
31
  - 宿主把 `{ id: <行 id>, disabled: <bool> }` 覆盖写进 **profile 自己的** `cordis.patch.yml`(保留注释、原子写)—— 只影响这个 profile,不动包内的 `cordis.patch.yml`,所以升级/重装不会丢开关。
31
32
  - **带 HMR 的 profile 立即生效**(远程结果 `application: "applied"`);**没有 HMR 的 profile 返回 `application: "restart-required"`(`restartReason: "no-hmr"`),重启 dsh 才生效**。
32
33
  - 行不可开关时,`listPlugins()` 会给出 `readOnlyReason`:`unaddressable`(不是顶层行 / 名字对不上)或 `management-required`(插件管理器自己的行或受保护模块)。
33
- - 关掉一条功能行只是让那条行不激活:另外五条行不受影响,管理标签仍在(载体行开着)。
34
+ - 关掉一条功能行只是让那条行不激活:另外六条行不受影响,管理标签仍在(载体行开着)。
34
35
 
35
36
  ## 安装 / 卸载
36
37
 
@@ -39,7 +40,7 @@ dsh plugin --profile web add dsh-hiss-plugins
39
40
  # 或从本仓 checkout:dsh plugin --profile web add link:./dsh-hiss-plugins
40
41
  ```
41
42
 
42
- 把 `web` 换成你的 profile 名(例如 `headless`),然后**重启 dsh**。`dsh plugin` 会把本包装进 profile 的 `node_modules`;因为 `package.json` 声明了 `dsh.bundle.patch`,profile 的 bundle 列表会自动追加 `dsh-hiss-plugins`,重启后七条行一起激活。
43
+ 把 `web` 换成你的 profile 名(例如 `headless`),然后**重启 dsh**。`dsh plugin` 会把本包装进 profile 的 `node_modules`;因为 `package.json` 声明了 `dsh.bundle.patch`,profile 的 bundle 列表会自动追加 `dsh-hiss-plugins`,重启后八条行一起激活。
43
44
 
44
45
  ```powershell
45
46
  dsh plugin --profile web remove dsh-hiss-plugins
@@ -49,7 +50,7 @@ dsh plugin --profile web remove dsh-hiss-plugins
49
50
 
50
51
  ## 管理标签(浏览器半)
51
52
 
52
- Plugins 页(侧边栏 **插件**)里多出一个 `dsh-hiss-plugins` 标签,列出上面六条功能行与它们的开关。
53
+ Plugins 页(侧边栏 **插件**)里多出一个 `dsh-hiss-plugins` 标签,列出上面七条功能行与它们的开关。
53
54
 
54
55
  - 浏览器半是 **`lib/client.js`** —— 手写的 lazy-CJS bundle,没有构建步骤:`window.__ModuleLoader__.load({ id: "dsh-hiss-plugins", factory })` 只注册工厂,模块体(slot 注册、locale 字典)在首次被 require 时执行。`id` 必须逐字等于包名(客户端图里的行 id 就是包名)。
55
56
  - `package.json` 里 `dsh.client.platform = "web"`、`exports["./client"]` 指向 `lib/client.js`;客户端模块系统按 Loader 行扫描,**只有本包有行挂载,这个文件才会被送进浏览器**。
@@ -155,6 +156,7 @@ colgrep command:"init" / command:"status" / command:"clear"
155
156
  - **首轮即生效**:挂载发生在 `agent/created`(宿主会 await 这个监听器)里,会话第一次对话就能看到工具;插件 reload 时也会给已经活着的 agent 补挂一次。
156
157
  - **${VAR} 展开**:`${TOKEN}` / `${TOKEN:-默认值}` 在挂载时用宿主进程环境求值,`.mcp.json` 里不必写明文密钥。
157
158
  - **失败不致命**:坏 JSON、不支持的 transport、起不来的 server 都只影响它自己,打一条 warn,会话照常开。
159
+ - **`/mcp` 看状态**:在本项目的会话里执行 `/mcp`,逐条列出 `.mcp.json` 声明的 server 与其实时状态 —— `connected, N tools`(MCP 桥连上并同步工具后才注册工具)、`no tools`(没连上,或 server 本身不暴露工具)、`skipped`(条目映射不了)、`unusable`(宿主 MCP 桥的 schema 拒绝);另外报告本会话里来自项目外配置的 MCP 工具总数。状态读的是当前 agent 自己的工具表,所以列的是**此刻真正可用**的工具;命令不接受参数。
158
160
 
159
161
  `.mcp.json` 就是 Claude Code 的项目级 MCP 配置文件:
160
162
 
@@ -185,7 +187,7 @@ colgrep command:"init" / command:"status" / command:"clear"
185
187
 
186
188
  工作原理:`agent/created` → 会话 cwd → 向上找 `.mcp.json`(止于含 `.git` 的项目根)→ 解析 `mcpServers`、逐条映射成 `dsh-mcp-client` 的 config → 用宿主自己的 `McpClient.Config(...)` schema 校验 → `await agent.ctx.plugin(McpClient, config)` 挂进该 agent 的 scope。
187
189
 
188
- 验证:在某个项目根放一份 `.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>`。
189
191
 
190
192
  安全边界:
191
193
 
@@ -197,6 +199,7 @@ colgrep command:"init" / command:"status" / command:"clear"
197
199
  2. **每个会话一套连接**:多会话同时开在同一项目会各起一份 MCP server 进程。
198
200
  3. **不支持 `sse`**:宿主 MCP 桥只支持 `stdio` 与 `streamable-http`,`sse` 条目会被跳过并告警。
199
201
  4. **只看 `.mcp.json`**:不读 `.dsh/mcp.yml`、用户层配置或 `~/.claude.json`。
202
+ 5. **`/mcp` 只列本项目声明的 server**:项目外(profile / preset 里)配置的 MCP server 只计入末尾的工具总数,不列名字 —— 宿主没有公开这些行的配置,公开的工具名也按设计不可反解出 server 名。
200
203
 
201
204
  ## 功能:git-bash
202
205
 
@@ -306,6 +309,22 @@ colgrep command:"init" / command:"status" / command:"clear"
306
309
 
307
310
  验证:`/ponytail ultra` 后给一个编码任务,模型应加载 `ponytail` 技能并按 ultra 档执行;`/ponytail off` 后该提示词段变空。
308
311
 
312
+ ## 功能:init(读项目生成 AGENTS.md)
313
+
314
+ 注册宿主命令 **`/init`**:把一条固定的、面向仓库调研的指令作为持久 user 消息交给模型,让智能体先读项目、再在项目根写 `AGENTS.md`。插件本身不读文件、不生成内容 —— 阅读、检索、写入都走智能体已有的工具,指令的质量就是功能的全部。
315
+
316
+ - **目标位置**:从会话工作目录向上找最近的、含 `.git` 的祖先目录作为项目根,写 `<项目根>/AGENTS.md`;找不到 `.git` 时用工作目录本身。
317
+ - **已有文件按增量合并**:先读 `AGENTS.md`,保留仍然正确的内容与维护者手写的规则,只删除错误或重复的部分并说明删了什么。没有 `AGENTS.md` 但有 `CLAUDE.md` / `AGENT.md` 时,读它作为上下文、新建 `AGENTS.md`,不改写旧文件。
318
+ - **命令必须有证据**:只允许记录 manifest、脚本、Makefile、CI 文件或文档里真实存在的命令;提示词明确禁止编造命令/路径/脚本名/版本,也禁止为了“发现”事实去跑安装、构建、测试、网络或破坏性命令。
319
+ - **结构**:项目概览、安装/首次运行、构建/测试/lint(含单测跑法)、架构地图、仓库特有约定、测试要求、Git/PR 规则、安全与陷阱;没有内容的段直接省略。目标 80–150 行,约 200 行是硬上限;用仓库现有文档的语言写;不写泛泛而谈的建议、不抄 README、不含密钥或个人路径。
320
+ - **完成前自检**:重新从磁盘读文件,逐条核对命令、路径、环境变量和配置名;确认文件回答了“怎么装、怎么验、核心代码在哪、什么不能碰”,并报告无法确认或刻意省略的内容。
321
+ - 命令**不接受参数**(`/init foo` 返回 `Usage: /init (no arguments)`),也不提交任何改动。
322
+ - 提示词在 `lib/init/prompt.js`(纯逻辑、无宿主导入),命令接缝在 `lib/init/index.js`(`commands` + `workingDirectory`,经 `invocation.agent.followup(createUserMessage(...))` 注入)。
323
+
324
+ 前置要求:无 —— 只用宿主已有的 `commands`、`workingDirectory` 服务,以及 `@deepseek-ai/dsh-llm` 的 `createUserMessage`。
325
+
326
+ 验证:在任意项目里执行 `/init`,模型应开始读仓库并写出 `AGENTS.md`;下一个会话由 DSH 的 `dsh-agent-instructions` 自动加载它。
327
+
309
328
  ## 开发与测试
310
329
 
311
330
  ```powershell
@@ -316,8 +335,8 @@ pnpm test # 在包目录内也可:node --test-isolation=none --test
316
335
  结构:
317
336
 
318
337
  ```text
319
- package.json 七条行的 bundle 声明(dsh.bundle.patch)+ 浏览器半声明(dsh.client)+ exports/files
320
- cordis.patch.yml 七条顶层行(载体 + 六个功能)
338
+ package.json 八条行的 bundle 声明(dsh.bundle.patch)+ 浏览器半声明(dsh.client)+ exports/files
339
+ cordis.patch.yml 八条顶层行(载体 + 七个功能)
321
340
  lib/index.js 载体行:空 host 半
322
341
  lib/client.js 浏览器半:Plugins 页管理标签(手写 lazy-CJS,无构建步骤)
323
342
  lib/colgrep/ colgrep 工具
@@ -326,17 +345,18 @@ lib/project-mcp/ lib/config.js 纯逻辑(无宿主依赖)+ lib/index.js
326
345
  lib/gitbash/ lib/resolve.js 纯逻辑 + lib/gitbash-executor.js 执行器 + lib/index.js 组合根
327
346
  lib/superpowers/ 常驻引导提示词段(只注册 systemPrompt 段,不导入宿主包)
328
347
  lib/ponytail/ lib/mode.js 纯逻辑(等级解析与默认值)+ lib/index.js 提示词段与 /ponytail 命令
348
+ lib/init/ lib/prompt.js 纯逻辑(/init 指令正文)+ lib/index.js 命令接缝
329
349
  locale/*.json 管理标签的文案字典
330
- test/ node:test:<feature>/ 六个目录 + manifest / patch / client 三个契约测试
350
+ test/ node:test:<feature>/ 七个目录 + manifest / patch / client 三个契约测试
331
351
  ```
332
352
 
333
- `lib/project-mcp/config.js`、`lib/gitbash/resolve.js` 与 `lib/ponytail/mode.js` 刻意不导入任何宿主包,所以解析与映射分支可以在没有 dsh 安装的环境里完整跑测试;宿主接缝由各功能的 `index.js` 承担。浏览器半用 fake `window.__ModuleLoader__` + fake `ctx` 测注册与远程调用,不启动浏览器。测试全部离线,不联网、不依赖 `colgrep`/`codegraph` CLI。
353
+ `lib/project-mcp/config.js`、`lib/gitbash/resolve.js`、`lib/ponytail/mode.js` 与 `lib/init/prompt.js` 刻意不导入任何宿主包,所以这些纯逻辑分支可以在没有 dsh 安装的环境里完整跑测试;宿主接缝由各功能的 `index.js` 承担。浏览器半用 fake `window.__ModuleLoader__` + fake `ctx` 测注册与远程调用,不启动浏览器。测试全部离线,不联网、不依赖 `colgrep`/`codegraph` CLI。
334
354
 
335
355
  ## 发布(给维护者)
336
356
 
337
357
  ```powershell
338
- git tag dsh-hiss-plugins@1.1.0 # 必须与本目录 package.json 的 version 逐字一致
339
- git push origin dsh-hiss-plugins@1.1.0
358
+ git tag dsh-hiss-plugins@1.2.1 # 必须与本目录 package.json 的 version 逐字一致
359
+ git push origin dsh-hiss-plugins@1.2.1
340
360
  ```
341
361
 
342
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`。
package/cordis.patch.yml CHANGED
@@ -1,10 +1,10 @@
1
- # dsh-hiss-plugins bundle patch: one package, seven top-level rows.
1
+ # dsh-hiss-plugins bundle patch: one package, eight top-level rows.
2
2
  #
3
3
  # The carrier row (`dsh-hiss-plugins`) is an empty host half: it exists so the package
4
4
  # holds a Loader row, which is what the client module system serves the browser half
5
5
  # (`lib/client.js`, the Plugins-page management tab) for.
6
6
  #
7
- # The six feature rows are deliberate TOP-LEVEL rows, never a `cordis:group` with
7
+ # The seven feature rows are deliberate TOP-LEVEL rows, never a `cordis:group` with
8
8
  # children: the plugin manager can only persist enablement for an entry whose parent
9
9
  # tree is the profile's include and that it can address by row id (see
10
10
  # `dsh-plugin-manager`'s `listPlugins()`), so a nested row can never be switched from
@@ -37,3 +37,6 @@
37
37
 
38
38
  - id: dsh-hiss-plugins-ponytail
39
39
  name: 'dsh-hiss-plugins/ponytail'
40
+
41
+ - id: dsh-hiss-plugins-init
42
+ name: 'dsh-hiss-plugins/init'
package/lib/client.js CHANGED
@@ -34,6 +34,7 @@ window.__ModuleLoader__.load({
34
34
  { key: "gitbash", moduleName: `${PACKAGE_ID}/gitbash`, description: "featureGitbashDescription" },
35
35
  { key: "superpowers", moduleName: `${PACKAGE_ID}/superpowers`, description: "featureSuperpowersDescription" },
36
36
  { key: "ponytail", moduleName: `${PACKAGE_ID}/ponytail`, description: "featurePonytailDescription" },
37
+ { key: "init", moduleName: `${PACKAGE_ID}/init`, description: "featureInitDescription" },
37
38
  ];
38
39
  /** The same features keyed by the name a card shows. */
39
40
  const FEATURE_BY_KEY = new Map(FEATURES.map((feature) => [feature.key, feature]));
@@ -75,6 +76,7 @@ window.__ModuleLoader__.load({
75
76
  featureGitbashDescription: "Windows 上的 Git Bash shell",
76
77
  featureSuperpowersDescription: "superpowers 技能常驻引导(任何回复前先检查并加载技能)",
77
78
  featurePonytailDescription: "ponytail 采纳提示与 /ponytail 等级切换",
79
+ featureInitDescription: "生成或更新项目 AGENTS.md(/init)",
78
80
  };
79
81
  /** English dictionary checked against the Chinese key set. */
80
82
  const en = {
@@ -96,6 +98,7 @@ window.__ModuleLoader__.load({
96
98
  featureGitbashDescription: "Git Bash shell on Windows",
97
99
  featureSuperpowersDescription: "always-on superpowers skill mandate",
98
100
  featurePonytailDescription: "ponytail adoption hint and /ponytail level switching",
101
+ featureInitDescription: "generates or updates the project's AGENTS.md (/init)",
99
102
  };
100
103
 
101
104
  /** Read one thrown value as text. */
@@ -0,0 +1,72 @@
1
+ /**
2
+ * The `/init` command: hand the model one self-contained instruction to read the
3
+ * repository and write its AGENTS.md.
4
+ *
5
+ * The row does no filesystem work of its own. The agent already has the reading,
6
+ * search, and writing tools, and the prompt is the product; a generator here would
7
+ * duplicate those tools and still guess at the repository's commands. The thin seam
8
+ * also keeps the command usable from every UI that composes `commands`.
9
+ *
10
+ * @module dsh-hiss-plugins/init
11
+ */
12
+ import { createUserMessage } from "@deepseek-ai/dsh-llm";
13
+ import { buildInitPrompt } from "./prompt.js";
14
+
15
+ export const name = "init";
16
+ export const inject = ["commands", "workingDirectory"];
17
+
18
+ /** The command is argument-free; extra input is a usage error, not a silent no-op. */
19
+ const USAGE = "Usage: /init (no arguments)";
20
+
21
+ /**
22
+ * Register the `/init` command.
23
+ *
24
+ * @param {import("@deepseek-ai/cordis").Context} ctx - host context carrying
25
+ * `commands` and `workingDirectory`.
26
+ */
27
+ export function apply(ctx) {
28
+ ctx.commands.register({
29
+ name: "init",
30
+ description: "Read this project and write AGENTS.md",
31
+ handler: (invocation) => runInit(ctx, invocation),
32
+ });
33
+ }
34
+
35
+ /**
36
+ * Execute one `/init` invocation.
37
+ *
38
+ * @param {object} ctx host context.
39
+ * @param {object} invocation the command invocation.
40
+ * @returns {Promise<{ kind: "success" | "error", text: string }>} the command result.
41
+ */
42
+ async function runInit(ctx, invocation) {
43
+ if (invocation.rawInput.trim().length > 0) return { kind: "error", text: USAGE };
44
+ const cwd = await resolveCwd(ctx, invocation);
45
+ invocation.agent.followup(createUserMessage({
46
+ content: [{ type: "text", text: buildInitPrompt(cwd) }],
47
+ source: { kind: "user" },
48
+ }));
49
+ return { kind: "success", text: "Reading this project and writing AGENTS.md." };
50
+ }
51
+
52
+ /**
53
+ * Name the session directory in the prompt, best effort.
54
+ *
55
+ * A failed lookup is not a reason to refuse: the agent's own tools still resolve
56
+ * relative paths against the session cwd, so the prompt simply omits the absolute
57
+ * path and lets the agent find the project root itself.
58
+ *
59
+ * @param {object} ctx host context.
60
+ * @param {object} invocation the command invocation.
61
+ * @returns {Promise<string | undefined>} the session working directory, when known.
62
+ */
63
+ async function resolveCwd(ctx, invocation) {
64
+ try {
65
+ return await ctx.workingDirectory.ensure(invocation.agent, invocation.signal);
66
+ } catch (error) {
67
+ // A cancellation is not a bookkeeping failure: never enqueue a prompt the
68
+ // user has already withdrawn.
69
+ if (invocation.signal.aborted) throw error;
70
+ return undefined;
71
+ }
72
+ }
@@ -0,0 +1,92 @@
1
+ /**
2
+ * The `/init` instruction: the evidence the model must collect, the sections a
3
+ * useful AGENTS.md carries, and the checks that keep it honest.
4
+ *
5
+ * Kept free of host imports so the text is testable under this repo's own
6
+ * `node --test` (the same split `lib/ponytail/mode.js` and
7
+ * `lib/project-mcp/config.js` use).
8
+ *
9
+ * @module dsh-hiss-plugins/init/prompt
10
+ */
11
+
12
+ /** The file this command produces. */
13
+ export const TARGET = "AGENTS.md";
14
+
15
+ /**
16
+ * The sections the prompt suggests, in order. Each entry is one source of truth:
17
+ * the prompt renders the same headings, and the tests assert every one survives.
18
+ */
19
+ export const SECTIONS = [
20
+ { heading: "Project overview", guidance: "what the project is, the stack and key versions, and the top-level layout (2–3 sentences)." },
21
+ { heading: "Setup", guidance: "install and first-run commands, required runtime and tool versions, environment-file steps." },
22
+ { heading: "Build, test, and lint", guidance: "exact commands, including how to run one test or one file, and what must pass before a change is done." },
23
+ { heading: "Architecture", guidance: "where the core code lives and the rules that keep the parts separate." },
24
+ { heading: "Conventions", guidance: "repository-specific style and patterns, not universal advice; one short real example when it beats prose." },
25
+ { heading: "Testing", guidance: "what to add or update, fixtures, and the checks CI runs." },
26
+ { heading: "Git and pull requests", guidance: "branch, commit message, pull request, and release or migration rules." },
27
+ { heading: "Security and gotchas", guidance: "secrets, dangerous commands, generated files, and do-not-touch areas; state what is always done, what needs asking first, and what is never done." },
28
+ ];
29
+
30
+ /**
31
+ * Build the user message `/init` hands the model.
32
+ *
33
+ * @param {string | undefined} cwd the session working directory, when the host resolved one.
34
+ * @returns {string} the complete instruction.
35
+ */
36
+ export function buildInitPrompt(cwd) {
37
+ const start = typeof cwd === "string" && cwd !== ""
38
+ ? `\`${cwd}\``
39
+ : "the current session working directory";
40
+ const sections = SECTIONS
41
+ .map((section, index) => `${index + 1}. **${section.heading}** — ${section.guidance}`)
42
+ .join("\n");
43
+ return [
44
+ "Generate or update `AGENTS.md` for this repository.",
45
+ "",
46
+ "DSH loads this file at the start of future sessions, so write it to be read cold: the reader is a capable coding agent with no prior context. After reading this one file it should know how to set the project up, run the checks that matter, find the code, follow the house rules, and avoid the traps. Write for that reader, not for a human browsing the README.",
47
+ "",
48
+ "## 1. Locate the target",
49
+ `- Start from ${start}.`,
50
+ "- The project root is the nearest ancestor that contains `.git`; if there is none, use the working directory itself.",
51
+ "- The target is `<project root>/AGENTS.md`.",
52
+ "- If it already exists, read it first and update it in place. Keep accurate content and rules written by the maintainers; remove only what is wrong or redundant, and say what you removed.",
53
+ "- If it does not exist but `AGENT.md` or `CLAUDE.md` does, read that file for context and write a new `AGENTS.md`. Do not delete or rewrite the other file.",
54
+ "",
55
+ "## 2. Gather evidence",
56
+ "Read the files that tell a new teammate what to do. Check what exists:",
57
+ "- README and contributor docs; package manifests and workspace config (`package.json`, `pnpm-workspace.yaml`, `pyproject.toml`, `Cargo.toml`, `go.mod`, ...); lockfiles and toolchain pins; `Makefile` / `Taskfile` / `justfile` / `scripts/`; CI workflows; lint, format, type-check, and test config.",
58
+ "- The entry points, one or two representative source files, and the tests around them.",
59
+ "- Release, migration, and deployment notes when the repository has them.",
60
+ "",
61
+ "Extract:",
62
+ "- The exact install, setup, build, test, lint, and single-test commands the repository really uses. A command may appear only if it is written in a manifest, script, Makefile, CI file, or documentation, or you ran it successfully and it is cheap and safe. Never invent a command, path, script name, or version.",
63
+ "- The small set of directories and files that carry the core behavior, and the boundaries between them. Write a map, not a full tree.",
64
+ "- Conventions a newcomer cannot infer from a glance: module system and language level, formatting and lint rules, naming, error handling, layering, generated code, migrations, platform assumptions.",
65
+ "- The traps: setup steps that are easy to miss, ordering constraints, checks CI runs that differ from local ones, environment variables, platform quirks, known failures, generated files, and paths that must not be edited by hand.",
66
+ "",
67
+ "Change only `AGENTS.md` files — no source, configuration, or other documentation edits. Do not commit anything. Do not run installs, builds, test suites, network calls, or destructive commands merely to discover facts; inspect the repository instead.",
68
+ "",
69
+ "## 3. Write the file",
70
+ "Use only the sections this repository needs; omit empty ones. A useful order:",
71
+ sections,
72
+ "",
73
+ "Quality bar:",
74
+ "- Put the commands early: setup and build/test before deeper explanation, so the reader does not have to hunt.",
75
+ "- Be specific: `pnpm --filter web test` beats a vague instruction to run the tests; name the package, file, or test when it matters.",
76
+ "- Keep it tight: aim for 80–150 lines and treat about 200 as a hard ceiling unless the repository genuinely needs more. Prefer bullets and short tables to prose.",
77
+ "- Include only what is true for this repository. No generic advice, no marketing, no full API documentation, and no copying the README.",
78
+ "- Prefer facts the agent cannot get from one quick look; leave out obvious file lists.",
79
+ "- Write for any future agent, not just this run: no references to this conversation, the `/init` command, or the fact that the file was generated.",
80
+ "- Write in the language of the repository's existing documentation. If there is none, use the language of this conversation.",
81
+ "- In a monorepo, one root `AGENTS.md` is still the default. Add a short per-package section instead of creating nested files unless a package genuinely needs its own file.",
82
+ "- Never include secrets, tokens, personal paths, or values that only work on your machine.",
83
+ "",
84
+ "## 4. Verify before you finish",
85
+ "- Re-read the file from disk.",
86
+ "- Check every command, path, environment variable, and config name against the repository; fix or delete anything you cannot confirm.",
87
+ "- Check that the file answers: how to set up, how to run the relevant checks, where the core code lives, and what not to touch.",
88
+ "- Do not claim the file was written until it exists on disk.",
89
+ "",
90
+ "Finish with a short report: the absolute path, the line count, the evidence behind each command, and anything you could not verify or deliberately left out.",
91
+ ].join("\n");
92
+ }
@@ -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/locale/en.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "dsh-hiss-plugins",
4
- "description": "One DeepSeek Harness bundle carrying six switchable plugins — colgrep, codegraph, project-mcp, git-bash, superpowers and ponytail — managed from a tab in the Plugins page."
4
+ "description": "One DeepSeek Harness bundle carrying seven switchable plugins — colgrep, codegraph, project-mcp, git-bash, superpowers, ponytail and init — managed from a tab in the Plugins page."
5
5
  },
6
6
  "loading": "Reading plugins…",
7
7
  "error": "Plugins are unavailable: {error}",
@@ -20,5 +20,6 @@
20
20
  "featureProjectMcpDescription": "mounts the project's .mcp.json per session",
21
21
  "featureGitbashDescription": "Git Bash shell on Windows",
22
22
  "featureSuperpowersDescription": "always-on superpowers skill mandate",
23
- "featurePonytailDescription": "ponytail adoption hint and /ponytail level switching"
23
+ "featurePonytailDescription": "ponytail adoption hint and /ponytail level switching",
24
+ "featureInitDescription": "generates or updates the project's AGENTS.md (/init)"
24
25
  }
package/locale/zh.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "dsh-hiss-plugins",
4
- "description": "一个 DeepSeek Harness 组合包,携带 colgrep、codegraph、project-mcp、git-bash、superpowers、ponytail 六个可独立开关的插件,并在插件页提供管理标签。"
4
+ "description": "一个 DeepSeek Harness 组合包,携带 colgrep、codegraph、project-mcp、git-bash、superpowers、ponytail、init 七个可独立开关的插件,并在插件页提供管理标签。"
5
5
  },
6
6
  "loading": "正在读取插件…",
7
7
  "error": "暂时无法读取插件:{error}",
@@ -20,5 +20,6 @@
20
20
  "featureProjectMcpDescription": "按会话挂载项目 .mcp.json",
21
21
  "featureGitbashDescription": "Windows 上的 Git Bash shell",
22
22
  "featureSuperpowersDescription": "superpowers 技能常驻引导(任何回复前先检查并加载技能)",
23
- "featurePonytailDescription": "ponytail 采纳提示与 /ponytail 等级切换"
23
+ "featurePonytailDescription": "ponytail 采纳提示与 /ponytail 等级切换",
24
+ "featureInitDescription": "生成或更新项目 AGENTS.md(/init)"
24
25
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-hiss-plugins",
3
- "version": "1.1.0",
4
- "description": "dsh-hiss-plugins — one DeepSeek Harness bundle carrying six independently switchable plugins (colgrep, codegraph, project-mcp, git-bash, superpowers, ponytail) plus a management tab in the Plugins page.",
3
+ "version": "1.2.1",
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",
7
7
  "deepseek-harness",
@@ -12,7 +12,9 @@
12
12
  "git-bash",
13
13
  "semantic-search",
14
14
  "superpowers",
15
- "ponytail"
15
+ "ponytail",
16
+ "agents-md",
17
+ "init"
16
18
  ],
17
19
  "license": "MIT",
18
20
  "author": {
@@ -37,6 +39,7 @@
37
39
  "./gitbash": "./lib/gitbash/index.js",
38
40
  "./superpowers": "./lib/superpowers/index.js",
39
41
  "./ponytail": "./lib/ponytail/index.js",
42
+ "./init": "./lib/init/index.js",
40
43
  "./client": "./lib/client.js",
41
44
  "./locale/*.json": "./locale/*.json",
42
45
  "./package.json": "./package.json"