1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
//! The sealed, content-addressed release plan — the read-only pre-image the
//! human approves (ADR-0002 §3).
//!
//! `release plan` computes and seals a `plan_id`; `release cut --plan <plan_id>`
//! executes it and refuses on repo drift. The binary never prompts: it plans
//! and exits at the approval boundary.
//!
//! ## What `plan_id` hashes (the content address)
//!
//! [`build`] derives a [`ReleasePlan`] from the already-normalized contract and
//! detected repo facts, then content-addresses it. The `plan_id` is the
//! lowercase SHA-256 hex digest of a canonical JSON pre-image (`serde_json`,
//! whose struct-field and `BTreeMap` ordering is deterministic) covering
//! **exactly**, in this fixed order:
//!
//! 1. a domain separator + `SEAL_VERSION` — so a `plan_id` can never collide
//! with any other ossctl digest and the canonicalization format can be
//! evolved by a deliberate `SEAL_VERSION` bump instead of silently;
//! 2. the contract-document `schema_version` (ADR-0002 lists it explicitly);
//! 3. the **full normalized contract JSON** (`contract show`'s canonical output
//! — every defaulted field, so any config change is drift; hashing the whole
//! contract is deliberately *fail-closed*: a cosmetic change re-requires
//! approval rather than risk missing a substantive one);
//! 4. the git `HEAD` sha the plan was sealed against;
//! 5. the chosen release version (the human's bump — design §3.4);
//! 6. the **resolved concrete target set** — each target's ecosystem, resolved
//! package name, registry, and adapter *identity*. Resolution overlays
//! facts-derived package names onto the contract's (which may be `null`), so
//! a manifest rename is detectable drift even though the contract text is
//! unchanged;
//! 7. the phase sequence (constant per ADR-0002 §2 for a `--bump`-less plan, so it
//! never *causes* drift within a binary, but binding it authenticates the
//! execution shape the approver saw and makes a future phase-model change a
//! `SEAL_VERSION` event). A `--bump` plan prepends a `bump` phase, which this
//! field binds;
//! 8. the engine-owned **bump plan** (`release-rust-workspace-multicrate` facet 2/3),
//! or absent. `--bump <level>` computes a new version from the current manifest
//! version + the level and seals the deterministic edit set (computed version,
//! intra-workspace pin rewrites, CHANGELOG-finalize intent, any declared
//! `bump_hook`). Omitted from the pre-image when absent (`skip_serializing_if`),
//! so a `--bump`-less plan hashes byte-for-byte as it did before this field
//! existed — the additive superset that made a `SEAL_VERSION` bump unnecessary.
//!
//! ## Coordinator seam (what the sibling consumes)
//!
//! The coordinator refuses a `release cut --plan <id>` on drift by re-deriving
//! current state and calling [`verify`]. It needs to persist only two plain
//! fields from an approved plan — `plan_id` and `version` — into its journal;
//! the approved [`ReleasePlan`] is otherwise reconstructed via [`build`] from
//! the journalled sealed inputs. The plan DTOs are therefore `Serialize`-only,
//! matching the repo-wide convention that the wire enums (`Ecosystem`/`Registry`
//! /`Adapter`) do not derive `Deserialize` (they collect-all-errors on parse).
//! The trust boundary is the *local journal*: an approved plan is one ossctl
//! itself wrote, not untrusted caller input.
//!
//! ## Out of this worker's scope (handed to the coordinator)
//!
//! - **Working-tree cleanliness.** The seal binds `HEAD`, not uncommitted
//! changes. Enforcing a clean tree / executing from a clean checkout of the
//! sealed commit is an *execution* guard the coordinator owns (it needs a new
//! read-only `GitRepo` status port). Until then a dirty tree can publish code
//! that differs from the sealed commit — an accepted, documented gap.
//!
//! **Adapter tool *versions* (accepted gap).** ADR-0002 §3 names "resolved
//! adapter identities+versions". The adapter registry (a sibling unit) is not
//! landed, so no adapter *tool version* (e.g. a pinned `cargo-dist` release) is
//! resolvable yet; today the address binds adapter **identity** (the enum). When
//! the registry lands, fold the resolved versions into the pre-image — a
//! deliberate `schema_version`-bumping change to what the address covers, never
//! a silent one.
//!
//! Determinism: no wall-clock, no id-gen, no ordering-unstable map enters the
//! pre-image — identical `(contract, facts, head, version)` always yield the
//! same `plan_id` (proven in tests).
use BTreeSet;
use Serialize;
use crate;
use crateFacts;
use crate;
/// Build and seal a [`ReleasePlan`] from an already-normalized `contract` and
/// detected `facts`, at git `head_sha`, for the chosen `version`.
///
/// The caller (the `ossctl-cli` handler behind `release plan`, or the release
/// coordinator re-deriving current state) is responsible for having normalized
/// the contract and gathered the facts through the same code paths behind
/// `contract show` / `facts` — this function never re-parses `OSS-RELEASE.md`
/// nor re-derives facts. `version` is treated as an opaque, already-validated
/// identifier (scheme-specific validation — semver vs a calver pattern — is the
/// contract's/skill's job, not the plan's).
/// Build and seal a `--bump` [`ReleasePlan`]: an engine-owned version-bump plan
/// that computes a new version from the current manifest version + a semantic
/// `level` and owns the deterministic edit set (`release-rust-workspace-multicrate`
/// facet 2).
///
/// `from_version` is the current `[workspace.package] version` (the tree's single
/// source of truth); the engine **computes** the new version by applying `level` to
/// it ([`crate::release::bump::bump_version`]) — the caller supplies only the level,
/// never a literal target, so the plan can never seal a `to_version` that contradicts
/// its declared `level` (the invariant lives in the core constructor, not the CLI).
/// The returned plan carries a [`PlanPhase::Bump`] at the front of its phase sequence
/// and a [`BumpPlan`] describing the edits (pin rewrites, CHANGELOG finalize, any
/// declared `bump_hook`), all folded into the content address. Its
/// [`ReleasePlan::version`] is the computed new version — every publish/tag threads it.
///
/// A `--bump`-less plan is [`build`]; the two share every non-bump derivation, so
/// the bump path is a strict additive superset.
///
/// # Errors
/// [`BumpError`](crate::release::bump::BumpError) when `from_version` is not a strict
/// `MAJOR.MINOR.PATCH` release version — the engine will not seal a plan whose computed
/// version it cannot derive (fail closed).
/// The shared core of [`build`] / [`build_with_bump`]: resolve targets, assemble the
/// (bump-aware) phase sequence, seal, and construct the [`ReleasePlan`]. `bump` is
/// `None` for the default path (identical output and `plan_id` to before this field
/// existed) and `Some` for a `--bump` plan.
/// Compute the content-addressed `plan_id` of a **`--bump`-less** plan for
/// `(contract, facts, head_sha, version)` **without** allocating a full
/// [`ReleasePlan`].
///
/// The drift-check seam for the coordinator: given the plan a human approved, it
/// re-derives the *current* repo's contract + facts + `HEAD`, calls this with
/// the approved plan's sealed `version`, and compares. Prefer [`verify`], which
/// wraps this and reports *which* inputs drifted; this raw form is exposed for
/// callers that only need the digest.
///
/// **No-bump only.** This seals the invariant phase sequence with **no** bump plan,
/// so it computes the id of the *no-bump* plan for these inputs — it is **not** the id
/// of a `--bump` plan (that comes from [`build_with_bump`]). The bump-aware drift check
/// lives in the CLI (`cut` re-derives via [`build_with_bump`] and compares `plan_id`
/// directly); this helper is unchanged by the bump feature and stays no-bump.
/// Check whether an `approved` plan still matches the **current** repo state.
///
/// The coordinator calls this before crossing into any irreversible phase of
/// `release cut --plan <plan_id>`. It re-derives the current `plan_id` from the
/// current `contract`, `facts`, and `head_sha`, holding the *chosen version*
/// fixed to the approved plan's (a cut may not change the sealed version — that
/// would require a new plan). `Ok(())` means the approval is still valid; a
/// [`PlanDrift`] carries the mismatched id pair and human-readable reasons for
/// the `plan_stale` error envelope. The `plan_id` mismatch is authoritative;
/// the reasons are **best-effort and may be non-exhaustive** — the approved
/// plan intentionally does not retain the old normalized contract (trust the
/// journal, not a re-supplied contract), so an exact field-level contract diff
/// is not possible here. When more than one input drifts, the reasons name
/// every one they can pinpoint (`HEAD`, schema version, target set) and fall
/// back to a generic contract-changed note only when none of those explain it.
///
/// # Errors
/// Returns [`PlanDrift`] when the recomputed `plan_id` differs from
/// `approved.plan_id` — i.e. the repo moved (a commit, a manifest rename, a
/// schema bump, a target-set change, or any normalized-contract change) since
/// approval.
/// Why a `release cut --plan <plan_id>` was refused: the current repo no longer
/// hashes to the approved plan (ADR-0002 §3, `plan_stale`).
/// Whether a publish target derives its release version from a package manifest
/// the version guard can read, or has no manifest version by design — the capability
/// the fail-closed guard keys on (`version-source-fail-closed-nonrust`).
///
/// The distinction is a function of the target's **[`Ecosystem`]**, not its publish
/// registry. A Rust/Node/Python package carries its version in a manifest
/// (`Cargo.toml`/`package.json`/`pyproject.toml`) regardless of *where* it is
/// published — a Rust crate repackaged for a Homebrew tap still reads its version
/// from `Cargo.toml`, so it is [`Manifest`](VersionSource::Manifest). Keying on the
/// registry instead would wrongly treat that crate (and a binary-distribution-only
/// Rust repo) as versionless and refuse to derive a version that is plainly in the
/// tree.
/// One publishable target's resolved package paired with the version its **tree
/// manifest** declares — the version the ecosystem's publish command (`cargo
/// publish` reading `Cargo.toml`, …) would **actually** upload.
///
/// The workspace manifest is the single source of truth for the release version
/// ([`resolve_release_version`]); this is one row of that truth. A tree whose
/// manifests disagree among themselves carries a set of these
/// ([`VersionResolveError::InconsistentTree`]).
/// A manifest-versioned target ([`VersionSource::Manifest`]) whose resolved package
/// has **no** detected manifest version in `facts` — the fail-closed row for
/// `version-source-fail-closed-nonrust`.
///
/// Unlike a [`VersionSource::Distribution`] target (skipped by design), a manifest
/// target with no readable version means the detector failed on an ecosystem that
/// *is* manifest-versioned. The guard refuses rather than publish an unchecked
/// version.
/// Why a single release version could not be resolved from the workspace manifest —
/// the **single source of truth** for the release version. `ossctl release cut`
/// publishes the version already in the tree; there is no `--version` input to
/// override it (`release-drop-version-flag`).
/// Resolve the release version from the workspace manifest — the **single source of
/// truth**.
///
/// `ossctl release cut` does **not** bump the manifest: each ecosystem's publish
/// command uploads the version already in the tree (`cargo publish` reads
/// `Cargo.toml`), and the engine threads that version into every registry probe,
/// index-wait, and receipt. So the version a cut publishes is a **projection of the
/// tree**, not an independent input — there is no `--version` flag to override it
/// (`release-drop-version-flag`), which removes the two-masters footgun at the root
/// (a flag and the manifest could silently drift, the engine publishing the manifest
/// version while waiting for/recording the flag's, which never lands —
/// `release-cut-publish-noop`).
///
/// The manifest version is the distinct version shared by every **checkable** target
/// (a [`VersionSource::Manifest`] target with a detected manifest version in
/// `facts`). A [`VersionSource::Distribution`] target (a homebrew/binary/cargo-dist
/// target) has no manifest version by design — its release version is bound to the
/// crate it repackages — so it is skipped. A manifest-versioned target whose version
/// the detector could not read is **not** skipped: it fails the guard closed
/// (`version-source-fail-closed-nonrust`).
///
/// # Errors
/// - [`VersionResolveError::MissingManifestVersion`] — a manifest-versioned target
/// has a resolved package but no readable manifest version (fail closed).
/// - [`VersionResolveError::InconsistentTree`] — the checkable targets declare more
/// than one distinct version, so no single source of truth exists.
/// - [`VersionResolveError::Undeterminable`] — no manifest version anywhere to derive
/// from.
/// The version-source classification of a repo's resolved targets: the checkable
/// rows the release version is projected from, and the manifest-versioned targets
/// whose version could not be read (the fail-closed set).
/// Classify every resolved target by its [`VersionSource`], separating the checkable
/// manifest versions from the manifest-versioned targets whose version could not be
/// read.
///
/// - A [`VersionSource::Distribution`] target (a `binary`/`go` ecosystem) is skipped
/// regardless of version: it has no tree-manifest version by design.
/// - A [`VersionSource::Manifest`] target with a detected version becomes a `checkable`
/// row; one with a resolved package but **no** detected version becomes a `missing`
/// row (fail closed).
/// - A manifest target with **no resolved package** cannot be looked up here at all.
/// Package resolution is a separate concern guarded elsewhere — `release plan` warns
/// and `release cut` refuses via `coordinator::validate_plan` — so it is not
/// double-reported here as a version failure. (Deeper: hardening the resolver itself
/// to fail closed on an unresolved manifest target is tracked as a follow-up.)
/// Overlay facts-derived package names onto the contract's target set, yielding
/// the concrete targets a cut would execute, then **expand a multi-crate Rust
/// workspace** into its full dependency-ordered publish set.
///
/// Base resolution is 1:1 with the contract's (normalizer-canonical) `targets`,
/// resolving a `null` package from facts. Then [`expand_rust_workspace_members`]
/// derives the complete crates.io publish set for a Cargo workspace from
/// [`Facts::rust_workspace`]: a downstream repo that declares only its bin crate
/// still gets its lib crate planned, lib-before-bin, so a cut never `cargo publish`es
/// a crate whose `=`-pinned workspace sibling is not yet on the index
/// (`release-rust-workspace-multicrate`). A repo that already declares every member
/// (ossctl itself) is unchanged: the derived set equals what it declared.
/// The coordinator phase sequence for a plan, prepending [`PlanPhase::Bump`] when
/// the plan owns a version bump. A `--bump`-less plan yields exactly
/// [`PlanPhase::SEQUENCE`], so its sealed `phases` (and `plan_id`) are unchanged.
/// Assemble the [`BumpPlan`] — the deterministic edit set the bump phase applies —
/// from the contract + workspace facts and the caller-computed `from`/`to` versions.
/// Whether the bump phase finalizes the CHANGELOG (`[Unreleased]` → a dated
/// `[to_version]` section).
///
/// True for the human/fragment-authored modes (`curated`, `fragment`) whose
/// `[Unreleased]` section the engine promotes on release. False for `automated`,
/// where a release bot (release-please/changesets) owns the CHANGELOG and the engine
/// must not also rewrite it (a double-writer would clash). The concrete date is a
/// cut-time value and is deliberately not part of the plan (see [`BumpPlan::changelog_finalize`]).
///
/// An **exhaustive** match (not `!= Automated`) so a future `ChangelogMode` variant —
/// e.g. a "none"/"off" that means *no* changelog to finalize — must make a deliberate
/// choice here rather than silently defaulting to engine-finalized (which would seal a
/// bump plan that promotes a changelog that does not exist).
/// Derive the intra-workspace `=`-version pin rewrites the bump applies in lockstep
/// with the workspace version.
///
/// For each publishable workspace member and each of its intra-workspace dependency
/// edges (`M` depends on `D`, both members), the workspace's `=`-pinning convention
/// (the bin's `lib = "=<workspace version>"`, `release-rust-workspace-multicrate`)
/// means `M`'s manifest carries a `D = "=<from_version>"` pin that must become
/// `D = "=<to_version>"`. Emitted deterministically (sorted by dependent then
/// dependency), one per edge; empty for a single-crate workspace or a repo with no
/// detected workspace graph.
///
/// **Precise, not over-broad** (`release-rust-workspace-multicrate` facet 3, llm-review):
/// a rewrite is emitted **only** when the member's manifest declares that edge's
/// requirement literally as `=<from_version>` — the exact lockstep pin — read from
/// [`WorkspaceMember::dep_reqs`](crate::protocol::facts::WorkspaceMember). A
/// caret/range/`workspace = true`/independently-versioned edge (whose recorded
/// requirement is absent or is not `=<from_version>`) is **skipped**, so the bump never
/// clobbers a `^1.2` or a `workspace = true` sibling that does not track the workspace
/// version in lockstep. Skipping a genuinely-lockstepped edge whose requirement the
/// parser could not read (a dotted-key blind spot) fails the cut *closed* — the stale
/// `=<from>` pin the publish rejects — never a mis-rewrite. The executor re-verifies the
/// exact old value in the manifest before replacing (fail closed on zero/multiple).
/// Whether a resolved target is a Rust crate published to crates.io via
/// `cargo-publish` — the target class the workspace-member derivation expands (a
/// `cargo-dist` binary distribution or a non-crates.io registry is left untouched).
/// Expand the crates.io `cargo-publish` Rust targets of `base` into the
/// **dependency-ordered closure** of the declared crates (lib before bin), leaving
/// every other target in place.
///
/// The gap this closes (`release-rust-workspace-multicrate`): a two-crate workspace
/// (a lib + a bin pinning `lib = "=X"`) whose contract declares **only** the bin as a
/// target would plan a single `cargo publish <bin>` — which fails, because `lib@X` is
/// not yet on crates.io. From [`Facts::rust_workspace`] this derives the bin's
/// intra-workspace dependency closure and adds each dep as its own ordered target so
/// the coordinator publishes lib → bin (ADR-0004, one target = one publish unit; the
/// coordinator walks plan order and the adapter index-waits on each crate's own deps).
///
/// **Closure, not "every member".** The publish set is the declared Rust crates.io
/// targets plus their transitive intra-workspace dependencies — **never** an unrelated
/// publishable member the contract deliberately omitted (a not-yet-release-ready
/// crate). Publishing is irreversible, so "all publishable members" would be the wrong,
/// dangerous safety property. It is still a **strict superset of what the contract
/// declared**: every declared Rust crates.io package is a closure root (a package not
/// present as a workspace member is planned as-is, never dropped). For a repo that
/// already declares every member (ossctl itself) the closure equals the declared set,
/// so its plan is unchanged.
///
/// **Ambiguity is preserved, never expanded.** If any Rust crates.io target is
/// unresolved (`package: None` — a monorepo the facts could not disambiguate), `base`
/// is returned untouched so the downstream null-package guard/warning fires; an
/// unnamed target must never be silently turned into a workspace-wide publish.
///
/// The derived targets are spliced in at the position of the **first** Rust crates.io
/// target; the contract's other targets (cargo-dist, homebrew, a non-crates.io
/// registry) keep their relative order. Cross-ecosystem/registry order is immaterial
/// to correctness (publishes are independent per registry and the single tag is taken
/// after *all* publishes), so hoisting the crates.io block changes no behavior. When
/// there is no Rust crates.io target, or the repo is not a multi-crate workspace
/// ([`Facts::rust_workspace`] is `None`), `base` is returned unchanged — so a
/// single-crate repo and every non-Rust plan are untouched.
/// The dependency-ordered publish set for `roots`: the transitive intra-workspace
/// dependency closure of the declared crates, topologically ordered (a dependency
/// before its dependents).
///
/// The closure follows [`WorkspaceMember::workspace_deps`](crate::protocol::facts::WorkspaceMember)
/// edges from each root. A root that is **not** a workspace member (an explicitly
/// declared package the graph did not capture) contributes no edges but is still
/// included — the superset guarantee. Only members in the closure are ordered; an
/// unrelated publishable member the contract omitted never enters the set.
/// Topologically order a workspace's publishable members so a dependency precedes
/// its dependents (lib before bin) — the publish order the coordinator walks.
///
/// Kahn's algorithm with a **deterministic** tie-break: among members whose
/// intra-workspace dependencies are all already emitted, the one earliest in
/// declaration order is chosen next, so the output is stable and reproducible (a
/// requirement of the content-addressed plan). Only edges to *other listed members*
/// gate order (an edge to a filtered-out member cannot, and does not, block).
///
/// Emission is tracked **by index**, not by package name, so two members that happen
/// to share a name (Cargo forbids this, but the graph is parsed from raw manifests)
/// are both emitted rather than one masking the other. A dependency **cycle** (which
/// Cargo itself rejects among normal/build deps, so unreachable for a valid
/// workspace) cannot be ordered; the remaining members are appended in declaration
/// order rather than dropped or looped on — the plan stays a faithful superset and the
/// cut fails later with a concrete registry error, never a planner-omitted crate.
/// The detected package name for `ecosystem`, resolved **only when
/// unambiguous** — exactly one named manifest for that ecosystem.
///
/// `None` when no manifest named one (a virtual workspace, a binary-only repo)
/// **or** when several do (a monorepo with multiple crates of one ecosystem):
/// with no per-target manifest key in the contract, picking the first would
/// silently mis-assign the same package to every `null` target, so we leave it
/// `null` for cut-time inference instead. A monorepo should declare explicit
/// per-target `package`s in the contract; the CLI warns when this fires.
/// Domain separator baked into every pre-image so a `plan_id` can never be
/// confused with any other SHA-256 an ossctl subsystem might compute over
/// similar bytes. Ends in the seal-format version for readability; the numeric
/// [`SEAL_VERSION`] is also hashed as its own field.
const SEAL_DOMAIN: &str = "ossctl.release-plan";
/// Version of the *hashing pre-image format* — the field set, their order, and
/// the canonicalization. Independent of the contract-document or wire-envelope
/// versions. Bump this (never silently) whenever the pre-image shape changes
/// (e.g. once resolved adapter versions are folded in), so old and new plan ids
/// are intentionally disjoint rather than accidentally colliding.
const SEAL_VERSION: u32 = 5;
/// The canonical hashed pre-image (see the module docs for the exact contents).
/// A dedicated struct rather than an ad-hoc byte concatenation so the field set
/// is explicit and serde's deterministic struct-field ordering fixes the byte
/// layout.
///
/// **DO NOT REORDER these fields** — field order is part of the content address,
/// so a reorder silently changes every `plan_id`. Evolve the format via
/// [`SEAL_VERSION`] instead.
/// Serialize the pre-image to canonical JSON and return its SHA-256 hex digest.
/// Short (first 12 hex chars) `HEAD` sha for drift messages; whole string if
/// shorter.
/// A self-contained SHA-256 (FIPS 180-4) so `plan_id` needs no third-party hash
/// dependency and no edit to the workspace `Cargo.toml` (a hot file). Content
/// addressing is an integrity check over local, non-adversarial inputs, so a
/// vendored reference implementation is appropriate; correctness is pinned by
/// the RFC known-answer vectors in the module tests.