name: development-remediation-dynamic
description: Dynamic-facet remediation loop for adjudicated review findings, including planning, fixing, and verification.
all_steps:
  rules:
    - ref: findings-handling
      position: before_instruction
    - ref: plain-terminology
      position: before_instruction

subworkflow:
  callable: true
  visibility: internal
  returns:
    - need_replan
  params:
    fix_pool:
      type: facet_pool_ref
      default: coding-facets
    fix_companions:
      type: companion_ref[]
      default: []
    plan_policy:
      type: facet_ref[]
      facet_kind: policy
      default:
        - coding
        - testing
        - review
    fix_policy:
      type: facet_ref[]
      facet_kind: policy
      default:
        - coding
        - testing
    verification_policy:
      type: facet_ref[]
      facet_kind: policy
      default:
        - coding
        - testing
        - review
    fix_knowledge:
      type: facet_ref[]
      facet_kind: knowledge
      default:
        - architecture
        - implementation-semantics
    verification_knowledge:
      type: facet_ref[]
      facet_kind: knowledge
      default:
        - architecture
        - unit-testing
        - e2e-testing
    fix_plan_instruction:
      type: facet_ref
      facet_kind: instruction
      default: fix-plan-from-review-resolution
    fix_replan_instruction:
      type: facet_ref
      facet_kind: instruction
      default: fix-replan
    fix_plan_report_format:
      type: facet_ref
      facet_kind: report_format
      default: fix-plan
facet_pools:
  coding-facets:
    uses: coding-facets
  takt-coding-facets:
    uses: takt-coding-facets
initial_step: fix-plan
loop_monitors:
  - cycle:
      - fix-replan
      - fix
    ignore_steps:
      - fix-verifier
      - fix-retry
    threshold: 4
    judge:
      persona: supervisor
      instruction: loop-monitor-reviewers-fix
      rules:
        - condition: Healthy (fix progress exists and report content is converging)
          next: fix-replan
        - condition: Fixes are incomplete or reports have not converged, but another review and fix is feasible
          next: fix-replan
        - condition: The fix approach assumptions must change and replanning is feasible
          next: fix-replan
        - condition: No feasible path can satisfy the requirements
          next: ABORT
  - cycle:
      - fix-retry
      - fix-verifier
    threshold: 4
    judge:
      persona: supervisor
      instruction: loop-monitor-reviewers-fix
      rules:
        - condition: Healthy (fix progress exists and report content is converging)
          next: fix-retry
        - condition: Fixes are incomplete or reports have not converged, but another fix is feasible
          next: fix-retry
        - condition: The fix approach assumptions must change and replanning is feasible
          next: fix-replan
        - condition: No feasible path can satisfy the requirements
          next: ABORT
steps:
  - name: fix-plan
    uses: peer-review-fix-plan
    with:
      plan_policy:
        $param: plan_policy
      fix_knowledge:
        $param: fix_knowledge
      plan_instruction:
        $param: fix_plan_instruction
      plan_report_format:
        $param: fix_plan_report_format
    rules:
      - condition: Fix plan finalized, or, even with an unconfirmed cause, a concrete investigation within the current requirements and repair scope can be executed as the first repair unit with safe repair and verification based on its result (unexecuted or unverified work alone does not require task-wide replanning)
        next: fix
      - condition: Task-wide premises such as requirements or repair scope must change, and the change would enable concrete project-local work (an unexecuted local cause investigation alone does not qualify)
        return: need_replan
      - condition: No project-local action can advance required work, with evidence identifying the necessary external action or incompatible requirements
        next: ABORT
  - name: fix-replan
    uses: peer-review-fix-plan
    with:
      plan_policy:
        $param: plan_policy
      fix_knowledge:
        $param: fix_knowledge
      plan_instruction:
        $param: fix_replan_instruction
      plan_report_format:
        $param: fix_plan_report_format
    rules:
      - condition: Fix plan finalized, or, even with an unconfirmed cause, a concrete investigation within the current requirements and repair scope can be executed as the first repair unit with safe repair and verification based on its result (unexecuted or unverified work alone does not require task-wide replanning)
        next: fix
      - condition: Task-wide premises such as requirements or repair scope must change, and the change would enable concrete project-local work (an unexecuted local cause investigation alone does not qualify)
        return: need_replan
      - condition: No project-local action can advance required work, with evidence identifying the necessary external action or incompatible requirements
        next: ABORT
  - name: fix
    capabilities:
      - edit
      - enable-skills
    uses: peer-review-fix
    with:
      fix_policy:
        $param: fix_policy
      fix_knowledge:
        $param: fix_knowledge
      fix_instruction: apply-fix-plan
    dynamic_facets:
      pool:
        $param: fix_pool
    companion:
      $param: fix_companions
    rules:
      - condition: Fix complete
        next: fix-verifier
      - condition: Fix plan requires revision
        next: fix-replan
      - condition: Task-level replanning required
        return: need_replan
  - name: fix-verifier
    uses: peer-review-fix-verifier
    with:
      verification_policy:
        $param: verification_policy
      fix_knowledge:
        $param: verification_knowledge
    rules:
      - condition: verified
        next: COMPLETE
      - condition: plan_invalid — The fix plan omits a required member, state, or path; includes an out-of-scope path; or has a defective assumption, boundary, method, or evidentiary power. This includes cases that also have implementation or evidence gaps
        next: fix-replan
      - condition: incomplete — The fix plan has no defect, but a planned obligation has an implementation or evidence gap
        next: fix-retry
  - name: fix-retry
    capabilities:
      - edit
      - enable-skills
    uses: peer-review-fix
    with:
      fix_policy:
        $param: fix_policy
      fix_knowledge:
        $param: fix_knowledge
      fix_instruction: apply-fix-verification
    dynamic_facets:
      pool:
        $param: fix_pool
    companion:
      $param: fix_companions
    rules:
      - condition: Fix complete
        next: fix-verifier
      - condition: Fix plan requires revision
        next: fix-replan
      - condition: Task-level replanning required
        return: need_replan
