onto-mcp 0.3.2 → 0.4.0
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/.onto/processes/reconstruct/actionable-ontology-seed-recomposition-design.md +447 -0
- package/.onto/processes/reconstruct/foundry-style-ontology-seed-contract.md +934 -0
- package/.onto/processes/reconstruct/reconstruct-boundary-contract.md +303 -725
- package/.onto/processes/reconstruct/reconstruct-contract-registry.yaml +1645 -0
- package/.onto/processes/reconstruct/reconstruct-execution-ux-contract.md +26 -22
- package/.onto/processes/reconstruct/source-profile-contract.md +49 -23
- package/.onto/processes/reconstruct/source-profiles/code.md +6 -3
- package/.onto/processes/reconstruct/source-profiles/database.md +5 -2
- package/.onto/processes/reconstruct/source-profiles/document.md +5 -2
- package/.onto/processes/reconstruct/source-profiles/spreadsheet.md +5 -4
- package/.onto/processes/review/review-execution-ux-contract.md +40 -0
- package/.onto/processes/shared/pipeline-execution-ledger-contract.md +26 -10
- package/.onto/processes/shared/target-material-kind-contract.md +29 -16
- package/AGENTS.md +6 -4
- package/README.md +135 -76
- package/dist/cli.js +8 -8
- package/dist/core-api/reconstruct-api.js +117 -31
- package/dist/core-api/review-api.js +47 -0
- package/dist/core-runtime/cli/codex-review-unit-executor.js +39 -2
- package/dist/core-runtime/cli/complete-review-session.js +2 -2
- package/dist/core-runtime/cli/mock-review-unit-executor.js +1 -1
- package/dist/core-runtime/cli/review-invoke.js +9 -9
- package/dist/core-runtime/cli/run-review-prompt-execution.js +39 -5
- package/dist/core-runtime/cli/spawn-watcher.js +266 -47
- package/dist/core-runtime/cli/start-review-session.js +3 -3
- package/dist/core-runtime/llm/llm-caller.js +11 -0
- package/dist/core-runtime/llm/llm-tool-loop.js +2 -0
- package/dist/core-runtime/observability/runtime-stream-observation.js +118 -0
- package/dist/core-runtime/onboard/cli-host.js +149 -0
- package/dist/core-runtime/onboard/host-target.js +22 -0
- package/dist/core-runtime/onboard/json-config-host.js +122 -0
- package/dist/core-runtime/onboard/path-scan.js +26 -0
- package/dist/core-runtime/onboard/prompt.js +51 -0
- package/dist/core-runtime/onboard/register.js +207 -0
- package/dist/core-runtime/onboard/types.js +27 -0
- package/dist/core-runtime/reconstruct/actionable-seed-validation.js +1777 -0
- package/dist/core-runtime/reconstruct/artifact-types.js +10 -4
- package/dist/core-runtime/reconstruct/contract-registry.js +623 -0
- package/dist/core-runtime/reconstruct/domain-id.js +10 -0
- package/dist/core-runtime/reconstruct/governing-snapshot.js +716 -0
- package/dist/core-runtime/reconstruct/material-profile-validation.js +191 -0
- package/dist/core-runtime/reconstruct/materialize-preparation.js +49 -11
- package/dist/core-runtime/reconstruct/pipeline-execution-ledger.js +269 -79
- package/dist/core-runtime/reconstruct/post-seed-validation.js +1194 -51
- package/dist/core-runtime/reconstruct/record.js +104 -20
- package/dist/core-runtime/reconstruct/run.js +2107 -413
- package/dist/core-runtime/reconstruct/seed-claim-projections.js +268 -0
- package/dist/core-runtime/reconstruct/source-profiles.js +93 -4
- package/dist/core-runtime/reconstruct/terminal-validation.js +807 -0
- package/dist/core-runtime/review/review-invocation-runner.js +4 -4
- package/dist/mcp/server.js +110 -38
- package/dist/mcp/tool-schemas.js +20 -6
- package/package.json +8 -17
- package/scripts/onto-review-watch.sh +486 -0
- package/scripts/onto-runtime-watch.sh +122 -0
- package/scripts/postinstall-hint.js +22 -0
- package/.onto/processes/reconstruct/top-level-concept-discovery-contract.md +0 -387
- package/dist/core-runtime/cli/bootstrap-review-binding.js +0 -186
- package/dist/core-runtime/cli/codex-nested-dispatch.test.js +0 -390
- package/dist/core-runtime/cli/codex-nested-teamlead-executor.test.js +0 -335
- package/dist/core-runtime/cli/coordinator-helpers.js +0 -583
- package/dist/core-runtime/cli/coordinator-state-machine-deliberation.test.js +0 -167
- package/dist/core-runtime/cli/coordinator-state-machine.js +0 -794
- package/dist/core-runtime/cli/e2e-codex-multi-agent-fixes.test.js +0 -615
- package/dist/core-runtime/cli/e2e-start-review-session.test.js +0 -312
- package/dist/core-runtime/cli/health.js +0 -44
- package/dist/core-runtime/cli/inline-http-review-unit-executor.test.js +0 -567
- package/dist/core-runtime/cli/materialize-review-execution-preparation.js +0 -104
- package/dist/core-runtime/cli/migrate-session-roots.js +0 -118
- package/dist/core-runtime/cli/repo-layout-migration-replace.smoke.test.js +0 -106
- package/dist/core-runtime/cli/review-invoke-auto-resolution.test.js +0 -268
- package/dist/core-runtime/cli/review-invoke-coordinator-topology.test.js +0 -136
- package/dist/core-runtime/cli/review-invoke-resolver-caching.test.js +0 -201
- package/dist/core-runtime/cli/review-invoke-topology-dispatch.test.js +0 -192
- package/dist/core-runtime/cli/session-root-guard.js +0 -168
- package/dist/core-runtime/cli/spawn-watcher.test.js +0 -457
- package/dist/core-runtime/cli/strip-wrapping-code-fence.test.js +0 -79
- package/dist/core-runtime/cli/teamcreate-lens-deliberation-executor.js +0 -412
- package/dist/core-runtime/cli/teamcreate-lens-deliberation-executor.test.js +0 -351
- package/dist/core-runtime/cli/topology-executor-mapping.js +0 -139
- package/dist/core-runtime/cli/topology-executor-mapping.test.js +0 -173
- package/dist/core-runtime/cli/write-review-interpretation.js +0 -81
- package/dist/core-runtime/config/onto-config-cli.js +0 -278
- package/dist/core-runtime/config/onto-config-key-path.js +0 -288
- package/dist/core-runtime/config/onto-config-key-path.test.js +0 -195
- package/dist/core-runtime/config/onto-config-preview.js +0 -108
- package/dist/core-runtime/config/onto-config-preview.test.js +0 -132
- package/dist/core-runtime/discovery/config-chain.js +0 -118
- package/dist/core-runtime/discovery/config-chain.test.js +0 -103
- package/dist/core-runtime/discovery/config-profile.js +0 -199
- package/dist/core-runtime/discovery/config-profile.test.js +0 -233
- package/dist/core-runtime/discovery/host-detection.test.js +0 -186
- package/dist/core-runtime/discovery/installation-paths.test.js +0 -65
- package/dist/core-runtime/discovery/lens-registry.test.js +0 -81
- package/dist/core-runtime/discovery/path-normalization.test.js +0 -22
- package/dist/core-runtime/discovery/plugin-path.js +0 -72
- package/dist/core-runtime/discovery/plugin-path.test.js +0 -95
- package/dist/core-runtime/evolve/adapters/code-product/compile/compile-defense.js +0 -344
- package/dist/core-runtime/evolve/adapters/code-product/compile/compile-defense.test.js +0 -915
- package/dist/core-runtime/evolve/adapters/code-product/compile/compile.js +0 -564
- package/dist/core-runtime/evolve/adapters/code-product/compile/compile.test.js +0 -708
- package/dist/core-runtime/evolve/adapters/code-product/parsers/brief-parser.js +0 -165
- package/dist/core-runtime/evolve/adapters/code-product/parsers/brief-parser.test.js +0 -227
- package/dist/core-runtime/evolve/adapters/code-product/validators/validate.js +0 -59
- package/dist/core-runtime/evolve/adapters/code-product/validators/validate.test.js +0 -205
- package/dist/core-runtime/evolve/adapters/methodology/adapter.js +0 -16
- package/dist/core-runtime/evolve/adapters/methodology/adapter.test.js +0 -9
- package/dist/core-runtime/evolve/adapters/methodology/perspectives/authority-consistency.js +0 -298
- package/dist/core-runtime/evolve/adapters/methodology/perspectives/authority-consistency.test.js +0 -70
- package/dist/core-runtime/evolve/adapters/methodology/scope-types/process.js +0 -46
- package/dist/core-runtime/evolve/adapters/methodology/scope-types/process.test.js +0 -73
- package/dist/core-runtime/evolve/adapters/registry.js +0 -47
- package/dist/core-runtime/evolve/adapters/registry.test.js +0 -67
- package/dist/core-runtime/evolve/cli.js +0 -256
- package/dist/core-runtime/evolve/commands/align.js +0 -194
- package/dist/core-runtime/evolve/commands/align.test.js +0 -82
- package/dist/core-runtime/evolve/commands/apply.js +0 -161
- package/dist/core-runtime/evolve/commands/apply.test.js +0 -138
- package/dist/core-runtime/evolve/commands/close.js +0 -39
- package/dist/core-runtime/evolve/commands/close.test.js +0 -99
- package/dist/core-runtime/evolve/commands/defer.js +0 -40
- package/dist/core-runtime/evolve/commands/defer.test.js +0 -134
- package/dist/core-runtime/evolve/commands/draft.js +0 -323
- package/dist/core-runtime/evolve/commands/draft.test.js +0 -178
- package/dist/core-runtime/evolve/commands/e2e-evolve-full-cycle.test.js +0 -208
- package/dist/core-runtime/evolve/commands/error-messages.js +0 -125
- package/dist/core-runtime/evolve/commands/error-messages.test.js +0 -167
- package/dist/core-runtime/evolve/commands/propose-align.js +0 -222
- package/dist/core-runtime/evolve/commands/propose-align.test.js +0 -136
- package/dist/core-runtime/evolve/commands/reconstruct.js +0 -330
- package/dist/core-runtime/evolve/commands/reconstruct.test.js +0 -278
- package/dist/core-runtime/evolve/commands/shared.js +0 -22
- package/dist/core-runtime/evolve/commands/stale-check.js +0 -103
- package/dist/core-runtime/evolve/commands/stale-check.test.js +0 -84
- package/dist/core-runtime/evolve/commands/start.js +0 -887
- package/dist/core-runtime/evolve/commands/start.test.js +0 -396
- package/dist/core-runtime/evolve/config/project-config.js +0 -99
- package/dist/core-runtime/evolve/config/project-config.test.js +0 -170
- package/dist/core-runtime/evolve/renderers/align-packet.js +0 -280
- package/dist/core-runtime/evolve/renderers/align-packet.test.js +0 -332
- package/dist/core-runtime/evolve/renderers/draft-packet.js +0 -303
- package/dist/core-runtime/evolve/renderers/draft-packet.test.js +0 -377
- package/dist/core-runtime/evolve/renderers/format.js +0 -5
- package/dist/core-runtime/evolve/renderers/scope-md.js +0 -237
- package/dist/core-runtime/evolve/renderers/scope-md.test.js +0 -306
- package/dist/core-runtime/govern/cli.js +0 -369
- package/dist/core-runtime/govern/cli.test.js +0 -314
- package/dist/core-runtime/govern/drift-engine.js +0 -103
- package/dist/core-runtime/govern/drift-engine.test.js +0 -319
- package/dist/core-runtime/govern/promote-principle.js +0 -206
- package/dist/core-runtime/govern/promote-principle.test.js +0 -368
- package/dist/core-runtime/govern/queue.js +0 -81
- package/dist/core-runtime/govern/types.js +0 -16
- package/dist/core-runtime/install/cli.js +0 -530
- package/dist/core-runtime/install/detect.js +0 -128
- package/dist/core-runtime/install/detect.test.js +0 -155
- package/dist/core-runtime/install/gitignore-update.js +0 -74
- package/dist/core-runtime/install/gitignore-update.test.js +0 -64
- package/dist/core-runtime/install/install-integration.test.js +0 -373
- package/dist/core-runtime/install/prompts.js +0 -389
- package/dist/core-runtime/install/prompts.test.js +0 -293
- package/dist/core-runtime/install/types.js +0 -26
- package/dist/core-runtime/install/validation.js +0 -295
- package/dist/core-runtime/install/validation.test.js +0 -313
- package/dist/core-runtime/install/writer.js +0 -254
- package/dist/core-runtime/install/writer.test.js +0 -218
- package/dist/core-runtime/learning/extractor.js +0 -461
- package/dist/core-runtime/learning/feedback.js +0 -179
- package/dist/core-runtime/learning/health-report.js +0 -165
- package/dist/core-runtime/learning/health-report.test.js +0 -169
- package/dist/core-runtime/learning/loader.js +0 -388
- package/dist/core-runtime/learning/loader.test.js +0 -102
- package/dist/core-runtime/learning/promote/apply-state.js +0 -240
- package/dist/core-runtime/learning/promote/audit-obligation.js +0 -195
- package/dist/core-runtime/learning/promote/collector.js +0 -432
- package/dist/core-runtime/learning/promote/degraded-state.js +0 -125
- package/dist/core-runtime/learning/promote/domain-doc-proposer.js +0 -166
- package/dist/core-runtime/learning/promote/e2e-promote.test.js +0 -6385
- package/dist/core-runtime/learning/promote/health-snapshot.js +0 -150
- package/dist/core-runtime/learning/promote/insight-reclassifier.js +0 -544
- package/dist/core-runtime/learning/promote/judgment-auditor.js +0 -517
- package/dist/core-runtime/learning/promote/panel-reviewer.js +0 -1158
- package/dist/core-runtime/learning/promote/promote-executor.js +0 -1675
- package/dist/core-runtime/learning/promote/promoter.js +0 -307
- package/dist/core-runtime/learning/promote/retirement.js +0 -122
- package/dist/core-runtime/learning/promote/types.js +0 -23
- package/dist/core-runtime/learning/prompt-sections.js +0 -51
- package/dist/core-runtime/learning/shared/artifact-registry-init.js +0 -45
- package/dist/core-runtime/learning/shared/artifact-registry.js +0 -254
- package/dist/core-runtime/learning/shared/audit-obligation-kernel.js +0 -73
- package/dist/core-runtime/learning/shared/audit-state.js +0 -99
- package/dist/core-runtime/learning/shared/duplicate-check.js +0 -28
- package/dist/core-runtime/learning/shared/llm-caller.js +0 -831
- package/dist/core-runtime/learning/shared/llm-caller.test.js +0 -601
- package/dist/core-runtime/learning/shared/llm-tool-loop.js +0 -393
- package/dist/core-runtime/learning/shared/mode.js +0 -25
- package/dist/core-runtime/learning/shared/paths.js +0 -84
- package/dist/core-runtime/learning/shared/paths.test.js +0 -79
- package/dist/core-runtime/learning/shared/patterns.js +0 -37
- package/dist/core-runtime/learning/shared/recoverability.js +0 -355
- package/dist/core-runtime/learning/shared/recovery-context.js +0 -374
- package/dist/core-runtime/learning/shared/scope.js +0 -1
- package/dist/core-runtime/learning/shared/semantic-classifier.js +0 -94
- package/dist/core-runtime/learning/shared/specs/apply-execution-state-spec.js +0 -42
- package/dist/core-runtime/learning/shared/specs/audit-state-spec.js +0 -37
- package/dist/core-runtime/learning/shared/specs/backup-metadata-spec.js +0 -39
- package/dist/core-runtime/learning/shared/specs/emergency-log-spec.js +0 -41
- package/dist/core-runtime/learning/shared/specs/layout-version-spec.js +0 -38
- package/dist/core-runtime/learning/shared/specs/promote-decisions-spec.js +0 -43
- package/dist/core-runtime/learning/shared/specs/promote-report-spec.js +0 -113
- package/dist/core-runtime/learning/shared/specs/prune-log-spec.js +0 -36
- package/dist/core-runtime/learning/shared/specs/recovery-resolution-spec.js +0 -48
- package/dist/core-runtime/learning/shared/specs/restore-manifest-spec.js +0 -43
- package/dist/core-runtime/learning/shared/specs/spec-helpers.js +0 -64
- package/dist/core-runtime/learning/usage-tracker.js +0 -190
- package/dist/core-runtime/learning/usage-tracker.test.js +0 -176
- package/dist/core-runtime/onboard/detect-review-axes.js +0 -122
- package/dist/core-runtime/onboard/detect-review-axes.test.js +0 -127
- package/dist/core-runtime/onboard/write-review-block.js +0 -188
- package/dist/core-runtime/onboard/write-review-block.test.js +0 -240
- package/dist/core-runtime/readers/brownfield-builder.js +0 -150
- package/dist/core-runtime/readers/brownfield-builder.test.js +0 -136
- package/dist/core-runtime/readers/code-chunk-collector.js +0 -53
- package/dist/core-runtime/readers/code-chunk-collector.test.js +0 -136
- package/dist/core-runtime/readers/file-utils.js +0 -240
- package/dist/core-runtime/readers/file-utils.test.js +0 -146
- package/dist/core-runtime/readers/lexicon-citation-check.js +0 -93
- package/dist/core-runtime/readers/lexicon-citation-check.test.js +0 -77
- package/dist/core-runtime/readers/mcp-figma.js +0 -30
- package/dist/core-runtime/readers/mcp-figma.test.js +0 -82
- package/dist/core-runtime/readers/mcp-generic.js +0 -31
- package/dist/core-runtime/readers/mcp-generic.test.js +0 -76
- package/dist/core-runtime/readers/ontology-index.js +0 -148
- package/dist/core-runtime/readers/ontology-index.test.js +0 -245
- package/dist/core-runtime/readers/ontology-query.js +0 -168
- package/dist/core-runtime/readers/ontology-query.test.js +0 -311
- package/dist/core-runtime/readers/ontology-resolve.js +0 -48
- package/dist/core-runtime/readers/ontology-resolve.test.js +0 -48
- package/dist/core-runtime/readers/patterns/index.js +0 -7
- package/dist/core-runtime/readers/review-log.js +0 -213
- package/dist/core-runtime/readers/review-log.test.js +0 -313
- package/dist/core-runtime/readers/scan-local.js +0 -102
- package/dist/core-runtime/readers/scan-local.test.js +0 -102
- package/dist/core-runtime/readers/scan-tarball.js +0 -121
- package/dist/core-runtime/readers/scan-tarball.test.js +0 -283
- package/dist/core-runtime/readers/scan-vault.js +0 -34
- package/dist/core-runtime/readers/scan-vault.test.js +0 -81
- package/dist/core-runtime/readers/types.js +0 -42
- package/dist/core-runtime/readers/types.test.js +0 -94
- package/dist/core-runtime/readers/viewpoint-collectors.js +0 -229
- package/dist/core-runtime/reconstruct/seed-candidate-validation.js +0 -385
- package/dist/core-runtime/review/citation-audit.test.js +0 -165
- package/dist/core-runtime/review/execution-plan-resolver.js +0 -247
- package/dist/core-runtime/review/execution-plan-resolver.test.js +0 -243
- package/dist/core-runtime/review/execution-topology-resolver-axis-first.test.js +0 -246
- package/dist/core-runtime/review/execution-topology-resolver.js +0 -401
- package/dist/core-runtime/review/execution-topology-resolver.test.js +0 -315
- package/dist/core-runtime/review/inline-context-embedder.test.js +0 -154
- package/dist/core-runtime/review/legacy-mode-policy.js +0 -88
- package/dist/core-runtime/review/materializers-effort-persist.test.js +0 -79
- package/dist/core-runtime/review/ontology-path-classifier.js +0 -179
- package/dist/core-runtime/review/ontology-path-classifier.test.js +0 -216
- package/dist/core-runtime/review/packet-boundary-policy.test.js +0 -107
- package/dist/core-runtime/review/participating-lens-paths.test.js +0 -73
- package/dist/core-runtime/review/review-config-legacy-translate.js +0 -244
- package/dist/core-runtime/review/review-config-legacy-translate.test.js +0 -161
- package/dist/core-runtime/review/review-config-validator.js +0 -289
- package/dist/core-runtime/review/review-config-validator.test.js +0 -236
- package/dist/core-runtime/review/shape-pipeline-audit.test.js +0 -311
- package/dist/core-runtime/review/shape-to-topology-id.js +0 -117
- package/dist/core-runtime/review/shape-to-topology-id.test.js +0 -132
- package/dist/core-runtime/review/topology-shape-derivation.js +0 -155
- package/dist/core-runtime/review/topology-shape-derivation.test.js +0 -195
- package/dist/core-runtime/scope-runtime/constants.js +0 -12
- package/dist/core-runtime/scope-runtime/constraint-pool.js +0 -166
- package/dist/core-runtime/scope-runtime/constraint-pool.test.js +0 -674
- package/dist/core-runtime/scope-runtime/domain-validation-log.js +0 -135
- package/dist/core-runtime/scope-runtime/domain-validation-log.test.js +0 -156
- package/dist/core-runtime/scope-runtime/eval-persistence.js +0 -65
- package/dist/core-runtime/scope-runtime/eval-persistence.test.js +0 -84
- package/dist/core-runtime/scope-runtime/event-pipeline.js +0 -64
- package/dist/core-runtime/scope-runtime/event-pipeline.test.js +0 -450
- package/dist/core-runtime/scope-runtime/event-store.js +0 -39
- package/dist/core-runtime/scope-runtime/event-store.test.js +0 -95
- package/dist/core-runtime/scope-runtime/gate-guard.js +0 -348
- package/dist/core-runtime/scope-runtime/gate-guard.test.js +0 -1047
- package/dist/core-runtime/scope-runtime/hash.js +0 -4
- package/dist/core-runtime/scope-runtime/hash.test.js +0 -33
- package/dist/core-runtime/scope-runtime/id.js +0 -4
- package/dist/core-runtime/scope-runtime/id.test.js +0 -17
- package/dist/core-runtime/scope-runtime/reducer.js +0 -297
- package/dist/core-runtime/scope-runtime/reducer.test.js +0 -759
- package/dist/core-runtime/scope-runtime/scope-manager.js +0 -161
- package/dist/core-runtime/scope-runtime/state-machine.js +0 -309
- package/dist/core-runtime/scope-runtime/state-machine.test.js +0 -704
- package/dist/core-runtime/scope-runtime/types.js +0 -116
- package/dist/core-runtime/scope-runtime/types.test.js +0 -69
- package/dist/core-runtime/translate/render-for-user.js +0 -169
- package/dist/core-runtime/translate/render-for-user.test.js +0 -122
- package/dist/providers/capability-contract.js +0 -1
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* domain-validation-log.ts — Domain knowledge 추정 적중률 계측 seat
|
|
3
|
-
*
|
|
4
|
-
* W-A-73: DL-017 기제 seat (reconstruct).
|
|
5
|
-
* reconstruct(build) 활동에서 발생하는 domain assumption 의
|
|
6
|
-
* validated/invalidated 비율을 기록·산출한다.
|
|
7
|
-
*
|
|
8
|
-
* 측정 대상 (§1.4 측면 3):
|
|
9
|
-
* - certainty 분류: observed / pending / rationale-absent / inferred / ambiguous / not-in-source
|
|
10
|
-
* - 적중률: inferred 분류 중 후속 검증에서 validated 된 비율
|
|
11
|
-
* - 가정 분포: Stage 1/Stage 2 분류 비율
|
|
12
|
-
*
|
|
13
|
-
* reconstruct 활동이 아직 완전 구현되지 않았으므로(W-A-74 pending),
|
|
14
|
-
* 본 모듈은 데이터 모델과 수집·산출 함수의 **seat** 을 제공한다.
|
|
15
|
-
* 실제 reconstruct 파이프라인 연동은 W-A-74 에서 수행.
|
|
16
|
-
*
|
|
17
|
-
* 소비자: W-A-74 (reconstruct-cli), onto:health (W-A-59), refresh protocol (§4)
|
|
18
|
-
*/
|
|
19
|
-
// ─── Core API ───
|
|
20
|
-
/**
|
|
21
|
-
* DomainAssumptionRecord 목록에서 도메인별 적중률 metric 을 산출한다.
|
|
22
|
-
*/
|
|
23
|
-
export function computeValidationMetrics(records) {
|
|
24
|
-
if (records.length === 0) {
|
|
25
|
-
return {
|
|
26
|
-
collected_at: new Date().toISOString(),
|
|
27
|
-
total_records: 0,
|
|
28
|
-
per_domain: [],
|
|
29
|
-
overall_accuracy_ratio: null,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
// 도메인별 그룹화
|
|
33
|
-
const groups = new Map();
|
|
34
|
-
for (const r of records) {
|
|
35
|
-
const group = groups.get(r.domain) ?? [];
|
|
36
|
-
group.push(r);
|
|
37
|
-
groups.set(r.domain, group);
|
|
38
|
-
}
|
|
39
|
-
const perDomain = [];
|
|
40
|
-
let totalValidated = 0;
|
|
41
|
-
let totalInvalidated = 0;
|
|
42
|
-
let totalRevised = 0;
|
|
43
|
-
for (const [domain, group] of groups) {
|
|
44
|
-
const metric = computeDomainMetric(domain, group);
|
|
45
|
-
perDomain.push(metric);
|
|
46
|
-
totalValidated += metric.inferred_validated;
|
|
47
|
-
totalInvalidated += metric.inferred_invalidated;
|
|
48
|
-
totalRevised += metric.inferred_revised;
|
|
49
|
-
}
|
|
50
|
-
perDomain.sort((a, b) => a.domain.localeCompare(b.domain));
|
|
51
|
-
const resolved = totalValidated + totalInvalidated + totalRevised;
|
|
52
|
-
const overallAccuracy = resolved > 0
|
|
53
|
-
? Math.round((totalValidated / resolved) * 1000) / 1000
|
|
54
|
-
: null;
|
|
55
|
-
return {
|
|
56
|
-
collected_at: new Date().toISOString(),
|
|
57
|
-
total_records: records.length,
|
|
58
|
-
per_domain: perDomain,
|
|
59
|
-
overall_accuracy_ratio: overallAccuracy,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
function computeDomainMetric(domain, records) {
|
|
63
|
-
const stage1 = { observed: 0, pending: 0 };
|
|
64
|
-
const stage2 = { rationale_absent: 0, inferred: 0, ambiguous: 0, not_in_source: 0 };
|
|
65
|
-
let inferredValidated = 0;
|
|
66
|
-
let inferredInvalidated = 0;
|
|
67
|
-
let inferredRevised = 0;
|
|
68
|
-
let inferredPending = 0;
|
|
69
|
-
for (const r of records) {
|
|
70
|
-
// Stage 1
|
|
71
|
-
stage1[r.stage1_certainty]++;
|
|
72
|
-
// Stage 2
|
|
73
|
-
if (r.stage2_certainty) {
|
|
74
|
-
const key = r.stage2_certainty.replace("-", "_");
|
|
75
|
-
if (key in stage2)
|
|
76
|
-
stage2[key]++;
|
|
77
|
-
}
|
|
78
|
-
// inferred 검증 추적
|
|
79
|
-
if (r.stage2_certainty === "inferred") {
|
|
80
|
-
switch (r.validation_status) {
|
|
81
|
-
case "validated":
|
|
82
|
-
inferredValidated++;
|
|
83
|
-
break;
|
|
84
|
-
case "invalidated":
|
|
85
|
-
inferredInvalidated++;
|
|
86
|
-
break;
|
|
87
|
-
case "revised":
|
|
88
|
-
inferredRevised++;
|
|
89
|
-
break;
|
|
90
|
-
case "pending":
|
|
91
|
-
inferredPending++;
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
const resolved = inferredValidated + inferredInvalidated + inferredRevised;
|
|
97
|
-
const accuracy = resolved > 0
|
|
98
|
-
? Math.round((inferredValidated / resolved) * 1000) / 1000
|
|
99
|
-
: null;
|
|
100
|
-
return {
|
|
101
|
-
domain,
|
|
102
|
-
total_assumptions: records.length,
|
|
103
|
-
stage1_distribution: stage1,
|
|
104
|
-
stage2_distribution: stage2,
|
|
105
|
-
inferred_validated: inferredValidated,
|
|
106
|
-
inferred_invalidated: inferredInvalidated,
|
|
107
|
-
inferred_revised: inferredRevised,
|
|
108
|
-
inferred_pending: inferredPending,
|
|
109
|
-
accuracy_ratio: accuracy,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* DomainAssumptionRecord 를 생성하는 팩터리.
|
|
114
|
-
* reconstruct 파이프라인(W-A-74)에서 가정 발견 시 호출.
|
|
115
|
-
*/
|
|
116
|
-
export function createAssumptionRecord(params) {
|
|
117
|
-
return {
|
|
118
|
-
...params,
|
|
119
|
-
validation_status: "pending",
|
|
120
|
-
validated_at: null,
|
|
121
|
-
validation_evidence: null,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* 기존 record 에 검증 결과를 기록한다.
|
|
126
|
-
* Phase 3 (주체자 확인) 에서 호출.
|
|
127
|
-
*/
|
|
128
|
-
export function markValidation(record, status, evidence) {
|
|
129
|
-
return {
|
|
130
|
-
...record,
|
|
131
|
-
validation_status: status,
|
|
132
|
-
validated_at: new Date().toISOString(),
|
|
133
|
-
validation_evidence: evidence,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { computeValidationMetrics, createAssumptionRecord, markValidation, } from "./domain-validation-log.js";
|
|
3
|
-
// ─── Test helpers ───
|
|
4
|
-
function makeRecord(overrides = {}) {
|
|
5
|
-
return {
|
|
6
|
-
assumption_id: "a-001",
|
|
7
|
-
session_id: "20260414-test",
|
|
8
|
-
domain: "SE",
|
|
9
|
-
stage1_certainty: "pending",
|
|
10
|
-
stage2_certainty: "inferred",
|
|
11
|
-
description: "test assumption",
|
|
12
|
-
abduction_quality: { explanatory_power: "high", coherence: "consistent" },
|
|
13
|
-
validation_status: "pending",
|
|
14
|
-
validated_at: null,
|
|
15
|
-
validation_evidence: null,
|
|
16
|
-
...overrides,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
// ─── Tests ───
|
|
20
|
-
describe("domain-validation-log", () => {
|
|
21
|
-
describe("computeValidationMetrics", () => {
|
|
22
|
-
it("빈 records 에서 null accuracy 를 반환한다", () => {
|
|
23
|
-
const result = computeValidationMetrics([]);
|
|
24
|
-
expect(result.total_records).toBe(0);
|
|
25
|
-
expect(result.per_domain).toHaveLength(0);
|
|
26
|
-
expect(result.overall_accuracy_ratio).toBeNull();
|
|
27
|
-
});
|
|
28
|
-
it("단일 도메인의 stage1/stage2 분포를 산출한다", () => {
|
|
29
|
-
const records = [
|
|
30
|
-
makeRecord({ assumption_id: "a-001", stage1_certainty: "observed", stage2_certainty: null }),
|
|
31
|
-
makeRecord({ assumption_id: "a-002", stage1_certainty: "pending", stage2_certainty: "inferred" }),
|
|
32
|
-
makeRecord({ assumption_id: "a-003", stage1_certainty: "pending", stage2_certainty: "rationale-absent" }),
|
|
33
|
-
makeRecord({ assumption_id: "a-004", stage1_certainty: "pending", stage2_certainty: "ambiguous" }),
|
|
34
|
-
];
|
|
35
|
-
const result = computeValidationMetrics(records);
|
|
36
|
-
expect(result.per_domain).toHaveLength(1);
|
|
37
|
-
const se = result.per_domain[0];
|
|
38
|
-
expect(se.domain).toBe("SE");
|
|
39
|
-
expect(se.stage1_distribution.observed).toBe(1);
|
|
40
|
-
expect(se.stage1_distribution.pending).toBe(3);
|
|
41
|
-
expect(se.stage2_distribution.inferred).toBe(1);
|
|
42
|
-
expect(se.stage2_distribution.rationale_absent).toBe(1);
|
|
43
|
-
expect(se.stage2_distribution.ambiguous).toBe(1);
|
|
44
|
-
});
|
|
45
|
-
it("inferred 검증 결과 별 카운트를 정확히 산출한다", () => {
|
|
46
|
-
const records = [
|
|
47
|
-
makeRecord({ assumption_id: "a-001", validation_status: "validated" }),
|
|
48
|
-
makeRecord({ assumption_id: "a-002", validation_status: "validated" }),
|
|
49
|
-
makeRecord({ assumption_id: "a-003", validation_status: "invalidated" }),
|
|
50
|
-
makeRecord({ assumption_id: "a-004", validation_status: "pending" }),
|
|
51
|
-
];
|
|
52
|
-
const result = computeValidationMetrics(records);
|
|
53
|
-
const se = result.per_domain[0];
|
|
54
|
-
expect(se.inferred_validated).toBe(2);
|
|
55
|
-
expect(se.inferred_invalidated).toBe(1);
|
|
56
|
-
expect(se.inferred_pending).toBe(1);
|
|
57
|
-
});
|
|
58
|
-
it("적중률을 정확히 계산한다 (validated / resolved)", () => {
|
|
59
|
-
const records = [
|
|
60
|
-
makeRecord({ assumption_id: "a-001", validation_status: "validated" }),
|
|
61
|
-
makeRecord({ assumption_id: "a-002", validation_status: "validated" }),
|
|
62
|
-
makeRecord({ assumption_id: "a-003", validation_status: "invalidated" }),
|
|
63
|
-
makeRecord({ assumption_id: "a-004", validation_status: "revised" }),
|
|
64
|
-
];
|
|
65
|
-
const result = computeValidationMetrics(records);
|
|
66
|
-
// 2 validated / (2 + 1 + 1) = 0.5
|
|
67
|
-
expect(result.per_domain[0].accuracy_ratio).toBe(0.5);
|
|
68
|
-
expect(result.overall_accuracy_ratio).toBe(0.5);
|
|
69
|
-
});
|
|
70
|
-
it("검증 완료 건이 없으면 accuracy null 을 반환한다", () => {
|
|
71
|
-
const records = [
|
|
72
|
-
makeRecord({ assumption_id: "a-001", validation_status: "pending" }),
|
|
73
|
-
makeRecord({ assumption_id: "a-002", validation_status: "pending" }),
|
|
74
|
-
];
|
|
75
|
-
const result = computeValidationMetrics(records);
|
|
76
|
-
expect(result.per_domain[0].accuracy_ratio).toBeNull();
|
|
77
|
-
expect(result.overall_accuracy_ratio).toBeNull();
|
|
78
|
-
});
|
|
79
|
-
it("여러 도메인을 별도 그룹으로 산출한다", () => {
|
|
80
|
-
const records = [
|
|
81
|
-
makeRecord({ assumption_id: "a-001", domain: "SE", validation_status: "validated" }),
|
|
82
|
-
makeRecord({ assumption_id: "a-002", domain: "SE", validation_status: "invalidated" }),
|
|
83
|
-
makeRecord({ assumption_id: "a-003", domain: "Business", validation_status: "validated" }),
|
|
84
|
-
];
|
|
85
|
-
const result = computeValidationMetrics(records);
|
|
86
|
-
expect(result.per_domain).toHaveLength(2);
|
|
87
|
-
expect(result.total_records).toBe(3);
|
|
88
|
-
const business = result.per_domain.find((d) => d.domain === "Business");
|
|
89
|
-
expect(business.accuracy_ratio).toBe(1.0);
|
|
90
|
-
const se = result.per_domain.find((d) => d.domain === "SE");
|
|
91
|
-
expect(se.accuracy_ratio).toBe(0.5);
|
|
92
|
-
});
|
|
93
|
-
it("overall_accuracy_ratio 는 전체 도메인 합산 기준이다", () => {
|
|
94
|
-
const records = [
|
|
95
|
-
makeRecord({ assumption_id: "a-001", domain: "SE", validation_status: "validated" }),
|
|
96
|
-
makeRecord({ assumption_id: "a-002", domain: "SE", validation_status: "invalidated" }),
|
|
97
|
-
makeRecord({ assumption_id: "a-003", domain: "Business", validation_status: "validated" }),
|
|
98
|
-
makeRecord({ assumption_id: "a-004", domain: "Business", validation_status: "validated" }),
|
|
99
|
-
];
|
|
100
|
-
const result = computeValidationMetrics(records);
|
|
101
|
-
// 3 validated / (3 + 1) = 0.75
|
|
102
|
-
expect(result.overall_accuracy_ratio).toBe(0.75);
|
|
103
|
-
});
|
|
104
|
-
it("non-inferred 항목은 적중률 계산에서 제외된다", () => {
|
|
105
|
-
const records = [
|
|
106
|
-
makeRecord({ assumption_id: "a-001", stage2_certainty: "inferred", validation_status: "validated" }),
|
|
107
|
-
makeRecord({ assumption_id: "a-002", stage2_certainty: "rationale-absent", validation_status: "validated" }),
|
|
108
|
-
makeRecord({ assumption_id: "a-003", stage2_certainty: "ambiguous", validation_status: "validated" }),
|
|
109
|
-
];
|
|
110
|
-
const result = computeValidationMetrics(records);
|
|
111
|
-
const se = result.per_domain[0];
|
|
112
|
-
// inferred 1건만 validated → accuracy 1.0
|
|
113
|
-
expect(se.inferred_validated).toBe(1);
|
|
114
|
-
expect(se.accuracy_ratio).toBe(1.0);
|
|
115
|
-
});
|
|
116
|
-
it("도메인을 알파벳순 정렬한다", () => {
|
|
117
|
-
const records = [
|
|
118
|
-
makeRecord({ assumption_id: "a-001", domain: "Zebra" }),
|
|
119
|
-
makeRecord({ assumption_id: "a-002", domain: "Alpha" }),
|
|
120
|
-
];
|
|
121
|
-
const result = computeValidationMetrics(records);
|
|
122
|
-
expect(result.per_domain[0].domain).toBe("Alpha");
|
|
123
|
-
expect(result.per_domain[1].domain).toBe("Zebra");
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
describe("createAssumptionRecord", () => {
|
|
127
|
-
it("validation_status=pending 으로 초기화한다", () => {
|
|
128
|
-
const record = createAssumptionRecord({
|
|
129
|
-
assumption_id: "a-new",
|
|
130
|
-
session_id: "20260414-new",
|
|
131
|
-
domain: "SE",
|
|
132
|
-
stage1_certainty: "pending",
|
|
133
|
-
stage2_certainty: "inferred",
|
|
134
|
-
description: "new assumption",
|
|
135
|
-
abduction_quality: { explanatory_power: "medium", coherence: "consistent" },
|
|
136
|
-
});
|
|
137
|
-
expect(record.validation_status).toBe("pending");
|
|
138
|
-
expect(record.validated_at).toBeNull();
|
|
139
|
-
expect(record.validation_evidence).toBeNull();
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
describe("markValidation", () => {
|
|
143
|
-
it("검증 결과를 기록한다", () => {
|
|
144
|
-
const record = makeRecord({ assumption_id: "a-001" });
|
|
145
|
-
const validated = markValidation(record, "validated", "confirmed by user");
|
|
146
|
-
expect(validated.validation_status).toBe("validated");
|
|
147
|
-
expect(validated.validated_at).toBeTruthy();
|
|
148
|
-
expect(validated.validation_evidence).toBe("confirmed by user");
|
|
149
|
-
});
|
|
150
|
-
it("원본을 변경하지 않는다 (immutable)", () => {
|
|
151
|
-
const record = makeRecord({ assumption_id: "a-001" });
|
|
152
|
-
markValidation(record, "invalidated", "wrong assumption");
|
|
153
|
-
expect(record.validation_status).toBe("pending");
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
});
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* eval-persistence — 산출물 재사용 횟수·비율 측정 (W-C-04, §1.4 측면 2 지속성).
|
|
3
|
-
*
|
|
4
|
-
* 지속성 = LLM 모델 교체 전후 eval 통과율 회귀 0.
|
|
5
|
-
* 본 모듈은 산출물 (review record, learning, ontology) 이 **재사용** 되는 이벤트를 기록하고,
|
|
6
|
-
* 재사용 횟수·비율을 산출하는 계측 seat.
|
|
7
|
-
*
|
|
8
|
-
* 저장: .onto/eval/persistence-log.ndjson (product-local, append-only event log)
|
|
9
|
-
*
|
|
10
|
-
* 이벤트 타입:
|
|
11
|
-
* - artifact_reuse: 기존 산출물이 새 session 에서 소비됨 (예: learning load, ontology reference)
|
|
12
|
-
*
|
|
13
|
-
* 소비자:
|
|
14
|
-
* - §1.4 지속성 metric dashboard (향후)
|
|
15
|
-
* - W-C-05 consumption feedback 와 보완 관계 (W-C-05 = learning 소비 baseline, W-C-04 = 산출물 전반 재사용)
|
|
16
|
-
*/
|
|
17
|
-
import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
18
|
-
import { dirname, join } from "node:path";
|
|
19
|
-
export function resolveEvalPath(projectRoot) {
|
|
20
|
-
return join(projectRoot, ".onto", "eval", "persistence-log.ndjson");
|
|
21
|
-
}
|
|
22
|
-
export function logArtifactReuse(projectRoot, event, now = new Date()) {
|
|
23
|
-
const logPath = resolveEvalPath(projectRoot);
|
|
24
|
-
const dir = dirname(logPath);
|
|
25
|
-
if (!existsSync(dir))
|
|
26
|
-
mkdirSync(dir, { recursive: true });
|
|
27
|
-
const full = {
|
|
28
|
-
type: "artifact_reuse",
|
|
29
|
-
...event,
|
|
30
|
-
reused_at: now.toISOString(),
|
|
31
|
-
};
|
|
32
|
-
appendFileSync(logPath, JSON.stringify(full) + "\n", "utf-8");
|
|
33
|
-
}
|
|
34
|
-
export function readReuseEvents(projectRoot) {
|
|
35
|
-
const logPath = resolveEvalPath(projectRoot);
|
|
36
|
-
if (!existsSync(logPath))
|
|
37
|
-
return [];
|
|
38
|
-
const raw = readFileSync(logPath, "utf-8");
|
|
39
|
-
const events = [];
|
|
40
|
-
for (const line of raw.split("\n")) {
|
|
41
|
-
if (!line.trim())
|
|
42
|
-
continue;
|
|
43
|
-
try {
|
|
44
|
-
const parsed = JSON.parse(line);
|
|
45
|
-
if (parsed?.type === "artifact_reuse")
|
|
46
|
-
events.push(parsed);
|
|
47
|
-
}
|
|
48
|
-
catch { /* skip malformed */ }
|
|
49
|
-
}
|
|
50
|
-
return events;
|
|
51
|
-
}
|
|
52
|
-
export function computePersistenceMetrics(events) {
|
|
53
|
-
const byKind = {};
|
|
54
|
-
const uniqueRefs = new Set();
|
|
55
|
-
for (const ev of events) {
|
|
56
|
-
byKind[ev.artifact_kind] = (byKind[ev.artifact_kind] ?? 0) + 1;
|
|
57
|
-
uniqueRefs.add(`${ev.artifact_kind}:${ev.artifact_ref}`);
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
total_reuse_events: events.length,
|
|
61
|
-
by_kind: byKind,
|
|
62
|
-
unique_artifacts: uniqueRefs.size,
|
|
63
|
-
reuse_ratio: uniqueRefs.size > 0 ? events.length / uniqueRefs.size : 0,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* eval-persistence unit tests (W-C-04).
|
|
3
|
-
*/
|
|
4
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
5
|
-
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
6
|
-
import { tmpdir } from "node:os";
|
|
7
|
-
import { join } from "node:path";
|
|
8
|
-
import { computePersistenceMetrics, logArtifactReuse, readReuseEvents, resolveEvalPath, } from "./eval-persistence.js";
|
|
9
|
-
describe("eval-persistence", () => {
|
|
10
|
-
let tmpRoot;
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
tmpRoot = mkdtempSync(join(tmpdir(), "onto-eval-persist-"));
|
|
13
|
-
});
|
|
14
|
-
afterEach(() => rmSync(tmpRoot, { recursive: true, force: true }));
|
|
15
|
-
it("logArtifactReuse appends ndjson event", () => {
|
|
16
|
-
logArtifactReuse(tmpRoot, {
|
|
17
|
-
artifact_kind: "learning",
|
|
18
|
-
artifact_ref: "~/.onto/learnings/logic.md:42",
|
|
19
|
-
consumer_session: "20260416-review-001",
|
|
20
|
-
consumer_activity: "review",
|
|
21
|
-
});
|
|
22
|
-
const raw = readFileSync(resolveEvalPath(tmpRoot), "utf-8");
|
|
23
|
-
const event = JSON.parse(raw.trim());
|
|
24
|
-
expect(event.type).toBe("artifact_reuse");
|
|
25
|
-
expect(event.artifact_kind).toBe("learning");
|
|
26
|
-
expect(event.artifact_ref).toBe("~/.onto/learnings/logic.md:42");
|
|
27
|
-
expect(event.consumer_activity).toBe("review");
|
|
28
|
-
expect(event.reused_at).toBeDefined();
|
|
29
|
-
});
|
|
30
|
-
it("multiple events appended as separate lines", () => {
|
|
31
|
-
logArtifactReuse(tmpRoot, {
|
|
32
|
-
artifact_kind: "learning",
|
|
33
|
-
artifact_ref: "logic.md:1",
|
|
34
|
-
consumer_session: "s1",
|
|
35
|
-
consumer_activity: "review",
|
|
36
|
-
});
|
|
37
|
-
logArtifactReuse(tmpRoot, {
|
|
38
|
-
artifact_kind: "ontology",
|
|
39
|
-
artifact_ref: "builds/001/output.yaml",
|
|
40
|
-
consumer_session: "s2",
|
|
41
|
-
consumer_activity: "evolve",
|
|
42
|
-
});
|
|
43
|
-
const events = readReuseEvents(tmpRoot);
|
|
44
|
-
expect(events.length).toBe(2);
|
|
45
|
-
expect(events[0].artifact_kind).toBe("learning");
|
|
46
|
-
expect(events[1].artifact_kind).toBe("ontology");
|
|
47
|
-
});
|
|
48
|
-
it("readReuseEvents returns empty for nonexistent file", () => {
|
|
49
|
-
expect(readReuseEvents(tmpRoot)).toEqual([]);
|
|
50
|
-
});
|
|
51
|
-
it("computePersistenceMetrics calculates correctly", () => {
|
|
52
|
-
logArtifactReuse(tmpRoot, {
|
|
53
|
-
artifact_kind: "learning",
|
|
54
|
-
artifact_ref: "logic.md:1",
|
|
55
|
-
consumer_session: "s1",
|
|
56
|
-
consumer_activity: "review",
|
|
57
|
-
});
|
|
58
|
-
logArtifactReuse(tmpRoot, {
|
|
59
|
-
artifact_kind: "learning",
|
|
60
|
-
artifact_ref: "logic.md:1",
|
|
61
|
-
consumer_session: "s2",
|
|
62
|
-
consumer_activity: "evolve",
|
|
63
|
-
});
|
|
64
|
-
logArtifactReuse(tmpRoot, {
|
|
65
|
-
artifact_kind: "review_record",
|
|
66
|
-
artifact_ref: "record-001.yaml",
|
|
67
|
-
consumer_session: "s3",
|
|
68
|
-
consumer_activity: "learn",
|
|
69
|
-
});
|
|
70
|
-
const events = readReuseEvents(tmpRoot);
|
|
71
|
-
const metrics = computePersistenceMetrics(events);
|
|
72
|
-
expect(metrics.total_reuse_events).toBe(3);
|
|
73
|
-
expect(metrics.by_kind.learning).toBe(2);
|
|
74
|
-
expect(metrics.by_kind.review_record).toBe(1);
|
|
75
|
-
expect(metrics.unique_artifacts).toBe(2);
|
|
76
|
-
expect(metrics.reuse_ratio).toBe(1.5);
|
|
77
|
-
});
|
|
78
|
-
it("computePersistenceMetrics handles empty events", () => {
|
|
79
|
-
const metrics = computePersistenceMetrics([]);
|
|
80
|
-
expect(metrics.total_reuse_events).toBe(0);
|
|
81
|
-
expect(metrics.unique_artifacts).toBe(0);
|
|
82
|
-
expect(metrics.reuse_ratio).toBe(0);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { writeFileSync } from "node:fs";
|
|
2
|
-
import { readEvents, appendEvent } from "./event-store.js";
|
|
3
|
-
import { reduce } from "./reducer.js";
|
|
4
|
-
import { validateEvent } from "./gate-guard.js";
|
|
5
|
-
import { makeId } from "./id.js";
|
|
6
|
-
// ─── Main pipeline ───
|
|
7
|
-
/**
|
|
8
|
-
* Append an event to a scope through the full pipeline:
|
|
9
|
-
* 1. Read current events → reduce to current state
|
|
10
|
-
* 2. Validate the new event (gate-guard)
|
|
11
|
-
* 3. Generate envelope (event_id, scope_id, ts, revision, state_before, state_after)
|
|
12
|
-
* 4. Append to event store
|
|
13
|
-
* 5. Re-reduce → write kernel materialized views (constraint-pool.json, verdict-log.json)
|
|
14
|
-
*
|
|
15
|
-
* Returns the updated ScopeState so the caller can render scope.md
|
|
16
|
-
* or other view-layer outputs without kernel depending on renderers.
|
|
17
|
-
*
|
|
18
|
-
* This is the ONLY path for recording events. No other code should
|
|
19
|
-
* call event-store.appendEvent directly.
|
|
20
|
-
*/
|
|
21
|
-
export function appendScopeEvent(paths, input, gateOptions) {
|
|
22
|
-
// ── Step 1: Current state ──
|
|
23
|
-
const currentEvents = readEvents(paths.events);
|
|
24
|
-
const currentState = reduce(currentEvents);
|
|
25
|
-
// ── Step 2: Build temporary event for validation ──
|
|
26
|
-
const revision = currentEvents.length + 1;
|
|
27
|
-
const tempEvent = {
|
|
28
|
-
event_id: makeId("evt_", revision),
|
|
29
|
-
scope_id: paths.scopeId,
|
|
30
|
-
type: input.type,
|
|
31
|
-
ts: new Date().toISOString(),
|
|
32
|
-
revision,
|
|
33
|
-
actor: input.actor,
|
|
34
|
-
state_before: input.type === "scope.created" ? null : currentState.current_state,
|
|
35
|
-
state_after: "draft", // placeholder, gate-guard determines actual value
|
|
36
|
-
payload: input.payload,
|
|
37
|
-
};
|
|
38
|
-
// ── Step 3: Validate ──
|
|
39
|
-
const gate = validateEvent(currentState, tempEvent, gateOptions);
|
|
40
|
-
if (!gate.allowed) {
|
|
41
|
-
return {
|
|
42
|
-
success: false,
|
|
43
|
-
reason: gate.reason,
|
|
44
|
-
current_state: currentState.current_state,
|
|
45
|
-
rejected_type: input.type,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
// ── Step 4: Set final state_after and append ──
|
|
49
|
-
const eventToAppend = {
|
|
50
|
-
...tempEvent,
|
|
51
|
-
state_after: gate.next_state,
|
|
52
|
-
};
|
|
53
|
-
appendEvent(paths.events, eventToAppend);
|
|
54
|
-
// ── Step 5: Incremental reduce (reuse currentEvents instead of re-reading) ──
|
|
55
|
-
const updatedState = reduce([...currentEvents, eventToAppend]);
|
|
56
|
-
writeFileSync(paths.constraintPool, JSON.stringify(updatedState.constraint_pool, null, 2) + "\n", "utf-8");
|
|
57
|
-
writeFileSync(paths.verdictLog, JSON.stringify(updatedState.verdict_log, null, 2) + "\n", "utf-8");
|
|
58
|
-
return {
|
|
59
|
-
success: true,
|
|
60
|
-
event: eventToAppend,
|
|
61
|
-
next_state: gate.next_state,
|
|
62
|
-
state: updatedState,
|
|
63
|
-
};
|
|
64
|
-
}
|