Repository navigation
polite-crawler 0.1.3
-
The recipes only add to the API. Code that compiled against 0.1.1 or 0.1.2 compiles against this version, and
compat.test.tsandcompat-012.test.tsstay green. The capture log, the bodies and the capture ids do not change.RuntimeOptions, and thusOpenOptions, has the optionalrecipes.OpenedCrawler,HybridCrawlerandPoliteCrawlerdo not change.polite-crawler/hourshas the newcompareHoursandHoursComparison. Its size for a browser stays in its budget.- In this version,
createRuntimeregisters the extractors before it opens a file of the store. Thus an extractor that it refuses leaves no open file.
-
The recipe SDK.
defineRecipe({ name, fetch, extract })declares what a recipe fetches and how it reads a body into documents. The README section "Writing a recipe" gives a full example and the rules.runRecipe(crawler, recipe, input)fetches the request of an input through the crawler and gives the documents of its capture.registerReciperegisters a recipe in a runtime of your own.readJson(body, capture)reads a body as JSON in its declared encoding. A body that is not JSON throws an error that names the URL and the content type.mode: "page"obeys robots.txt.mode: "api"is a documented API: robots.txt does not apply, and the pace (minInterval) does.reindexreads the captures of each recipe again, and the time travel (at,versions,diff) works on its documents. A runtime with no recipe keeps the documents.- The extractor of a recipe checks each document. A document that is not valid, a document id with the prefix
archive:and the kindarchivedmake the extractor throw. The runtime reports the error. - When the extractor cannot read a stored copy,
runRecipeasks the source one more time. A held-back document shows no title and only its structural metadata, unlessuserProvided. - With
fallback: "archive", a recipe of the modepagegets an archived copy after a refusal. The page reader reads the copy, so the documents of the recipe come only from live captures. - A recipe cannot use a name of the crawler (
RESERVED_RECIPES):page,archive-copy,archive-index,robots.txt,sitemapandfeed.
-
The venue recipe.
readVenue(crawler, url)reads the opening hours of a venue from its own site. It reads the JSON-LD and the text of the home page, and of the pages that most likely hold hours or a menu.- Each reading names its page, its document and its capture. The result gives the best reading, the best reading of the site with no guess (
from_site), and the days where the readings disagree. - It reads an OpenStreetMap
opening_hoursvalue that the caller gives (osm). It sends no request to OpenStreetMap. - On a page that lists more than one location, it reads only the location that matches
location. Withname, it tells if the home page names the venue.requireNamestops at a site that does not name it. - It gives the menu links and the phone, and it tells when the site moved to a different host.
venueReadingsOfreads one stored document or version with no request.compareHourscompares a reading with the week that an application keeps.
- Each reading names its page, its document and its capture. The result gives the best reading, the best reading of the site with no guess (
-
The product recipe.
readProduct(crawler, url)reads the schema.org Product data of a product page. It gives the name, the brand, the SKU, the GTIN, the price, the availability, the seller and the image.- A price is an amount and an ISO 4217 currency.
priceandprice_togive the range of the variants. A list price and a struck-through price are not the price. - It picks the product of the page, not a related product on the page. It reads the variant that the URL names.
- It reads a product that is larger than the JSON-LD of the index from the stored body. It renders the page once when the plain page has no Product data.
- A shop that refuses the crawler gives
wall: trueand a note.productOfreads JSON-LD records with no request, andreadAmountreads an amount as a shop writes it.
- A price is an amount and an ISO 4217 currency.
-
The library only. The command line and the MCP server do not change: the MCP server keeps its nine tools.
-
A failed question keeps the text held back. When the MCP client can ask the user about
user_provided, but the question fails (a timeout, a lost connection or a cancel), the text stays held back. Before, the opt-in of the operator (--allow-user-provided) released it. That opt-in applies only to a client that cannot ask. -
This version only adds to the API. Code that compiled against 0.1.1 or 0.1.2 compiles against this version.
compat.test.ts(0.1.1) andcompat-012.test.ts(0.1.2) are the proof. The capture log, the bodies and the capture ids do not change.OpenedCrawlerdoes not change.openCrawlergives aHybridCrawler: anOpenedCrawlerwithhybrid,embed,rankWithinand afindthat takesSearchOptions.PoliteCrawlerhas the optionalhybrid,embedandrankWithin.ReadingIndexhas the optionaldigests, andFoundhas the optionalpassage.- The class
DocIndexhas the new methoddigests. A subclass of your own with a member of the same name can conflict with it.
-
Hybrid search, opt-in.
find(q, { rank: "hybrid" })fuses the BM25 ranking with the ranking of the vectors of a local embedding model. The default ranking stays exact BM25.Embedderis the extension point:{ id, dimensions, maxInputTokens?, embed(texts, { signal, purpose }) }. The optionembedderofopenCrawlertakes one.transformersEmbedderuses transformers.js (@huggingface/transformers) in the process. The package is an optional peer (^3.0.0 || ^4.0.0), and it loads at the first text. The default model isXenova/bge-small-en-v1.5.- The first use of a transformers.js model downloads it from the Hugging Face Hub. That download does not go through the polite crawler.
ollamaEmbeddersends the texts to a local Ollama server (POST /api/embed), with no new dependency. It accepts only a loopback address, unlessallowRemoteis true. Its errors sayollama serveandollama pull <model>.- The vectors go into
vectors.sqlite, a projection beside the index, with WAL andbusy_timeout. The key of a row is the hash of the text, the chunk and the id of the embedder. Thus a reindex keeps each vector. - A chunk is a window of whole sentences that ends at a paragraph when it can. It fits the input of the model (512 tokens at most), with an overlap of 10 percent. Each hit gives the
passageof its best chunk. - A search gives vectors to its BM25 candidates.
crawler.embed({ budget })and the commandembedgive vectors to each stored page. A held-back page does not go to the embedder, and no result gives it. - The fusion is reciprocal rank fusion with k = 60, over 50 BM25 candidates and 50 vector neighbors (
HYBRID_DEFAULTS). Each one is an option offindandrankWithin. - Without an embedder,
rank: "hybrid"rejects withNO_EMBEDDER. It does not change to BM25 in silence. - The command line has
--embedder transformers|ollama,--embed-model,--ollama-url,--allow-remote-ollama,find --rank hybridandembed.embedtakes--budget,--max-docsand--kind. - The MCP tool
crawl_findtakesrank: "hybrid"only when the server has an embedder. - The search compares the question with each stored vector. The README gives the measured time: 82 ms for 89,100 chunks of 384 dimensions.
-
The benchmark.
bench/find.mts --hybridand the inputhybridofbench.ymltime hybrid search with a fake embedder. -
The daemon only adds to the API. Code that compiled against 0.1.2 compiles against this version, and
compat.test.tsstays green. The capture log, the bodies and the capture ids do not change.WatchRunOptionshas the optionaldrain, andCrawlServerOptionshas the optionaltasks. Withouttasks, the MCP server on the standard input and output does not change.- The daemon writes its own folder,
<store>/daemon/, withstate.jsonandmcp-token. The other files of the store do not change.
-
The daemon.
polite-crawler daemonandstartDaemon(options)check the watch list on a schedule. Each tick is onewatch run, so each polite rule applies.- A due entry wakes the daemon at its time, with a random jitter after it (
--tick,--jitter). A tick keeps its budget and its maximum (--tick-budget,--tick-pages). The entries that a tick leaves wait for the next tick. - The daemon writes each confirmed change as one JSON line, to the standard output or to
--events <file>.onChangeand--on-change <command>get each change. The command gets the event on its standard input, not in its command line. - At
SIGINTorSIGTERM, the daemon starts no new check. The checks in progress get--graceto end, then they abort, and the daemon releases their leases. polite-crawler daemon statusreads<store>/daemon/state.json: the next due watches, the last tick, the tasks that run and the last error. It exits with 0 when a daemon operates on the store.scheduleWatchesgives the schedule over the watch list of a crawler of your own.watch.runtakesdrain: the run starts no new check, and the checks in progress end with their state.- The package installs no service. The README gives example files for systemd, launchd and the Task Scheduler of Windows.
- A due entry wakes the daemon at its time, with a random jitter after it (
-
MCP over local HTTP, with MCP tasks.
daemon --mcp-httpserves the nine tools over the Streamable HTTP transport, athttp://127.0.0.1:9307/mcp.- Each request needs a bearer token. The daemon makes a new token at each start in
<store>/daemon/mcp-token, for the owner only, or it reads--mcp-token-file. The check compares SHA-256 digests in constant time. - The server binds to a loopback address. A different host needs
--allow-remote. On a loopback address, the server refuses aHostor anOriginheader of a different site. crawl_siteandcrawl_discoverare MCP tasks, with the native tasks of the MCP SDK 1.32.1. A client gets a task id, polls the status, gets the result and can cancel the task. A client with no tasks gets the result in the call, with progress.- The library has
startMcpHttpServerandmcpHttpHostinpolite-crawler/mcp. The daemon reaches MCP through the seamDaemonOptions.mcpHost, and it loads the MCP SDK only for--mcp-http. - The MCP SDK marks its task API as experimental. When the SDK changes it, the tasks change with it.
- Each request needs a bearer token. The daemon makes a new token at each start in