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,222 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Evolve propose-align — transition grounded → align_proposed.
|
|
3
|
-
*
|
|
4
|
-
* Consumes consolidated dialog output (direction, scope, constraints, tensions)
|
|
5
|
-
* from the agent who conducted the Principal dialog, then:
|
|
6
|
-
* 1. Emits constraint.discovered events (pool registration).
|
|
7
|
-
* 2. Renders build/align-packet.md.
|
|
8
|
-
* 3. Emits align.proposed event (state transition to align_proposed).
|
|
9
|
-
*
|
|
10
|
-
* The agent owns UX (selection-based choices, natural-language fallback,
|
|
11
|
-
* inquiry consolidation, convergence judgment); this CLI owns the bounded
|
|
12
|
-
* state machine + event log + packet rendering.
|
|
13
|
-
*/
|
|
14
|
-
import { createHash } from "node:crypto";
|
|
15
|
-
import { writeFileSync } from "node:fs";
|
|
16
|
-
import { join } from "node:path";
|
|
17
|
-
import { z } from "zod";
|
|
18
|
-
import { readEvents } from "../../scope-runtime/event-store.js";
|
|
19
|
-
import { reduce } from "../../scope-runtime/reducer.js";
|
|
20
|
-
import { appendScopeEvent } from "../../scope-runtime/event-pipeline.js";
|
|
21
|
-
import { renderAlignPacket } from "../renderers/align-packet.js";
|
|
22
|
-
// ─── Input schema ───
|
|
23
|
-
const constraintInputSchema = z.object({
|
|
24
|
-
summary: z.string().min(1),
|
|
25
|
-
perspective: z.enum(["experience", "code", "policy"]),
|
|
26
|
-
severity: z.enum(["required", "recommended"]),
|
|
27
|
-
decision_owner: z.enum(["product_owner", "builder"]),
|
|
28
|
-
impact_if_ignored: z.string().min(1),
|
|
29
|
-
source_refs: z
|
|
30
|
-
.array(z.object({ source: z.string(), detail: z.string() }))
|
|
31
|
-
.default([]),
|
|
32
|
-
evidence_status: z
|
|
33
|
-
.enum(["verified", "code_inferred", "brief_claimed", "unverified"])
|
|
34
|
-
.optional(),
|
|
35
|
-
evidence_note: z.string().optional(),
|
|
36
|
-
why_conflict: z.string().min(1),
|
|
37
|
-
scale: z.string().min(1),
|
|
38
|
-
options: z
|
|
39
|
-
.array(z.object({
|
|
40
|
-
choice: z.string(),
|
|
41
|
-
pros: z.string(),
|
|
42
|
-
risk: z.string(),
|
|
43
|
-
detail: z.string().optional(),
|
|
44
|
-
}))
|
|
45
|
-
.optional(),
|
|
46
|
-
recommendation: z.string().optional(),
|
|
47
|
-
});
|
|
48
|
-
const proposeAlignInputSchema = z.object({
|
|
49
|
-
interpreted_direction: z.string().min(1),
|
|
50
|
-
proposed_scope: z.object({
|
|
51
|
-
in: z.array(z.string()).min(1),
|
|
52
|
-
out: z.array(z.string()),
|
|
53
|
-
}),
|
|
54
|
-
scenarios: z.array(z.string()).default([]),
|
|
55
|
-
as_is: z.object({
|
|
56
|
-
experience: z.string().default(""),
|
|
57
|
-
policy: z.string().default(""),
|
|
58
|
-
code: z.string().default(""),
|
|
59
|
-
code_details: z.string().optional(),
|
|
60
|
-
}),
|
|
61
|
-
constraints: z.array(constraintInputSchema).default([]),
|
|
62
|
-
decision_questions: z.array(z.string()).default([]),
|
|
63
|
-
interface_extras: z
|
|
64
|
-
.object({
|
|
65
|
-
api_scope: z.string(),
|
|
66
|
-
breaking_change: z.string(),
|
|
67
|
-
version_policy: z.string(),
|
|
68
|
-
})
|
|
69
|
-
.optional(),
|
|
70
|
-
});
|
|
71
|
-
// ─── Main ───
|
|
72
|
-
export function executeProposeAlign(paths, jsonInput) {
|
|
73
|
-
// Step 1: Parse + validate input
|
|
74
|
-
let parsed;
|
|
75
|
-
try {
|
|
76
|
-
const raw = JSON.parse(jsonInput);
|
|
77
|
-
const result = proposeAlignInputSchema.safeParse(raw);
|
|
78
|
-
if (!result.success) {
|
|
79
|
-
const issues = result.error.issues
|
|
80
|
-
.map((i) => `${i.path.join(".")}: ${i.message}`)
|
|
81
|
-
.join("; ");
|
|
82
|
-
return {
|
|
83
|
-
success: false,
|
|
84
|
-
reason: `Invalid propose-align input: ${issues}`,
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
parsed = result.data;
|
|
88
|
-
}
|
|
89
|
-
catch (e) {
|
|
90
|
-
return {
|
|
91
|
-
success: false,
|
|
92
|
-
reason: `Failed to parse JSON: ${e instanceof Error ? e.message : String(e)}`,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
// Step 2: Verify current state is grounded
|
|
96
|
-
const initialEvents = readEvents(paths.events);
|
|
97
|
-
const initialState = reduce(initialEvents);
|
|
98
|
-
if (initialState.current_state !== "grounded") {
|
|
99
|
-
return {
|
|
100
|
-
success: false,
|
|
101
|
-
reason: `현재 상태가 ${initialState.current_state}입니다. propose-align은 grounded 상태에서만 실행할 수 있습니다.`,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
// Step 3: Emit constraint.discovered events
|
|
105
|
-
const tensions = [];
|
|
106
|
-
let registeredCount = 0;
|
|
107
|
-
for (let i = 0; i < parsed.constraints.length; i++) {
|
|
108
|
-
const c = parsed.constraints[i];
|
|
109
|
-
const constraintId = `C-${String(i + 1).padStart(3, "0")}`;
|
|
110
|
-
const payload = {
|
|
111
|
-
constraint_id: constraintId,
|
|
112
|
-
perspective: c.perspective,
|
|
113
|
-
summary: c.summary,
|
|
114
|
-
severity: c.severity,
|
|
115
|
-
discovery_stage: "grounding",
|
|
116
|
-
decision_owner: c.decision_owner,
|
|
117
|
-
impact_if_ignored: c.impact_if_ignored,
|
|
118
|
-
source_refs: c.source_refs,
|
|
119
|
-
};
|
|
120
|
-
if (c.evidence_status)
|
|
121
|
-
payload.evidence_status = c.evidence_status;
|
|
122
|
-
if (c.evidence_note)
|
|
123
|
-
payload.evidence_note = c.evidence_note;
|
|
124
|
-
const result = appendScopeEvent(paths, {
|
|
125
|
-
type: "constraint.discovered",
|
|
126
|
-
actor: "user",
|
|
127
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
128
|
-
payload: payload,
|
|
129
|
-
});
|
|
130
|
-
if (!result.success) {
|
|
131
|
-
return {
|
|
132
|
-
success: false,
|
|
133
|
-
reason: `constraint.discovered[${i}] (${constraintId}) emission 실패: ${result.reason}`,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
registeredCount++;
|
|
137
|
-
const tension = {
|
|
138
|
-
constraint_id: constraintId,
|
|
139
|
-
what: c.summary,
|
|
140
|
-
why_conflict: c.why_conflict,
|
|
141
|
-
scale: c.scale,
|
|
142
|
-
};
|
|
143
|
-
if (c.options) {
|
|
144
|
-
tension.options = c.options.map((o) => {
|
|
145
|
-
const base = {
|
|
146
|
-
choice: o.choice,
|
|
147
|
-
pros: o.pros,
|
|
148
|
-
risk: o.risk,
|
|
149
|
-
};
|
|
150
|
-
if (o.detail !== undefined)
|
|
151
|
-
base.detail = o.detail;
|
|
152
|
-
return base;
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
if (c.recommendation)
|
|
156
|
-
tension.recommendation = c.recommendation;
|
|
157
|
-
tensions.push(tension);
|
|
158
|
-
}
|
|
159
|
-
// Step 4: Re-read state after constraint events
|
|
160
|
-
const stateAfterConstraints = reduce(readEvents(paths.events));
|
|
161
|
-
// Step 5: Build AlignPacketContent
|
|
162
|
-
const asIs = {
|
|
163
|
-
experience: parsed.as_is.experience,
|
|
164
|
-
policy: parsed.as_is.policy,
|
|
165
|
-
code: parsed.as_is.code,
|
|
166
|
-
};
|
|
167
|
-
if (parsed.as_is.code_details !== undefined) {
|
|
168
|
-
asIs.code_details = parsed.as_is.code_details;
|
|
169
|
-
}
|
|
170
|
-
const content = {
|
|
171
|
-
user_original_text: stateAfterConstraints.title,
|
|
172
|
-
interpreted_direction: parsed.interpreted_direction,
|
|
173
|
-
proposed_scope: parsed.proposed_scope,
|
|
174
|
-
scenarios: parsed.scenarios,
|
|
175
|
-
as_is: asIs,
|
|
176
|
-
tensions,
|
|
177
|
-
decision_questions: parsed.decision_questions,
|
|
178
|
-
...(parsed.interface_extras
|
|
179
|
-
? { interface_extras: parsed.interface_extras }
|
|
180
|
-
: {}),
|
|
181
|
-
};
|
|
182
|
-
// Step 6: Render packet
|
|
183
|
-
let packetMd;
|
|
184
|
-
try {
|
|
185
|
-
packetMd = renderAlignPacket(stateAfterConstraints, content);
|
|
186
|
-
}
|
|
187
|
-
catch (e) {
|
|
188
|
-
return {
|
|
189
|
-
success: false,
|
|
190
|
-
reason: `renderAlignPacket 실패: ${e instanceof Error ? e.message : String(e)}`,
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
const packetPath = join(paths.build, "align-packet.md");
|
|
194
|
-
writeFileSync(packetPath, packetMd, "utf-8");
|
|
195
|
-
// Step 7: Compute packet hash
|
|
196
|
-
const packetHash = createHash("sha256").update(packetMd).digest("hex");
|
|
197
|
-
// Step 8: Emit align.proposed
|
|
198
|
-
const proposeResult = appendScopeEvent(paths, {
|
|
199
|
-
type: "align.proposed",
|
|
200
|
-
actor: "user",
|
|
201
|
-
payload: {
|
|
202
|
-
packet_path: "build/align-packet.md",
|
|
203
|
-
packet_hash: packetHash,
|
|
204
|
-
snapshot_revision: stateAfterConstraints.snapshot_revision,
|
|
205
|
-
},
|
|
206
|
-
});
|
|
207
|
-
if (!proposeResult.success) {
|
|
208
|
-
return {
|
|
209
|
-
success: false,
|
|
210
|
-
reason: `align.proposed emission 실패: ${proposeResult.reason}`,
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
return {
|
|
214
|
-
success: true,
|
|
215
|
-
scope_id: paths.scopeId,
|
|
216
|
-
constraints_registered: registeredCount,
|
|
217
|
-
packet_path: packetPath,
|
|
218
|
-
packet_hash: packetHash,
|
|
219
|
-
next_state: proposeResult.next_state,
|
|
220
|
-
next_action: "build/align-packet.md 를 검토하고 bounded evolve align input을 제출하세요 (verdict type: approve/revise/reject/redirect).",
|
|
221
|
-
};
|
|
222
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import { mkdtempSync, rmSync, readFileSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { executeProposeAlign } from "./propose-align.js";
|
|
6
|
-
import { createScope } from "../../scope-runtime/scope-manager.js";
|
|
7
|
-
import { appendScopeEvent } from "../../scope-runtime/event-pipeline.js";
|
|
8
|
-
import { readEvents } from "../../scope-runtime/event-store.js";
|
|
9
|
-
import { reduce } from "../../scope-runtime/reducer.js";
|
|
10
|
-
let tmpDir;
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
tmpDir = mkdtempSync(join(tmpdir(), "sprint-propose-align-"));
|
|
13
|
-
});
|
|
14
|
-
afterEach(() => {
|
|
15
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
16
|
-
});
|
|
17
|
-
function setupGrounded() {
|
|
18
|
-
const paths = createScope(tmpDir, "SC-PA-001");
|
|
19
|
-
appendScopeEvent(paths, {
|
|
20
|
-
type: "scope.created",
|
|
21
|
-
actor: "user",
|
|
22
|
-
payload: {
|
|
23
|
-
title: "Propose align test",
|
|
24
|
-
description: "test scope",
|
|
25
|
-
entry_mode: "experience",
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
appendScopeEvent(paths, {
|
|
29
|
-
type: "grounding.started",
|
|
30
|
-
actor: "system",
|
|
31
|
-
payload: {
|
|
32
|
-
sources: [{ type: "add-dir", path_or_url: "/test" }],
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
appendScopeEvent(paths, {
|
|
36
|
-
type: "grounding.completed",
|
|
37
|
-
actor: "system",
|
|
38
|
-
payload: {
|
|
39
|
-
snapshot_revision: 1,
|
|
40
|
-
source_hashes: { "add-dir:/test": "h1" },
|
|
41
|
-
perspective_summary: { experience: 1, code: 1, policy: 1 },
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
return paths;
|
|
45
|
-
}
|
|
46
|
-
const VALID_INPUT = JSON.stringify({
|
|
47
|
-
interpreted_direction: "test direction",
|
|
48
|
-
proposed_scope: { in: ["feature X"], out: ["feature Y"] },
|
|
49
|
-
scenarios: ["scenario 1"],
|
|
50
|
-
as_is: { experience: "exp-baseline", policy: "policy-baseline", code: "code-baseline" },
|
|
51
|
-
constraints: [
|
|
52
|
-
{
|
|
53
|
-
summary: "constraint 1",
|
|
54
|
-
perspective: "code",
|
|
55
|
-
severity: "required",
|
|
56
|
-
decision_owner: "builder",
|
|
57
|
-
impact_if_ignored: "breaks flow",
|
|
58
|
-
source_refs: [{ source: "code", detail: "src/foo.ts" }],
|
|
59
|
-
why_conflict: "conflict between X and Y",
|
|
60
|
-
scale: "medium",
|
|
61
|
-
},
|
|
62
|
-
],
|
|
63
|
-
decision_questions: ["Q1?"],
|
|
64
|
-
});
|
|
65
|
-
describe("executeProposeAlign", () => {
|
|
66
|
-
it("grounded + valid input → align_proposed + packet + events", () => {
|
|
67
|
-
const paths = setupGrounded();
|
|
68
|
-
const result = executeProposeAlign(paths, VALID_INPUT);
|
|
69
|
-
expect(result.success).toBe(true);
|
|
70
|
-
if (!result.success)
|
|
71
|
-
return;
|
|
72
|
-
expect(result.constraints_registered).toBe(1);
|
|
73
|
-
expect(result.next_state).toBe("align_proposed");
|
|
74
|
-
const packet = readFileSync(result.packet_path, "utf-8");
|
|
75
|
-
expect(packet).toContain("Align Packet");
|
|
76
|
-
expect(packet).toContain("test direction");
|
|
77
|
-
expect(packet).toContain("feature X");
|
|
78
|
-
const events = readEvents(paths.events);
|
|
79
|
-
const state = reduce(events);
|
|
80
|
-
expect(state.current_state).toBe("align_proposed");
|
|
81
|
-
expect(state.constraint_pool.summary.total).toBe(1);
|
|
82
|
-
});
|
|
83
|
-
it("rejects when not in grounded state", () => {
|
|
84
|
-
const paths = createScope(tmpDir, "SC-PA-002");
|
|
85
|
-
appendScopeEvent(paths, {
|
|
86
|
-
type: "scope.created",
|
|
87
|
-
actor: "user",
|
|
88
|
-
payload: { title: "t", description: "d", entry_mode: "experience" },
|
|
89
|
-
});
|
|
90
|
-
const result = executeProposeAlign(paths, VALID_INPUT);
|
|
91
|
-
expect(result.success).toBe(false);
|
|
92
|
-
if (result.success)
|
|
93
|
-
return;
|
|
94
|
-
expect(result.reason).toContain("grounded");
|
|
95
|
-
});
|
|
96
|
-
it("rejects invalid JSON", () => {
|
|
97
|
-
const paths = setupGrounded();
|
|
98
|
-
const result = executeProposeAlign(paths, "not-json");
|
|
99
|
-
expect(result.success).toBe(false);
|
|
100
|
-
if (result.success)
|
|
101
|
-
return;
|
|
102
|
-
expect(result.reason).toContain("Failed to parse JSON");
|
|
103
|
-
});
|
|
104
|
-
it("rejects missing required fields", () => {
|
|
105
|
-
const paths = setupGrounded();
|
|
106
|
-
const result = executeProposeAlign(paths, JSON.stringify({}));
|
|
107
|
-
expect(result.success).toBe(false);
|
|
108
|
-
if (result.success)
|
|
109
|
-
return;
|
|
110
|
-
expect(result.reason).toContain("Invalid propose-align input");
|
|
111
|
-
});
|
|
112
|
-
it("rejects empty scope_in", () => {
|
|
113
|
-
const paths = setupGrounded();
|
|
114
|
-
const bad = JSON.stringify({
|
|
115
|
-
interpreted_direction: "x",
|
|
116
|
-
proposed_scope: { in: [], out: [] },
|
|
117
|
-
as_is: { experience: "", policy: "", code: "" },
|
|
118
|
-
});
|
|
119
|
-
const result = executeProposeAlign(paths, bad);
|
|
120
|
-
expect(result.success).toBe(false);
|
|
121
|
-
});
|
|
122
|
-
it("accepts zero-constraints input (empty tensions ok per renderer)", () => {
|
|
123
|
-
const paths = setupGrounded();
|
|
124
|
-
const input = JSON.stringify({
|
|
125
|
-
interpreted_direction: "x",
|
|
126
|
-
proposed_scope: { in: ["a"], out: [] },
|
|
127
|
-
as_is: { experience: "e", policy: "p", code: "c" },
|
|
128
|
-
constraints: [],
|
|
129
|
-
});
|
|
130
|
-
const result = executeProposeAlign(paths, input);
|
|
131
|
-
expect(result.success).toBe(true);
|
|
132
|
-
if (!result.success)
|
|
133
|
-
return;
|
|
134
|
-
expect(result.constraints_registered).toBe(0);
|
|
135
|
-
});
|
|
136
|
-
});
|
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* reconstruct — runtime handler for the reconstruct activity (3-step bounded path).
|
|
3
|
-
*
|
|
4
|
-
* W-A-74 (DL-020 resolution): review 의 3-step bounded path 수준으로 reconstruct 비대칭 해소.
|
|
5
|
-
*
|
|
6
|
-
* Bounded surface:
|
|
7
|
-
* start — session 초기화 + gathering_context 상태 기록
|
|
8
|
-
* explore — 탐색 loop bounded invocation (현 단계는 placeholder — 실제 Explorer/lens
|
|
9
|
-
* loop 는 build runtime 확장과 함께 채운다)
|
|
10
|
-
* complete — ontology 초안 산출 + converted 상태 기록
|
|
11
|
-
*
|
|
12
|
-
* 본 handler 는 reconstruct runtime (.onto/processes/reconstruct.md) 의 bounded adapter 다.
|
|
13
|
-
* Bounded state 는 `{session_root}/reconstruct-state.json` 단일 파일로 관리한다 —
|
|
14
|
-
* 이는 build runtime 의 완전한 state machine (RECONSTRUCT_TRANSITIONS) 과 구별되는
|
|
15
|
-
* **runtime 관찰 가능 minimum surface**.
|
|
16
|
-
*/
|
|
17
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
18
|
-
import { join, resolve } from "node:path";
|
|
19
|
-
// ─── Internal helpers ───
|
|
20
|
-
function nowIso() {
|
|
21
|
-
return new Date().toISOString();
|
|
22
|
-
}
|
|
23
|
-
function sessionRoot(sessionsDir, sessionId) {
|
|
24
|
-
return resolve(sessionsDir, sessionId);
|
|
25
|
-
}
|
|
26
|
-
function stateFile(root) {
|
|
27
|
-
return join(root, "reconstruct-state.json");
|
|
28
|
-
}
|
|
29
|
-
function writeState(root, state) {
|
|
30
|
-
writeFileSync(stateFile(root), JSON.stringify(state, null, 2) + "\n", "utf-8");
|
|
31
|
-
}
|
|
32
|
-
function readState(root) {
|
|
33
|
-
const raw = readFileSync(stateFile(root), "utf-8");
|
|
34
|
-
return JSON.parse(raw);
|
|
35
|
-
}
|
|
36
|
-
function makeSessionId(now) {
|
|
37
|
-
const iso = now();
|
|
38
|
-
const date = iso.slice(0, 10).replace(/-/g, "");
|
|
39
|
-
const rand = Math.random().toString(16).slice(2, 10);
|
|
40
|
-
return `${date}-${rand}`;
|
|
41
|
-
}
|
|
42
|
-
// ─── Core API ───
|
|
43
|
-
/**
|
|
44
|
-
* Step 1 — start: session 초기화 + gathering_context 상태 진입.
|
|
45
|
-
*/
|
|
46
|
-
export function executeReconstructStart(options) {
|
|
47
|
-
const now = options.now ?? nowIso;
|
|
48
|
-
const nowStr = now();
|
|
49
|
-
if (options.source.trim() === "") {
|
|
50
|
-
throw new Error("[reconstruct] source is required.");
|
|
51
|
-
}
|
|
52
|
-
if (options.intent.trim() === "") {
|
|
53
|
-
throw new Error("[reconstruct] intent is required.");
|
|
54
|
-
}
|
|
55
|
-
const sessionId = options.sessionId ?? makeSessionId(now);
|
|
56
|
-
const root = sessionRoot(options.sessionsDir, sessionId);
|
|
57
|
-
if (existsSync(root)) {
|
|
58
|
-
throw new Error(`[reconstruct] session already exists: ${sessionId}`);
|
|
59
|
-
}
|
|
60
|
-
mkdirSync(root, { recursive: true });
|
|
61
|
-
const state = {
|
|
62
|
-
session_id: sessionId,
|
|
63
|
-
source: options.source,
|
|
64
|
-
intent: options.intent,
|
|
65
|
-
current_state: "gathering_context",
|
|
66
|
-
created_at: nowStr,
|
|
67
|
-
last_updated_at: nowStr,
|
|
68
|
-
started_at: nowStr,
|
|
69
|
-
explore_invocations: 0,
|
|
70
|
-
ontology_draft_path: null,
|
|
71
|
-
principal_review_status: "pending",
|
|
72
|
-
};
|
|
73
|
-
writeState(root, state);
|
|
74
|
-
return { success: true, session_id: sessionId, session_root: root, state };
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Step 2 — explore: build runtime 의 탐색 loop 1회 호출.
|
|
78
|
-
*
|
|
79
|
-
* 현 단계는 bounded placeholder — state 만 `exploring` 으로 전이하고 invocations 을 증가.
|
|
80
|
-
* 실제 Explorer/lens loop 실행은 후속 W-ID 에서 build runtime 과 연결한다.
|
|
81
|
-
* 이 분리 자체가 W-A-74 의 증분: runtime 관찰 가능 surface 를 build runtime 구현보다 먼저 확보.
|
|
82
|
-
*/
|
|
83
|
-
export function executeReconstructExplore(options) {
|
|
84
|
-
const root = sessionRoot(options.sessionsDir, options.sessionId);
|
|
85
|
-
if (!existsSync(stateFile(root))) {
|
|
86
|
-
throw new Error(`[reconstruct] session not found: ${options.sessionId}`);
|
|
87
|
-
}
|
|
88
|
-
const state = readState(root);
|
|
89
|
-
if (state.current_state === "converted") {
|
|
90
|
-
throw new Error(`[reconstruct] session already converted. explore is not allowed after completion.`);
|
|
91
|
-
}
|
|
92
|
-
const now = (options.now ?? nowIso)();
|
|
93
|
-
const next = {
|
|
94
|
-
...state,
|
|
95
|
-
current_state: "exploring",
|
|
96
|
-
last_updated_at: now,
|
|
97
|
-
explore_invocations: state.explore_invocations + 1,
|
|
98
|
-
};
|
|
99
|
-
writeState(root, next);
|
|
100
|
-
return {
|
|
101
|
-
success: true,
|
|
102
|
-
session_id: options.sessionId,
|
|
103
|
-
state: next,
|
|
104
|
-
next_action: "Resume reconstruct exploration to continue or complete reconstruct to finalize.",
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Step 3 — complete: ontology 초안 산출 + converted 전이 + Principal 검증 요청.
|
|
109
|
-
*
|
|
110
|
-
* 현 단계는 bounded: state 를 converted 로 바꾸고 ontology_draft_path 를 placeholder 로 기록.
|
|
111
|
-
* Principal 검증 경로는 §1.4 reconstruct 완료 기준 축 — 향후 학습 경로와 연결.
|
|
112
|
-
*/
|
|
113
|
-
export function executeReconstructComplete(options) {
|
|
114
|
-
const root = sessionRoot(options.sessionsDir, options.sessionId);
|
|
115
|
-
if (!existsSync(stateFile(root))) {
|
|
116
|
-
throw new Error(`[reconstruct] session not found: ${options.sessionId}`);
|
|
117
|
-
}
|
|
118
|
-
const state = readState(root);
|
|
119
|
-
if (state.current_state === "gathering_context") {
|
|
120
|
-
throw new Error(`[reconstruct] complete requires at least one explore invocation (current: gathering_context).`);
|
|
121
|
-
}
|
|
122
|
-
if (state.current_state === "converted") {
|
|
123
|
-
throw new Error(`[reconstruct] session already converted: ${options.sessionId}`);
|
|
124
|
-
}
|
|
125
|
-
const now = (options.now ?? nowIso)();
|
|
126
|
-
const draftPath = join(root, "ontology-draft.md");
|
|
127
|
-
// Minimal placeholder artifact — 실제 ontology 는 build runtime 이 채운다.
|
|
128
|
-
writeFileSync(draftPath, [
|
|
129
|
-
`# Ontology draft — ${options.sessionId}`,
|
|
130
|
-
"",
|
|
131
|
-
`- source: ${state.source}`,
|
|
132
|
-
`- intent: ${state.intent}`,
|
|
133
|
-
`- explore invocations: ${state.explore_invocations}`,
|
|
134
|
-
"",
|
|
135
|
-
"> Placeholder draft. build runtime (.onto/processes/reconstruct.md) 이 채울 영역.",
|
|
136
|
-
"> §1.4 reconstruct 완료 기준 충족 판단은 Principal 검증 경로에서 이뤄진다.",
|
|
137
|
-
"",
|
|
138
|
-
].join("\n"), "utf-8");
|
|
139
|
-
const next = {
|
|
140
|
-
...state,
|
|
141
|
-
current_state: "converted",
|
|
142
|
-
last_updated_at: now,
|
|
143
|
-
ontology_draft_path: draftPath,
|
|
144
|
-
principal_review_status: "requested",
|
|
145
|
-
};
|
|
146
|
-
writeState(root, next);
|
|
147
|
-
return {
|
|
148
|
-
success: true,
|
|
149
|
-
session_id: options.sessionId,
|
|
150
|
-
state: next,
|
|
151
|
-
next_action: "Present ontology-draft.md to Principal for verification. Update principal_review_status accordingly.",
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
export function executeReconstructConfirm(options) {
|
|
155
|
-
const now = (options.now ?? (() => new Date().toISOString()))();
|
|
156
|
-
const root = resolve(options.sessionsDir, options.sessionId);
|
|
157
|
-
const state = readState(root);
|
|
158
|
-
if (state.current_state !== "converted") {
|
|
159
|
-
throw new Error(`Cannot confirm: session is in "${state.current_state}" state, expected "converted".`);
|
|
160
|
-
}
|
|
161
|
-
if (state.principal_review_status !== "requested") {
|
|
162
|
-
throw new Error(`Cannot confirm: principal_review_status is "${state.principal_review_status}", expected "requested".`);
|
|
163
|
-
}
|
|
164
|
-
const next = {
|
|
165
|
-
...state,
|
|
166
|
-
last_updated_at: now,
|
|
167
|
-
principal_review_status: options.verdict,
|
|
168
|
-
};
|
|
169
|
-
writeState(root, next);
|
|
170
|
-
return {
|
|
171
|
-
success: true,
|
|
172
|
-
session_id: options.sessionId,
|
|
173
|
-
state: next,
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
// ─── Runtime entry ───
|
|
177
|
-
function readOption(argv, name) {
|
|
178
|
-
const idx = argv.indexOf(`--${name}`);
|
|
179
|
-
return idx >= 0 && idx + 1 < argv.length ? argv[idx + 1] : undefined;
|
|
180
|
-
}
|
|
181
|
-
function nonFlagArgs(argv) {
|
|
182
|
-
const out = [];
|
|
183
|
-
for (let i = 0; i < argv.length; i++) {
|
|
184
|
-
const a = argv[i];
|
|
185
|
-
if (a.startsWith("--")) {
|
|
186
|
-
// skip the flag and (if present) its value
|
|
187
|
-
const next = argv[i + 1];
|
|
188
|
-
if (next !== undefined && !next.startsWith("--"))
|
|
189
|
-
i++;
|
|
190
|
-
continue;
|
|
191
|
-
}
|
|
192
|
-
out.push(a);
|
|
193
|
-
}
|
|
194
|
-
return out;
|
|
195
|
-
}
|
|
196
|
-
function defaultSessionsDir(projectRoot) {
|
|
197
|
-
return join(projectRoot, ".onto", "reconstruct");
|
|
198
|
-
}
|
|
199
|
-
export async function handleReconstructCli(_ontoHome, argv) {
|
|
200
|
-
const subcommand = argv[0];
|
|
201
|
-
const subArgv = argv.slice(1);
|
|
202
|
-
const projectRoot = readOption(subArgv, "project-root") ?? process.cwd();
|
|
203
|
-
const sessionsDir = readOption(subArgv, "sessions-dir") ?? defaultSessionsDir(projectRoot);
|
|
204
|
-
if (!existsSync(sessionsDir)) {
|
|
205
|
-
mkdirSync(sessionsDir, { recursive: true });
|
|
206
|
-
}
|
|
207
|
-
switch (subcommand) {
|
|
208
|
-
case "start": {
|
|
209
|
-
const rest = nonFlagArgs(subArgv);
|
|
210
|
-
const source = rest[0];
|
|
211
|
-
const intent = rest.slice(1).join(" ").trim();
|
|
212
|
-
if (!source || !intent) {
|
|
213
|
-
console.error("[onto] reconstruct start requires <source> and <intent>.");
|
|
214
|
-
console.error('Example input: target=./src intent="recover domain ontology"');
|
|
215
|
-
return 1;
|
|
216
|
-
}
|
|
217
|
-
const sessionIdOpt = readOption(subArgv, "session-id");
|
|
218
|
-
try {
|
|
219
|
-
const result = executeReconstructStart({
|
|
220
|
-
source,
|
|
221
|
-
intent,
|
|
222
|
-
sessionsDir,
|
|
223
|
-
...(sessionIdOpt !== undefined ? { sessionId: sessionIdOpt } : {}),
|
|
224
|
-
});
|
|
225
|
-
console.log(JSON.stringify({
|
|
226
|
-
status: "started",
|
|
227
|
-
session_id: result.session_id,
|
|
228
|
-
session_root: result.session_root,
|
|
229
|
-
current_state: result.state.current_state,
|
|
230
|
-
next_action: "Resume reconstruct exploration with the session id to begin exploration.",
|
|
231
|
-
}, null, 2));
|
|
232
|
-
return 0;
|
|
233
|
-
}
|
|
234
|
-
catch (error) {
|
|
235
|
-
console.error(`[onto] reconstruct start error: ${error instanceof Error ? error.message : String(error)}`);
|
|
236
|
-
return 1;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
case "explore": {
|
|
240
|
-
const sessionId = readOption(subArgv, "session-id");
|
|
241
|
-
if (!sessionId) {
|
|
242
|
-
console.error("[onto] reconstruct explore requires --session-id.");
|
|
243
|
-
return 1;
|
|
244
|
-
}
|
|
245
|
-
try {
|
|
246
|
-
const result = executeReconstructExplore({ sessionsDir, sessionId });
|
|
247
|
-
console.log(JSON.stringify({ status: "explored", ...result }, null, 2));
|
|
248
|
-
return 0;
|
|
249
|
-
}
|
|
250
|
-
catch (error) {
|
|
251
|
-
console.error(`[onto] reconstruct explore error: ${error instanceof Error ? error.message : String(error)}`);
|
|
252
|
-
return 1;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
case "complete": {
|
|
256
|
-
const sessionId = readOption(subArgv, "session-id");
|
|
257
|
-
if (!sessionId) {
|
|
258
|
-
console.error("[onto] reconstruct complete requires --session-id.");
|
|
259
|
-
return 1;
|
|
260
|
-
}
|
|
261
|
-
try {
|
|
262
|
-
const result = executeReconstructComplete({ sessionsDir, sessionId });
|
|
263
|
-
console.log(JSON.stringify({ status: "completed", ...result }, null, 2));
|
|
264
|
-
return 0;
|
|
265
|
-
}
|
|
266
|
-
catch (error) {
|
|
267
|
-
console.error(`[onto] reconstruct complete error: ${error instanceof Error ? error.message : String(error)}`);
|
|
268
|
-
return 1;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
case "confirm": {
|
|
272
|
-
const sessionId = readOption(subArgv, "session-id");
|
|
273
|
-
const verdict = readOption(subArgv, "verdict");
|
|
274
|
-
if (!sessionId || !verdict) {
|
|
275
|
-
console.error("[onto] reconstruct confirm requires --session-id and --verdict (passed|rejected).");
|
|
276
|
-
return 1;
|
|
277
|
-
}
|
|
278
|
-
if (verdict !== "passed" && verdict !== "rejected") {
|
|
279
|
-
console.error(`[onto] Invalid verdict: "${verdict}". Must be "passed" or "rejected".`);
|
|
280
|
-
return 1;
|
|
281
|
-
}
|
|
282
|
-
try {
|
|
283
|
-
const result = executeReconstructConfirm({
|
|
284
|
-
sessionsDir,
|
|
285
|
-
sessionId,
|
|
286
|
-
verdict,
|
|
287
|
-
});
|
|
288
|
-
console.log(JSON.stringify({
|
|
289
|
-
status: "confirmed",
|
|
290
|
-
verdict: result.state.principal_review_status,
|
|
291
|
-
session_id: result.session_id,
|
|
292
|
-
}, null, 2));
|
|
293
|
-
return 0;
|
|
294
|
-
}
|
|
295
|
-
catch (error) {
|
|
296
|
-
console.error(`[onto] reconstruct confirm error: ${error instanceof Error ? error.message : String(error)}`);
|
|
297
|
-
return 1;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
case "--help":
|
|
301
|
-
case "-h":
|
|
302
|
-
case undefined:
|
|
303
|
-
console.log([
|
|
304
|
-
"Usage: reconstruct <subcommand> [options]",
|
|
305
|
-
"",
|
|
306
|
-
"Subcommands:",
|
|
307
|
-
" start <source> <intent> Initialize a reconstruct session",
|
|
308
|
-
" explore --session-id <id> Run one exploration invocation (bounded)",
|
|
309
|
-
" complete --session-id <id> Finalize ontology draft + request Principal review",
|
|
310
|
-
" confirm --session-id <id> --verdict passed|rejected",
|
|
311
|
-
" Record Principal verification result",
|
|
312
|
-
"",
|
|
313
|
-
"Options:",
|
|
314
|
-
" --project-root <path> Project root (default: cwd)",
|
|
315
|
-
" --sessions-dir <path> Sessions directory (default: <project-root>/.onto/reconstruct)",
|
|
316
|
-
" --session-id <id> Custom session id (start only)",
|
|
317
|
-
"",
|
|
318
|
-
"Bounded path (review 3-step 대응):",
|
|
319
|
-
" start → explore (1+ times) → complete → confirm",
|
|
320
|
-
"",
|
|
321
|
-
"State is persisted at {session_root}/reconstruct-state.json.",
|
|
322
|
-
"The process contract is .onto/processes/reconstruct.md (activity=reconstruct, process_name=build).",
|
|
323
|
-
].join("\n"));
|
|
324
|
-
return 0;
|
|
325
|
-
default:
|
|
326
|
-
console.error(`[onto] Unknown reconstruct subcommand: ${subcommand}`);
|
|
327
|
-
console.error("Run reconstruct help for usage.");
|
|
328
|
-
return 1;
|
|
329
|
-
}
|
|
330
|
-
}
|