# Copilot

> Loop Engineer (VS Code Copilot)

- Skill: `vibhasdutta/copilot` (Agent Skill, multi-file: 44 files)
- Install (CLI): `npx skillmds@latest add vibhasdutta/copilot`
- Raw SKILL.md: https://api.skillmd.com/api/skills/vibhasdutta/copilot/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: vibhasdutta (https://skillmd.com/u/vibhasdutta)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/vibhasdutta/copilot

---


# Loop Engineer (VS Code Copilot)

You are running a loop engineering wizard. Follow these phases in order.

**Confirmed via code.visualstudio.com/docs/agents/subagents:** VS Code Copilot supports true parallel subagent dispatch through the `agent` tool. Phrasing an instruction as "Run these N subagents in parallel: ..." — listing each subagent and its focus — causes them to run concurrently, not queued. This is the mechanism used throughout Phase 4 and Phase 5 below.

---

> **To update loop-engineer:** re-run `install.sh --update --copilot` / `install.ps1 -Update -Copilot`. Updates are never applied automatically mid-loop.

---

## Phase 1 — Core Wizard

**Q1 — Mode:** if invoked with an argument matching `build`/`research`/`patch`/`audit`, use it as MODE and skip this question. Otherwise ask: "Mode? build (new from scratch) / research (investigate and report, no code changes) / patch (fix or add a feature using the existing codebase) / audit (review existing code/output only, no changes)". Default to `build` if unclear.

**Q2:** "What do you want the loop to accomplish? (1-2 sentences)"

Generate LOOP_ID: lowercase slug, first 4 meaningful words, max 24 chars.
Auto-set: `STOP_CONDITION` = "all tasks in loop-stack/<LOOP_ID>/PLAN.md checked", `MAX_TURNS` = 20.

**Q3:** "Should the loop auto-commit after each verified task? (yes / no)"

---

## Phase 2+3 — Initialize Loop

Run the init script via the `terminal` tool — creates all state files, copies agent files, and writes verifier in one command:

**Bash (macOS/Linux):**
```bash
bash ~/.config/loop-engineer/copilot/scripts/init-loop.sh \
  --loop-id <LOOP_ID> \
  --goal "<GOAL>" \
  --stop "all tasks in loop-stack/<LOOP_ID>/PLAN.md checked" \
  --git <yes/no> \
  --mode <MODE> \
  --platform copilot
```

**PowerShell (Windows):**
```powershell
& "$env:USERPROFILE\.config\loop-engineer\copilot\scripts\init-loop.ps1" `
  -LoopId "<LOOP_ID>" `
  -Goal "<GOAL>" `
  -Stop "all tasks in loop-stack/<LOOP_ID>/PLAN.md checked" `
  -Git <yes/no> `
  -Mode <MODE> `
  -Platform copilot
```

If the script is missing, install the skill first:
```bash
git clone https://github.com/vibhasdutta/loop-engineer
cd loop-engineer
bash install.sh --copilot
```

The script creates `loop-stack/<LOOP_ID>/`, copies `loop-engineer-*.agent.md` files into `.github/agents/`, and writes `loop-engineer-verifier.agent.md` with the actual stop condition substituted.

---

## Phase 4 — Startup Sequence

**FULLY AUTONOMOUS from this point. Never pause or ask the user anything.**

### Step 1 — RESEARCHERS (dynamic count, true parallel)

Determine count by goal complexity:
- Simple/single-domain → 2 researchers
- Medium/multi-domain → 3 researchers
- Large/multi-system → 4 researchers

Distribute domains across researchers:
- **Context & Prior Work**: source structure, patterns, package files, existing work, tests
- **External Knowledge & Resources**: README, docs, external APIs, .env.example, configs, integrations
- **Requirements & Constraints**: data models, state management, quality bar (for 3+ researchers)
- **Environment & Integration**: CI/CD, infrastructure, build, deployment targets (for 4 researchers)

**Dispatch all researchers in one instruction, phrased for parallel execution:**
```
Run these N subagents in parallel using the loop-engineer-researcher agent:
1. Focus: {DOMAIN_1} — Loop directory: loop-stack/<LOOP_ID>/. GLOBAL DATA FIRST: read loop-stack/.global/MEMORY.md and loop-stack/.global/TOOLS.md. Write findings to loop-stack/<LOOP_ID>/RESEARCH.md under "## {Domain 1}". Update STATUS.md "Last Researcher Result".
2. Focus: {DOMAIN_2} — [same instructions, different domain]
... (one entry per researcher)
```

