evidence-mcp-dev 0.2.45 → 0.2.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +105 -58
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -9,9 +9,16 @@ console.debug = toStderr;
9
9
  // src/env.ts
10
10
  import { existsSync, readFileSync } from "fs";
11
11
  import { join, resolve } from "path";
12
- function dotenvFile(env = process.env) {
13
- const named = env.FH_ENV?.trim();
14
- if (named) return named;
12
+ function argEnv(argv = process.argv) {
13
+ for (let i = 0; i < argv.length; i++) {
14
+ if (argv[i] === "--env" && argv[i + 1]) return argv[i + 1];
15
+ if (argv[i].startsWith("--env=")) return argv[i].slice(6) || null;
16
+ }
17
+ return null;
18
+ }
19
+ function dotenvFile(env = process.env, argv = process.argv) {
20
+ const named = argEnv(argv)?.trim() || env.FH_ENV?.trim();
21
+ if (named) return resolve(named);
15
22
  if (existsSync(resolve(".env"))) return resolve(".env");
16
23
  const lib = env.FH_EVIDENCE_DIR?.trim() || (existsSync("/evidence") ? "/evidence" : "evidence");
17
24
  return join(resolve(lib), ".env");
@@ -1455,7 +1462,7 @@ async function unlockerHealth(name, unlockImpl = unlock) {
1455
1462
  }
1456
1463
 
1457
1464
  // src/walls.ts
1458
- import { mkdirSync as mkdirSync3, readFileSync as readFileSync3 } from "fs";
1465
+ import { existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync3, renameSync as renameSync2 } from "fs";
1459
1466
  import { join as join5 } from "path";
1460
1467
 
1461
1468
  // src/entry.ts
@@ -2572,7 +2579,7 @@ var host = (url) => {
2572
2579
  return "";
2573
2580
  }
2574
2581
  };
2575
- var file = (dir, h) => join5(dir, "walls", `${h.replace(/[^a-z0-9.-]/g, "_")}.json`);
2582
+ var file = (dir, h) => join5(dir, ".walls", `${h.replace(/[^a-z0-9.-]/g, "_")}.json`);
2576
2583
  var legacy = (stage2) => stage2.replace(/^(playwright|chrome) /, "browser ");
2577
2584
  function read(dir, h) {
2578
2585
  try {
@@ -2604,12 +2611,21 @@ function recordStage(url, stage2, ok, reason = "", dir = FH_EVIDENCE_DIR) {
2604
2611
  delete all[stage2];
2605
2612
  } else all[stage2] = { streak: (all[stage2]?.streak ?? 0) + 1, date: now(), reason: why };
2606
2613
  try {
2607
- mkdirSync3(join5(dir, "walls"), { recursive: true });
2614
+ mkdirSync3(join5(dir, ".walls"), { recursive: true });
2608
2615
  writeAtomic(file(dir, h), JSON.stringify(all) + "\n");
2609
2616
  } catch {
2610
2617
  }
2611
2618
  }
2612
2619
  var wallNote = (r) => `${r.reason} ${r.streak}\xD7 on this host, last ${r.date.slice(0, 10)}`;
2620
+ function migrateWalls(dir = FH_EVIDENCE_DIR) {
2621
+ const a = join5(dir, "walls"), b = join5(dir, ".walls");
2622
+ if (existsSync5(a) && !existsSync5(b)) {
2623
+ try {
2624
+ renameSync2(a, b);
2625
+ } catch {
2626
+ }
2627
+ }
2628
+ }
2613
2629
 
2614
2630
  // src/tiers/tier.ts
2615
2631
  var looked = (t, p, ctx) => ctx.lookups?.get(t.name) ?? t.lookup(p);
@@ -3144,6 +3160,7 @@ function urlTier(name, template, headers) {
3144
3160
  // src/config.ts
3145
3161
  var VARIABLES = [
3146
3162
  "FH_EVIDENCE_DIR",
3163
+ "FH_LOG_KEEP_DAYS",
3147
3164
  "FH_ENV",
3148
3165
  "FH_TIERS",
3149
3166
  "FH_CONTACT_EMAIL",
@@ -3376,18 +3393,30 @@ function isLocal(baseUrl) {
3376
3393
  }
3377
3394
 
3378
3395
  // src/log.ts
3379
- import { appendFileSync, existsSync as existsSync5, mkdirSync as mkdirSync4, renameSync as renameSync2, statSync } from "fs";
3396
+ import { appendFileSync, existsSync as existsSync6, mkdirSync as mkdirSync4, readdirSync as readdirSync2, renameSync as renameSync3, statSync, unlinkSync as unlinkSync2 } from "fs";
3380
3397
  import { hostname } from "os";
3381
- import { join as join6 } from "path";
3398
+ import { basename as basename2, dirname as dirname2, join as join6 } from "path";
3382
3399
  var HOST = hostname();
3383
- var LOG_FILE = join6(FH_EVIDENCE_DIR, "evidence.log");
3400
+ var LOG_DIR = join6(FH_EVIDENCE_DIR, "logs");
3401
+ var LOG_FILE = join6(LOG_DIR, "evidence.log");
3384
3402
  function stamp() {
3385
3403
  const d = /* @__PURE__ */ new Date();
3386
3404
  const p = (n) => String(n).padStart(2, "0");
3387
3405
  return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`;
3388
3406
  }
3389
- var LOG_MAX_BYTES = 50 * 1024 * 1024;
3390
- function rotateIfLarge(file3, max = LOG_MAX_BYTES) {
3407
+ var LOG_MAX_BYTES = 5 * 1024 * 1024;
3408
+ var DAY_MS = 864e5;
3409
+ var stampOf = (t) => {
3410
+ const p = (n) => String(n).padStart(2, "0");
3411
+ return `${t.getFullYear()}-${p(t.getMonth() + 1)}-${p(t.getDate())}-${p(t.getHours())}${p(t.getMinutes())}${p(t.getSeconds())}`;
3412
+ };
3413
+ function datedName(file3, when) {
3414
+ const base = join6(dirname2(file3), `${basename2(file3, ".log")}-${stampOf(when)}`);
3415
+ let name = `${base}.log`;
3416
+ for (let n = 2; existsSync6(name); n++) name = `${base}-${n}.log`;
3417
+ return name;
3418
+ }
3419
+ function rotateIfLarge(file3, max = LOG_MAX_BYTES, keepDays = num("FH_LOG_KEEP_DAYS", 7)) {
3391
3420
  let size = 0;
3392
3421
  try {
3393
3422
  size = statSync(file3).size;
@@ -3395,19 +3424,36 @@ function rotateIfLarge(file3, max = LOG_MAX_BYTES) {
3395
3424
  return false;
3396
3425
  }
3397
3426
  if (size <= max) return false;
3427
+ let moved = false;
3398
3428
  try {
3399
- renameSync2(file3, `${file3}.1`);
3400
- return true;
3429
+ renameSync3(file3, datedName(file3, /* @__PURE__ */ new Date()));
3430
+ moved = true;
3431
+ } catch {
3432
+ }
3433
+ pruneLogs(file3, keepDays);
3434
+ return moved;
3435
+ }
3436
+ function pruneLogs(file3, keepDays, now2 = Date.now()) {
3437
+ const dir = dirname2(file3), stem2 = basename2(file3, ".log");
3438
+ try {
3439
+ const old1 = `${file3}.1`;
3440
+ if (existsSync6(old1)) renameSync3(old1, datedName(file3, statSync(old1).mtime));
3441
+ for (const f of readdirSync2(dir)) {
3442
+ if (!f.startsWith(`${stem2}-`) || !f.endsWith(".log")) continue;
3443
+ const path = join6(dir, f);
3444
+ if (now2 - statSync(path).mtimeMs > keepDays * DAY_MS) unlinkSync2(path);
3445
+ }
3401
3446
  } catch {
3402
- return false;
3403
3447
  }
3404
3448
  }
3405
3449
  function migrateLogName(dir = FH_EVIDENCE_DIR) {
3406
- for (const [from, to] of [["library.log", "evidence.log"], ["library.log.1", "evidence.log.1"]]) {
3407
- const a = join6(dir, from), b = join6(dir, to);
3408
- if (existsSync5(a) && !existsSync5(b)) {
3450
+ const logs = join6(dir, "logs");
3451
+ for (const [from, to] of [["evidence.log", "evidence.log"], ["evidence.log.1", "evidence.log.1"], ["library.log", "evidence.log"], ["library.log.1", "evidence.log.1"]]) {
3452
+ const a = join6(dir, from), b = join6(logs, to);
3453
+ if (existsSync6(a) && !existsSync6(b)) {
3409
3454
  try {
3410
- renameSync2(a, b);
3455
+ mkdirSync4(logs, { recursive: true });
3456
+ renameSync3(a, b);
3411
3457
  } catch {
3412
3458
  }
3413
3459
  }
@@ -3418,7 +3464,7 @@ function log(tool, id, message) {
3418
3464
  const line = `${stamp()} ${HOST} ${tool} ${(id ?? "-").replace(/https:\/\//g, "")} ${clean2}
3419
3465
  `;
3420
3466
  try {
3421
- mkdirSync4(FH_EVIDENCE_DIR, { recursive: true });
3467
+ mkdirSync4(LOG_DIR, { recursive: true });
3422
3468
  rotateIfLarge(LOG_FILE);
3423
3469
  appendFileSync(LOG_FILE, line);
3424
3470
  } catch {
@@ -3426,7 +3472,7 @@ function log(tool, id, message) {
3426
3472
  }
3427
3473
 
3428
3474
  // src/stats.ts
3429
- import { mkdirSync as mkdirSync5, readdirSync as readdirSync2, readFileSync as readFileSync4, statSync as statSync2, unlinkSync as unlinkSync2 } from "fs";
3475
+ import { mkdirSync as mkdirSync5, readdirSync as readdirSync3, readFileSync as readFileSync4, statSync as statSync2, unlinkSync as unlinkSync3 } from "fs";
3430
3476
  import { join as join7 } from "path";
3431
3477
  var HEARTBEAT_MS = 5 * 6e4;
3432
3478
  var STALE_MS = 20 * 6e4;
@@ -3440,7 +3486,7 @@ function startStats(pkg2, libraryDir = FH_EVIDENCE_DIR) {
3440
3486
  setInterval(publish, HEARTBEAT_MS).unref();
3441
3487
  const stop = () => {
3442
3488
  try {
3443
- if (file2) unlinkSync2(file2);
3489
+ if (file2) unlinkSync3(file2);
3444
3490
  } catch {
3445
3491
  }
3446
3492
  };
@@ -3452,7 +3498,7 @@ function sweep(dir, staleMs = STALE_MS) {
3452
3498
  let n = 0;
3453
3499
  let names2;
3454
3500
  try {
3455
- names2 = readdirSync2(dir);
3501
+ names2 = readdirSync3(dir);
3456
3502
  } catch {
3457
3503
  return 0;
3458
3504
  }
@@ -3461,7 +3507,7 @@ function sweep(dir, staleMs = STALE_MS) {
3461
3507
  const p = join7(dir, name);
3462
3508
  try {
3463
3509
  if (Date.now() - statSync2(p).mtimeMs > staleMs) {
3464
- unlinkSync2(p);
3510
+ unlinkSync3(p);
3465
3511
  n++;
3466
3512
  }
3467
3513
  } catch {
@@ -3485,7 +3531,7 @@ function publish() {
3485
3531
  }
3486
3532
 
3487
3533
  // src/tools.ts
3488
- import { existsSync as existsSync13, readFileSync as readFileSync12 } from "fs";
3534
+ import { existsSync as existsSync14, readFileSync as readFileSync12 } from "fs";
3489
3535
  import { z } from "zod";
3490
3536
 
3491
3537
  // src/cascade.ts
@@ -3595,11 +3641,11 @@ function libraryIdForUrl(raw) {
3595
3641
  }
3596
3642
 
3597
3643
  // src/info.ts
3598
- import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync5, statSync as statSync3 } from "fs";
3599
- import { dirname as dirname2, join as join8 } from "path";
3644
+ import { existsSync as existsSync7, readdirSync as readdirSync4, readFileSync as readFileSync5, statSync as statSync3 } from "fs";
3645
+ import { dirname as dirname3, join as join8 } from "path";
3600
3646
  function* metaFiles(dir) {
3601
- if (!existsSync6(dir)) return;
3602
- for (const name of readdirSync3(dir)) {
3647
+ if (!existsSync7(dir)) return;
3648
+ for (const name of readdirSync4(dir)) {
3603
3649
  const p = join8(dir, name);
3604
3650
  if (statSync3(p).isDirectory()) yield* metaFiles(p);
3605
3651
  else if (name.endsWith("-meta.md")) yield p;
@@ -3640,7 +3686,7 @@ function libraryInfo(libraryDir, host3, tiers = resolveTiers()) {
3640
3686
  concerns: 0,
3641
3687
  updates: 0
3642
3688
  };
3643
- for (const type of existsSync6(libraryDir) ? readdirSync3(libraryDir) : []) {
3689
+ for (const type of existsSync7(libraryDir) ? readdirSync4(libraryDir) : []) {
3644
3690
  const typeDir = join8(libraryDir, type);
3645
3691
  if (!statSync3(typeDir).isDirectory()) continue;
3646
3692
  for (const meta of metaFiles(typeDir)) {
@@ -3653,8 +3699,8 @@ function libraryInfo(libraryDir, host3, tiers = resolveTiers()) {
3653
3699
  const t = info.types[type] ??= { entries: 0, full_text: 0, abstract: 0, title: 0, retracted: 0 };
3654
3700
  t.entries++;
3655
3701
  if (level === "full_text" || level === "abstract" || level === "title") t[level]++;
3656
- const dir = dirname2(meta);
3657
- for (const f of readdirSync3(dir)) {
3702
+ const dir = dirname3(meta);
3703
+ for (const f of readdirSync4(dir)) {
3658
3704
  try {
3659
3705
  const st = statSync3(join8(dir, f));
3660
3706
  if (st.isFile()) info.size_bytes += st.size;
@@ -4114,7 +4160,7 @@ function parseCsl(json2) {
4114
4160
 
4115
4161
  // src/urlfetch.ts
4116
4162
  import { createHash as createHash2 } from "crypto";
4117
- import { existsSync as existsSync7, mkdirSync as mkdirSync6, readFileSync as readFileSync6 } from "fs";
4163
+ import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync6 } from "fs";
4118
4164
  import { join as join9 } from "path";
4119
4165
 
4120
4166
  // src/pagemeta.ts
@@ -4278,7 +4324,7 @@ function renderUrlMeta(m) {
4278
4324
  return lines.map(([k, v]) => `${k}: ${v}`).join("\n") + "\n";
4279
4325
  }
4280
4326
  function readUrlMeta(p) {
4281
- if (!existsSync7(p.meta)) return null;
4327
+ if (!existsSync8(p.meta)) return null;
4282
4328
  const md = readFileSync6(p.meta, "utf8");
4283
4329
  const f = (k) => {
4284
4330
  const m = new RegExp(`^${k}:[ \\t]*(.*)$`, "m").exec(md);
@@ -4593,7 +4639,7 @@ function titleLine(m, md) {
4593
4639
  }
4594
4640
  function serve(requested, p, m, args, cached) {
4595
4641
  const maxLength = args.max_length ?? 5e3, startIndex = args.start_index ?? 0;
4596
- const read2 = (file3) => existsSync7(file3) ? readFileSync6(file3, "utf8") : "";
4642
+ const read2 = (file3) => existsSync8(file3) ? readFileSync6(file3, "utf8") : "";
4597
4643
  if (args.title_only) return { ok: true, text: `Contents of ${requested}:
4598
4644
  ${titleLine(m, read2(p.md))}`, cached, meta: m };
4599
4645
  const rawFile = m.files.find((f) => !f.endsWith("-meta.md") && !f.endsWith("-page.md"));
@@ -4618,7 +4664,7 @@ async function libraryFetch(libraryDir, requested, args, converter, logs = {}, f
4618
4664
  let stored = readUrlMeta(p);
4619
4665
  if (stored && fresh(stored) && stored.format === "html" && olderConverter(stored.converted_by, converter)) {
4620
4666
  const html = stored.files.find((f) => f.endsWith("-page.html"));
4621
- if (html && existsSync7(join9(p.entryDir, html))) {
4667
+ if (html && existsSync8(join9(p.entryDir, html))) {
4622
4668
  try {
4623
4669
  const page = await convert(readFileSync6(join9(p.entryDir, html)), stored.content_type || "text/html", stored.final_url || stored.url);
4624
4670
  if (page.md !== null) {
@@ -4664,11 +4710,11 @@ async function libraryFetch(libraryDir, requested, args, converter, logs = {}, f
4664
4710
 
4665
4711
  // src/verify/cache.ts
4666
4712
  import { createHash as createHash3 } from "crypto";
4667
- import { existsSync as existsSync9, mkdirSync as mkdirSync7, readFileSync as readFileSync8 } from "fs";
4668
- import { dirname as dirname3, join as join10 } from "path";
4713
+ import { existsSync as existsSync10, mkdirSync as mkdirSync7, readFileSync as readFileSync8 } from "fs";
4714
+ import { dirname as dirname4, join as join10 } from "path";
4669
4715
 
4670
4716
  // src/verify/verify.ts
4671
- import { existsSync as existsSync8, readFileSync as readFileSync7 } from "fs";
4717
+ import { existsSync as existsSync9, readFileSync as readFileSync7 } from "fs";
4672
4718
  var QUESTION = "Does the paper state this, in substance? Ignore section labels and definitions of terms in parentheses. Every fact and number of the statement must be stated in the paper or follow from its numbers; a rounded number counts. If any part of the statement is absent from the paper or contradicted by it, answer false.";
4673
4719
  function cleanMarkdown(md) {
4674
4720
  return paperYearOnly(dropReferences(md)).replace(/!\[[^\]]*\]\([^)]*\)/g, "").replace(/\]\([^)]*\)/g, "]").replace(/^\s*#+\s*(see more about|more for you|back to top)\b.*$/gim, "").replace(/\n{3,}/g, "\n\n");
@@ -4741,7 +4787,7 @@ async function readPaper(raw, libraryDir = FH_EVIDENCE_DIR) {
4741
4787
  if (p.error) return { id: p.requested, error: p.error };
4742
4788
  const paths = entryPaths(libraryDir, p.type, p.id);
4743
4789
  if (!entryExists(paths)) return { id: p.requested, error: "not in library" };
4744
- const full = existsSync8(paths.fulltextMd);
4790
+ const full = existsSync9(paths.fulltextMd);
4745
4791
  if (full) return { id: p.requested, basis: "full_text", text: readFileSync7(paths.fulltextMd, "utf8") };
4746
4792
  const meta = readMeta(paths);
4747
4793
  return { id: p.requested, basis: meta.has_abstract ? "abstract" : "title", text: readFileSync7(paths.md, "utf8") };
@@ -4797,7 +4843,7 @@ ${threshold}
4797
4843
  ${text4}`).slice(0, 16);
4798
4844
  var verdictFile = (libraryDir, key2) => join10(libraryDir, "verify", key2.slice(0, 2), key2.slice(0, 4), `${key2}.json`);
4799
4845
  function readVerdict(file3) {
4800
- if (!existsSync9(file3)) return null;
4846
+ if (!existsSync10(file3)) return null;
4801
4847
  try {
4802
4848
  return JSON.parse(readFileSync8(file3, "utf8"));
4803
4849
  } catch {
@@ -4809,7 +4855,7 @@ function lookup2(file3, maxDays) {
4809
4855
  return c && daysSince(c.date) < maxDays ? c : null;
4810
4856
  }
4811
4857
  function remember(file3, c) {
4812
- mkdirSync7(dirname3(file3), { recursive: true });
4858
+ mkdirSync7(dirname4(file3), { recursive: true });
4813
4859
  writeAtomic(file3, JSON.stringify(c, null, 2) + "\n");
4814
4860
  }
4815
4861
  async function verifyCached(claim, id, cfg, decide, libraryDir = FH_EVIDENCE_DIR, read2 = readPaper) {
@@ -4873,8 +4919,8 @@ var reviewTypes = (types) => types.filter((t) => t !== "Journal Article" && !/^R
4873
4919
 
4874
4920
  // src/trials.ts
4875
4921
  import { createHash as createHash4 } from "crypto";
4876
- import { existsSync as existsSync10, mkdirSync as mkdirSync8, readFileSync as readFileSync9 } from "fs";
4877
- import { dirname as dirname4, join as join11 } from "path";
4922
+ import { existsSync as existsSync11, mkdirSync as mkdirSync8, readFileSync as readFileSync9 } from "fs";
4923
+ import { dirname as dirname5, join as join11 } from "path";
4878
4924
  var searchCacheDays = () => settings().search_cache_days;
4879
4925
  var API2 = "https://clinicaltrials.gov/api/v2/studies";
4880
4926
  var FIELDS = ["NCTId", "BriefTitle", "OverallStatus", "WhyStopped", "Phase", "StudyType", "EnrollmentCount", "EnrollmentType", "StartDate", "PrimaryCompletionDate", "CompletionDate", "LastUpdatePostDate", "PrimaryOutcomeMeasure", "PrimaryOutcomeTimeFrame", "Condition", "InterventionName", "LeadSponsorName", "HasResults"];
@@ -4964,7 +5010,7 @@ async function searchTrials(raw, libraryDir = FH_EVIDENCE_DIR, fetchImpl = liveF
4964
5010
  const q = normalizeQuery(raw);
4965
5011
  if ("error" in q) return { ok: false, error: q.error };
4966
5012
  const file3 = searchFile(libraryDir, searchKey(q));
4967
- if (existsSync10(file3)) {
5013
+ if (existsSync11(file3)) {
4968
5014
  try {
4969
5015
  const r = JSON.parse(readFileSync9(file3, "utf8"));
4970
5016
  if (daysSince(r.searched) < searchCacheDays()) return { ok: true, result: r, cached: true };
@@ -4985,7 +5031,7 @@ async function searchTrials(raw, libraryDir = FH_EVIDENCE_DIR, fetchImpl = liveF
4985
5031
  }
4986
5032
  const result = { source: "clinicaltrials", query: q, total: parsed.total, columns: COLUMNS, rows: parsed.rows, searched: today() };
4987
5033
  try {
4988
- mkdirSync8(dirname4(file3), { recursive: true });
5034
+ mkdirSync8(dirname5(file3), { recursive: true });
4989
5035
  writeAtomic(file3, JSON.stringify(result, null, 2) + "\n");
4990
5036
  } catch {
4991
5037
  }
@@ -4998,8 +5044,8 @@ function trialsLogId(q) {
4998
5044
 
4999
5045
  // src/pubmedsearch.ts
5000
5046
  import { createHash as createHash5 } from "crypto";
5001
- import { existsSync as existsSync11, mkdirSync as mkdirSync9, readFileSync as readFileSync10 } from "fs";
5002
- import { dirname as dirname5 } from "path";
5047
+ import { existsSync as existsSync12, mkdirSync as mkdirSync9, readFileSync as readFileSync10 } from "fs";
5048
+ import { dirname as dirname6 } from "path";
5003
5049
  var MAX_RESULTS2 = 100;
5004
5050
  var DEFAULT_RESULTS2 = 20;
5005
5051
  var COLUMNS2 = ["pmid", "title", "first_author", "year", "journal", "publication_types", "pmcid", "level"];
@@ -5079,7 +5125,7 @@ async function searchArticles(raw, libraryDir = FH_EVIDENCE_DIR, fetchImpl = liv
5079
5125
  const q = normalizeQuery2(raw);
5080
5126
  if ("error" in q) return { ok: false, error: q.error };
5081
5127
  const file3 = searchFile(libraryDir, searchKey2(q));
5082
- if (existsSync11(file3)) {
5128
+ if (existsSync12(file3)) {
5083
5129
  try {
5084
5130
  const r = JSON.parse(readFileSync10(file3, "utf8"));
5085
5131
  if (daysSince(r.searched) < searchCacheDays()) return { ok: true, result: r, cached: true };
@@ -5102,7 +5148,7 @@ async function searchArticles(raw, libraryDir = FH_EVIDENCE_DIR, fetchImpl = liv
5102
5148
  }
5103
5149
  const result = { source: "pubmed", query: q, total, columns: COLUMNS2, rows, searched: today() };
5104
5150
  try {
5105
- mkdirSync9(dirname5(file3), { recursive: true });
5151
+ mkdirSync9(dirname6(file3), { recursive: true });
5106
5152
  writeAtomic(file3, JSON.stringify(result, null, 2) + "\n");
5107
5153
  } catch {
5108
5154
  }
@@ -5230,12 +5276,12 @@ function resultsText(nct, md, maxChars) {
5230
5276
  }
5231
5277
 
5232
5278
  // src/missing.ts
5233
- import { existsSync as existsSync12, mkdirSync as mkdirSync10, readFileSync as readFileSync11 } from "fs";
5279
+ import { existsSync as existsSync13, mkdirSync as mkdirSync10, readFileSync as readFileSync11 } from "fs";
5234
5280
  import { join as join12 } from "path";
5235
5281
  var missingFile = (p) => join12(p.entryDir, `${p.entry}-missing.md`);
5236
5282
  function readMissing(p) {
5237
5283
  const f = missingFile(p);
5238
- if (!existsSync12(f)) return null;
5284
+ if (!existsSync13(f)) return null;
5239
5285
  const md = readFileSync11(f, "utf8");
5240
5286
  const get4 = (k) => /^$/.test(k) ? "" : (new RegExp(`^${k}:[ \\t]*(.*)$`, "m").exec(md)?.[1] ?? "").trim();
5241
5287
  const checked = get4("checked"), reason = get4("reason");
@@ -5400,7 +5446,7 @@ Reading a document
5400
5446
 
5401
5447
  Status fields: pmid, pmcid, setid, nctid, publications, year, publication_types, retracted, corrections, citable, comment, has_abstract, level, version, retrieved_by, glyphs_unresolved, error. Funding and conflicts of interest: fh_library_read section "Declarations". Answers carry only what the call did not send: no echo of the ID, claim or query; a field that is null or an empty list is left out. fh_verify_claim always has verdict, score (null: no judgement) and basis.
5402
5448
 
5403
- Where records come from: PubMed for the record and abstract; the full text from PubMed Central, Europe PMC, publishers' text-mining links, Unpaywall, OpenAlex, CORE, and a proxy URL template from the configuration. Every action is appended as one line to <library>/evidence.log.`;
5449
+ Where records come from: PubMed for the record and abstract; the full text from PubMed Central, Europe PMC, publishers' text-mining links, Unpaywall, OpenAlex, CORE, and a proxy URL template from the configuration. Every action is appended as one line to <library>/logs/evidence.log.`;
5404
5450
  var idSchema = z.string().describe('ID as "type:value": a paper "pmid:30955454" (bare digits count as pmid) or "doi:10.5812/asjsm.110753" (a paper PubMed does not index; a DOI PubMed indexes is taken as its PMID), a drug label "dailymed:<set ID>" (the set ID from its DailyMed page URL), or a trial record "nct:05173896" (the eight digits; nct:NCT05173896 and a bare NCT05173896 are accepted).');
5405
5451
  var levelWord = (m) => m.level === "abstract" && !m.has_abstract ? "title" : m.level;
5406
5452
  var json = (s) => ({ content: [{ type: "text", text: statusAnswer(s) }] });
@@ -5737,7 +5783,7 @@ function registerTools(server2) {
5737
5783
  }
5738
5784
  added = true;
5739
5785
  }
5740
- const full = existsSync13(paths.fulltextMd);
5786
+ const full = existsSync14(paths.fulltextMd);
5741
5787
  const md = readFileSync12(full ? paths.fulltextMd : paths.md, "utf8");
5742
5788
  const text4 = full ? "full_text" : "abstract";
5743
5789
  const base = added ? { requested: parsed.requested, entry: paths.entry, text: text4, added: true } : { requested: parsed.requested, entry: paths.entry, text: text4 };
@@ -5758,7 +5804,7 @@ function registerTools(server2) {
5758
5804
  const cap = max_chars ?? 6e3;
5759
5805
  let sec = readSection(md, section2, cap);
5760
5806
  let via = "";
5761
- if (!sec && /abstract/i.test(section2) && full && existsSync13(paths.md)) {
5807
+ if (!sec && /abstract/i.test(section2) && full && existsSync14(paths.md)) {
5762
5808
  sec = readSection(readFileSync12(paths.md, "utf8"), "abstract", cap);
5763
5809
  via = " (from the abstract file)";
5764
5810
  }
@@ -5888,8 +5934,8 @@ ${st.funding.map((f) => `- ${f}`).join("\n")}` : ""].filter(Boolean).join("\n\n"
5888
5934
  return { content: [{ type: "text", text: `Failed to fetch ${url}: ${added.error}` }], isError: true };
5889
5935
  }
5890
5936
  }
5891
- const file3 = pid.type === "pmid" ? paths.md : existsSync13(paths.fulltextMd) ? paths.fulltextMd : paths.md;
5892
- const md = existsSync13(file3) ? readFileSync12(file3, "utf8") : "";
5937
+ const file3 = pid.type === "pmid" ? paths.md : existsSync14(paths.fulltextMd) ? paths.fulltextMd : paths.md;
5938
+ const md = existsSync14(file3) ? readFileSync12(file3, "utf8") : "";
5893
5939
  const text4 = title_only ? `Contents of ${url}:
5894
5940
  ${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "", max_length, start_index);
5895
5941
  bump("fetch", had);
@@ -5996,7 +6042,7 @@ ${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "
5996
6042
  return { content: [{ type: "text", text: compact2({ error: e.error }) }], isError: true };
5997
6043
  }
5998
6044
  const raw = e.paths.fulltextRaw("json");
5999
- const r = existsSync13(raw) ? recordSummary(readFileSync12(raw, "utf8")) : null;
6045
+ const r = existsSync14(raw) ? recordSummary(readFileSync12(raw, "utf8")) : null;
6000
6046
  if (!r) {
6001
6047
  log("trials", e.requested, "record error: no stored record");
6002
6048
  return { content: [{ type: "text", text: compact2({ error: "no stored record" }) }], isError: true };
@@ -6015,7 +6061,7 @@ ${(md.split("\n").find((l) => l.trim()) ?? "").trim()}` : fetchAnswer(url, md, "
6015
6061
  log("trials", nct, `results error: ${e.error}`);
6016
6062
  return { content: [{ type: "text", text: compact2({ error: e.error }) }], isError: true };
6017
6063
  }
6018
- const md = existsSync13(e.paths.fulltextMd) ? readFileSync12(e.paths.fulltextMd, "utf8") : "";
6064
+ const md = existsSync14(e.paths.fulltextMd) ? readFileSync12(e.paths.fulltextMd, "utf8") : "";
6019
6065
  const r = resultsText(e.requested.replace(/^nct:/, "NCT"), md, max_chars);
6020
6066
  log("trials", e.requested, `results ${r.has_results ? `${r.outcomes.length} outcomes${r.truncated ? " truncated" : ""}` : "none"}`);
6021
6067
  return { content: [{ type: "text", text: leanJson(r) }] };
@@ -6031,6 +6077,7 @@ var server = new McpServer(
6031
6077
  registerTools(server);
6032
6078
  startStats(pkg);
6033
6079
  migrateLogName();
6080
+ migrateWalls();
6034
6081
  log("startup", null, `${pkg.name} ${pkg.version}`);
6035
6082
  process.on("exit", abandonAll);
6036
6083
  for (const problem of [...resolveTiers().problems, ...verifyProblems()]) log("startup", null, `!! ${problem}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evidence-mcp-dev",
3
- "version": "0.2.45",
3
+ "version": "0.2.46",
4
4
  "description": "Internal development build of evidence-mcp. Not for public use.",
5
5
  "type": "module",
6
6
  "bin": {