diff --git a/assets/opencode/skills/searching-reading-archive/SKILL.md b/assets/opencode/skills/searching-reading-archive/SKILL.md new file mode 100644 index 00000000..e9059ecc --- /dev/null +++ b/assets/opencode/skills/searching-reading-archive/SKILL.md @@ -0,0 +1,63 @@ +--- +name: searching-reading-archive +description: Use when looking for something Jonathan read in Zvi Mowshowitz (Don't Worry About the Vase), Astral Codex Ten (Scott Alexander), Matt Levine (Money Stuff) or Matt Yglesias (Slow Boring), especially from a vague memory ("that post where an AI with a budget emailed people", "a few weeks ago"), or before concluding a remembered piece doesn't exist. +--- + +# Searching the Reading Archive + +`ra` is a BM25 (SQLite FTS5) search over every section of every archived post. Plain words are +OR'ed, so a wrong word only costs rank. One hit per post by default. + +**The archive lives on devbox only** (`~/projects/reading-archive`, data in +`/persist/reading-archive`; check with `hostname`). From any other host, have a devbox session +run the search (`swarm_launch` with machine `devbox`). It is synced twice a day by a timer that +sends a pigeon alert when something breaks; operating it is the repo-local +`operating-reading-archive` skill. + +```bash +RA="uv run --project ~/projects/reading-archive ra" +$RA status # ALWAYS FIRST +$RA search "AI agent emailed people token budget" -n 10 +$RA search "..." --source zvi --after 2026-08-01 --before 2026-10-15 +$RA show # full text of a hit +``` + +Sources: `zvi`, `acx`, `levine`, `yglesias`. Each hit shows date, source, `title › section`, +URL, a snippet with `[matched]` terms, and `key=` for `ra show`. + +## The procedure + +1. **Run `ra status` before trusting a miss.** Check the source covers the window, the newest + document is recent, the summary line's `failing` and `not yet fetched` counts are 0, and + there are no `MISSING`, `GAP` or `sitemap never fetched` lines. A source with no documents + at all is not listed; use `ra status --source `. An archive + can look fresh at the top and still have a hole in the middle, and that hole is where the + story you can't find will be. +2. **Double the remembered time window**, or drop it. People underestimate how long ago they + read something: a story remembered as "0–8 weeks ago" was 12 weeks old. +3. **Run 2–3 queries in different words for the same idea.** Search matches words, not ideas. + Describe what the text would *say*, not how you remember it: + - remembered: "AI was cold-emailing people or it would be shut off" + - the text said: "token budget", "die when their compute budget runs out", "email from an AI agent" + - `"AI budget cold emailed people"` ranked it 2nd; `"AI agent emailed people token budget"` ranked it 1st. +4. **Use phrases and operators only after a hit tells you the exact wording:** + `NEAR("compute budget" agent, 20)`, `iLand*`, `heading:survive`. Once a query contains any + FTS5 syntax (`"`, `:`, `*`, `(`, upper-case `AND/OR/NOT/NEAR`), it is passed through as written + and bare words are **AND'ed**, not OR'ed. +5. **Grep is the last resort:** `rg -il "ilands" /persist/reading-archive/docs/zvi`. +6. **Report** title, section, date and URL, plus a quote from `ra show`. + +## Things that look like misses but aren't + +- **Paywalled posts:** `status` counts them, and their text is only present if the paid email + arrived. A paid ACX or Slow Boring post with no hits may be one of these. +- **Zvi roundups** (`AI #N`) are split by section; the hit names the section, so read that one. +- **Levine** coverage starts 2026-02 (when my-podcasts began keeping his emails). + +## Substack gotchas (if you go to the web instead) + +- The per-publication `/api/v1/post/search` returns `[]`, and global `substack.com` search is + SEO noise. +- `https:///sitemap.xml` lists every post; `/api/v1/posts/` returns the full body of + a free post. +- `/api/v1/archive` is cursor-paged (`nextCursor`); `offset` and `limit=50` are rejected. diff --git a/hosts/devbox/configuration.nix b/hosts/devbox/configuration.nix index 5b9ba723..da012857 100644 --- a/hosts/devbox/configuration.nix +++ b/hosts/devbox/configuration.nix @@ -169,6 +169,19 @@ in group = "dev"; mode = "0400"; }; + # reading-archive's READ-ONLY R2 key for the my-podcasts bucket (it reads + # inbox/raw/*.eml; Cloudflare token "reading-archive R2 read-only + # (my-podcasts bucket)"). Never substitute the read-write r2_* keys above. + reading_archive_r2ro_access_key_id = { + owner = "dev"; + group = "dev"; + mode = "0400"; + }; + reading_archive_r2ro_secret_access_key = { + owner = "dev"; + group = "dev"; + mode = "0400"; + }; # GitHub API token (for gh CLI, GH_TOKEN) github_api_token = { owner = "dev"; @@ -1540,6 +1553,10 @@ Check: "L+ /home/dev/.ssh - - - - /persist/ssh" # My Podcasts persistent state "d /persist/my-podcasts 0755 dev dev -" + # reading-archive data root (users/dev/reading-archive.nix). Directory only: + # its .archive-root sentinel is created by hand, never here, so an + # unmounted /persist makes `ra` refuse instead of filling the root fs. + "d /persist/reading-archive 0755 dev dev -" ]; # User account with stable UID/GID for persistent volume ownership diff --git a/projects.nix b/projects.nix index 25ca83cc..c6ecada6 100644 --- a/projects.nix +++ b/projects.nix @@ -33,6 +33,10 @@ url = "git@github.com:johnnymo87/my-podcasts.git"; platforms = [ "devbox" ]; }; + reading-archive = { + url = "git@github.com:johnnymo87/reading-archive.git"; + platforms = [ "devbox" ]; + }; citadels = { url = "https://github.com/livia0804/citadels.git"; platforms = [ "devbox" ]; diff --git a/secrets/devbox.yaml b/secrets/devbox.yaml index 71f9d489..290f8d00 100644 --- a/secrets/devbox.yaml +++ b/secrets/devbox.yaml @@ -42,6 +42,8 @@ pigeon_slack_alarm_webhook: ENC[AES256_GCM,data:QuUCklyjfxG4/NCUXhD36r1WQ1ro/rrI em_alerts_slack_webhook: ENC[AES256_GCM,data:YWVUkLgR7oMPz2DMGEhAQ1gqaEnxuqq0F6VAa8bcIxq3wu/4Op/qYCs1Uvbe06r1B73ssHW/zPiEgY7Uaj70c4P2XnrwVLAAQfEURCA+c2io,iv:MU1GxFSa6PuS5zh6OIfd5rrZS8iA/Yfd2Rj2qgPd8PI=,tag:IQHsfSEjlN2eSxo0kownzA==,type:str] discord_bot_token: ENC[AES256_GCM,data:4PiV51230AxxfsnYJmr0xZrxK70oO37wF8x1r/LbgZvEuuTY0kQi9VWq3CpnhhhrKC/iFujCsuccXb93+3MIw27GQc3wMPx6,iv:X3PtWvlfvQn2q8dDsjXtfPM62WbVB5VHUDQWGq1Lzm4=,tag:WTa+7GWZVVpA0qm6eGT7TA==,type:str] tec_codex_bot_openai_api_key: ENC[AES256_GCM,data:AITI1+NrtEMRbx9+YtG3N9hXxHL67JP4XJFetW96CSTM4FMH2f4TvCljXijMWt11J5s6yrYu3NftLRiLGOLNJ03uzuP6qH93UT8r7LUbhuDzq/YKpInA8/WP3/uxAvnM5CH63Pvbo7PK1NxTtWmxXsxN2k4jjZVTF6U6HOOQtbKW4qKva6FazxWNH5ccW73VcW7A6iULrsLhtepH4nXIqZMLsRf6U0Q=,iv:GBa8yqCArjxCSuJ+afRwNp2UVYSPYzmHNaz8VLpZcQE=,tag:dKpSJrLpgklOQ04qBUcAVA==,type:str] +reading_archive_r2ro_access_key_id: ENC[AES256_GCM,data:H2grxQR/89BAYxWi27KdyBLN+m1QI60Fm8tiN4ABcHk=,iv:8RSVlMylD/Vwoe6BnAvlqROivyTR8316+/EcEjEtiDI=,tag:Gve1SkAhw1pofw8gMiuJ/A==,type:str] +reading_archive_r2ro_secret_access_key: ENC[AES256_GCM,data:LdTFsSpUzldhIOLlFwM/KYyHHb6ffFbGw2YuZ8cy+QQURzV0bUVVb7yix6AQEokN6iNrYd2jjMx6p2H89Iu5LQ==,iv:v+ipqmb96PXFkYWffqglcN5JETNR4kQk6Q3NC7aq8F0=,tag:RQdwL7Rou688DOYTxuH5nA==,type:str] sops: age: - enc: | @@ -53,7 +55,7 @@ sops: a6NZXiODK1UasHDYtcjodGI7BXpoy3gVBGpnGjH2oS7mVjoBLhOMOQ== -----END AGE ENCRYPTED FILE----- recipient: age1kyd7dzxtgte0rcd0nj3chfvcfvammhywe63f25tlsrf8knhf3u8sxp8z9n - lastmodified: "2026-12-01T18:36:32Z" - mac: ENC[AES256_GCM,data:GiibDjb6c8DU5nOyF3ewep57pWtp0PIgmNYG3aC/Ozq/UZ+uBW4zmCi24CyECuJmXhk8shdJHXUcDdAT3g1mJ36dB8QNIktvf7iS0BcG04by2wZ+izkjFBNOh5cwyYifJOvw+ps/sLu50ZMz7S3ML9uMZ9/hzmmJxqmfrfjmjnY=,iv:O4KsAhYE+0UJXGynEabPso9y/fd6qw7DfSdKAv/uips=,tag:lCwuphLFbJE3Wzx2i2fytw==,type:str] + lastmodified: "2026-12-01T19:50:40Z" + mac: ENC[AES256_GCM,data:qAjjHAPrj0x9LxlMHdJjjqUifa37P6YQ2cewVMok7EH5W1EId+kEbLOCB4cPftVhKbRZVmRSLM3urVIPMCZF9kpD07BbMTkAvG8LVWOK5FyBI1qLgo5tYsph5Mb8mxK+d9BKxO71+dybNR3GHi4xIc8jWy4EAvJXo9QG0iy7HmA=,iv:fCz1U6QGCeb94WS1ojA22FCTkLQgUGmolxMNL1CBdkA=,tag:wueyw5Nd+Kw360FWvVz3cg==,type:str] unencrypted_suffix: _unencrypted version: 3.13.3 diff --git a/users/dev/home.nix b/users/dev/home.nix index b0cfeb43..947a89b4 100644 --- a/users/dev/home.nix +++ b/users/dev/home.nix @@ -11,6 +11,7 @@ ./disk-cleanup.nix ./em-drift-detector.nix ./quota-telemetry.nix + ./reading-archive.nix ./em-test-postgres.nix ./em-scratch-db-gc.nix ./tec-codex-bot.nix diff --git a/users/dev/opencode-skills.nix b/users/dev/opencode-skills.nix index 4fd1311d..d7e0fe68 100644 --- a/users/dev/opencode-skills.nix +++ b/users/dev/opencode-skills.nix @@ -49,6 +49,10 @@ let "reviewing-github-prs" "reviving-worktree-orphaned-sessions" "scheduling-wakes" + # Cross, not devbox-only: the archive lives on devbox, but the question + # ("that Zvi post where...") gets asked on every host, and the skill says + # how to reach devbox from elsewhere. + "searching-reading-archive" "searching-sessions" # Cross, not work-only: PR shepherding applies to personal repos and this # one too, and the skill already anticipates devbox (it tells you to treat a diff --git a/users/dev/reading-archive.nix b/users/dev/reading-archive.nix new file mode 100644 index 00000000..0488007c --- /dev/null +++ b/users/dev/reading-archive.nix @@ -0,0 +1,153 @@ +# reading-archive (johnnymo87/reading-archive): twice-daily sync of Jonathan's +# searchable reading archive (Zvi, ACX, Levine, Slow Boring) on devbox. +# +# Runs from the repo's `main` checkout (~/projects/reading-archive, registered +# in projects.nix), so merging to main + `git pull` there is the deploy; this +# module only schedules it and turns failures into pigeon alerts. +# +# Each run: `ra sync` (exit 0/1 are normal: per-source errors are reported by +# the check once they matter; 2/3 = refused/crashed alerts at once), then +# `ra backup` (commits docs/ and pushes it to johnnymo87/reading-archive-docs; +# a failing push surfaces through the check), then `ra status --check --json`, +# whose problems -- each reported once (events) or every 3 days (conditions) +# -- become one alert, and are acknowledged (`ra status --ack`) only after +# pigeon accepted it. +# +# The unit fails when an alert could not be delivered or the run was killed; +# OnFailure then tries one more alert. +# +# The data root /persist/reading-archive is created by tmpfiles in +# hosts/devbox/configuration.nix; its `.archive-root` sentinel is deliberately +# NOT, so an unmounted /persist (nofail) makes `ra` refuse (exit 2 -> alert) +# rather than build a phantom archive on the root filesystem. +# +# Design: reading-archive docs/plans/2026-12-01-reading-archive-design.md (D6); +# bead my-podcasts-ad4.10. +{ pkgs, lib, isDevbox, ... }: + +let + alertFn = '' + # alert SEVERITY TEXT: POST to pigeon's /alert (rendered in the alerts + # channel). Returns non-zero when not delivered; never aborts the caller. + alert() { + local severity=$1 text=$2 body token + local -a auth=() + # Keep the message deliverable: providers reject very long texts. + [ "''${#text}" -gt 3500 ] && text="''${text:0:3500} + … (truncated; see journalctl --user -u reading-archive-sync)" + body=$(jq -n --arg t "$text" --arg s "$severity" '{text: $t, severity: $s}') + token=$(cat /run/secrets/pigeon_daemon_auth_token 2>/dev/null || true) + [ -n "$token" ] && auth=(-H "Authorization: Bearer $token") + if ! curl -fsS -m 15 "''${auth[@]}" -H 'Content-Type: application/json' \ + -d "$body" http://127.0.0.1:4731/alert >/dev/null; then + echo "ALERT NOT DELIVERED ($severity): $text" >&2 + return 1 + fi + } + ''; + + syncScript = pkgs.writeShellScript "reading-archive-sync" '' + set -u + ${alertFn} + undelivered=0 + send() { alert "$@" || undelivered=1; } + + if [ ! -f /persist/reading-archive/.archive-root ]; then + send error "reading-archive (devbox): /persist/reading-archive/.archive-root is missing (is /persist mounted?); nothing ran" + exit "$undelivered" + fi + cd "$HOME/projects/reading-archive" || exit 2 + # `uv run` syncs .venv to uv.lock on purpose: `git pull` on main is the + # deploy, and a pulled dependency change must take effect. + ra() { uv run --frozen --quiet ra "$@"; } + + log=$(mktemp) + err=$(mktemp) + trap 'rm -f "$log" "$err"' EXIT + + # Exit 1 = per-source errors, left to `--check` (it reports them once they + # matter); 2 = refused, 3 = crashed. + ra sync 2>&1 | tee "$log" + rc=''${PIPESTATUS[0]} + if [ "$rc" -gt 1 ]; then + send error "reading-archive (devbox): ra sync exited $rc: + $(tail -n 15 "$log")" + fi + + # A failing backup is reported by --check as a condition (every 3 days), + # not here (twice a day). + ra backup || true + + out=$(ra status --check --json 2>"$err") + crc=$? + cat "$err" >&2 + if [ "$crc" -eq 1 ]; then + text=$(printf '%s' "$out" | jq -r '.[].text') + echo "$text" + # Acknowledge only what was delivered, so nothing is lost to a failed send. + if alert warning "reading-archive needs attention (devbox; \`ra status\` for details): + $text"; then + mapfile -t ids < <(printf '%s' "$out" | jq -r '.[].id') + ra status --ack "''${ids[@]}" + else + undelivered=1 + fi + elif [ "$crc" -ne 0 ]; then + send error "reading-archive (devbox): ra status --check exited $crc: + $(tail -n 15 "$err")" + fi + + exit "$undelivered" + ''; + + # OnFailure: the job was killed (timeout, OOM at MemoryMax) or could not + # deliver an alert. Best effort: if pigeon is down this is lost too. + failScript = pkgs.writeShellScript "reading-archive-sync-failed" '' + set -u + ${alertFn} + alert error "reading-archive (devbox): reading-archive-sync.service failed (killed, timed out, or an alert could not be delivered); journalctl --user -u reading-archive-sync" || true + ''; +in +lib.mkIf isDevbox { + systemd.user.services.reading-archive-sync-failed = { + Unit.Description = "reading-archive: alert that reading-archive-sync failed"; + Service = { + Type = "oneshot"; + ExecStart = "${failScript}"; + Environment = [ "PATH=${lib.makeBinPath [ pkgs.coreutils pkgs.curl pkgs.jq ]}" ]; + }; + }; + + systemd.user.services.reading-archive-sync = { + Unit = { + Description = "reading-archive: sync sources, back up docs/, alert on problems"; + OnFailure = [ "reading-archive-sync-failed.service" ]; + }; + Service = { + Type = "oneshot"; + ExecStart = "${syncScript}"; + Environment = [ + "HOME=%h" + "UV_PYTHON_DOWNLOADS=never" + "PATH=${lib.makeBinPath [ pkgs.uv pkgs.git pkgs.openssh pkgs.coreutils pkgs.curl pkgs.jq pkgs.bash ]}" + "\"GIT_SSH_COMMAND=ssh -o BatchMode=yes -o ConnectTimeout=15 -o ServerAliveInterval=15\"" + ]; + MemoryMax = "1G"; + MemorySwapMax = "0"; + Nice = 10; + # A normal run is a few minutes; a backfill after a long outage can take + # hours at 1 request/s, and the sync lock keeps runs from overlapping. + TimeoutStartSec = "6h"; + }; + }; + + systemd.user.timers.reading-archive-sync = { + Unit.Description = "reading-archive sync at 05:00 and 21:00 New York time"; + Timer = { + OnCalendar = [ "*-*-* 05:00:00 America/New_York" "*-*-* 21:00:00 America/New_York" ]; + Persistent = true; + RandomizedDelaySec = "5min"; + }; + Install.WantedBy = [ "timers.target" ]; + }; +}