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,306 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { readFileSync } from "node:fs";
|
|
3
|
-
import { resolve } from "node:path";
|
|
4
|
-
import { renderScopeMd } from "./scope-md.js";
|
|
5
|
-
import { reduce } from "../../scope-runtime/reducer.js";
|
|
6
|
-
// ─── Helpers ───
|
|
7
|
-
function emptyPool() {
|
|
8
|
-
return {
|
|
9
|
-
constraints: [],
|
|
10
|
-
summary: { total: 0, required: 0, recommended: 0, decided: 0, clarify_pending: 0, invalidated: 0, undecided: 0 },
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
function makeState(overrides = {}) {
|
|
14
|
-
return {
|
|
15
|
-
scope_id: "SC-TEST",
|
|
16
|
-
title: "테스트 Scope",
|
|
17
|
-
description: "테스트용",
|
|
18
|
-
entry_mode: "experience",
|
|
19
|
-
current_state: "draft",
|
|
20
|
-
constraint_pool: emptyPool(),
|
|
21
|
-
stale: false,
|
|
22
|
-
compile_ready: false,
|
|
23
|
-
convergence_blocked: false,
|
|
24
|
-
revision_count_align: 0,
|
|
25
|
-
revision_count_surface: 0,
|
|
26
|
-
retry_count_compile: 0,
|
|
27
|
-
snapshot_revision: 0,
|
|
28
|
-
pre_apply_completed: false,
|
|
29
|
-
prd_review_completed: false,
|
|
30
|
-
verdict_log: [],
|
|
31
|
-
feedback_history: [],
|
|
32
|
-
latest_revision: 0,
|
|
33
|
-
...overrides,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
// ─── Golden data ───
|
|
37
|
-
describe("scope-md — golden data", () => {
|
|
38
|
-
it("renders scope.md from golden events", () => {
|
|
39
|
-
const goldenPath = resolve(import.meta.dirname, "../../scope-runtime/__fixtures__/example-tutor-block/events.ndjson");
|
|
40
|
-
const events = readFileSync(goldenPath, "utf-8")
|
|
41
|
-
.trimEnd()
|
|
42
|
-
.split("\n")
|
|
43
|
-
.map((line) => JSON.parse(line));
|
|
44
|
-
const state = reduce(events);
|
|
45
|
-
const md = renderScopeMd(state);
|
|
46
|
-
expect(md).toContain("# Scope: 튜터 차단 기능");
|
|
47
|
-
expect(md).toContain("Build Spec 생성 완료");
|
|
48
|
-
expect(md).toContain("방향");
|
|
49
|
-
expect(md).toContain("학생이 튜터를 차단하면");
|
|
50
|
-
expect(md).toContain("전체: 8건");
|
|
51
|
-
expect(md).toContain("결정 완료: 8건");
|
|
52
|
-
expect(md).toContain("revision 29");
|
|
53
|
-
// verdict_log shows last 5: CST-004~008 (CST-001 is older, trimmed)
|
|
54
|
-
expect(md).toContain("CST-008");
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
// ─── Structure tests ───
|
|
58
|
-
describe("scope-md — structure", () => {
|
|
59
|
-
it("renders header with title from state", () => {
|
|
60
|
-
const md = renderScopeMd(makeState({ title: "My Scope" }));
|
|
61
|
-
expect(md).toContain("# Scope: My Scope");
|
|
62
|
-
});
|
|
63
|
-
it("shows current state in human-readable form", () => {
|
|
64
|
-
const md = renderScopeMd(makeState({ current_state: "surface_confirmed" }));
|
|
65
|
-
expect(md).toContain("Surface 확정됨");
|
|
66
|
-
});
|
|
67
|
-
it("shows direction when present", () => {
|
|
68
|
-
const md = renderScopeMd(makeState({ direction: "test direction" }));
|
|
69
|
-
expect(md).toContain("**방향**: test direction");
|
|
70
|
-
});
|
|
71
|
-
it("omits direction when absent", () => {
|
|
72
|
-
const md = renderScopeMd(makeState());
|
|
73
|
-
expect(md).not.toContain("**방향**");
|
|
74
|
-
});
|
|
75
|
-
it("shows scope boundaries when locked", () => {
|
|
76
|
-
const md = renderScopeMd(makeState({
|
|
77
|
-
scope_boundaries: { in: ["기능A", "기능B"], out: ["기능C"] },
|
|
78
|
-
}));
|
|
79
|
-
expect(md).toContain("## 범위");
|
|
80
|
-
expect(md).toContain("기능A");
|
|
81
|
-
expect(md).toContain("기능C");
|
|
82
|
-
});
|
|
83
|
-
it("omits scope boundaries when not locked", () => {
|
|
84
|
-
const md = renderScopeMd(makeState());
|
|
85
|
-
expect(md).not.toContain("## 범위");
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
// ─── Next action ───
|
|
89
|
-
describe("scope-md — next action", () => {
|
|
90
|
-
it("draft → scan sources", () => {
|
|
91
|
-
const md = renderScopeMd(makeState({ current_state: "draft" }));
|
|
92
|
-
expect(md).toContain("/start");
|
|
93
|
-
});
|
|
94
|
-
it("surface_confirmed with undecided → decide constraints", () => {
|
|
95
|
-
const pool = emptyPool();
|
|
96
|
-
pool.summary.total = 3;
|
|
97
|
-
pool.summary.undecided = 2;
|
|
98
|
-
const md = renderScopeMd(makeState({ current_state: "surface_confirmed", constraint_pool: pool }));
|
|
99
|
-
expect(md).toContain("2건의 제약 사항");
|
|
100
|
-
});
|
|
101
|
-
it("surface_confirmed with clarify_pending → resolve clarify", () => {
|
|
102
|
-
const pool = emptyPool();
|
|
103
|
-
pool.summary.total = 3;
|
|
104
|
-
pool.summary.clarify_pending = 1;
|
|
105
|
-
const md = renderScopeMd(makeState({ current_state: "surface_confirmed", constraint_pool: pool }));
|
|
106
|
-
expect(md).toContain("clarify");
|
|
107
|
-
});
|
|
108
|
-
it("closed → scope terminated", () => {
|
|
109
|
-
const md = renderScopeMd(makeState({ current_state: "closed" }));
|
|
110
|
-
expect(md).toContain("종료");
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
// ─── Blockers ───
|
|
114
|
-
describe("scope-md — blockers", () => {
|
|
115
|
-
it("shows stale blocker with source details", () => {
|
|
116
|
-
const md = renderScopeMd(makeState({
|
|
117
|
-
stale: true,
|
|
118
|
-
stale_sources: [{ path: "src/a.ts", old_hash: "h1", new_hash: "h2" }],
|
|
119
|
-
stale_since: 10,
|
|
120
|
-
}));
|
|
121
|
-
expect(md).toContain("## 차단 상태");
|
|
122
|
-
expect(md).toContain("src/a.ts");
|
|
123
|
-
expect(md).toContain("revision 10");
|
|
124
|
-
});
|
|
125
|
-
it("shows convergence blocker", () => {
|
|
126
|
-
const md = renderScopeMd(makeState({ convergence_blocked: true }));
|
|
127
|
-
expect(md).toContain("수렴 차단");
|
|
128
|
-
});
|
|
129
|
-
it("shows clarify blocker", () => {
|
|
130
|
-
const pool = emptyPool();
|
|
131
|
-
pool.summary.total = 2;
|
|
132
|
-
pool.summary.clarify_pending = 1;
|
|
133
|
-
const md = renderScopeMd(makeState({ constraint_pool: pool }));
|
|
134
|
-
expect(md).toContain("clarify 미해소");
|
|
135
|
-
});
|
|
136
|
-
it("omits blocker section when no blockers", () => {
|
|
137
|
-
const md = renderScopeMd(makeState());
|
|
138
|
-
expect(md).not.toContain("## 차단 상태");
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
// ─── Constraint summary ───
|
|
142
|
-
describe("scope-md — constraint summary", () => {
|
|
143
|
-
it("shows constraint counts", () => {
|
|
144
|
-
const pool = emptyPool();
|
|
145
|
-
pool.summary = { total: 8, required: 3, recommended: 5, decided: 6, clarify_pending: 1, invalidated: 0, undecided: 1 };
|
|
146
|
-
const md = renderScopeMd(makeState({ constraint_pool: pool }));
|
|
147
|
-
expect(md).toContain("전체: 8건");
|
|
148
|
-
expect(md).toContain("필수 3");
|
|
149
|
-
expect(md).toContain("결정 완료: 6건");
|
|
150
|
-
expect(md).toContain("미결정: 1건");
|
|
151
|
-
expect(md).toContain("clarify 대기: 1건");
|
|
152
|
-
});
|
|
153
|
-
it("omits constraint section when total is 0", () => {
|
|
154
|
-
const md = renderScopeMd(makeState());
|
|
155
|
-
expect(md).not.toContain("## Constraint 현황");
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
// ─── Edge cases: convergence_blocked override, stale with undefined, empty verdict_log ───
|
|
159
|
-
describe("scope-md — edge cases", () => {
|
|
160
|
-
it("convergence_blocked overrides next action message", () => {
|
|
161
|
-
const md = renderScopeMd(makeState({
|
|
162
|
-
current_state: "surface_iterating",
|
|
163
|
-
convergence_blocked: true,
|
|
164
|
-
}));
|
|
165
|
-
expect(md).toContain("수렴 차단 상태입니다");
|
|
166
|
-
expect(md).toContain("방향 변경");
|
|
167
|
-
});
|
|
168
|
-
it("stale with undefined stale_sources shows '알 수 없음'", () => {
|
|
169
|
-
const md = renderScopeMd(makeState({
|
|
170
|
-
stale: true,
|
|
171
|
-
stale_sources: undefined,
|
|
172
|
-
stale_since: undefined,
|
|
173
|
-
}));
|
|
174
|
-
expect(md).toContain("알 수 없음");
|
|
175
|
-
expect(md).toContain("?");
|
|
176
|
-
});
|
|
177
|
-
it("empty verdict_log omits 최근 결정 section", () => {
|
|
178
|
-
const md = renderScopeMd(makeState({ verdict_log: [] }));
|
|
179
|
-
expect(md).not.toContain("## 최근 결정");
|
|
180
|
-
});
|
|
181
|
-
it("verdict_log with clarify_resolved renders correctly", () => {
|
|
182
|
-
const md = renderScopeMd(makeState({
|
|
183
|
-
verdict_log: [
|
|
184
|
-
{ type: "constraint.clarify_resolved", revision: 15, ts: "2026-01-01T00:00:15Z", constraint_id: "CST-002", decision: "inject", decision_owner: "product_owner" },
|
|
185
|
-
],
|
|
186
|
-
}));
|
|
187
|
-
expect(md).toContain("## 최근 결정");
|
|
188
|
-
expect(md).toContain("CST-002 clarify 해소");
|
|
189
|
-
expect(md).toContain("inject");
|
|
190
|
-
});
|
|
191
|
-
it("constraint summary omits undecided/clarify/invalidated lines when zero", () => {
|
|
192
|
-
const pool = emptyPool();
|
|
193
|
-
pool.summary = { total: 3, required: 2, recommended: 1, decided: 3, clarify_pending: 0, invalidated: 0, undecided: 0 };
|
|
194
|
-
const md = renderScopeMd(makeState({ constraint_pool: pool }));
|
|
195
|
-
expect(md).toContain("전체: 3건");
|
|
196
|
-
expect(md).toContain("결정 완료: 3건");
|
|
197
|
-
expect(md).not.toContain("미결정:");
|
|
198
|
-
expect(md).not.toContain("clarify 대기:");
|
|
199
|
-
expect(md).not.toContain("제외됨:");
|
|
200
|
-
});
|
|
201
|
-
it("terminal states show appropriate messages", () => {
|
|
202
|
-
expect(renderScopeMd(makeState({ current_state: "closed" }))).toContain("완료");
|
|
203
|
-
expect(renderScopeMd(makeState({ current_state: "deferred" }))).toContain("보류");
|
|
204
|
-
expect(renderScopeMd(makeState({ current_state: "rejected" }))).toContain("거절");
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
// ─── Backward transition ───
|
|
208
|
-
describe("scope-md — backward transition", () => {
|
|
209
|
-
it("shows compile retry blocker when constraints_resolved with retry_count > 0", () => {
|
|
210
|
-
const md = renderScopeMd(makeState({
|
|
211
|
-
current_state: "constraints_resolved",
|
|
212
|
-
retry_count_compile: 1,
|
|
213
|
-
}));
|
|
214
|
-
expect(md).toContain("## 차단 상태");
|
|
215
|
-
expect(md).toContain("compile 중 새 제약이 발견되어 결정이 필요합니다");
|
|
216
|
-
expect(md).toContain("재시도 1/3회");
|
|
217
|
-
});
|
|
218
|
-
it("shows retry count 2/3 in blocker message", () => {
|
|
219
|
-
const md = renderScopeMd(makeState({
|
|
220
|
-
current_state: "constraints_resolved",
|
|
221
|
-
retry_count_compile: 2,
|
|
222
|
-
}));
|
|
223
|
-
expect(md).toContain("재시도 2/3회");
|
|
224
|
-
});
|
|
225
|
-
it("does not show compile retry blocker when retry_count is 0", () => {
|
|
226
|
-
const md = renderScopeMd(makeState({
|
|
227
|
-
current_state: "constraints_resolved",
|
|
228
|
-
retry_count_compile: 0,
|
|
229
|
-
}));
|
|
230
|
-
expect(md).not.toContain("compile 중 새 제약이 발견되어");
|
|
231
|
-
});
|
|
232
|
-
it("does not show compile retry blocker for other states even with retry_count > 0", () => {
|
|
233
|
-
const md = renderScopeMd(makeState({
|
|
234
|
-
current_state: "target_locked",
|
|
235
|
-
retry_count_compile: 1,
|
|
236
|
-
}));
|
|
237
|
-
expect(md).not.toContain("compile 중 새 제약이 발견되어");
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
// ─── Verdict log ───
|
|
241
|
-
describe("scope-md — verdict log", () => {
|
|
242
|
-
it("shows recent decisions (last 5)", () => {
|
|
243
|
-
const md = renderScopeMd(makeState({
|
|
244
|
-
verdict_log: [
|
|
245
|
-
{ type: "align.locked", revision: 8, ts: "2026-01-01T00:00:08Z", locked_direction: "dir" },
|
|
246
|
-
{ type: "constraint.decision_recorded", revision: 19, ts: "2026-01-01T00:00:19Z", constraint_id: "CST-001", decision: "inject", decision_owner: "product_owner" },
|
|
247
|
-
],
|
|
248
|
-
}));
|
|
249
|
-
expect(md).toContain("## 최근 결정");
|
|
250
|
-
expect(md).toContain("방향 확정");
|
|
251
|
-
expect(md).toContain("CST-001");
|
|
252
|
-
expect(md).toContain("inject");
|
|
253
|
-
});
|
|
254
|
-
it("omits verdict section when empty", () => {
|
|
255
|
-
const md = renderScopeMd(makeState());
|
|
256
|
-
expect(md).not.toContain("## 최근 결정");
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
// ─── requires_policy_change rendering ───
|
|
260
|
-
describe("scope-md — requires_policy_change count", () => {
|
|
261
|
-
it("shows policy change count when requires_policy_change constraints exist", () => {
|
|
262
|
-
const pool = {
|
|
263
|
-
constraints: [
|
|
264
|
-
{
|
|
265
|
-
constraint_id: "CST-001", perspective: "policy", summary: "s",
|
|
266
|
-
severity: "required", discovery_stage: "draft_phase2",
|
|
267
|
-
decision_owner: "product_owner", impact_if_ignored: "i",
|
|
268
|
-
source_refs: [{ source: "t.ts", detail: "d" }],
|
|
269
|
-
evidence_status: "unverified",
|
|
270
|
-
status: "decided", decision: "inject", discovered_at: 1, decided_at: 2,
|
|
271
|
-
requires_policy_change: true,
|
|
272
|
-
},
|
|
273
|
-
{
|
|
274
|
-
constraint_id: "CST-002", perspective: "code", summary: "s2",
|
|
275
|
-
severity: "recommended", discovery_stage: "draft_phase2",
|
|
276
|
-
decision_owner: "product_owner", impact_if_ignored: "i",
|
|
277
|
-
source_refs: [{ source: "t.ts", detail: "d" }],
|
|
278
|
-
evidence_status: "unverified",
|
|
279
|
-
status: "decided", decision: "inject", discovered_at: 1, decided_at: 2,
|
|
280
|
-
requires_policy_change: false,
|
|
281
|
-
},
|
|
282
|
-
],
|
|
283
|
-
summary: { total: 2, required: 1, recommended: 1, decided: 2, clarify_pending: 0, invalidated: 0, undecided: 0 },
|
|
284
|
-
};
|
|
285
|
-
const md = renderScopeMd(makeState({ constraint_pool: pool }));
|
|
286
|
-
expect(md).toContain("정책 변경 검토 필요: 1건");
|
|
287
|
-
});
|
|
288
|
-
it("omits policy change count when no requires_policy_change constraints", () => {
|
|
289
|
-
const pool = {
|
|
290
|
-
constraints: [
|
|
291
|
-
{
|
|
292
|
-
constraint_id: "CST-001", perspective: "code", summary: "s",
|
|
293
|
-
severity: "recommended", discovery_stage: "draft_phase2",
|
|
294
|
-
decision_owner: "product_owner", impact_if_ignored: "i",
|
|
295
|
-
source_refs: [{ source: "t.ts", detail: "d" }],
|
|
296
|
-
evidence_status: "unverified",
|
|
297
|
-
status: "decided", decision: "inject", discovered_at: 1, decided_at: 2,
|
|
298
|
-
requires_policy_change: false,
|
|
299
|
-
},
|
|
300
|
-
],
|
|
301
|
-
summary: { total: 1, required: 0, recommended: 1, decided: 1, clarify_pending: 0, invalidated: 0, undecided: 0 },
|
|
302
|
-
};
|
|
303
|
-
const md = renderScopeMd(makeState({ constraint_pool: pool }));
|
|
304
|
-
expect(md).not.toContain("정책 변경 검토 필요");
|
|
305
|
-
});
|
|
306
|
-
});
|
|
@@ -1,369 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* govern runtime adapter (W-C-01, bounded minimum surface v0).
|
|
3
|
-
*
|
|
4
|
-
* Subcommands: submit / list / decide (queue pattern).
|
|
5
|
-
*
|
|
6
|
-
* Responsibility split (consistent with evolve propose-align precedent):
|
|
7
|
-
* - runtime adapter owns: queue I/O, event log append, deterministic projection, table/JSON rendering.
|
|
8
|
-
* - LLM / agent owns: proposal authoring (payload JSON assembly), judgment reasoning.
|
|
9
|
-
*
|
|
10
|
-
* v0 scope: 기록만. decide approve 후 authority 파일 실제 반영은 주체자 수동 편집 or W-C-02.
|
|
11
|
-
* 승인 강제 차단 (pre-commit/CI/merge gate) 도 W-C-02.
|
|
12
|
-
*/
|
|
13
|
-
import { appendQueueEvent, generateGovernId, projectQueue, readQueueEvents, resolveQueuePath, } from "./queue.js";
|
|
14
|
-
import { routeProposal } from "./drift-engine.js";
|
|
15
|
-
import { executePromotePrinciple } from "./promote-principle.js";
|
|
16
|
-
import { originToTag } from "./types.js";
|
|
17
|
-
export async function handleGovernCli(_ontoHome, argv) {
|
|
18
|
-
const subcommand = argv[0];
|
|
19
|
-
const subArgv = argv.slice(1);
|
|
20
|
-
switch (subcommand) {
|
|
21
|
-
case "submit":
|
|
22
|
-
return handleSubmit(subArgv);
|
|
23
|
-
case "list":
|
|
24
|
-
return handleList(subArgv);
|
|
25
|
-
case "decide":
|
|
26
|
-
return handleDecide(subArgv);
|
|
27
|
-
case "route":
|
|
28
|
-
return handleRoute(subArgv);
|
|
29
|
-
case "promote-principle":
|
|
30
|
-
return handlePromotePrinciple(subArgv);
|
|
31
|
-
case "--help":
|
|
32
|
-
case "-h":
|
|
33
|
-
case undefined:
|
|
34
|
-
printHelp();
|
|
35
|
-
return 0;
|
|
36
|
-
default:
|
|
37
|
-
console.error(`[onto] Unknown govern adapter subcommand: ${subcommand}`);
|
|
38
|
-
console.error("Use the govern runtime adapter help for usage.");
|
|
39
|
-
return 1;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function printHelp() {
|
|
43
|
-
console.log([
|
|
44
|
-
"Usage: govern-adapter <subcommand> [options]",
|
|
45
|
-
"",
|
|
46
|
-
"Subcommands:",
|
|
47
|
-
" submit Queue a norm-change proposal or drift-detection item",
|
|
48
|
-
" list Show queue entries (pending / decided / all)",
|
|
49
|
-
" decide Record Principal verdict on a queued item",
|
|
50
|
-
" route Classify a change proposal by drift policy (W-C-02, §1.3)",
|
|
51
|
-
" promote-principle Propose a promoted learning for principle promotion (W-C-03)",
|
|
52
|
-
"",
|
|
53
|
-
"Options (submit):",
|
|
54
|
-
" --origin <human|system> who is submitting (required)",
|
|
55
|
-
" --target <path> file/resource being proposed to change (required)",
|
|
56
|
-
" --json <payload-json> proposal payload JSON (required)",
|
|
57
|
-
" --prompted-by-drift <id> optional: this human proposal was prompted by a drift item",
|
|
58
|
-
" --submitted-by <actor> optional actor label (default: 'principal' for human, 'drift-engine' for system)",
|
|
59
|
-
" --project-root <path> project root (default: cwd)",
|
|
60
|
-
"",
|
|
61
|
-
"Options (list):",
|
|
62
|
-
" --status <pending|decided|all> filter (default: pending)",
|
|
63
|
-
" --format <table|json> output format (default: table)",
|
|
64
|
-
" --project-root <path> project root (default: cwd)",
|
|
65
|
-
"",
|
|
66
|
-
"Options (decide):",
|
|
67
|
-
" <id> queue entry id (positional, required)",
|
|
68
|
-
" --verdict <approve|reject> required",
|
|
69
|
-
" --reason <text> required",
|
|
70
|
-
" --decided-by <actor> optional (default: principal)",
|
|
71
|
-
" --project-root <path> project root (default: cwd)",
|
|
72
|
-
"",
|
|
73
|
-
"Options (route):",
|
|
74
|
-
" --json <proposal-json> required. ChangeProposal JSON (summary, target_files, change_kind, rationale?)",
|
|
75
|
-
" --project-root <path> project root (default: cwd)",
|
|
76
|
-
" (outcome routes)",
|
|
77
|
-
" self_apply drift-free local change. no queue append. caller logs only.",
|
|
78
|
-
" queue drift-risk change. appends origin=system, tag=drift to queue.",
|
|
79
|
-
" principal_direct governance-core change. appends with payload marker route=principal_direct.",
|
|
80
|
-
"",
|
|
81
|
-
"v0 scope (bounded minimum surface):",
|
|
82
|
-
" - submit appends to .onto/govern/queue.ndjson (event-sourced, append-only).",
|
|
83
|
-
" - decide records verdict only. Actual authority-file edit after approve is",
|
|
84
|
-
" manual (or delegated to W-C-02 drift-engine). No merge/CI gate in v0.",
|
|
85
|
-
" - origin→tag is deterministic: human→norm_change, system→drift.",
|
|
86
|
-
" - Cross-project norms (e.g., global meta-rules) are out of scope; see W-C-03.",
|
|
87
|
-
].join("\n"));
|
|
88
|
-
}
|
|
89
|
-
function readOption(argv, name) {
|
|
90
|
-
const idx = argv.indexOf(`--${name}`);
|
|
91
|
-
if (idx >= 0 && idx + 1 < argv.length)
|
|
92
|
-
return argv[idx + 1];
|
|
93
|
-
return undefined;
|
|
94
|
-
}
|
|
95
|
-
function resolveProjectRoot(argv) {
|
|
96
|
-
return readOption(argv, "project-root") ?? process.cwd();
|
|
97
|
-
}
|
|
98
|
-
// ─── submit ───
|
|
99
|
-
function handleSubmit(argv) {
|
|
100
|
-
const originRaw = readOption(argv, "origin");
|
|
101
|
-
const target = readOption(argv, "target");
|
|
102
|
-
const jsonRaw = readOption(argv, "json");
|
|
103
|
-
const promptedBy = readOption(argv, "prompted-by-drift");
|
|
104
|
-
const submittedByOverride = readOption(argv, "submitted-by");
|
|
105
|
-
if (!originRaw || (originRaw !== "human" && originRaw !== "system")) {
|
|
106
|
-
console.error("[onto] govern submit: --origin must be 'human' or 'system'.");
|
|
107
|
-
return 1;
|
|
108
|
-
}
|
|
109
|
-
if (!target) {
|
|
110
|
-
console.error("[onto] govern submit: --target is required.");
|
|
111
|
-
return 1;
|
|
112
|
-
}
|
|
113
|
-
if (!jsonRaw) {
|
|
114
|
-
console.error("[onto] govern submit: --json payload is required.");
|
|
115
|
-
return 1;
|
|
116
|
-
}
|
|
117
|
-
let payload;
|
|
118
|
-
try {
|
|
119
|
-
const parsed = JSON.parse(jsonRaw);
|
|
120
|
-
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
121
|
-
console.error("[onto] govern submit: --json must be a JSON object.");
|
|
122
|
-
return 1;
|
|
123
|
-
}
|
|
124
|
-
payload = parsed;
|
|
125
|
-
}
|
|
126
|
-
catch (e) {
|
|
127
|
-
console.error(`[onto] govern submit: --json parse error: ${e instanceof Error ? e.message : String(e)}`);
|
|
128
|
-
return 1;
|
|
129
|
-
}
|
|
130
|
-
const origin = originRaw;
|
|
131
|
-
const tag = originToTag(origin);
|
|
132
|
-
const projectRoot = resolveProjectRoot(argv);
|
|
133
|
-
const queuePath = resolveQueuePath(projectRoot);
|
|
134
|
-
const id = generateGovernId();
|
|
135
|
-
const submittedBy = submittedByOverride ?? (origin === "human" ? "principal" : "drift-engine");
|
|
136
|
-
const event = {
|
|
137
|
-
type: "submit",
|
|
138
|
-
id,
|
|
139
|
-
origin,
|
|
140
|
-
tag,
|
|
141
|
-
target,
|
|
142
|
-
payload,
|
|
143
|
-
submitted_at: new Date().toISOString(),
|
|
144
|
-
submitted_by: submittedBy,
|
|
145
|
-
};
|
|
146
|
-
if (promptedBy !== undefined)
|
|
147
|
-
event.prompted_by_drift_id = promptedBy;
|
|
148
|
-
appendQueueEvent(queuePath, event);
|
|
149
|
-
console.log(JSON.stringify({
|
|
150
|
-
status: "queued",
|
|
151
|
-
id,
|
|
152
|
-
origin,
|
|
153
|
-
tag,
|
|
154
|
-
target,
|
|
155
|
-
next_action: "govern MCP design pending; inspect the queue artifact before deciding",
|
|
156
|
-
}, null, 2));
|
|
157
|
-
return 0;
|
|
158
|
-
}
|
|
159
|
-
// ─── list ───
|
|
160
|
-
function handleList(argv) {
|
|
161
|
-
const statusFilterRaw = readOption(argv, "status") ?? "pending";
|
|
162
|
-
if (statusFilterRaw !== "pending" &&
|
|
163
|
-
statusFilterRaw !== "decided" &&
|
|
164
|
-
statusFilterRaw !== "all") {
|
|
165
|
-
console.error("[onto] govern list: --status must be 'pending', 'decided', or 'all'.");
|
|
166
|
-
return 1;
|
|
167
|
-
}
|
|
168
|
-
const format = readOption(argv, "format") ?? "table";
|
|
169
|
-
if (format !== "table" && format !== "json") {
|
|
170
|
-
console.error("[onto] govern list: --format must be 'table' or 'json'.");
|
|
171
|
-
return 1;
|
|
172
|
-
}
|
|
173
|
-
const projectRoot = resolveProjectRoot(argv);
|
|
174
|
-
const queuePath = resolveQueuePath(projectRoot);
|
|
175
|
-
const events = readQueueEvents(queuePath);
|
|
176
|
-
const entries = projectQueue(events);
|
|
177
|
-
const filtered = statusFilterRaw === "all"
|
|
178
|
-
? entries
|
|
179
|
-
: entries.filter((e) => e.status === statusFilterRaw);
|
|
180
|
-
if (format === "json") {
|
|
181
|
-
console.log(JSON.stringify(filtered, null, 2));
|
|
182
|
-
return 0;
|
|
183
|
-
}
|
|
184
|
-
renderTable(filtered, statusFilterRaw);
|
|
185
|
-
return 0;
|
|
186
|
-
}
|
|
187
|
-
function renderTable(entries, statusFilter) {
|
|
188
|
-
if (entries.length === 0) {
|
|
189
|
-
console.log(`(no ${statusFilter} govern entries)`);
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
const rows = entries.map((e) => ({
|
|
193
|
-
id: e.id,
|
|
194
|
-
status: e.status,
|
|
195
|
-
tag: e.tag,
|
|
196
|
-
origin: e.origin,
|
|
197
|
-
target: e.target,
|
|
198
|
-
submitted_at: e.submitted_at,
|
|
199
|
-
verdict: e.verdict?.verdict ?? "",
|
|
200
|
-
}));
|
|
201
|
-
const cols = [
|
|
202
|
-
"id",
|
|
203
|
-
"status",
|
|
204
|
-
"tag",
|
|
205
|
-
"origin",
|
|
206
|
-
"target",
|
|
207
|
-
"submitted_at",
|
|
208
|
-
"verdict",
|
|
209
|
-
];
|
|
210
|
-
const widths = {};
|
|
211
|
-
for (const c of cols) {
|
|
212
|
-
widths[c] = Math.max(c.length, ...rows.map((r) => String(r[c] ?? "").length));
|
|
213
|
-
}
|
|
214
|
-
const header = cols.map((c) => c.padEnd(widths[c])).join(" ");
|
|
215
|
-
console.log(header);
|
|
216
|
-
console.log(cols.map((c) => "-".repeat(widths[c])).join(" "));
|
|
217
|
-
for (const r of rows) {
|
|
218
|
-
console.log(cols.map((c) => String(r[c] ?? "").padEnd(widths[c])).join(" "));
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
// ─── promote-principle (W-C-03) ───
|
|
222
|
-
function handlePromotePrinciple(argv) {
|
|
223
|
-
const jsonRaw = readOption(argv, "json");
|
|
224
|
-
if (!jsonRaw) {
|
|
225
|
-
console.error("[onto] govern promote-principle: --json proposal is required.");
|
|
226
|
-
console.error("Example JSON shape: {\"learning_ref\":{\"agent_id\":\"logic\",\"entry_marker\":\"...\"},\"target\":{\"category\":\"principle\",\"file_path\":\".onto/principles/X.md\",\"section\":\"NEW\"},\"rationale\":\"...\",\"conflict_check\":{\"reviewed_by_agent\":true,\"existing_principle_refs\":[],\"conflict_summary\":\"no conflict\"},\"workload_evidence\":{\"state_transitions\":10,\"evidence_summary\":\"...\",\"event_refs\":[]},\"source_impact\":\"high\"}");
|
|
227
|
-
return 1;
|
|
228
|
-
}
|
|
229
|
-
let parsed;
|
|
230
|
-
try {
|
|
231
|
-
parsed = JSON.parse(jsonRaw);
|
|
232
|
-
}
|
|
233
|
-
catch (e) {
|
|
234
|
-
console.error(`[onto] govern promote-principle: --json parse error: ${e instanceof Error ? e.message : String(e)}`);
|
|
235
|
-
return 1;
|
|
236
|
-
}
|
|
237
|
-
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
238
|
-
console.error("[onto] govern promote-principle: --json must be a JSON object.");
|
|
239
|
-
return 1;
|
|
240
|
-
}
|
|
241
|
-
const projectRoot = resolveProjectRoot(argv);
|
|
242
|
-
const result = executePromotePrinciple(parsed, projectRoot);
|
|
243
|
-
if (!result.success) {
|
|
244
|
-
console.error(`[onto] govern promote-principle: ${result.reason}`);
|
|
245
|
-
return 1;
|
|
246
|
-
}
|
|
247
|
-
console.log(JSON.stringify({
|
|
248
|
-
status: "queued",
|
|
249
|
-
id: result.id,
|
|
250
|
-
gate_passed: result.gate_passed,
|
|
251
|
-
similar_to: result.similar_to,
|
|
252
|
-
next_action: "govern MCP design pending; inspect the queue artifact before deciding",
|
|
253
|
-
}, null, 2));
|
|
254
|
-
return 0;
|
|
255
|
-
}
|
|
256
|
-
// ─── route (W-C-02 drift engine) ───
|
|
257
|
-
function handleRoute(argv) {
|
|
258
|
-
const jsonRaw = readOption(argv, "json");
|
|
259
|
-
if (!jsonRaw) {
|
|
260
|
-
console.error("[onto] govern route: --json proposal is required.");
|
|
261
|
-
return 1;
|
|
262
|
-
}
|
|
263
|
-
let parsed;
|
|
264
|
-
try {
|
|
265
|
-
parsed = JSON.parse(jsonRaw);
|
|
266
|
-
}
|
|
267
|
-
catch (e) {
|
|
268
|
-
console.error(`[onto] govern route: --json parse error: ${e instanceof Error ? e.message : String(e)}`);
|
|
269
|
-
return 1;
|
|
270
|
-
}
|
|
271
|
-
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
272
|
-
console.error("[onto] govern route: --json must be a JSON object.");
|
|
273
|
-
return 1;
|
|
274
|
-
}
|
|
275
|
-
const obj = parsed;
|
|
276
|
-
const summary = obj.summary;
|
|
277
|
-
const targetFiles = obj.target_files;
|
|
278
|
-
const changeKind = obj.change_kind;
|
|
279
|
-
const rationale = obj.rationale;
|
|
280
|
-
if (typeof summary !== "string" || summary.trim().length === 0) {
|
|
281
|
-
console.error("[onto] govern route: proposal.summary (string) is required.");
|
|
282
|
-
return 1;
|
|
283
|
-
}
|
|
284
|
-
if (!Array.isArray(targetFiles) ||
|
|
285
|
-
targetFiles.length === 0 ||
|
|
286
|
-
!targetFiles.every((f) => typeof f === "string" && f.length > 0)) {
|
|
287
|
-
console.error("[onto] govern route: proposal.target_files must be a non-empty string array.");
|
|
288
|
-
return 1;
|
|
289
|
-
}
|
|
290
|
-
const validKinds = ["docs_only", "code", "config", "mixed"];
|
|
291
|
-
if (typeof changeKind !== "string" ||
|
|
292
|
-
!validKinds.includes(changeKind)) {
|
|
293
|
-
console.error(`[onto] govern route: proposal.change_kind must be one of ${validKinds.join(", ")}.`);
|
|
294
|
-
return 1;
|
|
295
|
-
}
|
|
296
|
-
const proposal = {
|
|
297
|
-
summary,
|
|
298
|
-
target_files: targetFiles,
|
|
299
|
-
change_kind: changeKind,
|
|
300
|
-
};
|
|
301
|
-
if (typeof rationale === "string")
|
|
302
|
-
proposal.rationale = rationale;
|
|
303
|
-
const projectRoot = resolveProjectRoot(argv);
|
|
304
|
-
const outcome = routeProposal(proposal, projectRoot);
|
|
305
|
-
console.log(JSON.stringify({
|
|
306
|
-
status: "routed",
|
|
307
|
-
route: outcome.decision.route,
|
|
308
|
-
matched_rule: outcome.decision.matched_rule,
|
|
309
|
-
reason: outcome.decision.reason,
|
|
310
|
-
...(outcome.queue_event_id
|
|
311
|
-
? { queue_event_id: outcome.queue_event_id }
|
|
312
|
-
: {}),
|
|
313
|
-
}, null, 2));
|
|
314
|
-
return 0;
|
|
315
|
-
}
|
|
316
|
-
// ─── decide ───
|
|
317
|
-
function handleDecide(argv) {
|
|
318
|
-
const id = argv.find((a) => !a.startsWith("--"));
|
|
319
|
-
if (!id) {
|
|
320
|
-
console.error("[onto] govern decide: <id> positional argument is required.");
|
|
321
|
-
return 1;
|
|
322
|
-
}
|
|
323
|
-
const verdictRaw = readOption(argv, "verdict");
|
|
324
|
-
const reason = readOption(argv, "reason");
|
|
325
|
-
const decidedByOverride = readOption(argv, "decided-by");
|
|
326
|
-
if (!verdictRaw || (verdictRaw !== "approve" && verdictRaw !== "reject")) {
|
|
327
|
-
console.error("[onto] govern decide: --verdict must be 'approve' or 'reject'.");
|
|
328
|
-
return 1;
|
|
329
|
-
}
|
|
330
|
-
if (!reason || reason.trim().length === 0) {
|
|
331
|
-
console.error("[onto] govern decide: --reason is required.");
|
|
332
|
-
return 1;
|
|
333
|
-
}
|
|
334
|
-
const projectRoot = resolveProjectRoot(argv);
|
|
335
|
-
const queuePath = resolveQueuePath(projectRoot);
|
|
336
|
-
const events = readQueueEvents(queuePath);
|
|
337
|
-
const entries = projectQueue(events);
|
|
338
|
-
const existing = entries.find((e) => e.id === id);
|
|
339
|
-
if (!existing) {
|
|
340
|
-
console.error(`[onto] govern decide: id '${id}' not found in queue.`);
|
|
341
|
-
return 1;
|
|
342
|
-
}
|
|
343
|
-
if (existing.status === "decided") {
|
|
344
|
-
console.error(`[onto] govern decide: id '${id}' already decided (verdict=${existing.verdict?.verdict}). v0 는 재판정 지원하지 않음.`);
|
|
345
|
-
return 1;
|
|
346
|
-
}
|
|
347
|
-
const verdict = verdictRaw;
|
|
348
|
-
const event = {
|
|
349
|
-
type: "decide",
|
|
350
|
-
id,
|
|
351
|
-
verdict,
|
|
352
|
-
reason,
|
|
353
|
-
decided_at: new Date().toISOString(),
|
|
354
|
-
decided_by: decidedByOverride ?? "principal",
|
|
355
|
-
};
|
|
356
|
-
appendQueueEvent(queuePath, event);
|
|
357
|
-
const applyNote = verdict === "approve"
|
|
358
|
-
? `(v0 는 기록만) 승인됨. ${existing.target} 파일의 실제 수정은 주체자 수동 편집 또는 W-C-02 drift-engine 책임.`
|
|
359
|
-
: `(v0 는 기록만) 거부됨. 제안 내용은 폐기. ${existing.target} 파일은 변경 없음.`;
|
|
360
|
-
console.log(JSON.stringify({
|
|
361
|
-
status: "decided",
|
|
362
|
-
id,
|
|
363
|
-
verdict,
|
|
364
|
-
target: existing.target,
|
|
365
|
-
tag: existing.tag,
|
|
366
|
-
note: applyNote,
|
|
367
|
-
}, null, 2));
|
|
368
|
-
return 0;
|
|
369
|
-
}
|