Skip to content

feat: HC-124 — end-to-end AI codegen demo#24

Merged
SoundBlaster merged 4 commits into
mainfrom
feat/hc-124-codegen-demo
Jun 12, 2026
Merged

feat: HC-124 — end-to-end AI codegen demo#24
SoundBlaster merged 4 commits into
mainfrom
feat/hc-124-codegen-demo

Conversation

@SoundBlaster

Copy link
Copy Markdown
Member

Summary

The RFC §9.7 pipeline, made runnable: Examples/codegen-demo/ shows the full loop spec → IR v2 → generated code → validated by the same contracts.

  • generated/*.py — one Claude-generated Python module per .hc node, each embedding its source node's hash and per-value provenance comments (# APIServer > Listen @ Examples/service.hcs:26). The service runs: python3 generated/service.py('0.0.0.0', 8080).
  • check.py (stdlib only) — two checks against a fresh IR emit:
    • freshness: node-hash comparison. A one-line port: 8080 → 9090 spec edit marks exactly api_server.py + the root wiring stale (Merkle), leaving logger.py/database.py untouched — regeneration is scoped, the review-compression story is demonstrable;
    • conformance (HC2104-gen): values embedded in generated code are validated against the contracts[] echoed in the IR — a hand-edited port: 99999 in a "generated" file is caught with the governing selector named.
  • generate.sh — regenerates only stale modules via claude -p, feeding each the IR subtree of its node. No stale module — no LLM call.
  • CI runs check.py on every push: committed artifacts cannot silently drift from the spec.
  • workplan.md: HC-124 marked done; DOCS/Usage.md §5 links the runnable loop.

Stacked on #23 (base: feat/hc-111-value-validation).

Test plan

  • check.py — all 4 modules FRESH, contracts conformant (runs in CI now)
  • One-line spec edit → exactly 2 modules stale (api_server + root wiring), 2 fresh
  • Tampered artifact (port: 99999) → error[HC2104-gen], exit 2
  • python3 generated/service.py runs and listens config is correct
  • 92 Swift tests unaffected

🤖 Generated with Claude Code

The RFC §9.7 pipeline made runnable: service spec → IR v2 → one generated
Python module per .hc node → the same contracts validate the artifacts.

- generated/*.py — Claude-generated modules embedding the source node's hash
  and per-value provenance comments; the service actually runs
- check.py (stdlib only) — freshness by node-hash comparison (Merkle: a
  one-line port edit marks exactly api_server.py + the root wiring stale,
  logger/database untouched) and HC2104-gen conformance of embedded values
  against contracts[] echoed in the IR (catches a hand-edited port: 99999)
- generate.sh — scoped regeneration of stale modules via `claude -p`, fed the
  IR subtree of each stale node; no stale module — no LLM call
- CI runs check.py on every push, so the committed artifacts can never drift
  from the spec silently
- workplan: HC-124 marked done; DOCS/Usage.md §5 links the runnable loop

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f9d7a939bb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread Examples/codegen-demo/check.py
SoundBlaster and others added 2 commits June 12, 2026 15:52
Review follow-up on #24: check.py imports the generated modules, which
left compiled .pyc files in the tree. Bytecode is a build artifact —
removed and ignored.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a runnable end-to-end demo of the RFC §9.7 pipeline, showing spec-driven Python code generation per node (with embedded node hashes + provenance) and a CI-enforced verification loop that detects artifact drift and scopes regeneration.

Changes:

  • Adds Examples/codegen-demo/ including committed generated Python modules, check.py (freshness + conformance checks), and generate.sh (regenerate only stale modules via claude -p).
  • Wires the demo into CI (runs check.py on every push/PR) and updates docs/workplan to reference the runnable loop.
  • Updates .gitignore to ignore Python bytecode caches.

Reviewed changes

Copilot reviewed 6 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
workplan.md Marks HC-124 as completed with pointers to the runnable demo and CI checks.
Examples/codegen-demo/README.md Documents how to run the demo, interpret freshness/conformance, and regenerate.
Examples/codegen-demo/generated/service.py Generated “wiring” module for /Service demonstrating node-hash embedding.
Examples/codegen-demo/generated/logger.py Generated module for /Service/Logger with provenance-annotated CONFIG.
Examples/codegen-demo/generated/database.py Generated module for /Service/Database with provenance-annotated CONFIG.
Examples/codegen-demo/generated/api_server.py Generated module for /Service/APIServer with provenance-annotated CONFIG.
Examples/codegen-demo/generate.sh Script to regenerate only stale modules using Claude + IR subtree prompts.
Examples/codegen-demo/check.py Stdlib-only validator that re-emits IR, checks freshness, and validates embedded values.
DOCS/Usage.md Links to the runnable loop and positions hypercode diff as the future productized comparator.
.gitignore Ignores __pycache__/ and *.pyc.
.github/workflows/swift.yml Adds a CI step to run the codegen demo’s check.py.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Examples/codegen-demo/check.py Outdated
Comment thread Examples/codegen-demo/check.py
Comment thread Examples/codegen-demo/check.py
Comment thread Examples/codegen-demo/generate.sh
@SoundBlaster SoundBlaster changed the base branch from feat/hc-111-value-validation to main June 12, 2026 13:53
…ty paths, mktemp trap

- check.py now enforces what its docstring promised: a key under a
  required contract must be present in CONFIG (dropping 'port' from a
  generated module is a violation), and a CONFIG key the spec doesn't
  resolve is flagged as drift.
- Conformance respects module boundaries: a module owns its node's
  subtree up to the next generated module, so the wiring module's empty
  CONFIG stays valid.
- Node paths use selector identity (type[.class][#id]) — the same
  addressing as 'hypercode diff' — so same-type siblings can't collide
  silently (ambiguity is a hard error); generate.sh resolves the same
  paths and cleans up its temp IR via an EXIT trap.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@SoundBlaster SoundBlaster merged commit d2dfaaa into main Jun 12, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants