Skip to content

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

Merged
admarble merged 6 commits into
mainfrom
feature/552-feat-spec-qa-detect-behavior-rule-implementations-
May 9, 2026
Merged

admarble merged 6 commits into
mainfrom
feature/552-feat-spec-qa-detect-behavior-rule-implementations-

Conversation

@admarble

@admarble admarble commented May 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds shared heuristic in src/lib/heuristics/behavior-rule-detector.ts exporting detectBehaviorRule, findTouchpoints, and findSurvivingInverseSymbols — gates expensive grep passes on a cheap keyword check (>=2 from default | always | never | rule | behavior | skip OR explicit pattern like always X unless Y).
  • Wires /spec (proactive Rule Touchpoints under Context Gathering) and /qa (reactive section 6e survival check, gated through section 7 verdict via new behavior_rule_survival_status).
  • Shared reference doc at _shared/references/behavior-rule-detection.md, mirrored across .claude/skills/, templates/skills/, and skills/ (sync script reports 3/3 for touched files).

Motivation

Issue #533 ("default /assess spec phase ON, remove bug/docs auto-skip") was the motivating miss: /spec scoped the work to a single assess/SKILL.md file, /exec implemented it, and /qa returned READY_FOR_MERGE — but the runtime CLI's BUG_LABELS/DOCS_LABELS short-circuit in phase-mapper.ts and batch-executor.ts survived and was caught only by manual user follow-up. This PR adds the cross-touchpoint detection that would have surfaced 90% of those misses in one pass.

AC Verification

AC Description Status Evidence
AC-1 /spec surfaces touchpoints proactively ✅ Implemented .claude/skills/spec/SKILL.md:154-195 (Rule Touchpoints subsection + plan output template)
AC-2 /qa verifies behavior at all touchpoints ✅ Implemented .claude/skills/qa/SKILL.md:2026-2080 (section 6e) + section 7 wiring at lines 2114, 2137
AC-3 Shared heuristic documented ✅ Implemented _shared/references/behavior-rule-detection.md, linked from both SKILL.md files via ../_shared/references/behavior-rule-detection.md
AC-4 3-dir sync ✅ Implemented npx tsx scripts/check-skill-sync.ts reports synced 3/3 match for spec/SKILL.md, qa/SKILL.md, _shared/references/behavior-rule-detection.md
AC-5 Tests verify trigger conditions ✅ Implemented 19 unit tests in src/lib/heuristics/__tests__/behavior-rule-detector.test.ts (uses verbatim #533 AC text per feedback_synthetic_test_fixture_trap.md + feedback_motivating_example_regression.md) + 23 integration tests in __tests__/integration/behavior-rule-*.integration.test.ts. 42 tests total, all passing.
AC-6 CHANGELOG entry ✅ Implemented CHANGELOG.md [Unreleased] / Added, references both #552 and #533

Quality Plan Alignment

Quality Dimension Items Addressed Notes
Performance budget 1/1 Both detectors short-circuit when detectBehaviorRule returns triggered: false; /qa scope bounded to diff blast radius
False-positive tuning 1/1 Threshold (>=2 keywords) and keyword set tunable in BEHAVIOR_KEYWORDS const; doc cites the source of truth
3-dir sync 1/1 Script reports synced 3/3 for all touched files

Test plan

  • npm run build — passes
  • npm run lint — passes
  • npx vitest run src/lib/heuristics __tests__/integration/behavior-rule- — 42/42 passing
  • npx tsx scripts/check-skill-sync.ts — touched files report synced 3/3 match
  • Manual: invoke /spec on a behavior-rule issue and verify the new "Rule Touchpoints" section appears in the plan output
  • Manual: invoke /qa on a feature branch where the OLD-rule symbol survives in the diff and verify section 6e flags AC NOT_MET

Closes #552

… touchpoints

Adds shared heuristic at src/lib/heuristics/behavior-rule-detector.ts:
- detectBehaviorRule(ac) — cheap keyword gate (>=2 from default|always|
  never|rule|behavior|skip OR explicit pattern like "always X unless Y")
- findTouchpoints(ac, repoRoot) — proactive enumeration for /spec
- findSurvivingInverseSymbols(ac, repoRoot, diffPaths) — reactive scan
  for OLD-rule survivors inside the diff blast radius for /qa

Wires into:
- /spec SKILL.md: new "Rule Touchpoints (Conditional)" subsection under
  Context Gathering, plus a "## Rule Touchpoints" plan output section.
- /qa SKILL.md: new section 6e "Behavior-Rule Survival Check" between
  6d (Adversarial Re-Read) and section 7 (Verdict). Wired into the
  section 7 verdict algorithm via behavior_rule_survival_status gate
  (Survivors Found -> AC_NOT_MET).

Shared reference doc at _shared/references/behavior-rule-detection.md
documents trigger keywords, threshold, symbol categories, inverse-keyword
map, false-positive guards, and the performance budget. Both /spec and
/qa SKILL.md files link it via ../_shared/references/.

Mirrored across .claude/skills/, templates/skills/, and skills/ — sync
script reports 3/3 for all touched files.

Tests: 19 unit cases (verbatim #533 AC text, no synthetic markers, per
feedback_synthetic_test_fixture_trap.md) + integration suites for /spec
wiring, /qa wiring, and 3-dir sync (42 tests total, all passing).

Motivated by miss in #533 ("default /assess spec phase ON, remove
bug/docs auto-skip"), where /spec scoped the work to a single SKILL.md,
/exec implemented it, and /qa returned READY_FOR_MERGE while the runtime
CLI's BUG_LABELS/DOCS_LABELS short-circuit in phase-mapper.ts and
batch-executor.ts survived — caught only by manual user follow-up.

Closes #552
admarble added 5 commits May 9, 2026 10:59
Gap 1: AC-5 literal "Always include Y" did not trigger.
The ≥2-keyword threshold rejected the literal AC-5 example strings from
the issue body. The unit test silently augmented the fixture to "Always
include Y in response payload behavior" to pass — a literal AC violation
per feedback_qa_ac_literal.md. Add three case-sensitive imperative-opener
patterns to EXPLICIT_PATTERNS so capitalized "Always|Never|Default <verb>"
at the start of an AC triggers with a single keyword. Add verbatim-string
unit tests covering all three AC-5 examples plus a guard that lowercase
prose ("the system always includes Y") does NOT self-trigger.

Gap 2: TOUCHPOINT_ROOTS missed the recurring CLI-wiring drift site.
Scope was limited to src/lib + .claude/skills. From CLAUDE.md memory:
"CLI wiring gap: Adding a field to RunOptions + runtime check is NOT
enough — must also register in bin/cli.ts." A behavior rule about a CLI
default would land in skill code while .option() registrations in
bin/cli.ts went stale — exactly the failure mode #533 surfaced. Add bin
and src/commands to TOUCHPOINT_ROOTS and add a tmp-dir test that builds
a fixture with bin/cli.ts + src/commands/run.ts + a backticked symbol in
the AC, then asserts both paths appear in findTouchpoints output.

Bonus: fix JSDoc cap drift on findTouchpoints — comment said "capped at
50" but TOTAL_CAP = 200.

Reference doc updated across all 3 mirrors (.claude/skills, templates/
skills, skills) to document the new explicit patterns and expanded scan
scope. check-skill-sync.ts reports synced 3/3 for behavior-rule-
detection.md.

Tests: 47/47 passing (was 42/42; +5 new). Build clean. Lint clean.
…-qa-detect-behavior-rule-implementations-

# Conflicts:
#	.claude/skills/qa/SKILL.md
#	CHANGELOG.md
#	skills/qa/SKILL.md
#	templates/skills/qa/SKILL.md
…st, meta-recursion docs

Round 2 of the adversarial review on PR #607. Round 1 (bf8a4fc) closed the
literal AC-5 divergence, the CLI-wiring scope gap, and the JSDoc cap drift;
this round closes the remaining material gaps surfaced in the same review.

Gap 3: Inflection-blind keyword regex.
`\bdefault\b` missed `defaults`/`defaulted`/`defaulting`; `\bskip\b` missed
`skipping`/`skipped`; `\bbehavior\b` missed `behaviors`/`behavioral`. Real
ACs use these forms — empirical: "The system defaults to true" → triggered:
false. Add `KEYWORD_REGEXES` map mirroring the stem-aware pattern landed by
#597 in `ac-linter.ts`. Word boundaries preserved so the camelCase
identifier `defaultValue` does NOT trigger. Three new unit tests cover the
positive cases and the boundary guard.

Gap 5: Common-word noise in INVERSE_KEYWORDS.
QA's self-dogfood pass on #607 returned 50 survivors entirely from
definitional documentation because `INVERSE_KEYWORDS["skip"]` and
`["never"]` listed `include`, `run`, `auto`, `old`, `previous` — words that
appear in any English prose. Two complementary fixes: (1) prune those
high-noise words from the map; (2) add a runtime guard in
`deriveInverseTerms` that drops any term in COMMON_WORDS (defense for
future tuners). New unit test asserts a fixture line containing all five
pruned words yields zero survivors.

Polish:
- Promote hardcoded `50` cap on `findSurvivingInverseSymbols` to named
  const `SURVIVOR_TOTAL_CAP` with documented rationale.
- Reference doc updated across 3 mirrors: keyword table now includes
  inflection columns, inverse-keyword table reflects pruned values,
  performance-budget section documents both caps, new "Known limitations"
  subsection captures the meta-recursion edge case QA flagged in its
  self-dogfood pass.
- Tuning checklist in reference doc now lists `KEYWORD_REGEXES` and
  `SURVIVOR_TOTAL_CAP` as tunable surfaces.

Tests: 51/51 passing (was 47/47; +4). Build clean. Lint clean.
check-skill-sync.ts reports synced 3/3 for behavior-rule-detection.md.
Add a one-line breadcrumb under "Known limitations" in the behavior-rule
detection reference doc (3 mirrors). Captures the inverse-English-phrase
fallback that the issue body's AC-2 risk callout flagged as a future
layer, without committing to build it. If a real /qa miss surfaces where
the inverse-keyword pass isn't enough, file a follow-up issue with the
concrete fixture rather than pre-emptively building NL-phrase derivation.
…-qa-detect-behavior-rule-implementations-

# Conflicts:
#	.claude/skills/qa/SKILL.md
#	skills/qa/SKILL.md
#	templates/skills/qa/SKILL.md
@admarble
admarble merged commit 322d616 into main May 9, 2026
8 checks passed
@admarble
admarble deleted the feature/552-feat-spec-qa-detect-behavior-rule-implementations- branch May 9, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant