dsh-plugin-dev-kb 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 +25 -7
  2. package/lib/index.js +113 -0
  3. package/package.json +7 -1
package/README.md CHANGED
@@ -1,7 +1,12 @@
1
1
  # dsh-plugin-dev-kb
2
2
 
3
- DeepSeek Harness(dsh)**插件开发知识库**:把官方文档站点
4
- <https://deepseek-harness.github.io/deepseek-harness/> 的全部内容整理为 dsh 原生可用的形态。
3
+ ![npm version](https://img.shields.io/npm/v/dsh-plugin-dev-kb)
4
+ ![License](https://img.shields.io/github/license/Pasumao/dsh-plugin-dev-kb)
5
+ ![AI Assisted](https://img.shields.io/badge/AI-Assisted-8A2BE2)
6
+
7
+ **写 dsh 插件时的随身官方文档**:把 DeepSeek Harness 官方文档站点
8
+ <https://deepseek-harness.github.io/deepseek-harness/> 的全部内容整理为 dsh 原生可用的形态——
9
+ 装了这个插件,agent 写插件时自动加载知识库,按任务场景定位文档,不用再翻网页。
5
10
 
6
11
  ## 这是什么
7
12
 
@@ -13,9 +18,21 @@ DeepSeek Harness(dsh)**插件开发知识库**:把官方文档站点
13
18
 
14
19
  ## 安装 / 挂载
15
20
 
16
- 插件目录放在 `D:\dsh\plugins\dsh-plugin-dev-kb\`(与本机其他 dsh 插件同级)。
17
- `cordis.patch.yml` 声明 `- insert: { id: dsh-plugin-dev-kb, name: dsh-plugin-dev-kb }`,
18
- 挂载为 profile 根层插件行;其 `skills/` 技能进入全局层。
21
+ ```powershell
22
+ # npm(推荐)
23
+ dsh plugin --profile web add dsh-plugin-dev-kb
24
+ # 或 GitHub
25
+ dsh plugin --profile web add github:Pasumao/dsh-plugin-dev-kb
26
+ ```
27
+
28
+ 本插件是「纯数据 + 技能」插件,不自带 bundle 自动挂载,装完后在 profile 的
29
+ `cordis.patch.yml` 末尾加一行手动挂载(挂载为 profile 根层插件行,其 `skills/` 技能进入全局层):
30
+
31
+ ```yaml
32
+ - insert:
33
+ - id: dsh-plugin-dev-kb
34
+ name: dsh-plugin-dev-kb
35
+ ```
19
36
 
20
37
  > 重新启动 / 新建 dsh 会话后,`dsh-plugin-dev-kb` 技能才会出现在可用技能列表中(技能清单在会话启动时快照)。
21
38
 
@@ -48,8 +65,9 @@ dsh-plugin-dev-kb/
48
65
 
49
66
  ## 更新知识库
50
67
 
51
- 见 `kb/README.md`:重新克隆 `deepseek-ai/deepseek-harness`,安装投影依赖后运行
52
- `scripts/project-doc-site.ts` 生成 `website/.generated/`,覆盖 `kb/site/`,再重新生成索引。
68
+ 见 `kb/README.md`:重新克隆 `deepseek-ai/deepseek-harness`(master 分支),安装投影依赖后
69
+ 在仓库内运行 `node --experimental-strip-types run-projector.ts` 生成 `website/.generated/`,
70
+ 覆盖本插件的 `kb/site/`,再在本插件根目录运行 `node scripts/rebuild-index.mjs` 重建索引与 INDEX.md。
53
71
 
54
72
  ## License
55
73
 
package/lib/index.js ADDED
@@ -0,0 +1,113 @@
1
+ /**
2
+ * dsh-plugin-dev-kb — 主机插件(纯技能载体,无工具/命令)。
3
+ *
4
+ * 挂载于 profile 根层(全局层),唯一职责:把 skills/ 目录下的
5
+ * dsh-plugin-dev-kb 技能注册为 runtime skill,让每个会话的 agent
6
+ * 在插件开发 / 查询 dsh 能力 / 写 Tool / 配置 cordis.yml 类任务时,
7
+ * 能按技能 description 自动加载,从而获知知识库位置与阅读路径。
8
+ *
9
+ * 知识库数据(kb/ 目录:site/ 站点镜像 + extra/ 补充文档 + meta/
10
+ * 主题导航与索引)是纯文档,模型通过文件工具按技能指示直接读取。
11
+ *
12
+ * 依赖纪律:本模块不 import 任何 @deepseek-ai/* 运行时包(插件以
13
+ * link: 方式装入 profile,Node ESM 按 realpath 解析链接包,外部依赖
14
+ * 从插件目录解析不到;这里本来也不需要)。
15
+ */
16
+
17
+ import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
18
+ import { homedir } from 'node:os'
19
+ import { dirname, join } from 'node:path'
20
+ import { fileURLToPath } from 'node:url'
21
+
22
+ export const name = 'dsh-plugin-dev-kb'
23
+ export const inject = ['skills']
24
+
25
+ const PKG_DIR = dirname(fileURLToPath(import.meta.url))
26
+ const SKILLS_DIR = join(PKG_DIR, '..', 'skills')
27
+
28
+ /** 极简 frontmatter 解析(name/description/whenToUse)。 */
29
+ function parseFrontmatter(md) {
30
+ const match = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(md)
31
+ if (!match) return { name: undefined, description: undefined, whenToUse: undefined, body: md }
32
+ const meta = {}
33
+ for (const line of match[1].split(/\r?\n/)) {
34
+ const i = line.indexOf(':')
35
+ if (i <= 0) continue
36
+ const key = line.slice(0, i).trim()
37
+ if (key) meta[key] = line.slice(i + 1).trim().replace(/^["']|["']$/g, '')
38
+ }
39
+ return { ...meta, body: md.slice(match[0].length) }
40
+ }
41
+
42
+ /** 从 skills/ 目录加载技能定义(文件缺失/无 frontmatter 时跳过并警告,绝不让插件挂载失败)。 */
43
+ function loadSkills() {
44
+ const out = []
45
+ if (!existsSync(SKILLS_DIR)) {
46
+ console.warn('[dsh-plugin-dev-kb] skills 目录缺失,技能未加载:' + SKILLS_DIR)
47
+ return out
48
+ }
49
+ for (const file of readdirSync(SKILLS_DIR)) {
50
+ if (!file.endsWith('.md')) continue
51
+ try {
52
+ const fm = parseFrontmatter(readFileSync(join(SKILLS_DIR, file), 'utf8'))
53
+ if (!fm.name || !fm.description) {
54
+ console.warn(`[dsh-plugin-dev-kb] 技能文件缺少 name/description frontmatter,已跳过:${file}`)
55
+ continue
56
+ }
57
+ out.push({
58
+ name: fm.name,
59
+ description: fm.description,
60
+ whenToUse: fm.whenToUse,
61
+ body: fm.body
62
+ })
63
+ } catch (err) {
64
+ console.warn(`[dsh-plugin-dev-kb] 技能文件读取失败,已跳过:${file}(${err?.message ?? err})`)
65
+ }
66
+ }
67
+ return out
68
+ }
69
+
70
+ /** 挂载状态文件(自诊断:$DSH_HOME/dsh-plugin-dev-kb.state.json)。 */
71
+ function dshHome() {
72
+ return process.env.DSH_HOME || join(homedir(), '.dsh')
73
+ }
74
+
75
+ export function apply(ctx, config) {
76
+ const disposers = []
77
+ const state = { skills: [] }
78
+
79
+ // 契约(dsh-skill validateDefinition):定义必须含 name/description/
80
+ // source/content 四个字符串;provider 缺省为 'runtime'。
81
+ for (const skill of loadSkills()) {
82
+ try {
83
+ disposers.push(ctx.skills.register({
84
+ name: skill.name,
85
+ description: skill.description,
86
+ ...(skill.whenToUse ? { whenToUse: skill.whenToUse } : {}),
87
+ source: 'runtime',
88
+ content: skill.body
89
+ }))
90
+ state.skills.push(skill.name)
91
+ console.log(`[dsh-plugin-dev-kb] 技能已注册:${skill.name}`)
92
+ } catch (err) {
93
+ console.warn(`[dsh-plugin-dev-kb] 技能注册失败:${skill.name}(${err?.message ?? err})`)
94
+ }
95
+ }
96
+
97
+ try {
98
+ writeFileSync(join(dshHome(), 'dsh-plugin-dev-kb.state.json'), JSON.stringify({
99
+ plugin: 'dsh-plugin-dev-kb',
100
+ mountedAt: new Date().toISOString(),
101
+ skills: state.skills
102
+ }, null, 2), 'utf8')
103
+ } catch { /* 状态文件写入失败不影响挂载 */ }
104
+
105
+ console.log(`[dsh-plugin-dev-kb] 已挂载:${state.skills.length} 技能(知识库在 kb/ 目录)`)
106
+
107
+ // 卸载清理(HMR 重载时避免重复注册)。
108
+ return () => {
109
+ for (const dispose of disposers) {
110
+ try { dispose() } catch { /* ignore */ }
111
+ }
112
+ }
113
+ }
package/package.json CHANGED
@@ -1,9 +1,15 @@
1
1
  {
2
2
  "name": "dsh-plugin-dev-kb",
3
3
  "description": "DeepSeek Harness (dsh) 插件开发知识库:官方文档站点的完整 Markdown 镜像(中英双语 168 页)+ 仓库补充文档(50 篇)+ 主题导航与搜索索引,以 dsh-plugin-dev-kb 技能形式让 agent 在插件开发任务中自动加载定位文档。纯数据插件,无运行时依赖。",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "type": "module",
6
+ "main": "lib/index.js",
7
+ "exports": {
8
+ ".": "./lib/index.js",
9
+ "./package.json": "./package.json"
10
+ },
6
11
  "files": [
12
+ "lib",
7
13
  "kb",
8
14
  "skills",
9
15
  "scripts",