@chongyan/autospec 1.0.1 → 1.0.2

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 (283) hide show
  1. package/LICENSE +21 -21
  2. package/README.en.md +447 -321
  3. package/README.md +418 -286
  4. package/knowledge/01-principles/00-principles-hierarchy.md +247 -0
  5. package/knowledge/01-principles/01-first-principles.md +241 -0
  6. package/knowledge/01-principles/02-strategic-principles.md +286 -0
  7. package/knowledge/01-principles/03-tactical-principles.md +385 -0
  8. package/knowledge/01-principles/04-operational-principles.md +275 -0
  9. package/knowledge/01-principles/05-domain-principles.md +539 -0
  10. package/knowledge/01-principles/06-methodology-principles.md +281 -0
  11. package/knowledge/01-principles/07-cognitive-principles.md +277 -0
  12. package/knowledge/01-principles/08-auto-fix-principles.md +320 -0
  13. package/knowledge/01-principles/09-constitution.md +220 -0
  14. package/knowledge/{principles/evolution.md → 01-principles/10-evolution-mechanism.md} +160 -14
  15. package/knowledge/01-principles/README.en.md +385 -0
  16. package/knowledge/01-principles/README.md +385 -0
  17. package/knowledge/{process/overview.md → 02-process/00-overview.md} +90 -5
  18. package/knowledge/02-process/README.en.md +143 -0
  19. package/knowledge/02-process/README.md +186 -0
  20. package/knowledge/{guides/support/pipeline-protocol.md → 03-guides/00-pipeline-protocol.md} +10 -10
  21. package/knowledge/{guides/support/team-orchestrator.md → 03-guides/01-team-orchestrator.md} +53 -8
  22. package/knowledge/{guides/stages/requirement-analyzer.md → 03-guides/02-analyze-requirement.md} +3 -3
  23. package/knowledge/{guides/stages/ai-effect-evaluator.md → 03-guides/08-evaluate-ai-effect.md} +14 -7
  24. package/knowledge/{guides/support/skill-distiller.md → 03-guides/19-distill-skill.md} +3 -3
  25. package/knowledge/{guides/support/skill-updater.md → 03-guides/20-update-skill.md} +1 -1
  26. package/knowledge/{guides/support/methodology-extractor.md → 03-guides/22-extract-methodology.md} +2 -2
  27. package/knowledge/{guides/support/complexity-assessor.md → 03-guides/24-assess-complexity.md} +6 -4
  28. package/knowledge/{guides/support/tech-stack-analyzer.md → 03-guides/26-analyze-tech-stack.md} +1 -1
  29. package/knowledge/{guides/domain-driven-design.md → 03-guides/42-apply-ddd.md} +1 -1
  30. package/knowledge/{process/ai-sdlc.md → 03-guides/43-run-ai-sdlc.md} +1 -1
  31. package/knowledge/{guides/knowledge-management.md → 03-guides/44-manage-knowledge.md} +4 -4
  32. package/knowledge/03-guides/README.en.md +212 -0
  33. package/knowledge/03-guides/README.md +212 -0
  34. package/knowledge/{checklists/requirement.md → 04-checklists/00-requirement.md} +1 -1
  35. package/knowledge/{checklists/design.md → 04-checklists/01-design.md} +1 -1
  36. package/knowledge/{checklists/code.md → 04-checklists/02-code.md} +16 -1
  37. package/knowledge/{checklists/release.md → 04-checklists/04-release.md} +1 -1
  38. package/knowledge/04-checklists/README.en.md +119 -0
  39. package/knowledge/04-checklists/README.md +123 -0
  40. package/knowledge/{config/validation-patterns.yaml → 05-config/00-validation-patterns.yaml} +1 -1
  41. package/knowledge/{config/team-tasks.yaml → 05-config/02-team-tasks.yaml} +2 -2
  42. package/knowledge/05-config/03-role-composition.yaml +346 -0
  43. package/knowledge/{config/skill-compositions.yaml → 05-config/05-skill-compositions.yaml} +24 -24
  44. package/knowledge/05-config/README.en.md +54 -0
  45. package/knowledge/05-config/README.md +132 -0
  46. package/knowledge/06-environment/00-template-registry.md +310 -0
  47. package/knowledge/06-environment/01-detection-patterns.yaml +1692 -0
  48. package/knowledge/{environment → 06-environment}/README.en.md +4 -0
  49. package/knowledge/{environment → 06-environment}/README.md +66 -25
  50. package/knowledge/{standards/coding-style.md → 07-standards/00-coding-style.md} +123 -4
  51. package/knowledge/{standards/code-review.md → 07-standards/01-code-review.md} +3 -3
  52. package/knowledge/{standards/data-consistency.md → 07-standards/02-data-consistency.md} +1 -1
  53. package/knowledge/{standards/document-versioning.md → 07-standards/03-document-versioning.md} +1 -1
  54. package/knowledge/{standards/risk-detection.md → 07-standards/04-risk-detection.md} +5 -5
  55. package/knowledge/07-standards/README.en.md +119 -0
  56. package/knowledge/07-standards/README.md +123 -0
  57. package/knowledge/08-organization/00-vision-mission.md +113 -0
  58. package/knowledge/{organization/ai-native-team.md → 08-organization/01-ai-native-culture.md} +1 -1
  59. package/knowledge/{organization/team-metrics.md → 08-organization/02-team-metrics.md} +1 -1
  60. package/knowledge/08-organization/03-committee-structure.md +54 -0
  61. package/knowledge/08-organization/04-governance-metrics.md +55 -0
  62. package/knowledge/08-organization/05-improvement-process.md +71 -0
  63. package/knowledge/08-organization/README.en.md +165 -0
  64. package/knowledge/08-organization/README.md +165 -0
  65. package/knowledge/09-templates/00-requirement-proposal.md +344 -0
  66. package/knowledge/09-templates/01-architecture-design.md +494 -0
  67. package/knowledge/09-templates/02-api-design.md +408 -0
  68. package/knowledge/09-templates/03-database-design.md +313 -0
  69. package/knowledge/09-templates/04-product-design.md +237 -0
  70. package/knowledge/09-templates/05-domain-business.md +388 -0
  71. package/knowledge/09-templates/06-test-design.md +268 -0
  72. package/knowledge/09-templates/07-evaluation-design.md +372 -0
  73. package/knowledge/09-templates/08-component-knowledge.md +272 -0
  74. package/knowledge/09-templates/09-best-practices.md +218 -0
  75. package/knowledge/{environment/middleware-knowledge.md → 09-templates/10-middleware-knowledge.md} +106 -1
  76. package/knowledge/09-templates/README.en.md +222 -0
  77. package/knowledge/09-templates/README.md +216 -0
  78. package/knowledge/README.en.md +372 -0
  79. package/knowledge/README.md +354 -99
  80. package/package.json +1 -1
  81. package/plugins/.claude-plugin/plugin.json +460 -81
  82. package/plugins/agents/roles/ceo.md +1 -1
  83. package/plugins/agents/roles/product-owner.md +1 -1
  84. package/plugins/agents/roles/tech-lead.md +1 -1
  85. package/plugins/agents/support/consistency-checker.md +36 -3
  86. package/plugins/agents/support/monitoring-agent.md +215 -0
  87. package/plugins/agents/support/safety-auditor.md +2 -2
  88. package/plugins/agents/support/stage-gate-evaluator.md +95 -11
  89. package/plugins/agents/support/test-coverage-reviewer.md +1 -1
  90. package/plugins/benchmarks/templates/README.md +165 -13
  91. package/plugins/benchmarks/templates/commands/apply-template.yaml +108 -0
  92. package/plugins/benchmarks/templates/commands/archive-template.yaml +65 -0
  93. package/plugins/benchmarks/templates/commands/env-export-template.yaml +64 -0
  94. package/plugins/benchmarks/templates/commands/env-sync-template.yaml +104 -0
  95. package/plugins/benchmarks/templates/commands/env-template-template.yaml +96 -0
  96. package/plugins/benchmarks/templates/commands/env-template.yaml +58 -0
  97. package/plugins/benchmarks/templates/commands/env-update-template.yaml +110 -0
  98. package/plugins/benchmarks/templates/commands/env-validate-template.yaml +95 -0
  99. package/plugins/benchmarks/templates/commands/field-evolve-template.yaml +104 -0
  100. package/plugins/benchmarks/templates/commands/project-evolve-template.yaml +104 -0
  101. package/plugins/benchmarks/templates/commands/propose-template.yaml +88 -0
  102. package/plugins/benchmarks/templates/commands/review-template.yaml +124 -0
  103. package/plugins/benchmarks/templates/commands/run-template.yaml +127 -0
  104. package/plugins/benchmarks/templates/commands/test-template.yaml +149 -0
  105. package/plugins/benchmarks/templates/pipeline/experiment-template.yaml +92 -0
  106. package/plugins/benchmarks/templates/pipeline/hotfix-template.yaml +81 -0
  107. package/plugins/benchmarks/templates/skills/agile-iteration-template.yaml +78 -0
  108. package/plugins/benchmarks/templates/skills/benchmark-executor-template.yaml +114 -0
  109. package/plugins/benchmarks/templates/skills/benchmark-generator-template.yaml +52 -0
  110. package/plugins/benchmarks/templates/skills/delivery-stage-template.yaml +130 -0
  111. package/plugins/benchmarks/templates/skills/design-stage-template.yaml +131 -0
  112. package/plugins/benchmarks/templates/skills/experiment-iteration-template.yaml +60 -0
  113. package/plugins/benchmarks/templates/skills/exploration-phase-template.yaml +114 -0
  114. package/plugins/benchmarks/templates/skills/field-evolve-analyzer-template.yaml +51 -0
  115. package/plugins/benchmarks/templates/skills/field-evolve-distiller-template.yaml +34 -0
  116. package/plugins/benchmarks/templates/skills/field-evolve-executor-template.yaml +50 -0
  117. package/plugins/benchmarks/templates/skills/field-evolve-fixer-template.yaml +52 -0
  118. package/plugins/benchmarks/templates/skills/field-evolve-learner-template.yaml +33 -0
  119. package/plugins/benchmarks/templates/skills/field-evolve-scanner-template.yaml +74 -0
  120. package/plugins/benchmarks/templates/skills/field-evolve-template.yaml +71 -0
  121. package/plugins/benchmarks/templates/skills/field-evolve-verifier-template.yaml +51 -0
  122. package/plugins/benchmarks/templates/skills/hotfix-iteration-template.yaml +54 -0
  123. package/plugins/benchmarks/templates/skills/implementation-stage-template.yaml +127 -0
  124. package/plugins/benchmarks/templates/skills/layer1-validation-template.yaml +121 -0
  125. package/plugins/benchmarks/templates/skills/project-evolve-analyzer-template.yaml +51 -0
  126. package/plugins/benchmarks/templates/skills/project-evolve-fixer-template.yaml +52 -0
  127. package/plugins/benchmarks/templates/skills/project-evolve-generator-template.yaml +34 -0
  128. package/plugins/benchmarks/templates/skills/project-evolve-learner-template.yaml +50 -0
  129. package/plugins/benchmarks/templates/skills/project-evolve-reviewer-template.yaml +50 -0
  130. package/plugins/benchmarks/templates/skills/project-evolve-scanner-template.yaml +75 -0
  131. package/plugins/benchmarks/templates/skills/project-evolve-template.yaml +72 -0
  132. package/plugins/benchmarks/templates/skills/project-evolve-verifier-template.yaml +51 -0
  133. package/plugins/benchmarks/templates/skills/skill-forge-template.yaml +117 -0
  134. package/plugins/benchmarks/templates/skills/startup-guard-template.yaml +103 -0
  135. package/plugins/benchmarks/templates/skills/testing-stage-template.yaml +146 -0
  136. package/plugins/benchmarks/templates/skills/waterfall-iteration-template.yaml +55 -0
  137. package/plugins/commands/README.en.md +2 -2
  138. package/plugins/commands/README.md +2 -2
  139. package/plugins/commands/apply.md +102 -16
  140. package/plugins/commands/archive.md +60 -4
  141. package/plugins/commands/env-sync.md +1047 -406
  142. package/plugins/commands/env-template.md +11 -135
  143. package/plugins/commands/env-update.md +1 -1
  144. package/plugins/commands/env-validate.md +3 -3
  145. package/plugins/commands/explore.md +118 -1
  146. package/plugins/commands/field-evolve.md +51 -175
  147. package/plugins/commands/project-evolve.md +167 -68
  148. package/plugins/commands/propose.md +97 -6
  149. package/plugins/commands/review.md +5 -5
  150. package/plugins/commands/run.md +841 -13
  151. package/plugins/commands/status.md +138 -17
  152. package/plugins/commands/test.md +389 -0
  153. package/plugins/hooks/constitution-guard.js +1 -1
  154. package/plugins/hooks/environment-autocommit.js +366 -24
  155. package/plugins/hooks/environment-manager.js +3 -2
  156. package/plugins/hooks/execution-tracker.js +109 -4
  157. package/plugins/hooks/layer1-validator.js +117 -1
  158. package/plugins/hooks/lib/auto-fix-loop.js +605 -0
  159. package/plugins/hooks/lib/environment-config-loader.js +11 -7
  160. package/plugins/hooks/lib/hook-state-manager.js +98 -0
  161. package/plugins/hooks/lib/memory-extractor.js +27 -5
  162. package/plugins/hooks/lib/memory-manager.js +1 -1
  163. package/plugins/hooks/lib/test-auto-fix.test.js +194 -0
  164. package/plugins/hooks/monitoring-trigger.js +467 -0
  165. package/plugins/skills/README.en.md +15 -3
  166. package/plugins/skills/README.md +21 -11
  167. package/plugins/skills/agile-iteration/SKILL.md +187 -0
  168. package/plugins/skills/delivery-stage/SKILL.md +133 -12
  169. package/plugins/skills/design-stage/SKILL.md +103 -12
  170. package/plugins/skills/experiment-evaluator/SKILL.md +271 -0
  171. package/plugins/skills/experiment-iteration/SKILL.md +154 -0
  172. package/plugins/skills/exploration-phase/SKILL.md +93 -10
  173. package/plugins/skills/field-evolve-analyzer/SKILL.md +65 -0
  174. package/plugins/skills/field-evolve-distiller/SKILL.md +66 -0
  175. package/plugins/skills/field-evolve-executor/SKILL.md +94 -0
  176. package/plugins/skills/field-evolve-executor/executor.js +342 -0
  177. package/plugins/skills/field-evolve-fixer/SKILL.md +69 -0
  178. package/plugins/skills/field-evolve-learner/SKILL.md +65 -0
  179. package/plugins/skills/field-evolve-scanner/SKILL.md +87 -0
  180. package/plugins/skills/field-evolve-scanner/scripts/fallback-scanner.js +288 -0
  181. package/plugins/skills/field-evolve-verifier/SKILL.md +64 -0
  182. package/plugins/skills/hotfix-iteration/SKILL.md +279 -0
  183. package/plugins/skills/implementation-stage/SKILL.md +156 -15
  184. package/plugins/skills/layer1-validation/SKILL.md +1 -1
  185. package/plugins/skills/pending-dashboard/SKILL.md +9 -8
  186. package/plugins/skills/project-evolve-analyzer/SKILL.md +95 -0
  187. package/plugins/skills/project-evolve-fixer/SKILL.md +99 -0
  188. package/plugins/skills/project-evolve-generator/SKILL.md +149 -0
  189. package/plugins/skills/project-evolve-learner/SKILL.md +103 -0
  190. package/plugins/skills/project-evolve-reviewer/SKILL.md +104 -0
  191. package/plugins/skills/project-evolve-scanner/SKILL.md +95 -0
  192. package/plugins/skills/project-evolve-scanner/scripts/dependency-reuse-checker.js +395 -0
  193. package/plugins/skills/project-evolve-scanner/scripts/subsystem-coverage.js +315 -0
  194. package/plugins/skills/project-evolve-verifier/SKILL.md +105 -0
  195. package/plugins/skills/requirement-stage/SKILL.md +47 -13
  196. package/plugins/skills/skill-forge/SKILL.md +2 -2
  197. package/plugins/skills/testing-stage/SKILL.md +583 -8
  198. package/plugins/skills/waterfall-iteration/SKILL.md +115 -0
  199. package/scripts/cli/index.js +1 -1
  200. package/scripts/cli/init.js +30 -4
  201. package/scripts/cli/list.js +3 -2
  202. package/scripts/config/commands.config.js +8 -8
  203. package/scripts/config/hooks.config.js +1 -1
  204. package/scripts/install/constants.js +204 -165
  205. package/scripts/state.js +210 -1
  206. package/knowledge/config/README.en.md +0 -44
  207. package/knowledge/config/README.md +0 -44
  208. package/knowledge/config/role-composition.yaml +0 -98
  209. package/knowledge/config/team-triggers.yaml +0 -198
  210. package/knowledge/domain/README.md +0 -115
  211. package/knowledge/domain/flows/README.md +0 -194
  212. package/knowledge/domain/glossary.md +0 -143
  213. package/knowledge/domain/rules.md +0 -138
  214. package/knowledge/environment/component-knowledge.md +0 -316
  215. package/knowledge/environment/detection-patterns.yaml +0 -502
  216. package/knowledge/environment/template-registry.md +0 -321
  217. package/knowledge/guides/requirement-engineering.md +0 -329
  218. package/knowledge/guides/system-design.md +0 -352
  219. package/knowledge/principles/constitution.md +0 -134
  220. package/knowledge/principles/core-principles.md +0 -368
  221. package/knowledge/principles/design-philosophy.md +0 -877
  222. package/knowledge/process/README.en.md +0 -38
  223. package/knowledge/process/README.md +0 -48
  224. package/knowledge/templates/ai-evaluation.md +0 -150
  225. package/knowledge/templates/api-design.md +0 -117
  226. package/knowledge/templates/database-design.md +0 -132
  227. package/knowledge/templates/domain-driven-design.md +0 -321
  228. package/knowledge/templates/product-proposal.md +0 -201
  229. package/knowledge/templates/system-design.md +0 -227
  230. package/knowledge/templates/task-breakdown.md +0 -107
  231. package/knowledge/templates/test-case.md +0 -170
  232. package/plugins/commands/validate.md +0 -108
  233. package/plugins/skills/benchmark-executor/README.md +0 -93
  234. package/plugins/skills/evolution-process/SKILL.md +0 -291
  235. package/plugins/skills/project-evolution/SKILL.md +0 -847
  236. package/scripts/evolution/evolution-router.js +0 -273
  237. package/scripts/evolution/evolution-signal-collector.js +0 -307
  238. package/scripts/evolution/knowledge-loader.js +0 -346
  239. package/scripts/evolution/marketplace.js +0 -317
  240. package/scripts/evolution/version-manager.js +0 -371
  241. /package/knowledge/{process → 02-process}/01-requirement.md +0 -0
  242. /package/knowledge/{process → 02-process}/02-design.md +0 -0
  243. /package/knowledge/{process → 02-process}/03-implementation.md +0 -0
  244. /package/knowledge/{process → 02-process}/04-review.md +0 -0
  245. /package/knowledge/{process → 02-process}/05-testing.md +0 -0
  246. /package/knowledge/{process → 02-process}/06-delivery.md +0 -0
  247. /package/knowledge/{guides/stages/design-planner.md → 03-guides/03-design-solution.md} +0 -0
  248. /package/knowledge/{guides/stages/code-implementer.md → 03-guides/04-implement-code.md} +0 -0
  249. /package/knowledge/{guides/stages/test-planner.md → 03-guides/05-plan-testing.md} +0 -0
  250. /package/knowledge/{guides/stages/test-generator.md → 03-guides/06-generate-tests.md} +0 -0
  251. /package/knowledge/{guides/stages/release-checker.md → 03-guides/07-check-release.md} +0 -0
  252. /package/knowledge/{guides/stages/requirement-reviewer.md → 03-guides/09-review-requirement.md} +0 -0
  253. /package/knowledge/{guides/stages/design-reviewer.md → 03-guides/10-review-design.md} +0 -0
  254. /package/knowledge/{guides/stages/code-reviewer.md → 03-guides/11-review-code.md} +0 -0
  255. /package/knowledge/{guides/stages/test-reviewer.md → 03-guides/12-review-testing.md} +0 -0
  256. /package/knowledge/{guides/stages/security-reviewer.md → 03-guides/13-audit-security.md} +0 -0
  257. /package/knowledge/{guides/stages/consistency-checker.md → 03-guides/14-check-consistency.md} +0 -0
  258. /package/knowledge/{guides/stages/unit-test-runner.md → 03-guides/15-run-unit-tests.md} +0 -0
  259. /package/knowledge/{guides/stages/integration-test-runner.md → 03-guides/16-run-integration-tests.md} +0 -0
  260. /package/knowledge/{guides/stages/test-context-analyzer.md → 03-guides/17-analyze-test-context.md} +0 -0
  261. /package/knowledge/{guides/support/practice-logger.md → 03-guides/18-log-practice.md} +0 -0
  262. /package/knowledge/{guides/support/skill-validator.md → 03-guides/21-validate-skill.md} +0 -0
  263. /package/knowledge/{guides/support/scope-inference.md → 03-guides/23-infer-scope.md} +0 -0
  264. /package/knowledge/{guides/support/component-discovery.md → 03-guides/25-discover-component.md} +0 -0
  265. /package/knowledge/{guides/support/environment-scanner.md → 03-guides/27-scan-environment.md} +0 -0
  266. /package/knowledge/{guides/support/environment-validator.md → 03-guides/28-validate-environment.md} +0 -0
  267. /package/knowledge/{guides/support/knowledge-generator.md → 03-guides/29-generate-knowledge.md} +0 -0
  268. /package/knowledge/{guides/support/ai-capability-analyzer.md → 03-guides/30-analyze-ai-capability.md} +0 -0
  269. /package/knowledge/{guides/support/ai-component-analyzer.md → 03-guides/31-analyze-ai-component.md} +0 -0
  270. /package/knowledge/{guides/support/ai-agent-analyzer.md → 03-guides/32-analyze-ai-agent.md} +0 -0
  271. /package/knowledge/{guides/support/ai-rag-analyzer.md → 03-guides/33-analyze-ai-rag.md} +0 -0
  272. /package/knowledge/{guides/support/ai-task-assessor.md → 03-guides/34-assess-ai-task.md} +0 -0
  273. /package/knowledge/{guides/support/ai-pipeline-evaluator.md → 03-guides/35-evaluate-ai-pipeline.md} +0 -0
  274. /package/knowledge/{guides/support/ai-artifact-evaluator.md → 03-guides/36-evaluate-ai-artifact.md} +0 -0
  275. /package/knowledge/{guides/support/ai-evaluation-planner.md → 03-guides/37-plan-ai-evaluation.md} +0 -0
  276. /package/knowledge/{guides/support/ai-path-evaluator.md → 03-guides/38-evaluate-ai-path.md} +0 -0
  277. /package/knowledge/{guides/support/ai-data-validator.md → 03-guides/39-validate-ai-data.md} +0 -0
  278. /package/knowledge/{guides/support/ai-anomaly-analyzer.md → 03-guides/40-detect-ai-anomaly.md} +0 -0
  279. /package/knowledge/{guides/support/ai-test-diagnostics.md → 03-guides/41-diagnose-ai-test.md} +0 -0
  280. /package/knowledge/{guides/support/test-runner.md → 03-guides/45-test-runner.md} +0 -0
  281. /package/knowledge/{checklists/test.md → 04-checklists/03-test.md} +0 -0
  282. /package/knowledge/{config/team-stage.yaml → 05-config/01-team-stage.yaml} +0 -0
  283. /package/knowledge/{config/role-extensions.yaml → 05-config/04-role-extensions.yaml} +0 -0
