Quality targets converge

From bdfinst/agentic-dev-team · View interactive version

Quality targets converge is an AI agent skill from the GitHub repository bdfinst/agentic-dev-team. Multi-workflow convergence worker. Closes the gap between the current test suite and the four quality targets (line+branch coverage ≥ 90%, zero surviving mutants, 100% deterministic, fastest pre-merge wall-clock achievable on-machine). Each iteration reads the latest measurements, picks the largest

How to use this skill

Skill file

Quality Targets Converge

Role: worker. The convergence close-out loop. Reads coverage, mutation, determinism, and wall-clock measurements; picks the largest gap; dispatches the smallest action that moves it; re-measures; repeats. The operator gates the loop and can waive any individual target.

You have been invoked with the /quality-targets-converge command.

Parse Arguments

Arguments: $ARGUMENTS

"coverage gap, no existing seam" action may propose a paired

[Refactor-for-testability] Story (see Step 4). **Default

refactor-allowed** when the flag is absent or carries an unrecognized

value — this preserves today's unconditional-propose behavior for callers

other than /test-improve that don't pass the flag. Whenever the default

fires because the flag was absent or unrecognized, print

"refactor-mode not specified by caller — defaulting to refactor-allowed"

(naming the unrecognized value received, if any) so a caller that forgot

to wire the flag is visible in the run output rather than silently

indistinguishable from one that explicitly wants refactor-allowed.

Path templates. Every filesystem path in the Steps below carries <workflow> as a placeholder; the skill interpolates the resolved --workflow value at run time. There is no literal workflow-name string inside a path.

Steps

1. Load targets

Read .dev-team/quality-targets.json if it exists; otherwise use defaults:

{
  "line_pct_min": 90,
  "branch_pct_min": 90,
  "surviving_mutants_max": 0,
  "determinism_runs": 5,
  "determinism_required_pass_rate": 1.0,
  "wall_clock_target_seconds": null
}

wall_clock_target_seconds = null means "fastest achievable" — the loop tracks it but does not gate on a number.

2. Measure all four dimensions

In one pass before the loop body:

