docs: add readme

This commit is contained in:
johannes committed 2026-10-23 16:01:59 +02:00
1 parent 6f4d6f5609
commit 0aedef8c8c
2 files changed
+177 -144

No files matched your search

-144
View File
@@ -1,144 +0,0 @@
# skm: skill manager
`skm` installs agent skills from git repos, pins each repo to a commit with a Nix hash, and updates on demand after you review the diff. Nix fetches the pinned sources and links them into place. `skm` only edits the manifest and lockfile.
It replaces the current setup, where skills are committed as plain copies under `~/Repos/nix/home/agents/skills` and their origin is tracked (without commits) in vercel's `~/.local/state/skills/.skill-lock.json`.
## Decisions
| Topic | Decision |
|---|---|
| Source of truth | `skills.json` manifest (hand-edited or edited by `skm`). `skills.lock.json` is written only by `skm`. |
| Location | Both files in `~/Repos/nix/home/agents`. No skill contents in the dotfiles. Own skills live in their own private repo. |
| Sources | Flake refs: `github:owner/repo`, `git+ssh://…`, `git+https://…`. Skills are directories containing `SKILL.md`, at the repo root or in subdirectories. No tarballs, registries, or local paths. |
| Pinning | Per repo. Optional `ref` (branch/tag), default branch otherwise. To hold one skill back, add a second source entry with its own `ref`. |
| Hash | `narHash` (`sha256-…` SRI, same value `fetchFromGitHub` uses), from `nix flake prefetch --json`. |
| Outdated | A skill is outdated only if its own subtree differs between the locked and the new store path. Repo commits that don't touch it don't count. |
| Update | `update [name]` shows the diff of the affected skills and applies after you confirm. `--yes` skips the prompt. |
| Local edits | Impossible (read-only store). Change a skill by forking it or moving it to your own repo. |
| Selection | Named skills, or `"*"` for every skill in the repo. With `*`, `outdated` reports skills added or removed upstream. |
| Name collisions | Error, unless one entry renames its skill with `"as"`. Within one repo names aren't unique (plugin monorepos ship the same skill twice), so an entry can pick one with `"path"`; `"*"` refuses repos with duplicate names. |
| Fetching | Only through `nix flake prefetch`. No git dependency in `skm`. |
| Linking | home-manager links each skill individually to `~/.claude/skills/<name>` and `~/.agents/skills/<name>`. The parent directories stay writable, so Claude's `synced/` dir keeps working. Targets are configurable globally. |
| Rebuild | `skm` prints "run the switch". With `--switch` it runs the configured `switchCommand`. |
| Git | `skm` never commits. It prints a suggested commit message. |
| UI | Go + bubbletea. Subcommands for scripting, plus a dashboard when run with no arguments. |
| Binary | `skm`. Repo stays `skill-manager`. |
## File formats
`skills.json`:
```json
{
"sources": {
"mattpocock": {
"url": "github:mattpocock/skills",
"skills": ["tdd", "prototype", { "name": "grilling", "as": "grilling-mp" }]
},
"own": {
"url": "git+ssh://git@<host>/<user>/skills",
"ref": "main",
"skills": "*"
}
}
}
```
`skills.lock.json` (written by `skm`; `locked` is `nix flake prefetch --json`'s `locked` with its `hash` added as `narHash`):
```json
{
"version": 1,
"sources": {
"mattpocock": {
"locked": { "type": "github", "owner": "mattpocock", "repo": "skills", "rev": "abc123…", "narHash": "sha256-…" },
"skills": { "tdd": "skills/tdd", "prototype": "skills/prototype", "grilling-mp": "skills/grilling" }
}
}
}
```
`skills` in the lock maps the installed name to the subpath, already resolved (including the `*` expansion). Nix can then link skills without scanning repos at eval time.
## Nix side (this repo's flake)
- `packages.skm`: `buildGoModule`.
- `homeModules.default`, options under `programs.skill-manager`:
- `enable`
- `manifestDir` (string path to the working tree, e.g. `/home/johannes/Repos/nix/home/agents`)
- `lockFile` (path inside the consuming flake, read at eval time; required, because pure eval can't read `manifestDir`)
- `targets` (default `[ ".claude/skills" ".agents/skills" ]`)
- `switchCommand` (string)
- The module reads the lock, calls `builtins.fetchTree source.locked` for each source, and emits `home.file."<target>/<name>".source = "${src}/${subpath}"`. It also writes `~/.config/skill-manager/config.json` with `manifestDir` and `switchCommand`, and installs `skm`.
- `devShells.default`: go, gopls, nix.
- `checks`: Go tests, including the end-to-end test.
## Required changes in `~/Repos/nix`
1. Add `skill-manager` as a flake input and import its home-manager module in `homeManager.johannes`.
2. **Rebuild must evaluate as the user** so `fetchTree` on the private `git+ssh` repo uses the user's SSH agent:
- Linux: `nixos-rebuild switch --sudo --flake …` instead of `sudo nixos-rebuild …` (`devenv.nix:85`).
- voyager: `nix build .#darwinConfigurations.voyager.system` as the user, then `sudo ./result/activate` (`devenv.nix:80`).
3. In `modules/home/dotfiles.nix`, drop `".claude/skills".source = live "agents/skills"` and the skills part of `.agents`. The module now owns those paths.
4. After migration: delete `home/agents/skills/*` from git (keep `skills.json`, `skills.lock.json`) and delete `~/.local/state/skills/.skill-lock.json`.
## CLI
| Command | Does |
|---|---|
| `skm` | Dashboard |
| `skm add <url> [--ref R] [--name N]` | Prefetch, list `SKILL.md` dirs, pick in TUI (or `--skill a,b=alias`, `--all`), write manifest + lock. Adding to an existing source keeps its pin. |
| `skm remove <name>` / `--source S` | Remove the skill from the manifest and drop the source when it's empty, or remove a whole source |
| `skm list` | Installed skills with source and short rev |
| `skm outdated` | Prefetch each source's ref in parallel and report changed / added / removed skills |
| `skm update [name…]` | Diff review, then write the lock. `--yes`, `--switch` |
| `skm import [path]` | Read vercel's `.skill-lock.json`, write the manifest, pin HEAD, show the diff against the current `home/agents/skills` copies |
Global flag: `--dir` overrides `manifestDir`.
## Dashboard
- A list of sources, each expanding to its skills, with a status per skill: ✓ up to date, ↑ outdated, ± added/removed upstream, spinner while checking.
- Upstream checks start in the background on open, in parallel across sources.
- Keys: `a` add (URL prompt, then the picker), `d` remove, `u` update the selected source (or `U` for all outdated), `enter` diff review, `q` quit.
- Diff review: a file list on the left, a scrollable diff viewport on the right, `y` accept, `n` skip.
- Every action calls the same core package as the subcommands. The TUI holds no logic of its own.
## Code layout
```
cmd/skm/ main, stdlib flag subcommands
internal/jsonfile/ atomic JSON read/write
internal/manifest/ load/save skills.json, validation, collisions
internal/lock/ load/save skills.lock.json
internal/fetch/ Fetcher interface; nix implementation (nix flake prefetch --json)
internal/skills/ discover SKILL.md dirs, subtree compare, diff generation
internal/core/ add/remove/outdated/update/import operations
internal/tui/ bubbletea models: dashboard, picker, diff review
nix/module.nix home-manager module
flake.nix
```
`Fetcher` interface: `Prefetch(url, ref) -> {StorePath, Locked}`. The real implementation shells out to nix. The fake serves fixture directories.
Diffs are computed in Go between `oldStorePath/subpath` and `newStorePath/subpath`. The old store path comes from prefetching the locked rev, which is cached in the store.
## Tests
- Unit: manifest/lock round-trips, collision and alias rules, `*` expansion, subtree change detection, diff output (fake fetcher).
- End-to-end: a temp `git+file://` repo with two skills; `add`, commit upstream, `outdated`, `update --yes`; assert the lock. Needs nix, no network. Nix can't run inside the build sandbox, so these tests skip during `nix flake check` and run via `go test` in the devShell.
- TUI: the picker, review and dashboard models are driven with key messages directly, asserting on state and ANSI-stripped views (no `teatest` golden files: less brittle, no extra dependency).
## Build order
1. Flake skeleton + devShell, Go module, `Fetcher` with the nix implementation.
2. Manifest/lock packages, `add` (non-interactive), `list`, `remove`.
3. home-manager module; switch `~/Repos/nix` over with one source to prove linking and the eval-as-user rebuild.
4. `outdated`, `update` with a plain-text diff and confirm.
5. `import`; migrate all sources. Find origins for `c4-model` and `create-readme`; move own skills to the private repo.
6. bubbletea: picker, diff review, then the dashboard.
## Out of scope (v1)
Non-git sources, patches/overlays, per-skill targets, per-skill pins, auto-commit.
+177
View File
@@ -0,0 +1,177 @@
# skm
**Pin agent skills from git repos with Nix, and update them only after you've reviewed the diff.**
`skm` manages [agent skills](https://docs.claude.com/en/docs/claude-code/skills) (directories containing a `SKILL.md`) that come from git repositories. Each repo is pinned to a commit and a Nix `narHash`. Nix fetches the pinned sources and home-manager links every skill into `~/.claude/skills` and `~/.agents/skills`. `skm` only ever edits two JSON files.
- **Reproducible**: a lockfile with commit and hash for every source, evaluated by Nix.
- **Reviewed updates**: see the diff of every changed skill before it is applied.
- **Precise outdated checks**: a skill counts as outdated only when its own directory changes upstream, not when anything else in the repo does.
- **Two interfaces**: scriptable subcommands, and a bubbletea dashboard when run without arguments.
## Contents
- [How it works](#how-it-works)
- [Installation](#installation)
- [Usage](#usage)
- [File formats](#file-formats)
- [Development](#development)
## How it works
```
skm add / update ──► skills.json + skills.lock.json ──► home-manager switch ──► ~/.claude/skills/<name>
(in your Nix flake) (builtins.fetchTree) ~/.agents/skills/<name>
```
1. `skills.json` is the manifest: which repos, which skills, optional branch or tag. Edit it by hand or with `skm`.
2. `skills.lock.json` is written only by `skm`. It holds the locked rev and `narHash` from `nix flake prefetch`, plus each skill's resolved subpath.
3. The home-manager module reads the lock at evaluation time and links each skill individually, so the target directories stay writable for other tools.
`skm` never commits and never fetches with git itself; all fetching goes through `nix flake prefetch`. After a change it prints a suggested commit message and tells you to rebuild (or runs your rebuild with `--switch`).
## Installation
> [!IMPORTANT]
> Requires Nix with flakes and [home-manager](https://github.com/nix-community/home-manager). The `nix` binary comes from your system, so it matches your daemon.
Add the flake as an input and import its home-manager module:
```nix
{
inputs.skill-manager.url = "git+https://git.jokresner.de/johannes/skm";
# in your home-manager configuration
imports = [ inputs.skill-manager.homeModules.default ];
programs.skill-manager = {
enable = true;
manifestDir = "/home/me/Repos/nix/home/agents"; # working tree, skm writes here
lockFile = ./home/agents/skills.lock.json; # same file, read at eval time
switchCommand = "cd ~/Repos/nix && nixos-rebuild switch --sudo --flake .";
};
}
```
| Option | Default | Description |
|---|---|---|
| `manifestDir` | | Directory holding `skills.json` and `skills.lock.json` |
| `lockFile` | | The lockfile as a path inside your flake; pure evaluation can't read `manifestDir` |
| `targets` | `[ ".claude/skills" ".agents/skills" ]` | Directories, relative to home, that get one symlink per skill |
| `switchCommand` | `""` | Command `skm update --switch` runs to apply a new lock |
| `package` | this flake's `skm` | The `skm` package to install |
The module installs `skm` and writes `~/.config/skill-manager/config.json` with `manifestDir` and `switchCommand`.
> [!WARNING]
> For private `git+ssh://` sources, the rebuild must evaluate as your user so `fetchTree` can use your SSH agent. Use `nixos-rebuild switch --sudo …` instead of `sudo nixos-rebuild …`.
## Usage
Run `skm` with no arguments to open the dashboard. It lists every source and its skills, and checks all sources upstream in the background.
| Key | Action |
|---|---|
| `↑`/`↓`, `j`/`k` | Move |
| `u`, `enter` | Review the selected source's update |
| `U` | Review all outdated sources |
| `a` | Add a source (URL prompt, then the skill picker) |
| `d` | Remove the selected skill or source |
| `r` | Check upstream again |
| `q` | Quit |
In the diff review, `y` accepts a source, `n` skips it, and `tab`/`shift+tab` move between files.
### Commands
```sh
skm add github:mattpocock/skills # pick skills interactively
skm add github:mattpocock/skills --skill tdd,grilling=grilling-mp
skm add git+ssh://git@host/me/skills --ref main --all
skm list # installed skills, source, short rev
skm outdated # changed, added and removed skills upstream
skm update # review diffs, then write the lock
skm update tdd --yes --switch # no review, then run switchCommand
skm remove tdd # or: skm remove --source mattpocock
skm import --diff # migrate from vercel's skills CLI
```
| Command | Description |
|---|---|
| `add <url> [--ref R] [--name N] (--skill a,b=alias,dir/c \| --all)` | Prefetch a repo, choose skills, write manifest and lock. Adding to an existing source keeps its pin. |
| `remove <name>` / `remove --source <source>` | Remove one skill (and the source once it's empty), or a whole source |
| `list` | Installed skills with source, rev and path |
| `outdated [source\|skill...]` | Prefetch sources in parallel and report changes |
| `update [source\|skill...] [--yes] [--switch]` | Review and apply updates. Without a terminal, diffs are printed and confirmed on stdin. |
| `import [--from lock] [--local dir] [--diff]` | Import `~/.local/state/skills/.skill-lock.json` and compare against committed skill copies |
The global `--dir DIR` flag overrides `manifestDir`. Sources are flake refs: `github:owner/repo`, `git+ssh://…` or `git+https://…`.
> [!NOTE]
> Skills live in the read-only Nix store, so you can't edit them in place. To change one, fork it or move it into your own repo.
Non-goals: non-git sources (tarballs, registries, local paths), patches or overlays, per-skill targets or pins, and auto-commit.
## File formats
`skills.json`:
```json
{
"sources": {
"mattpocock": {
"url": "github:mattpocock/skills",
"skills": ["tdd", "prototype", { "name": "grilling", "as": "grilling-mp" }]
},
"own": {
"url": "git+ssh://git@host/me/skills",
"ref": "main",
"skills": "*"
}
}
}
```
- `"*"` installs every skill in the repo, including ones added upstream later.
- `"as"` renames a skill. Two skills with the same installed name are an error.
- `"path"` picks a skill by directory, for repos that ship the same name twice.
- To hold one skill back, add a second source entry for the same repo with its own `ref`.
`skills.lock.json` (written by `skm`):
```json
{
"version": 1,
"sources": {
"mattpocock": {
"locked": { "type": "github", "owner": "mattpocock", "repo": "skills", "rev": "abc123…", "narHash": "sha256-…" },
"skills": { "tdd": "skills/tdd", "prototype": "skills/prototype", "grilling-mp": "skills/grilling" }
}
}
}
```
## Development
The dev shell provides Go and git (`nix develop`, or `devenv shell`).
```sh
go test ./... # unit, TUI and end-to-end tests
nix flake check # builds the package and runs the tests
nix build .#skm
```
The end-to-end tests create a temporary `git+file://` repo and need `nix` on `PATH`. They skip inside the Nix build sandbox, so run them with `go test` in the dev shell.
> [!TIP]
> After changing `go.mod`, set `vendorHash` in `flake.nix` to `lib.fakeHash`, build, and copy the hash Nix reports.
| Path | Contents |
|---|---|
| `cmd/skm/` | CLI entry point and subcommands |
| `internal/core/` | add, remove, outdated, update and import operations |
| `internal/fetch/` | `Fetcher` interface and the `nix flake prefetch` implementation |
| `internal/manifest/`, `internal/lock/` | `skills.json` and `skills.lock.json` |
| `internal/skills/` | `SKILL.md` discovery and subtree comparison |
| `internal/tui/` | bubbletea dashboard, picker and diff review |
| `nix/module.nix` | home-manager module |