@chongyan/autospec 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +472 -0
  3. package/README.md +476 -0
  4. package/bin/autospec.js +3 -0
  5. package/knowledge/README.md +144 -0
  6. package/knowledge/checklists/code.md +182 -0
  7. package/knowledge/checklists/design.md +196 -0
  8. package/knowledge/checklists/release.md +70 -0
  9. package/knowledge/checklists/requirement.md +169 -0
  10. package/knowledge/checklists/test.md +46 -0
  11. package/knowledge/config/README.en.md +44 -0
  12. package/knowledge/config/README.md +44 -0
  13. package/knowledge/config/role-composition.yaml +98 -0
  14. package/knowledge/config/role-extensions.yaml +140 -0
  15. package/knowledge/config/skill-compositions.yaml +142 -0
  16. package/knowledge/config/team-stage.yaml +95 -0
  17. package/knowledge/config/team-tasks.yaml +139 -0
  18. package/knowledge/config/team-triggers.yaml +198 -0
  19. package/knowledge/config/validation-patterns.yaml +137 -0
  20. package/knowledge/domain/README.md +115 -0
  21. package/knowledge/domain/flows/README.md +194 -0
  22. package/knowledge/domain/glossary.md +143 -0
  23. package/knowledge/domain/rules.md +138 -0
  24. package/knowledge/environment/README.en.md +36 -0
  25. package/knowledge/environment/README.md +87 -0
  26. package/knowledge/environment/component-knowledge.md +316 -0
  27. package/knowledge/environment/detection-patterns.yaml +502 -0
  28. package/knowledge/environment/middleware-knowledge.md +237 -0
  29. package/knowledge/environment/template-registry.md +321 -0
  30. package/knowledge/guides/domain-driven-design.md +345 -0
  31. package/knowledge/guides/knowledge-management.md +369 -0
  32. package/knowledge/guides/requirement-engineering.md +329 -0
  33. package/knowledge/guides/stages/ai-effect-evaluator.md +93 -0
  34. package/knowledge/guides/stages/code-implementer.md +205 -0
  35. package/knowledge/guides/stages/code-reviewer.md +111 -0
  36. package/knowledge/guides/stages/consistency-checker.md +177 -0
  37. package/knowledge/guides/stages/design-planner.md +401 -0
  38. package/knowledge/guides/stages/design-reviewer.md +83 -0
  39. package/knowledge/guides/stages/integration-test-runner.md +105 -0
  40. package/knowledge/guides/stages/release-checker.md +205 -0
  41. package/knowledge/guides/stages/requirement-analyzer.md +195 -0
  42. package/knowledge/guides/stages/requirement-reviewer.md +83 -0
  43. package/knowledge/guides/stages/security-reviewer.md +89 -0
  44. package/knowledge/guides/stages/test-context-analyzer.md +250 -0
  45. package/knowledge/guides/stages/test-generator.md +241 -0
  46. package/knowledge/guides/stages/test-planner.md +183 -0
  47. package/knowledge/guides/stages/test-reviewer.md +76 -0
  48. package/knowledge/guides/stages/unit-test-runner.md +83 -0
  49. package/knowledge/guides/support/ai-agent-analyzer.md +362 -0
  50. package/knowledge/guides/support/ai-anomaly-analyzer.md +213 -0
  51. package/knowledge/guides/support/ai-artifact-evaluator.md +192 -0
  52. package/knowledge/guides/support/ai-capability-analyzer.md +193 -0
  53. package/knowledge/guides/support/ai-component-analyzer.md +169 -0
  54. package/knowledge/guides/support/ai-data-validator.md +276 -0
  55. package/knowledge/guides/support/ai-evaluation-planner.md +374 -0
  56. package/knowledge/guides/support/ai-path-evaluator.md +274 -0
  57. package/knowledge/guides/support/ai-pipeline-evaluator.md +219 -0
  58. package/knowledge/guides/support/ai-rag-analyzer.md +339 -0
  59. package/knowledge/guides/support/ai-task-assessor.md +418 -0
  60. package/knowledge/guides/support/ai-test-diagnostics.md +133 -0
  61. package/knowledge/guides/support/complexity-assessor.md +268 -0
  62. package/knowledge/guides/support/component-discovery.md +183 -0
  63. package/knowledge/guides/support/environment-scanner.md +207 -0
  64. package/knowledge/guides/support/environment-validator.md +207 -0
  65. package/knowledge/guides/support/knowledge-generator.md +234 -0
  66. package/knowledge/guides/support/methodology-extractor.md +55 -0
  67. package/knowledge/guides/support/pipeline-protocol.md +438 -0
  68. package/knowledge/guides/support/practice-logger.md +359 -0
  69. package/knowledge/guides/support/scope-inference.md +174 -0
  70. package/knowledge/guides/support/skill-distiller.md +91 -0
  71. package/knowledge/guides/support/skill-updater.md +45 -0
  72. package/knowledge/guides/support/skill-validator.md +72 -0
  73. package/knowledge/guides/support/team-orchestrator.md +323 -0
  74. package/knowledge/guides/support/tech-stack-analyzer.md +139 -0
  75. package/knowledge/guides/support/test-runner.md +254 -0
  76. package/knowledge/guides/system-design.md +352 -0
  77. package/knowledge/organization/ai-native-team.md +318 -0
  78. package/knowledge/organization/team-metrics.md +228 -0
  79. package/knowledge/principles/constitution.md +134 -0
  80. package/knowledge/principles/core-principles.md +368 -0
  81. package/knowledge/principles/design-philosophy.md +877 -0
  82. package/knowledge/principles/evolution.md +553 -0
  83. package/knowledge/process/01-requirement.md +113 -0
  84. package/knowledge/process/02-design.md +123 -0
  85. package/knowledge/process/03-implementation.md +90 -0
  86. package/knowledge/process/04-review.md +80 -0
  87. package/knowledge/process/05-testing.md +90 -0
  88. package/knowledge/process/06-delivery.md +88 -0
  89. package/knowledge/process/README.en.md +38 -0
  90. package/knowledge/process/README.md +48 -0
  91. package/knowledge/process/ai-sdlc.md +475 -0
  92. package/knowledge/process/overview.md +319 -0
  93. package/knowledge/standards/code-review.md +876 -0
  94. package/knowledge/standards/coding-style.md +940 -0
  95. package/knowledge/standards/data-consistency.md +1085 -0
  96. package/knowledge/standards/document-versioning.md +210 -0
  97. package/knowledge/standards/risk-detection.md +186 -0
  98. package/knowledge/templates/ai-evaluation.md +150 -0
  99. package/knowledge/templates/api-design.md +117 -0
  100. package/knowledge/templates/database-design.md +132 -0
  101. package/knowledge/templates/domain-driven-design.md +321 -0
  102. package/knowledge/templates/product-proposal.md +201 -0
  103. package/knowledge/templates/system-design.md +227 -0
  104. package/knowledge/templates/task-breakdown.md +107 -0
  105. package/knowledge/templates/test-case.md +170 -0
  106. package/package.json +53 -0
  107. package/plugins/.claude-plugin/plugin.json +134 -0
  108. package/plugins/agents/roles/ai-engineer.md +129 -0
  109. package/plugins/agents/roles/backend-engineer.md +165 -0
  110. package/plugins/agents/roles/ceo.md +94 -0
  111. package/plugins/agents/roles/data-engineer.md +135 -0
  112. package/plugins/agents/roles/devops-engineer.md +181 -0
  113. package/plugins/agents/roles/frontend-engineer.md +129 -0
  114. package/plugins/agents/roles/product-owner.md +98 -0
  115. package/plugins/agents/roles/quality-engineer.md +129 -0
  116. package/plugins/agents/roles/security-engineer.md +180 -0
  117. package/plugins/agents/roles/tech-lead.md +97 -0
  118. package/plugins/agents/support/blind-comparator.md +88 -0
  119. package/plugins/agents/support/consistency-checker.md +103 -0
  120. package/plugins/agents/support/failure-diagnostician.md +141 -0
  121. package/plugins/agents/support/independent-reviewer.md +80 -0
  122. package/plugins/agents/support/safety-auditor.md +121 -0
  123. package/plugins/agents/support/skill-benchmarker.md +86 -0
  124. package/plugins/agents/support/skill-forger.md +105 -0
  125. package/plugins/agents/support/stage-gate-evaluator.md +121 -0
  126. package/plugins/agents/support/test-coverage-reviewer.md +73 -0
  127. package/plugins/benchmarks/templates/README.md +44 -0
  128. package/plugins/benchmarks/templates/commands/explore-template.yaml +48 -0
  129. package/plugins/benchmarks/templates/pipeline/agile-template.yaml +84 -0
  130. package/plugins/benchmarks/templates/pipeline/waterfall-template.yaml +106 -0
  131. package/plugins/benchmarks/templates/skills/requirement-analyzer-template.yaml +48 -0
  132. package/plugins/commands/README.en.md +96 -0
  133. package/plugins/commands/README.md +96 -0
  134. package/plugins/commands/apply.md +191 -0
  135. package/plugins/commands/archive.md +76 -0
  136. package/plugins/commands/env-export.md +79 -0
  137. package/plugins/commands/env-sync.md +640 -0
  138. package/plugins/commands/env-template.md +223 -0
  139. package/plugins/commands/env-update.md +264 -0
  140. package/plugins/commands/env-validate.md +176 -0
  141. package/plugins/commands/env.md +79 -0
  142. package/plugins/commands/explore.md +76 -0
  143. package/plugins/commands/field-evolve.md +536 -0
  144. package/plugins/commands/memory.md +249 -0
  145. package/plugins/commands/project-evolve.md +821 -0
  146. package/plugins/commands/propose.md +93 -0
  147. package/plugins/commands/review.md +140 -0
  148. package/plugins/commands/run.md +224 -0
  149. package/plugins/commands/status.md +62 -0
  150. package/plugins/commands/validate.md +108 -0
  151. package/plugins/hooks/README.en.md +56 -0
  152. package/plugins/hooks/README.md +56 -0
  153. package/plugins/hooks/ai-project-guard.js +329 -0
  154. package/plugins/hooks/artifact-evaluation-hook.js +237 -0
  155. package/plugins/hooks/constitution-guard.js +211 -0
  156. package/plugins/hooks/environment-autocommit.js +264 -0
  157. package/plugins/hooks/environment-manager.js +778 -0
  158. package/plugins/hooks/execution-tracker.js +354 -0
  159. package/plugins/hooks/frozen-zone-guard.js +140 -0
  160. package/plugins/hooks/layer1-validator.js +423 -0
  161. package/plugins/hooks/lib/artifact-evaluator.js +414 -0
  162. package/plugins/hooks/lib/benchmarks/change-detector.js +390 -0
  163. package/plugins/hooks/lib/benchmarks/evaluator.js +605 -0
  164. package/plugins/hooks/lib/benchmarks/integration-example.js +169 -0
  165. package/plugins/hooks/lib/data-and-ai-detector.js +275 -0
  166. package/plugins/hooks/lib/detection-pattern-loader.js +865 -0
  167. package/plugins/hooks/lib/directory-discovery.js +395 -0
  168. package/plugins/hooks/lib/environment-config-loader.js +341 -0
  169. package/plugins/hooks/lib/environment-detector.js +553 -0
  170. package/plugins/hooks/lib/environment-evolver.js +564 -0
  171. package/plugins/hooks/lib/environment-registry.js +813 -0
  172. package/plugins/hooks/lib/execution-path.js +427 -0
  173. package/plugins/hooks/lib/hook-error-recorder.js +245 -0
  174. package/plugins/hooks/lib/hook-logger.js +538 -0
  175. package/plugins/hooks/lib/hook-runner.js +97 -0
  176. package/plugins/hooks/lib/hook-runner.sh +44 -0
  177. package/plugins/hooks/lib/hook-state-manager.js +480 -0
  178. package/plugins/hooks/lib/memory-extractor.js +377 -0
  179. package/plugins/hooks/lib/memory-manager.js +673 -0
  180. package/plugins/hooks/lib/metrics-analyzer.js +489 -0
  181. package/plugins/hooks/lib/project-evolution/auto-fixer.js +511 -0
  182. package/plugins/hooks/lib/project-evolution/memory-manager.js +346 -0
  183. package/plugins/hooks/lib/project-evolution/pattern-detector.js +476 -0
  184. package/plugins/hooks/lib/project-evolution/semantic-indexer.js +480 -0
  185. package/plugins/hooks/lib/project-structure-detector.js +326 -0
  186. package/plugins/hooks/lib/rollback-tracker.js +346 -0
  187. package/plugins/hooks/lib/source-code-scanner.js +596 -0
  188. package/plugins/hooks/lib/technology-stack-detector.js +374 -0
  189. package/plugins/hooks/lib/test-failure-analyzer.js +375 -0
  190. package/plugins/hooks/lib/test-failure-fixer.js +268 -0
  191. package/plugins/hooks/lib/trace-context.js +277 -0
  192. package/plugins/hooks/lib/validation-patterns.js +415 -0
  193. package/plugins/hooks/memory-sync.js +171 -0
  194. package/plugins/hooks/pipeline-observer.js +413 -0
  195. package/plugins/hooks/scope-sentinel.js +204 -0
  196. package/plugins/hooks/trace-initialization.js +169 -0
  197. package/plugins/memory/templates/code-quality.yaml +149 -0
  198. package/plugins/memory/templates/multi-system.yaml +155 -0
  199. package/plugins/memory/templates/team-habits.yaml +119 -0
  200. package/plugins/memory/templates/testing.yaml +121 -0
  201. package/plugins/skills/README.en.md +47 -0
  202. package/plugins/skills/README.md +104 -0
  203. package/plugins/skills/benchmark-executor/README.md +93 -0
  204. package/plugins/skills/benchmark-executor/SKILL.md +647 -0
  205. package/plugins/skills/benchmark-generator/SKILL.md +349 -0
  206. package/plugins/skills/delivery-stage/SKILL.md +203 -0
  207. package/plugins/skills/design-stage/SKILL.md +216 -0
  208. package/plugins/skills/evolution-process/SKILL.md +291 -0
  209. package/plugins/skills/exploration-phase/SKILL.md +133 -0
  210. package/plugins/skills/implementation-stage/SKILL.md +179 -0
  211. package/plugins/skills/layer1-validation/SKILL.md +79 -0
  212. package/plugins/skills/pending-dashboard/SKILL.md +109 -0
  213. package/plugins/skills/project-evolution/SKILL.md +847 -0
  214. package/plugins/skills/requirement-stage/SKILL.md +183 -0
  215. package/plugins/skills/skill-forge/SKILL.md +223 -0
  216. package/plugins/skills/skill-forge/references/description-guide.md +92 -0
  217. package/plugins/skills/skill-forge/references/quality-rubric.md +104 -0
  218. package/plugins/skills/skill-forge/references/skill-template.md +106 -0
  219. package/plugins/skills/startup-guard/SKILL.md +38 -0
  220. package/plugins/skills/testing-stage/SKILL.md +195 -0
  221. package/scripts/cli/global-init.js +288 -0
  222. package/scripts/cli/global.js +324 -0
  223. package/scripts/cli/index.js +55 -0
  224. package/scripts/cli/init.js +382 -0
  225. package/scripts/cli/list.js +69 -0
  226. package/scripts/cli/org.js +340 -0
  227. package/scripts/cli/update.js +44 -0
  228. package/scripts/config/commands.config.js +145 -0
  229. package/scripts/config/hooks.config.js +197 -0
  230. package/scripts/evolution/evolution-router.js +273 -0
  231. package/scripts/evolution/evolution-signal-collector.js +307 -0
  232. package/scripts/evolution/knowledge-loader.js +346 -0
  233. package/scripts/evolution/marketplace.js +317 -0
  234. package/scripts/evolution/version-manager.js +371 -0
  235. package/scripts/install/agents.js +106 -0
  236. package/scripts/install/commands.js +133 -0
  237. package/scripts/install/constants.js +424 -0
  238. package/scripts/install/hook-logger.js +536 -0
  239. package/scripts/install/hooks.js +110 -0
  240. package/scripts/install/index.js +39 -0
  241. package/scripts/install/skills.js +95 -0
  242. package/scripts/postinstall.js +25 -0
  243. package/scripts/state.js +376 -0
