repo-audit-tool 1.2.0

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 (117) hide show
  1. package/AGENTS.md +67 -0
  2. package/AUDIT.md +802 -0
  3. package/BEST-PRACTICES.md +268 -0
  4. package/CLAUDE.md +1 -0
  5. package/CONTRIBUTING.md +42 -0
  6. package/DEVELOPMENT.md +112 -0
  7. package/HANDOFF.md +124 -0
  8. package/LICENSE +21 -0
  9. package/PUBLISHING.md +66 -0
  10. package/README.en.md +71 -0
  11. package/README.md +71 -0
  12. package/REPO-AUDIT.md +107 -0
  13. package/REPO-CLASSIFICATION.md +137 -0
  14. package/SECURITY.md +19 -0
  15. package/docs/repo-audit/AGENT-GUIDE.md +474 -0
  16. package/docs/repo-audit/HUMAN-GUIDE.md +749 -0
  17. package/package.json +36 -0
  18. package/repo-audit.mjs +1507 -0
  19. package/rules/categories/archive.yaml +48 -0
  20. package/rules/categories/content.yaml +34 -0
  21. package/rules/categories/dsh-plugin.yaml +79 -0
  22. package/rules/categories/go-service.yaml +67 -0
  23. package/rules/categories/product-oss.yaml +75 -0
  24. package/rules/categories/python-app.yaml +60 -0
  25. package/rules/categories/sandbox.yaml +33 -0
  26. package/rules/domains/docs.yaml +105 -0
  27. package/rules/domains/git.yaml +52 -0
  28. package/rules/domains/quality.yaml +69 -0
  29. package/rules/domains/security.yaml +79 -0
  30. package/shim/repo-audit.cmd +7 -0
  31. package/shim/repo-audit.ps1 +4 -0
  32. package/shim/repo-audit.sh +5 -0
  33. package/templates/AGENT-GUIDE.md +331 -0
  34. package/templates/README.md +192 -0
  35. package/templates/UPDATE-MODEL.md +141 -0
  36. package/templates/UPDATE-PLAN.md +79 -0
  37. package/templates/categories/content/AGENTS-append.md +6 -0
  38. package/templates/categories/content/CATEGORY.md +26 -0
  39. package/templates/categories/content/README.en.md +12 -0
  40. package/templates/categories/content/README.md +14 -0
  41. package/templates/categories/content/gitignore-append.md +6 -0
  42. package/templates/categories/dsh-plugin/AGENTS-append.md +21 -0
  43. package/templates/categories/dsh-plugin/CATEGORY.md +9 -0
  44. package/templates/categories/dsh-plugin/CONTRIBUTING-append.md +22 -0
  45. package/templates/categories/dsh-plugin/DEVELOPMENT-append.md +71 -0
  46. package/templates/categories/dsh-plugin/PUBLISHING-append.md +53 -0
  47. package/templates/categories/dsh-plugin/README-append.md +28 -0
  48. package/templates/categories/dsh-plugin/README.en.md +44 -0
  49. package/templates/categories/dsh-plugin/gitignore-append.md +15 -0
  50. package/templates/categories/go-service/.githooks/pre-commit +13 -0
  51. package/templates/categories/go-service/.github/workflows/ci.yml +31 -0
  52. package/templates/categories/go-service/.github/workflows/release.yml +58 -0
  53. package/templates/categories/go-service/.goreleaser.yaml +86 -0
  54. package/templates/categories/go-service/AGENTS-append.md +7 -0
  55. package/templates/categories/go-service/CATEGORY.md +33 -0
  56. package/templates/categories/go-service/CONTRIBUTING-append.md +13 -0
  57. package/templates/categories/go-service/DEVELOPMENT-append.md +21 -0
  58. package/templates/categories/go-service/Makefile +21 -0
  59. package/templates/categories/go-service/PUBLISHING-append.md +48 -0
  60. package/templates/categories/go-service/PUBLISHING.md +59 -0
  61. package/templates/categories/go-service/README-append.md +26 -0
  62. package/templates/categories/go-service/README.en.md +43 -0
  63. package/templates/categories/go-service/gitignore-append.md +13 -0
  64. package/templates/categories/product-oss/.github/CODEOWNERS +6 -0
  65. package/templates/categories/product-oss/.github/ISSUE_TEMPLATE/bug_report.yml +52 -0
  66. package/templates/categories/product-oss/.github/ISSUE_TEMPLATE/config.yml +8 -0
  67. package/templates/categories/product-oss/.github/dependabot.yml +28 -0
  68. package/templates/categories/product-oss/.github/workflows/dependency-review.yml +18 -0
  69. package/templates/categories/product-oss/.github/workflows/release-please.yml +39 -0
  70. package/templates/categories/product-oss/.release-please-manifest.json +3 -0
  71. package/templates/categories/product-oss/CATEGORY.md +27 -0
  72. package/templates/categories/product-oss/CHANGELOG.md +14 -0
  73. package/templates/categories/product-oss/PULL_REQUEST_TEMPLATE.md +15 -0
  74. package/templates/categories/product-oss/SUPPORT.md +71 -0
  75. package/templates/categories/product-oss/release-please-config.json +10 -0
  76. package/templates/categories/python-app/.githooks/pre-commit +13 -0
  77. package/templates/categories/python-app/.github/workflows/ci.yml +33 -0
  78. package/templates/categories/python-app/.github/workflows/publish.yml +112 -0
  79. package/templates/categories/python-app/AGENTS-append.md +18 -0
  80. package/templates/categories/python-app/CATEGORY.md +34 -0
  81. package/templates/categories/python-app/CONTRIBUTING-append.md +13 -0
  82. package/templates/categories/python-app/DEVELOPMENT-append.md +21 -0
  83. package/templates/categories/python-app/PUBLISHING-append.md +52 -0
  84. package/templates/categories/python-app/PUBLISHING.md +61 -0
  85. package/templates/categories/python-app/README-append.md +27 -0
  86. package/templates/categories/python-app/README.en.md +44 -0
  87. package/templates/categories/python-app/gitignore-append.md +19 -0
  88. package/templates/categories/python-app/pyproject.toml +41 -0
  89. package/templates/categories/python-app/scripts/verify.py +39 -0
  90. package/templates/categories/sandbox/AGENTS-append.md +7 -0
  91. package/templates/categories/sandbox/CATEGORY.md +31 -0
  92. package/templates/categories/sandbox/README.en.md +24 -0
  93. package/templates/categories/sandbox/README.md +23 -0
  94. package/templates/check-single-source.mjs +107 -0
  95. package/templates/common/AGENTS-core.md +28 -0
  96. package/templates/common/CONTRIBUTING-core.md +21 -0
  97. package/templates/common/DEVELOPMENT-core.md +45 -0
  98. package/templates/common/PUBLISHING-core.md +31 -0
  99. package/templates/common/README-core.md +60 -0
  100. package/templates/common/SECURITY-core.md +19 -0
  101. package/templates/common/copilot-instructions.md +5 -0
  102. package/templates/common/gitignore-core.md +11 -0
  103. package/templates/repo-root/.githooks/pre-commit +20 -0
  104. package/templates/repo-root/.github/workflows/ci.yml +45 -0
  105. package/templates/repo-root/.github/workflows/publish.yml +77 -0
  106. package/templates/repo-root/CLAUDE.md +3 -0
  107. package/templates/repo-root/LICENSE +21 -0
  108. package/templates/repo-root/package.json +71 -0
  109. package/templates/repo-root/scripts/build.mjs +24 -0
  110. package/templates/repo-root/scripts/check-deploy.mjs +176 -0
  111. package/templates/repo-root/scripts/verify.mjs +52 -0
  112. package/templates/repo-root/src/config.ts +25 -0
  113. package/templates/repo-root/src/index.ts +40 -0
  114. package/templates/repo-root/tsconfig.build.json +22 -0
  115. package/templates/repo-root/tsconfig.json +23 -0
  116. package/templates/scaffold.mjs +793 -0
  117. package/templates/skill/SKILL.md +47 -0
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "dsh-<name>",
3
+ "version": "0.1.0",
4
+ "description": "<一句话描述>",
5
+ "license": "MIT",
6
+ "author": "<org>",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/<org>/dsh-<name>.git"
10
+ },
11
+ "homepage": "https://github.com/<org>/dsh-<name>#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/<org>/dsh-<name>/issues"
14
+ },
15
+ "type": "module",
16
+ "main": "lib/index.js",
17
+ "types": "lib/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./lib/index.d.ts",
21
+ "default": "./lib/index.js"
22
+ },
23
+ "./client": {
24
+ "types": "./lib/client.d.ts",
25
+ "default": "./lib/client.js"
26
+ },
27
+ "./package.json": "./package.json"
28
+ },
29
+ "files": [
30
+ "lib",
31
+ "cordis.patch.yml",
32
+ "README.md",
33
+ "README.en.md"
34
+ ],
35
+ "dsh": {
36
+ "bundle": {
37
+ "patch": "./cordis.patch.yml"
38
+ },
39
+ "client": {
40
+ "inject": ["<client half 需要的宿主 UI 包,如 @deepseek-ai/dsh-client-runtime>"],
41
+ "platform": "web"
42
+ }
43
+ },
44
+ "engines": {
45
+ "node": ">=20"
46
+ },
47
+ "scripts": {
48
+ "build": "tsc -p tsconfig.build.json && node scripts/build.mjs",
49
+ "typecheck": "tsc -p tsconfig.json --noEmit",
50
+ "test": "node scripts/verify.mjs",
51
+ "check:deploy": "node scripts/check-deploy.mjs",
52
+ "prepublishOnly": "npm run build"
53
+ },
54
+ "peerDependencies": {
55
+ "@deepseek-ai/cordis": "^4.0.2",
56
+ "@deepseek-ai/dsh-<用到的宿主包>": "^0.1.2-alpha.4"
57
+ },
58
+ "peerDependenciesMeta": {
59
+ "@deepseek-ai/dsh-<可选宿主包>": {
60
+ "optional": true
61
+ }
62
+ },
63
+ "devDependencies": {
64
+ "@deepseek-ai/cordis": "^4.0.2",
65
+ "@deepseek-ai/schemastery": "^3.18.1",
66
+ "@types/node": "^24",
67
+ "@deepseek-ai/dsh-<用到的宿主包>": "^0.1.2-alpha.4",
68
+ "@deepseek-ai/dsh-<运行时可达的其他宿主包>": "^0.1.2-alpha.4",
69
+ "typescript": "^5.7.0"
70
+ }
71
+ }
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 构建探测包装(build 链后半段):tsc 之后按文件存在性执行可选项——
4
+ * scripts/build-client.mjs 存在 → 跑(client bundle;从 dsh-context-compass/scripts/build-client.mjs 复制适配)
5
+ * 不存在 → 静默通过(纯 host 插件无需任何额外产物)。
6
+ * package.json 的 "build" 固定调用本脚本:有 client 的库接入 build-client.mjs 后自动生效,
7
+ * 不用改 build 命令;无 client 的库验证链不再死在缺失脚本上。
8
+ */
9
+
10
+ import { existsSync } from 'node:fs';
11
+ import { spawnSync } from 'node:child_process';
12
+ import { join, resolve, dirname } from 'node:path';
13
+ import { fileURLToPath } from 'node:url';
14
+
15
+ const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
16
+
17
+ const buildClient = join(ROOT, 'scripts', 'build-client.mjs');
18
+ if (existsSync(buildClient)) {
19
+ const r = spawnSync('node', [buildClient], { stdio: 'inherit', cwd: ROOT });
20
+ if (r.status !== 0) {
21
+ console.error(`✗ build-client 失败(exit ${r.status})`);
22
+ process.exit(1);
23
+ }
24
+ }
@@ -0,0 +1,176 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 部署纪律装后自检(DEVELOPMENT.md「部署纪律:profile 安装」配套脚本)
4
+ *
5
+ * 三点检查:
6
+ * 1) 源码 lib == 部署 lib(file: 指向的源码目录 vs profile 内实际安装产物)
7
+ * 2) profile 内 @deepseek-ai/ 只允许 cosmokit / schemastery(防第二套宿主核心包)
8
+ * 3) file: 安装在 profile 内必须是真实目录(非软链,防 realpath 脱离宿主 fallback)
9
+ *
10
+ * 用法:
11
+ * node scripts/check-deploy.mjs # 全量检查 profile 里所有插件
12
+ * node scripts/check-deploy.mjs --pkg dsh-<name> [--pkg ...] # 只查指定插件
13
+ * node scripts/check-deploy.mjs --profile ~/.dsh/profiles/web # 指定 profile
14
+ *
15
+ * 退出码:0 = 全部 PASS(或无插件安装);1 = 存在 FAIL。
16
+ */
17
+
18
+ /*
19
+ * 模板说明(用后删除):本脚本从 dsh-context-compass(已跑通两库的单库适配版)
20
+ * 整编,单库/多包布局自适应(localSrcFor),**逻辑保持与参照实现一致,勿随手改算法**。
21
+ * 唯一可调项:默认 profile 名(下方 PROFILE 默认值,按本机实际 profile 改)。
22
+ * 与参照实现的一处既有差异:参照版 import 了未用的 statSync/basename(保真照抄),
23
+ * 本模板已清理——若日后从参照库同步本脚本,属预期差异,勿当作回归。
24
+ */
25
+
26
+ import { readdirSync, readFileSync, existsSync, lstatSync } from 'node:fs';
27
+ import { createHash } from 'node:crypto';
28
+ import { homedir } from 'node:os';
29
+ import { join, resolve, isAbsolute, dirname } from 'node:path';
30
+ import { fileURLToPath } from 'node:url';
31
+
32
+ const REPO_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
33
+ const ALLOWED_HOST_PKGS = new Set(['cosmokit', 'schemastery']);
34
+
35
+ // ---------- 参数 ----------
36
+ const argv = process.argv.slice(2);
37
+ function getFlag(name) {
38
+ const i = argv.indexOf(name);
39
+ return i >= 0 ? argv[i + 1] : undefined;
40
+ }
41
+ const profileArg = getFlag('--profile');
42
+ const PROFILE = profileArg
43
+ ? resolve(profileArg.replace(/^~(?=\/|$)/, homedir()))
44
+ : join(homedir(), '.dsh', 'profiles', 'web');
45
+ const pkgFilters = [];
46
+ for (let i = 0; i < argv.length; i++) {
47
+ if (argv[i] === '--pkg' && argv[i + 1]) pkgFilters.push(argv[i + 1]);
48
+ }
49
+
50
+ // ---------- 工具 ----------
51
+ function hashTree(dir, base = dir, acc = new Map()) {
52
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
53
+ const full = join(dir, entry.name);
54
+ const rel = full.slice(base.length + 1);
55
+ if (entry.isDirectory()) hashTree(full, base, acc);
56
+ else if (entry.isFile()) acc.set(rel, createHash('sha256').update(readFileSync(full)).digest('hex'));
57
+ }
58
+ return acc;
59
+ }
60
+ function diffTrees(aDir, bDir) {
61
+ const a = hashTree(aDir), b = hashTree(bDir);
62
+ const diffs = [];
63
+ for (const [k, v] of a) if (b.get(k) !== v) diffs.push(b.has(k) ? `M ${k}` : `D ${k}`);
64
+ for (const k of b.keys()) if (!a.has(k)) diffs.push(`+ ${k}`);
65
+ return diffs;
66
+ }
67
+ function resolveFileTarget(spec) {
68
+ // file: 相对路径按 profile package.json 所在目录解析
69
+ const p = spec.slice('file:'.length);
70
+ return isAbsolute(p) ? p : resolve(PROFILE, p);
71
+ }
72
+
73
+ // ---------- 读取 profile ----------
74
+ const pkgJsonPath = join(PROFILE, 'package.json');
75
+ if (!existsSync(pkgJsonPath)) {
76
+ console.error(`✗ profile 不存在或缺少 package.json:${PROFILE}`);
77
+ console.error(` → 本机尚未配置该 profile?先执行 dsh plugin --profile web install 完成首次接线,`);
78
+ console.error(` 再重跑本自检;确属无法部署的中间态可 commit --no-verify 并注明。`);
79
+ process.exit(1);
80
+ }
81
+ const profilePkg = JSON.parse(readFileSync(pkgJsonPath, 'utf8'));
82
+ const deps = profilePkg.dependencies || {};
83
+ const pluginDeps = Object.entries(deps).filter(([name]) => !name.startsWith('@') );
84
+
85
+ // 本仓库自身包名:单库布局下 REPO_ROOT 即插件目录(源码 lib 在 REPO_ROOT/lib);
86
+ // 多包布局下 REPO_ROOT/<name>/lib。有 REPO_ROOT/package.json 且 name 匹配时按单库处理。
87
+ let selfName = null;
88
+ try {
89
+ const selfPkgPath = join(REPO_ROOT, 'package.json');
90
+ if (existsSync(selfPkgPath)) selfName = JSON.parse(readFileSync(selfPkgPath, 'utf8')).name || null;
91
+ } catch { /* 忽略:读不到按多包布局 */ }
92
+ function localSrcFor(name) {
93
+ // 单库:被查插件即本仓库自身
94
+ return name === selfName ? join(REPO_ROOT, 'lib') : join(REPO_ROOT, name, 'lib');
95
+ }
96
+
97
+ let failed = 0, checked = 0;
98
+ const results = [];
99
+
100
+ for (const [name, spec] of pluginDeps) {
101
+ if (pkgFilters.length && !pkgFilters.includes(name)) continue;
102
+ checked++;
103
+ const installed = join(PROFILE, 'node_modules', name);
104
+
105
+ if (!spec.startsWith('file:')) {
106
+ // registry 安装:按纪律只在「发版→立即重装」闭环里可信
107
+ const localSrc = localSrcFor(name);
108
+ let note;
109
+ if (existsSync(localSrc) && existsSync(join(installed, 'lib'))) {
110
+ const diffs = diffTrees(localSrc, join(installed, 'lib'));
111
+ if (diffs.length) {
112
+ // 硬拦截点:改了源码未发版却仍 registry 安装 = 同版本号不同内容事故本体
113
+ results.push({ name, status: 'FAIL', msg: `registry 安装且与本仓 lib 有差异(${diffs.length} 个文件):\n ${diffs.slice(0, 10).join('\n ')}${diffs.length > 10 ? `\n …共 ${diffs.length} 项` : ''}\n → 改源码未发版必须改用 file: 安装:dsh plugin --profile web install` });
114
+ failed++; continue;
115
+ }
116
+ note = 'registry 安装,内容与本仓 lib 一致';
117
+ } else {
118
+ note = 'registry 安装(本仓无该插件或未 build,无法比对)';
119
+ }
120
+ results.push({ name, status: 'WARN', msg: `${note};registry 包只在「发版→立即重装」闭环里可信,若已改源码未发版请改用 file: 安装` });
121
+ continue;
122
+ }
123
+
124
+ const src = resolveFileTarget(spec);
125
+
126
+ // 检查 3:profile 内必须是真实目录,不是软链
127
+ if (existsSync(installed) && lstatSync(installed).isSymbolicLink()) {
128
+ results.push({ name, status: 'FAIL', msg: 'profile 内是软链:Node 按 realpath 解析会脱离宿主 fallback,报 Cannot find package' });
129
+ failed++; continue;
130
+ }
131
+
132
+ // 源码 lib vs 部署 lib
133
+ const srcLib = join(src, 'lib');
134
+ if (!existsSync(srcLib)) {
135
+ results.push({ name, status: 'FAIL', msg: `file: 源码缺少 lib/(未 build?):${srcLib}` });
136
+ failed++; continue;
137
+ }
138
+ if (!existsSync(join(installed, 'lib'))) {
139
+ results.push({ name, status: 'FAIL', msg: `profile 内插件不完整(无 lib/):${installed}` });
140
+ failed++; continue;
141
+ }
142
+ const diffs = diffTrees(srcLib, join(installed, 'lib'));
143
+ if (diffs.length) {
144
+ results.push({ name, status: 'FAIL', msg: `源码 lib ≠ 部署 lib(${diffs.length} 个文件差异):\n ${diffs.slice(0, 10).join('\n ')}${diffs.length > 10 ? `\n …共 ${diffs.length} 项` : ''}\n → 改完源码后重新 install:dsh plugin --profile web install` });
145
+ failed++; continue;
146
+ }
147
+
148
+ // 顺带验证 file: 目标确实存在
149
+ if (!existsSync(src)) {
150
+ results.push({ name, status: 'FAIL', msg: `file: 目标不存在:${src}` });
151
+ failed++; continue;
152
+ }
153
+ results.push({ name, status: 'PASS', msg: `file: 安装,源码 lib 与部署 lib 一致(源自 ${src})` });
154
+ }
155
+
156
+ // 检查 2:profile 内 @deepseek-ai/ 无宿主核心包阴影
157
+ const dsaiDir = join(PROFILE, 'node_modules', '@deepseek-ai');
158
+ if (existsSync(dsaiDir)) {
159
+ const present = readdirSync(dsaiDir).filter((n) => !ALLOWED_HOST_PKGS.has(n));
160
+ if (present.length) {
161
+ results.push({ name: '@deepseek-ai/*', status: 'FAIL', msg: `出现非白名单宿主核心包:${present.join(', ')} → 第二套 @deepseek-ai/*,Symbol 错配/400 前兆;用 dsh plugin --profile web install 重装` });
162
+ failed++;
163
+ } else {
164
+ results.push({ name: '@deepseek-ai/*', status: 'PASS', msg: '仅 cosmokit / schemastery,无宿主核心包阴影' });
165
+ }
166
+ }
167
+
168
+ // ---------- 输出 ----------
169
+ console.log(`部署纪律自检(profile: ${PROFILE})\n`);
170
+ for (const r of results) {
171
+ const icon = r.status === 'PASS' ? '✓' : r.status === 'WARN' ? '△' : '✗';
172
+ console.log(`${icon} [${r.status}] ${r.name} — ${r.msg}`);
173
+ }
174
+ if (!checked && !pkgFilters.length) console.log('(profile 内未发现插件依赖)');
175
+ console.log(`\n共 ${results.filter((r) => r.name !== '@deepseek-ai/*').length} 个插件,FAIL ${failed}。`);
176
+ process.exit(failed ? 1 : 0);
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 验证链单源入口(single source of truth)。
4
+ *
5
+ * package.json 的 "test"、.github/workflows/ci.yml 与 .github/workflows/publish.yml 的 Verify
6
+ * 步骤都只调本脚本——"验证链三处一致"由此从纪律约束变成结构保证:链内增删步骤只改这里。
7
+ *
8
+ * 固定步骤:build → typecheck
9
+ * 探测步骤(文件存在才跑,按序):
10
+ * scripts/smoke.mjs → 逻辑冒烟(stub 服务)
11
+ * vitest.config.{ts,mjs,js} → npx vitest run(真实驱动测试)
12
+ * scripts/mount.mjs → 真实 cordis 挂载测试
13
+ * scripts/client-mount.mjs → 浏览器启动路径
14
+ * 退出码:任一步 FAIL = 1(发布前门)。
15
+ *
16
+ * 说明:visual(Playwright 视觉回归)需要运行中 harness,是本地发布前门、不进 CI——
17
+ * 与实践库一致,不在本链内;需要时加 `npm run visual` 自查。
18
+ */
19
+
20
+ import { spawnSync } from 'node:child_process';
21
+ import { existsSync } from 'node:fs';
22
+ import { join, resolve, dirname } from 'node:path';
23
+ import { fileURLToPath } from 'node:url';
24
+
25
+ const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
26
+
27
+ const steps = [
28
+ { name: 'build', cmd: 'npm run build' },
29
+ { name: 'typecheck', cmd: 'npm run typecheck' },
30
+ ];
31
+ if (existsSync(join(ROOT, 'scripts', 'smoke.mjs')))
32
+ steps.push({ name: 'smoke', cmd: 'node scripts/smoke.mjs' });
33
+ if (existsSync(join(ROOT, 'vitest.config.ts')) || existsSync(join(ROOT, 'vitest.config.mjs')) || existsSync(join(ROOT, 'vitest.config.js')))
34
+ steps.push({ name: 'vitest', cmd: 'npx vitest run' });
35
+ if (existsSync(join(ROOT, 'scripts', 'mount.mjs')))
36
+ steps.push({ name: 'mount', cmd: 'node scripts/mount.mjs' });
37
+ if (existsSync(join(ROOT, 'scripts', 'client-mount.mjs')))
38
+ steps.push({ name: 'client-mount', cmd: 'node scripts/client-mount.mjs' });
39
+
40
+ console.log(`验证链(verify.mjs 单源):${steps.map((s) => s.name).join(' → ')}\n`);
41
+
42
+ const failed = [];
43
+ for (const step of steps) {
44
+ const r = spawnSync(step.cmd, { shell: true, stdio: 'inherit', cwd: ROOT });
45
+ if (r.status !== 0) {
46
+ console.error(`\n✗ [FAIL] ${step.name}(exit ${r.status ?? 'signal'})——验证链中断,禁止发布`);
47
+ process.exit(1);
48
+ }
49
+ console.log(`✓ [PASS] ${step.name}`);
50
+ }
51
+
52
+ console.log(`\n验证链全绿(${steps.length} 步)。`);
@@ -0,0 +1,25 @@
1
+ /**
2
+ * dsh-<name> — 插件配置定义
3
+ *
4
+ * schemastery `Config` 是 Loader / settings UI 读取的配置形状声明;
5
+ * resolveConfig() 给出防御性默认值,partial 配置(与测试)也能得到完整结果。
6
+ */
7
+ import z from '@deepseek-ai/schemastery'
8
+
9
+ export const Config = z.object({
10
+ enabled: z.boolean().default(true).description('是否启用'),
11
+ // <配置项:z.boolean()/.number()/.string()/.array(...),均给 .default(...) 与 .description(...)>
12
+ })
13
+
14
+ export interface ConfigType {
15
+ enabled?: boolean
16
+ // <与 Config 一一对应的 TS 类型,全部可选(partial 进,resolve 出)>
17
+ }
18
+
19
+ /** 防御性解析:任何 partial/测试输入都补全为完整配置 */
20
+ export function resolveConfig(config: ConfigType = {}): Required<ConfigType> {
21
+ return {
22
+ enabled: config.enabled ?? true,
23
+ // <逐字段 ?? 默认值,与 Config 的 .default 对齐>
24
+ }
25
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * dsh-<name> — Host half 入口(从零新建骨架)
3
+ *
4
+ * dsh 插件 = 一个 Cordis 插件包:default 导出必须是**插件对象本体**
5
+ * (OBJECT form,绝不是返回 { apply } 的工厂——loader 直接把 module.default
6
+ * 传给 ctx.plugin(),FUNCTION 会被当作插件体调用,工厂被静默忽略:
7
+ * entry 显示 ACTIVE 但 apply 永远不跑,knowledge-sqlite 踩过)。
8
+ */
9
+ import { Context } from '@deepseek-ai/cordis'
10
+ import { Config, resolveConfig, type ConfigType } from './config.ts'
11
+
12
+ export { Config } from './config.ts'
13
+
14
+ export const name = 'dsh-<name>'
15
+
16
+ export default {
17
+ name,
18
+ Config,
19
+ apply(ctx: Context, config: ConfigType = {}): void {
20
+ const cfg = resolveConfig(config)
21
+ if (!cfg.enabled) return
22
+
23
+ // ── 服务访问模式 ──────────────────────────────────────────────
24
+ // 可选服务:ctx.get() + undefined 检查(探针/降级模式)
25
+ const optional = ctx.get('someService')
26
+ if (optional !== undefined) {
27
+ // 有则增强
28
+ }
29
+ // 硬依赖服务:在插件对象上声明 inject: ['xxx'](缺服务时进入等待,
30
+ // Cordis 重挂后自动恢复)——需要时给 default 对象加 inject 字段
31
+
32
+ // ── 生命周期:每个副作用必须可逆 ──────────────────────────────
33
+ // 定时器用 ctx.timeout / ctx.interval(沙箱禁用 setTimeout 等全局)
34
+ // 订阅用 ctx.on(...),保留 disposer 或直接用 ctx.effect() 收口
35
+ // ctx.effect(() => ctx.on('some/event', handler), (disposer) => disposer())
36
+ // stop/update/undefine 时由 Fiber 统一清理
37
+
38
+ // <本插件的实际能力:工具 defineTool→registerTool / 命令 / RPC / Slot UI>
39
+ },
40
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2024",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "lib": ["ES2024", "DOM"],
7
+ "types": ["node"],
8
+ "jsx": "react-jsx",
9
+ "outDir": "lib",
10
+ "rootDir": "src",
11
+ "declaration": true,
12
+ "strict": true,
13
+ "noUnusedLocals": true,
14
+ "noUnusedParameters": true,
15
+ "skipLibCheck": true,
16
+ "esModuleInterop": true,
17
+ "allowImportingTsExtensions": true,
18
+ "rewriteRelativeImportExtensions": true,
19
+ "verbatimModuleSyntax": false
20
+ },
21
+ "include": ["src"]
22
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2024",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "lib": [
7
+ "ES2024",
8
+ "DOM"
9
+ ],
10
+ "jsx": "react-jsx",
11
+ "strict": true,
12
+ "skipLibCheck": true,
13
+ "esModuleInterop": true,
14
+ "allowImportingTsExtensions": true,
15
+ "noEmit": true,
16
+ "types": [
17
+ "node"
18
+ ]
19
+ },
20
+ "include": [
21
+ "src"
22
+ ]
23
+ }