Extract ssot

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

Extract ssot is an AI agent skill from the GitHub repository melodic-software/claude-code-plugins. Deduplicate repeated markdown (rule files, skill bodies, ADRs, docs) into one named source of truth and migrate every call site to cite it by exact heading. Use when the same prose, literal, or concept recurs across files: 'DRY this prose', 'extract a shared rule', 'single source of truth for X', a

How to use this skill

Skill file

Arguments. [identify|verify|plan|execute|batch|unwind] [<cluster>] [--fix] [--dry-run] [--repo <repo> ...]. Full form: [identify|verify|plan|execute|batch|unwind] [<cluster-name>] [--min-instances=<N>] [--buckets=<list>] [--fix] [--dry-run] [--yes] [--inline] [--parallel-waves] [--commit-mode=<per-wave|single|none>] [--repo <repo> ...|--repos-from <file|->|--owner <owner>|--fleet] [--skip <entry> ...]

Extract SSOT

Why this skill exists

Codifies the markdown-SSOT-extraction pattern as a repeatable workflow. Each invocation targets one cluster of repeated markdown content and resolves it to a single named source of truth, consolidating into an existing SSOT home when one already owns the concept, otherwise creating a new artifact (e.g. a rule file or a new skill), plus migration of all call sites to cite by exact heading.

The principle is the coding Rule of Three / DRY, applied to markdown text. If the same unit of prose appears 3+ times, changes together, and has an identity that can be named, collapse to one definition and reference by name. Below 3 instances, minting a new SSOT artifact is premature abstraction, the dominant failure mode, and the skill refuses it.

Refusing to create is not refusing to report. A lone consumer that recaps an SSOT it should be citing, and a pair of files asserting the same contract with no declared owner, are real defects that drift. Both are rostered in their own multiplicity bucket and remedied in place, with no new artifact.

Typical markdown extraction shapes the workflow handles:

Extraction is dangerous, for the reason the record in context/decision-framework.md, "The SkillsBench record", points at. This skill encodes the guardrails (Rule of Three, categorical-shape test, the size bound and one-level depth rule /playbooks:skill-authoring (if enabled) ## Body and ## Reference files record, Metz unwind procedure) so each invocation is reversible and reviewable.

Code / config escape-hatch. Repeated string literals, magic constants, helper functions in source code, or repeated CI / settings / MCP stanzas in config files are also extractable in principle (Rule of Three applies). This skill flags such clusters during identify but does not ship a citation contract for them, the caller uses the language-idiomatic form (import / using / source, YAML anchor, JSON $ref, build-tool include) and language-aware refactoring tools. Markdown is the only file class with no language-level rename safety net. That is where the contract here adds value.

Evidence discipline

Every extraction decision must be grounded in direct evidence captured this session. Grep output or file reads you performed yourself. This skill calls such evidence Tier 0. Recall ("I remember seeing this repeated"), a subagent's survey summary, or any other synthesized claim is not Tier 0. Promote it via your own grep before it drives a plan or an edit. A subagent roster is a lead list, never proof.

Scope: markdown SSOT

In-scope: repeated content across the consuming repository's tracked markdown. Instruction files (CLAUDE.md, AGENTS.md, README.md), rule files (.claude/rules/), skill bodies (.claude/skills/), agent definitions (.claude/agents/), automation/routine prompts, ADRs, and docs. Markdown is the file class with no compiler or IDE refactor to catch a broken reference, the citation contract here is what closes that gap.

| Citation target | Form |

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

| Rule-file H3 heading | ` per <file>.md "<exact heading>" ` |

| New skill | /<skill-name> invocation (skill internals not cited externally. See /docs-hygiene:audit-encapsulation) |

Out-of-scope, but flagged during identify:

The 6-test extraction gate (Rule of Three, namable, stable, self-contained, bounded, one level deep) generalizes to all file classes, and context/decision-framework.md annotates each test with code/config equivalents. The how (citation contract, rename sweep, encapsulation rule) is markdown-specific.

Across repositories. A target form (--repo <repo> and the others) widens the scope to those repositories' tracked markdown, per CODE1 and CODE2 "Several repositories". identify surveys each repository in its own subagent, then rosters a unit found in several repositories as one candidate listing each repository, counting its instances across all of them. That is the strongest SSOT case: the repository that owns the fact keeps it, and each other repository replaces its copy with a pointer at the owner, in its own pull request, after the owner's lands ("Writes stay per repository" there). plan names the owner: the repository whose code or config the fact describes, else the one the user picks; it never guesses. A pointer across repositories cannot use a relative path, so it links the owner's file on its default branch, with the heading anchor. Whole files copied between repositories are measured by /coupling:reduce (if enabled): invoke it for them; without it, list them in the report as not measured. Each repository's working notes hold only the candidates that repository acts on, each naming the other repositories it shares the candidate with.

Boundary with single-file refactoring: a rename, inline, or extract confined to one file or one recent diff is ordinary editing, not this skill's job. /docs-hygiene:extract-ssot handles cross-file markdown deduplication where the repeated unit needs a stable name and cross-file citations. When work touches both, normalize the call sites first, then lift the named unit.

When to use vs not use

Use when: the same unit appears more than once across files (3+ instances is the bar for creating a new SSOT artifact; 1 and 2 route to the non-abstracting buckets); the instances change together (correlated edits); the unit has a stable identity that can be named; the unit is self-contained (extracts cleanly without dragging unrelated context). Normal-work entry point, when a cleanup pass, audit, value-bump diff, or review surfaces any of the three duplication smells, (a) same literal repeated across tracked files, (b) value-bump diff touches multiple unrelated files, (c) same concept reworded across files or contradicting nuance between files. Route detection here. The skill accepts both literal and semantic clusters; the 6-test gate's "namable + categorical-shape + stable identity" tests admit semantic clusters provided the unit can be named and instances change together.

Classify each file's role before flagging it as a duplicate:

Contract identifiers the SSOT defines (tier names, label slugs, action verbs, command names) stay inline in consumers. Naming them is not duplication; those tokens are the contract surface. Content (definitions, criteria, mapping tables, thresholds, exception clauses) must cite, never recap.

Don't use for: single-file refactoring inside one diff; recent-diff simplification of a single skill or feature; filing a tracking issue (route to the repo's issue tracker); writing a new skill from scratch without an underlying repetition trigger (use a skill-authoring workflow such as the skill-creator plugin); cross-language type sharing where the answer is codegen, not text dedup.

Full decision matrix: context/decision-framework.md (6+5 checklist with worked examples).

Action router

| Argument | Action | Purpose |

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

| (empty) | Smart default | Auto-detect: working notes from a prior run hold an active candidate roster (defined in "Phases per invocation") → resume the current phase; the invocation or conversation already names a scope → identify; otherwise → confirm scope with the user first (see "Bare invocation: confirm scope first") |

| identify [<cluster-name>] | Find candidates (default = exhaustive subagent survey) | Dispatches a read-only exploration subagent over 30+ duplication heuristics (full body in actions/identify.md), or surveys inline with a Tier 0 grep per candidate when the corpus is small or --inline is passed; ranks by ROI; emits batch-sequencing matrix + recommended /docs-hygiene:extract-ssot batch invocation. Rosters every surviving candidate in a labeled multiplicity bucket (N=1 / N=2 / N≥3) with its instance count; artifact-creating outputs stay reserved for N≥3. Single-cluster mode (identify <name>) skips the subagent for a targeted Tier 0 grep |

| verify <cluster-name> | Refuse-fast pre-extraction gate | 6-gate cheap check (bucket assignment + Tier 0 grep, citation state, primary-source URL gate, bifurcation check, off-by-one heuristic, LOW-ROI threshold). Output: PROCEED \| REFUSE-{reason} \| WARN plus the assigned bucket:. Optional. Does not gate plan/execute. See actions/verify.md |

| plan <cluster-name> | Architect | Pre-step (Tier 0 grep): does an existing rule/doc already own the concept? If yes → consolidate-into-existing branch (extend the home + de-recap consumers, no new artifact). Else choose creation output type (rule vs skill); draft or extend SSOT body; sketch migration plan |

| execute <cluster-name> | Migrate | Write or extend the SSOT (skip writing when an existing home already documents the concept); rewrite call sites to cite + de-recap inline reproductions; sweep references by invoking /docs-hygiene:rename-references via the Skill tool if a heading/identifier changed; verify |

| batch <cluster-list> | Multi-candidate orchestration | Auto-verify filter, file-overlap matrix, sequential-by-default dispatch, lesson injection between subagents. See actions/batch.md |

| unwind <ssot-name> | Reverse | Re-introduce duplication per Sandi Metz wrong-abstraction recovery |

One action per response; actions don't chain implicitly.

Flags

Accepted by identify and batch (the roster-producing surfaces); batch passes them through to each dispatched identify/verify.

| Flag | Default | Behavior |

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

| --min-instances=<N> | 1 | Lowest bucket to roster. --min-instances=3 rosters only N≥3 clusters, so sub-three candidates never reach the user |

| --buckets=<list> | all | Filter the roster to the named buckets, e.g. --buckets=1,2 for the non-abstracting work only |

| --fix | off | Apply only the non-abstracting remedies (trim-to-citation, normalize-wording). Never writes a new artifact; still honors the per-bucket review gate unless --yes |

| --dry-run | off | Print the diff --fix would apply; write nothing |

| --yes | off | Non-interactive; skip the per-bucket review gate. Only meaningful with --fix |

| --inline | off | identify only. Survey in the main session with a Tier 0 grep per candidate instead of dispatching the survey subagent, whatever the corpus size. A small corpus already surveys inline without it |

| --parallel-waves | off | batch only. Permit parallel dispatch within a wave whose candidates the overlap matrix proves disjoint. Without it every wave runs sequentially |

| --commit-mode=<mode> | per-wave | batch only. per-wave commits each wave, single commits once after the last wave, none leaves the changes uncommitted for the caller. See context/orchestrated-mode.md "Cadence and commits" |

Bare invocation (no flags) stays read-only: it reports the buckets and stops, matching /docs-hygiene:audit-noise and /docs-hygiene:audit-derivability. Full flag semantics: actions/identify.md.

Bare invocation: confirm scope first

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.

A bare /docs-hygiene:extract-ssot with no working notes to resume, no

argument, and no scope implied by the conversation does not

auto-dispatch the exhaustive survey. Exhaustive identify sweeps every

tracked markdown file and, at whole-repo scale, feeds a multi-agent

verify/execute batch, a spend the user opts into, never a default.

Ask one question with prescribed defaults, recommended option first:

  1. Whole-repo exhaustive survey (recommended for maintenance

sweeps). It runs under context/orchestrated-mode.md defaults; in the

same ask, confirm depth (roster only / verified roster / full

pipeline with wave commits).

  1. Path- or glob-scoped exhaustive survey, the user names one or

more directories / globs (e.g. plugins/docs-hygiene/, docs/**/*.md);

routes to exhaustive identify restricted to tracked markdown under

that pathspec (still a survey, not a single-cluster grep).

  1. Targeted cluster, the user names a semantic cluster; routes to

identify <cluster-name> (Tier 0 grep on that cluster only).

  1. Not now.

Non-interactive sessions (no user to ask): proceed only when the

invoking automation supplied an explicit scope or action argument;

otherwise report the available options and stop rather than assuming

whole-repo intent.

Decision framework

Before recommending a new SSOT artifact, run the 6-test gate (all must pass) + 5-test inline gate (any one keeps inline). Full checklist with evidence and worked examples in context/decision-framework.md.

Headline gate: Rule of Three (Don Roberts / Fowler). Refuse creation of a new SSOT artifact at <3 instances. Premature abstraction is the dominant failure mode. Rule of Three gates artifact creation, not reporting: every candidate is rostered at its own multiplicity, and the bucket decides which remedies are on the table.

| Bucket | Rostered? | Permitted remedies | Creates a new artifact? |

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

| N=1. Inline recap of an existing SSOT | always | trim-to-citation, normalize-wording | never |

| N=2. Two consumers recap an existing home, or two files assert one contract with no declared owner (bifurcation risk) | always | trim-to-citation, edit-existing-rule, name-an-owner, normalize-wording | never |

| N≥3. Rule of Three met | always | all of the above, plus rule-file / new-skill / new-action | only behind the 6-test gate |

Lowering the reporting threshold does not lower the abstraction threshold: the sub-three buckets offer only remedies that edit files already present. Full rationale: context/decision-framework.md "Reporting gate vs abstraction gate".

Output type

Markdown branch (primary):

| Shape | Target | Trigger |

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

