adopt
Bootstrap an existing repo for ForgeDock — triage open issues, apply labels, suggest a starter milestone, and identify first…
Analyze this repo and generate per-repo adaptive scripts from learned patterns, git history, and existing configuration
> /plugin marketplace add RapierCraftStudios/ForgeDock > /plugin install forgedock@forgedock
How it fires
How this command gets triggered: by you, by Claude, or both.
/optimizeContext preview
What this command does when you run it.
Analyze this repo and generate per-repo adaptive scripts from learned patterns, git history, and existing configuration
description: Analyze this repo and generate per-repo adaptive scripts from learned patterns, git history, and existing configuration argument-hint: "[--dry-run | --force | --no-registry]" install: extras
**Input**: $ARGUMENTS
Proactively analyze the current repository and generate `.forgedock/scripts/` entries from `forge.yaml → learned:`, git commit history, and pipeline annotations — without waiting for a correction event. This is the proactive half of the learning loop; reactive capture happens in `/work-on` Phase 1D.
**Agent model policy**: `model: "{DEFAULT_MODEL}"` — resolved from forge.yaml `agents.default_model`, else "sonnet" (standard tier). Fallback: `model: "opus"` if rate-limited. Feature gate: pass `effort` in Task/Skill spawns only on Claude Code >= 2.1.154. **NEVER use plan mode (EnterPlanMode).**
---
| Flag | Effect | |------|--------| | (none) | Full run: analyze → generate → registry → report | | `--dry-run` | Analyze and report what would be generated; write nothing to disk | | `--force` | Overwrite scripts even if confidence < 0.7 | | `--no-registry` | Skip `registry.json` update |
Parse `$ARGUMENTS` and set:
DRY_RUN = true if --dry-run present, else false FORCE = true if --force present, else false NO_REG = true if --no-registry present, else false
---
REPO_PATH=$(git rev-parse --show-toplevel 2>/dev/null || pwd) FORGE_YAML="$REPO_PATH/forge.yaml" GH_REPO=$(yq '.project.owner + "/" + .project.repo' "$FORGE_YAML" 2>/dev/null) SCRIPTS_DIR="$REPO_PATH/.forgedock/scripts" ADAPTIVE_ENABLED=$(yq '.adaptive_scripts.enabled // true' "$FORGE_YAML" 2>/dev/null || echo "true") ADAPTIVE_COMMIT=$(yq '.adaptive_scripts.commit // false' "$FORGE_YAML" 2>/dev/null || echo "false")
If `$FORGE_YAML` is missing:
STOP: forge.yaml not found. Run `npx forgedock init` to generate it, then re-run /optimize.
If `ADAPTIVE_ENABLED` is `false`:
STOP: adaptive_scripts.enabled is false in forge.yaml. Set it to true to use /optimize.
mkdir -p "$SCRIPTS_DIR"
If `.forgedock/scripts/` is not gitignored, note in the report (non-blocking).
---
Read all available signal sources. Build a `PATTERNS` map — keyed by script name, value is `{evidence, confidence, value}`.
**Confidence scale**:
LEARNED=$(yq '.learned // {}' "$FORGE_YAML" 2>/dev/null || echo '{}')
echo "Learned section: $LEARNED"Extract each known key:
LEARNED_STAGING=$(yq '.learned.branch_targets.staging // ""' "$FORGE_YAML" 2>/dev/null)
LEARNED_TEST_CMDS=$(yq '.learned.test_commands // []' "$FORGE_YAML" -o json 2>/dev/null)
LEARNED_TEST_LOCS=$(yq '.learned.test_locations // []' "$FORGE_YAML" -o json 2>/dev/null)
LEARNED_LABEL_MAP=$(yq '.learned.label_map // {}' "$FORGE_YAML" -o json 2>/dev/null)
LEARNED_COMMIT_STYLE=$(yq '.learned.commit_style // ""' "$FORGE_YAML" 2>/dev/null)For each non-empty learned key, add to PATTERNS with confidence `1.0`:
| Non-empty key | Script to generate | |---------------|--------------------| | `branch_targets.staging` | `branch-targets.sh` | | `test_commands` (non-empty array) | `run-tests.sh` | | `test_locations` (non-empty array) | `find-tests.sh` | | `label_map` (non-empty object) | `label-map.sh` | | `commit_style` | `format-commit.sh` |
cd "$REPO_PATH" # Sample last 50 commits for style analysis COMMIT_SUBJECTS=$(git log --oneline -50 --format="%s" 2>/dev/null | head -50) echo "$COMMIT_SUBJECTS"
**Detect commit style**:
CONV_COUNT=$(echo "$COMMIT_SUBJECTS" | grep -cE '^(feat|fix|docs|chore|refactor|test|style|ci|build|perf)\(' 2>/dev/null || echo 0)
CONV_SIMPLE=$(echo "$COMMIT_SUBJECTS" | grep -cE '^(feat|fix|docs|chore|refactor|test|style|ci|build|perf):' 2>/dev/null || echo 0)
TOTAL=$(echo "$COMMIT_SUBJECTS" | wc -l | tr -d ' ')
CONV_WITH_SCOPE_PCT=$(( (CONV_COUNT * 100) / (TOTAL + 1) ))
CONV_SIMPLE_PCT=$(( (CONV_SIMPLE * 100) / (TOTAL + 1) ))Determine `DETECTED_COMMIT_STYLE`:
**If `LEARNED_COMMIT_STYLE` is non-empty**: use it (confidence `1.0`), skip git analysis for this signal.
**Detect test locations** (if `LEARNED_TEST_LOCS` is empty):
# Look for test directories with actual test files
TEST_DIRS=""
for candidate in tests/ __tests__/ test/ spec/ src/__tests__/; do
COUNT=$(git ls-files "$candidate" 2>/dev/null | wc -l | tr -d ' ')
if [ "$COUNT" -gt "0" ]; then
TEST_DIRS="$TEST_DIRS $candidate"
fi
done
TEST_DIRS=$(echo "$TEST_DIRS" | xargs) # trimIf `TEST_DIRS` is non-empty and differs from the default (`tests/`): add to PATTERNS for `find-tests.sh` with confidence `0.7`.
# Read closed issues for repeated FORGE:LEARNED annotations (last 30 closed issues)
FORGE_LEARNED_BODIES=$(gh api "repos/$GH_REPO/issues?state=closed&per_page=30" \
--jq '[.[] | .number]' 2>/dev/null | jq -r '.[]' 2>/dev/null | \
while read -r n; do
gh api "repos/$GH_REPO/issues/$n/comments" \
--jq '.[] | select(.body | contains("FORGE:LEARNED")) | .body' 2>/dev/null
done | head -200)
echo "$FORGE_LEARNED_BODIES" | head -50ForgeDock — autonomous AI dev pipeline for Claude Code. GitHub as agent memory: issue in, PR out.
Bootstrap an existing repo for ForgeDock — triage open issues, apply labels, suggest a starter milestone, and identify first…
Pull production analytics from GSC, Bing Webmaster, Clarity, Umami, Cloudflare, Stripe, and GA4 — generate insights and create…
Audit agent outputs from an orchestration run — timeline analysis, stall detection, active vs idle time breakdown
Trace a production issue or pipeline failure end-to-end through GitHub artifacts, then file a detailed improvement issue to the…
Autonomous deploy loop — runs until zero open issues remain. Detects pipeline state and resumes from any position. Fully…
Guided idea-to-backlog setup for a brand-new project — interview, defaults, doubts, spike doc, validated orchestrate-ready backlog