Metadata-Version: 2.5
Name: skill-linter
Version: 0.3.5
Summary: Validate Agent Skills repos: spec checks, shared conventions, per-repo policy, count stamping and plugin release checks
Project-URL: Repository, https://github.com/Jeffallan/skill-linter
Project-URL: Issues, https://github.com/Jeffallan/skill-linter/issues
Author: Jeff Smolinski
License-Expression: MIT
License-File: LICENSE
Requires-Python: >=3.11
Requires-Dist: pyyaml>=6
Description-Content-Type: text/markdown

# skill-linter

skill-linter checks a repo of Agent Skills before you commit or release it, and keeps the counts and version numbers in its docs current. One `[tool.skill-linter]` table in `pyproject.toml` configures it, so a new skill repo gets the same checks as the others without copying `validate-skills.py`, `validate-markdown.py` and `update-docs.py` into it.

It needs Python 3.11 or later. PyYAML is the only dependency, used for workflow YAML.

```sh
uvx skill-linter check        # run without installing
pipx install skill-linter     # or install it once
```

Status: early (0.x). Rule names and config keys may still change between minor versions.

## Commands

```text
skill-linter check   [--only GROUP[,GROUP]] [--skill NAME] [--format text|json] [--root PATH]
skill-linter stamp   [--check] [--dry-run] [--root PATH]
skill-linter release [--format text|json] [--root PATH]
skill-linter rules   [--format text|json]
```

- `check` runs every enabled rule except the release checks.
- `stamp` counts skills, references, workflows and domains, then writes those counts and the version from `version.json` into the files you list. `--check` writes nothing and exits 1 when anything is stale.
- `release` checks the tree the plugin directory will read (`plugin_root` or a `ship` list), then runs `check`.
- `rules` lists every rule with its group, layer and severity after your overrides.

`skill-linter --version` prints the installed version. Exit codes: 0 when there are no errors, 1 when there are errors or stale stamps, 2 for a usage or config error. `python -m skill_linter` runs the same CLI.

## Workflow runtime: `guard`

`skill-linter guard ...` is the runtime the claude-skills spec and ticket workflow calls through `uvx skill-linter@<pin> guard ...`. It keeps its state under the git directory, in `$(git rev-parse --git-dir)/ticket-guard/`, so nothing it writes is committed and each worktree gets its own copy. Settings come from `.claude/workflow-config.json` when it exists.

```text
skill-linter guard marker start <spec> <ticket> [--mode attended|goal]
skill-linter guard marker status | clear
skill-linter guard run red [--type test|stand-in|refactor] -- <command>
skill-linter guard run green -- <command>
skill-linter guard hook pre-tool-use | stop | session-start      # JSON on stdin
skill-linter guard block <ticket> <reason> [--spec NAME] [--start SHA]
skill-linter guard decide <row> wontfix|rejection-accepted|accepted|answered [--spec NAME] [--session ID]
skill-linter guard rerun [--ticket ID] [-- <command>]
skill-linter guard red-replay [--ticket ID]
skill-linter guard tamper-scan [--ticket ID] [--reason ID=TEXT ...]
skill-linter guard summary [--ticket ID] [--accept-lost-marker]
skill-linter guard metrics <spec> [--base REF]
skill-linter guard rollup <spec> --verdicts FILE [--transcripts DIR]
skill-linter guard gate <spec>
skill-linter guard spec-index [--check]
skill-linter guard run-batches <spec> [--batch-size N] [--claude PATH]
skill-linter guard commit-plan <spec>
```

- `marker start` refuses a dirty working tree (the spec's `implementation-plan.md` aside) and writes `ticket-guard/marker.json`: mode, spec, ticket, branch, start SHA, timestamps, the session claim and the GREEN failure count. Writes go through a temp file and a rename. Starting the same ticket on the same branch again resumes it, and the next hook re-claims it for its session. A marker for another ticket is refused.
- `marker status` prints the marker and warns once it is older than `guard.markerWarnHours` (default 24). `marker clear` removes it.
- Every marker event lands in the ticket's evidence record, `ticket-guard/evidence/<ticket>.jsonl`.
- `run red` runs the command from the repo root, saves its log under `ticket-guard/logs/`, and appends a RED record: command, exit code, HEAD, tree hash, the ticket's test files and their digest, and the log's sha256. It counts as RED only when the command fails, no non-test file has changed since the start SHA, and the failure doesn't look like a collection or import error. A runner that never started (exit 126 or 127, `python -m pytest` without pytest installed, or a shell "command not found") is never RED. `--type stand-in` (a no-code ticket) needs only a real failure; `--type refactor` needs the full suite passing and freezes every test file. A single argument after `--` runs as a shell string.
- `run green` records a run after the implementation and exits 1 when it fails or when the ticket's test files no longer match the RED digest.
- `hook pre-tool-use` freezes the RED test files: in goal mode it denies `Write`, `Edit`, `MultiEdit` and `NotebookEdit` on them, and attended it asks, logging an `amendment_requested` event. In goal mode it also denies edits under `text.ticketsDir`. `hook session-start` prints the ticket, mode and next step after a compaction (source `compact`).
- `hook stop` acts in goal mode only. It re-runs the latest GREEN command (or the RED one) and blocks the stop while that fails or the frozen tests have changed, naming the command and the log tail. It ignores `stop_hook_active`, since inside `/goal` that flag is true on nearly every stop. After `guard.greenFailLimit` consecutive failures (default 3) it lets the stop through and records `green_failure`, so `ticket:complete` fails the ticket. A passing run resets the count. A final message that starts with `BLOCKED:` always passes, in any mode, and sets `blocked_at` and `blocked_stop` on the marker.
- `block` on the marker's ticket saves the diff against the start SHA to `ticket-guard/blocked/<ticket>.patch` and new untracked files to `<ticket>-untracked.tar.gz` beside it, resets the tree to the start SHA, writes the ticket's row as `Blocked` with the reason in the plan's Completion Status table, logs a `blocked` event and clears the marker. It refuses, changing nothing, when HEAD has moved past the start SHA. With no marker, it does the same save and reset against `--start`, or against the `start_sha` of the ticket's last `marker_start` event when the marker was lost (its evidence has no logged clear), and then logs a `marker_clear` with `lost: true`. For any other ticket (a dependent, say `"depends on T3"`) it writes only the row and the event, and `--start` is refused while another ticket holds the marker. The plan file is never part of the patch or the reset, so earlier Blocked rows survive.
- `decide` appends the row, status, spec, session id and time to `ticket-guard/decisions.jsonl`. Owner-only statuses come only from this log. It refuses while a goal-mode marker exists. No session id is exported to Bash, so it takes `--session`, then `$CLAUDE_SESSION_ID` or `$CLAUDE_CODE_SESSION_ID`, then the marker's claim.
- The boundary commands run in `ticket:complete`, before the commit. `rerun` copies HEAD plus the uncommitted work (tracked changes and untracked files) into a temporary worktree and runs the command there, or each `verify` command from the workflow config, or the last GREEN command. `red-replay` copies only the RED test files onto the start SHA in a temporary worktree and expects the RED command to fail; refactor tickets skip it. `tamper-scan` flags deleted test files, added skips (`pytest.mark.skip`, `xfail`, `.only(`, `it.skip(`, `t.Skip(` and similar), changed snapshots or golden files, and tests with no assertion or with assertions only on mocks. It exits 1 until every flag has a one-line `--reason`. In goal mode it ignores `--reason`, since the agent must not clear its own flags, and a flagged ticket goes through `guard block`.
- `summary` prints the notes line for the Completion Status table (RED and GREEN commands with exit codes, the test digest, the re-run, the replay, the tamper flags with their reasons) and exits 1 with a list when any evidence is missing. Each of these commands takes the ticket and start SHA from the marker, or with `--ticket` from the evidence record. A marker that disappeared without a logged clear fails the summary: in goal mode the ticket goes through `guard block`, and attended the owner can pass `--accept-lost-marker`.
- `metrics` writes `<spec>/review/metrics.md` for the files changed since `--base` (default: the merge base with `origin/HEAD`, `main` or `master`), running `jscpd`, `knip`, `vulture` and `lizard` when each is on `PATH` and noting the ones that aren't.
- `rollup` writes `<spec>/review/rollup.md` with every finding from the verdicts file (a JSON list or JSONL, one object per finding with `id`, `tier`, `suggested`, `sources`, `location`, `claim`, `verdict`, `proof`, `evidence`, `reason` and `status`). Tokens and Minutes come from the verifier's subagent transcript, named by `transcript` or found as `agent-<agent_id>.jsonl` in `--transcripts`. Claude Code keeps these at `~/.claude/projects/<project>/<session-id>/subagents/`. Usage is counted once per message id, since one message can span several transcript entries. Owner statuses (`wontfix`, `rejection-accepted`) come only from `decisions.jsonl`.
- `gate` exits 0 only when every blocking row (by the higher of Tier and Suggested) is `fixed-verified` in the rollup or `wontfix` or `rejection-accepted` in the decision log, and every ticket in the Completion Status table is Done, Already done, or Blocked and accepted with `guard decide <ticket> accepted`. Every row in `<spec>/review/pr-feedback-<round>.md` (same row format as the rollup) must also be `fixed-verified` or carry a logged owner status, whatever its tier. `answered` (a question replied to with no code change) closes a PR-feedback row but never a review finding. It lists tickets the overview's Readiness table marks Blocked. Without a rollup or plan it exits 2.
- `spec-index` writes `<specsRoot>/INDEX.md` (default `docs/specs`): one row per spec folder under `todo/` and `completed/` with its status, discovery topics, feature areas and predecessors, read from the `Spec:`, `Discovery:`, `After:` and `Feature areas:` lines above the overview's first `##` heading (plain or bold labels, comma-separated values). Discovery topics are the folders under `todo/discovery/` and `completed/discovery/`; the `discovery/` folder itself is never a spec. Any other folder without `overview.md` gets a warning and stays out of the index. It exits 1 when a `Spec:` line is missing or doesn't match its folder, or when an `After:` name isn't a spec or a `Discovery:` name isn't a topic. `--check` writes nothing and also fails when the file is stale.
- `run-batches` drives a spec headless. It takes the next N tickets in Execution Order that are neither Done nor Blocked (N is `--batch-size`, else `goal.batchSize`, default 3), runs `claude -p "/goal ..."` with a next-batch kickoff pointing at the spec's `goal-prompt.md`, then `claude -p "/compact" --resume <session>`, and repeats in the same session until every ticket is Done or Blocked. It judges each batch by the final message and the plan, never by the exit status. A final message that starts with `BLOCKED:` stops it, and so does a batch that settles no ticket. Every call carries the writes-only deny set as `--disallowedTools`: `AskUserQuestion`, `git push`, `tag`, `rebase`, `reset` and `commit --amend`, `gh pr` and `gh issue` writes, `gh api` with POST, PATCH or DELETE, `guard decide`, and any tool names in `goal.deny` (the tracker MCP server's write tools). It also passes each rule in `goal.allow` as `--allowedTools`, by default `Skill(fullstack-dev-skills:ticket-guard)`, since a denied Skill call in `claude -p` fails silently and leaves the batch without its hooks; a repo that ships the skill under another plugin sets its own list. Every call also runs with `--permission-mode` from `goal.permissionMode` (default `auto`, since a bare `claude -p` refuses every edit) and the arguments in `goal.extraArgs`, such as `["--plugin-dir", "<build>"]`. The report lists Blocked tickets first. At the end it runs `commit-plan`.
- `commit-plan` commits the Blocked rows `guard block` left in the plan, as `docs(<spec>): record Blocked rows in the plan`. It refuses while a marker exists or when any other file is uncommitted, and does nothing when the plan is clean. Run it after a whole-spec goal run ends with Blocked rows, before `spec:review`.
- Hooks stand down (print nothing, exit 0) without a marker, for a session that didn't claim it, on another branch, and on bad input. Test for the marker in shell before starting `uvx`, so a session with no ticket pays for a file check only:

```sh
m="$(git rev-parse --git-dir 2>/dev/null)/ticket-guard/marker.json"; [ -f "$m" ] || exit 0; exec uvx skill-linter@<pin> guard hook pre-tool-use
```

Test files follow a default convention (`tests/`, `test/`, `__tests__/`, `spec/` folders, and names such as `test_*.py`, `*_test.go`, `*.test.ts`, `*.spec.js`); `guard.testPatterns`, a list of glob patterns, replaces it.

Guard commands exit 0 on success, 1 when they refuse, and 2 outside a git repo or when `gate` can't find its inputs. Hooks always exit 0.

## Rules

Rules come in three layers:

1. The [Agent Skills specification](https://agentskills.io/specification) (`SPEC-01` to `SPEC-10`). You can't switch these off.
2. Conventions shared across the skill repos: frontmatter metadata, the description rule, Markdown lint, workflow definitions, hidden conventions such as the docs backlink and title safety, and the changelog format, and the plugin-directory release checks (`CONV`, `DESC`, `MD`, `WF`, `H`, `CL`, `P`). Each one can be switched off or lowered to a warning.
3. Per-repo policy (`POL`, `LINK`, and your own `X-` rules). A policy rule runs only once you give it a value.

Every rule has an ID and a name, such as `POL-03` and `section-order`. Output shows both, and the config accepts either. Run `skill-linter rules` for the full list.

### Cross-skill references

A skill can cite a file in a sibling skill or in a shared folder, written from the skill root: `` `../vue-expert/references/components.md` `` or `` `../_shared/markup-convention.md` ``. The spec wants every reference to stay inside the skill folder, so `SPEC-10` (`reference-depth`) leaves these paths to two other rules:

- `CONV-15` (`cross-skill-references`) checks that the file exists, that the folder is a skill or is listed in `shared_dirs`, and that a cited skill appears in `metadata.related-skills` (a warning when it doesn't).
- `P17` (`cross-skill-targets-ship`) checks that the cited file ships with the plugin. A skill installed on its own won't find its sibling, so these references only work when the whole plugin is installed.

## Configuration

Everything lives under `[tool.skill-linter]` in the repo's `pyproject.toml`. Unknown keys and unknown rule IDs are errors, so a typo can't switch a check off without anyone noticing. `tests/adoption/` holds complete configs for claude-skills and writing-with-agents.

```toml
[tool.skill-linter]
skills_dir = "plugin/skills"
shared_dirs = ["_shared"]
commands_dir = "plugin/commands"
plugin_root = "plugin"
docs_url = "https://example.github.io/my-skills/skills/{domain}/{name}/"

[tool.skill-linter.policy]
workflow_steps = [5, 7]
license = "MIT"

[tool.skill-linter.severity]
plugin-icon = "off"   # or P10

[[tool.skill-linter.rules.custom]]
id = "X-lead-support"
target = "body"
pattern = '(?is)\blead\b.*\bsupport\b'
severity = "warning"
message = "Name a lead and a support role"
```

The changelog rules (`CL-01` to `CL-05`) expect Keep a Changelog headings, the six standard sections in order with `### Contributors` last, an `[Unreleased]` section, and compare links. `[tool.skill-linter.changelog]` takes `path`, `extra_sections` and `since`, the first version they apply to, so older entries can stay as published.

`allow_claude_hooks = true` under `[tool.skill-linter.policy]` lets `SPEC-02` accept a top-level `hooks` field in Claude Code's shape: a map from a PascalCase event name to a list of groups, each with an optional `matcher` string and a `hooks` list of handlers whose `type` is `command`, `http`, `mcp_tool`, `prompt` or `agent`, where a `command` handler needs a non-empty `command` string. The block is read as full YAML, so its nested lists parse. It is off by default, which keeps the base spec rule for every other repo.

Workflow definitions (the `.yaml` beside each command) may carry two optional fields. `unattended: true` marks a command that runs under unattended rules in a goal run, and `false` an attended-only one. `adapter-operations` lists the tracker and code-host operations the command uses: `create`, `read`, `list-spec-tickets`, `link`, `update`, `comment`, `close`, `reopen`, `ensure-group`, `link-groups`, `list-ungrouped`, `open-pr`, `read-pr-feedback`, `reply-resolve`, `check-pr` and `merge-pr`, or the list in `[tool.skill-linter.allowed_values] adapter-operations`. `WF-01` checks their types. `WF-02` checks the names and rejects any write operation on an unattended command, since goal runs write nothing to the tracker or the PR.

Custom rules are regular expressions applied to a frontmatter field, a section, the last line, the body or the reference files. Config never runs code.

### Stamping

Each `[[tool.skill-linter.stamp.files]]` entry names a file and how to update it:

```toml
[[tool.skill-linter.stamp.files]]
path = "README.md"   # .md, .mdx and .html files get marker stamping by default
patterns = [
  { key = "version", regex = 'version-([\d.]+)-blue\.svg' },
  { key = "referenceFileCount.{skill}", regex = '(?m)^\s+(?P<skill>[\w-]+)/\s+\(SKILL\.md \+ (?P<count>\d+) reference(?P<s>s?)\)' },
]

[[tool.skill-linter.stamp.files]]
path = ".claude-plugin/marketplace.json"
json = { "/metadata/version" = "version", "/plugins/0/version" = "version" }
patterns = [{ key = "skillCount", regex = '(\d+) specialized skills' }]
```

- Markers: `<!-- SKILL_COUNT -->67<!-- /SKILL_COUNT -->`, and likewise `WORKFLOW_COUNT`, `REFERENCE_COUNT`, `DOMAIN_COUNT` and `VERSION`. `SKILL_COUNT:<domain>` counts one domain and `REFERENCE_COUNT:<skill>` counts one skill's references.
- `json` maps a JSON Pointer to a key and replaces only that value, leaving the file's formatting alone.
- `patterns` replace the one group in each regex. A pattern that matches nothing is an error, which catches a sentence reworded after its pattern was written.
- `[tool.skill-linter.stamp.values]` holds named strings, such as `runtimePin = "0.3.1"`, usable as a key anywhere a count key is. A name can't shadow a count key.
- `paths` in place of `path` takes a list of globs, such as `["commands/**/*.md", "references/**/*.md"]`, and applies the entry to every file they match. A pattern there fails only when it matches nothing in any of the files, or when the globs match no file, so `stamp --check` catches a missed pin like `skill-linter@([\d.]+)`.
- The key `referenceFileCount.{skill}` stamps a count per skill, for places where an HTML comment would show up as text, such as a file tree inside a code block. Its regex names the skill and count groups. The optional `s` group becomes `s` unless the count is 1, and a line that names no skill is an error.

## Development

```sh
uv sync
uv run pytest
uv run ruff check . && uv run ruff format --check .
```

The adoption tests export pinned commits of the two skill repos with `git archive` and skip when those checkouts aren't present. One of them runs each repo's own `update-docs.py` and `skill-linter stamp` on the same change and checks that every file comes out identical.
