Skip to content

Introduce target-neutral capability/effect IR for <capabilities> parsing #1384

@prompt-driven-github

Description

@prompt-driven-github

Context

Issue #828 introduces <capabilities> as natural-language contracts. This sub-issue creates the foundational parsing layer that compiles <capabilities> tag text into a language-neutral effect IR, independent of any target backend.

Scope

Create a new capability_ir module at pdd/prompts/capability_ir_python.prompt.

The module must:

  1. Accept a <capabilities> block (raw text or parsed tag content).
  2. Parse each bullet into a normalized EffectItem dataclass/model with fields: modal (MAY | MUST_NOT), action (verb, e.g. read, write, call, send, log, modify), resource (normalized noun phrase, e.g. payment_records, email, secrets).
  3. Return a ContractEffectIR object containing a list of EffectItems and metadata (capabilities_present: bool, effect_count: int).
  4. Be entirely independent of Python AST analysis — no imports of ast, pylint, or code-inspection libraries.

Example input

<capabilities>
- MAY read payment records.
- MAY write refund records.
- MUST NOT send emails.
- MUST NOT log provider secrets, bearer tokens, card PAN, or CVV.
</capabilities>

Expected output (Python dataclass / Pydantic model)

ContractEffectIR(
    capabilities_present=True,
    effect_count=4,
    effects=[
        EffectItem(modal='MAY', action='read', resource='payment_records'),
        EffectItem(modal='MAY', action='write', resource='refund_records'),
        EffectItem(modal='MUST_NOT', action='send', resource='email'),
        EffectItem(modal='MUST_NOT', action='log', resource='secrets'),
    ]
)

Files to create/modify

  • pdd/prompts/capability_ir_python.prompt (NEW — prompt spec for capability_ir module)

Acceptance criteria

  • Parsing a well-formed <capabilities> block produces EffectItem objects with correct modal, action, and resource values.
  • A prompt with no <capabilities> tag returns ContractEffectIR(capabilities_present=False, effect_count=0, effects=[]).
  • The module has no imports of Python AST or code-analysis libraries.
  • Unit tests cover: basic MAY/MUST_NOT parsing, multi-line capabilities, empty/missing tag, compound resource phrases.

PDD Command Hint

change, sync


Split Contract

Command sequence: change → sync
Allowed write set:

  • pdd/prompts/capability_ir_python.prompt
    Acceptance criteria:
  • capability_ir.py exists and exports EffectItem and ContractEffectIR
  • Parsing a block with MAY/MUST_NOT bullets returns correct EffectItem list
  • Missing/empty tag returns capabilities_present=False
  • No Python AST or code-analysis imports in capability_ir.py
  • Unit tests for parsing pass
    Independently mergeable: True
    Scope rule: Do not expand beyond this contract or implement sibling sub-issue work. If the contract is insufficient, report the gap instead.

PDD Command Hint: This is a new feature. Use change → sync (modify prompts, then generate and validate code).


Parent: #1370
Parent issue: #1370

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions