Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Import iMessage conversations as owner-only pages, settle read-only mirror holds with one approval, and five smaller changes (#9623)

Garry Tana685e7616e49
diff --git a/.github/workflows/stress.yml b/.github/workflows/stress.yml
index 144f20c06e..edbbabe127 100644
--- a/.github/workflows/stress.yml
+++ b/.github/workflows/stress.yml
@@ -93,7 +93,7 @@ jobs:
needs: plan
if: needs.plan.outputs.run == 'true'
runs-on: ubicloud-standard-4-ubuntu-2404
- # Gate shards are planned under 25 minutes and race-hunt shards under 55;
+ # Gate shards are planned under 12 minutes and race-hunt shards under 55;
# the margin covers checkout, install and the snapshot build.
timeout-minutes: ${{ fromJSON(inputs.mode == 'gate' && '35' || '65') }}
strategy:
diff --git a/README.md b/README.md
index 66ae65acc7..2ed8fb2b90 100644
--- a/README.md
+++ b/README.md
@@ -325,7 +325,7 @@ Data flowing into the brain. Each integration is a recipe — markdown + setup h
- **Voice**: talk to your brain from a browser or phone with [`recipes/agent-voice.md`](recipes/agent-voice.md) (`gbrain integrations install agent-voice`); the older Twilio recipe is deprecated. Voice notes and chat transcripts you already have come in as files: put their Markdown in a folder and import it, or bring ChatGPT and Claude exports in with `gbrain transcripts ingest` ([chat connectors](docs/guides/chat-connectors.md)).
- **A second folder** (for example a company notes folder beside your personal one): `gbrain sources add company --path ~/company-notes`, then `gbrain sync --source company`. A plain folder works without Git. On a brain only you use, the new folder joins default search; on a shared brain, `gbrain sources federate company` adds it. More: [multi-source brains](docs/guides/multi-source-brains.md).
- **Gmail + Calendar + Contacts (native)**: the google source kind syncs threads, events, and contacts through your own OAuth client and runs the open-loop engine on top (`gbrain waiting`). Setup: [`docs/guides/google-connect.md`](docs/guides/google-connect.md); recipes: [`recipes/email-to-brain.md`](recipes/email-to-brain.md), [`recipes/calendar-to-brain.md`](recipes/calendar-to-brain.md).
-- **Meeting notes + Slack channels (native)**: the `meetings` source kind (Fireflies first) writes one page per meeting and the `slack` source kind one page per channel per day, synced on a schedule, on brains with or without a Git repository. Setup: [`docs/guides/meeting-and-slack-sources.md`](docs/guides/meeting-and-slack-sources.md).
+- **Meeting notes + Slack channels (native)**: the `meetings` source kind (Fireflies first) writes one page per meeting and the `slack` source kind one page per channel per day, synced on a schedule, on brains with or without a Git repository. Setup: [`docs/guides/meeting-and-slack-sources.md`](docs/guides/meeting-and-slack-sources.md). The `imessage` source kind imports Messages from a Mac, one private, owner-only page per chat per day: [`docs/guides/apple-setup.md`](docs/guides/apple-setup.md).
- **Email + calendar (webhooks)**: webhook handlers that route to brain signals. [`docs/integrations/meeting-webhooks.md`](docs/integrations/meeting-webhooks.md).
- **Embedding providers**: Voyage (new-install default: `voyage-4` @ 1024d), OpenAI, OpenRouter, Google Gemini, Azure OpenAI, MiniMax, Alibaba DashScope, Zhipu, Ollama (local), llama.cpp llama-server (local), LM Studio, Together, and LiteLLM proxy. Pricing matrix + decision tree in [`docs/integrations/embedding-providers.md`](docs/integrations/embedding-providers.md). Existing vectors are never converted by changing the default; use the explicitly approved [embedding migration](docs/guides/embedding-migration.md).
- **Rerankers**: Voyage `rerank-3-lite` hosted (the default unless `search.reranker.model` is set; on in `balanced` and `tokenmax`, same `VOYAGE_API_KEY` as embeddings; `gbrain config set search.reranker.model voyage:rerank-2.5` restores the previous default), plus the `llama-server-reranker` recipe for fully-local cross-encoder rerank via llama.cpp running Qwen3-Reranker against the same `gateway.rerank()` seam. Setup walkthrough in [`docs/ai-providers/llama-server-reranker.md`](docs/ai-providers/llama-server-reranker.md).
diff --git a/behavior-changes.d/conversation_slot_tagging_gbra574.md b/behavior-changes.d/conversation_slot_tagging_gbra574.md
new file mode 100644
index 0000000000..9a1304b23f
--- /dev/null
+++ b/behavior-changes.d/conversation_slot_tagging_gbra574.md
@@ -0,0 +1,4 @@
+---
+kind: add
+---
+`gbrain extract-conversation-facts` tags slots again (where a person lives, who employs them or their role), now with a second small call after extraction instead of in the extraction call itself, so the facts it saves are the same as without slots. The call reads only the facts the extraction produced about a person whose page it named exactly, at most 10 per conversation window, so a brain whose conversation facts name no person page makes no extra call. It is counted in the run's cost cap, the per-page cap and the `--dry-run` estimate. A window whose tagging call fails keeps its facts without slots, the run's summary counts it, and `--force` tags it again. Pages extracted before this release keep their facts without slots until that part of the page is extracted again; to tag them now, preview the paid run with `gbrain extract-conversation-facts --force --dry-run`, then run it with `--force`.
diff --git a/behavior-changes.d/dream_named_phase_no_database_9608.md b/behavior-changes.d/dream_named_phase_no_database_9608.md
new file mode 100644
index 0000000000..3b72a08266
--- /dev/null
+++ b/behavior-changes.d/dream_named_phase_no_database_9608.md
@@ -0,0 +1,4 @@
+---
+kind: fix
+---
+gbrain dream --input <file>, or gbrain dream --phase <name>, run with no database connection used to exit 0 after the phase it was asked to run skipped. Now a phase you named, or that --input implies, that skips for want of a database ends the command with database_error and exit 1 (the error envelope under --json). Other named phases that need no database still run first, and their report is not printed when the refusal fires. A plain gbrain dream names no phase and still exits 0 when it can only run the filesystem phases. A script that runs dream with --input or --phase and checks the exit code now sees the failure; fix the database connection (gbrain doctor --json names the cause) and run it again.
diff --git a/behavior-changes.d/dream_summary_keeps_earlier_runs_9598.md b/behavior-changes.d/dream_summary_keeps_earlier_runs_9598.md
new file mode 100644
index 0000000000..67a05f7a93
--- /dev/null
+++ b/behavior-changes.d/dream_summary_keeps_earlier_runs_9598.md
@@ -0,0 +1,4 @@
+---
+kind: fix
+---
+The dream summary page for a date now keeps the links a previous synthesize run wrote that day, as long as each linked page still exists, instead of keeping only the latest run's pages. "Pages written" still counts the latest run, and a new "Pages from earlier runs today" line counts the pages kept from earlier runs. The earlier runs' pages are read from the previous summary's list, which holds at most 20 links, so after a run that wrote more than 20 pages the kept count is a lower bound.
diff --git a/behavior-changes.d/mirror_holds_whole_class_apply.md b/behavior-changes.d/mirror_holds_whole_class_apply.md
new file mode 100644
index 0000000000..40d01336c0
--- /dev/null
+++ b/behavior-changes.d/mirror_holds_whole_class_apply.md
@@ -0,0 +1,4 @@
+---
+kind: add
+---
+gbrain repair file-drift --held --side unknown|database|both --prefer file --whole-class --apply --expect <hash> --yes applies a complete whole-class manifest after the user agrees to its hash: each page is re-read and applied only while its pins still match, on a read-only mirror the file is imported into the page database-only (a page version and a private backup first, the checkout untouched), and a stopped apply prints its resume command first and exits 1. A reconcile approved with keep_file_bytes on a source that is a read-only mirror now imports database-only when the file still matches the approved bytes, instead of refusing source_changed.
diff --git a/behavior-changes.d/mirror_holds_whole_class_preview.md b/behavior-changes.d/mirror_holds_whole_class_preview.md
new file mode 100644
index 0000000000..78b6d3cc38
--- /dev/null
+++ b/behavior-changes.d/mirror_holds_whole_class_preview.md
@@ -0,0 +1,4 @@
+---
+kind: add
+---
+gbrain repair file-drift --held --side unknown|database|both --prefer file --whole-class previews every held file-drift page of one side as one class: one manifest under the gbrain config directory and one hash, with the lines each page would lose, the pages kept held (kept_newer_page, and kept_protected_parts on a read-only mirror) and the data-loss card. On a read-only mirror the held window previews now list a page whose file is newer prefer_file instead of no_drift, and the held comparison names the whole-class preview instead of gbrain sources mirror-writable. A held deleted page whose file differs names neither preview: a tombstone_edited page names the keep-the-deletion preview (--held --side deleted --state tombstone_edited --prefer database) first and gbrain sources mirror-writable second, and a purged_differs page names only mirror-writable. The preview writes nothing else; --whole-class --apply refuses for now.
diff --git a/behavior-changes.d/push_credential_refused_gst2961.md b/behavior-changes.d/push_credential_refused_gst2961.md
new file mode 100644
index 0000000000..68a56e50e3
--- /dev/null
+++ b/behavior-changes.d/push_credential_refused_gst2961.md
@@ -0,0 +1,4 @@
+---
+kind: fix
+---
+gbrain git commit-push (and the post-commit hook, scripts/brain-commit-push.sh and autopilot's git reconcile, which run it) now stops at once when the Git host refuses a push with "Repository not found" (HTTP 404, what a host tells an account that cannot see a private repository) or HTTP 403: it exits 1 with the new code push_credential_refused, class host_only, not retryable, instead of exit 4 with push_unconfirmed, which every caller read as "try again later" while commits stayed on this machine. The message names the credential helpers git asked, in the order it asked them, with the scope (system, global, local) and config file of each, which one answered and the account login it gave; it never prints or stores the secret. Until a push lands, doctor git_convergence warns about that checkout at once instead of after six hours, and put_page's lastPushStatus reads needs_attention. A script that branched on exit 4 to retry now sees exit 1 for this case: relay the message to the user, who makes git use a credential for an account that can push there, then run gbrain git commit-push --push-only. A dropped connection or any other failure keeps push_unconfirmed and exit 4, with the same retries as before. The same refusal over SSH ("ERROR: Repository not found.", "ERROR: Permission to ... denied") is classified too; there git asks no credential helper, so the message says the key ssh offers decides the account. A managed worktree's own Git-effect pushes keep their current retry.
diff --git a/behavior-changes.d/slack_missing_user_daily_relist_9601.md b/behavior-changes.d/slack_missing_user_daily_relist_9601.md
new file mode 100644
index 0000000000..bfcad56d48
--- /dev/null
+++ b/behavior-changes.d/slack_missing_user_daily_relist_9601.md
@@ -0,0 +1,4 @@
+---
+kind: fix
+---
+Slack sync now looks a user up again when the last users listing lacked them and that listing is more than a day old, instead of waiting up to seven days. A new member's name replaces their raw id on day pages written after the next sync. A Slack Connect user from another workspace never appears in the listing, so a workspace with shared channels may make one extra full users listing a day.
diff --git a/changelog.d/capy-outside-fix-wave-4.md b/changelog.d/capy-outside-fix-wave-4.md
new file mode 100644
index 0000000000..a6ba7315fd
--- /dev/null
+++ b/changelog.d/capy-outside-fix-wave-4.md
@@ -0,0 +1,13 @@
+**`gbrain dream --input` with no database now fails instead of reporting success, a second dream run on the same day keeps the first run's summary links, and Slack day pages pick up a missing user's name within a day.**
+
+<!-- behavior-change: dream_named_phase_no_database_9608 -->
+<!-- behavior-change: dream_summary_keeps_earlier_runs_9598 -->
+<!-- behavior-change: slack_missing_user_daily_relist_9601 -->
+
+### Fixed
+- `gbrain dream --input <file>`, or `gbrain dream --phase <name>`, with no database connection exited 0 after the phase it was asked to run skipped. A phase you named (or that `--input` implies) that skips for want of a database now ends the command with `database_error` (exit 1, the error envelope under `--json`). A plain `gbrain dream` names no phase and is unchanged. Contributed by @Masashi-Ono0611 (#9613, fixes #9608).
+- The dream summary page is one page per date, but each synthesize run rebuilt it from its own pages, so a second run on the same day dropped the first run's links. It now keeps earlier links that still point at a live page. "Pages written" still counts this run, and a new "Pages from earlier runs today" line counts the pages it kept. First fixed by @Masashi-Ono0611 in #9602 (fixes #9598).
+- A Slack user missing from the last users listing (a new member, or a Slack Connect user from another workspace) was shown by raw id on day pages for up to seven days. Once the listing is a day old, the next sync that renders such a user lists the workspace again, so a new member's name shows up within a day. A Slack Connect user never appears in the listing, so a workspace with one costs at most one extra listing a day. First fixed by @Masashi-Ono0611 in #9605 (fixes #9601).
+- A rerank test that freed its unreachable port before running could fail when another process took the port; it now holds the port for the whole run.
+
+Contributed by @Masashi-Ono0611
diff --git a/changelog.d/ci-trial-stress-budget.md b/changelog.d/ci-trial-stress-budget.md
new file mode 100644
index 0000000000..599696829a
--- /dev/null
+++ b/changelog.d/ci-trial-stress-budget.md
@@ -0,0 +1 @@
+**The PR stress gate now plans its shards under 12 minutes instead of 25, and plans a test file with no timing history at its lane's p95 instead of p75, so a slow new test file no longer runs its shard past the job timeout.**
diff --git a/changelog.d/garrytan-imessage-source-kind.md b/changelog.d/garrytan-imessage-source-kind.md
new file mode 100644
index 0000000000..edfeb240b3
--- /dev/null
+++ b/changelog.d/garrytan-imessage-source-kind.md
@@ -0,0 +1,8 @@
+**You can bring your iMessage history into your brain from a Mac, as private pages only you can read.**
+
+### Added
+- A new `imessage` source kind: `gbrain sources add <id> --kind imessage` imports one page per chat per day through GBrain Helper, a small app on your own Mac that reads the Messages database and answers gbrain on `127.0.0.1` (`gbrain config set apple.helper.port <port>`). Each sync re-reads the recent days, so an edit or an unsend on your phone updates the page and retires facts taken from the old text. Setup and every error code: docs/guides/apple-setup.md.
+- iMessage pages are private, live only in the database (nothing reaches a Git checkout, commit or push, even on a brain that has one) and are stored at the external-untrusted trust tier, like email. Embedding and fact extraction run only if you already configured a provider for them.
+- Owner-only sources: an `imessage` source, or any source whose config sets `owner_only: true`, is readable only by the local CLI and by agents bound to the brain's owner. Every other member, guest, shared room or unbound key gets `not_found` for its pages and for anything derived from them (facts, concepts, timelines), whatever privacy relaxations the brain has on, and their writes into such a source are refused. Removing the source stops hiding derived pages and facts stored in other sources, so delete those first if they should stay private.
+- New error codes `apple_helper_not_running`, `apple_helper_unauthorized`, `apple_full_disk_access_pending` and `apple_schema_mismatch`, each with its fix.
+- Schema migration v320 adds the `gbrain_owner_only_lineage` database function. A brain with no owner-only source runs no extra query and plans no extra step on its read paths.
diff --git a/changelog.d/gbra574-slot-tagging.md b/changelog.d/gbra574-slot-tagging.md
new file mode 100644
index 0000000000..fbd1d95e8c
--- /dev/null
+++ b/changelog.d/gbra574-slot-tagging.md
@@ -0,0 +1,6 @@
+**Conversation facts get slots again, from a second small call that leaves extraction's own output unchanged.**
+
+### Added
+- `gbrain extract-conversation-facts` tags where a person lives, who employs them or their role on the facts it extracts, so the facts block can show when a value held ("valid FROM to UNTIL"). The tags come from a second, small call after extraction, which reads only the facts about a person whose page the extractor named exactly (at most 10 per conversation window); the extraction call stays the one that saves every wish, preference and idea. A brain whose conversation facts name no person page makes no extra call. The call counts toward the run's cost cap, the per-page cap and the `--dry-run` estimate. A window whose tagging call fails keeps its facts without slots, the summary counts it, and `--force` tags it again.
+
+<!-- behavior-change: conversation_slot_tagging_gbra574 -->
diff --git a/changelog.d/mirror-holds-class-apply.md b/changelog.d/mirror-holds-class-apply.md
new file mode 100644
index 0000000000..7f6e1531de
--- /dev/null
+++ b/changelog.d/mirror-holds-class-apply.md
@@ -0,0 +1,7 @@
+**One approval now settles every held file-drift page of a read-only mirror that the whole-class preview listed, without writing the mirror's checkout.**
+
+### Added
+- `gbrain repair file-drift --held --side unknown --prefer file --whole-class --apply --expect <hash> --yes` applies the manifest the whole-class preview printed, after the user agrees to its hash. Each page is re-read first and applied only while its revision, file, hold, side, upstream version and mirror flag still match and it loses no more lines than the preview said; a sync that only rewrote hold records keeps the approval. On a read-only mirror each page takes the file's text database-only, with a page version (`gbrain revert`) and a private backup saved first, and the next sync releases its hold.
+- A stopped apply prints its resume command first, then how many pages were applied, skipped and remaining, and exits 1; a rerun resumes at the next window and applies no page twice. It refuses a second apply of the same manifest (`class_apply_busy`), a manifest edited after its preview (`class_manifest_stale`) and any caller other than the local CLI.
+
+<!-- behavior-change: mirror_holds_whole_class_apply -->
diff --git a/changelog.d/mirror-holds-class-preview.md b/changelog.d/mirror-holds-class-preview.md
new file mode 100644
index 0000000000..48b1de383f
--- /dev/null
+++ b/changelog.d/mirror-holds-class-preview.md
@@ -0,0 +1,9 @@
+**One preview now lists every held file-drift page of a read-only mirror under one hash, so a person can review the whole class at once.**
+
+### Added
+- `gbrain repair file-drift --held --side unknown --prefer file --whole-class` (also `--side database` or `both`) walks every window of held pages into one manifest with one hash. It prints the total lines lost, the 50 pages that lose most, the pages kept held and why, and the data-loss card. It refuses `--prefer database` and `--side deleted` (`whole_class_prefer_unsupported`) and a class whose backups would pass the recovery-bytes limit (`class_capacity_exceeded`). Applying the manifest is not available yet.
+
+### Fixed
+- On a read-only mirror, the held window previews (`--held --side unknown --prefer file`) no longer read a page whose file is newer as `no_drift`; they list it `prefer_file`, the same way the held comparison does. The comparison now names the whole-class preview instead of `gbrain sources mirror-writable`. A held deleted page whose file differs names keeping the deletion first and `mirror-writable` second, never a `--prefer file` preview.
+
+<!-- behavior-change: mirror_holds_whole_class_preview -->
diff --git a/changelog.d/push-credential-refused-gst2961.md b/changelog.d/push-credential-refused-gst2961.md
new file mode 100644
index 0000000000..7707fd6f68
--- /dev/null
+++ b/changelog.d/push-credential-refused-gst2961.md
@@ -0,0 +1,7 @@
+**gbrain git commit-push stops and says so when the Git host refuses the push for the account git used, naming the credential helper that answered instead of retrying quietly.**
+
+<!-- behavior-change: push_credential_refused_gst2961 -->
+
+### Fixed
+- A push the host refuses with "Repository not found" (HTTP 404) or HTTP 403 is now a credential fault: `gbrain git commit-push` exits 1 with `push_credential_refused` (not retryable) after one attempt, instead of exit 4 `push_unconfirmed`, which the post-commit hook, autopilot's git reconcile and agents read as transient while commits stayed local for hours. The message names the credential helpers git asked, in order, with the scope and config file of each, which one answered and its account login; the secret is never printed, logged or stored, and a helper's arguments or inline body are never shown.
+- The refusal is recorded for the checkout until a push lands: doctor `git_convergence` warns about it at once (`credential_refused` in the root's details), put_page's `lastPushStatus` reads `needs_attention`, and the push log line says the push was refused rather than that the remote could not be reached. A dropped connection keeps `push_unconfirmed` and its retries.
diff --git a/docs/architecture/canonical-writers.tsv b/docs/architecture/canonical-writers.tsv
index 342a8c9e0c..07b6b32b57 100644
--- a/docs/architecture/canonical-writers.tsv
+++ b/docs/architecture/canonical-writers.tsv
@@ -141,7 +141,7 @@ src/core/schema-pack/retype.ts 1 engine_guard Canonical table SQL trigger requir
src/core/schema-pack/sync.ts 1 engine_guard Canonical table SQL trigger requires coordinator capability; legacy calls fail before canonical DB publication.
src/core/search/safe-chunks.ts 1 projection Derived indexing, retrieval telemetry, or source settings; canonical fields remain guarded by SQL triggers.
src/core/source-config-sql.ts 1 projection Derived indexing, retrieval telemetry, or source settings; canonical fields remain guarded by SQL triggers.
-src/core/sources-ops.ts 8 coordinator Managed source constructors, removal and reclone delegate to guarded lifecycle transactions and reserved directory recovery; legacy paths remain preactivation only.
+src/core/sources-ops.ts 9 coordinator Managed source constructors, removal and reclone delegate to guarded lifecycle transactions and reserved directory recovery; legacy paths remain preactivation only. The imessage branch of insertApiSource registers its database-only source row only on an unmanaged brain; addSource hands a managed brain to addManagedSource first.
src/core/sweep.ts 2 engine_guard Canonical table SQL trigger requires coordinator capability; legacy calls fail before canonical DB publication.
src/core/sync-anchor.ts 5 engine_guard Canonical table SQL trigger requires coordinator capability; legacy calls fail before canonical DB publication.
src/core/takes-write.ts 8 filesystem_guard Managed operation routes through journal; legacy atomic file helper checks the root.
@@ -303,6 +303,7 @@ src/core/persistence/git-conversion.ts 4 contract G8a sources canonical (trusted
src/core/connectors/api-source.ts 2 coordinator Shared Fireflies/Slack publish step (GBRA-220): a managed source imports and deletes only through ManagedConnectorSync (prepared journal publication); the importFromContent and deletePages calls run for unmanaged sources, and in git mode only after the file was committed through commitPathsLocked (git first, writer lock). Private pages are held with holdNoncanonicalPrivate.
src/core/meetings/meetings-source.ts 1 coordinator Meetings connector (GBRA-220): the one sources.last_sync_at/newest_content_at stamp (never page content) runs only for unmanaged sources; managed runs stamp through the connector checkpoint save in connector-sync.ts.
src/core/slack/slack-source.ts 1 coordinator Slack channel connector (GBRA-220): the one sources.last_sync_at/newest_content_at stamp (never page content) runs only for unmanaged sources; managed runs stamp through the connector checkpoint save in connector-sync.ts.
+src/core/imessage/imessage-source.ts 1 coordinator iMessage connector: the one sources.last_sync_at/newest_content_at stamp (never page content) runs only for unmanaged sources; managed runs stamp through the connector checkpoint save in connector-sync.ts, and pages write through the connector's api-source import.
src/core/access/attest-sources.ts 1 projection GST-1113: applyAttestSources sets only sources.config.qm_scope (and federated false) on a source a credential first lists in attest_sources, under the sources row lock in the binding transaction. It writes no page column, revision, content hash, generation, checkpoint or topology column, so gbrain_require_managed_writer passes it on a managed brain, as with policy.ts writeAccessStore; the mark only hides.
src/core/storage-manifest/source.ts 1 contract markRole sets role and federated in the config of the storage source that addSource or hostRepo created in the same storage init or first repo-less register; it writes source configuration only, never page content.
src/core/guests/sources.ts 1 projection GBRA-504 guest source setup (initGuestSource, the trusted local gbrain guests init): merges the guest, federated and trust_ceiling keys into sources.config in the transaction that writes the guest_sources row; a settings field, not page content, and canonical columns stay guarded by SQL triggers.
diff --git a/docs/architecture/key-files/commands-2-continued.md b/docs/architecture/key-files/commands-2-continued.md
index bcc5a66fdc..f512ec4a1d 100644
--- a/docs/architecture/key-files/commands-2-continued.md
+++ b/docs/architecture/key-files/commands-2-continued.md
@@ -20,9 +20,7 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL
- `src/commands/dream-reset-key.ts` — `gbrain dream reset-key <base-key>` persists a breaker reset for one dream key (deaths finished before it stop counting; survives restarts); `gbrain dream reset-key --list [--json]` lists tripped keys with counts and reset commands. Dispatched from `dream.ts` before cycle flag parsing. The `dream_paid_loop` doctor check (`src/commands/doctor/checks/dream-breaker.ts`) warns on keys at the limit through the same counter. Its help names the per-source patterns key `dream:patterns:source:<id>`; doctor `dream_paid_loop` reports that prefix as the key's `key_prefix`.
-- `src/commands/dream.ts` — `gbrain dream` CLI; thin alias over `runCycle`. Flags: `--dry-run`, `--json`, `--phase <name>`, `--pull`, `--dir <path>`, `--input <file>` (ad-hoc transcript, implies `--phase synthesize`), `--date YYYY-MM-DD`, `--from <d> --to <d>` (backfill range), `--unsafe-bypass-dream-guard` (plumbed through `runCycle.synthBypassDreamGuard` → `SynthesizePhaseOpts.bypassDreamGuard` → `discoverTranscripts({bypassGuard})` / `readSingleTranscript({bypassGuard})`; loud stderr warning at synthesize-phase entry; never auto-applied for `--input`). Conflict detection: `--input` + `--date` exits 2. ISO date validation. `--dry-run` runs the scored triage pass but skips synthesis (NOT zero LLM calls). Exit 1 on status=failed; a `cycle_already_running` skip names the lock holder (pid, host, age) from `report.lock_holder`. `resolveBrainDir` returns `string | null` (order: `--dir` → resolved `--source`'s `local_path` → global `sync.repo_path` → null); a checkout-less postgres/Supabase brain runs DB-only phases (incl. `resolve_symbol_edges`) and skips the 6 filesystem phases with `details.reason: 'no_brain_dir'`; `runDream` owns the only hard error (no checkout AND no engine). When `--source` resolves but has no on-disk checkout, returns null (DB-only) rather than borrowing another source's global `sync.repo_path` (would mix scopes). Pinned by `test/dream-postgres.serial.test.ts`. `--drain [--window <seconds>]` for `--phase extract_atoms`: `runDrain()` bypasses the pack-gate and runs the single-hold bounded drain from `src/core/cycle/extract-atoms-drain.ts` under the same `cycleLockIdFor(sourceId)` the routine cycle uses (concurrent autopilot tick defers with `cycle_already_running`), reporting `{extracted, skipped, remaining, stopped}`. `--window` is a hard deadline for starting work (the item in flight finishes). Every stop maps through `drainOutcome` (`src/core/cycle/extract-atoms-drain-outcome.ts`): exit 0 only for `stopped: drained` with `remaining: 0`; exit 11 (`BUDGET_STOP_EXIT_CODE`) for a retryable stop (`atom_drain_incomplete`: window, deadline, lock, batch cap, budget, a null count; `atom_drain_provider_failure` reasons `rate_limit`/`transient`), printing the rerun command (`gbrain dream --drain --window <s> [--source <id>]`) on stderr and adding `resume_command` under `--json`; exit 1 for a stop a rerun cannot clear (`atom_drain_provider_failure` reasons `auth`/`billing`/`model_not_found`/`content_block`, `atom_drain_no_progress` over a counted backlog), printing the registry suggestion as a `Fix:` line and adding the rendered `fix` instead of `resume_command`. `--json` of any incomplete stop carries `status` (`incomplete` or `provider_failure`, never `ok`), `retryable`, `code` and `reason`; `LockUnavailableError` → `cycle_already_running` skip (also exit 11). Under `--json` (D2) every path is one document: usage errors are `invalid_params` envelopes (exit 2, unknown `--phase` included), a failed or contained cycle under the guard is a `cycle_failed` envelope leading with the CycleReport keys, and `retriage` / `reset-key` refusals are envelopes. The `extract_atoms_backlog` doctor check (`computeExtractAtomsBacklogCheck`) surfaces the silent pack-gated backlog with the exact `--drain` command; pack-gated cycle skips carry a greppable `pack_gated:true` marker. `dream retriage` dispatches on `args[0] === 'retriage'` BEFORE `parseArgs` (its flag set never collides with cycle flags; `dream retriage --help` prints subcommand help engine-free per the same IRON RULE). `--eval-run` opts the process in to `GBRAIN_DECIDE_SLOTS` (`enableDecideEvalOverride`) for eval harnesses; consent, egress and the daily cap still apply.
-
-- `src/commands/dream.ts` — `gbrain dream` CLI; thin alias over `runCycle`. Flags: `--dry-run`, `--json`, `--phase <name>`, `--pull`, `--dir <path>`, `--input <file>` (ad-hoc transcript, implies `--phase synthesize`), `--date YYYY-MM-DD`, `--from <d> --to <d>` (backfill range), `--unsafe-bypass-dream-guard` (plumbed through `runCycle.synthBypassDreamGuard` → `SynthesizePhaseOpts.bypassDreamGuard` → `discoverTranscripts({bypassGuard})` / `readSingleTranscript({bypassGuard})`; loud stderr warning at synthesize-phase entry; never auto-applied for `--input`). Conflict detection: `--input` + `--date` exits 2. ISO date validation. `--dry-run` runs the scored triage pass but skips synthesis (NOT zero LLM calls). Exit 1 on status=failed; a `cycle_already_running` skip names the lock holder (pid, host, age) from `report.lock_holder`. Source scope enters the shared 6-tier resolver whenever `--source <id>` is given OR `GBRAIN_SOURCE` is set (a null explicit falls through to tier 2: validated + `assertSourceExists`, so an invalid/unknown env value is a clean exit 1; the `__all__` sentinel is excluded and falls through to the unscoped routing, which already spans every source); an env scope naming the brain's default-like source keeps the full implicit cycle (#4700 semantics), any other keeps the `--source` freshness boundary. `resolveBrainDir` returns `string | null` (order: `--dir` → resolved source's `local_path` → global `sync.repo_path` → null); a checkout-less postgres/Supabase brain runs DB-only phases (incl. `resolve_symbol_edges`) and skips the 6 filesystem phases with `details.reason: 'no_brain_dir'`; `runDream` owns the only hard error (no checkout AND no engine). When `--source` resolves but has no on-disk checkout, returns null (DB-only) rather than borrowing another source's global `sync.repo_path` (would mix scopes). Pinned by `test/dream-postgres.serial.test.ts`. `--drain [--window <seconds>]` for `--phase extract_atoms`: `runDrain()` bypasses the pack-gate and runs the single-hold bounded drain from `src/core/cycle/extract-atoms-drain.ts` under the same `cycleLockIdFor(sourceId)` the routine cycle uses (concurrent autopilot tick defers with `cycle_already_running`), reporting `{extracted, skipped, remaining, stopped}`. `--window` is a hard deadline for starting work (the item in flight finishes). Every stop maps through `drainOutcome` (`src/core/cycle/extract-atoms-drain-outcome.ts`): exit 0 only for `stopped: drained` with `remaining: 0`; exit 11 (`BUDGET_STOP_EXIT_CODE`) for a retryable stop (`atom_drain_incomplete`: window, deadline, lock, batch cap, budget, a null count; `atom_drain_provider_failure` reasons `rate_limit`/`transient`), printing the rerun command (`gbrain dream --drain --window <s> [--source <id>]`) on stderr and adding `resume_command` under `--json`; exit 1 for a stop a rerun cannot clear (`atom_drain_provider_failure` reasons `auth`/`billing`/`model_not_found`/`content_block`, `atom_drain_no_progress` over a counted backlog), printing the registry suggestion as a `Fix:` line and adding the rendered `fix` instead of `resume_command`. `--json` of any incomplete stop carries `status` (`incomplete` or `provider_failure`, never `ok`), `retryable`, `code` and `reason`; `LockUnavailableError` → `cycle_already_running` skip (also exit 11). Under `--json` (D2) every path is one document: usage errors are `invalid_params` envelopes (exit 2, unknown `--phase` included), a failed or contained cycle under the guard is a `cycle_failed` envelope leading with the CycleReport keys, and `retriage` / `reset-key` refusals are envelopes. The `extract_atoms_backlog` doctor check (`computeExtractAtomsBacklogCheck`) surfaces the silent pack-gated backlog with the exact `--drain` command; pack-gated cycle skips carry a greppable `pack_gated:true` marker. `dream retriage` dispatches on `args[0] === 'retriage'` BEFORE `parseArgs` (its flag set never collides with cycle flags; `dream retriage --help` prints subcommand help engine-free per the same IRON RULE). `--eval-run` opts the process in to `GBRAIN_DECIDE_SLOTS` (`enableDecideEvalOverride`) for eval harnesses; consent, egress and the daily cap still apply.
+- `src/commands/dream.ts` — `gbrain dream` CLI; thin alias over `runCycle`. Flags: `--dry-run`, `--json`, `--phase <name>`, `--pull`, `--dir <path>`, `--input <file>` (ad-hoc transcript, implies `--phase synthesize`), `--date YYYY-MM-DD`, `--from <d> --to <d>` (backfill range), `--unsafe-bypass-dream-guard` (plumbed through `runCycle.synthBypassDreamGuard` → `SynthesizePhaseOpts.bypassDreamGuard` → `discoverTranscripts({bypassGuard})` / `readSingleTranscript({bypassGuard})`; loud stderr warning at synthesize-phase entry; never auto-applied for `--input`). Conflict detection: `--input` + `--date` exits 2. ISO date validation. `--dry-run` runs the scored triage pass but skips synthesis (NOT zero LLM calls). Exit 1 on status=failed; a phase named by `--phase` (or implied by `--input`) that skips with `details.reason: 'no_database'` exits 1 with a `database_error` envelope (#9608), while a plain `gbrain dream` naming no phase still exits 0; a `cycle_already_running` skip names the lock holder (pid, host, age) from `report.lock_holder`. Source scope enters the shared 6-tier resolver whenever `--source <id>` is given OR `GBRAIN_SOURCE` is set (a null explicit falls through to tier 2: validated + `assertSourceExists`, so an invalid/unknown env value is a clean exit 1; the `__all__` sentinel is excluded and falls through to the unscoped routing, which already spans every source); an env scope naming the brain's default-like source keeps the full implicit cycle (#4700 semantics), any other keeps the `--source` freshness boundary. `resolveBrainDir` returns `string | null` (order: `--dir` → resolved source's `local_path` → global `sync.repo_path` → null); a checkout-less postgres/Supabase brain runs DB-only phases (incl. `resolve_symbol_edges`) and skips the 6 filesystem phases with `details.reason: 'no_brain_dir'`; `runDream` owns the only hard error (no checkout AND no engine). When `--source` resolves but has no on-disk checkout, returns null (DB-only) rather than borrowing another source's global `sync.repo_path` (would mix scopes). Pinned by `test/dream-postgres.serial.test.ts`. `--drain [--window <seconds>]` for `--phase extract_atoms`: `runDrain()` bypasses the pack-gate and runs the single-hold bounded drain from `src/core/cycle/extract-atoms-drain.ts` under the same `cycleLockIdFor(sourceId)` the routine cycle uses (concurrent autopilot tick defers with `cycle_already_running`), reporting `{extracted, skipped, remaining, stopped}`. `--window` is a hard deadline for starting work (the item in flight finishes). Every stop maps through `drainOutcome` (`src/core/cycle/extract-atoms-drain-outcome.ts`): exit 0 only for `stopped: drained` with `remaining: 0`; exit 11 (`BUDGET_STOP_EXIT_CODE`) for a retryable stop (`atom_drain_incomplete`: window, deadline, lock, batch cap, budget, a null count; `atom_drain_provider_failure` reasons `rate_limit`/`transient`), printing the rerun command (`gbrain dream --drain --window <s> [--source <id>]`) on stderr and adding `resume_command` under `--json`; exit 1 for a stop a rerun cannot clear (`atom_drain_provider_failure` reasons `auth`/`billing`/`model_not_found`/`content_block`, `atom_drain_no_progress` over a counted backlog), printing the registry suggestion as a `Fix:` line and adding the rendered `fix` instead of `resume_command`. `--json` of any incomplete stop carries `status` (`incomplete` or `provider_failure`, never `ok`), `retryable`, `code` and `reason`; `LockUnavailableError` → `cycle_already_running` skip (also exit 11). Under `--json` (D2) every path is one document: usage errors are `invalid_params` envelopes (exit 2, unknown `--phase` included), a failed or contained cycle under the guard is a `cycle_failed` envelope leading with the CycleReport keys, and `retriage` / `reset-key` refusals are envelopes. The `extract_atoms_backlog` doctor check (`computeExtractAtomsBacklogCheck`) surfaces the silent pack-gated backlog with the exact `--drain` command; pack-gated cycle skips carry a greppable `pack_gated:true` marker. `dream retriage` dispatches on `args[0] === 'retriage'` BEFORE `parseArgs` (its flag set never collides with cycle flags; `dream retriage --help` prints subcommand help engine-free per the same IRON RULE). `--eval-run` opts the process in to `GBRAIN_DECIDE_SLOTS` (`enableDecideEvalOverride`) for eval harnesses; consent, egress and the daily cap still apply.
- `src/commands/embed.ts` — `gbrain embed [--stale|--all] [--slugs ...]`. Explicit slug/slugs and non-stale all routes require live-source projection snapshots before healing or provider work; unavailable preparation and refused installation are recorded through existing failure results and the CLI nonzero exit verdict. Archived rows are preserved and never knowingly dispatched, while active pages in a mixed run can progress. Dry runs retain their read-only counts, and the global page selectors are unchanged. These routes keep provider calls outside the existing source-before-page guards. Pinned by the explicit archived-admission and actual CLI cases in `test/embedding-recovery.serial.test.ts` (PGLite) and its PostgreSQL wrapper, `test/e2e/embedding-recovery-parity.test.ts`. `--stale` first calls `engine.countChunklessPagesWithContent()` (chunkless-page safety net: a page written directly via `putPage` — e.g. an enrichment-generated stub — that never went through chunking has ZERO `content_chunks` rows, so it has no row to go stale and is otherwise invisible to this command forever; the predicate excludes quarantined/embed_skip pages, both intentionally chunkless). When found, `healChunklessPages` chunks them locally (mirrors `embedPage`'s chunkless branch: same `chunkText` calls over `compiled_truth`/`timeline`) with `embedding = NULL`, folding the new rows into the SAME pass; immediately before writing it reads the live canonical snapshot and re-checks `getChunks`. `installPageProjection` then locks the page, verifies the originating revision and source incarnation, and installs/seals chunks in one transaction. A newer canonical edit prevents installation; the single-page chunkless path uses the same guarded installer. Each page's work is try/caught (a bad chunkless page records a failure via the same `EmbedResult.failures`/`recordFailure` path as every other embed failure and the sweep moves on — it never aborts the whole `--stale` run before the normal stale-chunk pass even starts). `listChunklessPagesWithContent`'s default batch is 50 (not the 2000-row default elsewhere in this file) because each row carries a full page body. It honors the caller's pacer, mirrors `--catch-up` (removes its cap entirely, matching the main loop below), and otherwise shares ONE `GBRAIN_EMBED_TIME_BUDGET_MS` wall-clock budget with the main stale loop (both measure from the same `overallStartedAt`, not two independent 30-minute windows) so a large damaged brain can't run the combined `--stale` pass unbounded; a budget stop that leaves stale chunks is never silent: `src/core/embed-budget-stop.ts` records `reason: 'time_budget'`, `remaining_stale` and `resume_command`, `runEmbed` prints the verdict on stdout and the CLI exits 11 (`BUDGET_STOP_EXIT_CODE`); an abort during healing stops the whole function before falling through to `invalidateStaleSignatureEmbeddings`. Pinned by `test/embed-stale-chunkless-pages.serial.test.ts` + `test/e2e/engine-parity.test.ts`. Then `--stale` calls `engine.countStaleChunks()` (single SELECT count(*) WHERE embedding IS NULL, ~50 bytes wire) so a fully-embedded brain short-circuits with no further reads beyond those two counts. When stale chunks exist, `engine.listStaleChunks()` returns just the chunks needing embeddings (slug + chunk_index + chunk_text + metadata, no `vector(1536)` payload); caller groups by slug, captures a guarded projection snapshot, embeds outside the transaction, and installs through `installPageEmbeddings`. The installer checks revision, source incarnation, chunk identities/text and indexing context, then updates vectors and provenance without replacing chunk text or membership. Every re-embed merge carries per-chunk metadata through the ONE shared `carryChunkMetadata(chunk, loaded)` field list in `src/core/embed-stale.ts` — `modality` plus the code fields (`language`, `symbol_name`, `symbol_type`, `start_line`). Keep this shared field list for prepared chunk metadata rather than copying a per-path list. The final guarded embedding installer updates vectors and provenance only, preserving the installed modality, code metadata, text and chunk membership. Pinned by `test/embed-modality-preserved.test.ts`. All `console.log`/`console.error` call sites use `slog`/`serr` from `src/core/console-prefix.ts` so when `runEmbedCore` runs inside a per-source `withSourcePrefix` scope (installed by the `gbrain sync --all` worker pool) every line carries the `[<source-id>] ` prefix; standalone callers see identical output because slog/serr fall through to bare console fns outside the wrap. Successful complete page embeddings stamp `pages.embedding_signature` inside the guarded installation transaction so a later model/dims swap is detectable as stale. The per-slug path (`embedPage`, used by `gbrain embed <slug>` AND sync's post-import embed step) and the full-re-embed path (`embedAll`) stamp per page when every chunk embedded cleanly. The stale path (`embedAllStale`) first calls `invalidateStaleSignatureEmbeddings` on a live run so signature-drifted pages flow through the NULL cursor, then stamps each page through `stampIfPageProvenanceComplete` in `src/core/embed-stale.ts` (shared with the minion `embed-backfill` drain, `embedStaleForSource`): the stamp is judged from DB state — every chunk carries an active-column vector whose `model` and vector width match the signature and whose `embedded_text_hash` matches `md5(chunk_text)` — never from the batch subset, because `listStaleChunks` pages by row with no page alignment, so a page straddling a batch boundary is stamped by whichever batch lands its last chunk (a partially-stale page keeping preserved chunks of another model, or a NULL model/hash, stays unstamped rather than falsely marked current; `embed --all` fully re-embeds + stamps those). dry-run never mutates: it counts signature-drift via the widened `countStaleChunks({signature})` predicate without NULLing anything. `--include-null-signature` lifts the NULL-signature grandfather clause: threads `includeNullSignature: true` into the invalidation + counts so pages that predate the v108 stamp re-embed too after a model swap (both engines' `countStaleChunks`/`sumStaleChunkChars`/`invalidateStaleSignatureEmbeddings` accept the flag; predicate becomes `sig IS NULL OR sig <> current`). Without the flag, a live stale run that just invalidated drifted rows probes for left-behind NULL-signature chunks and emits a loud stderr warning naming the count + the fix — mixed embedding spaces in one index are never silent. Pinned by `test/embedding-migration.test.ts` + `test/e2e/migrate-embeddings-postgres.test.ts`. Embed failures are never silent: all three page paths embed via `embedPageTexts`, which tries the page's chunks in one batch and, on a PERMANENT request-shaped failure (non-429, non-`AITransientError`, non-auth), retries once per chunk so one bad chunk costs one chunk instead of darkening the whole page (failed chunks stay `embedding IS NULL` for the next `--stale` pass; a partially-failed page is never signature-stamped). Rate-limit/outage/auth failures do NOT fan out (cost bounding — `embedBatchWithBackoff` already owns 429 backoff). Failed chunk counts land on `EmbedResult.failures` + capped `failure_samples`, and `src/cli.ts`'s embed case sets a non-zero exit verdict on `failures > 0` (mirror of the `import` errors>0 guard). In `--stale`, a page whose guarded projection snapshot is unavailable when its turn comes (edited, tagged or unsealed after the readiness gate) counts its chunks as failures and is named in one end-of-run batch-summary sample (the first five slugs plus a count of the rest); a page whose source was archived mid-run is left to the archived-work report so it is counted once. Pinned by `test/embed-stale-unavailable-snapshot.serial.test.ts`. Pinned by `test/embed-partial-failure-3037.serial.test.ts` + `test/embed-exit-code-3037.serial.test.ts` (real spawned CLI). applies the `embed-skip` filter at all 5 stale-chunk sites: `runEmbedCore --stale`, `runEmbedCore --all`, the `embed-stale` Minion helper, plus both engines' `listStaleChunks` + `countStaleChunks` via `EMBED_SKIP_SQL_FRAGMENT`. A soft-blocked page is queryable by title/slug but its chunks never enter the embed sweep. The shared helper from `src/core/embed-skip.ts` is the single implementation — no per-site ad-hoc filter allowed. Pinned by `test/embed-skip.test.ts`. both inline sliding-pool sites (`embedAll` simple at `:458-467` and `embedAllStale` paginated + AbortSignal at `:586-632`) call `runSlidingPool` from the shared worker-pool helper. Invariant-level contract preserved (counts + cost + AbortSignal propagation + per-batch rate-limit retry via `embedBatchWithBackoff`); byte-equality on progress-event ORDERING is NOT promised. The `GBRAIN_EMBED_CONCURRENCY || 20` default is preserved and embed bypasses `resolveWorkersWithClamp` because the 20-worker default would otherwise silently change every brain's embed hot path. Pinned by `test/embed-default-concurrency.test.ts` (20 page workers on both paths when the env var is unset) and `test/embed-pool-abort.test.ts` (an abort stops both page pools from claiming further pages). wires `--background` as the reference integration for the `maybeBackground()` helper. `gbrain embed --stale --background` submits as a Minion job, prints `job_id=N` to stdout, exits 0. Composable: `JOB=$(gbrain embed --stale --background | grep -oE 'job_id=[0-9]+' | cut -d= -f2); gbrain jobs follow $JOB`. `runEmbedCore` accepts an optional `signal` threaded down both the `--stale` and `--all` paths (`embedAllStale`/`embedAll`/`embedPage`); each composes it with the internal wall-clock budget via `anySignal` and checks `isAborted`/`effectiveSignal.aborted` in every per-slug loop, page-claim pool, and `embedBatch` call, so a worker abort (wall-clock timeout / lock loss / SIGTERM) stops embedding within a batch. Pinned by `test/embed.serial.test.ts`. Keyless brains (`embedding_disabled: true`): the exported pure predicate `isKeylessStaleRefusal(args, embeddingDisabled)` gates a CLEAN refusal at the top of `runEmbed` — a bare stale run prints a stderr hint and returns a zero-failure result (exit 0), because the documented agent-scheduler chain `gbrain sync ... && gbrain embed --stale` must stay green on a keyless install; explicit asks (a slug, a slugs list, the all flag) and dry-run keep exiting 1 via `EmbeddingDisabledError`, mirroring the dispatch precedence where a slugs list wins over stale. Pinned by `test/embed-keyless-guard.test.ts` + `test/agent-scheduler-contract.test.ts`. The stale path's signature invalidation is PROBE-GATED — a drift pre-count (two `countStaleChunks` calls) followed by one live `probeEmbedder` embed call (from `src/core/embed-stale.ts`; validates a real vector whose dims match the signature's trailing `:<dims>`) must succeed before anything is NULLed, so a misresolved config (temp `GBRAIN_HOME` → default model, no key) can never strip vectors it cannot replace; a failed probe warns loudly on stderr and degrades to NULL-only staleness. Every live stale run also calls `engine.invalidateContentDriftEmbeddings` (not probe-gated — blast radius is bounded by real content edits) so chunks whose `embedded_text_hash` no longer matches `md5(chunk_text)` re-embed from their CURRENT text; NULL hash (pre-v133 rows) is grandfathered. Pinned by `test/embed-stale.test.ts` (probe-gate + content-drift blocks). The `--stale` single-flight lock HEARTBEAT (interval `GBRAIN_EMBED_LOCK_HEARTBEAT_MS`, default 5 min — test seam) is refresh-bounded per tick: each `refresh()` races a per-tick timeout (`GBRAIN_EMBED_LOCK_HEARTBEAT_TIMEOUT_MS`, default 30s via `DEFAULT_EMBED_LOCK_HEARTBEAT_TIMEOUT_MS`) with its own AbortController, so ONE never-settling refresh call can't silence the heartbeat forever; a slow tick never stacks on the next (`beating` guard), a refresh returning false (stolen/released lock) aborts the drain immediately as `lock_lost`, and 3 CONSECUTIVE tick failures (timeouts or throws) also abort as `lock_lost` rather than running without mutual exclusion. The interval is deliberately NOT unref'd (a lost drain promise stays a LOUD hang instead of a silent exit-0 that leaks the locks) while the per-tick timeout timer IS unref'd. `--stale` progress (#5968) is exact chunk accounting through `src/core/embed-stale-progress.ts`: `onProgress(done, total, embedded)` carries cumulative stale chunks against a total that grows by heal splits, behind-cursor rows and re-entries, the CLI ticks `embed.pages` by the delta and forwards the grown total with `setTotal`, and `done <= total` holds at every callback. `runEmbedCore --stale` also arms the progress-keyed stall watchdog from `src/core/embed-stall.ts` (`GBRAIN_EMBED_STALL_ABORT_SECONDS`, default 900 — see that entry): on stall it aborts the drain, releases the run's self-acquired locks, flushes the summary, and returns `reason: 'stall_timeout'`. Pinned by `test/embed.serial.test.ts` (heartbeat + stall blocks) + `test/jobs-embed-stall-wiring.serial.test.ts`. Explicit `--stale --facts --source ID` is a read-only NULL-fact preview; `--yes --max-cost-usd N` consents to bounded execution, not automatic/full-brain repair. Its result prints from `runEmbed` only without `--json`; under `--json` the CLI dispatch writes the one document. The selected-brain configuration is forwarded out of band to the resident owner, never reloaded from the host or supplied over the wire; selected and DB off-switches fail closed. #5183: the page-embedding worker count comes from `resolveEmbedConcurrency` in `src/core/embed-concurrency.ts` (GBRAIN_EMBED_CONCURRENCY, a paced cap, and on Postgres never above the client pool; one warning when an explicit setting is lowered). A chunkless page whose projection install loses to another installer (the resident rebuild) re-reads through `retryProjectionConflict` and embeds the sealed chunks it finds; a conflict that outlasts the retries is recorded as a `[page_projection_conflict]` failure sample with the envelope's next step (`test/embedding-recovery.serial.test.ts`). `--all` passes the sliding pool an `onError` handler: an error that escapes `embedOnePage` (its snapshot read runs before the page's own try) counts that page once on `result.failures` with an `Error embedding <slug>` stderr line, unless the run is already aborting when the error arrives (shutdown, not a failure); `test/embed-partial-failure-3037.serial.test.ts`. #6223: pages still blocked after bounded projection recovery no longer end `--stale` early; healthy chunks embed, the blocked pages' chunks count as failures, and one sample names them (not the mid-run "changed" summary) with `gbrain embed --stale --images` / `gbrain sync --full` for image and media pages. Fix wave 13 P1.18 (#6400): `runEmbed` takes the CLI's consent outcome; a finite approved `cap_usd` runs the foreground text and `--images` paths under `embedCostCap` (`src/core/embed-cost-cap.ts`) and returns `reason: 'cost_cap'` (exit `BUDGET_STOP_EXIT_CODE` from `src/cli/commands/embed.ts`, which now returns the Authorization from `authorizeEmbed`); `--background` stores it on the row through `maybeBackground(...spendAuthorization)` (PGLite runs inline, metered). `--slugs` takes the arguments up to the next flag. Tests: `test/embed-max-usd-metered.serial.test.ts`, `test/e2e/embed-background-cap.test.ts`. #6529: `runEmbed` with `--stale` (no `--slugs`) first runs `runStaleImageSweepFirst` (`core/embed-stale-images.ts`, multimodal installs only) inside the same cost cap and folds it into `EmbedResult.images`; the text pass's blocked-projection hint (`core/embedding-readiness.ts`) then points at that sweep's `missing_samples` instead of a separate `--images` command, and at `GBRAIN_EMBEDDING_MULTIMODAL=true` or `--images` / `sync --full` on a text-only install.
diff --git a/docs/architecture/key-files/core-persistence-facts.md b/docs/architecture/key-files/core-persistence-facts.md
index 91dac7d381..12e2d8ebb5 100644
--- a/docs/architecture/key-files/core-persistence-facts.md
+++ b/docs/architecture/key-files/core-persistence-facts.md
@@ -9,7 +9,8 @@ Managed facts extraction: the entity-intent preparer and publisher, conversation
- `src/core/facts/same-page-shadow.ts` — #6333 the shadow counter both fact writers share. `samePageRewording(engine, sourceId, fact, embedding)` re-reads the entity's nearest live same-visibility candidate (`listSupersessionCandidates`, the pool and filters of `decideSingleFact`'s cosine pass) and answers whether `wouldDedupSamePage` (capture-dedup.ts: same lane, same `source_session`, same visibility, cosine ≥ 0.85, no diverging guard token) would have called the fact a rewording; `warnSamePageShadow` is the one stderr spelling (`[facts-backstop] #6333 shadow: …; both kept`). `facts-prepare.ts` calls it for every candidate `decideSingleFact` did not match and counts `would_dedup_same_page` on the entity outcome, the completion outcome, `ManagedFactsResult` and the `extract_facts` result; the count is frozen in the receipt, so a replay reports it and does not recount. Nothing is dropped; this is the managed mirror of the unmanaged backstop's counter (`backstop.ts`), which never fired on a managed brain. Tests: `test/backstop-same-page-shadow-managed-6333.test.ts` (PGLite and Postgres), `test/backstop-same-page-shadow-6333.test.ts` (unmanaged).
- `src/core/persistence/derived-facts.ts` — `writeDerivedFacts`: the unmanaged conversation fact index commits in one maintenance transaction under the maintenance principal; on a managed brain it refuses with `writer_coordinator_required`, because every managed facts/takes writer publishes a receipted maintenance request (`test/receipt-coverage.test.ts` lists every coordinated write site). Tests: `test/write-attribution-misc.test.ts`.
- `src/core/facts/conversation-publication.ts` — managed conversation facts as database-only `managed_maintenance_conversation_facts` batch requests (`submitDatabaseMaintenanceIntent` on `ANCHOR_SLUG`, a dot-led slug no page can hold, dispatched from `prepareMaintenanceMutation`). Each page's frozen entry (`buildConversationPage`: `FrozenExtractedFact` rows, its generation and attempt, vectors only under the brain's facts embedding signature) joins the run's batch; `enqueueManagedPage` publishes it once `DEFAULT_BATCH_CAPS` is reached (25 pages, 10 with extracted facts, 8 MiB) and `flushManagedBatch` at the end of the run. The generation key (protocol, source incarnation, page id, revision, parser-input version token, `CONVERSATION_EXTRACTOR_VERSION`, selectors, newest extractor row id) is checked before model work by `startManagedPage` against `loadGenerationIndex` (the writer's unsettled and failed batches on the anchor, read once per run): a member of an unsettled batch waits and replays its receipt, a member of a retryably failed batch is resubmitted from its stored entry, a deterministic failure of a batch that held it alone or three failed batches block it (GBRA-130 A-51: `publishBatch` re-publishes a multi-page batch that failed deterministically in halves, so only the page that fails alone takes the code; `test/pathological/a-51-conversation-batch-booking.test.ts`); all without model calls. The batch request id digests its members' (generation, attempt) pairs; `submitConversationPages` raises every member's attempt past an id another write holds, or whose receipt lost its intent without committing (#7516: a redacted `purged_content` refusal or a compacted failure takes the attempt history `loadGenerationIndex` reads, so the same id came back on every run as `idempotency_conflict` after a paid extraction; test `test/conversation-facts-redacted-batch-7516.test.ts`, + Postgres arm). The preparer locks every member's key and applies each on its own (`applyEntry`): a deleted, replaced or moved page is skipped and reported, a page whose rows fail validation gets a durable `blocked:` not-extractable outcome, vectors under another signature are dropped; none fails the batch. `estimateConversationIntentBytes`/`conversationIntentByteLimit` skip a page whose largest entry cannot fit before any model call; `assertConversationAdmissionHeadroom` stops admitting at 80% of the writer's outstanding requests, reserved receipt bytes or lifetime ids (`maintenance_backpressure`, exit 12, naming the resource and a `--limit` that fits), up front for the run's planned batches and before each new batch. `publishConversationFacts` (the managed apply and the unmanaged writer) passes fact rows through the write gate at the page's derived tier and retires the prior batch only for a complete replacement (#7013: `full` scope, at least one fact, nothing held or rejected) or on a page with no active extractor facts, through `replaceConversationFacts`, which deletes the page's extractor rows (expiring referenced and keeping label-retired ones) and inserts the rows numbered above every remaining row, failing on a lost insert. Otherwise the prior facts stay: the outcome row replaces the page's prior outcome rows (so the page is not paid for again), a `window` run (`--since` dropped messages) adds its facts beside them, and a `partial` run (a `--segment-limit` cut, a page changed mid-run) publishes no facts over them. Each entry carries its `scope`; an entry frozen without one is `partial` without its outcome, `window` with a `--since` selector, else `full`. Rows carry an optional slot (GBRA-574 B2: `dimension`, `value`, `value_hash`, `dim_status 'active'`): `insertableSlots` drops a slot outside the vocabulary, without an entity, or whose unique slot key the page or an earlier row of the batch already holds (the fact stays), and `clearConversationFacts` clears the slot of every row it keeps expired in the same UPDATE. Tests: `test/pathological/h4-conversation-facts-zero-yield.test.ts` (managed and unmanaged, + Postgres arm). Tests: `test/conversation-facts-managed.test.ts` (+ Postgres arm), managed-connector contract cases `extract_conversation_facts*`.
-- `src/core/facts/slots.ts` — GBRA-574 B2/G4 conversation fact slots: the closed vocabulary (`location`, `employer`, `role`), `normalizeSlot` (entity required, value at most 80 characters), `CHANGE_CUE` and `deriveSlotEnds`, which works out read-time validity ends per (source, entity, dimension): a run of one value is one stint, and the next distinct value ends it at its `valid_from` only when it starts later and comes from a page the stint came from or its fact states a change; otherwise both values stay open. Nothing is written. The ontology keeps its own domain: `getOntology`, `discoverOntologyDimensions`, `findOntologyConflicts`, `mergeOntologyFact` and the ontology-facts repair skip conversation rows (`chronicle/ontology.ts` `NOT_CONVERSATION_SLOT_SQL`), `mergeOntologyFact` and the re-key dedup (`facts/ontology-rekey.ts`, also run by the twin merge) clear the slot of a conversation row that holds an observation's exact stint key instead of dropping either, and windows read conversation rows only. Tests: `test/facts-slot-windows-gbra574.test.ts` (+ Postgres arm), `test/facts/extract-slots.test.ts`.
+- `src/core/facts/slots.ts` — GBRA-574 B2/G4 conversation fact slots: the closed vocabulary (`location`, `employer`, `role`), `normalizeSlot` (entity required, value at most 80 characters), `CHANGE_CUE` and `deriveSlotEnds`, which works out read-time validity ends per (source, entity, dimension): a run of one value is one stint, and the next distinct value ends it at its `valid_from` only when it starts later and comes from a page the stint came from or its fact states a change; otherwise both values stay open. Nothing is written. The ontology keeps its own domain: `getOntology`, `discoverOntologyDimensions`, `findOntologyConflicts`, `mergeOntologyFact` and the ontology-facts repair skip conversation rows (`chronicle/ontology.ts` `NOT_CONVERSATION_SLOT_SQL`), `mergeOntologyFact` and the re-key dedup (`facts/ontology-rekey.ts`, also run by the twin merge) clear the slot of a conversation row that holds an observation's exact stint key instead of dropping either, and windows read conversation rows only. Tests: `test/facts-slot-windows-gbra574.test.ts` (+ Postgres arm), `test/facts/extract-slots.test.ts`, `test/facts/normalize-slot.test.ts`.
+- `src/core/facts/slot-tagging.ts` — GBRA-574 slot tagging: the main extraction call never asks for a slot, so `extractConversationWindow` sends a second small call (`tagSlots`, the facts extraction model, `SLOT_TAG_SYSTEM`, at most 10 facts and 400 output tokens) over the window's `fact` and `event` rows whose entity was named exactly (the extractor's name resolves to the same page through `resolveStrictEntityReference`: exact slug, unique basename or unique alias, never a prefix guess or a near name; or subject inference) and is a live, unretired `person` page; no candidate, no call, and BrainBench's injected extractor skips it. Each reply pair goes through `normalizeSlot`. A failed or unreadable reply keeps the facts without slots and counts `slot_tagging_failed`; abort and `BudgetExhausted` propagate. The per-page cap (`conversation-incremental.ts`) and `conversationRunEstimate` add one tagging call per window at its largest (`SLOT_TAG_INPUT_CHARS`). Tests: `test/facts/slot-tagging.test.ts`, `test/large-pages/conversation-slot-tagging-segmented.test.ts`.
- `src/core/facts/subject-infer.ts` — zero-LLM fact subject inference shared by the write paths (remember, the facts backstop) and `gbrain facts relink`. `inferFactSubject(engine, sourceId, { fact, pageSlug?, mode, excludePrivate? })` returns `{ slug, via: 'page' | 'mention' }` or a miss reason (`ambiguous`, `unverified_match`, `no_mention`, `no_page`). Page tier: the trusted page the fact came from, when it is a live fact-entity page. Mention tier: strong `extractCandidates` names plus slugs written in the text (lowercase Unicode page-slug letters without combining marks; a literal glued to further letters is not a literal), resolved through `resolveStrictEntityReference` (exact slug, unique basename, unique alias; `relink` mode adds the same-name trigram arm); exactly one entity links. Any other real name that does not resolve to the same entity (including names with no page and bare first names) vetoes the link; sentence-start capitals, weekdays/months and role terms (CEO, Q3) do not. `excludePrivate` removes private pages before uniqueness is counted. Also `appendContextNote`/`contextHead` (the `" — "` note convention), `recordedPageSlug` (page provenance of page-extraction rows only) and `isEntityInferenceEnabled` (`facts.entity_inference` kill switch for write-time inference; relink ignores it). `resolveStrictEntityReference` in `entities/resolve.ts` never guesses from a bare-name prefix and never slug-falls-back. Pinned by `test/facts-subject-infer.test.ts` (a 40+ fact labeled fixture: write precision >= 0.99, relink free tiers >= 0.95).
- `src/core/facts/conversation-subject-infer.ts` — #6764 write-time subject inference for `gbrain extract-conversation-facts` (both the classic and managed branches, trusted local only) and the free conversation relink. `inferConversationSubject` is the per-fact rule (a withdrawn claim misses as `withdrawn`); `inferConversationSubjects(engine, sourceId, visibility, rows)` gives each row the extractor left without an entity the slug `inferFactSubject` proves in `write` mode (mention tier; `excludePrivate` for world rows) plus the `entity inferred from <tier>` context note, unless `facts.entity_inference` is off or the claim was withdrawn. The row stays a derived row of the conversation page (`entity_slug` column only). Test: `test/conversation-facts-unlinked-6764.test.ts`.
- `src/core/facts/conversation-relink.ts` — `gbrain facts relink --conversation [--source] [--slugs] [--dry-run] [--json]` (#6764, dispatched from `src/commands/facts.ts`): the free relink of the conversation extractor's unlinked derived rows, which plain relink never examines. Pages are the named `--slugs`, else the 50 with the most unlinked rows not yet tried (`conversationRelinkPages`). Each row runs `inferConversationSubject` (write mode, visibility-filtered, withdrawn claims skipped; no model); a row the assistant or a third party said is never linked, never picks a page, and is counted as `not_user_attributed` (#7270). A page's links are one write: a managed brain publishes one database-only `managed_maintenance_conversation_relink` request on the anchor `.maintenance/conversation-relink` holding the page key (`prepareConversationRelink`, dispatched in `persistence/prepared-maintenance.ts`; the request id comes from the planned links, and a failed attempt retries under the next id), an unmanaged brain one `writeDerivedFacts` transaction. The write sets `entity_slug` and appends `entity relinked from <tier>` only on rows still exactly as planned (same claim, unlinked, active, target page live) and records a `linked` attempt; unresolved rows get a `conversation_unresolved` memo in `fact_relink_attempts` (reason the miss), which moves doctor `unlinked_facts` to the paid re-extraction fallback, and the report prints that command for their pages. Test: `test/conversation-relink-6764.test.ts`.
diff --git a/docs/architecture/key-files/security-continued.md b/docs/architecture/key-files/security-continued.md
index 10ce572be2..81ccd44b00 100644
--- a/docs/architecture/key-files/security-continued.md
+++ b/docs/architecture/key-files/security-continued.md
@@ -2,8 +2,10 @@
[Subsystem index](../KEY_FILES.md) · [Previous entries](security.md). Read only the entries relevant to your change.
-- `src/core/git-env.ts` + `src/core/hardened-git.ts` — #7584, the operator's `safe.directory` in scrubbed Git environments: `hardenedGitEnvironment` still drops system and global config and every `GIT_*` variable, but carries the operator's `safe.directory` entries (system and global, read from `/` with `git config --includes --show-scope` and cached for 30 s, then `GIT_CONFIG_*`) as environment config, so a source repository owned by another user reads once the operator allows it. `gitChildEnv` carries the environment entries the same way (`envSafeDirectories`, `safeDirectoryEnv`). Every other key in those places stays out. `gitChildEnv` also drops Git's global pathspec switches (`GIT_PATHSPEC_ENV_VARS`: `GIT_LITERAL_PATHSPECS`, `GIT_GLOB_PATHSPECS`, `GIT_NOGLOB_PATHSPECS`, `GIT_ICASE_PATHSPECS`; `extra` can still set one). gbrain's writers and readers mark each path literal with `literalPathspecs` (`:(literal)<path>`; an empty path throws, since `:(literal)` alone matches the whole tree, #7793), never `git --literal-pathspecs`, which Git exports to every hook, textconv and filter helper as `GIT_LITERAL_PATHSPECS=1`, where a hook's glob pathspec then matches nothing; `test/git-env-guard.test.ts` rejects a global pathspec switch (flag or env) anywhere in `src`. GST-2331: `NO_LAZY_FETCH_ENV` (`GIT_NO_LAZY_FETCH=1` and an empty `GIT_ALLOW_PROTOCOL`) is what a managed-sync read that runs under `gitChildEnv` adds beside `HARDENED_GIT_ARGS`, so a partial clone fetches nothing (Git before 2.45 ignores the first; the empty allowlist allows no transport on any Git): `syncGit`/`syncGitAsync`, every read in `sync-blobs.ts`, `sync-delta.ts`'s text runner (a rename whose old blob the clone lacks fails the diff, `diff_failed`, and discovery walks the whole tree), `sync-rename-identity.ts`, `sync-metafile-pages.ts`, `sync-origin-evidence.ts`, `sync-held-deletions.ts`, `unindexed-files.ts` and `pending-import.ts`. Tests: `test/hardened-git-safe-directory-7584.test.ts` (ownership forced with `GIT_TEST_ASSUME_DIFFERENT_OWNER` through a `git` wrapper on PATH), `test/git-literal-pathspec-hooks-7759.test.ts`, `test/git-literal-pathspecs-7793.test.ts`, `test/sync-partial-clone-2331.test.ts`.
+- `src/core/git-env.ts` + `src/core/hardened-git.ts` — #7584, the operator's `safe.directory` in scrubbed Git environments: `hardenedGitEnvironment` still drops system and global config and every `GIT_*` variable, but carries the operator's `safe.directory` entries (system and global, read from `/` with `git config --includes --show-scope` and cached for 30 s, then `GIT_CONFIG_*`) as environment config, so a source repository owned by another user reads once the operator allows it. `gitChildEnv` carries the environment entries the same way (`envSafeDirectories`, `safeDirectoryEnv`). Every other key in those places stays out. `gitChildEnv` also drops Git's global pathspec switches (`GIT_PATHSPEC_ENV_VARS`: `GIT_LITERAL_PATHSPECS`, `GIT_GLOB_PATHSPECS`, `GIT_NOGLOB_PATHSPECS`, `GIT_ICASE_PATHSPECS`; `extra` can still set one). gbrain's writers and readers mark each path literal with `literalPathspecs` (`:(literal)<path>`; an empty path throws, since `:(literal)` alone matches the whole tree, #7793), never `git --literal-pathspecs`, which Git exports to every hook, textconv and filter helper as `GIT_LITERAL_PATHSPECS=1`, where a hook's glob pathspec then matches nothing; `test/git-env-guard.test.ts` rejects a global pathspec switch (flag or env) anywhere in `src`. GST-2331: `NO_LAZY_FETCH_ENV` (`GIT_NO_LAZY_FETCH=1` and an empty `GIT_ALLOW_PROTOCOL`) is what a managed-sync read that runs under `gitChildEnv` adds beside `HARDENED_GIT_ARGS`, so a partial clone fetches nothing (Git before 2.45 ignores the first; the empty allowlist allows no transport on any Git): `syncGit`/`syncGitAsync`, every read in `sync-blobs.ts`, `sync-delta.ts`'s text runner (a rename whose old blob the clone lacks fails the diff, `diff_failed`, and discovery walks the whole tree), `sync-rename-identity.ts`, `sync-metafile-pages.ts`, `sync-origin-evidence.ts`, `sync-held-deletions.ts`, `unindexed-files.ts` and `pending-import.ts`. Tests: `test/hardened-git-safe-directory-7584.test.ts` (ownership f... (line truncated to 2000 chars)
- `src/core/outside-content.ts` — GBRA-221: `neutralizeOutsideText(text)`, the one neutralizer for text a third party wrote before it lands in a page body (Gmail/Calendar/Contacts renders in `google-render.ts`, GitHub `renderItemPage`/`renderRepoCard`, chat transcripts in `transcripts/render.ts`, `book-mirror` chapter output). It escapes every `gbrain<ws>:<ws><name>` marker token to `gbrain\:<name>` (case-insensitive), `[Source:` to `[Source\:`, and backslash-prefixes each timeline sentinel, bare `## Timeline`/`## History` heading, dated timeline row or heading, transcript message anchor and date heading, using the parsers' own predicates. Idempotent and readable; apply it per outside field (or a composed line holding one), never to a whole page that may hold gbrain's own fences or citations. Also owns `escapeAnchorLines` and `MESSAGE_ANCHOR_RE` (re-exported by `transcripts/render.ts`). New connectors use it.
- `src/core/function-search-path.ts` — #7632 search_path hardening (#7688, #7785): `PINNED_FUNCTION_NAMES` (every gbrain function with a pinned search_path; `scripts/check-search-path.sh` fails one missing from it or a pinned path not ending in `pg_temp`), `FUNCTION_SEARCH_PATH_HARDENING_SQL` (the schema blob's last statement), and `hardenFunctionSearchPaths` (v277 and the end of every migration run: one transaction under the migration timeouts, a pg_proc row lock it cannot take becomes `schema_lock_blocked`, a concurrent pg_proc update is retried, returns the functions left or null when listing them failed; it first re-creates the purge and withdrawal guards its role owns, retrying a concurrent update, and a re-create failure other than SQLSTATE 42501 is thrown as `LedgerGuardRecreateError` after the hardening runs, which `hardenFailureLine` prints as a `guards:` line). Doctor checks: `src/commands/doctor/checks/guard-ledger-checks.ts` (`guard_ledger_checks`, Postgres only: names each guard missing its ledger check, from `ledgerGuardsWithoutCheck` in `src/core/guard-ledger-checks.ts`, with its owner) and `src/commands/doctor/checks/function-search-path.ts` (`function_search_path`: names any pinned function whose path does not end in `pg_temp`; the fix is `gbrain apply-migrations --yes` below v277, else the schema-qualified `ALTER FUNCTION` SQL (argument types only) in `details.sql` to run as the owner, with no runnable fix).
- `src/core/facts/private-fact-pages.ts` + `src/commands/auth-private-facts.ts` + `src/commands/auth-client-rows.ts` — the per-credential private-facts axis (`PrivateFactsGrant` `none` | `granted_sources` in `access_tokens.private_facts` and `oauth_clients.private_facts`, migration v319 `principal_private_facts`, default `none`, never in the legacy permissions mirror; set only by the local `gbrain auth rescope --token|--client --private-facts`, refused for a credential with scope sources in `src/core/access/attest-sources.ts`). MCP dispatch puts the explicitly named sources (as for private pages, never the `default` floor) in `privateFactSources()` (`src/core/search/private-visibility.ts`) for remote reads only, never for mutating ops, `context_pack` or `delta`, an asserted audience, an attested actor, a scope read or an enforced member read; `grantedPrivateFactSql` (`src/core/access/member-facts.ts`) admits a private fact only in those sources and only while `factPagesOpenSql` holds: its holding, provenance (`factProvenanceSlugSql`) and entity pages are all open (not private, `readable_by`, folder-ruled, quarantined or a member page, `factPageReasons`), and it is not unpaged or in a transcript lane (`unpagedFactSql`). `gbrain repair open-facts` shares the same page predicate. The hot-memory cache (`src/core/facts/meta-hook.ts`) keys a granted read as `<tier>+xpf=<sorted sources>` and the query cache adds `xpf=` to its knobs hash, so a payload read under the grant never serves a credential without it. `auth-private-facts.ts` renders the setting, the rescope before/after lines and the warning; `auth-client-rows.ts` is `gbrain auth clients`' listing with a degrade ladder that drops `private_facts`, then `private_pages`, on older brains. Tests: `test/private-facts-grant-8194.test.ts`, `test/e2e/private-facts-grant-postgres.test.ts`, `test/qm-scope-writes.test.ts`, `test/auth-private-pages-output.test.ts`.
+- `src/core/access/owner-only.ts` — owner-only sources: a source of a kind in `OWNER_ONLY_KINDS` (`imessage`) or with `owner_only: true` in `sources.config` is read only by the local CLI and by a credential bound to the brain owner speaking for itself (`CallerAccess.owner`). Decided at read time from `sources`, so nothing is stored per page and no migration runs. `ownerOnlyPageSql` and `ownerOnlyFactSql` match a row in an owner-only source, a synthesized concept with a `concept-provenance` input there, or a row whose `derivation_inputs` (followed up to `OWNER_ONLY_LINEAGE_DEPTH` hops) reach a page, fact, take or timeline row there; each leads with one uncorrelated `EXISTS` over `sources`, so a brain with no owner-only source pays one InitPlan. `src/core/search/private-visibility.ts` appends them to the mandatory member-access part of the page and fact policies (no grant, hatch or lineage switch relaxes them), and `src/core/persistence/page-visibility.ts` refuses a remote write into an owner-only source from any credential but the owner's (`page_not_found`). `ownerOnlySourcesPresent` and `sourceIsOwnerOnly` fail closed. Tests: `test/imessage-owner-only.test.ts` (every caller class under each relaxation), `test/e2e/imessage-source-postgres.test.ts`.
+- `src/core/imessage/` + `src/core/apple/helper-client.ts` — the `imessage` connector kind. `helper-client.ts` reads the GBrain Helper's `/v1/imessage/threads` and `/v1/imessage/thread` over 127.0.0.1 with a bearer token (config `apple.helper.port`; token from `i_token_env`, `GBRAIN_CONNECTOR_IMESSAGE_TOKEN` or `~/.gbrain/connectors/imessage.json`) and maps the helper's problem codes to `apple_helper_not_running`, `apple_helper_unauthorized`, `apple_full_disk_access_pending` and `apple_schema_mismatch`, each of which stops the run. `imessage-source.ts` keeps a per-chat coverage window (`connectors/api-source.ts`) with a lookback that re-renders recent days, writes one `type: imessage`, `visibility: private` page per chat per day in the source's time zone (`render.ts`; the chat key is a hash, so no handle reaches a slug, the cursor or a log), always database-recorded and gated at the external-untrusted tier, and deletes a day whose messages were all unsent. `source-add.ts` is `sources add --kind imessage` (no `--dir` or `--record`). Tests: `test/imessage-source.test.ts`, `test/helpers/imessage-helper-fixture.ts`.
diff --git a/docs/contracts/public-surface.json b/docs/contracts/public-surface.json
index 98d703718f..fb8d8c0a96 100644
--- a/docs/contracts/public-surface.json
+++ b/docs/contracts/public-surface.json
@@ -1894,6 +1894,7 @@
"agent.use_gateway_loop",
"ai.chat.per_turn_timeout_ms",
"anthropic_api_key",
+ "apple.helper.port",
"artifacts_sync_mode",
"auto_chronicle",
"auto_link",
@@ -2420,6 +2421,10 @@
"answer_unavailable": 1,
"api_not_enabled": 1,
"append_links_fence": 1,
+ "apple_full_disk_access_pending": 1,
+ "apple_helper_not_running": 1,
+ "apple_helper_unauthorized": 1,
+ "apple_schema_mismatch": 1,
"approval_required": 1,
"archive_audience_unproven": 1,
"archive_gateway_auth": 1,
@@ -2475,6 +2480,9 @@
"chronicle_skipped": 1,
"chunkless_pages_healable": 1,
"claim_already_used": 1,
+ "class_apply_busy": 1,
+ "class_capacity_exceeded": 1,
+ "class_manifest_stale": 1,
"client_behind": 1,
"client_json_unreadable": 1,
"client_json_wrong_type": 1,
@@ -2831,6 +2839,7 @@
"purge_mirror_unwritable": 1,
"purge_replay_incomplete": 1,
"purged_content": 1,
+ "push_credential_refused": 1,
"push_unconfirmed": 4,
"question_not_found": 1,
"question_owner_only": 1,
@@ -3064,6 +3073,7 @@
"wakeshift_refused": 1,
"wakeshift_shared_brain": 1,
"wakeshift_unavailable": 1,
+ "whole_class_prefer_unsupported": 1,
"withdrawal_capacity": 1,
"withdrawal_mirror_failed": 1,
"withdrawal_mirror_pending": 1,
diff --git a/docs/evidence-delivery.md b/docs/evidence-delivery.md
index cd707c197b..b685bd6f3a 100644
--- a/docs/evidence-delivery.md
+++ b/docs/evidence-delivery.md
@@ -196,9 +196,9 @@ parameter (when the fact was said or became true). A `valid_from` that only
records the write time (within a minute of `created_at`) reads `unknown`, so a
header never presents when a fact was written as when it became true. An open
validity end reads `unknown`. When a conversation fact carries a slot
-(`location`, `employer` or `role`; extraction does not ask the model for one
-at the moment, so only facts stored with one under 0.60.735.0 have it, until
-the part of the page they came from is extracted again), the facts block and the temporal fact reserve work out its end
+(`location`, `employer` or `role`, tagged by a second small call after
+extraction on facts about a person whose page the extractor named exactly),
+the facts block and the temporal fact reserve work out its end
at read time: the start of the next different value for the same person, when
that value came from the same conversation or its fact says the value changed
(moved, joined, left and similar words). Otherwise both values stay open and
diff --git a/docs/guides/access-designations.md b/docs/guides/access-designations.md
index 6c05afc9dc..8e20047390 100644
--- a/docs/guides/access-designations.md
+++ b/docs/guides/access-designations.md
@@ -39,6 +39,7 @@ Five kinds of caller read a brain:
| folder rule (`gbrain access rule`) | reads | only when listed | only when listed | hidden | only when every entry is listed |
| derived from a `readable_by` page | reads | hidden | hidden | hidden | hidden |
| fact `visibility: private` | reads | reads | hidden | hidden | hidden |
+| page or fact in an owner-only source (`imessage`, `owner_only: true`), or derived from one | reads | reads | hidden | hidden | hidden, under every relaxation |
"Hidden" means the same `not_found` a missing page gets, on every read path (get_page, search, query, recall, lists,
links, timelines, versions). Designations govern readers, not processing: restricted pages are embedded
@@ -243,6 +244,18 @@ owner agent can copy private content into a shared page. A prompt planted in a p
Bind only agents you trust with the whole brain as the owner; give every other agent its own member, whose new pages
stay kept to it.
+### Owner-only sources (`owner_only`)
+
+An `imessage` source, and any source whose `sources.config` has `owner_only: true`, is read only by the local CLI and
+by the owner's own credentials speaking for themselves. Every other remote caller gets `not_found` for its pages
+(private or not), for its facts and timeline rows, and for pages and facts derived from them: a synthesized concept
+with an input page there, and any page or fact whose recorded derivation inputs reach a row there. None of the
+relaxations above widens it: `--private-pages granted-sources`, `--private-facts granted-sources`,
+`search.remote_private_pages`, `access.members_read_lineage`, `access.owner_reads_restricted` and
+`visibility.honor_aliases` leave it in place, and so do shared-room audiences, guests and attested calls. A remote
+write into an owner-only source from any credential but the owner's is refused the same way. The rule is worked out
+at read time from the source, so nothing is stored per page and a repo-less brain works the same.
+
### Audience members (`gbrain access member kind`)
A member can stand for a group chat or a shared assistant rather than a person. `gbrain access member kind <id>
diff --git a/docs/guides/apple-setup.md b/docs/guides/apple-setup.md
new file mode 100644
index 0000000000..8f0c409692
--- /dev/null
+++ b/docs/guides/apple-setup.md
@@ -0,0 +1,66 @@
+# iMessage on a Mac
+
+The `imessage` source kind brings your Messages history into your brain: one page per chat per day. It reads
+through GBrain Helper, a small app that runs on your own Mac and is the only thing that opens the Messages
+database. gbrain talks to the helper over `127.0.0.1` and never reads the database itself.
+
+Your messages hold other people's words, so these pages get stricter handling than any other kind:
+
+- **Owner-only.** Only you read them: the gbrain CLI on the brain's machine, and agents whose credentials are bound
+ to you as the brain's owner (`gbrain access owner set <member>`). Every other member, guest, shared room, attested
+ call or unbound key gets `not_found`, for the pages and for anything derived from them (facts, concepts,
+ timelines), whatever relaxations the brain has on. See
+ [owner-only sources](access-designations.md#owner-only-sources-owner_only).
+- **Private and database-only.** Every page is `visibility: private` and lives only in the database, even on a brain
+ that has a Git repository: nothing is written to the checkout, committed or pushed.
+- **Untrusted text.** Pages are stored at the external-untrusted trust tier, like email, so instructions inside a
+ message are never treated as yours.
+- **Nothing paid by default.** Pages are embedded and facts extracted only if you configured a provider for that.
+
+## Register and sync
+
+```bash
+gbrain config set apple.helper.port <port> # the helper's loopback port
+gbrain sources add messages --kind imessage --timezone America/Los_Angeles
+gbrain sync --source messages
+```
+
+The helper's token is read from `GBRAIN_CONNECTOR_IMESSAGE_TOKEN`, else from `~/.gbrain/connectors/imessage.json`
+(mode 0600), or from the variable a source names with `--token-env`. It never goes in `sources.config`, the
+database or a log.
+
+Options: `--history-days` (how far back the first sync reads, default 30), `--lookback-days` (recent days re-read
+every sync, default 7), `--timezone` (where a day page starts at midnight, default UTC), `--sync-interval-min`
+(default 15) and `--federated` (join unqualified searches; off by default). `--dir`, `--record` and
+`--visibility` are refused: the source is always private and database-only.
+
+Each sync reads the chats with new messages and rebuilds every day in the lookback window, so an edit or an unsend
+on your phone shows up and facts taken from the old text are retired. A message deleted after the lookback stays
+until you delete the page. Running a sync twice writes nothing the second time.
+
+The owner-only rule follows the source while it is registered and its pages are still in the database. If you
+remove the source (`gbrain sources remove`) or purge its pages, a concept or fact stored in another source that was
+derived from them is no longer hidden. Delete those derived pages and facts first if they should stay private.
+
+## Errors
+
+### apple_helper_not_running
+
+Nothing answered on the helper's port: the helper is stopped, the Mac is asleep, `apple.helper.port` is not set,
+or the helper has its iMessage source turned off. Nothing was imported. Start GBrain Helper, check
+`gbrain config get apple.helper.port`, then `gbrain sync --source <id>`.
+
+### apple_helper_unauthorized
+
+The helper refused gbrain's token, or gbrain has none. Save the helper's current token where GBrain reads it (above),
+then sync again.
+
+### apple_full_disk_access_pending
+
+The helper is running but macOS has not let it read Messages. Open System Settings > Privacy & Security > Full Disk
+Access, switch on GBrain Helper, then sync again. A grant turned off later gives the same error.
+
+### apple_schema_mismatch
+
+The helper does not recognise the Messages database, usually after a macOS update changed it. Update gbrain and
+GBrain Helper, then sync again.
diff --git a/docs/guides/error-codes.md b/docs/guides/error-codes.md
index 9d73e751ca..107697b501 100644
--- a/docs/guides/error-codes.md
+++ b/docs/guides/error-codes.md
@@ -334,6 +334,46 @@ More: [docs/guides/google-connect.md#troubleshooting](../../docs/guides/google-c
|---|---|---|---|---|---|---|
| append_page text held a links fence marker, so nothing was appended. | A page has one links section, and the rows it lists are the page's authored links: an appended links table would replace that section and delete every link it does not list. | Write each link with add_link (from, to, link_type); it adds the row to the page's links section and keeps the rows already there. | agent | `repeat the read that failed` | 1 | no |
+### apple_full_disk_access_pending
+
+<a id="apple_full_disk_access_pending"></a>
+
+| Meaning | Why | Next step | Who acts · consent | Verify | Exit | Retryable |
+|---|---|---|---|---|---|---|
+| GBrain Helper is running but cannot read Messages because Full Disk Access is off for it, so nothing was imported. | macOS lets an app read the Messages database only after the user switches it on in System Settings; only the user can do that, and a grant can be turned off again later. | Ask the user to open System Settings > Privacy & Security > Full Disk Access and switch on GBrain Helper, then run gbrain sync --source <id>. | user | `repeat the read that failed` | 1 | no |
+
+More: [docs/guides/apple-setup.md#apple_full_disk_access_pending](../../docs/guides/apple-setup.md#apple_full_disk_access_pending)
+
+### apple_helper_not_running
+
+<a id="apple_helper_not_running"></a>
+
+| Meaning | Why | Next step | Who acts · consent | Verify | Exit | Retryable |
+|---|---|---|---|---|---|---|
+| Nothing answered on the GBrain Helper's loopback port (the helper is stopped, the Mac is asleep, or apple.helper.port is not set), so nothing was imported. | An imessage source reads only from the helper on the same Mac over 127.0.0.1; it never opens the Messages database itself. | Start GBrain Helper on this Mac and check gbrain config get apple.helper.port names its port, then run gbrain sync --source <id>. | user | `repeat the read that failed` | 1 | no |
+
+More: [docs/guides/apple-setup.md#apple_helper_not_running](../../docs/guides/apple-setup.md#apple_helper_not_running)
+
+### apple_helper_unauthorized
+
+<a id="apple_helper_unauthorized"></a>
+
+| Meaning | Why | Next step | Who acts · consent | Verify | Exit | Retryable |
+|---|---|---|---|---|---|---|
+| GBrain Helper refused the token gbrain sent, or gbrain has no helper token, so nothing was imported. | The helper answers only a request that carries one of its own tokens with the read:imessage scope; the token is read from the source's --token-env variable when it names one, else GBRAIN_CONNECTOR_IMESSAGE_TOKEN, else the 0600 file ~/.gbrain/connectors/imessage.json. | Save the helper's current token where GBrain reads it, then run gbrain sync --source <id>. | user | `repeat the read that failed` | 1 | no |
+
+More: [docs/guides/apple-setup.md#apple_helper_unauthorized](../../docs/guides/apple-setup.md#apple_helper_unauthorized)
+
+### apple_schema_mismatch
+
+<a id="apple_schema_mismatch"></a>
+
+| Meaning | Why | Next step | Who acts · consent | Verify | Exit | Retryable |
+|---|---|---|---|---|---|---|
+| GBrain Helper does not recognise the layout of the Messages database (macOS may have changed it), so nothing was imported. | The helper reads only the tables and columns it knows; it refuses a changed database rather than guess at it. | Update GBrain and the GBrain Helper to their newest versions, then run gbrain sync --source <id>. | agent | `repeat the read that failed` | 1 | no |
+
+More: [docs/guides/apple-setup.md#apple_schema_mismatch](../../docs/guides/apple-setup.md#apple_schema_mismatch)
+
### approval_required
<a id="approval_required"></a>
@@ -834,6 +874,36 @@ More: [docs/guides/troubleshooting.md#embedding-state](../../docs/guides/trouble
More: [docs/guides/google-connect.md#troubleshooting](../../docs/guides/google-connect.md#troubleshooting)
+### class_apply_busy
+
+<a id="class_apply_busy"></a>
+
+| Meaning | Why | Next step | Who acts · consent | Verify | Exit | Retryable |
+|---|---|---|---|---|---|---|
+| Another apply of the same whole-class file-drift manifest is running, so this run wrote nothing. | One whole-class apply per manifest at a time keeps its progress record and request ids consistent; a second apply would race the first over the same pages. | Wait for the running apply to finish. If it was stopped, rerun the same apply command once its lock expires (the message names when); it resumes at the next window and applies no page twice. | agent | `repeat the read that failed` | 1 | yes |
+
+More: [docs/guides/repair.md#whole-class](../../docs/guides/repair.md#whole-class)
+
+### class_capacity_exceeded
+
+<a id="class_capacity_exceeded"></a>
+
+| Meaning | Why | Next step | Who acts · consent | Verify | Exit | Retryable |
+|---|---|---|---|---|---|---|
+| A whole-class file-drift preview found that the reconcile backups its apply would retain exceed the brain's recovery-bytes limit, so nothing was written. | Every page the apply replaces keeps a private reconcile backup, and those backups are bounded by persistence.limits.brain_recovery_bytes; an apply that ran out of room would stop partway through the class. | Show the user the bytes needed and the limit the message names. Raising persistence.limits.brain_recovery_bytes is their call; otherwise settle a smaller class with --only / --skip. Run: gbrain config get persistence.limits.brain_recovery_bytes | user | `repeat the read that failed` | 1 | no |
+
+More: [docs/guides/repair.md#whole-class](../../docs/guides/repair.md#whole-class)
+
+### class_manifest_stale
+
+<a id="class_manifest_stale"></a>
+
+| Meaning | Why | Next step | Who acts · consent | Verify | Exit | Retryable |
+|---|---|---|---|---|---|---|
+| The whole-class file-drift manifest no longer matches the hash passed with --expect or the pins its preview saved, so nothing was written. | The apply replaces exactly the pages the user approved; a manifest that was edited, partly written, removed, or previewed for another selection is not that approval. | Run the fresh preview the message prints, show the user its card, and apply its new hash after they agree. | agent | `repeat the read that failed` | 1 | no |
+
+More: [docs/guides/repair.md#whole-class](../../docs/guides/repair.md#whole-class)
+
### client_behind
<a id="client_behind"></a>
@@ -4214,6 +4284,18 @@ More: [docs/guides/write-refusals.md#purge_replay_incomplete](../../docs/guides/
More: [docs/guides/memory-boundaries.md#purge](../../docs/guides/memory-boundaries.md#purge)
+### push_credential_refused
+
+<a id="push_credential_refused"></a>
+
+| Meaning | Why | Next step | Who acts · consent | Verify | Exit | Retryable |
+|---|---|---|---|---|---|---|
+| The Git host refused the push for the credential git used ("Repository not found", HTTP 404, or HTTP 403); the commit is durable locally and nothing was pushed or retried. | A host answers "Repository not found" to an account that cannot see a private repository, and 403 to one that may not write to it. The same credential is refused on every attempt, so a retry only hides the fault while commits stay on this machine; which credential git uses is the user's configuration, and gbrain never changes it. | Relay the message to the user: it names the credential helpers git asked (with the scope and file that configure each), which one answered and its account login. Once they make git use a credential for an account that can push there, run gbrain git commit-push --push-only. | user | `gbrain doctor --json` | 1 | no |
+
+Reasons: `not_found`, `forbidden`.
+
+More: [docs/guides/shared-checkout-git.md#push_credential_refused](../../docs/guides/shared-checkout-git.md#push_credential_refused)
+
### push_unconfirmed
<a id="push_unconfirmed"></a>
@@ -6424,6 +6506,16 @@ More: [docs/guides/wakeshift.md#shared-brains](../../docs/guides/wakeshift.md#sh
More: [docs/guides/wakeshift.md#troubleshooting](../../docs/guides/wakeshift.md#troubleshooting)
+### whole_class_prefer_unsupported
+
+<a id="whole_class_prefer_unsupported"></a>
+
+| Meaning | Why | Next step | Who acts · consent | Verify | Exit | Retryable |
+|---|---|---|---|---|---|---|
+| gbrain repair file-drift --whole-class settles only --prefer file on held side unknown, database or both, so a --prefer database or deleted-side selection was refused before anything was read. | Letting the database win rewrites files, and each deleted-side state is its own decision; neither is settled for a whole class with one approval. | Preview that selection one window at a time with the per-window command the message names (--held --side <side> --prefer <side>, without --whole-class). Run: gbrain sources status '{source_id}' --json | agent | `repeat the read that failed` | 1 | no |
+
+More: [docs/guides/repair.md#whole-class](../../docs/guides/repair.md#whole-class)
+
### withdrawal_capacity
<a id="withdrawal_capacity"></a>
diff --git a/docs/guides/meeting-and-slack-sources.md b/docs/guides/meeting-and-slack-sources.md
index 8f2cb22c8b..1d2d0290ab 100644
--- a/docs/guides/meeting-and-slack-sources.md
+++ b/docs/guides/meeting-and-slack-sources.md
@@ -5,6 +5,8 @@ provider into brain pages, one page per meeting, on a schedule, with no
custom script. Fireflies is the first provider; others plug in behind the
same provider interface. The `slack` source kind imports chosen Slack
channels, one page per channel per day; see [Slack channels](#slack-channels).
+Messages on a Mac (the `imessage` kind, private and owner-only) are covered in
+[iMessage on a Mac](apple-setup.md).
The feature is opt-in and dormant until you register a meetings source and
run its first sync yourself.
diff --git a/docs/guides/repair.md b/docs/guides/repair.md
index 09a27cd2b3..48dd288ac2 100644
--- a/docs/guides/repair.md
+++ b/docs/guides/repair.md
@@ -3752,14 +3752,55 @@ gbrain repair file-drift --source <id> --held --json # compare every h
<a id="file-drift-compare-mirror"></a>On a [read-only mirror](multi-source-brains.md#read-only-mirror-sources)
(GST-2843), the held comparison reads each held page's file too: a page that
differs reads `prefer_file` or `needs_human` with its `evidence` (a held deleted
-page whose file differs reads `needs_human` and names the same route), one that
+page whose file differs reads `needs_human` and names
+[keeping the deletion](#mirror-keep-deleted) first and `gbrain sources
+mirror-writable <id>` second, never a `--prefer file` preview; a `purged_differs`
+page has no deletion to keep and names only `mirror-writable`), one that
matches reads `release_hold`, and only a page whose file is gone reads
`no_drift` with `database_only`. Every compared page in `details.pages`
-carries `evidence` (null when nothing was read). The comparison names no
-`--prefer` preview there, because a mirror's previews read every page as
-database-only and resolve nothing: a differing page stays held until the user
-makes the source writable again (`gbrain sources mirror-writable <id>`, which
-lets gbrain write files into its checkout) and picks a side then (GST-2869).
+carries `evidence` (null when nothing was read). The window previews read the
+same way, so `--held --side unknown --prefer file` lists a page whose file is
+newer `prefer_file`; the comparison names the [whole-class](#whole-class)
+preview of the side, which settles every such page with one approval and never
+writes the mirror's checkout.
+
+<a id="whole-class"></a>**Whole class.** `--whole-class` previews every window
+of one side (`--held --side unknown|database|both --prefer file`) as one class:
+one manifest, one hash, one approval. A large read-only mirror can hold
+thousands of pages, and a window preview covers 200.
+
+```bash
+gbrain repair file-drift --source <id> --held --side unknown --prefer file --whole-class # read-only: writes only a private manifest
+gbrain repair file-drift --source <id> --held --side unknown --prefer file --whole-class --apply --expect <hash> --yes # after the user agrees
+```
+
+The preview writes `repair-previews/file-drift/class-<hash>.json` under the
+gbrain config directory: per page its slug, path, revision, file blob, hold
+code, side, upstream version and lost lines. Its output (and `--json`) carries
+`details.class_manifest` with `path`, `hash`, `complete`, `pages`,
+`lost_lines_total`, `top` (the 50 pages that lose most lines) and `residual`
+(each kept group's count and next command), then the data-loss card: what is
+replaced, how many lines are lost, and how it comes back (`gbrain revert` from
+the page version saved first, and reconcile's private backup). Two groups stay
+held: `kept_newer_page` (edited in gbrain after the file's last commit) and,
+on a read-only mirror, `kept_protected_parts` (the file would need gbrain's
+protected keys, takes or private facts appended). A preview that stops early
+says `complete: false`, prints a resume command and no apply command.
+
+The apply needs the user's yes on the hash and the trusted local CLI. Each page
+is re-read: it applies only while its revision, file blob, hold code, side,
+upstream version and mirror flag still match and its lost lines did not grow,
+so a sync that only rewrote hold records keeps the approval; anything else is
+skipped and stays held. On a read-only mirror the file is imported into the
+page database-only, and the next sync releases each hold. A stopped apply
+prints its resume command first, then applied, skipped and remaining, and
+exits 1; a rerun resumes at the next window and applies no page twice.
+Refusals: `whole_class_prefer_unsupported` (`--prefer database` or `--side
+deleted`; use the window preview), `class_capacity_exceeded` (the backups would
+pass `persistence.limits.brain_recovery_bytes`; raising it is the user's call),
+`class_manifest_stale` (the manifest no longer matches its hash; preview again)
+and `class_apply_busy` (another apply of the same manifest is running). A brain
+with no repository has no held pages: the preview says so and exits 0.
<a id="file-drift-kept-newer"></a>`--prefer file` never drops a page edited after its file's last commit in
bulk. A `--held`, `--all-drifted` or `--request` preview lists such a page
diff --git a/docs/guides/shared-checkout-git.md b/docs/guides/shared-checkout-git.md
index 1d2674d0eb..cb2b26dd39 100644
--- a/docs/guides/shared-checkout-git.md
+++ b/docs/guides/shared-checkout-git.md
@@ -233,6 +233,7 @@ Follow the error's `fix.next` as the
| <a id="publish_secret_found"></a>`publish_secret_found` | 1 | On every push `gbrain git commit-push` makes (commit mode, `--pending` and `--push-only`; `--scan-secrets` is accepted for older scripts), so also the post-commit hook `gbrain sources harden` installs and `scripts/brain-commit-push.sh`, and on every automatic publish: the one `gbrain sources refresh` runs on its own, the push of a managed worktree's Git effects, doctor `git_convergence`'s push fixes, the access-policy and durability-scaffolding commits, `gbrain sources push` and the first push of `gbrain bootstrap repo` (#8902; there the remote has no branch yet, so the whole history is scanned). A commit about to be pushed that gbrain did not make for a page write (its commit ledger records its own page-write commits, whose bodies are stored raw by design and are not scanned; a Git effect's commit counts only by the sha gbrain created for it, when its files held the bytes the effect wrote, so an amended or reworded copy is scanned; one that adopted a file edited outside gbrain, or one older than the retained ledger, is scanned) adds a value that looks like a secret, in its message, an added line (even one a later commit removed) or a merge resolution, adds text too large to scan, or changes `.gbrain-scan-allow` or a `.gitattributes` (files that decide what the scan sees); nothing was pushed. The message names each file, line, rule and commit, never the value. Ask the user: remove the value from those unpushed commits, or add a false positive's fingerprint to `.gbrain-scan-allow`, then retry. A commit that changes `.gbrain-scan-allow` or a `.gitattributes` is never published automatically: the user reviews it and pushes it. The exception is the commit `gbrain sources push` or `gbrain bootstrap repo` makes itself from files it has just scanned with that allowlist. Never publish them with a command that skips the scan. On a managed worktree its Git effects hold meanwhile (`gbrain sync status` and doctor list them; the page writes are safe in the database and in local commits); after the fix, `gbrain sources writer retry-effects <source> --parked-pushes` runs the ones that parked. |
| <a id="publish_scan_unreadable"></a>`publish_scan_unreadable` | 1 | Wherever `publish_secret_found` can refuse: the scan could not read the commits about to be pushed in full (a missing or corrupt object, git output it does not recognise, or its time budget), so it reported no secret and nothing was pushed. When it ran out of time (a first push of a long history can need more than the 300 s default), the fix is the same command with `--scan-timeout <seconds>`, four times the budget and at least 1200: run it; the scan still reads every commit, and prints its progress on stderr. `gbrain git commit-push`, `gbrain sources push` and `gbrain bootstrap repo` take `--scan-timeout`. Otherwise run `git fsck` in the checkout, fix what it names, then retry. When the remote has no such branch, a managed worktree's Git effect scans the branch's whole history and creates it only when that scan passes; a history too large to scan in the owner process holds the effects with this code and names `git ls-remote --heads <remote>`: check the upstream, then point it at the right branch or review the history and push the branch yourself. Never publish with a command that skips the scan. On a managed worktree its Git effects hold meanwhile, as for `publish_secret_found`. |
| `integrate_conflict` | 1 | Local and remote commits changed the same file; nothing was merged and the checkout is unchanged. Stop, relay the question to the user, then [resolve](#conflicts). |
+| <a id="push_credential_refused"></a>`push_credential_refused` | 1 | The Git host refused the push for the credential git used: "Repository not found" (HTTP 404, what a host tells an account that cannot see a private repository) or HTTP 403 (permission denied). The commit is durable locally; nothing was pushed and gbrain did not retry, because the host refuses the same credential every time (before this code, the refusal was `push_unconfirmed`, exit 4, and read as transient). The message names the credential helpers git asked, in the order it asked them, with the scope (system, global, local) and file that configure each, which one answered and the account login it gave; never the secret. gbrain asks git once more to learn this (`git credential fill`), only after a refusal. Tell the user: they make git use a credential for an account that can push to this repository (often a machine-wide helper answering before the checkout's own); then run `gbrain git commit-push --push-only`. gbrain never changes which credential git uses. Until a push lands, doctor's `git_convergence` warns about the checkout at once (`credential_refused` in its root details) and put_page's `lastPushStatus` reads `needs_attention`. The same refusal over SSH is classified too; there git asks no credential helper, so the message says the key ssh offers decides the account. A managed worktree's own Git-effect pushes keep their current retry. |
| `push_unconfirmed` | 4 | The commit is durable locally but no push destination confirmed it (network, credentials, branch protection, a remote that kept moving, or another push that held the push lock for the whole wait). Fix what the message names, then run `gbrain git commit-push --push-only`. Never force-push. |
| `writer_coordinator_required` | 1 | This is a managed worktree. Stop using git for pages; save them through `put_page` and the other gbrain write tools. `scripts/brain-commit-push.sh` refuses this way on a checkout marked managed and commits nothing; `gbrain git commit-push` refuses this way when git left a named page out of its commit (the same causes as `commit_paths_skipped`), after committing the other named paths locally. Ask the user before re-saving such a page through `put_page` with the managed source (`gbrain put --source-id <source> <slug>`, or `source_id` over MCP; without it the write goes to the default source): it replaces the stored page with the file's content. |
| `git_unavailable` | 1 | A git command failed, often a missing `user.name`/`user.email` or a refusing pre-commit hook. Read the message, fix that, rerun. When the branch names a remote that does not exist (a typo or a broken clone), the run stops before committing: fix the name or add the remote, then rerun. A checkout with no remote at all commits locally instead (`committed_local`). |
diff --git a/docs/guides/sync-unblock-runbook.md b/docs/guides/sync-unblock-runbook.md
index 8df602494b..0d81bb25f4 100644
--- a/docs/guides/sync-unblock-runbook.md
+++ b/docs/guides/sync-unblock-runbook.md
@@ -279,6 +279,10 @@ it and kept going; the receipt lists the hold (`held`, `held_count`) and
`gbrain repair content --source <id>` previews it. A hold the lane will not
decide is `needs_human` with the paragraph in `human_reason`
([held files](repair.md#held-files)).
+- `file_drift` on a read-only mirror: the held pages settle together with
+ one approval. Preview the whole class and approve its hash
+ ([whole class](repair.md#whole-class)); a page the preview lists as
+ `kept_newer_page` or `kept_protected_parts` stays held for a person.
- `file_drift_mirror_database_only`: on a read-only mirror
(`gbrain sources mirror-readonly <id>`) a file gone upstream whose page was
edited in gbrain stays held and its page stays live and database-only, since
diff --git a/llms-full.txt b/llms-full.txt
index d27c5ed84b..24be72a6e8 100644
--- a/llms-full.txt
+++ b/llms-full.txt
@@ -4542,7 +4542,7 @@ Data flowing into the brain. Each integration is a recipe — markdown + setup h
- **Voice**: talk to your brain from a browser or phone with [`recipes/agent-voice.md`](recipes/agent-voice.md) (`gbrain integrations install agent-voice`); the older Twilio recipe is deprecated. Voice notes and chat transcripts you already have come in as files: put their Markdown in a folder and import it, or bring ChatGPT and Claude exports in with `gbrain transcripts ingest` ([chat connectors](docs/guides/chat-connectors.md)).
- **A second folder** (for example a company notes folder beside your personal one): `gbrain sources add company --path ~/company-notes`, then `gbrain sync --source company`. A plain folder works without Git. On a brain only you use, the new folder joins default search; on a shared brain, `gbrain sources federate company` adds it. More: [multi-source brains](docs/guides/multi-source-brains.md).
- **Gmail + Calendar + Contacts (native)**: the google source kind syncs threads, events, and contacts through your own OAuth client and runs the open-loop engine on top (`gbrain waiting`). Setup: [`docs/guides/google-connect.md`](docs/guides/google-connect.md); recipes: [`recipes/email-to-brain.md`](recipes/email-to-brain.md), [`recipes/calendar-to-brain.md`](recipes/calendar-to-brain.md).
-- **Meeting notes + Slack channels (native)**: the `meetings` source kind (Fireflies first) writes one page per meeting and the `slack` source kind one page per channel per day, synced on a schedule, on brains with or without a Git repository. Setup: [`docs/guides/meeting-and-slack-sources.md`](docs/guides/meeting-and-slack-sources.md).
+- **Meeting notes + Slack channels (native)**: the `meetings` source kind (Fireflies first) writes one page per meeting and the `slack` source kind one page per channel per day, synced on a schedule, on brains with or without a Git repository. Setup: [`docs/guides/meeting-and-slack-sources.md`](docs/guides/meeting-and-slack-sources.md). The `imessage` source kind imports Messages from a Mac, one private, owner-only page per chat per day: [`docs/guides/apple-setup.md`](docs/guides/apple-setup.md).
- **Email + calendar (webhooks)**: webhook handlers that route to brain signals. [`docs/integrations/meeting-webhooks.md`](docs/integrations/meeting-webhooks.md).
- **Embedding providers**: Voyage (new-install default: `voyage-4` @ 1024d), OpenAI, OpenRouter, Google Gemini, Azure OpenAI, MiniMax, Alibaba DashScope, Zhipu, Ollama (local), llama.cpp llama-server (local), LM Studio, Together, and LiteLLM proxy. Pricing matrix + decision tree in [`docs/integrations/embedding-providers.md`](docs/integrations/embedding-providers.md). Existing vectors are never converted by changing the default; use the explicitly approved [embedding migration](docs/guides/embedding-migration.md).
- **Rerankers**: Voyage `rerank-3-lite` hosted (the default unless `search.reranker.model` is set; on in `balanced` and `tokenmax`, same `VOYAGE_API_KEY` as embeddings; `gbrain config set search.reranker.model voyage:rerank-2.5` restores the previous default), plus the `llama-server-reranker` recipe for fully-local cross-encoder rerank via llama.cpp running Qwen3-Reranker against the same `gateway.rerank()` seam. Setup walkthrough in [`docs/ai-providers/llama-server-reranker.md`](docs/ai-providers/llama-server-reranker.md).
diff --git a/scripts/core-world-reads-baseline.tsv b/scripts/core-world-reads-baseline.tsv
index e8c730f496..31da117774 100644
--- a/scripts/core-world-reads-baseline.tsv
+++ b/scripts/core-world-reads-baseline.tsv
@@ -449,6 +449,9 @@ src/core/git/commit-ledger.ts spawn_import 1 W7: process-wide effects move to sr
src/core/git/commit-push.ts fs_import 1 W7: filesystem boundary moves to the local app
src/core/git/commit-push.ts module_collection 1 W6: per-engine state, or mark as a constant table
src/core/git/commit-push.ts process_env 6 W6: settings plane out of the core
+src/core/git/push-credential.ts fs_import 1 W7: filesystem boundary moves to the local app; GST-2961 reads and writes the 0600 push-refusal record under the checkout git dir, like commit-push.ts conflict state
+src/core/git/push-credential.ts process_env 2 W6: settings plane out of the core; GST-2961 reads GIT_ASKPASS only to say an askpass program may have answered, shown by its shape-checked program name, never its value
+src/core/git/push-credential.ts spawn_import 1 W7: process-wide effects move to src/cli; GST-2961 runs git credential fill under GIT_TRACE once after a refused push to name the helper that answered (stdout password dropped in place)
src/core/git/git-run.ts spawn_import 1 W7: process-wide effects move to src/cli; GST-2767 moved commit-push's git runner here unchanged
src/core/git/range-secret-scan.ts fs_import 1 W7: filesystem boundary moves to the local app (the publish scan streams git output through a private temp file)
src/core/git/range-secret-scan.ts spawn_import 1 W7: process-wide effects move to src/cli (the publish scan runs git plumbing)
@@ -879,6 +882,7 @@ src/core/remote-token-cache.ts fs_import 1 W7: filesystem boundary moves to the
src/core/repair/agent-session-facts.ts fs_import 1 W7: filesystem boundary moves to the local app
src/core/repair/captured-facts.ts fs_import 1 W7: filesystem boundary moves to the local app
src/core/repair/fences.ts process_env 2 W6: settings plane out of the core
+src/core/repair/file-drift-class.ts fs_import 1 W7: filesystem boundary moves to the local app (class manifest under the config dir)
src/core/repair/file-drift-compare.ts spawn_import 1 W7: process-wide effects move to src/cli
src/core/repair/file-drift.ts fs_import 1 W7: filesystem boundary moves to the local app
src/core/repair/frontmatter.ts fs_import 1 W7: filesystem boundary moves to the local app
diff --git a/scripts/engine-raw-sql-baseline.tsv b/scripts/engine-raw-sql-baseline.tsv
index 02482f3a4c..7354e7dd9f 100644
--- a/scripts/engine-raw-sql-baseline.tsv
+++ b/scripts/engine-raw-sql-baseline.tsv
@@ -281,6 +281,7 @@ src/core/access/members.ts execute_raw 25
src/core/access/members.ts sql_template 1
src/core/access/open-pages.ts execute_raw 8 came from master #9625 (shared company brains: owner setup, member keys), which landed after this ratchet was cut
src/core/access/open-twins.ts execute_raw 1
+src/core/access/owner-only.ts execute_raw 2 #9634, pre-ratchet: reads sources.config to tell whether the brain or one source is owner-only; no typed engine method exists yet
src/core/access/owner.ts execute_raw 1
src/core/access/policy-migrate.ts execute_raw 4
src/core/access/policy-transfer.ts execute_raw 1
@@ -498,6 +499,7 @@ src/core/facts/relink.ts execute_raw 5
src/core/facts/retire.ts execute_raw 1
src/core/facts/similar-active.ts execute_raw 2
src/core/facts/single-prepare.ts execute_raw 7
+src/core/facts/slot-tagging.ts execute_raw 1 GBRA-574 #9668: the live person-page read that picks slot-tagging candidates, written before this ratchet landed; moves behind a typed facts engine method with its area
src/core/facts/subject-infer.ts execute_raw 1
src/core/facts/unfenced-facts.ts execute_raw 8
src/core/facts/withdrawal-discovery.ts execute_raw 9
@@ -564,6 +566,7 @@ src/core/harness/client-setup.ts sql_template 1
src/core/heal-audit.ts execute_raw 3
src/core/health-memo.ts execute_raw 1
src/core/held-embedding.ts execute_raw 2
+src/core/imessage/imessage-source.ts execute_raw 3 #9634, pre-ratchet: reads the source row (incarnation, local_path, config), checks a page slug exists, and stamps sources.last_sync_at/newest_content_at; no typed engine method exists yet
src/core/import-chunk-reuse.ts execute_raw 2
src/core/import-file.ts execute_raw 7
src/core/import-identity.ts execute_raw 1
@@ -989,6 +992,7 @@ src/core/repair/fact-claim-dates.ts execute_raw 3
src/core/repair/facts-rehome.ts execute_raw 4
src/core/repair/failed-writes.ts execute_raw 19
src/core/repair/fences.ts execute_raw 4
+src/core/repair/file-drift-class.ts execute_raw 12 came from #9614 and #9615 (whole-class held file-drift preview and apply), opened before this ratchet: the preview reads the held file_drift checkpoints and the source incarnation, and the apply adds its lease, progress and manifest reads and writes; these move behind typed engine methods with the next change in the repair area
src/core/repair/file-drift.ts execute_raw 6
src/core/repair/frontmatter.ts execute_raw 8
src/core/repair/ghost-pages.ts execute_raw 1
@@ -1131,7 +1135,7 @@ src/core/source-health.ts execute_raw 6
src/core/source-resolver.ts execute_raw 15
src/core/sources-load.ts execute_raw 4
src/core/sources-not-readable.ts execute_raw 1
-src/core/sources-ops.ts execute_raw 15
+src/core/sources-ops.ts execute_raw 16 #9634, pre-ratchet: +1 is the INSERT that registers a database-only api source row (imessage); no typed engine method exists yet
src/core/spend-log.ts sql_template 2
src/core/sql-query.ts execute_raw 2
src/core/storage-manifest/adopt.ts execute_raw 4
diff --git a/scripts/module-size-limits.tsv b/scripts/module-size-limits.tsv
index 5ced9a0870..f8edc9e2ef 100644
--- a/scripts/module-size-limits.tsv
+++ b/scripts/module-size-limits.tsv
@@ -7,14 +7,14 @@ src/cli/main.ts 2882 ratchet +32 GST-2476 G2: enforced member gate call, static-
src/commands/autopilot.ts 1662 ratchet refactor wave 1 split target (W4 autopilot, cut line); ceiling rationale: docs/architecture/key-files/commands-1.md entry for src/commands/autopilot.ts; +2 fix wave 5: nosemgrep justifications on the per-brain job launchctl/systemctl calls (#5195); +2 #5813: boot reconcile names attempted and running versions in log + audit; +2 #5855: Bun floor gate before the swap and the swap-refusal hold (logic in core/bun-floor.ts); +3 agent operator wave E9: --dry-run and the persistent_install consent gate before anything is written (logic in autopilot/install-consent.ts); +8 GBRA-130 C-6/A-10: the --retry-global mode row, help line and --phase value flag, and --status reading the brain-wide maintenance verdict into its JSON, text and exit code (logic in core/minions/global-maintenance-stall.ts and autopilot-retry-global.ts); +12 GBRA-133 #7003: --status grades from the daemon's heartbeat sidecar (two report fields and their doc line, the classifier's daemon input and threshold branch, the import and the showStatus read; logic in core/autopilot-heartbeat.ts)
src/commands/doctor.ts 706 ratchet +2 Wave B decision #10: Check.skipped_segmented field (logic in doctor/check-fix.ts withSkippedSegmented); +19 #6696 doctor tiers: Check.elapsed_ms and DoctorReport tier/complete/unknown_sections/elapsed_ms/budget_ms fields, buildChecks/runDoctor deadline params (logic in doctor/budget.ts); +1 agent operator gate fixes: --probe consent gate (logic in doctor/probe-consent.ts); refactor wave 1 split target (W4 doctor); ceiling rationale: docs/architecture/key-files/commands-2.md entry for src/commands/doctor.ts; +4 #7142: DoctorReport.last_known_sections field and the buildChecks last-known/refresh scope params (logic in doctor/last-known.ts); +8 #7276: DoctorReport.unknown_count field and the unknown category/count lines of the text headline (scoring logic in doctor/budget.ts scoredChecks); +6 GBRA-224 W4: DoctorReport.alert field, the alert computation call and the --alert branch of runDoctor (logic in doctor/alert.ts)
src/commands/embed.ts 2307 ratchet +2 agent operator wave D2: --json failure envelope via writeCliError; lowered v0.46.26.0: embedBatchWithBackoff + retry cluster peeled to core/embed-retry.ts (core/commands layering fix); grown wave-g (#4530): per-model input-limit wiring; wave-k #3622 reimpl: --stale zero-progress failure quarantine; +29 #4668 (#4530): oversize-heal call sites in both --stale drains — kept low by peeling the healed-row remap to core/embed-oversize-heal.ts (shared with embed-stale.ts); +35 #4647 (refs #4599): per-tick timeout+abort on the single-flight lock heartbeat refresh (interval deliberately NOT unref'd); +122 refs #4599: stall-watchdog race around the drain + shared idempotent flushAndRelease + CLI stall exit mapping (watchdog machinery itself lives in core/embed-stall.ts); +12: adversarial-review hardening (healed_splits progress key + heal-tick comment); #5105: guarded derived projection preparation and read seals; #5105: conditional embedding installer wiring; archived eligibility: active-only dispatch with honest stranded-work reporting; explicit archived admission: live-source snapshots and honest refused-installation failures; +2 fw3: embed --stale --images dispatch (sweep lives in core/embed-stale-images.ts); +5 #5289: dry run reports restamp-only chunks apart from chunks to embed (count lives in core/embedding-invalidation.ts); +6 #4616: keep a partially refused batch in embedPageTexts and name the recovery command in failure samples (guard lives in core/ai/embedding-guard.ts); +5 #5226: embed summary counts distinct pages; +3 #5804: null projection snapshot counted as a failure with one batch summary in embed --stale; +18 wave 8 lane D1: #5527 mixed-space warning subtracts current-model chunks (+4), #5885 takes option/result fields and the stale-drain takes call (pass lives in core/embed-takes.ts); +9 Foundations 1 F4d: time-budget stop result fields, stdout verdict and stop recording in embed --stale (logic in core/embed-budget-stop.ts); +8 green-master lane A: chunkless install re-reads through retryProjectionConflict instead of recording an unavailable page (retry lives in core/page-state/projections.ts, failure line in core/agent-output.ts); +8 fix wave 13 P1.18: runEmbed consent parameter, cost-cap stop wiring and result fields, --slugs parsing to the next flag (cap, verdict and resume logic live in core/embed-cost-cap.ts); +28 large pages A9/T3/T16: --held listing and per-page cap metering on every embed path (logic in core/page-embedding-budget.ts meterPageBatch/spendGrant/heldEmbedArgv), approvedPageCapUsd from --max-usd on --slugs; +1 #6722: an explicit slug embed skips an embed_skip page (it keeps keyword chunks, never vectors); merge v0.60.240.0: large pages and master growth compose at 2265; +39 large pages Wave B lane 1e: segmented pages route to the keyset sweep on the slug, --all and --stale paths, with a dry-run count and provenance stamp (logic in core/page-body/segmented-embedding.ts); +2 agent operator wave D2: --json failure envelope via writeCliError; +1 Rust engine shell (plan PR 8): sqlEngineKind import so the dimension-mismatch recipe refuses a Rust kind (logic in core/sql-engine-kind.ts)
-src/commands/extract-conversation-facts.ts 1957 ratchet grown v0.46.x per-provider gateway-unavailable copy; grown wave-g (#4482): expected budget/deadline caps classified apart from error halts; wave-k: save-time resolution caller (#4052/#3729 — supersedes wave-g's per-row resolveEntitySlug mapper); +1: key-aware llm-fallback default (#3813); +1: pricingOverrides wiring into the owned BudgetTracker (#4633 adoption); +3: #4869 snapshot-mismatch counts as pages_failed; merged reliability/shared-skills source integration; +19: additive skip reasons and model-free dry-run (#5364); +21 #5757: managed extraction buffers a page's rows and replaces the prior batch in one coordinator transaction (replacement helper lives in core/persistence/derived-facts.ts); +18 #5823: result diagnostics, strict explicit-cap parsing and CLI recovery/help; default-cap decision lives in facts/conversation-budget.ts; +18 fix wave 7 (#5704, #5448): --json envelope on stdout (parser flag, help line, summary block gated behind the human-output branch); +2 fix wave 10 (#6037, issue #6033): explicit-slug page failures are contained per page through one bounded failure logger (recordPageFailure) shared with the pooled path; +4 fix wave 10 (#5120): facts.default_visibility resolved once per run (resolveDefaultVisibility) and applied to extracted rows only; 2 P2 segmentObservationDate + segmentValidFrom helpers (date-grounding observation time per segment; extractor event date wins over segment start); +4: ExtractConversationFactsResult.failed_pages (interface field) and the help text exit-status paragraph; partial-success logic lives in core/facts/conversation-run-status.ts; re-summed at the master 6ccf30c3e merge (2179 master lines + 20 integration lines over base); re-summed at the #6020 merge on actual lines (as rehearsed on capy/mpw-integration-p2); re-summed at the wave 10 merge on actual lines (+1 recordPageFailure fills failed_pages); lowered at the wave-9 follow-ups merge: the three zero-result literals became emptyExtractConversationFactsResult(); lowered to 2075 at wave 15 P2.5 (#6267): segment tunables, splitIntoSegments and renderSegmentForExtraction moved to core/facts/conversation-windows.ts, the message/segment types to core/facts/conversation-types.ts (re-exported here); +12 large pages T2: the oversized-sidecar snapshot and the durable size-skip receipt (skippedForSize; the cap and the bounded sidecar read live in core/conversation-parser/body.ts, the receipt in core/extraction-watermark.ts); merge v0.60.240.0: large pages and master growth compose at 2087; -6 wave 18 lane 3 (#6731 #6764): the two extractor call sites share one input object, inference lives in core/facts/conversation-subject-infer.ts; Wave B PR 2 (kept at the master 4e29d0904 merge): +7 large pages PR 2 lane 2e2: a segmented conversation over the window cap (snapshot.window, the tail_window receipt, the window fallback date; the window read lives in core/page-body/segment-conversation.ts); +9 lane 2e2 follow-up: the lossless window rule (a page over the window with conversation facts keeps them and is skipped, the receipt names the rule; the count lives in core/facts/conversation-publication.ts); integrated at the master 4e29d0904 merge: 2097 measured; lowered to 2044 by #7013: a page's rows publish once through publishConversationFacts (core/facts/conversation-publication.ts), so the delete-first cleanup, the per-segment inserts and the row-number peek left; +1 GBRA-159: facts from a private page are private (tightenToPage per page; helper in core/facts/visibility.ts); +3 #7438: ExtractConversationFactsResult.facts_skipped_purged (interface field) and one notePurgedSkips call (the count and log live in core/facts/conversation-publication.ts); grown v0.46.x per-provider gateway-unavailable copy; re-summed at the Wave B PR 4 merge with v0.60.452.0 (1949 measured); +6 #7068: ExtractConversationFactsCoreOpts.onInterrupted (interface field and its doc) and its one call before the rethrow (the cycle keeps the committed counters in core/cycle/conversation-facts-backfill.ts); +2 GBRA-574 B2: the --dry-run paid-run estimate (one call and one print; the estimate and its line live in core/facts/conversation-budget.ts)
+src/commands/extract-conversation-facts.ts 1960 ratchet grown v0.46.x per-provider gateway-unavailable copy; grown wave-g (#4482): expected budget/deadline caps classified apart from error halts; wave-k: save-time resolution caller (#4052/#3729 — supersedes wave-g's per-row resolveEntitySlug mapper); +1: key-aware llm-fallback default (#3813); +1: pricingOverrides wiring into the owned BudgetTracker (#4633 adoption); +3: #4869 snapshot-mismatch counts as pages_failed; merged reliability/shared-skills source integration; +19: additive skip reasons and model-free dry-run (#5364); +21 #5757: managed extraction buffers a page's rows and replaces the prior batch in one coordinator transaction (replacement helper lives in core/persistence/derived-facts.ts); +18 #5823: result diagnostics, strict explicit-cap parsing and CLI recovery/help; default-cap decision lives in facts/conversation-budget.ts; +18 fix wave 7 (#5704, #5448): --json envelope on stdout (parser flag, help line, summary block gated behind the human-output branch); +2 fix wave 10 (#6037, issue #6033): explicit-slug page failures are contained per page through one bounded failure logger (recordPageFailure) shared with the pooled path; +4 fix wave 10 (#5120): facts.default_visibility resolved once per run (resolveDefaultVisibility) and applied to extracted rows only; 2 P2 segmentObservationDate + segmentValidFrom helpers (date-grounding observation time per segment; extractor event date wins over segment start); +4: ExtractConversationFactsResult.failed_pages (interface field) and the help text exit-status paragraph; partial-success logic lives in core/facts/conversation-run-status.ts; re-summed at the master 6ccf30c3e merge (2179 master lines + 20 integration lines over base); re-summed at the #6020 merge on actual lines (as rehearsed on capy/mpw-integration-p2); re-summed at the wave 10 merge on actual lines (+1 recordPageFailure fills failed_pages); lowered at the wave-9 follow-ups merge: the three zero-result literals became emptyExtractConversationFactsResult(); lowered to 2075 at wave 15 P2.5 (#6267): segment tunables, splitIntoSegments and renderSegmentForExtraction moved to core/facts/conversation-windows.ts, the message/segment types to core/facts/conversation-types.ts (re-exported here); +12 large pages T2: the oversized-sidecar snapshot and the durable size-skip receipt (skippedForSize; the cap and the bounded sidecar read live in core/conversation-parser/body.ts, the receipt in core/extraction-watermark.ts); merge v0.60.240.0: large pages and master growth compose at 2087; -6 wave 18 lane 3 (#6731 #6764): the two extractor call sites share one input object, inference lives in core/facts/conversation-subject-infer.ts; Wave B PR 2 (kept at the master 4e29d0904 merge): +7 large pages PR 2 lane 2e2: a segmented conversation over the window cap (snapshot.window, the tail_window receipt, the window fallback date; the window read lives in core/page-body/segment-conversation.ts); +9 lane 2e2 follow-up: the lossless window rule (a page over the window with conversation facts keeps them and is skipped, the receipt names the rule; the count lives in core/facts/conversation-publication.ts); integrated at the master 4e29d0904 merge: 2097 measured; lowered to 2044 by #7013: a page's rows publish once through publishConversationFacts (core/facts/conversation-publication.ts), so the delete-first cleanup, the per-segment inserts and the row-number peek left; +1 GBRA-159: facts from a private page are private (tightenToPage per page; helper in core/facts/visibility.ts); +3 #7438: ExtractConversationFactsResult.facts_skipped_purged (interface field) and one notePurgedSkips call (the count and log live in core/facts/conversation-publication.ts); grown v0.46.x per-provider gateway-unavailable copy; re-summed at the Wave B PR 4 merge with v0.60.452.0 (1949 measured); +6 #7068: ExtractConversationFactsCoreOpts.onInterrupted (interface field and its doc) and its one call before the rethrow (the cycle keeps the committed counters in core/cycle/conversation-facts-backfill.ts); +2 GBRA-574 B2: the --dry-run paid-run estimate (one call and one print; the estimate and its line live in core/facts/conversation-budget.ts); +3 GBRA-574 slot tagging: ExtractConversationFactsResult.slot_tagging_failed, its per-source sum and its summary line (tagging and the count live in core/facts/slot-tagging.ts and conversation-window-extract.ts)
src/commands/extract.ts 2702 ratchet +8 GBRA-130 A-1: extract --stale --retry-held flag, help lines and the managed result failure fields (logic in core/persistence/links-maintenance.ts and links-extraction-holds.ts); grown v0.46.26.0 megawave: FS-walk stamp snapshot + legacy timeline repair wiring (#3957 D4) + PR#4486 rebase onto current master; grown wave-g (#4542): --from-meetings zero-match warning + default-pass note; +29: #3478 federated-only gate on the cross-source 'default' link fallback; +44: #3908 cross_source opt-in — counted drops + deterministic cross-source pick; +36: #4611 configured-sources.default fallback (resolveLinkFallbackDefault); +14: #4890 extractStaleFromDB quiet opt + extractForSlugs jsonMode batch_error stderr fallback; +5: #4855 stroke-letter fold in link extraction; +5: #4793 by-mention scan honours link_resolution.cross_source; +18: wave review — ExtractOpts.quiet threaded through the fs-walk extractors (stdout silence decoupled from jsonMode); +77: shared buildSlugPathIndex — every per-slug extractor resolves the real on-disk path, and the sync hooks report which slugs they actually read; +10 #4999: includeFrontmatter default-resolved inside extractLinksForSlugs + extractStaleFromDB (resolveIncludeFrontmatter), --stale flag absent -> configured knob; +20: pre-landing review of #4967 — resolveSlugRelPath: index miss falls back to the legacy slug+'.md' path so admitted _-prefixed / include_hidden pages keep their edges; T2: source-qualified inference and atomic origin-scoped derived links; standard DB extraction fences captured endpoint revisions; shared authoritative attendance/source reconciliation moved to the core module; +7 A2 preview-bound attendance repair import, help and authority dispatch; bounded incomplete-attendance diagnostics and consistent basename resolution; fail closed before graph mutation when active ontology is unavailable; +16 source-selected ontology cache, type-scoped preflight and non-starving failed stale drain; +7 write-path wave: per-slug extractors replace page links + retract removed timeline rows + rename-alias resolution; +5 fw3 derived-sync: timeline --prune-orphans CLI (#4649) and full-walk page link replacement; +13 fw3 A16/A15: sync link hook reads scoped page metadata and reports per-page extraction errors; +1 fw3 managed-lifecycle: extract --stale dispatches managed brains to the coordinator-safe path; +4 fw3 integration: managed brains refuse the direct timeline orphan prune; +26 #5609: managed extract --stale publishes links, canonical timeline and watermark per page in one coordinated transaction; fix wave 3 x fix wave 2 (v0.60.5.0) composition: +4 at the merge; +6 fix wave 3 lane B: a managed brain routes the extract phase file walk through extractManagedStaleLinks instead of the refused raw timeline batch, keeping the extract.links_fs progress phase; +6 #5761: the unmanaged extract --stale sweep marks unresolved-attendance skips attendance-blocked; +2 eval-wave N9-3/N12-7: a page-type-bound pack attended rule defers to canonical attendance on the filesystem path (ownsAttendanceInference); lowered to 2528 #5904: the DB timeline walk moved to commands/extract-timeline-db.ts (coordinated publication on managed brains, honest refusal + non-zero exit); +13 entity mention index: extract --stale runs the mention pass after link work (half the budget reserved while mention-due pages exist), dry-run and JSON report mention counts, and the help documents the pass and `extract mentions --explain` (logic in core/mentions/); cat40 entity wave merge with v0.60.61.0 (2541 measured); +6 fix wave 10 lane L1 #5556: quarantined pages skipped by the file walks, slug lists and DB walks (slug lookup in quarantine.ts quarantinedSlugs); +3 #5556: the abort check stays its own statement in each quarantine-aware scan loop (cycle-abort coverage pin); 2 P5 wanted pages: both DB extract paths record unresolved authored refs with each page's links; +5 P5 line grammar: stated relation types on the filesystem link scan; +3 PGLite stale link drains refresh planner statistics before and during the drain (logic in planner-stats.ts plannerStatsForLinkDrain); +10 fix wave 12 W2.1 S4 (#6228): extract --stale flushes and stamps the pages a batch finished before an aborting page; +12 P5 wanted pages: both DB extract paths record unresolved authored refs with each page's links; +9 Q2 parser gaps: both DB extract paths read the line-grammar settings once, publish through replaceDerivedLinksUnlessSettingsChanged and report pages a mid-run settings change left stale; +25 GBRA-69: extract --source db reads snapshots and publishes derived links BATCH_SIZE pages at a time (readPageSnapshotsBatch in core/page-snapshot-batch.ts, replay in derived-links.ts replaceDerivedLinksBatchOrReplay); +2 GBRA-75 w7: the --source db links walk refreshes planner statistics (logic in planner-stats.ts plannerStatsForLinkDrain); +10 fix wave 13 P2.16 (#6272): both unmanaged DB link drains defer and count a page a concurrent writer moved (skipped_concurrent_write) instead of aborting the run (classifier and skip line in core/derived-links.ts); +3 fix wave 13 P2.18 (S4): extract all --source db stamps the pages both phases completed at one revision, in a finally (stampCompletedIntersection), instead of every links-phase page; +1 fix wave 13 P2.15 (#6273): --from-meetings exits non-zero while managed entity pages are still pending; +7 fix wave 13 PR2: extractFromDB split out of runExtract so runExtract stays under its function-size baseline; Wave B PR 2 (kept at the master 4e29d0904 merge): +3 PR 2 fix lane J1: extract --stale reads a segmented page block by block (extractSegmentedPageLinks, segmentedTimelineText) now that the stale list includes it; integrated at the master 4e29d0904 merge: 2635 measured; +23 fix wave 20 #6954: the fs walks and the slug-scoped extract collect lost link/timeline writes, stamp only the pages whose writes landed and throw extract_write_lost (helpers in core/extract-watermark.ts); fix wave 20 integration: lane 1 (#6808, +11) and lane 2 (#6954, +23) compose at 2677 measured; +16 #7394: --type/--since/--infer-dates on the file walk refuse with the --source db command beside the other --source db refusals, and the help says so; +5 GBRA-161 PR 5 (T-2, L-6): timeline retraction and the mention rebuild sweep are bound to the revision they read (PageRevisionConflictError import, the scanned-revision read and its FOR SHARE check); +2 GBRA-133: ExtractOpts.timeBudgetMs, forwarded to the managed stale-page pass so the cycle bounds a pass with no slug list; +1 #9295: the stale sweep counts only the wanted-link producers it re-resolves (wantedProducers; SQL in engine-sql/pages.ts); +1 GBRA-438 PR 2: the mention pass gets no deadline budget once the cycle signal has aborted, so idle upkeep stops at the next request
src/commands/jobs.ts 693 ratchet refactor wave 1 split target (W4 jobs, cut line); ceiling rationale: docs/architecture/key-files/commands-4.md entry for src/commands/jobs.ts; help lines: authorize-legacy --select (#5157 T3) and jobs cancel --select (DX-T2); submit --queue-only + PGLite work drain note (agent-first operator wave E5); +2 spend authorization: jobs submit --yes/--max-usd and jobs list --group help lines; +4 fix wave 9: supervisor stop help documents the 45 s wait, --queue and the verified-drain exit codes; +1 #7142: doctor-refresh handler registration (logic in doctor/last-known.ts); +20 #7242 jobs wait: subcommand row, import, usage lines and its --help text with the exit codes (logic in jobs/wait.ts); +6 GBRA-283 B3a: runJobs enters the local scope (withLocalScope; scope store in core/engine-scope-store.ts), the entry wrapper and its import cannot move
src/commands/serve-http.ts 947 ratchet refactor wave 1 W4 split into serve-http-<area>.ts modules; ceiling rationale: docs/architecture/key-files/commands-5.md entry for src/commands/serve-http.ts; +2 agent operator wave A6: ServeHttpContext.noticeLedger (import + field; logic in core/notice-ledger.ts); +2 agent contract F1/F2: ServeHttpContext.readinessCache (probed readiness for initialize tails + gbrain://capabilities); +5 Lane D facts drain: serve --http starts the drain scheduler and stops it before the engine disconnect (logic in core/facts/drain-scheduler.ts); +2 agent-operator follow-up Item 3: ServeHttpOptions.adoptServer (status-only recovery hands its bound listener to listenOrRefuse; logic in serve-http-status.ts); +5 #6317: managed-sync movement watch start/stop (watch in persistence/sync-movement.ts); +1 #6589: imports loadServeConfigs (operations see the DB-plane config read once at startup; logic in mcp/serve-config.ts); +5 #6858 ask 6: on-commit HEAD watcher start/stop (watcher in core/serve-head-watcher.ts); +4 GBRA-199: serve --http --advertise parse, help line and pass-through (logic in mcp/surface.ts parseAdvertiseFlag); +6 GBRA-283 B3a: runServeHttp enters the local scope (withLocalScope; scope store in core/engine-scope-store.ts), the entry wrapper and its import cannot move
src/core/ai/gateway.ts 4576 ratchet +2 GST-2435: native-openai tool definitions carry strict: false (toAISDKTools strict parameter + the chat() call-site reason line; the Responses API makes a tool with no strict field strict); +5 GBRA-274 B1.3: withoutBudgetTracker export (runs a rollout hook outside the run's budget scope; the budget AsyncLocalStorage is gateway-private, so it cannot move); +2 #6997: ChatResult.fallbackReason (interface field + doc; recorded in ai/chat-fallback.ts); +17 #6607: lazy OpenAI model discovery (discoverBeforeOpenAICall, once per reconfigure, at the chat/expand/embed entry points; it re-resolves through the gateway-internal resolveGatewayModels, so it cannot move); +18 W11 item 3: embedQuery query-embedding cache lookup/store + clear at every model-cache clear site and the test transport seam (cache lives in ai/query-embed-cache.ts); +7 fix wave 5 (#5137): provider-key redactor on every upstream error path and the first embedding 401/403 report (logic in ai/key-redact.ts, ai/key-warnings.ts); +20 System One v1: decide() delegating export + transport seam, RerankInput.onMeta/RerankMeta, TypeSafe reranker delegation to ai/decide/rerank-adapter.ts; +3 #5585: reconfigureGatewayWithEngine records expansion/chat model provenance (ai/gateway-model-sources.ts) + clears it with gateway state; lowered #5585: tracker record sites collapsed onto ai/budget-record.ts (recordOnTracker + failedCallUsage) while adding ledger fields (requested model, purpose, failed, estimated, countsAsCall); +20: schema-rejection fallback in chat() (retry once schemaless on a json_schema 4xx, remember the recipe for the process — mirrors expand()); re-summed after merging master v0.50.0.0 with the wave (structured-output + pricing hunks); +48: #4863 ChatOpts.responseSchema → tolerant json_schema Output on the chat() generateText call for openai-compatible recipes that declare structured outputs (facts extraction on Ollama); +74: #3657 post-sunset rerank short-circuit (effective-model check, once-per-process audit row + stderr, injected-clock seam); grown v0.46.26.0 megawave: config-plane probes + halt telemetry (#3387 #4312); +21 lines (OpenAI Responses API reasoning-item echo: ChatBlock 'reasoning' variant, chat()/toModelMessages() round-trip); wave-k absorbs: OCR routing seam (#4107 class), config-snapshot reader block (#3980); +21: #4107 OCR-model routing (getImageOcrModel); +10: keyless OPENAI_BASE_URL embedding override (#4385); wave-k #3622 reimpl: GBRAIN_EMBED_MAX_BATCH_TOKENS env cap for no_batch_cap recipes; +9: DeepSeek judge thinking pin plumbed through chat opts (#4069); +master v0.48 merge true-up (reranker succession: no_key preflight, reranker_skipped stage, readiness); ranker wave v0.48.4.0: ChatOpts.temperature threaded to the transport (+15); +24: #4172 recipe-declared thinking headroom on the chat()/toolLoop() default — shared isThinkingModel predicate (Claude-5 regex || recipe thinking_by_default, fail-closed), also consumed by the subagent handler; +20: #4861 claude-cli expansion routed to the schemaless viaText path (the CLI adapter ignores responseFormat, so the native generateObject branch had no fallback); retired provider integration removed; safety wave: migration reranker input ceilings; lowered by fix wave 3 #5680 (embed request planning peeled to ai/embed-batch-plan.ts); +5 #4616: empty inputs skip the provider and every text/multimodal result is screened for zero-norm/NaN/Inf vectors (logic lives in ai/embedding-guard.ts); fix wave 3 integration: #4616 empty-input filtering feeds the shared #5680 batch planner; +3 #5691: embedQuery takes a per-request queryPrefix (no gateway state); +26 fix wave 7 (#5642): embed spend records bank provider-reported usage.tokens (all sub-batches reported → measured; chars-per-token estimate stays the fallback and the failure charge); +2 #5892: import + load-time call of installAiSdkWarningWriter (writer lives in ai/sdk-warnings.ts); +12 #5490: chat() delegation to ai/chat-fallback.ts when chat_fallback_chain is set (attempt loop lives there), ChatOpts.allowFallback + ToolLoopOpts.allowFallback fields and the toolLoop forward; +2 #5490 review: ChatResult.fallbackFrom (the call model a chat_fallback_chain answer replaced); +1 fix wave lane B3: configureGateway keeps chat_fallback_on_refusal (the refusal switch lives in ai/chat-fallback.ts); +18 fix wave 9 lane B: ChatOpts.thinking (#5331, per-route mapping lives in ai/thinking-off.ts), ChatOpts.timeoutMs + ToolLoopOpts.turnTimeoutMs and the turn forward (#4921); interface fields and their docs cannot move; +2 P8: GBRAIN_AI_CALL_LOG observer install in configureGateway (logic in ai/call-log.ts); +2 W9F item 5: thinkingOffOutputCap export shared by chat() and the judge preflight estimates (capability table lives in ai/thinking-off.ts); +3 A1 (wave 0): ChatResult.usage.reasoning_tokens (interface field + doc) and the chat() reasoning-subset read beside the cache counts; the ai-sdk importer allowlist is shrink-only, so the seam stays here); +9 GOOGLE_GENERATIVE_AI_BASE_URL: resolveNativeBaseUrl('google') + the three native-google construction sites (eval metering proxy); re-summed at the master 6ccf30c3e merge (4417 integration + 4423 master - 4408 base); lowered -5: the expand() prompt template peeled to ai/expansion-prompt.ts (buildExpansionPrompt) so the longmemeval call planner measures the same text; +5 #7176: expand() writes its chat_usage_log row (phase expansion) beside the budget record, and the guardedExpansion instance that names its invocation gateway.expand (ledger in ai/chat-usage.ts); +2 PR 4 (Wave B incremental derivation, transcripts) 4b round 4: chat() forwards a metered page step's providerRetries (BudgetTracker) as the SDK's maxRetries, so every attempt is one it reserved for; +24 GBRA-283 B2 (#8456): per-engine gateway state, the gw() accessor every config and model-cache read goes through (an embedded engine state or the process state), configure split into gatewayConfigOf, and configFor at the provider-resolution sites so a provider the engine lacks refuses before any call (state and refusal live in ai/engine-gateway.ts); +1 GBRA-283 B2: embedding diagnosis refuses a provider the embedded engine was not given; +1 GBRA-283 B2 (#8499 item 1): requireConfig refuses an unscoped call in a process holding embedded engines (engine_scope_missing; predicate in engine-scope.ts); +7 GBRA-283 B3a: every embed/chat/expand/rerank/toolLoop entry and requireConfig/configFor call refuseUnscoped (predicate and refusal in ai/engine-gateway.ts), the unscoped state, and the shrink/no_key/structured-output memory read through gw() (state in ai/engine-gateway.ts GatewayState); re-measured at the Train A merge of #8948: 4574; re-measured at the Train D merge onto master v0.60.711.0: 4574 + 2 (#8324 setThinkingOffBaseUrls import and its two calls)
src/commands/sync.ts 568 ratchet refactor wave 1 split target (W4 sync); ceiling rationale: docs/architecture/key-files/commands-6.md entry for src/commands/sync.ts; +2 for the #5751 SyncResult.legacySkips interface field (fix wave 4); +2 fix wave 4 lane B: SyncResult.connectorHolds interface field (held counts for the sync summary); +1 fix wave 5 (#5032): SyncResult.fileRefusals interface field (named per-file Windows colon refusals); +13 #5984: SyncResult.drain / managedCursor and SyncOpts.drain / drainStartedAt interface fields (drain loop lives in persistence/sync-drain.ts); +1 #5984: SyncOpts.noBulk / bulk interface fields; v0.60.48.0 merge: #5984 growth re-summed over v0.60.47.0 (510 measured); +2 #5984 lanes: SyncOpts.lanes field and the lanes progress-event field; +2 #6278: SyncResult.breaker interface field (the preparation-stall breaker verdict); +1 fix wave 13 P4.3 #6386: the JSON-output comment names writeJsonDocument for sync status/unblock; +2 fix wave 13 PR2: the transaction-pooler stderr line (P2.2) and the staged catch-up result field (P2.14, loop in commands/sync/perform.ts); +2 fix wave 15 P4.5 (#5459 adjacent): SyncResult.working_tree_kept interface field (the tree-walk keep lives in persistence/sync-discovery.ts); +4 #6643: SyncResult.retryWait / knockOns interface fields (recovery lives in persistence/sync-run.ts, sync-knock-on.ts); +2 #6696 (A7): SyncOpts.capacityPreflight interface field (preflight lives in persistence/sync-capacity-preflight.ts); +2 #6696 C1: SyncOpts.embedDeferred interface field (the cost gate's runtime embed deferral; an interface field cannot move), composed with PR A's SyncOpts.capacityPreflight; +2 #6693: SyncResult.replayedRemembers interface field (the post-sync replay lives in commands/sync/perform.ts and repair/failed-writes.ts); +12 #6712 PR 1: SyncResult.leaseHeld / inherited_options / cursorAdopted / cursorFanIn and SyncOpts.drainHolder / followDrainLease interface fields (the lease lives in persistence/sync-lease.ts, adoption in persistence/sync-cursor-key.ts and sync-admitted.ts); +2 #6712 PR 2 (L5): SyncResult.tail interface field (the tail lives in persistence/sync-tail.ts); +2 #6712 PR 2 integration: L4 ghostPages and L5 tail SyncResult interface fields both land (each lane raised 542->544 alone); +2 #6948: SyncResult.origin_twins_resolved interface field (the heal lives in repair/origin-twins-heal.ts); +5 #6712 PR 4b: SyncResult.pass / reconcile and SyncOpts.costApproved interface fields (an interface field cannot move; the pass summary and the pass reason union live in persistence/sync-pass-row.ts, the remote reconcile in sync-pass-apply.ts); lowered to 546 #6712 PR 4b lane C: SyncResult.cursorAdopted / cursorFanIn retired with the cursor engine; +2 #7167: SyncResult.writer interface field (a managed dry run reports the writer instead of waiting on it; the read lives in persistence/sync-dry-run-writer.ts); +6 G8a git-canonical: SyncOpts.canonicalOverride interface field and its doc comment (internal: only the conversion apply in persistence/git-conversion.ts passes it; applied in persistence/sync-discovery.ts); +2 #7866: SyncOpts.fullRound interface field and its doc comment (internal: the conversion strict passes in persistence/git-conversion.ts set it; read in persistence/sync-pass-run.ts); +1 #8007: SyncResult.storage_invalid_kept interface field (the keep lives in persistence/sync-discovery.ts); +2 GBRA-287: SyncResult.reexport_failures interface field (the re-export lives in commands/sync/full.ts); re-summed at the memory train #8481 merge with v0.60.576.0 (564 measured); +2 convergence PR A: SyncOpts.conversionBinding interface field and its doc comment (internal: only the conversion apply in persistence/git-conversion.ts passes it; applied in persistence/sync-pass.ts bindConversion); +2 GST-2462: SyncResult.privacy_label_notice interface field (the notice lives in core/search/ignored-privacy-labels.ts)
src/core/cycle.ts 3357 ratchet +2 GBRA-130 C-2 (#6946): the sync phase reads an owned clone's pull block and reports it as pull_blocked (logic in url-clone.ts urlClonePullBlock/urlClonePullBlockSummary); +6 GBRA-130 A-1: the extract phase warns on failed or breaker-stopped stale drain pages (logic in cycle/connector-extract.ts staleDrainFailures); +1 W1 belief ledger: the extract phase runs the sampled belief drift reconcile (logic in belief/coverage-report.ts); +2 System One v1 S9: extract_facts phase tail runs the conflict sweep (ai/decide/sweep.ts) only when the slot is not off; +2 System One v1: purge phase prunes decision receipts (ai/decide/store.ts); grown v0.46.26.0 megawave (#4102 #2608) + master v0.46.26.0 cycle-start orphan recovery; +10 wave G #3974: cycle-sync uncommitted-drift warn; grown wave-g (#4416): synthesize_concepts source threading; grown wave-g (#4416): synthesize_concepts source threading (same fix absorbed as #4417 on wave-k); wave-k: ); +7: #4077 abort threading; +10: #4745 fullImplicitSourceCycle opt-in contract; +3: #4890 extract phase jsonMode/quiet + pages-not-links totals; +1: wave review — extract phase passes quiet:true + jsonMode:false; +1: extract_facts pagesFailed detail; +8 fix wave 3: one cycle date resolved in runCycle and threaded to synthesize/patterns/drift (C-15); +1 #5632: cycle sync resumes an unfinished managed cursor with its stored options; fix wave 3 x fix wave 2 (v0.60.5.0) composition: +1 at the merge; -41 #5809: anyAbortSignal peeled to abort-signals.ts; +5 #5809: extract_atoms phase gets a real abort signal; +4 #5809: cycle_already_running names the lock holder; +7 #5255: cycle sync runs a managed pull request as no-pull and reports upstream_refresh; +1 #4578: a lock steal during the last selected phase reports lock_stolen, not aborted; +3 #5536: keyless embed phase clean-skips when embedding_disabled is set; +5 F4b: planner-stats refresh after the freshness phases (logic in planner-stats.ts); +2 agent operator wave A1: PhaseResult sibling code/fix; +20 #5876: Life Chronicle phase registration (CyclePhase, ALL_PHASES, NEEDS_LOCK) and its runCycle dispatch block; v0.60.46.0 merge: re-summed to the merged line count (3224); +3 retrieval feedback retention in the purge phase (logic in feedback/store.ts pruneRetrievalFeedback); 12 Lane D: facts_drain phase registration (CyclePhase, ALL_PHASES, NEEDS_LOCK) and its runCycle dispatch line (logic in cycle/facts-drain.ts); P3 x foundations-2 composition: deltas re-summed at the merge; 12 Lane D: facts_drain phase registration (CyclePhase, ALL_PHASES, NEEDS_LOCK) and its runCycle dispatch line (logic in cycle/facts-drain.ts); +15 GBRA-49 temporal typed edges: edge_contradictions phase registration + dispatch block + extract-phase relationship sweep call (logic in cycle/edge-contradictions.ts, link-relationships.ts); P3 x P1 (v0.60.57.0) composition: deltas re-summed at the merge; +1 fix wave 9 lane P (#5151): extract_facts phase passes drain so the facts watermark drain runs (logic in facts/reconcile-watermark.ts); +10 #6188: fence_repair phase registration (CyclePhase, ALL_PHASES, NEEDS_LOCK) and its runCycle dispatch block (logic in cycle/fence-repair.ts); +19 fix wave 12 #6242: source cycles with brain-wide phases also take the shared gbrain-cycle lease (acquireDbCycleLock lease set, needsMaintenanceLease, skipBrainWidePhases, all-skipped deriveStatus case; lease logic in cycle/lock-set.ts); +16 #6377: content_repair phase registration (CyclePhase, ALL_PHASES, NEEDS_LOCK), the REPAIR_LANE_PHASES dispatch helper shared with fence_repair (logic in cycle/content-repair.ts); +10 C4 pinned questions: standing_questions phase registration (CyclePhase, ALL_PHASES, NEEDS_LOCK) and its runCycle dispatch block (logic in questions/phase.ts); +11 #6696 (A5, A4): runCycle becomes the background-origin wrapper over runCycleUnscoped and adds the capacity notices (logic in persistence/admission-origin.ts, capacity-snapshot.ts) plus the CycleReport.notices interface field; +2 #6297: CycleOpts.directPhases (operator-named phases skip the patterns cadence); +5 #6865: unindexed_files phase registration (CyclePhase, ALL_PHASES, NEEDS_LOCK) and its line in the REPAIR_LANE_PHASES dispatch helper (logic in cycle/unindexed-files.ts); +2 fix wave 20 #6954: the extract phase warns on extract_write_lost and its stale drain retries the pages left due; +5 #7241: CycleOpts.onPhaseStart and its best-effort call in timePhase, so the autopilot-cycle job writes its current phase to minion_jobs.progress; +1 GBRA-133: the extract phase passes the stale-drain budget to its targeted pass when sync gave no slug list; +7 #7630 (GBRA-207): the sync phase refuses sync_anchor_relative when no source matches its directory and default's local_path is relative; re-summed at the memory train #8481 merge with v0.60.576.0 (3348 measured); +3 GST-1856: the purge phase drops applied-capture records past 90 days (logic in ingestion/applied-captures.ts purgeStaleAppliedCaptures); +4 train C: #9145 #6770 opt-in mcp_request_log retention purge step on top of master's cycle growth; +2 GBRA-387 storage manifest: dream skips a cycle scoped to the storage shelf (check in storage-manifest/door.ts); re-summed at the merge with master 3f138e1b (3357 measured)
-src/core/cycle/synthesize.ts 3244 ratchet +3 #7805: each captured session synthesizes only into its own frozen source (routing import, the outer wrapper, the routing parameter; logic in cycle/synthesize-source-routing.ts); +26 System One v1 S7/S8: triage and grounding decide delegation (triage-decide.ts, grounding-decide.ts); merged waves; grown v0.46.26.0 megawave + master rolling lease via shared throttled renewer; grown wave-g (#4506): cycle summaries can stay out of the source repo; +18: expired-verdict sweep + DeepSeek judge thinking pin (#4069); +47: #4077 cooperative-abort threading; +110: eval fix wave F6 spend surfacing (withChatPhase wrap, triage/child token telemetry, zero-page counter); +32: F1b quote-verify call site + kill switch; +2: F1a/F3/F4a OUTPUT POLICY rules; +59: F2 verified-segment rescue (gate at report construction, rescue knobs, telemetry); +19: rubric v2 peak-scoring + docblock rescue branch; +50: #4337 summary link-sample cap + dream_created_cycle_date preserve-on-rerun; +5: #4348 resolveCycleDate wiring (local-day summary bucketing); +3 round-3 rebase true-up; +55: #4805 synth-v2 completion skip (findSynthV2Completion + prefix-parameterized loadSuccessfulSynthesisKeys); +10: #4886 mode-aware buildSynthesisPrompt (oneshot children drop tool-use/final-prose guidance); #5105: small legacy writer/refusal and shared revision CAS delegates; +4: merge of #5666 durable synthesis completions with the v0.59.18.0 verify-epoch wiring; +7 #5413/#5471 discovery exclusions (self-capture session ids, dream output directories); +6 fix wave 2 (v0.60.5.0) integration: W7 paid-loop breaker check before submission and released-key daily-cap count on top of the W1b discovery exclusions; +6 v0.60.5.0 master-merge true-up: the wave-2 growth (+13 W1b, +6 W7) re-summed over master v0.59.18.0 at 3222 lines with no slack; +76 fix wave 3: per-run USD gate + fail-closed daily cap (C-13), child first-write ownership for stamp/reverse-write (C-8, #5685), cycle-date prompt hint (C-15), opt-in attribution rule (#5425); fix wave 3 x fix wave 2 (v0.60.5.0) composition: +19 at the merge; +2 #5806 triageNow clock seam forwarded to triage (interface field + call-site option); +4 #5854: a postprocess or summary publish still pending after its wait is deferred (publish_pending warn, no cooldown stamp; helper in synthesize-postprocess.ts); +14 #5490 review: a triage verdict a chat_fallback_chain model gave is used for the run but not cached (TriageResult.answeredBy, judge-client marker, guarded putDreamVerdict); Foundations 2 Lane C: maintenanceTransaction import (attributed summary page); +14 #5490 review: a triage verdict a chat_fallback_chain model gave is used for the run but not cached (TriageResult.answeredBy, judge-client marker, guarded putDreamVerdict); Foundations 2 Lane C: maintenanceTransaction import (attributed summary page); +14 #5490 review: a triage verdict a chat_fallback_chain model gave is used for the run but not cached (TriageResult.answeredBy, judge-client marker, guarded putDreamVerdict); lowered to 3200 by wave 9 lane W #5145: completion-key helpers (findLegacyCompletion, findSynthV2Completion, loadSuccessfulSynthesisKeys) peeled to synthesize-completion.ts with the new pre-triage partition; +13 P2 extraction.date_grounding: transcript observation date line instead of a run-date "Today's date" (config field + prompt arg); +1 fix wave 11 #6160: oneshot_task_prefixes on the child job data; +18 fix wave 12 #6069: unreliable-verdict backoff in runTriagePass (report code, pass backoff count, triage details entry; marker logic in triage-backoff.ts); +1 fix wave 12 #6242: SYNTH_PHASE_FAIL keeps an OperationError's suggestion and code (OperationError import); +3 wave 17 #6616: slug discovery and postprocessing share the canonical committed child outputs (loadCommittedSynthesisOutputs in synthesize-postprocess.ts; one call-site line, one parameter, one lookup line); lowered to 3224 by wave 17 #6642: the summary provenance section moved to summaryProvenanceLines in dream-provenance.ts; +6 GBRA-130 B-6 (#6860): surrogate-safe triage cuts (truncateUtf8) and the per-transcript verdict-cache write call site (logic in triage-backoff.ts VerdictCacheWrites); +2 GBRA-161 PR 4 (#7065): the synthesize phase activates each synthesized transcript's outputs as its generation (activateSynthesisGenerations import and call site; logic in cycle/synthesize-generations.ts); +8 GBRA-161 PR 5 (S-2): the dream summary publishes as a single-item dream_summary generation bound to its pre-run revision (publishSinglePage with a generation_fenced skip); +1 GBRA-60: a managed synthesis child carries dream_output (verify and stamp before put_page; cycle/synthesize-child-verify.ts)
+src/core/cycle/synthesize.ts 3252 ratchet +3 #7805: each captured session synthesizes only into its own frozen source (routing import, the outer wrapper, the routing parameter; logic in cycle/synthesize-source-routing.ts); +26 System One v1 S7/S8: triage and grounding decide delegation (triage-decide.ts, grounding-decide.ts); merged waves; grown v0.46.26.0 megawave + master rolling lease via shared throttled renewer; grown wave-g (#4506): cycle summaries can stay out of the source repo; +18: expired-verdict sweep + DeepSeek judge thinking pin (#4069); +47: #4077 cooperative-abort threading; +110: eval fix wave F6 spend surfacing (withChatPhase wrap, triage/child token telemetry, zero-page counter); +32: F1b quote-verify call site + kill switch; +2: F1a/F3/F4a OUTPUT POLICY rules; +59: F2 verified-segment rescue (gate at report construction, rescue knobs, telemetry); +19: rubric v2 peak-scoring + docblock rescue branch; +50: #4337 summary link-sample cap + dream_created_cycle_date preserve-on-rerun; +5: #4348 resolveCycleDate wiring (local-day summary bucketing); +3 round-3 rebase true-up; +55: #4805 synth-v2 completion skip (findSynthV2Completion + prefix-parameterized loadSuccessfulSynthesisKeys); +10: #4886 mode-aware buildSynthesisPrompt (oneshot children drop tool-use/final-prose guidance); #5105: small legacy writer/refusal and shared revision CAS delegates; +4: merge of #5666 durable synthesis completions with the v0.59.18.0 verify-epoch wiring; +7 #5413/#5471 discovery exclusions (self-capture session ids, dream output directories); +6 fix wave 2 (v0.60.5.0) integration: W7 paid-loop breaker check before submission and released-key daily-cap count on top of the W1b discovery exclusions; +6 v0.60.5.0 master-merge true-up: the wave-2 growth (+13 W1b, +6 W7) re-summed over master v0.59.18.0 at 3222 lines with no slack; +76 fix wave 3: per-run USD gate + fail-closed daily cap (C-13), child first-write ownership for stamp/reverse-write (C-8, #5685), cycle-date prompt hint (C-15), opt-in attribution rule (#5425); fix wave 3 x fix wave 2 (v0.60.5.0) composition: +19 at the merge; +2 #5806 triageNow clock seam forwarded to triage (interface field + call-site option); +4 #5854: a postprocess or summary publish still pending after its wait is deferred (publish_pending warn, no cooldown stamp; helper in synthesize-postprocess.ts); +14 #5490 review: a triage verdict a chat_fallback_chain model gave is used for the run but not cached (TriageResult.answeredBy, judge-client marker, guarded putDreamVerdict); Foundations 2 Lane C: maintenanceTransaction import (attributed summary page); +14 #5490 review: a triage verdict a chat_fallback_chain model gave is used for the run but not cached (TriageResult.answeredBy, judge-client marker, guarded putDreamVerdict); Foundations 2 Lane C: maintenanceTransaction import (attributed summary page); +14 #5490 review: a triage verdict a chat_fallback_chain model gave is used for the run but not cached (TriageResult.answeredBy, judge-client marker, guarded putDreamVerdict); lowered to 3200 by wave 9 lane W #5145: completion-key helpers (findLegacyCompletion, findSynthV2Completion, loadSuccessfulSynthesisKeys) peeled to synthesize-completion.ts with the new pre-triage partition; +13 P2 extraction.date_grounding: transcript observation date line instead of a run-date "Today's date" (config field + prompt arg); +1 fix wave 11 #6160: oneshot_task_prefixes on the child job data; +18 fix wave 12 #6069: unreliable-verdict backoff in runTriagePass (report code, pass backoff count, triage details entry; marker logic in triage-backoff.ts); +1 fix wave 12 #6242: SYNTH_PHASE_FAIL keeps an OperationError's suggestion and code (OperationError import); +3 wave 17 #6616: slug discovery and postprocessing share the canonical committed child outputs (loadCommittedSynthesisOutputs in synthesize-postprocess.ts; one call-site line, one parameter, one lookup line); lowered to 3224 by wave 17 #6642: the summary provenance section moved to summaryProvenanceLines in dream-provenance.ts; +6 GBRA-130 B-6 (#6860): surrogate-safe triage cuts (truncateUtf8) and the per-transcript verdict-cache write call site (logic in triage-backoff.ts VerdictCacheWrites); +2 GBRA-161 PR 4 (#7065): the synthesize phase activates each synthesized transcript's outputs as its generation (activateSynthesisGenerations import and call site; logic in cycle/synthesize-generations.ts); +8 GBRA-161 PR 5 (S-2): the dream summary publishes as a single-item dream_summary generation bound to its pre-run revision (publishSinglePage with a generation_fenced skip); +1 GBRA-60: a managed synthesis child carries dream_output (verify and stamp before put_page; cycle/synthesize-child-verify.ts); +8 #9598: a same-day rerun keeps the earlier runs' live summary links and counts them on their own line (in writeSummaryPage, which renders the summary)
src/core/cycle/extract-atoms.ts 1638 ratchet crossed the 1500 unlisted cap in the atoms/extraction fix wave: +21 embed-aware cost gate (#4878), +65 atoms-array anchor scan (#4913); peel candidate: the parse block (parseAtomsOutcome / parseArrayAtOffset / atomsFromParsedArray) into extract-atoms-parse.ts; +35: #4853 transcript-origin atoms link to their conversation page; +130: #4916 transcript failure-count/tombstone (extract_atoms_transcript_state, TODOS P2(b)); wave composition: #4916 transcript-state skip + #4948 zero-atom prompt + #4943 meetings source-id summed; +3: wave review — a later `[]` is an honest zero-yield, a non-atom-shaped array is a counted failure; +13: wave review — explicit budget keeps the cap over an unpriced embed route ($0-priced); +14: wave review — transcript-state write errors surfaced, missing table warns once; merged reliability/shared-skills source integration; +37 fix wave 3: stable undated atom dates + stale-atom retirement (C-14); +3 #5525: effectiveVisibility stamped on non-managed atoms; fix wave 3 x fix wave 2 (v0.60.5.0) composition: +3 at the merge; +6 fix wave 3 lane A (#5601): accepted-pending atom batches count as progress (helper in persistence/accepted-pending.ts); +4 fix wave 4: #5705 transcript-as-data system prompt lines and its message helper, #5627 response schema import (the atom-type list moved to extract-atoms-schema.ts); +30 #5809/#5832: drain hard/soft stop signals (ExtractAtomsOpts.signal/stopSignal, pre-commit abort checks, no strike or post-stop writes after a hard stop) and the cancellable backlog count; +1 #5812: transcript items are paste-stripped (corpusTextForExtraction import) before the input cut; +1 #5820: extract_atoms discovery passes selfCaptureSessionIds like synthesize; +10 #5856/#5854: drain attempt state (one BudgetTracker + one publish wait across batches) and the opt-in connector email/meeting exclusion (predicate in connector-atoms.ts); +1 Foundations 2 Lane C: maintenanceTransaction import (attributed stale-atom retirement); +5 fix wave 9 lane P (#5041): opt-in atom write-through hook and retired-atom slugs returned for file removal (logic in derived-write-through.ts); the parse block (parseAtomsOutcome / parseArrayAtOffset / atomsFromParsedArray) is peeled into extract-atoms-parse.ts (-193, fix wave 10 lane B); +35: #4853 transcript-origin atoms link to their conversation page; +130: #4916 transcript failure-count/tombstone (extract_atoms_transcript_state, TODOS P2(b)); wave composition: #4916 transcript-state skip + #4948 zero-atom prompt + #4943 meetings source-id summed; +3: wave review — a later `[]` is an honest zero-yield, a non-atom-shaped array is a counted failure; +13: wave review — explicit budget keeps the cap over an unpriced embed route ($0-priced); +14: wave review — transcript-state write errors surfaced, missing table warns once; merged reliability/shared-skills source integration; +37 fix wave 3: stable undated atom dates + stale-atom retirement (C-14); +3 #5525: effectiveVisibility stamped on non-managed atoms; fix wave 3 x fix wave 2 (v0.60.5.0) composition: +3 at the merge; +6 fix wave 3 lane A (#5601): accepted-pending atom batches count as progress (helper in persistence/accepted-pending.ts); +4 fix wave 4: #5705 transcript-as-data system prompt lines and its message helper, #5627 response schema import (the atom-type list moved to extract-atoms-schema.ts); +30 #5809/#5832: drain hard/soft stop signals (ExtractAtomsOpts.signal/stopSignal, pre-commit abort checks, no strike or post-stop writes after a hard stop) and the cancellable backlog count; +1 #5812: transcript items are paste-stripped (corpusTextForExtraction import) before the input cut; +1 #5820: extract_atoms discovery passes selfCaptureSessionIds like synthesize; +10 #5856/#5854: drain attempt state (one BudgetTracker + one publish wait across batches) and the opt-in connector email/meeting exclusion (predicate in connector-atoms.ts); +1 Foundations 2 Lane C: maintenanceTransaction import (attributed stale-atom retirement); +5 fix wave 9 lane P (#5041): opt-in atom write-through hook and retired-atom slugs returned for file removal (logic in derived-write-through.ts); +17 #5031: same-page case-insensitive atom adoption fallback (one page-atom scan per source page per run); +12 P2 atomsPrompt helper: extraction.date_grounding source observation date + rule in the atoms prompt; +4 GBRA-75: octet_length-bounded body-length predicate (minCompiledTruthChars) for discovery and the backlog count; GBRA-130 A-42 (#6804): dot-led atom stems and the legacy-slug adoption guard; re-measured at the Train A merge of #8948: 1633; re-measured at the Train C merge onto Train B (#9246 onto #9223): 1633 -> 1635, both sides' growth; +3 GBRA-504 guest notes: atom extraction skips guest sources (classification in guests/derived.ts)
src/core/engine.ts 2900 ratchet +5 #7191: findPages/countPagesBy signatures and type imports (SQL in engine-sql/page-lookup.ts); grown v0.46.26.0 megawave: relational/visibility/usage contract surface (#4352 #4218); grown wave-g (#4524 #4527): orphans-mode contract + removeLink deleted count; wave-k: +4 fail-closed TrajectoryOpts.remote contract doc (#3855), +2 FactListOpts.unconsolidatedOnly (#4070), +14 getAllConfig bulk-read contract (#3980); grown v0.46.26.0 megawave: relational/visibility/usage contract surface (#4352 #4218); grown wave-g (#4524 #4527): orphans-mode contract + removeLink deleted count; wave-k: +4 fail-closed TrajectoryOpts.remote contract doc (#3855), +2 FactListOpts.unconsolidatedOnly (#4070), +14 getAllConfig bulk-read contract (#3980); +1: getBacklinkCounts page-id contract doc (#4380); +9: FactListOpts.grep SQL pre-limit contract (#3851); +13: dream-verdict TTL contract (#4069); +33: softDeletePages batch soft-delete contract (#4587); +8: #4592 scoped getStats/getHealth contract doc; +5 read-time TTL validity contract docs (active vs history read semantics); +12: #4280 findOrphanPages type/quarantined metadata contract; +14: traversePathsDetailed row-cap contract (ship-review); +12: resolveSlugWithAliasDetailed owning-source contract (ship-review) | merged v0.48.1.0: master #4788 + wave traversePathsDetailed/resolveSlugWithAliasDetailed; master: | merged v0.48.1.0 true-up; corrective release: read-policy signatures and Chronicle scope; +7: #4882 listFactsSince entitySlug/sessionId composition doc; #5105: canonical page state shared module and transaction/snapshot delegates; #5105: guarded derived projection preparation and read seals; #5105: resident-stop registration and direct transaction contract; #5105: +1 raw preservation contract for legacy engine migration; merged company ingestion/schema routing changes; safety wave: fact embedding model and text identity contract; +5 write-path wave: findDuplicatePage excludeSlug + id-first ranking contract; +2 fw3 A14: addTag tagSource provenance contract; evidence delivery: getChunkWindows interface member + type import (+3); #5761: +4 markPagesAttendanceBlocked member + countStalePagesForExtraction attendance option; +4 #5888: FactListOpts.fingerprint + FactRow.fact_fingerprint contract (hot-memory duplicate collapse); +1 GBRA-49: LinkReadScope temporal opts on the link read contract; +4 #5984: upsertChunks sealChunkerVersion and createVersion preimage contract docs (round-trip diet); v0.60.58.0 merge: #5984 diet growth re-summed over v0.60.57.0 (2683 measured); +10 P7 relationalChainHop member + ChainHopOpts/ChainHopEdge imports (SQL in search/read-enrichment.ts); +14 contributor audit wave P0: listFactsKeyset member (delta facts keyset read contract) + FactRow.created_at_iso; +1 #5375: get_versions limit/include_body type import (GetVersionsOpts, PageVersionRows); 3 P2 speaker attribution: FactAttribution type + FactRow/NewFact.attributed_to fields + findCandidateDuplicates attributedTo option contract; +4 #5984 lane apply diet: setPageAliases inline option and upsertChunks pageId contract docs; +10 #6278: executeRaw timeoutMs contract (transaction-local statement_timeout for bounded preparation reads); +2 GBRA-69: replaceDerivedLinksBatch member; master v0.60.136.0 merge into #5575 memory trust (both sides kept); +6 GBRA-67: readPageSnapshotsBatch interface member (BrainEngine signatures cannot move); +1 GBRA-75 wave 10: optional findDuplicatePages member (batched findDuplicatePage, contract in engine-sql/pages.ts); +4 FactListOpts/TrajectoryOpts.excludePrivate fact-provenance visibility contract (interface fields cannot move); +18 GBRA-76: TransactionOptions (abort signal) interface and the transaction/transactionDirect signatures (abort logic in postgres-engine/transaction-abort.ts); +2 W14 P3.11 (#4381): LinkBatchInput.resolution_type on top of W13; +1 C2: findCandidateDuplicates arm:'keyword' contract doc (facts.candidate_fusion); re-summed at the master 6ccf30c3e merge (2708 integration + 2707 master - 2707 base); +5 Cat 40 Hard fix wave F2 (#6271): countKeywordPages/searchKeywordPages BrainEngine signatures (SQL in engine-sql/keyword-pages.ts); +6 W15 P1.2 (#6454): countStaleFrontmatterKeyPages/listStaleFrontmatterKeyPages/stripStaleFrontmatterKeys contract (SQL in engine-sql/pages.ts); +2 large pages Wave A sub-a: getChunkPage signature (get_chunks paging; SQL in engine-sql/chunks.ts); +5 #6696 B3: readEmbeddingStateCounts/listEmbeddingStateRows signatures + type import (SQL in engine-sql/chunks.ts); +2 Cat 40 next wave part 1: non-ranking link types on the relationalFanout/relationalChainHop/getBacklinkCounts/getAdjacencyBoosts contract docs (policy in link-ranking-policy.ts; re-summed at the 0.60.242.0 merge: master 2794 + 2); +26 Wave B PR 1: segmented page storage members (allocateBodyOccurrenceIds..sweepSegments) + page-body type import (SQL in engine-sql/page-body.ts); merge v0.60.248.0: Wave B PR 1 and master growth compose at 2822; +1 LHF wave 2 item 1: executeRaw opts gain jitOff/prepare (the JIT-off typed-search type check; logic in ops/search-type-filter.ts); +9 PR2 fix lane X: BrainEngine.keywordBoundedRead, one unscoped read under the keyword statement bound for the segmented-region read (interface member and its doc cannot move): 2823 + 9; +9 GBRA-177: TakesListOpts.oldestFirst/sinceOnOrBefore/ungradedFirst for the grade_takes window (interface fields cannot move; SQL in engine-sql/takes.ts): 2832 + 9; +6 GBRA-156: TransactionOptions.pipelineFirst (the declaration goes out with BEGIN behind a transaction-mode pooler; predicate in persistence/protocol.ts); interface fields cannot move; +1 GBRA-161 PR 2: deprecation notes on insertFacts({ deleteForPageFirst }), deleteFactsForPage and expireFact (interface docs cannot move); +7 GBRA-156: TransactionOptions.pipelineEarly (search read bodies go out behind BEGIN; predicate in postgres-engine/search-settings.ts); interface fields cannot move; +2 GBRA-156: TransactionOptions.readOnly (search read transactions open BEGIN READ ONLY; 2858 measured); grown v0.46.26.0 megawave: relational/visibility/usage contract surface (#4352 #4218); re-summed at the Wave B PR 4 merge with v0.60.452.0 (2866 measured); re-summed at the memory train #8481 merge with v0.60.576.0 (2874 measured); +1 GST-731: TrajectoryPoint.valid_until (interface fields cannot move); +9 #9068: deletePage/deletePages scrub contract docs (interface docs cannot move); +2 GBRA-467: optional holdSchemaMigrationLock member (interface members cannot move; logic in schema-migration-lock.ts); re-measured at the Train A merge of #8948: 2889; +1 #9295: wantedProducers option on the stale-page list signature (interface fields cannot move; SQL in engine-sql/pages.ts); +2 GBRA-574 B2: NewFact.dimension/value (the conversation fact slot; SQL in engine-sql/facts.ts); +6 W6 engine parity: typed sealChunks member and its doc (a test arm seals chunks without executeRaw; SQL in engine-sql/chunks.ts; interface members cannot move); +2 Rust engine plan PR 5: BrainEngine.capabilities member and its type import (table in engine-capabilities.ts; interface members cannot move); re-summed at the #9641 merge with #9631's head 56a9547a (2900 measured)
src/core/import-file.ts 2091 ratchet +2 #7880: importFromContent's holdNoncanonicalPrivate option (interface field; the hold is screenImportContent's); +2 #7848: importFromFile holds a non-canonical private request (predicate and hold in persistence/visibility-request.ts); +2 W1 belief ledger: the legacy import is an unmanaged projection point (logic in belief/projection-point.ts); +2: pre-publication withdrawal validation; grown v0.46.26.0 megawave: OCR budget + image import + embed-retry rewire (#3973 #3374); grown wave-g (#4530): per-model chunk-token cap wiring; +24 #4548: row-level visibility-aware fence merge on remote write-back (replaces the #2044 whole-block swap + #4553/#4555 warn-only paths); +7 #4546: merge extended to the timeline-embedded fence; +5 #4107: maybeOcr gates on the OCR model's provider; +3 #3893; +7: #4702 disabled_patterns pass-through to the sanity gate; composition true-up (fix-wave multi-train); +8 #4903: importCodeFile writes source_path so the full-sync reconcile can see code pages; -11: wave review — local fence append replaced by facts-fence.replaceOrInsertFactsFence (#4756 rule); security: durable queued authority and confined filesystem dispatch; master integration: grown v0.46.26.0 megawave: OCR budget + image import + embed-retry rewire (#3973 #3374); grown wave-g (#4530): per-model chunk-token cap wiring; +24 #4548: row-level visibility-aware fence merge on remote write-back (replaces the #2044 whole-block swap + #4553/#4555 warn-only paths); +7 #4546: merge extended to the timeline-embedded fence; +5 #4107: maybeOcr gates on the OCR model's provider; +3 #3893; +7: #4702 disabled_patterns pass-through to the sanity gate; composition true-up (fix-wave multi-train); +8 #4903: importCodeFile writes source_path so the full-sync reconcile can see code pages; -11: wave review — local fence append replaced by facts-fence.replaceOrInsertFactsFence (#4756 rule); harness support: boundary wiring to shared grants, isolated setup, withdrawal and delegated guards; merged v0.49: withdrawal preservation after data-only frontmatter parsing; #5105: small legacy writer/refusal and shared revision CAS delegates; #5105: +8 prepared contextual retrieval policy and retry boundary wiring; upstream integration: preserve independently reviewed master additions with branch facade extraction; #5252 wave: shared provider-free Markdown and code preparation; merged company ingestion/schema routing changes; master retrieval/projection integration with company ingestion; shared content: prepare managed image imports without bypassing canonical publication; +29 write-path wave: identity move/collision wiring (logic in import-identity.ts), deferred embedding on provider failure, image index completeness, file-time date anchor; +22 fw3 A13: markdown re-import reuses unchanged chunk vectors under the seal/wrapper/signature/protected-fence gate; +2 fw3 A12: importFromFile firstCommitAt option; +3 fw3 A14: managed imports keep add-only tags; +4 #5675: record the file origin move inference binds to (logic in import-identity.ts); fw3 integration: A12/A13/A14 (+27) and #5675 (+4) compose; +17 wave-2 W4: safe-chunk re-seal of unchanged legacy markdown/code pages (#5050 #5247) and embedding-input provenance on inline imports (#5553); -1 fix wave 2 (v0.60.5.0) integration: W4 delta re-summed over the merged master line count; fix wave 3 x fix wave 2 (v0.60.5.0) composition: +16 at the merge; +11 #4616: markdown and code imports keep the usable vectors of a partially refused batch and leave refused chunks for embed --stale; lowered to 2230: #5621 contextual-mode resolution peeled to core/import-contextual-mode.ts (shared with gbrain repair contextual-mode); +2 wave 8 lane D1 #5158: key-order fallback equality call (comparison lives in page-state/import-guard.ts); +1 F1c: direct imports run in maintenanceTransaction (write attribution; helper in persistence/attribution.ts); lowered to 2178: #5988 content screen and content-sanity config peeled to core/import-screen.ts; +1 #6007: the prepared apply returns its page id and seal (PreparedImportApplied); +1 #5333: trusted imports drop a stale oversized embed_skip/content_flag the gate no longer sets, and an embed_skip transition defeats both unchanged fast paths; wave 10 collector: lane E (#5333) and the other lanes compose at 2183; grown #6188 (+17): fence options interface, result fields and the Tier 1 step call (logic in fence-repair/import-step.ts); +2 #5984 single-write fast path: the coordinated existingSnapshot option (interface field) composes with the lane apply diet at 2202; +1 GBRA-69: a coordinated apply defers its chunker seal to the caller (sealImportedPage in page-state/projections.ts); lowered to 2023: #5001 the edge-mapping loop moved to code-chunks.ts mapCodeEdges (shared with the prepared apply); W14 P3.13 (#5001) lowered 2049→2023 by moving the edge loop to mapCodeEdges; +2 W13 PR1 on top (2025 measured); +2 #6529: the unchanged-image skip path records source_path (refreshSourcePath, as #4588 does for Markdown); +4 large pages A6/T33: code files keep CODE_FILE_MAX_BYTES, a page over PAGE_INLINE_MAX_BYTES commits with NULL vectors for the metered stale sweep; +1 #6722: an embed_skip page is chunked and never embedded (noEmbed folds the marker); merge v0.60.240.0: large pages and master growth compose at 2032; +24 Wave B lane 1d: the segmented storage step (stage before publication, flip in the apply, seal and post-commit projection; logic in persistence/segmented-apply.ts and page-body/ingest.ts) and the streamed-import dispatch over the single-string ceiling (logic in page-body/streamed-import.ts); merge v0.60.248.0: Wave B PR 1 and master growth compose at 2056; +4 Wave B review: a rename re-preparation reuses the staged segmented body (reuseSegments option) and the remote fence merge reads an unread body as fence-free (fenceBody in page-body/page-shape.ts); +2 Wave B gem A: a coordinated demotion versions the segmented page before demoting it (createVersion order); lanes compose at 2062; +2 Wave B lane 2q: ImportResult.searchable (interface field; the value comes from SegmentedImport.afterCommit);+2: pre-publication withdrawal validation; +9 #7172: kept chunk rows move to their new index and a bounded managed publication defers its chunk replacement (logic in page-state/chunk-moves.ts and page-state/projections.ts continueDeferredProjection); merge v0.60.332.0: #7172 and master growth compose at 2075; +7 GBRA-283 B3a (#8523): the three file import entry points re-enter an embedded engine's scope (needsEngineScope in core/engine-scope.ts), importFromContent runs its screened body in that scope as a closure, and the deferred embed resumes the import's scope; re-summed at the memory train #8481 merge with v0.60.576.0 (2088 measured); +3 GST-2112: importFromContent's expectedBaseRevision option and base check (a webhook capture binds its write to its readers check)
@@ -50,7 +50,7 @@ src/core/search/evidence-delivery.ts 1759 ratchet +5 W5: EvidencePlan.rankCut re
src/commands/config.ts 1546 ratchet +1 GBRA-216: recall.* config set value refusal (facts/recall-config.ts); +1 GBRA-216: config set refuses a dream.claim_conflicts.mode other than propose|off (refusal in facts/claim-conflicts.ts); new row: crossed the 1500 unlisted cap in wave 15 P7.4 #5461: set-time validation of think.pages_budget_chars / think.excerpt_ceiling_chars (range + parser live in core/think/pages-budget.ts), mirroring the cycle.consolidate.cluster_threshold hook; +1 wave 16 G5.1 (#6495): set-time refusal hook for search.keyword_statement_timeout_ms (check lives in commands/config/keyword-timeout-value.ts); +1 wave 18b lane 5 (#5012 item 6): search.contextual_retrieval prints the existing-pages hint after the write (text lives in commands/config/contextual-mode-hint.ts); +1 #6712 PR 2: retired/rollback sync key dispatch line (logic in core/sync-config-keys.ts handleSyncKeyConfig); +1 #6865: sync.slug_conflicts.auto_remove boolean validation at set time (refusal text in repair/slug-autoheal.ts); +1 #6948: sync.origin_twins.auto_resolve boolean validation at set time (refusal text in repair/origin-twins-heal.ts); +2 #6795: config set chat_model/expansion_model help line and the model-pin import (shadow report and file-pin unset live in commands/config/model-pin-shadow.ts); +1 #6712 PR 4b: sync.admission set-time hook (value logic in commands/config/sync-admission-value.ts); +4 #7130: set-time refusal hook for sync.max_deletes / sync.max_delete_ratio (and .source.<id>) / purge.retention_hours (check lives in core/sync-reconcile.ts deleteSafetyConfigRefusal); +1 GBRA-150: sync.metafile_pages set-time route (body in config/sync-metafile-pages-value.ts); re-summed at the v0.60.330.0 merge (1520 measured); +2 #7242 minions.terminal_hook file-plane key and its set branch (logic in minions/terminal-hook.ts); +1 GBRA-161: generations.* set-time route (refusal in commands/config/generations-values.ts); +1 GBRA-207 #7630: sync.repo_path set-time refusal hook (refusal in core/sync-config-keys.ts syncRepoPathRefusal); +4 GBRA-377 PR B: skills.resolver.* file-plane routing (doc line, the one-line router and its two dispatch lines; logic in core/setup/skill-resolver-config.ts); +8 train C: #8921 #7346 nested credential redaction on top of master's config growth; +1 train C: #9145 config.ts edit on top of #8921 #7346; +7 #8920: plural, acronym and credential secret words with the count-word exception (isSensitiveConfigKey) and URL userinfo masking (redactConfigValue)
src/commands/mcp-expose.ts 1524 ratchet hosted_option: Session carries the gbrain.io coaching notice on the first-receipt run and Tailscale/service friction exits (copy, refs and gating live in core/onboard/hosted-option.ts); +7 GBRA-199: --surface help lines, surfaceChosen option field and the advertise pass-through (registrationAdvertise in core/mcp-registration.ts); +5 GBRA-583: one-click Cursor/Claude link lines in the Next block and verified --status, and install_links in --json (builders live in core/connector-install-links.ts)
src/core/behavior-change-notice.ts 1774 ratchet +4 train R: #7491/#7492 keyword_identifier_probe and keyword_slug_handles rows and their comment, #7175 keyword phrase row; the BEHAVIOR_CHANGES table grows by one row per disclosed change: +4 the #7891 provenance-drift and #7917/#7918 maintenance-lowering rows and their comments (re-summed at the 0.60.495.0 merge: 1547 + 4); +1 GBRA-156 #7593: private_pages_granted_sources row (re-summed at the 0.60.527.0 merge: 1574 + 1); +3 GBRA-200 comment, write-grant refusal and degraded-stamp rows (re-summed at the 0.60.562.0 merge: 1615 + 3); +2 GBRA-280 get_page selector-precedence row and comment (re-summed at the 0.60.569.0 merge: 1619 + 2); the BEHAVIOR_CHANGES table grows by one row per disclosed change: +4 the #7891 provenance-drift and #7917/#7918 maintenance-lowering rows and their comments (re-summed at the 0.60.495.0 merge: 1547 + 4); +2 GBRA-205 saved_facts_stems row and its comment (re-summed at the #7901 0.60.492.0 merge: 1541 + 2); +2 GBRA-205 search.query_facts_block default-on row and its approval comment (re-summed at the #7610 0.60.490.0 merge: 1539 + 2); +2 the #7900 content checkpoint host-move row (since TBD until the merge slot), +2 the #7897 private-hold sweep row (since TBD until the merge slot), +2 the #7880 ingest_capture and company-brain private-hold row (since TBD until the merge slot), +5 the frozen-source wave comment and four rows (#7868, #7850, #7869/#7870, #7871), +2 the #7848 visibility_noncanonical hold row (since TBD until the merge slot), +2 the #7846 extract_atoms session-source row (re-summed at the 0.60.481.0 merge: master 1524 + 2), +2 the #7805 synthesize session-source and #7841 visibility_not_applied rows (re-summed at the 0.60.480.0 merge: master 1522 + 2), +2 strict door planned-state row (#7705, re-summed at the 0.60.470.0 merge: master 1514 + 2), +2 Bun floor 1.4.4 row (#7644), the GBRA-95 RLS backfill row (+2), +3 rows for #7596 pass_interrupted, #7599 read-only serve and the --access=read-only ceiling, +1 G5 lane C trust_release row, +1 #7619 cli_flag_equals, +3 GBRA-207 #7630 relative-anchor and stalled-write rows, +2 the #7632 function search_path disclosure row and +2 the #7679 orphaned worktree refresh row (re-summed at the 0.60.471.0 merge: master 1516 + 2), +2 the #7814 retired v0.13.1 grandfather row, +2 the #7618 conversion withhold/progress/push row (master 1520 + 2); the behavior-change table split (#7607) retires this row; +4 GBRA-188 #7489: the wave comment and three rows (brain-first instructions, starter surface default, per-turn rule); +1 GBRA-188 plugin_turn_hook_gbra188 row; +1 GBRA-242 provider_key_rules_7959 row (#7959), +2 the GBRA-199 registration_lists_verbs row (since TBD until the merge slot); +2 GBRA-133 #7652: the #7611 pass_abandoned reader row and the lean read-only serve socket row (re-summed at the 0.60.503.0 merge: master 1555 + 2); +1 GBRA-243: the per-turn hook disclosure row (rows are data and cannot move); +4 GBRA-156 #7598 harness wave comment and rows (remote page cap, sources_not_readable refusal, sources add next step); +4 GBRA-156 #7601 search_quotes_transcript_rows comment and row; +1 GBRA-175 #7475 autopilot_restarts_serve_7475 row (re-summed at the #8012 merge: 1566 + 1); +3 #7997/#8014/#8015 rows (redaction markers, company db_only keep, ignored supabase_only scope); +2 #7199 (re-port of #7228) classic_drift_rescreen_7199 comment and row; +2 #7931 file_drift_agrees_7931 comment and row; +1 #7950 file_drift_slug_release_7950 row; +1 #7974 file_drift_followups_7974 row; +1 #8059 quoted_fence_marker_8059 row; +2 GBRA-247 #8009 provenance_repair_held_8009 and #7982 pass_transient_streak_7982 rows; +4 GBRA-247 #7973 plain_directory_sync_7973, #7988 managed_marker_own_directory_7988, #7985 former_binding_parked_group_7985 and settle_effects_retire_7985 rows Train S merge: 1570 base + 5 (master since the #8077 base) + 13 (#8077) = 1588.; +2 GST-687 remote_quotes_unverified_text_gst687 row and its comment (re-summed at the gate-ahead on train S 0.60.534.0: 1588 + 2); +2 #8377: the quote fence follow-ups row and its comment; +2 #8384: the quote fence follow-ups 2 row and its comment; +2 #8384 wave 3: the quote fence follow-ups 3 row and its comment; +5 GBRA-218 train M rows (A1 member_read_access_gbra218 and member_access_hatch_scope_gbra218, B shared_agent_audience_gbra231, A2 folder_access_rules_gbra218, folder_access_scoped_role_gbra218), re-summed at the train M merge of master v0.60.541.0: 1596 + 5 = 1601 measured; +3 GST-359 train C rows (C1 qm_attested_actor_gst359, C2 member_facts_gst359, D qm_memory_provider_gst359), re-summed at the train C merge of master v0.60.543.0: 1601 + 3 = 1604 measured; +2 #8424: hook_launcher_8424 row and its comment (rows are data and cannot move), re-summed at the #8418 v0.60.546.0 merge: 1604 + 2 = 1606 measured; +2 #8426: mcp_lane_launcher_8426 row and its comment (rows are data and cannot move); +2 GST-927: empty_nonstring_args_gst927 row and its comment, re-summed at the gate-ahead on master v0.60.550.0 plus #8420: 1610 measured; +2 GBRA-283 Wave A (#8460): engine_keyed_caches_gbra283 row and its comment (rows are data and cannot move); +2 GBRA-287: segmented_freeze_hold_gbra287 and segmented_reexport_gbra287 rows (rows are data and cannot move); +1 GST-1209: segmented_tiling_gst1209 row (rows are data and cannot move); +1 GST-1251: skillopt_loop_deprecated_gst1251 row (rows are data and cannot move); +1 GST-1209 follow-up: untiled_hold_repair_gst1209 row (rows are data and cannot move); +1 GBRA-283 B3a: embedded_scope_required_gbra283 row (rows are data and cannot move); re-summed at the train R merge with v0.60.574.0: 1623 + 4; +2 GST-1387: refresh_fence_refusal_gst1387 row and its comment (rows are data and cannot move); re-summed at the memory train #8481 merge with v0.60.578.0 (1643 measured); +3 GBRA-253 #8109 rows (frontmatter_drift_write_8109, contacts_activity_advance_8109, contact_rows_dedupe_8109; rows are data and cannot move), re-summed at the master v0.60.581.0 merge: 1643 + 3 = 1646 measured; +3 #8123 part C rows: sync_write_through_off_writeback_7084, managed_sync_dry_run_counts_7087, frontmatter_missing_source_dir_7889 (since TBD until the merge slot; re-summed at the 0.60.583.0 merge: 1646 + 3); +4 PR B commit_ledger_prb, doctor_foreign_writers_prb and sources_guard_prb rows and their comment (rows are data and cannot move; since TBD until the merge slot); +1 PR B #8615: file_drift_held_needs_prefer_8615 row; +1 PR B #8617: refresh_source_changed_retry_8617 row; +1 PR B #8662: commit_push_checkout_not_a_source_8662 row (since TBD until the merge slot; rows are data and cannot move); +2 PR B refresh_barrier_prb and commit_push_base_prb rows (re-summed: 1658 measured); +3 convergence PR A: the wave comment and two rows (conversion_content_evidence_pr_a, git_gap_live_pages_pr_a; since TBD until the merge slot; rows are data and cannot move); re-summed at the gate-ahead on master v0.60.592.0 plus #8711: 1658 + 3 = 1661 measured; +4 GST-1094/GST-900 rows (memory_recall scope-read, member-bound acting_user, recall max_chars, unknown_param _meta-only) and +1 qm_scope_writes_gst1113 and +1 recall_question_terms_gst1304 rows (rows are data and cannot move), re-summed at the 0.60.595.0 slot merge: 1661 + 6; +1 GST-1582 refresh_barrier_import_gst1582 row (since TBD until the merge slot; rows are data and cannot move); +2 GST-1601 source_changed_origin_gst1601 and adopt_local_edits_gst1601 rows (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.596.0 merge: 1668 + 2; +1 GST-1623 refresh_barrier_capacity_gst1623 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.599.0 merge: 1670 + 1; +2 GBRA-224 W1 release_channel_stable_default row and its comment; +1 GST-1623 refresh_barrier_later_write_gst1623 row (#8765; rows are data and cannot move); +5 #8766 GST-1623 items 4/6-9 and #8755: the wave comment and four rows (doctor_foreign_writers_partial_gst1623, commit_push_enclosing_repo_gst1623, owner_guard_fail_closed_gst1623, adopt_local_edits_hardening_8755) and +1 managed_sync_kind_reserved_8765 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on master v0.60.608.0 plus #8798: 1674 + 6; +1 GST-1853 refresh_barrier_aborted_refresh_sync_gst1853 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.613.0 merge: 1680 + 1; +1 GST-1674 refresh_refused_merge_recovery_gst1674 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.614.0 merge: 1681 + 1; +1 #8824/#8826/#8767: adopt_local_edits_replay_markers_8824 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on #8837: 1682 + 1; +1 url_source_origin row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on #8834: 1683 + 1; +1 #8828: the refresh_replan_own_commits_8828 row (1684 + 1 at the 0.60.618.0 slot); +1 the managed commit-push unpublished-count row; +1 the refresh publish-diverged default row; +1 GST-2051 ungranted_member_writes_gst2051 row (since TBD until the merge slot; rows are data and cannot move); +1 GST-731 think_window_trajectory_gst731 row and +1 GST-1602 purge_cancels_deferred_write_gst1602 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on #8915 v0.60.621.0: 1688 + 2; +1 GST-2059: owner_reads_private row; +1 #8888: the record-origin checkout lock-down row (re-summed at the Q6 stack on #8934 v0.60.625.0: 1691 + 1); +1 GST-1158 F9: the attest_direct_page_writes_deferred_gst1158 row (since TBD until the merge slot); +1 GST-1158 E1/F3/F4 rows (since TBD until the merge slot), re-summed at the master merge; +1 GBRA-284 personal_sources_gbra284 row (since TBD until the merge slot) (re-summed at the QM wave merge onto master v0.60.626.0: 1692 + 3); +1 GST-1158 F9: the attest_direct_page_writes_deferred_gst1158 row (since TBD until the merge slot); +1 GST-1158 v3: the qm_personal_structured_gst1158 row (since TBD until the merge slot); +1 #8477 GST-1158 F2 personal-tools row at the QM wave merge (1695 + 1); +1 GST-1158 F9: the attest_direct_page_writes_deferred_gst1158 row (since TBD until the merge slot); +1 #8483 memory_propose row at the QM wave merge (1696 + 1); +1 GST-1094 gap 4: the qm_admin_http_gst1094 row (since TBD until the merge slot); +1 GST-1158: the member_email_link_gst1158 row (since TBD until the merge slot); +2 #8479 member-email rows at the QM wave merge (1697 + 2); +1 GST-2112: ingest_keeps_readers_gst2112 row (re-summed at the Q7 v0.60.627.0 merge: 1692 + 1); +1 #8982 federated_member_writes_8982 row (since TBD until the merge slot; rows are data and cannot move); +1 GST-2116 commit_push_skipped_paths_gst2116 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the Q10 slot on #9009 ee0f4a78: 1694 + 1; +1 GST-2118 pending_ledger_flagged_gst2118 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the Q12 slot on #9016 afb49de5: 1695 + 1; +1 GBRA-431: read_scope_params_gbra431 row (rows are data and cannot move), re-summed at the #9032 stack merge: 1697 measured; +2 GST-2201 sync_restored_file_gst2201 and purge_keeps_committed_file_gst2201 rows (since is the current VERSION until the merge slot; +1 GST-2243 remember_share_gst2243 row (re-summed at the #9098 stack merge: 1699 + 1); +1 GST-2312 #9024 sync_filter_owned_hold_9024 row (re-summed at the #9064 stack merge: 1700 + 1; rows are data and cannot move); +2 access-privacy wave (0.60.649.0): the owner_private_facts_gst2089 and private_labels_write_ahead_gst2092 rows; +1 GBRA-443 private_labels_batch_exit_gbra443 row (rows are data and cannot move), re-summed at the 0.60.650.0 slot on #9038: 1703 + 1; +1 postgres_tls_default row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.651.0 merge: 1704 + 1; +1 GST-2331 sync_reads_fetch_nothing_gst2331 row (rows are data and cannot move), re-summed at the 0.60.654.0 stack on #9045 6ff5540d: 1705 + 1; +7 QM wave (#9037) rows: attest_scope_read_ops_gst1158, attest_direct_page_writes_deferred_gst1158, personal_sources_gbra284, qm_personal_structured_gst1158, memory_propose_held_writes_gst1158, member_email_link_gst1158, qm_admin_http_gst1094 (re-summed at the 0.60.655.0 stack on #9110 f9b2072e: 1706 + 7); +1 GST-2228 recreated_takes_section_keeps_stored_takes_gst2228 row (since TBD; re-summed at the keep-takes-and-link-dates train merge: 1713 + 1); +1 GST-2228 links_rows_keep_own_dates_gst2228 row (since TBD; re-summed at the same train merge: 1714 + 1); +2 the W1 + memory proposals train (#9133): attest_every_page_write_deferred_gst2249 and memory_proposals_owner_http_gst2407 rows (rows are data and cannot move), re-summed at the #9138 v0.60.661.0 stack merge: 1715 + 2 = 1717 measured; +1 #8903 effect_git_secret_gate_gst1923 row (rows are data and cannot move), re-summed at the 0.60.664.0 stack on #9142 3931adb4: 1717 + 1; +1 GST-2407 PR 3: qm_recall_own_page_contract_v4 row (rows are data and cannot move), re-summed at the 0.60.666.0 stack on #9148 69c12917: 1718 + 1; +2 GST-363 PR 1 and PR 3 (#9135): the serves_several_labels_gst363 and stdio_member_per_harness_gst363 rows; +3 #9134 train rows member_forget_names_host_9101, refresh_fence_retry_id_gst2353 and recorded_read_view_args_gst2214 (rows are data and cannot move), re-summed at the #9134 slot merge onto #8829 dfc24954: 1721 + 3; +3 source-checkouts wave rows (autopilot_git_reconcile_gbra386, unknown_drift_history_rescreen, refresh_abandon_members_gst1465), re-summed at the #9137 stack merge: 1724 + 3; persistence train 13 at 0.60.676.0: its five rows on top of 0.60.675.0; +1 GST-2250 reconcile_publish_opt_out_gst2250 row (since TBD until the merge slot; rows are data and cannot move); +1 #8902 unmanaged_push_history_scan_8902 row (re-summed at the 0.60.678.0 stack on 501742d9: 1733 + 1); +1 GST-2246 maintain_safe_free_phases_gst2246 row (since TBD until the merge slot; rows are data and cannot move), re-summed on the doctor/dream/enrich train at the 0.60.679.0 slot merge onto #9170 82932eda: 1734 + 1; +2 GST-2462 privacy_label_ignored_gst2462 and access_page_rules_gst2462 rows (rows are data and cannot move), re-summed at the #9173 slot merge onto 49a922ef: 1735 + 2; +1 GST-2107 follow-up write_capacity_low_not_refusal_gst2107 row (rows are data and cannot move), re-summed at the 0.60.681.0 slot merge onto #9173 c08d0c8b: 1737 + 1; +1 GST-2490: owner_reads_derived_gst2490 row (rows are data and cannot move); +1 GST-2468: the label_only_operator_repairs_gst2468 row (a BEHAVIOR_CHANGES row cannot move); +1 GST-2446 remember_pageless_reply_gst2446, +1 GST-2492 strict_held_facts_gst2492 and +1 GST-2346 D1 owner_facts_shared_gst2346 rows (rows are data and cannot move), re-summed at the 0.60.685.0 train merge onto #9181 405ea4cf: 1740 + 3; +1 GST-2476: the readers_label_setter_gst2476 row (rows are data and cannot move), re-summed at the #9184 slot merge onto the #9179 train 361d57c6: 1743 + 1; +1 GST-2487: the fence_fact_private_in_place_gst2487 row (rows are data and cannot move), at the same slot merge of #9188 0075f09a: 1744 + 1; +1 GST-2515: the sync_status_commits_waiting_gst2515 row (rows are data and cannot move), at the 0.60.688.0 slot merge onto 599b1234: 1745 + 1; +3 GST-2519: commit_push_untrack_gst2519, db_only_labels_kept_gst2519 and git_ignored_label_repair_gst2519 rows (rows are data and cannot move), re-summed at the 0.60.691.0 slot merge onto #9167 ad4f0aef: 1746 + 3; +3 GST-2492 PR 2: the remember_pageless_ask, strict_fact_writers_held and sync_strict_requires_managed rows (rows are data and cannot move), re-summed at the master v0.60.691.0 merge: 1749 + 3; +3 GST-2346 rows owner_forget_private, owner_forget_readers_page and member_save_withdrawn_scope (rows are data and cannot move), re-summed at the 0.60.693.0 slot merge onto #9202 840858e9: 1752 + 3; +2 GST-2518 page_label_widening_held_gst2518 and GST-2521 owner_labels_guarded_gst2521 rows and +1 GST-2511 fence_fact_widening_held_gst2511 row (rows are data and cannot move), re-summed at the 0.60.694.0 slot merge onto master 2c8320d7: 1755 + 3; +3 the GST-2515/GST-2520 notifier_retry_unwatched_gst2515 and strict_skip_mode_refusal_gst2520 rows and the GST-2456 unmanaged_push_every_site_gst2456 row, re-summed at the 0.60.698.0 slot merge onto #9217 887398f0: 1758 + 3; +2 GST-2407: context_pack scope read and attestRead over the owner route; +9 releases per batch: the generated-table import, the releasedIn helper and its comment, the spread of RELEASED_BEHAVIOR_CHANGES; new rows now live in behavior-changes.d/ and stop growing this file (re-summed at the master v0.60.704.0 merge: 1763 + 9 = 1772 measured); +2 #7646 (GBRA-404 salvage): the disclosure lists releases oldest first whatever the table order
-src/core/git/commit-push.ts 1562 ratchet GST-2519: --untrack (#7753 port: untrackTargets, untrackPaths; untrackAdmitted, the managed-worktree storage.db_only admission; previewUntrack) and the staged-removal hint in skippedPathsError grow the commit door past the 1500 default (master 1487 + 140); GST-2456 (#9174): crossed the 1500 unlisted cap at the GST-2456 merge of master v0.60.678.0: pushBase (the scan base and lease read live from every push URL, #5138) and the scan budget and progress options; Ctx and publish internals keep it in this file (1487 + 31), re-summed at the master 0c577834 merge into #9198: 1627 + 31; +47 #8928 salvage rebuild (GBRA-404) #7752: previewPaths (the dry run asks git against a copied index), admitPaths/flaggedEntries/previewRoots split out of commitPaths and shared with it, settlePending exported (re-summed on master v0.60.699.0: 1658 + 47); +1 GBRA-404 /ship round 2: the dry run stages into its temporary index copy for real (staged-rename partner refusal); GST-2767: the git runner (git-run.ts) and the skipped-path checks with their reasons (skipped-paths.ts) moved out, 1600; +14 GST-2767 staged_for_removal refusal and dry-run skipped-path parity; +1 commit_paths_unmerged: admitPaths calls assertNoUnmergedPaths (skipped-paths.ts); GST-2964: the untrack admission (untrackTargets, untrackAdmitted, untrackPageCandidates) moved to untrack-admission.ts, 1561; +1 the relativeEscapesRoot import (path-confine.ts, #9606) so a ..drafts folder is not read as outside the checkout, 1562
+src/core/git/commit-push.ts 1585 ratchet GST-2519: --untrack (#7753 port: untrackTargets, untrackPaths; untrackAdmitted, the managed-worktree storage.db_only admission; previewUntrack) and the staged-removal hint in skippedPathsError grow the commit door past the 1500 default (master 1487 + 140); GST-2456 (#9174): crossed the 1500 unlisted cap at the GST-2456 merge of master v0.60.678.0: pushBase (the scan base and lease read live from every push URL, #5138) and the scan budget and progress options; Ctx and publish internals keep it in this file (1487 + 31), re-summed at the master 0c577834 merge into #9198: 1627 + 31; +47 #8928 salvage rebuild (GBRA-404) #7752: previewPaths (the dry run asks git against a copied index), admitPaths/flaggedEntries/previewRoots split out of commitPaths and shared with it, settlePending exported (re-summed on master v0.60.699.0: 1658 + 47); +1 GBRA-404 /ship round 2: the dry run stages into its temporary index copy for real (staged-rename partner refusal); GST-2767: the git runner (git-run.ts) and the skipped-path checks with their reasons (skipped-paths.ts) moved out, 1600; +14 GST-2767 staged_for_removal refusal and dry-run skipped-path parity; +1 commit_paths_unmerged: admitPaths calls assertNoUnmergedPaths (skipped-paths.ts); GST-2964: the untrack admission (untrackTargets, untrackAdmitted, untrackPageCandidates) moved to untrack-admission.ts, 1561; +1 the relativeEscapesRoot import (path-confine.ts, #9606) so a ..drafts folder is not read as outside the checkout, 1562; +23 GST-2961: publish stops on a push the host refuses for the credential (push_credential_refused) and the refusal record is read, kept while the push URL differs from the fetch URL, and cleared when a push lands; classification, helper naming and the record file live in push-credential.ts, but Ctx, publish and the commit-push cycle keep their call sites here, re-summed at the merge of master 8562a490: 1562 + 23 = 1585
src/commands/auth.ts 1518 ratchet new row: crossed the 1500 unlisted cap at the v0.60.595.0 merge: GST-1113 --attest-sources help lines plus GST-1158 F3 --attest-read help lines (3); CLI help lines cannot move; re-measured at the Train A merge onto master v0.60.708.0: 1503 + 2 (the #8930 shared-token notice) = 1505; re-measured at the Train C merge onto Train B (#9246 onto #9223): 1505 -> 1509, both sides' growth; +3 Wakeshift PR 2 (#8709), one line each: revoke (by name) calls forgetWakePrincipal for every token row its UPDATE returned (RETURNING 1 became RETURNING id, so no line added there), revokeById calls it for the revoked token id, and revokeClient calls it for the revoked OAuth client id; each call ends that principal's open watches and queues its Wakeshift forget (logic in core/wakeshift/forget.ts) after the command's own UPDATE/DELETE; master 1509 + 3 = 1512; +6 GBRA-585 E: auth create --member defaults to read,write (MEMBER_TOKEN_SCOPES, its help lines and the output note) = 1518
src/core/markdown.ts 1501 ratchet new row: crossed the 1500 unlisted cap at the train C merge: #8921 #7052 tag_too_long hold (tagLengthHold import; the limit lives in core/tag-limit.ts) on top of master's 1500
src/mcp/dispatch.ts 1505 ratchet new row: crossed the 1500 unlisted cap with GBRA-504 guest notes (+4): the guest attribution option threaded into dispatch (parsing and checks live in core/guests/admission.ts); next growth should peel the response-cap block into a sibling module; +3 GBRA-585: DispatchOpts.localSourceImplicit and its pass-through to the op context (placement logic in core/access/implicit-placement.ts)
diff --git a/scripts/postgres-arm-weights-postgres-only.json b/scripts/postgres-arm-weights-postgres-only.json
index 9474e18bfd..a3c8fc1e65 100644
--- a/scripts/postgres-arm-weights-postgres-only.json
+++ b/scripts/postgres-arm-weights-postgres-only.json
@@ -352,6 +352,7 @@
"test/repair-fences.test.ts": 19599,
"test/repair-file-drift-deleted-6712.test.ts": 11424,
"test/repair-file-drift-held-6712.test.ts": 5130,
+ "test/repair-file-drift-whole-class.test.ts": 20040,
"test/repair-frontmatter-keys-sweep-6454.test.ts": 7459,
"test/repair-frontmatter.test.ts": 12782,
"test/repair-receipt-compaction.test.ts": 10136,
diff --git a/scripts/postgres-arm-weights.json b/scripts/postgres-arm-weights.json
index b32f169742..e66965ddfd 100644
--- a/scripts/postgres-arm-weights.json
+++ b/scripts/postgres-arm-weights.json
@@ -553,6 +553,7 @@
"test/repair-file-drift-held-6712.test.ts": 11404,
"test/repair-file-drift-held-window-gbra133.test.ts": 30603,
"test/repair-file-drift-provenance-gbra133.test.ts": 7919,
+ "test/repair-file-drift-whole-class.test.ts": 50780,
"test/repair-frontmatter-keys-sweep-6454.test.ts": 10019,
"test/repair-frontmatter.test.ts": 26839,
"test/repair-ghost-database-ahead-gbra133.test.ts": 9540,
diff --git a/scripts/serial-files.tsv b/scripts/serial-files.tsv
index 738751811f..eb9a3fb937 100644
--- a/scripts/serial-files.tsv
+++ b/scripts/serial-files.tsv
@@ -478,3 +478,4 @@ test/hermes-snapshot-7067.serial.test.ts R2 R2: mock.module(node:fs) wraps copyF
test/wakeshift-pr2.serial.test.ts global-state global-state: R3: constructs a second PGLiteEngine inside a test (the git-backed brain for write.settled); binds a fake Wakeshift HTTP listener
test/wakeshift-emit-spool.serial.test.ts global-state global-state: resets the module-level Wakeshift env-key cache (resetWakeshiftEnvKeyForTests) and starts the process-wide persistence consumer; binds a fake Wakeshift HTTP listener
test/push-secret-scan-gaps.serial.test.ts global-state global-state: sets GBRAIN_HOME, PATH (a git wrapper for the index race) and GBRAIN_GIT_ALLOW_FILE_TRANSPORT through withEnv for real commits and pushes to local bare remotes
+test/git-commit-push-credential-refused-gst2961.serial.test.ts global-state global-state: sets GBRAIN_HOME through the withEnv helper to read the push log a commit-push child wrote, spawns real gbrain CLI children, and runs a local git smart-HTTP stub server on a random port
diff --git a/scripts/stress/README.md b/scripts/stress/README.md
index 03444d7603..34dad873d9 100644
--- a/scripts/stress/README.md
+++ b/scripts/stress/README.md
@@ -101,12 +101,16 @@ shards.
their Postgres arms join that night's race hunt. Changed test files are
never sampled or skipped.
- **Shards.** Work items (a file's iterations, split when ten exceed the
- budget) pack into the fewest shards whose measured estimates stay under 25
- minutes. A file's estimate is its measured stress iteration
+ budget) pack into the fewest shards whose measured estimates stay under 12
+ minutes, so the gate finishes about when the other cheap-tier lanes do. A
+ file's estimate is its measured stress iteration
(`scripts/stress/iteration-weights.json`, mined from stress shard job logs
with `bun scripts/stress/gate.ts mine-iterations <log>…`, which merges into
- the map), else its lane weight, else the lane's p75: a fresh database per
- iteration can make a stress iteration slower than the file's lane run.
+ the map), else its lane weight, else the lane's p95 (the race hunt uses p75):
+ a fresh database per iteration can make a stress iteration slower than the
+ file's lane run, and a new file has no history. At p75, a new Postgres-arm
+ file planned at 41 s an iteration ran 145 s and took its shard past the
+ 35-minute job timeout (Test run 44139096116).
There is no shard-count cap; `max-parallel: 12` keeps a large PR
from starving other jobs. Shard jobs record results and exit 0 on test
failures; the result job decides, so a planned iteration without a receipt
diff --git a/scripts/stress/gate.ts b/scripts/stress/gate.ts
index b80f5c1a46..e4e2315ad2 100644
--- a/scripts/stress/gate.ts
+++ b/scripts/stress/gate.ts
@@ -33,7 +33,8 @@ import {
} from './plan.ts';
const ROOT = resolve(import.meta.dir, '..', '..');
-export const GATE_SHARD_BUDGET_MS = 25 * 60_000;
+export const GATE_SHARD_BUDGET_MS = 12 * 60_000;
+export const GATE_UNMEASURED_QUANTILE = 0.95;
export const RACE_SHARD_BUDGET_MS = 55 * 60_000;
export const RACE_BASE_SHARDS = 6;
export const RACE_MAX_SHARDS = 12;
@@ -63,7 +64,7 @@ function liveKeyOnly(root: string): Set<string> {
return new Set(existsSync(path) ? readFileSync(path, 'utf8').split('\n').map(l => l.trim()).filter(l => l && !l.startsWith('#')) : []);
}
-function classify(root: string, files: string[], weights: Weights): { stress: Array<PlanFile & { perIterationMs: number; setupMs: number }>; notStressed: NotStressed[] } {
+function classify(root: string, files: string[], weights: Weights, unmeasured = 0.75): { stress: Array<PlanFile & { perIterationMs: number; setupMs: number }>; notStressed: NotStressed[] } {
const live = liveKeyOnly(root);
const stress: Array<PlanFile & { perIterationMs: number; setupMs: number }> = [];
const notStressed: NotStressed[] = [];
@@ -72,7 +73,7 @@ function classify(root: string, files: string[], weights: Weights): { stress: Ar
const reason = notStressedReason(file, live);
if (reason) { notStressed.push({ file, reason }); continue; }
const profile = profileFor(file, { armed: armMode(root, file).armed, postgres: true });
- const perIterationMs = iterationEstimateMs(file, profile.name, weights);
+ const perIterationMs = iterationEstimateMs(file, profile.name, weights, unmeasured);
stress.push({ file, profile: profile.name, iterations: DEFAULT_ITERATIONS, estimateMs: 0, perIterationMs, setupMs: profile.prereq ? 180_000 : 0 });
}
return { stress, notStressed };
@@ -115,7 +116,7 @@ export function planGate(root: string, input: GatePlanInput, weights = loadWeigh
return emptyPlan('gate', 'not a PR event');
}
files = withWrappers(root, files);
- const { stress, notStressed } = classify(root, files, weights);
+ const { stress, notStressed } = classify(root, files, weights, GATE_UNMEASURED_QUANTILE);
const shards = planShards(stress, DEFAULT_ITERATIONS, GATE_SHARD_BUDGET_MS);
return {
...emptyPlan('gate', stress.length ? `${stress.length} file(s) × ${DEFAULT_ITERATIONS} iterations` : 'no changed test files to stress'),
diff --git a/scripts/stress/plan.ts b/scripts/stress/plan.ts
index a00d7331eb..4e0d8f135e 100644
--- a/scripts/stress/plan.ts
+++ b/scripts/stress/plan.ts
@@ -293,7 +293,7 @@ export function loadWeights(root: string): Weights {
};
}
-const p75 = (values: number[]) => { const s = [...values].sort((a, b) => a - b); return s.length ? s[Math.min(s.length - 1, Math.ceil(0.75 * s.length) - 1)]! : 30_000; };
+const quantile = (values: number[], q: number) => { const s = [...values].sort((a, b) => a - b); return s.length ? s[Math.min(s.length - 1, Math.ceil(q * s.length) - 1)]! : 30_000; };
/**
* Per-file median of the stress iterations in `logs` (stress shard job logs: `✓|✗ <file> iteration N (seed S) 12.3s`), in
@@ -313,15 +313,18 @@ export function mineStressIterations(logs: string[]): Map<string, number> {
}));
}
-/** Measured milliseconds for one iteration of `file` in `profile`: a measured stress iteration first, else the lane's weight, else its p75. */
-export function iterationEstimateMs(file: string, profile: ProfileName, w: Weights): number {
+/**
+ * Measured milliseconds for one iteration of `file` in `profile`: a measured stress iteration first, else the lane's
+ * weight, else the lane's `unmeasured` quantile (p75 unless the caller asks for a more conservative one).
+ */
+export function iterationEstimateMs(file: string, profile: ProfileName, w: Weights, unmeasured = 0.75): number {
const stressed = w.stress?.get(file);
if (stressed !== undefined) return stressed;
switch (profile) {
- case 'postgres-arm': return w.arms.get(file) ?? p75([...w.arms.values()]);
- case 'e2e': return w.e2e.get(file) ?? p75([...w.e2e.values()]);
- case 'serial': return (w.serialSeconds.get(file) ?? p75([...w.serialSeconds.values()])) * 1000;
+ case 'postgres-arm': return w.arms.get(file) ?? quantile([...w.arms.values()], unmeasured);
+ case 'e2e': return w.e2e.get(file) ?? quantile([...w.e2e.values()], unmeasured);
+ case 'serial': return (w.serialSeconds.get(file) ?? quantile([...w.serialSeconds.values()], unmeasured)) * 1000;
case 'slow': return w.unit.get(file) ?? 120_000;
- default: return w.unit.get(file) ?? p75([...w.unit.values()]);
+ default: return w.unit.get(file) ?? quantile([...w.unit.values()], unmeasured);
}
}
diff --git a/scripts/structural-suites.tsv b/scripts/structural-suites.tsv
index a1f27f87f7..0b2f6ddb32 100644
--- a/scripts/structural-suites.tsv
+++ b/scripts/structural-suites.tsv
@@ -217,6 +217,7 @@ test/harness-onboarding.test.ts harness identity and private handoff 6 readFileS
test/hook-command.serial.test.ts user-prompt 18 source-surface-helper
test/hook-push-spawn-env.test.ts spawnDetachedPush env handoff 2 readFileSync
test/hook-push-spawn-env.test.ts tryExecAsync env handoff 1 readFileSync
+test/imessage-source.test.ts repo-less brain (${kind}) 10 readFileSync
test/import-calls.test.ts operations filter guard 1 exec-scan
test/import-private-hold-callers-7897.test.ts import entry points hold a non-canonical private request (#7897) 2 readFileSync
test/init-mode-picker.test.ts cost matrix: newest models, priced from model-pricing 6 readFileSync
@@ -380,7 +381,7 @@ test/scripts/run-verify-parallel.test.ts run-verify-parallel.sh — no-timeout-b
test/scripts/serial-files.test.ts scripts/serial-files.tsv (serial lane manifest) 5 readFileSync
test/scripts/stable-daily.test.ts stable-daily.yml 2 readFileSync
test/scripts/stress-gate.test.ts docs anchors 1 readFileSync
-test/scripts/stress-gate.test.ts gate plan 5 readFileSync
+test/scripts/stress-gate.test.ts gate plan 6 readFileSync
test/scripts/stress-plan.test.ts execution profiles 3 readFileSync
test/scripts/stress-plan.test.ts shards 5 readFileSync
test/scripts/test-env-opt-ins-guard.test.ts check-test-env-opt-ins 5 readFileSync
diff --git a/src/commands/autopilot-dispatch.ts b/src/commands/autopilot-dispatch.ts
index 49df7fb9c1..a7f97126cd 100644
--- a/src/commands/autopilot-dispatch.ts
+++ b/src/commands/autopilot-dispatch.ts
@@ -9,6 +9,7 @@ import { assertNever, type BrainHealth } from '../core/types.ts';
import { syncIntervalMinutes } from '../core/meetings/source-config.ts';
import { MEETINGS_DEFAULT_SYNC_INTERVAL_MIN } from '../core/meetings/types.ts';
import { SLACK_DEFAULT_SYNC_INTERVAL_MIN } from '../core/slack/types.ts';
+import { IMESSAGE_DEFAULT_SYNC_INTERVAL_MIN } from '../core/imessage/types.ts';
import type { MinionQueue } from '../core/minions/queue.ts';
import { loadAllSources, parseSourceConfig, sourceConfigHasRemoteUrl, sourceLocalPathSkipWarning, type SourceRow } from '../core/sources-load.ts';
import { isConnectorSourceKind } from '../core/persistence/connector-identity.ts';
@@ -584,6 +585,7 @@ export function connectorSyncIntervalMs(config: unknown, baseIntervalMs: number)
case 'github': return baseIntervalMs;
case 'meetings': return syncIntervalMinutes(parsed, MEETINGS_DEFAULT_SYNC_INTERVAL_MIN)! * 60_000;
case 'slack': return syncIntervalMinutes(parsed, SLACK_DEFAULT_SYNC_INTERVAL_MIN)! * 60_000;
+ case 'imessage': return syncIntervalMinutes(parsed, IMESSAGE_DEFAULT_SYNC_INTERVAL_MIN)! * 60_000;
default: return assertNever(kind);
}
}
diff --git a/src/commands/doctor/checks/git-convergence.ts b/src/commands/doctor/checks/git-convergence.ts
index 7e008db36d..f8d6156994 100644
--- a/src/commands/doctor/checks/git-convergence.ts
+++ b/src/commands/doctor/checks/git-convergence.ts
@@ -46,6 +46,8 @@ import { boundUnknownDetails } from '../bounded-unknown.ts';
import { isSyncDisabledConfig } from '../../../core/sync-policy.ts';
import { sourceMirrorReadOnly } from '../../../core/persistence/mirror-read-only.ts';
import { APPROVED_FILE, POLICY_FILE } from '../../../core/access/policy-git.ts';
+import { readCredentialRefusal } from '../../../core/git/commit-push.ts';
+import { CREDENTIAL_HELPER_KEYS_WHY, credentialHelperKeysArgv, describeHelpers, type CredentialRefusalState } from '../../../core/git/push-credential.ts';
export const GIT_CONVERGENCE_WARN_MS = 6 * 3_600_000;
export const GIT_CONVERGENCE_FAIL_MS = 24 * 3_600_000;
@@ -55,7 +57,9 @@ const MAX_DIRTY_PATHS = 200;
interface RootReport { root: string; source_ids: string[]; branch: string | null; ahead: number; behind: number; dirty: number;
oldest_unpushed_at: string | null; oldest_dirty_at: string | null; status: 'ok' | 'warn' | 'fail'; stranded?: true; uncommitted_pages?: string[];
- managed?: true; diverged?: true; unpushed_commits?: CheckoutCommit[]; porcelain?: CheckoutPorcelain; mirror_read_only?: true; policy_only_mirror?: true }
+ managed?: true; diverged?: true; unpushed_commits?: CheckoutCommit[]; porcelain?: CheckoutPorcelain; mirror_read_only?: true; policy_only_mirror?: true;
+ /** GST-2961: the last push was refused for the credential git used, and no push has landed since. */
+ credential_refused?: CredentialRefusalState }
const canonicalPath = (path: string) => { try { return realpathSync(path); } catch { return path; } };
@@ -211,6 +215,13 @@ export async function gitConvergenceCheck(engine: BrainEngine, now = Date.now())
if (pages.length) report.uncommitted_pages = pages;
if (report.status === 'ok') report.status = 'warn';
}
+ // GST-2961: a push the host refused for the credential git used is reported at once; no retry will land it.
+ for (const report of reports) {
+ const refused = readCredentialRefusal(report.root);
+ if (!refused) continue;
+ report.credential_refused = refused;
+ if (report.status === 'ok') report.status = 'warn';
+ }
const skipped = [...byTop.values()].filter((r): r is { root: string; source_ids: string[]; skipped: string } => 'skipped' in r);
const details = { roots: reports, skipped, ...(roots.size > MAX_ROOTS ? { not_probed: roots.size - MAX_ROOTS } : {}),
warn_after_hours: GIT_CONVERGENCE_WARN_MS / 3_600_000, fail_after_hours: GIT_CONVERGENCE_FAIL_MS / 3_600_000, fetched: false };
@@ -247,8 +258,22 @@ export async function gitConvergenceCheck(engine: BrainEngine, now = Date.now())
const remedy = [!publishable.length ? '' : publishable.some(r => isManagedFilesystemPath(r.root))
? 'Commit and push them: on a managed canonical worktree the persistence owner commits and pushes page writes (gbrain sources writer status <source> --json shows parked pushes; gbrain sources writer git-durability <source> --enable turns them on), and files that are not pages are committed with gbrain git commit-push -m <msg> -- <paths> in the checkout, never pulled or rebased; elsewhere gbrain sources push --path <root> for a bootstrap workspace, or git push in the checkout'
: 'Commit and push them (gbrain sources push --path <root> for a bootstrap workspace, or git push in the checkout)', mirrorNote].filter(Boolean).join('. ');
- const stranded = publishable.filter(r => r.stranded);
const status = bad.some(r => r.status === 'fail') ? 'fail' : 'warn';
+ const refused = bad.find(r => r.credential_refused);
+ if (refused) {
+ const c = refused.credential_refused!;
+ const answered = c.helpers.find(h => h.answered);
+ const who = answered ? `the credential from ${answered.helper}${answered.scope ? ` (${answered.scope} config)` : ''}${c.username ? ` for ${c.username}` : ''}` : 'the credential git used';
+ const others = bad.filter(r => r.credential_refused && r !== refused).length;
+ return { name: 'git_convergence', status, details,
+ message: `Git checkouts have not converged with their upstream: ${lines.join(' | ')}. ${refused.root}: ${c.url} has refused every push since ${c.since} (${c.attempts} attempt(s), push_credential_refused: ${c.kind === 'not_found' ? '"Repository not found", HTTP 404' : 'HTTP 403'}) for ${who}, so its commits stay on this machine until git uses a credential for an account that can push there. ${describeHelpers(c)}${others ? ` ${others} other checkout(s) are refused the same way, see details.roots (credential_refused).` : ''} This compares with the last fetched upstream and does not fetch.${boundNote}`,
+ fix: { actor: 'user', consent: [], requires_exclusive: false,
+ argv: credentialHelperKeysArgv(refused.root),
+ why: CREDENTIAL_HELPER_KEYS_WHY,
+ user_message: `Pushes from ${refused.root} to ${c.url} have been refused since ${c.since} for ${who}, so ${refused.ahead} commit(s) are only on this machine (nothing is lost). ${describeHelpers(c)} Please make git use a credential for an account that can push to this repository: the read-only command in this fix lists each credential helper key (such as credential.helper) with the file that sets it, so change the key in the file whose helper answered, then run gbrain git commit-push --push-only --path ${refused.root}.`,
+ verify: doctorVerify('git_convergence') } };
+ }
+ const stranded = publishable.filter(r => r.stranded);
const uncommitted = stranded.find(r => r.uncommitted_pages);
if (uncommitted) {
const pages = uncommitted.uncommitted_pages!;
diff --git a/src/commands/dream.ts b/src/commands/dream.ts
index 680156f97d..bdef105fe2 100644
--- a/src/commands/dream.ts
+++ b/src/commands/dream.ts
@@ -909,6 +909,16 @@ export async function runDream(engine: BrainEngine | null, args: string[]): Prom
onceForPhase: opts.once ? opts.phases[0]! : undefined,
});
+ // A phase the caller named (or --input implied) that skipped for want of a
+ // database did not do what was asked: refuse like --source/--drain do.
+ const noDbPhase = report.phases.find(p => p.status === 'skipped' && p.details?.reason === 'no_database'
+ && (opts.phases as string[]).includes(p.phase));
+ if (noDbPhase) {
+ dreamExit(opError('database_error',
+ `gbrain dream --phase ${noDbPhase.phase} requires a connected brain (no engine available); the phase was skipped (no_database)`,
+ 'Fix the brain connection (`gbrain doctor --json` names the cause), then run the phase again.'), opts.json);
+ }
+
// Exit non-zero when the cycle failed overall or any phase failed (agent-first
// operator wave E4): a 'partial' cycle whose phase reports 'fail' — thrown and
// contained, or caught inside the runner — is never success. Warn-only
diff --git a/src/commands/extract-conversation-facts.ts b/src/commands/extract-conversation-facts.ts
index 6e47251e54..ad33a64e1d 100644
--- a/src/commands/extract-conversation-facts.ts
+++ b/src/commands/extract-conversation-facts.ts
@@ -356,6 +356,7 @@ export interface ExtractConversationFactsResult {
fallback_slugify_count: number;
/** Entity values kept raw after a best-effort resolution failure. */
resolution_errors: number;
+ /** GBRA-574: windows whose slot-tagging call failed; their facts were kept without slots (--force tags them again). */ slot_tagging_failed?: number;
/** Managed brains: pages whose publication was accepted but is still pending (retried next run). */
pages_pending?: number;
/** Managed brains: pages whose extraction generation is blocked until the page changes (no model call). */
@@ -1805,6 +1806,7 @@ export async function runExtractConversationFacts(
aggregate.facts_inserted += perSource.facts_inserted;
aggregate.fallback_slugify_count += perSource.fallback_slugify_count;
aggregate.resolution_errors += perSource.resolution_errors;
+ if (perSource.slot_tagging_failed) aggregate.slot_tagging_failed = (aggregate.slot_tagging_failed ?? 0) + perSource.slot_tagging_failed;
if (perSource.pages_pending) aggregate.pages_pending = (aggregate.pages_pending ?? 0) + perSource.pages_pending;
if (perSource.pages_blocked) aggregate.pages_blocked = (aggregate.pages_blocked ?? 0) + perSource.pages_blocked;
if (perSource.pages_detection_ambiguous) aggregate.pages_detection_ambiguous = (aggregate.pages_detection_ambiguous ?? 0) + perSource.pages_detection_ambiguous;
@@ -1895,6 +1897,7 @@ export async function runExtractConversationFacts(
if (aggregate.resolution_errors > 0) {
console.log(` Preserved ${aggregate.resolution_errors} fact(s) without an entity target after best-effort resolution errors.`);
}
+ if (aggregate.slot_tagging_failed) console.log(` Kept the facts of ${aggregate.slot_tagging_failed} window(s) without slots after slot tagging failed; --force tags them again.`);
if (anyBudgetExhausted) {
console.log(unpricedModels.size > 0
? ` no_pricing: ${[...unpricedModels].join(', ')}. Raising --max-cost-usd cannot resolve missing pricing.`
diff --git a/src/commands/git.ts b/src/commands/git.ts
index b32f072cab..0fc70ab43b 100644
--- a/src/commands/git.ts
+++ b/src/commands/git.ts
@@ -382,11 +382,15 @@ export async function runGit(args: string[]): Promise<number> {
} catch { /* best-effort */ }
}
if (failed.code === 'push_unconfirmed' || failed.code === 'integrate_conflict' || failed.code === 'commit_outside_source_root'
- || failed.code === 'publish_secret_found' || failed.code === 'publish_scan_unreadable') {
+ || failed.code === 'publish_secret_found' || failed.code === 'publish_scan_unreadable' || failed.code === 'push_credential_refused') {
try {
const bi = args.indexOf('--branch');
const branch = bi !== -1 && args[bi + 1] ? args[bi + 1].replace(/^refs\/heads\//, '') : currentBranchOf(args);
- if (failed.code.startsWith('publish_')) appendPushLog('refused', branch, '', failed.code);
+ if (failed.code === 'push_credential_refused') {
+ const d = JSON.parse(String(failed.detail ?? '{}')) as { commit?: string; kind?: string; username?: string | null; helpers?: Array<{ helper: string; answered: boolean }> };
+ const answered = d.helpers?.find(h => h.answered);
+ appendPushLog('refused', branch, d.commit ?? '', `push_credential_refused: the host refused the credential git used (${d.kind === 'not_found' ? 'repository not found, HTTP 404' : 'HTTP 403'}${answered ? `, from ${answered.helper}${d.username ? ` for ${d.username}` : ''}` : ''})`);
+ } else if (failed.code.startsWith('publish_')) appendPushLog('refused', branch, '', failed.code);
else appendPushLog(failed.code === 'integrate_conflict' ? 'conflict' : 'local-only', branch, failed.detail ?? '');
} catch { /* best-effort */ }
}
diff --git a/src/commands/repair.ts b/src/commands/repair.ts
index d4de0dcf5b..88dc34049a 100644
--- a/src/commands/repair.ts
+++ b/src/commands/repair.ts
@@ -39,6 +39,9 @@ import { resolveSecretRules } from '../core/secret-spans.ts';
import { normalizeSeatLabel } from '../core/context/seat.ts';
import { agentSessionFlagArgs } from '../core/repair/agent-session-facts.ts';
import { fileDriftConsentText } from '../core/repair/file-drift.ts';
+import { loadConfig } from '../core/config.ts';
+import { currentCliWriteWait } from '../core/persistence/write-wait.ts';
+import type { OperationContext } from '../core/ops/contract.ts';
import { privateLabelsLedger } from './repair-private-labels.ts';
import { openFactsLedger, openFactsUndoLedger, readFactIdsFile } from './repair-open-facts.ts';
import { createdBeforeRequired, memberModeRefused } from '../core/repair/open-facts.ts';
@@ -188,6 +191,11 @@ Options:
--prefer file accepts the deletions.
--cursor <next_cursor>
file-drift --held: continue after the window the previous preview covered (its next_cursor).
+ --whole-class file-drift --held --side unknown|database|both --prefer file: preview every window of that side as one class
+ (one manifest, one hash; pages edited in gbrain after their file stay kept_newer_page, and on a read-only
+ mirror pages that need protected parts in the file stay kept_protected_parts). Only a complete preview
+ prints its apply (--apply --expect <hash> --yes, after the user agrees); on a read-only mirror it imports
+ each file into its page database-only. A stopped apply prints its resume command first and exits 1.
--since <ISO-8601|7d>
file-drift: keep only pages whose newest drift conflict is at or after the instant (with --all-drifted, or
the bare survey). An age (7d, 12h) is resolved once to a concrete instant; the preview, its hash and the
@@ -233,14 +241,14 @@ A sources add --url clone whose pull stops at pull_blocked_local_changes: docs/g
Proposed readers for the pages every member's key reads (visibility --propose): docs/guides/repair.md#propose-readers.
Renames whose identity sync did not keep (rename-identity): docs/guides/live-sync.md#renaming-a-page.`;
-const BOOLEAN_FLAGS = new Set(['--apply', '--all', '--json', '--no-embed', '--include-ambiguous', '--include-cross-entity', '--diff', '--yes', '--no-llm', '--all-drifted', '--include-failures', '--force', '--close', '--held', '--allow-without-owner', '--propose']);
+const BOOLEAN_FLAGS = new Set(['--apply', '--all', '--json', '--no-embed', '--include-ambiguous', '--include-cross-entity', '--diff', '--yes', '--no-llm', '--all-drifted', '--include-failures', '--force', '--close', '--held', '--allow-without-owner', '--propose', '--whole-class']);
const VALUE_FLAGS = new Set(['--readers', '--slugs-file', '--out', '--rules', '--source', '--limit', '--expect', '--only', '--skip', '--slug', '--max-usd', '--prefer', '--request', '--class', '--since', '--keep', '--request-id', '--older-than', '--from', '--side', '--state', '--after', '--cursor', '--provenance', '--kind', '--mode', '--run', '--key', '--generation', '--day', '--cwd', '--session', '--principal', '--created-before', '--ids-file', '--undo']);
/** Flags only some kinds accept, with the kinds that do. */
const KIND_FLAGS: Record<string, readonly string[]> = {
'--only': ['frontmatter', 'fences', 'slug-conflicts', 'file-drift', CONTENT_LANE], '--skip': ['frontmatter', 'fences', 'slug-conflicts', 'file-drift', CONTENT_LANE], '--diff': ['frontmatter', 'fences', 'slug-conflicts', CONTENT_LANE], '--yes': ['frontmatter', 'conversation-labels', 'stuck-recovery', 'ghost-pages', 'legacy-twins', 'rename-identity', 'url-clone-fences'],
'--include-cross-entity': ['duplicate-facts'],
'--slug': ['fences', 'file-drift', 'rename-identity', 'overwritten-edits', 'origin-twins', 'moved-pages', 'timeline-order', 'contact-rows', 'provenance', 'secret-spans', 'segmented-tiling', 'visibility'], '--from': ['rename-identity'], '--close': ['rename-identity'], '--prefer': ['file-drift'], '--request': ['file-drift'], '--all-drifted': ['file-drift'], '--class': ['file-drift', 'visibility', 'private-labels', 'open-facts'], '--since': ['file-drift', 'generations'],
- '--held': ['file-drift', 'generations'], '--side': ['file-drift'], '--state': ['file-drift'], '--cursor': ['file-drift'], '--provenance': ['file-drift'],
+ '--held': ['file-drift', 'generations'], '--side': ['file-drift'], '--state': ['file-drift'], '--cursor': ['file-drift'], '--provenance': ['file-drift'], '--whole-class': ['file-drift'],
'--keep': ['stuck-recovery'], '--request-id': ['stuck-recovery'],
'--older-than': ['receipt-compaction'], '--include-failures': ['receipt-compaction'], '--force': ['receipt-compaction'],
'--after': ['uncommitted-deletions', 'open-facts'], '--created-before': ['open-facts'], '--ids-file': ['open-facts'], '--undo': ['open-facts'],
@@ -260,7 +268,7 @@ const invalid = (message: string, suggestion: string, preview: string[] = ['gbra
interface RepairArgs { kind?: string; apply: boolean; all: boolean; json: boolean; noEmbed: boolean; includeAmbiguous: boolean; includeCrossEntity: boolean; diff: boolean; yes: boolean;
noLlm: boolean; source?: string; limit?: string; expect?: string; maxUsd?: number; only: string[]; skip: string[]; slugs: string[];
allDrifted: boolean; prefer?: 'file' | 'database'; requests: string[]; driftClass?: string; since?: string;
- held: boolean; side?: string; state?: string; provenance?: string; cursor?: string;
+ held: boolean; side?: string; state?: string; provenance?: string; cursor?: string; wholeClass: boolean;
keep?: 'prior' | 'disk' | 'withdrawn'; requestId?: string; olderThan?: string; includeFailures: boolean; force: boolean; from?: string; close: boolean; afterPage?: number;
generationKind?: string; generationMode?: string; run?: string; key?: string; generation?: number; day?: string; rules?: string[];
cwdPrefixes: string[]; sessions: string[]; principal?: string; readers?: string; slugsFile?: string; allowWithoutOwner: boolean; propose: boolean; out?: string;
@@ -309,7 +317,7 @@ function readSlugsFile(path: string): string[] {
/** Strict parse: every flag is known, value flags carry a value, at most one kind. */
export function parseRepairArgs(args: string[]): RepairArgs {
const parsed: RepairArgs = { apply: false, all: false, json: false, noEmbed: false, includeAmbiguous: false, includeCrossEntity: false, diff: false, yes: false, noLlm: false, only: [], skip: [], slugs: [],
- allDrifted: false, held: false, requests: [], includeFailures: false, force: false, close: false, cwdPrefixes: [], sessions: [], allowWithoutOwner: false, propose: false, classes: [] };
+ allDrifted: false, held: false, wholeClass: false, requests: [], includeFailures: false, force: false, close: false, cwdPrefixes: [], sessions: [], allowWithoutOwner: false, propose: false, classes: [] };
const used = new Set<string>();
const positional: string[] = [];
let maxUsdText: string | undefined;
@@ -338,6 +346,7 @@ export function parseRepairArgs(args: string[]): RepairArgs {
else if (flag === '--no-llm') parsed.noLlm = true;
else if (flag === '--all-drifted') parsed.allDrifted = true;
else if (flag === '--held') parsed.held = true;
+ else if (flag === '--whole-class') parsed.wholeClass = true;
else if (flag === '--include-failures') parsed.includeFailures = true;
else if (flag === '--force') parsed.force = true;
else if (flag === '--close') parsed.close = true;
@@ -496,6 +505,62 @@ export function parseRepairArgs(args: string[]): RepairArgs {
return parsed;
}
+/**
+ * `gbrain repair file-drift --held --side <side> --prefer file --whole-class [--apply --expect <hash> --yes]` (file-drift-class.ts):
+ * the preview prints the manifest summary (`details.class_manifest`) and, once complete, the data-loss card and the apply command;
+ * the apply asks for the user's consent on the hash, stops after the current page on SIGTERM or SIGHUP, and a stopped apply
+ * prints its resume command first and exits 1.
+ */
+async function runFileDriftClassCommand(engine: BrainEngine, a: { apply: boolean; json: boolean; source?: string; expect?: string; only: string[]; skip: string[]; slugs: string[];
+ requests: string[]; allDrifted: boolean; held: boolean; side?: string; state?: string; provenance?: string; cursor?: string; prefer?: string; args: string[] }): Promise<void> {
+ const { applyFileDriftClass, assertWholeClassSelection, classApplyLines, classConsentText, classPreviewArgv, previewFileDriftClass } = await import('../core/repair/file-drift-class.ts');
+ assertWholeClassSelection({ ...a, sourceId: a.source });
+ if (!a.source) throw invalid('gbrain repair file-drift --whole-class needs exactly one --source.', 'Name the source: gbrain repair file-drift --source <id> --held --side unknown --prefer file --whole-class');
+ const scope = await resolveRepairScope(engine, a.source);
+ const sel = { sourceId: a.source, side: a.side!, only: [...new Set(a.only)].sort(), skip: [...new Set(a.skip)].sort() };
+ if (!a.apply) {
+ if (a.expect) throw invalid('--expect only binds an --apply.', `Preview with ${shellQuote(classPreviewArgv(sel))}, then apply the hash it prints.`);
+ const preview = await previewFileDriftClass(engine, scope, sel, { remote: false, ...(a.cursor ? { cursor: a.cursor } : {}), progress: createProgress(cliOptsToProgressOptions(getCliOptions())) });
+ const result = preview.none ? { kind: 'file-drift', complete: true, message: 'no held pages', details: {} }
+ : { kind: 'file-drift', complete: preview.class_manifest!.complete, residuals: preview.other, details: { class_manifest: preview.class_manifest! },
+ ...(preview.resume_command ? { resume_command: preview.resume_command } : {}), ...(preview.apply_command ? { apply_command: preview.apply_command, card: preview.card } : {}) };
+ if (a.json) { console.log(JSON.stringify({ scope, mode: 'dry_run', results: [result] }, null, 2)); return; }
+ if (preview.none) { console.log(`file-drift: no held pages in source ${a.source}`); return; }
+ const m = preview.class_manifest!;
+ const lines = [`file-drift --whole-class: ${m.pages} page(s) in the class, ${m.lost_lines_total} line(s) lost in total, ${m.complete ? 'complete' : 'NOT complete'}`,
+ ` manifest: ${m.path}`, ` hash: ${m.hash}`,
+ ` kept_newer_page: ${m.residual.kept_newer_page.count} (next: ${m.residual.kept_newer_page.next})`,
+ ` kept_protected_parts: ${m.residual.kept_protected_parts.count} (next: ${m.residual.kept_protected_parts.next})`];
+ const other = Object.entries(preview.other).map(([k, v]) => `${k}=${v}`).join(', ');
+ if (other) lines.push(` not in the class: ${other}`);
+ for (const page of m.top.slice(0, 10)) lines.push(` loses ${page.lost_lines} line(s): ${page.slug} (${page.path})`);
+ if (preview.resume_command) lines.push(` The preview stopped before its last window; no apply command until it completes. Resume: ${preview.resume_command}`);
+ if (preview.card) lines.push('', ...preview.card);
+ console.log(lines.join('\n'));
+ return;
+ }
+ if (!a.expect) throw invalid('gbrain repair file-drift --whole-class --apply applies only the manifest a complete preview printed.', `Preview first: ${shellQuote(classPreviewArgv(sel))}, then run the apply command it prints after the user agrees.`,
+ [...classPreviewArgv(sel), '--json']);
+ const consent = classConsentText(a.expect);
+ const auth = await consentGate({ command: 'repair file-drift', effects: ['destructive'], actor: 'agent', ...consent,
+ argv: [...classPreviewArgv(sel), '--apply', '--expect', a.expect, ...(a.json ? ['--json'] : [])], preview_argv: [...classPreviewArgv(sel), '--json'], plan_hash: a.expect, args: a.args },
+ { json: a.json, env: engineConsentEnv(engine) });
+ if (!auth) return;
+ const stop = new AbortController();
+ const release = registerSignalOwner('repair apply', signal => {
+ if (!stop.signal.aborted) { process.stderr.write(`[repair] ${signal}: stopping after the current page; send it again to exit now\n`); stop.abort(signal); return; }
+ release(); process.kill(process.pid, signal);
+ });
+ const ctx = { engine, config: loadConfig() ?? { engine: engine.kind }, logger: { info: console.error, warn: console.error, error: console.error }, dryRun: false, remote: false,
+ sourceId: a.source, writeWaitMs: currentCliWriteWait().waitMs } as OperationContext;
+ const result = await applyFileDriftClass(ctx, scope, sel, a.expect, { stop: stop.signal }).finally(release);
+ clearHealthMemo(engine);
+ if (!result.complete) setCliExitVerdict(1);
+ if (a.json) { console.log(JSON.stringify({ scope, mode: 'apply', results: [{ kind: 'file-drift', ...result }] }, null, 2)); return; }
+ const lines = classApplyLines(result);
+ console.log(lines.join('\n'));
+}
+
export function renderRepairResult(result: RepairResult, opts: { diff: boolean } = { diff: false }): string {
const lines = [`${result.kind}: ${result.affected} item(s) ${result.mode === 'apply' ? 'pending before this run' : 'to repair'}`];
for (const warning of result.warnings ?? []) lines.push(` WARNING: ${warning}`);
@@ -551,7 +616,7 @@ export function renderRepairResult(result: RepairResult, opts: { diff: boolean }
export async function runRepairCommand(engine: BrainEngine, args: string[]): Promise<void> {
if (args.includes('--help') || args.includes('-h')) { console.log(REPAIR_HELP); return; }
const { kind, apply, all, json, noEmbed, includeAmbiguous, includeCrossEntity, source, expect, only, skip, slugs, diff, noLlm, maxUsd, limit: limitText,
- prefer, requests, allDrifted, driftClass, since, held, side, state, provenance, cursor, keep, requestId, olderThan, includeFailures, force, from, close, afterPage,
+ prefer, requests, allDrifted, driftClass, since, held, side, state, provenance, cursor, wholeClass, keep, requestId, olderThan, includeFailures, force, from, close, afterPage,
generationKind, generationMode, run, key, generation, day, rules, cwdPrefixes, sessions, principal, readers, slugsFile, allowWithoutOwner, propose, out,
classes, createdBefore, idsFile, undo } = parseRepairArgs(args);
if (kind === 'open-facts') {
@@ -592,6 +657,9 @@ export async function runRepairCommand(engine: BrainEngine, args: string[]): Pro
if (!kind && apply && !all) throw invalid('Name a kind or pass --all with --apply.',
'Review the preview of every automatic kind, then apply one by name (gbrain repair KIND --apply) or all of them with --all --apply.',
['gbrain', 'repair', ...(source ? ['--source', source] : []), '--json']);
+ if (kind === 'file-drift' && wholeClass) {
+ return runFileDriftClassCommand(engine, { apply, json, source, expect, only, skip, slugs, requests, allDrifted, held, side, state, provenance, cursor, prefer, args });
+ }
const kinds: RepairKind[] = kind ? [kind as RepairKind] : AUTO_REPAIR_REGISTRY.map(spec => spec.kind);
const explicitKindsNotRun = kind ? [] : explicitRepairNotices({ source });
const scope = await resolveRepairScope(engine, source);
diff --git a/src/commands/sources-add-api.ts b/src/commands/sources-add-api.ts
index 91866621d7..dde6368a7f 100644
--- a/src/commands/sources-add-api.ts
+++ b/src/commands/sources-add-api.ts
@@ -1,5 +1,5 @@
/**
- * `gbrain sources add <id> --kind meetings|slack` on an unmanaged brain (the default keyless install). These kinds use
+ * `gbrain sources add <id> --kind meetings|slack|imessage` on an unmanaged brain (the default keyless install). These kinds use
* the managed-lifecycle parser, so both paths accept exactly the same flags; a slack source is checked against Slack
* before it is registered, and --dry-run registers nothing.
*/
@@ -11,15 +11,16 @@ import { parseSourceLifecycleArgs } from './sources-lifecycle-args.ts';
export async function runApiSourceAdd(engine: BrainEngine, args: string[]): Promise<void> {
const { params } = parseSourceLifecycleArgs(['add', ...args]);
const opts = params.options as AddSourceOpts;
+ const kind = opts.slack ? 'slack' : opts.imessage ? 'imessage' : 'meetings';
if (params.dry_run === true) {
- console.log(`Dry run: would create ${opts.slack ? 'slack' : 'meetings'} source "${opts.id}"; nothing was registered.`);
+ console.log(`Dry run: would create ${kind} source "${opts.id}"; nothing was registered.`);
return;
}
if (opts.slack) await (await import('../core/slack/source-add.ts')).preflightSlackAdd(opts.id, opts.slack);
const created = await addSource(engine, opts);
const config = created.config as Record<string, unknown>;
- const record = opts.slack ? config.s_record : config.m_record;
- console.log(`Created ${opts.slack ? 'slack' : 'meetings'} source "${created.id}" (record: ${String(record)})${created.local_path ? ` → ${created.local_path}` : ''}`);
+ const record = opts.slack ? config.s_record : opts.imessage ? 'database' : config.m_record;
+ console.log(`Created ${kind} source "${created.id}" (record: ${String(record)})${created.local_path ? ` → ${created.local_path}` : ''}`);
console.log(` federated: ${isSourceFederated(created.config)}`);
console.log(` sync: run \`gbrain sync --source ${created.id}\` once; after its first sync, autopilot keeps it synced on its own interval.`);
}
diff --git a/src/commands/sources-lifecycle-args.ts b/src/commands/sources-lifecycle-args.ts
index 0d264381ed..f4487253b6 100644
--- a/src/commands/sources-lifecycle-args.ts
+++ b/src/commands/sources-lifecycle-args.ts
@@ -116,11 +116,14 @@ export function parseSourceLifecycleArgs(args: string[], generatedId = randomUUI
...Object.fromEntries(['account', 'access', 'token-command', 'services', 'future-days', 'loops-exclude-labels', 'contacts-dir', 'calendar-id'].map(key => [key, ['google']])),
...Object.fromEntries(['scope', 'repos', 'app-id', 'app-pem', 'app-install'].map(key => [key, ['github']])),
...Object.fromEntries(['provider', 'transcript'].map(key => [key, ['meetings']])),
- ...Object.fromEntries(['lookback-days', 'sync-interval-min', 'record', 'visibility'].map(key => [key, ['meetings', 'slack']])),
- ...Object.fromEntries(['channels', 'timezone', 'max-requests', 'skip'].map(key => [key, ['slack']])),
- 'history-days': ['google', 'meetings', 'slack'],
+ ...Object.fromEntries(['lookback-days', 'sync-interval-min'].map(key => [key, ['meetings', 'slack', 'imessage']])),
+ ...Object.fromEntries(['record', 'visibility'].map(key => [key, ['meetings', 'slack']])),
+ ...Object.fromEntries(['channels', 'max-requests', 'skip'].map(key => [key, ['slack']])),
+ timezone: ['slack', 'imessage'],
+ 'history-days': ['google', 'meetings', 'slack', 'imessage'],
'token-env': CONNECTOR_SOURCE_KINDS,
- dir: CONNECTOR_SOURCE_KINDS,
+ // An imessage source is always database-recorded: its message text never reaches a directory.
+ dir: CONNECTOR_SOURCE_KINDS.filter(k => k !== 'imessage'),
};
for (const [key, kinds] of Object.entries(optionKinds)) {
if (!values.has(key)) continue;
@@ -216,6 +219,13 @@ export function parseSourceLifecycleArgs(args: string[], generatedId = randomUUI
opts.slack = { channels, ...recordFlags('Slack page', 'pages of private channels'), ...(values.has('timezone') ? { timezone } : {}),
...(maxRequests !== undefined ? { maxRequests } : {}), ...(skip.length ? { skip: skip as SlackSkippable[] } : {}) };
}
+ if (kind === 'imessage') {
+ const timezone = values.get('timezone') ?? 'UTC';
+ if (!isValidTimeZone(timezone)) throw invalid('--timezone must be an IANA time zone.', 'Pass --timezone as an IANA zone name such as UTC or America/Los_Angeles; a day page starts at midnight there.');
+ const interval = number('sync-interval-min');
+ opts.imessage = { historyDays: number('history-days'), lookbackDays: number('lookback-days'), ...(values.has('timezone') ? { timezone } : {}),
+ ...(interval !== undefined ? { syncIntervalMin: interval } : {}), ...(values.has('token-env') ? { tokenEnv: values.get('token-env') } : {}) };
+ }
return { operation: 'source_add', params: { options: opts, request_id: requestId, ...(dryRun ? { dry_run: true } : {}) },
brain: values.get('brain'), legacyOnly: values.has('pat-file'), json: flags.has('json') };
}
diff --git a/src/commands/sources-lifecycle.ts b/src/commands/sources-lifecycle.ts
index 8ba18ff0ba..e91e182990 100644
--- a/src/commands/sources-lifecycle.ts
+++ b/src/commands/sources-lifecycle.ts
@@ -16,7 +16,7 @@ import { adminHostConfig } from './persistence-admin.ts';
import type { AddSourceOpts } from '../core/sources-ops.ts';
export const SOURCE_LIFECYCLE_HELP = `Managed source administration:
- gbrain sources add <id> [--path <directory> | --url <https-url> | --kind github|google|meetings|slack]
+ gbrain sources add <id> [--path <directory> | --url <https-url> | --kind github|google|meetings|slack|imessage]
gbrain sources archive <id>
gbrain sources restore <id> [--no-federate]
gbrain sources remove <id> --confirm-destructive
diff --git a/src/commands/sources.ts b/src/commands/sources.ts
index 007aa439ca..35a3c62e4f 100644
--- a/src/commands/sources.ts
+++ b/src/commands/sources.ts
@@ -148,11 +148,11 @@ async function countPages(engine: BrainEngine, sourceId: string): Promise<number
async function runAdd(engine: BrainEngine, args: string[]): Promise<void> {
const apiKind = args.includes('--kind') ? args[args.indexOf('--kind') + 1] : undefined;
- if (args[0] && (apiKind === 'meetings' || apiKind === 'slack')) return (await import('./sources-add-api.ts')).runApiSourceAdd(engine, args);
+ if (args[0] && (apiKind === 'meetings' || apiKind === 'slack' || apiKind === 'imessage')) return (await import('./sources-add-api.ts')).runApiSourceAdd(engine, args);
const id = args[0];
if (!id) {
console.error(
- 'Usage: gbrain sources add <id> [--path <path> | --url <https-url> | --kind github|google|meetings|slack] ' +
+ 'Usage: gbrain sources add <id> [--path <path> | --url <https-url> | --kind github|google|meetings|slack|imessage] ' +
'[--name <display>] [--federated|--no-federated] [--clone-dir <path>] [--force] [--json]\n' +
' github kind: [--token-env <env>] [--scope auto|repos] ' +
'[--repos owner/name,...] [--dir <path>] ' +
diff --git a/src/commands/sync/connector.ts b/src/commands/sync/connector.ts
index e2b0d769f5..dec8a2f6cf 100644
--- a/src/commands/sync/connector.ts
+++ b/src/commands/sync/connector.ts
@@ -55,6 +55,11 @@ async function runConnectorKind(engine: BrainEngine, sourceId: string, config: R
const { runSlackSync } = await import('../../core/slack/slack-source.ts');
return runSlackSync(engine, sourceId, parseSlackSourceConfig(config, fallbackDir), options);
}
+ case 'imessage': {
+ const { parseIMessageSourceConfig } = await import('../../core/imessage/source-config.ts');
+ const { runIMessageSync } = await import('../../core/imessage/imessage-source.ts');
+ return runIMessageSync(engine, sourceId, parseIMessageSourceConfig(config), options);
+ }
default: return assertNever(config.kind);
}
}
diff --git a/src/core/access/owner-only.ts b/src/core/access/owner-only.ts
new file mode 100644
index 0000000000..25f027808f
--- /dev/null
+++ b/src/core/access/owner-only.ts
@@ -0,0 +1,102 @@
+/**
+ * Owner-only sources (`owner_only`). A source whose `sources.config` carries `owner_only: true`, and every source of a
+ * kind that is always owner-only (`imessage`: other people's messages on the owner's Mac), is read only by the trusted
+ * local CLI and by a credential bound to the brain owner speaking for itself (CallerAccess.owner). Every other remote
+ * caller (another member, a guest, a shared-room audience, an attested call, an unbound or public credential) gets
+ * exactly what a page that does not exist gets, whatever the operator relaxed: `--private-pages granted-sources`, the
+ * `search.remote_private_pages` hatch, `access.members_read_lineage` and the owner opt-in widen nothing here.
+ *
+ * The rule follows lineage at read time and stores nothing per page, so it needs no backfill and works the same on a
+ * repo-less brain: a page or fact in an owner-only source, a synthesized concept or question with an input page there,
+ * and any page or fact whose recorded derivation inputs (`derivation_inputs`, followed transitively) reach a page,
+ * fact, take or timeline row there. Atoms, Life Chronicle events and `derived_from` pages resolve their origin in their
+ * own source, so the source test covers them. The test is the v320 function gbrain_owner_only_lineage(table, id), behind
+ * its zero-argument form (does the brain hold an owner-only source at all?), so a brain without one never calls it.
+ */
+import type { BrainEngine } from '../engine.ts';
+
+/** The `sources.config` flag that makes a source owner-only. */
+export const OWNER_ONLY_FLAG = 'owner_only';
+/** Source kinds that are owner-only whatever their flag says. */
+export const OWNER_ONLY_KINDS: readonly string[] = ['imessage'];
+
+/** A `sources` row alias is owner-only (the SQL twin of isOwnerOnlySourceConfig). */
+function ownerOnlySourceRowSql(alias: string): string {
+ return `(${alias}.config->>'kind' IN (${OWNER_ONLY_KINDS.map(kind => `'${kind}'`).join(',')}) OR ${alias}.config->>'${OWNER_ONLY_FLAG}' = 'true')`;
+}
+
+/**
+ * Does the brain hold an owner-only source? Uncorrelated, so a statement evaluates it once. Like search's other live read
+ * checks (search/read-policy-sql.ts, guests/marker.ts) it reads sources as `read_source`: a read check, not a listing.
+ * `id >= ''` holds for every row; it gives the planner the primary key as a path (a NOT NULL test would be folded away),
+ * so a plan that prices out sequential scans still reads sources by index.
+ */
+export const ANY_OWNER_ONLY_SQL = `EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND ${ownerOnlySourceRowSql('read_source')})`;
+
+/** The source whose id is the SQL expression `sourceId` is owner-only (the SQL twin of sourceIsOwnerOnly). */
+export function ownerOnlySourceSql(sourceId: string): string {
+ return `EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id = ${sourceId} AND ${ownerOnlySourceRowSql('read_source')})`;
+}
+
+/** A parsed `sources.config` is owner-only. */
+export function isOwnerOnlySourceConfig(config: unknown): boolean {
+ const value = typeof config === 'string' ? safeParse(config) : config;
+ if (!value || typeof value !== 'object') return false;
+ const record = value as Record<string, unknown>;
+ return OWNER_ONLY_KINDS.includes(String(record.kind)) || record[OWNER_ONLY_FLAG] === true || record[OWNER_ONLY_FLAG] === 'true';
+}
+
+function safeParse(text: string): unknown {
+ try { return JSON.parse(text); } catch { return null; }
+}
+
+/** Does the brain hold an owner-only source? An unreadable answer counts as yes (fail closed). */
+export async function ownerOnlySourcesPresent(engine: Pick<BrainEngine, 'executeRaw'>): Promise<boolean> {
+ try {
+ const [row] = await engine.executeRaw<{ present: boolean }>(`SELECT ${ANY_OWNER_ONLY_SQL} AS present`);
+ return row?.present !== false;
+ } catch {
+ return true;
+ }
+}
+
+/** Is this source owner-only? An unreadable answer counts as yes (fail closed). */
+export async function sourceIsOwnerOnly(engine: Pick<BrainEngine, 'executeRaw'>, sourceId: string): Promise<boolean> {
+ try {
+ const rows = await engine.executeRaw<{ config: unknown }>('SELECT config FROM sources WHERE id = $1', [sourceId]);
+ return rows.length > 0 && isOwnerOnlySourceConfig(rows[0]!.config);
+ } catch {
+ return true;
+ }
+}
+
+/** The read-time function (schema migration v320) that answers whether a page or fact row is owner-only. */
+export const OWNER_ONLY_LINEAGE_FN = 'gbrain_owner_only_lineage';
+/** The schema version (migration v320) that creates it; a literal so a read never loads a migration module. */
+export const OWNER_ONLY_LINEAGE_SINCE = 320;
+
+/**
+ * Which form of the owner-only test a read emits, by its schema version. `fn` at or above OWNER_ONLY_LINEAGE_SINCE: the
+ * v320 functions, so the planner sees the guard as one Result node and the test as one call that the guard keeps from
+ * running on a brain with no owner-only source. `closed` below it or when the version is unknown: the functions may not
+ * exist, so on a brain that holds an owner-only source every row counts as owner-only (fail closed); a brain without one
+ * pays one InitPlan. Remote reads carry the version in their request record, so they take the `fn` form.
+ */
+export type OwnerOnlyForm = 'fn' | 'closed';
+
+export function ownerOnlyForm(schemaVersion: number | undefined): OwnerOnlyForm {
+ return schemaVersion !== undefined && schemaVersion >= OWNER_ONLY_LINEAGE_SINCE ? 'fn' : 'closed';
+}
+
+/**
+ * The page row `alias` is owner-only: held in an owner-only source, a synthesized concept or question with an input page
+ * there, or derived (by its recorded inputs, up to 8 hops) from a row there. `alias` is a code-provided literal.
+ */
+export function ownerOnlyPageSql(alias: string, form: OwnerOnlyForm): string {
+ return form === 'fn' ? `((SELECT ${OWNER_ONLY_LINEAGE_FN}()) AND ${OWNER_ONLY_LINEAGE_FN}('pages', ${alias}.id))` : ANY_OWNER_ONLY_SQL;
+}
+
+/** The fact row `alias` is owner-only: held in an owner-only source, or derived (by its recorded inputs) from a row there. */
+export function ownerOnlyFactSql(alias: string, form: OwnerOnlyForm): string {
+ return form === 'fn' ? `((SELECT ${OWNER_ONLY_LINEAGE_FN}()) AND ${OWNER_ONLY_LINEAGE_FN}('facts', ${alias}.id))` : ANY_OWNER_ONLY_SQL;
+}
diff --git a/src/core/access/policy-git.ts b/src/core/access/policy-git.ts
index 04bc1be837..3a18a37446 100644
--- a/src/core/access/policy-git.ts
+++ b/src/core/access/policy-git.ts
@@ -250,6 +250,13 @@ export async function commitPolicyFile(root: string, relPath: string, edit: (cur
if (e instanceof OperationError && (e.code === 'push_unconfirmed' || (e as { canonical?: string }).canonical === 'push_unconfirmed') && e.detail) {
return { outcome: 'committed_not_pushed', commit: String(e.detail), path: relPath, note: 'Committed locally; the push is unconfirmed. Rerun gbrain git commit-push --push-only --scan-secrets to publish it.' };
}
+ if (e instanceof OperationError && e.code === 'push_credential_refused' && gitShow(root, 'HEAD', relPath) === next) {
+ let commit: string | null = null;
+ try { commit = String(JSON.parse(String(e.detail ?? '{}')).commit ?? '') || null; } catch { /* fall back to HEAD */ }
+ commit ??= spawnSync('git', ['rev-parse', 'HEAD'], { cwd: root, encoding: 'utf8', env: gitChildEnv() }).stdout.trim() || null;
+ return { outcome: 'committed_not_pushed', commit, path: relPath,
+ note: `Committed locally; nothing was pushed. ${e.code}: ${e.message} Fix: ${e.suggestion}` };
+ }
if (e instanceof OperationError && (e.code === 'publish_secret_found' || e.code === 'publish_scan_unreadable') && gitShow(root, 'HEAD', relPath) === next) {
const head = spawnSync('git', ['rev-parse', 'HEAD'], { cwd: root, encoding: 'utf8', env: gitChildEnv() }).stdout.trim();
return { outcome: 'committed_not_pushed', commit: head || null, path: relPath,
diff --git a/src/core/apple/helper-client.ts b/src/core/apple/helper-client.ts
new file mode 100644
index 0000000000..94e08150e1
--- /dev/null
+++ b/src/core/apple/helper-client.ts
@@ -0,0 +1,159 @@
+/**
+ * The GBrain Helper's iMessage routes, read over 127.0.0.1 only: `GET /v1/imessage/threads` (recent chats) and
+ * `GET /v1/imessage/thread` (one chat's messages after a cursor). The token travels as a bearer header, never in a
+ * query string. Failures map to the helper's own codes: nothing listening (`apple_helper_not_running`), a token the
+ * helper refuses (`apple_helper_unauthorized`), Full Disk Access off (`apple_full_disk_access_pending`) and a Messages
+ * database macOS changed (`apple_schema_mismatch`); each stops the whole run. Any other refusal is an item error.
+ */
+import { OperationError } from '../ops/contract.ts';
+import { ConnectorHttpError, ConnectorResponseTooLargeError, type ConnectorFetch } from '../connectors/client.ts';
+import type { IMessageMessage, IMessageThread } from '../imessage/types.ts';
+
+/** Chats listed per run, most recent first (the helper's own maximum). */
+export const IMESSAGE_THREADS_LIMIT = 200;
+const MESSAGES_PAGE = 500;
+/** Cursor pages one chat may walk in a run before the run stops partial. */
+const MAX_PAGES = 200;
+const MAX_RESPONSE_BYTES = 32 * 1024 * 1024;
+const REQUEST_TIMEOUT_MS = 30_000;
+
+/** A helper response missing a field it must carry: the chat is held, never published partially. */
+export class IMessageShapeDriftError extends Error {
+ readonly code = 'connector_shape_drift';
+ constructor(what: string) {
+ super(`imessage: the helper response is missing ${what}; the helper and gbrain may be out of step`);
+ this.name = 'IMessageShapeDriftError';
+ }
+}
+
+const DOCS = 'docs/guides/apple-setup.md';
+
+export function helperNotRunning(sourceId: string, port: number | null, detail: string): OperationError {
+ return new OperationError('apple_helper_not_running',
+ port === null ? `iMessage source ${sourceId} has no helper port configured (${detail}). Nothing was imported.`
+ : `Nothing answered on 127.0.0.1:${port} for iMessage source ${sourceId} (${detail}). The helper is stopped or the Mac is asleep. Nothing was imported.`,
+ `Start GBrain Helper on this Mac and check that gbrain config get apple.helper.port names its port, then run: gbrain sync --source ${sourceId}`,
+ `${DOCS}#apple_helper_not_running`);
+}
+
+function helperUnauthorized(sourceId: string): OperationError {
+ return new OperationError('apple_helper_unauthorized', `GBrain Helper refused the token for iMessage source ${sourceId}. Nothing was imported.`,
+ `Save the helper's current token for gbrain (the 0600 file ~/.gbrain/connectors/imessage.json, or the source's token variable), then run: gbrain sync --source ${sourceId}`,
+ `${DOCS}#apple_helper_unauthorized`);
+}
+
+function fullDiskAccessPending(sourceId: string): OperationError {
+ return new OperationError('apple_full_disk_access_pending', `GBrain Helper cannot read Messages for iMessage source ${sourceId}: Full Disk Access is off. Nothing was imported.`,
+ `Ask the user to open System Settings > Privacy & Security > Full Disk Access and switch on GBrain Helper, then run: gbrain sync --source ${sourceId}`,
+ `${DOCS}#apple_full_disk_access_pending`);
+}
+
+function schemaMismatch(sourceId: string): OperationError {
+ return new OperationError('apple_schema_mismatch', `GBrain Helper does not recognise the Messages database for iMessage source ${sourceId}; macOS may have changed it. Nothing was imported.`,
+ `Update GBrain and the GBrain Helper to their newest versions, then run: gbrain sync --source ${sourceId}`,
+ `${DOCS}#apple_schema_mismatch`);
+}
+
+const str = (value: unknown): string | null => (typeof value === 'string' && value.length > 0 ? value : null);
+
+export interface IMessageHelperOpts {
+ sourceId: string;
+ port: number;
+ token: string;
+ fetchImpl?: ConnectorFetch;
+}
+
+export interface IMessageHelper {
+ threads(signal?: AbortSignal): Promise<IMessageThread[]>;
+ /** Every message of one chat at or after `sinceIso`, oldest first. */
+ messages(threadId: string, sinceIso: string, signal?: AbortSignal): Promise<IMessageMessage[]>;
+}
+
+export function imessageHelper(opts: IMessageHelperOpts): IMessageHelper {
+ const fetchImpl = opts.fetchImpl ?? (fetch as unknown as ConnectorFetch);
+ const base = `http://127.0.0.1:${opts.port}`;
+ async function get(path: string, params: Record<string, string>, signal?: AbortSignal): Promise<Record<string, unknown>> {
+ const url = `${base}${path}?${new URLSearchParams(params).toString()}`;
+ const timeout = AbortSignal.timeout(REQUEST_TIMEOUT_MS);
+ let res: Response;
+ try {
+ res = await fetchImpl(url, { method: 'GET', headers: { authorization: `Bearer ${opts.token}`, accept: 'application/json' },
+ redirect: 'manual', signal: signal ? AbortSignal.any([signal, timeout]) : timeout });
+ } catch (error) {
+ if (signal?.aborted) throw error;
+ throw helperNotRunning(opts.sourceId, opts.port, error instanceof Error ? error.message : String(error));
+ }
+ const text = await readBounded(res, path);
+ let body: Record<string, unknown> = {};
+ try { body = text ? JSON.parse(text) as Record<string, unknown> : {}; } catch { body = {}; }
+ if (res.ok) return body;
+ const code = str(body.code) ?? str((body.type as string | undefined)?.split('/').pop());
+ if (res.status === 401 || code === 'unauthorized' || code === 'insufficient_scope') throw helperUnauthorized(opts.sourceId);
+ if (code === 'source_disabled') throw helperNotRunning(opts.sourceId, opts.port, 'the helper has its iMessage source turned off');
+ if (code === 'no_access') throw fullDiskAccessPending(opts.sourceId);
+ if (code === 'schema_mismatch') throw schemaMismatch(opts.sourceId);
+ throw new ConnectorHttpError(`imessage: the helper answered ${res.status}${code ? ` (${code})` : ''} for ${path}`, res.status);
+ }
+ return {
+ async threads(signal) {
+ const body = await get('/v1/imessage/threads', { limit: String(IMESSAGE_THREADS_LIMIT) }, signal);
+ if (!Array.isArray(body.data)) throw new IMessageShapeDriftError('threads.data');
+ return body.data.map((raw: Record<string, unknown>) => {
+ const threadId = str(raw?.thread_id);
+ if (!threadId) throw new IMessageShapeDriftError('threads.data[].thread_id');
+ const lastMessageAt = raw.last_message_at ?? null;
+ if (lastMessageAt !== null && !(typeof lastMessageAt === 'string' && Number.isFinite(Date.parse(lastMessageAt)))) {
+ throw new IMessageShapeDriftError('threads.data[].last_message_at');
+ }
+ return { threadId, displayName: str(raw.display_name), participants: Array.isArray(raw.participants) ? raw.participants.filter((p): p is string => typeof p === 'string') : [],
+ isGroup: raw.is_group === true, lastMessageAt };
+ });
+ },
+ async messages(threadId, sinceIso, signal) {
+ const out: IMessageMessage[] = [];
+ let cursor: string | null = null;
+ for (let page = 0; page < MAX_PAGES; page++) {
+ const body = await get('/v1/imessage/thread', { thread_id: threadId, limit: String(MESSAGES_PAGE),
+ ...(cursor ? { since_rowid: cursor } : { since_iso: sinceIso }) }, signal);
+ const data = body.data as Record<string, unknown> | undefined;
+ if (!data || !Array.isArray(data.messages)) throw new IMessageShapeDriftError('thread.data.messages');
+ for (const raw of data.messages as Record<string, unknown>[]) out.push(parseMessage(raw));
+ const meta = (body.meta ?? {}) as Record<string, unknown>;
+ const more = data.has_more ?? meta.has_more;
+ const next = data.next_since_rowid ?? meta.next_since_rowid;
+ if (more !== true) return out.filter(m => m.timestamp >= sinceIso).sort((a, b) => a.timestamp.localeCompare(b.timestamp) || a.rowid - b.rowid);
+ if (typeof next !== 'number' && typeof next !== 'string') throw new IMessageShapeDriftError('thread.next_since_rowid');
+ cursor = String(next);
+ }
+ throw new ConnectorHttpError(`imessage: one chat returned more than ${MAX_PAGES} pages`, 500);
+ },
+ };
+}
+
+function parseMessage(raw: Record<string, unknown>): IMessageMessage {
+ const id = str(raw?.id);
+ const timestamp = str(raw?.timestamp);
+ const rowid = Number(raw?.rowid);
+ if (!id || !timestamp || !Number.isFinite(Date.parse(timestamp)) || !Number.isSafeInteger(rowid)) throw new IMessageShapeDriftError('thread.data.messages[] id, rowid or timestamp');
+ const status = raw.text_status === 'empty' || raw.text_status === 'undecodable' ? raw.text_status : 'ok';
+ return { id, rowid, timestamp: new Date(timestamp).toISOString(), isFromMe: raw.is_from_me === true, text: typeof raw.text === 'string' ? raw.text : null,
+ textStatus: status, from: str(raw.from), hasAttachments: raw.has_attachments === true, editedAt: str(raw.edited_at), retracted: raw.retracted === true };
+}
+
+async function readBounded(res: Response, path: string): Promise<string> {
+ if (!res.body) return res.text();
+ const reader = res.body.getReader();
+ const chunks: Uint8Array[] = [];
+ let size = 0;
+ for (;;) {
+ const { done, value } = await reader.read();
+ if (done) break;
+ size += value.byteLength;
+ if (size > MAX_RESPONSE_BYTES) {
+ await reader.cancel().catch(() => {});
+ throw new ConnectorResponseTooLargeError(path, MAX_RESPONSE_BYTES);
+ }
+ chunks.push(value);
+ }
+ return new TextDecoder().decode(Buffer.concat(chunks));
+}
diff --git a/src/core/brain-repo-durability.ts b/src/core/brain-repo-durability.ts
index cbef3d1711..9e977be4d5 100644
--- a/src/core/brain-repo-durability.ts
+++ b/src/core/brain-repo-durability.ts
@@ -50,7 +50,7 @@ import { readFix } from './ops/op-fix.ts';
// don't ship their own — see resolveFilingRules().
import filingRulesDoc from '../../skills/_brain-filing-rules.json';
import { GIT_PATHSPEC_ENV_VARS, gitChildEnv } from './git-env.ts';
-import { commitAndPush, commitPathsLocked, readIntegrateConflict, SOURCE_ROOT_CONFIG } from './git/commit-push.ts';
+import { commitAndPush, commitPathsLocked, readCredentialRefusal, readIntegrateConflict, SOURCE_ROOT_CONFIG } from './git/commit-push.ts';
import { relativeEscapesRoot } from './path-confine.ts';
export { execFileBounded, type BoundedExecOptions } from './bounded-child-exec.ts';
@@ -785,6 +785,12 @@ export function getLastPushOutcome(branch: string, repo?: string): PushLogOutcom
return { status: 'needs_attention', at: conflict.at,
detail: `unresolved integrate_conflict on ${branch} (${conflict.paths.join(', ')}): run gbrain git commit-push --push-only --expect-remote ${String(conflict.remote).slice(0, 12)} --resolve <path>=ours|theirs` };
}
+ const refused = repo ? readCredentialRefusal(repo) : null;
+ if (refused) {
+ const answered = refused.helpers.find(h => h.answered);
+ return { status: 'needs_attention', at: refused.at,
+ detail: `push_credential_refused since ${refused.since}: ${refused.url} refused the credential git used (${refused.kind === 'not_found' ? 'repository not found, HTTP 404' : 'HTTP 403'}${answered ? `, from ${answered.helper} (${answered.scope ?? 'scope unknown'})${refused.username ? ` for ${refused.username}` : ''}` : ''}); fix the credential, then run gbrain git commit-push --push-only` };
+ }
const log = pushLogPath();
if (!existsSync(log)) return { status: 'unknown', detail: 'no push attempts logged yet' };
diff --git a/src/core/cli-flag-registry.generated.ts b/src/core/cli-flag-registry.generated.ts
index 554b60316e..26253e59b4 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', '--concurrency', '--db-url', '--dry-run', '--explain', '--filter', '--follow', '--force', '--force-retry', '--format', '--help', '--http', '--json', '--legacy-lock', '--locks', '--name', '--no-accept-pending', '--only', '--path', '--prefer-postgres', '--probe', '--progress-interval', '--progress-json', '--quiet', '--remediate', '--restart', '--room', '--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', '--filter', '--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', '--patch', '--path', '--phase', '--prefer', '--preview', '--privacy-url', '--purge', '--query', '--recent', '--refresh-operations', '--replace', '--restart-only', '--reverse', '--row', '--scopes', '--session', '--since', '--slug', '--slugs', '--source', '--source-id', '--sources', '--stale', '--surface', '--terms-url', '--to', '--updated-after', '--url', '--yes'],
- 'doctor': ['--abandon', '--abbrev-ref', '--abort', '--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', '--agent', '--aggressive', '--alert', '--aliases', '--all', '--all-drifted', '--all-from', '--all-sources', '--allow-old-serve', '--allow-outside-source-root', '--allow-shell-jobs', '--allow-unverified-remote', '--allow-without-owner', '--allowed-operations', '--anchor', '--applied', '--apply', '--apply-rewrites', '--approval-out', '--approved', '--as', '--assign-corpus', '--assume-unchanged', '--attest-actor', '--attest-ops', '--attest-read', '--attest-sources', '--audit', '--auto', '--auto-additive', '--auto-fix', '--autostash', '--background', '--base', '--batch', '--batch-check', '--body', '--bound-brain', '--bound-max-concurrent', '--bound-slug-prefixes', '--bound-source', '--bound-tools', '--brain', '--branch', '--break-lock', '--budget-ms', '--budget-policy', '--budget-tokens', '--budget-usd', '--bundled', '--by-mention', '--cached', '--cacheinfo', '--call-site', '--calls', '--catalog', '--catch-up', '--channel', '--check', '--check-downgrade', '--check-only', '--cherry-mark', '--claims', '--class', '--claude-plugins', '--clear', '--clear-never-installed', '--cli-socket', '--client', '--close', '--code', '--concurrency', '--concurrent', '--confidence', '--config', '--confirm', '--confirm-destructive', '--confirm-quiesced', '--confirm-relocated-root', '--conflicts', '--contacts-dir', '--content-audit', '--content-root', '--continue', '--conversation', '--count', '--created-before', '--credentials-file', '--cursor', '--cwd', '--dataset', '--day', '--days', '--db-url', '--dbname', '--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', '--email', '--embedding-dimensions', '--embedding-model', '--enable', '--enable-dcr', '--end-of-options', '--entity', '--env', '--env-file', '--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', '--filter', '--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-json', '--from-meetings', '--from-pages', '--from-prefix', '--full', '--full-tree', '--fuzzy', '--gbrain-bin', '--gbrain-skill-resolver', '--generation', '--get', '--get-all', '--get-regexp', '--get-url', '--git-common-dir', '--git-dir', '--git-path', '--grammar', '--group', '--group-by', '--hard', '--hard-deadline', '--harness', '--heads', '--held', '--help', '--history', '--hold-state', '--holds', '--home', '--http', '--id', '--ids-file', '--if-version', '--ignore-env-override', '--ignore-missing', '--ignore-unmatch', '--images', '--import', '--include-ambiguous', '--include-covered', '--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', '--input-type', '--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', '--label-lowerings', '--labelled-only', '--lanes', '--lang', '--left-right', '--legacy-lock', '--limit', '--link', '--link-source', '--link-type', '--list', '--list-out', '--local', '--local-env-vars', '--locks', '--log-noop', '--manifest', '--markdown', '--max-age', '--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', '--members', '--members-file', '--merge-base', '--migrate-legacy', '--migrate-only', '--migration', '--min', '--min-n', '--mode', '--model', '--multimodal', '--name', '--name-only', '--name-status', '--nice', '--no-accept-pending', '--no-assume-unchanged', '--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-extensions', '--no-extract', '--no-federated', '--no-filters', '--no-follow-tags', '--no-gpg-sign', '--no-hooks', '--no-instructions', '--no-lanes', '--no-llm', '--no-merges', '--no-migrate', '--no-open-pages', '--no-owner', '--no-probe', '--no-pull', '--no-renames', '--no-repair', '--no-restart', '--no-schema-pack', '--no-seat', '--no-skip-worktree', '--no-stdio-member', '--no-tags', '--no-verify', '--no-walk', '--no-write-fetch-head', '--non-interactive', '--not', '--now', '--of', '--older-than', '--once', '--only', '--open-history', '--operation', '--operations', '--others', '--out', '--output', '--oversized', '--overwrite', '--owner', '--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', '--preload', '--preset', '--preview', '--principal', '--priority', '--privacy-url', '--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', '--raw-only', '--read-sources', '--reader-mode', '--readers', '--reads-unscoped', '--reason', '--reauth', '--rebase', '--rebuild', '--recommended', '--recurse-submodules', '--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', '--require-clean', '--reranker', '--reset', '--reset-checkpoint', '--reset-default', '--reset-session', '--resolve', '--restart-only', '--restore-only', '--resume', '--retire', '--retry-failed', '--retry-global', '--retry-held', '--retry-parked', '--reverse', '--review-lower', '--revision', '--right-only', '--rollback-to-source', '--room', '--root', '--routing', '--rules', '--run', '--runtime', '--safe', '--sample', '--save', '--scan-secrets', '--scan-timeout', '--schedule', '--scope', '--scopes', '--search-mode', '--seat', '--section', '--segmented', '--select', '--self-transfer', '--semantic', '--serves', '--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', '--skip-worktree', '--slot', '--slot-a-model', '--slot-b-model', '--slot-c-model', '--slug', '--slugs', '--slugs-file', '--source', '--source-id', '--source-ids', '--sources', '--squash', '--src-subpath', '--staged', '--stale', '--stat', '--state', '--statement-timeout', '--status', '--stdin', '--stdio-member', '--stop-mcp', '--strategy', '--strict', '--strict-json', '--suite', '--supabase', '--surface', '--swap-only', '--symbol-kind', '--symbolic-full-name', '--synopsis', '--tags', '--take', '--takes-holders', '--target', '--target-score', '--terms-url', '--threshold', '--tier', '--timeout', '--timings', '--to', '--token', '--token-ttl', '--top-k', '--topo-order', '--trust', '--tsconfig-override', '--type', '--types', '--unattended', '--undo', '--unindexed', '--uninstall', '--unsafe-bypass-dream-guard', '--unschedule', '--unset', '--unset-all', '--unsettle', '--unshallow', '--untrack', '--untracked-files', '--url', '--url-env', '--user', '--vacuum', '--vectors', '--verbose', '--verify', '--version', '--wait', '--wait-drain', '--wakeshift', '--warn-only', '--watch', '--what-if-threshold', '--where', '--window', '--workers', '--working-tree', '--workspace', '--worktree', '--write-tree', '--yes'],
+ 'doctor': ['--abandon', '--abbrev-ref', '--abort', '--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', '--agent', '--aggressive', '--alert', '--aliases', '--all', '--all-drifted', '--all-from', '--all-sources', '--allow-old-serve', '--allow-outside-source-root', '--allow-shell-jobs', '--allow-unverified-remote', '--allow-without-owner', '--allowed-operations', '--anchor', '--applied', '--apply', '--apply-rewrites', '--approval-out', '--approved', '--as', '--assign-corpus', '--assume-unchanged', '--attest-actor', '--attest-ops', '--attest-read', '--attest-sources', '--audit', '--auto', '--auto-additive', '--auto-fix', '--autostash', '--background', '--base', '--batch', '--batch-check', '--body', '--bound-brain', '--bound-max-concurrent', '--bound-slug-prefixes', '--bound-source', '--bound-tools', '--brain', '--branch', '--break-lock', '--budget-ms', '--budget-policy', '--budget-tokens', '--budget-usd', '--bundled', '--by-mention', '--cached', '--cacheinfo', '--call-site', '--calls', '--catalog', '--catch-up', '--channel', '--check', '--check-downgrade', '--check-only', '--cherry-mark', '--claims', '--class', '--claude-plugins', '--clear', '--clear-never-installed', '--cli-socket', '--client', '--close', '--code', '--concurrency', '--concurrent', '--confidence', '--config', '--confirm', '--confirm-destructive', '--confirm-quiesced', '--confirm-relocated-root', '--conflicts', '--contacts-dir', '--content-audit', '--content-root', '--continue', '--conversation', '--count', '--created-before', '--credentials-file', '--cursor', '--cwd', '--dataset', '--day', '--days', '--db-url', '--dbname', '--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', '--email', '--embedding-dimensions', '--embedding-model', '--enable', '--enable-dcr', '--end-of-options', '--entity', '--env', '--env-file', '--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', '--filter', '--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-json', '--from-meetings', '--from-pages', '--from-prefix', '--full', '--full-tree', '--fuzzy', '--gbrain-bin', '--gbrain-skill-resolver', '--generation', '--get', '--get-all', '--get-regexp', '--get-url', '--git-common-dir', '--git-dir', '--git-path', '--grammar', '--group', '--group-by', '--hard', '--hard-deadline', '--harness', '--heads', '--held', '--help', '--history', '--hold-state', '--holds', '--home', '--http', '--id', '--ids-file', '--if-version', '--ignore-env-override', '--ignore-missing', '--ignore-unmatch', '--images', '--import', '--include-ambiguous', '--include-covered', '--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', '--input-type', '--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', '--label-lowerings', '--labelled-only', '--lanes', '--lang', '--left-right', '--legacy-lock', '--limit', '--link', '--link-source', '--link-type', '--list', '--list-out', '--local', '--local-env-vars', '--locks', '--log-noop', '--manifest', '--markdown', '--max-age', '--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', '--members', '--members-file', '--merge-base', '--migrate-legacy', '--migrate-only', '--migration', '--min', '--min-n', '--mode', '--model', '--multimodal', '--name', '--name-only', '--name-status', '--nice', '--no-accept-pending', '--no-assume-unchanged', '--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-extensions', '--no-extract', '--no-federated', '--no-filters', '--no-follow-tags', '--no-gpg-sign', '--no-hooks', '--no-instructions', '--no-lanes', '--no-llm', '--no-merges', '--no-migrate', '--no-open-pages', '--no-owner', '--no-probe', '--no-pull', '--no-renames', '--no-repair', '--no-restart', '--no-schema-pack', '--no-seat', '--no-skip-worktree', '--no-stdio-member', '--no-tags', '--no-verify', '--no-walk', '--no-write-fetch-head', '--non-interactive', '--not', '--now', '--of', '--older-than', '--once', '--only', '--open-history', '--operation', '--operations', '--others', '--out', '--output', '--oversized', '--overwrite', '--owner', '--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', '--preload', '--preset', '--preview', '--principal', '--priority', '--privacy-url', '--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', '--raw-only', '--read-sources', '--reader-mode', '--readers', '--reads-unscoped', '--reason', '--reauth', '--rebase', '--rebuild', '--recommended', '--recurse-submodules', '--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', '--require-clean', '--reranker', '--reset', '--reset-checkpoint', '--reset-default', '--reset-session', '--resolve', '--restart-only', '--restore-only', '--resume', '--retire', '--retry-failed', '--retry-global', '--retry-held', '--retry-parked', '--reverse', '--review-lower', '--revision', '--right-only', '--rollback-to-source', '--room', '--root', '--routing', '--rules', '--run', '--runtime', '--safe', '--sample', '--save', '--scan-secrets', '--scan-timeout', '--schedule', '--scope', '--scopes', '--search-mode', '--seat', '--section', '--segmented', '--select', '--self-transfer', '--semantic', '--serves', '--session', '--session-id', '--set', '--set-upstream-to', '--shadow', '--shared-skills', '--short', '--show-current', '--show-object-format', '--show-origin', '--show-prefix', '--show-scope', '--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', '--skip-worktree', '--slot', '--slot-a-model', '--slot-b-model', '--slot-c-model', '--slug', '--slugs', '--slugs-file', '--source', '--source-id', '--source-ids', '--sources', '--squash', '--src-subpath', '--staged', '--stale', '--stat', '--state', '--statement-timeout', '--status', '--stdin', '--stdio-member', '--stop-mcp', '--strategy', '--strict', '--strict-json', '--suite', '--supabase', '--surface', '--swap-only', '--symbol-kind', '--symbolic-full-name', '--synopsis', '--tags', '--take', '--takes-holders', '--target', '--target-score', '--terms-url', '--threshold', '--tier', '--timeout', '--timings', '--to', '--token', '--token-ttl', '--top-k', '--topo-order', '--trust', '--tsconfig-override', '--type', '--types', '--unattended', '--undo', '--unindexed', '--uninstall', '--unsafe-bypass-dream-guard', '--unschedule', '--unset', '--unset-all', '--unsettle', '--unshallow', '--untrack', '--untracked-files', '--url', '--url-env', '--user', '--vacuum', '--vectors', '--verbose', '--verify', '--version', '--wait', '--wait-drain', '--wakeshift', '--warn-only', '--watch', '--what-if-threshold', '--where', '--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', '--patch', '--path', '--phase', '--prefer', '--privacy-url', '--purge', '--recent', '--refresh-operations', '--row', '--scopes', '--session', '--since', '--slugs', '--source', '--sources', '--stale', '--status', '--surface', '--terms-url', '--to', '--updated-after', '--url', '--yes'],
'edges-backfill': ['--all-sources', '--brain', '--concurrency', '--help', '--json', '--max-chunks', '--source', '--workers'],
@@ -82,7 +82,7 @@ export const CLI_FLAG_REGISTRY: Record<string, readonly string[]> = {
'init': ['--abandon', '--absolute-git-dir', '--accept-all', '--accept-capabilities', '--access', '--access-policy', '--acknowledge-managed', '--admin-intent', '--adopt', '--advertise', '--after', '--aliases', '--all', '--all-drifted', '--allow-create-db', '--allow-docker', '--allow-outside-source-root', '--allow-without-owner', '--anchor', '--applied', '--apply', '--approval-out', '--approved', '--as', '--assign-corpus', '--attest-actor', '--attest-ops', '--attest-read', '--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', '--cached', '--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', '--email', '--embedding-dimensions', '--embedding-model', '--enable', '--entity', '--exclude', '--expand', '--expansion-model', '--expect', '--expect-local', '--expect-remote', '--expect-upstream', '--expected-state', '--explain', '--facts', '--fast', '--federated', '--file', '--filter', '--first-parent', '--fix', '--force', '--force-retry', '--force-schema', '--format', '--fresh-token', '--from', '--from-meetings', '--from-pages', '--full', '--git', '--grammar', '--grant-types', '--group-by', '--harness', '--held', '--help', '--hold-state', '--holds', '--http', '--id', '--images', '--include-ambiguous', '--include-covered', '--include-cross-entity', '--include-failures', '--include-frontmatter', '--include-gitignored', '--include-hidden', '--infer-dates', '--input', '--install', '--instructions-only', '--issuer-url', '--job-isolation', '--json', '--keep', '--keep-checkout', '--key', '--kind', '--label-lowerings', '--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', '--members', '--members-file', '--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-stdio-member', '--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', '--reason', '--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', '--safe', '--save', '--scan-secrets', '--scan-timeout', '--schedule', '--schema-pack', '--scope', '--scopes', '--search-mode', '--section', '--segmented', '--self-transfer', '--semantic', '--serves', '--session', '--session-id', '--shared-skills', '--show-toplevel', '--side', '--since', '--since-last-run', '--skip', '--skip-embed-check', '--skip-failed', '--slug', '--slugs', '--slugs-file', '--source', '--source-id', '--sources', '--squash', '--src-subpath', '--stale', '--state', '--status', '--stdin', '--stdio-member', '--stop-mcp', '--strategy', '--supabase', '--surface', '--swap-only', '--take', '--tier', '--timeout', '--to', '--token', '--touchpoint', '--type', '--types', '--uninstall', '--unsettle', '--untrack', '--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', '--room', '--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', '--agent', '--alert', '--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', '--bundled', '--by-mention', '--cached', '--calls', '--card', '--catalog', '--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-catalog', '--expect-local', '--expect-upstream', '--expected-revision', '--expected-state', '--explain', '--facts', '--federated-read', '--ff-only', '--file', '--filter', '--filters', '--finalize', '--finished-since', '--first-parent', '--fix', '--follow', '--force', '--force-break-lock', '--force-retry', '--force-schema', '--format', '--fresh', '--from-index', '--from-json', '--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-content', '--include-deleted', '--include-frontmatter', '--include-gitignored', '--include-hidden', '--include-null-signature', '--infer-dates', '--inject-bootstrap', '--inline', '--input', '--input-json', '--install', '--interval', '--is-ancestor', '--is-shallow-repository', '--job-id', '--job-isolation', '--json', '--keep', '--kind', '--labelled-only', '--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', '--members', '--members-file', '--migrate-only', '--migration', '--min-context', '--missing-path', '--mode', '--model', '--multimodal', '--name', '--name-only', '--ner', '--nice', '--no-assume-unchanged', '--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-skip-worktree', '--no-verify', '--no-worker', '--non-interactive', '--now', '--of', '--older-than', '--once', '--only', '--open-history', '--order', '--others', '--out', '--output', '--override-disabled', '--oversized', '--pace', '--pace-max-concurrency', '--pack', '--page', '--parallel', '--params', '--parked-code', '--pat-file', '--patch', '--path', '--pause', '--pglite', '--phase', '--pid-file', '--plan', '--port', '--prefer', '--prefix', '--preview', '--priority', '--privacy-url', '--probe', '--propose', '--prune-orphans', '--pull', '--purge', '--qm', '--question', '--queue', '--queue-only', '--quiet', '--rate', '--readers', '--reads-unscoped', '--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', '--routing', '--row', '--save', '--schedule', '--scope', '--scopes', '--section', '--segment-limit', '--segmented', '--select', '--self-transfer', '--serial', '--serves', '--session', '--show-toplevel', '--side', '--sigkill-rescue', '--since', '--skill-loading', '--skills-index-only', '--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', '--stdio-member', '--stop-mcp', '--strategy', '--suites', '--surface', '--swap-only', '--synopsis', '--target', '--terms-url', '--text', '--thin', '--thin-threshold', '--tier', '--timeout', '--timeout-ms', '--to', '--token', '--token-env', '--trust', '--type', '--types', '--unattended', '--uninstall', '--unschedule', '--unshallow', '--untrack', '--updated-after', '--url', '--user', '--vectors', '--verbose', '--verify', '--version', '--wakeshift', '--watch', '--wedge-rescue', '--workers', '--working-tree', '--yes'],
+ 'jobs': ['--abbrev-ref', '--access', '--access-policy', '--account', '--acknowledge-managed', '--add', '--admin-intent', '--adopt-slug-path', '--agent', '--alert', '--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', '--bundled', '--by-mention', '--cached', '--calls', '--card', '--catalog', '--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-catalog', '--expect-local', '--expect-upstream', '--expected-revision', '--expected-state', '--explain', '--facts', '--federated-read', '--ff-only', '--file', '--filter', '--filters', '--finalize', '--finished-since', '--first-parent', '--fix', '--follow', '--force', '--force-break-lock', '--force-retry', '--force-schema', '--format', '--fresh', '--from-index', '--from-json', '--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-content', '--include-deleted', '--include-frontmatter', '--include-gitignored', '--include-hidden', '--include-null-signature', '--infer-dates', '--inject-bootstrap', '--inline', '--input', '--input-json', '--install', '--interval', '--is-ancestor', '--is-shallow-repository', '--job-id', '--job-isolation', '--json', '--keep', '--kind', '--labelled-only', '--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', '--members', '--members-file', '--migrate-only', '--migration', '--min-context', '--missing-path', '--mode', '--model', '--multimodal', '--name', '--name-only', '--ner', '--nice', '--no-assume-unchanged', '--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-skip-worktree', '--no-verify', '--no-worker', '--non-interactive', '--now', '--of', '--older-than', '--once', '--only', '--open-history', '--order', '--others', '--out', '--output', '--override-disabled', '--oversized', '--pace', '--pace-max-concurrency', '--pack', '--page', '--parallel', '--params', '--parked-code', '--pat-file', '--patch', '--path', '--pause', '--pglite', '--phase', '--pid-file', '--plan', '--port', '--prefer', '--prefix', '--preview', '--priority', '--privacy-url', '--probe', '--propose', '--prune-orphans', '--pull', '--purge', '--push-only', '--qm', '--question', '--queue', '--queue-only', '--quiet', '--rate', '--readers', '--reads-unscoped', '--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', '--routing', '--row', '--save', '--schedule', '--scope', '--scopes', '--section', '--segment-limit', '--segmented', '--select', '--self-transfer', '--serial', '--serves', '--session', '--show-toplevel', '--side', '--sigkill-rescue', '--since', '--skill-loading', '--skills-index-only', '--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', '--stdio-member', '--stop-mcp', '--strategy', '--suites', '--surface', '--swap-only', '--synopsis', '--target', '--terms-url', '--text', '--thin', '--thin-threshold', '--tier', '--timeout', '--timeout-ms', '--to', '--token', '--token-env', '--trust', '--type', '--types', '--unattended', '--uninstall', '--unschedule', '--unshallow', '--untrack', '--updated-after', '--url', '--user', '--vectors', '--verbose', '--verify', '--version', '--wakeshift', '--watch', '--wedge-rescue', '--whole-class', '--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', '--error-unmatch', '--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-assume-unchanged', '--no-autostash', '--no-cron', '--no-pull', '--no-renames', '--no-skip-worktree', '--no-tags', '--no-verify', '--older-than', '--only', '--pat-file', '--path', '--porcelain', '--prefer', '--preview', '--probe', '--progress-interval', '--progress-json', '--provenance', '--pull', '--purge', '--push-only', '--quiet', '--readers', '--rebase', '--require-clean', '--resolve', '--room', '--scan-secrets', '--scan-timeout', '--scopes', '--self-transfer', '--short', '--show-toplevel', '--slug', '--slugs', '--source', '--source-id', '--stdin', '--timeout', '--timings', '--unset-all', '--untracked-files', '--verify', '--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'],
@@ -114,7 +114,7 @@ export const CLI_FLAG_REGISTRY: Record<string, readonly string[]> = {
'reindex-search-vector': ['--accept-pending', '--as', '--background', '--brain', '--dry-run', '--explain', '--follow', '--help', '--json', '--no-accept-pending', '--progress-interval', '--progress-json', '--quiet', '--resume', '--room', '--source', '--timeout', '--timings', '--wait', '--yes'],
'reinit-pglite': ['--abbrev-ref', '--acknowledge-managed', '--all', '--allow-create-db', '--allow-docker', '--allow-empty', '--apply', '--brain', '--break-lock', '--cached', '--chat-model', '--check', '--code', '--concurrency', '--confirm-destructive', '--content-root', '--cursor', '--db-only', '--detail', '--diff-filter', '--dim', '--embedding-dimensions', '--embedding-model', '--empty', '--exclude', '--exclude-standard', '--expansion-model', '--expect', '--filters', '--fix', '--force', '--force-break-lock', '--format', '--full', '--full-history', '--git', '--grant-types', '--hard-deadline', '--help', '--hold-state', '--http', '--include-gitignored', '--include-hidden', '--interval', '--is-ancestor', '--is-shallow-repository', '--issuer-url', '--json', '--key', '--lanes', '--limit', '--local-postgres', '--max-age', '--max-cost', '--max-sources', '--max-usd', '--mcp-only', '--mcp-url', '--migrate-only', '--missing-path', '--model', '--name-only', '--no-auto-embed', '--no-bulk', '--no-delegate', '--no-embed', '--no-embedding', '--no-extract', '--no-git', '--no-gpg-sign', '--no-hard-deadline', '--no-lanes', '--no-llm', '--no-migrate', '--no-pull', '--no-renames', '--no-repair', '--no-schema-pack', '--no-sync', '--no-verify', '--non-interactive', '--oauth-client-id', '--oauth-client-secret', '--others', '--parallel', '--path', '--pglite', '--plan', '--prefer', '--prefer-postgres', '--preview', '--priority', '--provenance', '--query', '--quiet', '--redact-paths', '--repo', '--reset-checkpoint', '--retry-failed', '--retry-held', '--schema-pack', '--scopes', '--search-mode', '--serial', '--show-toplevel', '--skip-embed-check', '--skip-failed', '--slug', '--slugs', '--source', '--source-id', '--src-subpath', '--stale', '--status', '--strategy', '--supabase', '--surface', '--timeout', '--to', '--trust', '--url', '--verify', '--version', '--watch', '--workers', '--working-tree', '--yes'],
'remote': ['--brain', '--help', '--json', '--mcp-only', '--only', '--remediation-plan', '--request-id', '--scopes', '--source', '--timeout'],
- 'repair': ['--accept-pending', '--acknowledge-managed', '--after', '--all', '--all-drifted', '--allow-without-owner', '--apply', '--as', '--audit', '--auto-additive', '--background', '--brain', '--break-lock', '--class', '--client', '--close', '--conflicts', '--created-before', '--cursor', '--cwd', '--day', '--diff', '--email', '--expect', '--explain', '--ff-only', '--follow', '--force', '--force-break-lock', '--from', '--full', '--full-history', '--generation', '--held', '--help', '--id', '--ids-file', '--include-ambiguous', '--include-cross-entity', '--include-failures', '--include-repairs', '--json', '--keep', '--key', '--kind', '--limit', '--max-cost', '--max-cost-usd', '--max-usd', '--mode', '--no-accept-pending', '--no-delegate', '--no-embed', '--no-llm', '--older-than', '--only', '--out', '--prefer', '--prefix', '--preview', '--principal', '--probe', '--progress-interval', '--progress-json', '--propose', '--provenance', '--quiet', '--readers', '--remediate', '--remediation-plan', '--request', '--request-id', '--reset-checkpoint', '--retry-failed', '--room', '--rules', '--run', '--scopes', '--seat', '--session', '--side', '--since', '--skip', '--skip-failed', '--slug', '--slugs', '--slugs-file', '--source', '--stale', '--state', '--timeout', '--timings', '--undo', '--url', '--wait', '--yes'],
+ 'repair': ['--accept-pending', '--acknowledge-managed', '--after', '--all', '--all-drifted', '--allow-without-owner', '--apply', '--as', '--audit', '--auto-additive', '--background', '--brain', '--break-lock', '--class', '--client', '--close', '--conflicts', '--created-before', '--cursor', '--cwd', '--day', '--diff', '--email', '--expect', '--explain', '--ff-only', '--follow', '--force', '--force-break-lock', '--from', '--full', '--full-history', '--generation', '--held', '--help', '--id', '--ids-file', '--include-ambiguous', '--include-cross-entity', '--include-failures', '--include-repairs', '--json', '--keep', '--key', '--kind', '--limit', '--max-cost', '--max-cost-usd', '--max-usd', '--mode', '--no-accept-pending', '--no-delegate', '--no-embed', '--no-llm', '--older-than', '--only', '--out', '--prefer', '--prefix', '--preview', '--principal', '--probe', '--progress-interval', '--progress-json', '--propose', '--provenance', '--quiet', '--readers', '--remediate', '--remediation-plan', '--request', '--request-id', '--reset-checkpoint', '--retry-failed', '--room', '--rules', '--run', '--scopes', '--seat', '--session', '--side', '--since', '--skip', '--skip-failed', '--slug', '--slugs', '--slugs-file', '--source', '--stale', '--state', '--timeout', '--timings', '--undo', '--url', '--wait', '--whole-class', '--yes'],
'repair-jsonb': ['--accept-pending', '--as', '--background', '--brain', '--dry-run', '--explain', '--follow', '--help', '--json', '--no-accept-pending', '--probe', '--progress-interval', '--progress-json', '--quiet', '--room', '--source', '--supabase', '--timeout', '--timings', '--url', '--wait'],
'report': ['--brain', '--content', '--dir', '--help', '--json', '--source', '--title', '--type'],
'repos': ['--abandon', '--abbrev-ref', '--abort', '--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', '--attest-actor', '--attest-ops', '--attest-read', '--attest-sources', '--audit', '--auto-additive', '--autostash', '--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', '--classify', '--cleanup-dead-local-locks', '--clear', '--client', '--clone-dir', '--code', '--config', '--confirm-destructive', '--confirm-quiesced', '--confirm-relocated-root', '--conflicts', '--contacts-dir', '--count', '--cursor', '--days', '--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', '--federated', '--federated-read', '--fetch-timeout-ms', '--ff-only', '--file', '--fix', '--force', '--force-with-lease', '--format', '--from', '--from-git', '--full', '--future-days', '--get', '--get-all', '--git-dir', '--git-path', '--github-repo', '--grant-types', '--group-by', '--hard', '--heads', '--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', '--labelled-only', '--lanes', '--limit', '--list-out', '--local', '--local-env-vars', '--loops-exclude-labels', '--manifest', '--max-cost-usd', '--may-act-for', '--member', '--members', '--members-file', '--message', '--migrate-legacy', '--migration', '--min-trust', '--mode', '--name', '--name-only', '--no-assume-unchanged', '--no-autostash', '--no-cron', '--no-edit', '--no-embed', '--no-extract', '--no-federate', '--no-federated', '--no-follow-tags', '--no-harden', '--no-lanes', '--no-open-pages', '--no-pull', '--no-renames', '--no-skip-worktree', '--no-tags', '--no-verify', '--not', '--only', '--operation', '--operations', '--origin', '--others', '--out', '--owner', '--params', '--parked-code', '--parked-pushes', '--pat-file', '--path', '--path-format', '--plan', '--porcelain', '--prefix', '--preview', '--private-facts', '--private-pages', '--probe', '--profile', '--pull', '--push-only', '--push-remote', '--quiet', '--read-sources', '--readers', '--reads-unscoped', '--rebase', '--recurse-submodules', '--redirect-uri', '--refresh-operations', '--remote', '--remove', '--remove-backup', '--repair', '--replace', '--repos', '--request-id', '--require-clean', '--reset-checkpoint', '--reset-default', '--resolve', '--resume', '--retire', '--retry-failed', '--sample', '--scan-secrets', '--scan-timeout', '--scope', '--scopes', '--secret', '--self-transfer', '--services', '--set', '--set-upstream-to', '--shared-skills', '--short', '--show-toplevel', '--since', '--slug-prefixes', '--source', '--source-id', '--source-ids', '--sources', '--stale', '--stat', '--state', '--status', '--stdin', '--surface', '--symbolic-full-name', '--takes-holders', '--to', '--token', '--token-command', '--token-endpoint-auth-method', '--token-env', '--token-ttl', '--unindexed', '--uninstall', '--unset-all', '--unsettle', '--untracked-files', '--url', '--usage', '--verify', '--wait', '--wait-drain', '--warn-only', '--window', '--yes'],
diff --git a/src/core/config-runtime-keys.ts b/src/core/config-runtime-keys.ts
index aca86c114a..63ad4fed4d 100644
--- a/src/core/config-runtime-keys.ts
+++ b/src/core/config-runtime-keys.ts
@@ -6,6 +6,7 @@
* recorded as internal state.
*/
export const RUNTIME_READER_CONFIG_KEYS: readonly string[] = [
+ 'apple.helper.port', // imessage/imessage-source.ts: the GBrain Helper's loopback port an imessage source reads (set by setup; no default)
'embed.max_usd_per_page', // page-embedding-budget.ts: large-page embedding cap, default $2 (unlimited under spend.posture tokenmax)
'derive.max_usd_per_page', // page-spend.ts: large-page cap per paid derivation (facts, synopsis), default $2 (unlimited under spend.posture tokenmax)
'embed.content_drift.pass_interval_hours', // content-drift-sweep.ts: hours between completed content-drift passes, default 24 (0 = every run)
diff --git a/src/core/connectors/api-source.ts b/src/core/connectors/api-source.ts
index f5dedf9b83..2a3301dd8c 100644
--- a/src/core/connectors/api-source.ts
+++ b/src/core/connectors/api-source.ts
@@ -107,6 +107,8 @@ export interface ConnectorPublishCtx {
/** The kind as people name it in messages ("Meetings", "Slack"), and the lower-case tag in commit subjects and logs. */
label: string; tag: string;
record: 'git' | 'database'; dir: string | null;
+ /** An unmanaged import passes the external-untrusted write gate, as every managed connector import does. */
+ gated?: boolean;
}
export interface ConnectorPage {
@@ -152,7 +154,8 @@ export async function publishConnectorPage(ctx: ConnectorPublishCtx, page: Conne
}
}
const { importFromContent } = await import('../import-file.ts');
- const result = await importFromContent(engine, slug, markdown, { noEmbed: true, sourceId, sourcePath: relPath, preserveGateMarkers: true, holdNoncanonicalPrivate: true });
+ const result = await importFromContent(engine, slug, markdown, { noEmbed: true, sourceId, sourcePath: relPath, preserveGateMarkers: true, holdNoncanonicalPrivate: true,
+ ...(ctx.gated ? { writeGate: { tier: 'external_untrusted' as const, origin: { channel: `connector:${ctx.tag}`, connector: ctx.tag, source_uri: relPath }, requestId: null } } : {}) });
if (result.status === 'error' || result.error) throw new Error(result.error ?? `Import failed for ${relPath}`);
status = result.status === 'imported' ? 'imported' : 'skipped';
created = !existing;
diff --git a/src/core/connectors/credentials.ts b/src/core/connectors/credentials.ts
index f3cca0b560..c93ef85b6e 100644
--- a/src/core/connectors/credentials.ts
+++ b/src/core/connectors/credentials.ts
@@ -30,6 +30,7 @@ import type {
CredentialProviderName,
ResolvedCredential,
TokenProviderName,
+ HelperTokenProviderName,
} from './types.ts';
/** `~/.gbrain/connectors` (GBRAIN_HOME honored via `gbrainPath`). */
@@ -123,7 +124,7 @@ export interface ResolvedApiToken { token: string; source: 'token_env' | 'env' |
* instead of falling back to another key); otherwise env `GBRAIN_CONNECTOR_<P>_TOKEN` wins over the 0600 file.
* `name` says where it came from (a variable name or the file path), never the value.
*/
-export function resolveApiToken(provider: TokenProviderName, tokenEnv?: string): ResolvedApiToken | null {
+export function resolveApiToken(provider: TokenProviderName | HelperTokenProviderName, tokenEnv?: string): ResolvedApiToken | null {
if (tokenEnv) {
const value = process.env[tokenEnv]?.trim();
return value ? { token: value, source: 'token_env', name: tokenEnv } : null;
diff --git a/src/core/connectors/item-holds-store.ts b/src/core/connectors/item-holds-store.ts
index 882afd0417..5f65b4bd4e 100644
--- a/src/core/connectors/item-holds-store.ts
+++ b/src/core/connectors/item-holds-store.ts
@@ -39,7 +39,7 @@ export async function managedBrain(engine: Exec): Promise<boolean> {
}
/** Kinds whose unmanaged cursor lives in the database (db-cursor.ts), never in a state file. */
-const usesDbCursor = (kind: ConnectorKind) => kind === 'meetings' || kind === 'slack';
+const usesDbCursor = (kind: ConnectorKind) => kind === 'meetings' || kind === 'slack' || kind === 'imessage';
/** The `state_file` a hold carry names for a database cursor. */
const DB_CURSOR_TARGET = 'op_checkpoints:connector-db-cursor';
diff --git a/src/core/connectors/types.ts b/src/core/connectors/types.ts
index d7531b8ecb..c4945c734b 100644
--- a/src/core/connectors/types.ts
+++ b/src/core/connectors/types.ts
@@ -31,8 +31,11 @@ export type TokenProviderName = 'fireflies' | 'slack';
export const TOKEN_PROVIDER_NAMES: readonly TokenProviderName[] = ['fireflies', 'slack'];
export function isTokenProviderName(name: string): name is TokenProviderName { return (TOKEN_PROVIDER_NAMES as readonly string[]).includes(name); }
+/** A token that a local helper app issues (the GBrain Helper's loopback token for `imessage`): saved by setup, never through `connectors auth`. */
+export type HelperTokenProviderName = 'imessage';
+
/** Every provider with a slot in the credential store. */
-export type CredentialProviderName = ConnectorProviderName | TokenProviderName;
+export type CredentialProviderName = ConnectorProviderName | TokenProviderName | HelperTokenProviderName;
/**
* Auth strategy axis. `browser-session` (paste-in cookie) is the PRIMARY lane
diff --git a/src/core/cycle/synthesize.ts b/src/core/cycle/synthesize.ts
index c56bb040dd..bb58f6fcda 100644
--- a/src/core/cycle/synthesize.ts
+++ b/src/core/cycle/synthesize.ts
@@ -3085,28 +3085,36 @@ async function writeSummaryPage(
: (await engine.readPageSnapshot(summarySlug, { sourceId, includeDeleted: true }))?.revision ?? null;
const completed = childOutcomes.filter(c => c.status === 'completed').length;
const failed = childOutcomes.length - completed;
+ // #9598: the summary is per date and synthesize can run more than once a day, so keep earlier runs' links to live pages.
+ const linked = new Set(writtenSlugs);
+ const earlierRuns = (await engine.getPage(summarySlug, { sourceId }))?.compiled_truth ?? '';
+ for (const [, slug] of earlierRuns.matchAll(/^- \[\[([^\]|#]+)\]\]$/gm)) {
+ if (slug !== summarySlug && !linked.has(slug!) && await engine.getPage(slug!, { sourceId })) linked.add(slug!);
+ }
+ const fromEarlierRuns = linked.size - new Set(writtenSlugs).size;
const lines: string[] = [];
lines.push(`# Dream cycle ${summaryDate}`);
lines.push('');
lines.push(`**Children:** ${completed} completed, ${failed} failed/timeout.`);
lines.push(`**Pages written:** ${writtenSlugs.length}.`);
+ if (fromEarlierRuns > 0) lines.push(`**Pages from earlier runs today:** ${fromEarlierRuns}.`);
lines.push('');
- if (writtenSlugs.length > 0) {
+ if (linked.size > 0) {
// #4337: deterministic, lexicographically sorted sample — small cycles
// stay fully linked; large cycles list exactly SUMMARY_LINK_SAMPLE_LIMIT
// links while keeping exact totals above. The provenance section below
// names the frontmatter query and what it misses (#6642).
- const sampledSlugs = [...writtenSlugs].sort().slice(0, SUMMARY_LINK_SAMPLE_LIMIT);
+ const sampledSlugs = [...linked].sort().slice(0, SUMMARY_LINK_SAMPLE_LIMIT);
lines.push(
- writtenSlugs.length > SUMMARY_LINK_SAMPLE_LIMIT
- ? `## Page sample (${sampledSlugs.length} of ${writtenSlugs.length})`
+ linked.size > SUMMARY_LINK_SAMPLE_LIMIT
+ ? `## Page sample (${sampledSlugs.length} of ${linked.size})`
: '## Pages',
'',
...sampledSlugs.map(slug => `- [[${slug}]]`),
'',
);
- if (writtenSlugs.length > SUMMARY_LINK_SAMPLE_LIMIT) {
+ if (linked.size > SUMMARY_LINK_SAMPLE_LIMIT) {
lines.push(...await summaryProvenanceLines(engine, { sourceId, cycleDate: summaryDate, summarySlug, writtenSlugs }));
}
}
diff --git a/src/core/error-registry.ts b/src/core/error-registry.ts
index 6794c4a498..6e5f8ee1c4 100644
--- a/src/core/error-registry.ts
+++ b/src/core/error-registry.ts
@@ -64,6 +64,22 @@ export interface CodeEntry {
export const CODES = {
absent_from_worktree: { class: 'caller', retryable: false, reasons: ['skip_worktree', 'deleted_locally'], summary: "Sync held one file that is committed at HEAD but missing from the working tree (a sparse checkout or a skip-worktree bit, or a local deletion that is not committed); the rest of the source synced.", why: "Sync imports from the working tree, so it cannot import a file that is not on disk, and treating it as deleted would drop a committed file silently. Whether the file comes back or its deletion is committed is the user's choice; classic sync re-screens the hold on every run.", docs: 'docs/guides/write-refusals.md#absent_from_worktree', suggestion: 'Restore the file (git restore -- <path>, or widen the sparse checkout) and the next sync imports it; or commit the deletion with gbrain git commit-push -m <msg> -- <path> and the next sync clears the hold.' },
+ apple_full_disk_access_pending: { class: 'caller', actor: 'user', summary: "GBrain Helper is running but cannot read Messages because Full Disk Access is off for it, so nothing was imported.",
+ why: 'macOS lets an app read the Messages database only after the user switches it on in System Settings; only the user can do that, and a grant can be turned off again later.',
+ docs: 'docs/guides/apple-setup.md#apple_full_disk_access_pending',
+ suggestion: 'Ask the user to open System Settings > Privacy & Security > Full Disk Access and switch on GBrain Helper, then run gbrain sync --source <id>.' },
+ apple_helper_not_running: { class: 'caller', actor: 'user', summary: "Nothing answered on the GBrain Helper's loopback port (the helper is stopped, the Mac is asleep, or apple.helper.port is not set), so nothing was imported.",
+ why: 'An imessage source reads only from the helper on the same Mac over 127.0.0.1; it never opens the Messages database itself.',
+ docs: 'docs/guides/apple-setup.md#apple_helper_not_running',
+ suggestion: 'Start GBrain Helper on this Mac and check gbrain config get apple.helper.port names its port, then run gbrain sync --source <id>.' },
+ apple_helper_unauthorized: { class: 'caller', actor: 'user', summary: "GBrain Helper refused the token gbrain sent, or gbrain has no helper token, so nothing was imported.",
+ why: 'The helper answers only a request that carries one of its own tokens with the read:imessage scope; the token is read from the source\'s --token-env variable when it names one, else GBRAIN_CONNECTOR_IMESSAGE_TOKEN, else the 0600 file ~/.gbrain/connectors/imessage.json.',
+ docs: 'docs/guides/apple-setup.md#apple_helper_unauthorized',
+ suggestion: "Save the helper's current token where GBrain reads it, then run gbrain sync --source <id>." },
+ apple_schema_mismatch: { class: 'caller', summary: "GBrain Helper does not recognise the layout of the Messages database (macOS may have changed it), so nothing was imported.",
+ why: 'The helper reads only the tables and columns it knows; it refuses a changed database rather than guess at it.',
+ docs: 'docs/guides/apple-setup.md#apple_schema_mismatch',
+ suggestion: 'Update GBrain and the GBrain Helper to their newest versions, then run gbrain sync --source <id>.' },
access_command_failed: { class: 'caller', summary: "Google connect credential error: access command failed.", docs: 'docs/guides/google-connect.md#troubleshooting' },
access_identity_unavailable: { class: 'retryable', actor: 'provider', summary: "The member a credential (access token, OAuth client or stdio binding) is bound to could not be looked up, so the request was refused and nothing was read or written.", why: "Reading the binding failed with a database error, or with a lock or statement timeout or a dropped connection while the request was submitted. Reading the credential as unbound instead would open every unlabelled page to a labelled-only member, so the request stops, and the same request succeeds once the database answers.", docs: 'docs/guides/write-refusals.md#access_identity_unavailable', suggestion: 'Retry the same request in a few seconds (a write with the same request_id); if it keeps failing, ask the brain operator to run gbrain doctor --json on the brain host.', fix: { argv: ['gbrain', 'whoami', '--json'], consent: [], actor: 'provider', requires_exclusive: false, why: 'Read-only: after a few seconds whoami reads the binding again and shows the member this connection reads as; then repeat the original request.', verify: { argv: ['gbrain', 'whoami', '--json'] } } },
access_member_disabled: { class: 'host_only', actor: 'user', reasons: ['disabled', 'removed', 'missing', 'malformed'], summary: "The credential (access token, OAuth client or stdio binding) is bound to a member who is disabled, removed or missing, so it was refused at verification and nothing was read.", why: 'A credential bound to a member reads as that member. While the member cannot read, the credential is refused rather than silently treated as unbound.', docs: 'docs/guides/write-refusals.md#access_member_disabled', suggestion: 'Ask the brain operator to enable the member (gbrain access member enable <id>) or rebind the credential (gbrain auth rescope --token <name>|--client <id> --member <id>|none).' },
@@ -181,6 +197,9 @@ export const CODES = {
checkpoint_missing: { class: 'caller', summary: "The approved source plan is missing; do not restart from a different revision." },
checkpoint_validation_timeout: { class: 'retryable', summary: "Validating the managed-sync checkpoint timed out." },
claim_already_used: { class: 'caller', summary: "Google connect credential error: claim already used.", docs: 'docs/guides/google-connect.md#troubleshooting' },
+ class_apply_busy: { class: 'retryable', summary: "Another apply of the same whole-class file-drift manifest is running, so this run wrote nothing.", why: "One whole-class apply per manifest at a time keeps its progress record and request ids consistent; a second apply would race the first over the same pages.", docs: 'docs/guides/repair.md#whole-class', suggestion: 'Wait for the running apply to finish. If it was stopped, rerun the same apply command once its lock expires (the message names when); it resumes at the next window and applies no page twice.' },
+ class_capacity_exceeded: { class: 'caller', retryable: false, actor: 'user', summary: "A whole-class file-drift preview found that the reconcile backups its apply would retain exceed the brain's recovery-bytes limit, so nothing was written.", why: "Every page the apply replaces keeps a private reconcile backup, and those backups are bounded by persistence.limits.brain_recovery_bytes; an apply that ran out of room would stop partway through the class.", docs: 'docs/guides/repair.md#whole-class', suggestion: 'Show the user the bytes needed and the limit the message names. Raising persistence.limits.brain_recovery_bytes is their call; otherwise settle a smaller class with --only / --skip.', fix: { argv: ['gbrain', 'config', 'get', 'persistence.limits.brain_recovery_bytes'], consent: [], actor: 'agent', why: 'Read-only: shows the recovery-bytes limit in effect.', requires_exclusive: false } },
+ class_manifest_stale: { class: 'caller', retryable: false, summary: "The whole-class file-drift manifest no longer matches the hash passed with --expect or the pins its preview saved, so nothing was written.", why: "The apply replaces exactly the pages the user approved; a manifest that was edited, partly written, removed, or previewed for another selection is not that approval.", docs: 'docs/guides/repair.md#whole-class', suggestion: 'Run the fresh preview the message prints, show the user its card, and apply its new hash after they agree.' },
client_behind: { class: 'host_only', retryable: false, actor: 'host_admin', summary: "Schema setup (initSchema, which gbrain init, init --migrate-only and upgrade run, and apply-migrations before its orchestrators) refused because the brain's schema version is newer than this gbrain binary's newest migration; nothing in its schema ran and nothing changed.", why: "initSchema replays the binary's whole schema, CREATE OR REPLACE FUNCTION included, before it runs migrations. An older binary sharing the database with a newer one (another host, a lagging cron running apply-migrations or upgrade) used to reinstall its own superseded function bodies, the writer-fence guards among them, over the newer ones and then apply nothing (#7776). Reads do not run schema setup and keep working on the older binary; doctor schema_function_bodies names bodies an older replay already reverted.", suggestion: 'Upgrade gbrain on this host (gbrain upgrade) to the release that migrated the database or newer, then rerun the command.', fix: { argv: ['gbrain', 'doctor', '--only', 'schema_version', '--json'], consent: [], actor: 'agent', why: "Read-only: shows the brain's schema version beside this binary's newest migration.", requires_exclusive: false } },
client_json_unreadable: { class: 'caller', summary: "Google connect credential error: client json unreadable.", docs: 'docs/guides/google-connect.md#troubleshooting' },
client_json_wrong_type: { class: 'caller', summary: "Google connect credential error: client json wrong type.", docs: 'docs/guides/google-connect.md#troubleshooting' },
@@ -627,6 +646,7 @@ export const CODES = {
persistence_write_stall: { class: 'host_only', summary: "A managed write request has held its claim longer than persistence.max_claim_ms, so later writes on its root wait behind it.", why: "The owner renews a claim for as long as its work is unsettled, so a preparation or publication that hangs never lets the lease lapse; doctor names the stuck phase, the root, the claim's age and whether the same request resumes on its own.", docs: 'docs/guides/troubleshooting.md#persistence-write-stall', suggestion: 'Inspect the request with the command in fix, then restart the gbrain serve that owns the root; attach that status output when reporting the hang.', fix: { argv: ['gbrain', 'sources', 'writer', 'status', '--source', '{source_id}', '--json'], consent: [], actor: 'agent', why: "Shows the owner, the stuck request's claim phase and the writes waiting behind it, read-only.", requires_exclusive: false } },
publish_secret_found: { class: 'consent', summary: "An automatic publish found values that look like secrets (or text too large to scan) in the commits it was about to push; nothing was pushed.", docs: 'docs/guides/shared-checkout-git.md#publish_secret_found', actor: 'user' },
publish_scan_unreadable: { class: 'host_only', summary: "An automatic publish could not read its local commits in full to scan them for secrets (a missing or corrupt object, git output the scan does not recognise, or the 300 s budget); no secret was reported and nothing was pushed.", docs: 'docs/guides/shared-checkout-git.md#publish_scan_unreadable', actor: 'user' },
+ push_credential_refused: { class: 'host_only', actor: 'user', retryable: false, reasons: ['not_found', 'forbidden'], summary: "The Git host refused the push for the credential git used (\"Repository not found\", HTTP 404, or HTTP 403); the commit is durable locally and nothing was pushed or retried.", why: "A host answers \"Repository not found\" to an account that cannot see a private repository, and 403 to one that may not write to it. The same credential is refused on every attempt, so a retry only hides the fault while commits stay on this machine; which credential git uses is the user's configuration, and gbrain never changes it.", docs: 'docs/guides/shared-checkout-git.md#push_credential_refused', suggestion: 'Relay the message to the user: it names the credential helpers git asked (with the scope and file that configure each), which one answered and its account login. Once they make git use a credential for an account that can push there, run gbrain git commit-push --push-only.' },
push_unconfirmed: { class: 'retryable', summary: "The commit is durable locally but no push destination confirmed it.", docs: 'docs/guides/shared-checkout-git.md#outcomes', exit: 4 },
schema_lock_blocked: { class: 'retryable', summary: "A schema step (the schema.sql replay in init/upgrade, or one migration) waited its lock_timeout for a table lock another session holds and stopped instead of hanging.", why: "Every ALTER TABLE in the replay takes an ACCESS EXCLUSIVE lock even as a no-op, so one open transaction in another client (idle in transaction, a stuck job) blocked gbrain init and upgrade forever with no output. The wait is now bounded (GBRAIN_SCHEMA_LOCK_TIMEOUT_SECONDS, default 60) and the refusal names the blocking sessions by pid, application and state, sampled while the wait was active; query text is never shown. The cancelled step changed nothing.", docs: 'docs/ENGINES.md#schema-lock-blocked', suggestion: 'Let the named session finish or, with the user\'s agreement, end it on the database host with SELECT pg_terminate_backend(<pid>), then rerun the same gbrain command; init retries a few times on its own with a short backoff.', fix: { argv: ['gbrain', 'doctor', '--json'], consent: [], actor: 'agent', why: 'Read-only: reports the database, the pooler and the schema version so the rerun is judged against the current state.', requires_exclusive: false, verify: { argv: ['gbrain', 'doctor', '--json'] } } },
postgres_tls_required: { class: 'host_only', actor: 'user', retryable: false, summary: "TLS was required by default for a non-local Postgres host, and the server does not accept TLS connections, so gbrain did not connect.", why: "gbrain connects with sslmode=require to any Postgres host that is not on this machine (localhost, 127.0.0.0/8, ::1 or a Unix socket) unless the database URL names an sslmode, so the password and page contents never cross a network in plaintext without an explicit choice. Brains whose URL had no sslmode connected in plaintext before this default.", suggestion: 'Turn TLS on at the database server and keep the default (sslmode=require encrypts; sslmode=verify-full with the server CA also verifies the certificate). To keep connecting without TLS on a network you trust, add sslmode=disable to the database URL.', fix: { ask_user: true, argv: ['gbrain', 'engine', 'status', '--probe', '--json'], consent: [], actor: 'agent', why: 'Read-only: shows where the database URL comes from (an environment variable or the config file), which is where the sslmode setting goes.', user_message: 'Your database server does not accept TLS, and gbrain now requires it for a server that is not on this machine. Either turn TLS on at the server (then nothing else changes), or, if this network is trusted, add sslmode=disable to the database URL to keep the old plaintext connection. sslmode=require and sslmode=verify-full are the secure choices.', requires_exclusive: false, verify: { argv: ['gbrain', 'doctor', '--only', 'postgres_tls', '--json'] } } },
@@ -997,6 +1017,7 @@ export const CODES = {
wakeshift_refused: { class: 'caller', summary: "Wakeshift refused the request; the reason carries its error code. Nothing was watched or sent.", why: "Wakeshift checks each request (the signed key, the event and its arguments, the conversation's session key). A refusal other than a rate limit does not go away on retry.", docs: 'docs/guides/wakeshift.md#troubleshooting', suggestion: 'Call wait_job to wait without Wakeshift; the brain owner can run gbrain wakeshift test to check the key and the app.' },
wakeshift_shared_brain: { class: 'host_only', actor: 'user', summary: "Reporting back refused (gbrain wakeshift enable, or a watch tool): this brain has live access members and its operator has not set the terms and privacy links Wakeshift requires.", why: "Wakeshift's terms (6.2, 6.6) make the operator show each person its own terms and privacy policy, which refer them to Wakeshift's Connector Terms and Privacy Policy, before the first wake. gbrain shows that step from the two links the owner sets on the brain host.", docs: 'docs/guides/wakeshift.md#shared-brains', suggestion: 'Ask the brain owner to run gbrain wakeshift enable --terms-url <https url> --privacy-url <https url>; meanwhile agents can use wait_job or get_write_request.' },
wakeshift_unavailable: { class: 'unavailable', retryable: true, summary: "Wakeshift could not be reached or answered with a server error or rate limit; nothing was watched.", why: "gbrain makes one request with a 10 s timeout and never retries inside a tool call, so a slow or down Wakeshift never holds the call.", docs: 'docs/guides/wakeshift.md#troubleshooting', suggestion: 'Retry in a minute, or call wait_job to wait without Wakeshift.' },
+ whole_class_prefer_unsupported: { class: 'caller', retryable: false, summary: "gbrain repair file-drift --whole-class settles only --prefer file on held side unknown, database or both, so a --prefer database or deleted-side selection was refused before anything was read.", why: "Letting the database win rewrites files, and each deleted-side state is its own decision; neither is settled for a whole class with one approval.", docs: 'docs/guides/repair.md#whole-class', suggestion: 'Preview that selection one window at a time with the per-window command the message names (--held --side <side> --prefer <side>, without --whole-class).', fix: { argv: ['gbrain', 'sources', 'status', '{source_id}', '--json'], consent: [], actor: 'agent', why: 'Read-only: lists the held files of the source with their side and state.', requires_exclusive: false } },
withdrawal_capacity: { class: 'caller', summary: "Withdrawal capacity." },
withdrawal_mirror_failed: { class: 'unavailable', summary: "A page's Git or embedding work is withheld because its withdrawal mirror failed before rewriting the page's file; the file may still hold the withdrawn text.", why: "A withdrawal's Git and embedding effects touch only the pages whose file its mirror recorded rewriting (GBRA-130 A-12); Git never commits a page the mirror passed without rewriting its file. Retrying the request's effects reruns the mirror for this page; once the mirror commits, the withheld work is re-armed automatically.", suggestion: 'Read the parked effects with gbrain doctor --only parked_effects, fix the cause the mirror recorded, then preview gbrain sources writer retry-effects <source> --request-id <id> --dry-run and run it without --dry-run.' },
withdrawal_mirror_pending: { class: 'retryable', summary: "A page's Git or embedding work is waiting because its withdrawal mirror is queued or running again (for example after retry-effects).", why: "Git and embedding work behind a withdrawal mirror touches only the pages the mirror recorded rewriting (GBRA-130 A-12); while the mirror runs, the effect worker releases the work and picks it up once the mirror settles.", suggestion: 'Nothing needs resubmitting; read the effects with gbrain sources writer status <source> --json and wait for the mirror to finish.' },
diff --git a/src/core/facts/conversation-budget.ts b/src/core/facts/conversation-budget.ts
index f563efb7bc..e66b9eea71 100644
--- a/src/core/facts/conversation-budget.ts
+++ b/src/core/facts/conversation-budget.ts
@@ -1,6 +1,7 @@
import type { BrainEngine } from '../engine.ts';
import { buildExtractorSystem, getExtractorVariant, getFactsExtractionModel } from './extract.ts';
import { SEGMENT_TEXT_CHAR_LIMIT } from './conversation-windows.ts';
+import { SLOT_TAG_INPUT_CHARS, SLOT_TAG_MAX_TOKENS } from './slot-tagging.ts';
import { CHAT_INPUT_CHARS_PER_TOKEN } from '../ai/chat-input-estimate.ts';
import { usageCostUsd } from '../budget/reservation-cost.ts';
import { loadPricingOverrides } from '../budget/budget-tracker.ts';
@@ -39,15 +40,19 @@ export interface ConversationRunEstimate { model: string; segments: number; inpu
/**
* GBRA-574 B2: what a paid run over `segments` would send, for the --dry-run preview: each segment at most a full window
* (SEGMENT_TEXT_CHAR_LIMIT) under the conversation extractor's system prompt, without prompt caching, and
- * OUTPUT_TOKENS_PER_SEGMENT back, priced per call by the budget tracker's price table. `usd` is null when the model has
- * no price.
+ * OUTPUT_TOKENS_PER_SEGMENT back, plus one slot-tagging call per segment at its largest (facts/slot-tagging.ts), each
+ * priced per call by the budget tracker's price table. `usd` is null when the model has no price.
*/
export async function conversationRunEstimate(engine: BrainEngine, segments: number): Promise<ConversationRunEstimate> {
const model = await getFactsExtractionModel(engine);
const system = buildExtractorSystem(true, await getExtractorVariant(engine));
const perSegment = Math.ceil((system.length + SEGMENT_TEXT_CHAR_LIMIT) / CHAT_INPUT_CHARS_PER_TOKEN);
- const price = usageCostUsd(model, perSegment, OUTPUT_TOKENS_PER_SEGMENT, 'chat', await loadPricingOverrides(engine));
- return { model, segments, input_tokens: segments * perSegment, output_tokens: segments * OUTPUT_TOKENS_PER_SEGMENT, usd: price == null ? null : segments * price };
+ const perTag = Math.ceil(SLOT_TAG_INPUT_CHARS / CHAT_INPUT_CHARS_PER_TOKEN);
+ const overrides = await loadPricingOverrides(engine);
+ const price = usageCostUsd(model, perSegment, OUTPUT_TOKENS_PER_SEGMENT, 'chat', overrides);
+ const tagPrice = usageCostUsd(model, perTag, SLOT_TAG_MAX_TOKENS, 'chat', overrides);
+ return { model, segments, input_tokens: segments * (perSegment + perTag), output_tokens: segments * (OUTPUT_TOKENS_PER_SEGMENT + SLOT_TAG_MAX_TOKENS),
+ usd: price == null || tagPrice == null ? null : segments * (price + tagPrice) };
}
/** The --dry-run line for an estimate; an unpriced model names the command that registers its price. */
diff --git a/src/core/facts/conversation-incremental.ts b/src/core/facts/conversation-incremental.ts
index a485910e90..09df3cfa1e 100644
--- a/src/core/facts/conversation-incremental.ts
+++ b/src/core/facts/conversation-incremental.ts
@@ -53,7 +53,7 @@ import { deriveDateContext } from '../conversation-parser/parse.ts';
import { loadPricingOverrides, type PricingOverrides } from '../budget/budget-tracker.ts';
import { providerItemRefusal } from '../ai/errors.ts';
import { writeDerivedFacts } from '../persistence/derived-facts.ts';
-import { estimateFactsExtractionUsd, meterPaidCall, unpricedModelReceipt } from '../page-embedding-budget.ts';
+import { estimateChatCallUsd, estimateFactsExtractionUsd, meterPaidCall, unpricedModelReceipt } from '../page-embedding-budget.ts';
import { readExtractionReceipt, setExtractionReceipt, type InputTruncated } from '../extraction-watermark.ts';
import { planSegmentDerivations, segmentDerivationContextHash, sourceWindowFor, sourceWindowKey, type SegmentDerivationInput,
type SegmentDerivationRow, type SourceWindow } from '../page-body/derivations.ts';
@@ -68,6 +68,7 @@ import type { ConversationSegment } from './conversation-types.ts';
import { renderSegmentForExtraction } from './conversation-windows.ts';
import { extractConversationWindow, nonExtractableAuditFact, regularPageVersionToken, terminalAuditFact, type ConversationWindowRun } from './conversation-window-extract.ts';
import { getFactsExtractionMaxTokens, resolveFactsExtractionModel, type ExtractInput } from './extract.ts';
+import { SLOT_TAG_INPUT_CHARS, SLOT_TAG_MAX_TOKENS } from './slot-tagging.ts';
import { tightenToStoredPage, type FactVisibility } from './visibility.ts';
const KIND = 'conversation_facts';
@@ -88,6 +89,8 @@ export interface SegmentedConversationCounters {
pages_marked_non_extractable: number; pages_failed: number; segments_processed: number; facts_extracted: number;
facts_inserted: number; orphan_facts_cleaned: number; fallback_slugify_count: number; resolution_errors: number;
failed_pages: Array<{ slug: string; error: string }>;
+ /** GBRA-574: windows whose slot-tagging call failed; their facts were kept without slots. */
+ slot_tagging_failed?: number;
/** Pages held because no format is detected over them yet some format parses a message (a detection_ambiguous receipt). */
pages_detection_ambiguous?: number;
/** --grammar --dry-run: what a run under the chosen format would extract and collect, per page. */
@@ -402,7 +405,7 @@ export async function processSegmentedConversationPage(run: SegmentedConversatio
const sha = w.window.window_text_sha;
let metered: Awaited<ReturnType<typeof meterPaidCall<Awaited<ReturnType<typeof extractConversationWindow>>>>>;
try {
- metered = await meterPaidCall(engine, page, `facts:${model}`, estimateFactsExtractionUsd(model, text.length, maxTokens, pricingOverrides),
+ metered = await meterPaidCall(engine, page, `facts:${model}`, estimateFactsExtractionUsd(model, text.length, maxTokens, pricingOverrides) + estimateChatCallUsd(model, SLOT_TAG_INPUT_CHARS, SLOT_TAG_MAX_TOKENS, pricingOverrides),
() => extractConversationWindow(run, page, w.seg, text, 0, entityHints), { pricingOverrides });
} catch (error) {
if (!windowFailure(error, run.signal)) throw error;
diff --git a/src/core/facts/conversation-window-extract.ts b/src/core/facts/conversation-window-extract.ts
index 63dc338300..51e7fc59f2 100644
--- a/src/core/facts/conversation-window-extract.ts
+++ b/src/core/facts/conversation-window-extract.ts
@@ -10,6 +10,7 @@ import type { Page } from '../types.ts';
import { observationDateFrom, resolveObservationDate, type ObservationDate } from '../ai/date-grounding.ts';
import { BudgetExhausted } from '../budget/budget-tracker.ts';
import { deriveDateContext } from '../conversation-parser/parse.ts';
+import { resolveStrictEntityReference } from '../entities/resolve.ts';
import { resolveExtractedEntitiesForSave, type SaveTimeResolutionCounts } from '../entities/resolve-on-save.ts';
import { NON_EXTRACTABLE_AUDIT_SOURCE, TERMINAL_AUDIT_SOURCE, stampExtractorVersion } from './audit-sources.ts';
import { CONVERSATION_ENTITY_HINTS_CAP } from './conversation-entity-hints.ts';
@@ -17,6 +18,7 @@ import { CONVERSATION_FACTS_SOURCE_PREFIX, type ConversationFactRow } from './co
import { inferConversationSubjects } from './conversation-subject-infer.ts';
import type { ConversationSegment } from './conversation-types.ts';
import { extractFactsFromTurnWithOutcome, type ExtractInput, type ExtractedFact } from './extract.ts';
+import { tagSlots } from './slot-tagging.ts';
import { tightenToStoredPage, type FactVisibility } from './visibility.ts';
/** What one window's extraction needs from the run. */
@@ -27,6 +29,8 @@ export interface ConversationWindowRun {
signal: AbortSignal | undefined;
/** Injected per-segment extractor (BrainBench decision 15); undefined runs the production fail-hard extractor. */
extractor?: (input: ExtractInput) => Promise<ExtractedFact[]>;
+ /** The run's counters: a window whose slot-tagging call failed adds one to `slot_tagging_failed`. */
+ result: { slot_tagging_failed?: number };
}
/**
@@ -79,6 +83,7 @@ export async function extractConversationWindow(run: ConversationWindowRun, page
}
// This bulk path bypasses writeSingleFact and writes through insertFacts: every extractor-provided entity goes
// through the shipped resolver (alias_exact / prefix / fuzzy / slugify) while source scope is known.
+ const raws = extracted.map(fact => fact.entity_slug);
const resolution = await resolveExtractedEntitiesForSave(run.engine, run.sourceId, extracted, (raw, message) => {
process.stderr.write(`[extract-conversation-facts] ${page.slug} segment ${seg.startIso}..${seg.endIso} `
+ `entity resolution failed for ${JSON.stringify(raw)}: ${message}; preserving fact without an entity target\n`);
@@ -94,7 +99,20 @@ export async function extractConversationWindow(run: ConversationWindowRun, page
...segmentValidFrom(fact.valid_from, seg.startIso),
context: fact.context ?? `from ${page.slug} segment ${seg.startIso}..${seg.endIso}`,
})));
- return { extracted: extracted.length, rows, resolution };
+ // GBRA-574: slots come from a second call over facts whose person was named exactly: by identity evidence alone (an
+ // exact slug, a unique basename or alias; never a prefix guess or a near name), or by subject inference, which needs
+ // one live page named in full. Never on BrainBench's injected extractor.
+ if (run.extractor) return { extracted: extracted.length, rows, resolution };
+ const exact: boolean[] = [];
+ for (const [i, row] of rows.entries()) exact.push(!!row.entity_slug && (!extracted[i]!.entity_slug
+ || (await resolveStrictEntityReference(run.engine, run.sourceId, raws[i]!)).slug === row.entity_slug));
+ const tagged = await tagSlots(run.engine, run.sourceId, rows, exact, run.signal);
+ if (tagged.failed) {
+ run.result.slot_tagging_failed = (run.result.slot_tagging_failed ?? 0) + 1;
+ process.stderr.write(`[extract-conversation-facts] ${page.slug} segment ${seg.startIso}..${seg.endIso}: slot tagging failed; `
+ + 'the facts are kept without slots, and --force tags them again\n');
+ }
+ return { extracted: extracted.length, rows: tagged.rows, resolution };
}
/**
diff --git a/src/core/facts/slot-tagging.ts b/src/core/facts/slot-tagging.ts
new file mode 100644
index 0000000000..55190c79db
--- /dev/null
+++ b/src/core/facts/slot-tagging.ts
@@ -0,0 +1,101 @@
+/**
+ * GBRA-574: conversation fact slots, tagged after extraction. The main extraction call never asks for a slot (asking
+ * cost wishes and preferences); this second, small call reads only the facts the main call produced whose entity is a
+ * live person page named exactly (an exact page or alias match, or subject inference), and tags each with at most one
+ * slot (facts/slots.ts). A failed call leaves the facts without slots; abort and an exhausted budget propagate.
+ */
+import { chat, isAvailable } from '../ai/gateway.ts';
+import { BudgetExhausted } from '../budget/budget-tracker.ts';
+import type { BrainEngine } from '../engine.ts';
+import { retiredPageSql } from '../entities/resolve.ts';
+import { getFactsExtractionModel } from './extract.ts';
+import { normalizeSlot, SLOT_DIMENSIONS } from './slots.ts';
+
+/** Kinds that can state where a person lives, who employs them or their role. */
+const SLOT_KINDS: ReadonlySet<string> = new Set(['fact', 'event']);
+/** Characters of one fact the tagging call sees; the main call returns at most 10 facts a window. */
+export const SLOT_TAG_FACT_CHARS = 400;
+export const SLOT_TAG_MAX_FACTS = 10;
+export const SLOT_TAG_MAX_TOKENS = 400;
+
+export const SLOT_TAG_SYSTEM = [
+ 'You tag facts about people with a slot when the fact states one: where the person lives (location), which',
+ 'organization employs them (employer), or their role or job title (role).',
+ 'Each input line is "<n>. [<person>] <fact>". Reply with JSON only:',
+ '{"slots":[{"i":<n>,"dimension":"location|employer|role","value":"<the place, organization or title alone>"}]}',
+ 'with one entry for each fact that states a slot for the bracketed person, and nothing for every other fact.',
+ '- The value must belong to the bracketed person and be stated by the fact.',
+ '- A fact saying the value changed (moved, joined, was promoted) carries the new value. A fact that only ends a value',
+ ' ("left the company") or states a past one ("used to live in ...") has no slot.',
+ '- No slot for plans, wishes, trips, visits or guesses.',
+ '- At most one slot per fact.',
+].join('\n');
+
+const SLOT_TAG_SCHEMA = { name: 'slot_tagging', schema: {
+ type: 'object',
+ properties: {
+ slots: {
+ type: 'array',
+ items: {
+ type: 'object',
+ properties: { i: { type: 'integer' }, dimension: { type: 'string', enum: [...SLOT_DIMENSIONS] }, value: { type: 'string' } },
+ required: ['i', 'dimension', 'value'],
+ },
+ },
+ },
+ required: ['slots'],
+} };
+
+/** The longest input one tagging call sends, for cost bounds. */
+export const SLOT_TAG_INPUT_CHARS = SLOT_TAG_SYSTEM.length + SLOT_TAG_MAX_FACTS * (SLOT_TAG_FACT_CHARS + 120);
+
+type TaggableRow = { fact: string; kind?: string | null; entity_slug?: string | null; dimension?: string | null; value?: string | null };
+
+/**
+ * Returns `rows` with a slot on each fact the model tagged (tagged rows are copies). `exact[i]` says row i's entity was
+ * named exactly; `called` says a tagging call went out, `failed` that it errored or its reply could not be read.
+ */
+export async function tagSlots<T extends TaggableRow>(engine: BrainEngine, sourceId: string, rows: T[], exact: readonly boolean[],
+ abortSignal?: AbortSignal): Promise<{ rows: T[]; called: boolean; failed: boolean }> {
+ const picked = rows.map((row, i) => ({ row, i }))
+ .filter(({ row, i }) => exact[i] && row.entity_slug && SLOT_KINDS.has(row.kind ?? 'fact'))
+ .slice(0, SLOT_TAG_MAX_FACTS);
+ if (!picked.length) return { rows, called: false, failed: false };
+ const people = new Map((await engine.executeRaw<{ slug: string; title: string | null }>(
+ `SELECT slug, title FROM pages WHERE source_id = $1 AND deleted_at IS NULL AND type = 'person' AND slug = ANY($2::text[]) AND NOT ${retiredPageSql('pages')}`,
+ [sourceId, [...new Set(picked.map(p => p.row.entity_slug!))]])).map(p => [p.slug, p.title || p.slug]));
+ const candidates = picked.filter(p => people.has(p.row.entity_slug!));
+ if (!candidates.length) return { rows, called: false, failed: false };
+ const model = await getFactsExtractionModel(engine);
+ if (!isAvailable('chat', model)) return { rows, called: false, failed: false };
+
+ const lines = candidates.map((c, n) => `${n + 1}. [${people.get(c.row.entity_slug!)}] ${c.row.fact.replace(/\s+/g, ' ').slice(0, SLOT_TAG_FACT_CHARS)}`);
+ let text: string;
+ try {
+ const result = await chat({ model, system: SLOT_TAG_SYSTEM, messages: [{ role: 'user', content: lines.join('\n') }],
+ maxTokens: SLOT_TAG_MAX_TOKENS, abortSignal, responseSchema: SLOT_TAG_SCHEMA, cacheSystem: true });
+ if (result.stopReason === 'length') return { rows, called: true, failed: true };
+ text = result.text;
+ } catch (err) {
+ if (err instanceof BudgetExhausted || abortSignal?.aborted || (err instanceof Error && err.name === 'AbortError')) throw err;
+ return { rows, called: true, failed: true };
+ }
+ let slots: unknown;
+ try {
+ slots = (JSON.parse(text.trim().replace(/^```(?:json)?\s*/i, '').replace(/\s*```$/, '')) as { slots?: unknown }).slots;
+ } catch {
+ return { rows, called: true, failed: true };
+ }
+ if (!Array.isArray(slots)) return { rows, called: true, failed: true };
+ const out = [...rows];
+ const tagged = new Set<number>();
+ for (const s of slots as Array<{ i?: unknown; dimension?: unknown; value?: unknown }>) {
+ const c = typeof s?.i === 'number' && Number.isInteger(s.i) ? candidates[s.i - 1] : undefined;
+ if (!c || tagged.has(c.i)) continue;
+ const slot = normalizeSlot(s.dimension, s.value, c.row.entity_slug);
+ if (!slot) continue;
+ tagged.add(c.i);
+ out[c.i] = { ...c.row, ...slot };
+ }
+ return { rows: out, called: true, failed: false };
+}
diff --git a/src/core/facts/slots.ts b/src/core/facts/slots.ts
index 86e3ddc956..6f39cb893e 100644
--- a/src/core/facts/slots.ts
+++ b/src/core/facts/slots.ts
@@ -1,6 +1,7 @@
/**
- * GBRA-574 B2: conversation fact slots. The conversation extractor may tag a fact with one slot, a (dimension, value)
- * pair on the ontology columns facts already has, from a closed vocabulary of single-valued dimensions. Nothing closes
+ * GBRA-574 B2: conversation fact slots. A second call after extraction (slot-tagging.ts) may tag a fact with one slot,
+ * a (dimension, value) pair on the ontology columns facts already has, from a closed vocabulary of single-valued
+ * dimensions. Nothing closes
* a slot value in storage: the query facts block derives each value's validity window at read time from the slot's
* chronology (deriveSlotEnds), so re-extracting pages in any order yields the same windows.
*/
diff --git a/src/core/function-search-path.ts b/src/core/function-search-path.ts
index cb0c1d1f23..59c029e1d5 100644
--- a/src/core/function-search-path.ts
+++ b/src/core/function-search-path.ts
@@ -43,7 +43,7 @@ export const PINNED_FUNCTION_NAMES = [
'gbrain_clear_atom_page_state', 'gbrain_concept_inputs_private', 'gbrain_count_git_canonical_sources', 'gbrain_count_modifications', 'gbrain_forget_page_retrievals',
'gbrain_fts_input', 'gbrain_graduation_fence', 'gbrain_guard_deferred_request', 'gbrain_guard_effect_protocol', 'gbrain_guard_guest_records', 'gbrain_guard_inserted_facts',
'gbrain_guard_protocol_activation', 'gbrain_guard_request_protocol', 'gbrain_guard_skill_publication',
- 'gbrain_lease_shared_skill_delivery', 'gbrain_mark_derivation_scope_entry', 'gbrain_preserve_fact_withdrawal',
+ 'gbrain_lease_shared_skill_delivery', 'gbrain_mark_derivation_scope_entry', 'gbrain_owner_only_lineage', 'gbrain_preserve_fact_withdrawal',
'gbrain_queue_page_projection', 'gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page',
'gbrain_refuse_purged_take', 'gbrain_refuse_purging_derivation', 'gbrain_release_refresh_barrier', 'gbrain_require_managed_writer',
'gbrain_require_persistence_protocol', 'gbrain_snapshot_version_trust', 'gbrain_stamp_revision_attribution',
diff --git a/src/core/git/commit-push.ts b/src/core/git/commit-push.ts
index 74736435f6..24e3f000af 100644
--- a/src/core/git/commit-push.ts
+++ b/src/core/git/commit-push.ts
@@ -38,6 +38,7 @@ import { canonicalFilesystemPath } from '../persistence/root-registry.ts';
import { assertManagedFilesystemWrite, hasFilesystemPublication, managedFilesystemRootFor, type ManagedFilesystemRoot } from '../persistence/filesystem-guard.ts';
import { acquireNativeLock, acquireNativeLockSync, type NativeLockSyncHandle } from '../persistence/native-lock.ts';
import { recordCommit, recordIntent } from './commit-ledger.ts';
+import { CREDENTIAL_STATE_NAME, credentialRefusal, pushCredentialRefusedError, readCredentialRefusalFile, recordCredentialRefusalFile, type CredentialRefusalState } from './push-credential.ts';
import { OperationError, opError } from '../ops/contract.ts';
import { shellQuote, type Action } from '../agent-output.ts';
import { isSyncable } from '../sync.ts';
@@ -1202,6 +1203,8 @@ function publish(ctx: Ctx, start: string, resolutions: Map<string, Resolution> |
if (push?.code === 0) return { sha: candidate, integrated, confirmed: 'push', ...notes() };
if (push) lastError = push.stderr.trim();
if (remoteContains(ctx, candidate)) return onRemote();
+ const refused = push ? credentialRefusal(push.stderr) : null;
+ if (refused) throw pushCredentialRefusedError(ctx.root, ctx.remote, ctx.mergeRef.replace(/^refs\/heads\//, ''), refused, candidate);
remoteTip = fetchTracking(ctx);
if (!remoteTip) break;
scannedBase = pushBase(ctx, remoteTip, candidate);
@@ -1337,6 +1340,24 @@ export function readIntegrateConflict(repo: string): IntegrateConflictState | nu
}
}
+/** GST-2961: the push refusal for the credential git used, recorded for this checkout until a push lands (by any route: when the remote pushes to the one URL it fetches from, a refused commit already on the remote-tracking ref is past), if any. */
+export function readCredentialRefusal(repo: string): CredentialRefusalState | null {
+ try {
+ const root = checkoutRoot(repo);
+ const state = readCredentialRefusalFile(absGitPath(root, CREDENTIAL_STATE_NAME));
+ const pushesWhereItFetches = () => {
+ const push = git(root, ['remote', 'get-url', '--push', '--all', '--', state!.remote]);
+ const fetch = git(root, ['remote', 'get-url', '--', state!.remote]);
+ const urls = push.stdout.trim().split('\n');
+ return push.code === 0 && fetch.code === 0 && urls.length === 1 && urls[0] === fetch.stdout.trim();
+ };
+ if (state?.commit && state.remote && state.branch && pushesWhereItFetches() && isAncestor(root, state.commit, `refs/remotes/${state.remote}/${state.branch}`)) return null;
+ return state;
+ } catch {
+ return null;
+ }
+}
+
function recordConflict(root: string, branch: string, e: unknown): void {
try {
const d = JSON.parse(String((e as { detail?: string }).detail ?? '{}'));
@@ -1484,10 +1505,12 @@ export function commitAndPush(opts: CommitPushOptions): CommitPushResult {
if (!opts.allowOutsideSourceRoot) assertLocalCommitsInsideRoots(ctx, target, roots);
const published = publish(ctx, target, resolutions, expectRemote, cwd);
if (!elsewhere) rmSync(absGitPath(root, CONFLICT_STATE_NAME), { force: true });
+ rmSync(absGitPath(root, CREDENTIAL_STATE_NAME), { force: true });
const moved = published.sha === head || elsewhere || opts.keepCheckout ? { checkout: 'unchanged' as const } : advanceWithLock(root, published.sha, head, onlyWhenClean, opts.lockWaitMs);
return { published, moved };
} catch (e) {
if ((e as { code?: string }).code === 'integrate_conflict' && !elsewhere) recordConflict(root, ctx.branch, e);
+ if ((e as { code?: string }).code === 'push_credential_refused') recordCredentialRefusalFile(absGitPath(root, CREDENTIAL_STATE_NAME), e);
if (requested) writeFileSync(requestPath, `${process.pid}\n`);
throw e;
}
diff --git a/src/core/git/push-credential.ts b/src/core/git/push-credential.ts
new file mode 100644
index 0000000000..81937da722
--- /dev/null
+++ b/src/core/git/push-credential.ts
@@ -0,0 +1,212 @@
+/**
+ * GST-2961: a push the Git host refused for the credential git used. "Repository not found" (HTTP 404, what a host
+ * says to an account that cannot see a private repository) and HTTP 403 ("Permission to ... denied") come back the
+ * same way on every attempt until someone changes which credential git uses, so the publish stops at once with
+ * `push_credential_refused` instead of reading it as a transient `push_unconfirmed`.
+ *
+ * The error names the credential helpers git asked, in the order it asked them, with the scope and file that
+ * configure each (system, global, the checkout's own), which one answered and the account login it gave. It learns
+ * them by asking git once more (`git credential fill` with GIT_TRACE on stderr), the same lookup the refused push just
+ * made; it runs only after a refusal, never on a push that landed. The password is read from that child's stdout and
+ * dropped there: it never reaches an error, a log line or the state file, and a helper's command line is shown only up
+ * to its program name, because an inline helper (`!f() { echo password=...; }; f`) can carry a secret in its body.
+ *
+ * The refusal is kept in `brain-push-credential.json` under the git dir until a push lands, so doctor
+ * (`git_convergence`) and put_page's `lastPushStatus` report it at once rather than after six hours.
+ */
+import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { isAbsolute } from 'node:path';
+import { spawnSync } from '../spawn.ts';
+import { gitChildEnv } from '../git-env.ts';
+import { GIT_ENV } from '../git-transport.ts';
+import { git } from './git-run.ts';
+import { opError, type OperationError } from '../ops/contract.ts';
+import type { Action } from '../agent-output.ts';
+
+export type CredentialRefusal = 'not_found' | 'forbidden';
+
+const NOT_FOUND = /^(?:remote: )?(?:ERROR: )?Repository not found\.?\s*$|^fatal: repository '[^']*' not found\s*$|The requested URL returned error: 404\b/m;
+const FORBIDDEN = /The requested URL returned error: 403\b|^(?:remote: )?(?:ERROR: )?Permission to \S+ denied to /m;
+
+/** Whether git's stderr for a refused push is the host refusing the credential (404 or 403), as opposed to a fault a retry can clear. */
+export function credentialRefusal(stderr: string): CredentialRefusal | null {
+ if (NOT_FOUND.test(stderr)) return 'not_found';
+ if (FORBIDDEN.test(stderr)) return 'forbidden';
+ return null;
+}
+
+export interface HelperAsked {
+ /** The helper's program as configured, without its arguments (`store`, `/usr/local/bin/helper`, `!gh`). */
+ helper: string;
+ /** Where git read it: `system`, `global`, `local`, `worktree` or `command`; null when no config entry matched. */
+ scope: string | null;
+ /** The config file that sets it (`file:<path>`). */
+ origin: string | null;
+ answered: boolean;
+}
+
+export interface PushCredential {
+ /** The push URL without any user or password in it. */
+ url: string;
+ helpers: HelperAsked[];
+ /** The account login the answering helper gave, when it gave one. */
+ username: string | null;
+ note?: string;
+}
+
+const anonymize = (url: string) => url.replace(/^([a-z][a-z0-9+.-]*:\/\/)[^@/]*@/i, '$1');
+
+const TOKEN_PREFIX = /^(?:gh[opusr]_|github_pat_|glpat-|glptt-|gldt-|xox[abpr]-)/i;
+
+/** A login is shown only when it reads as an account name: some helpers store a token as the username, and a long unbroken string can be one. */
+const shownLogin = (login: string | null): string | null =>
+ login && /^[A-Za-z0-9][A-Za-z0-9._@-]{0,63}$/.test(login) && !TOKEN_PREFIX.test(login) && !/^[A-Za-z0-9_-]{30,}$/.test(login) ? login : null;
+
+const SHOWN_COMMAND = /^[A-Za-z0-9._/-]{1,64}$/;
+
+/** A helper's command name only, and only when it has the shape of a plain command or path: arguments can hold a token, and
+ * an inline `!` helper's body or a leading NAME=value assignment can hold one too. Anything else is named generically. */
+function programOf(value: string): string {
+ const inline = value.startsWith('!');
+ const words = (inline ? value.slice(1) : value).trim().split(/\s+/).filter(Boolean);
+ let i = 0;
+ if (inline) while (i < words.length && /^[A-Za-z_][A-Za-z0-9_]*=/.test(words[i]!)) i++;
+ const command = words[i] ?? '';
+ if (!SHOWN_COMMAND.test(command)) return inline ? 'an inline shell helper' : 'a credential helper';
+ return (inline ? '!' : '') + command + (words.length > i + 1 ? ' …' : '');
+}
+
+/** The command line git runs for a configured helper value (credential.c): `!cmd` as is, an absolute path as is, else `git credential-<value>`. */
+function commandOf(value: string): string {
+ if (value.startsWith('!')) return value.slice(1).trim();
+ return isAbsolute(value.split(/\s+/)[0] ?? '') ? value.trim() : 'git credential-' + value.trim();
+}
+
+interface ConfiguredHelper { scope: string; origin: string; value: string }
+
+function configuredHelpers(root: string): ConfiguredHelper[] {
+ const listed = git(root, ['config', '--show-scope', '--show-origin', '--get-regexp', '^credential\\..*helper$'], { timeoutMs: 10_000, returnStopped: true });
+ if (listed.code !== 0) return [];
+ return listed.stdout.split('\n').flatMap(line => {
+ const [scope, origin, rest] = line.split('\t');
+ if (!scope || !origin || rest === undefined) return [];
+ const space = rest.indexOf(' ');
+ const value = space === -1 ? '' : rest.slice(space + 1);
+ return value ? [{ scope, origin, value }] : [];
+ });
+}
+
+/** The helpers git asks for the push URL of `remote` with the checkout's config, in order, and which one answered; never returns the password. */
+export function describePushCredential(root: string, remote: string): PushCredential {
+ const raw = git(root, ['remote', 'get-url', '--push', '--', remote], { timeoutMs: 10_000, returnStopped: true }).stdout.split('\n')[0]?.trim() ?? '';
+ const url = anonymize(raw);
+ if (!/^https?:\/\//i.test(raw)) {
+ return { url, helpers: [], username: null,
+ note: 'This remote is reached over SSH (or a local path), where git asks no credential helper: the key ssh offers decides the account.' };
+ }
+ if (/^https?:\/\/[^@/]*:[^@/]*@/i.test(raw)) {
+ return { url, helpers: [], username: null, note: 'The remote URL carries its own user and password, so git asked no credential helper: the URL decides the account.' };
+ }
+ const run = spawnSync('git', ['-C', root, 'credential', 'fill'], {
+ input: 'url=' + raw + '\n\n', encoding: 'utf8', timeout: 15_000, stdio: ['pipe', 'pipe', 'pipe'],
+ env: gitChildEnv({ ...GIT_ENV, LC_ALL: 'C', LANGUAGE: 'C', GIT_TRACE: '2', GIT_TRACE_SETUP: '0', GIT_TRACE_PACKET: '0', GIT_TRACE_CURL: '0', GIT_TRACE2: '0', GIT_TRACE2_EVENT: '0', GIT_TRACE2_PERF: '0' }),
+ });
+ const asked = String(run.stderr ?? '').split('\n').flatMap(line => {
+ const m = /trace: run_command: (.*)$/.exec(line);
+ if (!m) return [];
+ const cmd = m[1]!.replace(/^'(.*)'$/, '$1').replace(/'\\''/g, "'");
+ return / get$/.test(cmd) ? [cmd.slice(0, -4)] : [];
+ });
+ let username: string | null = null;
+ let answered = false;
+ if (run.status === 0) {
+ const fields = String(run.stdout ?? '').split('\n');
+ username = fields.find(f => f.startsWith('username='))?.slice('username='.length) || null;
+ answered = fields.some(f => f.startsWith('password='));
+ }
+ const configured = configuredHelpers(root);
+ const used = new Set<number>();
+ const helpers = asked.map((cmd, i): HelperAsked => {
+ const at = configured.findIndex((c, j) => !used.has(j) && commandOf(c.value) === cmd);
+ if (at !== -1) used.add(at);
+ const entry = at === -1 ? null : configured[at]!;
+ return { helper: programOf(entry ? entry.value : cmd), scope: entry?.scope ?? null, origin: entry?.origin ?? null, answered: answered && i === asked.length - 1 };
+ });
+ const urlUser = /^https?:\/\/[^@/]+@/i.test(raw);
+ const askpass = process.env.GIT_ASKPASS ? ' GIT_ASKPASS is set (' + programOf(process.env.GIT_ASKPASS) + '), so git may have used it for the refused push.' : '';
+ const note = !helpers.length ? 'Git asked no credential helper for this URL.' + askpass
+ : !answered ? 'No credential helper answered when git asked again.' + askpass
+ : urlUser ? 'The remote URL names its own user, which is not shown because it can be a token.' : undefined;
+ return { url, helpers, username: answered && !urlUser ? shownLogin(username) : null, ...(note ? { note } : {}) };
+}
+
+/** One sentence naming the helpers git asked, in order, with scope and file, and which answered for which login. */
+export function describeHelpers(cred: Pick<PushCredential, 'helpers' | 'username' | 'note'>): string {
+ if (!cred.helpers.length) return cred.note ?? 'Git asked no credential helper.';
+ const list = cred.helpers.map((h, i) => (i + 1) + '. ' + h.helper + ' (' + (h.scope ?? 'scope unknown') + (h.origin ? ', ' + h.origin : '') + ')').join('; ');
+ const answered = cred.helpers.find(h => h.answered);
+ return 'Git asked these credential helpers, in this order: ' + list + '. '
+ + (answered ? answered.helper + ' (' + (answered.scope ?? 'scope unknown') + ') answered' + (cred.username ? ' with the account login ' + cred.username : '') + '.' : (cred.note ?? ''));
+}
+
+/** Read-only: every credential helper key git consults in `root`, with the scope and file that set it, never the value (an inline helper's body can hold a secret). */
+export const credentialHelperKeysArgv = (root: string): string[] =>
+ ['git', '-C', root, 'config', '--show-scope', '--show-origin', '--name-only', '--get-regexp', '^credential\\..*helper$'];
+export const CREDENTIAL_HELPER_KEYS_WHY = 'Read-only: prints the scope, file and key of every credential helper git consults in this checkout, in the order git reads them, without the value.';
+
+/** The non-retryable error a publish throws when the host refused the push for the credential git used. */
+export function pushCredentialRefusedError(root: string, remote: string, branch: string, kind: CredentialRefusal, commit: string): OperationError {
+ const cred = describePushCredential(root, remote);
+ const answered = cred.helpers.find(h => h.answered);
+ const host = kind === 'not_found'
+ ? 'answered "Repository not found" (HTTP 404), which is what a Git host tells an account that cannot see a private repository'
+ : 'answered HTTP 403 (permission denied)';
+ const who = answered
+ ? 'the credential from ' + answered.helper + (answered.scope ? ' (' + answered.scope + ' config)' : '') + (cred.username ? ' for ' + cred.username : '')
+ : 'the credential git used';
+ const helpers = describeHelpers(cred);
+ const fix: Action = {
+ actor: 'user', consent: [], requires_exclusive: false,
+ argv: credentialHelperKeysArgv(root),
+ why: CREDENTIAL_HELPER_KEYS_WHY,
+ user_message: 'Pushes from ' + root + ' to ' + cred.url + ' are refused: the host ' + (kind === 'not_found' ? 'says the repository is not found' : 'denies permission')
+ + ' for ' + who + ', so ' + commit.slice(0, 7) + ' and any earlier local commits stay on this machine (nothing is lost). ' + helpers
+ + ' Please make git use a credential for an account that can push to this repository: the read-only command in this fix lists each credential helper key (such as credential.helper) with the file that sets it, so change the key in the file whose helper answered (for example by putting the helper meant for this repository ahead of a machine-wide one), then run gbrain git commit-push --push-only --path ' + root + '.',
+ verify: { argv: ['gbrain', 'doctor', '--only', 'git_convergence', '--json'] },
+ docs: 'docs/guides/shared-checkout-git.md#push_credential_refused',
+ };
+ return opError('push_credential_refused',
+ remote + ' (' + cred.url + ') refused the push of ' + branch + ': the host ' + host + ', so ' + who + ' cannot push there. ' + helpers + ' The commit is durable locally; gbrain did not retry, because the host refuses the same credential every time.',
+ 'Ask the user to make git use a credential for an account that can push to this repository, then rerun gbrain git commit-push --push-only. gbrain never changes which credential git uses.',
+ { reason: kind, retryable: false, fix,
+ detail: JSON.stringify({ commit, remote, branch, kind, url: cred.url, helpers: cred.helpers, username: cred.username, ...(cred.note ? { note: cred.note } : {}) }) });
+}
+
+// ── State: one record per checkout until a push lands ───────────────────────
+
+export const CREDENTIAL_STATE_NAME = 'brain-push-credential.json';
+
+export interface CredentialRefusalState {
+ branch: string; remote: string; url: string; kind: CredentialRefusal; commit: string;
+ helpers: HelperAsked[]; username: string | null; note?: string;
+ /** When this refusal was first recorded, the latest refused attempt, and how many attempts were refused since. */
+ since: string; at: string; attempts: number;
+}
+
+export function readCredentialRefusalFile(statePath: string): CredentialRefusalState | null {
+ try { return existsSync(statePath) ? JSON.parse(readFileSync(statePath, 'utf8')) as CredentialRefusalState : null; } catch { return null; }
+}
+
+/** Record a push_credential_refused error's detail; a repeat of the same refusal keeps its first time and counts the attempt. */
+export function recordCredentialRefusalFile(statePath: string, error: unknown): void {
+ try {
+ const d = JSON.parse(String((error as { detail?: string }).detail ?? '{}')) as Partial<CredentialRefusalState>;
+ const prior = readCredentialRefusalFile(statePath);
+ const now = new Date().toISOString();
+ const same = !!prior && prior.url === d.url && prior.kind === d.kind;
+ const state: CredentialRefusalState = { branch: d.branch ?? '', remote: d.remote ?? '', url: d.url ?? '', kind: d.kind ?? 'forbidden', commit: d.commit ?? '',
+ helpers: d.helpers ?? [], username: d.username ?? null, ...(d.note ? { note: d.note } : {}),
+ since: same ? prior!.since : now, at: now, attempts: same ? prior!.attempts + 1 : 1 };
+ writeFileSync(statePath, JSON.stringify(state), { mode: 0o600 });
+ } catch { /* best-effort */ }
+}
diff --git a/src/core/imessage/imessage-source.ts b/src/core/imessage/imessage-source.ts
new file mode 100644
index 0000000000..8c3a41788a
--- /dev/null
+++ b/src/core/imessage/imessage-source.ts
@@ -0,0 +1,237 @@
+/**
+ * The imessage source sweep (`sources.config.kind = 'imessage'`): one private page per chat per day, read from the
+ * GBrain Helper on this Mac over 127.0.0.1 (apple/helper-client.ts).
+ *
+ * Coverage is per chat (`connectors/api-source.ts` windows). A run reads each recent chat's window [from, to): `from`
+ * is aligned to the start of a day in the source's time zone, so every day the window touches is read whole and its
+ * page rebuilt from scratch. After the first window, the next starts `lookbackDays` before the boundary, so an edit or
+ * an unsend in recent days converges and the facts extracted from the changed page are retired. A day whose messages
+ * are unchanged (the fingerprint) publishes nothing, so a second run over the same messages writes nothing. A message
+ * deleted on the phone after the lookback stays until the page is deleted by hand.
+ *
+ * Privacy: every page is `visibility: private`, the record is always the database (no directory, nothing committed
+ * on a brain with a Git repository), and the source is owner-only (access/owner-only.ts), which is decided at read
+ * time from the source's kind. `source_kind: imessage` keeps every copy at the external-untrusted trust tier.
+ */
+import { randomUUID } from 'node:crypto';
+import type { BrainEngine } from '../engine.ts';
+import type { SyncOpts, SyncResult } from '../../commands/sync.ts';
+import { OperationError } from '../ops/contract.ts';
+import { withConnectorSync, pendingConnectorResult, type ManagedConnectorSync } from '../persistence/connector-sync.ts';
+import { connectorIdentity } from '../persistence/connector-identity.ts';
+import { ConnectorHoldSession, connectorHoldsResult } from '../connectors/connector-hold-session.ts';
+import { connectorDbCursorKey, readConnectorDbCursor, writeConnectorDbCursor } from '../connectors/db-cursor.ts';
+import { resolveApiToken } from '../connectors/credentials.ts';
+import { connectorRender } from '../connectors/connector-text.ts';
+import {
+ afterConnectorPublish, closeCoverageWindow, connectorDryRunResult, deleteConnectorPage, openCoverageWindow, publishConnectorPage, runScoped,
+ type ConnectorPublishCtx, type CoverageWindow, type PublishSummary,
+} from '../connectors/api-source.ts';
+import { slugifyPath } from '../sync.ts';
+import { nextSlackDay, slackAlignToDay, slackDayKey, slackDayStartMs } from '../slack/render.ts';
+import { IMESSAGE_THREADS_LIMIT, helperNotRunning, imessageHelper, type IMessageHelper } from '../apple/helper-client.ts';
+import { imessageChatKey, imessageDayFingerprint, imessagePagePath, renderIMessageDay, shownMessages } from './render.ts';
+import { IMESSAGE_HELPER_PORT_KEY, type IMessageMessage, type IMessageSourceConfig, type IMessageThread } from './types.ts';
+
+export interface IMessageChatState {
+ committed_to: string | null;
+ window: CoverageWindow | null;
+ /** Days published in the lookback horizon: the page path and the fingerprint it was rendered from. */
+ days: Record<string, { path: string; fp: string }>;
+}
+
+export interface IMessageState extends Record<string, unknown> {
+ /** Keyed by the handle-free chat key, so no handle is stored in the cursor. */
+ chats: Record<string, IMessageChatState>;
+ item_holds?: unknown;
+}
+
+const emptyState = (): IMessageState => ({ chats: {} });
+
+export interface IMessageSyncDeps {
+ /** Test seam: a helper bound to a fake transport. */
+ helper?: IMessageHelper;
+ now?: () => number;
+}
+
+interface Summary extends PublishSummary { status: 'synced' | 'partial'; failedFiles: number }
+
+export function imessageAuthRequired(sourceId: string, cfg: Pick<IMessageSourceConfig, 'tokenEnv'>): OperationError {
+ return new OperationError('apple_helper_unauthorized', `iMessage source ${sourceId} has no GBrain Helper token. Nothing was imported.`,
+ cfg.tokenEnv ? `Set ${cfg.tokenEnv} to the helper's token in the environment that runs the sync, then run: gbrain sync --source ${sourceId}`
+ : `Save the helper's token for gbrain (GBRAIN_CONNECTOR_IMESSAGE_TOKEN, or the 0600 file ~/.gbrain/connectors/imessage.json), then run: gbrain sync --source ${sourceId}`,
+ 'docs/guides/apple-setup.md#apple_helper_unauthorized');
+}
+
+/** A helper failure that stops the run (helper down, token refused, no Full Disk Access, an unknown database), never one chat. */
+const stopsRun = (error: unknown) => runScoped(error) || (error instanceof OperationError && error.code.startsWith('apple_'));
+
+async function helperPort(engine: BrainEngine): Promise<number | null> {
+ const raw = (await engine.getConfig(IMESSAGE_HELPER_PORT_KEY).catch(() => null))?.trim();
+ const port = raw ? Number(raw) : NaN;
+ return Number.isSafeInteger(port) && port >= 1024 && port <= 65535 ? port : null;
+}
+
+export async function runIMessageSync(engine: BrainEngine, sourceId: string, cfg: IMessageSourceConfig, opts: SyncOpts, deps: IMessageSyncDeps = {}): Promise<SyncResult> {
+ return withConnectorSync(engine, sourceId, 'imessage', cfg, opts,
+ async (managed, options) => options.dryRun ? connectorDryRunResult('iMessage', sourceId) : runIMessageSyncInner(engine, sourceId, cfg, options, managed, deps), pendingConnectorResult);
+}
+
+async function runIMessageSyncInner(engine: BrainEngine, sourceId: string, cfg: IMessageSourceConfig, opts: SyncOpts,
+ managed: ManagedConnectorSync | null, deps: IMessageSyncDeps): Promise<SyncResult> {
+ const now = deps.now ?? Date.now;
+ const runStart = now();
+ const runId = randomUUID();
+ let helper = deps.helper;
+ if (!helper) {
+ const port = await helperPort(engine);
+ if (port === null) throw helperNotRunning(sourceId, null, `config ${IMESSAGE_HELPER_PORT_KEY} is not set`);
+ const key = resolveApiToken('imessage', cfg.tokenEnv);
+ if (!key) throw imessageAuthRequired(sourceId, cfg);
+ helper = imessageHelper({ sourceId, port, token: key.token });
+ }
+ const signal = opts.signal;
+ const threads = await helper.threads(signal);
+
+ const [source] = await engine.executeRaw<{ incarnation: string; local_path: string | null; config: Record<string, unknown> }>(
+ 'SELECT incarnation::text AS incarnation,local_path,config FROM sources WHERE id=$1', [sourceId]);
+ const identity = connectorIdentity('imessage', source.config, source.local_path);
+ const cursorKey = connectorDbCursorKey(sourceId, source.incarnation, identity);
+ const state: IMessageState = managed ? { ...emptyState(), ...managed.state<IMessageState>(emptyState()) }
+ : { ...emptyState(), ...(await readConnectorDbCursor(engine, cursorKey)).state as IMessageState | null };
+
+ const summary: Summary = { status: 'synced', added: 0, modified: 0, deleted: 0, chunksCreated: 0, embedded: 0, pagesAffected: [], factsRetired: 0, failedFiles: 0 };
+ const holds = await ConnectorHoldSession.open(engine, sourceId, managed, emptyState(), state.item_holds, { full: opts.full });
+ const newest = () => Object.values(state.chats).map(c => c.committed_to).filter((v): v is string => !!v).sort().at(-1) ?? null;
+ const save = async (final: boolean) => {
+ if (managed) {
+ await managed.saveState(state, final && summary.status === 'synced', final ? newest() ?? undefined : undefined);
+ return;
+ }
+ await writeConnectorDbCursor(engine, cursorKey, state, final ? { run_id: runId, finished_at: new Date(now()).toISOString(),
+ counts: { added: summary.added, modified: summary.modified, deleted: summary.deleted, facts_retired: summary.factsRetired, failed: summary.failedFiles } } : undefined);
+ };
+ // Always the database: message text never reaches a directory, a commit or a push, whatever the brain has.
+ const ctx: ConnectorPublishCtx = { engine, sourceId, managed, summary, label: 'iMessage', tag: 'imessage', record: 'database', dir: null, gated: true };
+ const handle = async (key: string, work: () => Promise<void>, slug: string | null): Promise<boolean> => {
+ try { await work(); holds.succeed(key); return true; } catch (error) {
+ if (stopsRun(error)) throw error;
+ summary.failedFiles++;
+ await holds.fail(key, error, { slug });
+ return false;
+ }
+ };
+
+ const publishDay = async (thread: IMessageThread, chatKey: string, day: string, messages: IMessageMessage[], fp: string) => {
+ const relPath = imessagePagePath(chatKey, day);
+ await publishConnectorPage(ctx, {
+ relPath,
+ markdown: connectorRender(renderIMessageDay({ thread, chatKey, day, timezone: cfg.timezone, messages }), { path: relPath, imessage_chat: chatKey }),
+ commitMessage: `imessage(${sourceId}): ${chatKey} ${day}`,
+ privateMessage: `imessage(${sourceId}): ${chatKey} ${day} is private; database only`,
+ retireReason: 'the iMessage day changed on the Mac',
+ });
+ state.chats[chatKey]!.days[day] = { path: relPath, fp };
+ };
+
+ const deleteDay = async (chatKey: string, day: string) => {
+ const entry = state.chats[chatKey]!.days[day];
+ await deleteConnectorPage(ctx, entry?.path ?? imessagePagePath(chatKey, day), `imessage(${sourceId}): ${chatKey} ${day} has no messages`,
+ 'the iMessage day was deleted on the Mac');
+ delete state.chats[chatKey]!.days[day];
+ };
+
+ const pageExists = async (slug: string) =>
+ (await engine.executeRaw<{ n: number }>('SELECT count(*)::int AS n FROM pages WHERE source_id=$1 AND slug=$2 AND deleted_at IS NULL', [sourceId, slug]))[0]!.n > 0;
+
+ const dayOf = (m: IMessageMessage) => slackDayKey(Date.parse(m.timestamp), cfg.timezone);
+
+ /** One day read again on its own (a day an earlier run held). */
+ const rebuildDay = async (thread: IMessageThread, chatKey: string, day: string) => {
+ const start = slackDayStartMs(day, cfg.timezone);
+ const end = slackDayStartMs(nextSlackDay(day), cfg.timezone);
+ const messages = (await helper!.messages(thread.threadId, new Date(start).toISOString(), signal)).filter(m => Date.parse(m.timestamp) < end && dayOf(m) === day);
+ if (shownMessages(messages).length) await publishDay(thread, chatKey, day, messages, imessageDayFingerprint(thread, day, messages));
+ else if (state.chats[chatKey]!.days[day] || await pageExists(slugifyPath(imessagePagePath(chatKey, day)))) await deleteDay(chatKey, day);
+ };
+
+ const syncChat = async (thread: IMessageThread | null, chatKey: string) => {
+ const ch = state.chats[chatKey] ??= { committed_to: null, window: null, days: {} };
+ if (opts.full) Object.assign(ch, { committed_to: null, window: null });
+ const window = openCoverageWindow(ch, { runStart, historyDays: cfg.historyDays, lookbackDays: cfg.lookbackDays, alignFrom: ms => slackAlignToDay(ms, cfg.timezone) });
+ const from = Date.parse(window.from);
+ const to = Date.parse(window.to);
+ // A chat whose newest message is older than the window is not read: its days in the window have no messages. A chat
+ // the helper lists with no newest-message time is read, so its days are never deleted on a guess.
+ const recent = !!thread && (thread.lastMessageAt === null || Date.parse(thread.lastMessageAt) >= from);
+ const byDay = new Map<string, IMessageMessage[]>();
+ for (const m of recent ? await helper!.messages(thread!.threadId, window.from, signal) : []) {
+ const at = Date.parse(m.timestamp);
+ if (at < from || at >= to) continue;
+ const day = dayOf(m);
+ byDay.set(day, [...byDay.get(day) ?? [], m]);
+ }
+ for (const [day, messages] of [...byDay].sort(([a], [b]) => a.localeCompare(b))) {
+ const key = `${chatKey}/${day}`;
+ if (!holds.shouldAttempt(key) || slackDayStartMs(day, cfg.timezone) < from) continue;
+ if (!shownMessages(messages).length) { byDay.delete(day); continue; }
+ const fp = imessageDayFingerprint(thread!, day, messages);
+ if (!opts.full && ch.days[day]?.fp === fp) continue;
+ await handle(key, () => publishDay(thread!, chatKey, day, messages, fp), slugifyPath(imessagePagePath(chatKey, day)));
+ }
+ for (const day of Object.keys(ch.days)) {
+ const start = slackDayStartMs(day, cfg.timezone);
+ if (byDay.has(day) || start < from || start >= to) continue;
+ await handle(`${chatKey}/${day}`, () => deleteDay(chatKey, day), slugifyPath(ch.days[day]!.path));
+ }
+ if (thread) {
+ // Days held by an earlier run and now outside the window are read again on their own.
+ for (const key of holds.dueHeldKeys()) {
+ const day = key.startsWith(`${chatKey}/`) ? key.slice(chatKey.length + 1) : null;
+ if (!day || !/^\d{4}-\d{2}-\d{2}$/.test(day) || byDay.has(day)) continue;
+ await handle(key, () => rebuildDay(thread, chatKey, day), slugifyPath(imessagePagePath(chatKey, day)));
+ }
+ }
+ const horizon = closeCoverageWindow(ch, cfg.lookbackDays);
+ for (const day of Object.keys(ch.days)) if (slackDayStartMs(nextSlackDay(day), cfg.timezone) <= horizon) delete ch.days[day];
+ };
+
+ try {
+ const listed = new Map(threads.map(thread => [imessageChatKey(thread.threadId), thread]));
+ for (const [chatKey, thread] of listed) {
+ if (!holds.shouldAttempt(chatKey)) continue;
+ await handle(chatKey, () => syncChat(thread, chatKey), null);
+ }
+ // A chat the helper no longer lists (deleted on the Mac) has no messages left; when the list was cut at its limit, an
+ // unlisted chat may only be older, so it is left alone.
+ if (threads.length < IMESSAGE_THREADS_LIMIT) {
+ for (const chatKey of Object.keys(state.chats)) {
+ if (listed.has(chatKey) || !Object.keys(state.chats[chatKey]!.days).length || !holds.shouldAttempt(chatKey)) continue;
+ await handle(chatKey, () => syncChat(null, chatKey), null);
+ }
+ }
+ if (summary.failedFiles > 0) summary.status = 'partial';
+ state.item_holds = holds.finish();
+ await save(true);
+ await holds.complete();
+ if (!managed) {
+ await engine.executeRaw('UPDATE sources SET last_sync_at=now(), newest_content_at=COALESCE($1::timestamptz, newest_content_at) WHERE id=$2', [newest(), sourceId]).catch(() => undefined);
+ }
+ } catch (error) {
+ if (stopsRun(error) && !(error as { name?: string }).name?.startsWith('Lock')) {
+ try { state.item_holds = holds.holds.finish().state; await save(false); } catch { /* the original error is what the caller sees */ }
+ }
+ throw error;
+ }
+
+ await afterConnectorPublish(ctx, opts);
+ return {
+ status: summary.status === 'partial' ? 'partial' : summary.added + summary.modified + summary.deleted > 0 ? 'synced' : 'up_to_date',
+ fromCommit: null, toCommit: '', added: summary.added, modified: summary.modified, deleted: summary.deleted, renamed: 0,
+ chunksCreated: summary.chunksCreated, embedded: summary.embedded, pagesAffected: summary.pagesAffected,
+ ...(summary.failedFiles > 0 ? { failedFiles: summary.failedFiles } : {}),
+ ...(summary.status === 'partial' ? { filesImported: summary.added + summary.modified,
+ reason: summary.failedFiles > 0 ? 'connector_item_failures' as const : signal?.aborted ? 'timeout' as const : 'connector_partial' as const } : {}),
+ ...connectorHoldsResult(sourceId, holds.summary()),
+ };
+}
diff --git a/src/core/imessage/render.ts b/src/core/imessage/render.ts
new file mode 100644
index 0000000000..47494e507e
--- /dev/null
+++ b/src/core/imessage/render.ts
@@ -0,0 +1,110 @@
+/**
+ * One iMessage chat day → one `imessage` page at `imessage/<chat-key>/<yyyy-mm-dd>.md`, in the inline-date chat layout
+ * the conversation parser reads (`**Speaker** (YYYY-MM-DD H:MM AM): text`), the same layout Slack day pages use. The chat
+ * key is a hash of the chat identifier, so no handle appears in a slug, a path or a log line. The day boundary is midnight
+ * in the source's time zone. Every page is `visibility: private` and stamped `source_kind: imessage`, so a copy keeps
+ * the external-untrusted tier.
+ *
+ * Every outside field passes through `neutralizeOutsideText`, and a continuation line shaped like a chat anchor is
+ * escaped, so message text cannot forge another speaker, a timeline line or a gbrain marker. An unsent message is left
+ * out, so the day converges when it is re-read inside the lookback. Nothing run-specific is rendered, so an unchanged
+ * day renders byte-identical and publishes nothing.
+ */
+import { createHash } from 'node:crypto';
+import { dumpFrontmatterYaml } from '../data-frontmatter.ts';
+import { neutralizeOutsideText } from '../outside-content.ts';
+import { BUILTIN_PATTERNS } from '../conversation-parser/builtins.ts';
+import type { IMessageMessage, IMessageThread } from './types.ts';
+
+/** A rendered page larger than this is held, never truncated. */
+export const MAX_IMESSAGE_PAGE_BYTES = 2 * 1024 * 1024;
+/** Bumped when the render changes, so every day in the lookback re-renders once. */
+const RENDER_VERSION = 1;
+
+export class IMessagePageTooLargeError extends Error {
+ readonly code = 'connector_item_too_large';
+ constructor(readonly bytes: number) {
+ super(`the rendered iMessage day page is ${bytes} bytes, over the ${MAX_IMESSAGE_PAGE_BYTES}-byte limit; it was held, not truncated`);
+ this.name = 'IMessagePageTooLargeError';
+ }
+}
+
+/** The stable, handle-free key of a chat. */
+export function imessageChatKey(threadId: string): string {
+ return createHash('sha256').update(`imessage:${threadId}`).digest('hex').slice(0, 16);
+}
+
+export function imessagePagePath(chatKey: string, day: string): string {
+ return `imessage/${chatKey}/${day}.md`;
+}
+
+const inline = (text: string) => neutralizeOutsideText(text.replace(/\s+/g, ' ').trim());
+/** A speaker name inside gbrain's own anchor: no emphasis, colon, bracket or parenthesis can break out of it. */
+const speakerName = (text: string) => inline(text.replace(/[*:()[\]]/g, ' ')) || 'Unknown';
+
+/** The anchor time of a message as the wall clock of the page's time zone, so it agrees with the page's day. */
+function anchorTime(iso: string, zone: string): string {
+ const parts = Object.fromEntries(new Intl.DateTimeFormat('en-US', { timeZone: zone, hourCycle: 'h23', year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' })
+ .formatToParts(new Date(iso)).filter(p => p.type !== 'literal').map(p => [p.type, p.value]));
+ const hour = Number(parts.hour);
+ return `${parts.year}-${parts.month}-${parts.day} ${hour % 12 || 12}:${parts.minute} ${hour < 12 ? 'AM' : 'PM'}`;
+}
+
+export function imessageChatTitle(thread: IMessageThread): string {
+ const name = thread.displayName ?? (thread.participants.length ? thread.participants.join(', ') : 'Unnamed chat');
+ return name.replace(/\s+/g, ' ').trim().slice(0, 120) || 'Unnamed chat';
+}
+
+/** The messages that appear on a page: an unsent message is left out. */
+export const shownMessages = (messages: readonly IMessageMessage[]) => messages.filter(m => !m.retracted);
+
+/** What decides whether a day page changed since its last publish. */
+export function imessageDayFingerprint(thread: IMessageThread, day: string, messages: readonly IMessageMessage[]): string {
+ const rows = shownMessages(messages).map(m => [m.id, m.timestamp, m.isFromMe, m.from ?? '', m.text ?? '', m.textStatus, m.hasAttachments, m.editedAt ?? '']);
+ return createHash('sha256').update(JSON.stringify([RENDER_VERSION, imessageChatTitle(thread), thread.isGroup, day, rows])).digest('hex').slice(0, 32);
+}
+
+function messageLines(m: IMessageMessage, thread: IMessageThread, zone: string): string[] {
+ const speaker = speakerName(m.isFromMe ? 'Me' : m.from ?? (thread.isGroup ? 'Unknown' : thread.displayName ?? thread.participants[0] ?? 'Unknown'));
+ const body = m.textStatus === 'undecodable' ? '_(message could not be decoded)_'
+ : neutralizeOutsideText((m.text ?? '').split('\n').map(line => line.trimStart()).filter(Boolean).join('\n'));
+ const lines = body ? body.split('\n') : [];
+ if (m.hasAttachments) lines.push('[attachment]');
+ if (!lines.length) lines.push('_(no text)_');
+ for (let i = 1; i < lines.length; i++) if (BUILTIN_PATTERNS.some(p => p.regex.test(lines[i]!))) lines[i] = `\\${lines[i]}`;
+ const edited = m.editedAt ? ' _(edited)_' : '';
+ lines[lines.length - 1] += edited;
+ return [`**${speaker}** (${anchorTime(m.timestamp, zone)}): ${lines[0]}`, ...lines.slice(1)];
+}
+
+export interface IMessageDayInput {
+ thread: IMessageThread;
+ chatKey: string;
+ day: string;
+ timezone: string;
+ /** The day's messages, oldest first. */
+ messages: readonly IMessageMessage[];
+}
+
+export function renderIMessageDay(input: IMessageDayInput): string {
+ const shown = shownMessages(input.messages);
+ const title = imessageChatTitle(input.thread);
+ const frontmatter: Record<string, unknown> = {
+ type: 'imessage',
+ title: `${title} ${input.day}`,
+ date: input.day,
+ timezone: input.timezone,
+ connector: 'imessage',
+ source_kind: 'imessage',
+ imessage_chat: input.chatKey,
+ group: input.thread.isGroup,
+ messages: shown.length,
+ visibility: 'private',
+ };
+ const lines = [`# ${inline(title)} ${input.day}`, '', `**Chat:** ${inline(title)} · **Day:** ${input.day} (${input.timezone}) · **Messages:** ${shown.length}`, '',
+ ...shown.flatMap(m => messageLines(m, input.thread, input.timezone))];
+ const page = `---\n${dumpFrontmatterYaml(frontmatter, { lineWidth: 1000 })}---\n\n${lines.join('\n')}\n`;
+ const bytes = Buffer.byteLength(page, 'utf8');
+ if (bytes > MAX_IMESSAGE_PAGE_BYTES) throw new IMessagePageTooLargeError(bytes);
+ return page;
+}
diff --git a/src/core/imessage/source-add.ts b/src/core/imessage/source-add.ts
new file mode 100644
index 0000000000..e1de1989a3
--- /dev/null
+++ b/src/core/imessage/source-add.ts
@@ -0,0 +1,24 @@
+/** `sources add --kind imessage`: the registered config. Always database-recorded, so it takes no directory and no record mode. */
+import { SYNC_INTERVAL_MIN_FLOOR } from '../meetings/types.ts';
+
+export interface AddSourceIMessageOpts {
+ historyDays?: number;
+ lookbackDays?: number;
+ syncIntervalMin?: number;
+ tokenEnv?: string;
+ timezone?: string;
+}
+
+/** The `sources.config` a new imessage source is registered with. Only non-default tuning keys are written; no token ever is. */
+export function imessageSourceConfig(opts: AddSourceIMessageOpts, federated: boolean | null | undefined): Record<string, unknown> {
+ return {
+ kind: 'imessage',
+ ...(opts.historyDays !== undefined ? { i_history_days: opts.historyDays } : {}),
+ ...(opts.lookbackDays !== undefined ? { i_lookback_days: opts.lookbackDays } : {}),
+ ...(opts.timezone && opts.timezone !== 'UTC' ? { i_timezone: opts.timezone } : {}),
+ ...(opts.tokenEnv ? { i_token_env: opts.tokenEnv } : {}),
+ ...(opts.syncIntervalMin !== undefined ? { sync_interval_min: Math.max(SYNC_INTERVAL_MIN_FLOOR, opts.syncIntervalMin) } : {}),
+ // Messages join unqualified reads only when the owner asks (--federated), as Slack channels do.
+ federated: federated ?? false,
+ };
+}
diff --git a/src/core/imessage/source-config.ts b/src/core/imessage/source-config.ts
new file mode 100644
index 0000000000..49a3d6438e
--- /dev/null
+++ b/src/core/imessage/source-config.ts
@@ -0,0 +1,17 @@
+/** Parse an imessage source's `sources.config`. Dependency-light so the connector identity can import it. */
+import { syncIntervalMinutes } from '../meetings/source-config.ts';
+import { isValidTimeZone } from '../slack/source-config.ts';
+import { IMESSAGE_DEFAULT_HISTORY_DAYS, IMESSAGE_DEFAULT_LOOKBACK_DAYS, IMESSAGE_DEFAULT_SYNC_INTERVAL_MIN, type IMessageSourceConfig } from './types.ts';
+
+const positiveInt = (value: unknown, fallback: number, max: number): number =>
+ typeof value === 'number' && Number.isFinite(value) && value >= 1 ? Math.min(max, Math.floor(value)) : fallback;
+
+export function parseIMessageSourceConfig(config: Record<string, unknown>): IMessageSourceConfig {
+ return {
+ historyDays: positiveInt(config.i_history_days, IMESSAGE_DEFAULT_HISTORY_DAYS, 3650),
+ lookbackDays: positiveInt(config.i_lookback_days, IMESSAGE_DEFAULT_LOOKBACK_DAYS, 60),
+ timezone: typeof config.i_timezone === 'string' && isValidTimeZone(config.i_timezone) ? config.i_timezone : 'UTC',
+ ...(typeof config.i_token_env === 'string' && config.i_token_env.trim() ? { tokenEnv: config.i_token_env.trim() } : {}),
+ syncIntervalMin: syncIntervalMinutes(config, IMESSAGE_DEFAULT_SYNC_INTERVAL_MIN)!,
+ };
+}
diff --git a/src/core/imessage/types.ts b/src/core/imessage/types.ts
new file mode 100644
index 0000000000..aa1be9a856
--- /dev/null
+++ b/src/core/imessage/types.ts
@@ -0,0 +1,49 @@
+/**
+ * iMessage source kind (`sources.config.kind = 'imessage'`): one page per chat per day, read from the GBrain Helper
+ * running on the same Mac over 127.0.0.1. The source is always owner-only (access/owner-only.ts), every page is
+ * `visibility: private` and the database is always its record, so message text never reaches a Git checkout, even
+ * on a brain that has one. The text is other people's words, so the pages carry the external-untrusted tier.
+ */
+
+export const IMESSAGE_DEFAULT_HISTORY_DAYS = 30;
+/** Recent days re-read every run, so edits and unsends converge. */
+export const IMESSAGE_DEFAULT_LOOKBACK_DAYS = 7;
+export const IMESSAGE_DEFAULT_SYNC_INTERVAL_MIN = 15;
+/** The brain config key holding the helper's loopback port. */
+export const IMESSAGE_HELPER_PORT_KEY = 'apple.helper.port';
+
+export interface IMessageSourceConfig {
+ historyDays: number;
+ lookbackDays: number;
+ /** The IANA zone whose midnight starts a day page. */
+ timezone: string;
+ /** An environment variable holding the helper token, read instead of the credential store. Excluded from the identity. */
+ tokenEnv?: string;
+ /** Minutes between scheduled syncs. Excluded from the identity. */
+ syncIntervalMin: number;
+}
+
+/** A chat as the helper lists it. `threadId` is the chat identifier (a handle or a group id): never rendered or logged. */
+export interface IMessageThread {
+ threadId: string;
+ displayName: string | null;
+ participants: string[];
+ isGroup: boolean;
+ lastMessageAt: string | null;
+}
+
+export interface IMessageMessage {
+ /** The message guid. */
+ id: string;
+ rowid: number;
+ /** ISO 8601 UTC. */
+ timestamp: string;
+ isFromMe: boolean;
+ text: string | null;
+ textStatus: 'ok' | 'empty' | 'undecodable';
+ /** The sender's handle in a group chat; null for the owner or a one-to-one chat. */
+ from: string | null;
+ hasAttachments: boolean;
+ editedAt: string | null;
+ retracted: boolean;
+}
diff --git a/src/core/persistence/connector-errors.ts b/src/core/persistence/connector-errors.ts
index 34cdd94ead..f668828fc8 100644
--- a/src/core/persistence/connector-errors.ts
+++ b/src/core/persistence/connector-errors.ts
@@ -60,6 +60,11 @@ export function connectorAccountChanged(sourceId: string, kind: ConnectorKind, c
replace = `add a new source for the new workspace (gbrain sources add <new-id> --kind slack --channels ${slack.channels.join(',')}), then archive this one: gbrain sources archive ${sourceId}`;
break;
}
+ case 'imessage': {
+ restore = `restore the GBrain Helper token GBrain reads for ${show(recorded)}, then retry: gbrain sync --source ${sourceId}`;
+ replace = `add a new source (gbrain sources add <new-id> --kind imessage), then archive this one: gbrain sources archive ${sourceId}`;
+ break;
+ }
default: return assertNever(kind);
}
// Account emails and installation ids stay in the local suggestion: job records persist and serve the message remotely.
diff --git a/src/core/persistence/connector-identity.ts b/src/core/persistence/connector-identity.ts
index 67679a198d..a4e58f9d6e 100644
--- a/src/core/persistence/connector-identity.ts
+++ b/src/core/persistence/connector-identity.ts
@@ -29,12 +29,14 @@ import { parseMeetingsSourceConfig } from '../meetings/source-config.ts';
import type { MeetingsSourceConfig } from '../meetings/types.ts';
import { parseSlackSourceConfig } from '../slack/source-config.ts';
import type { SlackSourceConfig } from '../slack/types.ts';
+import { parseIMessageSourceConfig } from '../imessage/source-config.ts';
+import type { IMessageSourceConfig } from '../imessage/types.ts';
import { assertNever } from '../types.ts';
import type { ConnectorKind } from './connector-kinds.ts';
export { CONNECTOR_KINDS_SQL, CONNECTOR_SOURCE_KINDS, isConnectorSourceKind, type ConnectorKind } from './connector-kinds.ts';
-export type ConnectorConfig = GoogleSourceConfig | GitHubSourceConfig | MeetingsSourceConfig | SlackSourceConfig;
+export type ConnectorConfig = GoogleSourceConfig | GitHubSourceConfig | MeetingsSourceConfig | SlackSourceConfig | IMessageSourceConfig;
type LeafClass = 'identity' | 'excluded';
/** An identity leaf left out of the digest while it holds the default it was introduced with (#6561). */
interface ElidedLeaf { elideWhen: unknown }
@@ -47,7 +49,8 @@ const underAuto = (config: GitHubSourceConfig): LeafClass => config.scope === 'a
* output and fails on a leaf missing here; an unlisted leaf still joins the
* identity at runtime, never the exclusion list.
*/
-export const CONNECTOR_LEAF_RULES: { google: Record<string, LeafClass | ElidedLeaf>; github: Record<string, Rule>; meetings: Record<string, LeafClass>; slack: Record<string, LeafClass> } = {
+export const CONNECTOR_LEAF_RULES: { google: Record<string, LeafClass | ElidedLeaf>; github: Record<string, Rule>; meetings: Record<string, LeafClass>; slack: Record<string, LeafClass>;
+ imessage: Record<string, LeafClass> } = {
google: {
account: 'identity', services: 'identity', historyDays: 'identity', futureDays: 'identity', calendarId: 'identity', dir: 'identity',
contactsDir: { elideWhen: DEFAULT_CONTACTS_DIR },
@@ -69,6 +72,11 @@ export const CONNECTOR_LEAF_RULES: { google: Record<string, LeafClass | ElidedLe
// Where the token lives, the schedule and the per-run request cap never change what a sweep reads; the account pin covers a swapped token.
tokenEnv: 'excluded', syncIntervalMin: 'excluded', maxRequests: 'excluded',
},
+ imessage: {
+ historyDays: 'identity', lookbackDays: 'identity', timezone: 'identity',
+ // Where the helper token lives and the schedule never change what a sweep reads.
+ tokenEnv: 'excluded', syncIntervalMin: 'excluded',
+ },
};
/** Leaf paths of a parsed config: nested objects flatten to dotted keys; arrays and null are leaves. */
@@ -118,6 +126,7 @@ export function parseConnectorConfig(kind: ConnectorKind, raw: Record<string, un
case 'github': return parseGitHubSourceConfig(raw, localPath ?? '');
case 'meetings': return parseMeetingsSourceConfig(raw, localPath ?? '');
case 'slack': return parseSlackSourceConfig(raw, localPath ?? '');
+ case 'imessage': return parseIMessageSourceConfig(raw);
default: return assertNever(kind);
}
}
diff --git a/src/core/persistence/connector-kinds.ts b/src/core/persistence/connector-kinds.ts
index 857f51bea8..ba95011036 100644
--- a/src/core/persistence/connector-kinds.ts
+++ b/src/core/persistence/connector-kinds.ts
@@ -4,9 +4,9 @@
* kind list and kind branch reads these: a literal kind list elsewhere fails
* test/connector-kind-routing.test.ts.
*/
-export type ConnectorKind = 'google' | 'github' | 'meetings' | 'slack';
+export type ConnectorKind = 'google' | 'github' | 'meetings' | 'slack' | 'imessage';
-export const CONNECTOR_SOURCE_KINDS: readonly ConnectorKind[] = ['google', 'github', 'meetings', 'slack'];
+export const CONNECTOR_SOURCE_KINDS: readonly ConnectorKind[] = ['google', 'github', 'meetings', 'slack', 'imessage'];
/** A connector source kind (`sources.config.kind`). */
export function isConnectorSourceKind(kind: unknown): kind is ConnectorKind { return CONNECTOR_SOURCE_KINDS.includes(kind as ConnectorKind); }
/** The `sources.config` key holding a connector source's directory. */
@@ -16,8 +16,9 @@ export function connectorDirKey(kind: ConnectorKind): string {
case 'github': return 'gh_dir';
case 'meetings': return 'm_dir';
case 'slack': return 's_dir';
+ case 'imessage': return 'i_dir';
default: { const unhandled: never = kind; throw new Error(`Unhandled connector kind: ${String(unhandled)}`); }
}
}
-/** The connector kinds as a quoted SQL list (`'google','github','meetings','slack'`): every SQL filter on connector kinds interpolates it. */
+/** The connector kinds as a quoted SQL list (`'google','github','meetings','slack','imessage'`): every SQL filter on connector kinds interpolates it. */
export const CONNECTOR_KINDS_SQL = CONNECTOR_SOURCE_KINDS.map(kind => `'${kind}'`).join(',');
diff --git a/src/core/persistence/connector-sync.ts b/src/core/persistence/connector-sync.ts
index 2ebed8f1c1..a3e7556aae 100644
--- a/src/core/persistence/connector-sync.ts
+++ b/src/core/persistence/connector-sync.ts
@@ -273,7 +273,7 @@ async function strictPrivateFile(engine: BrainEngine, row: Pick<WriteRequest, 's
/** #9552: the connectors whose imports queue fact extraction, as an unmanaged sync does; never Google mail or GitHub. */
function factsConnector(connector: ConnectorKind): boolean {
- return connector === 'slack' || connector === 'meetings';
+ return connector === 'slack' || connector === 'meetings' || connector === 'imessage';
}
export async function beginConnectorSync(engine: BrainEngine, sourceId: string, connector: ConnectorKind,
diff --git a/src/core/persistence/git-push-holds.ts b/src/core/persistence/git-push-holds.ts
index bdc8b92c4f..148914ca0e 100644
--- a/src/core/persistence/git-push-holds.ts
+++ b/src/core/persistence/git-push-holds.ts
@@ -13,7 +13,7 @@ import { readFix } from '../ops/op-fix.ts';
import { readIntegrateConflict, type IntegrateConflictState } from '../git/commit-push.ts';
/** The error codes of a Git effect whose commit is local but whose push did not land. */
-export const GIT_PUSH_CODES = ['git_push_unavailable', 'push_unconfirmed', 'integrate_conflict', 'publish_secret_found', 'publish_scan_unreadable'] as const;
+export const GIT_PUSH_CODES = ['git_push_unavailable', 'push_unconfirmed', 'integrate_conflict', 'publish_secret_found', 'publish_scan_unreadable', 'push_credential_refused'] as const;
export interface GitPushHold {
source_id: string;
diff --git a/src/core/persistence/managed-sources.ts b/src/core/persistence/managed-sources.ts
index 7fec36793c..1e4c730527 100644
--- a/src/core/persistence/managed-sources.ts
+++ b/src/core/persistence/managed-sources.ts
@@ -9,6 +9,7 @@ import { runManagedSourceLifecycle, type SourceLifecycleInput } from './source-l
import { isValidSourceId } from '../source-id.ts';
import { chooseMeetingsRecord, meetingsSourceConfig } from '../meetings/source-add.ts';
import { slackSourceConfig } from '../slack/source-add.ts';
+import { imessageSourceConfig } from '../imessage/source-add.ts';
import { WRITE_ERROR_CODES, type WriteErrorCode } from './types.ts';
export function assertTopologyCommitted(result:Record<string,unknown>):void{
@@ -23,7 +24,7 @@ export function assertTopologyCommitted(result:Record<string,unknown>):void{
export function managedSourceAddInput(opts:AddSourceOpts):SourceLifecycleInput{
if(!isValidSourceId(opts.id))throw new OperationError('invalid_params','A valid explicit source ID is required.',
'Pass a source id of 1-32 lowercase letters, digits and inner hyphens (for example "notes" or "acme-wiki").');
- const connectors=[opts.github,opts.google,opts.meetings,opts.slack].filter(Boolean).length;
+ const connectors=[opts.github,opts.google,opts.meetings,opts.slack,opts.imessage].filter(Boolean).length;
if(opts.remoteUrl&&opts.localPath||connectors>1||connectors&&(opts.remoteUrl||opts.localPath))
throw new OperationError('invalid_params','Choose exactly one source location: path, remote URL, GitHub, Google, meetings, or Slack.',
`Add source ${opts.id} with exactly one of a local path, a Git remote URL, or one connector (GitHub, Google, meetings, Slack).`);
@@ -58,8 +59,9 @@ export function managedSourceAddInput(opts:AddSourceOpts):SourceLifecycleInput{
path=choice.dir??undefined;
config=slackSourceConfig(opts.slack,choice,opts.federated,true);
}
+ if(opts.imessage){path=undefined;config=imessageSourceConfig(opts.imessage,opts.federated);}
return {operation:'add',sourceId:opts.id,path,name:opts.name,config,remoteUrl:opts.remoteUrl,
- createDirectory:!!(opts.github||opts.google||(opts.meetings||opts.slack)&&path),requireGitContent:!!(path&&!opts.remoteUrl&&!opts.github&&!opts.google&&!opts.meetings&&!opts.slack&&!opts.force),requestId:opts.requestId,expectedIncarnation:opts.expectedIncarnation};
+ createDirectory:!!(opts.github||opts.google||(opts.meetings||opts.slack)&&path),requireGitContent:!!(path&&!opts.remoteUrl&&!opts.github&&!opts.google&&!opts.meetings&&!opts.slack&&!opts.imessage&&!opts.force),requestId:opts.requestId,expectedIncarnation:opts.expectedIncarnation};
}
export async function addManagedSource(engine:BrainEngine,opts:AddSourceOpts):Promise<SourceRow>{
const result=await runManagedSourceLifecycle(engine,managedSourceAddInput(opts));
diff --git a/src/core/persistence/page-visibility.ts b/src/core/persistence/page-visibility.ts
index ea4c5fae55..0f7bc8a02f 100644
--- a/src/core/persistence/page-visibility.ts
+++ b/src/core/persistence/page-visibility.ts
@@ -13,6 +13,7 @@ import type { BrainEngine } from '../engine.ts';
import { noGrantFloorReads } from '../source-resolver.ts';
import { hasScope } from '../scope.ts';
import { viewedEngine } from './switches.ts';
+import { ANY_OWNER_ONLY_SQL, ownerOnlySourceSql, ownerOnlySourcesPresent, sourceIsOwnerOnly } from '../access/owner-only.ts';
/** Publication uses fresh policy, independent of the read-side telemetry cache (read through the resolver). */
export async function excludesPrivateWrites(engine: SqlEngine, remote: boolean): Promise<boolean> {
@@ -45,15 +46,24 @@ export async function authorizePageVisibility(engine: SqlEngine, authority: Writ
const excludePrivate = authority.excludePrivate ?? true;
const hiddenSql = `SELECT (page_readers IS NOT NULL OR folder_rule_ids IS NOT NULL) FROM pages
WHERE source_id=$1 AND slug=$2 AND NOT (${readPolicyFragment('pages', [], true)}) LIMIT 1`;
- let probe: { any_labelled?: boolean; identity_may_open: boolean | null } | undefined;
+ // The owner-only tests (access/owner-only.ts) ride on the same read, so a write on a brain with no owner-only source
+ // costs no extra statement; an unreadable probe reads them live, and an unreadable live read counts as owner-only.
+ let probe: { any_labelled?: boolean; identity_may_open: boolean | null; owner_only_source?: boolean; owner_only_any?: boolean } | undefined;
if (excludePrivate) {
try {
- [probe] = await engine.executeRaw<{ any_labelled: boolean; identity_may_open: boolean | null }>(
- `SELECT EXISTS (SELECT 1 FROM access_members WHERE labelled_only) AS any_labelled, (${hiddenSql}) AS identity_may_open`, [authority.sourceId, slug]);
+ [probe] = await engine.executeRaw<{ any_labelled: boolean; identity_may_open: boolean | null; owner_only_source: boolean; owner_only_any: boolean }>(
+ `SELECT EXISTS (SELECT 1 FROM access_members WHERE labelled_only) AS any_labelled, (${hiddenSql}) AS identity_may_open,
+ ${ownerOnlySourceSql('$1')} AS owner_only_source, ${ANY_OWNER_ONLY_SQL} AS owner_only_any`, [authority.sourceId, slug]);
} catch {
probe = undefined;
}
}
+ // An owner-only source takes remote writes only from the owner speaking for itself, so no other credential plants,
+ // rewrites or probes a page there; the refusal reads like any page it may not see.
+ if ((probe?.owner_only_source ?? await sourceIsOwnerOnly(engine, authority.sourceId)) && !await storedOwnerSpeaksForItself(engine, authority)) {
+ throw pageNotVisibleError();
+ }
+ const ownerOnlyPresent = probe?.owner_only_any;
const anyLabelled = excludePrivate ? probe?.any_labelled ?? true : await anyLabelledOnlyMember(engine);
const labelled = anyLabelled && await writerLabelledOnly(engine, authority, await writerIdentities(engine, authority));
// GST-2091: the owner's own page write (storedOwnerWrite) to a live page is held to member access without the privacy
@@ -74,7 +84,7 @@ export async function authorizePageVisibility(engine: SqlEngine, authority: Writ
const hidePrivate = excludePrivate || !policy.privacyRelaxed;
if (!hidePrivate && !policy.restricted && !labelled) return;
const hiddenUnder = async (hide: boolean) => (await engine.executeRaw(`SELECT 1 FROM pages WHERE source_id=$1 AND slug=$2
- AND NOT (${await writerReadPolicySql(engine, authority, 'pages', hide, policy.restricted)}) LIMIT 1`, [authority.sourceId, slug])).length > 0;
+ AND NOT (${await writerReadPolicySql(engine, authority, 'pages', hide, policy.restricted, ownerOnlyPresent)}) LIMIT 1`, [authority.sourceId, slug])).length > 0;
if (!await hiddenUnder(hidePrivate && owner !== true)) return;
if (hidePrivate && owner === undefined && await ownerOnLivePage() && !await hiddenUnder(false)) return;
throw pageNotVisibleError();
@@ -87,11 +97,13 @@ export async function authorizePageVisibility(engine: SqlEngine, authority: Writ
* pages that name it too, the same rule its reads follow.
*/
export async function writerReadPolicySql(engine: SqlEngine, authority: WriteAuthority, pageAlias: string, hidePrivate: boolean,
- restricted?: boolean): Promise<string> {
+ restricted?: boolean, ownerOnlyPresent?: boolean): Promise<string> {
restricted ??= (await readRemotePolicyNow(engine)).restricted;
const identities = restricted ? await writerIdentities(engine, authority) : [[]];
const folder = restricted ? await folderAccessForAll(engine, identities) : { satisfiedRuleIds: [], folderCoverage: [] };
- const fragment = withCallerAccess({ folderCoverage: folder.folderCoverage }, () => readPolicyFragment(pageAlias, { all: identities }, hidePrivate, folder.satisfiedRuleIds));
+ const owner = (ownerOnlyPresent ?? await ownerOnlySourcesPresent(engine)) && await storedOwnerSpeaksForItself(engine, authority);
+ const fragment = withCallerAccess({ folderCoverage: folder.folderCoverage, ...(owner ? { owner: true } : {}) },
+ () => readPolicyFragment(pageAlias, { all: identities }, hidePrivate, folder.satisfiedRuleIds));
if (!restricted || !await anyLabelledOnlyMember(engine) || !await writerLabelledOnly(engine, authority, identities)) return fragment;
return `(${fragment} AND ${labelledOnlyForSql(pageAlias, identities, folder.satisfiedRuleIds)})`;
}
diff --git a/src/core/persistence/reconcile-prepare.ts b/src/core/persistence/reconcile-prepare.ts
index 37e605f450..026db1d538 100644
--- a/src/core/persistence/reconcile-prepare.ts
+++ b/src/core/persistence/reconcile-prepare.ts
@@ -30,6 +30,7 @@ import { assertAutoDecisions } from './reconcile-additive.ts';
import { admissionAllows, readSyncAdmission } from './sync-admission.ts';
import { bindOrigin } from './origin-guard.ts';
import { materializedSnapshot } from './segmented-apply.ts';
+import { sourceMirrorReadOnly } from './mirror-read-only.ts';
const pageFix = (sourceId: string, slug: string): Action => readFix(`Shows page ${slug} in source ${sourceId} as stored now, with its revision, read-only.`,
{ argv: ['gbrain', 'get', '--source', sourceId, '--', slug] });
@@ -167,9 +168,11 @@ export async function prepareReconcileMutation(engine: BrainEngine, row: WriteRe
? fileWinsContent(state.raw.toString('utf8'), state.file, prepared.result, text => readCanonicalFileText(state, row.slug, text), { sourceId: row.source_id, slug: row.slug })
: serializePageToMarkdown({ ...state.snapshot.page, ...prepared.result }, prepared.result.tags);
const ready = prepared.ready;
+ // A read-only mirror's checkout is never written: a file-wins result that keeps the file's exact bytes imports into the page database-only.
+ const mirror = row.intent.keep_file_bytes === true && !absent && sha256(content) === state.pins.raw_file_hash && await sourceMirrorReadOnly(engine, row.source_id);
return {
observedRevision: state.snapshot.revision, trust: await ownerImportTrust(engine, row, prepared.result.frontmatter, state.path),
- file: { path: state.path, root: state.root, content, expectedBeforeHash: absent ? null : state.pins.raw_file_hash },
+ ...(mirror ? { databaseOnlyReason: 'mirror_read_only' as const } : { file: { path: state.path, root: state.root, content, expectedBeforeHash: absent ? null : state.pins.raw_file_hash } }),
// A database-only page matched by its slug path always records that file as its origin.
noop: ready.noop && sha256(content) === state.pins.raw_file_hash && state.origin === 'recorded',
...(ready.afterCommit ? { afterCommit: (target: BrainEngine) => ready.afterCommit!(target) } : {}),
diff --git a/src/core/pglite-schema.generated.ts b/src/core/pglite-schema.generated.ts
index 942503053b..81e3952839 100644
--- a/src/core/pglite-schema.generated.ts
+++ b/src/core/pglite-schema.generated.ts
@@ -3002,7 +3002,7 @@ BEGIN
FOR f IN SELECT p.oid::regprocedure AS sig, substr(c.setting, 13) AS path
FROM pg_proc p JOIN pg_namespace n ON n.oid = p.pronamespace CROSS JOIN LATERAL unnest(p.proconfig) AS c(setting)
WHERE n.nspname = 'public' AND p.prokind = 'f' AND c.setting IN ('search_path=pg_catalog, public', 'search_path=pg_catalog')
- AND p.proname IN ('auto_enable_rls', 'bump_page_generation_clock_fn', 'bump_page_generation_fn', 'enforce_minion_queue_protocol', 'gbrain_access_derive_page_readers', 'gbrain_access_folder_rules', 'gbrain_access_lineage_rules', 'gbrain_access_mark_restricted', 'gbrain_access_norm_readers', 'gbrain_access_origin_closed_for', 'gbrain_access_origin_hidden_for', 'gbrain_access_origin_labelled_for', 'gbrain_access_origin_restricted', 'gbrain_access_pending_covers', 'gbrain_access_readers', 'gbrain_access_refresh_serves', 'gbrain_access_refresh_serves_trigger', 'gbrain_access_stamp_folder_rules', 'gbrain_access_state_unreadable', 'gbrain_advance_page_revision', 'gbrain_advance_tag_revision', 'gbrain_bump_trust_generation', 'gbrain_clear_atom_page_state', 'gbrain_concept_inputs_private', 'gbrain_count_git_canonical_sources', 'gbrain_count_modifications', 'gbrain_forget_page_retrievals', 'gbrain_fts_input', 'gbrain_graduation_fence', 'gbrain_guard_deferred_request', 'gbrain_guard_effect_protocol', 'gbrain_guard_guest_records', 'gbrain_guard_inserted_facts', 'gbrain_guard_protocol_activation', 'gbrain_guard_request_protocol', 'gbrain_guard_skill_publication', 'gbrain_lease_shared_skill_delivery', 'gbrain_mark_derivation_scope_entry', 'gbrain_preserve_fact_withdrawal', 'gbrain_queue_page_projection', 'gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take', 'gbrain_refuse_purging_derivation', 'gbrain_release_refresh_barrier', 'gbrain_require_managed_writer', 'gbrain_require_persistence_protocol', 'gbrain_snapshot_version_trust', 'gbrain_stamp_revision_attribution', 'gbrain_stamp_trust_tier', 'gbrain_stamp_version_attribution', 'gbrain_stamp_write_attribution', 'gbrain_try_jsonb', 'notify_minion_job_change', 'update_chunk_search_vector', 'update_page_search_vector')
+ AND p.proname IN ('auto_enable_rls', 'bump_page_generation_clock_fn', 'bump_page_generation_fn', 'enforce_minion_queue_protocol', 'gbrain_access_derive_page_readers', 'gbrain_access_folder_rules', 'gbrain_access_lineage_rules', 'gbrain_access_mark_restricted', 'gbrain_access_norm_readers', 'gbrain_access_origin_closed_for', 'gbrain_access_origin_hidden_for', 'gbrain_access_origin_labelled_for', 'gbrain_access_origin_restricted', 'gbrain_access_pending_covers', 'gbrain_access_readers', 'gbrain_access_refresh_serves', 'gbrain_access_refresh_serves_trigger', 'gbrain_access_stamp_folder_rules', 'gbrain_access_state_unreadable', 'gbrain_advance_page_revision', 'gbrain_advance_tag_revision', 'gbrain_bump_trust_generation', 'gbrain_clear_atom_page_state', 'gbrain_concept_inputs_private', 'gbrain_count_git_canonical_sources', 'gbrain_count_modifications', 'gbrain_forget_page_retrievals', 'gbrain_fts_input', 'gbrain_graduation_fence', 'gbrain_guard_deferred_request', 'gbrain_guard_effect_protocol', 'gbrain_guard_guest_records', 'gbrain_guard_inserted_facts', 'gbrain_guard_protocol_activation', 'gbrain_guard_request_protocol', 'gbrain_guard_skill_publication', 'gbrain_lease_shared_skill_delivery', 'gbrain_mark_derivation_scope_entry', 'gbrain_owner_only_lineage', 'gbrain_preserve_fact_withdrawal', 'gbrain_queue_page_projection', 'gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take', 'gbrain_refuse_purging_derivation', 'gbrain_release_refresh_barrier', 'gbrain_require_managed_writer', 'gbrain_require_persistence_protocol', 'gbrain_snapshot_version_trust', 'gbrain_stamp_revision_attribution', 'gbrain_stamp_trust_tier', 'gbrain_stamp_version_attribution', 'gbrain_stamp_write_attribution', 'gbrain_try_jsonb', 'notify_minion_job_change', 'update_chunk_search_vector', 'update_page_search_vector')
AND pg_has_role(current_user, p.proowner, 'USAGE')
ORDER BY 1
LOOP
diff --git a/src/core/repair/file-drift-class.ts b/src/core/repair/file-drift-class.ts
new file mode 100644
index 0000000000..480bfda24b
--- /dev/null
+++ b/src/core/repair/file-drift-class.ts
@@ -0,0 +1,458 @@
+/**
+ * `gbrain repair file-drift --source <id> --held --side unknown|database|both --prefer file --whole-class [--apply --expect <hash> --yes]`:
+ * settle one whole class of held `file_drift` pages with one approval. A `--held` preview covers one window of 200 pages; a
+ * large read-only mirror holds thousands, so approving it window by window was not practical.
+ *
+ * The preview walks every window of the source's held pages of the side (keyset reads in held-path order, one batched Git
+ * read of the window's commit evidence), runs each page through the same live read, newer-side rule and reconcile preparation
+ * as a window preview, and writes one manifest with the private artifact writer (`repair-previews/file-drift/class-<hash>.json`):
+ * per page its slug, path, page revision, file blob (sha256 of the file's bytes), hold code, side, upstream version and the
+ * lines the page holds that its file does not carry, plus the gbrain, file-drift and reconcile versions and the mirror flag.
+ * A run that stops early (deadline, kill) leaves a partial manifest (`complete: false`) and prints its resume command; only a
+ * complete manifest prints an apply command, and only it is saved for approval. Kept out of the class, each with its next step:
+ * - `kept_newer_page`: the page changed in gbrain after its file's last commit; it is never replaced in bulk.
+ * - `kept_protected_parts`: on a read-only mirror, letting the file win would append gbrain's protected parts to the file,
+ * and the checkout is never written, so the page stays held.
+ *
+ * The apply (trusted local CLI only, the user's yes on the preview hash) re-reads each page and applies it only when its pins
+ * (revision, file blob, hold code, side, upstream version, mirror flag) still hold and its lost lines did not grow; it binds
+ * no timestamp, so a sync that only rewrote hold records keeps the approval. Each page goes through the reconcile apply,
+ * which saves the replaced page as a page version (`gbrain revert`) and keeps reconcile's private backup; on a read-only mirror
+ * the file's bytes are imported into the page database-only and the checkout is never written. One apply per manifest at a
+ * time (a lock in the progress record); progress is saved per window under the manifest hash, request ids derive from the hash
+ * and the slug, so a rerun after a kill applies no page twice and resumes at the next window.
+ */
+import { existsSync, lstatSync, readdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';
+import { randomUUID } from 'node:crypto';
+import { hostname } from 'node:os';
+import { join } from 'node:path';
+import type { BrainEngine } from '../engine.ts';
+import { configDir } from '../config.ts';
+import { OperationError, opError, type OperationContext } from '../ops/contract.ts';
+import { readFix, trustedCliRequired } from '../ops/op-fix.ts';
+import { shellQuote } from '../agent-output.ts';
+import { VERSION } from '../../version.ts';
+import { digest, stableJson } from '../persistence/digest.ts';
+import { clearApprovedSet, loadApprovedSet, previewHash, saveApprovedSet } from '../persistence/preview-approval.ts';
+import { assertReconcileOutputPath } from '../persistence/reconcile-backup.ts';
+import { canonicalFilesystemPath } from '../persistence/root-registry.ts';
+import { sourceMirrorReadOnly } from '../persistence/mirror-read-only.ts';
+import { getWorktreeBinding } from '../persistence/ownership.ts';
+import { journalLimitKey, readJournalLimits } from '../persistence/limits.ts';
+import { FILE_DRIFT_VERSION, fileDriftSide, GIT_HOLD_OP, readGitHold, type GitHoldRecord } from '../persistence/sync-holds.ts';
+import { authorizeReconcile, runReconcileApply } from '../persistence/reconcile.ts';
+import { acceptedPendingReceipt } from '../persistence/accepted-pending.ts';
+import type { ProgressReporter } from '../progress.ts';
+import { fileCommitEvidenceBatch, heldLiveDrift, readDriftEvidence, type CommitEvidence } from './file-drift-compare.ts';
+import { artifactDirectory, asLocalCli, HELD_WINDOW_PAGES, keptProtectedPartsDetail, prepareDriftPage, selectedByGlobs, writeArtifact } from './file-drift.ts';
+import type { RepairScope } from './core.ts';
+
+/** The progress record of a whole-class apply, keyed by the manifest hash (`op_checkpoints`). */
+export const CLASS_PROGRESS_OP = 'file-drift-class-progress';
+/** The window a whole-class walk and its apply step by; tests make it small. */
+export const classWindow = { pages: HELD_WINDOW_PAGES };
+/** How long an apply's lease lasts without renewal; a running apply renews it on a timer. Tests make it small. */
+export const classLock = { ttlMs: 120_000 };
+export const CLASS_SIDES = ['unknown', 'database', 'both'] as const;
+const CLASS_TOP = 50;
+const RECONCILE_ARTIFACT_VERSION = 1;
+const CURSOR_PREFIX = 'c1.';
+const APPROVAL_PREFIX = 'class:';
+
+export interface ClassSelection { sourceId: string; side: string; only: string[]; skip: string[] }
+/** One page of the class: what its apply is bound to (never a timestamp) and the lines it drops. */
+export interface ClassPin { slug: string; path: string; revision: string; file_blob: string; hold_code: string; side: string; upstream_version: string | null; lost_lines: number }
+interface Kept { slug: string; path: string; next: string }
+export interface ClassManifest { format_version: 1; kind: 'file-drift-class'; gbrain_version: string; file_drift_version: number; reconcile_version: number;
+ mirror: boolean; brain_id: string; source_id: string; side: string; only: string[]; skip: string[]; complete: boolean; after: string | null; windows: number;
+ pages: ClassPin[]; residual: { kept_newer_page: Kept[]; kept_protected_parts: Kept[] }; other: Record<string, number>; backup_bytes: number }
+/** `details.class_manifest`: exactly the seven fields the output and `--json` carry. */
+export interface ClassManifestSummary { path: string; hash: string; complete: boolean; pages: number; lost_lines_total: number;
+ top: Array<{ slug: string; path: string; lost_lines: number }>; residual: { kept_newer_page: { count: number; next: string }; kept_protected_parts: { count: number; next: string } } }
+export interface ClassPreviewResult { none: boolean; class_manifest?: ClassManifestSummary; other: Record<string, number>; resume_command?: string; apply_command?: string; card?: string[] }
+export interface ClassApplyResult { complete: boolean; applied: number; skipped: number; remaining: number; skipped_pages: Array<{ slug: string; reason: string }>;
+ resume_command?: string; stopped?: { code: string; message: string }; trace?: string; next?: string }
+
+const argvSelection = (sel: ClassSelection) => [...sel.only.flatMap(glob => ['--only', glob]), ...sel.skip.flatMap(glob => ['--skip', glob])];
+export const classPreviewArgv = (sel: ClassSelection, cursor?: string) =>
+ ['gbrain', 'repair', 'file-drift', '--source', sel.sourceId, '--held', '--side', sel.side, ...argvSelection(sel), '--prefer', 'file', '--whole-class', ...(cursor ? ['--cursor', cursor] : [])];
+const classApplyArgv = (sel: ClassSelection, hash: string) => [...classPreviewArgv(sel), '--apply', '--expect', hash, '--yes'];
+const compareArgv = (sel: ClassSelection) => ['gbrain', 'repair', 'file-drift', '--source', sel.sourceId, '--held', '--side', sel.side, ...argvSelection(sel), '--json'];
+const manifestPath = (hash: string) => join(artifactDirectory(), `class-${hash}.json`);
+/** The hash binds what the class is (its pins, residual and walk), never `backup_bytes`: that estimate moves when a background text projection lands. */
+const manifestHash = ({ backup_bytes: _estimate, ...manifest }: ClassManifest) => previewHash({ kind: 'file-drift-class-v1', manifest });
+const requestIdFor = (hash: string, slug: string) => {
+ const h = digest(['file-drift-class-request-v1', hash, slug]);
+ return `${h.slice(0, 8)}-${h.slice(8, 12)}-4${h.slice(13, 16)}-a${h.slice(17, 20)}-${h.slice(20, 32)}`;
+};
+
+/** The whole-class refusals of a selection the CLI parsed; nothing was read or written when one throws. */
+export function assertWholeClassSelection(opts: { held?: boolean; side?: string; state?: string; provenance?: string; prefer?: string; slugs?: string[]; requests?: string[]; allDrifted?: boolean; sourceId?: string }): void {
+ if (opts.slugs?.length || opts.requests?.length || opts.allDrifted) throw opError('invalid_params', '--whole-class settles the held pages of one side; it does not take --slug, --request or --all-drifted.',
+ 'Drop --slug, --request and --all-drifted, and select the class with --held --side unknown|database|both --prefer file --whole-class; a single page is previewed with --slug and no --whole-class.');
+ if (!opts.held) throw opError('invalid_params', '--whole-class needs --held.', 'Select the class with --held --side unknown|database|both --prefer file --whole-class.');
+ const source = opts.sourceId ?? '<source>';
+ if (opts.prefer === 'database' || opts.side === 'deleted' || opts.state || opts.provenance) {
+ throw opError('whole_class_prefer_unsupported', `--whole-class settles only --prefer file on side unknown, database or both${opts.side === 'deleted' ? '; deleted-side holds need a decision per state' : ''}.`,
+ `Nothing was previewed. Preview this selection one window at a time instead: gbrain repair file-drift --source ${source} --held --side ${opts.side ?? '<side>'}${opts.state ? ` --state ${opts.state}` : ''}${opts.provenance ? ` --provenance ${opts.provenance}` : ''} --prefer ${opts.prefer ?? 'database'}`,
+ { fix: readFix('Lists the held files of this source with their side and state, read-only.', { argv: ['gbrain', 'sources', 'status', source, '--json'] }) });
+ }
+ if (!opts.side || !(CLASS_SIDES as readonly string[]).includes(opts.side)) throw opError('invalid_params', '--whole-class needs --side unknown, database or both.',
+ `Name the side: gbrain repair file-drift --source ${source} --held --side unknown --prefer file --whole-class (gbrain sources status ${source} --json lists each held file's side).`);
+ if (opts.prefer !== 'file') throw opError('invalid_params', '--whole-class needs --prefer file.', `Add --prefer file: gbrain repair file-drift --source ${source} --held --side ${opts.side} --prefer file --whole-class`);
+}
+
+function readManifest(hash: string): ClassManifest | null {
+ try {
+ const path = manifestPath(hash);
+ const stat = lstatSync(path);
+ if (!stat.isFile() || stat.isSymbolicLink()) return null;
+ return JSON.parse(readFileSync(path, 'utf8')) as ClassManifest;
+ } catch { return null; }
+}
+
+/** The consent wording of a whole-class apply, from its manifest when it is readable (the apply itself refuses a stale one). */
+export function classConsentText(hash: string): { what: string; why: string; risk: string; user_message: string } {
+ const manifest = /^[0-9a-f]{64}$/.test(hash) ? readManifest(hash) : null;
+ const pages = Array.isArray(manifest?.pages) ? manifest.pages : [];
+ const lost = pages.reduce((sum, page) => sum + (page.lost_lines ?? 0), 0);
+ const where = manifest ? ` of source ${manifest.source_id} (held file drift, side ${manifest.side})` : '';
+ return {
+ what: `Replace ${pages.length} held page(s)${where} with their upstream files${manifest?.mirror ? ', database-only: the read-only mirror\'s checkout is never written' : ''}.`,
+ why: `The whole-class preview ${hash} listed each page, its pins and the ${lost} line(s) the replaced pages hold that their files do not carry.`,
+ risk: 'Each replaced page is saved as a page version first (gbrain revert restores it) and reconcile keeps a private backup; a page that changed since the preview is skipped and stays held. A large page whose older versions are pruned survives only in the private backup.',
+ user_message: `Apply the whole-class file-drift repair (preview ${hash.slice(0, 12)})? It replaces ${pages.length} page(s)${where} with their files and drops ${lost} line(s) the pages hold; each page is saved as a version first.`,
+ };
+}
+
+function removeManifest(hash: string | null | undefined): void {
+ if (!hash) return;
+ try { unlinkSync(manifestPath(hash)); } catch { /* already gone */ }
+}
+
+function summary(manifest: ClassManifest, hash: string, path: string): ClassManifestSummary {
+ const sel = { sourceId: manifest.source_id, side: manifest.side, only: manifest.only, skip: manifest.skip };
+ return { path, hash, complete: manifest.complete, pages: manifest.pages.length, lost_lines_total: manifest.pages.reduce((sum, page) => sum + page.lost_lines, 0),
+ top: [...manifest.pages].sort((a, b) => b.lost_lines - a.lost_lines || (a.slug < b.slug ? -1 : 1)).slice(0, CLASS_TOP).map(({ slug, path: file, lost_lines }) => ({ slug, path: file, lost_lines })),
+ residual: { kept_newer_page: { count: manifest.residual.kept_newer_page.length, next: shellQuote(compareArgv(sel)) },
+ kept_protected_parts: { count: manifest.residual.kept_protected_parts.length, next: shellQuote(compareArgv(sel)) } } };
+}
+
+/** The data-loss gate card of a complete manifest: what the apply replaces, how much, and how it comes back. */
+export function classCard(manifest: ClassManifest, s: ClassManifestSummary, applyCommand: string): string[] {
+ const largest = s.top[0];
+ return ['DATA CHANGE: confirmation required',
+ `What: replace ${s.pages} held page(s) of source ${manifest.source_id} (held file drift, side ${manifest.side}) with their upstream files${manifest.mirror ? ', database-only: this read-only mirror\'s checkout is never written' : ''}`,
+ `Count: ${s.pages} page(s); kept held: ${s.residual.kept_newer_page.count} edited in gbrain after their file (kept_newer_page), ${s.residual.kept_protected_parts.count} needing protected parts in the file (kept_protected_parts)`,
+ `Lost lines: ${s.lost_lines_total} line(s) the replaced pages hold and their files do not carry${largest ? ` (most: ${largest.slug}, ${largest.lost_lines})` : ''}; details.class_manifest.top lists the 50 largest`,
+ 'Recoverable:',
+ ' - each replaced page is saved as a page version first: gbrain history <slug> lists it and gbrain revert <slug> <version_id> restores it',
+ ' - reconcile keeps a private backup of each replaced copy under the gbrain config directory (reconciliation-previews)',
+ 'What would be lost: a large page\'s older versions are pruned on their own policy; once its version is pruned, the replaced text survives only in the private backup.',
+ `Proceed only after the user says yes: ${applyCommand}`];
+}
+
+function backupDirectoryUse(): { bytes: number; count: number } {
+ const directory = join(canonicalFilesystemPath(configDir()), 'reconciliation-previews');
+ let bytes = 0, count = 0;
+ if (!existsSync(directory)) return { bytes, count };
+ for (const name of readdirSync(directory)) {
+ if (name === '.capacity.lock') continue;
+ try { const stat = lstatSync(join(directory, name)); if (stat.isFile()) { bytes += stat.size; count++; } } catch { /* removed meanwhile */ }
+ }
+ return { bytes, count };
+}
+
+/** H1: the reconcile backups the apply would retain must fit the brain's recovery-bytes limit; nothing is written otherwise. */
+async function assertClassCapacity(engine: BrainEngine, needed: number, pages: number): Promise<void> {
+ const limits = await readJournalLimits(engine);
+ const existing = backupDirectoryUse();
+ const key = journalLimitKey('brainRecoveryBytes');
+ if (existing.bytes + needed <= limits.brainRecoveryBytes && existing.count + pages <= limits.brainLifetimeIds) return;
+ const countOver = existing.count + pages > limits.brainLifetimeIds;
+ throw opError('class_capacity_exceeded', `The whole-class apply would retain ${existing.bytes + needed} bytes of reconcile backups (${needed} for this class, ${existing.bytes} already retained), over the limit of ${limits.brainRecoveryBytes} bytes (${key})${countOver ? `, or more than ${limits.brainLifetimeIds} retained backups` : ''}.`,
+ `Nothing was written. Raising ${key} is the user's call (gbrain config set ${key} <bytes>); or settle a smaller class with --only / --skip.`,
+ { fix: readFix(`Shows the recovery-bytes limit in effect (${key}), read-only.`, { argv: ['gbrain', 'config', 'get', key] }) });
+}
+
+/**
+ * The whole-class preview: every window of the selected held pages, one manifest. Trusted local CLI only. Returns `none` when
+ * the source holds no `file_drift` page (a repo-less brain never does).
+ */
+export async function previewFileDriftClass(engine: BrainEngine, scope: RepairScope, sel: ClassSelection,
+ opts: { remote?: boolean; cursor?: string; deadline?: number; progress?: ProgressReporter } = {}): Promise<ClassPreviewResult> {
+ if (opts.remote !== false) throw trustedCliRequired('gbrain repair file-drift --whole-class runs only for the trusted local CLI on the brain host.');
+ assertWholeClassSelection({ held: true, side: sel.side, prefer: 'file', sourceId: sel.sourceId });
+ const resumed = opts.cursor ? resumeManifest(scope, sel, opts.cursor) : null;
+ const [source] = await engine.executeRaw<{ incarnation: string }>('SELECT incarnation::text AS incarnation FROM sources WHERE id=$1', [sel.sourceId]);
+ const [held] = source ? await engine.executeRaw<{ n: number | string }>(`SELECT count(*) AS n FROM op_checkpoints h
+ WHERE h.op=$1 AND h.completed_keys->0->>'source_id'=$2 AND h.completed_keys->0->>'incarnation'=$3 AND h.completed_keys->0->>'code'='file_drift'`, [GIT_HOLD_OP, sel.sourceId, source.incarnation]) : [];
+ if (!resumed && Number(held?.n ?? 0) === 0) return { none: true, other: {} };
+ await assertReconcileOutputPath(engine, sel.sourceId, artifactDirectory());
+ const mirror = await sourceMirrorReadOnly(engine, sel.sourceId);
+ const manifest: ClassManifest = resumed?.manifest ?? { format_version: 1, kind: 'file-drift-class', gbrain_version: VERSION, file_drift_version: FILE_DRIFT_VERSION,
+ reconcile_version: RECONCILE_ARTIFACT_VERSION, mirror, brain_id: scope.brain_id, source_id: sel.sourceId, side: sel.side, only: sel.only, skip: sel.skip,
+ complete: false, after: null, windows: 0, pages: [], residual: { kept_newer_page: [], kept_protected_parts: [] }, other: {}, backup_bytes: 0 };
+ const count = (key: string) => { manifest.other[key] = (manifest.other[key] ?? 0) + 1; };
+ const binding = await getWorktreeBinding(engine, sel.sourceId);
+ const root = binding?.local_path ? join(binding.local_path, binding.relative_path) : null;
+ let partial: string | null = resumed?.hash ?? null;
+ const written: string[] = [];
+ const assessmentAt = new Date().toISOString();
+ const startWindows = manifest.windows;
+ await asLocalCli(engine, async () => {
+ for (;;) {
+ if (manifest.windows > startWindows && opts.deadline !== undefined && Date.now() >= opts.deadline) break;
+ const rows = await engine.executeRaw<{ record: GitHoldRecord }>(`SELECT h.completed_keys->0 AS record FROM op_checkpoints h
+ WHERE h.op=$1 AND h.completed_keys->0->>'source_id'=$2 AND h.completed_keys->0->>'incarnation'=$3 AND h.completed_keys->0->>'code'='file_drift'
+ AND ($4::text IS NULL OR (h.completed_keys->0->>'path') COLLATE "C" > $4::text)
+ ORDER BY (h.completed_keys->0->>'path') COLLATE "C" LIMIT $5`, [GIT_HOLD_OP, sel.sourceId, source!.incarnation, manifest.after, classWindow.pages]);
+ if (!rows.length) { manifest.complete = true; break; }
+ const targets = rows.map(row => row.record).filter(hold => fileDriftSide(hold.meta) === sel.side && selectedByGlobs(hold.path, sel));
+ const evidence = root ? fileCommitEvidenceBatch(root, targets.map(hold => hold.path)) : new Map<string, CommitEvidence>();
+ opts.progress?.start('repair.file_drift.whole_class', targets.length);
+ for (const hold of targets) {
+ opts.progress?.tick(1, hold.slug ?? hold.path);
+ const kept = await classifyPage(engine, sel, hold, mirror, assessmentAt, path => evidence.get(path));
+ if ('pin' in kept) { manifest.pages.push(kept.pin); manifest.backup_bytes += kept.bytes; }
+ else if (kept.kept === 'kept_newer_page' || kept.kept === 'kept_protected_parts') manifest.residual[kept.kept].push({ slug: kept.slug, path: hold.path, next: kept.next });
+ else count(kept.kept);
+ }
+ opts.progress?.finish();
+ manifest.after = rows[rows.length - 1]!.record.path;
+ manifest.windows++;
+ try { await assertClassCapacity(engine, manifest.backup_bytes, manifest.pages.length); }
+ catch (error) { for (const hash of written) removeManifest(hash); throw error; }
+ if (rows.length < classWindow.pages) { manifest.complete = true; break; }
+ const next = manifestHash(manifest);
+ writeArtifact(`class-${next}`, manifest);
+ written.push(next);
+ if (partial && partial !== next) removeManifest(partial);
+ partial = next;
+ process.stderr.write(`[repair] whole-class preview: ${manifest.windows} window(s) read, ${manifest.pages.length} page(s) in the class; to resume after a stop: ${shellQuote(classPreviewArgv(sel, CURSOR_PREFIX + next))}\n`);
+ }
+ });
+ const hash = manifestHash(manifest);
+ const path = writeArtifact(`class-${hash}`, manifest);
+ if (partial && partial !== hash) removeManifest(partial);
+ const s = summary(manifest, hash, path);
+ if (!manifest.complete) return { none: false, class_manifest: s, other: manifest.other, resume_command: shellQuote(classPreviewArgv(sel, CURSOR_PREFIX + hash)) };
+ await saveApprovedSet(engine, { command: 'file-drift', hash: APPROVAL_PREFIX + hash }, manifest.pages);
+ const applyCommand = shellQuote(classApplyArgv(sel, hash));
+ return { none: false, class_manifest: s, other: manifest.other, apply_command: applyCommand, card: classCard(manifest, s, applyCommand) };
+}
+
+function resumeManifest(scope: RepairScope, sel: ClassSelection, cursor: string): { manifest: ClassManifest; hash: string } {
+ const hash = cursor.startsWith(CURSOR_PREFIX) ? cursor.slice(CURSOR_PREFIX.length) : '';
+ const manifest = /^[0-9a-f]{64}$/.test(hash) ? readManifest(hash) : null;
+ if (!manifest || manifest.complete || manifestHash(manifest) !== hash || manifest.brain_id !== scope.brain_id || manifest.source_id !== sel.sourceId || manifest.side !== sel.side
+ || digest([manifest.only, manifest.skip]) !== digest([sel.only, sel.skip])) {
+ throw opError('invalid_params', `--cursor ${cursor} is not the resume cursor of a partial whole-class preview of this selection.`,
+ `Nothing was previewed. Start the preview again without --cursor: ${shellQuote(classPreviewArgv(sel))}`);
+ }
+ return { manifest, hash };
+}
+
+type Classified = { pin: ClassPin; bytes: number } | { kept: string; slug: string; next: string };
+
+/** One held page through the live read, the newer-side rule and the reconcile preparation, as the window preview reads it. */
+async function classifyPage(engine: BrainEngine, sel: ClassSelection, hold: GitHoldRecord, mirror: boolean, assessmentAt: string,
+ commit: (path: string) => CommitEvidence | undefined): Promise<Classified> {
+ const slug = hold.slug;
+ if (slug === null) return { kept: 'no_page', slug: hold.path, next: '' };
+ try {
+ await authorizeReconcile(engine, sel.sourceId, slug);
+ const live = await heldLiveDrift(engine, sel.sourceId, slug, { hold, mirror });
+ if (live.reason === 'canonical_file_missing') return { kept: 'side_changed', slug, next: '' };
+ if (live.still_present !== true) return { kept: live.reason === 'agrees' ? 'release_hold' : live.still_present === false ? 'no_drift' : `unknown_${live.reason}`, slug, next: '' };
+ const evidence = await readDriftEvidence(engine, sel.sourceId, slug, assessmentAt, commit);
+ if (evidence.newer === 'database' && evidence.differs !== 'none') {
+ return { kept: 'kept_newer_page', slug, next: `page ${slug} changed after ${evidence.path} was last committed; preview it alone: gbrain repair file-drift --source ${sel.sourceId} --slug ${slug} --prefer file (or --prefer database)` };
+ }
+ const page = await prepareDriftPage(engine, sel.sourceId, slug, 'file', assessmentAt);
+ if (mirror && page.file_appended) return { kept: 'kept_protected_parts', slug, next: keptProtectedPartsDetail(sel.sourceId, slug) };
+ if (page.discards) return { kept: 'kept_newer_file', slug, next: '' };
+ return { pin: { slug, path: hold.path, revision: page.preview.preconditions.revision, file_blob: page.preview.preconditions.raw_file_hash, hold_code: hold.code,
+ side: fileDriftSide(hold.meta) ?? '', upstream_version: hold.upstream_version ?? null, lost_lines: page.lost_lines }, bytes: Buffer.byteLength(stableJson(page.preview)) + 1024 };
+ } catch (error) {
+ if (!(error instanceof OperationError) || ['owner_unavailable', 'writer_registration_required'].includes(error.code)) throw error;
+ return { kept: `refused_${error.code}`, slug, next: '' };
+ }
+}
+
+/** G1: the manifest no longer matches its hash or the approved pins; nothing was written. */
+function staleManifest(sel: ClassSelection, hash: string, why: string): OperationError {
+ return opError('class_manifest_stale', `The whole-class manifest ${hash.slice(0, 12)} no longer matches what was previewed: ${why}.`,
+ `Nothing was written. Preview the class again and approve its new hash: ${shellQuote(classPreviewArgv(sel))}`,
+ { fix: readFix('Previews the whole class again, writing only a new private manifest; it prints a new hash and apply command.', { argv: [...classPreviewArgv(sel), '--json'] }) });
+}
+
+interface Lock { token: string; pid: number; host: string; expires_at: number }
+interface Progress { hash: string; window: number; applied: number; skipped: number; complete?: boolean; lock?: Lock | null; last_error?: string }
+
+function lockLive(lock: Lock | null | undefined): boolean {
+ if (!lock || lock.expires_at <= Date.now()) return false;
+ if (lock.host !== hostname()) return true;
+ try { process.kill(lock.pid, 0); return true; } catch (error) { return (error as NodeJS.ErrnoException).code === 'EPERM'; }
+}
+
+/** The per-manifest lock: one apply of a manifest at a time (`class_apply_busy`). */
+async function acquireLock(engine: BrainEngine, sel: ClassSelection, hash: string, token: string): Promise<Progress> {
+ return engine.transaction(async tx => {
+ await tx.executeRaw('INSERT INTO op_checkpoints(op,fingerprint,completed_keys) VALUES($1,$2,$3::text::jsonb) ON CONFLICT(op,fingerprint) DO NOTHING',
+ [CLASS_PROGRESS_OP, hash, JSON.stringify([{ hash, window: 0, applied: 0, skipped: 0 }])]);
+ const [row] = await tx.executeRaw<{ completed_keys: Progress[] }>('SELECT completed_keys FROM op_checkpoints WHERE op=$1 AND fingerprint=$2 FOR UPDATE', [CLASS_PROGRESS_OP, hash]);
+ const progress = row!.completed_keys[0]!;
+ if (lockLive(progress.lock)) throw opError('class_apply_busy', `Another apply of whole-class manifest ${hash.slice(0, 12)} is running (process ${progress.lock!.pid} on ${progress.lock!.host}).`,
+ `Nothing was written by this run. Wait for that apply to finish; if it was stopped, rerun the same command once its lock expires (${new Date(progress.lock!.expires_at).toISOString()}), and it resumes at the next window: ${shellQuote(classApplyArgv(sel, hash))}`,
+ { fix: readFix('Shows the source\'s held pages and sync state, read-only.', { argv: ['gbrain', 'sources', 'status', sel.sourceId, '--json'] }) });
+ const next = { ...progress, lock: { token, pid: process.pid, host: hostname(), expires_at: Date.now() + classLock.ttlMs } };
+ await tx.executeRaw('UPDATE op_checkpoints SET completed_keys=$3::text::jsonb, updated_at=now() WHERE op=$1 AND fingerprint=$2', [CLASS_PROGRESS_OP, hash, JSON.stringify([next])]);
+ return next;
+ });
+}
+
+/** Saves the progress record while this run holds its lock; false when another apply took the lock. */
+async function writeProgress(engine: BrainEngine, hash: string, token: string, update: Partial<Progress>): Promise<boolean> {
+ return engine.transaction(async tx => {
+ const [row] = await tx.executeRaw<{ completed_keys: Progress[] }>('SELECT completed_keys FROM op_checkpoints WHERE op=$1 AND fingerprint=$2 FOR UPDATE', [CLASS_PROGRESS_OP, hash]);
+ const progress = row?.completed_keys?.[0];
+ if (!progress || progress.lock?.token !== token) return false;
+ await tx.executeRaw('UPDATE op_checkpoints SET completed_keys=$3::text::jsonb, updated_at=now() WHERE op=$1 AND fingerprint=$2',
+ [CLASS_PROGRESS_OP, hash, JSON.stringify([{ ...progress, ...update }])]);
+ return true;
+ });
+}
+
+const lostLock = (sel: ClassSelection, hash: string) => opError('class_apply_busy', `Another apply took over whole-class manifest ${hash.slice(0, 12)} while this one was running.`,
+ `This run stopped and wrote nothing more. Wait for the other apply to finish, then rerun the same command; it resumes where that one stopped: ${shellQuote(classApplyArgv(sel, hash))}`,
+ { fix: readFix('Shows the source\'s held pages and sync state, read-only.', { argv: ['gbrain', 'sources', 'status', sel.sourceId, '--json'] }) });
+
+type PageOutcome = { applied: true } | { applied: false; reason: string };
+
+/** D1: one page re-read and applied only when every pin still holds and its lost lines did not grow. */
+async function applyPage(engine: BrainEngine, sel: ClassSelection, manifest: ClassManifest, hash: string, pin: ClassPin, incarnation: string): Promise<PageOutcome> {
+ const requestId = requestIdFor(hash, pin.slug);
+ const [prior] = await engine.executeRaw<{ state: string }>('SELECT state FROM persistence_requests WHERE request_id=$1::uuid', [requestId]);
+ if (prior?.state === 'committed') return { applied: true };
+ if (prior && !['conflict', 'failed', 'cancelled'].includes(prior.state)) {
+ throw opError('write_pending', `The apply of ${pin.slug} (request ${requestId}) has not settled yet.`, `Wait for it (gbrain write-request ${requestId}), then rerun the apply; it resumes where it stopped.`);
+ }
+ if (prior) return { applied: false, reason: `refused_${prior.state}` };
+ const mirror = await sourceMirrorReadOnly(engine, sel.sourceId);
+ if (mirror !== manifest.mirror) return { applied: false, reason: 'changed_since_preview' };
+ try { await authorizeReconcile(engine, sel.sourceId, pin.slug); }
+ catch (error) { if (!(error instanceof OperationError) || error.code !== 'permission_denied') throw error; return { applied: false, reason: 'refused_permission_denied' }; }
+ const hold = await readGitHold(engine, sel.sourceId, incarnation, pin.path);
+ if (!hold || hold.code !== pin.hold_code || (fileDriftSide(hold.meta) ?? '') !== pin.side || (hold.upstream_version ?? null) !== pin.upstream_version || hold.slug !== pin.slug) {
+ return { applied: false, reason: 'hold_changed' };
+ }
+ const assessmentAt = new Date().toISOString();
+ const live = await heldLiveDrift(engine, sel.sourceId, pin.slug, { hold, mirror });
+ if (live.still_present !== true) return { applied: false, reason: 'changed_since_preview' };
+ const evidence = await readDriftEvidence(engine, sel.sourceId, pin.slug, assessmentAt);
+ if (evidence.newer === 'database' && evidence.differs !== 'none') return { applied: false, reason: 'changed_since_preview' };
+ const page = await prepareDriftPage(engine, sel.sourceId, pin.slug, 'file', assessmentAt);
+ if (page.preview.preconditions.revision !== pin.revision || page.preview.preconditions.raw_file_hash !== pin.file_blob || page.lost_lines > pin.lost_lines
+ || (mirror && page.file_appended) || page.discards) return { applied: false, reason: 'changed_since_preview' };
+ try {
+ await runReconcileApply(engine, { source_id: sel.sourceId, slug: pin.slug, preview: page.preview, request_id: requestId, keep_file_bytes: true });
+ return { applied: true };
+ } catch (error) {
+ if (acceptedPendingReceipt(error) || !(error instanceof OperationError) || ['owner_unavailable', 'writer_lock_unavailable', 'writer_busy', 'write_pending', 'queue_capacity'].includes(error.code)) throw error;
+ const changed = ['revision_conflict', 'page_identity_changed', 'page_not_found', 'source_changed'].includes(error.code);
+ return { applied: false, reason: changed ? 'changed_since_preview' : `refused_${error.code}` };
+ }
+}
+
+/**
+ * The whole-class apply of the manifest the user approved (`--expect <hash>`). Trusted local CLI only. It stops (complete false,
+ * a resume command) on a stop signal, the deadline, or an error that is not one page's refusal; a rerun resumes at the window
+ * that was running, and the request ids derived from the hash and slug keep a page from applying twice.
+ */
+export async function applyFileDriftClass(ctx: OperationContext, scope: RepairScope, sel: ClassSelection, expect: string,
+ opts: { deadline?: number; stop?: AbortSignal; onWindow?: (window: number) => Promise<void> | void } = {}): Promise<ClassApplyResult> {
+ if (ctx.remote !== false) throw trustedCliRequired('gbrain repair file-drift --whole-class --apply runs only for the trusted local CLI on the brain host.');
+ const engine = ctx.engine;
+ assertWholeClassSelection({ held: true, side: sel.side, prefer: 'file', sourceId: sel.sourceId });
+ await assertReconcileOutputPath(engine, sel.sourceId, artifactDirectory());
+ const manifest = /^[0-9a-f]{64}$/.test(expect) ? readManifest(expect) : null;
+ if (!manifest) throw staleManifest(sel, expect, 'no manifest file with that hash is left in the preview directory');
+ if (manifest.source_id !== sel.sourceId || manifest.side !== sel.side || manifest.brain_id !== scope.brain_id || digest([manifest.only, manifest.skip]) !== digest([sel.only, sel.skip])) {
+ throw staleManifest(sel, expect, 'it was previewed for another selection');
+ }
+ const approved = await loadApprovedSet<ClassPin>(engine, { command: 'file-drift', hash: APPROVAL_PREFIX + expect, previewCommand: shellQuote(classPreviewArgv(sel)) })
+ .catch(error => { if (error instanceof OperationError && error.code === 'preview_changed') return null; throw error; });
+ if (!approved) throw staleManifest(sel, expect, 'no complete preview is saved under that hash (or it is older than 7 days)');
+ if (!manifest.complete || !Array.isArray(manifest.pages) || manifestHash(manifest) !== expect) {
+ const saved = new Map(approved.items.map(pin => [pin.slug, digest(pin)]));
+ const now = new Map((Array.isArray(manifest.pages) ? manifest.pages : []).map(pin => [pin.slug, digest(pin)]));
+ const changed = [...new Set([...saved.keys(), ...now.keys()])].filter(slug => saved.get(slug) !== now.get(slug)).length;
+ throw staleManifest(sel, expect, changed ? `${changed} page(s) or their pins differ from the approved set` : 'its versions, mirror flag or kept pages differ from the approved preview');
+ }
+ const [source] = await engine.executeRaw<{ incarnation: string }>('SELECT incarnation::text AS incarnation FROM sources WHERE id=$1', [sel.sourceId]);
+ const token = randomUUID();
+ const progress = await acquireLock(engine, sel, expect, token);
+ const renew = () => writeProgress(engine, expect, token, { lock: { token, pid: process.pid, host: hostname(), expires_at: Date.now() + classLock.ttlMs } });
+ let lost = false;
+ const heartbeat = setInterval(() => { renew().then(owned => { if (!owned) lost = true; }, () => { /* the next page's write reports it */ }); }, Math.max(50, Math.floor(classLock.ttlMs / 3)));
+ heartbeat.unref?.();
+ const result: ClassApplyResult = { complete: false, applied: progress.applied, skipped: progress.skipped, remaining: 0, skipped_pages: [] };
+ const size = Math.max(1, classWindow.pages);
+ const windows = Math.ceil(manifest.pages.length / size);
+ let window = progress.window;
+ let finished = false;
+ try {
+ await asLocalCli(engine, async () => {
+ for (; window < windows; window++) {
+ for (const pin of manifest.pages.slice(window * size, (window + 1) * size)) {
+ if (lost || !await renew()) throw lostLock(sel, expect);
+ if (opts.stop?.aborted) throw opError('interrupted', 'The whole-class apply was stopped by a signal.', 'Rerun the resume command; it continues at the window that was running.');
+ if (opts.deadline !== undefined && Date.now() >= opts.deadline) throw opError('interrupted', 'The whole-class apply reached its deadline.', 'Rerun the resume command; it continues at the window that was running.');
+ const outcome = await applyPage(engine, sel, manifest, expect, pin, source!.incarnation);
+ if (outcome.applied) result.applied++;
+ else { result.skipped++; result.skipped_pages.push({ slug: pin.slug, reason: outcome.reason }); }
+ }
+ if (!await writeProgress(engine, expect, token, { window: window + 1, applied: result.applied, skipped: result.skipped })) throw lostLock(sel, expect);
+ await opts.onWindow?.(window);
+ }
+ });
+ finished = true;
+ } catch (error) {
+ result.stopped = { code: error instanceof OperationError ? error.code : 'unexpected_error', message: error instanceof Error ? error.message : String(error) };
+ if (!(error instanceof OperationError)) {
+ const trace = join(artifactDirectory(), `class-${expect}.trace.txt`);
+ try { writeFileSync(trace, `${new Date().toISOString()} ${error instanceof Error ? error.stack ?? error.message : String(error)}\n`, { mode: 0o600 }); result.trace = trace; } catch { /* the message still names the error */ }
+ }
+ } finally {
+ clearInterval(heartbeat);
+ if (!finished) await writeProgress(engine, expect, token, { lock: null, last_error: result.stopped?.message ?? '' });
+ }
+ if (finished && !(await engine.executeRaw("DELETE FROM op_checkpoints WHERE op=$1 AND fingerprint=$2 AND completed_keys->0->'lock'->>'token'=$3 RETURNING 1",
+ [CLASS_PROGRESS_OP, expect, token])).length) {
+ finished = false;
+ const busy = lostLock(sel, expect);
+ result.stopped = { code: busy.code, message: busy.message };
+ }
+ if (finished) {
+ result.complete = true;
+ await clearApprovedSet(engine, { command: 'file-drift', hash: APPROVAL_PREFIX + expect });
+ removeManifest(expect);
+ result.next = `The next gbrain sync --source ${sel.sourceId} re-screens each applied file and releases its hold.`;
+ return result;
+ }
+ const saved = (await engine.executeRaw<{ completed_keys: Progress[] }>('SELECT completed_keys FROM op_checkpoints WHERE op=$1 AND fingerprint=$2', [CLASS_PROGRESS_OP, expect]))[0]?.completed_keys?.[0];
+ result.remaining = Math.max(0, manifest.pages.length - (saved?.window ?? 0) * size);
+ result.resume_command = shellQuote(classApplyArgv(sel, expect));
+ return result;
+}
+
+/** I1: the text lines of an apply result; a stopped apply leads with its resume command, then what it applied, skipped and left. */
+export function classApplyLines(result: ClassApplyResult): string[] {
+ const lines = result.complete ? [`file-drift --whole-class: applied ${result.applied}, skipped ${result.skipped}, complete`]
+ : [`Resume: ${result.resume_command}`, `file-drift --whole-class STOPPED: applied ${result.applied}, skipped ${result.skipped}, remaining ${result.remaining}`,
+ ` ${result.stopped?.code}: ${result.stopped?.message}`, ...(result.trace ? [` trace: ${result.trace}`] : [])];
+ for (const page of result.skipped_pages.slice(0, 50)) lines.push(` skipped ${page.slug} (${page.reason}); it stays held`);
+ if (result.next) lines.push(` ${result.next}`);
+ return lines;
+}
diff --git a/src/core/repair/file-drift-compare.ts b/src/core/repair/file-drift-compare.ts
index 2f4ed251b4..98be31f948 100644
--- a/src/core/repair/file-drift-compare.ts
+++ b/src/core/repair/file-drift-compare.ts
@@ -15,7 +15,9 @@ import { relative, sep } from 'node:path';
import type { BrainEngine } from '../engine.ts';
import type { ParsedPage } from '../import-file.ts';
import { digest } from '../persistence/digest.ts';
-import { liveFileDrift } from '../persistence/drift-conflicts.ts';
+import { liveFileDrift, type LiveDrift } from '../persistence/drift-conflicts.ts';
+import { classifyDrift } from '../persistence/reconcile-additive.ts';
+import { sha256 } from '../persistence/digest.ts';
import { reconcileCanonical } from '../persistence/reconcile-merge.ts';
import { readReconcileState } from '../persistence/reconcile-state.ts';
import { fileDriftActionVerb, fileDriftSide, holdRescreenDue, type GitHoldRecord } from '../persistence/sync-holds.ts';
@@ -42,7 +44,8 @@ export function driftDifference(file: ParsedPage, database: ParsedPage): { diffe
}
/** The file's last commit time at HEAD and whether its working-tree bytes differ from HEAD; a Git failure reads as no evidence. */
-export function fileCommitEvidence(root: string, path: string): { committed_at: string | null; uncommitted: boolean } {
+export interface CommitEvidence { committed_at: string | null; uncommitted: boolean }
+export function fileCommitEvidence(root: string, path: string): CommitEvidence {
const git = (args: string[]) => execFileSync('git', ['-C', root, ...args], { env: gitChildEnv(GIT_READ_ENV), encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
try {
return { committed_at: git(['log', '-1', '--format=%cI', 'HEAD', '--', path]) || null, uncommitted: git(['status', '--porcelain', '--', path]) !== '' };
@@ -60,13 +63,39 @@ export function newerSide(file: { committed_at: string | null; uncommitted: bool
return page > committed ? 'database' : page < committed ? 'file' : 'unknown';
}
-/** One live page's comparison with its canonical file (read as reconcile and `repair file-drift` read it). */
-export async function readDriftEvidence(engine: BrainEngine, sourceId: string, slug: string, assessmentAt: string): Promise<DriftEvidence> {
+/**
+ * Whole-class (file-drift-class.ts): the commit evidence of many paths in one Git read: one `git log` naming each path's last
+ * commit at HEAD and one `git status` for uncommitted bytes. Git prints paths from the repository top, so a source bound to a
+ * subdirectory is matched through its prefix. A path the read did not settle, or every path when Git fails, is left out, and the
+ * caller reads it alone.
+ */
+export function fileCommitEvidenceBatch(root: string, paths: readonly string[]): Map<string, CommitEvidence> {
+ if (!paths.length) return new Map();
+ const git = (args: string[]) => execFileSync('git', ['-C', root, '-c', 'core.quotePath=false', ...args], { env: gitChildEnv(GIT_READ_ENV), encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], maxBuffer: 256 * 1024 * 1024 });
+ try {
+ const prefix = git(['rev-parse', '--show-prefix']).trim();
+ const byTop = new Map(paths.map(path => [prefix + path, { committed_at: null as string | null, uncommitted: false }]));
+ let at: string | null = null;
+ for (const line of git(['log', '--format=%x01%cI', '--name-only', 'HEAD', '--', ...paths]).split('\n')) {
+ if (line.startsWith('\u0001')) { at = line.slice(1).trim() || null; continue; }
+ const entry = byTop.get(line);
+ if (entry && entry.committed_at === null) entry.committed_at = at;
+ }
+ for (const record of git(['status', '--porcelain', '-z', '--', ...paths]).split('\0')) {
+ const entry = record.length > 3 ? byTop.get(record.slice(3)) : undefined;
+ if (entry) entry.uncommitted = true;
+ }
+ return new Map(paths.flatMap(path => { const entry = byTop.get(prefix + path)!; return entry.committed_at === null ? [] : [[path, entry] as const]; }));
+ } catch { return new Map(); }
+}
+
+/** One live page's comparison with its canonical file (read as reconcile and `repair file-drift` read it); `commit` is the file's evidence when a batch already read it. */
+export async function readDriftEvidence(engine: BrainEngine, sourceId: string, slug: string, assessmentAt: string, commit?: (path: string) => CommitEvidence | undefined): Promise<DriftEvidence> {
const snapshot = await engine.readPageSnapshot(slug, { sourceId });
const state = await readReconcileState(engine, sourceId, slug, assessmentAt, { adoptSlugPath: !!snapshot && recordsNoFileOrigin(snapshot.page) });
const { differs, keys } = driftDifference(reconcileCanonical(state.file, state.file.tags), reconcileCanonical(state.snapshot.page, state.snapshot.tags));
const path = relative(state.root, state.path).split(sep).join('/');
- const file = fileCommitEvidence(state.root, path);
+ const file = commit?.(path) ?? fileCommitEvidence(state.root, path);
const updated = state.snapshot.page.updated_at ? new Date(state.snapshot.page.updated_at).toISOString() : null;
return { path, differs, keys, file_committed_at: file.committed_at, file_uncommitted: file.uncommitted, page_updated_at: updated, newer: newerSide(file, updated) };
}
@@ -80,12 +109,48 @@ export function newerPageParagraph(sourceId: string, slug: string, evidence: Dri
}
/**
- * GST-2869: what settles a read-only mirror's differing page. Its file-drift previews read every page as database-only and
- * resolve nothing, so naming one would send a caller to an empty preview; they apply once the source is writable again.
+ * GST-2869 / whole-class: what settles a read-only mirror's differing held pages. The whole-class preview lists every held page of
+ * the side whose file is newer for one approval and its apply imports each file into its page database-only (no file is written);
+ * a page edited in gbrain after its file stays held for a person.
+ */
+export function mirrorDriftRoute(sourceId: string, side = 'unknown'): string {
+ return `this source is a read-only mirror: gbrain repair file-drift --source ${sourceId} --held --side ${side} --prefer file --whole-class previews every held page of that side whose file is newer for one approval, `
+ + `and its apply imports each file into its page database-only (nothing is written to the checkout); a page edited in gbrain after its file was committed stays held for a person (kept_newer_page)`;
+}
+
+/**
+ * What settles a read-only mirror's held deleted page whose file differs. The mirror never removes its file, so a tombstone_edited
+ * page names keeping the deletion first (recorded on the hold, nothing written) and making the source writable second; a
+ * purged_differs page has no deletion to keep, so it names only the writable route. Never a --prefer file preview.
*/
-export function mirrorDriftRoute(sourceId: string): string {
- return `this source is a read-only mirror, so gbrain repair's file-drift previews read its pages as database-only and resolve nothing; `
- + `the page stays held until the user makes the source writable again (gbrain sources mirror-writable ${sourceId}, which lets gbrain write files into its checkout) and picks a side then`;
+export function mirrorDeletedRoute(sourceId: string, state: string): string {
+ const writable = `the user makes the source writable (gbrain sources mirror-writable ${sourceId}) and picks a side`;
+ if (state !== 'tombstone_edited') return `this source is a read-only mirror, so its file can't be removed; to settle the page ${writable}`;
+ return `this source is a read-only mirror: to keep the deletion, preview gbrain repair file-drift --source ${sourceId} --held --side deleted --state tombstone_edited --prefer database `
+ + `(the apply records the kept deletion on the hold and writes nothing); to bring the page back from its file instead, ${writable}`;
+}
+
+/**
+ * The live drift of a page, as every held file-drift read takes it (the comparison, the window preview, the whole-class walk and its
+ * apply). GST-2843: a read-only mirror never writes its files, so `liveFileDrift` calls every mirror page database-only; a held page of
+ * side both, unknown or database whose file sync still imports is compared with that file instead, and only a gone file stays
+ * database-only.
+ */
+export async function heldLiveDrift(engine: BrainEngine, sourceId: string, slug: string, target: { hold?: GitHoldRecord | null; mirror?: boolean }): Promise<LiveDrift> {
+ const live = await liveFileDrift(engine, sourceId, slug);
+ const side = target.hold ? fileDriftSide(target.hold.meta) : undefined;
+ if (target.mirror !== true || !target.hold || side === 'deleted' || live.still_present !== false || live.reason !== 'database_only') return live;
+ try {
+ const snapshot = await engine.readPageSnapshot(slug, { sourceId });
+ const state = await readReconcileState(engine, sourceId, slug, undefined, { adoptSlugPath: !!snapshot && recordsNoFileOrigin(snapshot.page) });
+ const agrees = classifyDrift(state.file, reconcileCanonical(state.snapshot.page, state.snapshot.tags)).verdict === 'no_drift';
+ return { still_present: !agrees, reason: agrees ? 'agrees' : 'file_database_drift', db_revision: state.snapshot.revision,
+ path: relative(state.root, state.path).split(sep).join('/'), file_hash: sha256(state.raw) };
+ } catch (error) {
+ if (!(error instanceof OperationError)) throw error;
+ if (error.detail === 'canonical_file_missing') return live;
+ return { still_present: null, reason: typeof error.detail === 'string' ? error.detail : error.code };
+ }
}
/** One selected page, compared: a held page by its hold, any other by its slug. Never writes. */
@@ -96,12 +161,12 @@ export async function comparePage(engine: BrainEngine, sourceId: string, target:
const held = { ...(side ? { side } : {}), ...(hold?.meta.state ? { state: hold.meta.state } : {}), ...(hold ? { path: hold.path } : {}) };
if (side === 'deleted' && hold?.meta.state && hold.meta.state !== 'file_gone') {
const state = hold.meta.state;
- return { item, slug, ...held, would: 'needs_human', why: target.mirror ? `the page at ${hold.path} is deleted and the file differs (${state}), so a person decides; ${mirrorDriftRoute(sourceId)}`
+ return { item, slug, ...held, would: 'needs_human', why: target.mirror ? `the page at ${hold.path} is deleted and the file differs (${state}), so a person decides; ${mirrorDeletedRoute(sourceId, state)}`
: `the page at ${hold.path} is deleted and the file differs (${state}); --prefer database would ${fileDriftActionVerb('deleted', state, 'database')} and --prefer file would ${fileDriftActionVerb('deleted', state, 'file')}, so a person decides` };
}
if (slug === null) return { item, slug, ...held, would: 'unknown', why: 'the hold names no page; the next sync re-classifies it' };
try {
- const live = await liveFileDrift(engine, sourceId, slug);
+ const live = await heldLiveDrift(engine, sourceId, slug, target);
if (live.reason === 'canonical_file_missing') return { item, slug, ...held, would: 'needs_human',
why: `the page has no file at the last commit, so letting the file win would delete the page; that is never the default here. Keep it with --prefer database (recreates the file), or preview --held --side deleted --state file_gone --prefer file for a deletion you intend` };
if (live.reason === 'agrees') {
@@ -110,21 +175,14 @@ export async function comparePage(engine: BrainEngine, sourceId: string, target:
why: !hold ? 'the page and its file agree' : due ? 'the page and its file agree once gbrain\'s own normalisation is read; the next sync releases the hold with no write'
: `the page and its file agree; gbrain repair file-drift --source ${sourceId} --slug ${slug} --prefer file previews the release` };
}
- // GST-2843: a read-only mirror never writes its files, so the live check calls every page database-only; a held page whose
- // file sync still imports is compared with that file instead, and only a file that is gone stays database-only.
- const mirrorHeld = live.still_present === false && live.reason === 'database_only' && !!hold && side !== 'deleted' && target.mirror === true;
- if (live.still_present !== true && !mirrorHeld) return { item, slug, ...held, would: live.still_present === false ? 'no_drift' : 'unknown', why: live.reason };
- const read = await readDriftEvidence(engine, sourceId, slug, assessmentAt).catch(error => {
- if (mirrorHeld && error instanceof OperationError && error.detail === 'canonical_file_missing') return null;
- throw error;
- });
- if (!read) return { item, slug, ...held, would: 'no_drift', why: live.reason };
- const { path, ...evidence } = read;
+ const mirrorHeld = !!hold && side !== 'deleted' && target.mirror === true;
+ if (live.still_present !== true) return { item, slug, ...held, would: live.still_present === false ? 'no_drift' : 'unknown', why: live.reason };
+ const { path, ...evidence } = await readDriftEvidence(engine, sourceId, slug, assessmentAt);
const base = { item, slug, ...held, path, evidence };
if (evidence.differs === 'none') return { ...base, would: hold ? 'release_hold' : 'no_drift', why: 'nothing differs once gbrain\'s own normalisation is read' };
- if (evidence.newer === 'file') return { ...base, would: 'prefer_file', why: mirrorHeld ? `${path} was committed after the page last changed, so the file wins (Git is the parent), but ${mirrorDriftRoute(sourceId)}`
+ if (evidence.newer === 'file') return { ...base, would: 'prefer_file', why: mirrorHeld ? `${path} was committed after the page last changed, so the file wins (Git is the parent); ${mirrorDriftRoute(sourceId, side)}`
: `${path} was committed after the page last changed, so the file wins (Git is the parent): gbrain repair file-drift --source ${sourceId} --slug ${slug} --prefer file` };
- if (evidence.newer === 'database') return { ...base, would: 'needs_human', why: mirrorHeld ? `page ${slug} changed after ${path} was last committed (page updated ${evidence.page_updated_at}, file committed ${evidence.file_committed_at}), so a person decides which side to keep; ${mirrorDriftRoute(sourceId)}`
+ if (evidence.newer === 'database') return { ...base, would: 'needs_human', why: mirrorHeld ? `page ${slug} changed after ${path} was last committed (page updated ${evidence.page_updated_at}, file committed ${evidence.file_committed_at}), so a person decides which side to keep; ${mirrorDriftRoute(sourceId, side)}`
: newerPageParagraph(sourceId, slug, { path, ...evidence }) };
return { ...base, would: 'needs_human', why: evidence.file_uncommitted ? `${path} has uncommitted bytes, so which side is newer is unknown; commit or restore the file, then compare again`
: `which side is newer is unknown (${evidence.file_committed_at ? 'the page has no update time' : `no commit holds ${path}`}); a person decides` };
diff --git a/src/core/repair/file-drift.ts b/src/core/repair/file-drift.ts
index 888e1f0b14..b60db8e9b2 100644
--- a/src/core/repair/file-drift.ts
+++ b/src/core/repair/file-drift.ts
@@ -98,7 +98,7 @@ import { discardedFilePaths, unimportedFile, unimportedFileText, type Unimported
import { acceptedPendingReceipt } from '../persistence/accepted-pending.ts';
import { recordsNoFileOrigin } from '../persistence/unbound-pages.ts';
import { sourceMirrorReadOnly } from '../persistence/mirror-read-only.ts';
-import { comparedListing, comparePage, linesNotCarried, mirrorDriftRoute, newerPageParagraph, readDriftEvidence, type ComparedPage } from './file-drift-compare.ts';
+import { comparedListing, comparePage, heldLiveDrift, linesNotCarried, mirrorDriftRoute, newerPageParagraph, readDriftEvidence, type ComparedPage } from './file-drift-compare.ts';
import { serializePageToMarkdown } from '../markdown.ts';
import { afterCursor, type RepairHandler, type RepairItem, type RepairItemOutcome, type RepairPlan, type RepairPlanOptions, type RepairScope } from './core.ts';
@@ -168,7 +168,7 @@ const ALL_DRIFTED_LIMIT = 1000;
* and it starts no page after the window's time budget (or the run's deadline) has passed. Each page costs a few dozen
* database round trips, so a whole large held set in one preview ran for an hour against a remote database with no output.
*/
-const HELD_WINDOW_PAGES = 200;
+export const HELD_WINDOW_PAGES = 200;
const HELD_WINDOW_BUDGET_MS = 60_000;
const HELD_CURSOR_PREFIX = 'h1.';
const heldCursor = (path: string) => HELD_CURSOR_PREFIX + Buffer.from(path, 'utf8').toString('base64url');
@@ -179,7 +179,7 @@ function heldCursorPath(sourceId: string, cursor: string): string {
return path;
}
const TOP_FIELDS = ['title', 'type', 'compiled_truth', 'timeline'] as const;
-const artifactDirectory = () => join(canonicalFilesystemPath(configDir()), 'repair-previews', 'file-drift');
+export const artifactDirectory = () => join(canonicalFilesystemPath(configDir()), 'repair-previews', 'file-drift');
const escapePointer = (key: string) => key.replace(/~/g, '~0').replace(/\//g, '~1');
function previewCommand(sourceId: string, opts: RepairPlanOptions): string {
@@ -191,7 +191,7 @@ function previewCommand(sourceId: string, opts: RepairPlanOptions): string {
}
/** Whether a canonical file path passes the `--only` / `--skip` globs (no `--only`: every path; an unknown path only then). */
-const selectedByGlobs = (path: string | undefined, opts: Pick<RepairPlanOptions, 'only' | 'skip'>) =>
+export const selectedByGlobs = (path: string | undefined, opts: Pick<RepairPlanOptions, 'only' | 'skip'>) =>
path === undefined ? !opts.only?.length && !opts.skip?.length
: (!opts.only?.length || matchesRepairPath(path, opts.only)) && !matchesRepairPath(path, opts.skip);
@@ -229,7 +229,7 @@ export function driftExceptions(result: ParsedPage, preferred: ParsedPage): Drif
return exceptions;
}
-async function asLocalCli<T>(engine: BrainEngine, run: () => Promise<T>): Promise<T> {
+export async function asLocalCli<T>(engine: BrainEngine, run: () => Promise<T>): Promise<T> {
const verified = currentVerifiedLocalWriter();
if (verified) {
if (verified.remote || verified.principal.kind !== 'local_cli') throw trustedCliRequired('gbrain repair file-drift runs only for the trusted local CLI.');
@@ -248,14 +248,15 @@ function requestIdFor(hash: string, page: Pick<ApprovedPage, 'source_id' | 'slug
return `${h.slice(0, 8)}-${h.slice(8, 12)}-4${h.slice(13, 16)}-a${h.slice(17, 20)}-${h.slice(20, 32)}`;
}
-function writeArtifact(hash: string, value: unknown): string {
+/** Writes a private preview file (`<name>.json`) under the file-drift preview directory, atomically; the whole-class manifest uses it too. */
+export function writeArtifact(name: string, value: unknown): string {
const directory = artifactDirectory();
if (!existsSync(directory)) mkdirSync(directory, { recursive: true, mode: 0o700 });
const stat = lstatSync(directory);
if (!stat.isDirectory() || stat.isSymbolicLink()) throw opError('permission_denied', 'The file-drift preview directory must be a private real directory.',
`Nothing was written. Make ${directory} a real directory owned by the user with mode 0700 (not a symlink), then preview again.`);
- const path = join(directory, `${hash}.json`);
- const temporary = join(directory, `.${hash}.${randomUUID()}.tmp`);
+ const path = join(directory, `${name}.json`);
+ const temporary = join(directory, `.${name}.${randomUUID()}.tmp`);
const fd = openSync(temporary, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600);
try { writeFileSync(fd, stableJson(value)); fsyncSync(fd); } finally { closeSync(fd); }
renameSync(temporary, path);
@@ -792,7 +793,7 @@ async function releaseAgreedHold(engine: BrainEngine, page: ApprovedPage, pin: R
return { applied: false, outcome: 'changed_since_preview', reason: 'hold_changed',
detail: { request_id: requestId, action: 'release_hold', message: `The hold on ${pin.path} changed since the preview; preview it again.` } };
}
- const live = await liveFileDrift(engine, page.source_id, page.slug);
+ const live = await heldLiveDrift(engine, page.source_id, page.slug, { hold, mirror: await sourceMirrorReadOnly(engine, page.source_id) });
if (live.reason !== 'agrees' || live.db_revision !== pin.revision || (live.file_hash ?? null) !== pin.file_hash) {
return { applied: false, outcome: 'changed_since_preview', reason: 'revision_conflict',
detail: { request_id: requestId, action: 'release_hold', message: `The page or ${pin.path} changed since the preview (${live.reason}); preview it again.` } };
@@ -801,6 +802,15 @@ async function releaseAgreedHold(engine: BrainEngine, page: ApprovedPage, pin: R
return { applied: true, outcome: 'repaired', detail: { request_id: requestId, action: 'release_hold', path: pin.path } };
}
+/**
+ * Whole-class C1: why a held page on a read-only mirror is kept when letting its file win would append gbrain's protected parts
+ * (protected keys, takes, private facts, database-only timeline rows) to the file, and its next step.
+ */
+export function keptProtectedPartsDetail(sourceId: string, slug: string): string {
+ return `kept: letting the file win would append gbrain's protected parts of page ${slug} (protected keys, takes, private facts or timeline rows) to its file, and this read-only mirror's checkout is never written, so the page stays held with nothing written. `
+ + `Carry those parts into the upstream file and commit it there, then run gbrain sync --source ${sourceId}; the comparison shows what differs: gbrain repair file-drift --source ${sourceId} --slug ${slug} --json`;
+}
+
/** GBRA-133: one held gone file's provenance, as the preview lists it. */
function provenanceText(found: DeletionProvenance): string {
if (found.kind === 'deleted_by_commit') return `deleted by commit ${found.commit.slice(0, 12)} (${found.date}, ${found.author}: ${found.subject})`;
@@ -850,7 +860,7 @@ async function compareSelection(engine: BrainEngine, sourceId: string, opts: Rep
const nextCursor = remaining > 0 && windowed > 0 ? heldCursor(held!.targets[windowed - 1]!.hold.path) : undefined;
if (remaining > 0) residuals.after_window = remaining;
const filesNewer = pages.filter(page => page.would === 'prefer_file').length;
- const next = [...(filesNewer ? [mirror ? `${filesNewer} page(s) have a newer file, but ${mirrorDriftRoute(sourceId)}`
+ const next = [...(filesNewer ? [mirror ? `${filesNewer} page(s) have a newer file; ${mirrorDriftRoute(sourceId, opts.side)}`
: `Preview the file side for the ${filesNewer} page(s) whose file is newer: ${previewCommand(sourceId, { ...opts, prefer: 'file' })} (pages newer than their file are left held, kept_newer_page)`] : []),
...(nextCursor ? [`Compare the next window: ${shellQuote(compareArgv(sourceId, { ...opts, cursor: nextCursor }).slice(0, -1))}`] : [])];
return { items: [], residuals, listing, ...(held ? { complete: remaining === 0 } : {}), details: { compare: true, writes: 'none',
@@ -936,6 +946,7 @@ export const fileDriftRepair: RepairHandler = {
}
const held = opts.held ? await selectHeld(engine, sourceId, opts) : null;
const mirror = held ? await sourceMirrorReadOnly(engine, sourceId) : false;
+ const mirrorFile = mirror && opts.prefer === 'file';
const { slugs, classes, notSelected, unknown } = held
? { slugs: [], classes: new Map<string, DriftClass>(), notSelected: held.notSelected, unknown: [] as UnknownDrift[] } : await selectSlugs(engine, sourceId, opts);
const assessmentAt = new Date().toISOString();
@@ -977,7 +988,7 @@ export const fileDriftRepair: RepairHandler = {
if (targetSlug === null) { count('no_page'); listing.push({ item: `${sourceId}:${label}`, class: 'no_page', detail: 'the hold names no page; the next sync re-classifies it' }); continue; }
const slug = targetSlug;
await authorizeReconcile(engine, sourceId, slug);
- const found = await liveFileDrift(engine, sourceId, slug);
+ const found = await heldLiveDrift(engine, sourceId, slug, { hold: target?.hold, mirror: mirrorFile });
const live = opts.slugs?.length && found.reason === 'database_only' ? await unboundCollisionDrift(engine, sourceId, slug) ?? found : found;
if (target && (target.state === 'file_gone') !== (live.reason === 'canonical_file_missing')) {
count('side_changed');
@@ -1027,6 +1038,12 @@ export const fileDriftRepair: RepairHandler = {
}
const page = await prepareDriftPage(engine, sourceId, slug, opts.prefer, assessmentAt);
if (classes.has(slug)) page.class = classes.get(slug);
+ // Whole-class C1: a read-only mirror's file is never written, so a page whose file-wins result needs protected parts appended stays held.
+ if (mirrorFile && page.file_appended) {
+ count('kept_protected_parts');
+ listing.push({ item: `${sourceId}:${slug}`, class: 'kept_protected_parts', detail: keptProtectedPartsDetail(sourceId, slug) });
+ continue;
+ }
// GST-2579: in bulk a newer file is kept (its hold stays); only an exact --slug selection may discard it, named here and in the consent.
if (page.discards && !opts.slugs?.length) {
count('kept_newer_file');
diff --git a/src/core/schema-embedded.generated.ts b/src/core/schema-embedded.generated.ts
index 48f0f2c4f8..ab10f3a223 100644
--- a/src/core/schema-embedded.generated.ts
+++ b/src/core/schema-embedded.generated.ts
@@ -3788,7 +3788,7 @@ BEGIN
FOR f IN SELECT p.oid::regprocedure AS sig, substr(c.setting, 13) AS path
FROM pg_proc p JOIN pg_namespace n ON n.oid = p.pronamespace CROSS JOIN LATERAL unnest(p.proconfig) AS c(setting)
WHERE n.nspname = 'public' AND p.prokind = 'f' AND c.setting IN ('search_path=pg_catalog, public', 'search_path=pg_catalog')
- AND p.proname IN ('auto_enable_rls', 'bump_page_generation_clock_fn', 'bump_page_generation_fn', 'enforce_minion_queue_protocol', 'gbrain_access_derive_page_readers', 'gbrain_access_folder_rules', 'gbrain_access_lineage_rules', 'gbrain_access_mark_restricted', 'gbrain_access_norm_readers', 'gbrain_access_origin_closed_for', 'gbrain_access_origin_hidden_for', 'gbrain_access_origin_labelled_for', 'gbrain_access_origin_restricted', 'gbrain_access_pending_covers', 'gbrain_access_readers', 'gbrain_access_refresh_serves', 'gbrain_access_refresh_serves_trigger', 'gbrain_access_stamp_folder_rules', 'gbrain_access_state_unreadable', 'gbrain_advance_page_revision', 'gbrain_advance_tag_revision', 'gbrain_bump_trust_generation', 'gbrain_clear_atom_page_state', 'gbrain_concept_inputs_private', 'gbrain_count_git_canonical_sources', 'gbrain_count_modifications', 'gbrain_forget_page_retrievals', 'gbrain_fts_input', 'gbrain_graduation_fence', 'gbrain_guard_deferred_request', 'gbrain_guard_effect_protocol', 'gbrain_guard_guest_records', 'gbrain_guard_inserted_facts', 'gbrain_guard_protocol_activation', 'gbrain_guard_request_protocol', 'gbrain_guard_skill_publication', 'gbrain_lease_shared_skill_delivery', 'gbrain_mark_derivation_scope_entry', 'gbrain_preserve_fact_withdrawal', 'gbrain_queue_page_projection', 'gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take', 'gbrain_refuse_purging_derivation', 'gbrain_release_refresh_barrier', 'gbrain_require_managed_writer', 'gbrain_require_persistence_protocol', 'gbrain_snapshot_version_trust', 'gbrain_stamp_revision_attribution', 'gbrain_stamp_trust_tier', 'gbrain_stamp_version_attribution', 'gbrain_stamp_write_attribution', 'gbrain_try_jsonb', 'notify_minion_job_change', 'update_chunk_search_vector', 'update_page_search_vector')
+ AND p.proname IN ('auto_enable_rls', 'bump_page_generation_clock_fn', 'bump_page_generation_fn', 'enforce_minion_queue_protocol', 'gbrain_access_derive_page_readers', 'gbrain_access_folder_rules', 'gbrain_access_lineage_rules', 'gbrain_access_mark_restricted', 'gbrain_access_norm_readers', 'gbrain_access_origin_closed_for', 'gbrain_access_origin_hidden_for', 'gbrain_access_origin_labelled_for', 'gbrain_access_origin_restricted', 'gbrain_access_pending_covers', 'gbrain_access_readers', 'gbrain_access_refresh_serves', 'gbrain_access_refresh_serves_trigger', 'gbrain_access_stamp_folder_rules', 'gbrain_access_state_unreadable', 'gbrain_advance_page_revision', 'gbrain_advance_tag_revision', 'gbrain_bump_trust_generation', 'gbrain_clear_atom_page_state', 'gbrain_concept_inputs_private', 'gbrain_count_git_canonical_sources', 'gbrain_count_modifications', 'gbrain_forget_page_retrievals', 'gbrain_fts_input', 'gbrain_graduation_fence', 'gbrain_guard_deferred_request', 'gbrain_guard_effect_protocol', 'gbrain_guard_guest_records', 'gbrain_guard_inserted_facts', 'gbrain_guard_protocol_activation', 'gbrain_guard_request_protocol', 'gbrain_guard_skill_publication', 'gbrain_lease_shared_skill_delivery', 'gbrain_mark_derivation_scope_entry', 'gbrain_owner_only_lineage', 'gbrain_preserve_fact_withdrawal', 'gbrain_queue_page_projection', 'gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take', 'gbrain_refuse_purging_derivation', 'gbrain_release_refresh_barrier', 'gbrain_require_managed_writer', 'gbrain_require_persistence_protocol', 'gbrain_snapshot_version_trust', 'gbrain_stamp_revision_attribution', 'gbrain_stamp_trust_tier', 'gbrain_stamp_version_attribution', 'gbrain_stamp_write_attribution', 'gbrain_try_jsonb', 'notify_minion_job_change', 'update_chunk_search_vector', 'update_page_search_vector')
AND pg_has_role(current_user, p.proowner, 'USAGE')
ORDER BY 1
LOOP
diff --git a/src/core/schema-migrations/latest.generated.ts b/src/core/schema-migrations/latest.generated.ts
index 85e81e2a08..34c82f3732 100644
--- a/src/core/schema-migrations/latest.generated.ts
+++ b/src/core/schema-migrations/latest.generated.ts
@@ -4,4 +4,4 @@
// The highest schema migration version (migrate.ts LATEST_VERSION), importable without
// loading the migrations themselves.
-export const LATEST_SCHEMA_VERSION = 319;
+export const LATEST_SCHEMA_VERSION = 320;
diff --git a/src/core/schema-migrations/registry.generated.ts b/src/core/schema-migrations/registry.generated.ts
index 874183243a..9b46163728 100644
--- a/src/core/schema-migrations/registry.generated.ts
+++ b/src/core/schema-migrations/registry.generated.ts
@@ -320,6 +320,7 @@ import { v316 } from './v316-pages-source-type-index.ts';
import { v317 } from './v317-pages-projection-waiting-index.ts';
import { v318 } from './v318-guard-ledgers-fail-closed.ts';
import { v319 } from './v319-principal-private-facts.ts';
+import { v320 } from './v320-owner-only-lineage.ts';
// Array order is historical (see HISTORICAL_ARRAY_ORDER in the generator); the
// runner sorts by version before applying.
@@ -638,4 +639,5 @@ export const MIGRATIONS: Migration[] = [
v317,
v318,
v319,
+ v320,
];
diff --git a/src/core/schema-migrations/v320-owner-only-lineage.ts b/src/core/schema-migrations/v320-owner-only-lineage.ts
new file mode 100644
index 0000000000..79acdfb866
--- /dev/null
+++ b/src/core/schema-migrations/v320-owner-only-lineage.ts
@@ -0,0 +1,62 @@
+import type { Migration } from './types.ts';
+import { OWNER_ONLY_LINEAGE_FN } from '../access/owner-only.ts';
+
+// Applied by src/core/migrate.ts on the next initSchema(); see docs/ENGINES.md
+// ("Canonical schema sources") for when schema.sql or a TS fragment also changes.
+//
+// Owner-only sources (access/owner-only.ts): gbrain_owner_only_lineage() answers whether the brain holds an owner-only
+// source at all (the guard, planned as one Result node instead of a scan of sources), and gbrain_owner_only_lineage(table, id) answers whether the row (a page or a
+// fact) is held in an owner-only source, is a synthesized concept or question with an input page there, or reaches a
+// row there through its recorded derivation inputs (derivation_inputs, followed up to 8 hops). Every read policy that
+// hides owner-only rows calls it behind one uncorrelated test of whether the brain has an owner-only source at all, so
+// a brain without one never calls it, and the planner sees one function call instead of the lineage walk (planned
+// inline, the walk doubled the read policy's planning time). The kinds and the flag repeat OWNER_ONLY_KINDS and
+// OWNER_ONLY_FLAG (test/imessage-owner-only.test.ts keeps them equal). Nothing is stored per row and nothing is
+// rewritten. COST 1: the guard keeps a brain without an owner-only source from ever calling it, so the planner must not
+// charge the default 100 per row (that pushed a 500-page read past jit_above_cost). No schema.sql mirror: like v283, v285 and v305, the function exists only through migrations. Reads call it
+// only at or above OWNER_ONLY_LINEAGE_SINCE (keep it equal to this version on a renumber) and run the walk inline below.
+export const v320: Migration = {
+ version: 320,
+ name: 'owner_only_lineage',
+ idempotent: true,
+ sql: `
+CREATE OR REPLACE FUNCTION ${OWNER_ONLY_LINEAGE_FN}(p_table TEXT, p_id BIGINT) RETURNS boolean
+ LANGUAGE plpgsql STABLE PARALLEL SAFE COST 1 SET search_path = pg_catalog, public, pg_temp AS $fn$
+DECLARE
+ owner_only TEXT[];
+BEGIN
+ SELECT array_agg(s.id) INTO owner_only FROM sources s WHERE s.config->>'kind' IN ('imessage') OR s.config->>'owner_only' = 'true';
+ IF owner_only IS NULL OR p_id IS NULL THEN
+ RETURN false;
+ END IF;
+ IF p_table = 'pages' THEN
+ IF EXISTS (SELECT 1 FROM pages p WHERE p.id = p_id AND p.source_id = ANY(owner_only)) THEN
+ RETURN true;
+ END IF;
+ IF EXISTS (SELECT 1 FROM pages p JOIN links l ON l.from_page_id = p.id JOIN pages i ON i.id = l.to_page_id
+ WHERE p.id = p_id AND p.type IN ('concept', 'question') AND l.link_source = 'concept-provenance'
+ AND l.link_type = 'synthesized_from' AND i.source_id = ANY(owner_only)) THEN
+ RETURN true;
+ END IF;
+ ELSIF p_table = 'facts' THEN
+ IF EXISTS (SELECT 1 FROM facts f WHERE f.id = p_id AND f.source_id = ANY(owner_only)) THEN
+ RETURN true;
+ END IF;
+ END IF;
+ RETURN EXISTS (WITH RECURSIVE up(t, id, depth) AS (
+ SELECT d.input_table, d.input_id, 1 FROM derivation_inputs d WHERE d.derived_table = p_table AND d.derived_id = p_id::text
+ UNION SELECT d.input_table, d.input_id, up.depth + 1 FROM derivation_inputs d JOIN up ON d.derived_table = up.t AND d.derived_id = up.id
+ WHERE up.depth < 8)
+ SELECT 1 FROM up WHERE up.id ~ '^[0-9]{1,18}$' AND (
+ (up.t = 'pages' AND EXISTS (SELECT 1 FROM pages ip WHERE ip.id = up.id::bigint AND ip.source_id = ANY(owner_only)))
+ OR (up.t = 'facts' AND EXISTS (SELECT 1 FROM facts f WHERE f.id = up.id::bigint AND f.source_id = ANY(owner_only)))
+ OR (up.t = 'takes' AND EXISTS (SELECT 1 FROM takes tk JOIN pages tp ON tp.id = tk.page_id WHERE tk.id = up.id::bigint AND tp.source_id = ANY(owner_only)))
+ OR (up.t = 'timeline_entries' AND EXISTS (SELECT 1 FROM timeline_entries te JOIN pages tep ON tep.id = te.page_id WHERE te.id = up.id::bigint AND tep.source_id = ANY(owner_only)))));
+END
+$fn$;
+CREATE OR REPLACE FUNCTION ${OWNER_ONLY_LINEAGE_FN}() RETURNS boolean
+ LANGUAGE sql STABLE PARALLEL SAFE SET search_path = pg_catalog, public, pg_temp AS $fn$
+ SELECT EXISTS (SELECT 1 FROM sources s WHERE s.config->>'kind' IN ('imessage') OR s.config->>'owner_only' = 'true')
+$fn$;
+`,
+};
diff --git a/src/core/schema-pack/base/gbrain-base.yaml b/src/core/schema-pack/base/gbrain-base.yaml
index f915532511..e54fd5d3af 100644
--- a/src/core/schema-pack/base/gbrain-base.yaml
+++ b/src/core/schema-pack/base/gbrain-base.yaml
@@ -205,6 +205,17 @@ page_types:
extractable: true
expert_routing: false
+ # imessage source kind: one private, owner-only page per chat per day. Not
+ # extractable: atom extraction never sends other people's messages to a
+ # model on its own (facts follow the connector's own extraction setting).
+ - name: imessage
+ primitive: temporal
+ path_prefixes:
+ - imessage/
+ aliases: []
+ extractable: false
+ expert_routing: false
+
- name: calendar-event
primitive: temporal
path_prefixes:
diff --git a/src/core/search/private-visibility.ts b/src/core/search/private-visibility.ts
index a35982a943..e30e3d37f1 100644
--- a/src/core/search/private-visibility.ts
+++ b/src/core/search/private-visibility.ts
@@ -31,6 +31,7 @@ import { ACCESS_ID_RE, hasReaders, MEMBER_PAGE_PREFIX, normalizePrincipal, reade
import { ruleCoversSql, validPrefix, validQualifiedRuleId } from '../access/folder-rules.ts';
import { holdingSlugSql } from '../facts-fence.ts';
import { atomMovedOriginPrivateSql, atomOriginSlugsSql } from '../persistence/atom-origin.ts';
+import { ownerOnlyFactSql, ownerOnlyForm, ownerOnlyPageSql, ownerOnlySourcesPresent } from '../access/owner-only.ts';
export const REMOTE_PRIVATE_PAGES_KEY = 'search.remote_private_pages';
@@ -114,9 +115,19 @@ export function accessAllowedSql(pageAlias: string, identity: readonly string[],
* the origin of what was derived from it (a fact's provenance page): raw-only rules (covers_derived false) do not count.
*/
export function accessAllowedForAllSql(pageAlias: string, identities: readonly (readonly string[])[], satisfied: readonly string[], derived = false): string {
- if (!currentCallerAccess().restricted) return `(${pageAlias}.page_readers IS NULL AND ${pageAlias}.folder_rule_ids IS NULL)`;
+ const ownerOnly = ownerOnlyAllowedSql(pageAlias, currentCallerAccess());
+ if (!currentCallerAccess().restricted) return `(${pageAlias}.page_readers IS NULL AND ${pageAlias}.folder_rule_ids IS NULL${ownerOnly})`;
const readers = (identities.length ? identities : [[]]).map(identity => readersAllowedSql(pageAlias, identity)).join(' AND ');
- return `(${readers} AND ${folderRulesAllowedSql(pageAlias, satisfied, derived)} AND ${originAllowedSql(pageAlias)})`;
+ return `(${readers} AND ${folderRulesAllowedSql(pageAlias, satisfied, derived)} AND ${originAllowedSql(pageAlias)}${ownerOnly})`;
+}
+
+/**
+ * Owner-only sources (access/owner-only.ts): a page in one, or derived from one, passes only for an owner read
+ * (CallerAccess.owner, never an audience of others or an attested call). Part of the member-access predicate, so no
+ * grant, hatch, lineage setting or owner opt-in relaxes it; empty for the owner.
+ */
+function ownerOnlyAllowedSql(pageAlias: string, access: Pick<CallerAccess, 'owner'>): string {
+ return access.owner ? '' : ` AND NOT ${ownerOnlyPageSql(pageAlias, ownerOnlyForm(readSchemaVersion()))}`;
}
/**
@@ -255,14 +266,15 @@ function lineageOriginAllowedSql(p: string, access: CallerAccess, ownPage: strin
function lineageAccessSql(pageAlias: string, access: CallerAccess, ownPage: string, derived = false): string {
const audience = audiencePages(access);
const notOther = notOtherMemberPageSql(pageAlias, ownPage, audience);
+ const ownerOnly = ownerOnlyAllowedSql(pageAlias, access);
if (!access.restricted) {
const unrestricted = `(${pageAlias}.page_readers IS NULL AND ${pageAlias}.folder_rule_ids IS NULL)`;
- return access.ownerReadsRestricted ? `(${unrestricted} OR ${notOther})` : unrestricted;
+ return `(${access.ownerReadsRestricted ? `(${unrestricted} OR ${notOther})` : unrestricted}${ownerOnly})`;
}
const readers = audience.length ? `(${readersAllowedSql(pageAlias, access.identity)} OR ${audiencePageSql(pageAlias, audience)})` : readersAllowedSql(pageAlias, access.identity);
const listed = `(${readers} AND ${folderRulesAllowedSql(pageAlias, access.satisfiedRuleIds, derived)})`;
const page = access.ownerReadsRestricted ? `(${listed} OR (${notOther}${coverageSql(pageAlias)}))` : listed;
- return `(${page} AND ${lineageOriginAllowedSql(pageAlias, access, ownPage)})`;
+ return `(${page} AND ${lineageOriginAllowedSql(pageAlias, access, ownPage)}${ownerOnly})`;
}
/**
@@ -271,7 +283,7 @@ function lineageAccessSql(pageAlias: string, access: CallerAccess, ownPage: stri
* access.owner_reads_restricted and audience members never apply here: a page kept to other members stays closed.
*/
export function ownerReadPolicyFragment(pageAlias: string, identity: readonly string[], satisfied: readonly string[]): string {
- const access: CallerAccess = { ...currentCallerAccess(), identity, satisfiedRuleIds: satisfied, lineage: true, ownerReadsRestricted: false, audienceKindMembers: [], restricted: true };
+ const access: CallerAccess = { ...currentCallerAccess(), identity, satisfiedRuleIds: satisfied, owner: true, lineage: true, ownerReadsRestricted: false, audienceKindMembers: [], restricted: true };
const ownPage = lineageReadPage(access);
return ownPage ? `(${lineageAccessSql(pageAlias, access, ownPage)} AND ${privacyPartSql(pageAlias)})` : 'FALSE';
}
@@ -730,12 +742,17 @@ export function privateSnapshotFilterFragment(alias: string): string {
/** The schema version (migration v311) that creates gbrain_concept_inputs_private; a literal so the CLI dispatcher never loads a migration module. */
export const CONCEPT_INPUTS_PRIVATE_SINCE = 311;
+/** The read's schema version: the one its remote, scope or attested caller record carries, else the one the engine in scope recorded (schemaVersionSeen); undefined when neither. */
+function readSchemaVersion(): number | undefined {
+ const { remotePolicy } = currentCallerAccess();
+ const scoped = engineScopeStore.getStore();
+ return remotePolicy ? remotePolicy.schemaVersion : scoped ? schemaVersionSeen(scoped) : undefined;
+}
+
function derivedOriginPrivateSql(p: string, shadowedPages: boolean): string {
const privateOrigin = (atom: string, alias: string) => `EXISTS (SELECT 1 FROM pages ${alias} WHERE ${alias}.source_id = ${atom}.source_id
AND ${alias}.slug = ANY(${atomOriginSlugsSql(atom)}) AND ${alias}.frontmatter->>'visibility' = 'private')`;
- const { remotePolicy } = currentCallerAccess();
- const scoped = engineScopeStore.getStore();
- const schema = remotePolicy ? remotePolicy.schemaVersion : scoped ? schemaVersionSeen(scoped) : undefined;
+ const schema = readSchemaVersion();
const conceptInputsPrivate = !shadowedPages && schema !== undefined && schema >= CONCEPT_INPUTS_PRIVATE_SINCE ? `gbrain_concept_inputs_private((${p}.id)::integer)`
: `EXISTS (SELECT 1 FROM links derived_input_link
JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id
@@ -969,7 +986,7 @@ export function privateProvenanceFilterUnderPolicy(factAlias: string, perCandida
const policy = member && ACCESS_ID_RE.test(member)
? `CASE WHEN pp.slug = '${MEMBER_PAGE_PREFIX}${member}' THEN ${readPolicyFragment('pp', access.identity, hide, access.satisfiedRuleIds, true)} ELSE ${otherwise} END`
: otherwise;
- return `(NOT EXISTS (SELECT 1 FROM pages pp WHERE pp.source_id = ${factAlias}.source_id AND pp.slug = ${factAlias}.source_markdown_slug AND NOT (${policy})) AND ${privateEntityFilterForCaller(factAlias, perCandidate)}${labelledOnlyFactSql(factAlias)})`;
+ return `(NOT EXISTS (SELECT 1 FROM pages pp WHERE pp.source_id = ${factAlias}.source_id AND pp.slug = ${factAlias}.source_markdown_slug AND NOT (${policy})) AND ${privateEntityFilterForCaller(factAlias, perCandidate)}${labelledOnlyFactSql(factAlias)}${ownerOnlyFactAllowedSql(factAlias)})`;
}
/**
@@ -1028,8 +1045,13 @@ export function callerRelaxesPrivacy(): boolean {
}
export function privateProvenanceFilterFragment(factAlias: string): string {
- return `NOT EXISTS (SELECT 1 FROM pages pp WHERE pp.source_id = ${factAlias}.source_id ` +
- `AND pp.slug = ${factAlias}.source_markdown_slug AND NOT (${privatePagesFilterFragment('pp', true)}))`;
+ return `(NOT EXISTS (SELECT 1 FROM pages pp WHERE pp.source_id = ${factAlias}.source_id ` +
+ `AND pp.slug = ${factAlias}.source_markdown_slug AND NOT (${privatePagesFilterFragment('pp', true)}))${ownerOnlyFactAllowedSql(factAlias)})`;
+}
+
+/** A fact held in or derived from an owner-only source (access/owner-only.ts) passes only for an owner read; empty for the owner. */
+function ownerOnlyFactAllowedSql(factAlias: string): string {
+ return currentCallerAccess().owner ? '' : ` AND NOT ${ownerOnlyFactSql(factAlias, ownerOnlyForm(readSchemaVersion()))}`;
}
/**
@@ -1274,5 +1296,5 @@ export async function resolveExcludePrivatePages(
if (!await remotePrivacyRelaxed(engine)) return true;
const access = currentCallerAccess();
if (access.audience?.length && access.hidePrivate) return true;
- return accessRestrictionsPresent(engine);
+ return await accessRestrictionsPresent(engine) || (!access.owner && await ownerOnlySourcesPresent(engine));
}
diff --git a/src/core/slack/slack-source.ts b/src/core/slack/slack-source.ts
index 98b8924e82..ea6a3b9fc6 100644
--- a/src/core/slack/slack-source.ts
+++ b/src/core/slack/slack-source.ts
@@ -46,6 +46,8 @@ import type { SlackAccount, SlackChannelInfo, SlackMessage, SlackSourceConfig, S
/** The user list is re-read when a message names a user it lacks, or once this old. */
const USERS_MAX_AGE_MS = 7 * 86_400_000;
+// A user the last listing lacked (cached under its raw id) is looked up again after a day; a Slack Connect user never appears.
+const USERS_MISSING_RETRY_MS = 86_400_000;
export interface SlackChannelState {
committed_to: string | null;
@@ -193,8 +195,9 @@ async function runSlackSyncInner(engine: BrainEngine, sourceId: string, cfg: Sla
if (m.user) ids.add(m.user);
for (const match of (m.text ?? '').matchAll(MENTION_RE)) ids.add(match[1]!);
}
- const stale = !state.users_listed_at || runStart - Date.parse(state.users_listed_at) > USERS_MAX_AGE_MS;
- if (listedUsers || (!stale && [...ids].every(id => state.users[id]))) return;
+ const age = state.users_listed_at ? runStart - Date.parse(state.users_listed_at) : Infinity;
+ const known = (id: string) => state.users[id] && (state.users[id]!.name !== id || !(age > USERS_MISSING_RETRY_MS));
+ if (listedUsers || (!(age > USERS_MAX_AGE_MS) && [...ids].every(known))) return;
const list = await api!.usersList(signal);
listedUsers = true;
state.users_listed_at = new Date(runStart).toISOString();
diff --git a/src/core/source-default-search.ts b/src/core/source-default-search.ts
index ae4a4b6b5a..e0f6266c02 100644
--- a/src/core/source-default-search.ts
+++ b/src/core/source-default-search.ts
@@ -32,7 +32,7 @@ async function acceptedChoice(engine: BrainEngine, opts: AddSourceOpts): Promise
/** Folder and Git sources only: connectors keep their own defaults (GitHub and Google federated, meetings and Slack chats out). */
export async function withDefaultSearchChoice(engine: BrainEngine, opts: AddSourceOpts): Promise<AddSourceOpts> {
- if (opts.federated != null || opts.github || opts.google || opts.meetings || opts.slack || opts.addedByRemoteCaller) return opts;
+ if (opts.federated != null || opts.github || opts.google || opts.meetings || opts.slack || opts.imessage || opts.addedByRemoteCaller) return opts;
const accepted = await acceptedChoice(engine, opts);
if (accepted) return accepted;
const joins = await newSourceJoinsDefaultSearch(engine);
diff --git a/src/core/sources-ops.ts b/src/core/sources-ops.ts
index 0206bcc870..e5619c6652 100644
--- a/src/core/sources-ops.ts
+++ b/src/core/sources-ops.ts
@@ -229,6 +229,8 @@ export interface AddSourceOpts {
* `tokenEnv`; no secret lands in sources.config. See src/core/slack/.
*/
slack?: import('./slack/source-add.ts').AddSourceSlackOpts;
+ /** Register an imessage-kind source (the GBrain Helper on this Mac); always database-recorded and owner-only. See src/core/imessage/. */
+ imessage?: import('./imessage/source-add.ts').AddSourceIMessageOpts;
}
export interface RemoveSourceOpts {
@@ -437,7 +439,13 @@ export async function assertNoOverlappingPath(
* pages into --dir, inside a Git checkout that no other source covers (a nested
* root would import every page twice).
*/
-async function insertApiSource(engine: BrainEngine, opts: AddSourceOpts, kind: 'meetings' | 'slack'): Promise<void> {
+async function insertApiSource(engine: BrainEngine, opts: AddSourceOpts, kind: 'meetings' | 'slack' | 'imessage'): Promise<void> {
+ if (kind === 'imessage') {
+ const { imessageSourceConfig } = await import('./imessage/source-add.ts');
+ await engine.executeRaw('INSERT INTO sources (id, name, local_path, config) VALUES ($1, $2, NULL, $3::text::jsonb)',
+ [opts.id, opts.name ?? opts.id, JSON.stringify(imessageSourceConfig(opts.imessage!, opts.federated))]);
+ return;
+ }
const { chooseMeetingsRecord, meetingsSourceConfig } = await import('./meetings/source-add.ts');
const { slackSourceConfig } = await import('./slack/source-add.ts');
const request = kind === 'slack' ? opts.slack! : opts.meetings!;
@@ -521,7 +529,7 @@ export async function addSource(
!!opts.localPath &&
!opts.remoteUrl &&
!opts.github &&
- !opts.google && !opts.meetings && !opts.slack;
+ !opts.google && !opts.meetings && !opts.slack && !opts.imessage;
if (existing.length > 0 && !attachPath) {
const pathNote = existing[0]!.local_path
? ` with local_path ${existing[0]!.local_path}`
@@ -697,8 +705,8 @@ export async function addSource(
VALUES ($1, $2, $3, $4::text::jsonb)`,
[opts.id, displayName, finalPath, JSON.stringify(config)],
);
- } else if (opts.meetings || opts.slack) {
- await insertApiSource(engine, opts, opts.slack ? 'slack' : 'meetings');
+ } else if (opts.meetings || opts.slack || opts.imessage) {
+ await insertApiSource(engine, opts, opts.imessage ? 'imessage' : opts.slack ? 'slack' : 'meetings');
} else {
// ── Path B: --path or no path (existing behavior, pre-v0.28) ─────────
// #2707: only validate when the path actually exists — a not-yet-created
diff --git a/src/schema.sql b/src/schema.sql
index fbca6302e8..97ad2f7270 100644
--- a/src/schema.sql
+++ b/src/schema.sql
@@ -3784,7 +3784,7 @@ BEGIN
FOR f IN SELECT p.oid::regprocedure AS sig, substr(c.setting, 13) AS path
FROM pg_proc p JOIN pg_namespace n ON n.oid = p.pronamespace CROSS JOIN LATERAL unnest(p.proconfig) AS c(setting)
WHERE n.nspname = 'public' AND p.prokind = 'f' AND c.setting IN ('search_path=pg_catalog, public', 'search_path=pg_catalog')
- AND p.proname IN ('auto_enable_rls', 'bump_page_generation_clock_fn', 'bump_page_generation_fn', 'enforce_minion_queue_protocol', 'gbrain_access_derive_page_readers', 'gbrain_access_folder_rules', 'gbrain_access_lineage_rules', 'gbrain_access_mark_restricted', 'gbrain_access_norm_readers', 'gbrain_access_origin_closed_for', 'gbrain_access_origin_hidden_for', 'gbrain_access_origin_labelled_for', 'gbrain_access_origin_restricted', 'gbrain_access_pending_covers', 'gbrain_access_readers', 'gbrain_access_refresh_serves', 'gbrain_access_refresh_serves_trigger', 'gbrain_access_stamp_folder_rules', 'gbrain_access_state_unreadable', 'gbrain_advance_page_revision', 'gbrain_advance_tag_revision', 'gbrain_bump_trust_generation', 'gbrain_clear_atom_page_state', 'gbrain_concept_inputs_private', 'gbrain_count_git_canonical_sources', 'gbrain_count_modifications', 'gbrain_forget_page_retrievals', 'gbrain_fts_input', 'gbrain_graduation_fence', 'gbrain_guard_deferred_request', 'gbrain_guard_effect_protocol', 'gbrain_guard_guest_records', 'gbrain_guard_inserted_facts', 'gbrain_guard_protocol_activation', 'gbrain_guard_request_protocol', 'gbrain_guard_skill_publication', 'gbrain_lease_shared_skill_delivery', 'gbrain_mark_derivation_scope_entry', 'gbrain_preserve_fact_withdrawal', 'gbrain_queue_page_projection', 'gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take', 'gbrain_refuse_purging_derivation', 'gbrain_release_refresh_barrier', 'gbrain_require_managed_writer', 'gbrain_require_persistence_protocol', 'gbrain_snapshot_version_trust', 'gbrain_stamp_revision_attribution', 'gbrain_stamp_trust_tier', 'gbrain_stamp_version_attribution', 'gbrain_stamp_write_attribution', 'gbrain_try_jsonb', 'notify_minion_job_change', 'update_chunk_search_vector', 'update_page_search_vector')
+ AND p.proname IN ('auto_enable_rls', 'bump_page_generation_clock_fn', 'bump_page_generation_fn', 'enforce_minion_queue_protocol', 'gbrain_access_derive_page_readers', 'gbrain_access_folder_rules', 'gbrain_access_lineage_rules', 'gbrain_access_mark_restricted', 'gbrain_access_norm_readers', 'gbrain_access_origin_closed_for', 'gbrain_access_origin_hidden_for', 'gbrain_access_origin_labelled_for', 'gbrain_access_origin_restricted', 'gbrain_access_pending_covers', 'gbrain_access_readers', 'gbrain_access_refresh_serves', 'gbrain_access_refresh_serves_trigger', 'gbrain_access_stamp_folder_rules', 'gbrain_access_state_unreadable', 'gbrain_advance_page_revision', 'gbrain_advance_tag_revision', 'gbrain_bump_trust_generation', 'gbrain_clear_atom_page_state', 'gbrain_concept_inputs_private', 'gbrain_count_git_canonical_sources', 'gbrain_count_modifications', 'gbrain_forget_page_retrievals', 'gbrain_fts_input', 'gbrain_graduation_fence', 'gbrain_guard_deferred_request', 'gbrain_guard_effect_protocol', 'gbrain_guard_guest_records', 'gbrain_guard_inserted_facts', 'gbrain_guard_protocol_activation', 'gbrain_guard_request_protocol', 'gbrain_guard_skill_publication', 'gbrain_lease_shared_skill_delivery', 'gbrain_mark_derivation_scope_entry', 'gbrain_owner_only_lineage', 'gbrain_preserve_fact_withdrawal', 'gbrain_queue_page_projection', 'gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take', 'gbrain_refuse_purging_derivation', 'gbrain_release_refresh_barrier', 'gbrain_require_managed_writer', 'gbrain_require_persistence_protocol', 'gbrain_snapshot_version_trust', 'gbrain_stamp_revision_attribution', 'gbrain_stamp_trust_tier', 'gbrain_stamp_version_attribution', 'gbrain_stamp_write_attribution', 'gbrain_try_jsonb', 'notify_minion_job_change', 'update_chunk_search_vector', 'update_page_search_vector')
AND pg_has_role(current_user, p.proowner, 'USAGE')
ORDER BY 1
LOOP
diff --git a/test/access-unrestricted-fast-path.test.ts b/test/access-unrestricted-fast-path.test.ts
index 7b529bbcff..c270000098 100644
--- a/test/access-unrestricted-fast-path.test.ts
+++ b/test/access-unrestricted-fast-path.test.ts
@@ -15,6 +15,7 @@ import { sqlQueryForEngine } from '../src/core/sql-query.ts';
import { dispatchToolCall } from '../src/mcp/dispatch.ts';
import { accessAllowedSql, withCallerAccess } from '../src/core/search/private-visibility.ts';
import type { AuthInfo } from '../src/core/ops/contract.ts';
+import { ownerOnlyPageSql } from '../src/core/access/owner-only.ts';
const SRC = 'fast-src';
let engine: PGLiteEngine;
@@ -47,7 +48,9 @@ describe('unrestricted fast path (pglite, repo-less)', () => {
const short = withCallerAccess({ restricted: false }, () => accessAllowedSql('p', ['member:alice-example']));
expect(full).toContain('gbrain_access_origin_restricted');
expect(short).not.toContain('gbrain_access_origin_restricted');
- expect(short).toBe('(p.page_readers IS NULL AND p.folder_rule_ids IS NULL)');
+ // Owner-only sources (access/owner-only.ts) stay mandatory on the short form. With no schema version in scope it is the
+ // fail-closed form: one uncorrelated EXISTS.
+ expect(short).toBe(`(p.page_readers IS NULL AND p.folder_rule_ids IS NULL AND NOT ${ownerOnlyPageSql('p', 'closed')})`);
expect(accessAllowedSql('p', [])).toContain('gbrain_access_origin_restricted');
});
diff --git a/test/cycle-synthesize-summary-same-day.test.ts b/test/cycle-synthesize-summary-same-day.test.ts
new file mode 100644
index 0000000000..5ff4427113
--- /dev/null
+++ b/test/cycle-synthesize-summary-same-day.test.ts
@@ -0,0 +1,49 @@
+/** #9598: a later same-day synthesize run keeps the earlier runs' summary links to live pages, and counts them apart. */
+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
+import { mkdtempSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { __testing } from '../src/core/cycle/synthesize.ts';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import { resetPgliteState } from './helpers/reset-pglite.ts';
+
+const writeSummaryPage = __testing.writeSummaryPage as (
+ engine: PGLiteEngine, brainDir: string, slug: string, date: string, written: string[],
+ outcomes: Array<{ jobId: number; status: string }>,
+) => Promise<unknown>;
+
+let engine: PGLiteEngine;
+beforeAll(async () => {
+ engine = new PGLiteEngine();
+ await engine.connect({});
+ await engine.initSchema();
+});
+afterAll(async () => {
+ await engine.disconnect();
+});
+
+describe('same-day dream summary (#9598)', () => {
+ test('a second run lists its own page and the first run\'s live pages, counting each run apart', async () => {
+ await resetPgliteState(engine);
+ const brainDir = mkdtempSync(join(tmpdir(), 'gbrain-summary-same-day-'));
+ const summary = 'dream-cycle-summaries/2026-08-20';
+ try {
+ for (const s of ['wiki/a', 'wiki/b', 'wiki/c']) {
+ await engine.putPage(s, { type: 'note', title: s, compiled_truth: 'body' });
+ }
+ const outcomes = [{ jobId: 1, status: 'completed' }];
+ await writeSummaryPage(engine, brainDir, summary, '2026-08-20', ['wiki/a', 'wiki/b'], outcomes);
+ await engine.deletePage('wiki/b');
+ await writeSummaryPage(engine, brainDir, summary, '2026-08-20', ['wiki/c'], outcomes);
+ const body = (await engine.getPage(summary))?.compiled_truth ?? '';
+ expect(body).toContain('- [[wiki/a]]');
+ expect(body).toContain('- [[wiki/c]]');
+ expect(body).not.toContain('[[wiki/b]]');
+ expect(body).toContain('**Pages written:** 1.');
+ expect(body).toContain('**Pages from earlier runs today:** 1.');
+ expect(body).toContain('## Pages');
+ } finally {
+ rmSync(brainDir, { recursive: true, force: true });
+ }
+ }, 120_000);
+});
diff --git a/test/dream-input-no-database-9608.test.ts b/test/dream-input-no-database-9608.test.ts
new file mode 100644
index 0000000000..a93488a1d0
--- /dev/null
+++ b/test/dream-input-no-database-9608.test.ts
@@ -0,0 +1,35 @@
+import { afterAll, beforeAll, expect, spyOn, test } from 'bun:test';
+import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { runDream } from '../src/commands/dream.ts';
+import { withEnv } from './helpers/with-env.ts';
+
+let home: string;
+let dir: string;
+
+beforeAll(() => {
+ home = mkdtempSync(join(tmpdir(), 'gbrain-dream-nodb-home-'));
+ dir = mkdtempSync(join(tmpdir(), 'gbrain-dream-nodb-dir-'));
+ writeFileSync(join(dir, 'transcript.txt'), 'a transcript long enough to matter\n'.repeat(50));
+});
+afterAll(() => {
+ rmSync(home, { recursive: true, force: true });
+ rmSync(dir, { recursive: true, force: true });
+});
+
+test('dream --input without a database exits non-zero', () => withEnv({ GBRAIN_HOME: home }, async () => {
+ const exit = spyOn(process, 'exit').mockImplementation(((code?: number) => { throw new Error(`EXIT ${code}`); }) as never);
+ const log = spyOn(console, 'log').mockImplementation(() => {});
+ const err = spyOn(console, 'error').mockImplementation(() => {});
+ const out = spyOn(process.stdout, 'write').mockImplementation((() => true) as never);
+ let outcome = 'returned';
+ try {
+ await runDream(null, ['--input', join(dir, 'transcript.txt'), '--dir', dir, '--json']);
+ } catch (e) {
+ outcome = (e as Error).message;
+ } finally {
+ exit.mockRestore(); log.mockRestore(); err.mockRestore(); out.mockRestore();
+ }
+ expect(outcome).toBe('EXIT 1');
+}), 60_000);
diff --git a/test/e2e/imessage-source-postgres.test.ts b/test/e2e/imessage-source-postgres.test.ts
new file mode 100644
index 0000000000..2b6951cd66
--- /dev/null
+++ b/test/e2e/imessage-source-postgres.test.ts
@@ -0,0 +1,3 @@
+import { registerPostgresTests } from '../helpers/test-backends.ts';
+
+await registerPostgresTests(() => import('../imessage-source.test.ts'), () => import('../imessage-owner-only.test.ts'));
diff --git a/test/facts-slot-windows-gbra574.test.ts b/test/facts-slot-windows-gbra574.test.ts
index d3e73f36e4..7394c3b131 100644
--- a/test/facts-slot-windows-gbra574.test.ts
+++ b/test/facts-slot-windows-gbra574.test.ts
@@ -32,7 +32,8 @@ import { dispatchToolCall } from '../src/mcp/dispatch.ts';
import { handleToolCall } from '../src/mcp/server.ts';
import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';
import { submitPageMutation } from '../src/core/persistence/page-mutations.ts';
-import { configureGateway, resetGateway, __setEmbedTransportForTests } from '../src/core/ai/gateway.ts';
+import { configureGateway, resetGateway, __setChatTransportForTests, __setEmbedTransportForTests, type ChatResult } from '../src/core/ai/gateway.ts';
+import { SLOT_TAG_SYSTEM } from '../src/core/facts/slot-tagging.ts';
import { LEGACY_EMBEDDING_CONFIG } from './helpers/legacy-embedding-config.ts';
import { persistencePostgresTemplate } from './helpers/persistence-postgres.ts';
import { requirePostgresTestDatabase, testBackends } from './helpers/test-backends.ts';
@@ -501,5 +502,25 @@ describe('managed brain', () => {
]);
}, { databaseUrl: backend === 'postgres' ? requirePostgresTestDatabase() : undefined });
}, 120_000);
+
+ test(`${backend}: a slot from the tagging call rides the receipted batch`, async () => {
+ const reply = (text: string) => ({ text, blocks: [{ type: 'text', text }], stopReason: 'end', model: 'test:stub', providerId: 'test',
+ usage: { input_tokens: 0, output_tokens: 0, cache_read_tokens: 0, cache_creation_tokens: 0 } }) as ChatResult;
+ __setChatTransportForTests(async opts => reply(opts.system === SLOT_TAG_SYSTEM
+ ? '{"slots":[{"i":1,"dimension":"location","value":"Lisbon"}]}'
+ : JSON.stringify({ facts: [{ fact: 'Alice Example lives in Lisbon.', kind: 'fact', entity: ALICE, confidence: 1, notability: 'high' }] })));
+ try {
+ await managedBrain(async (brain) => {
+ await putManaged(brain);
+ const result = await runExtractConversationFactsCore(brain.engine, { sourceId: 'default', slugs: [SLUG], sleepMs: 0, overrideDisabled: true });
+ expect([result.pages_failed, result.pages_processed, result.slot_tagging_failed]).toEqual([0, 1, undefined]);
+ const rows = await brain.engine.executeRaw<{ fact: string; dimension: string | null; value: string | null; value_hash: string | null; dim_status: string | null }>(
+ `SELECT fact, dimension, value, value_hash, dim_status FROM facts WHERE source_id='default' AND source_markdown_slug=$1
+ AND source LIKE 'cli:extract-conversation-facts%' AND fact NOT LIKE 'EXTRACTION_%' AND expired_at IS NULL`, [SLUG]);
+ expect(rows.map(r => [r.fact, r.dimension, r.value, r.value_hash, r.dim_status])).toEqual([
+ ['Alice Example lives in Lisbon.', 'location', 'Lisbon', valueHash('Lisbon'), 'active']]);
+ }, { databaseUrl: backend === 'postgres' ? requirePostgresTestDatabase() : undefined });
+ } finally { __setChatTransportForTests(null); resetGateway(); }
+ }, 120_000);
}
});
diff --git a/test/facts/extract-slots.test.ts b/test/facts/extract-slots.test.ts
index ad29cf2db9..c7b57f75f7 100644
--- a/test/facts/extract-slots.test.ts
+++ b/test/facts/extract-slots.test.ts
@@ -5,6 +5,7 @@
* preferences and ideas on two public dev worlds), so the call's system prompt stays byte-identical to the historical one
* for every variant (pinned by hash), its schema has no slot field, and a slot the model returns anyway is never stored.
* Regression: a conversation extraction call that carries slot text or a slot field.
+ * Slots come from the separate tagging call (slot-tagging.test.ts); the stub answers it with no slot.
* Seams: gateway chat transport stub (no provider call), PGLite with no git repository.
*/
import { createHash } from 'node:crypto';
@@ -12,6 +13,7 @@ import { afterAll, afterEach, beforeAll, describe, expect, spyOn, test } from 'b
import { runExtractConversationFactsCore } from '../../src/commands/extract-conversation-facts.ts';
import { __setChatTransportForTests, resetGateway, type ChatOpts, type ChatResult } from '../../src/core/ai/gateway.ts';
import { buildExtractorSystem } from '../../src/core/facts/extract.ts';
+import { SLOT_TAG_SYSTEM } from '../../src/core/facts/slot-tagging.ts';
import { PGLiteEngine } from '../../src/core/pglite-engine.ts';
const sha = (s: string) => createHash('sha256').update(s).digest('hex');
@@ -57,6 +59,8 @@ describe('conversation extraction main call', () => {
test('sends the historical prompt and a schema with no slot, and stores no slot the model returns anyway', async () => {
const seen: ChatOpts[] = [];
__setChatTransportForTests(async (opts): Promise<ChatResult> => {
+ if (opts.system === SLOT_TAG_SYSTEM) return { text: '{"slots":[]}', blocks: [{ type: 'text', text: '{"slots":[]}' }], stopReason: 'end', model: 'test:stub',
+ providerId: 'test', usage: { input_tokens: 0, output_tokens: 0, cache_read_tokens: 0, cache_creation_tokens: 0 } } as ChatResult;
seen.push(opts);
const text = JSON.stringify({ facts: [
{ fact: 'Alice Example joined Acme Example as head of design.', kind: 'fact', entity: 'people/alice-example', confidence: 1,
diff --git a/test/facts/slot-tagging.test.ts b/test/facts/slot-tagging.test.ts
new file mode 100644
index 0000000000..a73f6c6f35
--- /dev/null
+++ b/test/facts/slot-tagging.test.ts
@@ -0,0 +1,169 @@
+/**
+ * GBRA-574: conversation fact slots come from a second, small call after extraction (facts/slot-tagging.ts).
+ *
+ * Protects: the call reads only facts whose person was named exactly and is a live person page, of a kind that can
+ * state a slot; it stores only normalized slots; a failed call keeps the facts without slots and is counted; an
+ * exhausted budget stops the run; the --dry-run estimate and the page cap price the call.
+ * Seams: gateway chat transport stub (no provider call), PGLite with no git repository.
+ */
+import { afterAll, afterEach, beforeAll, describe, expect, spyOn, test } from 'bun:test';
+import { runExtractConversationFactsCore } from '../../src/commands/extract-conversation-facts.ts';
+import { __setChatTransportForTests, configureGateway, resetGateway, type ChatOpts, type ChatResult } from '../../src/core/ai/gateway.ts';
+import { CHAT_INPUT_CHARS_PER_TOKEN } from '../../src/core/ai/chat-input-estimate.ts';
+import { BudgetExhausted } from '../../src/core/budget/budget-tracker.ts';
+import { conversationRunEstimate, OUTPUT_TOKENS_PER_SEGMENT } from '../../src/core/facts/conversation-budget.ts';
+import { SEGMENT_TEXT_CHAR_LIMIT } from '../../src/core/facts/conversation-windows.ts';
+import { buildExtractorSystem, getExtractorVariant } from '../../src/core/facts/extract.ts';
+import { SLOT_TAG_INPUT_CHARS, SLOT_TAG_MAX_TOKENS, SLOT_TAG_SYSTEM, tagSlots } from '../../src/core/facts/slot-tagging.ts';
+import { PGLiteEngine } from '../../src/core/pglite-engine.ts';
+
+const ALICE = 'people/alice-example';
+const reply = (text: string): ChatResult => ({ text, blocks: [{ type: 'text', text }], stopReason: 'end', model: 'test:stub', providerId: 'test',
+ usage: { input_tokens: 0, output_tokens: 0, cache_read_tokens: 0, cache_creation_tokens: 0 } }) as ChatResult;
+const fact = (text: string, kind: string, entity: string | null) => ({ fact: text, kind, entity_slug: entity });
+
+let engine: PGLiteEngine;
+beforeAll(async () => {
+ engine = new PGLiteEngine();
+ await engine.connect({});
+ await engine.initSchema();
+ await engine.setConfig('facts.extraction_enabled', 'true');
+ await engine.setConfig('facts.default_visibility', 'world');
+ await engine.setConfig('conversation_parser.llm_fallback_enabled', 'false');
+ const page = (slug: string, type: string, title: string, frontmatter: Record<string, unknown> = {}) =>
+ engine.putPage(slug, { type: type as never, title, compiled_truth: `# ${title}`, timeline: '', frontmatter });
+ await page(ALICE, 'person', 'Alice Example');
+ await page('people/bob-example', 'person', 'Bob Example', { superseded_by: ALICE });
+ await page('companies/acme-example', 'company', 'Acme Example');
+}, 60_000);
+afterAll(async () => { await engine.disconnect(); });
+afterEach(() => { __setChatTransportForTests(null); resetGateway(); });
+
+function stub(answer: (opts: ChatOpts) => ChatResult | Promise<ChatResult>): ChatOpts[] {
+ const seen: ChatOpts[] = [];
+ __setChatTransportForTests(async opts => { seen.push(opts); return answer(opts); });
+ return seen;
+}
+
+describe('tagSlots', () => {
+ test('makes no call when no fact is an exactly named live person of a slot kind', async () => {
+ const seen = stub(() => reply('{"slots":[]}'));
+ const rows = [
+ fact('Alice Example moved to Lisbon.', 'fact', ALICE),
+ fact('Alice Example wants to live in Lisbon.', 'preference', ALICE),
+ fact('Acme Example opened an office in Porto.', 'fact', 'companies/acme-example'),
+ fact('Bob Example moved to Porto.', 'fact', 'people/bob-example'),
+ fact('Someone moved to Porto.', 'fact', null),
+ ];
+ const out = await tagSlots(engine, 'default', rows, [false, true, true, true, true]);
+ expect(out).toEqual({ rows, called: false, failed: false });
+ expect(seen).toHaveLength(0);
+ });
+
+ test('sends only the candidates and keeps each valid slot once, normalized', async () => {
+ const seen = stub(() => reply(JSON.stringify({ slots: [
+ { i: 1, dimension: 'location', value: ' Lisbon ' },
+ { i: 2, dimension: 'Company', value: 'Acme Example' },
+ { i: 2, dimension: 'role', value: 'head of design' },
+ { i: 3, dimension: 'location', value: 'Porto' },
+ { i: 1.5, dimension: 'role', value: 'x' },
+ ] })));
+ const rows = [
+ fact('Alice Example moved to Lisbon.', 'fact', ALICE),
+ fact('Alice Example likes tea.', 'preference', ALICE),
+ fact('Alice Example joined Acme Example as head of design.', 'event', ALICE),
+ ];
+ const out = await tagSlots(engine, 'default', rows, [true, true, true]);
+ expect(out.called).toBe(true);
+ expect(out.failed).toBe(false);
+ expect(seen).toHaveLength(1);
+ expect(seen[0]!.system).toBe(SLOT_TAG_SYSTEM);
+ expect(seen[0]!.messages).toEqual([{ role: 'user', content:
+ '1. [Alice Example] Alice Example moved to Lisbon.\n2. [Alice Example] Alice Example joined Acme Example as head of design.' }]);
+ expect(out.rows as unknown[]).toEqual([
+ { ...rows[0]!, dimension: 'location', value: 'Lisbon' },
+ rows[1]!,
+ { ...rows[2]!, dimension: 'employer', value: 'Acme Example' },
+ ]);
+ });
+
+ test('a reply it cannot read, a truncated reply or a provider error keeps the facts without slots', async () => {
+ const rows = [fact('Alice Example moved to Lisbon.', 'fact', ALICE)];
+ const answers: Array<() => ChatResult> = [() => reply('not json'), () => reply('{"slots":"none"}'), () => ({ ...reply('{"slots":['), stopReason: 'length' }) as ChatResult,
+ () => { throw new Error('provider down'); }];
+ for (const answer of answers) {
+ stub(answer);
+ expect(await tagSlots(engine, 'default', rows, [true])).toEqual({ rows, called: true, failed: true });
+ }
+ });
+
+ test('makes no call without a chat provider', async () => {
+ configureGateway({ env: {} });
+ const rows = [fact('Alice Example moved to Lisbon.', 'fact', ALICE)];
+ expect(await tagSlots(engine, 'default', rows, [true])).toEqual({ rows, called: false, failed: false });
+ });
+
+ test('an exhausted budget stops the run', async () => {
+ stub(() => { throw new BudgetExhausted('cap', { reason: 'cost', spent: 1, cap: 1 }); });
+ await expect(tagSlots(engine, 'default', [fact('Alice Example moved to Lisbon.', 'fact', ALICE)], [true])).rejects.toBeInstanceOf(BudgetExhausted);
+ });
+});
+
+describe('through extract-conversation-facts', () => {
+ const body = (line: string) => [
+ `**user** (2026-03-10 9:00 AM): ${line}`,
+ '**assistant** (2026-03-10 9:01 AM): Noted.',
+ '**user** (2026-03-10 9:02 AM): I want a quieter desk lamp for the study.',
+ ].join('\n');
+ const main = (personFact: string) => JSON.stringify({ facts: [
+ { fact: personFact, kind: 'event', entity: ALICE, confidence: 1, notability: 'high' },
+ { fact: 'Alice moved to Lisbon.', kind: 'fact', entity: 'alice', confidence: 1, notability: 'high' },
+ { fact: 'Alice Example works from a studio in Lisbon.', kind: 'fact', entity: 'alice-example', confidence: 1, notability: 'high' },
+ { fact: 'User wants a quieter desk lamp for the study.', kind: 'preference', entity: null, confidence: 1, notability: 'high' },
+ ] });
+
+ async function run(slug: string, personFact: string, tag: () => ChatResult) {
+ await engine.putPage(slug, { type: 'conversation' as never, title: 'Conversation 2026-03-10', compiled_truth: body(personFact),
+ timeline: '', frontmatter: { date: '2026-03-10' } });
+ const seen = stub(opts => opts.system === SLOT_TAG_SYSTEM ? tag() : reply(main(personFact)));
+ const spy = spyOn(process.stderr, 'write').mockImplementation(() => true);
+ let result;
+ try { result = await runExtractConversationFactsCore(engine, { sourceId: 'default', slugs: [slug], sleepMs: 0, overrideDisabled: true }); }
+ finally { spy.mockRestore(); }
+ const rows = await engine.executeRaw<{ fact: string; entity_slug: string | null; dimension: string | null; value: string | null }>(
+ 'SELECT fact, entity_slug, dimension, value FROM facts WHERE source_markdown_slug = $1 ORDER BY id', [slug]);
+ return { seen, result, rows };
+ }
+
+ test('the main call stays slot-free; the tagging call sees the person facts named by slug or in full, never a prefix guess; the slot is stored', async () => {
+ const { seen, rows, result } = await run('conversations/2026-03-10/slot-tag-ok', 'Alice Example joined Acme Example as head of design.', () => reply('{"slots":[{"i":1,"dimension":"role","value":"head of design"}]}'));
+ const main = seen.filter(o => o.system !== SLOT_TAG_SYSTEM);
+ const tags = seen.filter(o => o.system === SLOT_TAG_SYSTEM);
+ expect(main.length).toBeGreaterThan(0);
+ for (const o of main) {
+ expect(o.system as string).not.toContain('slot');
+ expect(JSON.stringify(o.responseSchema ?? null)).not.toContain('slot');
+ }
+ expect(tags).toHaveLength(1);
+ expect(tags[0]!.messages).toEqual([{ role: 'user', content:
+ '1. [Alice Example] Alice Example joined Acme Example as head of design.\n2. [Alice Example] Alice Example works from a studio in Lisbon.' }]);
+ expect(rows.filter(r => r.fact.endsWith('Lisbon.')).map(r => [r.fact, r.entity_slug, r.dimension])).toEqual([
+ ['Alice moved to Lisbon.', ALICE, null], ['Alice Example works from a studio in Lisbon.', ALICE, null]]);
+ expect(rows.filter(r => r.dimension)).toEqual([{ fact: 'Alice Example joined Acme Example as head of design.', entity_slug: ALICE, dimension: 'role', value: 'head of design' }]);
+ expect(result.slot_tagging_failed).toBeUndefined();
+ });
+
+ test('a failed tagging call keeps the facts, stores no slot and is counted', async () => {
+ const { rows, result } = await run('conversations/2026-03-10/slot-tag-fail', 'Alice Example was promoted to design director.', () => reply('not json'));
+ expect(rows.map(r => r.fact)).toContain('Alice Example was promoted to design director.');
+ expect(rows.every(r => r.dimension === null)).toBe(true);
+ expect(result.slot_tagging_failed).toBe(1);
+ });
+});
+
+test('the --dry-run estimate adds one tagging call per segment at its largest', async () => {
+ const e = await conversationRunEstimate(engine, 3);
+ const perSegment = Math.ceil((buildExtractorSystem(true, await getExtractorVariant(engine)).length + SEGMENT_TEXT_CHAR_LIMIT) / CHAT_INPUT_CHARS_PER_TOKEN);
+ expect(e.input_tokens).toBe(3 * (perSegment + Math.ceil(SLOT_TAG_INPUT_CHARS / CHAT_INPUT_CHARS_PER_TOKEN)));
+ expect(e.output_tokens).toBe(3 * (OUTPUT_TOKENS_PER_SEGMENT + SLOT_TAG_MAX_TOKENS));
+});
diff --git a/test/fixtures/git-credential-stub/server.ts b/test/fixtures/git-credential-stub/server.ts
new file mode 100644
index 0000000000..446785365b
--- /dev/null
+++ b/test/fixtures/git-credential-stub/server.ts
@@ -0,0 +1,50 @@
+/**
+ * GST-2961 test fixture: a local Git smart-HTTP server whose push answers are chosen by the first path segment.
+ * Reads (upload-pack) go to git http-backend without auth, except under /notfound/, where every request needs a
+ * credential and then answers 404 "Repository not found", like a host to an account that cannot see the repository.
+ * /notfound/<repo> push: 401 until a credential is sent, then 404 "Repository not found."
+ * /forbidden/<repo> push: 401 until a credential is sent, then 403 "Permission to ... denied"
+ * /drop/<repo> push: 502, as a dropped connection or a failing proxy
+ * /ok/<repo> push: git http-backend (the push lands)
+ * GET /__count/<mode> returns how many receive-pack requests that mode got. Prints its port on stdout.
+ * Usage: bun server.ts <project-root>
+ */
+const project = process.argv[2] ?? '';
+const counts: Record<string, number> = {};
+
+function backend(req: Request, path: string, body: Uint8Array): Response {
+ const url = new URL(req.url);
+ const run = Bun.spawnSync(['git', 'http-backend'], { stdin: body, env: { ...process.env, GIT_PROJECT_ROOT: project, GIT_HTTP_EXPORT_ALL: '1',
+ PATH_INFO: path, QUERY_STRING: url.search.slice(1), REQUEST_METHOD: req.method, CONTENT_TYPE: req.headers.get('content-type') ?? '',
+ CONTENT_LENGTH: String(body.length), REMOTE_USER: 'stub' } });
+ const out = Buffer.from(run.stdout);
+ const split = out.indexOf('\r\n\r\n');
+ const headers = new Headers();
+ let status = 200;
+ for (const line of out.subarray(0, split).toString().split('\r\n')) {
+ const i = line.indexOf(':');
+ if (i === -1) continue;
+ const key = line.slice(0, i), value = line.slice(i + 1).trim();
+ if (key.toLowerCase() === 'status') status = parseInt(value, 10); else headers.set(key, value);
+ }
+ return new Response(out.subarray(split + 4), { status, headers });
+}
+
+const server = Bun.serve({ port: 0, hostname: '127.0.0.1', async fetch(req) {
+ const url = new URL(req.url);
+ const [, mode = '', ...rest] = url.pathname.split('/');
+ if (mode === '__count') return new Response(String(counts[rest[0] ?? ''] ?? 0));
+ const path = '/' + rest.join('/');
+ const receive = path.endsWith('/git-receive-pack') || url.searchParams.get('service') === 'git-receive-pack';
+ if (receive) counts[mode] = (counts[mode] ?? 0) + 1;
+ const body = new Uint8Array(await req.arrayBuffer());
+ if (mode === 'notfound' || (receive && mode === 'forbidden')) {
+ if (!req.headers.get('authorization')) return new Response('', { status: 401, headers: { 'WWW-Authenticate': 'Basic realm="stub"' } });
+ return mode === 'notfound'
+ ? new Response('Repository not found.\n', { status: 404, headers: { 'content-type': 'text/plain' } })
+ : new Response('Permission to acme-example/brain.git denied to user-b.\n', { status: 403, headers: { 'content-type': 'text/plain' } });
+ }
+ if (receive && mode === 'drop') return new Response(null, { status: 502 });
+ return backend(req, path, body);
+} });
+console.log(server.port);
diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-default.json b/test/fixtures/goldens/catalog/pglite-engine-init-default.json
index 8b1d9e0f1c..10aee69d96 100644
--- a/test/fixtures/goldens/catalog/pglite-engine-init-default.json
+++ b/test/fixtures/goldens/catalog/pglite-engine-init-default.json
@@ -657,6 +657,8 @@
"gbrain_guard_skill_publication()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e854c0d058e75a65c3a90127c5c417380975100e83fc34288f6085e786df10a9",
"gbrain_lease_shared_skill_delivery()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=5e493c1ac8dce8cb025a736629e563437c4b214744137c302c532c20bf7e7acf",
"gbrain_mark_derivation_scope_entry()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=592e9e3bcab2cf339197544185dc0ae3664698acecaf77cc6a1588c4134d7a93",
+ "gbrain_owner_only_lineage()": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ab91d9d7e1c492ac608e00b812a621d950f5c693385d5370450fa67f2af02cea",
+ "gbrain_owner_only_lineage(p_table text, p_id bigint)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=01a7781cebe2d4b6605d0f15937b3c290a2d706469f375b77200036a8bbe5535",
"gbrain_preserve_fact_withdrawal()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=672d0b6ff2688229b69291156d7ab73216750e2d9e3a0b1c76e493d0072b2d4a",
"gbrain_queue_page_projection()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=dc7a279205df83f00b9147adea8e609a410d0484d04648ea3fdb4344a5caf259",
"gbrain_refuse_purged_fact()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a0a55426ae1c7a540b121c0d1a588f7dbcdb8afe60b5e68ee007aad703e8504d",
diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json b/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json
index 811d977f73..3741477cf7 100644
--- a/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json
+++ b/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json
@@ -657,6 +657,8 @@
"gbrain_guard_skill_publication()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e854c0d058e75a65c3a90127c5c417380975100e83fc34288f6085e786df10a9",
"gbrain_lease_shared_skill_delivery()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=5e493c1ac8dce8cb025a736629e563437c4b214744137c302c532c20bf7e7acf",
"gbrain_mark_derivation_scope_entry()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=592e9e3bcab2cf339197544185dc0ae3664698acecaf77cc6a1588c4134d7a93",
+ "gbrain_owner_only_lineage()": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ab91d9d7e1c492ac608e00b812a621d950f5c693385d5370450fa67f2af02cea",
+ "gbrain_owner_only_lineage(p_table text, p_id bigint)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=01a7781cebe2d4b6605d0f15937b3c290a2d706469f375b77200036a8bbe5535",
"gbrain_preserve_fact_withdrawal()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=672d0b6ff2688229b69291156d7ab73216750e2d9e3a0b1c76e493d0072b2d4a",
"gbrain_queue_page_projection()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=dc7a279205df83f00b9147adea8e609a410d0484d04648ea3fdb4344a5caf259",
"gbrain_refuse_purged_fact()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a0a55426ae1c7a540b121c0d1a588f7dbcdb8afe60b5e68ee007aad703e8504d",
diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json b/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json
index 24fb4537f0..52626e4ea2 100644
--- a/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json
+++ b/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json
@@ -657,6 +657,8 @@
"gbrain_guard_skill_publication()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e854c0d058e75a65c3a90127c5c417380975100e83fc34288f6085e786df10a9",
"gbrain_lease_shared_skill_delivery()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=5e493c1ac8dce8cb025a736629e563437c4b214744137c302c532c20bf7e7acf",
"gbrain_mark_derivation_scope_entry()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=592e9e3bcab2cf339197544185dc0ae3664698acecaf77cc6a1588c4134d7a93",
+ "gbrain_owner_only_lineage()": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ab91d9d7e1c492ac608e00b812a621d950f5c693385d5370450fa67f2af02cea",
+ "gbrain_owner_only_lineage(p_table text, p_id bigint)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=01a7781cebe2d4b6605d0f15937b3c290a2d706469f375b77200036a8bbe5535",
"gbrain_preserve_fact_withdrawal()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=672d0b6ff2688229b69291156d7ab73216750e2d9e3a0b1c76e493d0072b2d4a",
"gbrain_queue_page_projection()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=dc7a279205df83f00b9147adea8e609a410d0484d04648ea3fdb4344a5caf259",
"gbrain_refuse_purged_fact()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a0a55426ae1c7a540b121c0d1a588f7dbcdb8afe60b5e68ee007aad703e8504d",
diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-default.json b/test/fixtures/goldens/catalog/postgres-engine-init-default.json
index 285d700078..50096ce2dc 100644
--- a/test/fixtures/goldens/catalog/postgres-engine-init-default.json
+++ b/test/fixtures/goldens/catalog/postgres-engine-init-default.json
@@ -660,6 +660,8 @@
"gbrain_guard_skill_publication()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e854c0d058e75a65c3a90127c5c417380975100e83fc34288f6085e786df10a9",
"gbrain_lease_shared_skill_delivery()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=5e493c1ac8dce8cb025a736629e563437c4b214744137c302c532c20bf7e7acf",
"gbrain_mark_derivation_scope_entry()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=592e9e3bcab2cf339197544185dc0ae3664698acecaf77cc6a1588c4134d7a93",
+ "gbrain_owner_only_lineage()": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ab91d9d7e1c492ac608e00b812a621d950f5c693385d5370450fa67f2af02cea",
+ "gbrain_owner_only_lineage(p_table text, p_id bigint)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=01a7781cebe2d4b6605d0f15937b3c290a2d706469f375b77200036a8bbe5535",
"gbrain_preserve_fact_withdrawal()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=672d0b6ff2688229b69291156d7ab73216750e2d9e3a0b1c76e493d0072b2d4a",
"gbrain_queue_page_projection()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=dc7a279205df83f00b9147adea8e609a410d0484d04648ea3fdb4344a5caf259",
"gbrain_refuse_purged_fact()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a0a55426ae1c7a540b121c0d1a588f7dbcdb8afe60b5e68ee007aad703e8504d",
diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json b/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json
index ef6ad27408..aa3a447e2e 100644
--- a/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json
+++ b/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json
@@ -660,6 +660,8 @@
"gbrain_guard_skill_publication()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e854c0d058e75a65c3a90127c5c417380975100e83fc34288f6085e786df10a9",
"gbrain_lease_shared_skill_delivery()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=5e493c1ac8dce8cb025a736629e563437c4b214744137c302c532c20bf7e7acf",
"gbrain_mark_derivation_scope_entry()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=592e9e3bcab2cf339197544185dc0ae3664698acecaf77cc6a1588c4134d7a93",
+ "gbrain_owner_only_lineage()": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ab91d9d7e1c492ac608e00b812a621d950f5c693385d5370450fa67f2af02cea",
+ "gbrain_owner_only_lineage(p_table text, p_id bigint)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=01a7781cebe2d4b6605d0f15937b3c290a2d706469f375b77200036a8bbe5535",
"gbrain_preserve_fact_withdrawal()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=672d0b6ff2688229b69291156d7ab73216750e2d9e3a0b1c76e493d0072b2d4a",
"gbrain_queue_page_projection()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=dc7a279205df83f00b9147adea8e609a410d0484d04648ea3fdb4344a5caf259",
"gbrain_refuse_purged_fact()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a0a55426ae1c7a540b121c0d1a588f7dbcdb8afe60b5e68ee007aad703e8504d",
diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json b/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json
index 291792fe16..80626d6620 100644
--- a/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json
+++ b/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json
@@ -660,6 +660,8 @@
"gbrain_guard_skill_publication()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e854c0d058e75a65c3a90127c5c417380975100e83fc34288f6085e786df10a9",
"gbrain_lease_shared_skill_delivery()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=5e493c1ac8dce8cb025a736629e563437c4b214744137c302c532c20bf7e7acf",
"gbrain_mark_derivation_scope_entry()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=592e9e3bcab2cf339197544185dc0ae3664698acecaf77cc6a1588c4134d7a93",
+ "gbrain_owner_only_lineage()": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ab91d9d7e1c492ac608e00b812a621d950f5c693385d5370450fa67f2af02cea",
+ "gbrain_owner_only_lineage(p_table text, p_id bigint)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=01a7781cebe2d4b6605d0f15937b3c290a2d706469f375b77200036a8bbe5535",
"gbrain_preserve_fact_withdrawal()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=672d0b6ff2688229b69291156d7ab73216750e2d9e3a0b1c76e493d0072b2d4a",
"gbrain_queue_page_projection()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=dc7a279205df83f00b9147adea8e609a410d0484d04648ea3fdb4344a5caf259",
"gbrain_refuse_purged_fact()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a0a55426ae1c7a540b121c0d1a588f7dbcdb8afe60b5e68ee007aad703e8504d",
diff --git a/test/fixtures/goldens/exports/types.json b/test/fixtures/goldens/exports/types.json
index 4218c46567..b1848b7c05 100644
--- a/test/fixtures/goldens/exports/types.json
+++ b/test/fixtures/goldens/exports/types.json
@@ -6885,7 +6885,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\" | \"page_body_rows_unreadable\" | \"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_identity_unavailable\" | \"access_member_disabled\" | \"archive_audience_unproven\" | \"archive_gateway_unreachable\" | \"archive_gateway_auth\" | \"archive_gateway_failed\" | \"archive_owner_unset\" | \"archive_redaction_failed\" | \"archive_run_busy\" | \"autopilot_no_repo\" | \"autopilot_pglite_daemon\" | \"cycle_already_running\" | \"engine_degraded\" | \"rust_engine_addon_missing\" | \"rust_engine_addon_mismatch\" | \"maintenance_disabled\" | \"maintenance_owned_by_serve\" | \"schedule_unsupported\" | \"schedule_install_failed\" | \"maintenance_owned_by_autopilot\" | \"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_history_unreadable\" | \"access_policy_store_mismatch\" | \"access_rule_invalid\" | \"requester_scope_required\" | \"requester_scope_unknown\" | \"credential_scope_required\" | \"access_serves_roster_empty\" | \"access_serves_key_dir_in_git\" | \"repair_propose_dir_in_git\" | \"access_member_id_retired\" | \"access_labelled_only_owner\" | \"access_labelled_only_unnamed\" | \"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\" | \"append_links_fence\" | \"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_behind\" | \"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_unmerged\" | \"commit_paths_invalid\" | \"commit_paths_skipped\" | \"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_filter_owned\" | \"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_alert_act\" | \"doctor_alert_unknown\" | \"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\" | \"enforced_member_refused\" | \"engine_embedding_mismatch\" | \"embedded_engine_required\" | \"engine_closed\" | \"engine_host_missing\" | \"engine_scope_missing\" | \"engine_scope_required\" | \"engine_settings_invalid\" | \"engine_capability_missing\" | \"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\" | \"foreign_table\" | \"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\" | \"moved_pages_mass_fold_refused\" | \"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_command_stopped\" | \"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\" | \"link_dates_unattributed\" | \"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\" | \"migration_host_work_owed\" | \"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_projection_stale\" | \"label_edit_refused\" | \"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\" | \"publish_secret_found\" | \"publish_scan_unreadable\" | \"push_unconfirmed\" | \"schema_lock_blocked\" | \"postgres_tls_required\" | \"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\" | \"proposal_closed\" | \"proposal_expired\" | \"proposals_pending_limit\" | \"provider_response_unparseable\" | \"publication_pending\" | \"pull_blocked_local_changes\" | \"purge_blocked_pending_recovery\" | \"purge_lookup_timeout\" | \"purge_mirror_unwritable\" | \"purge_replay_incomplete\" | \"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\" | \"openclaw_not_found\" | \"setup_harness_unsupported\" | \"setup_hosted_connection\" | \"setup_owner_conflict\" | \"setup_serves_several\" | \"setup_history_choice_required\" | \"setup_serves_unreadable\" | \"hook_session_cwd\" | \"turn_hook_not_loaded\" | \"shared_skills_unavailable\" | \"shared_skills_unmanifested\" | \"shared_skills_unsupported\" | \"skill_asset_not_found\" | \"skill_candidate_invalid\" | \"skill_not_found\" | \"skill_catalog_mismatch\" | \"skill_catalog_too_large\" | \"skill_catalog_unknown\" | \"skill_index_incompatible\" | \"skill_index_locked\" | \"skill_index_missing\" | \"skill_index_removed\" | \"skill_resolve_invalid_input\" | \"skill_resolve_no_input\" | \"skill_resolve_timeout\" | \"skill_resolver_config_invalid\" | \"skill_resolver_config_unreadable\" | \"skill_resolver_setup_incomplete\" | \"skill_resolver_plugin_not_installed\" | \"skill_resolver_host_not_local\" | \"skill_resolver_selftest_failed\" | \"skill_resolver_pin_unknown\" | \"skill_resolver_library_missing\" | \"skill_resolver_library_mismatch\" | \"skill_resolver_library_skew\" | \"skill_resolver_worker_crash\" | \"skill_resolver_worker_stuck\" | \"skill_resolver_worker_unavailable\" | \"skill_resolver_state_missing\" | \"skill_resolver_host_load_cut\" | \"skill_resolver_internal\" | \"skill_source_invalid\" | \"skill_source_unreadable\" | \"skill_retention_capacity\" | \"skill_unavailable\" | \"skillpack_backup_corrupt\" | \"skillpack_journal_not_found\" | \"skillpack_restore_conflict\" | \"skillpack_state_locked\" | \"skillpack_update_incomplete\" | \"skillpack_workspace_locked\" | \"slug_page_mismatch\" | \"slug_root_mode_mismatch\" | \"source_binding_required\" | \"source_id_taken\" | \"source_mismatch\" | \"source_not_ready\" | \"source_profile_no_backfill\" | \"source_pages_remain\" | \"source_referenced\" | \"source_retire_superseded\" | \"source_root_conflict\" | \"source_root_unreadable\" | \"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\" | \"tag_too_long\" | \"target_escape\" | \"timeline_comment_markup\" | \"source_writer_restricted\" | \"guest_page_immutable\" | \"guest_page_promoted\" | \"guest_attribution_missing\" | \"guest_frontmatter_refused\" | \"guest_readers_invalid\" | \"guest_promotion_owner_only\" | \"guest_mark_immutable\" | \"guest_source_database_only\" | \"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\" | \"untrack_not_db_only\" | \"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\" | \"page_body_rows_unreadable\" | \"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\" | \"apple_full_disk_access_pending\" | \"apple_helper_not_running\" | \"apple_helper_unauthorized\" | \"apple_schema_mismatch\" | \"access_command_failed\" | \"access_identity_unavailable\" | \"access_member_disabled\" | \"archive_audience_unproven\" | \"archive_gateway_unreachable\" | \"archive_gateway_auth\" | \"archive_gateway_failed\" | \"archive_owner_unset\" | \"archive_redaction_failed\" | \"archive_run_busy\" | \"autopilot_no_repo\" | \"autopilot_pglite_daemon\" | \"cycle_already_running\" | \"engine_degraded\" | \"rust_engine_addon_missing\" | \"rust_engine_addon_mismatch\" | \"maintenance_disabled\" | \"maintenance_owned_by_serve\" | \"schedule_unsupported\" | \"schedule_install_failed\" | \"maintenance_owned_by_autopilot\" | \"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_history_unreadable\" | \"access_policy_store_mismatch\" | \"access_rule_invalid\" | \"requester_scope_required\" | \"requester_scope_unknown\" | \"credential_scope_required\" | \"access_serves_roster_empty\" | \"access_serves_key_dir_in_git\" | \"repair_propose_dir_in_git\" | \"access_member_id_retired\" | \"access_labelled_only_owner\" | \"access_labelled_only_unnamed\" | \"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\" | \"append_links_fence\" | \"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\" | \"class_apply_busy\" | \"class_capacity_exceeded\" | \"class_manifest_stale\" | \"client_behind\" | \"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_unmerged\" | \"commit_paths_invalid\" | \"commit_paths_skipped\" | \"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_filter_owned\" | \"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_alert_act\" | \"doctor_alert_unknown\" | \"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\" | \"enforced_member_refused\" | \"engine_embedding_mismatch\" | \"embedded_engine_required\" | \"engine_closed\" | \"engine_host_missing\" | \"engine_scope_missing\" | \"engine_scope_required\" | \"engine_settings_invalid\" | \"engine_capability_missing\" | \"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\" | \"foreign_table\" | \"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\" | \"moved_pages_mass_fold_refused\" | \"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_command_stopped\" | \"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\" | \"link_dates_unattributed\" | \"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\" | \"migration_host_work_owed\" | \"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_projection_stale\" | \"label_edit_refused\" | \"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\" | \"publish_secret_found\" | \"publish_scan_unreadable\" | \"push_credential_refused\" | \"push_unconfirmed\" | \"schema_lock_blocked\" | \"postgres_tls_required\" | \"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\" | \"proposal_closed\" | \"proposal_expired\" | \"proposals_pending_limit\" | \"provider_response_unparseable\" | \"publication_pending\" | \"pull_blocked_local_changes\" | \"purge_blocked_pending_recovery\" | \"purge_lookup_timeout\" | \"purge_mirror_unwritable\" | \"purge_replay_incomplete\" | \"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\" | \"openclaw_not_found\" | \"setup_harness_unsupported\" | \"setup_hosted_connection\" | \"setup_owner_conflict\" | \"setup_serves_several\" | \"setup_history_choice_required\" | \"setup_serves_unreadable\" | \"hook_session_cwd\" | \"turn_hook_not_loaded\" | \"shared_skills_unavailable\" | \"shared_skills_unmanifested\" | \"shared_skills_unsupported\" | \"skill_asset_not_found\" | \"skill_candidate_invalid\" | \"skill_not_found\" | \"skill_catalog_mismatch\" | \"skill_catalog_too_large\" | \"skill_catalog_unknown\" | \"skill_index_incompatible\" | \"skill_index_locked\" | \"skill_index_missing\" | \"skill_index_removed\" | \"skill_resolve_invalid_input\" | \"skill_resolve_no_input\" | \"skill_resolve_timeout\" | \"skill_resolver_config_invalid\" | \"skill_resolver_config_unreadable\" | \"skill_resolver_setup_incomplete\" | \"skill_resolver_plugin_not_installed\" | \"skill_resolver_host_not_local\" | \"skill_resolver_selftest_failed\" | \"skill_resolver_pin_unknown\" | \"skill_resolver_library_missing\" | \"skill_resolver_library_mismatch\" | \"skill_resolver_library_skew\" | \"skill_resolver_worker_crash\" | \"skill_resolver_worker_stuck\" | \"skill_resolver_worker_unavailable\" | \"skill_resolver_state_missing\" | \"skill_resolver_host_load_cut\" | \"skill_resolver_internal\" | \"skill_source_invalid\" | \"skill_source_unreadable\" | \"skill_retention_capacity\" | \"skill_unavailable\" | \"skillpack_backup_corrupt\" | \"skillpack_journal_not_found\" | \"skillpack_restore_conflict\" | \"skillpack_state_locked\" | \"skillpack_update_incomplete\" | \"skillpack_workspace_locked\" | \"slug_page_mismatch\" | \"slug_root_mode_mismatch\" | \"source_binding_required\" | \"source_id_taken\" | \"source_mismatch\" | \"source_not_ready\" | \"source_profile_no_backfill\" | \"source_pages_remain\" | \"source_referenced\" | \"source_retire_superseded\" | \"source_root_conflict\" | \"source_root_unreadable\" | \"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\" | \"tag_too_long\" | \"target_escape\" | \"timeline_comment_markup\" | \"source_writer_restricted\" | \"guest_page_immutable\" | \"guest_page_promoted\" | \"guest_attribution_missing\" | \"guest_frontmatter_refused\" | \"guest_readers_invalid\" | \"guest_promotion_owner_only\" | \"guest_mark_immutable\" | \"guest_source_database_only\" | \"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\" | \"untrack_not_db_only\" | \"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\" | \"whole_class_prefer_unsupported\" | \"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/fixtures/goldens/migrations/records.json b/test/fixtures/goldens/migrations/records.json
index 69c405f937..956e64633e 100644
--- a/test/fixtures/goldens/migrations/records.json
+++ b/test/fixtures/goldens/migrations/records.json
@@ -1,6 +1,6 @@
{
"golden": {
- "count": 314,
+ "count": 315,
"gaps": [
17,
18,
@@ -105,7 +105,7 @@
"widenIdentityIndex": "86a6176bd7637d964dbc1d3cd3b1bdfa3ca0161e1ee248c37d7380a1471282e6",
"withSchemaLockTimeout": "95605bd3004955e11e936c7a4aa6889319b401098abf9db18ef3e48da2c3fc59"
},
- "latest": 319,
+ "latest": 320,
"records": [
{
"handler": {
@@ -5216,6 +5216,19 @@
"transaction": "absent",
"verify": "absent",
"version": 319
+ },
+ {
+ "handler": "absent",
+ "idempotent": true,
+ "name": "owner_only_lineage",
+ "sql": {
+ "length": 2394,
+ "sha256": "3bce883ac217867e891d839a7254747b8aa1d2c1a42ef9f7a123dbc14fd39422"
+ },
+ "sqlFor": "absent",
+ "transaction": "absent",
+ "verify": "absent",
+ "version": 320
}
],
"versions": [
@@ -5532,7 +5545,8 @@
316,
317,
318,
- 319
+ 319,
+ 320
]
},
"normalizer": "migrations-record-v1"
diff --git a/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json b/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json
index cd3220f8c8..c020f34014 100644
--- a/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json
+++ b/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json
@@ -657,6 +657,8 @@
"gbrain_guard_skill_publication()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e854c0d058e75a65c3a90127c5c417380975100e83fc34288f6085e786df10a9",
"gbrain_lease_shared_skill_delivery()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=5e493c1ac8dce8cb025a736629e563437c4b214744137c302c532c20bf7e7acf",
"gbrain_mark_derivation_scope_entry()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=592e9e3bcab2cf339197544185dc0ae3664698acecaf77cc6a1588c4134d7a93",
+ "gbrain_owner_only_lineage()": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ab91d9d7e1c492ac608e00b812a621d950f5c693385d5370450fa67f2af02cea",
+ "gbrain_owner_only_lineage(p_table text, p_id bigint)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=01a7781cebe2d4b6605d0f15937b3c290a2d706469f375b77200036a8bbe5535",
"gbrain_preserve_fact_withdrawal()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=672d0b6ff2688229b69291156d7ab73216750e2d9e3a0b1c76e493d0072b2d4a",
"gbrain_queue_page_projection()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=dc7a279205df83f00b9147adea8e609a410d0484d04648ea3fdb4344a5caf259",
"gbrain_refuse_purged_fact()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a0a55426ae1c7a540b121c0d1a588f7dbcdb8afe60b5e68ee007aad703e8504d",
diff --git a/test/fixtures/goldens/sql-text/chunks.json b/test/fixtures/goldens/sql-text/chunks.json
index 250e8a1151..14944dba1d 100644
--- a/test/fixtures/goldens/sql-text/chunks.json
+++ b/test/fixtures/goldens/sql-text/chunks.json
@@ -138,8 +138,8 @@
"string",
"array<string>"
],
- "sql": "SELECT COALESCE(sum(t.n), 0) AS total, max(t.max_index) AS max_index, bool_or(t.segmented) AS segmented, max(t.n) AS max_page_chunks FROM ( SELECT count(*) AS n, max(cc.chunk_index) AS max_index, bool_or(cc.body_generation IS NOT NULL) AS segmented FROM content_chunks cc JOIN pages p ON p.id = cc.page_id WHERE p.slug = $1 AND p.source_id = ANY($2::text[]) AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (((p.text_projection_revision = p.knowledge_revision) IS TRUE OR (p.text_projection_revision = '00000000-0000-0000-0000-000000000153'::uuid) IS TRUE) AND (cc.body_generation IS NULL OR cc.body_generation <= p.body_generation)) AND p.chunker_version >= 4 GROUP BY cc.page_id ) t",
- "textSha256": "27a4eabe9b6bdd41a15c20ab492883e2681a1e20bbcd70c268d910f5d3f72e92"
+ "sql": "SELECT COALESCE(sum(t.n), 0) AS total, max(t.max_index) AS max_index, bool_or(t.segmented) AS segmented, max(t.n) AS max_page_chunks FROM ( SELECT count(*) AS n, max(cc.chunk_index) AS max_index, bool_or(cc.body_generation IS NOT NULL) AS segmented FROM content_chunks cc JOIN pages p ON p.id = cc.page_id WHERE p.slug = $1 AND p.source_id = ANY($2::text[]) AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (((p.text_projection_revision = p.knowledge_revision) IS TRUE OR (p.text_projection_revision = '00000000-0000-0000-0000-000000000153'::uuid) IS TRUE) AND (cc.body_generation IS NULL OR cc.body_generation <= p.body_generation)) AND p.chunker_version >= 4 GROUP BY cc.page_id ) t",
+ "textSha256": "3997624ae577e418977e55702ea9c4ca19acfaad8bcf7405f122b97e48129c70"
},
{
"lane": "pool",
@@ -149,8 +149,8 @@
"number",
"number"
],
- "sql": "SELECT cc.id, cc.page_id, cc.chunk_index, cc.chunk_text, cc.chunk_source, cc.model, cc.token_count, cc.embedded_at, cc.language, cc.symbol_name, cc.symbol_type, cc.start_line, cc.end_line, cc.parent_symbol_path, cc.doc_comment, cc.symbol_name_qualified, cc.modality, cc.projected_byte_start, cc.projected_byte_end, (cc.\"embedding\" IS NULL) AS embedding_is_null FROM content_chunks cc JOIN pages p ON p.id = cc.page_id LEFT JOIN page_body_manifest m ON cc.occurrence_id IS NOT NULL AND m.page_id = cc.page_id AND m.occurrence_id = cc.occurrence_id AND m.staging_id IS NULL AND m.gen_from <= p.body_generation AND (m.gen_to IS NULL OR m.gen_to > p.body_generation) WHERE p.slug = $1 AND p.source_id = ANY($2::text[]) AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (((p.text_projection_revision = p.knowledge_revision) IS TRUE OR (p.text_projection_revision = '00000000-0000-0000-0000-000000000153'::uuid) IS TRUE) AND (cc.body_generation IS NULL OR cc.body_generation <= p.body_generation)) AND p.chunker_version >= 4 AND cc.chunk_index >= $3 AND cc.chunk_index < $4 ORDER BY m.byte_start, cc.local_ordinal, cc.chunk_index",
- "textSha256": "59ef83c64302bf1a508c1e2563b7a2b615787dc7d5b9469594df47c45523d459"
+ "sql": "SELECT cc.id, cc.page_id, cc.chunk_index, cc.chunk_text, cc.chunk_source, cc.model, cc.token_count, cc.embedded_at, cc.language, cc.symbol_name, cc.symbol_type, cc.start_line, cc.end_line, cc.parent_symbol_path, cc.doc_comment, cc.symbol_name_qualified, cc.modality, cc.projected_byte_start, cc.projected_byte_end, (cc.\"embedding\" IS NULL) AS embedding_is_null FROM content_chunks cc JOIN pages p ON p.id = cc.page_id LEFT JOIN page_body_manifest m ON cc.occurrence_id IS NOT NULL AND m.page_id = cc.page_id AND m.occurrence_id = cc.occurrence_id AND m.staging_id IS NULL AND m.gen_from <= p.body_generation AND (m.gen_to IS NULL OR m.gen_to > p.body_generation) WHERE p.slug = $1 AND p.source_id = ANY($2::text[]) AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (((p.text_projection_revision = p.knowledge_revision) IS TRUE OR (p.text_projection_revision = '00000000-0000-0000-0000-000000000153'::uuid) IS TRUE) AND (cc.body_generation IS NULL OR cc.body_generation <= p.body_generation)) AND p.chunker_version >= 4 AND cc.chunk_index >= $3 AND cc.chunk_index < $4 ORDER BY m.byte_start, cc.local_ordinal, cc.chunk_index",
+ "textSha256": "100fc8285937233e7cc1e692c5a2344b7c5e0089c1e38e1ad26b62e83cbac5cd"
}
]
},
@@ -198,8 +198,8 @@
"array<string>",
"number"
],
- "sql": "WITH req AS ( SELECT * FROM unnest($1::int[], $2::int[], $3::int[], $4::int[]) AS r(page_id, lo, hi, prio) ), auth AS ( SELECT p.id, p.slug, p.source_id, p.type, p.knowledge_revision::text AS revision, p.compiled_truth, p.timeline, p.body_storage, p.body_generation, p.body_storage = 'segmented' AS segmented, (COALESCE(p.chunker_version, 0) >= $5) AS sealed, (SELECT MIN(req.prio) FROM req WHERE req.page_id = p.id) AS prio FROM pages p JOIN sources s ON s.id = p.source_id WHERE p.id = ANY($6::int[]) AND p.source_id = ANY($7::text[]) AND p.deleted_at IS NULL AND ((p.text_projection_revision = p.knowledge_revision) IS TRUE OR (p.text_projection_revision = '00000000-0000-0000-0000-000000000153'::uuid) IS TRUE) AND NOT s.archived AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.chunker_version >= 4 ), chunk_rows AS ( SELECT cc.page_id, cc.id AS chunk_id, cc.chunk_index, cc.chunk_text, cc.chunk_source, cc.projected_byte_start, cc.projected_byte_end, cc.occurrence_id, a.prio FROM auth a JOIN content_chunks cc ON cc.page_id = a.id WHERE a.sealed AND ((cc.body_generation IS NULL AND a.body_storage <> 'segmented') OR (cc.body_generation <= a.body_generation AND EXISTS (SELECT 1 FROM page_body_manifest lm WHERE lm.page_id = cc.page_id AND lm.occurrence_id = cc.occurrence_id AND lm.staging_id IS NULL AND lm.gen_from <= a.body_generation AND (lm.gen_to IS NULL OR lm.gen_to > a.body_generation)))) AND cc.chunk_source = ANY($8::text[]) AND COALESCE(cc.modality, 'text') = 'text' AND EXISTS (SELECT 1 FROM req r WHERE r.page_id = cc.page_id AND cc.chunk_index BETWEEN r.lo AND r.hi) ORDER BY a.prio, cc.page_id, cc.chunk_index LIMIT $9 ) SELECT 'page' AS kind, a.id AS page_id, a.slug, a.source_id, a.type, a.revision, a.sealed, a.segmented, a.prio, (SELECT MAX(c2.chunk_index) FROM content_chunks c2 WHERE c2.page_id = a.id AND ((c2.body_generation IS NULL AND a.body_storage <> 'segmented') OR (c2.body_generation <= a.body_generation AND EXISTS (SELECT 1 FROM page_body_manifest lm WHERE lm.page_id = c2.page_id AND lm.occurrence_id = c2.occurrence_id AND lm.staging_id IS NULL AND lm.gen_from <= a.body_generation AND (lm.gen_to IS NULL OR lm.gen_to > a.body_generation))))) AS max_chunk_index, a.compiled_truth, a.timeline, NULL::int AS chunk_id, NULL::int AS chunk_index, NULL::text AS chunk_text, NULL::text AS chunk_source, NULL::bigint AS projected_byte_start, NULL::bigint AS projected_byte_end, NULL::bigint AS occurrence_id FROM auth a UNION ALL SELECT 'chunk' AS kind, c.page_id, NULL, NULL, NULL, NULL, NULL, NULL, c.prio, NULL, NULL, NULL, c.chunk_id, c.chunk_index, c.chunk_text, c.chunk_source, c.projected_byte_start, c.projected_byte_end, c.occurrence_id FROM chunk_rows c",
- "textSha256": "5bcd45cd04bd8e67e1fa997f75418198809174197fa1767ceb6f8f7923e41eec"
+ "sql": "WITH req AS ( SELECT * FROM unnest($1::int[], $2::int[], $3::int[], $4::int[]) AS r(page_id, lo, hi, prio) ), auth AS ( SELECT p.id, p.slug, p.source_id, p.type, p.knowledge_revision::text AS revision, p.compiled_truth, p.timeline, p.body_storage, p.body_generation, p.body_storage = 'segmented' AS segmented, (COALESCE(p.chunker_version, 0) >= $5) AS sealed, (SELECT MIN(req.prio) FROM req WHERE req.page_id = p.id) AS prio FROM pages p JOIN sources s ON s.id = p.source_id WHERE p.id = ANY($6::int[]) AND p.source_id = ANY($7::text[]) AND p.deleted_at IS NULL AND ((p.text_projection_revision = p.knowledge_revision) IS TRUE OR (p.text_projection_revision = '00000000-0000-0000-0000-000000000153'::uuid) IS TRUE) AND NOT s.archived AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.chunker_version >= 4 ), chunk_rows AS ( SELECT cc.page_id, cc.id AS chunk_id, cc.chunk_index, cc.chunk_text, cc.chunk_source, cc.projected_byte_start, cc.projected_byte_end, cc.occurrence_id, a.prio FROM auth a JOIN content_chunks cc ON cc.page_id = a.id WHERE a.sealed AND ((cc.body_generation IS NULL AND a.body_storage <> 'segmented') OR (cc.body_generation <= a.body_generation AND EXISTS (SELECT 1 FROM page_body_manifest lm WHERE lm.page_id = cc.page_id AND lm.occurrence_id = cc.occurrence_id AND lm.staging_id IS NULL AND lm.gen_from <= a.body_generation AND (lm.gen_to IS NULL OR lm.gen_to > a.body_generation)))) AND cc.chunk_source = ANY($8::text[]) AND COALESCE(cc.modality, 'text') = 'text' AND EXISTS (SELECT 1 FROM req r WHERE r.page_id = cc.page_id AND cc.chunk_index BETWEEN r.lo AND r.hi) ORDER BY a.prio, cc.page_id, cc.chunk_index LIMIT $9 ) SELECT 'page' AS kind, a.id AS page_id, a.slug, a.source_id, a.type, a.revision, a.sealed, a.segmented, a.prio, (SELECT MAX(c2.chunk_index) FROM content_chunks c2 WHERE c2.page_id = a.id AND ((c2.body_generation IS NULL AND a.body_storage <> 'segmented') OR (c2.body_generation <= a.body_generation AND EXISTS (SELECT 1 FROM page_body_manifest lm WHERE lm.page_id = c2.page_id AND lm.occurrence_id = c2.occurrence_id AND lm.staging_id IS NULL AND lm.gen_from <= a.body_generation AND (lm.gen_to IS NULL OR lm.gen_to > a.body_generation))))) AS max_chunk_index, a.compiled_truth, a.timeline, NULL::int AS chunk_id, NULL::int AS chunk_index, NULL::text AS chunk_text, NULL::text AS chunk_source, NULL::bigint AS projected_byte_start, NULL::bigint AS projected_byte_end, NULL::bigint AS occurrence_id FROM auth a UNION ALL SELECT 'chunk' AS kind, c.page_id, NULL, NULL, NULL, NULL, NULL, NULL, c.prio, NULL, NULL, NULL, c.chunk_id, c.chunk_index, c.chunk_text, c.chunk_source, c.projected_byte_start, c.projected_byte_end, c.occurrence_id FROM chunk_rows c",
+ "textSha256": "2e9ef45421488770f8a25419bb9dc3932341dfc1a20a97e582cb42c1e696e500"
}
]
},
@@ -246,8 +246,8 @@
"string",
"string"
],
- "sql": "SELECT cc.id, cc.page_id, cc.chunk_index, cc.chunk_text, cc.chunk_source, cc.model, cc.token_count, cc.embedded_at, cc.language, cc.symbol_name, cc.symbol_type, cc.start_line, cc.end_line, cc.parent_symbol_path, cc.doc_comment, cc.symbol_name_qualified, cc.modality, cc.projected_byte_start, cc.projected_byte_end, (cc.\"embedding\" IS NULL) AS embedding_is_null FROM content_chunks cc JOIN pages p ON p.id = cc.page_id LEFT JOIN page_body_manifest m ON cc.occurrence_id IS NOT NULL AND m.page_id = cc.page_id AND m.occurrence_id = cc.occurrence_id AND m.staging_id IS NULL AND m.gen_from <= p.body_generation AND (m.gen_to IS NULL OR m.gen_to > p.body_generation) WHERE p.slug = $1 AND p.source_id = $2 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (((p.text_projection_revision = p.knowledge_revision) IS TRUE OR (p.text_projection_revision = '00000000-0000-0000-0000-000000000153'::uuid) IS TRUE) AND (cc.body_generation IS NULL OR cc.body_generation <= p.body_generation)) AND p.chunker_version >= 4 ORDER BY m.byte_start, cc.local_ordinal, cc.chunk_index",
- "textSha256": "723e136bddc29691b07ed55be488914b52e5531271c741645a8be03d4a36169b"
+ "sql": "SELECT cc.id, cc.page_id, cc.chunk_index, cc.chunk_text, cc.chunk_source, cc.model, cc.token_count, cc.embedded_at, cc.language, cc.symbol_name, cc.symbol_type, cc.start_line, cc.end_line, cc.parent_symbol_path, cc.doc_comment, cc.symbol_name_qualified, cc.modality, cc.projected_byte_start, cc.projected_byte_end, (cc.\"embedding\" IS NULL) AS embedding_is_null FROM content_chunks cc JOIN pages p ON p.id = cc.page_id LEFT JOIN page_body_manifest m ON cc.occurrence_id IS NOT NULL AND m.page_id = cc.page_id AND m.occurrence_id = cc.occurrence_id AND m.staging_id IS NULL AND m.gen_from <= p.body_generation AND (m.gen_to IS NULL OR m.gen_to > p.body_generation) WHERE p.slug = $1 AND p.source_id = $2 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (((p.text_projection_revision = p.knowledge_revision) IS TRUE OR (p.text_projection_revision = '00000000-0000-0000-0000-000000000153'::uuid) IS TRUE) AND (cc.body_generation IS NULL OR cc.body_generation <= p.body_generation)) AND p.chunker_version >= 4 ORDER BY m.byte_start, cc.local_ordinal, cc.chunk_index",
+ "textSha256": "9ddf5a2b90fc60efe30d81c188387fe1a02d3bea3057167c6260bfc1daebc94a"
}
],
"includeEmbedding": [
diff --git a/test/fixtures/goldens/sql-text/facts.json b/test/fixtures/goldens/sql-text/facts.json
index 44a6ad081b..191d535e61 100644
--- a/test/fixtures/goldens/sql-text/facts.json
+++ b/test/fixtures/goldens/sql-text/facts.json
@@ -159,8 +159,8 @@
"number",
"array<string>"
],
- "sql": "WITH cur AS ( SELECT entity_slug, dimension, value, source_markdown_slug AS source, confidence, id AS fact_id FROM facts WHERE dimension IS NOT NULL AND expired_at IS NULL AND valid_until IS NULL AND COALESCE(source, '') NOT LIKE 'cli:extract-conversation-facts%' AND (dim_status IS NULL OR dim_status = 'active') AND confidence >= $1 AND source_id = ANY($2) AND NOT EXISTS (SELECT 1 FROM pages elig_dp WHERE elig_dp.source_id = facts.source_id AND elig_dp.slug = ANY(ARRAY[facts.source_markdown_slug, facts.entity_slug]) AND elig_dp.deleted_at IS NOT NULL) AND (NOT EXISTS (SELECT 1 FROM pages pp WHERE pp.source_id = facts.source_id AND pp.slug = facts.source_markdown_slug AND NOT (((((pp.page_readers IS NULL AND NOT (pp.frontmatter ? 'readable_by'))) AND (pp.folder_rule_ids IS NULL OR COALESCE(gbrain_access_lineage_rules(pp.source_id, pp.folder_rule_ids) <@ ARRAY[]::text[], true)) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = pp.source_id AND (starts_with(pp.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR pp.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((pp.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (pp.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(pp.id, pp.source_id, pp.type, pp.frontmatter))) AND ((COALESCE(pp.frontmatter->>'visibility', CASE WHEN (pp.type IN ('atom', 'question') OR (pp.type = 'concept' AND pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(pp.frontmatter ? 'pinned_question', false) AND NOT (pp.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(pp.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(pp.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN pp.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = pp.source_id AND derived_origin.slug = ANY(ARRAY[(pp.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=pp.source_id AND renamed.alias_slug=(pp.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=pp.source_id AND moved.old_slug=(pp.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (pp.type IN ('atom', 'question') OR (pp.type = 'concept' AND pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = pp.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN pp.type = 'event' AND pp.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = pp.source_id AND chronicle_origin.slug = pp.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(pp.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = pp.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(pp.frontmatter->'derived_from') = 'array' THEN pp.frontmatter->'derived_from' ELSE jsonb_build_array(pp.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))))) AND (NOT EXISTS (SELECT 1 FROM pages entity_pp WHERE entity_pp.source_id = facts.source_id AND entity_pp.slug IN (facts.entity_slug, CASE WHEN facts.entity_slug IS NOT NULL AND (facts.source_markdown_slug = 'memory/unattributed' OR facts.source_markdown_slug LIKE '%/memory/unattributed') THEN facts.source_markdown_slug END) AND NOT ((((entity_pp.page_readers IS NULL AND NOT (entity_pp.frontmatter ? 'readable_by'))) AND (entity_pp.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = entity_pp.source_id AND (starts_with(entity_pp.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR entity_pp.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((entity_pp.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (entity_pp.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(entity_pp.id, entity_pp.source_id, entity_pp.type, entity_pp.frontmatter))) AND ((COALESCE(entity_pp.frontmatter->>'visibility', CASE WHEN (entity_pp.type IN ('atom', 'question') OR (entity_pp.type = 'concept' AND entity_pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(entity_pp.frontmatter ? 'pinned_question', false) AND NOT (entity_pp.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(entity_pp.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(entity_pp.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN entity_pp.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = entity_pp.source_id AND derived_origin.slug = ANY(ARRAY[(entity_pp.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=entity_pp.source_id AND renamed.alias_slug=(entity_pp.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=entity_pp.source_id AND moved.old_slug=(entity_pp.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (entity_pp.type IN ('atom', 'question') OR (entity_pp.type = 'concept' AND entity_pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = entity_pp.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN entity_pp.type = 'event' AND entity_pp.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = entity_pp.source_id AND chronicle_origin.slug = entity_pp.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(entity_pp.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = entity_pp.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(entity_pp.frontmatter->'derived_from') = 'array' THEN entity_pp.frontmatter->'derived_from' ELSE jsonb_build_array(entity_pp.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)))) AND NOT (facts.entity_slug IS NOT NULL AND (facts.source_markdown_slug = 'memory/unattributed' OR facts.source_markdown_slug LIKE '%/memory/unattributed') AND (NOT COALESCE(gbrain_access_folder_rules(facts.source_id, facts.entity_slug) <@ ARRAY[]::text[], true) OR gbrain_access_pending_covers(facts.source_id, facts.entity_slug))))) ) SELECT entity_slug, dimension, json_agg(json_build_object('value', value, 'source', source, 'confidence', confidence, 'fact_id', fact_id)) AS values FROM cur GROUP BY entity_slug, dimension HAVING count(DISTINCT value) >= 2 AND count(DISTINCT source) >= 2 ORDER BY entity_slug, dimension",
- "textSha256": "461e05c68b5656b845e29d506e167a61df50fa012ec3061a3c7c257406305413"
+ "sql": "WITH cur AS ( SELECT entity_slug, dimension, value, source_markdown_slug AS source, confidence, id AS fact_id FROM facts WHERE dimension IS NOT NULL AND expired_at IS NULL AND valid_until IS NULL AND COALESCE(source, '') NOT LIKE 'cli:extract-conversation-facts%' AND (dim_status IS NULL OR dim_status = 'active') AND confidence >= $1 AND source_id = ANY($2) AND NOT EXISTS (SELECT 1 FROM pages elig_dp WHERE elig_dp.source_id = facts.source_id AND elig_dp.slug = ANY(ARRAY[facts.source_markdown_slug, facts.entity_slug]) AND elig_dp.deleted_at IS NOT NULL) AND ((NOT EXISTS (SELECT 1 FROM pages pp WHERE pp.source_id = facts.source_id AND pp.slug = facts.source_markdown_slug AND NOT (((((pp.page_readers IS NULL AND NOT (pp.frontmatter ? 'readable_by'))) AND (pp.folder_rule_ids IS NULL OR COALESCE(gbrain_access_lineage_rules(pp.source_id, pp.folder_rule_ids) <@ ARRAY[]::text[], true)) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = pp.source_id AND (starts_with(pp.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR pp.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((pp.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (pp.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(pp.id, pp.source_id, pp.type, pp.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(pp.frontmatter->>'visibility', CASE WHEN (pp.type IN ('atom', 'question') OR (pp.type = 'concept' AND pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(pp.frontmatter ? 'pinned_question', false) AND NOT (pp.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(pp.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(pp.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN pp.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = pp.source_id AND derived_origin.slug = ANY(ARRAY[(pp.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=pp.source_id AND renamed.alias_slug=(pp.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=pp.source_id AND moved.old_slug=(pp.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (pp.type IN ('atom', 'question') OR (pp.type = 'concept' AND pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = pp.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN pp.type = 'event' AND pp.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = pp.source_id AND chronicle_origin.slug = pp.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(pp.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = pp.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(pp.frontmatter->'derived_from') = 'array' THEN pp.frontmatter->'derived_from' ELSE jsonb_build_array(pp.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))))) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND (NOT EXISTS (SELECT 1 FROM pages entity_pp WHERE entity_pp.source_id = facts.source_id AND entity_pp.slug IN (facts.entity_slug, CASE WHEN facts.entity_slug IS NOT NULL AND (facts.source_markdown_slug = 'memory/unattributed' OR facts.source_markdown_slug LIKE '%/memory/unattributed') THEN facts.source_markdown_slug END) AND NOT ((((entity_pp.page_readers IS NULL AND NOT (entity_pp.frontmatter ? 'readable_by'))) AND (entity_pp.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = entity_pp.source_id AND (starts_with(entity_pp.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR entity_pp.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((entity_pp.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (entity_pp.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(entity_pp.id, entity_pp.source_id, entity_pp.type, entity_pp.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(entity_pp.frontmatter->>'visibility', CASE WHEN (entity_pp.type IN ('atom', 'question') OR (entity_pp.type = 'concept' AND entity_pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(entity_pp.frontmatter ? 'pinned_question', false) AND NOT (entity_pp.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(entity_pp.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(entity_pp.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN entity_pp.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = entity_pp.source_id AND derived_origin.slug = ANY(ARRAY[(entity_pp.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=entity_pp.source_id AND renamed.alias_slug=(entity_pp.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=entity_pp.source_id AND moved.old_slug=(entity_pp.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (entity_pp.type IN ('atom', 'question') OR (entity_pp.type = 'concept' AND entity_pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = entity_pp.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN entity_pp.type = 'event' AND entity_pp.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = entity_pp.source_id AND chronicle_origin.slug = entity_pp.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(entity_pp.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = entity_pp.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(entity_pp.frontmatter->'derived_from') = 'array' THEN entity_pp.frontmatter->'derived_from' ELSE jsonb_build_array(entity_pp.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)))) AND NOT (facts.entity_slug IS NOT NULL AND (facts.source_markdown_slug = 'memory/unattributed' OR facts.source_markdown_slug LIKE '%/memory/unattributed') AND (NOT COALESCE(gbrain_access_folder_rules(facts.source_id, facts.entity_slug) <@ ARRAY[]::text[], true) OR gbrain_access_pending_covers(facts.source_id, facts.entity_slug))))) ) SELECT entity_slug, dimension, json_agg(json_build_object('value', value, 'source', source, 'confidence', confidence, 'fact_id', fact_id)) AS values FROM cur GROUP BY entity_slug, dimension HAVING count(DISTINCT value) >= 2 AND count(DISTINCT source) >= 2 ORDER BY entity_slug, dimension",
+ "textSha256": "9b3e993ead0aeb605a16920b58f4cfbe264a2d95c181e528a3d4deb4f17597e1"
}
]
},
@@ -253,8 +253,8 @@
"number",
"boolean"
],
- "sql": "SELECT DISTINCT ON (dimension) dimension, value, confidence, source_markdown_slug AS source, valid_from, valid_until AS valid_to, COALESCE(dim_status, 'active') AS status, id AS fact_id FROM facts WHERE entity_slug = $1 AND dimension IS NOT NULL AND expired_at IS NULL AND COALESCE(source, '') NOT LIKE 'cli:extract-conversation-facts%' AND source_id = ANY($2) AND NOT EXISTS (SELECT 1 FROM pages elig_dp WHERE elig_dp.source_id = facts.source_id AND elig_dp.slug = ANY(ARRAY[facts.source_markdown_slug, facts.entity_slug]) AND elig_dp.deleted_at IS NOT NULL) AND (NOT EXISTS (SELECT 1 FROM pages pp WHERE pp.source_id = facts.source_id AND pp.slug = facts.source_markdown_slug AND NOT (((((pp.page_readers IS NULL AND NOT (pp.frontmatter ? 'readable_by'))) AND (pp.folder_rule_ids IS NULL OR COALESCE(gbrain_access_lineage_rules(pp.source_id, pp.folder_rule_ids) <@ ARRAY[]::text[], true)) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = pp.source_id AND (starts_with(pp.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR pp.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((pp.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (pp.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(pp.id, pp.source_id, pp.type, pp.frontmatter))) AND ((COALESCE(pp.frontmatter->>'visibility', CASE WHEN (pp.type IN ('atom', 'question') OR (pp.type = 'concept' AND pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(pp.frontmatter ? 'pinned_question', false) AND NOT (pp.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(pp.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(pp.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN pp.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = pp.source_id AND derived_origin.slug = ANY(ARRAY[(pp.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=pp.source_id AND renamed.alias_slug=(pp.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=pp.source_id AND moved.old_slug=(pp.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (pp.type IN ('atom', 'question') OR (pp.type = 'concept' AND pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = pp.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN pp.type = 'event' AND pp.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = pp.source_id AND chronicle_origin.slug = pp.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(pp.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = pp.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(pp.frontmatter->'derived_from') = 'array' THEN pp.frontmatter->'derived_from' ELSE jsonb_build_array(pp.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))))) AND (NOT EXISTS (SELECT 1 FROM pages entity_pp WHERE entity_pp.source_id = facts.source_id AND entity_pp.slug IN (facts.entity_slug, CASE WHEN facts.entity_slug IS NOT NULL AND (facts.source_markdown_slug = 'memory/unattributed' OR facts.source_markdown_slug LIKE '%/memory/unattributed') THEN facts.source_markdown_slug END) AND NOT ((((entity_pp.page_readers IS NULL AND NOT (entity_pp.frontmatter ? 'readable_by'))) AND (entity_pp.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = entity_pp.source_id AND (starts_with(entity_pp.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR entity_pp.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((entity_pp.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (entity_pp.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(entity_pp.id, entity_pp.source_id, entity_pp.type, entity_pp.frontmatter))) AND ((COALESCE(entity_pp.frontmatter->>'visibility', CASE WHEN (entity_pp.type IN ('atom', 'question') OR (entity_pp.type = 'concept' AND entity_pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(entity_pp.frontmatter ? 'pinned_question', false) AND NOT (entity_pp.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(entity_pp.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(entity_pp.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN entity_pp.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = entity_pp.source_id AND derived_origin.slug = ANY(ARRAY[(entity_pp.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=entity_pp.source_id AND renamed.alias_slug=(entity_pp.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=entity_pp.source_id AND moved.old_slug=(entity_pp.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (entity_pp.type IN ('atom', 'question') OR (entity_pp.type = 'concept' AND entity_pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = entity_pp.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN entity_pp.type = 'event' AND entity_pp.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = entity_pp.source_id AND chronicle_origin.slug = entity_pp.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(entity_pp.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = entity_pp.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(entity_pp.frontmatter->'derived_from') = 'array' THEN entity_pp.frontmatter->'derived_from' ELSE jsonb_build_array(entity_pp.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)))) AND NOT (facts.entity_slug IS NOT NULL AND (facts.source_markdown_slug = 'memory/unattributed' OR facts.source_markdown_slug LIKE '%/memory/unattributed') AND (NOT COALESCE(gbrain_access_folder_rules(facts.source_id, facts.entity_slug) <@ ARRAY[]::text[], true) OR gbrain_access_pending_covers(facts.source_id, facts.entity_slug))))) AND COALESCE(valid_from, '-infinity'::timestamptz) <= COALESCE($3::timestamptz, now()) AND COALESCE(valid_until, 'infinity'::timestamptz) > COALESCE($4::timestamptz, now()) AND confidence >= $5 AND ($6::boolean OR dim_status IS NULL OR dim_status = 'active') ORDER BY dimension, valid_from DESC NULLS LAST, confidence DESC, id DESC",
- "textSha256": "986d17fca8adf7589458f80e7435c58b1c48173aff504f6b33eda543546edbcc"
+ "sql": "SELECT DISTINCT ON (dimension) dimension, value, confidence, source_markdown_slug AS source, valid_from, valid_until AS valid_to, COALESCE(dim_status, 'active') AS status, id AS fact_id FROM facts WHERE entity_slug = $1 AND dimension IS NOT NULL AND expired_at IS NULL AND COALESCE(source, '') NOT LIKE 'cli:extract-conversation-facts%' AND source_id = ANY($2) AND NOT EXISTS (SELECT 1 FROM pages elig_dp WHERE elig_dp.source_id = facts.source_id AND elig_dp.slug = ANY(ARRAY[facts.source_markdown_slug, facts.entity_slug]) AND elig_dp.deleted_at IS NOT NULL) AND ((NOT EXISTS (SELECT 1 FROM pages pp WHERE pp.source_id = facts.source_id AND pp.slug = facts.source_markdown_slug AND NOT (((((pp.page_readers IS NULL AND NOT (pp.frontmatter ? 'readable_by'))) AND (pp.folder_rule_ids IS NULL OR COALESCE(gbrain_access_lineage_rules(pp.source_id, pp.folder_rule_ids) <@ ARRAY[]::text[], true)) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = pp.source_id AND (starts_with(pp.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR pp.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((pp.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (pp.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(pp.id, pp.source_id, pp.type, pp.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(pp.frontmatter->>'visibility', CASE WHEN (pp.type IN ('atom', 'question') OR (pp.type = 'concept' AND pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(pp.frontmatter ? 'pinned_question', false) AND NOT (pp.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(pp.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(pp.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN pp.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = pp.source_id AND derived_origin.slug = ANY(ARRAY[(pp.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=pp.source_id AND renamed.alias_slug=(pp.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=pp.source_id AND moved.old_slug=(pp.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (pp.type IN ('atom', 'question') OR (pp.type = 'concept' AND pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = pp.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN pp.type = 'event' AND pp.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = pp.source_id AND chronicle_origin.slug = pp.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(pp.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = pp.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(pp.frontmatter->'derived_from') = 'array' THEN pp.frontmatter->'derived_from' ELSE jsonb_build_array(pp.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))))) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND (NOT EXISTS (SELECT 1 FROM pages entity_pp WHERE entity_pp.source_id = facts.source_id AND entity_pp.slug IN (facts.entity_slug, CASE WHEN facts.entity_slug IS NOT NULL AND (facts.source_markdown_slug = 'memory/unattributed' OR facts.source_markdown_slug LIKE '%/memory/unattributed') THEN facts.source_markdown_slug END) AND NOT ((((entity_pp.page_readers IS NULL AND NOT (entity_pp.frontmatter ? 'readable_by'))) AND (entity_pp.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = entity_pp.source_id AND (starts_with(entity_pp.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR entity_pp.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((entity_pp.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (entity_pp.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(entity_pp.id, entity_pp.source_id, entity_pp.type, entity_pp.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(entity_pp.frontmatter->>'visibility', CASE WHEN (entity_pp.type IN ('atom', 'question') OR (entity_pp.type = 'concept' AND entity_pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(entity_pp.frontmatter ? 'pinned_question', false) AND NOT (entity_pp.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(entity_pp.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(entity_pp.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN entity_pp.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = entity_pp.source_id AND derived_origin.slug = ANY(ARRAY[(entity_pp.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=entity_pp.source_id AND renamed.alias_slug=(entity_pp.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=entity_pp.source_id AND moved.old_slug=(entity_pp.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (entity_pp.type IN ('atom', 'question') OR (entity_pp.type = 'concept' AND entity_pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = entity_pp.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN entity_pp.type = 'event' AND entity_pp.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = entity_pp.source_id AND chronicle_origin.slug = entity_pp.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(entity_pp.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = entity_pp.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(entity_pp.frontmatter->'derived_from') = 'array' THEN entity_pp.frontmatter->'derived_from' ELSE jsonb_build_array(entity_pp.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)))) AND NOT (facts.entity_slug IS NOT NULL AND (facts.source_markdown_slug = 'memory/unattributed' OR facts.source_markdown_slug LIKE '%/memory/unattributed') AND (NOT COALESCE(gbrain_access_folder_rules(facts.source_id, facts.entity_slug) <@ ARRAY[]::text[], true) OR gbrain_access_pending_covers(facts.source_id, facts.entity_slug))))) AND COALESCE(valid_from, '-infinity'::timestamptz) <= COALESCE($3::timestamptz, now()) AND COALESCE(valid_until, 'infinity'::timestamptz) > COALESCE($4::timestamptz, now()) AND confidence >= $5 AND ($6::boolean OR dim_status IS NULL OR dim_status = 'active') ORDER BY dimension, valid_from DESC NULLS LAST, confidence DESC, id DESC",
+ "textSha256": "71571b9fc082e5012763f105ac18eeb8a26e05956fd8ce051a27d06b10ce0b24"
}
]
},
diff --git a/test/fixtures/goldens/sql-text/links.json b/test/fixtures/goldens/sql-text/links.json
index 98f363dd29..6deefb295c 100644
--- a/test/fixtures/goldens/sql-text/links.json
+++ b/test/fixtures/goldens/sql-text/links.json
@@ -76,8 +76,8 @@
"params": [
"array<string>"
],
- "sql": "SELECT p.slug, COALESCE(p.title, p.slug) AS title, p.frontmatter->>'domain' AS domain, p.type, (NOT NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine')) AS quarantined, p.source_id FROM pages p WHERE p.deleted_at IS NULL AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.source_id = ANY($1::text[]) AND NOT EXISTS ( SELECT 1 FROM links l JOIN pages src ON src.id = l.from_page_id WHERE l.to_page_id = p.id AND src.deleted_at IS NULL AND ((((src.page_readers IS NULL AND NOT (src.frontmatter ? 'readable_by'))) AND (src.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = src.source_id AND (starts_with(src.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR src.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((src.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (src.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(src.id, src.source_id, src.type, src.frontmatter))) AND ((COALESCE(src.frontmatter->>'visibility', CASE WHEN (src.type IN ('atom', 'question') OR (src.type = 'concept' AND src.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(src.frontmatter ? 'pinned_question', false) AND NOT (src.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(src.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(src.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN src.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = src.source_id AND derived_origin.slug = ANY(ARRAY[(src.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=src.source_id AND renamed.alias_slug=(src.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=src.source_id AND moved.old_slug=(src.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (src.type IN ('atom', 'question') OR (src.type = 'concept' AND src.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = src.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN src.type = 'event' AND src.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = src.source_id AND chronicle_origin.slug = src.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(src.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = src.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(src.frontmatter->'derived_from') = 'array' THEN src.frontmatter->'derived_from' ELSE jsonb_build_array(src.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (l.origin_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages origin_private WHERE origin_private.id = l.origin_page_id AND ((((origin_private.page_readers IS NULL AND NOT (origin_private.frontmatter ? 'readable_by'))) AND (origin_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = origin_private.source_id AND (starts_with(origin_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR origin_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((origin_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (origin_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(origin_private.id, origin_private.source_id, origin_private.type, origin_private.frontmatter))) AND ((COALESCE(origin_private.frontmatter->>'visibility', CASE WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(origin_private.frontmatter ? 'pinned_question', false) AND NOT (origin_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(origin_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(origin_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN origin_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = origin_private.source_id AND derived_origin.slug = ANY(ARRAY[(origin_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=origin_private.source_id AND renamed.alias_slug=(origin_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=origin_private.source_id AND moved.old_slug=(origin_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = origin_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN origin_private.type = 'event' AND origin_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = origin_private.source_id AND chronicle_origin.slug = origin_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = origin_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') = 'array' THEN origin_private.frontmatter->'derived_from' ELSE jsonb_build_array(origin_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) ) AND NOT EXISTS ( SELECT 1 FROM links l JOIN pages tgt ON tgt.id = l.to_page_id WHERE l.from_page_id = p.id AND tgt.deleted_at IS NULL AND ((((tgt.page_readers IS NULL AND NOT (tgt.frontmatter ? 'readable_by'))) AND (tgt.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = tgt.source_id AND (starts_with(tgt.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR tgt.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((tgt.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (tgt.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(tgt.id, tgt.source_id, tgt.type, tgt.frontmatter))) AND ((COALESCE(tgt.frontmatter->>'visibility', CASE WHEN (tgt.type IN ('atom', 'question') OR (tgt.type = 'concept' AND tgt.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(tgt.frontmatter ? 'pinned_question', false) AND NOT (tgt.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(tgt.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(tgt.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN tgt.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = tgt.source_id AND derived_origin.slug = ANY(ARRAY[(tgt.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=tgt.source_id AND renamed.alias_slug=(tgt.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=tgt.source_id AND moved.old_slug=(tgt.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (tgt.type IN ('atom', 'question') OR (tgt.type = 'concept' AND tgt.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = tgt.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN tgt.type = 'event' AND tgt.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = tgt.source_id AND chronicle_origin.slug = tgt.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(tgt.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = tgt.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(tgt.frontmatter->'derived_from') = 'array' THEN tgt.frontmatter->'derived_from' ELSE jsonb_build_array(tgt.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (l.origin_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages origin_private WHERE origin_private.id = l.origin_page_id AND ((((origin_private.page_readers IS NULL AND NOT (origin_private.frontmatter ? 'readable_by'))) AND (origin_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = origin_private.source_id AND (starts_with(origin_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR origin_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((origin_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (origin_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(origin_private.id, origin_private.source_id, origin_private.type, origin_private.frontmatter))) AND ((COALESCE(origin_private.frontmatter->>'visibility', CASE WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(origin_private.frontmatter ? 'pinned_question', false) AND NOT (origin_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(origin_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(origin_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN origin_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = origin_private.source_id AND derived_origin.slug = ANY(ARRAY[(origin_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=origin_private.source_id AND renamed.alias_slug=(origin_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=origin_private.source_id AND moved.old_slug=(origin_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = origin_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN origin_private.type = 'event' AND origin_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = origin_private.source_id AND chronicle_origin.slug = origin_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = origin_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') = 'array' THEN origin_private.frontmatter->'derived_from' ELSE jsonb_build_array(origin_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) ) ORDER BY p.slug",
- "textSha256": "150a76bb21e0c705645c6a1ee669ebdd8f4ba43ee2863d302431452705669484"
+ "sql": "SELECT p.slug, COALESCE(p.title, p.slug) AS title, p.frontmatter->>'domain' AS domain, p.type, (NOT NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine')) AS quarantined, p.source_id FROM pages p WHERE p.deleted_at IS NULL AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.source_id = ANY($1::text[]) AND NOT EXISTS ( SELECT 1 FROM links l JOIN pages src ON src.id = l.from_page_id WHERE l.to_page_id = p.id AND src.deleted_at IS NULL AND ((((src.page_readers IS NULL AND NOT (src.frontmatter ? 'readable_by'))) AND (src.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = src.source_id AND (starts_with(src.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR src.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((src.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (src.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(src.id, src.source_id, src.type, src.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(src.frontmatter->>'visibility', CASE WHEN (src.type IN ('atom', 'question') OR (src.type = 'concept' AND src.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(src.frontmatter ? 'pinned_question', false) AND NOT (src.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(src.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(src.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN src.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = src.source_id AND derived_origin.slug = ANY(ARRAY[(src.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=src.source_id AND renamed.alias_slug=(src.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=src.source_id AND moved.old_slug=(src.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (src.type IN ('atom', 'question') OR (src.type = 'concept' AND src.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = src.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN src.type = 'event' AND src.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = src.source_id AND chronicle_origin.slug = src.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(src.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = src.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(src.frontmatter->'derived_from') = 'array' THEN src.frontmatter->'derived_from' ELSE jsonb_build_array(src.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (l.origin_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages origin_private WHERE origin_private.id = l.origin_page_id AND ((((origin_private.page_readers IS NULL AND NOT (origin_private.frontmatter ? 'readable_by'))) AND (origin_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = origin_private.source_id AND (starts_with(origin_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR origin_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((origin_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (origin_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(origin_private.id, origin_private.source_id, origin_private.type, origin_private.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(origin_private.frontmatter->>'visibility', CASE WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(origin_private.frontmatter ? 'pinned_question', false) AND NOT (origin_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(origin_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(origin_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN origin_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = origin_private.source_id AND derived_origin.slug = ANY(ARRAY[(origin_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=origin_private.source_id AND renamed.alias_slug=(origin_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=origin_private.source_id AND moved.old_slug=(origin_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = origin_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN origin_private.type = 'event' AND origin_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = origin_private.source_id AND chronicle_origin.slug = origin_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = origin_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') = 'array' THEN origin_private.frontmatter->'derived_from' ELSE jsonb_build_array(origin_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) ) AND NOT EXISTS ( SELECT 1 FROM links l JOIN pages tgt ON tgt.id = l.to_page_id WHERE l.from_page_id = p.id AND tgt.deleted_at IS NULL AND ((((tgt.page_readers IS NULL AND NOT (tgt.frontmatter ? 'readable_by'))) AND (tgt.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = tgt.source_id AND (starts_with(tgt.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR tgt.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((tgt.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (tgt.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(tgt.id, tgt.source_id, tgt.type, tgt.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(tgt.frontmatter->>'visibility', CASE WHEN (tgt.type IN ('atom', 'question') OR (tgt.type = 'concept' AND tgt.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(tgt.frontmatter ? 'pinned_question', false) AND NOT (tgt.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(tgt.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(tgt.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN tgt.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = tgt.source_id AND derived_origin.slug = ANY(ARRAY[(tgt.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=tgt.source_id AND renamed.alias_slug=(tgt.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=tgt.source_id AND moved.old_slug=(tgt.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (tgt.type IN ('atom', 'question') OR (tgt.type = 'concept' AND tgt.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = tgt.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN tgt.type = 'event' AND tgt.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = tgt.source_id AND chronicle_origin.slug = tgt.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(tgt.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = tgt.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(tgt.frontmatter->'derived_from') = 'array' THEN tgt.frontmatter->'derived_from' ELSE jsonb_build_array(tgt.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (l.origin_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages origin_private WHERE origin_private.id = l.origin_page_id AND ((((origin_private.page_readers IS NULL AND NOT (origin_private.frontmatter ? 'readable_by'))) AND (origin_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = origin_private.source_id AND (starts_with(origin_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR origin_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((origin_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (origin_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(origin_private.id, origin_private.source_id, origin_private.type, origin_private.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(origin_private.frontmatter->>'visibility', CASE WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(origin_private.frontmatter ? 'pinned_question', false) AND NOT (origin_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(origin_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(origin_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN origin_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = origin_private.source_id AND derived_origin.slug = ANY(ARRAY[(origin_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=origin_private.source_id AND renamed.alias_slug=(origin_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=origin_private.source_id AND moved.old_slug=(origin_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = origin_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN origin_private.type = 'event' AND origin_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = origin_private.source_id AND chronicle_origin.slug = origin_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = origin_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') = 'array' THEN origin_private.frontmatter->'derived_from' ELSE jsonb_build_array(origin_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) ) ORDER BY p.slug",
+ "textSha256": "865533d9e3b49aa988ca25c03143268463d86f01b1c6f10a5e1a145fcada5dee"
}
]
},
@@ -98,8 +98,8 @@
"params": [
"string"
],
- "sql": "SELECT f.slug as from_slug, f.source_id as from_source_id, t.slug as to_slug, t.source_id as to_source_id, l.link_type, l.context, l.link_source, o.slug as origin_slug, o.source_id as origin_source_id, l.origin_field FROM links l JOIN pages f ON f.id = l.from_page_id JOIN pages t ON t.id = l.to_page_id LEFT JOIN pages o ON o.id = l.origin_page_id WHERE t.slug = $1 AND f.deleted_at IS NULL AND t.deleted_at IS NULL AND (l.origin_page_id IS NULL OR EXISTS (SELECT 1 FROM pages lo WHERE lo.id = l.origin_page_id AND lo.deleted_at IS NULL)) AND ((((f.page_readers IS NULL AND NOT (f.frontmatter ? 'readable_by'))) AND (f.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = f.source_id AND (starts_with(f.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR f.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((f.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (f.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(f.id, f.source_id, f.type, f.frontmatter))) AND ((COALESCE(f.frontmatter->>'visibility', CASE WHEN (f.type IN ('atom', 'question') OR (f.type = 'concept' AND f.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(f.frontmatter ? 'pinned_question', false) AND NOT (f.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(f.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(f.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN f.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = f.source_id AND derived_origin.slug = ANY(ARRAY[(f.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=f.source_id AND renamed.alias_slug=(f.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=f.source_id AND moved.old_slug=(f.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (f.type IN ('atom', 'question') OR (f.type = 'concept' AND f.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = f.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN f.type = 'event' AND f.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = f.source_id AND chronicle_origin.slug = f.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(f.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = f.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(f.frontmatter->'derived_from') = 'array' THEN f.frontmatter->'derived_from' ELSE jsonb_build_array(f.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND ((((t.page_readers IS NULL AND NOT (t.frontmatter ? 'readable_by'))) AND (t.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = t.source_id AND (starts_with(t.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR t.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((t.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (t.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(t.id, t.source_id, t.type, t.frontmatter))) AND ((COALESCE(t.frontmatter->>'visibility', CASE WHEN (t.type IN ('atom', 'question') OR (t.type = 'concept' AND t.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(t.frontmatter ? 'pinned_question', false) AND NOT (t.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(t.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(t.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN t.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = t.source_id AND derived_origin.slug = ANY(ARRAY[(t.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=t.source_id AND renamed.alias_slug=(t.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=t.source_id AND moved.old_slug=(t.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (t.type IN ('atom', 'question') OR (t.type = 'concept' AND t.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = t.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN t.type = 'event' AND t.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = t.source_id AND chronicle_origin.slug = t.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(t.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = t.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(t.frontmatter->'derived_from') = 'array' THEN t.frontmatter->'derived_from' ELSE jsonb_build_array(t.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (l.origin_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages origin_private WHERE origin_private.id = l.origin_page_id AND ((((origin_private.page_readers IS NULL AND NOT (origin_private.frontmatter ? 'readable_by'))) AND (origin_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = origin_private.source_id AND (starts_with(origin_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR origin_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((origin_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (origin_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(origin_private.id, origin_private.source_id, origin_private.type, origin_private.frontmatter))) AND ((COALESCE(origin_private.frontmatter->>'visibility', CASE WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(origin_private.frontmatter ? 'pinned_question', false) AND NOT (origin_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(origin_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(origin_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN origin_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = origin_private.source_id AND derived_origin.slug = ANY(ARRAY[(origin_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=origin_private.source_id AND renamed.alias_slug=(origin_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=origin_private.source_id AND moved.old_slug=(origin_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = origin_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN origin_private.type = 'event' AND origin_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = origin_private.source_id AND chronicle_origin.slug = origin_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = origin_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') = 'array' THEN origin_private.frontmatter->'derived_from' ELSE jsonb_build_array(origin_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) ORDER BY l.id",
- "textSha256": "216c9ad0c55b9a1d1790bac22c0905d15348dcb995c1351446670347ff816f67"
+ "sql": "SELECT f.slug as from_slug, f.source_id as from_source_id, t.slug as to_slug, t.source_id as to_source_id, l.link_type, l.context, l.link_source, o.slug as origin_slug, o.source_id as origin_source_id, l.origin_field FROM links l JOIN pages f ON f.id = l.from_page_id JOIN pages t ON t.id = l.to_page_id LEFT JOIN pages o ON o.id = l.origin_page_id WHERE t.slug = $1 AND f.deleted_at IS NULL AND t.deleted_at IS NULL AND (l.origin_page_id IS NULL OR EXISTS (SELECT 1 FROM pages lo WHERE lo.id = l.origin_page_id AND lo.deleted_at IS NULL)) AND ((((f.page_readers IS NULL AND NOT (f.frontmatter ? 'readable_by'))) AND (f.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = f.source_id AND (starts_with(f.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR f.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((f.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (f.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(f.id, f.source_id, f.type, f.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(f.frontmatter->>'visibility', CASE WHEN (f.type IN ('atom', 'question') OR (f.type = 'concept' AND f.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(f.frontmatter ? 'pinned_question', false) AND NOT (f.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(f.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(f.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN f.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = f.source_id AND derived_origin.slug = ANY(ARRAY[(f.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=f.source_id AND renamed.alias_slug=(f.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=f.source_id AND moved.old_slug=(f.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (f.type IN ('atom', 'question') OR (f.type = 'concept' AND f.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = f.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN f.type = 'event' AND f.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = f.source_id AND chronicle_origin.slug = f.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(f.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = f.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(f.frontmatter->'derived_from') = 'array' THEN f.frontmatter->'derived_from' ELSE jsonb_build_array(f.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND ((((t.page_readers IS NULL AND NOT (t.frontmatter ? 'readable_by'))) AND (t.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = t.source_id AND (starts_with(t.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR t.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((t.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (t.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(t.id, t.source_id, t.type, t.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(t.frontmatter->>'visibility', CASE WHEN (t.type IN ('atom', 'question') OR (t.type = 'concept' AND t.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(t.frontmatter ? 'pinned_question', false) AND NOT (t.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(t.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(t.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN t.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = t.source_id AND derived_origin.slug = ANY(ARRAY[(t.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=t.source_id AND renamed.alias_slug=(t.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=t.source_id AND moved.old_slug=(t.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (t.type IN ('atom', 'question') OR (t.type = 'concept' AND t.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = t.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN t.type = 'event' AND t.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = t.source_id AND chronicle_origin.slug = t.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(t.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = t.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(t.frontmatter->'derived_from') = 'array' THEN t.frontmatter->'derived_from' ELSE jsonb_build_array(t.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (l.origin_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages origin_private WHERE origin_private.id = l.origin_page_id AND ((((origin_private.page_readers IS NULL AND NOT (origin_private.frontmatter ? 'readable_by'))) AND (origin_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = origin_private.source_id AND (starts_with(origin_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR origin_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((origin_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (origin_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(origin_private.id, origin_private.source_id, origin_private.type, origin_private.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(origin_private.frontmatter->>'visibility', CASE WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(origin_private.frontmatter ? 'pinned_question', false) AND NOT (origin_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(origin_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(origin_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN origin_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = origin_private.source_id AND derived_origin.slug = ANY(ARRAY[(origin_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=origin_private.source_id AND renamed.alias_slug=(origin_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=origin_private.source_id AND moved.old_slug=(origin_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = origin_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN origin_private.type = 'event' AND origin_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = origin_private.source_id AND chronicle_origin.slug = origin_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = origin_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') = 'array' THEN origin_private.frontmatter->'derived_from' ELSE jsonb_build_array(origin_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) ORDER BY l.id",
+ "textSha256": "80828eb81bd96c39931a9d5ac17ee0130b40d4a6f39be75af57ede816411786c"
}
],
"sourceId": [
@@ -144,8 +144,8 @@
"params": [
"string"
],
- "sql": "SELECT f.slug as from_slug, f.source_id as from_source_id, t.slug as to_slug, t.source_id as to_source_id, l.link_type, l.context, l.link_source, o.slug as origin_slug, o.source_id as origin_source_id, l.origin_field FROM links l JOIN pages f ON f.id = l.from_page_id JOIN pages t ON t.id = l.to_page_id LEFT JOIN pages o ON o.id = l.origin_page_id WHERE f.slug = $1 AND f.deleted_at IS NULL AND t.deleted_at IS NULL AND (l.origin_page_id IS NULL OR EXISTS (SELECT 1 FROM pages lo WHERE lo.id = l.origin_page_id AND lo.deleted_at IS NULL)) AND ((((f.page_readers IS NULL AND NOT (f.frontmatter ? 'readable_by'))) AND (f.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = f.source_id AND (starts_with(f.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR f.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((f.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (f.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(f.id, f.source_id, f.type, f.frontmatter))) AND ((COALESCE(f.frontmatter->>'visibility', CASE WHEN (f.type IN ('atom', 'question') OR (f.type = 'concept' AND f.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(f.frontmatter ? 'pinned_question', false) AND NOT (f.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(f.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(f.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN f.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = f.source_id AND derived_origin.slug = ANY(ARRAY[(f.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=f.source_id AND renamed.alias_slug=(f.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=f.source_id AND moved.old_slug=(f.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (f.type IN ('atom', 'question') OR (f.type = 'concept' AND f.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = f.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN f.type = 'event' AND f.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = f.source_id AND chronicle_origin.slug = f.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(f.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = f.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(f.frontmatter->'derived_from') = 'array' THEN f.frontmatter->'derived_from' ELSE jsonb_build_array(f.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND ((((t.page_readers IS NULL AND NOT (t.frontmatter ? 'readable_by'))) AND (t.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = t.source_id AND (starts_with(t.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR t.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((t.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (t.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(t.id, t.source_id, t.type, t.frontmatter))) AND ((COALESCE(t.frontmatter->>'visibility', CASE WHEN (t.type IN ('atom', 'question') OR (t.type = 'concept' AND t.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(t.frontmatter ? 'pinned_question', false) AND NOT (t.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(t.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(t.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN t.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = t.source_id AND derived_origin.slug = ANY(ARRAY[(t.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=t.source_id AND renamed.alias_slug=(t.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=t.source_id AND moved.old_slug=(t.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (t.type IN ('atom', 'question') OR (t.type = 'concept' AND t.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = t.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN t.type = 'event' AND t.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = t.source_id AND chronicle_origin.slug = t.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(t.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = t.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(t.frontmatter->'derived_from') = 'array' THEN t.frontmatter->'derived_from' ELSE jsonb_build_array(t.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (l.origin_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages origin_private WHERE origin_private.id = l.origin_page_id AND ((((origin_private.page_readers IS NULL AND NOT (origin_private.frontmatter ? 'readable_by'))) AND (origin_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = origin_private.source_id AND (starts_with(origin_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR origin_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((origin_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (origin_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(origin_private.id, origin_private.source_id, origin_private.type, origin_private.frontmatter))) AND ((COALESCE(origin_private.frontmatter->>'visibility', CASE WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(origin_private.frontmatter ? 'pinned_question', false) AND NOT (origin_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(origin_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(origin_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN origin_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = origin_private.source_id AND derived_origin.slug = ANY(ARRAY[(origin_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=origin_private.source_id AND renamed.alias_slug=(origin_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=origin_private.source_id AND moved.old_slug=(origin_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = origin_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN origin_private.type = 'event' AND origin_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = origin_private.source_id AND chronicle_origin.slug = origin_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = origin_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') = 'array' THEN origin_private.frontmatter->'derived_from' ELSE jsonb_build_array(origin_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) ORDER BY l.id",
- "textSha256": "77dba99bc11eacaca5853d2073bf9747785657f241e13ec0ca03e05313704536"
+ "sql": "SELECT f.slug as from_slug, f.source_id as from_source_id, t.slug as to_slug, t.source_id as to_source_id, l.link_type, l.context, l.link_source, o.slug as origin_slug, o.source_id as origin_source_id, l.origin_field FROM links l JOIN pages f ON f.id = l.from_page_id JOIN pages t ON t.id = l.to_page_id LEFT JOIN pages o ON o.id = l.origin_page_id WHERE f.slug = $1 AND f.deleted_at IS NULL AND t.deleted_at IS NULL AND (l.origin_page_id IS NULL OR EXISTS (SELECT 1 FROM pages lo WHERE lo.id = l.origin_page_id AND lo.deleted_at IS NULL)) AND ((((f.page_readers IS NULL AND NOT (f.frontmatter ? 'readable_by'))) AND (f.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = f.source_id AND (starts_with(f.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR f.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((f.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (f.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(f.id, f.source_id, f.type, f.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(f.frontmatter->>'visibility', CASE WHEN (f.type IN ('atom', 'question') OR (f.type = 'concept' AND f.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(f.frontmatter ? 'pinned_question', false) AND NOT (f.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(f.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(f.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN f.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = f.source_id AND derived_origin.slug = ANY(ARRAY[(f.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=f.source_id AND renamed.alias_slug=(f.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=f.source_id AND moved.old_slug=(f.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (f.type IN ('atom', 'question') OR (f.type = 'concept' AND f.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = f.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN f.type = 'event' AND f.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = f.source_id AND chronicle_origin.slug = f.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(f.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = f.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(f.frontmatter->'derived_from') = 'array' THEN f.frontmatter->'derived_from' ELSE jsonb_build_array(f.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND ((((t.page_readers IS NULL AND NOT (t.frontmatter ? 'readable_by'))) AND (t.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = t.source_id AND (starts_with(t.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR t.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((t.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (t.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(t.id, t.source_id, t.type, t.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(t.frontmatter->>'visibility', CASE WHEN (t.type IN ('atom', 'question') OR (t.type = 'concept' AND t.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(t.frontmatter ? 'pinned_question', false) AND NOT (t.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(t.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(t.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN t.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = t.source_id AND derived_origin.slug = ANY(ARRAY[(t.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=t.source_id AND renamed.alias_slug=(t.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=t.source_id AND moved.old_slug=(t.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (t.type IN ('atom', 'question') OR (t.type = 'concept' AND t.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = t.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN t.type = 'event' AND t.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = t.source_id AND chronicle_origin.slug = t.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(t.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = t.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(t.frontmatter->'derived_from') = 'array' THEN t.frontmatter->'derived_from' ELSE jsonb_build_array(t.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (l.origin_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages origin_private WHERE origin_private.id = l.origin_page_id AND ((((origin_private.page_readers IS NULL AND NOT (origin_private.frontmatter ? 'readable_by'))) AND (origin_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = origin_private.source_id AND (starts_with(origin_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR origin_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((origin_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (origin_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(origin_private.id, origin_private.source_id, origin_private.type, origin_private.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(origin_private.frontmatter->>'visibility', CASE WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(origin_private.frontmatter ? 'pinned_question', false) AND NOT (origin_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(origin_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(origin_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN origin_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = origin_private.source_id AND derived_origin.slug = ANY(ARRAY[(origin_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=origin_private.source_id AND renamed.alias_slug=(origin_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=origin_private.source_id AND moved.old_slug=(origin_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = origin_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN origin_private.type = 'event' AND origin_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = origin_private.source_id AND chronicle_origin.slug = origin_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = origin_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') = 'array' THEN origin_private.frontmatter->'derived_from' ELSE jsonb_build_array(origin_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) ORDER BY l.id",
+ "textSha256": "f56a4e4ae486585a0464a0222b14c8d2b44546f79fa71210dfd644abf56973bf"
}
],
"sourceId": [
@@ -672,8 +672,8 @@
"number",
"number"
],
- "sql": "WITH RECURSIVE bfs(depth, frontier, visited) AS ( SELECT 0, array_agg(p.id ORDER BY p.slug, p.id), array_agg(p.id ORDER BY p.slug, p.id) FROM pages p WHERE p.slug = $1 AND p.deleted_at IS NULL AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) HAVING count(*) > 0 UNION ALL SELECT bfs.depth + 1, n.next, bfs.visited || n.next FROM bfs CROSS JOIN LATERAL ( SELECT array_agg(c.id ORDER BY c.slug, c.id) AS next FROM ( SELECT DISTINCT nb.id, nb.slug FROM (SELECT p2.id, p2.slug FROM unnest(bfs.frontier) f(id) JOIN links l ON l.from_page_id = f.id JOIN pages p2 ON p2.id = l.to_page_id WHERE p2.deleted_at IS NULL AND ((((p2.page_readers IS NULL AND NOT (p2.frontmatter ? 'readable_by'))) AND (p2.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p2.source_id AND (starts_with(p2.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p2.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p2.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p2.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p2.id, p2.source_id, p2.type, p2.frontmatter))) AND ((COALESCE(p2.frontmatter->>'visibility', CASE WHEN (p2.type IN ('atom', 'question') OR (p2.type = 'concept' AND p2.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p2.frontmatter ? 'pinned_question', false) AND NOT (p2.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p2.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p2.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p2.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p2.source_id AND derived_origin.slug = ANY(ARRAY[(p2.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p2.source_id AND renamed.alias_slug=(p2.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p2.source_id AND moved.old_slug=(p2.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p2.type IN ('atom', 'question') OR (p2.type = 'concept' AND p2.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p2.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p2.type = 'event' AND p2.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p2.source_id AND chronicle_origin.slug = p2.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p2.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p2.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p2.frontmatter->'derived_from') = 'array' THEN p2.frontmatter->'derived_from' ELSE jsonb_build_array(p2.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (l.origin_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages origin_private WHERE origin_private.id = l.origin_page_id AND ((((origin_private.page_readers IS NULL AND NOT (origin_private.frontmatter ? 'readable_by'))) AND (origin_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = origin_private.source_id AND (starts_with(origin_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR origin_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((origin_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (origin_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(origin_private.id, origin_private.source_id, origin_private.type, origin_private.frontmatter))) AND ((COALESCE(origin_private.frontmatter->>'visibility', CASE WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(origin_private.frontmatter ? 'pinned_question', false) AND NOT (origin_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(origin_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(origin_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN origin_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = origin_private.source_id AND derived_origin.slug = ANY(ARRAY[(origin_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=origin_private.source_id AND renamed.alias_slug=(origin_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=origin_private.source_id AND moved.old_slug=(origin_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = origin_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN origin_private.type = 'event' AND origin_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = origin_private.source_id AND chronicle_origin.slug = origin_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = origin_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') = 'array' THEN origin_private.frontmatter->'derived_from' ELSE jsonb_build_array(origin_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) AND (l.origin_page_id IS NULL OR EXISTS (SELECT 1 FROM pages lo WHERE lo.id = l.origin_page_id AND lo.deleted_at IS NULL)) ) nb WHERE NOT EXISTS (SELECT 1 FROM unnest(bfs.visited) v(id) WHERE v.id = nb.id) ORDER BY nb.slug, nb.id LIMIT greatest(0, $2::int - cardinality(bfs.visited)) ) c ) n WHERE bfs.depth < $3::int AND n.next IS NOT NULL ), walk AS ( SELECT u.id, b.depth, row_number() OVER (ORDER BY b.depth, u.ord) AS pos FROM bfs b CROSS JOIN LATERAL unnest(b.frontier) WITH ORDINALITY u(id, ord) ) SELECT g.slug, g.source_id, g.title, g.type, g.depth, coalesce( -- jsonb_agg(DISTINCT ...) collapses duplicate (to_slug, link_type) -- edges that originate from different provenance (markdown body -- vs frontmatter vs auto-extracted). The underlying links table -- preserves every row with its origin_page_id / link_source — -- the dedup is presentation-only for the legacy traverseGraph -- aggregation. See plan Bug 6/10. (SELECT jsonb_agg(DISTINCT jsonb_build_object('to_slug', p3.slug, 'link_type', l2.link_type)) FROM links l2 JOIN pages p3 ON p3.id = l2.to_page_id WHERE l2.from_page_id = g.id AND p3.deleted_at IS NULL AND ((((p3.page_readers IS NULL AND NOT (p3.frontmatter ? 'readable_by'))) AND (p3.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p3.source_id AND (starts_with(p3.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p3.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p3.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p3.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p3.id, p3.source_id, p3.type, p3.frontmatter))) AND ((COALESCE(p3.frontmatter->>'visibility', CASE WHEN (p3.type IN ('atom', 'question') OR (p3.type = 'concept' AND p3.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p3.frontmatter ? 'pinned_question', false) AND NOT (p3.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p3.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p3.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p3.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p3.source_id AND derived_origin.slug = ANY(ARRAY[(p3.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p3.source_id AND renamed.alias_slug=(p3.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p3.source_id AND moved.old_slug=(p3.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p3.type IN ('atom', 'question') OR (p3.type = 'concept' AND p3.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p3.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p3.type = 'event' AND p3.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p3.source_id AND chronicle_origin.slug = p3.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p3.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p3.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p3.frontmatter->'derived_from') = 'array' THEN p3.frontmatter->'derived_from' ELSE jsonb_build_array(p3.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (l2.origin_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages origin_private WHERE origin_private.id = l2.origin_page_id AND ((((origin_private.page_readers IS NULL AND NOT (origin_private.frontmatter ? 'readable_by'))) AND (origin_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = origin_private.source_id AND (starts_with(origin_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR origin_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((origin_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (origin_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(origin_private.id, origin_private.source_id, origin_private.type, origin_private.frontmatter))) AND ((COALESCE(origin_private.frontmatter->>'visibility', CASE WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(origin_private.frontmatter ? 'pinned_question', false) AND NOT (origin_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(origin_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(origin_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN origin_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = origin_private.source_id AND derived_origin.slug = ANY(ARRAY[(origin_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=origin_private.source_id AND renamed.alias_slug=(origin_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=origin_private.source_id AND moved.old_slug=(origin_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = origin_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN origin_private.type = 'event' AND origin_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = origin_private.source_id AND chronicle_origin.slug = origin_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = origin_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') = 'array' THEN origin_private.frontmatter->'derived_from' ELSE jsonb_build_array(origin_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) AND (l2.origin_page_id IS NULL OR EXISTS (SELECT 1 FROM pages lo WHERE lo.id = l2.origin_page_id AND lo.deleted_at IS NULL)) ), '[]'::jsonb ) as links FROM (SELECT p.id, p.slug, p.source_id, p.title, p.type, w.depth FROM walk w JOIN pages p ON p.id = w.id WHERE w.pos <= $4::int) g ORDER BY g.depth, g.slug, g.source_id",
- "textSha256": "136b493322d0ab99a00fac442f5db9e137fd718e6e3c4088f2b805f612ef5e44"
+ "sql": "WITH RECURSIVE bfs(depth, frontier, visited) AS ( SELECT 0, array_agg(p.id ORDER BY p.slug, p.id), array_agg(p.id ORDER BY p.slug, p.id) FROM pages p WHERE p.slug = $1 AND p.deleted_at IS NULL AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) HAVING count(*) > 0 UNION ALL SELECT bfs.depth + 1, n.next, bfs.visited || n.next FROM bfs CROSS JOIN LATERAL ( SELECT array_agg(c.id ORDER BY c.slug, c.id) AS next FROM ( SELECT DISTINCT nb.id, nb.slug FROM (SELECT p2.id, p2.slug FROM unnest(bfs.frontier) f(id) JOIN links l ON l.from_page_id = f.id JOIN pages p2 ON p2.id = l.to_page_id WHERE p2.deleted_at IS NULL AND ((((p2.page_readers IS NULL AND NOT (p2.frontmatter ? 'readable_by'))) AND (p2.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p2.source_id AND (starts_with(p2.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p2.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p2.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p2.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p2.id, p2.source_id, p2.type, p2.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p2.frontmatter->>'visibility', CASE WHEN (p2.type IN ('atom', 'question') OR (p2.type = 'concept' AND p2.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p2.frontmatter ? 'pinned_question', false) AND NOT (p2.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p2.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p2.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p2.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p2.source_id AND derived_origin.slug = ANY(ARRAY[(p2.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p2.source_id AND renamed.alias_slug=(p2.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p2.source_id AND moved.old_slug=(p2.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p2.type IN ('atom', 'question') OR (p2.type = 'concept' AND p2.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p2.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p2.type = 'event' AND p2.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p2.source_id AND chronicle_origin.slug = p2.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p2.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p2.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p2.frontmatter->'derived_from') = 'array' THEN p2.frontmatter->'derived_from' ELSE jsonb_build_array(p2.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (l.origin_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages origin_private WHERE origin_private.id = l.origin_page_id AND ((((origin_private.page_readers IS NULL AND NOT (origin_private.frontmatter ? 'readable_by'))) AND (origin_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = origin_private.source_id AND (starts_with(origin_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR origin_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((origin_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (origin_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(origin_private.id, origin_private.source_id, origin_private.type, origin_private.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(origin_private.frontmatter->>'visibility', CASE WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(origin_private.frontmatter ? 'pinned_question', false) AND NOT (origin_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(origin_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(origin_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN origin_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = origin_private.source_id AND derived_origin.slug = ANY(ARRAY[(origin_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=origin_private.source_id AND renamed.alias_slug=(origin_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=origin_private.source_id AND moved.old_slug=(origin_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = origin_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN origin_private.type = 'event' AND origin_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = origin_private.source_id AND chronicle_origin.slug = origin_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = origin_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') = 'array' THEN origin_private.frontmatter->'derived_from' ELSE jsonb_build_array(origin_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) AND (l.origin_page_id IS NULL OR EXISTS (SELECT 1 FROM pages lo WHERE lo.id = l.origin_page_id AND lo.deleted_at IS NULL)) ) nb WHERE NOT EXISTS (SELECT 1 FROM unnest(bfs.visited) v(id) WHERE v.id = nb.id) ORDER BY nb.slug, nb.id LIMIT greatest(0, $2::int - cardinality(bfs.visited)) ) c ) n WHERE bfs.depth < $3::int AND n.next IS NOT NULL ), walk AS ( SELECT u.id, b.depth, row_number() OVER (ORDER BY b.depth, u.ord) AS pos FROM bfs b CROSS JOIN LATERAL unnest(b.frontier) WITH ORDINALITY u(id, ord) ) SELECT g.slug, g.source_id, g.title, g.type, g.depth, coalesce( -- jsonb_agg(DISTINCT ...) collapses duplicate (to_slug, link_type) -- edges that originate from different provenance (markdown body -- vs frontmatter vs auto-extracted). The underlying links table -- preserves every row with its origin_page_id / link_source — -- the dedup is presentation-only for the legacy traverseGraph -- aggregation. See plan Bug 6/10. (SELECT jsonb_agg(DISTINCT jsonb_build_object('to_slug', p3.slug, 'link_type', l2.link_type)) FROM links l2 JOIN pages p3 ON p3.id = l2.to_page_id WHERE l2.from_page_id = g.id AND p3.deleted_at IS NULL AND ((((p3.page_readers IS NULL AND NOT (p3.frontmatter ? 'readable_by'))) AND (p3.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p3.source_id AND (starts_with(p3.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p3.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p3.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p3.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p3.id, p3.source_id, p3.type, p3.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p3.frontmatter->>'visibility', CASE WHEN (p3.type IN ('atom', 'question') OR (p3.type = 'concept' AND p3.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p3.frontmatter ? 'pinned_question', false) AND NOT (p3.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p3.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p3.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p3.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p3.source_id AND derived_origin.slug = ANY(ARRAY[(p3.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p3.source_id AND renamed.alias_slug=(p3.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p3.source_id AND moved.old_slug=(p3.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p3.type IN ('atom', 'question') OR (p3.type = 'concept' AND p3.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p3.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p3.type = 'event' AND p3.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p3.source_id AND chronicle_origin.slug = p3.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p3.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p3.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p3.frontmatter->'derived_from') = 'array' THEN p3.frontmatter->'derived_from' ELSE jsonb_build_array(p3.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (l2.origin_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages origin_private WHERE origin_private.id = l2.origin_page_id AND ((((origin_private.page_readers IS NULL AND NOT (origin_private.frontmatter ? 'readable_by'))) AND (origin_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = origin_private.source_id AND (starts_with(origin_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR origin_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((origin_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (origin_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(origin_private.id, origin_private.source_id, origin_private.type, origin_private.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(origin_private.frontmatter->>'visibility', CASE WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(origin_private.frontmatter ? 'pinned_question', false) AND NOT (origin_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(origin_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(origin_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN origin_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = origin_private.source_id AND derived_origin.slug = ANY(ARRAY[(origin_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=origin_private.source_id AND renamed.alias_slug=(origin_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=origin_private.source_id AND moved.old_slug=(origin_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = origin_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN origin_private.type = 'event' AND origin_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = origin_private.source_id AND chronicle_origin.slug = origin_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = origin_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') = 'array' THEN origin_private.frontmatter->'derived_from' ELSE jsonb_build_array(origin_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) AND (l2.origin_page_id IS NULL OR EXISTS (SELECT 1 FROM pages lo WHERE lo.id = l2.origin_page_id AND lo.deleted_at IS NULL)) ), '[]'::jsonb ) as links FROM (SELECT p.id, p.slug, p.source_id, p.title, p.type, w.depth FROM walk w JOIN pages p ON p.id = w.id WHERE w.pos <= $4::int) g ORDER BY g.depth, g.slug, g.source_id",
+ "textSha256": "80ec61ab256ab814dd626ab7207235e6bebfd2b35a431616a98126cf62569788"
}
],
"frontierCap": [
@@ -782,8 +782,8 @@
"array<string>",
"number"
],
- "sql": "WITH RECURSIVE bfs(depth, frontier, visited) AS ( SELECT 0, array_agg(p.id ORDER BY p.slug, p.id), array_agg(p.id ORDER BY p.slug, p.id) FROM pages p WHERE p.slug = $1 AND p.deleted_at IS NULL AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.source_id = ANY($2::text[]) HAVING count(*) > 0 UNION ALL SELECT bfs.depth + 1, n.next, bfs.visited || n.next FROM bfs CROSS JOIN LATERAL ( SELECT array_agg(c.id ORDER BY c.slug, c.id) AS next FROM ( SELECT DISTINCT nb.id, nb.slug FROM (SELECT p2.id, p2.slug FROM unnest(bfs.frontier) f(id) JOIN links l ON l.from_page_id = f.id JOIN pages p2 ON p2.id = l.to_page_id WHERE p2.deleted_at IS NULL AND ((((p2.page_readers IS NULL AND NOT (p2.frontmatter ? 'readable_by'))) AND (p2.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p2.source_id AND (starts_with(p2.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p2.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p2.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p2.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p2.id, p2.source_id, p2.type, p2.frontmatter))) AND ((COALESCE(p2.frontmatter->>'visibility', CASE WHEN (p2.type IN ('atom', 'question') OR (p2.type = 'concept' AND p2.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p2.frontmatter ? 'pinned_question', false) AND NOT (p2.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p2.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p2.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p2.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p2.source_id AND derived_origin.slug = ANY(ARRAY[(p2.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p2.source_id AND renamed.alias_slug=(p2.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p2.source_id AND moved.old_slug=(p2.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p2.type IN ('atom', 'question') OR (p2.type = 'concept' AND p2.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p2.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p2.type = 'event' AND p2.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p2.source_id AND chronicle_origin.slug = p2.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p2.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p2.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p2.frontmatter->'derived_from') = 'array' THEN p2.frontmatter->'derived_from' ELSE jsonb_build_array(p2.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (l.origin_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages origin_private WHERE origin_private.id = l.origin_page_id AND ((((origin_private.page_readers IS NULL AND NOT (origin_private.frontmatter ? 'readable_by'))) AND (origin_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = origin_private.source_id AND (starts_with(origin_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR origin_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((origin_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (origin_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(origin_private.id, origin_private.source_id, origin_private.type, origin_private.frontmatter))) AND ((COALESCE(origin_private.frontmatter->>'visibility', CASE WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(origin_private.frontmatter ? 'pinned_question', false) AND NOT (origin_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(origin_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(origin_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN origin_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = origin_private.source_id AND derived_origin.slug = ANY(ARRAY[(origin_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=origin_private.source_id AND renamed.alias_slug=(origin_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=origin_private.source_id AND moved.old_slug=(origin_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = origin_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN origin_private.type = 'event' AND origin_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = origin_private.source_id AND chronicle_origin.slug = origin_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = origin_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') = 'array' THEN origin_private.frontmatter->'derived_from' ELSE jsonb_build_array(origin_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) AND p2.source_id = ANY($3::text[]) AND (l.origin_page_id IS NULL OR EXISTS (SELECT 1 FROM pages lo WHERE lo.id = l.origin_page_id AND lo.deleted_at IS NULL AND lo.source_id = ANY($4::text[]))) UNION ALL SELECT p2.id, p2.slug FROM unnest(bfs.frontier) f(id) JOIN links l ON l.to_page_id = f.id JOIN pages p2 ON p2.id = l.from_page_id WHERE p2.deleted_at IS NULL AND ((((p2.page_readers IS NULL AND NOT (p2.frontmatter ? 'readable_by'))) AND (p2.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p2.source_id AND (starts_with(p2.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p2.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p2.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p2.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p2.id, p2.source_id, p2.type, p2.frontmatter))) AND ((COALESCE(p2.frontmatter->>'visibility', CASE WHEN (p2.type IN ('atom', 'question') OR (p2.type = 'concept' AND p2.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p2.frontmatter ? 'pinned_question', false) AND NOT (p2.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p2.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p2.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p2.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p2.source_id AND derived_origin.slug = ANY(ARRAY[(p2.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p2.source_id AND renamed.alias_slug=(p2.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p2.source_id AND moved.old_slug=(p2.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p2.type IN ('atom', 'question') OR (p2.type = 'concept' AND p2.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p2.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p2.type = 'event' AND p2.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p2.source_id AND chronicle_origin.slug = p2.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p2.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p2.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p2.frontmatter->'derived_from') = 'array' THEN p2.frontmatter->'derived_from' ELSE jsonb_build_array(p2.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (l.origin_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages origin_private WHERE origin_private.id = l.origin_page_id AND ((((origin_private.page_readers IS NULL AND NOT (origin_private.frontmatter ? 'readable_by'))) AND (origin_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = origin_private.source_id AND (starts_with(origin_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR origin_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((origin_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (origin_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(origin_private.id, origin_private.source_id, origin_private.type, origin_private.frontmatter))) AND ((COALESCE(origin_private.frontmatter->>'visibility', CASE WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(origin_private.frontmatter ? 'pinned_question', false) AND NOT (origin_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(origin_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(origin_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN origin_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = origin_private.source_id AND derived_origin.slug = ANY(ARRAY[(origin_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=origin_private.source_id AND renamed.alias_slug=(origin_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=origin_private.source_id AND moved.old_slug=(origin_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = origin_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN origin_private.type = 'event' AND origin_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = origin_private.source_id AND chronicle_origin.slug = origin_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = origin_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') = 'array' THEN origin_private.frontmatter->'derived_from' ELSE jsonb_build_array(origin_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) AND p2.source_id = ANY($5::text[]) AND (l.origin_page_id IS NULL OR EXISTS (SELECT 1 FROM pages lo WHERE lo.id = l.origin_page_id AND lo.deleted_at IS NULL AND lo.source_id = ANY($6::text[])))) nb WHERE NOT EXISTS (SELECT 1 FROM unnest(bfs.visited) v(id) WHERE v.id = nb.id) ORDER BY nb.slug, nb.id LIMIT greatest(0, $7::int - cardinality(bfs.visited)) ) c ) n WHERE bfs.depth < $8::int AND n.next IS NOT NULL ), walk AS ( SELECT u.id, b.depth, row_number() OVER (ORDER BY b.depth, u.ord) AS pos FROM bfs b CROSS JOIN LATERAL unnest(b.frontier) WITH ORDINALITY u(id, ord) ), nodes AS (SELECT p.id, p.slug, p.source_id, w.depth FROM walk w JOIN pages p ON p.id = w.id WHERE w.pos <= $9::int) SELECT (SELECT count(*) FROM walk) > $10::int AS walk_truncated, pf.id as from_id, pf.slug as from_slug, pf.source_id as from_source_id, pt.id as to_id, pt.slug as to_slug, pt.source_id as to_source_id, l.link_type, l.context, e.depth + 1 as depth FROM ( SELECT l.id AS link_id, wf.depth FROM nodes wf JOIN links l ON l.from_page_id = wf.id LEFT JOIN nodes wt ON wt.id = l.to_page_id WHERE wt.id IS NULL OR wf.depth <= wt.depth UNION ALL SELECT l.id, wt.depth FROM nodes wt JOIN links l ON l.to_page_id = wt.id LEFT JOIN nodes wf ON wf.id = l.from_page_id WHERE wf.id IS NULL OR wt.depth < wf.depth ) e JOIN links l ON l.id = e.link_id JOIN pages pf ON pf.id = l.from_page_id JOIN pages pt ON pt.id = l.to_page_id WHERE e.depth < $11 AND pf.deleted_at IS NULL AND ((((pf.page_readers IS NULL AND NOT (pf.frontmatter ? 'readable_by'))) AND (pf.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = pf.source_id AND (starts_with(pf.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR pf.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((pf.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (pf.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(pf.id, pf.source_id, pf.type, pf.frontmatter))) AND ((COALESCE(pf.frontmatter->>'visibility', CASE WHEN (pf.type IN ('atom', 'question') OR (pf.type = 'concept' AND pf.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(pf.frontmatter ? 'pinned_question', false) AND NOT (pf.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(pf.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(pf.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN pf.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = pf.source_id AND derived_origin.slug = ANY(ARRAY[(pf.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=pf.source_id AND renamed.alias_slug=(pf.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=pf.source_id AND moved.old_slug=(pf.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (pf.type IN ('atom', 'question') OR (pf.type = 'concept' AND pf.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = pf.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN pf.type = 'event' AND pf.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = pf.source_id AND chronicle_origin.slug = pf.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(pf.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = pf.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(pf.frontmatter->'derived_from') = 'array' THEN pf.frontmatter->'derived_from' ELSE jsonb_build_array(pf.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (l.origin_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages origin_private WHERE origin_private.id = l.origin_page_id AND ((((origin_private.page_readers IS NULL AND NOT (origin_private.frontmatter ? 'readable_by'))) AND (origin_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = origin_private.source_id AND (starts_with(origin_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR origin_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((origin_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (origin_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(origin_private.id, origin_private.source_id, origin_private.type, origin_private.frontmatter))) AND ((COALESCE(origin_private.frontmatter->>'visibility', CASE WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(origin_private.frontmatter ? 'pinned_question', false) AND NOT (origin_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(origin_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(origin_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN origin_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = origin_private.source_id AND derived_origin.slug = ANY(ARRAY[(origin_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=origin_private.source_id AND renamed.alias_slug=(origin_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=origin_private.source_id AND moved.old_slug=(origin_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = origin_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN origin_private.type = 'event' AND origin_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = origin_private.source_id AND chronicle_origin.slug = origin_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = origin_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') = 'array' THEN origin_private.frontmatter->'derived_from' ELSE jsonb_build_array(origin_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) AND pt.deleted_at IS NULL AND ((((pt.page_readers IS NULL AND NOT (pt.frontmatter ? 'readable_by'))) AND (pt.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = pt.source_id AND (starts_with(pt.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR pt.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((pt.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (pt.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(pt.id, pt.source_id, pt.type, pt.frontmatter))) AND ((COALESCE(pt.frontmatter->>'visibility', CASE WHEN (pt.type IN ('atom', 'question') OR (pt.type = 'concept' AND pt.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(pt.frontmatter ? 'pinned_question', false) AND NOT (pt.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(pt.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(pt.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN pt.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = pt.source_id AND derived_origin.slug = ANY(ARRAY[(pt.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=pt.source_id AND renamed.alias_slug=(pt.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=pt.source_id AND moved.old_slug=(pt.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (pt.type IN ('atom', 'question') OR (pt.type = 'concept' AND pt.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = pt.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN pt.type = 'event' AND pt.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = pt.source_id AND chronicle_origin.slug = pt.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(pt.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = pt.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(pt.frontmatter->'derived_from') = 'array' THEN pt.frontmatter->'derived_from' ELSE jsonb_build_array(pt.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND pf.source_id = ANY($12::text[]) AND pt.source_id = ANY($13::text[]) AND (l.origin_page_id IS NULL OR EXISTS (SELECT 1 FROM pages lo WHERE lo.id = l.origin_page_id AND lo.deleted_at IS NULL AND lo.source_id = ANY($14::text[]))) ORDER BY depth, from_slug, to_slug, from_source_id, to_source_id LIMIT $15",
- "textSha256": "c00373a0578931ca930d43cd7fa3ac9e45a9c90747f303971f75481169f41dbd"
+ "sql": "WITH RECURSIVE bfs(depth, frontier, visited) AS ( SELECT 0, array_agg(p.id ORDER BY p.slug, p.id), array_agg(p.id ORDER BY p.slug, p.id) FROM pages p WHERE p.slug = $1 AND p.deleted_at IS NULL AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.source_id = ANY($2::text[]) HAVING count(*) > 0 UNION ALL SELECT bfs.depth + 1, n.next, bfs.visited || n.next FROM bfs CROSS JOIN LATERAL ( SELECT array_agg(c.id ORDER BY c.slug, c.id) AS next FROM ( SELECT DISTINCT nb.id, nb.slug FROM (SELECT p2.id, p2.slug FROM unnest(bfs.frontier) f(id) JOIN links l ON l.from_page_id = f.id JOIN pages p2 ON p2.id = l.to_page_id WHERE p2.deleted_at IS NULL AND ((((p2.page_readers IS NULL AND NOT (p2.frontmatter ? 'readable_by'))) AND (p2.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p2.source_id AND (starts_with(p2.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p2.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p2.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p2.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p2.id, p2.source_id, p2.type, p2.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p2.frontmatter->>'visibility', CASE WHEN (p2.type IN ('atom', 'question') OR (p2.type = 'concept' AND p2.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p2.frontmatter ? 'pinned_question', false) AND NOT (p2.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p2.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p2.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p2.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p2.source_id AND derived_origin.slug = ANY(ARRAY[(p2.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p2.source_id AND renamed.alias_slug=(p2.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p2.source_id AND moved.old_slug=(p2.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p2.type IN ('atom', 'question') OR (p2.type = 'concept' AND p2.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p2.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p2.type = 'event' AND p2.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p2.source_id AND chronicle_origin.slug = p2.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p2.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p2.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p2.frontmatter->'derived_from') = 'array' THEN p2.frontmatter->'derived_from' ELSE jsonb_build_array(p2.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (l.origin_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages origin_private WHERE origin_private.id = l.origin_page_id AND ((((origin_private.page_readers IS NULL AND NOT (origin_private.frontmatter ? 'readable_by'))) AND (origin_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = origin_private.source_id AND (starts_with(origin_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR origin_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((origin_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (origin_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(origin_private.id, origin_private.source_id, origin_private.type, origin_private.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(origin_private.frontmatter->>'visibility', CASE WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(origin_private.frontmatter ? 'pinned_question', false) AND NOT (origin_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(origin_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(origin_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN origin_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = origin_private.source_id AND derived_origin.slug = ANY(ARRAY[(origin_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=origin_private.source_id AND renamed.alias_slug=(origin_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=origin_private.source_id AND moved.old_slug=(origin_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = origin_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN origin_private.type = 'event' AND origin_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = origin_private.source_id AND chronicle_origin.slug = origin_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = origin_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') = 'array' THEN origin_private.frontmatter->'derived_from' ELSE jsonb_build_array(origin_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) AND p2.source_id = ANY($3::text[]) AND (l.origin_page_id IS NULL OR EXISTS (SELECT 1 FROM pages lo WHERE lo.id = l.origin_page_id AND lo.deleted_at IS NULL AND lo.source_id = ANY($4::text[]))) UNION ALL SELECT p2.id, p2.slug FROM unnest(bfs.frontier) f(id) JOIN links l ON l.to_page_id = f.id JOIN pages p2 ON p2.id = l.from_page_id WHERE p2.deleted_at IS NULL AND ((((p2.page_readers IS NULL AND NOT (p2.frontmatter ? 'readable_by'))) AND (p2.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p2.source_id AND (starts_with(p2.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p2.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p2.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p2.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p2.id, p2.source_id, p2.type, p2.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p2.frontmatter->>'visibility', CASE WHEN (p2.type IN ('atom', 'question') OR (p2.type = 'concept' AND p2.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p2.frontmatter ? 'pinned_question', false) AND NOT (p2.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p2.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p2.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p2.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p2.source_id AND derived_origin.slug = ANY(ARRAY[(p2.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p2.source_id AND renamed.alias_slug=(p2.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p2.source_id AND moved.old_slug=(p2.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p2.type IN ('atom', 'question') OR (p2.type = 'concept' AND p2.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p2.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p2.type = 'event' AND p2.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p2.source_id AND chronicle_origin.slug = p2.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p2.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p2.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p2.frontmatter->'derived_from') = 'array' THEN p2.frontmatter->'derived_from' ELSE jsonb_build_array(p2.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (l.origin_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages origin_private WHERE origin_private.id = l.origin_page_id AND ((((origin_private.page_readers IS NULL AND NOT (origin_private.frontmatter ? 'readable_by'))) AND (origin_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = origin_private.source_id AND (starts_with(origin_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR origin_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((origin_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (origin_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(origin_private.id, origin_private.source_id, origin_private.type, origin_private.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(origin_private.frontmatter->>'visibility', CASE WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(origin_private.frontmatter ? 'pinned_question', false) AND NOT (origin_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(origin_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(origin_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN origin_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = origin_private.source_id AND derived_origin.slug = ANY(ARRAY[(origin_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=origin_private.source_id AND renamed.alias_slug=(origin_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=origin_private.source_id AND moved.old_slug=(origin_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = origin_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN origin_private.type = 'event' AND origin_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = origin_private.source_id AND chronicle_origin.slug = origin_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = origin_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') = 'array' THEN origin_private.frontmatter->'derived_from' ELSE jsonb_build_array(origin_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) AND p2.source_id = ANY($5::text[]) AND (l.origin_page_id IS NULL OR EXISTS (SELECT 1 FROM pages lo WHERE lo.id = l.origin_page_id AND lo.deleted_at IS NULL AND lo.source_id = ANY($6::text[])))) nb WHERE NOT EXISTS (SELECT 1 FROM unnest(bfs.visited) v(id) WHERE v.id = nb.id) ORDER BY nb.slug, nb.id LIMIT greatest(0, $7::int - cardinality(bfs.visited)) ) c ) n WHERE bfs.depth < $8::int AND n.next IS NOT NULL ), walk AS ( SELECT u.id, b.depth, row_number() OVER (ORDER BY b.depth, u.ord) AS pos FROM bfs b CROSS JOIN LATERAL unnest(b.frontier) WITH ORDINALITY u(id, ord) ), nodes AS (SELECT p.id, p.slug, p.source_id, w.depth FROM walk w JOIN pages p ON p.id = w.id WHERE w.pos <= $9::int) SELECT (SELECT count(*) FROM walk) > $10::int AS walk_truncated, pf.id as from_id, pf.slug as from_slug, pf.source_id as from_source_id, pt.id as to_id, pt.slug as to_slug, pt.source_id as to_source_id, l.link_type, l.context, e.depth + 1 as depth FROM ( SELECT l.id AS link_id, wf.depth FROM nodes wf JOIN links l ON l.from_page_id = wf.id LEFT JOIN nodes wt ON wt.id = l.to_page_id WHERE wt.id IS NULL OR wf.depth <= wt.depth UNION ALL SELECT l.id, wt.depth FROM nodes wt JOIN links l ON l.to_page_id = wt.id LEFT JOIN nodes wf ON wf.id = l.from_page_id WHERE wf.id IS NULL OR wt.depth < wf.depth ) e JOIN links l ON l.id = e.link_id JOIN pages pf ON pf.id = l.from_page_id JOIN pages pt ON pt.id = l.to_page_id WHERE e.depth < $11 AND pf.deleted_at IS NULL AND ((((pf.page_readers IS NULL AND NOT (pf.frontmatter ? 'readable_by'))) AND (pf.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = pf.source_id AND (starts_with(pf.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR pf.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((pf.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (pf.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(pf.id, pf.source_id, pf.type, pf.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(pf.frontmatter->>'visibility', CASE WHEN (pf.type IN ('atom', 'question') OR (pf.type = 'concept' AND pf.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(pf.frontmatter ? 'pinned_question', false) AND NOT (pf.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(pf.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(pf.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN pf.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = pf.source_id AND derived_origin.slug = ANY(ARRAY[(pf.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=pf.source_id AND renamed.alias_slug=(pf.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=pf.source_id AND moved.old_slug=(pf.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (pf.type IN ('atom', 'question') OR (pf.type = 'concept' AND pf.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = pf.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN pf.type = 'event' AND pf.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = pf.source_id AND chronicle_origin.slug = pf.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(pf.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = pf.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(pf.frontmatter->'derived_from') = 'array' THEN pf.frontmatter->'derived_from' ELSE jsonb_build_array(pf.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (l.origin_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages origin_private WHERE origin_private.id = l.origin_page_id AND ((((origin_private.page_readers IS NULL AND NOT (origin_private.frontmatter ? 'readable_by'))) AND (origin_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = origin_private.source_id AND (starts_with(origin_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR origin_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((origin_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (origin_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(origin_private.id, origin_private.source_id, origin_private.type, origin_private.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(origin_private.frontmatter->>'visibility', CASE WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(origin_private.frontmatter ? 'pinned_question', false) AND NOT (origin_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(origin_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(origin_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN origin_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = origin_private.source_id AND derived_origin.slug = ANY(ARRAY[(origin_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=origin_private.source_id AND renamed.alias_slug=(origin_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=origin_private.source_id AND moved.old_slug=(origin_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (origin_private.type IN ('atom', 'question') OR (origin_private.type = 'concept' AND origin_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = origin_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN origin_private.type = 'event' AND origin_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = origin_private.source_id AND chronicle_origin.slug = origin_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = origin_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(origin_private.frontmatter->'derived_from') = 'array' THEN origin_private.frontmatter->'derived_from' ELSE jsonb_build_array(origin_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) AND pt.deleted_at IS NULL AND ((((pt.page_readers IS NULL AND NOT (pt.frontmatter ? 'readable_by'))) AND (pt.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = pt.source_id AND (starts_with(pt.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR pt.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((pt.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (pt.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(pt.id, pt.source_id, pt.type, pt.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(pt.frontmatter->>'visibility', CASE WHEN (pt.type IN ('atom', 'question') OR (pt.type = 'concept' AND pt.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(pt.frontmatter ? 'pinned_question', false) AND NOT (pt.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(pt.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(pt.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN pt.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = pt.source_id AND derived_origin.slug = ANY(ARRAY[(pt.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=pt.source_id AND renamed.alias_slug=(pt.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=pt.source_id AND moved.old_slug=(pt.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (pt.type IN ('atom', 'question') OR (pt.type = 'concept' AND pt.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = pt.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN pt.type = 'event' AND pt.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = pt.source_id AND chronicle_origin.slug = pt.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(pt.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = pt.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(pt.frontmatter->'derived_from') = 'array' THEN pt.frontmatter->'derived_from' ELSE jsonb_build_array(pt.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND pf.source_id = ANY($12::text[]) AND pt.source_id = ANY($13::text[]) AND (l.origin_page_id IS NULL OR EXISTS (SELECT 1 FROM pages lo WHERE lo.id = l.origin_page_id AND lo.deleted_at IS NULL AND lo.source_id = ANY($14::text[]))) ORDER BY depth, from_slug, to_slug, from_source_id, to_source_id LIMIT $15",
+ "textSha256": "5b0f98941ddb0abcc7b517085356668c310745603f0a741bc4d4bcbe54499f64"
}
],
"default": [
diff --git a/test/fixtures/goldens/sql-text/pages.json b/test/fixtures/goldens/sql-text/pages.json
index d5a0d63c1e..b6d20aeaf8 100644
--- a/test/fixtures/goldens/sql-text/pages.json
+++ b/test/fixtures/goldens/sql-text/pages.json
@@ -10,8 +10,8 @@
"string",
"string"
],
- "sql": "SELECT p.source_id, p.type, count(*) AS pages FROM pages p JOIN sources s ON s.id = p.source_id WHERE p.deleted_at IS NULL AND NOT s.archived AND p.source_id = $1 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.deleted_at IS NULL AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id = p.source_id AND NOT read_source.archived) AND COALESCE(p.effective_date, p.updated_at, p.created_at) >= $2::text::timestamptz GROUP BY p.source_id, p.type",
- "textSha256": "fcb4caafb3c9db05f1877bce7fed9ce27368eddf6fe9f9d047d3fb12bc9eeb10"
+ "sql": "SELECT p.source_id, p.type, count(*) AS pages FROM pages p JOIN sources s ON s.id = p.source_id WHERE p.deleted_at IS NULL AND NOT s.archived AND p.source_id = $1 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.deleted_at IS NULL AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id = p.source_id AND NOT read_source.archived) AND COALESCE(p.effective_date, p.updated_at, p.created_at) >= $2::text::timestamptz GROUP BY p.source_id, p.type",
+ "textSha256": "188085380e32d3ff59411e028de4f34c69e792fdb4d83b20abcfabcce004a288"
},
{
"lane": "pool",
@@ -21,8 +21,8 @@
"string",
"string"
],
- "sql": "SELECT m.grp, GROUPING(m.grp) = 1 AS is_total, count(*) AS pages, count(DISTINCT p.slug COLLATE \"C\") AS distinct_slugs FROM pages p JOIN sources s ON s.id = p.source_id JOIN unnest($1::text[], $2::text[]) AS m(type, grp) ON m.type = p.type WHERE p.deleted_at IS NULL AND NOT s.archived AND p.source_id = $3 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.deleted_at IS NULL AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id = p.source_id AND NOT read_source.archived) AND COALESCE(p.effective_date, p.updated_at, p.created_at) >= $4::text::timestamptz GROUP BY GROUPING SETS ((m.grp), ())",
- "textSha256": "1375baf9bfa9627ebba4aaf286addaaeba03835e31b6e5a012f91e1a7d7e7dce"
+ "sql": "SELECT m.grp, GROUPING(m.grp) = 1 AS is_total, count(*) AS pages, count(DISTINCT p.slug COLLATE \"C\") AS distinct_slugs FROM pages p JOIN sources s ON s.id = p.source_id JOIN unnest($1::text[], $2::text[]) AS m(type, grp) ON m.type = p.type WHERE p.deleted_at IS NULL AND NOT s.archived AND p.source_id = $3 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.deleted_at IS NULL AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id = p.source_id AND NOT read_source.archived) AND COALESCE(p.effective_date, p.updated_at, p.created_at) >= $4::text::timestamptz GROUP BY GROUPING SETS ((m.grp), ())",
+ "textSha256": "a3d467d527a6223518a90a282d0c1b712bf6e394b35ff56d74d6278e6f60e4e6"
}
],
"totals": [
@@ -291,8 +291,8 @@
"array<string>",
"number"
],
- "sql": "SELECT p.slug, p.source_id, p.type, p.title, p.source_path, to_char(p.updated_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS updated_at, count(*) OVER () AS total FROM pages p JOIN sources s ON s.id = p.source_id WHERE (p.slug ILIKE $1 OR p.source_path ILIKE $2) AND p.deleted_at IS NULL AND NOT s.archived AND p.source_id = ANY($3::text[]) AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.deleted_at IS NULL AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id = p.source_id AND NOT read_source.archived) AND p.type = ANY($4::text[]) AND NOT (p.slug LIKE 'test/%' OR p.slug LIKE '.raw/%') ORDER BY p.slug COLLATE \"C\", p.source_id COLLATE \"C\" LIMIT $5",
- "textSha256": "22767b9c3c3af06b9c920756c309b40e2b282e697e0f5beeaf307cb20c11e79f"
+ "sql": "SELECT p.slug, p.source_id, p.type, p.title, p.source_path, to_char(p.updated_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS updated_at, count(*) OVER () AS total FROM pages p JOIN sources s ON s.id = p.source_id WHERE (p.slug ILIKE $1 OR p.source_path ILIKE $2) AND p.deleted_at IS NULL AND NOT s.archived AND p.source_id = ANY($3::text[]) AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.deleted_at IS NULL AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id = p.source_id AND NOT read_source.archived) AND p.type = ANY($4::text[]) AND NOT (p.slug LIKE 'test/%' OR p.slug LIKE '.raw/%') ORDER BY p.slug COLLATE \"C\", p.source_id COLLATE \"C\" LIMIT $5",
+ "textSha256": "7f680e73048026664ce3c8efde1ce2529a1cda4f8e39dbe007e3e96d4a189cf6"
}
],
"name": [
@@ -410,8 +410,8 @@
"params": [
"string"
],
- "sql": "SELECT pv.id, pv.page_id, pv.compiled_truth, pv.frontmatter, pv.snapshot_at, pv.knowledge_revision, pv.timeline, pv.title, pv.type, pv.tags, pv.is_deleted, pv.source_path, pv.body_storage, pv.body_generation, pv.body_bytes, pv.content_hash, CASE WHEN pv.change_reason IS NULL OR COALESCE(pv.successor_pruned, false) THEN NULL WHEN COALESCE((SELECT (COALESCE(rb_next.frontmatter->>'visibility', CASE WHEN (rb_next.type IN ('atom', 'question') OR (rb_next.type = 'concept' AND rb_next.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(rb_next.frontmatter ? 'pinned_question', false) AND NOT (rb_next.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(rb_next.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(rb_next.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND (NOT (rb_next.frontmatter ? 'readable_by')) FROM page_versions rb_next WHERE rb_next.page_id = pv.page_id AND rb_next.id > pv.id ORDER BY rb_next.id LIMIT 1), true) THEN pv.change_reason END AS replaced_because, (CASE WHEN substring(pv.frontmatter->>'valid_from' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$') IS NULL THEN NULL WHEN substr(substring(pv.frontmatter->>'valid_from' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$'), 1, 4)::int < 1000 OR substr(substring(pv.frontmatter->>'valid_from' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$'), 6, 2)::int NOT BETWEEN 1 AND 12 THEN NULL WHEN substr(substring(pv.frontmatter->>'valid_from' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$'), 9, 2)::int BETWEEN 1 AND extract(day from make_date(substr(substring(pv.frontmatter->>'valid_from' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$'), 1, 4)::int, substr(substring(pv.frontmatter->>'valid_from' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$'), 6, 2)::int, 1) + interval '1 month' - interval '1 day')::int THEN substring(pv.frontmatter->>'valid_from' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$') END) AS valid_from, (CASE WHEN substring(pv.frontmatter->>'valid_until' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$') IS NULL THEN NULL WHEN substr(substring(pv.frontmatter->>'valid_until' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$'), 1, 4)::int < 1000 OR substr(substring(pv.frontmatter->>'valid_until' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$'), 6, 2)::int NOT BETWEEN 1 AND 12 THEN NULL WHEN substr(substring(pv.frontmatter->>'valid_until' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$'), 9, 2)::int BETWEEN 1 AND extract(day from make_date(substr(substring(pv.frontmatter->>'valid_until' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$'), 1, 4)::int, substr(substring(pv.frontmatter->>'valid_until' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$'), 6, 2)::int, 1) + interval '1 month' - interval '1 day')::int THEN substring(pv.frontmatter->>'valid_until' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$') END) AS valid_until FROM page_versions pv JOIN pages p ON p.id = pv.page_id WHERE p.slug = $1 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (NOT (pv.frontmatter ? 'readable_by')) AND (COALESCE(pv.frontmatter->>'visibility', CASE WHEN (pv.type IN ('atom', 'question') OR (pv.type = 'concept' AND pv.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(pv.frontmatter ? 'pinned_question', false) AND NOT (pv.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(pv.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(pv.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT COALESCE(pv.frontmatter ? 'pinned_question', false) AND NOT EXISTS (SELECT 1 FROM needs_rederive elig_nr WHERE elig_nr.derived_table = 'pages' AND elig_nr.derived_id = p.id::text) ORDER BY pv.snapshot_at DESC, pv.id DESC",
- "textSha256": "9e8e1bfd9b55f9b6cb6c03da47aabf0861f04b2a3ea24acb5f77259020553bbd"
+ "sql": "SELECT pv.id, pv.page_id, pv.compiled_truth, pv.frontmatter, pv.snapshot_at, pv.knowledge_revision, pv.timeline, pv.title, pv.type, pv.tags, pv.is_deleted, pv.source_path, pv.body_storage, pv.body_generation, pv.body_bytes, pv.content_hash, CASE WHEN pv.change_reason IS NULL OR COALESCE(pv.successor_pruned, false) THEN NULL WHEN COALESCE((SELECT (COALESCE(rb_next.frontmatter->>'visibility', CASE WHEN (rb_next.type IN ('atom', 'question') OR (rb_next.type = 'concept' AND rb_next.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(rb_next.frontmatter ? 'pinned_question', false) AND NOT (rb_next.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(rb_next.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(rb_next.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND (NOT (rb_next.frontmatter ? 'readable_by')) FROM page_versions rb_next WHERE rb_next.page_id = pv.page_id AND rb_next.id > pv.id ORDER BY rb_next.id LIMIT 1), true) THEN pv.change_reason END AS replaced_because, (CASE WHEN substring(pv.frontmatter->>'valid_from' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$') IS NULL THEN NULL WHEN substr(substring(pv.frontmatter->>'valid_from' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$'), 1, 4)::int < 1000 OR substr(substring(pv.frontmatter->>'valid_from' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$'), 6, 2)::int NOT BETWEEN 1 AND 12 THEN NULL WHEN substr(substring(pv.frontmatter->>'valid_from' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$'), 9, 2)::int BETWEEN 1 AND extract(day from make_date(substr(substring(pv.frontmatter->>'valid_from' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$'), 1, 4)::int, substr(substring(pv.frontmatter->>'valid_from' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$'), 6, 2)::int, 1) + interval '1 month' - interval '1 day')::int THEN substring(pv.frontmatter->>'valid_from' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$') END) AS valid_from, (CASE WHEN substring(pv.frontmatter->>'valid_until' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$') IS NULL THEN NULL WHEN substr(substring(pv.frontmatter->>'valid_until' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$'), 1, 4)::int < 1000 OR substr(substring(pv.frontmatter->>'valid_until' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$'), 6, 2)::int NOT BETWEEN 1 AND 12 THEN NULL WHEN substr(substring(pv.frontmatter->>'valid_until' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$'), 9, 2)::int BETWEEN 1 AND extract(day from make_date(substr(substring(pv.frontmatter->>'valid_until' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$'), 1, 4)::int, substr(substring(pv.frontmatter->>'valid_until' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$'), 6, 2)::int, 1) + interval '1 month' - interval '1 day')::int THEN substring(pv.frontmatter->>'valid_until' from '^([0-9]{4}-[0-9]{2}-[0-9]{2})(?:T00:00:00(?:[.]0+)?(?:Z|[+]00:00))?$') END) AS valid_until FROM page_versions pv JOIN pages p ON p.id = pv.page_id WHERE p.slug = $1 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (NOT (pv.frontmatter ? 'readable_by')) AND (COALESCE(pv.frontmatter->>'visibility', CASE WHEN (pv.type IN ('atom', 'question') OR (pv.type = 'concept' AND pv.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(pv.frontmatter ? 'pinned_question', false) AND NOT (pv.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(pv.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(pv.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT COALESCE(pv.frontmatter ? 'pinned_question', false) AND NOT EXISTS (SELECT 1 FROM needs_rederive elig_nr WHERE elig_nr.derived_table = 'pages' AND elig_nr.derived_id = p.id::text) ORDER BY pv.snapshot_at DESC, pv.id DESC",
+ "textSha256": "377bfc2e8be2f6cdc043ab8d5a12dfcca46a4c3c036176fa712ef578c1cb67ac"
}
],
"limit": [
@@ -569,8 +569,8 @@
"number",
"number"
],
- "sql": "SELECT p.*, to_char(p.updated_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS updated_at_iso FROM pages p WHERE 1=1 AND p.deleted_at IS NULL AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) ORDER BY p.updated_at DESC, p.slug DESC, p.source_id DESC, p.id DESC LIMIT $1 OFFSET $2",
- "textSha256": "0c954eb13a22402e5413e04dde89a7a48f3042cf5edcea875681feaad9539f19"
+ "sql": "SELECT p.*, to_char(p.updated_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS updated_at_iso FROM pages p WHERE 1=1 AND p.deleted_at IS NULL AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) ORDER BY p.updated_at DESC, p.slug DESC, p.source_id DESC, p.id DESC LIMIT $1 OFFSET $2",
+ "textSha256": "4bcd588e7876769c53e44e236ac67bec8bc30e40fde01fa133db5470caa4a12c"
}
],
"includeDeleted": [
@@ -1240,8 +1240,8 @@
"array<string>",
"array<string>"
],
- "sql": "SELECT canonical_slug, source_id FROM slug_aliases WHERE alias_slug = $1 AND source_id = ANY($2::text[]) AND EXISTS (SELECT 1 FROM pages p WHERE p.slug = slug_aliases.canonical_slug AND p.source_id = slug_aliases.source_id AND p.deleted_at IS NULL AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)))) ORDER BY array_position($3::text[], source_id), id",
- "textSha256": "54a662544a92fd21fd6c0d77e5978872c4205b21e6a80e5dbba149a013de002b"
+ "sql": "SELECT canonical_slug, source_id FROM slug_aliases WHERE alias_slug = $1 AND source_id = ANY($2::text[]) AND EXISTS (SELECT 1 FROM pages p WHERE p.slug = slug_aliases.canonical_slug AND p.source_id = slug_aliases.source_id AND p.deleted_at IS NULL AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)))) ORDER BY array_position($3::text[], source_id), id",
+ "textSha256": "051a97956e443b5c74112803ed23838bcabc029b9bc728de7469e2ff0bead0f6"
}
]
},
@@ -1262,8 +1262,8 @@
"params": [
"string"
],
- "sql": "SELECT slug FROM pages WHERE slug = $1 AND deleted_at IS NULL AND ((((pages.page_readers IS NULL AND NOT (pages.frontmatter ? 'readable_by'))) AND (pages.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = pages.source_id AND (starts_with(pages.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR pages.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((pages.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (pages.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(pages.id, pages.source_id, pages.type, pages.frontmatter))) AND ((COALESCE(pages.frontmatter->>'visibility', CASE WHEN (pages.type IN ('atom', 'question') OR (pages.type = 'concept' AND pages.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(pages.frontmatter ? 'pinned_question', false) AND NOT (pages.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(pages.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(pages.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN pages.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = pages.source_id AND derived_origin.slug = ANY(ARRAY[(pages.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=pages.source_id AND renamed.alias_slug=(pages.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=pages.source_id AND moved.old_slug=(pages.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (pages.type IN ('atom', 'question') OR (pages.type = 'concept' AND pages.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = pages.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN pages.type = 'event' AND pages.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = pages.source_id AND chronicle_origin.slug = pages.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(pages.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = pages.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(pages.frontmatter->'derived_from') = 'array' THEN pages.frontmatter->'derived_from' ELSE jsonb_build_array(pages.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)))",
- "textSha256": "9095da6b669647ab0f1b381c2a0dd01d33ec8fefd49be1cd4758962a35c5192b"
+ "sql": "SELECT slug FROM pages WHERE slug = $1 AND deleted_at IS NULL AND ((((pages.page_readers IS NULL AND NOT (pages.frontmatter ? 'readable_by'))) AND (pages.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = pages.source_id AND (starts_with(pages.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR pages.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((pages.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (pages.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(pages.id, pages.source_id, pages.type, pages.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(pages.frontmatter->>'visibility', CASE WHEN (pages.type IN ('atom', 'question') OR (pages.type = 'concept' AND pages.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(pages.frontmatter ? 'pinned_question', false) AND NOT (pages.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(pages.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(pages.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN pages.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = pages.source_id AND derived_origin.slug = ANY(ARRAY[(pages.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=pages.source_id AND renamed.alias_slug=(pages.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=pages.source_id AND moved.old_slug=(pages.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (pages.type IN ('atom', 'question') OR (pages.type = 'concept' AND pages.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = pages.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN pages.type = 'event' AND pages.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = pages.source_id AND chronicle_origin.slug = pages.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(pages.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = pages.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(pages.frontmatter->'derived_from') = 'array' THEN pages.frontmatter->'derived_from' ELSE jsonb_build_array(pages.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)))",
+ "textSha256": "fe94a466dd04ba87d3bf670835db062c5b23915f5875c010d79313cd4eb72919"
},
{
"lane": "pool",
@@ -1272,8 +1272,8 @@
"string",
"string"
],
- "sql": "SELECT slug, similarity(title, $1) AS sim FROM pages WHERE deleted_at IS NULL AND (title % $2 OR slug ILIKE $3) AND ((((pages.page_readers IS NULL AND NOT (pages.frontmatter ? 'readable_by'))) AND (pages.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = pages.source_id AND (starts_with(pages.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR pages.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((pages.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (pages.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(pages.id, pages.source_id, pages.type, pages.frontmatter))) AND ((COALESCE(pages.frontmatter->>'visibility', CASE WHEN (pages.type IN ('atom', 'question') OR (pages.type = 'concept' AND pages.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(pages.frontmatter ? 'pinned_question', false) AND NOT (pages.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(pages.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(pages.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN pages.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = pages.source_id AND derived_origin.slug = ANY(ARRAY[(pages.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=pages.source_id AND renamed.alias_slug=(pages.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=pages.source_id AND moved.old_slug=(pages.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (pages.type IN ('atom', 'question') OR (pages.type = 'concept' AND pages.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = pages.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN pages.type = 'event' AND pages.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = pages.source_id AND chronicle_origin.slug = pages.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(pages.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = pages.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(pages.frontmatter->'derived_from') = 'array' THEN pages.frontmatter->'derived_from' ELSE jsonb_build_array(pages.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) ORDER BY sim DESC LIMIT 5",
- "textSha256": "efd44d0773fd56eeeb46bf16be7aa756c9f2185244d62f6549bc23743901fea1"
+ "sql": "SELECT slug, similarity(title, $1) AS sim FROM pages WHERE deleted_at IS NULL AND (title % $2 OR slug ILIKE $3) AND ((((pages.page_readers IS NULL AND NOT (pages.frontmatter ? 'readable_by'))) AND (pages.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = pages.source_id AND (starts_with(pages.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR pages.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((pages.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (pages.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(pages.id, pages.source_id, pages.type, pages.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(pages.frontmatter->>'visibility', CASE WHEN (pages.type IN ('atom', 'question') OR (pages.type = 'concept' AND pages.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(pages.frontmatter ? 'pinned_question', false) AND NOT (pages.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(pages.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(pages.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN pages.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = pages.source_id AND derived_origin.slug = ANY(ARRAY[(pages.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=pages.source_id AND renamed.alias_slug=(pages.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=pages.source_id AND moved.old_slug=(pages.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (pages.type IN ('atom', 'question') OR (pages.type = 'concept' AND pages.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = pages.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN pages.type = 'event' AND pages.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = pages.source_id AND chronicle_origin.slug = pages.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(pages.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = pages.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(pages.frontmatter->'derived_from') = 'array' THEN pages.frontmatter->'derived_from' ELSE jsonb_build_array(pages.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) ORDER BY sim DESC LIMIT 5",
+ "textSha256": "68ab449411358ba32bc5cb6524c53c23c252b8bbae3d1d91658b21751fee36a1"
}
],
"fuzzy": [
diff --git a/test/fixtures/goldens/sql-text/salience.json b/test/fixtures/goldens/sql-text/salience.json
index f340b4633e..079a87ffe0 100644
--- a/test/fixtures/goldens/sql-text/salience.json
+++ b/test/fixtures/goldens/sql-text/salience.json
@@ -82,8 +82,8 @@
"string",
"string"
],
- "sql": "WITH days AS ( SELECT day::date FROM generate_series( $1::date, $2::date - 1, '1 day'::interval ) AS day ), cohort_keys AS ( SELECT DISTINCT t.tag FROM tags t JOIN pages p ON p.id = t.page_id WHERE p.updated_at >= $3::timestamptz AND p.updated_at < $4::timestamptz AND p.source_id = $5 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.deleted_at IS NULL AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id = p.source_id AND NOT read_source.archived) ), touched AS ( SELECT t.tag, date_trunc('day', p.updated_at)::date AS day, COUNT(DISTINCT p.id) AS cnt FROM tags t JOIN pages p ON p.id = t.page_id WHERE p.updated_at >= $6::timestamptz AND p.updated_at < $7::timestamptz AND p.source_id = $8 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.deleted_at IS NULL AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id = p.source_id AND NOT read_source.archived) GROUP BY 1, 2 ) SELECT cd.tag AS cohort_value, d.day::text AS day, COALESCE(t.cnt, 0)::int AS count FROM cohort_keys cd CROSS JOIN days d LEFT JOIN touched t ON t.tag = cd.tag AND t.day = d.day",
- "textSha256": "8db78164602db88ff92262778d424d74c8effb782ee87ad507f7e05281f0c6f4"
+ "sql": "WITH days AS ( SELECT day::date FROM generate_series( $1::date, $2::date - 1, '1 day'::interval ) AS day ), cohort_keys AS ( SELECT DISTINCT t.tag FROM tags t JOIN pages p ON p.id = t.page_id WHERE p.updated_at >= $3::timestamptz AND p.updated_at < $4::timestamptz AND p.source_id = $5 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.deleted_at IS NULL AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id = p.source_id AND NOT read_source.archived) ), touched AS ( SELECT t.tag, date_trunc('day', p.updated_at)::date AS day, COUNT(DISTINCT p.id) AS cnt FROM tags t JOIN pages p ON p.id = t.page_id WHERE p.updated_at >= $6::timestamptz AND p.updated_at < $7::timestamptz AND p.source_id = $8 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.deleted_at IS NULL AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id = p.source_id AND NOT read_source.archived) GROUP BY 1, 2 ) SELECT cd.tag AS cohort_value, d.day::text AS day, COALESCE(t.cnt, 0)::int AS count FROM cohort_keys cd CROSS JOIN days d LEFT JOIN touched t ON t.tag = cd.tag AND t.day = d.day",
+ "textSha256": "34669ef2219ddc1a304ca63d0b0d20c4823dd90c6a34b5dbe2307e8be3b13019"
},
{
"lane": "pool",
@@ -97,8 +97,8 @@
"string",
"string"
],
- "sql": "WITH days AS ( SELECT day::date FROM generate_series( $1::date, $2::date - 1, '1 day'::interval ) AS day ), cohort_keys AS ( SELECT DISTINCT p.type FROM pages p WHERE p.updated_at >= $3::timestamptz AND p.updated_at < $4::timestamptz AND p.source_id = $5 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.deleted_at IS NULL AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id = p.source_id AND NOT read_source.archived) ), touched AS ( SELECT p.type, date_trunc('day', p.updated_at)::date AS day, COUNT(DISTINCT p.id) AS cnt FROM pages p WHERE p.updated_at >= $6::timestamptz AND p.updated_at < $7::timestamptz AND p.source_id = $8 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.deleted_at IS NULL AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id = p.source_id AND NOT read_source.archived) GROUP BY 1, 2 ) SELECT cd.type AS cohort_value, d.day::text AS day, COALESCE(t.cnt, 0)::int AS count FROM cohort_keys cd CROSS JOIN days d LEFT JOIN touched t ON t.type = cd.type AND t.day = d.day",
- "textSha256": "d5804c5f1e0aab0d03f31757192f8c63b9ba7daf82370515b120bc9ec0a284be"
+ "sql": "WITH days AS ( SELECT day::date FROM generate_series( $1::date, $2::date - 1, '1 day'::interval ) AS day ), cohort_keys AS ( SELECT DISTINCT p.type FROM pages p WHERE p.updated_at >= $3::timestamptz AND p.updated_at < $4::timestamptz AND p.source_id = $5 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.deleted_at IS NULL AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id = p.source_id AND NOT read_source.archived) ), touched AS ( SELECT p.type, date_trunc('day', p.updated_at)::date AS day, COUNT(DISTINCT p.id) AS cnt FROM pages p WHERE p.updated_at >= $6::timestamptz AND p.updated_at < $7::timestamptz AND p.source_id = $8 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.deleted_at IS NULL AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id = p.source_id AND NOT read_source.archived) GROUP BY 1, 2 ) SELECT cd.type AS cohort_value, d.day::text AS day, COALESCE(t.cnt, 0)::int AS count FROM cohort_keys cd CROSS JOIN days d LEFT JOIN touched t ON t.type = cd.type AND t.day = d.day",
+ "textSha256": "3c051be08dc839c460b7208108e89452a910b51546ba7645212105597d0b3644"
},
{
"lane": "pool",
@@ -107,8 +107,8 @@
"string",
"string"
],
- "sql": "SELECT t.tag AS cohort_value, COUNT(DISTINCT p.id)::int AS count, array_agg(DISTINCT p.slug) AS slugs FROM tags t JOIN pages p ON p.id = t.page_id WHERE p.updated_at >= $1::timestamptz AND p.updated_at < $2::timestamptz AND p.source_id = $3 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.deleted_at IS NULL AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id = p.source_id AND NOT read_source.archived) GROUP BY 1",
- "textSha256": "d45a775597c32fa4fa2ff56e01ca929da88b60c33516c6873a2b988bf2042c05"
+ "sql": "SELECT t.tag AS cohort_value, COUNT(DISTINCT p.id)::int AS count, array_agg(DISTINCT p.slug) AS slugs FROM tags t JOIN pages p ON p.id = t.page_id WHERE p.updated_at >= $1::timestamptz AND p.updated_at < $2::timestamptz AND p.source_id = $3 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.deleted_at IS NULL AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id = p.source_id AND NOT read_source.archived) GROUP BY 1",
+ "textSha256": "4ec868cf4cb63c69a5ec73865091de5c640d5d8284f134b0baec0154c4e0a243"
},
{
"lane": "pool",
@@ -117,8 +117,8 @@
"string",
"string"
],
- "sql": "SELECT p.type AS cohort_value, COUNT(DISTINCT p.id)::int AS count, array_agg(DISTINCT p.slug) AS slugs FROM pages p WHERE p.updated_at >= $1::timestamptz AND p.updated_at < $2::timestamptz AND p.source_id = $3 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.deleted_at IS NULL AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id = p.source_id AND NOT read_source.archived) GROUP BY 1",
- "textSha256": "91de0540bfa53717421b954737fb6bc63726fef00ed765540beec40844113e10"
+ "sql": "SELECT p.type AS cohort_value, COUNT(DISTINCT p.id)::int AS count, array_agg(DISTINCT p.slug) AS slugs FROM pages p WHERE p.updated_at >= $1::timestamptz AND p.updated_at < $2::timestamptz AND p.source_id = $3 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.deleted_at IS NULL AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id = p.source_id AND NOT read_source.archived) GROUP BY 1",
+ "textSha256": "4a7d8f476e6d6fb3aea73bfc9895cd1096865250939ad87412e8084007768fbe"
}
],
"sourceIds": [
@@ -196,8 +196,8 @@
"string",
"number"
],
- "sql": "SELECT p.slug, p.source_id, p.title, p.type, p.updated_at, 0 AS emotional_weight, COUNT(DISTINCT t.id) AS take_count, COALESCE(AVG(t.weight), 0) AS take_avg_weight, (0 * 5) + ln(1 + COUNT(DISTINCT t.id)) + (CASE WHEN p.slug LIKE 'media/articles/%' THEN 0.5 * 90.0 / (90.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) WHEN p.slug LIKE 'originals/%' THEN 0.5 * 180.0 / (180.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) WHEN p.slug LIKE 'companies/%' THEN 0.3 * 365.0 / (365.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) WHEN p.slug LIKE 'concepts/%' THEN 0 WHEN p.slug LIKE 'meetings/%' THEN 1 * 60.0 / (60.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) WHEN p.slug LIKE 'writing/%' THEN 0.4 * 365.0 / (365.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) WHEN p.slug LIKE 'media/x/%' THEN 1.5 * 7.0 / (7.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) WHEN p.slug LIKE 'people/%' THEN 0.3 * 365.0 / (365.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) WHEN p.slug LIKE 'daily/%' THEN 1.5 * 14.0 / (14.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) WHEN p.slug LIKE 'deals/%' THEN 0.5 * 180.0 / (180.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) WHEN p.slug LIKE 'chat/%' THEN 1 * 7.0 / (7.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) ELSE 0.3 * 90.0 / (90.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) END) AS score FROM pages p LEFT JOIN takes t ON t.page_id = p.id AND t.active = TRUE AND t.holder = ANY($1::text[]) WHERE p.updated_at >= $2::timestamptz AND p.slug LIKE $3 ESCAPE '\\' AND p.slug NOT LIKE 'briefings/%' AND p.source_id = $4 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.deleted_at IS NULL AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id = p.source_id AND NOT read_source.archived) GROUP BY p.id ORDER BY score DESC LIMIT $5",
- "textSha256": "a7a7399767b684a6fb3424f51474c8c08901d237b6e7884be68b5d25fc9907e0"
+ "sql": "SELECT p.slug, p.source_id, p.title, p.type, p.updated_at, 0 AS emotional_weight, COUNT(DISTINCT t.id) AS take_count, COALESCE(AVG(t.weight), 0) AS take_avg_weight, (0 * 5) + ln(1 + COUNT(DISTINCT t.id)) + (CASE WHEN p.slug LIKE 'media/articles/%' THEN 0.5 * 90.0 / (90.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) WHEN p.slug LIKE 'originals/%' THEN 0.5 * 180.0 / (180.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) WHEN p.slug LIKE 'companies/%' THEN 0.3 * 365.0 / (365.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) WHEN p.slug LIKE 'concepts/%' THEN 0 WHEN p.slug LIKE 'meetings/%' THEN 1 * 60.0 / (60.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) WHEN p.slug LIKE 'writing/%' THEN 0.4 * 365.0 / (365.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) WHEN p.slug LIKE 'media/x/%' THEN 1.5 * 7.0 / (7.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) WHEN p.slug LIKE 'people/%' THEN 0.3 * 365.0 / (365.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) WHEN p.slug LIKE 'daily/%' THEN 1.5 * 14.0 / (14.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) WHEN p.slug LIKE 'deals/%' THEN 0.5 * 180.0 / (180.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) WHEN p.slug LIKE 'chat/%' THEN 1 * 7.0 / (7.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) ELSE 0.3 * 90.0 / (90.0 + EXTRACT(EPOCH FROM (NOW() - COALESCE(p.effective_date, p.updated_at))) / 86400.0) END) AS score FROM pages p LEFT JOIN takes t ON t.page_id = p.id AND t.active = TRUE AND t.holder = ANY($1::text[]) WHERE p.updated_at >= $2::timestamptz AND p.slug LIKE $3 ESCAPE '\\' AND p.slug NOT LIKE 'briefings/%' AND p.source_id = $4 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND p.deleted_at IS NULL AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ? 'quarantine') AND EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id = p.source_id AND NOT read_source.archived) GROUP BY p.id ORDER BY score DESC LIMIT $5",
+ "textSha256": "f13d544e05ae6eec3df6e30e177eb7bd9decf898416895a959f5aca409821dc3"
}
],
"sourceIds": [
diff --git a/test/fixtures/goldens/sql-text/tags.json b/test/fixtures/goldens/sql-text/tags.json
index 5a6a16e57a..422e25d711 100644
--- a/test/fixtures/goldens/sql-text/tags.json
+++ b/test/fixtures/goldens/sql-text/tags.json
@@ -149,8 +149,8 @@
"string",
"string"
],
- "sql": "SELECT DISTINCT tag FROM tags WHERE page_id IN (SELECT id FROM pages WHERE slug = $1 AND source_id = $2 AND ((((pages.page_readers IS NULL AND NOT (pages.frontmatter ? 'readable_by'))) AND (pages.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = pages.source_id AND (starts_with(pages.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR pages.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((pages.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (pages.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(pages.id, pages.source_id, pages.type, pages.frontmatter))) AND ((COALESCE(pages.frontmatter->>'visibility', CASE WHEN (pages.type IN ('atom', 'question') OR (pages.type = 'concept' AND pages.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(pages.frontmatter ? 'pinned_question', false) AND NOT (pages.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(pages.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(pages.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN pages.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = pages.source_id AND derived_origin.slug = ANY(ARRAY[(pages.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=pages.source_id AND renamed.alias_slug=(pages.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=pages.source_id AND moved.old_slug=(pages.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (pages.type IN ('atom', 'question') OR (pages.type = 'concept' AND pages.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = pages.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN pages.type = 'event' AND pages.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = pages.source_id AND chronicle_origin.slug = pages.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(pages.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = pages.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(pages.frontmatter->'derived_from') = 'array' THEN pages.frontmatter->'derived_from' ELSE jsonb_build_array(pages.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND deleted_at IS NULL) ORDER BY tag",
- "textSha256": "05b571f22de48cbeb0078a9e6c3998d29a9444e427387fc78cee7ec90f7b5d47"
+ "sql": "SELECT DISTINCT tag FROM tags WHERE page_id IN (SELECT id FROM pages WHERE slug = $1 AND source_id = $2 AND ((((pages.page_readers IS NULL AND NOT (pages.frontmatter ? 'readable_by'))) AND (pages.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = pages.source_id AND (starts_with(pages.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR pages.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((pages.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (pages.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(pages.id, pages.source_id, pages.type, pages.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(pages.frontmatter->>'visibility', CASE WHEN (pages.type IN ('atom', 'question') OR (pages.type = 'concept' AND pages.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(pages.frontmatter ? 'pinned_question', false) AND NOT (pages.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(pages.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(pages.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN pages.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = pages.source_id AND derived_origin.slug = ANY(ARRAY[(pages.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=pages.source_id AND renamed.alias_slug=(pages.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=pages.source_id AND moved.old_slug=(pages.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (pages.type IN ('atom', 'question') OR (pages.type = 'concept' AND pages.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = pages.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN pages.type = 'event' AND pages.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = pages.source_id AND chronicle_origin.slug = pages.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(pages.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = pages.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(pages.frontmatter->'derived_from') = 'array' THEN pages.frontmatter->'derived_from' ELSE jsonb_build_array(pages.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND deleted_at IS NULL) ORDER BY tag",
+ "textSha256": "822361d3037a3524b4250208eba10b5fcd4447d27622cf2ad8cd61dad67398bd"
}
],
"sourceIds": [
diff --git a/test/fixtures/goldens/sql-text/takes.json b/test/fixtures/goldens/sql-text/takes.json
index 8c8f09561b..c207a0701e 100644
--- a/test/fixtures/goldens/sql-text/takes.json
+++ b/test/fixtures/goldens/sql-text/takes.json
@@ -59,8 +59,8 @@
"number",
"number"
],
- "sql": "WITH binned AS ( SELECT LEAST(FLOOR(weight::numeric / $1::numeric)::int, $2::int)::int AS bucket_idx, weight, (resolved_quality = 'correct')::int AS hit FROM takes WHERE resolved_quality IN ('correct','incorrect') AND holder = $3 AND holder = ANY($4::text[]) AND EXISTS (SELECT 1 FROM pages p WHERE p.id = takes.page_id AND p.source_id = ANY($5::text[])) AND EXISTS (SELECT 1 FROM pages p WHERE p.id = takes.page_id AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)))) ) SELECT (bucket_idx::numeric * $6::numeric)::float AS bucket_lo, ((bucket_idx + 1)::numeric * $7::numeric)::float AS bucket_hi, COUNT(*)::int AS n, AVG(hit)::float AS observed, AVG(weight)::float AS predicted FROM binned GROUP BY bucket_idx ORDER BY bucket_idx",
- "textSha256": "40ca357ea97f344f5fcc6581f3ad337ee5e01f8c321fe128a9327813239a2a61"
+ "sql": "WITH binned AS ( SELECT LEAST(FLOOR(weight::numeric / $1::numeric)::int, $2::int)::int AS bucket_idx, weight, (resolved_quality = 'correct')::int AS hit FROM takes WHERE resolved_quality IN ('correct','incorrect') AND holder = $3 AND holder = ANY($4::text[]) AND EXISTS (SELECT 1 FROM pages p WHERE p.id = takes.page_id AND p.source_id = ANY($5::text[])) AND EXISTS (SELECT 1 FROM pages p WHERE p.id = takes.page_id AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)))) ) SELECT (bucket_idx::numeric * $6::numeric)::float AS bucket_lo, ((bucket_idx + 1)::numeric * $7::numeric)::float AS bucket_hi, COUNT(*)::int AS n, AVG(hit)::float AS observed, AVG(weight)::float AS predicted FROM binned GROUP BY bucket_idx ORDER BY bucket_idx",
+ "textSha256": "f25db10b3f1257a9d7ad4c3c9a428fe0326f2a5b35769551028ca81460f8fc70"
}
],
"default": [
@@ -119,8 +119,8 @@
"array<string>",
"array<string>"
],
- "sql": "SELECT COUNT(*) FILTER (WHERE kind = 'bet')::int AS total_bets, COUNT(*) FILTER (WHERE resolved_quality IN ('correct','incorrect','partial'))::int AS resolved, COUNT(*) FILTER (WHERE resolved_quality = 'correct')::int AS correct, COUNT(*) FILTER (WHERE resolved_quality = 'incorrect')::int AS incorrect, COUNT(*) FILTER (WHERE resolved_quality = 'partial')::int AS partial, COUNT(*) FILTER (WHERE resolved_quality = 'unresolvable')::int AS unresolvable_count, AVG( CASE WHEN resolved_quality IN ('correct','incorrect') THEN POWER(weight - (CASE resolved_quality WHEN 'correct' THEN 1 ELSE 0 END), 2) END )::float AS brier FROM takes WHERE 1=1 AND holder = $1 AND EXISTS (SELECT 1 FROM pages p WHERE p.id = takes.page_id AND p.slug LIKE $2) AND since_date >= $3 AND since_date <= $4 AND holder = ANY($5::text[]) AND EXISTS (SELECT 1 FROM pages p WHERE p.id = takes.page_id AND p.source_id = ANY($6::text[])) AND EXISTS (SELECT 1 FROM pages p WHERE p.id = takes.page_id AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))))",
- "textSha256": "7d9b44e4e4f829563ddf3b0806071d6d5a6f5a521ac02623b7735188be69940d"
+ "sql": "SELECT COUNT(*) FILTER (WHERE kind = 'bet')::int AS total_bets, COUNT(*) FILTER (WHERE resolved_quality IN ('correct','incorrect','partial'))::int AS resolved, COUNT(*) FILTER (WHERE resolved_quality = 'correct')::int AS correct, COUNT(*) FILTER (WHERE resolved_quality = 'incorrect')::int AS incorrect, COUNT(*) FILTER (WHERE resolved_quality = 'partial')::int AS partial, COUNT(*) FILTER (WHERE resolved_quality = 'unresolvable')::int AS unresolvable_count, AVG( CASE WHEN resolved_quality IN ('correct','incorrect') THEN POWER(weight - (CASE resolved_quality WHEN 'correct' THEN 1 ELSE 0 END), 2) END )::float AS brier FROM takes WHERE 1=1 AND holder = $1 AND EXISTS (SELECT 1 FROM pages p WHERE p.id = takes.page_id AND p.slug LIKE $2) AND since_date >= $3 AND since_date <= $4 AND holder = ANY($5::text[]) AND EXISTS (SELECT 1 FROM pages p WHERE p.id = takes.page_id AND p.source_id = ANY($6::text[])) AND EXISTS (SELECT 1 FROM pages p WHERE p.id = takes.page_id AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))))",
+ "textSha256": "72b3530a0643f20fd0222fd898665ab65ec086136168584abf7a28369d918d9c"
}
],
"default": [
@@ -298,8 +298,8 @@
"number",
"number"
],
- "sql": "SELECT t.*, p.slug AS page_slug FROM takes t JOIN pages p ON p.id = t.page_id WHERE 1=1 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND ($1::int IS NULL OR t.page_id = $2::int) AND ($3::text IS NULL OR p.slug = $4::text) AND ($5::text IS NULL OR t.holder = $6::text) AND ($7::text IS NULL OR t.kind = $8::text) AND ($9::boolean IS NULL OR t.active = $10::boolean) AND ( $11::boolean IS NULL OR ($12::boolean = true AND t.resolved_at IS NOT NULL) OR ($13::boolean = false AND t.resolved_at IS NULL) ) AND ( $14::text[] IS NULL OR t.holder = ANY($15::text[]) ) AND ($16::text IS NULL OR (t.since_date IS NOT NULL AND NOT ( t.since_date ~ '^[0-9]{4}-[0-9]{2}(-[0-9]{2})?$' AND (CASE WHEN length(t.since_date) = 7 THEN t.since_date || '-15' ELSE t.since_date END) > $17::text))) AND p.source_id = ANY($18::text[]) ORDER BY CASE WHEN $19 = 'since_date' AND $20::boolean THEN t.since_date END ASC NULLS LAST, CASE WHEN $21 = 'weight' THEN t.weight END DESC NULLS LAST, CASE WHEN $22 = 'since_date' AND NOT $23::boolean THEN t.since_date END DESC NULLS LAST, CASE WHEN $24 = 'created_at' THEN t.created_at END DESC NULLS LAST, t.id DESC LIMIT $25 OFFSET $26",
- "textSha256": "848097224c102606b9c68ada004441d11d2a33df8b271b7e7161ec5ac475453c"
+ "sql": "SELECT t.*, p.slug AS page_slug FROM takes t JOIN pages p ON p.id = t.page_id WHERE 1=1 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND ($1::int IS NULL OR t.page_id = $2::int) AND ($3::text IS NULL OR p.slug = $4::text) AND ($5::text IS NULL OR t.holder = $6::text) AND ($7::text IS NULL OR t.kind = $8::text) AND ($9::boolean IS NULL OR t.active = $10::boolean) AND ( $11::boolean IS NULL OR ($12::boolean = true AND t.resolved_at IS NOT NULL) OR ($13::boolean = false AND t.resolved_at IS NULL) ) AND ( $14::text[] IS NULL OR t.holder = ANY($15::text[]) ) AND ($16::text IS NULL OR (t.since_date IS NOT NULL AND NOT ( t.since_date ~ '^[0-9]{4}-[0-9]{2}(-[0-9]{2})?$' AND (CASE WHEN length(t.since_date) = 7 THEN t.since_date || '-15' ELSE t.since_date END) > $17::text))) AND p.source_id = ANY($18::text[]) ORDER BY CASE WHEN $19 = 'since_date' AND $20::boolean THEN t.since_date END ASC NULLS LAST, CASE WHEN $21 = 'weight' THEN t.weight END DESC NULLS LAST, CASE WHEN $22 = 'since_date' AND NOT $23::boolean THEN t.since_date END DESC NULLS LAST, CASE WHEN $24 = 'created_at' THEN t.created_at END DESC NULLS LAST, t.id DESC LIMIT $25 OFFSET $26",
+ "textSha256": "a65001f12504e1561fc413f1d704ab171565411dd2742ad2e6ad8ea1542256c5"
}
]
},
@@ -402,8 +402,8 @@
"array<string>",
"number"
],
- "sql": "SELECT t.id AS take_id, t.page_id, p.slug AS page_slug, t.row_num, t.claim, t.kind, t.holder, t.weight, t.since_date, t.until_date, t.source, word_similarity($1, t.claim)::real AS score FROM takes t JOIN pages p ON p.id = t.page_id WHERE t.active AND $2 <% t.claim AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND ( $3::text[] IS NULL OR t.holder = ANY($4::text[]) ) AND p.source_id = ANY($5::text[]) ORDER BY score DESC, t.weight DESC LIMIT $6",
- "textSha256": "6b95e6b837edfb99616fb7068cdc0839da3e21553d5fc7dc576999eefdddf852"
+ "sql": "SELECT t.id AS take_id, t.page_id, p.slug AS page_slug, t.row_num, t.claim, t.kind, t.holder, t.weight, t.since_date, t.until_date, t.source, word_similarity($1, t.claim)::real AS score FROM takes t JOIN pages p ON p.id = t.page_id WHERE t.active AND $2 <% t.claim AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND ( $3::text[] IS NULL OR t.holder = ANY($4::text[]) ) AND p.source_id = ANY($5::text[]) ORDER BY score DESC, t.weight DESC LIMIT $6",
+ "textSha256": "d3d059cd33eedf4ef62a68b8d394be14d8a68004cd621b4f3b93f044e421d943"
}
]
},
@@ -448,8 +448,8 @@
"string",
"number"
],
- "sql": "SELECT t.id AS take_id, t.page_id, p.slug AS page_slug, t.row_num, t.claim, t.kind, t.holder, t.weight, t.since_date, t.until_date, t.source, (1 - (t.embedding <=> $1::vector))::real AS score FROM takes t JOIN pages p ON p.id = t.page_id WHERE t.active AND t.embedding IS NOT NULL AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND ( $2::text[] IS NULL OR t.holder = ANY($3::text[]) ) AND p.source_id = ANY($4::text[]) ORDER BY t.embedding <=> $5::vector LIMIT $6",
- "textSha256": "22a8826e8ac7c39545ad25049e07d681f0a92cb41d37c88a8f20116311a48d66"
+ "sql": "SELECT t.id AS take_id, t.page_id, p.slug AS page_slug, t.row_num, t.claim, t.kind, t.holder, t.weight, t.since_date, t.until_date, t.source, (1 - (t.embedding <=> $1::vector))::real AS score FROM takes t JOIN pages p ON p.id = t.page_id WHERE t.active AND t.embedding IS NOT NULL AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND ( $2::text[] IS NULL OR t.holder = ANY($3::text[]) ) AND p.source_id = ANY($4::text[]) ORDER BY t.embedding <=> $5::vector LIMIT $6",
+ "textSha256": "74dd9cf413c73d7aeec96e102a70336de40c2cbd4d29f7ee07520bfaafa9dbda"
}
]
},
diff --git a/test/fixtures/goldens/sql-text/timeline.json b/test/fixtures/goldens/sql-text/timeline.json
index b38e459728..89bbeaf23d 100644
--- a/test/fixtures/goldens/sql-text/timeline.json
+++ b/test/fixtures/goldens/sql-text/timeline.json
@@ -137,8 +137,8 @@
"string",
"number"
],
- "sql": "SELECT te.* FROM sources s CROSS JOIN LATERAL (SELECT * FROM pages WHERE source_id = s.id AND slug = $1 OFFSET 0) p JOIN timeline_entries te ON te.page_id = p.id WHERE p.slug = $2 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (te.event_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages event_private WHERE event_private.id = te.event_page_id AND ((((event_private.page_readers IS NULL AND NOT (event_private.frontmatter ? 'readable_by'))) AND (event_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = event_private.source_id AND (starts_with(event_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR event_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((event_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (event_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(event_private.id, event_private.source_id, event_private.type, event_private.frontmatter))) AND ((COALESCE(event_private.frontmatter->>'visibility', CASE WHEN (event_private.type IN ('atom', 'question') OR (event_private.type = 'concept' AND event_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(event_private.frontmatter ? 'pinned_question', false) AND NOT (event_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(event_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(event_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN event_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = event_private.source_id AND derived_origin.slug = ANY(ARRAY[(event_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=event_private.source_id AND renamed.alias_slug=(event_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=event_private.source_id AND moved.old_slug=(event_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (event_private.type IN ('atom', 'question') OR (event_private.type = 'concept' AND event_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = event_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN event_private.type = 'event' AND event_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = event_private.source_id AND chronicle_origin.slug = event_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(event_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = event_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(event_private.frontmatter->'derived_from') = 'array' THEN event_private.frontmatter->'derived_from' ELSE jsonb_build_array(event_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) ORDER BY te.date DESC, te.id DESC LIMIT $3",
- "textSha256": "0529b5b90d3eea5e1ad364cc39e2319affcef043d2936e2db2c45d95c82c73d7"
+ "sql": "SELECT te.* FROM sources s CROSS JOIN LATERAL (SELECT * FROM pages WHERE source_id = s.id AND slug = $1 OFFSET 0) p JOIN timeline_entries te ON te.page_id = p.id WHERE p.slug = $2 AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (te.event_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages event_private WHERE event_private.id = te.event_page_id AND ((((event_private.page_readers IS NULL AND NOT (event_private.frontmatter ? 'readable_by'))) AND (event_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = event_private.source_id AND (starts_with(event_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR event_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((event_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (event_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(event_private.id, event_private.source_id, event_private.type, event_private.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(event_private.frontmatter->>'visibility', CASE WHEN (event_private.type IN ('atom', 'question') OR (event_private.type = 'concept' AND event_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(event_private.frontmatter ? 'pinned_question', false) AND NOT (event_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(event_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(event_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN event_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = event_private.source_id AND derived_origin.slug = ANY(ARRAY[(event_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=event_private.source_id AND renamed.alias_slug=(event_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=event_private.source_id AND moved.old_slug=(event_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (event_private.type IN ('atom', 'question') OR (event_private.type = 'concept' AND event_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = event_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN event_private.type = 'event' AND event_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = event_private.source_id AND chronicle_origin.slug = event_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(event_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = event_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(event_private.frontmatter->'derived_from') = 'array' THEN event_private.frontmatter->'derived_from' ELSE jsonb_build_array(event_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) ORDER BY te.date DESC, te.id DESC LIMIT $3",
+ "textSha256": "4d7180630b43faadb95219fa617177b2285a54a571111bc4e263722d47e76e56"
}
],
"sourceId": [
@@ -189,8 +189,8 @@
"string",
"number"
],
- "sql": "SELECT te.date::text AS date, te.summary, te.detail, te.source, te.trust_tier, te.page_id, p.slug AS page_slug, te.event_page_id, ep.slug AS event_slug, ep.effective_date::text AS effective_date, ep.frontmatter->'event'->>'kind' AS kind FROM timeline_entries te JOIN pages p ON p.id = te.page_id AND p.deleted_at IS NULL LEFT JOIN pages ep ON ep.id = te.event_page_id WHERE te.date >= $1::date AND te.date <= $2::date AND (te.event_page_id IS NULL OR ep.deleted_at IS NULL) AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (te.event_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages event_private WHERE event_private.id = te.event_page_id AND ((((event_private.page_readers IS NULL AND NOT (event_private.frontmatter ? 'readable_by'))) AND (event_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = event_private.source_id AND (starts_with(event_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR event_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((event_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (event_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(event_private.id, event_private.source_id, event_private.type, event_private.frontmatter))) AND ((COALESCE(event_private.frontmatter->>'visibility', CASE WHEN (event_private.type IN ('atom', 'question') OR (event_private.type = 'concept' AND event_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(event_private.frontmatter ? 'pinned_question', false) AND NOT (event_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(event_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(event_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN event_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = event_private.source_id AND derived_origin.slug = ANY(ARRAY[(event_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=event_private.source_id AND renamed.alias_slug=(event_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=event_private.source_id AND moved.old_slug=(event_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (event_private.type IN ('atom', 'question') OR (event_private.type = 'concept' AND event_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = event_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN event_private.type = 'event' AND event_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = event_private.source_id AND chronicle_origin.slug = event_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(event_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = event_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(event_private.frontmatter->'derived_from') = 'array' THEN event_private.frontmatter->'derived_from' ELSE jsonb_build_array(event_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) ORDER BY COALESCE(ep.effective_date, te.date::timestamptz) ASC, te.id ASC LIMIT $3",
- "textSha256": "e74cfa80c86eaa6dc36b15253a4949eff905c7baeddb2ece691de1729c8448e4"
+ "sql": "SELECT te.date::text AS date, te.summary, te.detail, te.source, te.trust_tier, te.page_id, p.slug AS page_slug, te.event_page_id, ep.slug AS event_slug, ep.effective_date::text AS effective_date, ep.frontmatter->'event'->>'kind' AS kind FROM timeline_entries te JOIN pages p ON p.id = te.page_id AND p.deleted_at IS NULL LEFT JOIN pages ep ON ep.id = te.event_page_id WHERE te.date >= $1::date AND te.date <= $2::date AND (te.event_page_id IS NULL OR ep.deleted_at IS NULL) AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (te.event_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages event_private WHERE event_private.id = te.event_page_id AND ((((event_private.page_readers IS NULL AND NOT (event_private.frontmatter ? 'readable_by'))) AND (event_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = event_private.source_id AND (starts_with(event_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR event_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((event_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (event_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(event_private.id, event_private.source_id, event_private.type, event_private.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(event_private.frontmatter->>'visibility', CASE WHEN (event_private.type IN ('atom', 'question') OR (event_private.type = 'concept' AND event_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(event_private.frontmatter ? 'pinned_question', false) AND NOT (event_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(event_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(event_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN event_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = event_private.source_id AND derived_origin.slug = ANY(ARRAY[(event_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=event_private.source_id AND renamed.alias_slug=(event_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=event_private.source_id AND moved.old_slug=(event_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (event_private.type IN ('atom', 'question') OR (event_private.type = 'concept' AND event_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = event_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN event_private.type = 'event' AND event_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = event_private.source_id AND chronicle_origin.slug = event_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(event_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = event_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(event_private.frontmatter->'derived_from') = 'array' THEN event_private.frontmatter->'derived_from' ELSE jsonb_build_array(event_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) ORDER BY COALESCE(ep.effective_date, te.date::timestamptz) ASC, te.id ASC LIMIT $3",
+ "textSha256": "9d78eeb9f902a1e2560f3923a5e0025b0ec4daadb391f5007cc18f6db4f2728f"
}
],
"sourceIds+excludePrivate": [
@@ -203,8 +203,8 @@
"array<string>",
"number"
],
- "sql": "SELECT te.date::text AS date, te.summary, te.detail, te.source, te.trust_tier, te.page_id, p.slug AS page_slug, te.event_page_id, ep.slug AS event_slug, ep.effective_date::text AS effective_date, ep.frontmatter->'event'->>'kind' AS kind FROM timeline_entries te JOIN pages p ON p.id = te.page_id AND p.deleted_at IS NULL LEFT JOIN pages ep ON ep.id = te.event_page_id AND ep.source_id = ANY($1::text[]) WHERE te.date >= $2::date AND te.date <= $3::date AND (te.event_page_id IS NULL OR ep.deleted_at IS NULL) AND p.source_id = ANY($4::text[]) AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (te.event_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages event_private WHERE event_private.id = te.event_page_id AND ((((event_private.page_readers IS NULL AND NOT (event_private.frontmatter ? 'readable_by'))) AND (event_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = event_private.source_id AND (starts_with(event_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR event_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((event_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (event_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(event_private.id, event_private.source_id, event_private.type, event_private.frontmatter))) AND ((COALESCE(event_private.frontmatter->>'visibility', CASE WHEN (event_private.type IN ('atom', 'question') OR (event_private.type = 'concept' AND event_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(event_private.frontmatter ? 'pinned_question', false) AND NOT (event_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(event_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(event_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN event_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = event_private.source_id AND derived_origin.slug = ANY(ARRAY[(event_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=event_private.source_id AND renamed.alias_slug=(event_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=event_private.source_id AND moved.old_slug=(event_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (event_private.type IN ('atom', 'question') OR (event_private.type = 'concept' AND event_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = event_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN event_private.type = 'event' AND event_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = event_private.source_id AND chronicle_origin.slug = event_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(event_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = event_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(event_private.frontmatter->'derived_from') = 'array' THEN event_private.frontmatter->'derived_from' ELSE jsonb_build_array(event_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) ORDER BY COALESCE(ep.effective_date, te.date::timestamptz) ASC, te.id ASC LIMIT $5",
- "textSha256": "ca3b75bc104047517726d92bce6905e9485eef86577d15454d4385a6f21b977c"
+ "sql": "SELECT te.date::text AS date, te.summary, te.detail, te.source, te.trust_tier, te.page_id, p.slug AS page_slug, te.event_page_id, ep.slug AS event_slug, ep.effective_date::text AS effective_date, ep.frontmatter->'event'->>'kind' AS kind FROM timeline_entries te JOIN pages p ON p.id = te.page_id AND p.deleted_at IS NULL LEFT JOIN pages ep ON ep.id = te.event_page_id AND ep.source_id = ANY($1::text[]) WHERE te.date >= $2::date AND te.date <= $3::date AND (te.event_page_id IS NULL OR ep.deleted_at IS NULL) AND p.source_id = ANY($4::text[]) AND ((((p.page_readers IS NULL AND NOT (p.frontmatter ? 'readable_by'))) AND (p.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = p.source_id AND (starts_with(p.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR p.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((p.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (p.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(p.id, p.source_id, p.type, p.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(p.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(p.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = ANY(ARRAY[(p.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=p.source_id AND renamed.alias_slug=(p.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=p.source_id AND moved.old_slug=(p.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) AND (te.event_page_id IS NULL OR EXISTS ( SELECT 1 FROM pages event_private WHERE event_private.id = te.event_page_id AND ((((event_private.page_readers IS NULL AND NOT (event_private.frontmatter ? 'readable_by'))) AND (event_private.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = event_private.source_id AND (starts_with(event_private.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR event_private.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((event_private.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (event_private.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(event_private.id, event_private.source_id, event_private.type, event_private.frontmatter)) AND NOT EXISTS (SELECT 1 FROM sources read_source WHERE read_source.id >= '' AND (read_source.config->>'kind' IN ('imessage') OR read_source.config->>'owner_only' = 'true'))) AND ((COALESCE(event_private.frontmatter->>'visibility', CASE WHEN (event_private.type IN ('atom', 'question') OR (event_private.type = 'concept' AND event_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(event_private.frontmatter ? 'pinned_question', false) AND NOT (event_private.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(event_private.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(event_private.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN event_private.type = 'atom' THEN (EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = event_private.source_id AND derived_origin.slug = ANY(ARRAY[(event_private.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=event_private.source_id AND renamed.alias_slug=(event_private.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=event_private.source_id AND moved.old_slug=(event_private.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private')) WHEN (event_private.type IN ('atom', 'question') OR (event_private.type = 'concept' AND event_private.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = event_private.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = ANY(ARRAY[(derived_input.frontmatter->>'source_slug'), (SELECT renamed.canonical_slug FROM slug_aliases renamed WHERE renamed.source_id=derived_input.source_id AND renamed.alias_slug=(derived_input.frontmatter->>'source_slug') AND renamed.notes='rename')]) AND derived_input_origin.frontmatter->>'visibility' = 'private') OR EXISTS (SELECT 1 FROM slug_rename_history moved JOIN pages moved_to ON moved_to.source_id=moved.source_id AND moved_to.slug=moved.new_slug WHERE moved.source_id=derived_input.source_id AND moved.old_slug=(derived_input.frontmatter->>'source_slug') AND moved_to.frontmatter->>'visibility'='private'))) WHEN event_private.type = 'event' AND event_private.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = event_private.source_id AND chronicle_origin.slug = event_private.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(event_private.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = event_private.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(event_private.frontmatter->'derived_from') = 'array' THEN event_private.frontmatter->'derived_from' ELSE jsonb_build_array(event_private.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))) )) ORDER BY COALESCE(ep.effective_date, te.date::timestamptz) ASC, te.id ASC LIMIT $5",
+ "textSha256": "8adc91e69e73f4c2da7713fb5578aec4147caee04566c134c22db5971fa0d71d"
}
],
"week+sourceId": [
diff --git a/test/git-commit-push-credential-refused-gst2961.serial.test.ts b/test/git-commit-push-credential-refused-gst2961.serial.test.ts
new file mode 100644
index 0000000000..764f6fbe97
--- /dev/null
+++ b/test/git-commit-push-credential-refused-gst2961.serial.test.ts
@@ -0,0 +1,355 @@
+/**
+ * GST-2961: a push the Git host refuses for the credential git used ("Repository not found", HTTP 404, or HTTP 403)
+ * is a credential fault, not a transient one. `gbrain git commit-push` stops at once with push_credential_refused
+ * (exit 1, not retryable), names the credential helpers git asked in order with their scope and file, which one
+ * answered and its login, and never the secret; the refusal is recorded until a push lands, where doctor's
+ * git_convergence and put_page's lastPushStatus read it. A dropped connection keeps the retry it had before.
+ *
+ * Real git against a local smart-HTTP stub (test/fixtures/git-credential-stub/server.ts) with fake credential
+ * helpers; no network and no real tokens. The machine-wide helper answers first with another account's canary
+ * token, the shape of the incident.
+ */
+import { afterAll, beforeAll, describe, expect, spyOn, test } from 'bun:test';
+import { execFileSync, spawn, spawnSync, type ChildProcess } from 'node:child_process';
+import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join, resolve } from 'node:path';
+import { credentialHelperKeysArgv, credentialRefusal } from '../src/core/git/push-credential.ts';
+import { readCredentialRefusal } from '../src/core/git/commit-push.ts';
+import { getLastPushOutcome } from '../src/core/brain-repo-durability.ts';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import { gitConvergenceCheck } from '../src/commands/doctor/checks/git-convergence.ts';
+import { runAccessRules } from '../src/commands/access-rules.ts';
+import { policyStatus } from '../src/core/access/policy.ts';
+import { withEnv } from './helpers/with-env.ts';
+
+const CANARY = 'CANARY-gst2961-global-not-a-real-token';
+const LOCAL_SECRET = 'CANARY-gst2961-local-not-a-real-token';
+const INLINE_SECRET = 'CANARY-gst2961-inline-not-a-real-token';
+const CLI = resolve(import.meta.dir, '../src/cli.ts');
+
+let dir: string;
+let server: ChildProcess;
+let port = 0;
+let globalConfig: string;
+let home: string;
+
+function git(cwd: string, args: string[], env: Record<string, string> = {}): string {
+ return execFileSync('git', ['-C', cwd, '-c', 'protocol.file.allow=always', ...args], {
+ stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf8', env: { ...process.env, GIT_CONFIG_GLOBAL: globalConfig, GIT_CONFIG_NOSYSTEM: '1', ...env } }).trim();
+}
+
+const env = (extra: Record<string, string> = {}) => ({ ...process.env, GBRAIN_HOME: home, GIT_CONFIG_GLOBAL: globalConfig, GIT_CONFIG_NOSYSTEM: '1', GIT_TERMINAL_PROMPT: '0', ...extra });
+
+async function count(mode: string): Promise<number> {
+ return Number(await (await fetch('http://127.0.0.1:' + port + '/__count/' + mode)).text());
+}
+
+function writeHelper(name: string, user: string, secret: string, silentVar?: string): string {
+ const path = join(dir, name);
+ writeFileSync(path, '#!/bin/sh\n[ "$1" = get ] || exit 0\ncat >/dev/null\n' + (silentVar ? '[ -n "$' + silentVar + '" ] && exit 0\n' : '') + 'echo username=' + user + '\necho password=' + secret + '\n');
+ chmodSync(path, 0o755);
+ return path;
+}
+
+/** A checkout of a fresh bare repository served under /<mode>/, with its own helper, one commit ahead of the remote. */
+function checkout(name: string, mode: string): string {
+ const bare = join(dir, 'srv', name + '.git');
+ execFileSync('git', ['init', '-q', '--bare', '-b', 'main', bare]);
+ const work = join(dir, name);
+ git(dir, ['clone', '-q', bare, work]);
+ git(work, ['config', 'user.email', '[email protected]']);
+ git(work, ['config', 'user.name', 'a']);
+ writeFileSync(join(work, 'x.md'), 'one\n');
+ git(work, ['add', 'x.md']); git(work, ['commit', '-qm', 'seed']); git(work, ['push', '-q', '-u', 'origin', 'main']);
+ git(work, ['config', 'credential.helper', join(dir, 'helper-local.sh')]);
+ git(work, ['remote', 'set-url', 'origin', 'http://127.0.0.1:' + port + '/' + mode + '/' + name + '.git']);
+ writeFileSync(join(work, 'x.md'), 'two\n');
+ git(work, ['commit', '-qam', 'unpushed']);
+ return work;
+}
+
+function setMode(work: string, mode: string) {
+ const name = work.slice(work.lastIndexOf('/') + 1);
+ git(work, ['remote', 'set-url', 'origin', 'http://127.0.0.1:' + port + '/' + mode + '/' + name + '.git']);
+}
+
+function commitPush(work: string, extra: Record<string, string> = {}) {
+ const run = spawnSync(process.execPath, [CLI, 'git', 'commit-push', '--push-only', '--path', work, '--json'], { encoding: 'utf8', env: env(extra), timeout: 120_000 });
+ let doc: Record<string, unknown> = {};
+ try { doc = JSON.parse(run.stdout); } catch { /* asserted below */ }
+ return { status: run.status, stdout: run.stdout, stderr: run.stderr, doc };
+}
+
+/** How many receive-pack requests one plain git push makes against this mode, so attempt counts compare across git versions. */
+async function onePlainPush(work: string, mode: string): Promise<number> {
+ const before = await count(mode);
+ spawnSync('git', ['-C', work, 'push', 'origin', 'main'], { env: env(), stdio: 'ignore' });
+ return (await count(mode)) - before;
+}
+
+/** Every file gbrain could have written for this run: stdout, stderr, the push log and anything under the git dir it owns. */
+function everythingWritten(work: string, run: { stdout: string; stderr: string }): string {
+ const files = [join(home, '.gbrain', 'brain-push.log'), ...readdirSync(join(work, '.git')).filter(f => f.startsWith('brain-')).map(f => join(work, '.git', f))];
+ return [run.stdout, run.stderr, ...files.filter(f => existsSync(f) && statSync(f).isFile()).map(f => readFileSync(f, 'utf8'))].join('\n');
+}
+
+beforeAll(async () => {
+ dir = mkdtempSync(join(tmpdir(), 'gst2961-'));
+ home = join(dir, 'home');
+ mkdirSync(home);
+ mkdirSync(join(dir, 'srv'));
+ globalConfig = join(dir, 'global.gitconfig');
+ writeHelper('helper-global.sh', 'user-b', CANARY, 'GLOBAL_HELPER_SILENT');
+ writeHelper('helper-local.sh', 'user-a', LOCAL_SECRET);
+ writeFileSync(globalConfig, '[credential]\n\thelper = ' + join(dir, 'helper-global.sh') + '\n');
+ server = spawn(process.execPath, [resolve(import.meta.dir, 'fixtures/git-credential-stub/server.ts'), join(dir, 'srv')], { stdio: ['ignore', 'pipe', 'inherit'] });
+ port = await new Promise<number>((done, fail) => {
+ server.stdout!.once('data', chunk => done(Number(String(chunk).trim())));
+ server.once('exit', code => fail(new Error('stub server exited ' + code)));
+ });
+});
+
+afterAll(() => {
+ server?.kill('SIGKILL');
+ rmSync(dir, { recursive: true, force: true });
+});
+
+describe('credentialRefusal', () => {
+ test('404 and 403 texts are credential refusals; transient and other push failures are not', () => {
+ expect(credentialRefusal("remote: Repository not found.\nfatal: repository 'https://git.example/acme-example/brain.git/' not found\n")).toBe('not_found');
+ expect(credentialRefusal('ERROR: Repository not found.\nfatal: Could not read from remote repository.\n')).toBe('not_found');
+ expect(credentialRefusal("fatal: unable to access 'https://git.example/x.git/': The requested URL returned error: 404\n")).toBe('not_found');
+ expect(credentialRefusal("remote: Permission to acme-example/brain.git denied to user-b.\nfatal: unable to access 'https://git.example/x.git/': The requested URL returned error: 403\n")).toBe('forbidden');
+ expect(credentialRefusal('ERROR: Permission to acme-example/brain.git denied to user-b.\n')).toBe('forbidden');
+ for (const transient of [
+ "fatal: unable to access 'https://git.example/x.git/': The requested URL returned error: 502\n",
+ "fatal: unable to access 'https://git.example/x.git/': Could not resolve host: git.example\n",
+ 'error: RPC failed; curl 56 Recv failure: Connection reset by peer\nfatal: the remote end hung up unexpectedly\n',
+ " ! [rejected] main -> main (fetch first)\nerror: failed to push some refs to 'https://git.example/x.git'\n",
+ " ! [remote rejected] main -> main (protected branch hook declined)\n",
+ ]) expect(credentialRefusal(transient)).toBeNull();
+ });
+});
+
+describe('gbrain git commit-push against a host that refuses the credential', () => {
+ for (const [mode, kind, words] of [['notfound', 'not_found', 'Repository not found'], ['forbidden', 'forbidden', 'HTTP 403']] as const) {
+ test(mode + ': exit 1, push_credential_refused, one attempt, names the helper and login, never the secret', async () => {
+ const work = checkout('brain-' + mode, mode);
+ const plain = await onePlainPush(work, mode);
+ const before = await count(mode);
+ const run = commitPush(work);
+ expect(run.status).toBe(1);
+ expect(run.doc.code).toBe('push_credential_refused');
+ expect(run.doc.retryable).toBe(false);
+ expect(run.doc.reason).toBe(kind);
+ expect(String(run.doc.message)).toContain(words);
+ expect(String(run.doc.message)).toContain(join(dir, 'helper-global.sh'));
+ expect(String(run.doc.message)).toContain('(global, file:' + globalConfig + ')');
+ expect(String(run.doc.message)).toContain('user-b');
+ expect((run.doc.fix as { next?: string }).next).toBe('tell_user_to_run');
+ expect((await count(mode)) - before).toBe(plain);
+ const written = everythingWritten(work, run);
+ expect(written).not.toContain(CANARY);
+ expect(written).not.toContain(LOCAL_SECRET);
+ const state = readCredentialRefusal(work);
+ expect(state?.kind).toBe(kind);
+ expect(state?.username).toBe('user-b');
+ expect(state?.helpers).toEqual([{ helper: join(dir, 'helper-global.sh'), scope: 'global', origin: 'file:' + globalConfig, answered: true }]);
+ expect(readFileSync(join(home, '.gbrain', 'brain-push.log'), 'utf8')).toContain('push_credential_refused');
+ expect(getLastPushOutcome('main', work)).toMatchObject({ status: 'needs_attention' });
+ expect(getLastPushOutcome('main', work).detail).toContain('push_credential_refused');
+ }, 120_000);
+ }
+
+ test('lists every helper git asked, in order, when the first one stays silent', () => {
+ const work = checkout('brain-order', 'forbidden');
+ const run = commitPush(work, { GLOBAL_HELPER_SILENT: '1' });
+ expect(run.doc.code).toBe('push_credential_refused');
+ expect(readCredentialRefusal(work)?.helpers).toEqual([
+ { helper: join(dir, 'helper-global.sh'), scope: 'global', origin: 'file:' + globalConfig, answered: false },
+ { helper: join(dir, 'helper-local.sh'), scope: 'local', origin: 'file:.git/config', answered: true },
+ ]);
+ expect(String(run.doc.message)).toContain('user-a');
+ expect(everythingWritten(work, run)).not.toContain(LOCAL_SECRET);
+ }, 120_000);
+
+ test('an inline helper whose body holds the token is shown by its program only', () => {
+ const work = checkout('brain-inline', 'forbidden');
+ const inlineConfig = join(dir, 'inline.gitconfig');
+ writeFileSync(inlineConfig, '[credential]\n\thelper = "!f() { cat >/dev/null; echo username=user-c; echo password=' + INLINE_SECRET + '; }; f"\n');
+ const run = commitPush(work, { GIT_CONFIG_GLOBAL: inlineConfig });
+ expect(run.doc.code).toBe('push_credential_refused');
+ expect(readCredentialRefusal(work)?.helpers[0]).toMatchObject({ helper: 'an inline shell helper', scope: 'global', answered: true });
+ expect(everythingWritten(work, run)).not.toContain(INLINE_SECRET);
+ const argv = (run.doc.fix as { argv: string[] }).argv;
+ expect(argv).toEqual(credentialHelperKeysArgv(work));
+ const listed = execFileSync(argv[0]!, argv.slice(1), { encoding: 'utf8', env: env({ GIT_CONFIG_GLOBAL: inlineConfig }) });
+ expect(listed).toContain('credential.helper');
+ expect(listed).toContain(inlineConfig);
+ expect(listed).not.toContain(INLINE_SECRET);
+ }, 120_000);
+
+ test('a dropped connection is still push_unconfirmed (exit 4) and keeps its retry', async () => {
+ const work = checkout('brain-drop', 'drop');
+ const plain = await onePlainPush(work, 'drop');
+ const before = await count('drop');
+ const run = commitPush(work);
+ expect(run.status).toBe(4);
+ expect(run.doc.code).toBe('push_unconfirmed');
+ expect(run.doc.retryable).toBe(true);
+ expect((await count('drop')) - before).toBe(2 * plain);
+ expect(readCredentialRefusal(work)).toBeNull();
+ }, 120_000);
+
+ test('a token in the remote URL or given as the username never reaches the error, the push log or the state file', async () => {
+ const URL_TOKEN = 'CANARY-gst2961-url-token-not-real';
+ const USER_TOKEN = 'gho_CANARYgst2961helperusernotreal';
+ const passwordOnly = join(dir, 'helper-password-only.sh');
+ writeFileSync(passwordOnly, '#!/bin/sh\n[ "$1" = get ] || exit 0\ncat >/dev/null\necho password=' + LOCAL_SECRET + '\n');
+ chmodSync(passwordOnly, 0o755);
+ const urlToken = checkout('brain-urltoken', 'forbidden');
+ git(urlToken, ['config', 'credential.helper', passwordOnly]);
+ git(urlToken, ['remote', 'set-url', 'origin', 'http://' + URL_TOKEN + '@127.0.0.1:' + port + '/forbidden/brain-urltoken.git']);
+ const viaUrl = commitPush(urlToken, { GLOBAL_HELPER_SILENT: '1' });
+ expect(viaUrl.doc.code).toBe('push_credential_refused');
+ expect(everythingWritten(urlToken, viaUrl)).not.toContain(URL_TOKEN);
+
+ const userToken = checkout('brain-usertoken', 'forbidden');
+ git(userToken, ['config', 'credential.helper', writeHelper('helper-token-user.sh', USER_TOKEN, LOCAL_SECRET)]);
+ const viaHelper = commitPush(userToken, { GLOBAL_HELPER_SILENT: '1' });
+ expect(viaHelper.doc.code).toBe('push_credential_refused');
+ expect(everythingWritten(userToken, viaHelper)).not.toContain(USER_TOKEN);
+ expect(everythingWritten(userToken, viaHelper)).not.toContain(LOCAL_SECRET);
+ }, 180_000);
+
+ test('a push that lands outside commit-push ends the refusal for put_page and doctor', async () => {
+ const work = checkout('brain-outside', 'notfound');
+ commitPush(work);
+ expect(readCredentialRefusal(work)).not.toBeNull();
+ setMode(work, 'ok');
+ git(work, ['push', '-q', 'origin', 'main']);
+ expect(readCredentialRefusal(work)).toBeNull();
+ expect((await withEnv({ GBRAIN_HOME: home }, async () => getLastPushOutcome('main', work))).detail ?? '').not.toContain('push_credential_refused since');
+ }, 120_000);
+
+ test('a refusal stays while another push URL of the remote still refuses, and put_page reports it for a local branch named apart from its upstream', async () => {
+ const work = checkout('brain-twourls', 'notfound');
+ commitPush(work);
+ git(work, ['remote', 'set-url', '--push', 'origin', 'http://127.0.0.1:' + port + '/ok/brain-twourls.git']);
+ git(work, ['remote', 'set-url', '--add', '--push', 'origin', 'http://127.0.0.1:' + port + '/notfound/brain-twourls.git']);
+ spawnSync('git', ['-C', work, 'push', 'origin', 'main'], { env: env(), stdio: 'ignore' });
+ expect(git(work, ['rev-parse', 'refs/remotes/origin/main'])).toBe(git(work, ['rev-parse', 'HEAD']));
+ expect(readCredentialRefusal(work)?.kind).toBe('not_found');
+
+ const split = checkout('brain-split', 'notfound');
+ commitPush(split);
+ git(split, ['remote', 'set-url', '--push', 'origin', 'http://127.0.0.1:' + port + '/notfound/brain-split.git']);
+ git(split, ['remote', 'set-url', 'origin', 'http://127.0.0.1:' + port + '/ok/brain-split.git']);
+ git(split, ['push', '-q', join(dir, 'srv', 'brain-split.git'), 'main']);
+ git(split, ['fetch', '-q', 'origin']);
+ expect(git(split, ['rev-parse', 'refs/remotes/origin/main'])).toBe(git(split, ['rev-parse', 'HEAD']));
+ expect(readCredentialRefusal(split)?.kind).toBe('not_found');
+
+ const renamed = checkout('brain-renamed', 'notfound');
+ git(renamed, ['branch', '-m', 'main', 'local-work']);
+ git(renamed, ['branch', '--set-upstream-to', 'origin/main', 'local-work']);
+ commitPush(renamed);
+ expect(readCredentialRefusal(renamed)?.branch).toBe('main');
+ const outcome = await withEnv({ GBRAIN_HOME: home }, async () => getLastPushOutcome('local-work', renamed));
+ expect(outcome.status).toBe('needs_attention');
+ expect(outcome.detail).toContain('push_credential_refused since');
+ }, 180_000);
+
+ test('a helper is shown by its command only when it has a command shape, never a token, an inline body or an assignment', async () => {
+ const SHAPE = 'CANARY-gst2961-shape-not-a-real-token';
+ const bin = join(dir, 'bin');
+ mkdirSync(bin, { recursive: true });
+ writeFileSync(join(bin, 'gh'), '#!/bin/sh\n[ "$3" = get ] || exit 0\ncat >/dev/null\necho username=user-c\necho password=' + LOCAL_SECRET + '\n');
+ chmodSync(join(bin, 'gh'), 0o755);
+ const answer = join(dir, 'helper-local.sh');
+ const cases = [
+ { name: 'brain-shape-env', config: '[credential]\n\thelper = "!GH_TOKEN=' + SHAPE + ' gh auth git-credential"\n', shown: ['!gh …'] },
+ { name: 'brain-shape-body', config: '[credential]\n\thelper = "!f() { cat >/dev/null; echo username=user-c; echo password=' + SHAPE + '; }; f"\n', shown: ['an inline shell helper'] },
+ { name: 'brain-shape-quote', config: '[credential]\n\thelper = "!\'Q' + SHAPE + '\' x"\n\thelper = TOKEN=' + SHAPE + '\n\thelper = ' + answer + '\n', shown: ['an inline shell helper', 'a credential helper', answer] },
+ ];
+ const engine = new PGLiteEngine();
+ await engine.connect({});
+ await engine.initSchema();
+ try {
+ for (const c of cases) {
+ const work = checkout(c.name, 'forbidden');
+ git(work, ['config', '--unset', 'credential.helper']);
+ const config = join(dir, c.name + '.gitconfig');
+ writeFileSync(config, c.config);
+ const run = commitPush(work, { GIT_CONFIG_GLOBAL: config, PATH: bin + ':' + String(process.env.PATH) });
+ expect(run.doc.code).toBe('push_credential_refused');
+ const shown = readCredentialRefusal(work)?.helpers.map(h => h.helper) ?? [];
+ expect([shown[0], shown.at(-1)]).toEqual([c.shown[0], c.shown.at(-1)]);
+ for (const h of shown) expect(c.shown).toContain(h);
+ await engine.executeRaw('DELETE FROM sources');
+ await engine.executeRaw('INSERT INTO sources(id,name,local_path) VALUES($1,$1,$2)', ['brain', work]);
+ const check = await withEnv({ GIT_CONFIG_GLOBAL: config }, async () => gitConvergenceCheck(engine));
+ expect(check?.message).toContain('push_credential_refused');
+ const seen = [everythingWritten(work, run), check?.message ?? '', JSON.stringify(check?.fix ?? {})].join('\n');
+ expect(seen).not.toContain(SHAPE);
+ expect(seen).not.toContain('echo ');
+ }
+ } finally {
+ await engine.disconnect();
+ }
+ }, 240_000);
+
+ test('a narrowing gbrain access rule add on a checkout whose push the host refuses still applies the rule and reports committed_not_pushed', async () => {
+ const work = checkout('brain-access', 'forbidden');
+ const engine = new PGLiteEngine();
+ await engine.connect({});
+ await engine.initSchema();
+ try {
+ await engine.executeRaw("INSERT INTO sources (id, name, local_path, config) VALUES ($1, $1, $2, '{}')", ['src-a', work]);
+ await engine.executeRaw('INSERT INTO access_members (id) VALUES ($1)', ['alice-example']);
+ const lines: string[] = [];
+ const spy = spyOn(console, 'log').mockImplementation((...a: unknown[]) => { lines.push(a.map(String).join(' ')); });
+ try {
+ await withEnv({ GBRAIN_HOME: home, GIT_CONFIG_GLOBAL: globalConfig, GIT_CONFIG_NOSYSTEM: '1', GIT_TERMINAL_PROMPT: '0' }, async () =>
+ runAccessRules(engine, 'rule', ['add', '--source', 'src-a', '--prefix', 'partners/alice-example/', '--readers', 'alice-example', '--id', 'alice', '--yes', '--json'], true));
+ } finally { spy.mockRestore(); }
+ const r = JSON.parse(lines.join('\n'));
+ expect({ store: r.store, state: r.state, outcome: r.git.outcome }).toEqual({ store: 'git', state: 'applied', outcome: 'committed_not_pushed' });
+ expect(r.git.commit).toBe(git(work, ['rev-parse', 'HEAD']));
+ expect(r.git.note).toContain('push_credential_refused');
+ expect((await policyStatus(engine, 'src-a')).rules.map(x => x.id)).toEqual(['alice']);
+ } finally {
+ await engine.disconnect();
+ }
+ }, 180_000);
+
+ test('doctor git_convergence warns at once, and a push that lands clears the record', async () => {
+ const work = checkout('brain-clear', 'notfound');
+ commitPush(work);
+ commitPush(work);
+ expect(readCredentialRefusal(work)?.attempts).toBe(2);
+ const engine = new PGLiteEngine();
+ await engine.connect({});
+ await engine.initSchema();
+ try {
+ await engine.executeRaw('INSERT INTO sources(id,name,local_path) VALUES($1,$1,$2)', ['brain', work]);
+ const check = await gitConvergenceCheck(engine);
+ expect(check?.status).toBe('warn');
+ expect(check?.message).toContain('push_credential_refused');
+ expect(check?.message).toContain('user-b');
+ expect(check?.message).not.toContain(CANARY);
+ expect(check?.fix?.actor).toBe('user');
+ expect(check?.fix?.argv).toContain('--name-only');
+
+ setMode(work, 'ok');
+ const landed = commitPush(work);
+ expect(landed.status).toBe(0);
+ expect(readCredentialRefusal(work)).toBeNull();
+ expect((await withEnv({ GBRAIN_HOME: home }, async () => getLastPushOutcome('main', work))).status).toBe('ok');
+ expect((await gitConvergenceCheck(engine))?.status).toBe('ok');
+ } finally {
+ await engine.disconnect();
+ }
+ }, 180_000);
+});
diff --git a/test/helpers/imessage-helper-fixture.ts b/test/helpers/imessage-helper-fixture.ts
new file mode 100644
index 0000000000..6f245117ac
--- /dev/null
+++ b/test/helpers/imessage-helper-fixture.ts
@@ -0,0 +1,85 @@
+/**
+ * A synthetic GBrain Helper behind the two iMessage routes the imessage source calls, answering in the helper's own wire
+ * shape (snake_case JSON envelopes, problem+json refusals). Placeholder names and reserved numbers only; never real data.
+ */
+import { json } from './connector-fixture.ts';
+
+export interface FakeIMessage {
+ rowid: number;
+ /** Epoch ms. */
+ at: number;
+ text: string;
+ fromMe?: boolean;
+ from?: string;
+ edited?: boolean;
+ retracted?: boolean;
+ attachment?: boolean;
+ undecodable?: boolean;
+}
+export interface FakeChat { threadId: string; displayName: string; participants: string[]; isGroup?: boolean; messages: FakeIMessage[] }
+export interface FakeHelper {
+ token: string;
+ chats: FakeChat[];
+ calls: string[];
+ /** Messages per page, to exercise the cursor. */
+ pageSize?: number;
+ /** A problem code every /v1 route answers with (no_access, schema_mismatch, source_disabled, insufficient_scope). */
+ problem?: string;
+ /** The transport fails as if nothing listened on the port. */
+ down?: boolean;
+ /** Rewrites each /v1/imessage/threads row, to exercise a helper whose wire shape drifted. */
+ threadRow?: (row: Record<string, unknown>) => Record<string, unknown>;
+}
+
+export const HELPER_TEST_TOKEN = 'helper-test-token-0001';
+
+const iso = (ms: number) => new Date(ms).toISOString();
+const PROBLEM_STATUS: Record<string, number> = { no_access: 503, schema_mismatch: 503, source_disabled: 403, insufficient_scope: 403, unauthorized: 401, db_busy: 503 };
+
+function problem(code: string) {
+ return new Response(JSON.stringify({ type: `https://example.invalid/problems/${code}`, title: code, status: PROBLEM_STATUS[code] ?? 500, code, detail: code, retryable: false, request_id: 'r1' }),
+ { status: PROBLEM_STATUS[code] ?? 500, headers: { 'content-type': 'application/problem+json' } });
+}
+
+const wire = (m: FakeIMessage, chat: FakeChat) => ({
+ id: `guid-${chat.threadId}-${m.rowid}`, rowid: m.rowid, timestamp: iso(m.at), is_from_me: !!m.fromMe,
+ text: m.undecodable ? '' : m.text, text_status: m.undecodable ? 'undecodable' : m.text ? 'ok' : 'empty',
+ from: m.fromMe ? null : chat.isGroup ? m.from ?? null : null, from_identifier: null, has_attachments: !!m.attachment,
+ edited_at: m.edited ? iso(m.at + 60_000) : null, retracted: !!m.retracted,
+});
+
+export function helperFetch(fake: FakeHelper) {
+ return async (url: string, init: RequestInit) => {
+ const u = new URL(url);
+ fake.calls.push(u.pathname + (u.searchParams.get('thread_id') ? `:${u.searchParams.get('thread_id')}` : ''));
+ if (fake.down) throw new TypeError('fetch failed: connect ECONNREFUSED 127.0.0.1');
+ if (u.hostname !== '127.0.0.1') throw new Error('the helper is reached only on 127.0.0.1');
+ if (url.includes(fake.token)) throw new Error('token outside the authorization header');
+ const auth = new Headers(init.headers).get('authorization');
+ if (auth !== `Bearer ${fake.token}`) return problem('unauthorized');
+ if (fake.problem) return problem(fake.problem);
+ const p = u.searchParams;
+ if (u.pathname === '/v1/imessage/threads') {
+ const limit = Number(p.get('limit') ?? 30);
+ const last = (c: FakeChat) => Math.max(0, ...c.messages.map(m => m.at));
+ const data = [...fake.chats].sort((a, b) => last(b) - last(a)).slice(0, limit).map(c => ({
+ thread_id: c.threadId, chat_rowids: [1], chat_guids: [`chat-${c.threadId}`], display_name: c.displayName, participant_count: c.participants.length,
+ participants: c.participants, is_group: !!c.isGroup, service: 'iMessage', ...(c.messages.length ? { last_message_at: iso(last(c)) } : {}) })).map(row => fake.threadRow?.(row) ?? row);
+ return json({ data, meta: { count: data.length, undecodable: 0 } });
+ }
+ if (u.pathname === '/v1/imessage/thread') {
+ const chat = fake.chats.find(c => c.threadId === p.get('thread_id'));
+ if (!chat) return problem('not_found');
+ const sinceRowid = p.has('since_rowid') ? Number(p.get('since_rowid')) : null;
+ const since = p.has('since_iso') ? Date.parse(p.get('since_iso')!) : null;
+ const limit = Math.min(Number(p.get('limit') ?? 50), fake.pageSize ?? 500);
+ const all = [...chat.messages].sort((a, b) => a.rowid - b.rowid)
+ .filter(m => (sinceRowid === null || m.rowid > sinceRowid) && (since === null || m.at >= since));
+ const page = all.slice(0, limit);
+ const hasMore = all.length > limit;
+ return json({ data: { contact: chat.displayName, thread_id: chat.threadId, is_group: !!chat.isGroup, messages: page.map(m => wire(m, chat)) },
+ meta: { count: page.length, undecodable: 0, has_more: hasMore, next_since_rowid: hasMore ? page.at(-1)!.rowid : null } });
+ }
+ return problem('not_found');
+ };
+}
diff --git a/test/imessage-owner-only.test.ts b/test/imessage-owner-only.test.ts
new file mode 100644
index 0000000000..cb6acc924e
--- /dev/null
+++ b/test/imessage-owner-only.test.ts
@@ -0,0 +1,281 @@
+/**
+ * Owner-only sources (access/owner-only.ts): an imessage source, and any source flagged `owner_only: true`, is read
+ * only by the trusted local CLI and by credentials bound to the brain owner speaking for itself.
+ *
+ * 1. Protects: every other remote caller (another member, an unbound token, the owner's credential speaking for a
+ * shared room or a guest, an attested call linked to the owner) gets not_found for a page in an owner-only source
+ * (private or not), for pages and facts derived from one (recorded derivation inputs, followed transitively, and
+ * synthesized concepts), and for its timeline, through get_page, search, query, recall, list_pages, get_timeline and
+ * delta, under each operator relaxation alone and all together: granted-sources private pages and facts on the
+ * token, search.remote_private_pages visible, access.members_read_lineage, access.owner_reads_restricted and
+ * visibility.honor_aliases off. A remote write into an owner-only source from any credential but the owner's is
+ * refused like a page it may not see.
+ * 2. Fails when: any of those callers sees a canary, or the owner, its delegate or the local CLI loses one.
+ * 3. Real seams: the imessage sync against a synthetic helper writes the pages; tokens minted by the token service and
+ * verified by the serve --http verifier, dispatched through MCP dispatch with remote: true, on a repo-less brain;
+ * embeddings stubbed.
+ */
+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
+import type { BrainEngine } from '../src/core/engine.ts';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import { importFromContent } from '../src/core/import-file.ts';
+import { configureGateway, resetGateway, __setEmbedTransportForTests } from '../src/core/ai/gateway.ts';
+import { GBrainOAuthProvider } from '../src/core/oauth-provider.ts';
+import { sqlQueryForEngine } from '../src/core/sql-query.ts';
+import { mintLegacyToken } from '../src/core/token-mint.ts';
+import { noGrantFederatedScope } from '../src/core/source-resolver.ts';
+import { dispatchToolCall } from '../src/mcp/dispatch.ts';
+import { __resetPrivateVisibilityCacheForTests } from '../src/core/search/private-visibility.ts';
+import { setOwner } from '../src/core/access/owner.ts';
+import { bindCredential } from '../src/core/access/members.ts';
+import { linkMember } from '../src/core/access/actor.ts';
+import type { AuthInfo } from '../src/core/ops/contract.ts';
+import { runIMessageSync } from '../src/core/imessage/imessage-source.ts';
+import { parseIMessageSourceConfig } from '../src/core/imessage/source-config.ts';
+import { imessageHelper } from '../src/core/apple/helper-client.ts';
+import { imessageChatKey, imessagePagePath } from '../src/core/imessage/render.ts';
+import { slugifyPath } from '../src/core/sync.ts';
+import { HELPER_TEST_TOKEN, helperFetch } from './helpers/imessage-helper-fixture.ts';
+import { options } from './helpers/connector-fixture.ts';
+import { testBackends } from './helpers/test-backends.ts';
+import { isolatedPersistencePostgres } from './helpers/persistence-postgres.ts';
+import { readsUnscopedOnPurpose } from './helpers/reads-unscoped.ts';
+import { OWNER_ONLY_FLAG, OWNER_ONLY_KINDS, ownerOnlyFactSql, ownerOnlyPageSql, type OwnerOnlyForm } from '../src/core/access/owner-only.ts';
+import { v320 } from '../src/core/schema-migrations/v320-owner-only-lineage.ts';
+
+const DIMS = 1536;
+function vectorFor(text: string): number[] {
+ const v = new Array<number>(DIMS).fill(0);
+ for (const w of text.toLowerCase().match(/[a-z]+/g) ?? []) {
+ let h = 0;
+ for (const ch of w) h = (h * 31 + ch.charCodeAt(0)) >>> 0;
+ v[h % DIMS] += 1;
+ }
+ const n = Math.hypot(...v) || 1;
+ return v.map(x => x / n);
+}
+
+const OPEN_SRC = 'own-src';
+const IMSG = 'messages';
+const FLAGGED = 'flagged-src';
+const OWNER = 'owner-example';
+const NOW = Date.parse('2026-06-15T12:00:00Z');
+const PHRASE = 'harbor ledger planning notes';
+const CHAT_CANARY = 'canaryooday';
+const CHAT_SLUG = slugifyPath(imessagePagePath(imessageChatKey('+15555550100'), '2026-06-14'));
+/** Owner-only pages, by how they reach an owner-only source. */
+const HIDDEN = {
+ chat: { slug: CHAT_SLUG, canary: CHAT_CANARY },
+ plain: { slug: 'notes/plain-in-messages', canary: 'canaryooplain' },
+ flagged: { slug: 'notes/flagged-plan', canary: 'canaryooflag' },
+ derived: { slug: 'notes/derived-from-chat', canary: 'canaryooderived' },
+ derived2: { slug: 'notes/derived-twice', canary: 'canaryooderived2' },
+ concept: { slug: 'concepts/harbor-chat', canary: 'canaryooconcept' },
+} as const;
+type Hidden = keyof typeof HIDDEN;
+const OPEN = { slug: 'notes/open-plan', canary: 'canaryooopen' };
+const FACT_IN_SOURCE = 'canaryoofact';
+const FACT_DERIVED = 'canaryoofactderived';
+const TIMELINE = 'canaryootimeline';
+const ALL_CANARIES = [...Object.values(HIDDEN).map(h => h.canary), FACT_IN_SOURCE, FACT_DERIVED, TIMELINE];
+
+const pageText = (title: string, canary: string, fm: readonly string[] = []) =>
+ ['---', ...(fm.some(l => l.startsWith('type:')) ? [] : ['type: note']), `title: ${title}`, ...fm, '---', `# ${title}`, '', `Harbor ledger planning notes ${canary} for the roadmap.`].join('\n');
+
+/** Every read path a non-owner might reach an owner-only artifact through. */
+function reads(): Array<[string, string, Record<string, unknown>]> {
+ return [
+ ...Object.entries(HIDDEN).map(([key, h]) => [`get_page ${key}`, 'get_page', { slug: h.slug }] as [string, string, Record<string, unknown>]),
+ ['get_timeline', 'get_timeline', { slug: CHAT_SLUG }],
+ ['search', 'search', { query: PHRASE, fields: 'full', limit: 50 }],
+ ['search keyword', 'search', { query: 'planning notes', match: 'keyword', fields: 'full', limit: 50 }],
+ ['query', 'query', { query: PHRASE, expand: false, fields: 'full', limit: 50 }],
+ ['recall', 'recall', { query: PHRASE }],
+ ['recall question', 'recall', { question: `Harbor ledger planning notes ${FACT_DERIVED}` }],
+ ['list_pages', 'list_pages', { limit: 100 }],
+ ['delta', 'delta', { since: '2000-01-01T00:00:00Z' }],
+ ];
+}
+
+const RELAXATIONS: Record<string, Array<[string, string]>> = {
+ none: [],
+ 'search.remote_private_pages': [['search.remote_private_pages', 'visible']],
+ 'access.members_read_lineage': [['access.members_read_lineage', '1']],
+ 'access.owner_reads_restricted': [['access.owner_reads_restricted', '1']],
+ 'visibility.honor_aliases off': [['visibility.honor_aliases', 'false']],
+};
+RELAXATIONS.all = Object.values(RELAXATIONS).flat();
+
+for (const kind of testBackends()) {
+ describe(`owner-only sources (${kind}, repo-less)`, () => {
+ let engine: BrainEngine;
+ let close: () => Promise<void>;
+ const tokens: Record<string, string> = {};
+ const provider = () => new GBrainOAuthProvider({ sql: sqlQueryForEngine(engine), transaction: fn => engine.transaction(tx => fn(sqlQueryForEngine(tx))) });
+
+ async function call(who: string, op: string, params: Record<string, unknown>, ch: { header?: string; actor?: string } = {}): Promise<{ isError: boolean; text: string }> {
+ const auth = await provider().verifyAccessToken(tokens[who]!) as unknown as AuthInfo;
+ const sourceId = auth.sourceId ?? OPEN_SRC;
+ const localFederated = await noGrantFederatedScope(engine, auth.hasSourceGrant, sourceId);
+ const out = await dispatchToolCall(engine, op, { ...params }, {
+ remote: true, transport: 'http', auth, sourceId, takesHoldersAllowList: auth.takesHoldersAllowList ?? ['world'],
+ ...(localFederated ? { localFederatedSourceIds: localFederated } : {}), ...(ch.header ? { onBehalfOf: { header: ch.header } } : {}),
+ ...(ch.actor ? { actor: { header: ch.actor } } : {}),
+ });
+ return { isError: out.isError === true, text: out.content.map(c => c.text).join('\n') };
+ }
+
+ /** The owner-only canaries `who` sees on each read path, in every source its grant names. */
+ async function seenBy(who: string, ch: { header?: string; actor?: string } = {}): Promise<Record<string, string[]>> {
+ const out: Record<string, string[]> = {};
+ for (const sourceId of [OPEN_SRC, IMSG, FLAGGED]) {
+ for (const [label, op, params] of reads()) {
+ const { text } = await call(who, op, { ...params, ...(op === 'get_page' || op === 'get_timeline' ? {} : { source_id: sourceId }) }, ch);
+ const seen = ALL_CANARIES.filter(c => text.includes(c));
+ if (seen.length) out[label] = [...new Set([...(out[label] ?? []), ...seen])].sort();
+ }
+ }
+ return out;
+ }
+
+ beforeAll(async () => {
+ configureGateway({ embedding_model: 'openai:text-embedding-3-small', embedding_dimensions: DIMS, env: { OPENAI_API_KEY: 'test' } });
+ __setEmbedTransportForTests((async ({ values }: { values: string[] }) => ({ embeddings: values.map(vectorFor) })) as never);
+ if (kind === 'postgres') ({ engine, close } = await isolatedPersistencePostgres(process.env.DATABASE_URL!));
+ else { engine = new PGLiteEngine(); await engine.connect({ engine: 'pglite' } as never); await engine.initSchema(); close = () => engine.disconnect(); }
+ await engine.executeRaw('UPDATE persistence_brain SET enabled=false WHERE singleton=1');
+ __resetPrivateVisibilityCacheForTests();
+ await engine.executeRaw('INSERT INTO sources (id, name) VALUES ($1, $1) ON CONFLICT (id) DO NOTHING', [OPEN_SRC]);
+ await engine.executeRaw(`INSERT INTO sources (id, name, config) VALUES ($1, $1, '{"kind":"imessage","federated":true}'::jsonb)`, [IMSG]);
+ await engine.executeRaw(`INSERT INTO sources (id, name, config) VALUES ($1, $1, '{"owner_only":true,"federated":true}'::jsonb)`, [FLAGGED]);
+
+ // The chat day, written by the sync from a synthetic helper.
+ const fake = { token: HELPER_TEST_TOKEN, calls: [], chats: [{ threadId: '+15555550100', displayName: 'Alice Example', participants: ['+15555550100'],
+ messages: [{ rowid: 1, at: Date.parse('2026-06-14T09:00:00Z'), text: `Harbor ledger planning notes ${CHAT_CANARY} for the roadmap.` }] }] };
+ const synced = await runIMessageSync(engine, IMSG, parseIMessageSourceConfig({ kind: 'imessage' }), { ...options, noEmbed: false },
+ { helper: imessageHelper({ sourceId: IMSG, port: 47001, token: HELPER_TEST_TOKEN, fetchImpl: helperFetch(fake) }), now: () => NOW });
+ if (synced.added !== 1) throw new Error(`fixture sync added ${synced.added}`);
+ // A page in the imessage source that is not marked private is owner-only all the same.
+ await importFromContent(engine, HIDDEN.plain.slug, pageText('Plain', HIDDEN.plain.canary), { sourceId: IMSG });
+ await importFromContent(engine, HIDDEN.flagged.slug, pageText('Flagged', HIDDEN.flagged.canary), { sourceId: FLAGGED });
+ await importFromContent(engine, OPEN.slug, pageText('Open', OPEN.canary), { sourceId: OPEN_SRC });
+ await importFromContent(engine, HIDDEN.derived.slug, pageText('Derived', HIDDEN.derived.canary), { sourceId: OPEN_SRC });
+ await importFromContent(engine, HIDDEN.derived2.slug, pageText('Derived twice', HIDDEN.derived2.canary), { sourceId: OPEN_SRC });
+ await importFromContent(engine, HIDDEN.concept.slug, pageText('Harbor chat', HIDDEN.concept.canary, ['type: concept']), { sourceId: OPEN_SRC });
+ const id = async (slug: string, sourceId: string) => String((await engine.executeRaw<{ id: number }>('SELECT id FROM pages WHERE slug=$1 AND source_id=$2', [slug, sourceId]))[0]!.id);
+ const chatId = await id(CHAT_SLUG, IMSG);
+ const derivedId = await id(HIDDEN.derived.slug, OPEN_SRC);
+ await engine.executeRaw(`INSERT INTO derivation_inputs (derived_table, derived_id, input_table, input_id, source_id) VALUES
+ ('pages', $1, 'pages', $2, $4), ('pages', $3, 'pages', $1, $4)`, [derivedId, chatId, await id(HIDDEN.derived2.slug, OPEN_SRC), OPEN_SRC]);
+ await engine.executeRaw(`INSERT INTO links (from_page_id, to_page_id, link_type, link_source) VALUES ($1, $2, 'synthesized_from', 'concept-provenance')`,
+ [Number(await id(HIDDEN.concept.slug, OPEN_SRC)), Number(chatId)]);
+ await engine.executeRaw(`INSERT INTO timeline_entries (page_id, date, summary) VALUES ($1, '2026-06-14', $2)`, [Number(chatId), `Harbor ledger planning notes ${TIMELINE}`]);
+ await engine.executeRaw(`INSERT INTO facts (source_id, entity_slug, fact, kind, visibility, source) VALUES ($1, $2, $3, 'fact', 'world', 'fixture')`,
+ [IMSG, OPEN.slug, `Harbor ledger planning notes ${FACT_IN_SOURCE}`]);
+ const [fact] = await engine.executeRaw<{ id: number }>(`INSERT INTO facts (source_id, entity_slug, fact, kind, visibility, source) VALUES ($1, $2, $3, 'fact', 'world', 'fixture') RETURNING id`,
+ [OPEN_SRC, OPEN.slug, `Harbor ledger planning notes ${FACT_DERIVED}`]);
+ await engine.executeRaw(`INSERT INTO derivation_inputs (derived_table, derived_id, input_table, input_id, source_id) VALUES ('facts', $1, 'pages', $2, $3)`, [String(fact!.id), chatId, OPEN_SRC]);
+
+ for (const member of [OWNER, 'bob-example']) await engine.executeRaw('INSERT INTO access_members (id) VALUES ($1)', [member]);
+ const grant = [OPEN_SRC, IMSG, FLAGGED];
+ const mint = async (name: string, bind: Parameters<typeof bindCredential>[2] | null, scopes = ['read'], sourceGrant = grant) => {
+ const minted = await mintLegacyToken(engine, { name, scopes, takesHolders: ['world'], sourceGrant });
+ tokens[name] = minted.token;
+ if (bind) await bindCredential(engine, { kind: 'token', id: minted.id }, bind);
+ else await readsUnscopedOnPurpose(engine, minted.id);
+ };
+ await mint('owner', { member: OWNER, mayActFor: [`member:${OWNER}`, 'member:bob-example', 'guest'] }, ['read', 'write']);
+ await mint('delegate', { member: OWNER });
+ await mint('bob', { member: 'bob-example' }, ['read', 'write']);
+ await mint('unbound', null);
+ // Writers whose write floor (the grant's first source) is an owner-only source.
+ await mint('owner-writes-messages', { member: OWNER }, ['read', 'write'], [IMSG, OPEN_SRC]);
+ await mint('bob-writes-messages', { member: 'bob-example' }, ['read', 'write'], [IMSG, OPEN_SRC]);
+ await mint('bob-writes-flagged', { member: 'bob-example' }, ['read', 'write'], [FLAGGED, OPEN_SRC]);
+ await mint('unbound-writes-messages', null, ['read', 'write'], [IMSG, OPEN_SRC]);
+ await mint('attested', { attestActor: 'qm', attestOps: ['get_page', 'list_pages', 'search', 'query', 'recall', 'get_timeline', 'delta'], readsUnscoped: true });
+ await linkMember(engine, OWNER, 'qm', 'U0OWNER');
+ // Every relaxation a token can carry: private pages and private facts of its granted sources.
+ await engine.executeRaw(`UPDATE access_tokens SET private_pages = 'granted_sources', private_facts = 'granted_sources'`);
+ await setOwner(engine, OWNER);
+ }, 240_000);
+
+ afterAll(async () => {
+ __setEmbedTransportForTests(null);
+ resetGateway();
+ await close?.();
+ }, 60_000);
+
+ test('fixture control: the trusted local CLI reads every owner-only page, fact and timeline row', async () => {
+ const local = (op: string, params: Record<string, unknown>, sourceId = OPEN_SRC) =>
+ dispatchToolCall(engine, op, params, { remote: false, sourceId }).then(o => o.content.map(c => c.text).join('\n'));
+ for (const [key, h] of Object.entries(HIDDEN)) {
+ const sourceId = key === 'chat' || key === 'plain' ? IMSG : key === 'flagged' ? FLAGGED : OPEN_SRC;
+ expect({ key, seen: (await local('get_page', { slug: h.slug }, sourceId)).includes(h.canary) }).toEqual({ key, seen: true });
+ }
+ expect(await local('get_timeline', { slug: CHAT_SLUG }, IMSG)).toContain(TIMELINE);
+ expect(await local('recall', { question: `Harbor ledger planning notes ${FACT_DERIVED}` })).toContain(FACT_DERIVED);
+ }, 120_000);
+
+ test('the owner and its delegate read the owner-only pages and facts remotely', async () => {
+ for (const who of ['owner', 'delegate']) {
+ const seen = new Set(Object.values(await seenBy(who)).flat());
+ expect({ who, missing: ALL_CANARIES.filter(c => !seen.has(c)) }).toEqual({ who, missing: [] });
+ }
+ }, 240_000);
+
+ for (const [name, settings] of Object.entries(RELAXATIONS)) {
+ test(`relaxation ${name}: no other caller reads an owner-only page, a page or fact derived from one, or its timeline`, async () => {
+ for (const [key, value] of settings) await engine.setConfig(key, value);
+ __resetPrivateVisibilityCacheForTests();
+ try {
+ const callers: Array<[string, string, { header?: string; actor?: string }]> = [
+ ['another member', 'bob', {}],
+ ['an unbound token', 'unbound', {}],
+ ['the owner for a shared room', 'owner', { header: `member:${OWNER},member:bob-example` }],
+ ['the owner for a guest', 'owner', { header: 'guest' }],
+ ['an attested call linked to the owner', 'attested', { actor: 'U0OWNER' }],
+ ];
+ for (const [label, who, ch] of callers) expect({ caller: label, seen: await seenBy(who, ch) }).toEqual({ caller: label, seen: {} });
+ // The open page stays readable, so the empty result above is the rule and not a dead fixture.
+ expect((await call('bob', 'get_page', { slug: OPEN.slug })).text).toContain(OPEN.canary);
+ } finally {
+ for (const [key] of settings) await engine.unsetConfig(key);
+ __resetPrivateVisibilityCacheForTests();
+ }
+ }, 600_000);
+ }
+
+ test('a remote write into an owner-only source is refused for every credential but the owner\'s', async () => {
+ const put = (who: string, sourceId: string, slug: string) => call(who, 'put_page', { slug, source_id: sourceId, content: pageText('Planted', 'canaryooplanted') });
+ for (const [who, sourceId, slug] of [['bob-writes-messages', IMSG, HIDDEN.plain.slug], ['bob-writes-messages', IMSG, 'notes/planted'],
+ ['unbound-writes-messages', IMSG, 'notes/planted'], ['bob-writes-flagged', FLAGGED, 'notes/planted']] as const) {
+ const out = await put(who, sourceId, slug);
+ expect({ who, slug, refused: out.isError, code: out.text.match(/"code": "([a-z_]+)"/)?.[1] }).toEqual({ who, slug, refused: true, code: 'page_not_found' });
+ expect(out.text).not.toContain(HIDDEN.plain.canary);
+ }
+ // The control: the same credential writes its open source.
+ expect((await put('bob', OPEN_SRC, 'notes/bob-wrote')).isError).toBe(false);
+ expect((await dispatchToolCall(engine, 'get_page', { slug: HIDDEN.plain.slug }, { remote: false, sourceId: IMSG })).content.map(c => c.text).join('\n')).toContain(HIDDEN.plain.canary);
+ const own = await put('owner-writes-messages', IMSG, 'notes/owner-wrote');
+ expect({ refused: own.isError, text: own.isError ? own.text : '' }).toEqual({ refused: false, text: '' });
+ }, 120_000);
+ test('the v320 functions mark exactly the owner-only rows, the fail-closed form marks every row, and the migration names the same kinds', async () => {
+ const verdicts = async (table: 'pages' | 'facts', sql: (alias: string, form: OwnerOnlyForm) => string) => engine.executeRaw<{ id: number; fn: boolean; closed: boolean }>(
+ `SELECT r.id, ${sql('r', 'fn')} AS fn, ${sql('r', 'closed')} AS closed FROM ${table} r ORDER BY r.id`);
+ const pages = await verdicts('pages', ownerOnlyPageSql);
+ const facts = await verdicts('facts', ownerOnlyFactSql);
+ const hiddenIds = (await engine.executeRaw<{ id: number }>('SELECT id FROM pages WHERE slug = ANY($1::text[])', [Object.values(HIDDEN).map(h => h.slug)])).map(r => r.id);
+ const openId = (await engine.executeRaw<{ id: number }>('SELECT id FROM pages WHERE slug = $1 AND source_id = $2', [OPEN.slug, OPEN_SRC]))[0]!.id;
+ expect(hiddenIds.length).toBe(Object.keys(HIDDEN).length);
+ expect(pages.filter(r => hiddenIds.includes(r.id) && !r.fn)).toEqual([]);
+ expect(pages.find(r => r.id === openId)?.fn).toBe(false);
+ expect(facts.some(r => r.fn)).toBe(true);
+ // Without the functions (a schema below v320, or none recorded) a brain holding an owner-only source hides every row.
+ expect([...pages, ...facts].every(r => r.closed)).toBe(true);
+ // The function's kinds and flag are frozen in the migration; a new owner-only kind needs a new migration.
+ expect(v320.sql).toContain(`IN (${OWNER_ONLY_KINDS.map(k => `'${k}'`).join(', ')})`);
+ expect(v320.sql).toContain(`config->>'${OWNER_ONLY_FLAG}' = 'true'`);
+ }, 120_000);
+ });
+}
diff --git a/test/imessage-source.test.ts b/test/imessage-source.test.ts
new file mode 100644
index 0000000000..8fc1e1a8cf
--- /dev/null
+++ b/test/imessage-source.test.ts
@@ -0,0 +1,267 @@
+/**
+ * imessage source kind: a repo-less PGLite brain and a brain with a Git checkout, against a synthetic GBrain Helper
+ * (test/helpers/imessage-helper-fixture.ts; no network, no Mac, no real messages).
+ *
+ * Covers one private page per chat per day with no directory, file or Git command and the cursor in the database; a
+ * second run over the same messages writes nothing; an edit or an unsend inside the lookback re-renders the day and
+ * retires its facts, a day emptied there is deleted, and an edit older than the lookback is not re-read; the helper's
+ * refusals stop the run with their own codes before anything is imported; the token travels only in the authorization
+ * header; the pages keep the external-untrusted tier; and on a brain with a Git checkout no message text reaches the
+ * checkout, a commit or a push.
+ */
+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
+import { mkdtempSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { spawnSync } from 'node:child_process';
+import type { BrainEngine } from '../src/core/engine.ts';
+import { connectTemplateBrain } from './helpers/brain-template.ts';
+import { options } from './helpers/connector-fixture.ts';
+import { HELPER_TEST_TOKEN, helperFetch, type FakeHelper } from './helpers/imessage-helper-fixture.ts';
+import { withEnv } from './helpers/with-env.ts';
+import { testBackends } from './helpers/test-backends.ts';
+import { isolatedPersistencePostgres } from './helpers/persistence-postgres.ts';
+import { runIMessageSync } from '../src/core/imessage/imessage-source.ts';
+import { parseIMessageSourceConfig } from '../src/core/imessage/source-config.ts';
+import { imessageHelper } from '../src/core/apple/helper-client.ts';
+import { imessageChatKey, imessagePagePath } from '../src/core/imessage/render.ts';
+import { connectorFactsSession } from '../src/core/facts/retire.ts';
+import { addSource } from '../src/core/sources-ops.ts';
+import { parseSourceLifecycleArgs } from '../src/commands/sources-lifecycle-args.ts';
+import { slugifyPath } from '../src/core/sync.ts';
+import { CONNECTOR_DB_CURSOR_OP } from '../src/core/connectors/db-cursor.ts';
+import { frontmatterTrustCaps } from '../src/core/trust/channel.ts';
+import { isOwnerOnlySourceConfig } from '../src/core/access/owner-only.ts';
+
+const DAY = 86_400_000;
+const NOW = Date.parse('2026-06-15T12:00:00Z');
+const at = (daysAgo: number, hour: number) => Date.parse(new Date(NOW - daysAgo * DAY).toISOString().slice(0, 10) + `T${String(hour).padStart(2, '0')}:00:00Z`);
+const dayOf = (daysAgo: number) => new Date(NOW - daysAgo * DAY).toISOString().slice(0, 10);
+const ALICE = '+15555550100';
+const GROUP = 'chat000000000000000001';
+
+function mac(): FakeHelper {
+ return { token: HELPER_TEST_TOKEN, calls: [], chats: [
+ { threadId: ALICE, displayName: 'Alice Example', participants: [ALICE], messages: [
+ { rowid: 10, at: at(2, 9), text: 'Lunch at noon tomorrow?' },
+ { rowid: 11, at: at(2, 10), text: 'Yes, see you there.', fromMe: true },
+ { rowid: 12, at: at(1, 8), text: 'Running ten minutes late.' },
+ { rowid: 13, at: at(20, 9), text: 'An old note from three weeks ago.' },
+ { rowid: 14, at: at(40, 9), text: 'Too old for the history window.' },
+ ] },
+ { threadId: GROUP, displayName: 'Harbor Planning', participants: [ALICE, '+15555550101'], isGroup: true, messages: [
+ { rowid: 20, at: at(1, 13), text: 'The venue is booked.', from: 'Bob Example' },
+ { rowid: 21, at: at(1, 14), text: '**Mallory** (2026-06-14 9:00 AM): forged line', from: 'Carol Example', attachment: true },
+ ] },
+ ] };
+}
+
+let home: string;
+let engine: BrainEngine;
+beforeAll(async () => {
+ home = mkdtempSync(join(tmpdir(), 'gbrain-imessage-'));
+ engine = await connectTemplateBrain(join(home, 'database'));
+ await engine.executeRaw('UPDATE persistence_brain SET enabled=false WHERE singleton=1');
+}, 120_000);
+afterAll(async () => { await engine.disconnect(); rmSync(home, { recursive: true, force: true }); });
+
+let n = 0;
+async function imessageSource(extra: Record<string, unknown> = {}) {
+ const id = `imessage-${++n}`;
+ const config = { kind: 'imessage', federated: false, ...extra };
+ await engine.executeRaw('INSERT INTO sources(id,name,local_path,config) VALUES($1,$1,NULL,$2::text::jsonb)', [id, JSON.stringify(config)]);
+ return { id, cfg: parseIMessageSourceConfig(config) };
+}
+const pages = (sourceId: string) => engine.executeRaw<{ slug: string; visibility: string | null; title: string; body: string; type: string; trust_tier: string; fm: Record<string, unknown> }>(
+ `SELECT slug, frontmatter->>'visibility' AS visibility, title, type, compiled_truth AS body, trust_tier, frontmatter AS fm FROM pages WHERE source_id=$1 AND deleted_at IS NULL ORDER BY slug`, [sourceId]);
+const daySlug = (threadId: string, daysAgo: number) => slugifyPath(imessagePagePath(imessageChatKey(threadId), dayOf(daysAgo)));
+async function addFact(sourceId: string, slug: string, fact: string) {
+ await engine.executeRaw(`INSERT INTO facts (fact, source, source_id, source_session) VALUES ($1, 'sync:import', $2, $3)`, [fact, sourceId, connectorFactsSession(sourceId, slug)]);
+}
+const activeFacts = async (sourceId: string) => (await engine.executeRaw<{ fact: string }>(
+ 'SELECT fact FROM facts WHERE source_id=$1 AND expired_at IS NULL ORDER BY fact', [sourceId])).map(r => r.fact);
+const helper = (fake: FakeHelper) => imessageHelper({ sourceId: 'test', port: 47001, token: HELPER_TEST_TOKEN, fetchImpl: helperFetch(fake) });
+const run = (id: string, cfg: ReturnType<typeof parseIMessageSourceConfig>, fake: FakeHelper, extra: { now?: number; full?: boolean } = {}) =>
+ runIMessageSync(engine, id, cfg, { ...options, ...(extra.full ? { full: true } : {}) }, { helper: helper(fake), now: () => extra.now ?? NOW });
+
+test('an imessage source is owner-only by its kind; the owner_only flag makes any source owner-only', () => {
+ expect(isOwnerOnlySourceConfig({ kind: 'imessage' })).toBe(true);
+ expect(isOwnerOnlySourceConfig({ kind: 'slack', owner_only: true })).toBe(true);
+ expect(isOwnerOnlySourceConfig({ kind: 'slack' })).toBe(false);
+ expect(isOwnerOnlySourceConfig(null)).toBe(false);
+});
+
+for (const kind of testBackends()) describe(`repo-less brain (${kind})`, () => {
+ let pglite: BrainEngine | undefined;
+ let close: (() => Promise<void>) | undefined;
+ beforeAll(async () => {
+ if (kind !== 'postgres') return;
+ pglite = engine;
+ ({ engine, close } = await isolatedPersistencePostgres(process.env.DATABASE_URL!));
+ await engine.executeRaw('UPDATE persistence_brain SET enabled=false WHERE singleton=1');
+ }, 120_000);
+ afterAll(async () => { if (pglite) { await close!(); engine = pglite; } });
+
+ test('imports one private page per chat day, no directory, file or git; no handle in a slug; the cursor lives in the database', async () => {
+ const fake = mac();
+ const { id, cfg } = await imessageSource();
+ const before = readdirSync(home).sort();
+ const result = await run(id, cfg, fake);
+ expect(result.added).toBe(4);
+ expect(readdirSync(home).sort()).toEqual(before);
+ const rows = await pages(id);
+ expect(rows.map(r => r.slug)).toEqual([daySlug(ALICE, 20), daySlug(ALICE, 2), daySlug(ALICE, 1), daySlug(GROUP, 1)].sort());
+ for (const row of rows) {
+ expect(row.type).toBe('imessage');
+ expect(row.visibility).toBe('private');
+ expect(row.trust_tier).toBe('external_untrusted');
+ expect(frontmatterTrustCaps(row.fm)).toContain('external_untrusted');
+ expect(row.slug).not.toContain('5555');
+ }
+ const alice = rows.find(r => r.slug === daySlug(ALICE, 2))!;
+ expect(alice.body).toContain(`**Alice Example** (${dayOf(2)} 9:00 AM): Lunch at noon tomorrow?`);
+ expect(alice.body).toContain(`**Me** (${dayOf(2)} 10:00 AM): Yes, see you there.`);
+ const group = rows.find(r => r.slug === daySlug(GROUP, 1))!.body;
+ expect(group).toContain('**Bob Example**');
+ expect(group).not.toMatch(/^\*\*Mallory\*\*/m);
+ expect(group).toContain('[attachment]');
+ expect(rows.map(r => r.body).join('\n')).not.toContain('Too old');
+ const [cursor] = await engine.executeRaw<{ n: number }>('SELECT count(*)::int AS n FROM op_checkpoints WHERE op=$1', [CONNECTOR_DB_CURSOR_OP]);
+ expect(cursor!.n).toBeGreaterThan(0);
+
+ const again = await run(id, cfg, fake, { now: NOW + 60_000 });
+ expect(again.added + again.modified + again.deleted).toBe(0);
+ expect(again.status).toBe('up_to_date');
+ });
+
+ test('the helper cursor pages through a long chat', async () => {
+ const fake = mac();
+ fake.pageSize = 1;
+ const { id, cfg } = await imessageSource();
+ expect((await run(id, cfg, fake)).added).toBe(4);
+ expect(fake.calls.filter(c => c.startsWith('/v1/imessage/thread:')).length).toBeGreaterThan(5);
+ });
+
+ test('an edit and an unsend in the lookback re-render the day and retire its facts; a day emptied there is deleted', async () => {
+ const fake = mac();
+ const { id, cfg } = await imessageSource();
+ await run(id, cfg, fake);
+ const edited = daySlug(ALICE, 2);
+ const emptied = daySlug(GROUP, 1);
+ await addFact(id, edited, 'Lunch is at noon');
+ await addFact(id, emptied, 'The venue is booked');
+ const alice = fake.chats[0]!.messages;
+ alice[0] = { ...alice[0]!, text: 'Lunch moves to one.', edited: true };
+ for (const m of fake.chats[1]!.messages) m.retracted = true;
+ const result = await run(id, cfg, fake, { now: NOW + 3_600_000 });
+ expect(result.modified).toBe(1);
+ expect(result.deleted).toBe(1);
+ expect(await activeFacts(id)).toEqual([]);
+ const rows = await pages(id);
+ expect(rows.map(r => r.slug)).not.toContain(emptied);
+ expect(rows.find(r => r.slug === edited)!.body).toContain('Lunch moves to one. _(edited)_');
+ });
+
+ test('after the window advanced, an edit older than the lookback is not re-read', async () => {
+ const fake = mac();
+ const { id, cfg } = await imessageSource();
+ await run(id, cfg, fake);
+ fake.chats[0]!.messages[3]!.text = 'Rewritten long after.';
+ fake.chats[0]!.messages.push({ rowid: 15, at: NOW + 30 * 60_000, text: 'A new message today.' });
+ const result = await run(id, cfg, fake, { now: NOW + DAY });
+ expect(result.added).toBe(1);
+ expect(result.modified).toBe(0);
+ expect((await pages(id)).find(r => r.slug === daySlug(ALICE, 20))!.body).toContain('An old note from three weeks ago.');
+ });
+
+ test('a last_message_at the helper sends in another shape stops the run as shape drift; no page is deleted', async () => {
+ const fake = mac();
+ const { id, cfg } = await imessageSource();
+ await run(id, cfg, fake);
+ const before = (await pages(id)).map(r => r.slug);
+ expect(before.length).toBe(4);
+ for (const threadRow of [(row: Record<string, unknown>) => ({ ...row, last_message_at: 802_000_000 }),
+ (row: Record<string, unknown>) => ({ ...row, last_message_at: '' }),
+ (row: Record<string, unknown>) => ({ ...row, last_message_at: false }),
+ (row: Record<string, unknown>) => ({ ...row, last_message_at: 'yesterday' })]) {
+ await expect(run(id, cfg, { ...fake, threadRow }, { now: NOW + 3_600_000 })).rejects.toMatchObject({ code: 'connector_shape_drift' });
+ expect((await pages(id)).map(r => r.slug)).toEqual(before);
+ }
+ });
+
+ test('a chat the helper lists with no last_message_at (null, or left out as the helper encodes nil) is still read, so its days are kept', async () => {
+ const fake = mac();
+ const { id, cfg } = await imessageSource();
+ await run(id, cfg, fake);
+ const before = (await pages(id)).map(r => r.slug);
+ for (const threadRow of [(row: Record<string, unknown>) => ({ ...row, last_message_at: null }),
+ ({ last_message_at: _, ...row }: Record<string, unknown>) => row]) {
+ const result = await run(id, cfg, { ...fake, threadRow }, { now: NOW + 3_600_000 });
+ expect(result.deleted).toBe(0);
+ expect((await pages(id)).map(r => r.slug)).toEqual(before);
+ }
+ });
+
+ for (const [problem, code] of [['no_access', 'apple_full_disk_access_pending'], ['schema_mismatch', 'apple_schema_mismatch'],
+ ['insufficient_scope', 'apple_helper_unauthorized'], ['source_disabled', 'apple_helper_not_running']] as const) {
+ test(`a helper refusal (${problem}) stops the run with ${code}; nothing is imported`, async () => {
+ const fake = mac();
+ fake.problem = problem;
+ const { id, cfg } = await imessageSource();
+ await expect(run(id, cfg, fake)).rejects.toMatchObject({ code });
+ expect(await pages(id)).toEqual([]);
+ });
+ }
+
+ test('a wrong token, a helper that is not listening and a missing port each stop the run with their code', async () => {
+ const { id, cfg } = await imessageSource();
+ const fake = mac();
+ fake.token = 'another-token';
+ await expect(run(id, cfg, fake)).rejects.toMatchObject({ code: 'apple_helper_unauthorized' });
+ const down = { ...mac(), down: true };
+ await expect(run(id, cfg, down)).rejects.toMatchObject({ code: 'apple_helper_not_running' });
+ await engine.unsetConfig('apple.helper.port').catch(() => undefined);
+ await expect(runIMessageSync(engine, id, cfg, options)).rejects.toMatchObject({ code: 'apple_helper_not_running' });
+ await engine.setConfig('apple.helper.port', '47001');
+ await withEnv({ GBRAIN_CONNECTOR_IMESSAGE_TOKEN: undefined, GBRAIN_HOME: home }, async () => {
+ await expect(runIMessageSync(engine, id, cfg, options)).rejects.toMatchObject({ code: 'apple_helper_unauthorized' });
+ });
+ await engine.unsetConfig('apple.helper.port');
+ expect(await pages(id)).toEqual([]);
+ });
+});
+
+test('sources add --kind imessage registers a database-only, owner-only source and refuses a directory', async () => {
+ const { params } = parseSourceLifecycleArgs(['add', 'messages', '--kind', 'imessage', '--timezone', 'America/Los_Angeles', '--lookback-days', '3']);
+ const created = await addSource(engine, params.options as never);
+ expect(created.local_path).toBeNull();
+ expect(created.config).toMatchObject({ kind: 'imessage', i_timezone: 'America/Los_Angeles', i_lookback_days: 3, federated: false });
+ expect(isOwnerOnlySourceConfig(created.config)).toBe(true);
+ for (const flag of [['--dir', join(home, 'x')], ['--record', 'git'], ['--visibility', 'private']]) {
+ expect(() => parseSourceLifecycleArgs(['add', 'messages-2', '--kind', 'imessage', ...flag])).toThrow();
+ }
+});
+
+test('on a brain with a Git checkout, no message text reaches the checkout, a commit or a push', async () => {
+ const repo = join(home, 'brain-repo');
+ const remote = join(home, 'brain-remote.git');
+ mkdirSync(repo, { recursive: true });
+ const git = (cwd: string, ...args: string[]) => spawnSync('git', args, { cwd, encoding: 'utf8' });
+ git(home, 'init', '--bare', '-q', remote);
+ git(repo, 'init', '-q', '-b', 'main');
+ git(repo, 'remote', 'add', 'origin', remote);
+ writeFileSync(join(repo, 'README.md'), '# notes\n');
+ git(repo, '-c', 'user.name=t', '-c', '[email protected]', 'add', '-A');
+ git(repo, '-c', 'user.name=t', '-c', '[email protected]', 'commit', '-q', '-m', 'init');
+ git(repo, 'push', '-q', 'origin', 'main');
+ await engine.executeRaw('INSERT INTO sources(id,name,local_path,config) VALUES($1,$1,$2,$3::text::jsonb)', ['notes-git', repo, JSON.stringify({ federated: true })]);
+ const head = git(repo, 'rev-parse', 'HEAD').stdout.trim();
+ const { id, cfg } = await imessageSource();
+ expect((await run(id, cfg, mac())).added).toBe(4);
+ expect(git(repo, 'rev-parse', 'HEAD').stdout.trim()).toBe(head);
+ expect(git(remote, 'rev-parse', 'main').stdout.trim()).toBe(head);
+ expect(git(repo, 'status', '--porcelain').stdout).toBe('');
+ const files = spawnSync('grep', ['-rl', 'Lunch at noon', home, '--exclude-dir=database'], { encoding: 'utf8' }).stdout;
+ expect(files).toBe('');
+ expect(readFileSync(join(repo, 'README.md'), 'utf8')).toBe('# notes\n');
+});
diff --git a/test/large-pages/conversation-slot-tagging-segmented.test.ts b/test/large-pages/conversation-slot-tagging-segmented.test.ts
new file mode 100644
index 0000000000..72cbd61097
--- /dev/null
+++ b/test/large-pages/conversation-slot-tagging-segmented.test.ts
@@ -0,0 +1,101 @@
+/**
+ * GBRA-574: slot tagging on a segmented conversation page (the incremental path, conversation-incremental.ts).
+ *
+ * Protects: the per-page cap reserves the tagging call with the extraction call, so a cap that fits only the
+ * extraction refuses before any call; a failed tagging call leaves its window settled (facts kept without slots, the
+ * failure counted, no repeat on the next run); an exhausted budget during tagging stops the run while the windows
+ * finished before it stay published.
+ * Seams: gateway chat transport stub (no provider call), segmented PGLite brain with no git repository.
+ */
+import { afterAll, afterEach, beforeAll, describe, expect, spyOn, test } from 'bun:test';
+import { createHash, randomUUID } from 'node:crypto';
+import { runExtractConversationFactsCore } from '../../src/commands/extract-conversation-facts.ts';
+import { __setChatTransportForTests, type ChatOpts, type ChatResult } from '../../src/core/ai/gateway.ts';
+import { BudgetExhausted } from '../../src/core/budget/budget-tracker.ts';
+import { getFactsExtractionMaxTokens } from '../../src/core/facts/extract.ts';
+import { SLOT_TAG_INPUT_CHARS, SLOT_TAG_MAX_TOKENS, SLOT_TAG_SYSTEM } from '../../src/core/facts/slot-tagging.ts';
+import { estimateChatCallUsd, estimateFactsExtractionUsd, PAGE_EMBED_CAP_KEY } from '../../src/core/page-embedding-budget.ts';
+import { PAGE_DERIVATION_CAP_KEY } from '../../src/core/page-spend.ts';
+import { openAppendBrain, type AppendBrain } from '../helpers/append-brain.ts';
+import { chatDays, chatPage, derivations, PAID_MODEL, SOURCE } from '../helpers/conversation-facts-incremental-cases.ts';
+
+const ALICE = 'people/alice-example';
+const sha = (s: string) => createHash('sha256').update(s).digest('hex').slice(0, 12);
+const reply = (text: string): ChatResult => ({ text, blocks: [{ type: 'text', text }], stopReason: 'end', model: PAID_MODEL, providerId: 'anthropic',
+ usage: { input_tokens: 10, output_tokens: 10, cache_read_tokens: 0, cache_creation_tokens: 0 } }) as ChatResult;
+const userText = (o: ChatOpts) => String(o.messages[0]?.content ?? '');
+/** The main call answers one fact about Alice per window, distinct per window. */
+const mainReply = (o: ChatOpts) => reply(JSON.stringify({ facts: [
+ { fact: `Alice Example works at Acme Example (note ${sha(userText(o))}).`, kind: 'fact', entity: ALICE, confidence: 1, notability: 'high' }] }));
+
+let brain: AppendBrain;
+beforeAll(async () => {
+ brain = await openAppendBrain('pglite');
+ const { engine } = brain;
+ await engine.setConfig(PAGE_EMBED_CAP_KEY, 'off');
+ await engine.setConfig(PAGE_DERIVATION_CAP_KEY, 'off');
+ await engine.setConfig('facts.extraction_enabled', 'true');
+ await engine.setConfig('facts.default_visibility', 'world');
+ await engine.setConfig('facts.extraction_model', PAID_MODEL);
+ await engine.putPage(ALICE, { type: 'person' as never, title: 'Alice Example', compiled_truth: '# Alice Example', timeline: '', frontmatter: {} });
+}, 120_000);
+afterAll(async () => { await brain.close(); }, 120_000);
+afterEach(() => { __setChatTransportForTests(null); });
+
+async function run(slug: string, tag: (o: ChatOpts, n: number) => ChatResult) {
+ const seen: ChatOpts[] = [];
+ let tags = 0;
+ __setChatTransportForTests(async o => { seen.push(o); return o.system === SLOT_TAG_SYSTEM ? tag(o, ++tags) : mainReply(o); });
+ const spy = spyOn(process.stderr, 'write').mockImplementation(() => true);
+ try { return { seen, result: await runExtractConversationFactsCore(brain.engine, { sourceId: 'default', slugs: [slug], sleepMs: 0 }) }; }
+ finally { spy.mockRestore(); }
+}
+const slotsOf = (slug: string) => brain.engine.executeRaw<{ fact: string; dimension: string | null; value: string | null }>(
+ 'SELECT fact, dimension, value FROM facts WHERE source_markdown_slug = $1 AND source = $2 AND expired_at IS NULL ORDER BY id', [slug, SOURCE]);
+
+/** Over the inline page size, so the page is stored segmented and extracted window by window. */
+const BODY = chatPage('Chat', chatDays(10, 100, 7));
+
+describe('slot tagging on a segmented page', () => {
+ let firstWindow = '';
+
+ test('a failed tagging call keeps its window settled: facts without slots, counted, not repeated', async () => {
+ const slug = `notes/slot-fail-${randomUUID().slice(0, 8)}`;
+ await brain.seed(slug, BODY);
+ const { seen, result } = await run(slug, (_o, n) => n === 1 ? reply('not json') : reply('{"slots":[{"i":1,"dimension":"employer","value":"Acme Example"}]}'));
+ const main = seen.filter(o => o.system !== SLOT_TAG_SYSTEM);
+ firstWindow = userText(main[0]!);
+ expect(main.length).toBeGreaterThan(1);
+ expect(seen.filter(o => o.system === SLOT_TAG_SYSTEM)).toHaveLength(main.length);
+ expect(result.slot_tagging_failed).toBe(1);
+ const rows = await slotsOf(slug);
+ expect(rows).toHaveLength(main.length);
+ expect(rows.filter(r => r.dimension === null)).toHaveLength(1);
+ expect(rows.filter(r => r.dimension === 'employer' && r.value === 'Acme Example')).toHaveLength(main.length - 1);
+ expect([...new Set((await derivations(brain.engine, slug)).states)]).toEqual(['done']);
+ expect((await run(slug, () => reply('{"slots":[]}'))).seen).toHaveLength(0);
+ }, 600_000);
+
+ test('the per-page cap reserves the tagging call: a cap that fits only the extraction refuses before any call', async () => {
+ const slug = `notes/slot-cap-${randomUUID().slice(0, 8)}`;
+ await brain.seed(slug, BODY);
+ expect(firstWindow).not.toBe('');
+ const extraction = estimateFactsExtractionUsd(PAID_MODEL, firstWindow.length, await getFactsExtractionMaxTokens(brain.engine));
+ const tagging = estimateChatCallUsd(PAID_MODEL, SLOT_TAG_INPUT_CHARS, SLOT_TAG_MAX_TOKENS);
+ await brain.engine.setConfig(PAGE_DERIVATION_CAP_KEY, String(extraction + tagging / 2));
+ try {
+ expect((await run(slug, () => reply('{"slots":[]}'))).seen).toHaveLength(0);
+ } finally { await brain.engine.setConfig(PAGE_DERIVATION_CAP_KEY, 'off'); }
+ }, 600_000);
+
+ test('an exhausted budget during tagging stops the run; windows finished before it stay published', async () => {
+ const slug = `notes/slot-budget-${randomUUID().slice(0, 8)}`;
+ await brain.seed(slug, chatPage('Chat', chatDays(10, 100, 9)));
+ const { result } = await run(slug, (_o, n) => {
+ if (n === 2) throw new BudgetExhausted('cap reached', { reason: 'cost', spent: 1, cap: 1 });
+ return reply('{"slots":[{"i":1,"dimension":"employer","value":"Acme Example"}]}');
+ });
+ expect(result.budget_exhausted).toBe(true);
+ expect(await slotsOf(slug)).toEqual([{ fact: expect.stringContaining('Alice Example works at Acme Example'), dimension: 'employer', value: 'Acme Example' }]);
+ }, 600_000);
+});
diff --git a/test/postgres-unit-arms.txt b/test/postgres-unit-arms.txt
index 4448810d44..9ed8269d1b 100644
--- a/test/postgres-unit-arms.txt
+++ b/test/postgres-unit-arms.txt
@@ -638,6 +638,7 @@ test/repair-file-drift-deleted-6712.test.ts
test/repair-file-drift-held-6712.test.ts
test/repair-file-drift-held-window-gbra133.test.ts
test/repair-file-drift-provenance-gbra133.test.ts
+test/repair-file-drift-whole-class.test.ts
test/repair-frontmatter-keys-sweep-6454.test.ts
test/repair-frontmatter.test.ts
test/repair-ghost-database-ahead-gbra133.test.ts
diff --git a/test/private-facts-grant-8194.test.ts b/test/private-facts-grant-8194.test.ts
index ee9fb0e855..419a0d6e91 100644
--- a/test/private-facts-grant-8194.test.ts
+++ b/test/private-facts-grant-8194.test.ts
@@ -48,6 +48,7 @@ import { testBackends } from './helpers/test-backends.ts';
import { isolatedPersistencePostgres } from './helpers/persistence-postgres.ts';
import { readsUnscopedOnPurpose } from './helpers/reads-unscoped.ts';
import { withEnv } from './helpers/with-env.ts';
+import { v319 } from '../src/core/schema-migrations/v319-principal-private-facts.ts';
import { TEST_WRITE_ATTRIBUTION } from './helpers/write-attribution.ts';
const GRANTED = 'pf-alpha';
@@ -375,7 +376,7 @@ describe('private_facts migration and operator output', () => {
expect(clientRefusal?.code).toBe('grant_schema_required');
const tokenRefusal = await rescopeLegacyToken(engine, parseRescopeTokenArgs(['alice-example', '--private-facts', 'granted-sources'])).then(() => null, (e: { code?: string }) => e);
expect(tokenRefusal?.code).toBe('grant_schema_required');
- await engine.setConfig('version', String(LATEST_VERSION - 1));
+ await engine.setConfig('version', String(v319.version - 1));
await runMigrations(engine);
expect(await engine.getConfig('version')).toBe(String(LATEST_VERSION));
const tokens = await engine.executeRaw<{ private_facts: string }>('SELECT private_facts FROM access_tokens');
diff --git a/test/repair-file-drift-deleted-side-d5.test.ts b/test/repair-file-drift-deleted-side-d5.test.ts
index bf400344a1..7746f2f7e3 100644
--- a/test/repair-file-drift-deleted-side-d5.test.ts
+++ b/test/repair-file-drift-deleted-side-d5.test.ts
@@ -207,5 +207,17 @@ for (const backend of testBackends()) describe(`[${backend}] PR A item 5: repair
expect(uncommitted.residuals).toMatchObject({ deletion_uncommitted: 1, other_provenance: 2 });
expect(uncommitted.listing![0]!.detail).toContain('deletion uncommitted: HEAD still holds the file');
}
+
+ // On a read-only mirror the purged_differs --prefer database preview still plans remove_file; the coordinator's mirror guard
+ // refuses any prepared file target, a removal included, so its apply leaves the upstream file and the checkout as they were.
+ await engine.executeRaw(`UPDATE sources SET config = config || '{"mirror_read_only": true}'::jsonb WHERE id='default'`);
+ const mirrorPreview = await run(engine, { state: 'purged_differs', prefer: 'database' });
+ expect(pages(mirrorPreview)).toEqual([expect.objectContaining({ slug: 'notes/gamma-example', action: 'remove_file' })]);
+ const mirrorBefore = await state(engine, root);
+ const mirrorApplied = await run(engine, { state: 'purged_differs', prefer: 'database', expect: mirrorPreview.preview_hash! });
+ expect(existsSync(join(root, 'notes/gamma-example.md'))).toBe(true);
+ const mirrorAfter = await state(engine, root);
+ expect([mirrorAfter.files, mirrorAfter.head, mirrorAfter.status]).toEqual([mirrorBefore.files, mirrorBefore.head, mirrorBefore.status]);
+ expect(mirrorApplied.outcomes).not.toHaveProperty('repaired');
}, { databaseUrl, setup }), 300_000);
});
diff --git a/test/repair-file-drift-whole-class-reapply.test.ts b/test/repair-file-drift-whole-class-reapply.test.ts
new file mode 100644
index 0000000000..4c3516965e
--- /dev/null
+++ b/test/repair-file-drift-whole-class-reapply.test.ts
@@ -0,0 +1,151 @@
+/**
+ * Whole-class apply, rerun cases (`gbrain repair file-drift --held --side unknown --prefer file --whole-class --apply --expect <hash> --yes`):
+ * - an apply that finished without applying a page (every pin refused, here changed_since_preview) leaves no progress record, so the
+ * same class previewed again under the same hash applies its pages instead of reporting complete with nothing applied;
+ * - a database error while reading the saved approval surfaces as that error, not class_manifest_stale: the approval stands
+ * and a plain rerun applies it;
+ * - a running apply renews its lease, so a second apply is refused class_apply_busy even past the lease's length; one whose
+ * lease another apply took stops class_apply_busy and leaves that apply's progress record alone;
+ * - the mirror flag is read for each page: a source made writable during the apply skips its later pages changed_since_preview.
+ * PGLite only: the Postgres arm's shards have no room left, and neither case depends on the backend. Synthetic content only.
+ */
+import { afterEach, describe, expect, test } from 'bun:test';
+import { execFileSync } from 'node:child_process';
+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import type { BrainEngine } from '../src/core/engine.ts';
+import type { OperationContext } from '../src/core/ops/contract.ts';
+import { RECOVERY_VERSION } from '../src/core/markdown.ts';
+import { withCoordinatedWrite } from '../src/core/persistence/context.ts';
+import { registerLocalWriter, withVerifiedLocalRegistration } from '../src/core/persistence/identity.ts';
+import { FILE_DRIFT_VERSION, writeGitHold } from '../src/core/persistence/sync-holds.ts';
+import { performManagedSync } from '../src/core/persistence/sync-run.ts';
+import { resolveRepairScope } from '../src/core/repair/core.ts';
+import { applyFileDriftClass, classLock, CLASS_PROGRESS_OP, classWindow, previewFileDriftClass, type ClassSelection } from '../src/core/repair/file-drift-class.ts';
+import { managedBrain } from './helpers/managed-brain.ts';
+import { connectTemplateBrain } from './helpers/brain-template.ts';
+import { TEST_WRITE_ATTRIBUTION } from './helpers/write-attribution.ts';
+
+const git = (root: string, ...args: string[]) => execFileSync('git', ['-C', root, '-c', 'user.name=Example', '-c', '[email protected]',
+ '-c', 'commit.gpgsign=false', ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
+const OPTS = { sourceId: 'default', noPull: true, noEmbed: true, noExtract: true };
+const SLUGS = ['notes/n00', 'notes/n01'];
+const doc = (title: string, body: string) => `---\ntype: concept\ntitle: ${title}\n---\n\n${body}\n`;
+const write = (root: string, body: (slug: string) => string) => {
+ for (const slug of SLUGS) { mkdirSync(join(root, 'notes'), { recursive: true }); writeFileSync(join(root, `${slug}.md`), doc(slug, body(slug))); }
+ git(root, 'add', '-A'); git(root, 'commit', '-qm', 'pages');
+};
+const coordinated = (engine: BrainEngine, sql: string, params: unknown[] = []) =>
+ engine.transaction(tx => withCoordinatedWrite(tx, ['default'], () => tx.executeRaw(sql, params), TEST_WRITE_ATTRIBUTION));
+const sel: ClassSelection = { sourceId: 'default', side: 'unknown', only: [], skip: [] };
+const asCli = <T>(engine: BrainEngine, run: () => Promise<T>) => registerLocalWriter(engine, 'cli').then(writer => withVerifiedLocalRegistration(engine, writer, run));
+const preview = (engine: BrainEngine) => asCli(engine, async () => previewFileDriftClass(engine, await resolveRepairScope(engine, 'default'), sel, { remote: false }));
+const apply = (ctx: OperationContext, hash: string, opts: Parameters<typeof applyFileDriftClass>[4] = {}) =>
+ asCli(ctx.engine, async () => applyFileDriftClass({ ...ctx, remote: false }, await resolveRepairScope(ctx.engine, 'default'), sel, hash, opts));
+const progressLock = async (engine: BrainEngine, hash: string) => (await engine.executeRaw<{ t: string | null }>(
+ "SELECT completed_keys->0->'lock'->>'token' AS t FROM op_checkpoints WHERE op=$1 AND fingerprint=$2", [CLASS_PROGRESS_OP, hash]))[0];
+const setMirror = (engine: BrainEngine, on: boolean) => engine.executeRaw(`UPDATE sources SET config = config || jsonb_build_object('mirror_read_only', $1::boolean) WHERE id='default'`, [on]);
+const body = async (engine: BrainEngine, slug: string) => (await engine.executeRaw<{ b: string }>("SELECT compiled_truth AS b FROM pages WHERE source_id='default' AND slug=$1", [slug]))[0]?.b;
+
+/** A read-only mirror whose two pages changed in the database two hours ago and whose files were rewritten upstream since, each held file_drift on side unknown. */
+async function mirrorHolds(engine: BrainEngine, root: string): Promise<void> {
+ expect((await performManagedSync(engine, OPTS)).status).toBe('first_sync');
+ await coordinated(engine, "UPDATE pages SET compiled_truth='An old database body.', updated_at=now() - interval '2 hours' WHERE source_id='default' AND slug = ANY($1::text[])", [SLUGS]);
+ write(root, slug => `A newer file body of ${slug}.`);
+ await coordinated(engine, "DELETE FROM op_checkpoints WHERE op='sync-import-provenance'");
+ await coordinated(engine, "UPDATE pages SET knowledge_revision=gen_random_uuid(), revision_write_request_id=NULL WHERE source_id='default'");
+ await setMirror(engine, true);
+ for (const slug of SLUGS) {
+ const [page] = await engine.executeRaw<{ id: string; revision: string; incarnation: string }>(`SELECT p.id::text AS id, p.knowledge_revision::text AS revision,
+ s.incarnation::text AS incarnation FROM pages p JOIN sources s ON s.id=p.source_id WHERE p.source_id='default' AND p.slug=$1`, [slug]);
+ await engine.transaction(tx => writeGitHold(tx, { source_id: 'default', incarnation: page!.incarnation, path: `${slug}.md`, source_path: `${slug}.md`, slug,
+ page_id: Number(page!.id), code: 'file_drift', message: `${slug}.md is held: file drift`, upstream_version: null, observed_at: new Date().toISOString(),
+ run_id: null, mode: 'managed', meta: { recovery_version: RECOVERY_VERSION, page_revision: page!.revision, sides: 'unknown', side: 'unknown', drift_version: FILE_DRIFT_VERSION } as never }));
+ }
+}
+
+afterEach(() => { classWindow.pages = 200; classLock.ttlMs = 120_000; });
+
+describe('whole-class apply reruns', () => {
+ const pgliteClone = async () => {
+ const dir = mkdtempSync(join(tmpdir(), 'gbrain-whole-class-reapply-'));
+ const engine = await connectTemplateBrain(join(dir, 'brain'));
+ return { engine, close: async () => { await engine.disconnect(); rmSync(dir, { recursive: true, force: true }); } };
+ };
+ const opts = () => ({ open: pgliteClone, setup: ({ root }: { root: string }) => { git(root, 'init', '-q'); write(root, slug => `The committed body of ${slug}.`); } });
+
+ test('an apply that applied nothing leaves no progress record, so the same class previewed again applies its pages', () => managedBrain(async ({ engine, ctx, root }) => {
+ await mirrorHolds(engine, root);
+ const first = (await preview(engine)).class_manifest!;
+ expect(first.pages).toBe(2);
+ await setMirror(engine, false);
+ const skipped = await apply(ctx, first.hash);
+ expect([skipped.complete, skipped.applied, skipped.skipped_pages.map(page => page.reason)]).toEqual([true, 0, ['changed_since_preview', 'changed_since_preview']]);
+ expect((await engine.executeRaw('SELECT 1 FROM op_checkpoints WHERE op=$1', [CLASS_PROGRESS_OP])).length).toBe(0);
+ await setMirror(engine, true);
+ const again = (await preview(engine)).class_manifest!;
+ expect(again.hash).toBe(first.hash);
+ const applied = await apply(ctx, again.hash);
+ expect([applied.complete, applied.applied, applied.skipped]).toEqual([true, 2, 0]);
+ expect(await body(engine, 'notes/n00')).toBe('A newer file body of notes/n00.');
+ }, opts()), 300_000);
+
+ test('a database error reading the saved approval is reported as that error, and a rerun applies the same approval', () => managedBrain(async ({ engine, ctx, root }) => {
+ await mirrorHolds(engine, root);
+ const m = (await preview(engine)).class_manifest!;
+ let failed = false;
+ const flaky = new Proxy(engine, { get(target, key, receiver) {
+ if (key !== 'executeRaw') return Reflect.get(target, key, receiver);
+ return (sql: string, params?: unknown[]) => {
+ if (!failed && sql.includes('AS fresh')) { failed = true; return Promise.reject(new Error('connection terminated unexpectedly')); }
+ return target.executeRaw(sql, params as never);
+ };
+ } }) as BrainEngine;
+ const error = await apply({ ...ctx, engine: flaky }, m.hash).then(() => null, e => e);
+ expect([failed, (error as { code?: string })?.code, (error as Error)?.message]).toEqual([true, undefined, 'connection terminated unexpectedly']);
+ const applied = await apply(ctx, m.hash);
+ expect([applied.complete, applied.applied, applied.skipped]).toEqual([true, 2, 0]);
+ }, opts()), 300_000);
+
+ test('a running apply renews its lease: a second apply past the lease length is refused class_apply_busy', () => managedBrain(async ({ engine, ctx, root }) => {
+ await mirrorHolds(engine, root);
+ const m = (await preview(engine)).class_manifest!;
+ classWindow.pages = 1;
+ classLock.ttlMs = 600;
+ let second: unknown;
+ const first = await apply(ctx, m.hash, { onWindow: async window => {
+ if (window !== 0) return;
+ await new Promise(resolve => setTimeout(resolve, 2000));
+ second = await apply(ctx, m.hash).then(result => result, e => e);
+ } });
+ expect((second as { code?: string })?.code).toBe('class_apply_busy');
+ expect([first.complete, first.applied]).toEqual([true, 2]);
+ }, opts()), 300_000);
+
+ test('an apply whose lease another apply took stops class_apply_busy, applies nothing more and leaves that progress record', () => managedBrain(async ({ engine, ctx, root }) => {
+ await mirrorHolds(engine, root);
+ const m = (await preview(engine)).class_manifest!;
+ classWindow.pages = 1;
+ const foreign = '00000000-0000-4000-8000-000000000001';
+ const first = await apply(ctx, m.hash, { onWindow: async window => {
+ if (window !== 0) return;
+ await engine.executeRaw(`UPDATE op_checkpoints SET completed_keys = jsonb_set(completed_keys, '{0,lock}', jsonb_build_object('token', $3::text, 'pid', 1, 'host', 'other-host', 'expires_at', 9999999999999))
+ WHERE op=$1 AND fingerprint=$2`, [CLASS_PROGRESS_OP, m.hash, foreign]);
+ } });
+ expect([first.complete, first.applied, first.stopped?.code]).toEqual([false, 1, 'class_apply_busy']);
+ expect((await progressLock(engine, m.hash))?.t).toBe(foreign);
+ expect(await body(engine, 'notes/n01')).toBe('An old database body.');
+ }, opts()), 300_000);
+
+ test('a source made writable during the apply skips its later pages changed_since_preview and leaves them held', () => managedBrain(async ({ engine, ctx, root }) => {
+ await mirrorHolds(engine, root);
+ const m = (await preview(engine)).class_manifest!;
+ classWindow.pages = 1;
+ const result = await apply(ctx, m.hash, { onWindow: async window => { if (window === 0) await setMirror(engine, false); } });
+ expect([result.complete, result.applied, result.skipped_pages]).toEqual([true, 1, [{ slug: 'notes/n01', reason: 'changed_since_preview' }]]);
+ expect(await body(engine, 'notes/n01')).toBe('An old database body.');
+ const held = await engine.executeRaw<{ p: string }>("SELECT completed_keys->0->>'path' AS p FROM op_checkpoints WHERE op='sync-hold'");
+ expect(held.map(row => row.p)).toContain('notes/n01.md');
+ }, opts()), 300_000);
+});
diff --git a/test/repair-file-drift-whole-class.test.ts b/test/repair-file-drift-whole-class.test.ts
new file mode 100644
index 0000000000..8276e902bb
--- /dev/null
+++ b/test/repair-file-drift-whole-class.test.ts
@@ -0,0 +1,361 @@
+/**
+ * Whole-class settle for held file-drift pages (`gbrain repair file-drift --held --side <side> --prefer file --whole-class`).
+ * - B1: on a read-only mirror the held window preview lists a side unknown or both page whose file is newer prefer_file, not no_drift.
+ * - The whole-class preview walks every window into one manifest (totals equal the per-window sums; no apply command until it
+ * completes); it refuses past the recovery-bytes limit (class_capacity_exceeded) and on a repo-less brain finds no held pages.
+ * - kept_protected_parts: a mirror page whose file-wins result needs protected parts in its file stays held through syncs.
+ * - The apply binds pins, never timestamps (a sync that rewrote the holds keeps the approval), imports database-only on a mirror
+ * (a page version first, revert restores it, the checkout byte-identical), resumes after a kill without applying a page twice,
+ * refuses a concurrent apply (class_apply_busy), an edited manifest (class_manifest_stale) and a remote caller.
+ * - The preview and the apply refuse an output path inside a checkout before writing, both authorize each page like the
+ * window preview, and a resumed walk stops at its deadline after one window.
+ * PGLite always; Postgres when DATABASE_URL is set. Synthetic content only.
+ */
+import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
+import { createHash, randomUUID } from 'node:crypto';
+import { execFileSync } from 'node:child_process';
+import { existsSync, mkdirSync, readdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';
+import { join } from 'node:path';
+import type { BrainEngine } from '../src/core/engine.ts';
+import type { OperationContext } from '../src/core/ops/contract.ts';
+import { RECOVERY_VERSION } from '../src/core/markdown.ts';
+import { withCoordinatedWrite } from '../src/core/persistence/context.ts';
+import { submitPageMutation } from '../src/core/persistence/page-mutations.ts';
+import { registerLocalWriter, withVerifiedLocalRegistration } from '../src/core/persistence/identity.ts';
+import { FILE_DRIFT_VERSION, requestGitHoldRetry, writeGitHold } from '../src/core/persistence/sync-holds.ts';
+import { performManagedSync } from '../src/core/persistence/sync-run.ts';
+import { resolveRepairScope, type RepairPlanOptions } from '../src/core/repair/core.ts';
+import { repairRunner } from '../src/core/repair/registry.ts';
+import { artifactDirectory } from '../src/core/repair/file-drift.ts';
+import { applyFileDriftClass, assertWholeClassSelection, classApplyLines, classWindow, CLASS_PROGRESS_OP, previewFileDriftClass, type ClassSelection } from '../src/core/repair/file-drift-class.ts';
+import { fileCommitEvidence, fileCommitEvidenceBatch } from '../src/core/repair/file-drift-compare.ts';
+import { managedBrain } from './helpers/managed-brain.ts';
+import { requirePostgresTestDatabase, testBackends } from './helpers/test-backends.ts';
+import { persistencePostgresTemplate } from './helpers/persistence-postgres.ts';
+import { connectTemplateBrain } from './helpers/brain-template.ts';
+import { TEST_WRITE_ATTRIBUTION } from './helpers/write-attribution.ts';
+import { waitFor } from './helpers/wait-for.ts';
+import { withEnv } from './helpers/with-env.ts';
+import { isolatedSharedSkillsEngine } from './helpers/shared-skills-engine.ts';
+import { mkdtempSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+
+const git = (root: string, ...args: string[]) => execFileSync('git', ['-C', root, '-c', 'user.name=Example', '-c', '[email protected]',
+ '-c', 'commit.gpgsign=false', ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
+const OPTS = { sourceId: 'default', noPull: true, noEmbed: true, noExtract: true };
+const logger = { info() {}, warn() {}, error() {} };
+const doc = (title: string, body: string) => `---\ntype: concept\ntitle: ${title}\n---\n\n${body}\n`;
+const commitAll = (root: string, message: string) => { git(root, 'add', '-A'); git(root, 'commit', '-qm', message); };
+const files = (root: string, entries: Record<string, string>) => {
+ for (const [slug, text] of Object.entries(entries)) { mkdirSync(join(root, slug, '..'), { recursive: true }); writeFileSync(join(root, `${slug}.md`), text); }
+};
+const coordinated = (engine: BrainEngine, sql: string, params: unknown[] = []) =>
+ engine.transaction(tx => withCoordinatedWrite(tx, ['default'], () => tx.executeRaw(sql, params), TEST_WRITE_ATTRIBUTION));
+const sel = (side = 'unknown'): ClassSelection => ({ sourceId: 'default', side, only: [], skip: [] });
+const asCli = <T>(engine: BrainEngine, run: () => Promise<T>) => registerLocalWriter(engine, 'cli').then(writer => withVerifiedLocalRegistration(engine, writer, run));
+const preview = (engine: BrainEngine, side = 'unknown', opts: Parameters<typeof previewFileDriftClass>[3] = {}) =>
+ asCli(engine, async () => previewFileDriftClass(engine, await resolveRepairScope(engine, 'default'), sel(side), { remote: false, ...opts }));
+const apply = (ctx: OperationContext, hash: string, opts: Parameters<typeof applyFileDriftClass>[4] = {}, side = 'unknown') =>
+ asCli(ctx.engine, async () => applyFileDriftClass({ ...ctx, remote: false }, await resolveRepairScope(ctx.engine, 'default'), sel(side), hash, opts));
+async function windowPreview(engine: BrainEngine, opts: Partial<RepairPlanOptions>) {
+ return asCli(engine, async () => (await repairRunner(engine, { apply: false, logger })).run('file-drift', await resolveRepairScope(engine, 'default'), { explicit: true, sourceFlag: 'default', ...opts } as never));
+}
+const classes = (plan: { listing?: Array<{ item: string; class: string }> }) => Object.fromEntries((plan.listing ?? []).map(entry => [entry.item.replace('default:', ''), entry.class]));
+const holdRows = async (engine: BrainEngine) => (await engine.executeRaw<{ r: { path: string; code: string; observed_at: string; upstream_version: string | null; meta: Record<string, unknown> } }>(
+ "SELECT completed_keys->0 AS r FROM op_checkpoints WHERE op='sync-hold' ORDER BY fingerprint")).map(({ r }) => r);
+const body = async (engine: BrainEngine, slug: string) => (await engine.executeRaw<{ b: string }>("SELECT compiled_truth AS b FROM pages WHERE source_id='default' AND slug=$1", [slug]))[0]?.b;
+/** Every byte of the checkout (Git's own directory excluded), its HEAD and its status: what "byte-identical" compares. */
+function checkout(root: string): string {
+ const hash = createHash('sha256');
+ const walk = (dir: string) => { for (const name of readdirSync(dir).sort()) { if (name === '.git') continue; const path = join(dir, name);
+ try { hash.update(path).update(readFileSync(path)); } catch { walk(path); } } };
+ walk(root);
+ return `${git(root, 'rev-parse', 'HEAD')} ${git(root, 'status', '--porcelain', '--ignored')} ${hash.digest('hex')}`;
+}
+
+async function seedHold(engine: BrainEngine, slug: string, side: string): Promise<void> {
+ const [page] = await engine.executeRaw<{ id: string; revision: string; incarnation: string }>(`SELECT p.id::text AS id, p.knowledge_revision::text AS revision,
+ s.incarnation::text AS incarnation FROM pages p JOIN sources s ON s.id=p.source_id WHERE p.source_id='default' AND p.slug=$1`, [slug]);
+ await engine.transaction(tx => writeGitHold(tx, { source_id: 'default', incarnation: page!.incarnation, path: `${slug}.md`, source_path: `${slug}.md`, slug,
+ page_id: Number(page!.id), code: 'file_drift', message: `${slug}.md is held: file drift`, upstream_version: null, observed_at: new Date().toISOString(),
+ run_id: null, mode: 'managed', meta: { recovery_version: RECOVERY_VERSION, page_revision: page!.revision, sides: side, side, drift_version: FILE_DRIFT_VERSION } as never }));
+}
+
+const names = (n: number, prefix = 'notes/n') => Array.from({ length: n }, (_, i) => `${prefix}${String(i).padStart(2, '0')}`);
+/** The committed pages a fixture starts from: notes/n00.., plus notes/newer-page and notes/protected when asked. */
+const setup = (n: number, extra: string[] = []) => ({ root }: { root: string }) => {
+ git(root, 'init', '-q');
+ files(root, Object.fromEntries([...names(n), ...extra].map(slug => [slug, doc(slug, `The committed body of ${slug}.`)])));
+ commitAll(root, 'pages');
+};
+/**
+ * A read-only mirror whose pages changed in the database two hours ago and whose files were rewritten upstream since: each held
+ * file_drift on `side` (`both` for the slugs in `both`), the file newer. notes/newer-page changed in the database after its file;
+ * notes/protected carries a protected key only the database holds.
+ */
+async function mirrorHolds(engine: BrainEngine, root: string, slugs: string[], extra: { newerPage?: boolean; protectedPage?: boolean; both?: string[]; large?: boolean } = {}): Promise<void> {
+ expect((await performManagedSync(engine, OPTS)).status).toBe('first_sync');
+ const all = [...slugs, ...(extra.newerPage ? ['notes/newer-page'] : []), ...(extra.protectedPage ? ['notes/protected'] : [])];
+ await coordinated(engine, "UPDATE pages SET compiled_truth='An old database body.', updated_at=now() - interval '2 hours' WHERE source_id='default' AND slug = ANY($1::text[])", [all]);
+ if (extra.protectedPage) await coordinated(engine, `UPDATE pages SET frontmatter = frontmatter || '{"captured_at": "2026-01-01T00:00:00Z"}'::jsonb, updated_at=now() - interval '2 hours'
+ WHERE source_id='default' AND slug='notes/protected'`);
+ files(root, Object.fromEntries(all.map(slug => [slug, doc(slug, `A newer file body of ${slug}.\n\nWith a second paragraph.${extra.large ? Array.from({ length: 800 }, (_, n) => `\n\nLine ${n} of a long upstream page.`).join('') : ''}`)])));
+ commitAll(root, 'upstream rewrites');
+ if (extra.newerPage) await coordinated(engine, "UPDATE pages SET compiled_truth='A newer database body.', updated_at=now() + interval '1 minute' WHERE source_id='default' AND slug='notes/newer-page'");
+ await coordinated(engine, "DELETE FROM op_checkpoints WHERE op='sync-import-provenance'");
+ await coordinated(engine, "UPDATE pages SET knowledge_revision=gen_random_uuid(), revision_write_request_id=NULL WHERE source_id='default'");
+ await engine.executeRaw(`UPDATE sources SET config = config || '{"mirror_read_only": true}'::jsonb WHERE id='default'`);
+ for (const slug of all) await seedHold(engine, slug, extra.both?.includes(slug) ? 'both' : 'unknown');
+}
+
+
+describe('whole-class selection and batched commit evidence', () => {
+ test('every refused selection names its code before anything is read', () => {
+ const code = (opts: Parameters<typeof assertWholeClassSelection>[0]) => { try { assertWholeClassSelection(opts); return 'ok'; } catch (error) { return (error as { code: string }).code; } };
+ expect([
+ code({ held: true, side: 'unknown', prefer: 'file', slugs: ['notes/a'] }), code({ held: true, side: 'unknown', prefer: 'file', allDrifted: true }), code({ side: 'unknown', prefer: 'file' }),
+ code({ held: true, side: 'unknown', prefer: 'database' }), code({ held: true, side: 'deleted', prefer: 'file' }), code({ held: true, side: 'unknown', prefer: 'file', state: 'file_gone' }),
+ code({ held: true, side: 'sideways', prefer: 'file' }), code({ held: true, side: 'unknown' }), code({ held: true, side: 'both', prefer: 'file' }),
+ ]).toEqual(['invalid_params', 'invalid_params', 'invalid_params', 'whole_class_prefer_unsupported', 'whole_class_prefer_unsupported', 'whole_class_prefer_unsupported', 'invalid_params', 'invalid_params', 'ok']);
+ });
+
+ test('a source bound to a subdirectory reads the same evidence as one path at a time, and a path the batch cannot settle is left to that read', () => {
+ const top = mkdtempSync(join(tmpdir(), 'gbrain-batch-evidence-'));
+ try {
+ git(top, 'init', '-q');
+ const root = join(top, 'brain');
+ files(root, { 'notes/a': 'committed\n', 'notes/b': 'committed\n' });
+ commitAll(top, 'pages');
+ writeFileSync(join(root, 'notes/b.md'), 'uncommitted\n');
+ writeFileSync(join(root, 'notes/new.md'), 'never committed\n');
+ const batch = fileCommitEvidenceBatch(root, ['notes/a.md', 'notes/b.md', 'notes/new.md']);
+ expect(batch.get('notes/a.md')).toEqual(fileCommitEvidence(root, 'notes/a.md'));
+ expect(batch.get('notes/b.md')).toEqual(fileCommitEvidence(root, 'notes/b.md'));
+ expect(batch.get('notes/a.md')?.committed_at).not.toBeNull();
+ expect(batch.get('notes/b.md')?.uncommitted).toBe(true);
+ expect(batch.has('notes/new.md')).toBe(false);
+ expect(fileCommitEvidenceBatch(join(top, 'not-a-checkout'), ['notes/a.md']).size).toBe(0);
+ } finally { rmSync(top, { recursive: true, force: true }); }
+ });
+});
+
+afterEach(() => { classWindow.pages = 200; });
+
+describe.each(testBackends())('whole-class file-drift on a read-only mirror (%s)', backend => {
+ const databaseUrl = backend === 'postgres' ? requirePostgresTestDatabase() : undefined;
+ let template: Awaited<ReturnType<typeof persistencePostgresTemplate>> | undefined;
+ beforeAll(async () => { if (databaseUrl) template = await persistencePostgresTemplate(databaseUrl); }, 120_000);
+ afterAll(async () => { await template?.dispose(); });
+ const pgliteClone = async () => {
+ const dir = mkdtempSync(join(tmpdir(), 'gbrain-whole-class-'));
+ const engine = await connectTemplateBrain(join(dir, 'brain'));
+ return { engine, close: async () => { await engine.disconnect(); rmSync(dir, { recursive: true, force: true }); } };
+ };
+ const db = () => ({ open: template ? template.clone : pgliteClone });
+
+ test('B1: a held side-unknown or both page whose file is newer is listed prefer_file by the window preview, not no_drift', () => managedBrain(async ({ engine, root }) => {
+ await mirrorHolds(engine, root, names(3), { both: ['notes/n02'] });
+ expect(classes(await windowPreview(engine, { held: true, side: 'unknown', prefer: 'file' }))).toEqual({ 'notes/n00': 'prefer_file', 'notes/n01': 'prefer_file' });
+ expect(classes(await windowPreview(engine, { held: true, side: 'both', prefer: 'file' }))).toEqual({ 'notes/n02': 'prefer_file' });
+ expect(Object.values(classes(await windowPreview(engine, { held: true, side: 'unknown', prefer: 'database' })))).not.toContain('prefer_database');
+ expect(git(root, 'status', '--porcelain')).toBe('');
+ }, { ...db(), setup: setup(3) }), 300_000);
+
+ test('the preview walks every window into one manifest whose totals equal the per-window sums, with no apply command until it completes', () => managedBrain(async ({ engine, root }) => {
+ await mirrorHolds(engine, root, names(5), { newerPage: true, protectedPage: true });
+ const single = await windowPreview(engine, { held: true, side: 'unknown', prefer: 'file' }) as unknown as { listing: Array<{ class: string }>; details: { lost_lines_total: number } };
+ classWindow.pages = 3;
+ const stopped = await preview(engine, 'unknown', { deadline: Date.now() });
+ expect(stopped.class_manifest!.complete).toBe(false);
+ expect(stopped.apply_command).toBeUndefined();
+ expect(stopped.card).toBeUndefined();
+ expect(stopped.resume_command).toContain('--whole-class --cursor c1.');
+ expect(JSON.parse(readFileSync(stopped.class_manifest!.path, 'utf8')).complete).toBe(false);
+ const resumed = await preview(engine, 'unknown', { cursor: stopped.resume_command!.split('--cursor ')[1]!.trim(), deadline: Date.now() });
+ expect(resumed.class_manifest!.complete).toBe(false);
+ expect(JSON.parse(readFileSync(resumed.class_manifest!.path, 'utf8')).windows).toBe(2);
+ const cursor = resumed.resume_command!.split('--cursor ')[1]!.trim();
+ const done = await preview(engine, 'unknown', { cursor });
+ const m = done.class_manifest!;
+ expect(Object.keys(m).sort()).toEqual(['complete', 'hash', 'lost_lines_total', 'pages', 'path', 'residual', 'top']);
+ expect(m.complete).toBe(true);
+ const manifest = JSON.parse(readFileSync(m.path, 'utf8'));
+ expect(manifest.windows).toBe(3);
+ expect([manifest.mirror, manifest.file_drift_version, manifest.gbrain_version.length > 0]).toEqual([true, FILE_DRIFT_VERSION, true]);
+ expect(m.pages).toBe(single.listing.filter(entry => entry.class === 'prefer_file').length);
+ expect(m.pages).toBe(5);
+ expect(m.lost_lines_total).toBe(single.details.lost_lines_total);
+ expect([m.residual.kept_newer_page.count, m.residual.kept_protected_parts.count]).toEqual([1, 1]);
+ expect(m.top[0]!.lost_lines).toBeGreaterThan(0);
+ expect(done.apply_command).toContain(`--whole-class --apply --expect ${m.hash} --yes`);
+ expect(done.card!.join('\n')).toContain('gbrain revert');
+ expect(existsSync(stopped.class_manifest!.path)).toBe(false);
+ await coordinated(engine, "UPDATE pages SET text_projection_revision = CASE WHEN text_projection_revision IS NULL THEN knowledge_revision ELSE NULL END WHERE source_id='default'");
+ const fresh = await preview(engine);
+ expect(fresh.class_manifest!.hash).toBe(m.hash);
+ }, { ...db(), setup: setup(5, ['notes/newer-page', 'notes/protected']) }), 300_000);
+
+ test('class_capacity_exceeded names the bytes and the limit and writes nothing', () => managedBrain(async ({ engine, root }) => {
+ await mirrorHolds(engine, root, names(3), { large: true });
+ const first = (await preview(engine)).class_manifest!;
+ const needed = JSON.parse(readFileSync(first.path, 'utf8')).backup_bytes as number;
+ unlinkSync(first.path);
+ await engine.setConfig('persistence.limits.brain_recovery_bytes', String(needed - 1));
+ const error: any = await preview(engine).then(() => null, e => e);
+ expect(error?.code).toBe('class_capacity_exceeded');
+ expect(error.message).toContain('persistence.limits.brain_recovery_bytes');
+ expect(error.fix.argv).toEqual(['gbrain', 'config', 'get', 'persistence.limits.brain_recovery_bytes']);
+ const dir = artifactDirectory();
+ expect(existsSync(dir) ? readdirSync(dir).filter(name => name.startsWith('class-')) : []).toEqual([]);
+ }, { ...db(), setup: setup(3) }), 300_000);
+
+ test('the preview and the apply refuse an output path inside a checkout before writing, and leave a page outside the CLI grant held', () => managedBrain(async ({ engine, root }) => {
+ await mirrorHolds(engine, root, ['notes/n00', 'other/o00']);
+ const before = checkout(root);
+ const writer = await registerLocalWriter(engine, 'cli');
+ const scope = await resolveRepairScope(engine, 'default');
+ const ctx = { engine, config: { engine: engine.kind, embedding_disabled: true }, sourceId: 'default', remote: false, dryRun: false, logger } as OperationContext;
+ const inside = <T>(run: () => Promise<T>) => withEnv({ GBRAIN_HOME: root }, () => withVerifiedLocalRegistration(engine, writer, run).then(() => null, e => e));
+ expect(((await inside(() => previewFileDriftClass(engine, scope, sel(), { remote: false }))) as any)?.code).toBe('permission_denied');
+ const m = (await preview(engine)).class_manifest!;
+ expect(m.pages).toBe(2);
+ expect(((await inside(() => applyFileDriftClass(ctx, scope, sel(), m.hash))) as any)?.code).toBe('permission_denied');
+ expect(['repair-previews', 'reconciliation-previews'].filter(name => existsSync(join(root, '.gbrain', name)))).toEqual([]);
+ rmSync(join(root, '.gbrain'), { recursive: true, force: true });
+ const narrow = await registerLocalWriter(engine, 'cli', { sourceIds: ['*'], operations: null, scopes: ['read', 'write'], slugPrefixes: ['notes/'] }, true);
+ const asNarrow = <T>(run: () => Promise<T>) => withVerifiedLocalRegistration(engine, narrow, run);
+ const result = await asNarrow(() => previewFileDriftClass(engine, scope, sel(), { remote: false }));
+ expect(result.class_manifest!.top.map(page => page.slug)).toEqual(['notes/n00']);
+ expect(result.other).toEqual({ refused_permission_denied: 1 });
+ const applied = await asNarrow(() => applyFileDriftClass(ctx, scope, sel(), m.hash));
+ expect([applied.complete, applied.applied, applied.skipped_pages]).toEqual([true, 1, [{ slug: 'other/o00', reason: 'refused_permission_denied' }]]);
+ expect(await body(engine, 'other/o00')).toBe('An old database body.');
+ expect(checkout(root)).toBe(before);
+ }, { ...db(), setup: setup(1, ['other/o00']) }), 300_000);
+
+ test('kept_protected_parts: the apply leaves the page held and its protected parts as stored through two syncs, and the checkout byte-identical', () => managedBrain(async ({ engine, ctx, root }) => {
+ await mirrorHolds(engine, root, names(1), { protectedPage: true });
+ const before = checkout(root);
+ const m = (await preview(engine)).class_manifest!;
+ expect([m.pages, m.residual.kept_protected_parts.count]).toEqual([1, 1]);
+ const window = await windowPreview(engine, { held: true, side: 'unknown', prefer: 'file' });
+ expect(classes(window)['notes/protected']).toBe('kept_protected_parts');
+ expect((await apply(ctx, m.hash)).complete).toBe(true);
+ await performManagedSync(engine, OPTS);
+ await performManagedSync(engine, OPTS);
+ const held = (await holdRows(engine)).find(h => h.path === 'notes/protected.md')!;
+ expect([held.code, held.meta.side]).toEqual(['file_drift', 'unknown']);
+ const [page] = await engine.executeRaw<{ fm: Record<string, unknown>; b: string }>("SELECT frontmatter AS fm, compiled_truth AS b FROM pages WHERE slug='notes/protected'");
+ expect(page!.fm.captured_at).toBe('2026-01-01T00:00:00Z');
+ expect(page!.b).toBe('An old database body.');
+ expect(checkout(root)).toBe(before);
+ }, { ...db(), setup: setup(1, ['notes/protected']) }), 300_000);
+
+ test('the apply imports database-only: a page version first, revert restores it, the checkout byte-identical, and the next sync releases the holds', () => managedBrain(async ({ engine, ctx, root }) => {
+ await mirrorHolds(engine, root, names(2), { newerPage: true });
+ const before = checkout(root);
+ const m = (await preview(engine)).class_manifest!;
+ const result = await apply(ctx, m.hash);
+ expect([result.complete, result.applied, result.skipped]).toEqual([true, 2, 0]);
+ expect(await body(engine, 'notes/n00')).toContain('A newer file body of notes/n00.');
+ expect(await body(engine, 'notes/newer-page')).toBe('A newer database body.');
+ expect(checkout(root)).toBe(before);
+ const [version] = await engine.executeRaw<{ id: number; b: string }>("SELECT v.id, v.compiled_truth AS b FROM page_versions v JOIN pages p ON p.id=v.page_id WHERE p.slug='notes/n00' ORDER BY v.id DESC LIMIT 1");
+ expect(version!.b).toBe('An old database body.');
+ await performManagedSync(engine, OPTS);
+ expect((await holdRows(engine)).map(h => h.path)).toEqual(['notes/newer-page.md']);
+ const current = await engine.readPageSnapshot('notes/n00', { sourceId: 'default' });
+ const requestId = randomUUID();
+ await submitPageMutation(ctx, { operation: 'revert_version', params: { slug: 'notes/n00', version_id: version!.id, request_id: requestId, expected_revision: current!.revision } });
+ await waitFor(async () => (await engine.executeRaw<{ state: string }>('SELECT state FROM persistence_requests WHERE request_id=$1::uuid', [requestId]))[0]?.state === 'committed', { timeoutMs: 20_000, label: 'revert commits' });
+ expect(await body(engine, 'notes/n00')).toBe('An old database body.');
+ expect(checkout(root)).toBe(before);
+ }, { ...db(), setup: setup(2, ['notes/newer-page']) }), 300_000);
+
+ test('a sync that rewrites the hold records between preview and apply keeps the approval: unchanged pages still apply', () => managedBrain(async ({ engine, ctx, root }) => {
+ await mirrorHolds(engine, root, names(3));
+ const [{ i }] = await engine.executeRaw<{ i: string }>("SELECT incarnation::text AS i FROM sources WHERE id='default'");
+ const rehold = async () => { await requestGitHoldRetry(engine, 'default', i, names(3).map(slug => `${slug}.md`)); await performManagedSync(engine, OPTS); };
+ await rehold();
+ const m = (await preview(engine)).class_manifest!;
+ expect(m.pages).toBe(3);
+ const seen = Object.fromEntries((await holdRows(engine)).map(h => [h.path, h]));
+ await rehold();
+ const after = await holdRows(engine);
+ expect(after.map(h => h.path)).toEqual(Object.keys(seen));
+ expect(after.every(h => h.observed_at !== seen[h.path]!.observed_at && h.upstream_version === seen[h.path]!.upstream_version && h.meta.side === 'unknown')).toBe(true);
+ const result = await apply(ctx, m.hash);
+ expect(result.skipped_pages).toEqual([]);
+ expect([result.complete, result.applied, result.skipped]).toEqual([true, 3, 0]);
+ }, { ...db(), setup: setup(3) }), 300_000);
+
+ test('an apply killed after window 1 resumes at window 2 and applies no page twice; the stopped result leads with its resume command', () => managedBrain(async ({ engine, ctx, root }) => {
+ await mirrorHolds(engine, root, names(4));
+ classWindow.pages = 2;
+ const m = (await preview(engine)).class_manifest!;
+ const killed = await apply(ctx, m.hash, { onWindow: window => { if (window === 0) throw new Error('killed'); } });
+ expect([killed.complete, killed.applied, killed.remaining]).toEqual([false, 2, 2]);
+ expect(killed.stopped?.code).toBe('unexpected_error');
+ expect(existsSync(killed.trace!)).toBe(true);
+ const lines = classApplyLines(killed);
+ expect(lines[0]).toBe(`Resume: ${killed.resume_command}`);
+ expect(lines[1]).toContain('applied 2, skipped 0, remaining 2');
+ const windows: number[] = [];
+ const resumed = await apply(ctx, m.hash, { onWindow: window => { windows.push(window); } });
+ expect([resumed.complete, resumed.applied, resumed.skipped]).toEqual([true, 4, 0]);
+ expect(windows).toEqual([1]);
+ const versions = await engine.executeRaw<{ slug: string; n: number }>("SELECT p.slug, count(*)::int AS n FROM page_versions v JOIN pages p ON p.id=v.page_id GROUP BY p.slug ORDER BY p.slug");
+ expect(versions).toEqual(names(4).map(slug => ({ slug, n: 1 })));
+ }, { ...db(), setup: setup(4) }), 300_000);
+
+ test('a second concurrent apply of one manifest is refused class_apply_busy', () => managedBrain(async ({ engine, ctx, root }) => {
+ await mirrorHolds(engine, root, names(2));
+ classWindow.pages = 1;
+ const m = (await preview(engine)).class_manifest!;
+ let release!: () => void;
+ const gate = new Promise<void>(resolve => { release = resolve; });
+ let entered!: () => void;
+ const inside = new Promise<void>(resolve => { entered = resolve; });
+ const first = apply(ctx, m.hash, { onWindow: async window => { if (window === 0) { entered(); await gate; } } });
+ await inside;
+ const second: any = await apply(ctx, m.hash).then(() => null, e => e);
+ expect(second?.code).toBe('class_apply_busy');
+ release();
+ expect((await first).complete).toBe(true);
+ }, { ...db(), setup: setup(2) }), 300_000);
+
+ test('an edited manifest is refused class_manifest_stale with what changed and the fresh preview; nothing is written', () => managedBrain(async ({ engine, ctx, root }) => {
+ await mirrorHolds(engine, root, names(2));
+ const m = (await preview(engine)).class_manifest!;
+ const manifest = JSON.parse(readFileSync(m.path, 'utf8'));
+ manifest.pages[0].lost_lines = 0;
+ manifest.pages[0].revision = randomUUID();
+ writeFileSync(m.path, JSON.stringify(manifest));
+ const error: any = await apply(ctx, m.hash).then(() => null, e => e);
+ expect(error?.code).toBe('class_manifest_stale');
+ expect(error.message).toContain('1 page(s) or their pins differ');
+ expect(error.suggestion).toContain('gbrain repair file-drift --source default --held --side unknown --prefer file --whole-class');
+ expect(await body(engine, 'notes/n00')).toBe('An old database body.');
+ expect((await engine.executeRaw('SELECT 1 FROM op_checkpoints WHERE op=$1', [CLASS_PROGRESS_OP])).length).toBe(0);
+ }, { ...db(), setup: setup(2) }), 300_000);
+
+ test('a remote caller cannot reach --whole-class: preview and apply refuse before reading anything', () => managedBrain(async ({ engine, ctx }) => {
+ const scope = await resolveRepairScope(engine, 'default');
+ expect(((await previewFileDriftClass(engine, scope, sel(), { remote: true }).then(() => null, e => e)) as any)?.code).toBe('permission_denied');
+ expect(((await previewFileDriftClass(engine, scope, sel()).then(() => null, e => e)) as any)?.code).toBe('permission_denied');
+ expect(((await applyFileDriftClass({ ...ctx, remote: true }, scope, sel(), 'a'.repeat(64)).then(() => null, e => e)) as any)?.code).toBe('permission_denied');
+ }, { ...db() }), 120_000);
+
+ test('a repo-less brain has no held pages: the preview says so and refuses nothing', async () => {
+ const home = mkdtempSync(join(tmpdir(), 'gbrain-whole-class-'));
+ try {
+ await withEnv({ GBRAIN_HOME: home, DATABASE_URL: undefined, GBRAIN_DATABASE_URL: undefined }, async () => {
+ const { engine, close } = await isolatedSharedSkillsEngine(databaseUrl);
+ try {
+ expect((await engine.executeRaw<{ local_path: string | null }>("SELECT local_path FROM sources WHERE id='default'"))[0]?.local_path ?? null).toBeNull();
+ expect(await preview(engine)).toEqual({ none: true, other: {} });
+ } finally { await close(); }
+ });
+ } finally { rmSync(home, { recursive: true, force: true }); }
+ }, 120_000);
+});
diff --git a/test/schema-cli.test.ts b/test/schema-cli.test.ts
index 62da996634..9ca15ab644 100644
--- a/test/schema-cli.test.ts
+++ b/test/schema-cli.test.ts
@@ -98,7 +98,7 @@ describe('gbrain schema CLI (Phase C)', () => {
// v0.42.56.0 (#2390): extended to 27 by adding the Life Chronicle
// `event` + `diary` temporal types (life/events/, life/diary/).
// GST-2731: extended to 29 by adding the `facts` annotation type.
- expect(r.stdout).toContain('Page types (29)');
+ expect(r.stdout).toContain('Page types (30)');
expect(r.stdout).toContain('facts :: annotation');
expect(r.stdout).toContain('event :: temporal');
expect(r.stdout).toContain('diary :: temporal');
diff --git a/test/scripts/stress-gate.test.ts b/test/scripts/stress-gate.test.ts
index 9af907c9df..35022221c3 100644
--- a/test/scripts/stress-gate.test.ts
+++ b/test/scripts/stress-gate.test.ts
@@ -57,6 +57,17 @@ describe('gate plan', () => {
expect(plan.shards.flatMap(s => s.items).reduce((n, i) => n + i.count, 0)).toBe(20);
});
+ test('a changed file with no measured weight is planned at its lane p95 and split under the 12-minute budget', () => {
+ const { root, base } = repo({ 'test/a.test.ts': "test('a', () => {});\n" });
+ const head = commit(root, { 'test/new.test.ts': "test('new', () => {});\n" });
+ const unit = new Map(Array.from({ length: 20 }, (_, i) => [`test/w${i}.test.ts`, (i + 1) * 10_000] as [string, number]));
+ const plan = isPlan(planGate(root, { event: 'pull_request', baseSha: base, headSha: head }, { ...weights(), unit }));
+ expect(plan.files).toEqual([{ file: 'test/new.test.ts', profile: 'unit', iterations: 10, estimateMs: 10 * (190_000 + 3000) }]);
+ expect(plan.shards.map(s => s.items.reduce((n, i) => n + i.count, 0)).sort()).toEqual([1, 3, 3, 3]);
+ expect(plan.shards.every(s => s.estimateMs <= 12 * 60_000)).toBe(true);
+ expect(plan.shards.flatMap(s => s.items).reduce((n, i) => n + i.count, 0)).toBe(10);
+ });
+
test('a missing merge base fails the plan with the fetch next step', () => {
const { root } = repo({ 'test/a.test.ts': '' });
const result = planGate(root, { event: 'merge_group', baseSha: 'f'.repeat(40), headSha: 'HEAD' }, weights());
diff --git a/test/slack-users-fallback.test.ts b/test/slack-users-fallback.test.ts
new file mode 100644
index 0000000000..a2e092993b
--- /dev/null
+++ b/test/slack-users-fallback.test.ts
@@ -0,0 +1,58 @@
+/**
+ * #9601: a user the users listing lacked is cached under its raw id. A later run that renders that user lists the
+ * workspace again once the listing is a day old, so a new member gets a name; within the day it does not re-list,
+ * so a Slack Connect user (never in the listing) does not cost a full listing every run.
+ */
+import { afterAll, beforeAll, expect, test } from 'bun:test';
+import { mkdtempSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import type { BrainEngine } from '../src/core/engine.ts';
+import { connectTemplateBrain } from './helpers/brain-template.ts';
+import { options } from './helpers/connector-fixture.ts';
+import { slackFetch, slackTs, type FakeSlack, slackTestToken } from './helpers/slack-fixture.ts';
+import { runSlackSync } from '../src/core/slack/slack-source.ts';
+import { parseSlackSourceConfig } from '../src/core/slack/source-config.ts';
+import { slackApi } from '../src/core/slack/client.ts';
+
+const HOUR = 3_600_000;
+const NOW = Date.parse('2026-06-15T12:00:00Z');
+
+let home: string;
+let engine: BrainEngine;
+beforeAll(async () => {
+ home = mkdtempSync(join(tmpdir(), 'gbrain-slack-users-'));
+ engine = await connectTemplateBrain(join(home, 'database'));
+ await engine.executeRaw('UPDATE persistence_brain SET enabled=false WHERE singleton=1');
+}, 120_000);
+afterAll(async () => { await engine.disconnect(); rmSync(home, { recursive: true, force: true }); });
+
+test('a user cached under the raw id is looked up again once the listing is a day old, not before', async () => {
+ const fake: FakeSlack = { teamId: 'TACME00001', users: {}, calls: [], channels: [
+ { id: 'CGENERAL01', name: 'general', messages: [{ ts: slackTs(NOW - 50 * HOUR), user: 'UBOB000001', text: 'First sync, before the listing had me.' }] },
+ ] };
+ const config = { kind: 'slack', s_channels: 'CGENERAL01', s_record: 'database', federated: false };
+ await engine.executeRaw('INSERT INTO sources(id,name,local_path,config) VALUES($1,$1,NULL,$2::text::jsonb)', ['slack-users', JSON.stringify(config)]);
+ const cfg = parseSlackSourceConfig(config, '');
+ const sync = (at: number) => runSlackSync(engine, 'slack-users', cfg, { ...options }, {
+ api: slackApi({ token: slackTestToken(), userAgent: 'gbrain-test', fetchImpl: slackFetch(fake), sleep: async () => {}, minDelayMs: 0, now: () => at }), now: () => at });
+ const listings = () => fake.calls.filter(c => c === 'users.list').length;
+ const dayBody = async (text: string) => (await engine.executeRaw<{ body: string }>(
+ `SELECT compiled_truth AS body FROM pages WHERE source_id='slack-users' AND deleted_at IS NULL AND compiled_truth LIKE $1`, [`%${text}%`]))[0]?.body ?? '';
+
+ await sync(NOW);
+ expect(listings()).toBe(1);
+
+ fake.users.UBOB000001 = { name: 'Bob Example' };
+ fake.channels[0]!.messages.push({ ts: slackTs(NOW - 26 * HOUR), user: 'UBOB000001', text: 'Second sync, an hour later.' });
+ await sync(NOW + HOUR);
+ expect(listings()).toBe(1);
+ expect(await dayBody('Second sync')).toContain('**UBOB000001**');
+
+ fake.channels[0]!.messages.push({ ts: slackTs(NOW - 2 * HOUR), user: 'UBOB000001', text: 'Third sync, a day later.' });
+ await sync(NOW + 25 * HOUR);
+ expect(listings()).toBe(2);
+ const body = await dayBody('Third sync');
+ expect(body).toContain('**Bob Example**');
+ expect(body).not.toContain('**UBOB000001**');
+}, 120_000);
diff --git a/test/sync-connector-dry-run-9449.test.ts b/test/sync-connector-dry-run-9449.test.ts
index 99920c7092..725400e888 100644
--- a/test/sync-connector-dry-run-9449.test.ts
+++ b/test/sync-connector-dry-run-9449.test.ts
@@ -23,6 +23,7 @@ const configs: Record<string, Record<string, unknown>> = {
github: githubConfig,
meetings: { kind: 'meetings', m_provider: 'fireflies', m_record: 'database', federated: false },
slack: { kind: 'slack', s_channels: 'CGENERAL01' },
+ imessage: { kind: 'imessage', federated: false },
};
const googleContacts = withGoogleAccount(async () => json({ connections: [contact('first', 'First Example')], nextSyncToken: 'contacts-1' }));
const providers: Record<string, (url: string, init?: RequestInit) => Promise<Response>> = {
@@ -30,6 +31,7 @@ const providers: Record<string, (url: string, init?: RequestInit) => Promise<Res
github: githubFetch(),
meetings: async () => json({ data: {} }),
slack: async () => json({ ok: true, messages: [] }),
+ imessage: async () => json({ threads: [] }),
};
function files(dir: string): string[] {
diff --git a/test/sync-mirror-parked-gst2843.test.ts b/test/sync-mirror-parked-gst2843.test.ts
index 69d734d7de..07d67e2eb5 100644
--- a/test/sync-mirror-parked-gst2843.test.ts
+++ b/test/sync-mirror-parked-gst2843.test.ts
@@ -216,29 +216,32 @@ describe.each(testBackends())('GST-2843: the held comparison on a read-only mirr
expect(git(root, 'status', '--porcelain')).toBe('');
}, { databaseUrl, setup: heldSetup }), 240_000);
- test('GST-2869: on a mirror the comparison names no file-drift preview, and the route it names resolves the page once the source is writable', () => managedBrain(async ({ engine, root }) => {
+ test('GST-2869 / whole-class: on a mirror the comparison names the whole-class preview of the side, and a page still resolves once the source is writable', () => managedBrain(async ({ engine, root }) => {
await heldPages(engine, root);
const compared = await repair(engine, { held: true }) as Plan;
const why = Object.fromEntries((compared.details!.pages as Array<{ slug: string; would: string; why: string }>).map(page => [page.slug, page.why]));
for (const slug of ['notes/newer-file', 'notes/newer-page']) {
- expect(why[slug]).not.toContain('gbrain repair file-drift');
- expect(why[slug]).toContain('gbrain sources mirror-writable default');
+ expect(why[slug]).toContain('gbrain repair file-drift --source default --held --side unknown --prefer file --whole-class');
+ expect(why[slug]).toContain('database-only');
}
+ expect(why['notes/newer-page']).toContain('kept_newer_page');
const next = (compared.details!.next_actions ?? []) as string[];
- expect(next.join('\n')).not.toContain('--prefer file');
- expect(next.join('\n')).toContain('gbrain sources mirror-writable default');
+ expect(next.join('\n')).toContain('--prefer file --whole-class');
await engine.executeRaw(`UPDATE sources SET config = config || '{"mirror_read_only": false}'::jsonb WHERE id='default'`);
expect(classes(await repair(engine, { slugs: ['notes/newer-file'], prefer: 'file' }))).toEqual({ 'notes/newer-file': 'prefer_file' });
}, { databaseUrl, setup: heldSetup }), 240_000);
- test('GST-2869: on a mirror a held deleted page whose file differs names the writable route, not a --prefer preview', () => managedBrain(async ({ engine }) => {
+ test('GST-2869: on a mirror a held deleted page whose file differs names keeping the deletion first and the writable route second, never a --prefer file preview', () => managedBrain(async ({ engine }) => {
expect((await performManagedSync(engine, OPTS)).status).toBe('first_sync');
await mirror(engine);
await seedHold(engine, 'notes/same', { side: 'deleted', state: 'tombstone_edited' });
const compared = await repair(engine, { held: true }) as Plan;
const [page] = (compared.details!.pages as Array<{ slug: string; would: string; why: string }>).filter(found => found.slug === 'notes/same');
expect(page!.would).toBe('needs_human');
- expect(page!.why).not.toContain('--prefer');
- expect(page!.why).toContain('gbrain sources mirror-writable default');
+ const keep = 'this source is a read-only mirror: to keep the deletion, preview gbrain repair file-drift --source default --held --side deleted --state tombstone_edited --prefer database ';
+ expect(page!.why).toContain(`so a person decides; ${keep}`);
+ expect(page!.why).not.toContain('--prefer file');
+ expect(page!.why).not.toContain('--whole-class');
+ expect(page!.why.indexOf('gbrain sources mirror-writable default')).toBeGreaterThan(page!.why.indexOf(keep));
}, { databaseUrl, setup: heldSetup }), 240_000);
});