--- name: refine description: Skills Architecture v1.6 — proof-bearing goal contract generator with three entry modes (auto-detected from arguments). FULL mode reads .claude/contexts/.md + .claude/plans/.md and runs 4-10 review lenses. BARE mode skips lens dispatch and structures a free-form description. FROM-CONTRACT mode re-compacts an existing goal contract. ALWAYS emits a predictable square-prompt directive with the same 7-section shape (CONTEXT, OBJECTIVE, SCOPE, CONSTRAINTS, ACCEPTANCE, VERIFY, STOP) so a vague input like "fix ca" never reaches the goal state — synthesis rejects vague verbs and forces binary measurable acceptance criteria paired 1:1 with verifiers. The /goal directive has a 4000-char ceiling (hard tool limit); /refine aims for the minimum viable length that preserves the contract, never pads to fill the budget. Use when to turn a plan or a loose description into a /goal contract with binary acceptance criteria paired 1:1 with verifiers, so the goal state cannot be reached by a vague claim of success. metadata: short-description: Skills Architecture v1 generated-from: plugins/*/skills/refine argument-hint: | "" [--bare] [--full ] [--lenses light|full] --- > Paths below are rooted at `${CODEX_HOME:-$HOME/.codex}/plugins/cache/kodflow/kodflow-workflow/0.0.0-re61d6d4f6f77`, where Codex installs this plugin. If that directory is missing, the plugin root is the directory two levels above this SKILL.md. the arguments @../_shared/team-mode.md # /refine — Goal Contract Generator (v1.6 — Skills Architecture) ## Directive char-cap — ceiling, not target The `/goal` tool accepts a maximum **4000-character directive string**. This is a hard runtime limit of the tool — a **ceiling**, not a goal. `/refine` treats 4000 as the **ceiling** in every mode (FULL / BARE / FROM-CONTRACT) and regardless of LIGHT/FULL lens selection. The design **target is the minimum viable length** that still preserves the contract: enough chars to bind acceptance criteria, evidence, and scope; not a single char more. `/refine` decides the length from what it has to say, never from the input shape, and never pads to hit 4000. There is no separate LIGHT ceiling. LIGHT vs FULL only affects **how many lenses run** (4 critical vs all 10), not the directive ceiling — the 4000-char cap stays uniform across both lens depths. ## Mode auto-detection (v1.6) `/refine ` detects the mode from the argument shape + disk state: ``` arg contains spaces OR > 1 word → BARE (free-form description) arg is a kebab-case-or-similar single token ├─ plans/.md + contexts/.md both exist → FULL ├─ goals/.md exists, no plan/context → FROM-CONTRACT ├─ none exist → BARE (arg is a short description) └─ ambiguous (only plan OR only context) → BARE with WARN ``` Explicit overrides for the edge cases: | Flag | Forces | |---|---| | `--bare` | BARE mode even when files exist | | `--full ` | FULL mode even if only the contract exists (re-analyze) | | `--from-contract ` | FROM-CONTRACT even if plan/context still exist | | `--slug ` | Override the auto-derived slug in BARE mode | | `--lenses light` | Run only 4 critical lenses in FULL mode | | `--lenses full` | Run all 10 lenses in FULL mode (overrides AUTO) | | `--triplet` | Force proof-triplet CONTRACT form (overrides auto form-detection) | | `--square` | Force square-prompt form (overrides auto form-detection) | | `--auto` | Default: AUTO picks light/full lens depth + form-detection (proof-triplet vs square-prompt) | ## Phase 0: Mode + slug resolution ```bash resolve_mode_and_slug() { local arg="$1" # Explicit override flags win case "$EXPLICIT_MODE" in bare) MODE=BARE; return ;; full) MODE=FULL; return ;; from-contract) MODE=FROM_CONTRACT; return ;; esac # Free-form description: spaces or >1 word if [[ "$arg" == *" "* ]] || [[ $(echo "$arg" | wc -w) -gt 1 ]]; then MODE=BARE SLUG=${USER_SLUG:-$(derive_slug "$arg")} DESCRIPTION="$arg" return fi # Single-token slug: disk decides SLUG="$arg" local PLAN=".claude/plans/$SLUG.md" local CTX=".claude/contexts/$SLUG.md" local CONTRACT=".claude/goals/$SLUG.md" if [[ -r "$PLAN" && -r "$CTX" ]]; then MODE=FULL elif [[ -r "$CONTRACT" && ! -e "$PLAN" && ! -e "$CTX" ]]; then MODE=FROM_CONTRACT elif [[ ! -e "$PLAN" && ! -e "$CTX" && ! -e "$CONTRACT" ]]; then MODE=BARE; DESCRIPTION="$arg" else MODE=BARE; DESCRIPTION="$arg" echo "WARN: ambiguous state for '$SLUG' (only plan OR only context found) — defaulting to BARE" >&2 fi } ``` ### Project documents (all modes) Read the project's documents that concern the slug (the `ok` entries of `bash "${CODEX_HOME:-$HOME/.codex}/plugins/cache/kodflow/kodflow-workflow/0.0.0-re61d6d4f6f77"/skills/docs/scripts/docs.sh compute`) and its ADRs. A directive that contradicts one carries the contradiction in `# CONSTRAINTS`, with `fichier:ligne`, and the user is told before `/goal`. ## Phase 1: AUTO lens depth — FULL mode only Read `auto.md`. AUTO picks 4-critical-lenses vs all-10 based on plan frontmatter: | Field | Type | Notes | |---|---|---| | `risk` | string | `low` / `medium` / `high` / `critical` | | `loc_estimate_max` | number | numeric upper bound on LOC change | | `touches_public_api` | bool | true → all 10 | | `touches_security_surface` | bool | true → all 10 | | `touches_dev_infra` | bool | true → all 10 | Any missing or non-numeric field defaults to **all 10**. The char-cap is 4000 in both cases; lens depth is the only thing that varies. BARE and FROM-CONTRACT skip this phase entirely (no lens analysis). ## Phase 2: Dispatch lenses — FULL mode only Read `dispatch.md`. For each lens, call `route-agent.sh --skill /refine --phase lens-N-`. On exit code 20-31, fall back to the static lens map in `refine-static-fallback.sh` (fix #17 — critical lenses must run regardless of router state). ## Phase 3: Synthesize (all modes) Read `synthesis.md`. - **FULL**: collect lens findings → dedup → rank → render → refine-pipeline → square-prompt-validate → compact-to-minimum → square-prompt-validate. - **BARE**: apply WHAT/WHY/WHERE/HOW/DONE template → render → refine-pipeline → square-prompt-validate → compact-to-minimum → square-prompt-validate. - **FROM-CONTRACT**: read contract → extract → render → refine-pipeline → square-prompt-validate → compact-to-minimum → square-prompt-validate. Every mode goes through `square-prompt-validate` TWICE — once before compaction (diagnostic) and once after (final guarantee). The directive is ALWAYS the same 7-section square-prompt shape. Vague verbs like "fix", "improve", or "make it work" are rejected **inside the `# ACCEPTANCE` section only** (CONTEXT / OBJECTIVE / SCOPE / etc. may freely use them in prose) and replaced with a visible `- [ ] ` sentinel so the user notices the gap before running `/goal`. Output is bounded by the **4000-char ceiling**; the natural target is the minimum viable length given the content. There is no padding. ## Phase 4: Emit (all modes) Read `render.md`. Writes: - **FULL**: `.claude/goals/.md` (proof triplets) + runtime directive. - **BARE**: `.claude/goals/.md` skeleton (WHAT/WHY/WHERE/HOW/DONE) + runtime directive. - **FROM-CONTRACT**: runtime directive only (input file is never overwritten). The runtime directive is printed for the user to copy into `/goal`. There is no runtime state file (the `/goal` builtin loops on the directive condition directly). ## Next step (manual, no auto-chain) `/refine` ends by printing a textual suggestion of the form: ``` Suggested next step: /goal ``` There is **no auto-chain** into another skill — the user remains the trigger. Run `/goal ` to enter goal iteration once the contract on disk has been reviewed. ## Arguments | Pattern | Action | |---------|--------| | `` | Auto-detect mode from disk state (FULL / FROM-CONTRACT / BARE) | | `""` | Force BARE — text contains spaces | | `--bare` | Force BARE even when files exist | | `--full ` | Force FULL — re-analyze from plan even if contract exists | | `--from-contract ` | Force FROM-CONTRACT — re-compact contract | | `--slug ` | Override auto-derived slug in BARE mode | | `--lenses light` | FULL mode: only 4 critical lenses | | `--lenses full` | FULL mode: all 10 lenses | | `--triplet` | Force proof-triplet CONTRACT form (overrides auto form-detection) | | `--square` | Force square-prompt form (overrides auto form-detection) | | `--auto` | Default for FULL: pick lens depth + form-detection (proof-triplet vs square-prompt) | | `--help` | Display help | ## Workflow patterns (v1.6) ``` quick : /refine "fix race in worker.go pool init" → Suggested next: /goal fix-race-in-worker-go medium : /plan ... --auto → /refine my-feature → Suggested next: /goal my-feature full : /search → /plan → /refine my-feature → Suggested next: /goal my-feature edited : (edit .claude/goals/my-feature.md) → /refine my-feature → Suggested next: /goal my-feature ``` Every chain ends with a printed suggestion; `/goal ` is typed by the user. No auto-chain, no magic. The 4000-char ceiling applies in every case; the actual directive length is the minimum viable. No explicit mode flag needed in normal usage — the skill detects from the argument shape + disk state. Flags exist only for edge cases where you want to override the default detection. --- ## Model allocation (mandatory, not negotiable) Read `../_shared/model-policy.md` and resolve the tiers **before** writing the plan: ```bash bash "${CODEX_HOME:-$HOME/.codex}/plugins/cache/kodflow/kodflow-workflow/0.0.0-re61d6d4f6f77"/skills/_shared/scripts/detect-models.sh ``` Every plan carries the allocation, in one line under its constraints: ``` Models: orchestrator @medium · code workers Sonnet @medium (@medium on a defect or hook code, Opus @medium across modules) · review workers Opus @high · mechanical workers Sonnet @low · workers never inherit the orchestrator model · worktree isolation wherever workers write concurrently. ``` Four rules the plan may not weaken: - **Resolve, never hardcode.** A hardcoded top model is wrong the day a better one ships. - **Never let a worker inherit.** On a top-tier orchestrator that silently runs every worker at the top rate — the single most expensive mistake available. Effort too: a worker with none runs at the session's. - **No gated model without the user's yes** (`gated-models.txt`, policy §6). - **The orchestrator never does the work.** If it is editing, the allocation has collapsed. A plan that omits, reworders or weakens this is rejected and rewritten.