$npx -y skills add Borda/AI-Rig --skill runSustained metric-improvement loop with atomic commits, auto-rollback, and experiment logging. Iterates with specialist agents, commits atomically, auto-rolls back on regression. Accepts a program.md file path. Supports --resume, --team, --colab, --codex, --researcher, --architect
| 1 | <objective> |
| 2 | |
| 3 | Sustained metric-improvement loop — reads `program.md`, iterates specialist ideation agents, commits atomically, auto-rolls back on regression. For long-running automated improvement campaigns. |
| 4 | |
| 5 | NOT for: methodology validation before run (use `/research:judge`); hypothesis generation (use `research:scientist` agent); one-off feature work (use `/develop:feature`). |
| 6 | |
| 7 | </objective> |
| 8 | |
| 9 | <constants> |
| 10 | |
| 11 | Campaign mode only: |
| 12 | |
| 13 | ```yaml |
| 14 | MAX_ITERATIONS: 50 (hard cap); DEFAULT 20 when max_iterations unset in program.md; program.md may raise up to 50; values above 50 clamped to 50 with a warning |
| 15 | MAX_CODEX_RUNS: 10 (cost ceiling for --codex Phase 2c — disable Codex once exceeded) |
| 16 | STUCK_THRESHOLD: 5 consecutive discards → escalation |
| 17 | GUARD_REWORK_MAX: 2 attempts before revert |
| 18 | VERIFY_TIMEOUT_SEC: 120 (local), 300 (--colab) |
| 19 | COLAB_KNOWN_HW: H100, L4, T4, A100 |
| 20 | SUMMARY_INTERVAL: 10 iterations |
| 21 | DIMINISHING_RETURNS_WINDOW: 5 iterations < 0.5% each → warn user and suggest stopping |
| 22 | STATE_DIR: .experiments/state/<run-id>/ (timestamped dir per run — see .claude/rules/artifact-lifecycle.md) |
| 23 | SENTINEL_SLUG_FORMULA: | |
| 24 | eval "$(bash "${CLAUDE_PLUGIN_ROOT:-plugins/cc_research}/bin/git_slugs.sh")" |
| 25 | # Sentinel path: ${TMPDIR:-/tmp}/claude-commit-auth-${REPO_SLUG}-${BRANCH_SLUG} # tmpdir-exempt: user-shell-boundary |
| 26 | # Bash state is lost between tool calls — re-source git_slugs.sh at each use site; it is the only authorized slug form. |
| 27 | ``` |
| 28 | |
| 29 | <!-- Note: STATE_DIR (.experiments/state/) holds per-iteration artifacts (diary, experiments.jsonl). |
| 30 | Hypothesis pipeline outputs (hypotheses.jsonl, checkpoint.json, journal.md) go to .experiments/<run-id>/ (RUN_DIR). |
| 31 | These are two separate directories by design — see protocol.md for layout. --> |
| 32 | |
| 33 | **Agent strategy mapping** (`agent_strategy` in config → ideation agent to spawn): |
| 34 | |
| 35 | | `agent_strategy` | Specialist agent | When to use | |
| 36 | | --- | --- | --- | |
| 37 | | `auto` | heuristic | Default — infer from metric_cmd keywords | |
| 38 | | `perf` | `foundry:perf-optimizer` | latency, throughput, memory, GPU utilization | |
| 39 | | `code` | `foundry:sw-engineer` | coverage, complexity, lines, coupling | |
| 40 | | `ml` | `research:scientist` | accuracy, loss, F1, AUC, BLEU | |
| 41 | | `arch` | `foundry:solution-architect` | coupling, cohesion, modularity metrics | |
| 42 | |
| 43 | **Auto-inference keyword heuristics** (when `agent_strategy: auto` or omitted; checked against `## Goal` text AND metric command): |
| 44 | |
| 45 | **Precedence order** (first match wins; ML keywords beat test-framework keywords). ML-specific compound terms (not bare tokens) required — prevents over-triggering on `eval`/`train`/`val` as common words: |
| 46 | - contains `accuracy`, `loss` (paired with `train_loss`/`val_loss`/`eval_loss`), `f1_score`, `auc_roc`, `auroc`, `train_step`, `val_acc`, `eval_loss`, `epoch`, `gradient`, `tensor`, `overfit`, `generaliz`, `regulariz`, `validation`, `dropout`, `weight_decay`, `lr_schedule`, `cross_val`, `precision`, `recall`, OR explicit `--scientist` flag → `ml` → `research:scientist` |
| 47 | - contains `time`, `latency`, `bench`, `throughput`, `memory` → `perf` → `foundry:perf-optimizer` |
| 48 | - contains `pytest`, `coverage`, `complexity` → `code` → `foundry:sw-engineer` |
| 49 | - no keyword match → `perf` (default fallback) — **WARN**: print `⚠ No keyword match — defaulting to 'perf' strategy. If this is an ML task, set agent_strategy: ml in program.md.` Log resolved agent + reason in state.json `strategy_resolution`. |
| 50 | |
| 51 | Bare tokens `eval`, `train`, `val` (without compound suffix) do NOT trigger `ml` routing — too common in non-ML contexts (test eval scripts, training-environment configs, validator command names). |
| 52 | |
| 53 | **Stuck escalation sequence** (at STUCK_THRESHOLD consecutive discards): |
| 54 | |
| 55 | 1. Switch agent type. Rotation by current strategy: |
| 56 | |
| 57 | | Current strategy | Next strategy | Escalation agent | |
| 58 | | --- | --- | --- | |
| 59 | | `code` | `ml` | `research:scientist` | |
| 60 | | `ml` | `perf` | `foundry:perf-optimizer` | |
| 61 | | `perf` | `code` | `foundry:sw-engineer` | |
| 62 | | `arch` | `code` | `foundry:sw-engineer` (fallback `foundry:solution-architect` if sw-engineer unavailable) | |
| 63 | | `auto` | infer from resolved strategy | follow rotation row for whichever concrete strategy `auto` heuristics resolved t |