@@ -1,346 +0,0 @@
1
- /**
2
- * Knowledge Loader - 知识加载器
3
- *
4
- * 实现三级优先级加载:项目 > 用户全局 > 组织
5
- * 集成记忆模块的全局路径和双模式逻辑
6
- */
7
-
8
- import fs from 'fs';
9
- import path from 'path';
10
- import os from 'os';
11
- import {
12
- GLOBAL_AUTOSPEC_DIR,
13
- GLOBAL_AUTOSPEC_SUBDIRS,
14
- ORG_AUTOSPEC_DIR,
15
- ORG_AUTOSPEC_SUBDIRS,
16
- KNOWLEDGE_SCOPE,
17
- KNOWLEDGE_ZONES
18
- } from '../install/constants.js';
19
-
20
- // 缓存
21
- const knowledgeCache = new Map();
22
- const CACHE_TTL = 5000; // 5秒缓存
23
-
24
- /**
25
- * 获取全局知识库根目录
26
- * @returns {string} 全局知识库根目录
27
- */
28
- export function getGlobalKnowledgeRoot() {
29
- return path.join(os.homedir(), GLOBAL_AUTOSPEC_DIR);
30
- }
31
-
32
- /**
33
- * 获取组织知识库根目录
34
- * @param {string} orgName - 组织名称
35
- * @returns {string} 组织知识库根目录
36
- */
37
- export function getOrgKnowledgeRoot(orgName) {
38
- return path.join(os.homedir(), ORG_AUTOSPEC_DIR, orgName);
39
- }
40
-
41
- /**
42
- * 获取项目知识库根目录
43
- * @param {string} projectRoot - 项目根目录
44
- * @returns {string} 项目知识库根目录
45
- */
46
- export function getProjectKnowledgeRoot(projectRoot) {
47
- return path.join(projectRoot, '.autospec');
48
- }
49
-
50
- /**
51
- * 解析知识文件路径
52
- * @param {string} scope - 作用域 (global|org|project)
53
- * @param {string} type - 知识类型 (knowledge|skills|roles|environment)
54
- * @param {string} name - 知识名称
55
- * @param {Object} options - 选项
56
- * @returns {string} 完整文件路径
57
- */
58
- export function resolveKnowledgePath(scope, type, name, options = {}) {
59
- const { projectRoot = '.', orgName = null } = options;
60
-
61
- switch (scope) {
62
- case KNOWLEDGE_SCOPE.GLOBAL:
63
- return path.join(getGlobalKnowledgeRoot(), GLOBAL_AUTOSPEC_SUBDIRS[type.toUpperCase()] || type, name);
64
-
65
- case KNOWLEDGE_SCOPE.ORG:
66
- if (!orgName) {
67
- throw new Error('orgName is required for org scope');
68
- }
69
- return path.join(getOrgKnowledgeRoot(orgName), ORG_AUTOSPEC_SUBDIRS[type.toUpperCase()] || type, name);
70
-
71
- case KNOWLEDGE_SCOPE.PROJECT:
72
- default:
73
- return path.join(getProjectKnowledgeRoot(projectRoot), type, name);
74
- }
75
- }
76
-
77
- /**
78
- * 安全地读取文件
79
- * @param {string} filePath - 文件路径
80
- * @returns {string|null} 文件内容
81
- */
82
- function safeReadFile(filePath) {
83
- try {
84
- if (!fs.existsSync(filePath)) {
85
- return null;
86
- }
87
- return fs.readFileSync(filePath, 'utf-8');
88
- } catch (e) {
89
- return null;
90
- }
91
- }
92
-
93
- /**
94
- * 安全地读取 JSON 文件
95
- * @param {string} filePath - 文件路径
96
- * @param {any} defaultValue - 默认值
97
- * @returns {any} 解析后的数据
98
- */
99
- function safeReadJson(filePath, defaultValue = null) {
100
- try {
101
- const content = safeReadFile(filePath);
102
- if (!content) {
103
- return defaultValue;
104
- }
105
- return JSON.parse(content);
106
- } catch (e) {
107
- return defaultValue;
108
- }
109
- }
110
-
111
- /**
112
- * 获取知识缓存键
113
- * @param {string} scope - 作用域
114
- * @param {string} type - 类型
115
- * @param {string} name - 名称
116
- * @returns {string} 缓存键
117
- */
118
- function getCacheKey(scope, type, name) {
119
- return `${scope}:${type}:${name}`;
120
- }
121
-
122
- /**
123
- * 加载知识(带缓存)
124
- * @param {string} scope - 作用域
125
- * @param {string} type - 类型
126
- * @param {string} name - 名称
127
- * @param {Object} options - 选项
128
- * @returns {Object|null} 知识内容
129
- */
130
- export function loadKnowledge(scope, type, name, options = {}) {
131
- const { useCache = true, projectRoot = '.', orgName = null } = options;
132
- const cacheKey = getCacheKey(scope, type, name);
133
-
134
- if (useCache) {
135
- const cached = knowledgeCache.get(cacheKey);
136
- if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
137
- return cached.data;
138
- }
139
- }
140
-
141
- const filePath = resolveKnowledgePath(scope, type, name, { projectRoot, orgName });
142
- const content = safeReadFile(filePath);
143
-
144
- if (content && useCache) {
145
- knowledgeCache.set(cacheKey, { data: content, timestamp: Date.now() });
146
- }
147
-
148
- return content;
149
- }
150
-
151
- /**
152
- * 加载知识 JSON(带缓存)
153
- * @param {string} scope - 作用域
154
- * @param {string} type - 类型
155
- * @param {string} name - 名称
156
- * @param {Object} options - 选项
157
- * @returns {any} 知识内容
158
- */
159
- export function loadKnowledgeJson(scope, type, name, options = {}) {
160
- const { useCache = true, projectRoot = '.', orgName = null } = options;
161
- const cacheKey = `json:${getCacheKey(scope, type, name)}`;
162
-
163
- if (useCache) {
164
- const cached = knowledgeCache.get(cacheKey);
165
- if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
166
- return cached.data;
167
- }
168
- }
169
-
170
- const filePath = resolveKnowledgePath(scope, type, name, { projectRoot, orgName });
171
- const data = safeReadJson(filePath, null);
172
-
173
- if (data && useCache) {
174
- knowledgeCache.set(cacheKey, { data, timestamp: Date.now() });
175
- }
176
-
177
- return data;
178
- }
179
-
180
- /**
181
- * 三级优先级加载知识
182
- * 优先级:项目 > 用户全局 > 组织
183
- *
184
- * @param {string} type - 知识类型
185
- * @param {string} name - 知识名称
186
- * @param {Object} options - 选项
187
- * @returns {Object} 加载结果 { content, scope, path }
188
- */
189
- export function loadKnowledgeWithFallback(type, name, options = {}) {
190
- const { projectRoot = '.', orgName = null, preferScope = null } = options;
191
-
192
- // 如果指定了偏好作用域,优先尝试
193
- if (preferScope) {
194
- const content = loadKnowledge(preferScope, type, name, { projectRoot, orgName });
195
- if (content) {
196
- return {
197
- content,
198
- scope: preferScope,
199
- path: resolveKnowledgePath(preferScope, type, name, { projectRoot, orgName })
200
- };
201
- }
202
- }
203
-
204
- // 1. 优先加载项目知识
205
- const projectContent = loadKnowledge(KNOWLEDGE_SCOPE.PROJECT, type, name, { projectRoot });
206
- if (projectContent) {
207
- return {
208
- content: projectContent,
209
- scope: KNOWLEDGE_SCOPE.PROJECT,
210
- path: resolveKnowledgePath(KNOWLEDGE_SCOPE.PROJECT, type, name, { projectRoot })
211
- };
212
- }
213
-
214
- // 2. 回退到全局知识
215
- const globalContent = loadKnowledge(KNOWLEDGE_SCOPE.GLOBAL, type, name, { projectRoot });
216
- if (globalContent) {
217
- return {
218
- content: globalContent,
219
- scope: KNOWLEDGE_SCOPE.GLOBAL,
220
- path: resolveKnowledgePath(KNOWLEDGE_SCOPE.GLOBAL, type, name, { projectRoot })
221
- };
222
- }
223
-
224
- // 3. 最后回退到组织知识
225
- if (orgName) {
226
- const orgContent = loadKnowledge(KNOWLEDGE_SCOPE.ORG, type, name, { projectRoot, orgName });
227
- if (orgContent) {
228
- return {
229
- content: orgContent,
230
- scope: KNOWLEDGE_SCOPE.ORG,
231
- path: resolveKnowledgePath(KNOWLEDGE_SCOPE.ORG, type, name, { projectRoot, orgName })
232
- };
233
- }
234
- }
235
-
236
- return { content: null, scope: null, path: null };
237
- }
238
-
239
- /**
240
- * 加载技能(带版本支持)
241
- * @param {string} skillName - 技能名称
242
- * @param {Object} options - 选项
243
- * @returns {Object} 技能内容
244
- */
245
- export function loadSkill(skillName, options = {}) {
246
- const { version = 'latest', projectRoot = '.', orgName = null } = options;
247
-
248
- // 尝试加载指定版本
249
- if (version !== 'latest') {
250
- const versionedResult = loadKnowledgeWithFallback('skills', `${skillName}/v${version}/SKILL.md`, options);
251
- if (versionedResult.content) {
252
- return versionedResult;
253
- }
254
- }
255
-
256
- // 尝试加载最新版本
257
- const latestResult = loadKnowledgeWithFallback('skills', `${skillName}/SKILL.md`, options);
258
- if (latestResult.content) {
259
- return latestResult;
260
- }
261
-
262
- // 尝试从 plugins 源码加载
263
- const sourcePath = path.join(process.cwd(), 'plugins', 'skills', skillName, 'SKILL.md');
264
- const sourceContent = safeReadFile(sourcePath);
265
- if (sourceContent) {
266
- return {
267
- content: sourceContent,
268
- scope: 'source',
269
- path: sourcePath
270
- };
271
- }
272
-
273
- return { content: null, scope: null, path: null };
274
- }
275
-
276
- /**
277
- * 获取知识分区
278
- * @param {string} knowledgePath - 知识路径
279
- * @returns {string} 知识分区
280
- */
281
- export function getKnowledgeZone(knowledgePath) {
282
- // 冻结区检测
283
- if (/\/knowledge\/principles\/(constitution|evolution|design-philosophy)\.md$/.test(knowledgePath)) {
284
- return KNOWLEDGE_ZONES.FROZEN;
285
- }
286
-
287
- // 受控区检测
288
- if (/\/knowledge\/(process|guides\/support|config|checklists)\//.test(knowledgePath)) {
289
- return KNOWLEDGE_ZONES.CONTROLLED;
290
- }
291
-
292
- // 自由区检测
293
- if (/\/knowledge\/guides\/stages\/|\/knowledge\/domain\/|\/plugins\/skills\//.test(knowledgePath)) {
294
- return KNOWLEDGE_ZONES.FREE;
295
- }
296
-
297
- // 默认返回受控区
298
- return KNOWLEDGE_ZONES.CONTROLLED;
299
- }
300
-
301
- /**
302
- * 检查知识是否存在
303
- * @param {string} scope - 作用域
304
- * @param {string} type - 类型
305
- * @param {string} name - 名称
306
- * @param {Object} options - 选项
307
- * @returns {boolean} 是否存在
308
- */
309
- export function knowledgeExists(scope, type, name, options = {}) {
310
- const { projectRoot = '.', orgName = null } = options;
311
- const filePath = resolveKnowledgePath(scope, type, name, { projectRoot, orgName });
312
- return fs.existsSync(filePath);
313
- }
314
-
315
- /**
316
- * 清除知识缓存
317
- * @param {string} scope - 作用域(可选)
318
- */
319
- export function clearKnowledgeCache(scope = null) {
320
- if (scope) {
321
- for (const key of knowledgeCache.keys()) {
322
- if (key.startsWith(`${scope}:`)) {
323
- knowledgeCache.delete(key);
324
- }
325
- }
326
- } else {
327
- knowledgeCache.clear();
328
- }
329
- }
330
-
331
- export default {
332
- // 路径解析
333
- getGlobalKnowledgeRoot,
334
- getOrgKnowledgeRoot,
335
- getProjectKnowledgeRoot,
336
- resolveKnowledgePath,
337
- // 加载
338
- loadKnowledge,
339
- loadKnowledgeJson,
340
- loadKnowledgeWithFallback,
341
- loadSkill,
342
- // 工具
343
- getKnowledgeZone,
344
- knowledgeExists,
345
- clearKnowledgeCache
346
- };
@@ -1,317 +0,0 @@
1
- /**
2
- * Marketplace - 插件市场集成
3
- *
4
- * 实现插件市场发布接口、搜索/安装、生成兼容 Claude Code 的 plugin.json
5
- */
6
-
7
- import fs from 'fs';
8
- import path from 'path';
9
- import os from 'os';
10
- import {
11
- GLOBAL_AUTOSPEC_DIR,
12
- KNOWLEDGE_SCOPE
13
- } from '../install/constants.js';
14
- import { getLatestSkillVersion, listSkillVersions, getVersionHistory } from './version-manager.js';
15
-
16
- /**
17
- * 获取市场目录
18
- * @returns {string} 市场目录
19
- */
20
- function getMarketplaceDir() {
21
- return path.join(os.homedir(), '.claude/autospec/marketplace');
22
- }
23
-
24
- /**
25
- * 获取市场索引文件路径
26
- * @returns {string} 索引文件路径
27
- */
28
- function getMarketplaceIndexPath() {
29
- return path.join(getMarketplaceDir(), 'index.json');
30
- }
31
-
32
- /**
33
- * 安全地读取 JSON 文件
34
- * @param {string} filePath - 文件路径
35
- * @param {any} defaultValue - 默认值
36
- * @returns {any} 解析后的数据
37
- */
38
- function safeReadJson(filePath, defaultValue = null) {
39
- try {
40
- if (!fs.existsSync(filePath)) {
41
- return defaultValue;
42
- }
43
- const content = fs.readFileSync(filePath, 'utf-8');
44
- return JSON.parse(content);
45
- } catch (e) {
46
- return defaultValue;
47
- }
48
- }
49
-
50
- /**
51
- * 安全地写入 JSON 文件
52
- * @param {string} filePath - 文件路径
53
- * @param {any} data - 数据
54
- * @returns {boolean} 是否成功
55
- */
56
- function safeWriteJson(filePath, data) {
57
- try {
58
- const dir = path.dirname(filePath);
59
- if (!fs.existsSync(dir)) {
60
- fs.mkdirSync(dir, { recursive: true });
61
- }
62
- fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
63
- return true;
64
- } catch (e) {
65
- return false;
66
- }
67
- }
68
-
69
- /**
70
- * 生成 plugin.json(Claude Code 格式)
71
- *
72
- * @param {string} skillName - 技能名称
73
- * @param {Object} options - 选项
74
- * @returns {Object} plugin.json 内容
75
- */
76
- export function generatePluginJson(skillName, options = {}) {
77
- const { version = '1.0.0', description = '', author = '', namespace = 'autospec' } = options;
78
-
79
- // 获取技能内容
80
- const content = getLatestSkillVersion(skillName);
81
- const versions = listSkillVersions(skillName);
82
-
83
- // 从技能内容中提取描述
84
- let skillDescription = description;
85
- if (!skillDescription && content) {
86
- const match = content.match(/^---\n([\s\S]*?)\n---/);
87
- if (match) {
88
- const frontmatter = match[1];
89
- const descMatch = frontmatter.match(/description:\s*(.+)/);
90
- if (descMatch) {
91
- skillDescription = descMatch[1].trim();
92
- }
93
- }
94
- }
95
-
96
- return {
97
- name: `${namespace}-${skillName}`,
98
- version,
99
- namespace,
100
- description: skillDescription || `${skillName} skill`,
101
- skills: [
102
- {
103
- name: skillName,
104
- path: `skills/${skillName}/SKILL.md`,
105
- versions: versions.map(v => v.version)
106
- }
107
- ],
108
- author: author || 'AutoSpec User',
109
- releasedAt: new Date().toISOString()
110
- };
111
- }
112
-
113
- /**
114
- * 发布到市场
115
- *
116
- * @param {string} skillName - 技能名称
117
- * @param {Object} options - 选项
118
- * @returns {Object} 发布结果 { success, marketplaceUrl }
119
- */
120
- export function publishToMarketplace(skillName, options = {}) {
121
- const { version = '1.0.0', description = '', author = '', isPublic = false } = options;
122
-
123
- const marketplaceDir = getMarketplaceDir();
124
- const skillMarketplaceDir = path.join(marketplaceDir, skillName);
125
-
126
- try {
127
- // 创建技能市场目录
128
- if (!fs.existsSync(skillMarketplaceDir)) {
129
- fs.mkdirSync(skillMarketplaceDir, { recursive: true });
130
- }
131
-
132
- // 获取最新版本内容
133
- const content = getLatestSkillVersion(skillName);
134
- if (!content) {
135
- return { success: false, error: '技能不存在或无法获取内容' };
136
- }
137
-
138
- // 写入技能文件
139
- const skillPath = path.join(skillMarketplaceDir, 'SKILL.md');
140
- fs.writeFileSync(skillPath, content);
141
-
142
- // 生成并写入 plugin.json
143
- const pluginJson = generatePluginJson(skillName, { version, description, author });
144
- const pluginPath = path.join(skillMarketplaceDir, 'plugin.json');
145
- safeWriteJson(pluginPath, pluginJson);
146
-
147
- // 更新市场索引
148
- const indexPath = getMarketplaceIndexPath();
149
- const index = safeReadJson(indexPath, { skills: [], lastUpdated: null });
150
-
151
- const existingIndex = index.skills.findIndex(s => s.name === skillName);
152
- const skillEntry = {
153
- name: skillName,
154
- version,
155
- description: pluginJson.description,
156
- author,
157
- isPublic,
158
- publishedAt: new Date().toISOString()
159
- };
160
-
161
- if (existingIndex >= 0) {
162
- index.skills[existingIndex] = skillEntry;
163
- } else {
164
- index.skills.push(skillEntry);
165
- }
166
-
167
- index.lastUpdated = new Date().toISOString();
168
- safeWriteJson(indexPath, index);
169
-
170
- // 生成市场 URL(本地路径)
171
- const marketplaceUrl = `file://${skillMarketplaceDir}`;
172
-
173
- return {
174
- success: true,
175
- marketplaceUrl,
176
- skillName,
177
- version
178
- };
179
- } catch (e) {
180
- return {
181
- success: false,
182
- error: e.message
183
- };
184
- }
185
- }
186
-
187
- /**
188
- * 从市场安装技能
189
- *
190
- * @param {string} skillName - 技能名称
191
- * @param {Object} options - 选项
192
- * @returns {Object} 安装结果 { success, path }
193
- */
194
- export function installFromMarketplace(skillName, options = {}) {
195
- const { targetScope = KNOWLEDGE_SCOPE.GLOBAL, orgName = null } = options;
196
-
197
- const marketplaceDir = getMarketplaceDir();
198
- const skillMarketplaceDir = path.join(marketplaceDir, skillName);
199
- const skillPath = path.join(skillMarketplaceDir, 'SKILL.md');
200
-
201
- if (!fs.existsSync(skillPath)) {
202
- return { success: false, error: '市场技能不存在' };
203
- }
204
-
205
- try {
206
- // 读取市场技能内容
207
- const content = fs.readFileSync(skillPath, 'utf-8');
208
-
209
- // 目标目录
210
- const targetDir = targetScope === KNOWLEDGE_SCOPE.ORG
211
- ? path.join(os.homedir(), '.claude/autospec/orgs', orgName, 'skills')
212
- : path.join(os.homedir(), GLOBAL_AUTOSPEC_DIR, 'skills');
213
-
214
- const targetPath = path.join(targetDir, skillName);
215
-
216
- // 创建目标目录
217
- if (!fs.existsSync(targetPath)) {
218
- fs.mkdirSync(targetPath, { recursive: true });
219
- }
220
-
221
- // 写入技能文件
222
- const targetSkillPath = path.join(targetPath, 'SKILL.md');
223
- fs.writeFileSync(targetSkillPath, content);
224
-
225
- return {
226
- success: true,
227
- path: targetSkillPath
228
- };
229
- } catch (e) {
230
- return {
231
- success: false,
232
- error: e.message
233
- };
234
- }
235
- }
236
-
237
- /**
238
- * 搜索市场技能
239
- *
240
- * @param {string} query - 搜索关键词
241
- * @returns {Array} 搜索结果
242
- */
243
- export function searchMarketplace(query) {
244
- const indexPath = getMarketplaceIndexPath();
245
- const index = safeReadJson(indexPath, { skills: [] });
246
-
247
- if (!query) {
248
- return index.skills;
249
- }
250
-
251
- const queryLower = query.toLowerCase();
252
-
253
- return index.skills.filter(skill =>
254
- skill.name.toLowerCase().includes(queryLower) ||
255
- (skill.description && skill.description.toLowerCase().includes(queryLower))
256
- );
257
- }
258
-
259
- /**
260
- * 获取市场技能列表
261
- *
262
- * @returns {Array} 技能列表
263
- */
264
- export function listMarketplaceSkills() {
265
- const indexPath = getMarketplaceIndexPath();
266
- const index = safeReadJson(indexPath, { skills: [], lastUpdated: null });
267
-
268
- return {
269
- skills: index.skills,
270
- lastUpdated: index.lastUpdated,
271
- count: index.skills.length
272
- };
273
- }
274
-
275
- /**
276
- * 从市场移除技能
277
- *
278
- * @param {string} skillName - 技能名称
279
- * @returns {Object} 移除结果
280
- */
281
- export function removeFromMarketplace(skillName) {
282
- const marketplaceDir = getMarketplaceDir();
283
- const skillMarketplaceDir = path.join(marketplaceDir, skillName);
284
-
285
- if (!fs.existsSync(skillMarketplaceDir)) {
286
- return { success: false, error: '市场技能不存在' };
287
- }
288
-
289
- try {
290
- // 删除技能目录
291
- fs.rmSync(skillMarketplaceDir, { recursive: true });
292
-
293
- // 更新市场索引
294
- const indexPath = getMarketplaceIndexPath();
295
- const index = safeReadJson(indexPath, { skills: [], lastUpdated: null });
296
-
297
- index.skills = index.skills.filter(s => s.name !== skillName);
298
- index.lastUpdated = new Date().toISOString();
299
- safeWriteJson(indexPath, index);
300
-
301
- return { success: true };
302
- } catch (e) {
303
- return {
304
- success: false,
305
- error: e.message
306
- };
307
- }
308
- }
309
-
310
- export default {
311
- generatePluginJson,
312
- publishToMarketplace,
313
- installFromMarketplace,
314
- searchMarketplace,
315
- listMarketplaceSkills,
316
- removeFromMarketplace
317
- };