loop-generator
Generate two artifacts from a short interview: a loop instruction doc, and a loop driver shell script.
Generalized from a repo-specific skill that also generated a third artifact (a workflow-orchestrator YAML) — that part doesn't generalize since it assumed a specific internal workflow system. If your repo has an equivalent orchestrator, add that generation step back in; the interview and the two generic artifacts below don't depend on it.
Conversational mode (default)
Treat this as a conversation before a draft.
- Talk through edge cases, corner cases, and ambiguity with the human before drafting.
- If anything important is unclear, ask concise questions instead of drafting.
- Draft only after the human asks you to draft/proceed, or the conversation has already resolved the important choices and the human gives explicit draft authorization.
- Ambiguity policy: explore first. If multiple real choices remain, ask. If only one boring default remains, continue and record it under an
Assumptions note in the generated doc.
Required interview schema
Collect and resolve every field below before drafting. Don't improvise a different schema.
loop_name — short human name.
loop_slug — kebab-case slug used in generated filenames.
goal — one-sentence end state.
motivation — why the loop exists.
target_scope — what entities the loop watches (PRs, jobs, queue items, etc.).
target_discovery_command — the exact command(s) or read-only query that define the live target set right now.
target_identity_key — the field used to dedupe targets across runs.
success_criteria — exact conditions that count as success.
human_only_blockers — conditions the loop should surface once and stop retrying, not loop on forever.
evidence_sources — ordered richest-to-cheapest sources the loop must consult before making a change.
fail_condition_rule — repeated-attempt threshold and grouping key (e.g. "3 failures on the same (target, symptom) pair → stop and report, don't keep retrying").
local_proxy_command — the safest repeatable local/proxy verification command, or none.
write_mode — one of diagnostic_only (never mutate, just report), worker_owned_writes (the loop itself makes changes), or choose_each_run (ask each time).
Interview rules:
- Ask for missing
success_criteria before drafting — don't infer it from a vague goal.
- Ask for missing edge cases when
human_only_blockers, evidence_sources, fail_condition_rule, or write_mode would materially change behavior.
Before drafting, post a short resolved summary: the filled fields, any defaults taken, open questions if any remain, and a direct check like "Ready to draft?"
Loop instruction doc contract
Generate a doc with this exact section order:
Goal
Real target (what target_discovery_command actually returns, today)
Success invariants
Fail condition
Evidence sources
Local proxy
Rebuild + rerun (how the target set gets refreshed each round — never reuse a stale list)
Loop (the actual per-round procedure)
Exit conditions
Constraints
Rules:
- Make the real-world
write_mode explicit in the doc — don't bury it.
- Keep
Goal, Motivation, success rules, fail rules, and blockers concrete, not aspirational.
- Record assumptions explicitly instead of hiding them.
- Say what the live target is, how it's rebuilt each round, and how the loop dedupes it — don't hide mutable-state risk.
- If the loop will run unattended, log one row per iteration with
show-me-your-work instead of inventing a second trail format.
Driver shell script contract
The generated driver must:
- parse
--target <id> (repeatable), --state-file <path>, --skip-local-check, and --help;
- print loop context on start: cwd, branch (if applicable), and the state-file path;
- rebuild the live target set from
target_discovery_command every run — never trust a cached list from a prior round;
- dedupe the target set by
target_identity_key;
- print a repeated-failure summary keyed by
fail_condition_rule, so a stuck target is visible instead of silently retried forever;
- when
--target is passed for inspection, run any dry-run/probe command against a copy of mutable state, never the live state file;
- when
--skip-local-check is not set and local_proxy_command != none, run it and exit non-zero on failure;
- print a final reminder that loop success is defined by
write_mode, not by manual cleanup after the fact.
Safety rules:
- The inspection path must copy mutable state before any dry-run or probe command.
- Never let the driver silently widen from read-only inspection into live writes.
- If the target set comes from multiple commands, merge them, then dedupe by
target_identity_key.
Why the two-artifact split
The instruction doc is what a human (or an agent driving the loop) reads to understand intent, success/failure framing, and constraints. The driver script is what actually reruns deterministically. Keeping them separate means the doc stays reviewable prose while the script stays a real, rerunnable artifact — see principle-build-the-lever.
1---2name: loop-generator3description: Generate a reusable loop instruction doc and driver script for a recurring babysit/watch/retry task (e.g. "keep this PR merge-ready," "retry failed jobs until they pass," "watch this queue and fix what breaks"). Trigger: "loop generator", "generate a loop", or requests to build a reusable watch/retry loop.4---56# loop-generator78Generate two artifacts from a short interview: a loop instruction doc, and a loop driver shell script.910Generalized from a repo-specific skill that also generated a third artifact (a workflow-orchestrator YAML) — that part doesn't generalize since it assumed a specific internal workflow system. If your repo has an equivalent orchestrator, add that generation step back in; the interview and the two generic artifacts below don't depend on it.1112## Conversational mode (default)1314Treat this as a conversation before a draft.1516- Talk through edge cases, corner cases, and ambiguity with the human before drafting.17- If anything important is unclear, ask concise questions instead of drafting.18- Draft only after the human asks you to draft/proceed, or the conversation has already resolved the important choices and the human gives explicit draft authorization.19- Ambiguity policy: explore first. If multiple real choices remain, ask. If only one boring default remains, continue and record it under an `Assumptions` note in the generated doc.2021## Required interview schema2223Collect and resolve every field below before drafting. Don't improvise a different schema.24251. `loop_name` — short human name.262. `loop_slug` — kebab-case slug used in generated filenames.273. `goal` — one-sentence end state.284. `motivation` — why the loop exists.295. `target_scope` — what entities the loop watches (PRs, jobs, queue items, etc.).306. `target_discovery_command` — the exact command(s) or read-only query that define the live target set right now.317. `target_identity_key` — the field used to dedupe targets across runs.328. `success_criteria` — exact conditions that count as success.339. `human_only_blockers` — conditions the loop should surface once and stop retrying, not loop on forever.3410. `evidence_sources` — ordered richest-to-cheapest sources the loop must consult before making a change.3511. `fail_condition_rule` — repeated-attempt threshold and grouping key (e.g. "3 failures on the same (target, symptom) pair → stop and report, don't keep retrying").3612. `local_proxy_command` — the safest repeatable local/proxy verification command, or `none`.3713. `write_mode` — one of `diagnostic_only` (never mutate, just report), `worker_owned_writes` (the loop itself makes changes), or `choose_each_run` (ask each time).3839Interview rules:4041- Ask for missing `success_criteria` before drafting — don't infer it from a vague goal.42- Ask for missing edge cases when `human_only_blockers`, `evidence_sources`, `fail_condition_rule`, or `write_mode` would materially change behavior.4344Before drafting, post a short resolved summary: the filled fields, any defaults taken, open questions if any remain, and a direct check like "Ready to draft?"4546## Loop instruction doc contract4748Generate a doc with this exact section order:49501. `Goal`512. `Real target` (what `target_discovery_command` actually returns, today)523. `Success invariants`534. `Fail condition`545. `Evidence sources`556. `Local proxy`567. `Rebuild + rerun` (how the target set gets refreshed each round — never reuse a stale list)578. `Loop` (the actual per-round procedure)589. `Exit conditions`5910. `Constraints`6061Rules:62- Make the real-world `write_mode` explicit in the doc — don't bury it.63- Keep `Goal`, `Motivation`, success rules, fail rules, and blockers concrete, not aspirational.64- Record assumptions explicitly instead of hiding them.65- Say what the live target is, how it's rebuilt each round, and how the loop dedupes it — don't hide mutable-state risk.66- If the loop will run unattended, log one row per iteration with `show-me-your-work` instead of inventing a second trail format.6768## Driver shell script contract6970The generated driver must:7172- parse `--target <id>` (repeatable), `--state-file <path>`, `--skip-local-check`, and `--help`;73- print loop context on start: cwd, branch (if applicable), and the state-file path;74- rebuild the live target set from `target_discovery_command` every run — never trust a cached list from a prior round;75- dedupe the target set by `target_identity_key`;76- print a repeated-failure summary keyed by `fail_condition_rule`, so a stuck target is visible instead of silently retried forever;77- when `--target` is passed for inspection, run any dry-run/probe command against a **copy** of mutable state, never the live state file;78- when `--skip-local-check` is not set and `local_proxy_command != none`, run it and exit non-zero on failure;79- print a final reminder that loop success is defined by `write_mode`, not by manual cleanup after the fact.8081Safety rules:82- The inspection path must copy mutable state before any dry-run or probe command.83- Never let the driver silently widen from read-only inspection into live writes.84- If the target set comes from multiple commands, merge them, then dedupe by `target_identity_key`.8586## Why the two-artifact split8788The instruction doc is what a human (or an agent driving the loop) reads to understand intent, success/failure framing, and constraints. The driver script is what actually reruns deterministically. Keeping them separate means the doc stays reviewable prose while the script stays a real, rerunnable artifact — see `principle-build-the-lever`.