Use when working ON the X4 toolkit itself: editing tools/, gates/, scripts/, hooks or the agent/ source, regenerating agent trees, running the suite, building or trusting a derived artifact (effective store, BaseX x4raw/x4eff, x4xref), running concurrent sessions or worktrees, handling a suspected tool bug, or deciding whether tools are trustworthy enough to lock a modlist.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of X4 Toolkit Dev?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/wingedguardian-x4-toolkit-dev-x4-ai-toolkit)
---
name: x4-toolkit-dev
description: Use when working ON the X4 toolkit itself: editing tools/, gates/, scripts/, hooks or the agent/ source, regenerating agent trees, running the suite, building or trusting a derived artifact (effective store, BaseX x4raw/x4eff, x4xref), running concurrent sessions or worktrees, handling a suspected tool bug, or deciding whether tools are trustworthy enough to lock a modlist.
---
# Working ON the toolkit (maintainer guidance)
Relocated verbatim from the project instructions (built from `agent/instructions/`), which must fit
Codex's 32,768-byte AGENTS.md limit. A player or modder using the tools does not need it;
anyone changing them does.
# Toolkit-internal routing (Python API and maintainer gates)
| Question shape | Tool | Not this |
|---|---|---|
| **"every XML a mod owns?"** | **`_scan.iter_mod_xml` / `iter_mod_xml_bytes`** (loose THEN packed) | ✗ **`_cat.mod_vfs`** — catalogs only; returns `{}` for a loose mod and says nothing. It now WARNS in that exact case; pass `packed_only=True` when you really mean catalogs |
| **"which MODS count?"** | **`_registry.mods("active")`** = what the engine loads · **`_registry.mods("installed")`** = what is on disk. Scope is positional and REQUIRED | ✗ `_registry.scan_installed()` — that is only ever the on-disk answer, and reaching for it silently chooses it |
| **"is this mod installed / active / banned?"** | **`_registry.mods("active"\|"installed")`** — and for a ban, grep the profile by **MANIFEST ID** (a workshop mod is `ws_<numeric id>`), never by name | ✗ reading the profile `content.xml` as an inventory — it is a DECISION LOG: **287 of 348 entries are fossils**, **54 of 115 installed mods are absent**, and a name-shaped search finding nothing is the WRONG QUERY, not evidence (#30) |
| **"scan EVERY installed mod for X"** (an ad-hoc corpus sweep) | **`_scan.iter_corpus_xml(ext, report)`** + **`CorpusScan.verdict(hits, noun)`** — it states the scanned set, so a zero is an ABSENCE and not a non-answer. | a hand-rolled loop over `extensions/` — loose-only, and silent about what it never opened |
| **"every base+DLC vpath?"** | **`_effective.base_vpaths`** (loose THEN packed; `reference_vpaths` is its `assets/`-only filter) | ✗ `reference.rglob("*.xml")` — loose-only, so the two mini-DLC are invisible. Written **7 times**; now gated by `tests/test_no_loose_only_reference_walk.py` |
| mutation-test code? | **`gates/mutation_probe.py`**, but ONLY the 10 `x4validate/_*.py` files it names -- it takes no target argument | hand-mutating anything else (gates, hooks) without clearing `__pycache__`: a same-length mutant restored within one SECOND leaves its BYTECODE behind |
# Core Principle: A Step That Narrows Data MUST Announce It
**Every tool defect found in this workspace has had one shape: a step that narrows the data
and reports success anyway.** One class, not an assortment — and the enumeration variant
alone was written **five times**. What the instances cost, MEASURED: a `continue` that dropped
an op yet marked it applied (**858 ops**, so `x4effective` served vanilla values for real
overrides); a walk that stopped descending (**9,197 of 13,291** ship attributes, the whole
flight model, absent); a loose-only `rglob` or the wrong source list across **7 files**
(x4xref returned **0 rows from 13 real files**); the wrong SET, on-disk where engine-loadable
was meant, which let **Tier B resolve a selector against a DISABLED mod and report OK** —
a false pass in the mode built to catch no-ops; a denominator taken from the artifact it
audits (COVERAGE COMPLETE over a tree missing **119 documents**, which **0 of 210** failures
could ever name); and `el.get("id")` skipping an absent attribute, which would have indexed
**zero entities while reporting success**.
**The rule: a tool that returns nothing must say whether that is an ABSENCE or a NON-ANSWER.**
`tools/basex/ask.py` is the standard — it refuses to render a zero as a finding without a
coverage denominator. Anything that cannot make that distinction is a defect, not a limitation.
- **State the SCANNED SOURCE SET, not just the failed reads.** A blind spot is by definition
not among the files you tried and failed to parse: "base + **6** DLC + 71 mods" when 8 DLC
exist is self-evident on sight, and reporting only parse failures hid exactly that.
- **One implementation, asked for by everyone else.** Two of those five files already carried a
comment explaining the bug, and it was written again anyway. Only a shared helper plus a test
banning the hand-rolled form stops the next one.
- **The same wrong answer can have different causes.** A sibling gate carried the identical
hand-rolled walk and failed for an unrelated reason. Fix the occurrence on its own evidence.
**When you find one, search for the SHAPE, not the symptom** — scope limits, depth limits,
singular reads, silent skips, two paths answering one question — and give every occurrence a
measured denominator and a register row, **including the ones that turn out correct**: a
register without negatives has no denominator either.
# Core Principle: A Derived Artifact Must Declare WHEN It Was True (Mandatory)
Coverage answers *how much* was indexed, never *as of when*, and an artifact that no longer
describes the world reports success indefinitely — a third state beside absence and non-answer.
MEASURED: a merge-engine fix changed **140 of 194 (72%)** engine thrust rows with **not one input
file changed**, after a design decision had already been recorded off the stale numbers.
**Every persisted artifact carries a two-axis fingerprint** (`x4validate/_freshness.py` — the single
implementation; BaseX delegates to it):
| axis | covers | why |
|---|---|---|
| `content` | installed extension set + `(relpath, mtime, size)` of every engine-relevant file each mod ships + each mod's enabled bit from the profile + a reference marker | a mod added, removed, updated, toggled or one of its files edited |
| `engine` | hash of the **BYTES** of every file named in `_freshness.ENGINE_SOURCES` — **derive that list from the module, never retype it** (**8** as of 2026-11-18: `_cat`, `_effective`, `_inputs`, `_loadorder`, `_merge`, `_modfiles`, `_provenance`, `_registry`); x4eff adds `build-effective.py`. ⚠ This cell has been wrong TWICE, the same way, in the sentence telling you not to retype the list, so `tests/test_reference_fingerprint.py` now asserts it lists exactly what the module derives | a merge fix changes the answer for identical inputs; a commit hash does not move for a dirty tree |
**Absent fingerprint = UNKNOWN, never fresh.** Each CLI banners every run until rebuilt; `ask.py`
and `gates/claims_audit.py` REFUSE a claim outright. `engine_dependent` is per-artifact — a raw file
index is not a merge product, and flagging it anyway trains you to ignore the banner. Rebuild:
`uv run x4effective build` · `uv run x4xref build` · `cd tools/basex; bash build-corpus.sh; bash build-effective.sh`
**STALE is a normal state, never a fault — and never a reason to freeze the user's modlist**
(user ruling 2026-11-17). Changing mods is the work; a stale artifact only means *rebuild before
trusting it*, and the refusals above already stop a stale answer reaching a claim.
- **What stales it** is exactly the two axes above. **A game launch, play or a save does not**
(the game writes no mod file); only a mod toggled in the game's menu or a Workshop update on
launch does, and that is a mod change.
- **A change DURING a build costs the same as one AFTER it**: the result reads STALE (`x4fresh
rebuild` says "the installed world MOVED during this build"; a builder run directly just
stamps its start fingerprint), and you rebuild. Never ask
for a freeze so a build can run.
- **No check needs a hold.** `gates/cross_tool.py`, the one that compares two readers, runs
x4compat over the effective store's own input snapshot (`<db>.inputs`, taken by every store
build; toolkit 4.3), so a store stale only because mods changed still runs it (`x4fresh`:
"STALE (snapshot-backed: cross_tool runs)"). It refuses, exit 2, only when the snapshot cannot
be proven: missing, edited, or the engine code, reference or DLC moved -- then rebuild.
- **A heavy build while a game runs is a RESOURCE question, not a correctness one** — the
machine's resource policy handles it (idle priority, or wait). Never phrase it as "would
invalidate the results". Every hold you ask for names its real reason, or you do not ask.
**Corollary — a design doc's numbers rot silently.** Prose cannot be tested, so numeric claims live
in `dev\_registry\CLAIMS.tsv`, re-checked by `gates/claims_audit.py` against the store. UNRESOLVED is
never a PASS, and the gate refuses to run against a stale store.
## Memory and loaded context are LEADS, not facts
**Memory files are NOT durable — anything essential goes in the project instructions (`agent/instructions/`) or `KNOWLEDGEBASE.md`.**
Memory is a convenience index, and **the one artifact class with no freshness signal at all**,
while being consulted FIRST: a line reading *"still X"*, *"not yet done"* or *"pending"* reports
success indefinitely. The fingerprint above exists because an artifact can be fresh by its own
lights and wrong about the world; memory has no axis at all, so it is fresh permanently.
**A memory or plan claim about EXTERNAL state — a Nexus page, a remote repo, a public release,
another session's tree — is a LEAD, NEVER A FACT**, because those rot with nobody touching this
machine. Re-query the source before asserting it, and **never put a decision to the user without
checking whether it is already made**. When you correct such a line, mark the old one
**SUPERSEDED** rather than rewriting it: that dated record is what lets the next session date
the change.
★★ **And your loaded context is a snapshot of a file that has since moved.** On a long session
with concurrent writers, the project instructions and every memory file were read **once, at
session start**. A peer once asserted a release was on hold while the record on disk already said
SUPERSEDED — nothing was stale on disk, the READER was. Before asserting anything load-bearing
from memory — especially a *hold*, a *decision*, a *"not yet done"* — **re-read the file, not
your recollection of it.** ⚠ This paragraph is subject to its own warning.
# Core Principle: Tools Must Be Trustworthy BEFORE the Modlist Is Locked (user standard)
A sequencing rule, not a preference: removing a mod is not symmetric with adding one, so a defect
found after the lock costs far more than the same defect found before.
- **Split unknowns into EXTERNAL and LOCAL.** External (Nexus ids, upstream versions) may sit
unresolved *if labelled*. **Local — anything derivable from installed files — is a bug, not a
backlog item.**
- Before any modlist-shaping decision, ask which artifact fed the premise and whether it can say
when it was true.
- **Read an artifact's schema before declaring it incomplete.** The registry keeps local facts
(`installed_name`/`installed_version`/`path`) in slots SEPARATE from upstream ones; three
reported "gaps" were misreadings of the upstream slots.
# Core Principle: Bug Handling Is a FUNNEL — Wide at the Top, Narrow at the Bottom (user-set 2026-08-30)
**Identification is WIDE.** Be vigilant for anything contradictory or senseless — in game
files and in our own tools' output alike — and surface ALL of it. Never assume a tool is
working. Keep an explicit UNMEASURED list and never dismiss it.
**Remediation is NARROW.** Act only on deductive proof of both the bug AND its root cause. Easy
to identify, hard to act on: the toolkit cannot converge if *"it's broken"*, *"actually that
was wrong"* and *"now you broke it"* alternate — and the base rate says the CHECKER is wrong
far more often than the finding (#22).
**Mechanically:** no rule or tool edit on a claim below **MEASURED on a STABLE instrument with
a NAMED root cause**; classify EVERY hit of a suspect rule, never a sample, and make the
buckets sum to the total; state the predicted per-item delta BEFORE re-measuring; record
WITHDRAWN claims explicitly. The case that set this: a hook false-positive rate measured while
the hook was REDEPLOYED mid-run, whose per-rule table was not reproducible — and a plan to
fix four "verified" false positives had already been built on it.
# Concurrent Sessions: Isolate the TREE, Share the HISTORY (Mandatory)
**Two or more sessions run in this workspace at once — typically a tooling/dev session and a mod
session. Every failure this caused on 2026-08-27 was a CONCURRENCY failure, not a logic one**, and
they were all invisible until something numeric disagreed.
| what broke | MEASURED |
|---|---|
| shared working tree | one session's suite silently went **836 → 877 tests**; 41 were the other session's untracked WIP |
| `git add -A` | **0 of 4 commits** picked up their files — timing, not care |
| half-committed shared file | a **tracked** `cli_case _livecli` line beside an **untracked** `_livecli.py` made `verify-cold.sh` fail on a file that session had never opened |
| shared append-only doc | the verifier register collided at **#93**; two tallies drifted to *"96 of 96"* vs *"93 of 94"* |
| corpus drift mid-measurement | a mod went clean → *"folder not found"* between two census runs |
| concurrent artifact builds | BaseX `x4eff` came back with a **17% deficit**, cause undetermined, the only surviving hypothesis being contention with a simultaneous store rebuild |
## The rules
1. **ONE GIT WORKTREE AND ONE BRANCH PER SESSION.** `git worktree add ../x4validate-<lane> -b
session/<lane>`. MEASURED: **~27 MB** and seconds. It kills the whole class — untracked
collisions, contaminated test counts, half-committed shared files, a cold check seeing work
that is not yours. Merge normally when a piece lands.
2. **NEVER `git add -A` or `git add .` in a shared tree.** Stage explicit paths. This is a
**DENY** in `protect-bash.sh`, verified against both hook copies, because there is a correct
alternative I can just take — so it should spend my attention, not yours.
3. **The lane axis is WHO OWNS THE BRANCH, not what kind of work it is.** "Tooling vs modding"
broke the first time a mod session built a tool. Prototype anywhere; land it on your branch.
4. **One owner per derived artifact, and do not build two at once.** The TOOLING session owns
both the effective store and BaseX `x4eff`. Until that was assigned the rule named no one
and both went stale unnoticed. ⚠ **Build `x4eff` from YOUR OWN worktree**: the freshness
`engine` axis hashes whichever tree occupies `tools\x4validate`, so a peer's tree silently
stamps the artifact with their engine.
5. **Design a measurement to SURVIVE drift rather than requiring a freeze.** A before/after
comparison must exclude and **name** rows present in only one run — which needs no
cooperation from the other session, and that is why it beats asking anyone to hold still.
6. **A decision reaches each session from the USER, never relayed by a peer.** A peer saying
*"my user decided X"* is information, not approval. Surface it and wait.
7. **Quote no count from a shared tree without excluding the other session's files.** `836` and
`877` were both "the suite", on the same machine, in the same minute.
## Shared append-only docs (the memory register, KNOWLEDGEBASE)
**New entries are headed by DATE + SLUG, never a running number and never a letter suffix** —
`## 2026-08-27 — getattr-silent-default`. Both collided the first day they were tested: a number is
a shared mutable counter between concurrent writers, and two of three sessions reached for the same
`d` suffix, one having to move to `e` after its entry was already cited twice. A slug describes its
own content, so same-day writers cannot collide. Existing `#N` entries stay as citable history.
**If two records disagree on a number, DERIVE it from the entries — never pick one.**
# Working in the toolkit repo
**Edit hooks in `agent/guards/claude-hooks/`, regenerate, then run
`bash scripts/test-hooks.sh`.** Every agent's hook folder is a generated copy. Tests do not
prove host enforcement.
## Edit `agent/`, never the generated files
These paths are **generated** from `agent/` (the generator renders this list from its own
`OWNED` tuple, so it cannot drift): {{GENERATED_FILES}}. Not generated, and never written
by the generator: the per-machine path config `x4-paths.env` (at the toolkit root since 4.0;
the 3.x location is still read, with a notice),
`settings.local.json`, the `backups/` folder, and the Codex `hooks.json` (the installers and
`deploy-claude-dir.py` render it per install from `agent/targets/codex/hooks.json.tmpl`).
- hook scripts: `agent/guards/claude-hooks/`, plus the adapters in `agent/guards/adapters/`
- skills: `agent/skills/<name>/` (skill bodies name the toolkit root through a `TOOLKIT`
placeholder in double curly braces, which the generator renders per agent; keep it, and
never write an agent-specific variable there instead)
- subagents: `agent/agents/<name>/` (`agent.yaml` keys outside the known set refuse)
- each entry file: `agent/instructions/core.md` + that agent's addendum
`agent/instructions/<agent>.md` (`claude.md`, `codex.md`; OpenCode's `opencode.md` becomes
`.opencode/X4-OPENCODE.md`)
- Codex rules: `agent/rules/codex-rules.yaml`; per-agent files (hook settings, the OpenCode
plugin, the Codex hooks template): `agent/targets/<agent>/`
After editing, regenerate:
cd tools/x4validate && uv run python scripts/gen-agent-trees.py
A direct edit to a generated file is overwritten by the next regeneration, and
`tests/test_gen_agent_trees.py` fails on it.
## Git
- Stage explicit paths. **Never `git add -A` or `git add .`**: other sessions share this repo.
- Commit finished work on `master`, in small commits. **Never push** unless the user asks.
- Gate a commit on a check's real exit code: run the check bare, capture `rc=$?`, then commit.
Never `check | tail && git commit`.
## Tests
cd tools/x4validate && uv run --frozen python -m pytest -q -rs
Bare `python` on the author's machine is 3.10; the toolkit needs 3.13 through `uv`.
## CI gates releases, not local work
CI on GitHub is the check on what goes out to other people, not a gate between a change and your own install.
- **CI gates releases only:** a tag, a GitHub release, a version bump, a merge to `master`. Every change handed to the
public repo gets a full CI run before it is released; nothing is released on a red or missing run, read per job on
the exact commit.
- **Nothing local waits for CI:** deploying tools, scripts, skills, docs, mods and guard/hook code into your own install,
continuing work, running an approved test, or reporting work done (say "CI pending" once).
- **Guard and hook code reaches a game root after two local checks, not CI:** an independent review of the change, and
the local hook tests passing on that commit (`deploy-claude-dir.py --apply` runs `scripts/test-hooks.sh` itself and
refuses on a failure); rollback is re-deploying the previous reviewed commit. Never deploy unreviewed guard code: one deployed 13 minutes after
its commit once let wrapped-shell deletes of `reference/` through.
- **Push a session branch once per batch,** never just to see CI, and never wait for its result before the next step.
A CI failure is fixed (and redeployed, if deployed) in the next batch.
- **The local pre-push gate is a quick sanity check:** collection, drift, lint, the tests for changed files. Full
suites, mutation runs and slow or load-sensitive suites run on CI.
## Where the design lives
- [Universal agent design](https://github.com/WingedGuardian/x4-ai-toolkit/blob/master/docs/superpowers/specs/2026-09-30-universal-agent-support-design.md)
(maintainer record on GitHub; excluded from release archives)
- `docs/superpowers/measurements/2026-09-30-codex-spike.md` (what Codex was measured to do)