ship: phase-03 l2-modules-and-core-scripts #3

Merged
grimacing merged 17 commits from phase/03-l2-modules-and-core-scripts into milestone/v1.0-initial 2026-07-21 13:32:21 +00:00
Owner

Phase 03 ship

Creates the 4 L2 composition modules and the 5 core scripts.

L2 modules (each composes 5 L1s): l2-invoice-service, l2-commodity-price-feed, l2-energy-analytics-api, l2-regulatory-reporting

Core scripts:

  • scripts/policy_checker.py — POLICY_PASS / POLICY_VIOLATION:PUBLIC_INGRESS (REQ-07)
  • scripts/confidence_signal.py — {score: 0.90|0.40, reason} JSON (REQ-08)
  • scripts/evidence_writer.py — canonical-JSON SHA-256 hash chain (REQ-11, D-005/D-023)
  • scripts/mock_executor.sh — invokes L1s, writes state.json (REQ-06)
  • scripts/l3b_agent_stub.py — D-008 keyword map → contract.yaml (D-026)
  • scripts/verify_phase03.sh — 18/18 checks pass

Requirements covered: REQ-04, REQ-05, REQ-06, REQ-07, REQ-08, REQ-11
Requirements partial: REQ-12 (l3b_agent_stub created; full issue-trigger wiring in Phase 04)
Verification: 4 layers passed, 0 P1 findings.

Version target: v1.0.3 (feature milestone, phase 3 patch)

## Phase 03 ship Creates the 4 L2 composition modules and the 5 core scripts. **L2 modules** (each composes 5 L1s): `l2-invoice-service`, `l2-commodity-price-feed`, `l2-energy-analytics-api`, `l2-regulatory-reporting` **Core scripts:** - `scripts/policy_checker.py` — POLICY_PASS / POLICY_VIOLATION:PUBLIC_INGRESS (REQ-07) - `scripts/confidence_signal.py` — {score: 0.90|0.40, reason} JSON (REQ-08) - `scripts/evidence_writer.py` — canonical-JSON SHA-256 hash chain (REQ-11, D-005/D-023) - `scripts/mock_executor.sh` — invokes L1s, writes state.json (REQ-06) - `scripts/l3b_agent_stub.py` — D-008 keyword map → contract.yaml (D-026) - `scripts/verify_phase03.sh` — 18/18 checks pass **Requirements covered:** REQ-04, REQ-05, REQ-06, REQ-07, REQ-08, REQ-11 **Requirements partial:** REQ-12 (l3b_agent_stub created; full issue-trigger wiring in Phase 04) **Verification:** 4 layers passed, 0 P1 findings. **Version target:** v1.0.3 (feature milestone, phase 3 patch)
grimacing added 17 commits 2026-07-21 13:32:20 +00:00
---ci---
phase: 3
milestone: v1.0
status: clarify
decisions:
  - id: D-020
    decision: L2 manifest.yaml schema with l1s: list of {name, inputs: map}
    rationale: REQ-04 says L2 composes L1s; REQ-05 caps depth at 5 (L2->L1 is depth 1)
    confidence: 0.90
    alternatives: [graph-of-L1s with edges, single flat list of L1 names with no inputs]
  - id: D-021
    decision: contract.yaml schema with stack, inputs, optional public-ingress: bool
    rationale: REQ-07 cites public-ingress:true as the forbidden key; REQ-08 keys off policy pass/fail
    confidence: 0.90
    alternatives: [separate policy file, contract-free intent]
  - id: D-022
    decision: mock_executor.sh writes state.json with l2, l1s array (name+applied+exit_code), contract
    rationale: REQ-06 says writes state.json but does not specify shape
    confidence: 0.85
    alternatives: [per-L1 state files, no state file]
  - id: D-023
    decision: evidence_writer.py appends to audit.json (JSON array); each event has seq, ts, stage, event, prev_hash, hash (SHA-256 of canonical JSON); genesis has prev_hash=GENESIS, seq=0
    rationale: D-005 mandates hash-chained ledger; canonical JSON for deterministic hashing
    confidence: 0.90
    alternatives: [signed commits only, append-only log file]
  - id: D-024
    decision: confidence_signal.py prints {score, reason} JSON to stdout; exit 0 always
    rationale: REQ-08 literal: base 0.90, drops to 0.40, gate >= 0.50
    confidence: 0.95
    alternatives: [exit non-zero on fail, separate side-channel file]
  - id: D-025
    decision: policy_checker.py exits 1 with stdout POLICY_VIOLATION:PUBLIC_INGRESS on public-ingress:true; else exit 0 with stdout POLICY_PASS
    rationale: REQ-07 literal
    confidence: 0.99
    alternatives: []
  - id: D-026
    decision: l3b_agent_stub.py reads issue body from argv[1] or stdin, applies D-008 keyword map, writes contract.yaml to stdout (or -o <path>)
    rationale: D-008 + Act 3 example; L3B must produce same contract format as L3A
    confidence: 0.90
    alternatives: [fixed-output contract per stack, no -o flag]
