@fragmentoid/turbo-crawl 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Daniele Calleri
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,130 @@
1
- # Temporary Holding Version
1
+ # turbo-crawl
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Turn any web page into structured JSON without writing selectors.
4
+
5
+ The first time you crawl a URL pattern, turbo-crawl asks a coding agent you already use (**Claude Code** or **Codex**) to read the page's structure and write an extraction template: CSS, JSON-LD, meta or table selectors for each field. Every selector is checked on the live page, and any that fail go back to the agent to fix. After that, every page matching the same pattern is scraped with the saved template, with **no model call**: it's fast, free and deterministic.
6
+
7
+ ```console
8
+ $ npx @fragmentoid/turbo-crawl crawl https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html \
9
+ --fields title:string,price:number,availability:text,upc:string
10
+ Using claude to write the template.
11
+ Asking claude to write selectors for 4 fields…
12
+ {
13
+ "urlPattern": "/catalogue/:slug/index.html",
14
+ "path": "authored",
15
+ "llmUsed": true,
16
+ "data": {
17
+ "title": "A Light in the Attic",
18
+ "price": 51.77,
19
+ "availability": "In stock (22 available)",
20
+ "upc": "a897fe39b1053632"
21
+ },
22
+ ...
23
+ }
24
+
25
+ $ npx @fragmentoid/turbo-crawl crawl https://books.toscrape.com/catalogue/sapiens-a-brief-history-of-humankind_996/index.html
26
+ Extracting with the saved template for /catalogue/:slug/index.html…
27
+ {
28
+ "path": "template-reuse",
29
+ "llmUsed": false,
30
+ "data": { "title": "Sapiens: A Brief History of Humankind", "price": 54.23, ... }
31
+ }
32
+ ```
33
+
34
+ ## Requirements
35
+
36
+ - Node.js 20 or later.
37
+ - One template author:
38
+ - [Claude Code](https://docs.claude.com/en/docs/claude-code) (`claude`), installed and logged in. This is the default.
39
+ - or [Codex CLI](https://github.com/openai/codex) (`codex`), installed and logged in.
40
+ - or a local [LM Studio](https://lmstudio.ai) server, via `--provider lmstudio`.
41
+ - Chromium for Playwright: `npx playwright install chromium`.
42
+
43
+ turbo-crawl runs the agent CLIs in headless mode with no tools and no access to your files. It sends them only a text outline of the page, and uses your existing login, so there are no API keys to configure.
44
+
45
+ ## Install
46
+
47
+ ```bash
48
+ npm install -g @fragmentoid/turbo-crawl # provides the `turbo-crawl` command
49
+ npx playwright install chromium
50
+ ```
51
+
52
+ Or run it without installing: `npx @fragmentoid/turbo-crawl crawl <url> ...`.
53
+
54
+ ## Usage
55
+
56
+ ```bash
57
+ turbo-crawl crawl <url> [options]
58
+ ```
59
+
60
+ | Option | Description |
61
+ | --- | --- |
62
+ | `--fields name:type,...` | Fields to extract. Types: `string`, `text`, `number`, `boolean`, `date`, `url`. Omit it and the agent suggests fields for the page. |
63
+ | `--provider <name>` | `auto` (default), `claude`, `codex` or `lmstudio`. `auto` picks `claude` if it is installed, otherwise `codex`. |
64
+ | `--model <id>` | Model passed to the provider (e.g. `sonnet` or `opus` for Claude). Defaults to the provider's own default. |
65
+ | `--data-dir <path>` | Where schemas, templates and results are stored. Default `./data`. |
66
+ | `--max-repairs <n>` | How many times the agent may fix failing selectors. Default `2`. |
67
+ | `--json` | Run without the TUI and print JSON. This is automatic when `--fields` is given, output is piped, or you are not running under Bun. |
68
+ | `--tui` / `--no-tui` | Force or disable the interactive TUI (needs Bun, see below). |
69
+
70
+ The result goes to stdout as JSON and progress goes to stderr, so `turbo-crawl crawl <url> --fields ... > item.json` works as expected. Exit codes: `0` success, `1` runtime error, `2` invalid arguments.
71
+
72
+ ### Environment variables
73
+
74
+ | Variable | Purpose |
75
+ | --- | --- |
76
+ | `TURBO_CRAWL_PROVIDER` | Default provider when `--provider` is not given. |
77
+ | `TURBO_CRAWL_MODEL` | Default model. |
78
+ | `TURBO_CRAWL_DATA_DIR` | Default data directory. |
79
+ | `TURBO_CRAWL_LLM_TIMEOUT_MS` | Timeout for one agent call (default `600000`). |
80
+ | `TURBO_CRAWL_SKELETON_BYTES` | Size budget of the page outline sent to the agent (default `120000`). |
81
+ | `TURBO_CRAWL_CLAUDE_BIN`, `TURBO_CRAWL_CODEX_BIN` | Path to a specific `claude` or `codex` binary. |
82
+ | `TURBO_CRAWL_LMSTUDIO_URL` | LM Studio base URL (default `http://localhost:1234`). |
83
+
84
+ ## How it works
85
+
86
+ 1. **Render.** Playwright opens the page in headless Chromium, waits for the network to settle and dismisses cookie banners.
87
+ 2. **Reuse.** turbo-crawl turns the URL into a pattern (`/products/black-bay-58` becomes `/products/:slug`, and `/item/123` becomes `/item/:id`). If a template exists for that pattern, it is used and no model is called.
88
+ 3. **Author.** Otherwise the agent gets the field list, the page's JSON-LD, meta tags and tables, and a compact outline of the DOM (tags, ids, stable classes, semantic attributes, short text). It returns up to four ordered selectors per field.
89
+ 4. **Validate and repair.** Each selector runs on the live page and its value is normalized to the field type. Fields with no working selector go back to the agent, along with what each selector actually read. Fields that still fail are left `null` with a warning.
90
+ 5. **Save.** The template is saved and the page is extracted with it, so the first page and every later page go through the same extraction code.
91
+
92
+ ### Data layout
93
+
94
+ ```
95
+ data/<domain>/
96
+ schemas/<timestamp>.json field lists you created or the agent suggested
97
+ templates/<hash>.json one template per URL pattern and field set
98
+ packets/<url-hash>/
99
+ packet.json what was captured from the page
100
+ packet.llm.json the agent exchange, when a template was authored
101
+ result.json the extraction result
102
+ ```
103
+
104
+ Templates are plain JSON. You can review them, edit selectors by hand, or commit them next to your code.
105
+
106
+ ## Interactive TUI (Bun)
107
+
108
+ With [Bun](https://bun.sh) installed, run the interactive schema builder:
109
+
110
+ ```bash
111
+ bunx @fragmentoid/turbo-crawl crawl https://example.com --tui
112
+ ```
113
+
114
+ It suggests stored templates and schemas for the domain, lets you build a schema field by field (or press Tab with no fields to let the agent suggest them), and shows the extracted values when the crawl is done.
115
+
116
+ ## Development
117
+
118
+ ```bash
119
+ bun install
120
+ bun run dev crawl <url> # run from source
121
+ bun run typecheck
122
+ bun test
123
+ bun run build # dist/cli.js, runs on Node
124
+ ```
125
+
126
+ See [AGENTS.md](AGENTS.md) for conventions.
127
+
128
+ ## License
129
+
130
+ MIT