Compress

From melodic-software/claude-code-plugins · View interactive version

Compress is an AI agent skill from the GitHub repository melodic-software/claude-code-plugins. Compress markdown by dropping flavor, filler, and hedging while keeping every directive, qualifier, threshold, and example, behind a semantic-diff subagent that reverts any meaning loss. Articles (a, an, the) are kept by default; the compress_articles setting can allow cutting them. Use when: 'compr

How to use this skill

Skill file

Repository context. Gather first

<!-- BEGIN GENERATED: gather-block. Edit docs/conventions/gather-block/block.md, then run scripts/sync-gather-block.py -->

Run each command below as its own Bash call, all sent together in one message (worktree isolation).

Keep any bound in the command's own pipe (output limits).

Unless this section says otherwise, treat a failure (not a repository, git unavailable) as an unknown value and carry on. Keep these as body calls, never ## Pre-computed context lines (gather-block convention).

<!-- END GENERATED: gather-block -->

Purpose

Markdown in docs/, README files, onboarding docs, third-party pasted prose, and drifted skill bodies accumulates flavor: filler ("just", "really", "basically"), hedging ("perhaps", "might"), pleasantries, and, only when compress_articles is cut, articles. context/flavor-vs-content-matrix.md defines flavor (safe to cut) vs content (never cut). Under the default, keep, a run keeps every a, an and the and is held to the batch path's word-level cuts on every target, single file included (Articles). The batch fan-out path (Phase A LATITUDE) is a word-level trimmer: mechanical drops + passive→active + nominalization only, no sentence-level restatement deletion. Under cut, the single-file in-session Edit fallback may apply the full matrix taxonomy (including redundant restatement of bold rule names) behind the same semantic-diff net. Always-loaded instruction files (.claude/rules/**, AGENTS.md, CLAUDE.md, **/SKILL.md) bound empirically at 2-3% yield (see ## Sources); author-time-undisciplined content likely yields 5-15% under the Edit fallback's broader latitude, less under batch fan-out.

Methodology: snapshot original → mechanical compression (the caveman plugin via /caveman:caveman-compress, or in-session Edit fallback) → semantic-diff subagent compares original vs condensed (SEMANTIC LOSS / AMBIGUITY / FALSE POSITIVE per finding, verbatim citations) → revert every SEMANTIC LOSS + AMBIGUITY → run markdownlint-cli2 → ship or revert.

Articles: `compress_articles`

Resolve this before Step A and before the audit scan; it decides the backend and how much a run may cut. Layers, lowest first, a later one winning (key contract: CODE0):

| Layer | Value |

|---|---|

| default | keep |

| userConfig | ${user_config.compress_articles}. A literal unexpanded token means unset; keep here is reported as the default, since the two cannot be told apart. |

| repository | compress_articles in docs/conventions/docs-hygiene.yaml at the repository root |

Read the repository layer with bash "${CLAUDE_SKILL_DIR}/scripts/articles-setting.sh". It prints keep or cut for a valid value, unset with a reason when the layer does not apply (no git working tree, a root that is $HOME or an ancestor of it, no file, no key), or invalid with what the key holds (a value other than the two, an empty or null value, a map or list, a key set twice, a file that does not parse).

A layer holding anything other than keep or cut is named in the output (the file or userConfig that held it, the key, the value) and dropped. A valid higher layer still wins; with none, the run continues on the default, keep. It never stops on an invalid value and never falls through to a lower layer's value.

| Value | Backend | What may be cut |

|---|---|---|

| keep | in-session Edit, even when caveman is enabled (why CODE1 skips caveman) | the batch path's word-level set without articles: filler, hedging, pleasantries, verbose verb phrases, passive to active, nominalization collapse. No sentence or restatement deletion, on a single file as in a batch. An article dropped anyway is restored in the revert pass |

| cut | caveman when available, otherwise in-session Edit (Step A onward, unchanged) | articles too; a single-file Edit run may use the full matrix, restatement deletion included |

Report the result once per run, as the last line of the summary: compress_articles: keep (default), compress_articles: cut (docs/conventions/docs-hygiene.yaml), or compress_articles: cut (userConfig).

