Metadata-Version: 2.5
Name: farrier
Version: 8.1.0
Summary: Render an agent-neutral prompt library into a repository's Codex/Claude/Copilot adapters.
Project-URL: Homepage, https://github.com/GabrielCpp/stablemate
Project-URL: Repository, https://github.com/GabrielCpp/stablemate
Project-URL: Issues, https://github.com/GabrielCpp/stablemate/issues
Author: Gabriel Côté
License-Expression: MIT
License-File: LICENSE
Keywords: agent,claude,codex,copilot,installer,prompts,skills
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Build Tools
Classifier: Topic :: Utilities
Requires-Python: >=3.12
Requires-Dist: jinja2>=3.1
Requires-Dist: markdown-it-py>=3.0
Requires-Dist: mdit-py-plugins>=0.4
Requires-Dist: platformdirs>=4
Requires-Dist: pydantic>=2.0
Requires-Dist: pyyaml>=6.0
Requires-Dist: tomlkit>=0.13
Description-Content-Type: text/markdown

# farrier

[![PyPI](https://img.shields.io/pypi/v/farrier.svg)](https://pypi.org/project/farrier/)

**farrier** renders an agent-neutral prompt library into a repository — generating
the skill, prompt and instruction adapters expected by Codex, Claude, GitHub
Copilot and Antigravity, plus the launcher scaffolding (`.agents/agents.mk` and friends) that keeps
those adapters current.

A farrier is the craftsman who fits the right gear onto each horse. This tool
fits the shared prompt library onto each repository — and refits it as the library
moves, so an architecture, testing or review standard changes in one place and every
repository's installed copy follows, instead of each one drifting on a private copy.

## Install

```bash
pipx install farrier        # or: uv tool install farrier
```

The farrier package ships **no library content of its own.** Content resolves across
two layers: the **base library** — plain data, the toolchain skills and the packs that
select them, with nothing to install or import — and an optional private **overlay**
that shadows it name-for-name. Point farrier at an overlay once:

```bash
farrier config set-library /path/to/the/overlay
farrier config show
```

`config` writes one shared TOML file, `~/.config/stablemate/config.toml`
(`~/Library/Application Support/stablemate/` on macOS, `%APPDATA%\stablemate\` on
Windows; `$STABLEMATE_CONFIG` overrides it). Every stablemate tool reads and writes that
same file, so `library_dir` and `base_dir` mean one thing across all of them — a
pre-existing `~/.config/farrier/config.toml` is still read, and folded in on the first
write. `farrier config reference --file home` prints every key of that file with its type,
default, meaning and example.

**Finding the base library.** farrier ships the base library inside its wheel, so a
`pipx` install renders it with no network and no `git`. A base you name outranks it:
`$STABLEMATE_BASE_DIR`, then the `base_dir` config key (`farrier config set-base <path>`),
then a configured `stablemate_dir` checkout (`<checkout>/base-library`).

**`farrier install` mirrors the base for the other tools.** Under `pipx` each tool is its
own venv, so workhorse reads the base from the shared cache at `~/.cache/stablemate`.
Install copies the shipped base there when the cache holds a different digest, and swaps
it in whole. Two qualifications:

- **A base you named is never mirrored over.** When one answers, install leaves the cache alone.
- **`--check` writes no cache.** It renders the shipped base and runs in CI.

`STABLEMATE_CACHE_DIR` relocates the cache. See the monorepo's
[install guide](https://github.com/GabrielCpp/stablemate/blob/main/docs/INSTALL.md#finding-the-base-library)
for the full resolution order and why everything other than install reads the cache frozen.

## Use

In a repository that has no `agents.yml` yet:

```bash
farrier init                # write a starter agents.yml (--force to replace one)
```

`init` reads nothing — no library, no config — so it works on a fresh machine before
`farrier config set-library`. It refuses to overwrite an existing `agents.yml`.

Then, from a repository that has one:

```bash
farrier --repo .            # render/install the selected packs
farrier --repo . --check    # verify generated files are up to date (no writes)
```

Rendering is the default action; `farrier install --repo .` is an accepted alias
of `farrier --repo .`. A bare `farrier` with no arguments prints the verb listing.

Install has two scopes, and each one writes only where it is pointed. `--repo PATH`
renders the repo's `agents.yml` selection under `PATH` and nothing else. `--user` renders
the `[user_library.<harness>]` tables of the shared config into the harness homes
(`~/.claude`, `~/.gemini/config` for Antigravity, and `~/.agents` for Codex and Copilot), reads no repo and writes to none.
Workhorse also runs workflow turns on Antigravity, as `--cli antigravity`.
At repo scope it shares `.agents/skills` with Codex, and a repo with both on gets the path form of each skill reference.
Its guards run through a generated bridge, `~/.gemini/config/hooks/farrier-guards.py`.

A harness with no prompt folder takes each selected prompt as a skill the user runs by name.
At home only Claude has one, and in a repo Codex and Antigravity have none. The skill lands as `<name>/SKILL.md`
in the harness's skill folder, with `disable-model-invocation: true` in its front matter. A folder Codex
reads also gets `agents/openai.yaml` with `policy.allow_implicit_invocation: false`. Those switches keep
Pi and Codex from starting the skill on their own. Antigravity documents no such switch.
A prompt's `$ARGUMENTS` stays as written in a Claude or Pi command. A Copilot prompt file gets
`${input:arguments}`, and a skill gets `<arguments>`, with a line saying what the user types after its name.
A Claude or Codex table that names a `roots` entry also writes that home's always-on rules,
`~/.claude/CLAUDE.md` or `~/.codex/AGENTS.md`, from one file in the library.
A table that names `mcp` servers adds each one to `~/.claude.json` or `~/.codex/config.toml`,
and a value farrier did not install stops the install instead of being replaced.
A table that names `hooks` guards adds each one to `~/.claude/settings.json` or
`~/.codex/hooks.json`. Codex skips a new guard until you approve it in `/hooks`,
and `farrier install --user --check` names each guard still waiting.

A Claude table that names `settings` merges each `library/settings/<name>.json` object into
`~/.claude/settings.json`. Each top-level key is one entry farrier owns, so a key you set by
hand stays, and a key dropped from the library file leaves the home. `hooks` belongs to the
guards, and two files that set one key stop the install.

A table that names `agents` writes each helper agent to `~/.claude/agents` or
`~/.codex/agents`, on the model `[profiles.<harness>.delegates.<name>]` names.
Codex cannot enforce a read-only agent, so its prompt asks for it instead.
A Claude agent may call only the tools its file lists. An agent record's `session_mcp` names
servers the session runs, such as a channel, and the agent may call their tools. Codex and
OpenCode agents already reach every server the session runs, so they ignore it.
An Antigravity agent gets Antigravity's own tool names. An agent that names `delegates` becomes a
main agent that may call `invoke_subagent`, and Antigravity lets it call any subagent, not only those
it names. An agent's `mcp` servers are listed inside the agent, and `session_mcp` turns on `inheritMcp`.

A `[user_library.opencode]` table takes the same `roots`, `mcp`, `hooks` and `agents`.
They land in `~/.config/opencode`: rules in `AGENTS.md`, servers in `opencode.json`, helper
agents in `agents/`, and guards through a generated plugin, `plugins/farrier-guards.ts`.
Farrier never writes `opencode.jsonc`, and a server it holds under the same name with another
value stops the install. OpenCode reads skills from `~/.claude/skills`, so farrier writes none
for it and a pack's skills are left out.

A `[user_library.pi]` table takes `skills`, `roots`, `mcp`, `hooks` and `settings`. Skills land in
`~/.agents/skills`, shared with Codex and Copilot, and rules in `~/.pi/agent/AGENTS.md`. Servers go
to `~/.pi/agent/mcp.json`, settings to `~/.pi/agent/settings.json`, and guards through a generated
extension, `~/.pi/agent/extensions/farrier-guards.ts`. Pi has no helper agents, its prompts land as skills,
and a `done` guard must name `pi` in `not_on`.

Pass both, `farrier install --repo . --user`, to refresh the home right after the repo
from the same library. A repo install never touches the home on its own, so a worktree
on an older branch cannot overwrite the skills your main checkout installed there.

The rest of the verbs:

```bash
farrier config show                        # every config key as key=value
farrier config show --profile cheap        # one [profiles.<name>] table, flattened
farrier config --config ./c.toml show      # …read from that file rather than the home one
farrier source .claude/skills/x/SKILL.md   # the library file that generated an adapter
farrier eject <name>                       # hand a generated skill or a policy over to the repo
farrier scaffold --list                    # the scaffolds this repo may apply, and their params
farrier scaffold <id> [--param KEY=VALUE]  # seed repo files from one
farrier workflows                          # the workflows installed on this machine
farrier worktrees ~/code                   # the linked worktrees that are safe to remove
farrier version
```

`source` takes the path of a *generated* file and prints the library file behind it. It
is the one to reach for before editing anything under `.claude/`, `.codex/` or
`.github/`: those are outputs, and an edit there is discarded by the next install.

`eject <name>` stops farrier managing one thing and keeps its content. Given the
installed name of a generated skill folder (`myrepo-db`), it strips the farrier
provenance from the folder (the `generated_by`, `source`, `resolve`, `do_not_edit` and
`name` metadata keys, plus the banner and `farrier source` line of bundled files),
then edits `agents.yml` so nothing selects the skill again. A literal `skills:` entry
loses its line, a glob entry becomes the literal ids it still matches, and a skill
that only a pack selects goes under `exclude.skills`. Comments and every other byte of
`agents.yml` stay. It refuses when more than one harness holds a real copy: set
`claude: {skills_from: codex}` first. Given a policy listed in `localInstructions`, it
writes the policy body into each mapping's `text:` (ahead of any text there) and
removes the name from `policy`/`policies`. After either, it reinstalls, so
`farrier --repo . --check` passes. A skill name wins over a policy of the same name.
A `localInstructions` `skill:` name that no selected library skill carries resolves
to the hand-written skill folder of that name, which is how an ejected skill stays
embedded in `AGENTS.md`.

`config show --profile <name>` prints one `[profiles.<name>]` table — the named model
set a run selects with `workhorse-<name> run --profile <name>` — flattened to one dotted
line per leaf (`power.high.claude.model=haiku`). A profile **replaces** the top-level
tables rather than layering over them, so what it prints is the whole config that run
resolves from, and two profiles diff against each other line by line. `--config PATH`
goes before the action and names the file every config verb reads and writes, so the
question can be asked of a config that is not this machine's home one.
`farrier config set profiles.<name>.<key>=<value>` writes one profile leaf, and refuses
an undeclared key.

`worktrees` finds the linked worktrees agents left behind and changes nothing until you pass
`--apply`. Each path is a checkout or a folder of checkouts, the default is the current
directory, and the repositories behind the configured `worktree_dir` are always included.
A worktree goes only when its tree is clean and every commit on it is merged into the branch
the main checkout has out, or pushed to a remote. Ignored files do not count as changes, so
they go with it. The branch goes too when it is merged. Four things keep a worktree regardless:
`git worktree lock`, a running process using it, git state touched within `--idle-days`
(default 7), and a platform without `/proc`, where farrier cannot see which processes use it.
An entry whose folder is already gone is pruned.

## Configuring `agents.yml`

`agents.yml` (at your repo root) selects what farrier renders. `farrier init` writes a
starter one with the common keys as commented examples. `farrier config reference --file
manifest` prints every key of the file with its type, default, meaning and example, including
the keys the installed workflows and ostler read. A key the manifest does not declare loads
and logs a warning that names the closest declared key.
**[`agents.example.yml`](https://github.com/GabrielCpp/stablemate/blob/main/farrier/agents.example.yml)**
is a worked sample you can copy to your repo as `agents.yml` and prune to taste.

Each `agents.<harness>` is `true` or `false`. Claude also takes
`{skills_from: <harness>}`, naming codex, antigravity or pi, which read `.agents/skills`.
The mapping enables Claude and renders no skill folders for it. Instead farrier
writes a relative symlink `.claude/skills/<name>` to `../../.agents/skills/<name>`
for every skill folder there, hand-written ones included, so one set of skills
serves every harness:

```yaml
agents:
  codex: true
  claude:
    skills_from: codex
```

Most harnesses read `.agents/skills`, so Claude is the one that links. A prompt that
lands in `.agents/skills` as a skill gets no link, because Claude takes it as a command.
The source must be enabled. Prompts, commands,
root instructions and hooks still render per harness. A cross-skill link inside a
shared copy points at the source harness's home skills dir. A symlink in a linked
dir that targets the source dir is farrier-owned: install rewrites a wrong one and
sweeps a stale one, and `--check` reports a missing, extra or wrong one as drift. A
real folder or a foreign symlink there is not owned and follows the usual conflict
rules.

## Library layout

The other side of the contract is the **agent library** farrier renders *from* — what
goes in `library/skills/`, `library/prompts/`, `packs/` and `scaffolds/`, the file
formats expected, and how source names map to generated adapters. That is documented in
**[`docs/LAYOUT.md`](https://github.com/GabrielCpp/stablemate/blob/main/farrier/docs/LAYOUT.md)**.

A skill or prompt is markdown with YAML frontmatter, and `farrier.frontmatter` reads it
with a markdown parser and `yaml.safe_load` — never a fence regex. (It is farrier's own
module rather than `ostler.markdown` because farrier needs frontmatter only and does not
depend on ostler) A CRLF file, a closing `---` with a trailing space and a file with
no newline after it are all ordinary documents, and the regexes that preceded this read
every one of them as having no frontmatter at all.

**Farrier does not install workflows.** A library ships none, `agents.yml` has no
`workflows:` key, and no workflow files are written. A workflow is a Python
distribution that brings its own command: install it with pip/uv and run it directly.

```bash
uv tool install workhorse-workflows
workhorse-research run --dry-run # static preflight, drives nothing
workhorse-coder run
```

## Locating the library

`--library DIR`, `$FARRIER_LIBRARY_DIR` and `library_dir` in the home config
(`farrier config set-library`) select the **overlay**, in that precedence. The base
library is found separately, by the order under [Install](#install) above, and the two
stack: the overlay first, then the base.

A directory counts as a library if it holds `library/` — that is the whole contract.
Point farrier at one that does not and it exits with a setup hint; configure no overlay
at all and it runs base-only, which is a supported setup rather than an error. Only with
neither an overlay nor a base does it refuse to start.

## Related

- [`workhorse-agent`](https://pypi.org/project/workhorse-agent/) — the fail-soft runner
  that executes the workflows, against the adapters farrier renders.
- [`ostler`](https://pypi.org/project/ostler/) — the documentation-graph toolkit
  workflows call through its in-process Python API.

All three live in the [stablemate](https://github.com/GabrielCpp/stablemate) workspace.
