name: audit-architecture
description: Comprehensive architecture audit. Enumerate modules and boundaries, then produce an issue-ready report without modifying code
max_steps: 12
initial_step: plan

loop_monitors:
  - cycle:
      - supervise
      - review
    threshold: 3
    judge:
      persona: supervisor
      instruction: |
        The supervise → review cycle for the architecture audit has repeated {cycle_count} times.
        Compare the audit report against the plan report and judge:
        - Whether the audit scope has expanded since the previous cycle (new modules audited)
        - Whether remaining unaudited modules can be completed in a reasonable number of cycles
      rules:
        - condition: Audit quality and scope are sufficient
          next: COMPLETE
        - condition: Scope is expanding and progress continues
          next: review
        - condition: Scope is stalled with no prospect of improvement
          next: ABORT

steps:
  - name: plan
    tags:
      - plan
    persona: planner
    policy:
      - contract-change
      - architecture
    knowledge: architecture
    instruction: architecture-audit-plan
    edit: false
    output_contracts:
      report:
        - name: 01-architecture-audit-plan.md
          format: architecture-audit-plan
    rules:
      - condition: Module inventory and audit scope complete
        next: audit
      - condition: Requirements unclear, insufficient info
        next: ABORT

  - name: audit
    tags:
      - review
    persona: architecture-reviewer
    policy:
      - contract-change
      - review
      - architecture
    knowledge: architecture
    instruction: architecture-audit-team-leader
    edit: false
    team_leader:
      max_parts: 3
      part_persona: architecture-reviewer
      part_edit: false
    output_contracts:
      report:
        - name: 02-architecture-audit.md
          format: architecture-audit
    rules:
      - condition: Audit complete
        next: supervise

  - name: supervise
    tags:
      - review
      - supervise
    persona: supervisor
    policy:
      - contract-change
      - review
      - architecture
    knowledge: architecture
    instruction: architecture-audit-supervise
    edit: false
    pass_previous_response: false
    rules:
      - condition: Audit is complete and issue-ready
        next: COMPLETE
      - condition: Architecture audit is incomplete or evidence is insufficient
        next: review

  - name: review
    tags:
      - review
    persona: architecture-reviewer
    policy:
      - contract-change
      - review
      - architecture
    knowledge: architecture
    instruction: architecture-audit-review
    edit: false
    output_contracts:
      report:
        - name: 02-architecture-audit.md
          format: architecture-audit
    rules:
      - condition: Re-audit complete
        next: supervise
