Metadata-Version: 2.4
Name: slopkeeper
Version: 0.3.0
Summary: Someone has to clean up after your agents. Inventory, plan, human gate, all-or-nothing apply with undo: the agent classifies, the human approves, and nothing is ever deleted.
Author: Greg Brandt
License-Expression: MIT
Project-URL: Homepage, https://github.com/brandtg/slopkeeper
Project-URL: Repository, https://github.com/brandtg/slopkeeper
Project-URL: Issues, https://github.com/brandtg/slopkeeper/issues
Keywords: agent,corpus,organization,cli
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Utilities
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

<!--
SPDX-FileCopyrightText: 2026 Greg Brandt <brandt.greg@gmail.com>

SPDX-License-Identifier: MIT
-->

# SlopKeeper

Someone has to clean up after your agents. SlopKeeper does: inventory,
partition and scaffold messy file corpora — the tool side of
"each folder is a bot". A calling agent (Claude Code, Hermes, anything
that shells out) does the classification; SlopKeeper does everything else:
inventory, plan validation, reference-integrity checking, all-or-nothing
execution with a journal and undo, and the AGENTS.md/STATE.md layer that
makes the result agent-navigable.

**Zero dependencies. Python 3.11+ (oldest supported CPython) stdlib only.
No LLM calls. No network.**

## Install

Requires Python 3.11+ (what Debian 12 / RHEL 9 ship; anything newer
works). Zero dependencies, so the install is tiny.

With [pipx](https://pipx.pypa.io) (recommended — puts `slopkeeper` on your
PATH in its own venv):

```bash
pipx install slopkeeper
```

Also fine: `uv tool install slopkeeper`, or `pip install slopkeeper`
(in a virtualenv, or `pip install --user` if you prefer).

Verify:

```bash
slopkeeper --version
```

## Quickstart

SlopKeeper's whole model is *agent classifies, human approves, SlopKeeper
moves* — so the other half of installing it is making sure your agent
knows how to drive it. The canonical protocol ships **inside the
package**; the one-time setup is to install the skill and let your agent
read the guide:

```bash
slopkeeper skill install claude    # or: opencode, hermes — or a skills-dir path
slopkeeper guide                   # the full agent protocol (AGENT_GUIDE.md)
```

Each skill target is a known agent name (`claude`, `opencode`, `hermes`)
or a path to a skills directory. An already-present skill is left alone
with a warning; `--force` refreshes it. The skill is packaged inside the
wheel, so it always matches the version that installed it.

Then just ask your agent to organize a directory. It will read `slopkeeper
guide` and drive the rest; the loop looks like:

```bash
slopkeeper doctor ~/workspace                        # preflight: size, mess, strategy
slopkeeper inventory ~/workspace --fast --summary    # what's there (token-conscious)
slopkeeper draft ~/workspace                         # or: the agent authors plan.json itself
slopkeeper plan validate plan.json ~/workspace
slopkeeper plan render plan.json ~/workspace          # the human gate — read this
slopkeeper apply plan.json ~/workspace --execute     # all-or-nothing, journaled
slopkeeper scaffold plan.json ~/workspace --execute  # writes AGENTS.md/STATE.md
```

Humans: the rendered plan (`plan render`) is your approval gate — read
it, edit the JSON, or say no. If you'd rather drive by hand, run bare
`slopkeeper` for the interactive REPL (below).

## How it works

```
inventory → agent drafts plan → validate → render (HUMAN GATE)
          → apply --execute → scaffold → done (undo possible)
```

**Tending a corpus that's already organized** (the usual case after the
first sweep) is the cheap loop: `status` diffs against the last tend's
manifest, the agent triages only the new slop, and a delta plan moves
just that. See AGENT_GUIDE.md — "Re-tending".

The commands:

- **doctor** — preflight: size, messiness, strategy suggestion, token
  estimate, advice. Start here.
- **inventory** — structured JSON of the corpus: files, heads, titles,
  dir stats, date/prefix/ext clusters, a cross-reference index of
  which files mention which filenames, and (0.3.0) a parallel `imports`
  index of which files IMPORT which — python, js/ts, go and rust
  statements resolved against the tree. Token-conscious modes for big
  corpora (`--fast --summary`, or `--out` to land the full JSON in a
  file with counts alone on stdout).
- **clusters** — similarity hints for the planning agent: TF-IDF content
  clusters, scrape pairs, byte-identical copies, hub files. Hints, never
  a plan. `--out` lands the full payload in a file, counts on stdout.
