Cprune

From joshft/correctless · View interactive version

Cprune is an AI agent skill from the GitHub repository joshft/correctless. Documentation and artifact pruning skill. Detects stale entries and orphaned artifacts, archives documentation (never deletes), cleans ephemeral artifacts. Two modes — autonomous for /cauto pipeline, interactive for direct invocation.

How to use this skill

Skill file

/cprune — Documentation and Artifact Pruning

EXECUTE IMMEDIATELY. This skill being loaded into your context IS the user's instruction.

You are the pruning orchestrator. You detect stale documentation entries, orphaned artifacts, and count drift, then either auto-execute low-risk actions (autonomous mode) or present a formatted report for human disposition (interactive mode).

Mode Detection (INV-001)

Detect execution mode from prompt context:

Lockfile (BND-004)

Before starting, check for .correctless/artifacts/cprune-lock-{slug} (where slug is derived from branch_slug). If the lock exists and was created by a different process, refuse with "Another /cprune is running." Create the lock before scanning, remove it on completion (normal or error).

Scanner

The scanner script at scripts/prune-scan.sh (or .correctless/scripts/prune-scan.sh on installed projects) is the sole detection mechanism. It accepts --category and --base flags and outputs JSON to stdout.

Run the scanner for each category:

bash scripts/prune-scan.sh --category <category> --base .

Categories (9 total): architecture, antipatterns, claude-md, artifacts, deferred, counts, crossrefs, specs, driftdebt

Scanner output schema (BND-001)

For the artifacts category, the scanner emits a wrapped object (NOT a bare array). All other categories still emit a bare array. The skill must read .candidates from the wrapped object:

# Correct:
bash scripts/prune-scan.sh --category artifacts --base . | jq -r '.candidates[]'

# Wrong — would read the wrapper object as a candidate:
bash scripts/prune-scan.sh --category artifacts --base . | jq -r '.[]'

Wrapped-object schema (artifacts only):

{
  "candidates": [...],
  "skipped_unclassified": [{"pattern": "...", "count": N}],
  "protection_set": {
    "live_branches": [...],
    "live_branch_slugs": [...],
    "live_task_slugs": [...],
    "live_session_ids": [...],
    "source_workflow_state_files": [...]
  },
  "protection_status": {
    "task_slug": "ok|fail-closed",
    "reason": "no-workflow-state|incomplete-spec_file|parse-failure|null"
  }
}

Render the Protection Set section in the prune report from .protection_set (INV-017). When protection_status.task_slug is fail-closed, the report must include the reason and explain that no task-slug-named files were considered for pruning in this scan. Render skipped patterns from .skipped_unclassified (INV-007 — surfaces unclassified-pattern safety belt activations).

Baseline-update flag is interactive-only (INV-011):

The baseline manifest at .correctless/meta/prune-pattern-baseline.json is

updated only by interactive mode after the human confirms newly-emitted

medium-risk candidates have been reviewed. The autonomous code path below

must never pass the baseline-update flag to scripts/prune-scan.sh regardless

of the candidate set; the flag (its literal name redacted here so structural

tests can assert the autonomous block does not invoke it) is reserved for the

human-confirmed interactive flow.

Archive Contract (ABS-038)

/cprune is the sole writer for archive files. Only /cprune writes to these files:

Archive files are committed to the repo (not gitignored). Each has a header comment on first creation (BND-001):

# Archived [Type] Entries
# Entries moved here by /cprune. Original IDs are preserved — do not reuse them.
# To un-archive, copy the entry back from this file to the source file.

Archive-Before-Remove Ordering (PRH-001)

When archiving an entry:

  1. Write the entry to the archive file with an Archived field: - **Archived**: {date} — {reason}
  2. Verify the archive write succeeded (file exists and contains the entry ID)
  3. Only then remove the entry from the source file

If the archive write fails, preserve the source entry unchanged. Never permanently delete documentation entries — always archive first, then remove.

Entries with Live File References (PRH-003)

Never archive entries whose referenced file paths still exist. The scanner enforces this — only entries with ALL dead references are candidates. The skill must not override this criterion.

Autonomous Mode Behavior (AD-001)

In autonomous mode, execute only risk: low candidates:

Skip categories where bulk_warning: true (BND-002 safety valve).

Skip CLAUDE.md entirely (PRH-002 — interactive-only, never autonomous).

Skip deferred findings (PRH-004 — read-only, report stale count only).

Return a structured summary of actions taken.

Interactive Mode Behavior

Persist-Before-Present (INV-015, AP-029)

Write scan results to .correctless/artifacts/prune-report-{date}.md BEFORE presenting them to the user. The artifact is the recovery path if the terminal display is interrupted. The interactive presentation renders from the artifact.

Progress and Disposition (INV-018)

Display progress between categories: "Scanning {category}... found {N} candidates."

For each category with candidates, present:

  1. Category name and total candidate count
  2. Per-candidate: ID, reason, risk level, dead_refs count
  3. Confirmation prompt showing archive destination: "Archive {ID} to {destination}?"
  4. Disposition options per category:

1. Execute all (recommended for low-risk)

2. Review individually

3. Skip this category

After each category's disposition is confirmed, execute immediately (not batched at end).

Final summary: total actions taken, files modified, archive destination paths.

To un-archive an entry, copy it back from the archive file to the source file manually.

/cprune is Read-Only for Deferred Findings (PRH-004)

/cprune reports stale deferred findings but does NOT write to .correctless/meta/deferred-findings.json. Users should run /ctriage to update stale findings. This keeps /cprune as a scanner/reporter and avoids adding a 5th writer to ABS-033.

Risk Classification (DD-003)

Autonomous Defaults

When running in autonomous mode (mode: autonomous in prompt context), use these defaults instead of pausing for human input. Return autonomous decisions in the AUTONOMOUS_DECISIONS_START/AUTONOMOUS_DECISIONS_END format provided in the task prompt.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.