Implementation Plan: Compiler Chain (Unified Delivery Pipeline)

Implement the seven-stage compiler-style delivery pipeline defined in ADR-012:

1
Specs → Plan → SEA™ DSL → AST → IR → Manifest → Generated Code → Drift Check

This unified plan consolidates four previously separate plans (P001, P003, P013, P018) that all target the same pipeline stages. The consolidation eliminates overlap (e.g., both P003 and P018 touched ir_to_manifest.py and manifest.schema.json) and establishes a single source of truth for the compiler chain implementation.

Provenance & Traceability

Architectural Decisions (ADRs)

ADR ID Decision Title Impact on This Plan
ADR-012 Delivery Pipeline Primary driver. Defines all seven stages, mutation zones, and invariants.
ADR-003 Foundational Isomorphic Architecture Requires deterministic, schema-validated projections at each stage.
ADR-004 Semantic Core Formalization Defines semantic primitives (SEA™ DSL) that must compile cleanly.

Product Requirements (PRDs)

PRD ID Requirement Title Satisfied By (SDS) Acceptance Criteria
PRD-004 SEA™ Forge Delivery Pipeline SDS-021 Specs compile to manifests; determinism enforced; drift detected.

Software Design Specifications (SDS)

SDS ID Service/Component Bounded Context Implementation Status
SDS-021 Delivery Pipeline Service shared Target spec (exclusive)

Provenance Chain

graph TD
  ADR12[ADR-012: Delivery Pipeline] --> PRD4[PRD-004: Delivery Pipeline]
  ADR3[ADR-003: Isomorphism] --> PRD4
  ADR4[ADR-004: Semantic Core] --> PRD4
  PRD4 --> SDS21[SDS-021: Delivery Pipeline Service]

Consolidation Rationale

Retired Plan Original Scope Now Covered In
P001 AST validation, flow lint, AST→IR, IR→Manifest Waves 1–3
P003 IR→Manifest projection, manifest schema, codegen guardrails Waves 2–3
P013 Generation planning, deterministic regeneration, contract tests Waves 3–4
P018 Plan compiler, manifest compiler, drift check CI gates Waves 1–4

Architecture and Design

Design Principles Applied

Pipeline Stages (ADR-012 §Pipeline Stages)

