@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,377 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Extractor - 从对话中提取记忆
|
|
3
|
+
*
|
|
4
|
+
* 自动识别对话中的关键信息,写入对应的记忆层
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
MEMORY_SCOPE,
|
|
9
|
+
MEMORY_FILES
|
|
10
|
+
} from '../../../scripts/install/constants.js';
|
|
11
|
+
import {
|
|
12
|
+
getNorthStar,
|
|
13
|
+
updateNorthStar,
|
|
14
|
+
addKeyResult,
|
|
15
|
+
addActiveDecision,
|
|
16
|
+
getTeamPreferences,
|
|
17
|
+
updateTeamPreferences,
|
|
18
|
+
addHardConstraint,
|
|
19
|
+
getTechStack,
|
|
20
|
+
updateTechStack,
|
|
21
|
+
addArchitectureDecision,
|
|
22
|
+
addSession
|
|
23
|
+
} from './memory-manager.js';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 提取模式定义
|
|
27
|
+
*/
|
|
28
|
+
const EXTRACTION_PATTERNS = {
|
|
29
|
+
// 目标/指标相关 → 项目北极星
|
|
30
|
+
goals: [
|
|
31
|
+
{ patterns: [/我们的目标是/, /项目目标/, /产品目标/], type: 'mission' },
|
|
32
|
+
{ patterns: [/北极星指标/, /核心指标/, /关键指标/], type: 'northStarMetric' },
|
|
33
|
+
{ patterns: [/关键结果/, /KR\d*/, /里程碑/], type: 'keyResult' },
|
|
34
|
+
{ patterns: [/愿景/, /未来展望/, /长期目标/], type: 'vision' }
|
|
35
|
+
],
|
|
36
|
+
|
|
37
|
+
// 偏好相关 → 全局/项目偏好
|
|
38
|
+
preferences: [
|
|
39
|
+
{ patterns: [/我们偏好/, /我们喜欢/, /倾向于/], type: 'preference' },
|
|
40
|
+
{ patterns: [/不要/, /禁止/, /不允许/, /不能/], type: 'constraint' },
|
|
41
|
+
{ patterns: [/默认使用/, /默认配置/, /标准做法/], type: 'default' },
|
|
42
|
+
{ patterns: [/风格/, /习惯/, /惯例/], type: 'style' }
|
|
43
|
+
],
|
|
44
|
+
|
|
45
|
+
// 决策相关 → 项目架构记录
|
|
46
|
+
decisions: [
|
|
47
|
+
{ patterns: [/决定采用/, /选择使用/, /选定/, /最终方案/], type: 'decision' },
|
|
48
|
+
{ patterns: [/权衡后/, /综合考虑/, /对比之后/], type: 'tradeoff' },
|
|
49
|
+
{ patterns: [/放弃/, /不采用/, /排除/], type: 'rejected' }
|
|
50
|
+
],
|
|
51
|
+
|
|
52
|
+
// 技术栈相关 → 项目技术栈
|
|
53
|
+
techStack: [
|
|
54
|
+
{ patterns: [/使用.*框架/, /技术栈/, /技术选型/], type: 'framework' },
|
|
55
|
+
{ patterns: [/部署到/, /运行环境/, /基础设施/], type: 'environment' },
|
|
56
|
+
{ patterns: [/依赖/, /库/, /包/], type: 'dependency' }
|
|
57
|
+
]
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 记忆提取结果类型
|
|
62
|
+
*/
|
|
63
|
+
const MEMORY_TYPES = {
|
|
64
|
+
MISSION: 'mission',
|
|
65
|
+
NORTH_STAR: 'northStar',
|
|
66
|
+
KEY_RESULT: 'keyResult',
|
|
67
|
+
VISION: 'vision',
|
|
68
|
+
PREFERENCE: 'preference',
|
|
69
|
+
CONSTRAINT: 'constraint',
|
|
70
|
+
DECISION: 'decision',
|
|
71
|
+
TECH_STACK: 'techStack',
|
|
72
|
+
SESSION_SUMMARY: 'sessionSummary'
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 从文本中提取记忆
|
|
77
|
+
* @param {string} text - 对话文本
|
|
78
|
+
* @param {Object} context - 上下文信息
|
|
79
|
+
* @returns {Array<Object>} 提取的记忆列表
|
|
80
|
+
*/
|
|
81
|
+
export function extractFromText(text, context = {}) {
|
|
82
|
+
const extractions = [];
|
|
83
|
+
|
|
84
|
+
// 提取目标相关信息
|
|
85
|
+
EXTRACTION_PATTERNS.goals.forEach(({ patterns, type }) => {
|
|
86
|
+
patterns.forEach(pattern => {
|
|
87
|
+
const matches = text.matchAll(new RegExp(pattern.source, 'gi'));
|
|
88
|
+
for (const match of matches) {
|
|
89
|
+
// 获取匹配后的句子
|
|
90
|
+
const startIndex = match.index;
|
|
91
|
+
const endIndex = text.indexOf('。', startIndex);
|
|
92
|
+
const sentence = endIndex > startIndex
|
|
93
|
+
? text.slice(startIndex, endIndex + 1)
|
|
94
|
+
: text.slice(startIndex, startIndex + 100);
|
|
95
|
+
|
|
96
|
+
extractions.push({
|
|
97
|
+
type: MEMORY_TYPES[type.toUpperCase()] || type,
|
|
98
|
+
content: sentence.trim(),
|
|
99
|
+
context: {
|
|
100
|
+
matched: match[0],
|
|
101
|
+
fullText: text.slice(Math.max(0, startIndex - 50), startIndex + 150)
|
|
102
|
+
},
|
|
103
|
+
confidence: 'medium',
|
|
104
|
+
source: 'conversation'
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// 提取偏好相关信息
|
|
111
|
+
EXTRACTION_PATTERNS.preferences.forEach(({ patterns, type }) => {
|
|
112
|
+
patterns.forEach(pattern => {
|
|
113
|
+
const matches = text.matchAll(new RegExp(pattern.source, 'gi'));
|
|
114
|
+
for (const match of matches) {
|
|
115
|
+
const startIndex = match.index;
|
|
116
|
+
const endIndex = text.indexOf('。', startIndex);
|
|
117
|
+
const sentence = endIndex > startIndex
|
|
118
|
+
? text.slice(startIndex, endIndex + 1)
|
|
119
|
+
: text.slice(startIndex, startIndex + 100);
|
|
120
|
+
|
|
121
|
+
extractions.push({
|
|
122
|
+
type: type === 'constraint' ? MEMORY_TYPES.CONSTRAINT : MEMORY_TYPES.PREFERENCE,
|
|
123
|
+
content: sentence.trim(),
|
|
124
|
+
context: {
|
|
125
|
+
matched: match[0],
|
|
126
|
+
fullText: text.slice(Math.max(0, startIndex - 50), startIndex + 150)
|
|
127
|
+
},
|
|
128
|
+
confidence: 'medium',
|
|
129
|
+
source: 'conversation'
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// 提取决策相关信息
|
|
136
|
+
EXTRACTION_PATTERNS.decisions.forEach(({ patterns, type }) => {
|
|
137
|
+
patterns.forEach(pattern => {
|
|
138
|
+
const matches = text.matchAll(new RegExp(pattern.source, 'gi'));
|
|
139
|
+
for (const match of matches) {
|
|
140
|
+
const startIndex = match.index;
|
|
141
|
+
const endIndex = text.indexOf('。', startIndex);
|
|
142
|
+
const sentence = endIndex > startIndex
|
|
143
|
+
? text.slice(startIndex, endIndex + 1)
|
|
144
|
+
: text.slice(startIndex, startIndex + 100);
|
|
145
|
+
|
|
146
|
+
extractions.push({
|
|
147
|
+
type: MEMORY_TYPES.DECISION,
|
|
148
|
+
content: sentence.trim(),
|
|
149
|
+
decisionType: type,
|
|
150
|
+
context: {
|
|
151
|
+
matched: match[0],
|
|
152
|
+
fullText: text.slice(Math.max(0, startIndex - 50), startIndex + 150)
|
|
153
|
+
},
|
|
154
|
+
confidence: 'high',
|
|
155
|
+
source: 'conversation'
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// 去重
|
|
162
|
+
const uniqueExtractions = [];
|
|
163
|
+
const seen = new Set();
|
|
164
|
+
extractions.forEach(e => {
|
|
165
|
+
const key = `${e.type}:${e.content}`;
|
|
166
|
+
if (!seen.has(key)) {
|
|
167
|
+
seen.add(key);
|
|
168
|
+
uniqueExtractions.push(e);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
return uniqueExtractions;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* 将提取的记忆写入对应的存储
|
|
177
|
+
* @param {string} projectRoot - 项目根目录
|
|
178
|
+
* @param {Array<Object>} extractions - 提取的记忆列表
|
|
179
|
+
* @param {Object} options - 选项
|
|
180
|
+
* @returns {Object} 写入结果
|
|
181
|
+
*/
|
|
182
|
+
export function writeExtractions(projectRoot, extractions, options = {}) {
|
|
183
|
+
const results = {
|
|
184
|
+
success: [],
|
|
185
|
+
failed: [],
|
|
186
|
+
pending: []
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const { autoConfirm = false, defaultScope = MEMORY_SCOPE.PROJECT } = options;
|
|
190
|
+
|
|
191
|
+
extractions.forEach(extraction => {
|
|
192
|
+
try {
|
|
193
|
+
switch (extraction.type) {
|
|
194
|
+
case MEMORY_TYPES.MISSION:
|
|
195
|
+
case MEMORY_TYPES.VISION:
|
|
196
|
+
// 更新北极星
|
|
197
|
+
const northStar = getNorthStar(projectRoot);
|
|
198
|
+
if (extraction.type === MEMORY_TYPES.MISSION) {
|
|
199
|
+
if (autoConfirm || !northStar.mission) {
|
|
200
|
+
updateNorthStar(projectRoot, { mission: extraction.content });
|
|
201
|
+
results.success.push({ ...extraction, action: 'updated', target: 'north-star.mission' });
|
|
202
|
+
} else {
|
|
203
|
+
results.pending.push({ ...extraction, reason: 'mission already exists' });
|
|
204
|
+
}
|
|
205
|
+
} else {
|
|
206
|
+
if (autoConfirm || !northStar.vision) {
|
|
207
|
+
updateNorthStar(projectRoot, { vision: extraction.content });
|
|
208
|
+
results.success.push({ ...extraction, action: 'updated', target: 'north-star.vision' });
|
|
209
|
+
} else {
|
|
210
|
+
results.pending.push({ ...extraction, reason: 'vision already exists' });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
break;
|
|
214
|
+
|
|
215
|
+
case MEMORY_TYPES.KEY_RESULT:
|
|
216
|
+
// 添加关键结果
|
|
217
|
+
if (autoConfirm) {
|
|
218
|
+
addKeyResult(projectRoot, {
|
|
219
|
+
title: extraction.content,
|
|
220
|
+
current: '0%',
|
|
221
|
+
status: 'on-track'
|
|
222
|
+
});
|
|
223
|
+
results.success.push({ ...extraction, action: 'added', target: 'north-star.keyResults' });
|
|
224
|
+
} else {
|
|
225
|
+
results.pending.push({ ...extraction, reason: 'needs confirmation for key result' });
|
|
226
|
+
}
|
|
227
|
+
break;
|
|
228
|
+
|
|
229
|
+
case MEMORY_TYPES.PREFERENCE:
|
|
230
|
+
// 更新团队偏好(默认写入全局)
|
|
231
|
+
if (autoConfirm) {
|
|
232
|
+
updateTeamPreferences(MEMORY_SCOPE.GLOBAL, {
|
|
233
|
+
projectSpecific: {
|
|
234
|
+
[Date.now()]: extraction.content
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
results.success.push({ ...extraction, action: 'updated', target: 'global.team-preferences' });
|
|
238
|
+
} else {
|
|
239
|
+
results.pending.push({ ...extraction, reason: 'needs confirmation for preference' });
|
|
240
|
+
}
|
|
241
|
+
break;
|
|
242
|
+
|
|
243
|
+
case MEMORY_TYPES.CONSTRAINT:
|
|
244
|
+
// 添加约束(默认写入全局)
|
|
245
|
+
if (autoConfirm) {
|
|
246
|
+
addHardConstraint(MEMORY_SCOPE.GLOBAL, extraction.content);
|
|
247
|
+
results.success.push({ ...extraction, action: 'added', target: 'global.constraints' });
|
|
248
|
+
} else {
|
|
249
|
+
results.pending.push({ ...extraction, reason: 'needs confirmation for constraint' });
|
|
250
|
+
}
|
|
251
|
+
break;
|
|
252
|
+
|
|
253
|
+
case MEMORY_TYPES.DECISION:
|
|
254
|
+
// 添加架构决策
|
|
255
|
+
if (autoConfirm) {
|
|
256
|
+
addArchitectureDecision(projectRoot, {
|
|
257
|
+
title: extraction.content.slice(0, 50),
|
|
258
|
+
context: extraction.context?.fullText || '',
|
|
259
|
+
decision: extraction.content,
|
|
260
|
+
decisionType: extraction.decisionType
|
|
261
|
+
});
|
|
262
|
+
results.success.push({ ...extraction, action: 'added', target: 'project.architecture' });
|
|
263
|
+
} else {
|
|
264
|
+
results.pending.push({ ...extraction, reason: 'needs confirmation for decision' });
|
|
265
|
+
}
|
|
266
|
+
break;
|
|
267
|
+
|
|
268
|
+
case MEMORY_TYPES.TECH_STACK:
|
|
269
|
+
// 更新技术栈
|
|
270
|
+
if (autoConfirm) {
|
|
271
|
+
const techStack = getTechStack(projectRoot);
|
|
272
|
+
techStack.tools = techStack.tools || [];
|
|
273
|
+
techStack.tools.push({
|
|
274
|
+
name: extraction.content,
|
|
275
|
+
addedAt: new Date().toISOString(),
|
|
276
|
+
source: 'auto-extracted'
|
|
277
|
+
});
|
|
278
|
+
updateTechStack(projectRoot, techStack);
|
|
279
|
+
results.success.push({ ...extraction, action: 'updated', target: 'project.tech-stack' });
|
|
280
|
+
} else {
|
|
281
|
+
results.pending.push({ ...extraction, reason: 'needs confirmation for tech stack' });
|
|
282
|
+
}
|
|
283
|
+
break;
|
|
284
|
+
|
|
285
|
+
default:
|
|
286
|
+
results.pending.push({ ...extraction, reason: 'unknown memory type' });
|
|
287
|
+
}
|
|
288
|
+
} catch (error) {
|
|
289
|
+
results.failed.push({ ...extraction, error: error.message });
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
return results;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* 从会话中提取并生成会话摘要
|
|
298
|
+
* @param {string} projectRoot - 项目根目录
|
|
299
|
+
* @param {Object} sessionInfo - 会话信息
|
|
300
|
+
* @returns {Object} 会话摘要
|
|
301
|
+
*/
|
|
302
|
+
export function extractSessionSummary(projectRoot, sessionInfo = {}) {
|
|
303
|
+
const { title = '', keyDecisions = [], keyFiles = [], summary = '' } = sessionInfo;
|
|
304
|
+
|
|
305
|
+
const session = {
|
|
306
|
+
title: title || `会话 ${new Date().toISOString().split('T')[0]}`,
|
|
307
|
+
summary,
|
|
308
|
+
keyDecisions,
|
|
309
|
+
keyFiles,
|
|
310
|
+
tags: extractTags(summary + ' ' + keyDecisions.join(' '))
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
addSession(projectRoot, session);
|
|
314
|
+
|
|
315
|
+
return session;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* 从文本中提取标签
|
|
320
|
+
* @param {string} text - 文本
|
|
321
|
+
* @returns {Array<string>} 标签列表
|
|
322
|
+
*/
|
|
323
|
+
function extractTags(text) {
|
|
324
|
+
const tagPatterns = [
|
|
325
|
+
/架构|设计|重构/gi,
|
|
326
|
+
/测试|QA|质量/gi,
|
|
327
|
+
/性能|优化/gi,
|
|
328
|
+
/安全|漏洞/gi,
|
|
329
|
+
/部署|发布|交付/gi,
|
|
330
|
+
/需求|功能/gi,
|
|
331
|
+
/bug|修复/gi
|
|
332
|
+
];
|
|
333
|
+
|
|
334
|
+
const tags = new Set();
|
|
335
|
+
tagPatterns.forEach(pattern => {
|
|
336
|
+
const matches = text.match(pattern);
|
|
337
|
+
if (matches) {
|
|
338
|
+
matches.forEach(m => tags.add(m.toLowerCase()));
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
return Array.from(tags).slice(0, 5);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* 检查是否应该提取记忆
|
|
347
|
+
* @param {string} event - 事件类型
|
|
348
|
+
* @param {Object} data - 事件数据
|
|
349
|
+
* @returns {boolean} 是否应该提取
|
|
350
|
+
*/
|
|
351
|
+
export function shouldExtract(event, data = {}) {
|
|
352
|
+
// 会话结束时提取
|
|
353
|
+
if (event === 'Stop') {
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// 阶段完成时提取
|
|
358
|
+
if (event === 'StageComplete') {
|
|
359
|
+
return true;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// 交付完成时提取
|
|
363
|
+
if (event === 'DeliveryComplete') {
|
|
364
|
+
return true;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return false;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export default {
|
|
371
|
+
extractFromText,
|
|
372
|
+
writeExtractions,
|
|
373
|
+
extractSessionSummary,
|
|
374
|
+
shouldExtract,
|
|
375
|
+
MEMORY_TYPES,
|
|
376
|
+
EXTRACTION_PATTERNS
|
|
377
|
+
};
|