@mycodemap/mycodemap 0.5.2-beta.1 → 2.0.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 (272) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +138 -854
  3. package/README.zh-CN.md +1096 -0
  4. package/dist/cli/commands/analyze-options.d.ts.map +1 -1
  5. package/dist/cli/commands/analyze-options.js +8 -0
  6. package/dist/cli/commands/analyze-options.js.map +1 -1
  7. package/dist/cli/commands/analyze.d.ts.map +1 -1
  8. package/dist/cli/commands/analyze.js +60 -41
  9. package/dist/cli/commands/analyze.js.map +1 -1
  10. package/dist/cli/commands/benchmark.d.ts +8 -0
  11. package/dist/cli/commands/benchmark.d.ts.map +1 -0
  12. package/dist/cli/commands/benchmark.js +150 -0
  13. package/dist/cli/commands/benchmark.js.map +1 -0
  14. package/dist/cli/commands/deps.d.ts +2 -1
  15. package/dist/cli/commands/deps.d.ts.map +1 -1
  16. package/dist/cli/commands/deps.js +107 -78
  17. package/dist/cli/commands/deps.js.map +1 -1
  18. package/dist/cli/commands/doctor.d.ts +3 -0
  19. package/dist/cli/commands/doctor.d.ts.map +1 -0
  20. package/dist/cli/commands/doctor.js +34 -0
  21. package/dist/cli/commands/doctor.js.map +1 -0
  22. package/dist/cli/commands/init.d.ts +7 -2
  23. package/dist/cli/commands/init.d.ts.map +1 -1
  24. package/dist/cli/commands/init.js +22 -34
  25. package/dist/cli/commands/init.js.map +1 -1
  26. package/dist/cli/commands/publish-status.d.ts +31 -0
  27. package/dist/cli/commands/publish-status.d.ts.map +1 -0
  28. package/dist/cli/commands/publish-status.js +101 -0
  29. package/dist/cli/commands/publish-status.js.map +1 -0
  30. package/dist/cli/commands/query.d.ts +1 -0
  31. package/dist/cli/commands/query.d.ts.map +1 -1
  32. package/dist/cli/commands/query.js +123 -140
  33. package/dist/cli/commands/query.js.map +1 -1
  34. package/dist/cli/commands/readiness-gate.d.ts +25 -0
  35. package/dist/cli/commands/readiness-gate.d.ts.map +1 -0
  36. package/dist/cli/commands/readiness-gate.js +197 -0
  37. package/dist/cli/commands/readiness-gate.js.map +1 -0
  38. package/dist/cli/commands/ship/checker.d.ts +4 -9
  39. package/dist/cli/commands/ship/checker.d.ts.map +1 -1
  40. package/dist/cli/commands/ship/checker.js +60 -22
  41. package/dist/cli/commands/ship/checker.js.map +1 -1
  42. package/dist/cli/commands/ship/monitor.d.ts +6 -1
  43. package/dist/cli/commands/ship/monitor.d.ts.map +1 -1
  44. package/dist/cli/commands/ship/monitor.js +223 -46
  45. package/dist/cli/commands/ship/monitor.js.map +1 -1
  46. package/dist/cli/commands/ship/pipeline.d.ts.map +1 -1
  47. package/dist/cli/commands/ship/pipeline.js +14 -5
  48. package/dist/cli/commands/ship/pipeline.js.map +1 -1
  49. package/dist/cli/commands/ship/rules/quality-rules.d.ts +12 -8
  50. package/dist/cli/commands/ship/rules/quality-rules.d.ts.map +1 -1
  51. package/dist/cli/commands/ship/rules/quality-rules.js +49 -34
  52. package/dist/cli/commands/ship/rules/quality-rules.js.map +1 -1
  53. package/dist/cli/config-loader.js +1 -1
  54. package/dist/cli/config-loader.js.map +1 -1
  55. package/dist/cli/doctor/check-agent.d.ts +3 -0
  56. package/dist/cli/doctor/check-agent.d.ts.map +1 -0
  57. package/dist/cli/doctor/check-agent.js +60 -0
  58. package/dist/cli/doctor/check-agent.js.map +1 -0
  59. package/dist/cli/doctor/check-ghost-commands.d.ts +3 -0
  60. package/dist/cli/doctor/check-ghost-commands.d.ts.map +1 -0
  61. package/dist/cli/doctor/check-ghost-commands.js +86 -0
  62. package/dist/cli/doctor/check-ghost-commands.js.map +1 -0
  63. package/dist/cli/doctor/check-native-deps.d.ts +3 -0
  64. package/dist/cli/doctor/check-native-deps.d.ts.map +1 -0
  65. package/dist/cli/doctor/check-native-deps.js +54 -0
  66. package/dist/cli/doctor/check-native-deps.js.map +1 -0
  67. package/dist/cli/doctor/check-workspace-drift.d.ts +3 -0
  68. package/dist/cli/doctor/check-workspace-drift.d.ts.map +1 -0
  69. package/dist/cli/doctor/check-workspace-drift.js +83 -0
  70. package/dist/cli/doctor/check-workspace-drift.js.map +1 -0
  71. package/dist/cli/doctor/formatter.d.ts +20 -0
  72. package/dist/cli/doctor/formatter.d.ts.map +1 -0
  73. package/dist/cli/doctor/formatter.js +91 -0
  74. package/dist/cli/doctor/formatter.js.map +1 -0
  75. package/dist/cli/doctor/index.d.ts +8 -0
  76. package/dist/cli/doctor/index.d.ts.map +1 -0
  77. package/dist/cli/doctor/index.js +9 -0
  78. package/dist/cli/doctor/index.js.map +1 -0
  79. package/dist/cli/doctor/orchestrator.d.ts +3 -0
  80. package/dist/cli/doctor/orchestrator.d.ts.map +1 -0
  81. package/dist/cli/doctor/orchestrator.js +37 -0
  82. package/dist/cli/doctor/orchestrator.js.map +1 -0
  83. package/dist/cli/doctor/types.d.ts +19 -0
  84. package/dist/cli/doctor/types.d.ts.map +1 -0
  85. package/dist/cli/doctor/types.js +4 -0
  86. package/dist/cli/doctor/types.js.map +1 -0
  87. package/dist/cli/first-run-guide.d.ts.map +1 -1
  88. package/dist/cli/first-run-guide.js +10 -12
  89. package/dist/cli/first-run-guide.js.map +1 -1
  90. package/dist/cli/index.js +80 -21
  91. package/dist/cli/index.js.map +1 -1
  92. package/dist/cli/init/hooks.d.ts +17 -0
  93. package/dist/cli/init/hooks.d.ts.map +1 -0
  94. package/dist/cli/init/hooks.js +220 -0
  95. package/dist/cli/init/hooks.js.map +1 -0
  96. package/dist/cli/init/receipt.d.ts +4 -0
  97. package/dist/cli/init/receipt.d.ts.map +1 -0
  98. package/dist/cli/init/receipt.js +117 -0
  99. package/dist/cli/init/receipt.js.map +1 -0
  100. package/dist/cli/init/reconciler.d.ts +44 -0
  101. package/dist/cli/init/reconciler.d.ts.map +1 -0
  102. package/dist/cli/init/reconciler.js +377 -0
  103. package/dist/cli/init/reconciler.js.map +1 -0
  104. package/dist/cli/init/rule-templates.d.ts +9 -0
  105. package/dist/cli/init/rule-templates.d.ts.map +1 -0
  106. package/dist/cli/init/rule-templates.js +105 -0
  107. package/dist/cli/init/rule-templates.js.map +1 -0
  108. package/dist/cli/init/rules.d.ts +13 -0
  109. package/dist/cli/init/rules.d.ts.map +1 -0
  110. package/dist/cli/init/rules.js +113 -0
  111. package/dist/cli/init/rules.js.map +1 -0
  112. package/dist/cli/interface-contract/commands/analyze.d.ts +3 -0
  113. package/dist/cli/interface-contract/commands/analyze.d.ts.map +1 -0
  114. package/dist/cli/interface-contract/commands/analyze.js +138 -0
  115. package/dist/cli/interface-contract/commands/analyze.js.map +1 -0
  116. package/dist/cli/interface-contract/commands/benchmark.d.ts +3 -0
  117. package/dist/cli/interface-contract/commands/benchmark.d.ts.map +1 -0
  118. package/dist/cli/interface-contract/commands/benchmark.js +107 -0
  119. package/dist/cli/interface-contract/commands/benchmark.js.map +1 -0
  120. package/dist/cli/interface-contract/commands/deps.d.ts +3 -0
  121. package/dist/cli/interface-contract/commands/deps.d.ts.map +1 -0
  122. package/dist/cli/interface-contract/commands/deps.js +129 -0
  123. package/dist/cli/interface-contract/commands/deps.js.map +1 -0
  124. package/dist/cli/interface-contract/commands/doctor.d.ts +3 -0
  125. package/dist/cli/interface-contract/commands/doctor.d.ts.map +1 -0
  126. package/dist/cli/interface-contract/commands/doctor.js +59 -0
  127. package/dist/cli/interface-contract/commands/doctor.js.map +1 -0
  128. package/dist/cli/interface-contract/commands/index.d.ts +9 -0
  129. package/dist/cli/interface-contract/commands/index.d.ts.map +1 -0
  130. package/dist/cli/interface-contract/commands/index.js +18 -0
  131. package/dist/cli/interface-contract/commands/index.js.map +1 -0
  132. package/dist/cli/interface-contract/commands/init.d.ts +3 -0
  133. package/dist/cli/interface-contract/commands/init.d.ts.map +1 -0
  134. package/dist/cli/interface-contract/commands/init.js +87 -0
  135. package/dist/cli/interface-contract/commands/init.js.map +1 -0
  136. package/dist/cli/interface-contract/commands/query.d.ts +3 -0
  137. package/dist/cli/interface-contract/commands/query.d.ts.map +1 -0
  138. package/dist/cli/interface-contract/commands/query.js +185 -0
  139. package/dist/cli/interface-contract/commands/query.js.map +1 -0
  140. package/dist/cli/interface-contract/index.d.ts +22 -0
  141. package/dist/cli/interface-contract/index.d.ts.map +1 -0
  142. package/dist/cli/interface-contract/index.js +41 -0
  143. package/dist/cli/interface-contract/index.js.map +1 -0
  144. package/dist/cli/interface-contract/schema.d.ts +30 -0
  145. package/dist/cli/interface-contract/schema.d.ts.map +1 -0
  146. package/dist/cli/interface-contract/schema.js +72 -0
  147. package/dist/cli/interface-contract/schema.js.map +1 -0
  148. package/dist/cli/interface-contract/types.d.ts +76 -0
  149. package/dist/cli/interface-contract/types.d.ts.map +1 -0
  150. package/dist/cli/interface-contract/types.js +4 -0
  151. package/dist/cli/interface-contract/types.js.map +1 -0
  152. package/dist/cli/output/apply-suggestion.d.ts +12 -0
  153. package/dist/cli/output/apply-suggestion.d.ts.map +1 -0
  154. package/dist/cli/output/apply-suggestion.js +29 -0
  155. package/dist/cli/output/apply-suggestion.js.map +1 -0
  156. package/dist/cli/output/error-codes.d.ts +22 -0
  157. package/dist/cli/output/error-codes.d.ts.map +1 -0
  158. package/dist/cli/output/error-codes.js +82 -0
  159. package/dist/cli/output/error-codes.js.map +1 -0
  160. package/dist/cli/output/errors.d.ts +14 -0
  161. package/dist/cli/output/errors.d.ts.map +1 -0
  162. package/dist/cli/output/errors.js +170 -0
  163. package/dist/cli/output/errors.js.map +1 -0
  164. package/dist/cli/output/index.d.ts +13 -0
  165. package/dist/cli/output/index.d.ts.map +1 -0
  166. package/dist/cli/output/index.js +11 -0
  167. package/dist/cli/output/index.js.map +1 -0
  168. package/dist/cli/output/mode.d.ts +12 -0
  169. package/dist/cli/output/mode.d.ts.map +1 -0
  170. package/dist/cli/output/mode.js +23 -0
  171. package/dist/cli/output/mode.js.map +1 -0
  172. package/dist/cli/output/progress.d.ts +9 -0
  173. package/dist/cli/output/progress.d.ts.map +1 -0
  174. package/dist/cli/output/progress.js +65 -0
  175. package/dist/cli/output/progress.js.map +1 -0
  176. package/dist/cli/output/render.d.ts +11 -0
  177. package/dist/cli/output/render.d.ts.map +1 -0
  178. package/dist/cli/output/render.js +18 -0
  179. package/dist/cli/output/render.js.map +1 -0
  180. package/dist/cli/output/types.d.ts +53 -0
  181. package/dist/cli/output/types.d.ts.map +1 -0
  182. package/dist/cli/output/types.js +14 -0
  183. package/dist/cli/output/types.js.map +1 -0
  184. package/dist/cli/output/wasm-fallback.d.ts +13 -0
  185. package/dist/cli/output/wasm-fallback.d.ts.map +1 -0
  186. package/dist/cli/output/wasm-fallback.js +92 -0
  187. package/dist/cli/output/wasm-fallback.js.map +1 -0
  188. package/dist/cli/paths.d.ts +4 -2
  189. package/dist/cli/paths.d.ts.map +1 -1
  190. package/dist/cli/paths.js +13 -5
  191. package/dist/cli/paths.js.map +1 -1
  192. package/dist/cli/tree-sitter-check.d.ts +6 -1
  193. package/dist/cli/tree-sitter-check.d.ts.map +1 -1
  194. package/dist/cli/tree-sitter-check.js +23 -1
  195. package/dist/cli/tree-sitter-check.js.map +1 -1
  196. package/dist/infrastructure/storage/adapters/SQLiteStorage.d.ts.map +1 -1
  197. package/dist/infrastructure/storage/adapters/SQLiteStorage.js +2 -2
  198. package/dist/infrastructure/storage/adapters/SQLiteStorage.js.map +1 -1
  199. package/dist/infrastructure/storage/adapters/sqlite-loader.d.ts +23 -0
  200. package/dist/infrastructure/storage/adapters/sqlite-loader.d.ts.map +1 -0
  201. package/dist/infrastructure/storage/adapters/sqlite-loader.js +210 -0
  202. package/dist/infrastructure/storage/adapters/sqlite-loader.js.map +1 -0
  203. package/dist/orchestrator/test-linker.d.ts.map +1 -1
  204. package/dist/orchestrator/test-linker.js +5 -36
  205. package/dist/orchestrator/test-linker.js.map +1 -1
  206. package/dist/orchestrator/types.d.ts +2 -0
  207. package/dist/orchestrator/types.d.ts.map +1 -1
  208. package/dist/orchestrator/types.js.map +1 -1
  209. package/dist/parser/implementations/tree-sitter-loader.d.ts +16 -0
  210. package/dist/parser/implementations/tree-sitter-loader.d.ts.map +1 -0
  211. package/dist/parser/implementations/tree-sitter-loader.js +105 -0
  212. package/dist/parser/implementations/tree-sitter-loader.js.map +1 -0
  213. package/dist/parser/implementations/tree-sitter-parser.d.ts +3 -0
  214. package/dist/parser/implementations/tree-sitter-parser.d.ts.map +1 -1
  215. package/dist/parser/implementations/tree-sitter-parser.js +8 -3
  216. package/dist/parser/implementations/tree-sitter-parser.js.map +1 -1
  217. package/dist/server/mcp/schema-adapter.d.ts +45 -0
  218. package/dist/server/mcp/schema-adapter.d.ts.map +1 -0
  219. package/dist/server/mcp/schema-adapter.js +290 -0
  220. package/dist/server/mcp/schema-adapter.js.map +1 -0
  221. package/dist/server/mcp/server.d.ts.map +1 -1
  222. package/dist/server/mcp/server.js +32 -2
  223. package/dist/server/mcp/server.js.map +1 -1
  224. package/docs/AI_ASSISTANT_SETUP.md +173 -14
  225. package/docs/README.md +40 -1
  226. package/docs/SETUP_GUIDE.md +23 -26
  227. package/docs/agents/domain.md +36 -0
  228. package/docs/agents/issue-tracker.md +22 -0
  229. package/docs/agents/triage-labels.md +15 -0
  230. package/docs/ai-guide/COMMANDS.md +125 -13
  231. package/docs/ai-guide/INTEGRATION.md +78 -11
  232. package/docs/ai-guide/OUTPUT.md +295 -2
  233. package/docs/ai-guide/PATTERNS.md +3 -3
  234. package/docs/ai-guide/PROMPTS.md +2 -2
  235. package/docs/ai-guide/QUICKSTART.md +41 -5
  236. package/docs/ai-guide/README.md +9 -9
  237. package/docs/archive/ideation/2026-04-15-executable-architecture-constitution-ideation-archive.md +70 -0
  238. package/docs/archive/ideation/2026-04-20-mycodemap-init-enhancements-ideation-archive.md +109 -0
  239. package/docs/archive/ideation/2026-04-22-harness-rules-entry-docs-optimization-ideation.md +102 -0
  240. package/docs/archive/ideation/2026-04-22-rules-claude-agents-optimization-ideation.md +107 -0
  241. package/docs/archive/ideation/2026-04-22-rules-entry-docs-optimization-consolidated-ideation-archive.md +54 -0
  242. package/docs/brainstorms/2026-04-22-rules-entry-docs-phase1-structure-consolidation-requirements.md +110 -0
  243. package/docs/brainstorms/999.1-mycodemap-init-enhancements-requirements.md +166 -0
  244. package/docs/exec-plans/README.md +3 -0
  245. package/docs/ideation/2026-04-15-executable-architecture-constitution-ideation.md +10 -22
  246. package/docs/ideation/2026-04-20-mycodemap-init-enhancements-ideation.md +51 -0
  247. package/docs/ideation/2026-04-22-rules-entry-docs-optimization-consolidated-ideation.md +114 -0
  248. package/docs/ideation/2026-04-29-ux-install-agent-experience-ideation.md +256 -0
  249. package/docs/lesson-learn/2026-04-19-prerelease-trusted-publishing-fix.md +119 -0
  250. package/docs/lesson-learn/image.png +0 -0
  251. package/docs/plans/2026-04-30-install-guide-and-repo-analyzer-design.md +394 -0
  252. package/docs/rules/README.md +5 -1
  253. package/docs/rules/architecture-guardrails.md +2 -1
  254. package/docs/rules/deployment.md +7 -0
  255. package/docs/rules/engineering-with-codex-openai.md +48 -9
  256. package/docs/rules/harness.md +106 -0
  257. package/docs/rules/pre-release-checklist.md +72 -33
  258. package/docs/rules/release.md +303 -0
  259. package/docs/rules/testing.md +70 -0
  260. package/docs/rules/validation.md +16 -7
  261. package/examples/claude/skills/mycodemap-repo-analyzer/SKILL.md +294 -0
  262. package/examples/claude/skills/mycodemap-repo-analyzer/references/analysis-guide.md +166 -0
  263. package/examples/claude/skills/mycodemap-repo-analyzer/references/module-analysis-guide.md +150 -0
  264. package/mycodemap.config.schema.json +1 -1
  265. package/package.json +9 -6
  266. package/scripts/hooks/templates/commit-msg +38 -0
  267. package/scripts/hooks/templates/pre-commit +224 -0
  268. package/scripts/pre-release-check.js +4 -4
  269. package/scripts/release.sh +1 -1
  270. package/scripts/sync-analyze-docs.js +2 -2
  271. package/scripts/validate-docs.js +395 -29
  272. package/docs/references/tmp.md +0 -527
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycodemap/mycodemap",
3
- "version": "0.5.2-beta.1",
3
+ "version": "2.0.0",
4
4
  "description": "TypeScript 代码地图工具 - 为 AI 辅助开发提供结构化上下文",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,6 +22,7 @@
