Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .claude/skills/forklift-doctor/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
name: forklift-doctor
description: Eight drift checks for a fork managed by forklift. Run from the target fork repository. Each check is a self-contained command with a pass criterion and exact remediation.
---
<!-- forklift v1 -->

# forklift-doctor

The `forklift doctor` CLI runs all eight checks against the fork repo you are standing in. Each check is a self-contained command with a pass criterion and exact remediation.

## Setup

```bash
cd "$(git rev-parse --show-toplevel)"
export FORKLIFT=<absolute path to the forklift checkout that contains this skill>
test -f .forklift/registry.yaml || echo "MISSING: .forklift/registry.yaml (run forklift-init)"
```

Registry-scoped checks (1-4, 6) read `.forklift/registry.yaml`. Harness checks (5, 7) additionally read `.forklift/harness.lock` (written by `forklift install`).

## Usage

```bash
bun "$FORKLIFT/bin/forklift" doctor # all checks, human output
bun "$FORKLIFT/bin/forklift" doctor --check 6 # one check
bun "$FORKLIFT/bin/forklift" doctor --check 1,2,6 # several
bun "$FORKLIFT/bin/forklift" doctor --check 1-8 # range (same as default)
bun "$FORKLIFT/bin/forklift" doctor --list # print the check table, run nothing
bun "$FORKLIFT/bin/forklift" doctor --json # {registry, checks: [{id,name,status,lines}], ok}
bun "$FORKLIFT/bin/forklift" doctor --registry .forklift/registry.yaml # explicit path (default)
bun "$FORKLIFT/bin/forklift" doctor --help
```

The registry is validated against `schema/registry.schema.yaml` before any check runs; a schema error is a hard failure naming the registry. Human output is one block per check with its PASS/FAIL line and findings, then a final `doctor: N passed, M failed` summary; exit 0 only when every executed check passes. Check 7 derives the forklift root from the CLI's own location, so `FORKLIFT` is no longer required for it (still honored when set).

## Check reference

Run checks in order 1-8; 1-4 and 8 must pass before syncing, 5-6 before rebaselining, 7 any time. A script error (missing `harness` block, registry unparseable) is a hard failure with the setup remediation.

1. **Registry completeness** — no fork commit may touch a source path the registry does not claim. **PASS** = `PASS: registry covers every fork-touched source path (<range>)`. **FAIL** = one `UNREGISTERED` line per path (range `<upstream.remote>/<upstream.branch>..<fork.branch>`). **Remediation (per path):** find the owning feature with `git log --oneline -1 <upstream_branch> -- <path>` and `git log --oneline -1 <fork_branch> -- <path>`; then either register the path in an existing feature's `owned_paths`, add a new feature, add the file to `divergences` (take-upstream policy), or record a `removals` entry if the path is absent from the fork on purpose. A path covered by a `removals` entry counts as claimed: the fork deleted it on purpose, so it can never live in `owned_paths` (check 2 would report it stale). Re-run check 1 after every registry edit.

2. **Stale paths** — every `owned_paths` entry must exist on disk in the fork; a registered path with no file means prefer-ours resolutions on the next sync would resurrect deleted files. **PASS** = `PASS: all registered owned_paths exist`. **FAIL** = one `STALE` line per missing entry. **Remediation (per entry):** if the fork moved the file, update the registry path; if the fork deleted the file deliberately, drop the entry (or convert the feature to `divergences`/`removals` if the whole feature is gone). Never leave a `STALE` line: prefer-ours on a phantom path silently resurrects dead files.

3. **Feature coverage** — every feature that owns product behavior (matches `harness.checks.behavioral_source_regex`) must declare `protecting_tests` or a `coverage_exempt` reason. Draft features are reported, not enforced. **PASS** = `PASS: <n> behavioral feature(s) covered (exempt …, non-behavioral …, draft …)`. **FAIL** = one `UNCOVERED` line per feature. **Remediation:** add at least one test file (relative to repo root) to the feature's `protecting_tests`, or set `coverage_exempt: "<why no test can cover this>"` on the feature. A red test then acts as the feature-loss alarm across upstream refactors.

4. **Import liveness** — every JS/TS owned source must be imported by at least one file outside its own `owned_paths`, unless exempted; this catches a feature that kept its file but lost its `import "./pi"` wiring. **PASS** = `PASS: <n> owned source bucket(s), all imported` (or `SKIPPED:` when the registry owns no JS/TS sources — import liveness cannot apply). **FAIL** = one `ORPHAN` line per unimported source. **Remediation (per orphan):** (a) the importer was lost - restore the wiring (re-add the import side effect); (b) the source is a legitimate entrypoint / runtime-discovered plugin / spawned script with no static importer - add `liveness_exempt: "<reason>"` to its feature; (c) the path is wrong - fix the registry. Scope note: this check understands JS/TS import graphs; non-JS owned paths are skipped by design, so languages without quote-resolved imports need `liveness_exempt` instead.

