@kinloom/cli 0.1.1 → 0.3.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/dist/assets/cached-ocr.py +786 -0
- package/dist/assets/ocr.md +76 -0
- package/dist/assets/prep-scan.md +97 -0
- package/dist/assets/prep-scan.py +1313 -0
- package/dist/bundled-skills/acpl-persi/SKILL.md +103 -0
- package/dist/bundled-skills/acpl-persi/scripts/persi +539 -0
- package/dist/bundled-skills/archive-org/SKILL.md +162 -0
- package/dist/bundled-skills/archive-org/scripts/archive-org +1576 -0
- package/dist/bundled-skills/blm-glo/SKILL.md +54 -0
- package/dist/bundled-skills/california-archives/SKILL.md +130 -0
- package/dist/bundled-skills/california-archives/scripts/ca-archives +614 -0
- package/dist/bundled-skills/chronicling-america/SKILL.md +120 -0
- package/dist/bundled-skills/chronicling-america/scripts/chronam +553 -0
- package/dist/bundled-skills/cyndis-list/SKILL.md +53 -0
- package/dist/bundled-skills/findagrave/SKILL.md +129 -0
- package/dist/bundled-skills/findagrave/scripts/findagrave +965 -0
- package/dist/bundled-skills/hathitrust/SKILL.md +117 -0
- package/dist/bundled-skills/hathitrust/scripts/hathi +379 -0
- package/dist/bundled-skills/kentucky-archives/SKILL.md +124 -0
- package/dist/bundled-skills/kentucky-archives/scripts/ky-archives +646 -0
- package/dist/bundled-skills/library-of-michigan/SKILL.md +118 -0
- package/dist/bundled-skills/library-of-michigan/scripts/michiganology +515 -0
- package/dist/bundled-skills/missouri-archives/SKILL.md +109 -0
- package/dist/bundled-skills/missouri-archives/scripts/mo-archives +751 -0
- package/dist/bundled-skills/nara-catalog-search/SKILL.md +130 -0
- package/dist/bundled-skills/nara-catalog-search/scripts/nara +1387 -0
- package/dist/bundled-skills/narrative-audio/SKILL.md +103 -0
- package/dist/bundled-skills/narrative-audio/references/script-rules.md +109 -0
- package/dist/bundled-skills/narrative-audio/scripts/narrative-audio +290 -0
- package/dist/bundled-skills/new-jersey-archives/SKILL.md +135 -0
- package/dist/bundled-skills/new-jersey-archives/scripts/nj-archives +869 -0
- package/dist/bundled-skills/openarchieven/SKILL.md +97 -0
- package/dist/bundled-skills/openarchieven/scripts/openarchieven +624 -0
- package/dist/bundled-skills/texas-archives/SKILL.md +102 -0
- package/dist/bundled-skills/texas-archives/scripts/texas-archives +666 -0
- package/dist/bundled-skills/uk-archives/SKILL.md +110 -0
- package/dist/bundled-skills/uk-archives/scripts/uk-archives +631 -0
- package/dist/bundled-skills/usgs-gnis/SKILL.md +99 -0
- package/dist/bundled-skills/usgs-gnis/scripts/gnis +418 -0
- package/dist/bundled-skills/virginia-archives/SKILL.md +144 -0
- package/dist/bundled-skills/virginia-archives/scripts/va-archives +1039 -0
- package/dist/bundled-skills/wikitree/SKILL.md +154 -0
- package/dist/bundled-skills/wikitree/scripts/wikitree +455 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +488 -26
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +30 -5
- package/dist/client.js.map +1 -1
- package/dist/commands/ops/audit.d.ts +138 -0
- package/dist/commands/ops/audit.d.ts.map +1 -0
- package/dist/commands/ops/audit.js +872 -0
- package/dist/commands/ops/audit.js.map +1 -0
- package/dist/commands/ops/context.d.ts +100 -0
- package/dist/commands/ops/context.d.ts.map +1 -0
- package/dist/commands/ops/context.js +917 -0
- package/dist/commands/ops/context.js.map +1 -0
- package/dist/commands/ops/dates.d.ts +87 -0
- package/dist/commands/ops/dates.d.ts.map +1 -0
- package/dist/commands/ops/dates.js +228 -0
- package/dist/commands/ops/dates.js.map +1 -0
- package/dist/commands/ops/help.d.ts +8 -0
- package/dist/commands/ops/help.d.ts.map +1 -0
- package/dist/commands/ops/help.js +107 -0
- package/dist/commands/ops/help.js.map +1 -0
- package/dist/commands/ops/index.d.ts +8 -0
- package/dist/commands/ops/index.d.ts.map +1 -0
- package/dist/commands/ops/index.js +8 -0
- package/dist/commands/ops/index.js.map +1 -0
- package/dist/commands/ops/integrate.d.ts +61 -0
- package/dist/commands/ops/integrate.d.ts.map +1 -0
- package/dist/commands/ops/integrate.js +1063 -0
- package/dist/commands/ops/integrate.js.map +1 -0
- package/dist/commands/ops/sync.d.ts +194 -0
- package/dist/commands/ops/sync.d.ts.map +1 -0
- package/dist/commands/ops/sync.js +1251 -0
- package/dist/commands/ops/sync.js.map +1 -0
- package/dist/commands/ops/telemetry.d.ts +79 -0
- package/dist/commands/ops/telemetry.d.ts.map +1 -0
- package/dist/commands/ops/telemetry.js +249 -0
- package/dist/commands/ops/telemetry.js.map +1 -0
- package/dist/commands/ops/verify.d.ts +76 -0
- package/dist/commands/ops/verify.d.ts.map +1 -0
- package/dist/commands/ops/verify.js +325 -0
- package/dist/commands/ops/verify.js.map +1 -0
- package/dist/commands/records/help.d.ts +18 -0
- package/dist/commands/records/help.d.ts.map +1 -0
- package/dist/commands/records/help.js +174 -0
- package/dist/commands/records/help.js.map +1 -0
- package/dist/commands/records/index.d.ts +5 -0
- package/dist/commands/records/index.d.ts.map +1 -0
- package/dist/commands/records/index.js +5 -0
- package/dist/commands/records/index.js.map +1 -0
- package/dist/commands/records/registry.d.ts +32 -0
- package/dist/commands/records/registry.d.ts.map +1 -0
- package/dist/commands/records/registry.js +227 -0
- package/dist/commands/records/registry.js.map +1 -0
- package/dist/commands/records/resolve.d.ts +14 -0
- package/dist/commands/records/resolve.d.ts.map +1 -0
- package/dist/commands/records/resolve.js +61 -0
- package/dist/commands/records/resolve.js.map +1 -0
- package/dist/commands/records/runner.d.ts +27 -0
- package/dist/commands/records/runner.d.ts.map +1 -0
- package/dist/commands/records/runner.js +255 -0
- package/dist/commands/records/runner.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: archive-org
|
|
3
|
+
description: Search, inspect, grep cached OCR text, and download pages or files from Internet Archive items via the bundled Python 3.11+ `archive-org` CLI or the public advancedsearch and metadata APIs. Covers CLI usage, persistent local disk caching (`KINLOOM_IA_CACHE_DIR`), exact printed-page to leaf resolution, Lucene query syntax, field selection, pagination, file downloads, and worked examples. Use when finding digitized books, genealogies, newspapers, audio, or other archived material, or when searching inside or downloading scans from Internet Archive for family-history research.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Archive.org
|
|
7
|
+
|
|
8
|
+
This skill includes a standalone executable Python 3.11+ standard-library CLI at `skills/archive-org/scripts/archive-org` (`#!/usr/bin/env -S python3 -S`). No virtualenv, `uv`, third-party packages, or API key is required. The APIs are public and read-only.
|
|
9
|
+
|
|
10
|
+
## Bundled CLI (`scripts/archive-org`)
|
|
11
|
+
|
|
12
|
+
Path: `skills/archive-org/scripts/archive-org`
|
|
13
|
+
|
|
14
|
+
### Persistent local disk cache (all network commands)
|
|
15
|
+
|
|
16
|
+
Every network command (`get`, `grep`, `text`, `lookup`, `page`, `download`, `search`, and `fulltext`) writes atomically under `~/.cache/kinloom-ia/` (overrideable via `KINLOOM_IA_CACHE_DIR`) using per-item advisory locks (`fcntl.flock`) so concurrent processes never duplicate downloads and repeat calls make zero HTTP requests. Pass `--refresh` on any command to bypass the local cache and fetch fresh data.
|
|
17
|
+
|
|
18
|
+
Cache layout:
|
|
19
|
+
|
|
20
|
+
- `<item_id>/metadata.json`: item metadata and file inventory from `/metadata/<item_id>`, shared by `get`, `grep`, `page`, and `download`.
|
|
21
|
+
- `<item_id>/scandata.xml`: raw IA leaf/page scan metadata (when present).
|
|
22
|
+
- `<item_id>/page_index.json`: pre-parsed bidirectional lookup table mapping `scandata` `leafNum`, BookReader `n<leaf>` index (skipping deleted/non-access leaves), and `printed_page` label so cache hits never re-parse XML.
|
|
23
|
+
- `<item_id>/djvu.txt`: form-feed (`\x0c`) page-delimited OCR text (fetched from `_djvu.txt` first; falls back to `_hocr_searchtext.txt.gz` + `_hocr_pageindex.json.gz` only when `_djvu.txt` is absent, fails, or lacks `\x0c` page breaks).
|
|
24
|
+
- `<item_id>/pages/n<leaf>_<suffix>.jpg`: cached rendered page JPEGs (for example `n127_w2400.jpg` or `n127_s2.jpg`) served directly to `--out` on repeat `page` calls.
|
|
25
|
+
- `<item_id>/files/<relpath>`: cached item files downloaded via `download` (with path-traversal validation; exact raw `scandata.xml` and `_djvu.txt` artifacts are also reused without re-downloading).
|
|
26
|
+
- `_queries/<search|fulltext>/<sha256>.json`: cached JSON responses for `search` and `fulltext` keyed by canonical query parameters with a 168-hour (7-day) default TTL (`--cache-ttl-hours` or `KINLOOM_IA_QUERY_TTL_HOURS`).
|
|
27
|
+
|
|
28
|
+
Transient HTTP `429`, `502`, `503`, and `504` responses retry politely up to 2 times (honoring numeric `Retry-After` capped at 5s), while `403`, `404`, and socket timeouts fail fast with 0 retries.
|
|
29
|
+
|
|
30
|
+
### Search inside cached digitized books (`grep`)
|
|
31
|
+
|
|
32
|
+
Downloads missing metadata, `scandata.xml`, and OCR text in parallel (`max_workers=6`, `timeout=25`) on cache miss, then searches line by line (never `re.S` + `.*`) and maps every match to its exact BookReader `leaf`, `printed_page`, snippet, and direct JPEG URL:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# Search one or more digitized books (cache miss populates ~/.cache/kinloom-ia/<id>/)
|
|
36
|
+
skills/archive-org/scripts/archive-org grep ourmartyrpreside00banc --pattern 'Gettysburg' --context 240 --limit 25
|
|
37
|
+
|
|
38
|
+
# Case-insensitive multi-item regex grep with structured JSON output
|
|
39
|
+
skills/archive-org/scripts/archive-org grep item_a item_b --pattern 'Lincoln|Douglass' -i --json
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Download single high-res pages (`page`) by printed page or leaf
|
|
43
|
+
|
|
44
|
+
Resolve printed book page numbers to exact BookReader leaves automatically via cached `page_index.json` (eliminating off-by-one leaf offsets), or pass `--leaf` / legacy positional `<leaf>` directly:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# Resolve printed page "12" automatically and save at BookReader scale 2
|
|
48
|
+
skills/archive-org/scripts/archive-org page ourmartyrpreside00banc --printed-page 12 --scale 2 --out ./page12.jpg
|
|
49
|
+
|
|
50
|
+
# Fetch an explicit BookReader leaf n0 into a file or directory
|
|
51
|
+
skills/archive-org/scripts/archive-org page ourmartyrpreside00banc --leaf 0 --scale 2 --out ./cover.jpg
|
|
52
|
+
skills/archive-org/scripts/archive-org page ourmartyrpreside00banc 0 --width 1200 --out ./downloads
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Single-page URL patterns: `https://archive.org/download/<identifier>/page/n<leaf>_s<scale>.jpg` and `https://archive.org/download/<identifier>/page/n<leaf>_w<width>.jpg`. Returns HTTP 403 on borrow-only / `inlibrary` items.
|
|
56
|
+
|
|
57
|
+
### Read OCR text for specific pages (`text`) and resolve page numbers (`lookup`)
|
|
58
|
+
|
|
59
|
+
`text` reads the cached `djvu.txt` + `page_index.json` (populating them on a cache miss, same as `grep`), resolves printed page labels to BookReader leaves, and prints that page's OCR text with its leaf / printed-page / scandata-leaf metadata plus `image_url` and `details_url`. It never downloads a JPEG; use `page` only when you need to look at the scan. Pass exactly one of `--printed-page`, `--leaf`, or `--pages <p1-p2>` (inclusive printed-page range, which also covers unnumbered leaves between the endpoints):
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# OCR text of printed page 12 (cache-hit repeat calls make zero HTTP requests)
|
|
63
|
+
kinloom ia text ourmartyrpreside00banc --printed-page 12
|
|
64
|
+
|
|
65
|
+
# A printed-page range or an explicit BookReader leaf, as JSON
|
|
66
|
+
kinloom ia text ourmartyrpreside00banc --pages 12-14 --json
|
|
67
|
+
kinloom ia text ourmartyrpreside00banc --leaf 7 --json
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
JSON shape: `{identifier, cached, pages: [{leaf, scandata_leaf, printed_page, text, image_url, details_url}]}`. An unknown printed page, out-of-range leaf, reversed range, or OCR text without page breaks exits nonzero with a clear message.
|
|
71
|
+
|
|
72
|
+
`lookup` resolves printed page <-> BookReader leaf <-> scandata leaf using only `metadata.json` + `page_index.json` (never fetches `djvu.txt` or JPEGs). Pass exactly one of `--printed-page`, `--leaf`, or `--scandata-leaf`:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
kinloom ia lookup ourmartyrpreside00banc --printed-page 12
|
|
76
|
+
kinloom ia lookup ourmartyrpreside00banc --leaf 20 --json
|
|
77
|
+
kinloom ia lookup ourmartyrpreside00banc --scandata-leaf 21 --json
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Both accept `--refresh` to re-fetch cached metadata/scandata (and OCR text for `text`).
|
|
81
|
+
|
|
82
|
+
### Search item metadata (`search`) vs full-text OCR (`fulltext`)
|
|
83
|
+
|
|
84
|
+
`search` calls `advancedsearch.php`, which searches **item metadata only** (title, creator, description, subjects), NOT the OCR text inside digitized books. Use `fulltext` to search across books, and `grep` to search inside specific known items:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# Metadata search: titles mentioning Lincoln
|
|
88
|
+
skills/archive-org/scripts/archive-org search 'title:(Lincoln)'
|
|
89
|
+
|
|
90
|
+
# Narrow metadata search to digitized texts for a historical figure
|
|
91
|
+
skills/archive-org/scripts/archive-org search '"Frederick Douglass"' --mediatype texts
|
|
92
|
+
|
|
93
|
+
# Sort by popularity, second page, full JSON
|
|
94
|
+
skills/archive-org/scripts/archive-org search 'title:(Lincoln)' --sort 'downloads desc' --rows 5
|
|
95
|
+
skills/archive-org/scripts/archive-org search 'title:(Lincoln)' --page 2
|
|
96
|
+
skills/archive-org/scripts/archive-org search 'title:(Lincoln)' --json
|
|
97
|
+
|
|
98
|
+
# Full-text OCR search inside digitized books (returns highlighted OCR snippets)
|
|
99
|
+
skills/archive-org/scripts/archive-org fulltext '"Abraham Lincoln" Gettysburg' --rows 5
|
|
100
|
+
skills/archive-org/scripts/archive-org fulltext '"Clara Barton" Red Cross' --json
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The `search` query is Lucene syntax (see below). Default returned fields are `identifier`, `title`, `creator`, `date`, `mediatype`; pass `--field` (repeatable) to change them. A zero-hit `search` means no item metadata matched; run `fulltext` before concluding a name is absent from digitized directories or county histories.
|
|
104
|
+
|
|
105
|
+
### Read an item's metadata and files
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
skills/archive-org/scripts/archive-org get <identifier>
|
|
109
|
+
skills/archive-org/scripts/archive-org get <identifier> --files
|
|
110
|
+
skills/archive-org/scripts/archive-org get <identifier> --json
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Download files
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# List an item's files first, then download the OCR text or PDF
|
|
117
|
+
skills/archive-org/scripts/archive-org download <identifier> --list
|
|
118
|
+
skills/archive-org/scripts/archive-org download <identifier> <identifier>_djvu.txt --out ./downloads
|
|
119
|
+
skills/archive-org/scripts/archive-org download <identifier> <identifier>.pdf --out ./downloads
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The CLI refuses a file name that is not in the item's file list, so list first when unsure. Download URLs follow the site's redirect to the file server automatically.
|
|
123
|
+
|
|
124
|
+
### Build a website search URL offline
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
skills/archive-org/scripts/archive-org url 'title:(Lincoln)' --mediatype texts
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Advanced Search API (verified live 2026-11-24)
|
|
131
|
+
|
|
132
|
+
- Endpoint: `GET https://archive.org/advancedsearch.php`
|
|
133
|
+
- Auth: none for read access. No key is normally needed.
|
|
134
|
+
- Required params: `q` (Lucene query), `output=json`. Common params: `fl[]` (repeatable field list), `rows` (results per page, default 50), `page` (page number), `sort[]` (repeatable, e.g. `downloads desc`, `date asc`).
|
|
135
|
+
- Response shape: `{ responseHeader: { status: 0, QTime }, response: { numFound, start, docs: [...] } }`. `status: 0` means success.
|
|
136
|
+
- The human search UI lives at the same URL: `https://archive.org/advancedsearch.php` (interactive query builder at `https://archive.org/advancedsearch.php#raw`).
|
|
137
|
+
- Docs: `https://archive.org/help/json.php` and `https://archive.org/developers/index-apis.html`.
|
|
138
|
+
|
|
139
|
+
### Lucene query syntax (verified live)
|
|
140
|
+
|
|
141
|
+
- Fielded: `title:(Lincoln)`, `creator:(Douglass)`, `mediatype:(texts)`, `collection:(...)`, `year:1895`.
|
|
142
|
+
- Boolean: `title:(Lincoln) AND mediatype:(texts)`, `OR`, `NOT`, parentheses for grouping.
|
|
143
|
+
- Exact phrase: `"Clara Barton"`.
|
|
144
|
+
- Wildcard: `Clemens*`.
|
|
145
|
+
- Plain keywords match broadly across fields; quote exact names and use fielded queries to narrow results.
|
|
146
|
+
|
|
147
|
+
## Metadata API (verified live 2026-11-24)
|
|
148
|
+
|
|
149
|
+
- Endpoint: `GET https://archive.org/metadata/<identifier>`
|
|
150
|
+
- Auth: none. Returns JSON with `metadata` (title, creator, date, mediatype, collection, description, subject) and `files` (each with `name`, `format`, `size`, `md5`, `sha1`, `mtime`, `source`).
|
|
151
|
+
- Item page: `https://archive.org/details/<identifier>` (the metadata endpoint is the same path with `/details/` swapped to `/metadata/`).
|
|
152
|
+
|
|
153
|
+
## File download (verified live 2026-11-24)
|
|
154
|
+
|
|
155
|
+
- Pattern: `GET https://archive.org/download/<identifier>/<filename>` (follows a redirect to the file server; the CLI follows it).
|
|
156
|
+
- Common derivative files for a scanned book: `<id>.pdf` (full scan), `<id>_djvu.txt` (OCR text), `<id>_djvu.xml`, `<id>_files.xml` (file inventory), `<id>_meta.sqlite`. Always list the item's files first; not every derivative exists for every item.
|
|
157
|
+
- Be a good citizen: download only the files the research needs, one item at a time. Do not bulk-mirror collections. Uploads and writes need an account and are out of scope for this skill.
|
|
158
|
+
|
|
159
|
+
## Environment variables
|
|
160
|
+
|
|
161
|
+
- `KINLOOM_IA_CACHE_DIR` (optional): overrides the default `~/.cache/kinloom-ia` cache directory used by all network commands.
|
|
162
|
+
- `KINLOOM_IA_QUERY_TTL_HOURS` (optional): overrides the default `168` hour (7-day) TTL for cached `search` and `fulltext` responses. No API key or login is required.
|