22
22
  "examples/",
23
23
  "scripts/",
24
24
  "README.md",
25
+ "README.zh-CN.md",
25
26
  "LICENSE",
26
27
  "CHANGELOG.md",
27
28
  "mycodemap.config.schema.json"
@@ -34,6 +35,7 @@
34
35
  "docs:check:ai": "node scripts/validate-ai-docs.js",
35
36
  "docs:check:pre-release": "node scripts/pre-release-check.js",
36
37
  "test": "vitest run",
38
+ "test:e2e": "vitest run --config vitest.e2e.config.ts",
37
39
  "lint": "eslint src",
38
40
  "typecheck": "tsc --noEmit",
39
41
  "benchmark": "bash scripts/run-benchmark.sh",
@@ -42,9 +44,7 @@
42
44
  "validate-pack": "node scripts/validate-pack.js",
43
45
  "release": "./scripts/release.sh",
44
46
  "check:all": "npm run typecheck && npm run lint && npm test && npm run docs:check",
45
- "check:architecture": "echo 'dependency-cruiser not installed, run: npm i -D dependency-cruiser'",
46
47
  "check:security": "npm audit",
47
- "check:unused": "echo 'knip not installed, run: npm i -D knip'",
48
48
  "fix:all": "npm run lint -- --fix",
