Skip to content

Add discover: a breadth-first walk of the page graph#13

Merged
tamnd merged 3 commits into
mainfrom
discover-graph-bfs
Jun 15, 2026
Merged

Add discover: a breadth-first walk of the page graph#13
tamnd merged 3 commits into
mainfrom
discover-graph-bfs

Conversation

@tamnd

@tamnd tamnd commented Jun 15, 2026

Copy link
Copy Markdown
Owner

What

A new discover command (aliases walk, graph) that walks the Wikipedia graph breadth first. The structure commands each follow one edge of one page; discover chains them, from a seed page or category outward, streaming one row per object it reaches.

wiki discover "Alan Turing"                              # links + categories, one hop
wiki discover "Turing machine" --follow backlinks       # what-links-here, walked
wiki discover "Category:Turing Award laureates" --follow cats --depth 2
wiki discover "Alan Turing" --depth 2 -o jsonl > graph.jsonl

Shape

  • Five edges (links, backlinks, categories, members, subcats) across two node kinds (page, category), grouped into presets content (default), network, cats, all. --follow takes a preset or a bare edge list; the two vocabularies are disjoint so a preset can never shadow an edge.
  • Engine-agnostic walker. Built against a six-method grapher interface that is an exact subset of *Client, so the BFS is tested over an in-memory fake with no network.
  • Pre-hydrated neighbors. Every expansion takes only a title and the list rows already carry title + URL, so neighbors are enqueued already hydrated. A depth-1 walk costs one seed fetch plus the seed's list calls, nothing per neighbor.
  • Bounds: --depth (default 1; 0 = seeds only), --fanout per edge (default 25), and an -n streaming budget (default 500) so a bare walk always terminates.

Adapted to Wikipedia

Unlike the sibling discover commands in the other tamnd CLIs:

  • The API is uniformly open, so there are no gated edges and no scrape-tier / Restricted-Mode degradation path.
  • wiki keeps no local crawl database, so the walk is streaming-only (no --store); pipe it to keep it.

Error policy: a seed that cannot be fetched is fatal (like any single read); a flaky edge deeper in the walk becomes a one-line note on stderr and the walk continues.

Tests

wiki/discover_test.go is hermetic over a fakeGraph: edge/preset parsing, edge source/target, seed parsing, BFS order and via tagging from page and category seeds, the network backlink path, cycle dedup, the Max budget, --fanout capping, depth-0 seeds-only, fatal missing seed, deeper-error-degrades-to-note, and multiple seeds.

Docs & spec

  • Spec §17 added to 8002_wikipedia.md (graph taxonomy, BFS contract, the open-API / no-store contrasts).
  • discover section in the Page structure guide, a guides-index mention, and a reference CLI row.

CGO_ENABLED=0 go build/vet/test ./... green, gofmt clean, no em-dashes in code or docs.

tamnd added 3 commits June 15, 2026 15:44
Every structure command answers one question about one page: its links,
its categories, a category's members. discover chains them. From a seed
page or category it follows the object's edges, then each neighbor's, hop
by hop, streaming one row per object it reaches.

The walker is built against a six-method grapher interface, an exact
subset of the client, so the BFS logic is tested over an in-memory fake
with no network. Neighbors arrive pre-hydrated from the list they came in
on, so a depth-1 walk costs one seed fetch plus the seed's list calls and
nothing per neighbor.

Five edges (links, backlinks, categories, members, subcats) across two
node kinds (page, category), grouped into presets: content (the default),
network, cats, all. --follow takes a preset or a bare edge list; the two
vocabularies are disjoint so a preset can never shadow an edge.

Wikipedia's API is uniformly open, so unlike the sibling discover commands
there are no gated edges and no tier degradation. wiki keeps no local
database, so the walk streams to stdout; pipe it to keep it. A bad seed is
fatal like any single read; a flaky edge deeper in is a note and the walk
continues.
The walk was documented inside the page-structure guide, where it sat
awkwardly next to the single-edge reads. Pull it into a dedicated
Discovering guide so it reads as the one command that chains the others,
matching how the rest of the CLI tools document their graph walk. The
structure guide keeps a short pointer, and the guide index now lists
Discovering as its own entry.
@tamnd
tamnd merged commit f015444 into main Jun 15, 2026
7 checks passed
@tamnd
tamnd deleted the discover-graph-bfs branch June 15, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant