@dommaker/harness 0.16.6 → 0.16.8
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 +15 -0
- package/README.md +54 -14
- package/bin/harness.js +56 -96
- package/dist/architecture/constraint-engine.d.ts.map +1 -1
- package/dist/architecture/constraint-engine.js +0 -4
- package/dist/architecture/constraint-engine.js.map +1 -1
- package/dist/architecture/cross-project-checker.d.ts.map +1 -1
- package/dist/architecture/cross-project-checker.js +5 -25
- package/dist/architecture/cross-project-checker.js.map +1 -1
- package/dist/cli/commands/analyze-sessions.d.ts +2 -0
- package/dist/cli/commands/analyze-sessions.d.ts.map +1 -1
- package/dist/cli/commands/analyze-sessions.js +25 -181
- package/dist/cli/commands/analyze-sessions.js.map +1 -1
- package/dist/cli/commands/check.d.ts +1 -0
- package/dist/cli/commands/check.d.ts.map +1 -1
- package/dist/cli/commands/check.js +24 -216
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/cli/commands/doc-freshness-check.d.ts.map +1 -1
- package/dist/cli/commands/doc-freshness-check.js +14 -28
- package/dist/cli/commands/doc-freshness-check.js.map +1 -1
- package/dist/cli/commands/flow.d.ts.map +1 -1
- package/dist/cli/commands/flow.js +2 -1
- package/dist/cli/commands/flow.js.map +1 -1
- package/dist/cli/commands/init.js +2 -2
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/posteval-plan.d.ts.map +1 -1
- package/dist/cli/commands/posteval-plan.js +0 -1
- package/dist/cli/commands/posteval-plan.js.map +1 -1
- package/dist/cli/commands/release.js +1 -1
- package/dist/cli/commands/release.js.map +1 -1
- package/dist/cli/commands/report.d.ts.map +1 -1
- package/dist/cli/commands/report.js +2 -0
- package/dist/cli/commands/report.js.map +1 -1
- package/dist/cli/commands/spec-baseline-check.d.ts.map +1 -1
- package/dist/cli/commands/spec-baseline-check.js +12 -23
- package/dist/cli/commands/spec-baseline-check.js.map +1 -1
- package/dist/cli/commands/sync-docs/agents-syncer.d.ts +19 -0
- package/dist/cli/commands/sync-docs/agents-syncer.d.ts.map +1 -0
- package/dist/cli/commands/sync-docs/agents-syncer.js +288 -0
- package/dist/cli/commands/sync-docs/agents-syncer.js.map +1 -0
- package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts +37 -0
- package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts.map +1 -0
- package/dist/cli/commands/sync-docs/capabilities-syncer.js +235 -0
- package/dist/cli/commands/sync-docs/capabilities-syncer.js.map +1 -0
- package/dist/cli/commands/sync-docs/context-syncer.d.ts +17 -0
- package/dist/cli/commands/sync-docs/context-syncer.d.ts.map +1 -0
- package/dist/cli/commands/sync-docs/context-syncer.js +143 -0
- package/dist/cli/commands/sync-docs/context-syncer.js.map +1 -0
- package/dist/cli/commands/{sync-docs.d.ts → sync-docs/index.d.ts} +9 -2
- package/dist/cli/commands/sync-docs/index.d.ts.map +1 -0
- package/dist/cli/commands/sync-docs/index.js +338 -0
- package/dist/cli/commands/sync-docs/index.js.map +1 -0
- package/dist/cli/commands/sync-docs/preserve-block.d.ts +24 -0
- package/dist/cli/commands/sync-docs/preserve-block.d.ts.map +1 -0
- package/dist/cli/commands/sync-docs/preserve-block.js +55 -0
- package/dist/cli/commands/sync-docs/preserve-block.js.map +1 -0
- package/dist/cli/commands/sync-docs/project-reader.d.ts +41 -0
- package/dist/cli/commands/sync-docs/project-reader.d.ts.map +1 -0
- package/dist/cli/commands/sync-docs/project-reader.js +183 -0
- package/dist/cli/commands/sync-docs/project-reader.js.map +1 -0
- package/dist/cli/commands/update-user-model.d.ts +2 -0
- package/dist/cli/commands/update-user-model.d.ts.map +1 -1
- package/dist/cli/commands/update-user-model.js +19 -90
- package/dist/cli/commands/update-user-model.js.map +1 -1
- package/dist/cli/commands/validate.d.ts +3 -0
- package/dist/cli/commands/validate.d.ts.map +1 -1
- package/dist/cli/commands/validate.js +6 -39
- package/dist/cli/commands/validate.js.map +1 -1
- package/dist/cli/session-mining/corrections.d.ts +17 -0
- package/dist/cli/session-mining/corrections.d.ts.map +1 -0
- package/dist/cli/session-mining/corrections.js +58 -0
- package/dist/cli/session-mining/corrections.js.map +1 -0
- package/dist/cli/session-mining/index.d.ts +13 -0
- package/dist/cli/session-mining/index.d.ts.map +1 -0
- package/dist/{core/spec → cli/session-mining}/index.js +9 -3
- package/dist/cli/session-mining/index.js.map +1 -0
- package/dist/cli/session-mining/text.d.ts +31 -0
- package/dist/cli/session-mining/text.d.ts.map +1 -0
- package/dist/cli/session-mining/text.js +126 -0
- package/dist/cli/session-mining/text.js.map +1 -0
- package/dist/cli/session-mining/transcript.d.ts +28 -0
- package/dist/cli/session-mining/transcript.d.ts.map +1 -0
- package/dist/cli/session-mining/transcript.js +123 -0
- package/dist/cli/session-mining/transcript.js.map +1 -0
- package/dist/constraints/lifecycle-runner.d.ts +1 -1
- package/dist/constraints/lifecycle-runner.d.ts.map +1 -1
- package/dist/context/compaction.d.ts.map +1 -1
- package/dist/context/compaction.js +2 -3
- package/dist/context/compaction.js.map +1 -1
- package/dist/context/knowledge-injector.d.ts.map +1 -1
- package/dist/context/tool-output-budget.d.ts +1 -1
- package/dist/context/tool-output-budget.d.ts.map +1 -1
- package/dist/context/tool-output-budget.js +1 -1
- package/dist/context/tool-output-budget.js.map +1 -1
- package/dist/core/constraints/capabilities-parser.d.ts +24 -0
- package/dist/core/constraints/capabilities-parser.d.ts.map +1 -0
- package/dist/core/constraints/capabilities-parser.js +95 -0
- package/dist/core/constraints/capabilities-parser.js.map +1 -0
- package/dist/core/constraints/checker.d.ts +37 -100
- package/dist/core/constraints/checker.d.ts.map +1 -1
- package/dist/core/constraints/checker.js +150 -737
- package/dist/core/constraints/checker.js.map +1 -1
- package/dist/core/constraints/checkers/always-pass.d.ts +17 -0
- package/dist/core/constraints/checkers/always-pass.d.ts.map +1 -0
- package/dist/core/constraints/checkers/always-pass.js +23 -0
- package/dist/core/constraints/checkers/always-pass.js.map +1 -0
- package/dist/core/constraints/checkers/capability-sync.d.ts +10 -0
- package/dist/core/constraints/checkers/capability-sync.d.ts.map +1 -0
- package/dist/core/constraints/checkers/capability-sync.js +60 -0
- package/dist/core/constraints/checkers/capability-sync.js.map +1 -0
- package/dist/core/constraints/checkers/context-doc-sync.d.ts +6 -0
- package/dist/core/constraints/checkers/context-doc-sync.d.ts.map +1 -0
- package/dist/core/constraints/checkers/context-doc-sync.js +35 -0
- package/dist/core/constraints/checkers/context-doc-sync.js.map +1 -0
- package/dist/core/constraints/checkers/docs-freshness.d.ts +10 -0
- package/dist/core/constraints/checkers/docs-freshness.d.ts.map +1 -0
- package/dist/core/constraints/checkers/docs-freshness.js +111 -0
- package/dist/core/constraints/checkers/docs-freshness.js.map +1 -0
- package/dist/core/constraints/checkers/guideline-flags.d.ts +9 -0
- package/dist/core/constraints/checkers/guideline-flags.d.ts.map +1 -0
- package/dist/core/constraints/checkers/guideline-flags.js +13 -0
- package/dist/core/constraints/checkers/guideline-flags.js.map +1 -0
- package/dist/core/constraints/checkers/index.d.ts +17 -0
- package/dist/core/constraints/checkers/index.d.ts.map +1 -0
- package/dist/core/constraints/checkers/index.js +82 -0
- package/dist/core/constraints/checkers/index.js.map +1 -0
- package/dist/core/constraints/checkers/iron-flags.d.ts +14 -0
- package/dist/core/constraints/checkers/iron-flags.d.ts.map +1 -0
- package/dist/core/constraints/checkers/iron-flags.js +24 -0
- package/dist/core/constraints/checkers/iron-flags.js.map +1 -0
- package/dist/core/constraints/checkers/no-any-type.d.ts +6 -0
- package/dist/core/constraints/checkers/no-any-type.d.ts.map +1 -0
- package/dist/core/constraints/checkers/no-any-type.js +42 -0
- package/dist/core/constraints/checkers/no-any-type.js.map +1 -0
- package/dist/core/constraints/checkers/no-bypass-checkpoint.d.ts +6 -0
- package/dist/core/constraints/checkers/no-bypass-checkpoint.d.ts.map +1 -0
- package/dist/core/constraints/checkers/no-bypass-checkpoint.js +40 -0
- package/dist/core/constraints/checkers/no-bypass-checkpoint.js.map +1 -0
- package/dist/core/constraints/checkers/no-excuse-patterns.d.ts +6 -0
- package/dist/core/constraints/checkers/no-excuse-patterns.d.ts.map +1 -0
- package/dist/core/constraints/checkers/no-excuse-patterns.js +25 -0
- package/dist/core/constraints/checkers/no-excuse-patterns.js.map +1 -0
- package/dist/core/constraints/checkers/no-fuzzy-completion-claim.d.ts +6 -0
- package/dist/core/constraints/checkers/no-fuzzy-completion-claim.d.ts.map +1 -0
- package/dist/core/constraints/checkers/no-fuzzy-completion-claim.js +34 -0
- package/dist/core/constraints/checkers/no-fuzzy-completion-claim.js.map +1 -0
- package/dist/core/constraints/checkers/no-performative-agreement.d.ts +8 -0
- package/dist/core/constraints/checkers/no-performative-agreement.d.ts.map +1 -0
- package/dist/core/constraints/checkers/no-performative-agreement.js +23 -0
- package/dist/core/constraints/checkers/no-performative-agreement.js.map +1 -0
- package/dist/core/constraints/checkers/no-simplification-without-approval.d.ts +6 -0
- package/dist/core/constraints/checkers/no-simplification-without-approval.d.ts.map +1 -0
- package/dist/core/constraints/checkers/no-simplification-without-approval.js +30 -0
- package/dist/core/constraints/checkers/no-simplification-without-approval.js.map +1 -0
- package/dist/core/constraints/checkers/no-test-simplification.d.ts +6 -0
- package/dist/core/constraints/checkers/no-test-simplification.d.ts.map +1 -0
- package/dist/core/constraints/checkers/no-test-simplification.js +29 -0
- package/dist/core/constraints/checkers/no-test-simplification.js.map +1 -0
- package/dist/core/constraints/checkers/test-coverage.d.ts +6 -0
- package/dist/core/constraints/checkers/test-coverage.d.ts.map +1 -0
- package/dist/core/constraints/checkers/test-coverage.js +33 -0
- package/dist/core/constraints/checkers/test-coverage.js.map +1 -0
- package/dist/core/constraints/checkers/types.d.ts +43 -0
- package/dist/core/constraints/checkers/types.d.ts.map +1 -0
- package/dist/core/constraints/checkers/types.js +23 -0
- package/dist/core/constraints/checkers/types.js.map +1 -0
- package/dist/core/constraints/checkers/yagni.d.ts +8 -0
- package/dist/core/constraints/checkers/yagni.d.ts.map +1 -0
- package/dist/core/constraints/checkers/yagni.js +96 -0
- package/dist/core/constraints/checkers/yagni.js.map +1 -0
- package/dist/core/constraints/context-builder.d.ts +67 -0
- package/dist/core/constraints/context-builder.d.ts.map +1 -0
- package/dist/core/constraints/context-builder.js +294 -0
- package/dist/core/constraints/context-builder.js.map +1 -0
- package/dist/core/constraints/definitions/guidelines.d.ts +7 -0
- package/dist/core/constraints/definitions/guidelines.d.ts.map +1 -0
- package/dist/core/constraints/definitions/guidelines.js +641 -0
- package/dist/core/constraints/definitions/guidelines.js.map +1 -0
- package/dist/core/constraints/definitions/iron-laws.d.ts +7 -0
- package/dist/core/constraints/definitions/iron-laws.d.ts.map +1 -0
- package/dist/core/constraints/definitions/iron-laws.js +322 -0
- package/dist/core/constraints/definitions/iron-laws.js.map +1 -0
- package/dist/core/constraints/definitions/tips.d.ts +7 -0
- package/dist/core/constraints/definitions/tips.d.ts.map +1 -0
- package/dist/core/constraints/definitions/tips.js +62 -0
- package/dist/core/constraints/definitions/tips.js.map +1 -0
- package/dist/core/constraints/definitions.d.ts +8 -21
- package/dist/core/constraints/definitions.d.ts.map +1 -1
- package/dist/core/constraints/definitions.js +15 -1048
- package/dist/core/constraints/definitions.js.map +1 -1
- package/dist/core/constraints/doc-freshness/runner.d.ts.map +1 -1
- package/dist/core/constraints/doc-freshness/runner.js +0 -1
- package/dist/core/constraints/doc-freshness/runner.js.map +1 -1
- package/dist/core/constraints/index.d.ts +4 -5
- package/dist/core/constraints/index.d.ts.map +1 -1
- package/dist/core/constraints/index.js +1 -16
- package/dist/core/constraints/index.js.map +1 -1
- package/dist/core/constraints/interceptor.d.ts.map +1 -1
- package/dist/core/constraints/interceptor.js.map +1 -1
- package/dist/core/index.js +0 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/project-config-loader.d.ts +6 -4
- package/dist/core/project-config-loader.d.ts.map +1 -1
- package/dist/core/project-config-loader.js +46 -13
- package/dist/core/project-config-loader.js.map +1 -1
- package/dist/core/validators/check-handlers/command.d.ts +7 -0
- package/dist/core/validators/check-handlers/command.d.ts.map +1 -0
- package/dist/core/validators/check-handlers/command.js +58 -0
- package/dist/core/validators/check-handlers/command.js.map +1 -0
- package/dist/core/validators/check-handlers/file.d.ts +10 -0
- package/dist/core/validators/check-handlers/file.d.ts.map +1 -0
- package/dist/core/validators/check-handlers/file.js +128 -0
- package/dist/core/validators/check-handlers/file.js.map +1 -0
- package/dist/core/validators/check-handlers/http.d.ts +7 -0
- package/dist/core/validators/check-handlers/http.d.ts.map +1 -0
- package/dist/core/validators/check-handlers/http.js +88 -0
- package/dist/core/validators/check-handlers/http.js.map +1 -0
- package/dist/core/validators/check-handlers/output.d.ts +15 -0
- package/dist/core/validators/check-handlers/output.d.ts.map +1 -0
- package/dist/core/validators/check-handlers/output.js +152 -0
- package/dist/core/validators/check-handlers/output.js.map +1 -0
- package/dist/core/validators/checkpoint.d.ts +4 -72
- package/dist/core/validators/checkpoint.d.ts.map +1 -1
- package/dist/core/validators/checkpoint.js +21 -400
- package/dist/core/validators/checkpoint.js.map +1 -1
- package/dist/core/validators/cso.js +1 -1
- package/dist/core/validators/cso.js.map +1 -1
- package/dist/core/validators/passes-gate.js +2 -2
- package/dist/core/validators/passes-gate.js.map +1 -1
- package/dist/dashboard/stats.d.ts.map +1 -1
- package/dist/dashboard/types.d.ts.map +1 -1
- package/dist/evolution/auto-evolve.d.ts +1 -2
- package/dist/evolution/auto-evolve.d.ts.map +1 -1
- package/dist/evolution/auto-evolve.js +2 -1
- package/dist/evolution/auto-evolve.js.map +1 -1
- package/dist/failure/types.d.ts +5 -85
- package/dist/failure/types.d.ts.map +1 -1
- package/dist/failure/types.js +19 -115
- package/dist/failure/types.js.map +1 -1
- package/dist/gates/contract.d.ts.map +1 -1
- package/dist/gates/contract.js.map +1 -1
- package/dist/gates/index.d.ts.map +1 -1
- package/dist/gates/index.js.map +1 -1
- package/dist/gates/performance.js +1 -1
- package/dist/gates/performance.js.map +1 -1
- package/dist/gates/security.d.ts.map +1 -1
- package/dist/gates/security.js +1 -1
- package/dist/gates/security.js.map +1 -1
- package/dist/hooks/bootstrap.d.ts.map +1 -1
- package/dist/hooks/bootstrap.js +6 -48
- package/dist/hooks/bootstrap.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/knowledge/audit.d.ts.map +1 -1
- package/dist/knowledge/doctor.d.ts.map +1 -1
- package/dist/knowledge/doctor.js.map +1 -1
- package/dist/knowledge/import.d.ts.map +1 -1
- package/dist/knowledge/import.js +1 -1
- package/dist/knowledge/import.js.map +1 -1
- package/dist/knowledge/index-generator.d.ts.map +1 -1
- package/dist/knowledge/index-generator.js +0 -1
- package/dist/knowledge/index-generator.js.map +1 -1
- package/dist/knowledge/ingest.d.ts.map +1 -1
- package/dist/knowledge/ingest.js +1 -1
- package/dist/knowledge/ingest.js.map +1 -1
- package/dist/knowledge/lint.d.ts +1 -1
- package/dist/knowledge/lint.d.ts.map +1 -1
- package/dist/knowledge/lint.js +2 -2
- package/dist/knowledge/lint.js.map +1 -1
- package/dist/knowledge/primitives/code-structure.d.ts.map +1 -1
- package/dist/knowledge/primitives/code-structure.js +29 -12
- package/dist/knowledge/primitives/code-structure.js.map +1 -1
- package/dist/knowledge/query.d.ts.map +1 -1
- package/dist/knowledge/query.js.map +1 -1
- package/dist/knowledge/store.d.ts.map +1 -1
- package/dist/llm/adapter.d.ts +3 -3
- package/dist/llm/adapter.d.ts.map +1 -1
- package/dist/llm/adapter.js +3 -3
- package/dist/llm/adapter.js.map +1 -1
- package/dist/monitoring/analyzer-base.d.ts +50 -0
- package/dist/monitoring/analyzer-base.d.ts.map +1 -0
- package/dist/monitoring/analyzer-base.js +146 -0
- package/dist/monitoring/analyzer-base.js.map +1 -0
- package/dist/monitoring/constraint-doctor.d.ts +3 -46
- package/dist/monitoring/constraint-doctor.d.ts.map +1 -1
- package/dist/monitoring/constraint-doctor.js +11 -113
- package/dist/monitoring/constraint-doctor.js.map +1 -1
- package/dist/monitoring/constraint-evolver.d.ts +9 -63
- package/dist/monitoring/constraint-evolver.d.ts.map +1 -1
- package/dist/monitoring/constraint-evolver.js +8 -10
- package/dist/monitoring/constraint-evolver.js.map +1 -1
- package/dist/monitoring/diagnosis-rules.d.ts +18 -0
- package/dist/monitoring/diagnosis-rules.d.ts.map +1 -0
- package/dist/monitoring/diagnosis-rules.js +119 -0
- package/dist/monitoring/diagnosis-rules.js.map +1 -0
- package/dist/monitoring/knowledge-doctor.d.ts.map +1 -1
- package/dist/monitoring/knowledge-doctor.js.map +1 -1
- package/dist/monitoring/performance-analyzer.d.ts +0 -12
- package/dist/monitoring/performance-analyzer.d.ts.map +1 -1
- package/dist/monitoring/performance-analyzer.js +13 -93
- package/dist/monitoring/performance-analyzer.js.map +1 -1
- package/dist/monitoring/performance-collector.d.ts +0 -8
- package/dist/monitoring/performance-collector.d.ts.map +1 -1
- package/dist/monitoring/performance-collector.js +0 -21
- package/dist/monitoring/performance-collector.js.map +1 -1
- package/dist/monitoring/trace-analyzer.d.ts +0 -8
- package/dist/monitoring/trace-analyzer.d.ts.map +1 -1
- package/dist/monitoring/trace-analyzer.js +9 -91
- package/dist/monitoring/trace-analyzer.js.map +1 -1
- package/dist/presets/index.d.ts +1 -1
- package/dist/presets/index.d.ts.map +1 -1
- package/dist/presets/index.js +1 -4
- package/dist/presets/index.js.map +1 -1
- package/dist/presets/standard.d.ts +0 -9
- package/dist/presets/standard.d.ts.map +1 -1
- package/dist/presets/standard.js +1 -16
- package/dist/presets/standard.js.map +1 -1
- package/dist/safety/output-guardrail.d.ts +0 -1
- package/dist/safety/output-guardrail.d.ts.map +1 -1
- package/dist/safety/output-guardrail.js +0 -3
- package/dist/safety/output-guardrail.js.map +1 -1
- package/dist/tools/registry.d.ts.map +1 -1
- package/dist/types/constraint.d.ts +5 -59
- package/dist/types/constraint.d.ts.map +1 -1
- package/dist/types/constraint.js +1 -39
- package/dist/types/constraint.js.map +1 -1
- package/dist/types/failure.d.ts +89 -0
- package/dist/types/failure.d.ts.map +1 -0
- package/dist/types/failure.js +121 -0
- package/dist/types/failure.js.map +1 -0
- package/dist/types/index.d.ts +2 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +7 -6
- package/dist/types/index.js.map +1 -1
- package/dist/types/monitoring-types.d.ts +114 -0
- package/dist/types/monitoring-types.d.ts.map +1 -0
- package/dist/types/monitoring-types.js +10 -0
- package/dist/types/monitoring-types.js.map +1 -0
- package/dist/utils/detect-source-roots.js.map +1 -1
- package/dist/utils/file-walk.d.ts +33 -0
- package/dist/utils/file-walk.d.ts.map +1 -0
- package/dist/utils/file-walk.js +89 -0
- package/dist/utils/file-walk.js.map +1 -0
- package/dist/verification/rules-based.d.ts.map +1 -1
- package/dist/verification/rules-based.js.map +1 -1
- package/package.json +3 -7
- package/src/__tests__/checker-extra.test.ts +0 -30
- package/src/__tests__/checker.test.ts +0 -33
- package/src/__tests__/checkpoint.test.ts +46 -46
- package/src/__tests__/constraint-evolver.test.ts +22 -21
- package/src/__tests__/doctor-evolver.test.ts +3 -3
- package/src/__tests__/iron-laws.test.ts +0 -27
- package/src/__tests__/presets.test.ts +1 -40
- package/src/architecture/constraint-engine.ts +0 -5
- package/src/architecture/cross-project-checker.ts +6 -24
- package/src/cli/commands/__tests__/check.test.ts +3 -1
- package/src/cli/commands/__tests__/sync-docs.test.ts +77 -0
- package/src/cli/commands/__tests__/validate.test.ts +5 -0
- package/src/cli/commands/analyze-sessions.ts +31 -185
- package/src/cli/commands/check.ts +26 -225
- package/src/cli/commands/doc-freshness-check.ts +14 -25
- package/src/cli/commands/flow.ts +5 -3
- package/src/cli/commands/init.ts +3 -3
- package/src/cli/commands/posteval-plan.ts +0 -1
- package/src/cli/commands/release.ts +1 -1
- package/src/cli/commands/report.ts +2 -0
- package/src/cli/commands/spec-baseline-check.ts +12 -19
- package/src/cli/commands/sync-docs/agents-syncer.ts +280 -0
- package/src/cli/commands/sync-docs/capabilities-syncer.ts +229 -0
- package/src/cli/commands/sync-docs/context-syncer.ts +108 -0
- package/src/cli/commands/sync-docs/index.ts +355 -0
- package/src/cli/commands/sync-docs/preserve-block.ts +59 -0
- package/src/cli/commands/sync-docs/project-reader.ts +163 -0
- package/src/cli/commands/update-user-model.ts +23 -87
- package/src/cli/commands/validate.ts +6 -40
- package/src/cli/session-mining/corrections.ts +56 -0
- package/src/cli/session-mining/index.ts +13 -0
- package/src/cli/session-mining/text.ts +117 -0
- package/src/cli/session-mining/transcript.ts +107 -0
- package/src/constraints/__tests__/lifecycle-runner.test.ts +1 -1
- package/src/constraints/lifecycle-runner.ts +1 -1
- package/src/context/compaction.ts +2 -3
- package/src/context/knowledge-injector.ts +1 -1
- package/src/context/tool-output-budget.ts +1 -1
- package/src/core/constraints/capabilities-parser.ts +70 -0
- package/src/core/constraints/checker.ts +170 -779
- package/src/core/constraints/checkers/always-pass.ts +22 -0
- package/src/core/constraints/checkers/capability-sync.ts +71 -0
- package/src/core/constraints/checkers/context-doc-sync.ts +36 -0
- package/src/core/constraints/checkers/docs-freshness.ts +116 -0
- package/src/core/constraints/checkers/guideline-flags.ts +30 -0
- package/src/core/constraints/checkers/index.ts +114 -0
- package/src/core/constraints/checkers/iron-flags.ts +62 -0
- package/src/core/constraints/checkers/no-any-type.ts +42 -0
- package/src/core/constraints/checkers/no-bypass-checkpoint.ts +40 -0
- package/src/core/constraints/checkers/no-excuse-patterns.ts +24 -0
- package/src/core/constraints/checkers/no-fuzzy-completion-claim.ts +33 -0
- package/src/core/constraints/checkers/no-performative-agreement.ts +22 -0
- package/src/core/constraints/checkers/no-simplification-without-approval.ts +29 -0
- package/src/core/constraints/checkers/no-test-simplification.ts +28 -0
- package/src/core/constraints/checkers/test-coverage.ts +35 -0
- package/src/core/constraints/checkers/types.ts +54 -0
- package/src/core/constraints/checkers/yagni.ts +65 -0
- package/src/core/constraints/context-builder.ts +262 -0
- package/src/core/constraints/definitions/guidelines.ts +668 -0
- package/src/core/constraints/definitions/iron-laws.ts +333 -0
- package/src/core/constraints/definitions/tips.ts +63 -0
- package/src/core/constraints/definitions.ts +9 -1086
- package/src/core/constraints/doc-freshness/runner.ts +2 -3
- package/src/core/constraints/index.ts +1 -27
- package/src/core/constraints/interceptor.ts +0 -2
- package/src/core/index.ts +1 -1
- package/src/core/project-config-loader.ts +49 -13
- package/src/core/validators/check-handlers/command.ts +58 -0
- package/src/core/validators/check-handlers/file.ts +104 -0
- package/src/core/validators/check-handlers/http.ts +88 -0
- package/src/core/validators/check-handlers/output.ts +165 -0
- package/src/core/validators/checkpoint.ts +32 -407
- package/src/core/validators/cso.ts +1 -1
- package/src/core/validators/passes-gate.ts +2 -2
- package/src/dashboard/stats.ts +1 -1
- package/src/dashboard/types.ts +1 -1
- package/src/evolution/__tests__/auto-evolve.test.ts +1 -2
- package/src/evolution/auto-evolve.ts +3 -3
- package/src/failure/types.ts +5 -161
- package/src/gates/contract.ts +0 -1
- package/src/gates/index.ts +0 -2
- package/src/gates/performance.ts +1 -1
- package/src/gates/security.ts +1 -3
- package/src/hooks/bootstrap.ts +6 -16
- package/src/index.ts +4 -1
- package/src/knowledge/__tests__/lifecycle.test.ts +4 -1
- package/src/knowledge/audit.ts +1 -1
- package/src/knowledge/doctor.ts +0 -1
- package/src/knowledge/import.ts +2 -2
- package/src/knowledge/index-generator.ts +0 -1
- package/src/knowledge/ingest.ts +1 -2
- package/src/knowledge/lint.ts +2 -2
- package/src/knowledge/primitives/__tests__/code-structure-degrade.test.ts +24 -0
- package/src/knowledge/primitives/code-structure.ts +36 -12
- package/src/knowledge/query.ts +0 -3
- package/src/knowledge/store.ts +1 -1
- package/src/llm/adapter.ts +3 -3
- package/src/monitoring/analyzer-base.ts +112 -0
- package/src/monitoring/constraint-doctor.ts +14 -175
- package/src/monitoring/constraint-evolver.ts +20 -92
- package/src/monitoring/diagnosis-rules.ts +132 -0
- package/src/monitoring/knowledge-doctor.ts +0 -1
- package/src/monitoring/performance-analyzer.ts +22 -72
- package/src/monitoring/performance-collector.ts +0 -22
- package/src/monitoring/trace-analyzer.ts +17 -73
- package/src/presets/__tests__/standard.test.ts +2 -17
- package/src/presets/index.ts +1 -3
- package/src/presets/standard.ts +1 -26
- package/src/safety/output-guardrail.ts +0 -4
- package/src/tools/registry.ts +1 -1
- package/src/types/__tests__/types.test.ts +1 -33
- package/src/types/constraint.ts +6 -75
- package/src/types/failure.ts +165 -0
- package/src/types/index.ts +7 -5
- package/src/types/monitoring-types.ts +150 -0
- package/src/utils/detect-source-roots.ts +1 -1
- package/src/utils/file-walk.ts +78 -0
- package/src/verification/rules-based.ts +0 -1
- package/bin/harness-knowledge-capture.js +0 -99
- package/bin/harness-knowledge-check.js +0 -164
- package/bin/harness-knowledge-track.js +0 -118
- package/dist/cli/commands/sync-docs.d.ts.map +0 -1
- package/dist/cli/commands/sync-docs.js +0 -1074
- package/dist/cli/commands/sync-docs.js.map +0 -1
- package/dist/constraints/index.d.ts +0 -4
- package/dist/constraints/index.d.ts.map +0 -1
- package/dist/constraints/index.js +0 -20
- package/dist/constraints/index.js.map +0 -1
- package/dist/core/constraints/doc-freshness/auto-fix.d.ts +0 -23
- package/dist/core/constraints/doc-freshness/auto-fix.d.ts.map +0 -1
- package/dist/core/constraints/doc-freshness/auto-fix.js +0 -59
- package/dist/core/constraints/doc-freshness/auto-fix.js.map +0 -1
- package/dist/core/constraints/prompt-injection.d.ts +0 -16
- package/dist/core/constraints/prompt-injection.d.ts.map +0 -1
- package/dist/core/constraints/prompt-injection.js +0 -69
- package/dist/core/constraints/prompt-injection.js.map +0 -1
- package/dist/core/spec/index.d.ts +0 -7
- package/dist/core/spec/index.d.ts.map +0 -1
- package/dist/core/spec/index.js.map +0 -1
- package/dist/governance/executor.d.ts +0 -45
- package/dist/governance/executor.d.ts.map +0 -1
- package/dist/governance/executor.js +0 -243
- package/dist/governance/executor.js.map +0 -1
- package/dist/governance/index.d.ts +0 -9
- package/dist/governance/index.d.ts.map +0 -1
- package/dist/governance/index.js +0 -13
- package/dist/governance/index.js.map +0 -1
- package/dist/governance/types.d.ts +0 -46
- package/dist/governance/types.d.ts.map +0 -1
- package/dist/governance/types.js +0 -9
- package/dist/governance/types.js.map +0 -1
- package/dist/tools/definitions/definitions/core/code/fingerprint.sh +0 -273
- package/dist/tools/definitions/definitions/core/code/fingerprint.yml +0 -72
- package/dist/tools/definitions/definitions/core/code/parse.yml +0 -68
- package/dist/tools/definitions/definitions/core/code/register-language.sh +0 -475
- package/dist/tools/definitions/definitions/core/code/register-language.yml +0 -74
- package/dist/tools/definitions/definitions/core/docker/build.yml +0 -73
- package/dist/tools/definitions/definitions/core/docker/run.yml +0 -81
- package/dist/tools/definitions/definitions/core/file/copy.yml +0 -88
- package/dist/tools/definitions/definitions/core/file/read.yml +0 -69
- package/dist/tools/definitions/definitions/core/file/write.yml +0 -75
- package/dist/tools/definitions/definitions/core/git/branch.yml +0 -61
- package/dist/tools/definitions/definitions/core/git/cleanup-worktree.yml +0 -50
- package/dist/tools/definitions/definitions/core/git/clone.yml +0 -69
- package/dist/tools/definitions/definitions/core/git/commit.yml +0 -65
- package/dist/tools/definitions/definitions/core/git/push.yml +0 -79
- package/dist/tools/definitions/definitions/core/git/worktree.yml +0 -96
- package/dist/tools/definitions/definitions/core/notification/notify.sh +0 -152
- package/dist/tools/definitions/definitions/core/notification/notify.yml +0 -60
- package/dist/tools/definitions/definitions/core/npm/build.yml +0 -75
- package/dist/tools/definitions/definitions/core/npm/install.yml +0 -58
- package/dist/tools/definitions/definitions/core/npm/test.yml +0 -75
- package/dist/tools/definitions/definitions/core/validation/check-reuse.yml +0 -170
- package/dist/tools/definitions/definitions/core/validation/validate-handlers.yml +0 -118
- package/dist/tools/definitions/definitions/core/validation/validate-readme-stats.yml +0 -155
- package/dist/tools/definitions/definitions/core/validation/validate-yaml-syntax.yml +0 -134
- package/dist/tools/definitions/definitions/ext/browser/browser-automate.sh +0 -255
- package/dist/tools/definitions/definitions/ext/browser/browser-automate.yml +0 -166
- package/dist/tools/definitions/definitions/ext/browser/browser-close.sh +0 -104
- package/dist/tools/definitions/definitions/ext/browser/browser-close.yml +0 -55
- package/dist/tools/definitions/definitions/ext/browser/browser-mcp-debug.sh +0 -682
- package/dist/tools/definitions/definitions/ext/browser/browser-mcp-debug.yml +0 -167
- package/dist/tools/definitions/definitions/ext/browser/browser-start.sh +0 -101
- package/dist/tools/definitions/definitions/ext/browser/browser-start.yml +0 -62
- package/dist/tools/definitions/definitions/registry.json +0 -795
- package/dist/tools/definitions/definitions/std/README.md +0 -350
- package/dist/tools/definitions/definitions/std/analysis/analyze-codebase.yml +0 -72
- package/dist/tools/definitions/definitions/std/analysis/analyze-diff.yml +0 -182
- package/dist/tools/definitions/definitions/std/analysis/analyze-git-diff.yml +0 -70
- package/dist/tools/definitions/definitions/std/analysis/analyze-impact.yml +0 -78
- package/dist/tools/definitions/definitions/std/analysis/analyze-requirements.yml +0 -105
- package/dist/tools/definitions/definitions/std/analysis/brainstorm-options.yml +0 -106
- package/dist/tools/definitions/definitions/std/analysis/build-graph.yml +0 -154
- package/dist/tools/definitions/definitions/std/analysis/clarify-requirements.yml +0 -90
- package/dist/tools/definitions/definitions/std/analysis/detect-context.yml +0 -109
- package/dist/tools/definitions/definitions/std/analysis/detect-layers.yml +0 -125
- package/dist/tools/definitions/definitions/std/analysis/generate-tour.yml +0 -102
- package/dist/tools/definitions/definitions/std/analysis/search-enhance.yml +0 -105
- package/dist/tools/definitions/definitions/std/backlog/add.yml +0 -51
- package/dist/tools/definitions/definitions/std/backlog/decide.yml +0 -39
- package/dist/tools/definitions/definitions/std/backlog/github-sync.yml +0 -161
- package/dist/tools/definitions/definitions/std/backlog/list.yml +0 -53
- package/dist/tools/definitions/definitions/std/backlog/load.yml +0 -46
- package/dist/tools/definitions/definitions/std/backlog/resolve.yml +0 -37
- package/dist/tools/definitions/definitions/std/backlog/update.yml +0 -42
- package/dist/tools/definitions/definitions/std/bugfix/diagnose.yml +0 -68
- package/dist/tools/definitions/definitions/std/bugfix/fix.yml +0 -66
- package/dist/tools/definitions/definitions/std/bugfix/verify.yml +0 -69
- package/dist/tools/definitions/definitions/std/constraint/check-decomposition.yml +0 -103
- package/dist/tools/definitions/definitions/std/constraint/check-feature-list.yml +0 -77
- package/dist/tools/definitions/definitions/std/constraint/check-progress.yml +0 -97
- package/dist/tools/definitions/definitions/std/constraint/generate-report.yml +0 -147
- package/dist/tools/definitions/definitions/std/deploy/commit-push.yml +0 -33
- package/dist/tools/definitions/definitions/std/deploy/deploy-backend.yml +0 -37
- package/dist/tools/definitions/definitions/std/deploy/deploy-frontend.yml +0 -37
- package/dist/tools/definitions/definitions/std/deploy/rollback.yml +0 -148
- package/dist/tools/definitions/definitions/std/design/analyze-architecture-impact.yml +0 -113
- package/dist/tools/definitions/definitions/std/design/design-api.yml +0 -55
- package/dist/tools/definitions/definitions/std/design/design-architecture.yml +0 -97
- package/dist/tools/definitions/definitions/std/design/design-db.yml +0 -81
- package/dist/tools/definitions/definitions/std/design/generate-spec.yml +0 -182
- package/dist/tools/definitions/definitions/std/development/develop-api.yml +0 -85
- package/dist/tools/definitions/definitions/std/development/develop-backend.yml +0 -88
- package/dist/tools/definitions/definitions/std/development/develop-frontend.yml +0 -87
- package/dist/tools/definitions/definitions/std/development/develop-shared-types.yml +0 -74
- package/dist/tools/definitions/definitions/std/development/develop-task.yml +0 -122
- package/dist/tools/definitions/definitions/std/development/develop-tests.yml +0 -76
- package/dist/tools/definitions/definitions/std/development/execute-batch.yml +0 -152
- package/dist/tools/definitions/definitions/std/development/fix-issues.yml +0 -100
- package/dist/tools/definitions/definitions/std/development/implement-task.yml +0 -124
- package/dist/tools/definitions/definitions/std/development/review-fix-cycle.yml +0 -232
- package/dist/tools/definitions/definitions/std/evolution/implement.yml +0 -125
- package/dist/tools/definitions/definitions/std/evolution/prioritize.yml +0 -112
- package/dist/tools/definitions/definitions/std/evolution/report-gap.yml +0 -166
- package/dist/tools/definitions/definitions/std/file/read.yml +0 -21
- package/dist/tools/definitions/definitions/std/governance/aggregate-opinions.sh +0 -201
- package/dist/tools/definitions/definitions/std/governance/aggregate-opinions.yml +0 -79
- package/dist/tools/definitions/definitions/std/governance/audit-task.yml +0 -178
- package/dist/tools/definitions/definitions/std/governance/cast-vote.yml +0 -129
- package/dist/tools/definitions/definitions/std/governance/collect-issues.yml +0 -16
- package/dist/tools/definitions/definitions/std/governance/create-signed-document.yml +0 -23
- package/dist/tools/definitions/definitions/std/governance/create-voting-session.yml +0 -101
- package/dist/tools/definitions/definitions/std/governance/define-stance.sh +0 -243
- package/dist/tools/definitions/definitions/std/governance/define-stance.yml +0 -82
- package/dist/tools/definitions/definitions/std/governance/generate-review-report.yml +0 -23
- package/dist/tools/definitions/definitions/std/governance/impeach.yml +0 -179
- package/dist/tools/definitions/definitions/std/governance/multi-stance-review.yml +0 -154
- package/dist/tools/definitions/definitions/std/governance/prepare-artifact.yml +0 -20
- package/dist/tools/definitions/definitions/std/governance/review-spec-approval.yml +0 -262
- package/dist/tools/definitions/definitions/std/governance/rollback.yml +0 -186
- package/dist/tools/definitions/definitions/std/governance/stance-review.yml +0 -149
- package/dist/tools/definitions/definitions/std/governance/track-effect.yml +0 -199
- package/dist/tools/definitions/definitions/std/governance/vote-tally.yml +0 -144
- package/dist/tools/definitions/definitions/std/patch/execute.yml +0 -51
- package/dist/tools/definitions/definitions/std/planning/generate-tasks.yml +0 -36
- package/dist/tools/definitions/definitions/std/planning/load-tasks.yml +0 -44
- package/dist/tools/definitions/definitions/std/planning/split-batch.yml +0 -481
- package/dist/tools/definitions/definitions/std/planning/split-tasks.yml +0 -359
- package/dist/tools/definitions/definitions/std/planning/update-tasks.yml +0 -51
- package/dist/tools/definitions/definitions/std/planning/validate-tasks.yml +0 -46
- package/dist/tools/definitions/definitions/std/project/decide-next-workflow.yml +0 -38
- package/dist/tools/definitions/definitions/std/project/load-state.yml +0 -31
- package/dist/tools/definitions/definitions/std/project/save-state.yml +0 -32
- package/dist/tools/definitions/definitions/std/quality/check-quality.yml +0 -241
- package/dist/tools/definitions/definitions/std/quality/debug-systematic.yml +0 -163
- package/dist/tools/definitions/definitions/std/quality/handle-feedback.yml +0 -108
- package/dist/tools/definitions/definitions/std/quality/review-code.yml +0 -128
- package/dist/tools/definitions/definitions/std/quality/review-spec.yml +0 -140
- package/dist/tools/definitions/definitions/std/quality/review-task.yml +0 -190
- package/dist/tools/definitions/definitions/std/quality/run-tests.yml +0 -80
- package/dist/tools/definitions/definitions/std/quick/analyze.yml +0 -56
- package/dist/tools/definitions/definitions/std/quick/implement.yml +0 -67
- package/dist/tools/definitions/definitions/std/quick/verify.yml +0 -71
- package/dist/tools/definitions/definitions/std/verification/verify_completion.yml +0 -113
- package/dist/tools/definitions/definitions/std/verification/wait-condition.yml +0 -107
- package/dist/types/iron-law.d.ts +0 -25
- package/dist/types/iron-law.d.ts.map +0 -1
- package/dist/types/iron-law.js +0 -16
- package/dist/types/iron-law.js.map +0 -1
- package/src/cli/commands/sync-docs.ts +0 -1175
- package/src/constraints/index.ts +0 -3
- package/src/core/constraints/__tests__/prompt-injection.test.ts +0 -89
- package/src/core/constraints/doc-freshness/auto-fix.ts +0 -69
- package/src/core/constraints/prompt-injection.ts +0 -73
- package/src/core/spec/index.ts +0 -7
- package/src/governance/CONTEXT.md +0 -22
- package/src/governance/__tests__/executor.test.ts +0 -249
- package/src/governance/executor.ts +0 -229
- package/src/governance/index.ts +0 -13
- package/src/governance/types.ts +0 -53
- package/src/tools/core/package.json +0 -7
- package/src/tools/core/pnpm-lock.yaml +0 -232
- package/src/types/iron-law.ts +0 -50
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AGENTS.md 同步器(工单 22):agent 导读生成(项目简介/目录结构/常用命令/约束治理/知识入口)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as fs from 'fs/promises';
|
|
6
|
+
import { existsSync } from 'fs';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import { loadRawProjectConfig } from '../../../core/project-config-loader';
|
|
9
|
+
import {
|
|
10
|
+
readPackageJsonLite,
|
|
11
|
+
getConfigDescription,
|
|
12
|
+
detectPackageManager,
|
|
13
|
+
formatScriptCommand,
|
|
14
|
+
} from './project-reader';
|
|
15
|
+
|
|
16
|
+
/** 生成 AGENTS.md 目录结构表时跳过的目录(依赖/构建产物/报告等) */
|
|
17
|
+
const AGENTS_MD_SKIP_DIRS = new Set([
|
|
18
|
+
'node_modules', 'dist', 'build', 'out', 'coverage',
|
|
19
|
+
'playwright-report', 'test-results', '.git', '.next', '.turbo',
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
/** 知名顶层目录的一句话说明 */
|
|
23
|
+
const AGENTS_MD_DIR_ROLES: Record<string, string> = {
|
|
24
|
+
docs: '项目文档',
|
|
25
|
+
scripts: '工具脚本',
|
|
26
|
+
tests: '测试',
|
|
27
|
+
test: '测试',
|
|
28
|
+
bin: '可执行入口/脚本',
|
|
29
|
+
templates: '项目模板',
|
|
30
|
+
'.github': 'CI/CD 配置',
|
|
31
|
+
'.harness': 'harness 配置与运行时状态',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** 常用命令候选(按展示顺序),仅列出 package.json 中实际存在的脚本 */
|
|
35
|
+
const AGENTS_MD_COMMANDS: Array<[string, string]> = [
|
|
36
|
+
['dev', '启动开发环境'],
|
|
37
|
+
['build', '构建'],
|
|
38
|
+
['test', '运行测试'],
|
|
39
|
+
['test:e2e', '端到端测试'],
|
|
40
|
+
['test:unit', '单元测试'],
|
|
41
|
+
['typecheck', '类型检查'],
|
|
42
|
+
['lint', '代码检查'],
|
|
43
|
+
['start', '启动生产服务'],
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
export interface GovernanceInfo {
|
|
47
|
+
hasConfig: boolean;
|
|
48
|
+
preset?: string;
|
|
49
|
+
hasClaudeGovernance: boolean;
|
|
50
|
+
ironLaws?: number;
|
|
51
|
+
guidelines?: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 生成 AGENTS.md 内容(agent 导读:项目简介/目录结构/常用命令/约束治理/知识入口)
|
|
56
|
+
*
|
|
57
|
+
* 纯静态提取(零 LLM),确定性输出:同一代码库状态生成同一内容(无时间戳),
|
|
58
|
+
* 因此重跑幂等。既有文件中的 PRESERVE 标记块由 composeAgentsMd 组合回输出,
|
|
59
|
+
* --check 对组合结果做文本对比检测漂移(块内手改不报漂移)。
|
|
60
|
+
*/
|
|
61
|
+
export async function buildAgentsMd(projectPath: string, srcDirs: string[]): Promise<string> {
|
|
62
|
+
const pkg = await readPackageJsonLite(projectPath);
|
|
63
|
+
const [dirs, governance, hasKnowledge, contextDocCount] = await Promise.all([
|
|
64
|
+
getTopLevelDirEntries(projectPath, srcDirs),
|
|
65
|
+
getGovernanceInfo(projectPath),
|
|
66
|
+
hasKnowledgeDir(projectPath),
|
|
67
|
+
countContextDocs(projectPath, srcDirs),
|
|
68
|
+
]);
|
|
69
|
+
|
|
70
|
+
const name = pkg?.name || path.basename(projectPath);
|
|
71
|
+
const description = pkg?.description || await getConfigDescription(projectPath);
|
|
72
|
+
|
|
73
|
+
const lines: string[] = [
|
|
74
|
+
'# AGENTS.md',
|
|
75
|
+
'',
|
|
76
|
+
'> 本文件由 `harness sync-docs --agents` 自动生成,请勿手改。`<!-- PRESERVE:名称 -->` 与 `<!-- /PRESERVE:名称 -->` 之间的内容在重新生成时原样保留。内容漂移时重新运行该命令更新。',
|
|
77
|
+
'',
|
|
78
|
+
'## 项目简介',
|
|
79
|
+
'',
|
|
80
|
+
description ? `**${name}** — ${description}` : `**${name}**`,
|
|
81
|
+
'',
|
|
82
|
+
'## 目录结构',
|
|
83
|
+
'',
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
if (dirs.length > 0) {
|
|
87
|
+
lines.push('| 目录 | 说明 |', '|------|------|');
|
|
88
|
+
for (const d of dirs) {
|
|
89
|
+
lines.push(`| \`${d.dir}/\` | ${d.role} |`);
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
lines.push('(未检测到顶层目录)');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
lines.push('', '## 常用命令', '');
|
|
96
|
+
const pm = detectPackageManager(projectPath);
|
|
97
|
+
const scripts = pkg?.scripts || {};
|
|
98
|
+
const commands = AGENTS_MD_COMMANDS.filter(([n]) => scripts[n]);
|
|
99
|
+
if (commands.length > 0) {
|
|
100
|
+
lines.push('```bash');
|
|
101
|
+
for (const [n, comment] of commands) {
|
|
102
|
+
lines.push(`${formatScriptCommand(pm, n)} # ${comment}`);
|
|
103
|
+
}
|
|
104
|
+
lines.push('```');
|
|
105
|
+
} else {
|
|
106
|
+
lines.push('(package.json 中未检测到常用脚本)');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
lines.push('', '## 约束与治理', '');
|
|
110
|
+
if (governance.hasConfig) {
|
|
111
|
+
lines.push(`- 治理配置:\`.harness/config.yml\`${governance.preset ? `(preset: ${governance.preset})` : ''}`);
|
|
112
|
+
}
|
|
113
|
+
if (governance.hasClaudeGovernance) {
|
|
114
|
+
const counts = [
|
|
115
|
+
governance.ironLaws !== undefined ? `Iron Laws ${governance.ironLaws} 条` : null,
|
|
116
|
+
governance.guidelines !== undefined ? `Guidelines ${governance.guidelines} 条` : null,
|
|
117
|
+
].filter(Boolean).join('、');
|
|
118
|
+
lines.push(`- 约束清单:\`CLAUDE.md\` Governance Rules 块${counts ? `(${counts})` : ''}`);
|
|
119
|
+
}
|
|
120
|
+
if (!governance.hasConfig && !governance.hasClaudeGovernance) {
|
|
121
|
+
lines.push('- 未检测到 harness 治理配置,可运行 `harness init` 初始化');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
lines.push('', '## 知识入口', '');
|
|
125
|
+
if (hasKnowledge) {
|
|
126
|
+
// 不写条目数:.harness/knowledge 通常不入 git,条数是环境状态,
|
|
127
|
+
// 写进受 --check 漂移比对的文档会制造「必然过期」竞态(任何知识写入都使已提交文档过期)
|
|
128
|
+
lines.push('- `.harness/knowledge/`:项目知识库,用 `harness knowledge` 查询');
|
|
129
|
+
}
|
|
130
|
+
lines.push(
|
|
131
|
+
contextDocCount > 0
|
|
132
|
+
? `- 各源码目录的 \`CONTEXT.md\` 是权威模块文档(现有 ${contextDocCount} 个),改动代码时同步更新`
|
|
133
|
+
: '- 各源码目录的 `CONTEXT.md` 是权威模块文档,缺失目录可由 `harness sync-docs` 生成模板'
|
|
134
|
+
);
|
|
135
|
+
lines.push('');
|
|
136
|
+
|
|
137
|
+
return lines.join('\n');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** 收集顶层目录及其一句话说明(排序保证确定性) */
|
|
141
|
+
async function getTopLevelDirEntries(
|
|
142
|
+
projectPath: string,
|
|
143
|
+
srcDirs: string[]
|
|
144
|
+
): Promise<Array<{ dir: string; role: string }>> {
|
|
145
|
+
let dirents: import('fs').Dirent[];
|
|
146
|
+
try {
|
|
147
|
+
dirents = await fs.readdir(projectPath, { withFileTypes: true });
|
|
148
|
+
} catch {
|
|
149
|
+
return [];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const entries: Array<{ dir: string; role: string }> = [];
|
|
153
|
+
for (const d of dirents) {
|
|
154
|
+
if (!d.isDirectory()) continue;
|
|
155
|
+
if (AGENTS_MD_SKIP_DIRS.has(d.name)) continue;
|
|
156
|
+
// 隐藏目录只保留 .harness / .github
|
|
157
|
+
if (d.name.startsWith('.') && d.name !== '.harness' && d.name !== '.github') continue;
|
|
158
|
+
entries.push({ dir: d.name, role: await describeTopLevelDir(projectPath, d.name, srcDirs) });
|
|
159
|
+
}
|
|
160
|
+
entries.sort((a, b) => (a.dir < b.dir ? -1 : a.dir > b.dir ? 1 : 0));
|
|
161
|
+
return entries;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** 顶层目录的一句话说明:知名目录 → monorepo 成员 → 源码根 → 子包 description → 占位 */
|
|
165
|
+
async function describeTopLevelDir(projectPath: string, dir: string, srcDirs: string[]): Promise<string> {
|
|
166
|
+
const known = AGENTS_MD_DIR_ROLES[dir];
|
|
167
|
+
if (known) return known;
|
|
168
|
+
|
|
169
|
+
if (dir === 'apps' || dir === 'packages') {
|
|
170
|
+
const members = await listWorkspaceMembers(path.join(projectPath, dir));
|
|
171
|
+
if (members.length > 0) {
|
|
172
|
+
return `monorepo ${dir === 'apps' ? '应用' : '共享包'}:${members.join('、')}`;
|
|
173
|
+
}
|
|
174
|
+
return 'monorepo 工作区';
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (srcDirs.includes(dir)) return '源码目录';
|
|
178
|
+
|
|
179
|
+
const subPkg = await readPackageJsonLite(path.join(projectPath, dir));
|
|
180
|
+
if (subPkg?.description) return subPkg.description;
|
|
181
|
+
|
|
182
|
+
return '—';
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** 列出 monorepo 工作区成员(含 package.json 的子目录名,排序) */
|
|
186
|
+
async function listWorkspaceMembers(dir: string): Promise<string[]> {
|
|
187
|
+
try {
|
|
188
|
+
const dirents = await fs.readdir(dir, { withFileTypes: true });
|
|
189
|
+
const members: string[] = [];
|
|
190
|
+
for (const d of dirents) {
|
|
191
|
+
if (!d.isDirectory() || d.name.startsWith('.')) continue;
|
|
192
|
+
if (existsSync(path.join(dir, d.name, 'package.json'))) {
|
|
193
|
+
members.push(d.name);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return members.sort();
|
|
197
|
+
} catch {
|
|
198
|
+
return [];
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** 收集治理信息:.harness/config.yml 与 CLAUDE.md 治理块(含铁律/指南计数) */
|
|
203
|
+
async function getGovernanceInfo(projectPath: string): Promise<GovernanceInfo> {
|
|
204
|
+
const info: GovernanceInfo = { hasConfig: false, hasClaudeGovernance: false };
|
|
205
|
+
|
|
206
|
+
try {
|
|
207
|
+
const config = loadRawProjectConfig(projectPath);
|
|
208
|
+
info.hasConfig = config !== undefined;
|
|
209
|
+
if (config && typeof config.preset === 'string') {
|
|
210
|
+
info.preset = config.preset;
|
|
211
|
+
}
|
|
212
|
+
} catch {
|
|
213
|
+
// 配置不存在
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
try {
|
|
217
|
+
const claude = await fs.readFile(path.join(projectPath, 'CLAUDE.md'), 'utf-8');
|
|
218
|
+
if (/^##\s+Governance Rules/m.test(claude) || claude.includes('HARNESS_CONSTRAINTS_START')) {
|
|
219
|
+
info.hasClaudeGovernance = true;
|
|
220
|
+
info.ironLaws = countConstraintBullets(claude, 'Iron Laws');
|
|
221
|
+
info.guidelines = countConstraintBullets(claude, 'Guidelines');
|
|
222
|
+
}
|
|
223
|
+
} catch {
|
|
224
|
+
// CLAUDE.md 不存在
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return info;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** 统计 CLAUDE.md 指定约束分节下的条目数(`- **key**:` 行),分节不存在时返回 undefined */
|
|
231
|
+
function countConstraintBullets(content: string, section: string): number | undefined {
|
|
232
|
+
const heading = new RegExp(`^###\\s+${section}[^\\n]*$`, 'm').exec(content);
|
|
233
|
+
if (!heading) return undefined;
|
|
234
|
+
const rest = content.slice(heading.index + heading[0].length);
|
|
235
|
+
const end = rest.search(/^###\s|^\s*<!--\s*HARNESS_CONSTRAINTS_END/m);
|
|
236
|
+
const block = end === -1 ? rest : rest.slice(0, end);
|
|
237
|
+
const items = block.match(/^-\s+\*\*[A-Za-z0-9_]+\*\*/gm);
|
|
238
|
+
return items ? items.length : 0;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** 判断 .harness/knowledge 目录是否存在(只判存在性,不统计条数——条数易变,见 buildAgentsMd 注释) */
|
|
242
|
+
async function hasKnowledgeDir(projectPath: string): Promise<boolean> {
|
|
243
|
+
try {
|
|
244
|
+
return (await fs.stat(path.join(projectPath, '.harness', 'knowledge'))).isDirectory();
|
|
245
|
+
} catch {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** 统计源码根内的 CONTEXT.md 数量(含源码根本身,跨根去重) */
|
|
251
|
+
async function countContextDocs(projectPath: string, srcDirs: string[]): Promise<number> {
|
|
252
|
+
const found = new Set<string>();
|
|
253
|
+
|
|
254
|
+
async function scan(dir: string): Promise<void> {
|
|
255
|
+
let entries: import('fs').Dirent[];
|
|
256
|
+
try {
|
|
257
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
258
|
+
} catch {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
for (const entry of entries) {
|
|
262
|
+
if (!entry.isDirectory()) continue;
|
|
263
|
+
if (entry.name === 'node_modules' || entry.name === '__tests__' || entry.name === 'dist') continue;
|
|
264
|
+
const entryPath = path.join(dir, entry.name);
|
|
265
|
+
if (existsSync(path.join(entryPath, 'CONTEXT.md'))) {
|
|
266
|
+
found.add(entryPath);
|
|
267
|
+
}
|
|
268
|
+
await scan(entryPath);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
for (const root of srcDirs) {
|
|
273
|
+
const rootPath = path.join(projectPath, root);
|
|
274
|
+
if (existsSync(path.join(rootPath, 'CONTEXT.md'))) {
|
|
275
|
+
found.add(rootPath);
|
|
276
|
+
}
|
|
277
|
+
await scan(rootPath);
|
|
278
|
+
}
|
|
279
|
+
return found.size;
|
|
280
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CAPABILITIES.md 同步器(工单 22)
|
|
3
|
+
*
|
|
4
|
+
* 支持两种格式:
|
|
5
|
+
* - 文件表格格式:模块/文件/说明三列表格,增删行维护
|
|
6
|
+
* - 能力清单格式:计数行(CLI Commands (N) 等),FreshnessRunner 校验与刷新
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as fs from 'fs/promises';
|
|
10
|
+
import { IRON_LAWS, GUIDELINES, TIPS } from '../../../core/constraints/definitions';
|
|
11
|
+
import { readCapabilitiesEntries } from '../../../core/constraints/capabilities-parser';
|
|
12
|
+
import { FreshnessRunner } from '../../../core/constraints/doc-freshness/runner';
|
|
13
|
+
import type { DocFreshnessCheck } from '../../../types/project-config';
|
|
14
|
+
import type { ModuleInfo, SyncResult } from './project-reader';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 解析 CAPABILITIES.md 中的文件路径
|
|
18
|
+
*
|
|
19
|
+
* 提取所有表格行中提到的 .ts/.tsx/.js/.jsx 文件名(不含路径前缀)
|
|
20
|
+
* 用于模糊匹配:只要文档中提到了该文件名就算已记录
|
|
21
|
+
*/
|
|
22
|
+
export async function parseCapabilitiesFiles(capabilitiesPath: string): Promise<string[]> {
|
|
23
|
+
// 工单 19-B:解析收敛到 core/constraints/capabilities-parser;
|
|
24
|
+
// 此处保持原语义——文件条目取 basename,目录条目(以 / 结尾)原样保留
|
|
25
|
+
const entries = readCapabilitiesEntries(capabilitiesPath, { includeDirs: true });
|
|
26
|
+
const files: string[] = [];
|
|
27
|
+
for (const entry of entries) {
|
|
28
|
+
const value = entry.endsWith('/') ? entry : entry.split('/').pop()!;
|
|
29
|
+
if (!files.includes(value)) files.push(value);
|
|
30
|
+
}
|
|
31
|
+
return files;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 检测 CAPABILITIES.md 是否使用能力清单格式(计数行),而非文件表格格式
|
|
36
|
+
*/
|
|
37
|
+
export function isCapabilityListingFormat(content: string): boolean {
|
|
38
|
+
// 能力清单格式特征:包含 "CLI Commands (N)" / "Iron Laws (N)" 等计数行
|
|
39
|
+
return /CLI Commands\s*\(\d+\)/.test(content) ||
|
|
40
|
+
/Iron Laws?\s*\(\d+\)/.test(content) ||
|
|
41
|
+
/Guidelines?\s*\(\d+\)/.test(content);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 构建 CAPABILITIES.md 能力清单格式的检查配置
|
|
46
|
+
*/
|
|
47
|
+
function buildCapabilityChecks(): DocFreshnessCheck[] {
|
|
48
|
+
return [
|
|
49
|
+
{
|
|
50
|
+
type: 'doc_regex_count',
|
|
51
|
+
doc: 'CAPABILITIES.md',
|
|
52
|
+
label: 'CLI Commands',
|
|
53
|
+
pattern: 'CLI Commands\\s*\\((\\d+)\\)',
|
|
54
|
+
actual: { kind: 'dir_count', path: 'src/cli/commands', extension: '.ts', exclude: ['index.ts'] },
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
type: 'doc_regex_count',
|
|
58
|
+
doc: 'CAPABILITIES.md',
|
|
59
|
+
label: 'Quality Gates',
|
|
60
|
+
pattern: 'Quality Gates?\\s*\\((\\d+)\\)',
|
|
61
|
+
actual: { kind: 'dir_count', path: 'src/gates', extension: '.ts', exclude: ['index.ts', 'types.ts'] },
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
type: 'doc_regex_count',
|
|
65
|
+
doc: 'CAPABILITIES.md',
|
|
66
|
+
label: 'Iron Laws',
|
|
67
|
+
pattern: 'Iron Laws?\\s*\\((\\d+)\\)',
|
|
68
|
+
actual: { kind: 'const_count', value: Object.keys(IRON_LAWS).length },
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
type: 'doc_regex_count',
|
|
72
|
+
doc: 'CAPABILITIES.md',
|
|
73
|
+
label: 'Guidelines',
|
|
74
|
+
pattern: 'Guidelines?\\s*\\((\\d+)\\)',
|
|
75
|
+
actual: { kind: 'const_count', value: Object.keys(GUIDELINES).length },
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
type: 'doc_regex_count',
|
|
79
|
+
doc: 'CAPABILITIES.md',
|
|
80
|
+
label: 'Tips',
|
|
81
|
+
pattern: 'Tips?\\s*\\((\\d+)\\)',
|
|
82
|
+
actual: { kind: 'const_count', value: Object.keys(TIPS).length },
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 使用 FreshnessRunner 检查能力清单计数是否与代码一致(--check 模式)
|
|
89
|
+
*/
|
|
90
|
+
export function checkCapabilityCounts(
|
|
91
|
+
projectPath: string
|
|
92
|
+
): { match: boolean; mismatches: string[] } {
|
|
93
|
+
const runner = new FreshnessRunner();
|
|
94
|
+
const checks = buildCapabilityChecks();
|
|
95
|
+
const results = runner.runAll({ checks }, projectPath);
|
|
96
|
+
|
|
97
|
+
const mismatches: string[] = [];
|
|
98
|
+
for (const r of results) {
|
|
99
|
+
if (!r.pass && r.message) {
|
|
100
|
+
mismatches.push(r.message);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return { match: mismatches.length === 0, mismatches };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 更新 CAPABILITIES.md 中的能力清单计数(write 模式)
|
|
109
|
+
*
|
|
110
|
+
* 使用 FreshnessRunner 获取实际计数,然后 regex 替换文档计数行。
|
|
111
|
+
*/
|
|
112
|
+
export function updateCapabilityCounts(content: string, projectPath: string): string {
|
|
113
|
+
const runner = new FreshnessRunner();
|
|
114
|
+
|
|
115
|
+
const cliCount = runner.countFromDir('src/cli/commands', '.ts', ['index.ts'], projectPath);
|
|
116
|
+
const gateCount = runner.countFromDir('src/gates', '.ts', ['index.ts', 'types.ts'], projectPath);
|
|
117
|
+
const ironCount = Object.keys(IRON_LAWS).length;
|
|
118
|
+
const guideCount = Object.keys(GUIDELINES).length;
|
|
119
|
+
const tipsCount = Object.keys(TIPS).length;
|
|
120
|
+
|
|
121
|
+
const replacements: [RegExp, string][] = [
|
|
122
|
+
[/CLI Commands\s*\(\d+\)/, `CLI Commands (${cliCount})`],
|
|
123
|
+
[/Quality Gates?\s*\(\d+\)/, `Quality Gates (${gateCount})`],
|
|
124
|
+
[/Iron Laws?\s*\(\d+\)/, `Iron Laws (${ironCount})`],
|
|
125
|
+
[/Guidelines?\s*\(\d+\)/, `Guidelines (${guideCount})`],
|
|
126
|
+
[/Tips?\s*\(\d+\)/, `Tips (${tipsCount})`],
|
|
127
|
+
];
|
|
128
|
+
|
|
129
|
+
for (const [regex, replacement] of replacements) {
|
|
130
|
+
if (regex.test(content)) {
|
|
131
|
+
content = content.replace(regex, replacement);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return content;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 更新 CAPABILITIES.md 文件
|
|
140
|
+
*/
|
|
141
|
+
export async function updateCapabilitiesFile(
|
|
142
|
+
capabilitiesPath: string,
|
|
143
|
+
currentModules: ModuleInfo[],
|
|
144
|
+
existingFiles: string[],
|
|
145
|
+
result: SyncResult,
|
|
146
|
+
): Promise<void> {
|
|
147
|
+
let content: string;
|
|
148
|
+
try {
|
|
149
|
+
content = await fs.readFile(capabilitiesPath, 'utf-8');
|
|
150
|
+
} catch {
|
|
151
|
+
// 文件不存在,创建新的
|
|
152
|
+
content = generateCapabilitiesContent(currentModules);
|
|
153
|
+
await fs.writeFile(capabilitiesPath, content, 'utf-8');
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// 如果有表格行,更新表格
|
|
158
|
+
if (existingFiles.length > 0) {
|
|
159
|
+
// 移除已删除文件的行
|
|
160
|
+
for (const removed of result.removed) {
|
|
161
|
+
const escapedFile = removed.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
162
|
+
// 第二列存完整路径,basename 只在末尾出现,用 [^|]* 匹配路径前缀
|
|
163
|
+
const rowRegex = new RegExp(`^\\|[^|]*\\|[^|]*\\b${escapedFile}\\s*\\|.*$`, 'gm');
|
|
164
|
+
content = content.replace(rowRegex, '');
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// 添加新文件的行(在最后一个表格行之后)
|
|
168
|
+
if (result.added.length > 0) {
|
|
169
|
+
const getBasenameLocal = (f: string) => f.split('/').pop()!;
|
|
170
|
+
const addedModules = currentModules.filter(m => result.added.includes(getBasenameLocal(m.file)));
|
|
171
|
+
const tableEndRegex = /(^\|[^|]+\|[^|]+\|[^|]+\|\s*$)/gm;
|
|
172
|
+
let lastTableRow = '';
|
|
173
|
+
let match;
|
|
174
|
+
while ((match = tableEndRegex.exec(content)) !== null) {
|
|
175
|
+
lastTableRow = match[0];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (lastTableRow) {
|
|
179
|
+
const newRows = addedModules.map(m =>
|
|
180
|
+
`| ${m.name} | ${m.file} | ${m.description} |`
|
|
181
|
+
).join('\n');
|
|
182
|
+
content = content.replace(lastTableRow, lastTableRow + '\n' + newRows);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// 清理多余空行
|
|
187
|
+
content = content.replace(/\n{3,}/g, '\n\n');
|
|
188
|
+
} else {
|
|
189
|
+
// 没有表格,追加模块表格
|
|
190
|
+
content += '\n\n' + generateModuleTable(currentModules);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// 更新最后更新时间
|
|
194
|
+
const now = new Date().toISOString().split('T')[0];
|
|
195
|
+
content = content.replace(
|
|
196
|
+
/最后更新[::].*/,
|
|
197
|
+
`最后更新: ${now}`
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
await fs.writeFile(capabilitiesPath, content, 'utf-8');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* 生成 CAPABILITIES.md 内容
|
|
205
|
+
*/
|
|
206
|
+
function generateCapabilitiesContent(modules: ModuleInfo[]): string {
|
|
207
|
+
const now = new Date().toISOString().split('T')[0];
|
|
208
|
+
return `# CAPABILITIES.md
|
|
209
|
+
|
|
210
|
+
> 最后更新: ${now}
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
${generateModuleTable(modules)}
|
|
215
|
+
`;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* 生成模块表格
|
|
220
|
+
*/
|
|
221
|
+
function generateModuleTable(modules: ModuleInfo[]): string {
|
|
222
|
+
if (modules.length === 0) return '';
|
|
223
|
+
|
|
224
|
+
const rows = modules.map(m =>
|
|
225
|
+
`| ${m.name} | ${m.file} | ${m.description} |`
|
|
226
|
+
).join('\n');
|
|
227
|
+
|
|
228
|
+
return `| 模块 | 文件 | 说明 |\n|------|------|------|\n${rows}`;
|
|
229
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CONTEXT.md 同步器(工单 22):缺失模板生成 + 既有文件发现 + 过时判定
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as fs from 'fs/promises';
|
|
6
|
+
import * as path from 'path';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 创建 CONTEXT.md 模板
|
|
10
|
+
*/
|
|
11
|
+
export async function createContextMd(projectPath: string, dir: string): Promise<void> {
|
|
12
|
+
const contextPath = path.join(projectPath, dir, 'CONTEXT.md');
|
|
13
|
+
const dirName = path.basename(dir);
|
|
14
|
+
|
|
15
|
+
const content = `# ${dirName}
|
|
16
|
+
|
|
17
|
+
> 此文件描述 ${dir} 目录的职责和上下文。
|
|
18
|
+
> 请阅读本目录的源代码,然后填写以下各节。
|
|
19
|
+
> 如果使用 AI 编码助手,将本文件内容作为 prompt 请求它分析并填写。
|
|
20
|
+
|
|
21
|
+
## 职责
|
|
22
|
+
|
|
23
|
+
本目录的核心职责是?
|
|
24
|
+
|
|
25
|
+
## 核心导出
|
|
26
|
+
|
|
27
|
+
本目录对外暴露的主要模块/函数:
|
|
28
|
+
|
|
29
|
+
## 依赖关系
|
|
30
|
+
|
|
31
|
+
本目录依赖哪些其他模块,谁依赖本目录?
|
|
32
|
+
|
|
33
|
+
## 注意事项
|
|
34
|
+
|
|
35
|
+
开发时需要注意的约束或约定:
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
await fs.mkdir(path.join(projectPath, dir), { recursive: true });
|
|
39
|
+
await fs.writeFile(contextPath, content, 'utf-8');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 自动发现已有 CONTEXT.md 文件的目录(相对于 projectPath)
|
|
44
|
+
*/
|
|
45
|
+
export async function findExistingContextFiles(projectPath: string, srcDirs: string[]): Promise<string[]> {
|
|
46
|
+
const dirs: string[] = [];
|
|
47
|
+
|
|
48
|
+
async function scan(dir: string): Promise<void> {
|
|
49
|
+
let entries: string[];
|
|
50
|
+
try {
|
|
51
|
+
entries = await fs.readdir(dir);
|
|
52
|
+
} catch {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
for (const entry of entries) {
|
|
56
|
+
if (entry === 'node_modules' || entry === '__tests__' || entry === 'dist') continue;
|
|
57
|
+
const entryPath = path.join(dir, entry);
|
|
58
|
+
const stat = await fs.stat(entryPath);
|
|
59
|
+
if (stat.isDirectory()) {
|
|
60
|
+
// 检查该目录是否有 CONTEXT.md
|
|
61
|
+
try {
|
|
62
|
+
await fs.access(path.join(entryPath, 'CONTEXT.md'));
|
|
63
|
+
dirs.push(path.relative(projectPath, entryPath));
|
|
64
|
+
} catch {
|
|
65
|
+
// 没有,继续递归
|
|
66
|
+
}
|
|
67
|
+
await scan(entryPath);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
for (const srcDir of srcDirs) {
|
|
73
|
+
await scan(path.join(projectPath, srcDir));
|
|
74
|
+
}
|
|
75
|
+
return dirs;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 获取目录下最新 .ts 文件的修改时间
|
|
80
|
+
* 返回 null 如果目录不存在或没有 .ts 文件
|
|
81
|
+
*/
|
|
82
|
+
export async function getLatestTsMtime(dirPath: string): Promise<number | null> {
|
|
83
|
+
let latest: number | null = null;
|
|
84
|
+
|
|
85
|
+
async function scan(dir: string): Promise<void> {
|
|
86
|
+
let entries: string[];
|
|
87
|
+
try {
|
|
88
|
+
entries = await fs.readdir(dir);
|
|
89
|
+
} catch {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
for (const entry of entries) {
|
|
93
|
+
if (entry === 'node_modules' || entry === '__tests__' || entry === 'dist') continue;
|
|
94
|
+
const entryPath = path.join(dir, entry);
|
|
95
|
+
const stat = await fs.stat(entryPath);
|
|
96
|
+
if (stat.isDirectory()) {
|
|
97
|
+
await scan(entryPath);
|
|
98
|
+
} else if (entry.endsWith('.ts') && !entry.endsWith('.d.ts')) {
|
|
99
|
+
if (latest === null || stat.mtimeMs > latest) {
|
|
100
|
+
latest = stat.mtimeMs;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
await scan(dirPath);
|
|
107
|
+
return latest;
|
|
108
|
+
}
|