| Concept already has an SSOT home | Consolidate into the existing file (extend it only where a consumer carries nuance the home lacks) + de-recap the inline reproductions; create no new artifact | An existing rule/skill/doc already owns the concept and consumers recap it inline instead of citing it. Positive output-type form of verify Gate 2 + anti-pattern Shape C; identify flags it as edit-existing-rule / trim-to-citation |

| Divergent phrasings of one agreed truth | normalize-wording. Align every site onto the canonical/agreed wording in place; no new artifact | Instances say the same thing differently and the drift itself is the defect. Available in every bucket, including N=1 and N=2 |

| Two files assert the same contract, neither declared canonical | name-an-owner. Declare one existing file the owner; the other cites it | Accidental source-of-truth bifurcation (anti-pattern #11, accidental branch); the N=2 bucket's default remedy. No new artifact |

| Vocabulary, IF-THEN rules, hard constraints, within the line cap of /playbooks:skill-authoring (if enabled) ## Body | Rule file wherever the consuming repository's own conventions place shared rules, default .claude/rules/<topic>.md (always-loaded) or a path-scoped rule file | Categorical markdown content; consumers cite by H3 heading. Artifact-creating. N≥3 only, behind the 6-test gate |

| Workflow, multi-action, has its own actions/anti-patterns | New skill at .claude/skills/<name>/SKILL.md, authored via the consumer's skill-authoring workflow (e.g. the skill-creator plugin) | Process content; consumers invoke /<name>. Artifact-creating. N≥3 only, behind the 6-test gate |

| New action on existing skill | Action row added to the skill's action router | The workflow maps cleanly onto an existing skill's concern, same domain, same triggers, same output surface, rather than warranting a new top-level skill. Artifact-creating. N≥3 only, behind the 6-test gate |

Skill-vs-rule heuristic: if the SSOT body is mostly nouns (named units the caller cites), it's a rule file. If the SSOT body is mostly verbs (steps the caller invokes), it's a skill.

Non-markdown escape (out of scope for this skill's how; flag during identify, refer the caller to language-idiomatic tooling): code constants / shared modules / helper libraries; config includes / YAML anchors / JSON $ref. See context/decision-framework.md "Output type: rule file vs skill" for the fuller table including code/config rows and worked examples; this section is the canonical markdown summary.

Citation form

For markdown call sites, cite by exact H3 heading text + 1-line inline summary. Template:

<scope phrase> per `<rule-file>.md` "<exact heading text>".
<scope phrase> per `<rule-file>.md` "<exact heading text>": <optional ≤80-char summary>.

For code call sites, use the language's native import syntax. For config call sites, use the tooling's native include / anchor / $ref mechanism.

One level deep, never chain A.md → B.md → C.md. A heading rename triggers a sweep: invoke /docs-hygiene:rename-references via the Skill tool across every form in its pattern library.

Full contract incl. line-wrap edge case: context/citation-form.md.

Encapsulation rule

Encapsulation enforcement (detection grep, public/private surface matrix, remediation paths) lives in its own skill. /docs-hygiene:audit-encapsulation. Different concern from duplication: violations are single-instance matters (Rule of Three does not gate them).

/docs-hygiene:extract-ssot execute invokes /docs-hygiene:audit-encapsulation detect via the Skill tool during the refactor pass to catch any encapsulation violations introduced or exposed by the migration. See /docs-hygiene:audit-encapsulation for the public surface matrix, filter taxonomy, and remediation paths.

Anti-patterns guarded

13-pattern taxonomy with mitigations: citation rot, over-indirection, leaky abstraction, loss of locality, reference resolution failure, wrong abstraction, premature extraction, self-generated SSOT, always-loaded SSOT propagation lag, encapsulation violation, source-of-truth bifurcation, primary-source citation gate, Shape C dedup-by-deletion (positive). Each pattern + symptom + mitigation procedure: context/anti-patterns.md.

Patterns #11/#12/#13 derive from the empirical lessons in context/lessons.md and are surfaced as REFUSE triggers in the verify action.

The unwind action implements Metz's 3-step recovery for the wrong-abstraction case (re-introduce → keep used subset → delete unneeded → re-isolate).

Phases per invocation

identify-cluster → architect-plan → execute-migration → sweep-references → verify

For multi-session work, persist the candidate roster, plan, and per-phase status to working notes in the consuming repository (wherever its conventions put task notes) so a fresh session can resume from durable state instead of re-deriving it. End each phase with a short status entry: what's done, what's next. When the caller forbids commits (a sweep step recording "no findings", for one), keep those notes out of the tracked tree.

An active candidate roster is a persisted roster with at least one candidate still open: not yet executed, refused, or deferred with a tracking note. Only an active roster triggers resume. When every candidate is refused or done, the notes hold a closed record instead: its first line reads status: closed, and a bare invocation treats it as absent. The resume gates in the action router above and in actions/identify.md (step 1 and the pre-dispatch sanity check) use this definition.

Per-phase checklist: context/execution-checklist.md.

The verification level governs the adversarial-review round a WARN-borderline cluster gets (actions/verify.md). Resolve it in the session that runs a WARN-borderline cluster's execute, before that cluster's commit, with bash "${CLAUDE_PLUGIN_ROOT}/lib/read-verification.sh" --plugin docs-hygiene --skill extract-ssot --file docs/conventions/docs-hygiene.yaml and report its line (levels). standard and strict run the round as a fresh-context diff review before commit. Under light, and off, which acts as light here, dispatch no review and never review the diff inline in its place: the working notes record verification: skipped (<level>) for that cluster.

Sanity checks

| When | Check | Evidence |

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

| Pre-roster | Instance count confirmed via grep (Tier 0) and the bucket assigned from it | Grep output captured in the plan/working notes |

| Pre-new-artifact | 3+ full reproductions confirmed via grep (Tier 0); at 1-2 the remedy stays non-abstracting | Grep output captured in the plan/working notes |

| Pre-extraction | Cluster has stable identity that can be named; instances change together | Decision-framework checklist marked in the plan |

| Pre-extraction | File-class scope identified (markdown / code / config / mixed) | Listed in the plan; citation form chosen per class |

| Per-callsite | Citation/import in the form native to the call site's file class | Diff review |

| Post-extraction | Every /docs-hygiene:rename-references pattern swept (markdown call sites) | Skill output |

| Post-extraction | SSOT reads sensibly in isolation (leaky-abstraction self-test) | Manual read |

| Post-extraction | Lint clean across affected file classes; cross-references and imports resolve | Linter/build output |

What this skill does NOT do

Reference index. Load on demand

| Reference | Load when |

|---|---|

| context/decision-framework.md | Running the 6+5 gate on a candidate, or choosing its output type. |

| context/citation-form.md | Writing or repairing a call-site citation, line-wrap edge case included. |

| context/anti-patterns.md | Diagnosing a symptom the gate did not catch (stale citation, chained link, bifurcated source), or writing a REFUSE reason. |

| context/execution-checklist.md | Running execute, one checklist per phase. |

| context/lessons.md | Running verify, and before a batch that repeats a shape an earlier batch already hit. |

| context/orchestrated-mode.md | The user confirmed a whole-repo batch: worker tiering, concurrency cap, wave cadence. |

| actions/identify.md, actions/verify.md, actions/batch.md | Running that action; the router table above is only its summary. Private surface. |

| /docs-hygiene:rename-references | An extraction renamed a heading, and every citing form still needs sweeping. |

| /docs-hygiene:audit-encapsulation | The duplication turns out to sit across a skill boundary. |

Spoke paths

The actions/ and context/ files write this skill's directory as <skill-dir>, which is

${CLAUDE_SKILL_DIR}. Put that path in place of the placeholder before running a command or

writing it into a brief; never hand a ${…} token from those files to the Bash tool.

Related

Recheck triggers

| Condition | Action |

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

| External tool/CLI/API documented inside an SSOT rule ships a major version bump | Re-verify the Tier 0 flag/verb set in the affected rule file; cited entries may have moved or renamed |

| /docs-hygiene:rename-references adds a new syntactic form to its pattern library | Update the sweep step in context/execution-checklist.md |

| Anthropic ships a first-class native rule/skill linker (heading-rename auto-sweep) | Demote the /docs-hygiene:rename-references step to advisory; reduce sweep scope |

| A SkillsBench revision lowers its negative-delta count, or a later benchmark supersedes it with a lower one | Reduce gate strictness; consider relaxing the artifact-creation gate from Rule of Three to Two for low-risk vocabulary (the reporting buckets are unaffected. They already roster at one) |

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.