Revert threshold, compress_revert_below_pct (N below; a whole number 0-100, default 3): the same layers, from ${user_config.compress_revert_below_pct} and, at the repository root git rev-parse --show-toplevel prints (skipped as for compress_articles), bash "${CLAUDE_PLUGIN_ROOT}/lib/parse-concern-value.sh" --strict <root>/docs/conventions/docs-hygiene.yaml compress_revert_below_pct (empty means unset; exit 3 or any other value is invalid and dropped as above). 0 turns the auto-revert off. Report it beside the articles line: compress_revert_below_pct: 3 (default).

Over several repositories (a target form, below), resolve both settings once per repository, the repository layer from the tree that pass reads (articles-setting.sh <that tree>, and <root> above set to it), and report the two lines per repository. One repository's cut never applies to another.

Backend selection

Under compress_articles: keep, skip Step A and Step B's caveman path: the backend is the in-session Edit fallback, held to the keep row above. Under cut, default-action Step B picks the backend: the caveman plugin (marketplace caveman, invoked as /caveman:caveman-compress via the Skill tool) when present, otherwise the in-session Edit fallback, which also substitutes whenever caveman is unwanted. Caveman performs the mechanical flavor cuts; it is not the verification gate. /caveman:caveman, the same plugin's session-wide response formatter, is unrelated to this skill.

Step A. Detect caveman plugin: bash "${CLAUDE_SKILL_DIR}/scripts/detect-caveman.sh"

Tri-state: available → prefer caveman; absent or unknown → treat as absent and use the Edit fallback (unknown means claude/jq missing from PATH: fail open to Edit, not a hard error).

Step B, caveman backend (preferred when available): the steps span tool calls, and Bash state does not persist across them (no trap … EXIT, no relying on $tempdir in a later call):

  1. Bash call 1. Create a temp copy and echo its absolute path (no EXIT trap):

```bash

tempdir=$(mktemp -d)

cp "$target" "$tempdir/$(basename "$target")"

printf '%s\n' "$tempdir/$(basename "$target")"

```

  1. Skill call. Skill(caveman:caveman-compress, args="<absolute-path-from-step-1>") on that temp copy.
  2. Bash call 2. On caveman success, copy the compressed file back and remove the tempdir explicitly:

```bash

cp "<absolute-path-from-step-1>" "$target"

rm -rf "$(dirname "<absolute-path-from-step-1>")"

```

On caveman failure, skip the cp and still rm -rf the tempdir so the real target is untouched.

