# RSC v0.2 — Practical Notes from the First Week of the Discipline

**Oscar Serra¹, Jarvis (Claude Opus 4.7)²**
¹Independent Research
²TinkerClaw, anchored on OpenClaw
*Paper J15 — Version 0.2 — 11 May 2026*

**Internal codename:** RSC (after the retrosplenial cortex; see v0.1 §1.2 and §8)
**Status:** the four primitives proposed in v0.1 are deployed on the live fork. The merge gate runner exists (`pnpm bible:invariants`, 32/32 passing). Probes for the four high-priority surfaces are live RPCs. Bible is now a folder of fifteen files. The auto-merge cron itself is still off pending integration with the gate.

---

## 0. Why a v0.2

v0.1 was a proposal; v0.2 is a report from one week of using the proposal on a live system. Three things changed our mind about details of the design:

1. **The bible should be a folder, not a single file with frontmatter.** v0.1 imagined `bible.md` carrying per-section YAML frontmatter. In practice the AI's context window benefits more from *small files* than from *small sections inside a big file*: a single file is loaded all-or-nothing. Splitting the bible into sixteen targeted files lets the AI load `failures.md` (~150 lines) when debugging and `flows.md` when refactoring, and never look at the other fourteen.
2. **The pii-boundary file has to be self-aware.** Any file that *documents* a leak grep is itself going to match its own grep. The fix is a verify command that explicitly excludes the self-documenting file from the check. A general lesson: meta-rules need carve-outs from their own enforcement.
3. **Probe RPCs need PATH-aware shell invocation.** `pnpm` prepends `./node_modules/.bin` to PATH; if a binary like `openclaw` exists in both the local node_modules and `/usr/local/bin`, pnpm's stub wins. The merge gate runner must prepend `/usr/local/bin:/usr/bin:/bin` to PATH or every system-tool invocation breaks. We hit this on the first run and would have hit it in production.

What follows is the practical layer: how the discipline is actually applied, in our codebase, with dumbed-down examples from things that broke.

---

## 1. The bible folder, after one week

The bible is `~/src/tinkerclaw/TINKER_UI_DESIGN_BIBLE/`. Sixteen files. One entry point, one narrative, thirteen structural, plus a redirect stub at the old path.

```
TINKER_UI_DESIGN_BIBLE/
├── INDEX.md                  ← AI entry point and map
├── bible.md                  ← narrative, intent, decisions, don't-regress (now ~1730 lines)
├── tinker-ui.md              ← UI layout + visual language + feature registry (~1095 lines)
├── bug-log.md                ← historical bug-fix log, forensic timeline (~290 lines)
├── flows.md                  ← sequence diagrams (Mermaid) for the top 7 pipelines
├── lifecycles.md             ← state machines for sessions, workers, messages, recovery
├── topology.md               ← components, ports, plugins, channels, symlinks
├── config-shape.md           ← every openclaw.json key + override chain
├── failures.md               ← failure-mode propagation maps (M1–M10)
├── probes.md                 ← inspection primitives registry (live + proposed)
├── tool-loop.md              ← the cc-bridge / claude-cli divergence
├── auth-routing.md           ← model rank, provider routing, billing gate
├── crons.md                  ← cron registry + auto-merge policy
├── pii-boundary.md           ← public-OK vs private-only + sanitization workflow
├── memory-layout.md          ← workspace memory directory map + writers
└── subagents-and-recipes.md  ← subagent spawn + recipe catalog + Prefrontal split
```

`INDEX.md` is the only file the AI is *required* to read at session start. The rest are loaded on demand based on the question. The question-to-file mapping is encoded in INDEX.md as a verbatim lookup table.

### Concrete payoff: a debug session that was

When a user asks "why did Jarvis say something went wrong on WhatsApp yesterday at 16:55," the AI's old flow was:

> Open the bible. ctrl-F "WhatsApp". Read 200 lines of context. Read more. Try to remember if there was a cc-bridge thing. Open the bible's §11 because that's where backend stuff lives. Realize the timeout discussion was in §11.6d. Re-read the surrounding §11.6c and §11.6e. Now think about whether the symptom fits.

The new flow is:

> Read `failures.md` (150 lines). Match the symptom to row M1 (cc-bridge SIGTERM). Follow the cited probe (`debug.session.config`). Confirm the resolved timeout is 600000ms — the path is alive. Conclude the symptom is from an older session that timed out before the fix shipped.

The first flow is six turns; the second is two. The compression is the *single owner per fact* rule from v0.1 §4.1, paid for at write time.

---

## 2. The four primitives, instantiated

### 2.1 Multi-optic atlas → fifteen typed files

v0.1 named seven candidate optics. In practice we landed on fifteen files because some narrative content (the `bible.md` and the `bug-log.md` historical timeline) does not fit any single optic and deserves its own file, and because Tinker UI's visual feature registry is large enough to warrant a dedicated file (`tinker-ui.md` weighs in at ~1100 lines).

**Lesson:** don't constrain the count up front. Let each optic emerge from a distinct *class of question* that an AI is reasonably likely to ask. If two files would always be loaded together, merge them. If one file is loaded for two very different questions, split it.

### 2.2 Executable invariants → 32 verify commands across 11 files

Each structural file's frontmatter now carries a `verify:` block. Three concrete examples:

**a) Catching the cc-bridge dead-code regression from 2026-05-05.**
```yaml
# config-shape.md
verify:
  - name: claude-code provider overlay resolves timeoutSeconds=600
    cmd: python3 -c 'import subprocess,json; r=subprocess.run(
      ["openclaw","gateway","call","debug.session.config","--params",
      json.dumps({"provider":"claude-code"})],capture_output=True,text=True);
      assert "\"resolvedRequestTimeoutMs\": 600000" in r.stdout'
```

If this assertion fails, the cc-bridge plugin overlay broke. The bug Oscar typed `/new` to discover would have failed this check at merge time.

**b) Catching the handler-wipe class from 2026-04-29.**
```yaml
# failures.md
verify:
  - name: M3 fork RPC alive — config.openExternalFile
    cmd: python3 -c 'import subprocess,json; r=subprocess.run(
      ["openclaw","gateway","call","config.openExternalFile","--params",
      json.dumps({"path":"/dev/null"})],capture_output=True,text=True);
      assert "\"ok\"" in r.stdout'
```

If an upstream merge silently drops the handler again, the next nightly run of `pnpm bible:invariants` flags it.

**c) Catching the PII boundary breakage class.**
```yaml
# pii-boundary.md
verify:
  - name: bible files do not match the PII leak grep (excludes this self-referential file)
    cmd: |
      cd ~/src/tinkerclaw && for f in TINKER_UI_DESIGN_BIBLE/INDEX.md
      TINKER_UI_DESIGN_BIBLE/flows.md ...; do
        if grep -P 'Oscar(?! Serra)|...' "$f" >/dev/null 2>&1; then
          echo "LEAK in $f"; exit 1; fi; done
```

If a structural file gains a leaked literal, the gate refuses to push.

The 32 checks run in approximately 4 seconds end-to-end. Cost is bounded.

### 2.3 Probe symmetry → six live RPC probes + one log-line probe

We shipped these RPCs in one commit (`23f7585623`):

- `debug.session.config({provider})` — effective resolved providerConfig including plugin overlay state.
- `debug.session.state({sessionKey})` — session-store entry plus activeRunIds from the gateway's chatAbortControllers map.
- `debug.tail.lastN({sessionKey,n})` — last N parsed messages from a session transcript with a path-safety allowlist.
- `cron.lastRun({jobId})` — last receipt JSONL entry plus file mtime and size.
- `cron.listJobs` — full cron registry plus per-job freshness in seconds.
- `debug.dumpUiSnapshot` — preexisting; renders Tinker UI's chat DOM to a deterministic text file.

Plus one log-line probe: `[idle-timeout-diag]`, emitted by `attempt.ts` on every turn, showing the resolved idle timeout and where each component of the resolution came from. It is the canary for the cc-bridge timeout class of bugs.

The Symmetry Principle held up in practice. The probes that exist today were each added to *unblock an investigation that was expensive without them* — that's the right cadence, because it forces the maintainer to feel the cost of asymmetry before paying the cost of building a probe.

### 2.4 Commit-and-timestamp anchors → frontmatter on every file

Every structural file carries `last_verified: 2026-05-11` and `last_verified_commit: HEAD`. We treat HEAD-tracking as the lazy default; sections that need precise pinning (e.g., quoting a specific line number) get a frozen commit SHA. This is the discipline that catches Type B obsolescence: when the AI reads a section, the anchor tells it whether the section was rechecked recently. If git log shows the cited files changed yesterday but `last_verified` is from two weeks ago, the AI knows to re-verify before trusting.

---

## 3. The merge gate runner

`scripts/test-invariants.mjs` walks every `*.md` in the bible directory, parses YAML frontmatter, and runs each `verify.cmd` through a bash subshell with a 30-second timeout. Exits 0 if every check passes, 1 if any fails, 2 on internal error.

Invoked as `pnpm bible:invariants`. Total runtime on the current state: about 4 seconds for 32 checks.

The runner is small — under 300 lines, with a hand-rolled YAML subset parser to avoid pulling in `js-yaml` as a build-time dependency. It is intentionally not over-engineered.

### 3.1 Wiring into the merge cron

The `daily-fork-sync` cron job is currently **disabled** (per crons.md). When re-enabled, the gate inserts here:

```
upstream merge → pnpm build → pnpm bible:invariants → ship | block
```

If `pnpm bible:invariants` exits non-zero, the merge does not ship. The failing section names land in the cron receipt, so the operator sees exactly which behavior was lost and where the bible expects to find it.

We have not yet re-enabled the cron. The plan is: one more pass adding `verify` blocks to the four files that currently lack them (`bible.md`, `bug-log.md`, `flows.md`, `lifecycles.md`, `tool-loop.md`, `tinker-ui.md`), then a pilot week of running the gate manually before letting the cron own it.

---

## 4. Lessons from the first week (dumbed-down)

These are the lessons that I would have written into v0.1 if I had known them. They are all small. Together they describe what the discipline actually feels like in use.

**L1. "Single owner per fact" requires friction at write time, not at read time.**
The temptation when documenting something for two different audiences is to write it twice. Resist. Pick the file whose *primary question* the fact answers, write it there, and reference it everywhere else. Concretely: the cc-bridge idle timeout fix lives in *one* place — `config-shape.md` — and `failures.md`, `tool-loop.md`, and `auth-routing.md` all `see also:` it.

**L2. Probes pay for themselves the second time they're used.**
The first investigation that needed `debug.session.config` cost about two hours, partly because there was no probe and partly because the AI had to grep across six files to assemble the answer. The probe took 45 minutes to write. The next investigation will take five minutes. Net break-even is at investigation #2.

**L3. Verify commands are easier to author than verify *names*.**
The mechanical part — write a shell command that exits 0 on success — is fast. The hard part is naming the check well enough that, when it fails six months from now, the maintainer reads the name and immediately knows what's wrong. Spend the naming effort.

**L4. The PATH bug we hit on day one will recur in every CI integration.**
`pnpm` shadows system binaries via `./node_modules/.bin`. So does Yarn, sometimes. The runner prepends `/usr/local/bin:/usr/bin:/bin` to PATH explicitly. Any future runner that calls system tools needs the same fix. This is the kind of obstacle that v0.1 abstracted away as "implementation details"; in practice it eats half a day.

**L5. `jq` is not always installed.**
Several initial verify commands used `jq`. The runner failed because `jq` was not on the test machine. We rewrote with `python3 -c`. Lesson: assume nothing about installed tools beyond `bash`, `python3`, and `node`. Those three are reliably present; everything else is luck.

