Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(embedded-core): W1 guardrails: core world-reads ratchet, two-engine suite, hermeticity test, upgrade harness (GBRA-248)

garrytan200b7abece24
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d87cd8acd9..37dcda6aef 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,11 +10,25 @@ credits are retained; no result has been reassigned to another provider. Origina
identifiers and attribution are available in the pre-removal Git revision
`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).
+## [Unreleased]
+
+**Guardrails for the embedded core: a ratchet on what `src/core` reads from the process and the machine, a two-brains-in-one-process suite, a hermeticity test, and an upgrade-from-the-previous-release harness. Nothing changes for local users.**
+
+The planned embedded core lets one server process run many brains, each opened from its own settings. This release adds the guards that wave and every later one is measured against, with no runtime change. `bun run check:core-world-reads` (in `bun run verify`) counts, per file in `src/core`, `loadConfig` calls, environment reads, `fs` imports, module-level collections, spawn imports, process-wide hooks and `AsyncLocalStorage` stores, and fails when a count rises or a baseline row goes stale. The two-engine suite opens two brains in one process on PGLite and Postgres and shows what they still share today (AI keys and model clients, the query-embedding cache, the usage and telemetry sinks, link semantics, the admission and retrieval-tracking caches, page-lock names and home paths, and on Postgres the connection pool), each case naming the wave that fixes it. The upgrade harness opens a brain and keyless config written by the previous release, as a repository brain, a content-directory brain and a no-root brain, and requires the same page, schema, resolved settings and untouched config file.
+
+### Itemized changes
+
+- New guard `scripts/check-core-world-reads.ts` with baseline `scripts/core-world-reads-baseline.tsv` (rows only fall; `--prune` lowers stale rows).
+- New two-engine isolation suite (`test/two-engine-isolation.serial.test.ts`, `test/e2e/two-engine-isolation.test.ts`), hermeticity test (`test/embedded-hermeticity.test.ts`, expected to fail until W7) and upgrade harness (`test/upgrade-from-previous-release.slow.test.ts`, `test/e2e/upgrade-from-previous-release.test.ts`).
+- New example `examples/embedded-two-brains.ts` (two PGLite brains in one process).
+- Docs: [running gbrain on servers today](docs/guides/servers-today.md) and the planned [embedded core](docs/architecture/topologies.md#embedded-core-planned), including the opt-in `embedded_core` setting later waves add (nothing reads it yet) and which wave moves each piece of per-process state.
+- The 0.60.524.0 entry now names the command that exits 10 correctly: `gbrain trust review --accept-all`.
+
## [0.60.524.0] - 2026-10-31
**A brain moved or restored under a new host identity no longer leaves writes pending forever behind an `--accept-pending` exit 0, and a keyless re-init from a cold `GBRAIN_HOME` no longer switches an embedded brain to keyword-only (GBRA-248 W0).**
-A managed source publishes only through the host that owns its checkout. When a brain moved to another machine, was restored from a backup, or ran in a container that restarted with a fresh `GBRAIN_HOME`, the new process got a new host identity, its writes queued for the old owner, and nothing said that owner was gone: the receipt read as an ordinary pending write and `--accept-pending` (or `GBRAIN_ACCEPT_PENDING=1`) exited 0, so hooks and cron treated writes that would never publish as saved. A pending receipt now flags that owner (reason `owner_unavailable` with a new `diagnostic.owner` block holding its last activity, which older clients ignore; doctor names the host) when it runs no live consumer and has been quiet for more than 24 hours, or at once on PGLite when this process holds the database file under another identity. `--accept-pending` does not cover such a write: `gbrain put`, `gbrain call`, brainstorm saves and `gbrain trust accept --all` exit 10 and say why. A consumer's clean stop now stamps the worktrees its host owns, so a stopped owner is not mistaken for a gone one. The owner host never sees the block, a repo-less (database-only) write never names an owner, and nothing claims or transfers ownership. New doctor check `owner_host_stale` lists the waiting writes with the owner and the read-only next step.
+A managed source publishes only through the host that owns its checkout. When a brain moved to another machine, was restored from a backup, or ran in a container that restarted with a fresh `GBRAIN_HOME`, the new process got a new host identity, its writes queued for the old owner, and nothing said that owner was gone: the receipt read as an ordinary pending write and `--accept-pending` (or `GBRAIN_ACCEPT_PENDING=1`) exited 0, so hooks and cron treated writes that would never publish as saved. A pending receipt now flags that owner (reason `owner_unavailable` with a new `diagnostic.owner` block holding its last activity, which older clients ignore; doctor names the host) when it runs no live consumer and has been quiet for more than 24 hours, or at once on PGLite when this process holds the database file under another identity. `--accept-pending` does not cover such a write: `gbrain put`, `gbrain call`, brainstorm saves and `gbrain trust review --accept-all` exit 10 and say why. A consumer's clean stop now stamps the worktrees its host owns, so a stopped owner is not mistaken for a gone one. The owner host never sees the block, a repo-less (database-only) write never names an owner, and nothing claims or transfers ownership. New doctor check `owner_host_stale` lists the waiting writes with the owner and the read-only next step.
`gbrain init` with no provider key in reach falls back to keyless. Run from a cold home against a database that already had an embedding model and vectors, it wrote `embedding_disabled: true` into the new config file, and the brain stopped embedding. When that fallback was implicit and the database holds vectors, init now keeps the database's stored model and width in the config file instead and prints the key to set and `gbrain embed --stale`. A fresh keyless install, a keyless brain with no vectors, an explicit `--no-embedding` and a database that already disables embeddings behave as before. New doctor check `embedding_plane_disagreement` finds brains the old behavior left in that state and prints the `gbrain init --force --embedding-model …` enable for the same model.
diff --git a/docs/architecture/topologies.md b/docs/architecture/topologies.md
index 11fdf5e201..3bbf18fbad 100644
--- a/docs/architecture/topologies.md
+++ b/docs/architecture/topologies.md
@@ -960,6 +960,84 @@ recovery, idempotent replay and fresh readback after a clean restart. Do not
disable persistence to bypass this, and do not confuse live fact-backfill IPC
with live-owner dream delegation.
+## Embedded core (planned)
+
+Status: planned (GBRA-248). None of this runs yet, and nothing reads the
+setting below. Today one process serves one brain; to serve several, run one
+process per brain ([running gbrain on servers today](../guides/servers-today.md)).
+
+The embedded core lets a host such as a hosted service run many customers'
+brains in one server process. Each brain is opened from a settings object, and
+everything that belongs to a brain lives on the engine that settings object
+opened.
+
+**What the host supplies.** One settings object per brain: the database (URL,
+direct URL, pool size and an optional process-wide connection budget), storage
+(a `StorageBackend` and a per-brain key prefix), AI (keys, models, base URLs),
+the host identity, and whether the engine may touch a worktree.
+
+**What the core promises.** `openEngine(settings)` (a new name, because
+`createEngine(EngineConfig)` is already exported from `gbrain/engine-factory`)
+returns an engine that reads only its argument: no `~/.gbrain/config.json`, no
+process environment, no per-brain module state. The pool, the AI gateway with
+its model clients and caches, and the usage and telemetry sinks hang off the
+engine. Opening never migrates; a separate `migrate(settings)` does, and an
+engine refuses an older or newer schema. Every failure carries the
+[agent operator contract](../protocol/AGENT_OPERATOR_v1.md).
+
+**What the local app adds.** The CLI keeps reading `~/.gbrain/config.json` and
+the environment, builds the same settings and passes them in, and still
+migrates on connect. Process exit, signal handlers, timers, files under
+`GBRAIN_HOME` and child processes stay in the local app.
+
+**`database_only`.** A hosted brain with no repository is the existing no-root
+source state (`gbrain init --db-only`), not a new mode. Git stays the parent
+wherever a repository exists. Markdown and files leave a database-only brain
+through `gbrain export` and a `StorageBackend`, not through a mirror.
+
+**The `embedded_core` setting.** Every hosted or embedded behavior the program
+adds is opt-in behind one setting, `embedded_core`, off by default: no-root
+hosted sources opened through `openEngine`, the explicit-migration mode for
+servers, and export to a `StorageBackend`. A brain that never sets it sees no
+behavior change, which every wave proves with the upgrade-from-previous-release
+harness. No code reads the setting yet.
+
+**Guards.** `bun run check:core-world-reads` (in `bun run verify`) counts,
+per file in `src/core`, `loadConfig` calls, environment reads, `fs` imports,
+module-level mutable collections, spawn imports, process-wide hooks and
+`AsyncLocalStorage` stores against `scripts/core-world-reads-baseline.tsv`,
+whose rows name the wave that removes each count. Counts only fall: a rise
+fails (take the value from the settings the caller passes in, or justify a
+raised row in the same PR), and so does a stale row (`--prune` lowers it).
+Rules are in the script's header. The two-engine suite
+(`test/helpers/two-engine.ts`) runs two brains in one process on PGLite and
+Postgres and lists each dimension that still leaks with the wave that fixes
+it. `test/embedded-hermeticity.test.ts` runs
+[`examples/embedded-two-brains.ts`](../../examples/embedded-two-brains.ts) in a
+cold process with canary homes and environment. The upgrade harness
+(`test/helpers/upgrade-from-previous-release.ts`) opens the previous
+release's brain and config under the new build for the repo,
+content-directory and no-root shapes.
+
+**Per-process state and the wave that moves it.**
+
+| State | Where | Wave |
+|---|---|---|
+| Postgres pool singleton; a second `connect()` reuses it | `src/core/db.ts` | W2 |
+| AI gateway config, model-client cache (keyed without the key or endpoint), shrink state | `src/core/ai/gateway.ts` | W2 for the hosted slice, W3 for every caller |
+| Query-embedding cache (keyed without brain, key or caller) | `src/core/ai/query-embed-cache.ts` | W2 |
+| Chat usage sink (top of a process-wide stack) | `src/core/ai/chat-usage.ts` | W2 |
+| Search telemetry writer (bound to the first engine) | `src/core/search/telemetry.ts` | W2 |
+| Schema-pack link semantics | `src/core/link-validity.ts` | W2 |
+| Strict-params and default-surface fallbacks | `src/mcp/validate-params.ts`, `src/commands/serve-http-mcp.ts` | W2 |
+| Minion admission policy cache (keyed by job name) | `src/core/minions/admission.ts` | W6 |
+| Retrieval-tracking switch cache | `src/core/last-retrieved.ts` | W6 |
+| Sources query-shape memo | `src/core/source-resolver.ts` | W6 |
+| Full-text language cache | `src/core/fts-language.ts` | W6 |
+| `loadConfig` rereads and `GBRAIN_HOME` paths | `src/core/config.ts` | W6 |
+| Page-lock root and slug-only key | `src/core/page-lock.ts` | W5 |
+| Process handlers, telemetry and supervisor timers, claim leases | `src/core/process-cleanup.ts`, `src/core/minions/supervisor.ts`, `src/core/persistence/claim-lease.ts` | W7 |
+
## When NOT to use these topologies
- **Don't use Topology 2 if your agent only ever runs on the same machine
diff --git a/docs/guides/servers-today.md b/docs/guides/servers-today.md
new file mode 100644
index 0000000000..6422e16e1a
--- /dev/null
+++ b/docs/guides/servers-today.md
@@ -0,0 +1,65 @@
+# Running gbrain on servers today
+
+gbrain serves one brain per process. To serve several brains, or to run
+gbrain inside containers, give each brain its own process and its own
+`GBRAIN_HOME`. This guide covers what that takes today and what still
+breaks. The [embedded core](../architecture/topologies.md#embedded-core-planned)
+is the planned way to run many brains in one process.
+
+## Pick the brain's shape
+
+- **No-root (database-only).** `gbrain init --db-only --url postgresql://<user>:<password>@<host>:5432/<database>`
+ keeps the brain in the database with no content directory or checkout.
+ Any host can publish its writes, so a replaced container never strands
+ them. Take markdown out with `gbrain export`.
+- **Content directory or repository.** The default install, or a source
+ backed by a git checkout. Writes publish through the host that owns the
+ checkout, named by `host.json` in `GBRAIN_HOME`.
+
+## Keep GBRAIN_HOME stable
+
+`GBRAIN_HOME` holds the config file, the host identity, the content
+directory and the local locks. Mount a persistent volume there, one per
+brain, and never share one home between two brains. A container that
+restarts with an empty `GBRAIN_HOME` gets a new host identity: writes for a
+content-directory or repository source then wait for the old owner, and
+`gbrain doctor` warns `owner_host_stale`
+([troubleshooting](troubleshooting.md#owner-host-stale)). A no-root brain is
+not affected.
+
+## Keys
+
+Provider keys come from the process environment (`OPENAI_API_KEY`,
+`VOYAGE_API_KEY` and the rest) or from `gbrain config set` in that brain's
+home. Without a key the brain stays keyword-only. If a re-setup without a key
+left an embedded brain keyword-only, doctor warns
+`embedding_plane_disagreement` and prints the command that turns embeddings
+back on ([troubleshooting](troubleshooting.md#embedding-plane-disagreement)).
+
+## Migrations
+
+The CLI applies pending schema migrations when it connects. On a deploy, run
+`gbrain apply-migrations --yes` once before starting the server, so the
+first request does not pay for them and several containers do not race for
+the migration lock.
+
+## What still breaks
+
+Two brains opened in one process still share state: the Postgres pool, the
+AI keys and model clients, the query-embedding cache, the chat usage and
+search telemetry sinks, schema-pack link semantics, the minion admission and
+retrieval-tracking caches, page-lock names and `GBRAIN_HOME` paths. The
+two-engine suite (`test/helpers/two-engine.ts`) lists each one with the wave
+that fixes it. Until then, run one process per brain. `gbrain serve --http`
+serves one brain per process too.
+
+## Example
+
+Two brains, two processes, two homes:
+
+```bash
+GBRAIN_HOME=/srv/gbrain/brain-a gbrain init --db-only --url "$BRAIN_A_DATABASE_URL"
+GBRAIN_HOME=/srv/gbrain/brain-b gbrain init --db-only --url "$BRAIN_B_DATABASE_URL"
+GBRAIN_HOME=/srv/gbrain/brain-a gbrain serve --http --port 3001 &
+GBRAIN_HOME=/srv/gbrain/brain-b gbrain serve --http --port 3002 &
+```
diff --git a/examples/embedded-two-brains.ts b/examples/embedded-two-brains.ts
new file mode 100644
index 0000000000..6545e7b775
--- /dev/null
+++ b/examples/embedded-two-brains.ts
@@ -0,0 +1,58 @@
+/**
+ * Two brains in one process: the embedded-core quickstart
+ * (docs/architecture/topologies.md#embedded-core-planned).
+ *
+ * bun examples/embedded-two-brains.ts [dirA] [dirB]
+ *
+ * Each brain is a PGLite database in its own directory. The example imports a
+ * markdown page into each (keyword-searchable, no embedding key needed), searches each, closes both, reopens both and reads the pages
+ * back, then prints what each brain saw as JSON. Each brain must find only
+ * its own page.
+ *
+ * Today it uses the API an embedder already has (createEngine from
+ * gbrain/engine-factory; inside this repository the relative import below).
+ * The embedded core (GBRA-248) replaces it with openEngine(settings), which
+ * reads nothing from the process environment or the home directory.
+ */
+import { mkdtempSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { createEngine } from '../src/core/engine-factory.ts';
+import { importFromContent } from '../src/core/import-file.ts';
+import type { BrainEngine } from '../src/core/engine.ts';
+
+export interface BrainReport { slug: string; found: string[]; reopened: string | null }
+
+async function open(dir: string): Promise<BrainEngine> {
+ const engine = await createEngine({ engine: 'pglite' });
+ await engine.connect({ engine: 'pglite', database_path: join(dir, 'brain.pglite') });
+ await engine.initSchema();
+ return engine;
+}
+
+export async function runTwoBrains(dirs: { a: string; b: string }): Promise<Record<'a' | 'b', BrainReport>> {
+ const report = {} as Record<'a' | 'b', BrainReport>;
+ for (const name of ['a', 'b'] as const) {
+ const slug = 'notes/quickstart-' + name;
+ const engine = await open(dirs[name]);
+ await importFromContent(engine, slug, '---\ntype: concept\ntitle: Quickstart ' + name + '\n---\nEmbedded quickstart page for brain ' + name + '.\n', { noEmbed: true });
+ const found = (await engine.searchKeyword('quickstart')).map((r) => r.slug);
+ await engine.disconnect();
+ report[name] = { slug, found, reopened: null };
+ }
+ for (const name of ['a', 'b'] as const) {
+ const engine = await open(dirs[name]);
+ report[name].reopened = (await engine.getPage(report[name].slug))?.title ?? null;
+ await engine.disconnect();
+ }
+ return report;
+}
+
+if (import.meta.main) {
+ const [a, b] = process.argv.slice(2);
+ const report = await runTwoBrains({
+ a: a ?? mkdtempSync(join(tmpdir(), 'gbrain-quickstart-a-')),
+ b: b ?? mkdtempSync(join(tmpdir(), 'gbrain-quickstart-b-')),
+ });
+ console.log(JSON.stringify(report));
+}
diff --git a/package.json b/package.json
index 24a6c03136..4dafb3e06f 100644
--- a/package.json
+++ b/package.json
@@ -164,6 +164,7 @@
"check:schema-error-predicates": "bun scripts/check-schema-error-predicates.ts",
"check:windows-hide": "bun scripts/check-windows-hide.ts",
"check:engine-sql-ratchet": "bun scripts/check-engine-sql-ratchet.ts",
+ "check:core-world-reads": "bun scripts/check-core-world-reads.ts",
"check:derived-census": "bun scripts/check-derived-census.ts",
"check:chunk-visibility": "bun scripts/check-chunk-visibility.ts",
"check:page-body-readers": "bun scripts/check-page-body-readers.ts",
diff --git a/scripts/check-core-world-reads.ts b/scripts/check-core-world-reads.ts
new file mode 100644
index 0000000000..72f752cb39
--- /dev/null
+++ b/scripts/check-core-world-reads.ts
@@ -0,0 +1,210 @@
+#!/usr/bin/env bun
+/**
+ * Core world-reads ratchet (GBRA-248 W1; docs/architecture/topologies.md#embedded-core-planned).
+ *
+ * The embeddable core (docs/architecture/topologies.md#embedded-core-planned)
+ * takes every setting as an argument and keeps per-brain state on the engine.
+ * This guard counts, per file under src/core (TypeScript compiler API), the
+ * places that still reach the process or the machine instead:
+ *
+ * load_config loadConfig( calls (reads ~/.gbrain on every call)
+ * process_env process.env / Bun.env references
+ * fs_import imports or requires of fs, node:fs, fs/promises
+ * module_collection module-level Map/Set/WeakMap/WeakSet built empty or
+ * held in a let (per-process state; a const table built
+ * from a literal does not count)
+ * spawn_import imports of src/core/spawn.ts or child_process
+ * process_global process.exit/on/once/addListener/prependListener/
+ * chdir/umask calls
+ * als_store new AsyncLocalStorage(
+ *
+ * Baseline: scripts/core-world-reads-baseline.tsv, rows
+ * path<TAB>metric<TAB>count<TAB>justification (the wave that removes it, or
+ * why it stays). Counts only fall:
+ * 1. a count above its row (no row = 0) -> FAIL
+ * 2. a count below its row (stale) -> FAIL
+ * 3. a duplicate, malformed or unjustified row -> FAIL
+ * --prune lowers stale rows to the actual count and drops rows at zero; it
+ * never raises a row or adds one.
+ *
+ * Seam: GBRAIN_GUARD_ROOT (fixture tree root; baseline read from
+ * <root>/scripts/core-world-reads-baseline.tsv).
+ */
+import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
+import { join, relative } from 'node:path';
+import ts from 'typescript';
+
+const ROOT = process.env.GBRAIN_GUARD_ROOT ?? join(import.meta.dir, '..');
+const BASELINE_REL = 'scripts/core-world-reads-baseline.tsv';
+const ANCHOR = 'docs/architecture/topologies.md#embedded-core-planned';
+export const METRICS = ['load_config', 'process_env', 'fs_import', 'module_collection', 'spawn_import', 'process_global', 'als_store'] as const;
+export type Metric = (typeof METRICS)[number];
+
+const FS_MODULES = new Set(['fs', 'node:fs', 'fs/promises', 'node:fs/promises']);
+const CHILD_PROCESS = new Set(['child_process', 'node:child_process']);
+const COLLECTIONS = new Set(['Map', 'Set', 'WeakMap', 'WeakSet']);
+const PROCESS_GLOBALS = new Set(['exit', 'on', 'once', 'addListener', 'prependListener', 'chdir', 'umask']);
+
+function tsFiles(dir: string): string[] {
+ if (!existsSync(dir)) return [];
+ const out: string[] = [];
+ for (const entry of readdirSync(dir).sort()) {
+ const full = join(dir, entry);
+ if (statSync(full).isDirectory()) out.push(...tsFiles(full));
+ else if (entry.endsWith('.ts') && !entry.endsWith('.d.ts')) out.push(full);
+ }
+ return out;
+}
+
+function isSpawnModule(spec: string): boolean {
+ return CHILD_PROCESS.has(spec) || (spec.startsWith('.') && /(^|\/)spawn(\.ts)?$/.test(spec));
+}
+
+function moduleSpecifier(node: ts.Node): string | null {
+ if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
+ return node.moduleSpecifier.text;
+ }
+ if (ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference) && ts.isStringLiteral(node.moduleReference.expression)) {
+ return node.moduleReference.expression.text;
+ }
+ if (ts.isCallExpression(node) && node.arguments.length > 0 && ts.isStringLiteral(node.arguments[0])
+ && (node.expression.kind === ts.SyntaxKind.ImportKeyword || (ts.isIdentifier(node.expression) && node.expression.text === 'require'))) {
+ return node.arguments[0].text;
+ }
+ return null;
+}
+
+function isProcessEnv(node: ts.Node): boolean {
+ return ts.isPropertyAccessExpression(node) && node.name.text === 'env' && ts.isIdentifier(node.expression)
+ && (node.expression.text === 'process' || node.expression.text === 'Bun');
+}
+
+function moduleCollections(sf: ts.SourceFile): number {
+ let n = 0;
+ for (const stmt of sf.statements) {
+ if (!ts.isVariableStatement(stmt)) continue;
+ const isLet = (stmt.declarationList.flags & ts.NodeFlags.Let) !== 0;
+ for (const decl of stmt.declarationList.declarations) {
+ const init = decl.initializer;
+ if (!init || !ts.isNewExpression(init) || !ts.isIdentifier(init.expression) || !COLLECTIONS.has(init.expression.text)) continue;
+ if (isLet || !init.arguments || init.arguments.length === 0) n++;
+ }
+ }
+ return n;
+}
+
+export function countFile(text: string, fileName = 'file.ts'): Record<Metric, number> {
+ const sf = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
+ const counts = Object.fromEntries(METRICS.map((m) => [m, 0])) as Record<Metric, number>;
+ counts.module_collection = moduleCollections(sf);
+ const visit = (node: ts.Node): void => {
+ const spec = moduleSpecifier(node);
+ if (spec !== null) {
+ if (FS_MODULES.has(spec)) counts.fs_import++;
+ if (isSpawnModule(spec)) counts.spawn_import++;
+ }
+ if (isProcessEnv(node)) counts.process_env++;
+ if (ts.isCallExpression(node)) {
+ const callee = node.expression;
+ if ((ts.isIdentifier(callee) && callee.text === 'loadConfig') || (ts.isPropertyAccessExpression(callee) && callee.name.text === 'loadConfig')) counts.load_config++;
+ if (ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression) && callee.expression.text === 'process' && PROCESS_GLOBALS.has(callee.name.text)) counts.process_global++;
+ }
+ if (ts.isNewExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'AsyncLocalStorage') counts.als_store++;
+ ts.forEachChild(node, visit);
+ };
+ visit(sf);
+ return counts;
+}
+
+export function scanTree(root: string): Map<string, number> {
+ const out = new Map<string, number>();
+ for (const abs of tsFiles(join(root, 'src/core'))) {
+ const rel = relative(root, abs).replace(/\\/g, '/');
+ const counts = countFile(readFileSync(abs, 'utf8'), abs);
+ for (const m of METRICS) if (counts[m] > 0) out.set(rel + '\t' + m, counts[m]);
+ }
+ return out;
+}
+
+interface Row { lineNo: number; key: string; count: number; justification: string; malformed: string | null }
+
+function parseBaseline(text: string): Row[] {
+ const rows: Row[] = [];
+ text.split('\n').forEach((raw, i) => {
+ if (raw.trim() === '' || raw.startsWith('#')) return;
+ const cols = raw.split('\t');
+ const [path, metric, count, justification] = cols;
+ let malformed: string | null = null;
+ if (cols.length !== 4 || !path) malformed = "want 'path<TAB>metric<TAB>count<TAB>justification'";
+ else if (!(METRICS as readonly string[]).includes(metric)) malformed = 'unknown metric ' + JSON.stringify(metric) + ' (one of ' + METRICS.join(', ') + ')';
+ else if (!/^[1-9]\d*$/.test(count)) malformed = 'count must be a positive integer';
+ else if (!justification || !justification.trim()) malformed = 'empty justification';
+ rows.push({ lineNo: i + 1, key: path + '\t' + metric, count: Number(count), justification: justification ?? '', malformed });
+ });
+ return rows;
+}
+
+if (import.meta.main) {
+ const prune = process.argv.includes('--prune');
+ const baselinePath = join(ROOT, BASELINE_REL);
+ if (!existsSync(baselinePath)) {
+ console.error('FAIL: ' + BASELINE_REL + ':1 baseline file missing');
+ console.error('Fix: git checkout ' + BASELINE_REL);
+ console.error('See: ' + ANCHOR);
+ process.exit(1);
+ }
+ const baselineText = readFileSync(baselinePath, 'utf8');
+ const rows = parseBaseline(baselineText);
+ const actual = scanTree(ROOT);
+ const violations: string[] = [];
+ const rewrite = new Map<number, string | null>();
+ const seen = new Set<string>();
+
+ for (const row of rows) {
+ const where = BASELINE_REL + ':' + row.lineNo;
+ if (row.malformed) {
+ violations.push('FAIL: ' + where + ' malformed row: ' + row.malformed);
+ continue;
+ }
+ const [path, metric] = row.key.split('\t');
+ if (seen.has(row.key)) {
+ rewrite.set(row.lineNo, null);
+ violations.push('FAIL: ' + where + ' duplicate row for ' + path + ' ' + metric + '\n Fix: delete this line (or: bun scripts/check-core-world-reads.ts --prune)');
+ continue;
+ }
+ seen.add(row.key);
+ const now = actual.get(row.key) ?? 0;
+ if (now > row.count) {
+ violations.push('FAIL: ' + path + ' ' + metric + ': baseline ' + row.count + ', actual ' + now + '\n Fix: take it from engine settings (passed in by the caller) instead of the process or the machine; if it must stay, raise the row with a justification in this PR');
+ } else if (now < row.count) {
+ rewrite.set(row.lineNo, now === 0 ? null : [path, metric, String(now), row.justification].join('\t'));
+ violations.push('FAIL: ' + where + ' stale row: ' + path + ' ' + metric + ': baseline ' + row.count + ', actual ' + now + '\n Fix: lower the row to ' + now + (now === 0 ? ' (delete it)' : '') + '; counts only fall (or: bun scripts/check-core-world-reads.ts --prune)');
+ }
+ }
+ for (const [key, now] of actual) {
+ if (seen.has(key)) continue;
+ const [path, metric] = key.split('\t');
+ violations.push('FAIL: ' + path + ' ' + metric + ': baseline 0, actual ' + now + '\n Fix: take it from engine settings (passed in by the caller) instead of the process or the machine; if it must stay, add a row with a justification in this PR');
+ }
+
+ if (prune) {
+ const kept: string[] = [];
+ baselineText.split('\n').forEach((line, i) => {
+ if (!rewrite.has(i + 1)) kept.push(line);
+ else if (rewrite.get(i + 1) !== null) kept.push(rewrite.get(i + 1)!);
+ });
+ writeFileSync(baselinePath, kept.join('\n'));
+ console.log('check-core-world-reads: pruned ' + rewrite.size + ' row(s) in ' + BASELINE_REL);
+ process.exit(0);
+ }
+ if (violations.length) {
+ for (const v of violations) console.error(v);
+ console.error('Why: the embeddable core takes every setting as an argument; world reads in src/core only fall (GBRA-248).');
+ console.error('See: ' + ANCHOR);
+ console.error('check-core-world-reads: ' + violations.length + ' violation(s)');
+ process.exit(1);
+ }
+ const totals = Object.fromEntries(METRICS.map((m) => [m, 0])) as Record<Metric, number>;
+ for (const [key, n] of actual) totals[key.split('\t')[1] as Metric] += n;
+ console.log('check-core-world-reads: ok (' + METRICS.map((m) => m + ' ' + totals[m]).join(', ') + ')');
+}
diff --git a/scripts/core-world-reads-baseline.tsv b/scripts/core-world-reads-baseline.tsv
new file mode 100644
index 0000000000..6fd9fce21d
--- /dev/null
+++ b/scripts/core-world-reads-baseline.tsv
@@ -0,0 +1,1117 @@
+# Core world-reads ratchet baseline (GBRA-248 W1). Enforced by
+# scripts/check-core-world-reads.ts via `bun run check:core-world-reads` (in verify).
+# Rows: path<TAB>metric<TAB>count<TAB>justification (the wave that removes it, or why it stays).
+# Counts only fall; --prune lowers stale rows and never raises one. docs/architecture/topologies.md#embedded-core-planned
+src/core/advisor/collect-setup-smells.ts process_env 1 W6: settings plane out of the core
+src/core/advisor/collect-uninstalled-brain-pack.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/advisor/history.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/agent-contract-log.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/agent-install/entry.ts process_global 1 W7: process-wide effects move to src/cli
+src/core/agent-install/init-state.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/agent-install/init-state.ts process_global 1 W7: process-wide effects move to src/cli
+src/core/agent-install/setup.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/agent-install/setup.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/agent-install/shared-skills.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/agent-install/state.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/agent-install/state.ts process_env 1 W6: settings plane out of the core
+src/core/agent-output.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/agent-output.ts process_env 1 W6: settings plane out of the core
+src/core/ai/anthropic-key.ts load_config 1 W3: AI settings arrive on the engine
+src/core/ai/anthropic-key.ts process_env 3 W3: AI settings arrive on the engine
+src/core/ai/build-gateway-config.ts load_config 1 W3: AI settings arrive on the engine
+src/core/ai/build-gateway-config.ts process_env 13 W3: AI settings arrive on the engine
+src/core/ai/call-log.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/ai/call-log.ts process_env 1 W3: AI settings arrive on the engine
+src/core/ai/chat-fallback-planes.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/ai/chat-fallback-planes.ts process_env 4 W3: AI settings arrive on the engine
+src/core/ai/chat-key-probe.ts load_config 1 W3: AI settings arrive on the engine
+src/core/ai/chat-key-probe.ts process_env 1 W3: AI settings arrive on the engine
+src/core/ai/chat-usage.ts als_store 2 W2: engine scope (decision E) replaces ad hoc async context
+src/core/ai/decide/config.ts process_env 1 W3: AI settings arrive on the engine
+src/core/ai/decide/dataset.ts module_collection 2 W3: per-engine gateway state
+src/core/ai/decide/index.ts process_env 1 W3: AI settings arrive on the engine
+src/core/ai/decide/receipts.ts process_env 2 W3: AI settings arrive on the engine
+src/core/ai/decide/review-lane.ts module_collection 1 W3: per-engine gateway state
+src/core/ai/decide/runtime.ts module_collection 1 W3: per-engine gateway state
+src/core/ai/decide/store.ts module_collection 2 W3: per-engine gateway state
+src/core/ai/gateway-model-sources.ts module_collection 1 W3: per-engine gateway state
+src/core/ai/gateway-model-sources.ts process_env 1 W3: AI settings arrive on the engine
+src/core/ai/gateway.ts als_store 2 W2: engine scope (decision E) replaces ad hoc async context
+src/core/ai/gateway.ts load_config 3 W3: AI settings arrive on the engine
+src/core/ai/gateway.ts module_collection 5 W3: per-engine gateway state
+src/core/ai/gateway.ts process_env 4 W3: AI settings arrive on the engine
+src/core/ai/invocation-guard.ts als_store 3 W2: engine scope (decision E) replaces ad hoc async context
+src/core/ai/invocation-guard.ts module_collection 2 W3: per-engine gateway state
+src/core/ai/key-warnings.ts process_env 3 W3: AI settings arrive on the engine
+src/core/ai/legacy-model-pin.ts module_collection 1 W3: per-engine gateway state
+src/core/ai/openai-latest.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/ai/openai-latest.ts process_env 2 W3: AI settings arrive on the engine
+src/core/ai/probes.ts process_env 3 W3: AI settings arrive on the engine
+src/core/ai/provider-env.ts process_env 2 W3: AI settings arrive on the engine
+src/core/ai/providers/claude-cli-continuation.ts module_collection 1 W3: per-engine gateway state
+src/core/ai/providers/claude-cli-language-model.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/ai/providers/claude-cli-language-model.ts process_env 3 W3: AI settings arrive on the engine
+src/core/ai/providers/claude-cli-language-model.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/ai/providers/claude-cli-scratch.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/ai/query-embed-cache.ts module_collection 1 W3: per-engine gateway state
+src/core/ai/recipes/azure-openai.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/ai/recipes/llama-server.ts process_env 1 W3: AI settings arrive on the engine
+src/core/ai/recipes/lmstudio.ts process_env 1 W3: AI settings arrive on the engine
+src/core/ai/reranker-readiness-engine.ts load_config 1 W3: AI settings arrive on the engine
+src/core/ai/reranker-readiness-engine.ts process_env 1 W3: AI settings arrive on the engine
+src/core/archive-crawler-config.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/atomic-write.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/attendance-repair.ts process_env 1 W6: settings plane out of the core
+src/core/audit-quality-probe.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/audit-skill-brain-first.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/audit-skill-brain-first.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/audit-synopsis.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/audit-week-file.ts process_env 1 W6: settings plane out of the core
+src/core/audit/audit-writer.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/audit/audit-writer.ts process_env 1 W6: settings plane out of the core
+src/core/audit/batch-retry-audit.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/audit/lock-renewal-audit.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/audit/self-upgrade-audit.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/autopilot-heartbeat.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/autopilot-lock.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/autopilot-lock.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/autopilot-paths.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/autopilot-paths.ts process_env 1 W6: settings plane out of the core
+src/core/backfill-base.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/backfill-registry.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/background-work.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/background-work.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/background-work.ts process_env 1 W6: settings plane out of the core
+src/core/backoff.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/backup/archive.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/backup/coverage.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/backup/preflight.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/backup/private-path.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/backup/private-path.ts process_env 3 W6: settings plane out of the core
+src/core/backup/private-path.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/backup/repository.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/backup/repository.ts process_env 2 W6: settings plane out of the core
+src/core/backup/repository.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/backup/runtime-artefacts.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/backup/snapshot.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/backup/status-file.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/backup/status-file.ts process_env 5 W6: settings plane out of the core
+src/core/behavior-change-notice.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/behavior-change-notice.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/behavior-change-notice.ts process_env 1 W6: settings plane out of the core
+src/core/belief/keys.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/belief/ledger.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/belief/preimages.ts process_env 2 W6: settings plane out of the core
+src/core/belief/purge-mirror.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/belief/state.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/binary-self-update.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/binary-self-update.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/bootstrap/adopt-connection.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/adopted-connections.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/assets.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/atomic-write.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/attach.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/codex-hooks.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/codex-toml.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/contract.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/format.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/harness-brain-first.ts process_env 3 W6: settings plane out of the core
+src/core/bootstrap/harness-cleanup.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/harness-cleanup.ts load_config 1 W6: settings plane out of the core
+src/core/bootstrap/harness-skills.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/harness-skills.ts load_config 1 W6: settings plane out of the core
+src/core/bootstrap/harness.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/harness.ts load_config 4 W6: settings plane out of the core
+src/core/bootstrap/harness.ts process_env 2 W6: settings plane out of the core
+src/core/bootstrap/hooks.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/host-specs.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/host-specs.ts process_env 7 W6: settings plane out of the core
+src/core/bootstrap/instructions-block.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/interview.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/lock.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/opencode-json.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/plugin-lanes.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/plugin-lanes.ts process_env 1 W6: settings plane out of the core
+src/core/bootstrap/render-host.ts process_env 1 W6: settings plane out of the core
+src/core/bootstrap/render.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/repo.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/status.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/status.ts process_env 1 W6: settings plane out of the core
+src/core/bootstrap/status.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/bootstrap/template-repo.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/uninstall.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/uninstall.ts process_env 1 W6: settings plane out of the core
+src/core/bootstrap/verify.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bootstrap/verify.ts process_env 5 W6: settings plane out of the core
+src/core/bootstrap/verify.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/bounded-child-exec.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bounded-child-exec.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/brain-registry.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/brain-registry.ts load_config 1 W6: settings plane out of the core
+src/core/brain-registry.ts process_env 1 W6: settings plane out of the core
+src/core/brain-repo-durability.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/brain-repo-durability.ts process_env 7 W6: settings plane out of the core
+src/core/brain-repo-durability.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/brain-resolver.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/brain-resolver.ts process_env 1 W6: settings plane out of the core
+src/core/brain-score-recommendations.ts process_env 1 W6: settings plane out of the core
+src/core/brain-writer.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/brainstorm/checkpoint.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/brainstorm/orchestrator.ts process_global 1 W7: process-wide effects move to src/cli
+src/core/budget/budget-tracker.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/budget/budget-tracker.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/bun-floor.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/bun-floor.ts process_env 1 W6: settings plane out of the core
+src/core/bun-floor.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/calibration/gstack-coupling.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/calibration/undo-wave.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/capability.ts load_config 1 W6: settings plane out of the core
+src/core/capability.ts process_env 1 W6: settings plane out of the core
+src/core/check-resolvable.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/checkout-head.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/chunkers/code.ts module_collection 3 W6: per-engine state, or mark as a constant table
+src/core/chunkers/code.ts process_env 1 W6: settings plane out of the core
+src/core/chunkers/token-estimate.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/classic-file-holds.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/classic-file-holds.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/claw-test/agent-runner.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/claw-test/agent-runner.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/claw-test/agent-runner.ts process_env 2 W6: settings plane out of the core
+src/core/claw-test/agent-runner.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/claw-test/runners/grok.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/claw-test/runners/grok.ts process_env 1 W6: settings plane out of the core
+src/core/claw-test/runners/grok.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/claw-test/runners/opencode.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/claw-test/runners/opencode.ts process_env 2 W6: settings plane out of the core
+src/core/claw-test/runners/opencode.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/claw-test/scenarios.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/claw-test/scenarios.ts process_env 2 W6: settings plane out of the core
+src/core/claw-test/seed-pglite.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/claw-test/transcript-capture.ts fs_import 2 W7: filesystem boundary moves to the local app
+src/core/claw-test/transcript-capture.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/cli-force-exit.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cli-force-exit.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/cli-force-exit.ts process_env 4 W6: settings plane out of the core
+src/core/cli-force-exit.ts process_global 1 W7: process-wide effects move to src/cli
+src/core/cli-force-exit.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/cli-options.ts process_global 1 W7: process-wide effects move to src/cli
+src/core/cli-preflight.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cli-preflight.ts process_env 7 W6: settings plane out of the core
+src/core/cli-preflight.ts process_global 10 W7: process-wide effects move to src/cli
+src/core/cli-preflight.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/cli-socket/execute.ts load_config 1 W6: settings plane out of the core
+src/core/cli-socket/fs-guard.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cli-socket/identity.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cli-socket/output-capture.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/cli-socket/probe.ts load_config 1 W6: settings plane out of the core
+src/core/cli-socket/probe.ts process_env 1 W6: settings plane out of the core
+src/core/cli-socket/refusals.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cli-socket/server.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cli-socket/server.ts process_env 1 W6: settings plane out of the core
+src/core/cli-socket/server.ts process_global 3 W7: process-wide effects move to src/cli
+src/core/code-intel/sinks/index.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/commit-notifier.ts process_env 2 W6: settings plane out of the core
+src/core/company-brain/profile.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/company-brain/revision.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/company-brain/revision.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/company-brain/runtime.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/config-db-merge.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/config-snapshot.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/config-snapshot.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/config.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/config.ts load_config 1 W6: settings plane out of the core
+src/core/config.ts process_env 54 W6: settings plane out of the core
+src/core/connection-audit.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/connection-manager.ts process_env 6 W6: settings plane out of the core
+src/core/connectors/credentials.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/connectors/credentials.ts process_env 2 W6: settings plane out of the core
+src/core/connectors/item-holds-store.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/connectors/providers/claude.ts module_collection 3 W6: per-engine state, or mark as a constant table
+src/core/connectors/spool.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/consent-cli.ts process_global 1 W7: process-wide effects move to src/cli
+src/core/consent.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/console-prefix.ts als_store 3 W2: engine scope (decision E) replaces ad hoc async context
+src/core/content-repair/llm.ts load_config 1 W6: settings plane out of the core
+src/core/content-repair/llm.ts process_env 1 W6: settings plane out of the core
+src/core/content-sanity-literals.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/context-engine.ts fs_import 4 W7: filesystem boundary moves to the local app
+src/core/context-engine.ts load_config 2 W6: settings plane out of the core
+src/core/context-engine.ts process_env 1 W6: settings plane out of the core
+src/core/context/capture-consent.ts fs_import 2 W7: filesystem boundary moves to the local app
+src/core/context/capture-consent.ts load_config 1 W6: settings plane out of the core
+src/core/context/checkpoint-harvest.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/context/checkpoint-harvest.ts module_collection 3 W6: per-engine state, or mark as a constant table
+src/core/context/compiled-core.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/context/compiled-core.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/context/corpus-segments.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/context/corpus-source.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/context/corpus-source.ts process_env 1 W6: settings plane out of the core
+src/core/context/corpus-windows.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/context/corpus-windows.ts process_env 1 W6: settings plane out of the core
+src/core/context/hook-heartbeat.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/context/hook-heartbeat.ts process_env 4 W6: settings plane out of the core
+src/core/context/hook-heartbeat.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/context/ipc-path.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/context/ipc-path.ts process_env 1 W6: settings plane out of the core
+src/core/context/load-warning.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/context/openclaw-core.ts load_config 1 W6: settings plane out of the core
+src/core/context/openclaw-core.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/context/openclaw-core.ts process_env 4 W6: settings plane out of the core
+src/core/context/pressure.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/context/pressure.ts process_env 2 W6: settings plane out of the core
+src/core/context/proactive-brief.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/context/recall-needed.ts process_env 1 W6: settings plane out of the core
+src/core/context/reflex.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/context/reflex.ts load_config 2 W6: settings plane out of the core
+src/core/context/reflex.ts process_env 4 W6: settings plane out of the core
+src/core/context/resolve-ipc.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/context/resolve-ipc.ts process_env 1 W6: settings plane out of the core
+src/core/context/seat.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/context/sensitivity-scan.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/context/sensitivity-scan.ts process_env 1 W6: settings plane out of the core
+src/core/context/session-speaker.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/context/session-speaker.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/context/session-start-pack.ts process_env 2 W6: settings plane out of the core
+src/core/context/volunteer-events.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/contextual-retrieval-service.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/contextual-retrieval-service.ts process_env 1 W6: settings plane out of the core
+src/core/conversation-parser/body.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/conversation-parser/llm-base.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/conversation-parser/nightly-probe.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/conversation-parser/parse.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/creds/redirect.ts process_env 1 W6: settings plane out of the core
+src/core/creds/redirect.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/creds/relay-client.ts process_env 1 W6: settings plane out of the core
+src/core/creds/vault.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cross-modal-eval/receipt-name.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cross-modal-eval/receipt-write.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cycle.ts fs_import 2 W7: filesystem boundary moves to the local app
+src/core/cycle.ts load_config 2 W6: settings plane out of the core
+src/core/cycle.ts process_env 1 W6: settings plane out of the core
+src/core/cycle/auto-think.ts load_config 1 W6: settings plane out of the core
+src/core/cycle/budget-meter.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cycle/budget-meter.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/cycle/calibration-profile.ts load_config 1 W6: settings plane out of the core
+src/core/cycle/decide-datasets.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cycle/derived-write-through.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cycle/derived-write-through.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/cycle/edge-contradictions.ts process_env 1 W6: settings plane out of the core
+src/core/cycle/extract-atoms-generation.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cycle/extract-atoms.ts load_config 1 W6: settings plane out of the core
+src/core/cycle/extract-facts.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cycle/extract-takes.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cycle/filing-rules.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cycle/nightly-probe-adapters.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cycle/nightly-quality-probe.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cycle/pack-phase-gate.ts load_config 1 W6: settings plane out of the core
+src/core/cycle/phantom-redirect.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cycle/phantom-redirect.ts process_env 1 W6: settings plane out of the core
+src/core/cycle/synthesize-child-verify.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cycle/synthesize-postprocess.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cycle/synthesize-postprocess.ts load_config 1 W6: settings plane out of the core
+src/core/cycle/synthesize-source-routing.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/cycle/synthesize.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/cycle/transcript-discovery.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/db-lock.ts process_env 1 W6: settings plane out of the core
+src/core/db-repair-receipts.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/db.ts process_env 12 W6: settings plane out of the core
+src/core/destructive-guard.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/direct-pool-profile.ts process_env 1 W6: settings plane out of the core
+src/core/disk-walk.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/docker-postgres.ts process_env 1 W6: settings plane out of the core
+src/core/docker-postgres.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/doctor-categories.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/doctor-remote.ts process_env 3 W6: settings plane out of the core
+src/core/doctor-remote.ts process_global 1 W7: process-wide effects move to src/cli
+src/core/dry-fix.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/eligibility/fence-overlay.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/embed-backfill-submit.ts load_config 1 W6: settings plane out of the core
+src/core/embed-concurrency.ts process_env 2 W6: settings plane out of the core
+src/core/embed-consent.ts process_env 1 W6: settings plane out of the core
+src/core/embed-overlength-heal.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/embed-overlength-heal.ts process_env 1 W6: settings plane out of the core
+src/core/embed-stale-images.ts process_env 1 W6: settings plane out of the core
+src/core/embed-stale-images.ts process_global 1 W7: process-wide effects move to src/cli
+src/core/embed-stale-images.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/embed-stall.ts process_env 1 W6: settings plane out of the core
+src/core/embed-takes.ts process_env 1 W6: settings plane out of the core
+src/core/embedding-dim-check.ts load_config 1 W6: settings plane out of the core
+src/core/embedding-dim-check.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/embedding-disabled.ts load_config 1 W6: settings plane out of the core
+src/core/embedding-input-limit.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/embedding-input-limit.ts process_env 1 W6: settings plane out of the core
+src/core/embedding-migration-worst-case.ts process_env 2 W6: settings plane out of the core
+src/core/embedding-migration.ts process_env 3 W6: settings plane out of the core
+src/core/embedding-state.ts load_config 1 W6: settings plane out of the core
+src/core/engine-connect.ts load_config 1 W6: settings plane out of the core
+src/core/engine-connect.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/engine-connect.ts process_env 2 W6: settings plane out of the core
+src/core/env-number.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/env-number.ts process_env 1 W6: settings plane out of the core
+src/core/env-trust.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/env-trust.ts process_env 1 W6: settings plane out of the core
+src/core/eval-capture.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/eval-capture.ts process_env 1 W6: settings plane out of the core
+src/core/eval-contradictions/cost-prompt.ts process_env 2 W6: settings plane out of the core
+src/core/eval-contradictions/cost-prompt.ts process_global 1 W7: process-wide effects move to src/cli
+src/core/eval/drift-watch.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/eval/drift-watch.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/execution-env.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/execution-env.ts process_env 3 W6: settings plane out of the core
+src/core/export-publish.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/export-stage.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/extract-frontmatter.ts load_config 1 W6: settings plane out of the core
+src/core/extract-takes-from-pages.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/extract-takes-from-pages.ts load_config 1 W6: settings plane out of the core
+src/core/extract/rollup-writer.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/extraction-lag.ts process_env 2 W6: settings plane out of the core
+src/core/facts/backstop.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/facts/backstop.ts load_config 1 W6: settings plane out of the core
+src/core/facts/backstop.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/facts/backstop.ts process_env 1 W6: settings plane out of the core
+src/core/facts/capture-sources.ts load_config 1 W6: settings plane out of the core
+src/core/facts/conversation-publication.ts load_config 1 W6: settings plane out of the core
+src/core/facts/conversation-publication.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/facts/drain.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/facts/extract.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/facts/fence-write.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/facts/fence-write.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/facts/file-body-guard.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/facts/forget.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/facts/meta-hook.ts module_collection 3 W6: per-engine state, or mark as a constant table
+src/core/facts/proposal-review.ts load_config 1 W6: settings plane out of the core
+src/core/facts/proposal-supersede.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/facts/purge-verify.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/facts/purge-verify.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/facts/stub-guard-audit.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/facts/unfenced-facts.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/facts/writeback-config.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/feedback/record.ts module_collection 3 W6: per-engine state, or mark as a constant table
+src/core/fence-repair/census.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/fence-repair/census.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/fence-repair/model.ts load_config 1 W6: settings plane out of the core
+src/core/fence-repair/model.ts process_env 1 W6: settings plane out of the core
+src/core/fence-repair/repair-io.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/fence-repair/repair-io.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/fence-repair/uncommitted.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/fence-repair/uncommitted.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/fence-scan.ts process_env 1 W6: settings plane out of the core
+src/core/file-resolver.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/filing-audit.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/fix-routing.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/forward-progress.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/friction.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/friction.ts process_env 1 W6: settings plane out of the core
+src/core/fs-durable.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/fts-language.ts process_env 1 W6: settings plane out of the core
+src/core/funnel.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/funnel.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/gbrain-env-file.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/gbrain-env-file.ts process_env 2 W6: settings plane out of the core
+src/core/gbrain-home.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/generations/adapters/atoms.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/generations/managed-retire.ts load_config 1 W6: settings plane out of the core
+src/core/ghost-pages.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/git-checkout.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/git-env.ts process_env 2 W6: settings plane out of the core
+src/core/git-first-commit.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/git-first-commit.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/git-head.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/git-remote.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/git-remote.ts process_env 1 W6: settings plane out of the core
+src/core/git-remote.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/git-transport.ts process_env 1 W6: settings plane out of the core
+src/core/git-visible-files.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/git-visible-files.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/git-visible-files.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/git/commit-guard.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/git/commit-push.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/git/commit-push.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/git/commit-push.ts process_env 7 W6: settings plane out of the core
+src/core/git/commit-push.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/github-app-token.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/github-source.ts fs_import 2 W7: filesystem boundary moves to the local app
+src/core/github-source.ts load_config 1 W6: settings plane out of the core
+src/core/github-source.ts process_env 2 W6: settings plane out of the core
+src/core/google/access.ts process_env 1 W6: settings plane out of the core
+src/core/google/access.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/google/file-modes.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/google/google-source.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/google/google-source.ts load_config 1 W6: settings plane out of the core
+src/core/google/loop-detect.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/google/loops-reciprocity.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/google/people-calendar-sweep.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/google/sweep-shared.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/guarded-http.ts process_env 1 W6: settings plane out of the core
+src/core/guardrails.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/guardrails.ts process_env 2 W6: settings plane out of the core
+src/core/hardened-git.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/hardened-git.ts process_env 2 W6: settings plane out of the core
+src/core/hardened-git.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/harness/credentials.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/harness/install.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/harness/install.ts process_env 3 W6: settings plane out of the core
+src/core/harness/install.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/harness/native-router.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/harness/native-router.ts process_env 1 W6: settings plane out of the core
+src/core/harness/oauth-setup.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/harness/shared-skills.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/harness/status.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/health-memo.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/health-memo.ts process_env 2 W6: settings plane out of the core
+src/core/image-asset-resolver.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/import-checkpoint.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/import-file.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/import-file.ts process_env 2 W6: settings plane out of the core
+src/core/import-identity.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/import-screen.ts load_config 1 W6: settings plane out of the core
+src/core/import-screen.ts process_env 1 W6: settings plane out of the core
+src/core/ingestion/skillpack-load.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/ingestion/skillpack-load.ts process_env 1 W6: settings plane out of the core
+src/core/ingestion/sources/file-watcher.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/ingestion/sources/gstack-learnings.ts fs_import 2 W7: filesystem boundary moves to the local app
+src/core/ingestion/sources/inbox-folder.ts fs_import 2 W7: filesystem boundary moves to the local app
+src/core/ingestion/sources/markdown-greenfield.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/init-embed-check.ts process_env 1 W6: settings plane out of the core
+src/core/interaction.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/interaction.ts process_env 3 W6: settings plane out of the core
+src/core/last-retrieved.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/link-extraction.ts process_env 2 W6: settings plane out of the core
+src/core/link-validity.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/markdown-chunks.ts process_env 1 W6: settings plane out of the core
+src/core/markdown.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/mcp-client.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/mcp-client.ts process_env 1 W6: settings plane out of the core
+src/core/memory-trace.ts process_env 2 W6: settings plane out of the core
+src/core/mentions/pass.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/migrate.ts process_env 2 W6: settings plane out of the core
+src/core/migration-orchestration-lock.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/minions/admission.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/minions/admission.ts process_env 2 W6: settings plane out of the core
+src/core/minions/agent-audit.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/minions/agent-audit.ts process_env 1 W6: settings plane out of the core
+src/core/minions/backpressure-audit.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/minions/backpressure-audit.ts process_env 1 W6: settings plane out of the core
+src/core/minions/child-job-runner.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/minions/child-job-runner.ts process_env 1 W6: settings plane out of the core
+src/core/minions/child-job-runner.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/minions/child-readiness.ts process_env 3 W6: settings plane out of the core
+src/core/minions/child-readiness.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/minions/child-worker-supervisor.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/minions/child-worker-supervisor.ts process_env 1 W6: settings plane out of the core
+src/core/minions/child-worker-supervisor.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/minions/detached-stderr.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/minions/detached-stderr.ts process_env 1 W6: settings plane out of the core
+src/core/minions/detached-stderr.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/minions/global-maintenance-stall.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/minions/handlers/contextual-reindex-per-chunk.ts process_env 1 W6: settings plane out of the core
+src/core/minions/handlers/facts-absorb.ts load_config 1 W6: settings plane out of the core
+src/core/minions/handlers/shell-validate.ts load_config 1 W6: settings plane out of the core
+src/core/minions/handlers/shell.ts load_config 2 W6: settings plane out of the core
+src/core/minions/handlers/shell.ts process_env 2 W6: settings plane out of the core
+src/core/minions/handlers/shell.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/minions/handlers/subagent-audit.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/minions/handlers/subagent.ts load_config 1 W6: settings plane out of the core
+src/core/minions/handlers/subagent.ts process_env 1 W6: settings plane out of the core
+src/core/minions/handlers/supervisor-audit.ts fs_import 2 W7: filesystem boundary moves to the local app
+src/core/minions/job-isolation.ts fs_import 2 W7: filesystem boundary moves to the local app
+src/core/minions/job-isolation.ts process_env 2 W6: settings plane out of the core
+src/core/minions/job-isolation.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/minions/llm-halt-cooldown.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/minions/llm-halt-cooldown.ts process_env 1 W6: settings plane out of the core
+src/core/minions/lock-renewal-tick.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/minions/plugin-loader.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/minions/plugin-loader.ts process_env 1 W6: settings plane out of the core
+src/core/minions/proc-rss.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/minions/processing-state.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/minions/processing-state.ts process_env 1 W6: settings plane out of the core
+src/core/minions/queue.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/minions/queue.ts process_env 2 W6: settings plane out of the core
+src/core/minions/rss-default.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/minions/run-child.ts process_global 2 W7: process-wide effects move to src/cli
+src/core/minions/source-filesystem.ts als_store 3 W2: engine scope (decision E) replaces ad hoc async context
+src/core/minions/source-filesystem.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/minions/spawn-helpers.ts process_env 1 W6: settings plane out of the core
+src/core/minions/spawn-helpers.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/minions/submission-authority.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/minions/submission-authority.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/minions/supervisor-pid.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/minions/supervisor.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/minions/supervisor.ts process_env 4 W6: settings plane out of the core
+src/core/minions/supervisor.ts process_global 6 W7: process-wide effects move to src/cli
+src/core/minions/sync-queue-wake.ts process_env 3 W6: settings plane out of the core
+src/core/minions/terminal-hook.ts process_env 1 W6: settings plane out of the core
+src/core/minions/terminal-hook.ts process_global 1 W7: process-wide effects move to src/cli
+src/core/minions/terminal-hook.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/minions/worker-registry.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/minions/worker-registry.ts load_config 1 W6: settings plane out of the core
+src/core/minions/worker-registry.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/minions/worker.ts fs_import 2 W7: filesystem boundary moves to the local app
+src/core/minions/worker.ts process_env 2 W6: settings plane out of the core
+src/core/minions/worker.ts process_global 3 W7: process-wide effects move to src/cli
+src/core/model-config.ts load_config 1 W6: settings plane out of the core
+src/core/model-config.ts module_collection 3 W6: per-engine state, or mark as a constant table
+src/core/model-config.ts process_env 4 W6: settings plane out of the core
+src/core/mounts-cache.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/multi-source-drift.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/multi-source-drift.ts process_env 1 W6: settings plane out of the core
+src/core/notice-ledger.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/notifier/detect.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/notifier/resident.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/notifier/resident.ts process_env 5 W6: settings plane out of the core
+src/core/npm-squat-check.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/oauth-provider.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/onboard/checks.ts load_config 1 W6: settings plane out of the core
+src/core/onboard/init-nudge.ts process_env 2 W6: settings plane out of the core
+src/core/onboard/mcp-onboarding.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/onboard/mcp-onboarding.ts process_env 1 W6: settings plane out of the core
+src/core/onboard/writeback-nudge.ts load_config 1 W6: settings plane out of the core
+src/core/onboard/writeback-nudge.ts process_env 1 W6: settings plane out of the core
+src/core/operation-load.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/ops/context.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/ops/contract.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/ops/facts.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/ops/files.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/ops/schema-packs.ts fs_import 2 W7: filesystem boundary moves to the local app
+src/core/ops/schema-packs.ts load_config 4 W6: settings plane out of the core
+src/core/ops/skillopt.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/output/post-write.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/oversized-backfill.ts load_config 2 W6: settings plane out of the core
+src/core/pace-mode.ts process_env 1 W6: settings plane out of the core
+src/core/page-body/limits.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/page-body/projection.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/page-body/segment-facts.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/page-body/streamed-import.ts fs_import 2 W7: filesystem boundary moves to the local app
+src/core/page-lock.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/page-state/projection-window.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/page-state/projections.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/page-state/transactions.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/page-summary.ts process_env 1 W6: settings plane out of the core
+src/core/path-confine.ts fs_import 2 W7: filesystem boundary moves to the local app
+src/core/persistence/activation.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/admission-origin.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/persistence/atom-maintenance.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/atom-retry.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/attribution.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/bounded-reads.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/bundle-files.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/bundle-files.ts process_global 1 W7: process-wide effects move to src/cli
+src/core/persistence/canonical-projections.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/capacity-snapshot.ts module_collection 3 W6: per-engine state, or mark as a constant table
+src/core/persistence/checkout-state.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/persistence/compaction-pass.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/connector-sync.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/connector-sync.ts load_config 5 W6: settings plane out of the core
+src/core/persistence/consumer-diagnostics.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/consumer-heartbeat.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/consumer-lane.ts process_env 1 W6: settings plane out of the core
+src/core/persistence/consumer.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/persistence/context.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/persistence/coordination-lock.ts process_env 2 W6: settings plane out of the core
+src/core/persistence/coordinator.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/coordinator.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/deactivation.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/detached-pages.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/detached-pages.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/persistence/drain-step.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/drift-conflicts.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/effect-git.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/effect-git.ts process_env 2 W6: settings plane out of the core
+src/core/persistence/effect-journal.ts load_config 1 W6: settings plane out of the core
+src/core/persistence/effect-recovery-scan.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/effect-recovery.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/effect-settle.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/effects.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/engine-graduation.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/engine-graduation.ts process_env 10 W6: settings plane out of the core
+src/core/persistence/engine-graduation.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/persistence/file-claims.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/file-repair.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/filesystem-guard.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/persistence/filesystem-guard.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/persistence/git-conversion.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/git-conversion.ts load_config 1 W6: settings plane out of the core
+src/core/persistence/git-declared.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/persistence/git-door.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/git-door.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/persistence/git-durability-administration.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/git-gap.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/graduation-custody.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/graduation-custody.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/persistence/graduation-custody.ts process_env 1 W6: settings plane out of the core
+src/core/persistence/graduation-schema.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/graduation-serve-guard.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/graduation-serve-guard.ts load_config 6 W6: settings plane out of the core
+src/core/persistence/graduation-serve-guard.ts process_global 2 W7: process-wide effects move to src/cli
+src/core/persistence/graduation-target.ts process_env 5 W6: settings plane out of the core
+src/core/persistence/group-publish.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/persistence/head-blocker.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/held-reads.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/hosted-repo.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/hosted-repo.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/persistence/housekeeping-turn.ts process_env 1 W6: settings plane out of the core
+src/core/persistence/identity.ts als_store 3 W2: engine scope (decision E) replaces ad hoc async context
+src/core/persistence/identity.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/identity.ts process_env 2 W6: settings plane out of the core
+src/core/persistence/ignore-rules.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/ignore-rules.ts module_collection 3 W6: per-engine state, or mark as a constant table
+src/core/persistence/ignore-rules.ts process_env 3 W6: settings plane out of the core
+src/core/persistence/import-mutations.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/import-mutations.ts load_config 1 W6: settings plane out of the core
+src/core/persistence/import-mutations.ts process_env 1 W6: settings plane out of the core
+src/core/persistence/import-prepare.ts fs_import 2 W5: repo-less persistence for hosts
+src/core/persistence/import-reads.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/index-lock-reclaim.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/ipc.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/journal.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/journal.ts process_env 1 W6: settings plane out of the core
+src/core/persistence/large-file.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/links-preparation.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/local-client.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/maintenance.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/native-file-target.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/native-lock.ts fs_import 2 W5: repo-less persistence for hosts
+src/core/persistence/native-lock.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/persistence/onboarding.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/origin-guard.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/origin-twins.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/ownership.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/ownership.ts process_env 2 W6: settings plane out of the core
+src/core/persistence/page-mutations.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/page-prepare.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/page-purge.ts module_collection 3 W6: per-engine state, or mark as a constant table
+src/core/persistence/page-visibility.ts process_env 1 W6: settings plane out of the core
+src/core/persistence/pending-import.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/persistence/physical-root-record.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/physical-root-record.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/persistence/physical-root-recovery.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/physical-root.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/pool-capacity.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/persistence/preadmit-cache.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/prepared-maintenance.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/prepared-maintenance.ts load_config 1 W6: settings plane out of the core
+src/core/persistence/projection-reindex.ts load_config 1 W6: settings plane out of the core
+src/core/persistence/protocol.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/publication-deadline.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/persistence/publication-timing.ts process_env 1 W6: settings plane out of the core
+src/core/persistence/purge-deleted.ts load_config 1 W6: settings plane out of the core
+src/core/persistence/put-page-screen.ts load_config 1 W6: settings plane out of the core
+src/core/persistence/reconcile-audit.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/reconcile-backup.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/reconcile-prepare.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/reconcile-state.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/reconcile-state.ts load_config 1 W6: settings plane out of the core
+src/core/persistence/reconcile-state.ts process_env 1 W6: settings plane out of the core
+src/core/persistence/reconcile.ts load_config 1 W6: settings plane out of the core
+src/core/persistence/recovery-resolve.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/resolve-paths.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/root-registry.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/screening-paths.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/persistence/segmented-mirror-gate.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/persistence/service.ts module_collection 8 W6: per-engine state, or mark as a constant table
+src/core/persistence/slice-memo.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/source-lifecycle.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/source-storage.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/source-storage.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/staging.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/switches.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/persistence/switches.ts process_env 1 W6: settings plane out of the core
+src/core/persistence/sync-authority.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/persistence/sync-blobs.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/persistence/sync-capacity-preflight.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/sync-discovery.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/sync-discovery.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/sync-discovery.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/persistence/sync-entry-fault.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/sync-entry-fault.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/sync-ghosts.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/sync-ghosts.ts process_env 1 W6: settings plane out of the core
+src/core/persistence/sync-git-stream.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/sync-git-stream.ts module_collection 3 W6: per-engine state, or mark as a constant table
+src/core/persistence/sync-group.ts process_env 5 W6: settings plane out of the core
+src/core/persistence/sync-held-deletions.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/persistence/sync-holds.ts process_env 1 W6: settings plane out of the core
+src/core/persistence/sync-idle-skips.ts process_env 1 W6: settings plane out of the core
+src/core/persistence/sync-image.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/sync-lanes.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/sync-lease.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/persistence/sync-markers.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/sync-origin-evidence.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/persistence/sync-origin-evidence.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/persistence/sync-origin.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/sync-pass-batch.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/persistence/sync-pass-episode.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/sync-pass-episode.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/sync-pass-fold.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/sync-pass-run.ts load_config 1 W6: settings plane out of the core
+src/core/persistence/sync-pass.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/sync-pass.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/persistence/sync-prepare.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/sync-prepare.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/persistence/sync-prescreen.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/sync-run.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/sync-run.ts load_config 3 W6: settings plane out of the core
+src/core/persistence/sync-run.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/persistence/sync-screen.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/sync-screen.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/persistence/sync-slug-mode.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/sync-streamed.ts fs_import 2 W5: repo-less persistence for hosts
+src/core/persistence/sync-tree-reuse.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/persistence/sync-tree-reuse.ts process_env 1 W6: settings plane out of the core
+src/core/persistence/sync-waivers.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/sync-waivers.ts process_env 2 W6: settings plane out of the core
+src/core/persistence/topology-clone.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/topology-filesystem.ts fs_import 2 W5: repo-less persistence for hosts
+src/core/persistence/topology-filesystem.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/persistence/topology-locks.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/topology-recovery.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/topology-recovery.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/topology-transaction.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/persistence/unbound-pages.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/unindexed-files.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/persistence/upload-streamed.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/worktree-lease.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/worktree-lease.ts module_collection 6 W6: per-engine state, or mark as a constant table
+src/core/persistence/worktree-link.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/worktree-manifest.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/worktree-refresh.ts fs_import 1 W5: repo-less persistence for hosts
+src/core/persistence/worktree-refresh.ts load_config 2 W6: settings plane out of the core
+src/core/persistence/worktree-refresh.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/persistence/worktree-refresh.ts process_env 5 W6: settings plane out of the core
+src/core/persistence/write-wait.ts load_config 2 W6: settings plane out of the core
+src/core/persistence/write-wait.ts process_env 3 W6: settings plane out of the core
+src/core/pg-access-classify.ts process_env 1 W6: settings plane out of the core
+src/core/pg-type-cache.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/pg-type-cache.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/pg-type-cache.ts process_env 1 W6: settings plane out of the core
+src/core/pg-type-cache.ts process_global 1 W7: process-wide effects move to src/cli
+src/core/pglite-embedded-assets.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/pglite-engine.ts fs_import 3 W7: filesystem boundary moves to the local app
+src/core/pglite-engine.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/pglite-engine.ts process_env 4 W6: settings plane out of the core
+src/core/pglite-leftovers-check.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/pglite-legacy-lock.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/pglite-legacy-lock.ts process_env 1 W6: settings plane out of the core
+src/core/pglite-legacy-lock.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/pglite-lifecycle.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/pglite-lock.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/pglite-lock.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/pglite-lock.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/pglite-repair-consent.ts load_config 1 W6: settings plane out of the core
+src/core/pglite-repair.ts fs_import 2 W7: filesystem boundary moves to the local app
+src/core/pglite-repair.ts process_env 2 W6: settings plane out of the core
+src/core/pglite-resetwal.ts fs_import 2 W7: filesystem boundary moves to the local app
+src/core/pid1-reaper.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/pid1-reaper.ts process_env 1 W6: settings plane out of the core
+src/core/planner-stats.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/planner-stats.ts process_env 1 W6: settings plane out of the core
+src/core/pool-budget.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/pooler-notice.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/post-upgrade-notice.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/post-upgrade-notice.ts process_env 2 W6: settings plane out of the core
+src/core/post-upgrade-reembed.ts process_env 1 W6: settings plane out of the core
+src/core/postgres-engine.ts process_env 3 W6: settings plane out of the core
+src/core/postgres-engine/init-schema-lock.ts process_env 1 W6: settings plane out of the core
+src/core/postgres-engine/jit-off-statement.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/postgres-engine/schema-lock-timeout.ts process_env 1 W6: settings plane out of the core
+src/core/preferences.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/preferences.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/preferences.ts process_env 1 W6: settings plane out of the core
+src/core/process-cleanup.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/process-cleanup.ts process_global 4 W7: process-wide effects move to src/cli
+src/core/progress.ts module_collection 3 W6: per-engine state, or mark as a constant table
+src/core/progress.ts process_global 2 W7: process-wide effects move to src/cli
+src/core/progressive-batch/orchestrator.ts process_env 3 W6: settings plane out of the core
+src/core/progressive-batch/orchestrator.ts process_global 1 W7: process-wide effects move to src/cli
+src/core/published-config.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/questions/receipt.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/read-heartbeat.ts process_global 2 W7: process-wide effects move to src/cli
+src/core/readiness.ts module_collection 4 W6: per-engine state, or mark as a constant table
+src/core/readiness.ts process_env 1 W6: settings plane out of the core
+src/core/recall-cursor-state.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/remediation-checkpoint.ts fs_import 2 W7: filesystem boundary moves to the local app
+src/core/remediation/context.ts process_env 1 W6: settings plane out of the core
+src/core/remote-token-cache.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/repair/agent-session-facts.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/repair/captured-facts.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/repair/fences.ts process_env 2 W6: settings plane out of the core
+src/core/repair/file-drift.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/repair/frontmatter.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/repair/frontmatter.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/repair/ghost-pages.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/repair/legacy-twins.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/repair/origin-twins-heal.ts load_config 1 W6: settings plane out of the core
+src/core/repair/origin-twins.ts fs_import 2 W7: filesystem boundary moves to the local app
+src/core/repair/registry.ts load_config 1 W6: settings plane out of the core
+src/core/repair/rename-identity.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/repair/segmented-mirror.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/repair/slug-autoheal.ts load_config 1 W6: settings plane out of the core
+src/core/repair/slug-conflicts.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/repair/slug-conflicts.ts process_env 2 W6: settings plane out of the core
+src/core/repair/slug-conflicts.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/repair/url-clone-fences.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/repair/url-clone-fences.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/repo-root.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/repo-root.ts process_env 2 W6: settings plane out of the core
+src/core/repo-visibility.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/repo-visibility.ts process_env 1 W6: settings plane out of the core
+src/core/repo-visibility.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/request-signal.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/resolver-filenames.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/resolvers/builtin/x-api/handle-to-tweet.ts process_env 1 W6: settings plane out of the core
+src/core/retry.ts process_env 1 W6: settings plane out of the core
+src/core/routing-eval.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/runtime-build.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/runtime-version.ts process_global 2 W7: process-wide effects move to src/cli
+src/core/schema-events.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/schema-pack/bundled-assets.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/schema-pack/candidate-audit.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/schema-pack/candidate-audit.ts process_env 1 W6: settings plane out of the core
+src/core/schema-pack/engine-resolution.ts process_env 1 W6: settings plane out of the core
+src/core/schema-pack/load-active.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/schema-pack/load-active.ts process_env 1 W6: settings plane out of the core
+src/core/schema-pack/loader.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/schema-pack/loader.ts process_env 1 W6: settings plane out of the core
+src/core/schema-pack/mutate-audit.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/schema-pack/mutate.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/schema-pack/pack-lock.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/schema-pack/pack-lock.ts process_env 1 W6: settings plane out of the core
+src/core/schema-pack/redos-guard.ts process_env 1 W6: settings plane out of the core
+src/core/schema-pack/registry.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/schema-pack/registry.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/schema-pack/registry.ts process_env 1 W6: settings plane out of the core
+src/core/schema-pack/review.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/schema-pack/review.ts load_config 1 W6: settings plane out of the core
+src/core/schema-pack/scaffold-extractable.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/search/connection-budget.ts als_store 2 W2: engine scope (decision E) replaces ad hoc async context
+src/core/search/cosine-rescore.ts process_env 1 W6: settings plane out of the core
+src/core/search/decide-stage.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/search/eval.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/search/eval.ts load_config 1 W6: settings plane out of the core
+src/core/search/hnsw-iterative-scan.ts process_env 1 W6: settings plane out of the core
+src/core/search/hybrid.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/search/hybrid.ts process_env 2 W6: settings plane out of the core
+src/core/search/hybrid/cache-stages.ts load_config 1 W6: settings plane out of the core
+src/core/search/hybrid/request.ts load_config 1 W6: settings plane out of the core
+src/core/search/hybrid/request.ts process_env 1 W6: settings plane out of the core
+src/core/search/image-loader.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/search/image-vector-presence.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/search/mode-switch-ux.ts process_env 1 W6: settings plane out of the core
+src/core/search/private-visibility.ts module_collection 3 W6: per-engine state, or mark as a constant table
+src/core/search/private-visibility.ts process_env 1 W6: settings plane out of the core
+src/core/search/projection-readiness.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/search/projection-readiness.ts process_env 1 W6: settings plane out of the core
+src/core/search/projection-statistics.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/search/query-intent.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/search/recency-decay.ts process_env 1 W6: settings plane out of the core
+src/core/search/safe-chunks.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/search/search-cost.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/search/source-boost.ts process_env 2 W6: settings plane out of the core
+src/core/search/token-budget.ts process_env 1 W6: settings plane out of the core
+src/core/search/vector-legacy-guard.ts process_env 1 W6: settings plane out of the core
+src/core/secret-scan-allowlist.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/secret-scan-allowlist.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/secret-scan.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/secret-scan.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/self-upgrade-recovery.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/self-upgrade-recovery.ts load_config 1 W6: settings plane out of the core
+src/core/self-upgrade-swap.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/self-upgrade-swap.ts load_config 4 W6: settings plane out of the core
+src/core/self-upgrade-swap.ts process_env 1 W6: settings plane out of the core
+src/core/self-upgrade-swap.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/self-upgrade.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/self-upgrade.ts process_env 2 W6: settings plane out of the core
+src/core/serve-behavior-notice.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/serve-fail-fast.ts process_env 1 W6: settings plane out of the core
+src/core/serve-http-status-marker.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/serve-log.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/serve-log.ts process_env 1 W6: settings plane out of the core
+src/core/serve-log.ts process_global 1 W7: process-wide effects move to src/cli
+src/core/serve-service.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/serve-service.ts process_env 1 W6: settings plane out of the core
+src/core/serve-sync-runner.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/serve-sync-runner.ts process_env 2 W6: settings plane out of the core
+src/core/setup/brain-first.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/setup/brain-first.ts process_env 10 W6: settings plane out of the core
+src/core/setup/claude-code.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/setup/codex.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/setup/hermes-turn-hook.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/setup/local-receipts.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/setup/openclaw-turn-plugin.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/setup/openclaw-turn-plugin.ts process_env 2 W6: settings plane out of the core
+src/core/setup/openclaw-turn-plugin.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/setup/turn-hook-check.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/setup/turn-hook-check.ts process_env 4 W6: settings plane out of the core
+src/core/setup/turn-hook-check.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/setup/turn-hook.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/setup/turn-hook.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/shared-skills/adapter.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/shared-skills/adopted-packs.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/shared-skills/knowledge-guard.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/shared-skills/migration-export.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/shared-skills/migration-export.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/shared-skills/migration.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/shared-skills/optimizer.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/shared-skills/publication.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/shared-skills/receipt-root.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/shared-skills/setup-files.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/shared-skills/setup.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/shared-skills/setup.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/skill-catalog.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skill-catalog.ts process_env 1 W6: settings plane out of the core
+src/core/skill-fix-gates.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/skill-manifest.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skill-trigger-index.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skill-trigger-index.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/skillify/generator.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillopt/apply-edits.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillopt/apply-edits.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/skillopt/batch.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillopt/benchmark.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillopt/bootstrap-benchmark.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillopt/bundled-skill-gate.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillopt/checkpoint.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillopt/cycle-phase.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillopt/held-out.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillopt/models-plan.ts load_config 1 W6: settings plane out of the core
+src/core/skillopt/models-plan.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/skillopt/models-plan.ts process_env 1 W6: settings plane out of the core
+src/core/skillopt/orchestrator.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillopt/output-cap.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/skillopt/rejected-buffer.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillopt/rollout.ts load_config 1 W6: settings plane out of the core
+src/core/skillopt/version-store.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillopt/write-capture.ts load_config 1 W6: settings plane out of the core
+src/core/skillpack/audit.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/audit.ts process_env 1 W6: settings plane out of the core
+src/core/skillpack/bootstrap-display.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/brain-pack-advisory.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/brain-resident-locate.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/bridge-state.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/bundle.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/bundle.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/skillpack/copy.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/doctor.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/endorse.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/endorse.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/skillpack/harness-bridge.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/harvest-lint.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/harvest.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/init-scaffold.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/installer.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/manifest-v1.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/migrate-fence.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/nag-state.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/pack-publish.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/personas.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/post-install-advisory.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/reference.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/registry-client.ts fs_import 2 W7: filesystem boundary moves to the local app
+src/core/skillpack/registry-client.ts load_config 1 W6: settings plane out of the core
+src/core/skillpack/remote-source.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/remote-source.ts process_env 1 W6: settings plane out of the core
+src/core/skillpack/remote-source.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/skillpack/rubric.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/scrub-legacy.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/shared-brain-bridge.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/state.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/tarball.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skillpack/tarball.ts process_env 1 W6: settings plane out of the core
+src/core/skillpack/tarball.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/skillpack/writer-guard.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/skills-integrity.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/source-health.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/source-health.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/source-resolver.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/source-resolver.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/source-resolver.ts process_env 4 W6: settings plane out of the core
+src/core/sources-load.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/sources-ops.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/spawn.ts spawn_import 2 W7: process-wide effects move to src/cli
+src/core/sql-trace.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/sql-trace.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/sql-trace.ts process_env 2 W6: settings plane out of the core
+src/core/sql-trace.ts process_global 1 W7: process-wide effects move to src/cli
+src/core/stable-channel.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/stall-env.ts process_env 1 W6: settings plane out of the core
+src/core/statement-deadline.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/statement-deadline.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/storage-config.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/storage-config.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/storage.ts fs_import 2 W7: filesystem boundary moves to the local app
+src/core/storage/local.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/storage/s3.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/storage/supabase.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/sweep.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/sweep.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/sweep.ts process_env 3 W6: settings plane out of the core
+src/core/sync-anchor.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/sync-applicability.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/sync-applicability.ts load_config 1 W6: settings plane out of the core
+src/core/sync-byte-paths.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/sync-concurrency.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/sync-concurrency.ts process_env 1 W6: settings plane out of the core
+src/core/sync-config-keys.ts process_env 2 W6: settings plane out of the core
+src/core/sync-cost-gate.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/sync-delta.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/sync-dispatch-read.ts als_store 1 W2: engine scope (decision E) replaces ad hoc async context
+src/core/sync-failure-ledger.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/sync-failure-ledger.ts process_env 5 W6: settings plane out of the core
+src/core/sync-git.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/sync-git.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/sync-metafile-pages.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/sync-metafile-pages.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/sync-pending.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/sync-policy.ts module_collection 2 W6: per-engine state, or mark as a constant table
+src/core/sync-reconcile.ts process_env 2 W6: settings plane out of the core
+src/core/sync-reconcile.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/sync-rename-identity.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/sync-rename-identity.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/sync-status-report.ts load_config 1 W6: settings plane out of the core
+src/core/sync-upstream-rewrite.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/sync-upstream-rewrite.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/sync-upstream.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/sync-upstream.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/sync.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/sync.ts process_env 1 W6: settings plane out of the core
+src/core/tailscale.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/tailscale.ts process_env 2 W6: settings plane out of the core
+src/core/tailscale.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/takes-quality-eval/receipt-write.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/takes-quality-eval/replay.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/takes-write.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/thin-client-upgrade-prompt.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/thin-client-upgrade-prompt.ts process_global 2 W7: process-wide effects move to src/cli
+src/core/thin-client-upgrade-prompt.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/think/persist-take.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/timeline-write-through.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/trajectory.ts process_env 1 W6: settings plane out of the core
+src/core/transcription.ts fs_import 2 W7: filesystem boundary moves to the local app
+src/core/transcription.ts process_env 5 W6: settings plane out of the core
+src/core/transcription.ts spawn_import 2 W7: process-wide effects move to src/cli
+src/core/transcripts.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/transcripts/claude-code-jsonl.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/transcripts/claude-code.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/transcripts/codex-hook-lane.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/transcripts/codex.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/transcripts/detect.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/transcripts/detect.ts process_env 2 W6: settings plane out of the core
+src/core/transcripts/discover.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/transcripts/export-json.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/transcripts/grok.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/transcripts/hermes.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/transcripts/openclaw.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/transcripts/recover.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/trust/marker-repair.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/trust/proposals.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/uncommitted-deletions.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/url-clone.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/utils.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/verbs/usage-log.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/workspace-push.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/workspace-push.ts process_env 2 W6: settings plane out of the core
+src/core/workspace-push.ts spawn_import 1 W7: process-wide effects move to src/cli
+src/core/write-through.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/write-through.ts module_collection 1 W6: per-engine state, or mark as a constant table
+src/core/wsl-paths.ts fs_import 1 W7: filesystem boundary moves to the local app
+src/core/zombie-reap.ts process_global 1 W7: process-wide effects move to src/cli
diff --git a/scripts/guards-manifest.tsv b/scripts/guards-manifest.tsv
index b8baae764d..0122e23316 100644
--- a/scripts/guards-manifest.tsv
+++ b/scripts/guards-manifest.tsv
@@ -67,6 +67,7 @@ check-module-size.sh scanner yes committed per-file line ceilings (module-size-l
check-function-size.ts scanner yes W5 per-function line ratchet (TS compiler API): new >300-line function, growth, shrink-below-limit, stale slack, missing row, raise without issue/TODO id; baseline scripts/function-size-baseline.tsv keyed by path + name path; --transfer for verified move-only commits
check-item-allowlist-catches.ts scanner yes GBRA-130 per-item allowlist-catch ratchet (TS compiler API): a catch in a loop body or forEach/map callback that tests the caught error code against a set/list/literal and rethrows it; per-file counts in scripts/item-allowlist-catches-baseline.tsv only shrink (growth, stale row, zero/missing-file row, malformed rows fail); --update rewrites for shrinks
check-engine-sql-ratchet.ts scanner yes goal (a) engine-sql ratchet (TS AST): SQL-bearing engine members (façade classes + pglite-engine/ and postgres-engine/ modules) need a baseline row or an engine-sql-ok marker; stale/duplicate rows and unbacked migrated domains fail; baseline scripts/engine-sql-baseline.tsv; --prune drops stale rows only
+check-core-world-reads.ts scanner yes GBRA-248 W1 embeddable-core ratchet (TS AST): per-file counts in src/core of loadConfig calls, process.env/Bun.env, fs imports, module-level mutable collections, spawn-wrapper/child_process imports, process-wide hooks and AsyncLocalStorage stores; rises and stale rows fail; baseline scripts/core-world-reads-baseline.tsv; --prune lowers stale rows only
check-page-body-readers.ts scanner yes Wave B segmented storage (spec 1.5 layer 4, TS AST): src units reading .compiled_truth/.timeline, SQL literals naming the body columns or p.* from pages, and whole-body calls (serializePageToMarkdown, putPage, ...) need a baseline row with an action code; stale/duplicate/malformed rows fail; boundedBodyPrefixSql allowed by name; baseline scripts/page-body-readers-baseline.tsv; --prune drops stale rows only
check-engine-sql-dynamic.ts scanner yes CQ3/EO17 dynamic SQL in src/core/engine-sql/** (TS AST; fragment.ts exempt as the renderer): trustedSql args and composed .query/.unsafe/.executeRaw/executeRawJsonb SQL splice only literals, as-const/allowlisted constants, VETTED_BUILDERS calls or Number.isFinite-checked numbers; no $<digit> in composed strings; no expanded IN lists
check-engine-sql-brands.ts scanner yes EO4/AR2 RLS read brands (TS AST + text): brand-key mentions outside engine-sql/brands.ts; casts onto ScopedRead/LegacyUnscopedRead or `as unknown as` executor types in src/; unscopedExecutor/LegacyUnscopedRead/scopedRead imports outside their allowlists, src/core/ops/** always denied
diff --git a/scripts/run-verify-parallel.sh b/scripts/run-verify-parallel.sh
index 9b10122ad5..a104bfd16d 100755
--- a/scripts/run-verify-parallel.sh
+++ b/scripts/run-verify-parallel.sh
@@ -187,6 +187,9 @@ CHECKS=(
# Goal (a) (refactor wave 1): engine SQL only shrinks; baseline
# scripts/engine-sql-baseline.tsv.
"check:engine-sql-ratchet"
+ # GBRA-248 W1: world reads in src/core (loadConfig, env, fs, module state,
+ # spawn, process hooks) only fall; baseline scripts/core-world-reads-baseline.tsv.
+ "check:core-world-reads"
# GBRA-161: derived-retire writers only shrink; reviewed ceilings in
# docs/architecture/derived-census.tsv.
"check:derived-census"
diff --git a/scripts/serial-files.tsv b/scripts/serial-files.tsv
index 2a818722ac..3d1542a82f 100644
--- a/scripts/serial-files.tsv
+++ b/scripts/serial-files.tsv
@@ -449,3 +449,4 @@ test/embed-once-per-content-version.serial.test.ts global-state global-state: pr
test/page-embedding-lease.serial.test.ts global-state global-state: process-wide test seams __setEmbedTransportForTests (each case swaps the embed transport, one to a refusing provider) and pageEmbeddingLeaseProbe (the module-wide lease contention hook); withEnv scopes GBRAIN_HOME
test/migrate-search-path-best-effort.serial.test.ts R2 R2: mock.module(v277 migration module) replaces modules for every file in the process
test/agent-session-speaker-8064.serial.test.ts R1 R1: sets GBRAIN_HOME and GBRAIN_SESSION_AGENT and clears DATABASE_URL and the hook env on process.env
+test/two-engine-isolation.serial.test.ts R1 R1: mutates process.env (GBRAIN_HOME); also drives the process-wide AI gateway, chat usage sink, search telemetry, link semantics and module caches the suite proves are shared, and binds fake AI provider ports
diff --git a/scripts/structural-suites.tsv b/scripts/structural-suites.tsv
index f1fb35cead..4cf07b8a70 100644
--- a/scripts/structural-suites.tsv
+++ b/scripts/structural-suites.tsv
@@ -295,6 +295,7 @@ test/schema-pack-unify-types-handler.test.ts #1575 unify-types worker dry-run de
test/schema-pack/suggest.test.ts runSuggest — source-text contract (structural) 1 readFileSync
test/scripts/build-schema-migrations.test.ts generator diagnostics (FAIL/Why/Fix/See) 9 exec-scan
test/scripts/build-schema-migrations.test.ts out-of-order landing check 2 exec-scan
+test/scripts/check-core-world-reads.test.ts check-core-world-reads.ts: the ratchet 5 readFileSync
test/scripts/check-function-size.test.ts check-function-size.ts rules 11 readFileSync
test/scripts/check-item-allowlist-catches.test.ts CLI 2 readFileSync
test/scripts/chunk-visibility-ratchet.test.ts check-chunk-visibility.ts 6 readFileSync
diff --git a/test/e2e/two-engine-isolation.test.ts b/test/e2e/two-engine-isolation.test.ts
new file mode 100644
index 0000000000..d301db6123
--- /dev/null
+++ b/test/e2e/two-engine-isolation.test.ts
@@ -0,0 +1,44 @@
+/**
+ * GBRA-248 W1: the Postgres half of the two-engine isolation suite
+ * (test/helpers/two-engine.ts; the PGLite half is
+ * test/two-engine-isolation.serial.test.ts). Two databases on the test server,
+ * one engine each, in one process.
+ */
+import { afterAll, beforeAll, describe } from 'bun:test';
+import { mkdtempSync, rmSync } from 'node:fs';
+import { randomUUID } from 'node:crypto';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import postgres from '#postgres';
+import { assertSafeE2eDatabaseUrl } from '../helpers/db-guard.ts';
+import { twoEngineIsolationSuite } from '../helpers/two-engine.ts';
+
+const DATABASE_URL = process.env.DATABASE_URL;
+
+describe.skipIf(!DATABASE_URL)('two-engine isolation on Postgres', () => {
+ const names = ['a', 'b'].map((n) => 'gbrain_test_two_engine_' + n + '_' + randomUUID().replaceAll('-', '').slice(0, 12));
+ const urls = names.map((name) => {
+ const url = new URL(DATABASE_URL ?? 'postgresql://localhost/unset');
+ url.pathname = '/' + name;
+ return url.toString();
+ }) as [string, string];
+ const processHome = mkdtempSync(join(tmpdir(), 'gbrain-two-engine-process-home-'));
+ const savedHome = process.env.GBRAIN_HOME;
+ let admin: ReturnType<typeof postgres>;
+
+ beforeAll(async () => {
+ assertSafeE2eDatabaseUrl(DATABASE_URL!);
+ process.env.GBRAIN_HOME = processHome;
+ admin = postgres(DATABASE_URL!, { max: 1 });
+ for (const name of names) await admin.unsafe('CREATE DATABASE ' + name);
+ }, 60_000);
+
+ afterAll(async () => {
+ for (const name of names) await admin.unsafe('DROP DATABASE IF EXISTS ' + name + ' WITH (FORCE)');
+ await admin.end();
+ if (savedHome === undefined) delete process.env.GBRAIN_HOME; else process.env.GBRAIN_HOME = savedHome;
+ rmSync(processHome, { recursive: true, force: true });
+ }, 60_000);
+
+ twoEngineIsolationSuite('postgres', urls);
+});
diff --git a/test/e2e/upgrade-from-previous-release.test.ts b/test/e2e/upgrade-from-previous-release.test.ts
new file mode 100644
index 0000000000..e2499a0027
--- /dev/null
+++ b/test/e2e/upgrade-from-previous-release.test.ts
@@ -0,0 +1,52 @@
+/**
+ * GBRA-248 W1, gate condition 1: the Postgres half of the upgrade-from-
+ * previous-release harness (test/helpers/upgrade-from-previous-release.ts).
+ * One fresh database per brain shape, loaded from the newest Postgres
+ * schema-history fixture.
+ */
+import { afterAll, describe } from 'bun:test';
+import postgres from '#postgres';
+import { randomUUID } from 'node:crypto';
+import { assertSafeE2eDatabaseUrl } from '../helpers/db-guard.ts';
+import { upgradeFromPreviousReleaseSuite } from '../helpers/upgrade-from-previous-release.ts';
+
+const DATABASE_URL = process.env.DATABASE_URL;
+
+describe.skipIf(!DATABASE_URL)('upgrade from the previous release on Postgres', () => {
+ const created: string[] = [];
+ const admin = () => postgres(DATABASE_URL!, { max: 1, prepare: false, onnotice: () => {} });
+
+ afterAll(async () => {
+ const sql = admin();
+ try {
+ for (const name of created) await sql.unsafe('DROP DATABASE IF EXISTS ' + name + ' WITH (FORCE)');
+ } finally {
+ await sql.end({ timeout: 5 });
+ }
+ }, 60_000);
+
+ upgradeFromPreviousReleaseSuite('postgres', {
+ async databaseUrl() {
+ assertSafeE2eDatabaseUrl(DATABASE_URL!);
+ const name = 'gbrain_test_upgrade_' + randomUUID().replaceAll('-', '').slice(0, 16);
+ const sql = admin();
+ try {
+ await sql.unsafe('CREATE DATABASE ' + name);
+ } finally {
+ await sql.end({ timeout: 5 });
+ }
+ created.push(name);
+ const url = new URL(DATABASE_URL!);
+ url.pathname = '/' + name;
+ return url.toString();
+ },
+ async loadSql(url, text) {
+ const loader = postgres(url, { max: 1, prepare: false, onnotice: () => {} });
+ try {
+ await loader.unsafe(text);
+ } finally {
+ await loader.end({ timeout: 5 });
+ }
+ },
+ });
+});
diff --git a/test/embedded-hermeticity.test.ts b/test/embedded-hermeticity.test.ts
new file mode 100644
index 0000000000..c9981b0c0e
--- /dev/null
+++ b/test/embedded-hermeticity.test.ts
@@ -0,0 +1,87 @@
+/**
+ * GBRA-248 W1: the embedded core's hermeticity test, and the run that keeps
+ * examples/embedded-two-brains.ts (the docs quickstart) working.
+ *
+ * A cold child process runs the example with canary HOME, GBRAIN_HOME and
+ * TMPDIR directories (each holding a conflicting config.json) and canary
+ * provider keys in its environment. The quickstart must work. The hermetic
+ * case also requires that nothing under the canary directories changes and
+ * that no code under src/ reads an environment variable; today the core reads
+ * GBRAIN_* tuning variables during connect, migrate, search and close, so it
+ * is expected to fail until W7 (plans/GBRA-248-embeddable-core.md), which
+ * turns it into the required Linux lane that also denies filesystem and
+ * child-process access outside the injected paths.
+ */
+import { afterAll, beforeAll, expect, test } from 'bun:test';
+import { mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join, resolve } from 'node:path';
+
+const REPO = resolve(import.meta.dir, '..');
+const root = mkdtempSync(join(tmpdir(), 'gbrain-hermetic-'));
+const canaries = { HOME: join(root, 'home'), GBRAIN_HOME: join(root, 'gbrain-home'), TMPDIR: join(root, 'tmp') };
+const brains = { a: join(root, 'brain-a'), b: join(root, 'brain-b') };
+const canaryConfig = JSON.stringify({ engine: 'postgres', database_url: 'postgresql://[email protected]:1/canary', embedding_model: 'openai:text-embedding-3-large', embedding_dimensions: 768 });
+
+function snapshot(dir: string): Record<string, number> {
+ const out: Record<string, number> = {};
+ const walk = (d: string) => {
+ for (const entry of readdirSync(d)) {
+ const p = join(d, entry);
+ const st = statSync(p);
+ if (st.isDirectory()) walk(p); else out[p] = st.mtimeMs;
+ }
+ };
+ walk(dir);
+ return out;
+}
+
+let run: { code: number | null; stdout: string; stderr: string; envReads: string[]; before: Record<string, number>; after: Record<string, number> };
+
+beforeAll(async () => {
+ for (const dir of [...Object.values(canaries), ...Object.values(brains)]) mkdirSync(dir, { recursive: true });
+ mkdirSync(join(canaries.HOME, '.gbrain'));
+ writeFileSync(join(canaries.HOME, '.gbrain', 'config.json'), canaryConfig);
+ writeFileSync(join(canaries.GBRAIN_HOME, 'config.json'), canaryConfig);
+ const before = Object.assign({}, ...Object.values(canaries).map(snapshot));
+ const log = join(root, 'env-reads.json');
+ const proc = Bun.spawn(['bun', '--preload', join(REPO, 'test/helpers/hermetic-preload.ts'), join(REPO, 'examples/embedded-two-brains.ts'), brains.a, brains.b], {
+ cwd: root,
+ env: {
+ PATH: process.env.PATH ?? '',
+ ...canaries,
+ BUN_RUNTIME_TRANSPILER_CACHE_PATH: '0',
+ HERMETIC_LOG: log,
+ OPENAI_API_KEY: 'sk-canary-openai',
+ ANTHROPIC_API_KEY: 'sk-ant-canary',
+ DATABASE_URL: 'postgresql://[email protected]:1/canary',
+ GBRAIN_DATABASE_URL: 'postgresql://[email protected]:1/canary',
+ },
+ stdout: 'pipe',
+ stderr: 'pipe',
+ });
+ const [stdout, stderr, code] = await Promise.all([new Response(proc.stdout).text(), new Response(proc.stderr).text(), proc.exited]);
+ const after = Object.assign({}, ...Object.values(canaries).map(snapshot));
+ let envReads: string[] = [];
+ try { envReads = JSON.parse(readFileSync(log, 'utf8')); } catch { envReads = ['<no log: the child did not exit cleanly>']; }
+ run = { code, stdout, stderr, envReads, before, after };
+}, 120_000);
+
+afterAll(() => {
+ rmSync(root, { recursive: true, force: true });
+});
+
+test('the quickstart opens two brains in one process and each sees only its own page', () => {
+ expect(run.code, run.stderr).toBe(0);
+ const report = JSON.parse(run.stdout.trim().split('\n').pop()!);
+ expect(report).toEqual({
+ a: { slug: 'notes/quickstart-a', found: ['notes/quickstart-a'], reopened: 'Quickstart a' },
+ b: { slug: 'notes/quickstart-b', found: ['notes/quickstart-b'], reopened: 'Quickstart b' },
+ });
+});
+
+test.failing('hermetic: write, search, close and reopen touch no canary directory and read no environment (expected to fail until W7)', () => {
+ expect(run.code, run.stderr).toBe(0);
+ expect(run.after).toEqual(run.before);
+ expect(run.envReads).toEqual([]);
+});
diff --git a/test/fixtures/guards/check-core-world-reads.ts/bad-new/scripts/core-world-reads-baseline.tsv b/test/fixtures/guards/check-core-world-reads.ts/bad-new/scripts/core-world-reads-baseline.tsv
new file mode 100644
index 0000000000..5bd144ec2b
--- /dev/null
+++ b/test/fixtures/guards/check-core-world-reads.ts/bad-new/scripts/core-world-reads-baseline.tsv
@@ -0,0 +1 @@
+# fixture baseline
diff --git a/test/fixtures/guards/check-core-world-reads.ts/bad-new/src/core/a.ts b/test/fixtures/guards/check-core-world-reads.ts/bad-new/src/core/a.ts
new file mode 100644
index 0000000000..f27b601cd2
--- /dev/null
+++ b/test/fixtures/guards/check-core-world-reads.ts/bad-new/src/core/a.ts
@@ -0,0 +1,2 @@
+import { readFileSync } from 'node:fs';
+export const r = readFileSync;
diff --git a/test/fixtures/guards/check-core-world-reads.ts/bad-stale/scripts/core-world-reads-baseline.tsv b/test/fixtures/guards/check-core-world-reads.ts/bad-stale/scripts/core-world-reads-baseline.tsv
new file mode 100644
index 0000000000..2cdc2b269b
--- /dev/null
+++ b/test/fixtures/guards/check-core-world-reads.ts/bad-stale/scripts/core-world-reads-baseline.tsv
@@ -0,0 +1,2 @@
+# fixture baseline
+src/core/a.ts process_env 2 W6: fixture
diff --git a/test/fixtures/guards/check-core-world-reads.ts/bad-stale/src/core/a.ts b/test/fixtures/guards/check-core-world-reads.ts/bad-stale/src/core/a.ts
new file mode 100644
index 0000000000..1fddf0188a
--- /dev/null
+++ b/test/fixtures/guards/check-core-world-reads.ts/bad-stale/src/core/a.ts
@@ -0,0 +1 @@
+export const k = process.env.K;
diff --git a/test/fixtures/guards/check-core-world-reads.ts/bad/scripts/core-world-reads-baseline.tsv b/test/fixtures/guards/check-core-world-reads.ts/bad/scripts/core-world-reads-baseline.tsv
new file mode 100644
index 0000000000..7185632ab0
--- /dev/null
+++ b/test/fixtures/guards/check-core-world-reads.ts/bad/scripts/core-world-reads-baseline.tsv
@@ -0,0 +1,2 @@
+# fixture baseline
+src/core/a.ts process_env 1 W6: fixture
diff --git a/test/fixtures/guards/check-core-world-reads.ts/bad/src/core/a.ts b/test/fixtures/guards/check-core-world-reads.ts/bad/src/core/a.ts
new file mode 100644
index 0000000000..ec7f3001f1
--- /dev/null
+++ b/test/fixtures/guards/check-core-world-reads.ts/bad/src/core/a.ts
@@ -0,0 +1,2 @@
+export const k = process.env.K;
+export const j = process.env.J;
diff --git a/test/fixtures/guards/check-core-world-reads.ts/good/scripts/core-world-reads-baseline.tsv b/test/fixtures/guards/check-core-world-reads.ts/good/scripts/core-world-reads-baseline.tsv
new file mode 100644
index 0000000000..7185632ab0
--- /dev/null
+++ b/test/fixtures/guards/check-core-world-reads.ts/good/scripts/core-world-reads-baseline.tsv
@@ -0,0 +1,2 @@
+# fixture baseline
+src/core/a.ts process_env 1 W6: fixture
diff --git a/test/fixtures/guards/check-core-world-reads.ts/good/src/core/a.ts b/test/fixtures/guards/check-core-world-reads.ts/good/src/core/a.ts
new file mode 100644
index 0000000000..1fddf0188a
--- /dev/null
+++ b/test/fixtures/guards/check-core-world-reads.ts/good/src/core/a.ts
@@ -0,0 +1 @@
+export const k = process.env.K;
diff --git a/test/helpers/hermetic-preload.ts b/test/helpers/hermetic-preload.ts
new file mode 100644
index 0000000000..174ac2aaee
--- /dev/null
+++ b/test/helpers/hermetic-preload.ts
@@ -0,0 +1,24 @@
+/**
+ * Preload for test/embedded-hermeticity.test.ts: records every environment
+ * variable that repository source (src/) reads while the child runs, and
+ * writes the list to HERMETIC_LOG on exit. Bun lets process.env be replaced,
+ * so a Proxy sees reads through process.env; a stack frame under src/ marks
+ * the read as gbrain's rather than the runtime's.
+ */
+import { writeFileSync } from 'node:fs';
+import { sep } from 'node:path';
+
+const marker = sep + 'src' + sep;
+const reads = new Set<string>();
+const env = process.env;
+const record = (key: string | symbol) => {
+ if (typeof key !== 'string') return;
+ const stack = new Error().stack ?? '';
+ if (stack.split('\n').slice(2).some((frame) => frame.includes(marker))) reads.add(key);
+};
+process.env = new Proxy(env, {
+ get(target, key) { record(key); return Reflect.get(target, key); },
+ has(target, key) { record(key); return Reflect.has(target, key); },
+});
+const log = env.HERMETIC_LOG;
+process.on('exit', () => { if (log) writeFileSync(log, JSON.stringify([...reads].sort())); });
diff --git a/test/helpers/two-engine.ts b/test/helpers/two-engine.ts
new file mode 100644
index 0000000000..d9243e6828
--- /dev/null
+++ b/test/helpers/two-engine.ts
@@ -0,0 +1,366 @@
+/**
+ * GBRA-248 W1: the two-engine isolation suite. Two brains in one process on
+ * two databases (PGLite x2 in test/two-engine-isolation.serial.test.ts,
+ * Postgres x2 in test/e2e/two-engine-isolation.test.ts), each with its own
+ * settings: a home directory, an AI key, an embedding model and a fake
+ * OpenAI-compatible provider that records the key and model each request
+ * arrived with.
+ *
+ * One case per dimension the embeddable core must keep per engine (plan
+ * plans/GBRA-248-embeddable-core.md, wave W1). Every case runs for both
+ * creation orders. A case listed in EXPECTED_FAILURES runs as test.failing,
+ * so it must still fail today and an unexpected pass fails the suite: the
+ * wave that fixes a dimension deletes its row in the same PR. The program is
+ * done when EXPECTED_FAILURES is empty.
+ *
+ * openTestBrain is the seam later waves swap: today it opens a brain with the
+ * public API an embedder has (createEngine, connect, initSchema, and the
+ * process-wide configureGateway), and within() runs code with nothing
+ * scoped. W2 replaces both with openEngine(settings) and the engine scope.
+ */
+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
+import { mkdtempSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join, sep } from 'node:path';
+import type { BrainEngine } from '../../src/core/engine.ts';
+import { createEngine } from '../../src/core/engine-factory.ts';
+import { configureGateway, embedQuery, resetGateway } from '../../src/core/ai/gateway.ts';
+import { clearQueryEmbedCache } from '../../src/core/ai/query-embed-cache.ts';
+import { recordChatUsage } from '../../src/core/ai/chat-usage.ts';
+import { recordSearchTelemetry, awaitPendingTelemetryFlush, _resetTelemetryWriterForTest } from '../../src/core/search/telemetry.ts';
+import { relationSemantics, setPackRelationSemantics } from '../../src/core/link-validity.ts';
+import { resolveAdmissionPolicy, _resetAdmissionCacheForTest } from '../../src/core/minions/admission.ts';
+import { bumpLastRetrievedAt, awaitPendingLastRetrievedWrites, _resetTrackRetrievalCacheForTests } from '../../src/core/last-retrieved.ts';
+import { sourceGuardBlocksWrite } from '../../src/core/source-resolver.ts';
+import { acquirePageLock } from '../../src/core/page-lock.ts';
+import { gbrainPath } from '../../src/core/config.ts';
+import { MinionQueue } from '../../src/core/minions/queue.ts';
+import type { HybridSearchMeta } from '../../src/core/types.ts';
+
+export type EngineKind = 'pglite' | 'postgres';
+type Name = 'a' | 'b';
+
+export interface TestBrainSettings {
+ name: Name;
+ home: string;
+ databaseUrl?: string;
+ ai: { key: string; embeddingModel: string; baseUrl: string };
+}
+
+export interface TestBrain {
+ name: Name;
+ engine: BrainEngine;
+ settings: TestBrainSettings;
+ within<T>(fn: () => Promise<T> | T): Promise<T>;
+}
+
+export async function openTestBrain(kind: EngineKind, settings: TestBrainSettings): Promise<TestBrain> {
+ const engine = await createEngine({ engine: kind });
+ await engine.connect(kind === 'pglite' ? { engine: 'pglite' } : { engine: 'postgres', database_url: settings.databaseUrl });
+ await engine.initSchema();
+ configureGateway({
+ embedding_model: settings.ai.embeddingModel,
+ embedding_dimensions: DIMS,
+ env: { OPENAI_API_KEY: settings.ai.key, OPENAI_BASE_URL: settings.ai.baseUrl },
+ });
+ return { name: settings.name, engine, settings, within: async (fn) => fn() };
+}
+
+const DIMS = 1536;
+const MODELS: Record<Name, string> = { a: 'text-embedding-3-small', b: 'text-embedding-3-large' };
+const FILL: Record<Name, number> = { a: 0.25, b: 0.5 };
+
+interface ProviderCall { brain: Name; key: string; model: string; inputs: string[] }
+
+/** One fake OpenAI-compatible embeddings endpoint per brain; each records what reached it. */
+function fakeProvider(brain: Name, calls: ProviderCall[]) {
+ const server = Bun.serve({
+ port: 0,
+ async fetch(req) {
+ if (!new URL(req.url).pathname.endsWith('/embeddings')) return new Response('not found', { status: 404 });
+ const body = await req.json() as { model: string; input: string | string[] };
+ const inputs = Array.isArray(body.input) ? body.input : [body.input];
+ calls.push({ brain, key: (req.headers.get('authorization') ?? '').replace(/^Bearer /, ''), model: body.model, inputs });
+ return Response.json({
+ object: 'list',
+ model: body.model,
+ data: inputs.map((_, index) => ({ object: 'embedding', index, embedding: new Array(DIMS).fill(FILL[brain]) })),
+ usage: { prompt_tokens: inputs.length, total_tokens: inputs.length },
+ });
+ },
+ });
+ return { server, url: 'http://127.0.0.1:' + server.port + '/v1' };
+}
+
+export interface Pair { first: TestBrain; second: TestBrain; calls: ProviderCall[] }
+
+export interface IsolationCase {
+ id: string;
+ run(pair: Pair, kind: EngineKind): Promise<void>;
+}
+
+async function eventually(check: () => Promise<boolean>, ms = 3000): Promise<void> {
+ const end = Date.now() + ms;
+ while (Date.now() < end) {
+ if (await check()) return;
+ await new Promise((r) => setTimeout(r, 25));
+ }
+}
+
+const both = (pair: Pair): TestBrain[] => [pair.first, pair.second];
+const count = async (b: TestBrain, sql: string, params: unknown[] = []) =>
+ Number((await b.engine.executeRaw<{ n: string | number }>(sql, params))[0]?.n ?? 0);
+
+export const CASES: IsolationCase[] = [
+ {
+ id: 'pool: each engine reads and writes its own database',
+ async run(pair) {
+ for (const b of both(pair)) {
+ await b.within(() => b.engine.putPage('isolation/pool-' + b.name, { type: 'concept', title: 'pool ' + b.name, compiled_truth: 'pool probe' }));
+ }
+ for (const b of both(pair)) {
+ const other = b === pair.first ? pair.second : pair.first;
+ expect(await b.within(() => b.engine.getPage('isolation/pool-' + b.name))).not.toBeNull();
+ expect(await b.within(() => b.engine.getPage('isolation/pool-' + other.name))).toBeNull();
+ }
+ },
+ },
+ {
+ id: 'provider key: an embedding call carries its own brain\'s key',
+ async run(pair) {
+ clearQueryEmbedCache();
+ for (const b of both(pair)) await b.within(() => embedQuery('key probe ' + b.name));
+ for (const b of both(pair)) {
+ expect(pair.calls.find((c) => c.inputs.includes('key probe ' + b.name))?.key).toBe(b.settings.ai.key);
+ }
+ },
+ },
+ {
+ id: 'model client cache: an embedding call uses its own brain\'s model and endpoint',
+ async run(pair) {
+ clearQueryEmbedCache();
+ for (const b of both(pair)) await b.within(() => embedQuery('model probe ' + b.name));
+ for (const b of both(pair)) {
+ const call = pair.calls.find((c) => c.inputs.includes('model probe ' + b.name));
+ expect({ brain: call?.brain, model: call?.model }).toEqual({ brain: b.name, model: MODELS[b.name] });
+ }
+ },
+ },
+ {
+ id: 'query-embedding cache: one brain\'s cached vector never answers the other',
+ async run(pair) {
+ clearQueryEmbedCache();
+ const text = 'shared query text';
+ const vectors: Record<string, number> = {};
+ for (const b of both(pair)) vectors[b.name] = (await b.within(() => embedQuery(text)))[0]!;
+ for (const b of both(pair)) {
+ const reached = pair.calls.filter((c) => c.brain === b.name && c.inputs.includes(text)).length;
+ expect({ brain: b.name, vector: vectors[b.name], reachedOwnProvider: reached }).toEqual({ brain: b.name, vector: FILL[b.name], reachedOwnProvider: 1 });
+ }
+ },
+ },
+ {
+ id: 'usage: chat usage lands in the calling brain\'s ledger',
+ async run(pair) {
+ for (const b of both(pair)) {
+ await b.within(() => recordChatUsage({ model: 'openai:gpt-probe-' + b.name, usage: { input_tokens: 1, output_tokens: 1 } }));
+ }
+ const own = (b: TestBrain) => count(b, 'SELECT count(*) AS n FROM chat_usage_log WHERE model = $1', ['openai:gpt-probe-' + b.name]);
+ const anywhere = async () => {
+ let n = 0;
+ for (const b of both(pair)) n += await count(b, "SELECT count(*) AS n FROM chat_usage_log WHERE model LIKE 'openai:gpt-probe-%'");
+ return n;
+ };
+ await eventually(async () => (await anywhere()) >= 2);
+ for (const b of both(pair)) {
+ const other = b === pair.first ? pair.second : pair.first;
+ const foreign = await count(b, 'SELECT count(*) AS n FROM chat_usage_log WHERE model = $1', ['openai:gpt-probe-' + other.name]);
+ expect({ brain: b.name, own: await own(b), foreign }).toEqual({ brain: b.name, own: 1, foreign: 0 });
+ }
+ },
+ },
+ {
+ id: 'telemetry: search telemetry flushes into the searching brain',
+ async run(pair) {
+ _resetTelemetryWriterForTest();
+ try {
+ for (const b of both(pair)) {
+ await b.within(() => recordSearchTelemetry(b.engine, { mode: 'isolation-' + b.name } as unknown as HybridSearchMeta, { results_count: 1 }));
+ }
+ await awaitPendingTelemetryFlush(5000, 'exit');
+ for (const b of both(pair)) {
+ const other = b === pair.first ? pair.second : pair.first;
+ const own = await count(b, 'SELECT count(*) AS n FROM search_telemetry WHERE mode = $1', ['isolation-' + b.name]);
+ const foreign = await count(b, 'SELECT count(*) AS n FROM search_telemetry WHERE mode = $1', ['isolation-' + other.name]);
+ expect({ brain: b.name, own, foreign }).toEqual({ brain: b.name, own: 1, foreign: 0 });
+ }
+ } finally {
+ _resetTelemetryWriterForTest();
+ }
+ },
+ },
+ {
+ id: 'link semantics: a brain\'s schema-pack relation semantics stay its own',
+ async run(pair) {
+ const declared: Record<Name, 'state' | 'event'> = { a: 'state', b: 'event' };
+ for (const b of both(pair)) await b.within(() => setPackRelationSemantics(new Map([['isolation_probe', declared[b.name]]])));
+ try {
+ for (const b of both(pair)) expect(await b.within(() => relationSemantics('isolation_probe'))).toBe(declared[b.name]);
+ } finally {
+ setPackRelationSemantics(new Map());
+ }
+ },
+ },
+ {
+ id: 'admission policy: a job name resolves each brain\'s own quota',
+ async run(pair) {
+ _resetAdmissionCacheForTest();
+ const quota: Record<Name, string> = { a: '5', b: '9' };
+ for (const b of both(pair)) await b.engine.setConfig('minions.quota_max_waiting.isolation-probe', quota[b.name]);
+ for (const b of both(pair)) {
+ const policy = await b.within(() => resolveAdmissionPolicy(b.engine, 'isolation-probe'));
+ expect({ brain: b.name, quota: policy.quotaMaxWaiting }).toEqual({ brain: b.name, quota: Number(quota[b.name]) });
+ }
+ _resetAdmissionCacheForTest();
+ },
+ },
+ {
+ id: 'retrieval tracking: each brain honors its own search.track_retrieval',
+ async run(pair) {
+ _resetTrackRetrievalCacheForTests();
+ const tracking: Record<Name, string> = { a: 'off', b: 'on' };
+ const ids: Record<string, number> = {};
+ for (const b of both(pair)) {
+ await b.engine.setConfig('search.track_retrieval', tracking[b.name]);
+ const page = await b.engine.putPage('isolation/retrieval-' + b.name, { type: 'concept', title: 'retrieval', compiled_truth: 'retrieval probe' });
+ ids[b.name] = page.id;
+ await b.engine.executeRaw('DELETE FROM page_retrievals WHERE page_id = $1', [page.id]);
+ }
+ for (const b of both(pair)) {
+ await b.within(() => bumpLastRetrievedAt(b.engine, [ids[b.name]!]));
+ await awaitPendingLastRetrievedWrites(5000);
+ }
+ for (const b of both(pair)) {
+ const rows = await count(b, 'SELECT count(*) AS n FROM page_retrievals WHERE page_id = $1', [ids[b.name]]);
+ expect({ brain: b.name, tracked: rows }).toEqual({ brain: b.name, tracked: tracking[b.name] === 'on' ? 1 : 0 });
+ }
+ _resetTrackRetrievalCacheForTests();
+ },
+ },
+ {
+ id: 'source resolver: one brain\'s schema shape never decides another brain\'s source guard',
+ async run(pair) {
+ const legacy = pair.first;
+ const current = pair.second;
+ await current.engine.executeRaw("INSERT INTO sources (id, name, archived) VALUES ('isolation-archived', 'isolation-archived', true) ON CONFLICT (id) DO UPDATE SET archived = true");
+ await legacy.engine.executeRaw('ALTER TABLE sources RENAME COLUMN archived TO archived_isolation_probe');
+ try {
+ await legacy.within(() => sourceGuardBlocksWrite(legacy.engine, 'seed_default'));
+ } finally {
+ await legacy.engine.executeRaw('ALTER TABLE sources RENAME COLUMN archived_isolation_probe TO archived');
+ }
+ expect(await current.within(() => sourceGuardBlocksWrite(current.engine, 'seed_default'))).toBe(false);
+ },
+ },
+ {
+ id: 'lock names: the same slug in two brains takes two locks',
+ async run(pair) {
+ const held = [];
+ try {
+ for (const b of both(pair)) held.push(await b.within(() => acquirePageLock('people/alice-example')));
+ expect(held.map((h) => h !== null)).toEqual([true, true]);
+ } finally {
+ for (const h of held) h?.release();
+ }
+ },
+ },
+ {
+ id: 'files: a brain\'s local files resolve under its own home',
+ async run(pair) {
+ for (const b of both(pair)) {
+ const path = await b.within(() => gbrainPath('isolation-probe'));
+ expect(path.startsWith(b.settings.home + sep)).toBe(true);
+ }
+ },
+ },
+ {
+ id: 'jobs: a job submitted to one brain is invisible to the other',
+ async run(pair) {
+ const submitted: Record<string, number> = {};
+ for (const b of both(pair)) {
+ const job = await b.within(() => new MinionQueue(b.engine).add('isolation-probe-' + b.name, {}));
+ submitted[b.name] = job.id;
+ }
+ for (const b of both(pair)) {
+ const other = b === pair.first ? pair.second : pair.first;
+ const seen = await count(b, 'SELECT count(*) AS n FROM minion_jobs WHERE name = $1', ['isolation-probe-' + other.name]);
+ expect({ brain: b.name, sawOther: seen }).toEqual({ brain: b.name, sawOther: 0 });
+ }
+ },
+ },
+];
+
+/**
+ * Cases that still fail, each naming the wave that removes it. A wave that
+ * makes a case pass deletes its row in the same PR (test.failing turns an
+ * unexpected pass into a failure).
+ */
+export const EXPECTED_FAILURES: Record<string, { wave: string; kinds: EngineKind[] }> = {
+ 'pool: each engine reads and writes its own database': { wave: 'W2', kinds: ['postgres'] },
+ 'jobs: a job submitted to one brain is invisible to the other': { wave: 'W2', kinds: ['postgres'] },
+ 'provider key: an embedding call carries its own brain\'s key': { wave: 'W2', kinds: ['pglite', 'postgres'] },
+ 'model client cache: an embedding call uses its own brain\'s model and endpoint': { wave: 'W2', kinds: ['pglite', 'postgres'] },
+ 'query-embedding cache: one brain\'s cached vector never answers the other': { wave: 'W2', kinds: ['pglite', 'postgres'] },
+ 'usage: chat usage lands in the calling brain\'s ledger': { wave: 'W2', kinds: ['pglite', 'postgres'] },
+ 'telemetry: search telemetry flushes into the searching brain': { wave: 'W2', kinds: ['pglite', 'postgres'] },
+ 'link semantics: a brain\'s schema-pack relation semantics stay its own': { wave: 'W2', kinds: ['pglite', 'postgres'] },
+ 'admission policy: a job name resolves each brain\'s own quota': { wave: 'W6', kinds: ['pglite', 'postgres'] },
+ 'retrieval tracking: each brain honors its own search.track_retrieval': { wave: 'W6', kinds: ['pglite', 'postgres'] },
+ 'source resolver: one brain\'s schema shape never decides another brain\'s source guard': { wave: 'W6', kinds: ['pglite', 'postgres'] },
+ 'lock names: the same slug in two brains takes two locks': { wave: 'W5', kinds: ['pglite', 'postgres'] },
+ 'files: a brain\'s local files resolve under its own home': { wave: 'W6', kinds: ['pglite', 'postgres'] },
+};
+
+export function twoEngineIsolationSuite(kind: EngineKind, databaseUrls?: [string, string]): void {
+ for (const order of [['a', 'b'], ['b', 'a']] as [Name, Name][]) {
+ describe('two engines, ' + kind + ', created ' + order.join(' then '), () => {
+ const calls: ProviderCall[] = [];
+ const providers = (['a', 'b'] as Name[]).map((n) => fakeProvider(n, calls));
+ const homes: string[] = [];
+ let pair: Pair;
+
+ beforeAll(async () => {
+ const brains: TestBrain[] = [];
+ for (const name of order) {
+ const home = mkdtempSync(join(tmpdir(), 'gbrain-two-engine-' + name + '-'));
+ homes.push(home);
+ brains.push(await openTestBrain(kind, {
+ name,
+ home,
+ databaseUrl: databaseUrls?.[name === 'a' ? 0 : 1],
+ ai: { key: 'key-' + name, embeddingModel: 'openai:' + MODELS[name], baseUrl: providers[name === 'a' ? 0 : 1]!.url },
+ }));
+ }
+ pair = { first: brains[0]!, second: brains[1]!, calls };
+ }, 120_000);
+
+ afterAll(async () => {
+ resetGateway();
+ clearQueryEmbedCache();
+ for (const b of pair ? both(pair) : []) await b.engine.disconnect();
+ for (const p of providers) p.server.stop(true);
+ for (const h of homes) rmSync(h, { recursive: true, force: true });
+ });
+
+ test('both brains opened with their own settings', () => {
+ expect(both(pair).map((b) => b.name)).toEqual(order);
+ });
+
+ for (const c of CASES) {
+ const expected = EXPECTED_FAILURES[c.id];
+ const run = expected?.kinds.includes(kind) ? test.failing : test;
+ run(c.id + (expected?.kinds.includes(kind) ? ' (expected to fail until ' + expected.wave + ')' : ''), () => c.run(pair, kind), 30_000);
+ }
+ });
+ }
+}
diff --git a/test/helpers/upgrade-from-previous-release.ts b/test/helpers/upgrade-from-previous-release.ts
new file mode 100644
index 0000000000..0988c6848c
--- /dev/null
+++ b/test/helpers/upgrade-from-previous-release.ts
@@ -0,0 +1,195 @@
+/**
+ * GBRA-248 gate condition 1 (backward compatible): the upgrade-from-previous-
+ * release harness. Every wave of the embedded-core program extends it.
+ *
+ * A brain the previous release created (the newest schema-history fixture,
+ * test/fixtures/schema-history/, one release's own fresh install) holding a
+ * page, plus a config file in the previous release's keyless format, opens
+ * under this build through the production path (the CLI, which migrates on
+ * connect), keeps its page, and resolves the same settings as the frozen
+ * goldens below. The config file is never rewritten. It runs for the three
+ * brain shapes: a repo brain (the default source is a git checkout), the
+ * default keyless content-directory brain, and a no-root (init --db-only)
+ * brain.
+ *
+ * A wave that changes what the previous release's brain or config resolves
+ * to fails here; a wave that adds a setting proves the setting's absence
+ * leaves these goldens unchanged.
+ */
+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
+import { spawnSync } from 'node:child_process';
+import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { LATEST_VERSION } from '../../src/core/migrate.ts';
+import { PGLiteEngine } from '../../src/core/pglite-engine.ts';
+import { runCli, type CliResult } from './cli-spawn.ts';
+import { schemaHistorySql, schemaHistoryVersions } from './schema-history.ts';
+
+export type UpgradeEngine = 'pglite' | 'postgres';
+export type BrainShape = 'repo' | 'content-directory' | 'no-root';
+export const SHAPES: BrainShape[] = ['repo', 'content-directory', 'no-root'];
+
+const SLUG = 'notes/upgrade-probe';
+const TITLE = 'Upgrade probe';
+const BODY = 'Written by the previous release.';
+
+/** The keyless config file the previous release's init writes (gbrain init --pglite --no-embedding), database fields aside. */
+export const PREVIOUS_RELEASE_KEYLESS_CONFIG = {
+ embedding_disabled: true,
+ schema_pack: 'gbrain-base-v2',
+ mcp: { publish_skills: true },
+ self_upgrade: { mode: 'notify', mode_prompted: true },
+ protocol_installed_at: '2026-10-31T00:00:00.000Z',
+};
+
+/** Frozen golden: what gbrain config show resolves for that brain and config (a database URL prints with its credentials redacted). */
+export function expectedConfigShow(engine: UpgradeEngine): string[] {
+ return [
+ 'GBrain config:',
+ ' engine: ' + engine,
+ engine === 'pglite' ? ' database_path: <BRAIN>' : ' database_url: postgresql://***@<BRAIN>',
+ ' embedding_disabled: true (effective value (file: true, db: unset); either plane\'s true turns embedding off)',
+ ' schema_pack: gbrain-base-v2 (file plane (~/.gbrain/config.json); the tier gbrain schema active resolves)',
+ ' mcp: {"publish_skills":true}',
+ ' self_upgrade: {"mode":"notify","mode_prompted":true}',
+ ' protocol_installed_at: 2026-10-31T00:00:00.000Z',
+ ];
+}
+
+/** Frozen golden: the default source as gbrain sources list --json reports it. */
+export function expectedDefaultSource(shape: BrainShape): Record<string, unknown> {
+ return {
+ id: 'default',
+ name: 'default',
+ local_path: shape === 'no-root' ? null : shape === 'repo' ? '<HOME>/repo' : '<HOME>/.gbrain/content/default',
+ federated: true,
+ mirror_read_only: false,
+ strategy: null,
+ pull_strategy: 'rebase',
+ page_count: 1,
+ last_sync_at: null,
+ };
+}
+
+export interface PreviousReleaseBrain {
+ home: string;
+ brain: string;
+ config: string;
+ configText: string;
+ cli(args: string[]): Promise<CliResult>;
+ normalize(text: string): string;
+}
+
+/** The SQL that puts the previous release's brain at the fixture version, holding one page, with the shape's default source. */
+function shapeSql(shape: BrainShape, localPath: string | null): string {
+ const path = localPath === null ? 'NULL' : "'" + localPath.replaceAll("'", "''") + "'";
+ return [
+ 'UPDATE sources SET local_path = ' + path + " WHERE id = 'default';",
+ "INSERT INTO pages (slug, type, title, compiled_truth, source_id) VALUES ('" + SLUG + "', 'concept', '" + TITLE + "', '" + BODY + "', 'default');",
+ ].join('\n');
+}
+
+function git(cwd: string, args: string[]): void {
+ const r = spawnSync('git', args, { cwd, encoding: 'utf8', env: { ...process.env, GIT_AUTHOR_NAME: 'fixture', GIT_AUTHOR_EMAIL: '[email protected]', GIT_COMMITTER_NAME: 'fixture', GIT_COMMITTER_EMAIL: '[email protected]' } });
+ if (r.status !== 0) throw new Error('git ' + args.join(' ') + ': ' + r.stderr);
+}
+
+export async function previousReleaseBrain(engine: UpgradeEngine, shape: BrainShape, opts: { databaseUrl?: string; loadSql?: (sql: string) => Promise<void> } = {}): Promise<PreviousReleaseBrain> {
+ const home = mkdtempSync(join(tmpdir(), 'gbrain-upgrade-' + shape + '-'));
+ const dir = join(home, '.gbrain');
+ mkdirSync(dir, { recursive: true });
+ const markdown = '---\ntype: concept\ntitle: ' + TITLE + '\n---\n' + BODY + '\n';
+ let localPath: string | null = null;
+ if (shape === 'repo') {
+ localPath = join(home, 'repo');
+ mkdirSync(join(localPath, 'notes'), { recursive: true });
+ writeFileSync(join(localPath, SLUG + '.md'), markdown);
+ git(localPath, ['init', '-q', '-b', 'main']);
+ git(localPath, ['add', '.']);
+ git(localPath, ['commit', '-q', '-m', 'previous release']);
+ } else if (shape === 'content-directory') {
+ localPath = join(dir, 'content', 'default');
+ mkdirSync(join(localPath, 'notes'), { recursive: true });
+ writeFileSync(join(localPath, SLUG + '.md'), markdown);
+ }
+ const version = schemaHistoryVersions(engine).at(-1)!;
+ const sql = schemaHistorySql(engine, version) + '\n' + shapeSql(shape, localPath);
+ const brain = engine === 'pglite' ? join(dir, 'brain.pglite') : opts.databaseUrl!;
+ if (engine === 'pglite') {
+ const loader = new PGLiteEngine();
+ await loader.connect({ database_path: brain });
+ try {
+ await loader.db.exec(sql);
+ } finally {
+ await loader.disconnect();
+ }
+ } else {
+ await opts.loadSql!(sql);
+ }
+ const config = join(dir, 'config.json');
+ const configText = JSON.stringify({
+ engine,
+ ...(engine === 'pglite' ? { database_path: brain } : { database_url: brain }),
+ ...PREVIOUS_RELEASE_KEYLESS_CONFIG,
+ }, null, 2) + '\n';
+ writeFileSync(config, configText);
+ const redacted = engine === 'postgres' ? new URL(brain).host + new URL(brain).pathname : brain;
+ const normalize = (text: string) => text.replaceAll(brain, '<BRAIN>').replaceAll(redacted, '<BRAIN>').replaceAll(home, '<HOME>');
+ return {
+ home,
+ brain,
+ config,
+ configText,
+ cli: (args) => runCli(args, { home, timeoutMs: 120_000 }),
+ normalize,
+ };
+}
+
+export function upgradeFromPreviousReleaseSuite(engine: UpgradeEngine, opts: { databaseUrl?: (shape: BrainShape) => Promise<string>; loadSql?: (url: string, sql: string) => Promise<void> } = {}): void {
+ for (const shape of SHAPES) {
+ describe('previous-release ' + shape + ' brain on ' + engine, () => {
+ let b: PreviousReleaseBrain;
+ let got: CliResult;
+ let show: CliResult;
+ let sources: CliResult;
+ let version: CliResult;
+
+ beforeAll(async () => {
+ const url = await opts.databaseUrl?.(shape);
+ b = await previousReleaseBrain(engine, shape, { databaseUrl: url, loadSql: url ? (sql) => opts.loadSql!(url, sql) : undefined });
+ got = await b.cli(['get', SLUG]);
+ show = await b.cli(['config', 'show']);
+ sources = await b.cli(['sources', 'list', '--json']);
+ version = await b.cli(['config', 'get', 'version']);
+ }, 300_000);
+
+ afterAll(() => {
+ if (b) rmSync(b.home, { recursive: true, force: true });
+ });
+
+ test('opens through the CLI, migrates to the latest schema and keeps its page', () => {
+ expect(got.exitCode, got.stderr).toBe(0);
+ expect(got.stdout).toContain(TITLE);
+ expect(got.stdout).toContain(BODY);
+ expect(version.exitCode, version.stderr).toBe(0);
+ expect(version.stdout.trim()).toBe(String(LATEST_VERSION));
+ });
+
+ test('resolves the same settings as the frozen golden', () => {
+ expect(show.exitCode, show.stderr).toBe(0);
+ expect(b.normalize(show.stdout).trimEnd().split('\n')).toEqual(expectedConfigShow(engine));
+ });
+
+ test('keeps the default source\'s shape', () => {
+ expect(sources.exitCode, sources.stderr).toBe(0);
+ const listed = JSON.parse(b.normalize(sources.stdout)) as { sources: Record<string, unknown>[] };
+ expect(listed.sources).toEqual([expectedDefaultSource(shape)]);
+ });
+
+ test('never rewrites the previous release\'s config file', () => {
+ expect(readFileSync(b.config, 'utf8')).toBe(b.configText);
+ });
+ });
+ }
+}
diff --git a/test/scripts/check-core-world-reads.test.ts b/test/scripts/check-core-world-reads.test.ts
new file mode 100644
index 0000000000..c70aef26b4
--- /dev/null
+++ b/test/scripts/check-core-world-reads.test.ts
@@ -0,0 +1,139 @@
+/**
+ * GBRA-248 W1: scripts/check-core-world-reads.ts counts, per file under
+ * src/core, the reads and effects that reach the process or the machine
+ * (loadConfig, process.env, fs, module-level collections, the spawn wrapper,
+ * process-wide hooks, AsyncLocalStorage stores) and fails when a count rises
+ * above its baseline row or falls below it without the row falling too.
+ */
+import { afterEach, describe, expect, test } from 'bun:test';
+import { spawnSync } from 'node:child_process';
+import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join, resolve } from 'node:path';
+import { countFile } from '../../scripts/check-core-world-reads.ts';
+
+const REPO = resolve(import.meta.dir, '..', '..');
+const GUARD = join(REPO, 'scripts', 'check-core-world-reads.ts');
+const BASELINE = 'scripts/core-world-reads-baseline.tsv';
+const dirs: string[] = [];
+afterEach(() => {
+ for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true });
+});
+
+function tree(files: Record<string, string>): string {
+ const root = mkdtempSync(join(tmpdir(), 'gbrain-core-world-reads-'));
+ dirs.push(root);
+ for (const [rel, body] of Object.entries({ [BASELINE]: '# baseline\n', ...files })) {
+ mkdirSync(join(root, rel, '..'), { recursive: true });
+ writeFileSync(join(root, rel), body);
+ }
+ return root;
+}
+
+function run(root: string, args: string[] = []) {
+ const r = spawnSync('bun', [GUARD, ...args], { encoding: 'utf8', env: { ...process.env, GBRAIN_GUARD_ROOT: root } });
+ return { code: r.status, out: r.stdout + '\n' + r.stderr };
+}
+
+const row = (path: string, metric: string, count: number, why = 'W6: test') => [path, metric, count, why].join('\t');
+
+describe('check-core-world-reads.ts: what counts', () => {
+ test('each metric counts its own construct', () => {
+ const counts = countFile([
+ "import { readFileSync } from 'node:fs';",
+ "import * as fsp from 'fs/promises';",
+ "import { spawnSync } from '../spawn.ts';",
+ "import { AsyncLocalStorage } from 'node:async_hooks';",
+ "const cp = require('child_process');",
+ 'const cache = new Map<string, number>();',
+ 'let current = new Set([1, 2]);',
+ "const TABLE = new Set(['a', 'b']);",
+ 'const store = new AsyncLocalStorage<number>();',
+ 'export function f() {',
+ ' const local = new Map();',
+ ' const c = loadConfig();',
+ ' const k = process.env.OPENAI_API_KEY ?? Bun.env.HOME;',
+ " process.on('exit', () => {});",
+ ' process.exit(1);',
+ ' return [c, k, local, cp, fsp, readFileSync, spawnSync];',
+ '}',
+ ].join('\n'));
+ expect(counts).toEqual({
+ load_config: 1, process_env: 2, fs_import: 2, module_collection: 2, spawn_import: 2, process_global: 2, als_store: 1,
+ });
+ });
+
+ test('comments, strings and look-alike names never count', () => {
+ const counts = countFile([
+ '// loadConfig() and process.env.X in a comment',
+ "const s = 'process.env.HOME loadConfig() new Map()';",
+ "import { x } from './respawn.ts';",
+ 'export function g(proc: { env: string; exit(): void }) { proc.exit(); return proc.env + s + x; }',
+ ].join('\n'));
+ expect(Object.values(counts).every((n) => n === 0)).toBe(true);
+ });
+});
+
+describe('check-core-world-reads.ts: the ratchet', () => {
+ test('a tree at its baseline passes', () => {
+ const root = tree({
+ [BASELINE]: row('src/core/a.ts', 'process_env', 1) + '\n',
+ 'src/core/a.ts': 'export const k = process.env.K;\n',
+ });
+ const r = run(root);
+ expect(r.out).toContain('check-core-world-reads: ok');
+ expect(r.code).toBe(0);
+ });
+
+ test('a count above its row fails and names file, metric, baseline, actual and the docs anchor', () => {
+ const root = tree({
+ [BASELINE]: row('src/core/a.ts', 'process_env', 1) + '\n',
+ 'src/core/a.ts': 'export const k = process.env.K;\nexport const j = process.env.J;\n',
+ });
+ const r = run(root);
+ expect(r.code).toBe(1);
+ expect(r.out).toContain('src/core/a.ts process_env: baseline 1, actual 2');
+ expect(r.out).toContain('take it from engine settings');
+ expect(r.out).toContain('docs/architecture/topologies.md#embedded-core-planned');
+ });
+
+ test('a file with no row counts against a baseline of zero', () => {
+ const root = tree({ 'src/core/new.ts': 'export const c = loadConfig();\ndeclare function loadConfig(): unknown;\n' });
+ const r = run(root);
+ expect(r.code).toBe(1);
+ expect(r.out).toContain('src/core/new.ts load_config: baseline 0, actual 1');
+ });
+
+ test('a count below its row is stale, and --prune lowers it without raising anything', () => {
+ const root = tree({
+ [BASELINE]: [row('src/core/a.ts', 'process_env', 3), row('src/core/gone.ts', 'fs_import', 1)].join('\n') + '\n',
+ 'src/core/a.ts': 'export const k = process.env.K;\n',
+ });
+ const r = run(root);
+ expect(r.code).toBe(1);
+ expect(r.out).toContain('stale row: src/core/a.ts process_env: baseline 3, actual 1');
+ expect(r.out).toContain('stale row: src/core/gone.ts fs_import: baseline 1, actual 0');
+ expect(run(root, ['--prune']).code).toBe(0);
+ expect(readFileSync(join(root, BASELINE), 'utf8')).toBe(row('src/core/a.ts', 'process_env', 1) + '\n');
+ expect(run(root).code).toBe(0);
+ });
+
+ test('duplicate, malformed and unjustified rows fail', () => {
+ const root = tree({
+ [BASELINE]: [
+ row('src/core/a.ts', 'process_env', 1),
+ row('src/core/a.ts', 'process_env', 1),
+ row('src/core/a.ts', 'env_reads', 1),
+ row('src/core/a.ts', 'fs_import', 0),
+ ['src/core/a.ts', 'load_config', '1', ' '].join('\t'),
+ ].join('\n') + '\n',
+ 'src/core/a.ts': 'export const k = process.env.K;\n',
+ });
+ const r = run(root);
+ expect(r.code).toBe(1);
+ expect(r.out).toContain('duplicate row for src/core/a.ts process_env');
+ expect(r.out).toContain('unknown metric "env_reads"');
+ expect(r.out).toContain('count must be a positive integer');
+ expect(r.out).toContain('empty justification');
+ });
+});
diff --git a/test/two-engine-isolation.serial.test.ts b/test/two-engine-isolation.serial.test.ts
new file mode 100644
index 0000000000..48a0944858
--- /dev/null
+++ b/test/two-engine-isolation.serial.test.ts
@@ -0,0 +1,20 @@
+/**
+ * GBRA-248 W1: two PGLite brains in one process keep their own pool, AI key,
+ * caches, sinks, policies, locks, files and jobs (test/helpers/two-engine.ts).
+ * The Postgres half is test/e2e/two-engine-isolation.test.ts.
+ */
+import { afterAll, beforeAll } from 'bun:test';
+import { mkdtempSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { twoEngineIsolationSuite } from './helpers/two-engine.ts';
+
+const processHome = mkdtempSync(join(tmpdir(), 'gbrain-two-engine-process-home-'));
+const savedHome = process.env.GBRAIN_HOME;
+beforeAll(() => { process.env.GBRAIN_HOME = processHome; });
+afterAll(() => {
+ if (savedHome === undefined) delete process.env.GBRAIN_HOME; else process.env.GBRAIN_HOME = savedHome;
+ rmSync(processHome, { recursive: true, force: true });
+});
+
+twoEngineIsolationSuite('pglite');
diff --git a/test/upgrade-from-previous-release.slow.test.ts b/test/upgrade-from-previous-release.slow.test.ts
new file mode 100644
index 0000000000..045eb9b0ba
--- /dev/null
+++ b/test/upgrade-from-previous-release.slow.test.ts
@@ -0,0 +1,10 @@
+/**
+ * GBRA-248 W1, gate condition 1: a PGLite brain and keyless config from the
+ * previous release upgrade under this build with no behavior change, for the
+ * repo, content-directory and no-root shapes
+ * (test/helpers/upgrade-from-previous-release.ts; the Postgres half is
+ * test/e2e/upgrade-from-previous-release.test.ts).
+ */
+import { upgradeFromPreviousReleaseSuite } from './helpers/upgrade-from-previous-release.ts';
+
+upgradeFromPreviousReleaseSuite('pglite');