codegen: show imports in CODEGEN.md and reject unimported names

A 4B codegen model wrote a plausible body that called
urllib.request.urlopen and returned ActionResult without importing either.
The contract described imports in prose but never showed one (and the model
only ever sees CODEGEN.md, not the seeds it points at), and parse_skill_body
only compiled the AST — so the body was accepted and failed later at
materialize/run.

- CODEGEN.md: add a complete minimal example (imports first, then
  INTEGRATION/CONTRACT/act), an explicit "import everything you use" note,
  the correct DecisionRequest/Option import path, and a strengthened
  acceptance criterion.
- codegen.py: parse_skill_body now rejects a body that references names it
  never imports or binds, via a scope-aware symtable check (skips locals,
  parameters, closures, builtins, and module dunders). The failure is a
  ValueError, so the existing retry ladder fires with a corrective prompt.
- tests: parse-level coverage (missing imports, closures/locals/builtins,
  module dunders, wrong-but-bound module paths) plus a pipeline test that an
  import-less body fails authoring and leaves a restartable stub.
This commit is contained in:
gabby committed 2026-10-03 21:21:09 +00:00
1 parent 8426b85ce0
commit 780c9592ed
5 files changed
+274 -9

No files matched your search

+4 -2
View File
@@ -127,7 +127,8 @@ codegen.py CodegenClient (OpenAI-compatible) writes real-integration skill
declare INTEGRATION service/transport/config_vars, and declare
their own flat `CONTRACT` {var: description});
parse/validate (compile + act + CONTRACT keys all read from
ctx.config) + parse_contract / parse_integration /
ctx.config + every referenced name imported/bound, via symtable)
+ parse_contract / parse_integration /
infer_integration / integration_findings; the bridge catalog
(describe_bridges()) is injected into the body, retry, regen,
elicitation, and testgen prompts — it is the single source of
@@ -623,7 +624,8 @@ CLI, unit tests (24) + integration tests (2).
repair): CODEGEN.md + request + tree + requirements answers; the body is a
single `act(ctx, request)`, reads every operational value from `ctx.config`,
performs the real action, and declares `INTEGRATION` and its own flat
`CONTRACT` (every contract key must be read from `ctx.config`, enforced by
`CONTRACT` (every contract key must be read from `ctx.config`, and every
name the body references must be imported/bound — both enforced by
`parse_skill_body`).
3. **fidelity gate** (`authoring:fidelity` SemIf decision +
`integration_findings`): a rapid sanity check (accept/reconsider) — is the