@kinloom/cli 0.1.0 → 0.2.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.
Files changed (102) hide show
  1. package/dist/assets/cached-ocr.py +556 -0
  2. package/dist/assets/ocr.md +52 -0
  3. package/dist/assets/prep-scan.md +59 -0
  4. package/dist/assets/prep-scan.py +891 -0
  5. package/dist/bundled-skills/acpl-persi/SKILL.md +94 -0
  6. package/dist/bundled-skills/acpl-persi/scripts/persi +268 -0
  7. package/dist/bundled-skills/archive-org/SKILL.md +129 -0
  8. package/dist/bundled-skills/archive-org/scripts/archive-org +879 -0
  9. package/dist/bundled-skills/blm-glo/SKILL.md +54 -0
  10. package/dist/bundled-skills/california-archives/SKILL.md +120 -0
  11. package/dist/bundled-skills/california-archives/scripts/ca-archives +373 -0
  12. package/dist/bundled-skills/chronicling-america/SKILL.md +100 -0
  13. package/dist/bundled-skills/chronicling-america/scripts/chronam +250 -0
  14. package/dist/bundled-skills/cyndis-list/SKILL.md +53 -0
  15. package/dist/bundled-skills/findagrave/SKILL.md +116 -0
  16. package/dist/bundled-skills/findagrave/scripts/findagrave +520 -0
  17. package/dist/bundled-skills/hathitrust/SKILL.md +110 -0
  18. package/dist/bundled-skills/hathitrust/scripts/hathi +194 -0
  19. package/dist/bundled-skills/kentucky-archives/SKILL.md +123 -0
  20. package/dist/bundled-skills/kentucky-archives/scripts/ky-archives +358 -0
  21. package/dist/bundled-skills/library-of-michigan/SKILL.md +111 -0
  22. package/dist/bundled-skills/library-of-michigan/scripts/michiganology +346 -0
  23. package/dist/bundled-skills/missouri-archives/SKILL.md +100 -0
  24. package/dist/bundled-skills/missouri-archives/scripts/mo-archives +528 -0
  25. package/dist/bundled-skills/nara-catalog-search/SKILL.md +118 -0
  26. package/dist/bundled-skills/nara-catalog-search/scripts/nara +934 -0
  27. package/dist/bundled-skills/narrative-audio/SKILL.md +103 -0
  28. package/dist/bundled-skills/narrative-audio/references/script-rules.md +109 -0
  29. package/dist/bundled-skills/narrative-audio/scripts/narrative-audio +290 -0
  30. package/dist/bundled-skills/new-jersey-archives/SKILL.md +118 -0
  31. package/dist/bundled-skills/new-jersey-archives/scripts/nj-archives +585 -0
  32. package/dist/bundled-skills/openarchieven/SKILL.md +90 -0
  33. package/dist/bundled-skills/openarchieven/scripts/openarchieven +432 -0
  34. package/dist/bundled-skills/texas-archives/SKILL.md +93 -0
  35. package/dist/bundled-skills/texas-archives/scripts/texas-archives +441 -0
  36. package/dist/bundled-skills/uk-archives/SKILL.md +101 -0
  37. package/dist/bundled-skills/uk-archives/scripts/uk-archives +391 -0
  38. package/dist/bundled-skills/usgs-gnis/SKILL.md +89 -0
  39. package/dist/bundled-skills/usgs-gnis/scripts/gnis +254 -0
  40. package/dist/bundled-skills/virginia-archives/SKILL.md +104 -0
  41. package/dist/bundled-skills/virginia-archives/scripts/va-archives +466 -0
  42. package/dist/bundled-skills/wikitree/SKILL.md +148 -0
  43. package/dist/bundled-skills/wikitree/scripts/wikitree +219 -0
  44. package/dist/cli.d.ts +1 -1
  45. package/dist/cli.d.ts.map +1 -1
  46. package/dist/cli.js +383 -26
  47. package/dist/cli.js.map +1 -1
  48. package/dist/client.js +1 -1
  49. package/dist/commands/init.js +3 -3
  50. package/dist/commands/ops/audit.d.ts +138 -0
  51. package/dist/commands/ops/audit.d.ts.map +1 -0
  52. package/dist/commands/ops/audit.js +867 -0
  53. package/dist/commands/ops/audit.js.map +1 -0
  54. package/dist/commands/ops/context.d.ts +100 -0
  55. package/dist/commands/ops/context.d.ts.map +1 -0
  56. package/dist/commands/ops/context.js +917 -0
  57. package/dist/commands/ops/context.js.map +1 -0
  58. package/dist/commands/ops/help.d.ts +6 -0
  59. package/dist/commands/ops/help.d.ts.map +1 -0
  60. package/dist/commands/ops/help.js +74 -0
  61. package/dist/commands/ops/help.js.map +1 -0
  62. package/dist/commands/ops/index.d.ts +6 -0
  63. package/dist/commands/ops/index.d.ts.map +1 -0
  64. package/dist/commands/ops/index.js +6 -0
  65. package/dist/commands/ops/index.js.map +1 -0
  66. package/dist/commands/ops/integrate.d.ts +56 -0
  67. package/dist/commands/ops/integrate.d.ts.map +1 -0
  68. package/dist/commands/ops/integrate.js +872 -0
  69. package/dist/commands/ops/integrate.js.map +1 -0
  70. package/dist/commands/ops/sync.d.ts +177 -0
  71. package/dist/commands/ops/sync.d.ts.map +1 -0
  72. package/dist/commands/ops/sync.js +1078 -0
  73. package/dist/commands/ops/sync.js.map +1 -0
  74. package/dist/commands/ops/telemetry.d.ts +79 -0
  75. package/dist/commands/ops/telemetry.d.ts.map +1 -0
  76. package/dist/commands/ops/telemetry.js +249 -0
  77. package/dist/commands/ops/telemetry.js.map +1 -0
  78. package/dist/commands/records/help.d.ts +18 -0
  79. package/dist/commands/records/help.d.ts.map +1 -0
  80. package/dist/commands/records/help.js +174 -0
  81. package/dist/commands/records/help.js.map +1 -0
  82. package/dist/commands/records/index.d.ts +5 -0
  83. package/dist/commands/records/index.d.ts.map +1 -0
  84. package/dist/commands/records/index.js +5 -0
  85. package/dist/commands/records/index.js.map +1 -0
  86. package/dist/commands/records/registry.d.ts +32 -0
  87. package/dist/commands/records/registry.d.ts.map +1 -0
  88. package/dist/commands/records/registry.js +227 -0
  89. package/dist/commands/records/registry.js.map +1 -0
  90. package/dist/commands/records/resolve.d.ts +14 -0
  91. package/dist/commands/records/resolve.d.ts.map +1 -0
  92. package/dist/commands/records/resolve.js +61 -0
  93. package/dist/commands/records/resolve.js.map +1 -0
  94. package/dist/commands/records/runner.d.ts +25 -0
  95. package/dist/commands/records/runner.d.ts.map +1 -0
  96. package/dist/commands/records/runner.js +224 -0
  97. package/dist/commands/records/runner.js.map +1 -0
  98. package/dist/index.d.ts +2 -0
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +2 -0
  101. package/dist/index.js.map +1 -1
  102. package/package.json +3 -3
