From 7898badc99d116ba2719b2839c30a73301b8c64e Mon Sep 17 00:00:00 2001 From: Sam Gozman Date: Fri, 20 Nov 2026 10:48:37 +0400 Subject: [PATCH] feat: read archived copies of failed pages, Bloomberg articles and Cloudflare-protected pages (#14) --- AGENTS.md | 5 +- README.md | 38 ++- cmd/refetch/archive.go | 174 +++++++++++++ cmd/refetch/archive_test.go | 290 ++++++++++++++++++++++ cmd/refetch/doctor.go | 11 +- cmd/refetch/doctor_test.go | 1 + cmd/refetch/get.go | 3 +- cmd/refetch/get_test.go | 7 +- cmd/refetch/main.go | 8 +- cmd/refetch/main_test.go | 2 +- cmd/refetch/mcp.go | 10 +- cmd/refetch/notes.go | 9 +- cmd/refetch/notes_test.go | 18 ++ config/config.go | 4 + config/config_test.go | 23 +- e2e/run.py | 2 +- fetch/detect.go | 15 +- fetch/detect_test.go | 8 + fetch/paywall.go | 110 +++++++++ fetch/paywall_test.go | 57 +++++ fetch/structured.go | 35 ++- site/bloomberg.go | 354 +++++++++++++++++++++++++++ site/bloomberg_test.go | 94 +++++++ site/site.go | 3 + site/testdata/bloomberg_article.html | 58 +++++ skills/refetch/SKILL.md | 1 + stats/stats.go | 39 ++- stats/stats_test.go | 32 +++ stats/text.go | 6 + 29 files changed, 1379 insertions(+), 38 deletions(-) create mode 100644 cmd/refetch/archive.go create mode 100644 cmd/refetch/archive_test.go create mode 100644 fetch/paywall.go create mode 100644 fetch/paywall_test.go create mode 100644 site/bloomberg.go create mode 100644 site/bloomberg_test.go create mode 100644 site/testdata/bloomberg_article.html diff --git a/AGENTS.md b/AGENTS.md index 6a7aa46..02a87a9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -32,7 +32,10 @@ fetcher and the stats report. The repo root is also the Claude Code plugin. under `render_timeout` - `site/`: a site's own public API in place of its page: Stack Exchange questions, Discourse topics (`/raw`), long GitHub issues, Bluesky and - Mastodon posts, YouTube video data, Medium posts from RSS feeds + Mastodon posts, YouTube video data, Medium posts from RSS feeds, + Bloomberg story data +- `cmd/refetch/archive.go`: the Wayback Machine step after a failed read + (`archive` setting); it sends the URL to archive.org - `store/`: SQLite event log (`tool_calls`, `attempts`, `daily` roll-up) - `stats/`: the funnel and its text report - `config/`: defaults, `config.toml`, `REFETCH_*` env vars diff --git a/README.md b/README.md index f5583c6..de643f9 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,8 @@ Chrome step, which adds JavaScript-only pages and some challenges. many refetch picked up and which step resolved them. All data stays on your machine. - **Safe by default.** Public addresses only, one page per call, no - crawling, no cookies kept. + crawling, no cookies kept. A URL refetch cannot read is looked up at the + Wayback Machine unless you turn that off. ## Install @@ -121,8 +122,10 @@ flowchart TD Client -- "challenge or
JavaScript-only page" --> Headless["2. Headless Chrome
your installed Chrome, 15 s at most"] Client -- "page" --> Text["Page as Markdown"] Headless -- "page" --> Text - Client -- "HTTP 403/429
or error" --> Handoff["Hand-off: why it failed"] - Headless -- "still blocked" --> Handoff + Client -- "HTTP 403/429
or error" --> Wayback["3. Wayback Machine
latest archived copy, 20 s at most"] + Headless -- "still blocked" --> Wayback + Wayback -- "snapshot" --> Text + Wayback -- "none" --> Handoff["Hand-off: why it failed"] end Text --> Rescued(["Claude answers from the page"]) @@ -160,8 +163,13 @@ show how often each path was taken. Step by step: without Chrome. A host whose last two fetches in the past week only headless Chrome could read goes straight to it (this needs `stats` on, as it reads the stats database); the HTTP clients still run if it fails. -5. If both steps fail, the result says why and suggests a browser tool if - you have one. +5. If both steps fail (a refusal, a challenge, an error page, a dead host), + refetch looks the URL up at the Wayback Machine and reads its latest + snapshot saved with HTTP 200, within 20 s. The result says it is an + archived copy, gives its date and why the live page failed, and warns that + it may be out of date. `archive = "off"` turns this step off. +6. If there is no snapshot either, the result says why and suggests a + browser tool if you have one. `fetch_page` returns a page as Markdown: headings, lists, links, tables and code blocks kept, scripts and hidden elements dropped. So is the site's own @@ -212,6 +220,11 @@ Some sites serve the same public content better through their own API, and pages challenge automated readers. The feed holds the full text of only the newest posts, about ten; for an older or member-only post, or a `medium.com/p/…` address, refetch reads the page as before. +- Bloomberg articles are read from the story data their page carries for + its scripts. The HTML around it shows only the byline and the first + paragraphs; the data holds the whole text a reader without cookies is + served, rendered with its headline, authors, date, takeaways, headings, + lists and links. No extra request is made. When a site's API says refetch has used up its quota (HTTP 429, a Stack Exchange throttle or GitHub's rate-limit message), refetch leaves that API @@ -224,8 +237,11 @@ When a page loads but is not the content, the result starts with a note: a short page that is mostly a login form, a page whose title or main heading says it does not exist (a "soft 404" sent with HTTP 200), or the signed-out view of X, Instagram, Facebook, Threads, TikTok and LinkedIn, which may lack -the posts, comments and full profiles that need a signed-in browser. The -page text still comes back. +the posts, comments and full profiles that need a signed-in browser. A news +article whose schema.org data marks it for subscribers, or whose page shows +a paywall ("Subscribe to continue reading"), gets a note that the text may +stop at the paywall and be only the opening. The page text still comes back, +and notes change no outcome or statistic. Pages that put their content in `