@dommaker/harness 1.1.1 → 1.2.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/CHANGELOG.md +17 -0
- package/README.md +2 -4
- package/bin/harness.js +12 -37
- package/dist/cli/commands/check.d.ts +2 -2
- package/dist/cli/commands/check.d.ts.map +1 -1
- package/dist/cli/commands/check.js +8 -33
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/cli/commands/constraints-report.js +1 -1
- package/dist/cli/commands/constraints-report.js.map +1 -1
- package/dist/cli/commands/constraints-retire.d.ts +6 -3
- package/dist/cli/commands/constraints-retire.d.ts.map +1 -1
- package/dist/cli/commands/constraints-retire.js +34 -25
- package/dist/cli/commands/constraints-retire.js.map +1 -1
- package/dist/cli/commands/definitions.d.ts +2 -0
- package/dist/cli/commands/definitions.d.ts.map +1 -1
- package/dist/cli/commands/definitions.js.map +1 -1
- package/dist/cli/commands/init.d.ts +21 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +118 -40
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/knowledge.d.ts.map +1 -1
- package/dist/cli/commands/knowledge.js +1 -12
- package/dist/cli/commands/knowledge.js.map +1 -1
- package/dist/cli/commands/report.d.ts.map +1 -1
- package/dist/cli/commands/report.js +0 -2
- package/dist/cli/commands/report.js.map +1 -1
- package/dist/cli/commands/status.js +2 -2
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/context/index.d.ts +9 -6
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +18 -20
- package/dist/context/index.js.map +1 -1
- package/dist/core/constraints/capabilities-parser.d.ts +3 -2
- package/dist/core/constraints/capabilities-parser.d.ts.map +1 -1
- package/dist/core/constraints/capabilities-parser.js +25 -47
- package/dist/core/constraints/capabilities-parser.js.map +1 -1
- package/dist/core/constraints/checker.d.ts +29 -32
- package/dist/core/constraints/checker.d.ts.map +1 -1
- package/dist/core/constraints/checker.js +34 -126
- package/dist/core/constraints/checker.js.map +1 -1
- package/dist/core/constraints/checkers/governance-presence.d.ts +20 -0
- package/dist/core/constraints/checkers/governance-presence.d.ts.map +1 -0
- package/dist/core/constraints/checkers/governance-presence.js +76 -0
- package/dist/core/constraints/checkers/governance-presence.js.map +1 -0
- package/dist/core/constraints/checkers/index.d.ts +2 -1
- package/dist/core/constraints/checkers/index.d.ts.map +1 -1
- package/dist/core/constraints/checkers/index.js +5 -0
- package/dist/core/constraints/checkers/index.js.map +1 -1
- package/dist/core/constraints/checkers/types.d.ts +25 -0
- package/dist/core/constraints/checkers/types.d.ts.map +1 -1
- package/dist/core/constraints/checkers/types.js +24 -0
- package/dist/core/constraints/checkers/types.js.map +1 -1
- package/dist/core/constraints/definitions/guidelines.d.ts.map +1 -1
- package/dist/core/constraints/definitions/guidelines.js +21 -2
- package/dist/core/constraints/definitions/guidelines.js.map +1 -1
- package/dist/core/constraints/definitions/prompts.d.ts.map +1 -1
- package/dist/core/constraints/definitions/prompts.js +0 -5
- package/dist/core/constraints/definitions/prompts.js.map +1 -1
- package/dist/core/constraints/index.d.ts +1 -2
- package/dist/core/constraints/index.d.ts.map +1 -1
- package/dist/core/constraints/index.js +1 -7
- package/dist/core/constraints/index.js.map +1 -1
- package/dist/core/constraints/injection-drift.d.ts +29 -4
- package/dist/core/constraints/injection-drift.d.ts.map +1 -1
- package/dist/core/constraints/injection-drift.js +52 -20
- package/dist/core/constraints/injection-drift.js.map +1 -1
- package/dist/core/constraints/usage-report.d.ts +1 -2
- package/dist/core/constraints/usage-report.d.ts.map +1 -1
- package/dist/core/constraints/usage-report.js +2 -5
- package/dist/core/constraints/usage-report.js.map +1 -1
- package/dist/core/effective-constraints.d.ts +24 -4
- package/dist/core/effective-constraints.d.ts.map +1 -1
- package/dist/core/effective-constraints.js +28 -7
- package/dist/core/effective-constraints.js.map +1 -1
- package/dist/core/effective-set.d.ts +30 -0
- package/dist/core/effective-set.d.ts.map +1 -0
- package/dist/core/effective-set.js +35 -0
- package/dist/core/effective-set.js.map +1 -0
- package/dist/core/index.d.ts +13 -6
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +44 -21
- package/dist/core/index.js.map +1 -1
- package/dist/core/project-config-loader.d.ts +3 -6
- package/dist/core/project-config-loader.d.ts.map +1 -1
- package/dist/core/project-config-loader.js +47 -61
- package/dist/core/project-config-loader.js.map +1 -1
- package/dist/failure/constraint-handler.d.ts +1 -1
- package/dist/failure/constraint-handler.js +1 -1
- package/dist/gates/checker-gate.d.ts +1 -4
- package/dist/gates/checker-gate.d.ts.map +1 -1
- package/dist/gates/checker-gate.js +3 -11
- package/dist/gates/checker-gate.js.map +1 -1
- package/dist/gates/definitions.d.ts +9 -38
- package/dist/gates/definitions.d.ts.map +1 -1
- package/dist/gates/definitions.js +24 -13
- package/dist/gates/definitions.js.map +1 -1
- package/dist/gates/effective-gates.d.ts.map +1 -1
- package/dist/gates/effective-gates.js +14 -18
- package/dist/gates/effective-gates.js.map +1 -1
- package/dist/gates/index.d.ts +1 -1
- package/dist/gates/index.d.ts.map +1 -1
- package/dist/gates/index.js.map +1 -1
- package/dist/hooks/bootstrap.d.ts.map +1 -1
- package/dist/hooks/bootstrap.js +0 -3
- package/dist/hooks/bootstrap.js.map +1 -1
- package/dist/index.d.ts +43 -60
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +180 -143
- package/dist/index.js.map +1 -1
- package/dist/knowledge/query.d.ts +15 -0
- package/dist/knowledge/query.d.ts.map +1 -1
- package/dist/knowledge/query.js +23 -0
- package/dist/knowledge/query.js.map +1 -1
- package/dist/monitoring/analyzer-base.d.ts +0 -4
- package/dist/monitoring/analyzer-base.d.ts.map +1 -1
- package/dist/monitoring/analyzer-base.js +0 -21
- package/dist/monitoring/analyzer-base.js.map +1 -1
- package/dist/monitoring/index.d.ts +6 -12
- package/dist/monitoring/index.d.ts.map +1 -1
- package/dist/monitoring/index.js +13 -29
- package/dist/monitoring/index.js.map +1 -1
- package/dist/monitoring/trace-analyzer.d.ts.map +1 -1
- package/dist/monitoring/trace-analyzer.js +2 -68
- package/dist/monitoring/trace-analyzer.js.map +1 -1
- package/dist/monitoring/traces.d.ts +0 -4
- package/dist/monitoring/traces.d.ts.map +1 -1
- package/dist/monitoring/traces.js +0 -14
- package/dist/monitoring/traces.js.map +1 -1
- package/dist/presets/index.d.ts +2 -2
- package/dist/presets/index.d.ts.map +1 -1
- package/dist/presets/index.js +3 -4
- package/dist/presets/index.js.map +1 -1
- package/dist/presets/standard.d.ts +10 -22
- package/dist/presets/standard.d.ts.map +1 -1
- package/dist/presets/standard.js +15 -75
- package/dist/presets/standard.js.map +1 -1
- package/dist/types/constraint.d.ts +1 -29
- package/dist/types/constraint.d.ts.map +1 -1
- package/dist/types/constraint.js +1 -1
- package/dist/types/constraint.js.map +1 -1
- package/dist/types/index.d.ts +0 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +0 -4
- package/dist/types/index.js.map +1 -1
- package/dist/types/project-config.d.ts +4 -8
- package/dist/types/project-config.d.ts.map +1 -1
- package/dist/types/trace.d.ts +5 -18
- package/dist/types/trace.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/CONTEXT.md +4 -5
- package/src/__tests__/checker-extra.test.ts +33 -139
- package/src/__tests__/checker.test.ts +0 -376
- package/src/__tests__/governance-presence.test.ts +129 -0
- package/src/__tests__/iron-laws.test.ts +7 -7
- package/src/__tests__/project-config-loader-extra.test.ts +42 -29
- package/src/__tests__/public-exports.test.ts +138 -0
- package/src/__tests__/trace-analyzer-extra.test.ts +6 -86
- package/src/__tests__/trace-analyzer.test.ts +4 -5
- package/src/__tests__/trace-collector.test.ts +0 -11
- package/src/__tests__/traces.test.ts +3 -22
- package/src/cli/commands/CONTEXT.md +6 -3
- package/src/cli/commands/__tests__/check-skip-output.test.ts +10 -7
- package/src/cli/commands/__tests__/check.test.ts +29 -69
- package/src/cli/commands/__tests__/constraints-report.test.ts +3 -3
- package/src/cli/commands/__tests__/constraints-retire.test.ts +45 -4
- package/src/cli/commands/__tests__/init-injection.test.ts +202 -0
- package/src/cli/commands/__tests__/knowledge.test.ts +90 -1
- package/src/cli/commands/__tests__/registry.test.ts +8 -6
- package/src/cli/commands/__tests__/status-extra.test.ts +6 -6
- package/src/cli/commands/__tests__/status.test.ts +6 -6
- package/src/cli/commands/__tests__/sync-docs-agents.test.ts +28 -0
- package/src/cli/commands/check.ts +9 -35
- package/src/cli/commands/constraints-report.ts +1 -1
- package/src/cli/commands/constraints-retire.ts +38 -27
- package/src/cli/commands/definitions.ts +2 -0
- package/src/cli/commands/init.ts +129 -40
- package/src/cli/commands/knowledge.ts +1 -16
- package/src/cli/commands/report.ts +0 -2
- package/src/cli/commands/status.ts +2 -2
- package/src/context/index.ts +29 -6
- package/src/core/CONTEXT.md +4 -3
- package/src/core/__tests__/effective-set.test.ts +80 -0
- package/src/core/constraints/__tests__/injection-drift.test.ts +90 -0
- package/src/core/constraints/capabilities-parser.ts +43 -49
- package/src/core/constraints/checker.ts +51 -145
- package/src/core/constraints/checkers/governance-presence.ts +74 -0
- package/src/core/constraints/checkers/index.ts +4 -1
- package/src/core/constraints/checkers/types.ts +42 -0
- package/src/core/constraints/definitions/guidelines.ts +22 -2
- package/src/core/constraints/definitions/prompts.ts +0 -5
- package/src/core/constraints/index.ts +2 -17
- package/src/core/constraints/injection-drift.ts +60 -21
- package/src/core/constraints/usage-report.ts +5 -8
- package/src/core/effective-constraints.ts +35 -7
- package/src/core/effective-set.ts +56 -0
- package/src/core/index.ts +80 -6
- package/src/core/project-config-loader.ts +53 -68
- package/src/failure/CONTEXT.md +1 -1
- package/src/failure/constraint-handler.ts +1 -1
- package/src/gates/CONTEXT.md +3 -3
- package/src/gates/checker-gate.ts +4 -12
- package/src/gates/definitions.ts +27 -50
- package/src/gates/effective-gates.ts +14 -21
- package/src/gates/index.ts +1 -1
- package/src/hooks/bootstrap.ts +0 -3
- package/src/index.ts +384 -148
- package/src/knowledge/CONTEXT.md +2 -2
- package/src/knowledge/__tests__/query.test.ts +64 -0
- package/src/knowledge/query.ts +28 -0
- package/src/monitoring/CONTEXT.md +7 -13
- package/src/monitoring/__tests__/traces.test.ts +0 -10
- package/src/monitoring/analyzer-base.ts +0 -22
- package/src/monitoring/index.ts +6 -12
- package/src/monitoring/trace-analyzer.ts +2 -73
- package/src/monitoring/traces.ts +0 -20
- package/src/presets/__tests__/standard.test.ts +48 -69
- package/src/presets/index.ts +3 -5
- package/src/presets/standard.ts +14 -79
- package/src/spec/CONTEXT.md +5 -13
- package/src/types/constraint.ts +1 -51
- package/src/types/index.ts +0 -12
- package/src/types/project-config.ts +4 -10
- package/src/types/trace.ts +5 -30
- package/dist/core/constraints/interceptor.d.ts +0 -39
- package/dist/core/constraints/interceptor.d.ts.map +0 -1
- package/dist/core/constraints/interceptor.js +0 -166
- package/dist/core/constraints/interceptor.js.map +0 -1
- package/dist/dashboard/data.d.ts +0 -31
- package/dist/dashboard/data.d.ts.map +0 -1
- package/dist/dashboard/data.js +0 -81
- package/dist/dashboard/data.js.map +0 -1
- package/dist/dashboard/index.d.ts +0 -4
- package/dist/dashboard/index.d.ts.map +0 -1
- package/dist/dashboard/index.js +0 -20
- package/dist/dashboard/index.js.map +0 -1
- package/dist/dashboard/stats.d.ts +0 -20
- package/dist/dashboard/stats.d.ts.map +0 -1
- package/dist/dashboard/stats.js +0 -115
- package/dist/dashboard/stats.js.map +0 -1
- package/dist/dashboard/types.d.ts +0 -110
- package/dist/dashboard/types.d.ts.map +0 -1
- package/dist/dashboard/types.js +0 -8
- package/dist/dashboard/types.js.map +0 -1
- package/dist/monitoring/constraint-doctor.d.ts +0 -76
- package/dist/monitoring/constraint-doctor.d.ts.map +0 -1
- package/dist/monitoring/constraint-doctor.js +0 -189
- package/dist/monitoring/constraint-doctor.js.map +0 -1
- package/dist/monitoring/diagnosis-rules.d.ts +0 -18
- package/dist/monitoring/diagnosis-rules.d.ts.map +0 -1
- package/dist/monitoring/diagnosis-rules.js +0 -119
- package/dist/monitoring/diagnosis-rules.js.map +0 -1
- package/dist/monitoring/knowledge-doctor.d.ts +0 -78
- package/dist/monitoring/knowledge-doctor.d.ts.map +0 -1
- package/dist/monitoring/knowledge-doctor.js +0 -266
- package/dist/monitoring/knowledge-doctor.js.map +0 -1
- package/dist/monitoring/knowledge-evolver.d.ts +0 -72
- package/dist/monitoring/knowledge-evolver.d.ts.map +0 -1
- package/dist/monitoring/knowledge-evolver.js +0 -205
- package/dist/monitoring/knowledge-evolver.js.map +0 -1
- package/dist/monitoring/performance-analyzer.d.ts +0 -92
- package/dist/monitoring/performance-analyzer.d.ts.map +0 -1
- package/dist/monitoring/performance-analyzer.js +0 -343
- package/dist/monitoring/performance-analyzer.js.map +0 -1
- package/dist/monitoring/performance-collector.d.ts +0 -103
- package/dist/monitoring/performance-collector.d.ts.map +0 -1
- package/dist/monitoring/performance-collector.js +0 -298
- package/dist/monitoring/performance-collector.js.map +0 -1
- package/dist/safety/index.d.ts +0 -6
- package/dist/safety/index.d.ts.map +0 -1
- package/dist/safety/index.js +0 -22
- package/dist/safety/index.js.map +0 -1
- package/dist/safety/input-guardrail.d.ts +0 -36
- package/dist/safety/input-guardrail.d.ts.map +0 -1
- package/dist/safety/input-guardrail.js +0 -118
- package/dist/safety/input-guardrail.js.map +0 -1
- package/dist/safety/output-guardrail.d.ts +0 -39
- package/dist/safety/output-guardrail.d.ts.map +0 -1
- package/dist/safety/output-guardrail.js +0 -147
- package/dist/safety/output-guardrail.js.map +0 -1
- package/dist/safety/sandbox.d.ts +0 -45
- package/dist/safety/sandbox.d.ts.map +0 -1
- package/dist/safety/sandbox.js +0 -134
- package/dist/safety/sandbox.js.map +0 -1
- package/dist/safety/tool-guardrail.d.ts +0 -51
- package/dist/safety/tool-guardrail.d.ts.map +0 -1
- package/dist/safety/tool-guardrail.js +0 -147
- package/dist/safety/tool-guardrail.js.map +0 -1
- package/dist/safety/types.d.ts +0 -104
- package/dist/safety/types.d.ts.map +0 -1
- package/dist/safety/types.js +0 -6
- package/dist/safety/types.js.map +0 -1
- package/dist/spec/annotation-checker.d.ts +0 -47
- package/dist/spec/annotation-checker.d.ts.map +0 -1
- package/dist/spec/annotation-checker.js +0 -279
- package/dist/spec/annotation-checker.js.map +0 -1
- package/dist/types/enforcement.d.ts +0 -42
- package/dist/types/enforcement.d.ts.map +0 -1
- package/dist/types/enforcement.js +0 -6
- package/dist/types/enforcement.js.map +0 -1
- package/dist/types/monitoring-types.d.ts +0 -53
- package/dist/types/monitoring-types.d.ts.map +0 -1
- package/dist/types/monitoring-types.js +0 -10
- package/dist/types/monitoring-types.js.map +0 -1
- package/dist/types/performance.d.ts +0 -204
- package/dist/types/performance.d.ts.map +0 -1
- package/dist/types/performance.js +0 -12
- package/dist/types/performance.js.map +0 -1
- package/dist/verification/index.d.ts +0 -4
- package/dist/verification/index.d.ts.map +0 -1
- package/dist/verification/index.js +0 -20
- package/dist/verification/index.js.map +0 -1
- package/dist/verification/loop.d.ts +0 -30
- package/dist/verification/loop.d.ts.map +0 -1
- package/dist/verification/loop.js +0 -114
- package/dist/verification/loop.js.map +0 -1
- package/dist/verification/rules-based.d.ts +0 -40
- package/dist/verification/rules-based.d.ts.map +0 -1
- package/dist/verification/rules-based.js +0 -130
- package/dist/verification/rules-based.js.map +0 -1
- package/dist/verification/types.d.ts +0 -69
- package/dist/verification/types.d.ts.map +0 -1
- package/dist/verification/types.js +0 -6
- package/dist/verification/types.js.map +0 -1
- package/src/__tests__/annotation-checker.test.ts +0 -183
- package/src/__tests__/constraint-doctor.test.ts +0 -271
- package/src/__tests__/doctor-extra.test.ts +0 -155
- package/src/__tests__/extend-exceptions.test.ts +0 -149
- package/src/__tests__/interceptor.test.ts +0 -89
- package/src/__tests__/performance-analyzer.test.ts +0 -499
- package/src/__tests__/performance-collector.test.ts +0 -276
- package/src/__tests__/presets.test.ts +0 -65
- package/src/core/constraints/__tests__/interceptor.test.ts +0 -267
- package/src/core/constraints/interceptor.ts +0 -217
- package/src/dashboard/CONTEXT.md +0 -21
- package/src/dashboard/__tests__/data.test.ts +0 -111
- package/src/dashboard/__tests__/stats.test.ts +0 -159
- package/src/dashboard/data.ts +0 -103
- package/src/dashboard/index.ts +0 -3
- package/src/dashboard/stats.ts +0 -127
- package/src/dashboard/types.ts +0 -130
- package/src/monitoring/__tests__/knowledge-doctor.test.ts +0 -278
- package/src/monitoring/__tests__/knowledge-evolver.test.ts +0 -368
- package/src/monitoring/__tests__/performance-analyzer.test.ts +0 -137
- package/src/monitoring/__tests__/performance-collector.test.ts +0 -331
- package/src/monitoring/constraint-doctor.ts +0 -228
- package/src/monitoring/diagnosis-rules.ts +0 -132
- package/src/monitoring/knowledge-doctor.ts +0 -322
- package/src/monitoring/knowledge-evolver.ts +0 -289
- package/src/monitoring/performance-analyzer.ts +0 -400
- package/src/monitoring/performance-collector.ts +0 -326
- package/src/safety/CONTEXT.md +0 -23
- package/src/safety/__tests__/input-guardrail.test.ts +0 -105
- package/src/safety/__tests__/output-guardrail.test.ts +0 -108
- package/src/safety/__tests__/sandbox.test.ts +0 -158
- package/src/safety/__tests__/tool-guardrail.test.ts +0 -127
- package/src/safety/index.ts +0 -5
- package/src/safety/input-guardrail.ts +0 -133
- package/src/safety/output-guardrail.ts +0 -170
- package/src/safety/sandbox.ts +0 -148
- package/src/safety/tool-guardrail.ts +0 -176
- package/src/safety/types.ts +0 -124
- package/src/spec/__tests__/annotation-checker.test.ts +0 -294
- package/src/spec/annotation-checker.ts +0 -320
- package/src/types/enforcement.ts +0 -48
- package/src/types/monitoring-types.ts +0 -68
- package/src/types/performance.ts +0 -295
- package/src/verification/CONTEXT.md +0 -23
- package/src/verification/__tests__/loop.test.ts +0 -303
- package/src/verification/__tests__/rules-based.test.ts +0 -240
- package/src/verification/index.ts +0 -3
- package/src/verification/loop.ts +0 -137
- package/src/verification/rules-based.ts +0 -152
- package/src/verification/types.ts +0 -81
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 知识库健康诊断
|
|
3
|
-
*
|
|
4
|
-
* 从 ConstraintDoctor 转型,聚焦知识库健康:
|
|
5
|
-
* - 孤儿条目检测
|
|
6
|
-
* - 矛盾检测
|
|
7
|
-
* - 过时检测
|
|
8
|
-
* - 成熟度异常
|
|
9
|
-
* - 引用健康度
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import type { KnowledgeEntry, LintIssue } from '../knowledge/types';
|
|
13
|
-
|
|
14
|
-
// ── 诊断类型 ─────────────────────────────────────────────
|
|
15
|
-
|
|
16
|
-
export type DiagnosisSeverity = 'low' | 'medium' | 'high' | 'critical';
|
|
17
|
-
|
|
18
|
-
export interface KnowledgeDiagnosis {
|
|
19
|
-
id: string;
|
|
20
|
-
type: 'orphan' | 'contradiction' | 'outdated' | 'decay' | 'low_reference' | 'stale_index';
|
|
21
|
-
severity: DiagnosisSeverity;
|
|
22
|
-
entryId?: string;
|
|
23
|
-
title: string;
|
|
24
|
-
description: string;
|
|
25
|
-
rootCause: string;
|
|
26
|
-
impact: string;
|
|
27
|
-
recommendations: string[];
|
|
28
|
-
timestamp: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface DiagnosisReport {
|
|
32
|
-
timestamp: string;
|
|
33
|
-
totalEntries: number;
|
|
34
|
-
healthScore: number; // 0-100
|
|
35
|
-
diagnoses: KnowledgeDiagnosis[];
|
|
36
|
-
summary: Record<DiagnosisSeverity, number>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// ── 配置 ─────────────────────────────────────────────────
|
|
40
|
-
|
|
41
|
-
export interface KnowledgeDoctorConfig {
|
|
42
|
-
/** 低引用阈值(低于此值标记为 low_reference) */
|
|
43
|
-
lowReferenceThreshold?: number;
|
|
44
|
-
/** 过时天数(超过此天数未引用标记为 outdated) */
|
|
45
|
-
outdatedDays?: number;
|
|
46
|
-
/** 衰减预警天数 */
|
|
47
|
-
decayWarningDays?: number;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const DEFAULT_CONFIG: Required<KnowledgeDoctorConfig> = {
|
|
51
|
-
lowReferenceThreshold: 2,
|
|
52
|
-
outdatedDays: 180,
|
|
53
|
-
decayWarningDays: 90,
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// ── 知识库诊断器 ─────────────────────────────────────────
|
|
57
|
-
|
|
58
|
-
export class KnowledgeDoctor {
|
|
59
|
-
private config: Required<KnowledgeDoctorConfig>;
|
|
60
|
-
|
|
61
|
-
constructor(config?: KnowledgeDoctorConfig) {
|
|
62
|
-
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* 诊断知识库健康
|
|
67
|
-
*/
|
|
68
|
-
diagnose(entries: KnowledgeEntry[], lintIssues: LintIssue[] = []): DiagnosisReport {
|
|
69
|
-
const diagnoses: KnowledgeDiagnosis[] = [];
|
|
70
|
-
|
|
71
|
-
// 从 lint issues 转换
|
|
72
|
-
diagnoses.push(...this.fromLintIssues(lintIssues));
|
|
73
|
-
|
|
74
|
-
// 知识库特有诊断
|
|
75
|
-
diagnoses.push(...this.checkOrphans(entries));
|
|
76
|
-
diagnoses.push(...this.checkOutdated(entries));
|
|
77
|
-
diagnoses.push(...this.checkDecay(entries));
|
|
78
|
-
diagnoses.push(...this.checkLowReference(entries));
|
|
79
|
-
|
|
80
|
-
// 计算健康分数
|
|
81
|
-
const healthScore = this.calculateHealthScore(entries, diagnoses);
|
|
82
|
-
|
|
83
|
-
// 统计
|
|
84
|
-
const summary: Record<DiagnosisSeverity, number> = {
|
|
85
|
-
low: 0,
|
|
86
|
-
medium: 0,
|
|
87
|
-
high: 0,
|
|
88
|
-
critical: 0,
|
|
89
|
-
};
|
|
90
|
-
for (const d of diagnoses) {
|
|
91
|
-
summary[d.severity]++;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
timestamp: new Date().toISOString(),
|
|
96
|
-
totalEntries: entries.length,
|
|
97
|
-
healthScore,
|
|
98
|
-
diagnoses,
|
|
99
|
-
summary,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* 从 Lint issues 生成诊断
|
|
105
|
-
*/
|
|
106
|
-
private fromLintIssues(issues: LintIssue[]): KnowledgeDiagnosis[] {
|
|
107
|
-
return issues.map(issue => ({
|
|
108
|
-
id: `lint-${issue.type}-${issue.entryId ?? 'unknown'}`,
|
|
109
|
-
type: issue.type as KnowledgeDiagnosis['type'],
|
|
110
|
-
severity: issue.severity,
|
|
111
|
-
entryId: issue.entryId,
|
|
112
|
-
title: issue.description,
|
|
113
|
-
description: issue.description,
|
|
114
|
-
rootCause: this.inferRootCause(issue),
|
|
115
|
-
impact: this.inferImpact(issue),
|
|
116
|
-
recommendations: [issue.suggestion],
|
|
117
|
-
timestamp: new Date().toISOString(),
|
|
118
|
-
}));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* 检查孤儿条目
|
|
123
|
-
*/
|
|
124
|
-
private checkOrphans(entries: KnowledgeEntry[]): KnowledgeDiagnosis[] {
|
|
125
|
-
const diagnoses: KnowledgeDiagnosis[] = [];
|
|
126
|
-
|
|
127
|
-
for (const entry of entries) {
|
|
128
|
-
if (entry.maturity === 'archived') continue;
|
|
129
|
-
|
|
130
|
-
const hasRefs = entry.referencedBy.length > 0;
|
|
131
|
-
const hasContributors = entry.contributors.length > 0;
|
|
132
|
-
const hasProjects = entry.projects.length > 0;
|
|
133
|
-
|
|
134
|
-
if (!hasRefs && !hasContributors && !hasProjects && entry.maturity === 'draft') {
|
|
135
|
-
diagnoses.push({
|
|
136
|
-
id: `orphan-${entry.id}`,
|
|
137
|
-
type: 'orphan',
|
|
138
|
-
severity: 'low',
|
|
139
|
-
entryId: entry.id,
|
|
140
|
-
title: `孤儿条目: ${entry.title}`,
|
|
141
|
-
description: `条目 ${entry.id} 无引用、无贡献者、无项目验证`,
|
|
142
|
-
rootCause: '条目可能是自动生成但未被任何工作流引用',
|
|
143
|
-
impact: '占用知识库空间但不产生价值',
|
|
144
|
-
recommendations: ['归档该条目', '或标记为需要验证后等待引用'],
|
|
145
|
-
timestamp: new Date().toISOString(),
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return diagnoses;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* 检查过时条目
|
|
155
|
-
*/
|
|
156
|
-
private checkOutdated(entries: KnowledgeEntry[]): KnowledgeDiagnosis[] {
|
|
157
|
-
const diagnoses: KnowledgeDiagnosis[] = [];
|
|
158
|
-
const threshold = new Date();
|
|
159
|
-
threshold.setDate(threshold.getDate() - this.config.outdatedDays);
|
|
160
|
-
|
|
161
|
-
for (const entry of entries) {
|
|
162
|
-
if (entry.maturity === 'archived') continue;
|
|
163
|
-
if (entry.maturity !== 'draft') continue;
|
|
164
|
-
|
|
165
|
-
const lastRef = entry.lastReferenced ? new Date(entry.lastReferenced) : new Date(entry.created);
|
|
166
|
-
if (lastRef < threshold) {
|
|
167
|
-
diagnoses.push({
|
|
168
|
-
id: `outdated-${entry.id}`,
|
|
169
|
-
type: 'outdated',
|
|
170
|
-
severity: 'medium',
|
|
171
|
-
entryId: entry.id,
|
|
172
|
-
title: `过时条目: ${entry.title}`,
|
|
173
|
-
description: `条目 ${entry.id} 超过 ${this.config.outdatedDays} 天未引用且为 draft`,
|
|
174
|
-
rootCause: '长期未被引用,可能已失去相关性',
|
|
175
|
-
impact: '降低知识库整体质量',
|
|
176
|
-
recommendations: ['归档该条目', '或验证后提升成熟度'],
|
|
177
|
-
timestamp: new Date().toISOString(),
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return diagnoses;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* 检查衰减预警
|
|
187
|
-
*/
|
|
188
|
-
private checkDecay(entries: KnowledgeEntry[]): KnowledgeDiagnosis[] {
|
|
189
|
-
const diagnoses: KnowledgeDiagnosis[] = [];
|
|
190
|
-
const warningThreshold = new Date();
|
|
191
|
-
warningThreshold.setDate(warningThreshold.getDate() - this.config.decayWarningDays);
|
|
192
|
-
|
|
193
|
-
for (const entry of entries) {
|
|
194
|
-
if (entry.maturity !== 'proven' && entry.maturity !== 'verified') continue;
|
|
195
|
-
|
|
196
|
-
const lastRef = entry.lastReferenced ? new Date(entry.lastReferenced) : new Date(entry.created);
|
|
197
|
-
if (lastRef < warningThreshold) {
|
|
198
|
-
diagnoses.push({
|
|
199
|
-
id: `decay-${entry.id}`,
|
|
200
|
-
type: 'decay',
|
|
201
|
-
severity: entry.maturity === 'proven' ? 'high' : 'medium',
|
|
202
|
-
entryId: entry.id,
|
|
203
|
-
title: `衰减预警: ${entry.title}`,
|
|
204
|
-
description: `${entry.maturity} 条目 ${entry.id} 超过 ${this.config.decayWarningDays} 天未引用`,
|
|
205
|
-
rootCause: '长期未被引用,成熟度可能需要降级',
|
|
206
|
-
impact: '高成熟度条目未被引用,可能已过时',
|
|
207
|
-
recommendations: ['检查条目是否仍然相关', '如已过时则降级成熟度'],
|
|
208
|
-
timestamp: new Date().toISOString(),
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return diagnoses;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* 检查低引用条目
|
|
218
|
-
*/
|
|
219
|
-
private checkLowReference(entries: KnowledgeEntry[]): KnowledgeDiagnosis[] {
|
|
220
|
-
const diagnoses: KnowledgeDiagnosis[] = [];
|
|
221
|
-
|
|
222
|
-
for (const entry of entries) {
|
|
223
|
-
if (entry.maturity === 'archived') continue;
|
|
224
|
-
if (entry.maturity === 'draft') continue;
|
|
225
|
-
|
|
226
|
-
if (entry.referencedBy.length < this.config.lowReferenceThreshold) {
|
|
227
|
-
diagnoses.push({
|
|
228
|
-
id: `low-ref-${entry.id}`,
|
|
229
|
-
type: 'low_reference',
|
|
230
|
-
severity: 'low',
|
|
231
|
-
entryId: entry.id,
|
|
232
|
-
title: `低引用: ${entry.title}`,
|
|
233
|
-
description: `${entry.maturity} 条目 ${entry.id} 仅被引用 ${entry.referencedBy.length} 次`,
|
|
234
|
-
rootCause: '条目可能不够通用或不易被发现',
|
|
235
|
-
impact: '高成熟度但低引用,投入产出比低',
|
|
236
|
-
recommendations: ['检查条目是否需要更新以提高相关性', '考虑在更多场景中引用'],
|
|
237
|
-
timestamp: new Date().toISOString(),
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return diagnoses;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* 计算健康分数(0-100)
|
|
247
|
-
*/
|
|
248
|
-
private calculateHealthScore(entries: KnowledgeEntry[], diagnoses: KnowledgeDiagnosis[]): number {
|
|
249
|
-
if (entries.length === 0) return 100;
|
|
250
|
-
|
|
251
|
-
let penalty = 0;
|
|
252
|
-
for (const d of diagnoses) {
|
|
253
|
-
switch (d.severity) {
|
|
254
|
-
case 'critical': penalty += 10; break;
|
|
255
|
-
case 'high': penalty += 5; break;
|
|
256
|
-
case 'medium': penalty += 2; break;
|
|
257
|
-
case 'low': penalty += 1; break;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// 每个条目的最大扣分
|
|
262
|
-
const maxPenalty = entries.length * 10;
|
|
263
|
-
const score = Math.max(0, 100 - Math.round((penalty / Math.max(maxPenalty, 1)) * 100));
|
|
264
|
-
return score;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
private inferRootCause(issue: LintIssue): string {
|
|
268
|
-
switch (issue.type) {
|
|
269
|
-
case 'orphan': return '条目未被任何工作流或项目引用';
|
|
270
|
-
case 'contradiction': return '同标签下存在成熟度差异大的条目';
|
|
271
|
-
case 'outdated': return '长期未引用的 draft 条目';
|
|
272
|
-
case 'duplicate': return '同类型同标题的重复条目';
|
|
273
|
-
case 'index_inconsistent': return '索引与磁盘文件不一致';
|
|
274
|
-
default: return '未知原因';
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
private inferImpact(issue: LintIssue): string {
|
|
279
|
-
switch (issue.type) {
|
|
280
|
-
case 'orphan': return '占用空间但不产生价值';
|
|
281
|
-
case 'contradiction': return '可能误导 Agent 决策';
|
|
282
|
-
case 'outdated': return '降低知识库整体质量';
|
|
283
|
-
case 'duplicate': return '浪费查询预算';
|
|
284
|
-
case 'index_inconsistent': return '可能导致查询失败';
|
|
285
|
-
default: return '未知影响';
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* 生成诊断报告(Markdown)
|
|
291
|
-
*/
|
|
292
|
-
generateReport(report: DiagnosisReport): string {
|
|
293
|
-
const lines: string[] = [];
|
|
294
|
-
|
|
295
|
-
lines.push(`# 知识库健康报告`);
|
|
296
|
-
lines.push(`时间: ${report.timestamp}`);
|
|
297
|
-
lines.push(`条目总数: ${report.totalEntries}`);
|
|
298
|
-
lines.push(`健康分数: ${report.healthScore}/100`);
|
|
299
|
-
lines.push('');
|
|
300
|
-
|
|
301
|
-
lines.push(`## 问题统计`);
|
|
302
|
-
lines.push(`- 严重: ${report.summary.critical}`);
|
|
303
|
-
lines.push(`- 高: ${report.summary.high}`);
|
|
304
|
-
lines.push(`- 中: ${report.summary.medium}`);
|
|
305
|
-
lines.push(`- 低: ${report.summary.low}`);
|
|
306
|
-
lines.push('');
|
|
307
|
-
|
|
308
|
-
if (report.diagnoses.length > 0) {
|
|
309
|
-
lines.push(`## 诊断详情`);
|
|
310
|
-
for (const d of report.diagnoses) {
|
|
311
|
-
lines.push(`### [${d.severity.toUpperCase()}] ${d.title}`);
|
|
312
|
-
lines.push(d.description);
|
|
313
|
-
lines.push(`**根因**: ${d.rootCause}`);
|
|
314
|
-
lines.push(`**影响**: ${d.impact}`);
|
|
315
|
-
lines.push(`**建议**: ${d.recommendations.join(', ')}`);
|
|
316
|
-
lines.push('');
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
return lines.join('\n');
|
|
321
|
-
}
|
|
322
|
-
}
|
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 知识成熟度进化器
|
|
3
|
-
*
|
|
4
|
-
* 聚焦知识成熟度进化:
|
|
5
|
-
* - 基于引用数据提议成熟度变更
|
|
6
|
-
* - 自动审核(安全规则)
|
|
7
|
-
* - 执行变更
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { KnowledgeEntry, MaturityLevel } from '../knowledge/types';
|
|
11
|
-
import type { KnowledgeDiagnosis } from './knowledge-doctor';
|
|
12
|
-
import type { KnowledgeStore } from '../knowledge/store';
|
|
13
|
-
|
|
14
|
-
// ── 进化提案 ─────────────────────────────────────────────
|
|
15
|
-
|
|
16
|
-
export type ProposalAction = 'promote' | 'demote' | 'archive' | 'merge' | 'freeze';
|
|
17
|
-
|
|
18
|
-
export interface EvolutionProposal {
|
|
19
|
-
id: string;
|
|
20
|
-
entryId: string;
|
|
21
|
-
action: ProposalAction;
|
|
22
|
-
currentMaturity: MaturityLevel;
|
|
23
|
-
targetMaturity: MaturityLevel;
|
|
24
|
-
reason: string;
|
|
25
|
-
evidence: string[];
|
|
26
|
-
risk: 'low' | 'medium' | 'high';
|
|
27
|
-
autoApprovable: boolean;
|
|
28
|
-
status: 'pending' | 'approved' | 'rejected' | 'implemented';
|
|
29
|
-
createdAt: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface EvolutionReport {
|
|
33
|
-
timestamp: string;
|
|
34
|
-
proposals: EvolutionProposal[];
|
|
35
|
-
summary: Record<ProposalAction, number>;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// ── 配置 ─────────────────────────────────────────────────
|
|
39
|
-
|
|
40
|
-
export interface KnowledgeEvolverConfig {
|
|
41
|
-
/** 升级所需最小引用次数 */
|
|
42
|
-
promoteThreshold?: number;
|
|
43
|
-
/** 降级触发天数(未引用) */
|
|
44
|
-
demoteDays?: number;
|
|
45
|
-
/** 是否自动执行低风险提案 */
|
|
46
|
-
autoImplement?: boolean;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const DEFAULT_CONFIG: Required<KnowledgeEvolverConfig> = {
|
|
50
|
-
promoteThreshold: 2,
|
|
51
|
-
demoteDays: 180,
|
|
52
|
-
autoImplement: false,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// ── 成熟度进化规则 ───────────────────────────────────────
|
|
56
|
-
|
|
57
|
-
const MATURITY_ORDER: MaturityLevel[] = ['draft', 'verified', 'proven'];
|
|
58
|
-
|
|
59
|
-
function nextMaturity(current: MaturityLevel): MaturityLevel | undefined {
|
|
60
|
-
const idx = MATURITY_ORDER.indexOf(current);
|
|
61
|
-
return idx < MATURITY_ORDER.length - 1 ? MATURITY_ORDER[idx + 1] : undefined;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function prevMaturity(current: MaturityLevel): MaturityLevel | undefined {
|
|
65
|
-
const idx = MATURITY_ORDER.indexOf(current);
|
|
66
|
-
return idx > 0 ? MATURITY_ORDER[idx - 1] : undefined;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// ── 知识进化器 ───────────────────────────────────────────
|
|
70
|
-
|
|
71
|
-
export class KnowledgeEvolver {
|
|
72
|
-
private config: Required<KnowledgeEvolverConfig>;
|
|
73
|
-
private store?: KnowledgeStore;
|
|
74
|
-
|
|
75
|
-
constructor(config?: KnowledgeEvolverConfig, store?: KnowledgeStore) {
|
|
76
|
-
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
77
|
-
this.store = store;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* 从知识条目和诊断生成进化提案
|
|
82
|
-
*/
|
|
83
|
-
generateProposals(
|
|
84
|
-
entries: KnowledgeEntry[],
|
|
85
|
-
diagnoses: KnowledgeDiagnosis[] = [],
|
|
86
|
-
): EvolutionProposal[] {
|
|
87
|
-
const proposals: EvolutionProposal[] = [];
|
|
88
|
-
|
|
89
|
-
for (const entry of entries) {
|
|
90
|
-
if (entry.maturity === 'archived') continue;
|
|
91
|
-
|
|
92
|
-
// 升级检查
|
|
93
|
-
const promoteProposal = this.checkPromote(entry);
|
|
94
|
-
if (promoteProposal) proposals.push(promoteProposal);
|
|
95
|
-
|
|
96
|
-
// 降级检查
|
|
97
|
-
const demoteProposal = this.checkDemote(entry);
|
|
98
|
-
if (demoteProposal) proposals.push(demoteProposal);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// 从诊断生成提案
|
|
102
|
-
for (const diagnosis of diagnoses) {
|
|
103
|
-
if (diagnosis.type === 'contradiction' && diagnosis.entryId) {
|
|
104
|
-
const entry = entries.find(e => e.id === diagnosis.entryId);
|
|
105
|
-
if (entry) {
|
|
106
|
-
proposals.push({
|
|
107
|
-
id: `freeze-${entry.id}-${Date.now()}`,
|
|
108
|
-
entryId: entry.id,
|
|
109
|
-
action: 'freeze',
|
|
110
|
-
currentMaturity: entry.maturity,
|
|
111
|
-
targetMaturity: entry.maturity,
|
|
112
|
-
reason: diagnosis.description,
|
|
113
|
-
evidence: [diagnosis.rootCause],
|
|
114
|
-
risk: 'medium',
|
|
115
|
-
autoApprovable: false,
|
|
116
|
-
status: 'pending',
|
|
117
|
-
createdAt: new Date().toISOString(),
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return proposals;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* 检查是否可以升级
|
|
128
|
-
*/
|
|
129
|
-
private checkPromote(entry: KnowledgeEntry): EvolutionProposal | undefined {
|
|
130
|
-
const target = nextMaturity(entry.maturity);
|
|
131
|
-
if (!target) return undefined;
|
|
132
|
-
|
|
133
|
-
const refCount = entry.referencedBy.length;
|
|
134
|
-
const projectCount = entry.projects.length;
|
|
135
|
-
|
|
136
|
-
// draft → verified: 需要至少 1 次引用
|
|
137
|
-
if (entry.maturity === 'draft' && refCount >= 1) {
|
|
138
|
-
return this.createProposal(entry, 'promote', target,
|
|
139
|
-
`被引用 ${refCount} 次,可以升级为 verified`,
|
|
140
|
-
[`引用次数: ${refCount}`],
|
|
141
|
-
'low',
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// verified → proven: 需要 ≥2 个项目验证
|
|
146
|
-
if (entry.maturity === 'verified' && projectCount >= this.config.promoteThreshold) {
|
|
147
|
-
return this.createProposal(entry, 'promote', target,
|
|
148
|
-
`被 ${projectCount} 个项目验证,可以升级为 proven`,
|
|
149
|
-
[`项目数: ${projectCount}`],
|
|
150
|
-
'low',
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return undefined;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* 检查是否应该降级
|
|
159
|
-
*/
|
|
160
|
-
private checkDemote(entry: KnowledgeEntry): EvolutionProposal | undefined {
|
|
161
|
-
const target = prevMaturity(entry.maturity);
|
|
162
|
-
if (!target) return undefined;
|
|
163
|
-
|
|
164
|
-
const lastRef = entry.lastReferenced
|
|
165
|
-
? new Date(entry.lastReferenced)
|
|
166
|
-
: new Date(entry.created);
|
|
167
|
-
const daysSinceRef = Math.floor(
|
|
168
|
-
(Date.now() - lastRef.getTime()) / (1000 * 60 * 60 * 24),
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
if (daysSinceRef >= this.config.demoteDays) {
|
|
172
|
-
return this.createProposal(entry, 'demote', target,
|
|
173
|
-
`超过 ${this.config.demoteDays} 天未引用,建议降级`,
|
|
174
|
-
[`最后引用: ${daysSinceRef} 天前`],
|
|
175
|
-
'low',
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return undefined;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
private createProposal(
|
|
183
|
-
entry: KnowledgeEntry,
|
|
184
|
-
action: ProposalAction,
|
|
185
|
-
targetMaturity: MaturityLevel,
|
|
186
|
-
reason: string,
|
|
187
|
-
evidence: string[],
|
|
188
|
-
risk: 'low' | 'medium' | 'high',
|
|
189
|
-
): EvolutionProposal {
|
|
190
|
-
return {
|
|
191
|
-
id: `${action}-${entry.id}-${Date.now()}`,
|
|
192
|
-
entryId: entry.id,
|
|
193
|
-
action,
|
|
194
|
-
currentMaturity: entry.maturity,
|
|
195
|
-
targetMaturity,
|
|
196
|
-
reason,
|
|
197
|
-
evidence,
|
|
198
|
-
risk,
|
|
199
|
-
autoApprovable: risk === 'low',
|
|
200
|
-
status: 'pending',
|
|
201
|
-
createdAt: new Date().toISOString(),
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* 审核提案(规则自动审核)
|
|
207
|
-
*/
|
|
208
|
-
review(proposal: EvolutionProposal): { approved: boolean; reason: string } {
|
|
209
|
-
// 安全规则:proven 不允许直接归档
|
|
210
|
-
if (proposal.currentMaturity === 'proven' && proposal.action === 'archive') {
|
|
211
|
-
return { approved: false, reason: 'proven 条目不允许直接归档,需先降级' };
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// 安全规则:矛盾条目不允许升级
|
|
215
|
-
if (proposal.action === 'promote' && proposal.risk === 'high') {
|
|
216
|
-
return { approved: false, reason: '高风险提案需要人工审核' };
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// 低风险自动通过
|
|
220
|
-
if (proposal.risk === 'low' && proposal.autoApprovable) {
|
|
221
|
-
return { approved: true, reason: '低风险提案自动通过' };
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
return { approved: true, reason: '提案通过审核' };
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* 执行提案
|
|
229
|
-
*/
|
|
230
|
-
implement(proposal: EvolutionProposal): boolean {
|
|
231
|
-
if (!this.store) return false;
|
|
232
|
-
if (proposal.status !== 'approved') return false;
|
|
233
|
-
|
|
234
|
-
const entry = this.store.get(proposal.entryId);
|
|
235
|
-
if (!entry) return false;
|
|
236
|
-
|
|
237
|
-
switch (proposal.action) {
|
|
238
|
-
case 'promote':
|
|
239
|
-
case 'demote':
|
|
240
|
-
this.store.update(proposal.entryId, { maturity: proposal.targetMaturity });
|
|
241
|
-
break;
|
|
242
|
-
case 'archive':
|
|
243
|
-
this.store.update(proposal.entryId, { maturity: 'archived' as MaturityLevel });
|
|
244
|
-
break;
|
|
245
|
-
case 'freeze':
|
|
246
|
-
// 冻结:不修改成熟度,只标记
|
|
247
|
-
break;
|
|
248
|
-
default:
|
|
249
|
-
return false;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
proposal.status = 'implemented';
|
|
253
|
-
return true;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* 批量审核 + 执行
|
|
258
|
-
*/
|
|
259
|
-
processProposals(proposals: EvolutionProposal[]): EvolutionReport {
|
|
260
|
-
for (const proposal of proposals) {
|
|
261
|
-
const review = this.review(proposal);
|
|
262
|
-
if (review.approved) {
|
|
263
|
-
proposal.status = 'approved';
|
|
264
|
-
if (this.config.autoImplement && proposal.autoApprovable) {
|
|
265
|
-
this.implement(proposal);
|
|
266
|
-
}
|
|
267
|
-
} else {
|
|
268
|
-
proposal.status = 'rejected';
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
const summary: Record<ProposalAction, number> = {
|
|
273
|
-
promote: 0,
|
|
274
|
-
demote: 0,
|
|
275
|
-
archive: 0,
|
|
276
|
-
merge: 0,
|
|
277
|
-
freeze: 0,
|
|
278
|
-
};
|
|
279
|
-
for (const p of proposals) {
|
|
280
|
-
summary[p.action]++;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
return {
|
|
284
|
-
timestamp: new Date().toISOString(),
|
|
285
|
-
proposals,
|
|
286
|
-
summary,
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
}
|