@dommaker/harness 0.13.0 → 0.13.2
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 +169 -0
- package/bin/harness-knowledge-capture.js +99 -0
- package/bin/harness-knowledge-check.js +149 -0
- package/bin/harness-knowledge-track.js +92 -0
- package/bin/harness-knowledge-track.sh +47 -0
- package/bin/harness-sensitive-check.sh +67 -0
- package/dist/cli/commands/init.js +34 -2
- package/dist/cli/commands/init.js.map +1 -1
- package/package.json +6 -3
- package/src/CONTEXT.md +34 -0
- package/src/__tests__/acceptance-gate.test.ts +364 -0
- package/src/__tests__/annotation-checker.test.ts +183 -0
- package/src/__tests__/architecture-engine.test.ts +619 -0
- package/src/__tests__/checker-extra.test.ts +1627 -0
- package/src/__tests__/checker.test.ts +1268 -0
- package/src/__tests__/checkpoint.test.ts +697 -0
- package/src/__tests__/clean-state-extra.test.ts +301 -0
- package/src/__tests__/clean-state.test.ts +169 -0
- package/src/__tests__/constraint-doctor.test.ts +410 -0
- package/src/__tests__/constraint-evolver.test.ts +404 -0
- package/src/__tests__/constraint-handler.test.ts +136 -0
- package/src/__tests__/context/progressive-loader.test.ts +131 -0
- package/src/__tests__/contract-gate.test.ts +321 -0
- package/src/__tests__/cross-project-checker.test.ts +318 -0
- package/src/__tests__/cso-validator.test.ts +205 -0
- package/src/__tests__/detect-source-roots.test.ts +98 -0
- package/src/__tests__/doctor-evolver.test.ts +381 -0
- package/src/__tests__/error-classifier.test.ts +304 -0
- package/src/__tests__/exec.test.ts +83 -0
- package/src/__tests__/extend-exceptions.test.ts +149 -0
- package/src/__tests__/failure-recorder.test.ts +335 -0
- package/src/__tests__/hooks-pipeline.test.ts +214 -0
- package/src/__tests__/interceptor.test.ts +89 -0
- package/src/__tests__/iron-laws.test.ts +246 -0
- package/src/__tests__/long-running.test.ts +17 -0
- package/src/__tests__/passes-gate-check.test.ts +138 -0
- package/src/__tests__/passes-gate-extension.test.ts +151 -0
- package/src/__tests__/passes-gate-extra.test.ts +238 -0
- package/src/__tests__/passes-gate.test.ts +231 -0
- package/src/__tests__/performance-analyzer.test.ts +501 -0
- package/src/__tests__/performance-collector.test.ts +276 -0
- package/src/__tests__/performance-gate.test.ts +74 -0
- package/src/__tests__/presets.test.ts +104 -0
- package/src/__tests__/project-config-loader-extra.test.ts +269 -0
- package/src/__tests__/project-config-loader.test.ts +127 -0
- package/src/__tests__/review-gate.test.ts +92 -0
- package/src/__tests__/security-gate.test.ts +100 -0
- package/src/__tests__/session-startup.test.ts +334 -0
- package/src/__tests__/spec-validator.test.ts +57 -0
- package/src/__tests__/token-budget.test.ts +252 -0
- package/src/__tests__/trace-analyzer-extra.test.ts +307 -0
- package/src/__tests__/trace-analyzer.test.ts +131 -0
- package/src/__tests__/trace-collector.test.ts +258 -0
- package/src/__tests__/traces.test.ts +347 -0
- package/src/agents/CONTEXT.md +21 -0
- package/src/agents/__tests__/lifecycle.test.ts +248 -0
- package/src/agents/index.ts +2 -0
- package/src/agents/lifecycle.ts +201 -0
- package/src/agents/types.ts +46 -0
- package/src/architecture/CONTEXT.md +22 -0
- package/src/architecture/constraint-engine.ts +356 -0
- package/src/architecture/cross-project-checker.ts +563 -0
- package/src/cli/commands/CONTEXT.md +24 -0
- package/src/cli/commands/__tests__/acceptance.test.ts +180 -0
- package/src/cli/commands/__tests__/check.test.ts +598 -0
- package/src/cli/commands/__tests__/command.test.ts +149 -0
- package/src/cli/commands/__tests__/contract.test.ts +151 -0
- package/src/cli/commands/__tests__/failure.test.ts +199 -0
- package/src/cli/commands/__tests__/flow.test.ts +343 -0
- package/src/cli/commands/__tests__/init.test.ts +306 -0
- package/src/cli/commands/__tests__/passes-gate.test.ts +256 -0
- package/src/cli/commands/__tests__/performance.test.ts +116 -0
- package/src/cli/commands/__tests__/posteval-plan.test.ts +201 -0
- package/src/cli/commands/__tests__/report-extra.test.ts +98 -0
- package/src/cli/commands/__tests__/report.test.ts +109 -0
- package/src/cli/commands/__tests__/review.test.ts +153 -0
- package/src/cli/commands/__tests__/security.test.ts +147 -0
- package/src/cli/commands/__tests__/spec.test.ts +193 -0
- package/src/cli/commands/__tests__/status-extra.test.ts +223 -0
- package/src/cli/commands/__tests__/status.test.ts +306 -0
- package/src/cli/commands/__tests__/sync-docs.test.ts +335 -0
- package/src/cli/commands/__tests__/validate.test.ts +139 -0
- package/src/cli/commands/acceptance.ts +111 -0
- package/src/cli/commands/analyze-sessions.ts +488 -0
- package/src/cli/commands/check.ts +441 -0
- package/src/cli/commands/command.ts +90 -0
- package/src/cli/commands/constraints.ts +86 -0
- package/src/cli/commands/contract.ts +168 -0
- package/src/cli/commands/failure.ts +117 -0
- package/src/cli/commands/flow.ts +275 -0
- package/src/cli/commands/index.ts +26 -0
- package/src/cli/commands/init.ts +832 -0
- package/src/cli/commands/knowledge.ts +391 -0
- package/src/cli/commands/passes-gate.ts +158 -0
- package/src/cli/commands/performance.ts +108 -0
- package/src/cli/commands/posteval-plan.ts +85 -0
- package/src/cli/commands/release.ts +159 -0
- package/src/cli/commands/report.ts +198 -0
- package/src/cli/commands/review.ts +118 -0
- package/src/cli/commands/security.ts +122 -0
- package/src/cli/commands/spec.ts +158 -0
- package/src/cli/commands/status.ts +169 -0
- package/src/cli/commands/sync-docs.ts +743 -0
- package/src/cli/commands/update-user-model.ts +527 -0
- package/src/cli/commands/validate.ts +222 -0
- package/src/constraints/__tests__/lifecycle-runner.test.ts +246 -0
- package/src/constraints/__tests__/registry.test.ts +196 -0
- package/src/constraints/index.ts +3 -0
- package/src/constraints/lifecycle-runner.ts +184 -0
- package/src/constraints/registry.ts +134 -0
- package/src/constraints/types.ts +59 -0
- package/src/context/CONTEXT.md +28 -0
- package/src/context/__tests__/compaction.test.ts +169 -0
- package/src/context/__tests__/file-budget.test.ts +142 -0
- package/src/context/__tests__/knowledge-injector.test.ts +148 -0
- package/src/context/__tests__/progressive-loader.test.ts +264 -0
- package/src/context/__tests__/session-manager.test.ts +300 -0
- package/src/context/__tests__/token-budget.test.ts +338 -0
- package/src/context/__tests__/token-pipeline.test.ts +178 -0
- package/src/context/__tests__/tool-output-budget.test.ts +95 -0
- package/src/context/compaction.ts +202 -0
- package/src/context/file-budget.ts +142 -0
- package/src/context/index.ts +15 -0
- package/src/context/knowledge-injector.ts +168 -0
- package/src/context/progressive-loader.ts +260 -0
- package/src/context/session-manager.ts +343 -0
- package/src/context/token-budget.ts +295 -0
- package/src/context/token-pipeline.ts +265 -0
- package/src/context/tool-output-budget.ts +178 -0
- package/src/context/types.ts +160 -0
- package/src/core/CONTEXT.md +26 -0
- package/src/core/constraints/__tests__/default-executors.test.ts +57 -0
- package/src/core/constraints/__tests__/interceptor.test.ts +251 -0
- package/src/core/constraints/__tests__/prompt-injection.test.ts +89 -0
- package/src/core/constraints/check-cache.ts +96 -0
- package/src/core/constraints/checker.ts +1169 -0
- package/src/core/constraints/default-executors.ts +92 -0
- package/src/core/constraints/definitions.ts +1119 -0
- package/src/core/constraints/doc-freshness/__tests__/runner.test.ts +551 -0
- package/src/core/constraints/doc-freshness/auto-fix.ts +69 -0
- package/src/core/constraints/doc-freshness/runner.ts +486 -0
- package/src/core/constraints/index.ts +78 -0
- package/src/core/constraints/interceptor.ts +220 -0
- package/src/core/constraints/prompt-injection.ts +73 -0
- package/src/core/index.ts +23 -0
- package/src/core/project-config-loader.ts +252 -0
- package/src/core/session/__tests__/startup.test.ts +281 -0
- package/src/core/session/clean-state.ts +178 -0
- package/src/core/session/index.ts +15 -0
- package/src/core/session/startup.ts +253 -0
- package/src/core/spec/__tests__/validator.test.ts +379 -0
- package/src/core/spec/index.ts +7 -0
- package/src/core/spec/validator.ts +383 -0
- package/src/core/validators/__tests__/passes-gate.test.ts +131 -0
- package/src/core/validators/checkpoint.ts +547 -0
- package/src/core/validators/cso.ts +124 -0
- package/src/core/validators/index.ts +25 -0
- package/src/core/validators/passes-gate.ts +613 -0
- package/src/dashboard/CONTEXT.md +21 -0
- package/src/dashboard/__tests__/data.test.ts +115 -0
- package/src/dashboard/__tests__/stats.test.ts +156 -0
- package/src/dashboard/data.ts +113 -0
- package/src/dashboard/index.ts +3 -0
- package/src/dashboard/stats.ts +127 -0
- package/src/dashboard/types.ts +113 -0
- package/src/evolution/CONTEXT.md +22 -0
- package/src/evolution/__tests__/auto-evolve.test.ts +320 -0
- package/src/evolution/auto-evolve.ts +98 -0
- package/src/evolution/index.ts +1 -0
- package/src/failure/CONTEXT.md +24 -0
- package/src/failure/classifier.ts +156 -0
- package/src/failure/constraint-handler.ts +173 -0
- package/src/failure/index.ts +35 -0
- package/src/failure/recorder.ts +201 -0
- package/src/failure/types.ts +165 -0
- package/src/gates/CONTEXT.md +27 -0
- package/src/gates/__tests__/acceptance.test.ts +608 -0
- package/src/gates/__tests__/command.test.ts +206 -0
- package/src/gates/__tests__/performance.test.ts +381 -0
- package/src/gates/__tests__/review.test.ts +302 -0
- package/src/gates/__tests__/security.test.ts +332 -0
- package/src/gates/acceptance.ts +493 -0
- package/src/gates/command.ts +444 -0
- package/src/gates/contract.ts +260 -0
- package/src/gates/index.ts +67 -0
- package/src/gates/performance.ts +359 -0
- package/src/gates/review.ts +169 -0
- package/src/gates/security.ts +244 -0
- package/src/gates/types.ts +159 -0
- package/src/governance/CONTEXT.md +22 -0
- package/src/governance/__tests__/executor.test.ts +249 -0
- package/src/governance/executor.ts +229 -0
- package/src/governance/index.ts +13 -0
- package/src/governance/types.ts +53 -0
- package/src/hooks/CONTEXT.md +23 -0
- package/src/hooks/__tests__/bootstrap.test.ts +184 -0
- package/src/hooks/bootstrap.ts +144 -0
- package/src/hooks/index.ts +15 -0
- package/src/hooks/pipeline.ts +157 -0
- package/src/hooks/registry.ts +88 -0
- package/src/hooks/types.ts +80 -0
- package/src/index.ts +198 -0
- package/src/knowledge/CONTEXT.md +29 -0
- package/src/knowledge/__tests__/doctor.test.ts +272 -0
- package/src/knowledge/__tests__/import.test.ts +376 -0
- package/src/knowledge/__tests__/ingest.test.ts +125 -0
- package/src/knowledge/__tests__/lifecycle-hooks.test.ts +137 -0
- package/src/knowledge/__tests__/lifecycle.test.ts +248 -0
- package/src/knowledge/__tests__/lint.test.ts +401 -0
- package/src/knowledge/__tests__/query.test.ts +185 -0
- package/src/knowledge/__tests__/reference-tracker.test.ts +129 -0
- package/src/knowledge/__tests__/store.test.ts +238 -0
- package/src/knowledge/doctor.ts +104 -0
- package/src/knowledge/import.ts +505 -0
- package/src/knowledge/index.ts +16 -0
- package/src/knowledge/ingest.ts +126 -0
- package/src/knowledge/lifecycle-hooks.ts +199 -0
- package/src/knowledge/lifecycle.ts +175 -0
- package/src/knowledge/lint.ts +360 -0
- package/src/knowledge/query.ts +150 -0
- package/src/knowledge/reference-tracker.ts +99 -0
- package/src/knowledge/store.ts +264 -0
- package/src/knowledge/types.ts +139 -0
- package/src/llm/CONTEXT.md +21 -0
- package/src/llm/__tests__/adapter.test.ts +172 -0
- package/src/llm/adapter.ts +149 -0
- package/src/llm/index.ts +2 -0
- package/src/llm/types.ts +81 -0
- package/src/monitoring/CONTEXT.md +29 -0
- package/src/monitoring/__tests__/context-tracker.test.ts +172 -0
- package/src/monitoring/__tests__/knowledge-doctor.test.ts +276 -0
- package/src/monitoring/__tests__/knowledge-evolver.test.ts +365 -0
- package/src/monitoring/__tests__/performance-analyzer.test.ts +137 -0
- package/src/monitoring/__tests__/performance-collector.test.ts +332 -0
- package/src/monitoring/__tests__/traces.test.ts +190 -0
- package/src/monitoring/constraint-doctor.ts +499 -0
- package/src/monitoring/constraint-evolver.ts +573 -0
- package/src/monitoring/context-tracker.ts +148 -0
- package/src/monitoring/index.ts +23 -0
- package/src/monitoring/knowledge-doctor.ts +323 -0
- package/src/monitoring/knowledge-evolver.ts +289 -0
- package/src/monitoring/performance-analyzer.ts +450 -0
- package/src/monitoring/performance-collector.ts +348 -0
- package/src/monitoring/trace-analyzer.ts +470 -0
- package/src/monitoring/traces.ts +339 -0
- package/src/presets/__tests__/standard.test.ts +104 -0
- package/src/presets/index.ts +16 -0
- package/src/presets/standard.ts +163 -0
- package/src/safety/CONTEXT.md +23 -0
- package/src/safety/__tests__/input-guardrail.test.ts +105 -0
- package/src/safety/__tests__/output-guardrail.test.ts +108 -0
- package/src/safety/__tests__/sandbox.test.ts +158 -0
- package/src/safety/__tests__/tool-guardrail.test.ts +127 -0
- package/src/safety/index.ts +5 -0
- package/src/safety/input-guardrail.ts +133 -0
- package/src/safety/output-guardrail.ts +174 -0
- package/src/safety/sandbox.ts +148 -0
- package/src/safety/tool-guardrail.ts +176 -0
- package/src/safety/types.ts +124 -0
- package/src/spec/CONTEXT.md +19 -0
- package/src/spec/__tests__/annotation-checker.test.ts +289 -0
- package/src/spec/annotation-checker.ts +342 -0
- package/src/tools/CONTEXT.md +25 -0
- package/src/tools/__tests__/loader.test.ts +252 -0
- package/src/tools/__tests__/registry.test.ts +157 -0
- package/src/tools/core/__tests__/core.test.ts +122 -0
- package/src/tools/core/index.ts +201 -0
- package/src/tools/core/package.json +7 -0
- package/src/tools/core/pnpm-lock.yaml +232 -0
- package/src/tools/definitions/core/code/fingerprint.sh +273 -0
- package/src/tools/definitions/core/code/fingerprint.yml +72 -0
- package/src/tools/definitions/core/code/parse.yml +68 -0
- package/src/tools/definitions/core/code/register-language.sh +475 -0
- package/src/tools/definitions/core/code/register-language.yml +74 -0
- package/src/tools/definitions/core/docker/build.yml +73 -0
- package/src/tools/definitions/core/docker/run.yml +81 -0
- package/src/tools/definitions/core/file/copy.yml +88 -0
- package/src/tools/definitions/core/file/read.yml +69 -0
- package/src/tools/definitions/core/file/write.yml +75 -0
- package/src/tools/definitions/core/git/branch.yml +61 -0
- package/src/tools/definitions/core/git/cleanup-worktree.yml +50 -0
- package/src/tools/definitions/core/git/clone.yml +69 -0
- package/src/tools/definitions/core/git/commit.yml +65 -0
- package/src/tools/definitions/core/git/push.yml +79 -0
- package/src/tools/definitions/core/git/worktree.yml +96 -0
- package/src/tools/definitions/core/notification/notify.sh +152 -0
- package/src/tools/definitions/core/notification/notify.yml +60 -0
- package/src/tools/definitions/core/npm/build.yml +75 -0
- package/src/tools/definitions/core/npm/install.yml +58 -0
- package/src/tools/definitions/core/npm/test.yml +75 -0
- package/src/tools/definitions/core/validation/check-reuse.yml +170 -0
- package/src/tools/definitions/core/validation/validate-handlers.yml +118 -0
- package/src/tools/definitions/core/validation/validate-readme-stats.yml +155 -0
- package/src/tools/definitions/core/validation/validate-yaml-syntax.yml +134 -0
- package/src/tools/definitions/ext/browser/browser-automate.sh +255 -0
- package/src/tools/definitions/ext/browser/browser-automate.yml +166 -0
- package/src/tools/definitions/ext/browser/browser-close.sh +104 -0
- package/src/tools/definitions/ext/browser/browser-close.yml +55 -0
- package/src/tools/definitions/ext/browser/browser-mcp-debug.sh +682 -0
- package/src/tools/definitions/ext/browser/browser-mcp-debug.yml +167 -0
- package/src/tools/definitions/ext/browser/browser-start.sh +101 -0
- package/src/tools/definitions/ext/browser/browser-start.yml +62 -0
- package/src/tools/definitions/registry.json +795 -0
- package/src/tools/definitions/std/README.md +350 -0
- package/src/tools/definitions/std/analysis/analyze-codebase.yml +72 -0
- package/src/tools/definitions/std/analysis/analyze-diff.yml +182 -0
- package/src/tools/definitions/std/analysis/analyze-git-diff.yml +70 -0
- package/src/tools/definitions/std/analysis/analyze-impact.yml +78 -0
- package/src/tools/definitions/std/analysis/analyze-requirements.yml +105 -0
- package/src/tools/definitions/std/analysis/brainstorm-options.yml +106 -0
- package/src/tools/definitions/std/analysis/build-graph.yml +154 -0
- package/src/tools/definitions/std/analysis/clarify-requirements.yml +90 -0
- package/src/tools/definitions/std/analysis/detect-context.yml +109 -0
- package/src/tools/definitions/std/analysis/detect-layers.yml +125 -0
- package/src/tools/definitions/std/analysis/generate-tour.yml +102 -0
- package/src/tools/definitions/std/analysis/search-enhance.yml +105 -0
- package/src/tools/definitions/std/backlog/add.yml +51 -0
- package/src/tools/definitions/std/backlog/decide.yml +39 -0
- package/src/tools/definitions/std/backlog/github-sync.yml +161 -0
- package/src/tools/definitions/std/backlog/list.yml +53 -0
- package/src/tools/definitions/std/backlog/load.yml +46 -0
- package/src/tools/definitions/std/backlog/resolve.yml +37 -0
- package/src/tools/definitions/std/backlog/update.yml +42 -0
- package/src/tools/definitions/std/bugfix/diagnose.yml +68 -0
- package/src/tools/definitions/std/bugfix/fix.yml +66 -0
- package/src/tools/definitions/std/bugfix/verify.yml +69 -0
- package/src/tools/definitions/std/constraint/check-decomposition.yml +103 -0
- package/src/tools/definitions/std/constraint/check-feature-list.yml +77 -0
- package/src/tools/definitions/std/constraint/check-progress.yml +97 -0
- package/src/tools/definitions/std/constraint/generate-report.yml +147 -0
- package/src/tools/definitions/std/deploy/commit-push.yml +33 -0
- package/src/tools/definitions/std/deploy/deploy-backend.yml +37 -0
- package/src/tools/definitions/std/deploy/deploy-frontend.yml +37 -0
- package/src/tools/definitions/std/deploy/rollback.yml +148 -0
- package/src/tools/definitions/std/design/analyze-architecture-impact.yml +113 -0
- package/src/tools/definitions/std/design/design-api.yml +55 -0
- package/src/tools/definitions/std/design/design-architecture.yml +97 -0
- package/src/tools/definitions/std/design/design-db.yml +81 -0
- package/src/tools/definitions/std/design/generate-spec.yml +182 -0
- package/src/tools/definitions/std/development/develop-api.yml +85 -0
- package/src/tools/definitions/std/development/develop-backend.yml +88 -0
- package/src/tools/definitions/std/development/develop-frontend.yml +87 -0
- package/src/tools/definitions/std/development/develop-shared-types.yml +74 -0
- package/src/tools/definitions/std/development/develop-task.yml +122 -0
- package/src/tools/definitions/std/development/develop-tests.yml +76 -0
- package/src/tools/definitions/std/development/execute-batch.yml +152 -0
- package/src/tools/definitions/std/development/fix-issues.yml +100 -0
- package/src/tools/definitions/std/development/implement-task.yml +124 -0
- package/src/tools/definitions/std/development/review-fix-cycle.yml +232 -0
- package/src/tools/definitions/std/evolution/implement.yml +125 -0
- package/src/tools/definitions/std/evolution/prioritize.yml +112 -0
- package/src/tools/definitions/std/evolution/report-gap.yml +166 -0
- package/src/tools/definitions/std/file/read.yml +21 -0
- package/src/tools/definitions/std/governance/aggregate-opinions.sh +201 -0
- package/src/tools/definitions/std/governance/aggregate-opinions.yml +79 -0
- package/src/tools/definitions/std/governance/audit-task.yml +178 -0
- package/src/tools/definitions/std/governance/cast-vote.yml +129 -0
- package/src/tools/definitions/std/governance/collect-issues.yml +16 -0
- package/src/tools/definitions/std/governance/create-signed-document.yml +23 -0
- package/src/tools/definitions/std/governance/create-voting-session.yml +101 -0
- package/src/tools/definitions/std/governance/define-stance.sh +243 -0
- package/src/tools/definitions/std/governance/define-stance.yml +82 -0
- package/src/tools/definitions/std/governance/generate-review-report.yml +23 -0
- package/src/tools/definitions/std/governance/impeach.yml +179 -0
- package/src/tools/definitions/std/governance/multi-stance-review.yml +154 -0
- package/src/tools/definitions/std/governance/prepare-artifact.yml +20 -0
- package/src/tools/definitions/std/governance/review-spec-approval.yml +262 -0
- package/src/tools/definitions/std/governance/rollback.yml +186 -0
- package/src/tools/definitions/std/governance/stance-review.yml +149 -0
- package/src/tools/definitions/std/governance/track-effect.yml +199 -0
- package/src/tools/definitions/std/governance/vote-tally.yml +144 -0
- package/src/tools/definitions/std/patch/execute.yml +51 -0
- package/src/tools/definitions/std/planning/generate-tasks.yml +36 -0
- package/src/tools/definitions/std/planning/load-tasks.yml +44 -0
- package/src/tools/definitions/std/planning/split-batch.yml +481 -0
- package/src/tools/definitions/std/planning/split-tasks.yml +359 -0
- package/src/tools/definitions/std/planning/update-tasks.yml +51 -0
- package/src/tools/definitions/std/planning/validate-tasks.yml +46 -0
- package/src/tools/definitions/std/project/decide-next-workflow.yml +38 -0
- package/src/tools/definitions/std/project/load-state.yml +31 -0
- package/src/tools/definitions/std/project/save-state.yml +32 -0
- package/src/tools/definitions/std/quality/check-quality.yml +241 -0
- package/src/tools/definitions/std/quality/debug-systematic.yml +163 -0
- package/src/tools/definitions/std/quality/handle-feedback.yml +108 -0
- package/src/tools/definitions/std/quality/review-code.yml +128 -0
- package/src/tools/definitions/std/quality/review-spec.yml +140 -0
- package/src/tools/definitions/std/quality/review-task.yml +190 -0
- package/src/tools/definitions/std/quality/run-tests.yml +80 -0
- package/src/tools/definitions/std/quick/analyze.yml +56 -0
- package/src/tools/definitions/std/quick/implement.yml +67 -0
- package/src/tools/definitions/std/quick/verify.yml +71 -0
- package/src/tools/definitions/std/verification/verify_completion.yml +113 -0
- package/src/tools/definitions/std/verification/wait-condition.yml +107 -0
- package/src/tools/index.ts +5 -0
- package/src/tools/loader.ts +216 -0
- package/src/tools/paths.ts +15 -0
- package/src/tools/registry.ts +128 -0
- package/src/tools/types.ts +46 -0
- package/src/types/__tests__/types.test.ts +86 -0
- package/src/types/checkpoint.ts +174 -0
- package/src/types/constraint.ts +335 -0
- package/src/types/cso.ts +37 -0
- package/src/types/enforcement.ts +48 -0
- package/src/types/index.ts +59 -0
- package/src/types/iron-law.ts +50 -0
- package/src/types/passes-gate.ts +185 -0
- package/src/types/performance.ts +295 -0
- package/src/types/project-config.ts +251 -0
- package/src/types/session.ts +132 -0
- package/src/types/spec.ts +91 -0
- package/src/types/trace.ts +228 -0
- package/src/utils/detect-source-roots.ts +114 -0
- package/src/utils/exec.ts +61 -0
- package/src/verification/CONTEXT.md +23 -0
- package/src/verification/__tests__/loop.test.ts +303 -0
- package/src/verification/__tests__/rules-based.test.ts +240 -0
- package/src/verification/index.ts +3 -0
- package/src/verification/loop.ts +137 -0
- package/src/verification/rules-based.ts +153 -0
- package/src/verification/types.ts +81 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 监控模块导出
|
|
3
|
+
*
|
|
4
|
+
* Execution Trace 系统:
|
|
5
|
+
* - TraceCollector:轻量收集,零 Token
|
|
6
|
+
* - TraceAnalyzer:统计汇总,异常检测
|
|
7
|
+
* - ConstraintDoctor:Agent 诊断接口
|
|
8
|
+
* - ConstraintEvolver:约束提案流程
|
|
9
|
+
*
|
|
10
|
+
* Performance Trace 系统:
|
|
11
|
+
* - PerformanceCollector:性能日志收集,零 Token
|
|
12
|
+
* - PerformanceAnalyzer:统计汇总,异常检测
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export * from './traces';
|
|
16
|
+
export * from './trace-analyzer';
|
|
17
|
+
export * from './constraint-doctor';
|
|
18
|
+
export * from './constraint-evolver';
|
|
19
|
+
export * from './performance-collector';
|
|
20
|
+
export * from './performance-analyzer';
|
|
21
|
+
export * from './context-tracker';
|
|
22
|
+
export { KnowledgeDoctor } from './knowledge-doctor';
|
|
23
|
+
export { KnowledgeEvolver } from './knowledge-evolver';
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 知识库健康诊断
|
|
3
|
+
*
|
|
4
|
+
* 从 ConstraintDoctor 转型,聚焦知识库健康:
|
|
5
|
+
* - 孤儿条目检测
|
|
6
|
+
* - 矛盾检测
|
|
7
|
+
* - 过时检测
|
|
8
|
+
* - 成熟度异常
|
|
9
|
+
* - 引用健康度
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { KnowledgeEntry, LintIssue } from '../knowledge/types';
|
|
13
|
+
import type { ConstraintStats } from '../constraints/types';
|
|
14
|
+
|
|
15
|
+
// ── 诊断类型 ─────────────────────────────────────────────
|
|
16
|
+
|
|
17
|
+
export type DiagnosisSeverity = 'low' | 'medium' | 'high' | 'critical';
|
|
18
|
+
|
|
19
|
+
export interface KnowledgeDiagnosis {
|
|
20
|
+
id: string;
|
|
21
|
+
type: 'orphan' | 'contradiction' | 'outdated' | 'decay' | 'low_reference' | 'stale_index';
|
|
22
|
+
severity: DiagnosisSeverity;
|
|
23
|
+
entryId?: string;
|
|
24
|
+
title: string;
|
|
25
|
+
description: string;
|
|
26
|
+
rootCause: string;
|
|
27
|
+
impact: string;
|
|
28
|
+
recommendations: string[];
|
|
29
|
+
timestamp: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface DiagnosisReport {
|
|
33
|
+
timestamp: string;
|
|
34
|
+
totalEntries: number;
|
|
35
|
+
healthScore: number; // 0-100
|
|
36
|
+
diagnoses: KnowledgeDiagnosis[];
|
|
37
|
+
summary: Record<DiagnosisSeverity, number>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// ── 配置 ─────────────────────────────────────────────────
|
|
41
|
+
|
|
42
|
+
export interface KnowledgeDoctorConfig {
|
|
43
|
+
/** 低引用阈值(低于此值标记为 low_reference) */
|
|
44
|
+
lowReferenceThreshold?: number;
|
|
45
|
+
/** 过时天数(超过此天数未引用标记为 outdated) */
|
|
46
|
+
outdatedDays?: number;
|
|
47
|
+
/** 衰减预警天数 */
|
|
48
|
+
decayWarningDays?: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const DEFAULT_CONFIG: Required<KnowledgeDoctorConfig> = {
|
|
52
|
+
lowReferenceThreshold: 2,
|
|
53
|
+
outdatedDays: 180,
|
|
54
|
+
decayWarningDays: 90,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// ── 知识库诊断器 ─────────────────────────────────────────
|
|
58
|
+
|
|
59
|
+
export class KnowledgeDoctor {
|
|
60
|
+
private config: Required<KnowledgeDoctorConfig>;
|
|
61
|
+
|
|
62
|
+
constructor(config?: KnowledgeDoctorConfig) {
|
|
63
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 诊断知识库健康
|
|
68
|
+
*/
|
|
69
|
+
diagnose(entries: KnowledgeEntry[], lintIssues: LintIssue[] = []): DiagnosisReport {
|
|
70
|
+
const diagnoses: KnowledgeDiagnosis[] = [];
|
|
71
|
+
|
|
72
|
+
// 从 lint issues 转换
|
|
73
|
+
diagnoses.push(...this.fromLintIssues(lintIssues));
|
|
74
|
+
|
|
75
|
+
// 知识库特有诊断
|
|
76
|
+
diagnoses.push(...this.checkOrphans(entries));
|
|
77
|
+
diagnoses.push(...this.checkOutdated(entries));
|
|
78
|
+
diagnoses.push(...this.checkDecay(entries));
|
|
79
|
+
diagnoses.push(...this.checkLowReference(entries));
|
|
80
|
+
|
|
81
|
+
// 计算健康分数
|
|
82
|
+
const healthScore = this.calculateHealthScore(entries, diagnoses);
|
|
83
|
+
|
|
84
|
+
// 统计
|
|
85
|
+
const summary: Record<DiagnosisSeverity, number> = {
|
|
86
|
+
low: 0,
|
|
87
|
+
medium: 0,
|
|
88
|
+
high: 0,
|
|
89
|
+
critical: 0,
|
|
90
|
+
};
|
|
91
|
+
for (const d of diagnoses) {
|
|
92
|
+
summary[d.severity]++;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
timestamp: new Date().toISOString(),
|
|
97
|
+
totalEntries: entries.length,
|
|
98
|
+
healthScore,
|
|
99
|
+
diagnoses,
|
|
100
|
+
summary,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 从 Lint issues 生成诊断
|
|
106
|
+
*/
|
|
107
|
+
private fromLintIssues(issues: LintIssue[]): KnowledgeDiagnosis[] {
|
|
108
|
+
return issues.map(issue => ({
|
|
109
|
+
id: `lint-${issue.type}-${issue.entryId ?? 'unknown'}`,
|
|
110
|
+
type: issue.type as KnowledgeDiagnosis['type'],
|
|
111
|
+
severity: issue.severity,
|
|
112
|
+
entryId: issue.entryId,
|
|
113
|
+
title: issue.description,
|
|
114
|
+
description: issue.description,
|
|
115
|
+
rootCause: this.inferRootCause(issue),
|
|
116
|
+
impact: this.inferImpact(issue),
|
|
117
|
+
recommendations: [issue.suggestion],
|
|
118
|
+
timestamp: new Date().toISOString(),
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 检查孤儿条目
|
|
124
|
+
*/
|
|
125
|
+
private checkOrphans(entries: KnowledgeEntry[]): KnowledgeDiagnosis[] {
|
|
126
|
+
const diagnoses: KnowledgeDiagnosis[] = [];
|
|
127
|
+
|
|
128
|
+
for (const entry of entries) {
|
|
129
|
+
if (entry.maturity === 'archived') continue;
|
|
130
|
+
|
|
131
|
+
const hasRefs = entry.referencedBy.length > 0;
|
|
132
|
+
const hasContributors = entry.contributors.length > 0;
|
|
133
|
+
const hasProjects = entry.projects.length > 0;
|
|
134
|
+
|
|
135
|
+
if (!hasRefs && !hasContributors && !hasProjects && entry.maturity === 'draft') {
|
|
136
|
+
diagnoses.push({
|
|
137
|
+
id: `orphan-${entry.id}`,
|
|
138
|
+
type: 'orphan',
|
|
139
|
+
severity: 'low',
|
|
140
|
+
entryId: entry.id,
|
|
141
|
+
title: `孤儿条目: ${entry.title}`,
|
|
142
|
+
description: `条目 ${entry.id} 无引用、无贡献者、无项目验证`,
|
|
143
|
+
rootCause: '条目可能是自动生成但未被任何工作流引用',
|
|
144
|
+
impact: '占用知识库空间但不产生价值',
|
|
145
|
+
recommendations: ['归档该条目', '或标记为需要验证后等待引用'],
|
|
146
|
+
timestamp: new Date().toISOString(),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return diagnoses;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 检查过时条目
|
|
156
|
+
*/
|
|
157
|
+
private checkOutdated(entries: KnowledgeEntry[]): KnowledgeDiagnosis[] {
|
|
158
|
+
const diagnoses: KnowledgeDiagnosis[] = [];
|
|
159
|
+
const threshold = new Date();
|
|
160
|
+
threshold.setDate(threshold.getDate() - this.config.outdatedDays);
|
|
161
|
+
|
|
162
|
+
for (const entry of entries) {
|
|
163
|
+
if (entry.maturity === 'archived') continue;
|
|
164
|
+
if (entry.maturity !== 'draft') continue;
|
|
165
|
+
|
|
166
|
+
const lastRef = entry.lastReferenced ? new Date(entry.lastReferenced) : new Date(entry.created);
|
|
167
|
+
if (lastRef < threshold) {
|
|
168
|
+
diagnoses.push({
|
|
169
|
+
id: `outdated-${entry.id}`,
|
|
170
|
+
type: 'outdated',
|
|
171
|
+
severity: 'medium',
|
|
172
|
+
entryId: entry.id,
|
|
173
|
+
title: `过时条目: ${entry.title}`,
|
|
174
|
+
description: `条目 ${entry.id} 超过 ${this.config.outdatedDays} 天未引用且为 draft`,
|
|
175
|
+
rootCause: '长期未被引用,可能已失去相关性',
|
|
176
|
+
impact: '降低知识库整体质量',
|
|
177
|
+
recommendations: ['归档该条目', '或验证后提升成熟度'],
|
|
178
|
+
timestamp: new Date().toISOString(),
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return diagnoses;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* 检查衰减预警
|
|
188
|
+
*/
|
|
189
|
+
private checkDecay(entries: KnowledgeEntry[]): KnowledgeDiagnosis[] {
|
|
190
|
+
const diagnoses: KnowledgeDiagnosis[] = [];
|
|
191
|
+
const warningThreshold = new Date();
|
|
192
|
+
warningThreshold.setDate(warningThreshold.getDate() - this.config.decayWarningDays);
|
|
193
|
+
|
|
194
|
+
for (const entry of entries) {
|
|
195
|
+
if (entry.maturity !== 'proven' && entry.maturity !== 'verified') continue;
|
|
196
|
+
|
|
197
|
+
const lastRef = entry.lastReferenced ? new Date(entry.lastReferenced) : new Date(entry.created);
|
|
198
|
+
if (lastRef < warningThreshold) {
|
|
199
|
+
diagnoses.push({
|
|
200
|
+
id: `decay-${entry.id}`,
|
|
201
|
+
type: 'decay',
|
|
202
|
+
severity: entry.maturity === 'proven' ? 'high' : 'medium',
|
|
203
|
+
entryId: entry.id,
|
|
204
|
+
title: `衰减预警: ${entry.title}`,
|
|
205
|
+
description: `${entry.maturity} 条目 ${entry.id} 超过 ${this.config.decayWarningDays} 天未引用`,
|
|
206
|
+
rootCause: '长期未被引用,成熟度可能需要降级',
|
|
207
|
+
impact: '高成熟度条目未被引用,可能已过时',
|
|
208
|
+
recommendations: ['检查条目是否仍然相关', '如已过时则降级成熟度'],
|
|
209
|
+
timestamp: new Date().toISOString(),
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return diagnoses;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* 检查低引用条目
|
|
219
|
+
*/
|
|
220
|
+
private checkLowReference(entries: KnowledgeEntry[]): KnowledgeDiagnosis[] {
|
|
221
|
+
const diagnoses: KnowledgeDiagnosis[] = [];
|
|
222
|
+
|
|
223
|
+
for (const entry of entries) {
|
|
224
|
+
if (entry.maturity === 'archived') continue;
|
|
225
|
+
if (entry.maturity === 'draft') continue;
|
|
226
|
+
|
|
227
|
+
if (entry.referencedBy.length < this.config.lowReferenceThreshold) {
|
|
228
|
+
diagnoses.push({
|
|
229
|
+
id: `low-ref-${entry.id}`,
|
|
230
|
+
type: 'low_reference',
|
|
231
|
+
severity: 'low',
|
|
232
|
+
entryId: entry.id,
|
|
233
|
+
title: `低引用: ${entry.title}`,
|
|
234
|
+
description: `${entry.maturity} 条目 ${entry.id} 仅被引用 ${entry.referencedBy.length} 次`,
|
|
235
|
+
rootCause: '条目可能不够通用或不易被发现',
|
|
236
|
+
impact: '高成熟度但低引用,投入产出比低',
|
|
237
|
+
recommendations: ['检查条目是否需要更新以提高相关性', '考虑在更多场景中引用'],
|
|
238
|
+
timestamp: new Date().toISOString(),
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return diagnoses;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* 计算健康分数(0-100)
|
|
248
|
+
*/
|
|
249
|
+
private calculateHealthScore(entries: KnowledgeEntry[], diagnoses: KnowledgeDiagnosis[]): number {
|
|
250
|
+
if (entries.length === 0) return 100;
|
|
251
|
+
|
|
252
|
+
let penalty = 0;
|
|
253
|
+
for (const d of diagnoses) {
|
|
254
|
+
switch (d.severity) {
|
|
255
|
+
case 'critical': penalty += 10; break;
|
|
256
|
+
case 'high': penalty += 5; break;
|
|
257
|
+
case 'medium': penalty += 2; break;
|
|
258
|
+
case 'low': penalty += 1; break;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// 每个条目的最大扣分
|
|
263
|
+
const maxPenalty = entries.length * 10;
|
|
264
|
+
const score = Math.max(0, 100 - Math.round((penalty / Math.max(maxPenalty, 1)) * 100));
|
|
265
|
+
return score;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
private inferRootCause(issue: LintIssue): string {
|
|
269
|
+
switch (issue.type) {
|
|
270
|
+
case 'orphan': return '条目未被任何工作流或项目引用';
|
|
271
|
+
case 'contradiction': return '同标签下存在成熟度差异大的条目';
|
|
272
|
+
case 'outdated': return '长期未引用的 draft 条目';
|
|
273
|
+
case 'duplicate': return '同类型同标题的重复条目';
|
|
274
|
+
case 'index_inconsistent': return '索引与磁盘文件不一致';
|
|
275
|
+
default: return '未知原因';
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
private inferImpact(issue: LintIssue): string {
|
|
280
|
+
switch (issue.type) {
|
|
281
|
+
case 'orphan': return '占用空间但不产生价值';
|
|
282
|
+
case 'contradiction': return '可能误导 Agent 决策';
|
|
283
|
+
case 'outdated': return '降低知识库整体质量';
|
|
284
|
+
case 'duplicate': return '浪费查询预算';
|
|
285
|
+
case 'index_inconsistent': return '可能导致查询失败';
|
|
286
|
+
default: return '未知影响';
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* 生成诊断报告(Markdown)
|
|
292
|
+
*/
|
|
293
|
+
generateReport(report: DiagnosisReport): string {
|
|
294
|
+
const lines: string[] = [];
|
|
295
|
+
|
|
296
|
+
lines.push(`# 知识库健康报告`);
|
|
297
|
+
lines.push(`时间: ${report.timestamp}`);
|
|
298
|
+
lines.push(`条目总数: ${report.totalEntries}`);
|
|
299
|
+
lines.push(`健康分数: ${report.healthScore}/100`);
|
|
300
|
+
lines.push('');
|
|
301
|
+
|
|
302
|
+
lines.push(`## 问题统计`);
|
|
303
|
+
lines.push(`- 严重: ${report.summary.critical}`);
|
|
304
|
+
lines.push(`- 高: ${report.summary.high}`);
|
|
305
|
+
lines.push(`- 中: ${report.summary.medium}`);
|
|
306
|
+
lines.push(`- 低: ${report.summary.low}`);
|
|
307
|
+
lines.push('');
|
|
308
|
+
|
|
309
|
+
if (report.diagnoses.length > 0) {
|
|
310
|
+
lines.push(`## 诊断详情`);
|
|
311
|
+
for (const d of report.diagnoses) {
|
|
312
|
+
lines.push(`### [${d.severity.toUpperCase()}] ${d.title}`);
|
|
313
|
+
lines.push(d.description);
|
|
314
|
+
lines.push(`**根因**: ${d.rootCause}`);
|
|
315
|
+
lines.push(`**影响**: ${d.impact}`);
|
|
316
|
+
lines.push(`**建议**: ${d.recommendations.join(', ')}`);
|
|
317
|
+
lines.push('');
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return lines.join('\n');
|
|
322
|
+
}
|
|
323
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 知识成熟度进化器
|
|
3
|
+
*
|
|
4
|
+
* 从 ConstraintEvolver 转型,聚焦知识成熟度进化:
|
|
5
|
+
* - 基于引用数据提议成熟度变更
|
|
6
|
+
* - 自动审核(安全规则)
|
|
7
|
+
* - 执行变更
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { KnowledgeEntry, MaturityLevel } from '../knowledge/types';
|
|
11
|
+
import type { KnowledgeDiagnosis } from './knowledge-doctor';
|
|
12
|
+
import { 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
|
+
}
|