# ios-coding-standard: resolve and scan detail

<!-- toc -->
- [Phase 2](#phase-2)
- [Phase 3](#phase-3)
- [Verification reality](#verification-reality)
<!-- /toc -->

Read by `/multi-agent:ios-coding-standard` at the start of Phase 2 and again
before Phase 3. The rules themselves live in the `ai-ios-toolkit:ios-coding-standard`
skill (`references/rules.yml`); this file is procedure only.

## Phase 2

Module roles from Phase 1 decide which dependency edges are legal: **feature** ·
**core/common** · **seam** (cross-module contracts/bridges/navigation) ·
**composition root** (legitimately knows every module).

### 2a. The registry is the standard  -  in-module prose docs are NOT consulted

The skill's `references/rules.yml` (+ a project `modules/<Module>.yml` overlay) is the single
source of truth. Module prose docs are being retired so there is one place a rule can live;
consulting them re-creates the split this command exists to remove. If such a file exists and
contradicts the registry, that is a finding against the file, not against the code.

The only in-repo inputs are **code and manifests**: sources, tests, `Package.swift`, `Info.plist`,
the specs the generator reads, and the module registry from Phase 1.

### 2b. Per-module overlay, then inference

1. **`modules/<Module>.yml`** beside the project's own config carries what code cannot state: the vocabulary
   bindings, the module's role, prohibitions that currently have **zero** instances, deliberate
   carve-outs, name locks, and the real verification command. Registry-backed, so its findings may
   be `blocking`.
   *Why prohibitions need to be written down:* inference reads dominant patterns, and a rule
   obeyed everywhere has no counter-example to infer from. A ban at 100% compliance is invisible
   to a scan  -  it survives only if the overlay states it.
2. **Repo-level rules** (root `CLAUDE.md`, contributing docs) apply to every module.
3. **The module's own dominant pattern is its de-facto convention.** Count variants per dimension;
   the minority instances are the finding. Internal consistency beats conformity to a sibling.
4. No majority (even split, single instance) → not a finding. Record an Open Question.

Findings from step 3 are tagged `inferred` and capped at **suggestion**. Only registry- or
overlay-backed rules may be `blocking`.

**When the overlay is missing**, generate a draft from code evidence, print it for confirmation,
and mark every slot it could not derive  -  a frozen UI target, a name lock, a carve-out and an
operational constraint all look like ordinary code from the outside. Do not guess them; list them
as Open Questions.

### 2c. Vocabulary

Bind each slot to a real symbol by grepping the module, then the reference module. **An unbound
slot disables its rules**  -  never invent a name, never import a sibling's.

`HandlerName` · `EventParam` · `CoordinatorType` · `ResultType` / `ErrorType` / `ErrorFactory` ·
`DIResolver` / `DIConfigurator` · `RequestModelSuffix` / `ResponseModelSuffix` / `TransportSuffix` ·
`MapperShape` · `SafeEnumProtocol` / `UnknownCase` · `CopySurface` · `AnalyticsSurface` ·
`A11yIdentifierSource` · `GeneratedServiceRoot` · `SharedComponentsDir` / `SharedEntitiesDir` ·
`MicroComponentLibrary` · `FrozenUITarget` · `DesignTokenNamespaces` · `CalendarDayHelper` ·
`LoggerAPI` · `FileHeaderShape` · `ScreenRoot` · `ScreenRoleSuffixes` · `AsyncStyle` ·
`CompositionRoot` · `SeamLayer` · `ModuleEntrySurface` · `ConcurrencyPosture` · `LintToolchain` ·
`CredentialStore` (the module's Keychain wrapper, if any).

Print the resolved table before scanning so a wrong binding is caught early.

### 2d. Sensitive-data inventory  -  required before any SEC rule runs

The `SEC-*` rules are written against the **data classes** in `references/rules.yml →
sensitive_data_classes`, never against one module's field names. Resolve the module's concrete
instances of each class: grep entities, request/response models, storage calls and analytics
events for the values the module actually handles, and map each to its class.

Produce the inventory as a table  -  **class · concrete symbols · where it enters · required
lifetime (transient / survives-restart / survives-reinstall) · where it is actually stored ·
where it is logged · where it leaves (network, analytics, pasteboard, another module)**.

The **lifetime column is the one that decides SEC-01**, and it is filled by walking
`references/rules.yml → persistence_decision`, not by looking at what the code currently does. Compare it
against the storage column and report both mismatches:
- required transient but persisted anywhere (including the Keychain) → **over-persistence**;
- required to survive a restart but stored outside the Keychain → **under-protection**.

Then generate the SEC lint patterns *from this inventory*, so the checks match this module's real
vocabulary. A class with no instance here yields no finding; a symbol you cannot classify, or one
whose required lifetime nobody can state, is an Open Question, not a silent pass.

This table is a deliverable in its own right, independent of whether any violation is found.


## Phase 3

### Coverage gate  -  on disk, not in memory

Before scanning, write `.<module>-audit-coverage.tsv` to the scratch dir: one row per target
(every screen under `ScreenRoot`, every shared component, every entity, every file in every
target) with columns `path · status · rules-applied`. Mark rows as you go.

- Each target is **audited** or **explicitly skipped with a reason** (generated, fixture,
  vendored). No third state.
- **The run is incomplete while any row is unmarked**  -  and the file, not a claim, is the proof.
  Chunk the module if it is too large for one pass; the checklist survives a context reset.
- No sampling. A partial audit reported as complete certifies the unscanned screens as clean.

### Grep hygiene

Registry `mechanism` patterns are line-based and match doc comments. Filter
`^[[:space:]]*//`  -  BSD grep does not understand `\s`, so a `\s*//` filter silently lets `/// ...`
through  -  then open each surviving hit and confirm it is real code. Report pre-filter and
post-verification counts separately; a table padded with comment matches destroys trust.

### Judgement rules need evidence, not assertion

For any rule marked `enforcement: judgement`, a finding must carry the measurement its `check`
names  -  a reference count, a call-site count, a consumer count, a file list. **No count, no
finding.** This is what keeps a subjective rule from becoming an opinion.

Every judgement rule has a worked ✗/✓ pair in `EXAMPLES.md`, keyed by ID. Cite it in the finding's
proposed fix rather than re-describing the shape  -  the developer applying the fix should be
reading the same picture the audit used.

### Module-specific overrides

The module's own docs win over the registry, including where they contradict a sibling module.
Never apply one module's dialect to another. List every override honoured, so the reader sees why
a registry rule was not raised.

## Verification reality

Verification reality is per-module - establish it, do not assume it. Some
targets cannot be compiled from the CLI (asset symbol generation, UIKit-dependent
packages, a dependency failing earlier in the graph); there, verification is
Xcode and a manifest dump validates the manifest only. Never trust a piped
build's exit code - a pipe reports the tail's status. Record the module's actual
verification command in the plan.
