--- name: contrastive-refinement description: "Use when a skill or harness edit needs evidence before it lands — probe candidates on the same task, compose from contrasts, keep lessons with evidence." license: MIT metadata: version: 0.2.0 author: moonlight-lupin platforms: [linux, macos, windows] tags: [agent-ops, skill-improvement, evidence, refinement] related_skills: [repo-adoption-review, build-review-loop] --- # Contrastive Skill Refinement Refine a skill or harness edit with measured behavior, not judgment alone. Before an edit lands, run candidate versions of the skill on the SAME probe task, compare deliverables blind, and compose the surviving edit. Every recorded lesson carries an evidence line naming the observed contrast. This skill only changes skill definitions; for application code changes use `build-review-loop`. Pattern source: Harness² (google-research/harness2, Apache-2.0, arXiv:2610.14224) — the Propose–Probe–Compose loop and the evidence-required lesson format, ported to Hermes skill dirs. See `references/harness2-adaptation.md` for what was ported and what was not. ## When to Use - An edit to a skill promises better output but nobody has measured it - Two candidate edits both look right and you must pick one - A skill failed a real task and you want a proven fix, not a guess - A lesson about a skill needs to be written down and should carry evidence **Don't use for:** typo and frontmatter fixes (no behavior change), live code repos (`build-review-loop`), first drafts of brand-new skills (nothing to contrast yet). **Fire backlog:** an unanswered advisory re-fires every session until its fire row is closed. The contrastive-advisor plugin (v0.2.0+) self-installs a clearance cron (`contrastive-advisor fire clearance`) that closes backlog fires by classification (see its docs/README.md). Running this skill WITHOUT the plugin: either create an equivalent sweeper cron yourself with the same classification rules, or close each fire in the editing session — a documented classification with real-execution evidence is a legitimate close; never leave the demand unanswered. **When the contrastive-advisor fires but the edit fits 'Don't use for':** respond with a documented classification, not a probe cycle. Create the per-skill probe dir (`~/.hermes/skill-probes///`) with a `probe.md` stating WHAT was edited and WHY the edit makes no behavioral claim (diff scope: quoted lines preserved verbatim, only a pointer/label/metadata changed), plus a `selection.md` recording the decision and the commitment rule: any FUTURE behavioral edit to this skill runs the full cycle. Never fabricate probe evidence; never leave the advisor's demand unanswered — an undocumented gap re-fires every session, and inventing a cycle result poisons the evidence root. This also covers consolidation edits (a no-loss pointer repoint with 0 rule-title deltas): the no-loss check IS the evidence line. **Reconstruct the actual edit before classifying — do not classify from memory.** Pull the edit from the session store: query `state.db` `messages` (`tool_calls` column) for the fire's `session_id`, parse each call's `function.arguments` (a doubly-encoded JSON string), and extract the `skill_manage`/`patch`/`write_file` operations naming the skill. Behavioral claims backed by live execution in the editing session (a procedure that was run end-to-end against the real target) satisfy the evidence gate without a synthetic cycle. Three legitimate classifications beyond the mechanical one: - **Unresolved provenance** — the file changed but no logged tool row or backup carries the delta (parallel sessions and file writes outside the tool-call store). Document the gap, describe the current content class, and treat the skill's next edit as gate-bearing. Never guess the edit's purpose. - **Orphan fire** — the fired skill name has no SKILL.md in the tree (or a frontmatter-only sweep confirms absence). Close as orphan; do not classify an edit to a nonexistent artifact. - **Real-environment execution evidence** — a behavioral edit whose procedure was already exercised against the live target in the editing session. State the reopen condition in the selection doc. Close the bookkeeping too: set `answered_at` (+`answered_with` pointer) on the fire's rows in `~/.hermes/skill-probes/fire-ledger.jsonl`, and clear the advisor's pending record in its plugin-data `state.json` when the fire belongs to another session. ## Concepts - **Probe task** — one fixed, realistic task for the target skill, with inputs on disk. The judge is deliverable comparison, not a rubric score. - **Baseline** — the current skill, run once on the probe task. - **Candidate** — one proposed edit (INV or DOM), applied to a COPY of the skill, never to the live skill. The standard cycle uses two candidates: one INV, one DOM. A second pair of candidates is an extension, not default. - **INV edit** — skill-agnostic lever: a checklist, a script gate, an output contract, a guardrail. - **DOM edit** — domain-specific content: a rule, an example, a parameter tuned to the skill's actual subject matter. - **Composition** — one final edit merged from the contrasts that survived blind comparison. Additive: it changes only what the evidence showed. ## Procedure 1. **Choose the probe task.** Pick one realistic task for the target skill. Write inputs to a probe directory. The task must be judgeable by comparing the deliverable text. Completion: probe inputs exist on disk and will not change during the cycle. - Anti-contamination: describe the work in the probe prompt. Never mention that it is a test, a probe, a benchmark, or an evaluation — measurement language changes agent behavior. 2. **Run the baseline.** Execute the current skill on the probe task once. Save the deliverable and the trajectory in the probe directory. Completion: baseline deliverable exists. 3. **Propose candidates.** Write the candidate edits: one INV (a skill-agnostic lever: checklist, script gate, output contract, guardrail) and one DOM (a domain-specific rule, example, or parameter). Write more pairs only when a strong reason exists. Each candidate is a concrete patch to the target skill, written out in full. State the expected behavioral difference for each. Completion: every candidate has a written patch and a written expectation. 4. **Probe.** For each candidate, apply the patch to a COPY of the skill in a scratch directory and run the probe task with that copy. Run the candidates in parallel. Same model, same tools, same inputs — the only changing variable is the edit. Completion: one deliverable per candidate plus the baseline, all from identical probe inputs. 5. **Blind selection.** Run `/scripts/contrast.py ids` — `` is this skill's own directory (the path `skill_view` reports) — to assign anonymous ids to baseline plus every candidate deliverable. Read the deliverables blind, write one `` line per deliverable, then unmask. Completion: a choice with a written reason naming the observed contrast — or no choice. - Fallback rule: if no contrast is visible, keep the baseline. One retry of a failed candidate is the ceiling; after that, keep the base. - Inconclusive probes kill the edit. Do not compose from vibes. 6. **Compose, probe the composition, then apply.** Merge only the contrasts that won blind into one final patch. Probe the composition once: apply it to a FRESH copy of the baseline (not a copy that already holds a candidate patch — that would apply an edit twice) and run the probe task one more time. A merge of two individually winning changes can still behave badly together. Compare the composition's deliverable against the baseline through the same blind procedure (new `ids` round, fresh `` lines) before it lands: the composition must deliver and beat the baseline. Then apply via `skill_manage(action="patch", ...)` to the live skill: `name` is the target skill, `old_text` and `new_text` carry the composed edit. The edit is additive and minimal. If the composition probe loses, keep the baseline and discard the edit. Completion: patched skill, or a recorded decision to keep the base. 7. **Record the lesson with evidence.** Format (all four fields, or no entry): ``` cue: When lesson: evidence: confidence: ``` Field values are single-line. `/scripts/contrast.py lesson-check` enforces the gate: exit 0 required, and a value that is only a placeholder — `n/a`, `-`, `none`, `todo`, with or without markdown wraps (`**n/a**`, `N/A.`) — or one bare `