5. **Commit survival** — the fork's commit count must equal `expected_fork_commit_count`; drift means commits were dropped or added since the last verified rebuild/rebase. **PASS** = `PASS: expected=N actual=N`. **FAIL** = `DRIFT:` line with both numbers. **Remediation:** confirm the delta with `git log --oneline <upstream_remote>/<upstream_branch>..<fork_branch>` (the same local-branch range this check uses) - dropped commits must be recovered (re-registered or cherry-picked), deliberate additions recorded. Only then update `expected_fork_commit_count` and re-run this check.

6. **Deletion audit** — a path still registered under `owned_paths` that exists in upstream history but not at the current upstream tip means the next rebase would delete it; never-existed paths (fork-new files) are informational. A path the fork keeps as a deliberate port can be acknowledged: add it to the owning feature's `upstream_deleted_paths` (`path` required; `upstream_removed_in`, `note` optional provenance) and check 6 downgrades it to an informational `PORT (acknowledged) <path> | <feature>` line instead of failing. **PASS** = `PASS: no registered path deleted upstream (checked …, fork-new …)`. **FAIL** = one `DELETED-UPSTREAM` line per unacknowledged path. **Remediation (per path):** the porting protocol - upstream deleted it, the fork still needs it, so the rebase will drop it. Options: keep the fork copy and acknowledge it via `upstream_deleted_paths`, absorb the upstream replacement (update registry to the new upstream path), or drop the feature if upstream retired it deliberately. Resolve every line before syncing.

7. **Version drift** — `harness.lock` is the authority on the installed template version; every stamped install must match it, and the registry's `harness.version` must match the lock. **PASS** = `PASS: <n> stamped install(s) match harness.lock v<n>` (either all stamps match, or the target has no installs). **FAIL** = a `DRIFT` line naming file + expected/actual, or a registry/lock mismatch, or a missing lock. **Remediation:** version drift means the harness moved without reinstalling - re-run `forklift render` and then `forklift install` in the target repo to restamp, or set `harness.version` in the registry back if it was edited by hand. Never edit a stamp line directly.

