$npx -y skills add Borda/AI-Rig --skill distillOne-time snapshot extracting patterns from work history and accumulated lessons, distills into concrete improvements — new agent/skill suggestions, memory pruning, consolidating lessons into rules/agent updates, or performing bin/ extraction from /audit --efficiency candidates. R
| 1 | <objective> |
| 2 | |
| 3 | Analyze how Claude Code is used and surface concrete improvements — new agents/skills to reduce repetition, or consolidate lessons into governance files (rules, agent instructions, skill updates) — without duplicating what exists. |
| 4 | |
| 5 | NOT for single-file edits or quality checks — use `/foundry:audit` for config quality checks. |
| 6 | NOT for audit-only scan for extraction candidates (use `/foundry:audit --efficiency` instead of `distill executables` for detection-only). |
| 7 | |
| 8 | </objective> |
| 9 | |
| 10 | <inputs> |
| 11 | |
| 12 | - **$ARGUMENTS**: optional. Modes: |
| 13 | - Omitted — analyze existing patterns and agents; generate suggestions proactively. |
| 14 | - `prune [--eager]` — evaluate project memory file for stale, redundant, or verbose entries. Default: advisory diff + apply prompt. `--eager`: score every entry (Usage likelihood × Impact → Tier P0/P1/P2), print full scored table with `#` column, let user select by tier or item numbers, delegate edits to `foundry:curator`. |
| 15 | - `memory [--eager]` — read `.notes/lessons.md` and memory feedback files, distill recurring patterns into proposed rule files, agent instruction updates, and skill workflow changes. `--eager`: include Pattern count, Strength, and Tier columns in proposal table; let user select clusters to promote by tier or item numbers; delegate writes to `foundry:curator`. |
| 16 | - `external <source> [--eager]` — analyse external plugin, skill, or agentic resource and produce structured adoption proposal. `<source>` is URL, file path, or local directory. `--eager`: lower adoption bar — recommend partial adoption even for single useful components. |
| 17 | - `executables [--eager] [<run-dir-or-report-path>]` — perform bin/ extraction from `/foundry:audit --efficiency` Check 33 candidates. Auto-detects latest run dir under `.reports/audit/`; pass optional path to target a specific run dir or report file. Runs inline Check 33 scan when no report exists. Default gates on HIGH/MEDIUM verdict. `--eager`: also surface LOW verdict clusters as extraction candidates. Spawns `foundry:sw-engineer` per cluster. Skip to **Mode: Executables Extraction** below. |
| 18 | - `[--eager] <recurring task description>` — use description as context when generating suggestions. `--eager`: lower frequency threshold from 3+ to 2+ occurrences; single high-effort occurrence also qualifies. |
| 19 | - `--project` — in `prune` and `memory` modes, show an interactive project picker: enumerate all slugs under `~/.claude/projects/*/memory/` with MEMORY.md size in tokens, then let user select which project(s) to operate on. Omit to operate across **all** projects automatically. Has no effect on other modes. |
| 20 | |
| 21 | </inputs> |
| 22 | |
| 23 | <compaction> |
| 24 | Key boundary 1: end of Step 2 frequency heuristics (default mode only — prune/memory/external/executables exit early), before Step 3 gap analysis. |
| 25 | Preserve at boundary 1: EAGER flag, ARGUMENTS (stripped), no run-dir (default mode is stateless). |
| 26 | Terminal paths: end of Step 5 report (default mode); end of Memory Pruning mode (both eager and standard branches). |
| 27 | </compaction> |
| 28 | |
| 29 | <workflow> |
| 30 | |
| 31 | **Task hygiene**: load and follow the protocol below. |
| 32 | ```bash |
| 33 | # loads: compaction-contract.md |
| 34 | # audit-skip: resilience-replication |
| 35 | _FS=$(python "${CLAUDE_PLUGIN_ROOT:-plugins/cc_foundry}/bin/resolve_shared_path.py" foundry skills/_shared 2>/dev/null || echo "plugins/cc_foundry/skills/_shared") # timeout: 5000 |
| 36 | cat "$_FS/task-hygiene.md" |
| 37 | ``` |
| 38 | |
| 39 | ```bash |
| 40 | export CSID="${CLAUDE_CODE_SESSION_ID:-$PPID}" |
| 41 | KEEP_ITEMS="" |
| 42 | if [[ "$ARGUMENTS" =~ --keep[[:space:]]\"([^\"]+)\" ]]; then |
| 43 | KEEP_ITEMS="${BASH_REMATCH[1]}" |
| 44 | fi |
| 45 | ARGUMENTS=$(echo "$ARGUMENTS" | sed 's/--keep "[^"]*"//g') |
| 46 | rm -f .temp/state/skill-contract.md # clear stale contract (compaction-contract.md §Lifecycle) # timeout: 5000 |
| 47 | mkdir -p "${TMPDIR:-/tmp}/distill-state-${CSID}" |
| 48 | echo "$KEEP_ITEMS" > "${TMPDIR:-/tmp}/distill-state-${CSID}/keep-items" |
| 49 | EAGER=false |
| 50 | [[ "$ARGUMENTS" == *"--eager"* ]] && EAGER=true |
| 51 | ARGUMENTS=$(echo "$ARGUMENTS" | sed 's/--eager//g' | xargs) # timeout: 3000 |
| 52 | echo "EAGER=$EAGER" # shell vars don't persist across Bash calls — read from stdout |
| 53 | echo "ARGUMENTS_STRIPPED=$ARGUMENTS" |
| 54 | ``` |
| 55 | |
| 56 | > **Note**: `EAGER` and stripped `ARGUMENTS` are set by this Bash block, but shell variable state does **not** persist across separate Bash() tool calls. After this block runs, read its |