Skip to content

feat(spec,qa): detect behavior-rule implementations across skill+runtime touchpoints #552

Closed

Description

@admarble

Summary

When an issue's AC describes a behavior rule (e.g. "default becomes X", "always include Y", "never skip Z"), the rule is often implemented at multiple touchpoints — typically a skill prompt (LLM-interpreted) and runtime TypeScript code that duplicates the rule. Today, neither /spec nor /qa surfaces this duplication, so PRs frequently land with the skill updated and the runtime stale (or vice versa).

This issue adds a shared detection heuristic used in both phases:

  • /spec runs it proactively to surface all touchpoints in the plan, so the user can scope the work upfront.
  • /qa runs it reactively to verify no old-rule code survives anywhere in the diff's blast radius.

Motivation — concrete recent miss

Issue #533 ("default /assess spec phase ON, remove bug/docs auto-skip") is the motivating example.

The AC text mentioned .claude/skills/assess/SKILL.md explicitly. /spec scoped the work to that skill file + CHANGELOG. /exec implemented it. /qa gave READY_FOR_MERGE. All while the runtime CLI (phase-mapper.ts detectPhasesFromLabels + batch-executor.ts auto-detect branch) still short-circuited bug/docs issues to exec → qa, directly contradicting the new "spec by default" behavior.

The gap was caught only by manual user follow-up ("any other gaps?"), and required:

  • Three rounds of adversarial sweeps to find all stale references
  • Two additional commits on top of the original PR (2e79778 + e7632d8)
  • Updates to runtime code, 4 test files, 4 docs (docs-pipeline.md, exact-label-matching.md, workflow-phases.md, state-schema.ts), and a CHANGELOG rewrite

A pre-flight grep for BUG_LABELS/DOCS_LABELS/"skip spec" at /spec time would have surfaced 90% of these in one pass.

See the post-mortem in issue #533 comments: #533

Acceptance Criteria

  • AC-1: /spec surfaces touchpoints proactively. When /spec parses an AC containing behavior-rule keywords (default, always, never, rule, behavior, skip), it greps the codebase for related symbols/keywords and lists all touchpoints under a new "Rule Touchpoints" section in the plan.

  • AC-2: /qa verifies behavior at all touchpoints. When /qa reviews a behavior-rule AC, it greps for inverse keywords/symbols (the OLD rule's implementation) across the repo. Any survival → AC marked NOT_MET with the file paths/line numbers listed under the AC explanation.

  • AC-3: Shared heuristic documented. Both detectors reference a single references/behavior-rule-detection.md page describing: trigger keywords, grep patterns, common symbol categories (constants, function names, comment patterns), and false-positive guards. Both /spec and /qa SKILL.md files link to it.

  • AC-4: 3-dir sync. Edits applied identically across .claude/skills/, templates/skills/, skills/ for both spec/SKILL.md and qa/SKILL.md (and the new references/behavior-rule-detection.md). `scripts/check-skill-sync.ts` reports synced 3/3 for all touched files.

  • AC-5: Tests verify trigger conditions. Unit/integration tests assert:

    • Triggers fire on behavior-style AC text: "Default rule becomes X", "Always include Y", "Never skip Z"
    • Triggers do NOT fire on file-specific AC text: "Update line 42 of foo.ts", "Add field to interface X"
    • Touchpoint detection finds duplicate implementations across skill+TypeScript layers (use feat(assess): default spec phase ON, remove bug/docs auto-skip #533's BUG_LABELS/DOCS_LABELS as a fixture)
  • AC-6: CHANGELOG entry under `[Unreleased] / ### Added` referencing this issue and feat(assess): default spec phase ON, remove bug/docs auto-skip #533 as the motivating miss.

Non-Goals

  • Not auto-fixing detected drift — surfacing is enough; user/exec applies the fix.
  • Not a generic "behavior change linter" outside the spec/qa flow — scope is the AC-driven workflow only.
  • Not modifying the AC linter or scope-assessment logic — this is additive detection, not validation.

Risks / Open Questions

  • False positive rate on AC-1 trigger keywords. "Default" appears in many ACs that aren't behavior rules (e.g. "set default value to 5"). Mitigation: require ≥2 behavior keywords OR an explicit pattern ("always X unless Y"). Tunable in references/behavior-rule-detection.md.
  • Symbol enumeration is heuristic. Detection relies on grepping for constants/function names that implement the OLD rule. Some rules are inline conditionals with no named symbol. AC-2 should include a fallback: when no symbols match the AC's keywords, search for the inverse English phrasing of the rule.
  • /qa runtime cost. Adding another grep pass per behavior-AC is cheap (<1s) but compounds in large QA runs. Cache or short-circuit when no behavior-rule ACs are present.

Complexity

medium — shared heuristic + 2 skill updates + 3-dir sync + tests + docs. Estimated 1–2 days. Single PR.

Self-assessed workflow

spec → exec → qa with -q (skill changes + 3-dir sync + new reference doc + CHANGELOG)

Activity

  1. added
    enhancement
    on Apr 25, 2026
  2. admarble commented on Apr 26, 2026

    @admarble
    ContributorAuthor

    → PROCEED — Behavior-rule cross-touchpoint detection (skill+runtime), 6 ACs

    Workflow: spec → testgen → exec → qa with -q

    npx sequant run 552 -q --phases spec,testgen,exec,qa
    

    testgen triggered by AC-5 ("Unit/integration tests assert..."). -q for multi-file scope: 2 skill files × 3-dir sync + new reference doc + tests + CHANGELOG.

    ⚠ #551 also modifies qa/SKILL.md; land sequentially to avoid 3-dir-sync merge conflicts.

  3. added 2 commits that reference this issue on May 4, 2026
  4. admarble commented on May 8, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (6 ACs, ~3 directories: .claude/skills/{spec,qa}, src/lib/heuristics/, tests/)

    AC Quality Check

    All 6 ACs pass lintAcceptanceCriteria — no vague/unmeasurable/open-ended flags. AC-5 has nested bullets describing trigger conditions; the parser treats those as part of the AC body which is fine for execution. No title/body tension.


    Scope Assessment

    Non-Goals: Found in issue body (3 items: no auto-fix, not a generic linter, not modifying ac-linter/scope).

    Metric Value Status
    Feature count 2 (/spec proactive + /qa reactive sharing one heuristic) ⚠️
    AC items 6 ⚠️
    Directory spread 3 (skill dirs × 3-mirror, src/lib, tests) ⚠️

    Verdict: ⚠️ SCOPE_WARNING — auto-enables quality loop. Splitting into /spec-only and /qa-only issues was considered but rejected: AC-3 mandates a shared reference doc, so the heuristic must land atomically.


    Acceptance Criteria

    AC-1: /spec surfaces touchpoints proactively

    Verification: Integration Test
    Scenario: Given an AC with behavior-rule keywords (≥2 of default|always|never|rule|behavior|skip) → When /spec runs context gathering → Then the plan output includes a "Rule Touchpoints" section listing all grep'd symbols and their file:line locations.
    Assumptions: Trigger keyword set is finalized in references/behavior-rule-detection.md; ≥2-keyword threshold catches #533-style ACs without flagging "set default value to 5".

    AC-2: /qa verifies behavior at all touchpoints

    Verification: Integration Test
    Scenario: Given a feature branch where the OLD rule's symbol (e.g. BUG_LABELS short-circuit) survives → When /qa reviews the behavior-rule AC → Then that AC is marked NOT_MET and the comment lists path:line for every survival.
    Assumptions: "Inverse keyword" set can be derived from the AC text (e.g. AC says "spec on by default" → search for skip spec/SKIP_PHASES); fallback to inverse English phrasing when no symbol matches.

    AC-3: Shared heuristic documented

    Verification: Manual Test (doc inspection + link grep)
    Scenario: Given references/behavior-rule-detection.md exists in all 3 skill mirrors → When grep'ing spec/SKILL.md and qa/SKILL.md → Then both link to the doc with relative path. Doc covers: trigger keywords, grep patterns, symbol categories, false-positive guards, fixtures from #533.

    AC-4: 3-dir sync

    Verification: Integration Test
    Scenario: Given edits to spec/SKILL.md, qa/SKILL.md, and references/behavior-rule-detection.md → When running npx tsx scripts/check-skill-sync.ts → Then the script reports synced 3/3 for every touched file (no diverged or missing entries).

    AC-5: Tests verify trigger conditions

    Verification: Unit Test + Integration Test
    Scenario:

    • Unit: Given AC text "Default rule becomes X" / "Always include Y" / "Never skip Z" → When detectBehaviorRule(ac) runs → Then returns triggered: true.
    • Unit: Given AC text "Update line 42 of foo.ts" / "Add field to interface X" → Then returns triggered: false.
    • Integration: Given the feat(assess): default spec phase ON, remove bug/docs auto-skip #533 fixture (AC mentioning skill file + repo containing stale BUG_LABELS/DOCS_LABELS constants) → When findTouchpoints(ac, repoRoot) runs → Then it returns paths for phase-mapper.ts and batch-executor.ts.
      Assumptions: Detection logic exposed as a callable TS module (not pure prompt) so it's unit-testable.

    AC-6: CHANGELOG entry

    Verification: Manual Test
    Scenario: CHANGELOG.md has a bullet under [Unreleased] / ### Added referencing both #552 (this) and #533 (motivating miss).


    Implementation Plan

    Phase 1: Shared heuristic + runtime module

    1. Create src/lib/heuristics/behavior-rule-detector.ts exporting:
      • detectBehaviorRule(ac: AcceptanceCriterion): { triggered: boolean; keywords: string[] } (≥2 keywords OR explicit pattern).
      • findTouchpoints(ac, repoRoot): TouchpointHit[] (greps symbols + comment patterns; returns { path, line, snippet }).
      • findSurvivingInverseSymbols(ac, repoRoot, diffPaths): TouchpointHit[] (for /qa — searches blast radius for OLD-rule survivors).
    2. Create references/behavior-rule-detection.md (source of truth: .claude/skills/) covering trigger keywords, symbol categories (constants like *_LABELS, function names, comment patterns), false-positive guards, and the feat(assess): default spec phase ON, remove bug/docs auto-skip #533 fixture.

    Phase 2: Wire /spec (proactive)

    1. In .claude/skills/spec/SKILL.md, add a new "Rule Touchpoints" subsection under Context Gathering (after the existing "Sibling-site Scan" block). It calls detectBehaviorRule per AC; on hit, runs findTouchpoints and appends results to the plan output template under a new ## Rule Touchpoints section.
    2. Link references/behavior-rule-detection.md from the new subsection.

    Phase 3: Wire /qa (reactive)

    1. In .claude/skills/qa/SKILL.md, add ### 6e. Behavior-Rule Survival Check after ### 6d. Adversarial Re-Read. Trigger: any AC for which detectBehaviorRule returns triggered: true. On survival → AC marked NOT_MET, file paths/line numbers listed.
    2. Wire into the §7 verdict gating logic so survivals block READY_FOR_MERGE. Coordinate with feat(qa): wire CHANGELOG gate into §7 verdict algorithm so it actually blocks READY_FOR_MERGE #585 (also touching §7) — likely sequential.
    3. Link references/behavior-rule-detection.md.

    Phase 4: 3-dir sync, tests, CHANGELOG

    1. Mirror Phase 1–3 edits across .claude/skills/, templates/skills/, skills/ (3 files × 3 dirs = 9 file touchpoints). Run npx tsx scripts/check-skill-sync.ts and verify 3/3.
    2. Add src/lib/heuristics/__tests__/behavior-rule-detector.test.ts covering AC-5 trigger/non-trigger fixtures + the feat(assess): default spec phase ON, remove bug/docs auto-skip #533 integration fixture. Note: tests must use the verbatim feat(assess): default spec phase ON, remove bug/docs auto-skip #533 AC text, not synthetic — see feedback_motivating_example_regression.md and feedback_synthetic_test_fixture_trap.md.
    3. CHANGELOG entry under [Unreleased] / ### Added: "Behavior-rule cross-touchpoint detection in /spec and /qa (feat(spec,qa): detect behavior-rule implementations across skill+runtime touchpoints #552, motivated by miss in feat(assess): default spec phase ON, remove bug/docs auto-skip #533)."

    Design Review

    1. Where does this logic belong? A new src/lib/heuristics/ module, not inside ac-linter.ts or scope/. Per Non-Goals, this is additive detection, not validation. Heuristics is the right neighborhood for "warns about likely problems without blocking."
    2. What's the simplest correct approach? Two pure functions (detectBehaviorRule, findTouchpoints) + a third for /qa inverse-symbol survival. Reject (a) a class wrapper — no state to encapsulate; (b) auto-fix — explicitly out of scope per Non-Goals; (c) pure prompt-only — fails AC-5's unit-test requirement.
    3. What existing pattern does this follow? Same shape as src/lib/scope/analyzer.ts (pure analysis returning structured metrics + recommendation). SKILL.md calls the module via npx tsx exactly like it already calls extractAcceptanceCriteria / lintAcceptanceCriteria / performScopeAssessment.
    4. What would a senior reviewer challenge? "Why two separate symbol-search functions instead of one parameterized by direction?" — Answer: findTouchpoints and findSurvivingInverseSymbols solve different problems. Touchpoints surfaces all implementations (helpful even when none are stale). Survival check filters to the inverse only and runs against the diff blast radius. Collapsing them obscures intent. Keep separate; share helpers.

    Conflict Risk Analysis

    Three live worktrees touch overlapping files (none have committed work yet, but coordination still matters):

    Issue File overlap Risk Mitigation
    #585 qa/SKILL.md §7 verdict algorithm High — both touch the verdict gating block Land #585 first, then rebase #552's §6e wiring on top. /assess comment for #551 already flagged the same pattern.
    #568 qa/SKILL.md + spec/SKILL.md (Skill() namespace fix) Low — namespace qualification is line-local Coordinate via /merger if both reach PR simultaneously.
    #597 spec/SKILL.md ac-linter title-body Low — different subsection Land in either order.

    #551 (also flagged by /assess) is CLOSED — no conflict.


    Feature Quality Planning

    All standard checks pass. Notable:

    • Performance budget (per Risks in issue): /qa runtime adds one grep pass per behavior-rule AC. Short-circuit when detectBehaviorRule returns 0 hits across all ACs. Document the budget in references/behavior-rule-detection.md.
    • False-positive tuning hook: Trigger threshold (≥2 keywords) and keyword set must be tunable in the reference doc, not hardcoded in TS. Recommend exporting the keyword list from the doc via a small parser, OR keeping the source-of-truth in TS and citing it from the doc.

    Open Questions

    1. Where do trigger keywords live — markdown doc or TS const? Recommendation: TS const in behavior-rule-detector.ts is the source of truth; the reference doc cites it. Reason: AC-5 unit-tests need them stable; doc can drift. Impact if wrong: keyword tuning becomes a code change instead of a doc change.
    2. Should findSurvivingInverseSymbols scan the whole repo or just the diff blast radius? Recommendation: diff blast radius (changed files + their importers, 1 hop). Reason: cheaper and matches the AC-2 "diff's blast radius" wording. Impact if wrong: false positives from unrelated pre-existing legacy code.
    3. Does AC-3's "link to reference doc" require a specific anchor format? Recommendation: references/behavior-rule-detection.md (relative) — match how existing skills link verification-criteria.md. Impact if wrong: cosmetic.

    Recommended Workflow

    Phases: spec → testgen → exec → qa
    Quality Loop: enabled (forced by SCOPE_WARNING; aligns with -q from /assess)
    Reasoning: AC-5 has Unit Test + Integration Test verification → testgen recommended (matches /assess). SCOPE_WARNING auto-enables -q. No UI/browser changes → no test phase.

    npx sequant run 552 -q --phases spec,testgen,exec,qa
    

    Label Review

    Current: enhancement
    Recommended: enhancement, planned
    Reason: Plan approved — add planned per skill convention. Quality Loop will auto-enable from SCOPE_WARNING (no need for an explicit quality-loop label).

    → gh issue edit 552 --add-label planned


  5. added
    planned
    on May 8, 2026
  6. admarble commented on May 8, 2026

    @admarble
    ContributorAuthor

    Test Stubs Generated

    AC Verification Happy Path Failure Paths
    AC-1 Integration Test 1 test + 2 assumption validators 4 negative/error scenarios
    AC-2 Integration Test 1 test + 2 assumption validators 5 error scenarios
    AC-3 Manual Test Checklist below Link-grep guard built into AC-1/AC-2 stubs
    AC-4 Integration Test 3 sync tests 2 failure-path tests
    AC-5 Unit + Integration 6 unit + 3 integration 6 edge/failure stubs
    AC-6 Manual Test Checklist below —

    Counts explained

    • Happy Path — positive/success test stubs
    • Failure Paths — error handling, edge case, false-positive guards

    Unit + Integration Test Stubs (AC-5, plus AC-1/AC-2 underlying coverage)

    File: src/lib/heuristics/__tests__/behavior-rule-detector.test.ts

    • AC-5 unit: detectBehaviorRule triggers on Default rule becomes X, Always include Y, Never skip Z; does NOT trigger on Update line 42 of foo.ts, Add field to interface X, or set default value to 5 (single-keyword false-positive guard); explicit always X unless Y pattern overrides the ≥2-keyword threshold.
    • AC-5 integration: findTouchpoints finds the phase-mapper.ts + batch-executor.ts short-circuit sites against the feat(assess): default spec phase ON, remove bug/docs auto-skip #533 verbatim AC text, with { path, line, snippet } shape.
    • AC-2 underlying: findSurvivingInverseSymbols flags survival inside diff blast radius, returns empty on clean diffs, scopes to changed-files + 1-hop importers, falls back to inverse English phrasing when no symbol matches.
    • Edge/failure: undefined description, case-insensitive matching, missing repoRoot, empty AC.

    ⚠ Fixture rule (per feedback_motivating_example_regression.md and feedback_synthetic_test_fixture_trap.md): the #533 fixture must use the verbatim AC text from issue #533 and a real repo snapshot containing the actual BUG_LABELS / DOCS_LABELS short-circuit. Synthetic fixtures combining markers will hide false negatives.

    Integration Test Stubs

    File: __tests__/integration/behavior-rule-spec-wiring.integration.test.ts — AC-1

    • Mirrors the existing qa-markdown-only-ci-snippet.integration.test.ts pattern: extracts the npx tsx -e snippet from .claude/skills/spec/SKILL.md verbatim and runs it. Catches drift between SKILL.md prose and the underlying TS module.
    • Assumption validators: SKILL.md links references/behavior-rule-detection.md; SKILL.md invokes findTouchpoints via npx tsx -e.
    • Negative: non-behavior AC short-circuits (no Rule Touchpoints section), set default value to 5 does not trigger.

    File: __tests__/integration/behavior-rule-qa-wiring.integration.test.ts — AC-2

    File: __tests__/integration/behavior-rule-skill-sync.integration.test.ts — AC-4

    • Runs npx tsx scripts/check-skill-sync.ts and asserts synced 3/3 for spec/SKILL.md, qa/SKILL.md, and the new behavior-rule-detection.md reference doc.
    • Failure paths: diverged mirror, missing-mirror (file in 2 of 3 dirs — the dominant failure mode per CLAUDE.md memory).

    Manual Test Checklist — AC-3 (Shared heuristic documented)

    Prerequisites

    • references/behavior-rule-detection.md exists in all 3 skill mirrors (.claude/skills/, templates/skills/, skills/)

    Verification

    • Doc covers trigger keywords (default, always, never, rule, behavior, skip)
    • Doc covers grep patterns for symbol categories (constants like *_LABELS, function names, comment patterns)
    • Doc covers false-positive guards (≥2 keyword threshold, explicit always X unless Y pattern)
    • Doc cites the feat(assess): default spec phase ON, remove bug/docs auto-skip #533 fixture (the motivating BUG_LABELS / DOCS_LABELS miss)
    • .claude/skills/spec/SKILL.md links the doc with relative path
    • .claude/skills/qa/SKILL.md links the doc with relative path
    • Both links resolve when the skill is read from any of the 3 mirror dirs
    • Performance budget documented (per /spec Risks: short-circuit when no behavior-rule ACs)

    Manual Test Checklist — AC-6 (CHANGELOG entry)

    Prerequisites

    • CHANGELOG.md is on the feature branch with the new entry

    Verification


    Files created

    • src/lib/heuristics/__tests__/behavior-rule-detector.test.ts
    • __tests__/integration/behavior-rule-spec-wiring.integration.test.ts
    • __tests__/integration/behavior-rule-qa-wiring.integration.test.ts
    • __tests__/integration/behavior-rule-skill-sync.integration.test.ts

    Next steps

    1. Run /exec 552 to implement src/lib/heuristics/behavior-rule-detector.ts and the SKILL.md wiring.
    2. Replace throw new Error(...) and the commented import line with real assertions as the implementation lands.
    3. Use the verbatim feat(assess): default spec phase ON, remove bug/docs auto-skip #533 AC text in the integration fixture — do not synthesize.
    4. Verify with npx vitest run src/lib/heuristics __tests__/integration/behavior-rule-*.

    Generated with Claude Code

  7. admarble commented on May 8, 2026

    @admarble
    ContributorAuthor

    Progress Update — /exec complete

    PR: #607

    AC Coverage

    AC Description Status Evidence
    AC-1 /spec surfaces touchpoints proactively ✅ MET .claude/skills/spec/SKILL.md:154-195 (### Rule Touchpoints (Conditional) + ## Rule Touchpoints plan-output section)
    AC-2 /qa verifies behavior at all touchpoints ✅ MET .claude/skills/qa/SKILL.md:2026-2080 (section 6e) wired into section 7 verdict via behavior_rule_survival_status (Survivors Found → AC_NOT_MET) at lines 2114, 2137
    AC-3 Shared heuristic documented ✅ MET _shared/references/behavior-rule-detection.md (158 lines: trigger keywords, threshold, symbol categories, inverse-keyword map, false-positive guards, performance budget, #533 fixture); both SKILL.md files link via ../_shared/references/behavior-rule-detection.md
    AC-4 3-dir sync ✅ MET npx tsx scripts/check-skill-sync.ts reports synced spec/SKILL.md — 3/3 match, synced qa/SKILL.md — 3/3 match, synced _shared/references/behavior-rule-detection.md — 3/3 match
    AC-5 Tests verify trigger conditions ✅ MET 19 unit tests (verbatim #533 AC text per feedback_synthetic_test_fixture_trap.md) + 23 integration tests; 42/42 passing
    AC-6 CHANGELOG entry ✅ MET [Unreleased] / ### Added references both #552 and #533

    Files Changed

    • src/lib/heuristics/behavior-rule-detector.ts (446 lines) — detectBehaviorRule, findTouchpoints, findSurvivingInverseSymbols
    • src/lib/heuristics/__tests__/behavior-rule-detector.test.ts — 19 unit tests
    • __tests__/integration/behavior-rule-spec-wiring.integration.test.ts — AC-1 wiring
    • __tests__/integration/behavior-rule-qa-wiring.integration.test.ts — AC-2 wiring with real-shape feat(assess): default spec phase ON, remove bug/docs auto-skip #533 fixture
    • __tests__/integration/behavior-rule-skill-sync.integration.test.ts — AC-4
    • {.claude,templates,skills}/skills/spec/SKILL.md — Rule Touchpoints subsection (3 mirrors)
    • {.claude,templates,skills}/skills/qa/SKILL.md — section 6e + section 7 verdict gate (3 mirrors)
    • {.claude,templates,skills}/skills/_shared/references/behavior-rule-detection.md — new reference doc (3 mirrors)
    • CHANGELOG.md — [Unreleased] / ### Added entry

    Quality Plan Alignment

    Quality Dimension Items Addressed Notes
    Performance budget 2/2 detectBehaviorRule is a cheap regex pass; findTouchpoints/findSurvivingInverseSymbols short-circuit to [] when not triggered; /qa scope bounded to diff blast radius
    False-positive tuning 2/2 Threshold (>=2 keywords) and keyword set tunable as BEHAVIOR_KEYWORDS const in TS (source of truth); doc cites it; explicit always X unless Y pattern overrides single-keyword guard
    3-dir sync 1/1 Sync script reports 3/3 for all touched files
    Test fixture rule 1/1 Unit suite uses verbatim #533 AC text (combining AC-1 + AC-2), not synthetic markers

    Test/Build/Lint Results

    • npm run build: ✅ Passes (tsc)
    • npm run lint: ✅ Passes (eslint --max-warnings 0)
    • npx vitest run src/lib/heuristics __tests__/integration/behavior-rule-: ✅ 42 passed (4 test files)

    Pre-PR Confidence Check

    • Weakest part: The findSurvivingInverseSymbols heuristic is intentionally simple — it greps the diff blast radius for inverse keywords from the INVERSE_KEYWORDS map. False positives are possible when an unrelated comment mentions an inverse term inside a changed file; the doc calls this out and the per-file cap mitigates noise. Tuning is a doc/const change, not a code refactor.
    • Coverage gaps: None for changed source files. Each of the 3 detector functions has both unit tests (against the verbatim feat(assess): default spec phase ON, remove bug/docs auto-skip #533 AC) and a SKILL.md-prompt integration test exercising the same shape of npx tsx -e invocation that production runs.

    Conflict Coordination

    Per /spec Conflict Risk Analysis, #585 was flagged as also touching qa/SKILL.md section 7. #585 has not yet landed; this PR adds behavior_rule_survival_status to the section 7 algorithm in a way that is additive (new ELSE IF branch) and should rebase cleanly when #585 lands.

    Next Steps

    1. Run /qa 552 once PR CI is green
    2. After QA approval, merge to main
  8. admarble commented on May 8, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #552

    AC Coverage

    AC Source Description Status Notes
    AC-1 Original /spec surfaces touchpoints proactively ✅ MET Rule Touchpoints (Conditional) subsection added in .claude/skills/spec/SKILL.md:154-195; emits a ## Rule Touchpoints plan section when triggered. Mirrored 3/3.
    AC-2 Original /qa verifies behavior at all touchpoints ✅ MET ### 6e. Behavior-Rule Survival Check added in .claude/skills/qa/SKILL.md:2026-2080, wired into §7 verdict algorithm via new behavior_rule_survival_status gate (Survivors Found → AC_NOT_MET). Mirrored 3/3.
    AC-3 Original Shared heuristic documented ✅ MET _shared/references/behavior-rule-detection.md (158 lines): trigger keywords, threshold rationale, symbol categories, inverse-keyword map, false-positive guards, performance budget, #533 fixture. Both SKILL.md files link via ../_shared/references/behavior-rule-detection.md.
    AC-4 Original 3-dir sync ✅ MET npx tsx scripts/check-skill-sync.ts reports synced 3/3 match for spec/SKILL.md, qa/SKILL.md, and _shared/references/behavior-rule-detection.md (verified live).
    AC-5 Original Tests verify trigger conditions ✅ MET 19 unit + 23 integration = 42/42 passing. Verbatim #533 AC text used per feedback_synthetic_test_fixture_trap.md. Triggers: Default rule becomes X, Always include Y in response payload behavior, Never skip Z. Non-triggers: Update line 42 of foo.ts, Add field to interface X, set default value to 5 (single-keyword guard). Explicit-pattern override (always X unless Y) covered.
    AC-6 Original CHANGELOG entry ✅ MET CHANGELOG.md [Unreleased] / ### Added references both #552 and #533 as motivating miss.

    Coverage: 6/6 AC items fully met
    Original ACs: 6/6 met
    Derived ACs: N/A (no derived ACs in spec plan)


    Quality Plan Verification

    Dimension Items Planned Items Addressed Status
    Performance budget 2 2 ✅ Complete (detectBehaviorRule cheap regex pass; findTouchpoints/findSurvivingInverseSymbols short-circuit on triggered: false; /qa scope bounded to diff blast radius)
    False-positive tuning 2 2 ✅ Complete (≥2-keyword threshold; explicit always X unless Y override; BEHAVIOR_KEYWORDS const is source of truth, doc cites it)
    3-dir sync 1 1 ✅ Complete
    Test fixture rule 1 1 ✅ Complete (verbatim #533 AC, no synthetic markers)

    Quality Plan Status: Complete


    CI Status

    Check State Conclusion Impact
    typecheck COMPLETED SUCCESS ✅ MET
    validate-skills COMPLETED SUCCESS ✅ MET
    validate-plugin COMPLETED SUCCESS ✅ MET
    Setup Directory Creation COMPLETED SUCCESS ✅ MET
    Hooks Validation COMPLETED SUCCESS ✅ MET
    Plugin Structure Validation COMPLETED SUCCESS ✅ MET
    build (20.x) IN_PROGRESS - ⏳ PENDING
    build (22.x) IN_PROGRESS - ⏳ PENDING

    CI Summary: 6 passed, 2 pending, 0 failed
    CI-related AC items: None (no AC asserts "CI passes"); build matrix pending does not gate verdict
    Markdown-only relaxation: N/A (diff includes TS source + integration tests)


    Quality Metrics

    Metric Value Status
    Files changed 15 OK (3-dir mirror inflates count; 5 logical files)
    Lines added +1948 OK (3-dir mirror; ~650 logical lines)
    Lines deleted 0 -
    Type issues (any) 1 (intentional unknown as string in test for undefined-defense) OK
    Deleted tests 0 OK

    Build Verification

    npm run build ✅ Passed (tsc clean exit, no output)


    Test Coverage Analysis

    Changed File Tier Has Tests? Test File
    src/lib/heuristics/behavior-rule-detector.ts Standard (heuristic; non-security) ✅ Yes src/lib/heuristics/__tests__/behavior-rule-detector.test.ts (19 unit) + 3 integration suites
    .claude/skills/spec/SKILL.md (3 mirrors) Standard (SKILL prompt) ✅ Yes __tests__/integration/behavior-rule-spec-wiring.integration.test.ts
    .claude/skills/qa/SKILL.md (3 mirrors) Standard (SKILL prompt) ✅ Yes __tests__/integration/behavior-rule-qa-wiring.integration.test.ts
    _shared/references/behavior-rule-detection.md (3 mirrors) Optional (doc) N/A Skill-sync test asserts presence in all 3 mirrors

    Coverage: 1/1 source file has direct unit coverage; SKILL.md prompt-shell boundaries covered by 3 integration suites (AC-1 wiring, AC-2 wiring, AC-4 sync). Test corpus uses verbatim #533 AC text per feedback_synthetic_test_fixture_trap.md.


    Code Review

    Strengths:

    • Clean three-function API (detectBehaviorRule, findTouchpoints, findSurvivingInverseSymbols) with each function responsible for one phase concern; rejecting the "one parameterized function" alternative is justified in the spec design review.
    • Defensive coding: undefined-description guard, missing-repoRoot guard, ENOENT-safe safeReadFile/statSync, walk-skip set for noisy dirs.
    • Per-file cap (3) + total cap (200 in findTouchpoints, 50 in findSurvivingInverseSymbols) prevents one chatty file from drowning out the rest.
    • BEHAVIOR_KEYWORDS exported as the TS source of truth, doc cites it (matches the spec Open Question recommendation).
    • INVERSE_KEYWORDS map asymmetric on purpose (asserted "always" → search "skip"/"never"/etc., not "always" itself).
    • Test files excluded from findTouchpoints walk (*.test.ts, *.spec.ts) — they implement checks, not rules.
    • Verbatim feat(assess): default spec phase ON, remove bug/docs auto-skip #533 AC text used in fixture (line 141-144 of unit test); the integration qa-wiring suite uses real-shape fixture (BUG_LABELS short-circuit in phase-mapper.ts).

    Issues:

    • None blocking.

    Suggestions (non-blocking):

    • findSurvivingInverseSymbols total cap is 50 (line 300) but documented as 200 in the reference doc's "Per-file cap (3) + total cap (200) on findTouchpoints results" — the reference doc only documents findTouchpoints caps, not findSurvivingInverseSymbols. Consider documenting the 50-survivor cap and rationale (keeps QA output readable).
    • The INVERSE_KEYWORDS map could be expressed as a typed constant that the doc parses, rather than duplicating the table in markdown — current setup is readable but two sources can drift.

    Test Quality Review

    Category Status Notes
    Behavior vs Implementation ✅ OK Tests assert on returned {path, line, snippet} shape and verbatim AC text matches; no internal state probed.
    Coverage Depth ✅ OK Happy path + 5 negative paths + 3 edge cases (empty desc, undefined desc, case-insensitive).
    Mock Hygiene ✅ OK No mocks; uses tmp-dir fixtures for filesystem boundary.
    Test Reliability ✅ OK Deterministic; tmp-dir isolated; no timing dependencies.

    Anti-Pattern Detection

    Code Patterns

    File:Line Category Pattern Suggestion
    src/lib/heuristics/behavior-rule-detector.ts:120 Code Quality description: undefined as unknown as string Intentional in test only — documents undefined-defense check. OK.

    Critical Issues: 0
    Warnings: 0

    Dependency Audit

    N/A - No package.json changes.


    Call-Site Review

    New exported functions detected: 3 (detectBehaviorRule, findTouchpoints, findSurvivingInverseSymbols)

    Function Call Sites Loop? Conditions AC Match
    detectBehaviorRule findTouchpoints (gate), findSurvivingInverseSymbols (gate); SKILL.md npx tsx -e snippets in spec/SKILL.md and qa/SKILL.md No Always called first as gate ✅ Matches AC-1 trigger logic
    findTouchpoints spec/SKILL.md npx tsx -e snippet Per-AC loop (per spec instructions) After detectBehaviorRule.triggered === true ✅ Matches AC-1
    findSurvivingInverseSymbols qa/SKILL.md npx tsx -e snippet Per-behavior-rule-AC loop After detectBehaviorRule.triggered === true ✅ Matches AC-2

    Findings:

    • All call sites correctly gate on detectBehaviorRule.triggered first (cheap short-circuit per performance budget). No unconditional calls observed.
    • The SKILL.md snippets pass process.cwd() as repoRoot. Correct under /spec and /qa invocation contexts.

    Execution Evidence

    Test Type Command Exit Code Result
    Build npm run build 0 ✅ Clean (tsc passed)
    Unit + integration npx vitest run src/lib/heuristics __tests__/integration/behavior-rule- 0 ✅ 42 passed (4 test files)
    Sync check npx tsx scripts/check-skill-sync.ts 0 ✅ synced 3/3 match for all 3 newly-touched files
    Self-dogfood: QA snippet on AC-1 npx tsx -e ... per qa/SKILL.md §6e 0 Detector triggered (6 keywords); 50 survivors found, all in new feature's own definitional documentation (see Adversarial Re-Read finding)

    Evidence status: Complete


    Skill Command Verification

    Skill files changed: 2 SKILL.md (× 3 mirrors)

    File Commands Found Verification Status
    .claude/skills/spec/SKILL.md 1 (npx tsx -e snippet) ✅ Passed (covered by behavior-rule-spec-wiring.integration.test.ts — runs the verbatim snippet)
    .claude/skills/qa/SKILL.md 1 (npx tsx -e snippet) ✅ Passed (covered by behavior-rule-qa-wiring.integration.test.ts — uses parallel snippet shape)

    Verification Status: Passed (snippets are not just syntactically valid but are run end-to-end by integration tests)


    Detection Pattern Verification

    N/A — The skill markdown changes do not add raw grep/awk/jq/sed commands or freestanding regex literals. They invoke the typed TS module via npx tsx -e, and the regex/pattern logic lives in src/lib/heuristics/behavior-rule-detector.ts covered by 19 unit tests against verbatim #533 fixture. (The keyword regex \bdefault\b etc. is in TS, not in markdown.)


    CLI Registration Verification

    N/A — No RunOptions interface or bin/cli.ts changes.


    Skill Change Review

    • Command verified: Both SKILL.md npx tsx -e snippets are exercised by their respective integration test files.
    • Fields verified: detection.triggered, detection.keywords, detection.matchedPattern, survivors[].{path,line,snippet} — all asserted in tests.
    • Patterns complete: ≥2-keyword threshold + explicit-pattern override covers reasonable variations. Edge: AC text that lists trigger keywords as part of a feature description (this very PR) self-triggers — see Adversarial Re-Read.
    • Dependencies explicit: Requires npx tsx (already a sequant runtime dep).

    Smoke Test

    Test Command Result Notes
    Detector triggers on real behavior-rule AC detectBehaviorRule on #533 verbatim text ✅ triggered: true, keywords include default, always, skip, rule
    Detector skips localized fix AC detectBehaviorRule on Update line 42 of foo.ts ✅ triggered: false
    Touchpoint enumeration finds runtime + skill sites findTouchpoints on #533 verbatim ✅ Returns phase-mapper.ts and batch-executor.ts hits
    Survival check flags OLD-rule survivors findSurvivingInverseSymbols on tmp fixture w/ legacy BUG_LABELS shortcut ✅ Returns survivor with path:line
    Survival check empty on clean diff Same with no-legacy fixture ✅ Returns []

    Smoke Test Status: Complete


    Manual Test ACs

    AC Verification Method Runtime Test Status Evidence
    AC-3 Manual Test (doc inspection + link grep) ✅ Executed Reference doc reviewed inline (158 lines); both SKILL.md files contain ../_shared/references/behavior-rule-detection.md link; sync check confirms 3/3 mirroring.
    AC-6 Manual Test (CHANGELOG inspection) ✅ Executed Diff inspected: [Unreleased] / ### Added entry references #552 + #533, includes feature description, motivation, and test reference.

    Manual Test Enforcement: 2/2 manual-test ACs verified.


    CHANGELOG Verification

    Check Status
    CHANGELOG.md exists ✅ Found
    User-facing changes ✅ Yes (feat: skill+runtime change)
    [Unreleased] entry ✅ Present under ### Added
    Entry format ✅ Valid (issue numbers #552, #533 included; describes feature, motivation, tests)

    Result: CHANGELOG requirements met


    Risk Assessment

    • Likely failure mode: The findSurvivingInverseSymbols heuristic can false-positive on definitional documentation that mentions inverse keywords (e.g., this PR's own behavior-rule-detection.md lists skip/exclude/bypass as inverse keywords for default/always). This isn't a regression on the feat(assess): default spec phase ON, remove bug/docs auto-skip #533-style use case (the primary motivation), but it's a real edge case for "feature-add ACs that describe the detector itself." The reference doc's per-file/total caps mitigate noise.
    • Not tested: No test covers the meta-recursion case (running the detector against an AC that lists the trigger keywords as part of describing the trigger condition). The current fixture is #533-style rule-flips. Would be a 5-minute test to add as a follow-up.
    • Sibling sites considered: No similar heuristic detector exists elsewhere in the codebase that this could drift with. src/lib/scope/analyzer.ts is the closest analogue (cited in spec design review as the pattern followed).
    • Sibling-line audit: Each function is well-bounded with clear scope; no adjacent call sites in src/lib/heuristics/ have the same root-cause pattern (this is a new directory).

    Adversarial Re-Read

    # Sub-prompt Finding
    1 Verbatim fixtures The #533 motivating-example fixture is used verbatim in unit tests (line 141-144 of behavior-rule-detector.test.ts) and structurally in the qa-wiring integration test (real-shape BUG_LABELS short-circuit in phase-mapper.ts). Both run on every test pass.
    2 Evidence framing All evidence claims (npm run build, vitest, check-skill-sync.ts, self-dogfood QA snippet) are post-fix validations, not bug reproductions. Build was clean before AND after; tests pass after; sync check confirms 3/3 mirroring.
    3 Process state Worktree clean at dfa3740; no uncommitted changes; PR #607 open and mergeable; build matrix pending in CI but lint/typecheck/validate-skills/validate-plugin/Hooks Validation/Plugin Structure Validation already SUCCESS.
    4 Sibling sites No cross-file siblings — this is a new heuristic directory (src/lib/heuristics/) with no prior detector to drift with. Intra-file: each function is single-call-site within itself; spec/qa SKILL.md snippets are independent invocations with the same gate logic.
    5 Out-of-scope/Non-Goals Issue body lists 3 Non-Goals: no auto-fix, not a generic linter, not modifying ac-linter/scope-assessment. All respected — the implementation is detection-only, scoped to spec/qa flow, additive (no edits to ac-linter.ts or scope/).

    Findings:

    • Meta-recursion limitation surfaced (non-blocking): When the survival check runs against feat(spec,qa): detect behavior-rule implementations across skill+runtime touchpoints #552's own AC-1 (which lists all 6 trigger keywords as part of describing the trigger condition), the detector self-fires with 50 survivors — all in the new feature's own definitional documentation (_shared/references/behavior-rule-detection.md: 30 hits, qa/SKILL.md: 20 hits). These are definitional mentions of inverse keywords, not stale OLD-rule code. The reference doc already documents per-file caps and false-positive guards but does not specifically call out this "AC describes the detector" recursion case. Recommend: small note in references/behavior-rule-detection.md flagging that ACs describing the detector itself will trip survival on the new feature's own docs (acceptable; humans can override). Track as follow-up if anyone hits it; not blocking this PR since the primary use case (feat(assess): default spec phase ON, remove bug/docs auto-skip #533-style rule-flips on additive PRs) is unaffected.

    Status: Gaps Found (recommendation only — meta-recursion edge case)


    Behavior-Rule Survival Check

    Self-dogfood note: I ran §6e against #552's own AC-1 (which describes the trigger keywords). The detector triggered (all 6 keywords present); 50 survivors returned, all in this PR's own definitional documentation (_shared/references/behavior-rule-detection.md × 30, qa/SKILL.md × 20). These are not OLD-rule survivors — they're definitional content of the new feature.

    AC Triggered? Survivors (in diff blast radius) Status
    AC-1 Yes (6 keywords) 50 hits, all in new feature's own definitional docs (no OLD rule exists) N/A — feature-additive AC, not a rule-flip
    AC-2 Yes (6 keywords) Same as AC-1 N/A — feature-additive AC, not a rule-flip
    AC-3, AC-4, AC-5, AC-6 No — N/A

    Status: N/A (this PR is a feature-add, not a rule-flip; no OLD rule to survive). Recorded as a gap in Adversarial Re-Read for follow-up tuning.


    Verdict: AC_MET_BUT_NOT_A_PLUS

    All 6 ACs literally MET with strong evidence: 42/42 tests passing (verbatim #533 fixture per feedback_synthetic_test_fixture_trap.md), tsc clean, 3-dir sync synced 3/3 match, CHANGELOG entry comprehensive and well-formatted, both SKILL.md prompt-shell boundaries covered by integration tests. The implementation respects all 3 stated Non-Goals (detection-only, scoped to spec/qa, additive) and follows the spec plan's design review (3-function API, BEHAVIOR_KEYWORDS as TS source of truth, asymmetric INVERSE_KEYWORDS map).

    Why not READY_FOR_MERGE: Adversarial re-read surfaced a non-blocking meta-recursion edge case — when the survival check is run against #552's own AC-1/AC-2 (which list the 6 trigger keywords as the keyword definition), it self-fires with 50 survivors, all in the new feature's own definitional documentation. The reference doc's existing per-file/total caps mitigate noise but don't specifically call out this case. Recommend a small follow-up note in references/behavior-rule-detection.md flagging that ACs describing the detector itself will trip survival on its own docs. Not blocking — the primary use case (#533-style rule-flips on additive PRs) is unaffected and the cap of 50 prevents runaway output.

    Pending build matrix CI: build (20.x) and build (22.x) are still IN_PROGRESS at QA time. Local tsc passes clean. No AC asserts "CI passes," so this does not gate the verdict.

    Documentation

    Next Steps

    1. Optional follow-up (non-blocking): Add a 1-2 sentence note in references/behavior-rule-detection.md documenting the meta-recursion limitation — when an AC enumerates the 6 trigger keywords as part of describing the detector trigger condition, the survival check self-fires on the new feature's own definitional documentation. The per-file/total caps already mitigate noise, but a docs callout would prevent confusion if anyone re-runs /qa against this PR.
    2. Wait for build matrix CI before merge (already 6/8 checks SUCCESS, 2 still IN_PROGRESS).
    3. Documentation: Run /docs 552 if any user-facing skill behavior change requires admin-facing documentation updates beyond CHANGELOG (likely N/A — skill-internal change).
  9. added
    needs-improvement
    on May 8, 2026
  10. added 4 commits that reference this issue on May 9, 2026
  11. admarble commented on May 11, 2026

    @admarble
    ContributorAuthor

    Documentation Generated

    File: docs/features/behavior-rule-detection.md

    Sections Included

    • Trigger conditions (>= 2 behavior keywords OR explicit pattern; examples of triggering vs non-triggering ACs)
    • /spec output — new "Rule Touchpoints" table inserted between Implementation Plan and Design Review
    • /qa output — new "Behavior-Rule Survival Check" section + status semantics (Clean / Survivors Found / N/A) + verdict floor at AC_NOT_MET
    • Motivating example (issue feat(assess): default spec phase ON, remove bug/docs auto-skip #533 miss)
    • Behavior expectations (no new flags, cheap when not applicable, detection-only)
    • Reference to behavior-rule-detector.ts API and the shared reference doc
    • Troubleshooting (no touchpoints section when expected, intentional survivors, perceived cost)

    Next Steps

    1. Review for accuracy against shipped behavior
    2. Merge to main alongside the next release notes

    Ready to merge.

  12. added a commit that references this issue on Jul 16, 2026
  13. added 2 commits that reference this issue on Jul 28, 2026
  14. added a commit that references this issue on Sep 9, 2026
  15. added 2 commits that reference this issue on Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementneeds-improvementplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions