@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,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ReferenceTracker 测试
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect, beforeAll, afterAll, beforeEach } from '@jest/globals';
|
|
6
|
+
import { KnowledgeStore } from '../store';
|
|
7
|
+
import { ReferenceTracker } from '../reference-tracker';
|
|
8
|
+
import type { KnowledgeEntry } from '../types';
|
|
9
|
+
import * as fs from 'fs';
|
|
10
|
+
import * as path from 'path';
|
|
11
|
+
|
|
12
|
+
describe('ReferenceTracker', () => {
|
|
13
|
+
const tempDir = path.join(process.cwd(), 'temp-test-refs');
|
|
14
|
+
let store: KnowledgeStore;
|
|
15
|
+
let tracker: ReferenceTracker;
|
|
16
|
+
|
|
17
|
+
const makeEntry = (overrides?: Partial<KnowledgeEntry>): KnowledgeEntry => ({
|
|
18
|
+
id: 'DEC-001',
|
|
19
|
+
type: 'decision',
|
|
20
|
+
title: 'Test Decision',
|
|
21
|
+
content: 'Content.',
|
|
22
|
+
maturity: 'draft',
|
|
23
|
+
layer: 'project',
|
|
24
|
+
created: '2026-05-01T00:00:00.000Z',
|
|
25
|
+
lastReferenced: '',
|
|
26
|
+
contributors: [],
|
|
27
|
+
projects: [],
|
|
28
|
+
tags: [],
|
|
29
|
+
applicablePhases: [],
|
|
30
|
+
sourceReferences: [],
|
|
31
|
+
referencedBy: [],
|
|
32
|
+
...overrides,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
beforeAll(() => {
|
|
36
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterAll(() => {
|
|
40
|
+
try {
|
|
41
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
42
|
+
} catch {
|
|
43
|
+
// ignore
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
beforeEach(() => {
|
|
48
|
+
const files = fs.readdirSync(tempDir);
|
|
49
|
+
for (const f of files) {
|
|
50
|
+
fs.unlinkSync(path.join(tempDir, f));
|
|
51
|
+
}
|
|
52
|
+
store = new KnowledgeStore({ baseDir: tempDir });
|
|
53
|
+
tracker = new ReferenceTracker(store, tempDir);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('record', () => {
|
|
57
|
+
it('should append a reference record', () => {
|
|
58
|
+
tracker.record('decision-1', ['entry-1', 'entry-2']);
|
|
59
|
+
const filePath = path.join(tempDir, 'references.jsonl');
|
|
60
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
61
|
+
expect(content).toContain('decision-1');
|
|
62
|
+
expect(content).toContain('entry-1');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should append multiple records', () => {
|
|
66
|
+
tracker.record('decision-1', ['entry-1']);
|
|
67
|
+
tracker.record('decision-2', ['entry-2']);
|
|
68
|
+
const filePath = path.join(tempDir, 'references.jsonl');
|
|
69
|
+
const lines = fs.readFileSync(filePath, 'utf-8').split('\n').filter(Boolean);
|
|
70
|
+
expect(lines).toHaveLength(2);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe('getReferencesForEntry', () => {
|
|
75
|
+
it('should return decisions referencing an entry', () => {
|
|
76
|
+
tracker.record('decision-1', ['entry-1', 'entry-2']);
|
|
77
|
+
tracker.record('decision-2', ['entry-2', 'entry-3']);
|
|
78
|
+
|
|
79
|
+
const refs = tracker.getReferencesForEntry('entry-2');
|
|
80
|
+
expect(refs).toEqual(['decision-1', 'decision-2']);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should return empty array for unreferenced entry', () => {
|
|
84
|
+
tracker.record('decision-1', ['entry-1']);
|
|
85
|
+
expect(tracker.getReferencesForEntry('entry-999')).toEqual([]);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('getReferencesForDecision', () => {
|
|
90
|
+
it('should return entries referenced by a decision', () => {
|
|
91
|
+
tracker.record('decision-1', ['entry-1', 'entry-2']);
|
|
92
|
+
const entries = tracker.getReferencesForDecision('decision-1');
|
|
93
|
+
expect(entries).toEqual(['entry-1', 'entry-2']);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should return empty array for unknown decision', () => {
|
|
97
|
+
expect(tracker.getReferencesForDecision('unknown')).toEqual([]);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe('updateReferencedBy', () => {
|
|
102
|
+
it('should populate referencedBy on entries', () => {
|
|
103
|
+
store.save(makeEntry({ id: 'entry-1' }));
|
|
104
|
+
store.save(makeEntry({ id: 'entry-2' }));
|
|
105
|
+
|
|
106
|
+
tracker.record('decision-1', ['entry-1']);
|
|
107
|
+
tracker.record('decision-2', ['entry-1', 'entry-2']);
|
|
108
|
+
tracker.updateReferencedBy();
|
|
109
|
+
|
|
110
|
+
const e1 = store.get('entry-1');
|
|
111
|
+
const e2 = store.get('entry-2');
|
|
112
|
+
expect(e1!.referencedBy).toContain('decision-1');
|
|
113
|
+
expect(e1!.referencedBy).toContain('decision-2');
|
|
114
|
+
expect(e2!.referencedBy).toEqual(['decision-2']);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe('edge cases', () => {
|
|
119
|
+
it('should handle corrupt references file gracefully', () => {
|
|
120
|
+
const filePath = path.join(tempDir, 'references.jsonl');
|
|
121
|
+
fs.writeFileSync(filePath, 'NOT VALID JSON\n', 'utf-8');
|
|
122
|
+
expect(tracker.getReferencesForEntry('any')).toEqual([]);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('should return empty when file does not exist', () => {
|
|
126
|
+
expect(tracker.getReferencesForDecision('any')).toEqual([]);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KnowledgeStore 测试
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect, beforeAll, afterAll, beforeEach } from '@jest/globals';
|
|
6
|
+
import { KnowledgeStore } from '../store';
|
|
7
|
+
import type { KnowledgeEntry } from '../types';
|
|
8
|
+
import * as fs from 'fs';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
|
|
11
|
+
describe('KnowledgeStore', () => {
|
|
12
|
+
const tempDir = path.join(process.cwd(), 'temp-test-knowledge');
|
|
13
|
+
let store: KnowledgeStore;
|
|
14
|
+
|
|
15
|
+
const makeEntry = (overrides?: Partial<KnowledgeEntry>): KnowledgeEntry => ({
|
|
16
|
+
id: 'DEC-001',
|
|
17
|
+
type: 'decision',
|
|
18
|
+
title: 'Test Decision',
|
|
19
|
+
content: 'This is a test decision.',
|
|
20
|
+
maturity: 'draft',
|
|
21
|
+
layer: 'project',
|
|
22
|
+
created: '2026-05-01T00:00:00.000Z',
|
|
23
|
+
lastReferenced: '',
|
|
24
|
+
contributors: [],
|
|
25
|
+
projects: ['test-project'],
|
|
26
|
+
tags: ['test'],
|
|
27
|
+
applicablePhases: ['ARCHITECT'],
|
|
28
|
+
sourceReferences: [],
|
|
29
|
+
referencedBy: [],
|
|
30
|
+
...overrides,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
beforeAll(() => {
|
|
34
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
afterAll(() => {
|
|
38
|
+
try {
|
|
39
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
40
|
+
} catch {
|
|
41
|
+
// ignore
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
beforeEach(() => {
|
|
46
|
+
// Clean the temp dir before each test
|
|
47
|
+
const files = fs.readdirSync(tempDir);
|
|
48
|
+
for (const f of files) {
|
|
49
|
+
const p = path.join(tempDir, f);
|
|
50
|
+
const stat = fs.statSync(p);
|
|
51
|
+
if (stat.isDirectory()) {
|
|
52
|
+
fs.rmSync(p, { recursive: true, force: true });
|
|
53
|
+
} else {
|
|
54
|
+
fs.unlinkSync(p);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
store = new KnowledgeStore({ baseDir: tempDir });
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('save and get', () => {
|
|
61
|
+
it('should save and retrieve an entry', () => {
|
|
62
|
+
const entry = makeEntry();
|
|
63
|
+
store.save(entry);
|
|
64
|
+
const retrieved = store.get('DEC-001');
|
|
65
|
+
expect(retrieved).toBeDefined();
|
|
66
|
+
expect(retrieved!.id).toBe('DEC-001');
|
|
67
|
+
expect(retrieved!.title).toBe('Test Decision');
|
|
68
|
+
expect(retrieved!.content).toBe('This is a test decision.');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should return undefined for non-existent entry', () => {
|
|
72
|
+
expect(store.get('NON-EXISTENT')).toBeUndefined();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should preserve all fields through save/load cycle', () => {
|
|
76
|
+
const entry = makeEntry({
|
|
77
|
+
contributors: ['alice', 'bob'],
|
|
78
|
+
tags: ['arch', 'db'],
|
|
79
|
+
applicablePhases: ['ANALYSE_TECH', 'ARCHITECT'],
|
|
80
|
+
sourceReferences: [{ workflow: 'test-flow', step: 'step-1', timestamp: '2026-05-01' }],
|
|
81
|
+
});
|
|
82
|
+
store.save(entry);
|
|
83
|
+
const retrieved = store.get('DEC-001');
|
|
84
|
+
expect(retrieved!.contributors).toEqual(['alice', 'bob']);
|
|
85
|
+
expect(retrieved!.tags).toEqual(['arch', 'db']);
|
|
86
|
+
expect(retrieved!.applicablePhases).toEqual(['ANALYSE_TECH', 'ARCHITECT']);
|
|
87
|
+
expect(retrieved!.sourceReferences).toHaveLength(1);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('list', () => {
|
|
92
|
+
it('should list all entries', () => {
|
|
93
|
+
store.save(makeEntry({ id: 'DEC-001' }));
|
|
94
|
+
store.save(makeEntry({ id: 'DEC-002', title: 'Second' }));
|
|
95
|
+
const list = store.list();
|
|
96
|
+
expect(list).toHaveLength(2);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('should filter by type', () => {
|
|
100
|
+
store.save(makeEntry({ id: 'DEC-001', type: 'decision' }));
|
|
101
|
+
store.save(makeEntry({ id: 'PIT-001', type: 'pitfall', title: 'Pitfall' }));
|
|
102
|
+
const list = store.list({ types: ['decision'] });
|
|
103
|
+
expect(list).toHaveLength(1);
|
|
104
|
+
expect(list[0].type).toBe('decision');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('should filter by maturity', () => {
|
|
108
|
+
store.save(makeEntry({ id: 'DEC-001', maturity: 'draft' }));
|
|
109
|
+
store.save(makeEntry({ id: 'DEC-002', maturity: 'proven', title: 'Proven' }));
|
|
110
|
+
const list = store.list({ maturity: ['proven'] });
|
|
111
|
+
expect(list).toHaveLength(1);
|
|
112
|
+
expect(list[0].maturity).toBe('proven');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should exclude archived by default', () => {
|
|
116
|
+
store.save(makeEntry({ id: 'DEC-001', maturity: 'draft' }));
|
|
117
|
+
store.save(makeEntry({ id: 'DEC-002', maturity: 'archived', title: 'Archived' }));
|
|
118
|
+
const list = store.list();
|
|
119
|
+
expect(list).toHaveLength(1);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('should include archived when excludeArchived is false', () => {
|
|
123
|
+
store.save(makeEntry({ id: 'DEC-001', maturity: 'draft' }));
|
|
124
|
+
store.save(makeEntry({ id: 'DEC-002', maturity: 'archived', title: 'Archived' }));
|
|
125
|
+
const list = store.list({ excludeArchived: false });
|
|
126
|
+
expect(list).toHaveLength(2);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe('delete', () => {
|
|
131
|
+
it('should delete an entry', () => {
|
|
132
|
+
store.save(makeEntry());
|
|
133
|
+
expect(store.delete('DEC-001')).toBe(true);
|
|
134
|
+
expect(store.get('DEC-001')).toBeUndefined();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('should return false for non-existent entry', () => {
|
|
138
|
+
expect(store.delete('NON-EXISTENT')).toBe(false);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
describe('update', () => {
|
|
143
|
+
it('should update specific fields', () => {
|
|
144
|
+
store.save(makeEntry());
|
|
145
|
+
const updated = store.update('DEC-001', { title: 'Updated Title', maturity: 'verified' });
|
|
146
|
+
expect(updated!.title).toBe('Updated Title');
|
|
147
|
+
expect(updated!.maturity).toBe('verified');
|
|
148
|
+
expect(updated!.content).toBe('This is a test decision.'); // unchanged
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('should return undefined for non-existent entry', () => {
|
|
152
|
+
expect(store.update('NON-EXISTENT', { title: 'x' })).toBeUndefined();
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe('rebuildIndex', () => {
|
|
157
|
+
it('should rebuild index from files', () => {
|
|
158
|
+
store.save(makeEntry({ id: 'DEC-001' }));
|
|
159
|
+
store.save(makeEntry({ id: 'DEC-002', title: 'Second' }));
|
|
160
|
+
store.rebuildIndex();
|
|
161
|
+
const list = store.list();
|
|
162
|
+
expect(list).toHaveLength(2);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe('edge cases', () => {
|
|
167
|
+
it('should create directory if it does not exist', () => {
|
|
168
|
+
const newDir = path.join(process.cwd(), 'temp-test-knowledge-nested', 'sub', 'deep');
|
|
169
|
+
const s = new KnowledgeStore({ baseDir: newDir });
|
|
170
|
+
expect(fs.existsSync(newDir)).toBe(true);
|
|
171
|
+
fs.rmSync(path.join(process.cwd(), 'temp-test-knowledge-nested'), { recursive: true, force: true });
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('should handle corrupt index.json gracefully', () => {
|
|
175
|
+
const indexPath = path.join(tempDir, 'index.json');
|
|
176
|
+
fs.writeFileSync(indexPath, 'NOT VALID JSON{{{', 'utf-8');
|
|
177
|
+
// Should not throw, returns empty list
|
|
178
|
+
const list = store.list();
|
|
179
|
+
expect(list).toHaveLength(0);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('should fallback to indexToEntry when file is missing', () => {
|
|
183
|
+
store.save(makeEntry());
|
|
184
|
+
// Delete the .md file but leave index entry
|
|
185
|
+
const mdFiles = fs.readdirSync(tempDir).filter(f => f.endsWith('.md'));
|
|
186
|
+
for (const f of mdFiles) {
|
|
187
|
+
fs.unlinkSync(path.join(tempDir, f));
|
|
188
|
+
}
|
|
189
|
+
const list = store.list();
|
|
190
|
+
expect(list).toHaveLength(1);
|
|
191
|
+
expect(list[0].content).toBe(''); // indexToEntry returns empty content
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('should handle unreadable file gracefully', () => {
|
|
195
|
+
// Write a valid entry
|
|
196
|
+
store.save(makeEntry());
|
|
197
|
+
// Overwrite with content that fails to parse (no frontmatter)
|
|
198
|
+
const mdPath = path.join(tempDir, 'decision-DEC-001.md');
|
|
199
|
+
fs.writeFileSync(mdPath, 'no frontmatter here', 'utf-8');
|
|
200
|
+
const result = store.get('DEC-001');
|
|
201
|
+
expect(result).toBeUndefined();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('should filter by layer', () => {
|
|
205
|
+
store.save(makeEntry({ id: 'DEC-001', layer: 'project' }));
|
|
206
|
+
store.save(makeEntry({ id: 'DEC-002', layer: 'team', title: 'Team' }));
|
|
207
|
+
const list = store.list({ layers: ['team'] });
|
|
208
|
+
expect(list).toHaveLength(1);
|
|
209
|
+
expect(list[0].layer).toBe('team');
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('should filter by tags', () => {
|
|
213
|
+
store.save(makeEntry({ id: 'DEC-001', tags: ['arch', 'db'] }));
|
|
214
|
+
store.save(makeEntry({ id: 'DEC-002', tags: ['perf'], title: 'Perf' }));
|
|
215
|
+
const list = store.list({ tags: ['arch'] });
|
|
216
|
+
expect(list).toHaveLength(1);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('should filter by applicablePhases', () => {
|
|
220
|
+
store.save(makeEntry({ id: 'DEC-001', applicablePhases: ['ARCHITECT'] }));
|
|
221
|
+
store.save(makeEntry({ id: 'DEC-002', applicablePhases: ['IMPLEMENT'], title: 'Impl' }));
|
|
222
|
+
const list = store.list({ applicablePhases: ['IMPLEMENT'] });
|
|
223
|
+
expect(list).toHaveLength(1);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('should save and read back decayAt field', () => {
|
|
227
|
+
store.save(makeEntry({ decayAt: '2027-01-01' }));
|
|
228
|
+
const retrieved = store.get('DEC-001');
|
|
229
|
+
expect(retrieved!.decayAt).toBe('2027-01-01');
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('should exclude decayAt when not set', () => {
|
|
233
|
+
store.save(makeEntry());
|
|
234
|
+
const retrieved = store.get('DEC-001');
|
|
235
|
+
expect(retrieved!.decayAt).toBeUndefined();
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge Doctor — 知识库健康评分
|
|
3
|
+
*
|
|
4
|
+
* 计算整体健康分数,检测需要关注的问题。
|
|
5
|
+
* MonitorAgent 周期性调用,低于 60 分触发 Triage 告警。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { KnowledgeStore } from './store';
|
|
9
|
+
import { KnowledgeLinter } from './lint';
|
|
10
|
+
import type { LintIssue } from './types';
|
|
11
|
+
|
|
12
|
+
export interface HealthDetail {
|
|
13
|
+
category: string;
|
|
14
|
+
score: number;
|
|
15
|
+
message: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface HealthReport {
|
|
19
|
+
score: number;
|
|
20
|
+
details: HealthDetail[];
|
|
21
|
+
totalEntries: number;
|
|
22
|
+
timestamp: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class KnowledgeHealthScorer {
|
|
26
|
+
private store: KnowledgeStore;
|
|
27
|
+
private linter: KnowledgeLinter;
|
|
28
|
+
|
|
29
|
+
constructor(store: KnowledgeStore, linter: KnowledgeLinter) {
|
|
30
|
+
this.store = store;
|
|
31
|
+
this.linter = linter;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Calculate knowledge base health score (0-100).
|
|
36
|
+
*
|
|
37
|
+
* Scoring:
|
|
38
|
+
* - Start at 100
|
|
39
|
+
* - Orphans > 10% → -20
|
|
40
|
+
* - Outdated > 5% → -15
|
|
41
|
+
* - Duplicates > 5% → -25 (high weight)
|
|
42
|
+
* - Contradictions > 0 → -10 each
|
|
43
|
+
* - Index inconsistency → -30
|
|
44
|
+
*/
|
|
45
|
+
healthScore(): HealthReport {
|
|
46
|
+
const entries = this.store.list({ excludeArchived: false });
|
|
47
|
+
const totalEntries = entries.length;
|
|
48
|
+
const report = this.linter.run(false); // don't autoFix, just report
|
|
49
|
+
const details: HealthDetail[] = [];
|
|
50
|
+
let penalty = 0;
|
|
51
|
+
|
|
52
|
+
if (totalEntries === 0) {
|
|
53
|
+
return { score: 100, details: [{ category: 'empty', score: 0, message: 'Knowledge base is empty' }], totalEntries: 0, timestamp: new Date().toISOString() };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Orphans
|
|
57
|
+
const orphanCount = report.summary.orphan;
|
|
58
|
+
const orphanRate = orphanCount / totalEntries;
|
|
59
|
+
if (orphanRate > 0.1) {
|
|
60
|
+
penalty += 20;
|
|
61
|
+
details.push({ category: 'orphans', score: -20, message: `Orphan rate ${(orphanRate * 100).toFixed(0)}% (>10%): ${orphanCount}/${totalEntries}` });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Outdated
|
|
65
|
+
const outdatedCount = report.summary.outdated;
|
|
66
|
+
const outdatedRate = outdatedCount / totalEntries;
|
|
67
|
+
if (outdatedRate > 0.05) {
|
|
68
|
+
penalty += 15;
|
|
69
|
+
details.push({ category: 'outdated', score: -15, message: `Outdated rate ${(outdatedRate * 100).toFixed(0)}% (>5%): ${outdatedCount}/${totalEntries}` });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Duplicates (high weight)
|
|
73
|
+
const dupCount = report.summary.duplicate;
|
|
74
|
+
const dupRate = dupCount / totalEntries;
|
|
75
|
+
if (dupRate > 0.05) {
|
|
76
|
+
penalty += 25;
|
|
77
|
+
details.push({ category: 'duplicates', score: -25, message: `Duplicate rate ${(dupRate * 100).toFixed(0)}% (>5%): ${dupCount}/${totalEntries}` });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Contradictions
|
|
81
|
+
const contradictionCount = report.summary.contradiction;
|
|
82
|
+
if (contradictionCount > 0) {
|
|
83
|
+
const contradictionPenalty = Math.min(contradictionCount * 10, 30);
|
|
84
|
+
penalty += contradictionPenalty;
|
|
85
|
+
details.push({ category: 'contradictions', score: -contradictionPenalty, message: `${contradictionCount} contradictions found` });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Index inconsistency
|
|
89
|
+
const indexCount = report.summary.index_inconsistent;
|
|
90
|
+
if (indexCount > 0) {
|
|
91
|
+
penalty += 30;
|
|
92
|
+
details.push({ category: 'index', score: -30, message: `Index inconsistency: ${indexCount} issues` });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const score = Math.max(0, 100 - penalty);
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
score,
|
|
99
|
+
details,
|
|
100
|
+
totalEntries,
|
|
101
|
+
timestamp: new Date().toISOString(),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|