@ysgao/web-cli 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -34,25 +34,30 @@ per-site endpoint knowledge. Every command prints one JSON document to stdout on
34
34
 
35
35
  ## Quick Start
36
36
 
37
+ **Just want to use it?** Install the published package — this is the normal path for everyone
38
+ except someone actively developing this CLI's own source:
39
+
37
40
  ```bash
38
- npm install
39
- npm run build
41
+ npm install -g @ysgao/web-cli
40
42
 
41
43
  # Check authentication
42
- node dist/index.js auth status
44
+ web-cli auth status
43
45
 
44
46
  # Log in to a site (opens the dedicated automation Chrome profile)
45
- node dist/index.js login uptodate
47
+ web-cli login uptodate
46
48
 
47
49
  # Search medical sites
48
- node dist/index.js search "fever treatment"
50
+ web-cli search "fever treatment"
49
51
 
50
52
  # Get help
51
- node dist/index.js --help
53
+ web-cli --help
52
54
  ```
53
55
 
54
- Optionally, `npm link` after building to get a global `web-cli` command that live-updates on
55
- rebuild (see **Publishing** below).
56
+ Re-run `npm install -g @ysgao/web-cli` any time to pick up a newer published version.
57
+
58
+ **Developing this CLI's own source instead?** See **Publishing** below for the local, un-published
59
+ dev-install path (`npm link`) — a separate thing from the normal install above, and NOT what you
60
+ want just to use the tool.
56
61
 
57
62
  ## Commands
58
63
 
@@ -105,36 +110,75 @@ node dist/index.js observe --site <site> --intent <search|getArticle> --param "<
105
110
  node dist/index.js learned [--site <site>]
106
111
  node dist/index.js finalize [--markdown [path]] [--json] [--pretty] # reads {query, finalAnswer, summary?, keyReferences, answers} as JSON on stdin
107
112
  node dist/index.js render-markdown [--from <path>] [--markdown [path]] [--json] # renders a Markdown report from an ALREADY-RETRIEVED search result -- zero network calls
