---
name: multi-agent-ios-coding-standard
description: "Audit an iOS module against the shared coding-standard registry of stable-ID rules, produce a remediation plan, then hand off to /multi-agent. Use for a standards pass on a module, or when a review needs rule IDs rather than opinions."
user-invocable: true
argument-hint: "[module name or path]"
metadata:
  language: en
---

# multi-agent ios-coding-standard  -  Module audit → plan → dev handoff

**Input**: $ARGUMENTS  -  optionally a module name or path. When absent, Phase 1 discovers and asks.

This routine is the **procedure**. The rules live in the `ai-ios-toolkit:ios-coding-standard` skill, whose registry is
`references/rules.yml` and whose teaching doc is `references/STANDARD.md`. Load that
skill first; Claude Code loads it from the iOS stack plugin, Copilot/Codex from their local copy, so
there is one registry rather than a copy per CLI. Never restate a rule here  -  cite its ID. A rule that is not in the
registry is not a rule; if the audit needs one, propose it as `status: proposed` and say so.

Read-only + planning. This routine never edits source  -  the dev pipeline does.

**Goal.** A developer new to the repo can open any file in the module and understand it without a
guided tour, and nothing sensitive leaks on the way. Rank every finding by "does fixing this
shorten the time to first productive PR, or close a real risk?"

Render assistant-facing prose in `outputLanguage`. External payloads (branch names, plan file,
dev task) stay English.

Procedure detail, read when the phase starts:

```
$HOME/.claude/multi-agent-refs/ios-coding-standard/resolve-and-scan.md   (Phases 2 and 3)
$HOME/.claude/multi-agent-refs/ios-coding-standard/plan.md               (Phase 4)
```

---

## Phase 1  -  Discover and pick the module

1. Repo root via `git rev-parse --show-toplevel`.
2. **Discover module roots**  -  any directory with a `Package.swift`, a `Sources/` subtree or an
   `.xcodeproj`. Sweep the container dirs that exist (`Domains/`, `Packages/`, `Modules/`,
   `Features/`, `Core/`, `Common/`, top-level module dirs) one level deep, then two if empty.
3. Record per module: name · path · Swift files · lines · governance docs present · SPM targets.
   Keep this **module registry** for the whole run  -  `MOD-*` greps every import against it.
   Classify each module's role: **feature** · **core/common** · **seam** · **composition root**.
4. If `$ARGUMENTS` resolves to a module, skip the prompt. Otherwise `AskUserQuestion`
   (single-select, `outputLanguage`), documented modules first, each option showing file/line
   counts and `docs: yes/no`. If the list exceeds the question limit, group the smallest into an
   "other" option and ask again  -  never truncate silently.
5. Scope = the whole module's sources across all its targets, unless the user narrows it.

## Phase 2  -  Resolve what applies to THIS module

- **The registry is the standard.** `references/rules.yml` (+ a project `modules/<Module>.yml`
  overlay) is the single source of truth. **Do not read, cite, or derive rules from a module's own
  `*-CLAUDE.md`, `docs/` set or any other in-repo prose.** A file that contradicts the registry is a
  finding against the file. The only in-repo inputs are code and manifests.
- **Overlay, then inference.** Overlay- and registry-backed findings may be `blocking`; findings
  inferred from the module's dominant pattern are tagged `inferred` and capped at **suggestion**.
  No majority → Open Question, not a finding. A missing overlay gets a draft from code evidence,
  printed for confirmation, with every slot it could not derive listed as an Open Question.
- **Vocabulary.** Bind each slot to a real symbol by grepping. **An unbound slot disables its
  rules**  -  never invent a name, never import a sibling's. Print the resolved table before scanning.
- **Sensitive-data inventory, required before any SEC rule runs.** Map the module's real symbols to
  `sensitive_data_classes`; the lifetime column, filled from `persistence_decision`, decides
  SEC-01. A symbol you cannot classify is an Open Question, not a silent pass.

## Phase 3  -  Scan

Apply the rules that survived Phase 2 binding, plus the module's own `validation` gate. Tag every
finding: **rule ID · severity · source (`registry` / `doc` / `inferred`) · onboarding impact**.

- **Coverage gate on disk**: `.<module>-audit-coverage.tsv`, one row per target, each **audited**
  or **explicitly skipped with a reason**. The run is incomplete while any row is unmarked. No
  sampling.
- **Grep hygiene**: filter comment lines, confirm every hit, report pre-filter and verified counts.
- **Judgement rules**: no count, no finding; cite the `EXAMPLES.md` pair by ID.

## Phase 4  -  Produce the plan

No findings → report compliant and stop. Otherwise write
`<ModulePath>/ios-coding-standard-plan-<module>.md` (or the repo's scratch/docs dir if the module
tree must stay clean) with the 18 sections of `plan.md`, in order. Hard rules from it:

- A coverage ledger short of 100% accounted for means the plan is not deliverable.
- Behaviour changes go in a **separate group**, never inside a mechanical split commit.
- Linting is **local-only by decision**; never describe a gate that does not exist, and never imply
  the audit substitutes for the linter or the linter for a gate.

Then write the one-page onboarding summary beside the plan (`plan.md`, "Onboarding summary").
Show a concise version of the plan to the user too.

## Phase 5  -  Hand off

`AskUserQuestion` (single-select, `outputLanguage`):

| Option | What it does |
|---|---|
| `/multi-agent` | Opens a worktree; fixes on a fresh branch + PR |

Both run the whole pipeline; a standards sweep is usually already scoped, so Phase 1 has little to say and its document is short.

Invoke the chosen command with the plan file as the task input, branching off the repo's main
development branch (e.g. `chore/<module>-coding-standard`). The dev pipeline applies the fixes,
verifies, and commits only when asked. This routine ends at the handoff.

## Notes

- **Verification reality is per-module  -  establish it, do not assume it.** Never trust a piped
  build's exit code. Record the module's actual verification command in the plan
  (`resolve-and-scan.md`, "Verification reality").
- One module per run. Several modules means several runs and several plans, never one
  cross-module churn commit.
- If the audit wants a rule the registry lacks, add it to the skill's `references/rules.yml` as `status: proposed` with a
  rationale and surface it in Open Questions. Do not enforce an unregistered rule.
- No AI attribution anywhere (code, commits, PRs). Author = git identity.