Stage Name Input Output Tooling
1 Spec Authoring Human intent ADR/PRD/SDS N/A (human)
2 Plan Compilation Specs plan.yaml (future: SpecKit)
3 Semantic Compilation Specs + Plan SEA™ DSL → AST SEA™ parser
4 AST → IR AST IR tools/ast_to_ir.py
5 IR → Manifest IR manifest.json tools/ir_to_manifest.py
6 Code Generation Manifest **/src/gen/** tools/codegen/gen.py, Nx generators
7 Validation + Drift Generated code Pass/Fail tools/regen_check.py, CI gates

Dependency Justification

Expected Filetree

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/
├── docs/specs/**                              # Source-of-truth specs
├── tools/
│   ├── schemas/
│   │   ├── ast-v3.schema.json                 # AST contract
│   │   ├── sea_ir.schema.json                 # IR contract
│   │   └── manifest.schema.json               # Manifest contract
│   ├── flow_lint.py                           # AST annotation lint
│   ├── ast_to_ir.py                           # Stage 4: AST → IR
│   ├── ir_to_manifest.py                      # Stage 5: IR → Manifest
│   ├── codegen/
│   │   └── gen.py                             # Stage 6: Manifest → code
│   └── regen_check.py                         # Stage 7: Drift detection
├── generators/**                              # Nx generators (templates + schemas)
└── **/src/gen/**                              # Generated output only

Proposed Cycles

Cycle Branch Wave Files Modified Files Created Specs Implemented
C1A cycle/pcc-c1a-flow-contract 1 tools/flow_lint.py, tools/schemas/ast-v3.schema.json Flow annotation contract (CQRS, tx, outbox)
C1B cycle/pcc-c1b-ast-to-ir 1 tools/ast_to_ir.py, tools/schemas/sea_ir.schema.json AST → IR determinism + schema validation
C2A cycle/pcc-c2a-ir-to-manifest 2 tools/ir_to_manifest.py, tools/schemas/manifest.schema.json IR → Manifest projection
C2B cycle/pcc-c2b-manifest-spec-align 2 docs/specs/shared/reference/011-manifest-schema.md REF-011 alignment with schema
C3A cycle/pcc-c3a-codegen-guardrails 3 tools/codegen/gen.py Enforce src/gen/** output roots
C3B cycle/pcc-c3b-determinism 3 tools/regen_check.py Idempotent regen + drift detection
C4A cycle/pcc-c4a-ci-gates 4 .github/workflows/**, tools/nx/workspace/project.json CI pipeline integration
C4B cycle/pcc-c4b-contracts-tests 4 schemas/contracts/** Generated contracts and baseline tests

Task Breakdown

Wave 1: Semantic Foundation (Parallel)

Goal: Lock the semantic contract from SEA™ DSL through AST to IR.

Wave 2: Structural Projection (Parallel, depends on Wave 1)

Goal: Project IR into manifests with canonical schema.

Wave 3: Generation & Guardrails (Parallel, depends on Wave 2)

Goal: Deterministic code generation with strict output containment.

Wave 4: CI Integration & Contracts (Depends on Wave 3)

Goal: Full pipeline enforcement in CI; generated contracts and tests.


Validation & Verification

Spec Validation

Implementation Validation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Wave 1: Semantic foundation
python tools/flow_lint.py <ast.json> --strict
python tools/ast_to_ir.py <ast.json> /tmp/ir.json

# Wave 2: Structural projection
python tools/ir_to_manifest.py /tmp/ir.json /tmp/manifest.json

# Wave 3: Code generation
python tools/codegen/gen.py /tmp/manifest.json

# Wave 3: Drift check
python tools/regen_check.py

# Full pipeline (via just/Nx)
just pipeline <ctx>
nx run workspace:check

CI Integration Validation


Open Questions

Question Decision Rationale
Dotted annotation keys supported? Reject everywhere Nested JSON only; enforced in AST schema.
Manifest format (JSON vs YAML)? JSON (canonical) Simpler schema validation; YAML as optional view.
Minimal vs full manifest fields? Tiered schema Required fields for MVP; optional for governance/CALM refs.
Separate manifest diff tool? Use git diff for MVP First-class DX command deferred.

Risks & Mitigation

Risk Likelihood Impact Mitigation
Spec authors omit flow annotations High High Lint AST with actionable errors + GHA output.
Compiler accepts ambiguous semantics Medium High Fail fast: require CQRS kind + metadata per kind.
Generated code escapes src/gen/** Low High Schema + drift guard + codegen writer enforcement.
Schema/spec drift (REF-011 vs schema) Medium High Treat schema as canonical; CI check compares examples.
Overfitting manifest to one runtime Medium Medium Keep runtime section declarative; details at generator layer.

Rollback Strategy

  1. Lint too strict? Temporarily run --warn-only while updating specs; re-enable strict mode.
  2. Projection too strict? Allow missing optional fields while keeping outputRoots + CQRS required.
  3. CI gate failures? Temporary override record (per ADR-012 §Special-Case Manual Code) with expiry and backfill ref.

Deprecated Plans

The following plans are superseded by this consolidated plan and should be marked status: Superseded:

Plan File Action
P001 1_SemanticIntakeAndCompilation.plan.md Mark superseded; reference this plan
P003 3_ManifestProjectionRuntime.plan.md Mark superseded; reference this plan
P013 13_GenerativeSynthesis.plan.md Mark superseded; reference this plan
P018 18_DeliveryPipeline.plan.md Mark superseded; reference this plan

Reference Documents

Linked Specifications

Type ID Document
ADR ADR-012 Delivery Pipeline
ADR ADR-003 Foundational Isomorphic Architecture
ADR ADR-004 Semantic Core Formalization
PRD PRD-004 SEA™ Forge Delivery Pipeline
SDS SDS-021 Delivery Pipeline Service
REF REF-011 Manifest Schema