@ysgao/web-cli 0.0.0-stage → 0.1.2

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,738 @@
1
+ ---
2
+ name: web-cli
3
+ description: >
4
+ How to drive `web-cli`, the self-discovering search/retrieval CLI for subscription
5
+ medical-knowledge sites (UpToDate, ClinicalKey) and any other registered site (e.g. a Google
6
+ Programmable Search Engine). Covers the three-tier replay/discovery model, when a query needs
7
+ `login` first, when to fall back to `observe`, how to read a site's error whose message contains
8
+ `chrome-profile.lock`/`EPERM` (a sandbox filesystem denial blocking tier-2 discovery for a site
9
+ with no cached endpoint yet — not that site's API or subscription being broken), the per-site
10
+ `parsed` output (read `references/parsed-output.md` instead of hand-rolling your own parsing of
11
+ a site's raw JSON — every `parsed.hits[]` entry is guaranteed a title and a real, absolute,
12
+ clickable url, e.g. UpToDate's article text living only inside HTML that `parsed.text` already
13
+ strips, or ClinicalKey's search hits carrying no URL field at all in the raw response, which
14
+ `parsed.hits[].url` fixes by constructing ClinicalKey's real article URL from its id), why
15
+ `search` deliberately does NOT fetch full text for every hit (cheap title/url/year/source come
16
+ free for the whole hit list; only a small percentage-based `keyReferences` selection costs an
17
+ extra fetch — see the "keyReferences" section), that `web-cli` itself never reads or answers a
18
+ question — it only retrieves, so after a `search` you must read the retrieved `keyReferences`
19
+ full text yourself and write the actual prose answer, citing sources, rather than relaying the
20
+ JSON/its `summary` field and calling that done (see "After `search` returns" section), that
21
+ `search`/`finalize` auto-detect JSON vs. a HUMAN-READABLE report from whether stdout is a real
22
+ terminal (an agent's own command-execution mechanism gets JSON automatically, no flag needed;
23
+ pass `--json` explicitly for certainty, or if generating a standalone JSON file use `render-markdown`/`--out` — see "`--json`/`--pretty`" section), and —
24
+ critically — when NOT to trust a subscription clinical site's search results at all: UpToDate and
25
+ ClinicalKey are practice-medicine resources, not anatomical/terminological references, and
26
+ silently autocorrect or drop unfamiliar terms. Use this whenever you're about to run `web-cli
27
+ search`/`get`/`login`/`observe`, whenever a site's result contains an unexpected `error`/`code`
28
+ field, or whenever a query is about a specific anatomical structure, layer, or historical/Latin
29
+ anatomical synonym — in which case read `references/anatomy-lookup.md` and check FMA /
30
+ Terminologia Anatomica directly rather than relying on a `web-cli search` of a clinical site
31
+ alone.
32
+ ---
33
+
34
+ # web-cli
35
+
36
+ `web-cli` searches and retrieves content from subscription medical-knowledge sites by discovering
37
+ their REST APIs at runtime, reusing your own logged-in session in a dedicated Chrome profile. Every
38
+ command's failure path is the same JSON envelope on stderr (`{"error", "code"}`) — there is no
39
+ interactive UI to drive. On success, every command except `search`/`finalize` always prints one
40
+ JSON document to stdout, no exceptions.
41
+
42
+ **`search` and `finalize` are different: they can ALSO print a human-readable report instead of
43
+ JSON.** Which one prints by default is auto-detected per invocation from `process.stdout.isTTY` —
44
+ a real, interactive terminal (a human typing the command) gets the readable report; anything else
45
+ (an AI agent's own command-execution mechanism, a shell redirect, a pipe) gets the JSON envelope
46
+ **automatically, with no flag needed**. Confirmed empirically from inside a harness's own exec
47
+ tool: `process.stdout.isTTY` reports `undefined` there (not a terminal) — exactly the signal this
48
+ auto-detection reads, so the common case of an agent driving this CLI already gets JSON by
49
+ default. `agentTask`, `keyReferences[].article.text`, `summary`, `usedCount`,
50
+ `unmatchedAnswerUrls`, and `unverifiedQuotes` — everything the rest of this document tells you to
51
+ read — only exist in that JSON, never in the human-readable text. **Still pass `--json` explicitly
52
+ when you want certainty regardless of environment** (some execution mechanisms might allocate a
53
+ real pty to a subprocess, in which case auto-detection would otherwise pick the readable report) —
54
+ it's a harmless, portable way to guarantee JSON rather than relying on the auto-detected default.
55
+ `--pretty` is the inverse override, for forcing the readable report even when stdout isn't a
56
+ terminal. See "`--json`/`--pretty`" below for the full rationale.
57
+
58
+ `search` additionally writes plain-text progress lines to stderr as it runs (which sites are being
59
+ searched, each one finishing/failing, a final totals line) — see "Reading a `search` result" below;
60
+ these are for a human watching the terminal and are never part of the JSON, so don't parse them
61
+ either.
62
+
63
+ **If you (or whatever harness is running this command for you) capture stdout+stderr merged
64
+ together, or your captured output ever gets wrapped with extra framing** (a command echo, a
65
+ per-line log prefix, a trailing "exit code"/"EXIT:0" marker appended after the process exits) —
66
+ **pass `--out [path]` instead of relying on parsing captured terminal output at all.** It writes
67
+ the exact same object `--json` would print directly to a standalone `.json` file via this
68
+ process's own filesystem call, immune to anything added around a captured stdout transcript by
69
+ whatever ran this command; the file's path comes back as `outPath`, and the file's entire content
70
+ is plain, standard `JSON.parse`-able JSON with nothing else in it — no need to scan the file's head
71
+ for where the real JSON actually starts. See "Writing JSON output to disk (`--out`)" below.
72
+
73
+ Run with no arguments (or `--help`) to see the full current command list; that is the source of
74
+ truth over anything below.
75
+
76
+ ## Commands
77
+
78
+ ```
79
+ web-cli auth status [--site <site>]
80
+ web-cli login <site> [--durationSeconds 90]
81
+ web-cli search "<query>" [--site <site>]... [--allow-visible-login] [--disable-login-recovery] [--loginTimeoutSeconds 240] [--markdown [path]] [--out [path]] [--json] [--pretty]
82
+ web-cli get <site> <idOrUrl> [--allow-visible-login] [--disable-login-recovery] [--loginTimeoutSeconds 240]
83
+ web-cli websearch "<query>" [--engine google|bing|gemini] [--model <model>] [--maxResults <n>] [--fallbackWaitSeconds <n>] # general open-web search, google->bing->gemini chain
84
+ web-cli weather <location> # current conditions + 3-day forecast via wttr.in, no API key — ALWAYS use this for weather, never websearch
85
+ web-cli observe --site <site> --intent <search|getArticle> --param "<value>" [--durationSeconds 120]
86
+ web-cli learned [--site <site>]
87
+ web-cli finalize [--markdown [path]] [--json] [--pretty] # reads {query, finalAnswer, summary?, keyReferences, answers} as JSON on stdin
88
+ web-cli render-markdown [--from <path>] [--markdown [path]] [--json] # renders a Markdown report from an ALREADY-RETRIEVED search result -- zero network calls, see its own section below
89
+ ```
90
+
91
+ ### `--json`/`--pretty`: auto-detected by default, these are the explicit overrides
92
+
93
+ `search`/`finalize` auto-detect JSON vs. the human-readable report from `process.stdout.isTTY` — a
94
+ real terminal gets the readable report, anything else (including how you, as an agent, invoke this
95
+ command) gets JSON automatically. **You still don't need to think hard about this: passing
96
+ `--json` explicitly is always a safe, portable choice** that guarantees JSON regardless of exactly
97
+ how your own execution mechanism attaches stdout — cheap insurance against the one edge case
98
+ auto-detection can't resolve on its own (a mechanism that happens to allocate a real pty to its
99
+ subprocess). `--pretty` is the inverse override (forces the readable report even off a terminal);
100
+ passing both together is a usage error (`INVALID_ARGUMENT`).
101
+
102
+ ```bash
103
+ web-cli search "myocardial infarction" # as an agent: already JSON, automatically
104
+ web-cli search "myocardial infarction" --json # same result, guaranteed regardless of environment
105
+ web-cli search "myocardial infarction" --pretty # force the human report even though stdout isn't a terminal
106
+ ```
107
+
108
+ Every JSON field this document describes below — `agentTask`, `sites`, `keyReferences`, `summary`,
109
+ and everything `finalize` returns — exists ONLY in the JSON output, never the human-readable
110
+ report. The readable report is a real, complete artifact in its own right (title/url/snippet/status
111
+ for `search`, the full final-answer-with-quotes report for `finalize`) — it is not "broken" or
112
+ "less informative" if that's what you end up with, it simply has nothing in it your own
113
+ code/parsing can reliably extract, which is why explicit `--json` remains the unambiguous choice
114
+ whenever you're not certain which mode you'd otherwise get.
115
+
116
+ `search` ALWAYS covers `uptodate`, `clinicalkey`, and `googlemedsearch` — the login-gated/
117
+ medically-scoped subscription sites this CLI is actually built around; there is no other,
118
+ general-purpose site set it falls back to. `web-cli` has no judgment of its own to decide whether a
119
+ query is actually about medicine/anatomy/substances/organisms, so **that call is yours: only run
120
+ `search` for queries that actually are** — the three sites are pure overhead (possibly including an
121
+ interactive sign-in) on anything else. `--site` (repeatable) adds a site *beyond* that base set.
122
+ `get` is unaffected and still takes exactly one `<site>`, since fetching a specific article only
123
+ ever makes sense against the one site that has it.
124
+
125
+ **For a genuinely open-ended/general query — anything outside medicine/anatomy/substances/
126
+ organisms — use `web-cli websearch "<query>"` instead of forcing it through `search`.** This is
127
+ not just a recommendation: `search` has no general-purpose site to fall back to at all anymore, so
128
+ running a non-medical query through it will just waste time against three sites with nothing
129
+ relevant to say.
130
+
131
+ **Exception: for ANY weather query, use `web-cli weather <location>` instead of `websearch`
132
+ (regardless of which `--engine` you'd otherwise pick) — never route a weather question through
133
+ general/open-web search at all.** This is a dedicated, no-API-key/no-billing command backed by
134
+ wttr.in that actually geocodes `location` (confirmed live, correctly resolving "Manchester" to
135
+ Manchester, Greater Manchester, UK — see `src/weather/wttr.ts`) and returns real current
136
+ conditions plus a forecast (`{query, location, region, country, current: {...}, forecast: [{date,
137
+ minTempC, maxTempC, hourly: [...]}, ...]}`, 3 days: today + 2 more) — where BOTH `websearch`
138
+ engines demonstrably fail this specific kind of query (see each one's own confirmed-live example
139
+ below). `location` is a place name only, never a relative date phrase like "this weekend"/"this
140
+ Friday" — wttr.in has no way to interpret those; compute the actual date yourself and compare it
141
+ against each returned `forecast[].date`, and say so plainly if the date asked about falls outside
142
+ the 3 days returned (there is no way to get further ahead without a paid API this command
143
+ deliberately doesn't integrate — see that module's own doc comment).
144
+
145
+ For every other kind of genuinely open-ended/general query, `websearch` is not restricted to any
146
+ fixed site/domain list. Three engines are CHAINED together via `--engine` (default `google`), so
147
+ no single one is a hard dependency for this to return something usable:
148
+
149
+ ```
150
+ --engine google (default) --fails--> bing --fails--> gemini
151
+ --engine bing --fails--> gemini
152
+ --engine gemini (no further fallback)
153
+ ```
154
+
155
+ The result's own `"engine"` field always reports which engine actually answered (NOT necessarily
156
+ the one requested/defaulted into); a `"fallback"` array is present whenever at least one earlier
157
+ engine in the chain was tried and failed first — one entry per failed engine, in order, each with
158
+ its own `{from, reason}` — so you can always tell what happened, not just what you got back.
159
+
160
+ - **`google` (the default)**: drives web-cli's own automation Chrome (the same launch/kill
161
+ machinery `search`/`get`/`login`/`observe` use, via a completely separate CDP connection of its
162
+ own — see `src/search/googleSearch.ts`'s own doc comment; this never touches
163
+ `discovery/cdpSession.ts` or otherwise affects the subscription-site discovery path) against
164
+ `www.google.com/search` directly — no API key or billing, and (confirmed live, real, checked-in
165
+ fixture — see that module's own doc comment) genuinely relevant results, not geo-biased noise.
166
+ Confirmed live: a plain headless attempt alone is NOT reliable — Google answers either with a
167
+ hard IP-reputation CAPTCHA (`/sorry/index`, "unusual traffic from your computer network") or a
168
+ softer, very common cookie-consent interstitial ("Before you continue to Google…"), and a full
169
+ JS-executing headless browser does not bypass either on its own. So: if a headless attempt
170
+ returns nothing, this **opens a REAL, VISIBLE Chrome window** (same pattern as `web-cli login`)
171
+ for `--fallbackWaitSeconds` (default 90) so a human can actually resolve it by hand, explicitly
172
+ captures whatever cookies that produced, and retries headless with them already injected —
173
+ meaning it can take anywhere from a few seconds (headless succeeds outright, the common case
174
+ once this has been resolved once against this profile — cookies persist) up to
175
+ `--fallbackWaitSeconds` plus a few seconds. Only if THAT retry is still blocked does this move on
176
+ to `bing` next, rather than throwing.
177
+ - **`bing`**: no API key or billing at all — scrapes Bing's own HTML search results page directly
178
+ and returns a plain `hits: [{title, url, snippet}, ...]` list (same shape as a `search` site's
179
+ own `parsed.hits`) — unsynthesized, since nothing here has read the linked pages. Confirmed live
180
+ to actually work (Google's own results page and DuckDuckGo's HTML endpoint both refused a plain
181
+ scripted request when this was tested — see `src/search/bingSearch.ts`'s own doc comment for the
182
+ full comparison), but it is HTML-scraping a search engine's results page, not a documented/
183
+ stable API: markup drift or bot-detection can break or block it at any time with no notice, and
184
+ automated scraping may run against that engine's own Terms of Service. It's also geo-biased
185
+ toward wherever the request actually originates from, confirmed live: a "weather in Manchester
186
+ this weekend" query returned Herefordshire results, not Manchester — exactly the query type the
187
+ dedicated `web-cli weather <location>` command above exists for instead. If bing ALSO fails
188
+ (whether reached via `google`'s own fallback or requested directly), this moves on to `gemini`
189
+ next.
190
+ - **`gemini`**: hands the query to Gemini's own Google Search grounding tool and returns one
191
+ synthesized answer directly (`answer` instead of `hits` in the result — no separate
192
+ full-text-reading step to do here, the answer text itself is the whole result). Requires
193
+ `GEMINI_API_KEY` or `GOOGLE_API_KEY` to be configured (see the package's own README's "API keys"
194
+ section) and is subject to that key's own Gemini API quota — exactly why it sits at the END of
195
+ the chain rather than being tried first, and has no further engine to fall back to itself: with
196
+ no key configured, reaching `gemini` at the end of the chain still ends the whole call in a
197
+ thrown `CliError`, same as requesting it directly would.
198
+
199
+ If the whole chain doesn't work for you (no Gemini key configured AND both `google`/`bing` are
200
+ blocked/broken), or you already have your own general web-search tool available (e.g.
201
+ `WebSearch`/`web_search`), use whichever is actually available to you.
202
+
203
+ ## After `search` returns: your job is to answer the question, not relay the JSON
204
+
205
+ **`web-cli` has no LLM in it at all — it only retrieves.** Its `summary` field is a coverage/volume
206
+ digest (how many sites answered, how many hits, how many key references got full text — see
207
+ "`summary`" below), not an answer to whatever the person actually asked. Handing back the raw JSON,
208
+ or a restatement of `summary`, is not the deliverable when a person asked a substantive question —
209
+ reading the retrieved content and answering it is a step *you* do, every time, not something the
210
+ CLI does for you and not something to skip because the JSON "looks complete."
211
+
212
+ ### `agentTask`: the same instruction, reprinted in every result so it can't be missed
213
+
214
+ Every `search` result also carries a top-level `agentTask` field — `{"question": "<the exact
215
+ query you passed>", "instructions": "<what to do with it>"}`. This exists because a rule read once
216
+ from a skill doc at session start is easy to forget by the time a tool result actually lands
217
+ several turns later; `agentTask` puts the same expectation directly in the data itself, every
218
+ single time, next to the material to satisfy it from:
219
+
220
+ ```json
221
+ {
222
+ "agentTask": {
223
+ "question": "is finger the same as digit of the hand",
224
+ "instructions": "Answer the question above using the material already retrieved into \"keyReferences\" — do not just relay this JSON, \"summary\", or a list of titles as if that were the answer. For each \"keyReferences\" entry that has \"article.text\": read it and decide whether it actually helps answer the question. If it does, cite it (its \"url\") in your answer. If it does not, treat it as irrelevant to this question — leave it out of your answer entirely, rather than citing it just because it was fetched. ..."
225
+ }
226
+ }
227
+ ```
228
+
229
+ **"Treat it as irrelevant" means leave it out of *your answer*** — `web-cli` never deletes or
230
+ hides a `keyReferences` entry based on relevance (it has no way to judge that, and doing so would
231
+ throw away data already paid for with a real network fetch, possibly useful for a different
232
+ follow-up question later). The full, unfiltered list is always still there in `keyReferences`;
233
+ `agentTask` only ever tells you what to do with it, never mutates it.
234
+
235
+ Concretely, after a `search` whose result you intend to answer a question from:
236
+
237
+ 1. **Read `keyReferences` first** (see below) — these are the hits already judged worth a
238
+ full-text fetch. Read each entry's `article.text` where present; where it isn't
239
+ (`fetchError`/`fullTextUnparsed` — see `summary.keyReferences`), fall back to that entry's own
240
+ `snippet` rather than skipping it.
241
+ 2. **Skim titles/snippets across every site's `parsed.hits`** for anything clearly relevant that
242
+ the 20%-capped `keyReferences` selection didn't happen to include — that selection is a
243
+ defensible default ranking, not proof nothing else in the hit list matters.
244
+ 3. **Write an actual prose answer to the person's question**, citing the specific `url` from the
245
+ `keyReferences`/hit entry that backs each claim — see "keyReferences" below for the exact
246
+ citation convention. Counts, titles, or a coverage summary are not a substitute for this.
247
+ 4. **If the query touches anatomical terminology**, cross-check against FMA/Terminologia Anatomica
248
+ (`references/anatomy-lookup.md`) before treating a clinical site's search as authoritative for
249
+ it — see "don't trust a single site's silence" below.
250
+
251
+ Doing this by hand every time (rather than automating it into `search` itself) is deliberate:
252
+ automating it would mean wiring an LLM call into the CLI's own process — a real architectural
253
+ change (a new dependency, an API key to manage, a per-call cost) this project doesn't make; see
254
+ `CLAUDE.md`. This four-step read is the actual last step of using this tool, not an optional
255
+ afterthought — but `web-cli finalize` (next) is a genuinely optional fifth step for turning that
256
+ reading into its own polished artifact.
257
+
258
+ ### `web-cli finalize`: turn your reading into a curated report (optional fifth step)
259
+
260
+ Once you've done the four-step read above, you can hand your own conclusions back to `web-cli` and
261
+ get a report organized around the ANSWER — not around "everything that happened to get fetched."
262
+ Pipe JSON on **stdin** (the only command in this package that reads stdin rather than flags):
263
+
264
+ ```bash
265
+ echo '{
266
+ "query": "is finger the same as digit of the hand",
267
+ "finalAnswer": "Yes — FMA lists Finger as the preferred name with Digit of hand as a direct synonym; same structure, different register.",
268
+ "summary": { /* optional: the exact "summary" field from the search result, for a coverage recap */ },
269
+ "keyReferences": [ /* the exact keyReferences array from the search result */ ],
270
+ "answers": [
271
+ {
272
+ "url": "https://www.uptodate.com/contents/...",
273
+ "quote": "a verbatim excerpt from THAT reference's own article.text (or snippet) — the evidence",
274
+ "summary": "Your own take on what this source says in answer to the question, in your words — not a re-quote."
275
+ }
276
+ ]
277
+ }' | web-cli finalize --json --markdown
278
+ ```
279
+
280
+ (`--json` here for the same reason as `search`: `usedCount`/`unmatchedAnswerUrls`/`unverifiedQuotes`
281
+ only exist in the JSON envelope, not in the human-readable report text `finalize` prints without it.)
282
+
283
+ - **`finalAnswer` is required** — your own overall synthesized answer to `query`, drawn from every
284
+ entry in `answers`. It's rendered first, ahead of any per-source detail, because that's what a
285
+ reader actually came here for.
286
+ - If you pass through the original search result's own `summary` field, a "Search coverage"
287
+ section (sites/hits/key-reference counts) renders right after `finalAnswer`, for context.
288
+ - Every `keyReferences` entry you name in `answers` (matched by its exact `url`) gets its own
289
+ section under "Sources", with **your** `quote` and `summary` — never the raw snippet, never the
290
+ full article text. You already read the full text; `quote` is the evidence, `summary` is what
291
+ you concluded from it.
292
+ - **`quote` is required and mechanically checked**: it must be a verbatim excerpt of that
293
+ reference's own `article.text` (or `snippet` if there's no full text) — `web-cli` checks this
294
+ itself (a plain substring test, whitespace-normalized; no LLM needed for it) and flags a quote
295
+ that doesn't actually appear in the retrieved text, both inline in the report and in the
296
+ result's `unverifiedQuotes` array. This exists specifically to catch a summary that isn't
297
+ actually grounded in what was retrieved — don't paraphrase into `quote`, and don't reuse the
298
+ same quote for an unrelated claim just to pass the check.
299
+ - Every `keyReferences` entry you do NOT name in `answers` is treated as fetched-but-not-relevant
300
+ to this question: left out of "Sources", but never deleted — it still appears, unused, in a
301
+ closing "All retrieved sources" list, so nothing you fetched vanishes without a trace, and a
302
+ later follow-up question can still find it.
303
+ - Without `--json`, `finalize` prints the rendered report as plain text (mentioning where a
304
+ `--markdown` file was saved, or that you can pass `--markdown` to get one, right in that text
305
+ since there's no JSON for that to live in). **With `--json`**, you get the same report in a
306
+ `report` field, plus `usedCount`/`notUsedCount`, and — worth checking — `unmatchedAnswerUrls`
307
+ (a non-empty one means an `answers[].url` didn't match anything in `keyReferences` at all,
308
+ almost always a typo on your side) and `unverifiedQuotes` (see the `quote` bullet above).
309
+ `--markdown [path]` independently writes the report to disk either way (same convention as
310
+ `search --markdown` — off by default, a write failure reported as `markdownError`/on stderr
311
+ rather than losing the report).
312
+ - This step is entirely optional. Skipping it just means your answer to the person lives only in
313
+ your own chat response, the way it always has — `finalize` exists for when a durable, curated
314
+ artifact (a file someone can reopen later) is actually wanted.
315
+
316
+ Known sites are registered in the CLI itself (currently `uptodate`, `clinicalkey`, and
317
+ `googlemedsearch` — a Google Programmable Search Engine used as a broad medical-web fallback);
318
+ run `web-cli auth status` with no `--site` to see every registered site and whether a session
319
+ exists for it.
320
+
321
+ ### Sessions: `search` recovers expired logins by itself, silently, by default — no flag needed
322
+
323
+ **Read this before running `search` unattended** (which, as an AI agent, is almost always how you
324
+ run it). **By default, if a site's session has expired, `search`/`get` try a quick, SILENT,
325
+ credential-based refresh — a real, visible browser window is NEVER opened unless you explicitly
326
+ ask for one.** You do not need to run `web-cli login` first, and you should not treat
327
+ `SESSION_EXPIRED` as something to pre-empt.
328
+
329
+ - **The default behavior (no flag at all) is exactly what you want as an unattended agent.** If a
330
+ credential was saved for the site beforehand (`web-cli login <site> --save-credentials`), a
331
+ quick, silent, headless refresh using that credential runs automatically and needs no human at
332
+ all, typically recovering the session in a few seconds with no window shown. If nothing is
333
+ saved, this is a cheap no-op (no browser launched at all) and the command reports
334
+ `SESSION_EXPIRED` right away — no wasted wait either way. Concretely: a run that ends up with
335
+ `SESSION_EXPIRED` means either nobody has ever run `web-cli login <site> --save-credentials` for
336
+ that site, or the saved credential itself no longer works (password changed, account locked, a
337
+ CAPTCHA/2FA page the auto-fill heuristic can't get past) — not "you forgot a flag."
338
+ - **`--allow-visible-login` opts IN to the older, human-friendly convenience**: if the silent
339
+ refresh above doesn't recover the session, open a real, visible window and wait for a human to
340
+ sign in (up to `--loginTimeoutSeconds`, default **240s**). Pass this only when you know a human
341
+ is actually watching and able to act on a window that appears — otherwise this just means the
342
+ command can sit waiting for a sign-in that will never happen. As an unattended agent, you should
343
+ essentially never need this flag.
344
+ - **`--disable-login-recovery` is a DIFFERENT, stricter, rarely-needed flag.** It disables session
345
+ recovery entirely: not even the default silent, credential-based refresh is attempted, and zero
346
+ browser processes (not even headless) are ever launched. Use it only when you know the
347
+ environment genuinely cannot tolerate ANY browser automation attempt at all (a sandbox that
348
+ denies launching even a headless Chrome process — see the `chrome-profile.lock` EPERM case
349
+ below). Reaching for this by habit instead of just letting the default run loses the one
350
+ recovery path that needs no human at all, which is almost always the wrong tradeoff for an
351
+ agent that already has a saved credential to work with. If both flags are passed together,
352
+ `--disable-login-recovery` wins (it is the strict superset — nothing is attempted either way).
353
+ - **If you want every future unattended run of this CLI to recover a site's expired session with
354
+ no human involved at all**, tell a human to run `web-cli login <site> --save-credentials` once,
355
+ interactively, to save that site's username/password — after that, the default behavior recovers
356
+ that site silently with zero flags needed on every later call.
357
+ - **If a human is available and you want the old interactive convenience**, pass
358
+ `--allow-visible-login`, or tell them to run `web-cli login <site>` once beforehand. A visible
359
+ window needs an actual human sign-in; it will not complete on its own.
360
+
361
+ `web-cli auth status` reports whether cookies exist, but note that **cookies existing is not the
362
+ same as being signed in** — ClinicalKey in particular hands out an anonymous session that satisfies
363
+ search while still refusing full text. So a nonempty `auth status` does not guarantee full-text
364
+ access; the authoritative check is whether the call you actually need succeeds. `auth status` also
365
+ has no way to tell you whether a credential is saved for silent recovery — there is currently no
366
+ read command for that; the only way to find out is to try a search (with no flags — this is simply
367
+ the default) and see whether `SESSION_EXPIRED` appears (in which case either nothing is saved, or
368
+ the saved one no longer works).
369
+
370
+ A site missing a session never fails the whole `search` call — see "reading a `search` result"
371
+ below.
372
+
373
+ ### Reading a `search` result: per-site outcomes, not one flat list
374
+
375
+ Everything below assumes you passed `--json` (see above) — without it, this is prose text, not the
376
+ object this section describes. `search --json` queries every site concurrently and returns
377
+ `{"query": ..., "sites": {"<site>": {...}, ...}}` — one entry per site searched (the 3 defaults,
378
+ plus anything passed via `--site`), each independently either:
379
+
380
+ - `{"discovered": true|false, "results": ..., "parsed": ...}` — that site's normal result.
381
+ `discovered` tells you which of the three-tier model's stages produced `results` (see below);
382
+ `parsed` is a normalized extraction of `results` — see "Parsed output" below, and prefer it over
383
+ hand-parsing `results` yourself. This per-site entry is deliberately cheap: it never triggers an
384
+ extra network call beyond the one search itself — see `keyReferences` (top-level, not nested per
385
+ site) for the small subset of hits that get a full-text fetch.
386
+ - `{"error": "...", "code": "..."}` — that one site failed (commonly `SESSION_EXPIRED` — see
387
+ above — or `DISCOVERY_FAILED`); the *other* sites' entries are still real, usable results.
388
+
389
+ The command itself only fails (exit non-zero, `SEARCH_FAILED`) when every site failed — a mix of
390
+ some-succeeded/some-failed is a normal exit-0 result, so check each site's entry rather than
391
+ assuming a successful exit means every site returned data.
392
+
393
+ A `keyReferences` entry with a `fetchError` instead of an `article` is worth reading precisely: the
394
+ hit itself is real and citable (title/url/snippet are present), only its full text is missing.
395
+ `SESSION_EXPIRED` there means signed in but not entitled to that specific item; `DISCOVERY_FAILED`
396
+ means that site's article endpoint needs re-learning via `observe`; **`ARTICLE_MISMATCH`** means the
397
+ fetch technically succeeded but came back with a DIFFERENT article than the one this entry is
398
+ about — confirmed live (not hypothetical): a stale/mismatched `getArticle` endpoint template can
399
+ silently serve whatever topic it was last learned against, with no transport-level error at all, so
400
+ a mismatch is caught by cross-checking the response's own claimed id against the id actually
401
+ requested and deliberately never kept as `article` (an entry with the wrong content is worse than
402
+ no content — it can't be mistaken for a real answer). If you see this, the fix is the same as
403
+ `DISCOVERY_FAILED`: `web-cli observe --site <site> --intent getArticle --param "<a real article for
404
+ that site>"` to relearn a correct template.
405
+
406
+ ### `summary`: coverage and volume at a glance, without walking `sites`/`keyReferences` yourself
407
+
408
+ Every `search` result also carries a top-level `summary` field — a small, pre-computed digest of
409
+ exactly the two questions `sites`/`keyReferences` otherwise make you re-derive by hand: **which
410
+ sites actually came back**, and **how much did they return**. Example:
411
+
412
+ ```json
413
+ {
414
+ "sitesRequested": ["uptodate", "clinicalkey", "googlemedsearch"],
415
+ "sitesSucceeded": ["uptodate", "clinicalkey", "googlemedsearch"],
416
+ "sitesFailed": [],
417
+ "hitsBySite": { "uptodate": 12, "clinicalkey": 40, "googlemedsearch": 8 },
418
+ "totalHits": 60,
419
+ "keyReferences": { "selected": 8, "fullTextFetched": 7, "fullTextFailed": 1, "fullTextUnparsed": 0 }
420
+ }
421
+ ```
422
+
423
+ Read this first when you just need "did it work and how much did I get" — `sitesFailed` being
424
+ non-empty is the coverage check (compare its length against `sitesRequested`'s to see if it was
425
+ every site or just some), `totalHits`/`hitsBySite` is the volume check, and
426
+ `keyReferences.fullTextFetched` vs `.selected` tells you how many of the selected references
427
+ actually came back with readable text without checking each entry's `.article`/`.fetchError`
428
+ yourself. It never replaces `sites`/`keyReferences` — those still carry the actual data — `summary`
429
+ is purely a derived convenience on top of them.
430
+
431
+ A site missing from `hitsBySite` entirely means it's in `sitesFailed` (a failed site never produced
432
+ hits to count). A site present in `hitsBySite` with a value of `null` (rather than `0`) means it
433
+ succeeded but its raw response didn't match that site's parser — a parsing gap, not evidence of an
434
+ empty result set; don't read `null` as zero. `keyReferences.fullTextUnparsed` is the same distinction
435
+ applied to a `keyReferences` entry: its `getArticle` fetch succeeded (no `fetchError`) but the
436
+ response wasn't recognized (no `article` either) — rare, but real, and distinct from a fetch that
437
+ outright failed.
438
+
439
+ ### Progress on stderr while `search` is still running
440
+
441
+ Because `search` can legitimately take minutes (an interactive login, a tier-2 discovery pass) and
442
+ prints its one JSON document only at the very end, `search` also writes plain-text lines to stderr
443
+ as it goes — useful for a human watching, never meant to be parsed (parse the final JSON instead).
444
+ Example:
445
+
446
+ ```
447
+ web-cli: searching 3 sites — uptodate, clinicalkey, googlemedsearch
448
+ web-cli: clinicalkey finished — 40 hits
449
+ web-cli: googlemedsearch finished — 8 hits
450
+ web-cli: uptodate finished — 12 hits
451
+ web-cli: search complete — 3/3 sites succeeded, 60 hits total, 8 key references selected (7 with full text)
452
+ ```
453
+
454
+ Sites announce as *they* finish, not in request order (they run concurrently), and a failed site
455
+ gets its own distinct line (`web-cli: <site> failed — <code>: <message>`) instead of a "finished"
456
+ one. The final "search complete" line mirrors `summary` above and is written even when every site
457
+ fails, right before the command throws `SEARCH_FAILED` — so the reason is visible on the terminal,
458
+ not just in the thrown error.
459
+
460
+ ### Writing a report to disk (`--markdown`)
461
+
462
+ `--markdown` *additionally* writes a human-readable Markdown report; stdout stays exactly one JSON
463
+ document and gains a `markdownPath` field pointing at the file. Use it when a person will read the
464
+ output, not for your own parsing — parse the JSON. `--markdown` alone writes into the working
465
+ directory; `--markdown <file.md>` or `--markdown <dir>` picks a location. It is off by default, and
466
+ a failure to write it never fails the search: the results come back with a `markdownError` field
467
+ instead, so check that rather than assuming the file exists.
468
+
469
+ **The report is a citation index, not a full-text dump** — each key reference gets its
470
+ title/url/snippet and a status line (retrieved/unavailable/not retrieved), never the article text
471
+ itself (a single real reference's full text has run to several thousand report lines by itself).
472
+ Read the actual full text from the JSON's `keyReferences[].article.text` — that's what step 1 of
473
+ "After `search` returns" above is for, and it's true whether or not `--markdown` was passed at
474
+ all. Don't go looking for full text in the `.md` file; it was deliberately left out of it.
475
+
476
+ ### Writing JSON output to disk (`--out`) — prefer this over parsing captured stdout
477
+
478
+ `--out` writes the exact object `--json` prints — the complete result, including every
479
+ `keyReferences[].article.text` — directly to a standalone `.json` file on disk, via this process's
480
+ own filesystem write. Its path comes back as `outPath` (and a write failure as `outError`, never
481
+ failing the search itself — same convention as `markdownPath`/`markdownError` above). Freely
482
+ combine it with `--markdown`/`--json`; none of the three implies or excludes the others.
483
+
484
+ ```bash
485
+ web-cli search "myocardial infarction" --json --out # stdout: full JSON envelope; disk: a pure-JSON copy at "outPath"
486
+ ```
487
+
488
+ **Use this instead of parsing whatever you captured from this command's stdout/stderr whenever
489
+ that capture might not be pristine** — concretely: you merged stdout and stderr (`search`'s own
490
+ progress notices land on stderr, ahead of the real JSON, if so — see above), or the tool/harness
491
+ you're running this command through adds its own framing around captured output (a command echo,
492
+ a per-line log prefix, a trailing "exit code"/"EXIT:0" marker once the process exits). None of that
493
+ is unparseable in principle, but it means you'd otherwise have to inspect the captured text's own
494
+ head/tail to work out where the real JSON actually starts and ends — exactly the bespoke,
495
+ per-situation scripting `--out` exists to make unnecessary. A file written this way is produced by
496
+ this process's own `fs` call, so nothing outside the process ever gets a chance to wrap it in
497
+ anything: read it with a plain `JSON.parse`/`jq`, no pre-processing, regardless of how the same
498
+ command's own terminal output turned out to look.
499
+
500
+ ### A report from a result you already have — `web-cli render-markdown` (zero network calls)
501
+
502
+ `search --markdown` renders its report inline, as part of a live search. `render-markdown` is the
503
+ standalone counterpart: hand it a `search` result you already retrieved — the exact JSON
504
+ `search --json` printed, or a file written via `search --out` — and it renders the identical report
505
+ with **no network call and no re-querying any site**:
506
+
507
+ ```bash
508
+ web-cli search "aspirin" --json --out result.json # retrieve once, save the JSON
509
+ web-cli render-markdown --from result.json # render a report from it, any time later, for free
510
+ web-cli render-markdown < result.json # or pipe it in on stdin (the default input)
511
+ ```
512
+
513
+ Reach for this when you (or a human) want a readable report from a JSON blob that's already on
514
+ disk, without re-running a search that could take minutes and another interactive sign-in. Its
515
+ input validation only checks the three fields it actually reads (`query`, `sites`,
516
+ `keyReferences`), so the exact object `search --json` printed always satisfies it — extra fields
517
+ like `summary`/`agentTask`/`outPath` are simply ignored if present.
518
+
519
+ **Unlike `search`/`finalize`, this command's own default output is NOT isatty-gated** — it always
520
+ prints the rendered Markdown text to stdout, period, since that text is the one thing this command
521
+ exists to produce. `--json` opts into `{query, markdown, markdownPath?, markdownError?}` instead
522
+ (useful for confirming a `--markdown` write without reading stderr, or embedding the text in a
523
+ larger pipeline); `--markdown [path]` additionally writes a copy to disk, same off-by-default,
524
+ never-fails conventions as `search --markdown`.
525
+
526
+ ### `keyReferences`: only a small, cheaply-selected slice gets a full-text fetch
527
+
528
+ `search`'s top-level result also includes `keyReferences` — a single flattened list (not nested per
529
+ site) across every site searched, of the few hits judged worth a full-text fetch. **This is
530
+ deliberately not "fetch full text for every hit"**: every hit already gets a title/url/snippet (and,
531
+ where the site's raw data has it, `year`/`source`) for free from the one search call via
532
+ `parsed.hits` above, at no extra network cost — only `keyReferences` costs one extra `getArticle`
533
+ call per entry, so it is kept small on purpose (see "How selection works" below) rather than
534
+ expanding everything indiscriminately.
535
+
536
+ Each entry:
537
+
538
+ ```json
539
+ {
540
+ "site": "uptodate",
541
+ "title": "...",
542
+ "url": "https://...",
543
+ "id": "...",
544
+ "year": "2025",
545
+ "source": "UpToDate",
546
+ "snippet": "...",
547
+ "article": { "title": "...", "text": "...", "html": "...", "outline": [...], "meta": {...} }
548
+ }
549
+ ```
550
+
551
+ or, if the full-text fetch itself failed (rare — the hit was still worth selecting, but couldn't be
552
+ expanded):
553
+
554
+ ```json
555
+ { "site": "...", "title": "...", "url": "...", "fetchError": { "error": "...", "code": "..." } }
556
+ ```
557
+
558
+ A `fetchError` never removes the entry or the site's own `results`/`parsed` — the title/url/snippet
559
+ selected are still valid even when the deeper full-text fetch didn't succeed; check for the
560
+ presence of `article` rather than assuming every `keyReferences` entry has one. `site` is included
561
+ on every entry (unlike a hit inside `sites.<site>.parsed.hits`, where the site is only implicit from
562
+ its place in the response) precisely because this list is flattened across all sites searched — you
563
+ need it to know where each key reference was found.
564
+
565
+ **How selection works**: per site, the top `min(5, ceil(hits.length × 20%))` hits **in that site's
566
+ own returned order** (already its own relevance ranking) are selected — e.g. 10 UpToDate hits → 2
567
+ key references, 40 ClinicalKey hits → 5 (capped). No cross-site scoring/reweighting is applied; the
568
+ percentage is of hits actually returned in this response, not a site's own much larger reported
569
+ total match count (e.g. ClinicalKey's `numberfound`, routinely in the thousands).
570
+
571
+ **`googlemedsearch` is deliberately never expanded into `keyReferences`** — confirmed live: its own
572
+ `getArticle` endpoint is a known-stale decoy that returns unrelated tracking-pixel content for any
573
+ id, and the pages its hits link to are arbitrary third-party sites outside this CLI's
574
+ subscription-site scope anyway. Its `parsed.hits[].url` is already the correct, real destination —
575
+ fetch it yourself (e.g. via `WebFetch`) if you need that page's full text.
576
+
577
+ **Writing that answer (see "After `search` returns" above — this is step 3, not optional) has a
578
+ citation convention: cite the specific `url` from a `keyReferences` entry that backs each factual
579
+ statement** (e.g. "Aspirin is contraindicated in active peptic ulcer disease
580
+ [uptodate.com/contents/...]") rather than a general, unlinked claim — that's the whole point of
581
+ selecting a few hits for full-text expansion instead of leaving you with only a title/snippet. If a
582
+ statement instead comes from a hit that wasn't selected into `keyReferences`, don't invent a link
583
+ for it — say so as coming from the search-result snippet itself
584
+ (`sites.<site>.parsed.hits[].snippet`), not a full document.
585
+
586
+ ### Parsed output: use `parsed`, don't hand-roll your own per-site parsing
587
+
588
+ Every `search` site outcome, every `keyReferences[]` entry's `article`, and every `get` result also
589
+ carries a `parsed` field (on a key reference it's simply named `article` — see above) — a
590
+ normalized extraction produced by this package's own maintained per-site parsers
591
+ (`src/parsers/uptodate.ts`, `src/parsers/clinicalkey.ts`, `src/parsers/googlemedsearch.ts`), built
592
+ and tested against real captured output from each site. **Read `references/parsed-output.md` before
593
+ writing your own script to parse a site's raw JSON** — each site's raw shape has a real, confirmed
594
+ gotcha that a first-time ad-hoc parser is likely to get wrong.
595
+
596
+ **Every hit in `parsed.hits` is guaranteed to carry both a `title` and a real, absolute, directly
597
+ clickable `url`** (a hit missing either is dropped by that site's parser rather than emitted
598
+ half-formed) — you should never need to fall back to a root-relative path or an id-only hit to get
599
+ something citable. Each hit may also carry `year`/`source` (best-effort bibliographic metadata —
600
+ publication/last-revision year, and the site's own notion of "journal"/publisher — extracted only
601
+ from whatever the site's search response already has, never a new network call; absent when the
602
+ site's raw data has nothing to extract, e.g. UpToDate's own search hits carry no date field at all):
603
+
604
+ - **UpToDate**: the article's actual text exists *only* inside an HTML fragment (`bodyHtml`) — there
605
+ is no plain-text field in the raw response at all. `parsed.text` is that HTML already stripped to
606
+ plain text. The raw response's own `url` is root-relative; `parsed.hits[].url`/`parsed.url` are
607
+ already resolved absolute against `https://www.uptodate.com`. UpToDate has no real
608
+ publication-year/journal concept (it's a continuously-revised topic review, not a dated paper) —
609
+ `year`/`source` are unset at the search-hit level; a fully-expanded `keyReferences` entry's
610
+ `article.meta` fixes `source: "UpToDate"` and derives `year` from the topic's own last-major-update
611
+ timestamp as the closest available proxy.
612
+ - **ClinicalKey**: its raw search hits carry *no* URL/link field whatsoever — only an opaque id
613
+ (`eid`). `parsed.hits[].url` is nonetheless present and real: the parser constructs ClinicalKey's
614
+ actual hash-routed article URL itself from `eid` + `contenttype`
615
+ (`https://www.clinicalkey.com/#!/content/<contenttype>/<eid>`, confirmed against two independent
616
+ fields of ClinicalKey's own learned `getArticle` template). To fetch full content through this
617
+ CLI, either `parsed.hits[].url` or `parsed.hits[].id` works as `web-cli get clinicalkey <...>`'s
618
+ argument — but prefer `url`: it's what `search`'s own `keyReferences` expansion uses, since a
619
+ bare `id` alone can't be navigated to if a fresh discovery pass is ever needed (confirmed live:
620
+ it sent tier-2 discovery to a nonexistent page for every key reference once the cached template
621
+ went stale). `year`/`source` come from its own `pubdatetxt`/`copyrightyr` and `srctitle` fields,
622
+ already present on every search hit.
623
+ - **googlemedsearch**: a real test run confirmed the generic link-extraction approach this CLI used
624
+ to rely on was picking a Google click-tracking redirect URL instead of a hit's real destination —
625
+ now fixed by `parsed.hits[].url` using the correct field (`unescapedUrl`, never `clicktrackUrl`).
626
+ `year` is extracted from a leading "D Mon YYYY" date in the snippet when present (this site's only
627
+ date signal); `source` comes from Google's own `richSnippet.metatags.dcPublisher`.
628
+
629
+ `parsed` is purely additive and best-effort — a parsing gap or an unrecognized raw shape degrades to
630
+ `parsed: null`, never an error, and never removes or changes the existing raw `results`/`content`/
631
+ `article` field it was derived from. If `parsed` is `null`, fall back to the raw field (which may
632
+ still have ClinicalKey's URL-less shape or UpToDate's root-relative path, unresolved).
633
+
634
+ `parsed.didYouMean` (UpToDate, ClinicalKey) is also the concrete, structured version of this skill's
635
+ "don't trust a single site's silence" guidance below — a positive signal when present, but its
636
+ absence is still not proof the query was matched literally.
637
+
638
+ ### The three-tier model — what `discovered: true/false` means
639
+
640
+ Under the hood, `search` and `get` each resolve per-site (and, for `search`, per key reference
641
+ expanded) via the same 3-tier flow, per `(site, intent, param)`:
642
+
643
+ 1. **Replay** a previously learned endpoint template directly over HTTP — fast, no browser. A
644
+ result with `"discovered": false` came from here.
645
+ 2. **Discover**: launch a headless automation Chrome, drive the page (type into a search box, or
646
+ navigate to an article URL), and identify the real REST call from observed network traffic. A
647
+ result with `"discovered": true` came from here — expect it to take longer (the engine gives
648
+ in-flight requests up to ~10s to resolve) and, on success, the endpoint is cached so the *next*
649
+ search of that intent goes through tier 1 instead. Concurrent sites/key-reference fetches all
650
+ needing tier-2 discovery at once don't run truly simultaneously — they share one persistent
651
+ automation Chrome profile, so they queue for it internally — but that queuing never blocks a
652
+ site that didn't need discovery at all, so it only shows up as extra latency on the calls that
653
+ actually needed it.
654
+ 3. **Fail structured**: if discovery can't find a plausible candidate either, that site's (or key
655
+ reference's, via `fetchError` — see "keyReferences" above) entry gets a `DISCOVERY_FAILED` error
656
+ naming `web-cli observe` as the fallback.
657
+
658
+ ### When to use `observe` instead of `search`
659
+
660
+ `observe` runs the same discovery engine headful, with a human driving the actual interaction
661
+ (typing a search, clicking into a result) instead of the automated search-box heuristic. Reach for
662
+ it when one site's entry in a `search` result keeps coming back `DISCOVERY_FAILED` — that means the
663
+ automated heuristic couldn't find or successfully trigger a search box on that particular page, and
664
+ a human needs to do it once so the engine can watch and learn the real endpoint from that.
665
+
666
+ ### A site's error is `EPERM ... chrome-profile.lock`: a sandbox denial, not that site's fault
667
+
668
+ If a site's `search`/`get` entry looks like:
669
+
670
+ ```json
671
+ {"error": "EPERM: operation not permitted, open '.../chrome-profile.lock'", "code": "INTERNAL_ERROR"}
672
+ ```
673
+
674
+ this means the *execution environment itself* denied filesystem access to the automation-Chrome
675
+ lock file — tier 2 (see above) can't even launch Chrome to attempt discovery. **This is not
676
+ evidence the site's own API is broken, that the account isn't subscribed, or that this particular
677
+ site is somehow unsupported** — it fires whenever a `(site, intent)` reaches tier 2 in an
678
+ environment that blocks that lock path, and *any* site with nothing yet in
679
+ `~/.web-cli/learned/<site>.json` for that intent will hit it identically. Concretely: if one site
680
+ (say `uptodate`) already has a learned template from an earlier, unrestricted run and another (say
681
+ `clinicalkey`) doesn't, the same `search` call will show `uptodate` succeeding via tier 1 (no
682
+ Chrome, no lock) while `clinicalkey` fails this way — that's a caching-order artifact, not a sign
683
+ that `clinicalkey` itself is broken or unsupported while `uptodate` is fine. Don't report this to a
684
+ person as "ClinicalKey doesn't work" (or whichever site hit it) — report it as "this environment
685
+ can't run tier-2 discovery for a site with no cached endpoint yet."
686
+
687
+ What actually unblocks it, in order of preference:
688
+
689
+ 1. **Run `web-cli search`/`get` once for that site from an unrestricted shell** (outside whatever
690
+ sandboxed environment produced the `EPERM`) so tier 2 can complete normally there. That learns
691
+ and persists the template to `~/.web-cli/learned/<site>.json`; the exact same restricted
692
+ environment will then hit tier 1 for that `(site, intent)` and never touch Chrome or the lock
693
+ again for it.
694
+ 2. **Preseed the endpoint template** (`src/discovery/preseed.ts`'s `PRESEED_TEMPLATES`, checked
695
+ automatically between tier 1 and tier 2 — see `CLAUDE.md`'s architecture section for the exact
696
+ shape) so tier 1 works even on a machine that has never successfully run discovery at all. This
697
+ requires a code change (adding an entry) by whoever maintains this checkout — flag it as the fix
698
+ to make rather than attempting to work around the sandbox denial yourself.
699
+ 3. If neither is possible in the moment, treat that one site's entry the same as any other
700
+ site-level failure (see "reading a `search` result" above): report the other sites' results,
701
+ and name the concrete blocker (sandboxed lock-file access) rather than a generic "search
702
+ failed."
703
+
704
+ ### Interpreting results — don't trust a single site's silence
705
+
706
+ A site's entry showing `discovered` set and a nonempty `results` object is *not* proof the query
707
+ was actually understood by that site — search engines routinely autocorrect an unfamiliar or
708
+ technical term to something more common and return confident-looking, completely unrelated
709
+ results, often with no error and no "did you mean" flag at all (`parsed.didYouMean` surfaces one
710
+ when UpToDate/ClinicalKey's own response happens to carry that signal — see "Parsed output" above —
711
+ but its *absence* is not proof the query was matched literally). Concretely:
712
+ searching UpToDate/ClinicalKey for a precise anatomical term (e.g. a specific brain-structure layer
713
+ name) commonly returns real search results for a *different*, more common term the query got
714
+ silently corrected to — inspect the actual result titles/snippets for topical relevance before
715
+ treating a nonempty response as an answer. `search` returns all three medical sites' entries side
716
+ by side in one call, so use that to cross-check — if `uptodate` and
717
+ `clinicalkey` agree on a topic but `googlemedsearch`'s results look unrelated (or vice versa),
718
+ that's a sign one of them silently autocorrected. If the query is specifically about anatomical
719
+ structure/layer naming or a historical/Latin synonym, see `references/anatomy-lookup.md` — for
720
+ that class of query, none of these three sites' results should be trusted over FMA/Terminologia
721
+ Anatomica, regardless of how confident they look.
722
+
723
+ ### googlemedsearch as a broad fallback
724
+
725
+ `googlemedsearch` (a Google Programmable Search Engine scoped to medical sites) has no login wall
726
+ and searches much more broadly than UpToDate/ClinicalKey — useful when a query needs general
727
+ medical/scientific web coverage (overviews, peer-reviewed papers, Wikipedia) rather than a
728
+ specific subscription resource's own clinical-practice content. Its results are JSONP under the
729
+ hood; the CLI already unwraps that transparently, so its `results` entry is always plain parsed
730
+ JSON. It's included in every `search` call (there's no separate flag to opt into it — see this
731
+ skill's own note above on `search` always covering all three medical sites). Use
732
+ `parsed.hits[].url` rather than a raw hit's `clicktrackUrl` if you need its link — see "Parsed
733
+ output" above.
734
+
735
+ `search` itself has no general-purpose (non-medical) site to fall back to at all — for anything
736
+ outside medicine/anatomy/substances/organisms, use `web-cli websearch` instead (see that command's
737
+ own section above): a real Google/Bing/Gemini fallback chain, not restricted to any fixed site
738
+ list.