Skip to content

feat: Phase 1 — Contract enforcement pipeline #136

@windoliver

Description

@windoliver

Context

Parent: #132 (Grove v2 architecture)
Reviews: CEO review (CLEAN), Eng review (CLEAN), Design review (8/10)
PR: #135 (review artifacts)

Problem

The contract schema in contract.ts defines gates, stop conditions, outcome policies, and agent constraints — but createLocalRuntime defaults to parseContract: false, so they're all dormant. enforcing-store.ts only checks rate limits and artifact sizes. contributeOperation validates relation targets and artifact hashes but not scores, gates, or role-kind constraints. Contributions that violate the contract are silently accepted.

Solution

New enforcement-pipeline.ts (decorator pattern wrapping contributeOperation):

grove_contribute → enforcement-pipeline
  ├─ 1. agentConstraints.allowedKinds check
  ├─ 2. agentConstraints.requiredArtifacts check
  ├─ 3. agentConstraints.requiredRelations check
  ├─ 4. Gate evaluation (metric_improves, has_artifact, has_relation, min_reviews, min_score)
  ├─ 5. before_contribute hook (existing, blocking)
  ├─ 6. contributeOperation() (existing store write)
  ├─ 7. after_contribute hook (existing, flag on failure — not rolled back)
  ├─ 8. evaluateStopConditions() (existing in lifecycle.ts, just wired in)
  ├─ 9. Auto outcome derivation → outcomeStore.set()
  ├─ 10. EventBus publish (best-effort, Phase 3)
  └─ 11. Audit log write (best-effort)

~80% is wiring existing code. evaluateStopConditions(), HookRunner, all gate schemas already exist.

Tasks

  • Flip parseContract: true by default in runtime.ts:71
  • Create enforcement-pipeline.ts as decorator wrapping contributeOperation
  • Agent constraint enforcement (allowedKinds, requiredArtifacts, requiredRelations)
  • Gate evaluation (5 gate types from contract.ts:GateSchema)
  • First contribution auto-passes metric_improves gate (establishes baseline)
  • Automatic outcome derivation from contract.outcomePolicy
  • Wire evaluateStopConditions() post-contribute (already exists in lifecycle.ts)
  • Wire HookRunner before/after contribute hooks
  • Workspace mutation constraints (validate git diff against immutablePaths)
  • Structured rejection feedback — typed error objects: { rejected, reason, field, hint } (cherry-pick Define contribution manifest schema #1)
  • grove contract validate CLI command (cherry-pick Define relation schema and semantics #2)
  • grove_contribute --dry-run parameter (cherry-pick Define artifact schema and CAS addressing #3)
  • Enforcement pipeline audit log (cherry-pick Define claim lifecycle for swarm coordination #4)
  • ~15 unit tests + ~5 integration tests for enforcement pipeline

Key decisions (from reviews)

  • Enforcement pipeline lives in new enforcement-pipeline.ts (decorator pattern, like enforcing-store.ts)
  • Hook failures flag metadata, not rolled back (contribution persists)
  • First contribution auto-passes gates (establishes baseline)
  • Stop evaluation is O(n) — acceptable for v2 scale, incremental deferred to swarm
  • GROVE.md in immutablePaths (agents can't modify their own constraints)
  • EventBus publish is best-effort (DAG is truth)

Depends on

Nothing — this is the foundation. All other phases depend on this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions