# Stage 148: 60 Smells & Cures Scanner (aq148_scan_and_cure_sixty_code_smells / DB-UNIT-03)

Scans Python, JS, SQL, and config artifacts against 60 cataloged architectural smells and pairs every hit with a deterministic cure recipe.

- Atomic micro-queue: `aq148_scan_and_cure_sixty_code_smells` (visibility: `public_commons`)
- Backing database unit: `DB-UNIT-03` (`Confusion Diagnostics & Card Disambiguation Core`)
- Database cell: `queues-db.teleon.dev` (`teleon_core.agent_confusion_incidents`, `teleon_core.disambiguation_patches`, `teleon_core.negative_constraint_rules`)
- Claim row hydration: `single_self_contained_flat_task_row` (100% context inline, normalized writeback)
- Track 2 Sister queue (`SISTER-03`): `sq03-improve-confusion-queue.teleon.dev` (Discover new confusion aspects, sharpen agent consumption formatting, and automate recurring repairs.)
- Lanes: SMELL-001..060 Rules, SQL/AST/Config Scan, S125 Cure Prescribe

## Execution engines & AI Agent freedom contract

- **Deterministic (0 model calls)**: `schema_mismatch_rule_extractor_v1` (60-rule AST/SQL/regex smell detector & S125 cure lookup (0 calls))
- **Hybrid (<=1 model call)**: `contrast_pair_card_rewriter_v1`
- **AI Agent & Bot Fleet (1..6 calls)**: `multi_trace_root_cause_investigator_v1` (Surgical refactoring & regression-proof patch author)
  - Contract: **Instructions + Resources + Freedom to search for new resources and new ways not bound by instructions**

## Database invariants

- Every confusion patch must include a deterministic regression probe reproducing the prior failure.

## External & internal bot fleet actions

- Detect hot-row contention, unbounded polling, eval usage, cross-tenant cache keys, and fat monoliths
- Attach verified cure patterns and target engine slots to each finding
- Verify smell count decreases monotonically after patch application

## Sister self-tuning areas

- Add new diagnostic aspects for cross-model tool-call quirks
- Tune negative-constraint formatting density for smaller local models (Gemma 4)
- Convert recurring confusion fixes into deterministic lint code_blocks
