df-context-store — plant the inner-loop substrate (DF Stage 0.5)
Goal: give the repo a persistent, in-repo, read-first agent substrate so analysis
is done once and reused, hand-offs can't silently degrade, and nothing ships
unverified. This is the inner-loop complement to the heavy DF build stages — the
build injects rigor at the seams; this is what lives in the repo and binds every
future session. It runs between Stage 0 (Frame) and Stage 1 (PO), and again on
demand to refresh.
Template (source of truth): the substrate-template/ directory bundled alongside
this skill (skills/df-context-store/substrate-template/).
Procedure
- Emit the payload. Copy
substrate-template/dotclaude/ into the target repo
as .claude/ (agents + context store + hooks/ + contract-check + commit-sync
AGENT-CONTRACTS.md). Don't overwrite an existing populated store — merge.
- Populate from source, don't invent.
.claude/context/SERVICE-MAP.md — the structural map (services/db/queue/API +
flows), generated from the real codebase (use service-mapper).
.claude/context/DATA-FLOW.md — the data-transform view: data nodes
(schema/origin/authority/class), the transform graph (pure|effect), and
the validation rules (LOCAL reject / GLOBAL reconcile). Populate nodes +
authority from source; leave rules you can't yet cite as marked skeletons.
- Leave
FINDINGS.md/DECISIONS.md as clean skeletons that accumulate as the
repo is worked. Fill per-service <service>/CLAUDE.md stubs only where verified
(file:line).
- Wire the always-on carrier. Merge
substrate-template/CLAUDE-stanza.md into
the repo's root CLAUDE.md (read-first/dispatch/verify rules) — this is what binds
every session, not the one-time scaffold.
- Arm the lockstep gate + make it self-arming (the every-commit half). The gate
can't drift code from the context store silently:
chmod +x .claude/hooks/pre-commit .claude/hooks/ensure-gate.sh
- Self-arm carrier: merge the
SessionStart hook from substrate-template/dotclaude/settings.json
into the repo's .claude/settings.json (create it if absent; if it exists,
add the SessionStart entry — do not clobber existing hooks). This runs
ensure-gate.sh on every session so a fresh clone activates the gate with no
manual step. (core.hooksPath is local git config and never travels in a commit —
the SessionStart hook is what carries the every-clone half.)
- Arm it now (non-destructive): if the repo has no existing
core.hooksPath
and no husky, run git config core.hooksPath .claude/hooks (or just run
bash .claude/hooks/ensure-gate.sh, which does exactly this safely). If one
already exists, do not overwrite it — install the gate as
.claude/hooks/pre-commit.local under the existing path (it chains). Say which
path you took.
- Verify (acceptance). Run
bash substrate-template/verify-substrate.sh
(from this skill dir) against the template, and for an emitted repo confirm: required files present, no
leftover template placeholders in SERVICE-MAP/DATA-FLOW (they're populated), the
contract-check suite is green, the gate is executable + actually blocks an
undocumented structural change, and the CLAUDE.md stanza is merged. Green is the
bar; report the literal check counts.
Outputs
.claude/{agents,context,hooks,skills/contract-check,skills/commit-sync} in the target repo.
- A read-first stanza merged into the repo's
CLAUDE.md.
- A populated
SERVICE-MAP.md + DATA-FLOW.md; clean FINDINGS.md/DECISIONS.md skeletons.
- An armed
pre-commit staleness gate (core.hooksPath set, or chained via .local),
self-arming on future clones via the SessionStart → ensure-gate.sh hook merged
into .claude/settings.json.
Rules
- Populate, don't fabricate —
SERVICE-MAP entries cite real code; unknowns are
marked, not guessed (same discipline the agents enforce).
- Idempotent — re-running merges/refreshes; it must not duplicate entries or
clobber an accumulated
FINDINGS/DECISIONS ledger.
- Generic-in, specific-out — the template is project-neutral; the emitted
substrate is tailored to THIS repo. Don't ship template placeholders into a repo.
- Referenced by
dark-factory-build as Stage 0.5. An organisation layer may also call this
as the substrate step of its own cold-start generator where that toolchain is present —
optional integration, not required.
1---2name: df-context-store3description: Dark Factory Stage 0.5 — scaffold a repo's in-repo agent inner-loop substrate (read-first context store + single-responsibility agents + checkable hand-off contracts + commit gate) from the proven template, populate it from the real codebase, and verify it. Use when bootstrapping a repo for DF work, running a DF build, or adding the agent substrate to an existing repo. Triggers on "context store", "agent substrate", "inner loop", "bootstrap agents", "df stage 0.5".4---56# df-context-store — plant the inner-loop substrate (DF Stage 0.5)78Goal: give the repo a **persistent, in-repo, read-first agent substrate** so analysis9is done once and reused, hand-offs can't silently degrade, and nothing ships10unverified. This is the inner-loop complement to the heavy DF build stages — the11build injects rigor at the seams; this is what *lives in the repo* and binds every12future session. It runs between Stage 0 (Frame) and Stage 1 (PO), and again on13demand to refresh.1415Template (source of truth): the `substrate-template/` directory bundled alongside16this skill (`skills/df-context-store/substrate-template/`).1718## Procedure19201. **Emit the payload.** Copy `substrate-template/dotclaude/` into the target repo21 as `.claude/` (agents + context store + `hooks/` + `contract-check` + `commit-sync`22 + `AGENT-CONTRACTS.md`). Don't overwrite an existing populated store — merge.232. **Populate from source, don't invent.**24 - `.claude/context/SERVICE-MAP.md` — the structural map (services/db/queue/API +25 flows), generated from the real codebase (use `service-mapper`).26 - `.claude/context/DATA-FLOW.md` — the data-transform view: data nodes27 (schema/origin/**authority**/class), the transform graph (`pure|effect`), and28 the validation rules (`LOCAL` reject / `GLOBAL` reconcile). Populate nodes +29 authority from source; leave rules you can't yet cite as marked skeletons.30 - Leave `FINDINGS.md`/`DECISIONS.md` as clean skeletons that accumulate as the31 repo is worked. Fill per-service `<service>/CLAUDE.md` stubs only where verified32 (`file:line`).333. **Wire the always-on carrier.** Merge `substrate-template/CLAUDE-stanza.md` into34 the repo's root `CLAUDE.md` (read-first/dispatch/verify rules) — this is what binds35 every session, not the one-time scaffold.364. **Arm the lockstep gate + make it self-arming (the every-commit half).** The gate37 can't drift code from the context store silently:38 - `chmod +x .claude/hooks/pre-commit .claude/hooks/ensure-gate.sh`39 - **Self-arm carrier:** merge the `SessionStart` hook from `substrate-template/dotclaude/settings.json`40 into the repo's `.claude/settings.json` (create it if absent; if it exists,41 add the `SessionStart` entry — do **not** clobber existing hooks). This runs42 `ensure-gate.sh` on every session so a fresh clone activates the gate with no43 manual step. (`core.hooksPath` is local git config and never travels in a commit —44 the SessionStart hook is what carries the every-clone half.)45 - **Arm it now (non-destructive):** if the repo has **no** existing `core.hooksPath`46 and **no** husky, run `git config core.hooksPath .claude/hooks` (or just run47 `bash .claude/hooks/ensure-gate.sh`, which does exactly this safely). If one48 already exists, do **not** overwrite it — install the gate as49 `.claude/hooks/pre-commit.local` under the existing path (it chains). Say which50 path you took.515. **Verify (acceptance).** Run `bash substrate-template/verify-substrate.sh`52 (from this skill dir) against the template, and for an emitted repo confirm: required files present, no53 leftover template placeholders in `SERVICE-MAP`/`DATA-FLOW` (they're populated), the54 `contract-check` suite is green, the gate is executable + actually blocks an55 undocumented structural change, and the CLAUDE.md stanza is merged. Green is the56 bar; report the literal check counts.5758## Outputs59- `.claude/{agents,context,hooks,skills/contract-check,skills/commit-sync}` in the target repo.60- A read-first stanza merged into the repo's `CLAUDE.md`.61- A populated `SERVICE-MAP.md` + `DATA-FLOW.md`; clean `FINDINGS.md`/`DECISIONS.md` skeletons.62- An armed `pre-commit` staleness gate (`core.hooksPath` set, or chained via `.local`),63 self-arming on future clones via the `SessionStart` → `ensure-gate.sh` hook merged64 into `.claude/settings.json`.6566## Rules67- **Populate, don't fabricate** — `SERVICE-MAP` entries cite real code; unknowns are68 marked, not guessed (same discipline the agents enforce).69- **Idempotent** — re-running merges/refreshes; it must not duplicate entries or70 clobber an accumulated `FINDINGS`/`DECISIONS` ledger.71- **Generic-in, specific-out** — the template is project-neutral; the emitted72 substrate is tailored to THIS repo. Don't ship template placeholders into a repo.73- Referenced by `dark-factory-build` as Stage 0.5. An organisation layer may also call this74 as the substrate step of its own cold-start generator where that toolchain is present —75 optional integration, not required.