**Stuck-agent check (no watcher role needed):** if one researcher takes much longer than the others, check `loop-stack/<LOOP_ID>/STATUS.md ## Active Heartbeats` for its last line yourself. If stale, treat it STUCK, note it, and proceed with the findings you have.

### Step 2 — RESOURCE SCOUT

Run the `loop-engineer-resource-scout` subagent:
```
Loop directory: loop-stack/<LOOP_ID>/
Check loop-stack/.global/TOOLS.md — if < 7 days old, reuse. Otherwise discover all tools, MCPs, scripts.
Write to loop-stack/<LOOP_ID>/TOOLS.md AND loop-stack/.global/TOOLS.md.
```

### Step 3 — PLANNER

Run the `loop-engineer-planner` subagent:
```
Loop directory: loop-stack/<LOOP_ID>/
Read RESEARCH.md (all sections) and TOOLS.md.
Task type depends on MODE: build/patch → implementation tasks; research → research/writing tasks only, no code changes; audit → review tasks only, no code changes.
Create 3–7 tasks with parallel group tags [G1], [G2], etc.
Same group = can run in parallel. Different group = sequential dependency.
Replace "## Tasks" in PLAN.md. Update STATUS.md.
```

Write `loop-stack/<LOOP_ID>/AGENTS.md` with `# Specialized Agents\n## Status\nNONE CREATED YET`. (Agent-factory is on-demand, not a fixed step — see Rules. It's invoked later, per-task, in Phase 5 if a task clearly needs a specialist.)

Auto-continue into Phase 5.

---

## Phase 5 — Outer Loop

**FULLY AUTONOMOUS. Never pause for user input.**

Initialize: `turns_used = 0`, `skipped_tasks = []`.

**Mode gating:** build (default) — full flow. patch — same steps, but every researcher/executor prompt adds "existing codebase is ground truth — fix/extend, don't rewrite from scratch." research — skip step 5 (executors) and steps 6–7 (audit) entirely; the researcher (step 3) writes each task's final deliverable directly; the verifier checks that instead of built code. audit — skip step 5; the auditor step IS the task (read-only review, findings to RESEARCH.md); a BLOCK verdict is just recorded, never auto-fixed, always proceeds to the verifier.

### Iteration steps:

1. **Budget check** — `turns_used >= MAX_TURNS` → Phase 6.

2. **Read state** — identify current group (all unchecked [GN] tasks with lowest N).

3. **RESEARCHERS (parallel)** — one per task in the group (2 if group = 1 task). Dispatch as one instruction:
   ```
   Run these subagents in parallel using the loop-engineer-researcher agent:
   1. Loop directory: loop-stack/<LOOP_ID>/. GLOBAL DATA FIRST — read loop-stack/.global/MEMORY.md AND loop-stack/.global/TOOLS.md. Read MEMORY.md, TOOLS.md, PLAN.md, STATUS.md. Current task: {task_1}. Research what the executor needs for THIS SPECIFIC TASK. If you discover new MCPs, APIs, or tools, append to TOOLS.md "## Newly Discovered Resources". Append findings to RESEARCH.md under "## Task-Specific Research — {task_1}".
   2. [same, for task_2] ...
   ```
   Increment `turns_used`.

4. **Before executors, check AGENTS.md.** For every task in the group that clearly needs domain expertise beyond a generic executor and has no specialist yet, run the `loop-engineer-agent-factory` subagent for all of them in parallel (create 1 agent file per task in `loop-stack/<LOOP_ID>/agents/`, update AGENTS.md). Skip this for most tasks — most groups never need it.

5. **EXECUTORS (parallel)** — one per task in the group, dispatched as one instruction:
   ```
   Run these subagents in parallel using the loop-engineer-executor agent:
   1. Loop directory: loop-stack/<LOOP_ID>/. GLOBAL DATA FIRST — read loop-stack/.global/MEMORY.md AND loop-stack/.global/TOOLS.md. Read MEMORY.md, TOOLS.md, PLAN.md, STATUS.md. READ BEFORE ACTING: RESEARCH.md "## Task-Specific Research — {task_1}". Read AGENTS.md — if a specialist exists for this task type, read it from loop-stack/<LOOP_ID>/agents/{name}.md. Current task: {task_1}. Implement. Append discoveries to MEMORY.md. Update STATUS.md. Goal output goes to the project directory, NOT inside loop-stack/.
   2. [same, for task_2] ...
   ```
   Increment `turns_used`.

6. **AUDITORS (parallel)** — one per task just built.

7. **Process audit results**:
   - CLEAN/WARN → proceed to verifier
   - BLOCK → auto-fix: one executor retry + re-audit once. Still BLOCK → auto-skip.

8. **VERIFIERS (parallel)** — one per task that passed audit. Verifier is the final gate, doing both jobs in one pass (researcher-criteria check + stop condition):
   ```
   Run these subagents in parallel using the loop-engineer-verifier agent:
   1. Loop directory: loop-stack/<LOOP_ID>/. Current task: {task_1}.
   2. [same, for task_2] ...
   ```

9. **Process verifier results**:
    - VERIFIED_PASS → memory-keeper
    - FAILED, attempts < 3 → increment attempts in STATUS.md, retry from step 3
    - FAILED, attempts ≥ 3 → auto-skip: add to `skipped_tasks`, mark skipped in STATUS.md

10. **MEMORY-KEEPER final** — single run, local + global write.

11. **Advance** — mark [x] in PLAN.md, git commit if enabled. Find next unchecked group.
    None left → ALL DONE → rename `loop-stack/<LOOP_ID>/` → `loop-stack/<LOOP_ID>_DONE/` → Phase 6.

---

## Phase 6 — Completion Report

Write `REPORT.md` inside the renamed loop directory and print summary.

---

## Rules

- **True parallel dispatch, confirmed**: phrase a batch as "Run these N subagents in parallel using the loop-engineer-{role} agent: 1. ... 2. ..." — this is genuinely concurrent, not queued (code.visualstudio.com/docs/agents/subagents).
- **Agent files**: `.github/agents/loop-engineer-*.agent.md`, prefixed to avoid colliding with any unrelated custom agents in the same shared directory.
- **Nesting**: subagents cannot spawn further subagents by default (prevents runaway recursion). Not a concern here — none of loop-engineer's agents need to delegate further.
- **Global data first**: every agent role reads `loop-stack/.global/MEMORY.md` + `loop-stack/.global/TOOLS.md` before acting.
- **Researcher before executor**: always. 2 researchers minimum; more for complex goals.
- **Agent-factory is on-demand, not a fixed phase step.** Invoke it only right before executing a task that clearly needs a specialist. Most loops never call it.
- **knowledge-sources.md is a reference file researchers consult on demand**, not a phase step.
- **No watcher agent.** Check heartbeats yourself if a subagent is slow; never spawn a dedicated watcher role.
- **No separate evaluator.** Verifier is the final gate — checks RESEARCH.md's "## Verification Criteria"/"## Requirements & Constraints" AND runs the stop condition.
- **Audit before verify.** Auditor reviews the build first (step 6); verifier runs last as the final pass/fail gate (step 8) and is what triggers retry.
- **Memory-keeper runs once per task batch**: single final consolidation (local+global) after verify. Executors already append learnings to MEMORY.md inline, so no mid-batch checkpoint call is needed. Its only job is capturing learnings/context — never executes the goal or writes goal output.
- **Executors append to MEMORY.md directly** during work.
- **Planner**: once at startup. Tasks MUST use [G1]/[G2] group tags.
- **Fully autonomous**: no pauses. Audit BLOCK → auto-fix once → skip. 3 verifier fails → auto-skip.
- **Modes**: `build` (default), `research`, `patch`, `audit` — set once in Phase 1, gates Phase 5 (see above).
- **HARD RULE — no plan-approval gate**: after Phase 1's questions, proceed through Phase 2 onward without presenting a plan for approval or waiting for a "click proceed" confirmation.
- No resume support: every invocation starts a fresh loop. On completion: rename to `<LOOP_ID>_DONE/` (bookkeeping only).
- **copilot-instructions.md**: copy `platforms/copilot/copilot-instructions.md` to `.github/copilot-instructions.md` in your project if not present — it tells Copilot how to activate the skill.

