@mcoda/mswarm 0.1.56 → 0.1.60
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 +20 -1
- package/dist/codali-executor.d.ts +266 -0
- package/dist/codali-executor.d.ts.map +1 -0
- package/dist/codali-executor.js +227 -0
- package/dist/codali-executor.js.map +1 -0
- package/dist/runtime.d.ts +47 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +248 -30
- package/dist/runtime.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +83 -3
- package/dist/server.js.map +1 -1
- package/dist/vendor/codali/agents/AgentProtocol.d.ts +287 -0
- package/dist/vendor/codali/agents/AgentProtocol.d.ts.map +1 -0
- package/dist/vendor/codali/agents/AgentProtocol.js +365 -0
- package/dist/vendor/codali/agents/AgentResolver.d.ts +23 -0
- package/dist/vendor/codali/agents/AgentResolver.d.ts.map +1 -0
- package/dist/vendor/codali/agents/AgentResolver.js +77 -0
- package/dist/vendor/codali/agents/PhaseAgentSelector.d.ts +23 -0
- package/dist/vendor/codali/agents/PhaseAgentSelector.d.ts.map +1 -0
- package/dist/vendor/codali/agents/PhaseAgentSelector.js +287 -0
- package/dist/vendor/codali/cli/EvalCommand.d.ts +37 -0
- package/dist/vendor/codali/cli/EvalCommand.d.ts.map +1 -0
- package/dist/vendor/codali/cli/EvalCommand.js +333 -0
- package/dist/vendor/codali/cli/FeedbackCommand.d.ts +22 -0
- package/dist/vendor/codali/cli/FeedbackCommand.d.ts.map +1 -0
- package/dist/vendor/codali/cli/FeedbackCommand.js +163 -0
- package/dist/vendor/codali/cli/RunCommand.d.ts +78 -0
- package/dist/vendor/codali/cli/RunCommand.d.ts.map +1 -0
- package/dist/vendor/codali/cli/RunCommand.js +2261 -0
- package/dist/vendor/codali/cli.d.ts +3 -0
- package/dist/vendor/codali/cli.d.ts.map +1 -0
- package/dist/vendor/codali/cli.js +109 -0
- package/dist/vendor/codali/cognitive/ArchitectPlanner.d.ts +107 -0
- package/dist/vendor/codali/cognitive/ArchitectPlanner.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ArchitectPlanner.js +1726 -0
- package/dist/vendor/codali/cognitive/BuilderOutputParser.d.ts +25 -0
- package/dist/vendor/codali/cognitive/BuilderOutputParser.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/BuilderOutputParser.js +164 -0
- package/dist/vendor/codali/cognitive/BuilderRunner.d.ts +76 -0
- package/dist/vendor/codali/cognitive/BuilderRunner.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/BuilderRunner.js +1159 -0
- package/dist/vendor/codali/cognitive/ContextAssembler.d.ts +91 -0
- package/dist/vendor/codali/cognitive/ContextAssembler.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextAssembler.js +4547 -0
- package/dist/vendor/codali/cognitive/ContextBudget.d.ts +19 -0
- package/dist/vendor/codali/cognitive/ContextBudget.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextBudget.js +35 -0
- package/dist/vendor/codali/cognitive/ContextFileLoader.d.ts +30 -0
- package/dist/vendor/codali/cognitive/ContextFileLoader.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextFileLoader.js +307 -0
- package/dist/vendor/codali/cognitive/ContextManager.d.ts +47 -0
- package/dist/vendor/codali/cognitive/ContextManager.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextManager.js +272 -0
- package/dist/vendor/codali/cognitive/ContextRedactor.d.ts +18 -0
- package/dist/vendor/codali/cognitive/ContextRedactor.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextRedactor.js +53 -0
- package/dist/vendor/codali/cognitive/ContextSelector.d.ts +22 -0
- package/dist/vendor/codali/cognitive/ContextSelector.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextSelector.js +431 -0
- package/dist/vendor/codali/cognitive/ContextSerializer.d.ts +8 -0
- package/dist/vendor/codali/cognitive/ContextSerializer.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextSerializer.js +882 -0
- package/dist/vendor/codali/cognitive/ContextStore.d.ts +27 -0
- package/dist/vendor/codali/cognitive/ContextStore.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextStore.js +79 -0
- package/dist/vendor/codali/cognitive/ContextSummarizer.d.ts +16 -0
- package/dist/vendor/codali/cognitive/ContextSummarizer.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextSummarizer.js +45 -0
- package/dist/vendor/codali/cognitive/CostEstimator.d.ts +31 -0
- package/dist/vendor/codali/cognitive/CostEstimator.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/CostEstimator.js +66 -0
- package/dist/vendor/codali/cognitive/CriticEvaluator.d.ts +32 -0
- package/dist/vendor/codali/cognitive/CriticEvaluator.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/CriticEvaluator.js +297 -0
- package/dist/vendor/codali/cognitive/EvidenceGate.d.ts +9 -0
- package/dist/vendor/codali/cognitive/EvidenceGate.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/EvidenceGate.js +75 -0
- package/dist/vendor/codali/cognitive/GoldenExampleIndexer.d.ts +12 -0
- package/dist/vendor/codali/cognitive/GoldenExampleIndexer.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/GoldenExampleIndexer.js +34 -0
- package/dist/vendor/codali/cognitive/GoldenSetStore.d.ts +33 -0
- package/dist/vendor/codali/cognitive/GoldenSetStore.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/GoldenSetStore.js +159 -0
- package/dist/vendor/codali/cognitive/IntentSignals.d.ts +7 -0
- package/dist/vendor/codali/cognitive/IntentSignals.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/IntentSignals.js +285 -0
- package/dist/vendor/codali/cognitive/LearningGovernance.d.ts +100 -0
- package/dist/vendor/codali/cognitive/LearningGovernance.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/LearningGovernance.js +276 -0
- package/dist/vendor/codali/cognitive/MemoryWriteback.d.ts +64 -0
- package/dist/vendor/codali/cognitive/MemoryWriteback.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/MemoryWriteback.js +287 -0
- package/dist/vendor/codali/cognitive/PatchApplier.d.ts +49 -0
- package/dist/vendor/codali/cognitive/PatchApplier.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/PatchApplier.js +199 -0
- package/dist/vendor/codali/cognitive/PatchInterpreter.d.ts +35 -0
- package/dist/vendor/codali/cognitive/PatchInterpreter.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/PatchInterpreter.js +100 -0
- package/dist/vendor/codali/cognitive/PatchOutputNormalizer.d.ts +7 -0
- package/dist/vendor/codali/cognitive/PatchOutputNormalizer.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/PatchOutputNormalizer.js +59 -0
- package/dist/vendor/codali/cognitive/PostMortemAnalyzer.d.ts +17 -0
- package/dist/vendor/codali/cognitive/PostMortemAnalyzer.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/PostMortemAnalyzer.js +131 -0
- package/dist/vendor/codali/cognitive/PreferenceExtraction.d.ts +3 -0
- package/dist/vendor/codali/cognitive/PreferenceExtraction.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/PreferenceExtraction.js +85 -0
- package/dist/vendor/codali/cognitive/Prompts.d.ts +15 -0
- package/dist/vendor/codali/cognitive/Prompts.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/Prompts.js +326 -0
- package/dist/vendor/codali/cognitive/ProviderRouting.d.ts +16 -0
- package/dist/vendor/codali/cognitive/ProviderRouting.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ProviderRouting.js +24 -0
- package/dist/vendor/codali/cognitive/QueryExtraction.d.ts +12 -0
- package/dist/vendor/codali/cognitive/QueryExtraction.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/QueryExtraction.js +262 -0
- package/dist/vendor/codali/cognitive/RunHistoryIndexer.d.ts +13 -0
- package/dist/vendor/codali/cognitive/RunHistoryIndexer.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/RunHistoryIndexer.js +125 -0
- package/dist/vendor/codali/cognitive/SmartPipeline.d.ts +92 -0
- package/dist/vendor/codali/cognitive/SmartPipeline.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/SmartPipeline.js +4804 -0
- package/dist/vendor/codali/cognitive/Types.d.ts +474 -0
- package/dist/vendor/codali/cognitive/Types.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/Types.js +7 -0
- package/dist/vendor/codali/cognitive/ValidationRunner.d.ts +57 -0
- package/dist/vendor/codali/cognitive/ValidationRunner.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ValidationRunner.js +515 -0
- package/dist/vendor/codali/config/Config.d.ts +249 -0
- package/dist/vendor/codali/config/Config.d.ts.map +1 -0
- package/dist/vendor/codali/config/Config.js +200 -0
- package/dist/vendor/codali/config/ConfigLoader.d.ts +56 -0
- package/dist/vendor/codali/config/ConfigLoader.d.ts.map +1 -0
- package/dist/vendor/codali/config/ConfigLoader.js +1246 -0
- package/dist/vendor/codali/docdex/DocdexClient.d.ts +113 -0
- package/dist/vendor/codali/docdex/DocdexClient.d.ts.map +1 -0
- package/dist/vendor/codali/docdex/DocdexClient.js +524 -0
- package/dist/vendor/codali/eval/EvalRunner.d.ts +35 -0
- package/dist/vendor/codali/eval/EvalRunner.d.ts.map +1 -0
- package/dist/vendor/codali/eval/EvalRunner.js +38 -0
- package/dist/vendor/codali/eval/EvalTaskExecutor.d.ts +81 -0
- package/dist/vendor/codali/eval/EvalTaskExecutor.d.ts.map +1 -0
- package/dist/vendor/codali/eval/EvalTaskExecutor.js +371 -0
- package/dist/vendor/codali/eval/GateEvaluator.d.ts +31 -0
- package/dist/vendor/codali/eval/GateEvaluator.d.ts.map +1 -0
- package/dist/vendor/codali/eval/GateEvaluator.js +134 -0
- package/dist/vendor/codali/eval/MetricTypes.d.ts +28 -0
- package/dist/vendor/codali/eval/MetricTypes.d.ts.map +1 -0
- package/dist/vendor/codali/eval/MetricTypes.js +1 -0
- package/dist/vendor/codali/eval/MetricsAggregator.d.ts +4 -0
- package/dist/vendor/codali/eval/MetricsAggregator.d.ts.map +1 -0
- package/dist/vendor/codali/eval/MetricsAggregator.js +97 -0
- package/dist/vendor/codali/eval/RegressionComparator.d.ts +29 -0
- package/dist/vendor/codali/eval/RegressionComparator.d.ts.map +1 -0
- package/dist/vendor/codali/eval/RegressionComparator.js +155 -0
- package/dist/vendor/codali/eval/ReportInputAdapter.d.ts +52 -0
- package/dist/vendor/codali/eval/ReportInputAdapter.d.ts.map +1 -0
- package/dist/vendor/codali/eval/ReportInputAdapter.js +229 -0
- package/dist/vendor/codali/eval/ReportSerializer.d.ts +32 -0
- package/dist/vendor/codali/eval/ReportSerializer.d.ts.map +1 -0
- package/dist/vendor/codali/eval/ReportSerializer.js +33 -0
- package/dist/vendor/codali/eval/ReportStore.d.ts +18 -0
- package/dist/vendor/codali/eval/ReportStore.d.ts.map +1 -0
- package/dist/vendor/codali/eval/ReportStore.js +96 -0
- package/dist/vendor/codali/eval/SuiteLoader.d.ts +12 -0
- package/dist/vendor/codali/eval/SuiteLoader.d.ts.map +1 -0
- package/dist/vendor/codali/eval/SuiteLoader.js +51 -0
- package/dist/vendor/codali/eval/SuiteSchema.d.ts +56 -0
- package/dist/vendor/codali/eval/SuiteSchema.d.ts.map +1 -0
- package/dist/vendor/codali/eval/SuiteSchema.js +357 -0
- package/dist/vendor/codali/index.d.ts +11 -0
- package/dist/vendor/codali/index.d.ts.map +1 -0
- package/dist/vendor/codali/index.js +5 -0
- package/dist/vendor/codali/providers/CodexCliProvider.d.ts +8 -0
- package/dist/vendor/codali/providers/CodexCliProvider.d.ts.map +1 -0
- package/dist/vendor/codali/providers/CodexCliProvider.js +282 -0
- package/dist/vendor/codali/providers/OllamaRemoteProvider.d.ts +8 -0
- package/dist/vendor/codali/providers/OllamaRemoteProvider.d.ts.map +1 -0
- package/dist/vendor/codali/providers/OllamaRemoteProvider.js +300 -0
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.d.ts +8 -0
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.d.ts.map +1 -0
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.js +192 -0
- package/dist/vendor/codali/providers/ProviderRegistry.d.ts +12 -0
- package/dist/vendor/codali/providers/ProviderRegistry.d.ts.map +1 -0
- package/dist/vendor/codali/providers/ProviderRegistry.js +28 -0
- package/dist/vendor/codali/providers/ProviderTypes.d.ts +81 -0
- package/dist/vendor/codali/providers/ProviderTypes.d.ts.map +1 -0
- package/dist/vendor/codali/providers/ProviderTypes.js +1 -0
- package/dist/vendor/codali/runtime/CodaliRuntime.d.ts +183 -0
- package/dist/vendor/codali/runtime/CodaliRuntime.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/CodaliRuntime.js +1363 -0
- package/dist/vendor/codali/runtime/DeepInvestigationErrors.d.ts +39 -0
- package/dist/vendor/codali/runtime/DeepInvestigationErrors.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/DeepInvestigationErrors.js +57 -0
- package/dist/vendor/codali/runtime/RunContext.d.ts +27 -0
- package/dist/vendor/codali/runtime/RunContext.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/RunContext.js +51 -0
- package/dist/vendor/codali/runtime/RunLogQuery.d.ts +48 -0
- package/dist/vendor/codali/runtime/RunLogQuery.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/RunLogQuery.js +36 -0
- package/dist/vendor/codali/runtime/RunLogReader.d.ts +19 -0
- package/dist/vendor/codali/runtime/RunLogReader.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/RunLogReader.js +361 -0
- package/dist/vendor/codali/runtime/RunLogger.d.ts +71 -0
- package/dist/vendor/codali/runtime/RunLogger.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/RunLogger.js +100 -0
- package/dist/vendor/codali/runtime/RunTelemetryTypes.d.ts +117 -0
- package/dist/vendor/codali/runtime/RunTelemetryTypes.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/RunTelemetryTypes.js +299 -0
- package/dist/vendor/codali/runtime/Runner.d.ts +66 -0
- package/dist/vendor/codali/runtime/Runner.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/Runner.js +215 -0
- package/dist/vendor/codali/runtime/StoragePaths.d.ts +3 -0
- package/dist/vendor/codali/runtime/StoragePaths.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/StoragePaths.js +19 -0
- package/dist/vendor/codali/runtime/WorkspaceLock.d.ts +30 -0
- package/dist/vendor/codali/runtime/WorkspaceLock.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/WorkspaceLock.js +141 -0
- package/dist/vendor/codali/session/InstructionLoader.d.ts +14 -0
- package/dist/vendor/codali/session/InstructionLoader.d.ts.map +1 -0
- package/dist/vendor/codali/session/InstructionLoader.js +107 -0
- package/dist/vendor/codali/session/SessionStore.d.ts +81 -0
- package/dist/vendor/codali/session/SessionStore.d.ts.map +1 -0
- package/dist/vendor/codali/session/SessionStore.js +244 -0
- package/dist/vendor/codali/subagents/SubagentOrchestrator.d.ts +68 -0
- package/dist/vendor/codali/subagents/SubagentOrchestrator.d.ts.map +1 -0
- package/dist/vendor/codali/subagents/SubagentOrchestrator.js +150 -0
- package/dist/vendor/codali/tools/ToolRegistry.d.ts +9 -0
- package/dist/vendor/codali/tools/ToolRegistry.d.ts.map +1 -0
- package/dist/vendor/codali/tools/ToolRegistry.js +263 -0
- package/dist/vendor/codali/tools/ToolTypes.d.ts +66 -0
- package/dist/vendor/codali/tools/ToolTypes.d.ts.map +1 -0
- package/dist/vendor/codali/tools/ToolTypes.js +32 -0
- package/dist/vendor/codali/tools/diff/DiffTool.d.ts +3 -0
- package/dist/vendor/codali/tools/diff/DiffTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/diff/DiffTool.js +34 -0
- package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts +4 -0
- package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts.map +1 -0
- package/dist/vendor/codali/tools/docdex/DocdexTools.js +453 -0
- package/dist/vendor/codali/tools/filesystem/FileTools.d.ts +3 -0
- package/dist/vendor/codali/tools/filesystem/FileTools.d.ts.map +1 -0
- package/dist/vendor/codali/tools/filesystem/FileTools.js +141 -0
- package/dist/vendor/codali/tools/search/SearchTool.d.ts +3 -0
- package/dist/vendor/codali/tools/search/SearchTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/search/SearchTool.js +46 -0
- package/dist/vendor/codali/tools/shell/ShellTool.d.ts +3 -0
- package/dist/vendor/codali/tools/shell/ShellTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/shell/ShellTool.js +104 -0
- package/package.json +5 -3
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export type LearningRuleLifecycleState = "candidate" | "enforced";
|
|
2
|
+
export type LearningRuleConfidenceBand = "low" | "medium" | "high";
|
|
3
|
+
export type LearningRuleScope = "repo_memory" | "profile_memory";
|
|
4
|
+
export type LearningGovernanceStatus = "accepted" | "deferred" | "rejected";
|
|
5
|
+
export interface LearningEvidenceReference {
|
|
6
|
+
kind: "run" | "artifact" | "file" | "request" | "post_mortem" | "other";
|
|
7
|
+
ref: string;
|
|
8
|
+
note?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface LearningRuleProposal {
|
|
11
|
+
category: string;
|
|
12
|
+
content: string;
|
|
13
|
+
source?: string;
|
|
14
|
+
scope?: LearningRuleScope;
|
|
15
|
+
agent_id?: string;
|
|
16
|
+
lifecycle_state?: LearningRuleLifecycleState;
|
|
17
|
+
confidence_score?: number;
|
|
18
|
+
confidence_band?: LearningRuleConfidenceBand;
|
|
19
|
+
confidence_reasons?: string[];
|
|
20
|
+
evidence?: LearningEvidenceReference[];
|
|
21
|
+
explicit_confirmation?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface LearningGovernancePolicy {
|
|
24
|
+
persistence_min_confidence: number;
|
|
25
|
+
enforcement_min_confidence: number;
|
|
26
|
+
require_confirmation_for_low_confidence: boolean;
|
|
27
|
+
auto_enforce_high_confidence: boolean;
|
|
28
|
+
}
|
|
29
|
+
export declare const DEFAULT_LEARNING_GOVERNANCE_POLICY: LearningGovernancePolicy;
|
|
30
|
+
export interface LearningConfidenceInput {
|
|
31
|
+
source: string;
|
|
32
|
+
content: string;
|
|
33
|
+
explicit: boolean;
|
|
34
|
+
evidence_count: number;
|
|
35
|
+
has_revert_signal: boolean;
|
|
36
|
+
}
|
|
37
|
+
export interface LearningConfidenceScore {
|
|
38
|
+
score: number;
|
|
39
|
+
band: LearningRuleConfidenceBand;
|
|
40
|
+
reasons: string[];
|
|
41
|
+
}
|
|
42
|
+
export interface GovernedLearningRule {
|
|
43
|
+
schema_version: 1;
|
|
44
|
+
id: string;
|
|
45
|
+
dedupe_key: string;
|
|
46
|
+
category: string;
|
|
47
|
+
content: string;
|
|
48
|
+
normalized_content: string;
|
|
49
|
+
source: string;
|
|
50
|
+
scope: LearningRuleScope;
|
|
51
|
+
lifecycle_state: LearningRuleLifecycleState;
|
|
52
|
+
confidence_score: number;
|
|
53
|
+
confidence_band: LearningRuleConfidenceBand;
|
|
54
|
+
confidence_reasons: string[];
|
|
55
|
+
evidence: LearningEvidenceReference[];
|
|
56
|
+
explicit_confirmation: boolean;
|
|
57
|
+
created_at: string;
|
|
58
|
+
updated_at: string;
|
|
59
|
+
agent_id?: string;
|
|
60
|
+
supersedes?: string[];
|
|
61
|
+
}
|
|
62
|
+
export interface LearningRuleDecision {
|
|
63
|
+
status: LearningGovernanceStatus;
|
|
64
|
+
code: string;
|
|
65
|
+
message: string;
|
|
66
|
+
rule: GovernedLearningRule;
|
|
67
|
+
}
|
|
68
|
+
export interface LearningRuleLedgerRecord extends GovernedLearningRule {
|
|
69
|
+
superseded_by?: string;
|
|
70
|
+
superseded_at?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface LearningRuleLedger {
|
|
73
|
+
schema_version: 1;
|
|
74
|
+
rules: LearningRuleLedgerRecord[];
|
|
75
|
+
}
|
|
76
|
+
export interface LedgerMergeResult {
|
|
77
|
+
action: "inserted" | "suppressed" | "superseded";
|
|
78
|
+
rule: LearningRuleLedgerRecord;
|
|
79
|
+
superseded?: LearningRuleLedgerRecord;
|
|
80
|
+
}
|
|
81
|
+
export interface LedgerPromotionResult {
|
|
82
|
+
action: "promoted" | "not_found" | "already_enforced";
|
|
83
|
+
promoted?: LearningRuleLedgerRecord;
|
|
84
|
+
previous?: LearningRuleLedgerRecord;
|
|
85
|
+
}
|
|
86
|
+
export declare class LearningGovernanceError extends Error {
|
|
87
|
+
readonly code: string;
|
|
88
|
+
constructor(code: string, message: string);
|
|
89
|
+
}
|
|
90
|
+
export declare const normalizeLearningCategory: (value: string) => string;
|
|
91
|
+
export declare const normalizeLearningText: (value: string) => string;
|
|
92
|
+
export declare const scoreLearningConfidence: (input: LearningConfidenceInput) => LearningConfidenceScore;
|
|
93
|
+
export declare const buildLearningDedupeKey: (scope: LearningRuleScope, category: string, content: string) => string;
|
|
94
|
+
export declare const governLearningRule: (proposal: LearningRuleProposal, policy?: LearningGovernancePolicy, now?: string) => LearningRuleDecision;
|
|
95
|
+
export declare const createEmptyLearningRuleLedger: () => LearningRuleLedger;
|
|
96
|
+
export declare const mergeLearningRuleIntoLedger: (ledger: LearningRuleLedger, rule: GovernedLearningRule) => LedgerMergeResult;
|
|
97
|
+
export declare const promoteLearningRuleCandidate: (ledger: LearningRuleLedger, dedupeKey: string, policy?: LearningGovernancePolicy, now?: string) => LedgerPromotionResult;
|
|
98
|
+
export declare const readLearningRuleLedger: (filePath: string) => Promise<LearningRuleLedger>;
|
|
99
|
+
export declare const writeLearningRuleLedger: (filePath: string, ledger: LearningRuleLedger) => Promise<void>;
|
|
100
|
+
//# sourceMappingURL=LearningGovernance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LearningGovernance.d.ts","sourceRoot":"","sources":["../../src/cognitive/LearningGovernance.ts"],"names":[],"mappings":"AAGA,MAAM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O,CAAC,IAAI,CAGd,CAAC"}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
export const DEFAULT_LEARNING_GOVERNANCE_POLICY = {
|
|
4
|
+
persistence_min_confidence: 0.45,
|
|
5
|
+
enforcement_min_confidence: 0.85,
|
|
6
|
+
require_confirmation_for_low_confidence: true,
|
|
7
|
+
auto_enforce_high_confidence: true,
|
|
8
|
+
};
|
|
9
|
+
export class LearningGovernanceError extends Error {
|
|
10
|
+
constructor(code, message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "LearningGovernanceError";
|
|
13
|
+
this.code = code;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const clamp01 = (value) => Math.min(1, Math.max(0, value));
|
|
17
|
+
const normalizeWhitespace = (value) => value
|
|
18
|
+
.trim()
|
|
19
|
+
.replace(/\s+/g, " ");
|
|
20
|
+
export const normalizeLearningCategory = (value) => {
|
|
21
|
+
const normalized = normalizeWhitespace(value).toLowerCase();
|
|
22
|
+
if (!normalized) {
|
|
23
|
+
throw new LearningGovernanceError("invalid_category", "Learning rule category is required.");
|
|
24
|
+
}
|
|
25
|
+
if (normalized === "prefer" || normalized === "preference")
|
|
26
|
+
return "preference";
|
|
27
|
+
if (normalized === "constraint" || normalized === "rule" || normalized === "avoid") {
|
|
28
|
+
return "constraint";
|
|
29
|
+
}
|
|
30
|
+
if (normalized === "lesson" || normalized === "failure_lesson")
|
|
31
|
+
return "lesson";
|
|
32
|
+
return normalized;
|
|
33
|
+
};
|
|
34
|
+
export const normalizeLearningText = (value) => {
|
|
35
|
+
const normalized = normalizeWhitespace(value);
|
|
36
|
+
if (!normalized) {
|
|
37
|
+
throw new LearningGovernanceError("invalid_content", "Learning rule content is required.");
|
|
38
|
+
}
|
|
39
|
+
return normalized;
|
|
40
|
+
};
|
|
41
|
+
const canonicalizeLearningText = (value) => normalizeLearningText(value)
|
|
42
|
+
.toLowerCase()
|
|
43
|
+
.replace(/[“”]/g, "\"")
|
|
44
|
+
.replace(/[‘’]/g, "'")
|
|
45
|
+
.replace(/[.,;:!?]+$/g, "");
|
|
46
|
+
const normalizeLearningEvidence = (evidence) => {
|
|
47
|
+
if (!Array.isArray(evidence) || evidence.length === 0)
|
|
48
|
+
return [];
|
|
49
|
+
const map = new Map();
|
|
50
|
+
for (const entry of evidence) {
|
|
51
|
+
if (!entry || typeof entry !== "object")
|
|
52
|
+
continue;
|
|
53
|
+
const kind = normalizeWhitespace(String(entry.kind ?? "")).toLowerCase();
|
|
54
|
+
const ref = normalizeWhitespace(String(entry.ref ?? ""));
|
|
55
|
+
const note = entry.note ? normalizeWhitespace(String(entry.note)) : undefined;
|
|
56
|
+
if (!kind || !ref)
|
|
57
|
+
continue;
|
|
58
|
+
const safeKind = (["run", "artifact", "file", "request", "post_mortem"].includes(kind) ? kind : "other");
|
|
59
|
+
const key = `${safeKind}::${ref}::${note ?? ""}`.toLowerCase();
|
|
60
|
+
if (!map.has(key)) {
|
|
61
|
+
map.set(key, { kind: safeKind, ref, note });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return Array.from(map.values()).sort((left, right) => {
|
|
65
|
+
const leftKey = `${left.kind}:${left.ref}:${left.note ?? ""}`;
|
|
66
|
+
const rightKey = `${right.kind}:${right.ref}:${right.note ?? ""}`;
|
|
67
|
+
return leftKey.localeCompare(rightKey);
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
const resolveScope = (category, scope) => {
|
|
71
|
+
if (scope === "repo_memory" || scope === "profile_memory")
|
|
72
|
+
return scope;
|
|
73
|
+
if (category === "preference" || category === "constraint")
|
|
74
|
+
return "profile_memory";
|
|
75
|
+
return "repo_memory";
|
|
76
|
+
};
|
|
77
|
+
const resolveBand = (score) => {
|
|
78
|
+
if (score >= 0.8)
|
|
79
|
+
return "high";
|
|
80
|
+
if (score >= 0.5)
|
|
81
|
+
return "medium";
|
|
82
|
+
return "low";
|
|
83
|
+
};
|
|
84
|
+
export const scoreLearningConfidence = (input) => {
|
|
85
|
+
let score = 0.2;
|
|
86
|
+
const reasons = [];
|
|
87
|
+
if (input.explicit) {
|
|
88
|
+
score += 0.4;
|
|
89
|
+
reasons.push("explicit_directive");
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
reasons.push("inferred_directive");
|
|
93
|
+
}
|
|
94
|
+
if (input.source.includes("post_mortem")) {
|
|
95
|
+
score += 0.2;
|
|
96
|
+
reasons.push("post_mortem_source");
|
|
97
|
+
}
|
|
98
|
+
else if (input.source.includes("request")) {
|
|
99
|
+
score += 0.15;
|
|
100
|
+
reasons.push("request_source");
|
|
101
|
+
}
|
|
102
|
+
if (input.has_revert_signal) {
|
|
103
|
+
score += 0.15;
|
|
104
|
+
reasons.push("revert_signal");
|
|
105
|
+
}
|
|
106
|
+
if (input.evidence_count > 0) {
|
|
107
|
+
const evidenceBoost = Math.min(0.2, input.evidence_count * 0.05);
|
|
108
|
+
score += evidenceBoost;
|
|
109
|
+
reasons.push(`evidence_count:${input.evidence_count}`);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
reasons.push("no_evidence");
|
|
113
|
+
}
|
|
114
|
+
if (/(?:maybe|might|perhaps|probably|could)\b/i.test(input.content)) {
|
|
115
|
+
score -= 0.2;
|
|
116
|
+
reasons.push("ambiguous_language");
|
|
117
|
+
}
|
|
118
|
+
if (input.content.trim().length < 10) {
|
|
119
|
+
score -= 0.1;
|
|
120
|
+
reasons.push("short_rule_text");
|
|
121
|
+
}
|
|
122
|
+
const normalizedScore = clamp01(score);
|
|
123
|
+
return {
|
|
124
|
+
score: normalizedScore,
|
|
125
|
+
band: resolveBand(normalizedScore),
|
|
126
|
+
reasons,
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
const createRuleId = (dedupeKey, now, lifecycle) => `${dedupeKey}::${lifecycle}::${new Date(now).getTime()}`;
|
|
130
|
+
export const buildLearningDedupeKey = (scope, category, content) => `${scope}::${category}::${canonicalizeLearningText(content)}`;
|
|
131
|
+
export const governLearningRule = (proposal, policy = DEFAULT_LEARNING_GOVERNANCE_POLICY, now = new Date().toISOString()) => {
|
|
132
|
+
const category = normalizeLearningCategory(proposal.category);
|
|
133
|
+
const content = normalizeLearningText(proposal.content);
|
|
134
|
+
const source = normalizeWhitespace(proposal.source ?? "unknown_source").toLowerCase();
|
|
135
|
+
const scope = resolveScope(category, proposal.scope);
|
|
136
|
+
const evidence = normalizeLearningEvidence(proposal.evidence);
|
|
137
|
+
const dedupeKey = buildLearningDedupeKey(scope, category, content);
|
|
138
|
+
const confidence = Number.isFinite(proposal.confidence_score)
|
|
139
|
+
? clamp01(Number(proposal.confidence_score))
|
|
140
|
+
: scoreLearningConfidence({
|
|
141
|
+
source,
|
|
142
|
+
content,
|
|
143
|
+
explicit: source.includes("explicit"),
|
|
144
|
+
evidence_count: evidence.length,
|
|
145
|
+
has_revert_signal: source.includes("post_mortem"),
|
|
146
|
+
}).score;
|
|
147
|
+
const confidenceBand = proposal.confidence_band ?? resolveBand(confidence);
|
|
148
|
+
const confidenceReasons = proposal.confidence_reasons?.length
|
|
149
|
+
? proposal.confidence_reasons.map((entry) => normalizeWhitespace(entry)).filter(Boolean)
|
|
150
|
+
: scoreLearningConfidence({
|
|
151
|
+
source,
|
|
152
|
+
content,
|
|
153
|
+
explicit: source.includes("explicit"),
|
|
154
|
+
evidence_count: evidence.length,
|
|
155
|
+
has_revert_signal: source.includes("post_mortem"),
|
|
156
|
+
}).reasons;
|
|
157
|
+
let lifecycleState = "candidate";
|
|
158
|
+
const explicitConfirmation = Boolean(proposal.explicit_confirmation);
|
|
159
|
+
if (explicitConfirmation) {
|
|
160
|
+
lifecycleState = "enforced";
|
|
161
|
+
}
|
|
162
|
+
else if (policy.auto_enforce_high_confidence &&
|
|
163
|
+
confidence >= policy.enforcement_min_confidence &&
|
|
164
|
+
(!policy.require_confirmation_for_low_confidence || confidenceBand !== "low")) {
|
|
165
|
+
lifecycleState = "enforced";
|
|
166
|
+
}
|
|
167
|
+
const rule = {
|
|
168
|
+
schema_version: 1,
|
|
169
|
+
id: createRuleId(dedupeKey, now, lifecycleState),
|
|
170
|
+
dedupe_key: dedupeKey,
|
|
171
|
+
category,
|
|
172
|
+
content,
|
|
173
|
+
normalized_content: canonicalizeLearningText(content),
|
|
174
|
+
source,
|
|
175
|
+
scope,
|
|
176
|
+
lifecycle_state: lifecycleState,
|
|
177
|
+
confidence_score: confidence,
|
|
178
|
+
confidence_band: confidenceBand,
|
|
179
|
+
confidence_reasons: confidenceReasons,
|
|
180
|
+
evidence,
|
|
181
|
+
explicit_confirmation: explicitConfirmation,
|
|
182
|
+
created_at: now,
|
|
183
|
+
updated_at: now,
|
|
184
|
+
agent_id: proposal.agent_id,
|
|
185
|
+
};
|
|
186
|
+
if (confidence < policy.persistence_min_confidence) {
|
|
187
|
+
return {
|
|
188
|
+
status: "deferred",
|
|
189
|
+
code: "confidence_below_persistence_threshold",
|
|
190
|
+
message: "Rule confidence is below persistence threshold.",
|
|
191
|
+
rule,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
status: "accepted",
|
|
196
|
+
code: lifecycleState === "enforced" ? "accepted_enforced" : "accepted_candidate",
|
|
197
|
+
message: lifecycleState === "enforced"
|
|
198
|
+
? "Rule accepted as enforced."
|
|
199
|
+
: "Rule accepted as candidate.",
|
|
200
|
+
rule,
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
export const createEmptyLearningRuleLedger = () => ({
|
|
204
|
+
schema_version: 1,
|
|
205
|
+
rules: [],
|
|
206
|
+
});
|
|
207
|
+
const toLedgerRecord = (rule) => ({ ...rule });
|
|
208
|
+
const isActive = (entry) => !entry.superseded_by;
|
|
209
|
+
export const mergeLearningRuleIntoLedger = (ledger, rule) => {
|
|
210
|
+
const existing = ledger.rules.find((entry) => isActive(entry) && entry.dedupe_key === rule.dedupe_key);
|
|
211
|
+
if (!existing) {
|
|
212
|
+
const inserted = toLedgerRecord(rule);
|
|
213
|
+
ledger.rules.push(inserted);
|
|
214
|
+
return { action: "inserted", rule: inserted };
|
|
215
|
+
}
|
|
216
|
+
const shouldPromote = existing.lifecycle_state !== "enforced" && rule.lifecycle_state === "enforced";
|
|
217
|
+
const confidenceDelta = rule.confidence_score - existing.confidence_score;
|
|
218
|
+
const shouldReplaceByConfidence = existing.lifecycle_state === rule.lifecycle_state &&
|
|
219
|
+
(confidenceDelta > 0.05 || rule.normalized_content !== existing.normalized_content);
|
|
220
|
+
if (!shouldPromote && !shouldReplaceByConfidence) {
|
|
221
|
+
return { action: "suppressed", rule: existing };
|
|
222
|
+
}
|
|
223
|
+
const supersededAt = rule.updated_at;
|
|
224
|
+
existing.superseded_by = rule.id;
|
|
225
|
+
existing.superseded_at = supersededAt;
|
|
226
|
+
const inserted = toLedgerRecord({
|
|
227
|
+
...rule,
|
|
228
|
+
supersedes: [...(rule.supersedes ?? []), existing.id],
|
|
229
|
+
});
|
|
230
|
+
ledger.rules.push(inserted);
|
|
231
|
+
return { action: "superseded", rule: inserted, superseded: existing };
|
|
232
|
+
};
|
|
233
|
+
export const promoteLearningRuleCandidate = (ledger, dedupeKey, policy = DEFAULT_LEARNING_GOVERNANCE_POLICY, now = new Date().toISOString()) => {
|
|
234
|
+
const active = ledger.rules.find((entry) => isActive(entry) && entry.dedupe_key === dedupeKey);
|
|
235
|
+
if (!active)
|
|
236
|
+
return { action: "not_found" };
|
|
237
|
+
if (active.lifecycle_state === "enforced") {
|
|
238
|
+
return { action: "already_enforced", previous: active };
|
|
239
|
+
}
|
|
240
|
+
const promoted = {
|
|
241
|
+
...active,
|
|
242
|
+
id: createRuleId(active.dedupe_key, now, "enforced"),
|
|
243
|
+
lifecycle_state: "enforced",
|
|
244
|
+
confidence_score: Math.max(active.confidence_score, policy.enforcement_min_confidence),
|
|
245
|
+
confidence_band: resolveBand(Math.max(active.confidence_score, policy.enforcement_min_confidence)),
|
|
246
|
+
explicit_confirmation: true,
|
|
247
|
+
updated_at: now,
|
|
248
|
+
supersedes: [...(active.supersedes ?? []), active.id],
|
|
249
|
+
};
|
|
250
|
+
active.superseded_by = promoted.id;
|
|
251
|
+
active.superseded_at = now;
|
|
252
|
+
ledger.rules.push(promoted);
|
|
253
|
+
return { action: "promoted", promoted, previous: active };
|
|
254
|
+
};
|
|
255
|
+
export const readLearningRuleLedger = async (filePath) => {
|
|
256
|
+
try {
|
|
257
|
+
const content = await readFile(filePath, "utf8");
|
|
258
|
+
if (!content.trim())
|
|
259
|
+
return createEmptyLearningRuleLedger();
|
|
260
|
+
const parsed = JSON.parse(content);
|
|
261
|
+
if (parsed.schema_version !== 1 || !Array.isArray(parsed.rules)) {
|
|
262
|
+
return createEmptyLearningRuleLedger();
|
|
263
|
+
}
|
|
264
|
+
return {
|
|
265
|
+
schema_version: 1,
|
|
266
|
+
rules: parsed.rules.filter((entry) => Boolean(entry && typeof entry === "object" && typeof entry.id === "string")),
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
return createEmptyLearningRuleLedger();
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
export const writeLearningRuleLedger = async (filePath, ledger) => {
|
|
274
|
+
await mkdir(path.dirname(filePath), { recursive: true });
|
|
275
|
+
await writeFile(filePath, `${JSON.stringify(ledger, null, 2)}\n`, "utf8");
|
|
276
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { LearningConfig } from "../config/Config.js";
|
|
2
|
+
import type { DocdexClient } from "../docdex/DocdexClient.js";
|
|
3
|
+
import type { RunLogger } from "../runtime/RunLogger.js";
|
|
4
|
+
import { type LearningEvidenceReference, type LearningRuleProposal, type LearningRuleScope } from "./LearningGovernance.js";
|
|
5
|
+
export interface PreferenceWriteback {
|
|
6
|
+
category: string;
|
|
7
|
+
content: string;
|
|
8
|
+
agentId?: string;
|
|
9
|
+
source?: string;
|
|
10
|
+
scope?: LearningRuleScope;
|
|
11
|
+
confidence_score?: number;
|
|
12
|
+
confidence_band?: "low" | "medium" | "high";
|
|
13
|
+
confidence_reasons?: string[];
|
|
14
|
+
evidence?: LearningEvidenceReference[];
|
|
15
|
+
explicit_confirmation?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface RulePromotionRequest {
|
|
18
|
+
dedupe_key: string;
|
|
19
|
+
agentId?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface MemoryWritebackInput {
|
|
22
|
+
failures: number;
|
|
23
|
+
maxRetries: number;
|
|
24
|
+
lesson: string;
|
|
25
|
+
preferences?: PreferenceWriteback[];
|
|
26
|
+
rules?: LearningRuleProposal[];
|
|
27
|
+
promotions?: RulePromotionRequest[];
|
|
28
|
+
}
|
|
29
|
+
export interface MemoryWritebackOptions {
|
|
30
|
+
agentId?: string;
|
|
31
|
+
workspaceRoot?: string;
|
|
32
|
+
learning?: Partial<LearningConfig>;
|
|
33
|
+
logger?: RunLogger;
|
|
34
|
+
}
|
|
35
|
+
export interface LearningWriteOutcome {
|
|
36
|
+
status: "accepted" | "deferred" | "suppressed" | "rejected" | "promoted";
|
|
37
|
+
code: string;
|
|
38
|
+
message: string;
|
|
39
|
+
rule_id?: string;
|
|
40
|
+
dedupe_key?: string;
|
|
41
|
+
scope?: LearningRuleScope;
|
|
42
|
+
lifecycle_state?: "candidate" | "enforced";
|
|
43
|
+
confidence_score?: number;
|
|
44
|
+
confidence_band?: "low" | "medium" | "high";
|
|
45
|
+
target?: "repo_memory" | "profile_memory";
|
|
46
|
+
}
|
|
47
|
+
export interface MemoryWritebackResult {
|
|
48
|
+
outcomes: LearningWriteOutcome[];
|
|
49
|
+
ledgerPath: string;
|
|
50
|
+
}
|
|
51
|
+
export declare class MemoryWriteback {
|
|
52
|
+
private client;
|
|
53
|
+
private agentId;
|
|
54
|
+
private workspaceRoot;
|
|
55
|
+
private ledgerPath;
|
|
56
|
+
private logger?;
|
|
57
|
+
private policy;
|
|
58
|
+
constructor(client: DocdexClient, options?: MemoryWritebackOptions);
|
|
59
|
+
private logOutcome;
|
|
60
|
+
private toLegacyProposals;
|
|
61
|
+
private persistRuleToDocdex;
|
|
62
|
+
persist(input: MemoryWritebackInput): Promise<MemoryWritebackResult>;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=MemoryWriteback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryWriteback.d.ts","sourceRoot":"","sources":["../../src/cognitive/MemoryWriteback.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAOL,KAAK,yBAAyB,EAC9B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACvB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC5C,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,QAAQ,CAAC,EAAE,yBAAyB,EAAE,CAAC;IACvC,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,MA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