---
name: lfo-gap-analyse
description: Invoke after every 3 completed bids OR on Rocky-typed "run gap analysis" / "audit the system" / "find what's broken in the workflow". Spawns 3 parallel sub-agents (workflow auditor + standing-context completeness + skill coverage reviewer), each citing file:line evidence. Consolidates findings into `_Internal/system-gap-audit-{date}.md` and queues all proposals to `_Internal/lessons-learned/proposals-pending.md` per CLAUDE.md §3.3 (proposals stay as proposals; Rocky triages). Self-improving system — each invocation surfaces gaps to close before the next bid.
model: claude-sonnet-4-6
phase: post-Phase-7 cadence (every-bid / every-3-bids / monthly — configurable) OR ad-hoc
invoked_by: Rocky-typed command OR `lfo-bid-lifecycle` Phase 7 close hook (cadence-gated)
preconditions:
  - orchestrator session log open OR running in audit-only mode
  - at least 1 completed bid in vault for first run; >2 for meaningful pattern detection
inputs:
  - cadence (`per-bid` | `every-3-bids` | `monthly` | `ad-hoc`)
  - scope (`full` | `workflow-only` | `standing-context-only` | `skill-coverage-only`)
  - since_date (optional — restrict to sessions/lessons after this date)
outputs:
  - `_Internal/system-gap-audit-{YYYY-MM-DD}.md` — consolidated report
  - appended proposals in `_Internal/lessons-learned/proposals-pending.md` (gap-rules / standing-context / skills / refactors)
side_effects:
  - never auto-merges into standing-context.md or gaps-pattern-library.md (per CLAUDE.md §3.3)
  - never edits SKILL.md files; proposes new skills + descriptions only
authored_by: claude-code-orchestrator
created: 2026-05-10
---

# lfo-gap-analyse

Spawn 3 parallel sub-agents to audit the orchestrator's current state. Consolidate findings. Queue proposals. Self-improving loop.

## Why this exists

The first manual run of this audit on 2026-05-10 surfaced 18 codifiable gaps (10 §13 rule candidates + 7 missing skills + 5 workflow refactors). One pass found leverage worth ~10+ Rocky touchpoints per bid. As the precedent corpus grows + new bids run, new gaps appear continuously. Codifying the audit means it runs after every N bids without Rocky asking.

The skill is the **closure on Option C** from the 2026-05-09 multi-agent direction-setting session.

## Procedure

### 1. Cadence check

Read `state.json.last_gap_analyse_at` (new field — initialise to null on first run).

- **`cadence=per-bid`:** always proceed
- **`cadence=every-3-bids`:** count bids closed in `_Internal/orchestrator-sessions/` since last_gap_analyse_at; proceed if ≥3
- **`cadence=monthly`:** proceed if (now − last_gap_analyse_at) ≥ 30 days
- **`cadence=ad-hoc`:** always proceed (Rocky-triggered)

If skipping, log "gap-analyse skipped — cadence not met" and return.

### 2. Spawn 3 parallel sub-agents

Use the Agent tool with `subagent_type=general-purpose` and `run_in_background=true`. Three independent prompts (each ~600 words; full templates below). Each sub-agent reads its slice of files + returns a markdown report.

#### Sub-agent 1 — Workflow auditor

```
You are auditing the lfcs-orchestrator workflow to find where it could be more autonomous.

Goal: minimise Rocky touchpoints (target = 1 per bid: Phase 6 send-authorisation only).
Every avoidable Rocky touchpoint is a gap.

Files:
- Codebase/lfcs-orchestrator/CLAUDE.md
- _Internal/orchestrator-sessions/session-*.md (last 5)
- _Internal/2630-gaps-log.md
- _Internal/lessons-learned/*.md
- C:/Users/mclou/lfcs-lessons-learned/*.md
- _Internal/lessons-learned/proposals-pending.md

Find:
- Repeated Rocky touchpoints (auto-decide candidates)
- Missed gap-watch fires
- Manual workarounds
- Implicit knowledge not in §13 or gaps-pattern-library
- Sequential steps that could parallelise

Output (under 2000 words): markdown report with Top 5 gaps + repeated touchpoints + missed fires + implicit knowledge + friction. Cite file:line for every claim.
```

#### Sub-agent 2 — Standing-context completeness

```
You are auditing standing-context.md §13 (auto-decision rules) for completeness against bid history.

Files:
- Codebase/lfcs-orchestrator/standards/standing-context.md
- Codebase/lfcs-orchestrator/standards/intake-gate-questions.md
- Operations/Jobs/**/Pre-Pricing-Grill*.md (8-12 files)
- Operations/Jobs/{Upcoming,Completed,Ongoing}/**/00-brief.md
- C:/Users/mclou/lfcs-lessons-learned/*.md

For each Rocky-input question pattern that recurs across bids, propose a §13 rule with: question / inputs / logic / confidence floor / default / edge cases / evidence (file:line) / risk-if-wrong $.

Look for: HC-specific defaults, site-type→scope mappings, postcode-derived facts, drawing-spec→exposure mappings, programme→adverse-weather mappings.

Output (under 2500 words): top 10 candidate rules ranked by frequency × $-impact. Cite file:line.
```

#### Sub-agent 3 — Skill coverage reviewer

```
You are auditing the orchestrator-side skills in Codebase/lfcs-orchestrator/skills/ for coverage / overlap / never-invoked.

Files:
- Codebase/lfcs-orchestrator/CLAUDE.md (§5 phase table + §7 skills index)
- Codebase/lfcs-orchestrator/skills/lfo-*/SKILL.md (all)
- _Internal/orchestrator-sessions/session-*.md (last 5 — for invocation patterns)

Find:
- Orphan workflow steps (no skill)
- Overlapping skills (duplicated logic)
- Never-invoked skills
- Missing skills (steps obviously needed)
- Description quality (auto-trigger language)
- Frontmatter completeness

Output (under 2000 words): phase coverage matrix + orphans + overlaps + never-invoked + missing skills proposed (rank by leverage) + description fixes. Cite file:line.
```

### 3. Wait for all 3 to complete

Use the parallel-agent pattern. Notifications fire as each completes.

### 4. Consolidate

Write `_Internal/system-gap-audit-{YYYY-MM-DD}.md` with:
- Top 5 highest-leverage workflow gaps (rank by Rocky-touchpoint cost)
- Missed gap-watch fires (proposed G6+ rules)
- Standing-context §13 rule proposals (top 10 ranked frequency × $-impact)
- Skill coverage gaps (orphans / overlaps / never-invoked / missing skills)
- Workflow friction (parallelisation opportunities)
- Skill description / overlap fixes
- Source sub-agent transcripts (task IDs for drill-down)

### 5. Queue proposals

Append to `_Internal/lessons-learned/proposals-pending.md`:

- Each new gap-watch rule (G6, G7, G8...) under `## Gap-watch pattern proposals`
- Each new §13 rule under `## Standing-context proposals`
- Each new skill proposal under a new `## Skill proposals` section
- Each workflow refactor under `## Workflow / lifecycle refactor proposals`

Per CLAUDE.md §3.3 — proposals stay as proposals. NEVER auto-merge.

### 6. Surface to Rocky

Use `AskUserQuestion` ONCE with summary:

> "Gap-analyse done. {N} new proposals queued ({G} gap-rules + {C} standing-context + {S} skills + {W} workflow). Top-3 highest-leverage: [list]. Open the audit report to triage, or merge top-N now?"

Allow Rocky to: (a) review the report file, (b) accept top-N proposals (orchestrator drafts diffs), (c) defer all (re-surface next cadence).

### 7. Stamp state

Update `state.json.last_gap_analyse_at = <iso-now>`.

### 8. Log

Append to orchestrator session log:
```
## Gap-analyse fired
- timestamp: {iso}
- cadence: {value}
- workflow gaps surfaced: N
- §13 rule proposals: M
- skill proposals: K
- workflow refactor proposals: J
- audit report: _Internal/system-gap-audit-{date}.md
```

## Failure modes

- **Sub-agent crash mid-run:** other 2 still complete; consolidate from those + flag the missing one. Re-run failed agent on next invocation.
- **No new sessions since last audit (cadence=monthly):** still run; proposals may be repeats — log "no new evidence; previous proposals still pending".
- **Proposals queue over 50 unresolved:** STOP queuing. Surface to Rocky for triage before adding more (per CLAUDE.md §10 / known-limits).
- **Audit conflicts with Rocky-recently-rejected proposal:** check `proposals-resolved.md` for `status: rejected` matches; suppress duplicate proposals.

## Notes

- This skill is **expensive** — 3 sub-agent calls per invocation. Cadence-gating prevents over-triggering. Default `every-3-bids` is the right balance for early-stage system.
- Output is deterministic: same input state → same proposals (modulo sub-agent stochasticity). Re-runs surface deltas.
- The skill itself is a candidate for self-audit. If a future gap-analyse run finds this skill broken, propose `lfo-gap-analyse-meta-audit`. Then we're done.