- **refs** — every site that cites a given filename; the
  grep-before-move check behind reference integrity. The payload is
  honest about the query (`exists`, `ambiguous`, `ambiguous_paths`) and
  about its own limits (`truncated_files` + the `citation_scan_truncated`
  warning when a file was read only as far as the 512 KiB cap). Import
  statements naming the path come back separately (`import_count`,
  `imports` with `kind: "import"`) — same question, different answer,
  because the rewrite pass fixes citations and never an import.
  `--dangling` lists path-ish citations that resolve to nothing.
- **propose** — the layout fork as data: mechanical candidate partitions
  (by-project, by-role, by-topic, by-kind, hybrid), each priced with move
  counts, citation-break counts, unresolved and orphaned estimates.
  Read-only; the agent compares, then authors the real plan.
- **status** — diff since the last tend (manifest in `.slopkeeper/`):
  new/modified/removed files, folder health, still-unresolved items.
  `--all` returns one count-level digest over every registered root.
- **roots** — registry of tended corpora at
  `$XDG_CONFIG_HOME/slopkeeper/roots.json` (`SLOPKEEPER_HOME` overrides):
  `roots add/remove/list`, feeding `status --all` for scheduled tending.
- **draft** — auto-drafts a delta plan for the new slop. A starting
  point for the agent to reclassify, not a decision.
  `--suggest-code-edits` also proposes the path literals code builds out
  of separate strings (`join(base, "sub", "data")` holds no path token, so
  the rewrite pass cannot reach it) as ordinary plan edits.
- **plan** — the only write path. A JSON document of `moves` (from → to +
  reason), `keep`, `unresolved`, `folders` (to scaffold), `verify` (shell
  checks to run after the tend), and the corpus
  fingerprint it was authored against — required: validate and apply
  refuse an unbound plan (`plan_no_based_on`; `plan render` warns, never
  fabricates). Validated hard: path escapes,
  stale sources, collisions, nested moves, cycles, incomplete coverage.
  `plan validate` / `plan render` / `plan schema` are the subcommands.
- **apply** — all-or-nothing execution. Dry-run by default; refuses a
  corpus whose fingerprint changed since planning, and one that churned
  under the walk (`corpus_unstable` — files that vanished or denied
  `stat` mid-scan are counted in `stats.skipped_unstatable`, never
  skipped silently); refuses moves that
  cross symlinked paths (`symlink_escape`; `--allow-symlinks` for a
  deliberate traversal); pre-flights every
  destination before touching anything and re-checks it inside the
  write itself (an atomic no-replace link/unlink — a destination created
  mid-run is refused, not clobbered); journals every move with a
  content hash, one journal per tend, and undo VERIFIES those hashes
  (a file edited after the tend comes back flagged `content_changed`);
  flags every move cited from stay-put files. `data.path_map` gives the
  `{old: new}` dict for the moves that happened, so a caller's cached
  paths survive a tend. A plan (or any folder it declares) may carry
  `verify` commands: they run after the moves, rewrites and edits, and
  the first non-zero exit ROLLS THE WHOLE TEND BACK through the journal
  (`verify_failed`, exit 2, captured output in `data.verify`) unless
  `--no-auto-undo`. On a git corpus, tracked files move with `git mv`,
  and sources with uncommitted changes refuse the tend (`git_dirty`;
  `--force` / `--no-git`) — `data.git` reports the commit and the index.
- **move** — one bulk move (src dst root): builds the one-move plan,
  runs it through the same validate → gate → journal machinery, and
  renders the human gate. Dry-run by default; `--execute` runs it.
- **scaffold** — writes the folder-bot layer: root `AGENTS.md` roster,
  per-folder `AGENTS.md` and `STATE.md`. Never overwrites — existing
  files get a `*.slopkeeper-suggested` sibling instead.
- **undo** — reverses one journal exactly (restores, prunes empty dirs).
  One journal per tend — same-second tends get `-2`, `-3` siblings, so
  undo never reverts a neighbor tend. The journaled sha256s are verified
  on restore: a file edited after the tend still comes back, flagged
  `content_changed`. `data.path_map` is the inverse of apply's
  `{post-tend: restored}`. Undo never shells out to git, so when the tend
  used `git mv` it warns (`git_index_staged_moves`) and tells you to
  `git reset` — the files come home from the journal, the index from git.
  Takes one journal; name it (see `.slopkeeper/journal-*.jsonl`).
