@hongmaple0820/scale-engine 0.6.0 → 0.7.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/README.md +29 -6
- package/dist/adapters/ClaudeCodeAdapter.d.ts +1 -1
- package/dist/adapters/ClaudeCodeAdapter.js +1 -1
- package/dist/adapters/ClaudeCodeAdapter.js.map +1 -1
- package/dist/adapters/QCoderAdapter.d.ts +13 -0
- package/dist/adapters/QCoderAdapter.js +153 -0
- package/dist/adapters/QCoderAdapter.js.map +1 -0
- package/dist/adapters/TraeAdapter.d.ts +13 -0
- package/dist/adapters/TraeAdapter.js +153 -0
- package/dist/adapters/TraeAdapter.js.map +1 -0
- package/dist/adapters/VSCAdapter.d.ts +13 -0
- package/dist/adapters/VSCAdapter.js +153 -0
- package/dist/adapters/VSCAdapter.js.map +1 -0
- package/dist/adapters/WorkBuddyAdapter.d.ts +13 -0
- package/dist/adapters/WorkBuddyAdapter.js +153 -0
- package/dist/adapters/WorkBuddyAdapter.js.map +1 -0
- package/dist/adapters/index.d.ts +4 -0
- package/dist/adapters/index.js +13 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/api/cli.js +59 -3
- package/dist/api/cli.js.map +1 -1
- package/dist/api/doctor.js +29 -10
- package/dist/api/doctor.js.map +1 -1
- package/dist/artifact/types.d.ts +3 -3
- package/dist/artifact/types.js.map +1 -1
- package/dist/context/ContextBuilder.d.ts +4 -0
- package/dist/context/ContextBuilder.js +43 -9
- package/dist/context/ContextBuilder.js.map +1 -1
- package/dist/dashboard/DashboardServer.d.ts +63 -0
- package/dist/dashboard/DashboardServer.js +167 -0
- package/dist/dashboard/DashboardServer.js.map +1 -0
- package/dist/evolution/AutoDefectCreator.d.ts +34 -0
- package/dist/evolution/AutoDefectCreator.js +115 -0
- package/dist/evolution/AutoDefectCreator.js.map +1 -0
- package/dist/evolution/BehaviorTracker.d.ts +8 -0
- package/dist/evolution/BehaviorTracker.js +18 -1
- package/dist/evolution/BehaviorTracker.js.map +1 -1
- package/dist/evolution/EvolutionEvaluator.d.ts +59 -0
- package/dist/evolution/EvolutionEvaluator.js +115 -0
- package/dist/evolution/EvolutionEvaluator.js.map +1 -0
- package/dist/evolution/LessonValidator.d.ts +36 -0
- package/dist/evolution/LessonValidator.js +136 -0
- package/dist/evolution/LessonValidator.js.map +1 -0
- package/dist/fsm/FSMAgentBridge.d.ts +59 -0
- package/dist/fsm/FSMAgentBridge.js +195 -0
- package/dist/fsm/FSMAgentBridge.js.map +1 -0
- package/dist/fsm/index.d.ts +2 -0
- package/dist/fsm/index.js +3 -0
- package/dist/fsm/index.js.map +1 -0
- package/dist/guardrails/DetectorEnhanced.d.ts +111 -0
- package/dist/guardrails/DetectorEnhanced.js +200 -0
- package/dist/guardrails/DetectorEnhanced.js.map +1 -0
- package/dist/hooks/HookDeployer.d.ts +44 -0
- package/dist/hooks/HookDeployer.js +145 -0
- package/dist/hooks/HookDeployer.js.map +1 -0
- package/dist/hooks/HookGeneratorEnhanced.d.ts +67 -0
- package/dist/hooks/HookGeneratorEnhanced.js +238 -0
- package/dist/hooks/HookGeneratorEnhanced.js.map +1 -0
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/index.js +4 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/index.d.ts +26 -2
- package/dist/index.js +21 -5
- package/dist/index.js.map +1 -1
- package/dist/knowledge/SQLiteKnowledgeBase.js +28 -28
- package/dist/skills/SkillDiscovery.js +8 -0
- package/dist/skills/SkillDiscovery.js.map +1 -1
- package/dist/skills/SkillExecutor.d.ts +28 -0
- package/dist/skills/SkillExecutor.js +84 -0
- package/dist/skills/SkillExecutor.js.map +1 -0
- package/dist/skills/SkillRegistry.d.ts +93 -0
- package/dist/skills/SkillRegistry.js +130 -0
- package/dist/skills/SkillRegistry.js.map +1 -0
- package/dist/skills/TriggerEngine.d.ts +43 -0
- package/dist/skills/TriggerEngine.js +144 -0
- package/dist/skills/TriggerEngine.js.map +1 -0
- package/dist/skills/coreSkills.d.ts +6 -0
- package/dist/skills/coreSkills.js +41 -0
- package/dist/skills/coreSkills.js.map +1 -0
- package/dist/skills/index.d.ts +4 -0
- package/dist/skills/index.js +6 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/workflows/GateParser.d.ts +55 -0
- package/dist/workflows/GateParser.js +73 -0
- package/dist/workflows/GateParser.js.map +1 -0
- package/dist/workflows/WorkflowExecutor.d.ts +56 -0
- package/dist/workflows/WorkflowExecutor.js +145 -0
- package/dist/workflows/WorkflowExecutor.js.map +1 -0
- package/dist/workflows/index.d.ts +4 -0
- package/dist/workflows/index.js +5 -0
- package/dist/workflows/index.js.map +1 -0
- package/package.json +5 -2
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { IEventBus } from '../core/eventBus.js';
|
|
2
|
+
import type { IKnowledgeBase } from '../knowledge/KnowledgeBase.js';
|
|
3
|
+
import type { DetectorStatisticsTracker } from '../guardrails/DetectorEnhanced.js';
|
|
4
|
+
export interface EvolutionMetrics {
|
|
5
|
+
lessonsProposed: number;
|
|
6
|
+
lessonsValidated: number;
|
|
7
|
+
lessonsApproved: number;
|
|
8
|
+
lessonsRejected: number;
|
|
9
|
+
lessonQualityScore: number;
|
|
10
|
+
rulesProposed: number;
|
|
11
|
+
rulesApproved: number;
|
|
12
|
+
rulesEnforced: number;
|
|
13
|
+
ruleEffectivenessScore: number;
|
|
14
|
+
hooksGenerated: number;
|
|
15
|
+
hooksDeployed: number;
|
|
16
|
+
hooksTriggered: number;
|
|
17
|
+
hookBlockingRate: number;
|
|
18
|
+
detectorTriggers: number;
|
|
19
|
+
detectorBlocks: number;
|
|
20
|
+
detectorWarnings: number;
|
|
21
|
+
detectorEffectivenessScore: number;
|
|
22
|
+
overallScore: number;
|
|
23
|
+
trend: 'improving' | 'stable' | 'declining';
|
|
24
|
+
}
|
|
25
|
+
export interface EvolutionSnapshot {
|
|
26
|
+
timestamp: number;
|
|
27
|
+
metrics: EvolutionMetrics;
|
|
28
|
+
}
|
|
29
|
+
export interface IEvolutionEvaluator {
|
|
30
|
+
evaluate(): Promise<EvolutionMetrics>;
|
|
31
|
+
getHistory(): EvolutionSnapshot[];
|
|
32
|
+
compareWithBaseline(baseline: EvolutionMetrics): Promise<{
|
|
33
|
+
improved: boolean;
|
|
34
|
+
delta: Partial<EvolutionMetrics>;
|
|
35
|
+
}>;
|
|
36
|
+
getRecommendations(): Promise<string[]>;
|
|
37
|
+
}
|
|
38
|
+
export declare class EvolutionEvaluator implements IEvolutionEvaluator {
|
|
39
|
+
private eventBus;
|
|
40
|
+
private stats?;
|
|
41
|
+
private history;
|
|
42
|
+
private maxHistory;
|
|
43
|
+
constructor(eventBus: IEventBus, _kb?: IKnowledgeBase, stats?: DetectorStatisticsTracker | undefined, opts?: {
|
|
44
|
+
maxHistory?: number;
|
|
45
|
+
});
|
|
46
|
+
evaluate(): Promise<EvolutionMetrics>;
|
|
47
|
+
getHistory(): EvolutionSnapshot[];
|
|
48
|
+
compareWithBaseline(baseline: EvolutionMetrics): Promise<{
|
|
49
|
+
improved: boolean;
|
|
50
|
+
delta: Partial<EvolutionMetrics>;
|
|
51
|
+
}>;
|
|
52
|
+
getRecommendations(): Promise<string[]>;
|
|
53
|
+
private countEvents;
|
|
54
|
+
private calculateLessonQuality;
|
|
55
|
+
private calculateRuleEffectiveness;
|
|
56
|
+
private calculateDetectorEffectiveness;
|
|
57
|
+
private calculateOverallScore;
|
|
58
|
+
private determineTrend;
|
|
59
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// SCALE Engine — Evolution Evaluator (v0.7.0)
|
|
2
|
+
// Self-evolution 循环效果评估
|
|
3
|
+
import { logger } from '../core/logger.js';
|
|
4
|
+
export class EvolutionEvaluator {
|
|
5
|
+
eventBus;
|
|
6
|
+
stats;
|
|
7
|
+
history = [];
|
|
8
|
+
maxHistory;
|
|
9
|
+
constructor(eventBus,
|
|
10
|
+
// kb is reserved for future use with KB-based metrics
|
|
11
|
+
_kb, stats, opts = {}) {
|
|
12
|
+
this.eventBus = eventBus;
|
|
13
|
+
this.stats = stats;
|
|
14
|
+
this.maxHistory = opts.maxHistory ?? 30;
|
|
15
|
+
}
|
|
16
|
+
async evaluate() {
|
|
17
|
+
const metrics = {
|
|
18
|
+
lessonsProposed: await this.countEvents('lesson.proposed'),
|
|
19
|
+
lessonsValidated: await this.countEvents('lesson.validated'),
|
|
20
|
+
lessonsApproved: await this.countEvents('lesson.approved'),
|
|
21
|
+
lessonsRejected: await this.countEvents('lesson.rejected'),
|
|
22
|
+
lessonQualityScore: 0,
|
|
23
|
+
rulesProposed: await this.countEvents('rule.proposed'),
|
|
24
|
+
rulesApproved: await this.countEvents('rule.approved'),
|
|
25
|
+
rulesEnforced: await this.countEvents('rule.enforced'),
|
|
26
|
+
ruleEffectivenessScore: 0,
|
|
27
|
+
hooksGenerated: await this.countEvents('hook.generated'),
|
|
28
|
+
hooksDeployed: await this.countEvents('hook.deployed'),
|
|
29
|
+
hooksTriggered: await this.countEvents('tool.blocked'),
|
|
30
|
+
hookBlockingRate: 0,
|
|
31
|
+
detectorTriggers: this.stats ? this.stats.getRecentTriggers(100).length : 0,
|
|
32
|
+
detectorBlocks: this.stats ? this.stats.getRecentTriggers(100).filter(t => t.severity === 'block' || t.severity === 'deny').length : 0,
|
|
33
|
+
detectorWarnings: this.stats ? this.stats.getRecentTriggers(100).filter(t => t.severity === 'warn').length : 0,
|
|
34
|
+
detectorEffectivenessScore: 0,
|
|
35
|
+
overallScore: 0,
|
|
36
|
+
trend: 'stable',
|
|
37
|
+
};
|
|
38
|
+
metrics.lessonQualityScore = this.calculateLessonQuality(metrics);
|
|
39
|
+
metrics.ruleEffectivenessScore = this.calculateRuleEffectiveness(metrics);
|
|
40
|
+
metrics.hookBlockingRate = metrics.hooksTriggered > 0 ? metrics.detectorBlocks / metrics.hooksTriggered : 0;
|
|
41
|
+
metrics.detectorEffectivenessScore = this.calculateDetectorEffectiveness(metrics);
|
|
42
|
+
metrics.overallScore = this.calculateOverallScore(metrics);
|
|
43
|
+
metrics.trend = this.determineTrend(metrics);
|
|
44
|
+
this.history.push({ timestamp: Date.now(), metrics });
|
|
45
|
+
if (this.history.length > this.maxHistory)
|
|
46
|
+
this.history.shift();
|
|
47
|
+
this.eventBus.emit('evolution.evaluated', { score: metrics.overallScore, trend: metrics.trend });
|
|
48
|
+
logger.info({ score: metrics.overallScore, trend: metrics.trend }, 'Evolution evaluated');
|
|
49
|
+
return metrics;
|
|
50
|
+
}
|
|
51
|
+
getHistory() { return [...this.history]; }
|
|
52
|
+
async compareWithBaseline(baseline) {
|
|
53
|
+
const current = await this.evaluate();
|
|
54
|
+
const delta = {};
|
|
55
|
+
const keys = ['overallScore', 'lessonQualityScore', 'ruleEffectivenessScore', 'detectorEffectivenessScore'];
|
|
56
|
+
for (const key of keys) {
|
|
57
|
+
const currentVal = current[key];
|
|
58
|
+
const baselineVal = baseline[key];
|
|
59
|
+
const diff = currentVal - baselineVal;
|
|
60
|
+
// @ts-expect-error: Assigning number to optional field is intentional for delta calculation
|
|
61
|
+
delta[key] = diff;
|
|
62
|
+
}
|
|
63
|
+
const improved = delta.overallScore !== undefined && delta.overallScore > 0;
|
|
64
|
+
return { improved, delta };
|
|
65
|
+
}
|
|
66
|
+
async getRecommendations() {
|
|
67
|
+
const metrics = await this.evaluate();
|
|
68
|
+
const recommendations = [];
|
|
69
|
+
if (metrics.lessonQualityScore < 0.5)
|
|
70
|
+
recommendations.push('Lesson quality low. Focus on context-specific lessons.');
|
|
71
|
+
if (metrics.lessonsRejected > metrics.lessonsApproved)
|
|
72
|
+
recommendations.push('High rejection rate. Review validation criteria.');
|
|
73
|
+
if (metrics.rulesProposed > 0 && metrics.rulesApproved === 0)
|
|
74
|
+
recommendations.push('Rules proposed but none approved.');
|
|
75
|
+
if (metrics.hooksGenerated > metrics.hooksDeployed)
|
|
76
|
+
recommendations.push('Hooks not deployed. Run deployment.');
|
|
77
|
+
if (metrics.detectorWarnings > metrics.detectorBlocks * 3)
|
|
78
|
+
recommendations.push('Too many warnings. Consider stricter enforcement.');
|
|
79
|
+
return recommendations;
|
|
80
|
+
}
|
|
81
|
+
async countEvents(type) {
|
|
82
|
+
const events = await this.eventBus.query({ types: [type], limit: 1000 });
|
|
83
|
+
return events.length;
|
|
84
|
+
}
|
|
85
|
+
calculateLessonQuality(m) {
|
|
86
|
+
if (m.lessonsProposed === 0)
|
|
87
|
+
return 0;
|
|
88
|
+
return (m.lessonsApproved / m.lessonsProposed) * 0.6 + (m.lessonsValidated / m.lessonsProposed) * 0.4;
|
|
89
|
+
}
|
|
90
|
+
calculateRuleEffectiveness(m) {
|
|
91
|
+
if (m.rulesApproved === 0)
|
|
92
|
+
return 0;
|
|
93
|
+
return Math.min(1, m.rulesEnforced / m.rulesApproved);
|
|
94
|
+
}
|
|
95
|
+
calculateDetectorEffectiveness(m) {
|
|
96
|
+
if (m.detectorTriggers === 0)
|
|
97
|
+
return 0;
|
|
98
|
+
return Math.min(1, (m.detectorBlocks / m.detectorTriggers) * 2);
|
|
99
|
+
}
|
|
100
|
+
calculateOverallScore(m) {
|
|
101
|
+
return m.lessonQualityScore * 0.3 + m.ruleEffectivenessScore * 0.25 + m.detectorEffectivenessScore * 0.25 + (m.hookBlockingRate > 0 ? 0.2 : 0);
|
|
102
|
+
}
|
|
103
|
+
determineTrend(m) {
|
|
104
|
+
if (this.history.length < 2)
|
|
105
|
+
return 'stable';
|
|
106
|
+
const prev = this.history[this.history.length - 2].metrics.overallScore;
|
|
107
|
+
const delta = m.overallScore - prev;
|
|
108
|
+
if (delta > 0.05)
|
|
109
|
+
return 'improving';
|
|
110
|
+
if (delta < -0.05)
|
|
111
|
+
return 'declining';
|
|
112
|
+
return 'stable';
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=EvolutionEvaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EvolutionEvaluator.js","sourceRoot":"","sources":["../../src/evol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ry } from '../artifact/types.js';
|
|
2
|
+
import type { IEventBus } from '../core/eventBus.js';
|
|
3
|
+
import type { IKnowledgeBase } from '../knowledge/KnowledgeBase.js';
|
|
4
|
+
export interface ValidationResult {
|
|
5
|
+
valid: boolean;
|
|
6
|
+
gateResults: GateResult[];
|
|
7
|
+
overallScore: number;
|
|
8
|
+
reason?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface GateResult {
|
|
11
|
+
gateName: string;
|
|
12
|
+
passed: boolean;
|
|
13
|
+
score: number;
|
|
14
|
+
details: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ILessonValidator {
|
|
17
|
+
validate(entry: Omit<KnowledgeEntry, 'id' | 'createdAt' | 'accessCount' | 'relevance'>): Promise<ValidationResult>;
|
|
18
|
+
checkGoogleability(title: string): Promise<GateResult>;
|
|
19
|
+
checkContextSpecific(entry: Omit<KnowledgeEntry, 'id' | 'createdAt' | 'accessCount' | 'relevance'>): Promise<GateResult>;
|
|
20
|
+
checkDuplicate(title: string, contentRef: string): Promise<GateResult>;
|
|
21
|
+
}
|
|
22
|
+
export declare class LessonValidator implements ILessonValidator {
|
|
23
|
+
private eventBus;
|
|
24
|
+
private kb;
|
|
25
|
+
private minGoogleabilityScore;
|
|
26
|
+
private maxDuplicateSimilarity;
|
|
27
|
+
constructor(eventBus: IEventBus, kb?: IKnowledgeBase, opts?: {
|
|
28
|
+
minGoogleabilityScore?: number;
|
|
29
|
+
maxDuplicateSimilarity?: number;
|
|
30
|
+
});
|
|
31
|
+
validate(entry: Omit<KnowledgeEntry, 'id' | 'createdAt' | 'accessCount' | 'relevance'>): Promise<ValidationResult>;
|
|
32
|
+
checkGoogleability(title: string): Promise<GateResult>;
|
|
33
|
+
checkContextSpecific(entry: Omit<KnowledgeEntry, 'id' | 'createdAt' | 'accessCount' | 'relevance'>): Promise<GateResult>;
|
|
34
|
+
checkDuplicate(title: string, _contentRef: string): Promise<GateResult>;
|
|
35
|
+
private calculateSimilarity;
|
|
36
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// SCALE Engine — Lesson Validator (v0.7.0)
|
|
2
|
+
// Lesson 提取验证:Googleability、Context-Specific、Non-Duplicate
|
|
3
|
+
import { logger } from '../core/logger.js';
|
|
4
|
+
export class LessonValidator {
|
|
5
|
+
eventBus;
|
|
6
|
+
kb;
|
|
7
|
+
minGoogleabilityScore;
|
|
8
|
+
maxDuplicateSimilarity;
|
|
9
|
+
constructor(eventBus, kb, opts = {}) {
|
|
10
|
+
this.eventBus = eventBus;
|
|
11
|
+
this.kb = kb ?? null;
|
|
12
|
+
this.minGoogleabilityScore = opts.minGoogleabilityScore ?? 0.3;
|
|
13
|
+
this.maxDuplicateSimilarity = opts.maxDuplicateSimilarity ?? 0.8;
|
|
14
|
+
}
|
|
15
|
+
async validate(entry) {
|
|
16
|
+
const gateResults = [];
|
|
17
|
+
// Gate 1: Trigger Check (already done by LessonExtractor)
|
|
18
|
+
const triggerGate = {
|
|
19
|
+
gateName: 'trigger',
|
|
20
|
+
passed: true,
|
|
21
|
+
score: 1.0,
|
|
22
|
+
details: 'Defect passed trigger conditions',
|
|
23
|
+
};
|
|
24
|
+
gateResults.push(triggerGate);
|
|
25
|
+
// Gate 2: Googleability (not easily searchable)
|
|
26
|
+
const googleabilityGate = await this.checkGoogleability(entry.title);
|
|
27
|
+
gateResults.push(googleabilityGate);
|
|
28
|
+
// Gate 3: Context-Specific (references specific artifacts)
|
|
29
|
+
const contextGate = await this.checkContextSpecific(entry);
|
|
30
|
+
gateResults.push(contextGate);
|
|
31
|
+
// Gate 4: Deduplication
|
|
32
|
+
const duplicateGate = await this.checkDuplicate(entry.title, entry.contentRef);
|
|
33
|
+
gateResults.push(duplicateGate);
|
|
34
|
+
// Calculate overall score
|
|
35
|
+
const totalScore = gateResults.reduce((sum, g) => sum + g.score, 0) / gateResults.length;
|
|
36
|
+
const allPassed = gateResults.every(g => g.passed);
|
|
37
|
+
const result = {
|
|
38
|
+
valid: allPassed,
|
|
39
|
+
gateResults,
|
|
40
|
+
overallScore: totalScore,
|
|
41
|
+
reason: allPassed ? undefined : 'Failed gates: ' + gateResults.filter(g => !g.passed).map(g => g.gateName).join(', '),
|
|
42
|
+
};
|
|
43
|
+
this.eventBus.emit('lesson.validated', {
|
|
44
|
+
title: entry.title,
|
|
45
|
+
valid: result.valid,
|
|
46
|
+
score: result.overallScore,
|
|
47
|
+
gates: gateResults,
|
|
48
|
+
});
|
|
49
|
+
logger.info({ title: entry.title, valid: result.valid, score: totalScore }, 'Lesson validated');
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
async checkGoogleability(title) {
|
|
53
|
+
// Simulate googleability check (in production, would call actual search API)
|
|
54
|
+
// High googleability = easily found on Google = not unique enough
|
|
55
|
+
// We want lessons that are NOT easily googleable (context-specific)
|
|
56
|
+
// Placeholder implementation: check for generic terms
|
|
57
|
+
const genericTerms = [
|
|
58
|
+
'error', 'bug', 'fix', 'issue', 'how to', 'tutorial',
|
|
59
|
+
'guide', 'documentation', 'reference', 'api', 'example',
|
|
60
|
+
];
|
|
61
|
+
const titleLower = title.toLowerCase();
|
|
62
|
+
const hasGenericTerm = genericTerms.some(t => titleLower.includes(t));
|
|
63
|
+
// If title has many generic terms, it's probably googleable (bad)
|
|
64
|
+
// We want titles that are specific enough that you can't just Google them
|
|
65
|
+
const score = hasGenericTerm ? 0.2 : 0.8;
|
|
66
|
+
const passed = score >= this.minGoogleabilityScore;
|
|
67
|
+
return {
|
|
68
|
+
gateName: 'googleability',
|
|
69
|
+
passed,
|
|
70
|
+
score,
|
|
71
|
+
details: passed
|
|
72
|
+
? 'Title is context-specific, not easily googleable'
|
|
73
|
+
: 'Title contains generic terms, likely googleable',
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
async checkContextSpecific(entry) {
|
|
77
|
+
// Check if lesson references specific context (artifact, project, specific code)
|
|
78
|
+
const hasSourceArtifact = entry.sourceArtifact !== undefined;
|
|
79
|
+
const hasTags = entry.tags.length > 0;
|
|
80
|
+
// Check content for context markers
|
|
81
|
+
const contentRef = entry.contentRef.toLowerCase();
|
|
82
|
+
const hasContextMarkers = /art-|spec-|plan-|task-|defect-/.test(contentRef);
|
|
83
|
+
const score = (hasSourceArtifact ? 0.4 : 0) + (hasTags ? 0.3 : 0) + (hasContextMarkers ? 0.3 : 0);
|
|
84
|
+
const passed = score >= 0.5;
|
|
85
|
+
return {
|
|
86
|
+
gateName: 'context_specific',
|
|
87
|
+
passed,
|
|
88
|
+
score,
|
|
89
|
+
details: passed
|
|
90
|
+
? 'Lesson has context markers (artifact refs, tags)'
|
|
91
|
+
: 'Lesson lacks specific context references',
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
async checkDuplicate(title, _contentRef) {
|
|
95
|
+
if (!this.kb) {
|
|
96
|
+
return {
|
|
97
|
+
gateName: 'deduplication',
|
|
98
|
+
passed: true,
|
|
99
|
+
score: 1.0,
|
|
100
|
+
details: 'No KB available for deduplication check',
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
// Check for similar lessons in KB
|
|
104
|
+
const existing = await this.kb.recall({
|
|
105
|
+
tags: [],
|
|
106
|
+
limit: 100,
|
|
107
|
+
});
|
|
108
|
+
// Simple title similarity check
|
|
109
|
+
const titleLower = title.toLowerCase();
|
|
110
|
+
let maxSimilarity = 0;
|
|
111
|
+
for (const entry of existing) {
|
|
112
|
+
const existingTitle = entry.title.toLowerCase();
|
|
113
|
+
const similarity = this.calculateSimilarity(titleLower, existingTitle);
|
|
114
|
+
maxSimilarity = Math.max(maxSimilarity, similarity);
|
|
115
|
+
}
|
|
116
|
+
const passed = maxSimilarity < this.maxDuplicateSimilarity;
|
|
117
|
+
const score = 1 - maxSimilarity;
|
|
118
|
+
return {
|
|
119
|
+
gateName: 'deduplication',
|
|
120
|
+
passed,
|
|
121
|
+
score,
|
|
122
|
+
details: passed
|
|
123
|
+
? 'No similar lesson found (max similarity: ' + maxSimilarity.toFixed(2) + ')'
|
|
124
|
+
: 'Similar lesson exists (similarity: ' + maxSimilarity.toFixed(2) + ')',
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
calculateSimilarity(a, b) {
|
|
128
|
+
// Simple word overlap similarity
|
|
129
|
+
const wordsA = a.split(/\s+/);
|
|
130
|
+
const wordsB = b.split(/\s+/);
|
|
131
|
+
const intersection = wordsA.filter(w => wordsB.includes(w));
|
|
132
|
+
const union = [...new Set([...wordsA, ...wordsB])];
|
|
133
|
+
return intersection.length / union.length;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=LessonValidator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LessonValidator.js","sourceRoot":"","sources":["../../src/evolution/LessonValidator.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,2DAA2D;AAK3D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAuB1C,MAAM,OAAO,eAAe;IAMhB;IALF,EAAE,CAAuB;IACzB,qBAAqB,CAAQ;IAC7B,sBAAsB,CAAQ;IAEtC,YACU,QAAmB,EAC3B,EAAmB,EACnB,OAA4E,EAAE;QAFtE,aAAQ,GAAR,QAAQ,CAAW;QAI3B,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,IAAI,CAAA;QACpB,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC,qBAAqB,IAAI,GAAG,CAAA;QAC9D,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC,sBAAsB,IAAI,GAAG,CAAA;IAClE,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,KAA6E;QAC1F,MAAM,WAAW,GAAiB,EAAE,CAAA;QAEpC,0DAA0D;QAC1D,MAAM,WAAW,GAAe;YAC9B,QAAQ,EAAE,SAAS;YACnB,MAAM,EAAE,IAAI;YACZ,KAAK,EAAE,GAAG;YACV,OAAO,EAAE,kCAAkC;SAC5C,CAAA;QACD,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,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AC/C,MAAM,UAAU,GAAG,IAAI,CAAC,mBAAmB,CAAC,UAAU,EAAE,aAAa,CAAC,CAAA;YACtE,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,UAAU,CAAC,CAAA;QACrD,CAAC;QAED,MAAM,MAAM,GAAG,aAAa,GAAG,IAAI,CAAC,sBAAsB,CAAA;QAC1D,MAAM,KAAK,GAAG,CAAC,GAAG,aAAa,CAAA;QAE/B,OAAO;YACL,QAAQ,EAAE,eAAe;YACzB,MAAM;YACN,KAAK;YACL,OAAO,EAAE,MAAM;gBACb,CAAC,CAAC,2CAA2C,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,GAAG;gBAC9E,CAAC,CAAC,qCAAqC,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,GAAG;SAC3E,CAAA;IACH,CAAC;IAEO,mBAAmB,CAAC,CAAS,EAAE,CAAS;QAC9C,iCAAiC;QACjC,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAC7B,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAC7B,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;QAC3D,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;QAClD,OAAO,YAAY,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAA;IAC3C,CAAC;CACF"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { IArtifactStore } from "../artifact/store.js";
|
|
2
|
+
import type { IFSM } from "../artifact/fsm.js";
|
|
3
|
+
import type { IEventBus } from "../core/eventBus.js";
|
|
4
|
+
export interface FSMContextSnapshot {
|
|
5
|
+
artifactId: string;
|
|
6
|
+
artifactType: string;
|
|
7
|
+
currentStatus: string;
|
|
8
|
+
allowedTransitions: string[];
|
|
9
|
+
blockingReasons: string[];
|
|
10
|
+
downstreamImpact: string[];
|
|
11
|
+
parentStatus?: string;
|
|
12
|
+
childrenStatuses: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface SessionFSMContext {
|
|
15
|
+
sessionId: string;
|
|
16
|
+
artifacts: FSMContextSnapshot[];
|
|
17
|
+
recalledLessons: string[];
|
|
18
|
+
recommendations: string[];
|
|
19
|
+
generatedAt: number;
|
|
20
|
+
}
|
|
21
|
+
export interface IFSMAgentBridge {
|
|
22
|
+
getFSMContext(artifactId: string): Promise<FSMContextSnapshot | null>;
|
|
23
|
+
getSessionContext(sessionId: string, eventBus: IEventBus): Promise<SessionFSMContext>;
|
|
24
|
+
checkOperation(artifactId: string, operation: string): Promise<{
|
|
25
|
+
allowed: boolean;
|
|
26
|
+
reasons: string[];
|
|
27
|
+
}>;
|
|
28
|
+
getCreationPrerequisites(artifactType: string): Promise<{
|
|
29
|
+
requiredParentStatus: string[];
|
|
30
|
+
message: string;
|
|
31
|
+
}>;
|
|
32
|
+
injectFSMContextToPrompt(prompt: string, artifactIds: string[]): Promise<string>;
|
|
33
|
+
}
|
|
34
|
+
export declare class FSMAgentBridge implements IFSMAgentBridge {
|
|
35
|
+
private fsm;
|
|
36
|
+
private store;
|
|
37
|
+
constructor(fsm: IFSM, store: IArtifactStore);
|
|
38
|
+
getFSMContext(artifactId: string): Promise<FSMContextSnapshot | null>;
|
|
39
|
+
checkOperation(artifactId: string, operation: string): Promise<{
|
|
40
|
+
allowed: boolean;
|
|
41
|
+
reasons: string[];
|
|
42
|
+
}>;
|
|
43
|
+
getCreationPrerequisites(artifactType: string): Promise<{
|
|
44
|
+
requiredParentStatus: string[];
|
|
45
|
+
message: string;
|
|
46
|
+
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Get FSM context for all artifacts related to a session
|
|
49
|
+
* This is the primary method for SessionStart hook to inject context
|
|
50
|
+
*/
|
|
51
|
+
getSessionContext(sessionId: string, eventBus: IEventBus): Promise<SessionFSMContext>;
|
|
52
|
+
/**
|
|
53
|
+
* Generate actionable recommendations from FSM state
|
|
54
|
+
*/
|
|
55
|
+
private generateRecommendations;
|
|
56
|
+
injectFSMContextToPrompt(prompt: string, artifactIds: string[]): Promise<string>;
|
|
57
|
+
private calculateDownstreamImpact;
|
|
58
|
+
private formatFSMBlock;
|
|
59
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// SCALE Engine — FSM Agent Bridge (v0.7.0)
|
|
2
|
+
// 让 Agent 能感知 FSM 状态约束
|
|
3
|
+
export class FSMAgentBridge {
|
|
4
|
+
fsm;
|
|
5
|
+
store;
|
|
6
|
+
constructor(fsm, store) {
|
|
7
|
+
this.fsm = fsm;
|
|
8
|
+
this.store = store;
|
|
9
|
+
}
|
|
10
|
+
async getFSMContext(artifactId) {
|
|
11
|
+
const artifact = await this.store.get(artifactId);
|
|
12
|
+
if (!artifact)
|
|
13
|
+
return null;
|
|
14
|
+
const fsmDef = this.fsm.getDefinition(artifact.type);
|
|
15
|
+
if (!fsmDef)
|
|
16
|
+
return null;
|
|
17
|
+
// 计算允许的迁移
|
|
18
|
+
const availableActions = await this.fsm.availableActions(artifactId);
|
|
19
|
+
// 计算阻塞原因
|
|
20
|
+
const blockingReasons = [];
|
|
21
|
+
// 找出从当前状态出发的所有迁移
|
|
22
|
+
const transitionsFromCurrent = fsmDef.transitions.filter(t => t.from === artifact.status);
|
|
23
|
+
for (const tx of transitionsFromCurrent) {
|
|
24
|
+
const result = await this.fsm.canTransition(artifactId, tx.action);
|
|
25
|
+
if (!result.allowed && result.blockedBy) {
|
|
26
|
+
blockingReasons.push(`${tx.action}: ${result.blockedBy.map(g => g.message).join(', ')}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// 下游影响
|
|
30
|
+
const downstreamImpact = await this.calculateDownstreamImpact(artifact);
|
|
31
|
+
// 父子状态
|
|
32
|
+
const parentStatus = artifact.parents.length > 0
|
|
33
|
+
? (await this.store.get(artifact.parents[0]))?.status
|
|
34
|
+
: undefined;
|
|
35
|
+
const childrenStatuses = (await this.store.findChildren(artifactId))
|
|
36
|
+
.map(c => c.status);
|
|
37
|
+
return {
|
|
38
|
+
artifactId,
|
|
39
|
+
artifactType: artifact.type,
|
|
40
|
+
currentStatus: artifact.status,
|
|
41
|
+
allowedTransitions: availableActions,
|
|
42
|
+
blockingReasons,
|
|
43
|
+
downstreamImpact,
|
|
44
|
+
parentStatus,
|
|
45
|
+
childrenStatuses,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async checkOperation(artifactId, operation) {
|
|
49
|
+
const artifact = await this.store.get(artifactId);
|
|
50
|
+
if (!artifact)
|
|
51
|
+
return { allowed: false, reasons: ['Artifact not found'] };
|
|
52
|
+
const fsmDef = this.fsm.getDefinition(artifact.type);
|
|
53
|
+
if (!fsmDef)
|
|
54
|
+
return { allowed: false, reasons: ['No FSM definition for this artifact type'] };
|
|
55
|
+
// 检查是否是合法迁移
|
|
56
|
+
const transitionsFromCurrent = fsmDef.transitions.filter(t => t.from === artifact.status);
|
|
57
|
+
const transition = transitionsFromCurrent.find(t => t.action === operation);
|
|
58
|
+
if (!transition) {
|
|
59
|
+
const allowed = transitionsFromCurrent.map(t => t.action).join(', ') || 'none';
|
|
60
|
+
return {
|
|
61
|
+
allowed: false,
|
|
62
|
+
reasons: [`"${operation}" is not a valid transition from ${artifact.status}. Allowed: ${allowed}`]
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// 检查 Guards
|
|
66
|
+
const result = await this.fsm.canTransition(artifactId, operation);
|
|
67
|
+
if (!result.allowed && result.blockedBy) {
|
|
68
|
+
return { allowed: false, reasons: result.blockedBy.map(g => g.message) };
|
|
69
|
+
}
|
|
70
|
+
return { allowed: true, reasons: [] };
|
|
71
|
+
}
|
|
72
|
+
async getCreationPrerequisites(artifactType) {
|
|
73
|
+
// 基于 FSM 定义判断创建条件
|
|
74
|
+
const fsmDef = this.fsm.getDefinition(artifactType);
|
|
75
|
+
if (!fsmDef)
|
|
76
|
+
return { requiredParentStatus: [], message: 'No FSM definition available' };
|
|
77
|
+
// 从 FSM 定义中提取依赖关系(简化实现)
|
|
78
|
+
const deps = {
|
|
79
|
+
Plan: { parentType: 'Spec', parentStatus: 'FROZEN' },
|
|
80
|
+
Task: { parentType: 'Plan', parentStatus: 'APPROVED' },
|
|
81
|
+
Change: { parentType: 'Task', parentStatus: 'IN_PROGRESS' },
|
|
82
|
+
Evidence: { parentType: 'Task', parentStatus: 'DONE' },
|
|
83
|
+
};
|
|
84
|
+
const dep = deps[artifactType];
|
|
85
|
+
if (dep) {
|
|
86
|
+
return {
|
|
87
|
+
requiredParentStatus: [`${dep.parentType} must be in ${dep.parentStatus} status`],
|
|
88
|
+
message: `Creating ${artifactType} requires parent ${dep.parentType} to be ${dep.parentStatus}`,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return { requiredParentStatus: [], message: 'No special prerequisites' };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get FSM context for all artifacts related to a session
|
|
95
|
+
* This is the primary method for SessionStart hook to inject context
|
|
96
|
+
*/
|
|
97
|
+
async getSessionContext(sessionId, eventBus) {
|
|
98
|
+
// Find all artifacts related to this session
|
|
99
|
+
const events = await eventBus.query({
|
|
100
|
+
sessionId,
|
|
101
|
+
types: ['artifact.created', 'artifact.transitioned'],
|
|
102
|
+
limit: 50,
|
|
103
|
+
});
|
|
104
|
+
const artifactIds = new Set();
|
|
105
|
+
for (const event of events) {
|
|
106
|
+
if (event.artifactId)
|
|
107
|
+
artifactIds.add(event.artifactId);
|
|
108
|
+
}
|
|
109
|
+
// Get FSM snapshots for each artifact
|
|
110
|
+
const snapshots = await Promise.all(Array.from(artifactIds).map(id => this.getFSMContext(id)));
|
|
111
|
+
const validSnapshots = snapshots.filter(Boolean);
|
|
112
|
+
// Generate recommendations based on FSM state
|
|
113
|
+
const recommendations = this.generateRecommendations(validSnapshots);
|
|
114
|
+
return {
|
|
115
|
+
sessionId,
|
|
116
|
+
artifacts: validSnapshots,
|
|
117
|
+
recalledLessons: [], // Will be filled by context inject command
|
|
118
|
+
recommendations,
|
|
119
|
+
generatedAt: Date.now(),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Generate actionable recommendations from FSM state
|
|
124
|
+
*/
|
|
125
|
+
generateRecommendations(snapshots) {
|
|
126
|
+
const recs = [];
|
|
127
|
+
for (const s of snapshots) {
|
|
128
|
+
// Spec needs to be frozen before implementation
|
|
129
|
+
if (s.artifactType === 'Spec' && s.currentStatus === 'REVIEWING') {
|
|
130
|
+
if (s.allowedTransitions.includes('freeze')) {
|
|
131
|
+
recs.push(`Spec ${s.artifactId} is ready to freeze — execute 'scale transition ${s.artifactId} freeze'`);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
recs.push(`Spec ${s.artifactId} blocked from freezing: ${s.blockingReasons.join('; ')}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Plan needs approval before implementation
|
|
138
|
+
if (s.artifactType === 'Plan' && s.currentStatus === 'DRAFT') {
|
|
139
|
+
recs.push(`Plan ${s.artifactId} needs review before implementation`);
|
|
140
|
+
}
|
|
141
|
+
// Task ready to start
|
|
142
|
+
if (s.artifactType === 'Task' && s.currentStatus === 'READY') {
|
|
143
|
+
recs.push(`Task ${s.artifactId} is ready to implement`);
|
|
144
|
+
}
|
|
145
|
+
// Warning for blocked artifacts
|
|
146
|
+
if (s.blockingReasons.length > 0 && s.allowedTransitions.length === 0) {
|
|
147
|
+
recs.push(`⚠️ ${s.artifactId} (${s.artifactType}) is blocked in ${s.currentStatus}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return recs;
|
|
151
|
+
}
|
|
152
|
+
async injectFSMContextToPrompt(prompt, artifactIds) {
|
|
153
|
+
if (artifactIds.length === 0)
|
|
154
|
+
return prompt;
|
|
155
|
+
const snapshots = await Promise.all(artifactIds.map(id => this.getFSMContext(id)));
|
|
156
|
+
const validSnapshots = snapshots.filter(Boolean);
|
|
157
|
+
if (validSnapshots.length === 0)
|
|
158
|
+
return prompt;
|
|
159
|
+
const fsmBlock = this.formatFSMBlock(validSnapshots);
|
|
160
|
+
// 插入到 prompt 的合适位置
|
|
161
|
+
const insertPoints = ['<context_summary>', '## Task', '## Context', '## 上下文'];
|
|
162
|
+
for (const point of insertPoints) {
|
|
163
|
+
if (prompt.includes(point)) {
|
|
164
|
+
return prompt.replace(point, fsmBlock + '\n' + point);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// 如果找不到合适位置,添加到末尾
|
|
168
|
+
return prompt + '\n' + fsmBlock;
|
|
169
|
+
}
|
|
170
|
+
async calculateDownstreamImpact(artifact) {
|
|
171
|
+
const children = await this.store.findChildren(artifact.id);
|
|
172
|
+
return children.map(c => `${c.id} (${c.type}:${c.status})`);
|
|
173
|
+
}
|
|
174
|
+
formatFSMBlock(snapshots) {
|
|
175
|
+
const lines = snapshots.map(s => {
|
|
176
|
+
const allowed = s.allowedTransitions.length > 0 ? s.allowedTransitions.join(', ') : 'none';
|
|
177
|
+
const blocked = s.blockingReasons.length > 0 ? s.blockingReasons.slice(0, 3).join('; ') : 'none';
|
|
178
|
+
const impact = s.downstreamImpact.length > 0 ? `${s.downstreamImpact.length} children` : 'none';
|
|
179
|
+
return `### ${s.artifactId} (${s.artifactType})
|
|
180
|
+
- Status: **${s.currentStatus}**
|
|
181
|
+
- Allowed actions: ${allowed}
|
|
182
|
+
- Blocked: ${blocked}
|
|
183
|
+
- Downstream impact: ${impact}
|
|
184
|
+
- Parent: ${s.parentStatus ?? 'none'}
|
|
185
|
+
- Children: ${s.childrenStatuses.length > 0 ? s.childrenStatuses.join(', ') : 'none'}`;
|
|
186
|
+
});
|
|
187
|
+
return `\n## FSM Status Constraints
|
|
188
|
+
|
|
189
|
+
${lines.join('\n\n')}
|
|
190
|
+
|
|
191
|
+
> **Important**: Only execute actions listed in "Allowed actions". Blocked actions require resolving constraints first.
|
|
192
|
+
`;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=FSMAgentBridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FSMAgentBridge.js","sourceRoot":"","sources":["../../src/fsm/FSMAgentBridge.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,uBAAuB;AAkCvB,MAAM,OAAO,cAAc;IAEf;IACA;IAFV,YACU,GAAS,EACT,KAAqB;QADrB,QAAG,GAAH,GAAG,CAAM;QACT,UAAK,GAAL,KAAK,CAAgB;IAC5B,CAAC;IAEJ,KAAK,CAAC,aAAa,CAAC,UAAkB;QACpC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;QACjD,IAAI,CAAC,QAAQ;YAAE,OAAO,IAAI,CAAA;QAE1B,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QACpD,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAA;QAExB,UAAU;QACV,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAA;QAEpE,SAAS;QACT,MAAM,eAAe,GAAa,EAAE,CAAA;QAEpC,iBAAiB;QACjB,MAAM,sBAAsB,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,MAAM,CAAC,CAAA;QAEzF,KAAK,MAAM,EAAE,IAAI,sBAAsB,EAAE,CAAC;YACxC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,UAAU,E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