STRΛTΛ19

Add a detector

Declare a new finding-producing check in the canonical detector catalog and wire it into the verification gate

Goal

Add a detector whose implementation, disposition, severity, and surface are all declared in one place, so it cannot end up shipped-but-unregistered or registered-but-never-built.

Before you start

  • Know DETECTOR_GATE_SCAN_ROOTS — the catalog only scans src/mcp/facade, src/core/code-intel, and packages/mcp/src. A detector-shaped export anywhere else must be declared as an out-of-scope lineage (memberCount/memberCountPattern), not left undeclared.
  • Know DETECTOR_SYMBOL_SHAPE — an exported top-level function named detect* or scan* inside a scan root is treated as a detector candidate until a declaration says otherwise. This is a name shape, not a curated list, so a false match still needs an honest not-a-detector declaration rather than a silent exemption.
  • Decide the detector's disposition up front: ships-and-runs (fires on an ordinary verify_implementation scan), ships-but-manual (real, in the bundle, reached only by naming a specific tool), declared-external (deliberately not in the plugin — needs a binary, a key, or belongs to another surface), dormant (built, not wired), or not-a-detector (matched the name shape but isn't one).

Steps

Write the detector function

Export a top-level detectYourCheck/scanYourCheck function from a file under one of the three scan roots above.

Declare it in the catalog

Add one entry to DETECTOR_CATALOG in src/mcp/facade/detector-catalog.ts. A real entry (detector-catalog.ts:249):

src/mcp/facade/detector-catalog.ts
{
  id: 'GC-01',
  label: 'Unreachable-file candidate',
  purpose:
    'Source files that nothing in the project ever loads — no import, no route, no test, no config ' +
    'reaches them — so they are candidates for deletion.',
  family: 'graph',
  technique: 'graph-reachability (mark/sweep BFS over persisted import/re-export edges)',
  implementations: [{ file: 'src/mcp/facade/gc01-graph-detector.ts', symbol: 'detectGC01Reachability' }],
  disposition: 'ships-and-runs',
  dispositionReason: '...',   // required and non-trivial for every disposition except ships-and-runs
  surface: 'Findings',
  bundle: 'facade-stdio',      // 'facade-stdio' | 'index-build-worker' | 'local-analysis-runner' | null
  findingProvider: true,
  overlaps: ['GC-02'],         // ids this conceptually overlaps with, so a duplicate never ships unnoticed
}

id must be unique across the catalog. implementations[].file/.symbol must point at a file and export that really exist — a phantom declaration fails the gate as surely as an undeclared implementation does. If disposition is ships-but-manual, manualInvocation is required: a machine-readable "how do I run this myself" string, because a manual detector nobody is told how to invoke is indistinguishable from a dormant one.

Map its severity through the finding policy

Add an entry to LOCAL_FINDING_POLICY in src/mcp/facade/local-finding-policy.ts, keyed by ${detectorId} or ${detectorId}-${subCheck} for a detector with multiple outcome shapes:

src/mcp/facade/local-finding-policy.ts
'GC-08-throw': {
  severity: 'high',
  reason:
    '`throw new Error("not implemented")` is an explicit, unambiguous author admission that the ' +
    'code path is unfinished — the strongest signal this detector can produce.',
},

severity is one of 'critical' | 'high' | 'medium' | 'low'. Every call site reads this table rather than assigning a literal severity string directly — do the same. A detector with no policy entry has no defensible reason for the severity it will report.

Provide a truth set and test precision

Before shipping, prove the rule can be falsified: a fixture with both a true positive and a case that looks like one but isn't. Test the detector's blind spots explicitly rather than only its happy path — GC-01's own catalog entry, for example, states that unresolved local-target candidates are conservatively treated as live so a false positive costs a look, not a wrongful deletion; your detector's declared evidence should carry an equivalent honesty about what it cannot resolve.

A boundary worth stating before you rely on it

.strata19/extensions/<name>/strata19-extension.json project-local manifests (src/mcp/facade/extension-loader.ts) accept a detectors contribution tier — id, title, description, severity, appliesTo globs, no code. It is schema-validated and stored with provenance today, but nothing in this build wires a contributed detector to actually fire and produce findings. The steps above — a real catalog declaration in this repository — are the only path to a detector that runs.

Verify

pnpm gate:detector-registry

These checks run against the real TypeScript AST of every scan root, not a hand-maintained list: undeclared implementation, phantom declaration, lineage drift (for out-of-scope code declared by memberCount), disposition integrity (a non-ships-and-runs disposition must carry a real reason), and ledger consistency (findingProvider: true entries must reach DECLARED_FINDING_PROVIDERS in finding-store.ts, and the ledger must contain nothing the catalog doesn't declare). Exit codes are the CI contract: 0 clean, 1 found a violation, 2 indeterminate — a 2 is never a pass, even though the process technically didn't fail on check content; it means the gate could not measure and refused to guess.

If your disposition is ships-and-runs, also confirm it actually produces a finding on a fixture that should trigger it, through strata19.verify_implementation — a catalog entry alone does not prove the detector fires correctly, only that it is honestly recorded.

If it doesn't work

  • gate:detector-registry exits 1 naming your function as undeclared. Your exported detect*/scan* symbol has no catalog entry — add one, or rename it if it isn't really a detector (and declare it not-a-detector if the name shape is a false match you want on record).
  • The gate exits 1 naming a phantom declaration. Your catalog entry points at a file or symbol that doesn't exist — a rename or delete on the implementation side without updating the catalog produces this.
  • The gate exits 2 (indeterminate). The scanner itself could not measure plausibly — never read this as clean; it means something broke the AST walk, not that your tree is fine.
  • GC-01 (or another trust-root-gated detector) reports status: indeterminate with zero findings on an installed plugin, not just yours. That specific detector requires an out-of-band trust root (STRATA19_TRUSTED_BUNDLE_SHA256 or the marketplace attestation) before it runs at all on an installed bundle — this is unrelated to whether your new detector is declared correctly.
  • You changed detector-catalog.ts but an installed host still shows the old catalog. The plugin cache is version-keyed; bump the version, rebuild, push, and reinstall — see Interface and packaging.