The real file is replaced only on success. Consumers may add a defensive **/*.original.md entry to their .gitignore in case caveman's backup ever lands in the tree.

caveman-compress, Purpose

live.

Step B fallback. In-session Edit (compress_articles: keep, or caveman absent, unknown, or unwanted):

Apply Edit ops directly on $target per the context/flavor-vs-content-matrix.md taxonomy. Under cut: the full matrix, including restatement deletion. Under keep: word-level cuts only, every article kept, no sentence or restatement deleted.

Step C+ unchanged: semantic-diff dispatch (mandatory hard rule, skipped only by a light or off verification level, with the resolved compress_articles value as the prompt's {ARTICLES}, so under keep a dropped article is SEMANTIC LOSS and is restored), revert pass for SEMANTIC LOSS / AMBIGUITY / UNCERTAIN findings, markdownlint-cli2, summary.

Action router

| Action | Args | Behavior |

|---|---|---|

| <target> (default, no action keyword) | empty → uncommitted .md from git status; file path → single-file; dir path → batch | snapshot → backend → dispatch → revert-pass → markdownlint verify → summary |

| audit [target] | same target rules | read-only dry-run; run scripts/audit-scan.sh --articles <resolved compress_articles> (six-signal heuristic in context/target-types.md); classify SKIP/COMPRESS/UNCERTAIN |

| compare ORIG_DIR NEW_DIR [REASONS] | two skill directories, before and after a rewrite; optional file listing each intended cut with its deletion-test reason | read-only; see ## Compare |

Flags (apply to the default and audit actions):

Compare

Judges a rewrite of a whole skill directory, SKILL.md plus its references, where the default

action's per-file diff would call every moved line and every intended cut a loss.

  1. Check both paths are directories; stop on a missing one. Write nothing to either.
  2. Dispatch the read-only docs-hygiene:compare-labeler agent with context/compare-prompt.md,

never general-purpose, which can edit. The calling session never labels a difference: it may

have written the rewrite and would excuse its own cuts. The step is done when the return

carries labeled rows and a VERDICT: line.

  1. Print the labeler's rows and its literal VERDICT: PASS or VERDICT: BLOCK line verbatim, as

returned: no restyling, reformatting, reordering, bolding, recasing or paraphrase. Any summary

of your own goes after them. VERDICT: BLOCK (any SEMANTIC LOSS, or an instruction in the

compared text aimed at the labeler) is the gate a rollout PR blocks on.

Auto-detect default

Shared clean-tree / no-scope shape: CODE0. The rules below are what this skill runs; open the shared file only when editing them, for the sibling divergences it owns.

  1. Empty arg and clean tree → interactive session: repo-wide interview fallback (next section); non-interactive context (subagent, headless/CI): friendly no-op exit 0 ("No uncommitted .md files. Pass file/dir target.")
  2. Empty arg and uncommitted .md files → batch default action over those files
  3. Single file path → single-file default action
  4. Directory path → batch default action (filenames sorted lexically for deterministic output)
  5. First positional == audit → audit action on rest (same clean-tree offer as rule 1 when the rest is empty. Report-only corpus audit, no Edit)
  6. First positional == compare → compare action on the next two paths (and an optional REASONS file); no clean-tree fallback

Repo-wide interview fallback (empty arg, clean tree, interactive)

Instead of dead-ending, offer a repo-wide run, confirmation-gated at the offer (step 1) and before the run (step 4); declining at either exits with the friendly no-op message. Bare /docs-hygiene:compress audit on a clean tree uses steps 1–2 only (free audit + report; no compression defaults or run confirmation).

  1. Offer (AskUserQuestion): run against all tracked eligible .md files? Decline → no-op exit.
  2. Audit first (free, mechanical scan, no subagents): run the audit action over every tracked eligible .md. Present inline only aggregate counts per class, a dispatch-cost estimate (2 subagent requests per compressed file), and a top-20 excerpt of COMPRESS rows selected deterministically: expected-yield band descending, then word count descending, then lexical path (band strings tie; the two tie-breaks keep the excerpt stable run-to-run). Write the full per-file table, lexically sorted per the "Summary output deterministic" hard rule, to ${CLAUDE_PLUGIN_DATA}/audit/<branch-or-scope>-audit.md when that dir is writable, otherwise to a temp path echoed to the user, and point at it. Never render every row inline: on a large repo the full table can run to hundreds of KB and truncate the confirmation prompt it feeds. Stop here when the invocation was the audit action (report-only).
  3. Take the prescribed defaults, default (mutating) action only. Take each default below without asking and report all three in one line, each with its override, for example Defaults: scope top-10 COMPRESS (override: top-N, all COMPRESS, include UNCERTAIN, or report only); concurrency 2 (override: 1 or 3-5); always-loaded files excluded (override: explicit opt-in). The user overrides any of them in the reply to step 4's confirmation.
  1. Confirm and run: batch default action over the set step 3 reported, with any override the user gave, waves per context/fan-out-orchestration.md. Every per-file hard rule, semantic-diff dispatch, revert pass, markdownlint, <N% AND 0 semantic-loss → REVERT, applies unchanged.

Non-interactive contexts skip the offer and take the no-op branch. The fallback adds an entry path only. It changes no compression, verification, or revert semantics.

Hard rules

Output schema (default action, per target)

<basename>: <action_taken> (compression_pct=N.N%, semantic_loss=K, ambiguity=M, false_positive=P, markdownlint=PASS|FAIL)

action_taken ∈ {compressed, reverted, skipped}. Aggregate at end of batch.

Audit action output: table with target, expected_yield_pct, classify (SKIP/COMPRESS/UNCERTAIN), reason.

Related

Gotchas

Let subagents spawn their own subagents

live.

When NOT to use

What this skill is NOT

Sources

Reference index. Load on demand

| File | Load when |

|---|---|

| context/semantic-diff-prompt.md | Dispatching the semantic-diff subagent; it is the prompt body and the return contract. |

| context/compare-prompt.md | Dispatching the compare labeler; it is the prompt body and the return contract. |

| context/flavor-vs-content-matrix.md | Judging whether a specific span is flavor or content, and during the revert pass. |

| context/target-types.md | Resolving what an argument points at, or classifying SKIP / COMPRESS / UNCERTAIN in audit. |

| context/fan-out-orchestration.md | Compressing N files across parallel subagents, so the semantic diff stays in a separate context. |

| context/integration.md | Another skill, lint job, or gate wants to call this one, and you need the invocation form it may use. |

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.