- **strategies** — partitioning rubric packs the agent reads: `role-bots`
  (folder-as-bot), `topics`, `projects`, `by-kind` (mechanical baseline),
  `hybrid` (default). Your own pack is a file, not a release: drop
  `<id>.json` in `$XDG_CONFIG_HOME/slopkeeper/strategies`,
  `$SLOPKEEPER_HOME/strategies`, or `<root>/.slopkeeper/strategies` and
  it overrides the shipped pack by id. `strategies list` shows every pack
  with its `origin`, `strategies dirs` names the search path, and a
  malformed pack fails loudly at load (`strategy_bad_pack`) instead of
  inside scaffold.
- **guide** — prints the full agent protocol (also readable via the
  installed skill and AGENT_GUIDE.md, shipped in the wheel).
- **skill** — `skill install <agent|dir>` copies the packaged SKILL.md
  into an agent's skills directory (`claude`, `opencode`, `hermes`, or a
  path); existing files are left alone unless `--force`. The one-time
  setup that teaches your agent the protocol.

### The REPL (bare `slopkeeper`)

Run `slopkeeper` with no subcommand and you get an interactive
`/command` prompt — the human front door for exploring a corpus and
tending it by hand. It drives the exact same functions as the JSON
subcommands (no new write path); every `--execute` stops for an explicit
y/N, and the default is no. Since 0.2.10 that claim is tested, not
aspirational: `/render` calls the same `build_gate_report` the CLI's
`plan render` does (rewrite summary, stragglers, anchor and import
risks), `/refs` answers the honest query questions and takes
`--dangling`, and `/apply` takes `--force`, `--strict-references` and
`--allow-partial`. A human and an agent looking at the same corpus see
the same thing.

```text
$ slopkeeper
> /use ~/Documents/notes     # point it at a corpus
> /status                    # what changed since the last tend
> /new                       # the new slop, with titles and heads
> /draft                     # auto-draft a delta plan
> /moves  /show 1  /no 1  /defer 1  /dest 1 api/   # decide per move
> /plan                      # compile decisions, validate, save
> /render                    # read the human gate (same as plan render)
> /apply --force             # dry-run → [y/N] → execute
> /refs acme.md              # citations: exists? ambiguous? capped?
> /refs --dangling           # path-ish references that resolve to nothing
> /scaffold                  # [y/N] → write the AGENTS.md layer
> /undo                      # list journals, dry-run, execute
```

`/load <plan.json>` brings in a plan your agent wrote for move-by-move
review. Readline history persists, and Tab completes command names,
filesystem paths, and move/journal numbers. `/help` lists everything.

First-tend authoring (naming a taxonomy from a full inventory) is agent
work — point your agent at AGENT_GUIDE.md.

## Design notes

- The hard parts of corpus organization are *judgment* (the agent's),
  *reference integrity* (grep-before-move, baked into validate/apply),
  and *the human gate* (rendered markdown of every move with reasons and
  risks). The tool makes the gate cheap; it does not try to remove it.
- Fingerprint gating means a plan can never act on a corpus it wasn't
  written against — the "silent drift" failure mode is closed.
- Journals are JSONL — one file per tend, each line fsync'd whole, every
  move carrying its sha256 — and undo VERIFIES those hashes on the way
  back: exact, reversible, `content_changed` when a file was edited after
  the tend, empty dirs it created pruned. Nothing is ever deleted.
- Strategies are JSON rubric packs, not code: the agent reads them like
  documentation, and new strategies are new files, not releases.
- Code corpora get the same discipline without a parser dependency. Imports
  are detected, resolved and priced — never rewritten, because silently
  editing an `import` line is how a tidy tool breaks a build; the agent
  decides with `import_risk_moves` in front of them. String-built paths,
  which no rewrite pass can reach, come back as ordinary plan edits. The
  tend's own `verify` commands have the last word — a non-zero exit rolls
  the whole tend back through the journal — and on a git repo tracked files
  move with `git mv` behind a dirty check, so the diff stays reviewable.

## For developers

Everything above is the released package. To work on SlopKeeper itself:

From a local clone (or `uv tool install .` / `python3 -m pip install .`):

```bash
git clone https://github.com/brandtg/slopkeeper && cd slopkeeper
pipx install .
```

Install straight from GitHub without cloning (pin a tag as needed):

```bash
pipx install git+https://github.com/brandtg/slopkeeper.git@v0.2.0
```

Run from a checkout without installing anything:

```bash
make run ARGS="doctor ~/workspace"
# or, without uv:
PYTHONPATH=src python3 -m slopkeeper doctor ~/workspace
```

The canonical gate — lint, tests, license headers; what CI runs:

```bash
make check
```

The agent protocol lives in AGENT_GUIDE.md — shipped in the wheel and
printable via `slopkeeper guide`. Design rationale lives in module
docstrings and comments; audit reports land under docs/.

## License

MIT.
