@ysgao/web-cli 0.1.2 → 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.
- package/dist/index.js +48 -4
- package/package.json +1 -1
- package/skills/web-cli/SKILL.md +98 -2
package/dist/index.js
CHANGED
|
@@ -52120,17 +52120,61 @@ function describeError(err) {
|
|
|
52120
52120
|
code: err instanceof CliError ? err.code : "INTERNAL_ERROR"
|
|
52121
52121
|
};
|
|
52122
52122
|
}
|
|
52123
|
-
function
|
|
52123
|
+
function recommendedActionFor(code, site) {
|
|
52124
|
+
switch (code) {
|
|
52125
|
+
case "SESSION_EXPIRED":
|
|
52126
|
+
return `The silent, credential-based session refresh for "${site}" already ran and did not recover \u2014 do not retry the same call expecting a different result. Tell the user to run "web-cli login ${site} --save-credentials" once so every future run recovers silently with no human needed, or re-run with --allow-visible-login if a human can sign in right now. Never substitute another site's results, a previously-saved file, or any other data in place of this one without saying so.`;
|
|
52127
|
+
case "DISCOVERY_FAILED":
|
|
52128
|
+
return `This site's endpoint needs re-learning: run "web-cli observe --site ${site} --intent <search|getArticle> --param \\"<a real query/article for ${site}>\\"" once, then retry.`;
|
|
52129
|
+
case "ARTICLE_MISMATCH":
|
|
52130
|
+
return `The full-text fetch returned a different article than the one requested, so it was deliberately withheld rather than kept as wrong content. The fix is the same as DISCOVERY_FAILED: re-learn "${site}"'s getArticle endpoint via "web-cli observe".`;
|
|
52131
|
+
case "PAYWALLED":
|
|
52132
|
+
return `Signed in to "${site}" but not entitled to this specific item \u2014 this is not a session problem web-cli can retry its way out of; say so rather than treating it as missing data.`;
|
|
52133
|
+
default:
|
|
52134
|
+
return `No specific automatic recovery is known for this code ("${code}") \u2014 do not silently drop or paper over it; state the failure and its message/code plainly in your answer.`;
|
|
52135
|
+
}
|
|
52136
|
+
}
|
|
52137
|
+
function buildAgentTask(query, keyReferences, sites2) {
|
|
52138
|
+
const unrecoveredFailures = [];
|
|
52139
|
+
for (const [site, outcome] of Object.entries(sites2)) {
|
|
52140
|
+
if (outcome.error !== void 0) {
|
|
52141
|
+
const code = outcome.code ?? "INTERNAL_ERROR";
|
|
52142
|
+
unrecoveredFailures.push({
|
|
52143
|
+
scope: "site",
|
|
52144
|
+
site,
|
|
52145
|
+
code,
|
|
52146
|
+
error: outcome.error,
|
|
52147
|
+
recommendedAction: recommendedActionFor(code, site)
|
|
52148
|
+
});
|
|
52149
|
+
}
|
|
52150
|
+
}
|
|
52151
|
+
for (const ref of keyReferences) {
|
|
52152
|
+
if (ref.fetchError !== void 0) {
|
|
52153
|
+
const code = ref.fetchError.code ?? "INTERNAL_ERROR";
|
|
52154
|
+
unrecoveredFailures.push({
|
|
52155
|
+
scope: "keyReference",
|
|
52156
|
+
site: ref.site,
|
|
52157
|
+
title: ref.title,
|
|
52158
|
+
url: ref.url,
|
|
52159
|
+
code,
|
|
52160
|
+
error: ref.fetchError.error,
|
|
52161
|
+
recommendedAction: recommendedActionFor(code, ref.site)
|
|
52162
|
+
});
|
|
52163
|
+
}
|
|
52164
|
+
}
|
|
52165
|
+
const failureNote = unrecoveredFailures.length > 0 ? ` IMPORTANT: "unrecoveredFailures" lists ${pluralize(unrecoveredFailures.length, "source")} that did NOT come back (web-cli's own default recovery already ran for these and did not succeed) \u2014 you must state plainly, in your answer, which source(s) failed and why, and follow each entry's own "recommendedAction". Never silently substitute another site's results or any previously-cached/saved data in their place, and never present the answer as if coverage were complete when it wasn't.` : "";
|
|
52124
52166
|
const withFullText = keyReferences.filter((ref) => !!ref.article?.text);
|
|
52125
52167
|
if (keyReferences.length === 0) {
|
|
52126
52168
|
return {
|
|
52127
52169
|
question: query,
|
|
52128
|
-
instructions: 'No key references were selected for this query (see "keyReferences" and "summary" \u2014 nothing was retrieved to expand into full text). Answer the question above only if the per-site hit titles/snippets in "sites.<site>.parsed.hits" are genuinely enough to do so honestly; otherwise say plainly that this search did not surface enough to answer it.'
|
|
52170
|
+
instructions: 'No key references were selected for this query (see "keyReferences" and "summary" \u2014 nothing was retrieved to expand into full text). Answer the question above only if the per-site hit titles/snippets in "sites.<site>.parsed.hits" are genuinely enough to do so honestly; otherwise say plainly that this search did not surface enough to answer it.' + failureNote,
|
|
52171
|
+
...unrecoveredFailures.length > 0 ? { unrecoveredFailures } : {}
|
|
52129
52172
|
};
|
|
52130
52173
|
}
|
|
52131
52174
|
return {
|
|
52132
52175
|
question: query,
|
|
52133
|
-
instructions: `Answer the question above using the material already retrieved into "keyReferences" \u2014 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 \u2014 leave it out of your answer entirely, rather than citing it just because it was fetched.` + (withFullText.length < keyReferences.length ? ` For an entry with no "article.text" (see "fetchError"/omitted from ${withFullText.length}/${keyReferences.length} with full text in "summary.keyReferences"), fall back to its "snippet" instead of skipping it, but note that fallback is unconfirmed.` : "") + ` If nothing retrieved actually answers the question, say so plainly rather than forcing an answer out of unrelated material.`
|
|
52176
|
+
instructions: `Answer the question above using the material already retrieved into "keyReferences" \u2014 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 \u2014 leave it out of your answer entirely, rather than citing it just because it was fetched.` + (withFullText.length < keyReferences.length ? ` For an entry with no "article.text" (see "fetchError"/omitted from ${withFullText.length}/${keyReferences.length} with full text in "summary.keyReferences"), fall back to its "snippet" instead of skipping it, but note that fallback is unconfirmed.` : "") + ` If nothing retrieved actually answers the question, say so plainly rather than forcing an answer out of unrelated material.` + failureNote,
|
|
52177
|
+
...unrecoveredFailures.length > 0 ? { unrecoveredFailures } : {}
|
|
52134
52178
|
};
|
|
52135
52179
|
}
|
|
52136
52180
|
function siteHitCount(outcome) {
|
|
@@ -52345,7 +52389,7 @@ async function runSearch(query, extraSites = [], opts = {}) {
|
|
|
52345
52389
|
const result = {
|
|
52346
52390
|
...document2,
|
|
52347
52391
|
summary,
|
|
52348
|
-
agentTask: buildAgentTask(query, keyReferences),
|
|
52392
|
+
agentTask: buildAgentTask(query, keyReferences, sites2),
|
|
52349
52393
|
...markdownPath !== void 0 ? { markdownPath } : {},
|
|
52350
52394
|
// Present only when something actually went wrong, so its mere presence is the signal.
|
|
52351
52395
|
...markdownError !== void 0 ? { markdownError } : {},
|
package/package.json
CHANGED
package/skills/web-cli/SKILL.md
CHANGED
|
@@ -255,6 +255,54 @@ change (a new dependency, an API key to manage, a per-call cost) this project do
|
|
|
255
255
|
afterthought — but `web-cli finalize` (next) is a genuinely optional fifth step for turning that
|
|
256
256
|
reading into its own polished artifact.
|
|
257
257
|
|
|
258
|
+
### `agentTask.unrecoveredFailures`: a failed source, named in the data, so it can't be swapped out silently
|
|
259
|
+
|
|
260
|
+
`agentTask` gains a second field, **only when at least one site or `keyReferences` entry actually
|
|
261
|
+
failed** (commonly `SESSION_EXPIRED` — see "Sessions" above — after `web-cli`'s own default silent
|
|
262
|
+
recovery already ran and did not succeed):
|
|
263
|
+
|
|
264
|
+
```json
|
|
265
|
+
{
|
|
266
|
+
"agentTask": {
|
|
267
|
+
"question": "...",
|
|
268
|
+
"instructions": "... IMPORTANT: \"unrecoveredFailures\" lists 1 source that did NOT come back ... Never silently substitute another site's results or any previously-cached/saved data in their place ...",
|
|
269
|
+
"unrecoveredFailures": [
|
|
270
|
+
{
|
|
271
|
+
"scope": "site",
|
|
272
|
+
"site": "clinicalkey",
|
|
273
|
+
"code": "SESSION_EXPIRED",
|
|
274
|
+
"error": "no cookies for clinicalkey",
|
|
275
|
+
"recommendedAction": "The silent, credential-based session refresh for \"clinicalkey\" already ran and did not recover — do not retry the same call expecting a different result. Tell the user to run \"web-cli login clinicalkey --save-credentials\" once so every future run recovers silently with no human needed, or re-run with --allow-visible-login if a human can sign in right now. Never substitute another site's results, a previously-saved file, or any other data in place of this one without saying so."
|
|
276
|
+
}
|
|
277
|
+
]
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
This is the **data-backed, code-enforced form** of this skill's own "A `SESSION_EXPIRED` you
|
|
283
|
+
actually receive must never be silently worked around" rule above — present in every result,
|
|
284
|
+
regardless of whether you happen to still recall that rule from reading this doc at session start.
|
|
285
|
+
It cannot force what you write in your own final answer (this CLI has no visibility into, or
|
|
286
|
+
control over, anything that happens after it exits — there is no LLM inside it at all, see
|
|
287
|
+
`CLAUDE.md`), but it does guarantee the failure and its concrete fix travel with the result itself
|
|
288
|
+
rather than depending on you remembering a rule from a separate document. Each entry has:
|
|
289
|
+
|
|
290
|
+
- `scope`: `"site"` (a whole site's search failed — see `sites.<site>.error`) or `"keyReference"`
|
|
291
|
+
(one selected hit's full-text fetch failed — see `keyReferences[].fetchError`); a `"keyReference"`
|
|
292
|
+
entry also carries that hit's own `title`/`url` so it's identifiable without cross-referencing.
|
|
293
|
+
- `code`/`error`: the exact same values already on `sites.<site>`/`keyReferences[].fetchError` —
|
|
294
|
+
repeated here so this list is self-contained.
|
|
295
|
+
- `recommendedAction`: the concrete next step for `code` — for `SESSION_EXPIRED`, naming
|
|
296
|
+
`web-cli login <site> --save-credentials` (silent, no human needed on every future run) or
|
|
297
|
+
`--allow-visible-login` (a human signs in now); for `DISCOVERY_FAILED`/`ARTICLE_MISMATCH`, the
|
|
298
|
+
`web-cli observe` re-learning step; for `PAYWALLED`, a plain statement that there is nothing to
|
|
299
|
+
retry. An unrecognized code still gets an explicit "state this plainly, don't drop it" fallback
|
|
300
|
+
rather than silence.
|
|
301
|
+
|
|
302
|
+
**Absent entirely (not an empty array) when nothing failed** — same "presence is the signal"
|
|
303
|
+
convention as `markdownPath`/`outPath`'s own error siblings — so `"unrecoveredFailures" in
|
|
304
|
+
agentTask` is itself a reliable one-line check for "did everything come back clean."
|
|
305
|
+
|
|
258
306
|
### `web-cli finalize`: turn your reading into a curated report (optional fifth step)
|
|
259
307
|
|
|
260
308
|
Once you've done the four-step read above, you can hand your own conclusions back to `web-cli` and
|
|
@@ -358,6 +406,49 @@ ask for one.** You do not need to run `web-cli login` first, and you should not
|
|
|
358
406
|
`--allow-visible-login`, or tell them to run `web-cli login <site>` once beforehand. A visible
|
|
359
407
|
window needs an actual human sign-in; it will not complete on its own.
|
|
360
408
|
|
|
409
|
+
### A `SESSION_EXPIRED` you actually receive must never be silently worked around
|
|
410
|
+
|
|
411
|
+
By the time `SESSION_EXPIRED` reaches you in a result, the CLI itself has **already** tried the
|
|
412
|
+
default, no-human-needed recovery (the silent credential-based refresh above) and it did not
|
|
413
|
+
succeed — this is not a transient blip to quietly paper over, and it is not your call to decide
|
|
414
|
+
it "doesn't matter" because other sites or cached data happened to cover the gap. **This exact
|
|
415
|
+
rule is also enforced in the data itself**, not just in this prose — see
|
|
416
|
+
`agentTask.unrecoveredFailures` further below, which `search` populates automatically whenever
|
|
417
|
+
this happens, naming the failed source and its concrete fix directly in the JSON you read.
|
|
418
|
+
Concretely, when you see it (on a whole site's `sites.<site>.error`, or on one
|
|
419
|
+
`keyReferences[].fetchError`, or — the hard-to-miss form — listed in
|
|
420
|
+
`agentTask.unrecoveredFailures`):
|
|
421
|
+
|
|
422
|
+
1. **Say so, plainly, in your answer** — e.g. "ClinicalKey's session had expired and couldn't be
|
|
423
|
+
refreshed automatically, so its results/full text aren't included below." Never produce an
|
|
424
|
+
answer that reads as complete (or quietly leans on `googlemedsearch`/a previously-saved file/
|
|
425
|
+
another site's hits instead) without disclosing that a specific source actually failed and why.
|
|
426
|
+
Reusing an old result file (from an earlier `search --out`, or anything else already sitting on
|
|
427
|
+
disk) as a stand-in for a source that just failed is exactly the kind of silent substitution
|
|
428
|
+
this rule forbids — stale cached data is not a substitute for a disclosed failure, and
|
|
429
|
+
presenting it as if it were fresh is worse than just saying the fetch failed.
|
|
430
|
+
2. **Don't just retry the identical call hoping it works differently** — the silent phase already
|
|
431
|
+
ran and failed once; calling `search`/`get` again with no new flag will almost certainly repeat
|
|
432
|
+
the same `SESSION_EXPIRED`, burning time without starting a session.
|
|
433
|
+
3. **Take (or ask for) one of the concrete, documented recovery actions instead**, matching your
|
|
434
|
+
situation:
|
|
435
|
+
- A human is present and can act now → re-run with `--allow-visible-login` so a real sign-in
|
|
436
|
+
window opens or re-check the one that's already open, or just prompt them to run
|
|
437
|
+
`web-cli login <site>` directly, then retry.
|
|
438
|
+
- No human is present (the common unattended-agent case) → check whether a credential was ever
|
|
439
|
+
saved for that site. If you don't know, tell the person a credential needs to be saved once
|
|
440
|
+
(`web-cli login <site> --save-credentials`) so every future run recovers silently with zero
|
|
441
|
+
flags — this is the fix that actually starts a new, durable session rather than working
|
|
442
|
+
around the missing one. If a credential WAS saved and this still failed, say that explicitly
|
|
443
|
+
too (password changed / account locked / a CAPTCHA the auto-fill heuristic can't clear) —
|
|
444
|
+
don't guess silently and move on.
|
|
445
|
+
- If only one `keyReferences` entry failed while the rest of that site's search worked, you can
|
|
446
|
+
retry just that one item after recovery (`web-cli get <site> <its url>`) rather than
|
|
447
|
+
re-running the whole `search`.
|
|
448
|
+
4. **A site/entry failing this way never blocks you from reporting what every other source did
|
|
449
|
+
return** — see the next section. The requirement here is disclosure and an attempt at real
|
|
450
|
+
recovery for the part that failed, not blocking everything else on it.
|
|
451
|
+
|
|
361
452
|
`web-cli auth status` reports whether cookies exist, but note that **cookies existing is not the
|
|
362
453
|
same as being signed in** — ClinicalKey in particular hands out an anonymous session that satisfies
|
|
363
454
|
search while still refusing full text. So a nonempty `auth status` does not guarantee full-text
|
|
@@ -384,7 +475,10 @@ plus anything passed via `--site`), each independently either:
|
|
|
384
475
|
extra network call beyond the one search itself — see `keyReferences` (top-level, not nested per
|
|
385
476
|
site) for the small subset of hits that get a full-text fetch.
|
|
386
477
|
- `{"error": "...", "code": "..."}` — that one site failed (commonly `SESSION_EXPIRED` — see
|
|
387
|
-
above — or `DISCOVERY_FAILED`); the *other* sites' entries are still real, usable results.
|
|
478
|
+
above — or `DISCOVERY_FAILED`); the *other* sites' entries are still real, usable results. A
|
|
479
|
+
`SESSION_EXPIRED` here is NOT just another field to note and move past — see "A `SESSION_EXPIRED`
|
|
480
|
+
you actually receive must never be silently worked around" above for what you must actually do
|
|
481
|
+
with it before writing your answer.
|
|
388
482
|
|
|
389
483
|
The command itself only fails (exit non-zero, `SEARCH_FAILED`) when every site failed — a mix of
|
|
390
484
|
some-succeeded/some-failed is a normal exit-0 result, so check each site's entry rather than
|
|
@@ -392,7 +486,9 @@ assuming a successful exit means every site returned data.
|
|
|
392
486
|
|
|
393
487
|
A `keyReferences` entry with a `fetchError` instead of an `article` is worth reading precisely: the
|
|
394
488
|
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
|
|
489
|
+
`SESSION_EXPIRED` there means signed in but not entitled to that specific item — same disclose-and-
|
|
490
|
+
recover rule as above applies, it just applies to one entry rather than the whole site;
|
|
491
|
+
`DISCOVERY_FAILED`
|
|
396
492
|
means that site's article endpoint needs re-learning via `observe`; **`ARTICLE_MISMATCH`** means the
|
|
397
493
|
fetch technically succeeded but came back with a DIFFERENT article than the one this entry is
|
|
398
494
|
about — confirmed live (not hypothetical): a stale/mismatched `getArticle` endpoint template can
|