@ybotok/loam 0.2.0-alpha.7 → 0.2.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1315 -1
- package/COMPARISON.md +91 -3
- package/CONTRIBUTING.md +37 -0
- package/MIGRATING-from-OpenSpec.md +40 -22
- package/QUICKSTART.md +181 -9
- package/README.md +256 -57
- package/ROADMAP.md +83 -7
- package/SCHEMA.md +569 -98
- package/WORKFLOW.md +272 -62
- package/dist/cli.js +26 -8
- package/dist/cli.js.map +1 -1
- package/dist/commands/adopt/adopt.js +5 -10
- package/dist/commands/adopt/adopt.js.map +1 -1
- package/dist/commands/archive/archive.js +15 -18
- package/dist/commands/archive/archive.js.map +1 -1
- package/dist/commands/archive/plan/contracts/asyncapi.js +27 -41
- package/dist/commands/archive/plan/contracts/asyncapi.js.map +1 -1
- package/dist/commands/archive/plan/contracts/consumers.js +56 -0
- package/dist/commands/archive/plan/contracts/consumers.js.map +1 -0
- package/dist/commands/archive/plan/contracts/openapi.js +25 -42
- package/dist/commands/archive/plan/contracts/openapi.js.map +1 -1
- package/dist/commands/archive/plan/contracts/verdict-lines.js +41 -0
- package/dist/commands/archive/plan/contracts/verdict-lines.js.map +1 -0
- package/dist/commands/archive/plan/gate.js +3 -7
- package/dist/commands/archive/plan/gate.js.map +1 -1
- package/dist/commands/archive/plan/landscape.js +4 -4
- package/dist/commands/archive/plan/landscape.js.map +1 -1
- package/dist/commands/archive/plan/refusal.js +8 -18
- package/dist/commands/archive/plan/refusal.js.map +1 -1
- package/dist/commands/archive/plan/specs.js +134 -25
- package/dist/commands/archive/plan/specs.js.map +1 -1
- package/dist/commands/archive/plan/state.js +1 -0
- package/dist/commands/archive/plan/state.js.map +1 -1
- package/dist/commands/archive/run.js +33 -11
- package/dist/commands/archive/run.js.map +1 -1
- package/dist/commands/archive/shipped.js +49 -0
- package/dist/commands/archive/shipped.js.map +1 -0
- package/dist/commands/context/context.js +4 -7
- package/dist/commands/context/context.js.map +1 -1
- package/dist/commands/context/print.js +2 -2
- package/dist/commands/context/print.js.map +1 -1
- package/dist/commands/delta/delta.js +44 -12
- package/dist/commands/delta/delta.js.map +1 -1
- package/dist/commands/delta/print.js +1 -1
- package/dist/commands/delta/print.js.map +1 -1
- package/dist/commands/dependencies.js +3 -7
- package/dist/commands/dependencies.js.map +1 -1
- package/dist/commands/diff/diff.js +20 -27
- package/dist/commands/diff/diff.js.map +1 -1
- package/dist/commands/explore.js +4 -8
- package/dist/commands/explore.js.map +1 -1
- package/dist/commands/gate/gate.js +45 -8
- package/dist/commands/gate/gate.js.map +1 -1
- package/dist/commands/gate/print.js +15 -3
- package/dist/commands/gate/print.js.map +1 -1
- package/dist/commands/gherkin/commit.js +13 -54
- package/dist/commands/gherkin/commit.js.map +1 -1
- package/dist/commands/gherkin/gherkin.js +36 -20
- package/dist/commands/gherkin/gherkin.js.map +1 -1
- package/dist/commands/gherkin/reconcile.js +10 -13
- package/dist/commands/gherkin/reconcile.js.map +1 -1
- package/dist/commands/init/first-hour.js +44 -0
- package/dist/commands/init/first-hour.js.map +1 -1
- package/dist/commands/init/init.js +18 -22
- package/dist/commands/init/init.js.map +1 -1
- package/dist/commands/list/campaign/campaign.js +4 -6
- package/dist/commands/list/campaign/campaign.js.map +1 -1
- package/dist/commands/list/json.js +0 -4
- package/dist/commands/list/json.js.map +1 -1
- package/dist/commands/list/list.js +38 -23
- package/dist/commands/list/list.js.map +1 -1
- package/dist/commands/list/print.js +38 -6
- package/dist/commands/list/print.js.map +1 -1
- package/dist/commands/list/suites/suites.js +140 -0
- package/dist/commands/list/suites/suites.js.map +1 -0
- package/dist/commands/list/views.js +28 -33
- package/dist/commands/list/views.js.map +1 -1
- package/dist/commands/mcp/dispatch.js +91 -36
- package/dist/commands/mcp/dispatch.js.map +1 -1
- package/dist/commands/mcp/mcp.js +56 -15
- package/dist/commands/mcp/mcp.js.map +1 -1
- package/dist/commands/mcp/serve.js.map +1 -1
- package/dist/commands/migrate-openspec/materialize/active.js +27 -22
- package/dist/commands/migrate-openspec/materialize/active.js.map +1 -1
- package/dist/commands/migrate-openspec/materialize/stage.js +4 -3
- package/dist/commands/migrate-openspec/materialize/stage.js.map +1 -1
- package/dist/commands/migrate-openspec/materialize/target.js +2 -2
- package/dist/commands/migrate-openspec/materialize/target.js.map +1 -1
- package/dist/commands/migrate-openspec/openspec/decisions.js +9 -14
- package/dist/commands/migrate-openspec/openspec/decisions.js.map +1 -1
- package/dist/commands/migrate-openspec/openspec/error.js +7 -8
- package/dist/commands/migrate-openspec/openspec/error.js.map +1 -1
- package/dist/commands/migrate-openspec/openspec/mapping.js +1 -9
- package/dist/commands/migrate-openspec/openspec/mapping.js.map +1 -1
- package/dist/commands/migrate-openspec/openspec/paths.js +3 -6
- package/dist/commands/migrate-openspec/openspec/paths.js.map +1 -1
- package/dist/commands/new/capability-template.js +118 -0
- package/dist/commands/new/capability-template.js.map +1 -0
- package/dist/commands/new/commit.js +8 -22
- package/dist/commands/new/commit.js.map +1 -1
- package/dist/commands/new/modifies.js +206 -0
- package/dist/commands/new/modifies.js.map +1 -0
- package/dist/commands/new/new.js +59 -14
- package/dist/commands/new/new.js.map +1 -1
- package/dist/commands/new/templates.js +48 -124
- package/dist/commands/new/templates.js.map +1 -1
- package/dist/commands/open.js +3 -7
- package/dist/commands/open.js.map +1 -1
- package/dist/commands/policy/gate.js +27 -0
- package/dist/commands/policy/gate.js.map +1 -1
- package/dist/commands/rebase/plan.js +2 -2
- package/dist/commands/rebase/plan.js.map +1 -1
- package/dist/commands/rebase/rebase.js +60 -35
- package/dist/commands/rebase/rebase.js.map +1 -1
- package/dist/commands/seed/commit.js +21 -25
- package/dist/commands/seed/commit.js.map +1 -1
- package/dist/commands/seed/seed.js +6 -9
- package/dist/commands/seed/seed.js.map +1 -1
- package/dist/commands/show/show.js +3 -7
- package/dist/commands/show/show.js.map +1 -1
- package/dist/commands/status/print.js +13 -4
- package/dist/commands/status/print.js.map +1 -1
- package/dist/commands/status/status.js +3 -7
- package/dist/commands/status/status.js.map +1 -1
- package/dist/commands/steps/steps.js +3 -7
- package/dist/commands/steps/steps.js.map +1 -1
- package/dist/commands/subsystem/edit.js +3 -5
- package/dist/commands/subsystem/edit.js.map +1 -1
- package/dist/commands/subsystem/move.js +5 -8
- package/dist/commands/subsystem/move.js.map +1 -1
- package/dist/commands/subsystem/query.js +2 -4
- package/dist/commands/subsystem/query.js.map +1 -1
- package/dist/commands/subsystem/subsystem.js +4 -7
- package/dist/commands/subsystem/subsystem.js.map +1 -1
- package/dist/commands/subsystem/sync.js +14 -41
- package/dist/commands/subsystem/sync.js.map +1 -1
- package/dist/commands/subsystem/txn/txn.js +17 -38
- package/dist/commands/subsystem/txn/txn.js.map +1 -1
- package/dist/commands/subsystem/txn/views.js +32 -5
- package/dist/commands/subsystem/txn/views.js.map +1 -1
- package/dist/commands/tasks/render.js +116 -0
- package/dist/commands/tasks/render.js.map +1 -0
- package/dist/commands/tasks/tasks.js +113 -0
- package/dist/commands/tasks/tasks.js.map +1 -0
- package/dist/commands/unarchive/manifest.js +6 -9
- package/dist/commands/unarchive/manifest.js.map +1 -1
- package/dist/commands/unarchive/restore.js +17 -28
- package/dist/commands/unarchive/restore.js.map +1 -1
- package/dist/commands/unarchive/unarchive.js +22 -30
- package/dist/commands/unarchive/unarchive.js.map +1 -1
- package/dist/commands/validate/arch-coverage.js +6 -15
- package/dist/commands/validate/arch-coverage.js.map +1 -1
- package/dist/commands/validate/checks/fleet-shape.js +4 -49
- package/dist/commands/validate/checks/fleet-shape.js.map +1 -1
- package/dist/commands/validate/checks/requirements.js +18 -8
- package/dist/commands/validate/checks/requirements.js.map +1 -1
- package/dist/commands/validate/checks/sources.js +6 -2
- package/dist/commands/validate/checks/sources.js.map +1 -1
- package/dist/commands/validate/feature.js +23 -19
- package/dist/commands/validate/feature.js.map +1 -1
- package/dist/commands/validate/fleet/landscape.js +23 -23
- package/dist/commands/validate/fleet/landscape.js.map +1 -1
- package/dist/commands/validate/fleet/map/attest.js +6 -10
- package/dist/commands/validate/fleet/map/attest.js.map +1 -1
- package/dist/commands/validate/fleet/map/bindings.js +1 -3
- package/dist/commands/validate/fleet/map/bindings.js.map +1 -1
- package/dist/commands/validate/fleet/map/usecases.js +5 -11
- package/dist/commands/validate/fleet/map/usecases.js.map +1 -1
- package/dist/commands/validate/fleet/obligations.js +1 -5
- package/dist/commands/validate/fleet/obligations.js.map +1 -1
- package/dist/commands/validate/fleet/scorecard/print.js +5 -1
- package/dist/commands/validate/fleet/scorecard/print.js.map +1 -1
- package/dist/commands/validate/fleet/scorecard/scorecard.js +17 -11
- package/dist/commands/validate/fleet/scorecard/scorecard.js.map +1 -1
- package/dist/commands/validate/fleet/usecases/usecases.js +6 -4
- package/dist/commands/validate/fleet/usecases/usecases.js.map +1 -1
- package/dist/commands/validate/fleet/views/fleet-project.js.map +1 -1
- package/dist/commands/validate/fleet/views/root-documents.js +8 -28
- package/dist/commands/validate/fleet/views/root-documents.js.map +1 -1
- package/dist/commands/validate/links/corpus.js +1 -4
- package/dist/commands/validate/links/corpus.js.map +1 -1
- package/dist/commands/validate/links/glossary.js.map +1 -1
- package/dist/commands/validate/report.js +5 -4
- package/dist/commands/validate/report.js.map +1 -1
- package/dist/commands/validate/scope.js +113 -0
- package/dist/commands/validate/scope.js.map +1 -0
- package/dist/commands/validate/service/api.js +16 -104
- package/dist/commands/validate/service/api.js.map +1 -1
- package/dist/commands/validate/service/contracts/generated.js +134 -0
- package/dist/commands/validate/service/contracts/generated.js.map +1 -0
- package/dist/commands/validate/service/events/events.js +1 -1
- package/dist/commands/validate/service/events/events.js.map +1 -1
- package/dist/commands/validate/service/events/message-producers.js +1 -1
- package/dist/commands/validate/service/events/message-producers.js.map +1 -1
- package/dist/commands/validate/service/evidence-pins.js +56 -10
- package/dist/commands/validate/service/evidence-pins.js.map +1 -1
- package/dist/commands/validate/service/service.js +16 -26
- package/dist/commands/validate/service/service.js.map +1 -1
- package/dist/commands/validate/service/specs.js +31 -38
- package/dist/commands/validate/service/specs.js.map +1 -1
- package/dist/commands/validate/service/spine.js +8 -11
- package/dist/commands/validate/service/spine.js.map +1 -1
- package/dist/commands/validate/service/usecases/usecases.js +3 -3
- package/dist/commands/validate/service/usecases/usecases.js.map +1 -1
- package/dist/commands/validate/validate.js +44 -26
- package/dist/commands/validate/validate.js.map +1 -1
- package/dist/commands/verify/cross/diff.js +2 -6
- package/dist/commands/verify/cross/diff.js.map +1 -1
- package/dist/commands/verify/evidence/contract.js +1 -1
- package/dist/commands/verify/evidence/contract.js.map +1 -1
- package/dist/commands/verify/evidence/read.js +12 -3
- package/dist/commands/verify/evidence/read.js.map +1 -1
- package/dist/commands/verify/frozen.js +45 -23
- package/dist/commands/verify/frozen.js.map +1 -1
- package/dist/commands/verify/record.js +69 -17
- package/dist/commands/verify/record.js.map +1 -1
- package/dist/commands/verify/report.js +27 -44
- package/dist/commands/verify/report.js.map +1 -1
- package/dist/commands/verify/results.js +112 -30
- package/dist/commands/verify/results.js.map +1 -1
- package/dist/commands/verify/verify.js +54 -51
- package/dist/commands/verify/verify.js.map +1 -1
- package/dist/commands/vouch/pack/pack.js +2 -2
- package/dist/commands/vouch/pack/pack.js.map +1 -1
- package/dist/commands/vouch/pack/print.js +1 -6
- package/dist/commands/vouch/pack/print.js.map +1 -1
- package/dist/commands/vouch/pack/sections.js +1 -2
- package/dist/commands/vouch/pack/sections.js.map +1 -1
- package/dist/commands/vouch/run.js +26 -81
- package/dist/commands/vouch/run.js.map +1 -1
- package/dist/commands/vouch/sample/plan.js +20 -34
- package/dist/commands/vouch/sample/plan.js.map +1 -1
- package/dist/commands/vouch/vet/verify.js +39 -7
- package/dist/commands/vouch/vet/verify.js.map +1 -1
- package/dist/commands/vouch/vouch.js +10 -17
- package/dist/commands/vouch/vouch.js.map +1 -1
- package/dist/core/agent/agents-md/command-map.js +56 -101
- package/dist/core/agent/agents-md/command-map.js.map +1 -1
- package/dist/core/agent/agents-md/map/explain.js +4 -3
- package/dist/core/agent/agents-md/map/explain.js.map +1 -1
- package/dist/core/agent/agents-md/map/lenses/context.js +4 -3
- package/dist/core/agent/agents-md/map/lenses/context.js.map +1 -1
- package/dist/core/agent/agents-md/map/lenses/diff.js +33 -20
- package/dist/core/agent/agents-md/map/lenses/diff.js.map +1 -1
- package/dist/core/agent/agents-md/map/lenses/gate.js +13 -5
- package/dist/core/agent/agents-md/map/lenses/gate.js.map +1 -1
- package/dist/core/agent/agents-md/map/mcp.js +10 -7
- package/dist/core/agent/agents-md/map/mcp.js.map +1 -1
- package/dist/core/agent/agents-md/map/status.js +9 -3
- package/dist/core/agent/agents-md/map/status.js.map +1 -1
- package/dist/core/agent/agents-md/map/subsystem.js +4 -3
- package/dist/core/agent/agents-md/map/subsystem.js.map +1 -1
- package/dist/core/agent/agents-md/map/usecases.js +24 -6
- package/dist/core/agent/agents-md/map/usecases.js.map +1 -1
- package/dist/core/agent/agents-md/refusals.js +32 -18
- package/dist/core/agent/agents-md/refusals.js.map +1 -1
- package/dist/core/agent/agents-md.js +9 -3
- package/dist/core/agent/agents-md.js.map +1 -1
- package/dist/core/agent/agents-stamp.js +10 -0
- package/dist/core/agent/agents-stamp.js.map +1 -1
- package/dist/core/agent/scaffold.js +10 -15
- package/dist/core/agent/scaffold.js.map +1 -1
- package/dist/core/agent/tools/dialects.js +1 -0
- package/dist/core/agent/tools/dialects.js.map +1 -1
- package/dist/core/agent/tools/registry.js +41 -76
- package/dist/core/agent/tools/registry.js.map +1 -1
- package/dist/core/agent/workflows/adopt.js +5 -3
- package/dist/core/agent/workflows/adopt.js.map +1 -1
- package/dist/core/agent/workflows/check.js +20 -16
- package/dist/core/agent/workflows/check.js.map +1 -1
- package/dist/core/agent/workflows/closing.js +54 -21
- package/dist/core/agent/workflows/closing.js.map +1 -1
- package/dist/core/agent/workflows/feature.js +79 -11
- package/dist/core/agent/workflows/feature.js.map +1 -1
- package/dist/core/agent/workflows/implement.js +91 -13
- package/dist/core/agent/workflows/implement.js.map +1 -1
- package/dist/core/agent/workflows/reference/authoring.js +3 -1
- package/dist/core/agent/workflows/reference/authoring.js.map +1 -1
- package/dist/core/agent/workflows/reference/codes.js +8 -6
- package/dist/core/agent/workflows/reference/codes.js.map +1 -1
- package/dist/core/agent/workflows/reference/done-check.js +37 -15
- package/dist/core/agent/workflows/reference/done-check.js.map +1 -1
- package/dist/core/agent/workflows/reference/reference.js.map +1 -1
- package/dist/core/agent/workflows/reference/spine.js +50 -18
- package/dist/core/agent/workflows/reference/spine.js.map +1 -1
- package/dist/core/asyncapi/baseline/plan.js +14 -81
- package/dist/core/asyncapi/baseline/plan.js.map +1 -1
- package/dist/core/asyncapi/digest.js +30 -25
- package/dist/core/asyncapi/digest.js.map +1 -1
- package/dist/core/asyncapi/merge/components.js +5 -4
- package/dist/core/asyncapi/merge/components.js.map +1 -1
- package/dist/core/asyncapi/merge/error.js +7 -2
- package/dist/core/asyncapi/merge/error.js.map +1 -1
- package/dist/core/asyncapi/merge/markers.js +30 -50
- package/dist/core/asyncapi/merge/markers.js.map +1 -1
- package/dist/core/asyncapi/merge/merge.js +31 -53
- package/dist/core/asyncapi/merge/merge.js.map +1 -1
- package/dist/core/asyncapi/merge/pin.js +10 -36
- package/dist/core/asyncapi/merge/pin.js.map +1 -1
- package/dist/core/asyncapi/model.js.map +1 -1
- package/dist/core/asyncapi/read.js +36 -12
- package/dist/core/asyncapi/read.js.map +1 -1
- package/dist/core/brief/brief.js +6 -18
- package/dist/core/brief/brief.js.map +1 -1
- package/dist/core/brief/landscape.js +8 -12
- package/dist/core/brief/landscape.js.map +1 -1
- package/dist/core/brief/map/extend.js +8 -5
- package/dist/core/brief/map/extend.js.map +1 -1
- package/dist/core/brief/map/owed.js +8 -26
- package/dist/core/brief/map/owed.js.map +1 -1
- package/dist/core/brief/targets.js +15 -5
- package/dist/core/brief/targets.js.map +1 -1
- package/dist/core/c4/likec4.js +147 -16
- package/dist/core/c4/likec4.js.map +1 -1
- package/dist/core/c4/locate/unlocated.js +150 -0
- package/dist/core/c4/locate/unlocated.js.map +1 -0
- package/dist/core/c4/parsed/values.js +54 -1
- package/dist/core/c4/parsed/values.js.map +1 -1
- package/dist/core/c4/prefetch/fleet.js +1 -9
- package/dist/core/c4/prefetch/fleet.js.map +1 -1
- package/dist/core/c4/project/documents.js +31 -6
- package/dist/core/c4/project/documents.js.map +1 -1
- package/dist/core/c4/project/load.js +6 -17
- package/dist/core/c4/project/load.js.map +1 -1
- package/dist/core/c4/resolve/external.js +51 -0
- package/dist/core/c4/resolve/external.js.map +1 -0
- package/dist/core/c4/resolve/service.js +25 -1
- package/dist/core/c4/resolve/service.js.map +1 -1
- package/dist/core/c4/seed/template.js +15 -1
- package/dist/core/c4/seed/template.js.map +1 -1
- package/dist/core/c4/service-model/shape.js +2 -22
- package/dist/core/c4/service-model/shape.js.map +1 -1
- package/dist/core/c4/source-mask.js +288 -4
- package/dist/core/c4/source-mask.js.map +1 -1
- package/dist/core/c4/source-scan.js +203 -147
- package/dist/core/c4/source-scan.js.map +1 -1
- package/dist/core/c4/splice/authored-source.js +19 -0
- package/dist/core/c4/splice/authored-source.js.map +1 -1
- package/dist/core/c4/splice/delta-blocks.js +5 -18
- package/dist/core/c4/splice/delta-blocks.js.map +1 -1
- package/dist/core/c4/splice/landscape-merge.js +13 -8
- package/dist/core/c4/splice/landscape-merge.js.map +1 -1
- package/dist/core/c4/splice/model/merge.js +10 -6
- package/dist/core/c4/splice/model/merge.js.map +1 -1
- package/dist/core/c4/splice/placement.js +108 -18
- package/dist/core/c4/splice/placement.js.map +1 -1
- package/dist/core/c4/workspace.js +13 -22
- package/dist/core/c4/workspace.js.map +1 -1
- package/dist/core/capabilities/capabilities.js +6 -6
- package/dist/core/capabilities/capabilities.js.map +1 -1
- package/dist/core/capabilities/delta/doc.js +7 -10
- package/dist/core/capabilities/delta/doc.js.map +1 -1
- package/dist/core/capabilities/findings.js +15 -20
- package/dist/core/capabilities/findings.js.map +1 -1
- package/dist/core/capabilities/realizes/findings.js +12 -19
- package/dist/core/capabilities/realizes/findings.js.map +1 -1
- package/dist/core/capabilities/realizes/join.js +0 -20
- package/dist/core/capabilities/realizes/join.js.map +1 -1
- package/dist/core/capabilities/rollup.js +6 -0
- package/dist/core/capabilities/rollup.js.map +1 -1
- package/dist/core/capabilities/tree.js +6 -28
- package/dist/core/capabilities/tree.js.map +1 -1
- package/dist/core/capabilities/usecase-join.js +3 -13
- package/dist/core/capabilities/usecase-join.js.map +1 -1
- package/dist/core/coherence/authoring/scaffold.js +11 -3
- package/dist/core/coherence/authoring/scaffold.js.map +1 -1
- package/dist/core/coherence/authoring/sentinels.js +2 -1
- package/dist/core/coherence/authoring/sentinels.js.map +1 -1
- package/dist/core/coherence/coherence.js +30 -16
- package/dist/core/coherence/coherence.js.map +1 -1
- package/dist/core/coherence/consumed/operations.js +70 -0
- package/dist/core/coherence/consumed/operations.js.map +1 -0
- package/dist/core/coherence/consumed/refusal.js +38 -0
- package/dist/core/coherence/consumed/refusal.js.map +1 -0
- package/dist/core/coherence/declared.js +60 -34
- package/dist/core/coherence/declared.js.map +1 -1
- package/dist/core/coherence/events/declared.js +44 -59
- package/dist/core/coherence/events/declared.js.map +1 -1
- package/dist/core/coherence/events/events.js +119 -8
- package/dist/core/coherence/events/events.js.map +1 -1
- package/dist/core/coherence/events/grades.js +31 -8
- package/dist/core/coherence/events/grades.js.map +1 -1
- package/dist/core/coherence/events/lookups.js +14 -82
- package/dist/core/coherence/events/lookups.js.map +1 -1
- package/dist/core/coherence/lookups.js +18 -78
- package/dist/core/coherence/lookups.js.map +1 -1
- package/dist/core/coherence/retired/archived.js +285 -0
- package/dist/core/coherence/retired/archived.js.map +1 -0
- package/dist/core/coherence/retired/event-pair.js +62 -0
- package/dist/core/coherence/retired/event-pair.js.map +1 -0
- package/dist/core/coherence/retired/merged.js +79 -0
- package/dist/core/coherence/retired/merged.js.map +1 -0
- package/dist/core/coherence/retired/retirement.js +49 -0
- package/dist/core/coherence/retired/retirement.js.map +1 -0
- package/dist/core/coherence/retired/revival/arrivals.js +131 -0
- package/dist/core/coherence/retired/revival/arrivals.js.map +1 -0
- package/dist/core/coherence/retired/revival/revived.js +297 -0
- package/dist/core/coherence/retired/revival/revived.js.map +1 -0
- package/dist/core/consumers/after.js +113 -0
- package/dist/core/consumers/after.js.map +1 -0
- package/dist/core/consumers/consumers.js +296 -0
- package/dist/core/consumers/consumers.js.map +1 -0
- package/dist/core/consumers/current.js +211 -0
- package/dist/core/consumers/current.js.map +1 -0
- package/dist/core/consumers/scan.js +46 -0
- package/dist/core/consumers/scan.js.map +1 -0
- package/dist/core/consumers/state.js +27 -0
- package/dist/core/consumers/state.js.map +1 -0
- package/dist/core/delta/delta.js +1 -1
- package/dist/core/delta/delta.js.map +1 -1
- package/dist/core/deployment/delta.js +3 -6
- package/dist/core/deployment/delta.js.map +1 -1
- package/dist/core/diff/base-git.js +94 -12
- package/dist/core/diff/base-git.js.map +1 -1
- package/dist/core/diff/base-state.js +28 -16
- package/dist/core/diff/base-state.js.map +1 -1
- package/dist/core/diff/joins.js +136 -0
- package/dist/core/diff/joins.js.map +1 -0
- package/dist/core/diff/scope/changed-paths.js +22 -6
- package/dist/core/diff/scope/changed-paths.js.map +1 -1
- package/dist/core/diff/scope/edges.js +82 -0
- package/dist/core/diff/scope/edges.js.map +1 -0
- package/dist/core/diff/semantic.js +100 -31
- package/dist/core/diff/semantic.js.map +1 -1
- package/dist/core/doctor/agents.js +34 -18
- package/dist/core/doctor/agents.js.map +1 -1
- package/dist/core/doctor/report.js.map +1 -1
- package/dist/core/document/apply.js +10 -2
- package/dist/core/document/apply.js.map +1 -1
- package/dist/core/document/frontmatter.js +55 -0
- package/dist/core/document/frontmatter.js.map +1 -1
- package/dist/core/document/parse.js +29 -6
- package/dist/core/document/parse.js.map +1 -1
- package/dist/core/document/scenarios.js +17 -0
- package/dist/core/document/scenarios.js.map +1 -1
- package/dist/core/document/spec.js +4 -11
- package/dist/core/document/spec.js.map +1 -1
- package/dist/core/envelope/config.js +10 -0
- package/dist/core/envelope/config.js.map +1 -1
- package/dist/core/envelope/json.js +34 -0
- package/dist/core/envelope/json.js.map +1 -1
- package/dist/core/explain/families.js +17 -12
- package/dist/core/explain/families.js.map +1 -1
- package/dist/core/explain/refusals.js +3 -3
- package/dist/core/explain/refusals.js.map +1 -1
- package/dist/core/explain/terms.js +18 -9
- package/dist/core/explain/terms.js.map +1 -1
- package/dist/core/explore/explore.js +2 -7
- package/dist/core/explore/explore.js.map +1 -1
- package/dist/core/fleet-context.js +34 -95
- package/dist/core/fleet-context.js.map +1 -1
- package/dist/core/gate/checks.js +5 -2
- package/dist/core/gate/checks.js.map +1 -1
- package/dist/core/gate/partners.js +4 -2
- package/dist/core/gate/partners.js.map +1 -1
- package/dist/core/gate/report.js.map +1 -1
- package/dist/core/gate/verification.js +75 -12
- package/dist/core/gate/verification.js.map +1 -1
- package/dist/core/gherkin/stale.js +13 -37
- package/dist/core/gherkin/stale.js.map +1 -1
- package/dist/core/glossary/tree.js +6 -19
- package/dist/core/glossary/tree.js.map +1 -1
- package/dist/core/kernel/concurrency.js +19 -0
- package/dist/core/kernel/concurrency.js.map +1 -1
- package/dist/core/kernel/records.js +11 -0
- package/dist/core/kernel/records.js.map +1 -1
- package/dist/core/links/backlinks.js +1 -3
- package/dist/core/links/backlinks.js.map +1 -1
- package/dist/core/links/corpus.js +5 -36
- package/dist/core/links/corpus.js.map +1 -1
- package/dist/core/mcp/argv.js +101 -0
- package/dist/core/mcp/argv.js.map +1 -1
- package/dist/core/mcp/author-tools.js +2 -1
- package/dist/core/mcp/author-tools.js.map +1 -1
- package/dist/core/mcp/protocol.js +2 -2
- package/dist/core/mcp/protocol.js.map +1 -1
- package/dist/core/mcp/tools.js +43 -33
- package/dist/core/mcp/tools.js.map +1 -1
- package/dist/core/openapi/baseline/gate.js +53 -12
- package/dist/core/openapi/baseline/gate.js.map +1 -1
- package/dist/core/openapi/baseline/plan.js +22 -8
- package/dist/core/openapi/baseline/plan.js.map +1 -1
- package/dist/core/openapi/baseline/record.js +0 -1
- package/dist/core/openapi/baseline/record.js.map +1 -1
- package/dist/core/openapi/contract-text.js +33 -0
- package/dist/core/openapi/contract-text.js.map +1 -0
- package/dist/core/openapi/contract-tree.js +56 -0
- package/dist/core/openapi/contract-tree.js.map +1 -0
- package/dist/core/openapi/depth.js +38 -24
- package/dist/core/openapi/depth.js.map +1 -1
- package/dist/core/openapi/digest.js +52 -2
- package/dist/core/openapi/digest.js.map +1 -1
- package/dist/core/openapi/doc.js +12 -4
- package/dist/core/openapi/doc.js.map +1 -1
- package/dist/core/openapi/merge/components.js +25 -60
- package/dist/core/openapi/merge/components.js.map +1 -1
- package/dist/core/openapi/merge/error.js +3 -13
- package/dist/core/openapi/merge/error.js.map +1 -1
- package/dist/core/openapi/merge/markers.js +26 -30
- package/dist/core/openapi/merge/markers.js.map +1 -1
- package/dist/core/openapi/merge/merge.js +26 -52
- package/dist/core/openapi/merge/merge.js.map +1 -1
- package/dist/core/openapi/merge/pin.js +15 -35
- package/dist/core/openapi/merge/pin.js.map +1 -1
- package/dist/core/openspec/decide/verdict.js.map +1 -1
- package/dist/core/openspec/inventory.js +4 -5
- package/dist/core/openspec/inventory.js.map +1 -1
- package/dist/core/openspec/model/mapping.js +30 -28
- package/dist/core/openspec/model/mapping.js.map +1 -1
- package/dist/core/openspec/model/model.js +12 -7
- package/dist/core/openspec/model/model.js.map +1 -1
- package/dist/core/openspec/scan/changes.js +10 -4
- package/dist/core/openspec/scan/changes.js.map +1 -1
- package/dist/core/openspec/scan/config.js +7 -16
- package/dist/core/openspec/scan/config.js.map +1 -1
- package/dist/core/openspec/scan/shape.js +63 -19
- package/dist/core/openspec/scan/shape.js.map +1 -1
- package/dist/core/openspec/scan/walk.js +21 -38
- package/dist/core/openspec/scan/walk.js.map +1 -1
- package/dist/core/pack/living.js +2 -16
- package/dist/core/pack/living.js.map +1 -1
- package/dist/core/provenance/findings.js +48 -12
- package/dist/core/provenance/findings.js.map +1 -1
- package/dist/core/provenance/git.js +33 -57
- package/dist/core/provenance/git.js.map +1 -1
- package/dist/core/provenance/gitq/moves.js +71 -114
- package/dist/core/provenance/gitq/moves.js.map +1 -1
- package/dist/core/provenance/gitq/vouched-ancestor.js +2 -2
- package/dist/core/provenance/gitq/vouched-ancestor.js.map +1 -1
- package/dist/core/provenance/sources.js +23 -6
- package/dist/core/provenance/sources.js.map +1 -1
- package/dist/core/provenance/stamp.js +5 -17
- package/dist/core/provenance/stamp.js.map +1 -1
- package/dist/core/repo/entries.js.map +1 -1
- package/dist/core/repo/repo.js +24 -14
- package/dist/core/repo/repo.js.map +1 -1
- package/dist/core/repo/tree/find.js +12 -3
- package/dist/core/repo/tree/find.js.map +1 -1
- package/dist/core/repo/tree/fs.js +27 -1
- package/dist/core/repo/tree/fs.js.map +1 -1
- package/dist/core/repo/tree/walk.js +8 -30
- package/dist/core/repo/tree/walk.js.map +1 -1
- package/dist/core/results.js +47 -12
- package/dist/core/results.js.map +1 -1
- package/dist/core/staging/commit.js +10 -12
- package/dist/core/staging/commit.js.map +1 -1
- package/dist/core/staging/lock.js +74 -12
- package/dist/core/staging/lock.js.map +1 -1
- package/dist/core/staging/recovery/intent.js +2 -5
- package/dist/core/staging/recovery/intent.js.map +1 -1
- package/dist/core/staging/recovery/recover.js +60 -1
- package/dist/core/staging/recovery/recover.js.map +1 -1
- package/dist/core/staging/snapshot/manifest.js +152 -0
- package/dist/core/staging/snapshot/manifest.js.map +1 -0
- package/dist/core/staging/{snapshot.js → snapshot/snapshot.js} +10 -34
- package/dist/core/staging/snapshot/snapshot.js.map +1 -0
- package/dist/core/status/actions/execution.js +11 -0
- package/dist/core/status/actions/execution.js.map +1 -1
- package/dist/core/status/feature/artifacts.js +2 -2
- package/dist/core/status/feature/artifacts.js.map +1 -1
- package/dist/core/status/feature/feature.js +5 -11
- package/dist/core/status/feature/feature.js.map +1 -1
- package/dist/core/status/fleet/fleet.js +6 -2
- package/dist/core/status/fleet/fleet.js.map +1 -1
- package/dist/core/status/fleet/next.js +26 -3
- package/dist/core/status/fleet/next.js.map +1 -1
- package/dist/core/status/report.js.map +1 -1
- package/dist/core/status/verification.js +30 -15
- package/dist/core/status/verification.js.map +1 -1
- package/dist/core/tasks/packet.js +174 -0
- package/dist/core/tasks/packet.js.map +1 -0
- package/dist/core/tasks/record.js +43 -0
- package/dist/core/tasks/record.js.map +1 -0
- package/dist/core/tasks/sources.js +181 -0
- package/dist/core/tasks/sources.js.map +1 -0
- package/dist/core/tasks/stamps.js +76 -0
- package/dist/core/tasks/stamps.js.map +1 -0
- package/dist/core/tasks/unit.js +0 -0
- package/dist/core/tasks/unit.js.map +1 -0
- package/dist/core/usecases/capability.js +11 -14
- package/dist/core/usecases/capability.js.map +1 -1
- package/dist/core/usecases/delta/flows.js +5 -7
- package/dist/core/usecases/delta/flows.js.map +1 -1
- package/dist/core/usecases/fleet.js +178 -31
- package/dist/core/usecases/fleet.js.map +1 -1
- package/dist/core/usecases/operations.js +5 -4
- package/dist/core/usecases/operations.js.map +1 -1
- package/dist/core/usecases/service/flows.js +9 -6
- package/dist/core/usecases/service/flows.js.map +1 -1
- package/dist/core/usecases/suites/participants.js +83 -0
- package/dist/core/usecases/suites/participants.js.map +1 -0
- package/dist/core/usecases/suites/suites.js +45 -0
- package/dist/core/usecases/suites/suites.js.map +1 -0
- package/dist/core/verify/answers.js +12 -5
- package/dist/core/verify/answers.js.map +1 -1
- package/dist/core/verify/build.js +102 -82
- package/dist/core/verify/build.js.map +1 -1
- package/dist/core/verify/checklist.js +3 -0
- package/dist/core/verify/checklist.js.map +1 -1
- package/dist/core/verify/location.js +67 -0
- package/dist/core/verify/location.js.map +1 -0
- package/dist/core/verify/pins/lint.js +3 -2
- package/dist/core/verify/pins/lint.js.map +1 -1
- package/dist/core/verify/pins/pin.js +1 -1
- package/dist/core/verify/pins/pin.js.map +1 -1
- package/dist/core/verify/read/file.js +224 -0
- package/dist/core/verify/read/file.js.map +1 -0
- package/dist/core/verify/{file.js → read/shape.js} +16 -104
- package/dist/core/verify/read/shape.js.map +1 -0
- package/dist/core/verify/read/union.js +105 -0
- package/dist/core/verify/read/union.js.map +1 -0
- package/dist/core/verify/record.js +35 -12
- package/dist/core/verify/record.js.map +1 -1
- package/dist/core/verify/store/commit.js +40 -30
- package/dist/core/verify/store/commit.js.map +1 -1
- package/dist/core/verify/store/render.js +8 -4
- package/dist/core/verify/store/render.js.map +1 -1
- package/dist/core/vocabulary/issue.js +1 -0
- package/dist/core/vocabulary/issue.js.map +1 -1
- package/dist/core/vocabulary/maturity.js +12 -2
- package/dist/core/vocabulary/maturity.js.map +1 -1
- package/examples/README.md +21 -6
- package/examples/docs/architecture/landscape.likec4 +8 -0
- package/examples/docs/architecture/usecases/order-notification.likec4 +6 -2
- package/examples/docs/features/FEAT-101-payment-splitting/specs/payment-service/asyncapi.yaml +11 -8
- package/examples/docs/features/FEAT-101-payment-splitting/specs/payment-split-service/openapi.yaml +6 -6
- package/examples/docs/features/archive/FEAT-088-refunds/specs/payment-service/openapi.yaml +13 -10
- package/examples/docs/services/order-service/asyncapi.yaml +3 -2
- package/examples/docs/services/platform/notification-service/asyncapi.yaml +2 -1
- package/package.json +1 -1
- package/dist/commands/validate/checks/vocabulary.js +0 -16
- package/dist/commands/validate/checks/vocabulary.js.map +0 -1
- package/dist/core/agent/agents-md/artifacts.js +0 -221
- package/dist/core/agent/agents-md/artifacts.js.map +0 -1
- package/dist/core/agent/agents-md/cycle.js +0 -180
- package/dist/core/agent/agents-md/cycle.js.map +0 -1
- package/dist/core/agent/agents-md/shipped/archive-gate.js +0 -98
- package/dist/core/agent/agents-md/shipped/archive-gate.js.map +0 -1
- package/dist/core/agent/agents-md/spine.js +0 -40
- package/dist/core/agent/agents-md/spine.js.map +0 -1
- package/dist/core/coherence/events/merged.js +0 -40
- package/dist/core/coherence/events/merged.js.map +0 -1
- package/dist/core/diff/current-state.js +0 -96
- package/dist/core/diff/current-state.js.map +0 -1
- package/dist/core/diff/victims.js +0 -256
- package/dist/core/diff/victims.js.map +0 -1
- package/dist/core/staging/snapshot.js.map +0 -1
- package/dist/core/verify/file.js.map +0 -1
|
@@ -9,16 +9,17 @@
|
|
|
9
9
|
* survives a refactor.
|
|
10
10
|
*/
|
|
11
11
|
import { isDeepStrictEqual } from "node:util";
|
|
12
|
-
import { isMap
|
|
12
|
+
import { isMap } from "yaml";
|
|
13
13
|
// Every `isRecord` below asks one question of a resolved plain tree: is this a
|
|
14
14
|
// node that can hold OpenAPI keys — an object, not an array?
|
|
15
15
|
import { isRecord } from "../../kernel/records.js";
|
|
16
16
|
import { HTTP_METHODS } from "../doc.js";
|
|
17
|
-
import {
|
|
17
|
+
import { OpenapiMergeError, openapiRefusal } from "./error.js";
|
|
18
|
+
import { readTree, writeTree } from "../contract-tree.js";
|
|
18
19
|
import { classifyOperationBaseline } from "./pin.js";
|
|
19
20
|
import { classifyBaselineDigests, isRemoval, valueDigest } from "../digest.js";
|
|
20
21
|
import { entryFor, readBaselineRecord, restatedSurfaces } from "../baseline/record.js";
|
|
21
|
-
import { opLabel, operationIdOf, plainChild, withoutFeatureMarkers } from "./markers.js";
|
|
22
|
+
import { dropPathIfNoOperations, opLabel, operationIdOf, plainChild, withoutFeatureMarkers } from "./markers.js";
|
|
22
23
|
import { mergeComponentClosure } from "./components.js";
|
|
23
24
|
/**
|
|
24
25
|
* Merge the feature's `paths` into the living OpenAPI structurally (YAML AST, not
|
|
@@ -41,20 +42,8 @@ import { mergeComponentClosure } from "./components.js";
|
|
|
41
42
|
* says so — it is never "nothing to merge".
|
|
42
43
|
*/
|
|
43
44
|
export function mergeOpenapiPaths(livingText, featureText, service) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
throw new OpenapiMergeError("feature", service, feature.errors[0].message);
|
|
47
|
-
}
|
|
48
|
-
let featPlain;
|
|
49
|
-
try {
|
|
50
|
-
// Resolve aliases once with the document's own anchor context. Calling an
|
|
51
|
-
// individual AST node's toJSON() loses that context and can silently turn
|
|
52
|
-
// an aliased operation or component into the wrong value.
|
|
53
|
-
featPlain = feature.toJS() ?? {};
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
throw new OpenapiMergeError("feature", service, errorMessage(error));
|
|
57
|
-
}
|
|
45
|
+
// Aliases resolved once, with the document's own anchor context (readTree).
|
|
46
|
+
const { plain: featPlain } = readTree(featureText, openapiRefusal("feature", service));
|
|
58
47
|
const featPathsPlain = plainChild(featPlain, "paths");
|
|
59
48
|
// The SHAPE refusal is unchanged and stays first: a `paths` that is a
|
|
60
49
|
// sequence or a scalar is a document loam cannot merge. Absent and null
|
|
@@ -77,22 +66,13 @@ export function mergeOpenapiPaths(livingText, featureText, service) {
|
|
|
77
66
|
if (componentsAreTheDelta && !restatedSurfaces(featPlain).some((s) => s.kind === "component")) {
|
|
78
67
|
return noop();
|
|
79
68
|
}
|
|
80
|
-
const living =
|
|
81
|
-
if (living.errors.length > 0) {
|
|
82
|
-
throw new OpenapiMergeError("living", service, living.errors[0].message);
|
|
83
|
-
}
|
|
84
|
-
let livingPlain;
|
|
85
|
-
try {
|
|
86
|
-
livingPlain = living.toJS() ?? {};
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
throw new OpenapiMergeError("living", service, errorMessage(error));
|
|
90
|
-
}
|
|
69
|
+
const { doc: living, plain: livingPlain } = readTree(livingText, openapiRefusal("living", service));
|
|
91
70
|
const livingPathsPlain = plainChild(livingPlain, "paths");
|
|
92
71
|
if (livingPathsPlain !== undefined && livingPathsPlain !== null && !isRecord(livingPathsPlain)) {
|
|
93
72
|
throw new OpenapiMergeError("living", service, "`paths` is not a mapping");
|
|
94
73
|
}
|
|
95
74
|
const modified = [];
|
|
75
|
+
const modifiedOperationIds = new Map();
|
|
96
76
|
const pathItemModified = [];
|
|
97
77
|
const removed = [];
|
|
98
78
|
const quoted = [];
|
|
@@ -147,7 +127,7 @@ export function mergeOpenapiPaths(livingText, featureText, service) {
|
|
|
147
127
|
if (HTTP_METHODS.has(m)) {
|
|
148
128
|
const verdict = classifyOperationBaseline(afterPlain, before === undefined ? undefined : beforePlain);
|
|
149
129
|
// A QUOTE is not a merge input. The author wrote this operation down
|
|
150
|
-
//
|
|
130
|
+
// as a restatement, not because they changed it, so
|
|
151
131
|
// the living contract keeps whatever it holds — including a change
|
|
152
132
|
// that landed after this delta was written. This is mechanical, not a
|
|
153
133
|
// judgement, so `--approve` does not turn it back on: overriding a
|
|
@@ -183,10 +163,16 @@ export function mergeOpenapiPaths(livingText, featureText, service) {
|
|
|
183
163
|
// The difference check covers EVERY key of the path item; only the
|
|
184
164
|
// LABEL depends on whether the key is an HTTP method.
|
|
185
165
|
if (before !== undefined && !isDeepStrictEqual(beforePlain, afterPlain)) {
|
|
186
|
-
if (HTTP_METHODS.has(m))
|
|
187
|
-
|
|
188
|
-
|
|
166
|
+
if (HTTP_METHODS.has(m)) {
|
|
167
|
+
const label = opLabel(beforePlain, afterPlain, m, path);
|
|
168
|
+
modified.push(label);
|
|
169
|
+
const id = operationIdOf(beforePlain) ?? operationIdOf(afterPlain);
|
|
170
|
+
if (id !== undefined)
|
|
171
|
+
modifiedOperationIds.set(label, id);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
189
174
|
pathItemModified.push(`'${m}' (${path})`);
|
|
175
|
+
}
|
|
190
176
|
}
|
|
191
177
|
// Every shape question above was answered from the RESOLVED tree, which
|
|
192
178
|
// is exactly what makes an aliased path item read as an ordinary
|
|
@@ -204,16 +190,10 @@ export function mergeOpenapiPaths(livingText, featureText, service) {
|
|
|
204
190
|
living.setIn(["paths", path, m], publishable[m]);
|
|
205
191
|
written.push({ from: `paths ${path}`, value: publishable[m] });
|
|
206
192
|
}
|
|
207
|
-
//
|
|
208
|
-
//
|
|
209
|
-
//
|
|
210
|
-
|
|
211
|
-
// path goes, whatever else survived beside them. The same cleanup
|
|
212
|
-
// stripOpenapiRemovalMarkers does on the feature side.
|
|
213
|
-
const remaining = living.getIn(["paths", path]);
|
|
214
|
-
if (isMap(remaining) && !remaining.items.some((it) => isScalar(it.key) && HTTP_METHODS.has(String(it.key.value)))) {
|
|
215
|
-
living.deleteIn(["paths", path]);
|
|
216
|
-
}
|
|
193
|
+
// No methods left means the path goes, whatever else survived beside
|
|
194
|
+
// them — the same cleanup stripOpenapiRemovalMarkers does on the
|
|
195
|
+
// feature side, and the reason is spelled once, on the helper.
|
|
196
|
+
dropPathIfNoOperations(living, path);
|
|
217
197
|
continue;
|
|
218
198
|
}
|
|
219
199
|
if (!isRecord(featItemPlain)) {
|
|
@@ -227,15 +207,9 @@ export function mergeOpenapiPaths(livingText, featureText, service) {
|
|
|
227
207
|
}
|
|
228
208
|
const closure = mergeComponentClosure({ living, featPlain, livingPlain, record, written, componentsAreTheDelta });
|
|
229
209
|
const { componentsModified, componentsAdded, componentsQuoted, componentsStale, unresolved } = closure;
|
|
230
|
-
|
|
231
|
-
try {
|
|
232
|
-
text = living.toString();
|
|
233
|
-
}
|
|
234
|
-
catch (error) {
|
|
235
|
-
throw new OpenapiMergeError("living", service, errorMessage(error));
|
|
236
|
-
}
|
|
210
|
+
const text = writeTree(living, openapiRefusal("living", service));
|
|
237
211
|
return {
|
|
238
|
-
text, modified, pathItemModified, removed, quoted, baselineStale,
|
|
212
|
+
text, modified, modifiedOperationIds, pathItemModified, removed, quoted, baselineStale,
|
|
239
213
|
pathItemQuoted, pathItemStale, componentsModified, componentsAdded, componentsQuoted, componentsStale, unresolved,
|
|
240
214
|
};
|
|
241
215
|
}
|
|
@@ -248,8 +222,8 @@ export function mergeOpenapiPaths(livingText, featureText, service) {
|
|
|
248
222
|
*/
|
|
249
223
|
function noop() {
|
|
250
224
|
return {
|
|
251
|
-
text: null, modified: [],
|
|
252
|
-
pathItemQuoted: [], pathItemStale: [], componentsModified: [], componentsAdded: [],
|
|
225
|
+
text: null, modified: [], modifiedOperationIds: new Map(), pathItemModified: [], removed: [], quoted: [],
|
|
226
|
+
baselineStale: [], pathItemQuoted: [], pathItemStale: [], componentsModified: [], componentsAdded: [],
|
|
253
227
|
componentsQuoted: [], componentsStale: [], unresolved: [],
|
|
254
228
|
};
|
|
255
229
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../../../src/core/openapi/merge/merge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AACtD,+EAA+E;AAC/E,6DAA6D;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACvF,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACzF,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AA8DxD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,iBAAiB,CAC/B,UAAkB,EAClB,WAAmB,EACnB,OAAe;IAEf,MAAM,OAAO,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;IAC3C,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,iBAAiB,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAE,CAAC,OAAO,CAAC,CAAC;IAC9E,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's contract folded into the living one, and\n * every condition the caller has to surface afterwards.\n *\n * The result type carries far more than the merged text on purpose. A merge\n * that quietly overwrote an operation, dropped a component, or ran against a\n * stale baseline is not an error — it is a fact the archiving human has to be\n * told, and a return value nobody can forget to read is the only place that\n * survives a refactor.\n */\nimport { isDeepStrictEqual } from \"node:util\";\nimport { isMap, isScalar, parseDocument } from \"yaml\";\n// Every `isRecord` below asks one question of a resolved plain tree: is this a\n// node that can hold OpenAPI keys — an object, not an array?\nimport { isRecord } from \"../../kernel/records.js\";\nimport { HTTP_METHODS } from \"../doc.js\";\nimport { errorMessage, OpenapiMergeError } from \"./error.js\";\nimport { classifyOperationBaseline } from \"./pin.js\";\nimport { classifyBaselineDigests, isRemoval, valueDigest } from \"../digest.js\";\nimport { entryFor, readBaselineRecord, restatedSurfaces } from \"../baseline/record.js\";\nimport { opLabel, operationIdOf, plainChild, withoutFeatureMarkers } from \"./markers.js\";\nimport { mergeComponentClosure } from \"./components.js\";\n\n/** What an OpenAPI path merge computed, including every condition the caller must surface. */\nexport interface OpenapiMergeResult {\n /**\n * The merged living document, or null when the feature document restates\n * nothing at all — neither a path entry nor a component. It used to be null\n * for a document with no `paths` key whatever its components said, and a\n * delta whose whole change was a shared schema archived at exit 0 having\n * merged nothing.\n */\n text: string | null;\n /** Labels of existing operations overwritten with different content. */\n modified: string[];\n /**\n * Labels of PATH-LEVEL keys (`parameters`, `servers`, `summary`, `x-*`)\n * overwritten with different content. They are not operations, so they were\n * excluded from the difference check entirely and overwritten in silence —\n * a delta restating a path with a shorter `parameters` list dropped shared\n * parameters from every operation under it, and the plan said nothing.\n */\n pathItemModified: string[];\n /** Labels of living operations deleted by `x-loam-remove: true` markers. */\n removed: string[];\n /**\n * Labels of operations the delta QUOTED — pinned, and equal to their own\n * baseline — so the merge left the living contract's own copy alone. Reported\n * rather than silent: \"your delta mentions this and I did not write it\" is\n * exactly the sentence whose absence made the revert invisible.\n */\n quoted: string[];\n /**\n * Labels of operations whose pin matches neither the delta's own content nor\n * the living one: edited here AND changed by somebody else in between.\n * `openapi.baseline-stale` refuses these at the gate; the merge still\n * overwrites, because reaching it at all means `--approve` said to.\n */\n baselineStale: string[];\n /** Path-level keys the delta QUOTED (`x-loam-baselines` entry equal to own content) — skipped, living's copy kept. */\n pathItemQuoted: string[];\n /** Path-level keys written on a stale record entry — reaching the merge means `--approve` said to. */\n pathItemStale: string[];\n /** `<kind>/<name>` of living components overwritten with different content. */\n componentsModified: string[];\n /**\n * `<kind>/<name>` of components written into a living contract that did not\n * have them. Beside `componentsModified` because the plan needs a name for\n * what a merge ADDED: a components-only delta merges no operation, and the\n * plan line naming the merged operation ids read `merged ()` for it — empty\n * parentheses, which is how a merge that published a new shared schema\n * looked exactly like one that did nothing.\n */\n componentsAdded: string[];\n /** Components the delta QUOTED — not copied, living's copy kept. */\n componentsQuoted: string[];\n /** Components written on a stale record entry — under `--approve`, like the operations. */\n componentsStale: string[];\n /** Local refs reachable from merged content that resolve in neither document. */\n unresolved: Array<{ ref: string; from: string }>;\n}\n\n\n/**\n * Merge the feature's `paths` into the living OpenAPI structurally (YAML AST, not\n * text splicing). A feature document restating NOTHING — no path entry and no\n * component — is a successful no-op; one whose whole delta is a component is\n * merged like any other, through the closure at the end of this function.\n * The merged operations' local component-ref closure rides along recursively;\n * external refs are left untouched and never gated.\n *\n * Every SHAPE question — is there a `paths` mapping, is this path item a\n * mapping, which methods does it hold — is answered from the RESOLVED plain\n * trees, never from the AST node. Asking the AST (`isMap(node)`) answers a\n * different question: an alias node is not a map even when it resolves to one.\n * `paths: *alias` therefore read as \"no paths to merge\" and the whole contract\n * delta was dropped with a successful exit, and an aliased path ITEM fell into\n * the wholesale-replace branch and deleted every living operation on that path\n * that the alias did not restate. Aliases are legal OpenAPI and the natural way\n * to write a delta that repeats a shape; nothing here may treat them as absent.\n * An alias that cannot be resolved at all is a document loam cannot read, and\n * says so — it is never \"nothing to merge\".\n */\nexport function mergeOpenapiPaths(\n livingText: string,\n featureText: string,\n service: string,\n): OpenapiMergeResult {\n const feature = parseDocument(featureText);\n if (feature.errors.length > 0) {\n throw new OpenapiMergeError(\"feature\", service, feature.errors[0]!.message);\n }\n let featPlain: unknown;\n try {\n // Resolve aliases once with the document's own anchor context. Calling an\n // individual AST node's toJSON() loses that context and can silently turn\n // an aliased operation or component into the wrong value.\n featPlain = feature.toJS() ?? {};\n } catch (error) {\n throw new OpenapiMergeError(\"feature\", service, errorMessage(error));\n }\n const featPathsPlain = plainChild(featPlain, \"paths\");\n // The SHAPE refusal is unchanged and stays first: a `paths` that is a\n // sequence or a scalar is a document loam cannot merge. Absent and null\n // (`paths:` with nothing under it) are not shape faults — they are documents\n // holding no path entries, which is a different sentence and now has a\n // different answer.\n if (featPathsPlain !== undefined && featPathsPlain !== null && !isRecord(featPathsPlain)) {\n throw new OpenapiMergeError(\"feature\", service, \"`paths` is not a mapping\");\n }\n const featPathEntries = isRecord(featPathsPlain) ? Object.entries(featPathsPlain) : [];\n // \"Is there anything to merge?\" is a question about the whole delta, and for\n // years it was asked of `paths` alone — an absence test standing in for the\n // decision. It returned here, before the living document was even parsed, so\n // the component closure (the last statement of this function, and the only\n // thing that writes a component) never ran: a feature whose entire change was\n // a shared schema passed the gate and archived at exit 0 having merged\n // NOTHING. The components answer it too now, over the ONE surface\n // enumeration the gate and the rebase plan already grade the delta with.\n const componentsAreTheDelta = featPathEntries.length === 0;\n if (componentsAreTheDelta && !restatedSurfaces(featPlain).some((s) => s.kind === \"component\")) {\n return noop();\n }\n\n const living = parseDocument(livingText);\n if (living.errors.length > 0) {\n throw new OpenapiMergeError(\"living\", service, living.errors[0]!.message);\n }\n let livingPlain: unknown;\n try {\n livingPlain = living.toJS() ?? {};\n } catch (error) {\n throw new OpenapiMergeError(\"living\", service, errorMessage(error));\n }\n const livingPathsPlain = plainChild(livingPlain, \"paths\");\n if (livingPathsPlain !== undefined && livingPathsPlain !== null && !isRecord(livingPathsPlain)) {\n throw new OpenapiMergeError(\"living\", service, \"`paths` is not a mapping\");\n }\n const modified: string[] = [];\n const pathItemModified: string[] = [];\n const removed: string[] = [];\n const quoted: string[] = [];\n const baselineStale: string[] = [];\n const pathItemQuoted: string[] = [];\n const pathItemStale: string[] = [];\n // The surface record, read ONCE for the path-item loop and the component\n // closure. Malformed entries read back as absent — the gate refuses them,\n // and a value nobody can evaluate must never be why a merge skips a write.\n const { record } = readBaselineRecord(featPlain);\n // The plain values this merge actually WRITES, labelled for the ref sweep:\n // the closure copies new components reachable from these, and only these —\n // a quoted operation's refs are living's own business.\n const written: Array<{ from: string; value: unknown }> = [];\n for (const [path, featItemPlain] of featPathEntries) {\n const existing = living.getIn([\"paths\", path]);\n const existingPlain = plainChild(livingPathsPlain, path);\n if (existing !== undefined && !isRecord(existingPlain)) {\n // The living contract holds this path as something other than a path\n // item. Replacing it wholesale is the one branch that may delete living\n // operations without naming them, so it is reserved for paths the living\n // contract does not have at all.\n throw new OpenapiMergeError(\"living\", service, `path '${path}' is not a mapping`);\n }\n if (existing !== undefined) {\n if (!isRecord(featItemPlain)) {\n throw new OpenapiMergeError(\"feature\", service, `path '${path}' is not a mapping`);\n }\n // EVERY branch publishes through withoutFeatureMarkers. This one used to\n // copy every key of the feature path item and guard only the HTTP\n // methods, so a path-level `x-loam-remove` landed in the living contract\n // with `modified: []` and no warning. A key the strip drops is never\n // written; the removal handling below still reads the RAW item, because\n // that is where the markers it acts on live.\n const publish = withoutFeatureMarkers(featItemPlain);\n const publishable = isRecord(publish) ? publish : {};\n for (const [m, afterPlain] of Object.entries(featItemPlain)) {\n const before = living.getIn([\"paths\", path, m]);\n const beforePlain = plainChild(existingPlain, m);\n if (HTTP_METHODS.has(m) && isRemoval(afterPlain)) {\n // Coherence validates the marker and gates absent/mismatched targets.\n // The merge remains defensive under --approve: never delete a\n // different operation merely because it occupies the requested slot.\n if (\n before !== undefined &&\n operationIdOf(beforePlain) !== undefined &&\n operationIdOf(beforePlain) === operationIdOf(afterPlain)\n ) {\n removed.push(opLabel(beforePlain, afterPlain, m, path));\n living.deleteIn([\"paths\", path, m]);\n }\n continue;\n }\n if (HTTP_METHODS.has(m)) {\n const verdict = classifyOperationBaseline(afterPlain, before === undefined ? undefined : beforePlain);\n // A QUOTE is not a merge input. The author wrote this operation down\n // because the document is complete, not because they changed it, so\n // the living contract keeps whatever it holds — including a change\n // that landed after this delta was written. This is mechanical, not a\n // judgement, so `--approve` does not turn it back on: overriding a\n // gate is a decision, reverting an operation nobody edited is a bug.\n if (verdict === \"quote\") {\n quoted.push(opLabel(beforePlain, afterPlain, m, path));\n continue;\n }\n if (verdict === \"stale\") baselineStale.push(opLabel(beforePlain, afterPlain, m, path));\n }\n if (!(m in publishable)) {\n // A feature-only marker at path level. It is never published, and\n // never reported as a path-item overwrite either — it is not a key of\n // the contract at all. The archive gate names it to the author.\n continue;\n }\n if (!HTTP_METHODS.has(m)) {\n // The operations' verdict, for the keys beside them, from the root\n // record instead of an in-value pin. A QUOTE is skipped for the\n // operations' reason — the author restated it, they did not edit it\n // — and skipping matters MORE here: a path-level key applies to\n // every operation on the path, including ones this feature never\n // mentions. Stale still writes: reaching the merge means --approve.\n const verdict = classifyBaselineDigests(\n entryFor(record, { kind: \"path-item\", path, key: m, value: afterPlain }),\n valueDigest(afterPlain),\n before === undefined ? undefined : valueDigest(beforePlain),\n );\n if (verdict === \"quote\") {\n pathItemQuoted.push(`'${m}' (${path})`);\n continue;\n }\n if (verdict === \"stale\") pathItemStale.push(`'${m}' (${path})`);\n }\n // The difference check covers EVERY key of the path item; only the\n // LABEL depends on whether the key is an HTTP method.\n if (before !== undefined && !isDeepStrictEqual(beforePlain, afterPlain)) {\n if (HTTP_METHODS.has(m)) modified.push(opLabel(beforePlain, afterPlain, m, path));\n else pathItemModified.push(`'${m}' (${path})`);\n }\n // Every shape question above was answered from the RESOLVED tree, which\n // is exactly what makes an aliased path item read as an ordinary\n // mapping. The WRITE cannot be that forgiving: `setIn` walks the AST,\n // and one shared value backs every use of an anchor, so an operation\n // merged through the alias would land in every other path that\n // references it. There is no way to write into one use of an anchor and\n // not the rest, so this is a refusal rather than a fallback — and it is\n // asked here, at the write, because reading is safe and writing is not.\n if (!isMap(living.getIn([\"paths\", path]))) {\n throw new OpenapiMergeError(\n \"living\",\n service,\n `path '${path}' is written as a YAML alias — one shared value backs every use, so merging into it would rewrite every other path that aliases it. Expand it before archiving.`,\n );\n }\n // Without the strip the living contract would grow a pin to a version\n // of itself, and the NEXT feature's baseline would hash it.\n living.setIn([\"paths\", path, m], publishable[m]);\n written.push({ from: `paths ${path}`, value: publishable[m] });\n }\n // Removing the last method leaves a path the contract still advertises\n // and nothing answers — and `{}` is only the easy shape of that state: a\n // surviving path-LEVEL key (`parameters`, `summary`) kept the path alive\n // with zero operations just as misleadingly. No methods left means the\n // path goes, whatever else survived beside them. The same cleanup\n // stripOpenapiRemovalMarkers does on the feature side.\n const remaining = living.getIn([\"paths\", path]);\n if (isMap(remaining) && !remaining.items.some((it) => isScalar(it.key) && HTTP_METHODS.has(String(it.key.value)))) {\n living.deleteIn([\"paths\", path]);\n }\n continue;\n }\n if (!isRecord(featItemPlain)) {\n throw new OpenapiMergeError(\"feature\", service, `path '${path}' is not a mapping`);\n }\n const clean = withoutFeatureMarkers(featItemPlain);\n if (clean !== undefined) {\n living.setIn([\"paths\", path], clean);\n written.push({ from: `paths ${path}`, value: clean });\n }\n }\n\n const closure = mergeComponentClosure({ living, featPlain, livingPlain, record, written, componentsAreTheDelta });\n const { componentsModified, componentsAdded, componentsQuoted, componentsStale, unresolved } = closure;\n\n let text: string;\n try {\n text = living.toString();\n } catch (error) {\n throw new OpenapiMergeError(\"living\", service, errorMessage(error));\n }\n return {\n text, modified, pathItemModified, removed, quoted, baselineStale,\n pathItemQuoted, pathItemStale, componentsModified, componentsAdded, componentsQuoted, componentsStale, unresolved,\n };\n}\n\n/**\n * The successful \"the feature document has nothing to merge\" answer. Every key\n * of the result is spelled here, empty, rather than left off: the two objects\n * are compared field by field in the tests and read field by field by the plan,\n * and a `noop()` that quietly lacked a key would make \"no delta\" and \"a delta\n * that merged nothing\" structurally different shapes of the same answer.\n */\nfunction noop(): OpenapiMergeResult {\n return {\n text: null, modified: [], pathItemModified: [], removed: [], quoted: [], baselineStale: [],\n pathItemQuoted: [], pathItemStale: [], componentsModified: [], componentsAdded: [],\n componentsQuoted: [], componentsStale: [], unresolved: [],\n };\n}\n\n"]}
|
|
1
|
+
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../../../src/core/openapi/merge/merge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,+EAA+E;AAC/E,6DAA6D;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACvF,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACjH,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAuExD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,iBAAiB,CAC/B,UAAkB,EAClB,WAAmB,EACnB,OAAe;IAEf,4EAA4E;IAC5E,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,QAAQ,CAA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;;;;;;GAMG;AACH,SAAS,IAAI;IACX,OAAO;QACL,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,oBAAoB,EAAE,IAAI,GAAG,EAAE,EAAE,gBAAgB,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE;QACxG,aAAa,EAAE,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,eAAe,EAAE,EAAE;QACrG,gBAAgB,EAAE,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE;KAC1D,CAAC;AACJ,CAAC","sourcesContent":["/**\n * The archive-time merge: a feature's contract folded into the living one, and\n * every condition the caller has to surface afterwards.\n *\n * The result type carries far more than the merged text on purpose. A merge\n * that quietly overwrote an operation, dropped a component, or ran against a\n * stale baseline is not an error — it is a fact the archiving human has to be\n * told, and a return value nobody can forget to read is the only place that\n * survives a refactor.\n */\nimport { isDeepStrictEqual } from \"node:util\";\nimport { isMap } from \"yaml\";\n// Every `isRecord` below asks one question of a resolved plain tree: is this a\n// node that can hold OpenAPI keys — an object, not an array?\nimport { isRecord } from \"../../kernel/records.js\";\nimport { HTTP_METHODS } from \"../doc.js\";\nimport { OpenapiMergeError, openapiRefusal } from \"./error.js\";\nimport { readTree, writeTree } from \"../contract-tree.js\";\nimport { classifyOperationBaseline } from \"./pin.js\";\nimport { classifyBaselineDigests, isRemoval, valueDigest } from \"../digest.js\";\nimport { entryFor, readBaselineRecord, restatedSurfaces } from \"../baseline/record.js\";\nimport { dropPathIfNoOperations, opLabel, operationIdOf, plainChild, withoutFeatureMarkers } from \"./markers.js\";\nimport { mergeComponentClosure } from \"./components.js\";\n\n/** What an OpenAPI path merge computed, including every condition the caller must surface. */\nexport interface OpenapiMergeResult {\n /**\n * The merged living document, or null when the feature document restates\n * nothing at all — neither a path entry nor a component. It used to be null\n * for a document with no `paths` key whatever its components said, and a\n * delta whose whole change was a shared schema archived at exit 0 having\n * merged nothing.\n */\n text: string | null;\n /** Labels of existing operations overwritten with different content. */\n modified: string[];\n /**\n * The operationId each `modified` label overwrites, keyed by the label: the\n * LIVING operation's id, or the delta's when the living slot carries none.\n * The living id first because it is the join key consumers name today —\n * `loam archive` asks the fleet's consumer scan with it, to say who the\n * overwrite lands on. A label whose operation carries no id on either side\n * is absent: nothing can name it, so no consumer joins to it by name.\n */\n modifiedOperationIds: ReadonlyMap<string, string>;\n /**\n * Labels of PATH-LEVEL keys (`parameters`, `servers`, `summary`, `x-*`)\n * overwritten with different content. They are not operations, so they were\n * excluded from the difference check entirely and overwritten in silence —\n * a delta restating a path with a shorter `parameters` list dropped shared\n * parameters from every operation under it, and the plan said nothing.\n */\n pathItemModified: string[];\n /** Labels of living operations deleted by `x-loam-remove: true` markers. */\n removed: string[];\n /**\n * Labels of operations the delta QUOTED — pinned, and equal to their own\n * baseline — so the merge left the living contract's own copy alone. Reported\n * rather than silent: \"your delta mentions this and I did not write it\" is\n * exactly the sentence whose absence made the revert invisible.\n */\n quoted: string[];\n /**\n * Labels of operations whose pin matches neither the delta's own content nor\n * the living one: edited here AND changed by somebody else in between.\n * `openapi.baseline-stale` refuses these at the gate; the merge still\n * overwrites, because reaching it at all means `--approve` said to.\n */\n baselineStale: string[];\n /** Path-level keys the delta QUOTED (`x-loam-baselines` entry equal to own content) — skipped, living's copy kept. */\n pathItemQuoted: string[];\n /** Path-level keys written on a stale record entry — reaching the merge means `--approve` said to. */\n pathItemStale: string[];\n /** `<kind>/<name>` of living components overwritten with different content. */\n componentsModified: string[];\n /**\n * `<kind>/<name>` of components written into a living contract that did not\n * have them. Beside `componentsModified` because the plan needs a name for\n * what a merge ADDED: a components-only delta merges no operation, and the\n * plan line naming the merged operation ids read `merged ()` for it — empty\n * parentheses, which is how a merge that published a new shared schema\n * looked exactly like one that did nothing.\n */\n componentsAdded: string[];\n /** Components the delta QUOTED — not copied, living's copy kept. */\n componentsQuoted: string[];\n /** Components written on a stale record entry — under `--approve`, like the operations. */\n componentsStale: string[];\n /** Local refs reachable from merged content that resolve in neither document. */\n unresolved: Array<{ ref: string; from: string }>;\n}\n\n\n/**\n * Merge the feature's `paths` into the living OpenAPI structurally (YAML AST, not\n * text splicing). A feature document restating NOTHING — no path entry and no\n * component — is a successful no-op; one whose whole delta is a component is\n * merged like any other, through the closure at the end of this function.\n * The merged operations' local component-ref closure rides along recursively;\n * external refs are left untouched and never gated.\n *\n * Every SHAPE question — is there a `paths` mapping, is this path item a\n * mapping, which methods does it hold — is answered from the RESOLVED plain\n * trees, never from the AST node. Asking the AST (`isMap(node)`) answers a\n * different question: an alias node is not a map even when it resolves to one.\n * `paths: *alias` therefore read as \"no paths to merge\" and the whole contract\n * delta was dropped with a successful exit, and an aliased path ITEM fell into\n * the wholesale-replace branch and deleted every living operation on that path\n * that the alias did not restate. Aliases are legal OpenAPI and the natural way\n * to write a delta that repeats a shape; nothing here may treat them as absent.\n * An alias that cannot be resolved at all is a document loam cannot read, and\n * says so — it is never \"nothing to merge\".\n */\nexport function mergeOpenapiPaths(\n livingText: string,\n featureText: string,\n service: string,\n): OpenapiMergeResult {\n // Aliases resolved once, with the document's own anchor context (readTree).\n const { plain: featPlain } = readTree(featureText, openapiRefusal(\"feature\", service));\n const featPathsPlain = plainChild(featPlain, \"paths\");\n // The SHAPE refusal is unchanged and stays first: a `paths` that is a\n // sequence or a scalar is a document loam cannot merge. Absent and null\n // (`paths:` with nothing under it) are not shape faults — they are documents\n // holding no path entries, which is a different sentence and now has a\n // different answer.\n if (featPathsPlain !== undefined && featPathsPlain !== null && !isRecord(featPathsPlain)) {\n throw new OpenapiMergeError(\"feature\", service, \"`paths` is not a mapping\");\n }\n const featPathEntries = isRecord(featPathsPlain) ? Object.entries(featPathsPlain) : [];\n // \"Is there anything to merge?\" is a question about the whole delta, and for\n // years it was asked of `paths` alone — an absence test standing in for the\n // decision. It returned here, before the living document was even parsed, so\n // the component closure (the last statement of this function, and the only\n // thing that writes a component) never ran: a feature whose entire change was\n // a shared schema passed the gate and archived at exit 0 having merged\n // NOTHING. The components answer it too now, over the ONE surface\n // enumeration the gate and the rebase plan already grade the delta with.\n const componentsAreTheDelta = featPathEntries.length === 0;\n if (componentsAreTheDelta && !restatedSurfaces(featPlain).some((s) => s.kind === \"component\")) {\n return noop();\n }\n\n const { doc: living, plain: livingPlain } = readTree(livingText, openapiRefusal(\"living\", service));\n const livingPathsPlain = plainChild(livingPlain, \"paths\");\n if (livingPathsPlain !== undefined && livingPathsPlain !== null && !isRecord(livingPathsPlain)) {\n throw new OpenapiMergeError(\"living\", service, \"`paths` is not a mapping\");\n }\n const modified: string[] = [];\n const modifiedOperationIds = new Map<string, string>();\n const pathItemModified: string[] = [];\n const removed: string[] = [];\n const quoted: string[] = [];\n const baselineStale: string[] = [];\n const pathItemQuoted: string[] = [];\n const pathItemStale: string[] = [];\n // The surface record, read ONCE for the path-item loop and the component\n // closure. Malformed entries read back as absent — the gate refuses them,\n // and a value nobody can evaluate must never be why a merge skips a write.\n const { record } = readBaselineRecord(featPlain);\n // The plain values this merge actually WRITES, labelled for the ref sweep:\n // the closure copies new components reachable from these, and only these —\n // a quoted operation's refs are living's own business.\n const written: Array<{ from: string; value: unknown }> = [];\n for (const [path, featItemPlain] of featPathEntries) {\n const existing = living.getIn([\"paths\", path]);\n const existingPlain = plainChild(livingPathsPlain, path);\n if (existing !== undefined && !isRecord(existingPlain)) {\n // The living contract holds this path as something other than a path\n // item. Replacing it wholesale is the one branch that may delete living\n // operations without naming them, so it is reserved for paths the living\n // contract does not have at all.\n throw new OpenapiMergeError(\"living\", service, `path '${path}' is not a mapping`);\n }\n if (existing !== undefined) {\n if (!isRecord(featItemPlain)) {\n throw new OpenapiMergeError(\"feature\", service, `path '${path}' is not a mapping`);\n }\n // EVERY branch publishes through withoutFeatureMarkers. This one used to\n // copy every key of the feature path item and guard only the HTTP\n // methods, so a path-level `x-loam-remove` landed in the living contract\n // with `modified: []` and no warning. A key the strip drops is never\n // written; the removal handling below still reads the RAW item, because\n // that is where the markers it acts on live.\n const publish = withoutFeatureMarkers(featItemPlain);\n const publishable = isRecord(publish) ? publish : {};\n for (const [m, afterPlain] of Object.entries(featItemPlain)) {\n const before = living.getIn([\"paths\", path, m]);\n const beforePlain = plainChild(existingPlain, m);\n if (HTTP_METHODS.has(m) && isRemoval(afterPlain)) {\n // Coherence validates the marker and gates absent/mismatched targets.\n // The merge remains defensive under --approve: never delete a\n // different operation merely because it occupies the requested slot.\n if (\n before !== undefined &&\n operationIdOf(beforePlain) !== undefined &&\n operationIdOf(beforePlain) === operationIdOf(afterPlain)\n ) {\n removed.push(opLabel(beforePlain, afterPlain, m, path));\n living.deleteIn([\"paths\", path, m]);\n }\n continue;\n }\n if (HTTP_METHODS.has(m)) {\n const verdict = classifyOperationBaseline(afterPlain, before === undefined ? undefined : beforePlain);\n // A QUOTE is not a merge input. The author wrote this operation down\n // as a restatement, not because they changed it, so\n // the living contract keeps whatever it holds — including a change\n // that landed after this delta was written. This is mechanical, not a\n // judgement, so `--approve` does not turn it back on: overriding a\n // gate is a decision, reverting an operation nobody edited is a bug.\n if (verdict === \"quote\") {\n quoted.push(opLabel(beforePlain, afterPlain, m, path));\n continue;\n }\n if (verdict === \"stale\") baselineStale.push(opLabel(beforePlain, afterPlain, m, path));\n }\n if (!(m in publishable)) {\n // A feature-only marker at path level. It is never published, and\n // never reported as a path-item overwrite either — it is not a key of\n // the contract at all. The archive gate names it to the author.\n continue;\n }\n if (!HTTP_METHODS.has(m)) {\n // The operations' verdict, for the keys beside them, from the root\n // record instead of an in-value pin. A QUOTE is skipped for the\n // operations' reason — the author restated it, they did not edit it\n // — and skipping matters MORE here: a path-level key applies to\n // every operation on the path, including ones this feature never\n // mentions. Stale still writes: reaching the merge means --approve.\n const verdict = classifyBaselineDigests(\n entryFor(record, { kind: \"path-item\", path, key: m, value: afterPlain }),\n valueDigest(afterPlain),\n before === undefined ? undefined : valueDigest(beforePlain),\n );\n if (verdict === \"quote\") {\n pathItemQuoted.push(`'${m}' (${path})`);\n continue;\n }\n if (verdict === \"stale\") pathItemStale.push(`'${m}' (${path})`);\n }\n // The difference check covers EVERY key of the path item; only the\n // LABEL depends on whether the key is an HTTP method.\n if (before !== undefined && !isDeepStrictEqual(beforePlain, afterPlain)) {\n if (HTTP_METHODS.has(m)) {\n const label = opLabel(beforePlain, afterPlain, m, path);\n modified.push(label);\n const id = operationIdOf(beforePlain) ?? operationIdOf(afterPlain);\n if (id !== undefined) modifiedOperationIds.set(label, id);\n } else {\n pathItemModified.push(`'${m}' (${path})`);\n }\n }\n // Every shape question above was answered from the RESOLVED tree, which\n // is exactly what makes an aliased path item read as an ordinary\n // mapping. The WRITE cannot be that forgiving: `setIn` walks the AST,\n // and one shared value backs every use of an anchor, so an operation\n // merged through the alias would land in every other path that\n // references it. There is no way to write into one use of an anchor and\n // not the rest, so this is a refusal rather than a fallback — and it is\n // asked here, at the write, because reading is safe and writing is not.\n if (!isMap(living.getIn([\"paths\", path]))) {\n throw new OpenapiMergeError(\n \"living\",\n service,\n `path '${path}' is written as a YAML alias — one shared value backs every use, so merging into it would rewrite every other path that aliases it. Expand it before archiving.`,\n );\n }\n // Without the strip the living contract would grow a pin to a version\n // of itself, and the NEXT feature's baseline would hash it.\n living.setIn([\"paths\", path, m], publishable[m]);\n written.push({ from: `paths ${path}`, value: publishable[m] });\n }\n // No methods left means the path goes, whatever else survived beside\n // them — the same cleanup stripOpenapiRemovalMarkers does on the\n // feature side, and the reason is spelled once, on the helper.\n dropPathIfNoOperations(living, path);\n continue;\n }\n if (!isRecord(featItemPlain)) {\n throw new OpenapiMergeError(\"feature\", service, `path '${path}' is not a mapping`);\n }\n const clean = withoutFeatureMarkers(featItemPlain);\n if (clean !== undefined) {\n living.setIn([\"paths\", path], clean);\n written.push({ from: `paths ${path}`, value: clean });\n }\n }\n\n const closure = mergeComponentClosure({ living, featPlain, livingPlain, record, written, componentsAreTheDelta });\n const { componentsModified, componentsAdded, componentsQuoted, componentsStale, unresolved } = closure;\n\n const text = writeTree(living, openapiRefusal(\"living\", service));\n return {\n text, modified, modifiedOperationIds, pathItemModified, removed, quoted, baselineStale,\n pathItemQuoted, pathItemStale, componentsModified, componentsAdded, componentsQuoted, componentsStale, unresolved,\n };\n}\n\n/**\n * The successful \"the feature document has nothing to merge\" answer. Every key\n * of the result is spelled here, empty, rather than left off: the two objects\n * are compared field by field in the tests and read field by field by the plan,\n * and a `noop()` that quietly lacked a key would make \"no delta\" and \"a delta\n * that merged nothing\" structurally different shapes of the same answer.\n */\nfunction noop(): OpenapiMergeResult {\n return {\n text: null, modified: [], modifiedOperationIds: new Map(), pathItemModified: [], removed: [], quoted: [],\n baselineStale: [], pathItemQuoted: [], pathItemStale: [], componentsModified: [], componentsAdded: [],\n componentsQuoted: [], componentsStale: [], unresolved: [],\n };\n}\n\n"]}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The pin that tells a QUOTE from an EDIT.
|
|
3
3
|
*
|
|
4
|
-
* A feature's openapi.yaml
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* A feature's openapi.yaml needs only what it adds, changes or removes, but it
|
|
5
|
+
* may also restate living operations it does not change — for context, or a
|
|
6
|
+
* contract pasted whole — and then much of what it spells is quotation. Without
|
|
7
|
+
* a pin the merge cannot tell the two apart and upserts both,
|
|
7
8
|
* which is how a feature that only meant to touch `cancelOrder` silently
|
|
8
9
|
* reverted another team's landed change to `refundOrder` — no overlap between
|
|
9
10
|
* the two features required, just two deltas over one service.
|
|
@@ -11,19 +12,23 @@
|
|
|
11
12
|
* Separate from `./merge.ts` because this is `loam rebase`'s half: it plans the
|
|
12
13
|
* pins a delta is missing, while the merge only ever reads pins already written.
|
|
13
14
|
*/
|
|
14
|
-
import { isMap
|
|
15
|
+
import { isMap } from "yaml";
|
|
15
16
|
// Every `isRecord` below asks one question of a resolved plain tree: is this a
|
|
16
17
|
// node that can hold OpenAPI keys — an object, not an array?
|
|
17
18
|
import { isRecord } from "../../kernel/records.js";
|
|
18
19
|
import { HTTP_METHODS } from "../doc.js";
|
|
19
20
|
import { classifyBaselineDigests, operationBaselineOf, operationDigest, OPENAPI_BASELINE_KEY, } from "../digest.js";
|
|
20
|
-
import {
|
|
21
|
+
import { openapiRefusal } from "./error.js";
|
|
22
|
+
import { readTree, writeTree } from "../contract-tree.js";
|
|
21
23
|
import { isRemoval } from "../digest.js";
|
|
22
24
|
import { plainChild } from "./markers.js";
|
|
23
25
|
/**
|
|
24
26
|
* Classify one feature operation against its living counterpart, from the raw
|
|
25
|
-
* YAML trees the merge works in
|
|
26
|
-
* the
|
|
27
|
+
* YAML trees the merge works in: what the operation IS, relative to the living
|
|
28
|
+
* contract — the one judgement that tells a QUOTE from an EDIT (the module
|
|
29
|
+
* header says why that judgement exists). The rule itself lives in
|
|
30
|
+
* ../digest.ts, so the gate and the merge cannot drift apart about which
|
|
31
|
+
* operations get written.
|
|
27
32
|
*
|
|
28
33
|
* A malformed pin matches no digest and lands in `stale`, which merges rather
|
|
29
34
|
* than skips. Deliberate: `openapi.baseline-invalid` refuses it at the gate, and
|
|
@@ -51,28 +56,8 @@ export function classifyOperationBaseline(featureOp, livingOp) {
|
|
|
51
56
|
* path the contract does not serve yet.
|
|
52
57
|
*/
|
|
53
58
|
export function pinOpenapiOperations(featureText, livingText, service) {
|
|
54
|
-
const doc =
|
|
55
|
-
|
|
56
|
-
throw new OpenapiMergeError("feature", service, doc.errors[0].message);
|
|
57
|
-
let featPlain;
|
|
58
|
-
let livingPlain;
|
|
59
|
-
try {
|
|
60
|
-
featPlain = doc.toJS() ?? {};
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
throw new OpenapiMergeError("feature", service, errorMessage(error));
|
|
64
|
-
}
|
|
65
|
-
try {
|
|
66
|
-
const parsed = parseDocument(livingText);
|
|
67
|
-
if (parsed.errors.length > 0)
|
|
68
|
-
throw new OpenapiMergeError("living", service, parsed.errors[0].message);
|
|
69
|
-
livingPlain = parsed.toJS() ?? {};
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
if (error instanceof OpenapiMergeError)
|
|
73
|
-
throw error;
|
|
74
|
-
throw new OpenapiMergeError("living", service, errorMessage(error));
|
|
75
|
-
}
|
|
59
|
+
const { doc, plain: featPlain } = readTree(featureText, openapiRefusal("feature", service));
|
|
60
|
+
const { plain: livingPlain } = readTree(livingText, openapiRefusal("living", service));
|
|
76
61
|
const featPaths = plainChild(featPlain, "paths");
|
|
77
62
|
if (!isRecord(featPaths))
|
|
78
63
|
return { text: null, pins: [] };
|
|
@@ -118,11 +103,6 @@ export function pinOpenapiOperations(featureText, livingText, service) {
|
|
|
118
103
|
}
|
|
119
104
|
if (!edited)
|
|
120
105
|
return { text: null, pins };
|
|
121
|
-
|
|
122
|
-
return { text: doc.toString(), pins };
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
throw new OpenapiMergeError("feature", service, errorMessage(error));
|
|
126
|
-
}
|
|
106
|
+
return { text: writeTree(doc, openapiRefusal("feature", service)), pins };
|
|
127
107
|
}
|
|
128
108
|
//# sourceMappingURL=pin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pin.js","sourceRoot":"","sources":["../../../../src/core/openapi/merge/pin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAC5C,+EAA+E;AAC/E,6DAA6D;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,eAAe,EACf,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,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AAC;YACtF,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,oBAAoB,CAAC,EAAE,MAAM,CAAC,CAAC;YACjE,MAAM,GAAG,IAAI,CAAC;QAChB,CAAC;IACH,CAAC;IAED,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACzC,IAAI,CAAC;QACH,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC;IACxC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,iBAAiB,CAAC,SAAS,EAAE,OAAO,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;IACvE,CAAC;AACH,CAAC","sourcesContent":["/**\n * The pin that tells a QUOTE from an EDIT.\n *\n * A feature's openapi.yaml is a complete document, so most of what it spells is\n * quotation: the author restated the living contract around the slot they were\n * changing. Without a pin the merge cannot tell the two apart and upserts both,\n * which is how a feature that only meant to touch `cancelOrder` silently\n * reverted another team's landed change to `refundOrder` — no overlap between\n * the two features required, just two deltas over one service.\n *\n * Separate from `./merge.ts` because this is `loam rebase`'s half: it plans the\n * pins a delta is missing, while the merge only ever reads pins already written.\n */\nimport { isMap, parseDocument } from \"yaml\";\n// Every `isRecord` below asks one question of a resolved plain tree: is this a\n// node that can hold OpenAPI keys — an object, not an array?\nimport { isRecord } from \"../../kernel/records.js\";\nimport { HTTP_METHODS } from \"../doc.js\";\nimport {\n classifyBaselineDigests,\n operationBaselineOf,\n operationDigest,\n OPENAPI_BASELINE_KEY,\n} from \"../digest.js\";\nimport { errorMessage, OpenapiMergeError } from \"./error.js\";\nimport { isRemoval } from \"../digest.js\";\nimport { plainChild } from \"./markers.js\";\n\n/**\n * What a feature's operation IS, relative to the living contract — the one\n * judgement that tells a QUOTE from an EDIT.\n *\n * A feature's openapi.yaml is a complete document, so most of what it spells is\n * quotation: the author restated the living contract around the slot they were\n * changing. Without a pin the merge cannot tell the two apart and upserts both,\n * which is how a feature that only meant to touch `cancelOrder` silently\n * reverted another team's landed change to `refundOrder` — no overlap between\n * the features required, just two deltas over one service.\n */\nexport type OperationBaselineVerdict = ReturnType<typeof classifyBaselineDigests>;\n\n/**\n * Classify one feature operation against its living counterpart, from the raw\n * YAML trees the merge works in. The rule itself lives in ../digest.ts, so\n * the gate and the merge cannot drift apart about which operations get written.\n *\n * A malformed pin matches no digest and lands in `stale`, which merges rather\n * than skips. Deliberate: `openapi.baseline-invalid` refuses it at the gate, and\n * a value nobody can evaluate must never be the reason a merge quietly drops an\n * operation.\n */\nexport function classifyOperationBaseline(featureOp: unknown, livingOp: unknown): OperationBaselineVerdict {\n return classifyBaselineDigests(\n operationBaselineOf(featureOp),\n operationDigest(featureOp),\n livingOp === undefined ? undefined : operationDigest(livingOp),\n );\n}\n\n/** What happened to one operation's `x-loam-based-on`. */\nexport interface OperationPin {\n path: string;\n method: string;\n /** Empty when the operation declares none — the slot is still the identity. */\n operationId: string;\n status:\n /** It had no pin and now has one. */\n | \"pinned\"\n /** It named an older living version; it now names the current one. */\n | \"repinned\"\n /** It already named the current living version — no write. */\n | \"unchanged\"\n /** The living contract has no operation at this slot: this feature is adding it. */\n | \"unresolved\"\n /** Written as a YAML alias — one shared value backs every use, so loam will not stamp through it. */\n | \"unwritable\";\n from: string | null;\n to: string | null;\n}\n\nexport interface OpenapiPinPlan {\n /** The rewritten contract, or null when no pin changes. */\n text: string | null;\n pins: OperationPin[];\n}\n\n/**\n * Pin every operation in a feature contract against the living one — what\n * `loam rebase` writes on this axis.\n *\n * The pin is always `operationDigest` of the LIVING operation, never of the\n * delta's own, and that single rule produces both merge verdicts by itself: an\n * operation the author only QUOTED is byte-equal to living, so its pin equals\n * its own content and `classifyOperationBaseline` calls it a quote; one the\n * author EDITED differs from its pin, so the merge writes it. Nothing has to\n * guess at intent — the document already records it, and the pin makes it\n * legible to the merge.\n *\n * Slot-keyed (path + method), exactly as the merge upserts. An operationId that\n * moved to another slot is a new slot with nothing living behind it, which is\n * `unresolved` and correct: there is no living version of an operation at a\n * path the contract does not serve yet.\n */\nexport function pinOpenapiOperations(featureText: string, livingText: string, service: string): OpenapiPinPlan {\n const doc = parseDocument(featureText);\n if (doc.errors.length > 0) throw new OpenapiMergeError(\"feature\", service, doc.errors[0]!.message);\n let featPlain: unknown;\n let livingPlain: unknown;\n try {\n featPlain = doc.toJS() ?? {};\n } catch (error) {\n throw new OpenapiMergeError(\"feature\", service, errorMessage(error));\n }\n try {\n const parsed = parseDocument(livingText);\n if (parsed.errors.length > 0) throw new OpenapiMergeError(\"living\", service, parsed.errors[0]!.message);\n livingPlain = parsed.toJS() ?? {};\n } catch (error) {\n if (error instanceof OpenapiMergeError) throw error;\n throw new OpenapiMergeError(\"living\", service, errorMessage(error));\n }\n\n const featPaths = plainChild(featPlain, \"paths\");\n if (!isRecord(featPaths)) return { text: null, pins: [] };\n const livingPaths = plainChild(livingPlain, \"paths\");\n\n const pins: OperationPin[] = [];\n let edited = false;\n for (const [path, item] of Object.entries(featPaths)) {\n if (!isRecord(item)) continue;\n for (const [method, op] of Object.entries(item)) {\n if (!HTTP_METHODS.has(method) || !isRecord(op)) continue;\n // A removal marker asserts a slot rather than restating an operation, so\n // it has nothing to be based on; `openapi.remove-target-mismatch` is what\n // guards it against a living slot that moved under it.\n if (isRemoval(op)) continue;\n\n const id = typeof op[\"operationId\"] === \"string\" ? op[\"operationId\"] : \"\";\n const at = { path, method, operationId: id };\n const from = operationBaselineOf(op) ?? null;\n const livingItem = plainChild(livingPaths, path);\n const livingOp = isRecord(livingItem) ? livingItem[method] : undefined;\n if (!isRecord(livingOp)) {\n pins.push({ ...at, status: \"unresolved\", from, to: null });\n continue;\n }\n const digest = operationDigest(livingOp);\n if (from === digest) {\n pins.push({ ...at, status: \"unchanged\", from: digest, to: digest });\n continue;\n }\n // One shared value backs every use of an anchor, so `setIn` through an\n // alias would pin every other use of it too — the same reason\n // stripOpenapiRemovalMarkers refuses to edit aliases in place.\n if (!isMap(doc.getIn([\"paths\", path, method]))) {\n pins.push({ ...at, status: \"unwritable\", from, to: null });\n continue;\n }\n pins.push({ ...at, status: from === null ? \"pinned\" : \"repinned\", from, to: digest });\n doc.setIn([\"paths\", path, method, OPENAPI_BASELINE_KEY], digest);\n edited = true;\n }\n }\n\n if (!edited) return { text: null, pins };\n try {\n return { text: doc.toString(), pins };\n } catch (error) {\n throw new OpenapiMergeError(\"feature\", service, errorMessage(error));\n }\n}\n\n\n"]}
|
|
1
|
+
{"version":3,"file":"pin.js","sourceRoot":"","sources":["../../../../src/core/openapi/merge/pin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,+EAA+E;AAC/E,6DAA6D;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,eAAe,EACf,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,yBAAyB,CAAC,SAAkB,EAAE,QAAiB;IAC7E,OAAO,uBAAuB,CAC5B,mBAAmB,CAAC,SAAS,CAAC,EAC9B,eAAe,CAAC,SAAS,CAAC,EAC1B,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC,CAC/D,CAAC;AACJ,CAAC;AA6BD;;;;;;;;;;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,KAAK,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;YACtF,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,oBAAoB,CAAC,EAAE,MAAM,CAAC,CAAC;YACjE,MAAM,GAAG,IAAI,CAAC;QAChB,CAAC;IACH,CAAC;IAED,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACzC,OAAO,EAAE,IAAI,EAAE,SAAS,CAAC,GAAG,EAAE,cAAc,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;AAC5E,CAAC","sourcesContent":["/**\n * The pin that tells a QUOTE from an EDIT.\n *\n * A feature's openapi.yaml needs only what it adds, changes or removes, but it\n * may also restate living operations it does not change — for context, or a\n * contract pasted whole — and then much of what it spells is quotation. Without\n * a pin the merge cannot tell the two apart and upserts both,\n * which is how a feature that only meant to touch `cancelOrder` silently\n * reverted another team's landed change to `refundOrder` — no overlap between\n * the two features required, just two deltas over one service.\n *\n * Separate from `./merge.ts` because this is `loam rebase`'s half: it plans the\n * pins a delta is missing, while the merge only ever reads pins already written.\n */\nimport { isMap } from \"yaml\";\n// Every `isRecord` below asks one question of a resolved plain tree: is this a\n// node that can hold OpenAPI keys — an object, not an array?\nimport { isRecord } from \"../../kernel/records.js\";\nimport { HTTP_METHODS } from \"../doc.js\";\nimport {\n classifyBaselineDigests,\n operationBaselineOf,\n operationDigest,\n OPENAPI_BASELINE_KEY,\n} from \"../digest.js\";\nimport { openapiRefusal } from \"./error.js\";\nimport { readTree, writeTree } from \"../contract-tree.js\";\nimport { isRemoval } from \"../digest.js\";\nimport { plainChild } from \"./markers.js\";\n\n/**\n * Classify one feature operation against its living counterpart, from the raw\n * YAML trees the merge works in: what the operation IS, relative to the living\n * contract — the one judgement that tells a QUOTE from an EDIT (the module\n * header says why that judgement exists). The rule itself lives in\n * ../digest.ts, so the gate and the merge cannot drift apart about which\n * operations get written.\n *\n * A malformed pin matches no digest and lands in `stale`, which merges rather\n * than skips. Deliberate: `openapi.baseline-invalid` refuses it at the gate, and\n * a value nobody can evaluate must never be the reason a merge quietly drops an\n * operation.\n */\nexport function classifyOperationBaseline(featureOp: unknown, livingOp: unknown): ReturnType<typeof classifyBaselineDigests> {\n return classifyBaselineDigests(\n operationBaselineOf(featureOp),\n operationDigest(featureOp),\n livingOp === undefined ? undefined : operationDigest(livingOp),\n );\n}\n\n/** What happened to one operation's `x-loam-based-on`. */\nexport interface OperationPin {\n path: string;\n method: string;\n /** Empty when the operation declares none — the slot is still the identity. */\n operationId: string;\n status:\n /** It had no pin and now has one. */\n | \"pinned\"\n /** It named an older living version; it now names the current one. */\n | \"repinned\"\n /** It already named the current living version — no write. */\n | \"unchanged\"\n /** The living contract has no operation at this slot: this feature is adding it. */\n | \"unresolved\"\n /** Written as a YAML alias — one shared value backs every use, so loam will not stamp through it. */\n | \"unwritable\";\n from: string | null;\n to: string | null;\n}\n\nexport interface OpenapiPinPlan {\n /** The rewritten contract, or null when no pin changes. */\n text: string | null;\n pins: OperationPin[];\n}\n\n/**\n * Pin every operation in a feature contract against the living one — what\n * `loam rebase` writes on this axis.\n *\n * The pin is always `operationDigest` of the LIVING operation, never of the\n * delta's own, and that single rule produces both merge verdicts by itself: an\n * operation the author only QUOTED is byte-equal to living, so its pin equals\n * its own content and `classifyOperationBaseline` calls it a quote; one the\n * author EDITED differs from its pin, so the merge writes it. Nothing has to\n * guess at intent — the document already records it, and the pin makes it\n * legible to the merge.\n *\n * Slot-keyed (path + method), exactly as the merge upserts. An operationId that\n * moved to another slot is a new slot with nothing living behind it, which is\n * `unresolved` and correct: there is no living version of an operation at a\n * path the contract does not serve yet.\n */\nexport function pinOpenapiOperations(featureText: string, livingText: string, service: string): OpenapiPinPlan {\n const { doc, plain: featPlain } = readTree(featureText, openapiRefusal(\"feature\", service));\n const { plain: livingPlain } = readTree(livingText, openapiRefusal(\"living\", service));\n\n const featPaths = plainChild(featPlain, \"paths\");\n if (!isRecord(featPaths)) return { text: null, pins: [] };\n const livingPaths = plainChild(livingPlain, \"paths\");\n\n const pins: OperationPin[] = [];\n let edited = false;\n for (const [path, item] of Object.entries(featPaths)) {\n if (!isRecord(item)) continue;\n for (const [method, op] of Object.entries(item)) {\n if (!HTTP_METHODS.has(method) || !isRecord(op)) continue;\n // A removal marker asserts a slot rather than restating an operation, so\n // it has nothing to be based on; `openapi.remove-target-mismatch` is what\n // guards it against a living slot that moved under it.\n if (isRemoval(op)) continue;\n\n const id = typeof op[\"operationId\"] === \"string\" ? op[\"operationId\"] : \"\";\n const at = { path, method, operationId: id };\n const from = operationBaselineOf(op) ?? null;\n const livingItem = plainChild(livingPaths, path);\n const livingOp = isRecord(livingItem) ? livingItem[method] : undefined;\n if (!isRecord(livingOp)) {\n pins.push({ ...at, status: \"unresolved\", from, to: null });\n continue;\n }\n const digest = operationDigest(livingOp);\n if (from === digest) {\n pins.push({ ...at, status: \"unchanged\", from: digest, to: digest });\n continue;\n }\n // One shared value backs every use of an anchor, so `setIn` through an\n // alias would pin every other use of it too — the same reason\n // stripOpenapiRemovalMarkers refuses to edit aliases in place.\n if (!isMap(doc.getIn([\"paths\", path, method]))) {\n pins.push({ ...at, status: \"unwritable\", from, to: null });\n continue;\n }\n pins.push({ ...at, status: from === null ? \"pinned\" : \"repinned\", from, to: digest });\n doc.setIn([\"paths\", path, method, OPENAPI_BASELINE_KEY], digest);\n edited = true;\n }\n }\n\n if (!edited) return { text: null, pins };\n return { text: writeTree(doc, openapiRefusal(\"feature\", service)), pins };\n}\n\n\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verdict.js","sourceRoot":"","sources":["../../../../src/core/openspec/decide/verdict.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,U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;YAC5J,oBAAoB,EAAE,gBAAgB,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;YACpH,cAAc,EAAE,KAAK;SACtB;QACD,MAAM,EAAE,EAAE,GAAG,YAAY,EAAE,YAAY,EAAE;QACzC,OAAO,EAAE;YACP,MAAM;YACN,QAAQ;YACR,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE;SAC7D;QACD,OAAO;QACP,WAAW,EAAE,QAAQ;QACrB,kBAAkB;QAClB,gBAAgB;QAChB,YAAY;QACZ,eAAe;QACf,kBAAkB;QAClB,aAAa;QACb,SAAS;QACT,iBAAiB;QACjB,gBAAgB;KACjB,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Is this migration ready, and what does the answer look like?\n *\n * Readiness is one judgement over everything the scan and the decisions found,\n * and it lives in one function so the six conditions can be read together. Five\n * of them are human decisions and the sixth is the corpus itself; a migration\n * that satisfied five of six used to read as \"nearly ready\", which is not a\n * state `--apply` may act on.\n *\n * The per-axis `readiness` block exists so an agent can say WHICH of the six is\n * open without re-deriving it from the issue list — the same information, but\n * the derivation is here rather than in every reader.\n */\nimport { compareIds } from \"../../repo/entries.js\";\nimport {\n type CapabilityMappingDecision,\n type OpenSpecChangeDecision,\n type OpenSpecMappingIssue,\n} from \"../model/mapping.js\";\nimport {\n OPENSPEC_BASELINES,\n type OpenSpecArtifact,\n type OpenSpecArtifactDecision,\n type OpenSpecCapability,\n type OpenSpecChange,\n type OpenSpecCounts,\n type OpenSpecInventory,\n type OpenSpecRenamedUsage,\n type OpenSpecUnsupportedShape,\n} from \"../model/model.js\";\nimport { sortIssues } from \"../scan/changes.js\";\n\n/** Everything a finished read produced, before it is graded into a verdict. */\nexport interface Findings {\n located: { inputRoot: string; root: string; kind: OpenSpecInventory[\"workspace\"][\"kind\"] };\n inventoryDigest: string;\n config: OpenSpecInventory[\"workspace\"][\"config\"];\n storeMetadataPath: string | null;\n livingCounts: OpenSpecCounts;\n capabilities: OpenSpecCapability[];\n active: OpenSpecChange[];\n archived: OpenSpecChange[];\n renamed: OpenSpecRenamedUsage[];\n blockers: OpenSpecUnsupportedShape[];\n archiveDiagnostics: OpenSpecUnsupportedShape[];\n artifacts: OpenSpecArtifact[];\n mappingDecisions: CapabilityMappingDecision[];\n changeDecisions: OpenSpecChangeDecision[];\n mappingIssues: OpenSpecMappingIssue[];\n artifactDecisions: OpenSpecArtifactDecision[];\n}\n\nexport function inventoryVerdict(found: Findings): OpenSpecInventory {\n const {\n located, inventoryDigest, config, storeMetadataPath, livingCounts, capabilities,\n active, archived, renamed, blockers, archiveDiagnostics, artifacts,\n mappingDecisions, changeDecisions, mappingIssues, artifactDecisions,\n } = found;\n const { inputRoot, root } = located;\n mappingIssues.sort((a, b) => compareIds(a.key, b.key) || compareIds(a.code, b.code));\n\n renamed.sort((a, b) => compareIds(a.path, b.path) || a.line - b.line || compareIds(a.key, b.key));\n sortIssues(blockers);\n sortIssues(archiveDiagnostics);\n const livingIssueCount = blockers.filter((item) => item.scope === \"workspace\" || item.scope === \"living\").length;\n const activeIssueCount = blockers.filter((item) => item.scope === \"active\").length;\n const needsMapping = mappingDecisions.filter((decision) => decision.status === \"needsMapping\");\n const needsChangeMapping = changeDecisions.filter((decision) => decision.status === \"needsFeature\");\n const needsDisposition = artifactDecisions.filter((decision) => decision.status === \"needsDisposition\");\n const unresolvedActiveRenames = renamed.filter(\n (rename) => rename.scope === \"active\" && rename.status === \"needsIdentity\",\n );\n const mechanicallyCompatible = livingIssueCount === 0 && activeIssueCount === 0;\n const ready = mechanicallyCompatible\n && needsMapping.length === 0\n && needsChangeMapping.length === 0\n && unresolvedActiveRenames.length === 0\n && needsDisposition.length === 0\n && mappingIssues.length === 0;\n\n return {\n baselines: OPENSPEC_BASELINES,\n inputRoot,\n root,\n inventoryDigest,\n workspace: {\n kind: located.kind,\n config,\n storeMetadataPath,\n },\n ready,\n mechanicallyCompatible,\n readiness: {\n living: { compatible: livingIssueCount === 0, issueCount: livingIssueCount },\n active: { compatible: activeIssueCount === 0, issueCount: activeIssueCount },\n sourceCurrent: !mappingIssues.some((item) => item.code.startsWith(\"mapping.source-\")),\n mappingsResolved: needsMapping.length === 0 && !mappingIssues.some((item) =>\n item.code === \"mapping.unknown-capability\"\n || item.code === \"mapping.unknown-requirement\"\n || item.code.startsWith(\"mapping.requirement-\")\n || item.code === \"mapping.service-allocation-empty\"),\n changesResolved: needsChangeMapping.length === 0 && !mappingIssues.some((item) =>\n item.code === \"mapping.unknown-change\"\n || item.code === \"mapping.change-title-missing\"\n || item.code.startsWith(\"mapping.feature-id-\")),\n renamesResolved: unresolvedActiveRenames.length === 0 && !mappingIssues.some((item) => item.code.includes(\"rename\") || item.code.includes(\"requirement-id\")),\n dispositionsResolved: needsDisposition.length === 0 && !mappingIssues.some((item) => item.code.includes(\"artifact\")),\n migrationReady: ready,\n },\n living: { ...livingCounts, capabilities },\n changes: {\n active,\n archived,\n counts: { active: active.length, archived: archived.length },\n },\n renamed,\n unsupported: blockers,\n archiveDiagnostics,\n mappingDecisions,\n needsMapping,\n changeDecisions,\n needsChangeMapping,\n mappingIssues,\n artifacts,\n artifactDecisions,\n needsDisposition,\n };\n}\n"]}
|
|
@@ -22,7 +22,7 @@ import { parseRequirements } from "../document/parse.js";
|
|
|
22
22
|
import { emptyMapping } from "./model/mapping.js";
|
|
23
23
|
import {} from "./model/model.js";
|
|
24
24
|
import { locateOpenSpecRoot } from "./scan/workspace.js";
|
|
25
|
-
import { digestInventory, hiddenSubdirs, isSymbolicLink, portable, sourceInventoryPath, subdirs,
|
|
25
|
+
import { digestInventory, hiddenSubdirs, isSymbolicLink, portable, sourceInventoryPath, subdirs, walkTree, } from "./scan/walk.js";
|
|
26
26
|
import { inspectSpecFile, issue } from "./scan/shape.js";
|
|
27
27
|
import { inspectConfig } from "./scan/config.js";
|
|
28
28
|
import { artifactFor, artifactScope, inventoryChanges } from "./scan/changes.js";
|
|
@@ -44,7 +44,7 @@ export async function inventoryOpenSpec(input, options = {}) {
|
|
|
44
44
|
// contract pins — five arrays merged afterwards would be a different report.
|
|
45
45
|
const ingest = { root, mapping, renamed, unsupported: blockers };
|
|
46
46
|
const archiveDiagnostics = [];
|
|
47
|
-
for (const absolute of await
|
|
47
|
+
for (const absolute of (await walkTree(root)).links) {
|
|
48
48
|
const path = portable(root, absolute);
|
|
49
49
|
const scope = artifactScope(path);
|
|
50
50
|
issue(scope === "archive" ? archiveDiagnostics : blockers, scope, {
|
|
@@ -88,7 +88,7 @@ export async function inventoryOpenSpec(input, options = {}) {
|
|
|
88
88
|
const capabilities = [];
|
|
89
89
|
const livingRequirements = new Map();
|
|
90
90
|
const livingCounts = { specFiles: 0, requirements: 0, scenarios: 0 };
|
|
91
|
-
const livingTree = await
|
|
91
|
+
const livingTree = (await walkTree(specsRoot)).files;
|
|
92
92
|
const livingFiles = livingTree.filter((path) => basename(path) === "spec.md");
|
|
93
93
|
// The living twin of openspec.nonstandard-change-spec. Selecting living specs
|
|
94
94
|
// by exact basename is right, but without the mirror a mis-cased or renamed
|
|
@@ -161,7 +161,7 @@ export async function inventoryOpenSpec(input, options = {}) {
|
|
|
161
161
|
scope: "workspace",
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
|
-
const artifactFiles = await
|
|
164
|
+
const artifactFiles = (await walkTree(root)).files;
|
|
165
165
|
if (storeMetadataExists && !storeMetadataSymlink && !artifactFiles.includes(storeMetadata)) {
|
|
166
166
|
artifactFiles.push(storeMetadata);
|
|
167
167
|
}
|
|
@@ -200,7 +200,6 @@ export async function inventoryOpenSpec(input, options = {}) {
|
|
|
200
200
|
const artifactDecisions = artifactDispositions(artifacts, mapping, new Set(active.map((change) => change.id)), mappingIssues);
|
|
201
201
|
return inventoryVerdict({
|
|
202
202
|
located,
|
|
203
|
-
mapping,
|
|
204
203
|
inventoryDigest,
|
|
205
204
|
config,
|
|
206
205
|
storeMetadataPath: storeMetadataExists ? sourceInventoryPath(root, storeMetadata) : null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inventory.js","sourceRoot":"","sources":["../../../src/core/openspec/inventory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAwB,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAoF,MAAM,kBAAkB,CAAC;AACpH,OAAO,EAAE,kBAAkB,EAAe,MAAM,qBAAqB,CAAC;AACtE,OAAO,EACL,eAAe,EACf,aAAa,EACb,cAAc,EACd,QAAQ,EACR,mBAAmB,EACnB,OAAO,EACP,SAAS,EACT,YAAY,GACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,M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EAAE,GAAG,mBAAmB,CAAC;QACxF,IAAI;QACJ,OAAO;QACP,sEAAsE;QACtE,KAAK,EAAE,OAAO,CAAC,OAAO,KAAK,SAAS;QACpC,eAAe;QACf,kBAAkB;QAClB,MAAM;QACN,OAAO;KACR,CAAC,CAAC;IACH,cAAc,CACZ,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,EAAE,OAAO,EAAE,EAC7G,OAAO,EACP,aAAa,CACd,CAAC;IACF,MAAM,iBAAiB,GAAG,oBAAoB,CAC5C,SAAS,EACT,OAAO,EACP,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,EAC1C,aAAa,CACd,CAAC;IAEF,OAAO,gBAAgB,CAAC;QACtB,OAAO;QACP,OAAO;QACP,eAAe;QACf,MAAM;QACN,iBAAiB,EAAE,mBAAmB,CAAC,CAAC,CAAC,mBAAmB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI;QACxF,YAAY;QACZ,YAAY;QACZ,MAAM;QACN,QAAQ;QACR,OAAO;QACP,QAAQ;QACR,kBAAkB;QAClB,SAAS;QACT,gBAAgB;QAChB,eAAe;QACf,aAAa;QACb,iBAAiB;KAClB,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * One whole OpenSpec workspace, read and graded in one pass.\n *\n * The order below is the contract: everything is SCANNED before anything is\n * DECIDED, because a decision graded against a half-read corpus is worse than\n * no decision — it reads as reviewed. So this module locates the root, walks\n * it, reads every document through `./scan/`, and only then hands the result to\n * `./decide/`, which is the half a human's mapping can change.\n *\n * The digest is taken over the non-archive artifacts only. It binds a mapping\n * to the truth it was reviewed against, and frozen archive history is neither\n * migrated nor allowed to block readiness — covering it meant a colleague's typo\n * fix under `changes/archive/` killed a completed mapping, with no `--force` and\n * no indication of which file had moved.\n */\nimport { isUtf8 } from \"node:buffer\";\nimport { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { basename, dirname, join } from \"node:path\";\nimport { compareIds } from \"../repo/entries.js\";\nimport { parseRequirements } from \"../document/parse.js\";\nimport { emptyMapping, type OpenSpecMapping } from \"./model/mapping.js\";\nimport { type OpenSpecInventory, type OpenSpecRenamedUsage, type OpenSpecUnsupportedShape } from \"./model/model.js\";\nimport { locateOpenSpecRoot, type Ingest } from \"./scan/workspace.js\";\nimport {\n digestInventory,\n hiddenSubdirs,\n isSymbolicLink,\n portable,\n sourceInventoryPath,\n subdirs,\n walkFiles,\n walkSymlinks,\n} from \"./scan/walk.js\";\nimport { inspectSpecFile, issue } from \"./scan/shape.js\";\nimport { inspectConfig } from \"./scan/config.js\";\nimport { artifactFor, artifactScope, inventoryChanges } from \"./scan/changes.js\";\nimport { capabilityDecisions } from \"./decide/capabilities.js\";\nimport { resolveRenames } from \"./decide/renames.js\";\nimport { artifactDispositions } from \"./decide/dispositions.js\";\nimport { inventoryVerdict } from \"./decide/verdict.js\";\nimport { isDirectory } from \"./scan/walk.js\";\nimport { addCounts } from \"./scan/shape.js\";\nimport { type OpenSpecCapability, type OpenSpecCounts } from \"./model/model.js\";\n\nexport async function inventoryOpenSpec(\n input: string,\n options: { mapping?: OpenSpecMapping } = {},\n): Promise<OpenSpecInventory> {\n const located = await locateOpenSpecRoot(input);\n const { inputRoot, root } = located;\n const mapping = emptyMapping(options.mapping);\n const renamed: OpenSpecRenamedUsage[] = [];\n const blockers: OpenSpecUnsupportedShape[] = [];\n // The read in progress. Every reader below appends to these two lists rather\n // than returning findings, because the ORDER they land in is what the `--json`\n // contract pins — five arrays merged afterwards would be a different report.\n const ingest: Ingest = { root, mapping, renamed, unsupported: blockers };\n const archiveDiagnostics: OpenSpecUnsupportedShape[] = [];\n for (const absolute of await walkSymlinks(root)) {\n const path = portable(root, absolute);\n const scope = artifactScope(path);\n issue(scope === \"archive\" ? archiveDiagnostics : blockers, scope, {\n code: \"openspec.symlink-unsupported\",\n path: path,\n message: \"Symbolic links are not followed by migration inventory; replace this link with an in-tree regular file or directory.\",\n });\n }\n const config = await inspectConfig(root, blockers);\n const specsRoot = join(root, \"specs\");\n const changesRoot = join(root, \"changes\");\n const inputStoreMetadata = join(inputRoot, \".openspec-store\", \"store.yaml\");\n const parentStoreMetadata = basename(root) === \"openspec\"\n ? join(dirname(root), \".openspec-store\", \"store.yaml\")\n : inputStoreMetadata;\n const storeMetadata = existsSync(inputStoreMetadata) ? inputStoreMetadata : parentStoreMetadata;\n const storeMetadataExists = existsSync(storeMetadata);\n const storeMetadataSymlink = storeMetadataExists && await isSymbolicLink(storeMetadata);\n if (storeMetadataSymlink) {\n issue(blockers, \"workspace\", {\n code: \"openspec.symlink-unsupported\",\n path: sourceInventoryPath(root, storeMetadata),\n message: \"Symbolic Store metadata is not followed; replace it with an in-tree regular file.\",\n });\n }\n const hasModernEmptyShape = config !== null || (storeMetadataExists && !storeMetadataSymlink);\n if (!await isDirectory(specsRoot) && !hasModernEmptyShape) {\n issue(blockers, \"living\", {\n code: \"openspec.specs-missing\",\n path: \"specs\",\n message: \"Living specs/ directory is missing.\",\n });\n }\n if (config !== null && config.store !== null && !await isDirectory(specsRoot) && !await isDirectory(changesRoot)) {\n issue(blockers, \"workspace\", {\n code: \"openspec.external-store-pointer\",\n path: \"config.yaml\",\n message: `Planning is externalized to Store '${config.store}'; audit that registered Store checkout directly.`,\n });\n }\n\n const capabilities: OpenSpecCapability[] = [];\n const livingRequirements = new Map<string, ReturnType<typeof parseRequirements>>();\n const livingCounts: OpenSpecCounts = { specFiles: 0, requirements: 0, scenarios: 0 };\n const livingTree = await walkFiles(specsRoot);\n const livingFiles = livingTree.filter((path) => basename(path) === \"spec.md\");\n // The living twin of openspec.nonstandard-change-spec. Selecting living specs\n // by exact basename is right, but without the mirror a mis-cased or renamed\n // file simply disappears: specs/payments/Spec.md audited as a clean, empty\n // corpus while the identical shape under a change was reported.\n for (const file of livingTree.filter((path) =>\n /\\.md$/i.test(path) && basename(path) !== \"spec.md\" && basename(path) !== \"design.md\")) {\n blockers.push({\n code: \"openspec.nonstandard-living-spec\",\n path: portable(root, file),\n message: \"Markdown under specs/ is named neither spec.md nor design.md, so no capability reads it.\",\n scope: \"living\",\n });\n }\n for (const specFile of livingFiles) {\n const id = portable(specsRoot, dirname(specFile));\n const inspected = await inspectSpecFile(ingest, specFile, \"living\", null);\n livingRequirements.set(id, inspected.requirements);\n const capability = { id, files: [inspected.path], ...inspected.counts };\n capabilities.push(capability);\n addCounts(livingCounts, inspected.counts);\n }\n capabilities.sort((a, b) => compareIds(a.id, b.id));\n\n const activeIds = (await subdirs(changesRoot)).filter((id) => id !== \"archive\");\n const archiveRoot = join(changesRoot, \"archive\");\n const archivedIds = await subdirs(archiveRoot);\n for (const id of await hiddenSubdirs(changesRoot)) {\n blockers.push({\n code: \"openspec.hidden-change-directory\",\n path: portable(root, join(changesRoot, id)),\n message: \"A dot-prefixed change directory is not enumerated as a change, so nothing under it is migrated; rename it or move it out of changes/.\",\n scope: \"active\",\n });\n }\n for (const id of await hiddenSubdirs(archiveRoot)) {\n archiveDiagnostics.push({\n code: \"openspec.hidden-change-directory\",\n path: portable(root, join(archiveRoot, id)),\n message: \"A dot-prefixed archive directory is not enumerated as a change; frozen history is retained read-only where it is.\",\n scope: \"archive\",\n });\n }\n const fallbackSchema = config?.schema ?? \"spec-driven\";\n const active = await inventoryChanges(ingest, {\n base: changesRoot,\n ids: activeIds,\n scope: \"active\",\n fallbackSchema,\n findings: blockers,\n });\n const archived = await inventoryChanges(ingest, {\n base: archiveRoot,\n ids: archivedIds,\n scope: \"archive\",\n fallbackSchema,\n findings: archiveDiagnostics,\n });\n\n // Last-resort backstop under the whole \"audited past the corpus\" family, and\n // the one check that does not depend on root selection being right: an\n // inventory that read no living spec AND no active change describes nothing,\n // so no verdict over it can be `ready`. That is exactly the shape the Store\n // misdetection produced — ready, mechanically compatible, zero capabilities,\n // zero unsupported shapes — where the failure verdict was more confident than\n // any success verdict. A greenfield workspace whose only requirements live\n // under changes/ has an active change and is not caught here.\n if (livingCounts.specFiles === 0 && active.length === 0) {\n blockers.push({\n code: \"openspec.workspace-empty\",\n path: \".\",\n message: `Planning root ${root} holds no living spec and no active change; there is nothing to migrate, so confirm this is the directory that really holds the corpus.`,\n scope: \"workspace\",\n });\n }\n\n const artifactFiles = await walkFiles(root);\n if (storeMetadataExists && !storeMetadataSymlink && !artifactFiles.includes(storeMetadata)) {\n artifactFiles.push(storeMetadata);\n }\n for (const absolute of artifactFiles) {\n const bytes = await readFile(absolute);\n if (isUtf8(bytes)) continue;\n const rootPath = portable(root, absolute);\n const artifactPath = sourceInventoryPath(root, absolute);\n const scope = absolute === storeMetadata ? \"workspace\" : artifactScope(rootPath);\n issue(scope === \"archive\" ? archiveDiagnostics : blockers, scope, {\n code: \"openspec.non-utf8-artifact\",\n path: artifactPath,\n message: \"Migration can preserve only valid UTF-8 authored artifacts; convert this file to UTF-8 before apply.\",\n });\n }\n // The digest binds a mapping to the truth it was reviewed against, and frozen\n // archive history is neither migrated nor allowed to block readiness. Covering\n // it meant a colleague's typo fix under changes/archive/ killed a completed\n // mapping, with no --force and no indication of which file moved.\n const inventoryDigest = await digestInventory(\n root,\n artifactFiles.filter((absolute) => artifactScope(portable(root, absolute)) !== \"archive\"),\n );\n const artifacts = artifactFiles\n .map((path) => artifactFor(root, path))\n .sort((a, b) => compareIds(a.path, b.path));\n\n const { mappingIssues, mappingDecisions, changeDecisions, routing } = capabilityDecisions({\n root,\n mapping,\n // An audit grades no source binding: there is no mapping to bind yet.\n bound: options.mapping !== undefined,\n inventoryDigest,\n livingRequirements,\n active,\n renamed,\n });\n resolveRenames(\n { root, mapping, bound: options.mapping !== undefined, inventoryDigest, livingRequirements, active, renamed },\n routing,\n mappingIssues,\n );\n const artifactDecisions = artifactDispositions(\n artifacts,\n mapping,\n new Set(active.map((change) => change.id)),\n mappingIssues,\n );\n\n return inventoryVerdict({\n located,\n mapping,\n inventoryDigest,\n config,\n storeMetadataPath: storeMetadataExists ? sourceInventoryPath(root, storeMetadata) : null,\n livingCounts,\n capabilities,\n active,\n archived,\n renamed,\n blockers,\n archiveDiagnostics,\n artifacts,\n mappingDecisions,\n changeDecisions,\n mappingIssues,\n artifactDecisions,\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"inventory.js","sourceRoot":"","sources":["../../../src/core/openspec/inventory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAwB,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAoF,MAAM,kBAAkB,CAAC;AACpH,OAAO,EAAE,kBAAkB,EAAe,MAAM,qBAAqB,CAAC;AACtE,OAAO,EACL,eAAe,EACf,aAAa,EACb,cAAc,EACd,QAAQ,EACR,mBAAmB,EACnB,OAAO,EACP,QAAQ,GACT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD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,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAE9C,MAAM,EAAE,aAAa,EAAE,gBAAgB,EAAE,eAAe,EAAE,OAAO,EAAE,GAAG,mBAAmB,CAAC;QACxF,IAAI;QACJ,OAAO;QACP,sEAAsE;QACtE,KAAK,EAAE,OAAO,CAAC,OAAO,KAAK,SAAS;QACpC,eAAe;QACf,kBAAkB;QAClB,MAAM;QACN,OAAO;KACR,CAAC,CAAC;IACH,cAAc,CACZ,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,EAAE,OAAO,EAAE,EAC7G,OAAO,EACP,aAAa,CACd,CAAC;IACF,MAAM,iBAAiB,GAAG,oBAAoB,CAC5C,SAAS,EACT,OAAO,EACP,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,EAC1C,aAAa,CACd,CAAC;IAEF,OAAO,gBAAgB,CAAC;QACtB,OAAO;QACP,eAAe;QACf,MAAM;QACN,iBAAiB,EAAE,mBAAmB,CAAC,CAAC,CAAC,mBAAmB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI;QACxF,YAAY;QACZ,YAAY;QACZ,MAAM;QACN,QAAQ;QACR,OAAO;QACP,QAAQ;QACR,kBAAkB;QAClB,SAAS;QACT,gBAAgB;QAChB,eAAe;QACf,aAAa;QACb,iBAAiB;KAClB,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * One whole OpenSpec workspace, read and graded in one pass.\n *\n * The order below is the contract: everything is SCANNED before anything is\n * DECIDED, because a decision graded against a half-read corpus is worse than\n * no decision — it reads as reviewed. So this module locates the root, walks\n * it, reads every document through `./scan/`, and only then hands the result to\n * `./decide/`, which is the half a human's mapping can change.\n *\n * The digest is taken over the non-archive artifacts only. It binds a mapping\n * to the truth it was reviewed against, and frozen archive history is neither\n * migrated nor allowed to block readiness — covering it meant a colleague's typo\n * fix under `changes/archive/` killed a completed mapping, with no `--force` and\n * no indication of which file had moved.\n */\nimport { isUtf8 } from \"node:buffer\";\nimport { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { basename, dirname, join } from \"node:path\";\nimport { compareIds } from \"../repo/entries.js\";\nimport { parseRequirements } from \"../document/parse.js\";\nimport { emptyMapping, type OpenSpecMapping } from \"./model/mapping.js\";\nimport { type OpenSpecInventory, type OpenSpecRenamedUsage, type OpenSpecUnsupportedShape } from \"./model/model.js\";\nimport { locateOpenSpecRoot, type Ingest } from \"./scan/workspace.js\";\nimport {\n digestInventory,\n hiddenSubdirs,\n isSymbolicLink,\n portable,\n sourceInventoryPath,\n subdirs,\n walkTree,\n} from \"./scan/walk.js\";\nimport { inspectSpecFile, issue } from \"./scan/shape.js\";\nimport { inspectConfig } from \"./scan/config.js\";\nimport { artifactFor, artifactScope, inventoryChanges } from \"./scan/changes.js\";\nimport { capabilityDecisions } from \"./decide/capabilities.js\";\nimport { resolveRenames } from \"./decide/renames.js\";\nimport { artifactDispositions } from \"./decide/dispositions.js\";\nimport { inventoryVerdict } from \"./decide/verdict.js\";\nimport { isDirectory } from \"./scan/walk.js\";\nimport { addCounts } from \"./scan/shape.js\";\nimport { type OpenSpecCapability, type OpenSpecCounts } from \"./model/model.js\";\n\nexport async function inventoryOpenSpec(\n input: string,\n options: { mapping?: OpenSpecMapping } = {},\n): Promise<OpenSpecInventory> {\n const located = await locateOpenSpecRoot(input);\n const { inputRoot, root } = located;\n const mapping = emptyMapping(options.mapping);\n const renamed: OpenSpecRenamedUsage[] = [];\n const blockers: OpenSpecUnsupportedShape[] = [];\n // The read in progress. Every reader below appends to these two lists rather\n // than returning findings, because the ORDER they land in is what the `--json`\n // contract pins — five arrays merged afterwards would be a different report.\n const ingest: Ingest = { root, mapping, renamed, unsupported: blockers };\n const archiveDiagnostics: OpenSpecUnsupportedShape[] = [];\n for (const absolute of (await walkTree(root)).links) {\n const path = portable(root, absolute);\n const scope = artifactScope(path);\n issue(scope === \"archive\" ? archiveDiagnostics : blockers, scope, {\n code: \"openspec.symlink-unsupported\",\n path: path,\n message: \"Symbolic links are not followed by migration inventory; replace this link with an in-tree regular file or directory.\",\n });\n }\n const config = await inspectConfig(root, blockers);\n const specsRoot = join(root, \"specs\");\n const changesRoot = join(root, \"changes\");\n const inputStoreMetadata = join(inputRoot, \".openspec-store\", \"store.yaml\");\n const parentStoreMetadata = basename(root) === \"openspec\"\n ? join(dirname(root), \".openspec-store\", \"store.yaml\")\n : inputStoreMetadata;\n const storeMetadata = existsSync(inputStoreMetadata) ? inputStoreMetadata : parentStoreMetadata;\n const storeMetadataExists = existsSync(storeMetadata);\n const storeMetadataSymlink = storeMetadataExists && await isSymbolicLink(storeMetadata);\n if (storeMetadataSymlink) {\n issue(blockers, \"workspace\", {\n code: \"openspec.symlink-unsupported\",\n path: sourceInventoryPath(root, storeMetadata),\n message: \"Symbolic Store metadata is not followed; replace it with an in-tree regular file.\",\n });\n }\n const hasModernEmptyShape = config !== null || (storeMetadataExists && !storeMetadataSymlink);\n if (!await isDirectory(specsRoot) && !hasModernEmptyShape) {\n issue(blockers, \"living\", {\n code: \"openspec.specs-missing\",\n path: \"specs\",\n message: \"Living specs/ directory is missing.\",\n });\n }\n if (config !== null && config.store !== null && !await isDirectory(specsRoot) && !await isDirectory(changesRoot)) {\n issue(blockers, \"workspace\", {\n code: \"openspec.external-store-pointer\",\n path: \"config.yaml\",\n message: `Planning is externalized to Store '${config.store}'; audit that registered Store checkout directly.`,\n });\n }\n\n const capabilities: OpenSpecCapability[] = [];\n const livingRequirements = new Map<string, ReturnType<typeof parseRequirements>>();\n const livingCounts: OpenSpecCounts = { specFiles: 0, requirements: 0, scenarios: 0 };\n const livingTree = (await walkTree(specsRoot)).files;\n const livingFiles = livingTree.filter((path) => basename(path) === \"spec.md\");\n // The living twin of openspec.nonstandard-change-spec. Selecting living specs\n // by exact basename is right, but without the mirror a mis-cased or renamed\n // file simply disappears: specs/payments/Spec.md audited as a clean, empty\n // corpus while the identical shape under a change was reported.\n for (const file of livingTree.filter((path) =>\n /\\.md$/i.test(path) && basename(path) !== \"spec.md\" && basename(path) !== \"design.md\")) {\n blockers.push({\n code: \"openspec.nonstandard-living-spec\",\n path: portable(root, file),\n message: \"Markdown under specs/ is named neither spec.md nor design.md, so no capability reads it.\",\n scope: \"living\",\n });\n }\n for (const specFile of livingFiles) {\n const id = portable(specsRoot, dirname(specFile));\n const inspected = await inspectSpecFile(ingest, specFile, \"living\", null);\n livingRequirements.set(id, inspected.requirements);\n const capability = { id, files: [inspected.path], ...inspected.counts };\n capabilities.push(capability);\n addCounts(livingCounts, inspected.counts);\n }\n capabilities.sort((a, b) => compareIds(a.id, b.id));\n\n const activeIds = (await subdirs(changesRoot)).filter((id) => id !== \"archive\");\n const archiveRoot = join(changesRoot, \"archive\");\n const archivedIds = await subdirs(archiveRoot);\n for (const id of await hiddenSubdirs(changesRoot)) {\n blockers.push({\n code: \"openspec.hidden-change-directory\",\n path: portable(root, join(changesRoot, id)),\n message: \"A dot-prefixed change directory is not enumerated as a change, so nothing under it is migrated; rename it or move it out of changes/.\",\n scope: \"active\",\n });\n }\n for (const id of await hiddenSubdirs(archiveRoot)) {\n archiveDiagnostics.push({\n code: \"openspec.hidden-change-directory\",\n path: portable(root, join(archiveRoot, id)),\n message: \"A dot-prefixed archive directory is not enumerated as a change; frozen history is retained read-only where it is.\",\n scope: \"archive\",\n });\n }\n const fallbackSchema = config?.schema ?? \"spec-driven\";\n const active = await inventoryChanges(ingest, {\n base: changesRoot,\n ids: activeIds,\n scope: \"active\",\n fallbackSchema,\n findings: blockers,\n });\n const archived = await inventoryChanges(ingest, {\n base: archiveRoot,\n ids: archivedIds,\n scope: \"archive\",\n fallbackSchema,\n findings: archiveDiagnostics,\n });\n\n // Last-resort backstop under the whole \"audited past the corpus\" family, and\n // the one check that does not depend on root selection being right: an\n // inventory that read no living spec AND no active change describes nothing,\n // so no verdict over it can be `ready`. That is exactly the shape the Store\n // misdetection produced — ready, mechanically compatible, zero capabilities,\n // zero unsupported shapes — where the failure verdict was more confident than\n // any success verdict. A greenfield workspace whose only requirements live\n // under changes/ has an active change and is not caught here.\n if (livingCounts.specFiles === 0 && active.length === 0) {\n blockers.push({\n code: \"openspec.workspace-empty\",\n path: \".\",\n message: `Planning root ${root} holds no living spec and no active change; there is nothing to migrate, so confirm this is the directory that really holds the corpus.`,\n scope: \"workspace\",\n });\n }\n\n const artifactFiles = (await walkTree(root)).files;\n if (storeMetadataExists && !storeMetadataSymlink && !artifactFiles.includes(storeMetadata)) {\n artifactFiles.push(storeMetadata);\n }\n for (const absolute of artifactFiles) {\n const bytes = await readFile(absolute);\n if (isUtf8(bytes)) continue;\n const rootPath = portable(root, absolute);\n const artifactPath = sourceInventoryPath(root, absolute);\n const scope = absolute === storeMetadata ? \"workspace\" : artifactScope(rootPath);\n issue(scope === \"archive\" ? archiveDiagnostics : blockers, scope, {\n code: \"openspec.non-utf8-artifact\",\n path: artifactPath,\n message: \"Migration can preserve only valid UTF-8 authored artifacts; convert this file to UTF-8 before apply.\",\n });\n }\n // The digest binds a mapping to the truth it was reviewed against, and frozen\n // archive history is neither migrated nor allowed to block readiness. Covering\n // it meant a colleague's typo fix under changes/archive/ killed a completed\n // mapping, with no --force and no indication of which file moved.\n const inventoryDigest = await digestInventory(\n root,\n artifactFiles.filter((absolute) => artifactScope(portable(root, absolute)) !== \"archive\"),\n );\n const artifacts = artifactFiles\n .map((path) => artifactFor(root, path))\n .sort((a, b) => compareIds(a.path, b.path));\n\n const { mappingIssues, mappingDecisions, changeDecisions, routing } = capabilityDecisions({\n root,\n mapping,\n // An audit grades no source binding: there is no mapping to bind yet.\n bound: options.mapping !== undefined,\n inventoryDigest,\n livingRequirements,\n active,\n renamed,\n });\n resolveRenames(\n { root, mapping, bound: options.mapping !== undefined, inventoryDigest, livingRequirements, active, renamed },\n routing,\n mappingIssues,\n );\n const artifactDecisions = artifactDispositions(\n artifacts,\n mapping,\n new Set(active.map((change) => change.id)),\n mappingIssues,\n );\n\n return inventoryVerdict({\n located,\n inventoryDigest,\n config,\n storeMetadataPath: storeMetadataExists ? sourceInventoryPath(root, storeMetadata) : null,\n livingCounts,\n capabilities,\n active,\n archived,\n renamed,\n blockers,\n archiveDiagnostics,\n artifacts,\n mappingDecisions,\n changeDecisions,\n mappingIssues,\n artifactDecisions,\n });\n}\n"]}
|