@@ -0,0 +1,324 @@
1
+ /**
2
+ * AutoSpec global command
3
+ *
4
+ * 实现 autospec global 子命令
5
+ * 支持 init/sync/status/publish 操作
6
+ */
7
+
8
+ import fs from 'fs';
9
+ import path from 'path';
10
+ import os from 'os';
11
+ import chalk from 'chalk';
12
+ import {
13
+ GLOBAL_AUTOSPEC_DIR,
14
+ GLOBAL_AUTOSPEC_SUBDIRS,
15
+ CLAUDE_CODE_SKILLS_DIR,
16
+ KNOWLEDGE_SCOPE
17
+ } from '../install/constants.js';
18
+
19
+ /**
20
+ * 获取全局知识库根目录
21
+ */
22
+ function getGlobalDir() {
23
+ return path.join(os.homedir(), GLOBAL_AUTOSPEC_DIR);
24
+ }
25
+
26
+ /**
27
+ * 获取 Claude Code skills 目录
28
+ */
29
+ function getClaudeCodeSkillsDir() {
30
+ return path.join(os.homedir(), CLAUDE_CODE_SKILLS_DIR);
31
+ }
32
+
33
+ /**
34
+ * 创建目录
35
+ */
36
+ function ensureDir(dir) {
37
+ if (!fs.existsSync(dir)) {
38
+ fs.mkdirSync(dir, { recursive: true });
39
+ }
40
+ }
41
+
42
+ /**
43
+ * 初始化全局知识库
44
+ */
45
+ export function initGlobal(options = {}) {
46
+ const globalDir = getGlobalDir();
47
+ const results = {
48
+ directoriesCreated: false,
49
+ symlinksCreated: false,
50
+ errors: []
51
+ };
52
+
53
+ console.log(chalk.bold('\n AutoSpec Global Init\n'));
54
+ console.log(` Target: ${globalDir}`);
55
+ console.log();
56
+
57
+ try {
58
+ // 创建全局知识库目录结构
59
+ const subdirs = Object.values(GLOBAL_AUTOSPEC_SUBDIRS);
60
+ for (const subdir of subdirs) {
61
+ const fullPath = path.join(globalDir, subdir);
62
+ ensureDir(fullPath);
63
+ }
64
+ results.directoriesCreated = true;
65
+
66
+ // 创建 Claude Code skills 符号链接
67
+ const autoSpecSkillsDir = path.join(globalDir, GLOBAL_AUTOSPEC_SUBDIRS.SKILLS);
68
+ const claudeSkillsDir = getClaudeCodeSkillsDir();
69
+ ensureDir(claudeSkillsDir);
70
+
71
+ // 创建符号链接(如果不存在)
72
+ const symlinkPath = path.join(claudeSkillsDir, 'autospec');
73
+ if (!fs.existsSync(symlinkPath)) {
74
+ try {
75
+ fs.symlinkSync(autoSpecSkillsDir, symlinkPath, 'dir');
76
+ results.symlinksCreated = true;
77
+ } catch (e) {
78
+ // 符号链接创建失败时使用副本
79
+ console.log(chalk.yellow(` ⚠ 符号链接创建失败,将使用副本: ${e.message}`));
80
+ copyDir(autoSpecSkillsDir, path.join(claudeSkillsDir, 'autospec'));
81
+ results.symlinksCreated = true;
82
+ }
83
+ }
84
+
85
+ console.log(chalk.green(' ✓') + ' 全局知识库目录已创建');
86
+ console.log(chalk.green(' ✓') + ' Claude Code skills 已链接');
87
+
88
+ console.log(chalk.bold('\n 快速开始\n'));
89
+ console.log(' 全局知识库已初始化,您可以通过以下命令使用:');
90
+ console.log('');
91
+ console.log(chalk.cyan(' 发布技能到全局'));
92
+ console.log(' autospec global publish <skill-name>');
93
+ console.log('');
94
+ console.log(chalk.cyan(' 同步全局知识到项目'));
95
+ console.log(' autospec global sync');
96
+ console.log('');
97
+ console.log(chalk.cyan(' 查看全局状态'));
98
+ console.log(' autospec global status');
99
+ console.log('');
100
+
101
+ return results;
102
+ } catch (e) {
103
+ results.errors.push(e.message);
104
+ console.log(chalk.red(` ✗ 初始化失败: ${e.message}`));
105
+ return results;
106
+ }
107
+ }
108
+
109
+ /**
110
+ * 复制目录
111
+ */
112
+ function copyDir(src, dest) {
113
+ ensureDir(dest);
114
+ const entries = fs.readdirSync(src, { withFileTypes: true });
115
+ for (const entry of entries) {
116
+ const srcPath = path.join(src, entry.name);
117
+ const destPath = path.join(dest, entry.name);
118
+ if (entry.isDirectory()) {
119
+ copyDir(srcPath, destPath);
120
+ } else {
121
+ fs.copyFileSync(srcPath, destPath);
122
+ }
123
+ }
124
+ }
125
+
126
+ /**
127
+ * 同步全局知识到项目
128
+ */
129
+ export function syncToProject(projectDir, options = {}) {
130
+ const globalDir = getGlobalDir();
131
+ const results = {
132
+ skillsSynced: false,
133
+ knowledgeSynced: false,
134
+ errors: []
135
+ };
136
+
137
+ console.log(chalk.bold('\n AutoSpec Global Sync\n'));
138
+ console.log(` Global: ${globalDir}`);
139
+ console.log(` Project: ${projectDir}`);
140
+ console.log();
141
+
142
+ try {
143
+ // 同步 skills
144
+ const globalSkillsDir = path.join(globalDir, GLOBAL_AUTOSPEC_SUBDIRS.SKILLS);
145
+ const projectSkillsDir = path.join(projectDir, '.autospec', 'skills');
146
+
147
+ if (fs.existsSync(globalSkillsDir)) {
148
+ copyDir(globalSkillsDir, projectSkillsDir);
149
+ results.skillsSynced = true;
150
+ console.log(chalk.green(' ✓') + ' Skills 已同步');
151
+ }
152
+
153
+ // 同步 knowledge(只同步受控区和自由区)
154
+ const globalKnowledgeDir = path.join(globalDir, GLOBAL_AUTOSPEC_SUBDIRS.KNOWLEDGE);
155
+ const projectKnowledgeDir = path.join(projectDir, '.autospec', 'knowledge');
156
+
157
+ if (fs.existsSync(globalKnowledgeDir)) {
158
+ // 只复制 guides/stages 和 domain(自由区)
159
+ const stagesDir = path.join(globalKnowledgeDir, 'guides', 'stages');
160
+ const domainDir = path.join(globalKnowledgeDir, 'domain');
161
+
162
+ if (fs.existsSync(stagesDir)) {
163
+ copyDir(stagesDir, path.join(projectKnowledgeDir, 'guides', 'stages'));
164
+ }
165
+ if (fs.existsSync(domainDir)) {
166
+ copyDir(domainDir, path.join(projectKnowledgeDir, 'domain'));
167
+ }
168
+ results.knowledgeSynced = true;
169
+ console.log(chalk.green(' ✓') + ' Knowledge 已同步');
170
+ }
171
+
172
+ console.log('');
173
+ return results;
174
+ } catch (e) {
175
+ results.errors.push(e.message);
176
+ console.log(chalk.red(` ✗ 同步失败: ${e.message}`));
177
+ return results;
178
+ }
179
+ }
180
+
181
+ /**
182
+ * 查看全局状态
183
+ */
184
+ export function globalStatus(options = {}) {
185
+ const globalDir = getGlobalDir();
186
+
187
+ console.log(chalk.bold('\n AutoSpec Global Status\n'));
188
+ console.log(` Global: ${globalDir}`);
189
+ console.log();
190
+
191
+ // 检查目录是否存在
192
+ if (!fs.existsSync(globalDir)) {
193
+ console.log(chalk.yellow(' ⚠ 全局知识库未初始化'));
194
+ console.log(chalk.cyan(' 运行 autospec global init 初始化'));
195
+ return { initialized: false };
196
+ }
197
+
198
+ // 统计 skills
199
+ const skillsDir = path.join(globalDir, GLOBAL_AUTOSPEC_SUBDIRS.SKILLS);
200
+ let skillCount = 0;
201
+ if (fs.existsSync(skillsDir)) {
202
+ skillCount = fs.readdirSync(skillsDir).filter(f =>
203
+ fs.statSync(path.join(skillsDir, f)).isDirectory()
204
+ ).length;
205
+ }
206
+
207
+ // 统计 roles
208
+ const rolesDir = path.join(globalDir, GLOBAL_AUTOSPEC_SUBDIRS.ROLES);
209
+ let roleCount = 0;
210
+ if (fs.existsSync(rolesDir)) {
211
+ roleCount = fs.readdirSync(rolesDir).filter(f =>
212
+ fs.statSync(path.join(rolesDir, f)).isDirectory()
213
+ ).length;
214
+ }
215
+
216
+ console.log(chalk.green(' ✓') + ' 全局知识库已初始化');
217
+ console.log(` Skills: ${skillCount}`);
218
+ console.log(` Roles: ${roleCount}`);
219
+ console.log('');
220
+
221
+ return { initialized: true, skillCount, roleCount };
222
+ }
223
+
224
+ /**
225
+ * 发布技能到全局
226
+ */
227
+ export function publishSkill(skillName, options = {}) {
228
+ const { version = '1.0.0', message = '', force = false } = options;
229
+ const globalDir = getGlobalDir();
230
+ const skillsDir = path.join(globalDir, GLOBAL_AUTOSPEC_SUBDIRS.SKILLS);
231
+
232
+ console.log(chalk.bold('\n AutoSpec Global Publish\n'));
233
+ console.log(` Skill: ${skillName}`);
234
+ console.log(` Version: ${version}`);
235
+ console.log();
236
+
237
+ try {
238
+ // 从项目或源码获取技能
239
+ const projectSkillsDir = path.join(process.cwd(), 'plugins', 'skills', skillName);
240
+ const projectSkillFile = path.join(projectSkillsDir, 'SKILL.md');
241
+ const sourceSkillsDir = path.join(process.cwd(), 'plugins', 'skills');
242
+ const sourceSkillFile = path.join(sourceSkillsDir, skillName, 'SKILL.md');
243
+
244
+ let skillContent = null;
245
+ let sourcePath = null;
246
+
247
+ if (fs.existsSync(projectSkillFile)) {
248
+ skillContent = fs.readFileSync(projectSkillFile, 'utf-8');
249
+ sourcePath = projectSkillsDir;
250
+ } else if (fs.existsSync(sourceSkillFile)) {
251
+ skillContent = fs.readFileSync(sourceSkillFile, 'utf-8');
252
+ sourcePath = path.join(sourceSkillsDir, skillName);
253
+ }
254
+
255
+ if (!skillContent) {
256
+ console.log(chalk.red(` ✗ 技能 ${skillName} 不存在`));
257
+ return { success: false, error: 'Skill not found' };
258
+ }
259
+
260
+ // 创建技能目录
261
+ const targetSkillDir = path.join(skillsDir, skillName, `v${version}`);
262
+ ensureDir(targetSkillDir);
263
+
264
+ // 写入技能文件
265
+ const targetSkillFile = path.join(targetSkillDir, 'SKILL.md');
266
+ fs.writeFileSync(targetSkillFile, skillContent);
267
+
268
+ // 复制 references 目录(如果存在)
269
+ const sourceRefsDir = path.join(sourcePath, 'references');
270
+ if (fs.existsSync(sourceRefsDir)) {
271
+ const targetRefsDir = path.join(targetSkillDir, 'references');
272
+ copyDir(sourceRefsDir, targetRefsDir);
273
+ }
274
+
275
+ // 更新 latest(副本)
276
+ fs.writeFileSync(path.join(skillsDir, skillName, 'SKILL.md'), skillContent);
277
+
278
+ console.log(chalk.green(' ✓') + ` 技能 ${skillName} v${version} 已发布到全局`);
279
+ console.log(` Path: ${targetSkillFile}`);
280
+ console.log('');
281
+
282
+ return { success: true, skillName, version, path: targetSkillFile };
283
+ } catch (e) {
284
+ console.log(chalk.red(` ✗ 发布失败: ${e.message}`));
285
+ return { success: false, error: e.message };
286
+ }
287
+ }
288
+
289
+ /**
290
+ * global 命令入口
291
+ */
292
+ export function globalCommand(action, options = {}) {
293
+ switch (action) {
294
+ case 'init':
295
+ return initGlobal(options);
296
+
297
+ case 'sync':
298
+ return syncToProject(options.projectDir || process.cwd(), options);
299
+
300
+ case 'status':
301
+ return globalStatus(options);
302
+
303
+ case 'publish':
304
+ if (!options.skill) {
305
+ console.log(chalk.red(' ✗ 请指定技能名称'));
306
+ console.log(' 用法: autospec global publish <skill-name>');
307
+ return { success: false, error: 'Skill name required' };
308
+ }
309
+ return publishSkill(options.skill, options);
310
+
311
+ default:
312
+ console.log(chalk.red(` ✗ 未知操作: ${action}`));
313
+ console.log(' 可用操作: init, sync, status, publish');
314
+ return { success: false, error: 'Unknown action' };
315
+ }
316
+ }
317
+
318
+ export default {
319
+ initGlobal,
320
+ syncToProject,
321
+ globalStatus,
322
+ publishSkill,
323
+ globalCommand
324
+ };
@@ -0,0 +1,55 @@
1
+ /**
2
+ * AutoSpec CLI entry point
3
+ *
4
+ * CLI 命令仅保留 init、update、list,其他功能通过斜杠命令实现
5
+ */
6
+
7
+ import { Command } from 'commander';
8
+ import chalk from 'chalk';
9
+ import { initCommand } from './init.js';
10
+ import { updateCommand } from './update.js';
11
+ import { listCommand } from './list.js';
12
+ import { setVerbose, setLogLevel, LOG_LEVELS } from '../install/hook-logger.js';
13
+
14
+ const VERSION = '0.1.0';
15
+
16
+ const program = new Command();
17
+
18
+ program
19
+ .name('autospec')
20
+ .description('AI驱动的无人值守自动化产品研发流程')
21
+ .version(VERSION, '-V, --version')
22
+ .option('-v, --verbose', 'Enable verbose logging', false)
23
+ .hook('preAction', (thisCommand) => {
24
+ const options = thisCommand.opts();
25
+ if (options.verbose) {
26
+ setVerbose(true);
27
+ setLogLevel(LOG_LEVELS.DEBUG);
28
+ }
29
+ });
30
+
31
+ // --- init ---
32
+ program
33
+ .command('init')
34
+ .description('Initialize AutoSpec in current project')
35
+ .option('-w, --workflow <type>', 'Iteration mode (waterfall|agile|experiment|hotfix)', 'waterfall')
36
+ .option('-r, --roles <roles>', 'Project roles, comma-separated (backend,frontend,data,ai,quality)', '')
37
+ .option('-d, --domain <domain>', 'Business domain description (free text)', '')
38
+ .option('--force', 'Force overwrite existing files', false)
39
+ .option('-v, --verbose', 'Enable verbose logging', false)
40
+ .action(initCommand);
41
+
42
+ // --- update ---
43
+ program
44
+ .command('update')
45
+ .description('更新框架文件和 Claude Code 命令(保留 state)')
46
+ .action(updateCommand);
47
+
48
+ // --- list ---
49
+ program
50
+ .command('list')
51
+ .alias('ls')
52
+ .description('列出所有可用的斜杠命令')
53
+ .action(listCommand);
54
+
55
+ program.parse();