diff --git a/CLAUDE.md b/CLAUDE.md index 24b3e68..8c533bc 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -10,14 +10,17 @@ Walker crawls a website and collects performance, SEO and broken-link data. It s ```sh go build ./... # build everything -go run ./cmd/walker path/to/config.yaml # run the crawler + web UI (default addr :3001) -go run ./cmd/validator schema.html https://host/page # validate one page against an htmlschema file +go run ./cmd/walker path/to/config.yaml # run the crawler + web UI (default addr :3001), -exit-on-stdin-close for the macOS app +go run ./cmd/validator schema-root group https://host/page # validate one page, exit 3 on error findings go test ./... # all tests go test ./config -run TestLoad # single test -go test ./htmlschema/... -v # schema loader/group validator + example server +go test ./htmlschema/... -v # syntax, lint, rules + golden tests of the SPEC.md examples +go install ./cmd/htmlschema-lsp # language server for schema files, Zed extension in editors/zed-htmlschema +go run ./cmd/configvalidator config.yaml # validate a walker config: unknown keys, types, schema root - exit 3 on errors +go run ./cmd/demo # demo shop on :8080 (reads templates, css, catalogue from source on every request), schema in htmlschema/demo/schema, group header x-next-js-app ``` -The `Makefile` holds only ad-hoc deploy targets (cross-compile, then scp to a stage host); it isn't a build system. The `Dockerfile` builds both binaries and bakes in `cmd/walker/config-example.yaml`. +`mise.toml` pins Go and `gotsrpc` (keep it in sync with `go.mod`) and wraps the commands above as tasks (`mise tasks`; `mise run generate` regenerates the Go proxy and the Swift client; `goswiftrpc` is pre-alpha without mise support, so `generate:swift` runs `go install github.com/foomo/goswiftrpc/cmd/goswiftrpc@latest` first). The `Makefile` holds only ad-hoc deploy targets (cross-compile, then scp to a stage host); it isn't a build system. The `Dockerfile` builds both binaries and bakes in `cmd/walker/config-example.yaml`. ## Configuration @@ -27,11 +30,11 @@ The `Makefile` holds only ad-hoc deploy targets (cross-compile, then scp to a st - `interval` / `offset` (durations): wall-clock-aligned scrape schedule, see `schedule.go`. `0` means restart immediately. - Other keys: `ignore` (path prefixes), `ignorequerieswith`, `ignoreallqueries`, `ignorerobots`, `depth`, `paging`, `groupheader`, `schemaroot`. -Most `cmd/walker/*.yaml` files are local, site-specific configs and are usually untracked. +Most `cmd/walker/*.yaml` files are local, site-specific configs and are usually untracked. `config.Validate` checks a config file with line numbers (`Load` silently ignores unknown keys), `config.ReadForm`/`WriteForm` turn it into a form and back while keeping comments and unknown keys. ## Architecture -**Actor-style core (`walker.go`, `scrapeloop.go`).** `NewWalker` starts one goroutine, `scrapeloop`, which owns all crawl state: the job map, results and the client pool. Public methods (`Walk`, `Stop`, `GetStatus`, `GetStatuses`) never touch that state directly. Each one sends a request on a channel and waits for the reply on that same channel. Keep it this way: new features that read or change crawl state should add a channel case to the `select` in `scrapeloop`, not shared fields or mutexes. `GetStatuses()` returns the last completed cycle and the running one (`nil` while idle between scheduled cycles), and the reports render both. `GetStatus()` returns the current cycle. +**Actor-style core (`walker.go`, `scrapeloop.go`).** `NewWalker` starts one goroutine, `scrapeloop`, which owns all crawl state: the job map, results and the client pool. Public methods (`Walk`, `Stop`, `Restart`, `GetStatus`, `GetStatuses`) never touch that state directly. Each one sends a request on a channel and waits for the reply on that same channel. Keep it this way: new features that read or change crawl state should add a channel case to the `select` in `scrapeloop`, not shared fields or mutexes. `GetStatuses()` returns the last completed cycle and the running one (`nil` while idle between scheduled cycles), and the reports render both. `GetStatus()` returns the current cycle. `Restart()` starts a new cycle right away (service `RestartScrape`, the "New Scrape" button of the overview); requests still in flight of an aborted cycle free their clients, their results are dropped (`dispatched` remembers the cycle of each busy client). **Scraping (`scrape.go`).** `scrapeloop` hands each job a free `poolClient` from `clientPool` (one `http.Client` per unit of concurrency, optional cookie jar, TLS verification disabled, redirect chain recorded via request context) and calls `scrape` in its own goroutine. Results come back over `chanResult`. `scrape` parses the HTML with goquery and runs `extract.go`, which pulls out title, description, h1, canonical and JSON-LD into `vo.Structure`. It also collects links (including links inside `