cp-skill-revise-iterative

$npx mdskill add zby/commonplace/cp-skill-revise-iterative

Iteratively revise a note for flow, readability, and cohesion using non-interactive Claude calls

  • The user provides a note file path to be iteratively revised for better flow, readability, and cohesion.
  • This skill relies on the Claude API for generating revisions of the provided note.
  • Claude analyzes each revision pass for semantic fidelity and significance before moving to the next iteration.
  • Revisions are saved as numbered copies in the same directory as the original file.

SKILL.md

.github/skills/cp-skill-revise-iterativeView on GitHub ↗
---
name: cp-skill-revise-iterative
description: Iteratively revise a note for flow, readability, and cohesion using non-interactive Claude calls. Each pass produces a numbered copy; the outer agent reviews for semantic fidelity and significance before continuing. Triggers on "/cp-skill-revise-iterative [note]".
type: kb/types/instruction.md
user-invocable: true
allowed-tools: Read, Edit, Bash, Glob, Grep
argument-hint: <note-filename>
context: fork
model: opus
---

## EXECUTE NOW

**Target: $ARGUMENTS** (exactly one note path or filename — if empty, ask which note)

### Step 0: Resolve the file

Resolve `$ARGUMENTS` to a full path. If it's a bare filename, search `kb/notes/` for a match. Read the file to confirm it exists and capture the original content.

### Step 1: Initialize

```
i=0
source_file=<resolved path>
```

Copy the original to `${source_file}.0` — this is the baseline for the first revision pass.

The workflow makes substantive editorial changes. Remove `user-verified: true` from `${source_file}.0` if present, and keep it absent from every generated revision. Do not remove it from the original until the user accepts a revision; applying an accepted revision revokes the prior attestation automatically.

### Step 2: Revision loop

Run the following loop. **Max iterations: 5** (hard cap to prevent runaway).

#### 2a. Run non-interactive revision

```bash
claude -p "Revise $(basename ${source_file}).$i for flow, readability, and cohesion. Preserve all semantic content, claims, and structure. You MAY improve the title (# heading) and description frontmatter field if you see a clear improvement — but do not change tags, type, or traits. Focus on: sentence-level clarity, paragraph transitions, removing filler, tightening prose." \
  --allowedTools "Read,Edit,Write" \
  --max-turns 10
```

Run this from the directory containing the file so relative paths work.

#### 2b. Verify the revision happened

Read `${source_file}.$i` after the claude call. If the file is unchanged from before the call (content identical to pre-call state), the revision failed — report the failure and bail out. Do not increment or retry.

#### 2c. Semantic fidelity check

Compare `${source_file}.$i` (revised) against the previous version (`${source_file}.$((i-1))` for i>0, or the original `${source_file}` for i=0).

Check for:

1. **Semantic errors** — Did the revision change the meaning of any claim? Did it drop or add substantive content? Did it alter evidence, caveats, or qualifiers in ways that change the argument?
2. **Structural damage** — Did it remove sections, reorder arguments in ways that break logical flow, or merge distinct points?
3. **Frontmatter integrity** — Are tags, type, and traits unchanged? (Title and description MAY change — see 2e.)

If ANY semantic error or structural damage is found:
- Report exactly what went wrong (quote the before/after for the problematic passage)
- **Do not apply this revision** — the last good version is `${source_file}.$((i-1))` (or the original if i=0)
- Skip to Step 3 (finalize) using the last good version

#### 2d. Title and description change detection

Compare the `# Title` heading and `description:` frontmatter field between the current and previous version. If either changed, **flag it** — record the before/after values. These are not errors; they will be reported to the user in Step 3. Do not reject a revision solely because it changed the title or description.

#### 2e. Significance check

Assess whether the changes in this pass are **significant** — meaningful improvements to flow, readability, or cohesion beyond trivial whitespace or punctuation.

- If changes are significant: increment `i`, copy `${source_file}.$i` to `${source_file}.$((i+1))`, and loop back to 2a.
- If changes are minor or negligible: this version is good enough. Stop looping and proceed to Step 3.

**Note:** When copying to the next iteration file, always copy the current `${source_file}.$i` (not the original).

### Step 3: Finalize

The best version is the last file that passed the semantic fidelity check.

1. Show a **diff summary** between the original file and the best version — list the key changes made across all passes.
2. If the title or description changed, **report it explicitly** — show before/after for each.
3. Ask the user: "Apply these changes to `${source_file}`? (The intermediate files will be cleaned up either way.)"
4. If the user approves:
   - Copy the best version over the original file
   - **If the title changed** and the new title implies a different filename (per KB convention: lowercase, hyphens, derived from `# Title`):
     - Derive the new filename from the new title
     - Rename the file: `git mv ${source_file} ${new_filename}`
     - Find all markdown links pointing to the old filename across `kb/` and update them to the new filename
     - Report which files had links updated
   - Delete all intermediate files (`${source_file}.0`, `${source_file}.1`, etc.)
5. If the user declines:
   - Leave the original untouched
   - Delete all intermediate files

## Constraints

**Never:**
- Modify the original file until the user explicitly approves
- Let more than 5 iterations run
- Accept a revision that introduces semantic errors — always prefer the previous version
- Change tags, type, or traits frontmatter fields
- Skip the semantic fidelity check

**Always:**
- Show the user what changed before applying
- Clean up intermediate files regardless of outcome
- Report which iteration produced the final version
- Bail out early if a revision fails or introduces errors

More from zby/commonplace

SkillDescription
cp-skill-connectDiscover connections for a single artifact. Writes a connect-report under kb/reports/connect/<collection>/ without mutating library artifacts or indexes. Use with an artifact path or artifact name.
cp-skill-convertConvert notes between types. Currently supports text to note by adding unverified structured frontmatter, renaming the file to match the title, and fixing backlinks. Use with a note path or note name.
cp-skill-health-checkRun a Commonplace health check when agents, skills, or commonplace-* commands do not work correctly. Diagnoses project layout, promoted skill discovery, direnv/PATH state, package commands, and common launch-environment failures.
cp-skill-ingestUse when asked to ingest a URL or existing kb/sources snapshot into a .ingest.md source analysis.
cp-skill-revise-autoreasonExperimental: revise a note with an AutoReason-style loop using fresh Codex sub-agents for critic, revision, synthesis, and blind judging. Keep the incumbent, generate a critique-driven revision and synthesis, then use blind Borda judging to decide whether to continue. Triggers on \"/cp-skill-revise-autoreason [note]\".
cp-skill-snapshot-webSnapshot any URL into kb/sources/. Routes by URL type — GitHub issues/PRs via gh API, X/Twitter via xdk, PDFs via download+Read, web pages via WebFetch. One skill, URL in, markdown snapshot out. Triggers on "/cp-skill-snapshot-web", "/cp-skill-snapshot-web [url]".
cp-skill-validateRun the deterministic validation script on KB notes. Checks frontmatter validity, schema constraints, link health, required sections, and batch signals such as orphans.
cp-skill-writeWrite a single KB note — apply the target collection's conventions and path-valued type-spec, commit only in-hand links plus a cheap duplicate check, validate, then hand graph discovery to cp-skill-connect.
evaluate-scenariosDecompose each scenario into clean-context forks, measure framework-overhead bytes and hops per fork, and report a feasibility signal (heaviest fork's net load) and a cost signal (overhead summed across forks). Use to measure the operational overhead the framework imposes per agent.
roughdraft-reviewOpen a Markdown file in Roughdraft for the user to review, wait for Done Reviewing, then respond to the CriticMarkup feedback. Use when the user wants to review, comment on, or annotate a Markdown file (they may call the tool "rd"), and when presenting a plan — write the plan to disk and offer it for review this way.