---
name: ba-audit-menu
description: >
  Audits the menu (Application / Module) of a `.smartstack/ba/` project — module
  semantics, cross-app duplicates, SmartStack Core collisions, orphans/empty,
  out-of-scope coherence (MENU-001..005). Reads the tree, writes a verdict to
  `_audit/menu.md`. Run after `/ba-create-menu` or as part of pre-dev readiness.
allowed-tools: [Read, Write, Glob, Grep]
---

# ba-audit-menu — Menu (Application / Module) audit

You audit the menu structure of a `.smartstack/ba/` project against the rules
below and write a verdict file. The rules are unchanged from the SmartStack
convention; only the I/O is file-based.

## File model — how to audit

1. **Read state**: `Glob .smartstack/ba/**/index.md` to rebuild the tree. Read
   each relevant `index.md` (label, `## Contexte`, `## Hors-périmètre`, `## Enfants`).
   The root `.smartstack/ba/index.md` carries the project-level `## Hors-périmètre`.
2. **Apply** the rules MENU-001..005 (below) at the requested scope.
3. **Write** the verdict to `_audit/menu.md` under the audited app:
   `.smartstack/ba/<APP>/_audit/menu.md` (use the audit-verdict skeleton from
   `_workflow/doc-templates.md`). Then print a 3–6 line business summary in chat.

There is no database, no `[ACTION]` envelope, no i18n label codes — the `.md`
verdict IS the record. The verdict header (`0 err` = pass) is what a downstream
gate reads.

## Scope

- **App scope** (default): audit one application — apply MENU-001..005 to every
  module under it. Don't scan sibling apps.
- **Module scope**: apply MENU-001, MENU-003, MENU-004, MENU-005 to that single
  module (skip MENU-002 — cross-app duplicates aren't a single-module concern).
- The verdict file lives at the audited app's `_audit/menu.md` either way.

## Rules

### MENU-001 — Module semantically fits its parent application
- `warn` if a module's business scope doesn't match the parent app; else `ok`.
- Decide from the menu tree only (app + module + section labels/codes). Don't use
  a hardcoded mapping — use business semantics. `PROSPECTS` under `CRM` → ok;
  `RECRUTEMENT` under `CRM` → warn (suggest the right app + reason).
- Fix: `/ba-create-menu`.

### MENU-002 — No duplicate module concept across applications
- `warn` if the same concept appears in 2+ apps (exact code OR semantic match,
  e.g. `CONTACTS` in CRM vs `CUSTOMERS` in SALES); else `ok`. Only at project /
  ≥2-sibling-app scope.
- Distinguish legitimate per-app reuse (a `SETTINGS` module per app is expected)
  from true duplication. Fix: `/ba-create-menu`.

### MENU-003 — No module duplicates SmartStack Core
- `err` on collision. Core features that must NEVER be user modules:
  Ticketing/Support/Helpdesk, Auth/SSO, Admin/Administration, Notifications,
  Workflows, Data export, Audit log. Also flag any **application** named
  `SETTINGS`/`PARAMS`/`CONFIGURATION` (config is a module, not an app).
- Case-insensitive substring match on module codes + labels. Fix: `/ba-create-menu`.

### MENU-004 — No orphan module, no empty app, no empty module
- `err`. Scoped to the audited app:
  - **orphan**: a module whose parent folder/app is missing or non-existent.
  - **empty app**: the app has zero modules.
  - **empty module**: a module has zero sections (can't expose any UI → blocks
    downstream phases).
- An empty *sibling* app is not a finding here (it's that sibling's own audit).
  Fix: `/ba-create-menu`.

### MENU-005 — No module contradicts the declared out-of-scope
- `warn` when a module's purpose contradicts an `## Hors-périmètre` declaration;
  `ok` when no contradiction (or no out-of-scope declared anywhere relevant).
- Compare each module (label + `## Contexte`) against the **project root**'s
  `## Hors-périmètre`, the **parent app**'s, and the module's own. The
  contradiction is **semantic**, not lexical (a `BILLING` module under an app
  whose out-of-scope says "la facturation est couverte ailleurs" is a hit; a mere
  shared keyword on a different function is not).
- `warn` (not `err`) — the user may have evolved the scope. Suggest: trim the
  out-of-scope, relocate, or drop the module. Fix: `/ba-create-menu`.

## Output

Write `_audit/menu.md` per the doc-templates skeleton:
- Header `# Audit menu — <APP>` + `_<date> · Verdict : <emoji> N warn · M err · K ok_`.
- `## ✅ Conforme`, `## ⚠️ Avertissements`, `## ❌ Bloquants` sections; one bullet
  per finding. For `warn`/`err`: what's wrong (offending codes **bold**), why it
  matters, and a `→` fix naming `/ba-create-menu`.
- Re-Write the whole file each run (overwrite — it's a fresh verdict).

Then a 3–6 line chat summary in the user's language — business terms, not rule
codes. If any `err`, state clearly that the menu must be fixed before moving on.

## Used by the readiness orchestrator

`/ba-audit-pre-dev` runs every dimension and aggregates the verdicts. When invoked
by it, still write `_audit/menu.md` as usual — the orchestrator reads these files.
