{
  "_meta": {
    "extends": null,
    "version": "0.1.0",
    "overrides": [],
    "appends": [],
    "excludes": []
  },
  "state": "INIT",
  "contract_version": "0.6.38",
  "session": {
    "task_id": "",
    "branch": "",
    "created_at": "",
    "model": "",
    "previous_model": "",
    "model_changed_at": "",
    "model_change_count": 0
  },
  "scope": {
    "included": [],
    "excluded": [],
    "boundary": "project-root",
    "parallel_eligible": false,
    "max_parallel_agents": 1
  },
  "required_tools": {
    "description": "Tools agents MUST use. bash is BLOCKED — all operations use lean-ctx_* tools.",
    "mandatory_gateway": "lean-ctx",
    "enforced": true,
    "tools": {
      "lean-ctx_*": {
        "required": true,
        "reason": "Context persistence, audit trail, contract locking"
      },
      "bash": {
        "required": false,
        "blocked": true,
        "reason": "Bypasses audit trail, contract locking, and context persistence. Use lean-ctx ctx_shell instead."
      },
      "graphify": {
        "required": true,
        "reason": "Codebase exploration — use before any code search or exploration"
      }
    }
  },
  "enforcement": {
    "_doc": "Strict workflow enforcement rules. All fields are MANDATORY. Agents MUST comply or be BLOCKED.",
    "pre_flight": {
      "required": true,
      "required_steps": [
        "load_contract",
        "validate_state",
        "check_branch",
        "read_rules",
        "check_permissions"
      ],
      "skip_policy": "block",
      "_reason": "Agents MUST complete all 5 pre-flight steps. Skipping any step BLOCKS the agent."
    },
    "agent_roles": {
      "orchestrator": {
        "direct_ops_forbidden": true,
        "_direct_ops_reason": "Orchestrator coordinates and delegates. Direct exploration, implementation, and code review are FORBIDDEN. Use specialists.",
        "must_delegate": {
          "exploration": "@explorer",
          "implementation": "@fixer",
          "code_review": "@oracle or @code-reviewer",
          "design": "@designer",
          "research": "@librarian",
          "architecture": "@architect or @oracle"
        },
        "allowed_direct_ops": [
          "contract_ops",
          "delegation",
          "scoring_ops",
          "checkpoint_ops",
          "logging_ops"
        ]
      }
    },
    "checkpoints": {
      "required": true,
      "every_step": true,
      "skip_policy": "block",
      "_reason": "Checkpoint must be saved at start AND end of every workflow phase. Skipping BLOCKS progress."
    },
    "scoring": {
      "required": true,
      "after_each_delegation": true,
      "threshold_pass": 70,
      "threshold_retry": 50,
      "max_retries": 3,
      "_reason": "Every delegated task must be scored. Score < 70 triggers RETRY. Score < 50 triggers BLOCKED."
    },
    "audit_trail": {
      "required": true,
      "log_transitions": true,
      "log_violations": true,
      "_reason": "Every state transition and rule violation must be logged to audit trail."
    },
    "layers": {
      "l1_adoption_check": "required",
      "l2_preflight_gate": "required",
      "l3_contract_lock": "required",
      "l4_scoring_pipeline": "required",
      "l5_audit_trail": "required",
      "l6_agent_templates": "required",
      "l7_checkpoints": "required",
      "_reason": "All 7 enforcement layers are MANDATORY. Missing any layer BLOCKS the workflow."
    },
    "delegation_priority": {
      "order": [
        "@explorer",
        "@planner",
        "@fixer",
        "@code-reviewer",
        "@learner"
      ],
      "_reason": "Always delegate in this priority order. Orchestrator must NEVER skip delegation steps."
    }
  },
  "requirements": {
    "goal": "",
    "scope": {
      "boundary": "",
      "exclusions": []
    },
    "success_criteria": [],
    "acceptance_criteria": [],
    "constraints": {
      "time_limit_minutes": null,
      "step_limit": null,
      "budget_limit": null,
      "tool_restrictions": []
    }
  },
  "decisions": {
    "approved_architecture": null,
    "coding_standard": [],
    "rejected_approaches": [],
    "adr_log": [],
    "adr_index": {
      "folder": "adr",
      "files": [],
      "last_generated": null
    },
    "session_summary": {
      "last_generated": null,
      "file": null,
      "context_ready": false
    }
  },
  "governance": {
    "active_agent": "",
    "mode": "",
    "applicable_skills": [],
    "rules_references": [
      {
        "source": "AGENTS.md",
        "sections": [
          "§3 - Non-Negotiable Rules",
          "§5 - Writing Order",
          "§8 - Null Handling"
        ]
      },
      {
        "source": "PROJECT.md",
        "sections": [
          "scope",
          "constraints"
        ]
      },
      {
        "source": ".opencode/orchestration/contract.json",
        "sections": [
          "all"
        ]
      },
      {
        "source": ".opencode/rules/rules.json",
        "sections": [
          "all"
        ]
      }
    ],
    "current_guidance": "",
    "extension_skills": [],
    "permissions": {
      "do": [],
      "dont": [
        "push to main branch",
        "modify CI/CD or .opencode/ config",
        "use fully qualified names inline",
        "start work without loading contract"
      ],
      "allowed_execution": {
        "description": "Contract-based execution whitelist. Agents may ONLY use tools matching these patterns for shell execution. Default: lean-ctx_* tools.",
        "mandatory_gateway": "lean-ctx",
        "explanation": "Principle of least privilege — whitelist allowed tool patterns instead of denying specific tools. The pre-flight bootstrap uses this contract field to inject execution constraints into every agent session.",
        "tools": [
          "lean-ctx_*"
        ],
        "denied": [
          "bash",
          "snip"
        ]
      }
    },
    "previous_blockers": [],
    "decisions_log": [],
    "timeout": {
      "max_session_minutes": 60,
      "max_retries": 2,
      "escalation_on_timeout": "handoff"
    }
  },
  "validation": {
    "block_on": {
      "max_test_failures": 3,
      "max_score_drop": 30,
      "max_compile_errors": 1
    },
    "rule_overrides": {}
  },
  "outputs": {
    "plan": null,
    "architecture": null,
    "code_changes": [],
    "test_results": null,
    "agent_reports": [],
    "score_summary": null
  },
  "score": {
    "rules": {
      "pass": 0,
      "fail": 0,
      "deduction": 0,
      "subtotal": 0
    },
    "judge": {
      "score": 0,
      "rationale": "",
      "missing_items": []
    },
    "combined": 0,
    "verdict": "INIT"
  },
  "retry": {
    "current_phase": null,
    "attempt": 0,
    "max_attempts": 3,
    "score_threshold": 70,
    "escalation_threshold": 50,
    "issues": []
  },
  "metrics": {
    "cost_tokens": 0,
    "elapsed_ms": 0,
    "agents_used": [],
    "phases_completed": []
  },
  "lessons_learned": []
}
