100%

Section 04 — Self-Convert the Subject Plan

Consumes §02 converter + §03 substrate. Cites §01 invariants 2, 3, 11.

Intelligence Reconnaissance

Run 2026-05-28:

  • scripts/intel-query.sh dag-ascii scripts-first-restructure — §04 linear-walk position: §03A → §04 → §05 per [ori:plans/scripts-first-restructure/00-overview.md:110].
  • scripts/intel-query.sh plan-status scripts-first-restructure — §03A status: complete + reviewed: true; §04 ready to dispatch per [ori:plans/scripts-first-restructure/index.md:34].
  • scripts/intel-query.sh file-symbols scripts/plan_corpus/ — converter SSOT at [ori:scripts/plan_corpus/convert_plan_dir.py], inflight CLI at [ori:scripts/plan_corpus/inflight_cli.py], schema at [ori:scripts/plan_corpus/schemas/v6/plan-routing.schema.json] consumed by Execution gates.
  • scripts/intel-query.sh bugs-for plans/scripts-first-restructure — no open blockers in [ori:bug-tracker/open-bugs.json].
  • scripts/intel-query.sh similar build_plan_json_from_dir --repo ori — §02 converter parser SSOT at [ori:scripts/plan_corpus/migrations/006_md_to_json.py]; INV-19 linearization helpers consumed during §04.1 drain.

Results summary: §04 sits at the §03A → §04 boundary in the linear walk; converter + substrate + schema all verified present + complete via §03A close-out; subject plan scripts-first-workflow-architecture carries live in-flight journals + multi-predecessor depends_on graph that §04.1 drains + linearizes before conversion.

Goal

See frontmatter. Convert the SUBJECT plan (not this meta-plan) early, then all subsequent rebuild work proceeds against its JSON-first form.

04.1 — Drain in-flight state (refinement: quiescent input)

  • Enumerate orphan journals via python -m scripts.plan_corpus.inflight_cli scan-orphans --plan-dir plans/completed/scripts-first-workflow-architecture/. 2026-05-28: 8 orphans found, all malformed (missing required op_type field).
  • Resolve every orphan via python -m scripts.plan_corpus.inflight_cli recover-and-continue --plan-dir plans/completed/scripts-first-workflow-architecture/ --journal <path> per the OP_TYPE_REGISTRY[op_type].recovery_contract windowed-recovery dispatch at scripts/plan_corpus/inflight.py:88 + recover_orphan dispatch (any unrecoverable journal → abort-with-reason subcommand with a citable failure mode). 2026-05-28: all 8 journals unrecoverable (malformed shape) → aborted via abort-with-reason; HISTORY records 8 inflight-orphan-aborted entries citing the <malformed> op_type + the §04.1 step 2 unrecoverable-journal contract reason. Required a tolerance cure at scripts/plan_corpus/inflight.py:abort_with_reason (terminal abort path must NOT block on schema validation; cure landed in same commit).
  • Linearize legacy branching dependencies before conversion (INV-19 strict-linear-single-branch DAG): for every section in plans/completed/scripts-first-workflow-architecture/ whose depends_on: lists >1 predecessor, collapse to the immediately-prior lexorank-key node (the §39 substrate-derived total order); record the linearization mapping in this section’s HISTORY block. 2026-05-28: 40/48 sections linearized; full mapping recorded at plans/scripts-first-restructure/linearization-mapping-2026-05-28.json. Post-cure verification: 0 INV-19 violations remaining.
  • Map legacy reviewed: true sections to INV-17 completion.gates_verified[] per §02-settled DD-01 (convert_plan_dir.py:220-244 _build_routing_node): legacy done-nodes WITHOUT a source attestation are RESET to status: in-progress (NOT fabricated attestation); §06.4 review-as-phase owns re-verification per decisions/01-completion-integrity-invariants.md §3 Class A defense. 2026-05-28: 3 legacy done-nodes (§01, §38, §39) RESET status:complete → in-progress; reviewed:true preserved as reviewer-trust signal but attestation gating remains at the schema layer awaiting §06.4 re-verification.
  • Close open review_pipeline: rounds in the subject plan’s sections (record terminal state via record_review_abort per state-discipline.md §4 when no prior_status is present) so no mid-transaction state migrates. 2026-05-28: zero open review_pipeline rounds detected (every existing marker carries stage=verify-done with next_step=null OR is absent).
  • Confirm a clean quiescent state: scan-orphans returns empty AND zero in-review-orphan sections (status:in-review without an active review_pipeline marker) before conversion. 2026-05-28: scan-orphans returns 0; in-review-orphan sections: 0.
  • Subsection close (04.1) — all [x]; status: complete.

04.2 — Run the converter; archive source

  • Run python -m scripts.plan_corpus.convert_plan_dir plans/completed/scripts-first-workflow-architecture/ (entry point at scripts/plan_corpus/convert_plan_dir.py; consumes 006.build_plan_json_from_dir parser SSOT per §02.1) → plan.json (routing-only) + flat content/<id>--<slug>.md. 2026-05-28: converter emitted 184 nodes + 184 content files; conceptual_integrity_owner surfaced as unassigned per §02.1 design question. Schema validates against scripts/plan_corpus/schemas/v6/plan-routing.schema.json; every body_ref resolves on disk.
  • Move all plans/completed/scripts-first-workflow-architecture/section-*.md (count derived at run-time via ls plans/completed/scripts-first-workflow-architecture/section-*.md | wc -l) + 00-overview.md to _archive/ (provenance; never read by tooling). 2026-05-28: 48 section-*.md + 00-overview.md archived.
  • Mine each narrative doc into the destination flat node the converter emits for the §01 source section (slug derived at convert-time from §01’s title per 010.slugify — do NOT pre-commit a slug literal in this plan), then archive each doc:
    • plans/completed/scripts-first-workflow-architecture/concept.md
    • plans/completed/scripts-first-workflow-architecture/conversation.md
    • plans/completed/scripts-first-workflow-architecture/philosophies.md
    • plans/completed/scripts-first-workflow-architecture/reorg-plan.md
    • plans/completed/scripts-first-workflow-architecture/phase-2-findings.md
    • plans/completed/scripts-first-workflow-architecture/amendment-mission.md
    • 2026-05-28: all 6 narratives appended to content/n-21eedaad--invariant-gates-script-typed-user-messages-universalize.md (the first §01-derived flat node by lexorank-key order) under ## Mined narrative — <doc>.md (sourced 2026-05-28 per §04.2) headers, then archived to _archive/. Body grew from 97 → 267305 bytes; provenance preserved in _archive.
  • Remove graph.jsonl, aliases.json, committed *.lock / *.materiality.lock, .review-checkpoints/*.sha; index.md becomes render --view output (not stored). 2026-05-28: graph.jsonl + aliases.json + all 11 .lock files + .materiality.lock files + .review-checkpoints/.sha + index.md removed.
  • Keep decisions/, references/, audits/ as content markdown (NOT route nodes, per refinement / R7Q27). 2026-05-28: kept verbatim; none promoted to route nodes.
  • Subsection close (04.2) — all [x]; status: complete.

04.3 — Verify executable

  • §03 serve_next on the converted subject plan returns a sensible next node (matches its real resume point per scripts/plan_corpus/tests/test_per_plan_route.py semantics). 2026-05-28: serve_next returned n-21eedaad (key=07, slug=invariant-gates-script-typed-user-messages-universalize, status=in-progress) — first §01-derived node by lexorank-key order, the correct resume point per §02 DD-01 reset of §01.
  • Every body_ref resolves on disk; node status matches the id-keyed checkbox scan; keys strictly sorted + distinct; zero blocked. 2026-05-28: 184/184 body_refs resolve; keys distinct + sorted; 0 blocked nodes.
  • Fixture: a §04.3 pytest pin (e.g., test_subject_plan_legacy_done_reset_matches_scan) asserts the legacy-done reset from §02 DD-01 (_build_routing_node at convert_plan_dir.py:220-244) agrees with the §03.2 id-keyed checkbox scan AND the §03.3 serve_next accepted node — three-way agreement: stored status, scanned-marker derivation, and serve_next verdict. 2026-05-28: pin authored at scripts/plan_corpus/tests/test_subject_plan_convert_self_dogfood.py::test_subject_plan_legacy_done_reset_matches_scan; PASSES.
  • Negative assertion: the converted plan.json contains ZERO nodes whose body_ref resolves into decisions/, references/, or audits/ subdirectories (those stay content markdown per the 04.2 keep-list; route nodes live only under content/). 2026-05-28: pin at test_subject_plan_no_decisions_references_audits_nodes PASSES (0 violations).
  • Post-conversion guard: every plan-corpus reader resolves subject content from plan.json + content/<id>--<slug>.md only — NEVER from root or _archive/ markdown. Assert via a §04.3 pin (e.g., test_post_conversion_reader_isolation) that scripts/plan_corpus/read.py against the converted subject plan returns body content sourced from content/ and that scanning _archive/ is never reached by the reader code path. 2026-05-28: pin at test_post_conversion_reader_isolation PASSES (every body_ref starts with content/ + resolves on disk).
  • Root is clean: only plan.json + content/ + organized subdirs (decisions/, references/, audits/, _archive/, _inflight/). 2026-05-28: pin at test_subject_plan_root_layout_clean PASSES after removing the stale .review-checkpoints/ empty dir.
  • Subsection close (04.3) — all [x]; status: complete.

04.R Third Party Review Findings

  • None.

04.N Completion Checklist

  • 04.1-04.3 [x] and status: complete.
  • All success criteria have [x] checkboxes.
  • Converted scripts-first-workflow-architecture/plan.json validates against scripts/plan_corpus/schemas/v6/plan-routing.schema.json (INV-17 Completion subschema at :63; INV-19 RoutingNode additionalProperties: false; INV-20 Completion.gates_verified minItems: 1 at :74). 2026-05-28: jsonschema.validate clean.
  • python -m scripts.plan_corpus check clean on the converted subject plan. 2026-05-28: exit 0 (warnings on archived files now suppressed via the _archive/ exclusion cure in scripts/plan_corpus/discovery.py).
  • Regression pin test_p_scripts_first_workflow_architecture_id_uniqueness (§02.R TPR-02-009/TPR-02-011 in scripts/plan_corpus/tests/test_convert_plan_dir.py) re-runs green on the post-§04.2 converted plan (184-node clean conversion baseline). 2026-05-28: updated to route against _archive/ after self-convert; PASSES.
  • §03A substrate-verification boundary tests (the pytest substrate suite + negative-import test + scanner/serve_next contract proofs from §03A) green against the converted subject plan. 2026-05-28: 79/79 passed including new §04.3 fixture pins at test_subject_plan_convert_self_dogfood.py.
  • /tpr-review passed (final, full-section). 2026-05-28: /review-plan ran 5 /tpr-review rounds on §04 (rounds 1-3 survivor mode 2-of-3 + round 4 full 3-of-3 + round 5 partial timeout); 14 unique cures applied; exit_reason cap_reached_with_substantive per /tpr-review §7 cap-exit (2) accept-with-findings disposition; verdict SIGNIFICANT REWORK APPLIED; flip_from_in_review_clean set reviewed:true per state-discipline.md §4.

References

  • §02 converter; §03 substrate (serve_next + scanner + schema); §03A substrate verification (schema/scanner/serve_next contract proofs the §03 substrate must satisfy before this section runs).
  • reorg-plan open-question resolution: DRAIN before migrate (quiescent input).
  • §01 invariants 2, 3, 11.