@dommaker/harness 0.16.9 → 0.17.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 +39 -0
- package/README.md +33 -32
- package/bin/harness.js +33 -20
- package/dist/cli/commands/check.d.ts +3 -2
- package/dist/cli/commands/check.d.ts.map +1 -1
- package/dist/cli/commands/check.js +69 -36
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/cli/commands/constraints-report.d.ts +42 -0
- package/dist/cli/commands/constraints-report.d.ts.map +1 -0
- package/dist/cli/commands/constraints-report.js +233 -0
- package/dist/cli/commands/constraints-report.js.map +1 -0
- package/dist/cli/commands/constraints-retire.d.ts +71 -0
- package/dist/cli/commands/constraints-retire.d.ts.map +1 -0
- package/dist/cli/commands/constraints-retire.js +384 -0
- package/dist/cli/commands/constraints-retire.js.map +1 -0
- package/dist/cli/commands/constraints.d.ts +1 -1
- package/dist/cli/commands/constraints.d.ts.map +1 -1
- package/dist/cli/commands/constraints.js +4 -4
- package/dist/cli/commands/constraints.js.map +1 -1
- package/dist/cli/commands/index.d.ts +2 -1
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +10 -4
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/init.d.ts +20 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +81 -59
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/report.js +4 -4
- package/dist/cli/commands/report.js.map +1 -1
- package/dist/cli/commands/status.d.ts.map +1 -1
- package/dist/cli/commands/status.js +3 -4
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts +5 -1
- package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/capabilities-syncer.js +2 -10
- package/dist/cli/commands/sync-docs/capabilities-syncer.js.map +1 -1
- package/dist/cli/commands/validate.d.ts.map +1 -1
- package/dist/cli/commands/validate.js +1 -5
- package/dist/cli/commands/validate.js.map +1 -1
- package/dist/core/constraints/capabilities-parser.d.ts +7 -0
- package/dist/core/constraints/capabilities-parser.d.ts.map +1 -1
- package/dist/core/constraints/capabilities-parser.js +13 -0
- package/dist/core/constraints/capabilities-parser.js.map +1 -1
- package/dist/core/constraints/checker.d.ts +13 -5
- package/dist/core/constraints/checker.d.ts.map +1 -1
- package/dist/core/constraints/checker.js +62 -25
- package/dist/core/constraints/checker.js.map +1 -1
- package/dist/core/constraints/checkers/capability-sync.d.ts +9 -2
- package/dist/core/constraints/checkers/capability-sync.d.ts.map +1 -1
- package/dist/core/constraints/checkers/capability-sync.js +55 -22
- package/dist/core/constraints/checkers/capability-sync.js.map +1 -1
- package/dist/core/constraints/checkers/context-doc-sync.d.ts +3 -0
- package/dist/core/constraints/checkers/context-doc-sync.d.ts.map +1 -1
- package/dist/core/constraints/checkers/context-doc-sync.js +8 -2
- package/dist/core/constraints/checkers/context-doc-sync.js.map +1 -1
- package/dist/core/constraints/checkers/docs-freshness.d.ts +1 -0
- package/dist/core/constraints/checkers/docs-freshness.d.ts.map +1 -1
- package/dist/core/constraints/checkers/docs-freshness.js +39 -0
- package/dist/core/constraints/checkers/docs-freshness.js.map +1 -1
- package/dist/core/constraints/checkers/index.d.ts +8 -4
- package/dist/core/constraints/checkers/index.d.ts.map +1 -1
- package/dist/core/constraints/checkers/index.js +29 -46
- package/dist/core/constraints/checkers/index.js.map +1 -1
- package/dist/core/constraints/checkers/iron-flags.d.ts +6 -7
- package/dist/core/constraints/checkers/iron-flags.d.ts.map +1 -1
- package/dist/core/constraints/checkers/iron-flags.js +10 -17
- package/dist/core/constraints/checkers/iron-flags.js.map +1 -1
- package/dist/core/constraints/checkers/no-hardcoded-credentials.d.ts +13 -0
- package/dist/core/constraints/checkers/no-hardcoded-credentials.d.ts.map +1 -0
- package/dist/core/constraints/checkers/no-hardcoded-credentials.js +91 -0
- package/dist/core/constraints/checkers/no-hardcoded-credentials.js.map +1 -0
- package/dist/core/constraints/checkers/types.d.ts +15 -4
- package/dist/core/constraints/checkers/types.d.ts.map +1 -1
- package/dist/core/constraints/checkers/types.js +16 -4
- package/dist/core/constraints/checkers/types.js.map +1 -1
- package/dist/core/constraints/context-builder.d.ts +6 -3
- package/dist/core/constraints/context-builder.d.ts.map +1 -1
- package/dist/core/constraints/context-builder.js +29 -20
- package/dist/core/constraints/context-builder.js.map +1 -1
- package/dist/core/constraints/definitions/guidelines.d.ts +6 -2
- package/dist/core/constraints/definitions/guidelines.d.ts.map +1 -1
- package/dist/core/constraints/definitions/guidelines.js +29 -572
- package/dist/core/constraints/definitions/guidelines.js.map +1 -1
- package/dist/core/constraints/definitions/iron-laws.d.ts +6 -2
- package/dist/core/constraints/definitions/iron-laws.d.ts.map +1 -1
- package/dist/core/constraints/definitions/iron-laws.js +48 -231
- package/dist/core/constraints/definitions/iron-laws.js.map +1 -1
- package/dist/core/constraints/definitions/prompts.d.ts +12 -0
- package/dist/core/constraints/definitions/prompts.d.ts.map +1 -0
- package/dist/core/constraints/definitions/prompts.js +405 -0
- package/dist/core/constraints/definitions/prompts.js.map +1 -0
- package/dist/core/constraints/definitions.d.ts +15 -9
- package/dist/core/constraints/definitions.d.ts.map +1 -1
- package/dist/core/constraints/definitions.js +18 -12
- package/dist/core/constraints/definitions.js.map +1 -1
- package/dist/core/constraints/index.d.ts +3 -2
- package/dist/core/constraints/index.d.ts.map +1 -1
- package/dist/core/constraints/index.js +8 -2
- package/dist/core/constraints/index.js.map +1 -1
- package/dist/core/constraints/injection-drift.d.ts +48 -0
- package/dist/core/constraints/injection-drift.d.ts.map +1 -0
- package/dist/core/constraints/injection-drift.js +140 -0
- package/dist/core/constraints/injection-drift.js.map +1 -0
- package/dist/core/constraints/injection-renderer.d.ts +23 -0
- package/dist/core/constraints/injection-renderer.d.ts.map +1 -0
- package/dist/core/constraints/injection-renderer.js +44 -0
- package/dist/core/constraints/injection-renderer.js.map +1 -0
- package/dist/core/constraints/interceptor.d.ts.map +1 -1
- package/dist/core/constraints/interceptor.js +3 -2
- package/dist/core/constraints/interceptor.js.map +1 -1
- package/dist/core/constraints/usage-report.d.ts +95 -0
- package/dist/core/constraints/usage-report.d.ts.map +1 -0
- package/dist/core/constraints/usage-report.js +206 -0
- package/dist/core/constraints/usage-report.js.map +1 -0
- package/dist/core/effective-constraints.d.ts +47 -0
- package/dist/core/effective-constraints.d.ts.map +1 -0
- package/dist/core/effective-constraints.js +60 -0
- package/dist/core/effective-constraints.js.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/project-config-loader.d.ts +17 -2
- package/dist/core/project-config-loader.d.ts.map +1 -1
- package/dist/core/project-config-loader.js +55 -8
- package/dist/core/project-config-loader.js.map +1 -1
- package/dist/dashboard/data.d.ts +1 -9
- package/dist/dashboard/data.d.ts.map +1 -1
- package/dist/dashboard/data.js +7 -15
- package/dist/dashboard/data.js.map +1 -1
- package/dist/dashboard/types.d.ts +13 -1
- package/dist/dashboard/types.d.ts.map +1 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -13
- package/dist/index.js.map +1 -1
- package/dist/monitoring/index.d.ts +0 -2
- package/dist/monitoring/index.d.ts.map +1 -1
- package/dist/monitoring/index.js +0 -2
- package/dist/monitoring/index.js.map +1 -1
- package/dist/monitoring/knowledge-evolver.d.ts +1 -1
- package/dist/monitoring/knowledge-evolver.js +1 -1
- package/dist/monitoring/trace-analyzer.d.ts +1 -1
- package/dist/monitoring/trace-analyzer.d.ts.map +1 -1
- package/dist/monitoring/trace-analyzer.js +16 -10
- package/dist/monitoring/trace-analyzer.js.map +1 -1
- package/dist/monitoring/traces.d.ts +2 -1
- package/dist/monitoring/traces.d.ts.map +1 -1
- package/dist/monitoring/traces.js +5 -3
- package/dist/monitoring/traces.js.map +1 -1
- package/dist/presets/standard.d.ts +3 -1
- package/dist/presets/standard.d.ts.map +1 -1
- package/dist/presets/standard.js +18 -8
- package/dist/presets/standard.js.map +1 -1
- package/dist/types/constraint.d.ts +51 -11
- package/dist/types/constraint.d.ts.map +1 -1
- package/dist/types/constraint.js +8 -4
- package/dist/types/constraint.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/monitoring-types.d.ts +2 -63
- package/dist/types/monitoring-types.d.ts.map +1 -1
- package/dist/types/monitoring-types.js +2 -2
- package/dist/types/project-config.d.ts +26 -1
- package/dist/types/project-config.d.ts.map +1 -1
- package/dist/types/trace.d.ts +16 -7
- package/dist/types/trace.d.ts.map +1 -1
- package/dist/types/trace.js +8 -0
- package/dist/types/trace.js.map +1 -1
- package/package.json +1 -1
- package/src/CONTEXT.md +2 -2
- package/src/__tests__/checker-extra.test.ts +228 -333
- package/src/__tests__/checker.test.ts +87 -724
- package/src/__tests__/constraint-doctor.test.ts +5 -5
- package/src/__tests__/doctor-extra.test.ts +164 -0
- package/src/__tests__/effective-constraints.test.ts +147 -0
- package/src/__tests__/extend-exceptions.test.ts +3 -3
- package/src/__tests__/iron-laws.test.ts +115 -91
- package/src/__tests__/no-hardcoded-credentials.test.ts +90 -0
- package/src/__tests__/presets.test.ts +7 -7
- package/src/__tests__/project-config-loader-extra.test.ts +41 -4
- package/src/__tests__/skip-semantics.test.ts +322 -0
- package/src/cli/commands/CONTEXT.md +5 -3
- package/src/cli/commands/__tests__/check-drift.test.ts +127 -0
- package/src/cli/commands/__tests__/check-skip-output.test.ts +128 -0
- package/src/cli/commands/__tests__/check.test.ts +14 -25
- package/src/cli/commands/__tests__/constraints-report.test.ts +327 -0
- package/src/cli/commands/__tests__/constraints-retire.test.ts +283 -0
- package/src/cli/commands/__tests__/init-injection.test.ts +234 -0
- package/src/cli/commands/__tests__/status-extra.test.ts +11 -11
- package/src/cli/commands/__tests__/status.test.ts +1 -1
- package/src/cli/commands/check.ts +72 -38
- package/src/cli/commands/constraints-report.ts +234 -0
- package/src/cli/commands/constraints-retire.ts +443 -0
- package/src/cli/commands/constraints.ts +5 -5
- package/src/cli/commands/index.ts +2 -1
- package/src/cli/commands/init.ts +94 -66
- package/src/cli/commands/report.ts +6 -6
- package/src/cli/commands/status.ts +3 -4
- package/src/cli/commands/sync-docs/capabilities-syncer.ts +5 -7
- package/src/cli/commands/validate.ts +1 -5
- package/src/core/CONTEXT.md +7 -4
- package/src/core/constraints/__tests__/injection-drift.test.ts +164 -0
- package/src/core/constraints/__tests__/interceptor.test.ts +4 -0
- package/src/core/constraints/capabilities-parser.ts +13 -0
- package/src/core/constraints/checker.ts +73 -28
- package/src/core/constraints/checkers/capability-sync.ts +72 -29
- package/src/core/constraints/checkers/context-doc-sync.ts +9 -2
- package/src/core/constraints/checkers/docs-freshness.ts +43 -0
- package/src/core/constraints/checkers/index.ts +38 -71
- package/src/core/constraints/checkers/iron-flags.ts +13 -49
- package/src/core/constraints/checkers/no-hardcoded-credentials.ts +93 -0
- package/src/core/constraints/checkers/types.ts +27 -5
- package/src/core/constraints/context-builder.ts +28 -19
- package/src/core/constraints/definitions/guidelines.ts +29 -597
- package/src/core/constraints/definitions/iron-laws.ts +48 -239
- package/src/core/constraints/definitions/prompts.ts +419 -0
- package/src/core/constraints/definitions.ts +18 -11
- package/src/core/constraints/index.ts +10 -1
- package/src/core/constraints/injection-drift.ts +139 -0
- package/src/core/constraints/injection-renderer.ts +44 -0
- package/src/core/constraints/interceptor.ts +3 -2
- package/src/core/constraints/usage-report.ts +254 -0
- package/src/core/effective-constraints.ts +85 -0
- package/src/core/index.ts +4 -1
- package/src/core/project-config-loader.ts +59 -9
- package/src/dashboard/__tests__/data.test.ts +5 -12
- package/src/dashboard/data.ts +9 -19
- package/src/dashboard/types.ts +18 -1
- package/src/index.ts +0 -12
- package/src/knowledge/CONTEXT.md +2 -2
- package/src/monitoring/CONTEXT.md +3 -4
- package/src/monitoring/index.ts +0 -2
- package/src/monitoring/knowledge-evolver.ts +1 -1
- package/src/monitoring/trace-analyzer.ts +15 -10
- package/src/monitoring/traces.ts +10 -6
- package/src/presets/__tests__/standard.test.ts +11 -9
- package/src/presets/standard.ts +24 -15
- package/src/types/constraint.ts +59 -14
- package/src/types/index.ts +1 -3
- package/src/types/monitoring-types.ts +2 -84
- package/src/types/project-config.ts +30 -1
- package/src/types/trace.ts +18 -7
- package/src/verification/CONTEXT.md +1 -1
- package/dist/cli/commands/flow.d.ts +0 -22
- package/dist/cli/commands/flow.d.ts.map +0 -1
- package/dist/cli/commands/flow.js +0 -275
- package/dist/cli/commands/flow.js.map +0 -1
- package/dist/constraints/lifecycle-runner.d.ts +0 -52
- package/dist/constraints/lifecycle-runner.d.ts.map +0 -1
- package/dist/constraints/lifecycle-runner.js +0 -151
- package/dist/constraints/lifecycle-runner.js.map +0 -1
- package/dist/constraints/registry.d.ts +0 -27
- package/dist/constraints/registry.d.ts.map +0 -1
- package/dist/constraints/registry.js +0 -128
- package/dist/constraints/registry.js.map +0 -1
- package/dist/constraints/types.d.ts +0 -53
- package/dist/constraints/types.d.ts.map +0 -1
- package/dist/constraints/types.js +0 -8
- package/dist/constraints/types.js.map +0 -1
- package/dist/core/constraints/checkers/always-pass.d.ts +0 -17
- package/dist/core/constraints/checkers/always-pass.d.ts.map +0 -1
- package/dist/core/constraints/checkers/always-pass.js +0 -23
- package/dist/core/constraints/checkers/always-pass.js.map +0 -1
- package/dist/core/constraints/checkers/guideline-flags.d.ts +0 -9
- package/dist/core/constraints/checkers/guideline-flags.d.ts.map +0 -1
- package/dist/core/constraints/checkers/guideline-flags.js +0 -13
- package/dist/core/constraints/checkers/guideline-flags.js.map +0 -1
- package/dist/core/constraints/checkers/no-any-type.d.ts +0 -6
- package/dist/core/constraints/checkers/no-any-type.d.ts.map +0 -1
- package/dist/core/constraints/checkers/no-any-type.js +0 -42
- package/dist/core/constraints/checkers/no-any-type.js.map +0 -1
- package/dist/core/constraints/checkers/no-excuse-patterns.d.ts +0 -6
- package/dist/core/constraints/checkers/no-excuse-patterns.d.ts.map +0 -1
- package/dist/core/constraints/checkers/no-excuse-patterns.js +0 -25
- package/dist/core/constraints/checkers/no-excuse-patterns.js.map +0 -1
- package/dist/core/constraints/checkers/no-fuzzy-completion-claim.d.ts +0 -6
- package/dist/core/constraints/checkers/no-fuzzy-completion-claim.d.ts.map +0 -1
- package/dist/core/constraints/checkers/no-fuzzy-completion-claim.js +0 -34
- package/dist/core/constraints/checkers/no-fuzzy-completion-claim.js.map +0 -1
- package/dist/core/constraints/checkers/no-performative-agreement.d.ts +0 -8
- package/dist/core/constraints/checkers/no-performative-agreement.d.ts.map +0 -1
- package/dist/core/constraints/checkers/no-performative-agreement.js +0 -23
- package/dist/core/constraints/checkers/no-performative-agreement.js.map +0 -1
- package/dist/core/constraints/checkers/no-simplification-without-approval.d.ts +0 -6
- package/dist/core/constraints/checkers/no-simplification-without-approval.d.ts.map +0 -1
- package/dist/core/constraints/checkers/no-simplification-without-approval.js +0 -30
- package/dist/core/constraints/checkers/no-simplification-without-approval.js.map +0 -1
- package/dist/core/constraints/checkers/test-coverage.d.ts +0 -6
- package/dist/core/constraints/checkers/test-coverage.d.ts.map +0 -1
- package/dist/core/constraints/checkers/test-coverage.js +0 -33
- package/dist/core/constraints/checkers/test-coverage.js.map +0 -1
- package/dist/core/constraints/checkers/yagni.d.ts +0 -8
- package/dist/core/constraints/checkers/yagni.d.ts.map +0 -1
- package/dist/core/constraints/checkers/yagni.js +0 -96
- package/dist/core/constraints/checkers/yagni.js.map +0 -1
- package/dist/core/constraints/definitions/tips.d.ts +0 -7
- package/dist/core/constraints/definitions/tips.d.ts.map +0 -1
- package/dist/core/constraints/definitions/tips.js +0 -62
- package/dist/core/constraints/definitions/tips.js.map +0 -1
- package/dist/evolution/auto-evolve.d.ts +0 -35
- package/dist/evolution/auto-evolve.d.ts.map +0 -1
- package/dist/evolution/auto-evolve.js +0 -64
- package/dist/evolution/auto-evolve.js.map +0 -1
- package/dist/evolution/index.d.ts +0 -2
- package/dist/evolution/index.d.ts.map +0 -1
- package/dist/evolution/index.js +0 -18
- package/dist/evolution/index.js.map +0 -1
- package/dist/monitoring/constraint-evolver.d.ts +0 -120
- package/dist/monitoring/constraint-evolver.d.ts.map +0 -1
- package/dist/monitoring/constraint-evolver.js +0 -410
- package/dist/monitoring/constraint-evolver.js.map +0 -1
- package/src/__tests__/constraint-evolver.test.ts +0 -405
- package/src/__tests__/doctor-evolver.test.ts +0 -381
- package/src/cli/commands/__tests__/flow.test.ts +0 -343
- package/src/cli/commands/flow.ts +0 -277
- package/src/constraints/__tests__/lifecycle-runner.test.ts +0 -246
- package/src/constraints/__tests__/registry.test.ts +0 -196
- package/src/constraints/lifecycle-runner.ts +0 -184
- package/src/constraints/registry.ts +0 -134
- package/src/constraints/types.ts +0 -59
- package/src/core/constraints/checkers/always-pass.ts +0 -22
- package/src/core/constraints/checkers/guideline-flags.ts +0 -30
- package/src/core/constraints/checkers/no-any-type.ts +0 -42
- package/src/core/constraints/checkers/no-excuse-patterns.ts +0 -24
- package/src/core/constraints/checkers/no-fuzzy-completion-claim.ts +0 -33
- package/src/core/constraints/checkers/no-performative-agreement.ts +0 -22
- package/src/core/constraints/checkers/no-simplification-without-approval.ts +0 -29
- package/src/core/constraints/checkers/test-coverage.ts +0 -35
- package/src/core/constraints/checkers/yagni.ts +0 -65
- package/src/core/constraints/definitions/tips.ts +0 -63
- package/src/evolution/CONTEXT.md +0 -22
- package/src/evolution/__tests__/auto-evolve.test.ts +0 -319
- package/src/evolution/auto-evolve.ts +0 -98
- package/src/evolution/index.ts +0 -1
- package/src/monitoring/constraint-evolver.ts +0 -501
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* flow 命令测试
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { flow } from '../flow';
|
|
6
|
-
import * as fs from 'fs';
|
|
7
|
-
import * as readline from 'readline';
|
|
8
|
-
import { TraceCollector } from '../../../monitoring/traces';
|
|
9
|
-
import { TraceAnalyzer } from '../../../monitoring/trace-analyzer';
|
|
10
|
-
import { ConstraintDoctor } from '../../../monitoring/constraint-doctor';
|
|
11
|
-
import { ConstraintEvolver } from '../../../monitoring/constraint-evolver';
|
|
12
|
-
|
|
13
|
-
// Mock fs
|
|
14
|
-
jest.mock('fs', () => ({
|
|
15
|
-
existsSync: jest.fn().mockReturnValue(false),
|
|
16
|
-
readFileSync: jest.fn().mockReturnValue(''),
|
|
17
|
-
mkdirSync: jest.fn(),
|
|
18
|
-
writeFileSync: jest.fn(),
|
|
19
|
-
}));
|
|
20
|
-
|
|
21
|
-
// Mock readline
|
|
22
|
-
jest.mock('readline', () => ({
|
|
23
|
-
createInterface: jest.fn().mockReturnValue({
|
|
24
|
-
question: jest.fn(),
|
|
25
|
-
close: jest.fn(),
|
|
26
|
-
}),
|
|
27
|
-
}));
|
|
28
|
-
|
|
29
|
-
// Mock monitoring modules
|
|
30
|
-
jest.mock('../../../monitoring/traces', () => ({
|
|
31
|
-
TraceCollector: jest.fn(),
|
|
32
|
-
}));
|
|
33
|
-
|
|
34
|
-
jest.mock('../../../monitoring/trace-analyzer', () => ({
|
|
35
|
-
TraceAnalyzer: jest.fn(),
|
|
36
|
-
}));
|
|
37
|
-
|
|
38
|
-
jest.mock('../../../monitoring/constraint-doctor', () => ({
|
|
39
|
-
ConstraintDoctor: jest.fn(),
|
|
40
|
-
}));
|
|
41
|
-
|
|
42
|
-
jest.mock('../../../monitoring/constraint-evolver', () => ({
|
|
43
|
-
ConstraintEvolver: jest.fn(),
|
|
44
|
-
}));
|
|
45
|
-
|
|
46
|
-
// Mock chalk
|
|
47
|
-
jest.mock('chalk', () => ({
|
|
48
|
-
blue: jest.fn((str: string) => str),
|
|
49
|
-
yellow: jest.fn((str: string) => str),
|
|
50
|
-
green: jest.fn((str: string) => str),
|
|
51
|
-
gray: jest.fn((str: string) => str),
|
|
52
|
-
red: jest.fn((str: string) => str),
|
|
53
|
-
}));
|
|
54
|
-
|
|
55
|
-
const mockFs = fs as jest.Mocked<typeof fs>;
|
|
56
|
-
const MockTraceCollector = TraceCollector as jest.MockedClass<typeof TraceCollector>;
|
|
57
|
-
const MockTraceAnalyzer = TraceAnalyzer as jest.MockedClass<typeof TraceAnalyzer>;
|
|
58
|
-
const MockConstraintDoctor = ConstraintDoctor as jest.MockedClass<typeof ConstraintDoctor>;
|
|
59
|
-
const MockConstraintEvolver = ConstraintEvolver as jest.MockedClass<typeof ConstraintEvolver>;
|
|
60
|
-
|
|
61
|
-
describe('flow command', () => {
|
|
62
|
-
let consoleSpy: jest.SpyInstance;
|
|
63
|
-
let mockRl: { question: jest.Mock; close: jest.Mock };
|
|
64
|
-
|
|
65
|
-
beforeEach(() => {
|
|
66
|
-
jest.clearAllMocks();
|
|
67
|
-
consoleSpy = jest.spyOn(console, 'log').mockImplementation();
|
|
68
|
-
process.exitCode = 0;
|
|
69
|
-
|
|
70
|
-
mockRl = {
|
|
71
|
-
question: jest.fn((q: string, cb: (a: string) => void) => cb('y')),
|
|
72
|
-
close: jest.fn(),
|
|
73
|
-
};
|
|
74
|
-
(readline.createInterface as jest.Mock).mockReturnValue(mockRl);
|
|
75
|
-
|
|
76
|
-
// Reset fs mocks
|
|
77
|
-
mockFs.existsSync.mockReturnValue(false);
|
|
78
|
-
mockFs.readFileSync.mockReturnValue('');
|
|
79
|
-
mockFs.mkdirSync.mockReturnValue('');
|
|
80
|
-
mockFs.writeFileSync.mockReturnValue(undefined as any);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
afterEach(() => {
|
|
84
|
-
consoleSpy.mockRestore();
|
|
85
|
-
process.exitCode = 0;
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe('flow', () => {
|
|
89
|
-
it('应该跳过无 trace 记录情况', async () => {
|
|
90
|
-
mockFs.existsSync.mockReturnValue(false);
|
|
91
|
-
|
|
92
|
-
await flow({});
|
|
93
|
-
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('暂无 Trace'));
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('应该跳过无异常情况', async () => {
|
|
97
|
-
mockFs.existsSync.mockReturnValue(true);
|
|
98
|
-
mockFs.readFileSync.mockReturnValue('{}');
|
|
99
|
-
|
|
100
|
-
const mockCollector = {
|
|
101
|
-
read: jest.fn().mockReturnValue([]),
|
|
102
|
-
};
|
|
103
|
-
const mockAnalyzer = {
|
|
104
|
-
summarize: jest.fn().mockReturnValue([]),
|
|
105
|
-
detectAnomalies: jest.fn().mockReturnValue([]),
|
|
106
|
-
};
|
|
107
|
-
(MockTraceCollector as any).mockImplementation(() => mockCollector);
|
|
108
|
-
(MockTraceAnalyzer as any).mockImplementation(() => mockAnalyzer);
|
|
109
|
-
|
|
110
|
-
await flow({});
|
|
111
|
-
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('未发现异常'));
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('应该运行完整流程', async () => {
|
|
115
|
-
mockFs.existsSync.mockReturnValue(true);
|
|
116
|
-
mockFs.readFileSync.mockReturnValue(JSON.stringify({ constraintId: 'test' }));
|
|
117
|
-
|
|
118
|
-
const mockCollector = {
|
|
119
|
-
read: jest.fn().mockReturnValue([]),
|
|
120
|
-
};
|
|
121
|
-
const mockAnalyzer = {
|
|
122
|
-
summarize: jest.fn().mockReturnValue([
|
|
123
|
-
{ constraintId: 'test', level: 'iron_law', passRate: 0.3 },
|
|
124
|
-
]),
|
|
125
|
-
detectAnomalies: jest.fn().mockReturnValue([
|
|
126
|
-
{ constraintId: 'test', type: 'high_failure_rate' },
|
|
127
|
-
]),
|
|
128
|
-
};
|
|
129
|
-
(MockTraceCollector as any).mockImplementation(() => mockCollector);
|
|
130
|
-
(MockTraceAnalyzer as any).mockImplementation(() => mockAnalyzer);
|
|
131
|
-
|
|
132
|
-
const mockDoctor = {
|
|
133
|
-
diagnose: jest.fn().mockResolvedValue({
|
|
134
|
-
anomalyId: 'test-anomaly',
|
|
135
|
-
constraintId: 'test',
|
|
136
|
-
rootCause: { primary: 'test' },
|
|
137
|
-
impact: { severity: 'high' },
|
|
138
|
-
}),
|
|
139
|
-
};
|
|
140
|
-
(MockConstraintDoctor as any).mockImplementation(() => mockDoctor);
|
|
141
|
-
|
|
142
|
-
const mockEvolver = {
|
|
143
|
-
propose: jest.fn().mockResolvedValue({
|
|
144
|
-
constraintId: 'test',
|
|
145
|
-
type: 'adjust_threshold',
|
|
146
|
-
risk: { level: 'low' },
|
|
147
|
-
}),
|
|
148
|
-
};
|
|
149
|
-
(MockConstraintEvolver as any).mockImplementation(() => mockEvolver);
|
|
150
|
-
|
|
151
|
-
await flow({});
|
|
152
|
-
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('流程完成'));
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('应该支持从诊断步骤开始', async () => {
|
|
156
|
-
mockFs.existsSync.mockReturnValue(true);
|
|
157
|
-
mockFs.readFileSync.mockReturnValue(JSON.stringify({ constraintId: 'test' }));
|
|
158
|
-
|
|
159
|
-
const mockCollector = {
|
|
160
|
-
read: jest.fn().mockReturnValue([]),
|
|
161
|
-
};
|
|
162
|
-
const mockAnalyzer = {
|
|
163
|
-
summarize: jest.fn().mockReturnValue([]),
|
|
164
|
-
detectAnomalies: jest.fn().mockReturnValue([]),
|
|
165
|
-
};
|
|
166
|
-
(MockTraceCollector as any).mockImplementation(() => mockCollector);
|
|
167
|
-
(MockTraceAnalyzer as any).mockImplementation(() => mockAnalyzer);
|
|
168
|
-
|
|
169
|
-
await flow({ from: 'diagnose' });
|
|
170
|
-
expect(consoleSpy).toHaveBeenCalled();
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('应该自动应用低风险提案', async () => {
|
|
174
|
-
mockFs.existsSync.mockReturnValue(true);
|
|
175
|
-
mockFs.readFileSync.mockReturnValue(JSON.stringify({ constraintId: 'test' }));
|
|
176
|
-
|
|
177
|
-
const mockCollector = {
|
|
178
|
-
read: jest.fn().mockReturnValue([]),
|
|
179
|
-
};
|
|
180
|
-
const mockAnalyzer = {
|
|
181
|
-
summarize: jest.fn().mockReturnValue([
|
|
182
|
-
{ constraintId: 'test', level: 'iron_law', passRate: 0.3 },
|
|
183
|
-
]),
|
|
184
|
-
detectAnomalies: jest.fn().mockReturnValue([
|
|
185
|
-
{ constraintId: 'test', type: 'high_failure_rate' },
|
|
186
|
-
]),
|
|
187
|
-
};
|
|
188
|
-
(MockTraceCollector as any).mockImplementation(() => mockCollector);
|
|
189
|
-
(MockTraceAnalyzer as any).mockImplementation(() => mockAnalyzer);
|
|
190
|
-
|
|
191
|
-
const mockDoctor = {
|
|
192
|
-
diagnose: jest.fn().mockResolvedValue({
|
|
193
|
-
anomalyId: 'test-anomaly',
|
|
194
|
-
constraintId: 'test',
|
|
195
|
-
rootCause: { primary: 'test' },
|
|
196
|
-
impact: { severity: 'high' },
|
|
197
|
-
}),
|
|
198
|
-
};
|
|
199
|
-
(MockConstraintDoctor as any).mockImplementation(() => mockDoctor);
|
|
200
|
-
|
|
201
|
-
const mockEvolver = {
|
|
202
|
-
propose: jest.fn().mockResolvedValue({
|
|
203
|
-
constraintId: 'test',
|
|
204
|
-
type: 'adjust_threshold',
|
|
205
|
-
risk: { level: 'low' },
|
|
206
|
-
}),
|
|
207
|
-
};
|
|
208
|
-
(MockConstraintEvolver as any).mockImplementation(() => mockEvolver);
|
|
209
|
-
|
|
210
|
-
mockRl.question
|
|
211
|
-
.mockImplementationOnce((q: string, cb: (a: string) => void) => cb('y'))
|
|
212
|
-
.mockImplementationOnce((q: string, cb: (a: string) => void) => cb('y'));
|
|
213
|
-
|
|
214
|
-
await flow({ autoApply: true });
|
|
215
|
-
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('自动应用'));
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it('应该取消当用户在步骤1输入 n', async () => {
|
|
219
|
-
mockFs.existsSync.mockReturnValue(true);
|
|
220
|
-
mockFs.readFileSync.mockReturnValue(JSON.stringify({ constraintId: 'test' }));
|
|
221
|
-
|
|
222
|
-
const mockAnalyzer = {
|
|
223
|
-
summarize: jest.fn().mockReturnValue([]),
|
|
224
|
-
detectAnomalies: jest.fn().mockReturnValue([
|
|
225
|
-
{ constraintId: 'test', type: 'high_failure_rate' },
|
|
226
|
-
]),
|
|
227
|
-
};
|
|
228
|
-
(MockTraceCollector as any).mockImplementation(() => ({}));
|
|
229
|
-
(MockTraceAnalyzer as any).mockImplementation(() => mockAnalyzer);
|
|
230
|
-
|
|
231
|
-
mockRl.question.mockImplementationOnce((q: string, cb: (a: string) => void) => cb('n'));
|
|
232
|
-
|
|
233
|
-
await flow({});
|
|
234
|
-
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('已取消'));
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
it('应该跳过提案当无提案生成', async () => {
|
|
238
|
-
mockFs.existsSync.mockReturnValue(true);
|
|
239
|
-
mockFs.readFileSync.mockReturnValue(JSON.stringify({ constraintId: 'test' }));
|
|
240
|
-
|
|
241
|
-
const mockAnalyzer = {
|
|
242
|
-
summarize: jest.fn().mockReturnValue([]),
|
|
243
|
-
detectAnomalies: jest.fn().mockReturnValue([
|
|
244
|
-
{ constraintId: 'test', type: 'high_failure_rate' },
|
|
245
|
-
]),
|
|
246
|
-
};
|
|
247
|
-
(MockTraceCollector as any).mockImplementation(() => ({}));
|
|
248
|
-
(MockTraceAnalyzer as any).mockImplementation(() => mockAnalyzer);
|
|
249
|
-
|
|
250
|
-
const mockDoctor = {
|
|
251
|
-
diagnose: jest.fn().mockResolvedValue({
|
|
252
|
-
constraintId: 'test',
|
|
253
|
-
rootCause: { primary: 'test' },
|
|
254
|
-
impact: { severity: 'high' },
|
|
255
|
-
}),
|
|
256
|
-
};
|
|
257
|
-
(MockConstraintDoctor as any).mockImplementation(() => mockDoctor);
|
|
258
|
-
|
|
259
|
-
const mockEvolver = {
|
|
260
|
-
propose: jest.fn().mockResolvedValue(null),
|
|
261
|
-
};
|
|
262
|
-
(MockConstraintEvolver as any).mockImplementation(() => mockEvolver);
|
|
263
|
-
|
|
264
|
-
mockRl.question
|
|
265
|
-
.mockImplementationOnce((q: string, cb: (a: string) => void) => cb('y'))
|
|
266
|
-
.mockImplementationOnce((q: string, cb: (a: string) => void) => cb('y'));
|
|
267
|
-
|
|
268
|
-
await flow({});
|
|
269
|
-
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('无需优化'));
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
it('应该处理诊断失败', async () => {
|
|
273
|
-
mockFs.existsSync.mockReturnValue(true);
|
|
274
|
-
mockFs.readFileSync.mockReturnValue(JSON.stringify({ constraintId: 'test' }));
|
|
275
|
-
|
|
276
|
-
const mockAnalyzer = {
|
|
277
|
-
summarize: jest.fn().mockReturnValue([]),
|
|
278
|
-
detectAnomalies: jest.fn().mockReturnValue([
|
|
279
|
-
{ constraintId: 'test', type: 'high_failure_rate' },
|
|
280
|
-
]),
|
|
281
|
-
};
|
|
282
|
-
(MockTraceCollector as any).mockImplementation(() => ({}));
|
|
283
|
-
(MockTraceAnalyzer as any).mockImplementation(() => mockAnalyzer);
|
|
284
|
-
|
|
285
|
-
const mockDoctor = {
|
|
286
|
-
diagnose: jest.fn().mockRejectedValue(new Error('diagnosis failed')),
|
|
287
|
-
};
|
|
288
|
-
(MockConstraintDoctor as any).mockImplementation(() => mockDoctor);
|
|
289
|
-
|
|
290
|
-
const mockEvolver = {
|
|
291
|
-
propose: jest.fn().mockResolvedValue(null),
|
|
292
|
-
};
|
|
293
|
-
(MockConstraintEvolver as any).mockImplementation(() => mockEvolver);
|
|
294
|
-
|
|
295
|
-
mockRl.question
|
|
296
|
-
.mockImplementationOnce((q: string, cb: (a: string) => void) => cb('y'))
|
|
297
|
-
.mockImplementationOnce((q: string, cb: (a: string) => void) => cb('y'));
|
|
298
|
-
|
|
299
|
-
await flow({});
|
|
300
|
-
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('诊断失败'));
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
it('应该跳过提案当用户输入 n', async () => {
|
|
304
|
-
mockFs.existsSync.mockReturnValue(true);
|
|
305
|
-
mockFs.readFileSync.mockReturnValue(JSON.stringify({ constraintId: 'test' }));
|
|
306
|
-
|
|
307
|
-
const mockAnalyzer = {
|
|
308
|
-
summarize: jest.fn().mockReturnValue([]),
|
|
309
|
-
detectAnomalies: jest.fn().mockReturnValue([
|
|
310
|
-
{ constraintId: 'test', type: 'high_failure_rate' },
|
|
311
|
-
]),
|
|
312
|
-
};
|
|
313
|
-
(MockTraceCollector as any).mockImplementation(() => ({}));
|
|
314
|
-
(MockTraceAnalyzer as any).mockImplementation(() => mockAnalyzer);
|
|
315
|
-
|
|
316
|
-
const mockDoctor = {
|
|
317
|
-
diagnose: jest.fn().mockResolvedValue({
|
|
318
|
-
constraintId: 'test',
|
|
319
|
-
rootCause: { primary: 'test' },
|
|
320
|
-
impact: { severity: 'high' },
|
|
321
|
-
}),
|
|
322
|
-
};
|
|
323
|
-
(MockConstraintDoctor as any).mockImplementation(() => mockDoctor);
|
|
324
|
-
|
|
325
|
-
const mockEvolver = {
|
|
326
|
-
propose: jest.fn().mockResolvedValue({
|
|
327
|
-
constraintId: 'test',
|
|
328
|
-
type: 'adjust_threshold',
|
|
329
|
-
risk: { level: 'medium' },
|
|
330
|
-
}),
|
|
331
|
-
};
|
|
332
|
-
(MockConstraintEvolver as any).mockImplementation(() => mockEvolver);
|
|
333
|
-
|
|
334
|
-
mockRl.question
|
|
335
|
-
.mockImplementationOnce((q: string, cb: (a: string) => void) => cb('y'))
|
|
336
|
-
.mockImplementationOnce((q: string, cb: (a: string) => void) => cb('y'))
|
|
337
|
-
.mockImplementationOnce((q: string, cb: (a: string) => void) => cb('n'));
|
|
338
|
-
|
|
339
|
-
await flow({});
|
|
340
|
-
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('跳过提案'));
|
|
341
|
-
});
|
|
342
|
-
});
|
|
343
|
-
});
|
package/src/cli/commands/flow.ts
DELETED
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* harness flow 命令
|
|
3
|
-
*
|
|
4
|
-
* 一键执行诊断 + 提案流程
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import chalk from 'chalk';
|
|
8
|
-
import * as fs from 'fs';
|
|
9
|
-
import * as path from 'path';
|
|
10
|
-
import * as readline from 'readline';
|
|
11
|
-
import { TraceCollector } from '../../monitoring/traces';
|
|
12
|
-
import { TraceAnalyzer } from '../../monitoring/trace-analyzer';
|
|
13
|
-
import { ConstraintDoctor } from '../../monitoring/constraint-doctor';
|
|
14
|
-
import { ConstraintEvolver } from '../../monitoring/constraint-evolver';
|
|
15
|
-
import { getConstraint } from '../../core/constraints/definitions';
|
|
16
|
-
import type { Diagnosis, ConstraintProposal } from '../../types/monitoring-types';
|
|
17
|
-
import { ConstraintLifecycleRunner, type ExecutionResult } from '../../constraints/lifecycle-runner';
|
|
18
|
-
import type { TraceAnomaly } from '../../types/trace';
|
|
19
|
-
|
|
20
|
-
export interface FlowOptions {
|
|
21
|
-
/** 项目路径 */
|
|
22
|
-
projectPath?: string;
|
|
23
|
-
/** 从哪个步骤开始 */
|
|
24
|
-
from?: 'analyze' | 'diagnose' | 'propose';
|
|
25
|
-
/** 自动应用低风险提案 */
|
|
26
|
-
autoApply?: boolean;
|
|
27
|
-
/** 自动执行已接受的提案(调用 ConstraintLifecycleRunner) */
|
|
28
|
-
autoExecute?: boolean;
|
|
29
|
-
/** 时间范围(小时) */
|
|
30
|
-
hours?: number;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* 创建 readline 接口
|
|
35
|
-
*/
|
|
36
|
-
function createReadlineInterface(): readline.ReadLine {
|
|
37
|
-
return readline.createInterface({
|
|
38
|
-
input: process.stdin,
|
|
39
|
-
output: process.stdout,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* 询问用户
|
|
45
|
-
*/
|
|
46
|
-
function ask(rl: readline.ReadLine, question: string): Promise<string> {
|
|
47
|
-
return new Promise(resolve => {
|
|
48
|
-
rl.question(question, answer => {
|
|
49
|
-
resolve(answer.trim().toLowerCase());
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* 执行流程
|
|
56
|
-
*/
|
|
57
|
-
export async function flow(options: FlowOptions): Promise<void> {
|
|
58
|
-
const projectPath = options.projectPath || process.cwd();
|
|
59
|
-
const harnessDir = path.join(projectPath, '.harness');
|
|
60
|
-
const tracesPath = path.join(harnessDir, 'traces', 'execution.log');
|
|
61
|
-
const diagnosesDir = path.join(harnessDir, 'diagnoses');
|
|
62
|
-
const proposalsDir = path.join(harnessDir, 'proposals');
|
|
63
|
-
|
|
64
|
-
console.log(chalk.blue('🔄 Harness 自动化流程'));
|
|
65
|
-
console.log();
|
|
66
|
-
|
|
67
|
-
// 检查前置条件
|
|
68
|
-
if (!fs.existsSync(tracesPath)) {
|
|
69
|
-
console.log(chalk.yellow('⚠️ 暂无 Trace 记录'));
|
|
70
|
-
console.log(chalk.gray('💡 运行 harness check 开始记录'));
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// 读取 traces
|
|
75
|
-
const tracesContent = fs.readFileSync(tracesPath, 'utf-8');
|
|
76
|
-
const lines = tracesContent.trim().split('\n').filter(Boolean);
|
|
77
|
-
const traces = lines.map(line => {
|
|
78
|
-
try {
|
|
79
|
-
return JSON.parse(line);
|
|
80
|
-
} catch {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
}).filter(Boolean);
|
|
84
|
-
|
|
85
|
-
// 创建收集器和分析器
|
|
86
|
-
const collector = new TraceCollector({ traceFile: tracesPath });
|
|
87
|
-
const analyzer = new TraceAnalyzer(collector);
|
|
88
|
-
const summaries = analyzer.summarize(traces);
|
|
89
|
-
let anomalies = analyzer.detectAnomalies(summaries);
|
|
90
|
-
|
|
91
|
-
const rl = createReadlineInterface();
|
|
92
|
-
|
|
93
|
-
try {
|
|
94
|
-
// 步骤 1: 分析统计
|
|
95
|
-
if (!options.from || options.from === 'analyze') {
|
|
96
|
-
console.log(chalk.blue('📊 步骤 1/4: 分析统计'));
|
|
97
|
-
console.log(chalk.gray('────────────────────────────'));
|
|
98
|
-
|
|
99
|
-
console.log(chalk.gray(`约束统计: ${summaries.length} 条`));
|
|
100
|
-
console.log(chalk.gray(`检测异常: ${anomalies.length} 个`));
|
|
101
|
-
|
|
102
|
-
if (anomalies.length === 0) {
|
|
103
|
-
console.log(chalk.green('✅ 未发现异常'));
|
|
104
|
-
rl.close();
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
console.log(chalk.yellow('发现异常:'));
|
|
109
|
-
anomalies.forEach((a: TraceAnomaly) => {
|
|
110
|
-
console.log(chalk.yellow(` - ${a.constraintId}: ${a.type}`));
|
|
111
|
-
});
|
|
112
|
-
console.log();
|
|
113
|
-
|
|
114
|
-
// 询问是否继续
|
|
115
|
-
const continue1 = await ask(rl, '是否继续运行诊断? [Y/n] ');
|
|
116
|
-
if (continue1 === 'n') {
|
|
117
|
-
console.log(chalk.gray('已取消'));
|
|
118
|
-
rl.close();
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
console.log();
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// 步骤 2: 运行诊断
|
|
125
|
-
console.log(chalk.blue('🔍 步骤 2/4: 运行诊断'));
|
|
126
|
-
console.log(chalk.gray('────────────────────────────'));
|
|
127
|
-
|
|
128
|
-
const doctor = new ConstraintDoctor();
|
|
129
|
-
const diagnoses: Diagnosis[] = [];
|
|
130
|
-
|
|
131
|
-
for (const anomaly of anomalies) {
|
|
132
|
-
try {
|
|
133
|
-
const diagnosis = await doctor.diagnose(anomaly);
|
|
134
|
-
diagnoses.push(diagnosis);
|
|
135
|
-
} catch (e) {
|
|
136
|
-
console.log(chalk.yellow(` ⚠️ ${anomaly.constraintId} 诊断失败`));
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
console.log(chalk.gray(`诊断数量: ${diagnoses.length}`));
|
|
141
|
-
|
|
142
|
-
if (diagnoses.length > 0) {
|
|
143
|
-
console.log();
|
|
144
|
-
diagnoses.forEach((d: Diagnosis) => {
|
|
145
|
-
console.log(chalk.yellow(` ${d.constraintId}`));
|
|
146
|
-
console.log(chalk.gray(` 根因: ${d.rootCause.primary}`));
|
|
147
|
-
console.log(chalk.gray(` 严重度: ${d.impact.severity}`));
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// 保存诊断结果
|
|
152
|
-
if (diagnoses.length > 0) {
|
|
153
|
-
fs.mkdirSync(diagnosesDir, { recursive: true });
|
|
154
|
-
const diagnosisFile = path.join(diagnosesDir, `${new Date().toISOString().split('T')[0]}.json`);
|
|
155
|
-
fs.writeFileSync(diagnosisFile, JSON.stringify(diagnoses, null, 2));
|
|
156
|
-
console.log(chalk.green(`✅ 诊断已保存: ${diagnosisFile}`));
|
|
157
|
-
}
|
|
158
|
-
console.log();
|
|
159
|
-
|
|
160
|
-
// 询问是否继续
|
|
161
|
-
const continue2 = await ask(rl, '是否继续生成优化提案? [Y/n] ');
|
|
162
|
-
if (continue2 === 'n') {
|
|
163
|
-
console.log(chalk.gray('已取消'));
|
|
164
|
-
rl.close();
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
console.log();
|
|
168
|
-
|
|
169
|
-
// 步骤 3: 生成提案
|
|
170
|
-
console.log(chalk.blue('💡 步骤 3/4: 生成提案'));
|
|
171
|
-
console.log(chalk.gray('────────────────────────────'));
|
|
172
|
-
|
|
173
|
-
const evolver = new ConstraintEvolver(undefined, getConstraint);
|
|
174
|
-
const proposals: ConstraintProposal[] = [];
|
|
175
|
-
|
|
176
|
-
for (const diagnosis of diagnoses) {
|
|
177
|
-
try {
|
|
178
|
-
const proposal = await evolver.propose(diagnosis);
|
|
179
|
-
if (proposal) {
|
|
180
|
-
proposals.push(proposal);
|
|
181
|
-
}
|
|
182
|
-
} catch (e) {
|
|
183
|
-
console.log(chalk.yellow(` ⚠️ ${diagnosis.constraintId} 提案生成失败`));
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
console.log(chalk.gray(`提案数量: ${proposals.length}`));
|
|
188
|
-
|
|
189
|
-
if (proposals.length === 0) {
|
|
190
|
-
console.log(chalk.green('✅ 无需优化'));
|
|
191
|
-
rl.close();
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
console.log();
|
|
196
|
-
proposals.forEach((p: ConstraintProposal, i: number) => {
|
|
197
|
-
console.log(chalk.yellow(`提案 ${i + 1}:`));
|
|
198
|
-
console.log(chalk.gray(` 约束: ${p.constraintId}`));
|
|
199
|
-
console.log(chalk.gray(` 操作: ${p.type}`));
|
|
200
|
-
console.log(chalk.gray(` 风险: ${p.risk.level}`));
|
|
201
|
-
console.log();
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
// 保存提案
|
|
205
|
-
fs.mkdirSync(proposalsDir, { recursive: true });
|
|
206
|
-
const proposalFile = path.join(proposalsDir, `${new Date().toISOString().split('T')[0]}.json`);
|
|
207
|
-
fs.writeFileSync(proposalFile, JSON.stringify({ proposals, timestamp: new Date().toISOString() }, null, 2));
|
|
208
|
-
console.log(chalk.green(`✅ 提案已保存: ${proposalFile}`));
|
|
209
|
-
console.log();
|
|
210
|
-
|
|
211
|
-
// 步骤 4: 审核提案
|
|
212
|
-
console.log(chalk.blue('📝 步骤 4/4: 审核提案'));
|
|
213
|
-
console.log(chalk.gray('────────────────────────────'));
|
|
214
|
-
|
|
215
|
-
const runner = options.autoExecute ? new ConstraintLifecycleRunner() : null;
|
|
216
|
-
const executionResults: ExecutionResult[] = [];
|
|
217
|
-
|
|
218
|
-
for (let i = 0; i < proposals.length; i++) {
|
|
219
|
-
const p = proposals[i];
|
|
220
|
-
|
|
221
|
-
// 低风险 → 可自动应用
|
|
222
|
-
if (options.autoApply && p.risk.level === 'low') {
|
|
223
|
-
console.log(chalk.green(`✅ 自动应用提案 ${i + 1} (低风险)`));
|
|
224
|
-
if (runner) {
|
|
225
|
-
const result = runner.execute(p);
|
|
226
|
-
executionResults.push(result);
|
|
227
|
-
if (result.success) {
|
|
228
|
-
console.log(chalk.green(` ✅ 已执行: ${result.details}`));
|
|
229
|
-
} else {
|
|
230
|
-
console.log(chalk.yellow(` ⚠️ 执行失败: ${result.details}`));
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// 需要人工审核
|
|
237
|
-
const answer = await ask(rl, `是否应用提案 ${i + 1}? [y/N] `);
|
|
238
|
-
if (answer === 'y') {
|
|
239
|
-
console.log(chalk.green(`✅ 提案 ${i + 1} 已标记为应用`));
|
|
240
|
-
if (runner) {
|
|
241
|
-
const result = runner.execute(p);
|
|
242
|
-
executionResults.push(result);
|
|
243
|
-
if (result.success) {
|
|
244
|
-
console.log(chalk.green(` ✅ 已执行: ${result.details}`));
|
|
245
|
-
} else {
|
|
246
|
-
console.log(chalk.yellow(` ⚠️ 执行失败: ${result.details}`));
|
|
247
|
-
}
|
|
248
|
-
} else {
|
|
249
|
-
console.log(chalk.gray(' 请手动更新约束配置'));
|
|
250
|
-
}
|
|
251
|
-
} else {
|
|
252
|
-
console.log(chalk.gray(`⏭️ 跳过提案 ${i + 1}`));
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// 显示执行摘要
|
|
257
|
-
if (executionResults.length > 0) {
|
|
258
|
-
console.log();
|
|
259
|
-
console.log(chalk.blue('📊 执行摘要:'));
|
|
260
|
-
const succeeded = executionResults.filter(r => r.success).length;
|
|
261
|
-
const failed = executionResults.filter(r => !r.success).length;
|
|
262
|
-
console.log(chalk.gray(` 成功: ${succeeded}, 失败: ${failed}`));
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
console.log();
|
|
266
|
-
console.log(chalk.green('✅ 流程完成!'));
|
|
267
|
-
console.log();
|
|
268
|
-
console.log(chalk.blue('💡 下一步:'));
|
|
269
|
-
console.log(chalk.gray(' 1. 查看提案文件确认变更'));
|
|
270
|
-
if (!runner) {
|
|
271
|
-
console.log(chalk.gray(' 2. 手动更新约束配置'));
|
|
272
|
-
}
|
|
273
|
-
console.log(chalk.gray(` ${runner ? '2' : '3'}. 运行 harness status 查看效果`));
|
|
274
|
-
} finally {
|
|
275
|
-
rl.close();
|
|
276
|
-
}
|
|
277
|
-
}
|