**L6. Self-referential files need a carve-out.**
`pii-boundary.md` documents the regex it grep-tests against. The first run of the suite failed on the file's own content. The fix: have the verify command explicitly *list* the files it checks and exclude `pii-boundary.md`. The same pattern will recur for any meta-document.

**L7. Migrating a 3000-line file is faster as line-range surgery than as cut-and-paste.**
We slimmed bible.md from 3085 → 1728 lines by writing a Python script that read specific line ranges into the new files (`tinker-ui.md`, `bug-log.md`) and wrote the slimmed bible as the complement. The whole operation took under a minute and didn't lose a single line. The naive cut-and-paste would have taken hours and probably dropped content.

---

## 5. What v0.1 missed

In retrospect:

- **v0.1 underestimated the value of a redirect stub at the old path.** External references (CLAUDE.md, code comments, memory notes) point at `TINKER_UI_DESIGN_BIBLE.md` (the old single file). When that file became a directory, the old `.md` path stayed in place as a 525-byte stub redirecting to `INDEX.md`. This is cheaper than chasing every external reference and prevents silent lookup failures.
- **v0.1 said "the cost of an invariant is one line of YAML frontmatter."** That was wrong. The cost is roughly *five lines of YAML plus 30 minutes of design thought*: which probe should the check use? What is the failure mode this check is meant to catch? What's the right assertion shape? The discipline is cheap, not free.
- **v0.1 did not anticipate the meta-document carve-out (L6).** This is now baked in.
- **v0.1 underweighted the value of having the gate runner produce *colored, human-readable* output even when it exits non-zero.** A failing check that prints the stderr tail in red, with the section name highlighted, is dramatically easier to triage than a numeric exit code. The runner is only ~300 lines but the output formatting is doing real work.

---

## 6. Pending work, by class

> **Emptied 2026-05-12 — superseded by v0.3 §6.** Every item that lived here has either shipped or been re-classified under v0.3's leverage-ordered backlog. This section is preserved as a header (so external references resolve) but the list itself now lives in `2026-05-12-rsc-v0.3.md` §6 "Pending work, ordered by leverage", which is the canonical source going forward.
>
> Snapshot of how Class A–E from v0.2 resolved:
>
> - **Class A (verify backfill)** — all six files now carry `verify:` blocks (see v0.3 Appendix C).
> - **Class B (merge-gate cron integration)** — the runner is now wired into `pnpm test` AND `git-hooks/pre-push`, so the gate runs on every push regardless of cron state; merge-cron integration remains queued behind the `daily-fork-sync` re-enable decision.
> - **Class C (more probes)** — `wa.lastOutbound` and `plugin.boot.status` shipped, plus 4 additional probes (`gateway.stuckSessions`, `gateway.diagnosticSessionCount`, `gateway.observability.snapshot`, `gateway.flow.replay`). `cc-bridge.workerInfo` remains queued (requires plugin-API extension).
> - **Class D (architectural follow-ups)** — cc-bridge heartbeat stream events SHIPPED (commit `12bb2c4f7a`, made the 600s overlay belt-and-suspenders); `self.lid` population and synchronous session-status-on-surface_error still pending.
> - **Class E (bible slimming)** — `bible.md` slimmed from 1,730 → ~1,500 lines via phase-3 extraction (§5.66 cc-bridge mechanics → `tool-loop.md`, §5.78 branch policy → new `branch-policy.md`).

---

## 7. Conclusion

v0.1 was a thesis. v0.2 is a report on it being true.

The four primitives — multi-optic documentation, executable invariants, commit-and-timestamp anchors, probe symmetry — survived contact with a real codebase. They were not all proposed at the right scale (we needed sixteen files, not seven), and the runner needed two implementation-level fixes (PATH, jq) before it would run cleanly. But the underlying mechanic — *write down what should be true, then write down how to check it* — is exactly the right shape for AI-pair coding at velocity.

The merge gate runner is the load-bearing piece. Without it, every primitive degrades back into prose. With it, the bible's claims become refuseable: when a claim is false, the merge that made it false does not ship. This is the property that distinguishes a useful documentation discipline from a beautiful one.