8. **Upstream drift forecast** — upstream-changed files since the merge-base that intersect fork-owned paths, ranked by resolution policy and gated on protecting_tests. **PASS** = `PASS: conflict surface <n> upstream-changed file(s) (graft <g>, prefer-ours <o>, take-upstream <u>, unrelated <r>) - all gated`; when upstream has not moved: `PASS: no upstream drift since merge-base <sha8>`; when there is no merge base: `FAIL: no merge base between <fork.branch> and <up> (fetch <upstream.remote> first)`. **FAIL** = `FAIL: <k> conflict-surface file(s) belong to feature(s) with no protecting_tests (…)` plus one ` UNGATED <path> | <feature>` per ungated surface file. **Surface lines** = ` GRAFT <path> | <feature> | structural|whitespace-only` (file carries `owned_symbols` — MERGE PATH), ` OURS <path> | <feature> | structural|whitespace-only` (file in a feature's `owned_paths` — prefer ours), ` UPSTREAM <path> | take upstream` (in `divergences`), plus ` DRAFT (reported only) <feature>` for draft features. **INFO line** = ` INFO: harness.checks.semantic_drift is unset - the Conflict Walk renders git-only; set {tool: difftastic} (mise: "github:Wilfred/difftastic") when difftastic can be installed on this fork`. Never a failure: it asks the operator to add `"github:Wilfred/difftastic" = "latest"` to the fork's `mise.toml` `[tools]`, run `mise install`, set the registry key, and re-render — the alternative (difftastic uninstallable) is a legitimate answer. **Remediation (per UNGATED):** add `protecting_tests` (or a `coverage_exempt` reason) to the named feature before syncing, so the resolution has a gate; if the surface is larger than the sync can absorb, shrink contact surface per the skill's § Guidelines. Re-run `forklift doctor --check 8`.
92 changes: 92 additions & 0 deletions .claude/skills/forklift-init/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
name: forklift-init
description: Bootstrap forklift in a target repository - classify the repo as fork or host, discover the agent tools in use, scaffold .forklift/registry.yaml (fork role) or document the adapter layout (host role).
---
<!-- forklift v1 -->

# forklift-init

Run from the **target** repository root (`cd` there first). `FORKLIFT` is the absolute path of the forklift checkout containing this skill:

```bash
cd "$(git rev-parse --show-toplevel)"
export FORKLIFT=<absolute path to the forklift checkout>
bun --version || echo "WARN: bun missing - forklift tooling requires it"
```

## 1. Classify the target

```bash
cd "$(git rev-parse --show-toplevel)"
echo "--- remotes:"; git remote -v
echo "--- forklift dir:"; ls -d .forklift 2>/dev/null || echo "none"
```

- **fork** - the repo rebase-syncs against an upstream project: `.forklift/` exists, or `git remote -v` shows an `upstream` (or `origin` pointing at a sibling clone) remote it tracks and rewrites history against.
- **host** - the repo IS the upstream other repos fork: no upstream-remote relationship, no `.forklift/`.

State the classification and the evidence (remote URLs) before proceeding.

## 2. Discovery

**Fork role - probe which fork tooling targets this repo:**

```bash
bun "$FORKLIFT/bin/forklift" render --help >/dev/null 2>&1 && echo "forklift render: runnable" || echo "forklift render: NOT runnable (bun missing?)"
npx --no-install create-opencode --help >/dev/null 2>&1 && echo "create-opencode: available (opencode scaffold)" || echo "create-opencode: not available"
```

**Both roles - scan agent-tool directories** using root-relative paths from `$FORKLIFT/adapters/tools.yaml`:

```bash
cd "$(git rev-parse --show-toplevel)" && FORKLIFT="$FORKLIFT" bun -e '
const tools = Bun.YAML.parse(await Bun.file(`${process.env.FORKLIFT}/adapters/tools.yaml`).text());
for (const t of tools.tools) {
const ip = t.install_paths ?? {};
for (const [key, dir] of Object.entries(ip)) {
if (!dir) continue;
let count = 0;
try {
for await (const f of new Bun.Glob("**/*").scan(dir)) {
if (/\.(md|txt)$/.test(f)) count++;
}
} catch {}
console.log(`${t.id} ${key}: ${dir} - ${count} file(s)`);
}
}
'
```

Interpretation: `role: fork`/`both` entries are candidate **install** targets for this fork; `role: host` entries document the host project's layout (their counts are the `examples` a fork may record in `adapters/tools.yaml`).

## 3. Fork role - scaffold the registry

```bash
cd "$(git rev-parse --show-toplevel)"
mkdir -p .forklift
cp "$FORKLIFT/templates/registry.template.yaml" .forklift/registry.yaml
```

Then fill `.forklift/registry.yaml` - every field is documented in `$FORKLIFT/schema/registry.schema.yaml`:

1. `harness.fork` / `harness.upstream` - from `git remote -v` (remote names and branches), plus `sync_command` (how to start a sync: for a manual fork, `git rebase <upstream>/<branch>`), `fork_doc` (the doc that records sync points; `.forklift/README.md` when the repo keeps no other), and `sync_runner` **only** when the fork runs a forklift-style runner script with `--verify`/`--revert`/`--tag` flags - omit it otherwise, and the runner-flag sections are dropped from the rendered skill instead of rendering nonsense flags onto a plain `git rebase`.
2. `harness.project` - inspect the tree: `source_roots` (globs of fork source dirs), `test_globs` (test dir layouts), `conflict_marker_globs` (the file classes where conflict markers must be inspected), `package_aliases` (package name -> source dir for bare-specifier import resolution; from `package.json` workspaces if present).
3. `harness.checks` - `behavioral_source_regex` (paths whose features need protecting tests), `footprint_baseline` path once one exists, `excludes` for harness-generated paths, `semantic_drift: {tool: difftastic}` - enable it whenever difftastic can be installed for this fork: add `"github:Wilfred/difftastic" = "latest"` to the fork's mise.toml [tools], run `mise install`, confirm with `mise exec -- difft --version`, then set the key so the rendered skill's Conflict Walk reads conflicts structurally instead of by line diff. Omit it only when the tool cannot be installed here; the walk stays git-only and doctor check 8 says so.
4. `features` - enumerate fork-owned work from `git log --name-only <upstream>/<branch>..<fork>/<branch>` grouped by file overlap; each entry: `name`, `owned_paths`, and either `protecting_tests` or `coverage_exempt`. Put `status: draft` on every generated feature: the fresh registry is a migration worklist, and doctor checks 3 and 4 report draft findings without failing (protecting tests, import liveness) until you promote each feature to `active` once its worklist items are cleared.
5. `divergences` - upstream-owned files the fork deliberately does not override (always take upstream).
6. `expected_fork_commit_count` - `git rev-list --count <upstream>/<branch>..<fork>/<branch>`.

Then generate the skill and audit:

```bash
bun "$FORKLIFT/bin/forklift" render --registry .forklift/registry.yaml
bun "$FORKLIFT/bin/forklift" install
```

`forklift render` (default template `templates/SKILL.md.tmpl`) writes `sync-upstream/SKILL.md` into every adapter skills directory that already exists from step 2's scan; if none exists yet, create the directory this fork's agents use (e.g. `.omp/skills`) and re-render - until then the output is staged at `.forklift/SKILL.md`. `forklift install` then stamps the static skills into the same adapter directories, installs the sync command, and writes `.forklift/harness.lock`, which doctor check 7 requires.

Run `forklift doctor` checks 1-8 (skill in `$FORKLIFT/skills/forklift-doctor/SKILL.md`) and fix every finding before the first sync.

## 4. Host role - document the layout

Do **not** create `.forklift/`. From step 2's scan, record which adapter directories exist and their counts; if the counts differ from the `examples` block in `$FORKLIFT/adapters/tools.yaml`, report the corrected numbers so the table can be refreshed. Host repos consume forklift only through fork-side installs (`forklift install` run against them) - mention which `role: fork`/`both` tools could target this repo.
Loading