---/ci---

Phase 03 has real ambiguities (no schema was specified for L2 manifests,
contract.yaml, audit.json events, or the L3B output format). Seven
decisions logged: D-020 L2 schema, D-021 contract.yaml schema, D-022
state.json shape, D-023 audit.json event + hash chain, D-024
confidence_signal output, D-025 policy_checker output, D-026 l3b_agent
I/O contract.
---ci---
phase: 3
milestone: v1.0
status: research
research:
  l2_schema: l1s list of {name, inputs: map}; 4 L2s each referencing 5 L1s
  contract_schema: stack + inputs + optional public-ingress: bool
  state_json_shape: l2, l1s array (name+applied+exit_code), contract
  audit_json: JSON array; canonical-JSON SHA-256 hash chain; GENESIS prev_hash
  core_script_io: 5 scripts with explicit input/output/exit contracts
  personas: no change; backend-engineer owns core scripts + L2 manifests; infra-stub-engineer owns L1 manifests only
---/ci---

ARCHITECTURE.md gains the L2 manifest schema, the L2 list with per-L2
L1 references (5 each, within max-depth-5), the contract.yaml schema,
the state.json shape, the audit.json event + canonical-JSON hash chain,
and a core-script I/O contract table. PERSONAS.md is unchanged for
Phase 03 (backend-engineer and infra-stub-engineer were both already
active in the project-level roster).
---ci---
phase: 3
milestone: v1.0
status: plan
plan:
  waves: 3
  wave_1_infra_stub: [T-3.1..T-3.4 create 4 L2 manifests]
  wave_2_backend: [T-3.5 policy_checker, T-3.6 confidence_signal, T-3.7 evidence_writer, T-3.8 mock_executor, T-3.9 l3b_agent_stub]
  wave_3_coordination: [T-3.10 verify_phase03, T-3.11 traceability]
  requirements_covered: [REQ-04, REQ-05, REQ-06, REQ-07, REQ-08, REQ-11]
  must_haves: 9
  verification:
    typecheck: bash -n + python -m py_compile + yaml load
    test: scripts/verify_phase03.sh
    build: no-op
---/ci---

PLAN.md replaced with Phase 03 plan. Wave 1 (infra-stub-engineer) creates
the 4 L2 manifests. Wave 2 (backend-engineer) creates the 5 core scripts.
Wave 3 (lead-developer) wires the verify script + traceability.
---ci---
phase: 3
milestone: v1.0
status: execute
persona: infra-stub-engineer
task: T-3.1
requirements:
  covered: [REQ-04, REQ-05]
---/ci---

Wave 1, task T-3.1. Creates modules/l2/l2-invoice-service/manifest.yaml composing
5 L1s by name (D-020). All referenced L1 names exist in modules/l1/.
---ci---
phase: 3
milestone: v1.0
status: execute
persona: infra-stub-engineer
task: T-3.2
requirements:
  covered: [REQ-04, REQ-05]
---/ci---

Wave 1, task T-3.2. Creates modules/l2/l2-commodity-price-feed/manifest.yaml composing
5 L1s by name (D-020). All referenced L1 names exist in modules/l1/.
---ci---
phase: 3
milestone: v1.0
status: execute
persona: infra-stub-engineer
task: T-3.3
requirements:
  covered: [REQ-04, REQ-05]
---/ci---

Wave 1, task T-3.3. Creates modules/l2/l2-energy-analytics-api/manifest.yaml composing
5 L1s by name (D-020). All referenced L1 names exist in modules/l1/.
---ci---
phase: 3
milestone: v1.0
status: execute
persona: infra-stub-engineer
task: T-3.4
requirements:
  covered: [REQ-04, REQ-05]
---/ci---

Wave 1, task T-3.4. Creates modules/l2/l2-regulatory-reporting/manifest.yaml composing
5 L1s by name (D-020). All referenced L1 names exist in modules/l1/.
---ci---
phase: 3
milestone: v1.0
status: execute
persona: backend-engineer
task: T-3.5
requirements:
  covered: [REQ-07]
---/ci---

Wave 2, task T-3.5. Policy enforcement script: rejects contracts with public-ingress: true.
---ci---
phase: 3
milestone: v1.0
status: execute
persona: backend-engineer
task: T-3.6
requirements:
  covered: [REQ-08]
---/ci---

Wave 2, task T-3.6. Confidence signal: 0.90 on policy pass, 0.40 on violation; exit 0 always (D-024).
---ci---
phase: 3
milestone: v1.0
status: execute
persona: backend-engineer
task: T-3.7
requirements:
  covered: [REQ-11]
---/ci---

Wave 2, task T-3.7. Hash-chained audit event writer (D-023/D-005) with auto-genesis and atomic writes.
---ci---
phase: 3
milestone: v1.0
status: execute
persona: backend-engineer
task: T-3.8
requirements:
  covered: [REQ-06]
