Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
storage manifest: discovery row, skill, storage adopt, JSONL export/import and doctor storage_manifest (GBRA-387 PR 2)
garrytan7790b1ec92e5
diff --git a/AGENTS.md b/AGENTS.mdindex 3421302a8e..804ed92a83 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -76,6 +76,7 @@ instead of the CLI (one connection, no per-call startup).| Links, dated events, every page of a type | `gbrain backlinks <slug>`, `gbrain timeline <slug>`, `gbrain list --type T` | `get_backlinks`, `get_timeline`, `list_pages` || Save a fact the user stated | `gbrain remember "<fact>" --entity <slug> --content-origin user_said --provenance "<where>"` | `remember` || Why a page didn't rank | `gbrain query "<q>" --explain-target <slug>` | `query` |+| Find something archived to B2, Supabase or S3 | `gbrain storage-find "<phrase>"` | `storage_find` |Parse `--json` output instead of matching the text; notices go to stderr. Neversend stderr to `/dev/null`: a refusal there (`no_brain`, `GBRAIN_DB_ACCESS`)diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8882a9b8ed..7a0a5e534b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -18,8 +18,16 @@ Cards never carry credentials or commands. A card is refused when any field lookThe shelf is written only through the storage verbs. `put_page`, `remember` and every other page writer are refused `storage_source_managed` there, a request parameter cannot open the door, register and update run only from the trusted local CLI, and a dream cycle or enrichment run scoped to the shelf skips it. The source is not federated: a remote connection reads cards only when its grant names `storage`.+**Agents find the shelf, and older archive records move onto it.** The brain-first lookup table every harness reads gains one row, "Find something archived to B2, Supabase or S3" (`gbrain storage-find` / `storage_find`), and a new `storage-manifest` skill says when to register, to find before restoring, to restore through the agent's own restore skill with the card's `restore.skill` and `restore.args`, and to record the restore with `gbrain storage-update`. `gbrain storage adopt` moves interim records (`stored-object` pages under `storage-manifest/` holding their record as JSON under `## Record`) onto the shelf: the preview shows each mapped card and every field a card refuses with its reason; `--apply --expect <plan_hash>` registers each card with `origin: adopt` and tags the original `storage-manifest-adopted`, deleting nothing, and refuses until each refused field is named with `--drop-field` (a credential-shaped value always refuses); `--finalize` previews, then soft-deletes the adopted originals only when every card matches its original. `gbrain storage export --jsonl` and `gbrain storage import --jsonl <file>` (preview per line, then `--apply --expect`) rebuild a shelf from a file, registering missing cards with `origin: import` and never overwriting a differing card. Applies are idempotent and report `side_effects` and, when a run stops part way, the command that finishes it. The new doctor check `storage_manifest` warns about cards that fail the card schema, interim records not adopted yet and a hosted shelf whose directory is gone. On a brain with a Git checkout, adopt and import wait for `gbrain storage init`.+### Itemized changes+- `src/core/storage-manifest/adopt.ts`, `src/core/storage-manifest/jsonl.ts`, `src/commands/storage.ts`: `gbrain storage adopt` (preview, apply, finalize) and `gbrain storage export|import --jsonl`, each preview-first and bound to its plan_hash (a stale one refuses `preview_changed`). `schema.ts` exports the credential-shape rules, the command-key test and the card keys adopt maps onto, plus `cardContent`/`cardDigest` for comparing copies; `source.ts` gains `shelfWritable` (the refusal a storage write would get, without creating anything); `find.ts` gains `readShelfCards`.+- `src/commands/doctor/checks/storage-manifest.ts`, `src/commands/doctor/registry.ts`, `src/core/doctor-categories.ts`: the read-only `storage_manifest` check (brain category), `not_applicable` with no shelf and no interim record. Doctor goldens regenerated for the new check.+- `src/core/error-registry.ts`, `docs/guides/write-refusals.md`, `docs/guides/error-codes.md`: `storage_adopt_field_refused` (consent: the user agrees to leave refused fields out) and `storage_adopt_unverified`; `storage_record_invalid` gains reasons `no_record` and `duplicate_id`.+- `skills/conventions/brain-first.md` (and its generated copies in `AGENTS.md`, `INSTALL_FOR_AGENTS.md`, `skills/RESOLVER.md`, the bootstrap template and the plugin trees), `skills/storage-manifest/SKILL.md`, `skills/RESOLVER.md`, `skills/manifest.json`, `openclaw.plugin.json`: the lookup row and the skill.+- `docs/guides/storage-manifest.md`: the guide (verbs, repo-less and Git-checkout brains, adopt, export and import, doctor, privacy).+- Tests: `test/storage-manifest-adopt.test.ts`, `test/storage-manifest-jsonl.test.ts` and `test/doctor-storage-manifest.test.ts` (PGLite, repo-less) and `test/storage-manifest-adopt-hosted.serial.test.ts` (managed PGLite with a Git checkout).- `src/core/storage-manifest/` (`schema.ts`, `door.ts`, `source.ts`, `find.ts`) and `src/core/ops/storage-manifest.ts`: the card schema and secret checks, the write door, the source lifecycle (`storage init`), keyless ranked lookup (exact id, `page_aliases`, word matches, `pg_trgm` closest cards) and the five ops `storage_find`, `storage_get`, `storage_list`, `storage_register`, `storage_update`.- `src/core/persistence/page-mutations.ts`, `src/core/persistence/memory-mutations.ts`: the page door and `remember`/`forget` refuse writers other than the storage verbs on a source with `role: storage_manifest`; the owner's import of commits already in the hosted repository still syncs.- `src/core/cycle.ts`, `src/commands/enrich.ts`: a cycle scoped to the storage source returns `skipped` with reason `storage_manifest_source`; enrichment considers no card there.diff --git a/INSTALL_FOR_AGENTS.md b/INSTALL_FOR_AGENTS.mdindex 2bf86279d8..ad098e7c36 100644--- a/INSTALL_FOR_AGENTS.md+++ b/INSTALL_FOR_AGENTS.md@@ -393,6 +393,7 @@ instead of the CLI (one connection, no per-call startup).| Links, dated events, every page of a type | `gbrain backlinks <slug>`, `gbrain timeline <slug>`, `gbrain list --type T` | `get_backlinks`, `get_timeline`, `list_pages` || Save a fact the user stated | `gbrain remember "<fact>" --entity <slug> --content-origin user_said --provenance "<where>"` | `remember` || Why a page didn't rank | `gbrain query "<q>" --explain-target <slug>` | `query` |+| Find something archived to B2, Supabase or S3 | `gbrain storage-find "<phrase>"` | `storage_find` |Parse `--json` output instead of matching the text; notices go to stderr. Neversend stderr to `/dev/null`: a refusal there (`no_brain`, `GBRAIN_DB_ACCESS`)diff --git a/docs/architecture/key-files/commands-5-continued.md b/docs/architecture/key-files/commands-5-continued.mdindex c7fc6f5090..a55f6cd419 100644--- a/docs/architecture/key-files/commands-5-continued.md+++ b/docs/architecture/key-files/commands-5-continued.md@@ -17,4 +17,5 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL- `src/commands/status-funnel.ts` — `gbrain status --funnel [--json] [--enable | --delete]` (D8 adoption funnel): engine-free, dispatched from `src/cli/main.ts` before any connect so it works before `gbrain init` and on a thin client; reads and writes only the local record through `src/core/funnel.ts`. Guide: `docs/guides/adoption-funnel.md`. Tests: `test/funnel.test.ts`, `test/funnel-cli.test.ts`.-- `src/commands/storage.ts` — `gbrain storage status [--repo P] [--json]`. Split into pure data (`getStorageStatus`) + JSON formatter + human formatter (ASCII-only) matching the `orphans.ts` pattern. `PageCountsByTier` and `DiskUsageByTier` are distinct nominal types so swaps fail at compile time. The repo and the counted source come from `resolveRestoreTarget` (`src/core/restore-target.ts`, the `export --restore-only` rule), and a page is listed missing exactly when that export would restore it (`isDbOnly`, then `restoreFilePath` in the page source's `scannerSlugRootMode` and `nativeFileTarget`: the recorded `source_path`, else `<slug>.md`, absent; the repo walk answers without a per-page syscall whenever it saw that exact file as a regular file under real directories, and a recorded path starting with the repo's path inside its git checkout, which export re-anchors, takes the full check), so the printed `Use: gbrain export --restore-only --source <id> --repo <path>` (the path passed through `shellQuote`, `src/core/shell-quote.ts`) writes exactly the listed files into `--dir` (default `./export`, not the repo). An unsafe recorded path or a symlinked/ambiguous file target (`OperationError` from `nativeFileTarget`) becomes one warning per reason (lowest slug plus a count of further pages) plus the refusal export would give, printed even when no file is missing; a repo whose own owner (`resolveSourceForRepoPath`: dotfile, then longest registered `local_path`) is archived is refused too (unless an active source is registered at the repo's exact path, which owns it outright), although export's exact-path rule would fall back to the only active source; a refused rule prints `Cannot suggest a restore command:` and falls back to the `--repo` / default-source path, counting the active repo owner's pages (dotfile, then longest registered `local_path`) or every source's pages when no active source owns it. `restoreSource` / `restoreRefusal` carry this in the JSON result. Pinned by `test/storage-restore-hint.test.ts`.+- `src/commands/storage.ts` — `gbrain storage status [--repo P] [--json]`. Split into pure data (`getStorageStatus`) + JSON formatter + human formatter (ASCII-only) matching the `orphans.ts` pattern. `PageCountsByTier` and `DiskUsageByTier` are distinct nominal types so swaps fail at compile time. The repo and the counted source come from `resolveRestoreTarget` (`src/core/restore-target.ts`, the `export --restore-only` rule), and a page is listed missing exactly when that export would restore it (`isDbOnly`, then `restoreFilePath` in the page source's `scannerSlugRootMode` and `nativeFileTarget`: the recorded `source_path`, else `<slug>.md`, absent; the repo walk answers without a per-page syscall whenever it saw that exact file as a regular file under real directories, and a recorded path starting with the repo's path inside its git checkout, which export re-anchors, takes the full check), so the printed `Use: gbrain export --restore-only --source <id> --repo <path>` (the path passed through `shellQuote`, `src/core/shell-quote.ts`) writes exactly the listed files into `--dir` (default `./export`, not the repo). An unsafe recorded path or a symlinked/ambiguous file target (`OperationError` from `nativeFileTarget`) becomes one warning per reason (lowest slug plus a count of further pages) plus the refusal export would give, printed even when no file is missing; a repo whose own owner (`resolveSourceForRepoPath`: dotfile, then longest registered `local_path`) is archived is refused too (unless an active source is registered at the repo's exact path, which owns it outright), although export's exact-path rule would fall back to the only active source; a refused rule prints `Cannot suggest a restore command:` and falls back to the `--repo` / default-source path, counting the active repo owner's pages (dotfile, then longest registered `local_path`) or every source's pages when no active source owns it. `restoreSource` / `restoreRefusal` carry this in the JSON result. Pinned by `test/storage-restore-hint.test.ts`. The storage shelf subcommands (GST-1943) are `storage init`, `storage adopt` (preview, `--apply --expect`, `--finalize [--expect]`; logic in `src/core/storage-manifest/adopt.ts`) and `storage export|import --jsonl` (`src/core/storage-manifest/jsonl.ts`); each builds a trusted local `OperationContext` and renders refusals with `writeCliError`.+- `src/core/storage-manifest/adopt.ts`, `src/core/storage-manifest/jsonl.ts` and `src/commands/doctor/checks/storage-manifest.ts` — GST-1943 storage shelf recovery. Adopt reads interim `stored-object` pages under a prefix (never `<prefix>index`) from the bounded body prefix (`boundedBodyPrefixSql`), takes the JSON block under `## Record`, strips every field the card refuses (`command_field`, `unknown_field`, `stamped_field`; `CARD_KEYS` in `schema.ts`) and validates the rest with `parseCardInput`; a credential-shaped value (`credentialShape`) blocks the page whatever is dropped. Apply registers through `registerCard` (`origin: adopt`) and tags the original `storage-manifest-adopted` through `submitPageMutation`; it never deletes. Finalize soft-deletes tagged originals only when `cardDigest` of the shelf card equals the mapped card. Every plan_hash covers end state (mapped cards, refusals, blocks, conflicts), never progress, so the printed rerun of a partial apply still applies. JSONL import registers `origin: import` and never overwrites. The doctor check `storage_manifest` is read-only: schema-failing cards, unadopted interim records outside the shelf, a hosted shelf directory gone; `not_applicable` with neither shelf nor interim pages. Pinned by `test/storage-manifest-adopt.test.ts`, `test/storage-manifest-jsonl.test.ts`, `test/doctor-storage-manifest.test.ts` and `test/storage-manifest-adopt-hosted.serial.test.ts`.diff --git a/docs/guides/error-codes.md b/docs/guides/error-codes.mdindex b1b9b0ba62..ff0ca24e3d 100644--- a/docs/guides/error-codes.md+++ b/docs/guides/error-codes.md@@ -4702,6 +4702,26 @@ More: [docs/guides/shared-brain-skills.md#troubleshoot-leave-and-recover](../../More: [docs/guides/google-connect.md#troubleshooting](../../docs/guides/google-connect.md#troubleshooting)+### storage_adopt_field_refused++<a id="storage_adopt_field_refused"></a>++| Meaning | Why | Next step | Who acts · consent | Verify | Exit | Retryable |+|---|---|---|---|---|---|---|+| Interim storage records carry fields a card refuses (a command, an unknown field, or a field gbrain stamps), and the adopt apply did not name each one with --drop-field; nothing was written. | Adopting leaves those fields out of the card, so the user decides; the original pages keep them until finalize soft-deletes the originals. | Show the user the refused fields the adopt preview lists; with their agreement, run the apply the refusal names, which drops each with --drop-field. | user | `repeat the read that failed` | 1 | no |++More: [docs/guides/write-refusals.md#storage-manifest-refusals](../../docs/guides/write-refusals.md#storage-manifest-refusals)++### storage_adopt_unverified++<a id="storage_adopt_unverified"></a>++| Meaning | Why | Next step | Who acts · consent | Verify | Exit | Retryable |+|---|---|---|---|---|---|---|+| An adopted interim original has no card on the storage shelf that matches its record, so finalize deleted nothing. | Finalize soft-deletes an original only when its card holds everything the record mapped to, so no archive record is lost. | Compare the original with its card (gbrain storage-get), fix the card or the record, then preview gbrain storage adopt --finalize again. | agent | `repeat the read that failed` | 1 | no |++More: [docs/guides/write-refusals.md#storage-manifest-refusals](../../docs/guides/write-refusals.md#storage-manifest-refusals)+### storage_card_exists<a id="storage_card_exists"></a>@@ -4742,7 +4762,7 @@ More: [docs/guides/write-refusals.md#storage-manifest-refusals](../../docs/guide|---|---|---|---|---|---|---|| A storage card failed validation (a missing or malformed field, a command field, or a field gbrain stamps itself); nothing was written. | Every card must say where the item is, how big it is and how to restore it, and carries no commands, so a card is complete and safe to act on when it is found months later. | Fix the field the message names and send the card again; gbrain storage-register --help lists the card fields. | agent | `repeat the read that failed` | 1 | no |-Reasons: `schema`, `command_field`, `stamped_field`, `not_json`, `not_object`, `too_large`, `id_change`.+Reasons: `schema`, `command_field`, `stamped_field`, `not_json`, `not_object`, `too_large`, `id_change`, `no_record`, `duplicate_id`.More: [docs/guides/write-refusals.md#storage-manifest-refusals](../../docs/guides/write-refusals.md#storage-manifest-refusals)diff --git a/docs/guides/storage-manifest.md b/docs/guides/storage-manifest.mdnew file mode 100644index 0000000000..54cbcd0024--- /dev/null+++ b/docs/guides/storage-manifest.md@@ -0,0 +1,84 @@+# Storage manifest++The storage manifest is a shelf of cards, one per item an agent archived to object storage (B2, Supabase Storage,+S3, R2, GCS). A card says what the item is, where every copy lives (store, bucket, path, restic repository and+snapshot, size, file count, hash and its kind, when it was verified), where it came from, why it was archived, and+which skill restores it. Months later an agent finds the card from a plain phrase and restores the item through its+own restore skill.++**Say to your agent:** *"Bring back the October mail dataset."*++**Say to your agent:** *"Where did the old research runs go?"*++**Say to your agent:** *"What's in B2?"*++The skill behind these is `skills/storage-manifest/SKILL.md`.++## The verbs++| Step | CLI | MCP tool |+|---|---|---|+| Find a card from a phrase (closest cards on a miss) | `gbrain storage-find "<phrase>"` | `storage_find` |+| Read one card, its restore form and revision | `gbrain storage-get <id>` | `storage_get` |+| List cards by store, status or source machine | `gbrain storage-list [--store b2] [--status archived]` | `storage_list` |+| Register a card after a verified archive | `gbrain storage-register --card '<json>'` (or stdin) | local CLI only |+| Change a card, or record a restore | `gbrain storage-update <id> --expected-revision <rev> [--patch '<json>'] [--restored-to <path> --restored-verified]` | local CLI only |++A restore runs through the agent's own restore skill: the card's `restore.skill` with `restore.args`. Cards never+carry commands or credentials, and gbrain never contacts a store. After the restore, `storage-update` with+`--restored-to` records where it landed (newest first); pass `--restored-verified` only when the checksums matched.++## Repo-less brains and brains with a Git checkout++On a repo-less brain the database is the record: the first `storage-register` (or `gbrain storage init`) creates the+`storage` source, database-only and not federated, and every verb works there.++On a brain with a Git checkout, Git stays the parent. `gbrain storage init --dir <absolute path> --dry-run` previews a+hosted Git repository for the shelf, and the printed `--expect <plan_hash>` command creates it after the user agrees+(it needs managed persistence). Every card is then a commit before the database indexes it. Until init has run,+register, adopt and import refuse `storage_manifest_missing` with that preview as the fix.++## Adopt interim records++Agents that archived before the shelf existed often kept interim pages: `type: stored-object` pages under+`storage-manifest/`, each with its record as JSON in a fenced `json` block under a `## Record` heading.+`gbrain storage adopt` moves them onto the shelf in three preview-first steps:++1. `gbrain storage adopt [--source <id>] [--from-prefix <prefix>]` previews: per page, the card it maps to and each+ field a card refuses with its reason (`command_field` such as `restore.command`, `unknown_field`,+ `stamped_field`). It writes nothing and prints a `plan_hash`. The index page (`<prefix>index`) is skipped.+2. The printed apply, `--apply --expect <plan_hash>` with one `--drop-field <dotted.name>` per refused field, runs+ after the user agrees to leave those fields out. It registers each card with `origin: adopt` through the same+ path `storage-register` uses, then tags the original `storage-manifest-adopted`. It deletes nothing. A+ credential-shaped value (a secret, an environment assignment, a credential variable, a URL password, a signed URL)+ always refuses, whatever is dropped: fix the source page first.+3. `gbrain storage adopt --finalize` previews soft-deleting the tagged originals; its `--expect <plan_hash>` run deletes+ them (restorable for 72 hours with `gbrain restore`), only when every adopted card is on the shelf and matches its+ original's mapped card.++A rerun skips cards already on the shelf that match and originals already tagged. A card on the shelf that differs is+a conflict: it is reported and never overwritten, and its original stays untagged. Every apply reports+`side_effects: none | partial | complete`; a run that stopped part way prints the command that finishes it.++## Export and import (JSONL)++`gbrain storage export --jsonl [--out <new file>]` writes every card as one JSON line, sorted by id, with the fields+gbrain stamps (`registered_by`, `origin`). `gbrain storage import --jsonl <file>` previews each line as+`create`, `identical`, `conflict` or `invalid` with a `plan_hash`; `--apply --expect <plan_hash>` registers the+missing cards with `origin: import` (gbrain stamps both fields again), never overwrites a differing card, and skips+invalid lines without showing their values. Export from one brain and import into an empty one reproduces every card.++## Doctor++`gbrain doctor --only storage_manifest` (read-only) warns about cards that fail the current card schema, interim+records under `storage-manifest/` that are not adopted yet, and a hosted shelf whose directory is gone. It reports+not applicable on a brain with no shelf and no interim record.++## Privacy++Cards hold paths, sizes, hashes and restore forms, never file contents or credentials; the restore skill reads+credentials from its own environment. The `storage` source is not federated: ordinary search does not return cards,+and a remote connection reads them only when its grant names `storage`. Register and update run only from the trusted+local CLI, and only the storage verbs write the shelf.++Refusals and their fixes: [write refusals](write-refusals.md#storage-manifest-refusals).diff --git a/docs/guides/write-refusals.md b/docs/guides/write-refusals.mdindex 1daf57b496..f1aa83e692 100644--- a/docs/guides/write-refusals.md+++ b/docs/guides/write-refusals.md@@ -1077,7 +1077,10 @@ Links and the right live in the database, so they are the same on a repo-less br## Storage manifest refusalsThe storage shelf (source `storage`) holds one validated card per item an agent archived to object storage.-Only `gbrain storage-register` and `gbrain storage-update` write it, from the trusted local CLI.+Only the storage verbs write it (`gbrain storage-register`, `gbrain storage-update`, and `gbrain storage adopt` and+`gbrain storage import`, which register through the same path), from the trusted local CLI. Guide: [storage manifest](storage-manifest.md).+An adopt or import apply whose plan changed since its preview refuses `preview_changed`; `storage_record_invalid` and+`storage_record_secret` there name the interim page or JSONL line instead of a field you sent.| Code | What happened | What to do ||---|---|---|@@ -1087,6 +1090,8 @@ Only `gbrain storage-register` and `gbrain storage-update` write it, from the tr| `storage_card_exists` | A card with that id is already registered. | Update it with the revision `storage_get` returns, or use another id. || `storage_revision_conflict` | The card changed since its revision was read; `detail` holds the current revision. | Read it again, apply the change, update once. || `storage_manifest_missing` | No shelf yet on a brain with a Git checkout, or the `storage` source ID belongs to another source. | Preview `gbrain storage init --dir <path> --dry-run` and apply it after the user agrees (it needs managed persistence). |+| `storage_adopt_field_refused` | `gbrain storage adopt --apply` found interim records with fields a card refuses (a command, an unknown field, a stamped field) that it was not told to drop. | Show the user the fields the preview lists; with their agreement, run the apply the refusal names (one `--drop-field` per field). The original pages keep them until finalize. |+| `storage_adopt_unverified` | `gbrain storage adopt --finalize` found an adopted original whose card is missing or differs from its record. Nothing was deleted. | Compare the original with its card (`gbrain storage-get`), fix one of them, and preview finalize again. |## Relateddiff --git a/llms-full.txt b/llms-full.txtindex aa888256a4..55427d1e7b 100644--- a/llms-full.txt+++ b/llms-full.txt@@ -1848,6 +1848,7 @@ instead of the CLI (one connection, no per-call startup).| Links, dated events, every page of a type | `gbrain backlinks <slug>`, `gbrain timeline <slug>`, `gbrain list --type T` | `get_backlinks`, `get_timeline`, `list_pages` || Save a fact the user stated | `gbrain remember "<fact>" --entity <slug> --content-origin user_said --provenance "<where>"` | `remember` || Why a page didn't rank | `gbrain query "<q>" --explain-target <slug>` | `query` |+| Find something archived to B2, Supabase or S3 | `gbrain storage-find "<phrase>"` | `storage_find` |Parse `--json` output instead of matching the text; notices go to stderr. Neversend stderr to `/dev/null`: a refusal there (`no_brain`, `GBRAIN_DB_ACCESS`)@@ -3084,6 +3085,7 @@ instead of the CLI (one connection, no per-call startup).| Links, dated events, every page of a type | `gbrain backlinks <slug>`, `gbrain timeline <slug>`, `gbrain list --type T` | `get_backlinks`, `get_timeline`, `list_pages` || Save a fact the user stated | `gbrain remember "<fact>" --entity <slug> --content-origin user_said --provenance "<where>"` | `remember` || Why a page didn't rank | `gbrain query "<q>" --explain-target <slug>` | `query` |+| Find something archived to B2, Supabase or S3 | `gbrain storage-find "<phrase>"` | `storage_find` |Parse `--json` output instead of matching the text; notices go to stderr. Neversend stderr to `/dev/null`: a refusal there (`no_brain`, `GBRAIN_DB_ACCESS`)@@ -4940,6 +4942,7 @@ instead of the CLI (one connection, no per-call startup).| Links, dated events, every page of a type | `gbrain backlinks <slug>`, `gbrain timeline <slug>`, `gbrain list --type T` | `get_backlinks`, `get_timeline`, `list_pages` || Save a fact the user stated | `gbrain remember "<fact>" --entity <slug> --content-origin user_said --provenance "<where>"` | `remember` || Why a page didn't rank | `gbrain query "<q>" --explain-target <slug>` | `query` |+| Find something archived to B2, Supabase or S3 | `gbrain storage-find "<phrase>"` | `storage_find` |Parse `--json` output instead of matching the text; notices go to stderr. Neversend stderr to `/dev/null`: a refusal there (`no_brain`, `GBRAIN_DB_ACCESS`)@@ -4981,6 +4984,7 @@ off until the user opts in, and paid enrichment is a separate choice.| "turn on System One", "enable Jev", "TypeSafe decide", "why is the evidence gate inactive", "turn System One off" | `gbrain decide probe/status/enable/disable` directly (brain host only). See `docs/guides/system-one.md` || "eval results", "search benchmark", "haters-immune methodology", "regression check on retrieval" | `gbrain eval longmemeval <dataset.jsonl> --mode <mode> --record` per mode, `gbrain eval run-all` (BrainBench), then `gbrain eval compare`. See `docs/eval/SEARCH_MODE_METHODOLOGY.md` || "bulk delete", "wipe the", "rm -rf", "purge the", "bulk forget" | `skills/data-loss-gate/SKILL.md` |+| "bring back", "restore the archived", "where did X go", "what's in B2", "register this archive" | `skills/storage-manifest/SKILL.md` || "fact check", "fact-check", "verify the facts", "check the claims" | `skills/fact-check/SKILL.md` || "resolve before asking", "before asking the user", "unidentified contact", "unknown relationship" | `skills/resolve-before-asking/SKILL.md` || "move this to brain", "migrate to brain", "copy these files into the brain", "is this already in the brain" | `skills/brain-ingest-gate/SKILL.md` |diff --git a/openclaw.plugin.json b/openclaw.plugin.jsonindex 5ab4aaa42e..4fe14293f2 100644--- a/openclaw.plugin.json+++ b/openclaw.plugin.json@@ -98,6 +98,7 @@"skills/skillpack-check","skills/skillpack-harvest","skills/soul-audit",+ "skills/storage-manifest","skills/strategic-reading","skills/testing","skills/two-tier-extraction",diff --git a/plugin-variants/gbrain-coding/skills/conventions/brain-first.md b/plugin-variants/gbrain-coding/skills/conventions/brain-first.mdindex e9a0e72b04..d7ad9f4a53 100644--- a/plugin-variants/gbrain-coding/skills/conventions/brain-first.md+++ b/plugin-variants/gbrain-coding/skills/conventions/brain-first.md@@ -25,6 +25,7 @@ instead of the CLI (one connection, no per-call startup).| Links, dated events, every page of a type | `gbrain backlinks <slug>`, `gbrain timeline <slug>`, `gbrain list --type T` | `get_backlinks`, `get_timeline`, `list_pages` || Save a fact the user stated | `gbrain remember "<fact>" --entity <slug> --content-origin user_said --provenance "<where>"` | `remember` || Why a page didn't rank | `gbrain query "<q>" --explain-target <slug>` | `query` |+| Find something archived to B2, Supabase or S3 | `gbrain storage-find "<phrase>"` | `storage_find` |Parse `--json` output instead of matching the text; notices go to stderr. Neversend stderr to `/dev/null`: a refusal there (`no_brain`, `GBRAIN_DB_ACCESS`)diff --git a/plugin-variants/gbrain-daily/skills/conventions/brain-first.md b/plugin-variants/gbrain-daily/skills/conventions/brain-first.mdindex e9a0e72b04..d7ad9f4a53 100644--- a/plugin-variants/gbrain-daily/skills/conventions/brain-first.md+++ b/plugin-variants/gbrain-daily/skills/conventions/brain-first.md@@ -25,6 +25,7 @@ instead of the CLI (one connection, no per-call startup).| Links, dated events, every page of a type | `gbrain backlinks <slug>`, `gbrain timeline <slug>`, `gbrain list --type T` | `get_backlinks`, `get_timeline`, `list_pages` || Save a fact the user stated | `gbrain remember "<fact>" --entity <slug> --content-origin user_said --provenance "<where>"` | `remember` || Why a page didn't rank | `gbrain query "<q>" --explain-target <slug>` | `query` |+| Find something archived to B2, Supabase or S3 | `gbrain storage-find "<phrase>"` | `storage_find` |Parse `--json` output instead of matching the text; notices go to stderr. Neversend stderr to `/dev/null`: a refusal there (`no_brain`, `GBRAIN_DB_ACCESS`)diff --git a/plugin/skills/conventions/brain-first.md b/plugin/skills/conventions/brain-first.mdindex e9a0e72b04..d7ad9f4a53 100644--- a/plugin/skills/conventions/brain-first.md+++ b/plugin/skills/conventions/brain-first.md@@ -25,6 +25,7 @@ instead of the CLI (one connection, no per-call startup).| Links, dated events, every page of a type | `gbrain backlinks <slug>`, `gbrain timeline <slug>`, `gbrain list --type T` | `get_backlinks`, `get_timeline`, `list_pages` || Save a fact the user stated | `gbrain remember "<fact>" --entity <slug> --content-origin user_said --provenance "<where>"` | `remember` || Why a page didn't rank | `gbrain query "<q>" --explain-target <slug>` | `query` |+| Find something archived to B2, Supabase or S3 | `gbrain storage-find "<phrase>"` | `storage_find` |Parse `--json` output instead of matching the text; notices go to stderr. Neversend stderr to `/dev/null`: a refusal there (`no_brain`, `GBRAIN_DB_ACCESS`)diff --git a/plugin/skills/storage-manifest/SKILL.md b/plugin/skills/storage-manifest/SKILL.mdnew file mode 100644index 0000000000..16679b9bb4--- /dev/null+++ b/plugin/skills/storage-manifest/SKILL.md@@ -0,0 +1,65 @@+---+name: storage-manifest+version: 1.0.0+description: |+ The storage shelf: one card per item archived to object storage (B2,+ Supabase Storage, S3). Register a card after a verified archive, find a+ card before any restore, restore through the agent's own restore skill with+ the card's restore form, then record the restore on the card.+triggers:+ - "bring back"+ - "restore the archived"+ - "where did X go"+ - "what's in B2"+ - "what did we archive"+ - "register this archive"+tools:+ - storage_find+ - storage_get+ - storage_list+mutating: true+writes_pages: false+when_to_use: "Use when the user asks: \"bring back\", \"restore the archived\", \"where did X go\", \"what's in B2\", \"what did we archive\"."+---++# Storage manifest++> **Convention:** see [conventions/brain-first.md](../conventions/brain-first.md):+> look on the shelf with `gbrain storage-find` before listing a bucket or asking the user where something went.++Full guide: `docs/guides/storage-manifest.md`.++## Contract++- **Register after the archive is verified, never before.** Once the upload's checksum or snapshot check passed,+ run `gbrain storage-register --card '<json>'` (or pipe the card on stdin) from the trusted local CLI. The card+ names every copy (store, bucket, path, tool, repository, snapshot, size, hash and its kind, when verified), the+ original path, why it was archived, and the restore form `{ skill, args }`.+- **Find before restore.** `gbrain storage-find "<the user's words>" --json` (MCP `storage_find`), then+ `gbrain storage-get <id> --json` for the copies and the restore form. A miss lists the closest cards: show them.+- **Restore through the agent's own restore skill.** Run the skill the card's `restore.skill` names with+ `restore.args`. Cards never carry commands or credentials; the restore skill reads credentials from its own+ environment. gbrain never contacts a store.+- **Record the restore.** After the restore, run `gbrain storage-update <id> --expected-revision <rev>+ --restored-to <path>` with `--restored-verified` only when the checksums matched. `<rev>` is the revision+ `storage-get` returned; on `storage_revision_conflict` read the card again and update once.+- **Interim records** (`stored-object` pages under `storage-manifest/` written before the shelf existed) move with+ `gbrain storage adopt`: preview, show the user every refused field, then apply the printed command.++## Anti-Patterns++- Putting a command, a password, a signed URL or an environment assignment on a card: it is refused.+- Writing the shelf with `put_page` or `remember`: refused `storage_source_managed`.+- Restoring from a bucket listing without reading the card first.+- Recording `--restored-verified` without checking the hashes.++## Output Format++Tell the user what the card says in plain words: what the item is, where each copy lives, its size, when it was last+verified, and which skill restores it. After a restore, say where it landed and whether the checksums matched.++## When it fails++Read the refusal's `code` and follow its `fix` (see [the agent operator protocol](../conventions/agent-operator-protocol.md)).+`storage_manifest_missing` on a brain with a Git checkout means the shelf is not hosted yet: relay the+`gbrain storage init` preview to the user.diff --git a/skills/RESOLVER.md b/skills/RESOLVER.mdindex ec8127c6d1..dab506957d 100644--- a/skills/RESOLVER.md+++ b/skills/RESOLVER.md@@ -33,6 +33,7 @@ instead of the CLI (one connection, no per-call startup).| Links, dated events, every page of a type | `gbrain backlinks <slug>`, `gbrain timeline <slug>`, `gbrain list --type T` | `get_backlinks`, `get_timeline`, `list_pages` || Save a fact the user stated | `gbrain remember "<fact>" --entity <slug> --content-origin user_said --provenance "<where>"` | `remember` || Why a page didn't rank | `gbrain query "<q>" --explain-target <slug>` | `query` |+| Find something archived to B2, Supabase or S3 | `gbrain storage-find "<phrase>"` | `storage_find` |Parse `--json` output instead of matching the text; notices go to stderr. Neversend stderr to `/dev/null`: a refusal there (`no_brain`, `GBRAIN_DB_ACCESS`)@@ -74,6 +75,7 @@ off until the user opts in, and paid enrichment is a separate choice.| "turn on System One", "enable Jev", "TypeSafe decide", "why is the evidence gate inactive", "turn System One off" | `gbrain decide probe/status/enable/disable` directly (brain host only). See `docs/guides/system-one.md` || "eval results", "search benchmark", "haters-immune methodology", "regression check on retrieval" | `gbrain eval longmemeval <dataset.jsonl> --mode <mode> --record` per mode, `gbrain eval run-all` (BrainBench), then `gbrain eval compare`. See `docs/eval/SEARCH_MODE_METHODOLOGY.md` || "bulk delete", "wipe the", "rm -rf", "purge the", "bulk forget" | `skills/data-loss-gate/SKILL.md` |+| "bring back", "restore the archived", "where did X go", "what's in B2", "register this archive" | `skills/storage-manifest/SKILL.md` || "fact check", "fact-check", "verify the facts", "check the claims" | `skills/fact-check/SKILL.md` || "resolve before asking", "before asking the user", "unidentified contact", "unknown relationship" | `skills/resolve-before-asking/SKILL.md` || "move this to brain", "migrate to brain", "copy these files into the brain", "is this already in the brain" | `skills/brain-ingest-gate/SKILL.md` |diff --git a/skills/conventions/brain-first.md b/skills/conventions/brain-first.mdindex e9a0e72b04..d7ad9f4a53 100644--- a/skills/conventions/brain-first.md+++ b/skills/conventions/brain-first.md@@ -25,6 +25,7 @@ instead of the CLI (one connection, no per-call startup).| Links, dated events, every page of a type | `gbrain backlinks <slug>`, `gbrain timeline <slug>`, `gbrain list --type T` | `get_backlinks`, `get_timeline`, `list_pages` || Save a fact the user stated | `gbrain remember "<fact>" --entity <slug> --content-origin user_said --provenance "<where>"` | `remember` || Why a page didn't rank | `gbrain query "<q>" --explain-target <slug>` | `query` |+| Find something archived to B2, Supabase or S3 | `gbrain storage-find "<phrase>"` | `storage_find` |Parse `--json` output instead of matching the text; notices go to stderr. Neversend stderr to `/dev/null`: a refusal there (`no_brain`, `GBRAIN_DB_ACCESS`)diff --git a/skills/manifest.json b/skills/manifest.jsonindex 28e716c343..51c5b612a5 100644--- a/skills/manifest.json+++ b/skills/manifest.json@@ -289,6 +289,11 @@"path": "data-loss-gate/SKILL.md","description": "Confirmation gate before any bulk delete, cleanup, or destructive operation that could result in data loss \u2014 shell-level (rm -rf, git rm, bulk sed) or brain-level (bulk forget, delete sweeps, purge-deleted, source\u2026"},+ {+ "name": "storage-manifest",+ "path": "storage-manifest/SKILL.md",+ "description": "The storage shelf: register a card after a verified archive to B2, Supabase Storage or S3, find a card before any restore, restore through the agent's own restore skill with the card's restore form, then record the restore on the card."+ },{"name": "fact-check","path": "fact-check/SKILL.md",diff --git a/skills/skills.lock.json b/skills/skills.lock.jsonindex 76abef9092..e3c37d04f8 100644--- a/skills/skills.lock.json+++ b/skills/skills.lock.json@@ -1,5 +1,5 @@{- "RESOLVER.md": "587768c702e0badf5e7d6201cd5902b7313b218e5663ab527e3a8365f5c438ee",+ "RESOLVER.md": "40be9ec46c8a0c8e568c6c382ed2db68aff7abea3fee4ec41e87b9753b234e73","_AGENT_README.md": "ab51e36e9a0b53f4d0609294b0556444399147834932d9c1acfdc7aa367c70b8","_brain-filing-rules.json": "4e6ecee2d94867d146583d60bf98dccdd9205bb70793af56fe1397a2b258ae0d","_brain-filing-rules.md": "ff42b331bce542d708f97ff0a73ff0fb5664b46ee9b1862a5478b15dc637487e",@@ -45,7 +45,7 @@"context-audit/SKILL.md": "6d786629d40544ddaab4f4e6e333569d270bcb8b581589dc16fb9f8bcb4f6207","context-audit/routing-eval.jsonl": "fb1832e24cc1b04163a74c5cde72bca53050a66246ca902e1a5f40303f52b5ab","conventions/agent-operator-protocol.md": "12c7b876994b96babdffa903326f7e23253d54ad9023248820337f56f8770512",- "conventions/brain-first.md": "26035e2e1bb1f8386180ec4cdc6525ab2375c0f350af394b4de0d2e67987c899",+ "conventions/brain-first.md": "39fe2acdda024eaad950eb75a41c0b42a6e46fe6466b1c53730b9dfa758f0ba4","conventions/brain-routing.md": "f11c3e7c4f98163aa6c68aa7d8f09a7acb7b6a8695f42eb7d92d4ee5787d428a","conventions/calibration.md": "500dc26bd7c8400f50dc4c16fd83f1a588f3e7e68c59050a21fd8a0f69e4d198","conventions/cron-via-minions.md": "badb1cd6cd825d6f1ac0b6b28cc47e5d80facc783a3e59a14146ae901ee0f933",@@ -95,7 +95,7 @@"idea-lineage/routing-eval.jsonl": "ee2e00704b9accb7dd58bb8f126a3bc04a2c40be499180fa505dbf6d5061cd41","ingest/SKILL.md": "1acc220ce6e9e65876fa2ccede6ce11f9c75457feb6695ef904955f8debecaae","maintain/SKILL.md": "6faf40cb944a0deb7d032e41f44b66f05fe0ebe8178bd84d3cf05e2f766f6127",- "manifest.json": "357aa185d380f0a357cb15cd513317e290cbc5fcf5ca4e3860b0e829fdcbf1e4",+ "manifest.json": "f9d16966d26fe9b37ef6ce9609eaa29d06142a409f3b531f1289b1a8c1bc929e","mcp-access/SKILL.md": "1bc16338b89f476aa8c24ffec79c989fa60716793998af264d357f7886d2bc96","measure-before-you-fix/SKILL.md": "11906da29a1a31976b13d4796b686d9a9981825737846a85f32d88bf431b9b36","measure-before-you-fix/routing-eval.jsonl": "0661df9974a9cfe31216d574b1db0ef341945c2eb844ebf4ab6920fcbbc90d6c",@@ -226,6 +226,7 @@"skillpack-harvest/routing-eval.jsonl": "cb4783288e95af3132b32ecb40a54cffc095f57b36240f96a25c2d2adf5e68c6","smoke-test/SKILL.md": "f5099e1d2ab9dc6827096249e68414f7ae357c29b39fb069a54bb7fb74f414a5","soul-audit/SKILL.md": "7a48e180849f7502d332878c443397f90a3756f45caa94f76bcfcc7c997469c8",+ "storage-manifest/SKILL.md": "f7326969b1204d8de94488b9dd6030f2a2d812f7d37fbc24b239ec7582ea3306","strategic-reading/SKILL.md": "ab2cd3adc79289374cfbc5cb3d5ee17f962fd8f7f3c997a1da708da0ed67797c","strategic-reading/routing-eval.jsonl": "eb0fc239c93aac53cf7d856190967bb65eaf970b4fe8bd0aad1c87495fbb8ccd","testing/SKILL.md": "c69fe3456aa981bbcfe06c7633042eabf68617c69e9c26c00e47a0848fd90fb3",diff --git a/skills/storage-manifest/SKILL.md b/skills/storage-manifest/SKILL.mdnew file mode 100644index 0000000000..87f09f62bd--- /dev/null+++ b/skills/storage-manifest/SKILL.md@@ -0,0 +1,64 @@+---+name: storage-manifest+version: 1.0.0+description: |+ The storage shelf: one card per item archived to object storage (B2,+ Supabase Storage, S3). Register a card after a verified archive, find a+ card before any restore, restore through the agent's own restore skill with+ the card's restore form, then record the restore on the card.+triggers:+ - "bring back"+ - "restore the archived"+ - "where did X go"+ - "what's in B2"+ - "what did we archive"+ - "register this archive"+tools:+ - storage_find+ - storage_get+ - storage_list+mutating: true+writes_pages: false+---++# Storage manifest++> **Convention:** see [conventions/brain-first.md](../conventions/brain-first.md):+> look on the shelf with `gbrain storage-find` before listing a bucket or asking the user where something went.++Full guide: `docs/guides/storage-manifest.md`.++## Contract++- **Register after the archive is verified, never before.** Once the upload's checksum or snapshot check passed,+ run `gbrain storage-register --card '<json>'` (or pipe the card on stdin) from the trusted local CLI. The card+ names every copy (store, bucket, path, tool, repository, snapshot, size, hash and its kind, when verified), the+ original path, why it was archived, and the restore form `{ skill, args }`.+- **Find before restore.** `gbrain storage-find "<the user's words>" --json` (MCP `storage_find`), then+ `gbrain storage-get <id> --json` for the copies and the restore form. A miss lists the closest cards: show them.+- **Restore through the agent's own restore skill.** Run the skill the card's `restore.skill` names with+ `restore.args`. Cards never carry commands or credentials; the restore skill reads credentials from its own+ environment. gbrain never contacts a store.+- **Record the restore.** After the restore, run `gbrain storage-update <id> --expected-revision <rev>+ --restored-to <path>` with `--restored-verified` only when the checksums matched. `<rev>` is the revision+ `storage-get` returned; on `storage_revision_conflict` read the card again and update once.+- **Interim records** (`stored-object` pages under `storage-manifest/` written before the shelf existed) move with+ `gbrain storage adopt`: preview, show the user every refused field, then apply the printed command.++## Anti-Patterns++- Putting a command, a password, a signed URL or an environment assignment on a card: it is refused.+- Writing the shelf with `put_page` or `remember`: refused `storage_source_managed`.+- Restoring from a bucket listing without reading the card first.+- Recording `--restored-verified` without checking the hashes.++## Output Format++Tell the user what the card says in plain words: what the item is, where each copy lives, its size, when it was last+verified, and which skill restores it. After a restore, say where it landed and whether the checksums matched.++## When it fails++Read the refusal's `code` and follow its `fix` (see [the agent operator protocol](../conventions/agent-operator-protocol.md)).+`storage_manifest_missing` on a brain with a Git checkout means the shelf is not hosted yet: relay the+`gbrain storage init` preview to the user.diff --git a/src/commands/doctor/checks/storage-manifest.ts b/src/commands/doctor/checks/storage-manifest.tsnew file mode 100644index 0000000000..5ce787394f--- /dev/null+++ b/src/commands/doctor/checks/storage-manifest.ts@@ -0,0 +1,68 @@+/**+ * GST-1943: `storage_manifest`, read-only health of the storage shelf. Warns on+ * - cards on the shelf that fail the current card schema (or pages there that hold no card);+ * - interim `stored-object` pages under `storage-manifest/` outside the shelf that are not adopted yet (the fix is+ * the read-only `gbrain storage adopt` preview);+ * - a hosted shelf (source `storage` with role storage_manifest) whose worktree or repository directory is gone.+ * Reports not_applicable when there is no shelf and no interim page. Values are never echoed: findings name ids.+ */+import { existsSync } from 'node:fs';+import type { Check } from '../../doctor.ts';+import type { BrainEngine } from '../../../core/engine.ts';+import type { Action } from '../../../core/agent-output.ts';+import { ADOPT_DEFAULT_PREFIX, ADOPTED_TAG } from '../../../core/storage-manifest/adopt.ts';+import { readShelfCards } from '../../../core/storage-manifest/find.ts';+import { cardContent, ORIGINS, STORED_OBJECT_TYPE } from '../../../core/storage-manifest/schema.ts';+import { isStorageRole, STORAGE_SOURCE_ID } from '../../../core/storage-manifest/source.ts';+import { parseSourceConfig } from '../../../core/sources-load.ts';+import { agentFix, checkError, infoCheck } from '../check-fix.ts';+import { connectedEngine, type DoctorContext, type DoctorEntry } from '../context.ts';++const NAME = 'storage_manifest';+const DOCS = 'docs/guides/storage-manifest.md#doctor';++export async function storageManifestCheck(engine: BrainEngine): Promise<Check> {+ try {+ const [source] = await engine.executeRaw<{ local_path: string | null; config: unknown }>('SELECT local_path, config FROM sources WHERE id = $1 AND archived IS NOT TRUE', [STORAGE_SOURCE_ID]);+ const interim = await engine.executeRaw<{ source_id: string; n: number }>(`+ SELECT p.source_id, count(*)::int AS n FROM pages p+ WHERE p.type = $1 AND p.source_id <> $2 AND left(p.slug, length($3)) = $3 AND p.slug <> $3 || 'index' AND p.deleted_at IS NULL+ AND NOT EXISTS (SELECT 1 FROM tags t WHERE t.page_id = p.id AND t.tag = $4)+ GROUP BY p.source_id ORDER BY p.source_id`, [STORED_OBJECT_TYPE, STORAGE_SOURCE_ID, ADOPT_DEFAULT_PREFIX, ADOPTED_TAG]);+ const shelf = !!source && isStorageRole(source.config);+ if (!shelf && !interim.length) return infoCheck(NAME, 'No storage shelf and no interim storage records on this brain.', 'not_applicable', undefined, { docs: DOCS });+ const invalid = shelf ? (await readShelfCards(engine)).filter((row) => !row.card || !cardContent(row.card) || typeof row.card.registered_by !== 'string'+ || !(ORIGINS as readonly string[]).includes(row.card.origin)).map((row) => row.id) : [];+ const hosted = shelf ? parseSourceConfig(source!.config).hosted_repo as { repository?: string; worktree?: string } | undefined : undefined;+ const missingDirs = shelf ? [...new Set([source!.local_path, hosted?.worktree, hosted?.repository].filter((dir): dir is string => !!dir && !existsSync(dir)))] : [];+ const pending = interim.reduce((sum, row) => sum + Number(row.n), 0);+ const details = { shelf, invalid_cards: invalid, interim_pending: interim.map((row) => ({ source_id: row.source_id, count: Number(row.n) })), missing_dirs: missingDirs, docs: DOCS };+ const problems: string[] = [];+ if (missingDirs.length) problems.push(`the hosted shelf's directory is gone (${missingDirs.join(', ')}), so cards cannot be committed`);+ if (invalid.length) problems.push(`${invalid.length} card(s) fail the current card schema: ${invalid.slice(0, 10).join(', ')}${invalid.length > 10 ? ', and more' : ''}`);+ if (pending) problems.push(`${pending} interim storage record(s) under ${ADOPT_DEFAULT_PREFIX} are not adopted yet (${interim.map((row) => `${row.source_id}: ${row.n}`).join(', ')})`);+ if (!problems.length) return { name: NAME, status: 'ok', message: 'Every card on the storage shelf passes the card schema, and no interim storage record waits to be adopted.', details };+ const first = interim[0]?.source_id;+ const fix: Action = missingDirs.length+ ? { ask_user: true, consent: [], actor: 'user', requires_exclusive: false, docs: DOCS, why: 'Only the user knows where the shelf repository went (moved, deleted, or on another machine).',+ user_message: `The storage shelf's Git directory is missing: ${missingDirs.join(', ')}. Restore it from its push remote or a backup to the same path, then run gbrain doctor --only storage_manifest again.` }+ : invalid.length+ ? agentFix(['gbrain', 'storage-get', invalid[0]!, '--json'], 'Read-only: shows the card so it can be fixed with gbrain storage-update and its revision.', NAME, { docs: DOCS })+ : agentFix(['gbrain', 'storage', 'adopt', ...(first && first !== 'default' ? ['--source', first] : []), '--json'], 'Read-only preview: the card each interim record maps to and the fields a card refuses; it writes nothing.', NAME, { docs: DOCS });+ return { name: NAME, status: 'warn', message: `Storage shelf: ${problems.join('; ')}.`, details, fix };+ } catch (error) {+ return checkError(NAME, 'read the storage shelf', error, { details: { docs: DOCS } });+ }+}++async function runStorageManifest(ctx: DoctorContext): Promise<Check[]> {+ const checks: Check[] = [];+ checks.push(await storageManifestCheck(connectedEngine(ctx)));+ return checks;+}++export const storageManifestEntry: DoctorEntry = {+ name: 'storage_manifest',+ emits: ['storage_manifest'],+ run: runStorageManifest,+};diff --git a/src/commands/doctor/registry.ts b/src/commands/doctor/registry.tsindex 88f1a8a799..8cd9a19982 100644--- a/src/commands/doctor/registry.ts+++ b/src/commands/doctor/registry.ts@@ -130,6 +130,7 @@ import { chatFallbackChainEntry } from './checks/chat-fallback.ts';import { providerConsentEntry } from './checks/provider-consent.ts';import { behaviorChangesEntry } from './checks/behavior-changes.ts';import { fenceIntegrityEntry } from './checks/fence-integrity.ts';+import { storageManifestEntry } from './checks/storage-manifest.ts';import { outsideContentFencesEntry } from './checks/outside-content-fences.ts';import { dbAheadOfGitEntry } from './checks/db-ahead-of-git.ts';import { gitIndexLagEntry } from './checks/git-index-lag.ts';@@ -327,6 +328,8 @@ export const DOCTOR_CHECK_REGISTRY: readonly DoctorEntry[] = [ownerHostStaleEntry,embeddingPlaneDisagreementEntry,fenceIntegrityEntry,+ // GST-1943: the storage shelf: cards failing the card schema, interim records not adopted, a hosted shelf directory gone.+ storageManifestEntry,searchModeEntry,];diff --git a/src/commands/storage.ts b/src/commands/storage.tsindex ab4587a028..0b9099c229 100644--- a/src/commands/storage.ts+++ b/src/commands/storage.ts@@ -10,7 +10,9 @@ import { shellQuote } from '../core/shell-quote.ts';import { scannerSlugRootMode } from '../core/write-through.ts';import type { SlugRootMode } from '../core/sync-anchor.ts';import { nativeFileTarget } from '../core/persistence/native-file-target.ts';-import { OperationError } from '../core/ops/contract.ts';+import { opError, OperationError, type OperationContext } from '../core/ops/contract.ts';+import { readFix } from '../core/ops/op-fix.ts';+import { setCliExitVerdict } from '../core/cli-force-exit.ts';/*** Distinct nominal types for the two tier-keyed numeric maps. Both shapes@@ -54,6 +56,10 @@ const STORAGE_HELP = `gbrain storage — storage tiers of the brain repo, and thUSAGEgbrain storage [status] [--repo <path>] [--json]gbrain storage init [--dir <path>] [--push-remote <url>] [--dry-run | --expect <plan_hash>] [--json]+ gbrain storage adopt [--source <id>] [--from-prefix <prefix>] [--drop-field <dotted.name>]...+ [--apply --expect <plan_hash> | --finalize [--expect <plan_hash>]] [--json]+ gbrain storage export --jsonl [--out <file>]+ gbrain storage import --jsonl <file> [--apply --expect <plan_hash>] [--json]SUBCOMMANDSstatus (default) Report page counts and disk usage per storage@@ -66,6 +72,22 @@ SUBCOMMANDSGit checkout gets a hosted git-canonical repository under--dir, which needs managed persistence; preview first andapply the printed command after the user agrees.+ adopt Move interim records (type stored-object pages under+ --from-prefix, default storage-manifest/, in --source,+ default default; each with a json block under ## Record)+ onto the shelf. Preview by default; --apply --expect+ registers each card (origin adopt) and tags the original+ storage-manifest-adopted, deleting nothing. Fields a card+ refuses are left out only when named with --drop-field;+ a credential-shaped value always refuses. --finalize+ previews soft-deleting the adopted originals (72 h+ restore window); with --expect it deletes them, only when+ every card matches its original.+ export Write every card as one JSON line, sorted by id, to --out+ (a new file) or stdout.+ import Preview a JSONL export line by line (create, identical,+ conflict, invalid); --apply --expect registers the missing+ cards (origin import) and never overwrites a differing one.THE STORAGE SHELF (separate commands)gbrain storage-find "<phrase>" Find a card; closest cards when none match@@ -97,12 +119,20 @@ export async function runStorage(engine: BrainEngine, args: string[]): Promise<vawait runStorageInit(engine, args.slice(1));return;}+ if (subcommand === 'adopt') {+ await runStorageAdopt(engine, args.slice(1));+ return;+ }+ if (subcommand === 'export' || subcommand === 'import') {+ await runStorageJsonl(engine, subcommand, args.slice(1));+ return;+ }if (['find', 'get', 'list', 'register', 'update'].includes(subcommand)) {console.error(`The storage manifest verbs are their own commands: run gbrain storage-${subcommand} (see gbrain storage-${subcommand} --help).`);process.exit(1);}console.error(`Unknown storage subcommand: ${subcommand}`);- console.error('Available subcommands: status, init');+ console.error('Available subcommands: status, init, adopt, export, import');process.exit(1);}@@ -454,6 +484,129 @@ async function runStorageInit(engine: BrainEngine, args: string[]): Promise<voidif (!(error instanceof OperationError)) throw error;console.log(json ? JSON.stringify({ error: error.code, message: error.message, suggestion: error.suggestion }) : `Refused (${error.code}): ${error.message}Fix: ${error.suggestion ?? ''}`);- process.exitCode = error.code === 'invalid_params' ? 2 : 1;+ setCliExitVerdict(error.code === 'invalid_params' ? 2 : 1);+ }+}++// ── storage adopt / export / import (GST-1943) ─────────────++function flagValue(args: string[], flag: string): string | undefined {+ const i = args.indexOf(flag);+ return i >= 0 ? args[i + 1] : undefined;+}++async function shelfCliContext(engine: BrainEngine, sourceId: string): Promise<OperationContext> {+ const { loadConfig } = await import('../core/config.ts');+ const { resolveCliWriteWaitMs } = await import('../core/persistence/write-wait.ts');+ const config = loadConfig() ?? { engine: engine.kind };+ return { engine, config, remote: false, dryRun: false, sourceId, writeWaitMs: resolveCliWriteWaitMs({ config }),+ logger: { info: () => {}, warn: (m: string) => console.error(m), error: (m: string) => console.error(m) } } as unknown as OperationContext;+}++async function shelfRefusal(error: unknown, json: boolean): Promise<void> {+ if (!(error instanceof OperationError)) throw error;+ const { writeCliError } = await import('../cli/cli-error.ts');+ setCliExitVerdict(writeCliError(error, 'storage', { json }));+}++const argvText = (argv: string[]) => argv.map(shellQuote).join(' ');++function printOutcome(result: { side_effects: string; failure?: { item: string; code: string; message: string }; rerun?: string[] }): void {+ console.log(`Side effects: ${result.side_effects}.`);+ if (!result.failure) return;+ console.log(`Stopped at ${result.failure.item} (${result.failure.code}): ${result.failure.message}`);+ if (result.rerun) console.log(`Rerun after fixing it: ${argvText(result.rerun)}`);+}++async function runStorageAdopt(engine: BrainEngine, args: string[]): Promise<void> {+ const json = args.includes('--json');+ const adopt = await import('../core/storage-manifest/adopt.ts');+ const rawPrefix = (flagValue(args, '--from-prefix') ?? adopt.ADOPT_DEFAULT_PREFIX).trim().toLowerCase();+ const opts = { sourceId: flagValue(args, '--source') ?? adopt.ADOPT_DEFAULT_SOURCE, prefix: rawPrefix.endsWith('/') ? rawPrefix : `${rawPrefix}/` };+ const expect = flagValue(args, '--expect');+ const finalize = args.includes('--finalize');+ const apply = args.includes('--apply');+ const dropFields = args.flatMap((arg, i) => arg === '--drop-field' && args[i + 1] ? [args[i + 1]!] : []);+ try {+ const preview = [...adopt.adoptArgv(opts), ...(finalize ? ['--finalize'] : [])];+ if (opts.prefix === '/') throw opError('invalid_params', '--from-prefix needs a slug prefix such as storage-manifest/.', 'Pass the folder the interim pages live under, or omit --from-prefix for storage-manifest/.');+ if (apply && finalize) throw opError('invalid_params', '--apply and --finalize are separate steps.', 'Apply the adopt first; finalize afterwards with gbrain storage adopt --finalize, then its --expect value.');+ if ((apply && !expect) || (expect && !apply && !finalize)) {+ throw opError('invalid_params', 'An apply needs both --apply and the --expect value its preview printed.', 'Preview without --apply, then run the apply command the preview prints after the user agrees.',+ { fix: readFix('Prints the plan and its plan_hash; changes nothing.', { argv: [...preview, '--json'] }) });+ }+ const ctx = await shelfCliContext(engine, opts.sourceId);+ const result = finalize+ ? expect ? await adopt.applyFinalize(ctx, { ...opts, expect }) : await adopt.previewFinalize(ctx, opts)+ : expect ? await adopt.applyAdopt(ctx, { ...opts, expect, dropFields }) : await adopt.previewAdopt(ctx, opts);+ if (!result.dry_run && (result.failure || (result.action === 'adopt' && result.conflicts.length))) setCliExitVerdict(1);+ if (json) { console.log(JSON.stringify(result)); return; }+ if (result.dry_run) {+ for (const line of result.summary) console.log(line);+ for (const entry of result.entries) {+ const extra = 'refused' in entry ? [...entry.refused.map((f) => `${f.field} refused (${f.reason})`), ...(entry.problem ? [entry.problem.message] : [])] : [];+ console.log(` ${entry.state.padEnd(11)} ${entry.slug}${entry.card_id ? ` -> ${entry.card_id}` : ''}${extra.length ? `: ${extra.join('; ')}` : ''}`);+ }+ console.log(`plan_hash: ${result.plan_hash}`);+ if (result.apply) console.log(`Apply (after the user agrees): ${argvText(result.apply)}`);+ return;+ }+ if (result.action === 'adopt') {+ for (const row of result.results) console.log(` ${row.outcome.padEnd(10)} ${row.slug}${row.card_id ? ` -> ${row.card_id}` : ''}`);+ if (result.conflicts.length) console.log(`Conflicts (a different card with that id is on the shelf; nothing was overwritten): ${result.conflicts.join(', ')}`);+ printOutcome(result);+ if (result.finalize) console.log(`Originals are kept. Preview deleting them: ${argvText(result.finalize)}`);+ return;+ }+ console.log(`Soft-deleted ${result.deleted.length} original(s) (restorable for 72 hours with gbrain restore).`);+ printOutcome(result);+ } catch (error) {+ await shelfRefusal(error, json);+ }+}++async function runStorageJsonl(engine: BrainEngine, subcommand: 'export' | 'import', args: string[]): Promise<void> {+ const json = args.includes('--json');+ const jsonl = await import('../core/storage-manifest/jsonl.ts');+ const { readFileSync, writeFileSync } = await import('fs');+ try {+ if (!args.includes('--jsonl')) throw opError('invalid_params', `gbrain storage ${subcommand} reads and writes JSONL only, so it needs --jsonl.`,+ subcommand === 'export' ? 'Run gbrain storage export --jsonl, adding --out with a new file path to write a file.' : 'Run gbrain storage import --jsonl with the path of an export file.');+ if (subcommand === 'export') {+ const out = flagValue(args, '--out');+ if (out && existsSync(out)) throw opError('invalid_params', `${out} already exists; export never overwrites a file.`, 'Pass --out with a path that does not exist yet, or omit --out to write to stdout.');+ const { lines, skipped } = await jsonl.exportShelfJsonl(engine);+ const text = lines.length ? `${lines.join('\n')}\n` : '';+ if (!out) { process.stdout.write(text); }+ else { writeFileSync(out, text, { flag: 'wx' }); console.error(`Wrote ${lines.length} card(s) to ${out}.`); }+ if (skipped.length) console.error(`Skipped ${skipped.length} page(s) on the shelf that hold no card: ${skipped.join(', ')}`);+ return;+ }+ const file = flagValue(args, '--jsonl');+ if (!file || file.startsWith('--')) throw opError('invalid_params', 'gbrain storage import needs the JSONL file after --jsonl.', 'Run gbrain storage import --jsonl with the path of a file gbrain storage export wrote.');+ if (!existsSync(file)) throw opError('invalid_params', `No file at ${file}.`, 'Pass --jsonl with the path of a file gbrain storage export wrote.');+ const text = readFileSync(file, 'utf8');+ const expect = flagValue(args, '--expect');+ if (args.includes('--apply') !== (expect !== undefined)) throw opError('invalid_params', 'An import apply needs both --apply and the --expect value its preview printed.',+ 'Preview without --apply, then run the apply command the preview prints after the user agrees.',+ { fix: readFix('Prints the import plan and its plan_hash; writes nothing.', { argv: ['gbrain', 'storage', 'import', '--jsonl', file, '--json'] }) });+ if (expect !== undefined) {+ const result = await jsonl.applyImport(await shelfCliContext(engine, 'default'), file, text, expect);+ if (result.failure || result.conflicts.length || result.invalid.length) setCliExitVerdict(1);+ if (json) { console.log(JSON.stringify(result)); return; }+ console.log(`Created ${result.created.length} card(s); ${result.identical.length} already on the shelf.`);+ if (result.conflicts.length) console.log(`Conflicts (a different card with that id is on the shelf; nothing was overwritten): ${result.conflicts.join(', ')}`);+ if (result.invalid.length) console.log(`Invalid lines skipped: ${result.invalid.join(', ')}`);+ printOutcome(result);+ return;+ }+ const { cards: _cards, ...plan } = await jsonl.previewImport(engine, file, text);+ if (json) { console.log(JSON.stringify(plan)); return; }+ for (const line of plan.summary) console.log(line);+ for (const line of plan.lines) console.log(` line ${String(line.line).padEnd(5)} ${line.action.padEnd(9)} ${line.id ?? ''}${line.message ? `: ${line.message}` : ''}`);+ console.log(`plan_hash: ${plan.plan_hash}`);+ if (plan.apply) console.log(`Apply (after the user agrees): ${argvText(plan.apply)}`);+ } catch (error) {+ await shelfRefusal(error, json);}}diff --git a/src/core/cli-flag-registry.generated.ts b/src/core/cli-flag-registry.generated.tsindex e8bb6942fa..54eda85623 100644--- a/src/core/cli-flag-registry.generated.ts+++ b/src/core/cli-flag-registry.generated.ts@@ -52,7 +52,7 @@ export const CLI_FLAG_REGISTRY: Record<string, readonly string[]> = {'db-repair': ['--accept-pending', '--apply', '--apply-rewrites', '--as', '--background', '--brain', '--break-lock', '--db-url', '--dry-run', '--explain', '--filter', '--follow', '--force', '--force-retry', '--format', '--help', '--http', '--json', '--legacy-lock', '--locks', '--name', '--no-accept-pending', '--path', '--prefer-postgres', '--probe', '--progress-interval', '--progress-json', '--quiet', '--remediate', '--restart', '--skip-verify', '--source', '--statement-timeout', '--supabase', '--timeout', '--timings', '--undo-last-rewrite', '--url', '--version', '--wait', '--yes'],'decide': ['--accept-all', '--all', '--all-from', '--apply', '--brain', '--call-site', '--claims', '--dataset', '--dry-run', '--egress', '--embedding-dimensions', '--embedding-model', '--expect', '--from', '--help', '--include-withdrawals', '--input', '--items-out', '--json', '--kind', '--limit', '--max-cost', '--max-usd', '--min', '--non-interactive', '--out', '--provenance', '--provider', '--query', '--rate', '--reason', '--reason-family', '--recommended', '--remove', '--shadow', '--since', '--slot', '--source', '--status', '--suite', '--target', '--threshold', '--trust', '--undo', '--uri-prefix', '--version', '--what-if-threshold', '--yes'],'diag': ['--access', '--add', '--all', '--allowed-operations', '--apply', '--as', '--asof', '--body', '--bound-slug-prefixes', '--brain', '--budget-ms', '--card', '--client', '--count', '--cursor', '--date', '--dated-since', '--days', '--detach', '--entities', '--expect', '--expected-revision', '--federated-read', '--follow', '--format', '--from-index', '--full', '--fuzzy', '--group-by', '--held', '--help', '--http', '--id', '--include', '--include-ambiguous', '--include-deleted', '--json', '--kind', '--limit', '--max-usd', '--model', '--multimodal', '--no-autopilot-install', '--no-pull', '--no-walk', '--of', '--only', '--page', '--params', '--path', '--phase', '--prefer', '--preview', '--purge', '--query', '--recent', '--refresh-operations', '--replace', '--restart-only', '--reverse', '--row', '--scopes', '--session', '--side', '--since', '--slug', '--slugs', '--source', '--source-id', '--sources', '--stale', '--state', '--surface', '--to', '--updated-after', '--url', '--yes'],- 'doctor': ['--abandon', '--abbrev-ref', '--absolute-git-dir', '--accept-all', '--accept-capabilities', '--accept-pending', '--access', '--access-policy', '--account', '--acknowledge-managed', '--add', '--admin-intent', '--adopt', '--adopt-columns', '--adopt-permissions', '--advertise', '--after', '--aggressive', '--aliases', '--all', '--all-drifted', '--all-from', '--allow-old-serve', '--allow-outside-source-root', '--allow-shell-jobs', '--allow-unverified-remote', '--allowed-operations', '--applied', '--apply', '--apply-rewrites', '--approval-out', '--approved', '--as', '--assign-corpus', '--attest-actor', '--attest-ops', '--attest-sources', '--audit', '--auto', '--auto-additive', '--auto-fix', '--autostash', '--background', '--base', '--batch', '--batch-check', '--bound-brain', '--bound-max-concurrent', '--bound-slug-prefixes', '--bound-source', '--bound-tools', '--brain', '--branch', '--break-lock', '--budget-ms', '--budget-policy', '--budget-tokens', '--budget-usd', '--by-mention', '--cached', '--cacheinfo', '--call-site', '--catch-up', '--channel', '--check', '--check-downgrade', '--check-only', '--cherry-mark', '--claims', '--class', '--clear', '--clear-never-installed', '--cli-socket', '--client', '--close', '--code', '--concurrency', '--confidence', '--confirm', '--confirm-destructive', '--confirm-quiesced', '--confirm-relocated-root', '--conflicts', '--contacts-dir', '--content-audit', '--content-root', '--continue', '--conversation', '--count', '--credentials-file', '--cursor', '--cwd', '--dataset', '--day', '--db-url', '--deadline', '--decisions', '--delegated-namespace', '--delegated-slug-prefixes', '--delete-brain', '--dest', '--detach', '--detail', '--diff-filter', '--dim', '--dimensions', '--dir', '--disable', '--drain', '--drain-timeout', '--dry-run', '--egress', '--embedding-dimensions', '--embedding-model', '--enable', '--enable-dcr', '--end-of-options', '--entity', '--env', '--error-unmatch', '--exclude', '--exclude-standard', '--exit-code', '--expand', '--expect', '--expect-local', '--expect-remote', '--expect-upstream', '--expected-epoch', '--expected-revision', '--expected-state', '--explain', '--facts', '--fast', '--federated', '--federated-read', '--fetch-timeout-ms', '--ff-only', '--file', '--first-parent', '--fix', '--follow', '--force', '--force-break-lock', '--force-rechunk', '--force-remove', '--force-retry', '--force-schema', '--force-with-lease', '--format', '--fresh', '--fresh-token', '--from', '--from-meetings', '--from-pages', '--full', '--full-tree', '--fuzzy', '--gbrain-bin', '--generation', '--get', '--get-all', '--get-url', '--git-common-dir', '--git-dir', '--git-path', '--grammar', '--group', '--group-by', '--hard', '--hard-deadline', '--harness', '--held', '--help', '--hold-state', '--holds', '--home', '--http', '--id', '--if-version', '--ignore-env-override', '--ignore-missing', '--images', '--include-ambiguous', '--include-cross-entity', '--include-deleted', '--include-failures', '--include-flagged', '--include-frontmatter', '--include-gitignored', '--include-hidden', '--include-pseudo', '--include-repairs', '--include-withdrawals', '--index-audit', '--index-info', '--infer-dates', '--init', '--input', '--install', '--instructions', '--instructions-only', '--is-ancestor', '--is-bare-repository', '--is-inside-work-tree', '--is-shallow-repository', '--items-out', '--job-isolation', '--jq', '--json', '--keep', '--keep-checkout', '--key', '--kind', '--lanes', '--lang', '--left-right', '--legacy-lock', '--limit', '--link', '--link-source', '--link-type', '--list', '--list-out', '--literal-pathspecs', '--local', '--local-env-vars', '--locks', '--log-noop', '--manifest', '--markdown', '--max-cost', '--max-cost-usd', '--max-count', '--max-facts', '--max-jobs', '--max-requests', '--max-rss', '--max-runtime', '--max-usd', '--max-waiting', '--may-act-for', '--mcp-only', '--member', '--merge-base', '--migrate-legacy', '--migrate-only', '--migration', '--min', '--min-n', '--mode', '--model', '--multimodal', '--name', '--name-only', '--name-status', '--nice', '--no-accept-pending', '--no-autopilot-install', '--no-autostash', '--no-capture', '--no-commit-id', '--no-confirm', '--no-cron', '--no-delegate', '--no-edit', '--no-embed', '--no-embed-cache', '--no-embedding', '--no-expand', '--no-extract', '--no-federated', '--no-filters', '--no-gpg-sign', '--no-hooks', '--no-instructions', '--no-lanes', '--no-llm', '--no-merges', '--no-migrate', '--no-probe', '--no-pull', '--no-renames', '--no-repair', '--no-restart', '--no-schema-pack', '--no-seat', '--no-tags', '--no-verify', '--no-walk', '--no-write-fetch-head', '--non-interactive', '--not', '--now', '--of', '--older-than', '--once', '--only', '--operation', '--operations', '--others', '--out', '--output', '--oversized', '--overwrite', '--page', '--parallel', '--params', '--parents', '--parked-code', '--parked-pushes', '--pat-file', '--path', '--path-format', '--pending', '--pglite', '--phase', '--pid-file', '--plan', '--porcelain', '--port', '--prefer', '--prefer-postgres', '--prefix', '--preset', '--preview', '--principal', '--private-pages', '--probe', '--probe-pglite', '--profile', '--progress-interval', '--progress-json', '--project', '--provenance', '--provider', '--providers', '--prune-orphans', '--public-url', '--pull', '--pure', '--purge', '--push', '--push-only', '--qm', '--query', '--question', '--queue', '--quiet', '--rate', '--reader-mode', '--readers', '--reauth', '--rebase', '--rebuild', '--recommended', '--redact-paths', '--reference-date', '--refresh', '--refresh-operations', '--refresh-skills', '--regenerate', '--reissue', '--relative', '--relower', '--remediate', '--remediation-plan', '--remote', '--remove', '--remove-core', '--repair', '--repair-unknown-markers', '--replace', '--repo', '--request', '--request-id', '--require-clean', '--reranker', '--reset', '--reset-checkpoint', '--reset-default', '--resolve', '--restart-only', '--restore-only', '--resume', '--retire', '--retry-failed', '--retry-global', '--retry-held', '--retry-parked', '--reverse', '--review-lower', '--revision', '--right-only', '--rollback-to-source', '--root', '--rules', '--run', '--runtime', '--sample', '--save', '--scope', '--scopes', '--search-mode', '--seat', '--section', '--segmented', '--select', '--self-transfer', '--semantic', '--session', '--session-id', '--set', '--set-upstream-to', '--shadow', '--shared-skills', '--short', '--show-current', '--show-object-format', '--show-prefix', '--show-token', '--show-toplevel', '--side', '--since', '--since-last-run', '--skill-loading', '--skills-dir', '--skills-index-only', '--skip', '--skip-bare-tweet', '--skip-failed', '--skip-urls', '--skip-verify', '--slot', '--slot-a-model', '--slot-b-model', '--slot-c-model', '--slug', '--slugs', '--source', '--source-id', '--source-ids', '--sources', '--squash', '--src-subpath', '--staged', '--stale', '--stat', '--state', '--statement-timeout', '--status', '--stdin', '--stop-mcp', '--strategy', '--strict', '--suite', '--supabase', '--surface', '--swap-only', '--symbol-kind', '--symbolic-full-name', '--takes-holders', '--target', '--target-score', '--threshold', '--tier', '--timeout', '--timings', '--to', '--token', '--token-ttl', '--top-k', '--topo-order', '--trust', '--type', '--types', '--unindexed', '--uninstall', '--unsafe-bypass-dream-guard', '--unset', '--unset-all', '--unsettle', '--unshallow', '--untracked-files', '--url', '--url-env', '--user', '--vacuum', '--vectors', '--verbose', '--verify', '--version', '--wait', '--wait-drain', '--warn-only', '--watch', '--what-if-threshold', '--window', '--workers', '--working-tree', '--workspace', '--worktree', '--write-tree', '--yes'],+ 'doctor': ['--abandon', '--abbrev-ref', '--absolute-git-dir', '--accept-all', '--accept-capabilities', '--accept-pending', '--access', '--access-policy', '--account', '--acknowledge-managed', '--add', '--admin-intent', '--adopt', '--adopt-columns', '--adopt-permissions', '--advertise', '--after', '--aggressive', '--aliases', '--all', '--all-drifted', '--all-from', '--allow-old-serve', '--allow-outside-source-root', '--allow-shell-jobs', '--allow-unverified-remote', '--allowed-operations', '--applied', '--apply', '--apply-rewrites', '--approval-out', '--approved', '--as', '--assign-corpus', '--attest-actor', '--attest-ops', '--attest-sources', '--audit', '--auto', '--auto-additive', '--auto-fix', '--autostash', '--background', '--base', '--batch', '--batch-check', '--bound-brain', '--bound-max-concurrent', '--bound-slug-prefixes', '--bound-source', '--bound-tools', '--brain', '--branch', '--break-lock', '--budget-ms', '--budget-policy', '--budget-tokens', '--budget-usd', '--by-mention', '--cached', '--cacheinfo', '--call-site', '--catch-up', '--channel', '--check', '--check-downgrade', '--check-only', '--cherry-mark', '--claims', '--class', '--clear', '--clear-never-installed', '--cli-socket', '--client', '--close', '--code', '--concurrency', '--confidence', '--confirm', '--confirm-destructive', '--confirm-quiesced', '--confirm-relocated-root', '--conflicts', '--contacts-dir', '--content-audit', '--content-root', '--continue', '--conversation', '--count', '--credentials-file', '--cursor', '--cwd', '--dataset', '--day', '--db-url', '--deadline', '--decisions', '--delegated-namespace', '--delegated-slug-prefixes', '--delete-brain', '--dest', '--detach', '--detail', '--diff-filter', '--dim', '--dimensions', '--dir', '--disable', '--drain', '--drain-timeout', '--drop-field', '--dry-run', '--egress', '--embedding-dimensions', '--embedding-model', '--enable', '--enable-dcr', '--end-of-options', '--entity', '--env', '--error-unmatch', '--exclude', '--exclude-standard', '--exit-code', '--expand', '--expect', '--expect-local', '--expect-remote', '--expect-upstream', '--expected-epoch', '--expected-revision', '--expected-state', '--explain', '--facts', '--fast', '--federated', '--federated-read', '--fetch-timeout-ms', '--ff-only', '--file', '--finalize', '--first-parent', '--fix', '--follow', '--force', '--force-break-lock', '--force-rechunk', '--force-remove', '--force-retry', '--force-schema', '--force-with-lease', '--format', '--fresh', '--fresh-token', '--from', '--from-meetings', '--from-pages', '--from-prefix', '--full', '--full-tree', '--fuzzy', '--gbrain-bin', '--generation', '--get', '--get-all', '--get-url', '--git-common-dir', '--git-dir', '--git-path', '--grammar', '--group', '--group-by', '--hard', '--hard-deadline', '--harness', '--held', '--help', '--hold-state', '--holds', '--home', '--http', '--id', '--if-version', '--ignore-env-override', '--ignore-missing', '--images', '--include-ambiguous', '--include-cross-entity', '--include-deleted', '--include-failures', '--include-flagged', '--include-frontmatter', '--include-gitignored', '--include-hidden', '--include-pseudo', '--include-repairs', '--include-withdrawals', '--index-audit', '--index-info', '--infer-dates', '--init', '--input', '--install', '--instructions', '--instructions-only', '--is-ancestor', '--is-bare-repository', '--is-inside-work-tree', '--is-shallow-repository', '--items-out', '--job-isolation', '--jq', '--json', '--keep', '--keep-checkout', '--key', '--kind', '--lanes', '--lang', '--left-right', '--legacy-lock', '--limit', '--link', '--link-source', '--link-type', '--list', '--list-out', '--literal-pathspecs', '--local', '--local-env-vars', '--locks', '--log-noop', '--manifest', '--markdown', '--max-cost', '--max-cost-usd', '--max-count', '--max-facts', '--max-jobs', '--max-requests', '--max-rss', '--max-runtime', '--max-usd', '--max-waiting', '--may-act-for', '--mcp-only', '--member', '--merge-base', '--migrate-legacy', '--migrate-only', '--migration', '--min', '--min-n', '--mode', '--model', '--multimodal', '--name', '--name-only', '--name-status', '--nice', '--no-accept-pending', '--no-autopilot-install', '--no-autostash', '--no-capture', '--no-commit-id', '--no-confirm', '--no-cron', '--no-delegate', '--no-edit', '--no-embed', '--no-embed-cache', '--no-embedding', '--no-expand', '--no-extract', '--no-federated', '--no-filters', '--no-gpg-sign', '--no-hooks', '--no-instructions', '--no-lanes', '--no-llm', '--no-merges', '--no-migrate', '--no-probe', '--no-pull', '--no-renames', '--no-repair', '--no-restart', '--no-schema-pack', '--no-seat', '--no-tags', '--no-verify', '--no-walk', '--no-write-fetch-head', '--non-interactive', '--not', '--now', '--of', '--older-than', '--once', '--only', '--operation', '--operations', '--others', '--out', '--output', '--oversized', '--overwrite', '--page', '--parallel', '--params', '--parents', '--parked-code', '--parked-pushes', '--pat-file', '--path', '--path-format', '--pending', '--pglite', '--phase', '--pid-file', '--plan', '--porcelain', '--port', '--prefer', '--prefer-postgres', '--prefix', '--preset', '--preview', '--principal', '--private-pages', '--probe', '--probe-pglite', '--profile', '--progress-interval', '--progress-json', '--project', '--provenance', '--provider', '--providers', '--prune-orphans', '--public-url', '--pull', '--pure', '--purge', '--push', '--push-only', '--push-remote', '--qm', '--query', '--question', '--queue', '--quiet', '--rate', '--reader-mode', '--readers', '--reauth', '--rebase', '--rebuild', '--recommended', '--redact-paths', '--reference-date', '--refresh', '--refresh-operations', '--refresh-skills', '--regenerate', '--reissue', '--relative', '--relower', '--remediate', '--remediation-plan', '--remote', '--remove', '--remove-core', '--repair', '--repair-unknown-markers', '--replace', '--repo', '--request', '--request-id', '--require-clean', '--reranker', '--reset', '--reset-checkpoint', '--reset-default', '--resolve', '--restart-only', '--restore-only', '--resume', '--retire', '--retry-failed', '--retry-global', '--retry-held', '--retry-parked', '--reverse', '--review-lower', '--revision', '--right-only', '--rollback-to-source', '--root', '--rules', '--run', '--runtime', '--sample', '--save', '--scope', '--scopes', '--search-mode', '--seat', '--section', '--segmented', '--select', '--self-transfer', '--semantic', '--session', '--session-id', '--set', '--set-upstream-to', '--shadow', '--shared-skills', '--short', '--show-current', '--show-object-format', '--show-prefix', '--show-token', '--show-toplevel', '--side', '--since', '--since-last-run', '--skill-loading', '--skills-dir', '--skills-index-only', '--skip', '--skip-bare-tweet', '--skip-failed', '--skip-urls', '--skip-verify', '--slot', '--slot-a-model', '--slot-b-model', '--slot-c-model', '--slug', '--slugs', '--source', '--source-id', '--source-ids', '--sources', '--squash', '--src-subpath', '--staged', '--stale', '--stat', '--state', '--statement-timeout', '--status', '--stdin', '--stop-mcp', '--strategy', '--strict', '--suite', '--supabase', '--surface', '--swap-only', '--symbol-kind', '--symbolic-full-name', '--takes-holders', '--target', '--target-score', '--threshold', '--tier', '--timeout', '--timings', '--to', '--token', '--token-ttl', '--top-k', '--topo-order', '--trust', '--type', '--types', '--unindexed', '--uninstall', '--unsafe-bypass-dream-guard', '--unset', '--unset-all', '--unsettle', '--unshallow', '--untracked-files', '--url', '--url-env', '--user', '--vacuum', '--vectors', '--verbose', '--verify', '--version', '--wait', '--wait-drain', '--warn-only', '--watch', '--what-if-threshold', '--window', '--workers', '--working-tree', '--workspace', '--worktree', '--write-tree', '--yes'],'dream': ['--audit-rejects', '--brain', '--cancel-unmatched', '--date', '--dir', '--drain', '--dry-run', '--eval-run', '--force', '--from', '--help', '--input', '--install', '--json', '--limit', '--list', '--max-usd', '--once', '--phase', '--probe', '--pull', '--reconcile-queue', '--since', '--source', '--source-id', '--threshold', '--to', '--unsafe-bypass-dream-guard', '--window', '--yes'],'edge-proposals': ['--access', '--add', '--all', '--all-applied', '--all-held', '--allowed-operations', '--as', '--asof', '--body', '--bound-slug-prefixes', '--brain', '--card', '--client', '--cursor', '--date', '--dated-since', '--days', '--entities', '--expected-revision', '--federated-read', '--follow', '--from-index', '--full', '--fuzzy', '--group-by', '--help', '--http', '--id', '--include', '--include-deleted', '--json', '--kind', '--limit', '--max-usd', '--model', '--multimodal', '--no-autopilot-install', '--of', '--only', '--page', '--params', '--path', '--phase', '--prefer', '--purge', '--recent', '--refresh-operations', '--row', '--scopes', '--session', '--since', '--slugs', '--source', '--sources', '--stale', '--status', '--surface', '--to', '--updated-after', '--url', '--yes'],'edges-backfill': ['--all-sources', '--brain', '--concurrency', '--help', '--json', '--max-chunks', '--source', '--workers'],@@ -81,7 +81,7 @@ export const CLI_FLAG_REGISTRY: Record<string, readonly string[]> = {'init': ['--abandon', '--absolute-git-dir', '--accept-all', '--accept-capabilities', '--access', '--access-policy', '--acknowledge-managed', '--adopt', '--advertise', '--after', '--aliases', '--all', '--all-drifted', '--allow-create-db', '--allow-docker', '--allow-outside-source-root', '--applied', '--apply', '--approval-out', '--approved', '--as', '--assign-corpus', '--attest-actor', '--attest-ops', '--attest-sources', '--audit', '--auto', '--auto-additive', '--background', '--base', '--batch', '--bound-slug-prefixes', '--brain', '--branch', '--break-lock', '--budget-ms', '--budget-policy', '--budget-tokens', '--budget-usd', '--by-mention', '--catch-up', '--channel', '--chat-model', '--check', '--check-downgrade', '--class', '--clear', '--clear-never-installed', '--cli-socket', '--client', '--close', '--code', '--confirm-quiesced', '--confirm-relocated-root', '--conflicts', '--content-root', '--continue', '--conversation', '--cursor', '--db-only', '--deadline', '--decisions', '--dest', '--detach', '--detail', '--dim', '--disable', '--drain', '--embedding-dimensions', '--embedding-model', '--enable', '--entity', '--exclude', '--expand', '--expansion-model', '--expect', '--expect-local', '--expect-remote', '--expect-upstream', '--explain', '--facts', '--fast', '--federated', '--file', '--fix', '--force', '--force-retry', '--format', '--fresh-token', '--from', '--from-meetings', '--full', '--git', '--grammar', '--grant-types', '--group-by', '--harness', '--held', '--help', '--hold-state', '--holds', '--http', '--id', '--images', '--include-ambiguous', '--include-cross-entity', '--include-frontmatter', '--include-gitignored', '--include-hidden', '--infer-dates', '--input', '--install', '--instructions-only', '--issuer-url', '--job-isolation', '--json', '--keep', '--keep-checkout', '--key', '--kind', '--lanes', '--legacy-lock', '--limit', '--link', '--list', '--list-out', '--local', '--local-postgres', '--markdown', '--max-cost-usd', '--max-facts', '--max-requests', '--max-rss', '--max-usd', '--may-act-for', '--mcp-only', '--mcp-url', '--member', '--migrate-only', '--migration', '--min-n', '--mode', '--model', '--no-autopilot-install', '--no-autostash', '--no-delegate', '--no-embed', '--no-embedding', '--no-expand', '--no-extract', '--no-federated', '--no-filters', '--no-git', '--no-hooks', '--no-instructions', '--no-lanes', '--no-llm', '--no-probe', '--no-pull', '--no-renames', '--no-repair', '--no-restart', '--no-schema-pack', '--no-verify', '--non-interactive', '--oauth-client-id', '--oauth-client-secret', '--of', '--older-than', '--once', '--only', '--operation', '--output', '--oversized', '--page', '--params', '--parked-code', '--parked-pushes', '--pat-file', '--path', '--pending', '--pglite', '--phase', '--plan', '--prefer', '--prefer-postgres', '--prefix', '--preview', '--private-pages', '--probe', '--profile', '--provenance', '--providers', '--pull', '--purge', '--push-only', '--qm', '--query', '--question', '--quiet', '--readers', '--rebase', '--rebuild', '--redact-paths', '--reference-date', '--remediate', '--remote', '--remove', '--repair', '--repair-unknown-markers', '--repo', '--request', '--request-id', '--require-clean', '--reset', '--resolve', '--restart-only', '--resume', '--retire', '--retry-failed', '--retry-parked', '--runtime', '--save', '--schema-pack', '--scope', '--scopes', '--search-mode', '--section', '--segmented', '--self-transfer', '--semantic', '--session', '--session-id', '--shared-skills', '--show-toplevel', '--side', '--since', '--since-last-run', '--skip', '--skip-embed-check', '--skip-failed', '--slug', '--slugs', '--source', '--source-id', '--sources', '--squash', '--src-subpath', '--stale', '--state', '--status', '--stdin', '--stop-mcp', '--strategy', '--supabase', '--surface', '--swap-only', '--tier', '--timeout', '--to', '--token', '--touchpoint', '--type', '--types', '--uninstall', '--unsettle', '--url', '--url-env', '--user', '--vacuum', '--verbose', '--version', '--wait', '--warn-only', '--watch', '--working-tree', '--workspace', '--yes'],'integrations': ['--auto', '--brain', '--dry-run', '--help', '--json', '--overwrite', '--refresh', '--source', '--target'],'integrity': ['--accept-pending', '--as', '--auto', '--backend', '--background', '--body', '--brain', '--check', '--confidence', '--cost', '--dry-run', '--explain', '--follow', '--fresh', '--help', '--json', '--limit', '--no-accept-pending', '--progress-interval', '--progress-json', '--quiet', '--review-lower', '--skip-bare-tweet', '--skip-urls', '--source', '--timeout', '--timings', '--type', '--wait'],- 'jobs': ['--abbrev-ref', '--access', '--access-policy', '--account', '--acknowledge-managed', '--add', '--admin-intent', '--adopt-slug-path', '--aliases', '--all', '--all-sources', '--allow-empty', '--allow-shell-jobs', '--allowed-operations', '--apply', '--approval-out', '--approved', '--as', '--asof', '--assign-corpus', '--attest-actor', '--attest-ops', '--auto', '--background', '--backoff-delay', '--backoff-jitter', '--backoff-type', '--base', '--batch-size', '--body', '--bound-slug-prefixes', '--brain', '--break-lock', '--budget-ms', '--by-mention', '--cached', '--card', '--catch-up', '--channel', '--check', '--check-downgrade', '--check-only', '--clear', '--cli-path', '--client', '--close', '--cluster-errors', '--code', '--concurrency', '--confidence', '--confirm-destructive', '--confirm-relocated-root', '--cost-estimate', '--cursor', '--date', '--dated-since', '--days', '--decisions', '--delay', '--detach', '--detail', '--diff-filter', '--dir', '--drain', '--drain-timeout', '--dry-run', '--embedding-dimensions', '--embedding-model', '--empty', '--enable', '--entities', '--exclude', '--exclude-standard', '--expect', '--expect-local', '--expect-upstream', '--expected-revision', '--expected-state', '--explain', '--facts', '--federated-read', '--ff-only', '--file', '--filters', '--finished-since', '--first-parent', '--fix', '--follow', '--force', '--force-break-lock', '--force-retry', '--force-schema', '--format', '--fresh', '--from-index', '--from-meetings', '--full', '--full-history', '--fuzzy', '--git', '--grammar', '--grammar-diagnostics', '--group', '--group-by', '--hard-deadline', '--health-interval', '--held', '--help', '--hold-state', '--http', '--id', '--idempotency-key', '--ids', '--images', '--include', '--include-ambiguous', '--include-deleted', '--include-frontmatter', '--include-gitignored', '--include-hidden', '--include-null-signature', '--infer-dates', '--inject-bootstrap', '--inline', '--input', '--install', '--interval', '--is-ancestor', '--is-shallow-repository', '--job-id', '--job-isolation', '--json', '--keep', '--kind', '--lanes', '--legacy-lock', '--limit', '--list', '--local', '--lock-duration-ms', '--log-noop', '--markdown', '--max-age', '--max-attempts', '--max-cost', '--max-cost-usd', '--max-crashes', '--max-rss', '--max-sources', '--max-stalled', '--max-usd', '--max-waiting', '--may-act-for', '--mcp-only', '--member', '--migration', '--min-context', '--missing-path', '--mode', '--model', '--multimodal', '--name', '--name-only', '--ner', '--nice', '--no-auto-embed', '--no-autopilot-install', '--no-bulk', '--no-confirm', '--no-delegate', '--no-embed', '--no-embedding', '--no-extract', '--no-gpg-sign', '--no-hard-deadline', '--no-inject', '--no-lanes', '--no-llm', '--no-pull', '--no-renames', '--no-repair', '--no-restart', '--no-schema-pack', '--no-verify', '--no-worker', '--non-interactive', '--now', '--of', '--older-than', '--once', '--only', '--order', '--others', '--output', '--override-disabled', '--oversized', '--pace', '--pace-max-concurrency', '--pack', '--page', '--parallel', '--params', '--parked-code', '--pat-file', '--path', '--pause', '--pglite', '--phase', '--pid-file', '--plan', '--port', '--prefer', '--preview', '--priority', '--probe', '--prune-orphans', '--pull', '--purge', '--qm', '--question', '--queue', '--queue-only', '--quiet', '--rate', '--reason', '--reason-scan-limit', '--rebuild', '--recent', '--record', '--redact-paths', '--redact-secrets', '--reenrich-after', '--refresh-ms', '--refresh-operations', '--remediate', '--repo', '--request-id', '--reset-checkpoint', '--restart-only', '--resume', '--retry-failed', '--retry-global', '--retry-held', '--retry-parked', '--review-lower', '--row', '--save', '--scope', '--scopes', '--section', '--segment-limit', '--segmented', '--select', '--self-transfer', '--serial', '--session', '--show-toplevel', '--side', '--sigkill-rescue', '--since', '--skip', '--skip-bare-tweet', '--skip-failed', '--skip-urls', '--sleep', '--slug', '--slugs', '--source', '--source-guard', '--source-id', '--sources', '--src-subpath', '--staged', '--stale', '--state', '--statement-timeout', '--status', '--stop-mcp', '--strategy', '--suites', '--surface', '--swap-only', '--target', '--thin', '--thin-threshold', '--tier', '--timeout', '--timeout-ms', '--to', '--token', '--token-env', '--trust', '--type', '--types', '--uninstall', '--updated-after', '--url', '--user', '--vectors', '--verbose', '--verify', '--version', '--watch', '--wedge-rescue', '--workers', '--working-tree', '--yes'],+ 'jobs': ['--abbrev-ref', '--access', '--access-policy', '--account', '--acknowledge-managed', '--add', '--admin-intent', '--adopt-slug-path', '--aliases', '--all', '--all-sources', '--allow-empty', '--allow-shell-jobs', '--allowed-operations', '--apply', '--approval-out', '--approved', '--as', '--asof', '--assign-corpus', '--attest-actor', '--attest-ops', '--auto', '--background', '--backoff-delay', '--backoff-jitter', '--backoff-type', '--base', '--batch-size', '--body', '--bound-slug-prefixes', '--brain', '--break-lock', '--budget-ms', '--by-mention', '--cached', '--card', '--catch-up', '--channel', '--check', '--check-downgrade', '--check-only', '--clear', '--cli-path', '--client', '--close', '--cluster-errors', '--code', '--concurrency', '--confidence', '--confirm-destructive', '--confirm-relocated-root', '--cost-estimate', '--cursor', '--date', '--dated-since', '--days', '--decisions', '--delay', '--detach', '--detail', '--diff-filter', '--dir', '--drain', '--drain-timeout', '--drop-field', '--dry-run', '--embedding-dimensions', '--embedding-model', '--empty', '--enable', '--entities', '--exclude', '--exclude-standard', '--expect', '--expect-local', '--expect-upstream', '--expected-revision', '--expected-state', '--explain', '--facts', '--federated-read', '--ff-only', '--file', '--filters', '--finalize', '--finished-since', '--first-parent', '--fix', '--follow', '--force', '--force-break-lock', '--force-retry', '--force-schema', '--format', '--fresh', '--from-index', '--from-meetings', '--full', '--full-history', '--fuzzy', '--git', '--grammar', '--grammar-diagnostics', '--group', '--group-by', '--hard-deadline', '--health-interval', '--held', '--help', '--hold-state', '--http', '--id', '--idempotency-key', '--ids', '--images', '--include', '--include-ambiguous', '--include-deleted', '--include-frontmatter', '--include-gitignored', '--include-hidden', '--include-null-signature', '--infer-dates', '--inject-bootstrap', '--inline', '--input', '--install', '--interval', '--is-ancestor', '--is-shallow-repository', '--job-id', '--job-isolation', '--json', '--keep', '--kind', '--lanes', '--legacy-lock', '--limit', '--list', '--local', '--lock-duration-ms', '--log-noop', '--markdown', '--max-age', '--max-attempts', '--max-cost', '--max-cost-usd', '--max-crashes', '--max-rss', '--max-sources', '--max-stalled', '--max-usd', '--max-waiting', '--may-act-for', '--mcp-only', '--member', '--migration', '--min-context', '--missing-path', '--mode', '--model', '--multimodal', '--name', '--name-only', '--ner', '--nice', '--no-auto-embed', '--no-autopilot-install', '--no-bulk', '--no-confirm', '--no-delegate', '--no-embed', '--no-embedding', '--no-extract', '--no-gpg-sign', '--no-hard-deadline', '--no-inject', '--no-lanes', '--no-llm', '--no-pull', '--no-renames', '--no-repair', '--no-restart', '--no-schema-pack', '--no-verify', '--no-worker', '--non-interactive', '--now', '--of', '--older-than', '--once', '--only', '--order', '--others', '--output', '--override-disabled', '--oversized', '--pace', '--pace-max-concurrency', '--pack', '--page', '--parallel', '--params', '--parked-code', '--pat-file', '--path', '--pause', '--pglite', '--phase', '--pid-file', '--plan', '--port', '--prefer', '--preview', '--priority', '--probe', '--prune-orphans', '--pull', '--purge', '--qm', '--question', '--queue', '--queue-only', '--quiet', '--rate', '--reason', '--reason-scan-limit', '--rebuild', '--recent', '--record', '--redact-paths', '--redact-secrets', '--reenrich-after', '--refresh-ms', '--refresh-operations', '--remediate', '--repo', '--request-id', '--reset-checkpoint', '--restart-only', '--resume', '--retry-failed', '--retry-global', '--retry-held', '--retry-parked', '--review-lower', '--row', '--save', '--scope', '--scopes', '--section', '--segment-limit', '--segmented', '--select', '--self-transfer', '--serial', '--session', '--show-toplevel', '--side', '--sigkill-rescue', '--since', '--skip', '--skip-bare-tweet', '--skip-failed', '--skip-urls', '--sleep', '--slug', '--slugs', '--source', '--source-guard', '--source-id', '--sources', '--src-subpath', '--staged', '--stale', '--state', '--statement-timeout', '--status', '--stop-mcp', '--strategy', '--suites', '--surface', '--swap-only', '--target', '--thin', '--thin-threshold', '--tier', '--timeout', '--timeout-ms', '--to', '--token', '--token-env', '--trust', '--type', '--types', '--uninstall', '--updated-after', '--url', '--user', '--vectors', '--verbose', '--verify', '--version', '--watch', '--wedge-rescue', '--workers', '--working-tree', '--yes'],'lint': ['--abbrev-ref', '--accept-pending', '--add', '--admin-intent', '--adopt-slug-path', '--as', '--audit', '--autostash', '--background', '--brain', '--branch', '--cached', '--client', '--confirm-relocated-root', '--conflicts', '--dry-run', '--enable', '--exclude', '--expect-remote', '--expected-epoch', '--expected-revision', '--expected-state', '--explain', '--ff-only', '--file', '--fix', '--follow', '--force', '--get', '--get-all', '--git-dir', '--git-path', '--grammar-diagnostics', '--hard', '--help', '--id', '--infer-entity', '--is-inside-work-tree', '--json', '--keep', '--keep-checkout', '--local', '--local-env-vars', '--manifest', '--max-cost-usd', '--no-accept-pending', '--no-autostash', '--no-cron', '--no-pull', '--no-tags', '--no-verify', '--older-than', '--only', '--pat-file', '--path', '--prefer', '--preview', '--probe', '--progress-interval', '--progress-json', '--provenance', '--pull', '--purge', '--push-only', '--quiet', '--rebase', '--require-clean', '--resolve', '--scopes', '--self-transfer', '--short', '--show-toplevel', '--slug', '--slugs', '--source', '--source-id', '--timeout', '--timings', '--unset-all', '--wait', '--yes'],'loops': ['--all', '--as-of', '--brain', '--dry-run', '--fail-fast', '--help', '--json', '--note', '--source', '--stale-ok', '--status', '--tools-json', '--top', '--type'],'lsd': ['--brain', '--force-resume', '--help', '--json', '--judge-model', '--limit', '--list-runs', '--max-cost', '--max-far-set', '--max-ideas-per-judge-call', '--max-usd', '--no-save', '--resume', '--save', '--source', '--strict-budget', '--yes'],@@ -131,7 +131,7 @@ export const CLI_FLAG_REGISTRY: Record<string, readonly string[]> = {'smoke-test': ['--brain', '--help', '--json', '--source'],'sources': ['--abandon', '--abbrev-ref', '--abort', '--accept-pending', '--accept-suggested', '--access', '--account', '--add', '--admin-intent', '--adopt-columns', '--adopt-permissions', '--adopt-slug-path', '--after', '--all', '--all-new', '--allow-unverified-remote', '--allowed-operations', '--app-id', '--app-install', '--app-pem', '--apply', '--approval-out', '--approved', '--as', '--attest-actor', '--attest-ops', '--attest-sources', '--audit', '--auto-additive', '--autostash', '--background', '--backups', '--batch-check', '--before', '--bound-brain', '--bound-max-concurrent', '--bound-slug-prefixes', '--bound-source', '--bound-tools', '--brain', '--branch', '--break-lock', '--budget-usd-per-day', '--cached', '--calendar-id', '--category', '--channels', '--classify', '--cleanup-dead-local-locks', '--clear', '--client', '--clone-dir', '--code', '--config', '--confirm-destructive', '--confirm-quiesced', '--confirm-relocated-root', '--conflicts', '--contacts-dir', '--count', '--cursor', '--days', '--db-url', '--decisions', '--delegated-namespace', '--delegated-slug-prefixes', '--depth', '--detect', '--diff-filter', '--dir', '--disable', '--dry-run', '--enable', '--error-unmatch', '--exclude', '--expect', '--expect-local', '--expect-remote', '--expect-upstream', '--expected-epoch', '--expected-incarnation', '--expected-state', '--explain', '--federated', '--federated-read', '--fetch-timeout-ms', '--ff-only', '--file', '--fix', '--follow', '--force', '--format', '--from', '--from-git', '--full', '--future-days', '--get', '--get-all', '--git-dir', '--git-path', '--github-repo', '--grant-types', '--group-by', '--hard', '--help', '--history-days', '--holds', '--http', '--id', '--if-version', '--include', '--include-warns', '--install', '--is-ancestor', '--is-inside-work-tree', '--json', '--keep', '--keep-checkout', '--keep-storage', '--kind', '--lanes', '--legacy-lock', '--limit', '--list-out', '--local', '--local-env-vars', '--lookback-days', '--loops-exclude-labels', '--manifest', '--max-cost-usd', '--max-requests', '--may-act-for', '--member', '--message', '--migrate-legacy', '--migration', '--min-trust', '--mode', '--name', '--name-only', '--no-accept-pending', '--no-autostash', '--no-cron', '--no-embed', '--no-extract', '--no-federate', '--no-federated', '--no-harden', '--no-lanes', '--no-pull', '--no-tags', '--no-verify', '--not', '--only', '--operation', '--operations', '--origin', '--others', '--out', '--params', '--parked-code', '--parked-pushes', '--pat-file', '--path', '--path-format', '--plan', '--porcelain', '--preview', '--private-pages', '--probe', '--profile', '--progress-interval', '--progress-json', '--provider', '--pull', '--push-only', '--push-remote', '--quiet', '--read-sources', '--rebase', '--record', '--redirect-uri', '--refresh-operations', '--remote', '--remove-backup', '--repair', '--replace', '--repos', '--request-id', '--require-clean', '--reset-checkpoint', '--reset-default', '--resolve', '--resume', '--retire', '--retry-failed', '--sample', '--scope', '--scopes', '--secret', '--self-transfer', '--services', '--set', '--set-upstream-to', '--shared-skills', '--short', '--show-toplevel', '--since', '--skip', '--slug-prefixes', '--source', '--source-id', '--source-ids', '--sources', '--stale', '--state', '--status', '--stdin', '--surface', '--symbolic-full-name', '--sync-interval-min', '--takes-holders', '--timeout', '--timezone', '--timings', '--to', '--token', '--token-command', '--token-endpoint-auth-method', '--token-env', '--token-ttl', '--transcript', '--unindexed', '--uninstall', '--unset-all', '--unsettle', '--untracked-files', '--url', '--usage', '--verify', '--visibility', '--wait', '--wait-drain', '--warn-only', '--window', '--yes'],'status': ['--abbrev-ref', '--acknowledge-managed', '--all', '--allow-empty', '--apply', '--brain', '--break-lock', '--cached', '--check', '--code', '--concurrency', '--confirm-destructive', '--count', '--cursor', '--deadline-ms', '--delete', '--detail', '--diff-filter', '--empty', '--enable', '--exclude', '--exclude-standard', '--fast', '--filters', '--fix', '--force-break-lock', '--format', '--full', '--full-history', '--funnel', '--hard-deadline', '--help', '--hold-state', '--include-gitignored', '--include-hidden', '--install', '--interval', '--is-ancestor', '--is-shallow-repository', '--json', '--lanes', '--limit', '--max-age', '--max-sources', '--mcp-only', '--missing-path', '--name-only', '--no-auto-embed', '--no-bulk', '--no-delegate', '--no-embed', '--no-extract', '--no-gpg-sign', '--no-hard-deadline', '--no-lanes', '--no-llm', '--no-pull', '--no-renames', '--no-repair', '--no-schema-pack', '--no-verify', '--no-walk', '--others', '--parallel', '--path', '--prefer', '--preview', '--priority', '--quiet', '--redact-paths', '--repo', '--request-id', '--reset-checkpoint', '--retry-failed', '--retry-held', '--reverse', '--section', '--serial', '--show-toplevel', '--skip-failed', '--slug', '--slugs', '--source', '--source-id', '--src-subpath', '--stale', '--status', '--strategy', '--timeout', '--url', '--verify', '--watch', '--workers', '--working-tree', '--yes'],- 'storage': ['--brain', '--card', '--dir', '--dry-run', '--expect', '--expected-revision', '--help', '--json', '--patch', '--plan', '--push-remote', '--repo', '--restore-only', '--restored-to', '--source', '--status', '--store', '--to'],+ 'storage': ['--apply', '--brain', '--card', '--client', '--dir', '--drop-field', '--dry-run', '--expect', '--expected-revision', '--finalize', '--from-prefix', '--help', '--id', '--json', '--jsonl', '--out', '--patch', '--plan', '--push-remote', '--repo', '--restore-only', '--restored-to', '--scopes', '--source', '--status', '--store', '--to'],'sweep': ['--accept-pending', '--apply', '--as', '--assign-corpus', '--background', '--batch-limit', '--brain', '--budget-ms', '--delete-brain', '--explain', '--follow', '--help', '--home', '--json', '--no-accept-pending', '--no-delegate', '--once', '--only', '--progress-interval', '--progress-json', '--quiet', '--retry-failed', '--session', '--source', '--source-id', '--stale', '--timeout', '--timings', '--wait'],'sync': ['--abbrev-ref', '--absolute-git-dir', '--accept-pending', '--access-policy', '--account', '--acknowledge-managed', '--admin-intent', '--adopt-columns', '--adopt-permissions', '--after', '--all', '--allow-empty', '--allow-outside-source-root', '--apply', '--apply-rewrites', '--as', '--assign-corpus', '--audit', '--auto', '--background', '--batch', '--batch-check', '--batch-size', '--brain', '--branch', '--break-lock', '--budget-ms', '--by-mention', '--cached', '--catch-up', '--check', '--check-only', '--class', '--clear', '--client', '--close', '--code', '--concurrency', '--config', '--confirm-destructive', '--confirm-quiesced', '--confirm-relocated-root', '--conflicts', '--contacts-dir', '--content-audit', '--continue', '--conversation', '--count', '--cursor', '--cwd', '--db-url', '--delete-brain', '--depth', '--detach', '--detail', '--diff-filter', '--dim', '--dir', '--drain', '--dry-run', '--embedding-dimensions', '--embedding-model', '--empty', '--enable', '--end-of-options', '--entity', '--exclude', '--exclude-standard', '--expect', '--expect-local', '--expect-upstream', '--expected-epoch', '--expected-revision', '--expected-state', '--explain', '--facts', '--fast', '--ff-only', '--filters', '--first-parent', '--fix', '--follow', '--force', '--force-break-lock', '--force-rechunk', '--force-retry', '--force-schema', '--format', '--fresh', '--from', '--from-meetings', '--full', '--full-history', '--git-dir', '--git-path', '--grammar', '--group-by', '--hard-deadline', '--harness', '--held', '--help', '--hold-state', '--home', '--http', '--id', '--ignore-missing', '--images', '--include-ambiguous', '--include-flagged', '--include-frontmatter', '--include-gitignored', '--include-hidden', '--include-null-signature', '--include-repairs', '--index-audit', '--infer-dates', '--input', '--install', '--instructions-only', '--interval', '--is-ancestor', '--is-bare-repository', '--is-inside-work-tree', '--is-shallow-repository', '--json', '--keep-checkout', '--kind', '--lanes', '--lang', '--left-right', '--legacy-lock', '--limit', '--link-source', '--link-type', '--list', '--literal-pathspecs', '--local', '--locks', '--log-noop', '--manifest', '--markdown', '--max-age', '--max-cost', '--max-cost-usd', '--max-jobs', '--max-rss', '--max-sources', '--max-usd', '--may-act-for', '--migrate-legacy', '--migrate-only', '--missing-path', '--multimodal', '--name', '--name-only', '--name-status', '--ner', '--no-accept-pending', '--no-auto-embed', '--no-autopilot-install', '--no-bulk', '--no-capture', '--no-delegate', '--no-embed', '--no-extract', '--no-gpg-sign', '--no-hard-deadline', '--no-instructions', '--no-lanes', '--no-llm', '--no-pull', '--no-renames', '--no-repair', '--no-schema-pack', '--no-verify', '--no-walk', '--once', '--only', '--operations', '--others', '--output', '--oversized', '--overwrite', '--pace', '--pace-max-concurrency', '--pack', '--page', '--parallel', '--params', '--path', '--path-format', '--pending', '--pglite', '--phase', '--pid-file', '--plan', '--porcelain', '--prefer', '--prefer-postgres', '--preview', '--priority', '--probe', '--probe-pglite', '--progress-interval', '--progress-json', '--project', '--providers', '--prune-orphans', '--pull', '--purge', '--push-only', '--query', '--question', '--queue', '--quiet', '--raw', '--reader-mode', '--reauth', '--rebase', '--rebuild', '--redact-paths', '--refresh', '--regenerate', '--relative', '--remediate', '--remediation-plan', '--remote', '--remove', '--remove-core', '--replace', '--repo', '--request-id', '--reset', '--reset-checkpoint', '--reset-default', '--restart-only', '--restore-only', '--resume', '--retry-failed', '--retry-held', '--retry-parked', '--reverse', '--scope', '--scopes', '--self-transfer', '--serial', '--session', '--short', '--show-current', '--show-toplevel', '--side', '--since', '--skills-dir', '--skip', '--skip-failed', '--slot', '--slug', '--slugs', '--source', '--source-id', '--sources', '--src-subpath', '--staged', '--stale', '--stat', '--state', '--status', '--stdin', '--strategy', '--supabase', '--surface', '--symbol-kind', '--symbolic-full-name', '--takes-holders', '--target', '--target-score', '--tier', '--timeout', '--timings', '--to', '--token', '--token-env', '--top-k', '--type', '--unindexed', '--unshallow', '--untracked-files', '--url', '--url-env', '--verbose', '--verify', '--version', '--wait', '--watch', '--window', '--workers', '--working-tree', '--workspace', '--yes'],'takes': ['--about', '--accept', '--applied', '--apply', '--batch-size', '--before', '--brain', '--bucket-size', '--by', '--claim', '--date', '--dim', '--dir', '--domain', '--dry-run', '--embedding-dimensions', '--embedding-model', '--evidence', '--expected-revision', '--expired', '--failed', '--force', '--from-pages', '--group-by', '--help', '--holder', '--include-covered', '--json', '--kind', '--limit', '--max-pages', '--min-confidence', '--min-n', '--no-embed', '--no-embedding', '--offset', '--outcome', '--path', '--quality', '--reject', '--request-id', '--retry-failed', '--row', '--semantic', '--since', '--slug', '--sort', '--source', '--source-id', '--stale', '--state', '--status', '--supabase', '--to', '--unapplied', '--unit', '--until', '--value', '--verdict', '--weight', '--who', '--yes'],diff --git a/src/core/doctor-categories.ts b/src/core/doctor-categories.tsindex 7f676f4c6a..cbeeecddad 100644--- a/src/core/doctor-categories.ts+++ b/src/core/doctor-categories.ts@@ -208,6 +208,8 @@ export const BRAIN_CHECK_NAMES: ReadonlySet<string> = new Set(['source_config_shape','source_routing_health','stale_mentions',+ // GST-1943: storage shelf cards that fail the card schema, interim records not adopted, a hosted shelf directory gone.+ 'storage_manifest','stub_guard_24h',// Fact supersession threshold calibrated for the active embedding model (facts/supersession-threshold.ts).'supersession_calibration',diff --git a/src/core/error-registry.ts b/src/core/error-registry.tsindex 525e0d4521..13189e6de6 100644--- a/src/core/error-registry.ts+++ b/src/core/error-registry.ts@@ -766,9 +766,11 @@ export const CODES = {stale_unavailable: { class: 'unavailable', summary: "No complete, current authorized shared-skills view is available; cached shared skills stay unused.", docs: 'docs/guides/shared-brain-skills.md#troubleshoot-leave-and-recover' },state_mismatch: { class: 'caller', summary: "Google connect credential error: state mismatch.", docs: 'docs/guides/google-connect.md#troubleshooting' },store_unavailable: { class: 'retryable', summary: "The object store an engine opened from settings names did not answer a file check (file_register, file_verify, file_url), so nothing was recorded and no file was reported missing.", why: 'A failed read says nothing about whether the object exists; reporting it missing could lead a host to re-upload or delete a file that is still there.', docs: 'docs/ENGINES.md#opening-an-engine-from-settings-experimental', suggestion: "Check the store named in settings.storage (its path, or its endpoint, bucket and keys), then call again." },+ storage_adopt_field_refused: { class: 'consent', actor: 'user', summary: "Interim storage records carry fields a card refuses (a command, an unknown field, or a field gbrain stamps), and the adopt apply did not name each one with --drop-field; nothing was written.", why: 'Adopting leaves those fields out of the card, so the user decides; the original pages keep them until finalize soft-deletes the originals.', docs: 'docs/guides/write-refusals.md#storage-manifest-refusals', suggestion: 'Show the user the refused fields the adopt preview lists; with their agreement, run the apply the refusal names, which drops each with --drop-field.' },+ storage_adopt_unverified: { class: 'caller', summary: "An adopted interim original has no card on the storage shelf that matches its record, so finalize deleted nothing.", why: 'Finalize soft-deletes an original only when its card holds everything the record mapped to, so no archive record is lost.', docs: 'docs/guides/write-refusals.md#storage-manifest-refusals', suggestion: 'Compare the original with its card (gbrain storage-get), fix the card or the record, then preview gbrain storage adopt --finalize again.' },storage_card_exists: { class: 'caller', summary: "A storage card with this id is already on the storage shelf; nothing was written.", why: 'Registering never overwrites a card, so two archives cannot silently share one id; a change to an existing card names the revision it read.', docs: 'docs/guides/write-refusals.md#storage-manifest-refusals', suggestion: 'Change the card with gbrain storage-update <id> --expected-revision <revision from storage_get>, or register the new item under another id.' },storage_manifest_missing: { class: 'consent', actor: 'user', summary: "This brain has no storage shelf to write to (or the storage source ID belongs to another source); nothing was written.", why: 'On a brain with a Git checkout the shelf is a hosted git-canonical repository, created only after the user previews it, and hosting needs managed persistence. A repo-less brain gets its database-only shelf on the first register.', docs: 'docs/guides/write-refusals.md#storage-manifest-refusals', suggestion: 'Preview gbrain storage init --dir <absolute path> --dry-run and apply the command it prints after the user agrees.' },- storage_record_invalid: { class: 'caller', summary: "A storage card failed validation (a missing or malformed field, a command field, or a field gbrain stamps itself); nothing was written.", why: 'Every card must say where the item is, how big it is and how to restore it, and carries no commands, so a card is complete and safe to act on when it is found months later.', reasons: ['schema', 'command_field', 'stamped_field', 'not_json', 'not_object', 'too_large', 'id_change'], docs: 'docs/guides/write-refusals.md#storage-manifest-refusals', suggestion: 'Fix the field the message names and send the card again; gbrain storage-register --help lists the card fields.' },+ storage_record_invalid: { class: 'caller', summary: "A storage card failed validation (a missing or malformed field, a command field, or a field gbrain stamps itself); nothing was written.", why: 'Every card must say where the item is, how big it is and how to restore it, and carries no commands, so a card is complete and safe to act on when it is found months later.', reasons: ['schema', 'command_field', 'stamped_field', 'not_json', 'not_object', 'too_large', 'id_change', 'no_record', 'duplicate_id'], docs: 'docs/guides/write-refusals.md#storage-manifest-refusals', suggestion: 'Fix the field the message names and send the card again; gbrain storage-register --help lists the card fields.' },storage_record_secret: { class: 'caller', summary: "A storage card field looks like a secret or has a credential shape; nothing was written and the value is not echoed.", why: 'Cards are read by agents and copied into the stores; credentials stay in the environment of the skill that restores an item.', reasons: ['secret_scanner', 'env_assignment', 'credential_variable', 'url_userinfo', 'presigned_url'], docs: 'docs/guides/write-refusals.md#storage-manifest-refusals', suggestion: 'Remove the secret, environment assignment, credential variable, URL password or signed-URL parameter from the named field.' },storage_revision_conflict: { class: 'caller', summary: "A storage card changed since the revision the update named was read; nothing was written.", why: 'Updates bind to the revision they read, so two writers never silently overwrite each other; the refusal carries the current revision in detail.', docs: 'docs/guides/write-refusals.md#storage-manifest-refusals', suggestion: 'Read the card again with storage_get, apply the change to what it says now, and update once with its revision.' },storage_source_managed: { class: 'caller', summary: "A page write targeted the storage shelf outside the storage verbs; nothing was written.", why: 'The storage source holds only validated cards, so put_page, remember and the other page writers are refused there.', docs: 'docs/guides/write-refusals.md#storage-manifest-refusals', suggestion: 'Register cards with gbrain storage-register and change them with gbrain storage-update.' },diff --git a/src/core/skills/bundled-skills.generated.ts b/src/core/skills/bundled-skills.generated.tsindex dbf9cea9cb..46de7b8026 100644--- a/src/core/skills/bundled-skills.generated.ts+++ b/src/core/skills/bundled-skills.generated.ts@@ -84,10 +84,11 @@ import f81 from '../../../skills/skill-optimizer/skillopt-benchmark.jsonl' withimport f82 from '../../../skills/skillpack-check/SKILL.md' with { type: 'text' };import f83 from '../../../skills/smoke-test/SKILL.md' with { type: 'text' };import f84 from '../../../skills/soul-audit/SKILL.md' with { type: 'text' };-import f85 from '../../../skills/strategic-reading/SKILL.md' with { type: 'text' };-import f86 from '../../../skills/two-tier-extraction/SKILL.md' with { type: 'text' };-import f87 from '../../../skills/voice-note-ingest/SKILL.md' with { type: 'text' };-import f88 from '../../../skills/webhook-transforms/SKILL.md' with { type: 'text' };+import f85 from '../../../skills/storage-manifest/SKILL.md' with { type: 'text' };+import f86 from '../../../skills/strategic-reading/SKILL.md' with { type: 'text' };+import f87 from '../../../skills/two-tier-extraction/SKILL.md' with { type: 'text' };+import f88 from '../../../skills/voice-note-ingest/SKILL.md' with { type: 'text' };+import f89 from '../../../skills/webhook-transforms/SKILL.md' with { type: 'text' };export interface BundledSkillMeta { name: string; audience: 'owner' | 'downstream'; assets: string[] }@@ -720,6 +721,14 @@ export const BUNDLED_SKILLS: readonly BundledSkillMeta[] = ["conventions/agent-operator-protocol.md"]},+ {+ "name": "storage-manifest",+ "audience": "downstream",+ "assets": [+ "conventions/agent-operator-protocol.md",+ "conventions/brain-first.md"+ ]+ },{"name": "strategic-reading","audience": "downstream",@@ -851,8 +860,9 @@ export const BUNDLED_SKILL_FILES: Readonly<Record<string, string>> = {"skillpack-check/SKILL.md": f82,"smoke-test/SKILL.md": f83,"soul-audit/SKILL.md": f84,- "strategic-reading/SKILL.md": f85,- "two-tier-extraction/SKILL.md": f86,- "voice-note-ingest/SKILL.md": f87,- "webhook-transforms/SKILL.md": f88,+ "storage-manifest/SKILL.md": f85,+ "strategic-reading/SKILL.md": f86,+ "two-tier-extraction/SKILL.md": f87,+ "voice-note-ingest/SKILL.md": f88,+ "webhook-transforms/SKILL.md": f89,};diff --git a/src/core/storage-manifest/adopt.ts b/src/core/storage-manifest/adopt.tsnew file mode 100644index 0000000000..d0b54b9398--- /dev/null+++ b/src/core/storage-manifest/adopt.ts@@ -0,0 +1,302 @@+/**+ * `gbrain storage adopt` (GST-1943): moves interim storage records onto the shelf. An interim record is a page of type+ * `stored-object` under a slug prefix (default `storage-manifest/`) in an ordinary source, written before the shelf+ * existed, holding its record as JSON in a fenced json block under a `## Record` heading (other sections, such as+ * `## Restore`, are ignored). Records use the draft schema: card fields, plus free-text `restore.command` and other+ * fields the card refuses. Trusted local CLI only; three steps, each preview-first and bound to its plan_hash:+ *+ * preview (default) per page the mapped card and every refused field with its reason; writes nothing.+ * apply registers each card through registerCard (the storage_register path) with origin `adopt`, then tags the+ * original `storage-manifest-adopted` through its source's page door. Deletes nothing. Refused fields must+ * each be named with `--drop-field`; a credential-shaped value or an invalid record always refuses.+ * finalize soft-deletes the tagged originals through the page door (restorable for 72 h), only when every adopted+ * card is on the shelf and matches its original's mapped card.+ *+ * Idempotent: a card already on the shelf that matches is skipped, and so is an original already tagged. A card on+ * the shelf that differs is a conflict: reported, never overwritten, its original left untagged. The plan_hash covers+ * what the run ends with (mapped cards, refused fields, blocked pages, conflicts), not progress, so the apply+ * command a partial run prints still applies. The record is read from the page's bounded 64 KiB prefix.+ */+import { createHash } from 'node:crypto';+import { opError, OperationError, type OperationContext } from '../ops/contract.ts';+import { readFix } from '../ops/op-fix.ts';+import { registerCard } from '../ops/storage-manifest.ts';+import { boundedBodyPrefixSql } from '../page-window/bounded-lead.ts';+import { submitPageMutation } from '../persistence/page-mutations.ts';+import { readShelfCards } from './find.ts';+import { CARD_KEYS, cardContent, cardDigest, credentialShape, isCommandKey, parseCardInput, STAMPED_KEYS, STORED_OBJECT_TYPE, type CardInput } from './schema.ts';+import { shelfWritable, STORAGE_SOURCE_ID } from './source.ts';++export const ADOPT_DEFAULT_PREFIX = 'storage-manifest/';+export const ADOPT_DEFAULT_SOURCE = 'default';+export const ADOPTED_TAG = 'storage-manifest-adopted';++export type RefusedReason = 'command_field' | 'stamped_field' | 'unknown_field';+export interface RefusedField { field: string; reason: RefusedReason }+export interface EntryProblem { code: 'storage_record_secret' | 'storage_record_invalid'; reason: string; message: string }+export type AdoptState = 'register' | 'retag' | 'adopted' | 'conflict' | 'blocked';+export interface AdoptEntry { slug: string; card_id: string | null; state: AdoptState; card: CardInput | null; refused: RefusedField[]; problem: EntryProblem | null }+export interface AdoptOptions { sourceId: string; prefix: string }+export interface AdoptPlan {+ action: 'adopt'; dry_run: true; source_id: string; prefix: string; shelf: 'exists' | 'creates';+ entries: AdoptEntry[]; counts: Record<AdoptState, number>; drop_fields: string[]; plan_hash: string; summary: string[]; apply?: string[];+}+export type SideEffects = 'none' | 'partial' | 'complete';+export interface StepFailure { item: string; code: string; message: string }+export interface AdoptApplyResult {+ action: 'adopt'; dry_run: false; source_id: string; prefix: string; plan_hash: string; side_effects: SideEffects;+ results: Array<{ slug: string; card_id: string | null; outcome: 'registered' | 'retagged' | 'skipped' | 'conflict' }>;+ conflicts: string[]; failure?: StepFailure; rerun?: string[]; finalize?: string[];+}+export interface FinalizeEntry { slug: string; card_id: string | null; state: 'delete' | 'deleted' | 'unverified' | 'not_adopted' }+export interface FinalizePlan { action: 'finalize'; dry_run: true; source_id: string; prefix: string; entries: FinalizeEntry[]; plan_hash: string; summary: string[]; apply?: string[] }+export interface FinalizeApplyResult {+ action: 'finalize'; dry_run: false; source_id: string; prefix: string; plan_hash: string; side_effects: SideEffects;+ deleted: string[]; skipped: string[]; failure?: StepFailure; rerun?: string[];+}++interface InterimRow { slug: string; title: string; frontmatter: unknown; body: string | null; tagged: boolean; deleted: boolean }++const sha256 = (text: string) => createHash('sha256').update(text).digest('hex');+const SECTION = /^##[ \t]+Record[ \t]*$/m;+const NEXT_SECTION = /^##[ \t]/m;+const JSON_FENCE = /^```json[ \t]*\r?\n([\s\S]*?)\r?\n```[ \t]*$/m;++/** The adopt command for these options (a preview; callers add the step flags). */+export function adoptArgv(opts: AdoptOptions): string[] {+ return ['gbrain', 'storage', 'adopt',+ ...(opts.sourceId !== ADOPT_DEFAULT_SOURCE ? ['--source', opts.sourceId] : []),+ ...(opts.prefix !== ADOPT_DEFAULT_PREFIX ? ['--from-prefix', opts.prefix] : [])];+}++function previewFix(opts: AdoptOptions, finalize = false) {+ return readFix('Prints the current plan and its plan_hash; changes nothing.', { argv: [...adoptArgv(opts), ...(finalize ? ['--finalize'] : []), '--json'] });+}++/** The JSON text of a page's `## Record` section, or null when the page has none in its first 64 KiB. */+export function recordJson(body: string): string | null {+ const heading = SECTION.exec(body);+ if (!heading) return null;+ const rest = body.slice(heading.index + heading[0].length);+ const next = NEXT_SECTION.exec(rest);+ const fence = JSON_FENCE.exec(next ? rest.slice(0, next.index) : rest);+ return fence ? fence[1]! : null;+}++function keysAt(path: string): ReadonlySet<string> | null {+ return CARD_KEYS[path.replace(/\.\d+(?=\.|$)/g, '.*')] ?? null;+}++/** The record with every field the card refuses taken out; each one is pushed to `refused` with its reason. */+function strip(value: unknown, path: string, refused: RefusedField[]): unknown {+ if (Array.isArray(value)) return value.map((item, i) => strip(item, `${path}.${i}`, refused));+ if (!value || typeof value !== 'object') return value;+ const allowed = keysAt(path);+ const out: Record<string, unknown> = {};+ for (const [key, item] of Object.entries(value)) {+ const at = path ? `${path}.${key}` : key;+ const reason: RefusedReason | null = isCommandKey(key) ? 'command_field'+ : !path && (STAMPED_KEYS as readonly string[]).includes(key) ? 'stamped_field'+ : allowed && !allowed.has(key) ? 'unknown_field' : null;+ if (reason) refused.push({ field: at, reason });+ else out[key] = strip(item, at, refused);+ }+ return out;+}++/** The first string value with a credential shape, by dotted path; the value itself is never returned. */+function credentialAt(value: unknown, path: string): { field: string; shape: string } | null {+ if (typeof value === 'string') { const shape = credentialShape(value); return shape ? { field: path || '(record)', shape } : null; }+ if (!value || typeof value !== 'object') return null;+ const items: Array<readonly [string, unknown]> = Array.isArray(value) ? value.map((item, i) => [String(i), item] as const) : Object.entries(value);+ for (const [key, item] of items) {+ const found = credentialAt(item, path ? `${path}.${key}` : key);+ if (found) return found;+ }+ return null;+}++function invalidRecord(reason: string, message: string): EntryProblem {+ return { code: 'storage_record_invalid', reason, message };+}++/** Map one interim page onto a card. Pure: reads nothing beyond the row. */+export function mapInterimPage(row: Pick<InterimRow, 'slug' | 'title' | 'frontmatter' | 'body'>, prefix: string): Pick<AdoptEntry, 'card' | 'refused' | 'problem'> {+ const text = recordJson(row.body ?? '');+ if (text === null) return { card: null, refused: [], problem: invalidRecord('no_record', 'the page has no json block under a ## Record heading in its first 64 KiB') };+ let record: unknown;+ try { record = JSON.parse(text); } catch { return { card: null, refused: [], problem: invalidRecord('not_json', 'the ## Record block is not valid JSON') }; }+ if (!record || typeof record !== 'object' || Array.isArray(record)) return { card: null, refused: [], problem: invalidRecord('not_object', 'the ## Record block is not a JSON object') };+ const refused: RefusedField[] = [];+ const stripped = strip(record, '', refused) as Record<string, unknown>;+ const secret = credentialAt(record, '');+ if (secret) return { card: null, refused, problem: { code: 'storage_record_secret', reason: secret.shape, message: `field ${secret.field} has a credential shape (${secret.shape}); the value is not shown` } };+ const frontmatter = (typeof row.frontmatter === 'string' ? JSON.parse(row.frontmatter) : row.frontmatter ?? {}) as Record<string, unknown>;+ const aliases = Array.isArray(frontmatter.aliases) ? frontmatter.aliases.filter((a): a is string => typeof a === 'string') : [];+ const mapped = { ...stripped, id: stripped.id ?? row.slug.slice(prefix.length).replace(/\//g, '-'), title: stripped.title ?? row.title, aliases: stripped.aliases ?? aliases };+ try {+ return { card: parseCardInput(mapped), refused, problem: null };+ } catch (error) {+ if (!(error instanceof OperationError)) throw error;+ return { card: null, refused, problem: { code: error.code === 'storage_record_secret' ? 'storage_record_secret' : 'storage_record_invalid',+ reason: error.reason ?? 'schema', message: error.message.replace(/; nothing was written\.$/, '') } };+ }+}++async function listInterim(ctx: OperationContext, opts: AdoptOptions, includeDeleted: boolean): Promise<InterimRow[]> {+ return ctx.engine.executeRaw<InterimRow>(`+ SELECT p.slug, p.title, p.frontmatter, ${boundedBodyPrefixSql('p')} AS body, p.deleted_at IS NOT NULL AS deleted,+ EXISTS (SELECT 1 FROM tags t WHERE t.page_id = p.id AND t.tag = $4) AS tagged+ FROM pages p+ WHERE p.source_id = $1 AND p.type = $2 AND left(p.slug, length($3)) = $3 AND p.slug <> $3 || 'index'${includeDeleted ? '' : ' AND p.deleted_at IS NULL'}+ ORDER BY p.slug`, [opts.sourceId, STORED_OBJECT_TYPE, opts.prefix, ADOPTED_TAG]);+}++async function assertInterimSource(ctx: OperationContext, opts: AdoptOptions): Promise<void> {+ if (opts.sourceId === STORAGE_SOURCE_ID) throw opError('invalid_params', `Source ${STORAGE_SOURCE_ID} is the storage shelf itself; adopt reads interim records from another source.`,+ 'Pass --source with the source that holds the interim pages (the default is default); nothing was changed.');+ const rows = await ctx.engine.executeRaw('SELECT 1 FROM sources WHERE id = $1 AND archived IS NOT TRUE', [opts.sourceId]);+ if (!rows.length) throw opError('invalid_params', `No active source ${opts.sourceId}; nothing was changed.`,+ 'Pass --source with an id gbrain sources list shows.', { fix: readFix('Lists the sources of this brain.', { argv: ['gbrain', 'sources', 'list', '--json'] }) });+}++/** Preview: what apply would do. Writes nothing; refuses storage_manifest_missing on a brain with a Git checkout until storage init has run. */+export async function previewAdopt(ctx: OperationContext, opts: AdoptOptions): Promise<AdoptPlan> {+ await assertInterimSource(ctx, opts);+ const { creates } = await shelfWritable(ctx.engine);+ const shelf = new Map((await readShelfCards(ctx.engine)).map((row) => [row.id, row.card]));+ const seen = new Set<string>();+ const entries: AdoptEntry[] = (await listInterim(ctx, opts, false)).map((row): AdoptEntry => {+ const mapped = mapInterimPage(row, opts.prefix);+ const card_id = mapped.card?.id ?? null;+ if (card_id && seen.has(card_id)) return { slug: row.slug, card_id, state: 'blocked', card: null, refused: mapped.refused, problem: invalidRecord('duplicate_id', `another interim page maps to card id ${card_id}`) };+ if (card_id) seen.add(card_id);+ if (!mapped.card) return { slug: row.slug, card_id, state: 'blocked', ...mapped };+ const onShelf = shelf.get(mapped.card.id);+ const existing = onShelf ? cardContent(onShelf) : null;+ const state: AdoptState = !shelf.has(mapped.card.id) ? 'register'+ : !existing || cardDigest(existing) !== cardDigest(mapped.card) ? 'conflict' : row.tagged ? 'adopted' : 'retag';+ return { slug: row.slug, card_id, state, ...mapped };+ });+ const counts: Record<AdoptState, number> = { register: 0, retag: 0, adopted: 0, conflict: 0, blocked: 0 };+ for (const entry of entries) counts[entry.state]++;+ const drop_fields = [...new Set(entries.filter((e) => e.state !== 'blocked').flatMap((e) => e.refused.map((f) => f.field)))].sort();+ const plan_hash = sha256(JSON.stringify({ v: 1, kind: 'adopt', source_id: opts.sourceId, prefix: opts.prefix, entries: entries.map((e) => ({+ slug: e.slug, card: e.card ? cardDigest(e.card) : null, refused: e.refused.map((f) => `${f.field}:${f.reason}`),+ problem: e.problem ? `${e.problem.code}:${e.problem.reason}` : null, conflict: e.state === 'conflict' })) }));+ const summary = [`${entries.length} interim record(s) under ${opts.prefix} in source ${opts.sourceId}: ${counts.register} to register, ${counts.retag} already on the shelf to tag, ${counts.adopted} already adopted, ${counts.conflict} conflict(s), ${counts.blocked} blocked.`];+ if (creates && counts.register) summary.push(`The first card creates the storage shelf (source ${STORAGE_SOURCE_ID}, database-only: this brain has no Git checkout, so the database is the record).`);+ if (drop_fields.length) summary.push(`Fields a card refuses, left out only when each is named with --drop-field: ${drop_fields.join(', ')}. The original pages keep them until finalize.`);+ if (counts.conflict) summary.push('A conflict is a card already on the shelf that differs from the record: it is never overwritten, and its original is not tagged.');+ if (counts.blocked) summary.push('Blocked pages need their record fixed on the page first; apply refuses until then.');+ const apply = counts.blocked || !(counts.register + counts.retag) ? undefined+ : [...adoptArgv(opts), ...drop_fields.flatMap((f) => ['--drop-field', f]), '--apply', '--expect', plan_hash];+ return { action: 'adopt', dry_run: true, source_id: opts.sourceId, prefix: opts.prefix, shelf: creates ? 'creates' : 'exists', entries, counts, drop_fields, plan_hash, summary, ...(apply ? { apply } : {}) };+}++function staleHash(opts: AdoptOptions, expected: string, finalize: boolean): OperationError {+ return opError('preview_changed', `The ${finalize ? 'finalize' : 'adopt'} plan for ${opts.prefix} in source ${opts.sourceId} changed since its preview (approved plan ${expected}); nothing was changed.`,+ 'Preview again, show the user the new plan, and apply the plan_hash it prints only if they approve it.', { fix: previewFix(opts, finalize) });+}++function blockedRefusal(opts: AdoptOptions, blocked: AdoptEntry[]): OperationError {+ const first = blocked.find((e) => e.problem?.code === 'storage_record_secret') ?? blocked[0]!;+ const list = blocked.slice(0, 5).map((e) => `${e.slug} (${e.problem!.message})`).join('; ');+ return opError(first.problem!.code, `${blocked.length} interim record(s) cannot become cards: ${list}${blocked.length > 5 ? '; and more' : ''}. Nothing was written.`,+ first.problem!.code === 'storage_record_secret'+ ? 'Remove the credential from the record on each named page (the restore skill reads credentials from its own environment), then preview the adopt again.'+ : 'Fix the record on each named page so it is a complete card, then preview the adopt again.',+ { reason: first.problem!.reason, fix: previewFix(opts) });+}++/** Apply the previewed plan. Never deletes; a failure stops the run and reports side_effects and the rerun command. */+export async function applyAdopt(ctx: OperationContext, opts: AdoptOptions & { expect: string; dropFields: string[] }): Promise<AdoptApplyResult> {+ const plan = await previewAdopt(ctx, opts);+ if (opts.expect !== plan.plan_hash) throw staleHash(opts, opts.expect, false);+ const blocked = plan.entries.filter((e) => e.state === 'blocked');+ if (blocked.length) throw blockedRefusal(opts, blocked);+ const extra = opts.dropFields.filter((f) => !plan.drop_fields.includes(f));+ if (extra.length) throw opError('invalid_params', `--drop-field names a field no interim record has refused: ${extra.join(', ')}; nothing was written.`,+ `Name only the refused fields the preview lists (${plan.drop_fields.join(', ') || 'none'}).`, { fix: previewFix(opts) });+ const rerun = [...adoptArgv(opts), ...plan.drop_fields.flatMap((f) => ['--drop-field', f]), '--apply', '--expect', plan.plan_hash];+ const missing = plan.drop_fields.filter((f) => !opts.dropFields.includes(f));+ if (missing.length) {+ throw opError('storage_adopt_field_refused', `Interim records carry fields a card refuses: ${missing.join(', ')}; nothing was written.`,+ 'Show the user each refused field and its reason from the preview; with their agreement, apply again naming each one with --drop-field.',+ { fix: { ask_user: true, argv: rerun, consent: [], actor: 'agent', requires_exclusive: false, plan_hash: plan.plan_hash,+ why: 'Registers the cards without the refused fields, which stay on the original pages until finalize.',+ user_message: `These fields of the interim storage records cannot go on a card and would be left out: ${missing.join(', ')}. The original pages keep them until you finalize. Leave them out?` } });+ }+ const results: AdoptApplyResult['results'] = [];+ let failure: StepFailure | undefined;+ for (const entry of plan.entries) {+ if (entry.state === 'conflict' || entry.state === 'adopted') { results.push({ slug: entry.slug, card_id: entry.card_id, outcome: entry.state === 'conflict' ? 'conflict' : 'skipped' }); continue; }+ try {+ if (entry.state === 'register') {+ await registerCard(ctx, entry.card!, 'adopt');+ results.push({ slug: entry.slug, card_id: entry.card_id, outcome: 'registered' });+ }+ await submitPageMutation(ctx, { operation: 'add_tag', params: { slug: entry.slug, tag: ADOPTED_TAG, source_id: opts.sourceId } });+ results.push({ slug: entry.slug, card_id: entry.card_id, outcome: 'retagged' });+ } catch (error) {+ if (!(error instanceof OperationError)) throw error;+ failure = { item: entry.slug, code: error.canonical ?? error.code, message: error.message };+ break;+ }+ }+ const wrote = results.some((r) => r.outcome === 'registered' || r.outcome === 'retagged');+ return { action: 'adopt', dry_run: false, source_id: opts.sourceId, prefix: opts.prefix, plan_hash: plan.plan_hash,+ side_effects: failure ? (wrote ? 'partial' : 'none') : wrote ? 'complete' : 'none', results,+ conflicts: results.filter((r) => r.outcome === 'conflict').map((r) => r.slug),+ ...(failure ? { failure, rerun } : { finalize: [...adoptArgv(opts), '--finalize'] }) };+}++/** Preview finalize: the tagged originals to soft-delete. Writes nothing. */+export async function previewFinalize(ctx: OperationContext, opts: AdoptOptions): Promise<FinalizePlan> {+ await assertInterimSource(ctx, opts);+ const shelf = new Map((await readShelfCards(ctx.engine)).map((row) => [row.id, row.card]));+ const entries: FinalizeEntry[] = (await listInterim(ctx, opts, true)).flatMap((row): FinalizeEntry[] => {+ if (!row.tagged) return row.deleted ? [] : [{ slug: row.slug, card_id: null, state: 'not_adopted' }];+ const { card } = mapInterimPage(row, opts.prefix);+ if (row.deleted) return [{ slug: row.slug, card_id: card?.id ?? null, state: 'deleted' }];+ const onShelf = card ? shelf.get(card.id) : undefined;+ const existing = onShelf ? cardContent(onShelf) : null;+ return [{ slug: row.slug, card_id: card?.id ?? null, state: card && existing && cardDigest(existing) === cardDigest(card) ? 'delete' : 'unverified' }];+ });+ const count = (state: FinalizeEntry['state']) => entries.filter((e) => e.state === state).length;+ const plan_hash = sha256(JSON.stringify({ v: 1, kind: 'finalize', source_id: opts.sourceId, prefix: opts.prefix,+ entries: entries.filter((e) => e.state !== 'not_adopted').map((e) => ({ slug: e.slug, card_id: e.card_id, unverified: e.state === 'unverified' })) }));+ const summary = [`${count('delete')} adopted original(s) to soft-delete (restorable for 72 hours), ${count('deleted')} already deleted, ${count('unverified')} whose card is missing or differs, ${count('not_adopted')} not adopted yet (kept).`];+ if (count('unverified')) summary.push('Finalize refuses while an adopted original has no matching card; compare it with gbrain storage-get and fix the card or the record first.');+ const apply = count('unverified') || !count('delete') ? undefined : [...adoptArgv(opts), '--finalize', '--expect', plan_hash];+ return { action: 'finalize', dry_run: true, source_id: opts.sourceId, prefix: opts.prefix, entries, plan_hash, summary, ...(apply ? { apply } : {}) };+}++/** Soft-delete the adopted originals the preview listed, each bound to the revision read just before. */+export async function applyFinalize(ctx: OperationContext, opts: AdoptOptions & { expect: string }): Promise<FinalizeApplyResult> {+ const plan = await previewFinalize(ctx, opts);+ if (opts.expect !== plan.plan_hash) throw staleHash(opts, opts.expect, true);+ const unverified = plan.entries.filter((e) => e.state === 'unverified');+ if (unverified.length) {+ throw opError('storage_adopt_unverified', `${unverified.length} adopted original(s) have no matching card on the storage shelf: ${unverified.slice(0, 5).map((e) => e.slug).join(', ')}; nothing was deleted.`,+ 'Compare each original with its card (gbrain storage-get with the card id the finalize preview lists), fix the card or the record, then preview finalize again.', { fix: previewFix(opts, true) });+ }+ const deleted: string[] = [];+ let failure: StepFailure | undefined;+ for (const entry of plan.entries.filter((e) => e.state === 'delete')) {+ try {+ const snapshot = await ctx.engine.readPageSnapshot(entry.slug, { sourceId: opts.sourceId });+ if (!snapshot) continue;+ await submitPageMutation(ctx, { operation: 'delete_page', params: { slug: entry.slug, source_id: opts.sourceId, expected_revision: snapshot.revision } });+ deleted.push(entry.slug);+ } catch (error) {+ if (!(error instanceof OperationError)) throw error;+ failure = { item: entry.slug, code: error.canonical ?? error.code, message: error.message };+ break;+ }+ }+ return { action: 'finalize', dry_run: false, source_id: opts.sourceId, prefix: opts.prefix, plan_hash: plan.plan_hash,+ side_effects: failure ? (deleted.length ? 'partial' : 'none') : deleted.length ? 'complete' : 'none', deleted,+ skipped: plan.entries.filter((e) => e.state !== 'delete').map((e) => e.slug),+ ...(failure ? { failure, rerun: [...adoptArgv(opts), '--finalize', '--expect', plan.plan_hash] } : {}) };+}diff --git a/src/core/storage-manifest/find.ts b/src/core/storage-manifest/find.tsindex ebfa89efae..0d2369a361 100644--- a/src/core/storage-manifest/find.ts+++ b/src/core/storage-manifest/find.ts@@ -9,7 +9,7 @@ import { pageReadFilter } from '../search/read-policy-sql.ts';import { normalizeAlias } from '../search/alias-normalize.ts';import { boundedBodyPrefixSql } from '../page-window/bounded-lead.ts';import { STORAGE_SOURCE_ID } from './door.ts';-import { STORED_OBJECT_TYPE } from './schema.ts';+import { cardFromPage, STORED_OBJECT_TYPE, type Card } from './schema.ts';const STOPWORDS = new Set(['a', 'an', 'and', 'the', 'of', 'to', 'in', 'on', 'for', 'from', 'my', 'our', 'it', 'that', 'this', 'back', 'bring', 'restore', 'find', 'where', 'is', 'was', 'what', 'did', 'go', 'with', 'please']);const CLOSEST_FLOOR = 0.1;@@ -79,3 +79,13 @@ export async function listCards(engine: BrainEngine, opts: { limit: number; offsconst cards = await engine.executeRaw<CardRow>(`SELECT ${CARD_COLUMNS} FROM pages p WHERE ${where} ORDER BY p.slug LIMIT $${params.length - 1} OFFSET $${params.length}`, params);return { cards: cards.map((c) => ({ ...c, stores: c.stores ?? [] })), total: Number(n) };}++/** Every live page on the shelf, sorted by id, with the card it stores (null when its page holds none). Trusted local readers only. */+export async function readShelfCards(engine: BrainEngine): Promise<Array<{ id: string; card: Card | null }>> {+ const rows = await engine.executeRaw<{ slug: string; title: string; type: string | null; frontmatter: unknown }>(+ 'SELECT p.slug, p.title, p.type, p.frontmatter FROM pages p WHERE p.source_id = $1 AND p.deleted_at IS NULL ORDER BY p.slug', [STORAGE_SOURCE_ID]);+ return rows.map((row) => {+ const frontmatter = typeof row.frontmatter === 'string' ? JSON.parse(row.frontmatter) as Record<string, unknown> : (row.frontmatter ?? {}) as Record<string, unknown>;+ return { id: row.slug, card: row.type === STORED_OBJECT_TYPE ? cardFromPage({ slug: row.slug, title: row.title, frontmatter }) : null };+ });+}diff --git a/src/core/storage-manifest/jsonl.ts b/src/core/storage-manifest/jsonl.tsnew file mode 100644index 0000000000..b4b9934c97--- /dev/null+++ b/src/core/storage-manifest/jsonl.ts@@ -0,0 +1,113 @@+/**+ * Storage shelf recovery as JSONL (GST-1943). `gbrain storage export --jsonl` writes one card per line, sorted by id,+ * stamped fields (`registered_by`, `origin`) included. `gbrain storage import --jsonl <file>` previews each line+ * (create / identical / conflict / invalid) with a plan_hash, and the apply with that plan_hash registers the missing+ * cards through registerCard with origin `import`: gbrain stamps registered_by and origin again, so a file cannot set+ * them. A card on the shelf that differs from its line is a conflict, reported and never overwritten. Idempotent: a+ * rerun finds the cards it created identical. Trusted local CLI only. Lines are validated like a new card, so an+ * invalid line never echoes its values.+ */+import { createHash } from 'node:crypto';+import { canonicalJson } from '../remediation-step.ts';+import { opError, OperationError, type OperationContext } from '../ops/contract.ts';+import { readFix } from '../ops/op-fix.ts';+import { registerCard } from '../ops/storage-manifest.ts';+import type { BrainEngine } from '../engine.ts';+import { readShelfCards } from './find.ts';+import { cardContent, cardDigest, parseCardInput, type CardInput } from './schema.ts';+import { shelfWritable } from './source.ts';+import type { SideEffects, StepFailure } from './adopt.ts';++export type ImportAction = 'create' | 'identical' | 'conflict' | 'invalid';+export interface ImportLine { line: number; id: string | null; action: ImportAction; code?: string; reason?: string; message?: string }+export interface ImportPlan { action: 'import'; dry_run: true; file: string; lines: ImportLine[]; counts: Record<ImportAction, number>; plan_hash: string; summary: string[]; apply?: string[] }+export interface ImportApplyResult {+ action: 'import'; dry_run: false; file: string; plan_hash: string; side_effects: SideEffects;+ created: string[]; identical: string[]; conflicts: string[]; invalid: number[]; failure?: StepFailure; rerun?: string[];+}+interface ParsedLine { line: number; id: string | null; card: CardInput | null; code?: string; reason?: string; message?: string }++const sha256 = (text: string) => createHash('sha256').update(text).digest('hex');++/** One line per card on the shelf, sorted by id, keys sorted; pages on the shelf that hold no card are listed in `skipped`. */+export async function exportShelfJsonl(engine: BrainEngine): Promise<{ lines: string[]; skipped: string[] }> {+ const rows = await readShelfCards(engine);+ return { lines: rows.flatMap((row) => row.card ? [canonicalJson(row.card)] : []), skipped: rows.filter((row) => !row.card).map((row) => row.id) };+}++function invalidLine(line: number, id: string | null, reason: string, message: string, code = 'storage_record_invalid'): ParsedLine {+ return { line, id, card: null, code, reason, message };+}++function parseLines(text: string): ParsedLine[] {+ const seen = new Set<string>();+ return text.split('\n').flatMap((raw, i): ParsedLine[] => {+ if (!raw.trim()) return [];+ const line = i + 1;+ let value: unknown;+ try { value = JSON.parse(raw); } catch { return [invalidLine(line, null, 'not_json', 'the line is not valid JSON')]; }+ if (!value || typeof value !== 'object' || Array.isArray(value)) return [invalidLine(line, null, 'not_object', 'the line is not a JSON object')];+ const { registered_by: _by, origin: _origin, ...content } = value as Record<string, unknown>;+ const id = typeof content.id === 'string' ? content.id : null;+ let card: CardInput;+ try { card = parseCardInput(content); } catch (error) {+ if (!(error instanceof OperationError)) throw error;+ return [invalidLine(line, id, error.reason ?? 'schema', error.message.replace(/; nothing was written\.$/, ''), error.code)];+ }+ if (seen.has(card.id)) return [invalidLine(line, card.id, 'duplicate_id', `an earlier line holds card id ${card.id}`)];+ seen.add(card.id);+ return [{ line, id: card.id, card }];+ });+}++/** Preview an import: per line what the apply would do. Writes nothing; a brain with a Git checkout refuses until storage init has run. */+export async function previewImport(engine: BrainEngine, file: string, text: string): Promise<ImportPlan & { cards: Map<number, CardInput> }> {+ await shelfWritable(engine);+ const shelf = new Map((await readShelfCards(engine)).map((row) => [row.id, row.card]));+ const cards = new Map<number, CardInput>();+ const lines: ImportLine[] = parseLines(text).map(({ card, ...rest }) => {+ if (!card) return { ...rest, action: 'invalid' };+ cards.set(rest.line, card);+ if (!shelf.has(card.id)) return { line: rest.line, id: card.id, action: 'create' };+ const onShelf = shelf.get(card.id);+ const existing = onShelf ? cardContent(onShelf) : null;+ return { line: rest.line, id: card.id, action: existing && cardDigest(existing) === cardDigest(card) ? 'identical' : 'conflict' };+ });+ const counts: Record<ImportAction, number> = { create: 0, identical: 0, conflict: 0, invalid: 0 };+ for (const line of lines) counts[line.action]++;+ const plan_hash = sha256(JSON.stringify({ v: 1, kind: 'import', lines: lines.map((l) => ({ line: l.line, id: l.id,+ card: cards.has(l.line) ? cardDigest(cards.get(l.line)!) : null, invalid: l.action === 'invalid' ? l.reason : null, conflict: l.action === 'conflict' })) }));+ const summary = [`${lines.length} card line(s) in ${file}: ${counts.create} to create, ${counts.identical} already on the shelf, ${counts.conflict} conflict(s), ${counts.invalid} invalid.`];+ if (counts.conflict) summary.push('A conflict is a card already on the shelf that differs from its line; import never overwrites it.');+ if (counts.invalid) summary.push('Invalid lines are skipped; the line numbers and reasons are listed (values are not shown).');+ const apply = counts.create ? ['gbrain', 'storage', 'import', '--jsonl', file, '--apply', '--expect', plan_hash] : undefined;+ return { action: 'import', dry_run: true, file, lines, counts, plan_hash, summary, ...(apply ? { apply } : {}), cards };+}++/** Apply the previewed import. Creates only; a failure stops the run and reports side_effects and the rerun command. */+export async function applyImport(ctx: OperationContext, file: string, text: string, expect: string): Promise<ImportApplyResult> {+ const { cards, ...plan } = await previewImport(ctx.engine, file, text);+ const previewArgv = ['gbrain', 'storage', 'import', '--jsonl', file, '--json'];+ if (expect !== plan.plan_hash) {+ throw opError('preview_changed', `The import plan for ${file} changed since its preview (approved plan ${expect}); nothing was written.`,+ 'Preview the import again, show the user the new plan, and apply the plan_hash it prints only if they approve it.',+ { fix: readFix('Prints the current import plan and its plan_hash; writes nothing.', { argv: previewArgv }) });+ }+ const created: string[] = [];+ let failure: StepFailure | undefined;+ for (const line of plan.lines.filter((l) => l.action === 'create')) {+ try {+ await registerCard(ctx, cards.get(line.line)!, 'import');+ created.push(line.id!);+ } catch (error) {+ if (!(error instanceof OperationError)) throw error;+ failure = { item: line.id!, code: error.canonical ?? error.code, message: error.message };+ break;+ }+ }+ const ids = (action: ImportAction) => plan.lines.filter((l) => l.action === action).map((l) => l.id!);+ return { action: 'import', dry_run: false, file, plan_hash: plan.plan_hash,+ side_effects: failure ? (created.length ? 'partial' : 'none') : created.length ? 'complete' : 'none',+ created, identical: ids('identical'), conflicts: ids('conflict'), invalid: plan.lines.filter((l) => l.action === 'invalid').map((l) => l.line),+ ...(failure ? { failure, rerun: plan.apply ?? ['gbrain', 'storage', 'import', '--jsonl', file, '--apply', '--expect', plan.plan_hash] } : {}) };+}diff --git a/src/core/storage-manifest/schema.ts b/src/core/storage-manifest/schema.tsindex 82a6c2746c..c7eb3e2127 100644--- a/src/core/storage-manifest/schema.ts+++ b/src/core/storage-manifest/schema.ts@@ -9,8 +9,9 @@* contacts a store.*/import { z } from 'zod';-import { opError, type OperationError } from '../ops/contract.ts';+import { opError, OperationError } from '../ops/contract.ts';import { scanTextSpans } from '../secret-scan.ts';+import { canonicalJson } from '../remediation-step.ts';export const STORED_OBJECT_TYPE = 'stored-object';export const CARD_ID_RE = /^[a-z0-9][a-z0-9-]{1,79}$/;@@ -73,11 +74,19 @@ export const CardInputSchema = z.object({details: z.record(z.string(), z.unknown()).nullish(),}).strict();+/** The keys each object in a card takes, by dotted path with `*` for a list index (adopt maps draft records onto them). */+export const CARD_KEYS: Readonly<Record<string, ReadonlySet<string>>> = {+ '': new Set(Object.keys(CardInputSchema.shape)),+ 'locations.*': new Set(Object.keys(LocationSchema.shape)),+ restore: new Set(Object.keys(RestoreSchema.shape)),+ 'restores.*': new Set(Object.keys(RestoreEventSchema.shape)),+};+export type CardInput = z.infer<typeof CardInputSchema>;export type Card = CardInput & { registered_by: string; origin: (typeof ORIGINS)[number] };const COMMAND_KEYS = new Set(['command', 'cmd', 'script', 'exec', 'shell', 'instructions']);-const STAMPED_KEYS = ['registered_by', 'origin'] as const;+export const STAMPED_KEYS = ['registered_by', 'origin'] as const;const CREDENTIAL_NAME = /(?:KEY|SECRET|TOKEN|PASSWORD|PASSWD|PASS|CRED|AUTH)/i;const ENV_ASSIGNMENT = /(?:^|[\s;&|(])[A-Za-z_][A-Za-z0-9_]{1,}=\S/;const VAR_REFERENCE = /\$\{?([A-Za-z_][A-Za-z0-9_]*)/g;@@ -96,23 +105,36 @@ function walk(value: unknown, path: string, visit: (path: string, text: string)if (value && typeof value === 'object') {for (const [key, item] of Object.entries(value)) {const at = path ? `${path}.${key}` : key;- if (COMMAND_KEYS.has(key.toLowerCase())) throw invalid(at, 'a card carries no commands; restore runs through restore.skill and restore.args', 'command_field');+ if (isCommandKey(key)) throw invalid(at, 'a card carries no commands; restore runs through restore.skill and restore.args', 'command_field');walk(item, at, visit);}}}-/** The credential-shape rules over one string. Throws without echoing the value. */+export type CredentialShape = 'secret_scanner' | 'env_assignment' | 'url_userinfo' | 'presigned_url' | 'credential_variable';++/** The credential-shape rules over one string: the shape it has, or null. */+export function credentialShape(value: string): CredentialShape | null {+ if (scanTextSpans(value).some((span) => span.finding !== null)) return 'secret_scanner';+ return ENV_ASSIGNMENT.test(value) ? 'env_assignment'+ : URL_USERINFO.test(value) ? 'url_userinfo'+ : PRESIGNED.test(value) ? 'presigned_url'+ : [...value.matchAll(VAR_REFERENCE)].some((m) => CREDENTIAL_NAME.test(m[1]!)) ? 'credential_variable' : null;+}++/** Keys a card refuses wherever they appear: a card carries no commands. */+export function isCommandKey(key: string): boolean {+ return COMMAND_KEYS.has(key.toLowerCase());+}++/** Throws storage_record_secret without echoing the value. */function assertNoCredential(path: string, value: string): void {- if (scanTextSpans(value).some((span) => span.finding !== null)) {+ const shape = credentialShape(value);+ if (shape === 'secret_scanner') {throw opError('storage_record_secret', `Storage card field ${path} looks like it holds a secret; nothing was written.`,'Remove the secret from that field. Cards name where an item is and how to restore it; credentials stay in the environment of the skill that restores it.',{ reason: 'secret_scanner' });}- const shape = ENV_ASSIGNMENT.test(value) ? 'env_assignment'- : URL_USERINFO.test(value) ? 'url_userinfo'- : PRESIGNED.test(value) ? 'presigned_url'- : [...value.matchAll(VAR_REFERENCE)].some((m) => CREDENTIAL_NAME.test(m[1]!)) ? 'credential_variable' : null;if (shape) {throw opError('storage_record_secret', `Storage card field ${path} has a credential shape (${shape}); nothing was written.`,'Drop the environment assignment, credential variable, URL password or signed-URL parameter from that field; the restore skill reads credentials from its own environment.',@@ -171,6 +193,23 @@ function summary(card: Card): string {return lines.join('\n') + '\n';}+/** A card without the fields gbrain stamps, validated again: what two copies of one card compare on. Null when it fails the schema. */+export function cardContent(card: Record<string, unknown>): CardInput | null {+ const { registered_by: _by, origin: _origin, ...content } = card;+ try { return parseCardInput(content); } catch (error) { if (error instanceof OperationError) return null; throw error; }+}++function withoutEmpty(value: unknown): unknown {+ if (Array.isArray(value)) return value.map(withoutEmpty);+ if (!value || typeof value !== 'object') return value;+ return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== null && item !== undefined).map(([key, item]) => [key, withoutEmpty(item)]));+}++/** Stable text of a card's content (null and absent fields are the same), for comparing and hashing. */+export function cardDigest(card: CardInput): string {+ return canonicalJson(withoutEmpty(card));+}+/** Frontmatter and body for a card's page. */export function cardPage(card: Card): { frontmatter: Record<string, unknown>; body: string } {const { id: _id, title, aliases, ...rest } = card;diff --git a/src/core/storage-manifest/source.ts b/src/core/storage-manifest/source.tsindex 7d65b82795..0e1b5aa8aa 100644--- a/src/core/storage-manifest/source.ts+++ b/src/core/storage-manifest/source.ts@@ -49,17 +49,24 @@ async function markRole(engine: BrainEngine): Promise<void> {}/**- * The shelf a storage write lands in. A repo-less brain gets its database-only source on first use; a repo brain- * must run `gbrain storage init` first. A `storage` source that exists without the role is someone else's, refused.+ * Whether a storage write can land: throws the refusal it would get, and says whether the first write creates the+ * database-only shelf (a repo-less brain). A repo brain must run `gbrain storage init` first; a `storage` source that+ * exists without the role is someone else's, refused. Writes nothing.*/-export async function ensureStorageSource(engine: BrainEngine): Promise<void> {+export async function shelfWritable(engine: BrainEngine): Promise<{ creates: boolean }> {const state = await storageSourceState(engine);- if (state.exists && state.role) return;+ if (state.exists && state.role) return { creates: false };if (state.exists) throw opError('storage_manifest_missing', `Source ${STORAGE_SOURCE_ID} exists but is not a storage manifest; nothing was written.`,`The storage shelf needs the source ID ${STORAGE_SOURCE_ID}. Rename or remove the existing source (gbrain sources list shows it), then register again.`);if (state.repoBrain) throw opError('storage_manifest_missing', 'This brain keeps its pages in Git, so the storage shelf is a hosted Git repository that gbrain storage init creates; nothing was written.','Preview it with gbrain storage init --dir <absolute path> --dry-run, and apply the command it prints after the user agrees. It needs managed persistence (gbrain sources writer activate).',{ fix: initFix() });+ return { creates: true };+}++/** The shelf a storage write lands in: a repo-less brain gets its database-only source on first use (see shelfWritable). */+export async function ensureStorageSource(engine: BrainEngine): Promise<void> {+ if (!(await shelfWritable(engine)).creates) return;await addSource(engine, { id: STORAGE_SOURCE_ID, name: 'Storage manifest', federated: false });await markRole(engine);}diff --git a/templates/bootstrap/AGENTS.md.template b/templates/bootstrap/AGENTS.md.templateindex 12bf3b2c02..08b7c34efb 100644--- a/templates/bootstrap/AGENTS.md.template+++ b/templates/bootstrap/AGENTS.md.template@@ -104,6 +104,7 @@ instead of the CLI (one connection, no per-call startup).| Links, dated events, every page of a type | `gbrain backlinks <slug>`, `gbrain timeline <slug>`, `gbrain list --type T` | `get_backlinks`, `get_timeline`, `list_pages` || Save a fact the user stated | `gbrain remember "<fact>" --entity <slug> --content-origin user_said --provenance "<where>"` | `remember` || Why a page didn't rank | `gbrain query "<q>" --explain-target <slug>` | `query` |+| Find something archived to B2, Supabase or S3 | `gbrain storage-find "<phrase>"` | `storage_find` |Parse `--json` output instead of matching the text; notices go to stderr. Neversend stderr to `/dev/null`: a refusal there (`no_brain`, `GBRAIN_DB_ACCESS`)diff --git a/templates/bootstrap/template-repo/AGENTS.md b/templates/bootstrap/template-repo/AGENTS.mdindex 4d73f68abe..5cac71c94e 100644--- a/templates/bootstrap/template-repo/AGENTS.md+++ b/templates/bootstrap/template-repo/AGENTS.md@@ -108,6 +108,7 @@ instead of the CLI (one connection, no per-call startup).| Links, dated events, every page of a type | `gbrain backlinks <slug>`, `gbrain timeline <slug>`, `gbrain list --type T` | `get_backlinks`, `get_timeline`, `list_pages` || Save a fact the user stated | `gbrain remember "<fact>" --entity <slug> --content-origin user_said --provenance "<where>"` | `remember` || Why a page didn't rank | `gbrain query "<q>" --explain-target <slug>` | `query` |+| Find something archived to B2, Supabase or S3 | `gbrain storage-find "<phrase>"` | `storage_find` |Parse `--json` output instead of matching the text; notices go to stderr. Neversend stderr to `/dev/null`: a refusal there (`no_brain`, `GBRAIN_DB_ACCESS`)diff --git a/test/doctor-storage-manifest.test.ts b/test/doctor-storage-manifest.test.tsnew file mode 100644index 0000000000..0d501dc55b--- /dev/null+++ b/test/doctor-storage-manifest.test.ts@@ -0,0 +1,84 @@+/**+ * GST-1943: the storage_manifest doctor check (read-only, PGLite in-memory). Protects:+ * - not_applicable with no shelf and no interim record;+ * - interim stored-object pages under storage-manifest/ outside the shelf warn until adopted, with the read-only adopt+ * preview as the fix; the index page and adopted originals do not count;+ * - a card on the shelf that fails the current schema warns by id, never by value;+ * - a hosted shelf whose directory is gone warns and asks the user;+ * - the check writes nothing and is categorized brain.+ */+import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';+import { randomUUID } from 'node:crypto';+import { PGLiteEngine } from '../src/core/pglite-engine.ts';+import { operationsByName } from '../src/core/operations.ts';+import type { OperationContext } from '../src/core/ops/contract.ts';+import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';+import { storageManifestCheck } from '../src/commands/doctor/checks/storage-manifest.ts';+import { categorizeCheck } from '../src/core/doctor-categories.ts';+import { resetPgliteState } from './helpers/reset-pglite.ts';++let engine: PGLiteEngine;++beforeAll(async () => {+ engine = new PGLiteEngine();+ await engine.connect({});+ await engine.initSchema();+}, 60_000);+afterAll(async () => {+ await disposePersistenceConsumer(engine);+ await engine.disconnect();+}, 60_000);+beforeEach(async () => {+ await disposePersistenceConsumer(engine);+ await resetPgliteState(engine);+});++const ctx = (): OperationContext => ({+ engine, config: { engine: engine.kind, embedding_disabled: true } as OperationContext['config'],+ logger: { info() {}, warn() {}, error() {} }, dryRun: false, remote: false, sourceId: 'default',+}) as OperationContext;+const call = (name: string, params: Record<string, unknown>) => operationsByName[name]!.handler(ctx(), params) as Promise<Record<string, any>>;+const card = (id: string) => ({ id, title: `Dataset ${id}`, kind: 'dataset',+ locations: [{ store: 'b2', bucket: 'bucket-a', path: `/archive/${id}`, tool: 'restic', size_bytes: 64 }], restore: { skill: 'restore-data', args: { id } } });+const FENCE = '```';+const interim = (slug: string) => call('put_page', { slug, request_id: randomUUID(),+ content: `---\ntype: stored-object\ntitle: Interim ${slug}\n---\n## Record\n\n${FENCE}json\n${JSON.stringify(card(slug.split('/').pop()!))}\n${FENCE}\n` });++describe('storage_manifest doctor check', () => {+ test('not_applicable with no shelf and no interim record', async () => {+ const check = await storageManifestCheck(engine);+ expect(check).toMatchObject({ name: 'storage_manifest', status: 'ok', readiness_state: 'not_applicable' });+ expect(categorizeCheck('storage_manifest')).toBe('brain');+ }, 30_000);++ test('interim records warn until adopted; the index page does not count', async () => {+ await interim('storage-manifest/dataset-a');+ await interim('storage-manifest/index');+ const before = await engine.executeRaw('SELECT slug, updated_at::text AS at FROM pages ORDER BY slug');+ const check = await storageManifestCheck(engine);+ expect(check.status).toBe('warn');+ expect(check.message).toContain('1 interim storage record(s)');+ expect(check.details).toMatchObject({ shelf: false, interim_pending: [{ source_id: 'default', count: 1 }] });+ expect(check.fix).toMatchObject({ argv: ['gbrain', 'storage', 'adopt', '--json'], verify: { argv: ['gbrain', 'doctor', '--only', 'storage_manifest', '--json'] } });+ expect(await engine.executeRaw('SELECT slug, updated_at::text AS at FROM pages ORDER BY slug')).toEqual(before);++ await call('add_tag', { slug: 'storage-manifest/dataset-a', tag: 'storage-manifest-adopted' });+ await call('storage_register', { card: card('dataset-a') });+ expect(await storageManifestCheck(engine)).toMatchObject({ status: 'ok', details: { shelf: true, invalid_cards: [], interim_pending: [] } });+ }, 30_000);++ test('a card failing the current schema warns by id, never by value', async () => {+ await call('storage_register', { card: card('dataset-a') });+ await engine.executeRaw("UPDATE pages SET frontmatter = jsonb_set(frontmatter, '{storage,restore}', '{\"skill\":\"restore-data\",\"command\":\"placeholder-command-value\"}'::jsonb) WHERE source_id='storage' AND slug='dataset-a'");+ const check = await storageManifestCheck(engine);+ expect(check).toMatchObject({ status: 'warn', details: { invalid_cards: ['dataset-a'] }, fix: { argv: ['gbrain', 'storage-get', 'dataset-a', '--json'] } });+ expect(JSON.stringify(check)).not.toContain('placeholder-command-value');+ }, 30_000);++ test('a hosted shelf whose directory is gone warns and asks the user', async () => {+ await call('storage_register', { card: card('dataset-a') });+ await engine.executeRaw("UPDATE sources SET local_path = '/srv/data/missing-shelf/worktree' WHERE id='storage'");+ const check = await storageManifestCheck(engine);+ expect(check).toMatchObject({ status: 'warn', details: { missing_dirs: ['/srv/data/missing-shelf/worktree'] }, fix: { ask_user: true, actor: 'user' } });+ }, 30_000);+});diff --git a/test/fixtures/goldens/doctor/content-pglite-human.json b/test/fixtures/goldens/doctor/content-pglite-human.jsonindex 4e25de0931..5b70d1a36f 100644--- a/test/fixtures/goldens/doctor/content-pglite-human.json+++ b/test/fixtures/goldens/doctor/content-pglite-human.json@@ -29,7 +29,7 @@" [OK] skill_conformance: 1/1 skills pass"," [OK] skill_brain_first: 1 skill(s) compliant or exempt"," [OK] skills_manifest_integrity: No skills.lock.json in <home>/skills — integrity check not applicable",- " [WARN] skill_currency: 64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ " [WARN] skill_currency: 65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`."," [OK] skill_preconditions: no installed skills declare preconditions"," [OK] memorable_relay_health: memorable relay off (default)"," [OK] memory_writeback: ambient writeback off (default): Stop-hook turn capture is off, but the compaction harvest and SessionEnd transcripts still extract (installing the harness hooks opted into them; stop them: gbrain config set memory.auto_writeback off). Enable: gbrain config set memory.auto_writeback salient",@@ -257,6 +257,7 @@" [OK] owner_host_stale: No managed write is waiting on an owner host."," [OK] embedding_plane_disagreement: The config file disables embeddings and the database holds no vectors."," [OK] fence_integrity: No malformed facts or takes fence is held, stored or waiting in a checkout (2 source(s) scanned).",+ " [INFO] storage_manifest: No storage shelf and no interim storage records on this brain."," [OK] search_mode: Mode: conservative (no per-key overrides — mode bundle is canonical)."," [OK] hidden_by_search_policy: No pages hidden by search-exclude policy."," [OK] eval_drift: No retrieval-affecting files changed in working tree.",diff --git a/test/fixtures/goldens/doctor/content-pglite-json.json b/test/fixtures/goldens/doctor/content-pglite-json.jsonindex 63bb1b5937..1ec9c6cbe5 100644--- a/test/fixtures/goldens/doctor/content-pglite-json.json+++ b/test/fixtures/goldens/doctor/content-pglite-json.json@@ -158,6 +158,7 @@"skillpack-check","skillpack-harvest","soul-audit",+ "storage-manifest","strategic-reading","testing","two-tier-extraction",@@ -167,7 +168,7 @@},"elapsed_ms": "<volatile>","fix_unavailable_reason": "unstructured",- "message": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "message": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn"},@@ -4031,6 +4032,18 @@"name": "fence_integrity","status": "ok"},+ {+ "category": "brain",+ "details": {+ "docs": "docs/guides/storage-manifest.md#doctor"+ },+ "elapsed_ms": "<volatile>",+ "message": "No storage shelf and no interim storage records on this brain.",+ "name": "storage_manifest",+ "readiness_state": "not_applicable",+ "severity": "info",+ "status": "ok"+ },{"category": "ops","elapsed_ms": "<volatile>",@@ -4507,7 +4520,7 @@"tier": "symptom"},{- "fix": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "fix": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn","tier": "symptom"diff --git a/test/fixtures/goldens/doctor/early-stop-connection-failure.json b/test/fixtures/goldens/doctor/early-stop-connection-failure.jsonindex fc1f4b17a5..8084ebb4ec 100644--- a/test/fixtures/goldens/doctor/early-stop-connection-failure.json+++ b/test/fixtures/goldens/doctor/early-stop-connection-failure.json@@ -117,6 +117,7 @@"skillpack-check","skillpack-harvest","soul-audit",+ "storage-manifest","strategic-reading","testing","two-tier-extraction",@@ -125,7 +126,7 @@]},"elapsed_ms": "<volatile>",- "message": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "message": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn"},diff --git a/test/fixtures/goldens/doctor/early-stop-null-engine-connect-error.json b/test/fixtures/goldens/doctor/early-stop-null-engine-connect-error.jsonindex 12344e17cc..2a114e55a5 100644--- a/test/fixtures/goldens/doctor/early-stop-null-engine-connect-error.json+++ b/test/fixtures/goldens/doctor/early-stop-null-engine-connect-error.json@@ -107,6 +107,7 @@"skillpack-check","skillpack-harvest","soul-audit",+ "storage-manifest","strategic-reading","testing","two-tier-extraction",@@ -115,7 +116,7 @@]},"elapsed_ms": "<volatile>",- "message": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "message": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn"},diff --git a/test/fixtures/goldens/doctor/early-stop-null-engine-fast.json b/test/fixtures/goldens/doctor/early-stop-null-engine-fast.jsonindex 5a02a86f99..38fae692a0 100644--- a/test/fixtures/goldens/doctor/early-stop-null-engine-fast.json+++ b/test/fixtures/goldens/doctor/early-stop-null-engine-fast.json@@ -107,6 +107,7 @@"skillpack-check","skillpack-harvest","soul-audit",+ "storage-manifest","strategic-reading","testing","two-tier-extraction",@@ -115,7 +116,7 @@]},"elapsed_ms": "<volatile>",- "message": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "message": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn"},diff --git a/test/fixtures/goldens/doctor/early-stop-null-engine-no-config.json b/test/fixtures/goldens/doctor/early-stop-null-engine-no-config.jsonindex 6d94dd2632..fc6d4902a4 100644--- a/test/fixtures/goldens/doctor/early-stop-null-engine-no-config.json+++ b/test/fixtures/goldens/doctor/early-stop-null-engine-no-config.json@@ -107,6 +107,7 @@"skillpack-check","skillpack-harvest","soul-audit",+ "storage-manifest","strategic-reading","testing","two-tier-extraction",@@ -115,7 +116,7 @@]},"elapsed_ms": "<volatile>",- "message": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "message": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn"},diff --git a/test/fixtures/goldens/doctor/hot-checks-pglite-json.json b/test/fixtures/goldens/doctor/hot-checks-pglite-json.jsonindex 0bf4f033b0..29518773ed 100644--- a/test/fixtures/goldens/doctor/hot-checks-pglite-json.json+++ b/test/fixtures/goldens/doctor/hot-checks-pglite-json.json@@ -159,6 +159,7 @@"skillpack-check","skillpack-harvest","soul-audit",+ "storage-manifest","strategic-reading","testing","two-tier-extraction",@@ -168,7 +169,7 @@},"elapsed_ms": "<volatile>","fix_unavailable_reason": "unstructured",- "message": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "message": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn"},@@ -4463,6 +4464,18 @@"name": "fence_integrity","status": "warn"},+ {+ "category": "brain",+ "details": {+ "docs": "docs/guides/storage-manifest.md#doctor"+ },+ "elapsed_ms": "<volatile>",+ "message": "No storage shelf and no interim storage records on this brain.",+ "name": "storage_manifest",+ "readiness_state": "not_applicable",+ "severity": "info",+ "status": "ok"+ },{"category": "ops","elapsed_ms": "<volatile>",@@ -5006,7 +5019,7 @@"tier": "symptom"},{- "fix": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "fix": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn","tier": "symptom"@@ -5256,6 +5269,7 @@"skillpack-check","skillpack-harvest","soul-audit",+ "storage-manifest","strategic-reading","testing","two-tier-extraction",@@ -5265,7 +5279,7 @@},"elapsed_ms": "<volatile>","fix_unavailable_reason": "unstructured",- "message": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "message": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn"},@@ -9572,6 +9586,18 @@"name": "fence_integrity","status": "warn"},+ {+ "category": "brain",+ "details": {+ "docs": "docs/guides/storage-manifest.md#doctor"+ },+ "elapsed_ms": "<volatile>",+ "message": "No storage shelf and no interim storage records on this brain.",+ "name": "storage_manifest",+ "readiness_state": "not_applicable",+ "severity": "info",+ "status": "ok"+ },{"category": "ops","elapsed_ms": "<volatile>",@@ -10115,7 +10141,7 @@"tier": "symptom"},{- "fix": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "fix": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn","tier": "symptom"diff --git a/test/fixtures/goldens/doctor/hot-checks-postgres-json.json b/test/fixtures/goldens/doctor/hot-checks-postgres-json.jsonindex 8efd132b9c..f176a3e68d 100644--- a/test/fixtures/goldens/doctor/hot-checks-postgres-json.json+++ b/test/fixtures/goldens/doctor/hot-checks-postgres-json.json@@ -146,6 +146,7 @@"skillpack-check","skillpack-harvest","soul-audit",+ "storage-manifest","strategic-reading","testing","two-tier-extraction",@@ -155,7 +156,7 @@},"elapsed_ms": "<volatile>","fix_unavailable_reason": "unstructured",- "message": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "message": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn"},@@ -4466,6 +4467,18 @@"name": "fence_integrity","status": "warn"},+ {+ "category": "brain",+ "details": {+ "docs": "docs/guides/storage-manifest.md#doctor"+ },+ "elapsed_ms": "<volatile>",+ "message": "No storage shelf and no interim storage records on this brain.",+ "name": "storage_manifest",+ "readiness_state": "not_applicable",+ "severity": "info",+ "status": "ok"+ },{"category": "ops","elapsed_ms": "<volatile>",@@ -5007,7 +5020,7 @@"tier": "symptom"},{- "fix": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "fix": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn","tier": "symptom"@@ -5244,6 +5257,7 @@"skillpack-check","skillpack-harvest","soul-audit",+ "storage-manifest","strategic-reading","testing","two-tier-extraction",@@ -5253,7 +5267,7 @@},"elapsed_ms": "<volatile>","fix_unavailable_reason": "unstructured",- "message": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "message": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn"},@@ -9576,6 +9590,18 @@"name": "fence_integrity","status": "warn"},+ {+ "category": "brain",+ "details": {+ "docs": "docs/guides/storage-manifest.md#doctor"+ },+ "elapsed_ms": "<volatile>",+ "message": "No storage shelf and no interim storage records on this brain.",+ "name": "storage_manifest",+ "readiness_state": "not_applicable",+ "severity": "info",+ "status": "ok"+ },{"category": "ops","elapsed_ms": "<volatile>",@@ -10117,7 +10143,7 @@"tier": "symptom"},{- "fix": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "fix": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn","tier": "symptom"diff --git a/test/fixtures/goldens/doctor/json-pglite-degraded.json b/test/fixtures/goldens/doctor/json-pglite-degraded.jsonindex 5dc7b9d4bb..e1511c9b3a 100644--- a/test/fixtures/goldens/doctor/json-pglite-degraded.json+++ b/test/fixtures/goldens/doctor/json-pglite-degraded.json@@ -155,6 +155,7 @@"skillpack-check","skillpack-harvest","soul-audit",+ "storage-manifest","strategic-reading","testing","two-tier-extraction",@@ -164,7 +165,7 @@},"elapsed_ms": "<volatile>","fix_unavailable_reason": "unstructured",- "message": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "message": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn"},@@ -3609,6 +3610,18 @@"name": "fence_integrity","status": "ok"},+ {+ "category": "brain",+ "details": {+ "docs": "docs/guides/storage-manifest.md#doctor"+ },+ "elapsed_ms": "<volatile>",+ "message": "No storage shelf and no interim storage records on this brain.",+ "name": "storage_manifest",+ "readiness_state": "not_applicable",+ "severity": "info",+ "status": "ok"+ },{"category": "ops","elapsed_ms": "<volatile>",@@ -3910,7 +3923,7 @@"tier": "symptom"},{- "fix": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "fix": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn","tier": "symptom"diff --git a/test/fixtures/goldens/doctor/json-pglite-fast.json b/test/fixtures/goldens/doctor/json-pglite-fast.jsonindex adfdab69ca..413bc8149e 100644--- a/test/fixtures/goldens/doctor/json-pglite-fast.json+++ b/test/fixtures/goldens/doctor/json-pglite-fast.json@@ -145,6 +145,7 @@"skillpack-check","skillpack-harvest","soul-audit",+ "storage-manifest","strategic-reading","testing","two-tier-extraction",@@ -154,7 +155,7 @@},"elapsed_ms": "<volatile>","fix_unavailable_reason": "unstructured",- "message": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "message": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn"},@@ -419,7 +420,7 @@"tier": "root"},{- "fix": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "fix": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn","tier": "symptom"diff --git a/test/fixtures/goldens/doctor/json-pglite-fresh.json b/test/fixtures/goldens/doctor/json-pglite-fresh.jsonindex fe956f3135..6dd54048f6 100644--- a/test/fixtures/goldens/doctor/json-pglite-fresh.json+++ b/test/fixtures/goldens/doctor/json-pglite-fresh.json@@ -158,6 +158,7 @@"skillpack-check","skillpack-harvest","soul-audit",+ "storage-manifest","strategic-reading","testing","two-tier-extraction",@@ -167,7 +168,7 @@},"elapsed_ms": "<volatile>","fix_unavailable_reason": "unstructured",- "message": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "message": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn"},@@ -3654,6 +3655,18 @@"name": "fence_integrity","status": "ok"},+ {+ "category": "brain",+ "details": {+ "docs": "docs/guides/storage-manifest.md#doctor"+ },+ "elapsed_ms": "<volatile>",+ "message": "No storage shelf and no interim storage records on this brain.",+ "name": "storage_manifest",+ "readiness_state": "not_applicable",+ "severity": "info",+ "status": "ok"+ },{"category": "ops","elapsed_ms": "<volatile>",@@ -3985,7 +3998,7 @@"tier": "standard","top_issues": [{- "fix": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "fix": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn","tier": "symptom"diff --git a/test/fixtures/goldens/doctor/json-postgres-fresh.json b/test/fixtures/goldens/doctor/json-postgres-fresh.jsonindex 4c4b47af54..5ab226fa0e 100644--- a/test/fixtures/goldens/doctor/json-postgres-fresh.json+++ b/test/fixtures/goldens/doctor/json-postgres-fresh.json@@ -145,6 +145,7 @@"skillpack-check","skillpack-harvest","soul-audit",+ "storage-manifest","strategic-reading","testing","two-tier-extraction",@@ -154,7 +155,7 @@},"elapsed_ms": "<volatile>","fix_unavailable_reason": "unstructured",- "message": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "message": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn"},@@ -3657,6 +3658,18 @@"name": "fence_integrity","status": "ok"},+ {+ "category": "brain",+ "details": {+ "docs": "docs/guides/storage-manifest.md#doctor"+ },+ "elapsed_ms": "<volatile>",+ "message": "No storage shelf and no interim storage records on this brain.",+ "name": "storage_manifest",+ "readiness_state": "not_applicable",+ "severity": "info",+ "status": "ok"+ },{"category": "ops","elapsed_ms": "<volatile>",@@ -3986,7 +3999,7 @@"tier": "standard","top_issues": [{- "fix": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "fix": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn","tier": "symptom"diff --git a/test/fixtures/goldens/doctor/json-postgres-unreachable-fast.json b/test/fixtures/goldens/doctor/json-postgres-unreachable-fast.jsonindex 451eecd02e..f05afd3471 100644--- a/test/fixtures/goldens/doctor/json-postgres-unreachable-fast.json+++ b/test/fixtures/goldens/doctor/json-postgres-unreachable-fast.json@@ -132,6 +132,7 @@"skillpack-check","skillpack-harvest","soul-audit",+ "storage-manifest","strategic-reading","testing","two-tier-extraction",@@ -141,7 +142,7 @@},"elapsed_ms": "<volatile>","fix_unavailable_reason": "unstructured",- "message": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "message": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn"},@@ -371,7 +372,7 @@"tier": "root"},{- "fix": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "fix": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn","tier": "symptom"diff --git a/test/fixtures/goldens/doctor/json-postgres-unreachable.json b/test/fixtures/goldens/doctor/json-postgres-unreachable.jsonindex b4710ccb80..1c752ff0f4 100644--- a/test/fixtures/goldens/doctor/json-postgres-unreachable.json+++ b/test/fixtures/goldens/doctor/json-postgres-unreachable.json@@ -131,6 +131,7 @@"skillpack-check","skillpack-harvest","soul-audit",+ "storage-manifest","strategic-reading","testing","two-tier-extraction",@@ -140,7 +141,7 @@},"elapsed_ms": "<volatile>","fix_unavailable_reason": "unstructured",- "message": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "message": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn"},@@ -376,7 +377,7 @@"tier": "root"},{- "fix": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.",+ "fix": "65 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +57 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn","tier": "symptom"diff --git a/test/fixtures/goldens/doctor/registry-build-checks.json b/test/fixtures/goldens/doctor/registry-build-checks.jsonindex 51e19e3824..be46e888cd 100644--- a/test/fixtures/goldens/doctor/registry-build-checks.json+++ b/test/fixtures/goldens/doctor/registry-build-checks.json@@ -1097,6 +1097,10 @@"category": "brain","name": "fence_integrity"},+ {+ "category": "brain",+ "name": "storage_manifest"+ },{"category": "ops","name": "search_mode"diff --git a/test/fixtures/goldens/exports/types.json b/test/fixtures/goldens/exports/types.jsonindex b5f53550c6..40ce3e884b 100644--- a/test/fixtures/goldens/exports/types.json+++ b/test/fixtures/goldens/exports/types.json@@ -6840,7 +6840,7 @@{"kind": "class","members": [- "canonical?: \"unknown\" | \"timeout\" | \"keyword_candidates_incomplete\" | \"projection_pending\" | \"rate_limited\" | \"embedding_disabled\" | \"writer_lock_unavailable\" | \"writer_pool_capacity\" | \"owner_unavailable\" | \"recovery_required\" | \"queue_capacity\" | \"write_quota_exhausted\" | \"write_quota_insufficient\" | \"write_capacity_backpressure\" | \"revision_required\" | \"revision_conflict\" | \"idempotency_conflict\" | \"source_changed\" | \"write_pending\" | \"storage_error\" | \"cancelled\" | \"permission_denied\" | \"scope_denied\" | \"invalid_params\" | \"not_found\" | \"page_not_found\" | \"page_identity_changed\" | \"write_claim_lost\" | \"request_too_large\" | \"response_too_large\" | \"writer_registration_required\" | \"writer_identity_invalid\" | \"writer_not_initialized\" | \"writer_coordinator_required\" | \"fact_already_expired\" | \"source_writeback_required\" | \"unsupported_mutation_protocol\" | \"writer_upgrade_required\" | \"writer_not_quiesced\" | \"skill_bundle_required\" | \"take_row_collision\" | \"invalid_source_uri\" | \"writer_admin_locked\" | \"connector_account_changed\" | \"connector_intent_outdated\" | \"checkpoint_validation_timeout\" | \"invalid_connector_text\" | \"connector_holds_exhausted\" | \"connector_fence_below_timeline\" | \"core_budget_exceeded\" | \"core_mark_owner_only\" | \"core_remote_edit_refused\" | \"core_delete_owner_only\" | \"timeline_rows_would_be_removed\" | \"purged_content\" | \"preparation_stalled\" | \"fence_unrenderable\" | \"page_body_segmented\" | \"revision_changed\" | \"tail_changed\" | \"write_outcome_unknown\" | \"write_interrupted\" | \"connection_inherited_read_only\" | \"owner_marker_missing\" | \"embedding_failed\" | \"bucket_not_found\" | \"database_error\" | \"unknown_transport\" | \"extraction_failed\" | \"fact_not_found\" | \"provenance_required\" | \"unavailable\" | \"budget_unsatisfiable\" | \"embedding_budget_below_worst_case\" | \"absent_from_worktree\" | \"access_command_failed\" | \"access_member_disabled\" | \"on_behalf_of_invalid_audience\" | \"on_behalf_of_unknown_member\" | \"on_behalf_of_not_permitted\" | \"actor_not_attested\" | \"actor_unlinked\" | \"on_behalf_of_in_arguments\" | \"access_policy_invalid\" | \"access_policy_pending\" | \"access_policy_widening_held\" | \"access_policy_store_mismatch\" | \"access_rule_invalid\" | \"access_member_id_retired\" | \"access_member_invalid\" | \"access_denied_test_user\" | \"access_env_missing\" | \"acknowledgment_unavailable\" | \"admin_policy_enforced\" | \"admission_paused\" | \"ambient_capture_off\" | \"ambiguous_id\" | \"ambiguous_ref\" | \"ambiguous_skill\" | \"answer_not_yours\" | \"answer_pending\" | \"answer_unavailable\" | \"api_not_enabled\" | \"approval_required\" | \"atom_drain_incomplete\" | \"atom_drain_no_progress\" | \"atom_drain_provider_failure\" | \"autopilot_job_owned_by_other_brain\" | \"body_staging_expired\" | \"budget_below_recent_runtime\" | \"backup_dump_failed\" | \"backup_too_large\" | \"belief_coverage_required\" | \"belief_stale_preparation\" | \"benchmark_duplicate_task_id\" | \"benchmark_empty\" | \"benchmark_exists\" | \"benchmark_judge_llm_no_rubric\" | \"benchmark_judge_qrels_no_expected\" | \"benchmark_judge_rule_no_checks\" | \"benchmark_judge_unknown_kind\" | \"benchmark_malformed\" | \"benchmark_missing_judge\" | \"benchmark_missing_task\" | \"benchmark_missing_task_id\" | \"benchmark_not_found\" | \"benchmark_rule_check_bad_arg\" | \"benchmark_rule_check_malformed\" | \"benchmark_rule_check_unknown_op\" | \"bootstrap_cleanup_pending\" | \"bootstrap_empty\" | \"bootstrap_pending_review\" | \"bridge_ownership_conflict\" | \"valid_time_undeclared\" | \"coverage_from\" | \"coverage_gap\" | \"clock_mismatch\" | \"extract_write_lost\" | \"item_failures_systemic\" | \"known_as_of_unproven\" | \"cache_quota_exceeded\" | \"calendar_unreadable\" | \"capacity_paused\" | \"catalog_capacity_exceeded\" | \"catalog_unavailable\" | \"host_upgrade_required\" | \"change_reason_rejected\" | \"changed_since_preview\" | \"chronicle_skipped\" | \"no_pricing\" | \"checkout_not_a_source\" | \"checkpoint_missing\" | \"claim_already_used\" | \"client_json_unreadable\" | \"client_json_wrong_type\" | \"client_not_found\" | \"client_shape_invalid\" | \"code_callees_requires_symbol\" | \"code_callers_requires_symbol\" | \"code_def_requires_symbol\" | \"code_refs_requires_symbol\" | \"code_reused\" | \"colon_slug_windows_write_through\" | \"command_failed\" | \"commit_lock_busy\" | \"commit_base_moved\" | \"commit_paths_invalid\" | \"commit_prestaged_paths\" | \"commit_outside_source_root\" | \"concurrent_write\" | \"config_error\" | \"confirmation_required\" | \"conflicting_source_scope\" | \"connection_lost\" | \"connector_access_denied\" | \"connector_auth_required\" | \"connector_binding_missing\" | \"connector_item_too_large\" | \"connector_response_too_large\" | \"connector_shape_drift\" | \"chunkless_pages_healable\" | \"consent_required\" | \"consent_timeout\" | \"consumers_without_heartbeat\" | \"content_repair_needs_human\" | \"content_null_bytes\" | \"content_rejected\" | \"continuation_unproven\" | \"corpus_chat_unavailable\" | \"corpus_window_backoff\" | \"corpus_window_dead_lettered\" | \"convergence_read_failed\" | \"cost_cap_exceeded\" | \"cost_preview_requires_yes\" | \"cursor_incarnation_retired\" | \"cycle_failed\" | \"d_sel_too_small\" | \"delta_cursor_upgrade_required\" | \"deleted_page_chunks_overdue\" | \"demo_graph_failed\" | \"downgrade_blocked_deferred_writes\" | \"demo_import_failed\" | \"demo_verification_failed\" | \"derived_cap_exhausted\" | \"destination_not_ready\" | \"drain_holder_stalled\" | \"drain_stalled\" | \"managed_sync_not_moving\" | \"dream_breaker_tripped\" | \"dirty_tree\" | \"doctor_tier_unavailable\" | \"effect_not_failed\" | \"embed_backfill_stalled\" | \"embedding_auth_failed\" | \"embedding_configuration\" | \"embedding_identity_unqualified\" | \"embedding_model_mismatch\" | \"embedding_plane_split\" | \"embedding_state_unknown\" | \"embedding_storage_unavailable\" | \"embedding_unavailable\" | \"embedding_unconfigured\" | \"embedding_width_mismatch\" | \"embedded_core_required\" | \"engine_embedding_mismatch\" | \"embedded_engine_required\" | \"engine_closed\" | \"engine_host_missing\" | \"engine_scope_missing\" | \"engine_scope_required\" | \"engine_settings_invalid\" | \"engine_graduated\" | \"entity_types_unavailable\" | \"eval_suite_unwired\" | \"explicit_tasks_conflict\" | \"export_limit\" | \"extractor_identity_mismatch\" | \"fact_withdrawn\" | \"fact_rows_collide\" | \"fence_row_changed\" | \"facts_absorb_write_refused\" | \"facts_backstop_skipped\" | \"facts_drain_deferred\" | \"facts_drain_job_failed\" | \"facts_payload_expired\" | \"feedback_disabled\" | \"feedback_not_authorized\" | \"fetch_failed\" | \"file_database_drift\" | \"fix_not_writable\" | \"file_drift\" | \"file_drift_mixed_selection\" | \"file_drift_state_required\" | \"file_removed_during_scan\" | \"file_unreadable\" | \"file_wins_rewrite\" | \"file_too_large\" | \"follow_approval_required\" | \"forget_requires_owner\" | \"reserved_frontmatter_key\" | \"generation_fenced\" | \"generation_held\" | \"generation_live_conflict\" | \"frontmatter_slug_conflict\" | \"full_resync_required\" | \"gate_failed\" | \"ghost_mass_delete_refused\" | \"notifier_stalled\" | \"origin_twin_mass_merge_refused\" | \"ghost_storage_unknown\" | \"git_branch_unborn\" | \"git_durability_not_enabled\" | \"git_checkout_required\" | \"git_worktree_link_broken\" | \"hosted_repo_refused\" | \"git_detached_head\" | \"git_index_conflict\" | \"git_index_locked\" | \"git_index_stale\" | \"git_target_pending\" | \"git_operation_in_progress\" | \"git_push_unavailable\" | \"git_target_changed\" | \"git_target_ignored\" | \"git_target_unsafe\" | \"git_unavailable\" | \"git_object_missing\" | \"git_conversion_blocked\" | \"git_conversion_delta\" | \"conversion_file_in_source_root\" | \"git_conversion_incomplete\" | \"git_home_required\" | \"git_private_commit_refused\" | \"git_protocol_required\" | \"git_lfs_not_enabled\" | \"gitlink_not_followed\" | \"graduation_drain_timeout\" | \"graduation_embedding_dimension_mismatch\" | \"graduation_foreign_host_binding\" | \"graduation_in_progress\" | \"graduation_interrupted\" | \"graduation_rollback_writes_lost\" | \"graduation_source_writer_held\" | \"graduation_split_brain\" | \"graduation_target_auth_failed\" | \"graduation_target_ddl_unreachable\" | \"graduation_target_not_empty\" | \"graduation_target_unsupported\" | \"graduation_unclassified_table\" | \"graduation_unsupported_platform\" | \"graduation_verify_failed\" | \"grant_scope\" | \"graph_incomplete\" | \"host_identity_mismatch\" | \"harness_hook_duplicates\" | \"harness_hook_unowned\" | \"head_blocked\" | \"held_failed\" | \"held_out_overlaps_benchmark\" | \"held_out_required_for_bundled\" | \"independent_principal_required\" | \"insufficient_scope\" | \"integrate_conflict\" | \"internal\" | \"internal_error\" | \"interrupted\" | \"invalid_acknowledgment\" | \"invalid_client\" | \"invalid_fence\" | \"unclosed_ambiguous_tail\" | \"tail_exposure_approval\" | \"sync_in_progress\" | \"invalid_frontmatter\" | \"invalid_grant_clock_skew\" | \"invalid_grant_revoked\" | \"invalid_grant_testing_expiry\" | \"invalid_rating\" | \"invalid_receipt\" | \"invalid_receipt_transition\" | \"invalid_request\" | \"invalid_source\" | \"invalid_source_pin\" | \"invalid_token\" | \"invalid_write_wait\" | \"ipc_path_too_long\" | \"legacy_twin_mass_merge_refused\" | \"legacy_twins_storage_unknown\" | \"legacy_job_selection_invalid\" | \"legacy_jobs_active\" | \"legacy_lock_removal_refused\" | \"link_cursor_invalid\" | \"local_conflict\" | \"lock_busy\" | \"loops_extraction_skipped\" | \"maintenance_backpressure\" | \"maintenance_lock_busy\" | \"managed_failure_unsettled\" | \"managed_remedy_unavailable\" | \"memory_setting_write_outcome_unknown\" | \"merge_recommended\" | \"movement_unknown\" | \"managed_sync_flag_refused\" | \"managed_pull_skipped\" | \"manual_only_skipped\" | \"membership_inactive\" | \"membership_not_found\" | \"method_not_allowed\" | \"migration_lease_lost\" | \"migration_declined\" | \"migration_failed\" | \"migration_host_work_pending\" | \"migrations_pending\" | \"migrations_running\" | \"missing_source_scope\" | \"missing_source_value\" | \"models_strict_violation\" | \"no_context_ceiling\" | \"no_refresh_token\" | \"no_routing_eval\" | \"no_skill_md\" | \"no_worker\" | \"no_worker_surface\" | \"not_a_git_repo\" | \"not_converged\" | \"not_owner_host\" | \"not_connected\" | \"no_brain\" | \"overlapping_path\" | \"page_projection_conflict\" | \"page_body_rows_unreadable\" | \"page_projection_stale\" | \"page_shrink_refused\" | \"page_too_large_for_inline\" | \"parse_error\" | \"part_splits_code_point\" | \"part_too_large\" | \"frontmatter_alias_limit\" | \"parser_regression\" | \"pasted_wrong_url\" | \"payload_too_large\" | \"path_not_utf8\" | \"pattern_claims_pending\" | \"patterns_min_interval\" | \"pending_verify\" | \"pending_writes\" | \"persistence_restart_required\" | \"pool_inflight_over_budget\" | \"deep_health_probe_failed\" | \"refresh_required\" | \"serve_self_exit_suppressed\" | \"serve_unhealthy_exit\" | \"persistence_write_stall\" | \"push_unconfirmed\" | \"schema_lock_blocked\" | \"pg_connection_recovery_failed\" | \"pg_connection_stuck\" | \"pg_pool_stalled\" | \"pg_statement_build_failed\" | \"pglite_busy\" | \"pglite_vector_index_too_large\" | \"plan_output_failed\" | \"plan_stale\" | \"port_in_use\" | \"preview_changed\" | \"profile_incompatible\" | \"projection_owner_resident\" | \"knock_on_exhausted\" | \"keyword_skipped_after_timeout\" | \"publication_pending\" | \"pull_blocked_local_changes\" | \"purge_blocked_pending_recovery\" | \"purge_lookup_timeout\" | \"purge_mirror_unwritable\" | \"question_not_found\" | \"question_owner_only\" | \"rank_entities_timeout\" | \"read_budget_exhausted\" | \"reason_purge_scan_capped\" | \"reason_purge_scan_failed\" | \"reason_scan_capped\" | \"reason_scan_failed\" | \"reason_trailer_secret\" | \"receipt_conflict\" | \"receipt_fence_changed\" | \"receipt_fence_required\" | \"receipt_identity_mismatch\" | \"pat_file_unreadable\" | \"reconcile_host_required\" | \"reconcile_read_incomplete\" | \"recovery_prior_stage_unavailable\" | \"recovery_version_unsupported\" | \"redirect_uri_mismatch\" | \"ref_not_in_answer\" | \"refresh_dirty\" | \"refresh_diverged\" | \"refresh_drain_timeout\" | \"refresh_lock_timeout\" | \"refresh_no_upstream\" | \"refresh_not_managed\" | \"refresh_not_owner\" | \"pending_import_expired\" | \"refresh_barrier_expired\" | \"refresh_source_changed\" | \"refresh_sync_timeout\" | \"relay_disabled\" | \"relay_session_expired\" | \"relay_unreachable\" | \"rename_held\" | \"rename_identity_unreadable\" | \"rename_reconcile_failed\" | \"repair_preview_timeout\" | \"request_already_submitted\" | \"requirements_changed\" | \"requires_local_engine\" | \"restart_refused\" | \"restart_unverified\" | \"runtime_build_skew\" | \"reset_upstream_refused\" | \"resume_spec_mismatch\" | \"result_too_large\" | \"revision_backfill_pending\" | \"revision_unavailable\" | \"schema_owner_required\" | \"scope_missing\" | \"search_cursor_requires_keyword\" | \"search_mode_local_only\" | \"scorecard_group_by_local_only\" | \"search_offset_over_cap\" | \"segmented_mirror_writer_gate\" | \"serve_build_drift\" | \"serve_port_in_use\" | \"serve_status_only\" | \"settle_mismatch\" | \"setup_harness_unsupported\" | \"setup_hosted_connection\" | \"setup_owner_conflict\" | \"hook_session_cwd\" | \"turn_hook_not_loaded\" | \"shared_skills_unavailable\" | \"shared_skills_unsupported\" | \"skill_asset_not_found\" | \"skill_candidate_invalid\" | \"skill_not_found\" | \"skill_retention_capacity\" | \"skill_unavailable\" | \"slug_page_mismatch\" | \"slug_root_mode_mismatch\" | \"source_binding_required\" | \"source_id_taken\" | \"source_mismatch\" | \"source_not_ready\" | \"source_profile_no_backfill\" | \"source_referenced\" | \"source_root_conflict\" | \"sources_not_readable\" | \"split_bad_ratio\" | \"split_unparseable\" | \"stable_channel_unresolved\" | \"stable_invalid\" | \"stable_missing\" | \"stable_unreadable\" | \"stale_unavailable\" | \"state_mismatch\" | \"store_unavailable\" | \"storage_card_exists\" | \"storage_manifest_missing\" | \"storage_record_invalid\" | \"storage_record_secret\" | \"storage_revision_conflict\" | \"storage_source_managed\" | \"strict_requires_managed\" | \"sync_anchor_relative\" | \"sync_not_applicable\" | \"sync_admission_restricted\" | \"sync_deadline_stalled\" | \"sync_drain_lease_held\" | \"content_receipt_stale\" | \"sync_first_run_in_progress\" | \"sync_no_successful_sync\" | \"sync_cursor_replaced\" | \"sync_pass_superseded\" | \"sync_parser_regression\" | \"target_escape\" | \"timeline_comment_markup\" | \"readable_by_invalid\" | \"topology_change_required\" | \"transcript_secret_exposure\" | \"transcript_source_mismatch\" | \"triage_unreliable_backoff\" | \"trust_raise_refused\" | \"two_consumers_on_host\" | \"trusted_local_only\" | \"unexpected_file_bytes\" | \"unexpected_staging_bytes\" | \"unknown_command\" | \"unknown_flag\" | \"unknown_method\" | \"unknown_source\" | \"unknown_tool\" | \"unpriced_model\" | \"unmanaged_database_path\" | \"unmanaged_path\" | \"unsupported_export_data\" | \"unsupported_path\" | \"upload_expired\" | \"upload_not_found\" | \"upload_protected_content\" | \"upload_too_many_parts\" | \"upstream\" | \"upstream_diverged\" | \"upstream_rewritten\" | \"upstream_unknown\" | \"vector_prewarm_extension_missing\" | \"vector_prewarm_unsupported_engine\" | \"vector_prewarm_wont_fit\" | \"verification_failed\" | \"visibility_noncanonical\" | \"visibility_not_applied\" | \"wakeshift_key_invalid\" | \"wakeshift_needs_conversation\" | \"wakeshift_not_enabled\" | \"wakeshift_refused\" | \"wakeshift_shared_brain\" | \"wakeshift_unavailable\" | \"withdrawal_capacity\" | \"withdrawal_mirror_failed\" | \"withdrawal_mirror_pending\" | \"withdrawal_provenance\" | \"write_capacity_low\" | \"write_gate_rejected\" | \"write_held\" | \"worktree_dirty\" | \"worktree_refreshing\" | \"writer_admin_intent_required\" | \"writer_admin_state_changed\" | \"writer_busy\" | \"writer_identity_publish_failed\" | \"writer_manifest_mismatch\" | \"writer_manifest_rescope_required\" | \"writer_manifest_unsafe\" | \"writer_regrant_required\" | \"writer_transfer_conflict\" | \"writer_transfer_required\" | \"wrong_account_consented\" | \"schema_pack_too_large\" | \"schema_pack_emit_mismatch\" | undefined",+ "canonical?: \"unknown\" | \"timeout\" | \"keyword_candidates_incomplete\" | \"projection_pending\" | \"rate_limited\" | \"embedding_disabled\" | \"writer_lock_unavailable\" | \"writer_pool_capacity\" | \"owner_unavailable\" | \"recovery_required\" | \"queue_capacity\" | \"write_quota_exhausted\" | \"write_quota_insufficient\" | \"write_capacity_backpressure\" | \"revision_required\" | \"revision_conflict\" | \"idempotency_conflict\" | \"source_changed\" | \"write_pending\" | \"storage_error\" | \"cancelled\" | \"permission_denied\" | \"scope_denied\" | \"invalid_params\" | \"not_found\" | \"page_not_found\" | \"page_identity_changed\" | \"write_claim_lost\" | \"request_too_large\" | \"response_too_large\" | \"writer_registration_required\" | \"writer_identity_invalid\" | \"writer_not_initialized\" | \"writer_coordinator_required\" | \"fact_already_expired\" | \"source_writeback_required\" | \"unsupported_mutation_protocol\" | \"writer_upgrade_required\" | \"writer_not_quiesced\" | \"skill_bundle_required\" | \"take_row_collision\" | \"invalid_source_uri\" | \"writer_admin_locked\" | \"connector_account_changed\" | \"connector_intent_outdated\" | \"checkpoint_validation_timeout\" | \"invalid_connector_text\" | \"connector_holds_exhausted\" | \"connector_fence_below_timeline\" | \"core_budget_exceeded\" | \"core_mark_owner_only\" | \"core_remote_edit_refused\" | \"core_delete_owner_only\" | \"timeline_rows_would_be_removed\" | \"purged_content\" | \"preparation_stalled\" | \"fence_unrenderable\" | \"page_body_segmented\" | \"revision_changed\" | \"tail_changed\" | \"write_outcome_unknown\" | \"write_interrupted\" | \"connection_inherited_read_only\" | \"owner_marker_missing\" | \"embedding_failed\" | \"bucket_not_found\" | \"database_error\" | \"unknown_transport\" | \"extraction_failed\" | \"fact_not_found\" | \"provenance_required\" | \"unavailable\" | \"budget_unsatisfiable\" | \"embedding_budget_below_worst_case\" | \"absent_from_worktree\" | \"access_command_failed\" | \"access_member_disabled\" | \"on_behalf_of_invalid_audience\" | \"on_behalf_of_unknown_member\" | \"on_behalf_of_not_permitted\" | \"actor_not_attested\" | \"actor_unlinked\" | \"on_behalf_of_in_arguments\" | \"access_policy_invalid\" | \"access_policy_pending\" | \"access_policy_widening_held\" | \"access_policy_store_mismatch\" | \"access_rule_invalid\" | \"access_member_id_retired\" | \"access_member_invalid\" | \"access_denied_test_user\" | \"access_env_missing\" | \"acknowledgment_unavailable\" | \"admin_policy_enforced\" | \"admission_paused\" | \"ambient_capture_off\" | \"ambiguous_id\" | \"ambiguous_ref\" | \"ambiguous_skill\" | \"answer_not_yours\" | \"answer_pending\" | \"answer_unavailable\" | \"api_not_enabled\" | \"approval_required\" | \"atom_drain_incomplete\" | \"atom_drain_no_progress\" | \"atom_drain_provider_failure\" | \"autopilot_job_owned_by_other_brain\" | \"body_staging_expired\" | \"budget_below_recent_runtime\" | \"backup_dump_failed\" | \"backup_too_large\" | \"belief_coverage_required\" | \"belief_stale_preparation\" | \"benchmark_duplicate_task_id\" | \"benchmark_empty\" | \"benchmark_exists\" | \"benchmark_judge_llm_no_rubric\" | \"benchmark_judge_qrels_no_expected\" | \"benchmark_judge_rule_no_checks\" | \"benchmark_judge_unknown_kind\" | \"benchmark_malformed\" | \"benchmark_missing_judge\" | \"benchmark_missing_task\" | \"benchmark_missing_task_id\" | \"benchmark_not_found\" | \"benchmark_rule_check_bad_arg\" | \"benchmark_rule_check_malformed\" | \"benchmark_rule_check_unknown_op\" | \"bootstrap_cleanup_pending\" | \"bootstrap_empty\" | \"bootstrap_pending_review\" | \"bridge_ownership_conflict\" | \"valid_time_undeclared\" | \"coverage_from\" | \"coverage_gap\" | \"clock_mismatch\" | \"extract_write_lost\" | \"item_failures_systemic\" | \"known_as_of_unproven\" | \"cache_quota_exceeded\" | \"calendar_unreadable\" | \"capacity_paused\" | \"catalog_capacity_exceeded\" | \"catalog_unavailable\" | \"host_upgrade_required\" | \"change_reason_rejected\" | \"changed_since_preview\" | \"chronicle_skipped\" | \"no_pricing\" | \"checkout_not_a_source\" | \"checkpoint_missing\" | \"claim_already_used\" | \"client_json_unreadable\" | \"client_json_wrong_type\" | \"client_not_found\" | \"client_shape_invalid\" | \"code_callees_requires_symbol\" | \"code_callers_requires_symbol\" | \"code_def_requires_symbol\" | \"code_refs_requires_symbol\" | \"code_reused\" | \"colon_slug_windows_write_through\" | \"command_failed\" | \"commit_lock_busy\" | \"commit_base_moved\" | \"commit_paths_invalid\" | \"commit_prestaged_paths\" | \"commit_outside_source_root\" | \"concurrent_write\" | \"config_error\" | \"confirmation_required\" | \"conflicting_source_scope\" | \"connection_lost\" | \"connector_access_denied\" | \"connector_auth_required\" | \"connector_binding_missing\" | \"connector_item_too_large\" | \"connector_response_too_large\" | \"connector_shape_drift\" | \"chunkless_pages_healable\" | \"consent_required\" | \"consent_timeout\" | \"consumers_without_heartbeat\" | \"content_repair_needs_human\" | \"content_null_bytes\" | \"content_rejected\" | \"continuation_unproven\" | \"corpus_chat_unavailable\" | \"corpus_window_backoff\" | \"corpus_window_dead_lettered\" | \"convergence_read_failed\" | \"cost_cap_exceeded\" | \"cost_preview_requires_yes\" | \"cursor_incarnation_retired\" | \"cycle_failed\" | \"d_sel_too_small\" | \"delta_cursor_upgrade_required\" | \"deleted_page_chunks_overdue\" | \"demo_graph_failed\" | \"downgrade_blocked_deferred_writes\" | \"demo_import_failed\" | \"demo_verification_failed\" | \"derived_cap_exhausted\" | \"destination_not_ready\" | \"drain_holder_stalled\" | \"drain_stalled\" | \"managed_sync_not_moving\" | \"dream_breaker_tripped\" | \"dirty_tree\" | \"doctor_tier_unavailable\" | \"effect_not_failed\" | \"embed_backfill_stalled\" | \"embedding_auth_failed\" | \"embedding_configuration\" | \"embedding_identity_unqualified\" | \"embedding_model_mismatch\" | \"embedding_plane_split\" | \"embedding_state_unknown\" | \"embedding_storage_unavailable\" | \"embedding_unavailable\" | \"embedding_unconfigured\" | \"embedding_width_mismatch\" | \"embedded_core_required\" | \"engine_embedding_mismatch\" | \"embedded_engine_required\" | \"engine_closed\" | \"engine_host_missing\" | \"engine_scope_missing\" | \"engine_scope_required\" | \"engine_settings_invalid\" | \"engine_graduated\" | \"entity_types_unavailable\" | \"eval_suite_unwired\" | \"explicit_tasks_conflict\" | \"export_limit\" | \"extractor_identity_mismatch\" | \"fact_withdrawn\" | \"fact_rows_collide\" | \"fence_row_changed\" | \"facts_absorb_write_refused\" | \"facts_backstop_skipped\" | \"facts_drain_deferred\" | \"facts_drain_job_failed\" | \"facts_payload_expired\" | \"feedback_disabled\" | \"feedback_not_authorized\" | \"fetch_failed\" | \"file_database_drift\" | \"fix_not_writable\" | \"file_drift\" | \"file_drift_mixed_selection\" | \"file_drift_state_required\" | \"file_removed_during_scan\" | \"file_unreadable\" | \"file_wins_rewrite\" | \"file_too_large\" | \"follow_approval_required\" | \"forget_requires_owner\" | \"reserved_frontmatter_key\" | \"generation_fenced\" | \"generation_held\" | \"generation_live_conflict\" | \"frontmatter_slug_conflict\" | \"full_resync_required\" | \"gate_failed\" | \"ghost_mass_delete_refused\" | \"notifier_stalled\" | \"origin_twin_mass_merge_refused\" | \"ghost_storage_unknown\" | \"git_branch_unborn\" | \"git_durability_not_enabled\" | \"git_checkout_required\" | \"git_worktree_link_broken\" | \"hosted_repo_refused\" | \"git_detached_head\" | \"git_index_conflict\" | \"git_index_locked\" | \"git_index_stale\" | \"git_target_pending\" | \"git_operation_in_progress\" | \"git_push_unavailable\" | \"git_target_changed\" | \"git_target_ignored\" | \"git_target_unsafe\" | \"git_unavailable\" | \"git_object_missing\" | \"git_conversion_blocked\" | \"git_conversion_delta\" | \"conversion_file_in_source_root\" | \"git_conversion_incomplete\" | \"git_home_required\" | \"git_private_commit_refused\" | \"git_protocol_required\" | \"git_lfs_not_enabled\" | \"gitlink_not_followed\" | \"graduation_drain_timeout\" | \"graduation_embedding_dimension_mismatch\" | \"graduation_foreign_host_binding\" | \"graduation_in_progress\" | \"graduation_interrupted\" | \"graduation_rollback_writes_lost\" | \"graduation_source_writer_held\" | \"graduation_split_brain\" | \"graduation_target_auth_failed\" | \"graduation_target_ddl_unreachable\" | \"graduation_target_not_empty\" | \"graduation_target_unsupported\" | \"graduation_unclassified_table\" | \"graduation_unsupported_platform\" | \"graduation_verify_failed\" | \"grant_scope\" | \"graph_incomplete\" | \"host_identity_mismatch\" | \"harness_hook_duplicates\" | \"harness_hook_unowned\" | \"head_blocked\" | \"held_failed\" | \"held_out_overlaps_benchmark\" | \"held_out_required_for_bundled\" | \"independent_principal_required\" | \"insufficient_scope\" | \"integrate_conflict\" | \"internal\" | \"internal_error\" | \"interrupted\" | \"invalid_acknowledgment\" | \"invalid_client\" | \"invalid_fence\" | \"unclosed_ambiguous_tail\" | \"tail_exposure_approval\" | \"sync_in_progress\" | \"invalid_frontmatter\" | \"invalid_grant_clock_skew\" | \"invalid_grant_revoked\" | \"invalid_grant_testing_expiry\" | \"invalid_rating\" | \"invalid_receipt\" | \"invalid_receipt_transition\" | \"invalid_request\" | \"invalid_source\" | \"invalid_source_pin\" | \"invalid_token\" | \"invalid_write_wait\" | \"ipc_path_too_long\" | \"legacy_twin_mass_merge_refused\" | \"legacy_twins_storage_unknown\" | \"legacy_job_selection_invalid\" | \"legacy_jobs_active\" | \"legacy_lock_removal_refused\" | \"link_cursor_invalid\" | \"local_conflict\" | \"lock_busy\" | \"loops_extraction_skipped\" | \"maintenance_backpressure\" | \"maintenance_lock_busy\" | \"managed_failure_unsettled\" | \"managed_remedy_unavailable\" | \"memory_setting_write_outcome_unknown\" | \"merge_recommended\" | \"movement_unknown\" | \"managed_sync_flag_refused\" | \"managed_pull_skipped\" | \"manual_only_skipped\" | \"membership_inactive\" | \"membership_not_found\" | \"method_not_allowed\" | \"migration_lease_lost\" | \"migration_declined\" | \"migration_failed\" | \"migration_host_work_pending\" | \"migrations_pending\" | \"migrations_running\" | \"missing_source_scope\" | \"missing_source_value\" | \"models_strict_violation\" | \"no_context_ceiling\" | \"no_refresh_token\" | \"no_routing_eval\" | \"no_skill_md\" | \"no_worker\" | \"no_worker_surface\" | \"not_a_git_repo\" | \"not_converged\" | \"not_owner_host\" | \"not_connected\" | \"no_brain\" | \"overlapping_path\" | \"page_projection_conflict\" | \"page_body_rows_unreadable\" | \"page_projection_stale\" | \"page_shrink_refused\" | \"page_too_large_for_inline\" | \"parse_error\" | \"part_splits_code_point\" | \"part_too_large\" | \"frontmatter_alias_limit\" | \"parser_regression\" | \"pasted_wrong_url\" | \"payload_too_large\" | \"path_not_utf8\" | \"pattern_claims_pending\" | \"patterns_min_interval\" | \"pending_verify\" | \"pending_writes\" | \"persistence_restart_required\" | \"pool_inflight_over_budget\" | \"deep_health_probe_failed\" | \"refresh_required\" | \"serve_self_exit_suppressed\" | \"serve_unhealthy_exit\" | \"persistence_write_stall\" | \"push_unconfirmed\" | \"schema_lock_blocked\" | \"pg_connection_recovery_failed\" | \"pg_connection_stuck\" | \"pg_pool_stalled\" | \"pg_statement_build_failed\" | \"pglite_busy\" | \"pglite_vector_index_too_large\" | \"plan_output_failed\" | \"plan_stale\" | \"port_in_use\" | \"preview_changed\" | \"profile_incompatible\" | \"projection_owner_resident\" | \"knock_on_exhausted\" | \"keyword_skipped_after_timeout\" | \"publication_pending\" | \"pull_blocked_local_changes\" | \"purge_blocked_pending_recovery\" | \"purge_lookup_timeout\" | \"purge_mirror_unwritable\" | \"question_not_found\" | \"question_owner_only\" | \"rank_entities_timeout\" | \"read_budget_exhausted\" | \"reason_purge_scan_capped\" | \"reason_purge_scan_failed\" | \"reason_scan_capped\" | \"reason_scan_failed\" | \"reason_trailer_secret\" | \"receipt_conflict\" | \"receipt_fence_changed\" | \"receipt_fence_required\" | \"receipt_identity_mismatch\" | \"pat_file_unreadable\" | \"reconcile_host_required\" | \"reconcile_read_incomplete\" | \"recovery_prior_stage_unavailable\" | \"recovery_version_unsupported\" | \"redirect_uri_mismatch\" | \"ref_not_in_answer\" | \"refresh_dirty\" | \"refresh_diverged\" | \"refresh_drain_timeout\" | \"refresh_lock_timeout\" | \"refresh_no_upstream\" | \"refresh_not_managed\" | \"refresh_not_owner\" | \"pending_import_expired\" | \"refresh_barrier_expired\" | \"refresh_source_changed\" | \"refresh_sync_timeout\" | \"relay_disabled\" | \"relay_session_expired\" | \"relay_unreachable\" | \"rename_held\" | \"rename_identity_unreadable\" | \"rename_reconcile_failed\" | \"repair_preview_timeout\" | \"request_already_submitted\" | \"requirements_changed\" | \"requires_local_engine\" | \"restart_refused\" | \"restart_unverified\" | \"runtime_build_skew\" | \"reset_upstream_refused\" | \"resume_spec_mismatch\" | \"result_too_large\" | \"revision_backfill_pending\" | \"revision_unavailable\" | \"schema_owner_required\" | \"scope_missing\" | \"search_cursor_requires_keyword\" | \"search_mode_local_only\" | \"scorecard_group_by_local_only\" | \"search_offset_over_cap\" | \"segmented_mirror_writer_gate\" | \"serve_build_drift\" | \"serve_port_in_use\" | \"serve_status_only\" | \"settle_mismatch\" | \"setup_harness_unsupported\" | \"setup_hosted_connection\" | \"setup_owner_conflict\" | \"hook_session_cwd\" | \"turn_hook_not_loaded\" | \"shared_skills_unavailable\" | \"shared_skills_unsupported\" | \"skill_asset_not_found\" | \"skill_candidate_invalid\" | \"skill_not_found\" | \"skill_retention_capacity\" | \"skill_unavailable\" | \"slug_page_mismatch\" | \"slug_root_mode_mismatch\" | \"source_binding_required\" | \"source_id_taken\" | \"source_mismatch\" | \"source_not_ready\" | \"source_profile_no_backfill\" | \"source_referenced\" | \"source_root_conflict\" | \"sources_not_readable\" | \"split_bad_ratio\" | \"split_unparseable\" | \"stable_channel_unresolved\" | \"stable_invalid\" | \"stable_missing\" | \"stable_unreadable\" | \"stale_unavailable\" | \"state_mismatch\" | \"store_unavailable\" | \"storage_adopt_field_refused\" | \"storage_adopt_unverified\" | \"storage_card_exists\" | \"storage_manifest_missing\" | \"storage_record_invalid\" | \"storage_record_secret\" | \"storage_revision_conflict\" | \"storage_source_managed\" | \"strict_requires_managed\" | \"sync_anchor_relative\" | \"sync_not_applicable\" | \"sync_admission_restricted\" | \"sync_deadline_stalled\" | \"sync_drain_lease_held\" | \"content_receipt_stale\" | \"sync_first_run_in_progress\" | \"sync_no_successful_sync\" | \"sync_cursor_replaced\" | \"sync_pass_superseded\" | \"sync_parser_regression\" | \"target_escape\" | \"timeline_comment_markup\" | \"readable_by_invalid\" | \"topology_change_required\" | \"transcript_secret_exposure\" | \"transcript_source_mismatch\" | \"triage_unreliable_backoff\" | \"trust_raise_refused\" | \"two_consumers_on_host\" | \"trusted_local_only\" | \"unexpected_file_bytes\" | \"unexpected_staging_bytes\" | \"unknown_command\" | \"unknown_flag\" | \"unknown_method\" | \"unknown_source\" | \"unknown_tool\" | \"unpriced_model\" | \"unmanaged_database_path\" | \"unmanaged_path\" | \"unsupported_export_data\" | \"unsupported_path\" | \"upload_expired\" | \"upload_not_found\" | \"upload_protected_content\" | \"upload_too_many_parts\" | \"upstream\" | \"upstream_diverged\" | \"upstream_rewritten\" | \"upstream_unknown\" | \"vector_prewarm_extension_missing\" | \"vector_prewarm_unsupported_engine\" | \"vector_prewarm_wont_fit\" | \"verification_failed\" | \"visibility_noncanonical\" | \"visibility_not_applied\" | \"wakeshift_key_invalid\" | \"wakeshift_needs_conversation\" | \"wakeshift_not_enabled\" | \"wakeshift_refused\" | \"wakeshift_shared_brain\" | \"wakeshift_unavailable\" | \"withdrawal_capacity\" | \"withdrawal_mirror_failed\" | \"withdrawal_mirror_pending\" | \"withdrawal_provenance\" | \"write_capacity_low\" | \"write_gate_rejected\" | \"write_held\" | \"worktree_dirty\" | \"worktree_refreshing\" | \"writer_admin_intent_required\" | \"writer_admin_state_changed\" | \"writer_busy\" | \"writer_identity_publish_failed\" | \"writer_manifest_mismatch\" | \"writer_manifest_rescope_required\" | \"writer_manifest_unsafe\" | \"writer_regrant_required\" | \"writer_transfer_conflict\" | \"writer_transfer_required\" | \"wrong_account_consented\" | \"schema_pack_too_large\" | \"schema_pack_emit_mismatch\" | undefined","canonicalCode: string","cause?: unknown","code: ErrorCode",diff --git a/test/storage-manifest-adopt-hosted.serial.test.ts b/test/storage-manifest-adopt-hosted.serial.test.tsnew file mode 100644index 0000000000..d5ebf0df82--- /dev/null+++ b/test/storage-manifest-adopt-hosted.serial.test.ts@@ -0,0 +1,59 @@+/**+ * GST-1943: `gbrain storage adopt` and JSONL import on a brain with a Git checkout (managed persistence, PGLite). Git stays+ * the parent. Protects:+ * - adopt and import refuse storage_manifest_missing until storage init has hosted the shelf, and write nothing;+ * - after init, the adopt apply commits each card to the hosted repository (origin adopt) and tags the original through+ * its own source's page door, deleting nothing; finalize then soft-deletes the original.+ * .serial: real git subprocesses and a GBRAIN_HOME swap.+ */+import { describe, expect, test } from 'bun:test';+import { dirname, join } from 'node:path';+import { randomUUID } from 'node:crypto';+import { operationsByName } from '../src/core/operations.ts';+import type { OperationContext } from '../src/core/ops/contract.ts';+import { initStorageSource } from '../src/core/storage-manifest/source.ts';+import { applyAdopt, applyFinalize, previewAdopt, previewFinalize } from '../src/core/storage-manifest/adopt.ts';+import { previewImport } from '../src/core/storage-manifest/jsonl.ts';+import { git } from './helpers/git-publication.ts';+import { managedBrain } from './helpers/managed-brain.ts';++const call = (ctx: OperationContext, name: string, params: Record<string, unknown>) => operationsByName[name]!.handler(ctx, params) as Promise<Record<string, any>>;+const refusal = (promise: Promise<unknown>) => promise.then(() => null, (e: { code?: string; canonical?: string }) => e.canonical ?? e.code ?? 'error');+const FENCE = '```';+const record = (id: string) => ({ id, title: `Archive ${id}`, kind: 'directory',+ locations: [{ store: 'b2', bucket: 'bucket-a', path: `/archive/${id}`, tool: 'restic', repository: 'archive/restic', snapshot: 'c'.repeat(64), size_bytes: 4096, hash_kind: 'sha256-tree-v1' }],+ original_path: `/srv/data/${id}`, restore: { skill: 'restore-data', args: { id }, command: 'restic restore latest' } });+const opts = { sourceId: 'default', prefix: 'storage-manifest/' };++describe('storage adopt on a brain with a Git checkout', () => {+ test('adopt and import wait for storage init; then cards are committed first and originals are tagged, then finalized', () => managedBrain(async ({ engine, ctx, root }) => {+ await call(ctx, 'put_page', { slug: 'storage-manifest/runs-2026', request_id: randomUUID(),+ content: `---\ntype: stored-object\ntitle: Interim runs\n---\n## Record\n\n${FENCE}json\n${JSON.stringify(record('runs-2026'))}\n${FENCE}\n` });+ expect(await refusal(previewAdopt(ctx, opts))).toBe('storage_manifest_missing');+ expect(await refusal(previewImport(engine, 'shelf.jsonl', JSON.stringify({ ...record('runs-2026'), restore: { skill: 'restore-data' } })))).toBe('storage_manifest_missing');+ expect(await engine.executeRaw("SELECT 1 FROM sources WHERE id='storage'")).toEqual([]);++ const dir = join(dirname(root), 'shelf');+ const preview = await initStorageSource(engine, { dir, dryRun: true });+ await initStorageSource(engine, { dir, dryRun: false, expect: preview.plan!.plan_hash });+ const repository = join(dir, 'repo.git');+ const before = Number(git(repository, 'rev-list', '--count', 'main'));++ const plan = await previewAdopt(ctx, opts);+ expect(plan).toMatchObject({ shelf: 'exists', drop_fields: ['restore.command'], counts: { register: 1 } });+ const applied = await applyAdopt(ctx, { ...opts, expect: plan.plan_hash, dropFields: ['restore.command'] });+ expect(applied).toMatchObject({ side_effects: 'complete' });+ expect(Number(git(repository, 'rev-list', '--count', 'main'))).toBe(before + 1);+ const file = git(repository, 'ls-tree', '-r', '--name-only', 'main').split('\n').find((path) => path.includes('runs-2026'));+ const committed = git(repository, 'show', `main:${file}`);+ expect(committed).toContain('origin: adopt');+ expect(committed).not.toContain('restic restore latest');+ expect(await engine.executeRaw("SELECT t.tag FROM tags t JOIN pages p ON p.id = t.page_id WHERE p.source_id='default' AND p.slug='storage-manifest/runs-2026'")).toContainEqual({ tag: 'storage-manifest-adopted' });+ expect(await engine.executeRaw("SELECT 1 FROM pages WHERE source_id='default' AND deleted_at IS NOT NULL")).toEqual([]);++ const finalize = await previewFinalize(ctx, opts);+ expect(finalize.entries.map((e) => e.state)).toEqual(['delete']);+ expect(await applyFinalize(ctx, { ...opts, expect: finalize.plan_hash })).toMatchObject({ side_effects: 'complete', deleted: ['storage-manifest/runs-2026'] });+ expect((await call(ctx, 'storage_get', { id: 'runs-2026' })).origin).toBe('adopt');+ }), 90_000);+});diff --git a/test/storage-manifest-adopt.test.ts b/test/storage-manifest-adopt.test.tsnew file mode 100644index 0000000000..50cbc3c6b7--- /dev/null+++ b/test/storage-manifest-adopt.test.ts@@ -0,0 +1,215 @@+/**+ * GST-1943: `gbrain storage adopt` on a repo-less brain (PGLite; the database is the record). Protects:+ * - the preview maps each interim stored-object page under the prefix (never the index page) onto a card, lists every+ * refused field with its reason, and writes nothing;+ * - the apply needs the preview's plan_hash (a stale one refuses preview_changed) and each refused field named with+ * --drop-field (storage_adopt_field_refused otherwise); it registers each card with origin adopt and tags the+ * original storage-manifest-adopted, and never soft-deletes anything;+ * - a credential-shaped value refuses storage_record_secret whatever else is dropped, without echoing the value;+ * - idempotent: a card already on the shelf that matches is tagged only, a rerun writes nothing, and the plan_hash a+ * half-finished run printed still applies; a differing card is a conflict, never overwritten, its original untagged;+ * - finalize previews, then soft-deletes only the tagged originals whose card matches (storage_adopt_unverified when+ * one differs), restorable afterwards;+ * - a brain with a Git checkout refuses storage_manifest_missing until storage init has run.+ */+import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';+import { randomUUID } from 'node:crypto';+import { PGLiteEngine } from '../src/core/pglite-engine.ts';+import { operationsByName } from '../src/core/operations.ts';+import type { OperationContext } from '../src/core/ops/contract.ts';+import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';+import { applyAdopt, applyFinalize, previewAdopt, previewFinalize, ADOPTED_TAG } from '../src/core/storage-manifest/adopt.ts';+import { resetPgliteState } from './helpers/reset-pglite.ts';++let engine: PGLiteEngine;++beforeAll(async () => {+ engine = new PGLiteEngine();+ await engine.connect({});+ await engine.initSchema();+}, 60_000);+afterAll(async () => {+ await disposePersistenceConsumer(engine);+ await engine.disconnect();+}, 60_000);+beforeEach(async () => {+ await disposePersistenceConsumer(engine);+ await resetPgliteState(engine);+ await engine.unsetConfig('sync.repo_path');+});++const ctx = (): OperationContext => ({+ engine, config: { engine: engine.kind, embedding_disabled: true } as OperationContext['config'],+ logger: { info() {}, warn() {}, error() {} }, dryRun: false, remote: false, sourceId: 'default',+}) as OperationContext;+const call = (name: string, params: Record<string, unknown>) => operationsByName[name]!.handler(ctx(), params) as Promise<Record<string, any>>;+const refusal = (promise: Promise<unknown>) => promise.then(() => null, (e: { code?: string; canonical?: string; reason?: string; message?: string; fix?: Record<string, unknown> }) =>+ ({ code: e.canonical ?? e.code, reason: e.reason ?? null, message: e.message ?? '', fix: e.fix ?? null }));+const opts = { sourceId: 'default', prefix: 'storage-manifest/' };++function record(id: string, over: Record<string, unknown> = {}): Record<string, unknown> {+ return {+ id, title: `Dataset ${id}`, kind: 'dataset', status: 'archived',+ locations: [{ store: 'b2', bucket: 'bucket-a', path: `/archive/${id}`, tool: 'restic', repository: 'archive/restic', snapshot: 'a'.repeat(64),+ size_bytes: 2048, file_count: 4, sha256: 'b'.repeat(64), hash_kind: 'b2-listing-sha1-v1', verified_at: '2026-11-01T00:00:00Z' }],+ original_path: `/srv/data/${id}`, archived_at: '2026-11-01T00:00:00Z', reason: 'disk space',+ restore: { skill: 'restore-data', args: { id } },+ details: { manifest_lines: 4 },+ ...over,+ };+}++const FENCE = '```';++async function interim(slug: string, rec: Record<string, unknown> | string, type = 'stored-object'): Promise<void> {+ const json = typeof rec === 'string' ? rec : JSON.stringify(rec, null, 2);+ const content = `---\ntype: ${type}\ntitle: Interim ${slug}\n---\n# Interim ${slug}\n\n## Record\n\n${FENCE}json\n${json}\n${FENCE}\n\n## Restore\n\nAsk the archive agent.\n`;+ await call('put_page', { slug, content, request_id: randomUUID() });+}++const live = async () => (await engine.executeRaw<{ slug: string }>("SELECT slug FROM pages WHERE source_id='default' AND deleted_at IS NULL ORDER BY slug")).map((r) => r.slug);+const tagged = async () => (await engine.executeRaw<{ slug: string }>('SELECT p.slug FROM pages p JOIN tags t ON t.page_id = p.id WHERE t.tag = $1 ORDER BY p.slug', [ADOPTED_TAG])).map((r) => r.slug);++describe('storage adopt on a repo-less brain', () => {+ test('the preview maps interim pages, lists refused fields, skips the index and other types, and writes nothing', async () => {+ await interim('storage-manifest/dataset-a', record('dataset-a', { restore: { skill: 'restore-data', args: { id: 'dataset-a' }, command: 'restic restore latest' }, owner_note: 'kept for audits' }));+ await interim('storage-manifest/dataset-b', record('dataset-b'));+ await interim('storage-manifest/index', record('index-card'));+ await interim('storage-manifest/notes-c', record('notes-c'), 'note');+ await interim('other/dataset-d', record('dataset-d'));+ const pagesBefore = await live();+ const plan = await previewAdopt(ctx(), opts);+ expect(plan.entries.map((e) => [e.slug, e.state, e.card_id])).toEqual([['storage-manifest/dataset-a', 'register', 'dataset-a'], ['storage-manifest/dataset-b', 'register', 'dataset-b']]);+ expect(plan.entries[0]!.refused).toEqual([{ field: 'restore.command', reason: 'command_field' }, { field: 'owner_note', reason: 'unknown_field' }]);+ expect(plan.entries[0]!.card).toMatchObject({ id: 'dataset-a', kind: 'dataset', restore: { skill: 'restore-data', args: { id: 'dataset-a' } }, details: { manifest_lines: 4 } });+ expect(plan.entries[0]!.card!.restore).not.toHaveProperty('command');+ expect(plan.drop_fields).toEqual(['owner_note', 'restore.command']);+ expect(plan.shelf).toBe('creates');+ expect(plan.plan_hash).toMatch(/^[a-f0-9]{64}$/);+ expect(plan.apply).toEqual(['gbrain', 'storage', 'adopt', '--drop-field', 'owner_note', '--drop-field', 'restore.command', '--apply', '--expect', plan.plan_hash]);+ expect(await engine.executeRaw("SELECT 1 FROM sources WHERE id='storage'")).toEqual([]);+ expect(await live()).toEqual(pagesBefore);+ expect(await tagged()).toEqual([]);+ }, 60_000);++ test('apply needs the plan_hash and every refused field named; it registers origin adopt, tags the originals and deletes nothing', async () => {+ await interim('storage-manifest/dataset-a', record('dataset-a', { restore: { skill: 'restore-data', command: 'restic restore latest' } }));+ await interim('storage-manifest/dataset-b', record('dataset-b'));+ const plan = await previewAdopt(ctx(), opts);+ expect((await refusal(applyAdopt(ctx(), { ...opts, expect: 'f'.repeat(64), dropFields: ['restore.command'] })))?.code).toBe('preview_changed');+ const unnamed = await refusal(applyAdopt(ctx(), { ...opts, expect: plan.plan_hash, dropFields: [] }));+ expect(unnamed).toMatchObject({ code: 'storage_adopt_field_refused' });+ expect(unnamed!.message).toContain('restore.command');+ expect(unnamed!.fix).toMatchObject({ ask_user: true, argv: plan.apply });+ expect((await refusal(applyAdopt(ctx(), { ...opts, expect: plan.plan_hash, dropFields: ['restore.command', 'kind'] })))?.code).toBe('invalid_params');+ expect(await engine.executeRaw("SELECT 1 FROM sources WHERE id='storage'")).toEqual([]);++ const pagesBefore = await live();+ const applied = await applyAdopt(ctx(), { ...opts, expect: plan.plan_hash, dropFields: ['restore.command'] });+ expect(applied).toMatchObject({ side_effects: 'complete', conflicts: [], finalize: ['gbrain', 'storage', 'adopt', '--finalize'] });+ expect(applied.results.map((r) => r.outcome)).toEqual(['registered', 'retagged', 'registered', 'retagged']);+ const got = await call('storage_get', { id: 'dataset-a' });+ expect(got).toMatchObject({ origin: 'adopt', card: { id: 'dataset-a', restore: { skill: 'restore-data' }, locations: [{ hash_kind: 'b2-listing-sha1-v1' }] } });+ expect(got.card.restore).not.toHaveProperty('command');+ expect(await tagged()).toEqual(['storage-manifest/dataset-a', 'storage-manifest/dataset-b']);+ expect(await live()).toEqual(pagesBefore);+ expect(await engine.executeRaw("SELECT slug FROM pages WHERE source_id='default' AND deleted_at IS NOT NULL")).toEqual([]);+ const original = await call('get_page', { slug: 'storage-manifest/dataset-a' });+ expect(JSON.stringify(original)).toContain('restic restore latest');++ const again = await previewAdopt(ctx(), opts);+ expect(again.entries.map((e) => e.state)).toEqual(['adopted', 'adopted']);+ expect(again.apply).toBeUndefined();+ expect(await applyAdopt(ctx(), { ...opts, expect: again.plan_hash, dropFields: ['restore.command'] })).toMatchObject({ side_effects: 'none' });+ }, 60_000);++ test('a credential-shaped value always refuses, even in a field that would be dropped, and is never echoed', async () => {+ await interim('storage-manifest/dataset-a', record('dataset-a', { restore: { skill: 'restore-data', command: 'B2_ACCOUNT_KEY=fake-key-value restic restore' } }));+ const plan = await previewAdopt(ctx(), opts);+ expect(plan.entries[0]).toMatchObject({ state: 'blocked', card: null, problem: { code: 'storage_record_secret', reason: 'env_assignment' } });+ expect(plan.apply).toBeUndefined();+ const refused = await refusal(applyAdopt(ctx(), { ...opts, expect: plan.plan_hash, dropFields: [] }));+ expect(refused).toMatchObject({ code: 'storage_record_secret', reason: 'env_assignment' });+ expect(refused!.message).toContain('storage-manifest/dataset-a');+ expect(refused!.message).not.toContain('fake-key-value');+ expect(JSON.stringify(plan)).not.toContain('fake-key-value');+ expect(await engine.executeRaw("SELECT 1 FROM sources WHERE id='storage'")).toEqual([]);+ }, 60_000);++ test('an unreadable record and a duplicate card id block the apply', async () => {+ await interim('storage-manifest/dataset-a', '{ "id": "dataset-a", ');+ await interim('storage-manifest/dataset-b', record('dataset-b'));+ await interim('storage-manifest/dataset-c', record('dataset-b'));+ await call('put_page', { slug: 'storage-manifest/dataset-d', content: '---\ntype: stored-object\ntitle: No record\n---\n# No record\n\nMoved to bucket-a.\n', request_id: randomUUID() });+ const plan = await previewAdopt(ctx(), opts);+ expect(plan.entries.map((e) => [e.state, e.problem?.reason ?? null])).toEqual([['blocked', 'not_json'], ['register', null], ['blocked', 'duplicate_id'], ['blocked', 'no_record']]);+ expect((await refusal(applyAdopt(ctx(), { ...opts, expect: plan.plan_hash, dropFields: [] })))).toMatchObject({ code: 'storage_record_invalid' });+ }, 60_000);++ test('a matching card is only tagged, a differing one is a conflict, and a half-finished run applies with the hash it printed', async () => {+ await interim('storage-manifest/dataset-a', record('dataset-a'));+ await interim('storage-manifest/dataset-b', record('dataset-b'));+ await interim('storage-manifest/dataset-c', record('dataset-c'));+ const before = await previewAdopt(ctx(), opts);+ // As if a run stopped after registering dataset-a: the card is on the shelf, its original untagged.+ const { details: _d, ...rest } = record('dataset-a');+ await call('storage_register', { card: { ...rest, details: { manifest_lines: 4 } } });+ await call('storage_register', { card: { ...record('dataset-c'), reason: 'something else' } });+ const plan = await previewAdopt(ctx(), opts);+ expect(plan.entries.map((e) => e.state)).toEqual(['retag', 'register', 'conflict']);+ expect(plan.plan_hash).not.toBe(before.plan_hash);+ await call('storage_update', { id: 'dataset-c', expected_revision: (await call('storage_get', { id: 'dataset-c' })).revision, patch: { reason: 'disk space' } });+ expect((await previewAdopt(ctx(), opts)).plan_hash).toBe(before.plan_hash);+ const applied = await applyAdopt(ctx(), { ...opts, expect: before.plan_hash, dropFields: [] });+ expect(applied.results.map((r) => [r.slug, r.outcome])).toEqual([+ ['storage-manifest/dataset-a', 'retagged'], ['storage-manifest/dataset-b', 'registered'], ['storage-manifest/dataset-b', 'retagged'], ['storage-manifest/dataset-c', 'retagged']]);+ expect((await call('storage_get', { id: 'dataset-a' })).origin).toBe('local');++ await call('storage_update', { id: 'dataset-b', expected_revision: (await call('storage_get', { id: 'dataset-b' })).revision, patch: { reason: 'changed on the shelf' } });+ await call('remove_tag', { slug: 'storage-manifest/dataset-b', tag: ADOPTED_TAG });+ const conflicted = await previewAdopt(ctx(), opts);+ expect(conflicted.entries.map((e) => e.state)).toEqual(['adopted', 'conflict', 'adopted']);+ const result = await applyAdopt(ctx(), { ...opts, expect: conflicted.plan_hash, dropFields: [] });+ expect(result).toMatchObject({ side_effects: 'none', conflicts: ['storage-manifest/dataset-b'] });+ expect((await call('storage_get', { id: 'dataset-b' })).card.reason).toBe('changed on the shelf');+ expect(await tagged()).toEqual(['storage-manifest/dataset-a', 'storage-manifest/dataset-c']);+ }, 60_000);++ test('finalize previews, refuses while a card differs, then soft-deletes only the adopted originals', async () => {+ await interim('storage-manifest/dataset-a', record('dataset-a'));+ await interim('storage-manifest/dataset-b', record('dataset-b'));+ const plan = await previewAdopt(ctx(), opts);+ await applyAdopt(ctx(), { ...opts, expect: plan.plan_hash, dropFields: [] });+ await interim('storage-manifest/dataset-c', record('dataset-c'));++ await call('storage_update', { id: 'dataset-b', expected_revision: (await call('storage_get', { id: 'dataset-b' })).revision, patch: { status: 'retired' } });+ const blocked = await previewFinalize(ctx(), opts);+ expect(blocked.entries.map((e) => [e.slug, e.state])).toEqual([['storage-manifest/dataset-a', 'delete'], ['storage-manifest/dataset-b', 'unverified'], ['storage-manifest/dataset-c', 'not_adopted']]);+ expect(blocked.apply).toBeUndefined();+ expect((await refusal(applyFinalize(ctx(), { ...opts, expect: blocked.plan_hash })))?.code).toBe('storage_adopt_unverified');+ expect(await engine.executeRaw("SELECT slug FROM pages WHERE source_id='default' AND deleted_at IS NOT NULL")).toEqual([]);++ await call('storage_update', { id: 'dataset-b', expected_revision: (await call('storage_get', { id: 'dataset-b' })).revision, patch: { status: 'archived' } });+ const ready = await previewFinalize(ctx(), opts);+ expect(ready.apply).toEqual(['gbrain', 'storage', 'adopt', '--finalize', '--expect', ready.plan_hash]);+ expect(await live()).toContain('storage-manifest/dataset-a');+ expect((await refusal(applyFinalize(ctx(), { ...opts, expect: blocked.plan_hash })))?.code).toBe('preview_changed');+ const done = await applyFinalize(ctx(), { ...opts, expect: ready.plan_hash });+ expect(done).toMatchObject({ side_effects: 'complete', deleted: ['storage-manifest/dataset-a', 'storage-manifest/dataset-b'] });+ expect(await live()).toEqual(['storage-manifest/dataset-c']);+ expect((await call('storage_list', {})).total).toBe(2);+ expect(await applyFinalize(ctx(), { ...opts, expect: ready.plan_hash })).toMatchObject({ side_effects: 'none', deleted: [] });+ const tombstone = await engine.readPageSnapshot('storage-manifest/dataset-a', { sourceId: 'default', includeDeleted: true });+ await call('restore_page', { slug: 'storage-manifest/dataset-a', expected_revision: tombstone!.revision });+ expect(await live()).toContain('storage-manifest/dataset-a');+ }, 60_000);++ test('a brain with a Git checkout refuses storage_manifest_missing until storage init; the storage source is not an interim source', async () => {+ await interim('storage-manifest/dataset-a', record('dataset-a'));+ expect((await refusal(previewAdopt(ctx(), { ...opts, sourceId: 'storage' })))?.code).toBe('invalid_params');+ expect((await refusal(previewAdopt(ctx(), { ...opts, sourceId: 'source-missing' })))?.code).toBe('invalid_params');+ await engine.setConfig('sync.repo_path', '/srv/data/brain-checkout');+ expect((await refusal(previewAdopt(ctx(), opts)))?.code).toBe('storage_manifest_missing');+ expect(await engine.executeRaw("SELECT 1 FROM sources WHERE id='storage'")).toEqual([]);+ }, 60_000);+});diff --git a/test/storage-manifest-jsonl.test.ts b/test/storage-manifest-jsonl.test.tsnew file mode 100644index 0000000000..9f2fc436c8--- /dev/null+++ b/test/storage-manifest-jsonl.test.ts@@ -0,0 +1,99 @@+/**+ * GST-1943: storage shelf recovery as JSONL (PGLite, repo-less). Protects:+ * - export writes one card per line, sorted by id, stamped fields included;+ * - importing that export into an empty brain previews every line as create, and the apply (bound to its plan_hash)+ * reproduces every card with origin import, so a second export matches the first apart from the stamps;+ * - a rerun is idempotent (identical, side_effects none); a card on the shelf that differs is a conflict, never+ * overwritten; invalid lines (not JSON, a credential shape, a duplicate id) are listed without their values.+ */+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';+import { PGLiteEngine } from '../src/core/pglite-engine.ts';+import { operationsByName } from '../src/core/operations.ts';+import type { OperationContext } from '../src/core/ops/contract.ts';+import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';+import { applyImport, exportShelfJsonl, previewImport } from '../src/core/storage-manifest/jsonl.ts';++let source: PGLiteEngine;+let target: PGLiteEngine;++beforeAll(async () => {+ source = new PGLiteEngine();+ await source.connect({});+ await source.initSchema();+ target = new PGLiteEngine();+ await target.connect({});+ await target.initSchema();+}, 60_000);+afterAll(async () => {+ for (const engine of [source, target]) await disposePersistenceConsumer(engine);+ await source.disconnect();+ await target.disconnect();+}, 60_000);++const ctx = (engine: PGLiteEngine): OperationContext => ({+ engine, config: { engine: engine.kind, embedding_disabled: true } as OperationContext['config'],+ logger: { info() {}, warn() {}, error() {} }, dryRun: false, remote: false, sourceId: 'default',+}) as OperationContext;+const call = (engine: PGLiteEngine, name: string, params: Record<string, unknown>) => operationsByName[name]!.handler(ctx(engine), params) as Promise<Record<string, any>>;++function card(id: string, over: Record<string, unknown> = {}): Record<string, unknown> {+ return {+ id, title: `Dataset ${id}`, aliases: [`${id} archive`], kind: 'directory', description: 'Example archive for the JSONL tests.',+ locations: [{ store: 'supabase', bucket: 'bucket-a', path: `archive/${id}`, tool: 'object', size_bytes: 512, file_count: 2, hash_kind: 'supabase-listing-etag-v1', verified_at: '2026-11-02T00:00:00Z' },+ { store: 's3', bucket: 'bucket-b', path: `/archive/${id}`, tool: 'rclone', size_bytes: 512 }],+ original_path: `/srv/data/${id}`, on_source_machine: false, restore: { skill: 'restore-data', args: { id, verify: true } },+ restores: [{ at: '2026-11-03T00:00:00Z', to: `/srv/scratch/${id}`, verified: true }], details: { note: 'placeholder', parts: [1, 2] },+ ...over,+ };+}++const withoutStamps = (line: string) => { const { registered_by: _b, origin: _o, ...rest } = JSON.parse(line); return rest; };++describe('storage shelf JSONL export and import', () => {+ test('export, then import into an empty brain, reproduces every card; a rerun is idempotent', async () => {+ for (const id of ['dataset-b', 'dataset-a', 'acme-example-runs']) await call(source, 'storage_register', { card: card(id) });+ const exported = await exportShelfJsonl(source);+ expect(exported.skipped).toEqual([]);+ expect(exported.lines.map((l) => JSON.parse(l).id)).toEqual(['acme-example-runs', 'dataset-a', 'dataset-b']);+ expect(JSON.parse(exported.lines[0]!)).toMatchObject({ origin: 'local', registered_by: expect.any(String) });+ const text = `${exported.lines.join('\n')}\n`;++ expect((await exportShelfJsonl(target)).lines).toEqual([]);+ const { cards: _c, ...plan } = await previewImport(target, 'shelf.jsonl', text);+ expect(plan.lines.map((l) => l.action)).toEqual(['create', 'create', 'create']);+ expect(plan.apply).toEqual(['gbrain', 'storage', 'import', '--jsonl', 'shelf.jsonl', '--apply', '--expect', plan.plan_hash]);+ expect(await target.executeRaw("SELECT 1 FROM sources WHERE id='storage'")).toEqual([]);+ expect(await applyImport(ctx(target), 'shelf.jsonl', text, 'f'.repeat(64)).then(() => null, (e) => e.code)).toBe('preview_changed');++ const applied = await applyImport(ctx(target), 'shelf.jsonl', text, plan.plan_hash);+ expect(applied).toMatchObject({ side_effects: 'complete', created: ['acme-example-runs', 'dataset-a', 'dataset-b'], conflicts: [], invalid: [] });+ const reimported = await exportShelfJsonl(target);+ expect(reimported.lines.map(withoutStamps)).toEqual(exported.lines.map(withoutStamps));+ expect(reimported.lines.map((l) => JSON.parse(l).origin)).toEqual(['import', 'import', 'import']);++ const { cards: _again, ...rerun } = await previewImport(target, 'shelf.jsonl', text);+ expect(rerun.lines.map((l) => l.action)).toEqual(['identical', 'identical', 'identical']);+ expect(rerun.plan_hash).toBe(plan.plan_hash);+ expect(rerun.apply).toBeUndefined();+ expect(await applyImport(ctx(target), 'shelf.jsonl', text, plan.plan_hash)).toMatchObject({ side_effects: 'none', created: [], identical: ['acme-example-runs', 'dataset-a', 'dataset-b'] });+ }, 60_000);++ test('a differing card is a conflict and never overwritten; invalid lines are listed without their values', async () => {+ const lines = [+ JSON.stringify({ ...card('dataset-a'), reason: 'a different reason' }),+ '{ not json',+ JSON.stringify(card('dataset-c', { reason: 'export SUPABASE_SERVICE_KEY=fake-secret-value' })),+ JSON.stringify(card('dataset-d')),+ JSON.stringify(card('dataset-d')),+ '',+ ];+ const text = lines.join('\n');+ const { cards: _c, ...plan } = await previewImport(target, 'more.jsonl', text);+ expect(plan.lines.map((l) => [l.line, l.action, l.reason ?? null])).toEqual([[1, 'conflict', null], [2, 'invalid', 'not_json'], [3, 'invalid', 'env_assignment'], [4, 'create', null], [5, 'invalid', 'duplicate_id']]);+ expect(JSON.stringify(plan)).not.toContain('fake-secret-value');+ const applied = await applyImport(ctx(target), 'more.jsonl', text, plan.plan_hash);+ expect(applied).toMatchObject({ side_effects: 'complete', created: ['dataset-d'], conflicts: ['dataset-a'], invalid: [2, 3, 5] });+ expect((await call(target, 'storage_get', { id: 'dataset-a' })).card.reason ?? null).toBeNull();+ expect((await call(target, 'storage_get', { id: 'dataset-d' })).origin).toBe('import');+ }, 60_000);+});