@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.
- package/LICENSE +21 -0
- package/README.en.md +472 -0
- package/README.md +476 -0
- package/bin/autospec.js +3 -0
- package/knowledge/README.md +144 -0
- package/knowledge/checklists/code.md +182 -0
- package/knowledge/checklists/design.md +196 -0
- package/knowledge/checklists/release.md +70 -0
- package/knowledge/checklists/requirement.md +169 -0
- package/knowledge/checklists/test.md +46 -0
- package/knowledge/config/README.en.md +44 -0
- package/knowledge/config/README.md +44 -0
- package/knowledge/config/role-composition.yaml +98 -0
- package/knowledge/config/role-extensions.yaml +140 -0
- package/knowledge/config/skill-compositions.yaml +142 -0
- package/knowledge/config/team-stage.yaml +95 -0
- package/knowledge/config/team-tasks.yaml +139 -0
- package/knowledge/config/team-triggers.yaml +198 -0
- package/knowledge/config/validation-patterns.yaml +137 -0
- package/knowledge/domain/README.md +115 -0
- package/knowledge/domain/flows/README.md +194 -0
- package/knowledge/domain/glossary.md +143 -0
- package/knowledge/domain/rules.md +138 -0
- package/knowledge/environment/README.en.md +36 -0
- package/knowledge/environment/README.md +87 -0
- package/knowledge/environment/component-knowledge.md +316 -0
- package/knowledge/environment/detection-patterns.yaml +502 -0
- package/knowledge/environment/middleware-knowledge.md +237 -0
- package/knowledge/environment/template-registry.md +321 -0
- package/knowledge/guides/domain-driven-design.md +345 -0
- package/knowledge/guides/knowledge-management.md +369 -0
- package/knowledge/guides/requirement-engineering.md +329 -0
- package/knowledge/guides/stages/ai-effect-evaluator.md +93 -0
- package/knowledge/guides/stages/code-implementer.md +205 -0
- package/knowledge/guides/stages/code-reviewer.md +111 -0
- package/knowledge/guides/stages/consistency-checker.md +177 -0
- package/knowledge/guides/stages/design-planner.md +401 -0
- package/knowledge/guides/stages/design-reviewer.md +83 -0
- package/knowledge/guides/stages/integration-test-runner.md +105 -0
- package/knowledge/guides/stages/release-checker.md +205 -0
- package/knowledge/guides/stages/requirement-analyzer.md +195 -0
- package/knowledge/guides/stages/requirement-reviewer.md +83 -0
- package/knowledge/guides/stages/security-reviewer.md +89 -0
- package/knowledge/guides/stages/test-context-analyzer.md +250 -0
- package/knowledge/guides/stages/test-generator.md +241 -0
- package/knowledge/guides/stages/test-planner.md +183 -0
- package/knowledge/guides/stages/test-reviewer.md +76 -0
- package/knowledge/guides/stages/unit-test-runner.md +83 -0
- package/knowledge/guides/support/ai-agent-analyzer.md +362 -0
- package/knowledge/guides/support/ai-anomaly-analyzer.md +213 -0
- package/knowledge/guides/support/ai-artifact-evaluator.md +192 -0
- package/knowledge/guides/support/ai-capability-analyzer.md +193 -0
- package/knowledge/guides/support/ai-component-analyzer.md +169 -0
- package/knowledge/guides/support/ai-data-validator.md +276 -0
- package/knowledge/guides/support/ai-evaluation-planner.md +374 -0
- package/knowledge/guides/support/ai-path-evaluator.md +274 -0
- package/knowledge/guides/support/ai-pipeline-evaluator.md +219 -0
- package/knowledge/guides/support/ai-rag-analyzer.md +339 -0
- package/knowledge/guides/support/ai-task-assessor.md +418 -0
- package/knowledge/guides/support/ai-test-diagnostics.md +133 -0
- package/knowledge/guides/support/complexity-assessor.md +268 -0
- package/knowledge/guides/support/component-discovery.md +183 -0
- package/knowledge/guides/support/environment-scanner.md +207 -0
- package/knowledge/guides/support/environment-validator.md +207 -0
- package/knowledge/guides/support/knowledge-generator.md +234 -0
- package/knowledge/guides/support/methodology-extractor.md +55 -0
- package/knowledge/guides/support/pipeline-protocol.md +438 -0
- package/knowledge/guides/support/practice-logger.md +359 -0
- package/knowledge/guides/support/scope-inference.md +174 -0
- package/knowledge/guides/support/skill-distiller.md +91 -0
- package/knowledge/guides/support/skill-updater.md +45 -0
- package/knowledge/guides/support/skill-validator.md +72 -0
- package/knowledge/guides/support/team-orchestrator.md +323 -0
- package/knowledge/guides/support/tech-stack-analyzer.md +139 -0
- package/knowledge/guides/support/test-runner.md +254 -0
- package/knowledge/guides/system-design.md +352 -0
- package/knowledge/organization/ai-native-team.md +318 -0
- package/knowledge/organization/team-metrics.md +228 -0
- package/knowledge/principles/constitution.md +134 -0
- package/knowledge/principles/core-principles.md +368 -0
- package/knowledge/principles/design-philosophy.md +877 -0
- package/knowledge/principles/evolution.md +553 -0
- package/knowledge/process/01-requirement.md +113 -0
- package/knowledge/process/02-design.md +123 -0
- package/knowledge/process/03-implementation.md +90 -0
- package/knowledge/process/04-review.md +80 -0
- package/knowledge/process/05-testing.md +90 -0
- package/knowledge/process/06-delivery.md +88 -0
- package/knowledge/process/README.en.md +38 -0
- package/knowledge/process/README.md +48 -0
- package/knowledge/process/ai-sdlc.md +475 -0
- package/knowledge/process/overview.md +319 -0
- package/knowledge/standards/code-review.md +876 -0
- package/knowledge/standards/coding-style.md +940 -0
- package/knowledge/standards/data-consistency.md +1085 -0
- package/knowledge/standards/document-versioning.md +210 -0
- package/knowledge/standards/risk-detection.md +186 -0
- package/knowledge/templates/ai-evaluation.md +150 -0
- package/knowledge/templates/api-design.md +117 -0
- package/knowledge/templates/database-design.md +132 -0
- package/knowledge/templates/domain-driven-design.md +321 -0
- package/knowledge/templates/product-proposal.md +201 -0
- package/knowledge/templates/system-design.md +227 -0
- package/knowledge/templates/task-breakdown.md +107 -0
- package/knowledge/templates/test-case.md +170 -0
- package/package.json +53 -0
- package/plugins/.claude-plugin/plugin.json +134 -0
- package/plugins/agents/roles/ai-engineer.md +129 -0
- package/plugins/agents/roles/backend-engineer.md +165 -0
- package/plugins/agents/roles/ceo.md +94 -0
- package/plugins/agents/roles/data-engineer.md +135 -0
- package/plugins/agents/roles/devops-engineer.md +181 -0
- package/plugins/agents/roles/frontend-engineer.md +129 -0
- package/plugins/agents/roles/product-owner.md +98 -0
- package/plugins/agents/roles/quality-engineer.md +129 -0
- package/plugins/agents/roles/security-engineer.md +180 -0
- package/plugins/agents/roles/tech-lead.md +97 -0
- package/plugins/agents/support/blind-comparator.md +88 -0
- package/plugins/agents/support/consistency-checker.md +103 -0
- package/plugins/agents/support/failure-diagnostician.md +141 -0
- package/plugins/agents/support/independent-reviewer.md +80 -0
- package/plugins/agents/support/safety-auditor.md +121 -0
- package/plugins/agents/support/skill-benchmarker.md +86 -0
- package/plugins/agents/support/skill-forger.md +105 -0
- package/plugins/agents/support/stage-gate-evaluator.md +121 -0
- package/plugins/agents/support/test-coverage-reviewer.md +73 -0
- package/plugins/benchmarks/templates/README.md +44 -0
- package/plugins/benchmarks/templates/commands/explore-template.yaml +48 -0
- package/plugins/benchmarks/templates/pipeline/agile-template.yaml +84 -0
- package/plugins/benchmarks/templates/pipeline/waterfall-template.yaml +106 -0
- package/plugins/benchmarks/templates/skills/requirement-analyzer-template.yaml +48 -0
- package/plugins/commands/README.en.md +96 -0
- package/plugins/commands/README.md +96 -0
- package/plugins/commands/apply.md +191 -0
- package/plugins/commands/archive.md +76 -0
- package/plugins/commands/env-export.md +79 -0
- package/plugins/commands/env-sync.md +640 -0
- package/plugins/commands/env-template.md +223 -0
- package/plugins/commands/env-update.md +264 -0
- package/plugins/commands/env-validate.md +176 -0
- package/plugins/commands/env.md +79 -0
- package/plugins/commands/explore.md +76 -0
- package/plugins/commands/field-evolve.md +536 -0
- package/plugins/commands/memory.md +249 -0
- package/plugins/commands/project-evolve.md +821 -0
- package/plugins/commands/propose.md +93 -0
- package/plugins/commands/review.md +140 -0
- package/plugins/commands/run.md +224 -0
- package/plugins/commands/status.md +62 -0
- package/plugins/commands/validate.md +108 -0
- package/plugins/hooks/README.en.md +56 -0
- package/plugins/hooks/README.md +56 -0
- package/plugins/hooks/ai-project-guard.js +329 -0
- package/plugins/hooks/artifact-evaluation-hook.js +237 -0
- package/plugins/hooks/constitution-guard.js +211 -0
- package/plugins/hooks/environment-autocommit.js +264 -0
- package/plugins/hooks/environment-manager.js +778 -0
- package/plugins/hooks/execution-tracker.js +354 -0
- package/plugins/hooks/frozen-zone-guard.js +140 -0
- package/plugins/hooks/layer1-validator.js +423 -0
- package/plugins/hooks/lib/artifact-evaluator.js +414 -0
- package/plugins/hooks/lib/benchmarks/change-detector.js +390 -0
- package/plugins/hooks/lib/benchmarks/evaluator.js +605 -0
- package/plugins/hooks/lib/benchmarks/integration-example.js +169 -0
- package/plugins/hooks/lib/data-and-ai-detector.js +275 -0
- package/plugins/hooks/lib/detection-pattern-loader.js +865 -0
- package/plugins/hooks/lib/directory-discovery.js +395 -0
- package/plugins/hooks/lib/environment-config-loader.js +341 -0
- package/plugins/hooks/lib/environment-detector.js +553 -0
- package/plugins/hooks/lib/environment-evolver.js +564 -0
- package/plugins/hooks/lib/environment-registry.js +813 -0
- package/plugins/hooks/lib/execution-path.js +427 -0
- package/plugins/hooks/lib/hook-error-recorder.js +245 -0
- package/plugins/hooks/lib/hook-logger.js +538 -0
- package/plugins/hooks/lib/hook-runner.js +97 -0
- package/plugins/hooks/lib/hook-runner.sh +44 -0
- package/plugins/hooks/lib/hook-state-manager.js +480 -0
- package/plugins/hooks/lib/memory-extractor.js +377 -0
- package/plugins/hooks/lib/memory-manager.js +673 -0
- package/plugins/hooks/lib/metrics-analyzer.js +489 -0
- package/plugins/hooks/lib/project-evolution/auto-fixer.js +511 -0
- package/plugins/hooks/lib/project-evolution/memory-manager.js +346 -0
- package/plugins/hooks/lib/project-evolution/pattern-detector.js +476 -0
- package/plugins/hooks/lib/project-evolution/semantic-indexer.js +480 -0
- package/plugins/hooks/lib/project-structure-detector.js +326 -0
- package/plugins/hooks/lib/rollback-tracker.js +346 -0
- package/plugins/hooks/lib/source-code-scanner.js +596 -0
- package/plugins/hooks/lib/technology-stack-detector.js +374 -0
- package/plugins/hooks/lib/test-failure-analyzer.js +375 -0
- package/plugins/hooks/lib/test-failure-fixer.js +268 -0
- package/plugins/hooks/lib/trace-context.js +277 -0
- package/plugins/hooks/lib/validation-patterns.js +415 -0
- package/plugins/hooks/memory-sync.js +171 -0
- package/plugins/hooks/pipeline-observer.js +413 -0
- package/plugins/hooks/scope-sentinel.js +204 -0
- package/plugins/hooks/trace-initialization.js +169 -0
- package/plugins/memory/templates/code-quality.yaml +149 -0
- package/plugins/memory/templates/multi-system.yaml +155 -0
- package/plugins/memory/templates/team-habits.yaml +119 -0
- package/plugins/memory/templates/testing.yaml +121 -0
- package/plugins/skills/README.en.md +47 -0
- package/plugins/skills/README.md +104 -0
- package/plugins/skills/benchmark-executor/README.md +93 -0
- package/plugins/skills/benchmark-executor/SKILL.md +647 -0
- package/plugins/skills/benchmark-generator/SKILL.md +349 -0
- package/plugins/skills/delivery-stage/SKILL.md +203 -0
- package/plugins/skills/design-stage/SKILL.md +216 -0
- package/plugins/skills/evolution-process/SKILL.md +291 -0
- package/plugins/skills/exploration-phase/SKILL.md +133 -0
- package/plugins/skills/implementation-stage/SKILL.md +179 -0
- package/plugins/skills/layer1-validation/SKILL.md +79 -0
- package/plugins/skills/pending-dashboard/SKILL.md +109 -0
- package/plugins/skills/project-evolution/SKILL.md +847 -0
- package/plugins/skills/requirement-stage/SKILL.md +183 -0
- package/plugins/skills/skill-forge/SKILL.md +223 -0
- package/plugins/skills/skill-forge/references/description-guide.md +92 -0
- package/plugins/skills/skill-forge/references/quality-rubric.md +104 -0
- package/plugins/skills/skill-forge/references/skill-template.md +106 -0
- package/plugins/skills/startup-guard/SKILL.md +38 -0
- package/plugins/skills/testing-stage/SKILL.md +195 -0
- package/scripts/cli/global-init.js +288 -0
- package/scripts/cli/global.js +324 -0
- package/scripts/cli/index.js +55 -0
- package/scripts/cli/init.js +382 -0
- package/scripts/cli/list.js +69 -0
- package/scripts/cli/org.js +340 -0
- package/scripts/cli/update.js +44 -0
- package/scripts/config/commands.config.js +145 -0
- package/scripts/config/hooks.config.js +197 -0
- package/scripts/evolution/evolution-router.js +273 -0
- package/scripts/evolution/evolution-signal-collector.js +307 -0
- package/scripts/evolution/knowledge-loader.js +346 -0
- package/scripts/evolution/marketplace.js +317 -0
- package/scripts/evolution/version-manager.js +371 -0
- package/scripts/install/agents.js +106 -0
- package/scripts/install/commands.js +133 -0
- package/scripts/install/constants.js +424 -0
- package/scripts/install/hook-logger.js +536 -0
- package/scripts/install/hooks.js +110 -0
- package/scripts/install/index.js +39 -0
- package/scripts/install/skills.js +95 -0
- package/scripts/postinstall.js +25 -0
- package/scripts/state.js +376 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* AutoSpec 声明式 Hook 配置
|
|
5
|
+
*
|
|
6
|
+
* 替代硬编码的 hook 注册逻辑,使用声明式配置管理所有 hooks。
|
|
7
|
+
*
|
|
8
|
+
* 优先级规则(大数字先执行):
|
|
9
|
+
* - 200: trace-initialization (最高优先级,Trace ID 初始化)
|
|
10
|
+
* - 100: frozen-zone (保护核心文件)
|
|
11
|
+
* - 90: scope-sentinel (范围保护)
|
|
12
|
+
* - 85: constitution-guard (宪法门禁)
|
|
13
|
+
* - 80: layer1-validator (Layer 1 强制检查 + 结果捕获 + 质量追踪)
|
|
14
|
+
* - 75: environment-manager (环境知识验证 + 环境进化检查)
|
|
15
|
+
* - 50: ai-project-guard (AI 安全检查 + 效果验证)
|
|
16
|
+
* - 35: execution-tracker (执行追踪)
|
|
17
|
+
*
|
|
18
|
+
* 注意:evolution-trigger 和 practice-log-reminder 已合并到 skill:
|
|
19
|
+
* - knowledge/guides/support/practice-logger.md
|
|
20
|
+
*
|
|
21
|
+
* 缓存键规范:
|
|
22
|
+
* - ai-project:{projectRoot} - AI 项目检测结果
|
|
23
|
+
* - stage-check:{projectRoot}:stage - 当前阶段缓存
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
export const HOOKS_CONFIG = {
|
|
27
|
+
// PreToolUse - 工具执行前检查
|
|
28
|
+
PreToolUse: [
|
|
29
|
+
{
|
|
30
|
+
name: 'trace-initialization',
|
|
31
|
+
script: 'plugins/hooks/trace-initialization.js',
|
|
32
|
+
matcher: 'Write',
|
|
33
|
+
priority: 200,
|
|
34
|
+
description: '流程启动时初始化 Trace ID'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'frozen-zone',
|
|
38
|
+
script: 'plugins/hooks/frozen-zone-guard.js',
|
|
39
|
+
matcher: 'Write|Edit',
|
|
40
|
+
priority: 100,
|
|
41
|
+
description: '保护冻结区文件不被修改'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'scope-sentinel',
|
|
45
|
+
script: 'plugins/hooks/scope-sentinel.js',
|
|
46
|
+
matcher: 'Write|Edit',
|
|
47
|
+
priority: 90,
|
|
48
|
+
description: '实现阶段范围防漂移'
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'constitution-guard',
|
|
52
|
+
script: 'plugins/hooks/constitution-guard.js',
|
|
53
|
+
matcher: 'Write|Edit',
|
|
54
|
+
priority: 85,
|
|
55
|
+
description: '检查启动门禁是否遵循'
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'layer1-validator',
|
|
59
|
+
script: 'plugins/hooks/layer1-validator.js',
|
|
60
|
+
matcher: 'Write|Edit|Bash',
|
|
61
|
+
priority: 80,
|
|
62
|
+
description: 'Layer 1 强制检查(PreToolUse)+ 结果捕获(PostToolUse)+ 质量追踪'
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'environment-manager',
|
|
66
|
+
script: 'plugins/hooks/environment-manager.js',
|
|
67
|
+
matcher: 'Write|Edit',
|
|
68
|
+
priority: 75,
|
|
69
|
+
description: '环境知识验证(PreToolUse)+ 环境进化检查(Stop)'
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: 'ai-project-guard',
|
|
73
|
+
script: 'plugins/hooks/ai-project-guard.js',
|
|
74
|
+
matcher: '', // 所有 Bash 命令
|
|
75
|
+
priority: 50,
|
|
76
|
+
condition: 'isAIProject', // 条件执行:仅 AI 项目
|
|
77
|
+
description: 'AI 项目安全检查 + 效果验证'
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
|
|
81
|
+
// PostToolUse - 工具执行后处理
|
|
82
|
+
PostToolUse: [
|
|
83
|
+
{
|
|
84
|
+
name: 'artifact-evaluation',
|
|
85
|
+
script: 'plugins/hooks/artifact-evaluation-hook.js',
|
|
86
|
+
matcher: 'Write',
|
|
87
|
+
priority: 36,
|
|
88
|
+
description: '产出物评测(结构检查 + AI 质量评估触发)'
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: 'execution-tracker',
|
|
92
|
+
script: 'plugins/hooks/execution-tracker.js',
|
|
93
|
+
matcher: 'Write|Edit|Agent',
|
|
94
|
+
priority: 35,
|
|
95
|
+
description: '追踪关键步骤执行日志(skill 加载、agent 调用、产物生成、阶段完成)'
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: 'layer1-validator',
|
|
99
|
+
script: 'plugins/hooks/layer1-validator.js',
|
|
100
|
+
matcher: 'Write|Edit|Bash|Agent|AskUserQuestion',
|
|
101
|
+
priority: 40,
|
|
102
|
+
description: 'Layer 1 结果捕获 + 质量指标追踪'
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: 'ai-project-guard',
|
|
106
|
+
script: 'plugins/hooks/ai-project-guard.js',
|
|
107
|
+
matcher: 'Bash',
|
|
108
|
+
priority: 50,
|
|
109
|
+
condition: 'isAIProject',
|
|
110
|
+
description: 'AI 项目安全检查 + 效果验证'
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: 'pipeline-observer',
|
|
114
|
+
script: 'plugins/hooks/pipeline-observer.js',
|
|
115
|
+
matcher: '',
|
|
116
|
+
priority: 10,
|
|
117
|
+
description: '全链路事件采集和分析'
|
|
118
|
+
}
|
|
119
|
+
],
|
|
120
|
+
|
|
121
|
+
// Stop - 会话结束
|
|
122
|
+
Stop: [
|
|
123
|
+
{
|
|
124
|
+
name: 'pipeline-observer',
|
|
125
|
+
script: 'plugins/hooks/pipeline-observer.js',
|
|
126
|
+
priority: 10,
|
|
127
|
+
description: '会话结束时生成评测报告'
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: 'environment-manager',
|
|
131
|
+
script: 'plugins/hooks/environment-manager.js',
|
|
132
|
+
priority: 15,
|
|
133
|
+
description: '环境知识验证 + 环境进化检查'
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 获取指定事件类型的 hooks,按优先级排序
|
|
140
|
+
*/
|
|
141
|
+
export function getHooksForEvent(eventName) {
|
|
142
|
+
const hooks = HOOKS_CONFIG[eventName] || [];
|
|
143
|
+
return hooks.sort((a, b) => b.priority - a.priority);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* 检查 hook 是否应该对某个工具执行
|
|
148
|
+
*/
|
|
149
|
+
export function shouldHookRun(hook, toolName) {
|
|
150
|
+
// 无条件执行(matcher 为空)
|
|
151
|
+
if (!hook.matcher) {
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 检查工具名匹配
|
|
156
|
+
const matchers = hook.matcher.split('|').map(m => m.trim());
|
|
157
|
+
return matchers.includes(toolName);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* 构建完整的 hook 路径
|
|
162
|
+
*/
|
|
163
|
+
export function resolveHookPath(scriptPath, baseDir) {
|
|
164
|
+
if (scriptPath.startsWith('/')) {
|
|
165
|
+
return scriptPath;
|
|
166
|
+
}
|
|
167
|
+
return `${baseDir}/${scriptPath}`;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* 生成 Claude Code hooks 配置
|
|
172
|
+
* 输出格式与 claude-integration.js 兼容
|
|
173
|
+
*/
|
|
174
|
+
export function generateClaudeHooksConfig(autospecDir) {
|
|
175
|
+
const configs = [];
|
|
176
|
+
|
|
177
|
+
for (const [event, hooks] of Object.entries(HOOKS_CONFIG)) {
|
|
178
|
+
for (const hook of hooks) {
|
|
179
|
+
// 构建命令
|
|
180
|
+
const scriptPath = resolveHookPath(hook.script, autospecDir);
|
|
181
|
+
const command = `node ${scriptPath}`;
|
|
182
|
+
|
|
183
|
+
configs.push({
|
|
184
|
+
event,
|
|
185
|
+
command,
|
|
186
|
+
name: hook.name,
|
|
187
|
+
priority: hook.priority,
|
|
188
|
+
matcher: hook.matcher || '',
|
|
189
|
+
description: hook.description
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return configs;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export default HOOKS_CONFIG;
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evolution Router - 进化分流器
|
|
3
|
+
*
|
|
4
|
+
* 实现进化分区决策逻辑
|
|
5
|
+
* 集成记忆模块:读取 team-preferences 和 constraints 辅助决策
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import os from 'os';
|
|
10
|
+
import {
|
|
11
|
+
KNOWLEDGE_ZONES,
|
|
12
|
+
KNOWLEDGE_SCOPE,
|
|
13
|
+
GLOBAL_AUTOSPEC_DIR,
|
|
14
|
+
ORG_AUTOSPEC_DIR
|
|
15
|
+
} from '../install/constants.js';
|
|
16
|
+
|
|
17
|
+
// 记忆模块延迟加载
|
|
18
|
+
let memoryManager = null;
|
|
19
|
+
function getMemoryManager() {
|
|
20
|
+
if (memoryManager === null) {
|
|
21
|
+
try {
|
|
22
|
+
// eslint-disable-next-line import/no-unresolved
|
|
23
|
+
memoryManager = require('../../plugins/hooks/lib/memory-manager.js');
|
|
24
|
+
} catch (e) {
|
|
25
|
+
memoryManager = false; // 标记为不可用
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return memoryManager || null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 获取进化分区
|
|
33
|
+
* @param {string} knowledgePath - 知识路径
|
|
34
|
+
* @returns {string} 知识分区
|
|
35
|
+
*/
|
|
36
|
+
export function getEvolutionZone(knowledgePath) {
|
|
37
|
+
// 冻结区检测
|
|
38
|
+
if (/\/knowledge\/principles\/(constitution|evolution|design-philosophy)\.md$/.test(knowledgePath)) {
|
|
39
|
+
return KNOWLEDGE_ZONES.FROZEN;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 受控区检测
|
|
43
|
+
if (/\/knowledge\/(process|guides\/support|config|checklists)\//.test(knowledgePath)) {
|
|
44
|
+
return KNOWLEDGE_ZONES.CONTROLLED;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 自由区检测
|
|
48
|
+
if (/\/knowledge\/guides\/stages\/|\/knowledge\/domain\/|\/plugins\/skills\//.test(knowledgePath)) {
|
|
49
|
+
return KNOWLEDGE_ZONES.FREE;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 默认返回受控区
|
|
53
|
+
return KNOWLEDGE_ZONES.CONTROLLED;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 获取进化目标路径
|
|
58
|
+
* @param {string} targetScope - 目标作用域 (global|org)
|
|
59
|
+
* @param {string} knowledgeType - 知识类型
|
|
60
|
+
* @param {Object} options - 选项
|
|
61
|
+
* @returns {string} 目标路径
|
|
62
|
+
*/
|
|
63
|
+
export function getEvolutionTargetPath(targetScope, knowledgeType, options = {}) {
|
|
64
|
+
const { orgName = null } = options;
|
|
65
|
+
|
|
66
|
+
const baseDir = targetScope === KNOWLEDGE_SCOPE.ORG
|
|
67
|
+
? path.join(os.homedir(), ORG_AUTOSPEC_DIR, orgName)
|
|
68
|
+
: path.join(os.homedir(), GLOBAL_AUTOSPEC_DIR);
|
|
69
|
+
|
|
70
|
+
return path.join(baseDir, knowledgeType);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 路由进化决策
|
|
75
|
+
*
|
|
76
|
+
* @param {string} knowledgePath - 知识路径
|
|
77
|
+
* @param {Object} options - 选项
|
|
78
|
+
* @returns {Object} 进化决策 { action, target, path, reason }
|
|
79
|
+
*/
|
|
80
|
+
export function routeEvolution(knowledgePath, options = {}) {
|
|
81
|
+
const { projectRoot = '.', orgName = null, autoApprove = false } = options;
|
|
82
|
+
|
|
83
|
+
// 获取知识分区
|
|
84
|
+
const zone = getEvolutionZone(knowledgePath);
|
|
85
|
+
|
|
86
|
+
// 尝试从记忆模块获取进化偏好
|
|
87
|
+
let evolutionMode = 'auto'; // 默认自动进化
|
|
88
|
+
const mm = getMemoryManager();
|
|
89
|
+
if (mm) {
|
|
90
|
+
try {
|
|
91
|
+
const preferences = mm.getTeamPreferences(projectRoot);
|
|
92
|
+
evolutionMode = preferences?.workflowPreferences?.evolutionMode || 'auto';
|
|
93
|
+
} catch (e) {
|
|
94
|
+
// 使用默认模式
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 根据分区决定进化动作
|
|
99
|
+
switch (zone) {
|
|
100
|
+
case KNOWLEDGE_ZONES.FROZEN:
|
|
101
|
+
// 冻结区:拒绝进化
|
|
102
|
+
return {
|
|
103
|
+
action: 'reject',
|
|
104
|
+
reason: 'frozen-zone',
|
|
105
|
+
message: '冻结区知识不允许进化'
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
case KNOWLEDGE_ZONES.CONTROLLED:
|
|
109
|
+
// 受控区:根据偏好决定
|
|
110
|
+
if (autoApprove || evolutionMode === 'auto') {
|
|
111
|
+
// 自动回流到全局
|
|
112
|
+
return {
|
|
113
|
+
action: 'auto-merge',
|
|
114
|
+
target: KNOWLEDGE_SCOPE.GLOBAL,
|
|
115
|
+
path: getEvolutionTargetPath(KNOWLEDGE_SCOPE.GLOBAL, 'knowledge', { orgName }),
|
|
116
|
+
reason: 'controlled-zone-auto',
|
|
117
|
+
message: '受控区知识自动回流到全局'
|
|
118
|
+
};
|
|
119
|
+
} else {
|
|
120
|
+
// 提议回流,需要人工批准
|
|
121
|
+
return {
|
|
122
|
+
action: 'propose',
|
|
123
|
+
target: KNOWLEDGE_SCOPE.GLOBAL,
|
|
124
|
+
path: getEvolutionTargetPath(KNOWLEDGE_SCOPE.GLOBAL, 'knowledge', { orgName }),
|
|
125
|
+
reason: 'controlled-zone-manual',
|
|
126
|
+
message: '受控区知识需要人工批准后才能回流'
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
case KNOWLEDGE_ZONES.FREE:
|
|
131
|
+
default:
|
|
132
|
+
// 自由区:自动进化和回流
|
|
133
|
+
if (autoApprove || evolutionMode === 'auto') {
|
|
134
|
+
return {
|
|
135
|
+
action: 'auto-merge',
|
|
136
|
+
target: KNOWLEDGE_SCOPE.GLOBAL,
|
|
137
|
+
path: getEvolutionTargetPath(KNOWLEDGE_SCOPE.GLOBAL, 'skills', { orgName }),
|
|
138
|
+
reason: 'free-zone-auto',
|
|
139
|
+
message: '自由区知识自动回流到全局技能库'
|
|
140
|
+
};
|
|
141
|
+
} else {
|
|
142
|
+
return {
|
|
143
|
+
action: 'propose',
|
|
144
|
+
target: KNOWLEDGE_SCOPE.GLOBAL,
|
|
145
|
+
path: getEvolutionTargetPath(KNOWLEDGE_SCOPE.GLOBAL, 'skills', { orgName }),
|
|
146
|
+
reason: 'free-zone-manual',
|
|
147
|
+
message: '自由区知识建议回流,是否确认?'
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 路由进化到组织级别
|
|
155
|
+
*
|
|
156
|
+
* @param {string} knowledgePath - 知识路径
|
|
157
|
+
* @param {string} orgName - 组织名称
|
|
158
|
+
* @param {Object} options - 选项
|
|
159
|
+
* @returns {Object} 进化决策
|
|
160
|
+
*/
|
|
161
|
+
export function routeEvolutionToOrg(knowledgePath, orgName, options = {}) {
|
|
162
|
+
const { autoApprove = false } = options;
|
|
163
|
+
|
|
164
|
+
const zone = getEvolutionZone(knowledgePath);
|
|
165
|
+
|
|
166
|
+
// 冻结区不允许任何进化
|
|
167
|
+
if (zone === KNOWLEDGE_ZONES.FROZEN) {
|
|
168
|
+
return {
|
|
169
|
+
action: 'reject',
|
|
170
|
+
reason: 'frozen-zone',
|
|
171
|
+
message: '冻结区知识不允许进化到组织'
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// 其他分区都可以进化到组织
|
|
176
|
+
if (autoApprove) {
|
|
177
|
+
return {
|
|
178
|
+
action: 'auto-merge',
|
|
179
|
+
target: KNOWLEDGE_SCOPE.ORG,
|
|
180
|
+
path: getEvolutionTargetPath(KNOWLEDGE_SCOPE.ORG, 'skills', { orgName }),
|
|
181
|
+
reason: 'org-auto',
|
|
182
|
+
message: `自动进化到组织 ${orgName}`
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
action: 'propose',
|
|
188
|
+
target: KNOWLEDGE_SCOPE.ORG,
|
|
189
|
+
path: getEvolutionTargetPath(KNOWLEDGE_SCOPE.ORG, 'skills', { orgName }),
|
|
190
|
+
reason: 'org-manual',
|
|
191
|
+
message: `建议进化到组织 ${orgName},是否确认?`
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* 检查是否允许回流到全局
|
|
197
|
+
* 集成记忆模块的 constraints
|
|
198
|
+
*
|
|
199
|
+
* @param {string} knowledgePath - 知识路径
|
|
200
|
+
* @param {Object} options - 选项
|
|
201
|
+
* @returns {Object} 检查结果 { allowed, reason }
|
|
202
|
+
*/
|
|
203
|
+
export function checkGlobalMergeAllowed(knowledgePath, options = {}) {
|
|
204
|
+
const { projectRoot = '.' } = options;
|
|
205
|
+
|
|
206
|
+
// 冻结区直接拒绝
|
|
207
|
+
const zone = getEvolutionZone(knowledgePath);
|
|
208
|
+
if (zone === KNOWLEDGE_ZONES.FROZEN) {
|
|
209
|
+
return { allowed: false, reason: 'frozen-zone' };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// 尝试从记忆模块获取约束
|
|
213
|
+
const mm = getMemoryManager();
|
|
214
|
+
if (mm) {
|
|
215
|
+
try {
|
|
216
|
+
const constraints = mm.getConstraints(projectRoot);
|
|
217
|
+
const hardConstraints = constraints?.hardConstraints || [];
|
|
218
|
+
|
|
219
|
+
// 检查是否有硬约束阻止回流
|
|
220
|
+
for (const constraint of hardConstraints) {
|
|
221
|
+
if (constraint.content.includes('禁止回流') || constraint.content.includes('不允许全局')) {
|
|
222
|
+
return { allowed: false, reason: 'hard-constraint', detail: constraint.content };
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
} catch (e) {
|
|
226
|
+
// 使用默认行为
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return { allowed: true, reason: 'ok' };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* 获取回流目标列表
|
|
235
|
+
*
|
|
236
|
+
* @param {string} knowledgePath - 知识路径
|
|
237
|
+
* @param {Object} options - 选项
|
|
238
|
+
* @returns {Array} 可用的回流目标
|
|
239
|
+
*/
|
|
240
|
+
export function getEvolutionTargets(knowledgePath, options = {}) {
|
|
241
|
+
const { orgName = null } = options;
|
|
242
|
+
|
|
243
|
+
const targets = [
|
|
244
|
+
{
|
|
245
|
+
scope: KNOWLEDGE_SCOPE.GLOBAL,
|
|
246
|
+
label: '用户全局',
|
|
247
|
+
path: getEvolutionTargetPath(KNOWLEDGE_SCOPE.GLOBAL, 'skills'),
|
|
248
|
+
priority: 1
|
|
249
|
+
}
|
|
250
|
+
];
|
|
251
|
+
|
|
252
|
+
// 如果有组织名称,添加组织目标
|
|
253
|
+
if (orgName) {
|
|
254
|
+
targets.push({
|
|
255
|
+
scope: KNOWLEDGE_SCOPE.ORG,
|
|
256
|
+
label: `组织: ${orgName}`,
|
|
257
|
+
path: getEvolutionTargetPath(KNOWLEDGE_SCOPE.ORG, 'skills', { orgName }),
|
|
258
|
+
priority: 2
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// 按优先级排序
|
|
263
|
+
return targets.sort((a, b) => a.priority - b.priority);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export default {
|
|
267
|
+
getEvolutionZone,
|
|
268
|
+
getEvolutionTargetPath,
|
|
269
|
+
routeEvolution,
|
|
270
|
+
routeEvolutionToOrg,
|
|
271
|
+
checkGlobalMergeAllowed,
|
|
272
|
+
getEvolutionTargets
|
|
273
|
+
};
|