---/ci---

Wave 2, task T-3.8. Mock L2 composition executor: resolves manifest, invokes each L1 mock_apply.sh, writes state.json (D-022).
---ci---
phase: 3
milestone: v1.0
status: execute
persona: backend-engineer
task: T-3.9
requirements:
  covered: [REQ-12]
---/ci---

Wave 2, task T-3.9. L3B keyword parser: maps issue body text to L2 stack (D-008) and emits contract.yaml (D-021).
---ci---
phase: 3
milestone: v1.0
status: execute
persona: backend-engineer
task: T-3.6
requirements:
  covered: [REQ-08]
---/ci---

Wave 2, task T-3.6. json.dumps collapsed 0.90 -> 0.9; emit literal two-decimal score per contract while remaining valid JSON.
---ci---
phase: 3
milestone: v1.0
status: execute
persona: backend-engineer
task: T-3.9
requirements:
  covered: [REQ-12]
---/ci---

Wave 2, task T-3.9. parse_output_flag strips -o; read_issue_body now reads body from rest[0] (after -o removed) instead of sys.argv[1].
---ci---
phase: 3
milestone: v1.0
status: execute
persona: lead-developer
task: T-3.10
requirements:
  covered: [REQ-04, REQ-05, REQ-06, REQ-07, REQ-08, REQ-11]
---/ci---

Wave 3, task T-3.10. scripts/verify_phase03.sh checks: (1) 4 L2 folders
with exact names; (2) each L2 manifest.yaml structure + 5 existing L1
references + inputs maps; (3) typecheck (bash -n + py_compile + yaml load);
(4) policy_checker D-025 (pass/fail); (5) confidence_signal D-024
(score 0.90/0.40, exit 0 always); (6) evidence_writer D-023 hash chain
(genesis + 3 events, prev_hash links, SHA-256 recompute); (7) mock_executor
D-022 state.json (l2 + 5 l1s all exit 0 + contract); (8) l3b_agent_stub
D-008 keyword map (Act 3 example + 4 keyword cases + fallback). All 18
checks pass. Uses 'set -uo pipefail' (no set -e) so intentional
non-zero exits (policy_checker failure case) can be captured without
killing the script.
---ci---
phase: 3
milestone: v1.0
status: execute
persona: lead-developer
task: T-3.11
requirements:
  covered: [REQ-04, REQ-05, REQ-06, REQ-07, REQ-08, REQ-11]
  partial: [REQ-12]
---/ci---

Wave 3, task T-3.11. REQUIREMENTS: REQ-04/05/06/07/08/11 -> covered
(pending VERIFY). REQ-12 -> partial (l3b_agent_stub created in Phase 03;
full issue-trigger wiring in Phase 04). ROADMAP Phase 03 -> executing.
---ci---
phase: 3
milestone: v1.0
status: verify
requirements:
  covered: [REQ-04, REQ-05, REQ-06, REQ-07, REQ-08, REQ-11]
  partial: [REQ-12]
lessons:
  - 'set -e' + command substitution kills the parent script when the
    child exits non-zero, even when 'rc=$?' follows. verify_phase03.sh
    uses 'set -uo pipefail' (no set -e) so policy_checker's intended
    exit 1 can be captured. Same pattern recommended for future
    verify_phaseNN.sh scripts that test negative cases.
  - 'mock_executor.sh' resolves modules/l2/ relative to cwd, not to the
    script location. The pipeline (Phase 04) must 'cd' to the repo
    root before invoking it. Documented in the I/O contract.
  - Python json.dumps collapses 0.90 -> 0.9; confidence_signal emits
    the JSON literal as a string to preserve the spec-mandated 0.90/0.40.
    This is a demo-aesthetic choice; the parsed float is identical.
  - l3b_agent_stub keyword priority matters: 'gas price' (commodity)
    wins over 'compliance' (regulatory) because commodity is checked
    first per D-008. The Act 3 example was crafted to hit this case.
review:
  p0: 0
  p1: 0
---/ci---

Layer 1 STRUCTURAL: PASS (10/10 files; bash -n + py_compile + yaml load clean; no TODO/FIXME).
Layer 2 BEHAVIORAL: PASS (verify_phase03.sh 18/18; all 9 PLAN.md must-haves met).
Layer 3 SECURITY: PASS (no secrets; subprocess calls use argv lists; hash chain is tamper-evident).
Layer 4 QUALITY: PASS (correctness, testing, security, performance, maintainability, adversarial all green).

Requirements covered this phase: REQ-04, REQ-05, REQ-06, REQ-07, REQ-08, REQ-11.
Partial: REQ-12 (l3b_agent_stub created; full issue-trigger wiring in Phase 04).
grimacing merged commit 3ea36ef3ab into milestone/v1.0-initial 2026-07-21 13:32:21 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: continuous-intelligence/acdl#3