This directory contains two discovery backfill paths:
run-loop.tsis the primary runner. It executes the samedetect()->discover()agentic tool loop -> Worker packing/slug path that the website uses, backed by context.dev and sync OpenAI chat completions.corpus.ts,submit.ts, andcollect.tsare the older one-shot OpenAI Batch API alternative. They are useful for prompt-only experiments, but they do not run the multi-turn website loop.
All commands are Bun scripts and support --help.
Prepare a domain list, one domain per line or comma-separated:
bun scripts/batch/expand-domains.tsRun the website discovery loop in bulk:
bun scripts/batch/run-loop.ts \
--domains scripts/batch/domains-all.txt \
--model gpt-5.4-mini \
--concurrency 8 \
--out scripts/batch/results \
--existing path/to/current-kv-rowsRequirements:
OPENAI_API_KEYCONTEXT_DEV_API_KEY
Both are loaded through shared.ts envValue: process.env, then .dev.vars, then ~/.config/connectors/secrets.env. The runner hard-fails before work starts if either is missing. It never uses naiveWeb.
Behavior:
- skips existing
results/{domain}.jsonfiles unless--forceis passed - writes failures to
results/_failures.jsonland continues - writes
StoredDiscoveryrows withmodel: loop-{model}plus a siblingusageobject - preserves existing slugs by the same locator matching used by the Worker
- runs
dedupSurfacesafter packing and logs any collapses - prints one progress row per domain: surfaces, credentials, turns, tokens, seconds
Check the output:
bun scripts/batch/check-results.ts --dir scripts/batch/results/If a matching corpus file exists, URL grounding uses the corpus. If not, live-loop output is checked against the result evidence URLs, same registrable domain, and detected machine signals.
Load KV:
bun scripts/batch/load-kv.ts --dir scripts/batch/results/ --dry-run
bun scripts/batch/load-kv.ts --dir scripts/batch/results/The loader defaults to local KV. Production requires --remote. Remote rows are not overwritten unless --overwrite is passed.
run-loop.ts reports observed input/output tokens per domain. Price an observed run with:
cost = input_tokens / 1_000_000 * input_rate + output_tokens / 1_000_000 * output_rate
Sync chat-completions rates:
| Model | Input | Output |
|---|---|---|
gpt-5.4-mini |
$0.75/M |
$4.50/M |
gpt-5.4 |
$2.50/M |
$15.00/M |
gpt-5.5 |
$5.00/M |
$30.00/M |
The Batch API cannot execute the multi-turn tool loop. Use this path only for the one-shot corpus prompt/eval workflow.
Build a scrape corpus:
bun scripts/batch/corpus.ts --domains scripts/batch/domains-all.txt --out scripts/batch/corpus/Dry-run or submit batch requests:
bun scripts/batch/submit.ts --corpus scripts/batch/corpus/ --dry-run
bun scripts/batch/submit.ts --corpus scripts/batch/corpus/Collect and validate outputs:
bun scripts/batch/collect.ts --state scripts/batch/state.json --existing path/to/current-kv-rowsEvaluate a small one-shot sample:
head -50 scripts/batch/domains-all.txt > /tmp/discovery-sample.txt
bun scripts/batch/corpus.ts --domains /tmp/discovery-sample.txt --out scripts/batch/corpus-sample/
bun scripts/batch/submit.ts --corpus scripts/batch/corpus-sample/ --dry-run
bun scripts/batch/eval-discovery.ts --domains resend.com --corpus scripts/batch/corpus-sample/