@ysgao/web-cli 0.0.0-stage → 0.1.3

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.
@@ -0,0 +1,79 @@
1
+ # Checking FMA and Terminologia Anatomica for anatomy queries
2
+
3
+ When a question is about what a specific anatomical structure, layer, or historical/Latin synonym
4
+ actually *is* or *maps to* — rather than a clinical-practice question (diagnosis, management,
5
+ imaging findings) — check FMA (Foundational Model of Anatomy) and Terminologia Anatomica (TA)
6
+ directly. UpToDate and ClinicalKey are clinical-practice resources: they have essentially no
7
+ coverage of fine-grained structural nomenclature, and their search silently autocorrects an
8
+ unfamiliar term to something unrelated rather than reporting "not found" (see the main SKILL.md's
9
+ "don't trust a single site's silence" section) — do not treat a confident-looking result from them
10
+ as evidence about anatomical terminology.
11
+
12
+ **This outranks `web-cli search`'s own site set.** `search` returns `uptodate`, `clinicalkey`, and
13
+ `googlemedsearch` results together in one call, but for an anatomy-terminology question none of
14
+ those three carry any weight against FMA/TA — three clinical-practice/general-web sites agreeing
15
+ with each other is still not anatomical-nomenclature evidence, since all three are liable to have
16
+ autocorrected the same unfamiliar term the same way. Treat an FMA/TA hit as the answer, and a
17
+ `web-cli search` result as, at best, corroborating context once FMA/TA has already confirmed the
18
+ term — never the other way around. (Don't run `web-cli websearch` against it and treat that as a
19
+ substitute for FMA/TA either — general/open-web search has the same autocorrection problem, just
20
+ across a much wider and less curated set of sources.)
21
+
22
+ ## FMA via the EBI Ontology Lookup Service (OLS4) — scriptable, no auth
23
+
24
+ This is a real, live, unauthenticated JSON REST API — usable directly with `curl`/`WebFetch`, no
25
+ browser needed:
26
+
27
+ ```
28
+ GET https://www.ebi.ac.uk/ols4/api/search?q=<term>&ontology=fma&rows=<n>
29
+ ```
30
+
31
+ Returns a list of matching FMA classes (`label`, `obo_id`, `iri`). Then pull the full record —
32
+ crucially its Latin/TA cross-reference — for any hit that looks relevant:
33
+
34
+ ```
35
+ GET https://www.ebi.ac.uk/ols4/api/ontologies/fma/terms?iri=<url-encoded IRI>
36
+ ```
37
+
38
+ The `_embedded.terms[0].annotation` object is the payload that matters:
39
+ - `preferred name` — FMA's canonical English name
40
+ - `synonym` — other accepted English names
41
+ - `non-English equivalent` — this is where the **Latin (Terminologia Anatomica) name** and,
42
+ often, the **TA lamina/part number** (e.g. `"Lamina colliculi superioris IV"`) show up. In
43
+ practice this makes a separate TA lookup unnecessary for most questions — FMA already embeds the
44
+ TA cross-reference as a synonym.
45
+
46
+ **This FMA mirror is described by its own metadata as "a slimmed down version of FMA"** — a
47
+ specific compound/historical Latin phrase can return zero hits even when the modern English
48
+ structure it refers to is present. If a literal phrase search comes up empty, back off to the
49
+ modern head term (e.g. search "superior colliculus" rather than "corpora quadrigemina") and look
50
+ through *its* synonym list instead of concluding the structure isn't in FMA at all.
51
+
52
+ ## Terminologia Anatomica directly
53
+
54
+ The official TA2 viewer (`https://ta2viewer.openanatomy.org/`) is a real, live site, but it's a
55
+ client-side-rendered app with no static data endpoint — `curl`/`WebFetch` only get the empty page
56
+ shell, not the actual terminology data. Reaching it directly requires a JS-capable browser (the
57
+ `claude-in-chrome` tools), not a plain HTTP fetch. Given that, prefer the FMA route above first —
58
+ its embedded TA cross-references cover the common case — and only drive the TA2 viewer directly
59
+ when you specifically need to browse TA's own hierarchy/numbering rather than confirm a synonym.
60
+
61
+ ## Worked example: "stratum medium of corpora quadrigemina"
62
+
63
+ This phrase returns **zero results anywhere on the general web** (confirmed via an exact-phrase
64
+ search) — it is not itself an attested modern term. Searching FMA for the modern head term instead
65
+ resolved it cleanly:
66
+
67
+ - `fma72409` — **Middle gray layer of superior colliculus**, non-English equivalents include
68
+ `Stratum griseum intermediale` and **`Stratum griseum mediale`**; synonym `Intermediate gray
69
+ layer`.
70
+ - `fma71113` — **Middle white layer of superior colliculus**, non-English equivalents include
71
+ `Stratum album intermediale` and **`Stratum album mediale`**; synonym `Intermediate white layer`.
72
+
73
+ Both the gray and white intermediate laminae of the superior colliculus have a Latin `mediale`
74
+ ("medium/middle") form — the qualifier that actually distinguishes them is `griseum` (gray) vs.
75
+ `album` (white), not `medium` itself. So an unqualified "stratum medium" is genuinely ambiguous
76
+ between the intermediate gray layer and the intermediate white layer per FMA's own synonym data —
77
+ it isn't a synonym of one specifically unless the source that used the phrase had already narrowed
78
+ it some other way (e.g. by context, or a `griseum`/`album` qualifier that got dropped in
79
+ translation).
@@ -0,0 +1,246 @@
1
+ # Parsed output: use it instead of hand-rolling per-site parsing
2
+
3
+ `search` and `get` results include a `parsed` field alongside the existing raw `results` / `article`
4
+ fields — a normalized, best-effort extraction produced by this package's own maintained per-site
5
+ parsers (`src/parsers/uptodate.ts`, `src/parsers/clinicalkey.ts`, `src/parsers/googlemedsearch.ts`).
6
+ **Prefer `parsed` over writing your own ad-hoc parsing against the raw JSON** — each site's raw
7
+ shape has a real, non-obvious gotcha (documented per-site below) that an improvised one-off script
8
+ is likely to get wrong, and these parsers were written and tested against real captured output, not
9
+ guessed at.
10
+
11
+ `parsed` is always additive and best-effort: a parsing gap or an unrecognized raw shape (e.g. the
12
+ site changed its frontend) degrades to `parsed: null`, never an error and never a change to the
13
+ existing raw field it was derived from. If `parsed` is `null`, fall back to the raw field — it's
14
+ still there, unchanged.
15
+
16
+ **Every hit that makes it into `parsed.hits` has both a `title` and a real, absolute, directly
17
+ clickable `url`** — a hit missing either is dropped by that site's parser rather than emitted
18
+ half-formed, so you never have to guess whether a given hit is citable. This holds for every
19
+ registered site, including ClinicalKey, whose raw search response has no URL field at all (see
20
+ below for how its `url` is constructed).
21
+
22
+ ## `search` deliberately does not fetch full text for every hit
23
+
24
+ Populating `title`/`url`/`snippet`/`year`/`source` on every hit is pure in-process extraction from
25
+ the one search response already fetched — no extra network cost, so it happens for the whole hit
26
+ list. Fetching full article text (`getArticle`) is a real extra network call per hit, so `search`
27
+ only does it for a small, cheaply-selected slice — see `src/parsers/selectKeyReferences.ts` and the
28
+ main SKILL.md's "keyReferences" section. Don't expand every hit into full text yourself by looping
29
+ `get` over the whole `parsed.hits` list; that defeats the point of this selection. If you need full
30
+ text for a hit that wasn't selected into `keyReferences`, call `web-cli get <site> <id-or-url>`
31
+ explicitly for that one hit.
32
+
33
+ ## Shape
34
+
35
+ ```ts
36
+ // search's SiteOutcome.parsed
37
+ interface NormalizedSearchResult {
38
+ hits: Array<{
39
+ id?: string; // the site's own opaque identifier, if any (pass to `web-cli get <site> <id>`)
40
+ title: string;
41
+ url: string; // ALWAYS absolute and directly clickable — never root-relative, never absent
42
+ snippet?: string; // plain text, HTML/highlight markup already stripped
43
+ year?: string; // best-effort 4-digit publication/last-revision year, if the site's data has one
44
+ source?: string; // best-effort "journal"/publisher name, if the site's data has one
45
+ meta?: Record<string, unknown>;
46
+ }>;
47
+ totalCount?: number;
48
+ didYouMean?: string[]; // present only when the site's own response signals a reinterpreted query
49
+ }
50
+
51
+ // get's top-level .parsed, and a search keyReferences[] entry's .article
52
+ interface NormalizedArticle {
53
+ title?: string;
54
+ url?: string;
55
+ text: string; // ALWAYS plain text — HTML already stripped
56
+ html?: string; // the original HTML this was derived from, if the site had one
57
+ outline?: Array<{ label: string; level: number }>;
58
+ references?: unknown[];
59
+ meta?: Record<string, unknown>; // may include year/source too — see per-site notes below
60
+ }
61
+ ```
62
+
63
+ ## Per-site notes (each confirmed against a real, live `web-cli search`/`get` run)
64
+
65
+ ### uptodate
66
+
67
+ - **The article's real text lives only inside HTML** (`bodyHtml` in the raw response) — there is no
68
+ plain-text field anywhere in UpToDate's own raw `getArticle` response. `parsed.text` is that HTML
69
+ stripped to plain text; use it instead of reading `article.data.bodyHtml` (raw HTML) directly.
70
+ - The raw response's own `url` field is root-relative (`/contents/<slug>?...`) — `parsed` resolves
71
+ it against `https://www.uptodate.com` so `parsed.hits[].url`/`parsed.url` are always absolute.
72
+ - `parsed.didYouMean` is populated from `searchMessaging.systemAction.type` when it's anything other
73
+ than `"MATCHED"` — a concrete signal for this skill's own "don't trust a single site's silence"
74
+ guidance (see main SKILL.md), not just "eyeball the titles yourself."
75
+ - Search hit snippets carry literal `<b>...</b>` highlight markup and HTML entities (`&hellip;`) in
76
+ the raw response — already stripped in `parsed.hits[].snippet`.
77
+ - **UpToDate has no real publication-year/journal concept** — it's a continuously-revised topic
78
+ review, not a dated paper, and UpToDate itself is the sole publisher. `parsed.hits[].year`/
79
+ `.source` are therefore unset at the search-hit level (confirmed: UpToDate's own search hits carry
80
+ no date field at all). A fully-expanded `getArticle`/`keyReferences` article's `meta.source` is
81
+ fixed as `"UpToDate"`, and `meta.year` is derived from the topic's own last-major-update timestamp
82
+ (`translatedTopicInfos[].lastMajorUpdateMs`) as the closest available proxy for "year".
83
+
84
+ Real example (trimmed) — raw `search` response:
85
+ ```json
86
+ {
87
+ "data": {
88
+ "searchMessaging": { "systemAction": { "type": "MATCHED" } },
89
+ "searchResults": [
90
+ {
91
+ "id": "3869",
92
+ "title": "Hypertension in adults: Initial management",
93
+ "url": "/contents/hypertension-in-adults-initial-management?search=...&usage_type=default",
94
+ "snippet": "&hellip;drug <b>therapy</b>, initial drug selection...",
95
+ "subtype": "medical_review"
96
+ }
97
+ ]
98
+ }
99
+ }
100
+ ```
101
+ becomes:
102
+ ```json
103
+ {
104
+ "hits": [
105
+ {
106
+ "id": "3869",
107
+ "title": "Hypertension in adults: Initial management",
108
+ "url": "https://www.uptodate.com/contents/hypertension-in-adults-initial-management?search=...&usage_type=default",
109
+ "snippet": "\u2026drug therapy, initial drug selection...",
110
+ "meta": { "subtype": "medical_review" }
111
+ }
112
+ ],
113
+ "totalCount": 1
114
+ }
115
+ ```
116
+ Note `url` is now absolute (resolved against `https://www.uptodate.com`), unlike the raw response's
117
+ root-relative form, and `year`/`source` are absent (no date field exists at this level).
118
+
119
+ ### clinicalkey
120
+
121
+ - **ClinicalKey's own search hits carry no `url`/`link`/`href`-shaped field at all — only an opaque
122
+ `eid`.** No generic heuristic could ever find a link here — this is exactly why `search`'s
123
+ key-reference selection reads `id`/`url` from each site's own parser instead of guessing at the
124
+ raw JSON's shape.
125
+ - **`parsed.hits[].url` is nonetheless a real, absolute, directly clickable URL** — the parser
126
+ builds it itself from `eid` + `contenttype`, as
127
+ `https://www.clinicalkey.com/#!/content/<contenttype-lowercased>/<eid>`. This pattern is confirmed
128
+ from two independent pieces of ClinicalKey's own learned `getArticle` template
129
+ (`~/.web-cli/learned/clinicalkey.json`): the `CK-Path` request header
130
+ (`/content/clinical_overview/<eid>`) and the response's own `urlTemplate` field
131
+ (`#!/content/{contentType}/{eid}`) — ClinicalKey is an Angular-style hash-routed single-page app,
132
+ so this really is the URL a browser would show for that article. **To fetch a hit's full content
133
+ through this CLI, `web-cli get clinicalkey <parsed.hits[i].url>` and `... <parsed.hits[i].id>`
134
+ (the bare `eid`) both work** — `matchingParam()` (discovery/discover.ts) reduces either form to
135
+ the identical tier-1 replay needle, since the url's own last path segment IS the eid. Prefer
136
+ `url`, though: it's what `search`'s own `keyReferences` expansion uses, because only the full URL
137
+ also works if a fresh discovery pass is ever needed — a bare `eid` alone can't reconstruct the
138
+ `contenttype` segment ClinicalKey's real article URL needs, so tier-2 discovery given just the id
139
+ ends up trying to navigate to a nonexistent `clinicalkey.com/<eid>` page (confirmed live: this is
140
+ exactly what made every one of a search's ClinicalKey key references fail once its cached
141
+ `getArticle` template went stale).
142
+ - `parsed.hits[].year` comes from `pubdatetxt` (preferred) or `copyrightyr`; `.source` comes from
143
+ `srctitle` (e.g. "Clinical Overviews") — both already present on every search hit, no extra fetch.
144
+ - `parsed.didYouMean` is populated from `resultsAnalysis.refinements.relations[].concept` when
145
+ present — ClinicalKey's own related-concept signal, analogous to UpToDate's.
146
+ - **`getArticle` has two different confirmed-live raw shapes, not one** — this parser was
147
+ originally written against only the first and silently produced an empty `text`/`html` for
148
+ every article fetched through the second, undetected until a later session's key-reference
149
+ expansions were checked directly. Which shape a given account/content-type/endpoint variant
150
+ returns isn't predictable in advance, so `parsed` reads every field from whichever of the two
151
+ locations actually has it:
152
+ 1. An **older/richer** shape: `{ eid, contentType, title, html: { content }, metadata: {
153
+ publishedDate, copyrightYear, "hcs:hasConsumerFriendlyName", hasCreator: { name }, ... },
154
+ outline: [...], references: [...] }` — HTML nested under `html.content`, bibliographic detail
155
+ in a JSON-LD-ish `metadata` object, and (uniquely to this shape) a top-level `references[]`.
156
+ 2. A **flatter** shape (confirmed live via `web-cli observe --site clinicalkey --intent
157
+ getArticle`): `{ eid, contentType, title, copyright, copyrightYear?, dates: [{ type:
158
+ "PUBLISHED"|"CREATED"|..., date }], authors: [...], outline: [...], content }` — the HTML
159
+ body is a top-level `content` string, not nested; year comes from the `dates[]` entry typed
160
+ `"PUBLISHED"` or a top-level `copyrightYear`; there is no `metadata['hcs:hasConsumerFriendlyName']`
161
+ equivalent, so `parsed.meta.source` falls back to the top-level `copyright` string instead
162
+ (e.g. `"Elsevier"`, or a full `"Copyright © 2025 Elsevier Inc..."` sentence) — this shape has
163
+ never been observed with a top-level `references` field.
164
+
165
+ `parsed.text`/`.html` strip whichever HTML location is present, `parsed.outline` flattens the
166
+ already-nested `outline[]` (structured JSON in both shapes, unlike UpToDate's HTML outline),
167
+ `parsed.url` builds the same way as the search-hit case above, and `meta.year`/`meta.source` are
168
+ read from whichever pair of fields the actual response carries.
169
+
170
+ Real example (trimmed) — raw `search` hit:
171
+ ```json
172
+ {
173
+ "eid": "67-s2.0-CPLD-2ed33a2e-3f10-4ecb-adf2-c45d950531c0",
174
+ "itemtitle": "Hypertension Management in Patients With Severe Obesity",
175
+ "srctitle": "Clinical Overviews",
176
+ "contenttype": "CLINICAL_OVERVIEW",
177
+ "pubdatetxt": "2026-02-09T00:00:00Z",
178
+ "summary": "Obesity affects over 1 billion adults worldwide..."
179
+ }
180
+ ```
181
+ becomes:
182
+ ```json
183
+ {
184
+ "id": "67-s2.0-CPLD-2ed33a2e-3f10-4ecb-adf2-c45d950531c0",
185
+ "title": "Hypertension Management in Patients With Severe Obesity",
186
+ "url": "https://www.clinicalkey.com/#!/content/clinical_overview/67-s2.0-CPLD-2ed33a2e-3f10-4ecb-adf2-c45d950531c0",
187
+ "snippet": "Obesity affects over 1 billion adults worldwide...",
188
+ "year": "2026",
189
+ "source": "Clinical Overviews",
190
+ "meta": { "srctitle": "Clinical Overviews", "contenttype": "CLINICAL_OVERVIEW", "auth": [...], "pubdatetxt": "..." }
191
+ }
192
+ ```
193
+ Note `url` is present and real, even though the raw hit had no URL-shaped key at all — but calling
194
+ `get` to fetch full text still requires the bare `id`, not this `url`.
195
+
196
+ ### googlemedsearch
197
+
198
+ - **Uses the real destination URL, not a Google click-tracking redirect**: this site's raw hits
199
+ carry `clicktrackUrl` (a `https://www.google.com/url?...&q=<real URL>&...` wrapper) alongside the
200
+ hit's real destination (`url`/`unescapedUrl`/`formattedUrl`) — `parsed.hits[].url` always uses the
201
+ latter (preferring `unescapedUrl`), confirmed via a real captured hit where the two differ.
202
+ - `parsed.hits[].year` is extracted from a leading "D Mon YYYY" date in the snippet when present
203
+ (e.g. "28 Aug 2019 ..." — this site's only date signal; many hits have no such prefix, in which
204
+ case `year` is correctly left unset). `.source` comes from Google's own
205
+ `richSnippet.metatags.dcPublisher` (e.g. "NICE") when present.
206
+ - **`search` never expands this site's hits into `keyReferences`** (full-text fetch) — its own
207
+ `getArticle` endpoint is a known-stale decoy (see `src/discovery/preseed.ts`'s own comment) that
208
+ returns unrelated tracking-pixel content for any id, and the pages its hits link to are arbitrary
209
+ third-party sites outside this CLI's subscription-site scope anyway. There is no `parseArticle`
210
+ for this site; fetch a linked page yourself (e.g. via `WebFetch`) if you need its full text.
211
+
212
+ Real example (trimmed) — raw hit:
213
+ ```json
214
+ {
215
+ "title": "<b>Hypertension</b> in adults: diagnosis and <b>management</b> | Guidance - NICE",
216
+ "titleNoFormatting": "Hypertension in adults: diagnosis and management | Guidance - NICE",
217
+ "url": "https://www.nice.org.uk/guidance/ng136",
218
+ "unescapedUrl": "https://www.nice.org.uk/guidance/ng136",
219
+ "clicktrackUrl": "https://www.google.com/url?client=internal-element-cse&...&q=https://www.nice.org.uk/guidance/ng136&...",
220
+ "content": "28 Aug 2019 <b>...</b> This guideline covers identifying and treating primary <b>hypertension</b>...",
221
+ "richSnippet": { "metatags": { "dcPublisher": "NICE" } }
222
+ }
223
+ ```
224
+ becomes:
225
+ ```json
226
+ {
227
+ "title": "Hypertension in adults: diagnosis and management | Guidance - NICE",
228
+ "url": "https://www.nice.org.uk/guidance/ng136",
229
+ "snippet": "28 Aug 2019 ... This guideline covers identifying and treating primary hypertension...",
230
+ "year": "2019",
231
+ "source": "NICE"
232
+ }
233
+ ```
234
+ Note `url` is the real destination, not `clicktrackUrl`.
235
+
236
+ ## `keyReferences`: selection is a percentage of returned hits, not a fixed count
237
+
238
+ See the main SKILL.md's "keyReferences" section for the full field shape. The selection logic
239
+ itself (`src/parsers/selectKeyReferences.ts`) is intentionally simple and site-agnostic: take the
240
+ top `min(5, ceil(hits.length × 20%))` entries of `parsed.hits`, in the order the site itself already
241
+ returned them (each site's own relevance ranking) — no new cross-site scoring heuristic is invented,
242
+ since none of these sites expose a field this project has evidence to justify weighting by (e.g.
243
+ recency or content-type reputability). The 20% is computed against the number of hits actually
244
+ returned in this response, not a site's own much larger reported total match count (e.g.
245
+ ClinicalKey's `numberfound`, routinely in the thousands) — a percentage of that total would either
246
+ be meaningless or make the 5-cap the only thing that ever mattered.