Skip to content

feat: inherited when ... from agent attribution (Invariant prerequisite, v2 §43)#51

Merged
rmichaelthomas merged 1 commit into
mainfrom
feat/inherited-when-attribution
Jul 3, 2026
Merged

feat: inherited when ... from agent attribution (Invariant prerequisite, v2 §43)#51
rmichaelthomas merged 1 commit into
mainfrom
feat/inherited-when-attribution

Conversation

@rmichaelthomas

Copy link
Copy Markdown
Owner

Summary

Implements Invariant Checkpoint v2 §43 (IRQ-3) — the one upstream prerequisite for liminate-invariant. Extends statement-final agent attribution to inherited when headers.

Locked grammar:

inherited when <condition> [unless <guard>] from <agent-name> [:]
  • Legal only with the inherited prefix. A trailing from on a plain when header remains a parse error.
  • Agent-name rules are identical to existing statement attribution: single UNKNOWN token, hyphenated names, quoted strings rejected, reserved words rejected.
  • inherited_from flows into HANDLER_FIRE trigger metadata so downstream consumers (Invariant) can attribute Narratia-written handlers (inherited when ... from narratia) across sessions.
  • No new vocabulary word — reuses the MS-Q4 from reuse for one more grammatical position. The 60-word count is unchanged.

Phases completed

  • Phase 1 (parser)parse_when_block consumes from <agent> attribution after the optional unless guard and before the optional colon, gated on is_inherited. A non-inherited when with a trailing from now raises a targeted parse error directing the user to the inherited prefix. Reuses _try_consume_inherited_from unchanged.
  • Phase 2 (renderer)_render_when appends from <agent> to the header line (never after the multi-line action block). render()'s generic statement-final suffix is guarded against WhenNode so it doesn't double-append.
  • Phase 3 (tests) — 12 new tests in tests/test_inherited.py (45 → 57): parse success (bare / with guard / with colon / with of-condition), all four error paths, header-line rendering, round-trip fidelity (asserting compare=False fields explicitly), and an end-to-end HANDLER_FIRE trigger-metadata integration test through the actual listen() generator.

Files modified

  • src/liminate/parser.py
  • src/liminate/renderer.py
  • tests/test_inherited.py

Invariants satisfied

  1. Round-trip fidelity holds for attributed inherited when nodes.
  2. Plain when is untouched — trailing from still errors; without it, behavior is unchanged.
  3. inherited_from is inert provenance metadata (compare=False), never read by execution.
  4. Single agent-name ruleset — no forked validation logic.
  5. No vocabulary change — vocabulary.py untouched, word count remains 60.

listener.py required no change_wrap_with_trigger already read handler.when_node.inherited_from (built dark, ahead of this grammar landing); this PR is what gives it a non-None value to carry for the first time.

Test plan

  • Full suite: python3 -m pytest — 1511 passed, 0 failed, 0 regressions (was 1499 before this branch)
  • All Phase 1/2/3 acceptance criteria from the build prompt verified individually
  • Rendered canonical form confirmed to place attribution on the header line:
    inherited when level is above 50 unless level is above 90 from compliance-agent
      show level
    

🤖 Generated with Claude Code

…nt v2 §43)

Extends statement-final agent attribution to `inherited when` headers:
`inherited when <condition> [unless <guard>] from <agent-name> [:]`.
Legal only with the `inherited` prefix; a trailing `from` on a plain
`when` header remains a parse error. Reuses the existing
`_try_consume_inherited_from` agent-name validation unchanged.

`inherited_from` flows into HANDLER_FIRE trigger metadata via
listener._wrap_with_trigger, which already read this field — the
plumbing predates this change and required no modification.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@rmichaelthomas
rmichaelthomas merged commit 60a0ba6 into main Jul 3, 2026
2 checks passed
@rmichaelthomas
rmichaelthomas deleted the feat/inherited-when-attribution branch July 3, 2026 16:38
rmichaelthomas added a commit that referenced this pull request Jul 15, 2026
…ution

feat: `inherited when ... from` agent attribution (Invariant prerequisite, v2 §43)
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.

1 participant