1. Resolve the branch base (same idiom as /build's Farley-Score step — skills/build/SKILL.md Step 7 sub-step 1): git merge-base HEAD origin/HEAD, falling back to origin/main, then main, master, develop. Degenerate-base guard (issue #916): treat base == HEAD, or every candidate ref unresolvable (single-branch / no-remote repo where merge-base fails outright, or every commit landed directly on the fallback branch so merge-base resolves to HEAD) as a resolution failure, not a valid base. On resolution failure, fall back to the plan's recorded plan-start anchor — the same anchor /build resolves against (issue #865): python3 ${CLAUDE_PLUGIN_ROOT}/scripts/build_rollback_point.py get-by-symbolic --path .claude/memory/build-rollback.json --symbolic plan-start --repo <repo> --ancestor-of HEAD (the --repo/--ancestor-of args reject a stale plan-start from an unrelated earlier build). If a qualifying entry is found, use its sha as <base>. If none is found, print Branch-base resolution degraded — cannot bound the changed set; scoping to the full in-scope component list this run. and scope to the full in-scope component list only as a surfaced last resort — so a widened run is visible in the output, never a silent whole-repo default.

2. Cumulative changed set: git diff --name-only <base>...HEAD (three-dot — everything the branch added since it forked, across all sessions, not just the last commit).

3. Scope is the source covered by the changed TESTS, not just changed source files. A test-improvement branch commonly changes no production source at all, so mapping only changed *.ts/*.py/etc. would scope to nothing. From the changed set, take every changed test file and resolve the production source it exercises: a co-located X.spec.ts / X.test.ts maps to its sibling X.ts (same basename, same directory); an a11y / contract / integration spec that names no co-located sibling maps to the first-party production modules it imports (parse the spec's import statements, drop third-party paths). Union that resolved-source set with any changed production source files. That union is the mutation --scope.

1. For each in-scope file, look up the most recent entry in mutation-history.json.

2. Compare the entry's captured_at to the file's last committer date: git log -1 --format=%cI -- <file> (committer date — not file mtime. Uncommitted edits intentionally won't trigger re-measure; convergence runs over committed code).

3. If the entry post-dates the file's last commit AND status != "tool_unavailable", reuse the entry's survivors_after as the current count. Drop the file from the --scope glob passed to the fresh /mutation-testing run below.

4. Otherwise (no entry, stale entry, or prior status: "tool_unavailable") — measure the file fresh in the next bullet. The fresh result is written back to .dev-team-reports/<workflow>/<slug>/data/mutation-history.json as a synthetic entry with story: "converge-<iteration>" so within-iteration reuse works and so the next iteration sees the same evidence the upstream phase would have.

Backward compatibility — mutation-history.json absent. Workflows that pre-date this contract have no upstream mutation evidence. When the file is absent, fall through to measuring fresh: the next bullet runs /mutation-testing over every file in the branch-vs-base changed set defined above — the reuse rule is opportunistic, not required, but absence of history never widens the run back to whole-repo.

1. First retry the module's non-static subset with ignoreStatic (static initializers are the common OOM trigger); if that subset now measures, use it and mark only the static remainder held-at-baseline.

2. For whatever still cannot be measured, hold it at its persisted baseline count — the survivors_after recorded for that file in baseline-mutation.json / mutation-history.json — and record it in the snapshot's held_at_baseline list.

3. Report it in Step 6 verbatim as "held at baseline (could not measure — needs ≥N GB agent)" — never as a fresh zero, never dropped from the module list.

Write the snapshot to .claude/memory/<workflow>/<slug>/converge-<iteration>.json:

{
  "iteration": <n>,
  "captured_at": "<ISO-8601>",
  "line_pct": …, "branch_pct": …,
  "surviving_mutants": [ { "file":…, "line":…, "op":… }, … ],
  "surviving_mutants_whole_repo_spliced": <count>,
  "held_at_baseline": [ { "module":…, "baseline_survivors":…, "reason": "oom|timeout|tool_crash" }, … ],
  "mutation_scope": {
    "base_ref":              "<sha>",
    "changed_test_files":    <count>,
    "resolved_source_files": <count>
  },
  "mutation_reuse": {
    "reused_from_history": <count>,
    "measured_fresh":      <count>,
    "total_files":         <count>
  },
  "determinism_pass_rate": …, "flaky_tests": [ … ],
  "wall_clock_median_sec": …, "wall_clock_runs": [ …, … ]
}

The operator-visible iteration report (Step 6) names the cost saving directly: mutation: reused N, measured M — without that line, the reuse rule is invisible and the operator can't tell whether upstream mutation evidence actually paid off.

3. Compute the gap to each target

For each of the four, compute "distance to target":

4. Pick the largest gap + dispatch the smallest action

Use this priority order (matches the spec's order of operations) when two gaps tie:

  1. Determinism (a flaky suite invalidates every other metric).
  2. Surviving mutants (coverage you can't trust isn't coverage).
  3. Line + branch coverage.
  4. Wall-clock (only if the operator set a target).

For the picked gap, dispatch the smallest action — by emitting a recommendation, not by editing code (the actual edit happens via /build against a downstream Story):

| Gap | Smallest action |

| --- | --- |

| Flaky test | Identify the source of non-determinism (real clock, RNG, sleep, shared state, order dependence). Propose a downstream Story to remove it. |

| Surviving mutant on a covered line | The test asserts coverage but not behavior; propose a downstream Story to add the specific assertion that kills this mutant. |

| Surviving mutant on an uncovered line | Propose a downstream Story to add a test that hits the line and asserts the behavior. |

| Coverage gap on a single file, existing seam | Propose a downstream Story to add a component test for the uncovered branch at the existing seam. |

| Coverage gap on a single file, no existing seam, --refactor-mode refactor-allowed | Propose a paired [Refactor-for-testability] Story (today's behavior, unchanged). |

| Coverage gap on a single file, no existing seam, --refactor-mode no-refactor | Do not propose a [Refactor-for-testability] Story — the operator already closed that decision at Phase 6. Instead, write an entry (seam-needed / behavior-gained / estimated-risk) to .dev-team-reports/<workflow>/<slug>/refactor-backlog.md, appending to the file Phase 6 writes if it already exists rather than creating a second backlog file. |

| Behavior-preserving (invariant) test refactor — a done()→async/await rewrite, a real-timer→fakeAsync migration, a callback→promise conversion that changes no assertion and kills no mutant | Skip it — do not dispatch a Story. These migrations preserve test semantics, so they close no coverage / mutation / determinism gap; dispatching work for them is pure churn. Log the skip with its rationale to .dev-team-reports/<workflow>/<slug>/refactor-backlog.md (the same backlog the no-refactor row appends to) as invariant-refactor-skipped: <file> — <migration> — no gap closed, so the decision is auditable rather than silent. |

| Wall-clock regression | Identify the slowest tests (top 10). Propose a Story to swap a local container for an in-memory double where both prove the behavior. |

Invariant refactors are skipped, not dispatched (issue #1208). The "behavior-preserving (invariant) test refactor" row exists because a convergence loop scanning changed tests will encounter semantics-preserving migrations. They change no assertion and kill no mutant, so they close no target gap — proposing a Story for them only adds churn. Skip them and log the rationale to the backlog so the skip is auditable rather than silent.

Gherkin binding for proposed component tests. When the smallest action is "add a component test" (the surviving-mutant rows, or the coverage-gap-with-existing-seam row above), first check .claude/memory/<workflow>/<slug>/gherkin-bindings.json for an approved Scenario covering that behavior at the relevant public surface:

This keeps the approved Gherkin as the single source of intended behavior even when convergence discovers a gap. The operator stays the only author of intent.

Each recommendation lands as a new child issue on the parent (via the same CLI dispatch convention as /issues-from-assessment) or as a new file under .claude/plans/<workflow>/phase-7/. The orchestrator then drives /build against each.

5. Re-measure + decide whether to loop

After /build closes the dispatched Story:

6. Post the converge history

Append a markdown block to the parent (or FEATURE.md):

### Convergence iteration <n> (<ISO-8601>)
- Coverage: line <pct>% (target 90%) · branch <pct>% (target 90%)
- Surviving mutants (branch-scoped changed set): <n> (target 0)  ·  mutation: reused <N>, measured <M>
- Surviving mutants (whole-repo, spliced over persisted baseline): <n>  ·  Δ vs baseline: <±n>
- Held at baseline (could not measure — needs ≥N GB agent): <module list, or "none">
- Determinism: <passes>/<runs> (target <runs>/<runs>)
- Wall-clock median: <sec>s (target: fastest achievable / <n>s if set)
- Largest gap: <dimension>
- Dispatched: <story title / id>

Same CLI pattern as /coverage-baseline and /coverage-delta.

6b. Gherkin effectiveness roll-up (conditional)

When .claude/memory/<workflow>/<slug>/gherkin.md exists (Phase 3 ran — see

/gherkin-derive), run the roll-up after every iteration's re-measure so

there is a standing signal on whether the derived scenarios track real

coverage/mutation movement (issue #1296):

python3 "${CLAUDE_PLUGIN_ROOT}/scripts/gherkin_effectiveness_rollup.py" \
  --gherkin-md .claude/memory/<workflow>/<slug>/gherkin.md \
  --bindings-json .claude/memory/<workflow>/<slug>/gherkin-bindings.json \
  --baseline-coverage .dev-team-reports/<workflow>/<slug>/data/baseline-coverage.json \
  --current-coverage <this iteration's coverage measurement> \
  --baseline-mutation .dev-team-reports/<workflow>/<slug>/data/baseline-mutation.json \
  --current-mutation <this iteration's mutation measurement> \
  --out .claude/metrics/gherkin-derive-effectiveness.jsonl

Omit any flag whose file doesn't exist for this run (e.g. no

gherkin-bindings.json when the workflow only derived scenarios via

/gherkin-derive and never ran /gherkin-public) — the script degrades

gracefully and still records provenance/binding-mode per scenario with the

correlated field left null. When gherkin.md is absent (binding mode

none, or Phase 3 never ran), skip this step entirely — there is nothing

to roll up. This is a metrics side-effect only; it never changes convergence

gaps or which action Step 4 dispatches.

7. Waiver handling

If the operator chooses to waive a target:

A waiver counts as "met" for the loop's exit condition but is surfaced in the orchestrator's final Report.

8. Report

Print:

Examples / Integration

Notes

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.