@@ -0,0 +1,219 @@
1
+ #!/usr/bin/env -S uv run --script
2
+ # /// script
3
+ # requires-python = ">=3.11"
4
+ # dependencies = [
5
+ # "click>=8.1",
6
+ # "httpx>=0.27",
7
+ # ]
8
+ # ///
9
+ """Compact CLI for the public WikiTree API (https://api.wikitree.com/api.php).
10
+
11
+ Read-only. No account or API key is needed for public profiles; every call
12
+ sends an appId (WikiTree rate-limits calls without one). See
13
+ skills/wikitree/SKILL.md for the API reference and rules.
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ import json
19
+ import os
20
+ import sys
21
+
22
+ import click
23
+ import httpx
24
+
25
+ API_BASE = "https://api.wikitree.com/api.php"
26
+ DEFAULT_APP_ID = "Kinloom"
27
+ DEFAULT_FIELDS = "Id,Name,FirstName,LastNameAtBirth,BirthDate,DeathDate,BirthLocation"
28
+
29
+
30
+ def _app_id() -> str:
31
+ return os.environ.get("WIKITREE_APP_ID", DEFAULT_APP_ID)
32
+
33
+
34
+ def api_call(params: dict) -> list:
35
+ """One GET against the WikiTree API; returns the decoded JSON array."""
36
+ params = {"appId": _app_id(), **params}
37
+ try:
38
+ resp = httpx.get(API_BASE, params=params, timeout=30.0)
39
+ resp.raise_for_status()
40
+ except httpx.HTTPError as exc:
41
+ raise click.ClickException(f"WikiTree API request failed: {exc}") from exc
42
+ try:
43
+ data = resp.json()
44
+ except ValueError as exc:
45
+ raise click.ClickException("WikiTree API returned non-JSON") from exc
46
+ if not isinstance(data, list):
47
+ raise click.ClickException(f"Unexpected API response: {data!r}")
48
+ return data
49
+
50
+
51
+ def check_status(data: list, label: str) -> dict:
52
+ """Raise on a non-zero status element; return the first element."""
53
+ if not data:
54
+ raise click.ClickException(f"{label}: empty response from WikiTree API")
55
+ first = data[0]
56
+ status = first.get("status", 0)
57
+ if status != 0 and status != "":
58
+ raise click.ClickException(f"{label}: {status}")
59
+ return first
60
+
61
+
62
+ def show_person(person: dict) -> None:
63
+ """One compact line per profile, with unknown dates shown as such."""
64
+ name = person.get("Name") or person.get("Id", "?")
65
+ first = person.get("FirstName", "")
66
+ last = person.get("LastNameAtBirth") or person.get("LastNameCurrent", "")
67
+ birth = person.get("BirthDate") or ""
68
+ death = person.get("DeathDate") or ""
69
+ birth = "" if birth in ("", "0000-00-00") else birth
70
+ death = "" if death in ("", "0000-00-00") else death
71
+ place = person.get("BirthLocation", "")
72
+ dates = f"b. {birth}" if birth else "b. ?"
73
+ if death:
74
+ dates += f" d. {death}"
75
+ line = f"{name}: {first} {last} ({dates})"
76
+ if place:
77
+ line += f", born {place}"
78
+ click.echo(line.strip())
79
+
80
+
81
+ @click.group()
82
+ def cli() -> None:
83
+ """Read public WikiTree profiles (search, person, ancestors, bio)."""
84
+
85
+
86
+ @cli.command()
87
+ @click.option("--first", "first_name", default=None, help="First name.")
88
+ @click.option("--last", "last_name", default=None, help="Last name.")
89
+ @click.option("--birth-date", default=None, help="Birth date, YYYY-MM-DD.")
90
+ @click.option("--death-date", default=None, help="Death date, YYYY-MM-DD.")
91
+ @click.option("--birth-location", default=None, help="Birth location.")
92
+ @click.option("--death-location", default=None, help="Death location.")
93
+ @click.option("--date-include", type=click.Choice(["both", "neither"]),
94
+ default=None, help="'both' requires dates on matches.")
95
+ @click.option("--limit", type=click.IntRange(1, 100), default=10,
96
+ show_default=True, help="Results to return (1-100).")
97
+ @click.option("--start", type=int, default=0, show_default=True,
98
+ help="Result offset for paging.")
99
+ @click.option("--fields", default=DEFAULT_FIELDS, show_default=True,
100
+ help="Comma-separated profile fields, or '*'.")
101
+ @click.option("--json", "as_json", is_flag=True, help="Print raw JSON.")
102
+ def search(first_name, last_name, birth_date, death_date, birth_location,
103
+ death_location, date_include, limit, start, fields, as_json):
104
+ """Search person profiles, e.g. search --first Abraham --last Lincoln."""
105
+ if not any([first_name, last_name, birth_date, death_date,
106
+ birth_location, death_location]):
107
+ raise click.BadParameter("give at least one of --first/--last/--birth-date/--death-date/--birth-location/--death-location.")
108
+ params: dict = {"action": "searchPerson", "limit": limit, "start": start,
109
+ "fields": fields}
110
+ if first_name:
111
+ params["FirstName"] = first_name
112
+ if last_name:
113
+ params["LastName"] = last_name
114
+ if birth_date:
115
+ params["BirthDate"] = birth_date
116
+ if death_date:
117
+ params["DeathDate"] = death_date
118
+ if birth_location:
119
+ params["BirthLocation"] = birth_location
120
+ if death_location:
121
+ params["DeathLocation"] = death_location
122
+ if date_include:
123
+ params["dateInclude"] = date_include
124
+ data = api_call(params)
125
+ first = check_status(data, "searchPerson")
126
+ if as_json:
127
+ click.echo(json.dumps(data, indent=2))
128
+ return
129
+ matches = first.get("matches", [])
130
+ click.echo(f"{first.get('total', len(matches))} match(es), showing {len(matches)}:")
131
+ for match in matches:
132
+ if "Name" in match or "FirstName" in match:
133
+ show_person(match)
134
+ else:
135
+ # Sparse match (Id only): flag it so the caller follows up.
136
+ click.echo(f"Id {match.get('Id')}: sparse match, run `person {match.get('Id')}` for details")
137
+
138
+
139
+ @cli.command()
140
+ @click.argument("key")
141
+ @click.option("--fields", default=DEFAULT_FIELDS, show_default=True,
142
+ help="Comma-separated profile fields, or '*'.")
143
+ @click.option("--bio-format", type=click.Choice(["wiki", "html", "both"]),
144
+ default=None, help="Include Bio in this format.")
145
+ @click.option("--resolve-redirect", is_flag=True,
146
+ help="Follow merged-profile redirects.")
147
+ @click.option("--json", "as_json", is_flag=True, help="Print raw JSON.")
148
+ def person(key, fields, bio_format, resolve_redirect, as_json):
149
+ """Fetch one person by WikiTree ID (e.g. <Surname>-<Number>) or numeric Id."""
150
+ params: dict = {"action": "getPerson", "key": key, "fields": fields}
151
+ if bio_format:
152
+ params["bioFormat"] = bio_format
153
+ if "Bio" not in fields.split(",") and fields != "*":
154
+ params["fields"] = fields + ",Bio"
155
+ if resolve_redirect:
156
+ params["resolveRedirect"] = 1
157
+ data = api_call(params)
158
+ first = check_status(data, f"getPerson {key}")
159
+ if as_json:
160
+ click.echo(json.dumps(data, indent=2))
161
+ return
162
+ profile = first.get("person") or first.get("profile")
163
+ if not profile:
164
+ raise click.ClickException(f"getPerson {key}: no profile returned")
165
+ show_person(profile)
166
+ if bio_format and profile.get("Bio"):
167
+ click.echo(profile["Bio"])
168
+
169
+
170
+ @cli.command()
171
+ @click.argument("key")
172
+ @click.option("--depth", type=click.IntRange(1, 10), default=4,
173
+ show_default=True, help="Generations to follow (1-10).")
174
+ @click.option("--fields", default=DEFAULT_FIELDS, show_default=True,
175
+ help="Comma-separated profile fields, or '*'.")
176
+ @click.option("--json", "as_json", is_flag=True, help="Print raw JSON.")
177
+ def ancestors(key, depth, fields, as_json):
178
+ """Fetch ancestors of KEY, following father and mother.
179
+
180
+ Uses getPeople with ancestors=N: the standalone getAncestors action
181
+ is deprecated (the API returns an error telling callers to use
182
+ getPeople instead). The people dict includes the subject profile
183
+ itself, so it is excluded from the listing.
184
+ """
185
+ data = api_call({"action": "getPeople", "keys": key, "ancestors": depth,
186
+ "fields": fields})
187
+ first = check_status(data, f"getPeople {key}")
188
+ if as_json:
189
+ click.echo(json.dumps(data, indent=2))
190
+ return
191
+ people = first.get("people", {})
192
+ subject = (first.get("resultByKey") or {}).get(key, {})
193
+ subject_id = str(subject.get("Id", ""))
194
+ profiles = [p for pid, p in people.items() if pid != subject_id]
195
+ profiles.sort(key=lambda p: (p.get("BirthDate") or "9999",
196
+ p.get("Name") or ""))
197
+ click.echo(f"{len(profiles)} ancestor(s) within {depth} generation(s) of {key}:")
198
+ for profile in profiles:
199
+ show_person(profile)
200
+
201
+
202
+ @cli.command()
203
+ @click.argument("key")
204
+ @click.option("--format", "bio_format", type=click.Choice(["wiki", "html", "both"]),
205
+ default="wiki", show_default=True, help="Biography format.")
206
+ @click.option("--json", "as_json", is_flag=True, help="Print raw JSON.")
207
+ def bio(key, bio_format, as_json):
208
+ """Fetch the biography text of KEY (default wiki markup)."""
209
+ data = api_call({"action": "getBio", "key": key, "bioFormat": bio_format})
210
+ first = check_status(data, f"getBio {key}")
211
+ if as_json:
212
+ click.echo(json.dumps(data, indent=2))
213
+ return
214
+ text = first.get("bio") or ""
215
+ click.echo(text if text else "(no biography text returned)")
216
+
217
+
218
+ if __name__ == "__main__":
219
+ cli()
package/dist/cli.d.ts CHANGED
@@ -8,6 +8,6 @@ export interface RunCliOptions {
8
8
  io?: CliIo;
9
9
  fetchImpl?: typeof fetch;
10
10
  }
11
- export declare const ROOT_HELP = "Usage: kinloom <command> [options]\n\nCommands:\n init Scaffold a thin private family archive repository\n slice-gedcom Slice a combined GEDCOM export into deterministic YAML files\n seed Load local YAML + config and submit an idempotent seed batch\n submit-batch Validate and submit a typed BatchSubmission JSON/YAML file\n export-yaml Export deterministic YAML snapshot with ETag/304 support\n upload-media Validate and upload a media scan or recording via multipart POST\n reconcile Compare cached GET /api/bundle against full compileArchive\n\nGlobal options:\n -h, --help Show help for kinloom or a specific command\n\nEnvironment variables:\n KINLOOM_TOKEN Bearer token used when --token is omitted\n\nExit codes:\n 0 Success\n 1 Runtime, HTTP, or reconciliation drift error\n 2 CLI usage or boundary validation error\n 3 Optimistic concurrency conflict (HTTP 409)";
11
+ export declare const ROOT_HELP: string;
12
12
  export declare function runCli(argv: readonly string[], options?: RunCliOptions): Promise<CliExitCode>;
13
13
  //# sourceMappingURL=cli.d.ts.map
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAYA,OAAO,EAOL,KAAK,WAAW,EACjB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,KAAK;IACpB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,CAAC,EAAE,KAAK,CAAC;IACX,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B;AAWD,eAAO,MAAM,SAAS,m6BAqB0B,CAAC;AA8GjD,wBAAsB,MAAM,CAC1B,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,WAAW,CAAC,CAoVtB"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAaA,OAAO,EAOL,KAAK,WAAW,EACjB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,KAAK;IACpB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,CAAC,EAAE,KAAK,CAAC;IACX,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B;AAWD,eAAO,MAAM,SAAS,QAiC0B,CAAC;AA0RjD,wBAAsB,MAAM,CAC1B,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,WAAW,CAAC,CA0jBtB"}