108
- node dist/index.js install-skill [--agent claude|codex|agents|all] [--project] [--force]
109
- node dist/index.js uninstall-skill [--agent claude|codex|agents|all] [--project] [--force]
113
+ node dist/index.js install-skill [--agent claude|codex|agents|dsh|all] [--project] [--force]
114
+ node dist/index.js uninstall-skill [--agent claude|codex|agents|dsh|all] [--project] [--force]
110
115
  ```
111
116
 
112
- (Replace `node dist/index.js` with `web-cli` if you've run `npm link`.)
113
-
114
- ### `install-skill`'s three targets
115
-
116
- `--agent` accepts `claude`, `codex`, `agents`, or `all` — omit it and `install-skill` registers
117
- whichever of these are actually present on your machine (falling back to `claude` if none are).
118
- `claude`/`codex` register with Claude Code (`~/.claude/skills`) and Codex (`~/.codex/prompts`)
119
- respectively. **`agents`** registers with `~/.agents/skills` (or `$DSH_AGENTS_HOME/skills`) —
120
- DeepSeek Harness's own bundled skill provider scans this location (and `~/.dsh/skills`) directly
121
- for its `skill` tool's catalog, and never looks at `~/.claude`/`~/.codex` at all. If you're driving
122
- this CLI from a DSH-based agent and it reports the `web-cli` skill as "unknown or no longer
123
- available" even though `install-skill` has already run, this is almost always why — re-run with
124
- `--agent agents` (or `--agent all`) to also cover it.
117
+ (The commands above are written as `node dist/index.js ...` because that's what works from inside
118
+ a cloned, un-built-into-a-global-command checkout. If you installed via `npm install -g
119
+ @ysgao/web-cli` — the normal path, see **Quick Start** above — or ran `npm link` while developing
120
+ this checkout, use the plain `web-cli ...` form instead; both resolve to the exact same CLI.)
121
+
122
+ ### `install-skill`'s four targets — each a copy, refreshed on every run
123
+
124
+ `install-skill` **copies** the skill that ships inside the package (`skills/web-cli/`: `SKILL.md` +
125
+ `references/`) into each agent's skills folder as a real directory — never a symlink into the
126
+ package, and no generated pointer file. Re-running it after upgrading the CLI refreshes every copy
127
+ to the latest version (`"status":"updated"`); re-running with nothing changed reports
128
+ `already-current`. Each copy carries a small marker file (`.installed-by-web-cli.json`, recording
129
+ the package version and where it was copied from) — that's how a later run recognizes its own
130
+ outdated copy and refreshes it rather than mistaking it for a directory you wrote yourself. Delete
131
+ the marker if you want to take a copy over and edit it as your own: from then on `install-skill`
132
+ treats it as yours and leaves it alone unless you pass `--force`.
133
+
134
+ `--agent` accepts `claude`, `codex`, `agents`, `dsh`, or `all` (comma-separable) — omit it and
135
+ `install-skill` targets whichever of `claude`/`codex`/`dsh` are actually present on your machine
136
+ (falling back to `claude` if none are; `agents` is never auto-selected — see below):
137
+
138
+ - **`claude`** → `~/.claude/skills/web-cli/` (or `<cwd>/.claude/skills/web-cli/` with `--project`,
139
+ a self-contained copy you can commit).
140
+ - **`codex`** → `~/.codex/skills/web-cli/` (or `$CODEX_HOME/skills/web-cli/`) — Codex discovers
141
+ `SKILL.md` skills from this folder exactly like Claude Code does. Earlier versions of this tool
142
+ instead wrote a pointer prompt to `~/.codex/prompts/web-cli.md`, from before Codex had a skills
143
+ folder; `install-skill`/`uninstall-skill` both remove that legacy file if it's one of ours.
144
+ - **`agents`** → `~/.agents/skills/web-cli/` (or `$DSH_AGENTS_HOME/skills/`) — the cross-tool
145
+ "shared agent config root" DeepSeek Harness's bundled skill provider scans.
146
+ - **`dsh`** → `~/.dsh/skills/web-cli/` (or `$DSH_HOME/skills/`) — DSH's own dedicated home, the
147
+ directory where it also keeps its sessions/profile data, and where a user who manages all of
148
+ their DSH skills in one place typically already has the rest of them.
149
+
150
+ The two DSH targets both serve **DeepSeek Harness**, whose skill provider scans both user-level
151
+ roots for its `skill` tool's catalog — and never looks at `~/.claude`/`~/.codex` at all. They are
152
+ two genuinely different directories, not two spellings of one (`~/.agents` honors
153
+ `$DSH_AGENTS_HOME`; `~/.dsh` honors `$DSH_HOME`), so either can exist without the other and
154
+ neither stands in for the other. **`dsh` is the auto-detected DSH target; `agents` is
155
+ explicit-only** (`--agent agents` or `--agent all`): `~/.agents` is a cross-tool root that other
156
+ software creates and uses for its own purposes, so its mere existence says nothing about whether
157
+ you want this skill there — and since DSH scans both roots, installing into both automatically
158
+ would register the same skill with DSH twice on any machine that has both. If you're driving this
159
+ CLI from a DSH-based agent and it reports the `web-cli` skill as "unknown or no longer available"
160
+ even though `install-skill` has already run, this is almost always why — re-run with `--agent dsh`
161
+ (or `--agent all`) to cover it. If you previously copied `skills/web-cli/` into `~/.dsh/skills/` by
162
+ hand (the only option before the `dsh` target existed), `install-skill` recognizes a byte-identical
163
+ copy as its own and takes it over (adding the marker) without needing `--force`; a copy you've since
164
+ edited is left alone unless you pass `--force`.
165
+
166
+ Previous *symlink* installs from older versions of this tool — live or dangling after an
167
+ `npm rm -g` — are likewise recognized and replaced with a copy, no `--force` required.
125
168
 
126
169
  **On a brand-new machine (e.g. a fresh Termux:X11 proot-distro Debian install), a plain
127
- `install-skill` with no `--agent` flag can silently skip the `agents` target entirely** — its
128
- auto-detection (`detectAgents` in `src/skillInstall.ts`) only targets an agent whose home directory
129
- *already exists*, and `~/.agents` (or `$DSH_AGENTS_HOME`) won't exist yet if DSH itself, or some
130
- other tool that creates it, hasn't run there before. The command still reports success (typically
131
- `{"agent":"claude","status":"installed",...}`), which reads as "the skill is installed" — but
132
- nothing was ever written to `~/.agents/skills`, so DSH's `skill` tool still can't find it. Confirm
133
- which targets actually ran by checking the `results[].agent` list in the command's own JSON output,
134
- or just always pass `--agent all` explicitly when you specifically want DSH coverage rather than
135
- relying on auto-detection. After registering (or re-registering) the `agents` target, **start a new
136
- DSH session/chat** — the skill catalog a running agent sees is loaded once, at session start, so an
137
- already-open session won't pick up a skill installed mid-conversation.
170
+ `install-skill` with no `--agent` flag can silently skip the `dsh` target entirely** — its
171
+ auto-detection (`detectAgents` in `src/skillInstall.ts`) only targets an agent whose home
172
+ directory *already exists*, and `~/.dsh` (or `$DSH_HOME`) won't exist yet if DSH itself hasn't
173
+ run there before. The command still
174
+ reports success (typically `{"agent":"claude","status":"installed",...}`), which reads as "the
175
+ skill is installed" — but nothing was ever written to either DSH root, so DSH's `skill` tool still
176
+ can't find it. Confirm which targets actually ran by checking the `results[].agent` list in the
177
+ command's own JSON output, or just always pass `--agent all` explicitly when you specifically want
178
+ DSH coverage rather than relying on auto-detection. After registering (or re-registering) either
179
+ DSH target, **start a new DSH session/chat** — the skill catalog a running agent sees is loaded
180
+ once, at session start, so an already-open session won't pick up a skill installed
181
+ mid-conversation.
138
182
 
139
183
  ### `search`/`finalize`: JSON or a human-readable report, auto-detected from whether stdout is a terminal
140
184
 
@@ -538,20 +582,35 @@ Known sites are registered in `src/sites/index.ts`.
538
582
  | Full text missing on a hit | Check `keyReferences[].fetchError`. `SESSION_EXPIRED` there means signed in but not entitled to that item; `DISCOVERY_FAILED` means the article endpoint needs re-learning |
539
583
  | Your own Chrome is open | Not a problem, and never was worth quitting it for — automation uses its own instance (see `src/discovery/chromeWrapperApp.ts`, and its regression tests in `test/chromeWrapperApp.test.ts`) |
540
584
  | Discovery failed | Run: `node dist/index.js observe --site uptodate --intent search --param "test"` — see **Manual discovery with `observe`** above for a full walkthrough |
541
- | Build out of date | Run: `npm install && npm run build` |
585
+ | Installed version out of date (registry install) | Run: `npm install -g @ysgao/web-cli` again to pick up the newest published version |
586
+ | Build out of date (dev checkout) | Run: `npm install && npm run build` |
587
+ | `web-cli` still resolves to a local checkout instead of the published package | Check with `readlink -f "$(which web-cli)"` — if it points into a cloned repo rather than `.../node_modules/@ysgao/web-cli/...`, an `npm link` from earlier dev work is still active. Run `npm unlink -g @ysgao/web-cli` then `npm install -g @ysgao/web-cli` to switch to the real published package |
542
588
  | Platform-specific issues | See `KNOWN_ISSUES.md` |
543
589
 
544
590
  ## Publishing
545
591
 
546
- This package is **not published to npm** (see `CLAUDE.md` for why). For local use:
592
+ **This package IS published to npm, publicly, under `@ysgao/web-cli`** — see **Quick Start** above
593
+ for the normal way to get the `web-cli` command (`npm install -g @ysgao/web-cli`, no clone needed).
594
+ Everything below is only for someone developing this CLI's own source from a cloned checkout.
595
+
596
+ **Local dev install** (no registry round-trip — for iterating on this checkout itself):
547
597
 
548
598
  ```bash
549
599
  npm run build
550
- npm link # symlinks the `web-cli` command globally to this checkout's dist/index.js
600
+ npm link # symlinks the `web-cli` command globally to THIS checkout's dist/index.js
551
601
  ```
552
602
 
553
603
  After `npm link`, editing code + `npm run build` alone is enough for the global `web-cli` command
554
- to pick up the change. Undo with `npm unlink -g @ysgao/web-cli`.
604
+ to pick up the change — no relink needed. **Undo with `npm unlink -g @ysgao/web-cli` before
605
+ switching back to the real published package** (`npm install -g @ysgao/web-cli`) — a leftover link
606
+ silently shadows the registry version with whatever this checkout happens to contain, with no
607
+ warning that anything is out of the ordinary. Check which one is currently active with
608
+ `readlink -f "$(which web-cli)"`: it should point somewhere under
609
+ `.../node_modules/@ysgao/web-cli/...` for a real install, or into a cloned repo path if a link is
610
+ still active.
611
+
612
+ See `CLAUDE.md`'s own Publishing section for maintainer-facing detail on releasing a new version
613
+ (version-bump rules, the tarball sanity check, and a couple of hard-won registry/sandbox gotchas).
555
614
 
556
615
  ## Support
557
616
 
package/dist/index.js CHANGED
@@ -52024,6 +52024,7 @@ function articleKeyFrom(site, searchData, baseUrl) {
52024
52024
  }
52025
52025
  return hit.url ?? hit.id ?? null;
52026
52026
  }
52027
+ var PROBE_CANARY_QUERY = "pneumonia";
52027
52028
  async function probeWithJar(site, probeQuery, jar) {
52028
52029
  const config2 = getSiteConfig(site);
52029
52030
  const header = cookieJarToHeader(jar);
@@ -52041,7 +52042,16 @@ async function probeWithJar(site, probeQuery, jar) {
52041
52042
  if (!articleTemplate) {
52042
52043
  return "valid";
52043
52044
  }
52044
- const key = articleKeyFrom(site, searchData, config2.baseUrl);
52045
+ let key = articleKeyFrom(site, searchData, config2.baseUrl);
52046
+ if (!key && probeQuery !== PROBE_CANARY_QUERY) {
52047
+ let canaryData;
52048
+ try {
52049
+ canaryData = await callTemplate(renderTemplate(searchTemplate, PROBE_CANARY_QUERY), header);
52050
+ } catch (err) {
52051
+ return isAuthFailure(err) ? "expired" : "valid";
52052
+ }
52053
+ key = articleKeyFrom(site, canaryData, config2.baseUrl);
52054
+ }
52045
52055
  if (!key) {
52046
52056
  return "valid";
52047
52057
  }
@@ -53402,10 +53412,33 @@ var fs14 = __toESM(require("fs"));
53402
53412
  var os5 = __toESM(require("os"));
53403
53413
  var path11 = __toESM(require("path"));
53404
53414
  var SKILL_NAME = "web-cli";
53405
- var AGENT_CHOICES = ["claude", "codex", "agents"];
53415
+ var INSTALL_MARKER_FILE = ".installed-by-web-cli.json";
53416
+ var COPY_EXCLUDES = /* @__PURE__ */ new Set([".DS_Store"]);
53417
+ var AGENT_CHOICES = ["claude", "codex", "agents", "dsh"];
53418
+ function resolveCodexHomeDir(homeDir, override) {
53419
+ const fromEnv = process.env.CODEX_HOME;
53420
+ if (override !== void 0) {
53421
+ return path11.resolve(override);
53422
+ }
53423
+ return fromEnv !== void 0 && fromEnv.trim().length > 0 ? path11.resolve(fromEnv) : path11.join(homeDir, ".codex");
53424
+ }
53406
53425
  function resolveAgentsHomeDir(homeDir, override) {
53407
53426
  return override ?? process.env.DSH_AGENTS_HOME ?? path11.join(homeDir, ".agents");
53408
53427
  }
53428
+ function resolveDshHomeDir(homeDir, override) {
53429
+ const fromEnv = process.env.DSH_HOME;
53430
+ const configured = override ?? (fromEnv !== void 0 && fromEnv.trim().length > 0 ? fromEnv : void 0);
53431
+ if (configured === void 0) {
53432
+ return path11.join(homeDir, ".dsh");
53433
+ }
53434
+ if (configured === "~") {
53435
+ return homeDir;
53436
+ }
53437
+ if (configured.startsWith("~/") || configured.startsWith("~\\")) {
53438
+ return path11.join(homeDir, configured.slice(2));
53439
+ }
53440
+ return path11.resolve(configured);
53441
+ }
53409
53442
  function resolveShippedSkillDir(fromDir) {
53410
53443
  const candidates = [
53411
53444
  path11.resolve(fromDir, "..", "skills", SKILL_NAME),
@@ -53420,20 +53453,28 @@ function resolveShippedSkillDir(fromDir) {
53420
53453
  `Could not find the bundled skill (looked for skills/${SKILL_NAME}/SKILL.md in: ${candidates.join(", ")}). This means the installed package is incomplete \u2014 reinstall with "npm install -g web-cli".`
53421
53454
  );
53422
53455
  }
53423
- function detectAgents(homeDir, agentsHomeOverride) {
53456
+ function shippedSkillVersion(shippedSkillDir) {
53457
+ try {
53458
+ const pkg = JSON.parse(fs14.readFileSync(path11.resolve(shippedSkillDir, "..", "..", "package.json"), "utf8"));
53459
+ return typeof pkg.version === "string" ? pkg.version : void 0;
53460
+ } catch {
53461
+ return void 0;
53462
+ }
53463
+ }
53464
+ function detectAgents(homeDir, overrides = {}) {
53424
53465
  const detected = [];
53425
53466
  if (fs14.existsSync(path11.join(homeDir, ".claude"))) {
53426
53467
  detected.push("claude");
53427
53468
  }
53428
- if (fs14.existsSync(path11.join(homeDir, ".codex"))) {
53469
+ if (fs14.existsSync(resolveCodexHomeDir(homeDir, overrides.codexHomeDir))) {
53429
53470
  detected.push("codex");
53430
53471
  }
53431
- if (fs14.existsSync(resolveAgentsHomeDir(homeDir, agentsHomeOverride))) {
53432
- detected.push("agents");
53472
+ if (fs14.existsSync(resolveDshHomeDir(homeDir, overrides.dshHomeDir))) {
53473
+ detected.push("dsh");
53433
53474
  }
53434
53475
  return detected;
53435
53476
  }
53436
- function resolveAgents(requested, homeDir, agentsHomeOverride) {
53477
+ function resolveAgents(requested, homeDir, overrides = {}) {
53437
53478
  if (requested === "all") {
53438
53479
  return [...AGENT_CHOICES];
53439
53480
  }
@@ -53445,32 +53486,10 @@ function resolveAgents(requested, homeDir, agentsHomeOverride) {
53445
53486
  }
53446
53487
  return names;
53447
53488
  }
53448
- const detected = detectAgents(homeDir, agentsHomeOverride);
53489
+ const detected = detectAgents(homeDir, overrides);
53449
53490
  return detected.length ? detected : ["claude"];
53450
53491
  }
53451
53492
  var CODEX_PROMPT_MARKER = "# web-cli \u2014 search/retrieval CLI usage guidance";
53452
- function buildCodexPrompt(shippedSkillDir) {
53453
- const skillFile = path11.join(shippedSkillDir, "SKILL.md");
53454
- const anatomyFile = path11.join(shippedSkillDir, "references", "anatomy-lookup.md");
53455
- return [
53456
- CODEX_PROMPT_MARKER,
53457
- "",
53458
- `Read \`${skillFile}\` now, and follow it for the rest of this session whenever you run the`,
53459
- "`web-cli` command \u2014 before any `search`, `get`, `login`, or `observe` call. It documents the",
53460
- "three-tier discovery/replay model and site-specific gotchas that fail or mislead in non-obvious",
53461
- "ways if you don't know about them going in.",
53462
- "",
53463
- `Also read \`${anatomyFile}\` whenever the query is about a specific anatomical structure, layer,`,
53464
- "or historical/Latin synonym \u2014 subscription clinical sites (UpToDate, ClinicalKey) are",
53465
- "practice-medicine resources and routinely lack this granularity; FMA and Terminologia Anatomica",
53466
- "are the actual controlled vocabularies for it.",
53467
- "",
53468
- "Both files live inside the installed `web-cli` npm package, so they stay in step with the CLI",
53469
- "itself. If the paths above no longer exist, the package moved or was upgraded to a different",
53470
- "location \u2014 re-run `web-cli install-skill` to refresh this prompt.",
53471
- ""
53472
- ].join("\n");
53473
- }
53474
53493
  function symlinkTarget(target) {
53475
53494
  try {
53476
53495
  return path11.resolve(path11.dirname(target), fs14.readlinkSync(target));
@@ -53508,11 +53527,15 @@ function isOurCodexPrompt(target) {
53508
53527
  return false;
53509
53528
  }
53510
53529
  }
53530
+ function isOurInstalledCopy(target) {
53531
+ const stats = lstatOrNull(target);
53532
+ return stats !== null && stats.isDirectory() && !stats.isSymbolicLink() && fs14.existsSync(path11.join(target, INSTALL_MARKER_FILE));
53533
+ }
53511
53534
  function relativeFileList(dir) {
53512
- return fs14.readdirSync(dir, { recursive: true, withFileTypes: true }).filter((entry) => entry.isFile()).map((entry) => path11.relative(dir, path11.join(entry.parentPath, entry.name))).sort();
53535
+ return fs14.readdirSync(dir, { recursive: true, withFileTypes: true }).filter((entry) => entry.isFile() && entry.name !== INSTALL_MARKER_FILE && !COPY_EXCLUDES.has(entry.name)).map((entry) => path11.relative(dir, path11.join(entry.parentPath, entry.name))).sort();
53513
53536
  }
53514
- function isCopyOfShippedSkill(target, shippedSkillDir) {
53515
- if (!shippedSkillDir || !fs14.existsSync(shippedSkillDir)) {
53537
+ function matchesShippedSkill(target, shippedSkillDir) {
53538
+ if (!shippedSkillDir || !fs14.existsSync(shippedSkillDir) || !lstatOrNull(target)?.isDirectory()) {
53516
53539
  return false;
53517
53540
  }
53518
53541
  try {
@@ -53527,126 +53550,94 @@ function isCopyOfShippedSkill(target, shippedSkillDir) {
53527
53550
  return false;
53528
53551
  }
53529
53552
  }
53530
- function installClaude(options, homeDir, cwd) {
53531
- const skillsRoot = options.project ? path11.join(cwd, ".claude", "skills") : path11.join(homeDir, ".claude", "skills");
53532
- const target = path11.join(skillsRoot, SKILL_NAME);
53533
- const shipped = options.shippedSkillDir;
53534
- const linkPath = options.project && shipped.startsWith(cwd + path11.sep) ? path11.relative(path11.dirname(target), shipped) : shipped;
53535
- const existing = lstatOrNull(target);
53536
- let replaced = false;
53537
- if (existing) {
53538
- const linked = symlinkTarget(target);
53539
- if (linked === shipped && fs14.existsSync(linked)) {
53540
- return { agent: "claude", path: target, status: "already-current", kind: "symlink", detail: shipped };
53541
- }
53542
- const reclaimable = isOurSkillLink(target) || isCopyOfShippedSkill(target, shipped);
53543
- if (!reclaimable && !options.force) {
53544
- return { agent: "claude", path: target, status: "blocked", kind: "symlink", detail: describeExisting(target) };
53545
- }
53546
- fs14.rmSync(target, { recursive: true, force: true });
53547
- replaced = true;
53548
- }
53549
- fs14.mkdirSync(skillsRoot, { recursive: true });
53550
- try {
53551
- fs14.symlinkSync(linkPath, target, "dir");
53552
- return {
53553
- agent: "claude",
53554
- path: target,
53555
- status: replaced ? "replaced" : "installed",
53556
- kind: "symlink",
53557
- detail: linkPath
53558
- };
53559
- } catch (err) {
53560
- const code = err.code;
53561
- if (code !== "EPERM" && code !== "EACCES") {
53562
- throw err;
53563
- }
53564
- fs14.cpSync(shipped, target, { recursive: true });
53565
- return {
53566
- agent: "claude",
53567
- path: target,
53568
- status: replaced ? "replaced" : "installed",
53569
- kind: "copy",
53570
- detail: "symlinks unavailable on this platform \u2014 copied instead; re-run install-skill after upgrading the CLI"
53571
- };
53572
- }
53573
- }
53574
- function installCodex(options, homeDir) {
53575
- const promptsDir = path11.join(homeDir, ".codex", "prompts");
53576
- const target = path11.join(promptsDir, `${SKILL_NAME}.md`);
53577
- const contents = buildCodexPrompt(options.shippedSkillDir);
53578
- const existing = lstatOrNull(target);
53579
- let replaced = false;
53580
- if (existing) {
53581
- const current = existing.isFile() ? fs14.readFileSync(target, "utf8") : null;
53582
- if (current === contents) {
53583
- return { agent: "codex", path: target, status: "already-current", kind: "pointer" };
53584
- }
53585
- if (!isOurCodexPrompt(target) && !options.force) {
53586
- return { agent: "codex", path: target, status: "blocked", kind: "pointer", detail: describeExisting(target) };
53587
- }
53588
- fs14.rmSync(target, { recursive: true, force: true });
53589
- replaced = true;
53553
+ function copyShippedSkill(shippedSkillDir, target) {
53554
+ fs14.mkdirSync(path11.dirname(target), { recursive: true });
53555
+ fs14.cpSync(shippedSkillDir, target, {
53556
+ recursive: true,
53557
+ filter: (src) => !COPY_EXCLUDES.has(path11.basename(src))
53558
+ });
53559
+ const marker = {
53560
+ installer: "web-cli",
53561
+ version: shippedSkillVersion(shippedSkillDir) ?? null,
53562
+ source: shippedSkillDir,
53563
+ installedAt: (/* @__PURE__ */ new Date()).toISOString(),
53564
+ note: "This directory is a copy managed by `web-cli install-skill`; re-run it to refresh, or `web-cli uninstall-skill` to remove."
53565
+ };
53566
+ fs14.writeFileSync(path11.join(target, INSTALL_MARKER_FILE), JSON.stringify(marker, null, 2) + "\n", "utf8");
53567
+ }
53568
+ function skillsRootFor(agent, options, homeDir, cwd) {
53569
+ switch (agent) {
53570
+ case "claude":
53571
+ return path11.join(options.project ? cwd : homeDir, ".claude", "skills");
53572
+ case "codex":
53573
+ return path11.join(resolveCodexHomeDir(homeDir, options.codexHomeDir), "skills");
53574
+ case "agents":
53575
+ return path11.join(resolveAgentsHomeDir(homeDir, options.agentsHomeDir), "skills");
53576
+ case "dsh":
53577
+ return path11.join(resolveDshHomeDir(homeDir, options.dshHomeDir), "skills");
53578
+ }
53579
+ }
53580
+ function legacyCodexPromptPath(options, homeDir) {
53581
+ return path11.join(resolveCodexHomeDir(homeDir, options.codexHomeDir), "prompts", `${SKILL_NAME}.md`);
53582
+ }
53583
+ function cleanUpLegacyCodexPrompt(options, homeDir) {
53584
+ const prompt = legacyCodexPromptPath(options, homeDir);
53585
+ if (!isOurCodexPrompt(prompt)) {
53586
+ return null;
53590
53587
  }
53591
- fs14.mkdirSync(promptsDir, { recursive: true });
53592
- fs14.writeFileSync(target, contents, "utf8");
53593
- return { agent: "codex", path: target, status: replaced ? "replaced" : "installed", kind: "pointer" };
53588
+ fs14.rmSync(prompt, { force: true });
53589
+ return `removed legacy pointer prompt ${prompt}`;
53594
53590
  }
53595
- function installAgents(options, homeDir) {
53596
- const agentsHome = resolveAgentsHomeDir(homeDir, options.agentsHomeDir);
53597
- const skillsRoot = path11.join(agentsHome, "skills");
53591
+ function installCopyInto(agent, skillsRoot, options) {
53598
53592
  const target = path11.join(skillsRoot, SKILL_NAME);
53599
53593
  const shipped = options.shippedSkillDir;
53600
- const existing = lstatOrNull(target);
53601
- let replaced = false;
53602
- if (existing) {
53603
- const linked = symlinkTarget(target);
53604
- if (linked === shipped && fs14.existsSync(linked)) {
53605
- return { agent: "agents", path: target, status: "already-current", kind: "symlink", detail: shipped };
53606
- }
53607
- const reclaimable = isOurSkillLink(target) || isCopyOfShippedSkill(target, shipped);
53608
- if (!reclaimable && !options.force) {
53609
- return { agent: "agents", path: target, status: "blocked", kind: "symlink", detail: describeExisting(target) };
53594
+ const version = shippedSkillVersion(shipped);
53595
+ const provenance = `copied from ${shipped}${version ? ` (v${version})` : ""}`;
53596
+ let status = "installed";
53597
+ if (lstatOrNull(target)) {
53598
+ const current = matchesShippedSkill(target, shipped);
53599
+ if (isOurInstalledCopy(target)) {
53600
+ if (current) {
53601
+ return { agent, path: target, status: "already-current", kind: "copy", detail: provenance };
53602
+ }
53603
+ status = "updated";
53604
+ } else if (isOurSkillLink(target) || current) {
53605
+ status = "replaced";
53606
+ } else if (options.force) {
53607
+ status = "replaced";
53608
+ } else {
53609
+ return { agent, path: target, status: "blocked", kind: "copy", detail: describeExisting(target) };
53610
53610
  }
53611
53611
  fs14.rmSync(target, { recursive: true, force: true });
53612
- replaced = true;
53613
- }
53614
- fs14.mkdirSync(skillsRoot, { recursive: true });
53615
- try {
53616
- fs14.symlinkSync(shipped, target, "dir");
53617
- return { agent: "agents", path: target, status: replaced ? "replaced" : "installed", kind: "symlink", detail: shipped };
53618
- } catch (err) {
53619
- const code = err.code;
53620
- if (code !== "EPERM" && code !== "EACCES") {
53621
- throw err;
53622
- }
53623
- fs14.cpSync(shipped, target, { recursive: true });
53624
- return {
53625
- agent: "agents",
53626
- path: target,
53627
- status: replaced ? "replaced" : "installed",
53628
- kind: "copy",
53629
- detail: "symlinks unavailable on this platform \u2014 copied instead; re-run install-skill after upgrading the CLI"
53630
- };
53631
53612
  }
53613
+ copyShippedSkill(shipped, target);
53614
+ return { agent, path: target, status, kind: "copy", detail: provenance };
53632
53615
  }
53633
53616
  function installSkill(options) {
53634
53617
  const homeDir = options.homeDir ?? os5.homedir();
53635
53618
  const cwd = options.cwd ?? process.cwd();
53636
- const agents = options.agents ?? resolveAgents(void 0, homeDir, options.agentsHomeDir);
53637
- return agents.map(
53638
- (agent) => agent === "claude" ? installClaude(options, homeDir, cwd) : agent === "codex" ? installCodex(options, homeDir) : installAgents(options, homeDir)
53639
- );
53619
+ const agents = options.agents ?? resolveAgents(void 0, homeDir, options);
53620
+ return agents.map((agent) => {
53621
+ const result = installCopyInto(agent, skillsRootFor(agent, options, homeDir, cwd), options);
53622
+ if (agent === "codex" && result.status !== "blocked") {
53623
+ const note = cleanUpLegacyCodexPrompt(options, homeDir);
53624
+ if (note) {
53625
+ result.detail = result.detail ? `${result.detail}; ${note}` : note;
53626
+ }
53627
+ }
53628
+ return result;
53629
+ });
53640
53630
  }
53641
53631
  function uninstallSkill(options) {
53642
53632
  const homeDir = options.homeDir ?? os5.homedir();
53643
53633
  const cwd = options.cwd ?? process.cwd();
53644
53634
  return options.agents.map((agent) => {
53645
- const target = agent === "claude" ? path11.join(options.project ? path11.join(cwd, ".claude") : path11.join(homeDir, ".claude"), "skills", SKILL_NAME) : agent === "codex" ? path11.join(homeDir, ".codex", "prompts", `${SKILL_NAME}.md`) : path11.join(resolveAgentsHomeDir(homeDir, options.agentsHomeDir), "skills", SKILL_NAME);
53635
+ const target = path11.join(skillsRootFor(agent, options, homeDir, cwd), SKILL_NAME);
53636
+ const legacyNote = agent === "codex" ? cleanUpLegacyCodexPrompt(options, homeDir) : null;
53646
53637
  if (!lstatOrNull(target)) {
53647
- return { agent, path: target, status: "not-registered" };
53638
+ return { agent, path: target, status: "not-registered", ...legacyNote ? { detail: legacyNote } : {} };
53648
53639
  }
53649
- const ours = agent === "codex" ? isOurCodexPrompt(target) : isOurSkillLink(target) || isCopyOfShippedSkill(target, options.shippedSkillDir);
53640
+ const ours = isOurInstalledCopy(target) || isOurSkillLink(target) || matchesShippedSkill(target, options.shippedSkillDir);
53650
53641
  if (!ours && !options.force) {
53651
53642
  return {
53652
53643
  agent,
@@ -53655,9 +53646,9 @@ function uninstallSkill(options) {
53655
53646
  detail: `${describeExisting(target)} \u2014 not something this CLI created; re-run with --force to delete it anyway`
53656
53647
  };
53657
53648
  }
53658
- const detail = symlinkTarget(target) ?? void 0;
53649
+ const what = symlinkTarget(target) ? `symlink -> ${symlinkTarget(target)}` : "installed copy";
53659
53650
  fs14.rmSync(target, { recursive: true, force: true });
53660
- return { agent, path: target, status: "removed", detail };
53651
+ return { agent, path: target, status: "removed", detail: legacyNote ? `${what}; ${legacyNote}` : what };
53661
53652
  });
53662
53653
  }
53663
53654
 
@@ -53950,10 +53941,10 @@ program2.command("render-markdown").description(
53950
53941
  }
53951
53942
  });
53952
53943
  program2.command("install-skill").aliases(["install-skills"]).description(
53953
- `Registers the usage-guidance skill bundled with this package (agents: ${AGENT_CHOICES.join(
53944
+ `Copies the usage-guidance skill bundled with this package into your AI agent's skills folder (agents: ${AGENT_CHOICES.join(
53954
53945
  ", "
53955
- )}) with your AI agent, so /web-cli works alongside these commands \u2014 defaults to whichever agents are installed`
53956
- ).option("--agent <agent>", `"${AGENT_CHOICES.join("|")}", or "all"`).option("--project", "install into <cwd>/.claude/skills instead of ~/.claude/skills (Claude Code only)").option("--force", "replace an existing registration that is not already ours").action(
53946
+ )}), so /web-cli works alongside these commands; re-run after upgrading the CLI to refresh the copies \u2014 defaults to whichever of claude/codex/dsh are installed ("agents" is never auto-selected)`
53947
+ ).option("--agent <agent>", `"${AGENT_CHOICES.join("|")}" (comma-separable), or "all"`).option("--project", "install into <cwd>/.claude/skills instead of ~/.claude/skills (Claude Code only)").option("--force", "replace an existing registration that is not already ours").action(
53957
53948
  wrap(
53958
53949
  async (opts) => runInstallSkill({ agent: opts.agent, project: opts.project, force: opts.force })
53959
53950
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ysgao/web-cli",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "Self-discovering REST API CLI for subscription medical-knowledge sites, driven by an AI agent",
5
5
  "license": "Apache-2.0",
6
6
  "bin": {
@@ -452,7 +452,16 @@ Concretely, when you see it (on a whole site's `sites.<site>.error`, or on one
452
452
  `web-cli auth status` reports whether cookies exist, but note that **cookies existing is not the
453
453
  same as being signed in** — ClinicalKey in particular hands out an anonymous session that satisfies
454
454
  search while still refusing full text. So a nonempty `auth status` does not guarantee full-text
455
- access; the authoritative check is whether the call you actually need succeeds. `auth status` also
455
+ access; the authoritative check is whether the call you actually need succeeds. A related trap,
456
+ confirmed live: ClinicalKey can also silently *demote* a previously signed-in session to that same
457
+ anonymous tier, in which case its search answers with a clean, error-free **`0` hits** for any
458
+ subscription-only query (open-access content still appears, so a common term still returns
459
+ something). `search`'s pre-flight now catches this by itself (it probes an article via a generic
460
+ canary query when your own query returned nothing, and re-logs in on the resulting refusal), so an
461
+ up-to-date `web-cli` recovers automatically — but if you ever see `hitsBySite.clinicalkey: 0` for
462
+ a query you'd expect ClinicalKey to cover, with no error and no `didYouMean`, treat it as a
463
+ possible demoted session rather than evidence the site has nothing: re-run once, and if it stays
464
+ at 0, `web-cli login clinicalkey --save-credentials` is the fix, not a different query. `auth status` also
456
465
  has no way to tell you whether a credential is saved for silent recovery — there is currently no
457
466
  read command for that; the only way to find out is to try a search (with no flags — this is simply
458
467
  the default) and see whether `SESSION_EXPIRED` appears (in which case either nothing is saved, or