@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,76 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ocr
|
|
3
|
+
description: Run content-addressed cached OCR on archival scans: fast printed-text OCR via tesseract or handwritten cursive transcription via a configured vision CLI, keyed by image SHA-256 and mode so repeated runs return instantly from disk.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Cached OCR (`kinloom ocr`)
|
|
7
|
+
|
|
8
|
+
Content-addressed OCR for genealogical scans. Each image is hashed by SHA-256 and cached on disk by hash and mode so repeated reads return immediately without re-running OCR or paying vision API cost twice.
|
|
9
|
+
|
|
10
|
+
## Printed text (`--mode printed`, default)
|
|
11
|
+
|
|
12
|
+
Uses local `tesseract` (default `--psm 6`, single uniform block of text). Every `tesseract` call forces `OMP_THREAD_LIMIT=1` and a hard per-image timeout (`--timeout`, default `30` seconds for printed text, `90` seconds for cursive vision OCR) so parallel runs fail fast instead of thrashing CPU cores:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
kinloom ocr ./scans/obituary-1912.jpg
|
|
16
|
+
kinloom ocr ./scans/city-directory-p44.jpg --psm 4 --json
|
|
17
|
+
kinloom ocr ./scans/obituary-1912.jpg --force
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Multi-file batches
|
|
21
|
+
|
|
22
|
+
Pass two or more image paths in one call instead of writing a shell `for` loop. Every image runs with the same `OMP_THREAD_LIMIT=1` pin, SHA-256 disk cache, and per-image `--timeout`. Single-image output is unchanged; multi-image runs print `=== <path> ===` sections in text or `--tsv` mode, and `{ files: [...], count, cache_hits }` in `--json`, `--boxes`, or `--find` mode:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
kinloom ocr ./scans/page-01.jpg ./scans/page-02.jpg ./scans/page-03.jpg
|
|
26
|
+
kinloom ocr ./scans/page-*.jpg --find 'probate|docket'
|
|
27
|
+
kinloom ocr ./scans/crop-1.jpg ./scans/crop-2.jpg --json
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Line boxes and raw TSV (`--boxes`, `--find`, `--tsv`)
|
|
31
|
+
|
|
32
|
+
Use these flags instead of ad-hoc `tesseract ... tsv` calls when you need pixel coordinates (printed mode only). They run the same hardened `tesseract` call (`OMP_THREAD_LIMIT=1`, `--timeout`, default `30` seconds).
|
|
33
|
+
|
|
34
|
+
- `--boxes` prints JSON: `{ sha256, psm, image_width, image_height, lines: [{ text, x0, y0, x1, y1, conf, page, block, par, line, words: [...] }], cached, cache_path }`. Words are grouped into lines by Tesseract `(block_num, par_num, line_num)`. `conf` is the mean word confidence.
|
|
35
|
+
- `--find <regex>` implies `--boxes` and keeps only lines whose text matches the regex (case-insensitive). Pass each `x0 y0 x1 y1` box to `kinloom prep-scan crop` or `kinloom prep-scan stitch`.
|
|
36
|
+
- `--tsv` prints the raw Tesseract TSV. You cannot combine it with `--boxes` or `--find`.
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
kinloom ocr ./scans/county-history-p212.jpg --find 'probate|docket'
|
|
40
|
+
kinloom ocr ./scans/county-history-p212.jpg --boxes --psm 4
|
|
41
|
+
kinloom ocr ./scans/county-history-p212.jpg --tsv > p212.tsv
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Handwritten cursive (`--mode cursive`)
|
|
45
|
+
|
|
46
|
+
Automatically downsizes scans larger than 350 KB using the bundled `prep-scan` preview pipeline, then invokes the configured vision CLI (`KINLOOM_OCR_CLI`, default `agy`) to transcribe headers and rows verbatim while marking illegible text as `[?]`:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
kinloom ocr ./scans/census-1870-sheet4.jpg --mode cursive
|
|
50
|
+
kinloom ocr ./scans/deed-1848.jpg --mode cursive --effort medium --json
|
|
51
|
+
kinloom ocr ./scans/letter-1864.jpg --mode cursive --prompt "Transcribe this letter verbatim from {image_path}."
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Cache layout
|
|
55
|
+
|
|
56
|
+
Cached JSON records are written atomically to `<cache-dir>/<sha256>_<mode-slug>.json`. Layout output uses separate files, so it never collides with plain-text OCR: `<sha256>_printed_psm<N>.tsv` (raw TSV) and `<sha256>_printed_psm<N>.boxes.json` (parsed boxes). `--find` filters the cached boxes, so a new regex on the same scan does not run `tesseract` again. `<cache-dir>` defaults to:
|
|
57
|
+
|
|
58
|
+
1. `--cache-dir <dir>`
|
|
59
|
+
2. `KINLOOM_OCR_CACHE_DIR`
|
|
60
|
+
3. `$XDG_CACHE_HOME/kinloom-ocr`
|
|
61
|
+
4. `~/.cache/kinloom-ocr`
|
|
62
|
+
|
|
63
|
+
Pass `--force` to recompute and overwrite an existing cache entry, or `--json` to inspect cache status, SHA-256 digest, engine metadata, and timing.
|
|
64
|
+
|
|
65
|
+
## Environment variables
|
|
66
|
+
|
|
67
|
+
- `KINLOOM_OCR_CACHE_DIR` (optional): overrides the default cache directory.
|
|
68
|
+
- `KINLOOM_OCR_CLI` (optional): vision CLI binary invoked in `--mode cursive` (default: `agy`).
|
|
69
|
+
- `KINLOOM_OCR_MODEL` (optional): overrides the model name passed to the vision CLI.
|
|
70
|
+
- `XDG_CACHE_HOME` (optional): standard cache base directory used when `KINLOOM_OCR_CACHE_DIR` is unset.
|
|
71
|
+
|
|
72
|
+
## Requirements
|
|
73
|
+
|
|
74
|
+
- Python 3.11+ standard library only for the wrapper itself.
|
|
75
|
+
- `tesseract` (`tesseract-ocr`) on `PATH` for `--mode printed`.
|
|
76
|
+
- Configured vision CLI (`KINLOOM_OCR_CLI`, default `agy`) on `PATH` for `--mode cursive` (plus `uv` or Pillow when oversized cursive scans need downsizing).
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: prep-scan
|
|
3
|
+
description: Prepare archival scans for inspection and publication: generate compact JPEG previews in parallel, overlay original-pixel coordinate grids, rotate/crop/redact scans, stack multi-band header+household crops, stitch census sheet header strips, search PDF text by page via pdftotext, and render selective PDF pages via pdftoppm.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Scan Preparation (`kinloom prep-scan`)
|
|
7
|
+
|
|
8
|
+
Generate lightweight inspection previews, original-pixel coordinate grids, redacted archival crops, vertically stitched multi-band crops, census header contact strips, page-indexed PDF regex searches, and selective PDF page renders. The bundled Python script uses a PEP 723 `uv run --script` header (`pillow`, `httpx`), `pdf-pages` uses `pdftoppm`, and `pdf-grep` uses `pdftotext` (or `pypdf` fallback).
|
|
9
|
+
|
|
10
|
+
## Subcommands
|
|
11
|
+
|
|
12
|
+
### 1. Compact inspection previews (`preview`)
|
|
13
|
+
|
|
14
|
+
Resize and compress one or more large archival scans in parallel into compact JPEGs (default max width `1400px`, max size `280 KB`) for fast visual review:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
kinloom prep-scan preview ./raw/census-1880.tif ./raw/deed-1872.jpg --out-dir ./previews
|
|
18
|
+
kinloom prep-scan preview ./raw/*.jpg --out-dir ./previews --max-width 1600 --max-kb 250 --json
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### 2. Rotate, crop, and redact (`crop`)
|
|
22
|
+
|
|
23
|
+
Apply optional clockwise rotation (`90`, `180`, `270`), crop to `x0,y0,x1,y1`, draw solid black redaction boxes in cropped coordinates, write the archival output image, and automatically generate a compact verification preview:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
kinloom prep-scan crop ./raw/certificate.jpg ./media/certificate.jpg \
|
|
27
|
+
--rotate 90 \
|
|
28
|
+
--box 120,80,2400,3100 \
|
|
29
|
+
--redact 40,2100,900,2250 \
|
|
30
|
+
--preview-out ./previews/certificate.preview.jpg
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 3. Census header or street contact strip (`sheet-strip`)
|
|
34
|
+
|
|
35
|
+
Slice the top or left band from local scans or remote image URLs in parallel and stitch them into a single labeled contact sheet for fast enumeration-district or street scanning:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
kinloom prep-scan sheet-strip ./sheets/ed-12-*.jpg --out ./strips/ed-12-headers.jpg --band top --band-pct 18
|
|
39
|
+
kinloom prep-scan sheet-strip ./sheets/ed-12-*.jpg --out ./strips/ed-12-streets.jpg --band left --band-pct 12 --max-kb 250
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 4. Selective PDF page rendering (`pdf-pages`) and page-indexed text search (`pdf-grep`)
|
|
43
|
+
|
|
44
|
+
Search a multi-page PDF's text layer page by page (`pdftotext`, falling back to `pypdf`) to find exact 1-based page numbers, text snippets, and a ready-to-use `--pages` argument before rendering:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
kinloom prep-scan pdf-grep ./archive/county-history.pdf --pattern "Lincoln" -i --context 200 --limit 25
|
|
48
|
+
kinloom prep-scan pdf-grep ./archive/county-history.pdf --pattern "Hardin County" --json
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`pdf-grep` matches line by line (no cross-line backtracking), exits `0` when one or more matches are found, `1` when zero matches are found, and `2` on invalid regex/flags.
|
|
52
|
+
|
|
53
|
+
Render only the requested PDF page numbers via `pdftoppm`, build compact previews in parallel, and optionally emit a labeled contact strip:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
kinloom prep-scan pdf-pages ./archive/county-history.pdf --pages 1-4,18,42-45 --out-dir ./rendered --dpi 150
|
|
57
|
+
kinloom prep-scan pdf-pages ./archive/packet.pdf --pages 1-6 --out-dir ./rendered --strip ./rendered/contact.jpg --json
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 5. Coordinate-grid inspection preview (`grid`)
|
|
61
|
+
|
|
62
|
+
Draw semi-transparent grid lines every `--step` pixels in original image pixel coordinates with crisp coordinate labels along the top and left edges, resize under `--max-width` / `--max-kb`, and print JSON (`original_width`, `original_height`, `preview_width`, `preview_height`, `step`, `out`) so exact `--box x0,y0,x1,y1` values can be read from one compact preview:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
kinloom prep-scan grid ./raw/census-1930.jpg ./previews/census-1930-grid.jpg --step 200 --max-width 1600 --max-kb 280
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 6. Multi-band vertical stitch (`stitch`)
|
|
69
|
+
|
|
70
|
+
Crop two or more boxes from one scan (such as a census sheet column header band plus the target household band, skipping unrelated neighbor rows in between), apply optional black redactions in original image pixel coordinates before cropping, center/pad narrower bands, stack them vertically separated by `--gap` pixels of `--divider-color`, and print JSON (`width`, `height`, `bytes`, `bands`, `out`):
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
kinloom prep-scan stitch ./raw/census-1930.jpg ./scans/census-1930-household.jpg \
|
|
74
|
+
--box 80,140,3200,520 \
|
|
75
|
+
--box 80,1420,3200,1760 \
|
|
76
|
+
--redact 80,1710,3200,1760 \
|
|
77
|
+
--gap 6 \
|
|
78
|
+
--divider-color "#222222" \
|
|
79
|
+
--quality 90
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Output flags (forgiving)
|
|
83
|
+
|
|
84
|
+
- `grid`, `stitch`, and `crop` take the output path positionally (`<in> <out.jpg>`) or as `--out <out.jpg>` (aliases `-o`, `--output`). Giving both with different paths exits 2.
|
|
85
|
+
- `preview` and `pdf-pages` take `--out-dir <dir>`; `--out`, `-o`, `--output-dir`, and `--output` are aliases.
|
|
86
|
+
- `--box` and `--redact` accept `x0,y0,x1,y1`, `"x0, y0, x1, y1"`, `"x0 y0 x1 y1"`, and shell-split `--box 10, 20, 30, 40`.
|
|
87
|
+
- `crop` accepts `--quality 1..100` for the archival output (default `92`).
|
|
88
|
+
|
|
89
|
+
## Environment variables
|
|
90
|
+
|
|
91
|
+
- `KINLOOM_OCR_CACHE_DIR` (optional): overrides the default preview cache root (`$XDG_CACHE_HOME/kinloom-ocr` or `~/.cache/kinloom-ocr`).
|
|
92
|
+
- `XDG_CACHE_HOME` (optional): standard cache base directory used when `KINLOOM_OCR_CACHE_DIR` is unset.
|
|
93
|
+
|
|
94
|
+
## Requirements
|
|
95
|
+
|
|
96
|
+
- `uv` (or Python 3.11+ with `pillow`, plus `httpx` for URL inputs in `sheet-strip`).
|
|
97
|
+
- `pdftoppm` and `pdftotext` (`poppler-utils` on Linux or `poppler` on macOS) for `pdf-pages` and `pdf-grep` (`pdf-grep` falls back to `pypdf` if `pdftotext` is unavailable).
|