--- name: goal-driven-loop description: Use when the user sets a current goal with phrases like "设定当前目标为", "当前目标是", "current goal is", or "my goal is", and the task is not a trivial fix, hotfix, tweak, or quoted text --- # Goal-Driven Loop Keep the current session focused on a user-defined goal with explicit acceptance criteria. Iterate until all criteria pass, or genuine stagnation is detected. ## When to Activate **Trigger phrases (any language, semantic variants):** - Chinese: 设定当前目标为 / 当前目标是 / 把当前目标设为 / 我的目标是 - English: set current goal to / current goal is / my goal is / the goal is - Other: semantically equivalent phrasings + concrete deliverable **Do NOT activate when:** - Trigger phrase inside markdown quote (`>`) or code block, or same sentence as reported speech (he said / 他说) - Message contains trivial-task keywords: hotfix, tweak, quick fix, 修个bug, 小改 - Goal description ≤ 10 chars without architectural keywords, or agent estimates < 5 min without architectural keywords - `.agents/goal/GOAL.md` exists → extension prompts: continue / replace / abandon (10s timeout → continue) **Granularity:** Coarse (file count > 5, multi-module, architectural) → extension invokes `comet-open`. Fine (single concern, ≤ 5 files) → this skill. Fallback: if comet unavailable, auto-split into phases. ## Core Loop 1. **Initialize** — If `GOAL.md` exists, extension prompts with timed default. If no criteria provided, auto-generate (verifiability red line). Write `GOAL.md`. 2. **Execute** — Read `GOAL.md`, pick next unpassed criterion (least dependent), implement, verify, record in Progress Log. 3. **Verify** — Check each criterion against fresh evidence. Update checkboxes, iteration counter, timestamp. 4. **Loop** — All ✅ → exit. Stagnation → extension auto-injects strategy change (2x before user notification). Otherwise → step 2. 5. **Exit** — Deslop pass on modified files (failure doesn't block). Delete `GOAL.md`. Output summary. ## Acceptance Criteria Verifiability Auto-generated criteria must be verifiable. Examples: - ❌ "Implement rate limiting" → not verifiable - ✅ "Rate limiter middleware mounts on auth routes, excess requests return 429" → verifiable - ❌ "Code quality is good" → not verifiable - ✅ "Related files lint clean, typecheck passes" → verifiable Agent cannot unilaterally delete or skip criteria. Material modifications require logged reason; safe adjustments (typos, splitting compounds) may be auto-applied. ## Goal State File Path: `.agents/goal/GOAL.md` — frontmatter with `goal`, `created`, `updated`, `iteration`, `status` (in-progress | blocked | complete). Body has Acceptance Criteria (checkboxes), Progress Log (per-iteration), Blocked section. ## Error Handling See `references/error-handling.md` for retry strategy, exception classification, stagnation rules, and red flags. **Context tension:** Extension detects via `ctx.getContextUsage() > 0.8`. Auto-injects "save progress now" directive into next turn. **Mid-loop granularity upgrade:** If execution reveals the goal is more complex than estimated, extension auto-invokes `comet-open` with `GOAL.md` state. User is informed via UI notification, not asked for confirmation. **Explicit abandon:** User says "abandon / cancel / 不要了" → extension deletes `GOAL.md`, outputs brief summary, terminates.