49
49
  "ai:pre-task": "npm run check:all",
50
50
  "ai:post-task": "npm run fix:all && npm run check:all"
@@ -65,6 +65,7 @@
65
65
  "chalk": "^5.3.0",
66
66
  "chokidar": "^3.5.3",
67
67
  "commander": "^11.1.0",
68
+ "dependency-cruiser": "^17.3.10",
68
69
  "globby": "^14.0.0",
69
70
  "hono": "^4.12.8",
70
71
  "ora": "^8.0.1",
@@ -76,17 +77,19 @@
76
77
  },
77
78
  "devDependencies": {
78
79
  "@types/better-sqlite3": "^7.6.13",
79
- "@types/glob": "^8.1.0",
80
80
  "@types/node": "^20.10.0",
81
81
  "@typescript-eslint/eslint-plugin": "^6.21.0",
82
82
  "@typescript-eslint/parser": "^6.21.0",
83
83
  "@vitest/coverage-v8": "^1.6.1",
84
- "dependency-cruiser": "^17.3.10",
85
84
  "eslint": "^8.57.1",
86
85
  "vitest": "^1.1.0"
87
86
  },
87
+ "optionalDependencies": {
88
+ "web-tree-sitter": "^0.24.0",
89
+ "sql.js": "^1.12.0"
90
+ },
88
91
  "engines": {
89
- "node": ">=18.0.0"
92
+ "node": ">=20.0.0"
90
93
  },
