dsh-qq-instruction

开发规范(CONVENTIONS)

适用:github.com/Quisperc/dsh-qq-instruction(公开)及其本机工作副本 · 插件范本 packages/dsh-qq-whale(v0.14.0) 最后核对:2026-11-14 · 与仓库根 CONTRIBUTING.md 冲突时,以仓库为准并在本节记录差异 读者:下一个改这个仓库的 Agent。改任何东西之前先读第 1、2 节。


1. 真源与同步流程

唯一真源:github.com/Quisperc/dsh-qq-instruction(已公开,clone 不需要令牌)。 本机工作副本:/data/dsh/home/QQBotV2/dsh-qq-instruction(软链安装的插件就指向这里,改文件 = 改线上)。

1.1 标准顺序(每次改动都走这条)

# 动作 命令 / 说明
1 拉取 git -C <工作副本> fetch origin main
2 读 diff git diff --stat <旧HEAD> FETCH_HEAD,再 git diff <旧HEAD> FETCH_HEAD -- <关键文件>
3 对齐 git reset --hard FETCH_HEAD(先做第 2 节检查)
4 改 在工作副本里改;改插件包 = 改线上(软链自动跟随)
5 测试 见第 4 节,必须跑
6 提交 本地 git commit(本机无全局身份,见 2.3)
7 生效 plugin_manager set_bundle 关→开;需要冷启动验证才重启容器
8 验证 cd /tmp && dsh --profile web --dump-config > /dev/null; echo $? → 0
9 推送 git push origin main(公开仓库,无需凭据;历史若被重写过需 --force-with-lease)

1.2 分支与提交


2. 同步前的强制检查

2.1 先看 git status

cd /data/dsh/home/QQBotV2/dsh-qq-instruction && git status --short

2.2 正确的“清场”方式

# 方式 A:先 stash(可恢复)
git stash push -m "local edit before sync @$(date +%F)" -- <文件>

# 方式 B:先复制到持久目录(保险)
cp -a <文件> /data/dsh/home/QQBot2-backup-$(date +%m%d%H%M%S).md

清场后再 git reset --hard FETCH_HEAD。收尾时确认 stash 里有东西没处理:

git stash list

2.3 本机没有 git 身份

git config user.name / user.email 都是空的,直接 git commit 会失败或用错身份。用一次性覆盖:

git -c user.name="QQBot Agent" -c user.email="agent@local" commit -am "feat(whale): …"

曾经的上游提交作者是 WorkBuddy <workbuddy@agent.local>;沿用哪个身份由你决定,但不要把身份写进仓库配置文件。

2.4 其它前置检查

检查 为什么
cd /tmp && dsh --profile web --dump-config; echo $? 是否为 0 基线坏了先修基线,别叠加改动
是否在 /tmp 里做持久工作 容器重启清空 /tmp,克隆/产物一律放 /data/dsh/home
是否要动 profiles/web/cordis.patch.yml 先 cp -a 一份 .bak-<时间戳>

3. 插件开发约定(范本:packages/dsh-qq-whale)

3.1 包清单

{
  "name": "dsh-qq-whale",
  "type": "module",
  "main": "lib/index.js",
  "exports": {
    ".": "./lib/index.js",
    "./package.json": "./package.json",
    "./agent-guard": "./lib/agent-guard.js"   // 子路径导出 = 可被单独 import / 挂成独立行
  },
  "dsh": {
    "runtime": "host",
    "bundle": { "patch": "./cordis.patch.yml" },   // ★ 自带插入行:装上即注入
    "compatibility": { "dsh": ">=0.2.0-rc.2 <0.3.0" }
  },
  "meta": {                                        // ★ 决定插件页显示名与描述
    "title": "QQ 群聊受限预设(preset-qq)",
    "description": "装上即在 profile 组合树里多一张 preset-qq;…"
  }
}

3.2 宿主半(host)契约

export const name = 'dsh-qq-whale';
export const inject = [];              // 需要什么服务就列什么,如 ['tools']
export function apply(ctx, rawConfig) { /* … */ }
ctx.provide('whale', api);   // ✅
ctx.whale = api;             // ❌ Error: cannot set property "whale" without provide

3.3 client 半(若声明了)

3.4 preset 行(本仓库的核心手法)

preset-qq 是官方 @deepseek-ai/dsh-agent-preset 的一行配置,plugins 列表里每个 - id/name 都是挂进 agent scope 的插件行:

- id: preset-qq
  name: '@deepseek-ai/dsh-agent-preset'
  config:
    id: qq
    plugins:
      - id: persona
        name: '@deepseek-ai/dsh-persona'
        config: { prefix: '你不是助手也不是工具,是群里一起聊天的家伙。' }
      - id: my-plugin/feature
        name: 'my-plugin/feature'    # 子路径导出当插件行用

3.5 配置 schema


4. 测试规范

cd /data/dsh/home/QQBotV2/dsh-qq-instruction/packages/dsh-qq-whale
for t in test/*.mjs; do node --test "$t"; done

约定:

mkdir -p node_modules/@deepseek-ai
ln -sfn /data/dsh/profiles/web/node_modules/@deepseek-ai/schemastery node_modules/@deepseek-ai/schemastery
ln -sfn /data/dsh/profiles/web/node_modules/js-yaml node_modules/js-yaml

缺依赖会报 ERR_MODULE_NOT_FOUND。


5. CHANGELOG 与版本

## [1.15.0] - 2026-11-14(插件 v0.8.0)

> 一句话说清这版做了什么;**回滚方法**写在这里。

### Added / Changed / Fixed
- 具体改动 + 依据(文件:行 或 实测结论)

6. 已知坑清单

# 坑 依据 / 处理
1 preset 不收窄全局工具:工具可见性 = 全局 + 祖先 scope − restrict dsh-tools/lib/index.js:427-479;收窄唯一手段是 tools.restrict()(:456)。收窄前实测:QQ 会话头里 82 个工具,含 bash/terminal_*/subagent/workflow(该数字随版本变化,判断标准是“名单里有没有这些名字”)
2 restrict 遇到未知工具名会抛错,会把整个会话建不起来 dsh-tools 的 restrict() 先校验 restrictableNames,未知即 throw;实现必须先校验「白名单全部已注册」,缺一项就跳过(见 lib/agent-guard.js 的 hideTools)
3 preset 在建会话时锁定:跑过回合的会话沿用旧配置 session.v4.jsonl.zstd 首行 agentPreset 在创建时写入;切换 preset 只对新建会话生效
4 容器重启清空 /tmp 持久工作副本一律放 /data/dsh/home 下;曾在 /tmp/qqinstr 丢过一次克隆
5 本机无 python3 仓库 scripts/check-conventions.py、tools/probe-capabilities.py 跑不了;要么本地跑,要么改写成 node
6 pnpm 会删手工软链 profile 的 node_modules/@deepseek-ai/* 是手工软链到宿主安装目录;pnpm install/remove 会把它们当多余包清理 → DSH 起不来。加/卸插件走「软链 + dependencies + bundles」手工流程
7 插件页按 meta.title 显示、只认 dependencies 只在 bundles 里、没进 dependencies 的包在插件页不显示(过滤条件 installed \|\| official \|\| error)
8 ctx.x = v 直接赋值服务会报错 必须先 ctx.provide('x', v);且判断插件是否真跑起来要看 fiberPhase: active,status: schema 不算
9 只导出 Config 不会生成设置页 配置区是 slot plugins.bundle.config,必须由插件自己的 client 半注入

7. 文档写作约定(写给人看,也写给下一个 Agent)