91
94
  "publishConfig": {
92
95
  "access": "public",
@@ -0,0 +1,38 @@
1
+ #!/bin/sh
2
+ # Commit-msg hook: 仅验证 Commit 消息格式
3
+
4
+ MSG_FILE=$1
5
+ MSG=$(head -1 "$MSG_FILE")
6
+
7
+ VALID_TAGS="BUGFIX FEATURE REFACTOR CONFIG DOCS DELETE"
8
+
9
+ COMMIT_FILES=$(git diff --cached --name-only --diff-filter=ACM 2>/dev/null || true)
10
+
11
+ ONLY_DOT_DIRS=true
12
+ if [ -n "$COMMIT_FILES" ]; then
13
+ NON_DOT_FILES=$(echo "$COMMIT_FILES" | grep -v '^\.' || true)
14
+ if [ -n "$NON_DOT_FILES" ]; then
15
+ ONLY_DOT_DIRS=false
16
+ fi
17
+ fi
18
+
19
+ if [ "$ONLY_DOT_DIRS" = "true" ]; then
20
+ echo "Note: Commit only contains files in dot-directories, skipping message format check"
21
+ elif ! echo "$MSG" | grep -qE '^\[(BUGFIX|FEATURE|REFACTOR|CONFIG|DOCS|DELETE)\]'; then
22
+ echo "ERROR: Commit message must start with an uppercase tag."
23
+ echo "Format: [TAG] scope: message"
24
+ echo "Valid tags: $VALID_TAGS"
25
+ exit 1
26
+ fi
27
+
28
+ if [ "$ONLY_DOT_DIRS" = "true" ]; then
29
+ echo "Note: Commit only contains files in dot-directories, skipping scope check"
30
+ elif ! echo "$MSG" | grep -qE '^\[(BUGFIX|FEATURE|REFACTOR|CONFIG|DOCS|DELETE)\]\s+[^:]+:\s+.+'; then
31
+ echo "ERROR: scope and message are required."
32
+ echo "Format: [TAG] scope: message"
33
+ echo "Example: [FEATURE] cli: add new command"
34
+ exit 1
35
+ fi
36
+
37
+ echo "Commit message validated"
38
+ exit 0
@@ -0,0 +1,224 @@
1
+ #!/bin/sh
2
+ # Pre-commit hook: 运行测试和文件头检查
3
+
4
+ echo "Running pre-commit checks..."
5
+
6
+ # 1. 运行与变更相关的测试(失败即阻断)
7
+ echo "Running tests for changed files..."
8
+ if [ -f "node_modules/vitest/vitest.mjs" ]; then
9
+ node node_modules/vitest/vitest.mjs run --changed
10
+ else
11
+ if [ ! -e "node_modules/vitest" ]; then
12
+ VITEST_PACKAGE_DIR=$(find node_modules -type d -path '*/.pnpm/*/node_modules/vitest' | head -n 1)
13
+ if [ -n "$VITEST_PACKAGE_DIR" ]; then
14
+ ln -sfn "${VITEST_PACKAGE_DIR#node_modules/}" node_modules/vitest
15
+ fi
16
+ fi
17
+
18
+ if [ -f "node_modules/vitest/vitest.mjs" ]; then
19
+ node node_modules/vitest/vitest.mjs run --changed
20
+ else
21
+ VITEST_ENTRY=$(find node_modules -type f -path '*/.pnpm/*/node_modules/vitest/vitest.mjs' | head -n 1)
22
+ if [ -z "$VITEST_ENTRY" ]; then
23
+ VITEST_ENTRY=$(find node_modules -type f -path '*/.vitest-*/vitest.mjs' | head -n 1)
24
+ fi
25
+
26
+ if [ -n "$VITEST_ENTRY" ]; then
27
+ node "$VITEST_ENTRY" run --changed
28
+ else
29
+ npx --yes vitest run --changed
30
+ fi
31
+ fi
32
+ fi
33
+ if [ $? -ne 0 ]; then
34
+ echo "ERROR: Tests failed, commit rejected"
35
+ exit 1
36
+ fi
37
+
38
+ echo "Tests passed"
39
+
40
+ # 2. repo-local 规则校验(按 hard_gate.mode 决定 report-only / enforce)
41
+ RULE_CONFIG_PATH=".claude/rule-system.config.json"
42
+ RULE_HARD_GATE_MODE="report-only"
43
+
44
+ if [ -f "$RULE_CONFIG_PATH" ]; then
45
+ RULE_HARD_GATE_MODE=$(python3 - <<'PY'
46
+ import json
47
+ from pathlib import Path
48
+
49
+ config_path = Path(".claude/rule-system.config.json")
50
+
51
+ try:
52
+ config = json.loads(config_path.read_text(encoding="utf-8"))
53
+ except Exception:
54
+ print("report-only")
55
+ else:
56
+ print(config.get("hard_gate", {}).get("mode", "report-only"))
57
+ PY
58
+ )
59
+ fi
60
+
61
+ echo "Running repo-local rule validation (mode: $RULE_HARD_GATE_MODE)..."
62
+ case "$RULE_HARD_GATE_MODE" in
63
+ enforce)
64
+ python3 scripts/validate-rules.py code
65
+ VALIDATE_EXIT=$?
66
+ case "$VALIDATE_EXIT" in
67
+ 0)
68
+ echo "Rule validation passed"
69
+ ;;
70
+ 1)
71
+ echo "ERROR: Rule validation found blocking P0 failures, commit rejected"
72
+ exit 1
73
+ ;;
74
+ 2)
75
+ echo "WARNING: Rule validation reported warn-only P1 findings, continuing commit"
76
+ ;;
77
+ 3)
78
+ echo "WARNING: Rule validation reported notice-only P2 findings, continuing commit"
79
+ ;;
80
+ 4)
81
+ echo "ERROR: Rule validation dependencies unavailable, commit rejected"
82
+ exit 1
83
+ ;;
84
+ *)
85
+ echo "ERROR: Rule validation returned unexpected exit code ($VALIDATE_EXIT), commit rejected"
86
+ exit 1
87
+ ;;
88
+ esac
89
+ ;;
90
+ report-only|*)
91
+ if [ "$RULE_HARD_GATE_MODE" != "report-only" ]; then
92
+ echo "WARNING: Unknown hard gate mode '$RULE_HARD_GATE_MODE', defaulting to report-only"
93
+ fi
94
+ python3 scripts/validate-rules.py code --report-only >/dev/null
95
+ VALIDATE_EXIT=$?
96
+ if [ "$VALIDATE_EXIT" -ne 0 ]; then
97
+ echo "WARNING: Rule validation report-only command exited with $VALIDATE_EXIT, continuing commit"
98
+ else
99
+ echo "Rule validation report-only completed"
100
+ fi
101
+ ;;
102
+ esac
103
+
104
+ # 3. 检查 staged 文件数量(初始化 commit 除外)
105
+ MAX_FILES_PER_COMMIT=10
106
+ MAX_FILES_WITH_DOCS=20
107
+
108
+ STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM)
109
+ STAGED_FILE_COUNT=$(echo "$STAGED_FILES" | grep -c '^' || echo 0)
110
+
111
+ ONLY_DOT_DIRS=true
112
+ if [ -n "$STAGED_FILES" ]; then
113
+ NON_DOT_FILES=$(echo "$STAGED_FILES" | grep -v '^\.' || true)
114
+ if [ -n "$NON_DOT_FILES" ]; then
115
+ ONLY_DOT_DIRS=false
116
+ fi
117
+ fi
118
+
119
+ IS_INITIAL_COMMIT=false
120
+ git rev-parse --verify HEAD >/dev/null 2>&1
121
+ if [ $? -ne 0 ]; then
122
+ IS_INITIAL_COMMIT=true
123
+ fi
124
+
125
+ CONTAINS_DOC_FILES=false
126
+ if [ -n "$STAGED_FILES" ]; then
127
+ DOC_FILES=$(echo "$STAGED_FILES" | grep -E '(\.md$|^docs/|^README|^CHANGELOG|^LICENSE)' || true)
128
+ if [ -n "$DOC_FILES" ]; then
129
+ CONTAINS_DOC_FILES=true
130
+ fi
131
+ fi
132
+
133
+ if [ "$CONTAINS_DOC_FILES" = "true" ]; then
134
+ CURRENT_LIMIT=$MAX_FILES_WITH_DOCS
135
+ else
136
+ CURRENT_LIMIT=$MAX_FILES_PER_COMMIT
137
+ fi
138
+
139
+ if [ "$ONLY_DOT_DIRS" = "true" ]; then
140
+ echo "Note: Only dot-directory files staged, skipping count limit check"
141
+ elif [ "$STAGED_FILE_COUNT" -gt "$CURRENT_LIMIT" ] && [ "$IS_INITIAL_COMMIT" = "false" ]; then
142
+ echo ""
143
+ echo "WARNING: Staged files count ($STAGED_FILE_COUNT) exceeds limit ($CURRENT_LIMIT)"
144
+ echo ""
145
+ if [ "$CONTAINS_DOC_FILES" = "true" ]; then
146
+ echo "Note: This commit contains documentation files, so the limit is increased to $MAX_FILES_WITH_DOCS."
147
+ else
148
+ echo "Single commit should not contain more than $MAX_FILES_PER_COMMIT files."
149
+ fi
150
+ echo "Please consider splitting your changes into smaller, focused commits."
151
+ echo ""
152
+ echo "If you have a very good reason for this large commit, you can bypass"
153
+ echo "this warning with: git commit --no-verify"
154
+ echo ""
155
+ echo "Staged files:"
156
+ git diff --cached --name-only --diff-filter=ACM
157
+ echo ""
158
+ exit 1
159
+ fi
160
+
161
+ # 4. 检查文件头注释(只检查 staged 的 TS 源文件,豁免 . 开头目录)
162
+ echo "Checking file headers..."
163
+ if [ "$ONLY_DOT_DIRS" = "true" ]; then
164
+ echo "Note: Only dot-directory files staged, skipping header check"
165
+ STAGED_TS_FILES=""
166
+ else
167
+ STAGED_TS_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.ts$' | grep -v '\.test\.ts$' | grep -v '\.d\.ts$')
168
+ fi
169
+
170
+ if [ -n "$STAGED_TS_FILES" ]; then
171
+ MISSING_HEADERS=0
172
+
173
+ for file in $STAGED_TS_FILES; do
174
+ if [ ! -f "$file" ]; then
175
+ continue
176
+ fi
177
+
178
+ HEAD_CONTENT=$(head -10 "$file")
179
+
180
+ if ! echo "$HEAD_CONTENT" | grep -q '\[META\]'; then
181
+ echo "ERROR: $file missing [META] comment"
182
+ MISSING_HEADERS=$((MISSING_HEADERS + 1))
183
+ fi
184
+
185
+ if ! echo "$HEAD_CONTENT" | grep -q '\[WHY\]'; then
186
+ echo "ERROR: $file missing [WHY] comment"
187
+ MISSING_HEADERS=$((MISSING_HEADERS + 1))
188
+ fi
189
+ done
190
+
191
+ if [ $MISSING_HEADERS -gt 0 ]; then
192
+ echo ""
193
+ echo "Add header comments at file top:"
194
+ echo "// [META] since:YYYY-MM | owner:team | stable:false"
195
+ echo "// [WHY] Explain why this file exists"
196
+ exit 1
197
+ fi
198
+ fi
199
+
200
+ echo "File headers passed"
201
+
202
+ # 5. 检查文档与 CLI 护栏(仅在相关文件变更时阻断)
203
+ DOC_GUARDRAIL_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '^(README\.md|package\.json|docs/|src/cli/index\.ts|vitest\.config\.ts|vitest\.benchmark\.config\.ts|\.github/workflows/ci-gateway\.yml)$' || true)
204
+
205
+ if [ -n "$DOC_GUARDRAIL_FILES" ]; then
206
+ echo "Checking documentation guardrails..."
207
+ npm run docs:check
208
+ if [ $? -ne 0 ]; then
209
+ echo "ERROR: Documentation guardrails failed, commit rejected"
210
+ exit 1
211
+ fi
212
+ fi
213
+
214
+ echo "Documentation guardrails passed"
215
+
216
+ # 6. 生成 AI 饲料(警告级,不阻断)
217
+ echo "Generating AI feed..."
218
+ npx mycodemap generate --quiet >/dev/null 2>&1 &
219
+ if [ $? -ne 0 ]; then
220
+ echo "WARNING: Failed to start AI feed generation"
221
+ fi
222
+
223
+ echo "Pre-commit checks passed"
224
+ exit 0
@@ -710,10 +710,10 @@ async function runPreReleaseChecks() {
710
710
  const pkgVersion = JSON.parse(pkg).version;
711
711
  console.log(`\n当前版本: v${pkgVersion}`);
712
712
  console.log('\n📋 发布步骤:');
713
- console.log(' 1. npm run docs:check:pre-release # 运行此检查');
714
- console.log(' 2. ./scripts/release.sh patch|minor|major # 或指定版本');
715
- console.log(' 3. git push origin main --tags # 推送 tag');
716
- console.log(' 4. GitHub Actions 自动: 构建 → 测试 → 发布 → 创建 Release');
713
+ console.log(' 1. /release vX.Y # 统一入口:readiness → closeout → 双确认门');
714
+ console.log(' 2. Gate #2 通过后委托 ./scripts/release.sh X.Y.0 # 机械 helper');
715
+ console.log(' 3. 推送 tag 后由 .github/workflows/publish.yml 自动: 构建 → 测试 → 发布 → 创建 Release');
716
+ console.log(' 4. 若不是 milestone-bound release,才使用人工受控的例外流程');
717
717
  console.log('\n🔗 相关链接:');
718
718
  console.log(` - GitHub Actions: https://github.com/mycodemap/mycodemap/actions`);
719
719
  console.log(` - NPM 包: https://www.npmjs.com/package/@mycodemap/mycodemap`);
@@ -109,7 +109,7 @@ echo ""
109
109
  # 步骤 2: 提交版本更新
110
110
  echo -e "${BLUE}2/5 提交版本更新...${NC}"
111
111
  git add package.json package-lock.json
112
- git commit -m "[RELEASE] bump version to v$NEW_VERSION"
112
+ git commit -m "[CONFIG] version: bump to v$NEW_VERSION"
113
113
  echo -e "${GREEN} ✅ 已提交版本更新${NC}"
114
114
  echo ""
115
115
 
@@ -299,12 +299,12 @@ function renderAnalyzeOptionsTable(rootDir) {
299
299
 
300
300
  const ANALYZE_DOC_BLOCKS = [
301
301
  {
302
- relativePath: 'README.md',
302
+ relativePath: 'README.zh-CN.md',
303
303
  marker: 'analyze-readme-examples',
304
304
  render: () => renderReadmeAnalyzeExamples(),
305
305
  },
306
306
  {
307
- relativePath: 'README.md',
307
+ relativePath: 'README.zh-CN.md',
308
308
  marker: 'analyze-readme-options',
309
309
  render: rootDir => renderAnalyzeOptionsTable(rootDir),
310
310
  },